# When malicious behavior occurs and DSS requests slashing against vault during 2 day period after SLASHING_WINDOW of 7 days is passed after staker initiates a withdrawal, token amount to be slashed is calculated to be higher than what it should be

Karak's requestSlashing computes earmarked stake from vault totalAssets() including pending withdrawals past SLASHING_WINDOW, letting DSS slash more than its allowed percentage of remaining assets.

- Payout: Audit contest
- Severity: medium
- Program: Karak
- Found by: rbserver
- Disclosed: 2024-10-07
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-07-karak-findings/issues/17
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-karak%3AM-03
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** Core/SlasherLib slashing request on vaults
**Root cause:** fetchEarmarkedStakes multiplies slash percentage by vault totalAssets(), which still counts assets queued for withdrawal that have already passed SLASHING_WINDOW and are no longer slashable.
**Steps:**
1. Vault holds 100 tokens, one staker owns 100 shares.
2. Day 0: staker initiates withdrawal of 50 shares.
3. Days 0-7 (SLASHING_WINDOW): no malicious behavior, no slashing request; withdrawal should be safe.
4. Day 8: malicious behavior occurs; DSS with 50% slash allowance calls `Core.requestSlashing`; earmarked = `50% * totalAssets() = 50` tokens instead of `50% * (100-50) = 25`.
5. Day 9: staker calls `Vault.finishRedeem`, receives 50 tokens.
6. Day 10: DSS calls `Core.finalizeSlashing`, slashes 50 tokens (should be 25), draining more than allowed.
**How found:** Code reading of Constants (MIN_WITHDRAWAL_DELAY = SLASHING_WINDOW + SLASHING_VETO_WINDOW) against SlasherLib.fetchEarmarkedStakes using totalAssets(), spotting that assets past SLASHING_WINDOW remain in the base while still being slashable.
**Exploitation:** DSS submits a slashing request during the 2-day veto window after SLASHING_WINDOW elapses, capturing the pending-withdrawal assets in the earmarked amount; after MIN_WITHDRAWAL_DELAY the staker redeems, then DSS finalizes and slashes the inflated amount from remaining vault assets.
**Escalation:** Second scenario: miner reorders `finalizeSlashing` before `finishRedeem` so the withdrawing staker is slashed directly (judge deemed unrealistic).
**Insight:** When a protocol separates a slashing window from a longer withdrawal delay, check whether the slash base (totalAssets) still includes assets whose slashing window already expired; the gap between the two timers is where over-slashing occurs.

