The value tokenList.length is read from memory and therefore requires
a mload(...) (6 gas for push memory_offset + mload). On the other
hand, this value is already available in the stack as length and could
just be dup-ed (3 gas). Saves 3 gas for each loop iteration of the
interior loop.
Handle
hrkrshnn
Vulnerability details
Replace
tokenList.length
by existing variablelength
Context: https://github.com/code-423n4/2021-09-defiProtocol/blob/main/contracts/contracts/Basket.sol#L64
The value
tokenList.length
is read from memory and therefore requires amload(...)
(6 gas forpush memory_offset
+mload
). On the other hand, this value is already available in the stack aslength
and could just bedup-ed
(3 gas). Saves 3 gas for each loop iteration of the interior loop.