Skip to content
Business logic Audit finding Advanced

Invariant Breaking1

The addValue function in the Burve protocol increases both the closure's balances and targetX128 proportionally without enforcing the deMinimus limit, causing the difference between the sum of values and the target to grow beyond the designed invariant. An attacker could exploit this to break the invariant and potentially cause unfairness for users.

0xNov1ce Follow with future

Originally disclosed on Sherlock

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

This issue has been acknowledged by the team but won't be fixed at this time.

Found by

0xNov1ce, future

Summary

In the addValue function, both Closure.balances and Closure.targetX128 increase proportionally without control by the deMinimus. Consequently, the delta between the sum of values and the target also increases, which could lead to exceeding the designed limits.

Root Cause

https://github.com/sherlock-audit/2025-04-burve/tree/main/Burve/src/multi/closure/Closure.sol#L127-L142

Solidity
    function addValue(
        Closure storage self,
        uint256 value,
        uint256 bgtValue
    ) internal returns (uint256[MAX_TOKENS] memory requiredBalances) {
        trimAllBalances(self);
        // Round up so they add dust.
        uint256 scaleX128 = FullMath.mulDivX256(
            value,
            self.n * self.targetX128,
            true
        );
        uint256 valueX128 = value << 128;
        // Technically, by rounding up there will be a higher target value than actual value in the pool.
        // This is not an issue as it causes redeems to be less by dust and swaps to be more expensive by dust.
        // Plus this will be fixed when someone adds/removes value with an exact token amount.
127:    self.targetX128 +=
            valueX128 /
            self.n +
            ((valueX128 % self.n) > 0 ? 1 : 0);
        self.valueStaked += value;
        self.bgtValueStaked += bgtValue;
        // Value is handled. Now handle balances.
        for (uint8 i = 0; i < MAX_TOKENS; ++i) {
            if (!self.cid.contains(i)) continue;
            requiredBalances[i] = FullMath.mulX128(
                scaleX128,
                self.balances[i],
                true
            );
            // This happens after because the vault will have
142:        self.setBalance(i, self.balances[i] + requiredBalances[i]);
        }
    }

Internal pre-conditions

N/A

External pre-conditions

N/A

Attack Path

N/A

PoC

  1. Add this function:

https://github.com/sherlock-audit/2025-04-burve/tree/main/Burve/src/multi/closure/Closure.sol#L893

Solidity
    function realValue(Closure storage self) internal returns (uint256 _realValueX128) {
        uint256[MAX_TOKENS] storage esX128 = SimplexLib.getEsX128();
        for (uint8 i = 0; i < MAX_TOKENS; ++i) {
            if (!self.cid.contains(i)) continue;
            _realValueX128 += ValueLib.v(self.targetX128, esX128[i], self.balances[i], false);
        }
    }
  1. Change this function:

https://github.com/sherlock-audit/2025-04-burve/tree/main/Burve/src/multi/facets/ValueFacet.sol#L280

Solidity
    function queryValue(address owner, uint16 closureId) external 
        returns (
            uint256 valueX128,              
            uint256 targetX128,           
            uint256[MAX_TOKENS] memory,
            uint256 deMinimusX128         
        ) {
        ClosureId cid = ClosureId.wrap(closureId);
        Closure storage c = Store.closure(cid); // Validates cid.
        valueX128 = c.realValue();
        targetX128 = c.targetX128;
        SearchParams memory search = Store.simplex().searchParams;
        deMinimusX128 = uint256(search.deMinimusX128);
    }
  1. Add this testing function:

https://github.com/sherlock-audit/2025-04-burve/tree/main/Burve/test/facets/ValueFacet.t.sol

Solidity
    function test_invariant1() public {
        SearchParams memory sp = SearchParams(10, 500 << 128, 1e18);
        vm.prank(owner);
        simplexFacet.setSearchParams(sp);

        valueFacet.addSingleForValue(alice, 0x7, tokens[1], 0.52019107e20, 0, 0);

        uint256 valueX128;
        uint256 targetX128;
        uint256 deMinimusX128;
        
        console.log("Step1:");
        (valueX128, targetX128, , deMinimusX128) = valueFacet.queryValue(address(0), 0x7);
        console.log("valueX128     :", valueX128);
        console.log("targetX128    :", targetX128);
        console.log("deMinimusX128 :", deMinimusX128);
        console.log("valueX128 - targetX128 * 3                   : ", (int256)(valueX128) - (int256)(targetX128) * 3);
        console.log("");

        valueFacet.addValue(alice, 0x7, 3e11, 0);
        valueFacet.addValue(alice, 0x7, 3e16, 0);
        valueFacet.addValue(alice, 0x7, 3e20, 0);
        valueFacet.addValue(alice, 0x7, 3e23, 0);

        console.log("Step2:");
        (valueX128, targetX128, , deMinimusX128) = valueFacet.queryValue(address(0), 0x7);
        console.log("valueX128     :", valueX128);
        console.log("targetX128    :", targetX128);
        console.log("deMinimusX128 :", deMinimusX128);
        console.log("1<<128        : %e", uint256(1<<128));
        console.log("valueX128 - targetX128 * 3                   : %e", (int256)(valueX128) - (int256)(targetX128) * 3);
        console.log("valueX128 - (targetX128 + deMinimusX128) * 3 : %e", (int256)(valueX128) - (int256)(targetX128 + deMinimusX128) * 3);
    }

forge test --match-test "test_invariant1" -vv If deMinimus = 500 << 128, Result:

Bash
Ran 1 test for test/facets/ValueFacet.t.sol:ValueFacetTest
[PASS] test_invariant() (gas: 1851203)
Logs:
  Step1:
  valueX128     : 119314944465894084766175288988610974551985615884757447256035
  targetX128    : 39771648155298028255391763002698103876158974815006309630937
  deMinimusX128 : 170141183460469231731687303715884105728000
  valueX128 - targetX128 * 3                   :  -19483337076491308560261481636776

  Step2:
  valueX128     : 102306119939396807002502954459855135536085525869282809562368786
  targetX128    : 34102039979798935667015918447015107849047050355960606309630937
  deMinimusX128 : 170141183460469231731687303715884105728000
  1<<128        : 3.40282366920938463463374607431768211456e38
  valueX128 - targetX128 * 3                   : 1.455199118809811988944374801400990633475975e42
  valueX128 - (targetX128 + deMinimusX128) * 3 : 9.44775568428404293749312890253338316291975e41

If deMinimus = 500, Result:

Bash
Ran 1 test for test/facets/ValueFacet.t.sol:ValueFacetTest
[PASS] test_invariant() (gas: 1860320)
Logs:
  Step1:
  valueX128     : 119314944465894084766175288988541772502944067753271447915116
  targetX128    : 39771648155298028255391762996180590834314689251090482638472
  deMinimusX128 : 500
  valueX128 - targetX128 * 3                   :  -300

  Step2:
  valueX128     : 102306119939396807002502954459855066334036484321151276116477882
  targetX128    : 34102039979798935667015918447008590336005206070396690482638472
  deMinimusX128 : 500
  1<<128        : 3.40282366920938463463374607431768211456e38
  valueX128 - targetX128 * 3                   : 1.455199118829295326020866109961204668562466e42
  valueX128 - (targetX128 + deMinimusX128) * 3 : 1.455199118829295326020866109961204668560966e42

Impact

In the ReadMe:

The "value" of the closure (according to the formulas) can never be more than deMinimus * (number of tokens in the closure) from the target value of the pool times number of tokens in the closure.

  1. Invariant Breaking.
  2. This could result in unfairness for users.

Mitigation

Consider recalculating the target using ValueLib.t.

The original report as published on Sherlock, by 0xNov1ce. 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 addValue function updates targetX128 and balances proportionally without recalculating the target using ValueLib.t to enforce the deMinimus constraint.

Impact

The invariant that the value of the closure can never be more than deMinimus * (number of tokens) from the target times number of tokens is broken, which could result in unfairness for users.

What the attacker needed

None

The fix

The team acknowledged the issue but won't fix it at this time; a suggested mitigation is to recalculate the target using ValueLib.t.

How it was found

  1. Add a realValue function to Closure.sol that computes the actual value using ValueLib.v.
  2. Modify the queryValue function in ValueFacet.sol to return the real value, targetX128, and deMinimusX128.
  3. Add a test function that sets search parameters, performs an initial addSingleForValue, then calls addValue with increasing amounts.
  4. Run the test with forge test --match-test "test_invariant1" -vv and observe the difference between valueX128 and targetX128 * 3 exceeding deMinimusX128 * 3.

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.

The protocol has a rule that the total value in a pool should stay close to a target value, within a small allowed difference called deMinimus. The addValue function increases both the actual value and the target, but it doesn't check that the difference stays within the allowed limit. This means the difference can grow larger than intended, breaking the rule and potentially causing unfair outcomes for users.

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 0xNov1ce

View all

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