0

I am reading the Mastering Ethereum book and came across this piece:

Once mined into a block, transactions also modify the state of the Ethereum singleton, either by modifying the balance of an account (in the case of a simple payment) or by invoking contracts that change their internal state.

Reading further I come across:

As mentioned previously, it is important to remember that a contract’s code cannot be changed. However, a contract can be “deleted,” removing the code and its internal state (storage) from its address, leaving a blank account.

Which again makes me think we have two sources of states with Ethereum. One on the blockchain and another one often referred to as internal state.

Can someone help me in understanding this better?

Are there actually two states to think about? If so what is the differences? If not, then how does the blockchain state differs from the Ethereum singleton internal state.

1

The "internal state" here refers to the state of the storage for a given Ethereum account. It is included in the state of Ethereum. Remember that Ethereum's state contains all accounts, including their storage and balances.

To modify an account's "internal state" (or storage), a transaction must be executed in the Ethereum current state involving a transition to a new Ethereum current state.

There is only one state at a time in Ethereum. From the yellow paper:

Ethereum, taken as a whole, can be viewed as a transaction-based state machine: we begin with a genesis state and incrementally execute transactions to morph it into some current state. It is this current state which we accept as the canonical “version” of the world of Ethereum.

Also, remember that a contract is nothing more than an account with a non-empty string in its "codeHash" field. See AN ACCOUNT EXAMINED for more information on account fields.

7
  • > Remember that Ethereum's state contains all accounts, including their storage and balances so a full node, apart from storing the blockchain would also contain all accounts (including their storage and balances)? And this is not stored on chain? Also I thought account balances are stored on the chain and not in another internal state somewhere else? Sep 27 at 16:37
  • The state has the information of all accounts in the blockchain, it is not stored in each block. The state is generated processing each block since the genesis block. Each block will only modify parts of the state. There are two things to distinguish here: - The blockchain, stored by nodes - The state, generated by incrementally executing transactions since the genesis block. At each block, the hash of the state (represented as a merkle Patricia tree in Ethereum) is computed and verified against the stateRoot value in the block's header. This could help: youtube.com/watch?v=PraPZFMj6h8
    – KonyTech
    Sep 27 at 21:53
  • sorry but it still does not make sense. Especially when you also read the part of the book that says "As mentioned previously, it is important to remember that a contract’s code cannot be changed. However, a contract can be “deleted,” removing the code and its internal state (storage) from its address, leaving a blank account." which suggests there is another location where things are stored, which can be deleted apart from the blocks in the blockchain Sep 28 at 5:23
  • Apart from the blocks which are common to all nodes and stored on-chain, it's up to the node to decide how to locally store Ethereum's state (e.g. Go-ethereum uses levelDB, parity uses rocksDB to store states). Ethereum's state is kept up-to-date and stored locally by the nodes to allow fast access to accounts information. In the case of a contract code deletion, a transaction to delete the code is sent to the network, once mined all nodes execute this transaction therefore deleting the code from their local Ethereum state (from levelDB, rocksDB etc, not stored on-chain).
    – KonyTech
    Sep 28 at 5:44
  • To recap, the blockchain is stored on-chain containing blocks, each with its header and transactions. This is not the Ethereum state. For nodes to be able to validate blocks they all keep a locally stored Ethereum state, generated locally by processing each block since the genesis block. It's up to the Ethereum client implementation to decide how they want to store the Ethereum state. Since transactions are deterministic after all blocks are processed all nodes end up with the same Ethereum state, stored locally by each node. The way it is stored depends on the Ethereum client implementation.
    – KonyTech
    Sep 28 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.