Disambiguate naming of hash() -> hash_into()

This commit is contained in:
therealyingtong 2021-02-16 01:09:54 +08:00 committed by Sean Bowe
parent e7d6f67564
commit 52c028b4da
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
7 changed files with 25 additions and 23 deletions

View File

@ -79,17 +79,17 @@ impl<C: CurveAffine> VerifyingKey<C> {
}
/// Hashes a verification key into a transcript.
pub fn hash<T: Transcript<C>>(&self, transcript: &mut T) -> io::Result<()> {
pub fn hash_into<T: Transcript<C>>(&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<C: CurveAffine> VerifyingKey<C> {
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

View File

@ -29,7 +29,7 @@ impl<C: ColumnType> Column<C> {
&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<F: Field> Expression<F> {
}
/// 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<F: Field> ConstraintSystem<F> {
}
/// 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<F: Field> ConstraintSystem<F> {
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<F: Field> ConstraintSystem<F> {
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<F: Field> ConstraintSystem<F> {
.iter()
.zip(argument.table_columns.iter())
{
input.hash(&mut hasher);
table.hash(&mut hasher);
input.hash_into(&mut hasher);
table.hash_into(&mut hasher);
}
}
}

View File

@ -69,7 +69,7 @@ impl<C: CurveAffine> VerifyingKey<C> {
Ok(VerifyingKey { commitments })
}
pub(crate) fn hash<T: Transcript<C>>(
pub(crate) fn hash_into<T: Transcript<C>>(
&self,
hasher: &mut Blake2bState,
transcript: &mut T,

View File

@ -31,7 +31,9 @@ pub fn create_proof<C: CurveAffine, T: TranscriptWrite<C>, 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();

View File

@ -30,7 +30,8 @@ pub fn verify_proof<'a, C: CurveAffine, T: TranscriptRead<C>>(
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

View File

@ -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());
}
}

View File

@ -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<G: Group> EvaluationDomain<G> {
}
/// 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());