Skip to content

Commit

Permalink
perf: optimize console PoseidonSponge::apply_s_box
Browse files Browse the repository at this point in the history
Signed-off-by: Maciej Zwolinski <[email protected]>
  • Loading branch information
zvolin committed Oct 26, 2022
1 parent e1150d1 commit 1bfd5ce
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions console/algorithms/src/poseidon/helpers/sponge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ impl<E: Environment, const RATE: usize, const CAPACITY: usize> PoseidonSponge<E,
#[inline]
fn apply_s_box(&mut self, is_full_round: bool) {
// Full rounds apply the S Box (x^alpha) to every element of state
let alpha = Field::from_u64(self.parameters.alpha);
if is_full_round {
for elem in self.state.iter_mut() {
*elem = elem.pow(Field::from_u64(self.parameters.alpha));
*elem = elem.pow(alpha);
}
}
// Partial rounds apply the S Box (x^alpha) to just the first element of state
else {
self.state[0] = self.state[0].pow(Field::from_u64(self.parameters.alpha));
self.state[0] = self.state[0].pow(alpha);
}
}

Expand Down

0 comments on commit 1bfd5ce

Please sign in to comment.