From 52c028b4daf04dbc47466bbdc4a111508d76a3fc Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Tue, 16 Feb 2021 01:09:54 +0800 Subject: [PATCH] Disambiguate naming of hash() -> hash_into() --- src/plonk.rs | 8 ++++---- src/plonk/circuit.rs | 26 +++++++++++++------------- src/plonk/permutation.rs | 2 +- src/plonk/prover.rs | 4 +++- src/plonk/verifier.rs | 3 ++- src/poly.rs | 2 +- src/poly/domain.rs | 3 +-- 7 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/plonk.rs b/src/plonk.rs index 0655d18..95ad65e 100644 --- a/src/plonk.rs +++ b/src/plonk.rs @@ -79,17 +79,17 @@ impl VerifyingKey { } /// Hashes a verification key into a transcript. - pub fn hash>(&self, transcript: &mut T) -> io::Result<()> { + pub fn hash_into>(&self, transcript: &mut T) -> io::Result<()> { let mut hasher = Blake2bParams::new() .hash_length(64) .personal(C::BLAKE2B_PERSONALIZATION) .to_state(); // Hash in constants in the domain which influence the proof - self.domain.hash(&mut hasher); + self.domain.hash_into(&mut hasher); // Hash in `ConstraintSystem` - self.cs.hash(&mut hasher); + self.cs.hash_into(&mut hasher); // Hash in vector of fixed commitments hasher.update(b"num_fixed_commitments"); @@ -102,7 +102,7 @@ impl VerifyingKey { hasher.update(b"num_permutations"); hasher.update(&self.permutations.len().to_le_bytes()); for permutation in &self.permutations { - permutation.hash(&mut hasher, transcript)?; + permutation.hash_into(&mut hasher, transcript)?; } // Hash in final Blake2bState diff --git a/src/plonk/circuit.rs b/src/plonk/circuit.rs index 7792908..0d2dbf0 100644 --- a/src/plonk/circuit.rs +++ b/src/plonk/circuit.rs @@ -29,7 +29,7 @@ impl Column { &self.column_type } - pub(crate) fn hash(&self, hasher: &mut Blake2bState) { + pub(crate) fn hash_into(&self, hasher: &mut Blake2bState) { hasher.update(&format!("{:?}", self).as_bytes()); } } @@ -324,7 +324,7 @@ impl Expression { } /// Hash an Expression into a Blake2bState - pub fn hash(&self, hasher: &mut Blake2bState) { + pub fn hash_into(&self, hasher: &mut Blake2bState) { hasher.update(&format!("{:?}", self).as_bytes()); } } @@ -610,7 +610,7 @@ impl ConstraintSystem { } /// Hashes the `ConstraintSystem` into a `u64`. - pub fn hash(&self, mut hasher: &mut Blake2bState) { + pub fn hash_into(&self, mut hasher: &mut Blake2bState) { hasher.update(b"num_fixed_columns"); hasher.update(&self.num_fixed_columns.to_le_bytes()); @@ -623,28 +623,28 @@ impl ConstraintSystem { hasher.update(b"num_gates"); hasher.update(&self.gates.len().to_le_bytes()); for gate in self.gates.iter() { - gate.1.hash(&mut hasher); + gate.1.hash_into(&mut hasher); } hasher.update(b"num_advice_queries"); hasher.update(&self.advice_queries.len().to_le_bytes()); for query in self.advice_queries.iter() { - query.0.hash(&mut hasher); - query.1.hash(&mut hasher); + query.0.hash_into(&mut hasher); + query.1.hash_into(&mut hasher); } hasher.update(b"num_instance_queries"); hasher.update(&self.instance_queries.len().to_le_bytes()); for query in self.instance_queries.iter() { - query.0.hash(&mut hasher); - query.1.hash(&mut hasher); + query.0.hash_into(&mut hasher); + query.1.hash_into(&mut hasher); } hasher.update(b"num_fixed_queries"); hasher.update(&self.fixed_queries.len().to_le_bytes()); for query in self.fixed_queries.iter() { - query.0.hash(&mut hasher); - query.1.hash(&mut hasher); + query.0.hash_into(&mut hasher); + query.1.hash_into(&mut hasher); } hasher.update(b"num_permutations"); @@ -652,7 +652,7 @@ impl ConstraintSystem { for argument in self.permutations.iter() { hasher.update(&argument.get_columns().len().to_le_bytes()); for column in argument.get_columns().iter() { - column.hash(&mut hasher); + column.hash_into(&mut hasher); } } @@ -666,8 +666,8 @@ impl ConstraintSystem { .iter() .zip(argument.table_columns.iter()) { - input.hash(&mut hasher); - table.hash(&mut hasher); + input.hash_into(&mut hasher); + table.hash_into(&mut hasher); } } } diff --git a/src/plonk/permutation.rs b/src/plonk/permutation.rs index abf6af9..336a765 100644 --- a/src/plonk/permutation.rs +++ b/src/plonk/permutation.rs @@ -69,7 +69,7 @@ impl VerifyingKey { Ok(VerifyingKey { commitments }) } - pub(crate) fn hash>( + pub(crate) fn hash_into>( &self, hasher: &mut Blake2bState, transcript: &mut T, diff --git a/src/plonk/prover.rs b/src/plonk/prover.rs index 41069bb..15ec08b 100644 --- a/src/plonk/prover.rs +++ b/src/plonk/prover.rs @@ -31,7 +31,9 @@ pub fn create_proof, ConcreteCircuit: Circ } // Hash verification key into transcript - pk.vk.hash(transcript).map_err(|_| Error::TranscriptError)?; + pk.vk + .hash_into(transcript) + .map_err(|_| Error::TranscriptError)?; let domain = &pk.vk.domain; let mut meta = ConstraintSystem::default(); diff --git a/src/plonk/verifier.rs b/src/plonk/verifier.rs index d324d48..f1f09d2 100644 --- a/src/plonk/verifier.rs +++ b/src/plonk/verifier.rs @@ -30,7 +30,8 @@ pub fn verify_proof<'a, C: CurveAffine, T: TranscriptRead>( let num_proofs = instance_commitments.len(); // Hash verification key into transcript - vk.hash(transcript).map_err(|_| Error::TranscriptError)?; + vk.hash_into(transcript) + .map_err(|_| Error::TranscriptError)?; for instance_commitments in instance_commitments.iter() { // Hash the instance (external) commitments into the transcript diff --git a/src/poly.rs b/src/poly.rs index 1954d16..26e776a 100644 --- a/src/poly.rs +++ b/src/poly.rs @@ -231,7 +231,7 @@ impl Rotation { } /// Hash Rotation into a Blake2bState - pub fn hash(&self, hasher: &mut Blake2bState) { + pub fn hash_into(&self, hasher: &mut Blake2bState) { hasher.update(&format!("{:?}", self).as_bytes()); } } diff --git a/src/poly/domain.rs b/src/poly/domain.rs index 6298a27..04eaea9 100644 --- a/src/poly/domain.rs +++ b/src/poly/domain.rs @@ -9,7 +9,6 @@ use ff::{Field, PrimeField}; use std::marker::PhantomData; use blake2b_simd::State as Blake2bState; -use std::convert::TryInto; /// This structure contains precomputed constants and other details needed for /// performing operations on an evaluation domain of size $2^k$ and an extended @@ -381,7 +380,7 @@ impl EvaluationDomain { } /// Hashes the constants in the domain which influence the proof into a Blake2bState - pub fn hash(&self, hasher: &mut Blake2bState) { + pub fn hash_into(&self, hasher: &mut Blake2bState) { hasher.update(b"k"); hasher.update(&self.k.to_le_bytes());