Miscalculation of distributed tokens at revenue
The revenue handler calculates the amount to distribute using the contract's total balance, so unclaimed rewards from previous distributions are counted again as new revenue. This lets some users claim more than their fair share while others cannot claim their rewards.
Originally disclosed on Immunefi
- Disclosed after under an hour
31485 - [SC - Critical] Miscalculation of distributed tokens at revenue...
Submitted on May 20th 2024 at 06:40:34 UTC by @MahdiKarimi for Boost | Alchemix
Report ID: #31485
Report type: Smart Contract
Report severity: Critical
Target: https://github.com/alchemix-finance/alchemix-v2-dao/blob/main/src/RevenueHandler.sol
Impacts:
- Theft of unclaimed yield
Description
Brief/Intro
Revenue handler uses contract balance to calculate distribution amount, so if users didn't claim their rewards from the last distribution, unclaimed amount is mistakenly considered as newly distributed rewards
Vulnerability Details
Every time the checkpoint is called at revenue handler to distribute revenues, it uses the contract balance as the amount to be distributed. However, if some users haven't claimed their rewards from previous distributions, those unclaimed rewards are mistakenly considered as newly distributed rewards so some users can receive more rewards while others can't receive their rewards.
Impact Details
Inconsistency between contract balance and user claimable amount enables some users to receive more rewards while some users are not able to receive any rewards
References
Proof of Concept
function testClaimAfterNextCheckpoint() external {
uint256 revAmt = 1000e18;
uint256 tokenId = _setupClaimableNonAlchemicRevenue(revAmt, bal);
uint256 tokenId2 = _setupClaimableNonAlchemicRevenue(revAmt, bal);
uint256 claimable = revenueHandler.claimable(tokenId, bal);
uint256 claimable2 = revenueHandler.claimable(tokenId2, bal);
// as we see contract balance is not sufficient for claimable amount
assert(claimable > IERC20(bal).balanceOf(address(revenueHandler)));
assert(claimable + claimable2 > IERC20(bal).balanceOf(address(revenueHandler)));
}
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 the distribution logic uses the contract's current token balance as the total amount to distribute instead of tracking only newly added revenue, so unclaimed balances are double-counted.
Impact
Some users could receive more rewards than they are owed while others may be unable to claim any rewards, causing theft of unclaimed yield.
What the attacker needed
Unclaimed rewards from a previous distribution
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.
A smart contract distributes rewards to users. It decides how much to give out by looking at how many tokens it currently holds. If some users have not yet collected their earlier rewards, those tokens are still sitting in the contract, so the contract thinks they are new money and hands them out again. This means early claimers can take too much, leaving later users unable to get their share.
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.