Skip to content
Business logic Audit finding Intermediate

Incorrect earnings calculation in `removeValueSingle()` function causes partial user losses

The removeValueSingle() function calls the asset's remove() before updating the closure's earnings per value, so the asset's collect() uses outdated earnings data. This causes users to lose part of their earned rewards when removing value.

Drynooo Follow with TessKimy, bladeee and 5 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-04-burve-judging/issues/422

Found by

Drynooo, TessKimy, bladeee, future, h2134, nganhg, rsam_eth, zark

Summary

Asset removal before invoking trimBalance() in removeValueSingle() function causes partial loss of user earnings, as the asset's remove() function uses outdated earnings per value variable to calculate user collected earnings.

Root Cause

In ValueFacet.sol:229 the asset's remove() function is invoked prior to the closure's removeValueSingle(). (resulting in outdated earnings per value calculations) In Asset.sol:114 the asset's remove() function invoke collect function. In Asset.sol:143 the asset's collect() function gets outdated earnings per value from the closure.

Internal Pre-conditions

  1. Closures deposit their fee earnings into an active vault.

External Pre-conditions

  1. Vault distributes reward to closures.

Attack Path

  1. User call removeValueSingle() function.

Impact

Users may experience a loss exceeding 1% of their earnings if the pool is not sufficiently active, causing the earnings per value to remain outdated for an extended period.

PoC

Solidity
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.27;

import {Test} from "forge-std/Test.sol";
import {console2} from "forge-std/console2.sol";
import {SimplexDiamond as BurveDiamond} from "../../src/multi/Diamond.sol";
import {SimplexFacet} from "../../src/multi/facets/SimplexFacet.sol";
import {SwapFacet} from "../../src/multi/facets/SwapFacet.sol";
import {ValueFacet} from "../../src/multi/facets/ValueFacet.sol";
import {VaultFacet} from "../../src/multi/facets/VaultFacet.sol";
import {MockERC20} from "../mocks/MockERC20.sol";

contract PoC1 is Test {
    address payable diamond;
    BurveDiamond public burveDiamond;
    SimplexFacet public simplexFacet;
    SwapFacet public swapFacet;
    ValueFacet public valueFacet;
    VaultFacet public vaultFacet;
    uint16 cid = 3;

    address user = address(1);
    address randomUser = address(2);
    address fakeRewardDistributor = address(3);
    address[] tokens;
    address[] vaults;

    uint128 addValue = 10_000;
    uint128 bgtValue = 1_000;
    uint256 tokenAmount = 1000 * 1e18;

    function setUp() public {
        // address received after run script/Deploy.s.sol
        diamond = payable(0xa513E6E4b8f2a923D98304ec87F64353C4D5C853);
        burveDiamond = BurveDiamond(diamond);
        simplexFacet = SimplexFacet(diamond);
        swapFacet = SwapFacet(diamond);
        valueFacet = ValueFacet(diamond);
        vaultFacet = VaultFacet(diamond);

        // get tokens list
        tokens = simplexFacet.getTokens();

        // get vaults list
        vaults = new address[](tokens.length);
        for (uint256 i = 0; i < tokens.length; i++) {
            (vaults[i], ) = vaultFacet.viewVaults(tokens[i]);
        }

        vm.deal(user, 1000 * 1e18);
        vm.deal(randomUser, 1000 * 1e18);
        for (uint256 i = 0; i < tokens.length; i++) {
            deal(tokens[i], user, type(uint256).max);
            deal(tokens[i], randomUser, type(uint256).max);
            deal(tokens[i], fakeRewardDistributor, type(uint256).max);
            vm.startPrank(user);
            MockERC20(tokens[i]).approve(diamond, type(uint256).max);
            vm.stopPrank();
            vm.startPrank(randomUser);
            MockERC20(tokens[i]).approve(diamond, type(uint256).max);
            vm.stopPrank();
        }

        // User adds liquidity
        vm.startPrank(user);
        valueFacet.addValue(user, cid, addValue, bgtValue);
        vm.stopPrank();

        // fake vault reward distribution
        vm.startPrank(fakeRewardDistributor);
        for (uint256 i = 0; i < tokens.length; i++) {
            MockERC20(tokens[i]).transfer(vaults[i], tokenAmount);
        }
        vm.stopPrank();
    }

    function testNormalRemoveValueSingle() public {
        // User removes value
        vm.startPrank(user);
        valueFacet.removeValueSingle(user, cid, addValue, bgtValue, tokens[0], 0);

        // User collects earnings
        (uint256[16] memory collectedBalance, uint256 collectedBgt) = valueFacet
            .collectEarnings(user, cid);
        vm.stopPrank();

        for (uint256 i = 0; i < tokens.length; i++) {
            console2.log(
                "Collected balance of token %s: %s",
                tokens[i],
                collectedBalance[i]
            );
        }
    }

    function testRemoveValueSingleAfterCallTrimBalances() public {
        // Random user adds value => triggers trimBalances()
        vm.startPrank(randomUser);
        valueFacet.addValue(randomUser, cid, addValue, bgtValue);
        vm.stopPrank();

        // User removes value
        vm.startPrank(user);
        valueFacet.removeValueSingle(user, cid, addValue, bgtValue, tokens[0], 0);

        // User collects earnings
        (uint256[16] memory collectedBalance, uint256 collectedBgt) = valueFacet
            .collectEarnings(user, cid);
        vm.stopPrank();

        for (uint256 i = 0; i < tokens.length; i++) {
            console2.log(
                "Collected balance of token %s: %s",
                tokens[i],
                collectedBalance[i]
            );
        }
    }
}

Mitigation

Move the asset's remove() function below the closure's removeValueSingle().

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/itos-finance/Burve/pull/69

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

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 order of operations is wrong: the asset's remove() is called before the closure's removeValueSingle() updates the earnings per value, so collect() reads stale data.

Impact

Users may lose more than 1% of their earnings if the pool is not sufficiently active, because the earnings per value stays outdated for a long time.

What the attacker needed

Closures deposit fees into an active vault; Vault distributes rewards to closures

The fix

The asset's remove() function should be moved below the closure's removeValueSingle().

How it was found

  1. User calls removeValueSingle() function.

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 remove funds from a pool, the system should first update how much reward you have earned. Here it removes your funds before updating that reward calculation, so you get less reward than you should. This means you lose a small part of what you earned.

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 Drynooo

View all

4 more disclosed reports, best first.

More from Burve

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.