@@ -5,9 +5,10 @@ use std::fmt::Display;
55
66use risc0_aggregator:: {
77 AlignedRisc0VerificationError , Risc0AggregationError , Risc0ProofReceiptAndImageId ,
8+ Risc0ProofType ,
89} ;
910use sp1_aggregator:: {
10- AlignedSP1VerificationError , SP1AggregationError , SP1ProofWithPubValuesAndElf ,
11+ AlignedSP1VerificationError , SP1AggregationError , SP1ProofType , SP1ProofWithPubValuesAndElf ,
1112} ;
1213
1314#[ derive( Clone , Debug ) ]
@@ -59,16 +60,38 @@ impl ZKVMEngine {
5960 ) -> Result < ( AlignedProof , [ u8 ; 32 ] ) , ProofAggregationError > {
6061 let res = match self {
6162 ZKVMEngine :: SP1 => {
62- let proofs = proofs
63+ let proofs: Vec < SP1ProofWithPubValuesAndElf > = proofs
6364 . into_iter ( )
6465 . filter_map ( |proof| match proof {
6566 AlignedProof :: SP1 ( proof) => Some ( * proof) ,
6667 _ => None ,
6768 } )
6869 . collect ( ) ;
6970
70- let mut agg_proof = sp1_aggregator:: aggregate_proofs ( proofs)
71- . map_err ( ProofAggregationError :: SP1Aggregation ) ?;
71+ // we run the aggregator in chunks of 512 proofs
72+ let chunks = proofs. chunks ( 512 ) ;
73+ let mut agg_proofs: Vec < SP1ProofWithPubValuesAndElf > = vec ! [ ] ;
74+
75+ let agg_chunks_type = if chunks. len ( ) == 1 {
76+ SP1ProofType :: Groth16
77+ } else {
78+ SP1ProofType :: Compressed
79+ } ;
80+
81+ for chunk in chunks {
82+ let agg_proof =
83+ sp1_aggregator:: aggregate_proofs ( chunk, agg_chunks_type. clone ( ) )
84+ . map_err ( ProofAggregationError :: SP1Aggregation ) ?;
85+
86+ agg_proofs. push ( agg_proof) ;
87+ }
88+
89+ let mut agg_proof = if agg_proofs. len ( ) > 1 {
90+ sp1_aggregator:: aggregate_proofs ( & agg_proofs, SP1ProofType :: Groth16 )
91+ . map_err ( ProofAggregationError :: SP1Aggregation ) ?
92+ } else {
93+ agg_proofs. pop ( ) . unwrap ( )
94+ } ;
7295
7396 let merkle_root: [ u8 ; 32 ] = agg_proof
7497 . proof_with_pub_values
@@ -78,16 +101,37 @@ impl ZKVMEngine {
78101 ( AlignedProof :: SP1 ( agg_proof. into ( ) ) , merkle_root)
79102 }
80103 ZKVMEngine :: RISC0 => {
81- let proofs = proofs
104+ let proofs: Vec < Risc0ProofReceiptAndImageId > = proofs
82105 . into_iter ( )
83106 . filter_map ( |proof| match proof {
84107 AlignedProof :: Risc0 ( proof) => Some ( * proof) ,
85108 _ => None ,
86109 } )
87110 . collect ( ) ;
88111
89- let agg_proof = risc0_aggregator:: aggregate_proofs ( proofs)
90- . map_err ( ProofAggregationError :: Risc0Aggregation ) ?;
112+ let chunks = proofs. chunks ( 512 ) ;
113+ let mut agg_proofs: Vec < Risc0ProofReceiptAndImageId > = vec ! [ ] ;
114+
115+ let agg_chunks_type = if chunks. len ( ) == 1 {
116+ Risc0ProofType :: Groth16
117+ } else {
118+ Risc0ProofType :: Composite
119+ } ;
120+
121+ for chunk in chunks {
122+ let agg_proof =
123+ risc0_aggregator:: aggregate_proofs ( chunk, agg_chunks_type. clone ( ) )
124+ . map_err ( ProofAggregationError :: Risc0Aggregation ) ?;
125+
126+ agg_proofs. push ( agg_proof) ;
127+ }
128+
129+ let agg_proof = if agg_proofs. len ( ) > 1 {
130+ risc0_aggregator:: aggregate_proofs ( & agg_proofs, Risc0ProofType :: Groth16 )
131+ . map_err ( ProofAggregationError :: Risc0Aggregation ) ?
132+ } else {
133+ agg_proofs. pop ( ) . unwrap ( )
134+ } ;
91135
92136 // Note: journal.decode() won't work here as risc0 deserializer works under u32 words
93137 let public_input_bytes = agg_proof. receipt . journal . as_ref ( ) ;
0 commit comments