diff --git a/plonky2/src/hash/hashing.rs b/plonky2/src/hash/hashing.rs index 468bd1b8..9d043ea3 100644 --- a/plonky2/src/hash/hashing.rs +++ b/plonky2/src/hash/hashing.rs @@ -12,16 +12,6 @@ pub(crate) const SPONGE_RATE: usize = 8; pub(crate) const SPONGE_CAPACITY: usize = 4; pub const SPONGE_WIDTH: usize = SPONGE_RATE + SPONGE_CAPACITY; -/// Hash the slice if necessary to reduce its length to ~256 bits. If it already fits, this is a -/// no-op. -pub fn hash_or_noop>(inputs: &[F]) -> HashOut { - if inputs.len() <= 4 { - HashOut::from_partial(inputs) - } else { - hash_n_to_hash_no_pad::(inputs) - } -} - impl, const D: usize> CircuitBuilder { pub fn hash_or_noop>(&mut self, inputs: Vec) -> HashOutTarget { let zero = self.zero(); diff --git a/plonky2/src/plonk/config.rs b/plonky2/src/plonk/config.rs index 76891240..40179c38 100644 --- a/plonky2/src/plonk/config.rs +++ b/plonky2/src/plonk/config.rs @@ -3,6 +3,7 @@ use std::fmt::Debug; use plonky2_field::extension_field::quadratic::QuadraticExtension; use plonky2_field::extension_field::{Extendable, FieldExtension}; use plonky2_field::goldilocks_field::GoldilocksField; +use plonky2_util::ceil_div_usize; use serde::{de::DeserializeOwned, Serialize}; use crate::hash::hash_types::HashOut; @@ -49,8 +50,12 @@ pub trait Hasher: Sized + Clone + Debug + Eq + PartialEq { /// Hash the slice if necessary to reduce its length to ~256 bits. If it already fits, this is a /// no-op. fn hash_or_noop(inputs: &[F]) -> Self::Hash { - if inputs.len() <= 4 { - let inputs_bytes = HashOut::from_partial(inputs).to_bytes(); + if inputs.len() * ceil_div_usize(F::BITS, 8) <= Self::HASH_SIZE { + let mut inputs_bytes = inputs + .iter() + .flat_map(|x| x.to_canonical_u64().to_le_bytes()) + .collect::>(); + inputs_bytes.resize(Self::HASH_SIZE, 0); Self::Hash::from_bytes(&inputs_bytes) } else { Self::hash_no_pad(inputs)