Open code423n4 opened 2 years ago
This will mostly be executed on small arrays. This gas saving is irrelevant to gas usage for any of the protocol functions. Also, compiler might be able to optimize out this, so I would not fix this, as in general code will be less readable for saving of 20 gas maximum ...
Handle
WatchPug
Vulnerability details
Reading array length at each iteration of the loop takes 6 gas (3 for mload and 3 to place memory_offset) in the stack.
Caching the array length in the stack saves around 3 gas per iteration.
Instances include:
https://github.com/code-423n4/2021-10-tempus/blob/63f7639aad08f2bba717830ed81e0649f7fc23ee/contracts/amm/VecMath.sol#L14-L16