This series will provide answers to the list of Solidity interview questions that were published by RareSkills.
As of the Shanghai upgrade, the gas limit per block is 30 million. This means that the total amount of gas spent on all transactions in a block must be less than 30 million. This is how the number of transactions per block is limited.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
contract GasLimitExample {
uint256 public counter = 0;
/**
* This function's gas usage could hit the block limit of 30 million gas,
* if it is called with a high enough "_count" and enough gas is provided
* for execution.
*/
function loopIncrement(uint256 _count) public {
for (uint256 i = 0; i < _count; i++) {
counter += 1;
}
}
}
Further Discussion:
Although the gas limit per block is 30 million, the gas target per block is 15 million.