Skip to content

Commit d4c2d8e

Browse files
onbjerggrandizzy
andauthored
fix: persist auth items during simulation (#11601)
* fix: persist auth items during simulation Currently, when we persist calls during simulation, we do not account for EIP-7702 authorization items. This change implements an alternative path for 7702 transactions, just like we do for the non-persisting path. Closes #11483 * Lil space --------- Co-authored-by: grandizzy <[email protected]> Co-authored-by: grandizzy <[email protected]>
1 parent d334c99 commit d4c2d8e

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

crates/evm/evm/src/executors/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,22 @@ impl Executor {
492492
self.transact_with_env(env)
493493
}
494494

495+
/// Performs a raw call to an account on the current state of the VM with an EIP-7702
496+
/// authorization last.
497+
pub fn transact_raw_with_authorization(
498+
&mut self,
499+
from: Address,
500+
to: Address,
501+
calldata: Bytes,
502+
value: U256,
503+
authorization_list: Vec<SignedAuthorization>,
504+
) -> eyre::Result<RawCallResult> {
505+
let mut env = self.build_test_env(from, TxKind::Call(to), calldata, value);
506+
env.tx.set_signed_authorization(authorization_list);
507+
env.tx.tx_type = 4;
508+
self.transact_with_env(env)
509+
}
510+
495511
/// Execute the transaction configured in `env.tx`.
496512
///
497513
/// The state after the call is **not** persisted.

crates/forge/tests/cli/script.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,16 +2797,16 @@ Simulated On-chain Traces:
27972797
[..] → new Counter@0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
27982798
└─ ← [Return] 481 bytes of code
27992799
2800-
[0] 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266::increment()
2800+
[..] 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266::increment()
28012801
└─ ← [Stop]
28022802
2803-
[0] 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266::increment()
2803+
[..] 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266::increment()
28042804
└─ ← [Stop]
28052805
2806-
[0] 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266::setNumber(0)
2806+
[..] 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266::setNumber(0)
28072807
└─ ← [Stop]
28082808
2809-
[0] 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266::setNumber(0)
2809+
[..] 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266::setNumber(0)
28102810
└─ ← [Stop]
28112811
28122812

crates/script/src/runner.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,13 @@ impl ScriptRunner {
299299
authorization_list: Option<Vec<SignedAuthorization>>,
300300
commit: bool,
301301
) -> Result<ScriptResult> {
302-
let mut res = if let Some(authorization_list) = authorization_list {
302+
let mut res = if let Some(authorization_list) = &authorization_list {
303303
self.executor.call_raw_with_authorization(
304304
from,
305305
to,
306306
calldata.clone(),
307307
value,
308-
authorization_list,
308+
authorization_list.clone(),
309309
)?
310310
} else {
311311
self.executor.call_raw(from, to, calldata.clone(), value)?
@@ -319,7 +319,17 @@ impl ScriptRunner {
319319
// Otherwise don't re-execute, or some usecases might be broken: https://github.com/foundry-rs/foundry/issues/3921
320320
if commit {
321321
gas_used = self.search_optimal_gas_usage(&res, from, to, &calldata, value)?;
322-
res = self.executor.transact_raw(from, to, calldata, value)?;
322+
res = if let Some(authorization_list) = authorization_list {
323+
self.executor.transact_raw_with_authorization(
324+
from,
325+
to,
326+
calldata,
327+
value,
328+
authorization_list,
329+
)?
330+
} else {
331+
self.executor.transact_raw(from, to, calldata, value)?
332+
}
323333
}
324334

325335
let RawCallResult { result, reverted, logs, traces, labels, transactions, .. } = res;

0 commit comments

Comments
 (0)