World
Grants4

Grants4 runs World's monthly WLD grants from grant 39 onward, and lets relayers claim for a user right after Orb verification. We reviewed the claim logic, including older reservations for grants 21 to 38.
report id
0302
category
Token & RWA
language
Solidity
final report
September 23, 2024
lines of code
369
Content

Download audit report

1

Executive Summary

This document outlines the security review conducted by Nethermind Security for the Worldcoin Grants4 contracts. These new contracts will replace the previous ones starting from the 39th grant, distributed in August 2024. While grant reservation is no longer possible under the new system, users can still claim reservations made in the past for grants 21 to 38.

From Grant 39 through Grant 88, users are entitled to claim one WLD token drop per month. However, if a user is verified for the first time, they can claim the token drop from the previous month during their first month after joining. The new system also introduces a feature allowing authorized relayers to claim the drops on behalf of users immediately upon verification by the Orb. This enhancement addresses the previous delay, where users had to wait for their identity to be propagated across all relevant L2 networks before claiming their tokens.

The audited code comprises of 369 lines of code written in the Solidity language, and it was performed using (a) manual analysis of the codebase, (b) automated analysis tools, (c) simulation of the smart contract.

Audit assessment
Audit TypeSecurity Review
Initial ReportAug 30, 2024
Response from ClientRegular responses during audit engagement
Final ReportSep 23, 2024
Repositoryworldcoin-grants-contracts
Commit (Audit)107a056474
Commit (Final)e78b7dbc38
Documentation AssessmentMedium
Test Suite AssessmentHigh
Total findings
4
Fixed
4
Acknowledged
0
Mitigated
0
Unresolved
0

Findings by severity

  • Critical0
  • High0
  • Medium0
  • Low0
  • Informational0
  • Best Practices4

2

Audited Files

#ContractLoCCommentsRatioBlankTotal
1WLDGrantPreGrant4_new.sol281139.3%1150
2RecurringGrantDrop.sol1329471.2%58284
3WLDGrant.sol1062624.5%18150
4Grants4FirstBatch/Grants4FirstBatch.sol1034240.8%36181
Total36917346.9%123665

3

Summary of Issues

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: Authorized Worldcoin relayers can call the batch(...) function from this contract to claim drops on behalf of the users. This action marks the nullifierHash as used in the RecurringGrantDrop contract to prevent users from claiming the same grant for the second time.
  • RecurringGrantDrop (old): Users can still claim their existing reservations by interacting with the old instance of the RecurringGrantDrop contract.

The grant claiming process in the Worldcoin Grants4 system differs 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 new 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 is designed to improve the user experience by eliminating the delay 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. This created friction, as users could not claim their grant tokens immediately after being verified by the Orb, even though the Worldcoin backend already had their identity data. The delay occurred because this information had yet to be posted on-chain.

In the new system, authorized Worldcoin relayers can now step in to claim the tokens as soon as a user is verified. The relayer interacts with the Grants4FirstBatch contract, using the batch(...) function to claim the tokens. In turn, the Grants4FirstBatch contract calls the setNullifierHash(...) function in the RecurringGrantDrop contract to verify whether the nullifier hash for the particular grant claim has already been used. If the nullifier hash has not been used, the setNullifierHash(...) function sets it and transfers the WLD tokens to the user, completing the claim. If the nullifier hash has already been set, the function skips the grant claim, effectively 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 Missing zero address checks in Grants4FirstBatch

FileFix commitTypeStatus
Grants4FirstBatch.sole78b7dbBest PracticesFixed

In the RecurringGrantDrop contract, the constructor(...) and all the setter functions have address(0) checks. This is not the case for the Grants4FirstBatch contract. The constructor(...) doesn’t have address(0) checks for its input parameters, nor do the setter functions setAllowanceModule(...), setWldToken(...), setHolder(...), setRecurringGrantDrop(...), addCaller(...).

Recommendation

Consider adding zero address checks to maintain consistency throughout the codebase

Resolution

Addressed in e78b7db.

6.2 Third-party code should be imported and installed as an external dependency

FileFix commitTypeStatus
Grants4FirstBatch.sole78b7dbBest PracticesFixed

The Grants contracts use third-party libraries and utilities, such as OpenZeppelin’s Ownable2Step and SafeERC20. Unlike other contracts, the Grants4FirstBatch contract uses third-party utilities that are directly copied into the project’s source files rather than imported and installed as the project’s external dependencies.

This approach has implications for the security of the codebase. While libraries receive continuous updates to address any vulnerabilities or issues discovered, copying code internally makes tracking and applying necessary security updates more challenging. Additionally, the absence of the library version and the origin from where the code was copied makes it hard to review that particular code or function.

Below is the list of files where this issue is present:

Recommendation

To mitigate security risks and facilitate the review of the codebase, consider importing third-party code similarly to how it is done in other contracts such as RecurringGrantDrop. Alternatively, add comments about the code’s origin and the version used.

Resolution

Addressed in e78b7db. In some places we decided not to use imports (for now) but added docs there.

6.3 Unused code in Grants4FirstBatch contract

FileFix commitTypeStatus
Grants4FirstBatch.sole78b7dbBest PracticesFixed

The Grants4FirstBatch.sol file contains an Enum contract and a GnosisSafe interface. The execTransactionFromModule(...) function inside the GnosisSafe interface is never called and could be removed to keep the code clean and readable. This change makes the Enum contract obsolete as well.

Recommendation

Consider removing the unused code from the codebase or moving it to a separate file, from where it will be imported when needed.

Resolution

Addressed in e78b7db.

6.4 Unused imports

FileFix commitTypeStatus
RecurringGrantDrop.sole78b7dbBest PracticesFixed

The RecurringGrantDrop.sol file imports OpenZeppelin’s ECDSA library which is unused in the contract.

Recommendation

Consider removing unused import statement to keep the codebase clean and readable.

Resolution

Addressed in e78b7db.

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 Worldcoin team has provided documentation about their protocol in the form of in-line comments within the code.

Test suite
44Tests 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.