-
Notifications
You must be signed in to change notification settings - Fork 108
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 bug in sighash for coinbase transactions #2459
Conversation
All the signature hash zips miss specifying this coinbase detail, and all the test vectors in zips and in zcash-hackworks fail to exercise it, and the new ZIP-244 non-malleable tx id mentions coinbase but not relevant to this bug. I'm not sure exactly where this should be clarified but it is underspecified and under-tested to achieve consensus from the specs. |
@conradoplg can you open a ticket in https://github.com/zcash/zips to specify the coinbase output sighash? There's no need to open a PR, just describing the spec gap is enough. Edit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this after we've opened the ZIP bug ticket.
Then we can open another PR to switch to librustzcash
sighash and delete this code.
(Please feel free to dismiss my review once the ticket is open.)
Opened in zcash/zips#535 |
Created the ticket as requested, which was the only thing left to do.
Motivation
The sighash of coinbase transactions was being computed incorrectly because it ignored the "outpoint" of coinbase inputs while they shouldn't be.
Closes #1939.
Specifications
https://zips.z.cash/zip-0143, which does not have any exceptions for the coinbase transaction. (It could be more explicit about it...)
https://developer.bitcoin.org/reference/transactions.html#coinbase-input-the-input-of-the-first-transaction-in-a-block describes the "outpoint" of a coinbase transaction (a null hash, and a 0xFFFFFFFF index).
Designs
N/A
Solution
Recreate the "fake" outpoint of coinbase inputs in order to hash it.
I added two tests:
Note: our intention, as discussed in Discord, was to replace the entire sighash with librustzcash implementation. However I ended up identifying the bug while preparing the tests the replacement. We'll probably end up going forward with this strategy (#2183), but I wanted to fix the bug before doing that (and deleting the zebra sighash code) so that if for whatever reason we decide one day to go back to our own implementation, it won't have this bug.
Review
See #1939 for what this is blocking.
I think anyone can review this.
Reviewer Checklist
Follow Up Work
We'll probably follow this up with #2183