Anyone could call `depositReward` with zero reward to extend the period finish time
The depositReward function could be called by anyone with zero reward, which extended the reward period finish time and reduced the reward rate. This could cause users to receive fewer rewards than expected within the same time period.
0brxce Follow with 0xAnmol, 0xboriskataa and 43 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-03-zivoe-judging/issues/11
Found by
0brxce, 0xAnmol, 0xboriskataa, 0xpiken, 0xvj, 14si2o_Flint, 9oelm, AMOW, Afriaudit, Bauer, CL001, Dliteofficial, Drynooo, FastTiger, Ironsidesec, Krace, Kunhah, Maniacs, Nihavent, Ruhum, SilverChariot, Timenov, Tychai0s, amar, araj, asui, blockchain555, cergyk, coffiasd, dany.armstrong90, dimulski, forgebyola, heedfxn, jasonxiale, joicygiore, krikolkk, lemonmon, marchev, mt030d, novaman33, pashap9990, rbserver, sakshamguruji, sl1, sunill_eth, t0x1c
Summary
Anyone could extend the reward finish time, potentially resulting in users receiving fewer rewards than expected within the same time period.
Vulnerability Detail
The function depositReward can be called by anyone, even with zero rewards, allowing it to be exploited to extend the reward finish time at little cost.
This could result in loss of rewards; for instance, if there are 10 DAI rewards within a 10-day period, a malicious user could extend the finish time on day 5, extending the finish time to the 15th day. Participants would only receive 7.5 DAI by the 10th day.
function depositReward(address _rewardsToken, uint256 reward) external updateReward(address(0)) nonReentrant {
IERC20(_rewardsToken).safeTransferFrom(_msgSender(), address(this), reward);
// Update vesting accounting for reward (if existing rewards being distributed, increase proportionally).
if (block.timestamp >= rewardData[_rewardsToken].periodFinish) {
rewardData[_rewardsToken].rewardRate = reward.div(rewardData[_rewardsToken].rewardsDuration);
} else {
uint256 remaining = rewardData[_rewardsToken].periodFinish.sub(block.timestamp);
uint256 leftover = remaining.mul(rewardData[_rewardsToken].rewardRate);
rewardData[_rewardsToken].rewardRate = reward.add(leftover).div(rewardData[_rewardsToken].rewardsDuration);
}
rewardData[_rewardsToken].lastUpdateTime = block.timestamp;
rewardData[_rewardsToken].periodFinish = block.timestamp.add(rewardData[_rewardsToken].rewardsDuration);
emit RewardDeposited(_rewardsToken, reward, _msgSender());
}
POC
Add the test to zivoe-core-testing/src/TESTS_Core/Test_ZivoeRewards.sol and run it with forge test --match-test test_ZivoeRewards_deposit_zero --rpc-url <RPC_URL_MAINNET>
diff --git a/zivoe-core-testing/src/TESTS_Core/Test_ZivoeRewards.sol b/zivoe-core-testing/src/TESTS_Core/Test_ZivoeRewards.sol
index f5353b6..870a531 100644
--- a/zivoe-core-testing/src/TESTS_Core/Test_ZivoeRewards.sol
+++ b/zivoe-core-testing/src/TESTS_Core/Test_ZivoeRewards.sol
@@ -685,6 +685,33 @@ contract Test_ZivoeRewards is Utility {
}
+ function test_ZivoeRewards_deposit_zero() public {
+
+ depositReward_DAI(address(stZVE), 1);
+
+ (
+ uint256 rewardsDuration,
+ uint256 _prePeriodFinish,
+ uint256 _preRewardRate,
+ uint256 lastUpdateTime,
+ uint256 rewardPerTokenStored
+ ) = stZVE.rewardData(DAI);
+ console.log("period finish ", _prePeriodFinish);
+
+ vm.warp(block.timestamp + 1 days);
+
+ depositReward_DAI(address(stZVE), 0);
+
+ (,
+ uint256 _afterPeriodFinish,
+ ,
+ ,
+ ) = stZVE.rewardData(DAI);
+ console.log("period finish ", _afterPeriodFinish);
+ // extend the Finish 1 day
+ assertEq(_afterPeriodFinish - _prePeriodFinish, 1 days);
+ }
+
function test_ZivoeRewards_getRewards_works(uint96 random) public {
uint256 deposit = uint256(random) + 100 ether; // Minimum 100 DAI deposit.
Impact
Anyonce could extend the reward finish time and the users may receive less rewards than expected during the same time period.
Code Snippet
Tool used
Foundry
Recommendation
Only specific users are allowed to call function depositReward
Discussion
pseudonaut
Valid, considering adding whitelist
sherlock-admin3
1 comment(s) were left on this issue during the judging contest.
panprog commented:
high, allows anyone to extend reward finish time indefinitely and decrease reward rate.
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/Zivoe/zivoe-core-foundry/pull/260
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 depositReward function lacked access control, allowing anyone to call it and extend the reward period finish time even with zero reward.
Impact
Anyone could extend the reward finish time, causing users to potentially receive fewer rewards than expected during the same time period.
What the attacker needed
None
The fix
The protocol team fixed this issue by adding a whitelist to restrict who can call depositReward.
How it was found
- Call depositReward with a small reward to set up the reward period.
- Wait some time (e.g., one day).
- Call depositReward again with zero reward.
- Observe that the period finish time is extended by the duration.
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.
In a reward system, users earn tokens over a set period. The function that adds rewards could be called by anyone, even with zero tokens, and it would reset the end time of the reward period. This meant an attacker could keep pushing back the end date, so the same rewards were spread over a longer time, giving users less than they should get.
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.