Protocol won't be eligible for referral rewards for depositing ETH
The SophonFarming contract passes its own address as the referral when depositing ETH into Lido or Ether.fi, making the referrer and depositor the same account. As a result, the protocol does not receive referral rewards it intended to earn.
Source: https://github.com/sherlock-audit/2024-05-sophon-judging/issues/92
Found by
h2134
Summary
Protocol won't be eligible for referral rewards for depositing ETH, as the referral account is not properly set.
Vulnerability Detail
When user sends ETH to contract SophonFarming, or calls ETH deposit functions, protocol will first deposit ETH on external protocols (Lido or Ether.fi) for minting staking shares, then warp the shares to the predefined assets (wstETH or weETH), then user starts to earn reward points.
The external protocols allows caller to pass referral argument when depositing ETH, and referral account can be eligible for referral rewards if it is valid. Let's take Ether.fi for example:
function _ethTOeEth(uint256 _amount) internal returns (uint256) {
// deposit returns exact amount of eETH
return IeETHLiquidityPool(eETHLiquidityPool).deposit{value: _amount}(address(this));
}
To convert ETH to eETH, the function deposit in IeETHLiquidityPool is called. In fact, IeETHLiquidityPool exposes 2 deposit functions for users to deposit ETH, which have different signatures:
// Used by eETH staking flow
function deposit() external payable returns (uint256) {
return deposit(address(0));
}
// Used by eETH staking flow
function deposit(address _referral) public payable whenNotPaused returns (uint256) {
require(_isWhitelisted(msg.sender), "Invalid User");
emit Deposit(msg.sender, msg.value, SourceOfFunds.EETH, _referral);
return _deposit(msg.sender, msg.value, 0);
}
The _referral parameter in the second deposit function indicates the referral account which will be eligible for referral rewards, as stated by ether.fi here:
This referral program covers both ether.fi and ether.fan, each 0.1 ETH staked via ether.fi or ether.fan earns the person who stakes > and the the person who referred 100 loyalty points.
Note: Referral points may take up to 2 hours to display in your Portfolio.
Apparently, by calling the second deposit function and passing address(this) as _referral argument, our protocol expects to receive the referral rewards, however, this makes the referral as the same account as the depositor itself (msg.sender), this is invalid to ether.fi and no rewards will be granted to the account which uses one's own referral code for depositing.
Similarly, protocol won't receive referral rewards from Lido as it set referral to itself when submit to deposit ETH:
function _ethTOstEth(uint256 _amount) internal returns (uint256) {
// submit function does not return exact amount of stETH so we need to check balances
uint256 balanceBefore = IERC20(stETH).balanceOf(address(this));
@=> IstETH(stETH).submit{value: _amount}(address(this));
return (IERC20(stETH).balanceOf(address(this)) - balanceBefore);
}
Impact
Protocol won't be eligible for referral rewards as expected, this can be significant value leak to the protocol.
Code Snippet
https://github.com/sherlock-audit/2024-05-sophon/blob/main/farming-contracts/contracts/farm/SophonFarming.sol#L811 https://github.com/sherlock-audit/2024-05-sophon/blob/main/farming-contracts/contracts/farm/SophonFarming.sol#L834
Tool used
Manual Review
Recommendation
User owner account as referral instead of the caller contract itself.
function _ethTOstEth(uint256 _amount) internal returns (uint256) {
// submit function does not return exact amount of stETH so we need to check balances
uint256 balanceBefore = IERC20(stETH).balanceOf(address(this));
- IstETH(stETH).submit{value: _amount}(address(this));
+ IstETH(stETH).submit{value: _amount}(owner());
return (IERC20(stETH).balanceOf(address(this)) - balanceBefore);
}
function _ethTOeEth(uint256 _amount) internal returns (uint256) {
// deposit returns exact amount of eETH
- return IeETHLiquidityPool(eETHLiquidityPool).deposit{value: _amount}(address(this));
+ return IeETHLiquidityPool(eETHLiquidityPool).deposit{value: _amount}(owner());
}
Discussion
sherlock-admin3
1 comment(s) were left on this issue during the judging contest.
0xmystery commented:
valid because referral should indeed be an EOA which can be multisig
ZdravkoHr
Escalate This issue looks like Oportunity Loss which is not accepted as H/M by Sherlock. For example, a contract not opting-in for gas yield on Blast would not be a valid H/M.
sherlock-admin3
Escalate This issue looks like Oportunity Loss which is not accepted as H/M by Sherlock. For example, a contract not opting-in for gas yield on Blast would not be a valid H/M.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
mystery0x
Escalate This issue looks like Oportunity Loss which is not accepted as H/M by Sherlock. For example, a contract not opting-in for gas yield on Blast would not be a valid H/M.
I think this will mean a lot more than just Opportunity Loss given that many transactions are going to route through these calls.
WangSecurity
@mystery0x could you please iterate why you think it's not an Opportunity loss?
0xh2134
This issue is not opportunity loss because:
- It's not caused by loss of functionality but the wrong argument in the code;
- It's protocol design to receive referral rewards, this can be seen from the code implementation (and sponsor's confirmation of this issue)
This issue may fall into this category:
Loss of airdrops or liquidity fees or any other rewards that are not part of the original protocol design is not considered a valid high/medium
However because referral rewards is the protocol design, so this issue is valid.
mystery0x
@WangSecurity @0xh2134 addresses a valid point because of the erring integration (In the example provided by Sherlock Criteria for Issue Validity doc, users do not have an option to claim their airdrops whereas the referral bonus in this context is readily claimable albeit is denied due to wrong input of function argument.)
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/sophon-org/farming-contracts/commit/73adb6759b899e1a192fb5e28a5cd6202b5c3ff2
WangSecurity
I agree that it's not an opportunity loss and doesn't qualify for a loss of rewards, since the protocol's code wants to receive them, but it doesn't due to code issue. Hence, I believe it's part of the original protocol design.
Planning to reject the escalation and leave the issue as it is.
ZdravkoHr
Isn't the main reward from stETH coming from beacon chain staking rewards and thia refferal fee is just an additional bonus?
WangSecurity
As I understand yes, but as I see in the code, these rewards are part of the protocol's design and they want to accrue them, but it won't happen due to an issue in the code. Or am I missing something?
If not, decision remains the same, reject the escalation and leave the issue as it is.
ZdravkoHr
How do we understand that they want to accrue them?
WangSecurity
By the fact that they submit an address to receive the rewards, instead of address(0) for example, it would be fair if they didn't care. But, actually, looking at this issue a couple of times more, I'm not sure about it. Is it possible to see the code implementation of that submit function? I think it might shed some light on the problem.
ZdravkoHr
I found this function from the LIDO contract it seems the referral is used only in event emission.
function _submit(address _referral) internal returns (uint256) {
require(msg.value != 0, "ZERO_DEPOSIT");
StakeLimitState.Data memory stakeLimitData = STAKING_STATE_POSITION.getStorageStakeLimitStruct();
// There is an invariant that protocol pause also implies staking pause.
// Thus, no need to check protocol pause explicitly.
require(!stakeLimitData.isStakingPaused(), "STAKING_PAUSED");
if (stakeLimitData.isStakingLimitSet()) {
uint256 currentStakeLimit = stakeLimitData.calculateCurrentStakeLimit();
require(msg.value <= currentStakeLimit, "STAKE_LIMIT");
STAKING_STATE_POSITION.setStorageStakeLimitStruct(stakeLimitData.updatePrevStakeLimit(currentStakeLimit - msg.value));
}
uint256 sharesAmount = getSharesByPooledEth(msg.value);
_mintShares(msg.sender, sharesAmount);
_setBufferedEther(_getBufferedEther().add(msg.value));
emit Submitted(msg.sender, msg.value, _referral);
_emitTransferAfterMintingShares(msg.sender, sharesAmount);
return sharesAmount;
}
Also, in this article it's explained that the rewards go to the specified address and not to the calling one - I didn't know that :D
To participate, users simply need to generate a referral URL from their Ethereum addresses and share the link with others. The referrer is rewarded with payback in LDO, Lido's native token, based on the amount of ETH staked by users who join through the referral link.
0xh2134
The way I see it, it's obvious that they want to accrue referral rewards:
- When deposit into Lido, call
submit(address _referral)function with_referralbeingaddress(this)instead ofaddress(0) - When deposit into Ether.fi, call
deposit(address _referral)function with_referralbeingaddress(this), instead of calling the defaultdeposit()function
The deposit events are processed by Lido / Ether.fi offline, and referral rewards are distributed to _referral. However, in the context of deposit event, the msg.sender is SophonFarming contract and _referral is also SophonFarming contract, as I confirmed with Ether.fi, no referral rewards will be distributed if _referral is the same as the msg.sender.
So, because they want to accrue referral rewards, they need to set _referral to a different address other than msg.sender, for example, the owner, then the owner can send referral rewards back to SophonFarming contract.
BTW, I believe it's highly likely that the referral rewards would be used as rewards to point holders, that's why the want to accrue them.
WangSecurity
Thanks for both of your answers. I also confirmed with the sponsor that these referral rewards are indeed part of their original design and they intended to receive them. I know that some may say it was known only after the contest, but I believe in this situation it's quite unclear from the code if they intended to receive them and all the watsons could ask sponsors about it during the contest. With that said, since the team intends to receive these rewards, but made a code issue leading to losing these rewards, planning to reject the escalation and leave the issue as it is.
WangSecurity
Result: Medium Unique
sherlock-admin4
Escalations have been resolved successfully!
Escalation status:
- ZdravkoHr: rejected
sherlock-admin2
The Lead Senior Watson signed off on the fix.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The contract uses its own address as the referral argument instead of a separate account, so the referral is invalid.
Impact
The protocol does not receive referral rewards it expected, which could be a significant value leak.
What the attacker needed
None
The fix
The issue was fixed by using the owner account as the referral instead of the contract itself.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you deposit money into a service, you can sometimes name a friend who referred you, and that friend gets a bonus. Here the contract named itself as the friend, which the services do not allow, so no bonus is paid. The protocol loses the extra rewards it was trying to collect.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.