code-423n4 / 2022-01-sherlock-findings

0 stars 0 forks source link

Gas Optimization: cache array length #237

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

gzeon

Vulnerability details

Impact

https://github.com/code-423n4/2022-01-sherlock/blob/c763f10c4b5fe2127677d6c25b83adcf3bcec212/contracts/managers/SherlockClaimManager.sol#L232

    if (claimCallbacks.length == MAX_CALLBACKS) revert InvalidState();
    // Checks to see if this callback contract already exists
    for (uint256 i; i < claimCallbacks.length; i++) {
      if (claimCallbacks[i] == _callback) revert InvalidArgument();
    }

to

    uint _len = claimCallbacks.length;
    if (_len == MAX_CALLBACKS) revert InvalidState();
    // Checks to see if this callback contract already exists
    for (uint256 i; i < _len; i++) {
      if (claimCallbacks[i] == _callback) revert InvalidArgument();
    }
jack-the-pug commented 2 years ago

Dup #231