Tadle

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

In `PreMarkert::abortBidTaker` when calculating `transferAmount`, the `depositAmount` used in the calculation is not calculated properly.

Summary

In PreMarkert::abortBidTaker using openZeppelin's mulDiv function in math.sol to calculate the depositAmount that is used to get the transferAmount, the params are not arranged properly and the amount calculated is not accurate.

Vulnerability Details

When calculating, the depositAmount used to calculate the transferAmount in abortBidTaker, the stockInfo.points is multiplied by the preOfferInfo.points instead of the preOfferInfo.amount and then divided by preOfferInfo.amount instead of preOfferInfo.points.

This arises due to the wrong arrangement of parameters that are given to openZeppelin's mulDiv function which will first multiply the stockInfo.points and preOfferInfo.points, then divide them by preOfferInfo.amount. This will most likely lead to a zero amount or a very low deposit amount.

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

PreMarkert.sol Line 671

Proof of Concept

Here is a scenario where:
stockInfo.points = 500
preOfferInfo.points = 1000
preOfferInfo.amount = 100_000e18

When you workout the above scenario: (500 * 1000)/100_000e18 = 0
The depositAmount will be zero, making the transferAmount also to be zero.

Impact

User will not be able get back all their amount that they deposited, hence loss of funds.

Tools Used

Manual Review

Recommendation

Cosider changing the parameters given to openZeppelin's mulDiv function such that stockInfo.points is multiplied by preOfferInfo.amount and divided by preOfferInfo.points to get the correct calculation.

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

Lead Judging Commences

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