Skip to content

Commit

Permalink
Improve poseidon hash perf by using assign operators
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed Mar 14, 2024
1 parent 400deb6 commit b3205e6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions starknet-crypto/src/poseidon_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn poseidon_permute_comp(state: &mut [FieldElement; 3]) {
#[inline(always)]
fn mix(state: &mut [FieldElement; 3]) {
let t = state[0] + state[1] + state[2];
state[0] = t + state[0].double();
state[0] += state[0] + t;
state[1] = t - state[1].double();
state[2] = t - FieldElement::THREE * state[2];
}
Expand All @@ -130,12 +130,13 @@ fn round_comp(state: &mut [FieldElement; 3], idx: usize, full: bool) {
state[0] += POSEIDON_COMP_CONSTS[idx];
state[1] += POSEIDON_COMP_CONSTS[idx + 1];
state[2] += POSEIDON_COMP_CONSTS[idx + 2];
state[0] = state[0] * state[0] * state[0];
state[1] = state[1] * state[1] * state[1];
state[2] = state[2] * state[2] * state[2];

state[0] *= state[0] * state[0];
state[1] *= state[1] * state[1];
state[2] *= state[2] * state[2];
} else {
state[2] += POSEIDON_COMP_CONSTS[idx];
state[2] = state[2] * state[2] * state[2];
state[2] *= state[2] * state[2];
}
mix(state);
}
Expand Down

0 comments on commit b3205e6

Please sign in to comment.