Bitcoin Protocol For Developers
Bitcoin Protocol For Developers
Bitcoin Protocol For Developers
6 Febrero 2013
c_b_n_a
Coinffeine.com
Legans
6 Febrero 2013
Alberto Gmez
@gotoalberto
Alvaro Polo
@apolovald
Ximo Guanter
Theoretical computer science believer by night, pragmatic ship-it developer by day.
My brain runs on glucose, caffeine, general abstract nonsense and type theory.
c_b_n_a
Legans
6 Febrero 2013
#BitcoinT3F
Transactions Mechanics
Validations of the money source
Protocol to spend the money
Bitcoin Scripting
Legans
6 Febrero 2013
#BitcoinT3F
Network protocol
Blockchain
The Blockchain is a distributed ledger book
Legans
6 Febrero 2013
#BitcoinT3F
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.
Legans
6 Febrero 2013
#BitcoinT3F
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.
Legans
6 Febrero 2013
#BitcoinT3F
Transactions Mechanic
Transaction anatomy
{
txid
: 5c084b ,
locktime : 0,
vin
: [
{
txid
vout
scriptSig
:
:
{
feff4b
0
asm : d8f67a
}
}
vout
]
: [
{
value
reqsigs
scriptPubKey
:
:
{
2.52
1
asm : OP_DUP OP_HASH160 cb1f48
OP_EQUALSVERIFY OP_CHECKSIG
addresses
}
]
}
}
:
[ 172D5w7C ]
Legans
6 Febrero 2013
#BitcoinT3F
Transactions Mechanic
Transaction anatomy
{
txid
: 5c084b ,
locktime : 0,
vin
: [
{
txid
vout
scriptSig
:
:
{
feff4b
0
asm : d8f67a
}
}
vout
]
: [
{
value
reqsigs
scriptPubKey
:
:
{
2.52
1
asm : OP_DUP OP_HASH160 cb1f48
OP_EQUALSVERIFY OP_CHECKSIG
addresses
}
]
}
}
:
[ 172D5w7C ]
Legans
6 Febrero 2013
#BitcoinT3F
Transactions Mechanic
Transaction anatomy
{
txid
: 5c084b ,
locktime : 0,
Locktime, Block or Time up to which this tx cannot be broadcasted.
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 ]
}
]
}
Legans
6 Febrero 2013
#BitcoinT3F
Transactions Mechanic
Transaction anatomy
{
txid
: 5c084b ,
locktime : 0,
vin
: [
{
txid
vout
scriptSig
:
:
{
feff4b
0
asm : d8f67a
}
}
vout
]
: [
{
value
reqsigs
scriptPubKey
:
:
{
2.52
1
asm : OP_DUP OP_HASH160 cb1f48
OP_EQUALSVERIFY OP_CHECKSIG
addresses
}
]
}
}
:
[ 172D5w7C ]
Legans
6 Febrero 2013
#BitcoinT3F
Transactions Mechanic
Transaction anatomy
{
txid
: 5c084b ,
locktime : 0,
vin
: [
{
txid
vout
scriptSig
:
:
{
feff4b
0
asm : d8f67a
}
}
vout
]
: [
{
value
reqsigs
scriptPubKey
:
:
{
2.52
1
asm : OP_DUP OP_HASH160 cb1f48
OP_EQUALSVERIFY OP_CHECKSIG
addresses
}
]
}
}
:
[ 172D5w7C ]
Legans
6 Febrero 2013
#BitcoinT3F
Transactions Mechanic
Transaction anatomy
{
txid
: 5c084b ,
locktime : 0,
vin
: [
{
txid
vout
scriptSig
:
:
{
feff4b
0
asm : d8f67a
}
vout
]
: [
{
value
reqsigs
scriptPubKey
:
:
{
2.52
1
asm : OP_DUP OP_HASH160 cb1f48
OP_EQUALSVERIFY OP_CHECKSIG
addresses
}
]
}
}
:
[ 172D5w7C ]
Legans
6 Febrero 2013
#BitcoinT3F
Transactions Mechanic
Transaction anatomy
{
txid
: 5c084b ,
locktime : 0,
vin
: [
{
txid
vout
scriptSig
:
:
{
feff4b
0
asm : d8f67a
}
}
vout
]
: [
{
value
reqsigs
scriptPubKey
:
:
{
2.52
1
}
:
[ 172D5w7C ]
Legans
6 Febrero 2013
#BitcoinT3F
Transactions Mechanic
Transaction anatomy
{
txid
: 5c084b ,
locktime : 0,
vin
: [
{
txid
vout
scriptSig
:
:
{
feff4b
0
asm : d8f67a
}
}
vout
]
: [
{
value
reqsigs
scriptPubKey
addresses
}
]
}
:
:
{
}
:
[ 172D5w7C ]
Legans
6 Febrero 2013
#BitcoinT3F
Transactions Mechanic
Transaction anatomy
{
txid
: 5c084b ,
locktime : 0,
vin
: [
{
txid
vout
scriptSig
:
:
{
feff4b
0
asm : d8f67a
}
}
vout
]
: [
{
}
]
}
Legans
6 Febrero 2013
#BitcoinT3F
Transactions Mechanic
Transaction anatomy
{
txid
: 5c084b ,
locktime : 0,
vin
: [
{
txid
vout
scriptSig
:
:
{
feff4b
0
asm : d8f67a
}
}
vout
]
: [
{
value
reqsigs
scriptPubKey
:
:
{
2.52
1
asm : OP_DUP OP_HASH160 cb1f48
OP_EQUALSVERIFY OP_CHECKSIG
addresses
}
]
}
}
:
[ 172D5w7C ]
Legans
6 Febrero 2013
#BitcoinT3F
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.
Legans
6 Febrero 2013
#BitcoinT3F
OP_EQUALVERIFY OP_CHECKSIG
Legans
6 Febrero 2013
#BitcoinT3F
(Public Key)
bbba3f5 172D5w7C
OP_EQUALVERIFY OP_CHECKSIG
Legans
6 Febrero 2013
#BitcoinT3F
(Public Key)
bbba3f5 172D5w7C
Stack
OP_EQUALVERIFY OP_CHECKSIG
Legans
6 Febrero 2013
#BitcoinT3F
(Public Key)
bbba3f5 172D5w7C
Stack
OP_EQUALVERIFY OP_CHECKSIG
Legans
6 Febrero 2013
#BitcoinT3F
172D5w7C
Stack
(Signature)
bbba3f5
OP_EQUALVERIFY OP_CHECKSIG
Legans
6 Febrero 2013
#BitcoinT3F
172D5w7C
Stack
(Signature)
bbba3f5
OP_EQUALVERIFY OP_CHECKSIG
Legans
6 Febrero 2013
#BitcoinT3F
Stack
(Public Key)
(Signature)
172D5w7C
bbba3f5
OP_EQUALVERIFY OP_CHECKSIG
Legans
6 Febrero 2013
#BitcoinT3F
Stack
(Public Key)
(Signature)
172D5w7C
bbba3f5
OP_EQUALVERIFY OP_CHECKSIG
Legans
6 Febrero 2013
#BitcoinT3F
OP_HASH160 cb1f48
Stack
(Public Key)
(Public Key)
(Signature)
172D5w7C
172D5w7C
bbba3f5
OP_EQUALVERIFY OP_CHECKSIG
Legans
6 Febrero 2013
#BitcoinT3F
OP_HASH160 cb1f48
Stack
(Public Key)
(Public Key)
(Signature)
172D5w7C
172D5w7C
bbba3f5
OP_EQUALVERIFY OP_CHECKSIG
Legans
6 Febrero 2013
#BitcoinT3F
cb1f48
Stack
(Public Key Hash)
(Public Key)
(Signature)
cb1f48
172D5w7C
bbba3f5
OP_EQUALVERIFY OP_CHECKSIG
Legans
6 Febrero 2013
#BitcoinT3F
cb1f48
Stack
(Public Key Hash)
(Public Key)
(Signature)
cb1f48
172D5w7C
bbba3f5
OP_EQUALVERIFY OP_CHECKSIG
Legans
6 Febrero 2013
#BitcoinT3F
Stack
(Public Key Hash)
(Public Key Hash)
(Public Key)
(Signature)
cb1f48
cb1f48
172D5w7C
bbba3f5
Legans
6 Febrero 2013
#BitcoinT3F
Stack
(Public Key Hash)
(Public Key Hash)
(Public Key)
(Signature)
cb1f48
cb1f48
172D5w7C
bbba3f5
Legans
6 Febrero 2013
#BitcoinT3F
Stack
(Public Key)
(Signature)
172D5w7C
bbba3f5
Legans
6 Febrero 2013
#BitcoinT3F
Stack
(Public Key)
(Signature)
172D5w7C
bbba3f5
Legans
6 Febrero 2013
Stack
(EMPTY)
SUCCESS!
#BitcoinT3F
Legans
6 Febrero 2013
#BitcoinT3F
Legans
6 Febrero 2013
#BitcoinT3F
Random
diversion!
@_sortega
Legans
6 Febrero 2013
#BitcoinT3F
Stack
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<PubKey>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<7bb>
<PubKey>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<5aa>
<7bb>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<5aa>
<7bb>
<5aa>
<7bb>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<aHash>
<7bb>
<5aa>
<7bb>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<aHash>
<aHash>
<5aa>
<7bb>
<7bb>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<5aa>
<7bb>
<7bb>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<7bb>
<5aa>
<7bb>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<bHash>
<5aa>
<7bb>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<bHash>
<bHash>
<5aa>
<7bb>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<5aa>
<7bb>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<1>
<5aa>
<7bb>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<5>
<7bb>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<7bb>
<5>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<1>
<7bb>
<5>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<7>
<5>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
#BitcoinT3F
Stack
<12>
<PubKeyB>
<Sig>
Legans
6 Febrero 2013
Stack
<2>
<12>
<PubKeyB>
<Sig>
#BitcoinT3F
Legans
6 Febrero 2013
Stack
<12>
<2>
<PubKeyB>
<Sig>
#BitcoinT3F
Legans
6 Febrero 2013
Stack
<0>
<PubKeyB>
<Sig>
#BitcoinT3F
Legans
6 Febrero 2013
Stack
<PubKeyB>
<Sig>
(Standard Script)
#BitcoinT3F
Legans
6 Febrero 2013
#BitcoinT3F
Legans
6 Febrero 2013
#BitcoinT3F
Context: Oracles
The oracle contract allow define how the money
is spent including external state.
Allows to make reversible transactions.
Allow to pay, only if an external condition is true, for
example the result of a search in google, or the API SEUR
response.
Legans
6 Febrero 2013
#BitcoinT3F
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 }
TX3
in { TX1[0] }
out { 1 BTC
<SeurAPI(trackID) == RETURNED>
OP_HASH160 <ExternalScriptHash> OP_EQUALSVERIFY
<OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY }
<SeurAPI(trackID) == DELIVERED>
OP_HASH160 <ExternalScriptHash> OP_EQUALSVERIFY
<OraclePubKey> <BobPubKey> 2 OP_CHECKMULTISIGVERIFY }
Legans
6 Febrero 2013
Context: Oracles
Execution
TX2
in { TX1[0] }
out { 1 BTC
<SeurAPI(trackID) == RETURNED>
OP_HASH160 <ExternalScriptHash>
OP_EQUALSVERIFY
<OraclePubKey> <SamPubKey> 2
OP_CHECKMULTISIGVERIFY }
#BitcoinT3F
Legans
6 Febrero 2013
#BitcoinT3F
Context: Oracles
Execution
<OracleSig> <SamSig> <SeurAPI(trackID) == RETURNED>
OP_HASH160 <ExternalScriptHash> OP_EQUALSVERIFY
<OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY
Stack
Legans
6 Febrero 2013
#BitcoinT3F
Context: Oracles
Execution
<SamSig> <SeurAPI(trackID) == RETURNED>
OP_HASH160 <ExternalScriptHash> OP_EQUALSVERIFY
<OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY
Stack
<OracleSig>
Legans
6 Febrero 2013
#BitcoinT3F
Context: Oracles
Execution
<SeurAPI(trackID) == RETURNED>
OP_HASH160 <ExternalScriptHash> OP_EQUALSVERIFY
<OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY
Stack
<SamSig>
<OracleSig>
Legans
6 Febrero 2013
Context: Oracles
Execution
Stack
<SeurAPI(trackID) == RETURNED>
<SamSig>
<OracleSig>
#BitcoinT3F
Legans
6 Febrero 2013
Context: Oracles
Execution
<ExternalScriptHash> OP_EQUALSVERIFY
<OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY
Stack
<ScriptHash>
<SamSig>
<OacleSig>
#BitcoinT3F
Legans
6 Febrero 2013
Context: Oracles
Execution
OP_EQUALSVERIFY
<OraclePubKey> <SamPubKey> 2 OP_CHECKMULTISIGVERIFY
Stack
<ExternalScriptHash>
<ScriptHash>
<SamSig>
<OracleSig>
#BitcoinT3F
Legans
6 Febrero 2013
Context: Oracles
Execution
Stack
<SamSig>
<OracleSig>
#BitcoinT3F
Legans
6 Febrero 2013
Context: Oracles
Execution
SUCCESS!
Stack
#BitcoinT3F
Legans
6 Febrero 2013
#BitcoinT3F
Legans
6 Febrero 2013
#BitcoinT3F
Legans
6 Febrero 2013
TX2
IN {TX1[0]: 1 BTC
}
OUT {
0 : 1 BTC BOB }
LOCKTIME : 18
#BitcoinT3F
Legans
6 Febrero 2013
TX2
IN {TX1[0]: 1 BTC
}
OUT {
0 : 1 BTC BOB }
LOCKTIME : 18
#BitcoinT3F
Legans
6 Febrero 2013
TX2
IN {TX1[0]: 1 BTC
}
OUT {
0 : 1 BTC BOB }
LOCKTIME : 18
#BitcoinT3F
Legans
6 Febrero 2013
#BitcoinT3F
TX2
IN {TX1[0]: 1 BTC
}
OUT {
0 : 1 BTC BOB }
LOCKTIME : 18
IN {TX1[0] 1 BTC
}
OUT {0: 0,9 BTC BOB
0,1 BTC SAM }
Legans
6 Febrero 2013
#BitcoinT3F
TX2
IN {TX1[0]: 1 BTC
}
OUT {
0 : 1 BTC BOB }
LOCKTIME : 18
IN {TX1[0] 1 BTC
}
OUT {0: 0,8 BTC BOB
0,2 BTC SAM }
Legans
6 Febrero 2013
#BitcoinT3F
TX2
IN {TX1[0]: 1 BTC
}
OUT {
0 : 1 BTC BOB }
LOCKTIME : 18
IN {TX1[0] 1 BTC
}
OUT {0: 0,7 BTC BOB
0,3 BTC SAM }
Legans
6 Febrero 2013
#BitcoinT3F
IN {TX1[0] 1 BTC
}
OUT {0: 0,6 BTC BOB
0,4 BTC SAM }
TX2
IN {TX1[0]: 1 BTC
}
OUT {
0 : 1 BTC BOB }
LOCKTIME : 18
BREAK!
Legans
6 Febrero 2013
#BitcoinT3F
TX2
IN {TX1[0]: 1 BTC
}
OUT {
0 : 1 BTC BOB }
LOCKTIME : 18
IN {TX1[0] 1 BTC
}
OUT {0: 0,6 BTC BOB
0,4 BTC SAM }
Legans
6 Febrero 2013
#BitcoinT3F
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.