# SettleLongPremium is incorrectly implemented: premium should be deducted instead of added

PanopticPool.settleLongPremium passed a positive realizedPremia to CollateralTracker.exercise, so long option holders received premium instead of paying it, minting shares at pool expense.

- Payout: Audit contest
- Severity: high
- Program: Panoptic
- Found by: pkqs90
- Disclosed: 2024-06-24
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-04-panoptic-findings/issues/497
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-panoptic%3AH-01
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** PanopticPool.settleLongPremium / CollateralTracker.exercise (Solidity contracts)
**Root cause:** realizedPremia is computed as a positive value from accumulatedPremium*liquidity, but exercise() treats realizedPremium as a cost via tokenToPay = -realizedPremium; the sign is never negated, so a positive premium becomes a payout rather than a charge.
**Steps:**
1. Call `pp.settleLongPremium(collateralIdList, owner, 0)` for a long option holder.
2. Observe accumulatedPremium.sub(premiumAccumulatorsLast) yields positive realizedPremia.
3. exercise() computes `tokenToPay = -realizedPremium` (negative), hitting the `tokenToPay < 0` branch and `_mint(optionOwner, sharesToMint)`.
4. Compare `ct0.convertToAssets(ct0.balanceOf(Buyers[0]))` before/after: it increases by 33_342 instead of decreasing.
**How found:** Code review of the premium accumulator sign convention: noticed accumulatedPremium is LeftRightUnsigned (always positive) and realizedPremia therefore positive, contradicting exercise()'s convention that negative means user pays; confirmed by reading the unit test where the buyer's assets increase after settling.
**Exploitation:** Any long option holder repeatedly calls settleLongPremium; each settlement mints collateral shares to them instead of burning, diluting PLPs and draining pool assets.
**Insight:** When a value flows through an unsigned accumulator into a signed settlement API, verify the sign convention at the boundary; a passing unit test asserting the wrong direction (assets increasing after paying a premium) is a strong tell.

## Proof of concept (copied exactly from the original report)

**settleLongPremium computes positive realizedPremia and passes to exercise**

```
LeftRightSigned realizedPremia = LeftRightSigned
>               .wrap(0)
>               .toRightSlot(int128(int256((accumulatedPremium.rightSlot() * liquidity) / 2 ** 64)))
>               .toLeftSlot(int128(int256((accumulatedPremium.leftSlot() * liquidity) / 2 ** 64)));

            // deduct the paid premium tokens from the owner's balance and add them to the cumulative settled token delta
            s_collateralToken0.exercise(owner, 0, 0, 0, realizedPremia.rightSlot());
            s_collateralToken1.exercise(owner, 0, 0, 0, realizedPremia.leftSlot());
```

**Unit test asserting buyer assets increase after settleLongPremium**

```
assetsBefore0 = ct0.convertToAssets(ct0.balanceOf(Buyers[0]));
        assetsBefore1 = ct1.convertToAssets(ct1.balanceOf(Buyers[0]));

        // collect buyer 1's three relevant chunks
        for (uint256 i = 0; i < 3; ++i) {
            pp.settleLongPremium(collateralIdLists[i], Buyers[0], 0);
        }

        assertEq(
            ct0.convertToAssets(ct0.balanceOf(Buyers[0])) - assetsBefore0,
            33_342,
            "Incorrect Buyer 1 1st Collect 0"
```

