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

`Soulmate::getDivorced` require statement is missing, working even for non soulmates

[M-2] Soulmate::getDivorced require statement is missing, working even for non soulmates

Description: The getDivorced function lacks proper access control and a require statement, allowing any account to call it without restrictions.

Impact: The absence of access control and proper validation in the getDivorced function could lead to unauthorized parties initiating divorce proceedings, resulting in undesired outcomes and inconsistency in the relationship status. This could potentially disrupt the integrity of the relationship system and cause confusion among users.

Proof of Concept:

Past this code in SoulmateTest.t.sol

PoC
function testGetDivorced() public {
console.log("Divorced Status Before: ", soulmateContract.isDivorced());
assertEq(soulmateContract.isDivorced(), false);
// Assume an attacker calls the getDivorced function without authorization
soulmateContract.getDivorced();
console.log("Divorced Status After: ", soulmateContract.isDivorced());
assertEq(soulmateContract.isDivorced(), true);
}
Logs:
Divorced Status Before: false
Divorced Status After: true

Recommended Mitigation:

  1. Access Control: Implement access control mechanisms such as modifiers or access control lists (ACLs) to restrict the execution of the getDivorced function to authorized parties only.

  2. Validation: Add validation checks to ensure that only valid soulmates can initiate divorce proceedings. This could involve verifying that the caller is indeed in a valid relationship with the specified soulmate before allowing the divorce to proceed.

function getDivorced() public {
address soulmate2 = soulmateOf[msg.sender];
// Ensure that the caller has a valid soulmate
+ require(soulmate2 != address(0), "You do not have a soulmate.");
// Add access control to restrict function execution
+ require(msg.sender == soulmateContract.ownerOf(ownerToId[msg.sender]), "Unauthorized");
divorced[msg.sender] = true;
divorced[soulmateOf[msg.sender]] = 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

Support

FAQs

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