This audit focuses on the _sortIndexesDescending
function in the FundFlowController
contract, which uses the Bubble Sort algorithm to sort an array. The implementation lacks a swapped flag, an essential feature that allows the algorithm to terminate early when the array is already sorted. This results in excessive and unnecessary gas consumption.
Missing Swapped Flag Leading to Unnecessary Gas Consumption:
The Bubble Sort implementation does not include a swapped flag, which would detect if no swaps occurred in a pass through the array. Without this flag, the algorithm continues iterating even when the array is sorted, causing unnecessary gas consumption due to redundant operations, particularly for already sorted or nearly sorted arrays.
Increased Gas Costs: The absence of a swapped flag leads to wasteful iterations, significantly increasing gas costs for sorting operations.
Decreased Performance: For arrays that are already sorted, the algorithm runs its full course without an early exit, making the contract inefficient in terms of gas consumption and execution time.
Implement a Swapped Flag for Early Termination:
Introduce a swapped flag to detect when the array is already sorted and stop further iterations. This will reduce unnecessary operations and lower gas costs.
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.