code-423n4 / 2021-10-slingshot-findings

0 stars 0 forks source link

Cache length of array to avoid reading it multiple times #34

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

0x0x0x

Vulnerability details

Impact

Length is read multiple times. The length can be saved to a variable to avoid reading it repeatedly and waste gas.

Proof of Concept

Provide direct links to all referenced code in GitHub. Add screenshots, logs, or any other relevant proof that illustrates the concept.

Occurences

''' contracts/Executioner.sol: for(uint256 i = 0; i < trades.length; i++) { contracts/ModuleRegistry.sol: for (uint256 i = 0; i < _moduleAddresses.length; i++) { contracts/ModuleRegistry.sol: for (uint256 i = 0; i < _moduleAddresses.length; i++) { contracts/Slingshot.sol: for(uint256 i = 0; i < trades.length; i++) { '''

Tools Used

Grep

Recommended Mitigation Steps

Cache .length to and int before going into loop.

tommyz7 commented 2 years ago

Duplicate of #63