# TokenVault: dividend miscalculation lets flash-loan harvest drain vault

TokenVault mis-accounted fresh shares vs deposit fees, letting an attacker flash-borrow WBNB, donate/deposit, resolve and harvest inflated dividends for ~$3.2k profit.

- Payout: Real-world hack
- Severity: medium
- Program: TokenVault
- Credited: DeFiHackLabs
- Disclosed: 2025-06-20
- Write-up quality: 6/10
- Original: https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2025-06/TokenVault_exp.sol
- Library page: https://bugbountylibrary.com/r/dhl%3A20250620-tokenvault
- Tags: domain:web3 impact:funds-loss kind:incident platform:defihacklabs sev:medium tech:evm tech:solidity technique:chained vuln:business-logic vuln:flash-loan vuln:reward-distribution

**Target:** BSC staking/dividend vault contract (donate/depositTo/resolve/harvest)
**Root cause:** Freshly deposited shares are added before deposit fees are allocated, and a same-transaction holder can resolve then harvest against existing drip/fee accounting, so a temporary position receives more WBNB than principal.
**Steps:**
1. Flash-swap 4 WBNB from Pancake WBNB/USDT pair via `swap(0, 4 ether, attackContract, ...)`.
2. In `pancakeCall`, approve vault and call `donate(2 ether)`.
3. Call `depositTo(address(this), 1.1141e18)` to mint fresh shares into the same accounting round.
4. Read `myTokens()` (1.00269e18 shares).
5. Call `resolve(shareBalance)` then `harvest()` to pull 8.108 WBNB dividends.
6. Repay 4.0104 WBNB to pair; forward remaining ~4.98 WBNB profit to attacker.
**Exploitation:** Attacker flash-borrows WBNB, donates and deposits into the vault so fresh shares enter the current dividend round, resolves those shares, harvests inflated WBNB dividends exceeding principal, repays the flash swap and keeps the surplus.
**Insight:** In dividend/reward vaults, check whether shares minted in the same tx as a donation can immediately resolve and harvest against pre-existing drip accounting — a donate+deposit+resolve+harvest sequence in one tx is the tell.
