Description: When adding a new treat using SpookySwap::addTreat
, there is no verification to ensure the cost is non-zero. If a treat is added with a cost of 0
, attempts to later update the cost via the SpookySwap::setTreatCost
function will fail due to the check require(treatList[_treatName].cost > 0, "Treat must cost something.");
. Since the treat was initialized with zero, this check will trigger a revert.
Additionally, when a user tries to claim this treat by calling SpookySwap::trickOrTreat
, it will also fail because of the require(treat.cost > 0, "Treat cost not set.");
check.
Impact: The owner will be unable to update the treat's cost in the future, rendering the treat useless while it continues to occupy storage. From the users' perspective, they will also be unable to claim this treat.
Proof of Concept:
The owner creates a new treat with a cost of 0 ether
.
The owner calls SpookySwap::setTreatCost
to update the cost to a value greater than 0
.
The SpookySwap::setTreatCost
function reverts with the error message: "Treat must cost something."
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: Two potential solutions exist to mitigate this issue.
First Solution:
Update the SpookySwap::setTreatCost
function to check for a cost of 0
as well.
Second Solution:
Update the SpookySwap::addTreat
function to prevent the creation of a new treat with a zero value.
The cost of the treat is set only by the owner (in the constructor, in addTreat and in setTreatCost). That means the cost of the treat will always be greater than zero.
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.