mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-04 20:03:39 +00:00
Do not return hash results from component hash() methods
This commit is contained in:
parent
4aa4b4463a
commit
b204ff74a8
5 changed files with 19 additions and 23 deletions
|
|
@ -86,12 +86,10 @@ impl<C: CurveAffine> VerifyingKey<C> {
|
|||
.to_state();
|
||||
|
||||
// Hash in constants in the domain which influence the proof
|
||||
let domain_hash = &self.domain.hash(&mut hasher);
|
||||
transcript.common_scalar(C::Scalar::from_bytes_wide(domain_hash))?;
|
||||
self.domain.hash(&mut hasher);
|
||||
|
||||
// Hash in `ConstraintSystem`
|
||||
let cs_hash = &self.cs.hash(&mut hasher);
|
||||
transcript.common_scalar(C::Scalar::from_bytes_wide(cs_hash))?;
|
||||
self.cs.hash(&mut hasher);
|
||||
|
||||
// Hash in vector of fixed commitments
|
||||
hasher.update(b"num_fixed_commitments");
|
||||
|
|
@ -104,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(transcript)?;
|
||||
permutation.hash(&mut hasher, transcript)?;
|
||||
}
|
||||
|
||||
// Hash in final Blake2bState
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use core::cmp::max;
|
|||
use core::ops::{Add, Mul};
|
||||
use ff::Field;
|
||||
use std::{
|
||||
convert::{TryFrom, TryInto},
|
||||
convert::TryFrom,
|
||||
ops::{Neg, Sub},
|
||||
};
|
||||
|
||||
|
|
@ -29,9 +29,8 @@ impl<C: ColumnType> Column<C> {
|
|||
&self.column_type
|
||||
}
|
||||
|
||||
pub(crate) fn hash(&self, hasher: &mut Blake2bState) -> [u8; 64] {
|
||||
pub(crate) fn hash(&self, hasher: &mut Blake2bState) {
|
||||
hasher.update(&format!("{:?}", self).as_bytes());
|
||||
hasher.finalize().as_bytes().try_into().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -325,9 +324,8 @@ impl<F: Field> Expression<F> {
|
|||
}
|
||||
|
||||
/// Hash an Expression into a Blake2bState
|
||||
pub fn hash(&self, hasher: &mut Blake2bState) -> [u8; 64] {
|
||||
pub fn hash(&self, hasher: &mut Blake2bState) {
|
||||
hasher.update(&format!("{:?}", self).as_bytes());
|
||||
hasher.finalize().as_bytes().try_into().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -612,7 +610,7 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
}
|
||||
|
||||
/// Hashes the `ConstraintSystem` into a `u64`.
|
||||
pub fn hash(&self, mut hasher: &mut Blake2bState) -> [u8; 64] {
|
||||
pub fn hash(&self, mut hasher: &mut Blake2bState) {
|
||||
hasher.update(b"num_fixed_columns");
|
||||
hasher.update(&self.num_fixed_columns.to_le_bytes());
|
||||
|
||||
|
|
@ -625,7 +623,6 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
hasher.update(b"num_gates");
|
||||
hasher.update(&self.gates.len().to_le_bytes());
|
||||
for gate in self.gates.iter() {
|
||||
hasher.update(gate.0.to_owned().as_bytes());
|
||||
gate.1.hash(&mut hasher);
|
||||
}
|
||||
|
||||
|
|
@ -663,7 +660,7 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
hasher.update(&self.lookups.len().to_le_bytes());
|
||||
for argument in self.lookups.iter() {
|
||||
hasher.update(&argument.input_columns.len().to_le_bytes());
|
||||
hasher.update(&argument.table_columns.len().to_le_bytes());
|
||||
assert_eq!(argument.input_columns.len(), argument.table_columns.len());
|
||||
for (input, table) in argument
|
||||
.input_columns
|
||||
.iter()
|
||||
|
|
@ -673,7 +670,5 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
table.hash(&mut hasher);
|
||||
}
|
||||
}
|
||||
|
||||
hasher.finalize().as_bytes().try_into().unwrap()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ pub(crate) mod keygen;
|
|||
pub(crate) mod prover;
|
||||
pub(crate) mod verifier;
|
||||
|
||||
use blake2b_simd::State as Blake2bState;
|
||||
use std::io;
|
||||
|
||||
/// A permutation argument.
|
||||
|
|
@ -68,7 +69,13 @@ impl<C: CurveAffine> VerifyingKey<C> {
|
|||
Ok(VerifyingKey { commitments })
|
||||
}
|
||||
|
||||
pub(crate) fn hash<T: Transcript<C>>(&self, transcript: &mut T) -> io::Result<()> {
|
||||
pub(crate) fn hash<T: Transcript<C>>(
|
||||
&self,
|
||||
hasher: &mut Blake2bState,
|
||||
transcript: &mut T,
|
||||
) -> io::Result<()> {
|
||||
hasher.update(b"num_commitments");
|
||||
hasher.update(&self.commitments.len().to_le_bytes());
|
||||
for commitment in &self.commitments {
|
||||
transcript.common_point(*commitment)?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use crate::arithmetic::parallelize;
|
|||
|
||||
use blake2b_simd::State as Blake2bState;
|
||||
use ff::Field;
|
||||
use std::convert::TryInto;
|
||||
use std::fmt::Debug;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::{Add, Deref, DerefMut, Index, IndexMut, Mul, RangeFrom, RangeFull, Sub};
|
||||
|
|
@ -232,8 +231,7 @@ impl Rotation {
|
|||
}
|
||||
|
||||
/// Hash Rotation into a Blake2bState
|
||||
pub fn hash(&self, hasher: &mut Blake2bState) -> [u8; 64] {
|
||||
pub fn hash(&self, hasher: &mut Blake2bState) {
|
||||
hasher.update(&format!("{:?}", self).as_bytes());
|
||||
hasher.finalize().as_bytes().try_into().unwrap()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -380,8 +380,8 @@ impl<G: Group> EvaluationDomain<G> {
|
|||
self.quotient_poly_degree as usize
|
||||
}
|
||||
|
||||
/// Hashes the constants in the domain which influence the proof into a u64
|
||||
pub fn hash(&self, hasher: &mut Blake2bState) -> [u8; 64] {
|
||||
/// Hashes the constants in the domain which influence the proof into a Blake2bState
|
||||
pub fn hash(&self, hasher: &mut Blake2bState) {
|
||||
hasher.update(b"k");
|
||||
hasher.update(&self.k.to_le_bytes());
|
||||
|
||||
|
|
@ -390,7 +390,5 @@ impl<G: Group> EvaluationDomain<G> {
|
|||
|
||||
hasher.update(b"omega");
|
||||
hasher.update(&self.omega.to_bytes());
|
||||
|
||||
hasher.finalize().as_bytes().try_into().unwrap()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue