S03.1+-+Ethereum+Network+and+Ecosystem.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

UZH Blockchain &DLT Research Group Blockchain Center Ethereum Network and Ecosystem Blockchain and Crypto-Economics: Session 2.1 Dr. Sina Rafati Blockchain & Distributed Ledger Technologies UZH Blockchain Center Blockchain and Crypto-Economics HS 23 | 03.10.23 UZH Blockchain Center Blockch...

UZH Blockchain &DLT Research Group Blockchain Center Ethereum Network and Ecosystem Blockchain and Crypto-Economics: Session 2.1 Dr. Sina Rafati Blockchain & Distributed Ledger Technologies UZH Blockchain Center Blockchain and Crypto-Economics HS 23 | 03.10.23 UZH Blockchain Center Blockchain &DLT Research Group Lecture Objectives 1. 2. 3. Understanding the main differences between the Ethereum and Bitcoin blockhchains Learning Ethereum network components Learning Ethereum transaction and block fields and their use 2 UZH Blockchain Center Blockchain &DLT Research Group Introduction 3 UZH Blockchain Center Blockchain &DLT Research Group Deficits of Bitcoin Lack of applicability in different use cases 1. Bitcoin supports mainly p2p payments • Scalability Issues 2. Low throughput: calculated by Transactions validated Per 1. Second (TPS) High Latency 2. • 3. Long waiting time for a guaranteed transaction inclusion High energy consumption 4 UZH Blockchain Center Blockchain &DLT Research Group What were the goals in designing Ethereum back in 2014 - 2015? How did Ethereum achieve its goals? 5 UZH Blockchain Center Blockchain &DLT Research Group A permissionless blockchain with a builtin Turing-complete programming language that allows the creation of “smart contracts” to create decentralised applications 6 UZH Blockchain &DLT Research Group Blockchain Center 1.2. Ether: Ethereum’s native currency The cryptocurrency Ether (ETH) and its sub-units Value in (wei) Exponent Common Name SI Name 1 1 wei Wei 1,000,000,000 109 Shannon Gigawei or nanoether 1,000,000,000,000,000,000 1018 Ether Ether 7 UZH Blockchain Center Blockchain &DLT Research Group Ether (ETH) is the native asset of the Ethereum blockchain, used to reward block creation by validators but not only 8 UZH Blockchain Center Blockchain &DLT Research Group 1. Emerge of Ethereum Ethereum was conceived in 2013 by Vitalik Buterin as a blockchain platform that would allow the deployment of decentralised applications Ethereum network was launched in 2015 https://ethereum.org/en/foundation/ https://time.com/collection/time-issue-01-vitalik-buterin/6159859/issue-01-vitalik-buterin-march-2022/ 9 UZH Blockchain Center Blockchain &DLT Research Group 1.1. Ethereum Foundation • The Ethereum Foundation (EF) is a Swiss-based organisation • • It is one of the main supporters of the Ethereum ecosystem “Their role is not to control or lead Ethereum, nor are they the only organization that funds critical development of Ethereumrelated technologies.” https://ethereum.org/en/foundation/ 10 UZH Blockchain Center Blockchain &DLT Research Group Ethereum Foundation (EF) • EF received 12 million ETH from the initial supply for: • Ecosystem Support Program • Ongoing development, research, and promotion of the Ethereum platform • Ethereum Grants program • Developer Conferences • Fellowship Programs Ethereum Supply 11 UZH Blockchain Center Blockchain &DLT Research Group Ethereum vs. Bitcoin: Active Addresses and Daily Tranactions Ethereum has engaged a great number of users and handles a large number of transactions issued per day. Ethereum and Bitcoin Users and Transactions https://bitinfocharts.com/ 12 UZH Blockchain Center Blockchain &DLT Research Group 2. Ethereum Network Key Components 13 UZH Blockchain Center Blockchain &DLT Research Group 2. Ethereum Network Components (1 of 2) 2.1. P2P network: • Ethereum’s main network runs a protocol called ÐΞVp2p. • Miners (now validators) and clients • Accounts and Addresses 2.2. State machine: • Ethereum state transitions are processed by the Ethereum Virtual Machine (EVM) 14 UZH Blockchain Center Blockchain &DLT Research Group 2. Ethereum Network Components (2 of 2) 2.3. Transactions (Tx) • network messages that include (among other things) a sender, recipient, value, and data payload. 2.4. Blocks • Blocks encapsulate verified transactions • Blocks are the key units of the chain in the blockchain 2.5. Consensus rules: Ne xt S ess • 2015 - 2022: Proof-of-Work (PoW) ion • September 15, 2022 – present: Proof-of-Stake (PoS) 15 UZH Blockchain Center Blockchain &DLT Research Group 2.1. Ethereum P2P Network, Accounts, and Addresses 16 UZH Blockchain Center Blockchain &DLT Research Group 2.1. Ethereum P2P Network Each node persists the global state (“World State”) of the Ethereum P2P network 17 UZH Blockchain &DLT Research Group Blockchain Center 2.2. Accounts and Addresses Ethereum uses an account-based model which keeps track of balances associated with addresses. State 2 State 1 Address: Andrea Merlin … Balance: 70 10 … TX ID From Amount To …100 Andrea 50 Merlin Address: Andrea Merlin … Balance: 20 60 … 18 UZH Blockchain Center Blockchain &DLT Research Group There are two types of users in Ethereum: First Type: Externally Owned Accounts (EOA) - controlled by users with appropriate private keys 19 UZH Blockchain Center Blockchain &DLT Research Group Ethereum public key • Public keys are not the same as addresses! But there is a unique conversion which uses hashes and EIP-55 mixed-capitalization checksum which ensures that errors in typing or reading are easily detectable. • Ethereum public key (512 bits, 128 hex characters) 6e145ccef1033dea239875dd00dfb4fee6e3348b84985c92f103444683bae07b 83b5c38e5e2b0c8529d7fa3f64d46daa1ece2d9ac14cab9477d042c84c32ccd0 • Ethereum address (160 bits, 40 hex characters) 0x001d3F1ef827552Ae1114027BD3ECF1f086bA0F9 20 UZH Blockchain Center Blockchain &DLT Research Group Second Type: Smart contracts - controlled by the logic of the code Smart contracts can only execute transactions in response to other transactions, which ultimately have to be initiated by an EOA account! 21 UZH Blockchain Center Blockchain &DLT Research Group Ethereum Smart Contracts Smart Contracts Immutable and deterministic computer programs that run in an isolated fashion on blockchains. They are stored as transactions and executed by each network node. + Immutable - once deployed they cannot change + Deterministic - the outcome should be the same for everyone that runs it + Isolated - should not affect execution of other programs 22 UZH Blockchain Center Blockchain &DLT Research Group A lifecycle of a smart contract on Ethereum network 1. A smart contract developer writes a smart contract. (Any user can deploy a smart contract) 2. A validator (miner) writes the smart contract in a new block gets paid! 3. Any user can invoke read-only functions or state variables from a contract - free! 4. Any user can invoke a method that requires writing to blockchain - pays gas fee! 5. A validator executes a function and writes the result in a new block - gets paid! 23 UZH Blockchain Center Blockchain &DLT Research Group 2.2. States 24 UZH Blockchain Center Blockchain &DLT Research Group In the context of Ethereum, the state is kept in an enormous data structure called a modified Merkle Patricia Trie, which keeps all accounts linked by hashes, and it is reducible to a single root hash stored on the blockchain 25 UZH Blockchain Center Blockchain &DLT Research Group Effective use of Merkle root in a block In computer science, a trie (/ˈtriː/, /ˈtraɪ/), also called a digital tree or prefix tree, is a type of search tree, a tree data structure used for locating specific keys from within a set. An example of Merkle tree root used in blocks 26 UZH Blockchain Center Blockchain &DLT Research Group An Example of a Merkle Patricia Tree Each node is decided by the SHA3 hash value of its contents and the hash is used as a key 27 UZH Blockchain Center Blockchain &DLT Research Group Modified Merkle Patricia Tree Modified Merkle Patricia Trie is used as the main data structure in Ethereum tries: 1. world state trie, 2. account storage trie, 3. transaction trie, 4. receipt trie. https://doi.org/10.1155/2022/4723124 28 UZH Blockchain Center Blockchain &DLT Research Group Ethereum State roots stored in each Block Ethereum employs a set of “tries” to provide traceability of state changes https://medium.com/@JanessaTech/ethereum-a-latest-interpretation-of-yellow-paper-29ec14d05867 29 UZH Blockchain Center Blockchain &DLT Research Group State Trie – The one and only! State Trie There is one, and only one, global state trie in Ethereum, which is constantly updated. • Contains a key-value pair for every account • The “key” is a single 160-bit identifier (the address of an Ethereum account). • The “value” is created by encoding the following account details of an Ethereum account: – nonce , balance, storageRoot, codeHash 30 UZH Blockchain Center Blockchain &DLT Research Group Storage Trie — where the contract data lives Storage Trie • • • A storage trie is where all of the contract data lives. Each Ethereum account has its own storage trie. A 256-bit hash of the storage trie’s root node is stored as the storageRoot value in the global state 31 UZH Blockchain Center Blockchain &DLT Research Group Transaction trie — one per block Transaction Trie • Each Ethereum block has its own separate transaction trie. • The position of the transaction in a block is never changed. https://medium.com/cybermiles/diving-into-ethereums-world-state-c893102030ed 32 UZH Blockchain Center Blockchain &DLT Research Group Receipt trie • After a transaction is executed, a receipt is generated for that transaction to store: • gas used, • logs generated during execution, • Outcome of smart contract interactions: • • Contract address (if applicable) Developers and users can use these receipts to confirm that smart contract calls were executed 33 UZH Blockchain Center Blockchain &DLT Research Group 2.2.2. Ethereum Virtual Machine 34 UZH Blockchain Center Blockchain &DLT Research Group Ethereum nodes run the Ethereum Virtual Machine (EVM) to establish a distributed, replicated state machine that processes transactions according to the Consensus mechanism. 35 UZH Blockchain &DLT Research Group Blockchain Center Ethereum State Update via EVM The Ethereum state is changed by P2P transactions and smart contracts Smart Contract State 1 Address: Andrea Merlin … Balance: 70 10 … Account Storage State 2 TX ID From Amount To …100 Andrea 50 Merlin EVM Address: Andrea Merlin … Balance: 20 60 … up da ted Account Storage State changes are caused only through the EVM https://takenobu-hs.github.io/downloads/ethereum_evm_illustrated.pdf 36 UZH Blockchain &DLT Research Group Blockchain Center 2.2. Ethereum Virtual Machine (EVM) Components Ethereum Virtual Machine (EVM) Machine state (volatile) Program Counter (PC) Available Gas Virtual ROM (Immutable) EVM Code Stack Memory Account Storage • Stack: can contain up to 1024 operations of 256-bit word • Memory: does not persist between transactions https://ethereum.org/en/developers/docs/evm/ 37 UZH Blockchain &DLT Research Group Blockchain Center 2.2. Ethereum Virtual Machine (EVM) Components Ethereum Virtual Machine (EVM) Machine state (volatile) Program Counter (PC) Available Gas • Virtual ROM (Immutable) EVM Code Stack Memory Account Storage Account Storage: is the persistent 256 bits * 256 bits, Key-Value store All operations are performed in the stack (e.g., PUSH /POP /COPY /SWAP) https://ethereum.org/en/developers/docs/evm/ • 38 UZH Blockchain Center Blockchain &DLT Research Group The specific rules of changing state from block to block are defined by the EVM 39 UZH Blockchain Center Blockchain &DLT Research Group 2.3. Ethereum Transactions Structure 40 UZH Blockchain &DLT Research Group Blockchain Center Ethereum Transactions Transactions are serialized binary messages that contain different fields From • Recipient Signature Nonce Value Input data Gas Limit maxPriority FeePerGas maxFeePerGas Transaction Types: • Regular: from one account to another. • Contract deployment: without a 'to' address, where the • data field is used for the contract code. Execution of a contract: interacts with a deployed smart contract. The 'to' address is the smart contract address. 41 UZH Blockchain Center Blockchain &DLT Research Group Ethereum Transaction Content (1 of 2) From: • The address of the sender, that will be signing the transaction. • EOA only Recipient: • The receiving address • If an EOA, the transaction will transfer value • If a contract account, the transaction will execute the contract code Signature: • The identifier of the sender • This is generated when the sender's private key signs the transaction • confirms the sender has authorized this transaction Nonce: • A sequence number, issued by the originating EOA • Used to prevent message replay 42 UZH Blockchain Center Blockchain &DLT Research Group Ethereum Transaction Content (2 of 2) Value: • The amount of ether (in wei) to send to the destination Input Data: • The variable-length binary data payload (optional) Gas Limit: • The maximum amount of gas the originator is willing to buy for this transaction maxFeePerGas: • The amount of ether (in wei) that the originator is willing to pay for each unit of gas maxPriorityFee PerGas: • the maximum price of the consumed gas to be included as a tip to the validator https://ethereum.org/en/developers/docs/transactions/ 43 UZH Blockchain Center Blockchain &DLT Research Group “nonce” is a scalar value equal to the number of transactions sent from one address or, the number of contractcreations made by an account. It is an up-to-date count of the on-chain transactions that have originated from an account. 44 UZH Blockchain Center Blockchain &DLT Research Group nonce is not stored explicitly as part of an account’s state on the blockchain. Instead, it is calculated dynamically by counting the number of confirmed transactions originating from an address. 45 UZH Blockchain Center Blockchain &DLT Research Group Ethereum Transactions: Nonce Example The transaction count will be updated after the new transactions are added to the chain, even if the nonce is increased by the wallet. 46 UZH Blockchain Center Blockchain &DLT Research Group The use of the nonce is vital for an account-based protocol, in contrast to the “Unspent Transaction Output” (UTXO) mechanism of the Bitcoin protocol. 47 UZH Blockchain Center Blockchain &DLT Research Group Transactions are processed by validators sequentially using the EVM, based on the nonce. 48 UZH Blockchain Center Blockchain &DLT Research Group The nonce mechanics Gaps in transactions If a user transmits a transaction with nonce 0, and then transmit another with nonce 2, the second transaction will not be included in any block. It will be stored in the mempool, while the validator nodes await the transaction with the missing nonce to appear 49 UZH Blockchain Center Blockchain &DLT Research Group The nonce mechanics Duplicate nonces If transmitting two transactions with the same nonce but different recipients or values: one of them will be confirmed and one will be rejected. Which one is confirmed will be determined by the order in which they arrive at the node that confirms it 50 UZH Blockchain Center Blockchain &DLT Research Group How to charge for transactions execution? 51 UZH Blockchain Center Blockchain &DLT Research Group Gas is a measure of computational effort needed to execute specific operations on the Ethereum network It is paid in ETH. Price is determined with the auction-based mechanism. 52 UZH Blockchain Center Blockchain &DLT Research Group Gas is not Ether. it is a separate accounting unit with its own exchange rate against ETH 53 UZH Blockchain Center Blockchain &DLT Research Group GasPrice • Wallets can adjust the gasPrice in transactions they originate to achieve faster confirmation of transactions. • Recommended priority fee in Gwei (29.09.2023): • Fast <2m= 19 • • • Standard <5m = 16 Safe Low <30m =12 Minimum value for gasPrice: 0! https://ethereum.github.io/yellowpaper/paper.pdf https://ethgasstation.info/ 54 UZH Blockchain Center Blockchain &DLT Research Group Ethereum Average Gas Price The not too consistent average gas price in Ethereum Ethereum average Gas price – All-time view 55 UZH Blockchain Center Blockchain &DLT Research Group Minimum Gas price London Upgrade (August 2021) introduced a base fee as a minimum gas price needed for a transaction to be included in the block. These base fees are then burned! https://etherscan.io/block/13281446 56 UZH Blockchain Center Blockchain &DLT Research Group Ethereum Transactions: gasLimit Gas Limit sets the maximum number of units of gas the transaction originator is willing to buy to complete the transaction • Example 1: Deterministic gas usage of an EOA-to-EOA transaction: Total price = operation gas amount * gasPrice = 21,000 * gasPrice 2: Non-deterministic gas usage of contracts 57 UZH Blockchain Center Blockchain &DLT Research Group Ethereum Transaction Fee High transaction fee of Ethereum has been an issue for users Ethereum average Transaction fee – All-time view 58 UZH Blockchain Center Blockchain &DLT Research Group Ethereum Block Gas Limit Block Gas limit is dynamically adjusted by validators, but a cap is accepted in the network between miners In each block, miners can increase or decrease the block size by a maximum of the previous block size divided by 1024 Block Gas limit changes over time on the Ethereum network 59 UZH Blockchain Center Blockchain &DLT Research Group Block Size in Ethereum • Block size is bounded by the computational cost needed for the execution of all transactions contained in them • Each block has a target gas limit of 30 M gas, but this can increase or decrease based on the network demand. • The typical storage size of a block is less than 200 KByte. 60 UZH Blockchain Center Blockchain &DLT Research Group Ethereum Block Size Ethereum’s block size has increased over time: Block-size of Ethereum – All-time view 61 UZH Blockchain Center Blockchain &DLT Research Group Comparing Block size and Gas limit growth Ethereum network has seen block size encrements over time as the gas limit has increased Gas Limit effect on Average Block-size of Ethereum – All-time view 62 UZH Blockchain Center Blockchain &DLT Research Group The total amount of gas expended by all transactions in the block must be less than the block gas limit. 63 UZH Blockchain Center Blockchain &DLT Research Group Transmiting Data and Value through Transactions 64 UZH Blockchain Center Blockchain &DLT Research Group Fields of a transaction: “Recipient” Transaction recipient (‘to’) • EOA or a contract address • Contains a 20-byte address • Note: any 20-byte value is considered valid! • Burned Ether! 65 UZH Blockchain Center Blockchain &DLT Research Group Fields of a transaction: “value” and “data” “value” and “data” The main "payload" of a transaction is contained in two fields: ‘value’ and ‘data’. • A transaction with only value is a payment. • A transaction with only data is an invocation. • A transaction with both value and data is both a payment and an invocation. $ web3.eth.sendTransaction({from: src, to: dst, value: web3.utils.toWei(0.01, "ether"), data: "0x1234"}); 66 UZH Blockchain Center Blockchain &DLT Research Group 2.4. Ethereum Block Structure 67 UZH Blockchain Center Blockchain &DLT Research Group Structure of an Ethereum block (1 of 4) Each Ethereum block contains at least: • parentHash – hash of the previous block’s header • Fee Recipient: The 160-bit address to which all fees collected from the successful mining of this block be transferred; • StateRoot – hash of the root node of the state trie, after all transactions are executed and finalisations applied https://ethereum.org/en/developers/docs/blocks/ 68 UZH Blockchain Center Blockchain &DLT Research Group Structure of an Ethereum block (2 of 4) • Total difficulty – A scalar value corresponding to the difficulty level of this block. This can be calculated from the previous block's difficulty level and the timestamp. This field was used in the PoW era • gasLimit – A scalar value equal to the current limit of gas expenditure per block • gasUsed – A scalar value equal to the total gas used in transactions in this block https://ethereum.org/en/developers/docs/blocks/ 69 UZH Blockchain Center Blockchain &DLT Research Group Structure of an Ethereum block (3 of 4) • Transactions – transactions included in the block • Timestamp – time when the block was created • Base Fee Per Gas – minimum gas fee required for a transaction to be included in the block 70 UZH Blockchain Center Blockchain &DLT Research Group Average block time Except for a few months, Ethereum has performed with the same block time: raising scalability concerns Block time changes on the Ethereum network https://etherscan.io/chart/blocktime 71 UZH Blockchain Center Blockchain &DLT Research Group Block size and block time affect the blockchain’s scalability 72 UZH Blockchain Center Blockchain &DLT Research Group A key challenge experienced in the Ethereum Ecosystem - High number of TXs leading to high transaction fees 73 UZH Blockchain Center Blockchain &DLT Research Group 2.5. Ethereum consensus mechanism… (TBC in the NEXT LECTURE) 74 UZH Blockchain Center Blockchain &DLT Research Group Summary § Block and transaction content, the virtual machine, and the protocols implemented in the P2P network of blockchains are some of the key aspects affecting blockchains and their applications. § Storing the Ethereum state within the Merkle tries, plays an important role in reducing the size of the data each block has to contain while enabling the traceability of actions. § EVM is at the heart of all state updates, which enforces homogenous operations all over the network 75 UZH Blockchain Center Blockchain &DLT Research Group Bibliography and Refrences Basic reading for Ethereum Mastering Ethereum” by Antonopoulos A.M., Wood G. (O’Reilly • Media) • Ethereum whitepaper” • • https://ethereum.org/en/whitepaper/ Ethereum Yellowpaper • • • https://github.com/ethereumbook/ethereumbook https://ethereum.github.io/yellowpaper/paper.pdf Etherscan.io/chart/ 76 UZH Blockchain Center Blockchain &DLT Research Group Questions / Comments 77 UZH Blockchain Center Dr. Sina Rafati Blockchain & Distributed Ledger Technologies UZH Blockchain Center [email protected] https://www.blockchain.uzh.ch in/sina-rafati-niya-16242579/ @uzh_blockchain Blockchain &DLT Research Group

Use Quizgecko on...
Browser
Browser