Skip to content

Commit

Permalink
Merge branch 'main' into jrigada-vm-getCode-for-zksolc-contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrigada authored Oct 15, 2024
2 parents 0f32de5 + 902f992 commit aedf3c6
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 58 deletions.
15 changes: 8 additions & 7 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ foundry-config.workspace = true
foundry-debugger.workspace = true
foundry-evm.workspace = true
foundry-wallets.workspace = true
zksync-web3-rs.workspace = true

foundry-compilers = { workspace = true, features = ["full"] }

Expand Down
17 changes: 17 additions & 0 deletions crates/cli/src/opts/build/zksync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::PathBuf;
use clap::Parser;
use foundry_config::ZkSyncConfig;
use serde::Serialize;
use zksync_web3_rs::types::{Address, Bytes};

#[derive(Clone, Debug, Default, Serialize, Parser)]
#[clap(next_help_heading = "ZKSync configuration")]
Expand Down Expand Up @@ -104,6 +105,22 @@ pub struct ZkSyncArgs {
/// Contracts to avoid compiling on zkSync
#[clap(long = "zk-avoid-contracts", visible_alias = "avoid-contracts", value_delimiter = ',')]
pub avoid_contracts: Option<Vec<String>>,

/// Paymaster address
#[clap(
long = "zk-paymaster-address",
value_name = "PAYMASTER_ADDRESS",
visible_alias = "paymaster-address"
)]
pub paymaster_address: Option<Address>,

/// Paymaster input
#[clap(
long = "zk-paymaster-input",
value_name = "PAYMASTER_INPUT",
visible_alias = "paymaster-input"
)]
pub paymaster_input: Option<Bytes>,
}

impl ZkSyncArgs {
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ impl ProjectCompiler {
let files = self.files.clone();

{
let zksolc_version = ZkSolc::new(project.compiler.zksolc.clone()).version()?;
let zksolc_version = ZkSolc::get_version_for_path(&project.compiler.zksolc)?;
Report::new(SpinnerReporter::spawn_with(format!("Using zksolc-{zksolc_version}")));
}
self.zksync_compile_with(&project.paths.root, || {
Expand Down
35 changes: 31 additions & 4 deletions crates/forge/bin/cmd/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use std::{
sync::Arc,
};
use zksync_types::H256;
use zksync_web3_rs::eip712::PaymasterParams;

merge_impl_figment_convert!(CreateArgs, opts, eth);

Expand Down Expand Up @@ -114,6 +115,7 @@ pub struct ZkSyncData {
bytecode: Vec<u8>,
bytecode_hash: H256,
factory_deps: Vec<Vec<u8>>,
paymaster_params: Option<PaymasterParams>,
}

impl CreateArgs {
Expand All @@ -125,6 +127,22 @@ impl CreateArgs {

let zksync = self.opts.compiler.zk.enabled();
if zksync {
let paymaster_params =
if let Some(paymaster_address) = self.opts.compiler.zk.paymaster_address {
Some(PaymasterParams {
paymaster: paymaster_address,
paymaster_input: self
.opts
.compiler
.zk
.paymaster_input
.clone()
.unwrap_or_default()
.to_vec(),
})
} else {
None
};
let target_path = if let Some(ref mut path) = self.contract.path {
canonicalize(project.root().join(path))?
} else {
Expand Down Expand Up @@ -223,7 +241,7 @@ impl CreateArgs {
visited_bytecodes.insert(bytecode.clone());
visited_bytecodes.into_iter().collect()
};
let zk_data = ZkSyncData { bytecode, bytecode_hash, factory_deps };
let zk_data = ZkSyncData { bytecode, bytecode_hash, factory_deps, paymaster_params };

let result = if self.unlocked {
// Deploy with unlocked account
Expand Down Expand Up @@ -555,7 +573,7 @@ impl CreateArgs {
let is_args_empty = args.is_empty();
let mut deployer =
factory.deploy_tokens_zk(args.clone(), &zk_data).context("failed to deploy contract")
.map(|deployer| deployer.set_zk_factory_deps(zk_data.factory_deps.clone())).map_err(|e| {
.map(|deployer| deployer.set_zk_factory_deps(zk_data.factory_deps.clone()).set_zk_paymaster_params(zk_data.paymaster_params.clone())).map_err(|e| {
if is_args_empty {
e.wrap_err("no arguments provided for contract constructor; consider --constructor-args or --constructor-args-path")
} else {
Expand Down Expand Up @@ -777,6 +795,7 @@ pub struct Deployer<B, P, T> {
confs: usize,
timeout: u64,
zk_factory_deps: Option<Vec<Vec<u8>>>,
zk_paymaster_params: Option<PaymasterParams>,
_p: PhantomData<P>,
_t: PhantomData<T>,
}
Expand All @@ -793,6 +812,7 @@ where
confs: self.confs,
timeout: self.timeout,
zk_factory_deps: self.zk_factory_deps.clone(),
zk_paymaster_params: self.zk_paymaster_params.clone(),
_p: PhantomData,
_t: PhantomData,
}
Expand All @@ -811,6 +831,12 @@ where
self
}

/// Set zksync's paymaster params.
pub fn set_zk_paymaster_params(mut self, params: Option<PaymasterParams>) -> Self {
self.zk_paymaster_params = params;
self
}

/// Broadcasts the zk contract deployment transaction and after waiting for it to
/// be sufficiently confirmed (default: 1), it returns a tuple with
/// the [`Contract`](crate::Contract) struct at the deployed contract's address
Expand All @@ -823,12 +849,12 @@ where
let tx = foundry_zksync_core::new_eip712_transaction(
self.tx,
factory_deps,
self.zk_paymaster_params.clone(),
self.client.borrow(),
signer.expect("No signer was found"),
)
.await
.map_err(|_| ContractDeploymentError::ContractNotDeployed)?;

let receipt = self
.client
.borrow()
Expand Down Expand Up @@ -975,6 +1001,7 @@ where
confs: 1,
timeout: self.timeout,
zk_factory_deps: None,
zk_paymaster_params: None,
_p: PhantomData,
_t: PhantomData,
})
Expand Down Expand Up @@ -1012,14 +1039,14 @@ where
.to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address())
.input(data.into()),
);

Ok(Deployer {
client: self.client.clone(),
abi: self.abi,
tx,
confs: 1,
timeout: self.timeout,
zk_factory_deps: Some(vec![zk_data.bytecode.clone()]),
zk_paymaster_params: zk_data.paymaster_params.clone(),
_p: PhantomData,
_t: PhantomData,
})
Expand Down
7 changes: 4 additions & 3 deletions crates/verify/src/etherscan/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Diagnostics: {diags}",
) -> Result<()> {
let solc_version = strip_build_meta(compiler_version.solc.clone());
let zksolc_version = strip_build_meta(compiler_version.zksolc.clone());
let zksolc = ZkSolc::find_installed_version(&zksolc_version)?
let zksolc_path = ZkSolc::find_installed_version(&zksolc_version)?
.unwrap_or(ZkSolc::blocking_install(&solc_version)?);

let input = ZkSolcVersionedInput {
Expand All @@ -202,9 +202,10 @@ Diagnostics: {diags}",
SolcCompiler::Specific(solc)
};

let zksolc_compiler = ZkSolcCompiler { zksolc: zksolc.zksolc, solc: solc_compiler };
let zksolc_compiler = ZkSolcCompiler { zksolc: zksolc_path, solc: solc_compiler };
let zksolc = zksolc_compiler.zksolc(&input)?;

let out = zksolc_compiler.zksync_compile(&input)?;
let out = zksolc.compile(&input.input)?;
if out.has_error() {
let mut o = ZkAggregatedCompilerOutput::default();
o.extend(solc_version, raw_build_info_new(&input, &out, false)?, out);
Expand Down
15 changes: 6 additions & 9 deletions crates/verify/src/zk_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use foundry_compilers::{
compilers::CompilerSettings,
resolver::parse::SolData,
solc::{Solc, SolcCompiler},
zksolc::{ZkSolc, ZkSolcCompiler},
zksolc::{self, ZkSolc, ZkSolcCompiler},
zksync::artifact_output::zk::ZkArtifactOutput,
Graph, Project,
};
Expand Down Expand Up @@ -43,13 +43,11 @@ impl ZkVerificationContext {
let mut project =
foundry_zksync_compiler::config_create_project(&config, config.cache, false)?;
project.no_artifacts = true;
let zksolc_version = ZkSolc::new(project.compiler.zksolc.clone()).version()?;
let mut is_zksync_solc = false;
let zksolc_version = ZkSolc::get_version_for_path(&project.compiler.zksolc)?;

let solc_version = if let Some(solc) = &config.zksync.solc_path {
let solc = Solc::new(solc)?;
//TODO: determine if this solc is zksync or not
solc.version
let (solc_version, is_zksync_solc) = if let Some(solc) = &config.zksync.solc_path {
let solc_type_and_version = zksolc::get_solc_version_info(solc)?;
(solc_type_and_version.version, solc_type_and_version.zksync_version.is_some())
} else {
//if there's no `solc_path` specified then we use the same
// as the project version
Expand All @@ -64,8 +62,7 @@ impl ZkVerificationContext {
let solc = Solc::new_with_version(solc_path, context_solc_version.clone());
project.compiler.solc = SolcCompiler::Specific(solc);

is_zksync_solc = true;
context_solc_version
(context_solc_version, true)
};

let compiler_version =
Expand Down
Loading

0 comments on commit aedf3c6

Please sign in to comment.