DeliveryPlace::closeBidTaker
will close the user’s stock position and distribute point tokens and, in case the settled points are less than the used points, will also distribute the collateral in relation to the user’s points.
For this vulnerability, the following scenario is needed:
The offer settle type must be Protected
The settled points must be less than the used points (this can also be achieved by the same malicious user by calling DeliveryPlace::settleAskMaker
with _settledPoints
as zero but this is a different bug that will be reported separately because it has more implications)
In this scenario, if a user has listed and sold his stock, he can still invoke DeliveryPlace::closeBidTaker
and get the amount of collateral corresponding to his sold stockInfo.points
.
In DeliveryPlace::closeBidTaker
, if the offer settle type is protected, the user remaining points is set as stockInfo.points
without checking whether this stock is listed:
Later on, userCollaterlFee
and pointTokenAmount
is calculated and added to the user even though he has no points:
Add this test into PreMarkets.t.sol
As can be seen, the attacker starts with a USDC balance of 1_200e18 and ends up with 1_182.5e18 and 100e18 token points so the attacker just paid the fees and got the points for free.
N.B.
: Points are wrongly added to the makerInfo.tokenAddress
instead of marketPlaceInfo.tokenAddress
userTokenBalanceMap
but this will be reported separately as it has some other consequences.
Foundry
Even when the offer settle type is protected, check if the stock is listed and if so, calculate the remaining points.
Valid High, afaik, partial settlements are a valid flow and so when closing bid offers by takers and/or when settling offers by makers, we should return a proportionate amount of funds based on points settled. This issues could be related to issue #1008, but seems to be describing a different issue.
Valid high, in settleAskTaker/settleAskMaker, if the original offer maker performs a partial final settlement, the existing checks [here](https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/DeliveryPlace.sol#L356-L358) and [here](https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/DeliveryPlace.sol#L230-L232) will cause an revert when attempting to complete a full settlement, resulting in their collateral being locked and requiring a rescue from the admin. To note, although examples in the documentation implies settlement in a single click, it is not stated that partial settlements are not allowed, so I believe it is a valid user flow.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.