Skip to content

Commit b85262d

Browse files
fix: propagate spec in withCfg/modifyCfgChained; add revertFrame on transfer failure
- withCfg and modifyCfgChained now call setSpecId on the returned context's journaled_state so the journal spec stays in sync - setupCallCore now calls revertFrame() before checkpointRevert() on the two early-return paths when value transfer fails, matching the pattern in mainnet_builder.zig Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f26c76a commit b85262d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/context/context.zig

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,17 @@ pub fn Context(comptime DB: type) type {
252252
}
253253

254254
pub fn withCfg(self: @This(), cfg: CfgEnv) @This() {
255-
var new_cfg = cfg;
256-
_ = new_cfg.spec();
257-
return .{
255+
var result = @This(){
258256
.tx = self.tx,
259257
.block = self.block,
260-
.cfg = new_cfg,
258+
.cfg = cfg,
261259
.journaled_state = self.journaled_state,
262260
.local = self.local,
263261
.chain = self.chain,
264262
.ctx_error = ContextError.ok,
265263
};
264+
result.journaled_state.setSpecId(cfg.spec());
265+
return result;
266266
}
267267

268268
/// Creates a new context with a new local context type.
@@ -282,7 +282,7 @@ pub fn Context(comptime DB: type) type {
282282
pub fn modifyCfgChained(self: @This(), f: fn (*CfgEnv) void) @This() {
283283
var new_cfg = self.cfg;
284284
f(&new_cfg);
285-
return .{
285+
var result = @This(){
286286
.tx = self.tx,
287287
.block = self.block,
288288
.cfg = new_cfg,
@@ -291,6 +291,8 @@ pub fn Context(comptime DB: type) type {
291291
.chain = self.chain,
292292
.ctx_error = ContextError.ok,
293293
};
294+
result.journaled_state.setSpecId(new_cfg.spec());
295+
return result;
294296
}
295297

296298
/// Modifies the context block.

src/interpreter/host.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,10 +685,12 @@ fn setupCallCore(js: anytype, host: *Host, inputs: CallInputs, frame_depth: usiz
685685
// 5. Value transfer
686686
if (inputs.value > 0 and inputs.scheme != .delegatecall) {
687687
const transfer_err = js.transfer(inputs.caller, inputs.target, inputs.value) catch {
688+
js.revertFrame();
688689
js.checkpointRevert(checkpoint);
689690
return .{ .failed = CallResult.preExecFailure(inputs.gas_limit) };
690691
};
691692
if (transfer_err != null) {
693+
js.revertFrame();
692694
js.checkpointRevert(checkpoint);
693695
return .{ .failed = CallResult.preExecFailure(inputs.gas_limit) };
694696
}

0 commit comments

Comments
 (0)