Liquid Staking

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

test/core/insurance-pool.test.ts

Analyzing this code, I’ve identified potential vulnerabilities and issues that could be exploited or might need attention. Below is a breakdown:


1. Missing Access Control:

  • Issue: Critical functions like setRewardsPool, deposit, requestWithdrawal, initiateClaim, and executeClaim appear to lack any specific access control mechanisms in the provided code.

  • Risk: If not properly restricted in the contract, unauthorized users could invoke sensitive functions, potentially disrupting the contract’s state or draining funds.

  • Mitigation: Ensure only privileged roles (like an admin or owner) can modify critical state variables or perform sensitive operations.


2. Withdrawal Timing Window Vulnerability:

  • Issue: The withdrawal functionality depends on a timing window (setWithdrawalParams). Attackers could trigger front-running by closely monitoring the blockchain and withdrawing funds as soon as the withdrawal window opens.

  • Risk: Front-running might result in unfair withdrawals or drained liquidity before other users get a chance to act.

  • Mitigation: Use commit-reveal patterns or randomness to prevent front-running.


3. Potential Reentrancy Vulnerability:

  • Issue: Functions like withdraw interact with tokens, which might include external calls. If the ERC677 tokens allow calling arbitrary code (via transferAndCall), this introduces the risk of reentrancy attacks.

  • Risk: An attacker could repeatedly call withdraw before the state is updated, draining the pool.

  • Mitigation: Use checks-effects-interactions pattern and consider adding a reentrancy guard.


4. Unchecked Return Values for ERC677 Approvals and Transfers:

  • Issue: In the code, ERC677 token approvals (approve) and transfers (transferAndCall) are not verified to check whether they succeeded.

  • Risk: Some ERC20-compatible tokens return false on failure instead of reverting. Ignoring these return values can result in failed operations without anyone noticing.

  • Mitigation: Use require statements to check return values:

    require(token.approve(...), "Approval failed");

5. Integer Overflow and Underflow Risks:

  • Issue: If deployed with older Solidity versions, arithmetic operations could be susceptible to overflow or underflow (e.g., totalDeposits() calculations).

  • Mitigation: Ensure the Solidity version being used automatically includes SafeMath operations or explicitly use SafeMath libraries for older versions.


6. Token Decimals Assumption:

  • Issue: The code assumes tokens have a specific decimal configuration (e.g., toEther, fromEther). If the token decimals differ, this could lead to incorrect accounting.

  • Mitigation: Fetch and use the token's decimals dynamically to ensure correct conversions.


7. Lack of Slippage Control in executeClaim:

  • Issue: The executeClaim function is invoked with a specific claim amount. Without slippage control, unexpected market movements could cause losses.

  • Mitigation: Introduce slippage tolerance limits in executeClaim logic.


8. Rewards Logic Issues:

  • Observation:

    • The rewardPerToken() returns 0 initially and only updates on certain deposits. Depending on reward logic, this could cause distribution inefficiencies.

    • The rewardPerToken() being 0 might indicate either an incorrect reward configuration or a bug.

  • Mitigation: Check reward formula calculations and ensure they update consistently.


9. Use of any Type in TypeScript:

  • Issue: The use of any for the adrs object weakens type safety.

  • Mitigation: Define precise types for the adrs object to avoid type-related bugs.


10. Lack of Test Cases for Edge Scenarios:

  • Issue: The test suite focuses on normal behavior but lacks edge-case scenarios such as:

    • Depositing very large values.

    • Handling failures in approve or transfer.

    • Concurrent withdrawals or reward claims.

  • Mitigation: Add more test cases covering these scenarios to strengthen contract robustness.


Summary and Recommendations:

This code demonstrates a well-organized structure for testing the InsurancePool contract, but it contains vulnerabilities that could compromise the integrity of the system. Here are the main action points to improve the contract:

  1. Implement access control on sensitive functions.

  2. Check for reentrancy and use ReentrancyGuard.

  3. Validate ERC677 operations with require.

  4. Ensure arithmetic safety by using SafeMath if needed.

  5. Add more edge-case tests and slippage control mechanisms.

These changes should improve the security and reliability of the smart contracts.

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.