Ethereum Basics: Blockchain-Based Systems Engineering
Ethereum Basics: Blockchain-Based Systems Engineering
2. System Architecture
§ Concept of a World Computer
§ EVM
§ Accounts
§ Blockchain Properties
§ Smart Contracts
3. Network Architecture
§ Overview
§ Node Types
§ Clients
§ Geth
§ OpenEthereum
§ Non-profit organization
§ 1.716.600 peak of transactions per day § 439.549 peak of transactions per day1
§ Currently almost 6x the number of
BTC transactions each day 1
The given graph shows 7-day average.
Ethereum transaction chart by Etherscan: https://etherscan.io/chart/tx
06 Ethereum Basics © sebis
Bitcoin transaction chart by Blockchain.com: https://www.blockchain.com/charts/n-transactions 9
Like Bitcoin, Ethereum is in Productive Use
Active Wallets
2. System Architecture
§ Concept of a World Computer
§ EVM
§ Accounts
§ Blockchain Properties
§ Smart Contracts
3. Network Architecture
§ Overview
§ Node Types
§ Clients
§ Geth
§ OpenEthereum
Tx Properties
Tx
Tx • All participants are using the same
computer
Tx
• Users issue transactions to call
programs on the computer
World
Tx • Everyone shares the same
Computer resources and storage
Tx = Transaction
06 Ethereum Basics © sebis 13
Election Example Using a World Computer
State 0 (initial)
(nothing happened yet)
Class Election
var votes: {
World
amabo: 0
pmurt: 0
Computer
}
vote(key) {
votes[key]++
}
State 0 (initial)
(nothing happened yet)
Election
Computer
}
vote(key) {
votes[key]++
}
State 0 (initial)
(nothing happened yet)
Election
WorldComputer.execute(Election.vote("amabo"))
State 1 {amabo:1, pmurt:0}
var votes: { (vote for amabo)
World
amabo: 2
pmurt: 0
Computer
}
State 0 (initial)
(nothing happened yet)
Election
Computer
}
State 0 (initial)
(nothing happened yet)
var votes: {
World
amabo: 3
pmurt: 1
State 2 {amabo:2, pmurt:0}
Computer
}
(vote for amabo)
vote(key) {
votes[key]++
}
State 3 {amabo:2, pmurt:1}
(vote for pmurt)
06 Ethereum Basics
WorldComputer.execute(Election.vote(“amabo")) © sebis 18
Blockchain as a State Machine
State of the world Blockchain
Tx
Tx
Genesis
State 4 {amabo:3, pmurt:1} Block 1 Block 2 Block 3 Block 4
(vote for amabo) Block
(immutable)
The EVM specifies an execution model for state changes of the blockchain.
The block_state represents the global state of the whole blockchain including all accounts,
contracts and storage
Genesis
Block 1 Block 2 Block 3 Block N
Block
Compared to Bitcoin, Ethereum uses an account-based ledger. Each distinct address represents a
separate, unique account.
nonce
An increasing number that is attached to any transaction to prevent replay attacks.
balance
The current account balance of the account in Ether.
contract_code
The bytecode representation of the account. If no contract code is present, then the account is
externally controlled.
storage
The data storage used by the account and empty by default. Only contract accounts can have their
own storage.
A transaction is a signed data package that is always sent by a EOA and contains the following data:
§ The recipient of the transaction
§ A signature identifying the sender
§ The amount of ether to transfer from the sender to the recipient
§ An optional data field – data field is used for function call arguments (e.g. function inputs)
§ A GASLIMIT1 value, representing the maximum amount of gas
you are willing to consume on a transaction
§ A GASPRICE value, representing the fee the sender pays per computational step
§ There are two types of transactions: From EOA to EOA and from EOA to smart contract
A message is very similar to a transaction. Messages are only sent by contracts and
exist only virtually, i.e. they are not mined into a block like transactions.
A message contains:
§ The sender of the message (implicit)
§ The recipient of the message
§ The amount of ether to transfer alongside the message
§ An optional data field
§ A GASLIMIT value
code
The code basically represents a smart contract as bytecode. For the EVM, a smart contract
is a sequence of opcodes similar to assembly code.
Example:
PUSH1 0x60
PUSH1 0x40
MSTORE
PUSH1 0x04
CALLDATASIZE
LT
PUSH2 0x00b6
JUMPI
PUSH4 0xffffffff
memory
An infinitely expandable byte array that is non-persistent and used as temporal storage
during execution.
stack
The stack is also used as a fast, non-persistent buffer to which 32 byte values can be pushed
and popped during execution.
pc
PC stands for “program counter”. The program counter is always initialized with 0 and
points to the position of the current opcode instruction.
0 PUSH1 0x60
1 PUSH1 0x40
2 MSTORE Program Counter (2)
3 PUSH1 0x04
4 CALLDATASIZE
5 LT
6 PUSH2 0x00b6
7 JUMPI
8 PUSH4 0xffffffff
Gas
§ Every executed opcode instruction uses a EVM
miner’s computational resources More gas
§ Each opcode uses a certain amount of gas Program counter Stack Memory
(Account)
storage
which may depend on the arguments of the PC
operation, e.g., number of bytes to be
allocated. Gas available
Gas
§ The opcode for selfdestruct (address) uses
negative gas because it frees up space
from the blockchain.
More gas
§ At the beginning of a transaction, the sender must § The Ethereum Improvement Proposal (EIP)-1559,
specify a maximum amount of gas that he/she is enabled the deflationary functionality of the Ethereum
willing to pay for the transaction to be executed. blockchain and sought to alter how gas prices are
calculated.
§ The sender can set an arbitrary amount of Ether
he/she is willing to pay for each gas unit called § The main motivation for EIP-1559 was the large
gasprice. volatility in transaction fees.
§ The final cost for each transaction is gas * gasprice
§ With EIP-1559, gas price is now divided into two parts:
and this fee is received entirely by the miner.
§ base fee: calculated by the network based on the
§ If a transaction requires more gas than the demand level (burnt) – predictable
maximum specified gas, the transaction will fail. On § priority fee (tip): determined by the transaction
the other hand, if it takes less, the sender only pays sender (received by the miner)
for the gas that was used.
§ Transaction fee = gas * (basefee + tip)
§ The actual size of a block is not limited like in
Bitcoin. Instead, the miner sets a gaslimit that § As of January 5th, 2022, the network burns an average
defines how much computational resources he is of 6.18 ETH every minute. So far, the Ethereum
willing to provide for each block. blockchain has burned a total of 1,887,620 ETH.
Transaction: https://etherscan.io/tx/0xf053bfba668022c43f837939373b2fc35672d04d67bbc48d3d7c42e9d90ecc7e
06 Ethereum Basics © sebis 30
Properties of the Ethereum Blockchain
Ethereum (currently) is a Proof-of-Work (PoW) blockchain like Bitcoin.
§ The PoW algorithm used by Ethereum is called Ethash and designed to be ASIC resistant.
§ In Ethereum blockchain, when a miner creates a block successfully, they are rewarded with a digital
token called "ether”. Miners spend energy on mining and solving a puzzle. In return they get a block
reward which is transaction fee + mining reward. Mining reward is 2 ETH ($5,435 as of 25th of
February 2022).
§ Correctly mined blocks that are outpaced by a block of another miner are not orphaned like in
Bitcoin but added as uncle blocks.
§ The idea behind this is to counter mining centralization because miners who mine a correct
block are still rewarded.
§ As of January 2022, average block time of Ethereum blockchain is 12 to 14 seconds.1
§ A smart contract is a set of functions that can be called by other users or contracts.
§ They can be used to execute functions, send ether or store data.
§ Each smart contract is an account holding object, i.e. has its own address.
§ Smart contracts have some peculiarities compared to traditional software.
Security
§ Furthermore, the whole transaction history is accessible (function calls + actual arguments).
§ Smart contracts – once deployed – cannot be changed or patched anymore.
Smart contracts can’t access any data from outside the blockchain on their own. There are no HTTP
or similar network methods implemented to call external services. This is on purpose to prevent non-
deterministic behavior once a function is called (there are also no functions to generate random
values).
Currently, the only way to write smart contracts using external data (e.g. weather data, traffic data etc.)
is to use oracles. Oracles are basically third-party services that verify data from web services and write
the data via a special smart contract to the blockchain. Other smart contracts can now call the oracle
contract to get the data.
A: Requests Data
Oracle 3. Writes data Oracle External
SC Contract Web API
B: Returns Data Service
2. Returns Data
Usually, smart contracts are not written as a sequence of opcodes instructions directly. Solidity is a
high-level language with a JavaScript-like syntax and the de facto standard for writing Ethereum
smart contracts. However, unlike JavaScript, Solidity is statically typed.
Language properties
• Statically typed
• Object-oriented
• Supports inheritance
• Complex, user-defined types
• Public & private methods
• Dynamic binding
• Compiled to EVM opcode instructions
Play-to-Earn Games
Lately, smart contracts are also being used in play-to-earn games where users earn game-native tokens
which they can use to buy or trade in-game assets. Popular examples: Axie Infinity, Decentraland
2. System Architecture
§ Concept of a World Computer
§ EVM
§ Accounts
§ Blockchain Properties
§ Smart Contracts
3. Network Architecture
§ Overview
§ Node Types
§ Clients
§ Geth
§ OpenEthereum
Light node
Mining pool
Pool participant
provider
Light node
Solo miner
Full nodes
Full nodes are the foundation of the Ethereum network. Each full node holds a copy of the entire
blockchain and syncs it with other nodes. Transactions must be sent to a full node which distributes it
among the network participants.
Light nodes
A light node is a client that is connected to a full node for the sake of not having to sync and download
the entire blockchain. For most private people, light nodes are the most comfortable way of interacting
with the Ethereum blockchain. One of the most common light nodes is https://myetherwallet.com
(always triple check the domain).
Solo miner
A solo miner is an entity that tries to mine a block on its own. At the current network hashing rate this is
practically impossible. However, in order to mine a block it is required to have a synced copy of the full
blockchain.
Mining pools
Mining pools are a coalition of entities combining their hash power to solve a mining problem. A pool
consists of a controller that splits and distributes the mining puzzle among the participants.
Geth
The most commonly used and official Ethereum implementation. Geth is
implemented in Go and provides a command-line interface for running a full
node. Geth comes with a JavaScript console and a JSON RPC server.
Through which – if publicly exposed – other (light) nodes could connect to
the network.
Both Geth and OpenEthereum have a maintained list of default peers hardcoded into their source
code. Otherwise, it would be possible that no nodes are found, and the sync will always fail.
1. Looks up
New Node
Hardcoded Node
Once a node is selected, a hello message is sent to make an initial connection with the node.