Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
srinathsetty committed Apr 11, 2024
1 parent f25d18a commit 7d8546c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ keywords = ["zkSNARKs", "cryptography", "proofs"]
curve25519-dalek = { version = "4.1.1", features = [
"serde",
"alloc",
"rand_core",
], default-features = false }
merlin = { version = "3.0.0", default-features = false }
rand = { version = "0.7.3", features = ["getrandom"], default-features = false }
rand = "0.8"
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
digest = { version = "0.8.1", default-features = false }
sha3 = { version = "0.8.2", default-features = false }
byteorder = { version = "1.3.4", default-features = false }
rayon = { version = "1.3.0", optional = true }
serde = { version = "1.0.106", features = ["derive"], default-features = false }
bincode = { version = "1.3.3", default-features = false }
subtle = { version = "2.4", features = ["i128"], default-features = false }
zeroize = { version = "1.5", default-features = false }
itertools = { version = "0.10.0", default-features = false }
colored = { version = "2.0.0", default-features = false, optional = true }
flate2 = { version = "1.0.14" }
Expand Down Expand Up @@ -66,7 +67,6 @@ std = [
"byteorder/std",
"serde/std",
"subtle/std",
"zeroize/std",
"itertools/use_std",
"flate2/rust_backend",
]
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn produce_tiny_r1cs() -> (
// To construct these matrices, we will use `curve25519-dalek` but one can use any other method.

// a variable that holds a byte representation of 1
let one = Scalar::one().to_bytes();
let one = Scalar::ONE.to_bytes();

// R1CS is a set of three sparse matrices A B C, where is a row for every
// constraint and a column for every entry in z = (vars, 1, inputs)
Expand Down Expand Up @@ -224,10 +224,10 @@ fn produce_tiny_r1cs() -> (
let z1 = Scalar::random(&mut csprng);
let z2 = (z0 + z1) * i0; // constraint 0
let z3 = (z0 + i1) * z2; // constraint 1
let z4 = Scalar::zero(); //constraint 2
let z4 = Scalar::ZERO; //constraint 2

// create a VarsAssignment
let mut vars = vec![Scalar::zero().to_bytes(); num_vars];
let mut vars = vec![Scalar::ZERO.to_bytes(); num_vars];
vars[0] = z0.to_bytes();
vars[1] = z1.to_bytes();
vars[2] = z2.to_bytes();
Expand All @@ -236,7 +236,7 @@ fn produce_tiny_r1cs() -> (
let assignment_vars = VarsAssignment::new(&vars).unwrap();

// create an InputsAssignment
let mut inputs = vec![Scalar::zero().to_bytes(); num_inputs];
let mut inputs = vec![Scalar::ZERO.to_bytes(); num_inputs];
inputs[0] = i0.to_bytes();
inputs[1] = i1.to_bytes();
let assignment_inputs = InputsAssignment::new(&inputs).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions examples/cubic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn produce_r1cs() -> (
let mut B: Vec<(usize, usize, [u8; 32])> = Vec::new();
let mut C: Vec<(usize, usize, [u8; 32])> = Vec::new();

let one = Scalar::one().to_bytes();
let one = Scalar::ONE.to_bytes();

// R1CS is a set of three sparse matrices A B C, where is a row for every
// constraint and a column for every entry in z = (vars, 1, inputs)
Expand Down Expand Up @@ -80,15 +80,15 @@ fn produce_r1cs() -> (
let i0 = z3 + Scalar::from(5u32); // constraint 3

// create a VarsAssignment
let mut vars = vec![Scalar::zero().to_bytes(); num_vars];
let mut vars = vec![Scalar::ZERO.to_bytes(); num_vars];
vars[0] = z0.to_bytes();
vars[1] = z1.to_bytes();
vars[2] = z2.to_bytes();
vars[3] = z3.to_bytes();
let assignment_vars = VarsAssignment::new(&vars).unwrap();

// create an InputsAssignment
let mut inputs = vec![Scalar::zero().to_bytes(); num_inputs];
let mut inputs = vec![Scalar::ZERO.to_bytes(); num_inputs];
inputs[0] = i0.to_bytes();
let assignment_inputs = InputsAssignment::new(&inputs).unwrap();

Expand Down
18 changes: 3 additions & 15 deletions src/scalar/ristretto255.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use rand::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq, CtOption};
use zeroize::Zeroize;

// use crate::util::{adc, mac, sbb};
/// Compute a + b + carry, returning the result and the new carry over.
Expand Down Expand Up @@ -359,12 +358,6 @@ where
}
}

impl Zeroize for Scalar {
fn zeroize(&mut self) {
self.0 = [0u64; 4];
}
}

impl Scalar {
/// Returns zero, the additive identity.
#[inline]
Expand Down Expand Up @@ -609,22 +602,17 @@ impl Scalar {
// externally, but there's no corresponding distinction for
// field elements.

use zeroize::Zeroizing;

let n = inputs.len();
let one = Scalar::one();

// Place scratch storage in a Zeroizing wrapper to wipe it when
// we pass out of scope.
let scratch_vec = vec![one; n];
let mut scratch = Zeroizing::new(scratch_vec);
let mut scratch_vec = vec![one; n];

// Keep an accumulator of all of the previous products
let mut acc = Scalar::one();

// Pass through the input vector, recording the previous
// products in the scratch space
for (input, scratch) in inputs.iter().zip(scratch.iter_mut()) {
for (input, scratch) in inputs.iter().zip(scratch_vec.iter_mut()) {
*scratch = acc;

acc = acc * input;
Expand All @@ -641,7 +629,7 @@ impl Scalar {

// Pass through the vector backwards to compute the inverses
// in place
for (input, scratch) in inputs.iter_mut().rev().zip(scratch.iter().rev()) {
for (input, scratch) in inputs.iter_mut().rev().zip(scratch_vec.iter().rev()) {
let tmp = &acc * input.clone();
*input = &acc * scratch;
acc = tmp;
Expand Down

0 comments on commit 7d8546c

Please sign in to comment.