Bitcoin
$18,411.71 4.45%
BTC · 3w

A breakdown of Bitcoin "standard" script types (crazy long)

When challenged recently to provide an little known bitcoin fact, I presented that "Addresses are not stored anywhere in the blockchain". This got me thinking a bit more about the bitcoin op-codes and the scripting language they describe. There is a good [wiki article](https://en.bitcoin.it/wiki/Script) on it all as a refresher. It's basically a stack based language similar to Forth or [RPL](https://en.wikipedia.org/wiki/RPL_%28programming_language%29) language. Here's an example of a [Mancala game](https://brianddk.github.io/2016/05/hp-42s-mancala/) I wrote in RPL to show more complex code. So below I will set out to try to explain the seven most easily identifiable bitcoin transaction types and how the script assembly for them works. Originally the script assembly was basically just ` `, but with BIP16 and BIP141 the concept of deserializing either the `redeemScript` or the `witnessScript` were introduced. Most of this is done outside the scripting engine by the bitcoin client, but here I image a new op-code called `OP_DESERIALIZE` for the task. I realize it's fictional, but felt it was easier to present the material with this small imaginary op-code. This makes our complete script assemble a bit more than just ` ` in most cases. I'll go through what that assembly looks like as well as how block explorers or client software identify the seven major transaction types, and how the address is parsed and assembled. I've also written a [sample script](https://github.com/brianddk/reddit/blob/master/python/transaction_types.py) that will decode these by walking through testnet blocks. *** ### [Pay to Pubkey](https://en.bitcoin.it/wiki/Script#Obsolete_pay-to-pubkey_transaction) The original bitcoin client defined two fields `scriptSig` and `scriptPubKey` which each contained half of the script needed to validate a transaction. The two scripts were concatenated together to create a complete script. Here's an ...
Continue on self.Bitcoin
Recent news