The OG Gas Crisis
In 1973, following US support of Israel in the Yom Kippur war, Arab gulf countries used the best weapon they had at their disposal to punish the west: they limited the supply of oil, and drove gas prices up. Since the US at that point imported most of its oil (why ruin your own country when others are perfectly OK with ruining theirs, and selling you oil cheaply?), and since many Americans relied on gas guzzling cars to survive, that move brought the US to a halt. Many stations ran out of gas. In others, there was a limit on the number of gallons you could get. And everywhere, prices went up precipitously, in a short period of time.
I was reminded of that history lesson a couple of days ago, when Ethereum gas prices started reaching unimaginable heights.
What Causing the Ethereum Gas Crisis?
Based on its current technical design, the Ethereum blockchain can process about 15 transactions per second (contrast that with Visa that can handle 27,000 tx/sec). Since Ethereum uses a proof-of-work consensus algorithm, a block of transactions needs to be "mined" in order to be added to the blockchain. To compensate miners for the work they invest to mine (electricity, computing power, network resources), the network pays them a fee called "gas", measured in gwei (a tiny unit of ETH). Miners are incentivized to mine the transactions that would yield the highest fee.
Why does the Gas Price Rise?
To illustrate, let's imagine you're a guard at a bridge crossing, whose only income is tips paid by drivers who cross the bridge. Only one car at a time can cross your bridge.
People are lined up for miles at your crossing, trying to get home, on the other side. Then some of them start waving a dollar bill at you. You take their dollar, and wave them through. People catch on, and start waving a $5 bill. You point to those cars, and prioritize them. A $10 bill appears in someone's hand, and he jumps to the head of the line. Pretty soon, you start seeing $20, $50, and maybe even a $100 from someone who's really in a hurry.
And if you're poor driver, all the way at the back of the line, you start thinking that maybe you should give up, and try crossing tomorrow. But what if tomorrow it only gets worse? And what if our imaginary bridge operates 24/7/365, non-stop, with more drivers trying to cross added by the second?
In the same vain, if you're a miner, and you have several transactions available to mine, you'll look for the ones offering the highest amount of gas. People will catch on, and start offering more gas, hoping to entice miners to mine their transactions first. This creates a cycle of ever-rising prices. Until there's a lull (people go to sleep somewhere, there's a saturation, or more commonly, a drop in price/return rate) and price drop back to "normal". But those "normals" keep getting higher, and higher, and higher...
Why is this Happening Now?
The success of DeFi, and other Ethereum based products (e.g. Unstoppable Domains, Crypto Kitties, and even Publish0x) drives people to perform more and more transactions on the blockchain. Projects like Uniswap and Balancer, that make token exchange easy, contribute hundreds of thousands of transactions to the net. These cause the already limited bottleneck to get narrower. Many of those transactions are highly time sensitive: you wait too long, and the price of the token you wanted goes up (or down) netting you more/less tokens, or in some cases, failing your transaction entirely.
The Etherscan Gas Tracker shows average gas prices. It also shows you the contracts that consume the most gas ("gas guzzlers"). At the top of the list is Uniswap-V2, with almost $1.5 million in gas fees over the last 24 hours (let that number sink in...)
There are several gas calculators (my favorite is EthGasStation - also check out their Chrome extension) that allow you to calculate how long will your transaction take to execute for a gas price you pay (those are estimates - real numbers can change in real time). But when all calculators start suggesting prices are running up, you either get a head of the herd, catch up to the herd, or get left behind.
So far this week, the highest I've seen is 269 gwei for an average transaction (!!!) (meaning you'll have to pay even more to get your transaction handled faster). And I do not think we've seen the top yet. Things are so bad, that converting between coins was at a minimum of $30 in gas at one point.
What Dictates My Transaction Price?
3 factors that dictate your $ price for a transaction:
1. The price of gas - this is variable, and goes up/down based on the number of people competing with you for the miners' attention.
2. The ETH-USD price - gas is paid in ETH. The higher ETH is, the more $ you pay.
3. The complexity of the contract you're trying to execute - this will dictate how many units of gas are needed to complete the transaction.
Assuming 1 and 2 are out of your control, let's look at factor 3:
The simplest contract you can execute on a blockchain, is an ETH transfer. Transferring ETH is a basic operation, that require checking the payer has enough ETH to pay (that'd be the sum transferred + gas fee), debiting the payer, and crediting the payee.
Contrast that with a complex contract that converts between 2 tokens: you have to: debit an amount of TokenA from the wallet, convert TokenA to ETH, convert ETH to TokenB, credit the wallet with TokenB. Along the way, the prices of ETH, TokenA and TokenB might change, so you need to check for slippage: how much above/below a certain amount is the user willing to tolerate. On top of that, you have a time limit, after which you kill the transaction and revert the original funds... Quite a lot of logic, and therefore, more gas to pay.
And if you think a conversion contract is complex, you haven't seen some of the DeFi contracts out there (look at an Aave Flash Loan contract to get the potential scope).
Is There a Solution?
There are articles that suggest you can time your transactions, such that you pay the least amount of gas (here's one). The last week and a half proven these theories mostly wrong, with gas prices being high 24/7 (remember the "new normal" theory?).
There are some technical solutions suggested (like CHI token offered by 1Inch, or L2 contract bundling) but they come with their own limitations (CHI liquidity is low, and you need to pay gas to get it 😁; L2 is great but you need to be a developer to implement it, etc.).
It looks like, on a personal level, you should try to execute transactions where the impact of a high fee is negligent compare to the gains. Avoid small transactions, and avoid jumping from token to token on a whim.
Hope in the Future: Ethereum 2.0
Ethereum 2.0 is the proposed next generation of the Ethereum blockchain. Currently it's at an early testnet phase. Some (very) optimistic people think it'll come to mainnet in 2021. Once it does, it promises to do a couple of things:
- Change the consensus algorithm from Proof of Work to Proof of Stake.
- Allow a much higher number of transactions per second.
- Operate several sub-blockchains ("shards") at the same time.
All these will change the economy behind fees, and drive gas prices down. But they are still a future promise.
Also important to remember: ETH 1.0 will still be around for a while - even with ETH 2.0 running. All the current contracts will stay operational, along with the gas concerns.
Remember the 1973 crisis? the US came out of it stronger: The gas/mileage of cars improved, local oil resources were developed, and maybe one day alternate sources would replace oil altogether (despite big oil corporations doing their best to slow/derail the efforts).
My hope is that this gas crisis will solve itself as well - perhaps a drop in prices, or a rush out of some DeFi contracts. Until then, it looks like we'll have to wait to ETH 2.0, time the market as best we can, and grind our teeth as we pay higher gas fees.