diff --git a/acvm-repo/bn254_blackbox_solver/src/poseidon2.rs b/acvm-repo/bn254_blackbox_solver/src/poseidon2.rs index 3aa735388ca..fe1e176d824 100644 --- a/acvm-repo/bn254_blackbox_solver/src/poseidon2.rs +++ b/acvm-repo/bn254_blackbox_solver/src/poseidon2.rs @@ -548,19 +548,13 @@ impl<'a> Poseidon2<'a> { /// The `is_variable_length` parameter is there to so we can produce an equivalent hash with /// the Barretenberg implementation which distinguishes between variable and fixed length inputs. /// Set it to true if the input length matches the static size expected by the Noir function. -pub fn poseidon_hash( - inputs: &[FieldElement], - is_variable_length: bool, -) -> Result { +pub fn poseidon_hash(inputs: &[FieldElement]) -> Result { let two_pow_64 = 18446744073709551616_u128.into(); let iv = FieldElement::from(inputs.len()) * two_pow_64; let mut sponge = Poseidon2Sponge::new(iv, 3); for input in inputs.iter() { sponge.absorb(*input)?; } - if is_variable_length { - sponge.absorb(FieldElement::from(1u32))?; - } sponge.squeeze() } @@ -650,7 +644,7 @@ mod test { FieldElement::from(3u128), FieldElement::from(4u128), ]; - let result = super::poseidon_hash(&fields, false).expect("should hash successfully"); + let result = super::poseidon_hash(&fields).expect("should hash successfully"); assert_eq!( result, field_from_hex("130bf204a32cac1f0ace56c78b731aa3809f06df2731ebcf6b3464a15788b1b9"), diff --git a/noir_stdlib/src/hash/poseidon2.nr b/noir_stdlib/src/hash/poseidon2.nr index ad4476f0d7c..5599c9a8f70 100644 --- a/noir_stdlib/src/hash/poseidon2.nr +++ b/noir_stdlib/src/hash/poseidon2.nr @@ -13,7 +13,7 @@ pub struct Poseidon2 { impl Poseidon2 { #[no_predicates] pub fn hash(input: [Field; N], message_size: u32) -> Field { - Poseidon2::hash_internal(input, message_size, message_size != N) + Poseidon2::hash_internal(input, message_size) } pub fn new(iv: Field) -> Poseidon2 { @@ -59,11 +59,7 @@ impl Poseidon2 { self.state[0] } - fn hash_internal( - input: [Field; N], - in_len: u32, - is_variable_length: bool, - ) -> Field { + fn hash_internal(input: [Field; N], in_len: u32) -> Field { let two_pow_64 = 18446744073709551616; let iv: Field = (in_len as Field) * two_pow_64; let mut sponge = Poseidon2::new(iv); @@ -73,12 +69,6 @@ impl Poseidon2 { } } - // In the case where the hash preimage is variable-length, we append `1` to the end of the input, to distinguish - // from fixed-length hashes. (the combination of this additional field element + the hash IV ensures - // fixed-length and variable-length hashes do not collide) - if is_variable_length { - sponge.absorb(1); - } sponge.squeeze() } } diff --git a/tooling/nargo_cli/tests/stdlib-props.rs b/tooling/nargo_cli/tests/stdlib-props.rs index 780b34bf0c3..b2adb0ae347 100644 --- a/tooling/nargo_cli/tests/stdlib-props.rs +++ b/tooling/nargo_cli/tests/stdlib-props.rs @@ -268,7 +268,7 @@ fn fuzz_poseidon2_equivalence() { let strategy = (0..=max_len) .prop_flat_map(field_vec_strategy) .prop_map(move |mut msg| { - let output = poseidon_hash(&msg, msg.len() < max_len).expect("failed to hash"); + let output = poseidon_hash(&msg).expect("failed to hash"); // The input has to be padded to the maximum length. let msg_size = msg.len();