sherlock-audit / 2024-08-saffron-finance-judging

9 stars 5 forks source link

vizay9652 - strict equality check in `LidoVault::deposit` function prevents vault from starting. #158

Open sherlock-admin4 opened 1 month ago

sherlock-admin4 commented 1 month ago

vizay9652

Medium

strict equality check in LidoVault::deposit function prevents vault from starting.

Summary

The LidoVault::deposit function has a condition where strict equality check, which prevents the vault from starting.

Vulnerability Detail

In LidoVault.sol:382 and LidoVault.sol:383 lines uses strict equality checks

  1. let us assume fixedSideCapacity is 1000 ether.
  2. users started depositing their ETH in this contract.
  3. If fixedETHDepositTokenTotalSupply becomes 999.999 eth
  4. Now user has to deposit 0.001 eth in order to satisfy these conditions fixedETHDepositTokenTotalSupply == fixedSideCapacity && variableBearerTokenTotalSupply == variableSideCapacity.
  5. But he can't deposit 0.001 eth because minimumDepositAmount is 0.01 eth.
  6. So, the strict equality conditions fails and prevents the vault from starting.

Code Snippet

https://github.com/sherlock-audit/2024-08-saffron-finance/blob/main/lido-fiv/contracts/LidoVault.sol#L382-L383

 if (
@>      fixedETHDepositTokenTotalSupply == fixedSideCapacity && variableBearerTokenTotalSupply == variableSideCapacity
    ) {
      startTime = block.timestamp;
      endTime = block.timestamp + duration;
      fixedSidestETHOnStartCapacity = stakingBalance();
      fixedIntialTokenTotalSupply = fixedClaimTokenTotalSupply;
      emit VaultStarted(block.timestamp, msg.sender);
    }

Tool used

Manual Review

Recommendation

use tolerance

+  uint256 tolerance = 0.01 ether;
    if (
-     fixedETHDepositTokenTotalSupply == fixedSideCapacity && variableBearerTokenTotalSupply == variableSideCapacity
+    (fixedETHDepositTokenTotalSupply >= fixedSideCapacity - tolerance && fixedETHDepositTokenTotalSupply <= fixedSideCapacity) && (variableBearerTokenTotalSupply >= variableSideCapacity - tolerance && variableBearerTokenTotalSupply <= variableSideCapacity)
    )