code-423n4 / 2021-12-amun-findings

0 stars 0 forks source link

Recalculation of the variables inside the loop #279

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

pauliax

Vulnerability details

Impact

_amount.add(feeAmount) is re-evaluated again and again inside the loop:

  for (uint256 i; i < bs.tokens.length; i++) {
     ...
      uint256 tokenAmount =
          balance(address(token)).mul(_amount.add(feeAmount)).div(
              totalSupply
          );
     ...
  }

These values do not change so consider extracting outside the loop to reduce gas costs.

0xleastwood commented 2 years ago

Duplicate of #205