The proposed change implements an unchecked block for the loop counter increment in the `_splitRewards` function, optimizing gas usage. In Solidity versions 0.8.0 and above, automatic overflow and underflow checks are implemented by default, increasing gas costs for arithmetic operations. By using an unchecked block, we instruct the compiler to skip these checks for the loop counter increment. This optimization is considered safe because the number of iterations is bounded by `fees.length`, which is controlled by the contract owner and is extremely unlikely to approach the maximum value of uint256 (2^256 - 1). The unchecked block is applied only to the loop counter increment, not to any reward or fee calculations.
Original code:
Gas savings, while modest per iteration (approximately 3-5 gas), can accumulate in contracts that are called frequently or have loops that iterate multiple times. For example:\
If `fees.length = 10`, the total savings would be around 30-50 gas.\
If `fees.length = 100`, the total savings would be around 300-500 gas.
Remix IDE Desktop
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.