From 85a28686978d7ab20c6d59d3a6aa6c63c93f7a0c Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Fri, 11 Oct 2024 23:26:16 +0200 Subject: [PATCH 01/13] working impl --- Cargo.lock | 204 ++++++++--------- Cargo.toml | 2 + crates/cli/Cargo.toml | 1 + crates/cli/src/utils/mod.rs | 7 + crates/common/Cargo.toml | 1 + crates/common/src/provider/mod.rs | 42 ++++ crates/forge/Cargo.toml | 1 + crates/forge/bin/cmd/create.rs | 350 ++++++++++++++++++++++++++++-- crates/zksync/core/src/lib.rs | 9 +- 9 files changed, 476 insertions(+), 141 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8a83c505f..0d8813e2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,6 +83,31 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "alloy" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8367891bf380210abb0d6aa30c5f85a9080cb4a066c4d5c5acadad630823751b" +dependencies = [ + "alloy-consensus", + "alloy-contract", + "alloy-core", + "alloy-eips", + "alloy-genesis", + "alloy-network", + "alloy-provider", + "alloy-pubsub", + "alloy-rpc-client", + "alloy-rpc-types", + "alloy-serde", + "alloy-signer", + "alloy-signer-local", + "alloy-transport", + "alloy-transport-http", + "alloy-transport-ipc", + "alloy-transport-ws", +] + [[package]] name = "alloy-chains" version = "0.1.34" @@ -129,11 +154,24 @@ dependencies = [ "thiserror", ] +[[package]] +name = "alloy-core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ce854562e7cafd5049189d0268d6e5cba05fe6c9cb7c6f8126a79b94800629c" +dependencies = [ + "alloy-dyn-abi", + "alloy-json-abi", + "alloy-primitives", + "alloy-rlp", + "alloy-sol-types", +] + [[package]] name = "alloy-dyn-abi" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4004925bff5ba0a11739ae84dbb6601a981ea692f3bd45b626935ee90a6b8471" +checksum = "0b499852e1d0e9b8c6db0f24c48998e647c0d5762a01090f955106a7700e4611" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -208,9 +246,9 @@ dependencies = [ [[package]] name = "alloy-json-abi" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9996daf962fd0a90d3c93b388033228865953b92de7bb1959b891d78750a4091" +checksum = "a438d4486b5d525df3b3004188f9d5cd1d65cd30ecc41e5a3ccef6f6342e8af9" dependencies = [ "alloy-primitives", "alloy-sol-type-parser", @@ -613,9 +651,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0458ccb02a564228fcd76efb8eb5a520521a8347becde37b402afec9a1b83859" +checksum = "68e7f6e8fe5b443f82b3f1e15abfa191128f71569148428e49449d01f6f49e8b" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", @@ -627,14 +665,14 @@ dependencies = [ [[package]] name = "alloy-sol-macro-expander" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bc65475025fc1e84bf86fc840f04f63fcccdcf3cf12053c99918e4054dfbc69" +checksum = "6b96ce28d2fde09abb6135f410c41fad670a3a770b6776869bd852f1df102e6f" dependencies = [ "alloy-json-abi", "alloy-sol-macro-input", "const-hex", - "heck 0.5.0", + "heck", "indexmap 2.5.0", "proc-macro-error2", "proc-macro2", @@ -646,14 +684,14 @@ dependencies = [ [[package]] name = "alloy-sol-macro-input" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ed10f0715a0b69fde3236ff3b9ae5f6f7c97db5a387747100070d3016b9266b" +checksum = "906746396a8296537745711630d9185746c0b50c033d5e9d18b0a6eba3d53f90" dependencies = [ "alloy-json-abi", "const-hex", "dunce", - "heck 0.5.0", + "heck", "proc-macro2", "quote", "serde_json", @@ -663,9 +701,9 @@ dependencies = [ [[package]] name = "alloy-sol-type-parser" -version = "0.8.3" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3edae8ea1de519ccba896b6834dec874230f72fe695ff3c9c118e90ec7cff783" +checksum = "c07ebb0c1674ff8cbb08378d7c2e0e27919d2a2dae07ad3bca26174deda8d389" dependencies = [ "serde", "winnow 0.6.18", @@ -673,9 +711,9 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1eb88e4da0a1b697ed6a9f811fdba223cf4d5c21410804fd1707836af73a462b" +checksum = "d86a533ce22525969661b25dfe296c112d35eb6861f188fd284f8bd4bb3842ae" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -773,6 +811,21 @@ dependencies = [ "tracing", ] +[[package]] +name = "alloy-zksync" +version = "0.1.0" +dependencies = [ + "alloy", + "async-trait", + "futures-utils-wasm", + "k256 0.13.3", + "rand 0.8.5", + "serde", + "thiserror", + "tracing", + "url", +] + [[package]] name = "ammonia" version = "4.0.0" @@ -1857,7 +1910,7 @@ dependencies = [ "bitflags 2.6.0", "cexpr", "clang-sys", - "itertools 0.10.5", + "itertools 0.11.0", "lazy_static", "lazycell", "log", @@ -1996,37 +2049,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "boojum" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df88daa33db46d683967ca09a4f04817c38950483f2501a771d497669a8a4bb1" -dependencies = [ - "arrayvec 0.7.6", - "bincode", - "blake2", - "const_format", - "convert_case 0.6.0", - "crossbeam", - "crypto-bigint 0.5.5", - "cs_derive", - "derivative", - "ethereum-types 0.14.1", - "firestorm", - "itertools 0.10.5", - "lazy_static", - "num-modular", - "num_cpus", - "pairing_ce", - "rand 0.8.5", - "rayon", - "serde", - "sha2 0.10.8", - "sha3_ce", - "smallvec", - "unroll", -] - [[package]] name = "boojum" version = "0.30.1" @@ -2599,7 +2621,7 @@ version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "syn 2.0.77", @@ -3166,18 +3188,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "cs_derive" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24cf603ca4299c6e20e644da88897f7b81d688510f4887e818b0bfe0b792081b" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "ctor" version = "0.2.8" @@ -4437,34 +4447,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "ff_ce" -version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b538e4231443a5b9c507caee3356f016d832cf7393d2d90f03ea3180d4e3fbc" -dependencies = [ - "byteorder", - "ff_derive_ce", - "hex", - "rand 0.4.6", - "serde", -] - -[[package]] -name = "ff_derive_ce" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b96fbccd88dbb1fac4ee4a07c2fcc4ca719a74ffbd9d2b9d41d8c8eb073d8b20" -dependencies = [ - "num-bigint", - "num-integer", - "num-traits", - "proc-macro2", - "quote", - "serde", - "syn 1.0.109", -] - [[package]] name = "fiat-crypto" version = "0.2.9" @@ -4607,6 +4589,7 @@ dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", "alloy-transport", + "alloy-zksync", "anvil", "async-trait", "axum", @@ -4988,6 +4971,7 @@ dependencies = [ "alloy-primitives", "alloy-provider", "alloy-transport", + "alloy-zksync", "clap", "color-eyre", "dotenvy", @@ -5033,6 +5017,7 @@ dependencies = [ "alloy-transport-http", "alloy-transport-ipc", "alloy-transport-ws", + "alloy-zksync", "async-trait", "clap", "comfy-table", @@ -6289,12 +6274,6 @@ dependencies = [ "hashbrown 0.14.5", ] -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "heck" version = "0.5.0" @@ -7193,7 +7172,7 @@ version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7895f186d5921065d96e16bd795e5ca89ac8356ec423fafc6e3d7cf8ec11aee4" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro-crate 3.2.0", "proc-macro2", "quote", @@ -8188,7 +8167,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate 3.2.0", "proc-macro2", "quote", "syn 2.0.77", @@ -8528,19 +8507,6 @@ dependencies = [ "sha2 0.10.8", ] -[[package]] -name = "pairing_ce" -version = "0.28.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843b5b6fb63f00460f611dbc87a50bbbb745f0dfe5cbf67ca89299c79098640e" -dependencies = [ - "byteorder", - "cfg-if 1.0.0", - "ff_ce", - "rand 0.4.6", - "serde", -] - [[package]] name = "parity-scale-codec" version = "2.3.1" @@ -9325,7 +9291,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22505a5c94da8e3b7c2996394d1c933236c4d743e81a410bcca4e6989fc066a4" dependencies = [ "bytes", - "heck 0.4.1", + "heck", "itertools 0.11.0", "log", "multimap", @@ -11590,7 +11556,7 @@ checksum = "1804e8a7c7865599c9c79be146dc8a9fd8cc86935fa641d3ea58e5f0688abaa5" dependencies = [ "dotenvy", "either", - "heck 0.5.0", + "heck", "hex", "once_cell", "proc-macro2", @@ -11811,7 +11777,7 @@ version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "rustversion", @@ -11914,9 +11880,9 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "0.8.3" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b95156f8b577cb59dc0b1df15c6f29a10afc5f8a7ac9786b0b5c68c19149278" +checksum = "20e7b52ad118b2153644eea95c6fc740b6c1555b2344fdab763fc9de4075f665" dependencies = [ "paste", "proc-macro2", @@ -13972,7 +13938,7 @@ checksum = "e3c365c801e0c6eda83fbd153df45575172beb406bfb663d386f9154b4325eda" dependencies = [ "arrayvec 0.7.6", "bincode", - "boojum 0.2.2", + "boojum", "derivative", "hex", "itertools 0.10.5", @@ -13994,7 +13960,7 @@ checksum = "2ccd0352e122a4e6f0046d2163b7e692e627b23fc3264faa77331a21b65833fd" dependencies = [ "arrayvec 0.7.6", "bincode", - "boojum 0.2.2", + "boojum", "derivative", "hex", "itertools 0.10.5", @@ -14015,7 +13981,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "784fa7cfb51e17c5ced112bca43da30b3468b2347b7af0427ad9638759fb140e" dependencies = [ "arrayvec 0.7.6", - "boojum 0.30.1", + "boojum", "derivative", "hex", "itertools 0.10.5", @@ -14528,7 +14494,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "903c23a12e160a703f9b68d0dd961daa24156af912ca1bc9efb74969f3acc645" dependencies = [ "anyhow", - "heck 0.5.0", + "heck", "prettyplease", "proc-macro2", "prost-build", diff --git a/Cargo.toml b/Cargo.toml index f8dddee75..d24180820 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -225,6 +225,8 @@ syn-solidity = "0.8.1" alloy-chains = "0.1" alloy-rlp = "0.3" alloy-trie = "0.5.0" +# alloy-zksync = "0.1.0" +alloy-zksync = { path = "../nbaztec-alloy-zksync" } ## op-alloy for tests in anvil op-alloy-rpc-types = "0.2.9" diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index e8690a0a7..646ea766d 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -28,6 +28,7 @@ alloy-primitives.workspace = true alloy-provider.workspace = true alloy-transport.workspace = true alloy-chains.workspace = true +alloy-zksync.workspace = true clap = { version = "4", features = ["derive", "env", "unicode", "wrap_help"] } color-eyre.workspace = true diff --git a/crates/cli/src/utils/mod.rs b/crates/cli/src/utils/mod.rs index f5bee0a77..0473993f3 100644 --- a/crates/cli/src/utils/mod.rs +++ b/crates/cli/src/utils/mod.rs @@ -2,6 +2,7 @@ use alloy_json_abi::JsonAbi; use alloy_primitives::U256; use alloy_provider::{network::AnyNetwork, Provider}; use alloy_transport::Transport; +use alloy_zksync::network::Zksync; use eyre::{ContextCompat, Result}; use foundry_common::provider::{ProviderBuilder, RetryProvider}; use foundry_config::{Chain, Config}; @@ -86,6 +87,12 @@ pub fn get_provider(config: &Config) -> Result { get_provider_builder(config)?.build() } +/// Returns a [RetryProvider] instantiated using [Config]'s +/// RPC for ZKsync +pub fn get_provider_zksync(config: &Config) -> Result> { + get_provider_builder(config)?.build_zksync() +} + /// Returns a [ProviderBuilder] instantiated using [Config] values. /// /// Defaults to `http://localhost:8545` and `Mainnet`. diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index b83b04ad8..7054df8ab 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -46,6 +46,7 @@ alloy-transport-ipc.workspace = true alloy-transport-ws.workspace = true alloy-transport.workspace = true alloy-consensus = { workspace = true, features = ["k256"] } +alloy-zksync.workspace = true tower.workspace = true diff --git a/crates/common/src/provider/mod.rs b/crates/common/src/provider/mod.rs index fe7fd4ccc..d9d40d7fb 100644 --- a/crates/common/src/provider/mod.rs +++ b/crates/common/src/provider/mod.rs @@ -15,6 +15,7 @@ use alloy_transport::{ layers::{RetryBackoffLayer, RetryBackoffService}, utils::guess_local_url, }; +use alloy_zksync::network::Zksync; use eyre::{Result, WrapErr}; use foundry_config::NamedChain; use reqwest::Url; @@ -281,6 +282,47 @@ impl ProviderBuilder { Ok(provider) } + /// Constructs the `RetryProvider` taking all configs into account for ZKsync network. + pub fn build_zksync(self) -> Result> { + let Self { + url, + chain, + max_retry, + initial_backoff, + timeout, + compute_units_per_second, + jwt, + headers, + is_local, + } = self; + let url = url?; + + let retry_layer = + RetryBackoffLayer::new(max_retry, initial_backoff, compute_units_per_second); + + let transport = RuntimeTransportBuilder::new(url) + .with_timeout(timeout) + .with_headers(headers) + .with_jwt(jwt) + .build(); + let client = ClientBuilder::default().layer(retry_layer).transport(transport, is_local); + + if !is_local { + client.set_poll_interval( + chain + .average_blocktime_hint() + .unwrap_or(DEFAULT_UNKNOWN_CHAIN_BLOCK_TIME) + .mul_f32(POLL_INTERVAL_BLOCK_TIME_SCALE_FACTOR), + ); + } + + let provider = AlloyProviderBuilder::<_, _, Zksync>::default() + .on_provider(RootProvider::new(client)); + + Ok(provider) + } + + /// Constructs the `RetryProvider` with a wallet. pub fn build_with_wallet(self, wallet: EthereumWallet) -> Result { let Self { diff --git a/crates/forge/Cargo.toml b/crates/forge/Cargo.toml index 42ec8cdca..af25788dc 100644 --- a/crates/forge/Cargo.toml +++ b/crates/forge/Cargo.toml @@ -75,6 +75,7 @@ alloy-signer.workspace = true alloy-sol-macro-expander = { workspace = true, features = ["json"] } alloy-sol-macro-input.workspace = true alloy-transport.workspace = true +alloy-zksync.workspace = true async-trait.workspace = true clap = { version = "4", features = ["derive", "env", "unicode", "wrap_help"] } diff --git a/crates/forge/bin/cmd/create.rs b/crates/forge/bin/cmd/create.rs index 155c7c932..70aa7446a 100644 --- a/crates/forge/bin/cmd/create.rs +++ b/crates/forge/bin/cmd/create.rs @@ -2,12 +2,13 @@ use alloy_chains::Chain; use alloy_dyn_abi::{DynSolValue, JsonAbiExt, Specifier}; use alloy_json_abi::{Constructor, JsonAbi}; use alloy_network::{AnyNetwork, EthereumWallet, TransactionBuilder}; -use alloy_primitives::{hex, Address, Bytes}; +use alloy_primitives::{hex, Address, Bytes, U256}; use alloy_provider::{PendingTransactionError, Provider, ProviderBuilder}; use alloy_rpc_types::{AnyTransactionReceipt, TransactionRequest}; use alloy_serde::WithOtherFields; use alloy_signer::Signer; use alloy_transport::{Transport, TransportError}; +use alloy_zksync::{network::Zksync, provider::ZksyncProvider, wallet::ZksyncWallet}; use clap::{Parser, ValueHint}; use eyre::{Context, Result}; use forge_verify::{zk_provider::CompilerVerificationContext, RetryArgs}; @@ -152,7 +153,7 @@ impl CreateArgs { // Add arguments to constructor let config = self.eth.try_load_config_emit_warnings()?; - let provider = utils::get_provider(&config)?; + let provider = utils::get_provider_zksync(&config)?; let params = match abi.constructor { Some(ref v) => { let constructor_args = @@ -225,10 +226,52 @@ impl CreateArgs { }; let zk_data = ZkSyncData { bytecode, bytecode_hash, factory_deps }; - let result = if self.unlocked { + if std::env::var("CREATE_ZK").unwrap_or_default() == "1" { + let provider = utils::get_provider(&config)?; + let result = if self.unlocked { + // Deploy with unlocked account + let sender = self.eth.wallet.from.expect("required"); + self.deploy_zk( + abi, + bin.object, + params, + provider, + chain_id, + sender, + config.transaction_timeout, + zk_data, + None, + ) + .await + } else { + // Deploy with signer + let signer = self.eth.wallet.signer().await?; + let zk_signer = self.eth.wallet.signer().await?; + let deployer = signer.address(); + let provider = ProviderBuilder::<_, _, AnyNetwork>::default() + .wallet(EthereumWallet::new(signer)) + .on_provider(provider); + self.deploy_zk( + abi, + bin.object, + params, + provider, + chain_id, + deployer, + config.transaction_timeout, + zk_data, + Some(zk_signer), + ) + .await + }; + + return result; + } + + return if self.unlocked { // Deploy with unlocked account let sender = self.eth.wallet.from.expect("required"); - self.deploy_zk( + self.deploy2( abi, bin.object, params, @@ -237,18 +280,16 @@ impl CreateArgs { sender, config.transaction_timeout, zk_data, - None, ) .await } else { // Deploy with signer let signer = self.eth.wallet.signer().await?; - let zk_signer = self.eth.wallet.signer().await?; let deployer = signer.address(); - let provider = ProviderBuilder::<_, _, AnyNetwork>::default() - .wallet(EthereumWallet::new(signer)) + let provider = ProviderBuilder::<_, _, Zksync>::default() + .wallet(ZksyncWallet::new(signer)) .on_provider(provider); - self.deploy_zk( + self.deploy2( abi, bin.object, params, @@ -257,12 +298,9 @@ impl CreateArgs { deployer, config.transaction_timeout, zk_data, - Some(zk_signer), ) .await - }; - - return result; + } } let target_path = if let Some(ref mut path) = self.contract.path { @@ -532,6 +570,166 @@ impl CreateArgs { verify.run().await } + /// Deploys the contract + #[allow(clippy::too_many_arguments)] + async fn deploy2, T: Transport + Clone>( + self, + abi: JsonAbi, + bin: BytecodeObject, + args: Vec, + provider: P, + chain: u64, + deployer_address: Address, + timeout: u64, + zk_data: ZkSyncData, + ) -> Result<()> { + let bin = bin.into_bytes().unwrap_or_else(|| { + panic!("no bytecode found in bin object for {}", self.contract.name) + }); + let provider = Arc::new(provider); + let factory = ContractFactory::new_zk(abi.clone(), bin.clone(), provider.clone(), timeout); + + let is_args_empty = args.is_empty(); + let mut deployer = + factory.deploy_tokens_zk(args.clone(), &zk_data).context("failed to deploy contract").map_err(|e| { + if is_args_empty { + e.wrap_err("no arguments provided for contract constructor; consider --constructor-args or --constructor-args-path") + } else { + e + } + })?; + let is_legacy = self.tx.legacy || Chain::from(chain).is_legacy(); + + // The large L2 gas per pubdata to sign. This gas is enough to ensure that + // any reasonable limit will be accepted. Note, that the operator is NOT required to + // use the honest value of gas per pubdata and it can use any value up to the one signed by + // the user. In the future releases, we will provide a way to estimate the current + // gasPerPubdata. + pub const DEFAULT_GAS_PER_PUBDATA_LIMIT: u64 = 50000; + + deployer.tx_zk = + deployer.tx_zk.with_gas_per_pubdata(U256::from(DEFAULT_GAS_PER_PUBDATA_LIMIT)).with_factory_deps( + zk_data.factory_deps.clone().into_iter().map(|dep| dep.into()).collect(), + ); + deployer.tx_zk.set_from(deployer_address); + deployer.tx_zk.set_chain_id(chain); + // `to` field must be set explicitly, cannot be None. + if deployer.tx_zk.to().is_none() { + deployer.tx_zk.set_create(); + } + deployer.tx_zk.set_nonce(if let Some(nonce) = self.tx.nonce { + Ok(nonce.to()) + } else { + provider.get_transaction_count(deployer_address).await + }?); + + // set tx value if specified + if let Some(value) = self.tx.value { + deployer.tx_zk.set_value(value); + } + + let gas_price = if let Some(gas_price) = self.tx.gas_price { + gas_price.to() + } else { + provider.get_gas_price().await? + }; + deployer.tx_zk.set_gas_price(gas_price); + + if !is_legacy { + let estimate = provider.estimate_eip1559_fees(None).await.wrap_err("Failed to estimate EIP1559 fees. This chain might not support EIP1559, try adding --legacy to your command.")?; + let priority_fee = if let Some(priority_fee) = self.tx.priority_gas_price { + priority_fee.to() + } else { + estimate.max_priority_fee_per_gas + }; + let max_fee = if let Some(max_fee) = self.tx.gas_price { + max_fee.to() + } else { + estimate.max_fee_per_gas + }; + + deployer.tx_zk.set_max_fee_per_gas(max_fee); + deployer.tx_zk.set_max_priority_fee_per_gas(priority_fee); + } + + let fee = provider + .estimate_fee(&deployer.tx_zk) + .await + .map_err(|err| eyre::eyre!("failed rpc call for estimating fee: {:?}", err))? + .unwrap_or_default(); + + deployer.tx_zk.set_gas_limit(if let Some(gas_limit) = self.tx.gas_limit { + gas_limit.to::() + } else { + fee.gas_limit.saturating_to::() + }); + + // Before we actually deploy the contract we try check if the verify settings are valid + let mut constructor_args = None; + if self.verify { + if !args.is_empty() { + let encoded_args = abi + .constructor() + .ok_or_else(|| eyre::eyre!("could not find constructor"))? + .abi_encode_input(&args)?; + constructor_args = Some(hex::encode_prefixed(encoded_args)); + } + + self.verify_preflight_check(constructor_args.clone(), chain).await?; + } + + // Deploy the actual contract + let (deployed_contract, receipt) = deployer.send_with_receipt_zk().await?; + + let address = deployed_contract; + if self.json { + let output = json!({ + "deployer": deployer_address.to_string(), + "deployedTo": address.to_string(), + "transactionHash": receipt.transaction_hash + }); + println!("{output}"); + } else { + println!("Deployer: {deployer_address}"); + println!("Deployed to: {address}"); + println!("Transaction hash: {:?}", receipt.transaction_hash); + }; + + if !self.verify { + return Ok(()); + } + + println!("Starting contract verification..."); + + let num_of_optimizations = + if self.opts.compiler.optimize { self.opts.compiler.optimizer_runs } else { None }; + let verify = forge_verify::VerifyArgs { + address, + contract: Some(self.contract), + compiler_version: None, + constructor_args, + constructor_args_path: None, + num_of_optimizations, + etherscan: EtherscanOpts { key: self.eth.etherscan.key(), chain: Some(chain.into()) }, + rpc: Default::default(), + flatten: false, + force: false, + skip_is_verified_check: false, + watch: true, + retry: self.retry, + libraries: self.opts.libraries.clone(), + root: None, + verifier: self.verifier, + via_ir: self.opts.via_ir, + evm_version: self.opts.compiler.evm_version, + show_standard_json_input: self.show_standard_json_input, + guess_constructor_args: false, + zksync: self.opts.compiler.zk.enabled(), + }; + println!("Waiting for {} to detect contract deployment...", verify.verifier.verifier); + verify.run().await + } + // Deploys the zk contract #[allow(clippy::too_many_arguments)] async fn deploy_zk, T: Transport + Clone>( @@ -553,11 +751,16 @@ impl CreateArgs { let factory = ContractFactory::new(abi.clone(), bin.clone(), provider.clone(), timeout); 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| { + let mut deployer = factory + .deploy_tokens_zk_old(args.clone(), &zk_data) + .context("failed to deploy contract") + .map(|deployer| deployer.set_zk_factory_deps(zk_data.factory_deps.clone())) + .map_err(|e| { if is_args_empty { - e.wrap_err("no arguments provided for contract constructor; consider --constructor-args or --constructor-args-path") + e.wrap_err( + "no arguments provided for contract + constructor; consider --constructor-args or --constructor-args-path", + ) } else { e } @@ -628,7 +831,7 @@ impl CreateArgs { } // Deploy the actual contract - let (deployed_contract, receipt) = deployer.send_with_receipt_zk(zk_signer).await?; + let (deployed_contract, receipt) = deployer.send_with_receipt_zk_old(zk_signer).await?; let address = deployed_contract; if self.json { @@ -772,6 +975,7 @@ impl From> for ContractDeploymentTx { pub struct Deployer { /// The deployer's transaction, exposed for overriding the defaults pub tx: WithOtherFields, + pub tx_zk: alloy_zksync::network::transaction_request::TransactionRequest, abi: JsonAbi, client: B, confs: usize, @@ -788,6 +992,7 @@ where fn clone(&self) -> Self { Self { tx: self.tx.clone(), + tx_zk: self.tx_zk.clone(), abi: self.abi.clone(), client: self.client.clone(), confs: self.confs, @@ -815,7 +1020,7 @@ where /// be sufficiently confirmed (default: 1), it returns a tuple with /// the [`Contract`](crate::Contract) struct at the deployed contract's address /// and the corresponding [`AnyReceipt`]. - pub async fn send_with_receipt_zk( + pub async fn send_with_receipt_zk_old( self, signer: Option, ) -> Result<(Address, AnyTransactionReceipt), ContractDeploymentError> { @@ -867,6 +1072,35 @@ where } } +impl Deployer +where + B: Borrow

+ Clone, + P: Provider, + T: Transport + Clone, +{ + /// Broadcasts the 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 + /// and the corresponding [`AnyReceipt`]. + pub async fn send_with_receipt_zk( + self, + ) -> Result<(Address, AnyTransactionReceipt), ContractDeploymentError> { + let receipt = self + .client + .borrow() + .send_transaction(self.tx_zk) + .await? + .with_required_confirmations(self.confs as u64) + .get_receipt() + .await?; + + let address = + receipt.contract_address.ok_or(ContractDeploymentError::ContractNotDeployed)?; + + Ok((address, receipt)) + } +} + /// To deploy a contract to the Ethereum network, a `ContractFactory` can be /// created which manages the Contract bytecode and Application Binary Interface /// (ABI), usually generated from the Solidity compiler. @@ -966,12 +1200,18 @@ where }; // create the tx object. Since we're deploying a contract, `to` is `None` - let tx = WithOtherFields::new(TransactionRequest::default().input(data.into())); + let tx = WithOtherFields::new(TransactionRequest::default().input(data.clone().into())); + let tx_zk = alloy_zksync::network::transaction_request::TransactionRequest::default().base( + TransactionRequest::default() + .to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address()) + .input(data.into()), + ); Ok(Deployer { client: self.client.clone(), abi: self.abi, tx, + tx_zk, confs: 1, timeout: self.timeout, zk_factory_deps: None, @@ -982,7 +1222,7 @@ where /// Create a deployment tx using the provided tokens as constructor /// arguments - pub fn deploy_tokens_zk( + pub fn deploy_tokens_zk_old( self, params: Vec, zk_data: &ZkSyncData, @@ -1008,6 +1248,11 @@ where // create the tx object. let tx = WithOtherFields::new( + TransactionRequest::default() + .to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address()) + .input(data.clone().into()), + ); + let tx_zk = alloy_zksync::network::transaction_request::TransactionRequest::default().base( TransactionRequest::default() .to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address()) .input(data.into()), @@ -1017,6 +1262,7 @@ where client: self.client.clone(), abi: self.abi, tx, + tx_zk, confs: 1, timeout: self.timeout, zk_factory_deps: Some(vec![zk_data.bytecode.clone()]), @@ -1026,6 +1272,68 @@ where } } +impl DeploymentTxFactory +where + B: Borrow

+ Clone, + P: Provider, + T: Transport + Clone, +{ + /// Creates a factory for deployment of the Contract with bytecode, and the + /// constructor defined in the abi. The client will be used to send any deployment + /// transaction. + pub fn new_zk(abi: JsonAbi, bytecode: Bytes, client: B, timeout: u64) -> Self { + Self { client, abi, bytecode, timeout, _p: PhantomData, _t: PhantomData } + } + + /// Create a deployment tx using the provided tokens as constructor + /// arguments + pub fn deploy_tokens_zk( + self, + params: Vec, + zk_data: &ZkSyncData, + ) -> Result, ContractDeploymentError> + where + B: Clone, + { + // Encode the constructor args & concatenate with the bytecode if necessary + if self.abi.constructor().is_none() && !params.is_empty() { + return Err(ContractDeploymentError::ConstructorError) + } + + // Encode the constructor args & concatenate with the bytecode if necessary + let constructor_args = match self.abi.constructor() { + None => Default::default(), + Some(constructor) => constructor.abi_encode_input(¶ms).unwrap_or_default(), + }; + let data: Bytes = foundry_zksync_core::encode_create_params( + &forge::revm::primitives::CreateScheme::Create, + zk_data.bytecode_hash, + constructor_args, + ) + .into(); + + // create the tx object. Since we're deploying a contract, `to` is `None` + let tx = WithOtherFields::new(TransactionRequest::default().input(data.clone().into())); + let tx_zk = alloy_zksync::network::transaction_request::TransactionRequest::default().base( + TransactionRequest::default() + .to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address()) + .input(data.into()), + ); + + Ok(Deployer { + client: self.client.clone(), + abi: self.abi, + tx, + tx_zk, + confs: 1, + timeout: self.timeout, + zk_factory_deps: None, + _p: PhantomData, + _t: PhantomData, + }) + } +} + #[derive(thiserror::Error, Debug)] /// An Error which is thrown when interacting with a smart contract pub enum ContractDeploymentError { diff --git a/crates/zksync/core/src/lib.rs b/crates/zksync/core/src/lib.rs index a0d8a689b..16089170e 100644 --- a/crates/zksync/core/src/lib.rs +++ b/crates/zksync/core/src/lib.rs @@ -198,7 +198,11 @@ pub async fn estimate_gas, T: Transport + Clone>( provider.get_gas_price().await? }; let data = tx.input.clone().into_input().unwrap_or_default(); + for d in &factory_deps { + println!("{}", hex::encode(&d)); + } let custom_data = Eip712Meta::new().factory_deps(factory_deps); + let custom_data_min = Eip712Meta::new(); let mut deploy_request = Eip712TransactionRequest::new() .r#type(EIP712_TX_TYPE) @@ -207,11 +211,14 @@ pub async fn estimate_gas, T: Transport + Clone>( .nonce(nonce) .gas_price(gas_price) .data(data.to_ethers()) - .custom_data(custom_data); + .custom_data(custom_data_min); if let Some(from) = tx.from { deploy_request = deploy_request.from(from.to_h160()) } + println!("{}", serde_json::to_string_pretty(&deploy_request).unwrap()); + deploy_request = deploy_request.custom_data(custom_data); + let gas_price = provider.get_gas_price().await.unwrap(); let fee: Fee = provider .raw_request("zks_estimateFee".into(), [deploy_request.clone()]) From b4ece57ea63ac0a57f664661c0aff7535e7330f0 Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Sat, 12 Oct 2024 00:17:15 +0200 Subject: [PATCH 02/13] use alloy-zksync --- Cargo.lock | 1 + Cargo.toml | 2 +- crates/common/src/provider/mod.rs | 5 +- crates/forge/bin/cmd/create.rs | 381 +++++------------------------- 4 files changed, 65 insertions(+), 324 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0d8813e2c..0a4f6a634 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -814,6 +814,7 @@ dependencies = [ [[package]] name = "alloy-zksync" version = "0.1.0" +source = "git+https://github.com/nbaztec/alloy-zksync?branch=v0.3.6#0adab979cf081350a9c0d7a42d4e8905a39d8c92" dependencies = [ "alloy", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index d24180820..9086f38e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -226,7 +226,7 @@ alloy-chains = "0.1" alloy-rlp = "0.3" alloy-trie = "0.5.0" # alloy-zksync = "0.1.0" -alloy-zksync = { path = "../nbaztec-alloy-zksync" } +alloy-zksync = { git = "https://github.com/nbaztec/alloy-zksync", branch = "v0.3.6"} ## op-alloy for tests in anvil op-alloy-rpc-types = "0.2.9" diff --git a/crates/common/src/provider/mod.rs b/crates/common/src/provider/mod.rs index d9d40d7fb..369c02598 100644 --- a/crates/common/src/provider/mod.rs +++ b/crates/common/src/provider/mod.rs @@ -316,13 +316,12 @@ impl ProviderBuilder { ); } - let provider = AlloyProviderBuilder::<_, _, Zksync>::default() - .on_provider(RootProvider::new(client)); + let provider = + AlloyProviderBuilder::<_, _, Zksync>::default().on_provider(RootProvider::new(client)); Ok(provider) } - /// Constructs the `RetryProvider` with a wallet. pub fn build_with_wallet(self, wallet: EthereumWallet) -> Result { let Self { diff --git a/crates/forge/bin/cmd/create.rs b/crates/forge/bin/cmd/create.rs index 70aa7446a..dca66f2ea 100644 --- a/crates/forge/bin/cmd/create.rs +++ b/crates/forge/bin/cmd/create.rs @@ -32,7 +32,6 @@ use foundry_config::{ }, merge_impl_figment_convert, Config, }; -use foundry_wallets::WalletSigner; use foundry_zksync_core::convert::ConvertH160; use serde_json::json; use std::{ @@ -112,6 +111,7 @@ pub struct CreateArgs { /// Data used to deploy a contract on zksync pub struct ZkSyncData { + #[allow(dead_code)] bytecode: Vec, bytecode_hash: H256, factory_deps: Vec>, @@ -226,52 +226,10 @@ impl CreateArgs { }; let zk_data = ZkSyncData { bytecode, bytecode_hash, factory_deps }; - if std::env::var("CREATE_ZK").unwrap_or_default() == "1" { - let provider = utils::get_provider(&config)?; - let result = if self.unlocked { - // Deploy with unlocked account - let sender = self.eth.wallet.from.expect("required"); - self.deploy_zk( - abi, - bin.object, - params, - provider, - chain_id, - sender, - config.transaction_timeout, - zk_data, - None, - ) - .await - } else { - // Deploy with signer - let signer = self.eth.wallet.signer().await?; - let zk_signer = self.eth.wallet.signer().await?; - let deployer = signer.address(); - let provider = ProviderBuilder::<_, _, AnyNetwork>::default() - .wallet(EthereumWallet::new(signer)) - .on_provider(provider); - self.deploy_zk( - abi, - bin.object, - params, - provider, - chain_id, - deployer, - config.transaction_timeout, - zk_data, - Some(zk_signer), - ) - .await - }; - - return result; - } - return if self.unlocked { // Deploy with unlocked account let sender = self.eth.wallet.from.expect("required"); - self.deploy2( + self.deploy_zk( abi, bin.object, params, @@ -289,7 +247,7 @@ impl CreateArgs { let provider = ProviderBuilder::<_, _, Zksync>::default() .wallet(ZksyncWallet::new(signer)) .on_provider(provider); - self.deploy2( + self.deploy_zk( abi, bin.object, params, @@ -570,9 +528,9 @@ impl CreateArgs { verify.run().await } - /// Deploys the contract + /// Deploys the contract using ZKsync provider. #[allow(clippy::too_many_arguments)] - async fn deploy2, T: Transport + Clone>( + async fn deploy_zk, T: Transport + Clone>( self, abi: JsonAbi, bin: BytecodeObject, @@ -607,17 +565,19 @@ impl CreateArgs { // gasPerPubdata. pub const DEFAULT_GAS_PER_PUBDATA_LIMIT: u64 = 50000; - deployer.tx_zk = - deployer.tx_zk.with_gas_per_pubdata(U256::from(DEFAULT_GAS_PER_PUBDATA_LIMIT)).with_factory_deps( + deployer.tx = deployer + .tx + .with_gas_per_pubdata(U256::from(DEFAULT_GAS_PER_PUBDATA_LIMIT)) + .with_factory_deps( zk_data.factory_deps.clone().into_iter().map(|dep| dep.into()).collect(), ); - deployer.tx_zk.set_from(deployer_address); - deployer.tx_zk.set_chain_id(chain); + deployer.tx.set_from(deployer_address); + deployer.tx.set_chain_id(chain); // `to` field must be set explicitly, cannot be None. - if deployer.tx_zk.to().is_none() { - deployer.tx_zk.set_create(); + if deployer.tx.to().is_none() { + deployer.tx.set_create(); } - deployer.tx_zk.set_nonce(if let Some(nonce) = self.tx.nonce { + deployer.tx.set_nonce(if let Some(nonce) = self.tx.nonce { Ok(nonce.to()) } else { provider.get_transaction_count(deployer_address).await @@ -625,7 +585,7 @@ impl CreateArgs { // set tx value if specified if let Some(value) = self.tx.value { - deployer.tx_zk.set_value(value); + deployer.tx.set_value(value); } let gas_price = if let Some(gas_price) = self.tx.gas_price { @@ -633,8 +593,8 @@ impl CreateArgs { } else { provider.get_gas_price().await? }; - deployer.tx_zk.set_gas_price(gas_price); - + deployer.tx.set_gas_price(gas_price); + if !is_legacy { let estimate = provider.estimate_eip1559_fees(None).await.wrap_err("Failed to estimate EIP1559 fees. This chain might not support EIP1559, try adding --legacy to your command.")?; let priority_fee = if let Some(priority_fee) = self.tx.priority_gas_price { @@ -648,17 +608,17 @@ impl CreateArgs { estimate.max_fee_per_gas }; - deployer.tx_zk.set_max_fee_per_gas(max_fee); - deployer.tx_zk.set_max_priority_fee_per_gas(priority_fee); + deployer.tx.set_max_fee_per_gas(max_fee); + deployer.tx.set_max_priority_fee_per_gas(priority_fee); } let fee = provider - .estimate_fee(&deployer.tx_zk) + .estimate_fee(&deployer.tx) .await .map_err(|err| eyre::eyre!("failed rpc call for estimating fee: {:?}", err))? .unwrap_or_default(); - deployer.tx_zk.set_gas_limit(if let Some(gas_limit) = self.tx.gas_limit { + deployer.tx.set_gas_limit(if let Some(gas_limit) = self.tx.gas_limit { gas_limit.to::() } else { fee.gas_limit.saturating_to::() @@ -679,7 +639,7 @@ impl CreateArgs { } // Deploy the actual contract - let (deployed_contract, receipt) = deployer.send_with_receipt_zk().await?; + let (deployed_contract, receipt) = deployer.send_with_receipt().await?; let address = deployed_contract; if self.json { @@ -730,158 +690,6 @@ impl CreateArgs { verify.run().await } - // Deploys the zk contract - #[allow(clippy::too_many_arguments)] - async fn deploy_zk, T: Transport + Clone>( - self, - abi: JsonAbi, - bin: BytecodeObject, - args: Vec, - provider: P, - chain: u64, - deployer_address: Address, - timeout: u64, - zk_data: ZkSyncData, - zk_signer: Option, - ) -> Result<()> { - let bin = bin.into_bytes().unwrap_or_else(|| { - panic!("no bytecode found in bin object for {}", self.contract.name) - }); - let provider = Arc::new(provider); - let factory = ContractFactory::new(abi.clone(), bin.clone(), provider.clone(), timeout); - - let is_args_empty = args.is_empty(); - let mut deployer = factory - .deploy_tokens_zk_old(args.clone(), &zk_data) - .context("failed to deploy contract") - .map(|deployer| deployer.set_zk_factory_deps(zk_data.factory_deps.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 { - e - } - })?; - - deployer.tx.set_from(deployer_address); - deployer.tx.set_chain_id(chain); - // `to` field must be set explicitly, cannot be None. - if deployer.tx.to.is_none() { - deployer.tx.set_create(); - } - deployer.tx.set_nonce(if let Some(nonce) = self.tx.nonce { - Ok(nonce.to()) - } else { - provider.get_transaction_count(deployer_address).await - }?); - - // set tx value if specified - if let Some(value) = self.tx.value { - deployer.tx.set_value(value); - } - - let gas_price = if let Some(gas_price) = self.tx.gas_price { - gas_price.to() - } else { - provider.get_gas_price().await? - }; - deployer.tx.set_gas_price(gas_price); - - let estimated_gas = foundry_zksync_core::estimate_gas( - &deployer.tx, - zk_data.factory_deps.clone(), - &provider, - ) - .await?; - - deployer.tx.set_gas_limit(if let Some(gas_limit) = self.tx.gas_limit { - gas_limit.to::() - } else { - estimated_gas.limit - }); - - let zk_constructor_args = match abi.constructor() { - None => Default::default(), - Some(constructor) => constructor.abi_encode_input(&args).unwrap_or_default(), - }; - let data = foundry_zksync_core::encode_create_params( - &forge::revm::primitives::CreateScheme::Create, - zk_data.bytecode_hash, - zk_constructor_args, - ); - let data = Bytes::from(data); - deployer.tx.set_input(data); - - deployer.tx.set_to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address()); - - let mut constructor_args = None; - if self.verify { - if !args.is_empty() { - let encoded_args = abi - .constructor() - .ok_or_else(|| eyre::eyre!("could not find constructor"))? - .abi_encode_input(&args)?; - constructor_args = Some(hex::encode(encoded_args)); - } - - self.verify_preflight_check(constructor_args.clone(), chain).await?; - } - - // Deploy the actual contract - let (deployed_contract, receipt) = deployer.send_with_receipt_zk_old(zk_signer).await?; - - let address = deployed_contract; - if self.json { - let output = json!({ - "deployer": deployer_address.to_string(), - "deployedTo": address.to_string(), - "transactionHash": receipt.transaction_hash - }); - println!("{output}"); - } else { - println!("Deployer: {deployer_address}"); - println!("Deployed to: {address}"); - println!("Transaction hash: {:?}", receipt.transaction_hash); - }; - - if !self.verify { - return Ok(()); - } - - println!("Starting contract verification..."); - - let num_of_optimizations = - if self.opts.compiler.optimize { self.opts.compiler.optimizer_runs } else { None }; - let verify = forge_verify::VerifyArgs { - address, - contract: Some(self.contract), - compiler_version: None, - constructor_args, - constructor_args_path: None, - num_of_optimizations, - etherscan: EtherscanOpts { key: self.eth.etherscan.key(), chain: Some(chain.into()) }, - rpc: Default::default(), - flatten: false, - force: false, - skip_is_verified_check: false, - watch: true, - retry: self.retry, - libraries: self.opts.libraries.clone(), - root: None, - verifier: self.verifier, - via_ir: self.opts.via_ir, - evm_version: self.opts.compiler.evm_version, - show_standard_json_input: self.show_standard_json_input, - guess_constructor_args: false, - zksync: true, - }; - println!("Waiting for {} to detect contract deployment...", verify.verifier.verifier); - verify.run().await - } - /// Parses the given constructor arguments into a vector of `DynSolValue`s, by matching them /// against the constructor's input params. /// @@ -975,7 +783,6 @@ impl From> for ContractDeploymentTx { pub struct Deployer { /// The deployer's transaction, exposed for overriding the defaults pub tx: WithOtherFields, - pub tx_zk: alloy_zksync::network::transaction_request::TransactionRequest, abi: JsonAbi, client: B, confs: usize, @@ -992,7 +799,6 @@ where fn clone(&self) -> Self { Self { tx: self.tx.clone(), - tx_zk: self.tx_zk.clone(), abi: self.abi.clone(), client: self.client.clone(), confs: self.confs, @@ -1010,45 +816,6 @@ where P: Provider, T: Transport + Clone, { - /// Set zksync's factory deps. - pub fn set_zk_factory_deps(mut self, deps: Vec>) -> Self { - self.zk_factory_deps = Some(deps); - 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 - /// and the corresponding [`AnyReceipt`]. - pub async fn send_with_receipt_zk_old( - self, - signer: Option, - ) -> Result<(Address, AnyTransactionReceipt), ContractDeploymentError> { - let factory_deps = self.zk_factory_deps.unwrap_or_default(); - let tx = foundry_zksync_core::new_eip712_transaction( - self.tx, - factory_deps, - self.client.borrow(), - signer.expect("No signer was found"), - ) - .await - .map_err(|_| ContractDeploymentError::ContractNotDeployed)?; - - let receipt = self - .client - .borrow() - .send_raw_transaction(&tx) - .await? - .with_required_confirmations(self.confs as u64) - .get_receipt() - .await?; - - let address = - receipt.contract_address.ok_or(ContractDeploymentError::ContractNotDeployed)?; - - Ok((address, receipt)) - } - /// Broadcasts the 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 @@ -1072,7 +839,40 @@ where } } -impl Deployer +/// Helper which manages the deployment transaction of a smart contract +#[derive(Debug)] +#[must_use = "Deployer does nothing unless you `send` it"] +pub struct ZkDeployer { + /// The deployer's transaction, exposed for overriding the defaults + pub tx: alloy_zksync::network::transaction_request::TransactionRequest, + abi: JsonAbi, + client: B, + confs: usize, + timeout: u64, + zk_factory_deps: Option>>, + _p: PhantomData

, + _t: PhantomData, +} + +impl Clone for ZkDeployer +where + B: Clone, +{ + fn clone(&self) -> Self { + Self { + tx: self.tx.clone(), + abi: self.abi.clone(), + client: self.client.clone(), + confs: self.confs, + timeout: self.timeout, + zk_factory_deps: self.zk_factory_deps.clone(), + _p: PhantomData, + _t: PhantomData, + } + } +} + +impl ZkDeployer where B: Borrow

+ Clone, P: Provider, @@ -1082,13 +882,13 @@ where /// be sufficiently confirmed (default: 1), it returns a tuple with /// the [`Contract`](crate::Contract) struct at the deployed contract's address /// and the corresponding [`AnyReceipt`]. - pub async fn send_with_receipt_zk( + pub async fn send_with_receipt( self, ) -> Result<(Address, AnyTransactionReceipt), ContractDeploymentError> { let receipt = self .client .borrow() - .send_transaction(self.tx_zk) + .send_transaction(self.tx) .await? .with_required_confirmations(self.confs as u64) .get_receipt() @@ -1201,17 +1001,11 @@ where // create the tx object. Since we're deploying a contract, `to` is `None` let tx = WithOtherFields::new(TransactionRequest::default().input(data.clone().into())); - let tx_zk = alloy_zksync::network::transaction_request::TransactionRequest::default().base( - TransactionRequest::default() - .to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address()) - .input(data.into()), - ); Ok(Deployer { client: self.client.clone(), abi: self.abi, tx, - tx_zk, confs: 1, timeout: self.timeout, zk_factory_deps: None, @@ -1219,57 +1013,6 @@ where _t: PhantomData, }) } - - /// Create a deployment tx using the provided tokens as constructor - /// arguments - pub fn deploy_tokens_zk_old( - self, - params: Vec, - zk_data: &ZkSyncData, - ) -> Result, ContractDeploymentError> - where - B: Clone, - { - if self.abi.constructor().is_none() && !params.is_empty() { - return Err(ContractDeploymentError::ConstructorError) - } - - // Encode the constructor args & concatenate with the bytecode if necessary - let constructor_args = match self.abi.constructor() { - None => Default::default(), - Some(constructor) => constructor.abi_encode_input(¶ms).unwrap_or_default(), - }; - let data: Bytes = foundry_zksync_core::encode_create_params( - &forge::revm::primitives::CreateScheme::Create, - zk_data.bytecode_hash, - constructor_args, - ) - .into(); - - // create the tx object. - let tx = WithOtherFields::new( - TransactionRequest::default() - .to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address()) - .input(data.clone().into()), - ); - let tx_zk = alloy_zksync::network::transaction_request::TransactionRequest::default().base( - TransactionRequest::default() - .to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address()) - .input(data.into()), - ); - - Ok(Deployer { - client: self.client.clone(), - abi: self.abi, - tx, - tx_zk, - confs: 1, - timeout: self.timeout, - zk_factory_deps: Some(vec![zk_data.bytecode.clone()]), - _p: PhantomData, - _t: PhantomData, - }) - } } impl DeploymentTxFactory @@ -1291,7 +1034,7 @@ where self, params: Vec, zk_data: &ZkSyncData, - ) -> Result, ContractDeploymentError> + ) -> Result, ContractDeploymentError> where B: Clone, { @@ -1313,18 +1056,16 @@ where .into(); // create the tx object. Since we're deploying a contract, `to` is `None` - let tx = WithOtherFields::new(TransactionRequest::default().input(data.clone().into())); - let tx_zk = alloy_zksync::network::transaction_request::TransactionRequest::default().base( + let tx = alloy_zksync::network::transaction_request::TransactionRequest::default().base( TransactionRequest::default() .to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address()) .input(data.into()), ); - Ok(Deployer { + Ok(ZkDeployer { client: self.client.clone(), abi: self.abi, tx, - tx_zk, confs: 1, timeout: self.timeout, zk_factory_deps: None, From 393dd6d0231768d9da4332f5e4402cf54a175e9b Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Sat, 12 Oct 2024 00:24:09 +0200 Subject: [PATCH 03/13] cleanup debug code --- crates/zksync/core/src/lib.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/crates/zksync/core/src/lib.rs b/crates/zksync/core/src/lib.rs index 16089170e..a0d8a689b 100644 --- a/crates/zksync/core/src/lib.rs +++ b/crates/zksync/core/src/lib.rs @@ -198,11 +198,7 @@ pub async fn estimate_gas, T: Transport + Clone>( provider.get_gas_price().await? }; let data = tx.input.clone().into_input().unwrap_or_default(); - for d in &factory_deps { - println!("{}", hex::encode(&d)); - } let custom_data = Eip712Meta::new().factory_deps(factory_deps); - let custom_data_min = Eip712Meta::new(); let mut deploy_request = Eip712TransactionRequest::new() .r#type(EIP712_TX_TYPE) @@ -211,14 +207,11 @@ pub async fn estimate_gas, T: Transport + Clone>( .nonce(nonce) .gas_price(gas_price) .data(data.to_ethers()) - .custom_data(custom_data_min); + .custom_data(custom_data); if let Some(from) = tx.from { deploy_request = deploy_request.from(from.to_h160()) } - println!("{}", serde_json::to_string_pretty(&deploy_request).unwrap()); - deploy_request = deploy_request.custom_data(custom_data); - let gas_price = provider.get_gas_price().await.unwrap(); let fee: Fee = provider .raw_request("zks_estimateFee".into(), [deploy_request.clone()]) From b31eb9d99ef94b488802ad649ba1feb97388d951 Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Tue, 5 Nov 2024 09:04:30 +0100 Subject: [PATCH 04/13] update alloy-zksync, include paymaster --- Cargo.lock | 24 +++++++++++++++++++----- Cargo.toml | 2 +- crates/forge/bin/cmd/create.rs | 3 +++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b81a56777..1d685904b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -96,9 +96,9 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "alloy" -version = "0.3.6" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8367891bf380210abb0d6aa30c5f85a9080cb4a066c4d5c5acadad630823751b" +checksum = "056f2c01b2aed86e15b43c47d109bfc8b82553dc34e66452875e51247ec31ab2" dependencies = [ "alloy-consensus", "alloy-contract", @@ -166,6 +166,19 @@ dependencies = [ "thiserror", ] +[[package]] +name = "alloy-core" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeb750349efda145ca6aada68d0336067f7f364d7d44ef09e2cf000b040c5e99" +dependencies = [ + "alloy-dyn-abi", + "alloy-json-abi", + "alloy-primitives", + "alloy-rlp", + "alloy-sol-types", +] + [[package]] name = "alloy-dyn-abi" version = "0.8.8" @@ -788,13 +801,14 @@ dependencies = [ [[package]] name = "alloy-zksync" version = "0.1.0" -source = "git+https://github.com/nbaztec/alloy-zksync?branch=v0.3.6#0adab979cf081350a9c0d7a42d4e8905a39d8c92" +source = "git+https://github.com/popzxc/alloy-zksync?branch=main#d454818e7afd3a79d3ab3b5bc2875ba6c855e825" dependencies = [ "alloy", "async-trait", "futures-utils-wasm", - "k256 0.13.3", + "k256 0.13.4", "rand 0.8.5", + "reqwest 0.12.8", "serde", "thiserror", "tracing", @@ -8433,7 +8447,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate 3.2.0", "proc-macro2 1.0.88", "quote 1.0.37", "syn 2.0.79", diff --git a/Cargo.toml b/Cargo.toml index 8370a091e..7d634e0cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -231,7 +231,7 @@ alloy-chains = "0.1" alloy-rlp = "0.3" alloy-trie = "0.6.0" # alloy-zksync = "0.1.0" -alloy-zksync = { git = "https://github.com/nbaztec/alloy-zksync", branch = "v0.3.6"} +alloy-zksync = { git = "https://github.com/popzxc/alloy-zksync", branch = "main"} ## op-alloy op-alloy-rpc-types = "0.3.3" diff --git a/crates/forge/bin/cmd/create.rs b/crates/forge/bin/cmd/create.rs index 6aedaa2d8..75ec9e865 100644 --- a/crates/forge/bin/cmd/create.rs +++ b/crates/forge/bin/cmd/create.rs @@ -592,6 +592,9 @@ impl CreateArgs { .with_factory_deps( zk_data.factory_deps.clone().into_iter().map(|dep| dep.into()).collect(), ); + if let Some(paymaster_params) = zk_data.paymaster_params { + deployer.tx.set_paymaster(paymaster_params); + } deployer.tx.set_from(deployer_address); deployer.tx.set_chain_id(chain); // `to` field must be set explicitly, cannot be None. From 904767336378f847ee846df0f82865b99008754d Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Tue, 19 Nov 2024 11:21:26 +0100 Subject: [PATCH 05/13] remove zksync-web3-rs --- Cargo.lock | 1498 +++++----------------- Cargo.toml | 6 +- crates/cast/Cargo.toml | 4 +- crates/cast/bin/cmd/send.rs | 79 +- crates/cast/src/lib.rs | 69 + crates/cheatcodes/Cargo.toml | 1 - crates/cheatcodes/src/inspector.rs | 2 +- crates/cli/Cargo.toml | 1 - crates/cli/src/opts/build/zksync.rs | 2 +- crates/common/src/provider/mod.rs | 6 + crates/forge/Cargo.toml | 1 - crates/forge/bin/cmd/create.rs | 27 +- crates/script/Cargo.toml | 4 +- crates/script/src/broadcast.rs | 133 +- crates/zksync/core/Cargo.toml | 5 - crates/zksync/core/src/convert.rs | 67 - crates/zksync/core/src/convert/eip712.rs | 242 ---- crates/zksync/core/src/lib.rs | 123 +- crates/zksync/core/src/utils.rs | 2 +- deny.toml | 2 - 20 files changed, 505 insertions(+), 1769 deletions(-) delete mode 100644 crates/zksync/core/src/convert/eip712.rs diff --git a/Cargo.lock b/Cargo.lock index f2e6f7779..717976217 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -96,27 +96,27 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "alloy" -version = "0.4.2" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "056f2c01b2aed86e15b43c47d109bfc8b82553dc34e66452875e51247ec31ab2" +checksum = "ea8ebf106e84a1c37f86244df7da0c7587e697b71a0d565cce079449b85ac6f8" dependencies = [ - "alloy-consensus 0.4.2", - "alloy-contract 0.4.2", + "alloy-consensus", + "alloy-contract", "alloy-core", - "alloy-eips 0.4.2", - "alloy-genesis 0.4.2", - "alloy-network 0.4.2", - "alloy-provider 0.4.2", - "alloy-pubsub 0.4.2", - "alloy-rpc-client 0.4.2", - "alloy-rpc-types 0.4.2", - "alloy-serde 0.4.2", - "alloy-signer 0.4.2", - "alloy-signer-local 0.4.2", - "alloy-transport 0.4.2", - "alloy-transport-http 0.4.2", - "alloy-transport-ipc 0.4.2", - "alloy-transport-ws 0.4.2", + "alloy-eips", + "alloy-genesis", + "alloy-network", + "alloy-provider", + "alloy-pubsub", + "alloy-rpc-client", + "alloy-rpc-types", + "alloy-serde", + "alloy-signer", + "alloy-signer-local", + "alloy-transport", + "alloy-transport-http", + "alloy-transport-ipc", + "alloy-transport-ws", ] [[package]] @@ -131,58 +131,21 @@ dependencies = [ "strum", ] -[[package]] -name = "alloy-consensus" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "705687d5bfd019fee57cf9e206b27b30a9a9617535d5590a02b171e813208f8e" -dependencies = [ - "alloy-eips 0.4.2", - "alloy-primitives", - "alloy-rlp", - "alloy-serde 0.4.2", - "auto_impl", - "c-kzg", - "derive_more 1.0.0", - "serde", -] - [[package]] name = "alloy-consensus" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ - "alloy-eips 0.5.4", + "alloy-eips", "alloy-primitives", "alloy-rlp", - "alloy-serde 0.5.4", + "alloy-serde", "auto_impl", "c-kzg", "derive_more 1.0.0", "serde", ] -[[package]] -name = "alloy-contract" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "917f7d12cf3971dc8c11c9972f732b35ccb9aaaf5f28f2f87e9e6523bee3a8ad" -dependencies = [ - "alloy-dyn-abi", - "alloy-json-abi", - "alloy-network 0.4.2", - "alloy-network-primitives 0.4.2", - "alloy-primitives", - "alloy-provider 0.4.2", - "alloy-pubsub 0.4.2", - "alloy-rpc-types-eth 0.4.2", - "alloy-sol-types", - "alloy-transport 0.4.2", - "futures 0.3.31", - "futures-util", - "thiserror", -] - [[package]] name = "alloy-contract" version = "0.5.4" @@ -190,14 +153,14 @@ source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f14 dependencies = [ "alloy-dyn-abi", "alloy-json-abi", - "alloy-network 0.5.4", - "alloy-network-primitives 0.5.4", + "alloy-network", + "alloy-network-primitives", "alloy-primitives", - "alloy-provider 0.5.4", - "alloy-pubsub 0.5.4", - "alloy-rpc-types-eth 0.5.4", + "alloy-provider", + "alloy-pubsub", + "alloy-rpc-types-eth", "alloy-sol-types", - "alloy-transport 0.5.4", + "alloy-transport", "futures 0.3.31", "futures-util", "thiserror", @@ -250,18 +213,6 @@ dependencies = [ "serde", ] -[[package]] -name = "alloy-eip7702" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea59dc42102bc9a1905dc57901edc6dd48b9f38115df86c7d252acba70d71d04" -dependencies = [ - "alloy-primitives", - "alloy-rlp", - "k256 0.13.4", - "serde", -] - [[package]] name = "alloy-eip7702" version = "0.3.2" @@ -277,34 +228,16 @@ dependencies = [ "serde", ] -[[package]] -name = "alloy-eips" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ffb906284a1e1f63c4607da2068c8197458a352d0b3e9796e67353d72a9be85" -dependencies = [ - "alloy-eip2930", - "alloy-eip7702 0.1.1", - "alloy-primitives", - "alloy-rlp", - "alloy-serde 0.4.2", - "c-kzg", - "derive_more 1.0.0", - "once_cell", - "serde", - "sha2 0.10.8", -] - [[package]] name = "alloy-eips" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ "alloy-eip2930", - "alloy-eip7702 0.3.2", + "alloy-eip7702", "alloy-primitives", "alloy-rlp", - "alloy-serde 0.5.4", + "alloy-serde", "c-kzg", "derive_more 1.0.0", "once_cell", @@ -312,24 +245,13 @@ dependencies = [ "sha2 0.10.8", ] -[[package]] -name = "alloy-genesis" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8429cf4554eed9b40feec7f4451113e76596086447550275e3def933faf47ce3" -dependencies = [ - "alloy-primitives", - "alloy-serde 0.4.2", - "serde", -] - [[package]] name = "alloy-genesis" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ "alloy-primitives", - "alloy-serde 0.5.4", + "alloy-serde", "serde", ] @@ -345,20 +267,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "alloy-json-rpc" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8fa8a1a3c4cbd221f2b8e3693aeb328fca79a757fe556ed08e47bbbc2a70db7" -dependencies = [ - "alloy-primitives", - "alloy-sol-types", - "serde", - "serde_json", - "thiserror", - "tracing", -] - [[package]] name = "alloy-json-rpc" version = "0.5.4" @@ -372,40 +280,19 @@ dependencies = [ "tracing", ] -[[package]] -name = "alloy-network" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85fa23a6a9d612b52e402c995f2d582c25165ec03ac6edf64c861a76bc5b87cd" -dependencies = [ - "alloy-consensus 0.4.2", - "alloy-eips 0.4.2", - "alloy-json-rpc 0.4.2", - "alloy-network-primitives 0.4.2", - "alloy-primitives", - "alloy-rpc-types-eth 0.4.2", - "alloy-serde 0.4.2", - "alloy-signer 0.4.2", - "alloy-sol-types", - "async-trait", - "auto_impl", - "futures-utils-wasm", - "thiserror", -] - [[package]] name = "alloy-network" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ - "alloy-consensus 0.5.4", - "alloy-eips 0.5.4", - "alloy-json-rpc 0.5.4", - "alloy-network-primitives 0.5.4", + "alloy-consensus", + "alloy-eips", + "alloy-json-rpc", + "alloy-network-primitives", "alloy-primitives", - "alloy-rpc-types-eth 0.5.4", - "alloy-serde 0.5.4", - "alloy-signer 0.5.4", + "alloy-rpc-types-eth", + "alloy-serde", + "alloy-signer", "alloy-sol-types", "async-trait", "auto_impl", @@ -413,28 +300,15 @@ dependencies = [ "thiserror", ] -[[package]] -name = "alloy-network-primitives" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "801492711d4392b2ccf5fc0bc69e299fa1aab15167d74dcaa9aab96a54f684bd" -dependencies = [ - "alloy-consensus 0.4.2", - "alloy-eips 0.4.2", - "alloy-primitives", - "alloy-serde 0.4.2", - "serde", -] - [[package]] name = "alloy-network-primitives" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ - "alloy-consensus 0.5.4", - "alloy-eips 0.5.4", + "alloy-consensus", + "alloy-eips", "alloy-primitives", - "alloy-serde 0.5.4", + "alloy-serde", "serde", ] @@ -470,64 +344,27 @@ dependencies = [ "tiny-keccak 2.0.2", ] -[[package]] -name = "alloy-provider" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcfaa4ffec0af04e3555686b8aacbcdf7d13638133a0672749209069750f78a6" -dependencies = [ - "alloy-chains", - "alloy-consensus 0.4.2", - "alloy-eips 0.4.2", - "alloy-json-rpc 0.4.2", - "alloy-network 0.4.2", - "alloy-network-primitives 0.4.2", - "alloy-primitives", - "alloy-pubsub 0.4.2", - "alloy-rpc-client 0.4.2", - "alloy-rpc-types-eth 0.4.2", - "alloy-transport 0.4.2", - "alloy-transport-http 0.4.2", - "alloy-transport-ipc 0.4.2", - "alloy-transport-ws 0.4.2", - "async-stream", - "async-trait", - "auto_impl", - "dashmap 6.1.0", - "futures 0.3.31", - "futures-utils-wasm", - "lru", - "pin-project 1.1.7", - "reqwest 0.12.9", - "serde", - "serde_json", - "thiserror", - "tokio", - "tracing", - "url", -] - [[package]] name = "alloy-provider" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ "alloy-chains", - "alloy-consensus 0.5.4", - "alloy-eips 0.5.4", - "alloy-json-rpc 0.5.4", - "alloy-network 0.5.4", - "alloy-network-primitives 0.5.4", + "alloy-consensus", + "alloy-eips", + "alloy-json-rpc", + "alloy-network", + "alloy-network-primitives", "alloy-primitives", - "alloy-pubsub 0.5.4", - "alloy-rpc-client 0.5.4", - "alloy-rpc-types-eth 0.5.4", + "alloy-pubsub", + "alloy-rpc-client", + "alloy-rpc-types-eth", "alloy-rpc-types-trace", "alloy-rpc-types-txpool", - "alloy-transport 0.5.4", - "alloy-transport-http 0.5.4", - "alloy-transport-ipc 0.5.4", - "alloy-transport-ws 0.5.4", + "alloy-transport", + "alloy-transport-http", + "alloy-transport-ipc", + "alloy-transport-ws", "async-stream", "async-trait", "auto_impl", @@ -548,33 +385,14 @@ dependencies = [ "wasmtimer", ] -[[package]] -name = "alloy-pubsub" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f32cef487122ae75c91eb50154c70801d71fabdb976fec6c49e0af5e6486ab15" -dependencies = [ - "alloy-json-rpc 0.4.2", - "alloy-primitives", - "alloy-transport 0.4.2", - "bimap", - "futures 0.3.31", - "serde", - "serde_json", - "tokio", - "tokio-stream", - "tower 0.5.1", - "tracing", -] - [[package]] name = "alloy-pubsub" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ - "alloy-json-rpc 0.5.4", + "alloy-json-rpc", "alloy-primitives", - "alloy-transport 0.5.4", + "alloy-transport", "bimap", "futures 0.3.31", "serde", @@ -607,43 +425,18 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "alloy-rpc-client" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "370143ed581aace6e663342d21d209c6b2e34ee6142f7d6675adb518deeaf0dc" -dependencies = [ - "alloy-json-rpc 0.4.2", - "alloy-primitives", - "alloy-pubsub 0.4.2", - "alloy-transport 0.4.2", - "alloy-transport-http 0.4.2", - "alloy-transport-ipc 0.4.2", - "alloy-transport-ws 0.4.2", - "futures 0.3.31", - "pin-project 1.1.7", - "reqwest 0.12.9", - "serde", - "serde_json", - "tokio", - "tokio-stream", - "tower 0.5.1", - "tracing", - "url", -] - [[package]] name = "alloy-rpc-client" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ - "alloy-json-rpc 0.5.4", + "alloy-json-rpc", "alloy-primitives", - "alloy-pubsub 0.5.4", - "alloy-transport 0.5.4", - "alloy-transport-http 0.5.4", - "alloy-transport-ipc 0.5.4", - "alloy-transport-ws 0.5.4", + "alloy-pubsub", + "alloy-transport", + "alloy-transport-http", + "alloy-transport-ipc", + "alloy-transport-ws", "futures 0.3.31", "pin-project 1.1.7", "reqwest 0.12.9", @@ -657,19 +450,6 @@ dependencies = [ "wasmtimer", ] -[[package]] -name = "alloy-rpc-types" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ffc534b7919e18f35e3aa1f507b6f3d9d92ec298463a9f6beaac112809d8d06" -dependencies = [ - "alloy-primitives", - "alloy-rpc-types-engine 0.4.2", - "alloy-rpc-types-eth 0.4.2", - "alloy-serde 0.4.2", - "serde", -] - [[package]] name = "alloy-rpc-types" version = "0.5.4" @@ -677,11 +457,11 @@ source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f14 dependencies = [ "alloy-primitives", "alloy-rpc-types-anvil", - "alloy-rpc-types-engine 0.5.4", - "alloy-rpc-types-eth 0.5.4", + "alloy-rpc-types-engine", + "alloy-rpc-types-eth", "alloy-rpc-types-trace", "alloy-rpc-types-txpool", - "alloy-serde 0.5.4", + "alloy-serde", "serde", ] @@ -691,71 +471,38 @@ version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ "alloy-primitives", - "alloy-serde 0.5.4", + "alloy-serde", "serde", ] -[[package]] -name = "alloy-rpc-types-engine" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0285c4c09f838ab830048b780d7f4a4f460f309aa1194bb049843309524c64c" -dependencies = [ - "alloy-consensus 0.4.2", - "alloy-eips 0.4.2", - "alloy-primitives", - "alloy-rlp", - "derive_more 1.0.0", - "strum", -] - [[package]] name = "alloy-rpc-types-engine" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ - "alloy-consensus 0.5.4", - "alloy-eips 0.5.4", + "alloy-consensus", + "alloy-eips", "alloy-primitives", "alloy-rlp", - "alloy-serde 0.5.4", + "alloy-serde", "derive_more 1.0.0", - "jsonwebtoken 9.3.0", + "jsonwebtoken", "rand 0.8.5", "serde", "strum", ] -[[package]] -name = "alloy-rpc-types-eth" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413f4aa3ccf2c3e4234a047c5fa4727916d7daf25a89f9b765df0ba09784fd87" -dependencies = [ - "alloy-consensus 0.4.2", - "alloy-eips 0.4.2", - "alloy-network-primitives 0.4.2", - "alloy-primitives", - "alloy-rlp", - "alloy-serde 0.4.2", - "alloy-sol-types", - "derive_more 1.0.0", - "itertools 0.13.0", - "serde", - "serde_json", -] - [[package]] name = "alloy-rpc-types-eth" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ - "alloy-consensus 0.5.4", - "alloy-eips 0.5.4", - "alloy-network-primitives 0.5.4", + "alloy-consensus", + "alloy-eips", + "alloy-network-primitives", "alloy-primitives", "alloy-rlp", - "alloy-serde 0.5.4", + "alloy-serde", "alloy-sol-types", "derive_more 1.0.0", "itertools 0.13.0", @@ -769,8 +516,8 @@ version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ "alloy-primitives", - "alloy-rpc-types-eth 0.5.4", - "alloy-serde 0.5.4", + "alloy-rpc-types-eth", + "alloy-serde", "serde", "serde_json", "thiserror", @@ -782,22 +529,11 @@ version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ "alloy-primitives", - "alloy-rpc-types-eth 0.5.4", - "alloy-serde 0.5.4", + "alloy-rpc-types-eth", + "alloy-serde", "serde", ] -[[package]] -name = "alloy-serde" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dff0ab1cdd43ca001e324dc27ee0e8606bd2161d6623c63e0e0b8c4dfc13600" -dependencies = [ - "alloy-primitives", - "serde", - "serde_json", -] - [[package]] name = "alloy-serde" version = "0.5.4" @@ -808,20 +544,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "alloy-signer" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd4e0ad79c81a27ca659be5d176ca12399141659fef2bcbfdc848da478f4504" -dependencies = [ - "alloy-primitives", - "async-trait", - "auto_impl", - "elliptic-curve 0.13.8", - "k256 0.13.4", - "thiserror", -] - [[package]] name = "alloy-signer" version = "0.5.4" @@ -842,10 +564,10 @@ name = "alloy-signer-aws" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ - "alloy-consensus 0.5.4", - "alloy-network 0.5.4", + "alloy-consensus", + "alloy-network", "alloy-primitives", - "alloy-signer 0.5.4", + "alloy-signer", "async-trait", "aws-sdk-kms", "k256 0.13.4", @@ -859,10 +581,10 @@ name = "alloy-signer-gcp" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ - "alloy-consensus 0.5.4", - "alloy-network 0.5.4", + "alloy-consensus", + "alloy-network", "alloy-primitives", - "alloy-signer 0.5.4", + "alloy-signer", "async-trait", "gcloud-sdk", "k256 0.13.4", @@ -876,11 +598,11 @@ name = "alloy-signer-ledger" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ - "alloy-consensus 0.5.4", + "alloy-consensus", "alloy-dyn-abi", - "alloy-network 0.5.4", + "alloy-network", "alloy-primitives", - "alloy-signer 0.5.4", + "alloy-signer", "alloy-sol-types", "async-trait", "coins-ledger", @@ -890,34 +612,18 @@ dependencies = [ "tracing", ] -[[package]] -name = "alloy-signer-local" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "494e0a256f3e99f2426f994bcd1be312c02cb8f88260088dacb33a8b8936475f" -dependencies = [ - "alloy-consensus 0.4.2", - "alloy-network 0.4.2", - "alloy-primitives", - "alloy-signer 0.4.2", - "async-trait", - "k256 0.13.4", - "rand 0.8.5", - "thiserror", -] - [[package]] name = "alloy-signer-local" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ - "alloy-consensus 0.5.4", - "alloy-network 0.5.4", + "alloy-consensus", + "alloy-network", "alloy-primitives", - "alloy-signer 0.5.4", + "alloy-signer", "async-trait", - "coins-bip32 0.12.0", - "coins-bip39 0.12.0", + "coins-bip32", + "coins-bip39", "eth-keystore", "k256 0.13.4", "rand 0.8.5", @@ -929,10 +635,10 @@ name = "alloy-signer-trezor" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ - "alloy-consensus 0.5.4", - "alloy-network 0.5.4", + "alloy-consensus", + "alloy-network", "alloy-primitives", - "alloy-signer 0.5.4", + "alloy-signer", "async-trait", "semver 1.0.23", "thiserror", @@ -1013,31 +719,12 @@ dependencies = [ "serde", ] -[[package]] -name = "alloy-transport" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ac3e97dad3d31770db0fc89bd6a63b789fbae78963086733f960cf32c483904" -dependencies = [ - "alloy-json-rpc 0.4.2", - "base64 0.22.1", - "futures-util", - "futures-utils-wasm", - "serde", - "serde_json", - "thiserror", - "tokio", - "tower 0.5.1", - "tracing", - "url", -] - [[package]] name = "alloy-transport" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ - "alloy-json-rpc 0.5.4", + "alloy-json-rpc", "base64 0.22.1", "futures-util", "futures-utils-wasm", @@ -1051,52 +738,18 @@ dependencies = [ "wasmtimer", ] -[[package]] -name = "alloy-transport-http" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b367dcccada5b28987c2296717ee04b9a5637aacd78eacb1726ef211678b5212" -dependencies = [ - "alloy-json-rpc 0.4.2", - "alloy-transport 0.4.2", - "reqwest 0.12.9", - "serde_json", - "tower 0.5.1", - "tracing", - "url", -] - [[package]] name = "alloy-transport-http" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#31bccc864525b5ba64fefb8211363807c7a43d2d" dependencies = [ - "alloy-json-rpc 0.5.4", - "alloy-transport 0.5.4", + "alloy-json-rpc", + "alloy-transport", "reqwest 0.12.9", - "serde_json", - "tower 0.5.1", - "tracing", - "url", -] - -[[package]] -name = "alloy-transport-ipc" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b90cf9cde7f2fce617da52768ee28f522264b282d148384a4ca0ea85af04fa3a" -dependencies = [ - "alloy-json-rpc 0.4.2", - "alloy-pubsub 0.4.2", - "alloy-transport 0.4.2", - "bytes", - "futures 0.3.31", - "interprocess", - "pin-project 1.1.7", - "serde_json", - "tokio", - "tokio-util 0.7.12", + "serde_json", + "tower 0.5.1", "tracing", + "url", ] [[package]] @@ -1104,9 +757,9 @@ name = "alloy-transport-ipc" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#31bccc864525b5ba64fefb8211363807c7a43d2d" dependencies = [ - "alloy-json-rpc 0.5.4", - "alloy-pubsub 0.5.4", - "alloy-transport 0.5.4", + "alloy-json-rpc", + "alloy-pubsub", + "alloy-transport", "bytes", "futures 0.3.31", "interprocess", @@ -1119,37 +772,19 @@ dependencies = [ "tracing", ] -[[package]] -name = "alloy-transport-ws" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7153b88690de6a50bba81c11e1d706bc41dbb90126d607404d60b763f6a3947f" -dependencies = [ - "alloy-pubsub 0.4.2", - "alloy-transport 0.4.2", - "futures 0.3.31", - "http 1.1.0", - "rustls 0.23.16", - "serde_json", - "tokio", - "tokio-tungstenite 0.24.0", - "tracing", - "ws_stream_wasm", -] - [[package]] name = "alloy-transport-ws" version = "0.5.4" source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#31bccc864525b5ba64fefb8211363807c7a43d2d" dependencies = [ - "alloy-pubsub 0.5.4", - "alloy-transport 0.5.4", + "alloy-pubsub", + "alloy-transport", "futures 0.3.31", "http 1.1.0", "rustls 0.23.16", "serde_json", "tokio", - "tokio-tungstenite 0.24.0", + "tokio-tungstenite", "tracing", "ws_stream_wasm", ] @@ -1171,11 +806,11 @@ dependencies = [ [[package]] name = "alloy-zksync" -version = "0.1.0" -source = "git+https://github.com/popzxc/alloy-zksync?branch=main#d454818e7afd3a79d3ab3b5bc2875ba6c855e825" +version = "0.5.0" dependencies = [ "alloy", "async-trait", + "chrono", "futures-utils-wasm", "k256 0.13.4", "rand 0.8.5", @@ -1277,27 +912,27 @@ name = "anvil" version = "0.0.2" dependencies = [ "alloy-chains", - "alloy-consensus 0.5.4", - "alloy-contract 0.5.4", + "alloy-consensus", + "alloy-contract", "alloy-dyn-abi", - "alloy-eips 0.5.4", - "alloy-genesis 0.5.4", + "alloy-eips", + "alloy-genesis", "alloy-json-abi", - "alloy-json-rpc 0.5.4", - "alloy-network 0.5.4", + "alloy-json-rpc", + "alloy-network", "alloy-primitives", - "alloy-provider 0.5.4", - "alloy-pubsub 0.5.4", + "alloy-provider", + "alloy-pubsub", "alloy-rlp", - "alloy-rpc-client 0.5.4", - "alloy-rpc-types 0.5.4", - "alloy-serde 0.5.4", - "alloy-signer 0.5.4", - "alloy-signer-local 0.5.4", + "alloy-rpc-client", + "alloy-rpc-types", + "alloy-serde", + "alloy-signer", + "alloy-signer-local", "alloy-sol-types", - "alloy-transport 0.5.4", - "alloy-transport-ipc 0.5.4", - "alloy-transport-ws 0.5.4", + "alloy-transport", + "alloy-transport-ipc", + "alloy-transport-ws", "alloy-trie", "anvil-core", "anvil-rpc", @@ -1339,20 +974,20 @@ dependencies = [ "tracing", "tracing-subscriber", "vergen", - "yansi 1.0.1", + "yansi", ] [[package]] name = "anvil-core" version = "0.0.2" dependencies = [ - "alloy-consensus 0.5.4", + "alloy-consensus", "alloy-dyn-abi", - "alloy-eips 0.5.4", + "alloy-eips", "alloy-primitives", "alloy-rlp", - "alloy-rpc-types 0.5.4", - "alloy-serde 0.5.4", + "alloy-rpc-types", + "alloy-serde", "alloy-trie", "bytes", "foundry-common", @@ -1416,7 +1051,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44055e597c674aef7cb903b2b9f6e4cba1277ed0d2d61dae7cd52d7ffa81f8e2" dependencies = [ "unicode-width 0.1.14", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -1756,7 +1391,7 @@ dependencies = [ "fastrand", "hex", "http 0.2.12", - "ring 0.17.8", + "ring", "time", "tokio", "tracing", @@ -2110,7 +1745,7 @@ dependencies = [ "sha1", "sync_wrapper 1.0.1", "tokio", - "tokio-tungstenite 0.24.0", + "tokio-tungstenite", "tower 0.5.1", "tower-layer", "tower-service", @@ -2725,21 +2360,22 @@ name = "cast" version = "0.0.2" dependencies = [ "alloy-chains", - "alloy-consensus 0.5.4", - "alloy-contract 0.5.4", + "alloy-consensus", + "alloy-contract", "alloy-dyn-abi", "alloy-json-abi", - "alloy-json-rpc 0.5.4", - "alloy-network 0.5.4", + "alloy-json-rpc", + "alloy-network", "alloy-primitives", - "alloy-provider 0.5.4", + "alloy-provider", "alloy-rlp", - "alloy-rpc-types 0.5.4", - "alloy-serde 0.5.4", - "alloy-signer 0.5.4", - "alloy-signer-local 0.5.4", + "alloy-rpc-types", + "alloy-serde", + "alloy-signer", + "alloy-signer-local", "alloy-sol-types", - "alloy-transport 0.5.4", + "alloy-transport", + "alloy-zksync", "anvil", "async-trait", "aws-sdk-kms", @@ -2776,8 +2412,8 @@ dependencies = [ "tokio", "tracing", "vergen", - "yansi 1.0.1", - "zksync-web3-rs", + "yansi", + "zksync_types", ] [[package]] @@ -2846,7 +2482,7 @@ dependencies = [ "alloy-dyn-abi", "alloy-json-abi", "alloy-primitives", - "alloy-rpc-types 0.5.4", + "alloy-rpc-types", "clap", "dirs 5.0.1", "eyre", @@ -2873,7 +2509,7 @@ dependencies = [ "tracing", "tracing-subscriber", "vergen", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -3162,22 +2798,6 @@ dependencies = [ "cc", ] -[[package]] -name = "coins-bip32" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b6be4a5df2098cd811f3194f64ddb96c267606bffd9689ac7b0160097b01ad3" -dependencies = [ - "bs58", - "coins-core 0.8.7", - "digest 0.10.7", - "hmac", - "k256 0.13.4", - "serde", - "sha2 0.10.8", - "thiserror", -] - [[package]] name = "coins-bip32" version = "0.12.0" @@ -3185,7 +2805,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2073678591747aed4000dd468b97b14d7007f7936851d3f2f01846899f5ebf08" dependencies = [ "bs58", - "coins-core 0.12.0", + "coins-core", "digest 0.10.7", "hmac", "k256 0.13.4", @@ -3194,22 +2814,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "coins-bip39" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3db8fba409ce3dc04f7d804074039eb68b960b0829161f8e06c95fea3f122528" -dependencies = [ - "bitvec 1.0.1", - "coins-bip32 0.8.7", - "hmac", - "once_cell", - "pbkdf2 0.12.2", - "rand 0.8.5", - "sha2 0.10.8", - "thiserror", -] - [[package]] name = "coins-bip39" version = "0.12.0" @@ -3217,7 +2821,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74b169b26623ff17e9db37a539fe4f15342080df39f129ef7631df7683d6d9d4" dependencies = [ "bitvec 1.0.1", - "coins-bip32 0.12.0", + "coins-bip32", "hmac", "once_cell", "pbkdf2 0.12.2", @@ -3226,26 +2830,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "coins-core" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5286a0843c21f8367f7be734f89df9b822e0321d8bcce8d6e735aadff7d74979" -dependencies = [ - "base64 0.21.7", - "bech32", - "bs58", - "digest 0.10.7", - "generic-array", - "hex", - "ripemd", - "serde", - "serde_derive", - "sha2 0.10.8", - "sha3 0.10.8", - "thiserror", -] - [[package]] name = "coins-core" version = "0.12.0" @@ -4301,24 +3885,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" -[[package]] -name = "enr" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a3d8dc56e02f954cac8eb489772c552c473346fc34f67412bb6244fd647f7e4" -dependencies = [ - "base64 0.21.7", - "bytes", - "hex", - "k256 0.13.4", - "log", - "rand 0.8.5", - "rlp", - "serde", - "sha3 0.10.8", - "zeroize", -] - [[package]] name = "enum_dispatch" version = "0.3.13" @@ -4352,19 +3918,6 @@ dependencies = [ "regex", ] -[[package]] -name = "env_logger" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" -dependencies = [ - "humantime", - "is-terminal", - "log", - "regex", - "termcolor", -] - [[package]] name = "env_logger" version = "0.11.5" @@ -4581,252 +4134,56 @@ dependencies = [ "uint", ] -[[package]] -name = "ethers" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "816841ea989f0c69e459af1cf23a6b0033b19a55424a1ea3a30099becdb8dec0" -dependencies = [ - "ethers-addressbook", - "ethers-contract", - "ethers-core", - "ethers-etherscan", - "ethers-middleware", - "ethers-providers", - "ethers-signers", - "ethers-solc", -] - -[[package]] -name = "ethers-addressbook" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5495afd16b4faa556c3bba1f21b98b4983e53c1755022377051a975c3b021759" -dependencies = [ - "ethers-core", - "once_cell", - "serde", - "serde_json", -] - -[[package]] -name = "ethers-contract" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fceafa3578c836eeb874af87abacfb041f92b4da0a78a5edd042564b8ecdaaa" -dependencies = [ - "const-hex", - "ethers-contract-abigen", - "ethers-contract-derive", - "ethers-core", - "ethers-providers", - "futures-util", - "once_cell", - "pin-project 1.1.7", - "serde", - "serde_json", - "thiserror", -] - [[package]] name = "ethers-contract-abigen" version = "2.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04ba01fbc2331a38c429eb95d4a570166781f14290ef9fdb144278a90b5a739b" dependencies = [ - "Inflector", - "const-hex", - "dunce", - "ethers-core", - "ethers-etherscan", - "eyre", - "prettyplease", - "proc-macro2 1.0.89", - "quote 1.0.37", - "regex", - "reqwest 0.11.27", - "serde", - "serde_json", - "syn 2.0.87", - "toml 0.8.19", - "walkdir", -] - -[[package]] -name = "ethers-contract-derive" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87689dcabc0051cde10caaade298f9e9093d65f6125c14575db3fd8c669a168f" -dependencies = [ - "Inflector", - "const-hex", - "ethers-contract-abigen", - "ethers-core", - "proc-macro2 1.0.89", - "quote 1.0.37", - "serde_json", - "syn 2.0.87", -] - -[[package]] -name = "ethers-core" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82d80cc6ad30b14a48ab786523af33b37f28a8623fc06afd55324816ef18fb1f" -dependencies = [ - "arrayvec 0.7.6", - "bytes", - "cargo_metadata 0.18.1", - "chrono", - "const-hex", - "elliptic-curve 0.13.8", - "ethabi 18.0.0", - "generic-array", - "k256 0.13.4", - "num_enum 0.7.3", - "once_cell", - "open-fastrlp", - "rand 0.8.5", - "rlp", - "serde", - "serde_json", - "strum", - "syn 2.0.87", - "tempfile", - "thiserror", - "tiny-keccak 2.0.2", - "unicode-xid 0.2.6", -] - -[[package]] -name = "ethers-etherscan" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e79e5973c26d4baf0ce55520bd732314328cabe53193286671b47144145b9649" -dependencies = [ - "chrono", - "ethers-core", - "reqwest 0.11.27", - "semver 1.0.23", - "serde", - "serde_json", - "thiserror", - "tracing", -] - -[[package]] -name = "ethers-middleware" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48f9fdf09aec667c099909d91908d5eaf9be1bd0e2500ba4172c1d28bfaa43de" -dependencies = [ - "async-trait", - "auto_impl", - "ethers-contract", - "ethers-core", - "ethers-etherscan", - "ethers-providers", - "ethers-signers", - "futures-channel", - "futures-locks", - "futures-util", - "instant", - "reqwest 0.11.27", - "serde", - "serde_json", - "thiserror", - "tokio", - "tracing", - "tracing-futures", - "url", -] - -[[package]] -name = "ethers-providers" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6434c9a33891f1effc9c75472e12666db2fa5a0fec4b29af6221680a6fe83ab2" -dependencies = [ - "async-trait", - "auto_impl", - "base64 0.21.7", - "bytes", - "const-hex", - "enr", - "ethers-core", - "futures-core", - "futures-timer", - "futures-util", - "hashers", - "http 0.2.12", - "instant", - "jsonwebtoken 8.3.0", - "once_cell", - "pin-project 1.1.7", - "reqwest 0.11.27", - "serde", - "serde_json", - "thiserror", - "tokio", - "tokio-tungstenite 0.20.1", - "tracing", - "tracing-futures", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "ws_stream_wasm", -] - -[[package]] -name = "ethers-signers" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "228875491c782ad851773b652dd8ecac62cda8571d3bc32a5853644dd26766c2" -dependencies = [ - "async-trait", - "coins-bip32 0.8.7", - "coins-bip39 0.8.7", + "Inflector", "const-hex", - "elliptic-curve 0.13.8", - "eth-keystore", + "dunce", "ethers-core", - "rand 0.8.5", - "sha2 0.10.8", - "thiserror", - "tracing", + "eyre", + "prettyplease", + "proc-macro2 1.0.89", + "quote 1.0.37", + "regex", + "serde", + "serde_json", + "syn 2.0.87", + "toml 0.8.19", + "walkdir", ] [[package]] -name = "ethers-solc" +name = "ethers-core" version = "2.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66244a771d9163282646dbeffe0e6eca4dda4146b6498644e678ac6089b11edd" +checksum = "82d80cc6ad30b14a48ab786523af33b37f28a8623fc06afd55324816ef18fb1f" dependencies = [ - "cfg-if 1.0.0", + "arrayvec 0.7.6", + "bytes", + "cargo_metadata 0.18.1", + "chrono", "const-hex", - "dirs 5.0.1", - "dunce", - "ethers-core", - "glob", - "home", - "md-5", - "num_cpus", + "elliptic-curve 0.13.8", + "ethabi 18.0.0", + "generic-array", + "k256 0.13.4", + "num_enum 0.7.3", "once_cell", - "path-slash", - "rayon", - "regex", - "semver 1.0.23", + "open-fastrlp", + "rand 0.8.5", + "rlp", "serde", "serde_json", - "solang-parser", - "svm-rs 0.3.5", + "strum", + "syn 2.0.87", + "tempfile", "thiserror", "tiny-keccak 2.0.2", - "tokio", - "tracing", - "walkdir", - "yansi 0.5.1", + "unicode-xid 0.2.6", ] [[package]] @@ -5045,7 +4402,7 @@ checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" dependencies = [ "futures-core", "futures-sink", - "spin 0.9.8", + "spin", ] [[package]] @@ -5080,19 +4437,19 @@ name = "forge" version = "0.0.2" dependencies = [ "alloy-chains", - "alloy-consensus 0.5.4", + "alloy-consensus", "alloy-dyn-abi", "alloy-json-abi", - "alloy-network 0.5.4", + "alloy-network", "alloy-primitives", - "alloy-provider 0.5.4", - "alloy-rpc-types 0.5.4", - "alloy-serde 0.5.4", - "alloy-signer 0.5.4", - "alloy-signer-local 0.5.4", + "alloy-provider", + "alloy-rpc-types", + "alloy-serde", + "alloy-signer", + "alloy-signer-local", "alloy-sol-macro-expander", "alloy-sol-macro-input", - "alloy-transport 0.5.4", + "alloy-transport", "alloy-zksync", "anvil", "async-trait", @@ -5153,7 +4510,7 @@ dependencies = [ "solang-parser", "soldeer-commands", "strum", - "svm-rs 0.5.8", + "svm-rs", "tempfile", "thiserror", "tikv-jemallocator", @@ -5167,8 +4524,7 @@ dependencies = [ "watchexec", "watchexec-events", "watchexec-signals", - "yansi 1.0.1", - "zksync-web3-rs", + "yansi", "zksync_types", ] @@ -5215,17 +4571,18 @@ name = "forge-script" version = "0.0.2" dependencies = [ "alloy-chains", - "alloy-consensus 0.5.4", + "alloy-consensus", "alloy-dyn-abi", - "alloy-eips 0.5.4", + "alloy-eips", "alloy-json-abi", - "alloy-network 0.5.4", + "alloy-network", "alloy-primitives", - "alloy-provider 0.5.4", - "alloy-rpc-types 0.5.4", - "alloy-serde 0.5.4", - "alloy-signer 0.5.4", - "alloy-transport 0.5.4", + "alloy-provider", + "alloy-rpc-types", + "alloy-serde", + "alloy-signer", + "alloy-transport", + "alloy-zksync", "async-recursion", "clap", "dialoguer", @@ -5255,8 +4612,8 @@ dependencies = [ "tempfile", "tokio", "tracing", - "yansi 1.0.1", - "zksync-web3-rs", + "yansi", + "zksync_types", ] [[package]] @@ -5264,7 +4621,7 @@ name = "forge-script-sequence" version = "0.0.2" dependencies = [ "alloy-primitives", - "alloy-rpc-types 0.5.4", + "alloy-rpc-types", "eyre", "foundry-common", "foundry-compilers", @@ -5300,8 +4657,8 @@ dependencies = [ "alloy-dyn-abi", "alloy-json-abi", "alloy-primitives", - "alloy-provider 0.5.4", - "alloy-rpc-types 0.5.4", + "alloy-provider", + "alloy-rpc-types", "async-trait", "ciborium", "clap", @@ -5325,7 +4682,7 @@ dependencies = [ "tempfile", "tokio", "tracing", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -5358,16 +4715,16 @@ dependencies = [ name = "foundry-cheatcodes" version = "0.0.2" dependencies = [ - "alloy-consensus 0.5.4", + "alloy-consensus", "alloy-dyn-abi", - "alloy-genesis 0.5.4", + "alloy-genesis", "alloy-json-abi", "alloy-primitives", - "alloy-provider 0.5.4", + "alloy-provider", "alloy-rlp", - "alloy-rpc-types 0.5.4", - "alloy-signer 0.5.4", - "alloy-signer-local 0.5.4", + "alloy-rpc-types", + "alloy-signer", + "alloy-signer-local", "alloy-sol-types", "base64 0.22.1", "chrono", @@ -5403,7 +4760,6 @@ dependencies = [ "tracing", "vergen", "walkdir", - "zksync-web3-rs", "zksync_types", ] @@ -5432,12 +4788,12 @@ version = "0.0.2" dependencies = [ "alloy-chains", "alloy-dyn-abi", - "alloy-eips 0.5.4", + "alloy-eips", "alloy-json-abi", "alloy-primitives", - "alloy-provider 0.5.4", + "alloy-provider", "alloy-rlp", - "alloy-transport 0.5.4", + "alloy-transport", "alloy-zksync", "clap", "color-eyre", @@ -5462,30 +4818,29 @@ dependencies = [ "tracing", "tracing-subscriber", "tracing-tracy", - "yansi 1.0.1", - "zksync-web3-rs", + "yansi", ] [[package]] name = "foundry-common" version = "0.0.2" dependencies = [ - "alloy-consensus 0.5.4", - "alloy-contract 0.5.4", + "alloy-consensus", + "alloy-contract", "alloy-dyn-abi", "alloy-json-abi", - "alloy-json-rpc 0.5.4", + "alloy-json-rpc", "alloy-primitives", - "alloy-provider 0.5.4", - "alloy-pubsub 0.5.4", - "alloy-rpc-client 0.5.4", - "alloy-rpc-types 0.5.4", - "alloy-serde 0.5.4", + "alloy-provider", + "alloy-pubsub", + "alloy-rpc-client", + "alloy-rpc-types", + "alloy-serde", "alloy-sol-types", - "alloy-transport 0.5.4", - "alloy-transport-http 0.5.4", - "alloy-transport-ipc 0.5.4", - "alloy-transport-ws 0.5.4", + "alloy-transport", + "alloy-transport-http", + "alloy-transport-ipc", + "alloy-transport-ws", "alloy-zksync", "anstream", "anstyle", @@ -5512,19 +4867,19 @@ dependencies = [ "tracing", "url", "walkdir", - "yansi 1.0.1", + "yansi", ] [[package]] name = "foundry-common-fmt" version = "0.0.2" dependencies = [ - "alloy-consensus 0.5.4", + "alloy-consensus", "alloy-dyn-abi", - "alloy-network 0.5.4", + "alloy-network", "alloy-primitives", - "alloy-rpc-types 0.5.4", - "alloy-serde 0.5.4", + "alloy-rpc-types", + "alloy-serde", "chrono", "comfy-table", "foundry-macros", @@ -5532,7 +4887,7 @@ dependencies = [ "serde", "serde_json", "similar-asserts", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -5564,7 +4919,7 @@ dependencies = [ "serde_json", "sha2 0.10.8", "solang-parser", - "svm-rs 0.5.8", + "svm-rs", "svm-rs-builds", "tempfile", "thiserror", @@ -5572,7 +4927,7 @@ dependencies = [ "tracing", "walkdir", "winnow 0.6.20", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -5605,7 +4960,7 @@ dependencies = [ "tokio", "tracing", "walkdir", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -5640,7 +4995,7 @@ dependencies = [ "thiserror", "tracing", "walkdir", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -5658,7 +5013,7 @@ dependencies = [ "semver 1.0.23", "serde", "serde_json", - "svm-rs 0.5.8", + "svm-rs", "tempfile", "thiserror", "tokio", @@ -5698,7 +5053,7 @@ dependencies = [ "toml_edit 0.22.22", "tracing", "walkdir", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -5766,14 +5121,14 @@ name = "foundry-evm-core" version = "0.0.2" dependencies = [ "alloy-dyn-abi", - "alloy-genesis 0.5.4", + "alloy-genesis", "alloy-json-abi", "alloy-primitives", - "alloy-provider 0.5.4", - "alloy-rpc-types 0.5.4", - "alloy-serde 0.5.4", + "alloy-provider", + "alloy-rpc-types", + "alloy-serde", "alloy-sol-types", - "alloy-transport 0.5.4", + "alloy-transport", "auto_impl", "eyre", "foundry-cheatcodes-spec", @@ -5872,10 +5227,10 @@ version = "0.6.0" source = "git+https://github.com/Moonsong-Labs/foundry-zksync-fork-db?branch=zksync-v0.6.0#f2e915d1c476007ae16be9fb96b25ffe1b8f5113" dependencies = [ "alloy-primitives", - "alloy-provider 0.5.4", - "alloy-rpc-types 0.5.4", - "alloy-serde 0.5.4", - "alloy-transport 0.5.4", + "alloy-provider", + "alloy-rpc-types", + "alloy-serde", + "alloy-transport", "eyre", "futures 0.3.31", "parking_lot 0.12.3", @@ -5913,7 +5268,7 @@ name = "foundry-test-utils" version = "0.0.2" dependencies = [ "alloy-primitives", - "alloy-provider 0.5.4", + "alloy-provider", "era_test_node", "eyre", "fd-lock", @@ -5938,15 +5293,15 @@ dependencies = [ name = "foundry-wallets" version = "0.0.2" dependencies = [ - "alloy-consensus 0.5.4", + "alloy-consensus", "alloy-dyn-abi", - "alloy-network 0.5.4", + "alloy-network", "alloy-primitives", - "alloy-signer 0.5.4", + "alloy-signer", "alloy-signer-aws", "alloy-signer-gcp", "alloy-signer-ledger", - "alloy-signer-local 0.5.4", + "alloy-signer-local", "alloy-signer-trezor", "alloy-sol-types", "async-trait", @@ -5984,16 +5339,13 @@ dependencies = [ name = "foundry-zksync-core" version = "0.0.2" dependencies = [ - "alloy-consensus 0.5.4", - "alloy-dyn-abi", - "alloy-network 0.5.4", + "alloy-network", "alloy-primitives", - "alloy-provider 0.5.4", - "alloy-rpc-types 0.5.4", - "alloy-serde 0.5.4", - "alloy-signer 0.5.4", + "alloy-provider", + "alloy-rpc-types", + "alloy-serde", "alloy-sol-types", - "alloy-transport 0.5.4", + "alloy-transport", "ansiterm", "era_test_node", "eyre", @@ -6003,10 +5355,8 @@ dependencies = [ "itertools 0.13.0", "revm", "serde", - "serde_json", "tracing", "url", - "zksync-web3-rs", "zksync_basic_types", "zksync_contracts", "zksync_multivm", @@ -6065,16 +5415,6 @@ dependencies = [ "zksync_bellman", ] -[[package]] -name = "fs2" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "fs4" version = "0.8.4" @@ -6204,16 +5544,6 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" -[[package]] -name = "futures-locks" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45ec6fe3675af967e67c5536c0b9d44e34e6c52f86bedc4ea49c5317b8e94d06" -dependencies = [ - "futures-channel", - "futures-task", -] - [[package]] name = "futures-macro" version = "0.3.31" @@ -6272,15 +5602,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42012b0f064e01aa58b545fe3727f90f7dd4020f4a3ea735b50344965f5a57e9" -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - [[package]] name = "gcloud-sdk" version = "0.25.7" @@ -6292,7 +5613,7 @@ dependencies = [ "chrono", "futures 0.3.31", "hyper 1.5.0", - "jsonwebtoken 9.3.0", + "jsonwebtoken", "once_cell", "prost 0.13.3", "prost-types 0.13.3", @@ -6662,7 +5983,7 @@ dependencies = [ "google-cloud-metadata", "google-cloud-token", "home", - "jsonwebtoken 9.3.0", + "jsonwebtoken", "reqwest 0.12.9", "serde", "serde_json", @@ -6706,7 +6027,7 @@ dependencies = [ "regex", "reqwest 0.12.9", "reqwest-middleware", - "ring 0.17.8", + "ring", "serde", "serde_json", "sha2 0.10.8", @@ -6861,15 +6182,6 @@ dependencies = [ "serde", ] -[[package]] -name = "hashers" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2bca93b15ea5a746f220e56587f71e73c6165eab783df9e26590069953e3c30" -dependencies = [ - "fxhash", -] - [[package]] name = "hashlink" version = "0.9.1" @@ -7144,7 +6456,7 @@ dependencies = [ "tokio", "tokio-rustls 0.26.0", "tower-service", - "webpki-roots 0.26.6", + "webpki-roots", ] [[package]] @@ -7882,20 +7194,6 @@ dependencies = [ "url", ] -[[package]] -name = "jsonwebtoken" -version = "8.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378" -dependencies = [ - "base64 0.21.7", - "pem 1.1.1", - "ring 0.16.20", - "serde", - "serde_json", - "simple_asn1", -] - [[package]] name = "jsonwebtoken" version = "9.3.0" @@ -7904,8 +7202,8 @@ checksum = "b9ae10193d25051e74945f1ea2d0b42e03cc3b890f7e4cc5faa44997d808193f" dependencies = [ "base64 0.21.7", "js-sys", - "pem 3.0.4", - "ring 0.17.8", + "pem", + "ring", "serde", "serde_json", "simple_asn1", @@ -8012,7 +7310,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" dependencies = [ - "spin 0.9.8", + "spin", ] [[package]] @@ -8275,7 +7573,7 @@ dependencies = [ "clap", "clap_complete", "elasticlunr-rs", - "env_logger 0.11.5", + "env_logger", "handlebars 5.1.2", "log", "memchr", @@ -8888,14 +8186,14 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26c3b35b7b3e36d15e0563eebffe13c1d9ca16b7aaffcb6a64354633547e16b" dependencies = [ - "alloy-consensus 0.5.4", - "alloy-eips 0.5.4", + "alloy-consensus", + "alloy-eips", "alloy-primitives", "alloy-rlp", - "alloy-serde 0.5.4", + "alloy-serde", "derive_more 1.0.0", "serde", - "spin 0.9.8", + "spin", ] [[package]] @@ -8904,12 +8202,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94bae9bf91b620e1e2c2291562e5998bc1247bd8ada011773e1997b31a95de99" dependencies = [ - "alloy-consensus 0.5.4", - "alloy-eips 0.5.4", - "alloy-network-primitives 0.5.4", + "alloy-consensus", + "alloy-eips", + "alloy-network-primitives", "alloy-primitives", - "alloy-rpc-types-eth 0.5.4", - "alloy-serde 0.5.4", + "alloy-rpc-types-eth", + "alloy-serde", "op-alloy-consensus", "serde", "serde_json", @@ -9272,17 +8570,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "password-hash" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" -dependencies = [ - "base64ct", - "rand_core 0.6.4", - "subtle", -] - [[package]] name = "paste" version = "1.0.15" @@ -9302,9 +8589,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" dependencies = [ "digest 0.10.7", - "hmac", - "password-hash", - "sha2 0.10.8", ] [[package]] @@ -9325,7 +8609,7 @@ checksum = "bdeeaa00ce488657faba8ebf44ab9361f9365a97bd39ffb8a60663f57ff4b467" dependencies = [ "inlinable_string", "pear_codegen", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -9346,15 +8630,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" -[[package]] -name = "pem" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8" -dependencies = [ - "base64 0.13.1", -] - [[package]] name = "pem" version = "3.0.4" @@ -9665,7 +8940,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" dependencies = [ "diff", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -9822,7 +9097,7 @@ dependencies = [ "quote 1.0.37", "syn 2.0.87", "version_check", - "yansi 1.0.1", + "yansi", ] [[package]] @@ -10196,7 +9471,7 @@ checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" dependencies = [ "bytes", "rand 0.8.5", - "ring 0.17.8", + "ring", "rustc-hash 2.0.0", "rustls 0.23.16", "slab", @@ -10527,7 +9802,6 @@ dependencies = [ "http 0.2.12", "http-body 0.4.6", "hyper 0.14.31", - "hyper-rustls 0.24.2", "hyper-tls 0.5.0", "ipnet", "js-sys", @@ -10537,7 +9811,6 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls 0.21.12", "rustls-pemfile 1.0.4", "serde", "serde_json", @@ -10546,13 +9819,11 @@ dependencies = [ "system-configuration 0.5.1", "tokio", "tokio-native-tls", - "tokio-rustls 0.24.1", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 0.25.4", "winreg", ] @@ -10607,7 +9878,7 @@ dependencies = [ "wasm-bindgen-futures", "wasm-streams", "web-sys", - "webpki-roots 0.26.6", + "webpki-roots", "windows-registry", ] @@ -10673,7 +9944,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e29c662f7887f3b659d4b0fd234673419a8fcbeaa1ecc29bf7034c0a75cc8ea" dependencies = [ "alloy-primitives", - "alloy-rpc-types-eth 0.5.4", + "alloy-rpc-types-eth", "alloy-rpc-types-trace", "alloy-sol-types", "anstyle", @@ -10721,7 +9992,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d11fa1e195b0bebaf3fb18596f314a13ba3a4cb1fdd16d3465934d812fd921e" dependencies = [ "alloy-eip2930", - "alloy-eip7702 0.3.2", + "alloy-eip7702", "alloy-primitives", "auto_impl", "bitflags 2.6.0", @@ -10764,21 +10035,6 @@ dependencies = [ "bytemuck", ] -[[package]] -name = "ring" -version = "0.16.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" -dependencies = [ - "cc", - "libc", - "once_cell", - "spin 0.5.2", - "untrusted 0.7.1", - "web-sys", - "winapi", -] - [[package]] name = "ring" version = "0.17.8" @@ -10789,8 +10045,8 @@ dependencies = [ "cfg-if 1.0.0", "getrandom 0.2.15", "libc", - "spin 0.9.8", - "untrusted 0.9.0", + "spin", + "untrusted", "windows-sys 0.52.0", ] @@ -11033,7 +10289,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ "log", - "ring 0.17.8", + "ring", "rustls-webpki 0.101.7", "sct", ] @@ -11047,7 +10303,7 @@ dependencies = [ "aws-lc-rs", "log", "once_cell", - "ring 0.17.8", + "ring", "rustls-pki-types", "rustls-webpki 0.102.8", "subtle", @@ -11133,7 +10389,7 @@ dependencies = [ "rustls-webpki 0.102.8", "security-framework", "security-framework-sys", - "webpki-roots 0.26.6", + "webpki-roots", "winapi", ] @@ -11149,8 +10405,8 @@ version = "0.101.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", ] [[package]] @@ -11160,9 +10416,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ "aws-lc-rs", - "ring 0.17.8", + "ring", "rustls-pki-types", - "untrusted 0.9.0", + "untrusted", ] [[package]] @@ -11346,8 +10602,8 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ - "ring 0.17.8", - "untrusted 0.9.0", + "ring", + "untrusted", ] [[package]] @@ -12154,16 +11410,10 @@ dependencies = [ "tokio", "toml_edit 0.22.22", "uuid 1.11.0", - "zip 2.2.0", + "zip", "zip-extract", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - [[package]] name = "spin" version = "0.9.8" @@ -12534,26 +11784,6 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" -[[package]] -name = "svm-rs" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11297baafe5fa0c99d5722458eac6a5e25c01eb1b8e5cd137f54079093daa7a4" -dependencies = [ - "dirs 5.0.1", - "fs2", - "hex", - "once_cell", - "reqwest 0.11.27", - "semver 1.0.23", - "serde", - "serde_json", - "sha2 0.10.8", - "thiserror", - "url", - "zip 0.6.6", -] - [[package]] name = "svm-rs" version = "0.5.8" @@ -12571,7 +11801,7 @@ dependencies = [ "tempfile", "thiserror", "url", - "zip 2.2.0", + "zip", ] [[package]] @@ -12584,7 +11814,7 @@ dependencies = [ "const-hex", "semver 1.0.23", "serde_json", - "svm-rs 0.5.8", + "svm-rs", ] [[package]] @@ -12748,15 +11978,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - [[package]] name = "terminal_size" version = "0.4.0" @@ -13006,21 +12227,6 @@ dependencies = [ "tokio-util 0.7.12", ] -[[package]] -name = "tokio-tungstenite" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" -dependencies = [ - "futures-util", - "log", - "rustls 0.21.12", - "tokio", - "tokio-rustls 0.24.1", - "tungstenite 0.20.1", - "webpki-roots 0.25.4", -] - [[package]] name = "tokio-tungstenite" version = "0.24.0" @@ -13033,8 +12239,8 @@ dependencies = [ "rustls-pki-types", "tokio", "tokio-rustls 0.26.0", - "tungstenite 0.24.0", - "webpki-roots 0.26.6", + "tungstenite", + "webpki-roots", ] [[package]] @@ -13287,16 +12493,6 @@ dependencies = [ "tracing-subscriber", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project 1.1.7", - "tracing", -] - [[package]] name = "tracing-log" version = "0.2.0" @@ -13415,26 +12611,6 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "tungstenite" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" -dependencies = [ - "byteorder", - "bytes", - "data-encoding", - "http 0.2.12", - "httparse", - "log", - "rand 0.8.5", - "rustls 0.21.12", - "sha1", - "thiserror", - "url", - "utf-8", -] - [[package]] name = "tungstenite" version = "0.24.0" @@ -13617,12 +12793,6 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" - [[package]] name = "untrusted" version = "0.9.0" @@ -14009,12 +13179,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki-roots" -version = "0.25.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" - [[package]] name = "webpki-roots" version = "0.26.6" @@ -14086,7 +13250,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -14454,12 +13618,6 @@ version = "0.13.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" -[[package]] -name = "yansi" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" - [[package]] name = "yansi" version = "1.0.1" @@ -14510,26 +13668,6 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "zip" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" -dependencies = [ - "aes", - "byteorder", - "bzip2", - "constant_time_eq", - "crc32fast", - "crossbeam-utils", - "flate2", - "hmac", - "pbkdf2 0.11.0", - "sha1", - "time", - "zstd", -] - [[package]] name = "zip" version = "2.2.0" @@ -14556,7 +13694,7 @@ checksum = "25a8c9e90f27d1435088a7b540b6cc8ae6ee525d992a695f16012d2f365b3d3c" dependencies = [ "log", "thiserror", - "zip 2.2.0", + "zip", ] [[package]] @@ -14802,27 +13940,6 @@ dependencies = [ "sha3 0.10.8", ] -[[package]] -name = "zksync-web3-rs" -version = "0.2.1" -source = "git+https://github.com/jrigada/zksync-web3-rs.git?rev=bc3e6d3e75b7ff3747ff2dccefa9fb74d770931b#bc3e6d3e75b7ff3747ff2dccefa9fb74d770931b" -dependencies = [ - "anyhow", - "async-trait", - "clap", - "env_logger 0.10.2", - "ethers", - "ethers-contract", - "hex", - "lazy_static", - "log", - "serde", - "serde_json", - "sha2 0.9.9", - "thiserror", - "tokio", -] - [[package]] name = "zksync_basic_types" version = "0.1.0" @@ -15500,25 +14617,6 @@ dependencies = [ "simd-adler32", ] -[[package]] -name = "zstd" -version = "0.11.2+zstd.1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" -dependencies = [ - "zstd-safe", -] - -[[package]] -name = "zstd-safe" -version = "5.0.2+zstd.1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" -dependencies = [ - "libc", - "zstd-sys", -] - [[package]] name = "zstd-sys" version = "2.0.13+zstd.1.5.6" diff --git a/Cargo.toml b/Cargo.toml index 4b2110126..3ac53ffcf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -231,7 +231,9 @@ alloy-chains = "0.1" alloy-rlp = "0.3" alloy-trie = "0.6.0" # alloy-zksync = "0.1.0" -alloy-zksync = { git = "https://github.com/popzxc/alloy-zksync", branch = "main"} +# alloy-zksync = { git = "https://github.com/popzxc/alloy-zksync", branch = "main"} +# alloy-zksync = { git = "https://github.com/nbaztec/alloy-zksync", branch = "v0.5"} +alloy-zksync = { path = "../nbaztec-alloy-zksync" } ## op-alloy op-alloy-rpc-types = "0.5.0" @@ -244,8 +246,6 @@ terminal_size = "0.4" ## zksync era_test_node = { git="https://github.com/matter-labs/era-test-node.git" , rev = "94503847b402f0161c3372d5f357a4cb16a2d66d" } -zksync-web3-rs = {git = "https://github.com/jrigada/zksync-web3-rs.git", rev = "bc3e6d3e75b7ff3747ff2dccefa9fb74d770931b"} -# zksync-web3-rs = {git = "https://github.com/lambdaclass/zksync-web3-rs.git", rev = "56653345d14331e0865a6785c77cdda63c94eeba"} zksync_basic_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec" } zksync_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec" } zksync_state = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec" } diff --git a/crates/cast/Cargo.toml b/crates/cast/Cargo.toml index 5eb1e45b7..3e9c35256 100644 --- a/crates/cast/Cargo.toml +++ b/crates/cast/Cargo.toml @@ -36,7 +36,6 @@ foundry-config.workspace = true foundry-evm.workspace = true foundry-wallets.workspace = true foundry-zksync-core.workspace = true -zksync-web3-rs.workspace = true alloy-chains.workspace = true alloy-consensus = { workspace = true, features = ["serde", "kzg"] } @@ -59,6 +58,9 @@ alloy-signer-local = { workspace = true, features = ["mnemonic", "keystore"] } alloy-signer.workspace = true alloy-sol-types.workspace = true alloy-transport.workspace = true +alloy-zksync.workspace = true + +zksync_types.workspace = true chrono.workspace = true eyre.workspace = true diff --git a/crates/cast/bin/cmd/send.rs b/crates/cast/bin/cmd/send.rs index c05ce513d..e420dc7a8 100644 --- a/crates/cast/bin/cmd/send.rs +++ b/crates/cast/bin/cmd/send.rs @@ -1,12 +1,19 @@ use crate::tx::{self, CastTxBuilder}; -use alloy_network::{AnyNetwork, EthereumWallet}; +use alloy_network::{AnyNetwork, EthereumWallet, TransactionBuilder}; use alloy_primitives::{Address, Bytes, TxHash}; use alloy_provider::{Provider, ProviderBuilder}; use alloy_rpc_types::TransactionRequest; use alloy_serde::WithOtherFields; use alloy_signer::Signer; use alloy_transport::Transport; -use cast::Cast; +use alloy_zksync::{ + network::{ + transaction_request::TransactionRequest as ZkTransactionRequest, + unsigned_tx::eip712::PaymasterParams, Zksync, + }, + wallet::ZksyncWallet, +}; +use cast::{Cast, ZkCast}; use clap::{builder::ArgPredicate, Parser}; use eyre::Result; use foundry_cli::{ @@ -15,10 +22,9 @@ use foundry_cli::{ }; use foundry_common::ens::NameOrAddress; use foundry_config::Config; -use foundry_wallets::WalletSigner; -use foundry_zksync_core::{self, convert::ConvertAddress}; +use foundry_zksync_core::convert::ConvertU256; use std::{path::PathBuf, str::FromStr}; -use zksync_web3_rs::eip712::PaymasterParams; +use zksync_types::fee::Fee; /// ZkSync-specific paymaster parameters for transactions #[derive(Debug, Parser)] @@ -144,6 +150,7 @@ impl SendTxArgs { config.zksync.compile = zksync_params.zksync; let provider = utils::get_provider(&config)?; + let zk_provider = utils::get_provider_zksync(&config)?; let builder = CastTxBuilder::new(&provider, tx, &config) .await? @@ -189,20 +196,33 @@ impl SendTxArgs { } else { // Retrieve the signer, and bail if it can't be constructed. let signer = eth.wallet.signer().await?; + let zk_signer = eth.wallet.signer().await?; let from = signer.address(); tx::validate_from_address(eth.wallet.from, from)?; if zksync_params.zksync { + // Zksync transaction let (tx, _) = builder.build(&signer).await?; + + let wallet = EthereumWallet::from(signer); + let provider = ProviderBuilder::<_, _, AnyNetwork>::default() + .wallet(wallet) + .on_provider(&provider); + + let zk_wallet = ZksyncWallet::from(zk_signer); + let zk_provider = ProviderBuilder::<_, _, Zksync>::default() + .wallet(zk_wallet) + .on_provider(&zk_provider); + cast_send_zk( - &provider, - zksync_params, + provider, + zk_provider, tx, + zksync_params, cast_async, confirmations, timeout, - signer, ) .await } else { @@ -235,40 +255,41 @@ async fn cast_send, T: Transport + Clone>( handle_transaction_result(&cast, tx_hash, cast_async, confs, timeout).await } -#[allow(clippy::too_many_arguments)] -async fn cast_send_zk, T: Transport + Clone>( +async fn cast_send_zk, Z: Provider, T: Transport + Clone>( provider: P, - zksync_params: ZksyncParams, + zk_provider: Z, tx: WithOtherFields, + zksync_params: ZksyncParams, cast_async: bool, confs: u64, timeout: u64, - signer: WalletSigner, ) -> Result<()> { // ZkSync transaction let paymaster_params = zksync_params .paymaster_address .and_then(|addr| zksync_params.paymaster_input.map(|input| (addr, input))) .map(|(addr, input)| PaymasterParams { - paymaster: Address::from_str(&addr).expect("Invalid paymaster address").to_h160(), - paymaster_input: Bytes::from_str(&input).expect("Invalid paymaster input").to_vec(), + paymaster: Address::from_str(&addr).expect("Invalid paymaster address"), + paymaster_input: Bytes::from_str(&input).expect("Invalid paymaster input"), }); - // Build EIP712 transaction for ZKSync - let tx = foundry_zksync_core::new_eip712_transaction( - tx, - Vec::new(), // Empty factory_deps - paymaster_params, - &provider, - signer, - ) - .await - .map_err(|e| eyre::eyre!("Failed to create EIP712 transaction: {}", e))?; - - // Use send_raw_transaction for ZKSync - let tx_hash = provider.send_raw_transaction(&tx).await?.tx_hash().to_owned(); - let cast = Cast::new(provider); - handle_transaction_result(&cast, &tx_hash, cast_async, confs, timeout).await + let mut zk_tx: ZkTransactionRequest = tx.inner.clone().into(); + if let Some(paymaster_params) = paymaster_params { + zk_tx.set_paymaster(paymaster_params); + } + + let fee = provider.raw_request::<_, Fee>("zks_estimateFee".into(), [&zk_tx]).await.unwrap(); + zk_tx.set_gas_limit(fee.gas_limit.as_u64()); + zk_tx.set_max_fee_per_gas(fee.max_fee_per_gas.as_u128()); + zk_tx.set_max_priority_fee_per_gas(fee.max_priority_fee_per_gas.as_u128()); + zk_tx.set_gas_per_pubdata(fee.gas_per_pubdata_limit.to_ru256()); + + let cast = ZkCast::new(zk_provider, Cast::new(provider)); + let pending_tx = cast.send_zk(zk_tx).await?; + + let tx_hash = pending_tx.inner().tx_hash(); + + handle_transaction_result(cast.as_ref(), tx_hash, cast_async, confs, timeout).await } async fn handle_transaction_result, T: Transport + Clone>( diff --git a/crates/cast/src/lib.rs b/crates/cast/src/lib.rs index 75272b3b1..a1577bc18 100644 --- a/crates/cast/src/lib.rs +++ b/crates/cast/src/lib.rs @@ -19,6 +19,9 @@ use alloy_rpc_types::{BlockId, BlockNumberOrTag, Filter, TransactionRequest}; use alloy_serde::WithOtherFields; use alloy_sol_types::sol; use alloy_transport::Transport; +use alloy_zksync::network::{ + transaction_request::TransactionRequest as ZkTransactionRequest, Zksync, +}; use base::{Base, NumberWithBase, ToBase}; use chrono::DateTime; use eyre::{Context, ContextCompat, Result}; @@ -69,6 +72,72 @@ sol! { } } +pub struct ZkCast { + provider: Z, + inner: Cast, +} + +impl AsRef> for ZkCast +where + P: Provider, + T: Transport + Clone, + Z: Provider, +{ + fn as_ref(&self) -> &Cast { + &self.inner + } +} + +impl ZkCast +where + P: Provider, + T: Transport + Clone, + Z: Provider, +{ + /// Creates a new Cast instance from the provided client + /// + /// # Example + /// + /// ``` + /// use alloy_provider::{network::AnyNetwork, ProviderBuilder, RootProvider}; + /// use cast::Cast; + /// + /// # async fn foo() -> eyre::Result<()> { + /// let provider = + /// ProviderBuilder::<_, _, AnyNetwork>::default().on_builtin("http://localhost:8545").await?; + /// let cast = Cast::new(provider); + /// let zk_provider = + /// ProviderBuilder::<_, _, Zksync>::default().on_builtin("http://localhost:8011").await?; + /// let zk_cast = ZkCast::new(provider, cast); + /// # Ok(()) + /// # } + /// ``` + pub fn new(provider: Z, cast: Cast) -> Self { + Self { provider, inner: cast } + } + + pub async fn send_zk( + &self, + tx: ZkTransactionRequest, + ) -> Result> { + let res = self.provider.send_transaction(tx).await?; + + Ok(res) + } +} + +// pub struct Cast { +// provider: P, +// zk_provider: Option, +// transport: PhantomData, +// } + +// impl Cast +// where +// T: Transport + Clone, +// P: Provider, +// Z: Provider, +// { pub struct Cast { provider: P, transport: PhantomData, diff --git a/crates/cheatcodes/Cargo.toml b/crates/cheatcodes/Cargo.toml index 2ddec87d3..e817e1598 100644 --- a/crates/cheatcodes/Cargo.toml +++ b/crates/cheatcodes/Cargo.toml @@ -34,7 +34,6 @@ forge-script-sequence.workspace = true foundry-zksync-core.workspace = true foundry-zksync-compiler.workspace = true foundry-zksync-inspectors.workspace = true -zksync-web3-rs.workspace = true zksync_types.workspace = true diff --git a/crates/cheatcodes/src/inspector.rs b/crates/cheatcodes/src/inspector.rs index aad1f7dfd..e329ea4e2 100644 --- a/crates/cheatcodes/src/inspector.rs +++ b/crates/cheatcodes/src/inspector.rs @@ -76,12 +76,12 @@ use std::{ }; use zksync_types::{ block::{pack_block_info, unpack_block_info}, + transaction_request::PaymasterParams, utils::{decompose_full_nonce, nonces_to_full_nonce}, ACCOUNT_CODE_STORAGE_ADDRESS, CONTRACT_DEPLOYER_ADDRESS, CURRENT_VIRTUAL_BLOCK_INFO_POSITION, H256, KNOWN_CODES_STORAGE_ADDRESS, L2_BASE_TOKEN_ADDRESS, NONCE_HOLDER_ADDRESS, SYSTEM_CONTEXT_ADDRESS, }; -use zksync_web3_rs::eip712::PaymasterParams; mod utils; diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 65e433d08..89af3647f 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -19,7 +19,6 @@ 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"] } diff --git a/crates/cli/src/opts/build/zksync.rs b/crates/cli/src/opts/build/zksync.rs index a463975e8..d6a0e1c2b 100644 --- a/crates/cli/src/opts/build/zksync.rs +++ b/crates/cli/src/opts/build/zksync.rs @@ -1,10 +1,10 @@ use std::{collections::HashSet, path::PathBuf}; +use alloy_primitives::{Address, Bytes}; use clap::Parser; use foundry_compilers::zksolc::settings::{ZkSolcError, ZkSolcWarning}; 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")] diff --git a/crates/common/src/provider/mod.rs b/crates/common/src/provider/mod.rs index 2d92efcd3..b88d9c00f 100644 --- a/crates/common/src/provider/mod.rs +++ b/crates/common/src/provider/mod.rs @@ -87,6 +87,12 @@ pub fn try_get_http_provider(builder: impl AsRef) -> Result ProviderBuilder::new(builder.as_ref()).build() } +/// Constructs a ZKsync provider with a 100 millisecond interval poll if it's a localhost URL (most +/// likely an anvil or other dev node) and with the default, or 7 second otherwise. +#[inline] +pub fn try_get_zksync_http_provider(builder: impl AsRef) -> Result> { + ProviderBuilder::new(builder.as_ref()).build_zksync() +} /// Helper type to construct a `RetryProvider` #[derive(Debug)] pub struct ProviderBuilder { diff --git a/crates/forge/Cargo.toml b/crates/forge/Cargo.toml index 4c7ded70b..cd30adeb6 100644 --- a/crates/forge/Cargo.toml +++ b/crates/forge/Cargo.toml @@ -116,7 +116,6 @@ soldeer-commands.workspace = true quick-junit = "0.5.0" # zk -zksync-web3-rs.workspace = true zksync_types.workspace = true [target.'cfg(unix)'.dependencies] diff --git a/crates/forge/bin/cmd/create.rs b/crates/forge/bin/cmd/create.rs index a8167bb9b..50957eb6d 100644 --- a/crates/forge/bin/cmd/create.rs +++ b/crates/forge/bin/cmd/create.rs @@ -8,7 +8,11 @@ use alloy_rpc_types::{AnyTransactionReceipt, TransactionRequest}; use alloy_serde::WithOtherFields; use alloy_signer::Signer; use alloy_transport::{Transport, TransportError}; -use alloy_zksync::{network::Zksync, provider::ZksyncProvider, wallet::ZksyncWallet}; +use alloy_zksync::{ + network::{unsigned_tx::eip712::PaymasterParams, Zksync}, + provider::ZksyncProvider, + wallet::ZksyncWallet, +}; use clap::{Parser, ValueHint}; use eyre::{Context, Result}; use forge_verify::{zk_provider::CompilerVerificationContext, RetryArgs}; @@ -44,7 +48,6 @@ use std::{ sync::Arc, }; use zksync_types::H256; -use zksync_web3_rs::eip712::PaymasterParams; merge_impl_figment_convert!(CreateArgs, opts, eth); @@ -136,8 +139,7 @@ impl CreateArgs { .zk .paymaster_input .clone() - .unwrap_or_default() - .to_vec(), + .unwrap_or_default(), }) } else { None @@ -259,7 +261,9 @@ impl CreateArgs { // and potentially other devices that rely on HID too let zk_signer = self.eth.wallet.signer().await?; let deployer = zk_signer.address(); - let provider = ProviderBuilder::<_, _, Zksync>::default().wallet(ZksyncWallet::new(signer)).on_provider(provider); + let provider = ProviderBuilder::<_, _, Zksync>::default() + .wallet(ZksyncWallet::new(zk_signer)) + .on_provider(provider); self.deploy_zk( abi, bin.object, @@ -630,15 +634,14 @@ impl CreateArgs { } let fee = provider - .estimate_fee(&deployer.tx) + .estimate_fee(deployer.tx.clone()) .await - .map_err(|err| eyre::eyre!("failed rpc call for estimating fee: {:?}", err))? - .unwrap_or_default(); + .map_err(|err| eyre::eyre!("failed rpc call for estimating fee: {:?}", err))?; deployer.tx.set_gas_limit(if let Some(gas_limit) = self.tx.gas_limit { gas_limit.to::() } else { - fee.gas_limit.saturating_to::() + fee.gas_limit }); // Before we actually deploy the contract we try check if the verify settings are valid @@ -1079,11 +1082,11 @@ where .into(); // create the tx object. Since we're deploying a contract, `to` is `None` - let tx = alloy_zksync::network::transaction_request::TransactionRequest::default().base( + let tx: alloy_zksync::network::transaction_request::TransactionRequest = TransactionRequest::default() .to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address()) - .input(data.into()), - ); + .input(data.into()) + .into(); Ok(ZkDeployer { client: self.client.clone(), diff --git a/crates/script/Cargo.toml b/crates/script/Cargo.toml index 2f33e8887..a48ca8dac 100644 --- a/crates/script/Cargo.toml +++ b/crates/script/Cargo.toml @@ -58,9 +58,9 @@ alloy-primitives.workspace = true alloy-eips.workspace = true alloy-transport.workspace = true alloy-consensus.workspace = true +alloy-zksync.workspace = true -# zksync -zksync-web3-rs.workspace = true +zksync_types.workspace = true [dev-dependencies] tempfile.workspace = true diff --git a/crates/script/src/broadcast.rs b/crates/script/src/broadcast.rs index d837abde5..fa7ac9a13 100644 --- a/crates/script/src/broadcast.rs +++ b/crates/script/src/broadcast.rs @@ -3,35 +3,40 @@ use crate::{ verify::BroadcastedState, ScriptArgs, ScriptConfig, }; use alloy_chains::Chain; -use alloy_consensus::{Transaction, TxEnvelope}; +use alloy_consensus::TxEnvelope; use alloy_eips::eip2718::Encodable2718; use alloy_network::{AnyNetwork, EthereumWallet, TransactionBuilder}; use alloy_primitives::{ map::{AddressHashMap, AddressHashSet}, utils::format_units, - Address, TxHash, + Address, Bytes, TxHash, }; use alloy_provider::{utils::Eip1559Estimation, Provider}; use alloy_rpc_types::TransactionRequest; use alloy_serde::WithOtherFields; use alloy_transport::Transport; +use alloy_zksync::network::{ + transaction_request::TransactionRequest as ZkTransactionRequest, Zksync, +}; use eyre::{bail, Context, Result}; use forge_verify::provider::VerificationProviderType; use foundry_cheatcodes::Wallets; use foundry_cli::utils::{has_batch_support, has_different_gas_calc}; use foundry_common::{ - provider::{get_http_provider, try_get_http_provider, RetryProvider}, + provider::{ + get_http_provider, try_get_http_provider, try_get_zksync_http_provider, RetryProvider, + }, TransactionMaybeSigned, }; use foundry_config::Config; use foundry_zksync_core::{ - convert::{ConvertAddress, ConvertBytes, ConvertSignature, ToSignable}, + convert::{ConvertH160, ConvertU256}, ZkTransactionMetadata, }; use futures::{future::join_all, StreamExt}; use itertools::Itertools; use std::{cmp::Ordering, sync::Arc}; -use zksync_web3_rs::eip712::{Eip712Meta, Eip712Transaction, Eip712TransactionRequest}; +use zksync_types::fee::Fee; pub async fn estimate_gas( tx: &mut WithOtherFields, @@ -60,53 +65,10 @@ pub async fn next_nonce(caller: Address, provider_url: &str) -> eyre::Result, - tx: WithOtherFields, - zk: &ZkTransactionMetadata, -) -> Result<(Eip712TransactionRequest, Eip712Transaction)> { - let mut custom_data = Eip712Meta::new().factory_deps(zk.factory_deps.clone()); - - if let Some(paymaster_params) = &zk.paymaster_data { - custom_data = custom_data.paymaster_params(paymaster_params.clone()); - } - - let gas_price = match tx.gas_price() { - Some(price) => price, - None => provider.get_gas_price().await?, - }; - - let mut deploy_request = Eip712TransactionRequest::new() - .r#type(zksync_web3_rs::zks_utils::EIP712_TX_TYPE) - .from(Address(*tx.from().unwrap()).to_h160()) - .to(tx.to().map(|to| to.to_h160()).unwrap()) - .chain_id(tx.chain_id().unwrap()) - .nonce(tx.nonce().unwrap()) - .data(tx.input().cloned().unwrap_or_default().to_ethers()) - .gas_price(gas_price) - .custom_data(custom_data); - - let fee: zksync_web3_rs::zks_provider::types::Fee = - provider.raw_request("zks_estimateFee".into(), [deploy_request.clone()]).await.unwrap(); - deploy_request = deploy_request - .gas_limit(fee.gas_limit) - .max_fee_per_gas(fee.max_fee_per_gas) - .max_priority_fee_per_gas(fee.max_priority_fee_per_gas); - deploy_request.custom_data.gas_per_pubdata = fee.gas_per_pubdata_limit; - - // TODO: This is a work around as try_into is not propagating - // gas_per_pubdata_byte_limit. It always set the default We would need to - // fix that library or add EIP712 to alloy with correct implementation. - let mut signable: Eip712Transaction = - deploy_request.clone().try_into().wrap_err("converting deploy request")?; - signable.gas_per_pubdata_byte_limit = deploy_request.custom_data.gas_per_pubdata; - - Ok((deploy_request, signable)) -} - #[allow(clippy::too_many_arguments)] pub async fn send_transaction( provider: Arc, + zk_provider: Arc>, mut kind: SendTransactionKind<'_>, zk: Option<&ZkTransactionMetadata>, sequential_broadcast: bool, @@ -143,63 +105,64 @@ pub async fn send_transaction( // Chains which use `eth_estimateGas` are being sent sequentially and require their // gas to be re-estimated right before broadcasting. if !is_fixed_gas_limit && estimate_via_rpc { - // manually add factory_deps to estimate_gas - if let Some(zk) = zk { - tx.other.insert( - "eip712Meta".into(), - serde_json::to_value(&Eip712Meta { - factory_deps: zk.factory_deps.clone(), - ..Default::default() - }) - .expect("failed serializing json"), - ); + // We skip estimating gas for zk transactions as the fee is estimated manually later. + if zk.is_none() { + estimate_gas(tx, &provider, estimate_multiplier).await?; } - estimate_gas(tx, &provider, estimate_multiplier).await?; } } - let pending = match kind { + let pending_tx_hash = match kind { SendTransactionKind::Unlocked(tx) => { debug!("sending transaction from unlocked account {:?}", tx); // Submit the transaction - provider.send_transaction(tx).await? + *provider.send_transaction(tx).await?.tx_hash() } SendTransactionKind::Raw(tx, signer) => { debug!("sending transaction: {:?}", tx); - let signed = if let Some(zk) = zk { - let signer = signer - .signer_by_address(tx.from.expect("no sender")) - .ok_or(eyre::eyre!("Signer not found"))?; - - let (deploy_request, signable) = convert_to_zksync(&provider, tx, zk).await?; - let mut signable = signable.to_signable_tx(); - - let signature = signer - .sign_transaction(&mut signable) + if let Some(zk) = zk { + let mut zk_tx: ZkTransactionRequest = tx.inner.clone().into(); + if !zk.factory_deps.is_empty() { + zk_tx.set_factory_deps( + zk.factory_deps.iter().map(|bytes| Bytes::from_iter(bytes)).collect(), + ); + } + if let Some(paymaster_data) = &zk.paymaster_data { + zk_tx.set_paymaster( + alloy_zksync::network::unsigned_tx::eip712::PaymasterParams { + paymaster: paymaster_data.paymaster.to_address(), + paymaster_input: paymaster_data.paymaster_input.clone().into(), + }, + ); + } + let fee = provider + .raw_request::<_, Fee>("zks_estimateFee".into(), [&zk_tx]) .await - .wrap_err("Failed to sign typed data")?; + .unwrap(); + zk_tx.set_gas_limit(fee.gas_limit.as_u64()); + zk_tx.set_max_fee_per_gas(fee.max_fee_per_gas.as_u128()); + zk_tx.set_max_priority_fee_per_gas(fee.max_priority_fee_per_gas.as_u128()); + zk_tx.set_gas_per_pubdata(fee.gas_per_pubdata_limit.to_ru256()); - let encoded = &*deploy_request - .rlp_signed(signature.to_ethers()) - .wrap_err("able to rlp encode deploy request")?; + let zk_signer = alloy_zksync::wallet::ZksyncWallet::new(signer.default_signer()); + let signed = zk_tx.build(&zk_signer).await?.encoded_2718(); - [&[signable.ty()], encoded].concat() + *zk_provider.send_raw_transaction(signed.as_ref()).await?.tx_hash() } else { - tx.build(signer).await?.encoded_2718() - }; - - // Submit the raw transaction - provider.send_raw_transaction(signed.as_ref()).await? + let signed = tx.build(signer).await?.encoded_2718(); + // Submit the raw transaction + *provider.send_raw_transaction(signed.as_ref()).await?.tx_hash() + } } SendTransactionKind::Signed(tx) => { debug!("sending transaction: {:?}", tx); - provider.send_raw_transaction(tx.encoded_2718().as_ref()).await? + *provider.send_raw_transaction(tx.encoded_2718().as_ref()).await?.tx_hash() } }; - Ok(*pending.tx_hash()) + Ok(pending_tx_hash) } /// How to send a single transaction @@ -339,6 +302,7 @@ impl BundledState { let mut sequence = self.sequence.sequences_mut().get_mut(i).unwrap(); let provider = Arc::new(try_get_http_provider(sequence.rpc_url())?); + let zk_provider = Arc::new(try_get_zksync_http_provider(sequence.rpc_url())?); let already_broadcasted = sequence.receipts.len(); let seq_progress = progress.get_sequence_progress(i, sequence); @@ -446,6 +410,7 @@ impl BundledState { for (kind, zk, is_fixed_gas_limit) in batch { let fut = send_transaction( provider.clone(), + zk_provider.clone(), kind.clone(), zk.as_ref(), sequential_broadcast, diff --git a/crates/zksync/core/Cargo.toml b/crates/zksync/core/Cargo.toml index e3532b466..97a03ca66 100644 --- a/crates/zksync/core/Cargo.toml +++ b/crates/zksync/core/Cargo.toml @@ -16,15 +16,12 @@ foundry-common.workspace = true foundry-evm-abi.workspace = true foundry-cheatcodes-common.workspace = true alloy-primitives.workspace = true -alloy-signer.workspace = true alloy-network.workspace = true alloy-sol-types.workspace = true -alloy-dyn-abi.workspace = true alloy-serde.workspace = true alloy-provider.workspace = true alloy-transport.workspace = true alloy-rpc-types.workspace = true -alloy-consensus.workspace = true itertools.workspace = true revm = { workspace = true, default-features = false, features = [ "std", @@ -38,13 +35,11 @@ revm = { workspace = true, default-features = false, features = [ ] } tracing.workspace = true serde.workspace = true -serde_json.workspace = true # zk zksync_multivm.workspace = true zksync_basic_types.workspace = true zksync_types.workspace = true -zksync-web3-rs.workspace = true era_test_node.workspace = true zksync_utils.workspace = true zksync_contracts.workspace = true diff --git a/crates/zksync/core/src/convert.rs b/crates/zksync/core/src/convert.rs index c6f84a6f9..0702b332f 100644 --- a/crates/zksync/core/src/convert.rs +++ b/crates/zksync/core/src/convert.rs @@ -5,12 +5,6 @@ use revm::primitives::{Address, B256}; use zksync_basic_types::{H160, H256, U256}; use zksync_utils::{address_to_h256, h256_to_u256, u256_to_h256}; -use alloy_primitives::{Bytes as AlloyBytes, Signature as AlloySignature}; -use zksync_web3_rs::types::{Bytes as ZkBytes, Signature as ZkSignature}; - -mod eip712; -pub use eip712::*; - /// Conversions from [U256] pub trait ConvertU256 { /// Convert to [rU256] @@ -136,67 +130,6 @@ impl ConvertAddress for Address { } } -/// Conversions to/from [`ZkSignature`] & [`AlloySignature`] -pub trait ConvertSignature { - /// Cast to [`ZkSignature`] - fn to_ethers(self) -> ZkSignature; - /// Cast to [`AlloySignature`] - fn to_alloy(self) -> AlloySignature; -} - -impl ConvertSignature for ZkSignature { - fn to_ethers(self) -> ZkSignature { - self - } - - fn to_alloy(self) -> AlloySignature { - AlloySignature::from_rs_and_parity(self.r.to_ru256(), self.s.to_ru256(), self.v).unwrap() - } -} - -impl ConvertSignature for AlloySignature { - fn to_ethers(self) -> ZkSignature { - let v = self.v(); - ZkSignature { - r: self.r().to_u256(), - s: self.s().to_u256(), - v: v.y_parity_byte_non_eip155().unwrap_or(v.y_parity_byte()) as u64, - } - } - - fn to_alloy(self) -> AlloySignature { - self - } -} - -/// Convert to/from [`AlloyBytes`] & [`ZkBytes`] -pub trait ConvertBytes { - /// Convert to [`AlloyBytes`] - fn to_alloy(self) -> AlloyBytes; - /// Convert to [`ZkBytes`] - fn to_ethers(self) -> ZkBytes; -} - -impl ConvertBytes for AlloyBytes { - fn to_alloy(self) -> AlloyBytes { - self - } - - fn to_ethers(self) -> ZkBytes { - ZkBytes(self.0) - } -} - -impl ConvertBytes for ZkBytes { - fn to_alloy(self) -> AlloyBytes { - AlloyBytes(self.0) - } - - fn to_ethers(self) -> ZkBytes { - self - } -} - #[cfg(test)] mod test { use std::str::FromStr; diff --git a/crates/zksync/core/src/convert/eip712.rs b/crates/zksync/core/src/convert/eip712.rs deleted file mode 100644 index 228d598fd..000000000 --- a/crates/zksync/core/src/convert/eip712.rs +++ /dev/null @@ -1,242 +0,0 @@ -use alloy_consensus::{SignableTransaction, Transaction}; -use alloy_dyn_abi::TypedData; -use alloy_primitives::{bytes::BufMut, Signature, B256}; -/// Conversion between ethers and alloy for EIP712 items -use alloy_sol_types::Eip712Domain as AlloyEip712Domain; -use zksync_web3_rs::{ - eip712::Eip712Transaction, - types::transaction::eip712::{ - encode_type, EIP712Domain as EthersEip712Domain, Eip712 as EthersEip712, Eip712DomainType, - Types, - }, - zks_utils::EIP712_TX_TYPE, -}; - -use super::{ConvertAddress, ConvertH160, ConvertRU256, ConvertU256}; - -/// Convert between Eip712Domain types -pub trait ConvertEIP712Domain { - /// Cast to ethers-rs's Eip712Domain - fn to_ethers(self) -> EthersEip712Domain; - - /// Cast to alloy-rs's Eip712Domain - fn to_alloy(self) -> AlloyEip712Domain; -} - -impl ConvertEIP712Domain for AlloyEip712Domain { - fn to_ethers(self) -> EthersEip712Domain { - EthersEip712Domain { - name: self.name.map(Into::into), - version: self.version.map(Into::into), - chain_id: self.chain_id.map(ConvertRU256::to_u256), - verifying_contract: self.verifying_contract.map(ConvertAddress::to_h160), - salt: self.salt.map(Into::into), - } - } - - fn to_alloy(self) -> AlloyEip712Domain { - self - } -} - -impl ConvertEIP712Domain for EthersEip712Domain { - fn to_ethers(self) -> EthersEip712Domain { - self - } - - fn to_alloy(self) -> AlloyEip712Domain { - AlloyEip712Domain::new( - self.name.map(Into::into), - self.version.map(Into::into), - self.chain_id.map(ConvertU256::to_ru256), - self.verifying_contract.map(ConvertH160::to_address), - self.salt.map(Into::into), - ) - } -} - -/// Wrapper around [`Eip712Transaction`] implementing [`SignableTransaction`] -#[derive(Debug)] -pub struct Eip712SignableTransaction { - inner: Eip712Transaction, - input: alloy_primitives::Bytes, -} - -impl Eip712SignableTransaction { - /// Creates a new `Eip712SignableTransaction` from an existing `Eip712Transaction`. - pub fn new(inner: Eip712Transaction) -> Self { - Self { input: alloy_primitives::Bytes::from_iter(inner.data.iter()), inner } - } -} - -impl Transaction for Eip712SignableTransaction { - fn chain_id(&self) -> Option { - Some(self.inner.chain_id.as_u64()) - } - - fn nonce(&self) -> u64 { - self.inner.nonce.as_u64() - } - - fn gas_limit(&self) -> u64 { - self.inner.gas_limit.as_u64() - } - - fn gas_price(&self) -> Option { - None - } - - fn to(&self) -> Option { - Some(self.inner.to.to_address()) - } - - fn value(&self) -> alloy_primitives::U256 { - self.inner.value.to_ru256() - } - - fn input(&self) -> &alloy_primitives::Bytes { - &self.input - } - - fn max_fee_per_gas(&self) -> u128 { - self.inner.max_fee_per_gas.low_u128() - } - - fn max_priority_fee_per_gas(&self) -> Option { - Some(self.priority_fee_or_price()) - } - - fn max_fee_per_blob_gas(&self) -> Option { - None - } - - fn priority_fee_or_price(&self) -> u128 { - self.inner.max_priority_fee_per_gas.low_u128() - } - - fn ty(&self) -> u8 { - EIP712_TX_TYPE - } - - fn access_list(&self) -> Option<&alloy_rpc_types::AccessList> { - None - } - - fn blob_versioned_hashes(&self) -> Option<&[B256]> { - None - } - - fn authorization_list(&self) -> Option<&[revm::primitives::SignedAuthorization]> { - None - } - - fn kind(&self) -> alloy_primitives::TxKind { - alloy_primitives::TxKind::Call(self.inner.to.to_address()) - } -} - -impl SignableTransaction for Eip712SignableTransaction { - fn set_chain_id(&mut self, chain_id: alloy_primitives::ChainId) { - self.inner.chain_id = chain_id.into(); - } - - fn encode_for_signing(&self, out: &mut dyn BufMut) { - out.put_u8(0x19); - out.put_u8(0x01); - - let domain_separator = self.inner.domain_separator().expect("able to get domain separator"); - out.put_slice(&domain_separator); - - let struct_hash = self.inner.struct_hash().expect("able to get struct hash"); - out.put_slice(&struct_hash); - } - - fn payload_len_for_signature(&self) -> usize { - 2 + 32 + 32 - } - - fn into_signed(self, signature: Signature) -> alloy_consensus::Signed - where - Self: Sized, - { - let hash = self.inner.encode_eip712().map(B256::from).expect("able to encode EIP712 hash"); - alloy_consensus::Signed::new_unchecked(self, signature, hash) - } -} - -/// Convert to [`SignableTransaction`] -pub trait ToSignable { - /// Type to convert to - type Signable: SignableTransaction; - - /// Perform conversion - fn to_signable_tx(self) -> Self::Signable; -} - -impl ToSignable for Eip712Transaction { - type Signable = Eip712SignableTransaction; - - fn to_signable_tx(self) -> Self::Signable { - Eip712SignableTransaction::new(self) - } -} - -/// Convert to [`TypedData`] -pub trait ToTypedData { - /// Convert item to [`TypedData`] - fn to_typed_data(self) -> TypedData; -} - -impl ToTypedData for Eip712Transaction { - fn to_typed_data(self) -> TypedData { - use alloy_dyn_abi::*; - - let types = eip712_transaction_types(); - let primary_type = types.first_key_value().unwrap().0.clone(); - - let domain = EthersEip712::domain(&self).expect("Eip712Transaction has domain").to_alloy(); - - let message = serde_json::to_value(&self).expect("able to serialize as json"); - - let encode_type = encode_type(&primary_type, &types).expect("able to encodeType"); - - let resolver = { - let mut resolver = Resolver::default(); - resolver.ingest_string(&encode_type).expect("able to ingest encodeType"); - resolver - }; - - TypedData { domain, resolver, primary_type, message } - } -} - -//zksync_web3_rs::eip712::transaction -fn eip712_transaction_types() -> Types { - let mut types = Types::new(); - - types.insert( - "Transaction".to_owned(), - vec![ - Eip712DomainType { name: "txType".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { name: "from".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { name: "to".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { name: "gasLimit".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { - name: "gasPerPubdataByteLimit".to_owned(), - r#type: "uint256".to_owned(), - }, - Eip712DomainType { name: "maxFeePerGas".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { - name: "maxPriorityFeePerGas".to_owned(), - r#type: "uint256".to_owned(), - }, - Eip712DomainType { name: "paymaster".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { name: "nonce".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { name: "value".to_owned(), r#type: "uint256".to_owned() }, - Eip712DomainType { name: "data".to_owned(), r#type: "bytes".to_owned() }, - Eip712DomainType { name: "factoryDeps".to_owned(), r#type: "bytes32[]".to_owned() }, - Eip712DomainType { name: "paymasterInput".to_owned(), r#type: "bytes".to_owned() }, - ], - ); - types -} diff --git a/crates/zksync/core/src/lib.rs b/crates/zksync/core/src/lib.rs index 80af94fcd..3553b54e1 100644 --- a/crates/zksync/core/src/lib.rs +++ b/crates/zksync/core/src/lib.rs @@ -18,18 +18,14 @@ pub mod vm; /// ZKSync Era State implementation. pub mod state; -use alloy_network::{AnyNetwork, TxSigner}; +use alloy_network::AnyNetwork; use alloy_primitives::{address, hex, keccak256, Address, Bytes, U256 as rU256}; use alloy_provider::Provider; use alloy_rpc_types::TransactionRequest; use alloy_serde::WithOtherFields; -use alloy_signer::Signature; use alloy_transport::Transport; -use convert::{ - ConvertAddress, ConvertBytes, ConvertH160, ConvertH256, ConvertRU256, ConvertSignature, - ToSignable, -}; -use eyre::{eyre, OptionExt}; +use convert::{ConvertAddress, ConvertH160, ConvertH256, ConvertRU256}; +use eyre::eyre; use serde::{Deserialize, Serialize}; pub use utils::{fix_l2_gas_limit, fix_l2_gas_price}; @@ -42,13 +38,10 @@ pub use zksync_types::{ IMMUTABLE_SIMULATOR_STORAGE_ADDRESS, KNOWN_CODES_STORAGE_ADDRESS, L2_BASE_TOKEN_ADDRESS, NONCE_HOLDER_ADDRESS, }; -use zksync_types::{utils::storage_key_for_eth_balance, U256}; -pub use zksync_utils::bytecode::hash_bytecode; -use zksync_web3_rs::{ - eip712::{Eip712Meta, Eip712Transaction, Eip712TransactionRequest, PaymasterParams}, - zks_provider::types::Fee, - zks_utils::EIP712_TX_TYPE, +use zksync_types::{ + fee::Fee, transaction_request::PaymasterParams, utils::storage_key_for_eth_balance, U256, }; +pub use zksync_utils::bytecode::hash_bytecode; type Result = std::result::Result; @@ -102,78 +95,6 @@ impl ZkTransactionMetadata { Self { factory_deps, paymaster_data } } } - -/// Creates a new signed EIP-712 transaction with the provided factory deps. -pub async fn new_eip712_transaction< - P: Provider, - S: TxSigner + Sync, - T: Transport + Clone, ->( - tx: WithOtherFields, - factory_deps: Vec>, - paymaster_data: Option, - provider: P, - signer: S, -) -> Result { - let from = tx.from.ok_or_eyre("`from` cannot be empty")?; - let to = tx - .to - .and_then(|to| match to { - alloy_primitives::TxKind::Create => None, - alloy_primitives::TxKind::Call(to) => Some(to), - }) - .ok_or_eyre("`to` cannot be empty")?; - let chain_id = tx.chain_id.ok_or_eyre("`chain_id` cannot be empty")?; - let nonce = tx.nonce.ok_or_eyre("`nonce` cannot be empty")?; - let gas_price = tx.gas_price.ok_or_eyre("`gas_price` cannot be empty")?; - - let data = tx.input.clone().into_input().unwrap_or_default(); - let mut custom_data = Eip712Meta::new().factory_deps(factory_deps); - if let Some(params) = paymaster_data { - custom_data = custom_data.paymaster_params(params); - } - - let mut deploy_request = Eip712TransactionRequest::new() - .r#type(EIP712_TX_TYPE) - .from(from.to_h160()) - .to(to.to_h160()) - .chain_id(chain_id) - .nonce(nonce) - .gas_price(gas_price) - .data(data.to_ethers()) - .custom_data(custom_data); - - let gas_price = provider - .get_gas_price() - .await - .map_err(|err| eyre!("failed retrieving gas_price {:?}", err))?; - let fee: Fee = provider - .raw_request("zks_estimateFee".into(), [deploy_request.clone()]) - .await - .map_err(|err| eyre!("failed estimating fee {:?}", err))?; - deploy_request = deploy_request - .gas_limit(fee.gas_limit) - .max_fee_per_gas(fee.max_fee_per_gas) - .max_priority_fee_per_gas(fee.max_priority_fee_per_gas) - .gas_price(gas_price); - - let signable: Eip712Transaction = deploy_request - .clone() - .try_into() - .map_err(|err| eyre!("failed converting deploy request to eip-712 tx {:?}", err))?; - - let mut signable = signable.to_signable_tx(); - let signature = - signer.sign_transaction(&mut signable).await.expect("Failed to sign typed data"); - let encoded_rlp = deploy_request - .rlp_signed(signature.to_ethers()) - .map_err(|err| eyre!("failed encoding deployment request {:?}", err))?; - - let tx = [&[EIP712_TX_TYPE], encoded_rlp.to_vec().as_slice()].concat().into(); - - Ok(tx) -} - /// Estimated gas from a ZK network. pub struct EstimatedGas { /// Estimated gas price. @@ -185,41 +106,11 @@ pub struct EstimatedGas { /// Estimates the gas parameters for the provided transaction. pub async fn estimate_gas, T: Transport + Clone>( tx: &WithOtherFields, - factory_deps: Vec>, provider: P, ) -> Result { - let to = tx - .to - .and_then(|to| match to { - alloy_primitives::TxKind::Create => None, - alloy_primitives::TxKind::Call(to) => Some(to), - }) - .ok_or_eyre("`to` cannot be empty")?; - let chain_id = tx.chain_id.ok_or_eyre("`chain_id` cannot be empty")?; - let nonce = tx.nonce.ok_or_eyre("`nonce` cannot be empty")?; - let gas_price = if let Some(gas_price) = tx.gas_price { - gas_price - } else { - provider.get_gas_price().await? - }; - let data = tx.input.clone().into_input().unwrap_or_default(); - let custom_data = Eip712Meta::new().factory_deps(factory_deps); - - let mut deploy_request = Eip712TransactionRequest::new() - .r#type(EIP712_TX_TYPE) - .to(to.to_h160()) - .chain_id(chain_id) - .nonce(nonce) - .gas_price(gas_price) - .data(data.to_ethers()) - .custom_data(custom_data); - if let Some(from) = tx.from { - deploy_request = deploy_request.from(from.to_h160()) - } - let gas_price = provider.get_gas_price().await.unwrap(); let fee: Fee = provider - .raw_request("zks_estimateFee".into(), [deploy_request.clone()]) + .raw_request("zks_estimateFee".into(), [tx.clone()]) .await .map_err(|err| eyre!("failed rpc call for estimating fee: {:?}", err))?; diff --git a/crates/zksync/core/src/utils.rs b/crates/zksync/core/src/utils.rs index 191db267f..0f58aa4cc 100644 --- a/crates/zksync/core/src/utils.rs +++ b/crates/zksync/core/src/utils.rs @@ -32,7 +32,7 @@ use alloy_primitives::hex; use eyre::Result; use url::Url; use zksync_basic_types::U256; -use zksync_web3_rs::types::H256; +use zksync_types::H256; /// Gets the RPC URL for Ethereum. /// diff --git a/deny.toml b/deny.toml index 303bfec5b..a30889bca 100644 --- a/deny.toml +++ b/deny.toml @@ -110,9 +110,7 @@ allow-git = [ "https://github.com/alloy-rs/alloy", "https://github.com/paradigmxyz/revm-inspectors", "https://github.com/bluealloy/revm", - "https://github.com/lambdaclass/zksync-web3-rs", "https://github.com/RustCrypto/hashes", - "https://github.com/jrigada/zksync-web3-rs.git", "https://github.com/Karrq/alloy", ] From af7babda62471dd56569c82233763d17b9cd235e Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Tue, 19 Nov 2024 11:22:30 +0100 Subject: [PATCH 06/13] use published alloy-zksync --- Cargo.toml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3ac53ffcf..c84828325 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -230,10 +230,7 @@ syn-solidity = "0.8.11" alloy-chains = "0.1" alloy-rlp = "0.3" alloy-trie = "0.6.0" -# alloy-zksync = "0.1.0" -# alloy-zksync = { git = "https://github.com/popzxc/alloy-zksync", branch = "main"} -# alloy-zksync = { git = "https://github.com/nbaztec/alloy-zksync", branch = "v0.5"} -alloy-zksync = { path = "../nbaztec-alloy-zksync" } +alloy-zksync = "0.5" ## op-alloy op-alloy-rpc-types = "0.5.0" From fe16ece2c0fe45e5c681ad514c8ef6336f9f27a3 Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Tue, 19 Nov 2024 12:01:58 +0100 Subject: [PATCH 07/13] cleanup --- Cargo.lock | 3 ++- crates/cast/bin/cmd/send.rs | 15 +++++++-------- crates/script/Cargo.toml | 2 -- crates/script/src/broadcast.rs | 24 +++++++++--------------- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 717976217..81a5d47a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -807,6 +807,8 @@ dependencies = [ [[package]] name = "alloy-zksync" version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65f279833c27d8116f15d9a294c0529a716b3303ae1296063c71729a74c2e8b5" dependencies = [ "alloy", "async-trait", @@ -4613,7 +4615,6 @@ dependencies = [ "tokio", "tracing", "yansi", - "zksync_types", ] [[package]] diff --git a/crates/cast/bin/cmd/send.rs b/crates/cast/bin/cmd/send.rs index e420dc7a8..5a8b6852d 100644 --- a/crates/cast/bin/cmd/send.rs +++ b/crates/cast/bin/cmd/send.rs @@ -11,6 +11,7 @@ use alloy_zksync::{ transaction_request::TransactionRequest as ZkTransactionRequest, unsigned_tx::eip712::PaymasterParams, Zksync, }, + provider::ZksyncProvider, wallet::ZksyncWallet, }; use cast::{Cast, ZkCast}; @@ -22,9 +23,7 @@ use foundry_cli::{ }; use foundry_common::ens::NameOrAddress; use foundry_config::Config; -use foundry_zksync_core::convert::ConvertU256; use std::{path::PathBuf, str::FromStr}; -use zksync_types::fee::Fee; /// ZkSync-specific paymaster parameters for transactions #[derive(Debug, Parser)] @@ -255,7 +254,7 @@ async fn cast_send, T: Transport + Clone>( handle_transaction_result(&cast, tx_hash, cast_async, confs, timeout).await } -async fn cast_send_zk, Z: Provider, T: Transport + Clone>( +async fn cast_send_zk, Z: ZksyncProvider, T: Transport + Clone>( provider: P, zk_provider: Z, tx: WithOtherFields, @@ -278,11 +277,11 @@ async fn cast_send_zk, Z: Provider, T: Tra zk_tx.set_paymaster(paymaster_params); } - let fee = provider.raw_request::<_, Fee>("zks_estimateFee".into(), [&zk_tx]).await.unwrap(); - zk_tx.set_gas_limit(fee.gas_limit.as_u64()); - zk_tx.set_max_fee_per_gas(fee.max_fee_per_gas.as_u128()); - zk_tx.set_max_priority_fee_per_gas(fee.max_priority_fee_per_gas.as_u128()); - zk_tx.set_gas_per_pubdata(fee.gas_per_pubdata_limit.to_ru256()); + let fee = zk_provider.estimate_fee(zk_tx.clone()).await?; + zk_tx.set_gas_limit(fee.gas_limit); + zk_tx.set_max_fee_per_gas(fee.max_fee_per_gas); + zk_tx.set_max_priority_fee_per_gas(fee.max_priority_fee_per_gas); + zk_tx.set_gas_per_pubdata(fee.gas_per_pubdata_limit); let cast = ZkCast::new(zk_provider, Cast::new(provider)); let pending_tx = cast.send_zk(zk_tx).await?; diff --git a/crates/script/Cargo.toml b/crates/script/Cargo.toml index a48ca8dac..96d00e09d 100644 --- a/crates/script/Cargo.toml +++ b/crates/script/Cargo.toml @@ -60,7 +60,5 @@ alloy-transport.workspace = true alloy-consensus.workspace = true alloy-zksync.workspace = true -zksync_types.workspace = true - [dev-dependencies] tempfile.workspace = true diff --git a/crates/script/src/broadcast.rs b/crates/script/src/broadcast.rs index fa7ac9a13..8d9ffa106 100644 --- a/crates/script/src/broadcast.rs +++ b/crates/script/src/broadcast.rs @@ -15,8 +15,9 @@ use alloy_provider::{utils::Eip1559Estimation, Provider}; use alloy_rpc_types::TransactionRequest; use alloy_serde::WithOtherFields; use alloy_transport::Transport; -use alloy_zksync::network::{ - transaction_request::TransactionRequest as ZkTransactionRequest, Zksync, +use alloy_zksync::{ + network::{transaction_request::TransactionRequest as ZkTransactionRequest, Zksync}, + provider::ZksyncProvider, }; use eyre::{bail, Context, Result}; use forge_verify::provider::VerificationProviderType; @@ -29,14 +30,10 @@ use foundry_common::{ TransactionMaybeSigned, }; use foundry_config::Config; -use foundry_zksync_core::{ - convert::{ConvertH160, ConvertU256}, - ZkTransactionMetadata, -}; +use foundry_zksync_core::{convert::ConvertH160, ZkTransactionMetadata}; use futures::{future::join_all, StreamExt}; use itertools::Itertools; use std::{cmp::Ordering, sync::Arc}; -use zksync_types::fee::Fee; pub async fn estimate_gas( tx: &mut WithOtherFields, @@ -137,14 +134,11 @@ pub async fn send_transaction( }, ); } - let fee = provider - .raw_request::<_, Fee>("zks_estimateFee".into(), [&zk_tx]) - .await - .unwrap(); - zk_tx.set_gas_limit(fee.gas_limit.as_u64()); - zk_tx.set_max_fee_per_gas(fee.max_fee_per_gas.as_u128()); - zk_tx.set_max_priority_fee_per_gas(fee.max_priority_fee_per_gas.as_u128()); - zk_tx.set_gas_per_pubdata(fee.gas_per_pubdata_limit.to_ru256()); + let fee = zk_provider.estimate_fee(zk_tx.clone()).await?; + zk_tx.set_gas_limit(fee.gas_limit); + zk_tx.set_max_fee_per_gas(fee.max_fee_per_gas); + zk_tx.set_max_priority_fee_per_gas(fee.max_priority_fee_per_gas); + zk_tx.set_gas_per_pubdata(fee.gas_per_pubdata_limit); let zk_signer = alloy_zksync::wallet::ZksyncWallet::new(signer.default_signer()); let signed = zk_tx.build(&zk_signer).await?.encoded_2718(); From 4522846ac1b1970d2eca2d4debf83ef194db571a Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Tue, 19 Nov 2024 12:46:48 +0100 Subject: [PATCH 08/13] clippy --- Cargo.lock | 9 ++++---- Cargo.toml | 40 +++++++++++++++++++--------------- crates/script/src/broadcast.rs | 4 +--- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 81a5d47a6..536844153 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,8 +97,7 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "alloy" version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea8ebf106e84a1c37f86244df7da0c7587e697b71a0d565cce079449b85ac6f8" +source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ "alloy-consensus", "alloy-contract", @@ -741,7 +740,7 @@ dependencies = [ [[package]] name = "alloy-transport-http" version = "0.5.4" -source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#31bccc864525b5ba64fefb8211363807c7a43d2d" +source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ "alloy-json-rpc", "alloy-transport", @@ -755,7 +754,7 @@ dependencies = [ [[package]] name = "alloy-transport-ipc" version = "0.5.4" -source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#31bccc864525b5ba64fefb8211363807c7a43d2d" +source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ "alloy-json-rpc", "alloy-pubsub", @@ -775,7 +774,7 @@ dependencies = [ [[package]] name = "alloy-transport-ws" version = "0.5.4" -source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#31bccc864525b5ba64fefb8211363807c7a43d2d" +source = "git+https://github.com/Karrq/alloy?branch=zksync-v0.5.4#21484592682f146ba8f50de0d90883a10e82d52f" dependencies = [ "alloy-pubsub", "alloy-transport", diff --git a/Cargo.toml b/Cargo.toml index c84828325..cad9fb0db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -242,7 +242,7 @@ anstyle = "1.0" terminal_size = "0.4" ## zksync -era_test_node = { git="https://github.com/matter-labs/era-test-node.git" , rev = "94503847b402f0161c3372d5f357a4cb16a2d66d" } +era_test_node = { git = "https://github.com/matter-labs/era-test-node.git", rev = "94503847b402f0161c3372d5f357a4cb16a2d66d" } zksync_basic_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec" } zksync_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec" } zksync_state = { git = "https://github.com/matter-labs/zksync-era.git", rev = "6c034f6e180cc92e99766f14c8840c90efa56cec" } @@ -350,27 +350,31 @@ yansi = { version = "1.0", features = ["detect-tty", "detect-env"] } # alloy-transport-ipc = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" } # alloy-transport-ws = { git = "https://github.com/alloy-rs/alloy", rev = "7fab7ee" } +alloy-rpc-client = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-signer-ledger = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-rpc-types-txpool = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-signer-trezor = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-json-rpc = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-signer = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } alloy-consensus = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-contract = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-eips = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-transport-http = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-rpc-types-anvil = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-serde = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-transport-ws = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-signer-local = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } alloy-genesis = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-json-rpc = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-network = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-network-primitives = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-contract = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } alloy-provider = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-signer-aws = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-rpc-types-eth = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-network-primitives = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-transport-ipc = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } alloy-pubsub = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-rpc-client = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-transport = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } alloy-rpc-types = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-eips = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-network = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } +alloy-rpc-types-engine = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } alloy-rpc-types-trace = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-rpc-types-eth = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-serde = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-signer = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-signer-aws = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } alloy-signer-gcp = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-signer-ledger = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-signer-local = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-signer-trezor = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-transport = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-transport-http = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-transport-ipc = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } -alloy-transport-ws = { git = "https://github.com/Karrq/alloy", branch = "zksync-v0.5.4" } diff --git a/crates/script/src/broadcast.rs b/crates/script/src/broadcast.rs index 8d9ffa106..f44de2289 100644 --- a/crates/script/src/broadcast.rs +++ b/crates/script/src/broadcast.rs @@ -122,9 +122,7 @@ pub async fn send_transaction( if let Some(zk) = zk { let mut zk_tx: ZkTransactionRequest = tx.inner.clone().into(); if !zk.factory_deps.is_empty() { - zk_tx.set_factory_deps( - zk.factory_deps.iter().map(|bytes| Bytes::from_iter(bytes)).collect(), - ); + zk_tx.set_factory_deps(zk.factory_deps.iter().map(Bytes::from_iter).collect()); } if let Some(paymaster_data) = &zk.paymaster_data { zk_tx.set_paymaster( From 15aad4c3f807785d2d414201b70ee4ffd0935415 Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Tue, 19 Nov 2024 13:13:32 +0100 Subject: [PATCH 09/13] clippy --- crates/forge/bin/cmd/create.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/forge/bin/cmd/create.rs b/crates/forge/bin/cmd/create.rs index 50957eb6d..a890fd869 100644 --- a/crates/forge/bin/cmd/create.rs +++ b/crates/forge/bin/cmd/create.rs @@ -1025,7 +1025,7 @@ where }; // create the tx object. Since we're deploying a contract, `to` is `None` - let tx = WithOtherFields::new(TransactionRequest::default().input(data.clone().into())); + let tx = WithOtherFields::new(TransactionRequest::default().input(data.into())); Ok(Deployer { client: self.client.clone(), From 58482b46ff36072fd41def1f0f4822c197c8fcf9 Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Tue, 19 Nov 2024 13:55:58 +0100 Subject: [PATCH 10/13] simplify estimate_fee calls --- Cargo.lock | 4 +--- crates/cast/bin/cmd/send.rs | 8 ++------ crates/script/src/broadcast.rs | 11 +++-------- crates/zksync/core/Cargo.toml | 4 +--- crates/zksync/core/src/lib.rs | 32 +++++++++++++++++--------------- 5 files changed, 24 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 536844153..79fc2f606 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5341,11 +5341,9 @@ version = "0.0.2" dependencies = [ "alloy-network", "alloy-primitives", - "alloy-provider", - "alloy-rpc-types", - "alloy-serde", "alloy-sol-types", "alloy-transport", + "alloy-zksync", "ansiterm", "era_test_node", "eyre", diff --git a/crates/cast/bin/cmd/send.rs b/crates/cast/bin/cmd/send.rs index 5a8b6852d..d6573b315 100644 --- a/crates/cast/bin/cmd/send.rs +++ b/crates/cast/bin/cmd/send.rs @@ -1,5 +1,5 @@ use crate::tx::{self, CastTxBuilder}; -use alloy_network::{AnyNetwork, EthereumWallet, TransactionBuilder}; +use alloy_network::{AnyNetwork, EthereumWallet}; use alloy_primitives::{Address, Bytes, TxHash}; use alloy_provider::{Provider, ProviderBuilder}; use alloy_rpc_types::TransactionRequest; @@ -277,11 +277,7 @@ async fn cast_send_zk, Z: ZksyncProvider, T: Trans zk_tx.set_paymaster(paymaster_params); } - let fee = zk_provider.estimate_fee(zk_tx.clone()).await?; - zk_tx.set_gas_limit(fee.gas_limit); - zk_tx.set_max_fee_per_gas(fee.max_fee_per_gas); - zk_tx.set_max_priority_fee_per_gas(fee.max_priority_fee_per_gas); - zk_tx.set_gas_per_pubdata(fee.gas_per_pubdata_limit); + foundry_zksync_core::estimate_gas(&mut zk_tx, &zk_provider).await?; let cast = ZkCast::new(zk_provider, Cast::new(provider)); let pending_tx = cast.send_zk(zk_tx).await?; diff --git a/crates/script/src/broadcast.rs b/crates/script/src/broadcast.rs index f44de2289..7253cddbb 100644 --- a/crates/script/src/broadcast.rs +++ b/crates/script/src/broadcast.rs @@ -15,9 +15,8 @@ use alloy_provider::{utils::Eip1559Estimation, Provider}; use alloy_rpc_types::TransactionRequest; use alloy_serde::WithOtherFields; use alloy_transport::Transport; -use alloy_zksync::{ - network::{transaction_request::TransactionRequest as ZkTransactionRequest, Zksync}, - provider::ZksyncProvider, +use alloy_zksync::network::{ + transaction_request::TransactionRequest as ZkTransactionRequest, Zksync, }; use eyre::{bail, Context, Result}; use forge_verify::provider::VerificationProviderType; @@ -132,11 +131,7 @@ pub async fn send_transaction( }, ); } - let fee = zk_provider.estimate_fee(zk_tx.clone()).await?; - zk_tx.set_gas_limit(fee.gas_limit); - zk_tx.set_max_fee_per_gas(fee.max_fee_per_gas); - zk_tx.set_max_priority_fee_per_gas(fee.max_priority_fee_per_gas); - zk_tx.set_gas_per_pubdata(fee.gas_per_pubdata_limit); + foundry_zksync_core::estimate_gas(&mut zk_tx, &zk_provider).await?; let zk_signer = alloy_zksync::wallet::ZksyncWallet::new(signer.default_signer()); let signed = zk_tx.build(&zk_signer).await?.encoded_2718(); diff --git a/crates/zksync/core/Cargo.toml b/crates/zksync/core/Cargo.toml index 97a03ca66..0ab76fa90 100644 --- a/crates/zksync/core/Cargo.toml +++ b/crates/zksync/core/Cargo.toml @@ -18,10 +18,8 @@ foundry-cheatcodes-common.workspace = true alloy-primitives.workspace = true alloy-network.workspace = true alloy-sol-types.workspace = true -alloy-serde.workspace = true -alloy-provider.workspace = true alloy-transport.workspace = true -alloy-rpc-types.workspace = true +alloy-zksync.workspace = true itertools.workspace = true revm = { workspace = true, default-features = false, features = [ "std", diff --git a/crates/zksync/core/src/lib.rs b/crates/zksync/core/src/lib.rs index 3553b54e1..114e903ee 100644 --- a/crates/zksync/core/src/lib.rs +++ b/crates/zksync/core/src/lib.rs @@ -18,12 +18,13 @@ pub mod vm; /// ZKSync Era State implementation. pub mod state; -use alloy_network::AnyNetwork; +use alloy_network::TransactionBuilder; use alloy_primitives::{address, hex, keccak256, Address, Bytes, U256 as rU256}; -use alloy_provider::Provider; -use alloy_rpc_types::TransactionRequest; -use alloy_serde::WithOtherFields; use alloy_transport::Transport; +use alloy_zksync::{ + network::transaction_request::TransactionRequest as ZkTransactionRequest, + provider::ZksyncProvider, +}; use convert::{ConvertAddress, ConvertH160, ConvertH256, ConvertRU256}; use eyre::eyre; use serde::{Deserialize, Serialize}; @@ -39,7 +40,7 @@ pub use zksync_types::{ NONCE_HOLDER_ADDRESS, }; use zksync_types::{ - fee::Fee, transaction_request::PaymasterParams, utils::storage_key_for_eth_balance, U256, + transaction_request::PaymasterParams, utils::storage_key_for_eth_balance, U256, }; pub use zksync_utils::bytecode::hash_bytecode; @@ -104,17 +105,18 @@ pub struct EstimatedGas { } /// Estimates the gas parameters for the provided transaction. -pub async fn estimate_gas, T: Transport + Clone>( - tx: &WithOtherFields, +/// This will call `estimateFee` method on the rpc and set the gas parameters on the transaction. +pub async fn estimate_gas, T: Transport + Clone>( + tx: &mut ZkTransactionRequest, provider: P, -) -> Result { - let gas_price = provider.get_gas_price().await.unwrap(); - let fee: Fee = provider - .raw_request("zks_estimateFee".into(), [tx.clone()]) - .await - .map_err(|err| eyre!("failed rpc call for estimating fee: {:?}", err))?; - - Ok(EstimatedGas { price: gas_price, limit: fee.gas_limit.low_u64() }) +) -> Result<()> { + let fee = provider.estimate_fee(tx.clone()).await?; + tx.set_gas_limit(fee.gas_limit); + tx.set_max_fee_per_gas(fee.max_fee_per_gas); + tx.set_max_priority_fee_per_gas(fee.max_priority_fee_per_gas); + tx.set_gas_per_pubdata(fee.gas_per_pubdata_limit); + + Ok(()) } /// Returns true if the provided address is a reserved zkSync system address From e02708957358a4876598c6d11759e066f9667feb Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Tue, 19 Nov 2024 17:57:52 +0100 Subject: [PATCH 11/13] avoid initializing signer twice --- crates/cast/bin/cmd/send.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/crates/cast/bin/cmd/send.rs b/crates/cast/bin/cmd/send.rs index d6573b315..930db113d 100644 --- a/crates/cast/bin/cmd/send.rs +++ b/crates/cast/bin/cmd/send.rs @@ -193,26 +193,25 @@ impl SendTxArgs { // If we cannot successfully instantiate a local signer, then we will assume we don't have // enough information to sign and we must bail. } else { - // Retrieve the signer, and bail if it can't be constructed. - let signer = eth.wallet.signer().await?; - let zk_signer = eth.wallet.signer().await?; - let from = signer.address(); + // NOTE(zk): Avoid initializing `signer` twice as it will error out with Ledger, so we + // move the signers to their respective blocks. + if zksync_params.zksync { + // Retrieve the signer, and bail if it can't be constructed. + let zk_signer: foundry_wallets::WalletSigner = eth.wallet.signer().await?; + let from = zk_signer.address(); - tx::validate_from_address(eth.wallet.from, from)?; + tx::validate_from_address(eth.wallet.from, from)?; - if zksync_params.zksync { // Zksync transaction - let (tx, _) = builder.build(&signer).await?; - - let wallet = EthereumWallet::from(signer); - let provider = ProviderBuilder::<_, _, AnyNetwork>::default() - .wallet(wallet) - .on_provider(&provider); + let (tx, _) = builder.build(&zk_signer).await?; let zk_wallet = ZksyncWallet::from(zk_signer); let zk_provider = ProviderBuilder::<_, _, Zksync>::default() - .wallet(zk_wallet) + .wallet(zk_wallet.clone()) .on_provider(&zk_provider); + let provider = ProviderBuilder::<_, _, AnyNetwork>::default() + .wallet(zk_wallet) + .on_provider(&provider); cast_send_zk( provider, @@ -225,6 +224,12 @@ impl SendTxArgs { ) .await } else { + // Retrieve the signer, and bail if it can't be constructed. + let signer = eth.wallet.signer().await?; + let from = signer.address(); + + tx::validate_from_address(eth.wallet.from, from)?; + // Standard transaction let (tx, _) = builder.build(&signer).await?; From 2bc2b6dff8df9ecfb1bbbc34f690c3908a3939c7 Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Wed, 20 Nov 2024 15:03:09 +0100 Subject: [PATCH 12/13] cleanup create, dead code --- crates/cast/src/lib.rs | 15 +-------------- crates/forge/bin/cmd/create.rs | 35 ++++++++++------------------------ 2 files changed, 11 insertions(+), 39 deletions(-) diff --git a/crates/cast/src/lib.rs b/crates/cast/src/lib.rs index a1577bc18..d8776e3b5 100644 --- a/crates/cast/src/lib.rs +++ b/crates/cast/src/lib.rs @@ -94,7 +94,7 @@ where T: Transport + Clone, Z: Provider, { - /// Creates a new Cast instance from the provided client + /// Creates a new ZkCast instance from the provided client and Cast instance /// /// # Example /// @@ -125,19 +125,6 @@ where Ok(res) } } - -// pub struct Cast { -// provider: P, -// zk_provider: Option, -// transport: PhantomData, -// } - -// impl Cast -// where -// T: Transport + Clone, -// P: Provider, -// Z: Provider, -// { pub struct Cast { provider: P, transport: PhantomData, diff --git a/crates/forge/bin/cmd/create.rs b/crates/forge/bin/cmd/create.rs index a890fd869..1bcd25972 100644 --- a/crates/forge/bin/cmd/create.rs +++ b/crates/forge/bin/cmd/create.rs @@ -2,7 +2,7 @@ use alloy_chains::Chain; use alloy_dyn_abi::{DynSolValue, JsonAbiExt, Specifier}; use alloy_json_abi::{Constructor, JsonAbi}; use alloy_network::{AnyNetwork, EthereumWallet, TransactionBuilder}; -use alloy_primitives::{hex, Address, Bytes, U256}; +use alloy_primitives::{hex, Address, Bytes}; use alloy_provider::{PendingTransactionError, Provider, ProviderBuilder}; use alloy_rpc_types::{AnyTransactionReceipt, TransactionRequest}; use alloy_serde::WithOtherFields; @@ -10,7 +10,6 @@ use alloy_signer::Signer; use alloy_transport::{Transport, TransportError}; use alloy_zksync::{ network::{unsigned_tx::eip712::PaymasterParams, Zksync}, - provider::ZksyncProvider, wallet::ZksyncWallet, }; use clap::{Parser, ValueHint}; @@ -576,19 +575,9 @@ impl CreateArgs { })?; let is_legacy = self.tx.legacy || Chain::from(chain).is_legacy(); - // The large L2 gas per pubdata to sign. This gas is enough to ensure that - // any reasonable limit will be accepted. Note, that the operator is NOT required to - // use the honest value of gas per pubdata and it can use any value up to the one signed by - // the user. In the future releases, we will provide a way to estimate the current - // gasPerPubdata. - pub const DEFAULT_GAS_PER_PUBDATA_LIMIT: u64 = 50000; - - deployer.tx = deployer - .tx - .with_gas_per_pubdata(U256::from(DEFAULT_GAS_PER_PUBDATA_LIMIT)) - .with_factory_deps( - zk_data.factory_deps.clone().into_iter().map(|dep| dep.into()).collect(), - ); + deployer.tx = deployer.tx.with_factory_deps( + zk_data.factory_deps.clone().into_iter().map(|dep| dep.into()).collect(), + ); if let Some(paymaster_params) = zk_data.paymaster_params { deployer.tx.set_paymaster(paymaster_params); } @@ -616,6 +605,9 @@ impl CreateArgs { }; deployer.tx.set_gas_price(gas_price); + // estimate fee + foundry_zksync_core::estimate_gas(&mut deployer.tx, &provider).await?; + if !is_legacy { let estimate = provider.estimate_eip1559_fees(None).await.wrap_err("Failed to estimate EIP1559 fees. This chain might not support EIP1559, try adding --legacy to your command.")?; let priority_fee = if let Some(priority_fee) = self.tx.priority_gas_price { @@ -633,16 +625,9 @@ impl CreateArgs { deployer.tx.set_max_priority_fee_per_gas(priority_fee); } - let fee = provider - .estimate_fee(deployer.tx.clone()) - .await - .map_err(|err| eyre::eyre!("failed rpc call for estimating fee: {:?}", err))?; - - deployer.tx.set_gas_limit(if let Some(gas_limit) = self.tx.gas_limit { - gas_limit.to::() - } else { - fee.gas_limit - }); + if let Some(gas_limit) = self.tx.gas_limit { + deployer.tx.set_gas_limit(gas_limit.to::()); + }; // Before we actually deploy the contract we try check if the verify settings are valid let mut constructor_args = None; From 74f2c7d855f6260effc151512417b13b95f58294 Mon Sep 17 00:00:00 2001 From: Nisheeth Barthwal Date: Wed, 20 Nov 2024 17:07:04 +0100 Subject: [PATCH 13/13] fix comment --- crates/forge/bin/cmd/create.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/forge/bin/cmd/create.rs b/crates/forge/bin/cmd/create.rs index cbb9d0d0a..2cdb55890 100644 --- a/crates/forge/bin/cmd/create.rs +++ b/crates/forge/bin/cmd/create.rs @@ -1084,7 +1084,8 @@ where ) .into(); - // create the tx object. Since we're deploying a contract, `to` is `None` + // create the tx object. Since we're deploying a contract, `to` is + // `CONTRACT_DEPLOYER_ADDRESS` let tx: alloy_zksync::network::transaction_request::TransactionRequest = TransactionRequest::default() .to(foundry_zksync_core::CONTRACT_DEPLOYER_ADDRESS.to_address())