Project

One World
NFTDeFi
15,000 USDC
View results
Submission Details
Severity: medium
Invalid

Unchecked Array Length in MembershipFactory Contract Allows Gas Limit Denial of Service (DoS) Attack

Summary

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.

Vulnerability Details

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.

Affected Line of Code

Impact

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:

for (uint256 i = 0; i < tierConfigs.length; i++) {

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.

Tools Used

Manual Review

Recommendations

  • 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:

function processTierConfigs(uint256 startIndex, uint256 count) external {
uint256 endIndex = startIndex + count;
require(endIndex <= tierConfigs.length, "Out of bounds");
for (uint256 i = startIndex; i < endIndex; i++) {
// Processing logic for tierConfigs[i]
}
}
  • 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:

uint256 maxIterations = 100; // Define a maximum to limit gas consumption
for (uint256 i = 0; i < tierConfigs.length && i < maxIterations; i++) {
// Process each element
}
  • 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.

Updates

Lead Judging Commences

0xbrivan2 Lead Judge 8 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.