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

0 stars 0 forks source link

Cache length of array outside for-loop #210

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

byterocket

Vulnerability details

Impact

Caching the array length outside a loop in a variable saves reading it on each iteration, as long as the array's length is not changed during the loop.

Therefore, the following loops could be refactored:

arbitrum-lpt-bridge:
    - L1/gateway/L1Migrator -> Line 472
    - L2/gateway/L2Migrator -> Line 197

Recommended Mitigation Steps

Use the following pattern for refactoring:

uint256 len = array.length;
for (uint256 i; i < len; i++) {
    // ...
}
yondonfu commented 2 years ago

Duplicate of https://github.com/code-423n4/2022-01-livepeer-findings/issues/77