In setTreatCost
function, owner can reset the cost price of a treat. There's a condition check on the cost in treatList[_treatName]
within the setTreatCost
function itself, however there's no similar check on the new cost entered as input parameter. This could potentially cause the final treat cost be zero if it is somehow accidentally entered by mistake and there's no way to reset back again the treat to the correct cost price after the first mistaken action.
Function setTreatCost
implement a cost check on treatList[_treatName]
, however there's no similar condition check on the new cost input parameter _cost
This could potentially have the final treatList[_treatName].cost
be set to zero if it is entered unintentionally by mistake. Once this is set, there's no way for the owner to reset back the correct cost price as it will be reverted by require(treatList[_treatName].cost > 0, "Treat must cost something.");
and further causes the trickOrTreat
function to revert when user makes the call to that function on the affected treatName
.
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_lackOfSecondLevelCostCheckAtSetTreatCost
The test passed with the expected reverts and assertion indicating that owner can't reset the price of the treat once mistake of setting the cost to zero is made and user thenafter can't buy the affected NFT.
Owner can't reset the price of the treat once mistake of setting the cost to zero is made and user thenafter can't buy the affected NFT.
Manual review with test
Implement similar cost condition check on the input parameter as described below:
Rerun of the same test forge test --match-test test_audit_lackOfSecondLevelCostCheckAtSetTreatCost
will fail this round indicating that the implementation recommended has effectively blocked the wrong doing action of setting the cost of treat 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.