# Wrong modifier on `PreDeposit::setBondAndLeverageAmount` function leads to big differences in user balances

PreDeposit.setBondAndLeverageAmount used checkDepositNotEnded, letting a depositor frontrun governance's amount-setting with a withdraw, inflating bond/lev supplies and skewing coupon distribution.

- Payout: Audit contest
- Severity: medium
- Program: Plaza Finance
- Found by: 0xadrii
- Disclosed: 2024-12-16
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-12-plaza-finance-judging/issues/353
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-12-plaza-finance%3AM-5
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:race-window technique:source-review vuln:accounting-error vuln:business-logic vuln:reward-distribution

**Target:** PreDeposit.sol setBondAndLeverageAmount / deposit-withdraw flow
**Root cause:** setBondAndLeverageAmount is gated by checkDepositNotEnded, so governance must set amounts before deposit phase ends while users can still deposit/withdraw, allowing the reserve balance to change after amounts are computed.
**Steps:**
1. Deploy PreDeposit with depositEndTime = now+7d, RESERVE_CAP=100e18.
2. Griefer deposits 50e18 reserve tokens; 50 regular users deposit 1e18 each.
3. Warp to ~6.999 days; griefer calls `preDeposit.withdraw(50e18)` frontrunning governance.
4. Governance calls `preDeposit.setBondAndLeverageAmount(1500e18,1500e18)` based on pre-withdraw balance.
5. Warp past depositEndTime; further `setBondAndLeverageAmount` reverts due to checkDepositNotEnded.
6. `preDeposit.createPool()` mints inflated bond/lev supply; users claim and new users calling `Pool.create` get mismatched amounts.
**How found:** Code review of the modifier on setBondAndLeverageAmount: noticed it only allows calls before depositEndTime while deposit/withdraw remain open, hypothesizing a frontrun/backrun window around governance's call.
**Exploitation:** Attacker deposits large reserve amount during deposit phase, then frontruns governance's setBondAndLeverageAmount call with a withdraw, shrinking reserve balance so the set amounts no longer match, inflating bondETH/levETH total supply and skewing coupon distribution; no capital beyond the deposit is needed since it is withdrawn.
**Insight:** When a governance setter computes values from a live balance but is time-gated to a window where users can still move that balance, look for frontrun/backrun windows; here the fix is to move the setter after the phase ends rather than before.

