We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 211d4e9 commit 1123325Copy full SHA for 1123325
src/poseidon2.nr
@@ -66,11 +66,16 @@ impl Poseidon2 {
66
state[RATE] = iv;
67
68
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
- }
+ for i in 0..(in_len / RATE) {
+ state[0] += input[i * RATE];
+ state[1] += input[i * RATE + 1];
+ state[2] += input[i * RATE + 2];
+ 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];
79
}
80
} else {
81
for i in 0..input.len() {
0 commit comments