3

How do I compute the double sha256 shown in example of bip 143?

The example in Native P2WPKH

  hashPrevouts:
     dSHA256(fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f00000000ef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a01000000)
     = 96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37

I tried

  export PREV_OUT=fff7f7881a8099afa6940d42d1e7f6362bec38171ea3edf433541db4e4ad969f00000000ef51e1b804cc89d182d279655c3aa89e815b1b309fe287d9b2b55d57b90ec68a01000000
  echo -n $PREV_OUT |openssl dgst -sha256 -binary |openssl dgst -sha256

This is what I am getting

  cf4cff3b2196ae87636af6088736f0f9102106375f306c032804845a2d3b92d4
5

Do this:

echo -n $PREV_OUT | xxd -r -p | openssl dgst -sha256 -binary | openssl dgst -sha256

Explanation

You want to do this:

prevout (raw bytes) -> sha256 -> sha256 -> convert to hex

You're doing this:

prevout (raw bytes) -> convert to hex -> sha256 -> sha256 -> convert to hex

xxd -r -p reverses the hex conversion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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