code-423n4 / 2022-06-nested-findings

0 stars 1 forks source link

Gas Optimizations #57

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

G-1 Don't Initialize Variables with Default Values Unititialized variables are assigned with the type default. When you initializing a variable with its default value cost unnecasary gas. OperatorResolver.sol L#40 OperatorResolver.sol L#60 OperatorResolver.sol L#75 NestedFactory.sol L#124 NestedFactory.sol L#136 [NestedFactory.sol L#196]https://github.com/code-423n4/2022-06-nested/blob/main/contracts/NestedFactory.sol#:~:text=_msgSender()%2C%20_originalTokenId)%3B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20batchedOrdersLength%3B%20i%2B%2B)%20%7B,-(uint256%20fees NestedFactory.sol L#256 [NestedFactory.sol L#315]https://github.com/code-423n4/2022-06-nested/blob/main/contracts/NestedFactory.sol#:~:text=NF%3A%20RESERVE_MISMATCH%22)%3B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20batchedOrdersLength%3B%20i%2B%2B)%20%7B,-(uint256%20fees [NestedFactory.sol L#333]https://github.com/code-423n4/2022-06-nested/blob/main/contracts/NestedFactory.sol#:~:text=NF%3A%20RESERVE_MISMATCH%22)%3B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20batchedOrdersLength%3B%20i%2B%2B)%20%7B,-(uint256%20feesAmount

G-2 Unnecessary checked arithmetic in for loops Usually there is no risk that the loop counter can overflow. Using Solidity unchecked block saves the overflow checks. By using unchecked { ++i } OperatorResolver.sol L#40 OperatorResolver.sol L#75 [NestedFactory.sol L#196]https://github.com/code-423n4/2022-06-nested/blob/main/contracts/NestedFactory.sol#:~:text=_msgSender()%2C%20_originalTokenId)%3B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20batchedOrdersLength%3B%20i%2B%2B)%20%7B,-(uint256%20fees NestedFactory.sol L#256

Yashiru commented 2 years ago

G-1 Don't Initialize Variables with Default Values (Duplicated)

Duplicated of #2 at For loop optimizaion

G-2 Unnecessary checked arithmetic in for loops (Duplicated)

Duplicated of #2 at For loop optimizaion