Ethereum Blockchain

What is Ethereum Blockchain, Ethereum Virtual Machine (EVM), GWEI, Gas Fee, ERC 20 standards, EVM functional components.

Mat David
Coinmonks
Published in
9 min readOct 3, 2021

--

Ethereum is an open-source blockchain on which Ether is the token that can be mined. As per the Ethereum site, “Ethereum is the community-run technology powering the cryptocurrency, ether (ETH) and thousands of decentralized applications”. The core engine that powers Ethereum is the Ethereum virtual machine(EVM). It is a blockchain software platform that uses Smart Contract to validate transactions of Ethereum blocks.

Ethereum is a open-source decentralized platform using the peer-to-peer network and can be used to develop decentralized apps (Dapps). Ethereum Virtual Machine is a decentralized application, and every node runs EVM to execute the smart contracts.

Vitalik Buterin, a Canadian computer programmer, is one of the co-founder of Ethereum. When Ethereum was initiated, a pre-set number of Ethers were committed to the Ethereum blockchain to pay for any developers who submit bugs.

Ethereum has a market capitalization of $500 billion for a new all-time high. This value change based on market trends. The current estimate to build/submit a block on Ethereum is 13.13 seconds.

The smart contracts used in Ethereum are developed using solidity programming language. Solidity is a JavaScript-like syntax language. Smart contracts are a way of enforcing and validating an agreement using code without human intervention and smart contracts take away the need for the services of a middleman and it prevents conflicts. Smart Contracts once developed are compiled as byte code and run on the EVM.

Solidity is a programming language found by Gavin wood, and it is one of 4 programming languages that supports developing smart contracts. The set of instructions that form the smart- contracts follow a pre-written logic which satisfies a business use case. A Smart Contract can be used to exchange property or buy anything of value.

Ethereum- What is GWEI, Gas Fees

In Ethereum, different terms used are Gas Supply, Gas fee and & Gas. The transaction fees are called Gas fees. The smallest unit of Ether is a GWei. One ETH represents 1 billion gwei. Gwei is a useful denomination to calculate gas fees.

Gas is used in Ethereum to calculate the transaction fee and also for the computational resource. Gas is a very important Ethereum execution of transaction and execution of smart contracts.

The consensus algorithm is proof of work (POW), same as Bitcoin (Proof Of Work). Soon Ethereum will switch to Proof of Stake (POS), a different consensus algorithm that requires less computational resources than the POW. The main goal of the Ethereum blockchain is to be the large decentralized system that can power the decentralized apps (Dapps) running on it.

Every programmable computation in EVM needs fuel called Gas. Gas fee is the Gas spent on completion of a transaction, this fee is given to the miner who validates or completes the transaction. The unspent Gas is returned to the external caller or the originator of the transaction.

Consensus Algorithm

Proof of Work

Proof of Work consensus involves the miner (the node which validates a transaction in a block) in the blockchain to solve a complex mathematical value called the nonce of the block before submitting the block to the Ethereum blockchain. This complex nonce and hashes of the block uniquely identify a block in the blockchain. As the Ethereum network grows, the computational complexity/power required to verify a block using the POW increases. The miner gets rewarded for the successful calculation of the unique nonce in the blockchain. The proof of consensus algorithm that decides on the success of the mined transaction follows the rule of the longest chain to decide on which block to mine. In the longest chain rule, the miner keeps an eye on the blockchain network for a new block to mine. The longest chain becomes the valid blockchain and has taken the most effort to build.

Ethereum — Proof of Stake

In the Proof of Stake consensus, miners are chosen based on the Ethers they can stake to guarantee the mining work they can do in the blockchain. When the POS is introduced to Ethereum, 32 Ethers are required for a miner to take part. If a miner cannot put the expected ethers to stake, he can alternatively join the stake pool. A miner gets selected from the stake pool. If the miner successfully mines, signs and verifies the block, the miner gets rewarded with some transaction fees. The amount of Gas is the price a customer is willing to pay for a successful Ether transaction.

Any mining action on the blockchain triggers a malicious activity, the miner loses the ethers he puts to stake, and his rights to mine are revoked. However, for a miner to perform any malicious action, the hacker should have 51 % stake in the network; such a high amount to stake is practically impossible. Below are a few points on POS.

  1. In Proof Of Stake consensus, a miner can play the role of staker or be a validator, 32 ETHERs are required. If a miner does not have enough to stake, then to participate in mining, he can join the POS staking pool.
  2. The Validators are chosen randomly from the group of stakers. On Ethereum, Group of validators (128 stakers) will either commit blocks to the blockchain or validate the blocks.
  3. In the POS, the blocks are divided into chains and shards. Shard chains allow Ethereum to create multiple blocks simultaneously, increasing transaction throughput and secure sharding.
  4. What is a shard chain? The blockchain is broken into multiple blocks to reduce the complexity of the blocks that are mined. The group of such blocks combine to form a shard chain. The Beacon Chain will coordinate the understanding required to manage the shard chains. Beacon Chain continuously scans, validates, collects votes, and rewards the validators that correctly attest to blocks, deducting rewards for those not online and slashing the ETH from malicious actors.
  5. A POS 51% stake attack is still possible, but the risk of losing such a large sum of money with 51% stake makes the attack uninteresting. The more significant the stake, the larger the motivation to keep the blockchain healthy.
  6. POS is comparatively less resource intensive than POW, but POS is not yet battle-tested to be robust in the real-world blockchain market.

Ethereum ERC -20 Standard

ERC 20 is the standard on which we build the Ethereum tokens. The tokens on the Ethereum blockchain will have to follow the ERC 20 standards. The ERC-20 standard has specific methods which are mandatory that have to be implemented for a token to be valid. The required methods to implement are :

TotalSupply, Transfer, BalanceOf, Approve, Allowance, TransferFrom

The ERC-20 tokens are coded as smart contracts and executed on decentralized Ethereum Virtual Machine (EVMs). The standards have specific interfaces that require implementation as to how token-based transfer and approval takes place. The developers use the Solidity programming language to implement the ERC-20 tokens. Solidity is similar to Javascript / Java language in syntax and easy to use (business-friendly).

The optional interfaces are TokenName, Symbol and Decimal ( to 18).

ERC 20 Standard — Code interfaces

ERC stands for Ethereum Request for Comment. The number 20 is assigned to this request.

As mentioned above, to be compliant with the ERC-20 token, the following standards should be implemented. These methods are divided into mandatory and optional tokens.

function totalSupply() public view returns (uint256);
function balanceOf(address tokenOwner) public view returns (uint);
function allowance(address tokenOwner, address spender)
public view returns (uint);
function transfer(address to, uint tokens) public returns (bool);
function approve(address spender, uint tokens) public returns (bool);
function transferFrom(address from, address to, uint tokens) public returns (bool);

The tokens that implement those standards execute the commands to check the wallet’s balance and make transfers with proper authorization.

Ethereum Virtual Machine

  • Every node in the Ethereum blockchain runs an EVM that is a virtualized environment that executes smart contracts. EVM is not a hardware component but a virtualized environment like the Java Virtual Machine (JVM).
  • EVM is an independent virtual component with millions of lines of code and data running on Ethereum. EVM provides a sandbox for the smart contracts to run before it is submitted to the main blockchain. The smart contracts are written using solidity or any other similar language, compiled as byte code, and run on the EVM. .

The simplified architecture of EVM has the following components. -
EVM state.
Stack Memory
Bycode code state
Physical storage

  • Figure : Ethereum Virtual Machine Context
  • The EVM world state is stored in persistent storage. The EVM execution model uses stack and volatile memory. Compiled smart contract bytecode executes as a number of EVM opcodes, which perform standard stack operations like AND, ADD, SUB.
  • An EVM is a state machine whose execution is limited by a finite number of execution steps. This is controlled by the limited gas supply for each transaction.
  • A limited supply of Gas is used per transaction to avoid EVM threads and buffers overflowing and also to prevent an infinite loop execution of smart contracts .
  • The execution in EVM is single-threaded. There is an EVM scheduling component that is external to EVM.
  • EVM uses a memory stack to execute the smart contract compiled into the bytecode. It has input, outputs and permanent memory storage. It has an immutable code (compiled smart contract), volatile memory and permanent storage (zero-initialized).
  • The EVM stores all in-memory values on a stack. It uses a word size of 256 bits and has several addressable data components to facilitate hashing and elliptic curve operations.

The following components make the stack:

  • An immutable program called ROM
  • A volatile memory, every location of the memory initialized to zero.
  • A permanent memory initialized to zero.
  • The different operations that can be executed on EVM are
  • Bitwise and arithmetic operations
  • Control logic operations.
  • Access to stack, memory and storage
  • Logging and other operators
  • Execution context access

Ethereum Virtual Machine functional components

EVM Machine space

The EVM space has the stack memory, the volatile memory and the persistent storage memory.

EVM Stack

The EVM code runs on the virtual machine, and the commands are executed on the stack. The different operations like push, copy swap. The read/write are based on 256-bit operations.

EVM Memory

The EVM memory is linear, is initialized to zero and is addressed at the byte level. It could be an 8-bit store or 256-bit store. Different instructions are:

POP //Remove the top item from the stack
MLOAD //Load a word from memory
MSTORE //Save a word to memory
MSTORE8 //Save a byte to memory

EVM Code

The smart contract code written using a high-level language gets compiled to bytecode and gets executed on the EVM natively.

EVM Account Storage

EVM Storage is a key-value store that maps 256-bit words to 256-bit words. Storage can be accessed with SSTORE/SLOAD instructions. The storage locations are initially defined as zero.

High level Code execution flow in EVM

  • The high-level code gets compiled into EVM byte code.
  • The bytecode has the necessary instructions for specific operations.
  • There is an initial store of fuel called Gas to initiate the transaction. The instructions are executed on the stack.
  • The intermediate values of the stack are stored in volatile memory.
  • The final values and the stored in the account storage (persistent).

This post discusses a few concepts of Ethereum blockchain, viz what is a Ether, Gwei, the gas price, Proof of Stake, Ethereum Virtual Machine and it functional components. Read more articles on IAM & Security @https://iamblockc.medium.com/

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

Also, Read

--

--

Mat David
Coinmonks

I am an Identity & Access Management Consultant. My tech. writing interests are IAM (Forgerock, Oracle,Auth0,OKTA ). https://iamsolution.ca; info@iamsolution.ca