The addTreat
function does not check for duplicate names, allowing treats with the same name, cost, and metadata URI to be added multiple times. This leads to multiple identical entries in treatNames
and redundant storage in treatList
.
The following test attempts to see if when adding a new treat twice (The same addTreat line was added in the setUp function), we would expect that the length of the treatNames array would still be 1, since we are sending the same value, but due to not having a duplicate check, the length returned is 2.
Below is the output of the console.log:
This vulnerability allows for duplicate treat entries, which could lead to a bloated treatNames
array and potential confusion around unique treat retrieval.
Duplicate entries also increase storage usage and gas costs in transactions related to treat retrieval and minting, particularly for repeated retrieval or iteration over treats.
Although the function is restricted to onlyOwner
, duplicate entries due to error or oversight could degrade contract performance and user experience.
Manual review and unit tests with Foundry.
Add a uniqueness check in addTreat
to verify that no treat with the specified name already exists in treatList
before adding a new treat. This could be implemented with a simple require statement:
The function `addTreat` is called by the owner. The owner is trusted. There will be no duplicates.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.