The State Machine
January 21, 2022
Overview
Ethereum is a distributed, transaction-based state machine. The global state is made up of accounts and each account is represented as a mapping between an address and an account state. Furthermore, accounts may perform transactions where each transaction is represented as a valid arc between two states, collated into packages of data called blocks.
Accounts
Ethereum has two types of accounts: Externally-Owned Accounts (EOA) and Contract Accounts. An externally-owned account is controlled by a private key. This account incurs no cost when created and can initiate transactions. In contrast, a contract account is controlled by code. This account incurs a cost when created (for network storage) and can only send transactions in response to a transaction received.
Both types of accounts have the ability to send, receive and hold ETH/tokens and interact with smart contracts through transactions. Transactions orignate from an externally-owned account, and, if sent to a contract account, can execute code which can perform a variety of functions.
Addresses
An address maps to the account state of an account, derived as follows:
- Externally-owned account addresses:
Private Key
->Public Key
->Address
(160-bit) - Contract account address:
Private Key
->Public Key
+Nonce
->Address
(160-bit)
Addresses are represented in hexadecimal format (base 16 notation), often indicated explicitly by prepending 0x
to the address. Each byte of the address is represented by 2 hex characters. Therefore, a prefixed address is 42 characters long.
Account States
An account state stores relevant information about an account, consisting of four fields:
nonce
- a counter that indicates the number of transactions sent from the account (for a contract account, this number represents the number of contracts created by the account)balance
- the number of wei owned by the address, a denomination of ETH (with 1e+18 wei per ETH)codeHash
- the code of an account on the Ethereum virtual machine (for an externally-owned account, this hash represents the hash of an empty string)storageRoot
- a 256-bit hash of the root node that encodes the storage contents of the account (empty by default)