code-423n4/2021-11-nested-findings

.length in a loop

Closed this issue · 1 comments

Handle

pauliax

Vulnerability details

Impact

.length in a loop can be extracted into a variable and used where necessary to reduce the number of storage reads. Cache the length of the array and use this local variable when iterating over the storage array. This can be applied in functions findShareholder and _sendFees:

  for (uint256 i = 0; i < shareholders.length; i++)
  unit  shareholdersLength =  shareholders.length;
  for (uint256 i = 0; i < shareholdersLength; i++)

duplicated #7