Lagging median gas price when the set of observers changes
The median gas price calculation in ZetaChain includes stale votes from inactive observers, causing the computed gas price to lag behind the actual market price. This can lead to outbound transactions being underpriced and stuck in the mempool, and users underpaying gas fees.
berndartmueller Follow with deliriusz and p0wd3r
Originally disclosed on Code4rena
Submitted by berndartmueller, also found by deliriusz and p0wd3r
The median gas price used within ZetaChain may be inaccurate and lagging, causing outbound transactions to be underpriced and pending in the mempool and gas fees to be underpaid by users.
Proof of Concept
ZetaChain observers, i.e., zetaclients, watch the gas prices of the external chains and submit the current prices to ZetaChain by broadcasting the MsgGasPriceVoter message. This message is processed by the GasPriceVoter function in node/x/crosschain/keeper/keepergasprice.go#L125-L187.
Each observer’s gas price vote is stored in the GasPrice struct in the Prices array and the gas price is determined by using the median of the stored values in line 167.
The number of ZetaChain observers can increase or decrease over time, e.g., due to validator nodes exiting the network, slashing, or observers being removed/added by the admin.
This leads to an issue as there will be stale gas price “vote” entries in the GasPrice.Prices array that will affect the median calculation. As a result, the calculated gas price may be inaccurate and lag behind the actual gas price.
Consider the following example:
Given 9 observers and their gas price votes:
Observer Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
Gas Price | 10 | 5 | 5 | 20 | 15 | 10 | 10 | 40 | 20 |
Sorting the gas prices in ascending order:
Observer Index | 1 | 2 | 5 | 6 | 0 | 4 | 3 | 8 | 7 |
Gas Price | 5 | 5 | 10 | 10 | 10 | 15 | 20 | 20 | 40 |
The median gas price is: 10 (from the observer with index 0)
Now, let’s assume that 4 of the observers (observers 0, 1, 2, 3 - marked with *****) are inactive and do not submit gas price votes anymore. The remaining observers continue to submit gas prices (gas price spiked)
Observer Index | 0* | 1* | 2* | 3* | 4 | 5 | 6 | 7 | 8 |
Gas Price | 10* | 5* | 5* | 20* | 40 | 60 | 70 | 70 | 70 |
Sorting the gas prices in ascending order:
Observer Index | 1* | 2* | 0* | 3* | 4 | 5 | 6 | 7 | 8 |
Gas Price | 5* | 5* | 10* | 20* | 40 | 60 | 70 | 70 | 70 |
The median gas price is: 40 (from the observer with index 4)
As observers 0, 1, 2, and 3 are inactive, their stale gas price votes are still considered in the median calculation, leading to a lagging gas price. If we would ignore the inactive observers, the median gas price would be 70.
This can be mitigated by using the block height of the submitted gas price vote, stored in GasPrice.BlockNums and ignoring stale votes.
Recommended mitigation steps
Consider filtering out stale gas price votes based on the block height of the vote to prevent lagging gas prices.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The median calculation includes gas price votes from observers that are no longer active, because stale entries are not filtered out based on the block height of the vote.
Impact
Outbound transactions could be underpriced and remain pending in the mempool, and users may underpay gas fees.
What the attacker needed
Observers become inactive; stale votes remain in storage
The fix
The gas price calculation should filter out stale votes based on the block height of each vote.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
ZetaChain uses a median of gas prices reported by observers to set transaction fees. If some observers stop reporting, their old votes are still counted, so the median can be too low. This means transactions may pay too little and get stuck.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.