The getLiveMarketsIds
function in the LiveMarkets
contract does not impose any limits on the number of market IDs returned in a single call. This can lead to a Denial of Service (DoS) vulnerability when a large number of market IDs are added to the contract, causing excessive gas consumption and potential failure of the transaction due to exceeding the block gas limit.
Severity: Medium
Likelihood: High
Impact: Medium
Affected line of code
The getLiveMarketsIds
function retrieves all market IDs stored in the contract. However, as the number of live market IDs grows, the gas required to process the loop in the function increases. If the set of market IDs becomes large enough, calling this function can consume more gas than the block allows, leading to a failure (out-of-gas error).
Denial of Service (DoS): An attacker or user could add a large number of market IDs, and then any attempt to retrieve the list of market IDs would fail due to excessive gas usage.
This could make the contract unusable for retrieving market IDs once the list grows beyond a certain size.
Test Setup:
Add a large number of market IDs to the contract (e.g., 100,000 markets).
Call the getLiveMarketsIds
function to retrieve the list of market IDs.
Test Code:
Test Results:
Running the test resulted in an OutOfGas error, confirming that the function fails when attempting to handle a large number of market IDs:
Manual Review, Foundry
Pagination: Modify the getLiveMarketsIds
function to implement pagination, allowing users to query a smaller subset of market IDs at a time. This would limit the gas usage per query and prevent DoS.
Limit the number of market IDs: Implement a maximum limit on the number of market IDs that can be stored or retrieved in a single transaction.
For example, update the getLiveMarketsIds
function to accept an offset
and limit
parameter to return a portion of the market IDs:
This change would allow for smaller, paginated queries, reducing the risk of excessive gas consumption.
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.