Skip to content

Commit 32407a5

Browse files
authored
feat: remove unnecessary state write (#36)
1 parent 0ddc818 commit 32407a5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/poseidon2.nr

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ impl Poseidon2 {
7070
}
7171

7272
// handle remaining elements after last full RATE-sized chunk
73-
let remainder_start = (in_len / RATE) * RATE;
74-
for j in remainder_start..in_len {
75-
state[j - remainder_start] += input[j];
73+
let num_extra_fields = in_len % RATE;
74+
if num_extra_fields != 0 {
75+
let remainder_start = in_len - num_extra_fields;
76+
state[0] += input[remainder_start];
77+
if num_extra_fields > 1 {
78+
state[1] += input[remainder_start + 1]
79+
}
7680
}
7781
} else {
7882
let mut states: [[Field; 4]; N / RATE + 1] = [[0; 4]; N / RATE + 1];

0 commit comments

Comments
 (0)