Skip to content

Commit 766dd27

Browse files
lightsinggreged93
andauthored
fix: transact_system_call does not increase nonce (#272)
* fix: transact_system_call does not increase nonce * feat: add comment Signed-off-by: Gregory Edison <[email protected]> --------- Signed-off-by: Gregory Edison <[email protected]> Co-authored-by: Gregory Edison <[email protected]>
1 parent 29aa356 commit 766dd27

File tree

1 file changed

+12
-1
lines changed
  • crates/scroll/alloy/evm/src

1 file changed

+12
-1
lines changed

crates/scroll/alloy/evm/src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ where
183183
// disable the nonce check
184184
core::mem::swap(&mut self.cfg.disable_nonce_check, &mut disable_nonce_check);
185185

186-
let res = self.transact(ScrollTransactionIntoTxEnv::from(tx));
186+
let mut res = self.transact(ScrollTransactionIntoTxEnv::from(tx));
187187

188188
// swap back to the previous gas limit
189189
core::mem::swap(&mut self.block.gas_limit, &mut gas_limit);
@@ -192,6 +192,17 @@ where
192192
// swap back to the previous nonce check flag
193193
core::mem::swap(&mut self.cfg.disable_nonce_check, &mut disable_nonce_check);
194194

195+
// NOTE: We assume that only the contract storage is modified. Revm currently marks the
196+
// caller and block beneficiary accounts as "touched" when we do the above transact calls,
197+
// and includes them in the result.
198+
//
199+
// We're doing this state cleanup to make sure that changeset only includes the changed
200+
// contract storage.
201+
// Specifically prevents incorrect nonce increment for system contract caller.
202+
if let Ok(res) = &mut res {
203+
res.state.retain(|addr, _| *addr == contract);
204+
}
205+
195206
res
196207
}
197208

0 commit comments

Comments
 (0)