Skip to content

Commit 60b5434

Browse files
committed
Merge branch 'nish-upstream-5e72c69-fix-tests' of github.com:matter-labs/foundry-zksync into nish-upstream-5e72c69-fix-tests
2 parents 3240eb0 + 5920457 commit 60b5434

File tree

37 files changed

+2217
-529
lines changed

37 files changed

+2217
-529
lines changed

Cargo.lock

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/config/src/zksync.rs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,30 @@ pub fn config_zksolc_settings(config: &Config) -> Result<ZkSolcSettings, SolcErr
166166
Ok(config.zksync.settings(libraries, config.evm_version, config.via_ir))
167167
}
168168

169+
/// Return the configured `zksolc` compiler
170+
///
171+
/// If not `offline`, will install the default version automatically
172+
/// Will fallback to `zksolc` present in the environment
173+
pub fn config_zksolc_compiler(config: &Config) -> Result<ZkSolcCompiler, SolcError> {
174+
let zksolc = if let Some(zksolc) =
175+
config_ensure_zksolc(config.zksync.zksolc.as_ref(), config.offline)?
176+
{
177+
zksolc
178+
} else if !config.offline {
179+
let default_version = semver::Version::new(1, 5, 10);
180+
let mut zksolc = ZkSolc::find_installed_version(&default_version)?;
181+
if zksolc.is_none() {
182+
ZkSolc::blocking_install(&default_version)?;
183+
zksolc = ZkSolc::find_installed_version(&default_version)?;
184+
}
185+
zksolc.unwrap_or_else(|| panic!("Could not install zksolc v{default_version}"))
186+
} else {
187+
"zksolc".into()
188+
};
189+
190+
Ok(ZkSolcCompiler { zksolc, solc: config_solc_compiler(config)? })
191+
}
192+
169193
/// Create a new zkSync project
170194
pub fn config_create_project(
171195
config: &Config,
@@ -193,23 +217,7 @@ pub fn config_create_project(
193217
builder = builder.sparse_output(filter);
194218
}
195219

196-
let zksolc = if let Some(zksolc) =
197-
config_ensure_zksolc(config.zksync.zksolc.as_ref(), config.offline)?
198-
{
199-
zksolc
200-
} else if !config.offline {
201-
let default_version = semver::Version::new(1, 5, 10);
202-
let mut zksolc = ZkSolc::find_installed_version(&default_version)?;
203-
if zksolc.is_none() {
204-
ZkSolc::blocking_install(&default_version)?;
205-
zksolc = ZkSolc::find_installed_version(&default_version)?;
206-
}
207-
zksolc.unwrap_or_else(|| panic!("Could not install zksolc v{default_version}"))
208-
} else {
209-
"zksolc".into()
210-
};
211-
212-
let zksolc_compiler = ZkSolcCompiler { zksolc, solc: config_solc_compiler(config)? };
220+
let zksolc_compiler = config_zksolc_compiler(config)?;
213221

214222
let project = builder.build(zksolc_compiler)?;
215223

@@ -229,12 +237,12 @@ pub fn config_create_project(
229237
fn config_solc_compiler(config: &Config) -> Result<SolcCompiler, SolcError> {
230238
if let Some(path) = &config.zksync.solc_path {
231239
if !path.is_file() {
232-
return Err(SolcError::msg(format!("`solc` {} does not exist", path.display())))
240+
return Err(SolcError::msg(format!("`solc` {} does not exist", path.display())));
233241
}
234242
let version = get_solc_version_info(path)?.version;
235243
let solc =
236244
Solc::new_with_version(path, Version::new(version.major, version.minor, version.patch));
237-
return Ok(SolcCompiler::Specific(solc))
245+
return Ok(SolcCompiler::Specific(solc));
238246
}
239247

240248
if let Some(ref solc) = config.solc {
@@ -256,7 +264,7 @@ fn config_solc_compiler(config: &Config) -> Result<SolcCompiler, SolcError> {
256264
}
257265
SolcReq::Local(path) => {
258266
if !path.is_file() {
259-
return Err(SolcError::msg(format!("`solc` {} does not exist", path.display())))
267+
return Err(SolcError::msg(format!("`solc` {} does not exist", path.display())));
260268
}
261269
let version = get_solc_version_info(path)?.version;
262270
Solc::new_with_version(
@@ -307,7 +315,7 @@ pub fn config_ensure_zksolc(
307315
if offline {
308316
return Err(SolcError::msg(format!(
309317
"can't install missing zksolc {version} in offline mode"
310-
)))
318+
)));
311319
}
312320
ZkSolc::blocking_install(version)?;
313321
zksolc = ZkSolc::find_installed_version(version)?;
@@ -319,12 +327,12 @@ pub fn config_ensure_zksolc(
319327
return Err(SolcError::msg(format!(
320328
"`zksolc` {} does not exist",
321329
zksolc.display()
322-
)))
330+
)));
323331
}
324332
Some(zksolc.clone())
325333
}
326334
};
327-
return Ok(zksolc)
335+
return Ok(zksolc);
328336
}
329337

330338
Ok(None)

crates/evm/evm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ foundry-evm-core.workspace = true
2222
foundry-evm-coverage.workspace = true
2323
foundry-evm-fuzz.workspace = true
2424
foundry-evm-traces.workspace = true
25+
foundry-linking.workspace = true
2526
foundry-zksync-core.workspace = true
2627
foundry-zksync-compilers.workspace = true
2728
foundry-zksync-inspectors.workspace = true

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use std::{
4040
borrow::Cow,
4141
time::{Duration, Instant},
4242
};
43-
use strategy::ExecutorStrategy;
43+
use strategy::{DeployLibKind, DeployLibResult, ExecutorStrategy};
4444

4545
mod builder;
4646
pub use builder::ExecutorBuilder;
@@ -303,6 +303,23 @@ impl Executor {
303303
self.deploy_with_env(env, rd)
304304
}
305305

306+
/// Deploys a library contract and commits the new state to the underlying database.
307+
///
308+
/// Executes a `deploy_kind` transaction with the provided parameters
309+
/// and persistent database state modifications.
310+
///
311+
/// Will return a list of deployment results and transaction requests
312+
/// Will also ensure nonce is increased for the sender
313+
pub fn deploy_library(
314+
&mut self,
315+
from: Address,
316+
kind: DeployLibKind,
317+
value: U256,
318+
rd: Option<&RevertDecoder>,
319+
) -> Result<Vec<DeployLibResult>, EvmError> {
320+
self.strategy.runner.deploy_library(self, from, kind, value, rd)
321+
}
322+
306323
/// Deploys a contract using the given `env` and commits the new state to the underlying
307324
/// database.
308325
///

crates/evm/evm/src/executors/strategy.rs

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1-
use std::{any::Any, fmt::Debug};
1+
use std::{any::Any, fmt::Debug, path::Path};
22

33
use alloy_primitives::{Address, U256};
44
use alloy_serde::OtherFields;
55
use eyre::Result;
66
use foundry_cheatcodes::strategy::{
77
CheatcodeInspectorStrategy, EvmCheatcodeInspectorStrategyRunner,
88
};
9-
use foundry_evm_core::backend::{strategy::BackendStrategy, Backend, BackendResult, CowBackend};
10-
use foundry_zksync_compilers::dual_compiled_contracts::DualCompiledContracts;
9+
use foundry_compilers::ProjectCompileOutput;
10+
use foundry_config::Config;
11+
use foundry_evm_core::{
12+
backend::{strategy::BackendStrategy, Backend, BackendResult, CowBackend},
13+
decode::RevertDecoder,
14+
};
15+
use foundry_linking::LinkerError;
16+
use foundry_zksync_compilers::{
17+
compilers::{artifact_output::zk::ZkArtifactOutput, zksolc::ZkSolcCompiler},
18+
dual_compiled_contracts::DualCompiledContracts,
19+
};
1120
use revm::{
1221
primitives::{Env, EnvWithHandlerCfg, ResultAndState},
1322
DatabaseRef,
1423
};
1524

1625
use crate::inspectors::InspectorStack;
1726

18-
use super::Executor;
27+
use super::{EvmError, Executor};
28+
29+
mod libraries;
30+
pub use libraries::*;
1931

2032
pub trait ExecutorStrategyContext: Debug + Send + Sync + Any {
2133
/// Clone the strategy context.
@@ -68,9 +80,32 @@ pub trait ExecutorStrategyRunner: Debug + Send + Sync + ExecutorStrategyExt {
6880
amount: U256,
6981
) -> BackendResult<()>;
7082

83+
fn get_balance(&self, executor: &mut Executor, address: Address) -> BackendResult<U256>;
84+
7185
fn set_nonce(&self, executor: &mut Executor, address: Address, nonce: u64)
7286
-> BackendResult<()>;
7387

88+
fn get_nonce(&self, executor: &mut Executor, address: Address) -> BackendResult<u64>;
89+
90+
fn link(
91+
&self,
92+
ctx: &mut dyn ExecutorStrategyContext,
93+
config: &Config,
94+
root: &Path,
95+
input: &ProjectCompileOutput,
96+
deployer: Address,
97+
) -> Result<LinkOutput, LinkerError>;
98+
99+
/// Deploys a library, applying state changes
100+
fn deploy_library(
101+
&self,
102+
executor: &mut Executor,
103+
from: Address,
104+
input: DeployLibKind,
105+
value: U256,
106+
rd: Option<&RevertDecoder>,
107+
) -> Result<Vec<DeployLibResult>, EvmError>;
108+
74109
/// Execute a transaction and *WITHOUT* applying state changes.
75110
fn call(
76111
&self,
@@ -110,6 +145,13 @@ pub trait ExecutorStrategyExt {
110145
) {
111146
}
112147

148+
fn zksync_set_compilation_output(
149+
&self,
150+
_ctx: &mut dyn ExecutorStrategyContext,
151+
_output: ProjectCompileOutput<ZkSolcCompiler, ZkArtifactOutput>,
152+
) {
153+
}
154+
113155
/// Set the fork environment on the context.
114156
fn zksync_set_fork_env(
115157
&self,
@@ -153,6 +195,10 @@ impl ExecutorStrategyRunner for EvmExecutorStrategyRunner {
153195
Ok(())
154196
}
155197

198+
fn get_balance(&self, executor: &mut Executor, address: Address) -> BackendResult<U256> {
199+
executor.get_balance(address)
200+
}
201+
156202
fn set_nonce(
157203
&self,
158204
executor: &mut Executor,
@@ -166,6 +212,33 @@ impl ExecutorStrategyRunner for EvmExecutorStrategyRunner {
166212
Ok(())
167213
}
168214

215+
fn get_nonce(&self, executor: &mut Executor, address: Address) -> BackendResult<u64> {
216+
executor.get_nonce(address)
217+
}
218+
219+
fn link(
220+
&self,
221+
_: &mut dyn ExecutorStrategyContext,
222+
_: &Config,
223+
root: &Path,
224+
input: &ProjectCompileOutput,
225+
deployer: Address,
226+
) -> Result<LinkOutput, LinkerError> {
227+
self.link_impl(root, input, deployer)
228+
}
229+
230+
/// Deploys a library, applying state changes
231+
fn deploy_library(
232+
&self,
233+
executor: &mut Executor,
234+
from: Address,
235+
kind: DeployLibKind,
236+
value: U256,
237+
rd: Option<&RevertDecoder>,
238+
) -> Result<Vec<DeployLibResult>, EvmError> {
239+
self.deploy_library_impl(executor, from, kind, value, rd)
240+
}
241+
169242
fn call(
170243
&self,
171244
_ctx: &dyn ExecutorStrategyContext,

0 commit comments

Comments
 (0)