feat: reduced number of u128 ops in serialization#155
Closed
zac-williamson wants to merge 1 commit intomainfrom
Closed
feat: reduced number of u128 ops in serialization#155zac-williamson wants to merge 1 commit intomainfrom
zac-williamson wants to merge 1 commit intomainfrom
Conversation
Contributor
|
Thanks for catching this! benchmarks for |
Contributor
|
noticed we even don't have tests for |
Merged
2 tasks
TomAFrench
requested changes
Apr 7, 2025
Member
TomAFrench
left a comment
There was a problem hiding this comment.
The beta.4 release of noir will make the most efficient implementation of this to be
limb.assert_max_bit_size::<128>()
result[N - i - 1] = limb;We should avoid using an unconstrained function to do this.
Contributor
|
@zac-williamson @TomAFrench I have another PR open #157, that replicates this PR and also adds some other serialization methods. Should we close this branch and switch to the other PR? |
Contributor
|
closing this as it's done in #157 |
This file contains hidden or 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
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
calling
fn from_be_bytescalls a large number of u128 operations as byte sums are being computed. This PR constructs bignum limbs out of byte arrays using Field arithmetic operations, converting the result to u128.Problem*
u128 ops are expensive and
from_be_byteswas using a lot of them, makingfrom_be_bytescost ~1,000 gates more than neccessarySummary*
PR changes
from_be_bytesto evaluate most of its arithmetic operations using Field arithmetic. This is safe as we are computing sums ofu8objects and implicitly know that the output is range constrained.Additional Context
This PR should not create any breaking changes.
PR Checklist*
cargo fmton default settings.