Skip to main content

Gas fees

Basics of gas fees

Gas fees are an important mechanism for Proof-of-stake networks. Whenever one sends a transaction to a blockchain, they must pay gas fees. And the reason why they exist stems from the Turing completeness concept of computer programs. This concept states that we can not predict when a computer program will halt until we actually run it, which enables the possibility of infinite loops.

As the Ethereum Virtual Machine is a network of computers, which we call nodes, it is also considered Turing complete. All the software running on this machine could theoretically run forever and damage its functioning. This is in fact a kind of hacking attack which is called Denial of Service. Ill-intentioned individuals could deploy smart contracts that would run endlessly and thus compromise the integrity of the network.

The solution to DoS attacks

Enter Gas fees. They were introduced as a metering mechanism for constraining resources. Every single application deployed on the EVM has to pay fees. Those fees are calculated according to the number and kind of instructions involved in the program.

Transactions sent by users trigger smart contracts that include the upper limit of gas that can be consumed during their execution. The gas is bought with Ether and this token is sent along with the transaction with an acceptable gas price. Ethereum halts the execution of the program if that limit is surpassed.

The mechanism is in fact ingenious but it has its own flaws. Users had to bid a gas price to get their transactions included in a block. This could lead to unpredictable and often high fees, especially during times of network congestion.

Dynamic gas fees

Dynamic gas fees were introduced on Ethereum with the implementation of the Ethereum Improvement Proposal (EIP) 1559, also known as the "London hardfork." This update changed the transaction fee mechanism, introducing a base fee that adjusts dynamically based on network demand and includes an optional priority fee to speed up transactions.

After the London hardfork, each block has a base fee, which is the minimum amount of gas that users must pay for their transactions to be included. This base fee is burned and adjusts automatically based on the network's demand. If the network is busy, the base fee increases; if the network is idle, the base fee decreases.

Other important features

This proposal also introduced a few other features that improved the user experience:

  • Users can also include a tip to incentivize miners to prioritize their transactions over others. This tip goes directly to the miners as a reward.
  • The block gas limit can expand or contract to allow more transactions when there is high demand, making fees more stable and predictable.

After EIP-1559, fees became more predictable. The dynamic adjustment of the base fee helps in making transaction costs more predictable. Users no longer need to overbid to ensure their transactions are included in a block, reducing the likelihood of paying excessively high fees. Furthermore, since the base fee is burned, this introduces a deflationary mechanism to the Ethereum supply, potentially increasing the value of ETH over time.

Delhi hardfork

Although the London hardfork introduced an interesting solution to the gas issue, during high demand, there have still been gas spikes due to a rapid increase in the base fee.

On Ethereum, a series of constant full blocks will increase the gas price by a factor of 10 every ~20 blocks; while on the Polygon PoS chain (and thus on Shibarium), since the block time is 2 secs, the base fee goes 10x in just 40 seconds.

High gas prices cause congestion in the network: the base fee starts climbing and transactions get stuck as a result of that increase. Transactions will only go through and be added to blocks when those fees get lower again. While that doesn’t happen, applications that are dependent on transactions tend to deliver poor experiences.

Base Fee Change Denominator

The solution to this new challenge was proposed by the Polygon team and came in the form of another hardfork, now in the Polygon PoS network: the Delhi hardfork. The Shibarium team following this update, also hardforked its network and included the change of the BaseFeeChangeDenominator.

Delhi hardfork proposes the change of the Base Fee Change Denominator from the current value of 8 to 16. This smoothens the variation of the base fee when the gas used in blocks is higher(/lower) than the target gas limit. After this change, the rate of change decreases to 6.25% (100/16) as compared to the previous 12.5% (100/8).