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 bug in sighash for coinbase transactions #2459

Merged
merged 1 commit into from
Jul 8, 2021

Conversation

conradoplg
Copy link
Collaborator

@conradoplg conradoplg commented Jul 7, 2021

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

  • Code implements Specs and Designs
  • Tests for Expected Behaviour
  • Tests for Errors

Follow Up Work

We'll probably follow this up with #2183

@dconnolly
Copy link
Contributor

https://zips.z.cash/zip-0143, which does not have any exceptions for the coinbase transaction. (It could be more explicit about it...)

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.

@teor2345
Copy link
Contributor

teor2345 commented Jul 8, 2021

@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:
Let's also list ZIP-244 in the bug, because it also doesn't specify what happens to coinbase inputs:
https://zips.z.cash/zip-0244#t-2a-prevouts-digest

Copy link
Contributor

@teor2345 teor2345 left a 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.)

@conradoplg
Copy link
Collaborator Author

@conradoplg can you open a ticket in https://github.com/zcash/zips to specify the coinbase output sighash?

Opened in zcash/zips#535

@conradoplg conradoplg dismissed teor2345’s stale review July 8, 2021 15:33

Created the ticket as requested, which was the only thing left to do.

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.

Fix sapling binding signature errors
4 participants