Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade CS #333

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ readme = "README.md"
repository = "https://github.com/Microsoft/Nova"
license-file = "LICENSE"
keywords = ["zkSNARKs", "cryptography", "proofs"]
rust-version="1.79.0"
rust-version = "1.79.0"

[dependencies]
bellpepper-core = { version="0.4.0", default-features = false }
bellpepper = { version="0.4.0", default-features = false }
ff = { version = "0.13.0", features = ["derive"] }
digest = "0.10"
sha3 = "0.10"
Expand All @@ -23,7 +21,6 @@ rand_chacha = "0.3"
subtle = "2.5"
pasta_curves = { version = "0.5", features = ["repr-c", "serde"] }
halo2curves = { version = "0.6.0", features = ["bits", "derive_serde"] }
neptune = { version = "13.0.0", default-features = false }
generic-array = "1.0.0"
num-bigint = { version = "0.4", features = ["serde", "rand"] }
num-traits = "0.2"
Expand Down Expand Up @@ -78,6 +75,4 @@ harness = false
default = ["halo2curves/asm"]
# Compiles in portable mode, w/o ISA extensions => binary can be executed on all systems.
portable = ["pasta-msm/portable"]
cuda = ["neptune/cuda", "neptune/pasta", "neptune/arity24"]
opencl = ["neptune/opencl", "neptune/pasta", "neptune/arity24"]
flamegraph = ["pprof/flamegraph", "pprof/criterion"]
2 changes: 1 addition & 1 deletion benches/compressed-snark.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![allow(non_snake_case)]

use bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};
use core::marker::PhantomData;
use criterion::{measurement::WallTime, *};
use ff::PrimeField;
use nova_snark::{
frontend::{num::AllocatedNum, ConstraintSystem, SynthesisError},
provider::{Bn256EngineKZG, GrumpkinEngine},
traits::{
circuit::{StepCircuit, TrivialCircuit},
Expand Down
2 changes: 1 addition & 1 deletion benches/compute-digest.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{marker::PhantomData, time::Duration};

use bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use ff::PrimeField;
use nova_snark::{
frontend::{num::AllocatedNum, ConstraintSystem, SynthesisError},
provider::{Bn256EngineKZG, GrumpkinEngine},
traits::{
circuit::{StepCircuit, TrivialCircuit},
Expand Down
2 changes: 1 addition & 1 deletion benches/ppsnark.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![allow(non_snake_case)]

use bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};
use core::marker::PhantomData;
use criterion::*;
use ff::PrimeField;
use nova_snark::{
frontend::{num::AllocatedNum, ConstraintSystem, SynthesisError},
provider::Bn256EngineKZG,
spartan::direct::DirectSNARK,
traits::{circuit::StepCircuit, Engine},
Expand Down
2 changes: 1 addition & 1 deletion benches/recursive-snark.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![allow(non_snake_case)]

use bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};
use core::marker::PhantomData;
use criterion::*;
use ff::PrimeField;
use nova_snark::{
frontend::{num::AllocatedNum, ConstraintSystem, SynthesisError},
provider::{Bn256EngineKZG, GrumpkinEngine},
traits::{
circuit::{StepCircuit, TrivialCircuit},
Expand Down
13 changes: 5 additions & 8 deletions benches/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
//! This code invokes a hand-written SHA-256 gadget from bellman/bellperson.
//! It also uses code from bellman/bellperson to compare circuit-generated digest with sha2 crate's output
#![allow(non_snake_case)]
use bellpepper::gadgets::{sha256::sha256, Assignment};
use bellpepper_core::{
boolean::{AllocatedBit, Boolean},
num::{AllocatedNum, Num},
ConstraintSystem, SynthesisError,
};
use core::marker::PhantomData;
use core::time::Duration;
use core::{marker::PhantomData, time::Duration};
use criterion::*;
use ff::{PrimeField, PrimeFieldBits};
use nova_snark::{
frontend::{
num::{AllocatedNum, Num},
sha256, AllocatedBit, Assignment, Boolean, ConstraintSystem, SynthesisError,
},
provider::{Bn256EngineKZG, GrumpkinEngine},
traits::{
circuit::{StepCircuit, TrivialCircuit},
Expand Down
9 changes: 4 additions & 5 deletions examples/and.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
//! This example executes a batch of 64-bit AND operations.
//! It performs the AND operation by first decomposing the operands into bits and then performing the operation bit-by-bit.
//! We execute a configurable number of AND operations per step of Nova's recursion.
use bellpepper_core::{
boolean::AllocatedBit, num::AllocatedNum, ConstraintSystem, LinearCombination, SynthesisError,
};
use core::marker::PhantomData;
use ff::Field;
use ff::{PrimeField, PrimeFieldBits};
use ff::{Field, PrimeField, PrimeFieldBits};
use flate2::{write::ZlibEncoder, Compression};
use nova_snark::{
frontend::{
num::AllocatedNum, AllocatedBit, ConstraintSystem, LinearCombination, SynthesisError,
},
provider::{Bn256EngineKZG, GrumpkinEngine},
traits::{
circuit::{StepCircuit, TrivialCircuit},
Expand Down
22 changes: 9 additions & 13 deletions examples/hashchain.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
//! This example proves the knowledge of preimage to a hash chain tail, with a configurable number of elements per hash chain node.
//! The output of each step tracks the current tail of the hash chain
use bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};
use ff::Field;
use flate2::{write::ZlibEncoder, Compression};
use generic_array::typenum::U24;
use neptune::{
circuit2::Elt,
sponge::{
api::{IOPattern, SpongeAPI, SpongeOp},
circuit::SpongeCircuit,
vanilla::{Mode::Simplex, Sponge, SpongeTrait},
},
Strength,
};
use nova_snark::{
provider::{Bn256EngineKZG, GrumpkinEngine},
frontend::{num::AllocatedNum, ConstraintSystem, SynthesisError},
provider::{
poseidon::{
Elt, IOPattern, Simplex, Sponge, SpongeAPI, SpongeCircuit, SpongeOp, SpongeTrait, Strength,
},
Bn256EngineKZG, GrumpkinEngine,
},
traits::{
circuit::{StepCircuit, TrivialCircuit},
snark::RelaxedR1CSSNARKTrait,
Expand Down Expand Up @@ -91,9 +87,9 @@ impl<G: Group> StepCircuit<G::Scalar> for HashChainCircuit<G> {
let acc = &mut ns;

sponge.start(parameter, None, acc);
neptune::sponge::api::SpongeAPI::absorb(&mut sponge, num_absorbs, &elt, acc);
SpongeAPI::absorb(&mut sponge, num_absorbs, &elt, acc);

let output = neptune::sponge::api::SpongeAPI::squeeze(&mut sponge, 1, acc);
let output = SpongeAPI::squeeze(&mut sponge, 1, acc);
sponge.finish(acc).unwrap();
Elt::ensure_allocated(&output[0], &mut ns.namespace(|| "ensure allocated"), true)?
};
Expand Down
2 changes: 1 addition & 1 deletion examples/minroot.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Demonstrates how to use Nova to produce a recursive proof of the correct execution of
//! iterations of the `MinRoot` function, thereby realizing a Nova-based verifiable delay function (VDF).
//! We execute a configurable number of iterations of the `MinRoot` function per step of Nova's recursion.
use bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};
use ff::Field;
use flate2::{write::ZlibEncoder, Compression};
use nova_snark::{
frontend::{num::AllocatedNum, ConstraintSystem, SynthesisError},
provider::{Bn256EngineKZG, GrumpkinEngine},
traits::{
circuit::{StepCircuit, TrivialCircuit},
Expand Down
18 changes: 7 additions & 11 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use crate::{
constants::{NUM_FE_WITHOUT_IO_FOR_CRHF, NUM_HASH_BITS},
frontend::{
num::AllocatedNum, AllocatedBit, Assignment, Boolean, ConstraintSystem, SynthesisError,
},
gadgets::{
ecc::AllocatedPoint,
r1cs::{AllocatedR1CSInstance, AllocatedRelaxedR1CSInstance},
Expand All @@ -19,12 +22,6 @@ use crate::{
},
Commitment,
};
use bellpepper::gadgets::Assignment;
use bellpepper_core::{
boolean::{AllocatedBit, Boolean},
num::AllocatedNum,
ConstraintSystem, SynthesisError,
};
use ff::Field;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -383,17 +380,16 @@ impl<'a, E: Engine, SC: StepCircuit<E::Base>> NovaAugmentedCircuit<'a, E, SC> {
mod tests {
use super::*;
use crate::{
bellpepper::{
constants::{BN_LIMB_WIDTH, BN_N_LIMBS},
frontend::{
r1cs::{NovaShape, NovaWitness},
solver::SatisfyingAssignment,
test_shape_cs::TestShapeCS,
},
constants::{BN_LIMB_WIDTH, BN_N_LIMBS},
gadgets::utils::scalar_as_base,
provider::{
poseidon::PoseidonConstantsCircuit,
{Bn256EngineKZG, GrumpkinEngine}, {PallasEngine, VestaEngine},
{Secp256k1Engine, Secq256k1Engine},
poseidon::PoseidonConstantsCircuit, Bn256EngineKZG, GrumpkinEngine, PallasEngine,
Secp256k1Engine, Secq256k1Engine, VestaEngine,
},
traits::{circuit::TrivialCircuit, snark::default_ck_hint},
};
Expand Down
3 changes: 1 addition & 2 deletions src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use bincode::Options;
use ff::PrimeField;
use serde::Serialize;
use sha3::{Digest, Sha3_256};
use std::io;
use std::marker::PhantomData;
use std::{io, marker::PhantomData};

use crate::constants::NUM_HASH_BITS;

Expand Down
6 changes: 4 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
use core::fmt::Debug;
use thiserror::Error;

use crate::frontend::SynthesisError;

/// Errors returned by Nova
#[derive(Clone, Debug, Eq, PartialEq, Error)]
#[non_exhaustive]
Expand Down Expand Up @@ -69,8 +71,8 @@ pub enum NovaError {
InternalError,
}

impl From<bellpepper_core::SynthesisError> for NovaError {
fn from(err: bellpepper_core::SynthesisError) -> Self {
impl From<SynthesisError> for NovaError {
fn from(err: SynthesisError) -> Self {
Self::SynthesisError {
reason: err.to_string(),
}
Expand Down
Loading