diff --git a/Cargo.toml b/Cargo.toml index a709b65..ccaf8c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "nova-snark" -version = "0.4.2" +version = "0.5.0" authors = ["Srinath Setty "] -edition = "2018" +edition = "2021" description = "Recursive zkSNARKs without trusted setup" documentation = "https://docs.rs/nova-snark/" readme = "README.md" @@ -25,8 +25,9 @@ subtle = "2.4" pasta_curves = "0.3.1" neptune = "6.1" generic-array = "0.14.4" -bellperson-nonnative = { version = "0.2.1", default-features = false, features = ["wasm"] } -rug = { version = "1.10", default-features = false, features = ["integer", "serde", "rand"] } +bellperson-nonnative = { version = "0.3.0", default-features = false, features = ["wasm"] } +num-bigint = { version = "0.4", features = ["serde", "rand"] } +num-traits = "0.2" serde = { version = "1.0", features = ["derive"] } bincode = "1.2.1" flate2 = "1.0" diff --git a/src/gadgets/utils.rs b/src/gadgets/utils.rs index af9908c..7b28147 100644 --- a/src/gadgets/utils.rs +++ b/src/gadgets/utils.rs @@ -10,7 +10,7 @@ use bellperson::{ }; use bellperson_nonnative::mp::bignat::{nat_to_limbs, BigNat}; use ff::{Field, PrimeField, PrimeFieldBits}; -use rug::Integer; +use num_bigint::BigInt; /// Gets as input the little indian representation of a number and spits out the number #[allow(dead_code)] @@ -116,7 +116,7 @@ pub fn scalar_as_base(input: G::Scalar) -> G::Base { /// Allocate bignat a constant pub fn alloc_bignat_constant>( mut cs: CS, - val: &Integer, + val: &BigInt, limb_width: usize, n_limbs: usize, ) -> Result, SynthesisError> { diff --git a/src/pasta.rs b/src/pasta.rs index 0d1d92c..e9f30fb 100644 --- a/src/pasta.rs +++ b/src/pasta.rs @@ -6,6 +6,8 @@ use crate::{ use core::ops::Mul; use ff::Field; use merlin::Transcript; +use num_bigint::BigInt; +use num_traits::Num; use pasta_curves::{ self, arithmetic::{CurveAffine, CurveExt, Group as Grp}, @@ -14,7 +16,6 @@ use pasta_curves::{ }; use rand::SeedableRng; use rand_chacha::ChaCha20Rng; -use rug::Integer; //////////////////////////////////////Pallas/////////////////////////////////////////////// @@ -75,8 +76,8 @@ impl Group for pallas::Point { } } - fn get_order() -> Integer { - Integer::from_str_radix( + fn get_order() -> BigInt { + BigInt::from_str_radix( "40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001", 16, ) @@ -163,8 +164,8 @@ impl Group for vesta::Point { } } - fn get_order() -> Integer { - Integer::from_str_radix( + fn get_order() -> BigInt { + BigInt::from_str_radix( "40000000000000000000000000000000224698fc094cf91b992d30ed00000001", 16, ) diff --git a/src/traits.rs b/src/traits.rs index dfbbf47..52adefe 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -6,7 +6,7 @@ use core::{ }; use ff::{PrimeField, PrimeFieldBits}; use merlin::Transcript; -use rug::Integer; +use num_bigint::BigInt; /// Represents an element of a group pub trait Group: @@ -53,7 +53,7 @@ pub trait Group: fn to_coordinates(&self) -> (Self::Base, Self::Base, bool); /// Returns the order of the group as a big integer - fn get_order() -> Integer; + fn get_order() -> BigInt; } /// Represents a compressed version of a group element diff --git a/tests/nonnative.rs b/tests/nonnative.rs index d71c624..a88259e 100644 --- a/tests/nonnative.rs +++ b/tests/nonnative.rs @@ -9,11 +9,12 @@ use nova_snark::bellperson::{ shape_cs::ShapeCS, solver::SatisfyingAssignment, }; -use rug::Integer; +use num_bigint::BigInt; +use num_traits::Num as OtherNum; fn synthesize_is_equal>( cs: &mut CS, - a_val: &Integer, + a_val: &BigInt, limb_width: usize, n_limbs: usize, ) -> Result<(), SynthesisError> { @@ -42,11 +43,11 @@ fn synthesize_is_equal>( #[allow(clippy::too_many_arguments)] fn synthesize_mult_mod>( cs: &mut CS, - a_val: &Integer, - b_val: &Integer, - m_val: &Integer, - q_val: &Integer, - r_val: &Integer, + a_val: &BigInt, + b_val: &BigInt, + m_val: &BigInt, + q_val: &BigInt, + r_val: &BigInt, limb_width: usize, n_limbs: usize, ) -> Result<(), SynthesisError> { @@ -93,9 +94,9 @@ fn synthesize_mult_mod>( fn synthesize_add>( cs: &mut CS, - a_val: &Integer, - b_val: &Integer, - c_val: &Integer, + a_val: &BigInt, + b_val: &BigInt, + c_val: &BigInt, limb_width: usize, n_limbs: usize, ) -> Result<(), SynthesisError> { @@ -126,10 +127,10 @@ fn synthesize_add>( fn synthesize_add_mod>( cs: &mut CS, - a_val: &Integer, - b_val: &Integer, - c_val: &Integer, - m_val: &Integer, + a_val: &BigInt, + b_val: &BigInt, + c_val: &BigInt, + m_val: &BigInt, limb_width: usize, n_limbs: usize, ) -> Result<(), SynthesisError> { @@ -170,27 +171,27 @@ fn test_mult_mod() { type G = pasta_curves::pallas::Point; // Set the inputs - let a_val = Integer::from_str_radix( + let a_val = BigInt::from_str_radix( "11572336752428856981970994795408771577024165681374400871001196932361466228192", 10, ) .unwrap(); - let b_val = Integer::from_str_radix( + let b_val = BigInt::from_str_radix( "87673389408848523602668121701204553693362841135953267897017930941776218798802", 10, ) .unwrap(); - let m_val = Integer::from_str_radix( + let m_val = BigInt::from_str_radix( "40000000000000000000000000000000224698fc094cf91b992d30ed00000001", 16, ) .unwrap(); - let q_val = Integer::from_str_radix( + let q_val = BigInt::from_str_radix( "35048542371029440058224000662033175648615707461806414787901284501179083518342", 10, ) .unwrap(); - let r_val = Integer::from_str_radix( + let r_val = BigInt::from_str_radix( "26362617993085418618858432307761590013874563896298265114483698919121453084730", 10, ) @@ -217,13 +218,13 @@ fn test_add() { type G = pasta_curves::pallas::Point; // Set the inputs - let a_val = Integer::from_str_radix( + let a_val = BigInt::from_str_radix( "11572336752428856981970994795408771577024165681374400871001196932361466228192", 10, ) .unwrap(); - let b_val = Integer::from_str_radix("1", 10).unwrap(); - let c_val = Integer::from_str_radix( + let b_val = BigInt::from_str_radix("1", 10).unwrap(); + let c_val = BigInt::from_str_radix( "11572336752428856981970994795408771577024165681374400871001196932361466228193", 10, ) @@ -250,18 +251,18 @@ fn test_add_mod() { type G = pasta_curves::pallas::Point; // Set the inputs - let a_val = Integer::from_str_radix( + let a_val = BigInt::from_str_radix( "11572336752428856981970994795408771577024165681374400871001196932361466228192", 10, ) .unwrap(); - let b_val = Integer::from_str_radix("1", 10).unwrap(); - let c_val = Integer::from_str_radix( + let b_val = BigInt::from_str_radix("1", 10).unwrap(); + let c_val = BigInt::from_str_radix( "11572336752428856981970994795408771577024165681374400871001196932361466228193", 10, ) .unwrap(); - let m_val = Integer::from_str_radix( + let m_val = BigInt::from_str_radix( "40000000000000000000000000000000224698fc094cf91b992d30ed00000001", 16, ) @@ -288,7 +289,7 @@ fn test_equal() { type G = pasta_curves::pallas::Point; // Set the inputs - let a_val = Integer::from_str_radix("1157233675242885698197099479540877", 10).unwrap(); + let a_val = BigInt::from_str_radix("1157233675242885698197099479540877", 10).unwrap(); // First create the shape let mut cs: ShapeCS = ShapeCS::new();