Closed c4-bot-5 closed 7 months ago
Not sure I see the problem with this? The collateral requirement has to be a certain quantity of tokens, so we either allow users to have a 0 collateral req (risky) or round conservatively in favor of the protocol to the higher req.
I agree with the sponsor here that the magnitude of the error isn't significant and that there is no issue is slightly overestimating collateral req.
Picodes marked the issue as unsatisfactory: Overinflated severity
Lines of code
https://github.com/code-423n4/2024-04-panoptic/blob/main/contracts/CollateralTracker.sol#L1570
Vulnerability details
Accurate collateral calculations are crucial for maintaining the solvency of the Panoptic protocol. Underestimations can lead to insufficient collateral, risking the protocol's stability during market downturns, while overestimations can tie up unnecessary capital, reducing liquidity and trading efficiency.
The collateral requirement for spreads between two option legs is calculated as follows:
Loc
https://github.com/code-423n4/2024-04-panoptic/blob/main/contracts/CollateralTracker.sol#L1570
This calculation can cause significant rounding errors due to integer division, particularly when the difference between
notional
andnotionalP
is minimal compared to their absolute values.audit details
Impact
The precision in collateral calculations impacts not just individual trades but the overall health and functionality of the trading platform which makes impact in this case significant.
Traders with limited capital may find themselves unable to participate in certain trades, or may incur higher opportunity costs as their funds are tied up unnecessarily.
Traders might perceive positions as riskier than they are, or the platform may inadvertently encourage over-collateralization, affecting the natural balance and hedging strategies in place. This could lead to misaligned risk perceptions and decisions.
Inaccuracies in collateral calculations might expose the platform to compliance risks if they're interpreted as failing to provide accurate accountings or as misleading users about the terms of engagement.
Proof of Concept
Suppose we have:
notional
(amount moved in one leg of the spread): 1,000,000 tokensnotionalP
(amount moved in the other leg of the spread): 1,000,001 tokenscontracts
(size of the position): 10,000 contractsThis setup reflects a common scenario in financial derivatives where two legs are close in value but not identical, often seen in calendar spreads or tight vertical spreads.
Calculation Without Scaling: Using the
_computeSpread
function, wherenotional < notionalP
:notionalP - notional = 1,000,001 - 1,000,000 = 1
1 * 10,000 = 10,000
The division to be performed is:
What this Result Implies:
The actual decimal precise arithmetic would be:
But, since Solidity cannot handle decimal points, the division of 10,000 by 1,000,000 in integer arithmetic results in 0. The
unsafeDivRoundingUp
function then rounds this up to 1.The expected collateral requirement should ideally be close to 0.01 but instead, the rounding results in an overestimation to 1, which is significantly larger than the actual requirement by a factor of 100 times.
This demonstrates a scenario where small differences relative to the amounts involved lead to rounding that considerably overestimates the needed collateral. Such a rounding error could impact trading strategies, leading to inefficient capital usage where traders must lock up more capital than is theoretically necessary due to a computational artifact.
Poc Code
Output
Tools Used
Manual
Recommended Mitigation Steps
Scale up the calculations before the division and scale them back down afterward.
Assessed type
Math