Tadle

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

Referrer can't receive `referrerReferralBonus` from others.

Summary

SystemConfig.sol#updateReferrerInfo function set referrerInfo for referrer instead of msg.sender.
Therefore, referrer can't receive referrerReferralBonus from others who signed up using referrer's referral link.

Vulnerability Details

SystemConfig.sol#updateReferrerInfo function is the following.

function updateReferrerInfo(
address _referrer,
uint256 _referrerRate,
uint256 _authorityRate
) external {
if (_msgSender() == _referrer) {
revert InvalidReferrer(_referrer);
}
if (_referrer == address(0x0)) {
revert Errors.ZeroAddress();
}
if (_referrerRate < baseReferralRate) {
revert InvalidReferrerRate(_referrerRate);
}
uint256 referralExtraRate = referralExtraRateMap[_referrer];
uint256 totalRate = baseReferralRate + referralExtraRate;
if (totalRate > Constants.REFERRAL_RATE_DECIMAL_SCALER) {
revert InvalidTotalRate(totalRate);
}
if (_referrerRate + _authorityRate != totalRate) {
revert InvalidRate(_referrerRate, _authorityRate, totalRate);
}
69: ReferralInfo storage referralInfo = referralInfoMap[_referrer];
referralInfo.referrer = _referrer;
referralInfo.referrerRate = _referrerRate;
referralInfo.authorityRate = _authorityRate;
emit UpdateReferrerInfo(
msg.sender,
_referrer,
_referrerRate,
_authorityRate
);
}

As can be seen, the function set referralInfo for referrer instead of msg.sender.
Therefore, referrer can't receive referrerReferralBonus from msg.sender.

In more detail, PreMarket.sol#createTaker function is the following.

function createTaker(address _offer, uint256 _points) external payable {
--- SKIP ---
199: ReferralInfo memory referralInfo = systemConfig.getReferralInfo(
_msgSender()
);
--- SKIP ---
offerId = offerId + 1;
254: uint256 remainingPlatformFee = _updateReferralBonus(
platformFee,
depositAmount,
stockAddr,
makerInfo,
referralInfo,
tokenManager
);
--- SKIP ---
}

Where SystemConfig.sol#getReferralInfo is the following.

function getReferralInfo(
address _referrer
) external view returns (ReferralInfo memory) {
return referralInfoMap[_referrer];
}

Therefore, the _msgSender() == referralInfo.referrer always holds true in L199 and the PreMarket.sol#_updateReferralBonus function will give the referrerReferralBonus to the msg.sender instead of referrer in L870.

function _updateReferralBonus(
uint256 platformFee,
uint256 depositAmount,
address stockAddr,
MakerInfo storage makerInfo,
ReferralInfo memory referralInfo,
ITokenManager tokenManager
) internal returns (uint256 remainingPlatformFee) {
if (referralInfo.referrer == address(0x0)) {
remainingPlatformFee = platformFee;
} else {
/**
* @dev calculate referrer referral bonus and authority referral bonus
* @dev calculate remaining platform fee
* @dev remaining platform fee = platform fee - referrer referral bonus - authority referral bonus
* @dev referrer referral bonus = platform fee * referrer rate
* @dev authority referral bonus = platform fee * authority rate
* @dev emit ReferralBonus
*/
uint256 referrerReferralBonus = platformFee.mulDiv(
referralInfo.referrerRate,
Constants.REFERRAL_RATE_DECIMAL_SCALER,
Math.Rounding.Floor
);
/**
* @dev update referrer referral bonus
* @dev update authority referral bonus
*/
tokenManager.addTokenBalance(
TokenBalanceType.ReferralBonus,
870: referralInfo.referrer,
makerInfo.tokenAddress,
referrerReferralBonus
);
--- SKIP ---
}
}

Impact

Referrer can't receive referrerReferralBonus from others who signed up using referrer's referral link.
In other words, referrer can only receive referrerReferralBonus from the referrer himself.
This make the referral program useless.

Tools Used

Manual Review

Recommendations

Modify SystemConfig.sol#updateReferrerInfo function as follows.

function updateReferrerInfo(
address _referrer,
uint256 _referrerRate,
uint256 _authorityRate
) external {
--- SKIP ---
-- ReferralInfo storage referralInfo = referralInfoMap[_referrer];
++ ReferralInfo storage referralInfo = referralInfoMap[_msgSender()];
referralInfo.referrer = _referrer;
referralInfo.referrerRate = _referrerRate;
referralInfo.authorityRate = _authorityRate;
--- SKIP ---
}
Updates

Lead Judging Commences

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

finding-SystemConfig-updateReferrerInfo-msgSender

Valid high severity. There are two impacts here due to the wrong setting of the `refferalInfoMap` mapping. 1. Wrong refferal info is always set, so the refferal will always be delegated to the refferer address instead of the caller 2. Anybody can arbitrarily change the referrer and referrer rate of any user, resulting in gaming of the refferal system I prefer #1500 description the most, be cause it seems to be the only issue although without a poc to fully describe all of the possible impacts

Support

FAQs

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