Liquid Staking

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

contracts/core/StakingPool.sol

The Solidity code you provided outlines a StakingPool contract that includes various functionalities for staking tokens, managing strategies, and handling fees. Here are some potential vulnerabilities and areas of improvement to consider:

1. Reentrancy Vulnerability

  • Although the contract uses safeTransfer from OpenZeppelin's SafeERC20 library, it is essential to ensure that state changes (like totalStaked) occur before transferring tokens or invoking external calls (like strategy deposits or withdrawals). This prevents reentrancy attacks where a malicious contract could call back into the function before the state is fully updated.

  • Mitigation: Use a non-reentrant modifier from OpenZeppelin, or follow the Checks-Effects-Interactions pattern rigorously.

2. Integer Overflow/Underflow

  • Solidity 0.8.0 and above includes built-in overflow and underflow checks. However, when doing calculations like totalStaked -= toWithdraw, ensure that the contract never goes below zero, as this can lead to unintended behaviors.

  • Mitigation: Consider using require(totalStaked >= toWithdraw, "Insufficient staked amount"); before deducting.

3. Unchecked External Call

  • Functions like IStrategy(strategies[_index]).withdraw(...) and IStrategy(strategies[_index]).deposit(...) are external calls that can fail. If they do, the contract will not handle that gracefully, which can lead to funds being stuck or inconsistencies in the state.

  • Mitigation: Always check the return values of external calls, and consider implementing a failsafe or error handling mechanism.

4. Lack of Events for Critical Actions

  • While there are some events defined, certain critical actions (like deposits, withdrawals, and strategy updates) could benefit from additional events to improve transparency and traceability.

  • Mitigation: Emit events for state-changing functions to allow for better tracking of contract activity.

5. Improper Handling of Fees

  • The function getStrategyRewards allows for calculating fees based on rewards. If the fees exceed totalStaked, they are set to zero, which can lead to logical issues in the financial calculations.

  • Mitigation: Consider refining the fee calculation logic and ensuring that it reflects the expected behavior when managing funds.

6. Access Control

  • While there are modifiers like onlyOwner, make sure that all sensitive functions are protected against unauthorized access. Ensure that onlyOwner is only applied where necessary.

  • Mitigation: Review the use of onlyOwner to ensure that no unintended access is allowed.

7. Potential for Token Approval Race Condition

  • In the addStrategy function, the token approval (token.safeApprove(_strategy, type(uint256).max)) can create a race condition where a malicious contract could use this approval before it is used.

  • Mitigation: Consider using the recommended pattern of first setting the allowance to 0 and then to the desired value.

8. Unused Deposit Limit

  • The check for unusedDepositLimit in the deposit function may not prevent deposits beyond that limit, especially in the case of multiple deposits happening simultaneously.

  • Mitigation: Implement checks to ensure that the limit is respected, perhaps by accumulating the total deposits and checking against the limit before accepting new deposits.

9. Token Handling in donateTokens

  • The donateTokens function adds to totalStaked without regard to whether those tokens are actually usable or already part of the pool.

  • Mitigation: Ensure that there is logic in place to verify that the tokens received are legitimate and not already counted.

10. Gas Limit and Loops

  • Functions like getMaxDeposits, getMinDeposits, and getStrategyDepositRoom iterate through all strategies, which could run into gas limit issues if the number of strategies becomes too large.

  • Mitigation: Consider whether these functions can be optimized or whether they should have a limit on the number of strategies.

Summary

While the code seems well-structured and utilizes OpenZeppelin's libraries for safe token handling, these points highlight areas for improvement in security and robustness. Ensuring that the contract adheres to best practices for Solidity and incorporates thorough testing and auditing will help mitigate risks and improve reliability.

Updates

Lead Judging Commences

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Lack of quality

Support

FAQs

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