Ethereum World State Simplified

Kirubakumaresh Rajendran
Coinmonks
Published in
6 min readJun 26, 2022

--

Ethereum is a world computer meaning that it can be accessed by anyone anywhere and they could all see the same information. It has a single global state that holds information about account balances and smart contract data.

It is not a physical computer but an imaginary one made up of all the participating nodes. At the time of this writing, there are ~2000 nodes in the network. The complete state is maintained in each of these nodes and continuously updated by Ethereum Virtual Machine (EVM) upon executing transactions. There is no option to shut down Ethereum unless there are no participating nodes which is highly unlikely.

How did it all start and what does the Ethereum state hold?

The Ethereum network was launched in 2015. When the genesis block (i.e starting block of the blockchain) was created, the state was initialized with ETH balances assigned to specific accounts. These accounts belong to the users who participated in the Ethereum presale.

State at Genesis Block (Block 0)

Imagine there are only two accounts registered to receive certain ETH during the presale. When Ethereum went live, the transactions to send ETH to those accounts are grouped to create the genesis block. Block is nothing but a group of transactions. Upon the block creation, the state will be initialized as follows:

From then on, every block added to the blockchain changes the global state.

State at Block 1

Suppose that the account owner (starting with 0xf42…) transfers 10 ETH to the other account(0x756…), the transaction will be received and validated by all the nodes but not added to the blockchain immediately. Instead, it is added to the next block and updated to the blockchain in a certain interval (~12–14 seconds).

When the first block is added to the blockchain, the above transaction is included in it and the current state would be updated as follows:

Wait what? Why is there a new account with 5 ETH?

Mining Reward

There needs to be an incentive for the miners to spend the computational effort to participate in the network and secure the blockchain. Whenever a block is added to the blockchain, the miner receives 5 ETH as a reward. The reward value changes over time and as of now, the miner receives 2 ETH as a reward. In addition to the reward, the miner also receives gas fees which will be covered in a separate blog.

Smart Contract

Is Ethereum all about transferring ETH between accounts? Not really. Apart from ETH transfers, Ethereum supports smart contract execution. Similar to the way where every account has an ETH balance, every smart contract account has an ETH balance as well as its data as defined by its code.

Let us look at a simple smart contract that stores a message and the person quoted that. The constructor function will be executed when the smart contract is deployed and is responsible for setting up the initial values for the name and message. Post that, any updates to those fields have to happen by invoking the update function.

State at Block 2

To deploy the above contract to the Ethereum network, the contract owner has to invoke a transaction and supply initial values for the data fields (i.e name and message). Once the EVM executes the transaction, a new account (0x7d65…) is created for the contract and the storage is initialized with the values provided by the contract owner. Assuming that is the only transaction in the next block, the state would look like

There is an additional account (0x0019…) added to the state which by now you would have guessed is the reward for the miner who mined the second block.

State at Block 3

Given another user would like to update the smart contract message, they can do so by initiating a new transaction and passing in the new values for name and message. When the transaction is included in the blockchain, it will update the contract account data appropriately.

What happened to the previous message “Hello world”?

If you look at the smart contract code, it is designed to store only the latest value. Hence the previous name and message are overwritten with the new values. However, it is possible to access historical data either by storing it within the smart contract data as an array or emitting events that can be tracked outside of Ethereum.

For instance, if property ownership is stored in the blockchain, it is possible to look at the previous owners of property by querying the smart contract events.

Account types

As you would have observed by now, there are two types of accounts

  • Contract Accounts: These accounts are created when the smart contract is deployed. They have code and data associated with them. Anyone can change the state of these contract accounts by invoking transactions.
  • User Accounts (referred to as Externally Owned Accounts or EOA). These accounts are created outside of Ethereum (usually using wallets such as metamask). They have ETH balances but no code or storage associated with them. EOA accounts can do transfers, deploy smart contracts, and invoke contract methods.

What are the different types of data stored in the blockchain?

The above smart contract is naive to store only name and message. However, the Ethereum blockchain holds a variety of data in its state as dictated by the smart contract such as account balances, token ownership, NFT ownership, liquidity pools, and so on.

Until now, there are ~1B transactions processed in the Ethereum network and millions of smart contracts deployed. I’ll let you imagine the vastness of the current state of the network.

The above is a simplified representation of the world state. The state is stored in a trie structure. In addition to the balance and storage, it also holds nonce and code hash. Let us explore the technical details (shown below) in a separate post.

Please feel free to let me know any questions in the comments. If you like this content, Please follow for more web3 content.

Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also, Read

--

--

Kirubakumaresh Rajendran
Coinmonks

Building twigblock.com to empower anyone to unlock web3 data. I write about web3 data analytics/science. kikura.eth | linktr.ee/kirubakumaresh