Skip to content
Business logic Audit finding Intermediate

GetClaimableFlux miscalculates claimable FLUX f

The getClaimableFlux function in FluxToken.sol uses an incorrect formula to calculate the FLUX a veALCX holder would earn over a year, leading to wrong claimable amounts. This causes a permanent loss of value for NFT holders claiming FLUX.

Holterhus Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

31486 - [SC - High] getClaimableFlux miscalculates claimable FLUX f...

Submitted on May 20th 2024 at 09:53:00 UTC by @Holterhus for Boost | Alchemix

Report ID: #31486

Report type: Smart Contract

Report severity: High

Target: https://github.com/alchemix-finance/alchemix-v2-dao/blob/main/src/FluxToken.sol

Impacts:

  • Permanent freezing of unclaimed royalties

Description

Brief/Intro

When NFT holders claim FLUX, the base claimableFlux amount is calculated based on veALCX values, but the formula is implemented incorrectly which leads to the wrong results.

Vulnerability Details

claimableFlux is intended to calculate the amount of FLUX that would be earned in 1 year, assuming max lock was enabled.

This should be calculated as follows:

amount * fluxPerveALCX * maxLockMultiplier * numEpochsInOneYear

(This is because, each epoch, it would earn amount * fluxPerVeALCX * maxLockMultiplier.)

This can be expressed in Solidity as:

Solidity
claimableFlux = (_amount * fluxPerVe * veMul * veMax) / (BPS * WEEK * 2)

Instead, it is calculated as follows:

Solidity
claimableFlux = (((bpt * veMul) / veMax) * veMax * (fluxPerVe + BPS)) / BPS / fluxMul;

There are a number of issues with this calculation (ignoring that bpt is used instead of _amount, as that is covered in a separate submission):

  1. We multiply and divide by veMax, rather than dividing by the length of time of one epoch in order to get the number of epochs in MAXTIME.
  2. We do (fluxPerVe + BPS) / BPS instead of simply fluxPerVe / BPS, which gives us a 150% payout per Ve rather than the 50% that is intended.
  3. We divide by fluxMul, which does not appear to be relevant.

Impact Details

This will result in the wrong amount of FLUX being calculated when NFT holders claim FLUX. This leads to a permanent loss of value to the claimers of the FLUX.

References

FluxToken.sol

Proof of Concept

The following test can be added to FluxToken.t.sol. It should show that different values arise for the calculated claimable FLUX amount and the actual amount that is accrued for a year.

function test_IncorrectClaimableFlux() external {
    vm.startPrank(admin);
    uint256 amount = 1e18;
    uint256 bptAmount = flux.calculateBPT(amount);

    uint256 claimableFluxCalc = flux.getClaimableFlux(amount, patronNFT);
    uint256 tokenId = createVeAlcx(admin, bptAmount, veALCX.MAXTIME(), false);

    // Claim 365 days of flux with this lock
    for (uint256 i; i < 365; ++i) {
        uint256 currentEpoch = (block.timestamp / 2 weeks) * 2 weeks;
        if (currentEpoch > voter.lastVoted(tokenId)) voter.reset(tokenId);
        vm.roll(block.number + 1);
        vm.warp(block.timestamp + 1 days);
    }

    console.log("FLUX balance at end of year:", flux.getUnclaimedFlux(tokenId));
    console.log("Calculated FLUX:", claimableFluxCalc);

    vm.stopPrank();
}

The original report as published on Immunefi, by Holterhus. 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 formula multiplies and divides by the maximum lock multiplier instead of dividing by the epoch length, adds BPS to fluxPerVe before dividing, and divides by an irrelevant fluxMul factor.

Impact

This could lead to a permanent loss of value for NFT holders claiming FLUX because the calculated claimable amount is wrong.

What the attacker needed

None

The fix

The formula should be corrected to multiply the amount by fluxPerVe, the max lock multiplier, and the number of epochs in a year, then divide by BPS and the epoch length.

How it was found

  1. Deploy the contract and set up an admin account.
  2. Calculate the BPT amount corresponding to a given FLUX amount.
  3. Call getClaimableFlux with the amount and a patron NFT to get the calculated claimable FLUX.
  4. Create a veALCX lock with the BPT amount for the maximum lock time.
  5. Simulate 365 days by advancing time and resetting votes each epoch.
  6. Compare the unclaimed FLUX after a year with the calculated claimable FLUX.

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.

When you lock tokens in a voting escrow, you earn a reward token called FLUX over time. The contract has a function that estimates how much FLUX you would earn in a year, but the formula is wrong, so the estimate is too high or too low. This means users might get less FLUX than they should, and the mistake cannot be corrected later.

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 Holterhus

View all

7 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.