Tadle

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

Inconsistency in Update and Usage of `ReferralInfo`

Summary

In the SystemConfig::updateReferrerInfo function, the referralInfoMap is mistakenly updated for the _referrer instead of the _msgSender(). This allows anyone to modify the referralInfo for other users, which results in several issues:

  1. Anyone can modify another user’s referralInfoMap.

  2. When a user tries to update his own referralInfo, the update is ineffective.

  3. If a _referrer later uses PreMarkets::createTaker, the referrerReferralBonus could be wrongly attributed to himself, leading to incorrect self-referral bonuses.

Vulnerability Details

In the SystemConfig::updateReferrerInfo function, the following code incorrectly updates the referralInfoMap:

function updateReferrerInfo(
address _referrer,
uint256 _referrerRate,
uint256 _authorityRate
) external {
@=> if (_msgSender() == _referrer) {
revert InvalidReferrer(_referrer);
}
...
@=> ReferralInfo storage referralInfo = referralInfoMap[_referrer];
@=> referralInfo.referrer = _referrer;
referralInfo.referrerRate = _referrerRate;
referralInfo.authorityRate = _authorityRate;
...
}

This causes the referralInfoMap to be incorrectly updated for _referrer, not _msgSender(). This becomes problematic when referralInfoMap is later queried in PreMarkets::createTaker:

function createTaker(address _offer, uint256 _points) external payable {
...
ReferralInfo memory referralInfo = systemConfig.getReferralInfo(
@=> _msgSender()
);
...
uint256 remainingPlatformFee = _updateReferralBonus(
platformFee,
depositAmount,
stockAddr,
makerInfo,
@=> referralInfo,
tokenManager
);
}
function _updateReferralBonus(
uint256 platformFee,
uint256 depositAmount,
address stockAddr,
MakerInfo storage makerInfo,
ReferralInfo memory referralInfo,
ITokenManager tokenManager
) internal returns (uint256 remainingPlatformFee) {
...
tokenManager.addTokenBalance(
TokenBalanceType.ReferralBonus,
@=> referralInfo.referrer,
makerInfo.tokenAddress,
referrerReferralBonus
);
...
}

The assignment and usage of referralInfoMap is actually inconsistent:
- User A could set referralInfoMap info for User B, and he can't set it for himself.
- When User A calls createTaker, referralInfoMap[A] is queried instead of referralInfoMap[B].

This inconsistency causes several problems:

  1. Anyone can modify the referralInfoMap for any other user.

  2. Updates by users to their own referral information are ineffective.

  3. If _referrer uses PreMarkets::createTaker, the referral bonus could wrongly go to himself, creating an invalid self-referral scenario.

Impact

This issue could have a Medium to High impact:

  1. Anyone can modify the referralInfoMap for any other user.

  2. Updates by users to their own referral information are ineffective.

  3. If _referrer uses PreMarkets::createTaker, the referral bonus could wrongly go to himself, creating an invalid self-referral scenario.

Tools Used

Manual, VSCode

Recommendations

To resolve this issue, modify the updateReferrerInfo function so that it updates referralInfoMap for _msgSender() instead of _referrer. This will ensure that users can only update their own referral info and prevent the issues described above. Otherwise, refactor how the ReferralInfo is being used.

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.