Skip to content

Commit

Permalink
Linked proofs verifier (#217)
Browse files Browse the repository at this point in the history
* Linked proofs verifier
  • Loading branch information
Dimasik Kolezhniuk authored Mar 15, 2024
1 parent bb0bef4 commit 6e0d1c5
Show file tree
Hide file tree
Showing 5 changed files with 692 additions and 19 deletions.
42 changes: 42 additions & 0 deletions contracts/verifiers/UniversalVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ contract UniversalVerifier is Ownable2StepUpgradeable, IUniversalVerifier {

uint256 constant REQUESTS_RETURN_LIMIT = 1000;

/// @dev Key to retrieve the linkID from the proof storage
string constant LINKED_PROOF_KEY = "linkID";

/// @dev Linked proof custom error
error LinkedProofError(
string message,
uint64 requestId,
uint256 linkID,
uint64 requestIdToCompare,
uint256 linkIdToCompare
);

// keccak256(abi.encode(uint256(keccak256("iden3.storage.UniversalVerifier")) - 1)) & ~bytes32(uint256(0xff));
bytes32 private constant UNIVERSAL_VERIFIER_STORAGE_LOCATION =
0x0c87ac878172a541d6ba539a4e02bbe44e1f3a504bea30ed92c32fb1517db700;
Expand Down Expand Up @@ -327,4 +339,34 @@ contract UniversalVerifier is Ownable2StepUpgradeable, IUniversalVerifier {
) public view returns (uint256) {
return _getMainStorage().proofs[user][requestId].storageFields[key];
}

/// @notice Gets the list of request IDs and verifies the proofs are linked
/// @param sender the user's address
/// @param requestIds the list of request IDs
/// Throws if the proofs are not linked
function verifyLinkedProofs(address sender, uint64[] calldata requestIds) public view {
require(requestIds.length > 1, "Linked proof verification needs more than 1 request");
mapping(uint64 => Proof) storage proofs = _getMainStorage().proofs[sender];
Proof storage firstProof = proofs[requestIds[0]];
uint256 expectedLinkID = firstProof.storageFields[LINKED_PROOF_KEY];

if (expectedLinkID == 0) {
revert("Can't find linkID for given request Ids and user address");
}

for (uint256 i = 1; i < requestIds.length; i++) {
Proof storage proof = proofs[requestIds[i]];
uint256 actualLinkID = proof.storageFields[LINKED_PROOF_KEY];

if (expectedLinkID != actualLinkID) {
revert LinkedProofError(
"Proofs are not linked",
requestIds[0],
expectedLinkID,
requestIds[i],
actualLinkID
);
}
}
}
}
Loading

0 comments on commit 6e0d1c5

Please sign in to comment.