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

1 stars 1 forks source link

.length in a loop #212

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

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++)
adrien-supizet commented 2 years ago

duplicated #7