From 92ac39c1ebbc090e88b8a52ab5e09f2e95041202 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 20 Dec 2024 14:08:51 -0300 Subject: [PATCH 01/56] addd last_send_valid_nonce to InsufficientBalance Method --- batcher/aligned-batcher/src/lib.rs | 9 +++++---- batcher/aligned-sdk/src/communication/messaging.rs | 4 ++-- batcher/aligned-sdk/src/core/errors.rs | 8 ++++---- batcher/aligned-sdk/src/core/types.rs | 2 +- batcher/aligned/src/main.rs | 7 ++++--- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/batcher/aligned-batcher/src/lib.rs b/batcher/aligned-batcher/src/lib.rs index e5588d4e3..c774da722 100644 --- a/batcher/aligned-batcher/src/lib.rs +++ b/batcher/aligned-batcher/src/lib.rs @@ -628,6 +628,7 @@ impl Batcher { return Ok(()); } + // If there is one invalid proof we send message with one out of batch and send rejected one. if !zk_utils::verify(verification_data).await { error!("Invalid proof detected. Verification failed"); send_message( @@ -657,7 +658,7 @@ impl Batcher { if self.user_balance_is_unlocked(&addr).await { send_message( ws_conn_sink.clone(), - SubmitProofResponseMessage::InsufficientBalance(addr), + SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce), ) .await; self.metrics.user_error(&["insufficient_balance", ""]); @@ -749,7 +750,7 @@ impl Batcher { std::mem::drop(batch_state_lock); send_message( ws_conn_sink.clone(), - SubmitProofResponseMessage::InsufficientBalance(addr), + SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce), ) .await; self.metrics.user_error(&["insufficient_balance", ""]); @@ -1684,7 +1685,7 @@ impl Batcher { error!("Could not get balance for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - SubmitProofResponseMessage::InsufficientBalance(replacement_addr), + SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce), ) .await; return Ok(()); @@ -1694,7 +1695,7 @@ impl Batcher { error!("Insufficient funds for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - SubmitProofResponseMessage::InsufficientBalance(replacement_addr), + SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce), ) .await; return Ok(()); diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 7f3ad921c..6c093700a 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -190,9 +190,9 @@ async fn handle_batcher_response(msg: Message) -> Result { + Ok(SubmitProofResponseMessage::InsufficientBalance(addr, last_sent_valid_nonce)) => { error!("Batcher responded with insufficient balance"); - Err(SubmitError::InsufficientBalance(addr)) + Err(SubmitError::InsufficientBalance(addr, last_sent_valid_nonce)) } Ok(SubmitProofResponseMessage::InvalidChainId) => { error!("Batcher responded with invalid chain id"); diff --git a/batcher/aligned-sdk/src/core/errors.rs b/batcher/aligned-sdk/src/core/errors.rs index 8712009c6..3e47d6a16 100644 --- a/batcher/aligned-sdk/src/core/errors.rs +++ b/batcher/aligned-sdk/src/core/errors.rs @@ -2,7 +2,7 @@ use core::fmt; use ethers::providers::ProviderError; use ethers::signers::WalletError; use ethers::types::transaction::eip712::Eip712Error; -use ethers::types::{SignatureError, H160}; +use ethers::types::{SignatureError, H160, U256}; use serde::{Deserialize, Serialize}; use std::io; use std::path::PathBuf; @@ -90,7 +90,7 @@ pub enum SubmitError { InvalidProof(ProofInvalidReason), ProofTooLarge, InvalidReplacementMessage, - InsufficientBalance(H160), + InsufficientBalance(H160, U256), InvalidPaymentServiceAddress(H160, H160), BatchSubmissionFailed(String), AddToBatchError, @@ -195,8 +195,8 @@ impl fmt::Display for SubmitError { SubmitError::InvalidProof(reason) => write!(f, "Invalid proof {}", reason), SubmitError::ProofTooLarge => write!(f, "Proof too Large"), SubmitError::InvalidReplacementMessage => write!(f, "Invalid replacement message"), - SubmitError::InsufficientBalance(addr) => { - write!(f, "Insufficient balance, address: {}", addr) + SubmitError::InsufficientBalance(addr, last_sent_valid_nonce) => { + write!(f, "Insufficient balance, address: {} last_sent_valid_nonce: {}", addr, last_sent_valid_nonce) } SubmitError::InvalidPaymentServiceAddress(received_addr, expected_addr) => { write!( diff --git a/batcher/aligned-sdk/src/core/types.rs b/batcher/aligned-sdk/src/core/types.rs index ba59b5d6b..92e708e80 100644 --- a/batcher/aligned-sdk/src/core/types.rs +++ b/batcher/aligned-sdk/src/core/types.rs @@ -381,7 +381,7 @@ pub enum SubmitProofResponseMessage { InvalidSignature, ProofTooLarge, InvalidMaxFee, - InsufficientBalance(Address), + InsufficientBalance(Address, U256), InvalidChainId, InvalidReplacementMessage, AddToBatchError, diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 1153cacbd..7f272dafa 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -610,10 +610,11 @@ async fn handle_submit_err(err: SubmitError) { error!("Batch was reset. try resubmitting the proof"); } SubmitError::InvalidProof(reason) => error!("Submitted proof is invalid: {}", reason), - SubmitError::InsufficientBalance(sender_address) => { + SubmitError::InsufficientBalance(sender_address, last_sent_valid_nonce) => { error!( - "Insufficient balance to pay for the transaction, address: {}", - sender_address + "Insufficient balance to pay for the transaction, address: {} nonce: {}", + sender_address, + last_sent_valid_nonce ) } _ => {} From de4d543267a04324595de84c9ca86159fe0c1af8 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 20 Dec 2024 16:43:04 -0300 Subject: [PATCH 02/56] receive older msg's --- .../aligned-sdk/src/communication/messaging.rs | 18 ++++++++++++++---- batcher/aligned/src/main.rs | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 6c093700a..08de99aa9 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -99,7 +99,7 @@ pub async fn receive( // Responses are filtered to only admit binary or close messages. let mut response_stream = response_stream.lock().await; let mut aligned_submitted_data: Vec> = Vec::new(); - let last_proof_nonce = get_biggest_nonce(&sent_verification_data_rev); + let mut last_proof_nonce = get_biggest_nonce(&sent_verification_data_rev); // read from WS while let Some(Ok(msg)) = response_stream.next().await { @@ -123,9 +123,18 @@ pub async fn receive( let batch_inclusion_data_message = match handle_batcher_response(msg).await { Ok(data) => data, Err(e) => { - warn!("Error while handling batcher response: {:?}", e); - aligned_submitted_data.push(Err(e)); - break; + // In the case of an insufficient balance we still want to read and return the proofs. + // `last_valid_nonce` corresponds to the nonce of the proof that triggered InsufficientBalance. + // Therefore the other proofs are in order and we set the last_proof_nonce to the nonce of the InsufficientBalance. + if let SubmitError::InsufficientBalance(_, last_valid_nonce) = e { + aligned_submitted_data.push(Err(e)); + last_proof_nonce = last_valid_nonce - 1; + continue; + } else { + warn!("Error while handling batcher response: {:?}", e); + aligned_submitted_data.push(Err(e)); + break; + } } }; @@ -191,6 +200,7 @@ async fn handle_batcher_response(msg: Message) -> Result { + // If we receive an invalid balance we should grab the last_sent_valid_nonce. error!("Batcher responded with insufficient balance"); Err(SubmitError::InsufficientBalance(addr, last_sent_valid_nonce)) } diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 7f272dafa..6e47cab42 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -612,7 +612,7 @@ async fn handle_submit_err(err: SubmitError) { SubmitError::InvalidProof(reason) => error!("Submitted proof is invalid: {}", reason), SubmitError::InsufficientBalance(sender_address, last_sent_valid_nonce) => { error!( - "Insufficient balance to pay for the transaction, address: {} nonce: {}", + "Insufficient balance to pay for the transaction, address: {} last_valid_nonce: {}", sender_address, last_sent_valid_nonce ) From 820d4f3e8e4241865deb521e3bf679ee06b99f2e Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 20 Dec 2024 20:30:38 -0300 Subject: [PATCH 03/56] works --- batcher/aligned-batcher/src/lib.rs | 10 +++++-- .../src/communication/messaging.rs | 29 ++++++++++++++----- batcher/aligned-sdk/src/sdk.rs | 2 +- batcher/aligned/src/main.rs | 12 ++++++-- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/batcher/aligned-batcher/src/lib.rs b/batcher/aligned-batcher/src/lib.rs index c774da722..50a47ce41 100644 --- a/batcher/aligned-batcher/src/lib.rs +++ b/batcher/aligned-batcher/src/lib.rs @@ -658,6 +658,7 @@ impl Batcher { if self.user_balance_is_unlocked(&addr).await { send_message( ws_conn_sink.clone(), + // last_valid_nonce = client_msg.verification_data.nonce - 1. SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce), ) .await; @@ -750,7 +751,8 @@ impl Batcher { std::mem::drop(batch_state_lock); send_message( ws_conn_sink.clone(), - SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce), + // last_valid_nonce = client_msg.verification_data.nonce - 1. + SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce - 1), ) .await; self.metrics.user_error(&["insufficient_balance", ""]); @@ -1685,7 +1687,8 @@ impl Batcher { error!("Could not get balance for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce), + // last_valid_nonce = client_msg.verification_data.nonce - 1. + SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce - 1), ) .await; return Ok(()); @@ -1695,7 +1698,8 @@ impl Batcher { error!("Insufficient funds for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce), + // last_valid_nonce = client_msg.verification_data.nonce - 1. + SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce - 1), ) .await; return Ok(()); diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 08de99aa9..8afe7b1c4 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -95,11 +95,14 @@ pub async fn send_messages( pub async fn receive( response_stream: Arc>, mut sent_verification_data_rev: Vec>, + first_nonce: U256, ) -> Vec> { // Responses are filtered to only admit binary or close messages. let mut response_stream = response_stream.lock().await; let mut aligned_submitted_data: Vec> = Vec::new(); - let mut last_proof_nonce = get_biggest_nonce(&sent_verification_data_rev); + let last_sent_proof_nonce = get_biggest_nonce(&sent_verification_data_rev); + let mut last_proof_nonce = last_sent_proof_nonce; + info!("last_sent_proof_nonce: {}", last_sent_proof_nonce); // read from WS while let Some(Ok(msg)) = response_stream.next().await { @@ -123,18 +126,25 @@ pub async fn receive( let batch_inclusion_data_message = match handle_batcher_response(msg).await { Ok(data) => data, Err(e) => { - // In the case of an insufficient balance we still want to read and return the proofs. + warn!("Error while handling batcher response: {:?}", e); + // In the case of submitting multiple proofs we can have an multiple proofs be submitted but there + // insufficient balance we still want to read and return the `batch_inclusion_data` of the proofs that were approved. // `last_valid_nonce` corresponds to the nonce of the proof that triggered InsufficientBalance. // Therefore the other proofs are in order and we set the last_proof_nonce to the nonce of the InsufficientBalance. if let SubmitError::InsufficientBalance(_, last_valid_nonce) = e { aligned_submitted_data.push(Err(e)); - last_proof_nonce = last_valid_nonce - 1; + // last_valid_nonce = last_nonce - 1. In the case + info!("last_proof_nonce: {}", last_proof_nonce); + info!("last_valid_nonce: {}", last_valid_nonce); + // In the case all proofs are insufficient balance we go over them. + last_proof_nonce -= U256::from(1); + if last_proof_nonce <= first_nonce { + break; + } continue; - } else { - warn!("Error while handling batcher response: {:?}", e); - aligned_submitted_data.push(Err(e)); - break; } + aligned_submitted_data.push(Err(e)); + break; } }; @@ -168,6 +178,9 @@ pub async fn receive( aligned_submitted_data.push(Ok(aligned_verification_data)); debug!("Message response handled successfully"); + info!("last_proof_nonce: {}", last_proof_nonce); + info!("batch_inclusion_data_message.user_nonce: {}", batch_inclusion_data_message.user_nonce); + if batch_inclusion_data_message.user_nonce == last_proof_nonce { break; } @@ -314,4 +327,4 @@ fn get_biggest_nonce( } } biggest_nonce -} +} \ No newline at end of file diff --git a/batcher/aligned-sdk/src/sdk.rs b/batcher/aligned-sdk/src/sdk.rs index 6045d8411..8db9cdaff 100644 --- a/batcher/aligned-sdk/src/sdk.rs +++ b/batcher/aligned-sdk/src/sdk.rs @@ -340,7 +340,7 @@ async fn _submit_multiple( nonce, ) .await; - receive(response_stream, sent_verification_data_rev).await + receive(response_stream, sent_verification_data_rev, nonce).await } .await; diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 6e47cab42..d6668ab78 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -392,8 +392,14 @@ async fn main() -> Result<(), AlignedError> { } Err(e) => { warn!("Error while submitting proof: {:?}", e); - handle_submit_err(e).await; - return Ok(()); + handle_submit_err(&e).await; + // In the case of an InsufficientBalance error we record and process the entire msg queue. + // This covers the case of multiple submissions that succeed but fail for a comulative balance of all max_fee's. + if let SubmitError::InsufficientBalance(_,_) = e { + continue; + } else { + return Ok(()); + } } }; } @@ -601,7 +607,7 @@ fn verification_data_from_args(args: &SubmitArgs) -> Result { error!("Invalid nonce. try again"); From 6e68bffcc960bed642da3807dd5dc61c31103014 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 20 Dec 2024 21:43:11 -0300 Subject: [PATCH 04/56] edge case + msg --- batcher/aligned-sdk/src/communication/messaging.rs | 9 +++++++-- batcher/aligned/src/main.rs | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 8afe7b1c4..676c48b46 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -137,10 +137,15 @@ pub async fn receive( info!("last_proof_nonce: {}", last_proof_nonce); info!("last_valid_nonce: {}", last_valid_nonce); // In the case all proofs are insufficient balance we go over them. - last_proof_nonce -= U256::from(1); - if last_proof_nonce <= first_nonce { + //last_proof_nonce -= U256::from(1); + if last_valid_nonce < last_proof_nonce { + last_proof_nonce = last_valid_nonce; + } + + if last_proof_nonce < first_nonce { break; } + continue; } aligned_submitted_data.push(Err(e)); diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index d6668ab78..5eccbbedc 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -393,7 +393,7 @@ async fn main() -> Result<(), AlignedError> { Err(e) => { warn!("Error while submitting proof: {:?}", e); handle_submit_err(&e).await; - // In the case of an InsufficientBalance error we record and process the entire msg queue. + // In the case of an InsufficientBalance error we record and continue processing the entire msg queue. // This covers the case of multiple submissions that succeed but fail for a comulative balance of all max_fee's. if let SubmitError::InsufficientBalance(_,_) = e { continue; @@ -406,6 +406,8 @@ async fn main() -> Result<(), AlignedError> { match unique_batch_merkle_roots.len() { 1 => info!("Proofs submitted to aligned. See the batch in the explorer:"), + // If no verification data we do not log the msg. + 0 => (), _ => info!("Proofs submitted to aligned. See the batches in the explorer:"), } From 4d72694d0e00f0780c185b5d2f444d5581807f13 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 20 Dec 2024 21:59:59 -0300 Subject: [PATCH 05/56] fmt + clippy --- batcher/aligned-batcher/src/lib.rs | 28 +++++++++++++------ .../src/communication/messaging.rs | 18 ++++++++---- batcher/aligned-sdk/src/core/errors.rs | 6 +++- batcher/aligned/src/main.rs | 5 ++-- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/batcher/aligned-batcher/src/lib.rs b/batcher/aligned-batcher/src/lib.rs index 50a47ce41..8a97ec1b3 100644 --- a/batcher/aligned-batcher/src/lib.rs +++ b/batcher/aligned-batcher/src/lib.rs @@ -658,8 +658,11 @@ impl Batcher { if self.user_balance_is_unlocked(&addr).await { send_message( ws_conn_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. - SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce), + // last_valid_nonce = client_msg.verification_data.nonce - 1. + SubmitProofResponseMessage::InsufficientBalance( + addr, + nonced_verification_data.nonce, + ), ) .await; self.metrics.user_error(&["insufficient_balance", ""]); @@ -751,8 +754,11 @@ impl Batcher { std::mem::drop(batch_state_lock); send_message( ws_conn_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. - SubmitProofResponseMessage::InsufficientBalance(addr, nonced_verification_data.nonce - 1), + // last_valid_nonce = client_msg.verification_data.nonce - 1. + SubmitProofResponseMessage::InsufficientBalance( + addr, + nonced_verification_data.nonce - 1, + ), ) .await; self.metrics.user_error(&["insufficient_balance", ""]); @@ -1687,8 +1693,11 @@ impl Batcher { error!("Could not get balance for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. - SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce - 1), + // last_valid_nonce = client_msg.verification_data.nonce - 1. + SubmitProofResponseMessage::InsufficientBalance( + replacement_addr, + client_msg.verification_data.nonce - 1, + ), ) .await; return Ok(()); @@ -1698,8 +1707,11 @@ impl Batcher { error!("Insufficient funds for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. - SubmitProofResponseMessage::InsufficientBalance(replacement_addr, client_msg.verification_data.nonce - 1), + // last_valid_nonce = client_msg.verification_data.nonce - 1. + SubmitProofResponseMessage::InsufficientBalance( + replacement_addr, + client_msg.verification_data.nonce - 1, + ), ) .await; return Ok(()); diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 676c48b46..4b678a4c4 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -127,13 +127,13 @@ pub async fn receive( Ok(data) => data, Err(e) => { warn!("Error while handling batcher response: {:?}", e); - // In the case of submitting multiple proofs we can have an multiple proofs be submitted but there + // In the case of submitting multiple proofs we can have an multiple proofs be submitted but there // insufficient balance we still want to read and return the `batch_inclusion_data` of the proofs that were approved. - // `last_valid_nonce` corresponds to the nonce of the proof that triggered InsufficientBalance. + // `last_valid_nonce` corresponds to the nonce of the proof that triggered InsufficientBalance. // Therefore the other proofs are in order and we set the last_proof_nonce to the nonce of the InsufficientBalance. if let SubmitError::InsufficientBalance(_, last_valid_nonce) = e { aligned_submitted_data.push(Err(e)); - // last_valid_nonce = last_nonce - 1. In the case + // last_valid_nonce = last_nonce - 1. In the case info!("last_proof_nonce: {}", last_proof_nonce); info!("last_valid_nonce: {}", last_valid_nonce); // In the case all proofs are insufficient balance we go over them. @@ -184,7 +184,10 @@ pub async fn receive( debug!("Message response handled successfully"); info!("last_proof_nonce: {}", last_proof_nonce); - info!("batch_inclusion_data_message.user_nonce: {}", batch_inclusion_data_message.user_nonce); + info!( + "batch_inclusion_data_message.user_nonce: {}", + batch_inclusion_data_message.user_nonce + ); if batch_inclusion_data_message.user_nonce == last_proof_nonce { break; @@ -220,7 +223,10 @@ async fn handle_batcher_response(msg: Message) -> Result { // If we receive an invalid balance we should grab the last_sent_valid_nonce. error!("Batcher responded with insufficient balance"); - Err(SubmitError::InsufficientBalance(addr, last_sent_valid_nonce)) + Err(SubmitError::InsufficientBalance( + addr, + last_sent_valid_nonce, + )) } Ok(SubmitProofResponseMessage::InvalidChainId) => { error!("Batcher responded with invalid chain id"); @@ -332,4 +338,4 @@ fn get_biggest_nonce( } } biggest_nonce -} \ No newline at end of file +} diff --git a/batcher/aligned-sdk/src/core/errors.rs b/batcher/aligned-sdk/src/core/errors.rs index 3e47d6a16..5ce83de6c 100644 --- a/batcher/aligned-sdk/src/core/errors.rs +++ b/batcher/aligned-sdk/src/core/errors.rs @@ -196,7 +196,11 @@ impl fmt::Display for SubmitError { SubmitError::ProofTooLarge => write!(f, "Proof too Large"), SubmitError::InvalidReplacementMessage => write!(f, "Invalid replacement message"), SubmitError::InsufficientBalance(addr, last_sent_valid_nonce) => { - write!(f, "Insufficient balance, address: {} last_sent_valid_nonce: {}", addr, last_sent_valid_nonce) + write!( + f, + "Insufficient balance, address: {} last_sent_valid_nonce: {}", + addr, last_sent_valid_nonce + ) } SubmitError::InvalidPaymentServiceAddress(received_addr, expected_addr) => { write!( diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 5eccbbedc..fe81f94d8 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -395,7 +395,7 @@ async fn main() -> Result<(), AlignedError> { handle_submit_err(&e).await; // In the case of an InsufficientBalance error we record and continue processing the entire msg queue. // This covers the case of multiple submissions that succeed but fail for a comulative balance of all max_fee's. - if let SubmitError::InsufficientBalance(_,_) = e { + if let SubmitError::InsufficientBalance(_, _) = e { continue; } else { return Ok(()); @@ -621,8 +621,7 @@ async fn handle_submit_err(err: &SubmitError) { SubmitError::InsufficientBalance(sender_address, last_sent_valid_nonce) => { error!( "Insufficient balance to pay for the transaction, address: {} last_valid_nonce: {}", - sender_address, - last_sent_valid_nonce + sender_address, last_sent_valid_nonce ) } _ => {} From e550b811f7241bc74b10ec7ea2368b16a754d2e6 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 23 Dec 2024 13:06:55 -0300 Subject: [PATCH 06/56] julian's comments --- batcher/aligned-batcher/src/lib.rs | 3 +-- batcher/aligned-sdk/src/communication/messaging.rs | 9 --------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/batcher/aligned-batcher/src/lib.rs b/batcher/aligned-batcher/src/lib.rs index 8a97ec1b3..85e49db9d 100644 --- a/batcher/aligned-batcher/src/lib.rs +++ b/batcher/aligned-batcher/src/lib.rs @@ -628,7 +628,6 @@ impl Batcher { return Ok(()); } - // If there is one invalid proof we send message with one out of batch and send rejected one. if !zk_utils::verify(verification_data).await { error!("Invalid proof detected. Verification failed"); send_message( @@ -661,7 +660,7 @@ impl Batcher { // last_valid_nonce = client_msg.verification_data.nonce - 1. SubmitProofResponseMessage::InsufficientBalance( addr, - nonced_verification_data.nonce, + nonced_verification_data.nonce - 1, ), ) .await; diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 4b678a4c4..d4ae4f6cd 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -127,17 +127,8 @@ pub async fn receive( Ok(data) => data, Err(e) => { warn!("Error while handling batcher response: {:?}", e); - // In the case of submitting multiple proofs we can have an multiple proofs be submitted but there - // insufficient balance we still want to read and return the `batch_inclusion_data` of the proofs that were approved. - // `last_valid_nonce` corresponds to the nonce of the proof that triggered InsufficientBalance. - // Therefore the other proofs are in order and we set the last_proof_nonce to the nonce of the InsufficientBalance. if let SubmitError::InsufficientBalance(_, last_valid_nonce) = e { aligned_submitted_data.push(Err(e)); - // last_valid_nonce = last_nonce - 1. In the case - info!("last_proof_nonce: {}", last_proof_nonce); - info!("last_valid_nonce: {}", last_valid_nonce); - // In the case all proofs are insufficient balance we go over them. - //last_proof_nonce -= U256::from(1); if last_valid_nonce < last_proof_nonce { last_proof_nonce = last_valid_nonce; } From 7b86ef7c4c826e0049ab480f5157ffb8c82cf95f Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 23 Dec 2024 16:27:28 -0300 Subject: [PATCH 07/56] cmt + messaging fix --- batcher/aligned-batcher/src/lib.rs | 12 ++++-------- batcher/aligned-sdk/src/communication/messaging.rs | 9 ++++++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/batcher/aligned-batcher/src/lib.rs b/batcher/aligned-batcher/src/lib.rs index 85e49db9d..a652a92e3 100644 --- a/batcher/aligned-batcher/src/lib.rs +++ b/batcher/aligned-batcher/src/lib.rs @@ -657,10 +657,9 @@ impl Batcher { if self.user_balance_is_unlocked(&addr).await { send_message( ws_conn_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. SubmitProofResponseMessage::InsufficientBalance( addr, - nonced_verification_data.nonce - 1, + nonced_verification_data.nonce, ), ) .await; @@ -753,10 +752,9 @@ impl Batcher { std::mem::drop(batch_state_lock); send_message( ws_conn_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. SubmitProofResponseMessage::InsufficientBalance( addr, - nonced_verification_data.nonce - 1, + nonced_verification_data.nonce, ), ) .await; @@ -1692,10 +1690,9 @@ impl Batcher { error!("Could not get balance for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. SubmitProofResponseMessage::InsufficientBalance( replacement_addr, - client_msg.verification_data.nonce - 1, + client_msg.verification_data.nonce, ), ) .await; @@ -1706,10 +1703,9 @@ impl Batcher { error!("Insufficient funds for non-paying address {replacement_addr:?}"); send_message( ws_sink.clone(), - // last_valid_nonce = client_msg.verification_data.nonce - 1. SubmitProofResponseMessage::InsufficientBalance( replacement_addr, - client_msg.verification_data.nonce - 1, + client_msg.verification_data.nonce, ), ) .await; diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index d4ae4f6cd..8980bdccb 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -127,8 +127,15 @@ pub async fn receive( Ok(data) => data, Err(e) => { warn!("Error while handling batcher response: {:?}", e); - if let SubmitError::InsufficientBalance(_, last_valid_nonce) = e { + // When submitting multiple batches a InsufficientBalance error may occur when the `max_balance` of a user within the + // BatcherPaymentService.sol is exceeded. This leads to a scenario where some proofs are verified and others rejected with + // The SubmitError::InsufficientBalance(error_nonce) thrown. To ensure the user is notified of that some of there proofs were rejected + // we return upon erroring the nonce of the proof that has errored (is returned earlier) and set that as the new `last_proof_nonce`. + // This ensures the client messaging protocol continues receivng verification and error responses until all messages are received. + if let SubmitError::InsufficientBalance(_, error_nonce) = e { aligned_submitted_data.push(Err(e)); + + let last_valid_nonce = error_nonce - 1; if last_valid_nonce < last_proof_nonce { last_proof_nonce = last_valid_nonce; } From c3ea68fe83abb3ca21f5664a455ef48dc95d513f Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 23 Dec 2024 19:31:44 -0300 Subject: [PATCH 08/56] fmt --- batcher/aligned-sdk/src/communication/messaging.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 8980bdccb..c030f131e 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -127,7 +127,7 @@ pub async fn receive( Ok(data) => data, Err(e) => { warn!("Error while handling batcher response: {:?}", e); - // When submitting multiple batches a InsufficientBalance error may occur when the `max_balance` of a user within the + // When submitting multiple batches a InsufficientBalance error may occur when the `max_balance` of a user within the // BatcherPaymentService.sol is exceeded. This leads to a scenario where some proofs are verified and others rejected with // The SubmitError::InsufficientBalance(error_nonce) thrown. To ensure the user is notified of that some of there proofs were rejected // we return upon erroring the nonce of the proof that has errored (is returned earlier) and set that as the new `last_proof_nonce`. From 72cff089c01172a74c07b1d67922f6d0a90b8664 Mon Sep 17 00:00:00 2001 From: Uriel Mihura <43704209+uri-99@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:13:25 -0300 Subject: [PATCH 09/56] Update batcher/aligned-sdk/src/communication/messaging.rs --- batcher/aligned-sdk/src/communication/messaging.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index c030f131e..9ac3fae62 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -129,7 +129,7 @@ pub async fn receive( warn!("Error while handling batcher response: {:?}", e); // When submitting multiple batches a InsufficientBalance error may occur when the `max_balance` of a user within the // BatcherPaymentService.sol is exceeded. This leads to a scenario where some proofs are verified and others rejected with - // The SubmitError::InsufficientBalance(error_nonce) thrown. To ensure the user is notified of that some of there proofs were rejected + // The SubmitError::InsufficientBalance(error_nonce) thrown. To ensure the user is notified that some of their proofs were rejected // we return upon erroring the nonce of the proof that has errored (is returned earlier) and set that as the new `last_proof_nonce`. // This ensures the client messaging protocol continues receivng verification and error responses until all messages are received. if let SubmitError::InsufficientBalance(_, error_nonce) = e { From 6bdfb70f698159ca6b403cecb790b61a71ff9ea0 Mon Sep 17 00:00:00 2001 From: Uriel Mihura <43704209+uri-99@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:20:26 -0300 Subject: [PATCH 10/56] Update batcher/aligned-sdk/src/communication/messaging.rs --- batcher/aligned-sdk/src/communication/messaging.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 9ac3fae62..d43f680b8 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -127,11 +127,11 @@ pub async fn receive( Ok(data) => data, Err(e) => { warn!("Error while handling batcher response: {:?}", e); - // When submitting multiple batches a InsufficientBalance error may occur when the `max_balance` of a user within the - // BatcherPaymentService.sol is exceeded. This leads to a scenario where some proofs are verified and others rejected with - // The SubmitError::InsufficientBalance(error_nonce) thrown. To ensure the user is notified that some of their proofs were rejected - // we return upon erroring the nonce of the proof that has errored (is returned earlier) and set that as the new `last_proof_nonce`. - // This ensures the client messaging protocol continues receivng verification and error responses until all messages are received. + // When submitting multiple batches, an InsufficientBalance error may occur, when the required balance of a user would exceed his balance in the BatcherPaymentService.sol + // This leads to a scenario where some of the submitted proofs are accepted and others rejected, with + // the SubmitError::InsufficientBalance(error_nonce) thrown. To ensure the user is notified that some of their proofs were rejected, + // we return upon erroring the nonce of the proof that has errored and set the new `last_proof_nonce` value accordingly. + // This ensures the client messaging protocol continues receiving verification and error responses until all messages are received. if let SubmitError::InsufficientBalance(_, error_nonce) = e { aligned_submitted_data.push(Err(e)); From 62657d93cfdad3e18ec23010a276567e98dceb4b Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 30 Dec 2024 10:20:21 -0300 Subject: [PATCH 11/56] remove comments --- batcher/aligned-sdk/src/communication/messaging.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index d43f680b8..a8a7171ce 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -181,12 +181,6 @@ pub async fn receive( aligned_submitted_data.push(Ok(aligned_verification_data)); debug!("Message response handled successfully"); - info!("last_proof_nonce: {}", last_proof_nonce); - info!( - "batch_inclusion_data_message.user_nonce: {}", - batch_inclusion_data_message.user_nonce - ); - if batch_inclusion_data_message.user_nonce == last_proof_nonce { break; } From 35947b643d9369129bdf7a77afbca7f6792edd17 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 30 Dec 2024 10:23:02 -0300 Subject: [PATCH 12/56] rm print --- batcher/aligned-sdk/src/communication/messaging.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index a8a7171ce..742d894ae 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -102,7 +102,6 @@ pub async fn receive( let mut aligned_submitted_data: Vec> = Vec::new(); let last_sent_proof_nonce = get_biggest_nonce(&sent_verification_data_rev); let mut last_proof_nonce = last_sent_proof_nonce; - info!("last_sent_proof_nonce: {}", last_sent_proof_nonce); // read from WS while let Some(Ok(msg)) = response_stream.next().await { From 898bd09e5cdd3ab7ad1da9d4d4015bd52c3be489 Mon Sep 17 00:00:00 2001 From: Uriel Mihura <43704209+uri-99@users.noreply.github.com> Date: Mon, 30 Dec 2024 10:46:36 -0300 Subject: [PATCH 13/56] Update batcher/aligned/src/main.rs --- 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 fe81f94d8..24561d0f4 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -394,7 +394,7 @@ async fn main() -> Result<(), AlignedError> { warn!("Error while submitting proof: {:?}", e); handle_submit_err(&e).await; // In the case of an InsufficientBalance error we record and continue processing the entire msg queue. - // This covers the case of multiple submissions that succeed but fail for a comulative balance of all max_fee's. + // This covers the case of a `submit_multiple` in which some submissions succeed but others fail because of a cumulative `insufficient balance`. if let SubmitError::InsufficientBalance(_, _) = e { continue; } else { From 67bf22c60ba4c7e08767f444c411c69a491203f2 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 30 Dec 2024 11:16:57 -0300 Subject: [PATCH 14/56] fix variable names --- batcher/aligned-sdk/src/communication/messaging.rs | 9 +++++---- batcher/aligned-sdk/src/core/errors.rs | 6 +++--- batcher/aligned/src/main.rs | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 742d894ae..00c59be9e 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -2,6 +2,7 @@ use ethers::signers::Signer; use ethers::types::Address; use futures_util::{stream::SplitStream, SinkExt, StreamExt}; use log::{debug, error, info, warn}; +use std::error; use std::sync::Arc; use tokio::{net::TcpStream, sync::Mutex}; @@ -21,7 +22,7 @@ use crate::{ SubmitProofResponseMessage, VerificationData, VerificationDataCommitment, }, }, -}; + }; pub type ResponseStream = TryFilter< SplitStream>>, @@ -211,12 +212,12 @@ async fn handle_batcher_response(msg: Message) -> Result { - // If we receive an invalid balance we should grab the last_sent_valid_nonce. + Ok(SubmitProofResponseMessage::InsufficientBalance(addr, error_nonce)) => { + // If we receive an invalid balance we should grab the error_nonce. error!("Batcher responded with insufficient balance"); Err(SubmitError::InsufficientBalance( addr, - last_sent_valid_nonce, + error_nonce, )) } Ok(SubmitProofResponseMessage::InvalidChainId) => { diff --git a/batcher/aligned-sdk/src/core/errors.rs b/batcher/aligned-sdk/src/core/errors.rs index 5ce83de6c..e0f2eef86 100644 --- a/batcher/aligned-sdk/src/core/errors.rs +++ b/batcher/aligned-sdk/src/core/errors.rs @@ -195,11 +195,11 @@ impl fmt::Display for SubmitError { SubmitError::InvalidProof(reason) => write!(f, "Invalid proof {}", reason), SubmitError::ProofTooLarge => write!(f, "Proof too Large"), SubmitError::InvalidReplacementMessage => write!(f, "Invalid replacement message"), - SubmitError::InsufficientBalance(addr, last_sent_valid_nonce) => { + SubmitError::InsufficientBalance(addr, error_nonce) => { write!( f, - "Insufficient balance, address: {} last_sent_valid_nonce: {}", - addr, last_sent_valid_nonce + "Insufficient balance, address: {} error_nonce: {}", + addr, error_nonce ) } SubmitError::InvalidPaymentServiceAddress(received_addr, expected_addr) => { diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 24561d0f4..c8207c097 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -618,10 +618,10 @@ async fn handle_submit_err(err: &SubmitError) { error!("Batch was reset. try resubmitting the proof"); } SubmitError::InvalidProof(reason) => error!("Submitted proof is invalid: {}", reason), - SubmitError::InsufficientBalance(sender_address, last_sent_valid_nonce) => { + SubmitError::InsufficientBalance(sender_address, error_nonce) => { error!( - "Insufficient balance to pay for the transaction, address: {} last_valid_nonce: {}", - sender_address, last_sent_valid_nonce + "Insufficient balance to pay for the transaction, address: {} error_nonce: {}", + sender_address, error_nonce ) } _ => {} From 3c754bce3fbea3e9201f7e831e058c12e6fb335a Mon Sep 17 00:00:00 2001 From: PatStiles Date: Mon, 30 Dec 2024 11:39:55 -0300 Subject: [PATCH 15/56] clippy --- batcher/aligned-sdk/src/communication/messaging.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 00c59be9e..1c488178f 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -2,7 +2,6 @@ use ethers::signers::Signer; use ethers::types::Address; use futures_util::{stream::SplitStream, SinkExt, StreamExt}; use log::{debug, error, info, warn}; -use std::error; use std::sync::Arc; use tokio::{net::TcpStream, sync::Mutex}; @@ -22,7 +21,7 @@ use crate::{ SubmitProofResponseMessage, VerificationData, VerificationDataCommitment, }, }, - }; +}; pub type ResponseStream = TryFilter< SplitStream>>, @@ -215,10 +214,7 @@ async fn handle_batcher_response(msg: Message) -> Result { // If we receive an invalid balance we should grab the error_nonce. error!("Batcher responded with insufficient balance"); - Err(SubmitError::InsufficientBalance( - addr, - error_nonce, - )) + Err(SubmitError::InsufficientBalance(addr, error_nonce)) } Ok(SubmitProofResponseMessage::InvalidChainId) => { error!("Batcher responded with invalid chain id"); From 9cfc7bb365b662813661b0bc9bef9e26d08f4790 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Thu, 2 Jan 2025 11:44:46 -0300 Subject: [PATCH 16/56] handle overflow error case --- batcher/aligned-sdk/src/communication/messaging.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 1c488178f..1cdac82b8 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -134,7 +134,10 @@ pub async fn receive( if let SubmitError::InsufficientBalance(_, error_nonce) = e { aligned_submitted_data.push(Err(e)); - let last_valid_nonce = error_nonce - 1; + // We handle the explicit case that a user sends a proof without an balance deposited. + // This triggers an InsufficientBalance error with `error_nonce`` of `0` leading to an overflow error. + // If `error_nonce` == U256::zero() we return the `error_nonce` to prevent overflow. + let last_valid_nonce = if error_nonce == U256::zero() { error_nonce } else { error_nonce - 1 }; if last_valid_nonce < last_proof_nonce { last_proof_nonce = last_valid_nonce; } From 593b5ba921929ef496753db9f3ac7e8eb355aaa0 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Thu, 2 Jan 2025 13:08:21 -0300 Subject: [PATCH 17/56] fmt --- batcher/aligned-sdk/src/communication/messaging.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 1cdac82b8..f9ea82d56 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -134,10 +134,14 @@ pub async fn receive( if let SubmitError::InsufficientBalance(_, error_nonce) = e { aligned_submitted_data.push(Err(e)); - // We handle the explicit case that a user sends a proof without an balance deposited. + // We handle the explicit case that a user sends a proof without an balance deposited. // This triggers an InsufficientBalance error with `error_nonce`` of `0` leading to an overflow error. // If `error_nonce` == U256::zero() we return the `error_nonce` to prevent overflow. - let last_valid_nonce = if error_nonce == U256::zero() { error_nonce } else { error_nonce - 1 }; + let last_valid_nonce = if error_nonce == U256::zero() { + error_nonce + } else { + error_nonce - 1 + }; if last_valid_nonce < last_proof_nonce { last_proof_nonce = last_valid_nonce; } From 5211f448b6a602774c33d687562f6af6b43e7bcb Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 3 Jan 2025 09:53:26 -0300 Subject: [PATCH 18/56] gaston's comments --- batcher/aligned-sdk/src/communication/messaging.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index f9ea82d56..c6bcd2990 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -137,13 +137,14 @@ pub async fn receive( // We handle the explicit case that a user sends a proof without an balance deposited. // This triggers an InsufficientBalance error with `error_nonce`` of `0` leading to an overflow error. // If `error_nonce` == U256::zero() we return the `error_nonce` to prevent overflow. - let last_valid_nonce = if error_nonce == U256::zero() { - error_nonce + let last_error_nonce = if error_nonce == U256::zero() { + //error_nonce + break } else { error_nonce - 1 }; - if last_valid_nonce < last_proof_nonce { - last_proof_nonce = last_valid_nonce; + if last_error_nonce < last_proof_nonce { + last_proof_nonce = last_error_nonce; } if last_proof_nonce < first_nonce { From 22c14f82cf0e9bd45d34f124b55e8d9e08321596 Mon Sep 17 00:00:00 2001 From: PatStiles Date: Fri, 3 Jan 2025 12:42:41 -0300 Subject: [PATCH 19/56] clippy --- batcher/aligned-sdk/src/communication/messaging.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index c6bcd2990..821147c7d 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -138,8 +138,7 @@ pub async fn receive( // This triggers an InsufficientBalance error with `error_nonce`` of `0` leading to an overflow error. // If `error_nonce` == U256::zero() we return the `error_nonce` to prevent overflow. let last_error_nonce = if error_nonce == U256::zero() { - //error_nonce - break + break; } else { error_nonce - 1 }; From 3be473bcfa636e4d92a8f62664a529d3d4c4619e Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Tue, 7 Jan 2025 13:12:49 -0300 Subject: [PATCH 20/56] refactor: cut condition of error_nonce, now easier to read and follow --- .../src/communication/messaging.rs | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 821147c7d..0a3f9ebe3 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -100,8 +100,8 @@ pub async fn receive( // Responses are filtered to only admit binary or close messages. let mut response_stream = response_stream.lock().await; let mut aligned_submitted_data: Vec> = Vec::new(); - let last_sent_proof_nonce = get_biggest_nonce(&sent_verification_data_rev); - let mut last_proof_nonce = last_sent_proof_nonce; + let last_sent_nonce = get_biggest_nonce(&sent_verification_data_rev); + let mut last_valid_proof_nonce = last_sent_nonce; // read from WS while let Some(Ok(msg)) = response_stream.next().await { @@ -125,32 +125,24 @@ pub async fn receive( let batch_inclusion_data_message = match handle_batcher_response(msg).await { Ok(data) => data, Err(e) => { - warn!("Error while handling batcher response: {:?}", e); + warn!("Error detected while handling batcher response: {:?}", e); // When submitting multiple batches, an InsufficientBalance error may occur, when the required balance of a user would exceed his balance in the BatcherPaymentService.sol // This leads to a scenario where some of the submitted proofs are accepted and others rejected, with // the SubmitError::InsufficientBalance(error_nonce) thrown. To ensure the user is notified that some of their proofs were rejected, - // we return upon erroring the nonce of the proof that has errored and set the new `last_proof_nonce` value accordingly. - // This ensures the client messaging protocol continues receiving verification and error responses until all messages are received. + // we return upon erroring the nonce of the proof that has errored and set the new `last_valid_proof_nonce` value accordingly. + // This ensures the client messaging protocol continues receiving responses until all messages are received. if let SubmitError::InsufficientBalance(_, error_nonce) = e { aligned_submitted_data.push(Err(e)); - // We handle the explicit case that a user sends a proof without an balance deposited. - // This triggers an InsufficientBalance error with `error_nonce`` of `0` leading to an overflow error. - // If `error_nonce` == U256::zero() we return the `error_nonce` to prevent overflow. - let last_error_nonce = if error_nonce == U256::zero() { - break; - } else { - error_nonce - 1 - }; - if last_error_nonce < last_proof_nonce { - last_proof_nonce = last_error_nonce; + if error_nonce == first_nonce { // no proofs where accepted by the batcher (this also covers error_nonce==0) + break; // stop listening responses } - - if last_proof_nonce < first_nonce { - break; + + if last_valid_proof_nonce > (error_nonce - 1) { // last_valid_proof_nonce needs to be updated, since there is a new error_nonce + last_valid_proof_nonce = error_nonce - 1; } - continue; + continue; // continue listening responses } aligned_submitted_data.push(Err(e)); break; @@ -187,7 +179,7 @@ pub async fn receive( aligned_submitted_data.push(Ok(aligned_verification_data)); debug!("Message response handled successfully"); - if batch_inclusion_data_message.user_nonce == last_proof_nonce { + if batch_inclusion_data_message.user_nonce == last_valid_proof_nonce { break; } } @@ -220,7 +212,7 @@ async fn handle_batcher_response(msg: Message) -> Result { // If we receive an invalid balance we should grab the error_nonce. - error!("Batcher responded with insufficient balance"); + error!("Batcher responded with insufficient balance, for nonce {}", error_nonce); Err(SubmitError::InsufficientBalance(addr, error_nonce)) } Ok(SubmitProofResponseMessage::InvalidChainId) => { From 3c97f74ac68aa907e7854693ab404de973c2d75d Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Tue, 7 Jan 2025 13:26:39 -0300 Subject: [PATCH 21/56] chore: comments --- batcher/aligned-sdk/src/communication/messaging.rs | 3 ++- batcher/aligned/src/main.rs | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 0a3f9ebe3..5467d3cf4 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -134,7 +134,8 @@ pub async fn receive( if let SubmitError::InsufficientBalance(_, error_nonce) = e { aligned_submitted_data.push(Err(e)); - if error_nonce == first_nonce { // no proofs where accepted by the batcher (this also covers error_nonce==0) + if error_nonce == first_nonce { // no proofs where accepted by the batcher + // this also covers error_nonce==0, which as uint risks an underflow when substracting 1 break; // stop listening responses } diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index c8207c097..6eeb5d019 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -406,8 +406,7 @@ async fn main() -> Result<(), AlignedError> { match unique_batch_merkle_roots.len() { 1 => info!("Proofs submitted to aligned. See the batch in the explorer:"), - // If no verification data we do not log the msg. - 0 => (), + 0 => (), // No verification data, we do not log the msg. This happens when insufficient balance for first nonce _ => info!("Proofs submitted to aligned. See the batches in the explorer:"), } From 6da71a9bb33c668e55c09b918a7d0a1a4c96bf30 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:31:10 -0300 Subject: [PATCH 22/56] chore: cargo fmt --- .../aligned-sdk/src/communication/messaging.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 5467d3cf4..dfbf22752 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -134,12 +134,14 @@ pub async fn receive( if let SubmitError::InsufficientBalance(_, error_nonce) = e { aligned_submitted_data.push(Err(e)); - if error_nonce == first_nonce { // no proofs where accepted by the batcher - // this also covers error_nonce==0, which as uint risks an underflow when substracting 1 - break; // stop listening responses + if error_nonce == first_nonce { + // no proofs where accepted by the batcher + // this also covers error_nonce==0, which as uint risks an underflow when substracting 1 + break; // stop listening responses } - - if last_valid_proof_nonce > (error_nonce - 1) { // last_valid_proof_nonce needs to be updated, since there is a new error_nonce + + if last_valid_proof_nonce > (error_nonce - 1) { + // last_valid_proof_nonce needs to be updated, since there is a new error_nonce last_valid_proof_nonce = error_nonce - 1; } @@ -213,7 +215,10 @@ async fn handle_batcher_response(msg: Message) -> Result { // If we receive an invalid balance we should grab the error_nonce. - error!("Batcher responded with insufficient balance, for nonce {}", error_nonce); + error!( + "Batcher responded with insufficient balance, for nonce {}", + error_nonce + ); Err(SubmitError::InsufficientBalance(addr, error_nonce)) } Ok(SubmitProofResponseMessage::InvalidChainId) => { From 7189711c7fe506f5fa68acde04a7dfc56541c27b Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:47:23 -0300 Subject: [PATCH 23/56] refactor: better error messages for the user --- batcher/aligned-sdk/src/communication/messaging.rs | 4 ++-- batcher/aligned/src/main.rs | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index dfbf22752..926d8ac91 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -215,8 +215,8 @@ async fn handle_batcher_response(msg: Message) -> Result { // If we receive an invalid balance we should grab the error_nonce. - error!( - "Batcher responded with insufficient balance, for nonce {}", + warn!( + "Batcher responded with insufficient balance to pay for proof of nonce: {}. If you sent more proofs, your other proofs may have been accepted.", error_nonce ); Err(SubmitError::InsufficientBalance(addr, error_nonce)) diff --git a/batcher/aligned/src/main.rs b/batcher/aligned/src/main.rs index 6eeb5d019..e4abde1a3 100644 --- a/batcher/aligned/src/main.rs +++ b/batcher/aligned/src/main.rs @@ -356,8 +356,6 @@ async fn main() -> Result<(), AlignedError> { })?, }; - warn!("Nonce: {nonce}"); - let verification_data = verification_data_from_args(&submit_args)?; let verification_data_arr = vec![verification_data; repetitions]; @@ -391,7 +389,7 @@ async fn main() -> Result<(), AlignedError> { .insert(aligned_verification_data.batch_merkle_root); } Err(e) => { - warn!("Error while submitting proof: {:?}", e); + warn!("Error detected while submitting proof: {:?}", e); handle_submit_err(&e).await; // In the case of an InsufficientBalance error we record and continue processing the entire msg queue. // This covers the case of a `submit_multiple` in which some submissions succeed but others fail because of a cumulative `insufficient balance`. @@ -618,8 +616,8 @@ async fn handle_submit_err(err: &SubmitError) { } SubmitError::InvalidProof(reason) => error!("Submitted proof is invalid: {}", reason), SubmitError::InsufficientBalance(sender_address, error_nonce) => { - error!( - "Insufficient balance to pay for the transaction, address: {} error_nonce: {}", + warn!( + "Insufficient balance to pay for the proof verification, address: {}, for proof_nonce: {}.", sender_address, error_nonce ) } From 29635f66f6b8260f73c553e0d97f37fa0df5f582 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Tue, 7 Jan 2025 15:08:28 -0300 Subject: [PATCH 24/56] chore: better info messages --- batcher/aligned-sdk/src/communication/messaging.rs | 2 +- batcher/aligned-sdk/src/sdk.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index 926d8ac91..35c63ab72 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -80,7 +80,7 @@ pub async fn send_messages( sent_verification_data.push(Ok(verification_data)); } - info!("All proofs sent"); + info!("All proofs sent, wait until they are included in a batch"); // This vector is reversed so that while responses are received, removing from the end is cheaper. let sent_verification_data_rev: Vec> = sent_verification_data.into_iter().rev().collect(); diff --git a/batcher/aligned-sdk/src/sdk.rs b/batcher/aligned-sdk/src/sdk.rs index 8db9cdaff..dc824de32 100644 --- a/batcher/aligned-sdk/src/sdk.rs +++ b/batcher/aligned-sdk/src/sdk.rs @@ -345,7 +345,7 @@ async fn _submit_multiple( .await; // Close connection - info!("Closing WS connection"); + info!("All responses received, closing WS connection"); if let Err(e) = ws_write_clone.lock().await.close().await { return vec![Err(errors::SubmitError::GenericError(e.to_string()))]; } From d55f58ed78f8745c7a6588c45aa9fa7d41658eab Mon Sep 17 00:00:00 2001 From: PatStiles Date: Tue, 10 Dec 2024 10:39:33 -0300 Subject: [PATCH 25/56] 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 26/56] 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 27/56] 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 28/56] 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 29/56] 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 30/56] 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 31/56] 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 32/56] 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 33/56] 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 34/56] 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 35/56] 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 36/56] 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 37/56] 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 38/56] 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 39/56] 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 40/56] 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 41/56] 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 42/56] 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 43/56] 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 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 44/56] 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 45/56] 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 46/56] 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 47/56] 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 48/56] 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 49/56] 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 50/56] 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 51/56] 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 00a252cc051d5ae7c05f16b99e5dbf1b1f98f11b Mon Sep 17 00:00:00 2001 From: JuArce <52429267+JuArce@users.noreply.github.com> Date: Fri, 17 Jan 2025 18:23:43 -0300 Subject: [PATCH 52/56] fix: batcher urls --- batcher/aligned-sdk/src/core/constants.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/batcher/aligned-sdk/src/core/constants.rs b/batcher/aligned-sdk/src/core/constants.rs index e573dcbfd..ee6dd7b36 100644 --- a/batcher/aligned-sdk/src/core/constants.rs +++ b/batcher/aligned-sdk/src/core/constants.rs @@ -57,6 +57,6 @@ pub const ALIGNED_SERVICE_MANAGER_HOLESKY_STAGE: &str = 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: &str = "wss://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"; +pub const BATCHER_URL_MAINNET: &str = "wss://mainnet.batcher.alignedlayer.com"; From cc84f6e14291f9b241ea5d6b758bbd02384c3ec1 Mon Sep 17 00:00:00 2001 From: JuArce <52429267+JuArce@users.noreply.github.com> Date: Fri, 17 Jan 2025 18:24:42 -0300 Subject: [PATCH 53/56] fix: 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 5bd5fb93fa98b3ff5f7a9cfce3faff28362981a3 Mon Sep 17 00:00:00 2001 From: JuArce <52429267+JuArce@users.noreply.github.com> Date: Fri, 17 Jan 2025 18:38:06 -0300 Subject: [PATCH 54/56] fix: remove 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..ef18193b6 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 5a5447c7a28759f2dfed7654b814c1a77b6f7836 Mon Sep 17 00:00:00 2001 From: JuArce <52429267+JuArce@users.noreply.github.com> Date: Fri, 17 Jan 2025 18:38:28 -0300 Subject: [PATCH 55/56] fix: remove 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 ef18193b6..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"}, + "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 9dd858741b51aa03d2cc0834ece9585df75cfe60 Mon Sep 17 00:00:00 2001 From: Urix <43704209+uri-99@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:10:30 -0300 Subject: [PATCH 56/56] fix: pr comments --- batcher/aligned-sdk/src/communication/messaging.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/batcher/aligned-sdk/src/communication/messaging.rs b/batcher/aligned-sdk/src/communication/messaging.rs index b033abc81..8fa08631e 100644 --- a/batcher/aligned-sdk/src/communication/messaging.rs +++ b/batcher/aligned-sdk/src/communication/messaging.rs @@ -100,8 +100,7 @@ pub async fn receive( // Responses are filtered to only admit binary or close messages. let mut response_stream = response_stream.lock().await; let mut aligned_submitted_data: Vec> = Vec::new(); - let last_sent_nonce = get_biggest_nonce(&sent_verification_data_rev); - let mut last_valid_proof_nonce = last_sent_nonce; + let mut last_valid_proof_nonce = get_biggest_nonce(&sent_verification_data_rev); // read from WS while let Some(Ok(msg)) = response_stream.next().await { @@ -126,7 +125,7 @@ pub async fn receive( Ok(data) => data, Err(e) => { warn!("Error detected while handling batcher response: {:?}", e); - // When submitting multiple batches, an InsufficientBalance error may occur, when the required balance of a user would exceed his balance in the BatcherPaymentService.sol + // When submitting multiple proofs, an InsufficientBalance error may occur, when the required balance of a user would exceed his balance in the BatcherPaymentService.sol // This leads to a scenario where some of the submitted proofs are accepted and others rejected, with // the SubmitError::InsufficientBalance(error_nonce) thrown. To ensure the user is notified that some of their proofs were rejected, // we return upon erroring the nonce of the proof that has errored and set the new `last_valid_proof_nonce` value accordingly.