11use sp1_aggregator:: SP1CompressedProof ;
2- use sp1_sdk:: { ProverClient , SP1ProofWithPublicValues , SP1Stdin , SP1VerifyingKey } ;
2+ use sp1_sdk:: { ProverClient , SP1ProofMode , SP1ProofWithPublicValues , SP1Stdin , SP1VerifyingKey } ;
33
44use super :: interface:: { AggregatedProof , AggregatedVerificationError , ProgramOutput } ;
55
66const PROGRAM_ELF : & [ u8 ] = include_bytes ! ( "../../zkvm/sp1/elf/sp1_aggregator_program" ) ;
77
88pub struct SP1AggregatedProof {
9- proof : SP1ProofWithPublicValues ,
10- vk : SP1VerifyingKey ,
9+ pub proof : SP1ProofWithPublicValues ,
10+ pub vk : SP1VerifyingKey ,
1111}
1212
1313pub ( crate ) fn aggregate_proofs (
1414 proofs : Vec < SP1CompressedProof > ,
1515) -> Result < ProgramOutput , AggregatedVerificationError > {
16+ #[ cfg( feature = "prove" ) ]
17+ {
18+ prove ( proofs)
19+ }
20+ // If not in prove mode, execute the program and create a mock proof
21+ #[ cfg( not( feature = "prove" ) ) ]
22+ {
23+ mock_prove ( proofs)
24+ }
25+ }
26+
27+ #[ cfg( feature = "prove" ) ]
28+ fn prove ( proofs : Vec < SP1CompressedProof > ) -> Result < ProgramOutput , AggregatedVerificationError > {
1629 let mut stdin = SP1Stdin :: new ( ) ;
1730 stdin. write ( & proofs) ;
1831
@@ -33,3 +46,29 @@ pub(crate) fn aggregate_proofs(
3346
3447 Ok ( output)
3548}
49+
50+ fn mock_prove (
51+ proofs : Vec < SP1CompressedProof > ,
52+ ) -> Result < ProgramOutput , AggregatedVerificationError > {
53+ let mut stdin = SP1Stdin :: new ( ) ;
54+ stdin. write ( & proofs) ;
55+
56+ let client = ProverClient :: from_env ( ) ;
57+ let ( pk, vk) = client. setup ( PROGRAM_ELF ) ;
58+ let ( public_vales, _) = client
59+ . execute ( PROGRAM_ELF , & stdin)
60+ . run ( )
61+ . map_err ( |_| AggregatedVerificationError :: SP1Proving ) ?;
62+
63+ let output = ProgramOutput :: new ( AggregatedProof :: SP1 ( SP1AggregatedProof {
64+ proof : SP1ProofWithPublicValues :: create_mock_proof (
65+ & pk,
66+ public_vales,
67+ SP1ProofMode :: Groth16 ,
68+ "" ,
69+ ) ,
70+ vk,
71+ } ) ) ;
72+
73+ Ok ( output)
74+ }
0 commit comments