BERLIN VERSION Beacfbd - 2022-10-24
BERLIN VERSION Beacfbd - 2022-10-24
BERLIN VERSION Beacfbd - 2022-10-24
Abstract. The blockchain paradigm when coupled with cryptographically-secured transactions has demonstrated its
utility through a number of projects, with Bitcoin being one of the most notable ones. Each such project can be seen as
a simple application on a decentralised, but singleton, compute resource. We can call this paradigm a transactional
singleton machine with shared-state.
Ethereum implements this paradigm in a generalised manner. Furthermore it provides a plurality of such resources,
each with a distinct state and operating code but able to interact through a message-passing framework with others.
We discuss its design, implementation issues, the opportunities it provides and the future hurdles we envisage.
the Namecoin project which aims to provide a decentralised itself—that would be far too big). They also punctuate the
name-resolution system. transaction series with incentives for nodes to mine. This
Other projects still aim to build upon the Bitcoin net- incentivisation takes place as a state-transition function,
work itself, leveraging the large amount of value placed in adding value to a nominated account.
the system and the vast amount of computation that goes Mining is the process of dedicating effort (working) to
into the consensus mechanism. The Mastercoin project, bolster one series of transactions (a block) over any other
first proposed by Willett [2013], aims to build a richer potential competitor block. It is achieved thanks to a
protocol involving many additional high-level features on cryptographically secure proof. This scheme is known as a
top of the Bitcoin protocol through utilisation of a number proof-of-work and is discussed in detail in section 11.5.
of auxiliary parts to the core protocol. The Coloured Coins Formally, we expand to:
project, proposed by Rosenfeld et al. [2012], takes a similar (2) σ t+1 ≡ Π(σ t , B)
but more simplified strategy, embellishing the rules of a
transaction in order to break the fungibility of Bitcoin’s (3) B ≡ (..., (T0 , T1 , ...), ...)
base currency and allow the creation and tracking of tokens (4) Π(σ, B) ≡ Ω(B, Υ(Υ(σ, T0 ), T1 )...)
through a special “chroma-wallet”-protocol-aware piece of Where Ω is the block-finalisation state transition func-
software. tion (a function that rewards a nominated party); B is this
Additional work has been done in the area with discard- block, which includes a series of transactions amongst some
ing the decentralisation foundation; Ripple, discussed by other components; and Π is the block-level state-transition
Boutellier and Heinzen [2014], has sought to create a “fed- function.
erated” system for currency exchange, effectively creating This is the basis of the blockchain paradigm, a model
a new financial clearing system. It has demonstrated that that forms the backbone of not only Ethereum, but all
high efficiency gains can be made if the decentralisation decentralised consensus-based transaction systems to date.
premise is discarded.
Early work on smart contracts has been done by Szabo 2.1. Value. In order to incentivise computation within the
[1997] and Miller [1997]. Around the 1990s it became clear network, there needs to be an agreed method for transmit-
that algorithmic enforcement of agreements could become a ting value. To address this issue, Ethereum has an intrinsic
significant force in human cooperation. Though no specific currency, Ether, known also as ETH and sometimes referred
system was proposed to implement such a system, it was to by the Old English D̄. The smallest subdenomination
proposed that the future of law would be heavily affected of Ether, and thus the one in which all integer values of
by such systems. In this light, Ethereum may be seen as a the currency are counted, is the Wei. One Ether is defined
general implementation of such a crypto-law system. as being 1018 Wei. There exist other subdenominations of
For a list of terms used in this paper, refer to Appen- Ether:
dix A. Multiplier Name
0
10 Wei
2. The Blockchain Paradigm
1012 Szabo
Ethereum, taken as a whole, can be viewed as a 1015 Finney
transaction-based state machine: we begin with a gen- 1018 Ether
esis state and incrementally execute transactions to morph Throughout the present work, any reference to value,
it into some current state. It is this current state which we in the context of Ether, currency, a balance or a payment,
accept as the canonical “version” of the world of Ethereum. should be assumed to be counted in Wei.
The state can include such information as account bal-
ances, reputations, trust arrangements, data pertaining 2.2. Which History? Since the system is decentralised
to information of the physical world; in short, anything and all parties have an opportunity to create a new block
that can currently be represented by a computer is admis- on some older pre-existing block, the resultant structure is
sible. Transactions thus represent a valid arc between two necessarily a tree of blocks. In order to form a consensus
states; the ‘valid’ part is important—there exist far more as to which path, from root (the genesis block) to leaf (the
invalid state changes than valid state changes. Invalid state block containing the most recent transactions) through
changes might, e.g., be things such as reducing an account this tree structure, known as the blockchain, there must
balance without an equal and opposite increase elsewhere. be an agreed-upon scheme. If there is ever a disagreement
A valid state transition is one which comes about through between nodes as to which root-to-leaf path down the block
a transaction. Formally: tree is the ‘best’ blockchain, then a fork occurs.
This would mean that past a given point in time (block),
(1) σ t+1 ≡ Υ(σ t , T )
multiple states of the system may coexist: some nodes be-
where Υ is the Ethereum state transition function. In lieving one block to contain the canonical transactions,
Ethereum, Υ, together with σ are considerably more pow- other nodes believing some other block to be canonical,
erful than any existing comparable system; Υ allows com- potentially containing radically different or incompatible
ponents to carry out arbitrary computation, while σ allows transactions. This is to be avoided at all costs as the un-
components to store arbitrary state between transactions. certainty that would ensue would likely kill all confidence
Transactions are collated into blocks; blocks are chained in the entire system.
together using a cryptographic hash as a means of refer- The scheme we use in order to generate consensus is a
ence. Blocks function as a journal, recording a series of simplified version of the GHOST protocol introduced by
transactions together with the previous block and an iden- Sompolinsky and Zohar [2013]. This process is described
tifier for the final state (though do not store the final state in detail in section 10.
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 3
Sometimes, a path follows a new protocol from a par- Arbitrary-length sequences are typically denoted as a
ticular height (block number). This document describes bold lower-case letter, e.g. o is used to denote the byte
one version of the protocol, namely the Berlin version sequence given as the output data of a message call. For
defined by Beiko et al. [2021b]. In order to follow back the particularly important values, a bold uppercase letter may
history of a path, one must reference multiple versions of be used.
this document. Here are the block numbers of protocol Throughout, we assume scalars are non-negative inte-
updates on the Ethereum main network: gers and thus belong to the set N. The set of all byte
sequences is B, formally defined in Appendix B. If such
Name First Block Number
a set of sequences is restricted to those of a particular
FHomestead 1150000 length, it is denoted with a subscript, thus the set of all
FTangerineWhistle 2463000 byte sequences of length 32 is named B32 and the set of
FSpuriousDragon 2675000 all non-negative integers smaller than 2256 is named N256 .
FByzantium 4370000 This is formally defined in section 4.3.
FConstantinople 7280000 Square brackets are used to index into and reference
FPetersburg 7280000 individual components or subsequences of sequences, e.g.
FIstanbul 9069000 µs [0] denotes the first item on the machine’s stack. For
FMuirGlacier 9200000 subsequences, ellipses are used to specify the intended
FBerlin 12244000 range, to include elements at both limits, e.g. µm [0..31]
FLondon 12965000 denotes the first 32 items of the machine’s memory.
FArrowGlacier 13773000 In the case of the global state σ, which is a sequence of
FGrayGlacier 15050000 accounts, themselves tuples, the square brackets are used
Occasionally actors do not agree on a protocol change, to reference an individual account.
and a permanent fork occurs. In order to distinguish be- When considering variants of existing values, we follow
tween diverged blockchains, EIP-155 by Buterin [2016b] the rule that within a given scope for definition, if we
introduced the concept of chain ID, which we denote by β. assume that the unmodified ‘input’ value be denoted by
For the Ethereum main network the placeholder then the modified and utilisable value is
denoted as 0 , and intermediate values would be ∗ , ∗∗
(5) β=1 &c. On very particular occasions, in order to maximise
readability and only if unambiguous in meaning, we may
3. Conventions use alpha-numeric subscripts to denote intermediate values,
especially those of particular note.
We use a number of typographical conventions for the
When considering the use of existing functions, given a
formal notation, some of which are quite particular to the
function f , the function f ∗ denotes a similar, element-wise
present work:
version of the function mapping instead between sequences.
The two sets of highly structured, ‘top-level’, state val-
It is formally defined in section 4.3.
ues, are denoted with bold lowercase Greek letters. They
We define a number of useful functions throughout. One
fall into those of world-state, which are denoted σ (or a
of the more common is `, which evaluates to the last item
variant thereupon) and those of machine-state, µ.
in the given sequence:
Functions operating on highly structured values are
denoted with an upper-case Greek letter, e.g. Υ, the
Ethereum state transition function. (6) `(x) ≡ x[kxk − 1]
For most functions, an uppercase letter is used, e.g. C,
the general cost function. These may be subscripted to 4. Blocks, State and Transactions
denote specialised variants, e.g. CSSTORE , the cost func- Having introduced the basic concepts behind Ethereum,
tion for the SSTORE operation. For specialised and possibly we will discuss the meaning of a transaction, a block and
externally defined functions, we may format as typewriter the state in more detail.
text, e.g. the Keccak-256 hash function (as per version
3 of the winning entry to the SHA-3 contest by Bertoni 4.1. World State. The world state (state), is a map-
et al. [2011], rather than the final SHA-3 specification), is ping between addresses (160-bit identifiers) and account
denoted KEC (and generally referred to as plain Keccak). states (a data structure serialised as RLP, see Appendix B).
Also, KEC512 refers to the Keccak-512 hash function. Though not stored on the blockchain, it is assumed that
Tuples are typically denoted with an upper-case letter, the implementation will maintain this mapping in a modi-
e.g. T , is used to denote an Ethereum transaction. This fied Merkle Patricia tree (trie, see Appendix D). The trie
symbol may, if accordingly defined, be subscripted to refer requires a simple database backend that maintains a map-
to an individual component, e.g. Tn , denotes the nonce ping of byte arrays to byte arrays; we name this underlying
of said transaction. The form of the subscript is used to database the state database. This has a number of benefits;
denote its type; e.g. uppercase subscripts refer to tuples firstly the root node of this structure is cryptographically
with subscriptable components. dependent on all internal data and as such its hash can
Scalars and fixed-size byte sequences (or, synonymously, be used as a secure identity for the entire system state.
arrays) are denoted with a normal lower-case letter, e.g. Secondly, being an immutable data structure, it allows any
n is used in the document to denote a transaction nonce. previous state (whose root hash is known) to be recalled
Those with a particularly special meaning may be Greek, by simply altering the root hash accordingly. Since we
e.g. δ, the number of items required on the stack for a store all such root hashes in the blockchain, we are able to
given operation. trivially revert to old states.
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 4
The account state, σ[a], comprises the following four An account is empty when it has no code, zero nonce
fields: and zero balance:
nonce: A scalar value equal to the number of trans- (14)
actions sent from this address or, in the case EMPTY(σ, a) ≡ σ[a]c = KEC () ∧σ[a]n = 0∧σ[a]b = 0
of accounts with associated code, the number of
Even callable precompiled contracts can have an empty
contract-creations made by this account. For ac-
account state. This is because their account states do not
count of address a in state σ, this would be for-
usually contain the code describing its behavior.
mally denoted σ[a]n .
An account is dead when its account state is non-existent
balance: A scalar value equal to the number of Wei
or empty:
owned by this address. Formally denoted σ[a]b .
storageRoot: A 256-bit hash of the root node of a (15) DEAD(σ, a) ≡ σ[a] = ∅ ∨ EMPTY(σ, a)
Merkle Patricia tree that encodes the storage con-
tents of the account (a mapping between 256-bit 4.2. The Transaction. A transaction (formally, T ) is a
integer values), encoded into the trie as a mapping single cryptographically-signed instruction constructed by
from the Keccak 256-bit hash of the 256-bit integer an actor externally to the scope of Ethereum. The sender
keys to the RLP-encoded 256-bit integer values. of a transaction cannot be a contract. While it is assumed
The hash is formally denoted σ[a]s . that the ultimate external actor will be human in nature,
codeHash: The hash of the EVM code of this software tools will be used in its construction and dissemi-
account—this is the code that gets executed should nation1. EIP-2718 by Zoltu [2020] introduced the notion
this address receive a message call. All such of different transaction types. As of the Berlin version of
code fragments are contained in the state data- the protocol, there are two transaction types: 0 (legacy)
base under their corresponding hashes for later and 1 (EIP-2930 by Buterin and Swende [2020b]). Further,
retrieval. This hash is formally denoted σ[a]c , and there are two subtypes of transactions: those which result
thus the code may be denoted as b, given that in message calls and those which result in the creation of
KEC(b) = σ[a]c . new accounts with associated code (known informally as
Since we typically wish to refer not to the trie’s root ‘contract creation’). All transaction types specify a number
hash but to the underlying set of key/value pairs stored of common fields:
within, we define a convenient equivalence:
type: EIP-2718 transaction type; formally Tx .
TRIE L∗I (σ[a]s ) ≡ σ[a]s nonce: A scalar value equal to the number of trans-
(7)
actions sent by the sender; formally Tn .
The collapse function for the set of key/value pairs in gasPrice: A scalar value equal to the number of
the trie, L∗I , is defined as the element-wise transformation Wei to be paid per unit of gas for all computation
of the base function LI , given as: costs incurred as a result of the execution of this
transaction; formally Tp .
(8) LI (k, v) ≡ KEC(k), RLP(v)
gasLimit: A scalar value equal to the maximum
where: amount of gas that should be used in executing
this transaction. This is paid up-front, before any
(9) k ∈ B32 ∧ v∈N computation is done and may not be increased
It shall be understood that σ[a]s is not a ‘physical’ later; formally Tg .
member of the account and does not contribute to its later to: The 160-bit address of the message call’s recipi-
serialisation. ent or, for a contract creation transaction, ∅, used
If the codeHash field is the Keccak-256 hash of the here to denote the only member of B0 ; formally
empty string, i.e. σ[a]c = KEC () , then the node represents Tt .
a simple account, sometimes referred to as a “non-contract” value: A scalar value equal to the number of Wei to
account. be transferred to the message call’s recipient or,
Thus we may define a world-state collapse function LS : in the case of contract creation, as an endowment
to the newly created account; formally Tv .
(10) LS (σ) ≡ {p(a) : σ[a] 6= ∅} r, s: Values corresponding to the signature of the
transaction and used to determine the sender of
where
the transaction; formally Tr and Ts . This is ex-
panded in Appendix F.
(11) p(a) ≡ KEC(a), RLP (σ[a]n , σ[a]b , σ[a]s , σ[a]c )
EIP-2930 (type 1) transactions also have:
This function, LS , is used alongside the trie function
to provide a short identity (hash) of the world state. We accessList: List of access entries to warm up; for-
assume: mally TA . Each access list entry E is a tuple
of an account address and a list of storage keys:
(12) ∀a : σ[a] = ∅ ∨ (a ∈ B20 ∧ v(σ[a])) E ≡ (Ea , Es ).
where v is the account validity function: chainId: Chain ID; formally Tc . Must be equal to
the network chain ID β.
(13) v(x) ≡ xn ∈ N256 ∧xb ∈ N256 ∧xs ∈ B32 ∧xc ∈ B32 yParity: Signature Y parity; formally Ty .
1Notably, such ‘tools’ could ultimately become so causally removed from their human-based initiation—or humans may become so
causally-neutral—that there could be a point at which they rightly be considered autonomous agents. e.g. contracts may offer bounties to
humans for being sent transactions to initiate their execution.
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 5
Legacy transactions do not have an accessList (TA = parentHash: The Keccak 256-bit hash of the parent
()), while chainId and yParity for legacy transactions block’s header, in its entirety; formally Hp .
are combined into a single value: ommersHash: The Keccak 256-bit hash of the om-
w: A scalar value encoding Y parity and possi- mers list portion of this block; formally Ho .
bly chain ID; formally Tw . Tw = 27 + Ty or beneficiary: The 160-bit address to which all fees
Tw = 2β+35+Ty (see EIP-155 by Buterin [2016b]). collected from the successful mining of this block
Additionally, a contract creation transaction (regardless be transferred; formally Hc .
whether legacy or EIP-2930) contains: stateRoot: The Keccak 256-bit hash of the root
node of the state trie, after all transactions are
init: An unlimited size byte array specifying the
executed and finalisations applied; formally Hr .
EVM-code for the account initialisation procedure,
transactionsRoot: The Keccak 256-bit hash of the
formally Ti .
root node of the trie structure populated with each
init is an EVM-code fragment; it returns the body, transaction in the transactions list portion of the
a second fragment of code that executes each time the block; formally Ht .
account receives a message call (either through a trans- receiptsRoot: The Keccak 256-bit hash of the root
action or due to the internal execution of code). init is node of the trie structure populated with the re-
executed only once at account creation and gets discarded ceipts of each transaction in the transactions list
immediately thereafter. portion of the block; formally He .
In contrast, a message call transaction contains: logsBloom: The Bloom filter composed from index-
data: An unlimited size byte array specifying the able information (logger address and log topics)
input data of the message call, formally Td . contained in each log entry from the receipt of
Appendix F specifies the function, S, which maps trans- each transaction in the transactions list; formally
actions to the sender, and happens through the ECDSA of Hb .
the SECP-256k1 curve, using the hash of the transaction difficulty: A scalar value corresponding to the dif-
(excepting the latter three signature fields) as the datum ficulty level of this block. This can be calculated
to sign. For the present we simply assert that the sender from the previous block’s difficulty level and the
of a given transaction T can be represented with S(T ). timestamp; formally Hd .
number: A scalar value equal to the number of an-
(16) cestor blocks. The genesis block has a number of
(
(Tn , Tp , Tg , Tt , Tv , p, Tw , Tr , Ts ) if Tx = 0 zero; formally Hi .
LT (T ) ≡ gasLimit: A scalar value equal to the current limit
(Tc , Tn , Tp , Tg , Tt , Tv , p, TA , Ty , Tr , Ts ) if Tx = 1
of gas expenditure per block; formally Hl .
where gasUsed: A scalar value equal to the total gas used
(
Ti if Tt = ∅ in transactions in this block; formally Hg .
(17) p≡ timestamp: A scalar value equal to the reasonable
Td otherwise
output of Unix’s time() at this block’s inception;
Here, we assume all components are interpreted by the formally Hs .
RLP as integer values, with the exception of the access list extraData: An arbitrary byte array containing data
TA and the arbitrary length byte arrays Ti and Td . relevant to this block. This must be 32 bytes or
(18) Tx ∈ {0, 1} ∧ Tc = β ∧ Tn ∈ N256 ∧ fewer; formally Hx .
Tp ∈ N256 ∧ Tg ∈ N256 ∧ Tv ∈ N256 ∧ mixHash: A 256-bit hash which, combined with the
Tw ∈ N256 ∧ Tr ∈ N256 ∧ Ts ∈ N256 ∧ nonce, proves that a sufficient amount of compu-
Ty ∈ N1 ∧ Td ∈ B ∧ Ti ∈ B tation has been carried out on this block; formally
Hm .
where
nonce: A 64-bit value which, combined with the mix-
(19) Nn = {P : P ∈ N ∧ P < 2n } hash, proves that a sufficient amount of computa-
The address hash Tt is slightly different: it is either a tion has been carried out on this block; formally
20-byte address hash or, in the case of being a contract- Hn .
creation transaction (and thus formally equal to ∅), it is
the RLP empty byte sequence and thus the member of B0 :
(
B20 if Tt 6= ∅ The other two components in the block are simply a list
(20) Tt ∈
B0 otherwise of ommer block headers (of the same format as above),
BU and a series of the transactions, BT . Formally, we can
4.3. The Block. The block in Ethereum is the collec- refer to a block B:
tion of relevant pieces of information (known as the block
header ), H, together with information corresponding to
the comprised transactions, T, and a set of other block
headers U that are known to have a parent equal to the
present block’s parent’s parent (such blocks are known as
ommers 2). The block header contains several pieces of
information: (21) B ≡ (BH , BT , BU )
2ommer is a gender-neutral term to mean “sibling of parent”; see https://nonbinary.miraheze.org/wiki/Gender_neutral_language_in_
English#Aunt/Uncle
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 6
4.3.1. Transaction Receipt. In order to encode information 4.3.2. Holistic Validity. We can assert a block’s validity
about a transaction concerning which it may be useful if and only if it satisfies several conditions: it must be in-
to form a zero-knowledge proof, or index and search, we ternally consistent with the ommer and transaction block
encode a receipt of each transaction containing certain in- hashes and the given transactions BT (as specified in sec
formation from its execution. Each receipt, denoted BR [i] 11), when executed in order on the base state σ (derived
for the ith transaction, is placed in an index-keyed trie from the final state of the parent block), result in a new
and the root recorded in the header as He . state of the identity Hr :
The transaction receipt, R, is a tuple of five items com-
prising: the type of the transaction, Rx , the status code of (33) Hr ≡ TRIE(LS (Π(σ, B))) ∧
the transaction, Rz , the cumulative gas used in the block Ho ≡ KEC(RLP(L∗H (BU ))) ∧
containing the transaction receipt as of immediately after Ht ≡ TRIE({∀i < kBT k, i ∈ N :
the transaction has happened, Ru , the set of logs created pT (i, BT [i])}) ∧
through execution of the transaction, Rl and the Bloom He ≡ TRIE({∀i < kBR k, i ∈ N :
filter composed from information in those logs, Rb : W pR (i, BR [i])}) ∧
Hb ≡ r∈BR rb
(22) R ≡ (Rx , Rz , Ru , Rb , Rl )
where pT (k, v) and pR (k, v) are pairwise RLP transforma-
Rx is equal to the type of the corresponding transaction. tions, but with a special treatment for EIP-2718 transac-
The function LR prepares a transaction receipt for being tions:
transformed into an RLP-serialised byte array: (34) ( !
(23) LR (R) ≡ (Rz , Ru , Rb , Rl ) RLP(LT (T )) if Tx = 0
pT (k, T ) ≡ RLP(k),
(Tx ) · RLP(LT (T )) otherwise
We assert that the status code Rz is a non-negative
integer: and
(35)
(24) Rz ∈ N
( !
RLP(LR (R)) if Rx = 0
pR (k, R) ≡ RLP(k),
We assert that Ru , the cumulative gas used, is a non- (Rx ) · RLP(LR (R)) otherwise
negative integer and that the logs Bloom, Rb , is a hash of
size 2048 bits (256 bytes): (· is the concatenation of byte arrays).
Furthermore:
(25) Ru ∈ N ∧ Rb ∈ B256
(36) TRIE(LS (σ)) = P (BH )H r
The sequence Rl is a series of log entries, (O0 , O1 , ...).
A log entry, O, is a tuple of the logger’s address, Oa , a Thus TRIE(LS (σ)) is the root node hash of the Merkle
possibly empty series of 32-byte log topics, Ot and some Patricia tree structure containing the key-value pairs of
number of bytes of data, Od : the state σ with values encoded using RLP, and P (BH ) is
the parent block of B, defined directly.
(26) O ≡ (Oa , (Ot0 , Ot1 , ...), Od ) The values stemming from the computation of transac-
tions, specifically the transaction receipts, BR , and that
(27) Oa ∈ B20 ∧ ∀x ∈ Ot : x ∈ B32 ∧ Od ∈ B defined through the transaction’s state-accumulation func-
tion, Π, are formalised later in section 11.4.
We define the Bloom filter function, M , to reduce a log
entry into a single 256-byte hash: 4.3.3. Serialisation. The function LB and LH are the prepa-
_ ration functions for a block and block header respectively.
(28) M (O) ≡ x∈{Oa }∪Ot M3:2048 (x)
We assert the types and order of the structure for when
where M3:2048 is a specialised Bloom filter that sets three the RLP transformation is required:
bits out of 2048, given an arbitrary byte sequence. It does
(37) LH (H) ≡ ( Hp , H o , H c , H r , H t , H e , H b , H d ,
this through taking the low-order 11 bits of each of the
Hi , H l , H g , H s , H x , H m , H n )
first three pairs of bytes in a Keccak-256 hash of the byte
e ∗T (BT ), L∗H (BU )
sequence.3 Formally: (38) LB (B) ≡ LH (BH ), L
where B is the bit reference function such that Bj (x) equals with Le ∗T and L∗H being element-wise sequence transforma-
the bit of index j (indexed from 0) in the byte array x. tions, thus:
Notably, it treats x as big-endian (more significant bits (40)
f ∗ (x0 , x1 , ...) ≡ f (x0 ), f (x1 ), ... for any function f
will have smaller indices).
32048 = 211 (11 bits), and the low-order 11 bits is the modulo 2048 of the operand, which is in this case is “each of the first three pairs of
bytes in a Keccak-256 hash of the byte sequence.”
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 7
The component types are defined thus: the mean block time including uncle blocks by Buterin
(41) Hp ∈ B32 ∧ Ho ∈ B32 ∧ Hc ∈ B20 ∧ [2016a]. In the Byzantium release, with EIP-649, the ice
Hr ∈ B32 ∧ Ht ∈ B32 ∧ He ∈ B32 ∧ age was delayed by creating a fake block number, Hi0 , which
Hb ∈ B256 ∧ Hd ∈ N ∧ Hi ∈ N ∧ is obtained by subtracting three million from the actual
Hl ∈ N ∧ Hg ∈ N ∧ Hs ∈ N256 ∧ block number, which in other words reduced and the
Hx ∈ B ∧ Hm ∈ B32 ∧ Hn ∈ B8 time difference between blocks, in order to allow more
time to develop proof-of-stake and preventing the network
where from “freezing” up. Subsequently, EIP-1234 by Schoedon
(42) Bn = {B : B ∈ B ∧ kBk = n} [2018], EIP-2384 by Conner [2019], EIP-3554 by Hancock
[2021], EIP-4345 by Beiko et al. [2021a], and EIP-5133 by
We now have a rigorous specification for the construc-
Stanczak et al. [2022] increased the subtrahend κ.
tion of a formal block structure. The RLP function RLP
The canonical gas limit Hl of a block of header H must
(see Appendix B) provides the canonical method for trans-
fulfil the relation:
forming this structure into a sequence of bytes ready for
transmission over the wire or storage locally.
4.3.4. Block Header Validity. We define P (BH ) to be the
P (H)H l
parent block of B, formally: (53) Hl < P (H)H l + ∧
1024
0 0
(43) P (H) ≡ B : )) = Hp
KEC(RLP(BH P (H)H l
Hl > P (H)H l − ∧
The block number is the parent’s block number incre- 1024
mented by one: Hl > 5000
(44) Hi ≡ P (H)H i + 1
The canonical difficulty of a block of header H is defined
as D(H): Hs is the timestamp (in Unix’s time()) of block H and
(45) must fulfil the relation:
( 34
2 if Hi = 0
D(H) ≡
max Dmin , P (H)H d + x × ς2 + otherwise
(54) Hs > P (H)H s
where:
(46) Dmin ≡ 217
P (H)H d This mechanism enforces a homeostasis in terms of the
(47) x≡
2048 time between blocks; a smaller period between the last two
Hs − P (H)H s
blocks results in an increase in the difficulty level and thus
(48) ς2 ≡ max y − , −99
9 additional computation required, lengthening the likely
( next period. Conversely, if the period is too large, the
1 if kP (H)U k = 0
(49) y≡ difficulty, and expected time to the next block, is reduced.
2 otherwise The nonce, Hn , must satisfy the relations:
0
j k
(50) ≡ 2bHi ÷100000c−2
(51) Hi0 ≡ max(Hi − κ, 0)
2256
(52) (55) n6 ∧ m = Hm
Hd
3000000 if FByzantium 6 Hi < FConstantinople
5000000 if FConstantinople 6 Hi < FMuirGlacier
9000000 if FMuirGlacier 6 Hi < FLondon with (n, m) = PoW(Hn , Hn , d).
κ≡
9700000
if FLondon 6 Hi < FArrowGlacier Where Hn is the new block’s header H, but without the
nonce and mix-hash components, d being the current DAG,
10700000 if FArrowGlacier 6 Hi < FGrayGlacier
a large data set needed to compute the mix-hash, and PoW
11400000 if Hi > FGrayGlacier
is the proof-of-work function (see section 11.5): this evalu-
The Homestead difficulty parameter, ς2 , is used to affect ates to an array with the first item being the mix-hash, to
a dynamic homeostasis of time between blocks, as the time prove that a correct DAG has been used, and the second
between blocks varies, as discussed below, as implemented item being a pseudo-random number cryptographically
in EIP-2 by Buterin [2015]. In the Homestead release, dependent on H and d. Given an approximately uniform
the exponential difficulty symbol, causes the difficulty to distribution in the range [0, 264 ), the expected time to find
slowly increase (every 100,000 blocks) at an exponential a solution is proportional to the difficulty, Hd .
rate, and thus increasing the block time difference, and This is the foundation of the security of the blockchain
putting time pressure on transitioning to proof-of-stake. and is the fundamental reason why a malicious node can-
This effect, known as the “difficulty bomb”, or “ice age”, not propagate newly created blocks that would otherwise
was explained in EIP-649 by Schoedon and Buterin [2017] overwrite (“rewrite”) history. Because the nonce must sat-
and delayed and implemented earlier in EIP-2. ς2 was also isfy this requirement, and because its satisfaction depends
modified in EIP-100 with the use of x, the adjustment on the contents of the block and in turn its composed
factor above, and the denominator 9, in order to target transactions, creating new, valid, blocks is difficult and,
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 8
over time, requires approximately the total compute power 6. Transaction Execution
of the trustworthy portion of the mining peers.
The execution of a transaction is the most complex part
Thus we are able to define the block header validity
of the Ethereum protocol: it defines the state transition
function V (H):
function Υ. It is assumed that any transactions executed
2256 first pass the initial tests of intrinsic validity. These include:
(56) V (H) ≡ n6 ∧ m = Hm ∧
Hd
(1) The transaction is well-formed RLP, with no addi-
Hd = D(H) ∧
tional trailing bytes;
Hg ≤ Hl ∧ (2) the transaction signature is valid;
P (H)H l (3) the transaction nonce is valid (equivalent to the
Hl < P (H)H l + ∧
1024 sender account’s current nonce);
P (H)H l
(4) the sender account has no contract code deployed
Hl > P (H)H l − ∧ (see EIP-3607 by Feist et al. [2021]);
1024
(5) the gas limit is no smaller than the intrinsic gas,
Hl > 5000 ∧
g0 , used by the transaction; and
Hs > P (H)H s ∧ (6) the sender account balance contains at least the
Hi = P (H)H i + 1 ∧ cost, v0 , required in up-front payment.
kHx k ≤ 32 Formally, we consider the function Υ, with T being a
where (n, m) = PoW(Hn , Hn , d) transaction and σ the state:
Noting additionally that extraData must be at most
32 bytes. (57) σ 0 = Υ(σ, T )
6.2. Execution. We define intrinsic gas g0 , the amount of accrued substate A and status code z:
gas this transaction requires to be paid prior to execution, (66)
as follows: Λ4 (σ 0 , A∗ , S(T ), S(T ), g,
T , T , T , 0, ∅, >)
p v i if Tt = ∅
(60) (σ P , g 0 , A, z) ≡ ∗
(
Θ4 (σ 0 , A , S(T ), S(T ), Tt ,
X Gtxdatazero if i = 0
Tt , g, Tp , Tv , Tv , Td , 0, >) otherwise
g0 ≡
i∈Ti ,Td
Gtxdatanonzero otherwise
( where
Gtxcreate if Tt = ∅
+ (67) A∗ ≡ A0 except
0 otherwise
+ Gtransaction (68) A∗a ≡ A0a
∪ {S(T )} ∪E∈TA {E a }
[
A∗K
kTA k−1
X (69) ≡ ∀i < kEs k, i ∈ N : (Ea , Es [i])
+ Gaccesslistaddress + kTA [j]s kGaccessliststorage E∈TA
j=0
and g is the amount of gas remaining after deducting
where Ti , Td means the series of bytes of the transaction’s the basic amount required to pay for the existence of the
associated data and initialisation EVM-code, depending on transaction:
whether the transaction is for contract-creation or message- (70) g ≡ Tg − g0
call. Gtxcreate is added if the transaction is contract-
creating, but not if a result of EVM-code. Gaccesslistaddress Note we use Θ4 and Λ4 to denote the fact that only the
and Gaccessliststorage are the costs of warming up account first four components of the functions’ values are taken;
and storage access, respectively. G is fully defined in Ap- the final represents the message-call’s output value (a byte
pendix G. array) and is unused in the context of transaction evalua-
The up-front cost v0 is calculated as: tion.
After the message call or contract creation is processed,
(61) v0 ≡ Tg Tp + Tv the refund counter has to be incremented for the accounts
that were self-destructed throughout its invocation.
The validity is determined as: X
(71) A0r ≡ Ar + Rselfdestruct
i∈As
(62) S(T ) 6= ∅ ∧
σ[S(T )]c = KEC () ∧ Then the state is finalised by determining the amount
Tn = σ[S(T )]n ∧ to be refunded, g ∗ from the remaining gas, g 0 , plus some
g0 6 Tg ∧ allowance from the refund counter, to the sender at the
v0 6 σ[S(T )]b ∧ original rate.
Tg 6 BHl − `(BR )u j
Tg − g 0 k 0
(72) g ∗ ≡ g 0 + min , Ar
2
Note the final condition; the sum of the transaction’s gas
limit, Tg , and the gas utilised in this block prior, given by The total refundable amount is the legitimately remain-
`(BR )u , must be no greater than the block’s gasLimit, ing gas g 0 , added to Ar , with the latter component being
BHl . Also, with a slight abuse of notation, we assume that capped up to a maximum of half (rounded down) of the
total amount used Tg − g 0 . Therefore, g ∗ is the total gas
σ[S(T )]c = KEC () , σ[S(T )]n = 0, and σ[S(T )]b = 0 if
σ[S(T )] = ∅. that remains after the transaction has been executed.
The execution of a valid transaction begins with an The Ether for the gas is given to the miner, whose
irrevocable change made to the state: the nonce of the address is specified as the beneficiary of the present block
account of the sender, S(T ), is incremented by one and the B. So we define the pre-final state σ ∗ in terms of the
balance is reduced by part of the up-front cost, Tg Tp . The provisional state σ P :
gas available for the proceeding computation, g, is defined
(73) σ∗ ≡ σP except
as Tg − g0 . The computation, whether contract creation ∗
or a message call, results in an eventual state (which may (74) σ [S(T )]b ≡ σ P [S(T )]b + g ∗ Tp
∗
legally be equivalent to the current state), the change to (75) σ [m]b ≡ σ P [m]b + (Tg − g ∗ )Tp
which is deterministic and never invalid: there can be no (76) m ≡ BHc
invalid transactions from this point.
We define the checkpoint state σ 0 : The final state, σ 0 , is reached after deleting all accounts
that either appear in the self-destruct set or are touched
(63) σ0 ≡ σ except: and empty:
(64) σ 0 [S(T )]b ≡ σ[S(T )]b − Tg Tp (77) σ0 ≡ σ∗ except
(65) σ 0 [S(T )]n ≡ σ[S(T )]n + 1 (78) ∀i ∈ As : σ [i] 0
= ∅
(79) ∀i ∈ At : σ 0 [i] = ∅ if DEAD(σ ∗, i)
Evaluating σ P from σ 0 depends on the transaction type;
either contract creation or message call; we define the tuple And finally, we specify Υg , the total gas used in this
of post-execution provisional state σ P , remaining gas g 0 , transaction Υl , the logs created by this transaction and
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 10
These are used to help define the transaction receipt where v 0 is the account’s pre-existing value, in the event
and are also used later for state and nonce validation. it was previously in existence:
(
0 0 if σ[a] = ∅
7. Contract Creation (93) v ≡
σ[a]b otherwise
There are a number of intrinsic parameters used when
Finally, the account is initialised through the execution
creating an account: sender (s), original transactor4 (o),
of the initialising EVM code i according to the execution
available gas (g), gas price (p), endowment (v) together
model (see section 9). Code execution can effect several
with an arbitrary length byte array, i, the initialisation
events that are not internal to the execution state: the
EVM code, the present depth of the message-call/contract-
account’s storage can be altered, further accounts can be
creation stack (e), the salt for new account’s address (ζ)
created and further message calls can be made. As such,
and finally the permission to make modifications to the
the code execution function Ξ evaluates to a tuple of the
state (w). The salt ζ might be missing (ζ = ∅); formally,
resultant state σ ∗∗ , available gas remaining g ∗∗ , the re-
(83) ζ ∈ B32 ∪ B0 sultant accrued substate A∗∗ and the body code of the
account o.
If the creation was caused by CREATE2, then ζ 6= ∅.
We define the creation function formally as the function
Λ, which evaluates from these values, together with the (94) (σ ∗∗ , g ∗∗ , A∗∗ , o) ≡ Ξ(σ ∗ , g, A∗ , I)
state σ and the accrued substate A, to the tuple containing
where I contains the parameters of the execution environ-
the new state, remaining gas, new accrued substate, status
ment, that is:
code and output (σ 0 , g 0 , A0 , z, o):
(95) Ia ≡ a
(84) (σ 0 , g 0 , A0 , z, o) ≡ Λ(σ, A, s, o, g, p, v, i, e, ζ, w)
(96) Io ≡ o
The address of the new account is defined as being the (97) Ip ≡ p
rightmost 160 bits of the Keccak-256 hash of the RLP
encoding of the structure containing only the sender and (98) Id ≡ ()
the account nonce. For CREATE2 the rule is different and (99) Is ≡ s
is described in EIP-1014 by Buterin [2018]. Combining (100) Iv ≡ v
the two cases, we define the resultant address for the new (101) Ib ≡ i
account a:
(102) Ie ≡ e
(85) a ≡ ADDR(s, σ[s]n − 1, ζ, i) (103) Iw ≡ w
(86) ADDR(s, n, ζ, i) ≡ B96..255 KEC LA (s, n, ζ, i) Id evaluates to the empty tuple as there is no input data
( to this call. IH has no special treatment and is determined
RLP (s, n) if ζ = ∅
(87) LA (s, n, ζ, i) ≡ from the blockchain.
(255) · s · ζ · KEC(i) otherwise Code execution depletes gas, and gas may not go below
where · is the concatenation of byte arrays, Ba..b (X) evalu- zero, thus execution may exit before the code has come
ates to a binary value containing the bits of indices in the to a natural halting state. In this (and several other) ex-
range [a, b] of the binary data X, and σ[x] is the address ceptional cases we say an out-of-gas (OOG) exception has
state of x, or ∅ if none exists. Note we use one fewer than occurred: The evaluated state is defined as being the empty
the sender’s nonce value; we assert that we have incre- set, ∅, and the entire create operation should have no effect
mented the sender account’s nonce prior to this call, and on the state, effectively leaving it as it was immediately
so the value used is the sender’s nonce at the beginning of prior to attempting the creation.
the responsible transaction or VM operation. If the initialization code completes successfully, a final
The address of the new account is added to the set of contract-creation cost is paid, the code-deposit cost, c,
accessed accounts: proportional to the size of the created contract’s code:
7.1. Subtleties. Note that while the initialisation code (117) a01 ≡ (σ[r]n , σ[r]b + v, σ[r]s , σ[r]c )
is executing, the newly created address exists but with
no intrinsic body code5. Thus any message call received The account’s associated code (identified as the frag-
by it during this time causes no code to be executed. If ment whose Keccak-256 hash is σ[c]c ) is executed according
the initialisation execution ends with a SELFDESTRUCT to the execution model (see section 9). Just as with con-
instruction, the matter is moot since the account will be tract creation, if the execution halts in an exceptional
deleted before the transaction is completed. For a normal fashion (i.e. due to an exhausted gas supply, stack under-
STOP code, or if the code returned is otherwise empty, then flow, invalid jump destination or invalid instruction), then
the state is left with a zombie account, and any remaining no gas is refunded to the caller and the state is reverted to
balance will be locked into the account forever. the point immediately prior to balance transfer (i.e. σ).
5During initialization code execution, EXTCODESIZE on the address should return zero, which is the length of the code of the account while
CODESIZE should return the length of the initialization code (as defined in H.2).
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 12
9.4.2. Exceptional Halting. The exceptional halting func- 9.4.4. Normal Halting. The normal halting function H is
tion Z is defined as: defined:
(149) (154)
Z(σ, µ, A, I) ≡ µg < C(σ, µ, A, I) ∨ HRETURN (µ) if w ∈ {RETURN, REVERT}
δw = ∅ ∨ H(µ, I) ≡ () if w ∈ {STOP, SELFDESTRUCT}
kµs k < δw ∨
otherwise
∅
(w = JUMP ∧ µs [0] ∈ / D(Ib )) ∨
(w = JUMPI ∧ µs [1] 6= 0 ∧ The data-returning halt operations, RETURN and
µs [0] ∈
/ D(Ib )) ∨ REVERT, have a special function HRETURN . Note also
(w = RETURNDATACOPY ∧ the difference between the empty sequence and the empty
µs [1] + µs [2] > kµo k) ∨ set as discussed here.
kµs k − δw + αw > 1024 ∨
(¬Iw ∧ W (w, µ)) ∨
9.5. The Execution Cycle. Stack items are added or
(w = SSTORE ∧ µg 6 Gcallstipend )
removed from the left-most, lower-indexed portion of the
where series; all other items remain unchanged:
≡ (σ 0 , µ0 , A0 , I)
(155) O (σ, µ, A, I)
(150) W (w, µ) ≡ w ∈ {CREATE, CREATE2, SSTORE,
SELFDESTRUCT} ∨
(156) ∆ ≡ αw − δw
LOG0 ≤ w ∧ w ≤ LOG4 ∨ (157) kµ0s k ≡ kµs k + ∆
w = CALL ∧ µs [2] 6= 0 (158) ∀x ∈ [αw , kµ0s k) : µ0s [x] ≡ µs [x − ∆]
This states that the execution is in an exceptional halt- The gas is reduced by the instruction’s gas cost and
ing state if there is insufficient gas, if the instruction is for most instructions, the program counter increments on
invalid (and therefore its δ subscript is undefined), if there each cycle, for the three exceptions, we assume a function
are insufficient stack items, if a JUMP/JUMPI destination J, subscripted by one of two instructions, which evaluates
is invalid, the new stack size would be larger than 1024 or to the according value:
state modification is attempted during a static call. The
astute reader will realise that this implies that no instruc- (159) µ0g ≡ µg − C(σ, µ, A, I)
tion can, through its execution, cause an exceptional halt. JJUMP (µ) if w = JUMP
Also, the execution is in an exceptional halting state if the (160) µ0pc ≡ JJUMPI (µ) if w = JUMPI
gas left prior to executing an SSTORE instruction is less
N (µpc , w) otherwise
than or equal to the call stipend Gcallstipend – see EIP-2200
by Tang [2019] for more information. In general, we assume the memory, accrued substate
and system state do not change:
9.4.3. Jump Destination Validity. We previously used D (161) µ0m ≡ µm
as the function to determine the set of valid jump desti-
nations given the code that is being run. We define this (162) µ0i ≡ µi
0
as any position in the code occupied by a JUMPDEST (163) A ≡ A
instruction. (164) σ0 ≡ σ
All such positions must be on valid instruction bound-
aries, rather than sitting in the data portion of PUSH However, instructions do typically alter one or several
operations and must appear within the explicitly defined components of these values. Altered components listed by
portion of the code (rather than in the implicitly defined instruction are noted in Appendix H, alongside values for
STOP operations that trail it). α and δ and a formal description of the gas requirements.
Formally:
Thus we define the total difficulty of block B recursively If there are collisions of the beneficiary addresses be-
as: tween ommers and the block (i.e. two ommers with the
(165) Bt ≡ Bt0 + Bd same beneficiary address or an ommer with the same bene-
0 ficiary address as the present block), additions are applied
(166) B ≡ P (BH ) cumulatively.
As such given a block B, Bt is its total difficulty, B 0 is We define the block reward in Wei:
its parent block and Bd is its difficulty. (176)
5 if Hi < FByzantium
11. Block Finalisation Rblock = 1018 × 3 if FByzantium 6 Hi < FConstantinople
The process of finalising a block involves four stages:
2 if Hi > FConstantinople
(1) Validate (or, if mining, determine) ommers;
(2) validate (or, if mining, determine) transactions; 11.4. State & Nonce Validation. We may now define
(3) apply rewards; the function, Γ, that maps a block B to its initiation state:
(4) verify (or, if mining, compute a valid) state and (177) (
block nonce. σ0 if P (BH ) = ∅
Γ(B) ≡
σ i : TRIE(LS (σ i )) = P (BH )H r otherwise
11.1. Ommer Validation. The validation of ommer
headers means nothing more than verifying that each om- Here, TRIE(LS (σ i )) means the hash of the root node of
mer header is both a valid header and satisfies the relation a trie of state σ i ; it is assumed that implementations will
of N th-generation ommer to the present block where N ≤ 6. store this in the state database, which is trivial and efficient
The maximum of ommer headers is two. Formally: since the trie is by nature an immutable data structure.
^ And finally we define Φ, the block transition function,
(167) kBU k 6 2 V (U) ∧ k(U, P (BH )H , 6)
which maps an incomplete block B to a complete block
U∈BU
B0:
where k denotes the “is-kin” property:
(168) (178) Φ(B) ≡ B0 : B0 = B∗ except:
2256
false
if n=0 (179) Bn0 = n: x6
k(U, H, n) ≡ s(U, H) Hd
0 ∗
∨ k(U, P (H)H , n − 1) otherwise (180) Bm = m with (x, m) = PoW(Bn , n, d)
∗
(181) B ≡ B except: Br∗ = r(Π(Γ(B), B))
and s denotes the “is-sibling” property:
(169) With d being a dataset as specified in Appendix J.
s(U, H) ≡ (P (H) = P (U ) ∧ H 6= U ∧ U ∈ / B(H)U ) As specified at the beginning of the present work, Π is
the state-transition function, which is defined in terms of
where B(H) and P (H) are the block and the parent block
Ω, the block finalisation function and Υ, the transaction-
of the corresponding header H respectively.
evaluation function, both now well-defined.
11.2. Transaction Validation. The given gasUsed As previously detailed, R[n]z , R[n]l and R[n]u are the
must correspond faithfully to the transactions listed: BHg , nth corresponding status code, logs and cumulative gas
the total gas used in the block, must be equal to the used after each transaction (R[n]b , the fourth component
accumulated gas used according to the final transaction: in the tuple, has already been defined in terms of the logs).
We also define the nth state σ[n], which is defined simply
(170) BHg = `(R)u
as the state resulting from applying the corresponding
11.3. Reward Application. The application of rewards transaction to the state resulting from the previous trans-
to a block involves raising the balance of the accounts of action (or the block’s initial state in the case of the first
the beneficiary address of the block and each ommer by a such transaction):
certain amount. We raise the block’s beneficiary account (
Γ(B) if n < 0
by Rblock ; for each ommer, we raise the block’s beneficiary (182) σ[n] =
by an additional 32 1
of the block reward and the benefi- Υ(σ[n − 1], BT [n]) otherwise
ciary of the ommer gets rewarded depending on the block In the case of BR [n]u , we take a similar approach defin-
number. Formally we define the function Ω: ing each item as the gas used in evaluating the correspond-
(171) ing transaction summed with the previous item (or zero,
Ω(B, σ) ≡ σ 0 : σ 0 = σ except: if it is the first), giving us a running total:
kBU k 0 if n < 0
(172) σ 0 [BHc ]b = σ[BHc ]b + 1 + Rblock
32 (183) R[n]u = g
Υ (σ[n − 1], BT [n])
(173)
+R[n − 1]u otherwise
∀U ∈ BU :
( For R[n]l , we utilise the Υl function that we conve-
∅ if σ[Uc ] = ∅ ∧ R = 0 niently defined in the transaction execution function.
σ 0 [Uc ] =
a0 otherwise
(184) R[n]l = Υl (σ[n − 1], BT [n])
0
(174) a ≡ (σ[Uc ]n , σ[Uc ]b + R, σ[Uc ]s , σ[Uc ]c )
We define R[n]z in a similar manner.
1
(175) R ≡ 1 + (Ui − BHi ) Rblock
8 (185) R[n]z = Υz (σ[n − 1], BT [n])
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 16
Finally, we define Π as the new state given the block re- block difficulty from section 10). PoW is the proof-of-work
ward function Ω applied to the final transaction’s resultant function which evaluates to an array with the first item
state, `(σ): being the mixHash and the second item being a pseudo-
(186) Π(σ, B) ≡ Ω(B, `(σ)) random number cryptographically dependent on H and d.
The underlying algorithm is called Ethash and is described
Thus the complete block-transition mechanism is de- below.
fined, except for PoW, the proof-of-work function.
11.5.1. Ethash. Ethash is the PoW algorithm for Ethereum
11.5. Mining Proof-of-Work. The mining proof-of- 1.0. It is the latest version of Dagger-Hashimoto, intro-
work (PoW) exists as a cryptographically secure nonce duced by Buterin [2013b] and Dryja [2014], although it
that proves beyond reasonable doubt that a particular can no longer appropriately be called that since many of
amount of computation has been expended in the deter- the original features of both algorithms were drastically
mination of some token value n. It is utilised to enforce changed with R&D from February 2015 until May 4 2015
the blockchain security by giving meaning and credence (Jentzsch [2015]). The general route that the algorithm
to the notion of difficulty (and, by extension, total dif- takes is as follows:
ficulty). However, since mining new blocks comes with There exists a seed which can be computed for each
an attached reward, the proof-of-work not only functions block by scanning through the block headers up until that
as a method of securing confidence that the blockchain point. From the seed, one can compute a pseudorandom
will remain canonical into the future, but also as a wealth cache, Jcacheinit bytes in initial size. Light clients store
distribution mechanism. the cache. From the cache, we can generate a dataset,
For both reasons, there are two important goals of the Jdatasetinit bytes in initial size, with the property that each
proof-of-work function; firstly, it should be as accessible as item in the dataset depends on only a small number of
possible to as many people as possible. The requirement items from the cache. Full clients and miners store the
of, or reward from, specialised and uncommon hardware dataset. The dataset grows linearly with time.
should be minimised. This makes the distribution model Mining involves grabbing random slices of the dataset
as open as possible, and, ideally, makes the act of mining a and hashing them together. Verification can be done with
simple swap from electricity to Ether at roughly the same low memory by using the cache to regenerate the specific
rate for anyone around the world. pieces of the dataset that you need, so you only need to
Secondly, it should not be possible to make super-linear store the cache. The large dataset is updated once every
profits, and especially not so with a high initial barrier. Jepoch blocks, so the vast majority of a miner’s effort will
Such a mechanism allows a well-funded adversary to gain be reading the dataset, not making changes to it. The
a troublesome amount of the network’s total mining power mentioned parameters as well as the algorithm is explained
and as such gives them a super-linear reward (thus skewing in detail in Appendix J.
distribution in their favour) as well as reducing the network
security. 12. Implementing Contracts
One plague of the Bitcoin world is ASICs. These are
specialised pieces of compute hardware that exist only to There are several patterns of contracts engineering that
do a single task (Smith [1997]). In Bitcoin’s case the task is allow particular useful behaviours; two of these that we
the SHA256 hash function (Courtois et al. [2014]). While will briefly discuss are data feeds and random numbers.
ASICs exist for a proof-of-work function, both goals are
12.1. Data Feeds. A data feed contract is one which pro-
placed in jeopardy. Because of this, a proof-of-work func-
vides a single service: it gives access to information from
tion that is ASIC-resistant (i.e. difficult or economically
the external world within Ethereum. The accuracy and
inefficient to implement in specialised compute hardware)
timeliness of this information is not guaranteed and it is
has been identified as the proverbial silver bullet.
the task of a secondary contract author—the contract that
Two directions exist for ASIC resistance; firstly make
utilises the data feed—to determine how much trust can
it sequential memory-hard, i.e. engineer the function such
be placed in any single data feed.
that the determination of the nonce requires a lot of mem-
The general pattern involves a single contract within
ory and bandwidth such that the memory cannot be used
Ethereum which, when given a message call, replies with
in parallel to discover multiple nonces simultaneously. The
some timely information concerning an external phenome-
second is to make the type of computation it would need to
non. An example might be the local temperature of New
do general-purpose; the meaning of “specialised hardware”
York City. This would be implemented as a contract that
for a general-purpose task set is, naturally, general purpose
returned that value of some known point in storage. Of
hardware and as such commodity desktop computers are
course this point in storage must be maintained with the
likely to be pretty close to “specialised hardware” for the
correct such temperature, and thus the second part of the
task. For Ethereum 1.0 we have chosen the first path.
pattern would be for an external server to run an Ethereum
More formally, the proof-of-work function takes the
node, and immediately on discovery of a new block, creates
form of PoW:
a new valid transaction, sent to the contract, updating said
(187)
value in storage. The contract’s code would accept such
2256
m = Hm ∧ n 6 with (m, n) = PoW(Hn , Hn , d) updates only from the identity contained on said server.
Hd
Where Hn is the new block’s header but without the 12.2. Random Numbers. Providing random numbers
nonce and mix-hash components; Hn is the nonce of the within a deterministic system is, naturally, an impossible
header; d is a large data set needed to compute the mix- task. However, we can approximate with pseudo-random
Hash and Hd is the new block’s difficulty value (i.e. the numbers by utilising data which is generally unknowable
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 17
at the time of transacting. Such data might include the 15. Acknowledgements
block’s hash, the block’s timestamp and the block’s benefi-
Many thanks to Aeron Buchanan for authoring the
ciary address. In order to make it hard for malicious miners
Homestead revisions, Christoph Jentzsch for authoring the
to control those values, one should use the BLOCKHASH
Ethash algorithm and Yoichi Hirai for doing most of the
operation in order to use hashes of the previous 256 blocks
EIP-150 changes. Important maintenance, useful correc-
as pseudo-random numbers. For a series of such numbers,
tions and suggestions were provided by a number of others
a trivial solution would be to add some constant amount
from the Ethereum DEV organisation and Ethereum com-
and hashing the result.
munity at large including Gustav Simonsson, Pawel Bylica,
Jutta Steiner, Nick Savers, Viktor Trón, Marko Simovic,
13. Future Directions Giacomo Tazzari and, of course, Vitalik Buterin.
The state database won’t be forced to maintain all past
state trie structures into the future. It should maintain 16. Availability
an age for each node and eventually discard nodes that The source of this paper is maintained at https:
are neither recent enough nor checkpoints. Checkpoints, //github.com/ethereum/yellowpaper/. An auto-
or a set of nodes in the database that allow a particular generated PDF is located at https://ethereum.github.
block’s state trie to be traversed, could be used to place a io/yellowpaper/paper.pdf.
maximum limit on the amount of computation needed in
order to retrieve any state throughout the blockchain. References
Blockchain consolidation could be used in order to re-
duce the amount of blocks a client would need to download Jacob Aron. BitCoin software finds new life. New Scientist,
to act as a full, mining, node. A compressed archive of the 213(2847):20, 2012. URL http://www.sciencedirect.
trie structure at given points in time (perhaps one in every com/science/article/pii/S0262407912601055.
10,000th block) could be maintained by the peer network, Adam Back. Hashcash - Amortizable Publicly Auditable
effectively recasting the genesis block. This would reduce Cost-Functions, 2002. URL http://www.hashcash.org/
the amount to be downloaded to a single archive plus a papers/amortizable.pdf.
hard maximum limit of blocks. Tim Beiko, James Hancock, and Thomas Jay Rush. EIP-
Finally, blockchain compression could perhaps be con- 4345: Difficulty bomb delay to June 2022, October 2021a.
ducted: nodes in state trie that haven’t sent/received a URL https://eips.ethereum.org/EIPS/eip-4345.
transaction in some constant amount of blocks could be Tim Beiko et al. Berlin network upgrade specifica-
thrown out, reducing both Ether-leakage and the growth tion, 2021b. URL https://github.com/ethereum/
of the state database. eth1.0-specs/blob/master/network-upgrades/
mainnet-upgrades/berlin.md.
13.1. Scalability. Scalability remains an eternal concern. Guido Bertoni, Joan Daemen, Michal Peeters, and
With a generalised state transition function, it becomes dif- Gilles Van Assche. The KECCAK SHA-3 sub-
ficult to partition and parallelise transactions to apply the mission, 2011. URL https://keccak.team/files/
divide-and-conquer strategy. Unaddressed, the dynamic Keccak-submission-3.pdf.
value-range of the system remains essentially fixed and as Roman Boutellier and Mareike Heinzen. Pirates, Pio-
the average transaction value increases, the less valuable of neers, Innovators and Imitators. In Growth Through
them become ignored, being economically pointless to in- Innovation, pages 85–96. Springer, 2014. URL https:
clude in the main ledger. However, several strategies exist //www.springer.com/gb/book/9783319040158.
that may potentially be exploited to provide a considerably Vitalik Buterin. Ethereum: A Next-Generation Smart
more scalable protocol. Contract and Decentralized Application Platform,
Some form of hierarchical structure, achieved by either 2013a. URL https://github.com/ethereum/wiki/
consolidating smaller lighter-weight chains into the main wiki/White-Paper.
block or building the main block through the incremen- Vitalik Buterin. Dagger: A Memory-Hard to Compute,
tal combination and adhesion (through proof-of-work) of Memory-Easy to Verify Scrypt Alternative, 2013b. URL
smaller transaction sets may allow parallelisation of trans- http://www.hashcash.org/papers/dagger.html.
action combination and block-building. Parallelism could Vitalik Buterin. EIP-2: Homestead hard-fork changes,
also come from a prioritised set of parallel blockchains, 2015. URL https://eips.ethereum.org/EIPS/eip-2.
consolidating each block and with duplicate or invalid Vitalik Buterin. EIP-100: Change difficulty adjustment
transactions thrown out accordingly. to target mean block time including uncles, April 2016a.
Finally, verifiable computation, if made generally avail- URL https://eips.ethereum.org/EIPS/eip-100.
able and efficient enough, may provide a route to allow the Vitalik Buterin. EIP-155: Simple replay attack protec-
proof-of-work to be the verification of final state. tion, October 2016b. URL https://eips.ethereum.
org/EIPS/eip-155.
Vitalik Buterin. EIP-1014: Skinny CREATE2, April 2018.
14. Conclusion
URL https://eips.ethereum.org/EIPS/eip-1014.
We have introduced, discussed and formally defined the Vitalik Buterin and Martin Swende. EIP-2929: Gas cost in-
protocol of Ethereum. Through this protocol the reader creases for state access opcodes, September 2020a. URL
may implement a node on the Ethereum network and join https://eips.ethereum.org/EIPS/eip-2929.
others in a decentralised secure social operating system. Vitalik Buterin and Martin Swende. EIP-2930: Optional ac-
Contracts may be authored in order to algorithmically cess lists, August 2020b. URL https://eips.ethereum.
specify and autonomously enforce rules of interaction. org/EIPS/eip-2930.
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 18
Appendix A. Terminology
External Actor: A person or other entity able to interface to an Ethereum node, but external to the world of
Ethereum. It can interact with Ethereum through depositing signed Transactions and inspecting the blockchain
and associated state. Has one (or more) intrinsic Accounts.
Address: A 160-bit code used for identifying Accounts.
Account: Accounts have an intrinsic balance and transaction count maintained as part of the Ethereum state.
They also have some (possibly empty) EVM Code and a (possibly empty) Storage State associated with them.
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 19
Though homogenous, it makes sense to distinguish between two practical types of account: those with empty
associated EVM Code (thus the account balance is controlled, if at all, by some external entity) and those with
non-empty associated EVM Code (thus the account represents an Autonomous Object). Each Account has a
single Address that identifies it.
Transaction: A piece of data, signed by an External Actor. It represents either a Message or a new Autonomous
Object. Transactions are recorded into each block of the blockchain.
Autonomous Object: A notional object existent only within the hypothetical state of Ethereum. Has an intrinsic
address and thus an associated account; the account will have non-empty associated EVM Code. Incorporated
only as the Storage State of that account.
Storage State: The information particular to a given Account that is maintained between the times that the
Account’s associated EVM Code runs.
Message: Data (as a set of bytes) and Value (specified as Ether) that is passed between two Accounts, either
through the deterministic operation of an Autonomous Object or the cryptographically secure signature of the
Transaction.
Message Call: The act of passing a message from one Account to another. If the destination account is associated
with non-empty EVM Code, then the VM will be started with the state of said Object and the Message acted
upon. If the message sender is an Autonomous Object, then the Call passes any data returned from the VM
operation.
Gas: The fundamental network cost unit. Paid for exclusively by Ether (as of PoC-4), which is converted freely to
and from Gas as required. Gas does not exist outside of the internal Ethereum computation engine; its price is
set by the Transaction and miners are free to ignore Transactions whose Gas price is too low.
Contract: Informal term used to mean both a piece of EVM Code that may be associated with an Account or an
Autonomous Object.
Object: Synonym for Autonomous Object.
App: An end-user-visible application hosted in the Ethereum Browser.
Ethereum Browser: (aka Ethereum Reference Client) A cross-platform GUI of an interface similar to a simplified
browser (a la Chrome) that is able to host sandboxed applications whose backend is purely on the Ethereum
protocol.
Ethereum Virtual Machine: (aka EVM) The virtual machine that forms the key part of the execution model
for an Account’s associated EVM Code.
Ethereum Runtime Environment: (aka ERE) The environment which is provided to an Autonomous Object
executing in the EVM. Includes the EVM but also the structure of the world state on which the EVM relies for
certain I/O instructions including CALL & CREATE.
EVM Code: The bytecode that the EVM can natively execute. Used to formally specify the meaning and
ramifications of a message to an Account.
EVM Assembly: The human-readable form of EVM-code.
LLL: The Lisp-like Low-level Language, a human-writable language used for authoring simple contracts and general
low-level language toolkit for trans-compiling to.
If the value to be serialised is a byte array, the RLP serialisation takes one of three forms:
• If the byte array contains solely a single byte and that single byte is less than 128, then the input is exactly equal
to the output.
• If the byte array contains fewer than 56 bytes, then the output is equal to the input prefixed by the byte equal to
the length of the byte array plus 128.
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 20
• Otherwise, the output is equal to the input, provided that it contains fewer than 264 bytes, prefixed by the
minimal-length byte array which when interpreted as a big-endian integer is equal to the length of the input byte
array, which is itself prefixed by the number of bytes required to faithfully encode this length value plus 183.
Byte arrays containing 264 or more bytes cannot be encoded. This restriction ensures that the first byte of the encoding
of a byte array is always below 192, and thus it can be readily distinguished from the encodings of sequences in L.
Formally, we define Rb :
x if kxk = 1 ∧ x[0] < 128
(128 + kxk) · x else if kxk < 56
(192) Rb (x) ≡
183 +
BE(kxk)
· BE(kxk) · x else if kxk < 264
∅ otherwise
kbk−1
X
(193) BE(x) ≡ (b0 , b1 , ...) : b0 6= 0 ∧ x = bn · 256kbk−1−n
n=0
(194) (x1 , ..., xn ) · (y1 , ..., ym ) = (x1 , ..., xn , y1 , ..., ym )
Thus BE is the function that expands a non-negative integer value to a big-endian byte array of minimal length and
the dot operator performs sequence concatenation.
If instead, the value to be serialised is a sequence of other items then the RLP serialisation takes one of two forms:
• If the concatenated serialisations of each contained item is less than 56 bytes in length, then the output is equal
to that concatenation prefixed by the byte equal to the length of this byte array plus 192.
• Otherwise, the output is equal to the concatenated serialisations, provided that they contain fewer than 264 bytes,
prefixed by the minimal-length byte array which when interpreted as a big-endian integer is equal to the length
of the concatenated serialisations byte array, which is itself prefixed by the number of bytes required to faithfully
encode this length value plus 247.
Sequences whose concatenated serialized items contain 264 or more bytes cannot be encoded. This restriction ensures
that the first byte of the encoding does not exceed 255 (otherwise it would not be a byte).
Thus we finish by formally defining Rl :
(192 + ks(x)k)
· s(x)
if s(x) 6= ∅ ∧ ks(x)k < 56
(195) Rl (x) ≡ 247 + BE(ks(x)k) · BE(ks(x)k) · s(x) else if s(x) 6= ∅ ∧ ks(x)k < 264
otherwise
∅
(
RLP(x[0]) · RLP(x[1]) · ... if ∀i : RLP(x[i]) 6= ∅
(196) s(x) ≡
∅ otherwise
If RLP is used to encode a scalar, defined only as a non-negative integer (in N, or in Nx for any x), it must be encoded
as the shortest byte array whose big-endian interpretation is the scalar. Thus the RLP of some non-negative integer i is
defined as:
(197) RLP(i : i ∈ N) ≡ RLP(BE(i))
When interpreting RLP data, if an expected fragment is decoded as a scalar and leading zeroes are found in the byte
sequence, clients are required to consider it non-canonical and treat it in the same manner as otherwise invalid RLP data,
dismissing it completely.
There is no specific canonical encoding format for signed or floating-point values.
In a manner similar to a radix tree, when the trie is traversed from root to leaf, one may build a single key-value pair.
The key is accumulated through the traversal, acquiring a single nibble from each branch node (just as with a radix tree).
Unlike a radix tree, in the case of multiple keys sharing the same prefix or in the case of a single key having a unique
suffix, two optimising nodes are provided. Thus while traversing, one may potentially acquire multiple nibbles from each
of the other two node types, extension and leaf. There are three kinds of nodes in the trie:
Leaf: A two-item structure whose first item corresponds to the nibbles in the key not already accounted for by the
accumulation of keys and branches traversed from the root. The hex-prefix encoding method is used and the
second parameter to the function is required to be 1.
Extension: A two-item structure whose first item corresponds to a series of nibbles of size greater than one that
are shared by at least two distinct keys past the accumulation of the keys of nibbles and the keys of branches as
traversed from the root. The hex-prefix encoding method is used and the second parameter to the function is
required to be 0.
Branch: A 17-item structure whose first sixteen items correspond to each of the sixteen possible nibble values for
the keys at this point in their traversal. The 17th item is used in the case of this being a terminator node and
thus a key being ended at this point in its traversal.
A branch is then only used when necessary; no branch nodes may exist that contain only a single non-zero entry. We
may formally define this structure with the structural composition function c:
HP(I0 [i..(kI0 k − 1)], 1), I1 if kIk = 1 where ∃I : I ∈ I
HP(I0 [i..(j − 1)], 0), n(I, j) if i 6= j where j = max{x : ∃l : klk = x ∧ ∀I ∈ I : I0 [0..(x − 1)] = l}
(206) c(I, i) ≡ (u(0), u(1), ..., u(15), v) otherwise where u(j) ≡ n({I ( : I ∈ I ∧ I0 [i] = j}, i + 1)
I if ∃I : I ∈ I ∧ kI0 k = i
1
v =
() ∈ B otherwise
D.1. Trie Database. Thus no explicit assumptions are made concerning what data is stored and what is not, since
that is an implementation-specific consideration; we simply define the identity function mapping the key-value set I
to a 32-byte hash and assert that only a single such hash exists for any I, which though not strictly true is accurate
within acceptable precision given the Keccak hash’s collision resistance. In reality, a sensible implementation will not fully
recompute the trie root hash for each set.
A reasonable implementation will maintain a database of nodes determined from the computation of various tries or,
more formally, it will memoise the function c. This strategy uses the nature of the trie to both easily recall the contents of
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 22
any previous key-value set and to store multiple such sets in a very efficient manner. Due to the dependency relationship,
Merkle-proofs may be constructed with an O(log N ) space requirement that can demonstrate a particular leaf must exist
within a trie of a given root hash.
(211) if kok = 32 :
(212) o[0..11] = 0
(213) o[12..31] = KEC ECDSARECOVER(h, v − 27, r, s) [12..31] where:
(214) d[0..(kId k − 1)] = Id
(215) d[kId k..] = (0, 0, ...)
(216) h = d[0..31]
(217) v = d[32..63]
(218) r = d[64..95]
(219) s = d[96..127]
We define ΞSHA256 and ΞRIP160 as precompiled contracts implementing the SHA2-256 and RIPEMD-160 hash functions
respectively. Their gas usage is dependent on the input data size, a factor rounded up to the nearest number of words.
word in the input specifies the number of bytes that the third non-negative integer M occupies. These three words are
followed by B, E and M . The rest of the input is discarded. Whenever the input is too short, the missing bytes are
considered to be zero. The output is encoded big-endian into the same format as M ’s.
E.1. zkSNARK Related Precompiled Contracts. We choose two numbers, both of which are prime.
(245) p ≡ 21888242871839275222246405745257275088696311157297823662689037894645226208583
(246) q ≡ 21888242871839275222246405745257275088548364400416034343698204186575808495617
Since p is a prime number, {0, 1, . . . , p − 1} forms a field with addition and multiplication modulo p. We call this field Fp .
We define a set C1 with
(247) C1 ≡ {(X, Y ) ∈ Fp × Fp | Y 2 = X 3 + 3} ∪ {(0, 0)}
We define a binary operation + on C1 for distinct elements (X1 , Y1 ), (X2 , Y2 ) with
(
(X, Y ) if X1 6= X2
(248) (X1 , Y1 ) + (X2 , Y2 ) ≡
(0, 0) otherwise
Y2 − Y1
λ ≡
X2 − X1
X ≡ λ2 − X1 − X2
Y ≡ λ(X1 − X) − Y1
In the case where (X1 , Y1 ) = (X2 , Y2 ), we define + on C1 with
(
(X, Y ) if Y1 6= 0
(249) (X1 , Y1 ) + (X2 , Y2 ) ≡
(0, 0) otherwise
3X12
λ ≡
2Y1
X ≡ λ2 − 2X1
Y ≡ λ(X1 − X) − Y1
(C1 , +) is known to form a group. We define scalar multiplication · with
(250) n · P ≡ (0, 0) + P + · · · + P
| {z }
n
We define a binary operation + and scalar multiplication · with the same equations (248), (249) and (250). (C2 , +) is also
known to be a group. We define P2 in C2 with
(252) P2 ≡ (11559732032986387107991004021392285783925812861821192530917403151452391805634 × i
+10857046999023057135944570762232829481370756359578518086990519993285655852781,
4082367875863433681332203403145435568316851327593401208105741076214120093531 × i
+8495653923123431417604973247489272438418190587263600148770280649306958101930)
We define G2 to be the subgroup of (C2 , +) generated by P2 . G2 is known to be the only cyclic group of order q on C2 .
For a point P in G2 , we define logP2 (P ) be the smallest natural number n satisfying n · P2 = P . With this definition,
logP2 (P ) is at most q − 1.
Let GT be the multiplicative abelian group underlying Fq12 . It is known that a non-degenerate bilinear map
e : G1 × G2 → GT exists. This bilinear map is a type three pairing. There are several such bilinear maps, it does not
matter which is chosen to be e. Let PT = e(P1 , P2 ), a be a set of k points in G1 , and b be a set of k points in G2 . It
follows from the definition of a pairing that the following are equivalent
(253) logP1 (a1 ) × logP2 (b1 ) + · · · + logP1 (ak ) × logP2 (bk ) ≡ 1 mod q
k
Y
(254) e (ai , bi ) = PT
i=0
(
x if x < p
(255) δp (x) ≡
∅ otherwise
(
g1 if g1 ∈ G1
(256) δ1 (x) ≡
∅ otherwise
(
(x, y) if x 6= ∅ ∧ y 6= ∅
(257) g1 ≡
∅ otherwise
(258) x ≡ δp (x[0..31])
(259) y ≡ δp (x[32..63])
A 128 byte data x ∈ B1024 might and might not represent an element of G2 .
(
g2 if g2 ∈ G2
(260) δ2 (x) ≡
∅ otherwise
(
((x0 i + y0 ), (x1 i + y1 )) if x0 6= ∅ ∧ y0 6= ∅ ∧ x1 6= ∅ ∧ y1 6= ∅
(261) g2 ≡
∅ otherwise
(262) x0 ≡ δp (x[0..31])
(263) y0 ≡ δp (x[32..63])
(264) x1 ≡ δp (x[64..95])
(265) y1 ≡ δp (x[96..127])
We define ΞSNARKV as a precompiled contract which checks if (253) holds, for intended use in zkSNARK verification.
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 25
where r ∈ B32 , ∀i ∈ 0..7 : hi ∈ B64 , ∀i ∈ 0..15 : mi ∈ B64 , tlow ∈ B64 , thigh ∈ B64 , f ∈ B8 , BEk is the k-byte big-endian
representation—compare with(193):
k−1
X
(305) BEk (x) ≡ (b0 , b1 , ..., bk−1 ) : x = bn · 256k−1−n
n=0
where (
Ti if Tt = ∅
p ≡
Td otherwise
(
KEC(RLP(LX (T ))) if Tx = 0
(316) h(T ) ≡
KEC(Tx · RLP(LX (T ))) otherwise
The signed transaction G(T, pr ) is defined as:
(317) G(T, pr ) ≡ T except:
(318) (Ty , Tr , Ts ) = ECDSASIGN(h(T ), pr )
Reiterating from previously:
(319) Tr = r
(320) Ts = s
and Tw of legacy transcations is either 27 + Ty or 2β + 35 + Ty .
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 27
The assertion that the sender of a signed transaction equals the address of the signer should be self-evident:
H.1. Gas Cost. The general gas cost function, C, is defined as:
(324)
CSSTORE (σ, µ, A, I) if w = SSTORE
= EXP ∧ µs [1] = 0
G
exp
if w
Gexp + Gexpbyte × (1 + blog256 (µs [1])c) if w = EXP ∧ µs [1] > 0
Gverylow + Gcopy × dµs [2] ÷ 32e if w ∈ Wcopy
160
Caaccess (µs [0] mod 2 , A) + Gcopy × dµs [3] ÷ 32e if w = EXTCODECOPY
160
Caaccess (µs [0] mod 2 , A) if w ∈ Wextaccount
Glog + Glogdata × µs [1] if w = LOG0
Glog + Glogdata × µs [1] + Glogtopic if w = LOG1
Glog + Glogdata × µs [1] + 2Glogtopic if w = LOG2
log + Glogdata × µs [1] + 3Glogtopic
G if w = LOG3
Glog + Glogdata × µs [1] + 4Glogtopic
if w = LOG4
CCALL (σ, µ, A) if w ∈ Wcall
0
C(σ, µ, A, I) ≡ Cmem (µi ) − Cmem (µi ) + CSELFDESTRUCT (σ, µ) if w = SELFDESTRUCT
Gcreate if w = CREATE
Gcreate + Gkeccak256word × dµs [2] ÷ 32e if w = CREATE2
Gkeccak256 + Gkeccak256word × dµs [1] ÷ 32e
if w = KECCAK256
Gjumpdest if w = JUMPDEST
CSLOAD (µ, A, I) if w = SLOAD
∈ Wzero
Gzero
if w
∈ Wbase
Gbase if w
Gverylow if w ∈ Wverylow
Glow if w ∈ Wlow
Gmid if w ∈ Wmid
Ghigh if w ∈ Whigh
G
blockhash if w = BLOCKHASH
(
Ib [µpc ] if µpc < kIb k
(325) w≡
STOP otherwise
where:
a2
(326) Cmem (a) ≡ Gmemory · a +
512
(
Gwarmaccess if x ∈ Aa
(327) Caaccess (x, A) ≡
Gcoldaccountaccess otherwise
with CCALL , CSELFDESTRUCT , CSLOAD and CSSTORE as specified in the appropriate section below. We define the following
subsets of instructions:
Wzero = {STOP, RETURN, REVERT}
Wbase = {ADDRESS, ORIGIN, CALLER, CALLVALUE, CALLDATASIZE, CODESIZE, GASPRICE, COINBASE,
TIMESTAMP, NUMBER, DIFFICULTY, GASLIMIT, CHAINID, RETURNDATASIZE, POP, PC, MSIZE, GAS}
Wverylow = {ADD, SUB, NOT, LT, GT, SLT, SGT, EQ, ISZERO, AND, OR, XOR, BYTE, SHL, SHR, SAR,
CALLDATALOAD, MLOAD, MSTORE, MSTORE8, PUSH*, DUP*, SWAP*}
Wlow = {MUL, DIV, SDIV, MOD, SMOD, SIGNEXTEND, SELFBALANCE}
Wmid = {ADDMOD, MULMOD, JUMP}
Whigh = {JUMPI}
Wcopy = {CALLDATACOPY, CODECOPY, RETURNDATACOPY}
Wcall = {CALL, CALLCODE, DELEGATECALL, STATICCALL}
Wextaccount = {BALANCE, EXTCODESIZE, EXTCODEHASH}
Note the memory cost component, given as the product of Gmemory and the maximum of 0 & the ceiling of the number
of words in size that the memory must be over the current number of words, µi in order that all accesses reference valid
memory whether for read or write. Such accesses must be for non-zero number of bytes.
Referencing a zero length range (e.g. by attempting to pass it as the input range to a CALL) does not require memory
to be extended to the beginning of the range. µ0i is defined as this new maximum number of words of active memory;
special-cases are given where these two are not equal.
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 29
Note also that Cmem is the memory cost function (the expansion function being the difference between the cost before
and after). It is a polynomial, with the higher-order coefficient divided and floored, and thus linear up to 704B of memory
used, after which it costs substantially more.
While defining the instruction set, we defined the memory-expansion for range function, M , thus:
(
s if l = 0
(328) M (s, f, l) ≡
max(s, d(f + l) ÷ 32e) otherwise
Another useful function is “all but one 64th” function L defined as:
H.2. Instruction Set. As previously specified in section 9, these definitions take place in the final context there. In
particular we assume O is the EVM state-progression function and define the terms pertaining to the next cycle’s state
(σ 0 , µ0 ) such that:
Here given are the various exceptions to the state transition rules given in section 9 specified for each instruction,
together with the additional instruction-specific definitions of J and C. For each instruction, also specified is α, the
additional items placed on the stack and δ, the items removed from stack, as defined in section 9.
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 30
0x3d RETURNDATASIZE 0 1 Get size of output data from the previous call from the current
environment.
µ0s [0] ≡ kµo k
0x3e RETURNDATACOPY 3 0 Copy output data from the previous call ( to memory.
µo [µs [1] + i] if µs [1] + i < kµo k
∀i ∈ {0 . . . µs [2] − 1} : µ0m [µs [0] + i] ≡
0 otherwise
The additions in µs [1] + i are not subject to the 2256 modulo.
µ0i ≡ M (µi , µs [0], µs [2])
0x3f EXTCODEHASH 1 1 Get hash(of an account’s code.
0 if DEAD(σ, µs [0] mod 2160 )
µ0s [0] ≡
σ[µs [0] mod 2160 ]c otherwise
0
Aa ≡ Aa ∪ {µs [0] mod 2160 }
40s: Block Information
Value Mnemonic δ α Description
0x40 BLOCKHASH 1 1 Get the hash of one of the 256 most recent complete blocks.
µ0s [0] ≡ P (IHp , µs [0], 0)
where P is the hash of a block of a particular number, up to a maximum
age. 0 is left on the stack if the looked for block number is greater than or
equal to the current block number or more than 256 blocks behind the current block.
0
if n > Hi ∨ a = 256 ∨ h = 0
P (h, n, a) ≡ h if n = Hi
P (Hp , n, a + 1) otherwise
and we assert the header H can be determined from its hash h unless h is zero
(as is the case for the parent hash of the genesis block).
0x41 COINBASE 0 1 Get the current block’s beneficiary address.
µ0s [0] ≡ IHc
0x42 TIMESTAMP 0 1 Get the current block’s timestamp.
µ0s [0] ≡ IHs
0x43 NUMBER 0 1 Get the current block’s number.
µ0s [0] ≡ IHi
0x44 DIFFICULTY 0 1 Get the current block’s difficulty.
µ0s [0] ≡ IHd
0x45 GASLIMIT 0 1 Get the current block’s gas limit.
µ0s [0] ≡ IHl
0x46 CHAINID 0 1 Get the chain ID.
µ0s [0] ≡ β
0x47 SELFBALANCE 0 1 Get balance of currently executing account.
µ0s [0] ≡ σ[Ia ]b
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 34
0xf4 DELEGATECALL 6 1 Message-call into this account with an alternative account’s code, but
persisting the current values for sender and value.
Compared with CALL, DELEGATECALL takes one fewer arguments. The
omitted argument is µs [2]. As a result, µs [3], µs [4], µs [5] and µs [6] in the
definition of CALL should respectively be replaced with µs [2], µs [3], µs [4] and
µs [5]. Otherwise itis equivalent to CALL except:
Θ(σ, A∗ , Is , Io , Ia , t, CCALLGAS (σ, µ, A),
0 0 0
if Ie < 1024
(σ , g , A , x, o) ≡ Ip , 0, Iv , i, Ie + 1, Iw )
(σ, CCALLGAS (σ, µ, A), A, 0, ()) otherwise
Note the changes (in addition to that of the fourth parameter) to the second
and ninth parameters to the call Θ.
This means that the recipient is in fact the same account as at present, simply
that the code is overwritten and the context is almost entirely identical.
0xf5 CREATE2 4 1 Create a new account with associated code.
Exactly equivalent to CREATE except:
The salt ζ ≡ µs [3].
0xfa STATICCALL 6 1 Static message-call into an account.
Exactly equivalent to CALL except:
The argument µs [2] is replaced with 0.
The deeper argument µs [3], µs [4], µs [5] and µs [6] are respectively replaced
with µs [2], µs [3], µs [4] and µs [5].
The last argument of Θ is ⊥.
0xfd REVERT 2 0 Halt execution reverting state changes but returning data and remaining gas.
HRETURN (µ) ≡ µm [µs [0] . . . (µs [0] + µs [1] − 1)]
The effect of this operation is described in (143).
For the gas calculation, we use the memory expansion function,
µ0i ≡ M (µi , µs [0], µs [1])
0xfe INVALID ∅ ∅ Designated invalid instruction.
0xff SELFDESTRUCT 1 0 Halt execution and register account for later deletion.
A0s ≡ As ∪ {Ia }
A0a ≡ Aa∪ {r}
∅
if σ[r] = ∅ ∧ σ[Ia ]b = 0
0
σ [r] ≡ (σ[r]n , σ[r]b + σ[Ia ]b , σ[r]s , σ[r]c ) if r 6= Ia
(σ[r]n , 0, σ[r]s , σ[r]c ) otherwise
σ 0 [Ia ]b = 0 (
0 if r ∈ Aa
CSELFDESTRUCT (σ, µ) ≡ Gselfdestruct +
Gcoldaccountaccess otherwise
(
Gnewaccount if DEAD(σ, r) ∧ σ[Ia ]b 6= 0
+
0 otherwise
0256 , KEC RLP () , 0160 , stateRoot, 0, 0, 02048 , 234 , 0, 0, 3141592, time, 0, 0256 , KEC (42) , (), ()
(331)
Where 0256 refers to the parent hash, a 256-bit hash which is all zeroes; 0160 refers to the beneficiary address, a 160-bit
hash which is all zeroes; 02048 refers to the log bloom, 2048-bit of all zeros; 234 refers to the difficulty; the transaction trie
root, receipt trie root, gas used, block number and extradata are both 0, being equivalent to the empty byte array. The
sequences of both ommers and transactions are empty and represented by (). KEC (42) refers to the Keccak-256 hash of
a byte array of length one whose first and only byte is of value 42, used for the nonce. KEC RLP () value refers to the
hash of the ommer list in RLP, both empty lists.
The proof-of-concept series include a development premine, making the state root hash some value stateRoot. Also
time will be set to the initial timestamp of the genesis block. The latest documentation should be consulted for those
values.
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 39
Appendix J. Ethash
J.1. Definitions. We employ the following definitions:
Name Value Description
Jwordbytes 4 Bytes in word.
Jdatasetinit 230 Bytes in dataset at genesis.
Jdatasetgrowth 223 Dataset growth per epoch.
Jcacheinit 224 Bytes in cache at genesis.
Jcachegrowth 217 Cache growth per epoch.
Jepoch 30000 Blocks per epoch.
Jmixbytes 128 mix length in bytes.
Jhashbytes 64 Hash length in bytes.
Jparents 256 Number of parents of each dataset element.
Jcacherounds 3 Number of rounds in cache production.
Jaccesses 64 Number of accesses in hashimoto loop.
J.2. Size of dataset and cache. The size for Ethash’s cache c ∈ B and dataset d ∈ B depend on the epoch, which in
turn depends on the block number.
Hi
(332) Eepoch (Hi ) =
Jepoch
The size of the dataset growth by Jdatasetgrowth bytes, and the size of the cache by Jcachegrowth bytes, every epoch. In
order to avoid regularity leading to cyclic behavior, the size must be a prime number. Therefore the size is reduced by a
multiple of Jmixbytes , for the dataset, and Jhashbytes for the cache. Let dsize = kdk be the size of the dataset. Which is
calculated using
(333) dsize = Eprime (Jdatasetinit + Jdatasetgrowth · Eepoch − Jmixbytes , Jmixbytes )
The size of the cache, csize , is calculated using
(334) csize = Eprime (Jcacheinit + Jcachegrowth · Eepoch − Jhashbytes , Jhashbytes )
(
x if x/y ∈ N
(335) Eprime (x, y) =
Eprime (x − 2 · y, y) otherwise
J.3. Dataset generation. In order to generate the dataset we need the cache c, which is an array of bytes. It depends
on the cache size csize and the seed hash s ∈ B32 .
J.3.1. Seed hash. The seed hash is different for every epoch. For the first epoch it is the Keccak-256 hash of a series of 32
bytes of zeros. For every other epoch it is always the Keccak-256 hash of the previous seed hash:
(336) s = Cseedhash (Hi )
(
032 if Eepoch (Hi ) = 0
(337) Cseedhash (Hi ) =
KEC(Cseedhash (Hi − Jepoch )) otherwise
With 032 being 32 bytes of zeros.
J.3.2. Cache. The cache production process involves using the seed hash to first sequentially filling up csize bytes of
memory, then performing Jcacherounds passes of the RandMemoHash algorithm created by Lerner [2014]. The initial cache
c0 , being an array of arrays of single bytes, will be constructed as follows.
We define the array ci , consisting of 64 single bytes, as the ith element of the initial cache:
(
KEC512(s) if i = 0
(338) ci =
KEC512(ci−1 ) otherwise
Therefore c0 can be defined as
(339) c0 [i] = ci ∀ i < n
csize
(340) n=
Jhashbytes
The cache is calculated by performing Jcacherounds rounds of the RandMemoHash algorithm to the initial cache c0 :
(341) c = Ecacherounds (c0 , Jcacherounds )
x
if y = 0
(342) Ecacherounds (x, y) = ERMH (x) if y = 1
Ecacherounds (ERMH (x), y − 1) otherwise
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BERLIN VERSION 40
(344) Ermh (x, i) = KEC512(x0 [(i − 1 + n) mod n] ⊕ x0 [x0 [i][0] mod n])
with x0 = x except x0 [j] = Ermh (x, j) ∀ j<i
J.3.3. Full dataset calculation. Essentially, we combine data from Jparents pseudorandomly selected cache nodes, and hash
that to compute the dataset. The entire dataset is then generated by a number of items, each Jhashbytes bytes in size:
dsize
(345) d[i] = Edatasetitem (c, i) ∀ i <
Jhashbytes
In order to calculate the single item we use an algorithm inspired by the FNV hash (Glenn Fowler [1991]) in some cases
as a non-associative substitute for XOR.
(346) EFNV (x, y) = (x · (0x01000193 ⊕ y)) mod 232
The single item of the dataset can now be calculated as:
(347) Edatasetitem (c, i) = Eparents (c, i, −1, ∅)
(
Eparents (c, i, p + 1, Emix (m, c, i, p + 1)) if p < Jparents − 2
(348) Eparents (c, i, p, m) =
Emix (m, c, i, p + 1) otherwise
(
KEC512(c[i mod csize ] ⊕ i) if p = 0
(349) Emix (m, c, i, p) =
EFNV m, c[EFNV (i ⊕ p, m[p mod bJhashbytes /Jwordbytes c]) mod csize ] otherwise
J.4. Proof-of-work function. Essentially, we maintain a “mix” Jmixbytes bytes wide, and repeatedly sequentially fetch
Jmixbytes bytes from the full dataset and use the EFNV function to combine it with the mix. Jmixbytes bytes of sequential
access are used so that each round of the algorithm always fetches a full page from RAM, minimizing translation lookaside
buffer misses which ASICs would theoretically be able to avoid.
If the output of this algorithm is below the desired target, then the nonce is valid. Note that the extra application
of KEC at the end ensures that there exists an intermediate nonce which can be provided to prove that at least a small
amount of work was done; this quick outer PoW verification can be used for anti-DDoS purposes. It also serves to provide
statistical assurance that the result is an unbiased, 256 bit number.
The PoW-function returns an array with the compressed mix as its first item and the Keccak-256 hash of the
concatenation of the compressed mix with the seed hash as the second item:
(350)
PoW(Hn , Hn , d) = {mc (KEC(RLP(LH (Hn ))), Hn , d), KEC(sh (KEC(RLP(LH (Hn ))), Hn ) + mc (KEC(RLP(LH (Hn ))), Hn , d))}
With Hn being the hash of the header without the nonce. The compressed mix mc is obtained as follows:
nmix
X
(351) mc (h, n, d) = Ecompress (Eaccesses (d, sh (h, n), sh (h, n), −1), −4)
i=0