Flow

Sablier
FoundryDeFi
20,000 USDC
View results
Submission Details
Severity: low
Invalid

Use `unchecked` in for loops where the loop index cannot overflow

Summary

he Batch contract at abstracts/Batch.sol:18
uses a delegatecall operation in a loop within the batch function. delegatecall is a gas-intensive operation, and optimizations are recommended. Additionally, using unchecked arithmetic in the loop’s indexing can prevent unnecessary gas usage by bypassing Solidity’s default overflow checks on uint256.

Vulnerability Details

This is a Low & Informational level finding. The looping over calls and use of delegatecall for each invocation incurs a high gas cost, and the contract can reduce this cost by using unchecked blocks for the loop index. Solidity’s default safety checks on uint256 increments, while protective, are unnecessary here, as the index will not overflow given the constraints of the function.

Impact

Implementing these gas-saving measures can reduce the contract’s gas consumption, which becomes particularly significant when batch is used with a large number of calls. This optimization does not alter functionality or security but enhances the contract’s efficiency.

Tools Used

Manual Review

Recommendations

Add Unchecked Arithmetic: Wrap the loop’s incrementing line (i++) within an unchecked block. Since i will not exceed count, using unchecked will save on gas costs by avoiding redundant overflow checks.

By implementing unchecked on the loop index increment, the contract can achieve improved gas efficiency without compromising on correctness or security.

for (uint256 i = 0; i < count; ) {
(bool success, bytes memory result) = address(this).delegatecall(calls[i]);
if (!success) {
revert Errors.BatchError(result);
}
unchecked {
++i;
}
}
Updates

Lead Judging Commences

inallhonesty 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.