# Asymmetry in profit and loss (PnL) calculations

Flatmoney's PnL formula divides by current price, so intermediate position adjustments produce asymmetric rETH outcomes for identical absolute price moves, causing margin loss.

- Payout: Contest reward
- Severity: high
- Program: Flatmoney
- Credited: KingNFT
- Disclosed: 2023-12-11
- Write-up quality: 8/10
- Original: https://github.com/sherlock-audit/2023-12-flatmoney-judging/issues/186
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-12-flatmoney%3AH-4
- Tags: domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:precision-loss

**Target:** LeverageModule.sol PnL / margin settlement math
**Root cause:** PnL is computed in collateral terms as size*(currentPrice-lastPrice)/currentPrice, scaling by relative price change instead of absolute dollar value; each adjustment resets lastPrice and re-applies the nonlinear scaling.
**Steps:**
1. Open long: size 40 ETH at price $1000.
2. Price drops to $500; call adjustLeverage so newMargin = marginAdjustment + marginAfterSettlement and lastPrice=$500 (LeverageModule.sol L191-218).
3. Price rises to $2000; recompute PnL = 40*($2000-$500)/$2000 = 30 rETH.
4. Net result: marginDeposited = x-40+30 = x-10 rETH, i.e. 10 rETH lost despite net $40000 gain.
5. Compare no-adjustment path: 40*($2000-$1000)/$2000 = 20 rETH gain.
**How found:** Code-reading of the PnL formula; noticed it divides by current price (relative change) unlike Synthetix V2 which uses size*priceShift in dollars; constructed two scenarios with identical absolute price moves but different adjustment counts to expose asymmetry.
**Exploitation:** Trader times position adjustments (margin/size changes) around price swings so the per-adjustment PnL scaling locks in losses on the position's margin while the global accounting diverges; repeated adjustments drain margin relative to a single hold.
**Escalation:** Global vs per-position desync (updateGlobalPositionData vs individual PnL) lets marginDepositedTotal diverge from sum of positions, compounding losses across multiple traders.
**Insight:** When auditing perp/leverage PnL, check whether PnL is denominated in collateral (divided by price) vs dollars; any division by current price makes PnL path-dependent across adjustments — test by replaying the same absolute price path with and without intermediate settlements.
