Tadle

Tadle
DeFiFoundry
27,750 USDC
View results
Submission Details
Severity: high
Valid

Incorrect `depositAmount` calculation in abortBidTaker

Summary

In abortBidTaker(), when we calculate depositAmount, we use stockInfo.points * preOfferInfo.points/ preOfferInfo.amount. This is incorrect. The correct calculation should be stockInfo.points * preOfferInfo.amount / preOfferInfo.points.

Vulnerability Details

In PreMarkets, the ask maker can choose to abort the ask offer. And the related bid takers can get back the collateral amount which were used to buy points. Considering that there may be several bid takers, each bid taker's collateral amount should be calculated according to the point amount they buy.
The problem is that the calculation of depositAmount. We use stockInfo.points * preOfferInfo.points/ preOfferInfo.amount. This is incorrect. The correct calculation should be stockInfo.points * preOfferInfo.amount / preOfferInfo.points.

function abortBidTaker(address _stock, address _offer) external {
...
uint256 depositAmount = stockInfo.points.mulDiv(
@> preOfferInfo.points,
@> preOfferInfo.amount,
Math.Rounding.Floor
);

Impact

The calculation of depositAmount is incorrect. The bid taker may not get back the expected collateral amount.
For example, points is 10000. And the collateral amount is 1e18. The deposit amount will be zero. The bid takers will lose all their collateral.

Tools Used

Manual

Recommendations

Correct the calculation of depositAmount.

Updates

Lead Judging Commences

0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

finding-PreMarkets-abortBidTaker-amount-wrong-StockInfo-points

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.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!