Skip to content
Business logic Audit finding Intermediate

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.

MahdiKarimi Follow

Originally disclosed on Immunefi

Critical View original
  • 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

https://github.com/alchemix-finance/alchemix-v2-dao/blob/f1007439ad3a32e412468c4c42f62f676822dc1f/src/RevenueHandler.sol#L245-L264

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)));
        
    }

The original report as published on Immunefi, by MahdiKarimi. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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.

More by MahdiKarimi

View all

11 more disclosed reports, best first.

More from Alchemix

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.