Tadle

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

Incorrect balance updating of referrer bonus

Summary

The referrer and authority bonus both go to the msg.sender of createTaker function.

Vulnerability Details

In the _updateReferralBonus call from createTaker, the authority bonus is being updates in the msg.sender balance, and the referralBonus in the referralInfo's balance.
https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/PreMarkets.sol#L868-L886

tokenManager.addTokenBalance(
TokenBalanceType.ReferralBonus,
referralInfo.referrer,
makerInfo.tokenAddress,
referrerReferralBonus
);
tokenManager.addTokenBalance(
TokenBalanceType.ReferralBonus,
_msgSender(),
makerInfo.tokenAddress,
authorityReferralBonus
);

But the referralInfo object is being obtained by calling the getReferralInfo function
https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/PreMarkets.sol#L199-L201

ReferralInfo memory referralInfo = systemConfig.getReferralInfo(
_msgSender()
);

During the updation of the ReferralInfoMap in SystemConfig, the _referrer is used as the index.
https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/SystemConfig.sol#L69-L72

ReferralInfo storage referralInfo = referralInfoMap[_referrer];
referralInfo.referrer = _referrer;
referralInfo.referrerRate = _referrerRate;
referralInfo.authorityRate = _authorityRate;

This means that referralInfoMap[msg.sender] will have msg.sender as the referrer. And thus the referrer bonus in createTaker also goes to the msg.sender rather than a different referrer.

Impact

Referral system is broken.

Tools Used

Manual Review

Recommendations

Rewrite the updateReferrerInfo function in Systemconfig.sol

Updates

Lead Judging Commences

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