Summary
Everyone is NICE
by default
Vulnerability Details
Enums are user-defined data types that restrict the variable to have only one of the predefined values. Internally, enums are treated as numbers. Solidity automatically converts the enums to unsigned integers.
Impact
Santa can't find all NAUGHTY
persons and that's okay, but he should not consider all of us NICE
by default. Because of love and faith in us, NAUGHTY
persons can mint a SantasList
even if they are not checked twice.
Test:
function testEveryoneIsNice() public {
address naughtyPerson = makeAddr('naughtyPerson');
vm.warp(santasList.CHRISTMAS_2023_BLOCK_TIME() + 1);
vm.prank(naughtyPerson);
santasList.collectPresent();
assertEq(santasList.balanceOf(naughtyPerson), 1);
}
Traces:
[PASS] testEveryoneIsNice() (gas: 86266)
Traces:
[86266] NaughtyElf::testEveryoneIsNice()
├─ [0] VM::addr(59473258362455770892207176146854147308564458821009993074427965102032172865775 [5.947e76]) [staticcall]
│ └─ ← naughtyPerson: [0xF8C3Db5a31B41750A68A0C0B1847d38D0f3f6cFD]
├─ [0] VM::label(naughtyPerson: [0xF8C3Db5a31B41750A68A0C0B1847d38D0f3f6cFD], "naughtyPerson")
│ └─ ← ()
├─ [283] SantasList::CHRISTMAS_2023_BLOCK_TIME() [staticcall]
│ └─ ← 1703480381 [1.703e9]
├─ [0] VM::warp(1703480382 [1.703e9])
│ └─ ← ()
├─ [0] VM::prank(naughtyPerson: [0xF8C3Db5a31B41750A68A0C0B1847d38D0f3f6cFD])
│ └─ ← ()
├─ [74250] SantasList::collectPresent()
│ ├─ emit Transfer(from: 0x0000000000000000000000000000000000000000, to: naughtyPerson: [0xF8C3Db5a31B41750A68A0C0B1847d38D0f3f6cFD], tokenId: 0)
│ └─ ← ()
├─ [678] SantasList::balanceOf(naughtyPerson: [0xF8C3Db5a31B41750A68A0C0B1847d38D0f3f6cFD]) [staticcall]
│ └─ ← 1
└─ ← ()
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.89ms
Tools Used
Manual
Recommendations
Reorder Status
enum and place NOT_CHECKED_TWICE
on first position
enum Status {
NOT_CHECKED_TWICE,
NICE,
EXTRA_NICE,
NAUGHTY
}