@@ -2,20 +2,19 @@ use std::{any::Any, fmt::Debug};
22
33use alloy_primitives:: { Address , U256 } ;
44use alloy_serde:: OtherFields ;
5- use eyre:: { Context , Result } ;
5+ use eyre:: Result ;
66use foundry_cheatcodes:: strategy:: {
77 CheatcodeInspectorStrategy , EvmCheatcodeInspectorStrategyRunner ,
88} ;
9- use foundry_evm_core:: {
10- backend:: { strategy:: BackendStrategy , BackendResult , DatabaseExt } ,
11- InspectorExt ,
12- } ;
9+ use foundry_evm_core:: backend:: { strategy:: BackendStrategy , Backend , BackendResult , CowBackend } ;
1310use foundry_zksync_compiler:: DualCompiledContracts ;
1411use revm:: {
1512 primitives:: { Env , EnvWithHandlerCfg , ResultAndState } ,
1613 DatabaseRef ,
1714} ;
1815
16+ use crate :: inspectors:: InspectorStack ;
17+
1918use super :: Executor ;
2019
2120pub trait ExecutorStrategyContext : Debug + Send + Sync + Any {
@@ -76,24 +75,25 @@ pub trait ExecutorStrategyRunner: Debug + Send + Sync + ExecutorStrategyExt {
7675 fn set_nonce ( & self , executor : & mut Executor , address : Address , nonce : u64 )
7776 -> BackendResult < ( ) > ;
7877
79- fn set_inspect_context ( & self , ctx : & mut dyn ExecutorStrategyContext , other_fields : OtherFields ) ;
80-
81- fn call_inspect (
78+ /// Execute a transaction and *WITHOUT* applying state changes.
79+ fn call (
8280 & self ,
8381 ctx : & dyn ExecutorStrategyContext ,
84- db : & mut dyn DatabaseExt ,
82+ backend : & mut CowBackend < ' _ > ,
8583 env : & mut EnvWithHandlerCfg ,
86- inspector : & mut dyn InspectorExt ,
87- ) -> eyre:: Result < ResultAndState > ;
84+ executor_env : & EnvWithHandlerCfg ,
85+ inspector : & mut InspectorStack ,
86+ ) -> Result < ResultAndState > ;
8887
89- fn transact_inspect (
88+ /// Execute a transaction and apply state changes.
89+ fn transact (
9090 & self ,
9191 ctx : & mut dyn ExecutorStrategyContext ,
92- db : & mut dyn DatabaseExt ,
92+ backend : & mut Backend ,
9393 env : & mut EnvWithHandlerCfg ,
94- _executor_env : & EnvWithHandlerCfg ,
95- inspector : & mut dyn InspectorExt ,
96- ) -> eyre :: Result < ResultAndState > ;
94+ executor_env : & EnvWithHandlerCfg ,
95+ inspector : & mut InspectorStack ,
96+ ) -> Result < ResultAndState > ;
9797
9898 fn new_backend_strategy ( & self ) -> BackendStrategy ;
9999 fn new_cheatcode_inspector_strategy (
@@ -123,6 +123,19 @@ pub trait ExecutorStrategyExt {
123123 ) -> Result < ( ) > {
124124 Ok ( ( ) )
125125 }
126+
127+ /// Sets the transaction context for the next [ExecutorStrategyRunner::call] or
128+ /// [ExecutorStrategyRunner::transact]. This selects whether to run the transaction on zkEVM
129+ /// or the EVM.
130+ /// This is based if the [OtherFields] contains
131+ /// [foundry_zksync_core::ZKSYNC_TRANSACTION_OTHER_FIELDS_KEY] with
132+ /// [foundry_zksync_core::ZkTransactionMetadata].
133+ fn zksync_set_transaction_context (
134+ & self ,
135+ _ctx : & mut dyn ExecutorStrategyContext ,
136+ _other_fields : OtherFields ,
137+ ) {
138+ }
126139}
127140
128141/// Implements [ExecutorStrategyRunner] for EVM.
@@ -138,55 +151,6 @@ impl ExecutorStrategyRunner for EvmExecutorStrategyRunner {
138151 Box :: new ( self . clone ( ) )
139152 }
140153
141- fn set_inspect_context (
142- & self ,
143- _ctx : & mut dyn ExecutorStrategyContext ,
144- _other_fields : OtherFields ,
145- ) {
146- }
147-
148- /// Executes the configured test call of the `env` without committing state changes.
149- ///
150- /// Note: in case there are any cheatcodes executed that modify the environment, this will
151- /// update the given `env` with the new values.
152- fn call_inspect (
153- & self ,
154- _ctx : & dyn ExecutorStrategyContext ,
155- db : & mut dyn DatabaseExt ,
156- env : & mut EnvWithHandlerCfg ,
157- inspector : & mut dyn InspectorExt ,
158- ) -> eyre:: Result < ResultAndState > {
159- let mut evm = crate :: utils:: new_evm_with_inspector ( db, env. clone ( ) , inspector) ;
160-
161- let res = evm. transact ( ) . wrap_err ( "backend: failed while inspecting" ) ?;
162-
163- env. env = evm. context . evm . inner . env ;
164-
165- Ok ( res)
166- }
167-
168- /// Executes the configured test call of the `env` without committing state changes.
169- /// Modifications to the state are however allowed.
170- ///
171- /// Note: in case there are any cheatcodes executed that modify the environment, this will
172- /// update the given `env` with the new values.
173- fn transact_inspect (
174- & self ,
175- _ctx : & mut dyn ExecutorStrategyContext ,
176- db : & mut dyn DatabaseExt ,
177- env : & mut EnvWithHandlerCfg ,
178- _executor_env : & EnvWithHandlerCfg ,
179- inspector : & mut dyn InspectorExt ,
180- ) -> eyre:: Result < ResultAndState > {
181- let mut evm = crate :: utils:: new_evm_with_inspector ( db, env. clone ( ) , inspector) ;
182-
183- let res = evm. transact ( ) . wrap_err ( "backend: failed while inspecting" ) ?;
184-
185- env. env = evm. context . evm . inner . env ;
186-
187- Ok ( res)
188- }
189-
190154 fn set_balance (
191155 & self ,
192156 executor : & mut Executor ,
@@ -214,6 +178,28 @@ impl ExecutorStrategyRunner for EvmExecutorStrategyRunner {
214178 Ok ( ( ) )
215179 }
216180
181+ fn call (
182+ & self ,
183+ _ctx : & dyn ExecutorStrategyContext ,
184+ backend : & mut CowBackend < ' _ > ,
185+ env : & mut EnvWithHandlerCfg ,
186+ _executor_env : & EnvWithHandlerCfg ,
187+ inspector : & mut InspectorStack ,
188+ ) -> Result < ResultAndState > {
189+ backend. inspect ( env, inspector, Box :: new ( ( ) ) )
190+ }
191+
192+ fn transact (
193+ & self ,
194+ _ctx : & mut dyn ExecutorStrategyContext ,
195+ backend : & mut Backend ,
196+ env : & mut EnvWithHandlerCfg ,
197+ _executor_env : & EnvWithHandlerCfg ,
198+ inspector : & mut InspectorStack ,
199+ ) -> Result < ResultAndState > {
200+ backend. inspect ( env, inspector, Box :: new ( ( ) ) )
201+ }
202+
217203 fn new_backend_strategy ( & self ) -> BackendStrategy {
218204 BackendStrategy :: new_evm ( )
219205 }
0 commit comments