Bidders can pay less fees than required because of rounding down
Summary
Because of Rounding down fees calculations, when calculating the required fee amount, the value can be less than required by the protocol.
Vulnerability Detail
When There is a new Bid, the protocol takes fees from the Bidder. But when calculating this fee, it is calculated by rounding down feeNumerator and feeDenominator.
Al-Qa-qa
medium
Bidders can pay less fees than required because of rounding down
Summary
Because of Rounding down fees calculations, when calculating the required fee amount, the value can be less than required by the protocol.
Vulnerability Detail
When There is a new Bid, the protocol takes fees from the Bidder. But when calculating this fee, it is calculated by rounding down
feeNumerator
andfeeDenominator
.EnglishPeriodicAuctionInternal.sol#L594-L603
Example
10%
(feeNumerator = 1, feeDenominator = 10), with 4 Decimal AssetbidAmount
=99,999
feeAmount = (bidAmount * feeNumerator) / feeDenominator
= $(99,999 * 1) / 10 = 9,999$CollateralNeeded = bidAmount + feeAmount
= $9,999 + 99,999 = 109,998$collateralNeeded
decreased by 2 units when thebidAmound
is99,999
.bidAmound
is100,000
(greater than by just one unit, thefeeAmount
could be10,000
and theCollateralNeeded
would be110,000
.CollateralNeeeded
decreased by 2 units instead of 1 unit because of rounding down.Impact
Less fees collected by the protocol over time.
Code Snippet
https://github.com/sherlock-audit/2024-02-radicalxchange/blob/main/pco-art/contracts/auction/EnglishPeriodicAuctionInternal.sol#L602
Tool used
Manual Review
Recommendation
Always round in the favour of the protocol, not in the favour of the user, which is rounding Up instead of rounding Down.
You can use OpenZeppelin mulDiv function to multiply and then divide using Rounding Up.