Liquid Staking

Stakelink
DeFiHardhatOracle
50,000 USDC
View results
Submission Details
Severity: medium
Invalid

Reverting `splitRewards` Function When No New Rewards

Summary

The splitRewards function in the LSTRewardsSplitter contract reverts when there are no new rewards to split, causing unexpected behavior and violating the intended functionality of the contract. This issue occurs due to the else if (newRewards == 0) condition that explicitly reverts when newRewards is zero.

Vulnerability Details

The splitRewards function reverts with the InsufficientRewards error when there are no new rewards to split. This occurs because the function calculates the new rewards by subtracting the principalDeposits from the current balance of the contract. If the result is exactly zero, the function enters the else if (newRewards == 0) condition and reverts.

https://github.com/Cyfrin/2024-09-stakelink/blob/f5824f9ad67058b24a2c08494e51ddd7efdbb90b/contracts/core/lstRewardsSplitter/LSTRewardsSplitter.sol#L116-L125

else if (newRewards == 0) {
revert InsufficientRewards();
}

The issue arises when a user attempts to call the splitRewards function when there are no new rewards to distribute. Instead of gracefully handling this scenario and returning without performing any actions, the function reverts, causing the transaction to fail and potentially leading to unexpected behavior for users interacting with the contract.

Instead of gracefully handling the scenario where there are no new rewards and returning without performing any actions, the function reverts, causing the transaction to fail and potentially leading to confusion and frustration for users interacting with the contract.

To reproduce.

  1. Call the deposit function with an amount equal to the current balance of the contract, ensuring that there are no new rewards to split.

  2. Call the splitRewards function.

The splitRewards function will revert with the InsufficientRewards error because newRewards will be zero.

Impact

The reverting behavior of the splitRewards function can negatively impact users who attempt to call the function when there are no new rewards to split. Instead of the function executing successfully and not performing any actions, it will revert and cause the transaction to fail. This can lead to confusion and frustration for users interacting with the contract, as they may expect the function to handle the case when there are no new rewards gracefully.

Tools Used

Manual Review

Recommendations

Modify the splitRewards function to handle the case when newRewards is zero without reverting by removing the else if (newRewards == 0) condition and only calling _splitRewards when newRewards is greater than zero.

function splitRewards() external {
int256 newRewards = int256(lst.balanceOf(address(this))) - int256(principalDeposits);
if (newRewards < 0) {
principalDeposits -= uint256(-1 * newRewards);
- } else if (newRewards == 0) {
- revert InsufficientRewards();
} else {
_splitRewards(uint256(newRewards));
}
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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