Tadle

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

Incorrect calculation logic in function `PreMarkets.sol#abortBidTaker()`

Summary

Unexpected loss of funds may occur due to incorrect calculation logic in the PreMarkets.sol#abortBidTaker() function.

Vulnerability Details

In the PreMarkets.sol#abortBidTaker() function, depositAmount is calculated as follows.

uint256 depositAmount = stockInfo.points.mulDiv(
preOfferInfo.points,
preOfferInfo.amount,
Math.Rounding.Floor
);

Expressing this in a formula is as follows:

depositAmount = stockInfo.points * preOfferInfo.points / preOfferInfo.amount

As you can see, the units of stockInfo.points and preOfferInfo.points, and depositAmount and preOfferInfo.amount have to be same.

However, according to Woo's calculation formula, the unit of depositAmount is not calculated accurately.

In other words, the deposit amount is not calculated accurately, and therefore the maker refund amount cannot be calculated accurately.

The exact calculation formula is as follows:

depositAmount = stockInfo.points * preOfferInfo.amount / preOfferInfo.points

Impact

Unexpected loss of funds may occur.

Tools Used

Manual Review

Recommendations

It is recommended to modify the PreMarkets.sol#abortBidTaker() function as follows:

function abortBidTaker(address _stock, address _offer) external {
SNIP...
uint256 depositAmount = stockInfo.points.mulDiv(
--- preOfferInfo.points,
--- preOfferInfo.amount,
+++ preOfferInfo.amount
+++ preOfferInfo.points
Math.Rounding.Floor
);
uint256 transferAmount = OfferLibraries.getDepositAmount(
preOfferInfo.offerType,
preOfferInfo.collateralRate,
depositAmount,
false,
Math.Rounding.Floor
);
SNIP...
}
Updates

Lead Judging Commences

0xnevi Lead Judge about 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.