Open code423n4 opened 2 years ago
The require statements could be put at the beginning part of a block of statements if it doesn’t affect the logic to save gas. a. require(_orders.length != 0, "NF: INVALID_ORDERS");
Initializing i to 0 inside a for loop is redundant. As its initialized to 0 by default. Also i++ or ++I in the for loops can be put inside an unchecked block to save gas.
a. for (uint256 i = 0; i < operatorsCache.length; i++) b. for (uint256 i = 0; i < operatorsLength; i++) c. for (uint256 i = 0; i < batchedOrdersLength; i++) d. for (uint256 i = 0; i < tokensLength; i++) e. for (uint256 i = 0; i < batchedOrdersLength; i++) f. for (uint256 i = 0; i < batchedOrdersLength; i++) g. for (uint256 i = 0; i < batchLength; i++) h. for (uint256 i = 0; i < batchLength; i++) i. for (uint256 i = 0; i < _batchedOrders.length; i++) j. for (uint256 i = 0; i < namesLength; i++) k. for (uint256 i = 0; i < names.length; i++) l. for (uint256 i = 0; i < destinations.length; i++) m. for (uint256 i = 0; i < requiredOperators.length; i++) n. for (uint256 i = 0; i < requiredOperators.length; i++) o. for (uint256 i = 0; i < targets.length; ++i) p. for (uint256 i = 0; i < targets.length; ++i)
Unless it was introduced for readability saving memory to memory is redundant. address token = tokens[i];
These arithmetic operations can be unchecked. a. uint256 halfInvestment = investmentA / 2; b. uint256 halfInvestment = investmentA / 2;
This line could be pre-computed and defined as a constant to save gas. a. bytes4(keccak256(bytes("remove_liquidity_one_coin(uint256,int128,uint256)"))) b. bytes4(keccak256(bytes("remove_liquidity_one_coin(uint256,uint256,uint256)")))
Gas optimization confirmed
Duplicated of #2 at For loop optimizaion
The require statements could be put at the beginning part of a block of statements if it doesn’t affect the logic to save gas. a. require(_orders.length != 0, "NF: INVALID_ORDERS");
Initializing i to 0 inside a for loop is redundant. As its initialized to 0 by default. Also i++ or ++I in the for loops can be put inside an unchecked block to save gas.
a. for (uint256 i = 0; i < operatorsCache.length; i++) b. for (uint256 i = 0; i < operatorsLength; i++) c. for (uint256 i = 0; i < batchedOrdersLength; i++) d. for (uint256 i = 0; i < tokensLength; i++) e. for (uint256 i = 0; i < batchedOrdersLength; i++) f. for (uint256 i = 0; i < batchedOrdersLength; i++) g. for (uint256 i = 0; i < batchLength; i++) h. for (uint256 i = 0; i < batchLength; i++) i. for (uint256 i = 0; i < _batchedOrders.length; i++) j. for (uint256 i = 0; i < namesLength; i++) k. for (uint256 i = 0; i < names.length; i++) l. for (uint256 i = 0; i < destinations.length; i++) m. for (uint256 i = 0; i < requiredOperators.length; i++) n. for (uint256 i = 0; i < requiredOperators.length; i++) o. for (uint256 i = 0; i < targets.length; ++i) p. for (uint256 i = 0; i < targets.length; ++i)
Unless it was introduced for readability saving memory to memory is redundant. address token = tokens[i];
These arithmetic operations can be unchecked. a. uint256 halfInvestment = investmentA / 2; b. uint256 halfInvestment = investmentA / 2;
This line could be pre-computed and defined as a constant to save gas. a. bytes4(keccak256(bytes("remove_liquidity_one_coin(uint256,int128,uint256)"))) b. bytes4(keccak256(bytes("remove_liquidity_one_coin(uint256,uint256,uint256)")))