1

I have script to create a P2WPKH to P2WPKH transaction (1 input, 1 output) and sign it with the sighash type 0x01 SIGHASH_ALL.

Which fields would I need to change in the tx digest preimage to turn the signature into one with a sighash type of 0x83 (SINGLE|ANYONECANPAY)? I'm having trouble understanding the documentation in bip_143.

For reference, the tx digest preimage:

Double SHA256 of the serialization of:
1. nVersion of the transaction (4-byte little endian)
2. hashPrevouts (32-byte hash)
3. hashSequence (32-byte hash)
4. outpoint (32-byte hash + 4-byte little endian)
5. scriptCode of the input (serialized as scripts inside CTxOuts)
6. value of the output spent by this input (8-byte little endian)
7. nSequence of the input (4-byte little endian)
8. hashOutputs (32-byte hash)
9. nLocktime of the transaction (4-byte little endian)
10. sighash type of the signature (4-byte little endian)

1 Answer 1

2

From BIP143:

If the ANYONECANPAY flag is not set, hashPrevouts is the double SHA256 of the serialization of all input outpoints;

Otherwise, hashPrevouts is a uint256 of 0x0000......0000.

All the details you need are in the BIP

8
  • Thanks. It feels like I've tried every combination of setting hashPrevouts, hashSequence, hashOutputs to 0x0000......0000, as well as the sighash type itself, but I keep getting the error message: error message: non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation) (code 64)
    – Darius
    Jan 8, 2020 at 10:06
  • Have you looked at the code? You might find it more helpful: github.com/bitcoin/bitcoin/blob/master/src/script/… or in bcoin: github.com/bcoin-org/bcoin/blob/master/lib/primitives/…
    – pinhead
    Jan 8, 2020 at 19:53
  • Unfortunately I don't know cpp so it's a bit hard to follow
    – Darius
    Jan 10, 2020 at 18:23
  • @Darius bcoin is JavaScript, if that helps. What language are you using to compute this sighash?
    – pinhead
    Jan 10, 2020 at 18:26
  • 1
    Just took a quick look - you may need check that your txid is little-endian...
    – pinhead
    Jan 10, 2020 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.