-
Notifications
You must be signed in to change notification settings - Fork 1k
UInt256 long digits record #9677
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
Open
thomas-quadratic
wants to merge
17
commits into
hyperledger:main
Choose a base branch
from
thomas-quadratic:feat/uint256-as-record
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
UInt256 long digits record #9677
thomas-quadratic
wants to merge
17
commits into
hyperledger:main
from
thomas-quadratic:feat/uint256-as-record
Conversation
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
Before, limbs were stored in little-endian. But to use Arrays.mismatch to our advantage, it is better to have it big-endian. This commit makes UInt256.java big-endian in limbs. We still need to migrate all tests and benchmark. Signed-off-by: Thomas Zamojski <[email protected]>
Also added tests that were failing and now pass. Signed-off-by: Thomas Zamojski <[email protected]>
Signed-off-by: Thomas Zamojski <[email protected]>
Signed-off-by: Thomas Zamojski <[email protected]>
Small cleaning up of the private methods for addition and compareLimbs. Should be easier for the compiler. Signed-off-by: Thomas Zamojski <[email protected]>
UInt256 used int[] for limbs, primarily for simplicity, e.g. having the possibility to widen to long. However, methods exists to work with long[] and no widening. This commit implements long limbs. To avoid widening, we do: 1. add: overflow check 2. mul: native multiplyHigh (compiled to assembly mulq) 3. div: more complicated, see the gnump division paper. Signed-off-by: Thomas Zamojski <[email protected]>
Signed-off-by: Thomas Zamojski <[email protected]>
Signed-off-by: Thomas Zamojski <[email protected]>
Signed-off-by: Thomas Zamojski <[email protected]>
Signed-off-by: Thomas Zamojski <[email protected]>
Signed-off-by: Thomas Zamojski <[email protected]>
Signed-off-by: Thomas Zamojski <[email protected]>
This was referenced Jan 27, 2026
Signed-off-by: Thomas Zamojski <[email protected]>
Signed-off-by: Thomas Zamojski <[email protected]>
Contributor
Author
|
Updated benchmarks with the new commits that support the other operations: AddMod/MulMod/SMod
|
Signed-off-by: Thomas Zamojski <[email protected]>
Signed-off-by: Thomas Zamojski <[email protected]>
Contributor
Author
|
Changing single digit quotient estimates using 3 digits by 2 digits (div3by2) to 2 digits by 1 digit (div2by1).
|
Signed-off-by: Thomas Zamojski <[email protected]>
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.
PR description
This PR cumulates a few improvements/refactoring for UInt256 modular arithmetics:
Long limbs are more efficient because they divide by 2 the number of digits, thus reducing the number of steps in arithmetics operations. However, it complexifies the implementation for division as widening is not possible anymore. Fortunately, quotient estimates algorithms that avoids widening exists, see division paper.
Records are chosen to represent fixed-width UInt256 because of potential future support for Vahalla value records, which would require almost no change to the code.
Here are the benchmarks compared to the actual implementation:
Current status
Currently working and tested ops:
Thanks for sending a pull request! Have you done the following?
doc-change-requiredlabel to this PR if updates are required.Locally, you can run these tests to catch failures early:
./gradlew spotlessApply./gradlew build./gradlew acceptanceTest./gradlew integrationTest./gradlew ethereum:referenceTests:referenceTests