A user can collect present multiple times.
SantasList::CollectPresent()
expects only users who have no SantaList ECR721 token to be able to collect presents.
A user can bypass this rule by transferring all their balance to another address before calling SantasList::CollectPresent()
.
Below are the steps to follow to get around the rule:
Collect present by calling SantasList::CollectPresent()
.
Transfer the SantasList
ERC721 token received previously to another address.
Then call SantasList::CollectPresent()
again and collect a new NFT.
The user can go through those steps as many times as the want.
Place the code for the following test function in test/unit/SantasListTest.t.sol
.
In the terminal, run the following command:
forge test --mt test_CantCollectPresent_MoreThanOnce
EXTRA_NICE
users can collect as many presents as they want.
Manual review, Foundry
Add a state variable that maps address to bool, in order to keep track of addresses that have already collected presents.
Move from balance check to collected check
. And update s_collected
before the return
instruction in if-else statements
Implement a Snapshot behavior to SantasList
.
Take a snapshot at the CHRISTMAS_2023_BLOCK_TIME
. Perform a check on balanceOfAt
(user's balance at the time the snapshot was taken, with the snapshotId) instead of a check on balanceOf
. Then record the snapshotId for this user at the end of the first SantasList::collectPresent()
run for this user.
Note that this solution can be expensive in terms of gas, as retrieving values from snapshots costs a lot of gas.
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.