From 93b7b3424fb280ee7248f9629df823510c7af1fb Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Fri, 30 May 2025 10:25:10 -0300 Subject: [PATCH 1/3] feat: limit the number of proofs to fetch --- aggregation_mode/src/backend/config.rs | 1 + aggregation_mode/src/backend/fetcher.rs | 21 +++++++++++++++++---- aggregation_mode/src/backend/mod.rs | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/aggregation_mode/src/backend/config.rs b/aggregation_mode/src/backend/config.rs index 0fb47d2775..c56c02aaf2 100644 --- a/aggregation_mode/src/backend/config.rs +++ b/aggregation_mode/src/backend/config.rs @@ -22,6 +22,7 @@ pub struct Config { pub last_aggregated_block_filepath: String, pub ecdsa: ECDSAConfig, pub proofs_per_chunk: u16, + pub total_proofs_limit: u16, } impl Config { diff --git a/aggregation_mode/src/backend/fetcher.rs b/aggregation_mode/src/backend/fetcher.rs index b264c50217..8f9a470cac 100644 --- a/aggregation_mode/src/backend/fetcher.rs +++ b/aggregation_mode/src/backend/fetcher.rs @@ -55,6 +55,7 @@ impl ProofsFetcher { pub async fn fetch( &mut self, engine: ZKVMEngine, + limit: u16, ) -> Result, ProofsFetcherError> { // Get current block let current_block = self @@ -86,12 +87,9 @@ impl ProofsFetcher { info!("Logs collected {}", logs.len()); - // Update last processed block after collecting logs - self.last_aggregated_block = current_block; - let mut proofs = vec![]; - for (batch, _) in logs { + for (batch, log) in logs { info!( "New batch submitted, about to process. Batch merkle root {}...", batch.batchMerkleRoot @@ -153,6 +151,18 @@ impl ProofsFetcher { proofs_to_add.len() ); + if (proofs.len() + proofs_to_add.len()) > (limit as usize) { + let log_block_number = log.block_number.unwrap(); + info!( + "Limit of {} proofs reached, stopping at block number {}, which is {} from current block", + limit, log_block_number, current_block - log_block_number + ); + // Update last processed block to this log block number + // So the next aggregation starts at this block + self.last_aggregated_block = log_block_number; + return Ok(proofs); + } + // try to add them to the queue for proof in proofs_to_add { if let Err(err) = proof.verify() { @@ -164,6 +174,9 @@ impl ProofsFetcher { } } + // Update last processed block after collecting logs + self.last_aggregated_block = current_block; + Ok(proofs) } diff --git a/aggregation_mode/src/backend/mod.rs b/aggregation_mode/src/backend/mod.rs index b240cd716e..f9abf49d7a 100644 --- a/aggregation_mode/src/backend/mod.rs +++ b/aggregation_mode/src/backend/mod.rs @@ -97,7 +97,7 @@ impl ProofAggregator { ) -> Result<(), AggregatedProofSubmissionError> { let proofs = self .fetcher - .fetch(self.engine.clone()) + .fetch(self.engine.clone(), self.config.total_proofs_limit) .await .map_err(AggregatedProofSubmissionError::FetchingProofs)?; From 5fe0d4fbb45feafc0a7021efbcc71972f1aeb213 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Fri, 30 May 2025 10:26:13 -0300 Subject: [PATCH 2/3] chore: update config files --- config-files/config-proof-aggregator-ethereum-package.yaml | 5 +++++ .../config-proof-aggregator-mock-ethereum-package.yaml | 5 +++++ config-files/config-proof-aggregator-mock.yaml | 5 +++++ config-files/config-proof-aggregator.yaml | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/config-files/config-proof-aggregator-ethereum-package.yaml b/config-files/config-proof-aggregator-ethereum-package.yaml index 73f3f94305..93add6e9d1 100644 --- a/config-files/config-proof-aggregator-ethereum-package.yaml +++ b/config-files/config-proof-aggregator-ethereum-package.yaml @@ -5,6 +5,11 @@ eth_ws_url: "ws://localhost:8546" max_proofs_in_queue: 1000 last_aggregated_block_filepath: config-files/proof-aggregator.last_aggregated_block.json proofs_per_chunk: 512 # Amount of proofs to process per chunk +# This number comes from the blob data limit +# Since each blob has a capacity of (4096 * 32) = 131.072 bytes +# Since each proof commitments takes 32 bytes hash + 1 byte for padding +# We can aggregate as much proofs as 131.072 / 33 ~= 3971 per blob +total_proofs_limit: 3970 ecdsa: private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json" diff --git a/config-files/config-proof-aggregator-mock-ethereum-package.yaml b/config-files/config-proof-aggregator-mock-ethereum-package.yaml index e805af2b86..6417ad32e0 100644 --- a/config-files/config-proof-aggregator-mock-ethereum-package.yaml +++ b/config-files/config-proof-aggregator-mock-ethereum-package.yaml @@ -5,6 +5,11 @@ eth_ws_url: "ws://localhost:8546" max_proofs_in_queue: 1000 last_aggregated_block_filepath: config-files/proof-aggregator.last_aggregated_block.json proofs_per_chunk: 512 # Amount of proofs to process per chunk +# This number comes from the blob data limit +# Since each blob has a capacity of (4096 * 32) = 131.072 bytes +# Since each proof commitments takes 32 bytes hash + 1 byte for padding +# We can aggregate as much proofs as 131.072 / 33 ~= 3971 per blob +total_proofs_limit: 3970 ecdsa: private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json" diff --git a/config-files/config-proof-aggregator-mock.yaml b/config-files/config-proof-aggregator-mock.yaml index 644ed44b9c..4393fe8ee4 100644 --- a/config-files/config-proof-aggregator-mock.yaml +++ b/config-files/config-proof-aggregator-mock.yaml @@ -5,6 +5,11 @@ eth_ws_url: "ws://localhost:8545" max_proofs_in_queue: 1000 last_aggregated_block_filepath: config-files/proof-aggregator.last_aggregated_block.json proofs_per_chunk: 512 # Amount of proofs to process per chunk +# This number comes from the blob data limit +# Since each blob has a capacity of (4096 * 32) = 131.072 bytes +# Since each proof commitments takes 32 bytes hash + 1 byte for padding +# We can aggregate as much proofs as 131.072 / 33 ~= 3971 per blob +total_proofs_limit: 3970 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 f60b9dc902..a3c2e613f1 100644 --- a/config-files/config-proof-aggregator.yaml +++ b/config-files/config-proof-aggregator.yaml @@ -5,6 +5,11 @@ eth_ws_url: "ws://localhost:8545" max_proofs_in_queue: 1000 last_aggregated_block_filepath: config-files/proof-aggregator.last_aggregated_block.json proofs_per_chunk: 512 # Amount of proofs to process per chunk +# This number comes from the blob data limit +# Since each blob has a capacity of (4096 * 32) = 131.072 bytes +# Since each proof commitments takes 32 bytes hash + 1 byte for padding +# We can aggregate as much proofs as 131.072 / 33 ~= 3971 per blob +total_proofs_limit: 3970 ecdsa: private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json" From c9d5e78720d561e24feae3e28e9bc584881c87e9 Mon Sep 17 00:00:00 2001 From: Marcos Nicolau Date: Fri, 30 May 2025 18:04:57 -0300 Subject: [PATCH 3/3] chore: update config files proofs limit --- .../config-proof-aggregator-ethereum-package.yaml | 8 +++++--- .../config-proof-aggregator-mock-ethereum-package.yaml | 9 ++++++--- config-files/config-proof-aggregator-mock.yaml | 9 ++++++--- config-files/config-proof-aggregator.yaml | 9 ++++++--- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/config-files/config-proof-aggregator-ethereum-package.yaml b/config-files/config-proof-aggregator-ethereum-package.yaml index 93add6e9d1..00692ec0ff 100644 --- a/config-files/config-proof-aggregator-ethereum-package.yaml +++ b/config-files/config-proof-aggregator-ethereum-package.yaml @@ -7,9 +7,11 @@ last_aggregated_block_filepath: config-files/proof-aggregator.last_aggregated_bl proofs_per_chunk: 512 # Amount of proofs to process per chunk # This number comes from the blob data limit # Since each blob has a capacity of (4096 * 32) = 131.072 bytes -# Since each proof commitments takes 32 bytes hash + 1 byte for padding -# We can aggregate as much proofs as 131.072 / 33 ~= 3971 per blob -total_proofs_limit: 3970 +# But to not surpass the field modulus we pad with a 0xo byte so we have (4096 * 31) = 126.976 bytes +# of usable data +# Since each proof commitments takes 32 bytes hash +# We can aggregate as much proofs as 126.976 / 32 = 3968 per blob +total_proofs_limit: 3968 ecdsa: private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json" diff --git a/config-files/config-proof-aggregator-mock-ethereum-package.yaml b/config-files/config-proof-aggregator-mock-ethereum-package.yaml index 6417ad32e0..0effe2823e 100644 --- a/config-files/config-proof-aggregator-mock-ethereum-package.yaml +++ b/config-files/config-proof-aggregator-mock-ethereum-package.yaml @@ -7,9 +7,12 @@ last_aggregated_block_filepath: config-files/proof-aggregator.last_aggregated_bl proofs_per_chunk: 512 # Amount of proofs to process per chunk # This number comes from the blob data limit # Since each blob has a capacity of (4096 * 32) = 131.072 bytes -# Since each proof commitments takes 32 bytes hash + 1 byte for padding -# We can aggregate as much proofs as 131.072 / 33 ~= 3971 per blob -total_proofs_limit: 3970 +# But to not surpass the field modulus we pad with a 0xo byte so we have (4096 * 31) = 126.976 bytes +# of usable data +# Since each proof commitments takes 32 bytes hash +# We can aggregate as much proofs as 126.976 / 32 = 3968 per blob +total_proofs_limit: 3968 + ecdsa: private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json" diff --git a/config-files/config-proof-aggregator-mock.yaml b/config-files/config-proof-aggregator-mock.yaml index 4393fe8ee4..35451eee27 100644 --- a/config-files/config-proof-aggregator-mock.yaml +++ b/config-files/config-proof-aggregator-mock.yaml @@ -7,9 +7,12 @@ last_aggregated_block_filepath: config-files/proof-aggregator.last_aggregated_bl proofs_per_chunk: 512 # Amount of proofs to process per chunk # This number comes from the blob data limit # Since each blob has a capacity of (4096 * 32) = 131.072 bytes -# Since each proof commitments takes 32 bytes hash + 1 byte for padding -# We can aggregate as much proofs as 131.072 / 33 ~= 3971 per blob -total_proofs_limit: 3970 +# But to not surpass the field modulus we pad with a 0xo byte so we have (4096 * 31) = 126.976 bytes +# of usable data +# Since each proof commitments takes 32 bytes hash +# We can aggregate as much proofs as 126.976 / 32 = 3968 per blob +total_proofs_limit: 3968 + 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 a3c2e613f1..6ac560bf91 100644 --- a/config-files/config-proof-aggregator.yaml +++ b/config-files/config-proof-aggregator.yaml @@ -7,9 +7,12 @@ last_aggregated_block_filepath: config-files/proof-aggregator.last_aggregated_bl proofs_per_chunk: 512 # Amount of proofs to process per chunk # This number comes from the blob data limit # Since each blob has a capacity of (4096 * 32) = 131.072 bytes -# Since each proof commitments takes 32 bytes hash + 1 byte for padding -# We can aggregate as much proofs as 131.072 / 33 ~= 3971 per blob -total_proofs_limit: 3970 +# But to not surpass the field modulus we pad with a 0xo byte so we have (4096 * 31) = 126.976 bytes +# of usable data +# Since each proof commitments takes 32 bytes hash +# We can aggregate as much proofs as 126.976 / 32 = 3968 per blob +total_proofs_limit: 3968 + ecdsa: private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"