# Possible wrong accounting in L1Staking.sol

Staker can withdraw ETH before a challenged wrong batch is proven, so slashing hits an empty account and L1Staking accounting goes insolvent.

- Payout: Audit contest
- Severity: medium
- Program: Morphl2
- Found by: 0xRajkumar
- Disclosed: 2024-08-28
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-morphl2-judging/issues/104
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-morphl2%3AM-2
- Tags: area:web3 domain:web3 impact:dos impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:business-logic vuln:race-condition

**Target:** L1Staking.sol / Rollup.sol staking and challenge contracts
**Root cause:** Withdrawal lock period and proofWindow are independent; a staker can start withdrawal before a challenge resolves, so proveState slashes an already-exited staker and slashRemaining is credited against ETH no longer held.
**Steps:**
1. Set proofWindow = 7 days (max) and withdrawalLockBlocks = 7 days.
2. Alice (staker) commits a wrong batch, then immediately calls withdraw on L1Staking, starting her 7-day countdown.
3. Bob challenges the batch; the 7-day proofWindow countdown starts later than Alice's withdrawal timer.
4. Alice's withdrawal elapses first; she withdraws her ETH.
5. Bob calls proveState(); slashing runs `slashRemaining += valueSum - reward; _transfer(rollupContract, reward);` against funds Alice already removed.
6. Contract accounting now exceeds actual balance; last withdrawer/owner transfer reverts.
**How found:** Compared the admin-configurable proofWindow (up to 7 days) against the fixed withdrawalLockBlocks (7 days) and noticed the two timers are independent, so withdrawal can complete before challenge/slashing resolution.
**Exploitation:** Precondition: proofWindow >= withdrawal lock and staker commits an invalid batch. Staker front-runs challenge resolution by initiating withdrawal first, exits ETH, leaving slashRemaining over-credited; later withdrawals revert due to shortfall.
**Insight:** When a protocol has two independent time windows (challenge period vs withdrawal lock), check which can elapse first; if withdrawal can precede slashing resolution, slashed collateral is already gone and accounting becomes insolvent.

