@@ -5,12 +5,13 @@ use std::fmt::Display;
55
66use risc0_aggregator:: {
77 AlignedRisc0VerificationError , Risc0AggregationError , Risc0ProofReceiptAndImageId ,
8- Risc0ProofType ,
98} ;
109use sp1_aggregator:: {
11- AlignedSP1VerificationError , SP1AggregationError , SP1ProofType , SP1ProofWithPubValuesAndElf ,
10+ AlignedSP1VerificationError , SP1AggregationError , SP1ProofWithPubValuesAndElf ,
1211} ;
1312
13+ const AGG_PROOF_CHUNKS : usize = 512 ;
14+
1415#[ derive( Clone , Debug ) ]
1516pub enum ZKVMEngine {
1617 SP1 ,
@@ -68,29 +69,21 @@ impl ZKVMEngine {
6869 } )
6970 . collect ( ) ;
7071
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 ( ) )
72+ let mut agg_proof = if proofs. len ( ) > AGG_PROOF_CHUNKS {
73+ let chunks = proofs. chunks ( AGG_PROOF_CHUNKS ) ;
74+ let mut agg_proofs: Vec < SP1ProofWithPubValuesAndElf > = vec ! [ ] ;
75+ for chunk in chunks {
76+ let agg_proof = sp1_aggregator:: aggregate_proofs ( chunk, false , false )
8477 . map_err ( ProofAggregationError :: SP1Aggregation ) ?;
8578
86- agg_proofs. push ( agg_proof) ;
87- }
79+ agg_proofs. push ( agg_proof) ;
80+ }
8881
89- let mut agg_proof = if agg_proofs. len ( ) > 1 {
90- sp1_aggregator:: aggregate_proofs ( & agg_proofs, SP1ProofType :: Groth16 )
82+ sp1_aggregator:: aggregate_proofs ( & agg_proofs, true , true )
9183 . map_err ( ProofAggregationError :: SP1Aggregation ) ?
9284 } else {
93- agg_proofs. pop ( ) . unwrap ( )
85+ sp1_aggregator:: aggregate_proofs ( & proofs, false , true )
86+ . map_err ( ProofAggregationError :: SP1Aggregation ) ?
9487 } ;
9588
9689 let merkle_root: [ u8 ; 32 ] = agg_proof
@@ -109,28 +102,20 @@ impl ZKVMEngine {
109102 } )
110103 . collect ( ) ;
111104
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 ( ) )
105+ let agg_proof = if proofs. len ( ) > AGG_PROOF_CHUNKS {
106+ let chunks = proofs. chunks ( AGG_PROOF_CHUNKS ) ;
107+ let mut agg_proofs: Vec < Risc0ProofReceiptAndImageId > = vec ! [ ] ;
108+ for chunk in chunks {
109+ let agg_proof = risc0_aggregator:: aggregate_proofs ( chunk, false , false )
124110 . map_err ( ProofAggregationError :: Risc0Aggregation ) ?;
111+ agg_proofs. push ( agg_proof) ;
112+ }
125113
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 )
114+ risc0_aggregator:: aggregate_proofs ( & agg_proofs, true , true )
131115 . map_err ( ProofAggregationError :: Risc0Aggregation ) ?
132116 } else {
133- agg_proofs. pop ( ) . unwrap ( )
117+ risc0_aggregator:: aggregate_proofs ( & proofs, false , true )
118+ . map_err ( ProofAggregationError :: Risc0Aggregation ) ?
134119 } ;
135120
136121 // Note: journal.decode() won't work here as risc0 deserializer works under u32 words
0 commit comments