Open code423n4 opened 2 years ago
1. Title: Initializing var with default value
Occurrences: https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/CNft.sol#L49 https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/CNft.sol#L97
By declaring var by not set its default value (0 for uint) can save gas cost Change to:
uint256 totalAmount;
2. Title: Using unchecked for i in a for() loop
i
Occurence: https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/CNft.sol#L50 https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/CNft.sol#L72 https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/CNft.sol#L122 https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/ERC1155Enumerable.sol#L51
Using unchecked for i can save execution gas fee:
for (uint256 i; i < length;) { if (!is1155) { require(amounts[i] == 1, "CNFT: Amounts must be all 1s for non-ERC1155s."); unchecked{++i;} }
3. Title: Using && is not effective
Occurrences: https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/CNft.sol#L66
Instead of using && which cost 15 execution gas fee per call. Using multiple require() is more effective RECOMMENDED MITIGATION STEP
require(checkSuccess, "Not the NFT owner"); require(nftOwner == msg.sender, "Not the NFT owner");
GAS
1. Title: Initializing var with default value
Occurrences: https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/CNft.sol#L49 https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/CNft.sol#L97
By declaring var by not set its default value (0 for uint) can save gas cost Change to:
2. Title: Using unchecked for
i
in a for() loopOccurence: https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/CNft.sol#L50 https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/CNft.sol#L72 https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/CNft.sol#L122 https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/ERC1155Enumerable.sol#L51
Using unchecked for
i
can save execution gas fee:3. Title: Using && is not effective
Occurrences: https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/CNft.sol#L66
Instead of using && which cost 15 execution gas fee per call. Using multiple require() is more effective RECOMMENDED MITIGATION STEP