Tadle

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

Incorrect `depositAmount` Formula Causes Protocol to Record an Incorrect `depositAmount` for Taker

Summary

An error in the formula used to calculate depositAmount within the PreMarkets::abortBidTaker function leads to an incorrect recording of the depositAmount. This discrepancy can result in Bid Takers being refunded an incorrect amount of tokens, which differs from what they initially deposited.

Vulnerability Details

The vulnerability is found in the PreMarkets::abortBidTaker function, specifically in the calculation of the depositAmount. The current formula is incorrectly arranged, causing an inaccurate computation. Below is the problematic code:

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

Issue Breakdown:

  • Incorrect Formula:

    • The current formula is:

      depositAmount = (stockInfo.points * preOfferInfo.points) / preOfferInfo.amount
    • This formula is incorrect because it does not properly calculate the proportional deposit amount based on the points and amount.

  • Correct Formula:

    • The correct formula should be:

      depositAmount = (stockInfo.points * preOfferInfo.amount) / preOfferInfo.points
    • This corrects the order of operations, ensuring that the depositAmount is proportional to the points and amount as originally intended.

Impact in the Code:

  • The incorrect formula leads to a situation where the Bid Taker is refunded an incorrect amount of tokens, which can differ significantly from their original deposit.

  • This discrepancy is evident when compared to the correct formula used elsewhere in the code, specifically in the PreMarkets::createTaker function, which calculates the depositAmount correctly.

Impact

Due to the incorrect formula, the protocol miscalculates the depositAmount, resulting in incorrect refunds to Bid Takers. This can lead to financial losses or inconsistencies in the protocol's accounting, potentially undermining user trust and the protocol’s integrity.

Tools Used

  • Manual analysis

Recommendations

The protocol should update the formula in the PreMarkets::abortBidTaker function to correctly calculate the depositAmount. The correct formula should be:

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

This adjustment will ensure that the depositAmount is accurately recorded and that Bid Takers are refunded the correct amount of tokens.

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.