Closed code423n4 closed 1 year ago
minhquanym marked the issue as primary issue
0xRektora marked the issue as sponsor disputed
That's part of the design. First come first serve, it incentivize users to; A) take actions quickly B) Small amounts will get crushed by larger amounts, this is to de-incentivize spam by removing any benefit to it.
dmvt marked the issue as unsatisfactory: Invalid
Lines of code
https://github.com/Tapioca-DAO/tap-token-audit/blob/59749be5bc2286f0bdbf59d7ddc258ddafd49a9f/contracts/options/TapiocaOptionBroker.sol?#L382-L387
Vulnerability details
Tapioca DAO Treasury may loose up to 25% of potential earnings in a rapid weekly singularity market volume growth
Lets assume a situation, where the Topioca protocol has a strong weekly growth of value deposited in singularity markets and these singularity positions get locked in the tOLP contract. The eligibleTapAomunt calculated for a user in exerciseOption based on his oTAP is calculated counterintuativly in real time on the TapiocaOptionBroker:
where
tOLP.getTotalPoolDeposited(tOLPLockPosition.sglAssetID)
is calculated in the TapiocaOptionLiquidityProvisionWhere
activeSingularities[sglAssetIDToAddress[_sglAssetId]].totalDeposited
gets incremented and decremented when a user locks or unlocks a singularity position for this market in real time:This vulnerability is explained easiest with an example:
The user flow can be like this - a user mints 100 USD0 and:
Lets assume that:
Its because yesterday, another user minted 200 additional USD0. Now the eligibleTapAmount is 116 TAPs(100USD0 * 350TAPs)/300USD0 and line
eligibleTapAmount -= oTAPCalls[_oTAPTokenID][cachedEpoch];
reverts because 116 -175 is smaller than 0 (underflow)Impact
Lets further assume that half of the users do this strategy of only exercising 50% of the weekly oTap volume beginning of the newEpoch. This means 25% of the possible sold TAPs are not sold. Lets assume that 50% of these users switch to exercise 100% beginning of the week, bringing the potential loss to 12.5 to 25%.
The damage is for the Tapioca DAO Treasury that sells less TAPs than it could, in my sample calculation up to 25% less. The actual damage of course cannot be told exactly.
As well this will lead to a lot of frustration with users, because a promise is not kept - in my example the user was promised 350 TAPs but actually he was able to buy only 175. This can go to the user forums and from there to the media, slowing down user adoption.
Because it is quite certain that this scenario happens and a lot of value can be lost I rate this vulnerability as high.
Proof of Concept
I created a proof of concept named "should fail to claim partial exerciseOption in rising singularity markets". It behaves like this:
The script outputs the following lines.
And here the script
Tools Used
Visual Studio Code
Recommended Mitigation Steps
Using the current total singularity market volume to calculate the eligibleTapAmount is very dangerous. In another vulnerability I show that this enables another attack (and there might be more). I highly recommend to snapshot the volumes of all singularity markets every week pool volume when newEpoch is called. Then use these snapshotted singularity market volumes to calculate the eligibleTapAmount.
Assessed type
Under/Overflow