The MembershipFactory
contract includes a loop over the tierConfigs
array without limiting the number of iterations. If the array grows too large, looping through it may exceed the block gas limit, leading to a failure of all transactions that rely on this loop. This vulnerability becomes critical if an attacker can influence the array’s length, as they could deliberately inflate the array to perform a Denial of Service (DoS) attack, blocking functionality dependent on the loop.
The vulnerability arises from unbounded iterations over the tierConfigs
array in two separate instances within the MembershipFactory
contract. When these loops execute, they iterate over each element of the tierConfigs
array, and if the array size is excessively large, this operation may consume more gas than a single block’s limit allows. Consequently, the loop cannot complete, and the transaction fails.
The lack of bounds on tierConfigs.length
in this context is a critical oversight, especially if the array’s length is influenced by external actors, who may intentionally increase it to induce a DoS condition.
MembershipFactory.sol: Line 114
MembershipFactory.sol: Line 122
Denial of Service (DoS) risk due to unbounded loop iterations that may exceed the block gas limit, preventing transactions from confirming. This vulnerability is reasonably likely to be encountered, especially in a decentralized environment where users may attempt to game the system. If an attacker can add entries to the tierConfigs
array, either directly or through another mechanism within the system, they could intentionally inflate its length to disrupt the contract. Even without malicious intent, regular usage over time could grow the array sufficiently to unintentionally trigger this issue.
Proof of Concept
An attacker could invoke the contract in a way that adds multiple entries to the tierConfigs
array, either directly or indirectly. Here’s an outline of how they might proceed:
Add Entries: The attacker inflates the tierConfigs
array by adding a large number of entries.
Trigger DoS: When a function calls the following line:
The loop iterates over all entries, consuming excessive gas and exceeding the block gas limit.
Transaction Failure: The function fails due to the gas limit, preventing further operations that rely on this loop.
Manual Review
Implement Batching: Refactor the loop logic to process the tierConfigs
array in manageable batches rather than in a single transaction. This would allow handling large arrays across multiple transactions, avoiding the risk of gas exhaustion. A sample implementation could look like this:
Set Maximum Iteration Limit: Limit the number of iterations per call by defining a maxIterations
constant. This cap prevents the loop from executing an unbounded number of times:
Off-Chain Computation: Consider handling large datasets off-chain where feasible. Off-chain processing avoids the gas limit restrictions of Ethereum, especially for non-critical or repetitive tasks.
Implementing these changes will reduce the likelihood of DoS attacks and improve the contract’s resilience, ensuring it can handle varying data volumes without operational disruption.
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.