Tadle

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

incorrect calculation of remaining amount in function abortAskOffer

Summary

incorrect calculation of remaining amount

Vulnerability Details

if (
offerInfo.offerStatus != OfferStatus.Virgin &&
offerInfo.offerStatus != OfferStatus.Canceled
) {
revert InvalidOfferStatus();
}
MakerInfo storage makerInfo = makerInfoMap[offerInfo.maker];
if (
makerInfo.offerSettleType == OfferSettleType.Turbo &&
stockInfo.preOffer != address(0x0)
) {
revert InvalidOffer();
}
/// @dev market place must be online
ISystemConfig systemConfig = tadleFactory.getSystemConfig();
MarketPlaceInfo memory marketPlaceInfo = systemConfig
.getMarketPlaceInfo(makerInfo.marketPlace);
marketPlaceInfo.checkMarketPlaceStatus(
block.timestamp,
MarketPlaceStatus.Online
);
uint256 remainingAmount;
if (offerInfo.offerStatus == OfferStatus.Virgin) {
remainingAmount = offerInfo.amount;
} else {
remainingAmount = offerInfo.amount.mulDiv(
offerInfo.usedPoints,
offerInfo.points,
Math.Rounding.Floor
);
}
  1. When the offer status is Virgin, the calculation is correct: the remaining amount is the full offer amount.

  2. However, when the offer status is not Virgin (which in this case would be Canceled), the calculation is incorrect.

The current calculation for the non-Virgin case is:

remainingAmount = offerInfo.amount * (usedPoints / points)

This is wrong because it calculates the amount that has been used, not the amount remaining

To calculate the remaining amount correctly, we need to subtract the used amount from the total amount. The correct calculation should be:

remainingAmount = offerInfo.amount.mulDiv(
offerInfo.points - offerInfo.usedPoints,
offerInfo.points,
Math.Rounding.Floor
);

Impact

incorrect calculation of remaining amount

Tools Used

Manual Review

Recommendations

remainingAmount = offerInfo.amount.mulDiv(
offerInfo.points - offerInfo.usedPoints,
offerInfo.points,
Math.Rounding.Floor
);

Updates

Lead Judging Commences

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

[invalid] finding-PreMarkets-abortAskOffer-remainingAmount-compute

Valid high, for cancelled offers, the unused collateral should be returned back to the maker. The `remainingAmount` is calculated wrongly with regards to usedPoints instead of unused points. Note: See comments under 826 and 907 for invalidation reasons

Appeal created

0xnevi Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
Assigned finding tags:

[invalid] finding-PreMarkets-abortAskOffer-remainingAmount-compute

Valid high, for cancelled offers, the unused collateral should be returned back to the maker. The `remainingAmount` is calculated wrongly with regards to usedPoints instead of unused points. Note: See comments under 826 and 907 for invalidation reasons

Support

FAQs

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