From 60f7ed0cedcf32cfa727823a53caf8e94631904f Mon Sep 17 00:00:00 2001 From: Jrigada Date: Wed, 16 Oct 2024 10:57:15 -0300 Subject: [PATCH 1/7] Add paymaster support to cast send --- Cargo.lock | 2 + crates/cast/Cargo.toml | 2 + crates/cast/bin/cmd/send.rs | 85 +++++++++++++++++++++++++++++++++---- 3 files changed, 81 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 848c000df..da7206a48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4890,6 +4890,7 @@ dependencies = [ "foundry-evm", "foundry-test-utils", "foundry-wallets", + "foundry-zksync-core", "futures 0.3.30", "indicatif", "itertools 0.13.0", @@ -4906,6 +4907,7 @@ dependencies = [ "tracing", "vergen", "yansi 1.0.1", + "zksync-web3-rs", ] [[package]] diff --git a/crates/cast/Cargo.toml b/crates/cast/Cargo.toml index 46f8eac95..154015538 100644 --- a/crates/cast/Cargo.toml +++ b/crates/cast/Cargo.toml @@ -35,6 +35,8 @@ foundry-compilers.workspace = true 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"] } diff --git a/crates/cast/bin/cmd/send.rs b/crates/cast/bin/cmd/send.rs index cf3582fe0..6cc67048c 100644 --- a/crates/cast/bin/cmd/send.rs +++ b/crates/cast/bin/cmd/send.rs @@ -1,5 +1,6 @@ use crate::tx::{self, CastTxBuilder}; use alloy_network::{AnyNetwork, EthereumWallet}; +use alloy_primitives::{Address, Bytes, TxHash}; use alloy_provider::{Provider, ProviderBuilder}; use alloy_rpc_types::TransactionRequest; use alloy_serde::WithOtherFields; @@ -14,7 +15,21 @@ use foundry_cli::{ }; use foundry_common::{cli_warn, ens::NameOrAddress}; use foundry_config::Config; +use foundry_zksync_core::{self, convert::ConvertAddress}; use std::{path::PathBuf, str::FromStr}; +use zksync_web3_rs::eip712::PaymasterParams; + +/// ZkSync-specific paymaster parameters for transactions +#[derive(Debug, Parser)] +pub struct ZksyncParams { + /// The paymaster address for the ZKSync transaction + #[arg(long = "zk-paymaster-address")] + paymaster_address: Option, + + /// The paymaster input for the ZKSync transaction + #[arg(long = "zk-paymaster-input")] + paymaster_input: Option, +} /// CLI arguments for `cast send`. #[derive(Debug, Parser)] @@ -69,6 +84,9 @@ pub struct SendTxArgs { help_heading = "Transaction options" )] path: Option, + + #[command(flatten)] + zksync_params: ZksyncParams, } #[derive(Debug, Parser)] @@ -103,6 +121,7 @@ impl SendTxArgs { unlocked, path, timeout, + zksync_params, } = self; let blob_data = if let Some(path) = path { Some(std::fs::read(path)?) } else { None }; @@ -171,14 +190,53 @@ impl SendTxArgs { tx::validate_from_address(eth.wallet.from, from)?; - let (tx, _) = builder.build(&signer).await?; - - let wallet = EthereumWallet::from(signer); - let provider = ProviderBuilder::<_, _, AnyNetwork>::default() - .wallet(wallet) - .on_provider(&provider); - - cast_send(provider, tx, cast_async, confirmations, timeout, to_json).await + let paymaster_address = zksync_params + .paymaster_address + .as_ref() + .map(|s| Address::from_str(s)) + .transpose()?; + let paymaster_input = + zksync_params.paymaster_input.as_ref().map(|s| Bytes::from_str(s)).transpose()?; + + if paymaster_address.is_some() || paymaster_input.is_some() { + // ZkSync transaction + let paymaster_address = paymaster_address.unwrap().to_h160(); + let paymaster_input = paymaster_input.unwrap().to_vec(); + + // Build EIP712 transaction for ZKSync + let tx = foundry_zksync_core::new_eip712_transaction( + builder.build(&signer).await?.0, + Vec::new(), // Empty factory_deps + Some(PaymasterParams { paymaster: paymaster_address, paymaster_input }), + &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, + confirmations, + timeout, + to_json, + ) + .await + } else { + // Standard transaction + let (tx, _) = builder.build(&signer).await?; + + let wallet = EthereumWallet::from(signer); + let provider = ProviderBuilder::<_, _, AnyNetwork>::default() + .wallet(wallet) + .on_provider(&provider); + + cast_send(provider, tx, cast_async, confirmations, timeout, to_json).await + } } } } @@ -196,6 +254,17 @@ async fn cast_send, T: Transport + Clone>( let tx_hash = pending_tx.inner().tx_hash(); + handle_transaction_result(&cast, &tx_hash, cast_async, confs, timeout, to_json).await +} + +async fn handle_transaction_result, T: Transport + Clone>( + cast: &Cast, + tx_hash: &TxHash, + cast_async: bool, + confs: u64, + timeout: u64, + to_json: bool, +) -> Result<()> { if cast_async { println!("{tx_hash:#x}"); } else { From 42f6bd13402c6f34cf35b5ca43e90d4881651d43 Mon Sep 17 00:00:00 2001 From: Jrigada Date: Wed, 16 Oct 2024 11:22:51 -0300 Subject: [PATCH 2/7] remove reference --- crates/cast/bin/cmd/send.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cast/bin/cmd/send.rs b/crates/cast/bin/cmd/send.rs index 6cc67048c..ada1c3675 100644 --- a/crates/cast/bin/cmd/send.rs +++ b/crates/cast/bin/cmd/send.rs @@ -254,7 +254,7 @@ async fn cast_send, T: Transport + Clone>( let tx_hash = pending_tx.inner().tx_hash(); - handle_transaction_result(&cast, &tx_hash, cast_async, confs, timeout, to_json).await + handle_transaction_result(&cast, tx_hash, cast_async, confs, timeout, to_json).await } async fn handle_transaction_result, T: Transport + Clone>( From 042c7471d93e223c76c5028834c4e171679f2b7c Mon Sep 17 00:00:00 2001 From: Jrigada Date: Thu, 17 Oct 2024 12:21:51 -0300 Subject: [PATCH 3/7] Add zksync flag to cast send and handle missing zk paymaster parameters --- crates/cast/bin/cmd/send.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/crates/cast/bin/cmd/send.rs b/crates/cast/bin/cmd/send.rs index ada1c3675..e733172eb 100644 --- a/crates/cast/bin/cmd/send.rs +++ b/crates/cast/bin/cmd/send.rs @@ -22,12 +22,16 @@ use zksync_web3_rs::eip712::PaymasterParams; /// ZkSync-specific paymaster parameters for transactions #[derive(Debug, Parser)] pub struct ZksyncParams { + /// Use ZKSync + #[arg(long)] + zksync: bool, + /// The paymaster address for the ZKSync transaction - #[arg(long = "zk-paymaster-address")] + #[arg(long = "zk-paymaster-address", requires_all = ["paymaster_input", "zksync"])] paymaster_address: Option, /// The paymaster input for the ZKSync transaction - #[arg(long = "zk-paymaster-input")] + #[arg(long = "zk-paymaster-input", requires_all = ["paymaster_address", "zksync"])] paymaster_input: Option, } @@ -190,18 +194,22 @@ impl SendTxArgs { tx::validate_from_address(eth.wallet.from, from)?; - let paymaster_address = zksync_params - .paymaster_address - .as_ref() - .map(|s| Address::from_str(s)) - .transpose()?; - let paymaster_input = - zksync_params.paymaster_input.as_ref().map(|s| Bytes::from_str(s)).transpose()?; - - if paymaster_address.is_some() || paymaster_input.is_some() { + if zksync_params.zksync { // ZkSync transaction - let paymaster_address = paymaster_address.unwrap().to_h160(); - let paymaster_input = paymaster_input.unwrap().to_vec(); + let paymaster_address = zksync_params + .paymaster_address + .as_ref() + .map(|s| Address::from_str(s)) + .transpose()? + .map(|addr| addr.to_h160()) + .unwrap_or_default(); + let paymaster_input = zksync_params + .paymaster_input + .as_ref() + .map(|s| Bytes::from_str(s)) + .transpose()? + .map(|bytes| bytes.to_vec()) + .unwrap_or_default(); // Build EIP712 transaction for ZKSync let tx = foundry_zksync_core::new_eip712_transaction( From c77178c107624adbe0f8e5830587468c027f7f17 Mon Sep 17 00:00:00 2001 From: Jrigada Date: Thu, 17 Oct 2024 16:50:00 -0300 Subject: [PATCH 4/7] Clap zksync flag when paymaster parameters present, better handling paymaster parameters --- crates/cast/bin/cmd/send.rs | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/crates/cast/bin/cmd/send.rs b/crates/cast/bin/cmd/send.rs index e733172eb..ffd69d5dd 100644 --- a/crates/cast/bin/cmd/send.rs +++ b/crates/cast/bin/cmd/send.rs @@ -7,7 +7,7 @@ use alloy_serde::WithOtherFields; use alloy_signer::Signer; use alloy_transport::Transport; use cast::Cast; -use clap::Parser; +use clap::{builder::ArgPredicate, Parser}; use eyre::Result; use foundry_cli::{ opts::{EthereumOpts, TransactionOpts}, @@ -23,15 +23,15 @@ use zksync_web3_rs::eip712::PaymasterParams; #[derive(Debug, Parser)] pub struct ZksyncParams { /// Use ZKSync - #[arg(long)] + #[arg(long, default_value_ifs([("paymaster_address", ArgPredicate::IsPresent, "true"),("paymaster_input", ArgPredicate::IsPresent, "true")]))] zksync: bool, /// The paymaster address for the ZKSync transaction - #[arg(long = "zk-paymaster-address", requires_all = ["paymaster_input", "zksync"])] + #[arg(long = "zk-paymaster-address", requires_all = ["paymaster_input"])] paymaster_address: Option, /// The paymaster input for the ZKSync transaction - #[arg(long = "zk-paymaster-input", requires_all = ["paymaster_address", "zksync"])] + #[arg(long = "zk-paymaster-input", requires_all = ["paymaster_address"])] paymaster_input: Option, } @@ -196,26 +196,23 @@ impl SendTxArgs { if zksync_params.zksync { // ZkSync transaction - let paymaster_address = zksync_params + let paymaster_params = zksync_params .paymaster_address - .as_ref() - .map(|s| Address::from_str(s)) - .transpose()? - .map(|addr| addr.to_h160()) - .unwrap_or_default(); - let paymaster_input = zksync_params - .paymaster_input - .as_ref() - .map(|s| Bytes::from_str(s)) - .transpose()? - .map(|bytes| bytes.to_vec()) - .unwrap_or_default(); + .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(), + }); // Build EIP712 transaction for ZKSync let tx = foundry_zksync_core::new_eip712_transaction( builder.build(&signer).await?.0, Vec::new(), // Empty factory_deps - Some(PaymasterParams { paymaster: paymaster_address, paymaster_input }), + paymaster_params, &provider, signer, ) From 01cd764951d82bf6f7c3358580665b556bd59bd8 Mon Sep 17 00:00:00 2001 From: Jrigada Date: Fri, 18 Oct 2024 10:12:59 -0300 Subject: [PATCH 5/7] put cast send logic for zksync in it's own function --- crates/cast/bin/cmd/send.rs | 72 ++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/crates/cast/bin/cmd/send.rs b/crates/cast/bin/cmd/send.rs index ffd69d5dd..08791c1b5 100644 --- a/crates/cast/bin/cmd/send.rs +++ b/crates/cast/bin/cmd/send.rs @@ -15,6 +15,7 @@ use foundry_cli::{ }; use foundry_common::{cli_warn, ens::NameOrAddress}; use foundry_config::Config; +use foundry_wallets::WalletSigner; use foundry_zksync_core::{self, convert::ConvertAddress}; use std::{path::PathBuf, str::FromStr}; use zksync_web3_rs::eip712::PaymasterParams; @@ -195,40 +196,16 @@ impl SendTxArgs { tx::validate_from_address(eth.wallet.from, from)?; if zksync_params.zksync { - // 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(), - }); - - // Build EIP712 transaction for ZKSync - let tx = foundry_zksync_core::new_eip712_transaction( - builder.build(&signer).await?.0, - Vec::new(), // Empty factory_deps - paymaster_params, + let (tx, _) = builder.build(&signer).await?; + cast_send_zk( &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, + zksync_params, + tx, cast_async, confirmations, timeout, to_json, + signer, ) .await } else { @@ -262,6 +239,43 @@ async fn cast_send, T: Transport + Clone>( handle_transaction_result(&cast, tx_hash, cast_async, confs, timeout, to_json).await } +#[allow(clippy::too_many_arguments)] +async fn cast_send_zk, T: Transport + Clone>( + provider: P, + zksync_params: ZksyncParams, + tx: WithOtherFields, + cast_async: bool, + confs: u64, + timeout: u64, + to_json: bool, + 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(), + }); + + // 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, to_json).await +} + async fn handle_transaction_result, T: Transport + Clone>( cast: &Cast, tx_hash: &TxHash, From e5ae334d44132d43d5d81f8f342926544b38a594 Mon Sep 17 00:00:00 2001 From: Jrigada Date: Tue, 22 Oct 2024 07:25:22 -0300 Subject: [PATCH 6/7] Add cast paymaster tests --- crates/cast/bin/cmd/send.rs | 4 +- crates/cast/bin/tx.rs | 4 +- crates/cast/tests/cli/main.rs | 171 +++++++++++++++++++++++++++++++++- 3 files changed, 175 insertions(+), 4 deletions(-) diff --git a/crates/cast/bin/cmd/send.rs b/crates/cast/bin/cmd/send.rs index 08791c1b5..87b88bbc7 100644 --- a/crates/cast/bin/cmd/send.rs +++ b/crates/cast/bin/cmd/send.rs @@ -28,11 +28,11 @@ pub struct ZksyncParams { zksync: bool, /// The paymaster address for the ZKSync transaction - #[arg(long = "zk-paymaster-address", requires_all = ["paymaster_input"])] + #[arg(long = "zk-paymaster-address", requires = "paymaster_input")] paymaster_address: Option, /// The paymaster input for the ZKSync transaction - #[arg(long = "zk-paymaster-input", requires_all = ["paymaster_address"])] + #[arg(long = "zk-paymaster-input", requires = "paymaster_address")] paymaster_input: Option, } diff --git a/crates/cast/bin/tx.rs b/crates/cast/bin/tx.rs index 1dc9b0cd1..32954087e 100644 --- a/crates/cast/bin/tx.rs +++ b/crates/cast/bin/tx.rs @@ -165,7 +165,9 @@ where } if let Some(gas_price) = tx_opts.gas_price { - if legacy { + // We need to set the gas price to be able to create the EIP-712 transaction in + // zkcontext + if legacy || config.zksync.startup { tx.set_gas_price(gas_price.to()); } else { tx.set_max_fee_per_gas(gas_price.to()); diff --git a/crates/cast/tests/cli/main.rs b/crates/cast/tests/cli/main.rs index 01fdaef86..42a3ad092 100644 --- a/crates/cast/tests/cli/main.rs +++ b/crates/cast/tests/cli/main.rs @@ -10,10 +10,15 @@ use foundry_test_utils::{ next_ws_rpc_endpoint, }, str, - util::OutputExt, + util::{self, OutputExt}, + ZkSyncNode, }; use std::{fs, io::Write, path::Path, str::FromStr}; +const PAYMASTER_BYTECODE: &str = "0x0002000000000002000300000000000200000000030100190000006003300270000001080330019700010000003103550000008004000039000000400040043f00000001002001900000002d0000c13d000000040030008c000000380000413d000000000201043b000000e0022002700000010e0020009c0000003c0000213d000001120020009c000000760000613d000001130020009c000000b80000613d000001140020009c0000010b0000c13d0000000001000416000000000001004b0000010b0000c13d000000000100041a0000010a021001970000000005000411000000000052004b0000010d0000c13d0000010901100197000000000010041b0000000001000414000001080010009c0000010801008041000000c0011002100000010b011001c70000800d0200003900000003030000390000010c040000410000000006000019041c04120000040f00000001002001900000003a0000c13d0000010b0000013d0000000001000416000000000001004b0000010b0000c13d0000000006000411000000000006004b000000610000c13d0000011701000041000000000010043f000000040000043f00000116010000410000041e00010430000000000003004b0000010b0000c13d00000000010000190000041d0001042e0000010f0020009c000000dd0000613d000001100020009c000001030000613d000001110020009c0000010b0000c13d000000240030008c0000010b0000413d0000000002000416000000000002004b0000010b0000c13d0000000401100370000000000101043b0000010a0010009c0000010b0000213d000000000200041a0000010a032001970000000005000411000000000053004b0000010d0000c13d0000010a06100198000000330000613d0000010901200197000000000161019f000000000010041b0000000001000414000001080010009c0000010801008041000000c0011002100000010b011001c70000800d0200003900000003030000390000010c04000041041c04120000040f00000001002001900000003a0000c13d0000010b0000013d000000000100041a0000010902100197000000000262019f000000000020041b00000000020004140000010a05100197000001080020009c0000010802008041000000c0012002100000010b011001c70000800d0200003900000003030000390000010c04000041041c04120000040f00000001002001900000010b0000613d0000002001000039000001000010044300000120000004430000010d010000410000041d0001042e000000640030008c0000010b0000413d0000004402100370000000000402043b000001190040009c0000010b0000213d00000000054300490000011a0050009c0000010b0000213d000002640050008c0000010b0000413d0000000002000411000080010020008c000001170000c13d0000022402400039000000000621034f000000000606043b000000230550008a00000124076001970000012408500197000000000987013f000000000087004b00000000070000190000012407004041000000000056004b00000000050000190000012405008041000001240090009c000000000705c019000000000007004b0000010b0000c13d00000004044000390000000005640019000000000451034f000000000404043b000001190040009c0000010b0000213d0000000006430049000000200350003900000124056001970000012407300197000000000857013f000000000057004b00000000050000190000012405004041000000000063004b00000000060000190000012406002041000001240080009c000000000506c019000000000005004b0000010b0000c13d000000030040008c000001730000213d0000011f01000041000000800010043f0000002001000039000000840010043f0000003a01000039000000a40010043f0000013d01000041000000c40010043f0000013e01000041000000e40010043f00000123010000410000041e00010430000000240030008c0000010b0000413d0000000002000416000000000002004b0000010b0000c13d0000000401100370000000000301043b0000010a0030009c0000010b0000213d000000000100041a0000010a021001970000000001000411000000000012004b000001120000c13d000300000003001d0000011b010000410000000000100443000000000100041000000004001004430000000001000414000001080010009c0000010801008041000000c0011002100000011c011001c70000800a02000039041c04170000040f0000000100200190000001bb0000613d00000003020000290000010a04200197000000000301043b0000000001000414000000040040008c000001230000c13d00000001020000390000000001000031000001320000013d000000c40030008c0000010b0000413d0000000402100370000000000202043b000001190020009c0000010b0000213d0000002304200039000000000034004b0000010b0000813d0000000404200039000000000441034f000000000404043b000001190040009c0000010b0000213d00000000024200190000002402200039000000000032004b0000010b0000213d0000002402100370000000000202043b000001190020009c0000010b0000213d00000000022300490000011a0020009c0000010b0000213d000002640020008c0000010b0000413d0000008401100370000000000101043b000000010010008c0000010b0000213d0000000001000411000080010010008c00000000010000390000000101006039041c03fa0000040f00000000010000190000041d0001042e0000000001000416000000000001004b0000010b0000c13d000000000100041a0000010a01100197000000800010043f00000118010000410000041d0001042e00000000010000190000041e000104300000011501000041000000000010043f000000040050043f00000116010000410000041e000104300000011502000041000000000020043f000000040010043f00000116010000410000041e000104300000011f01000041000000800010043f0000002001000039000000840010043f0000002401000039000000a40010043f0000012101000041000000c40010043f0000012201000041000000e40010043f00000123010000410000041e00010430000001080010009c0000010801008041000000c001100210000000000003004b0000012a0000c13d00000000020400190000012d0000013d0000010b011001c700008009020000390000000005000019041c04120000040f00010000000103550000006001100270000001080010019d0000010801100197000000000001004b0000014a0000c13d00000001002001900000003a0000c13d000000400100043d00000064021000390000011d03000041000000000032043500000044021000390000011e0300004100000000003204350000002402100039000000280300003900000000003204350000011f020000410000000000210435000000040210003900000020030000390000000000320435000001080010009c0000010801008041000000400110021000000120011001c70000041e00010430000001190010009c000001b50000213d0000001f041000390000013f044001970000003f044000390000013f05400197000000400400043d0000000005540019000000000045004b00000000060000390000000106004039000001190050009c000001b50000213d0000000100600190000001b50000c13d000000400050043f00000000061404360000013f031001980000001f0410018f00000000013600190000000105000367000001650000613d000000000705034f000000007807043c0000000006860436000000000016004b000001610000c13d000000000004004b000001340000613d000000000335034f0000000304400210000000000501043300000000054501cf000000000545022f000000000303043b0000010004400089000000000343022f00000000034301cf000000000353019f0000000000310435000001340000013d000000000331034f000000000303043b0000012503300197000001260030009c000001bc0000c13d000001c00320008a000000000331034f000001800220008a000000000121034f000000000201043b000000000103043b000300000002001d00000000031200a9000200000001001d000000000001004b000001860000613d00000002013000fa000000030010006b000001c80000c13d0000000b01000039000000800010043f0000012a02000041000000a00020043f0000012b02000041000000e00020043f0000004002000039000000e40020043f000001240010043f000001440100043d0000012c011001970000012a011001c7000001440010043f0000014f0000043f000100000003001d000001040030043f0000008401000039000000c00010043f0000018001000039000000400010043f0000000001000414000001080010009c0000010801008041000000c0011002100000012d011001c70000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d00010000000103550000011b010000410000000000100443000000000100041000000004001004430000000001000414000001080010009c0000010801008041000000c0011002100000011c011001c70000800a02000039041c04170000040f0000000100200190000001bb0000613d000000400400043d0000012f0040009c000001ce0000413d0000012901000041000000000010043f0000004101000039000000040010043f00000116010000410000041e00010430000000000001042f0000011f01000041000000800010043f0000002001000039000000840010043f0000002e01000039000000a40010043f0000012701000041000000c40010043f0000012801000041000000e40010043f00000123010000410000041e000104300000012901000041000000000010043f0000001101000039000000040010043f00000116010000410000041e00010430000000000301043b0000004001400039000000400010043f00000020054000390000013001000041000000000015043500000007010000390000000000140435000000400100043d00000020021000390000012b0600004100000000006204350000002406100039000000400700003900000000007604350000000004040433000000640610003900000000004604350000013f084001970000001f0740018f0000008406100039000000000065004b000001f50000813d000000000008004b000001f10000613d000000000a7500190000000009760019000000200990008a000000200aa0008a000000000b890019000000000c8a0019000000000c0c04330000000000cb0435000000200880008c000001eb0000c13d000000000007004b0000020b0000613d0000000009060019000002010000013d0000000009860019000000000008004b000001fe0000613d000000000a050019000000000b06001900000000ac0a0434000000000bcb043600000000009b004b000001fa0000c13d000000000007004b0000020b0000613d00000000058500190000000307700210000000000809043300000000087801cf000000000878022f00000000050504330000010007700089000000000575022f00000000057501cf000000000585019f000000000059043500000000056400190000000000050435000000440510003900000000003504350000001f034000390000013f05000041000000000353016f00000064043000390000000000410435000000a303300039000000000453016f0000000003140019000000000043004b00000000040000390000000104004039000001190030009c000001b50000213d0000000100400190000001b50000c13d000000400030043f000001080020009c000001080200804100000040022002100000000001010433000001080010009c00000108010080410000006001100210000000000121019f0000000002000414000001080020009c0000010802008041000000c002200210000000000121019f0000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d0001000000010355000000400300043d000001310030009c000001b50000213d0000004001300039000000400010043f00000020043000390000013201000041000000000014043500000009010000390000000000130435000000400100043d00000020021000390000012b05000041000000000052043500000024051000390000004006000039000000000065043500000000030304330000006405100039000000000035043500000000050004160000013f083001970000001f0730018f0000008406100039000000000064004b0000025c0000813d000000000008004b000002580000613d000000000a7400190000000009760019000000200990008a000000200aa0008a000000000b890019000000000c8a0019000000000c0c04330000000000cb0435000000200880008c000002520000c13d000000000007004b000002720000613d0000000009060019000002680000013d0000000009860019000000000008004b000002650000613d000000000a040019000000000b06001900000000ac0a0434000000000bcb043600000000009b004b000002610000c13d000000000007004b000002720000613d00000000048400190000000307700210000000000809043300000000087801cf000000000878022f00000000040404330000010007700089000000000474022f00000000047401cf000000000484019f000000000049043500000000046300190000000000040435000000440410003900000000005404350000001f033000390000013f05000041000000000353016f00000064043000390000000000410435000000a303300039000000000453016f0000000003140019000000000043004b00000000040000390000000104004039000001190030009c000001b50000213d0000000100400190000001b50000c13d000000400030043f000001080020009c000001080200804100000040022002100000000001010433000001080010009c00000108010080410000006001100210000000000121019f0000000002000414000001080020009c0000010802008041000000c002200210000000000121019f0000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d0001000000010355000000400300043d000001310030009c000001b50000213d0000004001300039000000400010043f00000020043000390000013301000041000000000014043500000008010000390000000000130435000000400100043d00000020021000390000012b0500004100000000005204350000002405100039000000400600003900000000006504350000000003030433000000640510003900000000003504350000013f073001970000001f0630018f0000008405100039000000000054004b000002c20000813d000000000007004b000002be0000613d00000000096400190000000008650019000000200880008a000000200990008a000000000a780019000000000b790019000000000b0b04330000000000ba0435000000200770008c000002b80000c13d000000000006004b000002d80000613d0000000008050019000002ce0000013d0000000008750019000000000007004b000002cb0000613d0000000009040019000000000a050019000000009b090434000000000aba043600000000008a004b000002c70000c13d000000000006004b000002d80000613d00000000047400190000000306600210000000000708043300000000076701cf000000000767022f00000000040404330000010006600089000000000464022f00000000046401cf000000000474019f0000000000480435000000000453001900000000000404350000004404100039000000030500002900000000005404350000001f033000390000013f05000041000000000353016f00000064043000390000000000410435000000a303300039000000000453016f0000000003140019000000000043004b00000000040000390000000104004039000001190030009c000001b50000213d0000000100400190000001b50000c13d000000400030043f000001080020009c000001080200804100000040022002100000000001010433000001080010009c00000108010080410000006001100210000000000121019f0000000002000414000001080020009c0000010802008041000000c002200210000000000121019f0000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d0001000000010355000000400300043d000001310030009c000001b50000213d0000004001300039000000400010043f00000020043000390000013401000041000000000014043500000008010000390000000000130435000000400100043d00000020021000390000012b0500004100000000005204350000002405100039000000400600003900000000006504350000000003030433000000640510003900000000003504350000013f073001970000001f0630018f0000008405100039000000000054004b000003290000813d000000000007004b000003250000613d00000000096400190000000008650019000000200880008a000000200990008a000000000a780019000000000b790019000000000b0b04330000000000ba0435000000200770008c0000031f0000c13d000000000006004b0000033f0000613d0000000008050019000003350000013d0000000008750019000000000007004b000003320000613d0000000009040019000000000a050019000000009b090434000000000aba043600000000008a004b0000032e0000c13d000000000006004b0000033f0000613d00000000047400190000000306600210000000000708043300000000076701cf000000000767022f00000000040404330000010006600089000000000464022f00000000046401cf000000000474019f0000000000480435000000000453001900000000000404350000004404100039000000020500002900000000005404350000001f033000390000013f05000041000000000353016f00000064043000390000000000410435000000a303300039000000000453016f0000000003140019000000000043004b00000000040000390000000104004039000001190030009c000001b50000213d0000000100400190000001b50000c13d000000400030043f000001080020009c000001080200804100000040022002100000000001010433000001080010009c00000108010080410000006001100210000000000121019f0000000002000414000001080020009c0000010802008041000000c002200210000000000121019f0000012e02000041041c04170000040f00000000020100190000006002200270000001080020019d00010000000103550000000001000414000001080010009c0000010801008041000000c001100210000000010000006b0000036f0000c13d0000800102000039000003740000013d0000010b011001c70000800902000039000080010400003900000001030000290000000005000019041c04120000040f000100000001035500000000030100190000006003300270000001080030019d00000108033001980000039b0000c13d000000400100043d0000000100200190000003c10000613d0000002002100039000000400300003900000000003204350000013c0200004100000000002104350000004003100039000000600200043d00000000002304350000013f052001970000001f0420018f0000006003100039000000810030008c000003d70000413d000000000005004b000003960000613d000000000743001900000060064001bf000000200770008a0000000008570019000000000956001900000000090904330000000000980435000000200550008c000003900000c13d000000000004004b000003ed0000613d00000080050000390000000006030019000003e30000013d0000001f0430003900000135044001970000003f044000390000013604400197000000400500043d0000000004450019000000000054004b00000000060000390000000106004039000001190040009c000001b50000213d0000000100600190000001b50000c13d000000400040043f0000001f0430018f000000000635043600000137053001980000000003560019000003b30000613d000000000701034f000000007807043c0000000006860436000000000036004b000003af0000c13d000000000004004b0000037b0000613d000000000151034f0000000304400210000000000503043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f00000000001304350000037b0000013d00000084021000390000013803000041000000000032043500000064021000390000013903000041000000000032043500000044021000390000013a0300004100000000003204350000002402100039000000530300003900000000003204350000011f020000410000000000210435000000040210003900000020030000390000000000320435000001080010009c000001080100804100000040011002100000013b011001c70000041e000104300000000006530019000000000005004b0000008009000039000003e00000613d000000000703001900000000980904340000000007870436000000000067004b000003dc0000c13d000000000004004b000003ed0000613d00000080055000390000000304400210000000000706043300000000074701cf000000000747022f00000000050504330000010004400089000000000545022f00000000044501cf000000000474019f00000000004604350000001f042000390000013f04400197000000000232001900000000000204350000006002400039000001080020009c00000108020080410000006002200210000001080010009c00000108010080410000004001100210000000000112019f0000041d0001042e000000000001004b000003fd0000613d000000000001042d000000400100043d0000006402100039000001220300004100000000003204350000004402100039000001210300004100000000003204350000002402100039000000240300003900000000003204350000011f020000410000000000210435000000040210003900000020030000390000000000320435000001080010009c0000010801008041000000400110021000000120011001c70000041e00010430000000000001042f00000415002104210000000102000039000000000001042d0000000002000019000000000001042d0000041a002104230000000102000039000000000001042d0000000002000019000000000001042d0000041c000004320000041d0001042e0000041e00010430000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffff02000000000000000000000000000000000000000000000000000000000000008be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0000000020000000000000000000000000000004000000100000000000000000000000000000000000000000000000000000000000000000000000000817b17ef00000000000000000000000000000000000000000000000000000000817b17f0000000000000000000000000000000000000000000000000000000008da5cb5b00000000000000000000000000000000000000000000000000000000f2fde38b00000000000000000000000000000000000000000000000000000000038a24bc0000000000000000000000000000000000000000000000000000000051cff8d900000000000000000000000000000000000000000000000000000000715018a6118cdaa70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000001e4fbdf7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000800000000000000000000000000000000000000000000000000000000000000000ffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9cc7f708afc65944829bd487b90b72536b1951864fbfc14e125fc972a6507f390200000200000000000000000000000000000024000000000000000000000000796d61737465722e0000000000000000000000000000000000000000000000004661696c656420746f2077697468647261772066756e64732066726f6d20706108c379a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000840000000000000000000000004f6e6c7920626f6f746c6f616465722063616e2063616c6c2074686973206d6574686f640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000840000008000000000000000008000000000000000000000000000000000000000000000000000000000000000ffffffff000000000000000000000000000000000000000000000000000000008c5a344500000000000000000000000000000000000000000000000000000000556e737570706f72746564207061796d617374657220666c6f7720696e207061796d6173746572506172616d732e0000000000000000000000000000000000004e487b710000000000000000000000000000000000000000000000000000000072657175697265644554480000000000000000000000000000000000000000009710a9d0000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000084000000e00000000000000000000000000000000000000000000000000000000000636f6e736f6c652e6c6f67000000000000000000000000000000000000000000000000ffffffffffffffc062616c616e636500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffbf6d73672e76616c7565000000000000000000000000000000000000000000000067617350726963650000000000000000000000000000000000000000000000006761734c696d697400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001ffffffe000000000000000000000000000000000000000000000000000000003ffffffe000000000000000000000000000000000000000000000000000000000ffffffe069676874206e6f7420626520656e6f7567682e0000000000000000000000000020426f6f746c6f616465722e205061796d61737465722062616c616e6365206d4661696c656420746f207472616e736665722074782066656520746f2074686500000000000000000000000000000000000000a4000000000000000000000000038a24bc00000000000000000000000000000000000000000000000000000000546865207374616e64617264207061796d617374657220696e707574206d757374206265206174206c656173742034206279746573206c6f6e67000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0665706818478a33d2e5c855cee339a5e2954659335637b967b7e5433b81a588b"; + +const COUNTER_BYTECODE: &str = "0x0000008003000039000000400030043f0000000100200190000000150000c13d000000000201001900000010002001980000002d0000613d000000000101043b000000e001100270000000110010009c000000200000613d000000120010009c0000002d0000c13d0000000001000416000000000001004b0000002d0000c13d000000000100041a000000ff0110018f000000800010043f0000001501000041000000370001042e0000000001000416000000000001004b0000002d0000c13d000000000200041a0000001601200197000000000010041b0000002001000039000001000010044300000120000004430000000f01000041000000370001042e0000000001000416000000000001004b0000002d0000c13d000000000100041a000000ff0210018f000000ff0020008c0000002f0000c13d0000001301000041000000000010043f0000001101000039000000040010043f000000140100004100000038000104300000000001000019000000380001043000000016021001970000000101100039000000ff0110018f000000000121019f000000000010041b0000000001000019000000370001042e0000003600000432000000370001042e0000003800010430000000000000000000000000000000000000000000000000000000020000000000000000000000000000004000000100000000000000000000000000000000000000000000000000fffffffc00000000000000000000000000000000000000000000000000000000000000000000000000000000d09de08a000000000000000000000000000000000000000000000000000000008381f58a4e487b710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000020000000800000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000000000000000000000000027b95d8697efbdb44a7508247e8c640a64fb3ead050f40cb23deb1910c501315"; + // tests `--help` is printed to std out casttest!(print_help, |_prj, cmd| { cmd.arg("--help").assert_success().stdout_eq(str![[r#" @@ -1318,3 +1323,167 @@ casttest!(hash_message, |_prj, cmd| { "#]]); }); + +casttest!(cast_using_paymaster, async |prj, cmd| { + util::initialize(prj.root()); + + let node = ZkSyncNode::start(); + let url = node.url(); + + let (addr, private_key) = ZkSyncNode::rich_wallets() + .next() + .map(|(addr, pk, _)| (addr, pk)) + .expect("No rich wallets available"); + + // Deploy paymaster + cmd.args([ + "rpc", + "hardhat_setCode", + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + PAYMASTER_BYTECODE, + "--rpc-url", + &url, + ]) + .assert_success(); + + // Deploy counter + cmd.cast_fuse() + .args([ + "rpc", + "hardhat_setCode", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + COUNTER_BYTECODE, + "--rpc-url", + &url, + ]) + .assert_success(); + + // Fund the paymaster + cmd.cast_fuse() + .args([ + "send", + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "0x", + "--value", + "0.1ether", + "--private-key", + private_key, + "--rpc-url", + &url, + ]) + .assert_success(); + + let balance_before = cmd + .cast_fuse() + .args(["balance", addr, "--rpc-url", &url]) + .assert_success() + .get_output() + .stdout_lossy(); + + // Interact with the counter using the paymaster + cmd.cast_fuse().args([ + "send", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + "increment()", + "--private-key", + private_key, + "--zk-paymaster-address", + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "--zk-paymaster-input", + "0x8c5a344500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000", + "--rpc-url", + &url, + "--gas-price", + "1000000000000002", + ]) + .assert_success(); + + let balance_after = cmd + .cast_fuse() + .args(["balance", addr, "--rpc-url", &url]) + .assert_success() + .get_output() + .stdout_lossy(); + + assert_eq!(balance_after, balance_before); +}); + +casttest!(cast_without_paymaster, async |prj, cmd| { + util::initialize(prj.root()); + + let node = ZkSyncNode::start(); + let url = node.url(); + + let (addr, private_key) = ZkSyncNode::rich_wallets() + .next() + .map(|(addr, pk, _)| (addr, pk)) + .expect("No rich wallets available"); + + // Deploy paymaster + cmd.args([ + "rpc", + "hardhat_setCode", + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + PAYMASTER_BYTECODE, + "--rpc-url", + &url, + ]) + .assert_success(); + + // Deploy counter + cmd.cast_fuse() + .args([ + "rpc", + "hardhat_setCode", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + COUNTER_BYTECODE, + "--rpc-url", + &url, + ]) + .assert_success(); + + // Fund the paymaster + cmd.cast_fuse() + .args([ + "send", + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", + "0x", + "--value", + "0.1ether", + "--private-key", + private_key, + "--rpc-url", + &url, + ]) + .assert_success(); + + let balance_before = cmd + .cast_fuse() + .args(["balance", addr, "--rpc-url", &url]) + .assert_success() + .get_output() + .stdout_lossy(); + + cmd.cast_fuse() + .args([ + "send", + "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", + "increment()", + "--private-key", + private_key, + "--rpc-url", + &url, + "--gas-price", + "1000000000000002", + ]) + .assert_success(); + + let balance_after = cmd + .cast_fuse() + .args(["balance", addr, "--rpc-url", &url]) + .assert_success() + .get_output() + .stdout_lossy(); + + assert!(balance_after != balance_before); +}); From 01cf2675ea8426b7a733fc987b15e83e1fd0059f Mon Sep 17 00:00:00 2001 From: Jrigada Date: Tue, 22 Oct 2024 14:21:30 -0300 Subject: [PATCH 7/7] Remove unnecesary paymaster settings in test --- crates/cast/tests/cli/main.rs | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/crates/cast/tests/cli/main.rs b/crates/cast/tests/cli/main.rs index 42a3ad092..b1eefa9a3 100644 --- a/crates/cast/tests/cli/main.rs +++ b/crates/cast/tests/cli/main.rs @@ -1419,17 +1419,6 @@ casttest!(cast_without_paymaster, async |prj, cmd| { .map(|(addr, pk, _)| (addr, pk)) .expect("No rich wallets available"); - // Deploy paymaster - cmd.args([ - "rpc", - "hardhat_setCode", - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - PAYMASTER_BYTECODE, - "--rpc-url", - &url, - ]) - .assert_success(); - // Deploy counter cmd.cast_fuse() .args([ @@ -1442,21 +1431,6 @@ casttest!(cast_without_paymaster, async |prj, cmd| { ]) .assert_success(); - // Fund the paymaster - cmd.cast_fuse() - .args([ - "send", - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", - "0x", - "--value", - "0.1ether", - "--private-key", - private_key, - "--rpc-url", - &url, - ]) - .assert_success(); - let balance_before = cmd .cast_fuse() .args(["balance", addr, "--rpc-url", &url])