The _recalculateConnectedMarketsState
function contains nested loops that iterate over connectedMarketsIdsCache
, potentially leading to gas exhaustion when processing a large number of connected markets. This issue can cause transactions to fail due to excessive gas consumption, making the contract inefficient and unreliable. To mitigate this, implementing pagination or batch processing is recommended.
Location: _recalculateConnectedMarketsState
function
Severity: High
Type: Gas Optimization
Issue: The function contains unbounded nested loops that iterate over connectedMarketsIdsCache
. If the array grows too large, executing this function in a transaction could exceed the block gas limit, causing transaction failure and potential denial of service.
Reproducibility: High
The function does not impose a limit on the number of iterations when processing connectedMarketsIdsCache
. As a result, when the number of connected markets is large, the computation required becomes excessive, leading to gas exhaustion.
Transactions may fail due to excessive gas consumption.
The function could make certain operations unusable in production environments where the dataset grows significantly.
Users interacting with the function may experience higher transaction fees.
Potential denial of service if critical functions depend on this logic.
Hardhat
Foundry
Slither (for static analysis)
Gas Reporter (for gas cost estimation)
To validate this issue, i simulate a scenario where connectedMarketsIdsCache
contains a large number of entries, causing gas exhaustion. Below is a Hardhat test to demonstrate this:
This test populates connectedMarketsIdsCache
with a large dataset and attempts to execute _recalculateConnectedMarketsState()
, expecting a gas exhaustion failure.
To resolve this issue, consider the following fixes:
Batch Processing: Process the connectedMarketsIdsCache
in smaller chunks rather than iterating over all entries in a single transaction.
Pagination: Allow users to process connectedMarketsIdsCache
incrementally across multiple transactions instead of doing it all at once.
Gas Limit Check: Implement logic to halt execution when the function is approaching the block gas limit.
These changes prevent excessive gas consumption, making the function more efficient and scalable.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.