Token buyers can pay less fees in AuctionHouse::purchase setting the referer as himself
Summary
AuctionHouse::purchase function allows token buyers to pay less fess while purchasing tokens as it allows setting himself as referer thus substracting the total fee
This means that if a user set himself as the referer then he will gain the referrer fee thus paying less fees to the protocol (because protocolfee = protocolfee - referrerFee )
Vulnerability Detail
The vulnerability exists in AuctionHouse::purchase because it allows setting referrer as caller ie msg.sender
function calculateQuoteFees(
uint96 protocolFee_,
uint96 referrerFee_,
bool hasReferrer_,
uint96 amount_
) public pure returns (uint96 toReferrer, uint96 toProtocol) {
uint96 feeDecimals = uint96(_FEE_DECIMALS);
if (hasReferrer_) {
// In this case we need to:
// 1. Calculate referrer fee
// 2. Calculate protocol fee as the total expected fee amount minus the referrer fee
// to avoid issues with rounding from separate fee calculations
toReferrer = uint96(Math.mulDivDown(amount_, referrerFee_, feeDecimals)); // <@ referrer
toProtocol = uint96(Math.mulDivDown(amount_, protocolFee_ + referrerFee_, feeDecimals))
- toReferrer;
} //... snippet
}
As is seen the referer Fee is substracted from protocolFee, so if the user set himself as the referer then he will pay less to purchase tokens.
To show it, create a new testcase in test/AuctionHouse/purchase.t.sol
cryptonoob
medium
Token buyers can pay less fees in AuctionHouse::purchase setting the referer as himself
Summary
AuctionHouse::purchase function allows token buyers to pay less fess while purchasing tokens as it allows setting himself as referer thus substracting the total fee
This means that if a user set himself as the referer then he will gain the referrer fee thus paying less fees to the protocol (because protocolfee = protocolfee - referrerFee )
Vulnerability Detail
The vulnerability exists in AuctionHouse::purchase because it allows setting referrer as caller ie msg.sender
The referrer is set in PurchaseParams params_ argument and then allocateQuoteFees is called:
That calls FeeManager::calculateQuoteFees:
As is seen the referer Fee is substracted from protocolFee, so if the user set himself as the referer then he will pay less to purchase tokens. To show it, create a new testcase in test/AuctionHouse/purchase.t.sol
And add this function in test/AuctionHouse/AuctionHouseTest.sol
Impact
The impact of this vulnerability includes:
Code Snippet
https://github.com/sherlock-audit/2024-03-axis-finance/blob/cadf331f12b485bac184111cdc9ba1344d9fbf01/moonraker/src/AuctionHouse.sol#L201-L217
https://github.com/sherlock-audit/2024-03-axis-finance/blob/cadf331f12b485bac184111cdc9ba1344d9fbf01/moonraker/src/AuctionHouse.sol#L835-L850
https://github.com/sherlock-audit/2024-03-axis-finance/blob/cadf331f12b485bac184111cdc9ba1344d9fbf01/moonraker/src/bases/FeeManager.sol#L68-L83
Tool used
Manual Review
Recommendation
To mitigate this vulnerability it is recommended to check referer value is not msg.sender in AuctionHouse::purchase params_ argument
Duplicate of #133