# Malicious actors can execute sandwich attacks during market addition with existing funds

Re-adding a market with pre-existing vault assets instantly inflates totalAssets without minting shares, letting an attacker sandwich-deposit and redeem to steal value from existing vault users.

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

**Target:** CuratedVault (ERC4626-style lending vault) acceptCap/_setCap market addition
**Root cause:** _setCap pushes the new pool into withdrawQueue and immediately adds its supplyAssets to lastTotalAssets, so totalAssets() jumps without minting corresponding shares, diluting existing holders.
**Steps:**
1. User deposits 800 ether; totalAssets=800, shares=800 (1:1).
2. Remove market allMarkets[0] via submitCap(0)+submitMarketRemoval, warp timelock, updateWithdrawQueue to exclude it; market retains vault position funds.
3. Attacker calls `vault.deposit(300 ether)` just before re-addition, receiving 1199 shares at current ratio.
4. Curator calls `submitCap(allMarkets[0], 600 ether)` then after timelock `acceptCap(allMarkets[0])`; _setCap does `pool.forceUpdateReserve(asset())` and `_updateLastTotalAssets(lastTotalAssets + supplyAssets)`, inflating totalAssets.
5. Attacker calls `vault.redeem(attackerShares, attacker, attacker)` receiving 659 ether for 300 ether deposited.
6. Original user's 800 shares now convert to 440 ether; loss 359 ether equals attacker profit.
**How found:** Code reading of _setCap: noticed the comment 'Take into account assets of the new market without applying a fee' and that lastTotalAssets is bumped immediately while no shares are minted, then reasoned about ERC4626 share-price manipulation via deposit/withdraw around the admin transaction.
**Exploitation:** Attacker monitors pending acceptCap for a market holding pre-existing vault funds, front-runs with a deposit sized to the expected totalAssets jump, then back-runs with redeem after the ratio shifts, extracting the dilution from existing depositors.
**Insight:** In ERC4626-style vaults, any admin action that changes totalAssets without minting/burning shares (market add/remove, donation, fee skip) is a sandwich target; check every path that writes lastTotalAssets or totalAssets outside deposit/withdraw.

