Skip to content

Commit 46ebd22

Browse files
committed
feat: proofs per chunk as a config param instead of const
1 parent 42febf2 commit 46ebd22

File tree

8 files changed

+23
-15
lines changed

8 files changed

+23
-15
lines changed

aggregation_mode/src/aggregators/mod.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ use sp1_aggregator::{
1313
};
1414
use tracing::info;
1515

16-
const MAX_PROOFS_PER_AGGREGATION: usize = 512;
17-
1816
#[derive(Clone, Debug)]
1917
pub enum ZKVMEngine {
2018
SP1,
@@ -63,6 +61,7 @@ impl ZKVMEngine {
6361
pub fn aggregate_proofs(
6462
&self,
6563
proofs: Vec<AlignedProof>,
64+
proofs_per_chunk: u16,
6665
) -> Result<(AlignedProof, [u8; 32]), ProofAggregationError> {
6766
let res = match self {
6867
ZKVMEngine::SP1 => {
@@ -77,11 +76,12 @@ impl ZKVMEngine {
7776
})
7877
.collect();
7978

80-
let chunks = proofs.chunks(MAX_PROOFS_PER_AGGREGATION);
79+
let chunks = proofs.chunks(proofs_per_chunk as usize);
8180
info!(
82-
"Total proofs to aggregate {}. They aggregation will be performed in {} chunks",
81+
"Total proofs to aggregate {}. They aggregation will be performed in {} chunks (i.e {} proofs per chunk)",
8382
proofs.len(),
84-
chunks.len()
83+
chunks.len(),
84+
proofs_per_chunk,
8585
);
8686

8787
let mut agg_proofs: Vec<(SP1ProofWithPubValuesAndElf, Vec<[u8; 32]>)> = vec![];
@@ -118,11 +118,12 @@ impl ZKVMEngine {
118118
})
119119
.collect();
120120

121-
let chunks = proofs.chunks(MAX_PROOFS_PER_AGGREGATION);
121+
let chunks = proofs.chunks(proofs_per_chunk as usize);
122122
info!(
123-
"Total proofs to aggregate {}. They aggregation will be performed in {} chunks",
123+
"Total proofs to aggregate {}. They aggregation will be performed in {} chunks (i.e {} proofs per chunk)",
124124
proofs.len(),
125-
chunks.len()
125+
chunks.len(),
126+
proofs_per_chunk,
126127
);
127128

128129
let mut agg_proofs: Vec<(Risc0ProofReceiptAndImageId, Vec<[u8; 32]>)> = vec![];

aggregation_mode/src/backend/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct Config {
2121
pub aligned_service_manager_address: String,
2222
pub last_aggregated_block_filepath: String,
2323
pub ecdsa: ECDSAConfig,
24+
pub proofs_per_chunk: u16,
2425
}
2526

2627
impl Config {

aggregation_mode/src/backend/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ pub struct ProofAggregator {
4242
engine: ZKVMEngine,
4343
proof_aggregation_service: AlignedProofAggregationServiceContract,
4444
fetcher: ProofsFetcher,
45+
config: Config,
4546
}
4647

4748
impl ProofAggregator {
48-
pub fn new(config: &Config) -> Self {
49+
pub fn new(config: Config) -> Self {
4950
let rpc_url = config.eth_rpc_url.parse().expect("RPC URL should be valid");
5051
let signer = LocalSigner::decrypt_keystore(
5152
config.ecdsa.private_key_store_path.clone(),
@@ -62,24 +63,25 @@ impl ProofAggregator {
6263

6364
let engine =
6465
ZKVMEngine::from_env().expect("AGGREGATOR env variable to be set to one of sp1|risc0");
65-
let fetcher = ProofsFetcher::new(config);
66+
let fetcher = ProofsFetcher::new(&config);
6667

6768
Self {
6869
engine,
6970
proof_aggregation_service,
7071
fetcher,
72+
config,
7173
}
7274
}
7375

74-
pub async fn start(&mut self, config: &Config) {
76+
pub async fn start(&mut self) {
7577
info!("Starting proof aggregator service");
7678

7779
info!("About to aggregate and submit proof to be verified on chain");
7880
let res = self.aggregate_and_submit_proofs_on_chain().await;
7981

8082
match res {
8183
Ok(()) => {
82-
config
84+
self.config
8385
.update_last_aggregated_block(self.fetcher.get_last_aggregated_block())
8486
.unwrap();
8587
info!("Process finished successfully");
@@ -113,7 +115,7 @@ impl ProofAggregator {
113115
info!("Starting proof aggregation program...");
114116
let (aggregated_proof, zkvm_merkle_root) = self
115117
.engine
116-
.aggregate_proofs(proofs)
118+
.aggregate_proofs(proofs, self.config.proofs_per_chunk)
117119
.map_err(AggregatedProofSubmissionError::ZKVMAggregation)?;
118120
info!("Proof aggregation program finished");
119121

aggregation_mode/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ async fn main() {
2626
let config = Config::from_file(&config_file_path).expect("Config is valid");
2727
tracing::info!("Config loaded");
2828

29-
let mut proof_aggregator = ProofAggregator::new(&config);
30-
proof_aggregator.start(&config).await;
29+
let mut proof_aggregator = ProofAggregator::new(config);
30+
proof_aggregator.start().await;
3131
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ eth_rpc_url: "http://localhost:8545"
44
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
7+
proofs_per_chunk: 512 # Amount of proofs to process per chunk
78

89
ecdsa:
910
private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ eth_rpc_url: "http://localhost:8545"
44
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
7+
proofs_per_chunk: 512 # Amount of proofs to process per chunk
78

89
ecdsa:
910
private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ eth_rpc_url: "http://localhost:8545"
44
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
7+
proofs_per_chunk: 512 # Amount of proofs to process per chunk
78

89
ecdsa:
910
private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"

config-files/config-proof-aggregator.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ eth_rpc_url: "http://localhost:8545"
44
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
7+
proofs_per_chunk: 512 # Amount of proofs to process per chunk
78

89
ecdsa:
910
private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"

0 commit comments

Comments
 (0)