Liquid Staking

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

test/core/priorityPool/withdrawal-pool.test.ts

Below are key areas of concern based on your provided test suite and code logic.


1. Authorization Issues

Observation:

  • There are checks for SenderNotAuthorized() on withdrawal functions, but:

    • It is important to verify that only intended roles (like the contract owner or assigned addresses) can queue and withdraw funds.

    • The presence of .connect(signers[1]) indicates that multiple accounts can interact with the contract, which raises concerns. Ensure access control is enforced.

Risk:

  • A missing or incorrect access control setup can lead to unauthorized withdrawals or deposits.

Mitigation:

  • Verify that onlyOwner or AccessControl patterns are correctly used in queueWithdrawal and withdraw.


2. Reentrancy Vulnerability

Observation:

  • There is no mention of a reentrancy guard in the withdraw function. If a token or staking contract used allows fallback functions or external calls, reentrancy can occur.

Risk:

  • If the contract sends tokens or Ether before updating state variables, an attacker might exploit reentrancy and withdraw multiple times.

Mitigation:

  • Use nonReentrant modifiers (like from OpenZeppelin) or follow the checks-effects-interactions pattern in critical functions such as withdraw.


3. Inconsistent Data Validation (Deposit Logic)

Observation:

  • In the deposit function:

    await withdrawalPool.deposit(toEther(1751)).to.be.reverted
    • The logic assumes a strict limit for deposits, but overflows or underflows might occur if token balances aren’t managed well (e.g., ERC20 token decimals vs Ether precision).

    • There’s also a lot of batching logic, which could result in incorrect tracking of withdrawal states if batch IDs are not carefully maintained.

Risk:

  • Incorrect balances or infinite reverts during deposits if the total queued withdrawals don’t align with expected amounts.

Mitigation:

  • Ensure deposit logic handles overflows gracefully, and batch IDs are tracked accurately without double spending of tokens. Use safemath operations (if not covered by Solidity 0.8.x).


4. Withdrawal Logic Validation

Observation:

  • Withdrawals depend on IDs returned from getWithdrawalIdsByOwner and getBatchIds. If these IDs are not correctly tracked or reset, the system may malfunction.

    • The following assertion is problematic if state changes are not atomic:

      assert.deepEqual(
      (await withdrawalPool.getWithdrawals([1, 2, 3])).map((d: any) => [fromEther(d[0]), fromEther(d[1])]),
      [[0, 0], [0, 0], [0, 0]]
      )

Risk:

  • If an ID tracking bug exists, users may withdraw more than intended, leading to financial loss.

Mitigation:

  • Carefully validate edge cases where withdrawal IDs might not reset correctly. Implement unit tests to cover multiple deposit/withdrawal cycles and stale withdrawal requests.


5. Insufficient Handling of ERC20 Approval Limits

Observation:

await token.approve(stakingPool.target, ethers.MaxUint256)
  • Approving unlimited allowances can expose the user to attacks, especially if the StakingPool or WithdrawalPool contracts are malicious or compromised.

Risk:

  • A malicious actor could drain the user’s entire token balance if proper revocation of approvals is not in place.

Mitigation:

  • Use limited allowances wherever possible and encourage users to revoke approvals after interactions.


6. Lack of Event Emissions for Key Actions

Observation:

  • There are no indications that the functions emit events when withdrawals, deposits, or updates occur. This can make tracking critical actions difficult on-chain.

Risk:

  • Security monitoring and debugging become harder without events, leading to undetected issues.

Mitigation:

  • Add events like WithdrawalQueued, DepositMade, and WithdrawalCompleted for better transparency and auditing.


7. Time Dependency Risks

Observation:

  • The contract relies on block timestamps for withdrawals (e.g., 86400 seconds). If users can manipulate timestamps (through miners or flashbots), it could lead to time-based exploits.

Risk:

  • A block timestamp manipulation could allow users to game the system for faster or delayed withdrawals.

Mitigation:

  • Use block numbers or a range-based check for time-sensitive operations.


8. Batch Logic Vulnerability

Observation:

  • The batching logic with IDs can introduce inconsistencies if not handled properly (e.g., withdrawals might be queued incorrectly or skipped).

  • This could result in some users receiving more than their fair share.

Risk:

  • If batch tracking gets corrupted, it may cause loss of funds or withdrawal deadlocks.

Mitigation:

  • Include edge-case tests to ensure the correct functioning of batched withdrawals, especially under stress or network failures.


Summary of Vulnerabilities and Mitigations

Issue Risk Mitigation
Authorization Issues Unauthorized withdrawals Use onlyOwner or AccessControl
Reentrancy Multiple withdrawals via fallback attack Use nonReentrant or checks-effects-interactions
Inconsistent Deposit Logic Overflow or underflow in deposits Use safe math and validate deposits carefully
Incorrect ID Tracking Users withdraw more than allowed Validate batch logic with comprehensive tests
Unlimited Allowances Draining of funds via compromised contracts Use limited approvals and encourage revocation
Lack of Event Emissions Harder to audit and detect issues Add events for key actions
Time Dependency Timestamp manipulation for advantage Use block numbers instead of timestamps
Batch Logic Vulnerability Incorrect batching leading to loss or deadlocks Implement edge-case tests for batching functionality

This review covers the potential risks in your code based on the visible logic and test suite.

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.