Slide 1

Slide 1 text

Alberto Gómez Toribio ( @gotoalberto ) Bitcoin protocol for developers Except where otherwise noted, this work is licensed under: http://creativecommons.org/licenses/by-nc-sa/3.0/ c_b_n_a Leganés 6 Febrero 2013

Slide 2

Slide 2 text

Except where otherwise noted, this work is licensed under: http://creativecommons.org/licenses/by-nc-sa/3.0/ c_b_n_a Leganés 6 Febrero 2013 Alberto Gómez @gotoalberto Alvaro Polo @apolovald “Software development enthusiast and aviation geek. Give me a higher-order function and I shall move the world.” “Vocational coder since childhood, he will annoy you with concepts like "monad" and "actor model" but gets the work done.” “Theoretical computer science believer by night, pragmatic ship-it developer by day. My brain runs on glucose, caffeine, general abstract nonsense and type theory.” “OpenData and Bitcoin Developer on fire. Great coders are today’s rock stars. That’s it!” Coinffeine.com Sebastián Ortega @_sortega Ximo Guanter A P2P Bitcoin exchange

Slide 3

Slide 3 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 What is the Bitcoin Protocol? ● Network protocol ● Transactions Mechanics ○ Blockchain mining ○ Fees and commitment rules ○ Sharing protocol: Gossip, Bittorrent, Gnutella... ○ Validations of the money source ○ Protocol to spend the money ○ Bitcoin Scripting

Slide 4

Slide 4 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Network protocol ● Blockchain ○ The Blockchain is a distributed ledger book ○ Create a Block in chain require a proof of work dc7047be… = SHA256(new_block_hash) ○ Forks are discarded, the most complex chain wins.

Slide 5

Slide 5 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Network protocol ● Other services: ○ The Blockchain is used to storage usernames. ○ Tweets are shared between users using a DHT protocol. ○ The older messages are discarded. ○ Incentive to generate blocks on Blockchain: Sponsored messages.

Slide 6

Slide 6 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Network protocol ● Colored Coins: ○ The Blockchain is used to storage key-value strings, as internet web domains / IP. ○ You can register a domain spending Namecoins. ○ The fee by register a name is decreased in time.

Slide 7

Slide 7 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Transactions Mechanic ● Transaction anatomy { txid : 5c084b… , locktime : 0, vin : [ { txid : feff4b… vout : 0 scriptSig { asm : d8f67a… …} …} …] vout : [ { value : 2.52 reqsigs : 1 scriptPubKey { asm : OP_DUP OP_HASH160 cb1f48… OP_EQUALSVERIFY OP_CHECKSIG …} addresses : [ 172D5w7C… ] …} …] …}

Slide 8

Slide 8 text

{ txid : 5c084b… , locktime : 0, vin : [ { txid : feff4b… vout : 0 scriptSig { asm : d8f67a… …} …} …] vout : [ { value : 2.52 reqsigs : 1 scriptPubKey { asm : OP_DUP OP_HASH160 cb1f48… OP_EQUALSVERIFY OP_CHECKSIG …} addresses : [ 172D5w7C… ] …} …] …} Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Transactions Mechanic ● Transaction anatomy Transaction Id, changes when a field is changed or tx is signed.

Slide 9

Slide 9 text

{ txid : 5c084b… , locktime : 0, vin : [ { txid : feff4b… vout : 0 scriptSig { asm : d8f67a… …} …} …] vout : [ { value : 2.52 reqsigs : 1 scriptPubKey { asm : OP_DUP OP_HASH160 cb1f48… OP_EQUALSVERIFY OP_CHECKSIG …} addresses : [ 172D5w7C… ] …} …] …} Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Transactions Mechanic ● Transaction anatomy Locktime, Block or Time up to which this tx cannot be broadcasted.

Slide 10

Slide 10 text

{ txid : 5c084b… , locktime : 0, vin : [ { txid : feff4b… vout : 0 scriptSig { asm : d8f67a… …} …} …] vout : [ { value : 2.52 reqsigs : 1 scriptPubKey { asm : OP_DUP OP_HASH160 cb1f48… OP_EQUALSVERIFY OP_CHECKSIG …} addresses : [ 172D5w7C… ] …} …] …} Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Transactions Mechanic ● Transaction anatomy TXid reference output for this input.

Slide 11

Slide 11 text

{ txid : 5c084b… , locktime : 0, vin : [ { txid : feff4b… vout : 0 scriptSig { asm : d8f67a… …} …} …] vout : [ { value : 2.52 reqsigs : 1 scriptPubKey { asm : OP_DUP OP_HASH160 cb1f48… OP_EQUALSVERIFY OP_CHECKSIG …} addresses : [ 172D5w7C… ] …} …] …} Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Transactions Mechanic ● Transaction anatomy Output number reference in previous tx

Slide 12

Slide 12 text

{ txid : 5c084b… , locktime : 0, vin : [ { txid : feff4b… vout : 0 scriptSig { asm : d8f67a… …} …} …] vout : [ { value : 2.52 reqsigs : 1 scriptPubKey { asm : OP_DUP OP_HASH160 cb1f48… OP_EQUALSVERIFY OP_CHECKSIG …} addresses : [ 172D5w7C… ] …} …] …} Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Transactions Mechanic ● Transaction anatomy ScriptSig which unlock the connected OutputScript

Slide 13

Slide 13 text

{ txid : 5c084b… , locktime : 0, vin : [ { txid : feff4b… vout : 0 scriptSig { asm : d8f67a… …} …} …] vout : [ { value : 2.52 reqsigs : 1 scriptPubKey { asm : OP_DUP OP_HASH160 cb1f48… OP_EQUALSVERIFY OP_CHECKSIG …} addresses : [ 172D5w7C… ] …} …] …} Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Transactions Mechanic ● Transaction anatomy Value to transfer. The difference with the summatory of inputs values is the fee.

Slide 14

Slide 14 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Transactions Mechanic ● Transaction anatomy { txid : 5c084b… , locktime : 0, vin : [ { txid : feff4b… vout : 0 scriptSig { asm : d8f67a… …} …} …] vout : [ { value : 2.52 reqsigs : 1 scriptPubKey { asm : OP_DUP OP_HASH160 cb1f48… OP_EQUALSVERIFY OP_CHECKSIG …} addresses : [ 172D5w7C… ] …} …] …} Number of sigs required to broadcast this transaction. The signers are included in the “addresses” array.

Slide 15

Slide 15 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Transactions Mechanic ● Transaction anatomy { txid : 5c084b… , locktime : 0, vin : [ { txid : feff4b… vout : 0 scriptSig { asm : d8f67a… …} …} …] vout : [ { value : 2.52 reqsigs : 1 scriptPubKey { asm : OP_DUP OP_HASH160 cb1f48… OP_EQUALSVERIFY OP_CHECKSIG …} addresses : [ 172D5w7C… ] …} …] …} Script. It defines how the money can be spent and by whom.

Slide 16

Slide 16 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Transactions Mechanic ● Transaction anatomy { txid : 5c084b… , locktime : 0, vin : [ { txid : feff4b… vout : 0 scriptSig { asm : d8f67a… …} …} …] vout : [ { value : 2.52 reqsigs : 1 scriptPubKey { asm : OP_DUP OP_HASH160 cb1f48… OP_EQUALSVERIFY OP_CHECKSIG …} addresses : [ 172D5w7C… ] …} …] …}

Slide 17

Slide 17 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Bitcoin Script ● It Allows to define how an output will be spent and by whom. ● Is a non Turing-Complete language which is evaluated as a Stack, from left to right. ● It just allows to write pure functions (without context) ● Is a non Turing-Complete language which is evaluated with a stack machine.

Slide 18

Slide 18 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG (Public Key Hash)

Slide 19

Slide 19 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG bbba3f5… 172D5w7C… (Public Key) (Signature) (Public Key Hash)

Slide 20

Slide 20 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG bbba3f5… 172D5w7C… (Public Key) (Signature) (Public Key Hash)

Slide 21

Slide 21 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG bbba3f5… 172D5w7C… (Public Key) (Signature) (Public Key Hash)

Slide 22

Slide 22 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack bbba3f5… (Signature) OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG 172D5w7C… (Public Key) (Public Key Hash)

Slide 23

Slide 23 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack (Signature) bbba3f5… OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG 172D5w7C… (Public Key) (Public Key Hash)

Slide 24

Slide 24 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack bbba3f5… 172D5w7C… (Signature) (Public Key) OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG (Public Key Hash)

Slide 25

Slide 25 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack bbba3f5… 172D5w7C… (Signature) (Public Key) OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG (Public Key Hash)

Slide 26

Slide 26 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack bbba3f5… 172D5w7C… (Public Key) (Signature) 172D5w7C… (Public Key) OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG (Public Key Hash)

Slide 27

Slide 27 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack bbba3f5… 172D5w7C… (Public Key) (Signature) 172D5w7C… (Public Key) OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG (Public Key Hash)

Slide 28

Slide 28 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack bbba3f5… 172D5w7C… (Public Key) (Signature) cb1f48… (Public Key Hash) cb1f48… OP_EQUALVERIFY OP_CHECKSIG (Public Key Hash)

Slide 29

Slide 29 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack bbba3f5… 172D5w7C… (Public Key) (Signature) cb1f48… (Public Key Hash) cb1f48… OP_EQUALVERIFY OP_CHECKSIG (Public Key Hash)

Slide 30

Slide 30 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack bbba3f5… 172D5w7C… (Public Key) (Signature) cb1f48… (Public Key Hash) cb1f48… (Public Key Hash) OP_EQUALVERIFY OP_CHECKSIG

Slide 31

Slide 31 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack bbba3f5… 172D5w7C… (Public Key) (Signature) cb1f48… (Public Key Hash) cb1f48… (Public Key Hash) OP_EQUALVERIFY OP_CHECKSIG

Slide 32

Slide 32 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack bbba3f5… 172D5w7C… (Public Key) (Signature) OP_CHECKSIG

Slide 33

Slide 33 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack bbba3f5… 172D5w7C… (Public Key) (Signature) OP_CHECKSIG

Slide 34

Slide 34 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 How Bitcoin Script works? Stack (EMPTY) (EMPTY) SUCCESS!

Slide 35

Slide 35 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) <7bb> <5aa> OP_2DUP OP_HASH160 OP_EQUALVERIFY OP_SWAP OP_HASH160 OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 36

Slide 36 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) @_sortega Random diversion! <7bb> <5aa> OP_2DUP OP_HASH160 OP_EQUALVERIFY OP_SWAP OP_HASH160 OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 37

Slide 37 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <7bb> <5aa> OP_2DUP OP_HASH160 OP_EQUALVERIFY OP_SWAP OP_HASH160 OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 38

Slide 38 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <7bb> <5aa> OP_2DUP OP_HASH160 OP_EQUALVERIFY OP_SWAP OP_HASH160 OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 39

Slide 39 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <7bb> <5aa> OP_2DUP OP_HASH160 OP_EQUALVERIFY OP_SWAP OP_HASH160 OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 40

Slide 40 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <7bb> <5aa> OP_2DUP OP_HASH160 OP_EQUALVERIFY OP_SWAP OP_HASH160 OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 41

Slide 41 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <5aa> <7bb> OP_2DUP OP_HASH160 OP_EQUALVERIFY OP_SWAP OP_HASH160 OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 42

Slide 42 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <7bb> <5aa> <5aa> <7bb> OP_HASH160 OP_EQUALVERIFY OP_SWAP OP_HASH160 OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 43

Slide 43 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <7bb> <5aa> <7bb> OP_EQUALVERIFY OP_SWAP OP_HASH160 OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 44

Slide 44 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <5aa> <7bb> <7bb> OP_EQUALVERIFY OP_SWAP OP_HASH160 OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 45

Slide 45 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <5aa> <7bb> <7bb> OP_SWAP OP_HASH160 OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 46

Slide 46 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack OP_HASH160 OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF <7bb> <5aa> <7bb>

Slide 47

Slide 47 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF <5aa> <7bb>

Slide 48

Slide 48 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF <5aa> <7bb>

Slide 49

Slide 49 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF <5aa> <7bb>

Slide 50

Slide 50 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF <5aa> <7bb> <1>

Slide 51

Slide 51 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF <5> <7bb>

Slide 52

Slide 52 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF <7bb> <5>

Slide 53

Slide 53 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack OP_LEFT OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF <7bb> <5> <1>

Slide 54

Slide 54 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack OP_ADD <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF <7> <5>

Slide 55

Slide 55 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <12> <2> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 56

Slide 56 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <2> <12> OP_SWAP OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 57

Slide 57 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <12> <2> OP_MOD OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 58

Slide 58 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack <0> OP_IF OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ELSE OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG OP_ENDIF

Slide 59

Slide 59 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) Stack (Standard Script) OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG

Slide 60

Slide 60 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 The sky is the limit! (Odd/Even Bet) ● Possible real use: ○ Random user to pay the transaction fees. ○ Help to define asymmetric scenario (secrets)

Slide 61

Slide 61 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Context: Oracles ● The oracle contract allow define how the money is spent including external state. ○ Allow to pay, only if an external condition is true, for example the result of a search in google, or the API SEUR response. ○ Allows to make reversible transactions.

Slide 62

Slide 62 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Context: Oracles ● Example of a reversible payment using a Oracle ○ First you generate (in private) a multisig transaction as this: TX1 in { 1 BTC BOB } out { 1 BTC MULTISIGVERIFY BOB SAM } ○ Then you must obtain signed from counterpart: OP_HASH160 OP_EQUALSVERIFY 2 OP_CHECKMULTISIGVERIFY } TX3 in { TX1[0] } out { 1 BTC OP_HASH160 OP_EQUALSVERIFY 2 OP_CHECKMULTISIGVERIFY } TX2 in { TX1[0] } out { 1 BTC

Slide 63

Slide 63 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Context: Oracles ● Execution OP_HASH160 OP_EQUALSVERIFY 2 OP_CHECKMULTISIGVERIFY } TX2 in { TX1[0] } out { 1 BTC

Slide 64

Slide 64 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Context: Oracles ● Execution OP_HASH160 OP_EQUALSVERIFY 2 OP_CHECKMULTISIGVERIFY Stack

Slide 65

Slide 65 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Context: Oracles ● Execution OP_HASH160 OP_EQUALSVERIFY 2 OP_CHECKMULTISIGVERIFY Stack

Slide 66

Slide 66 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Context: Oracles ● Execution OP_HASH160 OP_EQUALSVERIFY 2 OP_CHECKMULTISIGVERIFY Stack

Slide 67

Slide 67 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Context: Oracles ● Execution OP_HASH160 OP_EQUALSVERIFY 2 OP_CHECKMULTISIGVERIFY Stack

Slide 68

Slide 68 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Context: Oracles ● Execution OP_EQUALSVERIFY 2 OP_CHECKMULTISIGVERIFY Stack

Slide 69

Slide 69 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Context: Oracles ● Execution OP_EQUALSVERIFY 2 OP_CHECKMULTISIGVERIFY Stack

Slide 70

Slide 70 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Context: Oracles ● Execution 2 OP_CHECKMULTISIGVERIFY Stack

Slide 71

Slide 71 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Context: Oracles ● Execution Stack SUCCESS!

Slide 72

Slide 72 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Fees? Micro Payment Channels! ● Transactions from a checkpoint without broadcast ● Allows commit money safely ● Allows to pay on demand by the second ● For example: decentralized WiFi Hotspots or subcontracting services in third world countries.

Slide 73

Slide 73 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Micro Payment Channels Mechanic TX1 IN {0: 1 BTC } OUT {0: 1 BTC MULTISIG BOB SAM }

Slide 74

Slide 74 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Micro Payment Channels Mechanic TX1 IN {0: 1 BTC } OUT {0: 1 BTC MULTISIG BOB SAM } IN {TX1[0]: 1 BTC } OUT { 0 : 1 BTC BOB } LOCKTIME : 18 TX2

Slide 75

Slide 75 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Micro Payment Channels Mechanic TX1 IN {0: 1 BTC } OUT {0: 1 BTC MULTISIG BOB SAM } IN {TX1[0]: 1 BTC } OUT { 0 : 1 BTC BOB } LOCKTIME : 18 TX2

Slide 76

Slide 76 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Micro Payment Channels Mechanic TX1 IN {0: 1 BTC } OUT {0: 1 BTC MULTISIG BOB SAM } IN {TX1[0]: 1 BTC } OUT { 0 : 1 BTC BOB } LOCKTIME : 18 TX2

Slide 77

Slide 77 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Micro Payment Channels Mechanic TX1 IN {0: 1 BTC } OUT {0: 1 BTC MULTISIG BOB SAM } IN {TX1[0]: 1 BTC } OUT { 0 : 1 BTC BOB } LOCKTIME : 18 TX2 IN {TX1[0] 1 BTC } OUT {0: 0,9 BTC BOB 0,1 BTC SAM }

Slide 78

Slide 78 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Micro Payment Channels Mechanic TX1 IN {0: 1 BTC } OUT {0: 1 BTC MULTISIG BOB SAM } IN {TX1[0]: 1 BTC } OUT { 0 : 1 BTC BOB } LOCKTIME : 18 TX2 IN {TX1[0] 1 BTC } OUT {0: 0,8 BTC BOB 0,2 BTC SAM }

Slide 79

Slide 79 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Micro Payment Channels Mechanic TX1 IN {0: 1 BTC } OUT {0: 1 BTC MULTISIG BOB SAM } IN {TX1[0]: 1 BTC } OUT { 0 : 1 BTC BOB } LOCKTIME : 18 TX2 IN {TX1[0] 1 BTC } OUT {0: 0,7 BTC BOB 0,3 BTC SAM }

Slide 80

Slide 80 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Micro Payment Channels Mechanic TX1 IN {0: 1 BTC } OUT {0: 1 BTC MULTISIG BOB SAM } IN {TX1[0]: 1 BTC } OUT { 0 : 1 BTC BOB } LOCKTIME : 18 TX2 IN {TX1[0] 1 BTC } OUT {0: 0,6 BTC BOB 0,4 BTC SAM } BREAK!

Slide 81

Slide 81 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 Micro Payment Channels Mechanic TX1 IN {0: 1 BTC } OUT {0: 1 BTC MULTISIG BOB SAM } IN {TX1[0]: 1 BTC } OUT { 0 : 1 BTC BOB } LOCKTIME : 18 TX2 IN {TX1[0] 1 BTC } OUT {0: 0,6 BTC BOB 0,4 BTC SAM }

Slide 82

Slide 82 text

Bitcoin Protocol for Developers #BitcoinT3F Leganés 6 Febrero 2013 THANKS! ● BigData is the current wave, P2P is the next. ● APIs and P2P are the next challenge on finantial world. ● Bitcoin technology and protocol is here to stay.