Skip to content

Commit c92ab8f

Browse files
committed
feat: remove unnecessary state write
1 parent 7e81d48 commit c92ab8f

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/poseidon2.nr

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,13 @@ impl Poseidon2 {
7171

7272
// handle remaining elements after last full RATE-sized chunk
7373
let num_extra_fields = in_len % RATE;
74-
let remainder_start = in_len - num_extra_fields;
75-
state[0] += if num_extra_fields > 0 {
76-
input[remainder_start]
77-
} else {
78-
0
79-
};
80-
state[1] += if num_extra_fields > 1 {
81-
input[remainder_start + 1]
82-
} else {
83-
0
84-
};
85-
state[2] += if num_extra_fields > 2 {
86-
input[remainder_start + 2]
87-
} else {
88-
0
89-
};
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+
}
80+
}
9081
} else {
9182
let mut states: [[Field; 4]; N / RATE + 1] = [[0; 4]; N / RATE + 1];
9283
states[0] = state;

0 commit comments

Comments
 (0)