Tadle

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

Anyone except the referrer can call the updateReferrerInfo function and update the referrer rates value of any referrer as this function is unprotected

Summary

The updateReferrerInfo function is meant to allow a referrer to update the values of the ReferralInfo struct so he can split the referral bonus with his referral, but this function allows anyone except the referrer to change the referral rates.

https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/SystemConfig.sol#L41-L80

Vulnerability Details

The updateReferrerInfo function is meant to enable the referrer to update the values of the ReferralInfo struct so he can split the referral bonus with his referrals, but this function allows anyone to update the ReferralInfo data except the referrer who is the owner and should be the only one who can decide how to split the rates of this referral info.

When a referrer wants to update the bonus referral rate between him and his referrals he should be able to call the updateReferrerInfo function to update these values as he wishes, but this function denies this access to the referrer on his first if, so the referrer can't change his own values, but any other user can do it.

function updateReferrerInfo(
address _referrer,
uint256 _referrerRate,
uint256 _authorityRate
) external {
// The referrer can't change his own data because the call is reverted here
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
);
}

This test shows that the referrer can't call the updateReferrerInfo function to update his referral rates info, but another user can update the referral info of the referrer.

function test_referral_turbo_usdc() public {
// another user can change the referrer info.
vm.prank(user1);
systemConfig.updateReferrerInfo(user, 300_000, 0);
vm.stopPrank();
vm.startPrank(user);
// the referrer can't change his own info.
vm.expectRevert(abi.encodeWithSelector(ISystemConfig.InvalidReferrer.selector, user));
systemConfig.updateReferrerInfo(user, 300_000, 0);
preMarktes.createOffer(
CreateOfferParams(
marketPlace, address(mockUSDCToken), 1000, 0.01 * 1e18, 12000, 300, OfferType.Ask, OfferSettleType.Turbo
)
);
address offerAddr = GenerateAddress.generateOfferAddress(0);
preMarktes.createTaker(offerAddr, 500);
address stock1Addr = GenerateAddress.generateStockAddress(1);
preMarktes.listOffer(stock1Addr, 0.006 * 1e18, 12000);
vm.stopPrank();
}

Impact

The referrer can't update his own ReferralInfo struct data, but other users can.

Tools Used

Manual review

Recommendations

if this function should be callable only by the owner add the corresponding modifier, if this function should be called only by the referrer correct the first if of the function to allow only the referrer to call this function.

if (_msgSender() == _referrer) {
revert InvalidReferrer(_referrer);
}
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.