# Incorrect tax distribution when adding value single-sided

Burve Closure.addValueSingle updates valueStaked before distributing the single-sided deposit tax, diluting existing LPs' earnings and stranding fees in the contract.

- Payout: Audit contest
- Severity: high
- Program: Burve
- Found by: 0xNov1ce
- Disclosed: 2025-04-17
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2025-04-burve-judging/issues/196
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-04-burve%3AH-4
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:solidity technique:source-review vuln:accounting-error vuln:fee-bypass vuln:reward-distribution

**Target:** Closure.addValueSingle / addEarnings in Burve multi-pool
**Root cause:** addValueSingle increments self.valueStaked before addEarnings computes earningsPerValueX128 using (valueStaked - bgtValueStaked) as denominator, so the new LP is included in the reward denominator.
**Steps:**
1. Deploy closure with initial value and Alice as sole LP; set closure fee to 1 bp via `setClosureFees(0x9, oneX128/100, 0)`.
2. Alice calls `addValue(alice, 0x9, 1e20, 0)`; queryValue shows earnings[0]==0.
3. Bob calls `addValueSingle(tapir, 0x9, 5e20, 0, tokens[0], 0)` paying tax.
4. Observe emitted tax vs Alice's earnings after: Alice receives only a fraction of the tax because denominator now includes Bob's valueStaked.
5. Remainder of tax stays stuck in contract.
**How found:** Code reading of addValueSingle ordering: noticed valueStaked is mutated before addEarnings computes per-value earnings, hypothesizing the denominator wrongly includes the new staker.
**Exploitation:** Occurs naturally on any single-sided deposit; new depositor's valueStaked dilutes the tax owed to prior LPs, leaving excess fees stranded in the contract and reducing LP incentives.
**Insight:** When auditing reward/fee accounting, check ordering between state mutations (stake/value updates) and accumulator updates that divide by that state; the denominator must reflect pre-deposit balances.

## Proof of concept (copied exactly from the original report)

**Foundry test proving tax dilution on single-sided add**

```
// forge test --match-contract ValueFacetTest --match-test test_tapir -vv
    function test_tapir() public {

        (, , , uint256 valueStaked, ) = simplexFacet.getClosureValue(0x9);
        console.log("valueStaked", valueStaked); // initial valueStaked
        uint256 oneX128 = 1 << 128;
        vm.prank(owner);
        simplexFacet.setClosureFees(0x9, uint128(oneX128 / 100), 0); // One basis point. Realistic.

        uint128 value = 1e20;
        valueFacet.addValue(alice, 0x9, value, 0);
        uint256[MAX_TOKENS] memory earnings;
        (, , earnings, ) = valueFacet.queryValue(alice, 0x9);
        console.log("earnings[0]", earnings[0]); // expect to be 0
        assertEq(earnings[0], 0);

        // there will be fees which should be distributed to the other LP's.
        address tapir = address(69);
        vm.recordLogs();

        // single value add, fee should be distributed to Alice and the initial value staked.
        valueFacet.addValueSingle(
            tapir,
            0x9,
            value * 5,
            0,
            tokens[0],
            0
        );

        Vm.Log[] memory entries = vm.getRecordedLogs();
        bytes32 tapirEventSig = keccak256("Tapir(uint256)");

        uint256 tax = 0;
        for (uint256 i = 0; i < entries.length; i++) {
            if (entries[i].topics[0] == tapirEventSig) {
                tax = abi.decode(entries[i].data, (uint256));
                console.log("Tax emitted:", tax);
                break;
            }
        }

        (, , earnings, ) = valueFacet.queryValue(alice, 0x9);
        console.log("earnings[0] after", earnings[0]);  // should be almost the entire tax above (minus the share of first dead shares)
        (, , earnings, ) = valueFacet.queryValue(tapir, 0x9);
        console.log("earnings[0]", earnings[0]); // should be 0

        uint256[MAX_TOKENS] memory collectedBalances;
        uint256 collectedBgt;
        vm.prank(Alice);
        (collectedBalances, collectedBgt) = valueFacet.collectEarnings(alice, 0x9);
        console.log("collectedBalances[0]", collectedBalances[0]);
    }
```

**Event added to addValueSingle to emit tax**

```
event Tapir(uint256 tax);
function addValueSingle(
        address recipient,
        uint16 _closureId,
        uint128 value,
        uint128 bgtValue,
        address token,
        uint128 maxRequired
    ) external nonReentrant returns (uint256 requiredBalance) {
        //..
        emit Tapir(realTax);
    }
```

