Trick or Treat

First Flight #27
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

Duplicate Treat Names Allowed in addTreat Function

Description

The addTreat function does not verify whether a treat with the same name already exists. This can lead to duplicate entries in the treatNames array if the owner attempts to add a treat with an existing name. Additionally, this would update the metadataURI of the treat for future tokens, creating potential inconsistencies in treat metadata.

Impact

Allowing duplicate treat names in treatNames could lead to data inconsistency, user confusion and gas-inefficiency, as it may appear that multiple treats with the same name are distinct, when they are not, they are actually the same treat.

Proof of Concept

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {Test} from "lib/forge-std/src/Test.sol";
import {SpookySwap} from "../src/TrickOrTreat.sol";
contract TrickOrTreat is Test {
SpookySwap spookySwap;
address owner;
function setUp() external {
owner = makeAddr("owner");
SpookySwap.Treat[] memory t = new SpookySwap.Treat[]();
t[0] = SpookySwap.Treat("test", 1, "testUri");
vm.prank(owner);
spookySwap = new SpookySwap(t);
}
function testAddDup() public {
vm.prank(owner);
spookySwap.addTreat("test", 5, "testUri23");
(string memory name, uint256 cost, string memory uri) = spookySwap.treatList("test");
assertEq(name, "test");
assertEq(cost, 5);
assertEq(uri, "testUri23");
assertEq(spookySwap.getTreats().length, 2);
}
}

Recommended Mitigation

Add a check to ensure that a treat with the specified _name does not already exist before adding it:

function addTreat(string memory _name, uint256 _rate, string memory _metadataURI) public onlyOwner {
+ require(treatList[_name].cost == 0, "Treat with this name already exists.");
treatList[_name] = Treat(_name, _rate, _metadataURI);
treatNames.push(_name);
emit TreatAdded(_name, _rate, _metadataURI);
}

This check ensures treats are unique by name and prevents unexpected updates to metadata.

Updates

Appeal created

bube Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

[invalid] Duplicate treats

The function `addTreat` is called by the owner. The owner is trusted. There will be no duplicates.

Support

FAQs

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