diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index abda4fd..1037e4a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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 @@ -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 @@ -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 - diff --git a/Cargo.toml b/Cargo.toml index 9870a93..9fef677 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,11 @@ 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 } @@ -24,7 +26,6 @@ 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" } @@ -66,7 +67,6 @@ std = [ "byteorder/std", "serde/std", "subtle/std", - "zeroize/std", "itertools/use_std", "flate2/rust_backend", ] diff --git a/README.md b/README.md index df7f305..dc3281a 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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(); @@ -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(); diff --git a/examples/cubic.rs b/examples/cubic.rs index ded7349..f14321f 100644 --- a/examples/cubic.rs +++ b/examples/cubic.rs @@ -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) @@ -80,7 +80,7 @@ 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(); @@ -88,7 +88,7 @@ fn produce_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(); let assignment_inputs = InputsAssignment::new(&inputs).unwrap(); diff --git a/profiler/nizk.rs b/profiler/nizk.rs index e2d3a15..1499c86 100644 --- a/profiler/nizk.rs +++ b/profiler/nizk.rs @@ -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() { diff --git a/profiler/snark.rs b/profiler/snark.rs index b347480..f30d715 100644 --- a/profiler/snark.rs +++ b/profiler/snark.rs @@ -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() { diff --git a/src/product_tree.rs b/src/product_tree.rs index 6e2f932..3be6bde 100644 --- a/src/product_tree.rs +++ b/src/product_tree.rs @@ -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) { assert!(!prod_circuit_vec.is_empty()); diff --git a/src/scalar/ristretto255.rs b/src/scalar/ristretto255.rs index 94ce945..b678d5a 100755 --- a/src/scalar/ristretto255.rs +++ b/src/scalar/ristretto255.rs @@ -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. @@ -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] @@ -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; @@ -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; diff --git a/src/sparse_mlpoly.rs b/src/sparse_mlpoly.rs index 5faf233..14beaf5 100644 --- a/src/sparse_mlpoly.rs +++ b/src/sparse_mlpoly.rs @@ -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], @@ -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], @@ -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,