The collectPresent
function in the provided code introduces a vulnerability in the smart contract Which allows users to be able to collect presents more than once.
Any user that has been checked twice and eligible to collect present can collect the present and transfer to another address then collect again because of the check on line 151.
The vulnerability exposes a flaw in the contract's conditional checks, enabling an attacker to undermine the intended security and functionality of the collectPresent function.
in the test file add this line of code as a state variable:
address reciever = makeAddr("reciever");
then add this block of code to the file:
after that run this command to confirm the exploit
forge t --mt testAttackCollectPresent
Foundry & Manual Review
A mapping could be implemented to mitigate it, say using a mapping of address => bool
and calling it hasClaimed
so if a user has passed all the checks in the function has claimed can be set to true then a require statement would be needed to check if the user has claimed before or not.
Relying on balanceOf > 0 in collectPresent() allows the msg.sender to send their present to another address and then collect again.
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.