Lecture 7 Print
Lecture 7 Print
1 3
4 5
What to do? Ethereum: enables a world of applications
A world of Ethereum Decentralized apps (DAPPs)
NameCoin: a fork of Bitcoin that implements this contract
• New coins: ERC-20 standard interface
(see also the Ethereum Name Service -- ENS)
• DeFi: exchanges, lending, stablecoins, derivatives, etc.
Can we build a blockchain that natively supports generic • Insurance
contracts like this? • DAOs: decentralized organizations
• NFTs: Managing asset ownership (ERC-721 interface)
⇒ Ethereum
stateofthedapps.com, dapp.review
6 7
8 9
Running a program on a blockchain (DAPP) The Ethereum system
… blockchain … Proof-of-Stake consensus
One block every 12 seconds.
Tx1 state1 Tx2 state2 …
state0 about 150 Tx per block.
program
code create a DAPP
Block proposer receives
compute layer (execution chain): The EVM Tx fees for block
(along with other rewards)
consensus layer (beacon chain)
10 11
A bit about the beacon chain (Eth2 consensus layer) The economics of staking
To become a validator: stake (lock up) 32 ETH … or use Lido.
Validator locks up 32 ETH. Oct 2023: 27M ETH staked (total)
Validators: - sign blocks to express correctness (finalized once enough sigs)
- occasionally act as block proposer (chosen at random) Annual validator income (an example):
Can be adjusted
- correct behavior ⇒ issued new ETH every epoch (32 blocks) • Issuance: 1.0 ETH (BASE_REWARD_FACTOR)
12 13
The Ethereum system
update
world state compute layer (execution chain)
The Ethereum Compute Layer:
notify_new_payload(payload) [Engine API] The EVM
sends transactions to compute layer
14 15
18 19
20 21
Messages: virtual Tx initiated by a contract Example Tx
Same as Tx, but no signature (contract has no signing key)
Block proposer creates a block of n Tx: (from Txs submitted by users) (1) consensus data: proposer ID, parent hash, votes, etc.
• To produce a block do: (2) address of gas beneficiary: where Tx fees will go
• for i=1,…,n: execute state change of Txi sequentially
(can change state of >n accounts) (3) world state root: updated world state
• record updated world state in block Merkle Patricia Tree hash of all accounts in the system
(4) Tx root: Merkle hash of all Tx processed in block
Other validators re-execute all Tx to verify block ⇒ (5) Tx receipt root: Merkle hash of log messages generated in block
sign block if valid ⇒ enough sigs, epoch is finalized.
(5) Gas used: used to adjust gas price (target 15M gas per block)
24 25
The Ethereum blockchain: abstractly Amount of memory to run a node
accts. accts.
26 27
28 29
An example contract: NameCoin An example contract: NameCoin
function nameUpdate(
bytes32 name, bytes32 newValue, address newOwner) { function nameLookup(bytes32 name) {
// check if message is from domain owner, return data[name];
// and update cost of 10 Wei is paid }
if (data[name].owner == msg.sender && msg.value >= 10) {
} // end of contract
data[name].value = newValue; // record new value
data[name].owner = newOwner; // record new owner Used by other contracts
}}} Humans do not need this
(use etherscan.io)
30 31
32 33
Every instruction costs gas, examples: Gas calculation
SSTORE addr (32 bytes), value (32 bytes) Why charge gas?
• Tx fees (gas) prevents submitting Tx that runs for many steps.
• zero ⇾ non-zero: 20,000 gas
• During high load: block proposer chooses Tx from mempool
• non-zero ⇾ non-zero: 5,000 gas (for a cold slot) that maximize its income.
• non-zero ⇾ zero: 15,000 gas refund (example)
Old EVM: (prior to EIP1559, live on 8/2021)
Refund is given for reducing size of blockchain state
• Every Tx contains a gasPrice ``bid’’ (gas ⇾ Wei conversion price)
CREATE : 32,000 + 200×(code size) gas; CALL gas, addr, value, args • Producer chooses Tx with highest gasPrice (max sum(gasPrice×gasLimit))
SELFDESTRUCT addr: kill current contract (5000 gas) ⟹ not an efficient auction mechanism (first price auction)
34 35
Gas prices spike during congestion Gas calculation: EIP1559 (since 8/2021)
GasPrice in Gwei:
EIP1559 goals (informal):
86 Gwei = 86×10-9 ETH
• users incentivized to bid their true utility for posting Tx,
• block proposer incentivized to not create fake Tx, and
• disincentivize off chain agreements.
36 37
Gas calculation: EIP1559 Gas calculation
Every block has a “baseFee”:
EIP1559 Tx specifies three parameters:
the minimum gasPrice for all Tx in the block • gasLimit: max total gas allowed for Tx
• maxFee: maximum allowed gas price (max gas ⇾ Wei conversion)
baseFee is computed from total gas in earlier blocks: • maxPriorityFee: additional “tip” to be paid to block proposer
• earlier blocks at gas limit (30M gas) ⟹ base fee goes up 12.5% interpolate
in between
Computed gasPrice bid:
• earlier blocks empty ⟹ base fee decreases by 12.5%
gasPrice ⇽ min(maxFee, baseFee + maxPriorityFee)
If earlier blocks at “target size” (15M gas) ⟹ base fee does not change Max Tx fee: gasLimit × gasPrice
38 39
40 41
Example baseFee and effect of burn Why burn ETH ???
block # gasUsed baseFee (Gwei) ETH burned
15763570 21,486,058 16.92 ↓ 0.363
Recall: EIP1559 goals (informal)
15763569 14,609,185 (<15M) 16.97 0.248 • users incentivized to bid their true utility for posting Tx,
15763568 25,239,720 15.64 0.394 • block proposer incentivized to not create fake Tx, and
15763567 29,976,215 13.90 ↓ 0.416 • disincentivize off chain agreements.
15763566 14,926,172 (<15M) 13.91 ↓ 0.207
15763565 1,985,580 (<15M) 15.60 0.031
Suppose no burn (i.e., baseFee given to block producer):
≈ gasUsed×baseFee
beacon chain ⟹ in periods of low Tx volume proposer would try to increase
baseFee < 16Gwei ⇒ new issuance > burn ⇒ ETH inflates volume by offering to refund the baseFee off chain to users.
baseFee > 16Gwei ⇒ new issuance < burn ⇒ ETH deflates
42 43
END OF LECTURE
44 45