Rewards supplied to a gauge, prior to its first depositor will be permanently lost
Rewards sent to a gauge before its first depositor are permanently locked because the gauge's reward accounting does not handle a zero total supply. An attacker or automated process could cause loss of funds by triggering reward distribution to an empty gauge.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-06-velocimeter-judging/issues/243
Found by
bughuntoor
Summary
Rewards supplied to a gauge, prior to its first depositor will be permanently lost.
Vulnerability Detail
Every week, gauges receive rewards based on their pool weight, within the Voter contract.
function distribute(address _gauge) public lock {
IMinter(minter).update_period();
_updateFor(_gauge); // should set claimable to 0 if killed
uint _claimable = claimable[_gauge];
if (_claimable > IGauge(_gauge).left(base) && _claimable / DURATION > 0) {
claimable[_gauge] = 0;
if((_claimable * 1e18) / currentEpochRewardAmount > minShareForActiveGauge) {
activeGaugeNumber += 1;
}
IGauge(_gauge).notifyRewardAmount(base, _claimable);
emit DistributeReward(msg.sender, _gauge, _claimable);
}
}
The problem is that any rewards sent to the gauge prior to its first depositor will remain permanently stuck. Given that rewards are sent automatically, the likelihood of such occurrence is significantly higher
Impact
Loss of funds
Code Snippet
Tool used
Manual Review
Recommendation
Revert in case current supply is 0.
Discussion
nevillehuang
@dawiddrzala Could you assist in verifying if this issue is valid? I initially thought it was invalid because it is unrealistic to deposit rewards when there is no depositors. However, given distribute is permissionless, could this be an issue?
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Velocimeter/v4-contracts/pull/23
Audinarey
@WangSecurity
This impact alone I believe is low severity, I don't see it as a "loss of funds" or a "loss of yield".
...As I've said it's not a loss of funds because no one should get those rewards, including the protocol.
you mentioned here about a week ago that this is a low. How come this is a medium in this case as the scenario is about the same?
cc: @nevillehuang @cvetanovv
spacegliderrrr
There is loss of funds - tokens are stuck and no once can retrieve them. The tokens hold monetary value, therefore this is loss of funds.
Given that distribution happens both automatically and in a permissionless way, the likelihood of the vulnerability scales exponentially. Issue should remain as is.
WangSecurity
I agree with @spacegliderrrr here. The reward distribution on Velocimeter is automatic, while on Kwenta it required an admin to send the rewards.
Additionally, on the issue you mentioned, the problem was that the owner would send rewards before anyone stakes, which is admin mistake and we should assume it wouldn't happen. I didn't mention it initially because I understood it a bit later when the discussion on Kwenta stopped. Also, the issue required for all the stakers to withdraw from the contract. Here, the distribution is automatic and doesn't require any mistakes.
Also, for a detailed answer on Kwenta, look at the discussion under issue 94 where Watsons explained why in the context of Kwenta it was even better to keep these funds in the contract.
Hence, I agree it should remain as it is in the context of Velocimeter.
spacegliderrrr
Fix looks good. notifyRewardAmount now checks that totalSupply > 0
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
Likely the gauge's notifyRewardAmount function does not check that totalSupply is greater than zero before accepting rewards, so rewards sent when no one has deposited become permanently locked.
Impact
Rewards sent to a gauge before its first depositor are permanently lost, and because distribution is automatic and permissionless, the likelihood of this occurring is significantly higher.
What the attacker needed
Gauge has no depositors yet; rewards are distributed to the gauge
The fix
The issue was fixed by making notifyRewardAmount check that totalSupply is greater than zero.
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 gauge is a smart contract that holds rewards for people who deposit tokens. If rewards are sent before anyone deposits, the contract has no way to give them out, so the tokens are stuck forever. This can happen automatically because rewards are distributed on a schedule.
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.