Submitted by pkqs90, also found by Udsen, 0xLogos, and bin2chen
https://github.com/code-423n4/2024-04-panoptic/blob/main/contracts/PanopticPool.sol#L1367-L1391
https://github.com/code-423n4/2024-04-panoptic/blob/main/contracts/PanopticPool.sol#L887-L893
The underlying issue is that _validatePositionList() does not check for duplicate tokenIds. Attackers can use this issue to bypass solvency checks, which leads to several impacts:
This also conflicts a main invariant stated in audit readme: Users should not be allowed to mint/burn options or pay premium if their end state is insolvent.
First, lets see why _validatePositionList does not check for duplicate tokenIds. For a user position hash, the first 8 bits is the length of tokenIds which overflows, last 248 bits is the xor hash. However, we can easily add 256 tokenIds of the same kind to create a duplicate positionHash.
For example: Hash(key0, key1, key2) == Hash(key0, key1, key2, key0, key0, ..., 256 more key0). This way, we can add any tokenId we want while still arriving the same position hash.
PanopticPool.sol
PanopticMath.sol
Then, lets see how duplicate ids can bypass solvency check. The solvency check is in _validateSolvency(), which is called by all the user interaction functions, such as mint/burn/liquidate/forceExercise/settleLongPremium. This function first checks for a user passed in positionIdList (which we already proved can include duplicates), then calls _checkSolvencyAtTick() to calculate the balanceCross (collateral balance) and thresholdCross (required collateral) for all tokens.
The key is the collateral balance includes the premium that is collected for each of the positions. For most of the positions, the collected premium should be less than required collateral to keep this position open. However, if a position has been open for a long enough time, the fees it accumulated may be larger than required collateral.
For this kind of position, we can duplicate it 256 times (or multiple of 256 times, as long as gas fee is enough), and make our collateral balance grow faster than required collateral. This can make a insolvent account solvent, by duplicating the key tokenId multiple times.
CollateralTracker.sol
Now we have shown how to bypass the _validateSolvency(), we can bypass all related checks. Listing them here:
In this report, we will only prove the core issue: duplicate tokenIds are allowed, and wont craft complicated scenarios for relevant impacts.
Add the following test code in PanopticPool.t.sol, we can see that passing 257 of the same token ids can still work for mintOptions().
Add a check in _validatePositionList that the length is shorter than MAX_POSITIONS (32).
Invalid Validation
dyedm1 (Panoptic) confirmed
Picodes (judge) decreased severity to Medium and commented:
Note: for full discussion, please see the original submission.
