From b0c1a0a4e34de4bb2e56fa082b5a45cf55a28f7c Mon Sep 17 00:00:00 2001 From: Jrigada Date: Mon, 20 Jan 2025 12:27:33 -0300 Subject: [PATCH] simplify approach --- crates/cast/bin/cmd/send.rs | 2 +- crates/cli/src/opts/build/zksync.rs | 5 ----- crates/config/src/zksync.rs | 4 ---- crates/evm/evm/src/executors/strategy.rs | 7 ------- crates/forge/bin/cmd/create.rs | 2 +- crates/forge/tests/it/zk/gas.rs | 2 +- crates/script/src/broadcast.rs | 8 +++----- crates/script/src/lib.rs | 9 ++++----- .../zksync/src/cheatcode/runner/mod.rs | 7 +------ crates/strategy/zksync/src/executor/runner.rs | 10 ---------- crates/zksync/core/src/lib.rs | 20 ++++++++----------- crates/zksync/core/src/vm/env.rs | 3 --- 12 files changed, 19 insertions(+), 60 deletions(-) diff --git a/crates/cast/bin/cmd/send.rs b/crates/cast/bin/cmd/send.rs index 9694e8e49..4af89835b 100644 --- a/crates/cast/bin/cmd/send.rs +++ b/crates/cast/bin/cmd/send.rs @@ -286,7 +286,7 @@ async fn cast_send_zk, Z: ZksyncProvider, T: Trans zk_tx.set_paymaster_params(paymaster_params); } - foundry_zksync_core::estimate_fee(&mut zk_tx, &zk_provider, 130).await?; + foundry_zksync_core::estimate_fee(&mut zk_tx, &zk_provider, 130, None).await?; let cast = ZkCast::new(zk_provider, Cast::new(provider)); let pending_tx = cast.send_zk(zk_tx).await?; diff --git a/crates/cli/src/opts/build/zksync.rs b/crates/cli/src/opts/build/zksync.rs index 89ab86477..1a0cb9d74 100644 --- a/crates/cli/src/opts/build/zksync.rs +++ b/crates/cli/src/opts/build/zksync.rs @@ -133,10 +133,6 @@ pub struct ZkSyncArgs { )] #[serde(skip_serializing_if = "Option::is_none")] pub suppressed_errors: Option>, - - /// Gas per pubdata to be set on transactions when broadcasting on scripts - #[clap(long = "zk-gas-per-pubdata", value_name = "GAS_PER_PUBDATA")] - pub gas_per_pubdata: Option, } impl ZkSyncArgs { @@ -176,7 +172,6 @@ impl ZkSyncArgs { let suppressed_errors = self.suppressed_errors.clone().map(|values| values.into_iter().collect::>()); set_if_some!(suppressed_errors, zksync.suppressed_errors); - set_if_some!(self.gas_per_pubdata, zksync.gas_per_pubdata); zksync } diff --git a/crates/config/src/zksync.rs b/crates/config/src/zksync.rs index 42a0d8b2b..0181bd18f 100644 --- a/crates/config/src/zksync.rs +++ b/crates/config/src/zksync.rs @@ -74,9 +74,6 @@ pub struct ZkSyncConfig { // zksolc suppressed errors. pub suppressed_errors: HashSet, - - // Gas per pubdata - pub gas_per_pubdata: Option, } impl Default for ZkSyncConfig { @@ -96,7 +93,6 @@ impl Default for ZkSyncConfig { optimizer_details: Default::default(), suppressed_errors: Default::default(), suppressed_warnings: Default::default(), - gas_per_pubdata: Default::default(), } } } diff --git a/crates/evm/evm/src/executors/strategy.rs b/crates/evm/evm/src/executors/strategy.rs index 6025972ae..a719e841a 100644 --- a/crates/evm/evm/src/executors/strategy.rs +++ b/crates/evm/evm/src/executors/strategy.rs @@ -110,13 +110,6 @@ pub trait ExecutorStrategyExt { ) { } - fn zksync_set_gas_per_pubdata( - &self, - _ctx: &mut dyn ExecutorStrategyContext, - _gas_per_pubdata: u64, - ) { - } - /// Set the fork environment on the context. fn zksync_set_fork_env( &self, diff --git a/crates/forge/bin/cmd/create.rs b/crates/forge/bin/cmd/create.rs index f0483e25e..c8d4a4ddf 100644 --- a/crates/forge/bin/cmd/create.rs +++ b/crates/forge/bin/cmd/create.rs @@ -692,7 +692,7 @@ impl CreateArgs { deployer.tx.set_gas_price(gas_price); // estimate fee - foundry_zksync_core::estimate_fee(&mut deployer.tx, &provider, 130).await?; + foundry_zksync_core::estimate_fee(&mut deployer.tx, &provider, 130, None).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.")?; diff --git a/crates/forge/tests/it/zk/gas.rs b/crates/forge/tests/it/zk/gas.rs index 916068e80..c80e9044c 100644 --- a/crates/forge/tests/it/zk/gas.rs +++ b/crates/forge/tests/it/zk/gas.rs @@ -68,7 +68,7 @@ forgetest_async!(zk_script_execution_with_gas_multiplier, |prj, cmd| { cmd.arg("script").args(&sufficient_multiplier_args); let stdout = cmd.assert_success().get_output().stdout_lossy(); assert!(stdout.contains("ONCHAIN EXECUTION COMPLETE & SUCCESSFUL")); -}); +}); forgetest_async!(zk_script_execution_with_gas_per_pubdata, |prj, cmd| { // Setup diff --git a/crates/script/src/broadcast.rs b/crates/script/src/broadcast.rs index ab6103320..ecd9f424d 100644 --- a/crates/script/src/broadcast.rs +++ b/crates/script/src/broadcast.rs @@ -70,6 +70,7 @@ pub async fn send_transaction( is_fixed_gas_limit: bool, estimate_via_rpc: bool, estimate_multiplier: u64, + gas_per_pubdata: Option, ) -> Result { let zk_tx_meta = if let SendTransactionKind::Raw(tx, _) | SendTransactionKind::Unlocked(tx) = &mut kind { @@ -142,11 +143,7 @@ pub async fn send_transaction( ); } - if let Some(gas_per_pubdata) = zk_tx_meta.gas_per_pubdata { - zk_tx.set_gas_per_pubdata(alloy_primitives::Uint::from(gas_per_pubdata)); - } - - foundry_zksync_core::estimate_fee(&mut zk_tx, &zk_provider, estimate_multiplier) + foundry_zksync_core::estimate_fee(&mut zk_tx, &zk_provider, estimate_multiplier, gas_per_pubdata) .await?; let zk_signer = alloy_zksync::wallet::ZksyncWallet::new(signer.default_signer()); @@ -445,6 +442,7 @@ impl BundledState { *is_fixed_gas_limit, estimate_via_rpc, self.args.gas_estimate_multiplier, + self.args.gas_per_pubdata, ); pending_transactions.push(fut); } diff --git a/crates/script/src/lib.rs b/crates/script/src/lib.rs index fb093d206..79b08fca2 100644 --- a/crates/script/src/lib.rs +++ b/crates/script/src/lib.rs @@ -217,6 +217,10 @@ pub struct ScriptArgs { #[command(flatten)] pub retry: RetryArgs, + + /// Gas per pubdata + #[clap(long = "zk-gas-per-pubdata", value_name = "GAS_PER_PUBDATA")] + pub gas_per_pubdata: Option, } impl ScriptArgs { @@ -638,11 +642,6 @@ impl ScriptConfig { strategy.context.as_mut(), dual_compiled_contracts, ); - if let Some(gas_per_pubdata) = self.config.zksync.gas_per_pubdata { - strategy - .runner - .zksync_set_gas_per_pubdata(strategy.context.as_mut(), gas_per_pubdata); - } if let Some(fork_url) = &self.evm_opts.fork_url { strategy.runner.zksync_set_fork_env(strategy.context.as_mut(), fork_url, &env)?; diff --git a/crates/strategy/zksync/src/cheatcode/runner/mod.rs b/crates/strategy/zksync/src/cheatcode/runner/mod.rs index 3bb455143..b14217d01 100644 --- a/crates/strategy/zksync/src/cheatcode/runner/mod.rs +++ b/crates/strategy/zksync/src/cheatcode/runner/mod.rs @@ -126,8 +126,6 @@ impl CheatcodeInspectorStrategyRunner for ZksyncCheatcodeInspectorStrategyRunner paymaster_input: paymaster_data.input.to_vec(), }); - let gas_per_pubdata = ctx.zk_env.gas_per_pubdata; - let rpc = ecx_inner.db.active_fork_url(); let injected_factory_deps = ctx @@ -167,7 +165,6 @@ impl CheatcodeInspectorStrategyRunner for ZksyncCheatcodeInspectorStrategyRunner serde_json::to_value(ZkTransactionMetadata::new( factory_deps, paymaster_params.clone(), - gas_per_pubdata, )) .expect("failed encoding json"), ); @@ -195,7 +192,6 @@ impl CheatcodeInspectorStrategyRunner for ZksyncCheatcodeInspectorStrategyRunner serde_json::to_value(ZkTransactionMetadata::new( zk_tx_factory_deps, paymaster_params, - gas_per_pubdata, )) .expect("failed encoding json"), ); @@ -263,7 +259,6 @@ impl CheatcodeInspectorStrategyRunner for ZksyncCheatcodeInspectorStrategyRunner paymaster: paymaster_data.address.to_h160(), paymaster_input: paymaster_data.input.to_vec(), }); - let gas_per_pubdata = ctx.zk_env.gas_per_pubdata; let factory_deps = if call.target_address == DEFAULT_CREATE2_DEPLOYER_ZKSYNC { // We shouldn't need factory_deps for CALLs factory_deps.clone() @@ -271,7 +266,7 @@ impl CheatcodeInspectorStrategyRunner for ZksyncCheatcodeInspectorStrategyRunner // For this case we use only the injected factory deps injected_factory_deps }; - let zk_tx = ZkTransactionMetadata::new(factory_deps, paymaster_params, gas_per_pubdata); + let zk_tx = ZkTransactionMetadata::new(factory_deps, paymaster_params); let mut tx_req = TransactionRequest { from: Some(broadcast.new_origin), to: Some(TxKind::from(Some(call.target_address))), diff --git a/crates/strategy/zksync/src/executor/runner.rs b/crates/strategy/zksync/src/executor/runner.rs index e3ed5c0c4..347d9ae1b 100644 --- a/crates/strategy/zksync/src/executor/runner.rs +++ b/crates/strategy/zksync/src/executor/runner.rs @@ -154,15 +154,6 @@ impl ExecutorStrategyExt for ZksyncExecutorStrategyRunner { ctx.dual_compiled_contracts = dual_compiled_contracts; } - fn zksync_set_gas_per_pubdata( - &self, - ctx: &mut dyn ExecutorStrategyContext, - gas_per_pubdata: u64, - ) { - let ctx = get_context(ctx); - ctx.zk_env.gas_per_pubdata = Some(gas_per_pubdata); - } - fn zksync_set_fork_env( &self, ctx: &mut dyn ExecutorStrategyContext, @@ -182,7 +173,6 @@ impl ExecutorStrategyExt for ZksyncExecutorStrategyRunner { if let Some(block_details) = maybe_block_details { ctx.zk_env = ZkEnv { - gas_per_pubdata: ctx.zk_env.gas_per_pubdata, l1_gas_price: block_details .l1_gas_price .try_into() diff --git a/crates/zksync/core/src/lib.rs b/crates/zksync/core/src/lib.rs index 50395082b..9841c2218 100644 --- a/crates/zksync/core/src/lib.rs +++ b/crates/zksync/core/src/lib.rs @@ -113,18 +113,12 @@ pub struct ZkTransactionMetadata { pub factory_deps: Vec>, /// Paymaster data for ZK transactions. pub paymaster_data: Option, - /// Gas per pubdata for ZK transactions. - pub gas_per_pubdata: Option, } impl ZkTransactionMetadata { /// Create a new [`ZkTransactionMetadata`] with the given factory deps - pub fn new( - factory_deps: Vec>, - paymaster_data: Option, - gas_per_pubdata: Option, - ) -> Self { - Self { factory_deps, paymaster_data, gas_per_pubdata } + pub fn new(factory_deps: Vec>, paymaster_data: Option) -> Self { + Self { factory_deps, paymaster_data } } } /// Estimated gas from a ZK network. @@ -141,18 +135,20 @@ pub async fn estimate_fee, T: Transport + Clone>( tx: &mut ZkTransactionRequest, provider: P, estimate_multiplier: u64, + gas_per_pubdata: Option, ) -> Result<()> { let fee = provider.estimate_fee(tx.clone()).await?; tx.set_gas_limit(fee.gas_limit * estimate_multiplier / 100); // If user provided a gas price, use it for both maxFeePerGas let max_fee = tx.max_fee_per_gas().unwrap_or(fee.max_fee_per_gas); let max_priority_fee = tx.max_priority_fee_per_gas().unwrap_or(fee.max_priority_fee_per_gas); + let gas_per_pubdata = match gas_per_pubdata { + Some(value) => rU256::from(value), + None => fee.gas_per_pubdata_limit, + }; tx.set_max_fee_per_gas(max_fee); tx.set_max_priority_fee_per_gas(max_priority_fee); - match tx.gas_per_pubdata() { - Some(v) if !v.is_zero() => (), - _ => tx.set_gas_per_pubdata(fee.gas_per_pubdata_limit), - } + tx.set_gas_per_pubdata(gas_per_pubdata); Ok(()) } diff --git a/crates/zksync/core/src/vm/env.rs b/crates/zksync/core/src/vm/env.rs index 68cfee348..3ae8a073a 100644 --- a/crates/zksync/core/src/vm/env.rs +++ b/crates/zksync/core/src/vm/env.rs @@ -23,8 +23,6 @@ pub struct ZkEnv { pub fair_l2_gas_price: u64, /// fair pubdata price pub fair_pubdata_price: u64, - /// gas per pubdata - pub gas_per_pubdata: Option, } impl Default for ZkEnv { @@ -35,7 +33,6 @@ impl Default for ZkEnv { l1_gas_price: 0, fair_l2_gas_price: 0, fair_pubdata_price: 1000, - gas_per_pubdata: None, } } }