First Flight #12: Kitty Connect

First Flight #12: Kitty Connect
Beginner FriendlyFoundryNFTGameFi
100 EXP
View results
Submission Details
Severity: low
Invalid

Reading from storage in `KittyConnect::constructor` every iteration in the for-loop, which is gas inefficient.

Vulnerability Details

In KittyConnect::constructor, the function reads from storage in every iteration of the for-loop. Reading from storage is more expensive than reading from memory.

Impact

Leads to spending more gas than necessary.

Tools Used

Manual Review

Recommendations

Consider storing the length of the array in a local variable and using it in the for-loop. This will reduce the gas cost of the function.

constructor(
address[] memory initShops,
address router,
address link
) ERC721("KittyConnect", "KC") {
+ uint256 initialShopsArray = initShops.length;
+ for (uint256 i = 0; i < initialShopsArray; i++) {
- for (uint256 i = 0; i < initShops.length; i++) {
s_kittyShops.push(initShops[i]);
s_isKittyShop[initShops[i]] = true;
}
i_kittyConnectOwner = msg.sender;
i_kittyBridge = new KittyBridge(router, link, msg.sender);
}
Updates

Lead Judging Commences

inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.