Commission fees can always be bypassed
The commission fee calculation in settleBurn uses the minimum of the premium fee and notional fee, but when called from _settleOptions the notional fee is zero, so the commission becomes zero. Also, if realizedPremium is zero, the commission calculation is skipped entirely, allowing users to avoid commission fees by settling premium first and then burning.
prk0 Follow with ElmInNyc99, peazzycole and 1 other
Originally disclosed on Code4rena
Submitted by prk0, also found by ElmInNyc99, peazzycole, and zzebra83
CollateralTracker.solL1612-L1632PanopticPool.solL1010-L1011
Finding description
Original code block has been omitted. View complete submission.
CollateralTracker::settleBurn() computes the commissionFee as the minimum between premium fee and notional fee.
CollateralTracker::settleBurn() is called in the following flows:
Flow 1 - Force Exercise:
PanopticPool::dispatchFrom()
→ PanopticPool::_forceExercise()
→ PanopticPool::_burnOptions()
→ CollateralTracker::settleBurn()
Flow 2 - Burn:
PanopticPool::dispatch()
→ PanopticPool::_burnOptions()
→ CollateralTracker::settleBurn()
Flow 3 - Liquidate:
PanopticPool::dispatchFrom()
→ PanopticPool::_liquidate()
→ PanopticPool::_burnAllOptionsFrom()
→ PanopticPool::_burnOptions()
→ CollateralTracker::settleBurn()
Flow 4 - Settle Premium:
PanopticPool::dispatchFrom()
→ PanopticPool::_settlePremium()
→ PanopticPool::_settleOptions()
→ CollateralTracker::settleBurn()
Flow 5 - Settle Premium:
PanopticPool::dispatch()
→ PanopticPool::_settleOptions()
→ CollateralTracker::settleBurn()
function _settleOptions(
address owner,
TokenId tokenId,
uint128 positionSize,
RiskParameters riskParameters,
int24 currentTick
) internal {
// call _updateSettlementPostBurn to settle the long premia or the short premia (only for self calling)
LeftRightUnsigned[4] memory emptyCollectedByLegs;
LeftRightSigned realizedPremia;
unchecked {
// cannot be miscast because currentTick is a int24
(realizedPremia, ) = _updateSettlementPostBurn(
owner, // owner
tokenId, // tokenId
emptyCollectedByLegs, // collectedByLeg
positionSize, // positionSize
riskParameters, // riskParameters
LeftRightSigned.wrap(1).addToLeftSlot(1 + (int128(currentTick) << 2))
);
}
// deduct the paid premium tokens from the owner's balance
> collateralToken0().settleBurn(owner, 0, 0, 0, realizedPremia.rightSlot(), riskParameters); // @audit
> collateralToken1().settleBurn(owner, 0, 0, 0, realizedPremia.leftSlot(), riskParameters); // @audit
}
In Flow 4 and Flow 5, settleBurn() is called from _settleOptions() - The supplied longAmount, shortAmount, and ammDeltaAmount parameters are all 0. Therefore, we can expect the computed notional fee to also be 0.
As mentioned above, the commission fee is taken from the minimum between notional fee and premium fee. As a result, the commission fee will always be computed to 0, when settleBurn() is called from _settleOptions() (Flow 4 and Flow 5).
function settleBurn(
address optionOwner,
int128 longAmount,
int128 shortAmount,
int128 ammDeltaAmount,
int128 realizedPremium,
RiskParameters riskParameters
) external onlyPanopticPool returns (int128) {
(, int128 tokenPaid, uint256 _totalAssets, uint256 _totalSupply) = _updateBalancesAndSettle(
optionOwner,
false, // isCreation = false
longAmount,
shortAmount,
ammDeltaAmount,
realizedPremium
);
> if (realizedPremium != 0) {
// SNIP
}
return tokenPaid;
}
CollateralTracker::settleBurn() also skips the commission fee computation altogether when realizedPremium = 0. Therefore, a user can always avoid commission fees by settling premium first, then burning.
Impact
Commission fees are always computed to 0 in flows that involve _settleOptions(). In addition, commission fees are skipped if realizedPremium is 0. This results in commission fees being skipped in many flows.
Users can avoid commission fees completely by settling premium, then burning, on exit.
Recommended mitigation steps
Consider removing the realizedPremium != 0 check and consider deriving commission fee directly from premium fee, when shortAmount and longAmount are both = 0.
function settleBurn(
address optionOwner,
int128 longAmount,
int128 shortAmount,
int128 ammDeltaAmount,
int128 realizedPremium,
RiskParameters riskParameters
) external onlyPanopticPool returns (int128) {
(, int128 tokenPaid, uint256 _totalAssets, uint256 _totalSupply) = _updateBalancesAndSettle(
optionOwner,
false, // isCreation = false
longAmount,
shortAmount,
ammDeltaAmount,
realizedPremium
);
- if (realizedPremium != 0) {
uint128 commissionFee;
// compute the minimum of the notionalFee and the premiumFee
{
uint128 commissionP;
unchecked {
commissionP = realizedPremium > 0
? uint128(realizedPremium)
: uint128(-realizedPremium);
}
uint128 commissionFeeP = Math
.mulDivRoundingUp(commissionP, riskParameters.premiumFee(), DECIMALS)
.toUint128();
uint128 commissionN = uint256(int256(shortAmount) + int256(longAmount)).toUint128();
uint128 commissionFeeN;
unchecked {
commissionFeeN = Math
.mulDivRoundingUp(commissionN, 10 * riskParameters.notionalFee(), DECIMALS)
.toUint128();
}
+ if (shortAmount == 0 && longAmount == 0) {
+ commissionFee = commissionFeeP;
+ } else {
commissionFee = Math.min(commissionFeeP, commissionFeeN).toUint128();
+ }
}
// SNIP
- }
return tokenPaid;
}
Proof of Concept
View detailed Proof of Concept
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.75s (100.30ms CPU time)
Ran 1 test suite in 2.04s (1.75s CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)
The trace output above displays the last two interactions with PanopticPool, where Charlie settles his own premium, then burns the position.
In the first interaction (settle premium), the commission fee is computed to 0 for both CollateralTracker0 and CollateralTracker1. This can be observed via the CommissionPaid event.
In the second interaction (burn), the commission fee is skipped. This can be confirmed due to the absence of the CommissionPaid event.
As a result, Charlie avoided paying any commission fees for his position.
Prevent commission bypass.
Status: Mitigation confirmed. Full details in reports from Valves, edoscoba, and Nyx.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the commission fee is computed as the minimum of a premium-based fee and a notional-based fee, but the notional-based fee is zero when settleBurn is called from _settleOptions, and the entire fee calculation is skipped when realizedPremium is zero.
Impact
Users can avoid commission fees completely by settling premium first, then burning, on exit.
What the attacker needed
A position with options; ability to call settle premium and burn
The fix
The mitigation was confirmed: the check on realizedPremium was removed and the commission fee is derived directly from the premium fee when both shortAmount and longAmount are zero.
How it was found
- Call settle premium on a position, which invokes _settleOptions and then settleBurn with zero longAmount, shortAmount, and ammDeltaAmount, resulting in a zero commission fee.
- Then burn the position, which calls settleBurn with realizedPremium equal to zero, skipping the commission fee calculation entirely.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This is a smart contract bug where a fee that should be charged when closing an options position can be avoided. The code calculates the fee as the smaller of two possible fees, but in some cases one of those fees is zero, so the final fee becomes zero. Also, if a certain value is zero, the fee code is skipped altogether, letting users pay nothing.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.