Skip to content

Commit e8fae1a

Browse files
authored
fix(forge): keep gas memory on gas metering reset (#12539)
1 parent 19f2de7 commit e8fae1a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

crates/cheatcodes/src/inspector.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,10 @@ impl Cheatcodes {
19541954

19551955
#[cold]
19561956
fn meter_gas_reset(&mut self, interpreter: &mut Interpreter) {
1957-
interpreter.gas = Gas::new(interpreter.gas.limit());
1957+
let mut gas = Gas::new(interpreter.gas.limit());
1958+
gas.memory_mut().words_num = interpreter.gas.memory().words_num;
1959+
gas.memory_mut().expansion_cost = interpreter.gas.memory().expansion_cost;
1960+
interpreter.gas = gas;
19581961
self.gas_metering.reset = false;
19591962
}
19601963

crates/forge/tests/cli/test_cmd/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,15 @@ contract ATest is DSTest {
17441744
b = new B();
17451745
vm.resetGasMetering();
17461746
}
1747+
1748+
// https://github.com/foundry-rs/foundry/issues/12474
1749+
function testMemoryOnReset(uint8[1] memory x) public {
1750+
uint8[1] memory z;
1751+
z[0] = x[0];
1752+
assertEq(z[0], x[0]);
1753+
vm.resetGasMetering();
1754+
assertEq(x[0], z[0]);
1755+
}
17471756
}
17481757
"#,
17491758
);

0 commit comments

Comments
 (0)