Bitcoin full node and query server

Oct 16, 2018

View in context in the libbitcoin Slack #general mirror.

M
Mlmikael13:23
The P2WSH pubkey script, the hash it contains, is it a single- or dual-iteration SHA256 of the witness program (which is stored in the spending input's witness data)? Could you give me some reference to where LibBitcoin validates or generates such a hash in the pubkey script?
7 replies · James C., Mlmikael, evoskuil · last Oct 17, 2018
James C.16:45
Hi Mikael! I think witness script validation is here: https://github.com/libbitcoin/libbitcoin/blob/master/src/chain/witness.cpp#L454 The witness verify method is here: https://github.com/libbitcoin/libbitcoin/blob/master/src/chain/witness.cpp#L478 And the overall script evaluate method is here: https://github.com/libbitcoin/libbitcoin/blob/master/src/chain/script.cpp#L1381 Is that what you are looking for?
(edited)
M
Mlmikael01:26
James, excellent thanks. Right the P2WSH pubkey hash is based on single-iteration SHA256. This was not so easy to read out of Bitcoin Core - there apparently this https://github.com/bitcoin/bitcoin/tree/master/src/script/standard.cpp#L24 is the main location, and there's some very secondary location such as this https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L1433 . Actually now when talking about it, where does LibBitcoin do the HASH160 for the P2WPKH pubkey hash validation?
(edited)
James C.07:56
Hi Mikael, glad that was what you were looking for. There is a P2PKH script “extraction” step from the witness object here: https://github.com/libbitcoin/libbitcoin/blob/master/src/chain/witness.cpp#L436 A couple lines above, you’ll find how the PKH from the witness is moved into a standard P2PKH script template for evaluation. https://github.com/libbitcoin/libbitcoin/blob/master/src/chain/witness.cpp#L363
(edited)
James C.07:58
I wrote up a script machine documentation article for the wiki a while back, perhaps helpful? https://github.com/libbitcoin/libbitcoin/wiki/Script-Machine
(edited)
James C.08:03
The actual script run of the witness-extracted P2PKH script happens here: https://github.com/libbitcoin/libbitcoin/blob/master/src/machine/interpreter.cpp#L29
(edited)
James C.08:10
(the interpreter evaluates all script runs, not not P2W specific, and is called by program.evaluate() )
evoskuil18:31
(edited)