Skip to content

Commit

Permalink
allow world-id address to be zero (for off-chain verification)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Jan 7, 2025
1 parent fa5b04a commit 3791224
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
21 changes: 11 additions & 10 deletions contracts/src/PBHEntryPointImplV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ contract PBHEntryPointImplV1 is IPBHEntryPoint, WorldIDImpl, ReentrancyGuard {
/// @dev This function is explicitly not virtual as it does not make sense to override even when
/// upgrading. Create a separate initializer function instead.
///
/// @param _worldId The World ID instance that will be used for verifying proofs.
/// @param _worldId The World ID instance that will be used for verifying proofs. If set to the
/// 0 addess, then it will be assumed that verification will take place off chain.
/// @param _entryPoint The ERC-4337 Entry Point.
/// @param _numPbhPerMonth The number of allowed PBH transactions per month.
///
Expand All @@ -154,7 +155,7 @@ contract PBHEntryPointImplV1 is IPBHEntryPoint, WorldIDImpl, ReentrancyGuard {
external
reinitializer(1)
{
if (address(_worldId) == address(0) || address(_entryPoint) == address(0) || _multicall3 == address(0)) {
if (address(_entryPoint) == address(0) || _multicall3 == address(0)) {
revert AddressZero();
}

Expand Down Expand Up @@ -205,10 +206,14 @@ contract PBHEntryPointImplV1 is IPBHEntryPoint, WorldIDImpl, ReentrancyGuard {
// Verify the external nullifier
PBHExternalNullifier.verify(pbhPayload.pbhExternalNullifier, numPbhPerMonth);

// We now verify the provided proof is valid and the user is verified by World ID
worldId.verifyProof(
pbhPayload.root, signalHash, pbhPayload.nullifierHash, pbhPayload.pbhExternalNullifier, pbhPayload.proof
);
// If worldId address is set, proceed with on chain verification,
// otherwise assume verification has been done off chain by the builder.
if (address(worldId) != address(0)) {
// We now verify the provided proof is valid and the user is verified by World ID
worldId.verifyProof(
pbhPayload.root, signalHash, pbhPayload.nullifierHash, pbhPayload.pbhExternalNullifier, pbhPayload.proof
);
}
}

/// Execute a batch of PackedUserOperation with Aggregators
Expand Down Expand Up @@ -295,10 +300,6 @@ contract PBHEntryPointImplV1 is IPBHEntryPoint, WorldIDImpl, ReentrancyGuard {
/// @notice Sets the World ID instance that will be used for verifying proofs.
/// @param _worldId The World ID instance that will be used for verifying proofs.
function setWorldId(address _worldId) external virtual onlyProxy onlyInitialized onlyOwner {
if (_worldId == address(0)) {
revert AddressZero();
}

worldId = IWorldID(_worldId);
emit WorldIdSet(_worldId);
}
Expand Down
8 changes: 1 addition & 7 deletions contracts/test/PBHEntryPointImplV1Init.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,8 @@ contract PBHEntryPointImplV1InitTest is Test {

address pbhEntryPointImpl = address(new PBHEntryPointImplV1());

// Expect revert when worldId is address(0)
bytes memory initCallData =
abi.encodeCall(PBHEntryPointImplV1.initialize, (IWorldID(address(0)), entryPoint, numPbh, multicall));
vm.expectRevert(PBHEntryPointImplV1.AddressZero.selector);
IPBHEntryPoint(address(new PBHEntryPoint(pbhEntryPointImpl, initCallData)));

// Expect revert when entrypoint is address(0)
initCallData =
bytes memory initCallData =
abi.encodeCall(PBHEntryPointImplV1.initialize, (worldId, IEntryPoint(address(0)), numPbh, multicall));
vm.expectRevert(PBHEntryPointImplV1.AddressZero.selector);
IPBHEntryPoint(address(new PBHEntryPoint(pbhEntryPointImpl, initCallData)));
Expand Down

0 comments on commit 3791224

Please sign in to comment.