diff --git a/benches/end2end.rs b/benches/end2end.rs index b08e68903..7dc8e6a7a 100644 --- a/benches/end2end.rs +++ b/benches/end2end.rs @@ -13,7 +13,7 @@ use lurk::{ pointers::Ptr, store::Store, }, - proof::{nova::NovaProver, RecursiveSNARKTrait}, + proof::{nova::NovaProver, Prover, RecursiveSNARKTrait}, public_parameters::{ self, instance::{Instance, Kind}, diff --git a/benches/fibonacci.rs b/benches/fibonacci.rs index 8c900bc22..b0e03d881 100644 --- a/benches/fibonacci.rs +++ b/benches/fibonacci.rs @@ -11,6 +11,7 @@ use lurk::{ lang::{Coproc, Lang}, lem::{eval::evaluate, store::Store}, proof::nova::NovaProver, + proof::Prover, public_parameters::{ instance::{Instance, Kind}, public_params, diff --git a/benches/sha256.rs b/benches/sha256.rs index d311076d5..d880a9032 100644 --- a/benches/sha256.rs +++ b/benches/sha256.rs @@ -23,7 +23,7 @@ use lurk::{ pointers::Ptr, store::Store, }, - proof::{nova::NovaProver, supernova::SuperNovaProver, RecursiveSNARKTrait}, + proof::{nova::NovaProver, supernova::SuperNovaProver, Prover, RecursiveSNARKTrait}, public_parameters::{ instance::{Instance, Kind}, public_params, supernova_public_params, diff --git a/examples/tp_table.rs b/examples/tp_table.rs index 04860afb2..c9998a3d2 100644 --- a/examples/tp_table.rs +++ b/examples/tp_table.rs @@ -7,6 +7,7 @@ use lurk::{ lang::{Coproc, Lang}, lem::{eval::evaluate, store::Store}, proof::nova::{public_params, NovaProver, PublicParams}, + proof::Prover, }; use num_traits::ToPrimitive; use statrs::statistics::Statistics; diff --git a/src/cli/repl/mod.rs b/src/cli/repl/mod.rs index fc6424eef..9f43afd62 100644 --- a/src/cli/repl/mod.rs +++ b/src/cli/repl/mod.rs @@ -38,7 +38,7 @@ use crate::{ proof::{ nova::{CurveCycleEquipped, Dual, NovaProver}, supernova::SuperNovaProver, - RecursiveSNARKTrait, + Prover, RecursiveSNARKTrait, }, public_parameters::{instance::Instance, public_params, supernova_public_params}, state::{State, StateRcCell}, diff --git a/src/proof/mod.rs b/src/proof/mod.rs index c03c00409..d86f6c33b 100644 --- a/src/proof/mod.rs +++ b/src/proof/mod.rs @@ -160,7 +160,7 @@ impl FoldingMode { } /// A trait for a prover that works with a field `F`. -pub trait Prover { +pub trait Prover> { /// Associated type for a frame-like datatype type Frame: FrameLike> + Send; @@ -215,4 +215,31 @@ pub trait Prover { let unfull_multiframe_frame_count = raw_iterations % rc; full_multiframe_count + usize::from(unfull_multiframe_frame_count != 0) } + + /// Generate a proof from a sequence of frames + fn prove_from_frames( + &self, + pp: &Self::PublicParams, + frames: &[crate::lem::interpreter::Frame], + store: &Arc>, + init: Option< + >::BaseRecursiveSNARK, + >, + ) -> Result<(Self::RecursiveSNARK, Vec, Vec, usize), ProofError> { + let folding_config = self + .folding_mode() + .folding_config(self.lang().clone(), self.reduction_count()); + let steps = Self::from_frames(frames, store, &folding_config.into()); + self.prove(pp, steps, store, init) + } + + /// Returns the `Lang` wrapped with `Arc` for cheap cloning + fn lang(&self) -> &Arc>; + + /// Converts input into Self::Frames according to the rules of the Prover + fn from_frames( + frames: &[crate::lem::interpreter::Frame], + store: &Arc>, + folding_config: &Arc>, + ) -> Vec; } diff --git a/src/proof/nova.rs b/src/proof/nova.rs index 36fd16a0b..d9730587a 100644 --- a/src/proof/nova.rs +++ b/src/proof/nova.rs @@ -392,30 +392,9 @@ impl> NovaProver { folding_mode: FoldingMode::IVC, } } - - /// Generate a proof from a sequence of frames - pub fn prove_from_frames( - &self, - pp: &PublicParams, - frames: &[Frame], - store: &Arc>, - init: Option>>, - ) -> Result<(Proof>, Vec, Vec, usize), ProofError> { - let folding_config = self - .folding_mode() - .folding_config(self.lang().clone(), self.reduction_count()); - let steps = C1LEM::::from_frames(frames, store, &folding_config.into()); - self.prove(pp, steps, store, init) - } - - #[inline] - /// Returns the `Lang` wrapped with `Arc` for cheap cloning - pub fn lang(&self) -> &Arc> { - &self.lang - } } -impl> Prover for NovaProver { +impl> Prover for NovaProver { type Frame = C1LEM; type PublicParams = PublicParams; type RecursiveSNARK = Proof>; @@ -444,4 +423,17 @@ impl> Prover for NovaProver { C1LEM::::build_frames(expr, env, store, limit, &eval_config, ch_terminal)?; self.prove_from_frames(pp, &frames, store, None) } + + fn from_frames( + frames: &[Frame], + store: &Arc>, + folding_config: &Arc>, + ) -> Vec { + C1LEM::::from_frames(frames, store, folding_config) + } + + #[inline] + fn lang(&self) -> &Arc> { + &self.lang + } } diff --git a/src/proof/supernova.rs b/src/proof/supernova.rs index f57ad2a5c..946e24512 100644 --- a/src/proof/supernova.rs +++ b/src/proof/supernova.rs @@ -195,12 +195,6 @@ impl> SuperNovaProver { let steps = C1LEM::::from_frames(frames, store, &folding_config.into()); self.prove(pp, steps, store, init) } - - #[inline] - /// Returns the `Lang` wrapped with `Arc` for cheap cloning - pub fn lang(&self) -> &Arc> { - &self.lang - } } impl> RecursiveSNARKTrait> @@ -323,7 +317,7 @@ impl> RecursiveSNARKTrait> Prover for SuperNovaProver { +impl> Prover for SuperNovaProver { type Frame = C1LEM; type PublicParams = PublicParams; type RecursiveSNARK = Proof>; @@ -352,6 +346,19 @@ impl> Prover for SuperNovaProver::build_frames(expr, env, store, limit, &eval_config, ch_terminal)?; self.prove_from_frames(pp, &frames, store, None) } + + fn from_frames( + frames: &[Frame], + store: &Arc>, + folding_config: &Arc>, + ) -> Vec { + C1LEM::::from_frames(frames, store, folding_config) + } + + #[inline] + fn lang(&self) -> &Arc> { + &self.lang + } } #[derive(Clone, Debug)]