sherlock-audit / 2024-02-radicalxchange-judging

3 stars 1 forks source link

Al-Qa-qa - Bidders can pay less fees than required because of rounding down #110

Closed sherlock-admin2 closed 8 months ago

sherlock-admin2 commented 8 months ago

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 and feeDenominator.

EnglishPeriodicAuctionInternal.sol#L594-L603

    function _calculateFeeFromBid(uint256 bidAmount) internal view returns (uint256) {
        uint256 feeNumerator = IPeriodicPCOParamsReadable(address(this)).feeNumerator();
        uint256 feeDenominator = IPeriodicPCOParamsReadable(address(this)).feeDenominator();

        // @audit Rounding Down makes the value of fees decrease
        return (bidAmount * feeNumerator) / feeDenominator;
    }

Example

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.