Skip to content

Commit eae61ba

Browse files
committed
chore: add comments for aggregation function
1 parent e39ed67 commit eae61ba

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

aggregation_mode/aggregation_programs/risc0/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub struct Risc0ImageIdAndPubInputs {
99

1010
impl Risc0ImageIdAndPubInputs {
1111
pub fn commitment(&self, is_aggregated_chunk: bool) -> [u8; 32] {
12+
// If the proof is the aggregation of a chunk
13+
// the commitment is simply the public input (the merkle root of the chunk)
1214
if is_aggregated_chunk {
1315
self.public_inputs.clone().try_into().unwrap()
1416
} else {

aggregation_mode/aggregation_programs/sp1/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub struct SP1VkAndPubInputs {
99

1010
impl SP1VkAndPubInputs {
1111
pub fn commitment(&self, is_aggregated_chunk: bool) -> [u8; 32] {
12+
// If the proof is the aggregation of a chunk
13+
// the commitment is simply the public input (the merkle root of the chunk)
1214
if is_aggregated_chunk {
1315
self.public_inputs.clone().try_into().unwrap()
1416
} else {

aggregation_mode/src/aggregators/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use sp1_aggregator::{
1010
AlignedSP1VerificationError, SP1AggregationError, SP1ProofWithPubValuesAndElf,
1111
};
1212

13-
const AGG_PROOF_CHUNKS: usize = 512;
13+
const MAX_PROOFS_PER_AGGREGATION: usize = 512;
1414

1515
#[derive(Clone, Debug)]
1616
pub enum ZKVMEngine {
@@ -55,6 +55,15 @@ impl ZKVMEngine {
5555
///
5656
/// This function performs proof aggregation and ensures the resulting Merkle root
5757
/// can be independently verified by external systems.
58+
///
59+
/// If the number of proofs exceeds [`MAX_PROOFS_PER_AGGREGATION`], it first aggregates
60+
/// them in chunks of [`MAX_PROOFS_PER_AGGREGATION`], and then aggregates those intermediate results into
61+
/// the final proof.
62+
///
63+
/// Note: Intermediate proof commitments are not computed using the Keccak hash of the
64+
/// verification key and public inputs. Instead, the raw bytes of the public input—
65+
/// which represent the chunk's merkle root are used directly. This is to ensure
66+
/// the final Merkle root matches the leaf hashes published on the blob.
5867
pub fn aggregate_proofs(
5968
&self,
6069
proofs: Vec<AlignedProof>,
@@ -69,8 +78,8 @@ impl ZKVMEngine {
6978
})
7079
.collect();
7180

72-
let mut agg_proof = if proofs.len() > AGG_PROOF_CHUNKS {
73-
let chunks = proofs.chunks(AGG_PROOF_CHUNKS);
81+
let mut agg_proof = if proofs.len() > MAX_PROOFS_PER_AGGREGATION {
82+
let chunks = proofs.chunks(MAX_PROOFS_PER_AGGREGATION);
7483
let mut agg_proofs: Vec<SP1ProofWithPubValuesAndElf> = vec![];
7584
for chunk in chunks {
7685
let agg_proof = sp1_aggregator::aggregate_proofs(chunk, false, false)
@@ -102,8 +111,8 @@ impl ZKVMEngine {
102111
})
103112
.collect();
104113

105-
let agg_proof = if proofs.len() > AGG_PROOF_CHUNKS {
106-
let chunks = proofs.chunks(AGG_PROOF_CHUNKS);
114+
let agg_proof = if proofs.len() > MAX_PROOFS_PER_AGGREGATION {
115+
let chunks = proofs.chunks(MAX_PROOFS_PER_AGGREGATION);
107116
let mut agg_proofs: Vec<Risc0ProofReceiptAndImageId> = vec![];
108117
for chunk in chunks {
109118
let agg_proof = risc0_aggregator::aggregate_proofs(chunk, false, false)

0 commit comments

Comments
 (0)