# TriggerOrder.notionalValue() Using the wrong latestPositionLocal to calculate the value causes the user to overpay fees

TriggerOrder.notionalValue() used latestPositionLocal instead of currentPositionLocal when closing, causing users to overpay interface fees on pending-decreased positions.

- Payout: Audit contest
- Severity: medium
- Program: Perennial
- Found by: bin2chen
- Disclosed: 2024-08-17
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3-judging/issues/62
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-perennial-v2-update-3%3AM-11
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error

**Target:** Perennial V2 TriggerOrder contract / Market.update
**Root cause:** notionalValue() computes close size from market.positions() (latestPositionLocal) while Market.update computes delta from currentPositionLocal; the two diverge when a pending position change exists.
**Steps:**
1. User has a position and a pending decrease (e.g. pending close of 3 against 5 long).
2. User submits a TriggerOrder with delta == MAGIC_VALUE_CLOSE_POSITION.
3. notionalValue() reads market.positions(account) = latestPositionLocal (5) instead of currentPositionLocal (2).
4. Fee = notionalValue() * order.interfaceFee.amount is charged on the larger stale size, overpaying.
**How found:** Code-reading comparison of TriggerOrder._position() (uses market.positions) against Market.update's delta computation (uses currentPositionLocal), spotting the mismatch when a pending position exists.
**Exploitation:** No attacker path; the user executing the trigger order overpays interface fees when currentPositionLocal < latestPositionLocal due to a pending decrease.
**Insight:** When a fee or size is derived from a position, check whether the protocol's execution path uses current vs latest (pending-adjusted) position state; any divergence between the quoting function and the settlement function is a fee-accounting bug.

