Skip to content

Commit 5353a10

Browse files
authored
feat: add strategy objects (#781)
* add strategy objects * use Box instead of Arc<Mutex<T>>
1 parent 1781234 commit 5353a10

File tree

54 files changed

+3393
-1878
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3393
-1878
lines changed

Cargo.lock

Lines changed: 32 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ members = [
2323
"crates/script-sequence/",
2424
"crates/macros/",
2525
"crates/test-utils/",
26+
"crates/strategy/zksync/",
2627
]
2728
resolver = "2"
2829

@@ -173,6 +174,7 @@ foundry-linking = { path = "crates/linking" }
173174
foundry-zksync-core = { path = "crates/zksync/core" }
174175
foundry-zksync-compiler = { path = "crates/zksync/compiler" }
175176
foundry-zksync-inspectors = { path = "crates/zksync/inspectors" }
177+
foundry-strategy-zksync = { path = "crates/strategy/zksync" }
176178

177179
# solc & compilation utilities
178180
# foundry-block-explorers = { version = "0.9.0", default-features = false }

crates/cast/bin/cmd/call.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ impl CallArgs {
112112
let figment = Into::<Figment>::into(&self.eth).merge(&self);
113113
let evm_opts = figment.extract::<EvmOpts>()?;
114114
let mut config = Config::try_from(figment)?.sanitized();
115+
let strategy = utils::get_executor_strategy(&config);
115116

116117
let Self {
117118
to,
@@ -177,8 +178,15 @@ impl CallArgs {
177178
env.cfg.disable_block_gas_limit = true;
178179
env.block.gas_limit = U256::MAX;
179180

180-
let mut executor =
181-
TracingExecutor::new(env, fork, evm_version, debug, decode_internal, alphanet);
181+
let mut executor = TracingExecutor::new(
182+
env,
183+
fork,
184+
evm_version,
185+
debug,
186+
decode_internal,
187+
alphanet,
188+
strategy,
189+
);
182190

183191
let value = tx.value.unwrap_or_default();
184192
let input = tx.inner.input.into_input().unwrap_or_default();

crates/cast/bin/cmd/run.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use clap::Parser;
88
use eyre::{Result, WrapErr};
99
use foundry_cli::{
1010
opts::{EtherscanOpts, RpcOpts},
11-
utils::{handle_traces, init_progress, TraceResult},
11+
utils::{self, handle_traces, init_progress, TraceResult},
1212
};
1313
use foundry_common::{is_known_system_sender, shell, SYSTEM_TRANSACTION_TYPE};
1414
use foundry_compilers::artifacts::EvmVersion;
@@ -99,6 +99,7 @@ impl RunArgs {
9999
let figment = Into::<Figment>::into(&self.rpc).merge(&self);
100100
let evm_opts = figment.extract::<EvmOpts>()?;
101101
let mut config = Config::try_from(figment)?.sanitized();
102+
let strategy = utils::get_executor_strategy(&config);
102103

103104
let compute_units_per_second =
104105
if self.no_rate_limit { Some(u64::MAX) } else { self.compute_units_per_second };
@@ -166,6 +167,7 @@ impl RunArgs {
166167
self.debug,
167168
self.decode_internal,
168169
alphanet,
170+
strategy,
169171
);
170172
let mut env =
171173
EnvWithHandlerCfg::new_with_spec_id(Box::new(env.clone()), executor.spec_id());

crates/cheatcodes/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ foundry-evm-traces.workspace = true
3232
foundry-wallets.workspace = true
3333
forge-script-sequence.workspace = true
3434
foundry-zksync-core.workspace = true
35-
foundry-zksync-compiler.workspace = true
3635
foundry-zksync-inspectors.workspace = true
3736

38-
zksync_types.workspace = true
39-
4037
alloy-dyn-abi.workspace = true
4138
alloy-json-abi.workspace = true
4239
alloy-primitives.workspace = true

crates/cheatcodes/src/config.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use super::Result;
2-
use crate::Vm::Rpc;
2+
use crate::{
3+
strategy::{CheatcodeInspectorStrategy, EvmCheatcodeInspectorStrategy},
4+
Vm::Rpc,
5+
};
36
use alloy_primitives::{map::AddressHashMap, U256};
47
use foundry_common::{fs::normalize_path, ContractsByArtifact};
58
use foundry_compilers::{utils::canonicalize, ProjectPathsConfig};
@@ -8,8 +11,6 @@ use foundry_config::{
811
ResolvedRpcEndpoints,
912
};
1013
use foundry_evm_core::opts::EvmOpts;
11-
use foundry_zksync_compiler::DualCompiledContracts;
12-
use foundry_zksync_core::vm::ZkEnv;
1314
use semver::Version;
1415
use std::{
1516
path::{Path, PathBuf},
@@ -55,16 +56,12 @@ pub struct CheatsConfig {
5556
pub running_contract: Option<String>,
5657
/// Version of the script/test contract which is currently running.
5758
pub running_version: Option<Version>,
58-
/// ZKSolc -> Solc Contract codes
59-
pub dual_compiled_contracts: DualCompiledContracts,
60-
/// Use ZK-VM on startup
61-
pub use_zk: bool,
59+
/// The behavior strategy.
60+
pub strategy: Box<dyn CheatcodeInspectorStrategy>,
6261
/// Whether to enable legacy (non-reverting) assertions.
6362
pub assertions_revert: bool,
6463
/// Optional seed for the RNG algorithm.
6564
pub seed: Option<U256>,
66-
/// Era Vm environment
67-
pub zk_env: Option<ZkEnv>,
6865
}
6966

7067
impl CheatsConfig {
@@ -76,9 +73,7 @@ impl CheatsConfig {
7673
available_artifacts: Option<ContractsByArtifact>,
7774
running_contract: Option<String>,
7875
running_version: Option<Version>,
79-
dual_compiled_contracts: DualCompiledContracts,
80-
use_zk: bool,
81-
zk_env: Option<ZkEnv>,
76+
strategy: Box<dyn CheatcodeInspectorStrategy>,
8277
) -> Self {
8378
let mut allowed_paths = vec![config.root.0.clone()];
8479
allowed_paths.extend(config.libs.clone());
@@ -108,11 +103,9 @@ impl CheatsConfig {
108103
available_artifacts,
109104
running_contract,
110105
running_version,
111-
dual_compiled_contracts,
112-
use_zk,
106+
strategy,
113107
assertions_revert: config.assertions_revert,
114108
seed: config.fuzz.seed,
115-
zk_env,
116109
}
117110
}
118111

@@ -241,11 +234,9 @@ impl Default for CheatsConfig {
241234
available_artifacts: Default::default(),
242235
running_contract: Default::default(),
243236
running_version: Default::default(),
244-
dual_compiled_contracts: Default::default(),
245-
use_zk: false,
237+
strategy: Box::new(EvmCheatcodeInspectorStrategy::default()),
246238
assertions_revert: true,
247239
seed: None,
248-
zk_env: Default::default(),
249240
}
250241
}
251242
}
@@ -262,9 +253,7 @@ mod tests {
262253
None,
263254
None,
264255
None,
265-
Default::default(),
266-
false,
267-
None,
256+
Box::new(EvmCheatcodeInspectorStrategy::default()),
268257
)
269258
}
270259

0 commit comments

Comments
 (0)