Skip to content

Commit

Permalink
fixed compliation errors resulting from verifier interface change
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKitsune committed Sep 13, 2023
1 parent 730452f commit 07a4b34
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 74 deletions.
24 changes: 4 additions & 20 deletions src/WorldIDIdentityManagerImplV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -391,16 +391,9 @@ contract WorldIDIdentityManagerImplV1 is WorldIDImpl, IWorldID {

// With that, we can properly try and verify.
try insertionVerifier.verifyProof(
[insertionProof[0], insertionProof[1]],
[[insertionProof[2], insertionProof[3]], [insertionProof[4], insertionProof[5]]],
[insertionProof[6], insertionProof[7]],
insertionProof,
[reducedElement]
) returns (bool verifierResult) {
// If the proof did not verify, we revert with a failure.
if (!verifierResult) {
revert ProofValidationFailure();
}

) {
// If it did verify, we need to update the contract's state. We set the currently valid
// root to the root after the insertions.
_latestRoot = postRoot;
Expand Down Expand Up @@ -534,20 +527,11 @@ contract WorldIDIdentityManagerImplV1 is WorldIDImpl, IWorldID {
uint256 preRoot,
uint256 postRoot
) internal virtual onlyProxy onlyInitialized onlyIdentityOperator {
// Pull out the proof terms and verifier input.
uint256[2] memory ar = [updateProof[0], updateProof[1]];
uint256[2][2] memory bs =
[[updateProof[2], updateProof[3]], [updateProof[4], updateProof[5]]];
uint256[2] memory krs = [updateProof[6], updateProof[7]];
// Pull out the verifier input.
uint256[1] memory proofInput = [inputHash];

// Now it's possible to verify the proof.
try updateVerifier.verifyProof(ar, bs, krs, proofInput) returns (bool verifierResult) {
// If the proof did not verify, we revert with a failure.
if (!verifierResult) {
revert ProofValidationFailure();
}

try updateVerifier.verifyProof(updateProof, proofInput) {
// If it did verify, we need to update the contract's state. We set the currently valid
// root to the root after the insertions.
_latestRoot = postRoot;
Expand Down
11 changes: 2 additions & 9 deletions src/WorldIDIdentityManagerImplV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,9 @@ contract WorldIDIdentityManagerImplV2 is WorldIDIdentityManagerImplV1 {

// With that, we can properly try and verify.
try deletionVerifier.verifyProof(
[deletionProof[0], deletionProof[1]],
[[deletionProof[2], deletionProof[3]], [deletionProof[4], deletionProof[5]]],
[deletionProof[6], deletionProof[7]],
deletionProof,
[reducedElement]
) returns (bool verifierResult) {
// If the proof did not verify, we revert with a failure.
if (!verifierResult) {
revert ProofValidationFailure();
}

) {
// If it did verify, we need to update the contract's state. We set the currently valid
// root to the root after the insertions.
_latestRoot = postRoot;
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/ITreeVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface ITreeVerifier {
/// of compressProof.
/// @param input the public input field elements in the scalar field Fr.
/// Elements must be reduced.
function verifyProof(
function verifyProof(
uint256[8] calldata proof,
uint256[1] calldata input
) external;
Expand Down
20 changes: 10 additions & 10 deletions src/test/mock/DeletionTreeVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ contract Verifier is ITreeVerifier {
* above and the public inputs
*/
function verifyProof(
uint256[2] memory a,
uint256[2][2] memory b,
uint256[2] memory c,
uint256[1] calldata input
) public view returns (bool r) {
uint256[8] memory _proof,
uint256[1] memory input
) public view {
Proof memory proof;
proof.A = Pairing.G1Point(a[0], a[1]);
proof.B = Pairing.G2Point([b[0][0], b[0][1]], [b[1][0], b[1][1]]);
proof.C = Pairing.G1Point(c[0], c[1]);

//TODO: going to need to double check the order of nested b
proof.A = Pairing.G1Point(_proof[0], _proof[1]);
proof.B = Pairing.G2Point([_proof[2], _proof[3]], [_proof[4], _proof[5]]);
proof.C = Pairing.G1Point(_proof[6], _proof[7]);

// Make sure that proof.A, B, and C are each less than the prime q
require(proof.A.X < PRIME_Q, "verifier-aX-gte-prime-q");
Expand Down Expand Up @@ -321,7 +321,7 @@ contract Verifier is ITreeVerifier {
mul_input[2] = input[0];
accumulate(mul_input, q, add_input, vk_x); // vk_x += vk.K[1] * input[0]

return Pairing.pairing(
require(Pairing.pairing(
Pairing.negate(proof.A),
proof.B,
vk.alfa1,
Expand All @@ -330,6 +330,6 @@ contract Verifier is ITreeVerifier {
vk.gamma2,
proof.C,
vk.delta2
);
), "Invalid proof");
}
}
18 changes: 9 additions & 9 deletions src/test/mock/InsertionTreeVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ contract Verifier is ITreeVerifier {
* above and the public inputs
*/
function verifyProof(
uint256[2] memory a,
uint256[2][2] memory b,
uint256[2] memory c,
uint256[8] memory _proof,
uint256[1] memory input
) public view returns (bool r) {
) public view {
Proof memory proof;
proof.A = Pairing.G1Point(a[0], a[1]);
proof.B = Pairing.G2Point([b[0][0], b[0][1]], [b[1][0], b[1][1]]);
proof.C = Pairing.G1Point(c[0], c[1]);

//TODO: going to need to double check the order of nested b
proof.A = Pairing.G1Point(_proof[0], _proof[1]);
proof.B = Pairing.G2Point([_proof[2], _proof[3]], [_proof[4], _proof[5]]);
proof.C = Pairing.G1Point(_proof[6], _proof[7]);

VerifyingKey memory vk = verifyingKey();

Expand Down Expand Up @@ -253,7 +253,7 @@ contract Verifier is ITreeVerifier {

vk_x = Pairing.plus(vk_x, vk.IC[0]);

return Pairing.pairing(
require(Pairing.pairing(
Pairing.negate(proof.A),
proof.B,
vk.alfa1,
Expand All @@ -262,6 +262,6 @@ contract Verifier is ITreeVerifier {
vk.gamma2,
proof.C,
vk.delta2
);
), "Invalid proof");
}
}
10 changes: 3 additions & 7 deletions src/test/mock/SequencerVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ contract SequencerVerifier is ITreeVerifier {
21888242871839275222246405745257275088548364400416034343698204186575808495617;

function verifyProof(
uint256[2] memory a,
uint256[2][2] memory b,
uint256[2] memory c,
uint256[8] memory proof,
uint256[1] memory input
) external pure override returns (bool) {
delete b;
delete c;
return a[0] % 2 == 0 && a[1] % SNARK_SCALAR_FIELD == input[0];
) external {
require(proof[0] % 2 == 0 && proof[1] % SNARK_SCALAR_FIELD == input[0], "Invalid Proof");
}
}
4 changes: 2 additions & 2 deletions src/test/mock/SimpleVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ contract SimpleVerifier is ITreeVerifier {
function verifyProof(
uint256[8] memory proof,
uint256[1] memory input
) external returns (bool result) {
result = proof[0] % 2 == 0;
) external {
bool result = proof[0] % 2 == 0;

if (result) {
emit VerifiedProof(batchSize);
Expand Down
28 changes: 12 additions & 16 deletions src/utils/UnimplementedTreeVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,21 @@ contract UnimplementedTreeVerifier is ITreeVerifier {
/// @notice Thrown when an operation is not supported.
error UnsupportedOperation();

/// @notice Verifies the provided proof data for the provided public inputs.
/// @dev Exists to satisfy the interface. Will always revert.
///
/// @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`.
///
/// @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.
/// @custom:reverts UnsupportedOperation When called.
function verifyProof(
uint256[2] memory a,
uint256[2][2] memory b,
uint256[2] memory c,
uint256[8] memory proof,
uint256[1] memory input
) external pure returns (bool) {
delete a;
delete b;
delete c;
) external pure {
delete proof;
delete input;
revert UnsupportedOperation();
}
Expand Down

0 comments on commit 07a4b34

Please sign in to comment.