Skip to content
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

Fix witness display bug #1999

Merged
merged 2 commits into from Aug 30, 2023

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented Aug 16, 2023

When we introduce a custom Debug implementation for the Witness we introduced a bug that causes code to panic if the witness contains an empty instruction.

The bug can be verified by putting patch 2 first or by running cargo run --example sighash on master.

@tcharding tcharding marked this pull request as draft August 16, 2023 06:37
Currently if the witness has zero elements or any of the individual
witnesses is empty we panic. Panic is caused by subtracting 1 from a
zero length.

Check the length is non-zero before subtracting 1, print `[]` if empty.
We recently fixed a bug that causes a panic if a `Witness` contains an
empty instruction. Add a unit test to verify it.
@tcharding tcharding marked this pull request as ready for review August 16, 2023 23:36
@tcharding tcharding added the bug label Aug 17, 2023
@apoelstra
Copy link
Member

Looks good! I guess there are technically two bugs, since there are two - 1s that could overflow. But I'm okay with only having a unit test for one.

Copy link
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 84614d9

@tcharding
Copy link
Member Author

The sighash example tests the other one, that is how I found this. Its not in any way obvious though. The code is so simple I rekon one test is ok.

@tcharding tcharding added the one ack PRs that have one ACK, so one more can progress them label Aug 21, 2023
@tcharding tcharding added the P-high High priority label Aug 28, 2023
Copy link
Collaborator

@RCasatta RCasatta left a comment

Choose a reason for hiding this comment

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

ACK 84614d9

Since this is a bug fix better to merge and in case the comment is found appropriate do another MR

Comment on lines +71 to +72
if instructions.len() > 0 {
let last_instruction = instructions.len() - 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think

match instructions.len().checked_sub(1) {
  Some(last_instruction) => ...
  None => ..
}

would be more refactor-solid and better convey the underflow risk

Copy link
Member Author

Choose a reason for hiding this comment

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

Good suggestion, I'll do up another PR and let this one merge. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in #2035

@RCasatta RCasatta merged commit feafac3 into rust-bitcoin:master Aug 30, 2023
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug one ack PRs that have one ACK, so one more can progress them P-high High priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants