From 85643d636eded4dd7fc263fc2bdcd5141257a1c6 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Fri, 9 Jan 2026 16:29:12 -0300 Subject: [PATCH 01/16] feat(aggregation-mode): Bump fee when proof verification times out --- .../proof_aggregator/src/backend/mod.rs | 240 ++++++++++++------ 1 file changed, 160 insertions(+), 80 deletions(-) diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index f43398595..916425fb3 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -22,7 +22,7 @@ use alloy::{ consensus::{BlobTransactionSidecar, EnvKzgSettings, EthereumTxEnvelope, TxEip4844WithSidecar}, eips::{eip4844::BYTES_PER_BLOB, eip7594::BlobTransactionSidecarEip7594, Encodable2718}, hex, - network::EthereumWallet, + network::{EthereumWallet, TransactionBuilder}, primitives::{utils::parse_ether, Address, U256}, providers::{PendingTransactionError, Provider, ProviderBuilder}, rpc::types::TransactionReceipt, @@ -334,90 +334,170 @@ impl ProofAggregator { info!("Sending proof to ProofAggregationService contract..."); - let tx_req = match aggregated_proof { - AlignedProof::SP1(proof) => self - .proof_aggregation_service - .verifyAggregationSP1( - blob_versioned_hash.into(), - proof.proof_with_pub_values.public_values.to_vec().into(), - proof.proof_with_pub_values.bytes().into(), - self.sp1_chunk_aggregator_vk_hash_bytes.into(), - ) - .sidecar(blob) - .into_transaction_request(), - AlignedProof::Risc0(proof) => { - let encoded_seal = encode_seal(&proof.receipt) - .map_err(|e| AggregatedProofSubmissionError::Risc0EncodingSeal(e.to_string())) - .map_err(RetryError::Permanent)?; - self.proof_aggregation_service - .verifyAggregationRisc0( + // TODO: Read from config + let max_retries = 5; + let retry_interval = Duration::from_secs(120); + let fee_multiplier: f64 = 1.2; + + for attempt in 0..max_retries { + let mut tx_req = match aggregated_proof { + AlignedProof::SP1(proof) => self + .proof_aggregation_service + .verifyAggregationSP1( blob_versioned_hash.into(), - encoded_seal.into(), - proof.receipt.journal.bytes.clone().into(), - self.risc0_chunk_aggregator_image_id_bytes.into(), + proof.proof_with_pub_values.public_values.to_vec().into(), + proof.proof_with_pub_values.bytes().into(), + self.sp1_chunk_aggregator_vk_hash_bytes.into(), ) - .sidecar(blob) - .into_transaction_request() - } - }; - - let provider = self.proof_aggregation_service.provider(); - let envelope = provider - .fill(tx_req) - .await - .map_err(|err| { - AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( - err.to_string(), - ) - }) - .map_err(RetryError::Transient)? - .try_into_envelope() - .map_err(|err| { - AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( - err.to_string(), - ) - }) - .map_err(RetryError::Transient)?; - let tx: EthereumTxEnvelope> = envelope - .try_into_pooled() - .map_err(|err| { - AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( - err.to_string(), - ) - }) - .map_err(RetryError::Transient)? - .try_map_eip4844(|tx| { - tx.try_map_sidecar(|sidecar| sidecar.try_into_7594(EnvKzgSettings::Default.get())) - }) - .map_err(|err| { - AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( - err.to_string(), - ) - }) - .map_err(RetryError::Transient)?; + .sidecar(blob.clone()) + .into_transaction_request(), + AlignedProof::Risc0(proof) => { + let encoded_seal = encode_seal(&proof.receipt) + .map_err(|e| { + AggregatedProofSubmissionError::Risc0EncodingSeal(e.to_string()) + }) + .map_err(RetryError::Permanent)?; + self.proof_aggregation_service + .verifyAggregationRisc0( + blob_versioned_hash.into(), + encoded_seal.into(), + proof.receipt.journal.bytes.clone().into(), + self.risc0_chunk_aggregator_image_id_bytes.into(), + ) + .sidecar(blob.clone()) + .into_transaction_request() + } + }; - let encoded_tx = tx.encoded_2718(); - let pending_tx = provider - .send_raw_transaction(&encoded_tx) - .await - .map_err(|err| { - AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( - err.to_string(), - ) - }) - .map_err(RetryError::Transient)?; + let provider = self.proof_aggregation_service.provider(); + + // TODO: Move this to a separate method reset_gas_fees() + // Increase gas price/fees for retries before filling + if attempt > 0 { + let multiplier = fee_multiplier.powi(attempt as i32); + + info!( + "Retry attempt {} with increased fee ({}x)", + attempt, multiplier + ); + + // Obtain the current gas price if not set + if tx_req.max_fee_per_gas.is_none() { + let current_gas_price = provider.get_gas_price().await.map_err(|e| { + RetryError::Transient(AggregatedProofSubmissionError::GasPriceError( + e.to_string(), + )) + })?; + + let new_max_fee = (current_gas_price as f64 * multiplier) as u128; + let new_priority_fee = (current_gas_price as f64 * multiplier * 0.1) as u128; + + tx_req = tx_req + .with_max_fee_per_gas(new_max_fee) + .with_max_priority_fee_per_gas(new_priority_fee); + } else { + // If set, multiplicate the current ones + if let Some(max_fee) = tx_req.max_fee_per_gas { + let new_max_fee = (max_fee as f64 * multiplier) as u128; + tx_req = tx_req.with_max_fee_per_gas(new_max_fee); + } + if let Some(priority_fee) = tx_req.max_priority_fee_per_gas { + let new_priority_fee = (priority_fee as f64 * multiplier * 0.1) as u128; + tx_req = tx_req.with_max_priority_fee_per_gas(new_priority_fee); + } + } + } - let receipt = pending_tx - .get_receipt() - .await - .map_err(|err| { - AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( - err.to_string(), - ) - }) - .map_err(RetryError::Transient)?; + let envelope = provider + .fill(tx_req) + .await + .map_err(|err| { + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( + err.to_string(), + ) + }) + .map_err(RetryError::Transient)? + .try_into_envelope() + .map_err(|err| { + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( + err.to_string(), + ) + }) + .map_err(RetryError::Transient)?; + + let tx: EthereumTxEnvelope> = + envelope + .try_into_pooled() + .map_err(|err| { + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( + err.to_string(), + ) + }) + .map_err(RetryError::Transient)? + .try_map_eip4844(|tx| { + tx.try_map_sidecar(|sidecar| { + sidecar.try_into_7594(EnvKzgSettings::Default.get()) + }) + }) + .map_err(|err| { + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( + err.to_string(), + ) + }) + .map_err(RetryError::Transient)?; + + let encoded_tx = tx.encoded_2718(); + let pending_tx = provider + .send_raw_transaction(&encoded_tx) + .await + .map_err(|err| { + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( + err.to_string(), + ) + }) + .map_err(RetryError::Transient)?; + + // Wait for the receipt with timeout + let receipt_result = + tokio::time::timeout(retry_interval, pending_tx.get_receipt()).await; + + match receipt_result { + Ok(Ok(receipt)) => { + info!( + "Transaction confirmed successfully on attempt {}", + attempt + 1 + ); + return Ok(receipt); + } + Ok(Err(err)) => { + warn!("Error getting receipt on attempt {}: {}", attempt + 1, err); + if attempt == max_retries - 1 { + return Err(RetryError::Transient( + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( + err.to_string(), + ), + )); + } + } + Err(_) => { + warn!("Transaction not confirmed after {} seconds on attempt {}, retrying with higher fee...", + retry_interval.as_secs(), attempt + 1); + if attempt == max_retries - 1 { + return Err(RetryError::Transient( + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( + "Transaction timeout after all retries".to_string(), + ), + )); + } + } + } + } - Ok(receipt) + Err(RetryError::Transient( + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( + "Max retries exceeded".to_string(), + ), + )) } async fn wait_until_can_submit_aggregated_proof( From e377dda8d1390733beea5ebbbc415e21e074781b Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Fri, 9 Jan 2026 16:46:48 -0300 Subject: [PATCH 02/16] fix clippy lint removing unnecessary cast --- aggregation_mode/proof_aggregator/src/backend/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index 916425fb3..ea5868861 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -374,7 +374,7 @@ impl ProofAggregator { // TODO: Move this to a separate method reset_gas_fees() // Increase gas price/fees for retries before filling if attempt > 0 { - let multiplier = fee_multiplier.powi(attempt as i32); + let multiplier = fee_multiplier.powi(attempt); info!( "Retry attempt {} with increased fee ({}x)", From cc96a7ecbd73412d66a37283324483681962cdbd Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Fri, 9 Jan 2026 18:04:55 -0300 Subject: [PATCH 03/16] refactor: move the gas fees update to a separate method --- .../proof_aggregator/src/backend/mod.rs | 103 ++++++++++++------ 1 file changed, 68 insertions(+), 35 deletions(-) diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index ea5868861..891d18e45 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -369,45 +369,15 @@ impl ProofAggregator { } }; - let provider = self.proof_aggregation_service.provider(); - - // TODO: Move this to a separate method reset_gas_fees() // Increase gas price/fees for retries before filling if attempt > 0 { - let multiplier = fee_multiplier.powi(attempt); - - info!( - "Retry attempt {} with increased fee ({}x)", - attempt, multiplier - ); - - // Obtain the current gas price if not set - if tx_req.max_fee_per_gas.is_none() { - let current_gas_price = provider.get_gas_price().await.map_err(|e| { - RetryError::Transient(AggregatedProofSubmissionError::GasPriceError( - e.to_string(), - )) - })?; - - let new_max_fee = (current_gas_price as f64 * multiplier) as u128; - let new_priority_fee = (current_gas_price as f64 * multiplier * 0.1) as u128; - - tx_req = tx_req - .with_max_fee_per_gas(new_max_fee) - .with_max_priority_fee_per_gas(new_priority_fee); - } else { - // If set, multiplicate the current ones - if let Some(max_fee) = tx_req.max_fee_per_gas { - let new_max_fee = (max_fee as f64 * multiplier) as u128; - tx_req = tx_req.with_max_fee_per_gas(new_max_fee); - } - if let Some(priority_fee) = tx_req.max_priority_fee_per_gas { - let new_priority_fee = (priority_fee as f64 * multiplier * 0.1) as u128; - tx_req = tx_req.with_max_priority_fee_per_gas(new_priority_fee); - } - } + tx_req = self + .update_gas_fees(fee_multiplier, attempt, tx_req) + .await?; } + let provider = self.proof_aggregation_service.provider(); + let envelope = provider .fill(tx_req) .await @@ -500,6 +470,69 @@ impl ProofAggregator { )) } + // Updates the gas fees of a `TransactionRequest` for retry attempts by applying an exponential fee + // multiplier based on the retry number. This method is intended to be used when a previous transaction + // attempt was not confirmed (e.g. receipt timeout or transient failure). By increasing the gas fees + // on each retry, it improves the likelihood that the transaction will be included + // on the next block. + // + // Fee strategy: + // An exponential multiplier is computed on each iteration. For example, with `fee_multiplier = 1.2`: + // - `attempt = 1` → `1.2x` + // - `attempt = 2` → `1.44x` + // - `attempt = 3` → `1.728x` + // + // If the transaction request doesn't have `max_fee_per_gas` set, the current network gas price is fetched + // from the provider, the max fee per gas is set to `current_gas_price * multiplier` and the max priority + // fee per gas is set to `current_gas_price * multiplier * 0.1`. + // + // If the transaction request already contains the fee fields, the existing max fee per gas is multiplied + // by `multiplier`, and the existing max priority fee per gas is multiplied by multiplier * 0.1`. + async fn update_gas_fees( + &self, + fee_multiplier: f64, + attempt: i32, + tx_req: alloy::rpc::types::TransactionRequest, + ) -> Result> + { + let provider = self.proof_aggregation_service.provider(); + + let multiplier = fee_multiplier.powi(attempt); + + info!( + "Retry attempt {} with increased fee ({}x)", + attempt, multiplier + ); + + let mut current_tx_req = tx_req.clone(); + + // Obtain the current gas price if not set + if tx_req.max_fee_per_gas.is_none() { + let current_gas_price = provider.get_gas_price().await.map_err(|e| { + RetryError::Transient(AggregatedProofSubmissionError::GasPriceError(e.to_string())) + })?; + + let new_max_fee = (current_gas_price as f64 * multiplier) as u128; + let new_priority_fee = (current_gas_price as f64 * multiplier * 0.1) as u128; + + current_tx_req = current_tx_req + .with_max_fee_per_gas(new_max_fee) + .with_max_priority_fee_per_gas(new_priority_fee); + } else { + // If set, multiplicate the current ones + if let Some(max_fee) = tx_req.max_fee_per_gas { + let new_max_fee = (max_fee as f64 * multiplier) as u128; + current_tx_req = tx_req.clone().with_max_fee_per_gas(new_max_fee); + } + if let Some(priority_fee) = tx_req.max_priority_fee_per_gas { + let new_priority_fee = (priority_fee as f64 * multiplier * 0.1) as u128; + current_tx_req = tx_req.with_max_priority_fee_per_gas(new_priority_fee); + } + } + + Ok(current_tx_req) + } + async fn wait_until_can_submit_aggregated_proof( &self, ) -> Result<(), RetryError> { From 31807fb37108ef0767e25c28f955b36e2c34a395 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Fri, 9 Jan 2026 18:37:50 -0300 Subject: [PATCH 04/16] Move the bump behavior config values to the proof aggregator config files --- aggregation_mode/proof_aggregator/src/backend/config.rs | 3 +++ aggregation_mode/proof_aggregator/src/backend/mod.rs | 9 ++++----- .../config-proof-aggregator-ethereum-package.yaml | 5 +++++ config-files/config-proof-aggregator.yaml | 5 +++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/aggregation_mode/proof_aggregator/src/backend/config.rs b/aggregation_mode/proof_aggregator/src/backend/config.rs index 41081afc7..eff20fe14 100644 --- a/aggregation_mode/proof_aggregator/src/backend/config.rs +++ b/aggregation_mode/proof_aggregator/src/backend/config.rs @@ -21,6 +21,9 @@ pub struct Config { pub sp1_chunk_aggregator_vk_hash: String, pub monthly_budget_eth: f64, pub db_connection_urls: Vec, + pub max_bump_retries: u16, + pub bump_retry_interval_seconds: u64, + pub bump_increase_fee_multiplier: f64, } impl Config { diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index 891d18e45..766fd665a 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -334,10 +334,9 @@ impl ProofAggregator { info!("Sending proof to ProofAggregationService contract..."); - // TODO: Read from config - let max_retries = 5; - let retry_interval = Duration::from_secs(120); - let fee_multiplier: f64 = 1.2; + let max_retries = self.config.max_bump_retries; + let retry_interval = Duration::from_secs(self.config.bump_retry_interval_seconds); + let fee_multiplier: f64 = self.config.bump_increase_fee_multiplier; for attempt in 0..max_retries { let mut tx_req = match aggregated_proof { @@ -372,7 +371,7 @@ impl ProofAggregator { // Increase gas price/fees for retries before filling if attempt > 0 { tx_req = self - .update_gas_fees(fee_multiplier, attempt, tx_req) + .update_gas_fees(fee_multiplier, attempt as i32, tx_req) .await?; } diff --git a/config-files/config-proof-aggregator-ethereum-package.yaml b/config-files/config-proof-aggregator-ethereum-package.yaml index 23034743c..2942a7658 100644 --- a/config-files/config-proof-aggregator-ethereum-package.yaml +++ b/config-files/config-proof-aggregator-ethereum-package.yaml @@ -27,6 +27,11 @@ monthly_budget_eth: 15.0 sp1_chunk_aggregator_vk_hash: "00d6e32a34f68ea643362b96615591c94ee0bf99ee871740ab2337966a4f77af" risc0_chunk_aggregator_image_id: "8908f01022827e80a5de71908c16ee44f4a467236df20f62e7c994491629d74c" +# These values modify the bumping behavior after the aggregated proof on-chain submission times out. +max_bump_retries: 5 +bump_retry_interval_seconds: 120 +bump_increase_fee_multiplier: 1.2 + ecdsa: private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json" private_key_store_password: "" diff --git a/config-files/config-proof-aggregator.yaml b/config-files/config-proof-aggregator.yaml index 61a4f982a..804962bf2 100644 --- a/config-files/config-proof-aggregator.yaml +++ b/config-files/config-proof-aggregator.yaml @@ -27,6 +27,11 @@ monthly_budget_eth: 15.0 sp1_chunk_aggregator_vk_hash: "00ba19eed0aaeb0151f07b8d3ee7c659bcd29f3021e48fb42766882f55b84509" risc0_chunk_aggregator_image_id: "d8cfdd5410c70395c0a1af1842a0148428cc46e353355faccfba694dd4862dbf" +# These values modify the bumping behavior after the aggregated proof on-chain submission times out. +max_bump_retries: 5 +bump_retry_interval_seconds: 120 +bump_increase_fee_multiplier: 1.2 + ecdsa: private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json" private_key_store_password: "" From 6e99953679faa820f4ac3adae874e402c2d98788 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 12 Jan 2026 11:07:54 -0300 Subject: [PATCH 05/16] fix: use modified tx_req in update_gas_fees --- .../proof_aggregator/src/backend/mod.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index 766fd665a..15fc18596 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -505,8 +505,7 @@ impl ProofAggregator { let mut current_tx_req = tx_req.clone(); - // Obtain the current gas price if not set - if tx_req.max_fee_per_gas.is_none() { + if current_tx_req.max_fee_per_gas.is_none() { let current_gas_price = provider.get_gas_price().await.map_err(|e| { RetryError::Transient(AggregatedProofSubmissionError::GasPriceError(e.to_string())) })?; @@ -518,14 +517,13 @@ impl ProofAggregator { .with_max_fee_per_gas(new_max_fee) .with_max_priority_fee_per_gas(new_priority_fee); } else { - // If set, multiplicate the current ones - if let Some(max_fee) = tx_req.max_fee_per_gas { + if let Some(max_fee) = current_tx_req.max_fee_per_gas { let new_max_fee = (max_fee as f64 * multiplier) as u128; - current_tx_req = tx_req.clone().with_max_fee_per_gas(new_max_fee); + current_tx_req = current_tx_req.with_max_fee_per_gas(new_max_fee); } - if let Some(priority_fee) = tx_req.max_priority_fee_per_gas { - let new_priority_fee = (priority_fee as f64 * multiplier * 0.1) as u128; - current_tx_req = tx_req.with_max_priority_fee_per_gas(new_priority_fee); + if let Some(priority_fee) = current_tx_req.max_priority_fee_per_gas { + let new_priority_fee = (priority_fee as f64 * multiplier) as u128; + current_tx_req = current_tx_req.with_max_priority_fee_per_gas(new_priority_fee); } } From f475f08d14e4fd8e1f3955335f311a47619d5c83 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 12 Jan 2026 11:26:58 -0300 Subject: [PATCH 06/16] rework the bump logic to use a linear bump instead of an exponential one --- .../proof_aggregator/src/backend/config.rs | 3 +- .../proof_aggregator/src/backend/mod.rs | 65 ++++++++++--------- ...fig-proof-aggregator-ethereum-package.yaml | 3 +- config-files/config-proof-aggregator.yaml | 3 +- 4 files changed, 41 insertions(+), 33 deletions(-) diff --git a/aggregation_mode/proof_aggregator/src/backend/config.rs b/aggregation_mode/proof_aggregator/src/backend/config.rs index eff20fe14..94788f01a 100644 --- a/aggregation_mode/proof_aggregator/src/backend/config.rs +++ b/aggregation_mode/proof_aggregator/src/backend/config.rs @@ -23,7 +23,8 @@ pub struct Config { pub db_connection_urls: Vec, pub max_bump_retries: u16, pub bump_retry_interval_seconds: u64, - pub bump_increase_fee_multiplier: f64, + pub base_bump_percentage: u64, + pub retry_attempt_percentage: u64, } impl Config { diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index 15fc18596..630b347be 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -336,7 +336,8 @@ impl ProofAggregator { let max_retries = self.config.max_bump_retries; let retry_interval = Duration::from_secs(self.config.bump_retry_interval_seconds); - let fee_multiplier: f64 = self.config.bump_increase_fee_multiplier; + let base_bump_percentage = self.config.base_bump_percentage; // e.g., 10 + let retry_attempt_percentage = self.config.retry_attempt_percentage; // e.g., 5 for attempt in 0..max_retries { let mut tx_req = match aggregated_proof { @@ -371,7 +372,12 @@ impl ProofAggregator { // Increase gas price/fees for retries before filling if attempt > 0 { tx_req = self - .update_gas_fees(fee_multiplier, attempt as i32, tx_req) + .update_gas_fees( + base_bump_percentage, + retry_attempt_percentage, + attempt as u64, + tx_req, + ) .await?; } @@ -469,39 +475,31 @@ impl ProofAggregator { )) } - // Updates the gas fees of a `TransactionRequest` for retry attempts by applying an exponential fee - // multiplier based on the retry number. This method is intended to be used when a previous transaction - // attempt was not confirmed (e.g. receipt timeout or transient failure). By increasing the gas fees - // on each retry, it improves the likelihood that the transaction will be included - // on the next block. - // - // Fee strategy: - // An exponential multiplier is computed on each iteration. For example, with `fee_multiplier = 1.2`: - // - `attempt = 1` → `1.2x` - // - `attempt = 2` → `1.44x` - // - `attempt = 3` → `1.728x` + // Updates the gas fees of a `TransactionRequest` for retry attempts by applying a linear fee + // bump based on the retry number. This method is intended to be used when a previous transaction + // attempt was not confirmed (e.g. receipt timeout or transient failure). // - // If the transaction request doesn't have `max_fee_per_gas` set, the current network gas price is fetched - // from the provider, the max fee per gas is set to `current_gas_price * multiplier` and the max priority - // fee per gas is set to `current_gas_price * multiplier * 0.1`. + // Fee strategy (similar to Go implementation): + // The bump is calculated as: base_bump_percentage + (retry_count * retry_attempt_percentage) + // For example, with `base_bump_percentage = 10` and `retry_attempt_percentage = 5`: + // - `attempt = 1` → 10% + (1 * 5%) = 15% bump + // - `attempt = 2` → 10% + (2 * 5%) = 20% bump + // - `attempt = 3` → 10% + (3 * 5%) = 25% bump // - // If the transaction request already contains the fee fields, the existing max fee per gas is multiplied - // by `multiplier`, and the existing max priority fee per gas is multiplied by multiplier * 0.1`. + // The bumped price is: current_gas_price * (1 + total_bump_percentage / 100) async fn update_gas_fees( &self, - fee_multiplier: f64, - attempt: i32, + base_bump_percentage: u64, + retry_attempt_percentage: u64, + attempt: u64, tx_req: alloy::rpc::types::TransactionRequest, ) -> Result> { let provider = self.proof_aggregation_service.provider(); - let multiplier = fee_multiplier.powi(attempt); - - info!( - "Retry attempt {} with increased fee ({}x)", - attempt, multiplier - ); + // Calculate total bump percentage: base + (retry_count * retry_attempt) + let incremental_retry_percentage = retry_attempt_percentage * attempt; + let total_bump_percentage = base_bump_percentage + incremental_retry_percentage; let mut current_tx_req = tx_req.clone(); @@ -510,19 +508,21 @@ impl ProofAggregator { RetryError::Transient(AggregatedProofSubmissionError::GasPriceError(e.to_string())) })?; - let new_max_fee = (current_gas_price as f64 * multiplier) as u128; - let new_priority_fee = (current_gas_price as f64 * multiplier * 0.1) as u128; + let new_max_fee = + Self::calculate_bumped_price(current_gas_price, total_bump_percentage); + let new_priority_fee = new_max_fee / 10; // 10% of max fee current_tx_req = current_tx_req .with_max_fee_per_gas(new_max_fee) .with_max_priority_fee_per_gas(new_priority_fee); } else { if let Some(max_fee) = current_tx_req.max_fee_per_gas { - let new_max_fee = (max_fee as f64 * multiplier) as u128; + let new_max_fee = Self::calculate_bumped_price(max_fee, total_bump_percentage); current_tx_req = current_tx_req.with_max_fee_per_gas(new_max_fee); } if let Some(priority_fee) = current_tx_req.max_priority_fee_per_gas { - let new_priority_fee = (priority_fee as f64 * multiplier) as u128; + let new_priority_fee = + Self::calculate_bumped_price(priority_fee, total_bump_percentage); current_tx_req = current_tx_req.with_max_priority_fee_per_gas(new_priority_fee); } } @@ -530,6 +530,11 @@ impl ProofAggregator { Ok(current_tx_req) } + fn calculate_bumped_price(current_price: u128, total_bump_percentage: u64) -> u128 { + let bump_amount = (current_price * total_bump_percentage as u128) / 100; + current_price + bump_amount + } + async fn wait_until_can_submit_aggregated_proof( &self, ) -> Result<(), RetryError> { diff --git a/config-files/config-proof-aggregator-ethereum-package.yaml b/config-files/config-proof-aggregator-ethereum-package.yaml index 2942a7658..3f594d7d8 100644 --- a/config-files/config-proof-aggregator-ethereum-package.yaml +++ b/config-files/config-proof-aggregator-ethereum-package.yaml @@ -30,7 +30,8 @@ risc0_chunk_aggregator_image_id: "8908f01022827e80a5de71908c16ee44f4a467236df20f # These values modify the bumping behavior after the aggregated proof on-chain submission times out. max_bump_retries: 5 bump_retry_interval_seconds: 120 -bump_increase_fee_multiplier: 1.2 +base_bump_percentage: 10 +retry_attempt_percentage: 2 ecdsa: private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json" diff --git a/config-files/config-proof-aggregator.yaml b/config-files/config-proof-aggregator.yaml index 804962bf2..b3fd9af67 100644 --- a/config-files/config-proof-aggregator.yaml +++ b/config-files/config-proof-aggregator.yaml @@ -30,7 +30,8 @@ risc0_chunk_aggregator_image_id: "d8cfdd5410c70395c0a1af1842a0148428cc46e353355f # These values modify the bumping behavior after the aggregated proof on-chain submission times out. max_bump_retries: 5 bump_retry_interval_seconds: 120 -bump_increase_fee_multiplier: 1.2 +base_bump_percentage: 10 +retry_attempt_percentage: 2 ecdsa: private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json" From c47fffa5c18ae57bceab0fcd578a1100d16baa9f Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 12 Jan 2026 11:40:22 -0300 Subject: [PATCH 07/16] Wrap the entire proof submission in a result to catch all errors --- .../proof_aggregator/src/backend/mod.rs | 296 ++++++++++-------- 1 file changed, 169 insertions(+), 127 deletions(-) diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index 630b347be..ca8c0f41c 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -336,143 +336,179 @@ impl ProofAggregator { let max_retries = self.config.max_bump_retries; let retry_interval = Duration::from_secs(self.config.bump_retry_interval_seconds); - let base_bump_percentage = self.config.base_bump_percentage; // e.g., 10 - let retry_attempt_percentage = self.config.retry_attempt_percentage; // e.g., 5 + let base_bump_percentage = self.config.base_bump_percentage; + let retry_attempt_percentage = self.config.retry_attempt_percentage; - for attempt in 0..max_retries { - let mut tx_req = match aggregated_proof { - AlignedProof::SP1(proof) => self - .proof_aggregation_service - .verifyAggregationSP1( - blob_versioned_hash.into(), - proof.proof_with_pub_values.public_values.to_vec().into(), - proof.proof_with_pub_values.bytes().into(), - self.sp1_chunk_aggregator_vk_hash_bytes.into(), - ) - .sidecar(blob.clone()) - .into_transaction_request(), - AlignedProof::Risc0(proof) => { - let encoded_seal = encode_seal(&proof.receipt) - .map_err(|e| { - AggregatedProofSubmissionError::Risc0EncodingSeal(e.to_string()) - }) - .map_err(RetryError::Permanent)?; - self.proof_aggregation_service - .verifyAggregationRisc0( - blob_versioned_hash.into(), - encoded_seal.into(), - proof.receipt.journal.bytes.clone().into(), - self.risc0_chunk_aggregator_image_id_bytes.into(), - ) - .sidecar(blob.clone()) - .into_transaction_request() - } - }; - - // Increase gas price/fees for retries before filling - if attempt > 0 { - tx_req = self - .update_gas_fees( - base_bump_percentage, - retry_attempt_percentage, - attempt as u64, - tx_req, - ) - .await?; - } - - let provider = self.proof_aggregation_service.provider(); + let mut last_error: Option = None; - let envelope = provider - .fill(tx_req) - .await - .map_err(|err| { - AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( - err.to_string(), - ) - }) - .map_err(RetryError::Transient)? - .try_into_envelope() - .map_err(|err| { - AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( - err.to_string(), - ) - }) - .map_err(RetryError::Transient)?; - - let tx: EthereumTxEnvelope> = - envelope - .try_into_pooled() - .map_err(|err| { - AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( - err.to_string(), - ) - }) - .map_err(RetryError::Transient)? - .try_map_eip4844(|tx| { - tx.try_map_sidecar(|sidecar| { - sidecar.try_into_7594(EnvKzgSettings::Default.get()) - }) - }) - .map_err(|err| { - AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( - err.to_string(), - ) - }) - .map_err(RetryError::Transient)?; - - let encoded_tx = tx.encoded_2718(); - let pending_tx = provider - .send_raw_transaction(&encoded_tx) - .await - .map_err(|err| { - AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( - err.to_string(), - ) - }) - .map_err(RetryError::Transient)?; + for attempt in 0..max_retries { + info!("Transaction attempt {} of {}", attempt + 1, max_retries); - // Wait for the receipt with timeout - let receipt_result = - tokio::time::timeout(retry_interval, pending_tx.get_receipt()).await; + // Wrap the entire transaction submission in a result to catch all errors + let attempt_result = self + .try_submit_transaction( + &blob, + blob_versioned_hash, + aggregated_proof, + base_bump_percentage, + retry_attempt_percentage, + attempt as u64, + retry_interval, + ) + .await; - match receipt_result { - Ok(Ok(receipt)) => { + match attempt_result { + Ok(receipt) => { info!( "Transaction confirmed successfully on attempt {}", attempt + 1 ); return Ok(receipt); } - Ok(Err(err)) => { - warn!("Error getting receipt on attempt {}: {}", attempt + 1, err); - if attempt == max_retries - 1 { - return Err(RetryError::Transient( - AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( - err.to_string(), - ), - )); - } - } - Err(_) => { - warn!("Transaction not confirmed after {} seconds on attempt {}, retrying with higher fee...", - retry_interval.as_secs(), attempt + 1); - if attempt == max_retries - 1 { - return Err(RetryError::Transient( - AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( - "Transaction timeout after all retries".to_string(), - ), - )); + Err(err) => { + warn!("Attempt {} failed: {:?}", attempt + 1, err); + last_error = Some(err); + + if attempt < max_retries - 1 { + info!("Retrying with bumped gas fees..."); + + tokio::time::sleep(Duration::from_millis(500)).await; + } else { + warn!("Max retries ({}) exceeded", max_retries); } } } } - Err(RetryError::Transient( + // If we exhausted all retries, return the last error + Err(RetryError::Transient(last_error.unwrap_or_else(|| { AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction( - "Max retries exceeded".to_string(), + "Max retries exceeded with no error details".to_string(), + ) + }))) + } + + async fn try_submit_transaction( + &self, + blob: &BlobTransactionSidecar, + blob_versioned_hash: [u8; 32], + aggregated_proof: &AlignedProof, + base_bump_percentage: u64, + retry_attempt_percentage: u64, + attempt: u64, + retry_interval: Duration, + ) -> Result { + // Build the transaction request + let mut tx_req = match aggregated_proof { + AlignedProof::SP1(proof) => self + .proof_aggregation_service + .verifyAggregationSP1( + blob_versioned_hash.into(), + proof.proof_with_pub_values.public_values.to_vec().into(), + proof.proof_with_pub_values.bytes().into(), + self.sp1_chunk_aggregator_vk_hash_bytes.into(), + ) + .sidecar(blob.clone()) + .into_transaction_request(), + AlignedProof::Risc0(proof) => { + let encoded_seal = encode_seal(&proof.receipt).map_err(|e| { + AggregatedProofSubmissionError::Risc0EncodingSeal(e.to_string()) + })?; + self.proof_aggregation_service + .verifyAggregationRisc0( + blob_versioned_hash.into(), + encoded_seal.into(), + proof.receipt.journal.bytes.clone().into(), + self.risc0_chunk_aggregator_image_id_bytes.into(), + ) + .sidecar(blob.clone()) + .into_transaction_request() + } + }; + + // Apply gas fee bump for retries + if attempt > 0 { + tx_req = self + .apply_gas_fee_bump( + base_bump_percentage, + retry_attempt_percentage, + attempt, + tx_req, + ) + .await?; + } + + let provider = self.proof_aggregation_service.provider(); + + // Fill the transaction + let envelope = provider + .fill(tx_req) + .await + .map_err(|err| { + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction(format!( + "Failed to fill transaction: {}", + err + )) + })? + .try_into_envelope() + .map_err(|err| { + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction(format!( + "Failed to convert to envelope: {}", + err + )) + })?; + + // Convert to EIP-4844 transaction + let tx: EthereumTxEnvelope> = envelope + .try_into_pooled() + .map_err(|err| { + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction(format!( + "Failed to pool transaction: {}", + err + )) + })? + .try_map_eip4844(|tx| { + tx.try_map_sidecar(|sidecar| sidecar.try_into_7594(EnvKzgSettings::Default.get())) + }) + .map_err(|err| { + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction(format!( + "Failed to convert to EIP-7594: {}", + err + )) + })?; + + // Send the transaction + let encoded_tx = tx.encoded_2718(); + let pending_tx = provider + .send_raw_transaction(&encoded_tx) + .await + .map_err(|err| { + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction(format!( + "Failed to send raw transaction: {}", + err + )) + })?; + + info!("Transaction sent, waiting for confirmation..."); + + // Wait for the receipt with timeout + let receipt_result = tokio::time::timeout(retry_interval, pending_tx.get_receipt()).await; + + match receipt_result { + Ok(Ok(receipt)) => Ok(receipt), + Ok(Err(err)) => Err( + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction(format!( + "Error getting receipt: {}", + err + )), + ), + Err(_) => Err( + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction(format!( + "Transaction timeout after {} seconds", + retry_interval.as_secs() + )), ), - )) + } } // Updates the gas fees of a `TransactionRequest` for retry attempts by applying a linear fee @@ -487,30 +523,36 @@ impl ProofAggregator { // - `attempt = 3` → 10% + (3 * 5%) = 25% bump // // The bumped price is: current_gas_price * (1 + total_bump_percentage / 100) - async fn update_gas_fees( + async fn apply_gas_fee_bump( &self, base_bump_percentage: u64, retry_attempt_percentage: u64, attempt: u64, tx_req: alloy::rpc::types::TransactionRequest, - ) -> Result> - { + ) -> Result { let provider = self.proof_aggregation_service.provider(); // Calculate total bump percentage: base + (retry_count * retry_attempt) let incremental_retry_percentage = retry_attempt_percentage * attempt; let total_bump_percentage = base_bump_percentage + incremental_retry_percentage; + info!( + "Applying {}% gas fee bump for attempt {}", + total_bump_percentage, + attempt + 1 + ); + let mut current_tx_req = tx_req.clone(); if current_tx_req.max_fee_per_gas.is_none() { - let current_gas_price = provider.get_gas_price().await.map_err(|e| { - RetryError::Transient(AggregatedProofSubmissionError::GasPriceError(e.to_string())) - })?; + let current_gas_price = provider + .get_gas_price() + .await + .map_err(|e| AggregatedProofSubmissionError::GasPriceError(e.to_string()))?; let new_max_fee = Self::calculate_bumped_price(current_gas_price, total_bump_percentage); - let new_priority_fee = new_max_fee / 10; // 10% of max fee + let new_priority_fee = new_max_fee / 10; current_tx_req = current_tx_req .with_max_fee_per_gas(new_max_fee) From 8bed204b7f73098f62a1bbde384696263af9e4e5 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 12 Jan 2026 12:14:09 -0300 Subject: [PATCH 08/16] fix clippy lints --- .../proof_aggregator/src/backend/mod.rs | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index ca8c0f41c..2dc2f495c 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -335,9 +335,6 @@ impl ProofAggregator { info!("Sending proof to ProofAggregationService contract..."); let max_retries = self.config.max_bump_retries; - let retry_interval = Duration::from_secs(self.config.bump_retry_interval_seconds); - let base_bump_percentage = self.config.base_bump_percentage; - let retry_attempt_percentage = self.config.retry_attempt_percentage; let mut last_error: Option = None; @@ -350,10 +347,7 @@ impl ProofAggregator { &blob, blob_versioned_hash, aggregated_proof, - base_bump_percentage, - retry_attempt_percentage, attempt as u64, - retry_interval, ) .await; @@ -393,11 +387,12 @@ impl ProofAggregator { blob: &BlobTransactionSidecar, blob_versioned_hash: [u8; 32], aggregated_proof: &AlignedProof, - base_bump_percentage: u64, - retry_attempt_percentage: u64, attempt: u64, - retry_interval: Duration, ) -> Result { + let retry_interval = Duration::from_secs(self.config.bump_retry_interval_seconds); + let base_bump_percentage = self.config.base_bump_percentage; + let retry_attempt_percentage = self.config.retry_attempt_percentage; + // Build the transaction request let mut tx_req = match aggregated_proof { AlignedProof::SP1(proof) => self @@ -446,15 +441,13 @@ impl ProofAggregator { .await .map_err(|err| { AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction(format!( - "Failed to fill transaction: {}", - err + "Failed to fill transaction: {err}" )) })? .try_into_envelope() .map_err(|err| { AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction(format!( - "Failed to convert to envelope: {}", - err + "Failed to convert to envelope: {err}" )) })?; @@ -463,8 +456,7 @@ impl ProofAggregator { .try_into_pooled() .map_err(|err| { AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction(format!( - "Failed to pool transaction: {}", - err + "Failed to pool transaction: {err}" )) })? .try_map_eip4844(|tx| { @@ -472,8 +464,7 @@ impl ProofAggregator { }) .map_err(|err| { AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction(format!( - "Failed to convert to EIP-7594: {}", - err + "Failed to convert to EIP-7594: {err}" )) })?; @@ -484,8 +475,7 @@ impl ProofAggregator { .await .map_err(|err| { AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction(format!( - "Failed to send raw transaction: {}", - err + "Failed to send raw transaction: {err}" )) })?; @@ -498,8 +488,7 @@ impl ProofAggregator { Ok(Ok(receipt)) => Ok(receipt), Ok(Err(err)) => Err( AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction(format!( - "Error getting receipt: {}", - err + "Error getting receipt: {err}" )), ), Err(_) => Err( From 01d25d6262a143d535ef43e7a4bae204e1893f88 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Mon, 12 Jan 2026 14:51:52 -0300 Subject: [PATCH 09/16] Update the vk hash and image id at proof aggregator config file --- config-files/config-proof-aggregator.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config-files/config-proof-aggregator.yaml b/config-files/config-proof-aggregator.yaml index b3fd9af67..5feb9e232 100644 --- a/config-files/config-proof-aggregator.yaml +++ b/config-files/config-proof-aggregator.yaml @@ -24,8 +24,8 @@ monthly_budget_eth: 15.0 # These program ids are the ones from the chunk aggregator programs # Can be found in the Proof Aggregation Service deployment config # (remember to trim the 0x prefix) -sp1_chunk_aggregator_vk_hash: "00ba19eed0aaeb0151f07b8d3ee7c659bcd29f3021e48fb42766882f55b84509" -risc0_chunk_aggregator_image_id: "d8cfdd5410c70395c0a1af1842a0148428cc46e353355faccfba694dd4862dbf" +sp1_chunk_aggregator_vk_hash: "00d6e32a34f68ea643362b96615591c94ee0bf99ee871740ab2337966a4f77af" +risc0_chunk_aggregator_image_id: "8908f01022827e80a5de71908c16ee44f4a467236df20f62e7c994491629d74c" # These values modify the bumping behavior after the aggregated proof on-chain submission times out. max_bump_retries: 5 From 019e4bbdc653d6f835af69447355b8e30138938b Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 13 Jan 2026 14:11:47 -0300 Subject: [PATCH 10/16] change the logic to have a fixed priority fee in gwei by config --- .../proof_aggregator/src/backend/config.rs | 3 +- .../proof_aggregator/src/backend/mod.rs | 87 ++++++------------- ...fig-proof-aggregator-ethereum-package.yaml | 3 +- config-files/config-proof-aggregator.yaml | 3 +- 4 files changed, 34 insertions(+), 62 deletions(-) diff --git a/aggregation_mode/proof_aggregator/src/backend/config.rs b/aggregation_mode/proof_aggregator/src/backend/config.rs index 94788f01a..deaa39a67 100644 --- a/aggregation_mode/proof_aggregator/src/backend/config.rs +++ b/aggregation_mode/proof_aggregator/src/backend/config.rs @@ -24,7 +24,8 @@ pub struct Config { pub max_bump_retries: u16, pub bump_retry_interval_seconds: u64, pub base_bump_percentage: u64, - pub retry_attempt_percentage: u64, + pub max_fee_bump_percentage: u64, + pub priority_fee_gwei: u128, } impl Config { diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index 2dc2f495c..674a87537 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -25,7 +25,7 @@ use alloy::{ network::{EthereumWallet, TransactionBuilder}, primitives::{utils::parse_ether, Address, U256}, providers::{PendingTransactionError, Provider, ProviderBuilder}, - rpc::types::TransactionReceipt, + rpc::types::{TransactionReceipt, TransactionRequest}, signers::local::LocalSigner, }; use config::Config; @@ -391,7 +391,8 @@ impl ProofAggregator { ) -> Result { let retry_interval = Duration::from_secs(self.config.bump_retry_interval_seconds); let base_bump_percentage = self.config.base_bump_percentage; - let retry_attempt_percentage = self.config.retry_attempt_percentage; + let max_fee_bump_percentage = self.config.max_fee_bump_percentage; + let priority_fee_gwei = self.config.priority_fee_gwei; // Build the transaction request let mut tx_req = match aggregated_proof { @@ -426,8 +427,8 @@ impl ProofAggregator { tx_req = self .apply_gas_fee_bump( base_bump_percentage, - retry_attempt_percentage, - attempt, + max_fee_bump_percentage, + priority_fee_gwei, tx_req, ) .await?; @@ -500,70 +501,38 @@ impl ProofAggregator { } } - // Updates the gas fees of a `TransactionRequest` for retry attempts by applying a linear fee - // bump based on the retry number. This method is intended to be used when a previous transaction - // attempt was not confirmed (e.g. receipt timeout or transient failure). + // Updates the gas fees of a `TransactionRequest` using a fixed bump strategy. + // Intended for retrying an on-chain submission after a timeout. // - // Fee strategy (similar to Go implementation): - // The bump is calculated as: base_bump_percentage + (retry_count * retry_attempt_percentage) - // For example, with `base_bump_percentage = 10` and `retry_attempt_percentage = 5`: - // - `attempt = 1` → 10% + (1 * 5%) = 15% bump - // - `attempt = 2` → 10% + (2 * 5%) = 20% bump - // - `attempt = 3` → 10% + (3 * 5%) = 25% bump + // Strategy: + // - Fetch the current network gas price. + // - Apply `base_bump_percentage` to compute a bumped base fee. + // - Apply `max_fee_bump_percentage` on top of the bumped base fee to set `max_fee_per_gas`. + // - Set `max_priority_fee_per_gas` to a fixed value derived from `priority_fee_gwei`. // - // The bumped price is: current_gas_price * (1 + total_bump_percentage / 100) + // Fees are recomputed on each retry using the latest gas price (no incremental per-attempt bump). + async fn apply_gas_fee_bump( &self, base_bump_percentage: u64, - retry_attempt_percentage: u64, - attempt: u64, - tx_req: alloy::rpc::types::TransactionRequest, - ) -> Result { + max_fee_bump_percentage: u64, + priority_fee_gwei: u128, + tx_req: TransactionRequest, + ) -> Result { let provider = self.proof_aggregation_service.provider(); - // Calculate total bump percentage: base + (retry_count * retry_attempt) - let incremental_retry_percentage = retry_attempt_percentage * attempt; - let total_bump_percentage = base_bump_percentage + incremental_retry_percentage; - - info!( - "Applying {}% gas fee bump for attempt {}", - total_bump_percentage, - attempt + 1 - ); - - let mut current_tx_req = tx_req.clone(); - - if current_tx_req.max_fee_per_gas.is_none() { - let current_gas_price = provider - .get_gas_price() - .await - .map_err(|e| AggregatedProofSubmissionError::GasPriceError(e.to_string()))?; - - let new_max_fee = - Self::calculate_bumped_price(current_gas_price, total_bump_percentage); - let new_priority_fee = new_max_fee / 10; - - current_tx_req = current_tx_req - .with_max_fee_per_gas(new_max_fee) - .with_max_priority_fee_per_gas(new_priority_fee); - } else { - if let Some(max_fee) = current_tx_req.max_fee_per_gas { - let new_max_fee = Self::calculate_bumped_price(max_fee, total_bump_percentage); - current_tx_req = current_tx_req.with_max_fee_per_gas(new_max_fee); - } - if let Some(priority_fee) = current_tx_req.max_priority_fee_per_gas { - let new_priority_fee = - Self::calculate_bumped_price(priority_fee, total_bump_percentage); - current_tx_req = current_tx_req.with_max_priority_fee_per_gas(new_priority_fee); - } - } + let current_gas_price = provider + .get_gas_price() + .await + .map_err(|e| AggregatedProofSubmissionError::GasPriceError(e.to_string()))?; - Ok(current_tx_req) - } + let new_base_fee = current_gas_price * (1 + base_bump_percentage as u128 / 100); + let new_max_fee = new_base_fee * (1 + max_fee_bump_percentage as u128 / 100); + let new_priority_fee = priority_fee_gwei * 1000000000; // Convert to wei - fn calculate_bumped_price(current_price: u128, total_bump_percentage: u64) -> u128 { - let bump_amount = (current_price * total_bump_percentage as u128) / 100; - current_price + bump_amount + Ok(tx_req + .with_max_fee_per_gas(new_max_fee) + .with_max_priority_fee_per_gas(new_priority_fee)) } async fn wait_until_can_submit_aggregated_proof( diff --git a/config-files/config-proof-aggregator-ethereum-package.yaml b/config-files/config-proof-aggregator-ethereum-package.yaml index 3f594d7d8..0ec4f9b78 100644 --- a/config-files/config-proof-aggregator-ethereum-package.yaml +++ b/config-files/config-proof-aggregator-ethereum-package.yaml @@ -31,7 +31,8 @@ risc0_chunk_aggregator_image_id: "8908f01022827e80a5de71908c16ee44f4a467236df20f max_bump_retries: 5 bump_retry_interval_seconds: 120 base_bump_percentage: 10 -retry_attempt_percentage: 2 +max_fee_bump_percentage: 100 +priority_fee_gwei: 2 ecdsa: private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json" diff --git a/config-files/config-proof-aggregator.yaml b/config-files/config-proof-aggregator.yaml index 5feb9e232..86a080034 100644 --- a/config-files/config-proof-aggregator.yaml +++ b/config-files/config-proof-aggregator.yaml @@ -31,7 +31,8 @@ risc0_chunk_aggregator_image_id: "8908f01022827e80a5de71908c16ee44f4a467236df20f max_bump_retries: 5 bump_retry_interval_seconds: 120 base_bump_percentage: 10 -retry_attempt_percentage: 2 +max_fee_bump_percentage: 100 +priority_fee_gwei: 2 ecdsa: private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json" From 2e1dfcecf065f4d0e7199ebe63e2893ad5d3e565 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 13 Jan 2026 15:10:56 -0300 Subject: [PATCH 11/16] handle the same nonce for the transaction on bumps --- .../proof_aggregator/src/backend/mod.rs | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index 674a87537..4c97fcb8d 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -338,16 +338,34 @@ impl ProofAggregator { let mut last_error: Option = None; + // Get the nonce once at the beginning and reuse it for all retries + let nonce = self + .proof_aggregation_service + .provider() + .get_transaction_count(*self.proof_aggregation_service.address()) + .await + .map_err(|e| { + RetryError::Transient( + AggregatedProofSubmissionError::SendVerifyAggregatedProofTransaction(format!( + "Failed to get nonce: {e}" + )), + ) + })?; + + info!("Using nonce {} for all retry attempts", nonce); + for attempt in 0..max_retries { info!("Transaction attempt {} of {}", attempt + 1, max_retries); - // Wrap the entire transaction submission in a result to catch all errors + // Wrap the entire transaction submission in a result to catch all errors, passing + // the same nonce to all attempts let attempt_result = self .try_submit_transaction( &blob, blob_versioned_hash, aggregated_proof, attempt as u64, + nonce, ) .await; @@ -364,7 +382,7 @@ impl ProofAggregator { last_error = Some(err); if attempt < max_retries - 1 { - info!("Retrying with bumped gas fees..."); + info!("Retrying with bumped gas fees and same nonce {}...", nonce); tokio::time::sleep(Duration::from_millis(500)).await; } else { @@ -388,6 +406,7 @@ impl ProofAggregator { blob_versioned_hash: [u8; 32], aggregated_proof: &AlignedProof, attempt: u64, + nonce: u64, ) -> Result { let retry_interval = Duration::from_secs(self.config.bump_retry_interval_seconds); let base_bump_percentage = self.config.base_bump_percentage; @@ -422,6 +441,9 @@ impl ProofAggregator { } }; + // Set the nonce explicitly + tx_req = tx_req.with_nonce(nonce); + // Apply gas fee bump for retries if attempt > 0 { tx_req = self @@ -480,7 +502,10 @@ impl ProofAggregator { )) })?; - info!("Transaction sent, waiting for confirmation..."); + info!( + "Transaction sent with nonce {}, waiting for confirmation...", + nonce + ); // Wait for the receipt with timeout let receipt_result = tokio::time::timeout(retry_interval, pending_tx.get_receipt()).await; From c5c06c5dad00bb9177eecec26bc2116cc3e2cfae Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 13 Jan 2026 15:34:58 -0300 Subject: [PATCH 12/16] change the priority fee value to be a number in wei as it can be represented in u128 entirely --- .../proof_aggregator/src/backend/config.rs | 2 +- aggregation_mode/proof_aggregator/src/backend/mod.rs | 10 +++++----- .../config-proof-aggregator-ethereum-package.yaml | 2 +- config-files/config-proof-aggregator.yaml | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/aggregation_mode/proof_aggregator/src/backend/config.rs b/aggregation_mode/proof_aggregator/src/backend/config.rs index deaa39a67..3e6e1b11c 100644 --- a/aggregation_mode/proof_aggregator/src/backend/config.rs +++ b/aggregation_mode/proof_aggregator/src/backend/config.rs @@ -25,7 +25,7 @@ pub struct Config { pub bump_retry_interval_seconds: u64, pub base_bump_percentage: u64, pub max_fee_bump_percentage: u64, - pub priority_fee_gwei: u128, + pub priority_fee_wei: u128, } impl Config { diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index 4c97fcb8d..51bc9dd0a 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -411,7 +411,7 @@ impl ProofAggregator { let retry_interval = Duration::from_secs(self.config.bump_retry_interval_seconds); let base_bump_percentage = self.config.base_bump_percentage; let max_fee_bump_percentage = self.config.max_fee_bump_percentage; - let priority_fee_gwei = self.config.priority_fee_gwei; + let priority_fee_wei = self.config.priority_fee_wei; // Build the transaction request let mut tx_req = match aggregated_proof { @@ -450,7 +450,7 @@ impl ProofAggregator { .apply_gas_fee_bump( base_bump_percentage, max_fee_bump_percentage, - priority_fee_gwei, + priority_fee_wei, tx_req, ) .await?; @@ -533,7 +533,7 @@ impl ProofAggregator { // - Fetch the current network gas price. // - Apply `base_bump_percentage` to compute a bumped base fee. // - Apply `max_fee_bump_percentage` on top of the bumped base fee to set `max_fee_per_gas`. - // - Set `max_priority_fee_per_gas` to a fixed value derived from `priority_fee_gwei`. + // - Set `max_priority_fee_per_gas` to a fixed value derived from `priority_fee_wei`. // // Fees are recomputed on each retry using the latest gas price (no incremental per-attempt bump). @@ -541,7 +541,7 @@ impl ProofAggregator { &self, base_bump_percentage: u64, max_fee_bump_percentage: u64, - priority_fee_gwei: u128, + priority_fee_wei: u128, tx_req: TransactionRequest, ) -> Result { let provider = self.proof_aggregation_service.provider(); @@ -553,7 +553,7 @@ impl ProofAggregator { let new_base_fee = current_gas_price * (1 + base_bump_percentage as u128 / 100); let new_max_fee = new_base_fee * (1 + max_fee_bump_percentage as u128 / 100); - let new_priority_fee = priority_fee_gwei * 1000000000; // Convert to wei + let new_priority_fee = priority_fee_wei; Ok(tx_req .with_max_fee_per_gas(new_max_fee) diff --git a/config-files/config-proof-aggregator-ethereum-package.yaml b/config-files/config-proof-aggregator-ethereum-package.yaml index 0ec4f9b78..124a3cae3 100644 --- a/config-files/config-proof-aggregator-ethereum-package.yaml +++ b/config-files/config-proof-aggregator-ethereum-package.yaml @@ -32,7 +32,7 @@ max_bump_retries: 5 bump_retry_interval_seconds: 120 base_bump_percentage: 10 max_fee_bump_percentage: 100 -priority_fee_gwei: 2 +priority_fee_wei: 2000000000 ecdsa: private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json" diff --git a/config-files/config-proof-aggregator.yaml b/config-files/config-proof-aggregator.yaml index 86a080034..9eba16206 100644 --- a/config-files/config-proof-aggregator.yaml +++ b/config-files/config-proof-aggregator.yaml @@ -32,7 +32,7 @@ max_bump_retries: 5 bump_retry_interval_seconds: 120 base_bump_percentage: 10 max_fee_bump_percentage: 100 -priority_fee_gwei: 2 +priority_fee_wei: 2000000000 ecdsa: private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json" From c2fdc66378517094d2fadeb563b1c2c37346fc1d Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 13 Jan 2026 18:16:31 -0300 Subject: [PATCH 13/16] fix: use float values to avoid lossing presicion on operation --- aggregation_mode/proof_aggregator/src/backend/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index 51bc9dd0a..cbf885f21 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -551,13 +551,13 @@ impl ProofAggregator { .await .map_err(|e| AggregatedProofSubmissionError::GasPriceError(e.to_string()))?; - let new_base_fee = current_gas_price * (1 + base_bump_percentage as u128 / 100); - let new_max_fee = new_base_fee * (1 + max_fee_bump_percentage as u128 / 100); + let new_base_fee = current_gas_price as f64 * (1.0 + base_bump_percentage as f64 / 100.0); + let new_max_fee = new_base_fee as f64 * (1.0 + max_fee_bump_percentage as f64 / 100.0); let new_priority_fee = priority_fee_wei; Ok(tx_req - .with_max_fee_per_gas(new_max_fee) - .with_max_priority_fee_per_gas(new_priority_fee)) + .with_max_fee_per_gas(new_max_fee as u128) + .with_max_priority_fee_per_gas(new_priority_fee as u128)) } async fn wait_until_can_submit_aggregated_proof( From ea3779f7b7493dd8ee049eeef8744ae51cf2722f Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 13 Jan 2026 18:17:09 -0300 Subject: [PATCH 14/16] fix: use the right address when obtaining the tx nonce --- aggregation_mode/proof_aggregator/src/backend/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index cbf885f21..abbe405e8 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -24,7 +24,7 @@ use alloy::{ hex, network::{EthereumWallet, TransactionBuilder}, primitives::{utils::parse_ether, Address, U256}, - providers::{PendingTransactionError, Provider, ProviderBuilder}, + providers::{PendingTransactionError, Provider, ProviderBuilder, WalletProvider}, rpc::types::{TransactionReceipt, TransactionRequest}, signers::local::LocalSigner, }; @@ -342,7 +342,11 @@ impl ProofAggregator { let nonce = self .proof_aggregation_service .provider() - .get_transaction_count(*self.proof_aggregation_service.address()) + .get_transaction_count( + self.proof_aggregation_service + .provider() + .default_signer_address(), + ) .await .map_err(|e| { RetryError::Transient( From c4914e2c522402d38f5dba9833f2bac2a48b8a49 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 13 Jan 2026 18:17:34 -0300 Subject: [PATCH 15/16] also set the base fee to the tx request (gas_price field) --- aggregation_mode/proof_aggregator/src/backend/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index abbe405e8..0b9f5e47a 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -560,6 +560,9 @@ impl ProofAggregator { let new_priority_fee = priority_fee_wei; Ok(tx_req + // In TransactionRequest docs the gas_price field is defined as + // "The max base fee per gas the sender is willing to pay." + .with_gas_price(new_base_fee as u128) .with_max_fee_per_gas(new_max_fee as u128) .with_max_priority_fee_per_gas(new_priority_fee as u128)) } From bb309a41f02de7dbd40c6af49c615ce893d68e71 Mon Sep 17 00:00:00 2001 From: maximopalopoli Date: Tue, 13 Jan 2026 18:45:06 -0300 Subject: [PATCH 16/16] fix clippy lints --- aggregation_mode/proof_aggregator/src/backend/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aggregation_mode/proof_aggregator/src/backend/mod.rs b/aggregation_mode/proof_aggregator/src/backend/mod.rs index 0b9f5e47a..8f452123a 100644 --- a/aggregation_mode/proof_aggregator/src/backend/mod.rs +++ b/aggregation_mode/proof_aggregator/src/backend/mod.rs @@ -556,7 +556,7 @@ impl ProofAggregator { .map_err(|e| AggregatedProofSubmissionError::GasPriceError(e.to_string()))?; let new_base_fee = current_gas_price as f64 * (1.0 + base_bump_percentage as f64 / 100.0); - let new_max_fee = new_base_fee as f64 * (1.0 + max_fee_bump_percentage as f64 / 100.0); + let new_max_fee = new_base_fee * (1.0 + max_fee_bump_percentage as f64 / 100.0); let new_priority_fee = priority_fee_wei; Ok(tx_req @@ -564,7 +564,7 @@ impl ProofAggregator { // "The max base fee per gas the sender is willing to pay." .with_gas_price(new_base_fee as u128) .with_max_fee_per_gas(new_max_fee as u128) - .with_max_priority_fee_per_gas(new_priority_fee as u128)) + .with_max_priority_fee_per_gas(new_priority_fee)) } async fn wait_until_can_submit_aggregated_proof(