Skip to content

Commit

Permalink
add strategy objects
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec committed Dec 12, 2024
1 parent 85f68fd commit f1c871c
Show file tree
Hide file tree
Showing 47 changed files with 3,467 additions and 1,695 deletions.
44 changes: 42 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ members = [
"crates/script-sequence/",
"crates/macros/",
"crates/test-utils/",
"crates/strategy/core/",
"crates/strategy/zksync/",
]
resolver = "2"

Expand Down Expand Up @@ -173,6 +175,8 @@ foundry-linking = { path = "crates/linking" }
foundry-zksync-core = { path = "crates/zksync/core" }
foundry-zksync-compiler = { path = "crates/zksync/compiler" }
foundry-zksync-inspectors = { path = "crates/zksync/inspectors" }
foundry-strategy-core = { path = "crates/strategy/core" }
foundry-strategy-zksync = { path = "crates/strategy/zksync" }

# solc & compilation utilities
# foundry-block-explorers = { version = "0.9.0", default-features = false }
Expand Down
12 changes: 10 additions & 2 deletions crates/cast/bin/cmd/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ impl CallArgs {
let figment = Into::<Figment>::into(&self.eth).merge(&self);
let evm_opts = figment.extract::<EvmOpts>()?;
let mut config = Config::try_from(figment)?.sanitized();
let strategy = utils::get_executor_strategy(&config);

let Self {
to,
Expand Down Expand Up @@ -177,8 +178,15 @@ impl CallArgs {
env.cfg.disable_block_gas_limit = true;
env.block.gas_limit = U256::MAX;

let mut executor =
TracingExecutor::new(env, fork, evm_version, debug, decode_internal, alphanet);
let mut executor = TracingExecutor::new(
env,
fork,
evm_version,
debug,
decode_internal,
alphanet,
strategy,
);

let value = tx.value.unwrap_or_default();
let input = tx.inner.input.into_input().unwrap_or_default();
Expand Down
4 changes: 3 additions & 1 deletion crates/cast/bin/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use clap::Parser;
use eyre::{Result, WrapErr};
use foundry_cli::{
opts::{EtherscanOpts, RpcOpts},
utils::{handle_traces, init_progress, TraceResult},
utils::{self, handle_traces, init_progress, TraceResult},
};
use foundry_common::{is_known_system_sender, shell, SYSTEM_TRANSACTION_TYPE};
use foundry_compilers::artifacts::EvmVersion;
Expand Down Expand Up @@ -99,6 +99,7 @@ impl RunArgs {
let figment = Into::<Figment>::into(&self.rpc).merge(&self);
let evm_opts = figment.extract::<EvmOpts>()?;
let mut config = Config::try_from(figment)?.sanitized();
let strategy = utils::get_executor_strategy(&config);

let compute_units_per_second =
if self.no_rate_limit { Some(u64::MAX) } else { self.compute_units_per_second };
Expand Down Expand Up @@ -166,6 +167,7 @@ impl RunArgs {
self.debug,
self.decode_internal,
alphanet,
strategy,
);
let mut env =
EnvWithHandlerCfg::new_with_spec_id(Box::new(env.clone()), executor.spec_id());
Expand Down
3 changes: 0 additions & 3 deletions crates/cheatcodes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ foundry-evm-traces.workspace = true
foundry-wallets.workspace = true
forge-script-sequence.workspace = true
foundry-zksync-core.workspace = true
foundry-zksync-compiler.workspace = true
foundry-zksync-inspectors.workspace = true

zksync_types.workspace = true

alloy-dyn-abi.workspace = true
alloy-json-abi.workspace = true
alloy-primitives.workspace = true
Expand Down
28 changes: 14 additions & 14 deletions crates/cheatcodes/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use super::Result;
use crate::Vm::Rpc;
use crate::{
strategy::{CheatcodeInspectorStrategyExt, EvmCheatcodeInspectorStrategy},
Vm::Rpc,
};
use alloy_primitives::{map::AddressHashMap, U256};
use foundry_common::{fs::normalize_path, ContractsByArtifact};
use foundry_compilers::{utils::canonicalize, ProjectPathsConfig};
Expand All @@ -8,10 +11,10 @@ use foundry_config::{
ResolvedRpcEndpoints,
};
use foundry_evm_core::opts::EvmOpts;
use foundry_zksync_compiler::DualCompiledContracts;
use semver::Version;
use std::{
path::{Path, PathBuf},
sync::{Arc, Mutex},
time::Duration,
};

Expand Down Expand Up @@ -54,10 +57,11 @@ pub struct CheatsConfig {
pub running_contract: Option<String>,
/// Version of the script/test contract which is currently running.
pub running_version: Option<Version>,
/// ZKSolc -> Solc Contract codes
pub dual_compiled_contracts: DualCompiledContracts,
/// Use ZK-VM on startup
pub use_zk: bool,
// /// ZKSolc -> Solc Contract codes
// pub dual_compiled_contracts: DualCompiledContracts,
// /// Use ZK-VM on startup
// pub use_zk: bool,
pub strategy: Arc<Mutex<dyn CheatcodeInspectorStrategyExt>>,
/// Whether to enable legacy (non-reverting) assertions.
pub assertions_revert: bool,
/// Optional seed for the RNG algorithm.
Expand All @@ -72,8 +76,7 @@ impl CheatsConfig {
available_artifacts: Option<ContractsByArtifact>,
running_contract: Option<String>,
running_version: Option<Version>,
dual_compiled_contracts: DualCompiledContracts,
use_zk: bool,
strategy: Arc<Mutex<dyn CheatcodeInspectorStrategyExt>>,
) -> Self {
let mut allowed_paths = vec![config.root.0.clone()];
allowed_paths.extend(config.libs.clone());
Expand Down Expand Up @@ -103,8 +106,7 @@ impl CheatsConfig {
available_artifacts,
running_contract,
running_version,
dual_compiled_contracts,
use_zk,
strategy,
assertions_revert: config.assertions_revert,
seed: config.fuzz.seed,
}
Expand Down Expand Up @@ -235,8 +237,7 @@ impl Default for CheatsConfig {
available_artifacts: Default::default(),
running_contract: Default::default(),
running_version: Default::default(),
dual_compiled_contracts: Default::default(),
use_zk: false,
strategy: Arc::new(Mutex::new(EvmCheatcodeInspectorStrategy::default())),
assertions_revert: true,
seed: None,
}
Expand All @@ -255,8 +256,7 @@ mod tests {
None,
None,
None,
Default::default(),
false,
Arc::new(Mutex::new(EvmCheatcodeInspectorStrategy::default())),
)
}

Expand Down
Loading

0 comments on commit f1c871c

Please sign in to comment.