Skip to content

Commit

Permalink
Bump Arkworks to 0.5.0 (nexus-xyz#291)
Browse files Browse the repository at this point in the history
* Initial work towards bumping arkworks to move past patches.

* Bump Jolt.

* Rename generally for consistency with arkworks.

* Formatting.

* Clippy fixing

* Fix newline.
  • Loading branch information
sjudson authored Dec 3, 2024
1 parent d2f0ef7 commit fc96e11
Show file tree
Hide file tree
Showing 24 changed files with 155 additions and 187 deletions.
47 changes: 14 additions & 33 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,47 +52,28 @@ jsonrpsee = { version = "0.23", default-features = false }
sha3 = { version = "0.10", default-features = false }
hex = { version = "0.4.3" }

ark-crypto-primitives = { version = "0.4.0", features = [
ark-crypto-primitives = { version = "0.5.0", features = [
"r1cs",
"sponge",
"crh",
"merkle_tree",
] }
ark-std = "0.4.0"
ark-std = "0.5.0"

ark-relations = { version = "0.4.0" }
ark-r1cs-std = { version = "0.4.0" }
ark-relations = { version = "0.5.0" }
ark-r1cs-std = { version = "0.5.0" }

ark-ff = "0.4.0"
ark-ec = { version = "0.4.0", default-features = false }
ark-serialize = { version = "0.4.0", features = ["derive"] }
ark-poly = "0.4.0"
ark-poly-commit = "0.4.0"
ark-ff = "0.5.0"
ark-ec = { version = "0.5.0", default-features = false }
ark-serialize = { version = "0.5.0", features = ["derive"] }
ark-poly = "0.5.0"
ark-poly-commit = "0.5.0"

ark-bn254 = "0.4.0"
ark-grumpkin = { git = "https://github.com/arkworks-rs/curves/", rev = "8c0256a" }
ark-pallas = "0.4.0"
ark-vesta = "0.4.0"
ark-test-curves = { version = "0.4.2", features = ["bls12_381_curve"] }

[patch.crates-io]
ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitives", rev = "d27a5c8" }

ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std/", rev = "2ca3bd7" }

ark-ff = { git = "https://github.com/arkworks-rs/algebra/", rev = "2a80c54" }
ark-ec = { git = "https://github.com/arkworks-rs/algebra/", rev = "2a80c54" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra/", rev = "2a80c54" }
ark-poly = { git = "https://github.com/arkworks-rs/algebra/", rev = "2a80c54" }
ark-test-curves = { git = "https://github.com/arkworks-rs/algebra/", rev = "2a80c54" }

ark-poly-commit = { git = "https://github.com/arkworks-rs/poly-commit/", rev = "12f5529" }

# note bls is using a different commit from the other curves
ark-bn254 = { git = "https://github.com/arkworks-rs/curves/", rev = "8c0256a" }
ark-pallas = { git = "https://github.com/arkworks-rs/curves/", rev = "8c0256a" }
ark-vesta = { git = "https://github.com/arkworks-rs/curves/", rev = "8c0256a" }
ark-bls12-381 = { git = "https://github.com/arkworks-rs/curves/", rev = "3fded1f" }
ark-bn254 = "0.5.0"
ark-grumpkin = "0.5.0"
ark-pallas = "0.5.0"
ark-vesta = "0.5.0"
ark-test-curves = { version = "0.5.0", features = ["bls12_381_curve"] }

[profile.release]
codegen-units = 1
Expand Down
8 changes: 4 additions & 4 deletions jolt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ thiserror = "1.0"
rayon = "1.8"
strum = "0.25.0"

ark-bn254 = "0.4"
ark-bn254 = "0.5.0"

# latest commit on slumber-arkworks-compat
jolt-core = { git = "https://github.com/nexus-xyz/jolt", rev = "f0f1f12" }
jolt-common = { git = "https://github.com/nexus-xyz/jolt", rev = "f0f1f12", package = "common" }
# latest commit on legacy-compat
jolt-core = { git = "https://github.com/nexus-xyz/jolt", rev = "8292b49" }
jolt-common = { git = "https://github.com/nexus-xyz/jolt", rev = "8292b49", package = "common" }
33 changes: 8 additions & 25 deletions nova-benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ark-ff = "0.4.0"
ark-relations = { version = "0.4.0" }
ark-r1cs-std = { version = "0.4.0" }
ark-crypto-primitives = { version = "0.4.0", features = ["sponge"] }
ark-ff = "0.5.0"
ark-relations = { version = "0.5.0" }
ark-r1cs-std = { version = "0.5.0" }
ark-crypto-primitives = { version = "0.5.0", features = ["sponge"] }

ark-pallas = "0.4.0"
ark-vesta = "0.4.0"
ark-bn254 = "0.4.0"
ark-grumpkin = { git = "https://github.com/arkworks-rs/curves/", rev = "8c0256a" }
ark-pallas = "0.5.0"
ark-vesta = "0.5.0"
ark-bn254 = "0.5.0"
ark-grumpkin = "0.5.0"

criterion = "0.5"
pprof = { version = "0.13", features = ["criterion", "flamegraph"] }
Expand All @@ -34,20 +34,3 @@ harness = false
[[bench]]
name = "hypernova"
harness = false

[patch.crates-io]
ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitives", rev = "d27a5c8" }

ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std/", rev = "2ca3bd7" }

ark-ff = { git = "https://github.com/arkworks-rs/algebra/", rev = "2a80c54" }
ark-ec = { git = "https://github.com/arkworks-rs/algebra/", rev = "2a80c54" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra/", rev = "2a80c54" }
ark-poly = { git = "https://github.com/arkworks-rs/algebra/", rev = "2a80c54" }

ark-poly-commit = { git = "https://github.com/arkworks-rs/poly-commit/", rev = "12f5529" }

ark-pallas = { git = "https://github.com/arkworks-rs/curves/", rev = "8c0256a" }
ark-vesta = { git = "https://github.com/arkworks-rs/curves/", rev = "8c0256a" }
ark-bn254 = { git = "https://github.com/arkworks-rs/curves/", rev = "8c0256a" }
ark-bls12-381 = { git = "https://github.com/arkworks-rs/curves/", rev = "3fded1f" }
16 changes: 8 additions & 8 deletions nova/src/absorb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Poseidon cryptographic sponge from arkworks is defined over some specified field, and current implementation may
//! either silently discard non-native field element absorbed into the sponge, or panic. Thus, care must be taken
//! when choosing between [`Absorb`] and [`AbsorbNonNative`], because both would compile.
//! when choosing between [`Absorb`] and [`AbsorbEmulatedFp`], because both would compile.
//!
//! Let G1, G2 denote a cycle of elliptic curves: G1 = E(F2) with scalar field F1, G2 = E(F1) with scalar field F2.
//! If r1cs input consists of elements from F1, then its commitment is a point on the curve G1 -- elements from F2.
Expand All @@ -28,7 +28,7 @@ use crate::r1cs::{R1CSInstance, RelaxedR1CSInstance};

/// An interface to objects that can be absorbed by [`ark_sponge::CryptographicSponge`] defined
/// over F1, but cannot be natively represented as an array of elements of F1.
pub trait AbsorbNonNative<F1: PrimeField + Absorb> {
pub trait AbsorbEmulatedFp<F1: PrimeField + Absorb> {
/// Converts self into an array of elements from non-native field F1 and appends
/// it to `dest`.
fn to_non_native_field_elements(&self, dest: &mut Vec<F1>);
Expand All @@ -46,7 +46,7 @@ pub trait AbsorbNonNative<F1: PrimeField + Absorb> {
/// Extension of [`ark_sponge::CryptographicSponge`] for non-native objects.
pub trait CryptographicSpongeExt: ark_sponge::CryptographicSponge {
/// Absorb an input using non-native implementation.
fn absorb_non_native<F>(&mut self, input: &impl AbsorbNonNative<F>)
fn absorb_non_native<F>(&mut self, input: &impl AbsorbEmulatedFp<F>)
where
F: PrimeField + Absorb;
}
Expand All @@ -55,7 +55,7 @@ impl<S> CryptographicSpongeExt for S
where
S: ark_sponge::CryptographicSponge,
{
fn absorb_non_native<F>(&mut self, input: &impl AbsorbNonNative<F>)
fn absorb_non_native<F>(&mut self, input: &impl AbsorbEmulatedFp<F>)
where
F: PrimeField + Absorb,
{
Expand All @@ -69,7 +69,7 @@ where
/// Unique affine coordinates are non-native elements, boolean `infinity` is converted to `ZERO` or `ONE`.
///
/// The conversion to affine point must be consistent with in-circuit implementation.
impl<P: SWCurveConfig> AbsorbNonNative<P::ScalarField> for Projective<P>
impl<P: SWCurveConfig> AbsorbEmulatedFp<P::ScalarField> for Projective<P>
where
P::BaseField: PrimeField,
P::ScalarField: Absorb,
Expand All @@ -88,7 +88,7 @@ where
/// native absorb implementation: either it has to cast commitments coordinates or the input `X`.
///
/// Assume that native implementation is the one that doesn't have to cast public input.
impl<G, C> AbsorbNonNative<G::BaseField> for R1CSInstance<G, C>
impl<G, C> AbsorbEmulatedFp<G::BaseField> for R1CSInstance<G, C>
where
G: CurveGroup,
G::BaseField: PrimeField + Absorb,
Expand All @@ -106,7 +106,7 @@ where
}

/// See the above comment for [`R1CSInstance`] non-native absorb implementation.
impl<G, C> AbsorbNonNative<G::BaseField> for RelaxedR1CSInstance<G, C>
impl<G, C> AbsorbEmulatedFp<G::BaseField> for RelaxedR1CSInstance<G, C>
where
G: CurveGroup,
G::BaseField: PrimeField + Absorb,
Expand All @@ -124,7 +124,7 @@ where
}
}

impl<F: PrimeField + Absorb, A: AbsorbNonNative<F>> AbsorbNonNative<F> for &A {
impl<F: PrimeField + Absorb, A: AbsorbEmulatedFp<F>> AbsorbEmulatedFp<F> for &A {
fn to_non_native_field_elements(&self, dest: &mut Vec<F>) {
(*self).to_non_native_field_elements(dest)
}
Expand Down
10 changes: 5 additions & 5 deletions nova/src/ccs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use rayon::iter::{
use crate::safe_loglike;

pub use super::sparse::{MatrixRef, SparseMatrix};
use super::{absorb::AbsorbNonNative, r1cs::R1CSShape};
use super::{absorb::AbsorbEmulatedFp, r1cs::R1CSShape};
use mle::vec_to_mle;

pub mod mle;
Expand Down Expand Up @@ -232,7 +232,7 @@ impl<G: CurveGroup> CCSWitness<G> {

impl<G, C> Absorb for CCSInstance<G, C>
where
G: CurveGroup + AbsorbNonNative<G::ScalarField>,
G: CurveGroup + AbsorbEmulatedFp<G::ScalarField>,
G::ScalarField: Absorb,
C: PolyCommitmentScheme<G>,
C::Commitment: Into<Vec<G>>,
Expand All @@ -243,7 +243,7 @@ where

fn to_sponge_field_elements<F: PrimeField>(&self, dest: &mut Vec<F>) {
self.commitment_W.clone().into().iter().for_each(|c| {
<G as AbsorbNonNative<G::ScalarField>>::to_sponge_field_elements(c, dest)
<G as AbsorbEmulatedFp<G::ScalarField>>::to_sponge_field_elements(c, dest)
});

(&self.X[1..]).to_sponge_field_elements(dest);
Expand Down Expand Up @@ -302,7 +302,7 @@ impl<G: CurveGroup, C: PolyCommitmentScheme<G>> Eq for CCSInstance<G, C> where C

impl<G, C> Absorb for LCCSInstance<G, C>
where
G: CurveGroup + AbsorbNonNative<G::ScalarField>,
G: CurveGroup + AbsorbEmulatedFp<G::ScalarField>,
G::ScalarField: Absorb,
C: PolyCommitmentScheme<G>,
C::Commitment: Into<Vec<G>>,
Expand All @@ -313,7 +313,7 @@ where

fn to_sponge_field_elements<F: PrimeField>(&self, dest: &mut Vec<F>) {
self.commitment_W.clone().into().iter().for_each(|c| {
<G as AbsorbNonNative<G::ScalarField>>::to_sponge_field_elements(c, dest)
<G as AbsorbEmulatedFp<G::ScalarField>>::to_sponge_field_elements(c, dest)
});

self.X.to_sponge_field_elements(dest);
Expand Down
3 changes: 2 additions & 1 deletion nova/src/circuits/hypernova/sequential/augmented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// !!!
// !!! before modifying this circuit.

use std::ops::Not;
use std::{borrow::Borrow, marker::PhantomData};

use ark_crypto_primitives::sponge::{
Expand Down Expand Up @@ -362,7 +363,7 @@ where
)?;

let is_base_case = input.i.is_zero()?;
let should_enforce = is_base_case.not();
let should_enforce = is_base_case.clone().not();

const NUM_MATRICES: usize = 3;

Expand Down
13 changes: 7 additions & 6 deletions nova/src/circuits/nova/pcd/augmented.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::ops::Not;
use std::{borrow::Borrow, marker::PhantomData};

use ark_crypto_primitives::sponge::{
Expand Down Expand Up @@ -31,7 +32,7 @@ use crate::{
nova::{multifold, multifold_with_relaxed, primary},
secondary,
},
gadgets::nonnative::short_weierstrass::NonNativeAffineVar,
gadgets::emulated::short_weierstrass::EmulatedFpAffineVar,
};

pub const SQUEEZE_NATIVE_ELEMENTS_NUM: usize = 1;
Expand Down Expand Up @@ -143,7 +144,7 @@ where
u: primary::R1CSInstanceVar<G1, C1>,

// proof
commitment_T: NonNativeAffineVar<G1>,
commitment_T: EmulatedFpAffineVar<G1>,
proof_secondary: (secondary::ProofVar<G2, C2>, secondary::ProofVar<G2, C2>),

_random_oracle: PhantomData<RO>,
Expand Down Expand Up @@ -206,7 +207,7 @@ where

nodes: [AllocatedPCDNodeInput<G1, G2, C1, C2, RO>; 2],
// proof
commitment_T: NonNativeAffineVar<G1>,
commitment_T: EmulatedFpAffineVar<G1>,
commitment_T_secondary: ProjectiveVar<G2, FpVar<G2::BaseField>>,
proof_secondary: (
[secondary::ProofVar<G2, C2>; 2],
Expand Down Expand Up @@ -247,7 +248,7 @@ where

let commitment_T_point = input.proof.commitment_T.into();
let commitment_T =
NonNativeAffineVar::new_variable(cs.clone(), || Ok(&commitment_T_point), mode)?;
EmulatedFpAffineVar::new_variable(cs.clone(), || Ok(&commitment_T_point), mode)?;

let u_secondary = (
secondary::ProofVar::new_variable(
Expand Down Expand Up @@ -359,7 +360,7 @@ where

let commitment_T_point = input.proof.commitment_T.into();
let commitment_T =
NonNativeAffineVar::new_variable(cs.clone(), || Ok(&commitment_T_point), mode)?;
EmulatedFpAffineVar::new_variable(cs.clone(), || Ok(&commitment_T_point), mode)?;
let commitment_T_secondary = <ProjectiveVar<G2, FpVar<G2::BaseField>> as AllocVar<
Projective<G2>,
G2::BaseField,
Expand Down Expand Up @@ -465,7 +466,7 @@ where
let right = &input.nodes[1];

let is_base_case = i.is_eq(j)?;
let should_enforce = is_base_case.not();
let should_enforce = is_base_case.clone().not();

let U_base = primary::RelaxedR1CSInstanceVar::<G1, C1>::new_constant(
cs.clone(),
Expand Down
9 changes: 5 additions & 4 deletions nova/src/circuits/nova/sequential/augmented.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::ops::Not;
use std::{borrow::Borrow, marker::PhantomData};

use ark_crypto_primitives::sponge::{
Expand Down Expand Up @@ -30,7 +31,7 @@ use crate::{
nova::{multifold, primary},
secondary,
},
gadgets::nonnative::short_weierstrass::NonNativeAffineVar,
gadgets::emulated::short_weierstrass::EmulatedFpAffineVar,
};

pub const SQUEEZE_NATIVE_ELEMENTS_NUM: usize = 1;
Expand Down Expand Up @@ -109,7 +110,7 @@ where
u: primary::R1CSInstanceVar<G1, C1>,

// proof
commitment_T: NonNativeAffineVar<G1>,
commitment_T: EmulatedFpAffineVar<G1>,
proof_secondary: (secondary::ProofVar<G2, C2>, secondary::ProofVar<G2, C2>),

_random_oracle: PhantomData<RO>,
Expand Down Expand Up @@ -186,7 +187,7 @@ where
)?;
let u = primary::R1CSInstanceVar::new_variable(cs.clone(), || Ok(&input.u), mode)?;

let commitment_T = NonNativeAffineVar::new_variable(
let commitment_T = EmulatedFpAffineVar::new_variable(
cs.clone(),
|| Ok(input.proof.commitment_T.into()),
mode,
Expand Down Expand Up @@ -275,7 +276,7 @@ where
})?;

let is_base_case = input.i.is_zero()?;
let should_enforce = is_base_case.not();
let should_enforce = is_base_case.clone().not();

let U_base = primary::RelaxedR1CSInstanceVar::<G1, C1>::new_constant(
cs.clone(),
Expand Down
9 changes: 5 additions & 4 deletions nova/src/circuits/supernova/augmented.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::ops::Not;
use std::{borrow::Borrow, marker::PhantomData};

use ark_crypto_primitives::sponge::{
Expand Down Expand Up @@ -31,7 +32,7 @@ use crate::{
nova::{multifold, primary},
secondary,
},
gadgets::nonnative::short_weierstrass::NonNativeAffineVar,
gadgets::emulated::short_weierstrass::EmulatedFpAffineVar,
};

pub const SQUEEZE_NATIVE_ELEMENTS_NUM: usize = 1;
Expand Down Expand Up @@ -130,7 +131,7 @@ where
u: primary::R1CSInstanceVar<G1, C1>,

// proof
commitment_T: NonNativeAffineVar<G1>,
commitment_T: EmulatedFpAffineVar<G1>,
proof_secondary: (secondary::ProofVar<G2, C2>, secondary::ProofVar<G2, C2>),

_random_oracle: PhantomData<RO>,
Expand Down Expand Up @@ -227,7 +228,7 @@ where
.collect::<Result<_, _>>()?;
let u = primary::R1CSInstanceVar::new_variable(cs.clone(), || Ok(&input.u), mode)?;

let commitment_T = NonNativeAffineVar::new_variable(
let commitment_T = EmulatedFpAffineVar::new_variable(
cs.clone(),
|| Ok(input.proof.commitment_T.into()),
mode,
Expand Down Expand Up @@ -384,7 +385,7 @@ where
assert_eq!(input.U_secondary.len(), num_augmented_circuits);

let is_base_case = input.i.is_zero()?;
let should_enforce = is_base_case.not();
let should_enforce = is_base_case.clone().not();

let U_base = primary::RelaxedR1CSInstanceVar::<G1, C1>::new_constant(
cs.clone(),
Expand Down
Loading

0 comments on commit fc96e11

Please sign in to comment.