In Solidity, the use of for loops within public or external functions can lead to high gas costs and potential Denial of Service (DoS) attacks. This report identifies instances of for loops in the SablierV2 contracts that could pose these risks, particularly in the context of nested loops and large input arrays.
For loops in public or external functions can be exploited to cause DoS attacks by making the function calls prohibitively expensive or causing them to run out of gas. This is especially problematic when loops iterate over large arrays or when nested loops are used. Specific instances of such for loops in the SablierV2 contracts are as follows:
SablierV2Lockup.sol
SablierV2BatchLockup.sol
SablierV2MerkleLockupFactory.sol
The primary impact of this vulnerability is the potential for DoS attacks. Attackers can exploit the high gas costs associated with these for loops to make the functions prohibitively expensive to call, thereby disrupting the contract’s intended operations and potentially locking out legitimate users.
Manual code review
Static analysis tools for identifying loops and gas usage patterns
Avoid large for loops: Refactor the functions to avoid iterating over large arrays in a single transaction.
Batch processing: Implement batch processing with a limit on the number of items processed in each transaction to prevent excessive gas consumption.
Off-chain computation: Where feasible, perform computations off-chain and submit the results on-chain to reduce gas costs.
Gas limit checks: Incorporate checks to ensure that the gas required for loop execution does not exceed a safe threshold.
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.