The PreMarkets contract implements functionality for managing pre-market trading activities. One of its key functions, abortBidTaker(), is responsible for handling the abortion of a bid taker position. This function is critical as it involves refunding tokens to users based on complex calculations involving offer and stock information.
The core issue lies in the calculation of the depositAmount within the abortBidTaker() function. Currently, the function uses stockInfo.points and preOfferInfo.points to calculate the depositAmount:
However, this calculation may not accurately represent the intended logic for determining the deposit amount. The use of points from both stockInfo and preOfferInfo could lead to inconsistencies, especially if these values are set or updated independently in other parts of the contract.
This miscalculation directly affects the transferAmount, which is subsequently used to update token balances:
The potential for incorrect calculations in this critical function could lead to significant financial discrepancies, affecting the overall integrity of the pre-market trading system.
The incorrect calculation of depositAmount in the abortBidTaker() function can lead to substantial financial losses or unintended gains for users. In scenarios where the calculated amount is lower than it should be, users may receive fewer tokens than they are entitled to when aborting their bid taker position. Conversely, if the calculation results in a higher amount, it could lead to an excess distribution of tokens, potentially draining the contract's reserves.
Alice creates a bid taker position with 100 points and 1000 tokens.
The market conditions change, and Alice decides to abort her position.
Alice calls the abortBidTaker() function.
Due to the incorrect calculation, instead of receiving back her 1000 tokens, Alice only receives 800 tokens.
Alice has now lost 200 tokens due to the miscalculation in the abortBidTaker() function.
Manual review
To address this issue, the calculation of depositAmount should be revised to use the correct parameters that accurately represent the user's position. Here's a suggested fix:
This change ensures that the depositAmount is calculated based on the actual amounts involved in the stock and offer, rather than potentially mismatched point values.
Valid high severity, due to incorrect computation of `depositAmount` within `abortBidTaker`, when aborting bid offers created by takers, the collateral refund will be completely wrong for the taker, and depending on the difference between the value of `points` and `amount`, it can possibly even round down to zero, causing definite loss of funds. If not, if points were worth less than the collateral, this could instead be used to drain the CapitalPool contract instead.
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.