8000 Use `sha256d::Hash` type for sighash encoding by tcharding · Pull Request #1567 · rust-bitcoin/rust-bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use sha256d::Hash type for sighash encoding #1567

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 1 commit into from
Jan 24, 2023

Conversation

tcharding
Copy link
Member

From BIP143:

If sighash type is SINGLE and the input index is smaller than the number of outputs, hashOutputs is the double SHA256 of the output amount with scriptPubKey of the same index as the input;

Currently we are using a Sighash which wraps double sha256 so while technically correct this means we are relying on Sighash to implement Encodable. We can remove this requirement by directly using the sha256d::Hash type to hash the outputs data.

Fix: #1549

Kixunil
Kixunil previously approved these changes Jan 20, 2023
Copy link
Collaborator
@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 895fb6ef2219eca0f64cb900a0f084c8d5ab9cd7

@tcharding
Copy link
Member Author

Oh I just saw your comment @apoelstra, I'll revisit this. #1549 (comment)

`Sighash` does not need to implement `Encodable` because it is
claimed (I don't know exactly myself) that `Sighash` is never consensus
encode in Bitcoin.

We are currently relying on `Sighash` to implement `Encodable` when
encoding creating the segwit v0 sighash for a single input.

For reference, from BIP143:

 If sighash type is SINGLE and the input index is smaller than the
 number of outputs, hashOutputs is the double SHA256 of the output
 amount with scriptPubKey of the same index as the input;

We can use `write_all` directly to write the hashed bytes and remove the
implementation of `Encodable` from the `Sighash` type.

While we are at it, use `write_all` to write the zero hash also to make
the code more uniform and understandable.

Fix: rust-bitcoin#1549
@tcharding
Copy link
Member Author

Re-wrote to use suggestions from the issue. Note I use the phrase "it is claimed" in the git log because I am following the issue with no real knowledge of the topic myself.

Copy link
Collaborator
@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 49e8b8d

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 49e8b8d

@apoelstra apoelstra merged commit 1b8f52a into rust-bitcoin:master Jan 24, 2023
@tcharding tcharding deleted the 01-20-sighash-encodable branch January 24, 2023 21:11
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.

Remove consensus encoding from Sighash?
3 participants
0