@@ -13,7 +13,11 @@ use sp1_sdk::{
1313 HashableKey , Prover , SP1ProofMode , SP1ProofWithPublicValues , SP1ProvingKey , SP1Stdin ,
1414 SP1VerifyingKey ,
1515} ;
16- use std:: { fmt:: Debug , sync:: OnceLock , time:: Instant } ;
16+ use std:: {
17+ fmt:: Debug ,
18+ sync:: OnceLock ,
19+ time:: { Duration , Instant } ,
20+ } ;
1721use tracing:: info;
1822use url:: Url ;
1923
@@ -84,15 +88,25 @@ pub fn execute(input: ProgramInput) -> Result<(), Box<dyn std::error::Error>> {
8488
8589 let setup = PROVER_SETUP . get_or_init ( || init_prover_setup ( None ) ) ;
8690
87- let now = Instant :: now ( ) ;
8891 setup. client . execute ( ZKVM_SP1_PROGRAM_ELF , & stdin) ?;
89- let elapsed = now. elapsed ( ) ;
90-
91- info ! ( "Successfully executed SP1 program in {elapsed:.2?}" ) ;
9292
9393 Ok ( ( ) )
9494}
9595
96+ pub fn execute_timed ( input : ProgramInput ) -> Result < Duration , Box < dyn std:: error:: Error > > {
97+ let mut stdin = SP1Stdin :: new ( ) ;
98+ let bytes = rkyv:: to_bytes :: < Error > ( & input) ?;
99+ stdin. write_slice ( bytes. as_slice ( ) ) ;
100+
101+ let setup = PROVER_SETUP . get_or_init ( || init_prover_setup ( None ) ) ;
102+
103+ let start = Instant :: now ( ) ;
104+ setup. client . execute ( ZKVM_SP1_PROGRAM_ELF , & stdin) ?;
105+ let duration = start. elapsed ( ) ;
106+
107+ Ok ( duration)
108+ }
109+
96110pub fn prove (
97111 input : ProgramInput ,
98112 format : ProofFormat ,
@@ -103,21 +117,38 @@ pub fn prove(
103117
104118 let setup = PROVER_SETUP . get_or_init ( || init_prover_setup ( None ) ) ;
105119
106- // contains the receipt along with statistics about execution of the guest
107120 let format = match format {
108121 ProofFormat :: Compressed => SP1ProofMode :: Compressed ,
109122 ProofFormat :: Groth16 => SP1ProofMode :: Groth16 ,
110123 } ;
111124
112- let now = Instant :: now ( ) ;
113125 let proof = setup. client . prove ( & setup. pk , & stdin, format) ?;
114- let elapsed = now. elapsed ( ) ;
115-
116- info ! ( "Successfully proved SP1 program in {elapsed:.2?}" ) ;
117126
118127 Ok ( ProveOutput :: new ( proof, setup. vk . clone ( ) ) )
119128}
120129
130+ pub fn prove_timed (
131+ input : ProgramInput ,
132+ format : ProofFormat ,
133+ ) -> Result < ( ProveOutput , Duration ) , Box < dyn std:: error:: Error > > {
134+ let mut stdin = SP1Stdin :: new ( ) ;
135+ let bytes = rkyv:: to_bytes :: < Error > ( & input) ?;
136+ stdin. write_slice ( bytes. as_slice ( ) ) ;
137+
138+ let setup = PROVER_SETUP . get_or_init ( || init_prover_setup ( None ) ) ;
139+
140+ let format = match format {
141+ ProofFormat :: Compressed => SP1ProofMode :: Compressed ,
142+ ProofFormat :: Groth16 => SP1ProofMode :: Groth16 ,
143+ } ;
144+
145+ let start = Instant :: now ( ) ;
146+ let proof = setup. client . prove ( & setup. pk , & stdin, format) ?;
147+ let duration = start. elapsed ( ) ;
148+
149+ Ok ( ( ProveOutput :: new ( proof, setup. vk . clone ( ) ) , duration) )
150+ }
151+
121152pub fn verify ( output : & ProveOutput ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
122153 let setup = PROVER_SETUP . get_or_init ( || init_prover_setup ( None ) ) ;
123154 setup. client . verify ( & output. proof , & output. vk ) ?;
0 commit comments