Example for P2WSH wrong?
weskerfoot opened this issue · 4 comments
Forgive me if I am missing something, but should this line not include the size of the hash?
I.e.
txin_redeemScript = CScript([OP_0, 0x20, txin_scriptHash])
BIP141 says
The '0' in scriptPubKey indicates the following push is a version 0 witness program. The length of the witness program indicates that it is a P2WSH type. The last item in the witness (the "witnessScript") is popped off, hashed with SHA256, compared against the 32-byte-hash in scriptPubKey, and deserialized:
See here
When I had tested the library, it did not add this length byte automatically.
>>> from bitcoin.core.script import CScript
>>> CScript([b'X'*20])[0]
20
relevant line:
python-bitcoinlib/bitcoin/core/script.py
Line 536 in 78aaaf6
Thank you, I see what's going on there now! I didn't realize it was using isinstance
to behave differently.
python-bitcoinlib is forked from bitcoin core's test harness, and as such its semantics and syntax are designed to precisely match the semantics and syntax of classes with the same name in the C++ codebase. Over there, the second argument is a variable width byte array, with the length encoded when you do a pushdata.
You can see some examples in its test harness here:
So as the example matches the C++ codebase, I'd say it's correct. ;-)