Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: readyrocky on January 20, 2017, 12:42:23 PM



Title: Bitcoinbook P2SH(P2WPKH/P2WSH) example??
Post by: readyrocky on January 20, 2017, 12:42:23 PM
I'm trying to replicate the example on Andreas bitcoinbook dev branch, about upgrading to segwit addresses but without success. Someone can please confirm that the example at least is correct?

https://github.com/bitcoinbook/bitcoinbook/blob/develop/segwit.asciidoc#pay-to-witness-public-key-hash-inside-pay-to-script-hash

For example, in the P2WPKH case, the final P2SH(P2WPKH) the book says the resulting address is 3AzZFY4WJJZbVr2A6qBTbdkYRpMLbdg6gD but I'm getting 37Lx99uaGn5avKBxiW26HjedQE3LrDCZru . I checked that address  and the hash coincides with the base58 encoding, so can someone make a full example confirmation? I think I'm getting the p2wpkh program hash wrong. you can watch my code on the issue i linked below.

I opened an issue but the last commit is from 3 months ago: https://github.com/bitcoinbook/bitcoinbook/issues/228




Title: Re: Bitcoinbook P2SH(P2WPKH/P2WSH) example??
Post by: achow101 on January 20, 2017, 04:13:46 PM
Double check that you are hashing everything correctly and that all of the hashes match up to what they say they should be.

You should also take a look in the actual BIP where this is specified: https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#P2WPKH_nested_in_BIP16_P2SH


Title: Re: Bitcoinbook P2SH(P2WPKH/P2WSH) example??
Post by: readyrocky on January 20, 2017, 04:25:40 PM
Double check that you are hashing everything correctly and that all of the hashes match up to what they say they should be.

You should also take a look in the actual BIP where this is specified: https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#P2WPKH_nested_in_BIP16_P2SH

Yes, I'm not even getting the right hash160 of the segwit program (according to the book example) but it seems that I'm following the right process (the lib author hadn't seen anything wrong with my code).

The process I'm following:

1) Create segwit program with the pubkeyhash and the version number provided in the book:
Code:
OP_0 0x14 0xab68025513c3dbd2f7b92a94e0581f5d50f654e7

2) Getting the hash160 of 1) (not matching from here below):
Code:
3e0547268b3b19288b3adef9719ec8659f4b2b0b 

3) Embedding 2) in a p2sh script:
Code:
OP_HASH160 0x14 0x3e0547268b3b19288b3adef9719ec8659f4b2b0b OP_EQUAL

4) Obtaining the address from 3):
Code:
37Lx99uaGn5avKBxiW26HjedQE3LrDCZru

Using bcoin lib.


Title: Re: Bitcoinbook P2SH(P2WPKH/P2WSH) example??
Post by: achow101 on January 20, 2017, 05:57:53 PM
Double check that you are hashing everything correctly and that all of the hashes match up to what they say they should be.

You should also take a look in the actual BIP where this is specified: https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#P2WPKH_nested_in_BIP16_P2SH

Yes, I'm not even getting the right hash160 of the segwit program (according to the book example) but it seems that I'm following the right process (the lib author hadn't seen anything wrong with my code).

The process I'm following:

1) Create segwit program with the pubkeyhash and the version number provided in the book:
Code:
OP_0 0x14 0xab68025513c3dbd2f7b92a94e0581f5d50f654e7

2) Getting the hash160 of 1) (not matching from here below):
Code:
3e0547268b3b19288b3adef9719ec8659f4b2b0b 

3) Embedding 2) in a p2sh script:
Code:
OP_HASH160 0x14 0x3e0547268b3b19288b3adef9719ec8659f4b2b0b OP_EQUAL

4) Obtaining the address from 3):
Code:
37Lx99uaGn5avKBxiW26HjedQE3LrDCZru

Using bcoin lib.
Yes. This is correct. It looks like there is an error in book.


Title: Re: Bitcoinbook P2SH(P2WPKH/P2WSH) example??
Post by: readyrocky on January 20, 2017, 07:19:45 PM
Double check that you are hashing everything correctly and that all of the hashes match up to what they say they should be.

You should also take a look in the actual BIP where this is specified: https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#P2WPKH_nested_in_BIP16_P2SH

Yes, I'm not even getting the right hash160 of the segwit program (according to the book example) but it seems that I'm following the right process (the lib author hadn't seen anything wrong with my code).

The process I'm following:

1) Create segwit program with the pubkeyhash and the version number provided in the book:
Code:
OP_0 0x14 0xab68025513c3dbd2f7b92a94e0581f5d50f654e7

2) Getting the hash160 of 1) (not matching from here below):
Code:
3e0547268b3b19288b3adef9719ec8659f4b2b0b 

3) Embedding 2) in a p2sh script:
Code:
OP_HASH160 0x14 0x3e0547268b3b19288b3adef9719ec8659f4b2b0b OP_EQUAL

4) Obtaining the address from 3):
Code:
37Lx99uaGn5avKBxiW26HjedQE3LrDCZru

Using bcoin lib.
Yes. This is correct. It looks like there is an error in book.

Ok, issue updated, just in case...


Title: Re: Bitcoinbook P2SH(P2WPKH/P2WSH) example??
Post by: readyrocky on February 18, 2017, 10:24:38 AM
Fixed

https://github.com/bitcoinbook/bitcoinbook/commit/49e8b5653347b21ca9d2bf34384a5e0a21b5fa3e