Hash in field modulus, curve parameters

This commit is contained in:
therealyingtong 2021-02-17 11:32:14 +08:00 committed by Sean Bowe
parent 52c028b4da
commit f35e190455
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
3 changed files with 54 additions and 0 deletions

View File

@ -85,6 +85,53 @@ impl<C: CurveAffine> VerifyingKey<C> {
.personal(C::BLAKE2B_PERSONALIZATION) .personal(C::BLAKE2B_PERSONALIZATION)
.to_state(); .to_state();
// Hash in curve parameters
hasher.update(&C::Scalar::ROOT_OF_UNITY.to_bytes());
hasher.update(&C::Scalar::ROOT_OF_UNITY_INV.to_bytes());
hasher.update(
&(C::Scalar::T_MINUS1_OVER2
.iter()
.fold(Vec::new(), |mut res, word| {
res.extend_from_slice(&word.to_le_bytes());
res
})),
);
hasher.update(&C::Scalar::DELTA.to_bytes());
hasher.update(&C::Scalar::TWO_INV.to_bytes());
hasher.update(&C::Scalar::RESCUE_ALPHA.to_le_bytes());
hasher.update(
&(C::Scalar::RESCUE_INVALPHA
.iter()
.fold(Vec::new(), |mut res, word| {
res.extend_from_slice(&word.to_le_bytes());
res
})),
);
hasher.update(&C::Base::ZETA.to_bytes());
hasher.update(&C::Base::ROOT_OF_UNITY.to_bytes());
hasher.update(&C::Base::ROOT_OF_UNITY_INV.to_bytes());
hasher.update(
&(C::Base::T_MINUS1_OVER2
.iter()
.fold(Vec::new(), |mut res, word| {
res.extend_from_slice(&word.to_le_bytes());
res
})),
);
hasher.update(&C::Base::DELTA.to_bytes());
hasher.update(&C::Base::TWO_INV.to_bytes());
hasher.update(&C::Base::RESCUE_ALPHA.to_le_bytes());
hasher.update(
&(C::Base::RESCUE_INVALPHA
.iter()
.fold(Vec::new(), |mut res, word| {
res.extend_from_slice(&word.to_le_bytes());
res
})),
);
hasher.update(&C::Base::ZETA.to_bytes());
// Hash in constants in the domain which influence the proof // Hash in constants in the domain which influence the proof
self.domain.hash_into(&mut hasher); self.domain.hash_into(&mut hasher);

View File

@ -30,6 +30,7 @@ impl<C: ColumnType> Column<C> {
} }
pub(crate) fn hash_into(&self, hasher: &mut Blake2bState) { pub(crate) fn hash_into(&self, hasher: &mut Blake2bState) {
hasher.update(&format!("{:?}", self).as_bytes().len().to_le_bytes());
hasher.update(&format!("{:?}", self).as_bytes()); hasher.update(&format!("{:?}", self).as_bytes());
} }
} }
@ -325,6 +326,7 @@ impl<F: Field> Expression<F> {
/// Hash an Expression into a Blake2bState /// Hash an Expression into a Blake2bState
pub fn hash_into(&self, hasher: &mut Blake2bState) { pub fn hash_into(&self, hasher: &mut Blake2bState) {
hasher.update(&format!("{:?}", self).as_bytes().len().to_le_bytes());
hasher.update(&format!("{:?}", self).as_bytes()); hasher.update(&format!("{:?}", self).as_bytes());
} }
} }

View File

@ -381,6 +381,11 @@ impl<G: Group> EvaluationDomain<G> {
/// Hashes the constants in the domain which influence the proof into a Blake2bState /// Hashes the constants in the domain which influence the proof into a Blake2bState
pub fn hash_into(&self, hasher: &mut Blake2bState) { pub fn hash_into(&self, hasher: &mut Blake2bState) {
// Hash in field modulus
let modulus = G::Scalar::char_le_bits();
hasher.update(&modulus.len().to_le_bytes());
hasher.update(format!("{:?}", modulus).as_bytes());
hasher.update(b"k"); hasher.update(b"k");
hasher.update(&self.k.to_le_bytes()); hasher.update(&self.k.to_le_bytes());