Tadle

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

Incorrect rounding direction when calculating `depositAmount` in the `PreMarkets.relistOffer()` function.

Summary

The calculation of depositAmount should favor the protocol and be rounded up.

Vulnerability Details

The issue arises because when calculating the depositAmount for a relisted offer, the OfferLibraries.getRefundAmount() function is used. However, this function is designed for refund calculations, which are rounded down (in two instances):

File: OfferLibraries.sol
63: function getRefundAmount(
64: OfferType _offerType,
65: uint256 _amount,
66: uint256 _points,
67: uint256 _usedPoints,
68: uint256 _collateralRate
69: ) internal pure returns (uint256) {
70: uint256 usedAmount = Math.mulDiv(
71: _amount,
72: _usedPoints,
73: _points,
74: Math.Rounding.Ceil // <== should be Floor when calculating deposit amount
75: );
76:
77: if (_offerType == OfferType.Bid) {
78: return _amount - usedAmount;
79: }
80:
81: return
82: Math.mulDiv(
83: _amount - usedAmount,
84: _collateralRate,
85: Constants.COLLATERAL_RATE_DECIMAL_SCALER,
86: Math.Rounding.Floor // <== should be Ceil when calculating deposit amount
87: );
88: }

When reused for relisting the offer, the rounding is in the wrong direction as it should be rounded up (in two instances).

This can lead to unexpected behavior, such as a DoS for some users due to a missing dust amount of assets that will be needed later for withdrawals.

Impact

  • Incorrect calculations.

  • DoS.

  • Loss of funds.

Tools Used

Manual review.

Recommendations

Calculate depositAmount in the PreMarkets.relistOffer() function by rounding up the calculations if needed. Do not use OfferLibraries.getRefundAmount() for this purpose.

Updates

Lead Judging Commences

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

finding-PreMarkets-Rounding-Direction

Duplicate of #456, however, for issues noting rounding directions, will be low severity given the impact is not proven sufficiently with a PoC/numerical example and most rounding will not result in significant losses e.g. most examples only proved at most a 1 wei difference when computing `depositAmount/platFormFees` and involves lower amount offers

Support

FAQs

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