The SDLPoolSecondary
contract _mintQueuedNewLocks
function has an optimization opportunity. The current implementation uses two loops to process and clean up an array of new locks. By introducing a minor adjustment, the need for the second loop is eliminated, resulting in improved efficiency and gas cost savings.
The original code contains a while
loop that iterates through an array of new locks. Within the loop, certain elements are skipped using a break
statement based on a condition (newLockPointer.updateBatchIndex > finalizedBatchIndex
). The skipped elements were previously handled in a second loop, copying the remaining elements to the beginning of the array. Which can introduce many gas issues and redundant code.
The impact of this issue lies in the efficiency and gas cost of the _mintQueuedNewLocks
function. The redundant second loop for cleanup introduces unnecessary computational steps and increases gas consumption.
Manual review.
The proposed optimization involves moving the ++i
increment operation above the if condition and adding continue
instead of break
. This modification eliminates the need for the second loop, streamlining the code execution. The revised code snippet is as follows:
This adjustment enhances the efficiency of the function and reduces gas consumption by eliminating the need for a separate loop to clean up the array.
NOTE: The same issue is present in _executeQueuedLockUpdates
function also, and the recommendation can be applied to this function.
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.