diff --git a/contracts/interfaces/IVerifier.sol b/contracts/interfaces/IVerifier.sol index 0b60623a..a0ec107f 100644 --- a/contracts/interfaces/IVerifier.sol +++ b/contracts/interfaces/IVerifier.sol @@ -143,14 +143,14 @@ interface IVerifier { } /** - * @dev Query. Structure for query. - * @param queryId Query id. - * @param requestIds Request ids for this multi query (without groupId. Single requests). - * @param groupIds Group ids for this multi query (all the requests included in the group. Grouped requests). - * @param metadata Metadata for the query. Empty in first version. + * @dev MultiRequest. Structure for multiRequest. + * @param multiRequestId MultiRequest id. + * @param requestIds Request ids for this multi multiRequest (without groupId. Single requests). + * @param groupIds Group ids for this multi multiRequest (all the requests included in the group. Grouped requests). + * @param metadata Metadata for the multiRequest. Empty in first version. */ - struct Query { - uint256 queryId; + struct MultiRequest { + uint256 multiRequestId; uint256[] requestIds; uint256[] groupIds; bytes metadata; @@ -202,13 +202,13 @@ interface IVerifier { function requestIdExists(uint256 requestId) external view returns (bool); /** - * @dev Gets the status of the query verification - * @param queryId The ID of the query + * @dev Gets the status of the multiRequest verification + * @param multiRequestId The ID of the MultiRequest * @param userAddress The address of the user - * @return status The status of the query. "True" if all requests are verified, "false" otherwise + * @return status The status of the MultiRequest. "True" if all requests are verified, "false" otherwise */ - function getQueryStatus( - uint256 queryId, + function getMultiRequestStatus( + uint256 multiRequestId, address userAddress ) external view returns (AuthProofStatus[] memory, RequestProofStatus[] memory); @@ -239,17 +239,17 @@ interface IVerifier { function setAuthType(AuthType calldata authType) external; /** - * @dev Sets a query - * @param query The query data + * @dev Sets a multiRequest + * @param multiRequest The multiRequest data */ - function setQuery(Query calldata query) external; + function setMultiRequest(MultiRequest calldata multiRequest) external; /** - * @dev Gets a specific multi query by ID - * @param queryId The ID of the multi query - * @return query The query data + * @dev Gets a specific multiRequest by ID + * @param multiRequestId The ID of the multiRequest + * @return multiRequest The multiRequest data */ - function getQuery(uint256 queryId) external view returns (IVerifier.Query memory query); + function getMultiRequest(uint256 multiRequestId) external view returns (MultiRequest memory multiRequest); /** * @dev Get the proof status for the sender and request with requestId. diff --git a/contracts/verifiers/UniversalVerifier.sol b/contracts/verifiers/UniversalVerifier.sol index 340442ed..7ffe0404 100644 --- a/contracts/verifiers/UniversalVerifier.sol +++ b/contracts/verifiers/UniversalVerifier.sol @@ -61,14 +61,14 @@ contract UniversalVerifier is ); /** - * @dev Event emitted upon adding a query + * @dev Event emitted upon adding a multiRequest */ - event QuerySet(uint256 indexed queryId, uint256[] requestIds); + event MultiRequestSet(uint256 indexed multiRequestId, uint256[] requestIds); /** - * @dev Event emitted upon updating a query + * @dev Event emitted upon updating a multiRequest */ - event QueryUpdate(uint256 indexed queryId, uint256[] requestIds); + event MultiRequestUpdate(uint256 indexed multiRequestId, uint256[] requestIds); /// @dev Modifier to check if the caller is the contract Owner or ZKP Request Owner modifier onlyOwnerOrRequestOwner(uint256 requestId) { @@ -117,14 +117,14 @@ contract UniversalVerifier is } /** - * @dev Sets a query - * @param query The query data + * @dev Sets a multiRequest + * @param multiRequest The multiRequest data */ - function setQuery( - Query calldata query - ) public override checkQueryExistence(query.queryId, false) { - super.setQuery(query); - emit QuerySet(query.queryId, query.requestIds); + function setMultiRequest( + IVerifier.MultiRequest calldata multiRequest + ) public override checkMultiRequestExistence(multiRequest.multiRequestId, false) { + super.setMultiRequest(multiRequest); + emit MultiRequestSet(multiRequest.multiRequestId, multiRequest.requestIds); } /** diff --git a/contracts/verifiers/Verifier.sol b/contracts/verifiers/Verifier.sol index f36f30d4..9947597a 100644 --- a/contracts/verifiers/Verifier.sol +++ b/contracts/verifiers/Verifier.sol @@ -13,8 +13,8 @@ error RequestIdNotFound(uint256 requestId); error RequestAlreadyExists(uint256 requestId); error GroupIdNotFound(uint256 groupId); error GroupIdAlreadyExists(uint256 groupId); -error QueryIdNotFound(uint256 queryId); -error QueryIdAlreadyExists(uint256 queryId); +error MultiRequestIdNotFound(uint256 multiRequestId); +error MultiRequestIdAlreadyExists(uint256 multiRequestId); error AuthTypeNotFound(string authType); error AuthTypeAlreadyExists(string authType); error ValidatorNotWhitelisted(address validator); @@ -54,9 +54,9 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { mapping(uint256 groupId => uint256[] requestIds) _groupedRequests; uint256[] _groupIds; IState _state; - // Information about queries - mapping(uint256 queryId => Query) _queries; - uint256[] _queryIds; + // Information about multiRequests + mapping(uint256 multiRequestId => IVerifier.MultiRequest) _multiRequests; + uint256[] _multiRequestIds; // Information linked between users and their addresses mapping(address userAddress => uint256 userID) _user_address_to_id; mapping(uint256 userID => address userAddress) _id_to_user_address; @@ -115,16 +115,16 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { } /** - * @dev Modifier to check if the query exists + * @dev Modifier to check if the multiRequest exists */ - modifier checkQueryExistence(uint256 queryId, bool existence) { + modifier checkMultiRequestExistence(uint256 multiRequestId, bool existence) { if (existence) { - if (!queryIdExists(queryId)) { - revert QueryIdNotFound(queryId); + if (!multiRequestIdExists(multiRequestId)) { + revert MultiRequestIdNotFound(multiRequestId); } } else { - if (queryIdExists(queryId)) { - revert QueryIdAlreadyExists(queryId); + if (multiRequestIdExists(multiRequestId)) { + revert MultiRequestIdAlreadyExists(multiRequestId); } } _; @@ -186,12 +186,12 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { } /** - * @dev Checks if a query ID exists - * @param queryId The ID of the query - * @return Whether the query ID exists + * @dev Checks if a multiRequest ID exists + * @param multiRequestId The ID of the multiRequest + * @return Whether the multiRequest ID exists */ - function queryIdExists(uint256 queryId) public view returns (bool) { - return _getVerifierStorage()._queries[queryId].queryId == queryId; + function multiRequestIdExists(uint256 multiRequestId) public view returns (bool) { + return _getVerifierStorage()._multiRequests[multiRequestId].multiRequestId == multiRequestId; } /** @@ -287,33 +287,33 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { } /** - * @dev Sets a query - * @param query The query data + * @dev Sets a multiRequest + * @param multiRequest The multiRequest data */ - function setQuery( - IVerifier.Query calldata query - ) public virtual checkQueryExistence(query.queryId, false) { + function setMultiRequest( + IVerifier.MultiRequest calldata multiRequest + ) public virtual checkMultiRequestExistence(multiRequest.multiRequestId, false) { VerifierStorage storage s = _getVerifierStorage(); - s._queries[query.queryId] = query; - s._queryIds.push(query.queryId); + s._multiRequests[multiRequest.multiRequestId] = multiRequest; + s._multiRequestIds.push(multiRequest.multiRequestId); - // checks for all the requests in this query - _checkRequestsInQuery(query.queryId); + // checks for all the requests in this multiRequest + _checkRequestsInMultiRequest(multiRequest.multiRequestId); } /** - * @dev Gets a specific multi query by ID - * @param queryId The ID of the multi query - * @return query The query data + * @dev Gets a specific multiRequest by ID + * @param multiRequestId The ID of the multiRequest + * @return multiRequest The multiRequest data */ - function getQuery(uint256 queryId) public view returns (IVerifier.Query memory query) { - return _getVerifierStorage()._queries[queryId]; + function getMultiRequest(uint256 multiRequestId) public view returns (IVerifier.MultiRequest memory multiRequest) { + return _getVerifierStorage()._multiRequests[multiRequestId]; } - function _checkRequestsInQuery(uint256 queryId) internal view { + function _checkRequestsInMultiRequest(uint256 multiRequestId) internal view { VerifierStorage storage s = _getVerifierStorage(); - uint256[] memory requestIds = s._queries[queryId].requestIds; + uint256[] memory requestIds = s._multiRequests[multiRequestId].requestIds; // check that all the single requests doesn't have group for (uint256 i = 0; i < requestIds.length; i++) { @@ -558,11 +558,11 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { return s._authProofs[authType][userID][0].storageFields[responseFieldName]; } - function _checkLinkedResponseFields(uint256 queryId, uint256 userID) internal view { + function _checkLinkedResponseFields(uint256 multiRequestId, uint256 userID) internal view { VerifierStorage storage s = _getVerifierStorage(); - for (uint256 i = 0; i < s._queries[queryId].groupIds.length; i++) { - uint256 groupId = s._queries[queryId].groupIds[i]; + for (uint256 i = 0; i < s._multiRequests[multiRequestId].groupIds.length; i++) { + uint256 groupId = s._multiRequests[multiRequestId].groupIds[i]; // Check linkID in the same group or requests is the same uint256 requestLinkID = getResponseFieldValue( @@ -587,18 +587,18 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { } /** - * @dev Gets the status of the query verification - * @param queryId The ID of the query + * @dev Gets the status of the multiRequest verification + * @param multiRequestId The ID of the multiRequest * @param userAddress The address of the user - * @return status The status of the query. "True" if all requests are verified, "false" otherwise + * @return status The status of the multiRequest. "True" if all requests are verified, "false" otherwise */ - function getQueryStatus( - uint256 queryId, + function getMultiRequestStatus( + uint256 multiRequestId, address userAddress ) public view - checkQueryExistence(queryId, true) + checkMultiRequestExistence(multiRequestId, true) returns (IVerifier.AuthProofStatus[] memory, IVerifier.RequestProofStatus[] memory) { VerifierStorage storage s = _getVerifierStorage(); @@ -613,29 +613,29 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { ( IVerifier.AuthProofStatus[] memory authProofStatus, IVerifier.RequestProofStatus[] memory requestProofStatus - ) = _getQueryStatus(queryId, userID); + ) = _getMultiRequestStatus(multiRequestId, userID); // 3. Check if all linked response fields are the same - _checkLinkedResponseFields(queryId, userID); + _checkLinkedResponseFields(multiRequestId, userID); return (authProofStatus, requestProofStatus); } /** - * @dev Gets the status of the query verification - * @param queryId The ID of the query + * @dev Gets the status of the multiRequest verification + * @param multiRequestId The ID of the multiRequest * @param userAddress The address of the user * @param userID The user id of the user - * @return status The status of the query. "True" if all requests are verified, "false" otherwise + * @return status The status of the multiRequest. "True" if all requests are verified, "false" otherwise */ - function getQueryStatus( - uint256 queryId, + function getMultiRequestStatus( + uint256 multiRequestId, address userAddress, uint256 userID ) public view - checkQueryExistence(queryId, true) + checkMultiRequestExistence(multiRequestId, true) returns (IVerifier.AuthProofStatus[] memory, IVerifier.RequestProofStatus[] memory) { VerifierStorage storage s = _getVerifierStorage(); @@ -658,16 +658,16 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { ( IVerifier.AuthProofStatus[] memory authProofStatus, IVerifier.RequestProofStatus[] memory requestProofStatus - ) = _getQueryStatus(queryId, userIDSelected); + ) = _getMultiRequestStatus(multiRequestId, userIDSelected); // 3. Check if all linked response fields are the same - _checkLinkedResponseFields(queryId, userIDSelected); + _checkLinkedResponseFields(multiRequestId, userIDSelected); return (authProofStatus, requestProofStatus); } - function _getQueryStatus( - uint256 queryId, + function _getMultiRequestStatus( + uint256 multiRequestId, uint256 userID ) internal @@ -675,13 +675,13 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { returns (IVerifier.AuthProofStatus[] memory, IVerifier.RequestProofStatus[] memory) { VerifierStorage storage s = _getVerifierStorage(); - Query storage query = s._queries[queryId]; + IVerifier.MultiRequest storage multiRequest = s._multiRequests[multiRequestId]; uint256 lengthGroupIds; - if (query.groupIds.length > 0) { - for (uint256 i = 0; i < query.groupIds.length; i++) { - uint256 groupId = query.groupIds[i]; + if (multiRequest.groupIds.length > 0) { + for (uint256 i = 0; i < multiRequest.groupIds.length; i++) { + uint256 groupId = multiRequest.groupIds[i]; lengthGroupIds += s._groupedRequests[groupId].length; } } @@ -691,7 +691,7 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { ); IVerifier.RequestProofStatus[] memory requestProofStatus = new IVerifier.RequestProofStatus[]( - query.requestIds.length + lengthGroupIds + multiRequest.requestIds.length + lengthGroupIds ); for (uint256 i = 0; i < s._authTypes.length; i++) { @@ -704,8 +704,8 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { }); } - for (uint256 i = 0; i < query.requestIds.length; i++) { - uint256 requestId = query.requestIds[i]; + for (uint256 i = 0; i < multiRequest.requestIds.length; i++) { + uint256 requestId = multiRequest.requestIds[i]; requestProofStatus[i] = IVerifier.RequestProofStatus({ requestId: requestId, @@ -715,13 +715,13 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { }); } - for (uint256 i = 0; i < query.groupIds.length; i++) { - uint256 groupId = query.groupIds[i]; + for (uint256 i = 0; i < multiRequest.groupIds.length; i++) { + uint256 groupId = multiRequest.groupIds[i]; for (uint256 j = 0; j < s._groupedRequests[groupId].length; j++) { uint256 requestId = s._groupedRequests[groupId][j]; - requestProofStatus[query.requestIds.length + j] = IVerifier.RequestProofStatus({ + requestProofStatus[multiRequest.requestIds.length + j] = IVerifier.RequestProofStatus({ requestId: requestId, isVerified: s._proofs[requestId][userID][0].isVerified, validatorVersion: s._proofs[requestId][userID][0].validatorVersion, diff --git a/test/verifier/universal-verifier-multi-query.test.ts b/test/verifier/universal-verifier-multi-query.test.ts index 6c315f7c..0c26d3f8 100644 --- a/test/verifier/universal-verifier-multi-query.test.ts +++ b/test/verifier/universal-verifier-multi-query.test.ts @@ -9,9 +9,8 @@ import { buildCrossChainProofs, packCrossChainProofs, packZKProof } from "../uti import { CircuitId } from "@0xpolygonid/js-sdk"; import { loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers"; import { calculateQueryHashV3 } from "../utils/query-hash-utils"; -import { request } from "http"; -describe("Universal Verifier Multi-query", function () { +describe("Universal Verifier Multi-request", function () { let verifier: any, v3Validator: any, authV2Validator: any, v3_2Validator: any; let signer; let signerAddress: string; @@ -180,10 +179,10 @@ describe("Universal Verifier Multi-query", function () { await loadFixture(deployContractsFixture); }); - it("Test submit response multiquery without groupID", async () => { + it("Test submit response multi-request without groupID", async () => { const requestId = 1; - const queryId = 1; - const nonExistingQueryId = 5; + const multiRequestId = 1; + const nonExistingMultiRequestId = 5; const userId = 1; const userId2 = 2; const authType = "authV2"; @@ -221,17 +220,17 @@ describe("Universal Verifier Multi-query", function () { expect(authRequestStored.params).to.be.equal(params); expect(authRequestStored.isActive).to.be.equal(true); - const query = { - queryId, + const multiRequest = { + multiRequestId, requestIds: [requestId], groupIds: [], metadata: "0x", }; - const txSetQuery = await verifier.setQuery(query); - await txSetQuery.wait(); - const queryStored = await verifier.getQuery(queryId); - expect(queryStored.queryId).to.be.equal(queryId); - expect(queryStored.requestIds).to.be.deep.equal(query.requestIds); + const txSetMultiRequest = await verifier.setMultiRequest(multiRequest); + await txSetMultiRequest.wait(); + const multiRequestStored = await verifier.getMultiRequest(multiRequestId); + expect(multiRequestStored.multiRequestId).to.be.equal(multiRequestId); + expect(multiRequestStored.requestIds).to.be.deep.equal(multiRequest.requestIds); const { inputs, pi_a, pi_b, pi_c } = prepareInputs(proofJson); @@ -282,11 +281,11 @@ describe("Universal Verifier Multi-query", function () { expect(events[0].args.requestId).to.be.equal(requestId); expect(events[0].args.caller).to.be.equal(signerAddress); - await expect(verifier.getQueryStatus(nonExistingQueryId, signerAddress)).to.be.rejectedWith( - `QueryIdNotFound(${nonExistingQueryId})`, - ); + await expect( + verifier.getMultiRequestStatus(nonExistingMultiRequestId, signerAddress), + ).to.be.rejectedWith(`MultiRequestIdNotFound(${nonExistingMultiRequestId})`); - const status = await verifier.getQueryStatus(queryId, signerAddress); + const status = await verifier.getMultiRequestStatus(multiRequestId, signerAddress); expect(status[0][0].authType).to.be.equal(authType); expect(status[0][0].isVerified).to.be.equal(true); // auth type isVerified expect(status[1][0].requestId).to.be.equal(requestId); @@ -298,13 +297,13 @@ describe("Universal Verifier Multi-query", function () { expect(requestStored.isVerifierAuthenticated).to.be.equal(true); }); - it("Test submit response multiquery with same groupID and linkID", async () => { + it("Test submit response multi-request with same groupID and linkID", async () => { const requestId2 = 2; const requestId3 = 3; const groupId = 1; const authType = "authV2"; - const queryId = 1; - const nonExistingQueryId = 5; + const multiRequestId = 1; + const nonExistingMultiRequestId = 5; const userId = 1; const authParams = "0x"; const paramsRequest2 = packV3ValidatorParams(requestQuery2); @@ -353,18 +352,18 @@ describe("Universal Verifier Multi-query", function () { expect(authRequestStored.params).to.be.equal(authParams); expect(authRequestStored.isActive).to.be.equal(true); - const query = { - queryId, + const multiRequest = { + multiRequestId, requestIds: [], groupIds: [groupId], metadata: "0x", }; - const txSetQuery = await verifier.setQuery(query); - await txSetQuery.wait(); + const txSetMultiRequest = await verifier.setMultiRequest(multiRequest); + await txSetMultiRequest.wait(); - const queryStored = await verifier.getQuery(queryId); - expect(queryStored[0]).to.be.equal(queryId); - expect(queryStored[1]).to.be.deep.equal(query.requestIds); + const multiRequestStored = await verifier.getMultiRequest(multiRequestId); + expect(multiRequestStored[0]).to.be.equal(multiRequestId); + expect(multiRequestStored[1]).to.be.deep.equal(multiRequest.requestIds); const { inputs, pi_a, pi_b, pi_c } = prepareInputs(proofJson); @@ -414,10 +413,10 @@ describe("Universal Verifier Multi-query", function () { expect(events[0].args.requestId).to.be.equal(requestId2); expect(events[0].args.caller).to.be.equal(signerAddress); - await expect(verifier.getQueryStatus(nonExistingQueryId, signerAddress)).to.be.rejectedWith( - `QueryIdNotFound(${nonExistingQueryId})`, - ); - const status = await verifier.getQueryStatus(queryId, signerAddress); + await expect( + verifier.getMultiRequestStatus(nonExistingMultiRequestId, signerAddress), + ).to.be.rejectedWith(`MultiRequestIdNotFound(${nonExistingMultiRequestId})`); + const status = await verifier.getMultiRequestStatus(multiRequestId, signerAddress); expect(status[0][0].authType).to.be.equal(authType); expect(status[0][0].isVerified).to.be.equal(true); // auth type isVerified expect(status[1][0].requestId).to.be.equal(requestId2); @@ -426,12 +425,12 @@ describe("Universal Verifier Multi-query", function () { expect(status[1][1].isVerified).to.be.equal(true); // requestId3 isVerified }); - it("Test submit response multiquery with same groupID and different linkID", async () => { + it("Test submit response multi-request with same groupID and different linkID", async () => { const requestId2 = 2; const requestId3 = 3; const groupId = 1; const authType = "authV2"; - const queryId = 1; + const multiRequestId = 1; const authParams = "0x"; const paramsRequest2 = packV3ValidatorParams(requestQuery2); const paramsRequest3 = packV3ValidatorParams(requestQuery3); @@ -466,14 +465,14 @@ describe("Universal Verifier Multi-query", function () { params: authParams, }); - const query = { - queryId, + const multiRequest = { + multiRequestId, requestIds: [], groupIds: [groupId], metadata: "0x", }; - const txSetQuery = await verifier.setQuery(query); - await txSetQuery.wait(); + const txSetMultiRequest = await verifier.setMultiRequest(multiRequest); + await txSetMultiRequest.wait(); const { inputs, pi_a, pi_b, pi_c } = prepareInputs(proofJson); @@ -508,7 +507,7 @@ describe("Universal Verifier Multi-query", function () { ); await tx.wait(); - await expect(verifier.getQueryStatus(queryId, signerAddress)).to.be.rejectedWith( + await expect(verifier.getMultiRequestStatus(multiRequestId, signerAddress)).to.be.rejectedWith( "LinkIDNotTheSameForGroupedRequests(3, 4)", ); });