World
Chain PBH

Covered the PBH entrypoint contract, EIP-4337 signature aggregator, and modified Safe Account module.
report id
0417
category
Infra & Wallets
language
Solidity
final report
April 1, 2025
lines of code
432
Content

Download audit report

1

Executive Summary

This document outlines the security review conducted by Nethermind Security for the World Chain Priority Blockspace for Humans (PBH) smart contracts. PBH allows World ID users to execute transactions with top-of-block priority, providing a smoother and more seamless user experience. This functionality is powered by a custom block builder and EIP-4337-style smart contracts, which identify transactions containing valid World ID proofs. The priority blockspace is a fixed-size subset of the regular blockspace, with transactions in the priority blockspace being processed first, followed by regular transactions.

This audit engagement focuses only on the smart contract layer, which consists of three contracts:

  • 1) A custom PBH entrypoint contract with World ID proof checking capabilities.
  • 2) An EIP-4337 signature aggregator, which is tightly integrated with the PBH entrypoint.
  • 3) A modified Safe Account EIP4337 module able to handle the unique PBH signature scheme.

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

Audit assessment
Audit TypeSecurity Review
Draft ReportJanuary 28, 2025
Final ReportFebruary 11, 2025
MethodsManual Review, Automated analysis
Repositoryworldcoin/world-chain
Initial Commit Hashcc112c4015
Final Commit Hash64fa073799
Documentation AssessmentHigh
Test Suite AssessmentHigh
Total findings
5
Fixed
4
Acknowledged
1
Mitigated
0
Unresolved
0

Findings by severity

  • Critical0
  • High0
  • Medium1
  • Low1
  • Informational0
  • Best Practices3

4

System Overview

The Worldcoin team introduced a custom block builder: World Chain Builder, which provides Priority Blockspace for Humans (PBH). With PBH a verified World ID user can benefit from top-of-block inclusion by providing a valid proof as part of their transaction. This mechanism ensures that certain transactions are prioritized for inclusion in the next block based on verified proof, offering a reliable way for users to access high-priority block space. The builder is designed to allocated a limited blockspace for PBH transactions per block, ensuring fair allocation between priority and non-priority transactions.

The PBH system consists of the following key components:

  • Bundlers: Bundlers are off-chain entities responsible for collecting and submitting user operations (userOps) for PBH inclusion. A bundler groups multiple userOps together with an aggregator and submits the resulting bundles to the PBH EntryPoint.
  • PBH EntryPoint: The PBHEntryPointImplV1 contract is the core contract responsible for PBH validation. It exposes the primary entry points for submitting PBH transactions. The PBHEntryPoint is a proxy contract that points to the PBHEntryPointImplV1 implementation, forwarding calls to the actual implementation.
  • Signature Aggregator: The signature aggregator is a utility contract used by bundlers to group multiple userOps. It provides functions for signature validation, and is tightly integrated with the PBH entrypoint contract, using transient storage to verify that a set of userOps already have valid proofs associated with them.
  • PBH4337 Module: The PBH4337Module extends the Safe 4337 module, enabling the acceptance of a threshold of ECDSA or ERC1271 signatures, with or without an attached proof.

The following diagram illustrates the system's main actors and components, along with their interactions:

Worldchain Contracts Overview
Worldchain Contracts Overview

4.1 PBH EntryPoint

Users can submit PBH transactions using one of two available methods. A PBH transaction can either contain a single-user operation or a bundle of multiple-user operations.

  • handleAggregatedOps: The user submits a PBH user operation, or a bundle of user operations, to the builder, which invokes the handleAggregatedOps function to submit the PBH transaction. The associated proof data is either verified on-chain, through the WorldID's verifyProof function, or by the block builder itself. Each set of user operations associated with the same aggregator is hashed and stored in transient storage for later signature validation. Once the verification is complete, the call is forwarded to the actual entry point of the Safe 4337 module, which processes the user operations, validating their signatures and executing them.
    function handleAggregatedOps( IEntryPoint.UserOpsPerAggregator[] calldata opsPerAggregator, address payable beneficiary ) external virtual onlyProxy onlyInitialized nonReentrant
  • pbhMulticall: Users are able to execute multicalls with top-of-block inclusion through the pbhMulticall function.
    function pbhMulticall( IMulticall3.Call3[] calldata calls, PBHPayload calldata pbhPayload ) external virtual onlyProxy onlyInitialized nonReentrant returns ( IMulticall3.Result[] memory returnData )

4.2 PBH Signature Aggregator

The PBHSignatureAggregator contract is used as a utility by the bundler to aggregate UserOperation proofs onto the signature to be passed to the handleAggregatedOps function. This aggregation is implemented through the aggregateSignatures function, which consolidates the signatures from the user operations into a single aggregated signature.

function aggregateSignatures(
PackedUserOperation[] calldata userOps
) external view returns (bytes memory aggregatedSignature)

The PBHSignatureAggregator contract also defines the validateSignatures function, which is invoked by the Safe 4337 EntryPoint contract to validate the signatures of the user operations. This function forwards the call to the PBHEntryPoint's validateSignaturesCallback function. In this callback, the stored hashed user operations are compared with those provided. If they match, the signature is considered valid. This ensures that only correctly signed and verified operations are executed.

function validateSignatures(
PackedUserOperation[] calldata userOps,
bytes calldata
) external view

4.3 PBH4337 Module

The PBH4337Module extends the Safe 4337 module, allowing the handling of a set of signatures following the PBH signature schema. Eventually, it overrides the _validateSignatures function to allow the acceptance of a threshold of ECDSA signatures, with or without an attached proof.

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 Nullifier hashes may be consumed without a valid proof

FileFix commitTypeStatus
PBHEntryPointImplV1.sol—MediumFixed

When attempting to execute a priority transaction through the PBH entrypoint, a user must provide a valid external nullifier and nullifier hash. These are combined with other data to verify a proof, ensuring that the user has a valid World ID. To prevent replay attacks, a storage mapping nullifierHashes tracks all previously used hashes. Upon successful execution of a PBH transaction, the nullifier hash will be marked as "used" and cannot be used again.

The entrypoint contract supports two PBH flows: handleAggregatedOps and pbhMulticall. Both functions verify the proof and mark the nullifier hash as used. If the entrypoint storage variable worldId is not set, then proofs are not verified onchain, and it becomes the builder's responsibility to validate them.

function verifyPbh(uint256 signalHash, PBHPayload memory pbhPayload) ... {
// Check for nullifier hash reuse
if (nullifierHashes[pbhPayload.nullifierHash]) {
revert InvalidNullifier();
}

// Verify the external nullifier
PBHExternalNullifier.verify(pbhPayload.pbhExternalNullifier, numPbhPerMonth);

// Skip onchain verification if `worldId` is not set
if (address(worldId) != address(0)) {
worldId.verifyProof(
..., pbhPayload.nullifierHash, ...
);
}
}

When the worldId is not set, it may be possible for a user to call either of the two entrypoint functions with an invalid proof and still consume a nullifier hash. Depending on the builder implementation, there are two behaviors when an invalid proof is provided to the PBH entrypoint contract:

  1. Allow the transaction to be included in the block but without priority
  2. Reject the transaction, preventing it from being included in the block

If the builder follows the first behavior, users could call handleAggregatedOps or pbhMulticall with invalid proofs and still consume these nullifier hashes. During discussions related to this finding, the Worldcoin team raised the concern that an entity could become a bundler and get access to user PBH calls before they have been executed. This malicious entity could then attempt to mark a user's nullifier hashes as used before the user transaction executes, causing the user's call to revert since the nullifier hash is already used.

Recommendation

Ensure that the Worldchain block builder excludes transactions that include a call to the PBH entrypoint functions handleAggregatedOps and pbhMulticall if they do not meet the PBH conditions (invalid proof).

Resolution

The World Chain block builder ensures that transactions can not call into the PBHEntryPoint unless it is specified as the transaction’s to address. Additionally, in the follow-up commit a change has been applied to only allow authorized builder addresses to spend nullifier hashes.

6.2 Missing length check for pbhPayloads and userOps

FileFix commitTypeStatus
PBHEntryPointImplV1.solPR #140LowFixed

In the function handleAggregatedOps, there is a nested loop which iterates through the userOps for each aggregator. Each userOp should have a phbPayload associated with it, which is used in verifyPbh to ensure that a valid proof has been provided. If any userOp has an invalid proof then the transaction will revert. The code is shown below:

function handleAggregatedOps(...) ... {
for (uint256 i = 0; i < opsPerAggregator.length; ++i) {
//...
PBHPayload[] memory pbhPayloads = abi.decode(
opsPerAggregator[i].signature,
(PBHPayload[])
);
for (uint256 j = 0; j < pbhPayloads.length; ++j) {
address sender = opsPerAggregator[i].userOps[j].sender;
// Generate signal hash for verification
uint256 signalHash = abi.encodePacked(...).hashToField();
// Verify proof
verifyPbh(signalHash, pbhPayloads[j]);
// ...
}
}
// ...
}

However, there are no checks to ensure that the length of pbhPayloads extracted from the aggregator signature is equal to the number of userOps in the aggregator's struct. The inner loop which does the proof verification will stop once it has reached the length of pbhPayloads. When pbhPayloads is less than userOps the loop will stop executing even though there are additional user operations which have not been verified. These skipped userOps will not be verified and their nullifier hash will not be consumed, but their call will still execute successfully.

This method of skipping proof verification can be done even when the worldId address is set and onchain proof verification is supposed to occur. Since this logic flow of skipping proof verification is unexpected, the builder implementation may not be written in such a way that can detect this, and may consider all userOps as PBH regardless. If this is the case, then any user may be able to append additional userOps without an associated proof and bypass the numPbhPerMonth limit.

Recommendation

Consider adding a check to handleAggregatedOps to ensure that the length of pbhPayloads is equal to opsPerAggregator.

Resolution

Addressed in PR #140.

6.3 Unnecessary gas check in pbhMulticall

FileFix commitTypeStatus
PBHEntryPointImplV1.solPR #139Best PracticesFixed

The function pbhMulticall verifies a user's calls and pbhPayload before making a call to Multicall3.aggregate3, which executes the users intended actions. After these calls are executed, the following gas check is done:

function pbhMulticall(...) ... returns (...) {
// Verify calls and proof
// ...
returnData = IMulticall3(_multicall3).aggregate3{gas: pbhGasLimit}(calls);
// ...

// Check if pbh gas limit is exceeded
if (gasleft() > pbhGasLimit) {
revert GasLimitExceeded(gasleft());
}
// ...
}

The purpose of this check is to ensure that an excessive amount of gas hasn't been spent in the transaction, as it may affect other PBH users if excessive gas amounts reach the block limits. However, this check is ineffective as it's possible for gas to have been spent before the call to pbhMulticall. The check only ensures that there is some small amount of gas (pbhGasLimit) remaining after the call.

Recommendation

Consider removing the ineffective check, and explore options for a more complete gas spend check, potentially one that is integrated into the builder.

Resolution

Addressed in PR #139.

6.4 Opportunity to save gas in checkSignatures on next Safe release

FileFix commitTypeStatus
PBHEntryPointImplV1.sol—Best PracticesAcknowledged

The PBH4337Module is an override of a forked Safe4337Module with a change to _validateSignatures which allows it to handle the unique PBH signature structure. Once the userOp.signature has been processed properly (prepended and appended data extracted) the module calls checkSignatures on the user's Safe smart contract account, as shown below:

function _validateSignatures(...) ... {
// ...
// Get threshold
uint256 threshold = ISafe(payable(userOp.sender)).getThreshold();
// ...
// Extract signature
if (isPBH && userOp.signature.length > expectedLength) {
if (userOp.signature.length - expectedLength != ENCODED_PROOF_BYTES) {
revert InvalidProofSize();
}
signatures = userOp.signature[TIMESTAMP_BYTES:expectedLength];
}
// ...
try ISafe(payable(userOp.sender)).checkSignatures(keccak256(operationData), operationData, signatures) {}
catch {
validSignature = false;
}
// ...
}

In Safe's latest code (ahead of the latest version 1.4.1-3), there are two versions of this function, each accepting different arguments:

checkSignatures(bytes32,bytes,bytes)
checkSignatures(address,bytes32,bytes)

A comment in the Safe implementation states that the (bytes32,bytes,bytes) function will only exist for compatibility reasons, and that the newer (address,bytes32,bytes) should be used instead. When the next Safe version is released, using the newer function will reduce gas costs since the unhashed operationData won't have to be sent as part of the call, only the hashed data.

Recommendation

No action needs to be taken now, this finding only serves to highlight the opportunity to reduce gas costs during signature verification when a future Safe version is released.

Resolution

Acknowledged.

6.5 Natspec and comments

FileFix commitTypeStatus
/*PR #142
PR #153
Best PracticesFixed

The following is a list of Natspec and comment corrections:

`PBHEntryPointImplV1.initialize` the args `multicall3` and `_pbhGasLimit` are missing natspec comments
`PBHEntryPointImplV1.initialize` @dev comment for `_worldId` has typo "addess" -> "address"
`PBHEntryPointImplV1.PBHEntryPointImplInitialized` event arg `pbhGasLimit` missing natspec comment
`PBHExternalNullifier.encode` the arg `version` is missing a natspec comment

Recommendation

Consider correcting the comments mentioned above.

Resolution

Addressed in PR #142 and PR #153.

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 documentation for the World Chain contracts is contained in two README files in the project's GitHub repository. The first README, located in the root directory, provides a high-level overview of PBH, covering both the smart contracts and block-building architecture. Within the contracts directory, there is a README specifically detailing the smart contracts. This document explains the dependencies of the contracts (EIP-4337, Safe Accounts) and provides an explanation of each contract. For the entrypoint contract, the two primary functions, handleAggregatedOps and pbhMulticall, are also covered.

The information is presented in a very concise and technical manner, with well-written explanations and references where necessary. It also features a section explaining development dependencies and instructions on how to build and test the code.

Code comments are also of high quality, with explanations for many functions describing the purpose, context, and situations where the function will be called. Other than functions, some comments exist in other areas of the code where extra information is necessary, allowing readers to understand the codebase at a faster pace.

The test suite for the PBH contracts is extensive, covering public functions of the contracts as well as internal functions, as in the case of PBH4337Module, where a function override occurs. The fuzzing features of Foundry are used throughout the test suite to ensure that functions behave correctly with a wide range of inputs. For the PBHEntryPoint logic, testing extends not only to expected function behavior but also to initialization and proxy-related behaviors, such as blocking access to direct interactions with the implementation contract.

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