fix: fix value bit corruption in right_shift#348
Merged
apoelstra merged 2 commits intoBlockstreamResearch:masterfrom Mar 3, 2026
Merged
fix: fix value bit corruption in right_shift#348apoelstra merged 2 commits intoBlockstreamResearch:masterfrom
apoelstra merged 2 commits intoBlockstreamResearch:masterfrom
Conversation
Collaborator
|
Can you swap the two commits? I appreciate having them separate but I'd like them both to pass tests in the git history. |
Collaborator
|
c70e3ed looks great! This is a simple, elegant fix (and way simpler than the stuff we were trying to do with the constructors, and with attempting to enforce an "all padding is 0" invariant). The tests look good to me. Appreciate the comments, though I suspect they'll wind up being out-of-date if we change anything about our internal representation. We can eventually delete them. But for now let's keep them. |
Contributor
Author
|
swap or squash? Happy to do either, but squashing is easier |
Collaborator
|
@stringhandler I'd prefer to swap. You can swap pretty easily with |
New benchmarks test node::redeem::benches::decode_fixed_program ... bench: 47,575.83 ns/iter (+/- 1,888.92) test value::benches::bench_value_create_512_256 ... bench: 62,040.00 ns/iter (+/- 684.18) test value::benches::bench_value_create_512_256_compact ... bench: 3,091.83 ns/iter (+/- 19.26) test value::benches::bench_value_create_512_256_padded ... bench: 3,034.38 ns/iter (+/- 17.38) test value::benches::bench_value_create_64k ... bench: 671,748.75 ns/iter (+/- 4,494.75) test value::benches::bench_value_create_64k_compact ... bench: 32,111.70 ns/iter (+/- 5,517.22) test value::benches::bench_value_create_64k_padded ... bench: 32,177.62 ns/iter (+/- 7,199.71) test value::benches::bench_value_create_deep_some ... bench: 401,901.88 ns/iter (+/- 4,945.75) test value::benches::bench_value_create_deep_some_compact ... bench: 145,748.00 ns/iter (+/- 833.20) test value::benches::bench_value_create_deep_some_padded ... bench: 1,205.44 ns/iter (+/- 5.89) test value::benches::bench_value_create_u2048 ... bench: 482,537.50 ns/iter (+/- 8,726.38) test value::benches::bench_value_create_u2048_compact ... bench: 2,169.61 ns/iter (+/- 7.86) test value::benches::bench_value_create_u2048_padded ... bench: 2,075.53 ns/iter (+/- 16.34) test value::benches::bench_value_create_u64 ... bench: 32.03 ns/iter (+/- 0.91) test value::benches::bench_value_create_u64_compact ... bench: 162.57 ns/iter (+/- 1.75) test value::benches::bench_value_create_u64_padded ... bench: 113.74 ns/iter (+/- 0.67) test value::benches::bench_value_display_512_256 ... bench: 74,847.14 ns/iter (+/- 1,099.57) test value::benches::bench_value_display_64k ... bench: 709,160.00 ns/iter (+/- 12,038.00) test value::benches::bench_value_display_deep_some ... bench: 43,401.18 ns/iter (+/- 559.59) test value::benches::bench_value_display_u2024 ... bench: 44,913.00 ns/iter (+/- 477.15) test value::benches::bench_value_display_u64 ... bench: 357.24 ns/iter (+/- 7.69)
c70e3ed to
b64e1b3
Compare
Contributor
Author
|
Done |
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.
Yet another option to solve #337
The tests are actually generated by Claude. The comments are a bit wordy, so happy to try clean it up if it bothers anyone.
The interesting thing to note is that the bug is not as a result of
from_padded_bits, as apoelstra (and myself) suspected. Upon adding the two regression tests from #339,prune_regression_337_1still fails, indicating another bug infrom_padded_bits.However,
prune_regression_337_2passes on this PR without any changes tofrom_padded_bits. The tests added in this PR also reproduce the error without callingfrom_padded_bits.I have also tried to keep the optimization of not cloning the array if the bit is already equal to
new_bitand added it to the true case as well.For those interested here are the before and after benchmarks. Nothing jumps out at me as a huge improvement or degradation.
BEFORE (Commit f84b09d)
AFTER (c70e3ed)