arnaucube
arnaucube/NovaPublic Self-hosted repository
small fixes
Srinath Setty srinath@microsoft.com
Fri, 23 Jul 2021 15:03:51 -0700
commit

d52be5cf4ac8fe6040e5855d93301dcdbcaaeab6

parent

ba3a1e3922dd34165c0238d21247c91e180c64db

3 files changed, 21 insertions(+), 27 deletions(-)

jump to
M README.md → README.md

@@ -5,7 +5,7 @@

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 ```
M src/lib.rs → src/lib.rs

@@ -65,7 +65,7 @@ // fold the witness using `r` and `T`

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 @@ // fold the instance using `r` and `comm_T`

let U = U1.fold(U2, &self.comm_T, &r)?; // return the folded instance and witness - return Ok(U); + Ok(U) } }
M src/r1cs.rs → 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 @@ pub fn new(

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<R1CSShape, NovaError> { 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 @@ Ok(())

} }; - 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 @@ let shape = 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 R1CSWitness { - pub fn new(S: &R1CSShape, W: &Vec<Scalar>, E: &Vec<Scalar>) -> Result<R1CSWitness, NovaError> { + pub fn new(S: &R1CSShape, W: &[Scalar], E: &[Scalar]) -> Result<R1CSWitness, NovaError> { 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 @@ pub fn commit(&self, gens: &R1CSGens) -> (Commitment, Commitment) {

(self.W.commit(&gens.gens_W), self.E.commit(&gens.gens_E)) } - pub fn fold( - &self, - W2: &R1CSWitness, - T: &Vec<Scalar>, - r: &Scalar, - ) -> Result<R1CSWitness, NovaError> { + pub fn fold(&self, W2: &R1CSWitness, T: &[Scalar], r: &Scalar) -> Result<R1CSWitness, NovaError> { let (W1, E1) = (&self.W, &self.E); let (W2, E2) = (&W2.W, &W2.E);

@@ -274,7 +268,7 @@ pub fn new(

S: &R1CSShape, comm_W: &Commitment, comm_E: &Commitment, - X: &Vec<Scalar>, + X: &[Scalar], u: &Scalar, ) -> Result<R1CSInstance, NovaError> { if S.num_inputs != X.len() {

@@ -283,7 +277,7 @@ } else {

Ok(R1CSInstance { comm_W: comm_W.clone(), comm_E: comm_E.clone(), - X: X.clone(), + X: X.to_owned(), u: *u, }) }