-
Notifications
You must be signed in to change notification settings - Fork 70
Round up bits_precision when creating BoxedUint
#365
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
Merged
Merged
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
d85d5e4 to
fce073b
Compare
tarcieri
reviewed
Nov 30, 2023
Member
|
I'm generally OK with this. We had similar requests in the past: #258 |
Contributor
Author
|
Should I add rounding up there too? I think it is self-evident that |
fce073b to
a6a937b
Compare
Member
@fjarri sure, sounds good |
a6a937b to
bc9709c
Compare
Contributor
Author
|
Done |
Member
|
@fjarri this needs a rebase now |
…instead of panicking
And also fix the copy-paste artifacts in tests.
bc9709c to
41462bd
Compare
Contributor
Author
|
Rebased |
tarcieri
reviewed
Dec 2, 2023
tarcieri
reviewed
Dec 2, 2023
tarcieri
reviewed
Dec 2, 2023
Merged
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.
I understand that this change may be controversial, but let me just put it out there. The reason being, why panic when we don't have to, and also to prevent bugs when something works on a 32 bit but doesn't on a 64 bit target.
BoxedUint::zero_with_precision(),one_with_precision(),max()round upbits_precisionto a multiple ofLimb::BITS. It's a little weird in the case ofmax(), but I am not sure this method should be public in the first place (and perhaps should be renamed).bits_precisioninBoxedUint::random()(generating a random number in range[0, 2^bits_precision)).boxed/rand.rswhich didn't actually testBoxedUint.bits_precisionwhen decodingBoxedUintfrom bytes, to match the constructors' behavior.nlimbs()in the same way. Fixesnlimbs!()macro doesn't support rounding up to the limb size #258.An option here is to keep the given
bits_precisionas a field in theBoxedUintwithout rounding it up. Then we will have to zeroize MSBs in arithmetic operations.