The withdrawMultiple
function in the SablierV2Lockup contract presents a potential vulnerability due to its high gas consumption. This function, which loops over arrays of streamId
and amount
, can become very expensive to execute if the arrays are large, possibly leading to failed transactions if the gas limit is exceeded.
The withdrawMultiple
function iterates through the provided arrays of streamId
, recipients
, and amounts
, calling the withdraw
function for each element. This linear increase in operations can result in high gas usage, especially with large input arrays. If the total gas required exceeds the block gas limit, the transaction will fail.
Adding this code to the withdrawMultiple.t.sol
file
Changing the parameters of uint256 testIds = 25
and uint128 testAmount = 25
, with 25 and 50 we can see the gas consumption of the withdrawMultiple
function.
Test for 25 streams and 50 streams here are the results:
High gas consumption due to the withdrawMultiple
function's design can lead to:
Transaction Failures: Users attempting to withdraw from multiple streams might experience failed transactions if the gas required exceeds the block limit.
High Transaction Costs: Even if the transaction does not fail, users may incur high gas fees, making the function impractical for large arrays.
Reduced Usability: The potential for high costs and failures can discourage users from using this function, reducing the overall utility of the contract.
Manual Code Review: Analyzed the contract's code to identify the looping mechanism and its implications on gas usage.
Gas Estimation Tools: foundry gas.
Limit Batch Size: Restrict the number of withdrawals processed in a single transaction to prevent excessive gas usage. For example, set a maximum batch size:
Optimize Withdraw Function: Ensure that the withdraw
function is as gas-efficient as possible by minimizing state changes and external calls:
Alternative Solutions: Explore off-chain computation and batching techniques where feasible to reduce on-chain operations and gas costs.
https://docs.codehawks.com/hawks-auditors/how-to-determine-a-finding-validity
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.