Skip to content

Commit

Permalink
refactor: Nova structs become generic on their field type (+ update N…
Browse files Browse the repository at this point in the history
…ova) (#556)

* refactor: Refactor Nova struct to make them generic on the field type

- makes all of our Nova-related structures generic in the type of the used primary scalar field, provided the field can be attached to a curve cycle with the suitable properties
- sets up the curve cycle attachments for the pallas::Scalar and bn256::Scalar fields,
- allows us to start using bn256.

- making public parameter caching generic,
- making clutch generic, or supporting SnarkPack,
- making fcomm generic, or supporting SnarkPack,
- making the repl generic.

- Implemented the `CurveCycleEquipped` trait, replacing previous curve-specific scalar types for improved generic programming over curve cycles.
- Updated various files, including `fcomm.rs`, `lurk_proof.rs`, `lib.rs` and `nova.rs` to accommodate the new `CurveCycleEquipped` type.
- Extended `LanguageField` enum with `BN256` and `Grumpkin` values and updated respective `fmt` display.
- Refactored the `public_params` function in `public_parameters/mod.rs and registry.rs` to use the new `CurveCycleEquipped` type.
- Modified proofs in `nova.rs` to work with the new `CurveCycleEquipped` type.
- Removed `nova` and `pasta_curves::pallas` dependencies from `lurk-tests.rs` and `registry.rs` respectively, demonstrating reduction in dependency.

* chore: update PR to latest Nova version
  • Loading branch information
huitseeker authored Jul 28, 2023
1 parent c1960b7 commit f36971e
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 194 deletions.
95 changes: 25 additions & 70 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ ff = "0.13"
log = "0.4.19"
metrics = "0.21.1"
neptune = { version = "10.0.0" }
nova = { package = "nova-snark", version = "0.22", default-features = false }
nova = { version = "0.23", default-features = false, package = "nova-snark" }
once_cell = "1.18.0"
pairing = { version = "0.23" }
pasta_curves = { version = "0.5.1" }
Expand Down
2 changes: 1 addition & 1 deletion examples/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn main() {
println!("Setting up public parameters...");

let pp_start = Instant::now();
let pp = public_params::<Sha256Coproc<Fr>>(REDUCTION_COUNT, lang_rc.clone()).unwrap();
let pp = public_params::<_, Sha256Coproc<Fr>>(REDUCTION_COUNT, lang_rc.clone()).unwrap();
let pp_end = pp_start.elapsed();

println!("Public parameters took {:?}", pp_end);
Expand Down
3 changes: 2 additions & 1 deletion fcomm/src/bin/fcomm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use log::info;
use lurk::proof::nova::CurveCycleEquipped;
use std::convert::TryFrom;
use std::env;
use std::fs::read_to_string;
Expand Down Expand Up @@ -492,7 +493,7 @@ fn opening_request<P: AsRef<Path>, F: LurkField + Serialize + DeserializeOwned>(
}

// Get proof from supplied path or else from stdin.
fn proof<'a, P: AsRef<Path>, F: LurkField>(
fn proof<'a, P: AsRef<Path>, F: CurveCycleEquipped>(
proof_path: Option<P>,
) -> Result<Proof<'a, F>, error::Error>
where
Expand Down
16 changes: 8 additions & 8 deletions fcomm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use proptest_derive::Arbitrary;

use ff::PrimeField;
use hex::FromHex;
use lurk::error::ReductionError;
#[cfg(not(target_arch = "wasm32"))]
use lurk::field::FWrap;
use lurk::{
Expand Down Expand Up @@ -38,6 +37,7 @@ use lurk_macros::serde_test;
#[cfg(not(target_arch = "wasm32"))]
use lurk::z_data;

use lurk::{error::ReductionError, proof::nova::CurveCycleEquipped};
use once_cell::sync::OnceCell;
use pasta_curves::pallas;
use rand::rngs::OsRng;
Expand Down Expand Up @@ -269,9 +269,9 @@ pub struct VerificationResult {
}

#[derive(Serialize, Deserialize)]
pub struct Proof<'a, F: LurkField> {
pub struct Proof<'a, F: CurveCycleEquipped> {
pub claim: Claim<F>,
pub proof: nova::Proof<'a, Coproc<S1>>,
pub proof: nova::Proof<'a, F, Coproc<F>>,
pub num_steps: usize,
pub reduction_count: ReductionCount,
}
Expand Down Expand Up @@ -632,7 +632,7 @@ impl<'a> Opening<S1> {
chain: bool,
only_use_cached_proofs: bool,
nova_prover: &'a NovaProver<S1, Coproc<S1>>,
pp: &'a PublicParams<'_, Coproc<S1>>,
pp: &'a PublicParams<'_, S1, Coproc<S1>>,
lang: Arc<Lang<S1, Coproc<S1>>>,
) -> Result<Proof<'a, S1>, Error> {
let claim = Self::apply(s, input, function, limit, chain, &lang)?;
Expand All @@ -653,7 +653,7 @@ impl<'a> Opening<S1> {
limit: usize,
only_use_cached_proofs: bool,
nova_prover: &'a NovaProver<S1, Coproc<S1>>,
pp: &'a PublicParams<'_, Coproc<S1>>,
pp: &'a PublicParams<'_, S1, Coproc<S1>>,
lang: Arc<Lang<S1, Coproc<S1>>>,
) -> Result<Proof<'a, S1>, Error> {
let input = request.input.expr.ptr(s, limit, &lang);
Expand Down Expand Up @@ -787,7 +787,7 @@ impl<'a> Proof<'a, S1> {
limit: usize,
only_use_cached_proofs: bool,
nova_prover: &'a NovaProver<S1, Coproc<S1>>,
pp: &'a PublicParams<'_, Coproc<S1>>,
pp: &'a PublicParams<'_, S1, Coproc<S1>>,
lang: Arc<Lang<S1, Coproc<S1>>>,
) -> Result<Self, Error> {
let env = supplied_env.unwrap_or_else(|| empty_sym_env(s));
Expand Down Expand Up @@ -825,7 +825,7 @@ impl<'a> Proof<'a, S1> {
limit: usize,
only_use_cached_proofs: bool,
nova_prover: &'a NovaProver<S1, Coproc<S1>>,
pp: &'a PublicParams<'_, Coproc<S1>>,
pp: &'a PublicParams<'_, S1, Coproc<S1>>,
lang: &Arc<Lang<S1, Coproc<S1>>>,
) -> Result<Self, Error> {
let reduction_count = nova_prover.reduction_count();
Expand Down Expand Up @@ -911,7 +911,7 @@ impl<'a> Proof<'a, S1> {

pub fn verify(
&self,
pp: &PublicParams<'_, Coproc<S1>>,
pp: &PublicParams<'_, S1, Coproc<S1>>,
lang: &Lang<S1, Coproc<S1>>,
) -> Result<VerificationResult, Error> {
let (public_inputs, public_outputs) = self.io_vecs(lang)?;
Expand Down
Loading

0 comments on commit f36971e

Please sign in to comment.