Paper
Paper
Paper
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 Appendix Ether:
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 final state. It is this final 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 BYZANTIUM VERSION 7e819ec - 2019-10-20 3
Sometimes, a path follows a new protocol from a par- assume that the unmodified ‘input’ value be denoted by
ticular height. This document describes one version of the the placeholder then the modified and utilisable value is
protocol. In order to follow back the history of a path, one denoted as 0 , and intermediate values would be ∗ , ∗∗
must reference multiple versions of this document. &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. (5) `(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
Also, KEC512 refers to the Keccak-512 hash function. B). Though not stored on the blockchain, it is assumed
Tuples are typically denoted with an upper-case letter, that the implementation will maintain this mapping in
e.g. T , is used to denote an Ethereum transaction. This a modified Merkle Patricia tree (trie, see Appendix D).
symbol may, if accordingly defined, be subscripted to refer The trie requires a simple database backend that main-
to an individual component, e.g. Tn , denotes the nonce tains a mapping of byte arrays to byte arrays; we name
of said transaction. The form of the subscript is used to this underlying database the state database. This has a
denote its type; e.g. uppercase subscripts refer to tuples number of benefits; firstly the root node of this structure
with subscriptable components. is cryptographically dependent on all internal data and
Scalars and fixed-size byte sequences (or, synonymously, as such its hash can be used as a secure identity for the
arrays) are denoted with a normal lower-case letter, e.g. entire system state. Secondly, being an immutable data
n is used in the document to denote a transaction nonce. structure, it allows any previous state (whose root hash
Those with a particularly special meaning may be Greek, is known) to be recalled by simply altering the root hash
e.g. δ, the number of items required on the stack for a accordingly. Since we store all such root hashes in the
given operation. blockchain, we are able to trivially revert to old states.
Arbitrary-length sequences are typically denoted as a The account state, σ[a], comprises the following four
bold lower-case letter, e.g. o is used to denote the byte fields:
sequence given as the output data of a message call. For nonce: A scalar value equal to the number of trans-
particularly important values, a bold uppercase letter may actions sent from this address or, in the case
be used. of accounts with associated code, the number of
Throughout, we assume scalars are non-negative inte- contract-creations made by this account. For ac-
gers and thus belong to the set N. The set of all byte count of address a in state σ, this would be for-
sequences is B, formally defined in Appendix B. If such mally denoted σ[a]n .
a set of sequences is restricted to those of a particular balance: A scalar value equal to the number of Wei
length, it is denoted with a subscript, thus the set of all owned by this address. Formally denoted σ[a]b .
byte sequences of length 32 is named B32 and the set of storageRoot: A 256-bit hash of the root node of a
all non-negative integers smaller than 2256 is named N256 . Merkle Patricia tree that encodes the storage con-
This is formally defined in section 4.3. tents of the account (a mapping between 256-bit
Square brackets are used to index into and reference integer values), encoded into the trie as a mapping
individual components or subsequences of sequences, e.g. from the Keccak 256-bit hash of the 256-bit integer
µs [0] denotes the first item on the machine’s stack. For keys to the RLP-encoded 256-bit integer values.
subsequences, ellipses are used to specify the intended The hash is formally denoted σ[a]s .
range, to include elements at both limits, e.g. µm [0..31] codeHash: The hash of the EVM code of this
denotes the first 32 items of the machine’s memory. account—this is the code that gets executed should
In the case of the global state σ, which is a sequence of this address receive a message call; it is immutable
accounts, themselves tuples, the square brackets are used and thus, unlike all other fields, cannot be changed
to reference an individual account. after construction. All such code fragments are
When considering variants of existing values, we follow contained in the state database under their corre-
the rule that within a given scope for definition, if we sponding hashes for later retrieval. This hash is
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BYZANTIUM VERSION 7e819ec - 2019-10-20 4
formally denoted σ[a]c , and thus the code may be gasPrice: A scalar value equal to the number of
denoted as b, given that KEC(b) = σ[a]c . Wei to be paid per unit of gas for all computation
Since we typically wish to refer not to the trie’s root costs incurred as a result of the execution of this
hash but to the underlying set of key/value pairs stored transaction; formally Tp .
within, we define a convenient equivalence: gasLimit: A scalar value equal to the maximum
amount of gas that should be used in executing
TRIE L∗I (σ[a]s ) ≡ σ[a]s
(6) this transaction. This is paid up-front, before any
The collapse function for the set of key/value pairs in computation is done and may not be increased
the trie, L∗I , is defined as the element-wise transformation later; formally Tg .
of the base function LI , given as: to: The 160-bit address of the message call’s recipi-
ent or, for a contract creation transaction, ∅, used
(7) LI (k, v) ≡ KEC(k), RLP(v) here to denote the only member of B0 ; formally
where: Tt .
value: A scalar value equal to the number of Wei to
(8) k ∈ B32 ∧ v∈N be transferred to the message call’s recipient or,
in the case of contract creation, as an endowment
It shall be understood that σ[a]s is not a ‘physical’
to the newly created account; formally Tv .
member of the account and does not contribute to its later
v, r, s: Values corresponding to the signature of the
serialisation.
transaction and used to determine the sender of
If the codeHash field is the Keccak-256 hash of the
the transaction; formally Tw , Tr and Ts . This is
empty string, i.e. σ[a]c = KEC () , then the node represents
expanded in Appendix F.
a simple account, sometimes referred to as a “non-contract”
account. Additionally, a contract creation transaction contains:
Thus we may define a world-state collapse function LS : init: An unlimited size byte array specifying the
(9) LS (σ) ≡ {p(a) : σ[a] 6= ∅} EVM-code for the account initialisation procedure,
formally Ti .
where
init is an EVM-code fragment; it returns the body,
(10) p(a) ≡ KEC(a), RLP (σ[a]n , σ[a]b , σ[a]s , σ[a]c ) a second fragment of code that executes each time the
account receives a message call (either through a trans-
This function, LS , is used alongside the trie function
action or due to the internal execution of code). init is
to provide a short identity (hash) of the world state. We
executed only once at account creation and gets discarded
assume:
immediately thereafter.
(11) ∀a : σ[a] = ∅ ∨ (a ∈ B20 ∧ v(σ[a])) In contrast, a message call transaction contains:
where v is the account validity function: data: An unlimited size byte array specifying the
input data of the message call, formally Td .
(12) v(x) ≡ xn ∈ N256 ∧xb ∈ N256 ∧xs ∈ B32 ∧xc ∈ B32
Appendix F specifies the function, S, which maps trans-
An account is empty when it has no code, zero nonce actions to the sender, and happens through the ECDSA of
and zero balance: the SECP-256k1 curve, using the hash of the transaction
(13) (excepting the latter three signature fields) as the datum
EMPTY(σ, a) ≡ σ[a]c = KEC () ∧σ[a]n = 0∧σ[a]b = 0 to sign. For the present we simply assert that the sender
Even callable precompiled contracts can have an empty of a given transaction T can be represented with S(T ).
account state. This is because their account states do not
usually contain the code describing its behavior. (15) (
An account is dead when its account state is non-existent (Tn , Tp , Tg , Tt , Tv , Ti , Tw , Tr , Ts ) if Tt = ∅
LT (T ) ≡
or empty: (Tn , Tp , Tg , Tt , Tv , Td , Tw , Tr , Ts ) otherwise
(14) DEAD(σ, a) ≡ σ[a] = ∅ ∨ EMPTY(σ, a) Here, we assume all components are interpreted by the
RLP as integer values, with the exception of the arbitrary
4.2. The Transaction. A transaction (formally, T ) is a
length byte arrays Ti and Td .
single cryptographically-signed instruction constructed by
an actor externally to the scope of Ethereum. While it is (16) Tn ∈ N256 ∧ Tv ∈ N256 ∧ Tp ∈ N256 ∧
assumed that the ultimate external actor will be human in Tg ∈ N256 ∧ Tw ∈ N5 ∧ Tr ∈ N256 ∧
nature, software tools will be used in its construction and Ts ∈ N256 ∧ Td ∈ B ∧ Ti ∈ B
dissemination1. There are two types of transactions: those
which result in message calls and those which result in where
the creation of new accounts with associated code (known
(17) Nn = {P : P ∈ N ∧ P < 2n }
informally as ‘contract creation’). Both types specify a
number of common fields: The address hash Tt is slightly different: it is either a
nonce: A scalar value equal to the number of trans- 20-byte address hash or, in the case of being a contract-
actions sent by the sender; formally Tn . creation transaction (and thus formally equal to ∅), it is
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 BYZANTIUM VERSION 7e819ec - 2019-10-20 5
the RLP empty byte sequence and thus the member of B0 : nonce: A 64-bit value which, combined with the mix-
hash, proves that a sufficient amount of computa-
( tion has been carried out on this block; formally
B20 if Tt 6= ∅
(18) Tt ∈ Hn .
B0 otherwise
The other two components in the block are simply a list
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 (19) B ≡ (BH , BT , BU )
the comprised transactions, T, and a set of other block
headers U that are known to have a parent equal to the 4.3.1. Transaction Receipt. In order to encode information
present block’s parent’s parent (such blocks are known as about a transaction concerning which it may be useful
ommers 2). The block header contains several pieces of to form a zero-knowledge proof, or index and search, we
information: encode a receipt of each transaction containing certain in-
formation from its execution. Each receipt, denoted BR [i]
parentHash: The Keccak 256-bit hash of the parent for the ith transaction, is placed in an index-keyed trie
block’s header, in its entirety; formally Hp . and the root recorded in the header as He .
ommersHash: The Keccak 256-bit hash of the om- The transaction receipt, R, is a tuple of four items com-
mers list portion of this block; formally Ho . prising: the cumulative gas used in the block containing
beneficiary: The 160-bit address to which all fees the transaction receipt as of immediately after the trans-
collected from the successful mining of this block action has happened, Ru , the set of logs created through
be transferred; formally Hc . execution of the transaction, Rl and the Bloom filter com-
stateRoot: The Keccak 256-bit hash of the root posed from information in those logs, Rb and the status
node of the state trie, after all transactions are code of the transaction, Rz :
executed and finalisations applied; formally Hr .
transactionsRoot: The Keccak 256-bit hash of the (20) R ≡ (Ru , Rb , Rl , Rz )
root node of the trie structure populated with each
transaction in the transactions list portion of the The function LR trivially prepares a transaction receipt
block; formally Ht . for being transformed into an RLP-serialised byte array:
receiptsRoot: The Keccak 256-bit hash of the root (21) LR (R) ≡ (0 ∈ B256 , Ru , Rb , Rl )
node of the trie structure populated with the re-
ceipts of each transaction in the transactions list where 0 ∈ B256 replaces the pre-transaction state root that
portion of the block; formally He . existed in previous versions of the protocol.
logsBloom: The Bloom filter composed from index- We assert that the status code Rz is a non-negative
able information (logger address and log topics) integer.
contained in each log entry from the receipt of
each transaction in the transactions list; formally (22) Rz ∈ N
Hb . We assert that Ru , the cumulative gas used, is a non-
difficulty: A scalar value corresponding to the dif- negative integer and that the logs Bloom, Rb , is a hash of
ficulty level of this block. This can be calculated size 2048 bits (256 bytes):
from the previous block’s difficulty level and the
timestamp; formally Hd . (23) Ru ∈ N ∧ Rb ∈ B256
number: A scalar value equal to the number of an-
cestor blocks. The genesis block has a number of The sequence Rl is a series of log entries, (O0 , O1 , ...).
zero; formally Hi . A log entry, O, is a tuple of the logger’s address, Oa , a
gasLimit: A scalar value equal to the current limit possibly empty series of 32-byte log topics, Ot and some
of gas expenditure per block; formally Hl . number of bytes of data, Od :
gasUsed: A scalar value equal to the total gas used (24) O ≡ (Oa , (Ot0 , Ot1 , ...), Od )
in transactions in this block; formally Hg .
timestamp: A scalar value equal to the reasonable
output of Unix’s time() at this block’s inception; (25) Oa ∈ B20 ∧ ∀x ∈ Ot : x ∈ B32 ∧ Od ∈ B
formally Hs .
We define the Bloom filter function, M , to reduce a log
extraData: An arbitrary byte array containing data
entry into a single 256-byte hash:
relevant to this block. This must be 32 bytes or
_
fewer; formally Hx .
(26) M (O) ≡ x∈{Oa }∪Ot M3:2048 (x)
mixHash: A 256-bit hash which, combined with the
nonce, proves that a sufficient amount of compu- where M3:2048 is a specialised Bloom filter that sets
tation has been carried out on this block; formally three bits out of 2048, given an arbitrary byte sequence.
Hm . It does this through taking the low-order 11 bits of each of
2ommer is a gender-neutral term to mean “sibling of parent”; see https://nonbinary.miraheze.org/wiki/Gender_neutral_language#Aunt.
2FUncle
311 bits = 22048 , 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 BYZANTIUM VERSION 7e819ec - 2019-10-20 6
more time to develop proof-of-stake and preventing the 5. Gas and Payment
network from “freezing” up.
In order to avoid issues of network abuse and to sidestep
The canonical gas limit Hl of a block of header H must
the inevitable questions stemming from Turing complete-
fulfil the relation:
ness, all programmable computation in Ethereum is subject
P (H)H l to fees. The fee schedule is specified in units of gas (see Ap-
(47) Hl < P (H)H l + ∧
1024 pendix G for the fees associated with various computation).
P (H)H l Thus any given fragment of programmable computation
Hl > P (H)H l − ∧
1024 (this includes creating contracts, making message calls,
Hl > 5000 utilising and accessing account storage and executing op-
erations on the virtual machine) has a universally agreed
Hs is the timestamp (in Unix’s time()) of block H and cost in terms of gas.
must fulfil the relation: Every transaction has a specific amount of gas associ-
(48) Hs > P (H)H s ated with it: gasLimit. This is the amount of gas which
is implicitly purchased from the sender’s account balance.
This mechanism enforces a homeostasis in terms of the
The purchase happens at the according gasPrice, also
time between blocks; a smaller period between the last two
specified in the transaction. The transaction is consid-
blocks results in an increase in the difficulty level and thus
ered invalid if the account balance cannot support such
additional computation required, lengthening the likely
a purchase. It is named gasLimit since any unused gas
next period. Conversely, if the period is too large, the
at the end of the transaction is refunded (at the same
difficulty, and expected time to the next block, is reduced.
rate of purchase) to the sender’s account. Gas does not
The nonce, Hn , must satisfy the relations:
exist outside of the execution of a transaction. Thus for
2256 accounts with trusted code associated, a relatively high
(49) n6 ∧ m = Hm
Hd gas limit may be set and left alone.
with (n, m) = PoW(Hn , Hn , d). In general, Ether used to purchase gas that is not re-
Where Hn is the new block’s header H, but without the funded is delivered to the beneficiary address, the address
nonce and mix-hash components, d being the current DAG, of an account typically under the control of the miner.
a large data set needed to compute the mix-hash, and PoW Transactors are free to specify any gasPrice that they
is the proof-of-work function (see section 11.5): this evalu- wish, however miners are free to ignore transactions as
ates to an array with the first item being the mix-hash, to they choose. A higher gas price on a transaction will there-
prove that a correct DAG has been used, and the second fore cost the sender more in terms of Ether and deliver
item being a pseudo-random number cryptographically a greater value to the miner and thus will more likely be
dependent on H and d. Given an approximately uniform selected for inclusion by more miners. Miners, in general,
distribution in the range [0, 264 ), the expected time to find will choose to advertise the minimum gas price for which
a solution is proportional to the difficulty, Hd . they will execute transactions and transactors will be free
This is the foundation of the security of the blockchain to canvas these prices in determining what gas price to
and is the fundamental reason why a malicious node can- offer. Since there will be a (weighted) distribution of min-
not propagate newly created blocks that would otherwise imum acceptable gas prices, transactors will necessarily
overwrite (“rewrite”) history. Because the nonce must sat- have a trade-off to make between lowering the gas price
isfy this requirement, and because its satisfaction depends and maximising the chance that their transaction will be
on the contents of the block and in turn its composed mined in a timely manner.
transactions, creating new, valid, blocks is difficult and,
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:
(50) 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;
(3) the transaction nonce is valid (equivalent to the
P (H)H l
Hl < P (H)H l + ∧ sender account’s current nonce);
1024
(4) the gas limit is no smaller than the intrinsic gas,
P (H)H l g0 , used by the transaction; and
Hl > P (H)H l − ∧
1024 (5) the sender account balance contains at least the
Hl > 5000 ∧ cost, v0 , required in up-front payment.
Hs > P (H)H s ∧ Formally, we consider the function Υ, with T being a
Hi = P (H)H i + 1 ∧ transaction and σ the state:
kHx k ≤ 32 (51) σ 0 = Υ(σ, T )
where (n, m) = PoW(Hn , Hn , d) Thus σ 0 is the post-transactional state. We also define
g
Noting additionally that extraData must be at most Υ to evaluate to the amount of gas used in the execution
32 bytes. of a transaction, Υl to evaluate to the transaction’s accrued
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BYZANTIUM VERSION 7e819ec - 2019-10-20 8
log items and Υz to evaluate to the status code resulting as Tg − g0 . The computation, whether contract creation
from the transaction. These will be formally defined later. or a message call, results in an eventual state (which may
legally be equivalent to the current state), the change to
6.1. Substate. Throughout transaction execution, we ac- which is deterministic and never invalid: there can be no
crue certain information that is acted upon immediately invalid transactions from this point.
following the transaction. We call this the accrued transac- We define the checkpoint state σ 0 :
tion substate, or accrued substate for short, and represent
it as A, which is a tuple: (59) σ0 ≡ σ except:
(52) A ≡ (As , Al , At , Ar ) (60) σ 0 [S(T )]b ≡ σ[S(T )]b − Tg Tp
The tuple contents include As , the self-destruct set: a (61) σ 0 [S(T )]n ≡ σ[S(T )]n + 1
set of accounts that will be discarded following the trans- Evaluating σ P from σ 0 depends on the transaction
action’s completion. Al is the log series: this is a series of type; either contract creation or message call; we define
archived and indexable ‘checkpoints’ in VM code execu- the tuple of post-execution provisional state σ P , remaining
tion that allow for contract-calls to be easily tracked by gas g 0 , accrued substate A and status code z:
onlookers external to the Ethereum world (such as decen- (62)
tralised application front-ends). At is the set of touched
Λ4 (σ 0 , S(T ), To , g,
accounts, of which the empty ones are deleted at the end
of a transaction. Finally there is Ar , the refund balance,
Tp , Tv , Ti , 0, >) if Tt = ∅
(σ P , g 0 , A, z) ≡
increased through using the SSTORE instruction in order
Θ4 (σ 0 , S(T ), To , Tt , Tt ,
to reset contract storage to zero from some non-zero value. g, Tp , Tv , Tv , Td , 0, >) otherwise
Though not immediately refunded, it is allowed to partially
offset the total execution costs. where g is the amount of gas remaining after deducting
We define the empty accrued substate A0 to have no the basic amount required to pay for the existence of the
self-destructs, no logs, no touched accounts and a zero transaction:
refund balance:
(63) g ≡ Tg − g0
(53) A0 ≡ (∅, (), ∅, 0)
and To is the original transactor, which can differ from the
6.2. Execution. We define intrinsic gas g0 , the amount of sender in the case of a message call or contract creation
gas this transaction requires to be paid prior to execution, not directly triggered by a transaction but coming from
as follows: the execution of EVM-code.
Note we use Θ4 and Λ4 to denote the fact that only the
(
X Gtxdatazero if i = 0
(54) g0 ≡ first four components of the functions’ values are taken;
G txdatanonzero otherwise
i∈Ti ,Td the final represents the message-call’s output value (a byte
(
Gtxcreate if Tt = ∅ array) and is unused in the context of transaction evalua-
(55) + tion.
0 otherwise
After the message call or contract creation is processed,
(56) + Gtransaction the refund counter has to be incremented for the accounts
where Ti , Td means the series of bytes of the trans- that were self-destructed throughout its invocation.
action’s associated data and initialisation EVM-code, de- X
(64) A0r ≡ Ar + Rself destruct
pending on whether the transaction is for contract-creation
i∈As
or message-call. Gtxcreate is added if the transaction is
contract-creating, but not if a result of EVM-code. G is Then the state is finalised by determining the amount
fully defined in Appendix G. to be refunded, g ∗ from the remaining gas, g 0 , plus some
The up-front cost v0 is calculated as: allowance from the refund counter, to the sender at the
original rate.
(57) v0 ≡ Tg Tp + Tv
Tg − g 0 k 0
j
The validity is determined as: (65) g ∗ ≡ g 0 + min , Ar
2
(58) S(T ) 6= ∅ ∧
σ[S(T )] 6 = ∅ ∧ The total refundable amount is the legitimately remain-
Tn = σ[S(T )]n ∧ ing gas g 0 , added to Ar , with the latter component being
g0 6 Tg ∧ capped up to a maximum of half (rounded down) of the
v0 6 σ[S(T )]b ∧ total amount used Tg − g 0 . Therefore, g ∗ is the total gas
Tg 6 BH l − `(BR )u that remains after the transaction has been executed.
The Ether for the gas is given to the miner, whose
Note the final condition; the sum of the transaction’s
address is specified as the beneficiary of the present block
gas limit, Tg , and the gas utilised in this block prior, given
B. So we define the pre-final state σ ∗ in terms of the
by `(BR )u , must be no greater than the block’s gasLimit,
provisional state σ P :
BH l .
The execution of a valid transaction begins with an (66) σ∗ ≡ σP except
irrevocable change made to the state: the nonce of the ∗
(67) σ [S(T )]b ≡ σ P [S(T )]b + g ∗ Tp
account of the sender, S(T ), is incremented by one and the
balance is reduced by part of the up-front cost, Tg Tp . The (68) σ ∗ [m]b ≡ σ P [m]b + (Tg − g ∗ )Tp
gas available for the proceeding computation, g, is defined (69) m ≡ BH c
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BYZANTIUM VERSION 7e819ec - 2019-10-20 9
The final state, σ 0 , is reached after deleting all accounts where v 0 is the account’s pre-existing value, in the event
that either appear in the self-destruct set or are touched it was previously in existence:
and empty: (
0 if σ[a] = ∅
(70) σ0 ≡ σ∗ except (82) 0
v ≡
0 σ[a]b otherwise
(71) ∀i ∈ As : σ [i] = ∅
(72) ∀i ∈ At : σ 0 [i] = ∅ if DEAD(σ ∗, i) Finally, the account is initialised through the execution
g of the initialising EVM code i according to the execution
And finally, we specify Υ , the total gas used in this
model (see section 9). Code execution can effect several
transaction Υl , the logs created by this transaction and
events that are not internal to the execution state: the
Υz , the status code of this transaction:
account’s storage can be altered, further accounts can be
(73) Υg (σ, T ) ≡ Tg − g ∗ created and further message calls can be made. As such,
(74) l
Υ (σ, T ) ≡ Al the code execution function Ξ evaluates to a tuple of the re-
sultant state σ ∗∗ , available gas remaining g ∗∗ , the accrued
(75) Υz (σ, T ) ≡ z substate A and the body code of the account o.
These are used to help define the transaction receipt
and are also used later for state and nonce validation.
(83) (σ ∗∗ , g ∗∗ , A, o) ≡ Ξ(σ ∗ , g, I, {s, a})
accrued substate A and the resultant output, o, given these 9.4.1. Machine State. The machine state µ is defined as
definitions. For the present context, we will define it as: the tuple (g, pc, m, i, s) which are the gas available, the
program counter pc ∈ N256 , the memory contents, the
(121) (σ 0 , g 0 , A, o) ≡ Ξ(σ, g, I) active number of words in memory (counting continuously
from position 0), and the stack contents. The memory
where we will remember that A, the accrued substate, contents µm are a series of zeroes of size 2256 .
is defined as the tuple of the self-destructs set As , the log For the ease of reading, the instruction mnemonics,
series Al , the touched accounts At and the refund balance written in small-caps (e.g. ADD), should be interpreted as
Ar : their numeric equivalents; the full table of instructions and
their specifics is given in Appendix H.
(122) A ≡ (As , Al , At , Ar )
For the purposes of defining Z, H and O, we define w
as the current operation to be executed:
9.4. Execution Overview. We must now define the Ξ (
function. In most practical implementations this will be Ib [µpc ] if µpc < kIb k
(136) w≡
modelled as an iterative progression of the pair comprising STOP otherwise
the full system state, σ and the machine state, µ. For-
mally, we define it recursively with a function X. This We also assume the fixed amounts of δ and α, specifying
uses an iterator function O (which defines the result of a the stack items removed and added, both subscriptable
single cycle of the state machine) together with functions on the instruction and an instruction cost function C eval-
Z which determines if the present state is an exceptional uating to the full cost, in gas, of executing the given
halting state of the machine and H, specifying the output instruction.
data of the instruction if and only if the present state is a
normal halting state of the machine. 9.4.2. Exceptional Halting. The exceptional halting func-
The empty sequence, denoted (), is not equal to the tion Z is defined as:
empty set, denoted ∅; this is important when interpreting (137)
the output of H, which evaluates to ∅ when execution is to Z(σ, µ, I) ≡ µg < C(σ, µ, I) ∨
continue but a series (potentially empty) when execution δw = ∅ ∨
should halt. kµs k < δw ∨
(w = JUMP ∧ µs [0] ∈ / D(Ib )) ∨
(123) Ξ(σ, g, I, T ) ≡ (σ 0, µ0g , A, o) (w = JUMPI ∧ µs [1] 6= 0 ∧
(σ 0 , µ0, A, ..., o) X (σ, µ, A0, I)
(124) ≡ µs [0] ∈
/ D(Ib )) ∨
(125) µg ≡ g (w = RETURNDATACOPY∧
µs [1] + µs [2] > kµo k) ∨
(126) µpc ≡ 0
kµs k − δw + αw > 1024 ∨ (¬Iw ∧ W (w, µ))
(127) µm ≡ (0, 0, ...)
(128) µi ≡ 0 where
(138)
(129) µs ≡ () W (w, µ) ≡ w ∈ {CREATE, SSTORE,
(130) µo ≡ () SELFDESTRUCT} ∨
LOG0 ≤ w ∧ w ≤ LOG4 ∨
(131) w ∈ {CALL, CALLCODE} ∧ µs [2] 6= 0
∅, µ, A0 , I, ∅
if Z(σ, µ, I)
∅, µ0 , A0 , I, o
if w = REVERT This states that the execution is in an exceptional halt-
X (σ, µ, A, I) ≡ ing state if there is insufficient gas, if the instruction is
O(σ, µ, A, I) · o if o 6= ∅
invalid (and therefore its δ subscript is undefined), if there
X O(σ, µ, A, I) otherwise are insufficient stack items, if a JUMP/JUMPI destination
is invalid, the new stack size would be larger than 1024 or
where
state modification is attempted during a static call. The as-
(132) o ≡ H(µ, I) tute reader will realise that this implies that no instruction
can, through its execution, cause an exceptional halt.
(133) (a, b, c, d) · e ≡ (a, b, c, d, e)
(134) µ0 ≡ µ except: 9.4.3. Jump Destination Validity. We previously used D
(135) µ0g ≡ µg − C(σ, µ, I) as the function to determine the set of valid jump desti-
nations given the code that is being run. We define this
Note that, when we evaluate Ξ, we drop the fourth as any position in the code occupied by a JUMPDEST
element I 0 and extract the remaining gas µ0g from the instruction.
resultant machine state µ0 . All such positions must be on valid instruction bound-
X is thus cycled (recursively here, but implementations aries, rather than sitting in the data portion of PUSH
are generally expected to use a simple iterative loop) until operations and must appear within the explicitly defined
either Z becomes true indicating that the present state is portion of the code (rather than in the implicitly defined
exceptional and that the machine must be halted and any STOP operations that trail it).
changes discarded or until H becomes a series (rather than Formally:
the empty set) indicating that the machine has reached a
controlled halt. (139) D(c) ≡ DJ (c, 0)
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BYZANTIUM VERSION 7e819ec - 2019-10-20 13
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
(175) value in storage. The contract’s code would accept such
2256 updates only from the identity contained on said server.
m = Hm ∧ n 6 with (m, n) = PoW(Hn , Hn , d)
Hd
12.2. Random Numbers. Providing random numbers
Where Hn is the new block’s header but without the within a deterministic system is, naturally, an impossible
nonce and mix-hash components; Hn is the nonce of the task. However, we can approximate with pseudo-random
header; d is a large data set needed to compute the mix- numbers by utilising data which is generally unknowable
Hash and Hd is the new block’s difficulty value (i.e. the at the time of transacting. Such data might include the
block difficulty from section 10). PoW is the proof-of-work block’s hash, the block’s timestamp and the block’s benefi-
function which evaluates to an array with the first item ciary address. In order to make it hard for malicious miners
being the mixHash and the second item being a pseudo- to control those values, one should use the BLOCKHASH
random number cryptographically dependent on H and d. operation in order to use hashes of the previous 256 blocks
The underlying algorithm is called Ethash and is described as pseudo-random numbers. For a series of such numbers,
below. a trivial solution would be to add some constant amount
11.5.1. Ethash. Ethash is the PoW algorithm for Ethereum and hashing the result.
1.0. It is the latest version of Dagger-Hashimoto, intro-
duced by Buterin [2013b] and Dryja [2014], although it 13. Future Directions
can no longer appropriately be called that since many of The state database won’t be forced to maintain all past
the original features of both algorithms were drastically state trie structures into the future. It should maintain
changed with R&D from February 2015 until May 4 2015 an age for each node and eventually discard nodes that
(Jentzsch [2015]). The general route that the algorithm are neither recent enough nor checkpoints. Checkpoints,
takes is as follows: or a set of nodes in the database that allow a particular
There exists a seed which can be computed for each block’s state trie to be traversed, could be used to place a
block by scanning through the block headers up until that maximum limit on the amount of computation needed in
point. From the seed, one can compute a pseudorandom order to retrieve any state throughout the blockchain.
cache, Jcacheinit bytes in initial size. Light clients store Blockchain consolidation could be used in order to re-
the cache. From the cache, we can generate a dataset, duce the amount of blocks a client would need to download
Jdatasetinit bytes in initial size, with the property that to act as a full, mining, node. A compressed archive of the
each item in the dataset depends on only a small number trie structure at given points in time (perhaps one in every
of items from the cache. Full clients and miners store the 10,000th block) could be maintained by the peer network,
dataset. The dataset grows linearly with time. effectively recasting the genesis block. This would reduce
Mining involves grabbing random slices of the dataset the amount to be downloaded to a single archive plus a
and hashing them together. Verification can be done with hard maximum limit of blocks.
low memory by using the cache to regenerate the specific Finally, blockchain compression could perhaps be con-
pieces of the dataset that you need, so you only need to ducted: nodes in state trie that haven’t sent/received a
store the cache. The large dataset is updated once every transaction in some constant amount of blocks could be
Jepoch blocks, so the vast majority of a miner’s effort will thrown out, reducing both Ether-leakage and the growth
be reading the dataset, not making changes to it. The of the state database.
mentioned parameters as well as the algorithm is explained
in detail in appendix J. 13.1. Scalability. Scalability remains an eternal concern.
With a generalised state transition function, it becomes dif-
12. Implementing Contracts ficult to partition and parallelise transactions to apply the
divide-and-conquer strategy. Unaddressed, the dynamic
There are several patterns of contracts engineering that
value-range of the system remains essentially fixed and as
allow particular useful behaviours; two of these that we
the average transaction value increases, the less valuable of
will briefly discuss are data feeds and random numbers.
them become ignored, being economically pointless to in-
12.1. Data Feeds. A data feed contract is one which pro- clude in the main ledger. However, several strategies exist
vides a single service: it gives access to information from that may potentially be exploited to provide a considerably
the external world within Ethereum. The accuracy and more scalable protocol.
timeliness of this information is not guaranteed and it is Some form of hierarchical structure, achieved by either
the task of a secondary contract author—the contract that consolidating smaller lighter-weight chains into the main
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BYZANTIUM VERSION 7e819ec - 2019-10-20 16
block or building the main block through the incremen- Vitalik Buterin. EIP-100: Change difficulty adjust-
tal combination and adhesion (through proof-of-work) of ment to target mean block time including uncles,
smaller transaction sets may allow parallelisation of trans- April 2016. URL https://github.com/ethereum/EIPs/
action combination and block-building. Parallelism could blob/master/EIPS/eip-100.md.
also come from a prioritised set of parallel blockchains, Nicolas T. Courtois, Marek Grajek, and Rahul Naik.
consolidating each block and with duplicate or invalid Optimizing SHA256 in Bitcoin Mining, pages 131–
transactions thrown out accordingly. 144. Springer Berlin Heidelberg, Berlin, Heidel-
Finally, verifiable computation, if made generally avail- berg, 2014. ISBN 978-3-662-44893-9. doi: 10.
able and efficient enough, may provide a route to allow the 1007/978-3-662-44893-9 12. URL https://doi.org/10.
proof-of-work to be the verification of final state. 1007/978-3-662-44893-9_12.
B.A. Davey and H.A. Priestley. Introduction to lattices
14. Conclusion and order. 2nd ed. Cambridge: Cambridge University
Press, 2nd ed. edition, 2002. ISBN 0-521-78451-4/pbk.
We have introduced, discussed and formally defined the Thaddeus Dryja. Hashimoto: I/O bound proof of
protocol of Ethereum. Through this protocol the reader work, 2014. URL http://diyhpl.us/~bryan/papers2/
may implement a node on the Ethereum network and join bitcoin/meh/hashimoto.pdf.
others in a decentralised secure social operating system. Cynthia Dwork and Moni Naor. Pricing via pro-
Contracts may be authored in order to algorithmically cessing or combatting junk mail. In In 12th An-
specify and autonomously enforce rules of interaction. nual International Cryptology Conference, pages 139–
147, 1992. URL http://www.wisdom.weizmann.ac.il/
15. Acknowledgements
~naor/PAPERS/pvp.pdf.
Many thanks to Aeron Buchanan for authoring the Phong Vo Glenn Fowler, Landon Curt Noll. FowlerNol-
Homestead revisions, Christoph Jentzsch for authoring the lVo hash function, 1991. URL http://www.isthe.com/
Ethash algorithm and Yoichi Hirai for doing most of the chongo/tech/comp/fnv/index.html.
EIP-150 changes. Important maintenance, useful correc- Nils Gura, Arun Patel, Arvinderpal Wander, Hans Eberle,
tions and suggestions were provided by a number of others and Sheueling Chang Shantz. Comparing elliptic curve
from the Ethereum DEV organisation and Ethereum com- cryptography and RSA on 8-bit CPUs. In Cryptographic
munity at large including Gustav Simonsson, Pawel Bylica, Hardware and Embedded Systems-CHES 2004, pages
Jutta Steiner, Nick Savers, Viktor Trón, Marko Simovic, 119–132. Springer, 2004. URL https://www.iacr.org/
Giacomo Tazzari and, of course, Vitalik Buterin. archive/ches2004/31560117/31560117.pdf.
Christoph Jentzsch. Commit date for ethash, 2015. URL
16. Availability https://github.com/ethereum/yellowpaper/commit/
77a8cf2428ce245bf6e2c39c5e652ba58a278666#
The source of this paper is maintained at https: commitcomment-24644869.
//github.com/ethereum/yellowpaper/. An auto- Don Johnson, Alfred Menezes, and Scott Van-
generated PDF is located at https://ethereum.github. stone. The Elliptic Curve Digital Signa-
io/yellowpaper/paper.pdf. ture Algorithm (ECDSA), 2001. URL https:
//web.archive.org/web/20170921160141/http://
References cs.ucsb.edu/~koc/ccs130h/notes/ecdsa-cert.pdf.
Accessed 21 September 2017, but the original link was
Jacob Aron. BitCoin software finds new life. New Scientist,
inaccessible on 19 October 2017. Refer to section 6.2 for
213(2847):20, 2012. URL http://www.sciencedirect.
ECDSAPUBKEY, and section 7 for ECDSASIGN and
com/science/article/pii/S0262407912601055.
ECDSARECOVER.
Adam Back. Hashcash - Amortizable Publicly Auditable
Sergio Demian Lerner. Strict Memory Hard Hashing Func-
Cost-Functions, 2002. URL http://www.hashcash.org/
tions, 2014. URL http://www.hashcash.org/papers/
papers/amortizable.pdf.
memohash.pdf.
Guido Bertoni, Joan Daemen, Michal Peeters, and
Mark Miller. The Future of Law. In pa-
Gilles Van Assche. The KECCAK SHA-3 sub-
per delivered at the Extro 3 Conference (August
mission, 2011. URL https://keccak.team/files/
9), 1997. URL https://drive.google.com/file/d/
Keccak-submission-3.pdf.
0Bw0VXJKBgYPMS0J2VGIyWWlocms/edit?usp=sharing.
Roman Boutellier and Mareike Heinzen. Pirates, Pio-
Satoshi Nakamoto. Bitcoin: A peer-to-peer electronic cash
neers, Innovators and Imitators. In Growth Through
system, 2008. URL http://www.bitcoin.org/bitcoin.
Innovation, pages 85–96. Springer, 2014. URL https:
pdf.
//www.springer.com/gb/book/9783319040158.
Meni Rosenfeld, Yoni Assia, Vitalik Buterin, m li-
Vitalik Buterin. Ethereum: A Next-Generation Smart
orhakiLior, Oded Leiba, Assaf Shomer, and Eli-
Contract and Decentralized Application Platform,
ran Zach. Colored Coins Protocol Specification,
2013a. URL https://github.com/ethereum/wiki/
2012. URL https://github.com/Colored-Coins/
wiki/White-Paper.
Colored-Coins-Protocol-Specification.
Vitalik Buterin. Dagger: A Memory-Hard to Compute,
Afri Schoedon and Vitalik Buterin. EIP-649: Metropo-
Memory-Easy to Verify Scrypt Alternative, 2013b. URL
lis difficulty bomb delay and block reward reduction,
http://www.hashcash.org/papers/dagger.html.
June 2017. URL https://github.com/ethereum/EIPs/
Vitalik Buterin. EIP-2: Homestead hard-fork changes,
blob/master/EIPS/eip-649.md.
2015. URL https://github.com/ethereum/EIPs/
blob/master/EIPS/eip-2.md.
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BYZANTIUM VERSION 7e819ec - 2019-10-20 17
Michael John Sebastian Smith. Application-Specific Nick Szabo. Formalizing and securing relation-
Integrated Circuits. Addison-Wesley, 1997. ISBN ships on public networks. First Monday, 2(9),
0201500221. 1997. URL http://firstmonday.org/ojs/index.php/
Yonatan Sompolinsky and Aviv Zohar. Accelerating bit- fm/article/view/548.
coin’s transaction processing. fast money grows on trees, Vivek Vishnumurthy, Sangeeth Chandrakumar, and
not chains, 2013. URL https://eprint.iacr.org/ Emin Gn Sirer. KARMA: A secure economic framework
2013/881. for peer-to-peer resource sharing, 2003. URL https://
Simon Sprankel. Technical Basis of Digital Currencies, www.cs.cornell.edu/people/egs/papers/karma.pdf.
2013. URL http://www.coderblog.de/wp-content/ J. R. Willett. MasterCoin Complete Specification, 2013.
uploads/technical-basis-of-digital-currencies. URL https://github.com/mastercoin-MSC/spec.
pdf.
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.
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.
(
(16f (t), 16x[0] + x[1], 16x[2] + x[3], ...) if kxk is even
(186) HP(x, t) : x ∈ Y ≡
(16(f (t) + 1) + x[0], 16x[1] + x[2], 16x[3] + x[4], ...) otherwise
(
2 if t 6= 0
(187) f (t) ≡
0 otherwise
Thus the high nibble of the first byte contains two flags; the lowest bit encoding the oddness of the length and the
second-lowest encoding the flag t. The low nibble of the first byte is zero in the case of an even number of nibbles and the
first nibble in the case of an odd number. All remaining nibbles (now an even number) fit properly into the remaining
bytes.
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.
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BYZANTIUM VERSION 7e819ec - 2019-10-20 20
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:
(194)
RLP HP(I0 [i..(kI0 k − 1)], 1), I1 if kIk = 1 where ∃I : I ∈ I
RLP HP(I0 [i..(j − 1)], 0), n(I, if i 6= j where j = max{x : ∃l : klk = x ∧ ∀I ∈ I : I0 [0..(x − 1)] = l}
j)
c(I, i) ≡ RLP (u(0), u(1), ..., u(15), v)
otherwise where u(j) ≡ n({I ( : I ∈ I ∧ I0 [i] = j}, i + 1)
I1 if ∃I : I ∈ I ∧ kI0 k = i
v =
() 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
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.
The precompiled contracts each use these definitions and provide specifications for the o (the output data) and gr , the
gas requirements.
We define ΞECREC as a precompiled contract for the elliptic curve digital signature algorithm (ECDSA) public key
recovery function (ecrecover). See Appendix F for the definition of the function ECDSARECOVER. We also define d to be
the input data, well-defined for an infinite length by appending zeroes as required. In the case of an invalid signature
(ECDSARECOVER(h, v, r, s) = ∅), we return no output.
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.
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BYZANTIUM VERSION 7e819ec - 2019-10-20 21
(237) n · P ≡ (0, 0) + P + · · · + P
| {z }
n
We define a binary operation + and scalar multiplication · with the same equations (235), (236) and (237). (C2 , +) is also
known to be a group. We define P2 in C2 with
(239) 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
(240) logP1 (a1 ) × logP2 (b1 ) + · · · + logP1 (ak ) × logP2 (bk ) ≡ 1 mod q
k
Y
(241) e (ai , bi ) = PT
i=0
5A signature of a transaction can be valid not only with a recovery identifier but with some other numbers. See how the component T
w
of a transaction is interpreted.
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BYZANTIUM VERSION 7e819ec - 2019-10-20 25
H.1. Gas Cost. The general gas cost function, C, is defined as:
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BYZANTIUM VERSION 7e819ec - 2019-10-20 26
(294)
CSSTORE (σ, µ) if w = SSTORE
= EXP ∧ µs [1] = 0
Gexp if w
Gexp + Gexpbyte × (1 + blog256 (µs [1])c) = EXP ∧ µs [1] > 0
if w
Gverylow + Gcopy × dµs [2] ÷ 32e if w = CALLDATACOPY ∨
CODECOPY ∨ RETURNDATACOPY
Gextcode + Gcopy × dµs [3] ÷ 32e if w = EXTCODECOPY
G log + Glogdata × µs [1] if w = LOG0
Glog + Glogdata × µs [1] + Glogtopic
if w = LOG1
Glog + Glogdata × µs [1] + 2Glogtopic if w = LOG2
Glog + Glogdata × µs [1] + 3Glogtopic if w = LOG3
Glog + Glogdata × µs [1] + 4Glogtopic
if w = LOG4
w = CALL ∨ CALLCODE ∨
CCALL (σ, µ) if
DELEGATECALL
C(σ, µ, I) ≡ Cmem (µ0i ) − Cmem (µi ) + CSELFDESTRUCT (σ, µ) if w = SELFDESTRUCT
Gcreate
if w = CREATE
Gsha3 + Gsha3word ds[1] ÷ 32e if w = SHA3
Gjumpdest if w = JUMPDEST
Gsload
if w = SLOAD
Gzero if w ∈ Wzero
∈ Wbase
Gbase if w
∈ Wverylow
Gverylow
if w
Glow if w ∈ Wlow
Gmid if w ∈ Wmid
Ghigh if w ∈ Whigh
Gextcode if w ∈ Wextcode
Gbalance if w = BALANCE
G
blockhash if w = BLOCKHASH
(
Ib [µpc ] if µpc < kIb k
(295) w≡
STOP otherwise
where:
a2
(296) Cmem (a) ≡ Gmemory · a +
512
with CCALL , CSELFDESTRUCT 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, RETURNDATASIZE, POP, PC, MSIZE, GAS}
Wverylow = {ADD, SUB, NOT, LT, GT, SLT, SGT, EQ, ISZERO, AND, OR, XOR, BYTE, CALLDATALOAD,
MLOAD, MSTORE, MSTORE8, PUSH*, DUP*, SWAP*}
Wlow = {MUL, DIV, SDIV, MOD, SMOD, SIGNEXTEND}
Wmid = {ADDMOD, MULMOD, JUMP}
Whigh = {JUMPI}
Wextcode = {EXTCODESIZE}
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.
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 724B of memory
used, after which it costs substantially more.
While defining the instruction set, we defined the memory-expansion for range function, M , thus:
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BYZANTIUM VERSION 7e819ec - 2019-10-20 27
(
s if l = 0
(297) 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 BYZANTIUM VERSION 7e819ec - 2019-10-20 28
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 it is equivalent to CALL except:
Θ(σ ∗ , Is , Io , Ia , t, CCALLGAS (µ),
if Iv 6 σ[Ia ]b ∧
Ip , 0, Iv , i, Ie + 1, Iw )
(σ 0 , g 0 , A+ , o) ≡
Ie < 1024
(σ, g, ∅, ()) 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.
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.
The effect of this operation is described in (131).
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 }
∅
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 (
Gnewaccount if n
CSELFDESTRUCT (σ, µ) ≡ Gself destruct +
0 otherwise
n ≡ DEAD(σ, µs [0] mod 2160 ) ∧ σ[Ia ]b =
6 0
0256 , KEC RLP () , 0160 , stateRoot, 0, 0, 02048 , 217 , 0, 0, 3141592, time, 0, 0256 , KEC (42) , (), ()
(300)
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; 217 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 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.
Appendix J. Ethash
J.1. Definitions. We employ the following definitions:
ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER BYZANTIUM VERSION 7e819ec - 2019-10-20 37
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
(301) 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
(302) dsize = Eprime (Jdatasetinit + Jdatasetgrowth · Eepoch − Jmixbytes , Jmixbytes )
The size of the cache, csize , is calculated using
(303) csize = Eprime (Jcacheinit + Jcachegrowth · Eepoch − Jhashbytes , Jhashbytes )
(
x if x/y ∈ N
(304) 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:
(305) s = Cseedhash (Hi )
(
032 if Eepoch (Hi ) = 0
(306) 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
(307) ci =
KEC512(ci−1 ) otherwise
Therefore c0 can be defined as
(308) c0 [i] = ci ∀ i < n
csize
(309) n=
Jhashbytes
The cache is calculated by performing Jcacherounds rounds of the RandMemoHash algorithm to the initial cache c0 :
(310) c = Ecacherounds (c0 , Jcacherounds )
x
if y = 0
(311) Ecacherounds (x, y) = ERMH (x) if y = 1
Ecacherounds (ERMH (x), y − 1) otherwise
(313) 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
(314) 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.
(315) EFNV (x, y) = (x · (0x01000193 ⊕ y)) mod 232
The single item of the dataset can now be calculated as:
(316) Edatasetitem (c, i) = Eparents (c, i, −1, ∅)
(
Eparents (c, i, p + 1, Emix (m, c, i, p + 1)) if p < Jparents − 2
(317) Eparents (c, i, p, m) =
Emix (m, c, i, p + 1) otherwise
(
KEC512(c[i mod csize ] ⊕ i) if p = 0
(318) 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:
(319)
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
(320) mc (h, n, d) = Ecompress (Eaccesses (d, sh (h, n), sh (h, n), −1), −4)
i=0