Skip to content

Commit

Permalink
move from rug to num-bigint (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
srinathsetty authored May 13, 2022
1 parent 677fe23 commit 562fa71
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 40 deletions.
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "nova-snark"
version = "0.4.2"
version = "0.5.0"
authors = ["Srinath Setty <[email protected]>"]
edition = "2018"
edition = "2021"
description = "Recursive zkSNARKs without trusted setup"
documentation = "https://docs.rs/nova-snark/"
readme = "README.md"
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/gadgets/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -116,7 +116,7 @@ pub fn scalar_as_base<G: Group>(input: G::Scalar) -> G::Base {
/// Allocate bignat a constant
pub fn alloc_bignat_constant<F: PrimeField, CS: ConstraintSystem<F>>(
mut cs: CS,
val: &Integer,
val: &BigInt,
limb_width: usize,
n_limbs: usize,
) -> Result<BigNat<F>, SynthesisError> {
Expand Down
11 changes: 6 additions & 5 deletions src/pasta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -14,7 +16,6 @@ use pasta_curves::{
};
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;
use rug::Integer;

//////////////////////////////////////Pallas///////////////////////////////////////////////

Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
55 changes: 28 additions & 27 deletions tests/nonnative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Fr: PrimeField, CS: ConstraintSystem<Fr>>(
cs: &mut CS,
a_val: &Integer,
a_val: &BigInt,
limb_width: usize,
n_limbs: usize,
) -> Result<(), SynthesisError> {
Expand Down Expand Up @@ -42,11 +43,11 @@ fn synthesize_is_equal<Fr: PrimeField, CS: ConstraintSystem<Fr>>(
#[allow(clippy::too_many_arguments)]
fn synthesize_mult_mod<Fr: PrimeField, CS: ConstraintSystem<Fr>>(
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> {
Expand Down Expand Up @@ -93,9 +94,9 @@ fn synthesize_mult_mod<Fr: PrimeField, CS: ConstraintSystem<Fr>>(

fn synthesize_add<Fr: PrimeField, CS: ConstraintSystem<Fr>>(
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> {
Expand Down Expand Up @@ -126,10 +127,10 @@ fn synthesize_add<Fr: PrimeField, CS: ConstraintSystem<Fr>>(

fn synthesize_add_mod<Fr: PrimeField, CS: ConstraintSystem<Fr>>(
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> {
Expand Down Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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<G> = ShapeCS::new();
Expand Down

0 comments on commit 562fa71

Please sign in to comment.