Missing price check for treat at constructor could result the treat price couldn't be reset later on by owner and function trickOrTreat
is not callable by user if the treat price was set as zero during contract deployment
The constructor of the contract takes in an array of Treat
and loop through each item in the array with addTreat
function. However, there is no check to ensure that the treats[i].cost
is > 0
In function setTreatCost
where owner can reset the price of the treat, there's a condition check of require(treatList[_treatName].cost > 0, "Treat must cost something.");
Similarly, in function trickOrTreat
which the user calls to participate and buy the NFT, there's also a check require(treat.cost > 0, "Treat cost not set.")
If any of the treat item was deployed with cost 0 at constructor stage, the owner can't reset the price anymore for that treat via setTreatCost
and users can't buy that particular treat viatrickOrTreat
due to the condition check of cost > 0
causing that particular treat inaccessible by both owner and user.
Proof of Concept:
Step 1: Add the following test file test\TrickOrTreatTest.t.sol
:
Step 2: Run the test forge test --match-test test_audit_treatWithZeroCostIssueAtDeployment
The test passed with the expected revert indicating that owner can't reset the price of the treat and user can't buy that treat.
Owner can't reset the price of the treat and users can't buy the treat when the treat is set with zero cost during contract deployment
Manual review with test
Implement the cost price condition check for the treat at constructor stage :
Rerun of the same test forge test --match-test test_audit_treatWithZeroCostIssueAtDeployment
will fail this round indicating that the implementation recommended has effectively blocked treat item that has its cost set to zero.
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.