Skip to content

Commit 703f766

Browse files
feat(aggregation-mode): limit number of proofs to fetch (#1956)
1 parent b39a038 commit 703f766

7 files changed

Lines changed: 50 additions & 5 deletions

aggregation_mode/src/backend/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct Config {
2222
pub last_aggregated_block_filepath: String,
2323
pub ecdsa: ECDSAConfig,
2424
pub proofs_per_chunk: u16,
25+
pub total_proofs_limit: u16,
2526
}
2627

2728
impl Config {

aggregation_mode/src/backend/fetcher.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl ProofsFetcher {
5555
pub async fn fetch(
5656
&mut self,
5757
engine: ZKVMEngine,
58+
limit: u16,
5859
) -> Result<Vec<AlignedProof>, ProofsFetcherError> {
5960
// Get current block
6061
let current_block = self
@@ -86,12 +87,9 @@ impl ProofsFetcher {
8687

8788
info!("Logs collected {}", logs.len());
8889

89-
// Update last processed block after collecting logs
90-
self.last_aggregated_block = current_block;
91-
9290
let mut proofs = vec![];
9391

94-
for (batch, _) in logs {
92+
for (batch, log) in logs {
9593
info!(
9694
"New batch submitted, about to process. Batch merkle root {}...",
9795
batch.batchMerkleRoot
@@ -153,6 +151,18 @@ impl ProofsFetcher {
153151
proofs_to_add.len()
154152
);
155153

154+
if (proofs.len() + proofs_to_add.len()) > (limit as usize) {
155+
let log_block_number = log.block_number.unwrap();
156+
info!(
157+
"Limit of {} proofs reached, stopping at block number {}, which is {} from current block",
158+
limit, log_block_number, current_block - log_block_number
159+
);
160+
// Update last processed block to this log block number
161+
// So the next aggregation starts at this block
162+
self.last_aggregated_block = log_block_number;
163+
return Ok(proofs);
164+
}
165+
156166
// try to add them to the queue
157167
for proof in proofs_to_add {
158168
if let Err(err) = proof.verify() {
@@ -164,6 +174,9 @@ impl ProofsFetcher {
164174
}
165175
}
166176

177+
// Update last processed block after collecting logs
178+
self.last_aggregated_block = current_block;
179+
167180
Ok(proofs)
168181
}
169182

aggregation_mode/src/backend/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl ProofAggregator {
9797
) -> Result<(), AggregatedProofSubmissionError> {
9898
let proofs = self
9999
.fetcher
100-
.fetch(self.engine.clone())
100+
.fetch(self.engine.clone(), self.config.total_proofs_limit)
101101
.await
102102
.map_err(AggregatedProofSubmissionError::FetchingProofs)?;
103103

config-files/config-proof-aggregator-ethereum-package.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ eth_ws_url: "ws://localhost:8546"
55
max_proofs_in_queue: 1000
66
last_aggregated_block_filepath: config-files/proof-aggregator.last_aggregated_block.json
77
proofs_per_chunk: 512 # Amount of proofs to process per chunk
8+
# This number comes from the blob data limit
9+
# Since each blob has a capacity of (4096 * 32) = 131.072 bytes
10+
# But to not surpass the field modulus we pad with a 0xo byte so we have (4096 * 31) = 126.976 bytes
11+
# of usable data
12+
# Since each proof commitments takes 32 bytes hash
13+
# We can aggregate as much proofs as 126.976 / 32 = 3968 per blob
14+
total_proofs_limit: 3968
815

916
ecdsa:
1017
private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"

config-files/config-proof-aggregator-mock-ethereum-package.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ eth_ws_url: "ws://localhost:8546"
55
max_proofs_in_queue: 1000
66
last_aggregated_block_filepath: config-files/proof-aggregator.last_aggregated_block.json
77
proofs_per_chunk: 512 # Amount of proofs to process per chunk
8+
# This number comes from the blob data limit
9+
# Since each blob has a capacity of (4096 * 32) = 131.072 bytes
10+
# But to not surpass the field modulus we pad with a 0xo byte so we have (4096 * 31) = 126.976 bytes
11+
# of usable data
12+
# Since each proof commitments takes 32 bytes hash
13+
# We can aggregate as much proofs as 126.976 / 32 = 3968 per blob
14+
total_proofs_limit: 3968
15+
816

917
ecdsa:
1018
private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"

config-files/config-proof-aggregator-mock.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ eth_ws_url: "ws://localhost:8545"
55
max_proofs_in_queue: 1000
66
last_aggregated_block_filepath: config-files/proof-aggregator.last_aggregated_block.json
77
proofs_per_chunk: 512 # Amount of proofs to process per chunk
8+
# This number comes from the blob data limit
9+
# Since each blob has a capacity of (4096 * 32) = 131.072 bytes
10+
# But to not surpass the field modulus we pad with a 0xo byte so we have (4096 * 31) = 126.976 bytes
11+
# of usable data
12+
# Since each proof commitments takes 32 bytes hash
13+
# We can aggregate as much proofs as 126.976 / 32 = 3968 per blob
14+
total_proofs_limit: 3968
15+
816

917
ecdsa:
1018
private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"

config-files/config-proof-aggregator.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ eth_ws_url: "ws://localhost:8545"
55
max_proofs_in_queue: 1000
66
last_aggregated_block_filepath: config-files/proof-aggregator.last_aggregated_block.json
77
proofs_per_chunk: 512 # Amount of proofs to process per chunk
8+
# This number comes from the blob data limit
9+
# Since each blob has a capacity of (4096 * 32) = 131.072 bytes
10+
# But to not surpass the field modulus we pad with a 0xo byte so we have (4096 * 31) = 126.976 bytes
11+
# of usable data
12+
# Since each proof commitments takes 32 bytes hash
13+
# We can aggregate as much proofs as 126.976 / 32 = 3968 per blob
14+
total_proofs_limit: 3968
15+
816

917
ecdsa:
1018
private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"

0 commit comments

Comments
 (0)