Storm-Labs-Inc / cove-contracts-boosties

Core smart contracts of the Cove Protocol
Other
18 stars 6 forks source link

Security: Incorrect Order of Checkpoint in function _withdraw #338

Open smartsmartsec opened 7 months ago

smartsmartsec commented 7 months ago

Impact

Affected component(s)

function _withdraw in YearnStakingDelegate.sol

Attack vector(s)

An attacker could exploit the out-of-order execution of balance update and checkpoint recording, possibly leading to inaccurate state management within the contract, which could further be manipulated to disrupt the contract’s intended functionality.

Suggested description of the vulnerability for use in the CVE

The _withdraw function in the smart contract managing staking operations exhibits a vulnerability where the checkpoint for user balance (_checkpointUserBalance) is recorded after updating the user's balance (balanceOf[msg.sender][gauge]). This incorrect sequence can lead to discrepancies between the actual user balance and the recorded checkpoint. This flaw can potentially be exploited to cause disruptions in balance tracking and operations within the contract, leading to denial of service and other unintended behaviors.

Discoverer(s)/Credits

xFuzz

Proposed Solution

To mitigate this vulnerability, the checkpoint recording operation should be reordered to occur before updating the user’s balance. The corrected sequence should be:

  1. Record the checkpoint using _checkpointUserBalance.
  2. Update balanceOf[msg.sender][gauge].
  3. Adjust totalDeposited[gauge].

Reference(s)