Skip to content

Commit

Permalink
fix build (#68)
Browse files Browse the repository at this point in the history
* fix build

* address clippy, switch to stable

* fix build
  • Loading branch information
srinathsetty authored Apr 11, 2024
1 parent f25d18a commit f30375e
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 47 deletions.
21 changes: 6 additions & 15 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ on:
branches: [ master ]

jobs:
build_nightly:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install
run: rustup default nightly
run: rustup default stable
- name: Install rustfmt Components
run: rustup component add rustfmt
- name: Install clippy
Expand All @@ -28,13 +28,15 @@ jobs:
- name: Check clippy warnings
run: cargo clippy --all-targets --all-features -- -D warnings

build_nightly_wasm:


build_wasm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install
run: rustup default nightly
run: rustup default stable

- name: Build without std
run: cargo build --no-default-features --verbose
Expand All @@ -53,14 +55,3 @@ jobs:

- name: Build for target wasm-wasi
run: RUSTFLAGS="" cargo build --target=wasm32-wasi --no-default-features --verbose

- name: Patch Cargo.toml for wasm-bindgen
run: |
echo "[dependencies.getrandom]" >> Cargo.toml
echo "version = \"0.1\"" >> Cargo.toml
echo "default-features = false" >> Cargo.toml
echo "features = [\"wasm-bindgen\"]" >> Cargo.toml
- name: Build for target wasm32-unknown-unknown
run: RUSTFLAGS="" cargo build --target=wasm32-unknown-unknown --no-default-features --verbose

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
2 changes: 1 addition & 1 deletion profiler/nizk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn print(msg: &str) {

pub fn main() {
// the list of number of variables (and constraints) in an R1CS instance
let inst_sizes = vec![10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
let inst_sizes = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];

println!("Profiler:: NIZK");
for &s in inst_sizes.iter() {
Expand Down
2 changes: 1 addition & 1 deletion profiler/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn print(msg: &str) {

pub fn main() {
// the list of number of variables (and constraints) in an R1CS instance
let inst_sizes = vec![10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
let inst_sizes = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];

println!("Profiler:: SNARK");
for &s in inst_sizes.iter() {
Expand Down
4 changes: 2 additions & 2 deletions src/product_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ impl ProductCircuitEvalProof {

impl ProductCircuitEvalProofBatched {
pub fn prove(
prod_circuit_vec: &mut Vec<&mut ProductCircuit>,
dotp_circuit_vec: &mut Vec<&mut DotProductCircuit>,
prod_circuit_vec: &mut [&mut ProductCircuit],
dotp_circuit_vec: &mut [&mut DotProductCircuit],
transcript: &mut Transcript,
) -> (Self, Vec<Scalar>) {
assert!(!prod_circuit_vec.is_empty());
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
6 changes: 3 additions & 3 deletions src/sparse_mlpoly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ impl ProductLayerProof {
};

let (proof_ops, rand_ops) = ProductCircuitEvalProofBatched::prove(
&mut vec![
&mut [
&mut row_read_A[0],
&mut row_read_B[0],
&mut row_read_C[0],
Expand All @@ -1168,7 +1168,7 @@ impl ProductLayerProof {
&mut col_write_B[0],
&mut col_write_C[0],
],
&mut vec![
&mut [
&mut dotp_left_A[0],
&mut dotp_right_A[0],
&mut dotp_left_B[0],
Expand All @@ -1181,7 +1181,7 @@ impl ProductLayerProof {

// produce a batched proof of memory-related product circuits
let (proof_mem, rand_mem) = ProductCircuitEvalProofBatched::prove(
&mut vec![
&mut [
&mut row_prod_layer.init,
&mut row_prod_layer.audit,
&mut col_prod_layer.init,
Expand Down

0 comments on commit f30375e

Please sign in to comment.