Closed stalker474 closed 4 months ago
The DepositsLinkedList::sumExpiredDeposits function will iterate through all locks inefficiently as the locks are introduced in an ascending manner based on the DepositsLinkedList::insertEnd integration by the ElasticVault::makeDeposit function.
DepositsLinkedList::sumExpiredDeposits
DepositsLinkedList::insertEnd
ElasticVault::makeDeposit
function sumExpiredDeposits(List storage list, uint256 lock_duration) internal view returns (uint256 sum) { uint current = list.head; sum = 0; while (current != NULL) { if (lock_duration == 0 || ((block.timestamp - list.nodes[current].deposit.timestamp) > lock_duration)) { sum = sum.add(list.nodes[current].deposit.amount); } current = list.nodes[current].next; } return sum; }
We advise the loop to break if an unexpired deposit is identified, significantly optimizing the gas cost of the summation function.
break
DLL-02C: Potential Optimization of Search
Description:
The
DepositsLinkedList::sumExpiredDeposits
function will iterate through all locks inefficiently as the locks are introduced in an ascending manner based on theDepositsLinkedList::insertEnd
integration by theElasticVault::makeDeposit
function.Example:
Recommendation:
We advise the loop to
break
if an unexpired deposit is identified, significantly optimizing the gas cost of the summation function.