ETHEREUM: Demystifying The Concept Of Gas.
The EVM is a quasi–Turing-complete state machine; "quasi" because all execution processes are limited to a finite number of computational steps by the amount of gas available for any given smart contract execution. This might sound a bit technical, let’s break it down. You can write a script to run on a user's browser that would just run a while loop infinitely, this script would run until the computer no longer has the resources to continue, then the system would crash.
This same scenario could have been the fate of the Ethereum World Computer (EVM) if the concept of gas was not implemented. If the concept of gas was not implemented, a smart contract programmer could just program a solidity script that would run an infinite, remember, all the miners run the EVM and that infinite loop we are talking about would literally be running on their mining machine keeping it occupied with irrelevant tasks now the system is placed on a halt no transaction can be processed during this time, this is popularly known in the cybersecurity world as a Distributed Denial Of Service Attract (DDoS).
Now with the gas implementation, early operation on the EVM cost some amount of gas which is paid for in Ethereum native token [ether]. Should a transaction be in process and the gas gets exhausted, the transaction is halted and the spent gas fee is not refunded.
Gas Before the London Fork
The London fork was proposed to handle the problem of high gas fees and the irregularity of the gas chart. Before the London fork, paying gas was more like an auction where the highest bidder get his/her transaction mined first. This system is not fair to the users because if they need to process an arbitrage transaction which needs to be processed fast they would need to pay a high gas fee and in this gas system, the gas price increases exponentially during network congestion, this only favors the miner.
How gas fee is calculated before the London fork
Gas fee before the London fork was calculated using this formula,
gas_fee = gas_price * gas_cost
Where gas cost is the cost in units of gas, this was determined by the current network congestion and gas price is how much ether a user is willing to pay for each unit of gas, this is controlled fully by the user or the wallet provider e.g. Metamask. Though the user has full control over the gas price, the user can’t just set it as zero because the miners would not be incentivized to put up the transaction from the mempool.
Gas After The London Fork
The London fork which happened in August 2021 introduced a new gas system. First the Ethereum max gas limit for a block was 12.5M gas units; during the London fork, the max gas limit was pumped up to 25M gas units. With this, the block can accommodate more transactions.
In the London fork, the base fee concept was introduced. The base fee represents a minimum amount of gas that must be paid for a transaction to be included in a block.
The London fork was introduced to place the gas system of Ethereum in equilibrium such that when the network usage is higher that 50% utilization the base fee increases, when less the base fee reduces.
A miners tip was introduced for those transactions that need fast confirmation, the user needing this functionality can include the tip when sending the transaction.