Tadle

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

The platformFee and the tradeTax should be round up

Summary

All the amounts that benefit the platform should be rounded up always to avoid problems in internal calculations that can allow an attacker to manipulate the token values in the contracts.

Vulnerability Details

The createTaker function calculates the amount of tokens the user needs to deposit to pay the points they want to buy, this function also calculates the platformFee and the tradeTax the user must pay to complete the trade.

when the createTaker function calculates the depositAmount it calls the mulDiv function and rounds the result up which is good, but when it calculates the platformFee and the tradeTax it calls the mulDiv function which rounds the result down, this is a mistake that can open the door to an attacker to manipulate the internal token amounts to his benefit, it's always recommended to round all the calculations in a way that favors the protocol instead of the user, so the recommended here would be to round up the platformFee and the tradeTax calculations.

https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/PreMarkets.sol#L217-L224

uint256 platformFee = depositAmount.mulDiv(
platformFeeRate,
Constants.PLATFORM_FEE_DECIMAL_SCALER
);
uint256 tradeTax = depositAmount.mulDiv(
makerInfo.eachTradeTax,
Constants.EACH_TRADE_TAX_DECIMAL_SCALER
);

Impact

bad rounding direction that benefits the user instead of the protocol.

Tools Used

Manual Review

Recommendations

Round the platformFee and the tradeTax in favor of the protocol, in this case the rounding of these variables should be up.

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.