The depositAmount calculation formula in the PreMarkets::abortBidTaker() function is incorrect, causing the caller to lose all collateral.
The issue is in the PreMarkets::abortBidTaker() function. The depositAmount is calculated using the formula highlighted below (indicated by @>). This value is then used to compute transferAmount, which is subsequently passed to the tokenManager.addTokenBalance() method. This method updates the amount corresponding to TokenBalanceType.MakerRefund in the storage mapping.
However, due to an error in the depositAmount calculation formula, depositAmount is set to 0, resulting in the caller losing all collateral.
To demonstrate the issue, add the following test code to test/PreMarkets.t.sol and run it:
The test output shows that depositAmount == 0, resulting in the caller losing all collateral.
The incorrect calculation of depositAmount in the PreMarkets::abortBidTaker() function causes the caller to lose all collateral.
Manual Review
Use the correct calculation formula: depositAmount = preOfferInfo.amount * stockInfo.points / preOfferInfo.points:
After applying this fix, the test should pass successfully, as shown below:
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.