Browse Source

move from rug to num-bigint (#53)

main
Srinath Setty 2 years ago
committed by GitHub
parent
commit
562fa71027
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 40 deletions
  1. +5
    -4
      Cargo.toml
  2. +2
    -2
      src/gadgets/utils.rs
  3. +6
    -5
      src/pasta.rs
  4. +2
    -2
      src/traits.rs
  5. +28
    -27
      tests/nonnative.rs

+ 5
- 4
Cargo.toml

@ -1,8 +1,8 @@
[package] [package]
name = "nova-snark" name = "nova-snark"
version = "0.4.2"
version = "0.5.0"
authors = ["Srinath Setty <srinath@microsoft.com>"] authors = ["Srinath Setty <srinath@microsoft.com>"]
edition = "2018"
edition = "2021"
description = "Recursive zkSNARKs without trusted setup" description = "Recursive zkSNARKs without trusted setup"
documentation = "https://docs.rs/nova-snark/" documentation = "https://docs.rs/nova-snark/"
readme = "README.md" readme = "README.md"
@ -25,8 +25,9 @@ subtle = "2.4"
pasta_curves = "0.3.1" pasta_curves = "0.3.1"
neptune = "6.1" neptune = "6.1"
generic-array = "0.14.4" 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"] } serde = { version = "1.0", features = ["derive"] }
bincode = "1.2.1" bincode = "1.2.1"
flate2 = "1.0" flate2 = "1.0"

+ 2
- 2
src/gadgets/utils.rs

@ -10,7 +10,7 @@ use bellperson::{
}; };
use bellperson_nonnative::mp::bignat::{nat_to_limbs, BigNat}; use bellperson_nonnative::mp::bignat::{nat_to_limbs, BigNat};
use ff::{Field, PrimeField, PrimeFieldBits}; 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 /// Gets as input the little indian representation of a number and spits out the number
#[allow(dead_code)] #[allow(dead_code)]
@ -116,7 +116,7 @@ pub fn scalar_as_base(input: G::Scalar) -> G::Base {
/// Allocate bignat a constant /// Allocate bignat a constant
pub fn alloc_bignat_constant<F: PrimeField, CS: ConstraintSystem<F>>( pub fn alloc_bignat_constant<F: PrimeField, CS: ConstraintSystem<F>>(
mut cs: CS, mut cs: CS,
val: &Integer,
val: &BigInt,
limb_width: usize, limb_width: usize,
n_limbs: usize, n_limbs: usize,
) -> Result<BigNat<F>, SynthesisError> { ) -> Result<BigNat<F>, SynthesisError> {

+ 6
- 5
src/pasta.rs

@ -6,6 +6,8 @@ use crate::{
use core::ops::Mul; use core::ops::Mul;
use ff::Field; use ff::Field;
use merlin::Transcript; use merlin::Transcript;
use num_bigint::BigInt;
use num_traits::Num;
use pasta_curves::{ use pasta_curves::{
self, self,
arithmetic::{CurveAffine, CurveExt, Group as Grp}, arithmetic::{CurveAffine, CurveExt, Group as Grp},
@ -14,7 +16,6 @@ use pasta_curves::{
}; };
use rand::SeedableRng; use rand::SeedableRng;
use rand_chacha::ChaCha20Rng; use rand_chacha::ChaCha20Rng;
use rug::Integer;
//////////////////////////////////////Pallas/////////////////////////////////////////////// //////////////////////////////////////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", "40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001",
16, 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", "40000000000000000000000000000000224698fc094cf91b992d30ed00000001",
16, 16,
) )

+ 2
- 2
src/traits.rs

@ -6,7 +6,7 @@ use core::{
}; };
use ff::{PrimeField, PrimeFieldBits}; use ff::{PrimeField, PrimeFieldBits};
use merlin::Transcript; use merlin::Transcript;
use rug::Integer;
use num_bigint::BigInt;
/// Represents an element of a group /// Represents an element of a group
pub trait Group: pub trait Group:
@ -53,7 +53,7 @@ pub trait Group:
fn to_coordinates(&self) -> (Self::Base, Self::Base, bool); fn to_coordinates(&self) -> (Self::Base, Self::Base, bool);
/// Returns the order of the group as a big integer /// 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 /// Represents a compressed version of a group element

+ 28
- 27
tests/nonnative.rs

@ -9,11 +9,12 @@ use nova_snark::bellperson::{
shape_cs::ShapeCS, shape_cs::ShapeCS,
solver::SatisfyingAssignment, solver::SatisfyingAssignment,
}; };
use rug::Integer;
use num_bigint::BigInt;
use num_traits::Num as OtherNum;
fn synthesize_is_equal<Fr: PrimeField, CS: ConstraintSystem<Fr>>( fn synthesize_is_equal<Fr: PrimeField, CS: ConstraintSystem<Fr>>(
cs: &mut CS, cs: &mut CS,
a_val: &Integer,
a_val: &BigInt,
limb_width: usize, limb_width: usize,
n_limbs: usize, n_limbs: usize,
) -> Result<(), SynthesisError> { ) -> Result<(), SynthesisError> {
@ -42,11 +43,11 @@ fn synthesize_is_equal>(
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn synthesize_mult_mod<Fr: PrimeField, CS: ConstraintSystem<Fr>>( fn synthesize_mult_mod<Fr: PrimeField, CS: ConstraintSystem<Fr>>(
cs: &mut CS, 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, limb_width: usize,
n_limbs: usize, n_limbs: usize,
) -> Result<(), SynthesisError> { ) -> Result<(), SynthesisError> {
@ -93,9 +94,9 @@ fn synthesize_mult_mod>(
fn synthesize_add<Fr: PrimeField, CS: ConstraintSystem<Fr>>( fn synthesize_add<Fr: PrimeField, CS: ConstraintSystem<Fr>>(
cs: &mut CS, cs: &mut CS,
a_val: &Integer,
b_val: &Integer,
c_val: &Integer,
a_val: &BigInt,
b_val: &BigInt,
c_val: &BigInt,
limb_width: usize, limb_width: usize,
n_limbs: usize, n_limbs: usize,
) -> Result<(), SynthesisError> { ) -> Result<(), SynthesisError> {
@ -126,10 +127,10 @@ fn synthesize_add>(
fn synthesize_add_mod<Fr: PrimeField, CS: ConstraintSystem<Fr>>( fn synthesize_add_mod<Fr: PrimeField, CS: ConstraintSystem<Fr>>(
cs: &mut CS, 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, limb_width: usize,
n_limbs: usize, n_limbs: usize,
) -> Result<(), SynthesisError> { ) -> Result<(), SynthesisError> {
@ -170,27 +171,27 @@ fn test_mult_mod() {
type G = pasta_curves::pallas::Point; type G = pasta_curves::pallas::Point;
// Set the inputs // Set the inputs
let a_val = Integer::from_str_radix(
let a_val = BigInt::from_str_radix(
"11572336752428856981970994795408771577024165681374400871001196932361466228192", "11572336752428856981970994795408771577024165681374400871001196932361466228192",
10, 10,
) )
.unwrap(); .unwrap();
let b_val = Integer::from_str_radix(
let b_val = BigInt::from_str_radix(
"87673389408848523602668121701204553693362841135953267897017930941776218798802", "87673389408848523602668121701204553693362841135953267897017930941776218798802",
10, 10,
) )
.unwrap(); .unwrap();
let m_val = Integer::from_str_radix(
let m_val = BigInt::from_str_radix(
"40000000000000000000000000000000224698fc094cf91b992d30ed00000001", "40000000000000000000000000000000224698fc094cf91b992d30ed00000001",
16, 16,
) )
.unwrap(); .unwrap();
let q_val = Integer::from_str_radix(
let q_val = BigInt::from_str_radix(
"35048542371029440058224000662033175648615707461806414787901284501179083518342", "35048542371029440058224000662033175648615707461806414787901284501179083518342",
10, 10,
) )
.unwrap(); .unwrap();
let r_val = Integer::from_str_radix(
let r_val = BigInt::from_str_radix(
"26362617993085418618858432307761590013874563896298265114483698919121453084730", "26362617993085418618858432307761590013874563896298265114483698919121453084730",
10, 10,
) )
@ -217,13 +218,13 @@ fn test_add() {
type G = pasta_curves::pallas::Point; type G = pasta_curves::pallas::Point;
// Set the inputs // Set the inputs
let a_val = Integer::from_str_radix(
let a_val = BigInt::from_str_radix(
"11572336752428856981970994795408771577024165681374400871001196932361466228192", "11572336752428856981970994795408771577024165681374400871001196932361466228192",
10, 10,
) )
.unwrap(); .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", "11572336752428856981970994795408771577024165681374400871001196932361466228193",
10, 10,
) )
@ -250,18 +251,18 @@ fn test_add_mod() {
type G = pasta_curves::pallas::Point; type G = pasta_curves::pallas::Point;
// Set the inputs // Set the inputs
let a_val = Integer::from_str_radix(
let a_val = BigInt::from_str_radix(
"11572336752428856981970994795408771577024165681374400871001196932361466228192", "11572336752428856981970994795408771577024165681374400871001196932361466228192",
10, 10,
) )
.unwrap(); .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", "11572336752428856981970994795408771577024165681374400871001196932361466228193",
10, 10,
) )
.unwrap(); .unwrap();
let m_val = Integer::from_str_radix(
let m_val = BigInt::from_str_radix(
"40000000000000000000000000000000224698fc094cf91b992d30ed00000001", "40000000000000000000000000000000224698fc094cf91b992d30ed00000001",
16, 16,
) )
@ -288,7 +289,7 @@ fn test_equal() {
type G = pasta_curves::pallas::Point; type G = pasta_curves::pallas::Point;
// Set the inputs // 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 // First create the shape
let mut cs: ShapeCS<G> = ShapeCS::new(); let mut cs: ShapeCS<G> = ShapeCS::new();

Loading…
Cancel
Save