Skip to content

Commit 1123325

Browse files
committed
unroll
1 parent 211d4e9 commit 1123325

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/poseidon2.nr

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,16 @@ impl Poseidon2 {
6666
state[RATE] = iv;
6767

6868
if std::runtime::is_unconstrained() {
69-
for i in 0..in_len {
70-
state[i % RATE] += input[i];
71-
if (i + 1) % RATE == 0 {
72-
state = crate::poseidon2_permutation(state, 4);
73-
}
69+
for i in 0..(in_len / RATE) {
70+
state[0] += input[i * RATE];
71+
state[1] += input[i * RATE + 1];
72+
state[2] += input[i * RATE + 2];
73+
state = crate::poseidon2_permutation(state, 4);
74+
}
75+
// handle remaining (<3) elements
76+
let remainder_start = (in_len / RATE) * RATE;
77+
for j in remainder_start..in_len {
78+
state[j - remainder_start] += input[j];
7479
}
7580
} else {
7681
for i in 0..input.len() {

0 commit comments

Comments
 (0)