From 9a62d14a860dd185b475031b34e8755fb5e16543 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 2 Dec 2024 20:33:44 -0300 Subject: [PATCH 01/45] add get_first_nonce command --- batcher/aligned/src/main.rs | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index e8df5118b..ed08a6dfe 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -12,6 +12,7 @@ use aligned_sdk::core::{ }; use aligned_sdk::sdk::get_chain_id; use aligned_sdk::sdk::get_nonce_from_batcher; +use aligned_sdk::sdk::get_nonce_from_ethereum; use aligned_sdk::sdk::{deposit_to_aligned, get_balance_in_aligned}; use aligned_sdk::sdk::{get_vk_commitment, is_proof_verified, save_response, submit_multiple}; use clap::Parser; @@ -29,6 +30,7 @@ use transaction::eip2718::TypedTransaction; use crate::AlignedCommands::DepositToBatcher; use crate::AlignedCommands::GetUserBalance; use crate::AlignedCommands::GetUserNonce; +use crate::AlignedCommands::GetUserFirstNonce; use crate::AlignedCommands::GetVkCommitment; use crate::AlignedCommands::Submit; use crate::AlignedCommands::VerifyProofOnchain; @@ -58,6 +60,8 @@ pub enum AlignedCommands { GetUserBalance(GetUserBalanceArgs), #[clap(about = "Get user nonce from the batcher", name = "get-user-nonce")] GetUserNonce(GetUserNonceArgs), + #[clap(about = "Get the first user nonce from ethereum", name = "get-user-first-nonce")] + GetUserFirstNonce(GetUserFirstNonceArgs), } #[derive(Parser, Debug)] @@ -218,6 +222,29 @@ pub struct GetUserNonceArgs { address: String, } +#[derive(Parser, Debug)] +#[command(version, about, long_about = None)] +pub struct GetUserFirstNonceArgs { + #[arg( + name = "Ethereum RPC provider address", + long = "rpc_url", + default_value = "http://localhost:8545" + )] + eth_rpc_url: String, + #[arg( + name = "The user's Ethereum address", + long = "user_addr", + required = true + )] + address: String, + #[arg( + name = "The working network's name", + long = "network", + default_value = "devnet" + )] + network: NetworkArg, +} + #[derive(Debug, Clone, ValueEnum, Copy)] enum NetworkArg { Devnet, @@ -528,6 +555,20 @@ async fn main() -> Result<(), AlignedError> { } } } + GetUserFirstNonce(args) => { + let address = H160::from_str(&args.address).unwrap(); + let network = args.network.into(); + match get_nonce_from_ethereum(&args.eth_rpc_url, address, network).await { + Ok(nonce) => { + let first_nonce = nonce + 1; + info!("Nonce for address {} is {}", address, first_nonce); + } + Err(e) => { + error!("Error while getting nonce: {:?}", e); + return Ok(()); + } + } + } } Ok(()) From 650beeba0856d7657a2d901887ab041130cbc8ec Mon Sep 17 00:00:00 2001 From: PatStiles Date: Tue, 3 Dec 2024 00:10:31 -0300 Subject: [PATCH 02/45] fmt --- batcher/aligned/src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index ed08a6dfe..4f349bfaa 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -29,8 +29,8 @@ use transaction::eip2718::TypedTransaction; use crate::AlignedCommands::DepositToBatcher; use crate::AlignedCommands::GetUserBalance; -use crate::AlignedCommands::GetUserNonce; use crate::AlignedCommands::GetUserFirstNonce; +use crate::AlignedCommands::GetUserNonce; use crate::AlignedCommands::GetVkCommitment; use crate::AlignedCommands::Submit; use crate::AlignedCommands::VerifyProofOnchain; @@ -60,7 +60,10 @@ pub enum AlignedCommands { GetUserBalance(GetUserBalanceArgs), #[clap(about = "Get user nonce from the batcher", name = "get-user-nonce")] GetUserNonce(GetUserNonceArgs), - #[clap(about = "Get the first user nonce from ethereum", name = "get-user-first-nonce")] + #[clap( + about = "Get the first user nonce from ethereum", + name = "get-user-first-nonce" + )] GetUserFirstNonce(GetUserFirstNonceArgs), } From 3f61db1812406d0436c85f805a820a551e47380b Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Thu, 5 Dec 2024 12:30:58 -0300 Subject: [PATCH 03/45] fix get first nonce --- batcher/aligned/src/main.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 4f349bfaa..64e1489a2 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -29,8 +29,8 @@ use transaction::eip2718::TypedTransaction; use crate::AlignedCommands::DepositToBatcher; use crate::AlignedCommands::GetUserBalance; -use crate::AlignedCommands::GetUserFirstNonce; use crate::AlignedCommands::GetUserNonce; +use crate::AlignedCommands::GetUserNonceFromEthereum; use crate::AlignedCommands::GetVkCommitment; use crate::AlignedCommands::Submit; use crate::AlignedCommands::VerifyProofOnchain; @@ -58,13 +58,16 @@ pub enum AlignedCommands { DepositToBatcher(DepositToBatcherArgs), #[clap(about = "Get user balance from the batcher", name = "get-user-balance")] GetUserBalance(GetUserBalanceArgs), - #[clap(about = "Get user nonce from the batcher", name = "get-user-nonce")] + #[clap( + about = "Gets user current nonce from the batcher. This is the nonce you should send in your next proof.", + name = "get-user-nonce" + )] GetUserNonce(GetUserNonceArgs), #[clap( - about = "Get the first user nonce from ethereum", - name = "get-user-first-nonce" + about = "Gets the user nonce directly from the Ethereum blockchain's BatcherPaymentService contract. Useful for validating the on-chain state and check if your transactions are pending in the batcher.", + name = "get-user-nonce-from-ethereum" )] - GetUserFirstNonce(GetUserFirstNonceArgs), + GetUserNonceFromEthereum(GetUserNonceFromEthereumArgs), } #[derive(Parser, Debug)] @@ -227,7 +230,7 @@ pub struct GetUserNonceArgs { #[derive(Parser, Debug)] #[command(version, about, long_about = None)] -pub struct GetUserFirstNonceArgs { +pub struct GetUserNonceFromEthereumArgs { #[arg( name = "Ethereum RPC provider address", long = "rpc_url", @@ -558,13 +561,16 @@ async fn main() -> Result<(), AlignedError> { } } } - GetUserFirstNonce(args) => { + GetUserNonceFromEthereum(args) => { let address = H160::from_str(&args.address).unwrap(); let network = args.network.into(); match get_nonce_from_ethereum(&args.eth_rpc_url, address, network).await { Ok(nonce) => { - let first_nonce = nonce + 1; - info!("Nonce for address {} is {}", address, first_nonce); + let first_nonce = nonce; + info!( + "Nonce for address {} in BatcherPaymentService contract is {}", + address, first_nonce + ); } Err(e) => { error!("Error while getting nonce: {:?}", e); From 26b013869432432ef3a03ec9d123348610bb6d7a Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Thu, 5 Dec 2024 12:33:06 -0300 Subject: [PATCH 04/45] refactor: nit --- batcher/aligned/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 64e1489a2..493fa22ab 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -566,10 +566,9 @@ async fn main() -> Result<(), AlignedError> { let network = args.network.into(); match get_nonce_from_ethereum(&args.eth_rpc_url, address, network).await { Ok(nonce) => { - let first_nonce = nonce; info!( "Nonce for address {} in BatcherPaymentService contract is {}", - address, first_nonce + address, nonce ); } Err(e) => { From 87e0e8763f88265fc7dbcb40389b2ec4920f2227 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:09:01 -0300 Subject: [PATCH 05/45] feat: GetAmountOfProofsInBatcherQueue --- batcher/aligned/src/main.rs | 65 ++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 493fa22ab..6aeeb0457 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -32,6 +32,7 @@ use crate::AlignedCommands::GetUserBalance; use crate::AlignedCommands::GetUserNonce; use crate::AlignedCommands::GetUserNonceFromEthereum; use crate::AlignedCommands::GetVkCommitment; +use crate::AlignedCommands::GetAmountOfProofsInBatcherQueue; use crate::AlignedCommands::Submit; use crate::AlignedCommands::VerifyProofOnchain; @@ -64,10 +65,15 @@ pub enum AlignedCommands { )] GetUserNonce(GetUserNonceArgs), #[clap( - about = "Gets the user nonce directly from the Ethereum blockchain's BatcherPaymentService contract. Useful for validating the on-chain state and check if your transactions are pending in the batcher.", + about = "Gets the user nonce directly from the BatcherPaymentService contract. Useful for validating the on-chain state and check if your transactions are pending in the batcher.", name = "get-user-nonce-from-ethereum" )] GetUserNonceFromEthereum(GetUserNonceFromEthereumArgs), + #[clap( + about = "Gets the amount of proofs a user has queued in the Batcher.", + name = "get-amount-of-proofs-in-batcher-queue" + )] + GetAmountOfProofsInBatcherQueue(GetAmountOfProofsInBatcherQueueArgs), } #[derive(Parser, Debug)] @@ -251,6 +257,35 @@ pub struct GetUserNonceFromEthereumArgs { network: NetworkArg, } +#[derive(Parser, Debug)] +#[command(version, about, long_about = None)] +pub struct GetAmountOfProofsInBatcherQueueArgs { + #[arg( + name = "Ethereum RPC provider address", + long = "rpc_url", + default_value = "http://localhost:8545" + )] + eth_rpc_url: String, + #[arg( + name = "The user's Ethereum address", + long = "user_addr", + required = true + )] + address: String, + #[arg( + name = "The working network's name", + long = "network", + default_value = "devnet" + )] + network: NetworkArg, + #[arg( + name = "Batcher connection address", + long = "batcher_url", + default_value = "ws://localhost:8080" + )] + batcher_url: String, +} + #[derive(Debug, Clone, ValueEnum, Copy)] enum NetworkArg { Devnet, @@ -577,6 +612,34 @@ async fn main() -> Result<(), AlignedError> { } } } + GetAmountOfProofsInBatcherQueue(args) => { + let address = H160::from_str(&args.address).unwrap(); + let network = args.network.into(); + let ethereum_nonce = match get_nonce_from_ethereum(&args.eth_rpc_url, address, network).await { + Ok(nonce) => { + nonce + } + Err(e) => { + error!("Error while getting nonce: {:?}", e); + return Ok(()); + } + }; + let batcher_nonce = match get_nonce_from_batcher(&args.batcher_url, address).await { + Ok(nonce) => { + nonce + } + Err(e) => { + error!("Error while getting nonce: {:?}", e); + return Ok(()); + } + }; + if ethereum_nonce > batcher_nonce { + error!("User {} is in an invalid state.", address); + } else { + info!("User {} has {} proofs in the batcher queue", address, ethereum_nonce - batcher_nonce); + } + return Ok(()); + } } Ok(()) From 934de62b167c502f75f7dd58b7890ce361934ee9 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:22:09 -0300 Subject: [PATCH 06/45] fix: substraction --- batcher/aligned/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 6aeeb0457..d07bb3e23 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -636,7 +636,7 @@ async fn main() -> Result<(), AlignedError> { if ethereum_nonce > batcher_nonce { error!("User {} is in an invalid state.", address); } else { - info!("User {} has {} proofs in the batcher queue", address, ethereum_nonce - batcher_nonce); + info!("User {} has {} proofs in the batcher queue", address, batcher_nonce - ethereum_nonce); } return Ok(()); } From 6440e87c761e247f9f7093fc88bad438ba584d9f Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:24:20 -0300 Subject: [PATCH 07/45] chore: cargo clippy --- batcher/aligned/src/main.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index d07bb3e23..7aaa212b6 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -28,11 +28,11 @@ use log::{error, info}; use transaction::eip2718::TypedTransaction; use crate::AlignedCommands::DepositToBatcher; +use crate::AlignedCommands::GetAmountOfProofsInBatcherQueue; use crate::AlignedCommands::GetUserBalance; use crate::AlignedCommands::GetUserNonce; use crate::AlignedCommands::GetUserNonceFromEthereum; use crate::AlignedCommands::GetVkCommitment; -use crate::AlignedCommands::GetAmountOfProofsInBatcherQueue; use crate::AlignedCommands::Submit; use crate::AlignedCommands::VerifyProofOnchain; @@ -615,19 +615,16 @@ async fn main() -> Result<(), AlignedError> { GetAmountOfProofsInBatcherQueue(args) => { let address = H160::from_str(&args.address).unwrap(); let network = args.network.into(); - let ethereum_nonce = match get_nonce_from_ethereum(&args.eth_rpc_url, address, network).await { - Ok(nonce) => { - nonce - } - Err(e) => { - error!("Error while getting nonce: {:?}", e); - return Ok(()); - } - }; + let ethereum_nonce = + match get_nonce_from_ethereum(&args.eth_rpc_url, address, network).await { + Ok(nonce) => nonce, + Err(e) => { + error!("Error while getting nonce: {:?}", e); + return Ok(()); + } + }; let batcher_nonce = match get_nonce_from_batcher(&args.batcher_url, address).await { - Ok(nonce) => { - nonce - } + Ok(nonce) => nonce, Err(e) => { error!("Error while getting nonce: {:?}", e); return Ok(()); @@ -636,7 +633,11 @@ async fn main() -> Result<(), AlignedError> { if ethereum_nonce > batcher_nonce { error!("User {} is in an invalid state.", address); } else { - info!("User {} has {} proofs in the batcher queue", address, batcher_nonce - ethereum_nonce); + info!( + "User {} has {} proofs in the batcher queue", + address, + batcher_nonce - ethereum_nonce + ); } return Ok(()); } From b67cd0baa2b98cf67dbe0c6a58b11a69f393fc0d Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 6 Dec 2024 14:04:43 -0300 Subject: [PATCH 08/45] change command name --- batcher/aligned/src/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 7aaa212b6..fd5953139 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -28,7 +28,7 @@ use log::{error, info}; use transaction::eip2718::TypedTransaction; use crate::AlignedCommands::DepositToBatcher; -use crate::AlignedCommands::GetAmountOfProofsInBatcherQueue; +use crate::AlignedCommands::GetUserNumberOfQueuedProofs; use crate::AlignedCommands::GetUserBalance; use crate::AlignedCommands::GetUserNonce; use crate::AlignedCommands::GetUserNonceFromEthereum; @@ -70,10 +70,10 @@ pub enum AlignedCommands { )] GetUserNonceFromEthereum(GetUserNonceFromEthereumArgs), #[clap( - about = "Gets the amount of proofs a user has queued in the Batcher.", - name = "get-amount-of-proofs-in-batcher-queue" + about = "Gets the number of proofs a user has queued in the Batcher.", + name = "get-user-number-of-queued-proofs" )] - GetAmountOfProofsInBatcherQueue(GetAmountOfProofsInBatcherQueueArgs), + GetUserNumberOfQueuedProofs(GetUserNumberOfQueuedProofsArgs), } #[derive(Parser, Debug)] @@ -259,7 +259,7 @@ pub struct GetUserNonceFromEthereumArgs { #[derive(Parser, Debug)] #[command(version, about, long_about = None)] -pub struct GetAmountOfProofsInBatcherQueueArgs { +pub struct GetUserNumberOfQueuedProofsArgs { #[arg( name = "Ethereum RPC provider address", long = "rpc_url", @@ -612,7 +612,7 @@ async fn main() -> Result<(), AlignedError> { } } } - GetAmountOfProofsInBatcherQueue(args) => { + GetUserNumberOfQueuedProofs(args) => { let address = H160::from_str(&args.address).unwrap(); let network = args.network.into(); let ethereum_nonce = From 5a7628a89f46fcd04e46de659628dcbf035286a0 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 6 Dec 2024 14:13:53 -0300 Subject: [PATCH 09/45] join two futures --- batcher/aligned/src/main.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index fd5953139..0c58c9bd0 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -23,6 +23,7 @@ use ethers::prelude::*; use ethers::utils::format_ether; use ethers::utils::hex; use ethers::utils::parse_ether; +use futures_util::future; use log::warn; use log::{error, info}; use transaction::eip2718::TypedTransaction; @@ -615,20 +616,11 @@ async fn main() -> Result<(), AlignedError> { GetUserNumberOfQueuedProofs(args) => { let address = H160::from_str(&args.address).unwrap(); let network = args.network.into(); - let ethereum_nonce = - match get_nonce_from_ethereum(&args.eth_rpc_url, address, network).await { - Ok(nonce) => nonce, - Err(e) => { - error!("Error while getting nonce: {:?}", e); - return Ok(()); - } - }; - let batcher_nonce = match get_nonce_from_batcher(&args.batcher_url, address).await { - Ok(nonce) => nonce, - Err(e) => { - error!("Error while getting nonce: {:?}", e); - return Ok(()); - } + let Ok((ethereum_nonce, batcher_nonce)) = future::try_join( + get_nonce_from_ethereum(&args.eth_rpc_url, address, network), + get_nonce_from_batcher(&args.batcher_url, address), + ).await.map_err(|e| error!("Error while getting nonce: {:?}", e)) else { + return Ok(()); }; if ethereum_nonce > batcher_nonce { error!("User {} is in an invalid state.", address); From 5e8807ecaab479427c4b5a3b7c0778dadf1c36e4 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 6 Dec 2024 14:17:25 -0300 Subject: [PATCH 10/45] remove invalid state check --- batcher/aligned/src/main.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 0c58c9bd0..bb8637801 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -29,10 +29,10 @@ use log::{error, info}; use transaction::eip2718::TypedTransaction; use crate::AlignedCommands::DepositToBatcher; -use crate::AlignedCommands::GetUserNumberOfQueuedProofs; use crate::AlignedCommands::GetUserBalance; use crate::AlignedCommands::GetUserNonce; use crate::AlignedCommands::GetUserNonceFromEthereum; +use crate::AlignedCommands::GetUserNumberOfQueuedProofs; use crate::AlignedCommands::GetVkCommitment; use crate::AlignedCommands::Submit; use crate::AlignedCommands::VerifyProofOnchain; @@ -619,18 +619,16 @@ async fn main() -> Result<(), AlignedError> { let Ok((ethereum_nonce, batcher_nonce)) = future::try_join( get_nonce_from_ethereum(&args.eth_rpc_url, address, network), get_nonce_from_batcher(&args.batcher_url, address), - ).await.map_err(|e| error!("Error while getting nonce: {:?}", e)) else { + ) + .await + .map_err(|e| error!("Error while getting nonce: {:?}", e)) else { return Ok(()); }; - if ethereum_nonce > batcher_nonce { - error!("User {} is in an invalid state.", address); - } else { - info!( - "User {} has {} proofs in the batcher queue", - address, - batcher_nonce - ethereum_nonce - ); - } + info!( + "User {} has {} proofs in the batcher queue", + address, + batcher_nonce - ethereum_nonce + ); return Ok(()); } } From 2612234739fb3e482057b6ea6a9a574f8ee5680b Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 6 Dec 2024 15:07:23 -0300 Subject: [PATCH 11/45] user_addr -> user_address --- batcher/aligned/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index bb8637801..f262c8776 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -212,7 +212,7 @@ pub struct GetUserBalanceArgs { eth_rpc_url: String, #[arg( name = "The user's Ethereum address", - long = "user_addr", + long = "user_address", required = true )] user_address: String, From 9a2bdadd6db95a8aa97d5184c48078a31d645a4c Mon Sep 17 00:00:00 2001 From: PatStiles Date: Tue, 10 Dec 2024 14:22:07 -0300 Subject: [PATCH 12/45] change user_addr --- batcher/aligned/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index f262c8776..bb8637801 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -212,7 +212,7 @@ pub struct GetUserBalanceArgs { eth_rpc_url: String, #[arg( name = "The user's Ethereum address", - long = "user_address", + long = "user_addr", required = true )] user_address: String, From d55f58ed78f8745c7a6588c45aa9fa7d41658eab Mon Sep 17 00:00:00 2001 From: PatStiles Date: Tue, 10 Dec 2024 10:39:33 -0300 Subject: [PATCH 13/45] remove NetworkArg type --- batcher/aligned-sdk/Cargo.toml | 1 + batcher/aligned-sdk/src/core/types.rs | 28 +++++++++++++++++++- batcher/aligned-sdk/src/sdk.rs | 38 ++++++--------------------- batcher/aligned/src/main.rs | 37 ++++++-------------------- 4 files changed, 44 insertions(+), 60 deletions(-) diff --git a/batcher/aligned-sdk/Cargo.toml b/batcher/aligned-sdk/Cargo.toml index 019a65984..9b1bcedd0 100644 --- a/batcher/aligned-sdk/Cargo.toml +++ b/batcher/aligned-sdk/Cargo.toml @@ -25,3 +25,4 @@ hex = "0.4.3" ciborium = "=0.2.2" serde_repr = "0.1.19" dialoguer = "0.11.0" +clap = { version = "4.5.4", features = ["derive"] } diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index ba59b5d6b..3c5a07a18 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -3,6 +3,7 @@ use std::fmt::Display; use std::fmt::Formatter; use std::str::FromStr; +use clap::ValueEnum; use ethers::core::k256::ecdsa::SigningKey; use ethers::signers::Signer; use ethers::signers::Wallet; @@ -11,6 +12,7 @@ use ethers::types::transaction::eip712::Eip712; use ethers::types::transaction::eip712::Eip712Error; use ethers::types::Address; use ethers::types::Signature; +use ethers::types::H160; use ethers::types::U256; use lambdaworks_crypto::merkle_tree::{ merkle::MerkleTree, proof::Proof, traits::IsMerkleTreeBackend, @@ -396,7 +398,7 @@ pub enum GetNonceResponseMessage { InvalidRequest(String), } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, ValueEnum)] pub enum Network { Devnet, Holesky, @@ -404,6 +406,30 @@ pub enum Network { Mainnet, } +impl Network { + pub fn get_batcher_payment_service_address(&self) -> ethers::types::H160 { + match self { + Self::Devnet => H160::from_str("0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650").unwrap(), + Self::Holesky => H160::from_str("0x815aeCA64a974297942D2Bbf034ABEe22a38A003").unwrap(), + Self::HoleskyStage => { + H160::from_str("0x7577Ec4ccC1E6C529162ec8019A49C13F6DAd98b").unwrap() + } + Self::Mainnet => H160::from_str("0xb0567184A52cB40956df6333510d6eF35B89C8de").unwrap(), + } + } + + pub fn get_aligned_service_manager_address(&self) -> ethers::types::H160 { + match self { + Self::Devnet => H160::from_str("0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8").unwrap(), + Self::Holesky => H160::from_str("0x58F280BeBE9B34c9939C3C39e0890C81f163B623").unwrap(), + Self::HoleskyStage => { + H160::from_str("0x9C5231FC88059C086Ea95712d105A2026048c39B").unwrap() + } + Self::Mainnet => H160::from_str("0xeF2A435e5EE44B2041100EF8cbC8ae035166606c").unwrap(), + } + } +} + impl FromStr for Network { type Err = String; diff --git a/batcher/aligned-sdk/src/sdk.rs b/batcher/aligned-sdk/src/sdk.rs index 6045d8411..c3cb2a7a8 100644 --- a/batcher/aligned-sdk/src/sdk.rs +++ b/batcher/aligned-sdk/src/sdk.rs @@ -28,10 +28,10 @@ use ethers::{ prelude::k256::ecdsa::SigningKey, providers::{Http, Middleware, Provider}, signers::{LocalWallet, Wallet}, - types::{Address, H160, U256}, + types::{Address, U256}, }; use sha3::{Digest, Keccak256}; -use std::{str::FromStr, sync::Arc}; +use std::sync::Arc; use tokio::{net::TcpStream, sync::Mutex}; use tokio_tungstenite::{connect_async, tungstenite::Message, MaybeTlsStream, WebSocketStream}; @@ -271,28 +271,6 @@ pub async fn submit_multiple( .await } -pub fn get_payment_service_address(network: Network) -> ethers::types::H160 { - match network { - Network::Devnet => H160::from_str("0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650").unwrap(), - Network::Holesky => H160::from_str("0x815aeCA64a974297942D2Bbf034ABEe22a38A003").unwrap(), - Network::HoleskyStage => { - H160::from_str("0x7577Ec4ccC1E6C529162ec8019A49C13F6DAd98b").unwrap() - } - Network::Mainnet => H160::from_str("0xb0567184A52cB40956df6333510d6eF35B89C8de").unwrap(), - } -} - -pub fn get_aligned_service_manager_address(network: Network) -> ethers::types::H160 { - match network { - Network::Devnet => H160::from_str("0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8").unwrap(), - Network::Holesky => H160::from_str("0x58F280BeBE9B34c9939C3C39e0890C81f163B623").unwrap(), - Network::HoleskyStage => { - H160::from_str("0x9C5231FC88059C086Ea95712d105A2026048c39B").unwrap() - } - Network::Mainnet => H160::from_str("0xeF2A435e5EE44B2041100EF8cbC8ae035166606c").unwrap(), - } -} - // Will submit the proofs to the batcher and wait for their responses // Will return once all proofs are responded, or up to a proof that is responded with an error async fn _submit_multiple( @@ -328,7 +306,7 @@ async fn _submit_multiple( let response_stream = Arc::new(Mutex::new(response_stream)); - let payment_service_addr = get_payment_service_address(network); + let payment_service_addr = network.get_batcher_payment_service_address(); let result = async { let sent_verification_data_rev = send_messages( @@ -498,8 +476,8 @@ async fn _is_proof_verified( network: Network, eth_rpc_provider: Provider, ) -> Result { - let contract_address = get_aligned_service_manager_address(network); - let payment_service_addr = get_payment_service_address(network); + let contract_address = network.get_aligned_service_manager_address(); + let payment_service_addr = network.get_batcher_payment_service_address(); // All the elements from the merkle proof have to be concatenated let merkle_proof: Vec = aligned_verification_data @@ -640,7 +618,7 @@ pub async fn get_nonce_from_ethereum( let eth_rpc_provider = Provider::::try_from(eth_rpc_url) .map_err(|e| GetNonceError::EthRpcError(e.to_string()))?; - let payment_service_address = get_payment_service_address(network); + let payment_service_address = network.get_batcher_payment_service_address(); match batcher_payment_service(eth_rpc_provider, payment_service_address).await { Ok(contract) => { @@ -691,7 +669,7 @@ pub async fn deposit_to_aligned( signer: SignerMiddleware, LocalWallet>, network: Network, ) -> Result { - let payment_service_address = get_payment_service_address(network); + let payment_service_address = network.get_batcher_payment_service_address(); let from = signer.address(); let tx = TransactionRequest::new() @@ -729,7 +707,7 @@ pub async fn get_balance_in_aligned( let eth_rpc_provider = Provider::::try_from(eth_rpc_url) .map_err(|e| errors::BalanceError::EthereumProviderError(e.to_string()))?; - let payment_service_address = get_payment_service_address(network); + let payment_service_address = network.get_batcher_payment_service_address(); match batcher_payment_service(eth_rpc_provider, payment_service_address).await { Ok(batcher_payment_service) => { diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 1153cacbd..fe51bbba4 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -120,7 +120,7 @@ pub struct SubmitArgs { long = "network", default_value = "devnet" )] - network: NetworkArg, + network: Network, } #[derive(Parser, Debug)] @@ -143,7 +143,7 @@ pub struct DepositToBatcherArgs { long = "network", default_value = "devnet" )] - network: NetworkArg, + network: Network, #[arg(name = "Amount to deposit", long = "amount", required = true)] amount: String, } @@ -164,7 +164,7 @@ pub struct VerifyProofOnchainArgs { long = "network", default_value = "devnet" )] - network: NetworkArg, + network: Network, } #[derive(Parser, Debug)] @@ -186,7 +186,7 @@ pub struct GetUserBalanceArgs { long = "network", default_value = "devnet" )] - network: NetworkArg, + network: Network, #[arg( name = "Ethereum RPC provider address", long = "rpc_url", @@ -218,25 +218,6 @@ pub struct GetUserNonceArgs { address: String, } -#[derive(Debug, Clone, ValueEnum, Copy)] -enum NetworkArg { - Devnet, - Holesky, - HoleskyStage, - Mainnet, -} - -impl From for Network { - fn from(env_arg: NetworkArg) -> Self { - match env_arg { - NetworkArg::Devnet => Network::Devnet, - NetworkArg::Holesky => Network::Holesky, - NetworkArg::HoleskyStage => Network::HoleskyStage, - NetworkArg::Mainnet => Network::Mainnet, - } - } -} - #[derive(Debug, Clone, ValueEnum)] pub enum ProvingSystemArg { #[clap(name = "GnarkPlonkBls12_381")] @@ -366,7 +347,7 @@ async fn main() -> Result<(), AlignedError> { let aligned_verification_data_vec = submit_multiple( &connect_addr, - submit_args.network.into(), + submit_args.network, &verification_data_arr, max_fee_wei, wallet.clone(), @@ -425,7 +406,7 @@ async fn main() -> Result<(), AlignedError> { info!("Verifying response data matches sent proof data..."); let response = is_proof_verified( &aligned_verification_data, - verify_inclusion_args.network.into(), + verify_inclusion_args.network, &verify_inclusion_args.eth_rpc_url, ) .await?; @@ -490,9 +471,7 @@ async fn main() -> Result<(), AlignedError> { let client = SignerMiddleware::new(eth_rpc_provider.clone(), wallet.clone()); - match deposit_to_aligned(amount_wei, client, deposit_to_batcher_args.network.into()) - .await - { + match deposit_to_aligned(amount_wei, client, deposit_to_batcher_args.network).await { Ok(receipt) => { info!( "Payment sent to the batcher successfully. Tx: 0x{:x}", @@ -509,7 +488,7 @@ async fn main() -> Result<(), AlignedError> { match get_balance_in_aligned( user_address, &get_user_balance_args.eth_rpc_url, - get_user_balance_args.network.into(), + get_user_balance_args.network, ) .await { From bd1139b0857d20ee45a498013499a2590ea2bb82 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Tue, 10 Dec 2024 15:05:56 -0300 Subject: [PATCH 14/45] add lock --- batcher/Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/batcher/Cargo.lock b/batcher/Cargo.lock index f04cb8c63..8183b1673 100644 --- a/batcher/Cargo.lock +++ b/batcher/Cargo.lock @@ -130,6 +130,7 @@ name = "aligned-sdk" version = "0.1.0" dependencies = [ "ciborium", + "clap", "dialoguer", "ethers", "futures-util", From bab051aea8c466844d9d758faf61b96774ede272 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Thu, 2 Jan 2025 16:29:25 -0300 Subject: [PATCH 15/45] pass by copy --- batcher/aligned-sdk/src/core/types.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index 3c5a07a18..a041fe26d 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -407,7 +407,7 @@ pub enum Network { } impl Network { - pub fn get_batcher_payment_service_address(&self) -> ethers::types::H160 { + pub fn get_batcher_payment_service_address(self) -> ethers::types::H160 { match self { Self::Devnet => H160::from_str("0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650").unwrap(), Self::Holesky => H160::from_str("0x815aeCA64a974297942D2Bbf034ABEe22a38A003").unwrap(), @@ -418,7 +418,7 @@ impl Network { } } - pub fn get_aligned_service_manager_address(&self) -> ethers::types::H160 { + pub fn get_aligned_service_manager_address(self) -> ethers::types::H160 { match self { Self::Devnet => H160::from_str("0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8").unwrap(), Self::Holesky => H160::from_str("0x58F280BeBE9B34c9939C3C39e0890C81f163B623").unwrap(), From 8c4049afbc5fef7a5c556f3000ab788669b6c491 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Tue, 7 Jan 2025 12:04:28 -0300 Subject: [PATCH 16/45] remove need for ValueEnum --- .../aligned-sdk/src/communication/batch.rs | 2 +- batcher/aligned-sdk/src/core/types.rs | 7 +++---- batcher/aligned-sdk/src/sdk.rs | 6 +++--- batcher/aligned/src/main.rs | 19 ++++++++++++------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/batch.rs b/batcher/aligned-sdk/src/communication/batch.rs index d3935593f..56c0b2ad1 100644 --- a/batcher/aligned-sdk/src/communication/batch.rs +++ b/batcher/aligned-sdk/src/communication/batch.rs @@ -41,7 +41,7 @@ pub async fn await_batch_verification( network: Network, ) -> Result<(), errors::SubmitError> { for _ in 0..RETRIES { - if is_proof_verified(aligned_verification_data, network, rpc_url) + if is_proof_verified(aligned_verification_data, network.clone(), rpc_url) .await .is_ok_and(|r| r) { diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index a041fe26d..b716e811e 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -3,7 +3,6 @@ use std::fmt::Display; use std::fmt::Formatter; use std::str::FromStr; -use clap::ValueEnum; use ethers::core::k256::ecdsa::SigningKey; use ethers::signers::Signer; use ethers::signers::Wallet; @@ -398,7 +397,7 @@ pub enum GetNonceResponseMessage { InvalidRequest(String), } -#[derive(Debug, Clone, Copy, ValueEnum)] +#[derive(Debug, Clone)] pub enum Network { Devnet, Holesky, @@ -407,7 +406,7 @@ pub enum Network { } impl Network { - pub fn get_batcher_payment_service_address(self) -> ethers::types::H160 { + pub fn get_batcher_payment_service_address(&self) -> ethers::types::H160 { match self { Self::Devnet => H160::from_str("0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650").unwrap(), Self::Holesky => H160::from_str("0x815aeCA64a974297942D2Bbf034ABEe22a38A003").unwrap(), @@ -418,7 +417,7 @@ impl Network { } } - pub fn get_aligned_service_manager_address(self) -> ethers::types::H160 { + pub fn get_aligned_service_manager_address(&self) -> ethers::types::H160 { match self { Self::Devnet => H160::from_str("0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8").unwrap(), Self::Holesky => H160::from_str("0x58F280BeBE9B34c9939C3C39e0890C81f163B623").unwrap(), diff --git a/batcher/aligned-sdk/src/sdk.rs b/batcher/aligned-sdk/src/sdk.rs index c3cb2a7a8..27cd4cb16 100644 --- a/batcher/aligned-sdk/src/sdk.rs +++ b/batcher/aligned-sdk/src/sdk.rs @@ -89,7 +89,7 @@ pub async fn submit_multiple_and_wait_verification( ) -> Vec> { let mut aligned_verification_data = submit_multiple( batcher_url, - network, + network.clone(), verification_data, max_fee, wallet, @@ -102,7 +102,7 @@ pub async fn submit_multiple_and_wait_verification( let mut error_awaiting_batch_verification: Option = None; for aligned_verification_data_item in aligned_verification_data.iter().flatten() { if let Err(e) = - await_batch_verification(aligned_verification_data_item, eth_rpc_url, network).await + await_batch_verification(aligned_verification_data_item, eth_rpc_url, network.clone()).await { error_awaiting_batch_verification = Some(e); break; @@ -476,7 +476,7 @@ async fn _is_proof_verified( network: Network, eth_rpc_provider: Provider, ) -> Result { - let contract_address = network.get_aligned_service_manager_address(); + let contract_address = network.clone().get_aligned_service_manager_address(); let payment_service_addr = network.get_batcher_payment_service_address(); // All the elements from the merkle proof have to be concatenated diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index fe51bbba4..fbc62abe1 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -14,6 +14,7 @@ use aligned_sdk::sdk::get_chain_id; use aligned_sdk::sdk::get_nonce_from_batcher; use aligned_sdk::sdk::{deposit_to_aligned, get_balance_in_aligned}; use aligned_sdk::sdk::{get_vk_commitment, is_proof_verified, save_response, submit_multiple}; +use clap::value_parser; use clap::Parser; use clap::Subcommand; use clap::ValueEnum; @@ -118,7 +119,8 @@ pub struct SubmitArgs { #[arg( name = "The working network's name", long = "network", - default_value = "devnet" + default_value = "devnet", + value_parser = value_parser!(Network) )] network: Network, } @@ -141,7 +143,8 @@ pub struct DepositToBatcherArgs { #[arg( name = "The working network's name", long = "network", - default_value = "devnet" + default_value = "devnet", + value_parser = value_parser!(Network) )] network: Network, #[arg(name = "Amount to deposit", long = "amount", required = true)] @@ -162,7 +165,8 @@ pub struct VerifyProofOnchainArgs { #[arg( name = "The working network's name", long = "network", - default_value = "devnet" + default_value = "devnet", + value_parser = value_parser!(Network) )] network: Network, } @@ -184,7 +188,8 @@ pub struct GetUserBalanceArgs { #[arg( name = "The working network's name", long = "network", - default_value = "devnet" + default_value = "devnet", + value_parser = value_parser!(Network) )] network: Network, #[arg( @@ -347,7 +352,7 @@ async fn main() -> Result<(), AlignedError> { let aligned_verification_data_vec = submit_multiple( &connect_addr, - submit_args.network, + submit_args.network.into(), &verification_data_arr, max_fee_wei, wallet.clone(), @@ -406,7 +411,7 @@ async fn main() -> Result<(), AlignedError> { info!("Verifying response data matches sent proof data..."); let response = is_proof_verified( &aligned_verification_data, - verify_inclusion_args.network, + verify_inclusion_args.network.into(), &verify_inclusion_args.eth_rpc_url, ) .await?; @@ -471,7 +476,7 @@ async fn main() -> Result<(), AlignedError> { let client = SignerMiddleware::new(eth_rpc_provider.clone(), wallet.clone()); - match deposit_to_aligned(amount_wei, client, deposit_to_batcher_args.network).await { + match deposit_to_aligned(amount_wei, client, deposit_to_batcher_args.network.into()).await { Ok(receipt) => { info!( "Payment sent to the batcher successfully. Tx: 0x{:x}", From a289328a88c46fa725ee63225a5b9deb07f4e5d8 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Tue, 7 Jan 2025 12:12:46 -0300 Subject: [PATCH 17/45] fmt + clippy --- batcher/aligned-sdk/src/sdk.rs | 3 ++- batcher/aligned/src/main.rs | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/batcher/aligned-sdk/src/sdk.rs b/batcher/aligned-sdk/src/sdk.rs index 27cd4cb16..2e698ad99 100644 --- a/batcher/aligned-sdk/src/sdk.rs +++ b/batcher/aligned-sdk/src/sdk.rs @@ -102,7 +102,8 @@ pub async fn submit_multiple_and_wait_verification( let mut error_awaiting_batch_verification: Option = None; for aligned_verification_data_item in aligned_verification_data.iter().flatten() { if let Err(e) = - await_batch_verification(aligned_verification_data_item, eth_rpc_url, network.clone()).await + await_batch_verification(aligned_verification_data_item, eth_rpc_url, network.clone()) + .await { error_awaiting_batch_verification = Some(e); break; diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index fbc62abe1..9601238a6 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -352,7 +352,7 @@ async fn main() -> Result<(), AlignedError> { let aligned_verification_data_vec = submit_multiple( &connect_addr, - submit_args.network.into(), + submit_args.network, &verification_data_arr, max_fee_wei, wallet.clone(), @@ -411,7 +411,7 @@ async fn main() -> Result<(), AlignedError> { info!("Verifying response data matches sent proof data..."); let response = is_proof_verified( &aligned_verification_data, - verify_inclusion_args.network.into(), + verify_inclusion_args.network, &verify_inclusion_args.eth_rpc_url, ) .await?; @@ -476,7 +476,7 @@ async fn main() -> Result<(), AlignedError> { let client = SignerMiddleware::new(eth_rpc_provider.clone(), wallet.clone()); - match deposit_to_aligned(amount_wei, client, deposit_to_batcher_args.network.into()).await { + match deposit_to_aligned(amount_wei, client, deposit_to_batcher_args.network).await { Ok(receipt) => { info!( "Payment sent to the batcher successfully. Tx: 0x{:x}", From 82fa72172df3383d6a999cc21f748b3293b5a235 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Wed, 8 Jan 2025 13:33:59 -0300 Subject: [PATCH 18/45] move values to constants --- batcher/aligned-sdk/src/core/constants.rs | 18 +++++++++++++++++ batcher/aligned-sdk/src/core/types.rs | 24 +++++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/batcher/aligned-sdk/src/core/constants.rs b/batcher/aligned-sdk/src/core/constants.rs index b7a253f7a..e71e48bf4 100644 --- a/batcher/aligned-sdk/src/core/constants.rs +++ b/batcher/aligned-sdk/src/core/constants.rs @@ -37,3 +37,21 @@ pub const BUMP_MIN_RETRY_DELAY: u64 = 500; // milliseconds pub const BUMP_MAX_RETRIES: usize = 33; // ~ 1 day pub const BUMP_BACKOFF_FACTOR: f32 = 2.0; pub const BUMP_MAX_RETRY_DELAY: u64 = 3600; // seconds + +/// NETWORK ADDRESSES /// +/// BatcherPaymentService +pub const BATCHER_PAYMENT_SERVICE_ADDRESS_DEVNET: &str = + "0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650"; +pub const BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY: &str = + "0x815aeCA64a974297942D2Bbf034ABEe22a38A003"; +pub const BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY_STAGE: &str = + "0x7577Ec4ccC1E6C529162ec8019A49C13F6DAd98b"; +pub const BATCHER_PAYMENT_SERVICE_ADDRESS_MAINNET: &str = + "0xb0567184A52cB40956df6333510d6eF35B89C8de"; +/// AlignedServiceManager +pub const ALIGNED_SERVICE_MANAGER_DEVNET: &str = "0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8"; +pub const ALIGNED_SERVICE_MANAGER_HOLESKY: &str = "0x58F280BeBE9B34c9939C3C39e0890C81f163B623"; +pub const ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE: &str = + "0x9C5231FC88059C086Ea95712d105A2026048c39B"; +pub const ALIGNED_SERVICE_MANAGER_HOLESKY_MAINNET: &str = + "0xeF2A435e5EE44B2041100EF8cbC8ae035166606c"; diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index b716e811e..6222ee302 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -19,6 +19,12 @@ use lambdaworks_crypto::merkle_tree::{ use serde::{Deserialize, Serialize}; use sha3::{Digest, Keccak256}; +use super::constants::{ + ALIGNED_SERVICE_MANAGER_DEVNET, ALIGNED_SERVICE_MANAGER_HOLESKY, + ALIGNED_SERVICE_MANAGER_HOLESKY_MAINNET, ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE, + BATCHER_PAYMENT_SERVICE_ADDRESS_DEVNET, BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY, + BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY_STAGE, BATCHER_PAYMENT_SERVICE_ADDRESS_MAINNET, +}; use super::errors::VerifySignatureError; // VerificationData is a bytes32 instead of a VerificationData struct because in the BatcherPaymentService contract @@ -408,23 +414,21 @@ pub enum Network { impl Network { pub fn get_batcher_payment_service_address(&self) -> ethers::types::H160 { match self { - Self::Devnet => H160::from_str("0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650").unwrap(), - Self::Holesky => H160::from_str("0x815aeCA64a974297942D2Bbf034ABEe22a38A003").unwrap(), + Self::Devnet => H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_DEVNET).unwrap(), + Self::Holesky => H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY).unwrap(), Self::HoleskyStage => { - H160::from_str("0x7577Ec4ccC1E6C529162ec8019A49C13F6DAd98b").unwrap() + H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY_STAGE).unwrap() } - Self::Mainnet => H160::from_str("0xb0567184A52cB40956df6333510d6eF35B89C8de").unwrap(), + Self::Mainnet => H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_MAINNET).unwrap(), } } pub fn get_aligned_service_manager_address(&self) -> ethers::types::H160 { match self { - Self::Devnet => H160::from_str("0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8").unwrap(), - Self::Holesky => H160::from_str("0x58F280BeBE9B34c9939C3C39e0890C81f163B623").unwrap(), - Self::HoleskyStage => { - H160::from_str("0x9C5231FC88059C086Ea95712d105A2026048c39B").unwrap() - } - Self::Mainnet => H160::from_str("0xeF2A435e5EE44B2041100EF8cbC8ae035166606c").unwrap(), + Self::Devnet => H160::from_str(ALIGNED_SERVICE_MANAGER_DEVNET).unwrap(), + Self::Holesky => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY).unwrap(), + Self::HoleskyStage => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE).unwrap(), + Self::Mainnet => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY_MAINNET).unwrap(), } } } From 510f6e29366c9769466fe2fc70b095478134483d Mon Sep 17 00:00:00 2001 From: PatStiles Date: Wed, 8 Jan 2025 14:18:09 -0300 Subject: [PATCH 19/45] add custom network arg --- batcher/aligned-sdk/src/core/types.rs | 30 +++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index 6222ee302..20f80eec0 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -409,6 +409,7 @@ pub enum Network { Holesky, HoleskyStage, Mainnet, + Custom(String, String) } impl Network { @@ -420,6 +421,7 @@ impl Network { H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY_STAGE).unwrap() } Self::Mainnet => H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_MAINNET).unwrap(), + Self::Custom(s, _) => H160::from_str(s.as_str()).unwrap(), } } @@ -429,6 +431,7 @@ impl Network { Self::Holesky => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY).unwrap(), Self::HoleskyStage => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE).unwrap(), Self::Mainnet => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY_MAINNET).unwrap(), + Self::Custom(_, s) => H160::from_str(s.as_str()).unwrap(), } } } @@ -442,10 +445,29 @@ impl FromStr for Network { "holesky-stage" => Ok(Network::HoleskyStage), "devnet" => Ok(Network::Devnet), "mainnet" => Ok(Network::Mainnet), - _ => Err( - "Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\", \"mainnet\"" - .to_string(), - ), + s => { + if !s.contains("custom") { + return Err( + "Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\", \"mainnet\", \"'custom '\"" + .to_string(), + ) + } + let parts: Vec<&str> = s.split_whitespace().collect(); + + if parts.len() == 3 { + Ok(Network::Custom( + parts[1].to_string(), + parts[2].to_string() + )) + } else { + Err( + "Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\", \"mainnet\", \"'custom '\"" + .to_string() + ) + } + + + } } } } From 9b2d37b44d0c1cb1241015e5f508559203221984 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Wed, 8 Jan 2025 14:18:49 -0300 Subject: [PATCH 20/45] fmt --- batcher/aligned-sdk/src/core/types.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index 20f80eec0..93fe3d547 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -409,7 +409,7 @@ pub enum Network { Holesky, HoleskyStage, Mainnet, - Custom(String, String) + Custom(String, String), } impl Network { @@ -450,23 +450,18 @@ impl FromStr for Network { return Err( "Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\", \"mainnet\", \"'custom '\"" .to_string(), - ) + ); } let parts: Vec<&str> = s.split_whitespace().collect(); if parts.len() == 3 { - Ok(Network::Custom( - parts[1].to_string(), - parts[2].to_string() - )) + Ok(Network::Custom(parts[1].to_string(), parts[2].to_string())) } else { Err( "Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\", \"mainnet\", \"'custom '\"" .to_string() ) } - - } } } From a320ab07e465e9727b950aa89935aca422bed278 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Wed, 8 Jan 2025 14:50:34 -0300 Subject: [PATCH 21/45] change error messages --- batcher/aligned-sdk/src/core/types.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index 93fe3d547..9aa769e47 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -448,7 +448,7 @@ impl FromStr for Network { s => { if !s.contains("custom") { return Err( - "Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\", \"mainnet\", \"'custom '\"" + "Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\", \"mainnet\", \"custom \"" .to_string(), ); } @@ -458,7 +458,7 @@ impl FromStr for Network { Ok(Network::Custom(parts[1].to_string(), parts[2].to_string())) } else { Err( - "Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\", \"mainnet\", \"'custom '\"" + "Invalid custom network, \"custom \"" .to_string() ) } From 587a5fad988ad2fd3cf114c67ee58a1cd412f466 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 10 Jan 2025 11:32:39 -0300 Subject: [PATCH 22/45] enforce custom in right place + fix --- batcher/aligned-sdk/src/core/constants.rs | 4 ++-- batcher/aligned-sdk/src/core/types.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/batcher/aligned-sdk/src/core/constants.rs b/batcher/aligned-sdk/src/core/constants.rs index e71e48bf4..6bc085868 100644 --- a/batcher/aligned-sdk/src/core/constants.rs +++ b/batcher/aligned-sdk/src/core/constants.rs @@ -49,9 +49,9 @@ pub const BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY_STAGE: &str = pub const BATCHER_PAYMENT_SERVICE_ADDRESS_MAINNET: &str = "0xb0567184A52cB40956df6333510d6eF35B89C8de"; /// AlignedServiceManager -pub const ALIGNED_SERVICE_MANAGER_DEVNET: &str = "0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8"; +pub const ALIGNED_SERVICE_MANAGER_DEVNET: &str = "0x851356ae760d987E095750cCeb3bC6014560891C"; pub const ALIGNED_SERVICE_MANAGER_HOLESKY: &str = "0x58F280BeBE9B34c9939C3C39e0890C81f163B623"; pub const ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE: &str = "0x9C5231FC88059C086Ea95712d105A2026048c39B"; -pub const ALIGNED_SERVICE_MANAGER_HOLESKY_MAINNET: &str = +pub const ALIGNED_SERVICE_MANAGER_MAINNET: &str = "0xeF2A435e5EE44B2041100EF8cbC8ae035166606c"; diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index 9aa769e47..03b0db973 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -21,7 +21,7 @@ use sha3::{Digest, Keccak256}; use super::constants::{ ALIGNED_SERVICE_MANAGER_DEVNET, ALIGNED_SERVICE_MANAGER_HOLESKY, - ALIGNED_SERVICE_MANAGER_HOLESKY_MAINNET, ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE, + ALIGNED_SERVICE_MANAGER_MAINNET, ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE, BATCHER_PAYMENT_SERVICE_ADDRESS_DEVNET, BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY, BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY_STAGE, BATCHER_PAYMENT_SERVICE_ADDRESS_MAINNET, }; @@ -430,7 +430,7 @@ impl Network { Self::Devnet => H160::from_str(ALIGNED_SERVICE_MANAGER_DEVNET).unwrap(), Self::Holesky => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY).unwrap(), Self::HoleskyStage => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE).unwrap(), - Self::Mainnet => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY_MAINNET).unwrap(), + Self::Mainnet => H160::from_str(ALIGNED_SERVICE_MANAGER_MAINNET).unwrap(), Self::Custom(_, s) => H160::from_str(s.as_str()).unwrap(), } } @@ -454,7 +454,7 @@ impl FromStr for Network { } let parts: Vec<&str> = s.split_whitespace().collect(); - if parts.len() == 3 { + if parts.len() == 3 && parts[0].contains("custom") { Ok(Network::Custom(parts[1].to_string(), parts[2].to_string())) } else { Err( From 1a4ef2914137bac57ee578090c67049957cea979 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Thu, 9 Jan 2025 16:37:23 -0300 Subject: [PATCH 23/45] remove clap from cargo.toml --- batcher/aligned-sdk/Cargo.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/batcher/aligned-sdk/Cargo.toml b/batcher/aligned-sdk/Cargo.toml index 9b1bcedd0..90b828ba3 100644 --- a/batcher/aligned-sdk/Cargo.toml +++ b/batcher/aligned-sdk/Cargo.toml @@ -24,5 +24,4 @@ url = "2.5.0" hex = "0.4.3" ciborium = "=0.2.2" serde_repr = "0.1.19" -dialoguer = "0.11.0" -clap = { version = "4.5.4", features = ["derive"] } +dialoguer = "0.11.0" \ No newline at end of file From 0ac4db3b077c23b733aafafb16876b7d6c4770f5 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 10 Jan 2025 15:02:18 -0300 Subject: [PATCH 24/45] deprecate batcher_url --- alerts/.env.devnet | 1 - alerts/.env.example | 1 - alerts/sender_with_alert.sh | 4 +- batcher/aligned-sdk/src/core/constants.rs | 5 +++ batcher/aligned-sdk/src/core/types.rs | 25 ++++++++--- batcher/aligned-sdk/src/sdk.rs | 21 +++------ batcher/aligned-task-sender/README.md | 2 - batcher/aligned-task-sender/src/commands.rs | 7 +-- batcher/aligned-task-sender/src/structs.rs | 44 ++++++------------- batcher/aligned/generate_proof_and_send.sh | 2 - .../send_infinite_sp1_tasks.sh | 2 - batcher/aligned/send_infinite_tasks.sh | 2 - batcher/aligned/src/main.rs | 20 +++------ 13 files changed, 51 insertions(+), 85 deletions(-) diff --git a/alerts/.env.devnet b/alerts/.env.devnet index cf967dba1..55bfc07ba 100644 --- a/alerts/.env.devnet +++ b/alerts/.env.devnet @@ -24,7 +24,6 @@ # Variables for sender_with_alert.sh REPETITIONS=8 SENDER_ADDRESS=0x14dC79964da2C08b23698B3D3cc7Ca32193d9955 -BATCHER_URL=ws://localhost:8080 RPC_URL=http://localhost:8545 EXPLORER_URL=http://localhost:3000 NETWORK=devnet diff --git a/alerts/.env.example b/alerts/.env.example index 2c0fe8a84..d210912a5 100644 --- a/alerts/.env.example +++ b/alerts/.env.example @@ -26,7 +26,6 @@ NETWORK= # Variables for sender_with_alert.sh REPETITIONS= SENDER_ADDRESS= -BATCHER_URL= RPC_URL= EXPLORER_URL= NETWORK= diff --git a/alerts/sender_with_alert.sh b/alerts/sender_with_alert.sh index 3b70d57d7..124a675e7 100755 --- a/alerts/sender_with_alert.sh +++ b/alerts/sender_with_alert.sh @@ -4,7 +4,6 @@ # - REPETITIONS # - EXPLORER_URL # - SENDER_ADDRESS -# - BATCHER_URL # - RPC_URL # - EXPLORER_URL # - NETWORK @@ -76,7 +75,7 @@ do mkdir -p ./scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs ## Generate Proof - nonce=$(aligned get-user-nonce --batcher_url $BATCHER_URL --user_addr $SENDER_ADDRESS 2>&1 | awk '{print $9}') + nonce=$(aligned get-user-nonce --network $NETWORK --user_addr $SENDER_ADDRESS 2>&1 | awk '{print $9}') x=$((nonce + 1)) # So we don't have any issues with nonce = 0 echo "Generating proof $x != 0" go run ./scripts/test_files/gnark_groth16_bn254_infinite_script/cmd/main.go $x @@ -92,7 +91,6 @@ do --proof_generator_addr $SENDER_ADDRESS \ --private_key $PRIVATE_KEY \ --rpc_url $RPC_URL \ - --batcher_url $BATCHER_URL \ --network $NETWORK \ --max_fee 4000000000000000 \ 2>&1) diff --git a/batcher/aligned-sdk/src/core/constants.rs b/batcher/aligned-sdk/src/core/constants.rs index 6bc085868..900800b83 100644 --- a/batcher/aligned-sdk/src/core/constants.rs +++ b/batcher/aligned-sdk/src/core/constants.rs @@ -55,3 +55,8 @@ pub const ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE: &str = "0x9C5231FC88059C086Ea95712d105A2026048c39B"; pub const ALIGNED_SERVICE_MANAGER_MAINNET: &str = "0xeF2A435e5EE44B2041100EF8cbC8ae035166606c"; +/// Batcher URL's +pub const BATCHER_URL_DEVNET: &str = "ws://localhost:8080"; +pub const BATCHER_URL_HOLESKY: &str = "wss://holesky.batcher.alignedlayer.com"; +pub const BATCHER_URL_HOLESKY_STAGE: &str = "wss://stage.batcher.alignedlayer.com"; +pub const BATCHER_URL_MAINNET: &str = "wss://batcher.alignedlayer.com"; \ No newline at end of file diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index 03b0db973..b440415f6 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -24,6 +24,7 @@ use super::constants::{ ALIGNED_SERVICE_MANAGER_MAINNET, ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE, BATCHER_PAYMENT_SERVICE_ADDRESS_DEVNET, BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY, BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY_STAGE, BATCHER_PAYMENT_SERVICE_ADDRESS_MAINNET, + BATCHER_URL_DEVNET, BATCHER_URL_HOLESKY, BATCHER_URL_HOLESKY_STAGE, BATCHER_URL_MAINNET, }; use super::errors::VerifySignatureError; @@ -409,7 +410,7 @@ pub enum Network { Holesky, HoleskyStage, Mainnet, - Custom(String, String), + Custom(String, String, String), } impl Network { @@ -421,7 +422,7 @@ impl Network { H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY_STAGE).unwrap() } Self::Mainnet => H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_MAINNET).unwrap(), - Self::Custom(s, _) => H160::from_str(s.as_str()).unwrap(), + Self::Custom(s, _, _) => H160::from_str(s.as_str()).unwrap(), } } @@ -431,7 +432,17 @@ impl Network { Self::Holesky => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY).unwrap(), Self::HoleskyStage => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE).unwrap(), Self::Mainnet => H160::from_str(ALIGNED_SERVICE_MANAGER_MAINNET).unwrap(), - Self::Custom(_, s) => H160::from_str(s.as_str()).unwrap(), + Self::Custom(_, s, _) => H160::from_str(s.as_str()).unwrap(), + } + } + + pub fn get_batcher_url(&self) -> &str { + match self { + Self::Devnet => BATCHER_URL_DEVNET, + Self::Holesky => BATCHER_URL_HOLESKY, + Self::HoleskyStage => BATCHER_URL_HOLESKY_STAGE, + Self::Mainnet => BATCHER_URL_MAINNET, + Self::Custom(_, _, s) => s.as_str(), } } } @@ -448,17 +459,17 @@ impl FromStr for Network { s => { if !s.contains("custom") { return Err( - "Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\", \"mainnet\", \"custom \"" + "Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\", \"mainnet\", \"custom \"" .to_string(), ); } let parts: Vec<&str> = s.split_whitespace().collect(); - if parts.len() == 3 && parts[0].contains("custom") { - Ok(Network::Custom(parts[1].to_string(), parts[2].to_string())) + if parts.len() == 4 && parts[0].contains("custom") { + Ok(Network::Custom(parts[1].to_string(), parts[2].to_string(), parts[3].to_string())) } else { Err( - "Invalid custom network, \"custom \"" + "Invalid custom network, \"custom \"" .to_string() ) } diff --git a/batcher/aligned-sdk/src/sdk.rs b/batcher/aligned-sdk/src/sdk.rs index 2e698ad99..13de4b62d 100644 --- a/batcher/aligned-sdk/src/sdk.rs +++ b/batcher/aligned-sdk/src/sdk.rs @@ -49,7 +49,6 @@ use std::path::PathBuf; /// Submits multiple proofs to the batcher to be verified in Aligned and waits for the verification on-chain. /// # Arguments -/// * `batcher_url` - The url of the batcher to which the proof will be submitted. /// * `eth_rpc_url` - The URL of the Ethereum RPC node. /// * `chain` - The chain on which the verification will be done. /// * `verification_data` - An array of verification data of each proof. @@ -79,7 +78,6 @@ use std::path::PathBuf; /// * `GenericError` if the error doesn't match any of the previous ones. #[allow(clippy::too_many_arguments)] // TODO: Refactor this function, use NoncedVerificationData pub async fn submit_multiple_and_wait_verification( - batcher_url: &str, eth_rpc_url: &str, network: Network, verification_data: &[VerificationData], @@ -88,8 +86,7 @@ pub async fn submit_multiple_and_wait_verification( nonce: U256, ) -> Vec> { let mut aligned_verification_data = submit_multiple( - batcher_url, - network.clone(), + network, verification_data, max_fee, wallet, @@ -219,7 +216,6 @@ async fn fetch_gas_price( /// Submits multiple proofs to the batcher to be verified in Aligned. /// # Arguments -/// * `batcher_url` - The url of the batcher to which the proof will be submitted. /// * `network` - The netork on which the verification will be done. /// * `verification_data` - An array of verification data of each proof. /// * `max_fees` - An array of the maximum fee that the submitter is willing to pay for each proof verification. @@ -243,14 +239,13 @@ async fn fetch_gas_price( /// * `ProofQueueFlushed` if there is an error in the batcher and the proof queue is flushed. /// * `GenericError` if the error doesn't match any of the previous ones. pub async fn submit_multiple( - batcher_url: &str, network: Network, verification_data: &[VerificationData], max_fee: U256, wallet: Wallet, nonce: U256, ) -> Vec> { - let (ws_stream, _) = match connect_async(batcher_url).await { + let (ws_stream, _) = match connect_async(network.get_batcher_url()).await { Ok((ws_stream, response)) => (ws_stream, response), Err(e) => return vec![Err(errors::SubmitError::WebSocketConnectionError(e))], }; @@ -333,7 +328,6 @@ async fn _submit_multiple( /// Submits a proof to the batcher to be verified in Aligned and waits for the verification on-chain. /// # Arguments -/// * `batcher_url` - The url of the batcher to which the proof will be submitted. /// * `eth_rpc_url` - The URL of the Ethereum RPC node. /// * `chain` - The chain on which the verification will be done. /// * `verification_data` - The verification data of the proof. @@ -363,7 +357,6 @@ async fn _submit_multiple( /// * `GenericError` if the error doesn't match any of the previous ones. #[allow(clippy::too_many_arguments)] // TODO: Refactor this function, use NoncedVerificationData pub async fn submit_and_wait_verification( - batcher_url: &str, eth_rpc_url: &str, network: Network, verification_data: &VerificationData, @@ -374,7 +367,6 @@ pub async fn submit_and_wait_verification( let verification_data = vec![verification_data.clone()]; let aligned_verification_data = submit_multiple_and_wait_verification( - batcher_url, eth_rpc_url, network, &verification_data, @@ -395,7 +387,6 @@ pub async fn submit_and_wait_verification( /// Submits a proof to the batcher to be verified in Aligned. /// # Arguments -/// * `batcher_url` - The url of the batcher to which the proof will be submitted. /// * `chain` - The chain on which the verification will be done. /// * `verification_data` - The verification data of the proof. /// * `max_fee` - The maximum fee that the submitter is willing to pay for the verification. @@ -419,7 +410,6 @@ pub async fn submit_and_wait_verification( /// * `ProofQueueFlushed` if there is an error in the batcher and the proof queue is flushed. /// * `GenericError` if the error doesn't match any of the previous ones. pub async fn submit( - batcher_url: &str, network: Network, verification_data: &VerificationData, max_fee: U256, @@ -429,7 +419,6 @@ pub async fn submit( let verification_data = vec![verification_data.clone()]; let aligned_verification_data = submit_multiple( - batcher_url, network, &verification_data, max_fee, @@ -537,17 +526,17 @@ pub fn get_vk_commitment( /// as the batcher proofs might not yet be on ethereum, /// producing an out-of-sync nonce with the payment service contract on ethereum /// # Arguments -/// * `batcher_url` - The batcher websocket url. /// * `address` - The user address for which the nonce will be retrieved. +/// * `network` - The network from which the nonce will be retrieved. /// # Returns /// * The next nonce of the proof submitter account. /// # Errors /// * `EthRpcError` if the batcher has an error in the Ethereum call when retrieving the nonce if not already cached. pub async fn get_nonce_from_batcher( - batcher_ws_url: &str, + network: Network, address: Address, ) -> Result { - let (ws_stream, _) = connect_async(batcher_ws_url).await.map_err(|_| { + let (ws_stream, _) = connect_async(network.get_batcher_url()).await.map_err(|_| { GetNonceError::ConnectionFailed("Ws connection to batcher failed".to_string()) })?; diff --git a/batcher/aligned-task-sender/README.md b/batcher/aligned-task-sender/README.md index 73b1df868..fdf49195d 100644 --- a/batcher/aligned-task-sender/README.md +++ b/batcher/aligned-task-sender/README.md @@ -61,7 +61,6 @@ To run it, you can: cargo run --release -- send-infinite-proofs \ --burst-size --burst-time-secs \ --eth-rpc-url \ - --batcher-url \ --network holesky-stage \ --proofs-dirpath $(PWD)/scripts/test_files/task_sender/proofs \ --private-keys-filepath @@ -82,7 +81,6 @@ This command enables and hangs N connections with the Batcher. To run it, you can: ``` cargo run --release -- test-connections \ - --batcher-url \ --num-senders ``` diff --git a/batcher/aligned-task-sender/src/commands.rs b/batcher/aligned-task-sender/src/commands.rs index f074b9156..233e5cb79 100644 --- a/batcher/aligned-task-sender/src/commands.rs +++ b/batcher/aligned-task-sender/src/commands.rs @@ -211,15 +211,11 @@ pub async fn generate_and_fund_wallets(args: GenerateAndFundWalletsArgs) { /// infinitely hangs connections pub async fn test_connection(args: TestConnectionsArgs) { - if args.batcher_url == "wss://batcher.alignedlayer.com" { - error!("Network not supported by the connection tester"); - return; - } info!("Going to only open a connection"); let mut handlers = vec![]; for i in 0..args.num_senders { - let ws_url = args.batcher_url.clone(); + let ws_url = args.network.get_batcher_url().clone(); let handle = tokio::spawn(async move { let conn = connect_async(ws_url).await; if let Ok((mut ws_stream, _)) = conn { @@ -349,7 +345,6 @@ pub async fn send_infinite_proofs(args: SendInfiniteProofsArgs) { let batcher_url = batcher_url.clone(); let aligned_verification_data = submit_multiple( - &batcher_url.clone(), args.network.into(), &verification_data_to_send.clone(), max_fee, diff --git a/batcher/aligned-task-sender/src/structs.rs b/batcher/aligned-task-sender/src/structs.rs index 7c5d36f6b..d2ea2b4ec 100644 --- a/batcher/aligned-task-sender/src/structs.rs +++ b/batcher/aligned-task-sender/src/structs.rs @@ -78,22 +78,24 @@ pub struct GenerateAndFundWalletsArgs { )] pub private_keys_filepath: String, #[arg( - name = "The Ethereum network's name", + name = "The working network's name", long = "network", - default_value = "devnet" + default_value = "devnet", + value_parser = value_parser!(Network) )] - pub network: NetworkArg, + pub network: Network, } #[derive(Parser, Debug)] #[command(version, about, long_about = None)] pub struct TestConnectionsArgs { #[arg( - name = "Batcher connection address", - long = "batcher-url", - default_value = "ws://localhost:8080" + name = "The working network's name", + long = "network", + default_value = "devnet", + value_parser = value_parser!(Network) )] - pub batcher_url: String, + pub network: Network, #[arg( name = "Number of spawned sockets", long = "num-senders", @@ -132,11 +134,12 @@ pub struct SendInfiniteProofsArgs { #[arg(name = "Max Fee", long = "max-fee", default_value = "1300000000000000")] pub max_fee: String, #[arg( - name = "The Ethereum network's name", + name = "The working network's name", long = "network", - default_value = "devnet" + default_value = "devnet", + value_parser = value_parser!(Network) )] - pub network: NetworkArg, + pub network: Network, #[arg( name = "Private keys filepath for the senders", long = "private-keys-filepath" @@ -148,23 +151,4 @@ pub struct SendInfiniteProofsArgs { default_value = "devnet" )] pub proofs_dir: String, -} - -#[derive(Debug, Clone, Copy, ValueEnum)] -pub enum NetworkArg { - Devnet, - Holesky, - HoleskyStage, - Mainnet, -} - -impl From for Network { - fn from(chain_arg: NetworkArg) -> Self { - match chain_arg { - NetworkArg::Devnet => Network::Devnet, - NetworkArg::Holesky => Network::Holesky, - NetworkArg::HoleskyStage => Network::HoleskyStage, - NetworkArg::Mainnet => Network::Mainnet, - } - } -} +} \ No newline at end of file diff --git a/batcher/aligned/generate_proof_and_send.sh b/batcher/aligned/generate_proof_and_send.sh index bcfa68454..42d01b8fb 100755 --- a/batcher/aligned/generate_proof_and_send.sh +++ b/batcher/aligned/generate_proof_and_send.sh @@ -26,7 +26,6 @@ go run scripts/test_files/gnark_groth16_bn254_infinite_script/cmd/main.go $x # Set default values for RPC and BATCHER if they are not set RPC=${RPC:-http://localhost:8545} -BATCHER_CONN=${BATCHER_CONN:-ws://localhost:8080} if [ -z "$NETWORK" ]; then echo "NETWORK is not set. Setting it to devnet" NETWORK="devnet" @@ -42,7 +41,6 @@ cmd=( --vk "scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs/ineq_${x}_groth16.vk" --proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 --rpc_url "$RPC" - --batcher_url "$BATCHER_CONN" --network "$NETWORK" ) diff --git a/batcher/aligned/send_infinite_sp1_tasks/send_infinite_sp1_tasks.sh b/batcher/aligned/send_infinite_sp1_tasks/send_infinite_sp1_tasks.sh index 079a8dcc5..620a46571 100755 --- a/batcher/aligned/send_infinite_sp1_tasks/send_infinite_sp1_tasks.sh +++ b/batcher/aligned/send_infinite_sp1_tasks/send_infinite_sp1_tasks.sh @@ -13,7 +13,6 @@ else fi RPC=${RPC:-http://localhost:8545} -BATCHER_CONN=${BATCHER_CONN:-ws://localhost:8080} if [ -z "$NETWORK" ]; then echo "NETWORK is not set. Setting it to devnet" NETWORK="devnet" @@ -33,7 +32,6 @@ do --vm_program ../../scripts/test_files/sp1/sp1_fibonacci.elf \ --proof_generator_addr "$random_address" \ --network "$NETWORK" \ - --batcher_url "$BATCHER_CONN" \ --repetitions "2" \ --rpc_url "$RPC" diff --git a/batcher/aligned/send_infinite_tasks.sh b/batcher/aligned/send_infinite_tasks.sh index d79ff8ab3..90e24a401 100755 --- a/batcher/aligned/send_infinite_tasks.sh +++ b/batcher/aligned/send_infinite_tasks.sh @@ -14,7 +14,6 @@ fi # Set default values for RPC and BATCHER if they are not set RPC=${RPC:-http://localhost:8545} -BATCHER_CONN=${BATCHER_CONN:-ws://localhost:8080} if [ -z "$NETWORK" ]; then echo "NETWORK is not set. Setting it to devnet" NETWORK="devnet" @@ -35,7 +34,6 @@ do --proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \ --repetitions "2" \ --rpc_url "$RPC" \ - --batcher_url "$BATCHER_CONN" \ --network "$NETWORK" cd ../.. diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 9601238a6..bed698fb1 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -64,12 +64,6 @@ pub enum AlignedCommands { #[derive(Parser, Debug)] #[command(version, about, long_about = None)] pub struct SubmitArgs { - #[arg( - name = "Batcher connection address", - long = "batcher_url", - default_value = "ws://localhost:8080" - )] - batcher_url: String, #[arg( name = "Ethereum RPC provider connection address", long = "rpc_url", @@ -210,11 +204,12 @@ pub struct GetUserBalanceArgs { #[command(version, about, long_about = None)] pub struct GetUserNonceArgs { #[arg( - name = "Batcher connection address", - long = "batcher_url", - default_value = "ws://localhost:8080" + name = "The working network's name", + long = "network", + default_value = "devnet", + value_parser = value_parser!(Network) )] - batcher_url: String, + network: Network, #[arg( name = "The user's Ethereum address", long = "user_addr", @@ -317,7 +312,7 @@ async fn main() -> Result<(), AlignedError> { let nonce = match &submit_args.nonce { Some(nonce) => U256::from_dec_str(nonce).map_err(|_| SubmitError::InvalidNonce)?, - None => get_nonce_from_batcher(&connect_addr, wallet.address()) + None => get_nonce_from_batcher(&submit_args.network, wallet.address()) .await .map_err(|e| match e { aligned_sdk::core::errors::GetNonceError::EthRpcError(e) => { @@ -351,7 +346,6 @@ async fn main() -> Result<(), AlignedError> { info!("Submitting proofs to the Aligned batcher..."); let aligned_verification_data_vec = submit_multiple( - &connect_addr, submit_args.network, &verification_data_arr, max_fee_wei, @@ -512,7 +506,7 @@ async fn main() -> Result<(), AlignedError> { } GetUserNonce(args) => { let address = H160::from_str(&args.address).unwrap(); - match get_nonce_from_batcher(&args.batcher_url, address).await { + match get_nonce_from_batcher(&args.network, address).await { Ok(nonce) => { info!("Nonce for address {} is {}", address, nonce); } From c765ecff00bc391d1dea7288abcc67d91772fa35 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 10 Jan 2025 15:02:31 -0300 Subject: [PATCH 25/45] deprecate more --- batcher/Cargo.lock | 1 - batcher/aligned-sdk/src/sdk.rs | 2 +- batcher/aligned-task-sender/src/commands.rs | 6 +++--- batcher/aligned-task-sender/src/structs.rs | 1 + batcher/aligned/src/main.rs | 7 +++---- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/batcher/Cargo.lock b/batcher/Cargo.lock index 8183b1673..f04cb8c63 100644 --- a/batcher/Cargo.lock +++ b/batcher/Cargo.lock @@ -130,7 +130,6 @@ name = "aligned-sdk" version = "0.1.0" dependencies = [ "ciborium", - "clap", "dialoguer", "ethers", "futures-util", diff --git a/batcher/aligned-sdk/src/sdk.rs b/batcher/aligned-sdk/src/sdk.rs index 13de4b62d..7bdd13458 100644 --- a/batcher/aligned-sdk/src/sdk.rs +++ b/batcher/aligned-sdk/src/sdk.rs @@ -86,7 +86,7 @@ pub async fn submit_multiple_and_wait_verification( nonce: U256, ) -> Vec> { let mut aligned_verification_data = submit_multiple( - network, + network.clone(), verification_data, max_fee, wallet, diff --git a/batcher/aligned-task-sender/src/commands.rs b/batcher/aligned-task-sender/src/commands.rs index 233e5cb79..395b57dfa 100644 --- a/batcher/aligned-task-sender/src/commands.rs +++ b/batcher/aligned-task-sender/src/commands.rs @@ -2,7 +2,6 @@ use aligned_sdk::core::types::{Network, ProvingSystemId, VerificationData}; use aligned_sdk::sdk::{deposit_to_aligned, get_nonce_from_batcher, submit_multiple}; use ethers::prelude::*; use ethers::utils::parse_ether; -use futures_util::StreamExt; use k256::ecdsa::SigningKey; use log::{debug, error, info}; use rand::seq::SliceRandom; @@ -189,7 +188,7 @@ pub async fn generate_and_fund_wallets(args: GenerateAndFundWalletsArgs) { ); let signer = SignerMiddleware::new(eth_rpc_provider.clone(), wallet.clone()); if let Err(err) = - deposit_to_aligned(amount_to_deposit_to_aligned, signer, args.network.into()).await + deposit_to_aligned(amount_to_deposit_to_aligned, signer, args.network.clone()).await { error!("Could not deposit to aligned, err: {:?}", err); return; @@ -213,9 +212,10 @@ pub async fn generate_and_fund_wallets(args: GenerateAndFundWalletsArgs) { pub async fn test_connection(args: TestConnectionsArgs) { info!("Going to only open a connection"); let mut handlers = vec![]; + let network = network.clone(); for i in 0..args.num_senders { - let ws_url = args.network.get_batcher_url().clone(); + let ws_url = network.get_batcher_url().clone(); let handle = tokio::spawn(async move { let conn = connect_async(ws_url).await; if let Ok((mut ws_stream, _)) = conn { diff --git a/batcher/aligned-task-sender/src/structs.rs b/batcher/aligned-task-sender/src/structs.rs index d2ea2b4ec..3456047a4 100644 --- a/batcher/aligned-task-sender/src/structs.rs +++ b/batcher/aligned-task-sender/src/structs.rs @@ -1,4 +1,5 @@ use aligned_sdk::core::types::Network; +use clap::value_parser; use clap::Parser; use clap::Subcommand; use clap::ValueEnum; diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index bed698fb1..9ae991941 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -272,7 +272,6 @@ async fn main() -> Result<(), AlignedError> { })?; let repetitions = submit_args.repetitions; - let connect_addr = submit_args.batcher_url.clone(); let keystore_path = &submit_args.keystore_path; let private_key = &submit_args.private_key; @@ -312,7 +311,7 @@ async fn main() -> Result<(), AlignedError> { let nonce = match &submit_args.nonce { Some(nonce) => U256::from_dec_str(nonce).map_err(|_| SubmitError::InvalidNonce)?, - None => get_nonce_from_batcher(&submit_args.network, wallet.address()) + None => get_nonce_from_batcher(submit_args.network, wallet.address()) .await .map_err(|e| match e { aligned_sdk::core::errors::GetNonceError::EthRpcError(e) => { @@ -346,7 +345,7 @@ async fn main() -> Result<(), AlignedError> { info!("Submitting proofs to the Aligned batcher..."); let aligned_verification_data_vec = submit_multiple( - submit_args.network, + submit_args.network.clone(), &verification_data_arr, max_fee_wei, wallet.clone(), @@ -506,7 +505,7 @@ async fn main() -> Result<(), AlignedError> { } GetUserNonce(args) => { let address = H160::from_str(&args.address).unwrap(); - match get_nonce_from_batcher(&args.network, address).await { + match get_nonce_from_batcher(args.network, address).await { Ok(nonce) => { info!("Nonce for address {} is {}", address, nonce); } From 2f6da7c711ae198f1dbf92818edccf5d9c7e477d Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Wed, 15 Jan 2025 18:38:17 -0300 Subject: [PATCH 26/45] feat: better implementation of this pr --- batcher/aligned-sdk/src/core/types.rs | 50 ++------- batcher/aligned/src/main.rs | 141 ++++++++++++++++++-------- docs/3_guides/9_aligned_cli.md | 55 +++++++--- 3 files changed, 148 insertions(+), 98 deletions(-) diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index b440415f6..596cd9bc1 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -414,6 +414,16 @@ pub enum Network { } impl Network { + pub fn get_aligned_service_manager_address(&self) -> ethers::types::H160 { + match self { + Self::Devnet => H160::from_str(ALIGNED_SERVICE_MANAGER_DEVNET).unwrap(), + Self::Holesky => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY).unwrap(), + Self::HoleskyStage => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE).unwrap(), + Self::Mainnet => H160::from_str(ALIGNED_SERVICE_MANAGER_MAINNET).unwrap(), + Self::Custom(s, _, _) => H160::from_str(s.as_str()).unwrap(), + } + } + pub fn get_batcher_payment_service_address(&self) -> ethers::types::H160 { match self { Self::Devnet => H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_DEVNET).unwrap(), @@ -422,16 +432,6 @@ impl Network { H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY_STAGE).unwrap() } Self::Mainnet => H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_MAINNET).unwrap(), - Self::Custom(s, _, _) => H160::from_str(s.as_str()).unwrap(), - } - } - - pub fn get_aligned_service_manager_address(&self) -> ethers::types::H160 { - match self { - Self::Devnet => H160::from_str(ALIGNED_SERVICE_MANAGER_DEVNET).unwrap(), - Self::Holesky => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY).unwrap(), - Self::HoleskyStage => H160::from_str(ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE).unwrap(), - Self::Mainnet => H160::from_str(ALIGNED_SERVICE_MANAGER_MAINNET).unwrap(), Self::Custom(_, s, _) => H160::from_str(s.as_str()).unwrap(), } } @@ -447,36 +447,6 @@ impl Network { } } -impl FromStr for Network { - type Err = String; - - fn from_str(s: &str) -> Result { - match s.to_lowercase().as_str() { - "holesky" => Ok(Network::Holesky), - "holesky-stage" => Ok(Network::HoleskyStage), - "devnet" => Ok(Network::Devnet), - "mainnet" => Ok(Network::Mainnet), - s => { - if !s.contains("custom") { - return Err( - "Invalid network, possible values are: \"holesky\", \"holesky-stage\", \"devnet\", \"mainnet\", \"custom \"" - .to_string(), - ); - } - let parts: Vec<&str> = s.split_whitespace().collect(); - - if parts.len() == 4 && parts[0].contains("custom") { - Ok(Network::Custom(parts[1].to_string(), parts[2].to_string(), parts[3].to_string())) - } else { - Err( - "Invalid custom network, \"custom \"" - .to_string() - ) - } - } - } - } -} #[cfg(test)] mod tests { diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 9ae991941..748c33888 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -14,7 +14,6 @@ use aligned_sdk::sdk::get_chain_id; use aligned_sdk::sdk::get_nonce_from_batcher; use aligned_sdk::sdk::{deposit_to_aligned, get_balance_in_aligned}; use aligned_sdk::sdk::{get_vk_commitment, is_proof_verified, save_response, submit_multiple}; -use clap::value_parser; use clap::Parser; use clap::Subcommand; use clap::ValueEnum; @@ -110,13 +109,8 @@ pub struct SubmitArgs { max_fee: String, // String because U256 expects hex #[arg(name = "Nonce", long = "nonce")] nonce: Option, // String because U256 expects hex - #[arg( - name = "The working network's name", - long = "network", - default_value = "devnet", - value_parser = value_parser!(Network) - )] - network: Network, + #[clap(flatten)] + network: NetworkArg, } #[derive(Parser, Debug)] @@ -134,13 +128,9 @@ pub struct DepositToBatcherArgs { default_value = "http://localhost:8545" )] eth_rpc_url: String, - #[arg( - name = "The working network's name", - long = "network", - default_value = "devnet", - value_parser = value_parser!(Network) - )] - network: Network, + + #[clap(flatten)] + network: NetworkArg, #[arg(name = "Amount to deposit", long = "amount", required = true)] amount: String, } @@ -156,13 +146,9 @@ pub struct VerifyProofOnchainArgs { default_value = "http://localhost:8545" )] eth_rpc_url: String, - #[arg( - name = "The working network's name", - long = "network", - default_value = "devnet", - value_parser = value_parser!(Network) - )] - network: Network, + + #[clap(flatten)] + network: NetworkArg, } #[derive(Parser, Debug)] @@ -179,13 +165,8 @@ pub struct GetVkCommitmentArgs { #[derive(Parser, Debug)] #[command(version, about, long_about = None)] pub struct GetUserBalanceArgs { - #[arg( - name = "The working network's name", - long = "network", - default_value = "devnet", - value_parser = value_parser!(Network) - )] - network: Network, + #[clap(flatten)] + network: NetworkArg, #[arg( name = "Ethereum RPC provider address", long = "rpc_url", @@ -203,13 +184,8 @@ pub struct GetUserBalanceArgs { #[derive(Parser, Debug)] #[command(version, about, long_about = None)] pub struct GetUserNonceArgs { - #[arg( - name = "The working network's name", - long = "network", - default_value = "devnet", - value_parser = value_parser!(Network) - )] - network: Network, + #[clap(flatten)] + network: NetworkArg, #[arg( name = "The user's Ethereum address", long = "user_addr", @@ -246,6 +222,87 @@ impl From for ProvingSystemId { } } +#[derive(Debug, Clone, Copy)] +enum NetworkNameArg { + Devnet, + Holesky, + HoleskyStage, + Mainnet, +} + +impl FromStr for NetworkNameArg { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "devnet" => Ok(NetworkNameArg::Devnet), + "holesky" => Ok(NetworkNameArg::Holesky), + "holesky-stage" => Ok(NetworkNameArg::HoleskyStage), + "mainnet" => Ok(NetworkNameArg::Mainnet), + _ => Err("Unknown network. Possible values: devnet, holesky, holesky-stage, mainnet".to_string()), + } + } +} + +#[derive(Debug, clap::Args, Clone)] +struct NetworkArg { + #[arg( + name = "The working network's name", + long = "network", + default_value = "devnet", + help = "[possible values: devnet, holesky, holesky-stage, mainnet]" + )] + network: Option, + #[arg( + name = "Aligned Service Manager Contract Address", + long = "aligned_service_manager", + conflicts_with("The working network's name"), + requires("Batcher Payment Service Contract Address"), + requires("Batcher URL"), + )] + aligned_service_manager_address: Option, + + #[arg( + name = "Batcher Payment Service Contract Address", + long = "batcher_payment_service", + conflicts_with("The working network's name"), + requires("Aligned Service Manager Contract Address"), + requires("Batcher URL"), + )] + batcher_payment_service_address: Option, + + #[arg( + name = "Batcher URL", + long = "batcher_url", + conflicts_with("The working network's name"), + requires("Aligned Service Manager Contract Address"), + requires("Batcher Payment Service Contract Address"), + )] + batcher_url: Option, +} + +impl From for Network { + fn from(network_arg: NetworkArg) -> Self { + let mut processed_network_argument = network_arg.clone(); + + if network_arg.batcher_url.is_some() || network_arg.aligned_service_manager_address.is_some() || network_arg.batcher_payment_service_address.is_some() { + processed_network_argument.network = None; // We need this because network is Devnet as default, which is not true for a Custom network + } + + match processed_network_argument.network { + None => Network::Custom( + network_arg.aligned_service_manager_address.unwrap(), + network_arg.batcher_payment_service_address.unwrap(), + network_arg.batcher_url.unwrap(), + ), + Some(NetworkNameArg::Devnet) => Network::Devnet, + Some(NetworkNameArg::Holesky) => Network::Holesky, + Some(NetworkNameArg::HoleskyStage) => Network::HoleskyStage, + Some(NetworkNameArg::Mainnet) => Network::Mainnet, + } + } +} + #[tokio::main] async fn main() -> Result<(), AlignedError> { env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); @@ -311,7 +368,7 @@ async fn main() -> Result<(), AlignedError> { let nonce = match &submit_args.nonce { Some(nonce) => U256::from_dec_str(nonce).map_err(|_| SubmitError::InvalidNonce)?, - None => get_nonce_from_batcher(submit_args.network, wallet.address()) + None => get_nonce_from_batcher(submit_args.network.clone().into(), wallet.address()) .await .map_err(|e| match e { aligned_sdk::core::errors::GetNonceError::EthRpcError(e) => { @@ -345,7 +402,7 @@ async fn main() -> Result<(), AlignedError> { info!("Submitting proofs to the Aligned batcher..."); let aligned_verification_data_vec = submit_multiple( - submit_args.network.clone(), + submit_args.network.into(), &verification_data_arr, max_fee_wei, wallet.clone(), @@ -404,7 +461,7 @@ async fn main() -> Result<(), AlignedError> { info!("Verifying response data matches sent proof data..."); let response = is_proof_verified( &aligned_verification_data, - verify_inclusion_args.network, + verify_inclusion_args.network.into(), &verify_inclusion_args.eth_rpc_url, ) .await?; @@ -469,7 +526,7 @@ async fn main() -> Result<(), AlignedError> { let client = SignerMiddleware::new(eth_rpc_provider.clone(), wallet.clone()); - match deposit_to_aligned(amount_wei, client, deposit_to_batcher_args.network).await { + match deposit_to_aligned(amount_wei, client, deposit_to_batcher_args.network.into()).await { Ok(receipt) => { info!( "Payment sent to the batcher successfully. Tx: 0x{:x}", @@ -486,7 +543,7 @@ async fn main() -> Result<(), AlignedError> { match get_balance_in_aligned( user_address, &get_user_balance_args.eth_rpc_url, - get_user_balance_args.network, + get_user_balance_args.network.into(), ) .await { @@ -505,7 +562,7 @@ async fn main() -> Result<(), AlignedError> { } GetUserNonce(args) => { let address = H160::from_str(&args.address).unwrap(); - match get_nonce_from_batcher(args.network, address).await { + match get_nonce_from_batcher(args.network.into(), address).await { Ok(nonce) => { info!("Nonce for address {} is {}", address, nonce); } diff --git a/docs/3_guides/9_aligned_cli.md b/docs/3_guides/9_aligned_cli.md index fb4cbaa43..d4f100308 100644 --- a/docs/3_guides/9_aligned_cli.md +++ b/docs/3_guides/9_aligned_cli.md @@ -71,9 +71,15 @@ Submit a proof to the Aligned Layer batcher. - Default: `0.0013ether` - `--nonce `: Proof nonce. - By default, the nonce is set automatically. By setting the nonce manually, you can perform a proof replacement. -- `--network `: Network name to interact with. - - Default: `devnet` - - Possible values: `devnet`, `holesky`, `mainnet` +- One of the following, to specify which Network to interact with: + - `--network `: Network name to interact with. + - Default: `devnet` + - Possible values: `devnet`, `holesky`, `mainnet` + - For a custom Network, you must specify the following parameters: + - `--aligned_service_manager ` + - `--batcher_payment_service ` + - `--batcher_url ` + #### Example: ```bash @@ -108,9 +114,14 @@ Check if a proof was verified by Aligned on Ethereum. - Mainnet: `https://ethereum-rpc.publicnode.com` - Holesky: `https://ethereum-holesky-rpc.publicnode.com` - Also, you can use your own Ethereum RPC providers. -- `--network `: Network name to interact with. - - Default: `devnet` - - Possible values: `devnet`, `holesky`, `mainnet` +- One of the following, to specify which Network to interact with: + - `--network `: Network name to interact with. + - Default: `devnet` + - Possible values: `devnet`, `holesky`, `mainnet` + - For a custom Network, you must specify the following parameters: + - `--aligned_service_manager ` + - `--batcher_payment_service ` + - `--batcher_url ` #### Example: ```bash @@ -157,10 +168,15 @@ Deposits Ethereum into the Aligned Layer's `BatcherPaymentService.sol` contract. - Mainnet: `https://ethereum-rpc.publicnode.com` - Holesky: `https://ethereum-holesky-rpc.publicnode.com` - Also, you can use your own Ethereum RPC providers. -- `--network `: Network name to interact with. - - Default: `devnet` - - Possible values: `devnet`, `holesky`, `mainnet` - `--amount `: Amount of Ether to deposit. +- One of the following, to specify which Network to interact with: + - `--network `: Network name to interact with. + - Default: `devnet` + - Possible values: `devnet`, `holesky`, `mainnet` + - For a custom Network, you must specify the following parameters: + - `--aligned_service_manager ` + - `--batcher_payment_service ` + - `--batcher_url ` #### Example: ```bash @@ -185,9 +201,14 @@ Retrieves the user's balance in the Aligned Layer's contract. #### Options: -- `--network `: Network name to interact with. - - Default: `devnet` - - Possible values: `devnet`, `holesky`, `mainnet` +- One of the following, to specify which Network to interact with: + - `--network `: Network name to interact with. + - Default: `devnet` + - Possible values: `devnet`, `holesky`, `mainnet` + - For a custom Network, you must specify the following parameters: + - `--aligned_service_manager ` + - `--batcher_payment_service ` + - `--batcher_url ` - `--rpc_url `: User's Ethereum RPC provider connection address. - Default: `http://localhost:8545` - Mainnet: `https://ethereum-rpc.publicnode.com` @@ -217,11 +238,13 @@ Retrieves the user's current nonce from the batcher. `get-user-nonce [OPTIONS] --user_addr ` #### Options: -- **`--batcher_url`**: Websocket URL for the Aligned Layer batcher. - - Default: `ws://localhost:8080` - - Mainnet: `wss://mainnet.batcher.alignedlayer.com` - - Holesky: `wss://batcher.alignedlayer.com` - `--user_addr `: User's Ethereum address. +- One of the following, to specify which Network to interact with: + - `--network `: Network name to interact with. + - Default: `devnet` + - Possible values: `devnet`, `holesky`, `mainnet` + - For a custom Network, you must specify the following parameter: + - `--batcher_url ` #### Example: ```bash From ec9685ddd402e7a4538b14d5c8c5c76e9040dea1 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Thu, 16 Jan 2025 14:45:49 -0300 Subject: [PATCH 27/45] chore: cargo fmt --- batcher/aligned-sdk/src/core/constants.rs | 5 +- batcher/aligned-sdk/src/core/types.rs | 5 +- batcher/aligned-sdk/src/sdk.rs | 28 +++------ batcher/aligned-task-sender/src/structs.rs | 2 +- batcher/aligned/src/main.rs | 72 ++++++++++++---------- 5 files changed, 55 insertions(+), 57 deletions(-) diff --git a/batcher/aligned-sdk/src/core/constants.rs b/batcher/aligned-sdk/src/core/constants.rs index 900800b83..7554d9624 100644 --- a/batcher/aligned-sdk/src/core/constants.rs +++ b/batcher/aligned-sdk/src/core/constants.rs @@ -53,10 +53,9 @@ pub const ALIGNED_SERVICE_MANAGER_DEVNET: &str = "0x851356ae760d987E095750cCeb3b pub const ALIGNED_SERVICE_MANAGER_HOLESKY: &str = "0x58F280BeBE9B34c9939C3C39e0890C81f163B623"; pub const ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE: &str = "0x9C5231FC88059C086Ea95712d105A2026048c39B"; -pub const ALIGNED_SERVICE_MANAGER_MAINNET: &str = - "0xeF2A435e5EE44B2041100EF8cbC8ae035166606c"; +pub const ALIGNED_SERVICE_MANAGER_MAINNET: &str = "0xeF2A435e5EE44B2041100EF8cbC8ae035166606c"; /// Batcher URL's pub const BATCHER_URL_DEVNET: &str = "ws://localhost:8080"; pub const BATCHER_URL_HOLESKY: &str = "wss://holesky.batcher.alignedlayer.com"; pub const BATCHER_URL_HOLESKY_STAGE: &str = "wss://stage.batcher.alignedlayer.com"; -pub const BATCHER_URL_MAINNET: &str = "wss://batcher.alignedlayer.com"; \ No newline at end of file +pub const BATCHER_URL_MAINNET: &str = "wss://batcher.alignedlayer.com"; diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index 596cd9bc1..2acf6a681 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -21,7 +21,7 @@ use sha3::{Digest, Keccak256}; use super::constants::{ ALIGNED_SERVICE_MANAGER_DEVNET, ALIGNED_SERVICE_MANAGER_HOLESKY, - ALIGNED_SERVICE_MANAGER_MAINNET, ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE, + ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE, ALIGNED_SERVICE_MANAGER_MAINNET, BATCHER_PAYMENT_SERVICE_ADDRESS_DEVNET, BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY, BATCHER_PAYMENT_SERVICE_ADDRESS_HOLESKY_STAGE, BATCHER_PAYMENT_SERVICE_ADDRESS_MAINNET, BATCHER_URL_DEVNET, BATCHER_URL_HOLESKY, BATCHER_URL_HOLESKY_STAGE, BATCHER_URL_MAINNET, @@ -423,7 +423,7 @@ impl Network { Self::Custom(s, _, _) => H160::from_str(s.as_str()).unwrap(), } } - + pub fn get_batcher_payment_service_address(&self) -> ethers::types::H160 { match self { Self::Devnet => H160::from_str(BATCHER_PAYMENT_SERVICE_ADDRESS_DEVNET).unwrap(), @@ -447,7 +447,6 @@ impl Network { } } - #[cfg(test)] mod tests { use ethers::signers::LocalWallet; diff --git a/batcher/aligned-sdk/src/sdk.rs b/batcher/aligned-sdk/src/sdk.rs index 7bdd13458..910ad4ac0 100644 --- a/batcher/aligned-sdk/src/sdk.rs +++ b/batcher/aligned-sdk/src/sdk.rs @@ -85,14 +85,8 @@ pub async fn submit_multiple_and_wait_verification( wallet: Wallet, nonce: U256, ) -> Vec> { - let mut aligned_verification_data = submit_multiple( - network.clone(), - verification_data, - max_fee, - wallet, - nonce, - ) - .await; + let mut aligned_verification_data = + submit_multiple(network.clone(), verification_data, max_fee, wallet, nonce).await; // TODO: open issue: use a join to .await all at the same time, avoiding the loop // And await only once per batch, no need to await multiple proofs if they are in the same batch. @@ -418,14 +412,8 @@ pub async fn submit( ) -> Result { let verification_data = vec![verification_data.clone()]; - let aligned_verification_data = submit_multiple( - network, - &verification_data, - max_fee, - wallet, - nonce, - ) - .await; + let aligned_verification_data = + submit_multiple(network, &verification_data, max_fee, wallet, nonce).await; match aligned_verification_data.first() { Some(Ok(aligned_verification_data)) => Ok(aligned_verification_data.clone()), @@ -536,9 +524,11 @@ pub async fn get_nonce_from_batcher( network: Network, address: Address, ) -> Result { - let (ws_stream, _) = connect_async(network.get_batcher_url()).await.map_err(|_| { - GetNonceError::ConnectionFailed("Ws connection to batcher failed".to_string()) - })?; + let (ws_stream, _) = connect_async(network.get_batcher_url()) + .await + .map_err(|_| { + GetNonceError::ConnectionFailed("Ws connection to batcher failed".to_string()) + })?; debug!("WebSocket handshake has been successfully completed"); let (mut ws_write, mut ws_read) = ws_stream.split(); diff --git a/batcher/aligned-task-sender/src/structs.rs b/batcher/aligned-task-sender/src/structs.rs index 3456047a4..c42b29368 100644 --- a/batcher/aligned-task-sender/src/structs.rs +++ b/batcher/aligned-task-sender/src/structs.rs @@ -152,4 +152,4 @@ pub struct SendInfiniteProofsArgs { default_value = "devnet" )] pub proofs_dir: String, -} \ No newline at end of file +} diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 4da2d544b..b058ade14 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -235,14 +235,17 @@ enum NetworkNameArg { impl FromStr for NetworkNameArg { type Err = String; - + fn from_str(s: &str) -> Result { match s { "devnet" => Ok(NetworkNameArg::Devnet), "holesky" => Ok(NetworkNameArg::Holesky), "holesky-stage" => Ok(NetworkNameArg::HoleskyStage), "mainnet" => Ok(NetworkNameArg::Mainnet), - _ => Err("Unknown network. Possible values: devnet, holesky, holesky-stage, mainnet".to_string()), + _ => Err( + "Unknown network. Possible values: devnet, holesky, holesky-stage, mainnet" + .to_string(), + ), } } } @@ -261,7 +264,7 @@ struct NetworkArg { long = "aligned_service_manager", conflicts_with("The working network's name"), requires("Batcher Payment Service Contract Address"), - requires("Batcher URL"), + requires("Batcher URL") )] aligned_service_manager_address: Option, @@ -270,7 +273,7 @@ struct NetworkArg { long = "batcher_payment_service", conflicts_with("The working network's name"), requires("Aligned Service Manager Contract Address"), - requires("Batcher URL"), + requires("Batcher URL") )] batcher_payment_service_address: Option, @@ -279,7 +282,7 @@ struct NetworkArg { long = "batcher_url", conflicts_with("The working network's name"), requires("Aligned Service Manager Contract Address"), - requires("Batcher Payment Service Contract Address"), + requires("Batcher Payment Service Contract Address") )] batcher_url: Option, } @@ -288,7 +291,10 @@ impl From for Network { fn from(network_arg: NetworkArg) -> Self { let mut processed_network_argument = network_arg.clone(); - if network_arg.batcher_url.is_some() || network_arg.aligned_service_manager_address.is_some() || network_arg.batcher_payment_service_address.is_some() { + if network_arg.batcher_url.is_some() + || network_arg.aligned_service_manager_address.is_some() + || network_arg.batcher_payment_service_address.is_some() + { processed_network_argument.network = None; // We need this because network is Devnet as default, which is not true for a Custom network } @@ -302,7 +308,7 @@ impl From for Network { Some(NetworkNameArg::Holesky) => Network::Holesky, Some(NetworkNameArg::HoleskyStage) => Network::HoleskyStage, Some(NetworkNameArg::Mainnet) => Network::Mainnet, - } + } } } @@ -366,29 +372,31 @@ async fn main() -> Result<(), AlignedError> { let nonce = match &submit_args.nonce { Some(nonce) => U256::from_dec_str(nonce).map_err(|_| SubmitError::InvalidNonce)?, - None => get_nonce_from_batcher(submit_args.network.clone().into(), wallet.address()) - .await - .map_err(|e| match e { - aligned_sdk::core::errors::GetNonceError::EthRpcError(e) => { - SubmitError::GetNonceError(e) - } - aligned_sdk::core::errors::GetNonceError::ConnectionFailed(e) => { - SubmitError::GenericError(e) - } - aligned_sdk::core::errors::GetNonceError::InvalidRequest(e) => { - SubmitError::GenericError(e) - } - aligned_sdk::core::errors::GetNonceError::SerializationError(e) => { - SubmitError::GenericError(e) - } - aligned_sdk::core::errors::GetNonceError::ProtocolMismatch { - current, - expected, - } => SubmitError::ProtocolVersionMismatch { current, expected }, - aligned_sdk::core::errors::GetNonceError::UnexpectedResponse(e) => { - SubmitError::UnexpectedBatcherResponse(e) - } - })?, + None => { + get_nonce_from_batcher(submit_args.network.clone().into(), wallet.address()) + .await + .map_err(|e| match e { + aligned_sdk::core::errors::GetNonceError::EthRpcError(e) => { + SubmitError::GetNonceError(e) + } + aligned_sdk::core::errors::GetNonceError::ConnectionFailed(e) => { + SubmitError::GenericError(e) + } + aligned_sdk::core::errors::GetNonceError::InvalidRequest(e) => { + SubmitError::GenericError(e) + } + aligned_sdk::core::errors::GetNonceError::SerializationError(e) => { + SubmitError::GenericError(e) + } + aligned_sdk::core::errors::GetNonceError::ProtocolMismatch { + current, + expected, + } => SubmitError::ProtocolVersionMismatch { current, expected }, + aligned_sdk::core::errors::GetNonceError::UnexpectedResponse(e) => { + SubmitError::UnexpectedBatcherResponse(e) + } + })? + } }; warn!("Nonce: {nonce}"); @@ -529,7 +537,9 @@ async fn main() -> Result<(), AlignedError> { let client = SignerMiddleware::new(eth_rpc_provider.clone(), wallet.clone()); - match deposit_to_aligned(amount_wei, client, deposit_to_batcher_args.network.into()).await { + match deposit_to_aligned(amount_wei, client, deposit_to_batcher_args.network.into()) + .await + { Ok(receipt) => { info!( "Payment sent to the batcher successfully. Tx: 0x{:x}", From 9da8dcc1a45ff86b14d44fa624c41b427b2da555 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:28:06 -0300 Subject: [PATCH 28/45] feat: migrate rust task sender --- Makefile | 13 +-- batcher/aligned-task-sender/src/commands.rs | 27 +++-- batcher/aligned-task-sender/src/structs.rs | 121 +++++++++++++++----- 3 files changed, 114 insertions(+), 47 deletions(-) diff --git a/Makefile b/Makefile index c102b55cf..b1f6abfb7 100644 --- a/Makefile +++ b/Makefile @@ -504,7 +504,6 @@ task_sender_send_infinite_proofs_devnet: cargo run --release -- send-infinite-proofs \ --burst-size $(BURST_SIZE) --burst-time-secs $(BURST_TIME_SECS) \ --eth-rpc-url http://localhost:8545 \ - --batcher-url ws://localhost:8080 \ --network devnet \ --proofs-dirpath $(CURDIR)/scripts/test_files/task_sender/proofs \ --private-keys-filepath $(CURDIR)/batcher/aligned-task-sender/wallets/devnet @@ -512,8 +511,8 @@ task_sender_send_infinite_proofs_devnet: task_sender_test_connections_devnet: @cd batcher/aligned-task-sender && \ cargo run --release -- test-connections \ - --batcher-url ws://localhost:8080 \ - --num-senders $(NUM_SENDERS) + --num-senders $(NUM_SENDERS) \ + --network devnet # ===== HOLESKY-STAGE ===== task_sender_generate_and_fund_wallets_holesky_stage: @@ -532,7 +531,6 @@ task_sender_send_infinite_proofs_holesky_stage: cargo run --release -- send-infinite-proofs \ --burst-size $(BURST_SIZE) --burst-time-secs $(BURST_TIME_SECS) \ --eth-rpc-url https://ethereum-holesky-rpc.publicnode.com \ - --batcher-url wss://stage.batcher.alignedlayer.com \ --network holesky-stage \ --proofs-dirpath $(CURDIR)/scripts/test_files/task_sender/proofs \ --private-keys-filepath $(CURDIR)/batcher/aligned-task-sender/wallets/holesky-stage @@ -540,13 +538,14 @@ task_sender_send_infinite_proofs_holesky_stage: task_sender_test_connections_holesky_stage: @cd batcher/aligned-task-sender && \ cargo run --release -- test-connections \ - --batcher-url wss://stage.batcher.alignedlayer.com \ - --num-senders $(NUM_SENDERS) + --num-senders $(NUM_SENDERS) \ + --network holesky-stage __UTILS__: aligned_get_user_balance_devnet: @cd batcher/aligned/ && cargo run --release -- get-user-balance \ - --user_addr $(USER_ADDR) + --user_addr $(USER_ADDR) \ + --network devnet aligned_get_user_balance_holesky: @cd batcher/aligned/ && cargo run --release -- get-user-balance \ diff --git a/batcher/aligned-task-sender/src/commands.rs b/batcher/aligned-task-sender/src/commands.rs index 395b57dfa..82c45c6b9 100644 --- a/batcher/aligned-task-sender/src/commands.rs +++ b/batcher/aligned-task-sender/src/commands.rs @@ -63,7 +63,7 @@ pub async fn generate_proofs(args: GenerateProofsArgs) { } pub async fn generate_and_fund_wallets(args: GenerateAndFundWalletsArgs) { - if matches!(args.network.into(), Network::Devnet) { + if matches!(args.network.clone().into(), Network::Devnet) { let Ok(eth_rpc_provider) = Provider::::try_from(args.eth_rpc_url.clone()) else { error!("Could not connect to eth rpc"); return; @@ -96,11 +96,12 @@ pub async fn generate_and_fund_wallets(args: GenerateAndFundWalletsArgs) { let funded_wallet_signer = SignerMiddleware::new(eth_rpc_provider.clone(), wallet.clone()); tokio::time::sleep(Duration::from_millis(50)).await; // To avoid overloading the RPC + let network = args.network.clone(); let handle = tokio::spawn(async move { if let Err(err) = deposit_to_aligned( amount_to_deposit_to_aligned, funded_wallet_signer.clone(), - args.network.into(), + network.into(), ) .await { @@ -188,7 +189,7 @@ pub async fn generate_and_fund_wallets(args: GenerateAndFundWalletsArgs) { ); let signer = SignerMiddleware::new(eth_rpc_provider.clone(), wallet.clone()); if let Err(err) = - deposit_to_aligned(amount_to_deposit_to_aligned, signer, args.network.clone()).await + deposit_to_aligned(amount_to_deposit_to_aligned, signer, args.network.clone().into()).await { error!("Could not deposit to aligned, err: {:?}", err); return; @@ -212,10 +213,11 @@ pub async fn generate_and_fund_wallets(args: GenerateAndFundWalletsArgs) { pub async fn test_connection(args: TestConnectionsArgs) { info!("Going to only open a connection"); let mut handlers = vec![]; - let network = network.clone(); + let network: Network = args.network.into(); + let ws_url_string = network.get_batcher_url().to_string(); for i in 0..args.num_senders { - let ws_url = network.get_batcher_url().clone(); + let ws_url = ws_url_string.clone(); let handle = tokio::spawn(async move { let conn = connect_async(ws_url).await; if let Ok((mut ws_stream, _)) = conn { @@ -246,7 +248,7 @@ struct Sender { } pub async fn send_infinite_proofs(args: SendInfiniteProofsArgs) { - if matches!(args.network.into(), Network::Holesky) { + if matches!(args.network.clone().into(), Network::Holesky) { error!("Network not supported this infinite proof sender"); return; } @@ -310,18 +312,20 @@ pub async fn send_infinite_proofs(args: SendInfiniteProofsArgs) { let max_fee = U256::from_dec_str(&args.max_fee).expect("Invalid max fee"); let mut handles = vec![]; + let network: Network = args.network.into(); info!("Starting senders!"); for (i, sender) in senders.iter().enumerate() { - // this is necessary because of the move - let batcher_url = args.batcher_url.clone(); let wallet = sender.wallet.clone(); let verification_data = verification_data.clone(); + // this is necessary because of the move + let network_clone = network.clone(); // a thread to send tasks from each loaded wallet: let handle = tokio::spawn(async move { loop { + let n = network_clone.clone(); let mut result = Vec::with_capacity(args.burst_size); - let nonce = get_nonce_from_batcher(&batcher_url, wallet.address()) + let nonce = get_nonce_from_batcher(n.clone(), wallet.address()) .await .inspect_err(|e| { error!( @@ -340,12 +344,11 @@ pub async fn send_infinite_proofs(args: SendInfiniteProofsArgs) { info!( "Sending {:?} Proofs to Aligned Batcher on {:?} from sender {}, nonce: {}, address: {:?}", - args.burst_size, args.network, i, nonce, wallet.address(), + args.burst_size, n.clone(), i, nonce, wallet.address(), ); - let batcher_url = batcher_url.clone(); let aligned_verification_data = submit_multiple( - args.network.into(), + n.clone().into(), &verification_data_to_send.clone(), max_fee, wallet.clone(), diff --git a/batcher/aligned-task-sender/src/structs.rs b/batcher/aligned-task-sender/src/structs.rs index c42b29368..f5f5db1d5 100644 --- a/batcher/aligned-task-sender/src/structs.rs +++ b/batcher/aligned-task-sender/src/structs.rs @@ -1,8 +1,8 @@ use aligned_sdk::core::types::Network; -use clap::value_parser; use clap::Parser; use clap::Subcommand; use clap::ValueEnum; +use std::str::FromStr; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] @@ -78,25 +78,15 @@ pub struct GenerateAndFundWalletsArgs { long = "private-keys-filepath" )] pub private_keys_filepath: String, - #[arg( - name = "The working network's name", - long = "network", - default_value = "devnet", - value_parser = value_parser!(Network) - )] - pub network: Network, + #[clap(flatten)] + pub network: NetworkArg, } #[derive(Parser, Debug)] #[command(version, about, long_about = None)] pub struct TestConnectionsArgs { - #[arg( - name = "The working network's name", - long = "network", - default_value = "devnet", - value_parser = value_parser!(Network) - )] - pub network: Network, + #[clap(flatten)] + pub network: NetworkArg, #[arg( name = "Number of spawned sockets", long = "num-senders", @@ -114,12 +104,6 @@ pub struct SendInfiniteProofsArgs { default_value = "http://localhost:8545" )] pub eth_rpc_url: String, - #[arg( - name = "Batcher connection address", - long = "batcher-url", - default_value = "ws://localhost:8080" - )] - pub batcher_url: String, #[arg( name = "Number of proofs per burst", long = "burst-size", @@ -134,13 +118,8 @@ pub struct SendInfiniteProofsArgs { pub burst_time_secs: u64, #[arg(name = "Max Fee", long = "max-fee", default_value = "1300000000000000")] pub max_fee: String, - #[arg( - name = "The working network's name", - long = "network", - default_value = "devnet", - value_parser = value_parser!(Network) - )] - pub network: Network, + #[clap(flatten)] + pub network: NetworkArg, #[arg( name = "Private keys filepath for the senders", long = "private-keys-filepath" @@ -153,3 +132,89 @@ pub struct SendInfiniteProofsArgs { )] pub proofs_dir: String, } + + +#[derive(Debug, Clone, Copy)] +enum NetworkNameArg { + Devnet, + Holesky, + HoleskyStage, + Mainnet, +} + +impl FromStr for NetworkNameArg { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "devnet" => Ok(NetworkNameArg::Devnet), + "holesky" => Ok(NetworkNameArg::Holesky), + "holesky-stage" => Ok(NetworkNameArg::HoleskyStage), + "mainnet" => Ok(NetworkNameArg::Mainnet), + _ => Err( + "Unknown network. Possible values: devnet, holesky, holesky-stage, mainnet" + .to_string(), + ), + } + } +} + +#[derive(Debug, clap::Args, Clone)] +pub struct NetworkArg { + #[arg( + name = "The working network's name", + long = "network", + default_value = "devnet", + help = "[possible values: devnet, holesky, holesky-stage, mainnet]" + )] + network: Option, + #[arg( + name = "Aligned Service Manager Contract Address", + long = "aligned_service_manager", + conflicts_with("The working network's name"), + requires("Batcher Payment Service Contract Address"), + requires("Batcher URL") + )] + aligned_service_manager_address: Option, + #[arg( + name = "Batcher Payment Service Contract Address", + long = "batcher_payment_service", + conflicts_with("The working network's name"), + requires("Aligned Service Manager Contract Address"), + requires("Batcher URL") + )] + batcher_payment_service_address: Option, + #[arg( + name = "Batcher URL", + long = "batcher_url", + conflicts_with("The working network's name"), + requires("Aligned Service Manager Contract Address"), + requires("Batcher Payment Service Contract Address") + )] + batcher_url: Option, +} + +impl From for Network { + fn from(network_arg: NetworkArg) -> Self { + let mut processed_network_argument = network_arg.clone(); + + if network_arg.batcher_url.is_some() + || network_arg.aligned_service_manager_address.is_some() + || network_arg.batcher_payment_service_address.is_some() + { + processed_network_argument.network = None; // We need this because network is Devnet as default, which is not true for a Custom network + } + + match processed_network_argument.network { + None => Network::Custom( + network_arg.aligned_service_manager_address.unwrap(), + network_arg.batcher_payment_service_address.unwrap(), + network_arg.batcher_url.unwrap(), + ), + Some(NetworkNameArg::Devnet) => Network::Devnet, + Some(NetworkNameArg::Holesky) => Network::Holesky, + Some(NetworkNameArg::HoleskyStage) => Network::HoleskyStage, + Some(NetworkNameArg::Mainnet) => Network::Mainnet, + } + } +} From 5873fa41e7317fb48d080c258d1dfa63f4e767d1 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:29:40 -0300 Subject: [PATCH 29/45] chore: docs --- batcher/aligned-task-sender/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batcher/aligned-task-sender/README.md b/batcher/aligned-task-sender/README.md index fdf49195d..c73d454b1 100644 --- a/batcher/aligned-task-sender/README.md +++ b/batcher/aligned-task-sender/README.md @@ -61,7 +61,7 @@ To run it, you can: cargo run --release -- send-infinite-proofs \ --burst-size --burst-time-secs \ --eth-rpc-url \ - --network holesky-stage \ + --network \ --proofs-dirpath $(PWD)/scripts/test_files/task_sender/proofs \ --private-keys-filepath ``` From ceafba515440e3f0fda8e8d045ed8744b81c0484 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:31:24 -0300 Subject: [PATCH 30/45] chore: cargo fmt --- batcher/aligned-task-sender/src/commands.rs | 8 ++++++-- batcher/aligned-task-sender/src/structs.rs | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/batcher/aligned-task-sender/src/commands.rs b/batcher/aligned-task-sender/src/commands.rs index 82c45c6b9..dadcd9d75 100644 --- a/batcher/aligned-task-sender/src/commands.rs +++ b/batcher/aligned-task-sender/src/commands.rs @@ -188,8 +188,12 @@ pub async fn generate_and_fund_wallets(args: GenerateAndFundWalletsArgs) { amount_to_deposit_to_aligned, i ); let signer = SignerMiddleware::new(eth_rpc_provider.clone(), wallet.clone()); - if let Err(err) = - deposit_to_aligned(amount_to_deposit_to_aligned, signer, args.network.clone().into()).await + if let Err(err) = deposit_to_aligned( + amount_to_deposit_to_aligned, + signer, + args.network.clone().into(), + ) + .await { error!("Could not deposit to aligned, err: {:?}", err); return; diff --git a/batcher/aligned-task-sender/src/structs.rs b/batcher/aligned-task-sender/src/structs.rs index f5f5db1d5..fdeba460d 100644 --- a/batcher/aligned-task-sender/src/structs.rs +++ b/batcher/aligned-task-sender/src/structs.rs @@ -133,7 +133,6 @@ pub struct SendInfiniteProofsArgs { pub proofs_dir: String, } - #[derive(Debug, Clone, Copy)] enum NetworkNameArg { Devnet, From ab8708670084ed9b1d80f125ca99271708aa2f92 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:37:57 -0300 Subject: [PATCH 31/45] chore: cargo clippy --- batcher/aligned-task-sender/src/commands.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batcher/aligned-task-sender/src/commands.rs b/batcher/aligned-task-sender/src/commands.rs index dadcd9d75..6a163c191 100644 --- a/batcher/aligned-task-sender/src/commands.rs +++ b/batcher/aligned-task-sender/src/commands.rs @@ -352,7 +352,7 @@ pub async fn send_infinite_proofs(args: SendInfiniteProofsArgs) { ); let aligned_verification_data = submit_multiple( - n.clone().into(), + n.clone(), &verification_data_to_send.clone(), max_fee, wallet.clone(), From 0e6c0a6bbe6225c05bac8fa68efb2ed2ad1cf7c3 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:16:30 -0300 Subject: [PATCH 32/45] chore: docs --- batcher/aligned/src/main.rs | 10 +++--- docs/3_guides/9_aligned_cli.md | 56 +++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 4aea9e069..496afc663 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -33,7 +33,7 @@ use crate::AlignedCommands::DepositToBatcher; use crate::AlignedCommands::GetUserBalance; use crate::AlignedCommands::GetUserNonce; use crate::AlignedCommands::GetUserNonceFromEthereum; -use crate::AlignedCommands::GetUserNumberOfQueuedProofs; +use crate::AlignedCommands::GetUserAmountOfQueuedProofs; use crate::AlignedCommands::GetVkCommitment; use crate::AlignedCommands::Submit; use crate::AlignedCommands::VerifyProofOnchain; @@ -73,9 +73,9 @@ pub enum AlignedCommands { GetUserNonceFromEthereum(GetUserNonceFromEthereumArgs), #[clap( about = "Gets the number of proofs a user has queued in the Batcher.", - name = "get-user-number-of-queued-proofs" + name = "get-user-amount-of-queued-proofs" )] - GetUserNumberOfQueuedProofs(GetUserNumberOfQueuedProofsArgs), + GetUserAmountOfQueuedProofs(GetUserAmountOfQueuedProofsArgs), } #[derive(Parser, Debug)] @@ -255,7 +255,7 @@ pub struct GetUserNonceFromEthereumArgs { #[derive(Parser, Debug)] #[command(version, about, long_about = None)] -pub struct GetUserNumberOfQueuedProofsArgs { +pub struct GetUserAmountOfQueuedProofsArgs { #[arg( name = "Ethereum RPC provider address", long = "rpc_url", @@ -627,7 +627,7 @@ async fn main() -> Result<(), AlignedError> { } } } - GetUserNumberOfQueuedProofs(args) => { + GetUserAmountOfQueuedProofs(args) => { let address = H160::from_str(&args.address).unwrap(); let network = args.network.into(); let Ok((ethereum_nonce, batcher_nonce)) = future::try_join( diff --git a/docs/3_guides/9_aligned_cli.md b/docs/3_guides/9_aligned_cli.md index da3bd2a50..aa71318cc 100644 --- a/docs/3_guides/9_aligned_cli.md +++ b/docs/3_guides/9_aligned_cli.md @@ -194,7 +194,7 @@ Retrieves the user's balance in the Aligned Layer's contract. - Mainnet: `https://ethereum-rpc.publicnode.com` - Holesky: `https://ethereum-holesky-rpc.publicnode.com` - Also, you can use your own Ethereum RPC providers. -- **`--user_addr`**: User's Ethereum address. +- `--user_addr`: User's Ethereum address. #### Example: ```bash @@ -206,27 +206,67 @@ aligned get-user-balance \ --- -### **get-user-nonce** +### **get-user-nonce-from-ethereum** #### Description: -Retrieves the user's current nonce from the batcher. +Retrieves the user's current nonce from the Blockhain, in the Batcher Payment Service Contract. #### Command: -`get-user-nonce [OPTIONS] --user_addr ` +`get-user-nonce-from-ethereum [OPTIONS] --user_addr ` #### Options: -- **`--batcher_url`**: Websocket URL for the Aligned Layer batcher. - - Default: `ws://localhost:8080` +- `--user_addr `: User's Ethereum address. +- `--network `: Network name to interact with. + - Default: `devnet` + - Possible values: `devnet`, `holesky`, `mainnet` +- `--rpc_url `: User's Ethereum RPC provider connection address. + - Default: `http://localhost:8545` + - Mainnet: `https://ethereum-rpc.publicnode.com` + - Holesky: `https://ethereum-holesky-rpc.publicnode.com` + - Also, you can use your own Ethereum RPC providers. + +#### Example: +```bash +aligned get-user-nonce-from-ethereum \ +--user_addr \ +--network holesky \ +--rpc_url https://ethereum-holesky-rpc.publicnode.com +``` + +--- + +### **get-user-amount-of-queued-proofs** + +#### Description: + +Retrieves the user's amount of queued proofs in the Batcher. + +#### Command: + +`get-user-amount-of-queued-proofs [OPTIONS] --user_addr ` + +#### Options: +- `--user_addr `: User's Ethereum address. +- `--network `: Network name to interact with. + - Default: `devnet` + - Possible values: `devnet`, `holesky`, `mainnet` +- `--rpc_url `: User's Ethereum RPC provider connection address. + - Default: `http://localhost:8545` + - Mainnet: `https://ethereum-rpc.publicnode.com` + - Holesky: `https://ethereum-holesky-rpc.publicnode.com` + - Also, you can use your own Ethereum RPC providers. +- `--batcher_url `: Websocket URL for the Aligned Layer batcher + - Default: `ws://localhost:8080` - Mainnet: `wss://mainnet.batcher.alignedlayer.com` - Holesky: `wss://batcher.alignedlayer.com` -- `--user_addr `: User's Ethereum address. #### Example: ```bash -aligned get-user-nonce \ +aligned get-user-amount-of-queued-proofs \ --user_addr \ +--network holesky \ --batcher_url wss://batcher.alignedlayer.com ``` From 10fedc62aaef38fccea2a8f3fe6cdad5fc020081 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:17:26 -0300 Subject: [PATCH 33/45] chore: cargo fmt --- batcher/aligned/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 496afc663..a41991879 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -30,10 +30,10 @@ use log::{error, info}; use transaction::eip2718::TypedTransaction; use crate::AlignedCommands::DepositToBatcher; +use crate::AlignedCommands::GetUserAmountOfQueuedProofs; use crate::AlignedCommands::GetUserBalance; use crate::AlignedCommands::GetUserNonce; use crate::AlignedCommands::GetUserNonceFromEthereum; -use crate::AlignedCommands::GetUserAmountOfQueuedProofs; use crate::AlignedCommands::GetVkCommitment; use crate::AlignedCommands::Submit; use crate::AlignedCommands::VerifyProofOnchain; From 51f576ade08ae99343e2c72218b376771f45b03b Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Fri, 17 Jan 2025 12:56:02 -0300 Subject: [PATCH 34/45] chore: add error failure on CI --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index b1f6abfb7..4afa46c0c 100644 --- a/Makefile +++ b/Makefile @@ -1065,6 +1065,7 @@ docker_verify_proof_submission_success: --rpc_url $$(echo $(DOCKER_RPC_URL)) 2>&1); \ if echo "$$verification" | grep -q not; then \ echo "ERROR: Proof verification failed for $${proof}"; \ + echo "With error: $$verification"; \ exit 1; \ elif echo "$$verification" | grep -q verified; then \ echo "Proof verification succeeded for $${proof}"; \ From 79a3b8a37570a1f7ae7b9a18879c0758854eff8c Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Fri, 17 Jan 2025 13:07:01 -0300 Subject: [PATCH 35/45] chore: fix comment --- batcher/aligned-batcher/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batcher/aligned-batcher/src/lib.rs b/batcher/aligned-batcher/src/lib.rs index 420b435e1..304e68dff 100644 --- a/batcher/aligned-batcher/src/lib.rs +++ b/batcher/aligned-batcher/src/lib.rs @@ -1516,7 +1516,7 @@ impl Batcher { } Err(e) => { error!( - "Failed to send batch to contract, batch will be lost: {:?}", + "Failed to send batch to contract: {:?}", e ); From d7dc1c1aa12fca0b9621055717eb08a99772949f Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:21:44 -0300 Subject: [PATCH 36/45] fix: debugging error in CI --- Makefile | 4 +++- batcher/aligned-sdk/src/sdk.rs | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4afa46c0c..bac5a4afb 100644 --- a/Makefile +++ b/Makefile @@ -1060,12 +1060,14 @@ docker_verify_proof_submission_success: sleep $(DOCKER_PROOFS_WAIT_TIME); \ for proof in ./aligned_verification_data/*.cbor; do \ echo "Verifying proof $${proof} \n"; \ + cat $${proof}; verification=$$(aligned verify-proof-onchain \ --aligned-verification-data $${proof} \ --rpc_url $$(echo $(DOCKER_RPC_URL)) 2>&1); \ if echo "$$verification" | grep -q not; then \ echo "ERROR: Proof verification failed for $${proof}"; \ - echo "With error: $$verification"; \ + echo "With error:"; \ + echo "$$verification"; \ exit 1; \ elif echo "$$verification" | grep -q verified; then \ echo "Proof verification succeeded for $${proof}"; \ diff --git a/batcher/aligned-sdk/src/sdk.rs b/batcher/aligned-sdk/src/sdk.rs index 910ad4ac0..0ac06024b 100644 --- a/batcher/aligned-sdk/src/sdk.rs +++ b/batcher/aligned-sdk/src/sdk.rs @@ -457,6 +457,9 @@ async fn _is_proof_verified( let contract_address = network.clone().get_aligned_service_manager_address(); let payment_service_addr = network.get_batcher_payment_service_address(); + info!("contract_address: {}", contract_address); + info!("payment_service_addr: {}", payment_service_addr); + // All the elements from the merkle proof have to be concatenated let merkle_proof: Vec = aligned_verification_data .batch_inclusion_proof From ce35d416b074175ac85174492c1cc82485467c3c Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Fri, 17 Jan 2025 15:05:23 -0300 Subject: [PATCH 37/45] fix(wip): print .json contents --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index bac5a4afb..fe1a004a9 100644 --- a/Makefile +++ b/Makefile @@ -1061,6 +1061,7 @@ docker_verify_proof_submission_success: for proof in ./aligned_verification_data/*.cbor; do \ echo "Verifying proof $${proof} \n"; \ cat $${proof}; + cat $${proof%.cbor}.json verification=$$(aligned verify-proof-onchain \ --aligned-verification-data $${proof} \ --rpc_url $$(echo $(DOCKER_RPC_URL)) 2>&1); \ From f05869ed6fdb216e46fb3071b55efa8c7a593f79 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Fri, 17 Jan 2025 15:06:15 -0300 Subject: [PATCH 38/45] fix: prints --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fe1a004a9..a3218fa00 100644 --- a/Makefile +++ b/Makefile @@ -1060,8 +1060,8 @@ docker_verify_proof_submission_success: sleep $(DOCKER_PROOFS_WAIT_TIME); \ for proof in ./aligned_verification_data/*.cbor; do \ echo "Verifying proof $${proof} \n"; \ - cat $${proof}; - cat $${proof%.cbor}.json + cat $${proof}; \ + cat $${proof%.cbor}.json; \ verification=$$(aligned verify-proof-onchain \ --aligned-verification-data $${proof} \ --rpc_url $$(echo $(DOCKER_RPC_URL)) 2>&1); \ From 1c3b24527c3b5a3aefb1f1ff4e52d9b11230dd1e Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Fri, 17 Jan 2025 16:27:57 -0300 Subject: [PATCH 39/45] fix: revert CI changes, they are in another pr --- Makefile | 4 ---- batcher/aligned-sdk/src/sdk.rs | 3 --- 2 files changed, 7 deletions(-) diff --git a/Makefile b/Makefile index a3218fa00..b1f6abfb7 100644 --- a/Makefile +++ b/Makefile @@ -1060,15 +1060,11 @@ docker_verify_proof_submission_success: sleep $(DOCKER_PROOFS_WAIT_TIME); \ for proof in ./aligned_verification_data/*.cbor; do \ echo "Verifying proof $${proof} \n"; \ - cat $${proof}; \ - cat $${proof%.cbor}.json; \ verification=$$(aligned verify-proof-onchain \ --aligned-verification-data $${proof} \ --rpc_url $$(echo $(DOCKER_RPC_URL)) 2>&1); \ if echo "$$verification" | grep -q not; then \ echo "ERROR: Proof verification failed for $${proof}"; \ - echo "With error:"; \ - echo "$$verification"; \ exit 1; \ elif echo "$$verification" | grep -q verified; then \ echo "Proof verification succeeded for $${proof}"; \ diff --git a/batcher/aligned-sdk/src/sdk.rs b/batcher/aligned-sdk/src/sdk.rs index 0ac06024b..910ad4ac0 100644 --- a/batcher/aligned-sdk/src/sdk.rs +++ b/batcher/aligned-sdk/src/sdk.rs @@ -457,9 +457,6 @@ async fn _is_proof_verified( let contract_address = network.clone().get_aligned_service_manager_address(); let payment_service_addr = network.get_batcher_payment_service_address(); - info!("contract_address: {}", contract_address); - info!("payment_service_addr: {}", payment_service_addr); - // All the elements from the merkle proof have to be concatenated let merkle_proof: Vec = aligned_verification_data .batch_inclusion_proof From 5d32849279ec3f7fa5eba4b9afd2292617f084e7 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Fri, 17 Jan 2025 17:26:56 -0300 Subject: [PATCH 40/45] fix: docs --- docs/3_guides/9_aligned_cli.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/3_guides/9_aligned_cli.md b/docs/3_guides/9_aligned_cli.md index 30bbaa0b7..42bcbb7af 100644 --- a/docs/3_guides/9_aligned_cli.md +++ b/docs/3_guides/9_aligned_cli.md @@ -244,7 +244,9 @@ Retrieves the user's current nonce from the batcher. - `--network `: Network name to interact with. - Default: `devnet` - Possible values: `devnet`, `holesky`, `mainnet` - - For a custom Network, you must specify the following parameter: + - For a custom Network, you must specify the following parameters: + - `--aligned_service_manager ` + - `--batcher_payment_service ` - `--batcher_url ` #### Example: From 544723738158e3d5ba5fad72304eb64c3ff3c657 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Fri, 17 Jan 2025 17:35:04 -0300 Subject: [PATCH 41/45] chore: cargo fmt --- batcher/aligned-batcher/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/batcher/aligned-batcher/src/lib.rs b/batcher/aligned-batcher/src/lib.rs index bda2af87a..7fa09d539 100644 --- a/batcher/aligned-batcher/src/lib.rs +++ b/batcher/aligned-batcher/src/lib.rs @@ -1522,10 +1522,7 @@ impl Batcher { Ok(()) } Err(e) => { - error!( - "Failed to send batch to contract: {:?}", - e - ); + error!("Failed to send batch to contract: {:?}", e); self.metrics.reverted_batches.inc(); Err(e) From 178fabaed9a38253da3fd2ee3940f00577da269c Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Fri, 17 Jan 2025 18:26:10 -0300 Subject: [PATCH 42/45] fix: compatibility with base branch --- batcher/aligned/src/main.rs | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index a50ba29a3..f6e8a3b0c 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -220,11 +220,7 @@ pub struct GetUserNonceFromEthereumArgs { required = true )] address: String, - #[arg( - name = "The working network's name", - long = "network", - default_value = "devnet" - )] + #[clap(flatten)] network: NetworkArg, } @@ -243,18 +239,8 @@ pub struct GetUserAmountOfQueuedProofsArgs { required = true )] address: String, - #[arg( - name = "The working network's name", - long = "network", - default_value = "devnet" - )] + #[clap(flatten)] network: NetworkArg, - #[arg( - name = "Batcher connection address", - long = "batcher_url", - default_value = "ws://localhost:8080" - )] - batcher_url: String, } #[derive(Args, Debug)] @@ -672,10 +658,10 @@ async fn main() -> Result<(), AlignedError> { } GetUserAmountOfQueuedProofs(args) => { let address = H160::from_str(&args.address).unwrap(); - let network = args.network.into(); + let network: Network = args.network.into(); let Ok((ethereum_nonce, batcher_nonce)) = future::try_join( - get_nonce_from_ethereum(&args.eth_rpc_url, address, network), - get_nonce_from_batcher(&args.batcher_url, address), + get_nonce_from_ethereum(&args.eth_rpc_url, address, network.clone()), + get_nonce_from_batcher(network, address), ) .await .map_err(|e| error!("Error while getting nonce: {:?}", e)) else { From 09489e0af36499865c1fa9fda1ea44216fc2eefa Mon Sep 17 00:00:00 2001 From: JuArce <52429267+JuArce@users.noreply.github.com> Date: Tue, 21 Jan 2025 12:08:49 -0300 Subject: [PATCH 43/45] fix: add missing new line --- batcher/aligned-sdk/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batcher/aligned-sdk/Cargo.toml b/batcher/aligned-sdk/Cargo.toml index 90b828ba3..019a65984 100644 --- a/batcher/aligned-sdk/Cargo.toml +++ b/batcher/aligned-sdk/Cargo.toml @@ -24,4 +24,4 @@ url = "2.5.0" hex = "0.4.3" ciborium = "=0.2.2" serde_repr = "0.1.19" -dialoguer = "0.11.0" \ No newline at end of file +dialoguer = "0.11.0" From 689e77a7ec8499f363a8bb9377af5d1885f75e3b Mon Sep 17 00:00:00 2001 From: JuArce <52429267+JuArce@users.noreply.github.com> Date: Tue, 21 Jan 2025 12:09:53 -0300 Subject: [PATCH 44/45] fix: remove explorer mix.lock changes --- explorer/mix.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/explorer/mix.lock b/explorer/mix.lock index 336bebe7e..17f684b6a 100644 --- a/explorer/mix.lock +++ b/explorer/mix.lock @@ -23,7 +23,7 @@ "floki": {:hex, :floki, "0.36.2", "a7da0193538c93f937714a6704369711998a51a6164a222d710ebd54020aa7a3", [:mix], [], "hexpm", "a8766c0bc92f074e5cb36c4f9961982eda84c5d2b8e979ca67f5c268ec8ed580"}, "gettext": {:hex, :gettext, "0.24.0", "6f4d90ac5f3111673cbefc4ebee96fe5f37a114861ab8c7b7d5b30a1108ce6d8", [:mix], [{:expo, "~> 0.5.1", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "bdf75cdfcbe9e4622dd18e034b227d77dd17f0f133853a1c73b97b3d6c770e8b"}, "hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"}, - "heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized", depth: 1]}, + "heroicons": {:git, "https://github.com/tailwindlabs/heroicons.git", "88ab3a0d790e6a47404cba02800a6b25d2afae50", [tag: "v2.1.1", sparse: "optimized"]}, "hpax": {:hex, :hpax, "0.2.0", "5a58219adcb75977b2edce5eb22051de9362f08236220c9e859a47111c194ff5", [:mix], [], "hexpm", "bea06558cdae85bed075e6c036993d43cd54d447f76d8190a8db0dc5893fa2f1"}, "httpoison": {:hex, :httpoison, "2.2.1", "87b7ed6d95db0389f7df02779644171d7319d319178f6680438167d7b69b1f3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "51364e6d2f429d80e14fe4b5f8e39719cacd03eb3f9a9286e61e216feac2d2df"}, "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, From 88559ca05540dec228c297ce61a96ee002d592cd Mon Sep 17 00:00:00 2001 From: JuArce <52429267+JuArce@users.noreply.github.com> Date: Tue, 21 Jan 2025 14:43:59 -0300 Subject: [PATCH 45/45] docs: add get-user-nonce command docs: format file --- docs/3_guides/9_aligned_cli.md | 61 ++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/docs/3_guides/9_aligned_cli.md b/docs/3_guides/9_aligned_cli.md index b6f07269e..1575431b6 100644 --- a/docs/3_guides/9_aligned_cli.md +++ b/docs/3_guides/9_aligned_cli.md @@ -8,25 +8,28 @@ This document serves as a reference for the commands of the Aligned CLI. 1. Download and install Aligned from the Aligned GitHub repo `https://github.com/yetanotherco/aligned_layer`: -```bash -curl -L https://raw.githubusercontent.com/yetanotherco/aligned_layer/main/batcher/aligned/install_aligned.sh | bash -``` + ```bash + curl -L https://raw.githubusercontent.com/yetanotherco/aligned_layer/main/batcher/aligned/install_aligned.sh | bash + ``` 2. A source command will be printed in your terminal after installation. Execute that command to update your shell environment. 3. Verify that the installation was successful: -```bash -aligned --version -``` + + ```bash + aligned --version + ``` ## Help: To see the available commands, run: + ```bash aligned --help ``` To see the usage of a command, run: + ```bash aligned [COMMAND] --help ``` @@ -44,6 +47,7 @@ Submit a proof to the Aligned Layer batcher. `submit [OPTIONS] --proving_system --proof ` #### Options: + - `--batcher_url `: Websocket URL for the Aligned Layer batcher - Default: `ws://localhost:8080` - Mainnet: `wss://mainnet.batcher.alignedlayer.com` @@ -85,6 +89,7 @@ Submit a proof to the Aligned Layer batcher. #### Example: + ```bash aligned submit \ --proving_system Risc0 \ @@ -111,6 +116,7 @@ Check if a proof was verified by Aligned on Ethereum. `verify-proof-onchain [OPTIONS] --aligned-verification-data ` #### Options: + - `--aligned-verification-data `: Path to the aligned verification data file. - `--rpc_url `: User's Ethereum RPC provider connection address. - Default: `http://localhost:8545` @@ -127,6 +133,7 @@ Check if a proof was verified by Aligned on Ethereum. - `--batcher_url ` #### Example: + ```bash aligned verify-proof-onchain \ --aligned-verification-data ./aligned_verification_data/ \ @@ -147,6 +154,7 @@ Computes the verification data commitment from the verification data file. `get-vk-commitment [OPTIONS] --verification_key_file --proving_system ` #### Options: + - `--verification_key_file `: Path to the verification key file. - `--proving_system `: Proof system of the verification data file. - Possible values: `GnarkPlonkBls12_381`, `GnarkPlonkBn254`, `Groth16Bn254`, `SP1`, `Risc0` @@ -165,6 +173,7 @@ Deposits Ethereum into the Aligned Layer's `BatcherPaymentService.sol` contract. `deposit-to-batcher [OPTIONS] --keystore_path --amount ` #### Options: + - `--keystore_path `: Path to the local keystore. - `--private_key `: User's wallet private key. - `--rpc_url `: User's Ethereum RPC provider connection address. @@ -183,6 +192,7 @@ Deposits Ethereum into the Aligned Layer's `BatcherPaymentService.sol` contract. - `--batcher_url ` #### Example: + ```bash aligned deposit-to-batcher \ --network holesky \ @@ -205,6 +215,7 @@ Retrieves the user's balance in the Aligned Layer's contract. #### Options: + - One of the following, to specify which Network to interact with: - `--network `: Network name to interact with. - Default: `devnet` @@ -221,6 +232,7 @@ Retrieves the user's balance in the Aligned Layer's contract. - `--user_addr`: User's Ethereum address. #### Example: + ```bash aligned get-user-balance \ --user_addr \ @@ -230,8 +242,39 @@ aligned get-user-balance \ --- -### **get-user-nonce-from-ethereum** +### **get-user-nonce** + +#### Description: + +Retrieves the user's current nonce from the Batcher. + +#### Command: + +`get-user-nonce [OPTIONS] --user_addr ` +#### Options: + +- `--user_addr `: User's Ethereum address. +- One of the following, to specify which Network to interact with: + - `--network `: Network name to interact with. + - Default: `devnet` + - Possible values: `devnet`, `holesky`, `mainnet` + - For a custom Network, you must specify the following parameters: + - `--aligned_service_manager ` + - `--batcher_payment_service ` + - `--batcher_url ` + +#### Example: + +```bash +aligned get-user-nonce \ +--user_addr \ +--network holesky +``` + +--- + +### **get-user-nonce-from-ethereum** #### Description: @@ -242,6 +285,7 @@ Retrieves the user's current nonce from the Blockhain, in the Batcher Payment Se `get-user-nonce-from-ethereum [OPTIONS] --user_addr ` #### Options: + - `--user_addr `: User's Ethereum address. - One of the following, to specify which Network to interact with: - `--network `: Network name to interact with. @@ -258,6 +302,7 @@ Retrieves the user's current nonce from the Blockhain, in the Batcher Payment Se - Also, you can use your own Ethereum RPC providers. #### Example: + ```bash aligned get-user-nonce-from-ethereum \ --user_addr \ @@ -278,6 +323,7 @@ Retrieves the user's amount of queued proofs in the Batcher. `get-user-amount-of-queued-proofs [OPTIONS] --user_addr ` #### Options: + - `--user_addr `: User's Ethereum address. - `--network `: Network name to interact with. - Default: `devnet` @@ -293,6 +339,7 @@ Retrieves the user's amount of queued proofs in the Batcher. - Holesky: `wss://batcher.alignedlayer.com` #### Example: + ```bash aligned get-user-amount-of-queued-proofs \ --user_addr \