ExtraRewardStashV2’s stashRewards can become unavailable
The stashRewards function transfers reward tokens without checking if the amount is zero. If a reward token reverts on zero-value transfers, the entire function fails, blocking all extra reward collection.
Submitted by hyh
There is no check for the reward token amount to be transferred out in stashRewards(). As reward token list is external (controlled with IGauge(gauge).reward_tokens), and an arbitrary token can end up there, in the case when such token doesn’t allow for zero amount transfers, the stashRewards() managed extra rewards retrieval can become unavailable.
I.e. stashRewards() can be blocked for even an extended period of time, so all other extra rewards gathering will not be possible. This cannot be controlled by the system as pool reward token list is external.
Setting the severity to medium as reward gathering is a base functionality of the system and its availability is affected.
Proof of Concept
stashRewards() attempts to send the amount to rewardArbitrator() without checking:
if (activeCount > 1) {
//take difference of before/after(only send new tokens)
uint256 amount = IERC20(token).balanceOf(address(this));
amount = amount.sub(before);
//send to arbitrator
address arb = IDeposit(operator).rewardArbitrator();
if (arb != address(0)) {
IERC20(token).safeTransfer(arb, amount);
}
}
If IStaker(staker).withdraw() produced no new tokens for any reason, the amount = amount.sub(before) above can be zero:
uint256 before = IERC20(token).balanceOf(address(this));
IStaker(staker).withdraw(token);
As reward token can be arbitrary, it can also be reverting on an attempt to transfer zero amounts:
https://github.com/d-xo/weird-erc20#revert-on-zero-value-transfers
If this be the case then the whole stashRewards() call will be failing until IStaker(staker).withdraw() manage to withdraw some tokens or such token be removed from gauge’s reward token list. Both events aren’t directly controllable by the system.
Recommended Mitigation Steps
Consider running the transfer only when amount is positive:
- if (activeCount > 1) {
+ if (amount > 0 && activeCount > 1) {
//take difference of before/after(only send new tokens)
uint256 amount = IERC20(token).balanceOf(address(this));
amount = amount.sub(before);
//send to arbitrator
address arb = IDeposit(operator).rewardArbitrator();
if (arb != address(0)) {
IERC20(token).safeTransfer(arb, amount);
}
}
jetbrain10 (veToken Finance) confirmed
Alex the Entreprenerd (judge) commented:
The warden has shown how, due to a lack of check for zero-transfer, for specific tokens, the
stashRewadsfunction can be made to revert, causing it not to process any reward tokenBecause this is contingent on the token having zero-balance and reverting, I think Medium Severity to be appropriate.
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 code does not check that the transfer amount is greater than zero before calling safeTransfer, and some ERC20 tokens revert on zero-value transfers.
Impact
Reward gathering, a base functionality, can be blocked for an extended period, preventing all extra rewards from being collected.
What the attacker needed
A reward token that reverts on zero transfers; the token is in the gauge's reward list
The fix
The transfer should only be executed when the amount is positive.
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 smart contract tries to send reward tokens to a central address. Some tokens refuse to transfer if the amount is zero. If such a token is in the reward list, the whole reward-collection function stops working, so no rewards can be gathered.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.