Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: low
Invalid

Soulmate.sol::totalSouls() When only one person mints an NFT, the totalSouls count is incorrect

Summary

Soulmate.sol::totalSouls() When only one person mints an NFT, the totalSouls count is incorrect

Vulnerability Details

Add this test to SoulmateTest.t.sol and run forge test --match-test test_totalSouls -vvvv the issue

function test_totalSouls() public {
vm.prank(soulmate1);
soulmateContract.mintSoulmateToken();
uint256 totalSouls = soulmateContract.totalSouls();
assertEq(totalSouls, 0);
}

The output confirms that when only one person mints an NFT, the souls count is 0 instead of 1

Running 1 test for test/unit/SoulmateTest.t.sol:SoulmateTest
[PASS] test_totalSouls() (gas: 44223)
Traces:
[44223] SoulmateTest::test_totalSouls()
├─ [0] VM::prank(soulmate1: [0x65629adcc2F9C857Aeb285100Cc00Fb41E78DC2f])
│ └─ ← ()
├─ [33015] Soulmate::mintSoulmateToken()
│ ├─ emit SoulmateIsWaiting(soulmate: soulmate1: [0x65629adcc2F9C857Aeb285100Cc00Fb41E78DC2f])
│ └─ ← 0
├─ [454] Soulmate::totalSouls() [staticcall]
│ └─ ← 0
└─ ← ()

Impact

When only one person mints, one soul is disregarded.

Tools Used

Manual review

Recommendations

Add conditional checks in the totalSouls() function,Even if nextID is 0, one soul can still be counted correctly

function totalSouls() external view returns (uint256) {
+ if(nextID == 0 && idToOwners[0][0] != address(0)){
+ return 1;
+ }
return nextID * 2;
}
Updates

Lead Judging Commences

0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Other

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.