Open code423n4 opened 2 years ago
WatchPug
https://github.com/code-423n4/2021-12-amun/blob/98f6e2ff91f5fcebc0489f5871183566feaec307/contracts/basket/contracts/factories/PieFactoryContract.sol#L91
for (uint256 i = 0; i < _tokens.length; i++) { IERC20 token = IERC20(_tokens[i]); token.safeTransferFrom(msg.sender, address(pie), _amounts[i]); pie.addToken(_tokens[i]); }
tokens[i] at L91 is already cached in the local variable token at L89, reusing the result instead of doing the subscript operation again can save gas.
tokens[i]
token
Handle
WatchPug
Vulnerability details
https://github.com/code-423n4/2021-12-amun/blob/98f6e2ff91f5fcebc0489f5871183566feaec307/contracts/basket/contracts/factories/PieFactoryContract.sol#L91
tokens[i]
at L91 is already cached in the local variabletoken
at L89, reusing the result instead of doing the subscript operation again can save gas.