Toronto Aug 20 2017 [email protected] Ethan Buchman€¦ · and Smart Contracts Day 2 Ethan...
Transcript of Toronto Aug 20 2017 [email protected] Ethan Buchman€¦ · and Smart Contracts Day 2 Ethan...
Transaction Scripts
- Output: scriptPubKey- conditions that must be met to spend
these outputs
- Input: scriptSig- data satisfying the conditions of the
scriptPubKey
Transaction Scripts - P2PKH
Pay-2-Pubkey-HashscriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
scriptSig: <sig> <pubKey>
https://blockchain.info/tx/cadbe6ea2bdc089f7093d532cecdd10dde69c124722b35a009538497536e80a7
Transaction Scripts - P2PKH
Pay-2-Pubkey-HashscriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
scriptSig: <sig> <pubKey>
https://blockchain.info/tx/9f456b95ea97cfc9dcb6eec6c5d42afef2974b49517894251fba974ad1fd5910
Transaction Scripts - MultiSig
MultiSigscriptPubKey: <m> <A pubkey> [B pubkey] [C pubkey...] <n> OP_CHECKMULTISIG
scriptSig: OP_0 <A sig> [B sig] [C sig...]
https://blockchain.info/tx/59609f66c65c85c2990ed5699275e99eb9af358dece111107eddbed02100cb34
Transaction Scripts - MultiSig
MultiSigscriptPubKey: <m> <A pubkey> [B pubkey] [C pubkey...] <n> OP_CHECKMULTISIG
scriptSig: OP_0 <A sig> [B sig] [C sig...]
https://blockchain.info/tx/a1dd1e764940543e7ca53a05f7c15e7ca1b35a88dac82802cf4a19db77340e8e
Transaction Scripts - P2SH (Multisig)
Pay-2-Script-HashscriptPubKey: OP_HASH160 <Hash160(redeemScript)> OP_EQUAL
scriptSig: <sig> [sig] [sig...] <redeemScript>
https://blockchain.info/tx/5fb8e21e4e5d0557f0bb6ec3d8c4f4b7968e39c9c3d1af486322c3098ae633a3
Transaction Scripts - P2SH (Multisig)
Pay-2-Script-HashscriptPubKey: OP_HASH160 <Hash160(redeemScript)> OP_EQUAL
scriptSig: <sig> [sig] [sig...] <redeemScript>
https://blockchain.info/tx/24c5a606501655c00345c485fb11771103d95e15bffe3e2f10c62fa66bead654https://chainquery.com/bitcoin-api/decodescript
Transaction Scripts - P2SH (CSV)
OP_IF 2 <pubkey1> <pubkey2> 2 OP_CHECKMULTISIG
OP_ELSE10 OP_CHECKSEQUENCEVERIFY OP_DROP OP_DUP OP_HASH160 <addr> OP_EQUALVERIFY OP_CHECKSIG
OP_ENDIF
Redeem condition 1: https://blockchain.info/tx/3fa26dc97735f657bdf997360b3de698e1e8b92f4dc88193a38be926ff183e0c
Redeem condition 2: https://blockchain.info/tx/4ba75dfe11988663cfcbbc8911eedee1f867d99fa744a6137e885315b3a073e1
https://chainquery.com/bitcoin-api/decodescript
Transaction Scripts - Embedding Data
OP_RETURNscriptPubKey: OP_RETURN <data>
scriptSig: N/A
https://blockchain.info/tx/d29c9c0e8e4d2a9790922af73f0b8d51f0bd4bb19940d9cf910ead8fbe85bc9b
Transaction Scripts - Embedding Data
https://blockchain.info/address/35ty8iaSbWsj4YVkoHzs9pZMze6dapeoZ8
Transaction Scripts - Craziness
https://blockchain.info/tx/9f17f3ce43019c24baa6d679edfdddeada856f617cd9c1f6008d49be4542b768
https://blockchain.info/tx/219b5815886af9c9ff74fdbe8146731534b0c1b1dc23bfd3fab81745433bbc3f
Storing State: Accounts
- Accounts are:- Address- Balance- Nonce- Bytecode- Storage
Ether. The ethereum cryptofuel
# of transactions sent. Avoid replay attacks and the mess of inputs/outputs
Turing complete EVM assembly language.32-byte word stack, byte-array memory
32-byte word storage area. Isolated per account
Last 20 bytes of the hash of the pubkey
Transactions
Nonce
Data
Value
To
Gas Limit
Gas Price
Sender’s transaction count
The product of these is the fee paid
Destination address. Can be a contract or another account
Amount of ether being sent
Data to be processed by a contract
Contracts
Code Storage
Calldata Stack Memory
Non-volatile
Volatile
Nonce
Data
Value
To
Gas Limit
Gas Price
Contract Code
https://etherscan.io/address/0x6090a6e47849629b7245dfa1ca21d94cd15878ef
Contract State
https://etherscan.io/address/0x6090a6e47849629b7245dfa1ca21d94cd15878ef
Deploying Contracts
https://etherscan.io/tx/0x4c3fd67575a9254c553d906af0f2c84789502bae5a6723ea3bc345c5dcbf0751
Interacting with Contracts
https://www.myetherwallet.com/#contracts
Contract Notes
- Thoughts on Solidity: https://news.ycombinator.com/item?id=14691212- Guide: https://github.com/CoinCulture/evm-tools/
- Security:- Basics: https://blog.ethereum.org/2016/06/10/smart-contract-security/- The Docs: http://solidity.readthedocs.io/en/develop/security-considerations.html- Extensive Guide: https://github.com/ConsenSys/smart-contract-best-practices- Contract Framework: https://github.com/OpenZeppelin/zeppelin-solidity- Analysis: http://hackingdistributed.com/2016/06/16/scanning-live-ethereum-contracts-for-bugs/
- Post Mortems- Parity Wallet Bug: http://hackingdistributed.com/2017/07/20/parity-wallet-not-alone/- King of the Ether: http://www.kingoftheether.com/postmortem.html- Quadriga:
https://www.reddit.com/r/ethereum/comments/6ettq5/statement_on_quadrigacx_ether_contract_error/
Somebody else’s state machine
- Zookeeper, etcd, consul- Fancy key-value store- Emphasis on distributed systems tasks (dynamic config, locking,
etc.)
- Bitcoin- “Programmable money”- “Functional programming” - no state (!), contracts renewed
every transaction- Forth like, purposefully not Turing-complete
- Ethereum- “Smart contracts”- “Contract-oriented” - stateful contracts live independently on the
blockchain- Turing complete (Ethereum Virtual Machine)
Application Blockchain Interface
SECURITY & NETWORKING PLATFORMS
APPLICATION PLATFORMS
SOCKET PROTOCOLSCGI ABCI
Tendermint
Tendermint
ABCI
- Network of “validators”, each with private key
- Validators take turns (round-robin) proposing blocks of recent transactions
- Validators vote on proposed blocks
- Once more than ⅔ vote for same block, it is committed
- Transactions in committed blocks are run against the application to get a final checksum included in the next block
More on Tendermint
https://tendermint.com
https://cosmos.network
https://github.com/tendermint/tendermint
Tendermint in a Nutshell
https://medium.com/@tendermint/tendermint-in-a-nutshell-39d9f7f66ad7