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

Logical issue in `getDivorce` function, allows user to get divorce without having a soulmate

Summary

The Soulmate contains a potential vulnerability in the getDivorced function. Currently, any user, regardless of whether they have a soulmate or not, can call this function and trigger a divorce. This lack of access control could lead to unintended consequences and abuse. And logically it doesn't make sense that a user who don't have soulmate can get divorce.

Vulnerability Details

The getDivorced function does not include a check to ensure that the caller has a soulmate before allowing the divorce operation to proceed. As a result, any user can call this function, potentially leading to unauthorized divorces and disrupting the intended functionality of the protocol.

function getDivorced() public {
address soulmate2 = soulmateOf[msg.sender];
divorced[msg.sender] = true;
divorced[soulmateOf[msg.sender]] = true;
emit CoupleHasDivorced(msg.sender, soulmate2);
}

Impact

The lack of access control in the getDivorced function poses several risks:

Unauthorized Divorces: Any user can call the function, even if they do not have a soulmate. This could lead to unauthorized divorces, disrupting the intended relationship management.

Logical issue: It doesn't make any sense that user who don't have a soulmate can get a divorce.

POC

  • Run the below test and it will pass successfully. Even the soulmate1 has no soulmate, it can get divorce.

function testGetDivorcedIfUserDontHaveSoulmate() public {
vm.prank(soulmate1);
soulmateContract.mintSoulmateToken();
assertEq(soulmateContract.isDivorced(), false);
soulmateContract.getDivorced();
assertEq(soulmateContract.isDivorced(), true);
vm.prank(soulmate2);
console2.log(soulmateContract.isDivorced()); // false
soulmateContract.mintSoulmateToken();
}

Result:

Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.98ms
Ran 1 test suites: 1 tests passed, 0 failed, 0 skipped (1 total tests)

Recommendations

Access Control: Implement access control mechanisms in the getDivorced function to ensure that only users with a soulmate can initiate a divorce.

modifier onlySoulmate(address account) {
require(soulmateOf[account] != address(0), "Caller does not have a soulmate");
_;
}
function getDivorced() public onlySoulmate(msg.sender) {
address soulmate2 = soulmateOf[msg.sender];
divorced[msg.sender] = true;
divorced[soulmate2] = true;
emit CoupleHasDivorced(msg.sender, soulmate2);
}
Updates

Lead Judging Commences

0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
0xtheblackpanther Submitter
over 1 year ago
0xnevi Lead Judge
over 1 year ago
0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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