Summary
ChristmasDinner::changeParticipationStatus() allows users to become a participant before the deadline without depositing any tokens or ether.
Vulnerability Details
Users who have not deposit before will always return false when you call participant[msg.sender]. Hence, the function ChristmasDinner::changeParticipationStatus() allows any users to change their status to true before deadline.
function changeParticipationStatus() external {
if(participant[msg.sender]) {
participant[msg.sender] = false;
} else if(!participant[msg.sender] && block.timestamp <= deadline) {
participant[msg.sender] = true;
} else {
revert BeyondDeadline();
}
emit ChangedParticipation(msg.sender, participant[msg.sender]);
}
Impact
function testParticipateByChangingStatus() public {
vm.startPrank(user1);
cd.changeParticipationStatus();
assertEq(cd.getParticipationStatus(user1), true, "User1 is not participant");
}
Results
[PASS] testParticipateByChangingStatus() (gas: 39020)
Traces:
[39020] CDTest::testParticipateByChangingStatus()
├─ [0] VM::startPrank(user1: [0x29E3b139f4393aDda86303fcdAa35F60Bb7092bF])
│ └─ ← [Return]
├─ [26604] ChristmasDinner::changeParticipationStatus()
│ ├─ emit ChangedParticipation(: user1: [0x29E3b139f4393aDda86303fcdAa35F60Bb7092bF], : true)
│ └─ ← [Stop]
├─ [638] ChristmasDinner::getParticipationStatus(user1: [0x29E3b139f4393aDda86303fcdAa35F60Bb7092bF]) [staticcall]
│ └─ ← [Return] true
├─ [0] VM::assertEq(true, true, "User1 is not participant") [staticcall]
│ └─ ← [Return]
└─ ← [Stop]
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 3.19s (862.87µs CPU time)
Tools Used
Foundry
Recommendations
Add a mapping to track who are the users that have deposit before. Then check if the user exist before changing participant status.