Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: high
Invalid

[H-1] Staking rewards exceed `Staking.sol` contract balance leading to stuck user funds

Description: In the current implementation of the Staking.sol contract, there is an issue where user funds could become stuck due to the contract attempting to distribute more staking rewards than the balance it holds. The contract calculates rewards based on the number of tokens staked and the time they have been staked, without adequately checking whether sufficient funds are available to cover these rewards.

Impact: If the contract's balance is insufficient to cover the calculated rewards, any call to the claimRewards function will fail, preventing the claiming of rewards.

Proof of concept: Add this function to the existing StakingTest.t.sol file.

function testRewardsExceedContractBalance() public {
// Step 1: Deposit Tokens
uint256 amountToStake = 100000 ether; // Large amount to stake
uint256 weeksToFastForward = 50; // Number of weeks to simulate
_depositTokenToStake(amountToStake);
// Step 2: Fast Forward Time
vm.warp(block.timestamp + weeksToFastForward * 1 weeks);
// Check the expected rewards and ensure they exceed the contract's balance
uint256 expectedRewards = amountToStake * weeksToFastForward;
console2.log("ExpectedRewards: ", expectedRewards);
uint256 contractBalance = loveToken.balanceOf(address(stakingContract));
console2.log("Contractbalance: ", contractBalance);
require(contractBalance < expectedRewards, "Contract has enough funds, adjust the test scenario");
// Step 3: Attempt to Claim Rewards, expecting revert
vm.startPrank(soulmate1);
vm.expectRevert();
stakingContract.claimRewards();
vm.stopPrank();
}

Recommended mitigation: To prevent this issue, the Staking contract should implement a check before attempting to distribute rewards to ensure that the contract's balance is sufficient to cover the rewards. If the balance is not sufficient, the contract could proportionally reduce the rewards to match the available balance or prevent the reward claim until the balance is replenished.

Updates

Lead Judging Commences

0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.