Writing Smart Contracts
Dionysis Zindros
Smart Contracts Day Athens, March 2017
Writing Smart Contracts Dionysis Zindros Smart Contracts Day - - PowerPoint PPT Presentation
Writing Smart Contracts Dionysis Zindros Smart Contracts Day Athens, March 2017 We talked all about what smart contracts are... ...but what does a real smart contract look like? Lets talk about writing actual Smart Contracts with code
Smart Contracts Day Athens, March 2017
...but what does a real smart contract look like?
In this talk, we’ll get slightly more technical :)
○ Can express ideas such as a “payment contract” ○ We’ll go through that in this talk
○ e.g. Ethereum, Cardano ○ Darryl will talk more about this in a bit
tx from to
tx Alice Bob
which is its nominal monetary value
tx Alice Bob 15€ 15€
tx Alice Bob 15mBTC 15mBTC
tx input
tx
together
Alice Bob 1 BTC 1 BTC
tx
Charlie 1 BTC
tx tx
Dionysis 1 BTC
1 BTC
tx Alice Bob 1 BTC tx Charlie 1 BTC tx Unspent transaction output
1 BTC Alice tx
1 BTC Alice tx utxo
1 BTC Alice tx tx
1 BTC Alice 1 BTC Bob tx tx
1 BTC Alice 1 BTC Bob not utxo any more new utxo tx tx
cannot be forged towards a wrong owner with just copying it
1 BTC Alice tx 1 BTC Bob Alice signs tx
contracts
○ Alice owns some money ○ Alice and Bob own money together ○ Micropayments - continuous transfer of value
bitcoin address!
edge can be spent
tx Alice Bob 36 mBTC 36 mBTC
1FdtUtvK5vZxwo8jzjzid5EwGAB7paqX4n 128MZKqUsvg2kYJQ5LCVDx8Mdn8xrijzQY
tx 36 mBTC 36 mBTC
tx
OP_DUP OP_HASH160 128MZKqUsvg2kYJQ5LCVDx8Mdn8xrijzQY OP_EQUALVERIFY OP_CHECKSIG
36 mBTC
OP_DUP OP_HASH160 1FdtUtvK5vZxwo8jzjzid5EwGAB7paqX4n OP_EQUALVERIFY OP_CHECKSIG
36 mBTC
○ i.e. that the output edge is spent fairly
(the program = the encumbrance) so that when the scriptPubKey program runs with these parameters, it outputs 1
connected to
for failure or success
to an owner
bank or government
scriptPubKey: 045a5f526dfe5d5995bf95f12 OP_CHECKSIG scriptSig: signature σ
scriptPubKey: 045a5f526dfe5d5995bf95f12 OP_CHECKSIG scriptSig: signature σ σ
scriptPubKey: 045a5f526dfe5d5995bf95f12 OP_CHECKSIG scriptSig: signature σ σ
scriptPubKey: 045a5f526dfe5d5995bf95f12 OP_CHECKSIG scriptSig: signature σ 045a5f526dfe5d5995bf95f12 σ
scriptPubKey: 045a5f526dfe5d5995bf95f12 OP_CHECKSIG scriptSig: signature σ 045a5f526dfe5d5995bf95f12 σ
scriptPubKey: 045a5f526dfe5d5995bf95f12 OP_CHECKSIG scriptSig: signature σ 1
transaction completed successfully
scriptPubKey: OP_DUP OP_HASH160 1FdtUtvK5vZxwo8jzjzid5Ew OP_EQUALVERIFY OP_CHECKSIG scriptSig: pubKey signature σ
scriptPubKey: OP_DUP OP_HASH160 1FdtUtvK5vZxwo8jzjzid5Ew OP_EQUALVERIFY OP_CHECKSIG scriptSig: pubKey signature σ pubKey signature σ
scriptPubKey: OP_DUP OP_HASH160 1FdtUtvK5vZxwo8jzjzid5Ew OP_EQUALVERIFY OP_CHECKSIG scriptSig: pubKey signature σ pubKey signature σ
scriptPubKey: OP_DUP OP_HASH160 1FdtUtvK5vZxwo8jzjzid5Ew OP_EQUALVERIFY OP_CHECKSIG scriptSig: pubKey signature σ pubKey pubKey signature σ
scriptPubKey: OP_DUP OP_HASH160 1FdtUtvK5vZxwo8jzjzid5Ew OP_EQUALVERIFY OP_CHECKSIG scriptSig: pubKey signature σ pubKey pubKey signature σ
scriptPubKey: OP_DUP OP_HASH160 1FdtUtvK5vZxwo8jzjzid5Ew OP_EQUALVERIFY OP_CHECKSIG scriptSig: pubKey signature σ H(pubKey) pubKey signature σ
scriptPubKey: OP_DUP OP_HASH160 1FdtUtvK5vZxwo8jzjzid5Ew OP_EQUALVERIFY OP_CHECKSIG scriptSig: pubKey signature σ H(pubKey) pubKey signature σ
scriptPubKey: OP_DUP OP_HASH160 1FdtUtvK5vZxwo8jzjzid5Ew OP_EQUALVERIFY OP_CHECKSIG scriptSig: pubKey signature σ 1FdtUtvK5vZxwo8jzjzid5Ew H(pubKey) pubKey signature σ
scriptPubKey: OP_DUP OP_HASH160 1FdtUtvK5vZxwo8jzjzid5Ew OP_EQUALVERIFY OP_CHECKSIG scriptSig: pubKey signature σ 1FdtUtvK5vZxwo8jzjzid5Ew H(pubKey) pubKey signature σ
scriptPubKey: OP_DUP OP_HASH160 1FdtUtvK5vZxwo8jzjzid5Ew OP_EQUALVERIFY OP_CHECKSIG scriptSig: pubKey signature σ pubKey signature σ
scriptPubKey: OP_DUP OP_HASH160 1FdtUtvK5vZxwo8jzjzid5Ew OP_EQUALVERIFY OP_CHECKSIG scriptSig: pubKey signature σ 1
transaction completed successfully
OP_SIZE OP_NIP 16 OP_NUMEQUAL OP_NUMEQUAL OP_IF ALICE_PUB_KEY OP_ELSE BOB_PUB_KEY OP_END_IF OP_CHECKSIG OP_2DUP OP_HASH160 BOB_HASH_CONST OP_EQUALVERIFY OP_HASH160 ALICE_HASH_CONST OP_EQUALVERIFY OP_SIZE OP_NIP 16 OP_NUMEQUAL OP_SWAP