Skip to content

Fix Uint256::increment panics#612

Merged
apoelstra merged 4 commits intorust-bitcoin:masterfrom
TheBlueMatt:2021-06-fix-increment
Sep 27, 2021
Merged

Fix Uint256::increment panics#612
apoelstra merged 4 commits intorust-bitcoin:masterfrom
TheBlueMatt:2021-06-fix-increment

Conversation

@TheBlueMatt
Copy link
Copy Markdown
Member

This is #578 with review feedback addressed.

@TheBlueMatt TheBlueMatt force-pushed the 2021-06-fix-increment branch from dc08760 to 9c256cc Compare June 10, 2021 16:03
sgeisler
sgeisler previously approved these changes Jun 11, 2021
Copy link
Copy Markdown
Contributor

@sgeisler sgeisler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 9c256cc

EDIT: Why did we choose little-endian btw? Was hard to wrap my mind around the resulting mixed-endianess.

Copy link
Copy Markdown
Collaborator

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly speaking, to be rust ideomatic, we should have inc function panic on overflows, and special wrapping_inc, checked_inc and overflowing_inc and saturating_inc functions... But we are not numeric crate, so the question is why we need this increment function at all? Shouldn't we implement those methods on UInt* types and just use appropriate *_add(1) for do the incrementing?

($name(ret), sub_copy)
}

/// Increment by 1
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to explain in the doc that the function does wrapping increment

@dr-orlovsky
Copy link
Copy Markdown
Collaborator

Personally I had to update/extend current UInt* implementations in https://docs.rs/amplify_num/0.1.1/amplify_num/ crate, and did all those arithmetic methods there, so they can be taken from it if needed here (or just use it since it is MSRV compatible)

sanket1729
sanket1729 previously approved these changes Jun 15, 2021
Copy link
Copy Markdown
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack 9c256cc
Unrelated to this PR and also does not affect the correctness of the fuzzer, but while reviewing I found this line to be slightly confusing. I think it should be

if data.len() != 16*2 { return; }

But since the +1 is explicitly added, I maybe also be misunderstanding the code.

I think it should
https://github.com/TheBlueMatt/rust-bitcoin/blob/9c256cc88e4b71f7ee4e486a10b0be26c31a5f66/fuzz/fuzz_targets/uint128_fuzz.rs#L30

In an earlier version of the uint128 fuzz target, there was a byte
which incidated the specific operation to test. However, that was
dropped for the much-more-effective approach of simply testing all
operations in each fuzz iteration.
@TheBlueMatt TheBlueMatt dismissed stale reviews from sanket1729 and sgeisler via 5d71a9d June 15, 2021 23:11
@TheBlueMatt
Copy link
Copy Markdown
Member Author

Unrelated to this PR and also does not affect the correctness of the fuzzer, but while reviewing I found this line to be slightly confusing. I think it should be

Yep! Totally right. That's just stale against a (probably never upstreamed) version of that fuzz target.

Copy link
Copy Markdown
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 5d71a9d

Copy link
Copy Markdown
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 5d71a9d

@apoelstra apoelstra merged commit 454379c into rust-bitcoin:master Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants