Canto Identity Subprotocols contest - alejandrocovrr's results

Subprotocols for Canto Identity Protocol.

General Information

Platform: Code4rena

Start Date: 17/03/2023

Pot Size: $36,500 USDC

Total HM: 10

Participants: 98

Period: 3 days

Judge: leastwood

Total Solo HM: 5

Id: 223

League: ETH

Canto Identity Subprotocols

Findings Distribution

Researcher Performance

Rank: 62/98

Findings: 1

Award: $22.77

QA:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

22.7749 USDC - $22.77

Labels

bug
grade-b
QA (Quality Assurance)
Q-07

External Links

Improve readibility and adding validation to increase code quality on burn function

On canto-namespace-protocol/src/Namespace.sol#L184 the burn function has the following structure:

function burn(uint256 _id) external { address nftOwner = ownerOf(_id); if (nftOwner != msg.sender && getApproved[_id] != msg.sender && !isApprovedForAll[nftOwner][msg.sender]) revert CallerNotAllowedToBurn(); string memory associatedName = tokenToName[_id]; delete tokenToName[_id]; delete nameToToken[associatedName]; _burn(_id); }

I'm suggesting the following code as a refactor for QA purposes:

function burn(uint256 _id) external { require(_id != 0, "Invalid ID"); address nftOwner = ownerOf(_id); require( nftOwner == msg.sender || getApproved(_id) == msg.sender || isApprovedForAll[nftOwner][msg.sender], "Caller not authorized to burn" ); string memory associatedName = tokenToName[_id]; require(bytes(associatedName).length > 0, "No name associated with token"); delete tokenToName[_id]; delete nameToToken[associatedName]; _burn(_id); }

In this revised code:

  • Input validation is added to check that the _id parameter is not zero.
  • The require statement is used to check that the caller is authorized to burn the NFT. This replaces the if statement and makes the code easier to read and less error-prone.
  • A check is added to ensure that there is a name associated with the token being burned.
  • The error message in the require statement is made more generic to avoid revealing information about the contract's internal workings.
  • The getApproved function is called using the correct syntax for a function call.

#0 - c4-judge

2023-04-11T05:48:48Z

0xleastwood marked the issue as grade-b

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter