From 36e721095056757d9793eef1c5715aaeb8b66189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sun, 4 Feb 2024 20:29:45 -0500 Subject: [PATCH 01/10] chore: point to type simplifications PR --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 549c33fd9e..711ad55f5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -121,7 +121,7 @@ clap = "4.3.17" ff = "0.13" metrics = "0.22.0" neptune = { git = "https://github.com/lurk-lab/neptune", branch = "dev", features = ["abomonation"] } -nova = { git = "https://github.com/lurk-lab/arecibo", branch = "dev", package = "arecibo", features = ["abomonate"]} +nova = { git = "https://github.com/lurk-lab/arecibo", branch = "type_simplifications", package = "arecibo", features = ["abomonate"]} once_cell = "1.18.0" pairing = { version = "0.23" } pasta_curves = { git = "https://github.com/lurk-lab/pasta_curves", branch = "dev" } From 2b4fef22e6c65acb7e542b17c6f010b0e5be4af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sun, 4 Feb 2024 20:29:49 -0500 Subject: [PATCH 02/10] refactor: Refactor to adapt to Arecibo simplifications - Significant refactoring has been done across multiple files to include the `SecEng` trait and `RecursiveSNARKTrait`, replacing `C1LEM`, `E2`, `C2` as well as `GrumpkinEngine` and `VestaEngine`. - Adjustments to various function arguments and returns to reflect the above changes, primarily noted in `public_parameters/mod.rs` and `proof/nova.rs`. - The implementation of `NonUniformCircuit` has been updated to only work with `E1` and has `C1` and `C2` types added. - removal of `MultiFrame` usage from `PublicParams` and simplification of type declarations. - Replaced functions across files, mainly `public_params`, `supernova_circuit_params`, `supernova_aux_params`, and `supernova_public_params`, have been adjusted for syntax changes. --- benches/end2end.rs | 27 +++++-- benches/sha256.rs | 12 ++- examples/circom.rs | 6 +- examples/sha256_ivc.rs | 18 +++-- examples/sha256_nivc.rs | 15 ++-- examples/tp_table.rs | 5 +- src/cli/lurk_proof.rs | 35 ++++----- src/cli/repl/meta_cmd.rs | 26 +++---- src/cli/repl/mod.rs | 15 ++-- src/lem/multiframe.rs | 7 +- src/proof/mod.rs | 8 +- src/proof/nova.rs | 110 ++++++++++++---------------- src/proof/supernova.rs | 96 ++++++++++++------------ src/proof/tests/mod.rs | 7 +- src/public_parameters/disk_cache.rs | 9 +-- src/public_parameters/mod.rs | 55 ++++++-------- 16 files changed, 230 insertions(+), 221 deletions(-) diff --git a/benches/end2end.rs b/benches/end2end.rs index e6e5602edb..6b9aa2677c 100644 --- a/benches/end2end.rs +++ b/benches/end2end.rs @@ -12,7 +12,10 @@ use lurk::{ pointers::Ptr, store::Store, }, - proof::{nova::NovaProver, RecursiveSNARKTrait}, + proof::{ + nova::{NovaProver, C1LEM}, + RecursiveSNARKTrait, + }, public_parameters::{ self, instance::{Instance, Kind}, @@ -302,7 +305,8 @@ fn prove_compressed_benchmark(c: &mut Criterion) { b.iter(|| { let (proof, _, _, _) = prover.prove_from_frames(&pp, &frames, &store).unwrap(); - let compressed_result = proof.compress(&pp).unwrap(); + let compressed_result = + RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::compress(proof, &pp).unwrap(); black_box(compressed_result); }) }); @@ -350,7 +354,13 @@ fn verify_benchmark(c: &mut Criterion) { b.iter_batched( || z0.clone(), |z0| { - let result = proof.verify(&pp, &z0, &zi[..]).unwrap(); + let result = RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::verify( + &proof, + &pp, + &z0, + &zi[..], + ) + .unwrap(); black_box(result); }, BatchSize::LargeInput, @@ -400,12 +410,19 @@ fn verify_compressed_benchmark(c: &mut Criterion) { let (proof, z0, zi, _num_steps) = prover.prove_from_frames(&pp, &frames, &store).unwrap(); - let compressed_proof = proof.compress(&pp).unwrap(); + let compressed_proof = + RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::compress(proof, &pp).unwrap(); b.iter_batched( || z0.clone(), |z0| { - let result = compressed_proof.verify(&pp, &z0, &zi[..]).unwrap(); + let result = RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::verify( + &compressed_proof, + &pp, + &z0, + &zi[..], + ) + .unwrap(); black_box(result); }, BatchSize::LargeInput, diff --git a/benches/sha256.rs b/benches/sha256.rs index b8f6d55a0e..2c7d385a00 100644 --- a/benches/sha256.rs +++ b/benches/sha256.rs @@ -15,14 +15,18 @@ use std::{cell::RefCell, rc::Rc, sync::Arc, time::Duration}; use lurk::{ coprocessor::sha256::{Sha256Coproc, Sha256Coprocessor}, - eval::lang::Lang, + eval::lang::{Coproc, Lang}, field::LurkField, lem::{ eval::{evaluate, make_cprocs_funcs_from_lang, make_eval_step_from_config, EvalConfig}, pointers::Ptr, store::Store, }, - proof::{nova::NovaProver, supernova::SuperNovaProver, RecursiveSNARKTrait}, + proof::{ + nova::{NovaProver, C1LEM}, + supernova::SuperNovaProver, + RecursiveSNARKTrait, + }, public_parameters::{ instance::{Instance, Kind}, public_params, supernova_public_params, @@ -220,7 +224,9 @@ fn sha256_ivc_prove_compressed( || frames, |frames| { let (proof, _, _, _) = prover.prove_from_frames(&pp, frames, store).unwrap(); - let compressed_result = proof.compress(&pp).unwrap(); + let compressed_result = + RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::compress(proof, &pp) + .unwrap(); let _ = black_box(compressed_result); }, diff --git a/examples/circom.rs b/examples/circom.rs index 5a934a9921..71d3dc5c2e 100644 --- a/examples/circom.rs +++ b/examples/circom.rs @@ -38,9 +38,10 @@ use lurk::circuit::gadgets::pointer::AllocatedPtr; #[cfg(not(target_arch = "wasm32"))] use lurk::coprocessor::circom::non_wasm::CircomCoprocessor; -use lurk::eval::lang::Lang; +use lurk::eval::lang::{Coproc, Lang}; use lurk::field::LurkField; use lurk::lem::{pointers::Ptr, store::Store}; +use lurk::proof::nova::C1LEM; use lurk::proof::{nova::NovaProver, Prover, RecursiveSNARKTrait}; use lurk::public_parameters::{ instance::{Instance, Kind}, @@ -133,7 +134,8 @@ fn main() { println!("Verifying proof..."); let verify_start = Instant::now(); - let res = proof.verify(&pp, &z0, &zi).unwrap(); + let res = + RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::verify(&proof, &pp, &z0, &zi).unwrap(); let verify_end = verify_start.elapsed(); println!("Verify took {verify_end:?}"); diff --git a/examples/sha256_ivc.rs b/examples/sha256_ivc.rs index ce36b1822c..21d3ce7086 100644 --- a/examples/sha256_ivc.rs +++ b/examples/sha256_ivc.rs @@ -5,10 +5,13 @@ use tracing_texray::TeXRayLayer; use lurk::{ coprocessor::sha256::{Sha256Coproc, Sha256Coprocessor}, - eval::lang::Lang, + eval::lang::{Coproc, Lang}, field::LurkField, lem::{pointers::Ptr, store::Store}, - proof::{nova::NovaProver, Prover, RecursiveSNARKTrait}, + proof::{ + nova::{NovaProver, C1LEM}, + Prover, RecursiveSNARKTrait, + }, public_parameters::{ instance::{Instance, Kind}, public_params, @@ -97,14 +100,17 @@ fn main() { println!("Verifying proof..."); let verify_start = Instant::now(); - assert!(proof.verify(&pp, &z0, &zi).unwrap()); + assert!( + RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::verify(&proof, &pp, &z0, &zi).unwrap() + ); let verify_end = verify_start.elapsed(); println!("Verify took {:?}", verify_end); println!("Compressing proof.."); let compress_start = Instant::now(); - let compressed_proof = proof.compress(&pp).unwrap(); + let compressed_proof = + RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::compress(proof, &pp).unwrap(); let compress_end = compress_start.elapsed(); println!("Compression took {:?}", compress_end); @@ -113,7 +119,9 @@ fn main() { println!("proof size : {:}B", buf.len()); let compressed_verify_start = Instant::now(); - let res = compressed_proof.verify(&pp, &z0, &zi).unwrap(); + let res = + RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::verify(&compressed_proof, &pp, &z0, &zi) + .unwrap(); let compressed_verify_end = compressed_verify_start.elapsed(); println!("Final verification took {:?}", compressed_verify_end); diff --git a/examples/sha256_nivc.rs b/examples/sha256_nivc.rs index c7ab304645..fdfdb7ea27 100644 --- a/examples/sha256_nivc.rs +++ b/examples/sha256_nivc.rs @@ -5,14 +5,14 @@ use tracing_texray::TeXRayLayer; use lurk::{ coprocessor::sha256::{Sha256Coproc, Sha256Coprocessor}, - eval::lang::Lang, + eval::lang::{Coproc, Lang}, field::LurkField, lem::{ eval::{evaluate, make_cprocs_funcs_from_lang, make_eval_step_from_config, EvalConfig}, pointers::Ptr, store::Store, }, - proof::{supernova::SuperNovaProver, RecursiveSNARKTrait}, + proof::{nova::C1LEM, supernova::SuperNovaProver, RecursiveSNARKTrait}, public_parameters::{ instance::{Instance, Kind}, supernova_public_params, @@ -106,14 +106,17 @@ fn main() { println!("Verifying proof..."); let verify_start = Instant::now(); - assert!(proof.verify(&pp, &z0, &zi).unwrap()); + assert!( + RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::verify(&proof, &pp, &z0, &zi).unwrap() + ); let verify_end = verify_start.elapsed(); println!("Verify took {:?}", verify_end); println!("Compressing proof.."); let compress_start = Instant::now(); - let compressed_proof = proof.compress(&pp).unwrap(); + let compressed_proof = + RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::compress(proof, &pp).unwrap(); let compress_end = compress_start.elapsed(); println!("Compression took {:?}", compress_end); @@ -122,7 +125,9 @@ fn main() { println!("proof size : {:}B", buf.len()); let compressed_verify_start = Instant::now(); - let res = compressed_proof.verify(&pp, &z0, &zi).unwrap(); + let res = + RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::verify(&compressed_proof, &pp, &z0, &zi) + .unwrap(); let compressed_verify_end = compressed_verify_start.elapsed(); println!("Final verification took {:?}", compressed_verify_end); diff --git a/examples/tp_table.rs b/examples/tp_table.rs index 73459290e8..c2347d7a9f 100644 --- a/examples/tp_table.rs +++ b/examples/tp_table.rs @@ -3,7 +3,7 @@ use ascii_table::{Align, AsciiTable}; use criterion::black_box; use lurk::{ eval::lang::{Coproc, Lang}, - lem::{eval::evaluate, multiframe::MultiFrame, store::Store}, + lem::{eval::evaluate, store::Store}, proof::nova::{public_params, NovaProver, PublicParams}, }; use num_traits::ToPrimitive; @@ -166,8 +166,7 @@ fn main() { let prover: NovaProver<'_, _, _> = NovaProver::new(rc, lang_arc.clone()); println!("Getting public params for rc={rc}"); // TODO: use cache once it's fixed - let pp: PublicParams<_, MultiFrame<'_, _, Coproc>> = - public_params(rc, lang_arc.clone()); + let pp: PublicParams<_> = public_params(rc, lang_arc.clone()); let n_folds_data = (0..=max_n_folds) .map(|n_folds| { let n_frames = n_iters(n_folds, rc); diff --git a/src/cli/lurk_proof.rs b/src/cli/lurk_proof.rs index 1ccc37dea9..9488c6abb6 100644 --- a/src/cli/lurk_proof.rs +++ b/src/cli/lurk_proof.rs @@ -1,4 +1,4 @@ -use ::nova::traits::Engine; +use ::nova::traits::{Engine, SecEng}; use abomonation::Abomonation; use anyhow::{bail, Result}; use serde::{de::DeserializeOwned, Deserialize, Serialize}; @@ -10,7 +10,7 @@ use crate::{ field::LurkField, lem::{pointers::ZPtr, store::Store}, proof::{ - nova::{self, CurveCycleEquipped, C1LEM, E1, E2}, + nova::{self, CurveCycleEquipped, C1LEM, E1}, RecursiveSNARKTrait, }, public_parameters::{ @@ -122,13 +122,9 @@ impl LurkProofMeta { #[non_exhaustive] #[derive(Serialize, Deserialize)] #[serde(bound(serialize = "F: Serialize", deserialize = "F: DeserializeOwned"))] -pub(crate) enum LurkProof< - 'a, - F: CurveCycleEquipped, - C: Coprocessor + Serialize + DeserializeOwned, -> { +pub(crate) enum LurkProof + Serialize + DeserializeOwned> { Nova { - proof: nova::Proof>, + proof: nova::Proof, public_inputs: Vec, public_outputs: Vec, rc: usize, @@ -137,15 +133,15 @@ pub(crate) enum LurkProof< } impl<'a, F: CurveCycleEquipped, C: Coprocessor + 'a + Serialize + DeserializeOwned> - HasFieldModulus for LurkProof<'a, F, C> + HasFieldModulus for LurkProof { fn field_modulus() -> String { F::MODULUS.to_owned() } } -impl<'a, F: CurveCycleEquipped + Serialize, C: Coprocessor + Serialize + DeserializeOwned> - LurkProof<'a, F, C> +impl + Serialize + DeserializeOwned> + LurkProof { #[inline] pub(crate) fn persist(self, proof_key: &str) -> Result<()> { @@ -155,8 +151,8 @@ impl<'a, F: CurveCycleEquipped + Serialize, C: Coprocessor + Serialize + Dese impl< F: CurveCycleEquipped + DeserializeOwned, - C: Coprocessor + Serialize + DeserializeOwned + 'static, - > LurkProof<'static, F, C> + C: Coprocessor + Serialize + DeserializeOwned, + > LurkProof { #[inline] pub(crate) fn is_cached(proof_key: &str) -> bool { @@ -166,11 +162,11 @@ impl< impl< F: CurveCycleEquipped + DeserializeOwned, - C: Coprocessor + Serialize + DeserializeOwned + 'static, - > LurkProof<'static, F, C> + C: Coprocessor + Serialize + DeserializeOwned, + > LurkProof where < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, { pub(crate) fn verify_proof(proof_key: &str) -> Result<()> { let lurk_proof = load::(&proof_path(proof_key))?; @@ -195,7 +191,12 @@ where let instance = Instance::new(*rc, Arc::new(lang.clone()), true, Kind::NovaPublicParams); let pp = public_params(&instance)?; - Ok(proof.verify(&pp, public_inputs, public_outputs)?) + Ok(RecursiveSNARKTrait::<_, C1LEM<'_, F, C>>::verify( + proof, + &pp, + public_inputs, + public_outputs, + )?) } } } diff --git a/src/cli/repl/meta_cmd.rs b/src/cli/repl/meta_cmd.rs index 11e561ed9f..ccc25418b5 100644 --- a/src/cli/repl/meta_cmd.rs +++ b/src/cli/repl/meta_cmd.rs @@ -1,4 +1,4 @@ -use ::nova::traits::Engine; +use ::nova::traits::{Engine, SecEng}; use abomonation::Abomonation; use anyhow::{anyhow, bail, Context, Result}; use camino::{Utf8Path, Utf8PathBuf}; @@ -22,7 +22,7 @@ use crate::{ }, package::{Package, SymbolRef}, proof::{ - nova::{self, CurveCycleEquipped, C1LEM, E1, E2}, + nova::{self, CurveCycleEquipped, C1LEM, E1}, RecursiveSNARKTrait, }, public_parameters::{ @@ -49,7 +49,7 @@ impl< > MetaCmd where < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, { const LOAD: MetaCmd = MetaCmd { name: "load", @@ -962,7 +962,7 @@ where let mut z_dag = ZDag::default(); let z_ptr = z_dag.populate_with(&args, &repl.store, &mut Default::default()); let args = LurkData { z_ptr, z_dag }; - match load::>(&proof_path(&proof_key))? { + match load::>(&proof_path(&proof_key))? { LurkProof::Nova { proof, .. } => { dump(ProtocolProof::Nova { args, proof }, &path)?; println!("Protocol proof saved at {path}"); @@ -992,7 +992,7 @@ where let (fun, proto_rc) = Self::get_fun_and_rc(repl, ptcl)?; - match load::>(&path)? { + match load::>(&path)? { ProtocolProof::Nova { args: LurkData { z_ptr, z_dag }, proof, @@ -1010,7 +1010,8 @@ where Instance::new(proto_rc, repl.lang.clone(), true, Kind::NovaPublicParams); let pp = public_params(&instance)?; - if !proof.verify( + if !RecursiveSNARKTrait::<_, C1LEM<'_, F, C>>::verify( + &proof, &pp, &repl.store.to_scalar_vector(&cek_io[..3]), &repl.store.to_scalar_vector(&cek_io[3..]), @@ -1096,22 +1097,17 @@ fn get_path + Serialize + DeserializeOwned>( #[non_exhaustive] #[derive(Serialize, Deserialize)] #[serde(bound(serialize = "F: Serialize", deserialize = "F: DeserializeOwned"))] -enum ProtocolProof<'a, F: CurveCycleEquipped, C: Coprocessor + Serialize + DeserializeOwned> -where - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, -{ +enum ProtocolProof { Nova { args: LurkData, - proof: nova::Proof>, + proof: nova::Proof, }, } -impl<'a, F: CurveCycleEquipped, C: Coprocessor + 'a + Serialize + DeserializeOwned> - HasFieldModulus for ProtocolProof<'a, F, C> +impl HasFieldModulus for ProtocolProof where < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, { fn field_modulus() -> String { F::MODULUS.to_owned() diff --git a/src/cli/repl/mod.rs b/src/cli/repl/mod.rs index 7d2a72e76c..0fddc928ae 100644 --- a/src/cli/repl/mod.rs +++ b/src/cli/repl/mod.rs @@ -3,7 +3,7 @@ mod meta_cmd; use abomonation::Abomonation; use anyhow::{anyhow, bail, Context, Result}; use camino::{Utf8Path, Utf8PathBuf}; -use nova::traits::Engine; +use nova::traits::{Engine, SecEng}; use rustyline::{ error::ReadlineError, history::DefaultHistory, @@ -39,7 +39,7 @@ use crate::{ }, parser, proof::{ - nova::{CurveCycleEquipped, NovaProver, E1, E2}, + nova::{CurveCycleEquipped, NovaProver, C1LEM, E1}, RecursiveSNARKTrait, }, public_parameters::{ @@ -167,7 +167,7 @@ impl< > Repl where < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, { pub(crate) fn new( store: Store, @@ -342,9 +342,14 @@ where let (proof, public_inputs, public_outputs, num_steps) = prover.prove_from_frames(&pp, frames, &self.store)?; info!("Compressing proof"); - let proof = proof.compress(&pp)?; + let proof = RecursiveSNARKTrait::<_, C1LEM<'_, F, C>>::compress(proof, &pp)?; assert_eq!(self.rc * num_steps, pad(n_frames, self.rc)); - assert!(proof.verify(&pp, &public_inputs, &public_outputs)?); + assert!(RecursiveSNARKTrait::<_, C1LEM<'_, F, C>>::verify( + &proof, + &pp, + &public_inputs, + &public_outputs + )?); let lurk_proof = LurkProof::Nova { proof, diff --git a/src/lem/multiframe.rs b/src/lem/multiframe.rs index 9fc1cfe5f9..89f7783372 100644 --- a/src/lem/multiframe.rs +++ b/src/lem/multiframe.rs @@ -15,7 +15,7 @@ use crate::{ eval::lang::Lang, field::{LanguageField, LurkField}, proof::{ - nova::{CurveCycleEquipped, E1, E2}, + nova::{CurveCycleEquipped, E1}, supernova::{FoldingConfig, C2}, CEKState, EvaluationStore, FrameLike, Provable, }, @@ -898,11 +898,14 @@ impl<'a, F: LurkField, C: Coprocessor> nova::supernova::StepCircuit for Mu } } -impl<'a, F, C> NonUniformCircuit, E2, MultiFrame<'a, F, C>, C2> for MultiFrame<'a, F, C> +impl<'a, F, C> NonUniformCircuit> for MultiFrame<'a, F, C> where F: CurveCycleEquipped + LurkField, C: Coprocessor + 'a, { + type C1 = MultiFrame<'a, F, C>; + type C2 = C2; + fn num_circuits(&self) -> usize { assert_eq!(self.pc, 0); self.get_lang().coprocessor_count() + 1 diff --git a/src/proof/mod.rs b/src/proof/mod.rs index 86cdf7a0a6..69800d4231 100644 --- a/src/proof/mod.rs +++ b/src/proof/mod.rs @@ -15,7 +15,7 @@ pub mod supernova; #[cfg(test)] mod tests; -use ::nova::traits::Engine; +use ::nova::traits::{Engine, SecEng}; use std::sync::Arc; use crate::{ @@ -24,7 +24,7 @@ use crate::{ eval::lang::Lang, field::LurkField, lem::{eval::EvalConfig, pointers::Ptr, store::Store}, - proof::nova::E2, + proof::nova::E1, }; use self::{nova::CurveCycleEquipped, supernova::FoldingConfig}; @@ -111,9 +111,9 @@ where /// Return the `z0_secondary` #[inline] - fn z0_secondary() -> Vec<::Scalar> { + fn z0_secondary() -> Vec<> as Engine>::Scalar> { use ff::Field; - vec![ as Engine>::Scalar::ZERO] + vec![> as Engine>::Scalar::ZERO] } } diff --git a/src/proof/nova.rs b/src/proof/nova.rs index 0e5c887d77..9345f635c8 100644 --- a/src/proof/nova.rs +++ b/src/proof/nova.rs @@ -2,12 +2,12 @@ use bellpepper_core::{num::AllocatedNum, ConstraintSystem}; use halo2curves::bn256::Fr as Bn256Scalar; use nova::{ errors::NovaError, - provider::{Bn256Engine, GrumpkinEngine, PallasEngine, VestaEngine}, + provider::{Bn256Engine, PallasEngine}, traits::{ circuit::{StepCircuit, TrivialCircuit}, evaluation::EvaluationEngineTrait, snark::RelaxedR1CSSNARKTrait, - Engine, + CurveCycleEquipped as NovaCurveCycleEquipped, Engine, SecEng, }, CompressedSNARK, ProverKey, R1CSWithArity, RecursiveSNARK, VerifierKey, }; @@ -43,40 +43,32 @@ pub trait CurveCycleEquipped: LurkField { /// /// The following abstracts over curve cycle groups for which there exists an implementation of [`nova::traits::evaluation::EvaluationEngineTrait`], /// encapsulating these idiosyncracies within Nova. + type E1: NovaCurveCycleEquipped; /// a concrete implementation of an [`nova::traits::evaluation::EvaluationEngineTrait`] for G1, type EE1: EvaluationEngineTrait; /// a concrete implementation of an [`nova::traits::evaluation::EvaluationEngineTrait`] for G2, - type EE2: EvaluationEngineTrait; - - /// The group type for the first curve in the cycle. - type E1: Engine::Scalar, Scalar = Self>; - /// The group type for the second curve in the cycle. - type E2: Engine::Scalar>; + type EE2: EvaluationEngineTrait>; } impl CurveCycleEquipped for pallas::Scalar { - type EE1 = nova::provider::ipa_pc::EvaluationEngine; - type EE2 = nova::provider::ipa_pc::EvaluationEngine; - type E1 = PallasEngine; - type E2 = VestaEngine; + + type EE1 = nova::provider::ipa_pc::EvaluationEngine; + type EE2 = nova::provider::ipa_pc::EvaluationEngine>; } // The impl CurveCycleEquipped for vesta::Scalar is academically possible, but voluntarily omitted to avoid confusion. impl CurveCycleEquipped for Bn256Scalar { type EE1 = nova::provider::ipa_pc::EvaluationEngine; - type EE2 = nova::provider::ipa_pc::EvaluationEngine; + type EE2 = nova::provider::ipa_pc::EvaluationEngine>; type E1 = Bn256Engine; - type E2 = GrumpkinEngine; } // The impl CurveCycleEquipped for grumpkin::Scalar is academically possible, but voluntarily omitted to avoid confusion. /// Convenience alias for the primary group type pegged to a LurkField through a CurveCycleEquipped type. pub type E1 = ::E1; -/// Convenience alias for the secondary group type pegged to a LurkField through a CurveCycleEquipped type. -pub type E2 = ::E2; /// Type alias for the Evaluation Engine using G1 group elements. pub type EE1 = ::EE1; @@ -90,42 +82,40 @@ pub type SS1 = nova::spartan::snark::RelaxedR1CSSNARK, EE1>; /// Type alias for the Relaxed R1CS Spartan SNARK using G2 group elements, EE2. // NOTE: this is not a SNARK that uses computational commitments, // that SNARK would be found at nova::spartan::ppsnark::RelaxedR1CSSNARK, -pub type SS2 = nova::spartan::snark::RelaxedR1CSSNARK, EE2>; +pub type SS2 = nova::spartan::snark::RelaxedR1CSSNARK>, EE2>; /// Type alias for a MultiFrame with S1 field elements. /// This uses the <::G1 as Group>::Scalar type for the G1 scalar field elements /// to reflect it this should not be used outside the Nova context pub type C1LEM<'a, F, C> = crate::lem::multiframe::MultiFrame<'a, F, C>; /// Type alias for a Trivial Test Circuit with G2 scalar field elements. -pub type C2 = TrivialCircuit< as Engine>::Scalar>; +pub type C2 = TrivialCircuit<> as Engine>::Scalar>; /// Type alias for Nova Circuit Parameters with the curve cycle types defined above. pub type NovaCircuitShape = R1CSWithArity>; /// Type alias for Nova Public Parameters with the curve cycle types defined above. -pub type NovaPublicParams = nova::PublicParams, E2, C1, C2>; +pub type NovaPublicParams = nova::PublicParams>; /// A struct that contains public parameters for the Nova proving system. #[derive(Serialize, Deserialize)] #[serde(bound = "")] -pub struct PublicParams> +pub struct PublicParams where F: CurveCycleEquipped, { /// Public parameters for the Nova proving system. - pub pp: NovaPublicParams, + pub pp: NovaPublicParams, /// Prover and verifier key for final proof compression #[serde(skip)] pk_and_vk: OnceCell<( - ProverKey, E2, SC, C2, SS1, SS2>, - VerifierKey, E2, SC, C2, SS1, SS2>, + ProverKey, SS1, SS2>, + VerifierKey, SS1, SS2>, )>, } // this avoids dipping into the pk/vk -impl + std::fmt::Debug> std::fmt::Debug - for PublicParams -{ +impl std::fmt::Debug for PublicParams { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("PublicParams") .field("pp", &self.pp) @@ -133,28 +123,26 @@ impl + std::fmt::Debug> std::fmt::Debu } } -impl> PublicParams { +impl PublicParams { /// provides a reference to a ProverKey suitable for producing a CompressedProof - pub fn pk(&self) -> &ProverKey, E2, SC, C2, SS1, SS2> { - let (pk, _vk) = self.pk_and_vk.get_or_init(|| { - CompressedSNARK::, E2, SC, C2, SS1, SS2>::setup(&self.pp).unwrap() - }); + pub fn pk(&self) -> &ProverKey, SS1, SS2> { + let (pk, _vk) = self + .pk_and_vk + .get_or_init(|| CompressedSNARK::, SS1, SS2>::setup(&self.pp).unwrap()); pk } /// provides a reference to a VerifierKey suitable for verifying a CompressedProof - pub fn vk(&self) -> &VerifierKey, E2, SC, C2, SS1, SS2> { - let (_pk, vk) = self.pk_and_vk.get_or_init(|| { - CompressedSNARK::, E2, SC, C2, SS1, SS2>::setup(&self.pp).unwrap() - }); + pub fn vk(&self) -> &VerifierKey, SS1, SS2> { + let (_pk, vk) = self + .pk_and_vk + .get_or_init(|| CompressedSNARK::, SS1, SS2>::setup(&self.pp).unwrap()); vk } } -impl> From> - for PublicParams -{ - fn from(pp: NovaPublicParams) -> PublicParams { +impl From> for PublicParams { + fn from(pp: NovaPublicParams) -> PublicParams { PublicParams { pp, pk_and_vk: OnceCell::new(), @@ -165,16 +153,13 @@ impl> From> /// An enum representing the two types of proofs that can be generated and verified. #[derive(Serialize, Deserialize)] #[serde(bound = "")] -pub enum Proof> { +pub enum Proof { /// A proof for the intermediate steps of a recursive computation along with /// the number of steps used for verification - Recursive(Box, E2, C1, C2>>, usize), + Recursive(Box>>, usize), /// A proof for the final step of a recursive computation along with the number /// of steps used for verification - Compressed( - Box, E2, C1, C2, SS1, SS2>>, - usize, - ), + Compressed(Box, SS1, SS2>>, usize), } /// Computes a cache key of the primary circuit. The point is that if a circuit @@ -189,18 +174,18 @@ pub fn circuit_cache_key<'a, F: CurveCycleEquipped, C: Coprocessor + 'a>( ) -> F { let folding_config = Arc::new(FoldingConfig::new_ivc(lang, 2)); let circuit = C1LEM::<'a, F, C>::blank(folding_config, 0); - F::from(rc as u64) * nova::circuit_digest::(&circuit) + F::from(rc as u64) * nova::circuit_digest::(&circuit) } /// Generates the public parameters for the Nova proving system. pub fn public_params<'a, F: CurveCycleEquipped, C: Coprocessor + 'a>( reduction_count: usize, lang: Arc>, -) -> PublicParams> { +) -> PublicParams { let (circuit_primary, circuit_secondary) = circuits(reduction_count, lang); let commitment_size_hint1 = as RelaxedR1CSSNARKTrait>>::ck_floor(); - let commitment_size_hint2 = as RelaxedR1CSSNARKTrait>>::ck_floor(); + let commitment_size_hint2 = as RelaxedR1CSSNARKTrait>>>::ck_floor(); let pp = nova::PublicParams::setup( &circuit_primary, @@ -227,15 +212,15 @@ pub fn circuits<'a, F: CurveCycleEquipped, C: Coprocessor + 'a>( } impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait> - for Proof> + for Proof { - type PublicParams = PublicParams>; + type PublicParams = PublicParams; type ErrorType = NovaError; #[tracing::instrument(skip_all, name = "nova::prove_recursively")] fn prove_recursively( - pp: &PublicParams>, + pp: &PublicParams, z0: &[F], steps: Vec>, store: &Store, @@ -244,7 +229,7 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait>>::z0_secondary(); let circuit_secondary = TrivialCircuit::default(); @@ -252,8 +237,7 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait, E2, C1LEM<'a, F, C>, C2>> = - None; + let mut recursive_snark: Option>> = None; // the shadowing here is voluntary let recursive_snark = if lurk_config(None, None) @@ -282,7 +266,7 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait> RecursiveSNARKTrait> RecursiveSNARKTrait>) -> Result { + fn compress(self, pp: &PublicParams) -> Result { match self { Self::Recursive(recursive_snark, num_steps) => Ok(Self::Compressed( - Box::new(CompressedSNARK::<_, _, _, _, SS1, SS2>::prove( + Box::new(CompressedSNARK::<_, SS1, SS2>::prove( &pp.pp, pp.pk(), &recursive_snark, @@ -358,7 +342,7 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait Result { let (z0_primary, zi_primary) = (z0, zi); - let z0_secondary = Self::z0_secondary(); + let z0_secondary = >>::z0_secondary(); let zi_secondary = &z0_secondary; let (zi_primary_verified, zi_secondary_verified) = match self { @@ -399,10 +383,10 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor + 'a> NovaProver<'a, F, C> { /// Generate a proof from a sequence of frames pub fn prove_from_frames( &self, - pp: &PublicParams>, + pp: &PublicParams, frames: &[Frame], store: &'a Store, - ) -> Result<(Proof>, Vec, Vec, usize), ProofError> { + ) -> Result<(Proof, Vec, Vec, usize), ProofError> { let folding_config = self .folding_mode() .folding_config(self.lang().clone(), self.reduction_count()); @@ -419,8 +403,8 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor + 'a> NovaProver<'a, F, C> { impl<'a, F: CurveCycleEquipped, C: Coprocessor + 'a> Prover<'a, F, C1LEM<'a, F, C>> for NovaProver<'a, F, C> { - type PublicParams = PublicParams>; - type RecursiveSnark = Proof>; + type PublicParams = PublicParams; + type RecursiveSnark = Proof; #[inline] fn reduction_count(&self) -> usize { diff --git a/src/proof/supernova.rs b/src/proof/supernova.rs index 9809be3fea..4159b761d4 100644 --- a/src/proof/supernova.rs +++ b/src/proof/supernova.rs @@ -3,12 +3,11 @@ use nova::{ self, error::SuperNovaError, snark::{CompressedSNARK, ProverKey, VerifierKey}, - AuxParams, CircuitDigests, NonUniformCircuit, RecursiveSNARK, - StepCircuit as SuperStepCircuit, TrivialSecondaryCircuit, + AuxParams, CircuitDigests, NonUniformCircuit, RecursiveSNARK, TrivialSecondaryCircuit, }, traits::{ snark::{BatchedRelaxedR1CSSNARKTrait, RelaxedR1CSSNARKTrait}, - Engine, + Engine, SecEng, }, }; use once_cell::sync::OnceCell; @@ -29,7 +28,7 @@ use crate::{ field::LurkField, lem::{interpreter::Frame, pointers::Ptr, store::Store}, proof::{ - nova::{CurveCycleEquipped, NovaCircuitShape, E1, E2}, + nova::{CurveCycleEquipped, NovaCircuitShape, E1}, Prover, RecursiveSNARKTrait, }, }; @@ -37,48 +36,46 @@ use crate::{ use super::{nova::C1LEM, FoldingMode}; /// Type alias for a Trivial Test Circuit with G2 scalar field elements. -pub type C2 = TrivialSecondaryCircuit< as Engine>::Scalar>; +pub type C2 = TrivialSecondaryCircuit<> as Engine>::Scalar>; /// Type alias for SuperNova Aux Parameters with the curve cycle types defined above. -pub type SuperNovaAuxParams = AuxParams, E2>; +pub type SuperNovaAuxParams = AuxParams>; /// Type alias for SuperNova Public Parameters with the curve cycle types defined above. -pub type SuperNovaPublicParams = supernova::PublicParams, E2, C1, C2>; +pub type SuperNovaPublicParams = supernova::PublicParams>; /// A struct that contains public parameters for the SuperNova proving system. -pub struct PublicParams> { +pub struct PublicParams { /// Public params for SuperNova. - pub pp: SuperNovaPublicParams, + pub pp: SuperNovaPublicParams, /// Prover key and Verifier key for SuperNova // TODO: mark as #[serde(skip)] when serializing pub pk_and_vk: OnceCell<( - ProverKey, E2, SC, C2, SS1, SS2>, - VerifierKey, E2, SC, C2, SS1, SS2>, + ProverKey, SS1, SS2>, + VerifierKey, SS1, SS2>, )>, } -impl> PublicParams { +impl PublicParams { /// provides a reference to a ProverKey suitable for producing a CompressedProof - pub fn pk(&self) -> &ProverKey, E2, SC, C2, SS1, SS2> { - let (pk, _vk) = self.pk_and_vk.get_or_init(|| { - CompressedSNARK::, E2, SC, C2, SS1, SS2>::setup(&self.pp).unwrap() - }); + pub fn pk(&self) -> &ProverKey, SS1, SS2> { + let (pk, _vk) = self + .pk_and_vk + .get_or_init(|| CompressedSNARK::, SS1, SS2>::setup(&self.pp).unwrap()); pk } /// provides a reference to a VerifierKey suitable for verifying a CompressedProof - pub fn vk(&self) -> &VerifierKey, E2, SC, C2, SS1, SS2> { - let (_pk, vk) = self.pk_and_vk.get_or_init(|| { - CompressedSNARK::, E2, SC, C2, SS1, SS2>::setup(&self.pp).unwrap() - }); + pub fn vk(&self) -> &VerifierKey, SS1, SS2> { + let (_pk, vk) = self + .pk_and_vk + .get_or_init(|| CompressedSNARK::, SS1, SS2>::setup(&self.pp).unwrap()); vk } } -impl> From> - for PublicParams -{ - fn from(pp: SuperNovaPublicParams) -> PublicParams { +impl From> for PublicParams { + fn from(pp: SuperNovaPublicParams) -> PublicParams { PublicParams { pp, pk_and_vk: OnceCell::new(), @@ -86,7 +83,7 @@ impl> From> Index for PublicParams { +impl Index for PublicParams { type Output = NovaCircuitShape; fn index(&self, index: usize) -> &Self::Output { @@ -94,7 +91,7 @@ impl> Index for PublicPara } } -impl> PublicParams { +impl PublicParams { /// return the digest pub fn digest(&self) -> F { self.pp.digest() @@ -113,21 +110,21 @@ pub type SS1 = nova::spartan::batched::BatchedRelaxedR1CSSNARK, EE1> /// Type alias for the Relaxed R1CS Spartan SNARK using G2 group elements, EE2. // NOTE: this is not a SNARK that uses computational commitments, // that SNARK would be found at nova::spartan::ppsnark::RelaxedR1CSSNARK, -pub type SS2 = nova::spartan::snark::RelaxedR1CSSNARK, EE2>; +pub type SS2 = nova::spartan::snark::RelaxedR1CSSNARK>, EE2>; /// Generates the running claim params for the SuperNova proving system. -pub fn public_params<'a, F: CurveCycleEquipped, C: Coprocessor + 'a>( +pub fn public_params>( rc: usize, lang: Arc>, -) -> PublicParams> { +) -> PublicParams { let folding_config = Arc::new(FoldingConfig::new_nivc(lang, rc)); let non_uniform_circuit = C1LEM::<'a, F, C>::blank(folding_config, 0); // grab hints for the compressed SNARK variants we will use this with let commitment_size_hint1 = as BatchedRelaxedR1CSSNARKTrait>>::ck_floor(); - let commitment_size_hint2 = as RelaxedR1CSSNARKTrait>>::ck_floor(); + let commitment_size_hint2 = as RelaxedR1CSSNARKTrait>>>::ck_floor(); - let pp = SuperNovaPublicParams::>::setup( + let pp = SuperNovaPublicParams::::setup( &non_uniform_circuit, &*commitment_size_hint1, &*commitment_size_hint2, @@ -141,11 +138,11 @@ pub fn public_params<'a, F: CurveCycleEquipped, C: Coprocessor + 'a>( /// An enum representing the two types of proofs that can be generated and verified. #[derive(Serialize, Deserialize)] #[serde(bound = "")] -pub enum Proof> { +pub enum Proof { /// A proof for the intermediate steps of a recursive computation - Recursive(Box, E2>>), + Recursive(Box>>), /// A proof for the final step of a recursive computation - Compressed(Box, E2, C1, C2, SS1, SS2>>), + Compressed(Box, SS1, SS2>>), } /// A struct for the Nova prover that operates on field elements of type `F`. @@ -174,10 +171,10 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor + 'a> SuperNovaProver<'a, F, C /// Generate a proof from a sequence of frames pub fn prove_from_frames( &self, - pp: &PublicParams>, + pp: &PublicParams, frames: &[Frame], store: &'a Store, - ) -> Result<(Proof>, Vec, Vec, usize), ProofError> { + ) -> Result<(Proof, Vec, Vec, usize), ProofError> { let folding_config = self .folding_mode() .folding_config(self.lang().clone(), self.reduction_count()); @@ -192,23 +189,23 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor + 'a> SuperNovaProver<'a, F, C } impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait> - for Proof> + for Proof { - type PublicParams = PublicParams>; + type PublicParams = PublicParams; type ErrorType = SuperNovaError; #[tracing::instrument(skip_all, name = "supernova::prove_recursively")] fn prove_recursively( - pp: &PublicParams>, + pp: &PublicParams, z0: &[F], steps: Vec>, store: &Store, ) -> Result { - let mut recursive_snark_option: Option, E2>> = None; + let mut recursive_snark_option: Option>> = None; let z0_primary = z0; - let z0_secondary = Self::z0_secondary(); + let z0_secondary = >>::z0_secondary(); let mut prove_step = |i: usize, step: &C1LEM<'a, F, C>| { info!("prove_recursively, step {i}"); @@ -298,14 +295,11 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait>) -> Result { + fn compress(self, pp: &PublicParams) -> Result { match &self { Self::Recursive(recursive_snark) => { - let snark = CompressedSNARK::<_, _, _, _, SS1, SS2>::prove( - &pp.pp, - pp.pk(), - recursive_snark, - )?; + let snark = + CompressedSNARK::<_, SS1, SS2>::prove(&pp.pp, pp.pk(), recursive_snark)?; Ok(Self::Compressed(Box::new(snark))) } Self::Compressed(..) => Ok(self), @@ -314,7 +308,7 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait Result { let (z0_primary, zi_primary) = (z0, zi); - let z0_secondary = Self::z0_secondary(); + let z0_secondary = >>::z0_secondary(); let zi_secondary = &z0_secondary; let (zi_primary_verified, zi_secondary_verified) = match self { @@ -329,8 +323,8 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait> Prover<'a, F, C1LEM<'a, F, C>> for SuperNovaProver<'a, F, C> { - type PublicParams = PublicParams>; - type RecursiveSnark = Proof>; + type PublicParams = PublicParams; + type RecursiveSnark = Proof; #[inline] fn reduction_count(&self) -> usize { @@ -423,7 +417,7 @@ pub fn circuit_cache_key<'a, F: CurveCycleEquipped, C: Coprocessor + 'a>( let circuit = C1LEM::<'a, F, C>::blank(folding_config, 0); let num_circuits = circuit.num_circuits(); let circuit = circuit.primary_circuit(circuit_index); - F::from(rc as u64) * supernova::circuit_digest::(&circuit, num_circuits) + F::from(rc as u64) * supernova::circuit_digest::(&circuit, num_circuits) } /// Collects all the cache keys of supernova instance. We need all of them to compute diff --git a/src/proof/tests/mod.rs b/src/proof/tests/mod.rs index 649f8d3d10..cfedae1a6f 100644 --- a/src/proof/tests/mod.rs +++ b/src/proof/tests/mod.rs @@ -124,14 +124,15 @@ fn nova_test_full_aux2<'a, F: CurveCycleEquipped, C: Coprocessor + 'a>( let pp = public_params(reduction_count, lang.clone()); let (proof, z0, zi, _num_steps) = nova_prover.prove_from_frames(&pp, &frames, s).unwrap(); - let res = proof.verify(&pp, &z0, &zi); + let res = RecursiveSNARKTrait::<_, C1LEM<'_, _, C>>::verify(&proof, &pp, &z0, &zi); if res.is_err() { tracing::debug!("{:?}", &res); } assert!(res.unwrap()); - let compressed = proof.compress(&pp).unwrap(); - let res2 = compressed.verify(&pp, &z0, &zi); + let compressed: crate::proof::nova::Proof = + RecursiveSNARKTrait::<_, C1LEM<'_, _, C>>::compress(proof, &pp).unwrap(); + let res2 = RecursiveSNARKTrait::<_, C1LEM<'_, _, C>>::verify(&compressed, &pp, &z0, &zi); assert!(res2.unwrap()); } diff --git a/src/public_parameters/disk_cache.rs b/src/public_parameters/disk_cache.rs index 0f23913fa1..87fa3345eb 100644 --- a/src/public_parameters/disk_cache.rs +++ b/src/public_parameters/disk_cache.rs @@ -7,7 +7,7 @@ use camino::{Utf8Path, Utf8PathBuf}; use crate::config::lurk_config; use crate::coprocessor::Coprocessor; -use crate::proof::nova::{CurveCycleEquipped, PublicParams, C1LEM}; +use crate::proof::nova::{CurveCycleEquipped, PublicParams}; use crate::public_parameters::error::Error; use super::instance::Instance; @@ -37,10 +37,7 @@ impl> DiskCache { }) } - pub(crate) fn read<'a>( - &self, - instance: &Instance, - ) -> Result>, Error> { + pub(crate) fn read(&self, instance: &Instance) -> Result, Error> { let file = instance.open(&self.dir)?; let reader = BufReader::new(file); bincode::deserialize_from(reader) @@ -61,7 +58,7 @@ impl> DiskCache { pub(crate) fn write( &self, instance: &Instance, - data: &PublicParams>, + data: &PublicParams, ) -> Result<(), Error> { let file = instance.create(&self.dir)?; let writer = BufWriter::new(&file); diff --git a/src/public_parameters/mod.rs b/src/public_parameters/mod.rs index 1afdbc9c38..f6b65786a5 100644 --- a/src/public_parameters/mod.rs +++ b/src/public_parameters/mod.rs @@ -1,12 +1,16 @@ -use ::nova::{supernova::FlatAuxParams, traits::Engine, FlatPublicParams}; +use ::nova::{ + supernova::FlatAuxParams, + traits::{Engine, SecEng}, + FlatPublicParams, +}; use abomonation::{decode, Abomonation}; use once_cell::sync::OnceCell; use tap::TapFallible; use tracing::{info, warn}; use crate::coprocessor::Coprocessor; -use crate::proof::nova::{self, NovaCircuitShape, NovaPublicParams, PublicParams, C1LEM}; -use crate::proof::nova::{CurveCycleEquipped, C2, E1, E2}; +use crate::proof::nova::{self, NovaCircuitShape, NovaPublicParams, PublicParams}; +use crate::proof::nova::{CurveCycleEquipped, E1}; pub mod disk_cache; mod error; @@ -17,12 +21,12 @@ use crate::public_parameters::disk_cache::{public_params_dir, DiskCache}; use crate::public_parameters::error::Error; use crate::public_parameters::instance::Instance; -pub fn public_params<'a, F: CurveCycleEquipped, C: Coprocessor + 'static>( +pub fn public_params>( instance: &Instance, -) -> Result>, Error> +) -> Result, Error> where < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, { let default = |instance: &Instance| nova::public_params(instance.rc, instance.lang()); @@ -35,13 +39,9 @@ where match disk_cache.read_bytes(instance, &mut bytes) { Ok(()) => { info!("loading abomonated {}", instance.key()); - let (pp, rest) = unsafe { - decode::, E2, C1LEM<'a, F, C>, C2>>(&mut bytes) - .unwrap() - }; + let (pp, rest) = unsafe { decode::>>(&mut bytes).unwrap() }; assert!(rest.is_empty()); - let pp = - PublicParams::from(NovaPublicParams::>::from(pp.clone())); // this clone is VERY expensive + let pp = PublicParams::from(NovaPublicParams::::from(pp.clone())); // this clone is VERY expensive Ok(pp) } Err(Error::IO(e)) => { @@ -54,9 +54,7 @@ where .write_abomonated(instance, &fp) .tap_ok(|_| info!("writing public params to disk-cache: {}", instance.key())) .map_err(|e| Error::Cache(format!("Disk write error: {e}")))?; - Ok(PublicParams::from( - NovaPublicParams::>::from(fp), - )) + Ok(PublicParams::from(NovaPublicParams::::from(fp))) } _ => unreachable!(), } @@ -81,7 +79,7 @@ pub fn supernova_circuit_params<'a, F: CurveCycleEquipped, C: Coprocessor + ' ) -> Result, Error> where < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, { let disk_cache = DiskCache::::new(public_params_dir()).unwrap(); @@ -102,14 +100,14 @@ pub fn supernova_aux_params<'a, F: CurveCycleEquipped, C: Coprocessor + 'a>( ) -> Result, Error> where < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, { let disk_cache = DiskCache::::new(public_params_dir()).unwrap(); let mut bytes = vec![]; disk_cache.read_bytes(instance, &mut bytes).and_then(|()| { if let Some((flat_aux_params, remaining)) = - unsafe { decode::, E2>>(&mut bytes) } + unsafe { decode::>>(&mut bytes) } { assert!(remaining.is_empty()); Ok(SuperNovaAuxParams::::from(flat_aux_params.clone())) @@ -122,14 +120,13 @@ where /// Attempts to extract abomonated public parameters. pub fn supernova_public_params<'a, F: CurveCycleEquipped, C: Coprocessor + 'a>( instance_primary: &Instance, -) -> Result>, Error> +) -> Result, Error> where < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, { - let default = |instance: &Instance| { - supernova::public_params::<'a, F, C>(instance.rc, instance.lang()) - }; + let default = + |instance: &Instance| supernova::public_params::(instance.rc, instance.lang()); let disk_cache = DiskCache::::new(public_params_dir()).unwrap(); let maybe_circuit_params_vec = instance_primary @@ -145,10 +142,7 @@ where { println!("generating public params"); - let pp = SuperNovaPublicParams::>::from_parts_unchecked( - circuit_params_vec, - aux_params, - ); + let pp = SuperNovaPublicParams::::from_parts_unchecked(circuit_params_vec, aux_params); supernova::PublicParams { pp, @@ -160,7 +154,7 @@ where let (circuit_params_vec, aux_params) = pp.pp.into_parts(); - let flat_aux_params = FlatAuxParams::, E2>::try_from(aux_params).unwrap(); + let flat_aux_params = FlatAuxParams::>::try_from(aux_params).unwrap(); disk_cache.write_abomonated(instance_primary, &flat_aux_params)?; let aux_params = SuperNovaAuxParams::::from(flat_aux_params); @@ -169,10 +163,7 @@ where disk_cache.write_abomonated(&instance, circuit_params)?; } - let pp = SuperNovaPublicParams::>::from_parts_unchecked( - circuit_params_vec, - aux_params, - ); + let pp = SuperNovaPublicParams::::from_parts_unchecked(circuit_params_vec, aux_params); supernova::PublicParams { pp, From 1b445948d4f67179ffecea92461cdb2a4092e33a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sun, 4 Feb 2024 20:29:52 -0500 Subject: [PATCH 03/10] refactor: Refactor to replace SecEng with Dual Alias - Consolidated the use of `nova` related code with the use of `seceng` being changed to `Dual` in various contexts across multiple files. --- src/cli/lurk_proof.rs | 8 ++++---- src/cli/repl/meta_cmd.rs | 14 +++++--------- src/cli/repl/mod.rs | 8 ++++---- src/proof/mod.rs | 9 ++++----- src/proof/nova.rs | 9 ++++++++- src/proof/supernova.rs | 6 +++--- src/public_parameters/mod.rs | 16 ++++++---------- 7 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/cli/lurk_proof.rs b/src/cli/lurk_proof.rs index 9488c6abb6..6601403a60 100644 --- a/src/cli/lurk_proof.rs +++ b/src/cli/lurk_proof.rs @@ -1,6 +1,6 @@ -use ::nova::traits::{Engine, SecEng}; use abomonation::Abomonation; use anyhow::{bail, Result}; +use ff::PrimeField; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::{collections::HashMap, sync::Arc}; @@ -10,7 +10,7 @@ use crate::{ field::LurkField, lem::{pointers::ZPtr, store::Store}, proof::{ - nova::{self, CurveCycleEquipped, C1LEM, E1}, + nova::{self, CurveCycleEquipped, Dual, C1LEM}, RecursiveSNARKTrait, }, public_parameters::{ @@ -165,8 +165,8 @@ impl< C: Coprocessor + Serialize + DeserializeOwned, > LurkProof where - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + F::Repr: Abomonation, + as PrimeField>::Repr: Abomonation, { pub(crate) fn verify_proof(proof_key: &str) -> Result<()> { let lurk_proof = load::(&proof_path(proof_key))?; diff --git a/src/cli/repl/meta_cmd.rs b/src/cli/repl/meta_cmd.rs index ccc25418b5..a1447f01ab 100644 --- a/src/cli/repl/meta_cmd.rs +++ b/src/cli/repl/meta_cmd.rs @@ -1,7 +1,7 @@ -use ::nova::traits::{Engine, SecEng}; use abomonation::Abomonation; use anyhow::{anyhow, bail, Context, Result}; use camino::{Utf8Path, Utf8PathBuf}; +use ff::PrimeField; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::{collections::HashMap, process}; @@ -22,7 +22,7 @@ use crate::{ }, package::{Package, SymbolRef}, proof::{ - nova::{self, CurveCycleEquipped, C1LEM, E1}, + nova::{self, CurveCycleEquipped, Dual, C1LEM}, RecursiveSNARKTrait, }, public_parameters::{ @@ -48,8 +48,8 @@ impl< C: Coprocessor + Serialize + DeserializeOwned + 'static, > MetaCmd where - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + F::Repr: Abomonation, + as PrimeField>::Repr: Abomonation, { const LOAD: MetaCmd = MetaCmd { name: "load", @@ -1104,11 +1104,7 @@ enum ProtocolProof { }, } -impl HasFieldModulus for ProtocolProof -where - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, -{ +impl HasFieldModulus for ProtocolProof { fn field_modulus() -> String { F::MODULUS.to_owned() } diff --git a/src/cli/repl/mod.rs b/src/cli/repl/mod.rs index 0fddc928ae..84d03fa53c 100644 --- a/src/cli/repl/mod.rs +++ b/src/cli/repl/mod.rs @@ -3,7 +3,7 @@ mod meta_cmd; use abomonation::Abomonation; use anyhow::{anyhow, bail, Context, Result}; use camino::{Utf8Path, Utf8PathBuf}; -use nova::traits::{Engine, SecEng}; +use ff::PrimeField; use rustyline::{ error::ReadlineError, history::DefaultHistory, @@ -39,7 +39,7 @@ use crate::{ }, parser, proof::{ - nova::{CurveCycleEquipped, NovaProver, C1LEM, E1}, + nova::{CurveCycleEquipped, Dual, NovaProver, C1LEM}, RecursiveSNARKTrait, }, public_parameters::{ @@ -166,8 +166,8 @@ impl< C: Coprocessor + Serialize + DeserializeOwned + 'static, > Repl where - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + F::Repr: Abomonation, + as PrimeField>::Repr: Abomonation, { pub(crate) fn new( store: Store, diff --git a/src/proof/mod.rs b/src/proof/mod.rs index 69800d4231..549aa53429 100644 --- a/src/proof/mod.rs +++ b/src/proof/mod.rs @@ -15,7 +15,7 @@ pub mod supernova; #[cfg(test)] mod tests; -use ::nova::traits::{Engine, SecEng}; +use ff::Field; use std::sync::Arc; use crate::{ @@ -24,7 +24,7 @@ use crate::{ eval::lang::Lang, field::LurkField, lem::{eval::EvalConfig, pointers::Ptr, store::Store}, - proof::nova::E1, + proof::nova::Dual, }; use self::{nova::CurveCycleEquipped, supernova::FoldingConfig}; @@ -111,9 +111,8 @@ where /// Return the `z0_secondary` #[inline] - fn z0_secondary() -> Vec<> as Engine>::Scalar> { - use ff::Field; - vec![> as Engine>::Scalar::ZERO] + fn z0_secondary() -> Vec> { + vec![Dual::::ZERO] } } diff --git a/src/proof/nova.rs b/src/proof/nova.rs index 9345f635c8..a48c9cf522 100644 --- a/src/proof/nova.rs +++ b/src/proof/nova.rs @@ -70,6 +70,13 @@ impl CurveCycleEquipped for Bn256Scalar { /// Convenience alias for the primary group type pegged to a LurkField through a CurveCycleEquipped type. pub type E1 = ::E1; +/// Convenience alias for the Dual field of a CurveCycleEquipped field. +/// By definition, this is both: +/// - the Base field for the associated Primary Engine, +/// - the Scalar field for the Secondary Engine. +pub type Dual = + <<::E1 as NovaCurveCycleEquipped>::Secondary as Engine>::Scalar; + /// Type alias for the Evaluation Engine using G1 group elements. pub type EE1 = ::EE1; /// Type alias for the Evaluation Engine using G2 group elements. @@ -89,7 +96,7 @@ pub type SS2 = nova::spartan::snark::RelaxedR1CSSNARK>, EE2>; /// to reflect it this should not be used outside the Nova context pub type C1LEM<'a, F, C> = crate::lem::multiframe::MultiFrame<'a, F, C>; /// Type alias for a Trivial Test Circuit with G2 scalar field elements. -pub type C2 = TrivialCircuit<> as Engine>::Scalar>; +pub type C2 = TrivialCircuit>; /// Type alias for Nova Circuit Parameters with the curve cycle types defined above. pub type NovaCircuitShape = R1CSWithArity>; diff --git a/src/proof/supernova.rs b/src/proof/supernova.rs index 4159b761d4..eb1b048d8d 100644 --- a/src/proof/supernova.rs +++ b/src/proof/supernova.rs @@ -7,7 +7,7 @@ use nova::{ }, traits::{ snark::{BatchedRelaxedR1CSSNARKTrait, RelaxedR1CSSNARKTrait}, - Engine, SecEng, + SecEng, }, }; use once_cell::sync::OnceCell; @@ -28,7 +28,7 @@ use crate::{ field::LurkField, lem::{interpreter::Frame, pointers::Ptr, store::Store}, proof::{ - nova::{CurveCycleEquipped, NovaCircuitShape, E1}, + nova::{CurveCycleEquipped, Dual, NovaCircuitShape, E1}, Prover, RecursiveSNARKTrait, }, }; @@ -36,7 +36,7 @@ use crate::{ use super::{nova::C1LEM, FoldingMode}; /// Type alias for a Trivial Test Circuit with G2 scalar field elements. -pub type C2 = TrivialSecondaryCircuit<> as Engine>::Scalar>; +pub type C2 = TrivialSecondaryCircuit>; /// Type alias for SuperNova Aux Parameters with the curve cycle types defined above. pub type SuperNovaAuxParams = AuxParams>; diff --git a/src/public_parameters/mod.rs b/src/public_parameters/mod.rs index f6b65786a5..34a6cb0a97 100644 --- a/src/public_parameters/mod.rs +++ b/src/public_parameters/mod.rs @@ -1,8 +1,4 @@ -use ::nova::{ - supernova::FlatAuxParams, - traits::{Engine, SecEng}, - FlatPublicParams, -}; +use ::nova::{supernova::FlatAuxParams, traits::Engine, FlatPublicParams}; use abomonation::{decode, Abomonation}; use once_cell::sync::OnceCell; use tap::TapFallible; @@ -10,7 +6,7 @@ use tracing::{info, warn}; use crate::coprocessor::Coprocessor; use crate::proof::nova::{self, NovaCircuitShape, NovaPublicParams, PublicParams}; -use crate::proof::nova::{CurveCycleEquipped, E1}; +use crate::proof::nova::{CurveCycleEquipped, Dual, E1}; pub mod disk_cache; mod error; @@ -26,7 +22,7 @@ pub fn public_params>( ) -> Result, Error> where < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + as ff::PrimeField>::Repr: Abomonation, { let default = |instance: &Instance| nova::public_params(instance.rc, instance.lang()); @@ -79,7 +75,7 @@ pub fn supernova_circuit_params<'a, F: CurveCycleEquipped, C: Coprocessor + ' ) -> Result, Error> where < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + as ff::PrimeField>::Repr: Abomonation, { let disk_cache = DiskCache::::new(public_params_dir()).unwrap(); @@ -100,7 +96,7 @@ pub fn supernova_aux_params<'a, F: CurveCycleEquipped, C: Coprocessor + 'a>( ) -> Result, Error> where < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + as ff::PrimeField>::Repr: Abomonation, { let disk_cache = DiskCache::::new(public_params_dir()).unwrap(); @@ -123,7 +119,7 @@ pub fn supernova_public_params<'a, F: CurveCycleEquipped, C: Coprocessor + 'a ) -> Result, Error> where < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, - <> as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + as ff::PrimeField>::Repr: Abomonation, { let default = |instance: &Instance| supernova::public_params::(instance.rc, instance.lang()); From 0e771ee70b052fb2f11af05a869c9cc888d0c233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sun, 4 Feb 2024 20:29:55 -0500 Subject: [PATCH 04/10] refactor: Improve readability through correct use of F - Simplified type declarations and trait bounds in `src/public_parameters/mod.rs` for improved readability - Updated `TestConstraintSystem` initialization in `src/proof/nova.rs` --- src/proof/nova.rs | 2 +- src/public_parameters/mod.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/proof/nova.rs b/src/proof/nova.rs index a48c9cf522..b9a45a52e6 100644 --- a/src/proof/nova.rs +++ b/src/proof/nova.rs @@ -293,7 +293,7 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait as Engine>::Scalar>::new(); + let mut cs = TestConstraintSystem::::new(); let zi = store.to_scalar_vector(circuit_primary.input()); let zi_allocated: Vec<_> = zi diff --git a/src/public_parameters/mod.rs b/src/public_parameters/mod.rs index 34a6cb0a97..ebb589a21c 100644 --- a/src/public_parameters/mod.rs +++ b/src/public_parameters/mod.rs @@ -1,4 +1,4 @@ -use ::nova::{supernova::FlatAuxParams, traits::Engine, FlatPublicParams}; +use ::nova::{supernova::FlatAuxParams, FlatPublicParams}; use abomonation::{decode, Abomonation}; use once_cell::sync::OnceCell; use tap::TapFallible; @@ -21,7 +21,7 @@ pub fn public_params>( instance: &Instance, ) -> Result, Error> where - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + ::Repr: Abomonation, as ff::PrimeField>::Repr: Abomonation, { let default = |instance: &Instance| nova::public_params(instance.rc, instance.lang()); @@ -74,7 +74,7 @@ pub fn supernova_circuit_params<'a, F: CurveCycleEquipped, C: Coprocessor + ' instance: &Instance, ) -> Result, Error> where - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + ::Repr: Abomonation, as ff::PrimeField>::Repr: Abomonation, { let disk_cache = DiskCache::::new(public_params_dir()).unwrap(); @@ -95,7 +95,7 @@ pub fn supernova_aux_params<'a, F: CurveCycleEquipped, C: Coprocessor + 'a>( instance: &Instance, ) -> Result, Error> where - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + ::Repr: Abomonation, as ff::PrimeField>::Repr: Abomonation, { let disk_cache = DiskCache::::new(public_params_dir()).unwrap(); @@ -118,7 +118,7 @@ pub fn supernova_public_params<'a, F: CurveCycleEquipped, C: Coprocessor + 'a instance_primary: &Instance, ) -> Result, Error> where - < as Engine>::Scalar as ff::PrimeField>::Repr: Abomonation, + ::Repr: Abomonation, as ff::PrimeField>::Repr: Abomonation, { let default = From 02e0ee1a6cb229056099bcc6c04ef84ce89ec7db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sun, 4 Feb 2024 20:29:58 -0500 Subject: [PATCH 05/10] refactor: avoid most pedantic instances of compress/verify --- benches/end2end.rs | 27 +++++---------------------- benches/sha256.rs | 12 +++--------- examples/circom.rs | 6 ++---- examples/sha256_ivc.rs | 18 +++++------------- examples/sha256_nivc.rs | 15 +++++---------- src/cli/lurk_proof.rs | 31 ++++++++++++++++--------------- src/cli/repl/meta_cmd.rs | 13 +++++++------ src/cli/repl/mod.rs | 11 +++-------- src/proof/nova.rs | 28 +++++++++++++++++----------- src/proof/supernova.rs | 33 ++++++++++++++++++--------------- src/proof/tests/mod.rs | 8 ++++---- 11 files changed, 85 insertions(+), 117 deletions(-) diff --git a/benches/end2end.rs b/benches/end2end.rs index 6b9aa2677c..e6e5602edb 100644 --- a/benches/end2end.rs +++ b/benches/end2end.rs @@ -12,10 +12,7 @@ use lurk::{ pointers::Ptr, store::Store, }, - proof::{ - nova::{NovaProver, C1LEM}, - RecursiveSNARKTrait, - }, + proof::{nova::NovaProver, RecursiveSNARKTrait}, public_parameters::{ self, instance::{Instance, Kind}, @@ -305,8 +302,7 @@ fn prove_compressed_benchmark(c: &mut Criterion) { b.iter(|| { let (proof, _, _, _) = prover.prove_from_frames(&pp, &frames, &store).unwrap(); - let compressed_result = - RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::compress(proof, &pp).unwrap(); + let compressed_result = proof.compress(&pp).unwrap(); black_box(compressed_result); }) }); @@ -354,13 +350,7 @@ fn verify_benchmark(c: &mut Criterion) { b.iter_batched( || z0.clone(), |z0| { - let result = RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::verify( - &proof, - &pp, - &z0, - &zi[..], - ) - .unwrap(); + let result = proof.verify(&pp, &z0, &zi[..]).unwrap(); black_box(result); }, BatchSize::LargeInput, @@ -410,19 +400,12 @@ fn verify_compressed_benchmark(c: &mut Criterion) { let (proof, z0, zi, _num_steps) = prover.prove_from_frames(&pp, &frames, &store).unwrap(); - let compressed_proof = - RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::compress(proof, &pp).unwrap(); + let compressed_proof = proof.compress(&pp).unwrap(); b.iter_batched( || z0.clone(), |z0| { - let result = RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::verify( - &compressed_proof, - &pp, - &z0, - &zi[..], - ) - .unwrap(); + let result = compressed_proof.verify(&pp, &z0, &zi[..]).unwrap(); black_box(result); }, BatchSize::LargeInput, diff --git a/benches/sha256.rs b/benches/sha256.rs index 2c7d385a00..b8f6d55a0e 100644 --- a/benches/sha256.rs +++ b/benches/sha256.rs @@ -15,18 +15,14 @@ use std::{cell::RefCell, rc::Rc, sync::Arc, time::Duration}; use lurk::{ coprocessor::sha256::{Sha256Coproc, Sha256Coprocessor}, - eval::lang::{Coproc, Lang}, + eval::lang::Lang, field::LurkField, lem::{ eval::{evaluate, make_cprocs_funcs_from_lang, make_eval_step_from_config, EvalConfig}, pointers::Ptr, store::Store, }, - proof::{ - nova::{NovaProver, C1LEM}, - supernova::SuperNovaProver, - RecursiveSNARKTrait, - }, + proof::{nova::NovaProver, supernova::SuperNovaProver, RecursiveSNARKTrait}, public_parameters::{ instance::{Instance, Kind}, public_params, supernova_public_params, @@ -224,9 +220,7 @@ fn sha256_ivc_prove_compressed( || frames, |frames| { let (proof, _, _, _) = prover.prove_from_frames(&pp, frames, store).unwrap(); - let compressed_result = - RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::compress(proof, &pp) - .unwrap(); + let compressed_result = proof.compress(&pp).unwrap(); let _ = black_box(compressed_result); }, diff --git a/examples/circom.rs b/examples/circom.rs index 71d3dc5c2e..5a934a9921 100644 --- a/examples/circom.rs +++ b/examples/circom.rs @@ -38,10 +38,9 @@ use lurk::circuit::gadgets::pointer::AllocatedPtr; #[cfg(not(target_arch = "wasm32"))] use lurk::coprocessor::circom::non_wasm::CircomCoprocessor; -use lurk::eval::lang::{Coproc, Lang}; +use lurk::eval::lang::Lang; use lurk::field::LurkField; use lurk::lem::{pointers::Ptr, store::Store}; -use lurk::proof::nova::C1LEM; use lurk::proof::{nova::NovaProver, Prover, RecursiveSNARKTrait}; use lurk::public_parameters::{ instance::{Instance, Kind}, @@ -134,8 +133,7 @@ fn main() { println!("Verifying proof..."); let verify_start = Instant::now(); - let res = - RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::verify(&proof, &pp, &z0, &zi).unwrap(); + let res = proof.verify(&pp, &z0, &zi).unwrap(); let verify_end = verify_start.elapsed(); println!("Verify took {verify_end:?}"); diff --git a/examples/sha256_ivc.rs b/examples/sha256_ivc.rs index 21d3ce7086..ce36b1822c 100644 --- a/examples/sha256_ivc.rs +++ b/examples/sha256_ivc.rs @@ -5,13 +5,10 @@ use tracing_texray::TeXRayLayer; use lurk::{ coprocessor::sha256::{Sha256Coproc, Sha256Coprocessor}, - eval::lang::{Coproc, Lang}, + eval::lang::Lang, field::LurkField, lem::{pointers::Ptr, store::Store}, - proof::{ - nova::{NovaProver, C1LEM}, - Prover, RecursiveSNARKTrait, - }, + proof::{nova::NovaProver, Prover, RecursiveSNARKTrait}, public_parameters::{ instance::{Instance, Kind}, public_params, @@ -100,17 +97,14 @@ fn main() { println!("Verifying proof..."); let verify_start = Instant::now(); - assert!( - RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::verify(&proof, &pp, &z0, &zi).unwrap() - ); + assert!(proof.verify(&pp, &z0, &zi).unwrap()); let verify_end = verify_start.elapsed(); println!("Verify took {:?}", verify_end); println!("Compressing proof.."); let compress_start = Instant::now(); - let compressed_proof = - RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::compress(proof, &pp).unwrap(); + let compressed_proof = proof.compress(&pp).unwrap(); let compress_end = compress_start.elapsed(); println!("Compression took {:?}", compress_end); @@ -119,9 +113,7 @@ fn main() { println!("proof size : {:}B", buf.len()); let compressed_verify_start = Instant::now(); - let res = - RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::verify(&compressed_proof, &pp, &z0, &zi) - .unwrap(); + let res = compressed_proof.verify(&pp, &z0, &zi).unwrap(); let compressed_verify_end = compressed_verify_start.elapsed(); println!("Final verification took {:?}", compressed_verify_end); diff --git a/examples/sha256_nivc.rs b/examples/sha256_nivc.rs index fdfdb7ea27..c7ab304645 100644 --- a/examples/sha256_nivc.rs +++ b/examples/sha256_nivc.rs @@ -5,14 +5,14 @@ use tracing_texray::TeXRayLayer; use lurk::{ coprocessor::sha256::{Sha256Coproc, Sha256Coprocessor}, - eval::lang::{Coproc, Lang}, + eval::lang::Lang, field::LurkField, lem::{ eval::{evaluate, make_cprocs_funcs_from_lang, make_eval_step_from_config, EvalConfig}, pointers::Ptr, store::Store, }, - proof::{nova::C1LEM, supernova::SuperNovaProver, RecursiveSNARKTrait}, + proof::{supernova::SuperNovaProver, RecursiveSNARKTrait}, public_parameters::{ instance::{Instance, Kind}, supernova_public_params, @@ -106,17 +106,14 @@ fn main() { println!("Verifying proof..."); let verify_start = Instant::now(); - assert!( - RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::verify(&proof, &pp, &z0, &zi).unwrap() - ); + assert!(proof.verify(&pp, &z0, &zi).unwrap()); let verify_end = verify_start.elapsed(); println!("Verify took {:?}", verify_end); println!("Compressing proof.."); let compress_start = Instant::now(); - let compressed_proof = - RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::compress(proof, &pp).unwrap(); + let compressed_proof = proof.compress(&pp).unwrap(); let compress_end = compress_start.elapsed(); println!("Compression took {:?}", compress_end); @@ -125,9 +122,7 @@ fn main() { println!("proof size : {:}B", buf.len()); let compressed_verify_start = Instant::now(); - let res = - RecursiveSNARKTrait::<_, C1LEM<'_, _, Coproc<_>>>::verify(&compressed_proof, &pp, &z0, &zi) - .unwrap(); + let res = compressed_proof.verify(&pp, &z0, &zi).unwrap(); let compressed_verify_end = compressed_verify_start.elapsed(); println!("Final verification took {:?}", compressed_verify_end); diff --git a/src/cli/lurk_proof.rs b/src/cli/lurk_proof.rs index 6601403a60..76cc2b7eeb 100644 --- a/src/cli/lurk_proof.rs +++ b/src/cli/lurk_proof.rs @@ -122,9 +122,13 @@ impl LurkProofMeta { #[non_exhaustive] #[derive(Serialize, Deserialize)] #[serde(bound(serialize = "F: Serialize", deserialize = "F: DeserializeOwned"))] -pub(crate) enum LurkProof + Serialize + DeserializeOwned> { +pub(crate) enum LurkProof< + 'a, + F: CurveCycleEquipped, + C: Coprocessor + Serialize + DeserializeOwned, +> { Nova { - proof: nova::Proof, + proof: nova::Proof>, public_inputs: Vec, public_outputs: Vec, rc: usize, @@ -133,15 +137,15 @@ pub(crate) enum LurkProof + Serialize + } impl<'a, F: CurveCycleEquipped, C: Coprocessor + 'a + Serialize + DeserializeOwned> - HasFieldModulus for LurkProof + HasFieldModulus for LurkProof<'a, F, C> { fn field_modulus() -> String { F::MODULUS.to_owned() } } -impl + Serialize + DeserializeOwned> - LurkProof +impl<'a, F: CurveCycleEquipped + Serialize, C: Coprocessor + Serialize + DeserializeOwned> + LurkProof<'a, F, C> { #[inline] pub(crate) fn persist(self, proof_key: &str) -> Result<()> { @@ -150,9 +154,10 @@ impl + Serialize + Deserial } impl< + 'a, F: CurveCycleEquipped + DeserializeOwned, - C: Coprocessor + Serialize + DeserializeOwned, - > LurkProof + C: Coprocessor + Serialize + DeserializeOwned + 'a, + > LurkProof<'a, F, C> { #[inline] pub(crate) fn is_cached(proof_key: &str) -> bool { @@ -161,9 +166,10 @@ impl< } impl< + 'a, F: CurveCycleEquipped + DeserializeOwned, - C: Coprocessor + Serialize + DeserializeOwned, - > LurkProof + C: Coprocessor + Serialize + DeserializeOwned + 'a, + > LurkProof<'a, F, C> where F::Repr: Abomonation, as PrimeField>::Repr: Abomonation, @@ -191,12 +197,7 @@ where let instance = Instance::new(*rc, Arc::new(lang.clone()), true, Kind::NovaPublicParams); let pp = public_params(&instance)?; - Ok(RecursiveSNARKTrait::<_, C1LEM<'_, F, C>>::verify( - proof, - &pp, - public_inputs, - public_outputs, - )?) + Ok(proof.verify(&pp, public_inputs, public_outputs)?) } } } diff --git a/src/cli/repl/meta_cmd.rs b/src/cli/repl/meta_cmd.rs index a1447f01ab..c4079d250a 100644 --- a/src/cli/repl/meta_cmd.rs +++ b/src/cli/repl/meta_cmd.rs @@ -1,3 +1,4 @@ +use ::nova::supernova::StepCircuit; use abomonation::Abomonation; use anyhow::{anyhow, bail, Context, Result}; use camino::{Utf8Path, Utf8PathBuf}; @@ -44,6 +45,7 @@ pub(super) struct MetaCmd + Serialize + Deserial } impl< + 'a, F: CurveCycleEquipped + Serialize + DeserializeOwned, C: Coprocessor + Serialize + DeserializeOwned + 'static, > MetaCmd @@ -992,7 +994,7 @@ where let (fun, proto_rc) = Self::get_fun_and_rc(repl, ptcl)?; - match load::>(&path)? { + match load::>>(&path)? { ProtocolProof::Nova { args: LurkData { z_ptr, z_dag }, proof, @@ -1010,8 +1012,7 @@ where Instance::new(proto_rc, repl.lang.clone(), true, Kind::NovaPublicParams); let pp = public_params(&instance)?; - if !RecursiveSNARKTrait::<_, C1LEM<'_, F, C>>::verify( - &proof, + if !proof.verify( &pp, &repl.store.to_scalar_vector(&cek_io[..3]), &repl.store.to_scalar_vector(&cek_io[3..]), @@ -1097,14 +1098,14 @@ fn get_path + Serialize + DeserializeOwned>( #[non_exhaustive] #[derive(Serialize, Deserialize)] #[serde(bound(serialize = "F: Serialize", deserialize = "F: DeserializeOwned"))] -enum ProtocolProof { +enum ProtocolProof { Nova { args: LurkData, - proof: nova::Proof, + proof: nova::Proof, }, } -impl HasFieldModulus for ProtocolProof { +impl> HasFieldModulus for ProtocolProof { fn field_modulus() -> String { F::MODULUS.to_owned() } diff --git a/src/cli/repl/mod.rs b/src/cli/repl/mod.rs index 84d03fa53c..bb55493174 100644 --- a/src/cli/repl/mod.rs +++ b/src/cli/repl/mod.rs @@ -39,7 +39,7 @@ use crate::{ }, parser, proof::{ - nova::{CurveCycleEquipped, Dual, NovaProver, C1LEM}, + nova::{CurveCycleEquipped, Dual, NovaProver}, RecursiveSNARKTrait, }, public_parameters::{ @@ -342,14 +342,9 @@ where let (proof, public_inputs, public_outputs, num_steps) = prover.prove_from_frames(&pp, frames, &self.store)?; info!("Compressing proof"); - let proof = RecursiveSNARKTrait::<_, C1LEM<'_, F, C>>::compress(proof, &pp)?; + let proof = proof.compress(&pp)?; assert_eq!(self.rc * num_steps, pad(n_frames, self.rc)); - assert!(RecursiveSNARKTrait::<_, C1LEM<'_, F, C>>::verify( - &proof, - &pp, - &public_inputs, - &public_outputs - )?); + assert!(proof.verify(&pp, &public_inputs, &public_outputs)?); let lurk_proof = LurkProof::Nova { proof, diff --git a/src/proof/nova.rs b/src/proof/nova.rs index b9a45a52e6..22915d7450 100644 --- a/src/proof/nova.rs +++ b/src/proof/nova.rs @@ -160,13 +160,17 @@ impl From> for PublicParams { /// An enum representing the two types of proofs that can be generated and verified. #[derive(Serialize, Deserialize)] #[serde(bound = "")] -pub enum Proof { +pub enum Proof { /// A proof for the intermediate steps of a recursive computation along with /// the number of steps used for verification - Recursive(Box>>, usize), + Recursive(Box>>, usize, PhantomData), /// A proof for the final step of a recursive computation along with the number /// of steps used for verification - Compressed(Box, SS1, SS2>>, usize), + Compressed( + Box, SS1, SS2>>, + usize, + PhantomData, + ), } /// Computes a cache key of the primary circuit. The point is that if a circuit @@ -219,7 +223,7 @@ pub fn circuits<'a, F: CurveCycleEquipped, C: Coprocessor + 'a>( } impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait> - for Proof + for Proof> { type PublicParams = PublicParams; @@ -236,7 +240,7 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait>>::z0_secondary(); + let z0_secondary = Self::z0_secondary(); let circuit_secondary = TrivialCircuit::default(); @@ -330,18 +334,20 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait) -> Result { match self { - Self::Recursive(recursive_snark, num_steps) => Ok(Self::Compressed( + Self::Recursive(recursive_snark, num_steps, _phantom) => Ok(Self::Compressed( Box::new(CompressedSNARK::<_, SS1, SS2>::prove( &pp.pp, pp.pk(), &recursive_snark, )?), num_steps, + PhantomData, )), Self::Compressed(..) => Ok(self), } @@ -349,14 +355,14 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait Result { let (z0_primary, zi_primary) = (z0, zi); - let z0_secondary = >>::z0_secondary(); + let z0_secondary = Self::z0_secondary(); let zi_secondary = &z0_secondary; let (zi_primary_verified, zi_secondary_verified) = match self { - Self::Recursive(p, num_steps) => { + Self::Recursive(p, num_steps, _phantom) => { p.verify(&pp.pp, *num_steps, z0_primary, &z0_secondary)? } - Self::Compressed(p, num_steps) => { + Self::Compressed(p, num_steps, _phantom) => { p.verify(pp.vk(), *num_steps, z0_primary, &z0_secondary)? } }; @@ -393,7 +399,7 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor + 'a> NovaProver<'a, F, C> { pp: &PublicParams, frames: &[Frame], store: &'a Store, - ) -> Result<(Proof, Vec, Vec, usize), ProofError> { + ) -> Result<(Proof>, Vec, Vec, usize), ProofError> { let folding_config = self .folding_mode() .folding_config(self.lang().clone(), self.reduction_count()); @@ -411,7 +417,7 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor + 'a> Prover<'a, F, C1LEM<'a, for NovaProver<'a, F, C> { type PublicParams = PublicParams; - type RecursiveSnark = Proof; + type RecursiveSnark = Proof>; #[inline] fn reduction_count(&self) -> usize { diff --git a/src/proof/supernova.rs b/src/proof/supernova.rs index eb1b048d8d..c8dded33c8 100644 --- a/src/proof/supernova.rs +++ b/src/proof/supernova.rs @@ -138,11 +138,11 @@ pub fn public_params>( /// An enum representing the two types of proofs that can be generated and verified. #[derive(Serialize, Deserialize)] #[serde(bound = "")] -pub enum Proof { +pub enum Proof { /// A proof for the intermediate steps of a recursive computation - Recursive(Box>>), + Recursive(Box>>, PhantomData), /// A proof for the final step of a recursive computation - Compressed(Box, SS1, SS2>>), + Compressed(Box, SS1, SS2>>, PhantomData), } /// A struct for the Nova prover that operates on field elements of type `F`. @@ -174,7 +174,7 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor + 'a> SuperNovaProver<'a, F, C pp: &PublicParams, frames: &[Frame], store: &'a Store, - ) -> Result<(Proof, Vec, Vec, usize), ProofError> { + ) -> Result<(Proof>, Vec, Vec, usize), ProofError> { let folding_config = self .folding_mode() .folding_config(self.lang().clone(), self.reduction_count()); @@ -189,7 +189,7 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor + 'a> SuperNovaProver<'a, F, C } impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait> - for Proof + for Proof> { type PublicParams = PublicParams; @@ -205,7 +205,7 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait>> = None; let z0_primary = z0; - let z0_secondary = >>::z0_secondary(); + let z0_secondary = Self::z0_secondary(); let mut prove_step = |i: usize, step: &C1LEM<'a, F, C>| { info!("prove_recursively, step {i}"); @@ -290,17 +290,18 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait) -> Result { match &self { - Self::Recursive(recursive_snark) => { + Self::Recursive(recursive_snark, _phantom) => { let snark = CompressedSNARK::<_, SS1, SS2>::prove(&pp.pp, pp.pk(), recursive_snark)?; - Ok(Self::Compressed(Box::new(snark))) + Ok(Self::Compressed(Box::new(snark), PhantomData)) } Self::Compressed(..) => Ok(self), } @@ -308,12 +309,14 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> RecursiveSNARKTrait Result { let (z0_primary, zi_primary) = (z0, zi); - let z0_secondary = >>::z0_secondary(); + let z0_secondary = Self::z0_secondary(); let zi_secondary = &z0_secondary; let (zi_primary_verified, zi_secondary_verified) = match self { - Self::Recursive(p) => p.verify(&pp.pp, z0_primary, &z0_secondary)?, - Self::Compressed(p) => p.verify(&pp.pp, pp.vk(), z0_primary, &z0_secondary)?, + Self::Recursive(p, _phantom) => p.verify(&pp.pp, z0_primary, &z0_secondary)?, + Self::Compressed(p, _phantom) => { + p.verify(&pp.pp, pp.vk(), z0_primary, &z0_secondary)? + } }; Ok(zi_primary == zi_primary_verified && zi_secondary == &zi_secondary_verified) @@ -324,7 +327,7 @@ impl<'a, F: CurveCycleEquipped, C: Coprocessor> Prover<'a, F, C1LEM<'a, F, C> for SuperNovaProver<'a, F, C> { type PublicParams = PublicParams; - type RecursiveSnark = Proof; + type RecursiveSnark = Proof>; #[inline] fn reduction_count(&self) -> usize { diff --git a/src/proof/tests/mod.rs b/src/proof/tests/mod.rs index cfedae1a6f..d7655d941f 100644 --- a/src/proof/tests/mod.rs +++ b/src/proof/tests/mod.rs @@ -124,15 +124,15 @@ fn nova_test_full_aux2<'a, F: CurveCycleEquipped, C: Coprocessor + 'a>( let pp = public_params(reduction_count, lang.clone()); let (proof, z0, zi, _num_steps) = nova_prover.prove_from_frames(&pp, &frames, s).unwrap(); - let res = RecursiveSNARKTrait::<_, C1LEM<'_, _, C>>::verify(&proof, &pp, &z0, &zi); + let res = proof.verify(&pp, &z0, &zi); if res.is_err() { tracing::debug!("{:?}", &res); } assert!(res.unwrap()); - let compressed: crate::proof::nova::Proof = - RecursiveSNARKTrait::<_, C1LEM<'_, _, C>>::compress(proof, &pp).unwrap(); - let res2 = RecursiveSNARKTrait::<_, C1LEM<'_, _, C>>::verify(&compressed, &pp, &z0, &zi); + let compressed: crate::proof::nova::Proof> = + proof.compress(&pp).unwrap(); + let res2 = compressed.verify(&pp, &z0, &zi); assert!(res2.unwrap()); } From 37c2072d44d202cd09188ae1d43735dfa7fbc512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sun, 4 Feb 2024 20:30:02 -0500 Subject: [PATCH 06/10] refactor: use default argument for Lang --- benches/common/fib.rs | 2 +- benches/end2end.rs | 10 +++++----- benches/fibonacci.rs | 2 +- benches/public_params.rs | 8 ++------ benches/synthesis.rs | 2 +- examples/tp_table.rs | 2 +- src/eval/lang.rs | 6 +++--- src/lem/eval.rs | 7 ++----- src/lem/multiframe.rs | 4 ++-- src/lem/tests/eval_tests.rs | 2 +- src/public_parameters/mod.rs | 2 +- 11 files changed, 20 insertions(+), 27 deletions(-) diff --git a/benches/common/fib.rs b/benches/common/fib.rs index f32c1844b9..e9426bd32a 100644 --- a/benches/common/fib.rs +++ b/benches/common/fib.rs @@ -68,7 +68,7 @@ fn compute_coeffs(store: &Store) -> (usize, usize) { store.intern_empty_env(), store.cont_outermost(), ]; - let lang: Lang> = Lang::new(); + let lang: Lang = Lang::new(); let mut coef_lin = 0; let coef_ang; let step_func = eval_step(); diff --git a/benches/end2end.rs b/benches/end2end.rs index e6e5602edb..d201c08d82 100644 --- a/benches/end2end.rs +++ b/benches/end2end.rs @@ -59,7 +59,7 @@ fn end2end_benchmark(c: &mut Criterion) { let reduction_count = DEFAULT_REDUCTION_COUNT; // setup - let lang_pallas = Lang::>::new(); + let lang_pallas = Lang::::new(); let lang_pallas_rc = Arc::new(lang_pallas.clone()); let store = Store::default(); @@ -234,7 +234,7 @@ fn prove_benchmark(c: &mut Criterion) { let state = State::init_lurk_state().rccell(); - let lang_pallas = Lang::>::new(); + let lang_pallas = Lang::::new(); let lang_pallas_rc = Arc::new(lang_pallas.clone()); // use cached public params @@ -282,7 +282,7 @@ fn prove_compressed_benchmark(c: &mut Criterion) { let state = State::init_lurk_state().rccell(); - let lang_pallas = Lang::>::new(); + let lang_pallas = Lang::::new(); let lang_pallas_rc = Arc::new(lang_pallas.clone()); // use cached public params @@ -324,7 +324,7 @@ fn verify_benchmark(c: &mut Criterion) { let state = State::init_lurk_state().rccell(); - let lang_pallas = Lang::>::new(); + let lang_pallas = Lang::::new(); let lang_pallas_rc = Arc::new(lang_pallas.clone()); // use cached public params @@ -377,7 +377,7 @@ fn verify_compressed_benchmark(c: &mut Criterion) { let state = State::init_lurk_state().rccell(); - let lang_pallas = Lang::>::new(); + let lang_pallas = Lang::::new(); let lang_pallas_rc = Arc::new(lang_pallas.clone()); // use cached public params diff --git a/benches/fibonacci.rs b/benches/fibonacci.rs index 9cbd85c5b1..5cdac5a357 100644 --- a/benches/fibonacci.rs +++ b/benches/fibonacci.rs @@ -80,7 +80,7 @@ fn fibonacci_prove( c: &mut BenchmarkGroup<'_, M>, ) { let limit = fib_limit(prove_params.fib_n, prove_params.reduction_count); - let lang_pallas = Lang::>::new(); + let lang_pallas = Lang::::new(); let lang_rc = Arc::new(lang_pallas.clone()); // use cached public params diff --git a/benches/public_params.rs b/benches/public_params.rs index df52634ee9..9332a6c6b1 100644 --- a/benches/public_params.rs +++ b/benches/public_params.rs @@ -1,8 +1,5 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion, SamplingMode}; -use lurk::{ - eval::lang::{Coproc, Lang}, - proof::nova, -}; +use lurk::{eval::lang::Lang, proof::nova}; use std::sync::Arc; use std::time::Duration; @@ -14,8 +11,7 @@ const DEFAULT_REDUCTION_COUNT: usize = 10; fn public_params_benchmark(c: &mut Criterion) { let mut group = c.benchmark_group("public_params_benchmark"); group.sampling_mode(SamplingMode::Flat); - let lang_pallas = - Lang::>::new(); + let lang_pallas = Lang::::new(); let lang_pallas_rc = Arc::new(lang_pallas); let reduction_count = DEFAULT_REDUCTION_COUNT; diff --git a/benches/synthesis.rs b/benches/synthesis.rs index c130df7e4b..661038ec8f 100644 --- a/benches/synthesis.rs +++ b/benches/synthesis.rs @@ -40,7 +40,7 @@ fn synthesize( c: &mut BenchmarkGroup<'_, M>, ) { let limit = 1_000_000; - let lang_rc = Arc::new(Lang::>::new()); + let lang_rc = Arc::new(Lang::::new()); let state = State::init_lurk_state().rccell(); c.bench_with_input( diff --git a/examples/tp_table.rs b/examples/tp_table.rs index c2347d7a9f..588accd9e2 100644 --- a/examples/tp_table.rs +++ b/examples/tp_table.rs @@ -157,7 +157,7 @@ fn main() { let frames = evaluate::>(None, program, &store, limit).unwrap(); - let lang = Lang::>::new(); + let lang = Lang::::new(); let lang_arc = Arc::new(lang.clone()); let mut data = Vec::with_capacity(rc_vec.len()); diff --git a/src/eval/lang.rs b/src/eval/lang.rs index 43ae0d0a58..0ad5f6ca65 100644 --- a/src/eval/lang.rs +++ b/src/eval/lang.rs @@ -73,7 +73,7 @@ pub enum Coproc { /// // TODO: Define a trait for the Hash and parameterize on that also. #[derive(Debug, Default, Clone, Deserialize, Serialize)] -pub struct Lang { +pub struct Lang> { /// An IndexMap that stores coprocessors with their associated `Sym` keys. coprocessors: IndexMap, _p: PhantomData, @@ -185,12 +185,12 @@ pub(crate) mod test { #[test] fn lang() { - Lang::>::new(); + Lang::::new(); } #[test] fn dummy_lang() { - let _lang = Lang::>::new_with_bindings(vec![( + let _lang = Lang::::new_with_bindings(vec![( sym!("coproc", "dummy"), DummyCoprocessor::new().into(), )]); diff --git a/src/lem/eval.rs b/src/lem/eval.rs index 6631b153ad..135ebf0731 100644 --- a/src/lem/eval.rs +++ b/src/lem/eval.rs @@ -1720,10 +1720,7 @@ fn make_thunk() -> Func { #[cfg(test)] mod tests { use super::*; - use crate::{ - eval::lang::{Coproc, Lang}, - lem::store::Store, - }; + use crate::{eval::lang::Lang, lem::store::Store}; use bellpepper_core::{test_cs::TestConstraintSystem, Comparable}; use expect_test::{expect, Expect}; use halo2curves::bn256::Fr; @@ -1734,7 +1731,7 @@ mod tests { let func = eval_step(); let frame = Frame::blank(func, 0, &store); let mut cs = TestConstraintSystem::::new(); - let lang: Lang> = Lang::new(); + let lang: Lang = Lang::new(); let _ = func.synthesize_frame_aux(&mut cs, &store, &frame, &lang); let expect_eq = |computed: usize, expected: Expect| { expected.assert_eq(&computed.to_string()); diff --git a/src/lem/multiframe.rs b/src/lem/multiframe.rs index 89f7783372..e269fb09fa 100644 --- a/src/lem/multiframe.rs +++ b/src/lem/multiframe.rs @@ -1045,7 +1045,7 @@ mod tests { let mut cs_clone = cs.clone(); - let lang = Lang::>::new(); + let lang = Lang::::new(); let output_sequential = synthesize_frames_sequential( &mut cs, @@ -1086,7 +1086,7 @@ mod tests { // not self-evaluating let expr = store.read_with_default_state("(+ 1 2)").unwrap(); - let lang = Arc::new(Lang::>::new()); + let lang = Arc::new(Lang::::new()); let mut frames = evaluate::>(None, expr, &store, 1).unwrap(); assert_eq!(frames.len(), 1); diff --git a/src/lem/tests/eval_tests.rs b/src/lem/tests/eval_tests.rs index ed19de2a10..0b3e39c393 100644 --- a/src/lem/tests/eval_tests.rs +++ b/src/lem/tests/eval_tests.rs @@ -87,7 +87,7 @@ fn do_test_aux>( lang, ) } else { - let lang = Lang::>::new(); + let lang = Lang::::new(); do_test( s, ptr, diff --git a/src/public_parameters/mod.rs b/src/public_parameters/mod.rs index ebb589a21c..01dc7202a2 100644 --- a/src/public_parameters/mod.rs +++ b/src/public_parameters/mod.rs @@ -184,7 +184,7 @@ mod tests { let tmp_dir = Builder::new().prefix("tmp").tempdir().unwrap(); std::env::set_var("LURK_PUBLIC_PARAMS", tmp_dir.path()); - let lang: Arc>> = Arc::new(Lang::new()); + let lang: Arc> = Arc::new(Lang::new()); let instance = Instance::new(10, lang, true, Kind::NovaPublicParams); // Without disk cache, writes to tmpfile let _public_params = public_params::>(&instance).unwrap(); From 4c67a2f18b95090150c5b4b923bda093dc134487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sun, 4 Feb 2024 20:30:06 -0500 Subject: [PATCH 07/10] chore: clippy --- benches/sha256.rs | 8 ++++---- src/cli/repl/meta_cmd.rs | 2 +- src/proof/supernova.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/benches/sha256.rs b/benches/sha256.rs index b8f6d55a0e..5ef0fce4a6 100644 --- a/benches/sha256.rs +++ b/benches/sha256.rs @@ -38,7 +38,7 @@ fn sha256_ivc( state: Rc>, arity: usize, n: usize, - input: &Vec, + input: &[usize], ) -> Ptr { assert_eq!(n, input.len()); let input = input @@ -128,7 +128,7 @@ fn sha256_ivc_prove( state.clone(), black_box(prove_params.arity), black_box(prove_params.n), - &(0..prove_params.n).collect(), + &(0..prove_params.n).collect::>(), ); let prover = NovaProver::new(prove_params.reduction_count, lang_rc.clone()); @@ -209,7 +209,7 @@ fn sha256_ivc_prove_compressed( state.clone(), black_box(prove_params.arity), black_box(prove_params.n), - &(0..prove_params.n).collect(), + &(0..prove_params.n).collect::>(), ); let prover = NovaProver::new(prove_params.reduction_count, lang_rc.clone()); @@ -293,7 +293,7 @@ fn sha256_nivc_prove( state.clone(), black_box(prove_params.arity), black_box(prove_params.n), - &(0..prove_params.n).collect(), + &(0..prove_params.n).collect::>(), ); let prover = SuperNovaProver::new(prove_params.reduction_count, lang_rc.clone()); diff --git a/src/cli/repl/meta_cmd.rs b/src/cli/repl/meta_cmd.rs index c4079d250a..5c38f148b4 100644 --- a/src/cli/repl/meta_cmd.rs +++ b/src/cli/repl/meta_cmd.rs @@ -964,7 +964,7 @@ where let mut z_dag = ZDag::default(); let z_ptr = z_dag.populate_with(&args, &repl.store, &mut Default::default()); let args = LurkData { z_ptr, z_dag }; - match load::>(&proof_path(&proof_key))? { + match load::>(&proof_path(&proof_key))? { LurkProof::Nova { proof, .. } => { dump(ProtocolProof::Nova { args, proof }, &path)?; println!("Protocol proof saved at {path}"); diff --git a/src/proof/supernova.rs b/src/proof/supernova.rs index c8dded33c8..a2efd6ed4b 100644 --- a/src/proof/supernova.rs +++ b/src/proof/supernova.rs @@ -118,7 +118,7 @@ pub fn public_params>( lang: Arc>, ) -> PublicParams { let folding_config = Arc::new(FoldingConfig::new_nivc(lang, rc)); - let non_uniform_circuit = C1LEM::<'a, F, C>::blank(folding_config, 0); + let non_uniform_circuit = C1LEM::<'_, F, C>::blank(folding_config, 0); // grab hints for the compressed SNARK variants we will use this with let commitment_size_hint1 = as BatchedRelaxedR1CSSNARKTrait>>::ck_floor(); From b5d413d541664f23bec744a2fc5a88c83765eda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Sun, 4 Feb 2024 20:30:09 -0500 Subject: [PATCH 08/10] chore: rename nova_tests_lem -> nova_tests --- src/proof/tests/mod.rs | 2 +- src/proof/tests/{nova_tests_lem.rs => nova_tests.rs} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/proof/tests/{nova_tests_lem.rs => nova_tests.rs} (100%) diff --git a/src/proof/tests/mod.rs b/src/proof/tests/mod.rs index d7655d941f..3bed17ed0b 100644 --- a/src/proof/tests/mod.rs +++ b/src/proof/tests/mod.rs @@ -1,4 +1,4 @@ -mod nova_tests_lem; +mod nova_tests; use bellpepper::util_cs::{metric_cs::MetricCS, witness_cs::WitnessCS, Comparable}; use bellpepper_core::{test_cs::TestConstraintSystem, Circuit, ConstraintSystem, Delta}; use expect_test::Expect; diff --git a/src/proof/tests/nova_tests_lem.rs b/src/proof/tests/nova_tests.rs similarity index 100% rename from src/proof/tests/nova_tests_lem.rs rename to src/proof/tests/nova_tests.rs From 31767f99b3aa648d7d125bf9eebee1e8fe492cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Mon, 5 Feb 2024 15:09:16 -0500 Subject: [PATCH 09/10] chore: rename SecEng -> DualEng --- src/proof/nova.rs | 12 ++++++------ src/proof/supernova.rs | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/proof/nova.rs b/src/proof/nova.rs index 22915d7450..88d78a5a84 100644 --- a/src/proof/nova.rs +++ b/src/proof/nova.rs @@ -7,7 +7,7 @@ use nova::{ circuit::{StepCircuit, TrivialCircuit}, evaluation::EvaluationEngineTrait, snark::RelaxedR1CSSNARKTrait, - CurveCycleEquipped as NovaCurveCycleEquipped, Engine, SecEng, + CurveCycleEquipped as NovaCurveCycleEquipped, Dual as DualEng, Engine, }, CompressedSNARK, ProverKey, R1CSWithArity, RecursiveSNARK, VerifierKey, }; @@ -48,20 +48,20 @@ pub trait CurveCycleEquipped: LurkField { /// a concrete implementation of an [`nova::traits::evaluation::EvaluationEngineTrait`] for G1, type EE1: EvaluationEngineTrait; /// a concrete implementation of an [`nova::traits::evaluation::EvaluationEngineTrait`] for G2, - type EE2: EvaluationEngineTrait>; + type EE2: EvaluationEngineTrait>; } impl CurveCycleEquipped for pallas::Scalar { type E1 = PallasEngine; type EE1 = nova::provider::ipa_pc::EvaluationEngine; - type EE2 = nova::provider::ipa_pc::EvaluationEngine>; + type EE2 = nova::provider::ipa_pc::EvaluationEngine>; } // The impl CurveCycleEquipped for vesta::Scalar is academically possible, but voluntarily omitted to avoid confusion. impl CurveCycleEquipped for Bn256Scalar { type EE1 = nova::provider::ipa_pc::EvaluationEngine; - type EE2 = nova::provider::ipa_pc::EvaluationEngine>; + type EE2 = nova::provider::ipa_pc::EvaluationEngine>; type E1 = Bn256Engine; } @@ -89,7 +89,7 @@ pub type SS1 = nova::spartan::snark::RelaxedR1CSSNARK, EE1>; /// Type alias for the Relaxed R1CS Spartan SNARK using G2 group elements, EE2. // NOTE: this is not a SNARK that uses computational commitments, // that SNARK would be found at nova::spartan::ppsnark::RelaxedR1CSSNARK, -pub type SS2 = nova::spartan::snark::RelaxedR1CSSNARK>, EE2>; +pub type SS2 = nova::spartan::snark::RelaxedR1CSSNARK>, EE2>; /// Type alias for a MultiFrame with S1 field elements. /// This uses the <::G1 as Group>::Scalar type for the G1 scalar field elements @@ -196,7 +196,7 @@ pub fn public_params<'a, F: CurveCycleEquipped, C: Coprocessor + 'a>( let (circuit_primary, circuit_secondary) = circuits(reduction_count, lang); let commitment_size_hint1 = as RelaxedR1CSSNARKTrait>>::ck_floor(); - let commitment_size_hint2 = as RelaxedR1CSSNARKTrait>>>::ck_floor(); + let commitment_size_hint2 = as RelaxedR1CSSNARKTrait>>>::ck_floor(); let pp = nova::PublicParams::setup( &circuit_primary, diff --git a/src/proof/supernova.rs b/src/proof/supernova.rs index a2efd6ed4b..619143c143 100644 --- a/src/proof/supernova.rs +++ b/src/proof/supernova.rs @@ -7,7 +7,7 @@ use nova::{ }, traits::{ snark::{BatchedRelaxedR1CSSNARKTrait, RelaxedR1CSSNARKTrait}, - SecEng, + Dual as DualEng, }, }; use once_cell::sync::OnceCell; @@ -110,7 +110,7 @@ pub type SS1 = nova::spartan::batched::BatchedRelaxedR1CSSNARK, EE1> /// Type alias for the Relaxed R1CS Spartan SNARK using G2 group elements, EE2. // NOTE: this is not a SNARK that uses computational commitments, // that SNARK would be found at nova::spartan::ppsnark::RelaxedR1CSSNARK, -pub type SS2 = nova::spartan::snark::RelaxedR1CSSNARK>, EE2>; +pub type SS2 = nova::spartan::snark::RelaxedR1CSSNARK>, EE2>; /// Generates the running claim params for the SuperNova proving system. pub fn public_params>( @@ -122,7 +122,7 @@ pub fn public_params>( // grab hints for the compressed SNARK variants we will use this with let commitment_size_hint1 = as BatchedRelaxedR1CSSNARKTrait>>::ck_floor(); - let commitment_size_hint2 = as RelaxedR1CSSNARKTrait>>>::ck_floor(); + let commitment_size_hint2 = as RelaxedR1CSSNARKTrait>>>::ck_floor(); let pp = SuperNovaPublicParams::::setup( &non_uniform_circuit, From 442f2715d8739227b28e997e354f3c1eb1ecb6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Mon, 5 Feb 2024 08:20:21 -0500 Subject: [PATCH 10/10] chore: point back to dev --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 711ad55f5b..549c33fd9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -121,7 +121,7 @@ clap = "4.3.17" ff = "0.13" metrics = "0.22.0" neptune = { git = "https://github.com/lurk-lab/neptune", branch = "dev", features = ["abomonation"] } -nova = { git = "https://github.com/lurk-lab/arecibo", branch = "type_simplifications", package = "arecibo", features = ["abomonate"]} +nova = { git = "https://github.com/lurk-lab/arecibo", branch = "dev", package = "arecibo", features = ["abomonate"]} once_cell = "1.18.0" pairing = { version = "0.23" } pasta_curves = { git = "https://github.com/lurk-lab/pasta_curves", branch = "dev" }