diff --git a/prover/src/lib.rs b/prover/src/lib.rs index e48364fd8e..737ff1f35e 100644 --- a/prover/src/lib.rs +++ b/prover/src/lib.rs @@ -57,8 +57,10 @@ use sp1_recursion_gnark_ffi::Groth16Prover; use sp1_recursion_program::hints::Hintable; pub use sp1_recursion_program::machine::ReduceProgramType; use sp1_recursion_program::machine::{ - SP1CompressVerifier, SP1DeferredMemoryLayout, SP1DeferredVerifier, SP1RecursionMemoryLayout, - SP1RecursiveVerifier, SP1ReduceMemoryLayout, SP1RootMemoryLayout, SP1RootVerifier, + SP1CompressVerifier, SP1DeferredVerifier, SP1RecursiveVerifier, SP1RootVerifier, +}; +pub use sp1_recursion_program::machine::{ + SP1DeferredMemoryLayout, SP1RecursionMemoryLayout, SP1ReduceMemoryLayout, SP1RootMemoryLayout, }; use std::env; use std::path::PathBuf; @@ -426,27 +428,12 @@ impl SP1Prover { is_complete, }; - let mut runtime = RecursionRuntime::, Challenge, _>::new( + let proof = self.compress_machine_proof( + input, &self.compress_program, - self.compress_machine.config().perm.clone(), - ); - - let mut witness_stream = Vec::new(); - witness_stream.extend(input.write()); - - runtime.witness_stream = witness_stream.into(); - runtime.run(); - runtime.print_stats(); - - let mut recursive_challenger = self.compress_machine.config().challenger(); - let mut proof = self.compress_machine.prove::>( &self.compress_pk, - runtime.record, - &mut recursive_challenger, ); - - debug_assert_eq!(proof.shard_proofs.len(), 1); - (proof.shard_proofs.pop().unwrap(), ReduceProgramType::Reduce) + (proof, ReduceProgramType::Reduce) }) .collect(); @@ -465,6 +452,32 @@ impl SP1Prover { } } + pub fn compress_machine_proof( + &self, + input: impl Hintable, + program: &RecursionProgram, + pk: &StarkProvingKey, + ) -> ShardProof { + let mut runtime = RecursionRuntime::, Challenge, _>::new( + program, + self.compress_machine.config().perm.clone(), + ); + + let mut witness_stream = Vec::new(); + witness_stream.extend(input.write()); + + runtime.witness_stream = witness_stream.into(); + runtime.run(); + runtime.print_stats(); + + let mut recursive_challenger = self.compress_machine.config().challenger(); + self.compress_machine + .prove::>(pk, runtime.record, &mut recursive_challenger) + .shard_proofs + .pop() + .unwrap() + } + /// Wrap a reduce proof into a STARK proven over a SNARK-friendly field. #[instrument(name = "shrink", level = "info", skip_all)] pub fn shrink(&self, reduced_proof: SP1ReduceProof) -> SP1ReduceProof {