8000 BIP 34: Check last minimal encoding accoriding of heights by sanket1729 · Pull Request #1244 · rust-bitcoin/rust-bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

BIP 34: Check last minimal encoding accoriding of heights #1244

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 2 commits into from
Sep 8, 2022

Conversation

sanket1729
Copy link
Member
@sanket1729 sanket1729 commented Sep 6, 2022

See: https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki

The BIP was updated with commit: bitcoin/bips@08844fd

Found while reviewing #1240

Also cleanly deals with negative heights as errors.

// byte is the most significant one.
if b.last() == Some(&0x00) {
return Err(Bip34Error::NonMinimalPush(b.to_vec()));
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this correct? Can't a number start with 0080 to force it to be positive if it'd otherwise be negative?

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 catch! This is incorrect.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed this in a much cleaner way

@dpc
Copy link
Contributor
dpc commented Sep 6, 2022

I'm confused if "accoriding of heights" is just a mistake, or there's some meaning there that I'm missing.

@sanket1729 sanket1729 force-pushed the bip34_height branch 2 times, most recently from 3b7b1f7 to 8bf53e4 Compare September 6, 2022 20:55
@sanket1729 sanket1729 force-pushed the bip34_height branch 4 times, most recently from 790ffc8 to be7985c Compare September 6, 2022 21:12
@sanket1729
Copy link
Member Author

Sorry about the poor description. Fixed this in two steps:

  1. Make sure that decoding CScriptNums is always done in a minimal way.
  2. BIP34 logic to use the CScriptNum decoding to read it.

Err(Bip34Error::UnexpectedPush(b.to_vec()))
script::Instruction::PushBytes(b) => {
// Check that the number is encoded in the minimal way.
let h = script::read_scriptint(b).map_err(|_e| Bip34Error::UnexpectedPush(b.to_vec()))?;
Copy link
Member Author

Choose a reason for hiding this comment

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

I am unsure if I want to propagate the script error here. It has many other invariants that are unreadable from this particular function.

Copy link
Member

Choose a reason for hiding this comment

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

I think what you've done is probably the right thing.

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 8405200

Copy link
Member
@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 8405200

@@ -225,9 +225,9 @@ impl From<bitcoinconsensus::Error> for Error {
}
}

/// Helper to encode an integer in script format.
/// Helper to encode an integer in script(minimal CScriptNum) format.
Copy link
Member

Choose a reason for hiding this comment

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

Can I ask a question, why is the open parenthesis used with no space before it in docs? I've seen this elsewhere and wondered why its done like that, this is the first PR I've seen add one - hence my question. Cheers

Copy link
Member Author

Choose a reason for hiding this comment

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

I had no idea that we are supposed to put spaces there. Won't be dismissing the two ACKs for this nit

Copy link
Member

Choose a reason for hiding this comment

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

There should be a space there -- but agreed, we can fix this in a later doc-fixup PR.

Copy link
Member

Choose a reason for hiding this comment

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

No need to fix it, I can do them when I'm cleaning up docs. I just wanted to make sure it wasn't for a reason I did not know about. Cheers

@apoelstra apoelstra merged commit 94a4c51 into rust-bitcoin:master Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0