DatingDapp

First Flight #33
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Severity: low
Invalid

[I-2] Duplicated profile deletion code increases maintenance burden (Code Duplication + Risk of Inconsistent Updates)

Description: In SoulboundProfileNFT.sol, the same profile deletion logic is duplicated in two different places. This includes burning the token, cleaning up mappings, and emitting events.

Duplicated code found in:

function burnProfile() external {
// ... checks ...
_burn(tokenId);
delete profileToToken[msg.sender];
delete _profiles[tokenId];
emit ProfileBurned(msg.sender, tokenId);
}
function blockProfile(address blockAddress) external onlyOwner {
// ... checks ...
_burn(tokenId);
delete profileToToken[blockAddress];
delete _profiles[tokenId];
emit ProfileBurned(blockAddress, tokenId);
}

Impact:

  • Code duplication increases maintenance burden

  • Changes need to be made in multiple places

  • Increased risk of inconsistencies if one instance is updated but not the other

  • Larger contract size due to duplicate code

Recommended Mitigation: Create a private function to handle profile deletion:

function _deleteUserProfile(address user, uint256 tokenId) private {
_burn(tokenId);
delete profileToToken[user];
delete _profiles[tokenId];
emit ProfileBurned(user, tokenId);
}
function burnProfile() external {
uint256 tokenId = profileToToken[msg.sender];
require(tokenId != 0, "No profile found");
_deleteUserProfile(msg.sender, tokenId);
}
function blockProfile(address blockAddress) external onlyOwner {
uint256 tokenId = profileToToken[blockAddress];
require(tokenId != 0, "No profile found");
_deleteUserProfile(blockAddress, tokenId);
}

This refactoring:

  • Reduces code duplication

  • Makes maintenance easier

  • Ensures consistent profile deletion logic

  • Makes the code more modular and easier to test

Updates

Appeal created

n0kto Lead Judge 6 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational or Gas

Please read the CodeHawks documentation to know which submissions are valid. If you disagree, provide a coded PoC and explain the real likelyhood and the detailed impact on the mainnet without any supposition (if, it could, etc) to prove your point.

Support

FAQs

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