Keepers loss gas is never accounted
The gas fee processing function incorrectly calculates the loss fee when the actual execution fee exceeds the user's provided fee, always resulting in zero loss fee. This means keepers' excess gas losses are never recorded, causing them to lose funds over time.
Source: https://github.com/sherlock-audit/2024-05-elfi-protocol-judging/issues/108
Found by
4rdiii, KupiaSec, PNS, Yuriisereda, ZeroTrust, aman, brakeless, chaduke, dany.armstrong90, dethera, mstpr-brainbot, nikhil840096, pashap9990, qpzm, whitehair0330
Summary
When keepers send excess gas, the excess gas is accounted in Diamonds storage so that keeper can compensate itself later. However, losses are never accounted due to math error in calculating it.
Vulnerability Detail
Almost every facet uses the same pattern, which eventually calls the GasProcess::processExecutionFee function:
function processExecutionFee(PayExecutionFeeParams memory cache) external {
uint256 usedGas = cache.startGas - gasleft();
uint256 executionFee = usedGas * tx.gasprice;
uint256 refundFee;
uint256 lossFee;
if (executionFee > cache.userExecutionFee) {
executionFee = cache.userExecutionFee;
// @review always 0
lossFee = executionFee - cache.userExecutionFee;
} else {
refundFee = cache.userExecutionFee - executionFee;
}
// ...
if (lossFee > 0) {
CommonData.addLossExecutionFee(lossFee);
}
}
As we can see in the snippet above, if the execution fee is higher than the user's provided execution fee, then the execution fee is set to cache.userExecutionFee, and the loss fee is calculated as the difference between these two, which are now the same value. This means the lossFee variable will always be "0", and the loss fees for keepers will never be accounted for.
Impact
In a scaled system, these fees will accumulate significantly, resulting in substantial losses for the keeper. Hence, labelling it as high.
Code Snippet
Tool used
Manual Review
Recommendation
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/0xCedar/elfi-perp-contracts/pull/40
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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
Likely a logic error: after capping the execution fee to the user's fee, the loss fee is computed as the difference between the capped fee and the user's fee, which is always zero.
Impact
Keepers' excess gas losses are never accounted for, leading to substantial cumulative losses for keepers in a scaled system.
What the attacker needed
Keeper executes transactions; actual gas cost exceeds user fee
The fix
The loss fee should be calculated as the original execution fee minus the user's execution fee before capping, and the issue was fixed in a pull request.
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.
Keepers are automated bots that execute transactions for users and get reimbursed for gas. If the actual gas cost is higher than what the user paid, the keeper should be able to claim the difference later, but a coding mistake means that difference is always recorded as zero, so keepers lose money.
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.