Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appendix D (SegWit) confusion around SegWit P2SH address generation. #440

Closed
grisha opened this issue Dec 27, 2017 · 2 comments
Closed

Appendix D (SegWit) confusion around SegWit P2SH address generation. #440

grisha opened this issue Dec 27, 2017 · 2 comments

Comments

@grisha
Copy link

grisha commented Dec 27, 2017

Right above 3deadbeef (fixed in issue #331) there is also a confusing (if not erroneous) part:

The hash of the witness program is then embedded in a P2SH script:
HASH160 3e0547268b3b19288b3adef9719ec8659f4b2b0b EQUAL

Finally, the P2SH script is converted to a P2SH bitcoin address:

37Lx99uaGn5avKBxiW26HjedQE3LrDCZru

This reads to me like HASH160 3e0547268b3b19288b3adef9719ec8659f4b2b0b EQUAL somehow becomes 37Lx99uaGn5avKBxiW26HjedQE3LrDCZru, but actually, the address is derived from the witness program mentioned three paragraphs earlier (0 ab68025513c3dbd2f7b92a94e0581f5d50f654e7):

echo '0 [ab68025513c3dbd2f7b92a94e0581f5d50f654e7]' | bx script-to-address 
37Lx99uaGn5avKBxiW26HjedQE3LrDCZru

A similar problem down below (bottom of page 339 in print):

Mohammed’s wallet creates a P2WSH witness program

0 9592d601848d04b172905e0ddb0adde59f1590f1e553ffc81ddc4b0ed927dd73

Then, the witness program itself is hashed with SHA256 and RIPEMD160, producing a new 20-byte hash, as used in traditional P2SH:

  86762607e8fe87c0c37740cddee880988b9455b2

Next, Mohammed’s wallet puts the hash into a P2SH script:

  HASH160 86762607e8fe87c0c37740cddee880988b9455b2 EQUAL

Finally, the wallet constructs a bitcoin address from this script:

3Dwz1MXhM6EfFoJChHCxh1jWHb8GQqRenG

The wallet constructs the address not from "this script", but rather from the witness program:

echo '0 [9592d601848d04b172905e0ddb0adde59f1590f1e553ffc81ddc4b0ed927dd73]' | bx script-to-address 
3Dwz1MXhM6EfFoJChHCxh1jWHb8GQqRenG

P.S. Fantastic book, BTW, thank you!

@aantonop
Copy link
Collaborator

aantonop commented Feb 3, 2018

Confirming...

@aantonop aantonop added this to the Second Edition - Third Print milestone Feb 3, 2018
aantonop added a commit that referenced this issue Feb 3, 2018
There were several errors in the address and hash calculations. Fixed errors and added command line examples to clarify the process
@aantonop
Copy link
Collaborator

aantonop commented Feb 3, 2018

Thank you for this. You found several errors. I had mixed up the steps.

Now fixed, with bx examples throughout and correct addresses 1ddd89b

Please review and confirm, if you can!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants