Transactions 102
@blockstrap
#StartingBlock2015
Introduction & Primer
First, some context
These slides are from the #StartingBlock2015 tour by @blockstrap.
6 European countries in 8 days – (Istanbul, Amsterdam, Barcelona, Prague, Berlin
& London). We met lots of great people, answered lots of great questions and had
a great time. We look forward to meeting many of them again in the near future.
These slides might only make perfect sense if you were at the talks and can
remember all the additional points we made whilst discussing the tech.
This deck is 6th
of 6.
Questions? Comments? @MrAdamGiles adam@neuroware.io
Transactions 102
Refresher
➔ Transactions transfer control of coins from inputs to outputs
➔ Control is enforced by cryptography
➔ Refresh on public/private keys
• Two keys, one private one public
• Encryption by one, decryption by the other and vice versa
• If you can encrypt a known value, which is then decrypted by the
public key, you must have the private key
Transactions 102
To Construct A Transaction
➔ You need the address of the person you’re going to pay
➔ Find UTXO’s Unspent Transaction Outputs that exceed the amount you
wish to pay (that you control)
➔ Calculate the transaction fee (optional but recommended)
➔ Create the outputs with the correct scriptPubKey
➔ Sign the transaction details
➔ Broadcast the transaction, see if it works
Transactions 102
ScriptPubKey Is A Mini-Program
➔ scriptPubKey defines who can spend the coin by specifying a small
verification program that is run in order to perform that verification
➔ 40 bytes of instructions
➔ Forth like scripting language, deliberately not turing complete
➔ Elements are pushed onto a stack, if the end of the stack is true then the
Transaction is valid and works
Transactions 102
ScriptPubKey Is A Mini-Program
You can get quite clever with it
• Multi-signatures required where m of n are required
• Verifications that don’t need private keys
• Time bound, escrow services
• The beginnings of smart contracts
• Deliberately make coins unspendable
Transactions 102
Signature Scripts
➔ In order for the network to validate and relay your transaction you have to
prove you have that private key
➔ You do this through the SignatureScript
◆ Full unhashed public key
◆ A secp256k1 signature of most of the transaction data
● The Txn ID & output index of the input
● Previous Txn’s scriptPubKey
● The output’s scriptPubKey
● The value of the transaction
➔ The signed transaction is then sent to the network for relaying
Transactions 102
P2PKH
➔ When decoded the scriptPubKey says this:
OP_DUP OP_HASH160 <PubkeyHash> OP_EQUALVERIFY OP_CHECKSIG
➔ You append the SignatureScript to the front, then evaluate LtoR
<Sig> <PubKey> OP_DUP OP_HASH160 <PubkeyHash> OP_EQUALVERIFY OP_CHECKSIG
Transactions 102
This Is Complicated
➔ Use a library or toolset to do this encryption - if it’s wrong you don’t get
error messages, it just doesn’t work
➔ … and you could lose your coins!
➔ Start on the testnets
• work just like the real networks
• coins are free
• playground for experimentation
Transactions 102
Store Data In The Blockchain
➔ Space is limited - 79 bytes in the testnet
➔ If your data is larger than that, use an external reference
• URL to object
• Magnet link for torrentable files
➔ People store things on the blockchain
• Messages
• Prayers
• Proof of existence
• URLs/email addresses/auth codes
• Marketing
➔ FlorinCoin blockchain provides more storage space
Transactions 102
Store Data In The Blockchain
➔ Burn 0 satoshi as one output as part of a bigger transaction, and pay the
mining fee
➔ First command says ‘these coins can’t be spent’ - takes 1 byte
➔ Known as OP_RETURN, always evaluates to false
➔ What you do with the rest of the data is up to you
➔ You’ll need a special script that looks for this data and processes it
independently
➔ Obviously, read only once the Transaction is sent
Programmable Money
Transactions 102
Multi-Signaure Addresses
➔ An Address that requires multiple people to sign Transactions from it
➔ Known as m of n where n<16
➔ The public keys of all the signers are combined to create a special multi-sig
Address. Anyone can send coins to this Address
➔ To spend these coins you have to create a Transaction without
broadcasting it, then pass it round the signers until you have the required
number of signatures
OP_2 [A's pubkey] [B's pubkey] [C's pubkey] OP_3 OP_CHECKMULTISIG
Transactions 102
Micropayment Channel
➔ A way to allow many mini-transactions to be rolled up into two Transactions
➔ Buyer places a bond Transaction and a time-bound refund Transaction
(which isn't broadcast yet)
➔ As the buyer consumes the service, new refund Transactions are created
but not broadcast, changing the amount of the refund
➔ When the service is complete, the most recent refund Transaction is
broadcast
Transactions 101
Addresses Private key
Public key
Hash
Encode
Address
Transactions 101
HD f(n) = Private key
Public key
Hash
Encode
Address
Any Questions?

CBGTBT - Part 6 - Transactions 102

  • 1.
  • 2.
    Introduction & Primer First,some context These slides are from the #StartingBlock2015 tour by @blockstrap. 6 European countries in 8 days – (Istanbul, Amsterdam, Barcelona, Prague, Berlin & London). We met lots of great people, answered lots of great questions and had a great time. We look forward to meeting many of them again in the near future. These slides might only make perfect sense if you were at the talks and can remember all the additional points we made whilst discussing the tech. This deck is 6th of 6. Questions? Comments? @MrAdamGiles adam@neuroware.io
  • 3.
    Transactions 102 Refresher ➔ Transactionstransfer control of coins from inputs to outputs ➔ Control is enforced by cryptography ➔ Refresh on public/private keys • Two keys, one private one public • Encryption by one, decryption by the other and vice versa • If you can encrypt a known value, which is then decrypted by the public key, you must have the private key
  • 4.
    Transactions 102 To ConstructA Transaction ➔ You need the address of the person you’re going to pay ➔ Find UTXO’s Unspent Transaction Outputs that exceed the amount you wish to pay (that you control) ➔ Calculate the transaction fee (optional but recommended) ➔ Create the outputs with the correct scriptPubKey ➔ Sign the transaction details ➔ Broadcast the transaction, see if it works
  • 5.
    Transactions 102 ScriptPubKey IsA Mini-Program ➔ scriptPubKey defines who can spend the coin by specifying a small verification program that is run in order to perform that verification ➔ 40 bytes of instructions ➔ Forth like scripting language, deliberately not turing complete ➔ Elements are pushed onto a stack, if the end of the stack is true then the Transaction is valid and works
  • 6.
    Transactions 102 ScriptPubKey IsA Mini-Program You can get quite clever with it • Multi-signatures required where m of n are required • Verifications that don’t need private keys • Time bound, escrow services • The beginnings of smart contracts • Deliberately make coins unspendable
  • 7.
    Transactions 102 Signature Scripts ➔In order for the network to validate and relay your transaction you have to prove you have that private key ➔ You do this through the SignatureScript ◆ Full unhashed public key ◆ A secp256k1 signature of most of the transaction data ● The Txn ID & output index of the input ● Previous Txn’s scriptPubKey ● The output’s scriptPubKey ● The value of the transaction ➔ The signed transaction is then sent to the network for relaying
  • 8.
    Transactions 102 P2PKH ➔ Whendecoded the scriptPubKey says this: OP_DUP OP_HASH160 <PubkeyHash> OP_EQUALVERIFY OP_CHECKSIG ➔ You append the SignatureScript to the front, then evaluate LtoR <Sig> <PubKey> OP_DUP OP_HASH160 <PubkeyHash> OP_EQUALVERIFY OP_CHECKSIG
  • 10.
    Transactions 102 This IsComplicated ➔ Use a library or toolset to do this encryption - if it’s wrong you don’t get error messages, it just doesn’t work ➔ … and you could lose your coins! ➔ Start on the testnets • work just like the real networks • coins are free • playground for experimentation
  • 11.
    Transactions 102 Store DataIn The Blockchain ➔ Space is limited - 79 bytes in the testnet ➔ If your data is larger than that, use an external reference • URL to object • Magnet link for torrentable files ➔ People store things on the blockchain • Messages • Prayers • Proof of existence • URLs/email addresses/auth codes • Marketing ➔ FlorinCoin blockchain provides more storage space
  • 12.
    Transactions 102 Store DataIn The Blockchain ➔ Burn 0 satoshi as one output as part of a bigger transaction, and pay the mining fee ➔ First command says ‘these coins can’t be spent’ - takes 1 byte ➔ Known as OP_RETURN, always evaluates to false ➔ What you do with the rest of the data is up to you ➔ You’ll need a special script that looks for this data and processes it independently ➔ Obviously, read only once the Transaction is sent
  • 13.
  • 14.
    Transactions 102 Multi-Signaure Addresses ➔An Address that requires multiple people to sign Transactions from it ➔ Known as m of n where n<16 ➔ The public keys of all the signers are combined to create a special multi-sig Address. Anyone can send coins to this Address ➔ To spend these coins you have to create a Transaction without broadcasting it, then pass it round the signers until you have the required number of signatures OP_2 [A's pubkey] [B's pubkey] [C's pubkey] OP_3 OP_CHECKMULTISIG
  • 15.
    Transactions 102 Micropayment Channel ➔A way to allow many mini-transactions to be rolled up into two Transactions ➔ Buyer places a bond Transaction and a time-bound refund Transaction (which isn't broadcast yet) ➔ As the buyer consumes the service, new refund Transactions are created but not broadcast, changing the amount of the refund ➔ When the service is complete, the most recent refund Transaction is broadcast
  • 17.
    Transactions 101 Addresses Privatekey Public key Hash Encode Address
  • 18.
    Transactions 101 HD f(n)= Private key Public key Hash Encode Address
  • 19.

Editor's Notes

  • #3 Assume familiar with software, just not blockchains Bitcoin can be polizing, quickly decends into conversations/arguments about politics, But as software is eating the workd, that&amp;apos;s what we&amp;apos;ll be focusing on Simplified first , then circle back round and dive deeper Simplifications can be missleading Tell meif too fast/slow