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)?; diff --git a/config-files/config-proof-aggregator-ethereum-package.yaml b/config-files/config-proof-aggregator-ethereum-package.yaml index 73f3f94305..00692ec0ff 100644 --- a/config-files/config-proof-aggregator-ethereum-package.yaml +++ b/config-files/config-proof-aggregator-ethereum-package.yaml @@ -5,6 +5,13 @@ 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 +# 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 e805af2b86..0effe2823e 100644 --- a/config-files/config-proof-aggregator-mock-ethereum-package.yaml +++ b/config-files/config-proof-aggregator-mock-ethereum-package.yaml @@ -5,6 +5,14 @@ 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 +# 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 644ed44b9c..35451eee27 100644 --- a/config-files/config-proof-aggregator-mock.yaml +++ b/config-files/config-proof-aggregator-mock.yaml @@ -5,6 +5,14 @@ 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 +# 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 f60b9dc902..6ac560bf91 100644 --- a/config-files/config-proof-aggregator.yaml +++ b/config-files/config-proof-aggregator.yaml @@ -5,6 +5,14 @@ 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 +# 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"