(Eth Deep Dive) Ethereum & Smart Contracts - Enabling A Decentralized Future-Blockchain-Berkeley
(Eth Deep Dive) Ethereum & Smart Contracts - Enabling A Decentralized Future-Blockchain-Berkeley
ETHEREUM AND
SMART CONTRACTS:
ENABLING A
DECENTRALIZED FUTURE
Max Fang
2
OUR MISSION
BLOCKCHAIN AT BERKELEY
We seek to educate people about blockchain technology through a wide variety of educational
offerings, to expand blockchain integration by building everything from prototypes to full-fledged
solutions, and to foster innovation through original research and infrastructural contributions.
STRUCTURE
Blockchain at Berkeley
OUTLINE
ETHEREUM DEEP DIVE
1 ETHEREUM
SMART
2 CONTRACTS
3 EVM
4 USE CASES
5 GENERALIZATIONS
5
1 INTRODUCTION TO
BLOCKCHAIN
6
Consensus
Trustless
Distributed
wow
7
BLOCKCHAIN INTRO
ETHEREUM DEEP DIVE
what is a Blockchain?
BLOCKCHAIN INTRO
ETHEREUM DEEP DIVE
Ledger
Alice $500
Charlie $1000
BLOCKCHAIN INTRO
ETHEREUM DEEP DIVE
BLOCKCHAIN INTRO
ETHEREUM DEEP DIVE
why Distributed?
BLOCKCHAIN INTRO
ETHEREUM DEEP DIVE
Immutable?
BLOCKCHAIN INTRO
ETHEREUM DEEP DIVE
Cryptographic Identity
Authentication
Peers sign transactions with their
cryptographic identity
Enables account "ownership"
Can attribute blame
AUTHOR: PHILIP HAYES
13
BLOCKCHAIN INTRO
ETHEREUM DEEP DIVE
BLOCKCHAIN INTRO
ETHEREUM DEEP DIVE
USING ETHEREUM
ETHEREUM DEEP DIVE
BLOCKCHAIN COMPONENTS
ETHEREUM DEEP DIVE
Transactions
Commits changes to the blockchain
Contains signature of owner of address
Blocks
Contains an ordered bunch of transactions
Timestamps the transactions, are immutable
Each block References a previous block
Blockchain
The entire series of blocks 'chained' together Source: Bitcoin Developer Guide
2 ETHEREUM
OVERVIEW
19
WHAT IS ETHEREUM?
ETHEREUM DEEP DIVE
High-level Overview:
Ethereum is a decentralized platform designed to run smart contracts
no single point of control/failure
censorship resistant
Distributed state machine
(block of) transactions == state transition function
Or just think decentralized computer
Account-based blockchain
20
WHAT IS ETHEREUM?
ETHEREUM DEEP DIVE
Recall:
A Bitcoin users available balance is the sum of unspent transaction
outputs for which they own the private keys to the output addresses.
Instead Ethereum uses a different concept, called Accounts.
Account:
Bitcoin: Ethereum:
address Bob owns private keys to Evan owns private keys
set of UTXOs to an account
balance
5 BTC Bob address: 0xfa38b...
(optional) code
3 BTC Bob balance: 10 ETH
ACCOUNTS RATIONALE
ETHEREUM DEEP DIVE
Space Savings
Nodes only need to update each accounts balance instead of storing
every UTXO
More Intuitive
smart contracts are more easier to program when transferring
between accounts with a balance
vs. constantly updating a UTXO set to compute users available
balance.
28
3
ETHEREUM
VIRTUAL
MACHINE
29
EVM
ETHEREUM DEEP DIVE
EVM
ETHEREUM DEEP DIVE
EVM
(block_state, gas)
Simplicity:
op-codes should be as low-level as possible.
The number of op-codes should be minimized.
Space Efficiency:
EVM assembly should be as compact as possible
Determinism:
The execution of EVM code should be deterministic
The same input state should always yield the same output state.
Specialization:
should easily handle 20-byte addresses and custom cryptography with 32-byte values
modular arithmetic used in custom cryptography
read block and transaction data, interact with state, etc
Security:
should be easy to create gas cost model for operations so VM non-exploitable
32
Solidity Contract
contract PhilipToken {
solc
/* ... */ (Solidity Compiler) EVM Code
}
PUSH1 0x60
PUSH1 0x40
. . .
POP
Serpent Contract JUMP
def register(key, value): serpent compiler
/* */
33
Immediate Issue:
function foo()
{
while (true) {
/* Loop forever! */
}
}
34
Immediate Issue:
Every node on the network will get stuck executing the loop forever!
By the halting problem, it is impossible to determine ahead of time
whether the contract will ever terminate
Denial of Service Attack!
35
Ethereums Solution:
Every contract requires gas, which fuels contract execution.
Every EVM op-code requires some gas in order to execute.
Every transaction specifies
the startgas , or the maximum quantity of gas it is willing to
consume
the gasprice , or the fee in ether it is willing to pay per unit
gas.
36
ETHEREUM CONCLUSIONS
ETHEREUM DEEP DIVE
4 SMART
CONTRACTS
40
contract
(noun) /kntrakt/
smart contract
SMART CONTRACTS
ETHEREUM DEEP DIVE
Example: Namecoin
DNS system
Maps domain name to IP address
"maxfa.ng" => "69.69.69.69"
Immutable
Easy implementation in Ethereum
5 NOVEL USE
CASES
49
Prediction markets draws on the wisdom of the crowd to forecast the future
Market makers create event
Ex: "Who will win the 2020 US Presidential election?"
Events must be public and easily verifiable, with set due date
Participants buy shares of Trump or Zuckerberg and pay a small fee
On election day, random oracles on the network vote on who won.
Oracles who voted with the majority collect a fee, they are otherwise penalized
Shareholders who voted correctly cash out on their bet
The share price for each market accurately represents the best
predicted probability of event occurring
Shares resolve to $1 if true, $0 otherwise
Someone has extra information => arbitrage opportunity
50
5.1 GENERALIZATIONS
CONCLUSION
ETHEREUM DEEP DIVE
Blockchain technology (and distributed
tech) is going to lead to a new world of
decentralization
Remember:
Why is blockchain better than using
a centralized database?
Almost any app that exists today
can (theoretically) be built in a
completely decentralized way
The only limitation is what we can
secure and scale
Contact me:
[email protected]
Website: maxfa.ng
59
QUESTIONS?
60
X
(EXTRA)
BUSINESS
USE CASES
61
After hours trading has not taken off because it faces a liquidity problem
"Convenience is great, but Id rather have a better price" - Direct Edge COO
62
Brokerages can let users "withdraw" their stock into stock tokens on a
blockchain.
The stock is subtracted from the user's account, brokerage holds it in the
meantime.
Brokerage writes a legal contract: "Anyone who proves that they own a stock
token is eligible to redeem it for a stock I am currently holding"
Tokens are backed by real stocks
Create a trustless blockchain-based stock exchange that allows users to
trade around stock tokens.
63
Result:
After hours trading enabled with very little cost
Anyone can now use their Ethereum to buy stock tokens and trade, 24/7/365
Multiple brokerages can participate and create a shared liquidity pool
Brokerages don't have no need to trust each other, since asset management
and deduplication handled by the blockchain
Anti money laundering is enforced when traders redeem their tokens.
All trading history is transparently logged on the blockchain.
Coordination of development
"I, house A, commit $10k to building this infrastructure. If house B and house C
also commit $10k, the total amount will go to this contractor to begin
construction, and it can only go to this contractor."
Households can coordinate to build infrastructure without trusting each other