diff --git a/README.md b/README.md index c7b010a..65375f6 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Nova is a high-speed recursive SNARK (a SNARK is type cryptographic proof system This repository provides `libnova,` a Rust library library implementation of Nova. The current release implements the core building blocks in Nova, and future releases will use cycles of elliptic curves to support recursive composition of proofs. To run tests, run: -```rust +```text cargo test ``` diff --git a/src/lib.rs b/src/lib.rs index 0801458..478ce95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,7 +65,7 @@ impl StepSNARK { let W = W1.fold(W2, &T, &r)?; // return the folded instance and witness - return Ok((StepSNARK { comm_T }, (U, W))); + Ok((StepSNARK { comm_T }, (U, W))) } /// Takes as input two relaxed R1CS instances `U1` and `U2` @@ -92,7 +92,7 @@ impl StepSNARK { let U = U1.fold(U2, &self.comm_T, &r)?; // return the folded instance and witness - return Ok(U); + Ok(U) } } diff --git a/src/r1cs.rs b/src/r1cs.rs index 6acdcbd..39aaf29 100644 --- a/src/r1cs.rs +++ b/src/r1cs.rs @@ -1,3 +1,4 @@ +#![allow(clippy::type_complexity)] use super::commitments::Scalar; use super::commitments::{CommitGens, CommitTrait, Commitment, CompressedCommitment}; use super::errors::NovaError; @@ -50,21 +51,19 @@ impl R1CSShape { num_cons: usize, num_vars: usize, num_inputs: usize, - A: &Vec<(usize, usize, Scalar)>, - B: &Vec<(usize, usize, Scalar)>, - C: &Vec<(usize, usize, Scalar)>, + A: &[(usize, usize, Scalar)], + B: &[(usize, usize, Scalar)], + C: &[(usize, usize, Scalar)], ) -> Result { let is_valid = |num_cons: usize, num_vars: usize, num_io: usize, - M: &Vec<(usize, usize, Scalar)>| + M: &[(usize, usize, Scalar)]| -> Result<(), NovaError> { let res = (0..num_cons) .map(|i| { let (row, col, _val) = M[i]; - if row >= num_cons { - Err(NovaError::InvalidIndex) - } else if col >= num_io + num_vars + 1 { + if row >= num_cons || col > num_io + num_vars { Err(NovaError::InvalidIndex) } else { Ok(()) @@ -79,9 +78,9 @@ impl R1CSShape { } }; - let res_A = is_valid(num_cons, num_vars, num_inputs, &A); - let res_B = is_valid(num_cons, num_vars, num_inputs, &B); - let res_C = is_valid(num_cons, num_vars, num_inputs, &C); + let res_A = is_valid(num_cons, num_vars, num_inputs, A); + let res_B = is_valid(num_cons, num_vars, num_inputs, B); + let res_C = is_valid(num_cons, num_vars, num_inputs, C); if res_A.is_err() || res_B.is_err() || res_C.is_err() { return Err(NovaError::InvalidIndex); @@ -91,9 +90,9 @@ impl R1CSShape { num_cons, num_vars, num_inputs, - A: A.clone(), - B: B.clone(), - C: C.clone(), + A: A.to_owned(), + B: B.to_owned(), + C: C.to_owned(), }; Ok(shape) @@ -226,13 +225,13 @@ impl R1CSShape { } impl R1CSWitness { - pub fn new(S: &R1CSShape, W: &Vec, E: &Vec) -> Result { + pub fn new(S: &R1CSShape, W: &[Scalar], E: &[Scalar]) -> Result { if S.num_vars != W.len() || S.num_cons != E.len() { Err(NovaError::InvalidWitnessLength) } else { Ok(R1CSWitness { - W: W.clone(), - E: E.clone(), + W: W.to_owned(), + E: E.to_owned(), }) } } @@ -241,12 +240,7 @@ impl R1CSWitness { (self.W.commit(&gens.gens_W), self.E.commit(&gens.gens_E)) } - pub fn fold( - &self, - W2: &R1CSWitness, - T: &Vec, - r: &Scalar, - ) -> Result { + pub fn fold(&self, W2: &R1CSWitness, T: &[Scalar], r: &Scalar) -> Result { let (W1, E1) = (&self.W, &self.E); let (W2, E2) = (&W2.W, &W2.E); @@ -274,7 +268,7 @@ impl R1CSInstance { S: &R1CSShape, comm_W: &Commitment, comm_E: &Commitment, - X: &Vec, + X: &[Scalar], u: &Scalar, ) -> Result { if S.num_inputs != X.len() { @@ -283,7 +277,7 @@ impl R1CSInstance { Ok(R1CSInstance { comm_W: comm_W.clone(), comm_E: comm_E.clone(), - X: X.clone(), + X: X.to_owned(), u: *u, }) }