Top Banner
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
82

Bitcoin protocol for developers at techfest

Jan 29, 2015

Download

Technology

Bitcoin Scripting explained on T3chFest Confference by Alberto Gomez Toribio
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Bitcoin protocol for developers at techfest

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és6 Febrero 2013

Page 2: Bitcoin protocol for developers at techfest

Except where otherwise noted, this work is licensed under: http://creativecommons.org/licenses/by-nc-sa/3.0/ c_b_n_a

Leganés6 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

Page 3: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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

Page 4: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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.

Page 5: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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.

Page 6: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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.

Page 7: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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… ] …} …] …}

Page 8: Bitcoin protocol for developers at techfest

{ 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 #BitcoinT3FLeganés6 Febrero 2013

Transactions Mechanic● Transaction anatomy

Transaction Id, changes when a field is changed or tx is signed.

Page 9: Bitcoin protocol for developers at techfest

{ 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 #BitcoinT3FLeganés6 Febrero 2013

Transactions Mechanic● Transaction anatomy

Locktime, Block or Time up to which this tx cannot be broadcasted.

Page 10: Bitcoin protocol for developers at techfest

{ 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 #BitcoinT3FLeganés6 Febrero 2013

Transactions Mechanic● Transaction anatomy

TXid reference output for this input.

Page 11: Bitcoin protocol for developers at techfest

{ 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 #BitcoinT3FLeganés6 Febrero 2013

Transactions Mechanic● Transaction anatomy

Output number reference in previous tx

Page 12: Bitcoin protocol for developers at techfest

{ 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 #BitcoinT3FLeganés6 Febrero 2013

Transactions Mechanic● Transaction anatomy

ScriptSig which unlock the connected OutputScript

Page 13: Bitcoin protocol for developers at techfest

{ 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 #BitcoinT3FLeganés6 Febrero 2013

Transactions Mechanic● Transaction anatomy

Value to transfer. The difference with thesummatory of inputs values is the fee.

Page 14: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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 thistransaction. The signers are included in the“addresses” array.

Page 15: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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.

Page 16: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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… ] …} …] …}

Page 17: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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.

Page 18: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG

(Public Key Hash)

Page 19: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG bbba3f5… 172D5w7C…

(Public Key)(Signature) (Public Key Hash)

Page 20: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

Stack

OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG bbba3f5… 172D5w7C…

(Public Key)(Signature) (Public Key Hash)

Page 21: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

Stack

OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG bbba3f5… 172D5w7C…

(Public Key)(Signature) (Public Key Hash)

Page 22: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

Stack

bbba3f5…(Signature)

OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG 172D5w7C…

(Public Key) (Public Key Hash)

Page 23: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

Stack

(Signature) bbba3f5…

OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG 172D5w7C…

(Public Key) (Public Key Hash)

Page 24: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

Stack

bbba3f5…

172D5w7C…

(Signature)

(Public Key)

OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG

(Public Key Hash)

Page 25: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

Stack

bbba3f5…

172D5w7C…

(Signature)

(Public Key)

OP_DUP OP_HASH160 cb1f48… OP_EQUALVERIFY OP_CHECKSIG

(Public Key Hash)

Page 26: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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)

Page 27: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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)

Page 28: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

Stack

bbba3f5…

172D5w7C…(Public Key)

(Signature)

cb1f48…(Public Key Hash)

cb1f48… OP_EQUALVERIFY OP_CHECKSIG

(Public Key Hash)

Page 29: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

Stack

bbba3f5…

172D5w7C…(Public Key)

(Signature)

cb1f48…(Public Key Hash)

cb1f48… OP_EQUALVERIFY OP_CHECKSIG

(Public Key Hash)

Page 30: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

Stack

bbba3f5…

172D5w7C…(Public Key)

(Signature)

cb1f48…(Public Key Hash)

cb1f48…(Public Key Hash)

OP_EQUALVERIFY OP_CHECKSIG

Page 31: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

Stack

bbba3f5…

172D5w7C…(Public Key)

(Signature)

cb1f48…(Public Key Hash)

cb1f48…(Public Key Hash)

OP_EQUALVERIFY OP_CHECKSIG

Page 32: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

Stack

bbba3f5…

172D5w7C…(Public Key)

(Signature)

OP_CHECKSIG

Page 33: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

Stack

bbba3f5…

172D5w7C…(Public Key)

(Signature)

OP_CHECKSIG

Page 34: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

How Bitcoin Script works?

Stack

(EMPTY)

(EMPTY)

SUCCESS!

Page 35: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet) <Sig> <PubKeyB> <7bb> <5aa> OP_2DUP OP_HASH160 <aHash> OP_EQUALVERIFY OP_SWAP OP_HASH160 <bHash> OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

Page 36: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

@_sortega

Random diversion!

<Sig> <PubKeyB> <7bb> <5aa> OP_2DUP OP_HASH160 <aHash> OP_EQUALVERIFY OP_SWAP OP_HASH160 <bHash> OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

Page 37: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

<Sig> <PubKeyB> <7bb> <5aa> OP_2DUP OP_HASH160 <aHash> OP_EQUALVERIFY OP_SWAP OP_HASH160 <bHash> OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

Page 38: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack<Sig>

<PubKeyB> <7bb> <5aa> OP_2DUP OP_HASH160 <aHash> OP_EQUALVERIFY OP_SWAP OP_HASH160 <bHash> OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

Page 39: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack<PubKey>

<Sig>

<7bb> <5aa> OP_2DUP OP_HASH160 <aHash> OP_EQUALVERIFY OP_SWAP OP_HASH160 <bHash> OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

Page 40: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack<7bb>

<PubKey>

<Sig>

<5aa> OP_2DUP OP_HASH160 <aHash> OP_EQUALVERIFY OP_SWAP OP_HASH160 <bHash> OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

Page 41: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack<5aa>

<7bb>

<PubKeyB>

OP_2DUP OP_HASH160 <aHash> OP_EQUALVERIFY OP_SWAP OP_HASH160 <bHash> OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

<Sig>

Page 42: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

<7bb>

<5aa>

<PubKeyB>

<5aa>

<7bb>

OP_HASH160 <aHash> OP_EQUALVERIFY OP_SWAP OP_HASH160 <bHash> OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

<Sig>

Page 43: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

<7bb>

<5aa>

<PubKeyB>

<aHash>

<7bb>

<aHash> OP_EQUALVERIFY OP_SWAP OP_HASH160 <bHash> OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

<Sig>

Page 44: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

<5aa>

<7bb>

<PubKeyB>

<aHash>

<7bb>

<aHash>

OP_EQUALVERIFY OP_SWAP OP_HASH160 <bHash> OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

<Sig>

Page 45: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack<5aa>

<7bb>

<PubKeyB>

<7bb>

OP_SWAP OP_HASH160 <bHash> OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

<Sig>

Page 46: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

OP_HASH160 <bHash> OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

<7bb>

<5aa>

<PubKeyB>

<7bb>

<Sig>

Page 47: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

<bHash> OP_EQUALVERIFY <1> OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

<bHash>

<5aa>

<PubKeyB>

<7bb>

<Sig>

Page 48: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

<bHash>

<5aa>

<PubKeyB>

<7bb>

<bHash>

<Sig>

Page 49: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

<5aa>

<PubKeyB>

<7bb>

<Sig>

Page 50: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

OP_LEFT OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

<5aa>

<PubKeyB>

<7bb>

<Sig>

<1>

Page 51: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

OP_SWAP <1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

<5>

<PubKeyB>

<7bb>

<Sig>

Page 52: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

<1> OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

<7bb>

<PubKeyB>

<5>

<Sig>

Page 53: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

OP_LEFT OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

<7bb>

<PubKeyB>

<5>

<Sig>

<1>

Page 54: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

OP_ADD <2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

<7>

<PubKeyB>

<5>

<Sig>

Page 55: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

<PubKeyB>

<12>

<Sig>

<2> OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

Page 56: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

<PubKeyB>

<2>

<12>

<Sig>

OP_SWAP OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

Page 57: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

<PubKeyB>

<12>

<2>

<Sig>

OP_MODOP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

Page 58: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack

<PubKeyB>

<0>

<Sig>

OP_IF OP_DUP OP_HASH160 <pubKeyAHash> OP_EQUALVERIFY OP_CHECKSIGOP_ELSE OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIGOP_ENDIF

Page 59: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

The sky is the limit! (Odd/Even Bet)

Stack<PubKeyB>

<Sig>

(Standard Script)

OP_DUP OP_HASH160 <pubKeyBHash> OP_EQUALVERIFY OP_CHECKSIG

Page 60: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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)

Page 61: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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.

Page 62: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Context: Oracles● Example of a reversible payment using a Oracle ○ First you generate (in private) a multisig transaction as

this:TX1in { 1 BTC BOB }out { 1 BTC MULTISIGVERIFY BOB SAM }

○ Then you must obtain signed from counterpart:

<SeurAPI(trackID) == ‘DELIVERED’> OP_HASH160 <ExternalScriptHash> OP_EQUALSVERIFY <OraclePubKey> <BobPubKey> 2 OP_CHECKMULTISIGVERIFY }

TX3in { TX1[0] }out { 1 BTC

<SeurAPI(trackID) == ‘RETURNED’> OP_HASH160 <ExternalScriptHash> OP_EQUALSVERIFY <OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY }

TX2in { TX1[0] }out { 1 BTC

Page 63: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Context: Oracles● Execution

<SeurAPI(trackID) == ‘RETURNED’> OP_HASH160 <ExternalScriptHash> OP_EQUALSVERIFY <OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY }

TX2in { TX1[0] }out { 1 BTC

Page 64: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Context: Oracles● Execution

<OracleSig> <SamSig> <SeurAPI(trackID) == ‘RETURNED’>OP_HASH160 <ExternalScriptHash> OP_EQUALSVERIFY <OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY

Stack

Page 65: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Context: Oracles● Execution

<SamSig> <SeurAPI(trackID) == ‘RETURNED’>OP_HASH160 <ExternalScriptHash> OP_EQUALSVERIFY <OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY

Stack<OracleSig>

Page 66: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Context: Oracles● Execution

<SeurAPI(trackID) == ‘RETURNED’>OP_HASH160 <ExternalScriptHash> OP_EQUALSVERIFY <OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY

Stack<SamSig><OracleSig>

Page 67: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Context: Oracles● Execution

OP_HASH160 <ExternalScriptHash> OP_EQUALSVERIFY <OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY

Stack<SeurAPI(trackID) == ‘RETURNED’>

<SamSig><OracleSig>

Page 68: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Context: Oracles● Execution

<ExternalScriptHash> OP_EQUALSVERIFY <OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY

Stack<ScriptHash><SamSig><OacleSig>

Page 69: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Context: Oracles● Execution

OP_EQUALSVERIFY <OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY

Stack

<ScriptHash><ExternalScriptHash>

<SamSig><OracleSig>

Page 70: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Context: Oracles● Execution

<OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY

Stack<SamSig><OracleSig>

Page 71: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Context: Oracles● Execution

Stack

SUCCESS!

Page 72: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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.

Page 73: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Micro Payment Channels MechanicTX1

IN {0: 1 BTC }OUT {0: 1 BTC MULTISIG BOB SAM }

Page 74: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Micro Payment Channels MechanicTX1

IN {0: 1 BTC }OUT {0: 1 BTC MULTISIG BOB SAM }

IN {TX1[0]: 1 BTC }OUT { 0 : 1 BTC BOB }

LOCKTIME : 18

TX2

Page 75: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Micro Payment Channels MechanicTX1

IN {0: 1 BTC }OUT {0: 1 BTC MULTISIG BOB SAM }

IN {TX1[0]: 1 BTC }OUT { 0 : 1 BTC BOB }

LOCKTIME : 18

TX2

Page 76: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Micro Payment Channels MechanicTX1

IN {0: 1 BTC }OUT {0: 1 BTC MULTISIG BOB SAM }

IN {TX1[0]: 1 BTC }OUT { 0 : 1 BTC BOB }

LOCKTIME : 18

TX2

Page 77: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Micro Payment Channels MechanicTX1

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 }

Page 78: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Micro Payment Channels MechanicTX1

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 }

Page 79: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Micro Payment Channels MechanicTX1

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 }

Page 80: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Micro Payment Channels MechanicTX1

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!

Page 81: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 Febrero 2013

Micro Payment Channels MechanicTX1

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 }

Page 82: Bitcoin protocol for developers at techfest

Bitcoin Protocol for Developers #BitcoinT3FLeganés6 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.