Bitcoin Script for Beginners


Jason Dreyzehner

@bitjson


bitauth.com

Poll

Heard about Bitcoin Script before this talk?

Tried to learn Bitcoin Script?

Written a locking/unlocking script?

I'm going to say “Bitcoin”


But this talk applies to BTC, BCH, and BSV.


Part 1

Storing Bitcoin

Common Security Options


  • Single device (“P2PKH”)

  • Multi-device (“P2SH Multisig”)

Something else?

Example – High-Security Business Wallet


  • 2-of-2 – normally each co-owner must approve transactions.

  • Recovery – if either loses their wallet, a trusted lawyer can approve transactions.

  • *Lawyer can't approve transactions until 30 days later.

Bitcoin Script


A programming language for authentication.

Part 2

Bitcoin Transactions

Transactions


some addresses → other addresses


inputs → outputs

Transactions: Deconstructed

0100000001bdd84c0a10482ee004977ae99cdf7109b9b640f21d54cccafef1315c9d346a81010000006b483045022100c1f209db2e8efb2e90ef054bd100f4c2badba4ce5f0710141cf19969bc63065c02203f34b4c6dd8f19355dc457dbd01273f006faab8abf29b670debcdc1e3f551d0a412103adf90e9560aa579e128a64f7c4f024fe32031a9f7550f6f6e511db3f8e062a080000000003c8cf0300000000001976a914deedd3c18efe2b2c6838e8bacca056cd4aacf8d388acc8cf0300000000001976a914bc07ca234f8ff0dbe26513ee093312aa4f21be0a88ac00000000000000000e6a0401010101076269746175746800000000

01000000 ← version 01 ← number of inputs bdd84c0a10482ee004977ae99cdf7109b9b640f21d54cccafef1315c9d346a81 ← txid 1 01000000 ← outpoint index 1 6b483045022100c1f209db2e8efb2e90ef054bd100f4c2badba4ce5f0710141cf19969bc63065c02203f34b4c6dd8f19355dc457dbd01273f006faab8abf29b670debcdc1e3f551d0a412103adf90e9560aa579e128a64f7c4f024fe32031a9f7550f6f6e511db3f8e062a08 ← unlocking script 1 00000000 ← sequence number 1 03 ← number of outputs c8cf030000000000 ← value 1 (249,800 satoshis) 1976a914deedd3c18efe2b2c6838e8bacca056cd4aacf8d388ac ← locking script 1 c8cf030000000000 ← value 2 1976a914bc07ca234f8ff0dbe26513ee093312aa4f21be0a88ac ← locking script 2 0000000000000000 ← value 3 0e6a04010101010762697461757468 ← locking script 3 00000000 ← locktime

Decoding Locking Script 1

76a914deedd3c18efe2b2c6838e8bacca056cd4aacf8d388ac

76 a9 14 deedd3c18efe2b2c6838e8bacca056cd4aacf8d3 88 ac

OP_DUP OP_HASH160 OP_PUSHBYTES_20 (20 bytes) OP_EQUALVERIFY OP_CHECKSIG

Visualizing a Stack





Demo Time

BitAuth IDE


  • low-level language for bitcoin script

  • compiler with support variables and signing

  • an IDE and line-by-line interactive debugger

Questions?


to be released at:

bitauth.com