I've read over the bip173, bip141, and bip143 specifications and they're a bit too technical to get at the simple answers I'm looking for.

  • Are you asking about the differences between P2WPKH/P2WSH in general, or about the differences between their corresponding address formats? Dec 13, 2018 at 23:21
  • In short, both. As you can see, I've added some of the research I've done over the past month or so. I'm programming a bech32 encoder/decoder in perl, but also trying to understand bech32, segwit, P2WPKH, and P2WSH beyond simply porting the code from the node/c++ code in bip173. Dec 13, 2018 at 23:34
  • Also, there were few simple and concise answers that I could find with a google search that correspond to bech32 validation and how bech32 relates to SegWit, so I wanted to share the conclusions I came to. Dec 13, 2018 at 23:38

1 Answer 1

  • P2WPKH - This stands for "Pay To Witness Public Key Hash" and the scriptPubkey is OP_0 0x14 {20-byte-hash}, where OP_0 is the version, byte 0x14 is the size of the data, and the {20-byte-hash} is a HASH160(PubKey).
  • P2WSH - This stands for "Pay To Witness Script Hash" and the scriptPubkey is OP_0 0x20 {32-byte-hash}, where OP_0 is the version, byte 0x20 is the size of the data, and the {32-byte-hash} is a SHA256(script).

This data is taken from: http://bcoin.io/guides/segwit.html


For the P2WPKH address: "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4"

OP_0 , 0x14 , HASH160(PubKey) -- looks like (in hex):

00 14 751e76e8199196d454941c45d1b3a323f1433bd6

For the P2WSH address: "bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3"

OP_0 , 0x20 , SHA256(script) -- looks like (in hex):

00 20 1863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262

Examples taken from http://bitcoin.sipa.be/bech32/demo/demo.html and https://github.com/sipa/bech32/blob/master/ref/c%2B%2B/tests.cpp

  • 1
    Not MD5 (lol), it's SHA256. Dec 13, 2018 at 23:38
  • Ah, thanks! I thought md5 sounded wrong myself! Dec 13, 2018 at 23:39

Your Answer

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

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