Liquid Staking

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

Risk of Arithmetic Error in Total Deposit Change Calculation

Summary

The performUpkeep function in the RebaseController contract is at risk of arithmetic errors due to the multiplication of a potentially large totalDepositChange by 10000. This can result in numerical inaccuracies and cause the transaction to fail, disrupting the contract's intended functionality.

Vulnerability Details

Multiplying totalDepositChange by 10000 can produce a value that exceeds the numerical limits of the data type.

https://github.com/Cyfrin/2024-09-stakelink/blob/f5824f9ad67058b24a2c08494e51ddd7efdbb90b/contracts/core/RebaseController.sol#L130

function performUpkeep(bytes calldata _performData) external onlyRebaseBot {
if (priorityPool.poolStatus() == IPriorityPool.PoolStatus.CLOSED) revert PoolClosed();
(uint256[] memory strategiesToUpdate, uint256 totalDepositChange) = abi.decode(
_performData,
(uint256[], uint256)
);
if (strategiesToUpdate.length == 0 || totalDepositChange == 0)
revert NoStrategiesToUpdate();
@=> if ((10000 * totalDepositChange) / stakingPool.totalSupply() > maxRebaseLossBP) {
priorityPool.setPoolStatus(IPriorityPool.PoolStatus.CLOSED);
insurancePool.initiateClaim();
} else {
stakingPool.updateStrategyRewards(strategiesToUpdate, "");
}
}

Scenario:
- Values:

  • totalDepositChange = 2,000,000,000,000,000,000,000 (2e21)

  • stakingPool.totalSupply() = 10,000,000,000,000,000,000,000 (1e22)

  • maxRebaseLossBP = 500 (5%)


- Calculation:

  1. Multiplication:

    • Calculate 10000 * totalDepositChange

    • 10000 * 2,000,000,000,000,000,000,000 = 20,000,000,000,000,000,000,000,000

  2. Division:

    • (20,000,000,000,000,000,000,000,000,000) / 10,000,000,000,000,000,000,000

    • The result is 2000

  3. Result:

    • 2000 > maxRebaseLossBP (500)

Impact

  • The arithmetic error can cause repeated transaction failures.

  • Legitimate updates to strategy rewards may be blocked.

Tools Used

Manual review

Recommendations

Instead of performing a direct multiplication, you can rearrange the arithmetic to avoid large intermediate values. This approach involves calculating the ratio first and then scaling it.

Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Out of scope

Support

FAQs

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