-
Notifications
You must be signed in to change notification settings - Fork 504
optimize paddingFixedWidth of sha3 using divmod hint #1450
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
optimize paddingFixedWidth of sha3 using divmod hint #1450
Conversation
|
Thanks for the PR. I'll review it soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constraint comparator.AssertIsLessEq(length, maxLen) should be added to prevent the wrong value from being returned when length>maxLen.
|
Thanks for the contribution @ggq89! Looks good to me. However, I currently removed the I also added the assertions you mentioned in the comments, even though I'm not sure if it could be exploitable without, imo as far as I figured, it looks like it would create a digest for which there really isn't a preimage, so I guess in most applications it would be safe. But maybe there are some use cases where it could lead to some unexpected output (i.e. hashing known message and the digest is incorrect, leading to double spend using nullifiers etc.). Can you have a look at my changes and if it is OK? If so, then I'll go forward with merging the PR. Thanks again! |
|
@ivokub It looks fine after you make some changes,and thank you for stepping in! |
Thanks for confirming! |
Description
In this PR, a divmod function is implemented with hint, and it is used to optimize the paddingFixedWidth of sha3 to reduce the number of selects in the process of padding data and calculating numberOfBlocks.
In the project we are currently working on, one of the data lengths to be keccak256 hashed ranges from 1130 to 1710. Using the new FixedLengthSum can reduce about 50,000 constraints, as shown below:
Type of change
How has this been tested?
How has this been benchmarked?
Checklist:
golangci-lintdoes not output errors locally