Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove unnecessary branching in keccak impl (#6133)
# Description ## Problem\* Resolves <!-- Link to GitHub Issue --> ## Summary\* This PR simplifies the keccak256 implementation by removing a branch which we'll never actually go down. When converting from bytes to u64 limbs we have an if statement with the condition `if (limb_start + WORD_SIZE > max_blocks_length)`. We can show that the maximum value of the LHS is exactly `max_blocks_length` and so this branch will never trigger (however brillig cannot know that so it's preserved in the bytecode). ``` num_limbs * WORD_SIZE = max_blocks * LIMBS_PER_BLOCK * WORD_SIZE = (max_blocks_length / BLOCK_SIZE_IN_BYTES) * LIMBS_PER_BLOCK * WORD_SIZE // using definition of `max_blocks` = max_blocks_length * (LIMBS_PER_BLOCK * WORD_SIZE / BLOCK_SIZE_IN_BYTES) = max_blocks_length * (LIMBS_PER_BLOCK / LIMBS_PER_BLOCK) // using definition of `LIMBS_PER_BLOCK` = max_blocks_length ``` ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
- Loading branch information