ConvexStakingWrapper deposits and withdraws will frequently be disabled if a token that doesn’t allow zero value transfers will be added as a reward one
The ConvexStakingWrapper contract unconditionally transfers reward tokens to a claim contract during deposit and withdraw operations, even when the incremental reward amount is zero. If a reward token that reverts on zero-value transfers is added, these transfers will fail, causing deposits and withdrawals to revert and effectively disabling them.
Submitted by hyh
If deposits and withdraws are done frequently enough, the reward update operation they invoke will deal mostly with the case when there is nothing to add yet, i.e. reward.remaining match the reward token balance.
If reward token doesn’t allow for zero value transfers, the reward update function will fail on an empty incremental reward transfer, which is now done unconditionally, reverting the caller deposit/withdrawal functionality
Proof of Concept
When ConvexStakingWrapper isn’t paused, every deposit and withdraw update current rewards via _checkpoint function before proceeding:
_checkpoint calls _calcRewardIntegral for each of the reward tokens of the pid:
_calcRewardIntegral updates the incremental reward for the token, running the logic even if reward is zero, which is frequently the case:
If the reward token doesn’t allow zero value transfers, this transfer will fail, reverting the corresponding deposit or withdraw.
Recommended Mitigation Steps
Consider checking the reward before doing transfer (and the related computations as an efficiency measure):
Now:
IERC20(reward.token).transfer(address(claimContract), d_reward);
To be:
if (d_reward > 0)
IERC20(reward.token).transfer(address(claimContract), d_reward);
Alex the Entreprenerd (judge) commented:
The warden has shown how, due to a pattern that always transfers the reward token to the claim contract, in the case of a 0 transfer, certain transfers could fail, causing reverts.
While there can be an argument that this finding may not happen in reality, I believe that ultimately the system has been shown to be flawed in it’s conception, perhaps adding a storage variable for the amount to claim would be more appropriate instead of dripping the rewards each time.
For that reason, and because the finding is contingent on a reward token that does revert on 0 transfer, I believe 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
The contract performs an unconditional transfer of reward tokens, even when the incremental reward amount is zero, without checking if the amount is greater than zero.
Impact
Deposits and withdrawals could be frequently disabled for users if a reward token that reverts on zero-value transfers is added, as the reward update would fail and revert the entire transaction.
What the attacker needed
A reward token that reverts on zero-value transfers; frequent deposits or withdrawals
The fix
The contract should check that the incremental reward amount is greater than zero before attempting the transfer, so that zero-value transfers are skipped.
How it was found
- A reward token that does not allow zero-value transfers is added to the ConvexStakingWrapper.
- A user frequently deposits or withdraws, causing the reward update to run when the incremental reward is zero.
- The contract attempts to transfer zero reward tokens to the claim contract.
- The transfer reverts because the token disallows zero-value transfers, causing the deposit or withdrawal to fail.
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 or withdraw tokens, the contract also updates and sends out any rewards you've earned. It always tries to send the reward amount, even if that amount is zero. Some tokens don't allow sending zero amounts and will cause an error, which stops your deposit or withdrawal from working.
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.