Bitcoin Forum
January 26, 2020, 08:46:29 PM *
News: Latest Bitcoin Core release: 0.19.0.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoinbook P2SH(P2WPKH/P2WSH) example??  (Read 1077 times)
readyrocky
Newbie
*
Offline Offline

Activity: 15
Merit: 0


View Profile
January 20, 2017, 12:42:23 PM
 #1

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


1580071589
Hero Member
*
Offline Offline

Posts: 1580071589

View Profile Personal Message (Offline)

Ignore
1580071589
Reply with quote  #2

1580071589
Report to moderator
1580071589
Hero Member
*
Offline Offline

Posts: 1580071589

View Profile Personal Message (Offline)

Ignore
1580071589
Reply with quote  #2

1580071589
Report to moderator
1580071589
Hero Member
*
Offline Offline

Posts: 1580071589

View Profile Personal Message (Offline)

Ignore
1580071589
Reply with quote  #2

1580071589
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 2016
Merit: 3011


bc1qshxkrpe4arppq89fpzm6c0tpdvx5cfkve2c8kl


View Profile WWW
January 20, 2017, 04:13:46 PM
 #2

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

readyrocky
Newbie
*
Offline Offline

Activity: 15
Merit: 0


View Profile
January 20, 2017, 04:25:40 PM
 #3

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.
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 2016
Merit: 3011


bc1qshxkrpe4arppq89fpzm6c0tpdvx5cfkve2c8kl


View Profile WWW
January 20, 2017, 05:57:53 PM
 #4

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.

readyrocky
Newbie
*
Offline Offline

Activity: 15
Merit: 0


View Profile
January 20, 2017, 07:19:45 PM
 #5

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...
readyrocky
Newbie
*
Offline Offline

Activity: 15
Merit: 0


View Profile
February 18, 2017, 10:24:38 AM
 #6

Fixed

https://github.com/bitcoinbook/bitcoinbook/commit/49e8b5653347b21ca9d2bf34384a5e0a21b5fa3e
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!