Tadle

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

Invalid referrer mapping in `SystemConfig::updateReferrerInfo(...)`

Summary

The Tadle protocol allows users to use referral links, thus obtaining bonus tax fees on each referred user transaction. However, the current referrer update process in the SystemConfig contract is invalid, leading to incorrect referrer/referral settings.

Vulnerability Details

Users who want to update their referrer information will invoke the SystemConfig::updateReferrerInfo(...), passing in the address of the user, together with the information for the referrer rates (referrerRate + authorityRate). Currently, whenever, a user calls the function, the _referrer input is set, not only as the referralInfo.referrer = _referrer, but also as the referralInfoMap mapping key:

function updateReferrerInfo(address _referrer, uint256 _referrerRate, uint256 _authorityRate) external {
__SNIP__
@> ReferralInfo storage referralInfo = referralInfoMap[_referrer];
@> referralInfo.referrer = _referrer;
referralInfo.referrerRate = _referrerRate;
referralInfo.authorityRate = _authorityRate;
emit UpdateReferrerInfo(msg.sender, _referrer, _referrerRate, _authorityRate);
}

From the above code logic, it turns out that if Alice referred Bob and Bob updated Alice's referrer information, then when Bob uses PreMarkets::createTaker(...), the systemConfig.getReferralInfo(_msgSender()) call in PreMarkets/sol, won't return anything, as getReferralInfo will pass msg.sender to the referralInfoMap mapping, which contains Alice as the mapping owner. This in turn will lead to the referral/referrer bonuses being skipped later on in the code execution.

function createTaker(address _offer, uint256 _points) external payable {
__SNIP__
@> ReferralInfo memory referralInfo = systemConfig.getReferralInfo(_msgSender()); // Bob (a referral) invokes create taker; function returns empty result
__SNIP__
offerId = offerId + 1;
uint256 remainingPlatformFee =
@> _updateReferralBonus(platformFee, depositAmount, stockAddr, makerInfo, referralInfo, tokenManager); // no referrer/referral bonuses will be applied
__SNIP__
}
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)) { // the referralInfo.referrer will be 0 address
remainingPlatformFee = platformFee;
} else {
__SNIP__
}

Impact

Referrer bonuses will not be properly assigned to the corresponding individuals

Tools Used

Manual review

Recommendations

Change the mapping key in SystemConfig::updateReferrerInfo(...) to be msg.sender instead of _referrer.

diff --git a/src/core/SystemConfig.sol b/src/core/SystemConfig.sol
index 9b7eb4d..2018204 100644
--- a/src/core/SystemConfig.sol
+++ b/src/core/SystemConfig.sol
@@ -66,7 +66,7 @@ contract SystemConfig is SystemConfigStorage, Rescuable, ISystemConfig {
revert InvalidRate(_referrerRate, _authorityRate, totalRate);
}
- ReferralInfo storage referralInfo = referralInfoMap[_referrer];
+ ReferralInfo storage referralInfo = referralInfoMap[msg.sender];
referralInfo.referrer = _referrer;
referralInfo.referrerRate = _referrerRate;
referralInfo.authorityRate = _authorityRate
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.