Tadle

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

updateReferrerInfo() incorrectly sets address in referralInfoMap to referrer instead of referree

Summary

referralInfoMap should map referree addresses to the referrer who referred them. In SystemConfig.sol the updateReferrerInfo() function incorrectly maps the referrer back to the referrer:

function updateReferrerInfo(
address _referrer,
uint256 _referrerRate,
uint256 _authorityRate
) external {
...
@1 ReferralInfo storage referralInfo = referralInfoMap[_referrer];
...
}
  1. https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/SystemConfig.sol#L69

Now, if the referree calls createTaker() on an offer, the referrer won't receive the referral bonus and the referree won't receive the authority fee if one existed.

Vulnerability Details

Here's a POC that can be added to PreMarket.t.sol:

function testUpdatReferrerInfoIncorrectlySetsAddress() public {
// 1. Set referrer and referree address
address referree = vm.addr(0x1234);
address referrer = vm.addr(0x5678);
// 2. Referree is referred by referrer to Tadle, but that info isn't stored correctly in referralInfoMap
vm.startPrank(referree);
systemConfig.updateReferrerInfo(referrer, baseReferralRate, 0);
ReferralInfo memory referreeInfo = systemConfig.getReferralInfo(referree);
// No referrer is set for the referree
assertEq(referreeInfo.referrer, address(0));
// 3. Create an offer that referree will take in 4th step
vm.startPrank(user);
preMarktes.createOffer(
CreateOfferParams(
marketPlace,
address(mockUSDCToken),
1000,
20_000_000e18,
12000,
300,
OfferType.Ask,
OfferSettleType.Turbo
)
);
address offerAddr = GenerateAddress.generateOfferAddress(0);
vm.stopPrank();
// 4. Referree takes offer
vm.startPrank(referree);
deal(address(mockUSDCToken), referree, 100000000 * 10 ** 18);
mockUSDCToken.approve(address(tokenManager), type(uint256).max);
preMarktes.createTaker(offerAddr, 1000);
// 5. Referrer doesn't recieve referral bonus for this referral
uint256 referrerReferreralBonusBalance = tokenManager.userTokenBalanceMap(address(referrer), address(mockUSDCToken), TokenBalanceType.ReferralBonus);
assertEq(referrerReferreralBonusBalance,0);
vm.stopPrank();
}

Impact

Referral system breaks and both referrers and referree don't receive referral bonus / authority fees.

Tools Used

Manual Review / Foundry

Recommendations

msg.sender is supposed to the be the referree, so update to something like this:

ReferralInfo storage referralInfo = referralInfoMap[_msgSender()];
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.