First Flight #12: Kitty Connect

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

`addShop` function can add the same shop address multiple times which create a duplicate entry in the `s_kittyShops` array

Summary

  • addShop function can add the same shop address multiple times which create a duplicate entry in the s_kittyShops array ans also we can not remove the shop address from the s_kittyShops array if it is added multiple times.

Vulnerability Details

  • addShop function can add the same shop address multiple times which create a duplicate entry in the s_kittyShops array ans also we can not remove the shop address from the s_kittyShops array if it is added multiple times.

  • So, we can put a check in the addShop function to check if the shop address is already added or not. If it is already added then we can revert the transaction.

function addShop(address shopAddress) external onlyKittyConnectOwner {
@>
s_isKittyShop[shopAddress] = true;
s_kittyShops.push(shopAddress);
emit ShopPartnerAdded(shopAddress);
}

POC

  • Paste this POC code in the KittyTest.t.sol.

function test_CanAddNewPartnerShopRepetitively() public {
address partnerC = makeAddr("partnerC");
vm.startPrank(kittyConnectOwner);
kittyConnect.addShop(partnerC);
kittyConnect.addShop(partnerC);
vm.stopPrank();
assertEq(kittyConnect.getKittyShopAtIdx(2), partnerC);
assertEq(kittyConnect.getKittyShopAtIdx(3), partnerC);
}
  • Run this test by this command.

forge test --mt test_CanAddNewPartnerShopRepetitively -vvvv

Impact

  • leads to the duplicate entry in the s_kittyShops array.

  • we can not remove the shop address from the s_kittyShops array if it is added multiple times.

Tools Used

  • Manual review

Recommendations

  • Here, we add a check in addShop funtion to check the shop address is already added or not. If it is already added then we can revert the transaction.

function addShop(address shopAddress) external onlyKittyConnectOwner {
+ require(!s_isKittyShop[shopAddress], "KittyConnect__ShopAlreadyAdded");
s_isKittyShop[shopAddress] = true;
s_kittyShops.push(shopAddress);
emit ShopPartnerAdded(shopAddress);
}
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.