Skip to content

Commit

Permalink
updated ITreeVerifier interface
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKitsune committed Sep 12, 2023
1 parent 4053d20 commit 730452f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
4 changes: 3 additions & 1 deletion src/Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

pragma solidity ^0.8.0;

import {ITreeVerifier} from "src/interfaces/ITreeVerifier.sol";

/// @title Groth16 verifier template.
/// @author Remco Bloemen
/// @notice Supports verifying Groth16 proofs. Proofs can be in uncompressed
/// (256 bytes) and compressed (128 bytes) format. A view function is provided
/// to compress proofs.
/// @notice See <https://2π.com/23/bn254-compression> for further explanation.
contract Verifier {
contract Verifier is ITreeVerifier{

/// Some of the provided public input values are larger than the field modulus.
/// @dev Public input elements are not automatically reduced, as this is can be
Expand Down
31 changes: 13 additions & 18 deletions src/interfaces/ITreeVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@ pragma solidity ^0.8.21;
/// @author Worldcoin
/// @notice An interface representing a merkle tree verifier.
interface ITreeVerifier {
/// @notice Verifies the provided proof data for the provided public inputs.
/// @dev It is highly recommended that the implementation is restricted to `view` if possible.
///
/// @param a The first G1Point of the proof (ar).
/// @param b The G2Point for the proof (bs).
/// @param c The second G1Point of the proof (kr).
/// @param input The public inputs to the function, reduced such that it is a member of the
/// field `Fr` where `r` is `SNARK_SCALAR_FIELD`.
///
/// @return result True if the proof verifies successfully, false otherwise.
/// @custom:reverts string If the proof elements are not < `PRIME_Q` or if the `input` is not
/// less than `SNARK_SCALAR_FIELD`.
function verifyProof(
uint256[2] memory a,
uint256[2][2] memory b,
uint256[2] memory c,
uint256[1] memory input
) external returns (bool result);
/// @notice Verify an uncompressed Groth16 proof.
/// @notice Reverts with InvalidProof if the proof is invalid or
/// with PublicInputNotInField the public input is not reduced.
/// @notice There is no return value. If the function does not revert, the
/// proof was succesfully verified.
/// @param proof the points (A, B, C) in EIP-197 format matching the output
/// of compressProof.
/// @param input the public input field elements in the scalar field Fr.
/// Elements must be reduced.
function verifyProof(
uint256[8] calldata proof,
uint256[1] calldata input
) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {WorldIDIdentityManagerTest} from "./WorldIDIdentityManagerTest.sol";
import {ITreeVerifier} from "../../interfaces/ITreeVerifier.sol";
import {SimpleVerifier, SimpleVerify} from "../mock/SimpleVerifier.sol";
import {TypeConverter as TC} from "../utils/TypeConverter.sol";
import {Verifier as TreeVerifier} from "../mock/InsertionTreeVerifier.sol";
import {Verifier as TreeVerifier} from "src/Verifier.sol";
import {VerifierLookupTable} from "../../data/VerifierLookupTable.sol";

import {WorldIDIdentityManager as IdentityManager} from "../../WorldIDIdentityManager.sol";
Expand Down
11 changes: 3 additions & 8 deletions src/test/mock/SimpleVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@ contract SimpleVerifier is ITreeVerifier {
}

function verifyProof(
uint256[2] memory a,
uint256[2][2] memory b,
uint256[2] memory c,
uint256[8] memory proof,
uint256[1] memory input
) external override returns (bool result) {
delete b;
delete c;
delete input;
result = a[0] % 2 == 0;
) external returns (bool result) {
result = proof[0] % 2 == 0;

if (result) {
emit VerifiedProof(batchSize);
Expand Down

0 comments on commit 730452f

Please sign in to comment.