11use ethlambda_prover_core:: { Proof , ProverError , StfInput , StfProver , StfPublicValues } ;
22use sp1_sdk:: {
3- MockProver , Prover , SP1ProofWithPublicValues , SP1ProvingKey , SP1Stdin , SP1VerifyingKey ,
4- include_elf,
3+ Elf , MockProver , ProveRequest , Prover , ProvingKey , SP1ProofWithPublicValues , SP1ProvingKey ,
4+ SP1Stdin , SP1VerifyingKey , include_elf,
55} ;
66
7-
8- const STATE_TRANSITION_ELF : & [ u8 ] = include_elf ! ( "zkvm_guest_sp1" ) ;
7+ const STATE_TRANSITION_ELF : Elf = include_elf ! ( "zkvm_guest_sp1" ) ;
98const CYCLE_LIMIT : u64 = 10_000_000 ;
109
1110/// SP1 prover: proves the STF guest and verifies its proofs.
@@ -25,7 +24,13 @@ impl Sp1Prover {
2524 pub async fn new ( ) -> Self {
2625 let client = MockProver :: new ( ) . await ;
2726 // let client = ProverClient::builder().cpu().await;
28- let ( pk, vk) = client. setup ( STATE_TRANSITION_ELF ) . await ;
27+ // `setup` returns only the proving key (fallible); the verifying key is
28+ // derived from it.
29+ let pk = client
30+ . setup ( STATE_TRANSITION_ELF )
31+ . await
32+ . expect ( "failed to set up SP1 proving key" ) ;
33+ let vk = pk. verifying_key ( ) . clone ( ) ;
2934 Self { client, pk, vk }
3035 }
3136}
@@ -56,12 +61,29 @@ impl StfProver for Sp1Prover {
5661 let mut sp1_proof: SP1ProofWithPublicValues = bincode:: deserialize ( proof. as_bytes ( ) )
5762 . map_err ( |err| ProverError :: Serialization ( err. to_string ( ) ) ) ?;
5863
64+ // `verify` is synchronous in this SDK and takes an optional status code.
5965 self . client
60- . verify ( & sp1_proof, & self . vk )
61- . await
66+ . verify ( & sp1_proof, & self . vk , None )
6267 . map_err ( |err| ProverError :: Verify ( err. to_string ( ) ) ) ?;
6368
6469 // The guest committed `StfPublicValues` via `io::commit`; read it back.
6570 Ok ( sp1_proof. public_values . read :: < StfPublicValues > ( ) )
6671 }
72+
73+ async fn execute ( & self , input : & StfInput ) -> Result < StfPublicValues , ProverError > {
74+ let mut stdin = SP1Stdin :: new ( ) ;
75+ stdin. write ( input) ;
76+
77+ // Runs the guest in the SP1 executor without proving; the future yields
78+ // `(SP1PublicValues, ExecutionReport)`. We ignore the report for now.
79+ let ( mut public_values, _report) = self
80+ . client
81+ . execute ( STATE_TRANSITION_ELF , stdin)
82+ . cycle_limit ( CYCLE_LIMIT )
83+ . await
84+ . map_err ( |err| ProverError :: Execute ( err. to_string ( ) ) ) ?;
85+
86+ // The guest committed `StfPublicValues` via `io::commit`; read it back.
87+ Ok ( public_values. read :: < StfPublicValues > ( ) )
88+ }
6789}
0 commit comments