World
NFC ID

NFC ID builds on World's Grants4 contracts, which we audited earlier. This review covered the NFC_ID contract and a gated Multicall3 contract that controls who can batch calls.
report id
0382
category
Identity & Cryptography
language
Solidity
final report
November 18, 2024
lines of code
281
Content

Download audit report

1

Executive Summary

This document outlines the security review conducted by Nethermind Security for the WORLD NFC-ID contracts. The codebase is an evolution of the codebase audited in the report NM-0302-WORLDCOIN-GRANTS4 contracts. This audit focused on two contracts: src/NFC_ID/NFC_ID.sol and src/GatedMulticall3/GatedMulticall3.sol comprising 281 lines of Solidity code, and it was performed using (a) manual analysis of the codebase, (b) automated analysis tools, (c) simulation of the smart contract. The codebase has high quality.

The issues relate to best practices that enhance code consistency and pose no security threats. For example, missing zero-address checks, unnecessary payable keywords, and omitted event emissions do not compromise contract security but can improve reliability and maintainability when addressed.

Out of the six issues identified, three were fixed: First, the issue with events not being emitted in the constructor was resolved, ensuring that storage variable updates trigger events as expected. Second, a zero-address check was added to the addAuthorizedCaller function, aligning it with the rest of the codebase’s standards for address validation. Third, an unchecked conversion on the _amount parameter in the claim(...) function was addressed by implementing a check to prevent overflow, thus improving reliability.

The remaining three issues were acknowledged. Centralization risks were accepted. Additionally, functions that don’t expect native tokens to be transferred were left marked as payable to maintain compatibility with the Allowance Module interface, avoiding interface modifications. Finally, the lack of enforcement linking _nullifierHash and _recipient was accepted as a manageable risk, given that only trusted callers can access the function.

Audit assessment
Audit TypeSecurity Review
Initial ReportNov 15, 2024
Response from ClientRegular responses during audit engagement
Final ReportNov 18, 2024
RepositoryWorld NFC-ID
Commit (Audit)8672196e6b
Commit (Final)d82b025501
Documentation AssessmentHigh
Test Suite AssessmentHigh
Total findings
6
Fixed
3
Acknowledged
3
Mitigated
0
Unresolved
0

Findings by severity

  • Critical0
  • High0
  • Medium0
  • Low0
  • Informational1
  • Best Practices5

2

Audited Files

#ContractLoCCommentsRatioBlankTotal
1src/GatedMulticall3/GatedMulticall3.sol1866937.1%41296
2src/NFC_ID/NFC_ID.sol954042.1%34169
Total28110938.8%75465

4

System Overview

The following section provides an overview of the system architecture and key contracts involved in the current Worldcoin Grants contracts (Grants4) version, which replaces the previous contracts starting from the 39th grant.

4.1 Contracts overview

The Worldcoin Grants4 system is primarily composed of the following contracts:

  • RecurringGrantDrop (new): This contract handles the distribution of grant tokens (WLD) for grants with a grantId of 39 or higher. The contract allows users to claim monthly WLD drops once the Orb verifies them. The contract supports the new feature where authorized relayers can claim drops on behalf of users immediately after their verification.
  • WLDGrant: This contract holds the configuration of the Grants contracts. It is used to query the currently active grants and their token amounts. The checkValidity(...) function can be used to determine if a particular grantId is claimable.
  • Grants4FirstBatch (replaced): Previously, this contract allowed authorized Worldcoin relayers to call the batch(...) function to claim drops on behalf of users. This action marked the nullifierHash as used in the RecurringGrantDrop contract to prevent users from claiming the same grant twice. This was replaced by the NFC_ID contract.
  • GatedMulticall3 (new): This contract is a modified version of the well-known Multicall3, adding an authorization layer. Only authorized msg.sender accounts can interact with it, ensuring secure execution of multiple contract calls in a single transaction.
  • NFC_ID (new): This contract replaces the Grants4FirstBatch. It allows authorized relayers to claim WLD tokens for individual users. Unlike its predecessor, NFC_ID does not handle batch claims but instead stores the nullifierHash directly within the contract, eliminating the need to call the RecurringGrantDrop contract for nullifier validation.

The grant-claiming process in the Worldcoin Grants4 system remains largely similar, depending on whether the grant is part of the new grant cycle (Grants 39-88) or involves reservations made in the previous system. The following section outlines the updated grant-claiming process.

4.2 Grant claiming process

For the new grants cycle, starting from Grant 39 and continuing through to Grant 88, users are entitled to claim WLD token drops every month. the new system introduces a decreasing grant amount each month. However, the initial month’s token amount starts from a higher base than in the previous system, providing a larger initial drop. The specific amounts are predetermined and stored in the grantAmountsList array in the WLDGrant contract. Whenever the user or authorized relayer claims a grant, the RecurringGrantDrop contract queries the WLDGrant contract to determine the exact token amount to be distributed for that particular month.

At any given time, two grants are active: the current month’s grant and the previous month’s grant. This allows users who missed claiming their tokens in the current month to still claim them in the following month.

For old reservations (Grants 21-38), users can still claim their previously reserved tokens by interacting with the old instance of the RecurringGrantDrop contract.

4.3 Immediate post-verification grant claims

One of the enhancements in the Worldcoin Grants4 protocol is the introduction of authorized relayers who can claim WLD token drops on behalf of users immediately after they are verified by the Orb. This feature improves the user experience by eliminating delays that existed in the previous system.

Previously, users had to wait until their identity was propagated across all relevant Layer 2 (L2) networks before claiming their tokens, causing a delay between verification and the ability to claim. In the new system, authorized Worldcoin relayers interact with the NFC_ID contract to claim tokens for users individually.

When a claim is made, the NFC_ID contract validates the nullifierHash directly. If the nullifierHash has not been used, it is marked as used within NFC_ID, and the WLD tokens are transferred to the user, completing the claim. If the nullifierHash has already been set, the claim is skipped, preventing duplicate claims.

5

Risk Rating Methodology

The risk rating methodology used by Nethermind Security follows the principles established by the OWASP Foundation. The severity of each finding is determined by two factors: Likelihood and Impact.

Likelihood measures how likely the finding is to be uncovered and exploited by an attacker. This factor will be one of the following values:

  1. High: the issue is trivial to exploit and has no specific conditions that need to be met;
  2. Medium: the issue is moderately complex and may have some conditions that need to be met;
  3. Low: the issue is very complex and requires very specific conditions to be met.

When defining the likelihood of a finding, other factors are also considered. These can include but are not limited to motive, opportunity, exploit accessibility, ease of discovery, and ease of exploit.

Impact is a measure of the damage that may be caused if an attacker exploits the finding. This factor will be one of the following values:

  1. High: the issue can cause significant damage, such as loss of funds or the protocol entering an unrecoverable state;
  2. Medium: the issue can cause moderate damage, such as impacts that only affect a small group of users or only a particular part of the protocol;
  3. Low: the issue can cause little to no damage, such as bugs that are easily recoverable or cause unexpected interactions that cause minor inconveniences.

When defining the impact of a finding, other factors are also considered. These can include but are not limited to data and state integrity, loss of availability, financial loss, and reputation damage. After defining the likelihood and impact of an issue, the severity is determined according to the table below.

Impact / LikelihoodLowMediumHigh
HighMediumHighCritical
MediumLowMediumHigh
LowInfo / Best PracticesLowMedium
UndeterminedUndeterminedUndeterminedUndetermined

To address issues that do not fit a High, Medium or Low severity, Nethermind Security also uses three more finding severities: Informational, Best Practices, and Undetermined.

  1. Informational findings do not pose any risk to the application, but they carry some information that the audit team intends to pass to the client formally;
  2. Best Practice findings are used when some piece of code does not conform with smart contract development best practices;
  3. Undetermined findings are used when we cannot predict the impact or likelihood of the issue.

6

Issues

6.1 Centralization Risks

FileFix commitTypeStatus
src/NFC_ID/NFC_ID.sol—InfoAcknowledged

The contract allows the owner to update the address of the WLD token, the HOLDER, and the ALLOWANCE_MODULE. Arbitrary changes in critical configuration contracts may open the door to malicious modifications compromising contract security. The functions setWldToken(...), setHolder(...), and setAllowanceModule(...) are reproduced below.

function setWldToken(address _wldToken) external onlyOwner {
if (_wldToken == address(0)) {
revert ZeroAddress();
}
WLD_TOKEN = _wldToken;
emit WldTokenSet(_wldToken);
}
function setHolder(address _holder) external onlyOwner {
if (_holder == address(0)) {
revert ZeroAddress();
}
HOLDER = GnosisSafe(_holder);
emit HolderSet(_holder);
}
function setAllowanceModule(address _allowanceModuleAddress) external onlyOwner {
if (_allowanceModuleAddress == address(0)) {
revert ZeroAddress();
}
ALLOWANCE_MODULE = AllowanceModule(_allowanceModuleAddress);
emit AllowanceModuleSet(_allowanceModuleAddress);
}

Recommendation

No action is required.

Resolution

While it is true that it is questionable that we will ever update the token address, etc. The owner will be a trusted multisig, and we accept these risks.

6.2 Functions that don’t expect native tokens to be transferred shouldn’t be payable

FileFix commitTypeStatus
src/GatedMulticall3/GatedMulticall3.sol—Best PracticesAcknowledged

The aggregate(...), tryAggregate(...), tryBlockAndAggregate(...), blockAndAggregate(...), and aggregate3(...) function doesn’t expect any native tokens to be transferred unlike aggregate3Value(...) so they shouldn’t be payable. Any native token sent will be locked in the contract.

Recommendation

Consider removing the payable keyword in the functions that don’t expect native tokens to be transferred.

Resolution

We won’t fix it. The Allowance Module interface expects a payable address, so to avoid changes to the interface, we keep marking it as payable.

Update from Nethermind Security

We agree with this decision.

6.3 Events not emitted in the constructor

FileFix commitTypeStatus
src/NFC_ID/NFC_ID.solPR #36Best PracticesFixed

When ALLOWANCE_MODULE, WLD_TOKEN or HOLDER is changed using setAllowanceModule(...), setWldToken(...) or setHolder(...) function respectively, event AllowanceModuleSet, WldTokenSet or HolderSet is emitted but when these variables are initially set in the constructor, no events are emitted.

Recommendation

Emit appropriate events in the constructor as the storage variables are also updated in the constructor.

Resolution

Added in d82b025501f3d4d90899b6ed20ca1e1676efe70e.

6.4 Lack of zero address check on GatedMulticall3::addAuthorizedCaller function

FileFix commitTypeStatus
src/GatedMulticall3/GatedMulticall3.solPR #36Best PracticesFixed

All the setter functions inside the codebase have a check that prevents the owner from giving any roles to address(0x0), except for the function GatedMulticall3::addAuthorizedCaller(...). The function is reproduced below.

function addAuthorizedCaller(address _caller) public onlyOwner {
////////////////////////////////////////////////
//@audit: lack of zero address check
////////////////////////////////////////////////
authorizedCallers[_caller] = true;
emit AuthorizedCallerAdded(_caller);
}

Recommendation

Consider adding a zero address check in this function to maintain consistency throughout the codebase. However, there is no harm in keeping the code as it is.

Resolution

Fixed in d82b025501f3d4d90899b6ed20ca1e1676efe70e.

6.5 Unchecked conversion on _amount in the function claim(...)

FileFix commitTypeStatus
src/NFC_ID/NFC_ID.solPR #36Best PracticesFixed

The function claim(...) converts the variable _amount from uint256 to uint96 but there is no check to ensure that _amount actually fits within a uint96.

function claim( uint256 _nullifierHash, address _recipient, uint256 _amount ) external {
...
/////////////////////////////////////////////////////////
// @audit: Check if "_amount" fits in a uint96 before
// making the conversion.
/////////////////////////////////////////////////////////
AllowanceModule(ALLOWANCE_MODULE).executeAllowanceTransfer(
HOLDER, WLD_TOKEN, payable(_recipient), uint96(_amount)
);

emit NFCIDGrantClaimed(_recipient);
}

Recommendation

Add a check to ensure that _amount always fits a uint96 before making the conversion.

Resolution

Fixed in d82b025501f3d4d90899b6ed20ca1e1676efe70e.

6.6 Lack of enforcement linking _nullifierHash and _recipient

FileFix commitTypeStatus
src/NFC_ID/NFC_ID.sol—Best PracticesAcknowledged

The function NFC_ID::claim(...) does not enforce any relationship between the _nullifierHash and the _recipient parameters. As long as the caller provides a valid _nullifierHash, they can set their own address as the _recipient, claiming the tokens meant for other users.

Since this function can only be called by a whitelisted allowedCaller, the impact is mitigated, but the security of this function can be further improved if these two parameters are tied together.

Recommendation

Consider adding checks that tie the _nullifierHash to the adequate _recipient.

Resolution

We won’t fix it. The contract can only be called by a trusted caller, and we accept this risk.

7

Documentation Evaluation

Software documentation refers to the written or visual information that describes the functionality, architecture, design, and implementation of software. It provides a comprehensive overview of the software system and helps users, developers, and stakeholders understand how the software works, how to use it, and how to maintain it. Software documentation can take different forms, such as user manuals, system manuals, technical specifications, requirements documents, design documents, and code comments. Software documentation is critical in software development, enabling effective communication between developers, testers, users, and other stakeholders. It helps to ensure that everyone involved in the development process has a shared understanding of the software system and its functionality. Moreover, software documentation can improve software maintenance by providing a clear and complete understanding of the software system, making it easier for developers to maintain, modify, and update the software over time. Smart contracts can use various types of software documentation. Some of the most common types include:

  • Technical whitepaper: A technical whitepaper is a comprehensive document describing the smart contract’s design and technical details. It includes information about the purpose of the contract, its architecture, its components, and how they interact with each other;
  • User manual: A user manual is a document that provides information about how to use the smart contract. It includes step-by-step instructions on how to perform various tasks and explains the different features and functionalities of the contract;
  • Code documentation: Code documentation is a document that provides details about the code of the smart contract. It includes information about the functions, variables, and classes used in the code, as well as explanations of how they work;
  • API documentation: API documentation is a document that provides information about the API (Application Programming Interface) of the smart contract. It includes details about the methods, parameters, and responses that can be used to interact with the contract;
  • Testing documentation: Testing documentation is a document that provides information about how the smart contract was tested. It includes details about the test cases that were used, the results of the tests, and any issues that were identified during testing;
  • Audit documentation: Audit documentation includes reports, notes, and other materials related to the security audit of the smart contract. This type of documentation is critical in ensuring that the smart contract is secure and free from vulnerabilities.

These types of documentation are essential for smart contract development and maintenance. They help ensure that the contract is properly designed, implemented, and tested, and they provide a reference for developers who need to modify or maintain the contract in the future.

8

Remarks & Test Suite

The World team has provided documentation about their protocol in the form of in-line comments within the code.

Remarks about World test suite

The World team has a comprehensive test suite that checks the main features of the codebase. This rigorous testing contributes to a well-written and secure codebase.

Test suite
59Tests passed0Failed

The complete test output is in the full report.

As auditors, we recommend that any changes or updates made to the audited codebase undergo a re-audit or security review to address potential vulnerabilities or risks introduced by the modifications. By conducting a re-audit or security review of the modified codebase, you can significantly enhance the overall security of your system and reduce the likelihood of exploitation. However, we do not possess the authority or right to impose obligations or restrictions on our clients regarding codebase updates, modifications, or subsequent audits. Accordingly, the decision to seek a re-audit or security review lies solely with you.

This report is based on the scope of materials and documentation provided by you to Nethermind in order that Nethermind could conduct the security review outlined in 1. Executive Summary and 2. Audited Files. The results set out in this report may not be complete nor inclusive of all vulnerabilities. Nethermind has provided the review and this report on an as-is, where-is, and as-available basis. You agree that your access and/or use, including but not limited to any associated services, products, protocols, platforms, content, and materials, will be at your sole risk. Blockchain technology remains under development and is subject to unknown risks and flaws. The review does not extend to the compiler layer, or any other areas beyond the programming language, or other programming aspects that could present security risks. This report does not indicate the endorsement of any particular project or team, nor guarantee its security. No third party should rely on this report in any way, including for the purpose of making any decisions to buy or sell a product, service or any other asset. To the fullest extent permitted by law, Nethermind disclaims any liability in connection with this report, its content, and any related services and products and your use thereof, including, without limitation, the implied warranties of merchantability, fitness for a particular purpose, and non-infringement. Nethermind does not warrant, endorse, guarantee, or assume responsibility for any product or service advertised or offered by a third party through the product, any open source or third-party software, code, libraries, materials, or information linked to, called by, referenced by or accessible through the report, its content, and the related services and products, any hyperlinked websites, any websites or mobile applications appearing on any advertising, and Nethermind will not be a party to or in any way be responsible for monitoring any transaction between you and any third-party providers of products or services. As with the purchase or use of a product or service through any medium or in any environment, you should use your best judgment and exercise caution where appropriate. FOR AVOIDANCE OF DOUBT, THE REPORT, ITS CONTENT, ACCESS, AND/OR USAGE THEREOF, INCLUDING ANY ASSOCIATED SERVICES OR MATERIALS, SHALL NOT BE CONSIDERED OR RELIED UPON AS ANY FORM OF FINANCIAL, INVESTMENT, TAX, LEGAL, REGULATORY, OR OTHER ADVICE.