Open code423n4 opened 2 years ago
G001 - Don't Initialize Variables with Default Value Uninitialized variables are assigned with the types default value.
Explicitly initializing a variable with it's default value costs unnecesary gas. Puttyv2.sol L#556
[Puttyv2.sol L#594]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20assets.length%3B%20i%2B%2B)%20%7B,-address%20token%20%3D
[Puttyv2.sol L#611]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=from)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20assets.length%3B%20i%2B%2B)%20%7B,-ERC721(assets%5Bi%5D.token
[Puttyv2.sol L#627]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20floorTokens.length%3B%20i%2B%2B)%20%7B,-ERC721(floorTokens%5Bi%5D).safeTransferFrom(from
[Puttyv2.sol L#637]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20assets.length%3B%20i%2B%2B)%20%7B,-ERC20(assets%5Bi
[Puttyv2.sol L#647]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=assets)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20assets.length%3B%20i%2B%2B)%20%7B,-ERC721(assets%5Bi%5D.token
[Puttyv2.sol L#658]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=floorTokenIds)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20floorTokens.length%3B%20i%2B%2B)%20%7B,-ERC721(floorTokens%5Bi%5D).
[Puttyv2.sol L#670]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20whitelist.length%3B%20i%2B%2B)%20%7B
[Puttyv2.sol L#728]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=function%20encodeERC20Assets(,i%2B%2B)%20%7B
[Puttyv2.sol L#741]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=function%20encodeERC721Assets(,i%2B%2B)%20%7B
G002 - Cache Array Length Outside of Loop Caching the array length outside a loop saves reading it on each iteration, as long as the array's length is not changed during the loop. Puttyv2.sol L#556
Puttyv2.sol L#670
[Puttyv2.sol L#742]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=function%20encodeERC721Assets(,i%2B%2B)%20%7B
G03 - Unnecessary checked arithmetic in for loop Using Solidity's unchecked block saves the overflow checks.
The for loops in G-02 can use unchecked.
G-04 ++I COSTS LESS GAS THAN I++, ESPECIALLY WHEN IT’S USED IN FOR-LOOPS (--I/I-- TOO) The for loops link in G-02 can use ++i
++I
I++
--I
I--
++i
G001 - Don't Initialize Variables with Default Value Uninitialized variables are assigned with the types default value.
Explicitly initializing a variable with it's default value costs unnecesary gas. Puttyv2.sol L#556
[Puttyv2.sol L#594]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20assets.length%3B%20i%2B%2B)%20%7B,-address%20token%20%3D
[Puttyv2.sol L#611]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=from)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20assets.length%3B%20i%2B%2B)%20%7B,-ERC721(assets%5Bi%5D.token
[Puttyv2.sol L#627]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20floorTokens.length%3B%20i%2B%2B)%20%7B,-ERC721(floorTokens%5Bi%5D).safeTransferFrom(from
[Puttyv2.sol L#637]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20assets.length%3B%20i%2B%2B)%20%7B,-ERC20(assets%5Bi
[Puttyv2.sol L#647]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=assets)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20assets.length%3B%20i%2B%2B)%20%7B,-ERC721(assets%5Bi%5D.token
[Puttyv2.sol L#658]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=floorTokenIds)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20floorTokens.length%3B%20i%2B%2B)%20%7B,-ERC721(floorTokens%5Bi%5D).
[Puttyv2.sol L#670]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20whitelist.length%3B%20i%2B%2B)%20%7B
[Puttyv2.sol L#728]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=function%20encodeERC20Assets(,i%2B%2B)%20%7B
[Puttyv2.sol L#741]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=function%20encodeERC721Assets(,i%2B%2B)%20%7B
G002 - Cache Array Length Outside of Loop Caching the array length outside a loop saves reading it on each iteration, as long as the array's length is not changed during the loop. Puttyv2.sol L#556
[Puttyv2.sol L#594]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20assets.length%3B%20i%2B%2B)%20%7B,-address%20token%20%3D
[Puttyv2.sol L#611]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=from)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20assets.length%3B%20i%2B%2B)%20%7B,-ERC721(assets%5Bi%5D.token
[Puttyv2.sol L#627]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20floorTokens.length%3B%20i%2B%2B)%20%7B,-ERC721(floorTokens%5Bi%5D).safeTransferFrom(from
[Puttyv2.sol L#637]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20assets.length%3B%20i%2B%2B)%20%7B,-ERC20(assets%5Bi
[Puttyv2.sol L#647]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=assets)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20assets.length%3B%20i%2B%2B)%20%7B,-ERC721(assets%5Bi%5D.token
[Puttyv2.sol L#658]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=floorTokenIds)%20internal%20%7B-,for%20(uint256%20i%20%3D%200%3B%20i%20%3C%20floorTokens.length%3B%20i%2B%2B)%20%7B,-ERC721(floorTokens%5Bi%5D).
Puttyv2.sol L#670
[Puttyv2.sol L#728]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=function%20encodeERC20Assets(,i%2B%2B)%20%7B
[Puttyv2.sol L#742]https://github.com/code-423n4/2022-06-putty/blob/main/contracts/src/PuttyV2.sol#:~:text=function%20encodeERC721Assets(,i%2B%2B)%20%7B
G03 - Unnecessary checked arithmetic in for loop Using Solidity's unchecked block saves the overflow checks.
The for loops in G-02 can use unchecked.
G-04
++I
COSTS LESS GAS THANI++
, ESPECIALLY WHEN IT’S USED IN FOR-LOOPS (--I
/I--
TOO) The for loops link in G-02 can use++i