Tadle

Tadle
DeFi
30,000 USDC
View results
Submission Details
Severity: high
Valid

`SystemConfig::updateReferrerInfo` Updates `_referrer` Info Instead of Caller's

[H-01] SystemConfig::updateReferrerInfo Updates _referrer Info Instead of Caller's

Summary

The updateReferrerInfo function is utilized by users to set or update their referrals. However, a critical bug causes the _referrer's referralInfo mapping to be updated instead of the caller's (msg.sender). Consequently, the referral system fails entirely, with everyone's referrer being set to themselves.

Vulnerability Details

Upon execution, the function mistakenly loads the referralInfoMap of the _referrer instead of msg.sender. Subsequently, the values are set accordingly, leading to incorrect updates in the referral system.

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);
}
@> ReferralInfo storage referralInfo = referralInfoMap[_referrer];
@> referralInfo.referrer = _referrer;
@> referralInfo.referrerRate = _referrerRate;
@> referralInfo.authorityRate = _authorityRate;
emit UpdateReferrerInfo(
msg.sender,
_referrer,
_referrerRate,
_authorityRate
);
}

Impact

This bug renders the referral system ineffective, preventing users from correctly setting their referrers. Additionally, it allows anyone to change another user's referrer to themselves by simply invoking this function once.

Proof of Concept

The following test demonstrates the failure of the referral system due to this bug. It attempts to update a user's referral to user1 but fails to change the referrer. Moreover, it incorrectly sets user1's referral to themselves.

function test_referralDoesntWork() public {
vm.prank(user1); //user 1 is referrer
systemConfig.updateReferralExtraRateMap(user1, 100000);
vm.prank(user);
systemConfig.updateReferrerInfo(user1, 310000, 90000);
ReferralInfo memory user1_ref = systemConfig.getReferralInfo(user1);
assert(user1_ref.referrer == user1);
ReferralInfo memory user_ref = systemConfig.getReferralInfo(user);
assert(user_ref.referrer == address(0));
}

Tools Used

Manual Review

Recommendations

To correct this issue, the function should load the referralInfoMap using msg.sender instead of _referrer. The corrected version of the function is as follows:

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);
}
- ReferralInfo storage referralInfo = referralInfoMap[_referrer];
+ ReferralInfo storage referralInfo = referralInfoMap[_msgSender()];
referralInfo.referrer = _referrer;
referralInfo.referrerRate = _referrerRate;
referralInfo.authorityRate = _authorityRate;
emit UpdateReferrerInfo(
msg.sender,
_referrer,
_referrerRate,
_authorityRate
);
}

This correction ensures that the referral information is correctly updated for the caller (msg.sender), restoring the functionality of the referral system as intended.

Updates

Lead Judging Commences

0xnevi Lead Judge 10 months 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.