How Ethereum’s Gas Limit is Determined
Originally published on my blog, EleniThinks.com.
Ethereum’s gas limit is often said to be determined by a ‘vote’ by the miners. How this vote actually works is one of the most misunderstood pieces of the Ethereum ecosystem. Here I will explain what it means to ‘vote’ and how we have seen miners vote in the past.
Some background
First, let’s explain a few fundamental points.
Gas Fees
Ethereum is more like a “World’s Computer” than a ledger. Any given transaction can have a set of instructions embedded in it. This means, not all transactions are equal and some require more computational power to execute then others. Transactions that are more computationally complex cost more gas to execute.
Users must pay miners to use gas. Each user can decide for themselves how much they are willing to pay for a unit of gas. Paying more increases the chances a miner will include your transaction since miners want to include the highest paying transactions first.
You can see what some transactions cost here.
The block size
Unlike in Bitcoin, which has 1MB blocks set by the protocol (e.g. the core devs), blocks in Ethereum are not a set size. Instead, the size of the block (i.e. bytes) is determined by the number of transactions that are included in the block. The number of transactions included, in turn, is dependent on the sum of all the gas used to run those transactions.
Instead of setting a block size limit, in Ethereum there is a Gas Limit. The sum of all the transactions in a block must be below this predetermined limit. Hence, the gas limit is related to the block size, but they are not one and the same. While these two fields tend to be directionally related, two blocks which use the same amount of gas may have different byte sizes.
Now, how is the block Gas Limit set? Well, that’s where the elusive “voting” comes in.
The Vote
It’s actually not a vote at all, in the traditional sense at least. To understand what I mean, let’s first, talk about what a block is. A block is simply a header, a list of transactions, and references to past blocks. What we care about here is the header.
The header
The block header contains several pieces of information such as the block number, timestamp and the “gasLimit”. This field is defined as “A scalar value equal to the current limit of gas expenditure per block.”
In English, the miners can decide what value to place in this field, but there is one big constraint: the miner can set the gasLlimit only within +/- 1% of the parent block's (i.e. the prior block) gas limit. Here’s the formula from Ethereum's Yellow Paper for those mathematically inclined.
So, with each new block that a miner makes, she can mine a block 1% bigger or smaller than the last block. In practice, miners are not actively picking this number with each block, but rather setting a target gas limit. A miner will mine blocks pushing the limit up towards the target limit or down if it has passed the target limit.
In practice, this is exactly what we see. Below is a chart of actual block limits over the last 7 days.
Gas Limit Jumps
Sometimes people say “miners changed the gas limit.” While this is technically incorrect (as we’ve shown above, miners change the gas limit with every block) what they really mean is a new gas level is held constant. In practice, what this actually looks like is miners increasing their target gas limits to a new higher point.
On June 19th we saw the prevailing gas limit jump.
This didn’t happen in one go of course. The block size crept up throughout the day.
Conclusion
To bring it all back. Miners don't "vote" at all, rather, they each try to push the gas limit towards their individual gas limit target. The more hash power a miner controls, the more often she is able to vote and the larger influence she has on the prevailing block size. If the majority pushes towards a given level, then that level will hold fairly constant but will "vibrate" up and down due to blocks being mined by the minority pushing for a different level. The natural next question is how are miners determining the “correct” gas limit, but that’s for another post.