Skip to content

Commit af9b726

Browse files
authored
feat!: remove variable length hash padding (#15)
1 parent f6ca8ad commit af9b726

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
dist
2+
node_modules
13
target
24
export
35
gates_report.json

src/poseidon2.nr

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct Poseidon2 {
1313
impl Poseidon2 {
1414
#[no_predicates]
1515
pub fn hash<let N: u32>(input: [Field; N], message_size: u32) -> Field {
16-
Poseidon2::hash_internal(input, message_size, message_size != N)
16+
Poseidon2::hash_internal(input, message_size)
1717
}
1818

1919
pub(crate) fn new(iv: Field) -> Poseidon2 {
@@ -59,11 +59,7 @@ impl Poseidon2 {
5959
self.state[0]
6060
}
6161

62-
fn hash_internal<let N: u32>(
63-
input: [Field; N],
64-
in_len: u32,
65-
is_variable_length: bool,
66-
) -> Field {
62+
fn hash_internal<let N: u32>(input: [Field; N], in_len: u32) -> Field {
6763
let two_pow_64 = 18446744073709551616;
6864
let iv: Field = (in_len as Field) * two_pow_64;
6965
let mut sponge = Poseidon2::new(iv);
@@ -72,13 +68,6 @@ impl Poseidon2 {
7268
sponge.absorb(input[i]);
7369
}
7470
}
75-
76-
// In the case where the hash preimage is variable-length, we append `1` to the end of the input, to distinguish
77-
// from fixed-length hashes. (the combination of this additional field element + the hash IV ensures
78-
// fixed-length and variable-length hashes do not collide)
79-
if is_variable_length {
80-
sponge.absorb(1);
81-
}
8271
sponge.squeeze()
8372
}
8473
}

0 commit comments

Comments
 (0)