Tadle

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

`SystemConfig.updateReferrerInfo` implementation isn't correct

Summary

SystemConfig.updateReferrerInfo implementation isn't correct

Vulnerability Details

According to UI, referralInfo.referrerRate and referralInfo.authorityRate should be the bonus split between referrer and authority.
And according to SystemConfig.getReferralInfo's usage in PreMarkets.sol#L199-L201. bonus is updated in PreMarkets.sol#L254-L261, and in PreMarkets._updateReferralBonus, referralInfo.referrer will be msg.sender because in SystemConfig.sol#L69, _referrer is used as index for referralInfoMap

839 function _updateReferralBonus(
...
846 ) internal returns (uint256 remainingPlatformFee) {
847 if (referralInfo.referrer == address(0x0)) {
848 remainingPlatformFee = platformFee;
849 } else {
...
863
864 /**
865 * @dev update referrer referral bonus
866 * @dev update authority referral bonus
867 */
868 tokenManager.addTokenBalance(
869 TokenBalanceType.ReferralBonus,
870 referralInfo.referrer, <<< --- here will also be `_msgSender`
871 makerInfo.tokenAddress,
872 referrerReferralBonus
873 );
...
881 tokenManager.addTokenBalance(
882 TokenBalanceType.ReferralBonus,
883 _msgSender(),
884 makerInfo.tokenAddress,
885 authorityReferralBonus
886 );
887
...
904 }

Impact

authority will get all bonus, and referrer get nothing

Tools Used

VS code

Recommendations

diff --git a/src/core/SystemConfig.sol b/src/core/SystemConfig.sol
index 9b7eb4d..aed150f 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[_msgSender()];
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.