Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add strategy objects #781

Merged
merged 33 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f1c871c
add strategy objects
nbaztec Dec 12, 2024
b38109d
remove unused parts
nbaztec Dec 12, 2024
57f32f2
fix test build
nbaztec Dec 12, 2024
06aedf4
remove use_zk completely, fix ExecutorStrategy trait
nbaztec Dec 13, 2024
5d77f8c
fix deadlock
nbaztec Dec 14, 2024
6c00749
clippy
nbaztec Dec 14, 2024
b5fd952
fix tests, startup bug
nbaztec Dec 15, 2024
9009698
switch to try_lock to prevent deadlocks
nbaztec Dec 15, 2024
bee659d
revert try_lock
nbaztec Dec 15, 2024
b5b7e5f
noop instead of panic on zksync methods for evm, clippy
nbaztec Dec 15, 2024
5ee99fc
fix warp and roll
nbaztec Dec 15, 2024
2151459
fix script
nbaztec Dec 15, 2024
e9fbf13
make call immutable
nbaztec Dec 15, 2024
7b23078
deep clone strategies on clone
nbaztec Dec 16, 2024
095903b
trigger ci
nbaztec Dec 16, 2024
da60354
revert unintended change
nbaztec Dec 16, 2024
f740454
Merge branch 'main' into nish-abstraction-strategy
nbaztec Dec 16, 2024
193f955
fix zk cheatcodes in evm context
nbaztec Dec 16, 2024
a506866
fix get_code, remove unintended sleep
nbaztec Dec 16, 2024
0e9c64f
fix script test, clippy
nbaztec Dec 16, 2024
589c8ba
Merge branch 'main' into nish-abstraction-strategy
nbaztec Dec 16, 2024
f0d0f9d
fix zk_env
nbaztec Dec 16, 2024
d80312f
guard zk provider
nbaztec Dec 16, 2024
bdba380
use blocking provider call
nbaztec Dec 16, 2024
53d5d9a
Merge branch 'main' into nish-abstraction-strategy
nbaztec Dec 16, 2024
1876c01
use Box instead of Arc<Mutex<T>>
nbaztec Dec 17, 2024
d7e6f1d
remove arc/mutex
nbaztec Dec 19, 2024
e5ccd9e
use standard strategy traits
nbaztec Dec 19, 2024
5e5536a
use Ext trait pattern
nbaztec Dec 19, 2024
940757c
fix test
nbaztec Dec 19, 2024
42801bc
Revert "fix test"
nbaztec Dec 19, 2024
d757f7a
Revert "use Ext trait pattern"
nbaztec Dec 19, 2024
9660f7c
clippy
nbaztec Dec 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions Cargo.lock

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

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

Expand Down Expand Up @@ -173,6 +174,7 @@ 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-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
31 changes: 10 additions & 21 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::{CheatcodeInspectorStrategy, 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,8 +11,6 @@ use foundry_config::{
ResolvedRpcEndpoints,
};
use foundry_evm_core::opts::EvmOpts;
use foundry_zksync_compiler::DualCompiledContracts;
use foundry_zksync_core::vm::ZkEnv;
use semver::Version;
use std::{
path::{Path, PathBuf},
Expand Down Expand Up @@ -55,16 +56,12 @@ 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,
/// The behavior strategy.
pub strategy: Box<dyn CheatcodeInspectorStrategy>,
/// Whether to enable legacy (non-reverting) assertions.
pub assertions_revert: bool,
/// Optional seed for the RNG algorithm.
pub seed: Option<U256>,
/// Era Vm environment
pub zk_env: Option<ZkEnv>,
}

impl CheatsConfig {
Expand All @@ -76,9 +73,7 @@ impl CheatsConfig {
available_artifacts: Option<ContractsByArtifact>,
running_contract: Option<String>,
running_version: Option<Version>,
dual_compiled_contracts: DualCompiledContracts,
use_zk: bool,
zk_env: Option<ZkEnv>,
strategy: Box<dyn CheatcodeInspectorStrategy>,
) -> Self {
let mut allowed_paths = vec![config.root.0.clone()];
allowed_paths.extend(config.libs.clone());
Expand Down Expand Up @@ -108,11 +103,9 @@ impl CheatsConfig {
available_artifacts,
running_contract,
running_version,
dual_compiled_contracts,
use_zk,
strategy,
assertions_revert: config.assertions_revert,
seed: config.fuzz.seed,
zk_env,
}
}

Expand Down Expand Up @@ -241,11 +234,9 @@ 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: Box::new(EvmCheatcodeInspectorStrategy::default()),
assertions_revert: true,
seed: None,
zk_env: Default::default(),
}
}
}
Expand All @@ -262,9 +253,7 @@ mod tests {
None,
None,
None,
Default::default(),
false,
None,
Box::new(EvmCheatcodeInspectorStrategy::default()),
)
}

Expand Down
Loading
Loading