From 706d688a133b8a26d6127bd8eaa9f794b9ea0b2f Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Fri, 13 May 2022 11:04:12 +0530 Subject: [PATCH] add hash(params, U, z0, zi, i) when generating a challenge (#51) * add hash(params, U, z0, zi, i) when generating a challenge * address clippy --- src/circuit.rs | 3 ++- src/gadgets/r1cs.rs | 3 +++ src/poseidon.rs | 14 +++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/circuit.rs b/src/circuit.rs index 92f9bb5..619a943 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -201,7 +201,7 @@ where u: AllocatedR1CSInstance, T: AllocatedPoint, ) -> Result<(AllocatedRelaxedR1CSInstance, AllocatedBit), SynthesisError> { - // Check that u.x[0] = Hash(params, U,i,z0,zi) + // Check that u.x[0] = Hash(params, U, i, z0, zi) let mut ro: PoseidonROGadget = PoseidonROGadget::new(self.poseidon_constants.clone()); ro.absorb(params); ro.absorb(i); @@ -220,6 +220,7 @@ where // Run NIFS Verifier let U_fold = U.fold_with_r1cs( cs.namespace(|| "compute fold of U and u"), + hash, // hash of the (params, U, i, z0, zi) u, T, self.poseidon_constants.clone(), diff --git a/src/gadgets/r1cs.rs b/src/gadgets/r1cs.rs index 43a2f05..2b4ce43 100644 --- a/src/gadgets/r1cs.rs +++ b/src/gadgets/r1cs.rs @@ -212,9 +212,11 @@ where } /// Folds self with a relaxed r1cs instance and returns the result + #[allow(clippy::too_many_arguments)] pub fn fold_with_r1cs::Base>>( &self, mut cs: CS, + hash: AllocatedNum, // hash of (params, running_instance, i, z0, zi) u: AllocatedR1CSInstance, T: AllocatedPoint, poseidon_constants: NovaPoseidonConstants, @@ -223,6 +225,7 @@ where ) -> Result, SynthesisError> { // Compute r: let mut ro: PoseidonROGadget = PoseidonROGadget::new(poseidon_constants); + ro.absorb(hash); u.absorb_in_ro(&mut ro); ro.absorb(T.x.clone()); ro.absorb(T.y.clone()); diff --git a/src/poseidon.rs b/src/poseidon.rs index 7b208cc..0725e52 100644 --- a/src/poseidon.rs +++ b/src/poseidon.rs @@ -12,7 +12,7 @@ use bellperson::{ }; use core::marker::PhantomData; use ff::{PrimeField, PrimeFieldBits}; -use generic_array::typenum::{U27, U8}; +use generic_array::typenum::{U27, U9}; use neptune::{ circuit::poseidon_hash, poseidon::{Poseidon, PoseidonConstants}, @@ -25,7 +25,7 @@ pub struct NovaPoseidonConstants where Scalar: PrimeField, { - constants8: PoseidonConstants, + constants9: PoseidonConstants, constants27: PoseidonConstants, } @@ -36,10 +36,10 @@ where /// Generate Poseidon constants for the arities that Nova uses #[allow(clippy::new_without_default)] fn new() -> Self { - let constants8 = PoseidonConstants::::new_with_strength(Strength::Strengthened); + let constants9 = PoseidonConstants::::new_with_strength(Strength::Strengthened); let constants27 = PoseidonConstants::::new_with_strength(Strength::Strengthened); Self { - constants8, + constants9, constants27, } } @@ -65,7 +65,7 @@ where { fn hash_inner(&self) -> Base { match self.state.len() { - 8 => Poseidon::::new_with_preimage(&self.state, &self.constants.constants8).hash(), + 9 => Poseidon::::new_with_preimage(&self.state, &self.constants.constants9).hash(), 27 => { Poseidon::::new_with_preimage(&self.state, &self.constants.constants27).hash() } @@ -169,10 +169,10 @@ where CS: ConstraintSystem, { let out = match self.state.len() { - 8 => poseidon_hash( + 9 => poseidon_hash( cs.namespace(|| "Posideon hash"), self.state.clone(), - &self.constants.constants8, + &self.constants.constants9, )?, 27 => poseidon_hash( cs.namespace(|| "Poseidon hash"),