Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: low
Invalid

Market Pausing/Unpausing Optimization and Zero Input Validation

Summary

The pauseMarket and unpauseMarket functions in the contract provide mechanisms to pause and unpause specific markets. While the functions operate correctly, certain improvements can be made to enhance efficiency and robustness, such as validating input and preventing redundant operations. This report highlights potential areas for improvement.

Affected Line of Code:

https://github.com/Cyfrin/2025-01-zaros-part-2/blob/main/src/market-making/branches/MarketMakingEngineConfigurationBranch.sol#L570-L573

https://github.com/Cyfrin/2025-01-zaros-part-2/blob/main/src/market-making/branches/MarketMakingEngineConfigurationBranch.sol#L578-L581

Vulnerability Details

  1. Zero Input Check (Low Severity):
    The current implementation does not validate whether the marketId is zero, which could lead to unintended behavior or errors when the contract processes invalid market IDs. While this doesn't introduce a direct security risk, it is a good practice to enforce this validation.

  2. Redundant Action Check (Low Severity):
    There is no check to ensure that the market is already in the desired state (paused or unpaused) before performing the action. While this doesn't directly compromise security, it results in unnecessary state changes, leading to increased gas usage and unnecessary transactions.

Impact

  • Zero Input Check:
    If a marketId of zero is passed, the contract could execute operations on an invalid market, potentially leading to errors or incorrect behavior. Adding this check helps ensure the contract only processes valid inputs.

  • Redundant Action Check:
    Without a check to verify the current state of the market, operations could be executed unnecessarily, causing inefficiency and increased gas costs. While not a critical vulnerability, this issue affects the contract's performance.

Tools Used

  • Manual Code Review

Recommendations

  1. Zero Input Check:
    Add a check to ensure that the marketId is non-zero before processing the operation. This would prevent errors and improve input validation.

    Example:

    require(marketId ! = 0, "Invalid market ID");
  2. Redundant Action Check:
    If the contract is not already tracking the market's current state (e.g., whether it's paused or unpaused), consider introducing a state tracking mechanism (e.g., a mapping) to optimize the contract's performance by avoiding unnecessary actions.

    Example:

    // Assuming a mapping that tracks whether a market is paused
    mapping(uint128 => bool) public pausedMarkets;
    if (pausedMarkets[marketId]) {
    revert("Market is already paused");
    }

By incorporating these checks, the contract will be more efficient and resilient, preventing unnecessary operations and ensuring that only valid actions are performed.

Updates

Lead Judging Commences

inallhonesty Lead Judge 6 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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