Ethereum's groundbreaking

Many people tend to come to Ethereum when they already know a little bit about cryptocurrencies, especially Bitcoin. The bitcoin blockchain network will track the change in ownership status of cryptocurrency units. We can think of Bitcoin as a distributed consensus state system in which transactions change state. These transactions will be collected into a block, and blocks make up the blockchain under a consensus mechanism.

Regarding Ethereum, instead of only tracking the change in ownership of cryptocurrency units, it tracks the change in the state of a general-purpose data store. For example, store the key-value pair "duongnd - blog's author." Ethereum has a memory that stores both code and data and uses the Ethereum block to track state changes over time. Like a computer, Ethereum can load code into its state machine and run that code, storing the resulting state changes in its blockchain. However, there will be two differences between Ethereum and a computer: Ethereum state transition works under a consensus algorithm, and the state machine is distributed to all nodes.

Ethereum can execute programs stored in a state machine called Ethereum virtual machine (EVM). Since the EVM can read and write data to memory, Ethereum can execute any program that a Turing machine can do with finite memory.

Therefore, Ethereum's groundbreaking innovation is to combine a stored-program computer's general-purpose computing architecture with a decentralized blockchain.

Gas

Ethereum introduced the concept of gas, a measure of the number of computational steps. The question here is, why do we need to include this gas concept? As mentioned in the previous section, EVM can execute programs like a Turing computer. Thus, there will be programs that never end, like infinite loops or programs that consume too much computation and resources during execution and validation. As a result, gas provides EVM with information about the resources used when executing the program by carefully calculating the amount of gas for each instruction. Each instruction has a predetermined amount of gas.

Each transaction,, when sending, must set an upper gas limit. If the total amount of gas consumed exceeds the gas limit, the EVM will terminate the transaction. Ethereum uses the gas concept to allow Turing-complete computation while limiting the resources that every program can consume.

Accounts

Accounts is an entity in Ethereum. An account is an object in the world state, a mapping between address and account state.

Account state has 4 fields:

  • nonce: Count the number of transactions sent from the account. For the contract account, count the number of new contracts created by it.
  • balance: The number of wei held by the account
  • storage root: The hash value of the Merkle Patricia trie root node - a data structure for storage on Ethereum.
  • code hash: The hash value of contract code, the hash value of empty string if EOC.

Ethereum has two account types:

  • Externally-owned – controlled by anyone with the private keys
  • Contract – a smart contract deployed to the network, controlled by code.

Both account types have the ability to:

  • Receive, hold and send ETH and tokens
  • Interact with deployed smart contracts

The key difference between the External owner account and a Contract account:

External owner account 

Contract account

Creating an account costs nothing

Creating a contract has a cost

Can initiate transactions

Can only send transactions in response to receiving a transaction

Transactions between externally-owned accounts can only be ETH/token transfers

Transactions from an external account to a contract account can trigger code which can execute many different actions, such as transferring tokens or even creating a new contract

The models of Externally owned account (EOA) and contract account
Difference between Externally owned account and Contract account. Source: ethereum.org

Transaction

A transaction is a signed message sent from an External Owner Account (EOA). Transactions will be sent to the Ethereum network for validation and combined into a block. A transaction can be called a state transition function in the state machine. And only transactions can change the Ethereum state.

a model describes that Ethereum can be seen as a state chain
From the viewpoint of the states, Ethereum can be seen as a state chain. Source: ethereum.org

There are two types of transactions: transaction creates contract and transaction message call.

The model describes two types of transactions
Two types of transactions (1). Source: ethereum.org
The model describes two types of transaction (2)
Two types of transactions (2). Source: ethereum.org

Transactions are atomic and cannot be split or interrupted in the middle. It means that either the transaction executes successfully or the transaction fails to execute at all. The order between transactions is decided by the miner.