-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
engine-modexp
bug fixes and performance improvements
#809
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The main issue was that q_hat could exceed Word::MAX, so it needs to be DoubleWord, not Word. Additionally, the q_hat/r_hat adjustment loop has been replaced with the canonical version from Knuth's algorithm, and some minor optimizations around Word/DoubleWord casting are implemented.
joshuajbouw
approved these changes
Jul 31, 2023
I believe the cargo fmt is failing due to the use of nightly cargo fmt check in the CI. |
@joshuajbouw no. We have pretty old nightly in our CI so it should be fixed, I guess. |
birchmd
approved these changes
Aug 1, 2023
github-merge-queue bot
pushed a commit
that referenced
this pull request
Aug 3, 2023
## Description With the improvements from #809 merged, we can start using the Aurora implementation of modexp. ## Performance / NEAR gas cost considerations There is a gas cost increase in one of the repro tests. This must mean the `ibig` implementation of modexp is faster for the case used in that transaction. But using the Aurora implementation of modexp is still an improvement because the worst-case performance of the Aurora implementation is better than `ibig`, as exemplified in the `bench_modexp_standalone` test. ## Testing Existing tests.
aleksuss
pushed a commit
that referenced
this pull request
Aug 10, 2023
## Description This fixes the following issues with `engine-modexp`: - addition overflow in big_sq that would lead to incorrect output (and a crash in debug mode) - assert failure in sub_to_same_size that would lead to incorrect output - slow modular exponentiation with even modulus. The bottleneck was the routine were the inverse of A mod M was computed, where M is a power of two. This inversion function has been replaced with the algorithm found in [this paper](https://eprint.iacr.org/2017/411.pdf), which is much faster. ## Performance / NEAR gas cost considerations The performance of modular exponentiation with even modulus is improved. Performance remains the same for odd modulus. ## Testing Extensive fuzz testing, was was also the method used to detect the issues that this PR addresses. ## How should this be reviewed ## Additional information --------- Co-authored-by: Michael Birch <michael.birch@aurora.dev>
aleksuss
pushed a commit
that referenced
this pull request
Aug 10, 2023
## Description With the improvements from #809 merged, we can start using the Aurora implementation of modexp. ## Performance / NEAR gas cost considerations There is a gas cost increase in one of the repro tests. This must mean the `ibig` implementation of modexp is faster for the case used in that transaction. But using the Aurora implementation of modexp is still an improvement because the worst-case performance of the Aurora implementation is better than `ibig`, as exemplified in the `bench_modexp_standalone` test. ## Testing Existing tests.
mrLSD
approved these changes
Nov 22, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This fixes the following issues with
engine-modexp
:Performance / NEAR gas cost considerations
The performance of modular exponentiation with even modulus is improved. Performance remains the same for odd modulus.
Testing
Extensive fuzz testing, was was also the method used to detect the issues that this PR addresses.
How should this be reviewed
Additional information