Skip to content

Commit

Permalink
add verifyCompressedProof function
Browse files Browse the repository at this point in the history
  • Loading branch information
karankurbur committed Jan 29, 2025
1 parent 0115c67 commit bb48d8a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/WorldIDIdentityManagerImplV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,27 @@ contract WorldIDIdentityManagerImplV3 is WorldIDIdentityManagerImplV2 {
semaphoreVerifier.verifyProof(proof, input);
}
}

/// @notice A verifier for the semaphore protocol that supports compressed proofs
/// @dev Note that a double-signaling check is not included here, and should be carried by the
/// caller.
///
/// @param root The of the Merkle tree
/// @param signalHash A keccak256 hash of the Semaphore signal
/// @param nullifierHash The nullifier hash
/// @param externalNullifierHash A keccak256 hash of the external nullifier
/// @param compressedProof The zero-knowledge proof
/// @custom:reverts string If the zero-knowledge proof cannot be verified for the public inputs.
function verifyCompressedProof(
uint256 root,
uint256 signalHash,
uint256 nullifierHash,
uint256 externalNullifierHash,
uint256[4] calldata compressedProof
) public view virtual onlyProxy onlyInitialized {
// Check the preconditions on the inputs.
requireValidRoot(root);
uint256[4] memory input = [root, nullifierHash, signalHash, externalNullifierHash];
semaphoreVerifier.verifyCompressedProof(compressedProof, input);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {SemaphoreVerifier} from "src/test/SemaphoreVerifier16.sol";
import {WorldIDIdentityManager as IdentityManager} from "../../WorldIDIdentityManager.sol";
import {WorldIDIdentityManagerImplV2 as ManagerImpl} from "../../WorldIDIdentityManagerImplV2.sol";
import {WorldIDIdentityManagerImplV1 as ManagerImplV1} from "../../WorldIDIdentityManagerImplV1.sol";
import {WorldIDIdentityManagerImplV3 as ManagerImplV3} from "../../WorldIDIdentityManagerImplV3.sol";

/// @title World ID Identity Manager Semaphore Proof Verification Tests
/// @notice Contains tests for the WorldID identity manager.
Expand Down Expand Up @@ -51,6 +52,14 @@ contract WorldIDIdentityManagerSemaphoreVerification is WorldIDIdentityManagerTe

// Test
assertCallSucceedsOn(identityManagerAddress, verifyProofCallData);

bytes memory verifyCompressedProofCallData = abi.encodeCall(
ManagerImplV3.verifyCompressedProof,
(insertionPreRoot, nullifierHash, signalHash, externalNullifierHash, prf)
);

// Test
assertCallSucceedsOn(identityManagerAddress, verifyCompressedProofCallData);
}

/// @notice Checks that the proof validates properly with the correct inputs.
Expand Down

0 comments on commit bb48d8a

Please sign in to comment.