Description: The SpookySwap::treatList
mapping uses the treat name as a key to store relevant Treat
structs. Currently, there is no safeguard to prevent the owner from adding a new treat with a name that already exists in the mapping. As a result, adding a new treat with an existing name will overwrite the previous treat data with the new values, in addition to creating a new treat.
Impact: The original treat entry is unintentionally updated with the new treat’s values, leading to unintended data overwriting and loss of the original treat’s details.
Proof of Concept:
The owner adds a treat named PumpkinBurst
with a cost of 1 ether
and metadata URI PumpkinBurstValley.com
.
The owner then accidentally adds another treat with the same name, PumpkinBurst
.
For the second treat, a cost of 3 ether
and metadata URI PumpkinCity.com
are used.
This overwrites the original treat's data, resulting in both treats reflecting the latest cost and metadata URI values.
Proof of Code
Create a directory for the test file at the root level of the repository as test/unit
. Create a new file named TrickOrTreatTest.t.sol
inside this directory and paste the following code into this file.
Recommended Mitigation:
Introduce a new mapping treatExists
in the SpookySwap
contract to track names already used for treats. This mapping will prevent adding a treat with an existing name.
Then, modify the SpookySwap::addTreat
function to check treatExists
to verify if a treat with the specified name already exists, and update treatExists
when a new treat with a unique name is added.
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.