SettleLongPremium
is incorrectly implemented: premium should be deducted instead of added
#497
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
H-01
primary issue
Highest quality submission among a set of duplicates
🤖_98_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
selected for report
This submission will be included/highlighted in the audit report
Lines of code
https://github.com/code-423n4/2024-04-panoptic/blob/main/contracts/PanopticPool.sol#L1621-L1640
https://github.com/code-423n4/2024-04-panoptic/blob/main/contracts/CollateralTracker.sol#L1043-L1089
Vulnerability details
Impact
SettleLongPremium
is the function intended to settle premiums for long option holders. When called, it should deduct the premium from the option owner's account, but the current implementation adds the premium instead.Bug Description
Lets see the code for premium calculation. We can see that
accumulatedPremium
ands_options[owner][tokenId][legIndex]
are premium accumulators for calculating the owed amount of premium, and thataccumulatedPremium
is a LeftRightUnsigned type, which means it must be positive.The
realizedPremia
is also positive, because it is calculated byaccumulatedPremium * liquidity
.The issue occurs when calling
s_collateralToken.exercise()
. TherealizedPremia
that is passed inside should be negative instead of positive, because negative means user pays premia, and positive means user receives premia. The current implementation is incorrect.PanopticPool.sol
CollateralTracker.sol
Proof of Concept
We can also see from unit test
test_success_settleLongPremium
: The tests checks that after callingsettleLongPremium
, the assets ofBuyer[0]
actually increases instead of decreases, which is obviously incorrect.Tools Used
Manual review.
Recommended Mitigation Steps
Take the negative of
realizedPremia
before callings_collateralToken.exercise()
.Assessed type
Other
The text was updated successfully, but these errors were encountered: