Transcript for #bitcoin-dev 2017/04/24

03:55 suryab what's the difference between a scriptPubKey/scriptSig and scriptCode?
03:56 suryab the segwit dev guide says: "Please note that for a P2SH-P2WPKH, the scriptCode is always 26 bytes including the leading size byte, as 0x1976a914{20-byte keyhash}88ac, NOT the redeemScript nor scriptPubKey"
04:35 arubi suryab, scriptcode is kinda like a redeemscript for witness v0 (p2wpkh,p2wsh) scriptpubkeys. when redeeming from a p2wpkh (or p2sh(p2wpkh)), the script you're actually signing will be a p2pkh script like the one in the example. when redeeming a p2wsh (or p2sh(p2wsh)), the scripcode is the redeemscript for the p2wsh. what the guide says not to do is to use the segwit scriptpubkeys themselves for the signing
09:35 rugu Anyone know how Insight API are able to index UTXO by address?
09:50 rugu I am trying to use the RPC commands to a full node as well as the bitcoin-lib repo from github, so far I can get the transactions per block as per the hash or block height, but not sure wht to do next, in order to get a UTXO mapping that can be queried by public address
10:00 arubi rugu, did you see ?
13:24 suryab arubi when you said that the guide is saying not to use the segwit scriptPubKey itself, you mean the don't use the p2sh(p2spkh) scriptPubKey as it's defined here: correct? But instead use the byte that they say
13:55 arubi suryab, p2spkh? do you mean p2wpkh or p2wsh?
13:56 arubi what the guide means is that for redeeming p2wpkh, either nested in p2sh or not, the scriptcode is the same as a p2pkh script with the hash160 taken from the p2wpkh script
13:57 arubi a p2wpkh looks like '0 <hash160 pubkey>', so your scriptcode will be '0x19 DUP HASH160 <hash160 pubkey> EQUALVERIFY CHECKSIG' serialized
13:57 suryab that was a typo, i mean p2wpkh not p2spkh
13:58 arubi a p2wsh looks like '0 <sha256 hash>' , and the scriptcode will be the redeemscript that when serialized and sha256'ed, will have give that same <sha256 hash> value from the scriptpbukey
13:59 arubi ( plus a first byte for its size )
14:01 suryab okay, so my scriptPubKey looks like: HASH_160 <hash-160(pubkey)> EQUAL. the scriptSig looks like: 0 <hash160(pubkey)> and the script that I use when I compute te sig hash I use the script you specified above
14:02 suryab sorry scriptPubKey hash160 is of the redeem script: hash160( 0 hash160(pubkey) )
14:02 suryab sorry scriptPubKey hash160 is of the redeem script: hash160( 0 <hash160(pubkey)> )
14:03 arubi right, in scriptsig there should only be the segwit scriptpubkey as a single push
14:03 arubi just like redeeming any other p2sh. it doesn't come into contact with the signing itself
14:05 suryab yeah i've been trying variations of this but it looks like i can never produce valid transactions... strange
14:05 arubi can you show what it is you're trying to sign?
14:05 suryab i'm pretty sure I've made a valid p2sh(p2wpkh) address as the output of a different transaction
14:05 suryab okay, give me a sec
14:06 suryab aside from the script that's being signed in the sighash, does anything else about computing the has change betwee p2wpkh and p2sh(p2wpkh)?
14:06 arubi nothing
14:07 arubi the mid state is completely the same
14:07 arubi er, what do you mean aside from?
14:08 arubi to redeem a p2wpkh, or a p2sh(p2wpkh) you will have the same exact signature
14:08 arubi the only difference is in relay when the preimage to the p2sh hash160 is set in scriptsig as a single push
14:09 suryab okay looks like the output I was making was wrong
14:09 suryab tranasctions are valid now, hallelujah
14:09 arubi \o/
14:09 suryab i've been grinding at this for some time, thanks a ton arubi!
14:09 arubi cheers suryab
17:38 suryab p2sh(p2wpkh) is supposed be relay-able by all nodes, even nodes that aren't NODE_WITNESS
17:38 suryab right?
17:41 arubi not the spend
17:42 arubi the backward compatibility is in the ability for old software to send to p2sh addresses, relay and mining of transactions with a witness is only possible with a segwit aware node