Deposited staking tokens can be lost if rewards token info added by mistake in addReward() in VE3DRewardPool and there is no checking to ensure this would not happen (ve3Token for one reward was equal to stacking token)
The addReward function lacks validation, so if the owner mistakenly sets a new reward token's ve3Token to an existing reward token address, then getReward will transfer the entire balance of that existing token to the caller. An attacker could then claim all staking rewards.
Originally disclosed on Code4rena
Submitted by unforgiven
Impact
If owner by mistake or bad intention add a reward token that ve3Token of new reward token was equal to old reward token address then old reward token balance of VE3DRewardPool can be lost by calling getReward(account, _claimExtras=False,_stake=False) because of the line 314 which is IERC20(rewardTokenInfo[_rewardToken].ve3Token).safeTransfer(_account,ve3TokenBalance);
Proof of Concept
This is addReward() code in VE3DRewardPool:
function addReward(
address _rewardToken,
address _veAssetDeposits,
address _ve3TokenRewards,
address _ve3Token
) external onlyOwner {
rewardTokenInfo[_rewardToken].veAssetDeposits = _veAssetDeposits;
rewardTokenInfo[_rewardToken].ve3TokenRewards = _ve3TokenRewards;
rewardTokenInfo[_rewardToken].ve3Token = _ve3Token;
rewardTokens.add(_rewardToken);
}
As you can see there is no check for values and it sets new rewardToken parameters. This is getReward() code:
function getReward(
address _account,
bool _claimExtras,
bool _stake
) public updateReward(_account) {
address _rewardToken;
for (uint256 i = 0; i < rewardTokens.length(); i++) {
_rewardToken = rewardTokens.at(i);
uint256 reward = earnedReward(_rewardToken, _account);
if (reward > 0) {
rewardTokenInfo[_rewardToken].rewards[_account] = 0;
IERC20(_rewardToken).safeApprove(rewardTokenInfo[_rewardToken].veAssetDeposits, 0);
IERC20(_rewardToken).safeApprove(
rewardTokenInfo[_rewardToken].veAssetDeposits,
reward
);
IVeAssetDeposit(rewardTokenInfo[_rewardToken].veAssetDeposits).deposit(
reward,
false
);
uint256 ve3TokenBalance = IERC20(rewardTokenInfo[_rewardToken].ve3Token).balanceOf(
address(this)
);
if (_stake) {
IERC20(rewardTokenInfo[_rewardToken].ve3Token).safeApprove(
rewardTokenInfo[_rewardToken].ve3TokenRewards,
0
);
IERC20(rewardTokenInfo[_rewardToken].ve3Token).safeApprove(
rewardTokenInfo[_rewardToken].ve3TokenRewards,
ve3TokenBalance
);
IRewards(rewardTokenInfo[_rewardToken].ve3TokenRewards).stakeFor(
_account,
ve3TokenBalance
);
} else {
IERC20(rewardTokenInfo[_rewardToken].ve3Token).safeTransfer(
_account,
ve3TokenBalance
);
}
emit RewardPaid(_account, ve3TokenBalance);
}
}
//also get rewards from linked rewards
if (_claimExtras) {
uint256 length = extraRewards.length;
for (uint256 i = 0; i < length; i++) {
IRewards(extraRewards[i]).getReward(_account);
}
}
}
As you can see it loops through all rewardTokens and in line 314 it transfers all balance of rewardTokenInfo[_rewardToken].ve3Token of contract to account address. So if owner by mistake or bad intention add a new rewardToken that rewardTokenInfo[newRewardToken].ve3Token == oldRewardToken then by calling getReward(account, False, False) contract will loop through all reward tokens and when it reaches the newRewardToken it will transfer all the balance of contract in rewardTokenInfo[newRewardToken].ve3Token address to account address and rewardTokenInfo[newRewardToken].ve3Token is oldRewardToken, so it will transfer all the oldRewardToken balance of contract(which was supposed to be distributed among all stackers) to account address. This is like a backdoor that gives owner the ability to withdraw rewards tokens and if owner makes a simple mistake then one can easily withdraw that contract balance of reward token.
Tools Used
VIM
Recommended Mitigation Steps
In addReward() check that there is no mistake or any malicious values added to rewards.
solvetony (veToken Finance) disagreed with severity and commented:
We would try to decrease chance of that, most likely by implementing validation, to reduce manual check for owner.
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
The warden has shown how due to misconfiguration all rewards could be sent to the first claimer, because this is contingent on a misconfiguration, I believe Medium Severity to be more appropriate.
Alex the Entreprenerd (judge) commented:
While this report and #179 can be grouped as similar, I believe the warden has shown two different potential risks and at this time am choosing to leave the two findings as separate.
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
Likely the addReward function does not validate that the ve3Token address for a new reward token is distinct from existing reward tokens, allowing a misconfiguration that causes getReward to transfer the entire balance of an existing token.
Impact
If the owner misconfigures a reward token, all rewards of an existing token could be sent to the first claimer, but this requires a misconfiguration by the owner.
What the attacker needed
Owner misconfigures addReward; attacker can call getReward
The fix
The addReward function should be fixed to validate that the ve3Token address is not already used by another reward token.
How it was found
- Owner calls addReward with a new reward token whose ve3Token equals an existing reward token address.
- Attacker calls getReward with _claimExtras and _stake set to false.
- The function loops through reward tokens and for the new token transfers the entire balance of the existing token to the attacker.
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.
A reward pool lets people deposit tokens and earn rewards. The owner can add new reward tokens, but the code does not check that the new token's settings are correct. If the owner accidentally points a new reward to an existing reward token, then anyone calling getReward can drain all of that existing token from the pool.
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.