11use std:: sync:: LazyLock ;
22
33use alloy:: primitives:: Keccak256 ;
4- use sp1_aggregation_program:: { ProofVkAndPubInputs , SP1VkAndPubInputs } ;
4+ use sp1_aggregation_program:: SP1VkAndPubInputs ;
55use sp1_sdk:: {
66 EnvProver , HashableKey , Prover , ProverClient , SP1ProofWithPublicValues , SP1Stdin ,
77 SP1VerifyingKey ,
88} ;
99
10- use super :: lib:: { AggregatedProof , ProgramOutput , ProofAggregationError } ;
11-
1210const PROGRAM_ELF : & [ u8 ] =
1311 include_bytes ! ( "../../aggregation_programs/sp1/elf/sp1_aggregator_program" ) ;
1412
@@ -33,38 +31,39 @@ impl SP1ProofWithPubValuesAndElf {
3331 }
3432}
3533
36- pub struct SP1AggregationInput {
37- pub proofs : Vec < SP1ProofWithPubValuesAndElf > ,
38- pub merkle_root : [ u8 ; 32 ] ,
34+ #[ derive( Debug ) ]
35+ pub enum SP1AggregationError {
36+ Verification ( sp1_sdk:: SP1VerificationError ) ,
37+ Prove ( String ) ,
38+ UnsupportedProof ,
3939}
4040
4141pub ( crate ) fn aggregate_proofs (
42- input : SP1AggregationInput ,
43- ) -> Result < ProgramOutput , ProofAggregationError > {
42+ proofs : Vec < SP1ProofWithPubValuesAndElf > ,
43+ ) -> Result < SP1ProofWithPubValuesAndElf , SP1AggregationError > {
4444 let mut stdin = SP1Stdin :: new ( ) ;
4545
4646 let mut program_input = sp1_aggregation_program:: Input {
4747 proofs_vk_and_pub_inputs : vec ! [ ] ,
48- merkle_root : input. merkle_root ,
4948 } ;
5049
5150 // write vk + public inputs
52- for proof in input . proofs . iter ( ) {
51+ for proof in proofs. iter ( ) {
5352 program_input
5453 . proofs_vk_and_pub_inputs
55- . push ( ProofVkAndPubInputs :: SP1Compressed ( SP1VkAndPubInputs {
54+ . push ( SP1VkAndPubInputs {
5655 public_inputs : proof. proof_with_pub_values . public_values . to_vec ( ) ,
5756 vk : proof. vk ( ) . hash_u32 ( ) ,
58- } ) ) ;
57+ } ) ;
5958 }
6059 stdin. write ( & program_input) ;
6160
6261 // write proofs
63- for input_proof in input . proofs {
62+ for input_proof in proofs {
6463 let vk = input_proof. vk ( ) . vk ;
6564 // we only support sp1 Compressed proofs for now
6665 let sp1_sdk:: SP1Proof :: Compressed ( proof) = input_proof. proof_with_pub_values . proof else {
67- return Err ( ProofAggregationError :: UnsupportedProof ) ;
66+ return Err ( SP1AggregationError :: UnsupportedProof ) ;
6867 } ;
6968 stdin. write_proof ( * proof, vk) ;
7069 }
@@ -80,21 +79,19 @@ pub(crate) fn aggregate_proofs(
8079 . prove ( & pk, & stdin)
8180 . groth16 ( )
8281 . run ( )
83- . map_err ( |_| ProofAggregationError :: SP1Proving ) ?;
82+ . map_err ( |e| SP1AggregationError :: Prove ( e . to_string ( ) ) ) ?;
8483
8584 // a sanity check, vm already performs it
8685 client
8786 . verify ( & proof, & vk)
88- . map_err ( ProofAggregationError :: SP1Verification ) ?;
87+ . map_err ( SP1AggregationError :: Verification ) ?;
8988
9089 let proof_and_elf = SP1ProofWithPubValuesAndElf {
9190 proof_with_pub_values : proof,
9291 elf : PROGRAM_ELF . to_vec ( ) ,
9392 } ;
9493
95- let output = ProgramOutput :: new ( AggregatedProof :: SP1 ( proof_and_elf. into ( ) ) ) ;
96-
97- Ok ( output)
94+ Ok ( proof_and_elf)
9895}
9996
10097#[ derive( Debug ) ]
0 commit comments