diff --git a/contracts/interfaces/IAuthValidator.sol b/contracts/interfaces/IAuthValidator.sol index 8578b07f..b69b94be 100644 --- a/contracts/interfaces/IAuthValidator.sol +++ b/contracts/interfaces/IAuthValidator.sol @@ -26,14 +26,14 @@ interface IAuthValidator { * @dev Verify the proof with the supported method informed in the auth query data * packed as bytes and that the proof was generated by the sender. * @param proof Proof packed as bytes to verify. - * @param data Request query data of the credential to verify. + * @param params Request query data of the credential to verify. * @param sender Sender of the proof. * @param state State contract to get identities and gist states to check. * @return Array of response fields as result. */ function verify( bytes calldata proof, - bytes calldata data, + bytes calldata params, address sender, IState state ) external returns (ResponseField[] memory); diff --git a/contracts/interfaces/IRequestValidator.sol b/contracts/interfaces/IRequestValidator.sol index 70effc38..a7292f71 100644 --- a/contracts/interfaces/IRequestValidator.sol +++ b/contracts/interfaces/IRequestValidator.sol @@ -17,6 +17,16 @@ interface IRequestValidator { uint256 value; } + /** + * @dev RequestParams. Information about request params from request query data. + * @param groupID Group ID of the request query params + * @param verifierID Verifier ID of the request query params + */ + struct RequestParams { + uint256 groupID; + uint256 verifierID; + } + /** * @dev Get version of the contract */ @@ -26,29 +36,22 @@ interface IRequestValidator { * @dev Verify the proof with the supported method informed in the request query data * packed as bytes and that the proof was generated by the sender. * @param proof Proof packed as bytes to verify. - * @param data Request query data of the credential to verify. + * @param params Request query data of the credential to verify. * @param sender Sender of the proof. * @param state State contract to get identities and gist states to check. * @return Array of response fields as result. */ function verify( bytes calldata proof, - bytes calldata data, + bytes calldata params, address sender, IState state ) external returns (ResponseField[] memory); /** - * @dev Get the group ID of the request query data. + * @dev Get the request params of the request query data. * @param params Request query data of the credential to verify. * @return Group ID of the request query data. */ - function getGroupID(bytes calldata params) external view returns (uint256); - - /** - * @dev Get the verifier ID of the request query data. - * @param params Request query data of the credential to verify. - * @return Verifier ID encoded in the request query data. - */ - function getVerifierId(bytes calldata params) external view returns (uint256); + function getRequestParams(bytes calldata params) external view returns (RequestParams memory); } diff --git a/contracts/interfaces/IVerifier.sol b/contracts/interfaces/IVerifier.sol index c5fafe71..0b60623a 100644 --- a/contracts/interfaces/IVerifier.sol +++ b/contracts/interfaces/IVerifier.sol @@ -240,10 +240,9 @@ interface IVerifier { /** * @dev Sets a query - * @param queryId The ID of the query * @param query The query data */ - function setQuery(uint256 queryId, Query calldata query) external; + function setQuery(Query calldata query) external; /** * @dev Gets a specific multi query by ID diff --git a/contracts/lib/VerifierLib.sol b/contracts/lib/VerifierLib.sol index 20af4992..1b291077 100644 --- a/contracts/lib/VerifierLib.sol +++ b/contracts/lib/VerifierLib.sol @@ -20,10 +20,9 @@ library VerifierLib { // TODO: discuss if we need this field // uint256 blockNumber; uint256 blockTimestamp; - mapping(string key => bytes) metadata; // This empty reserved space is put in place to allow future versions // (see https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#storage-gaps) - uint256[45] __gap; + uint256[46] __gap; } /** diff --git a/contracts/test-helpers/RequestValidatorAuthV2Stub.sol b/contracts/test-helpers/RequestValidatorAuthV2Stub.sol index 51820f44..64ad9e69 100644 --- a/contracts/test-helpers/RequestValidatorAuthV2Stub.sol +++ b/contracts/test-helpers/RequestValidatorAuthV2Stub.sol @@ -33,11 +33,7 @@ contract RequestValidatorAuthV2Stub is IRequestValidator, ERC165 { return signals; } - function getGroupID(bytes calldata) external pure override returns (uint256) { - return 0; - } - - function getVerifierId(bytes calldata) external pure override returns (uint256) { - return 0; + function getRequestParams(bytes calldata) external pure override returns (IRequestValidator.RequestParams memory) { + return IRequestValidator.RequestParams({ groupID: 0, verifierID: 0 }); } } diff --git a/contracts/test-helpers/RequestValidatorV2Stub.sol b/contracts/test-helpers/RequestValidatorV2Stub.sol index 66b79081..549f1077 100644 --- a/contracts/test-helpers/RequestValidatorV2Stub.sol +++ b/contracts/test-helpers/RequestValidatorV2Stub.sol @@ -35,11 +35,7 @@ contract RequestValidatorV2Stub is IRequestValidator, ERC165 { return signals; } - function getGroupID(bytes calldata) external pure override returns (uint256) { - return 0; - } - - function getVerifierId(bytes calldata) external pure override returns (uint256) { - return 0; + function getRequestParams(bytes calldata) external pure override returns (IRequestValidator.RequestParams memory) { + return IRequestValidator.RequestParams({ groupID: 0, verifierID: 0 }); } } diff --git a/contracts/test-helpers/RequestValidatorV3Stub.sol b/contracts/test-helpers/RequestValidatorV3Stub.sol index e3f4c73c..71048ba7 100644 --- a/contracts/test-helpers/RequestValidatorV3Stub.sol +++ b/contracts/test-helpers/RequestValidatorV3Stub.sol @@ -53,19 +53,11 @@ contract RequestValidatorV3Stub is IRequestValidator, ERC165 { return signals; } - function getGroupID(bytes calldata params) external pure override returns (uint256) { + function getRequestParams(bytes calldata params) external pure override returns (IRequestValidator.RequestParams memory) { CredentialAtomicQueryV3 memory credAtomicQuery = abi.decode( params, (CredentialAtomicQueryV3) ); - return credAtomicQuery.groupID; - } - - function getVerifierId(bytes calldata params) external pure override returns (uint256) { - CredentialAtomicQueryV3 memory credAtomicQuery = abi.decode( - params, - (CredentialAtomicQueryV3) - ); - return credAtomicQuery.verifierID; - } + return IRequestValidator.RequestParams({ groupID: credAtomicQuery.groupID, verifierID: credAtomicQuery.verifierID }); + } } diff --git a/contracts/test-helpers/RequestValidatorV3_2Stub.sol b/contracts/test-helpers/RequestValidatorV3_2Stub.sol index 13b3b7f2..4140e913 100644 --- a/contracts/test-helpers/RequestValidatorV3_2Stub.sol +++ b/contracts/test-helpers/RequestValidatorV3_2Stub.sol @@ -53,19 +53,11 @@ contract RequestValidatorV3_2Stub is IRequestValidator, ERC165 { return signals; } - function getGroupID(bytes calldata params) external pure override returns (uint256) { + function getRequestParams(bytes calldata params) external pure override returns (IRequestValidator.RequestParams memory) { CredentialAtomicQueryV3 memory credAtomicQuery = abi.decode( params, (CredentialAtomicQueryV3) ); - return credAtomicQuery.groupID; - } - - function getVerifierId(bytes calldata params) external pure override returns (uint256) { - CredentialAtomicQueryV3 memory credAtomicQuery = abi.decode( - params, - (CredentialAtomicQueryV3) - ); - return credAtomicQuery.verifierID; + return IRequestValidator.RequestParams({ groupID: credAtomicQuery.groupID, verifierID: credAtomicQuery.verifierID }); } } diff --git a/contracts/validators/AuthV2Validator.sol b/contracts/validators/AuthV2Validator.sol index 3ca40325..0fef4671 100644 --- a/contracts/validators/AuthV2Validator.sol +++ b/contracts/validators/AuthV2Validator.sol @@ -65,22 +65,8 @@ contract AuthV2Validator is CredentialAtomicQueryValidatorBase { return pubSignals; } - /** - * @dev Get the group ID of the request query data. - * @param params Request query data of the credential to verify. - * @return Group ID of the request query data. - */ - function getGroupID(bytes calldata params) external pure override returns (uint256) { - return 0; - } - - /** - * @dev Get the verifier ID from the request query data - * @param params Request query data of the credential to verify. - * @return Verifier ID - */ - function getVerifierId(bytes calldata params) external pure override returns (uint256) { - return 0; + function getRequestParams(bytes calldata) external pure override returns (IRequestValidator.RequestParams memory) { + return IRequestValidator.RequestParams({ groupID: 0, verifierID: 0 }); } /** diff --git a/contracts/validators/CredentialAtomicQueryV2ValidatorBase.sol b/contracts/validators/CredentialAtomicQueryV2ValidatorBase.sol index 779afe8d..800f69dd 100644 --- a/contracts/validators/CredentialAtomicQueryV2ValidatorBase.sol +++ b/contracts/validators/CredentialAtomicQueryV2ValidatorBase.sol @@ -82,22 +82,8 @@ abstract contract CredentialAtomicQueryV2ValidatorBase is CredentialAtomicQueryV return _getResponseFields(pubSignals); } - /** - * @dev Get the group ID of the request query data. - * @param params Request query data of the credential to verify. - * @return Group ID of the request query data. - */ - function getGroupID(bytes calldata params) external pure override returns (uint256) { - return 0; - } - - /** - * @dev Get the verifier ID from the request query data - * @param params Request query data of the credential to verify. - * @return Verifier ID - */ - function getVerifierId(bytes calldata params) external pure override returns (uint256) { - return 0; + function getRequestParams(bytes calldata) external pure override returns (IRequestValidator.RequestParams memory) { + return IRequestValidator.RequestParams({ groupID: 0, verifierID: 0 }); } /** diff --git a/contracts/validators/CredentialAtomicQueryV3Validator.sol b/contracts/validators/CredentialAtomicQueryV3Validator.sol index 1f1905d5..6dac4c13 100644 --- a/contracts/validators/CredentialAtomicQueryV3Validator.sol +++ b/contracts/validators/CredentialAtomicQueryV3Validator.sol @@ -147,32 +147,14 @@ contract CredentialAtomicQueryV3Validator is CredentialAtomicQueryValidatorBase return _getResponseFields(pubSignals, hasSD); } - /** - * @dev Get the group ID of the request query data. - * @param params Request query data of the credential to verify. - * @return Group ID of the request query data. - */ - function getGroupID(bytes calldata params) external pure override returns (uint256) { + function getRequestParams(bytes calldata params) external pure override returns (IRequestValidator.RequestParams memory) { CredentialAtomicQueryV3 memory credAtomicQuery = abi.decode( params, (CredentialAtomicQueryV3) ); - return credAtomicQuery.groupID; + return IRequestValidator.RequestParams({ groupID: credAtomicQuery.groupID, verifierID: credAtomicQuery.verifierID }); } - - /** - * @dev Get the verifier ID from the request query data - * @param params Request query data of the credential to verify. - * @return Verifier ID - */ - function getVerifierId(bytes calldata params) external pure override returns (uint256) { - CredentialAtomicQueryV3 memory credAtomicQuery = abi.decode( - params, - (CredentialAtomicQueryV3) - ); - return credAtomicQuery.verifierID; - } - + /** * @dev Verify the groth16 proof and check the request query data * @param inputs Public inputs of the circuit. diff --git a/contracts/validators/EthIdentityValidator.sol b/contracts/validators/EthIdentityValidator.sol index 737c8ba0..a79a483d 100644 --- a/contracts/validators/EthIdentityValidator.sol +++ b/contracts/validators/EthIdentityValidator.sol @@ -100,17 +100,8 @@ contract EthIdentityValidator is Ownable2StepUpgradeable, IRequestValidator, ERC require(calcId == id, "Sender is not owner of the ethereum identity"); } - function getGroupID(bytes calldata) external pure override returns (uint256) { - // TODO: Implement group ID - return 0; - } - - /** - * @dev Get the verifier ID of the request query data. - * @param params Request query data of the credential to verify. - * @return Verifier ID encoded in the request query data. - */ - function getVerifierId(bytes calldata params) external view returns (uint256) { - return 0; + function getRequestParams(bytes calldata) external pure override returns (IRequestValidator.RequestParams memory) { + return IRequestValidator.RequestParams({ groupID: 0, verifierID: 0 }); } + } diff --git a/contracts/verifiers/UniversalVerifier.sol b/contracts/verifiers/UniversalVerifier.sol index 97a9abe3..65407786 100644 --- a/contracts/verifiers/UniversalVerifier.sol +++ b/contracts/verifiers/UniversalVerifier.sol @@ -152,15 +152,13 @@ contract UniversalVerifier is /** * @dev Sets a query - * @param queryId The ID of the query * @param query The query data */ function setQuery( - uint256 queryId, Query calldata query - ) public override checkQueryExistence(queryId, false) { - super.setQuery(queryId, query); - emit QuerySet(queryId, query.requestIds); + ) public override checkQueryExistence(query.queryId, false) { + super.setQuery(query); + emit QuerySet(query.queryId, query.requestIds); } /** diff --git a/contracts/verifiers/Verifier.sol b/contracts/verifiers/Verifier.sol index 3eb71f3d..58f3fdef 100644 --- a/contracts/verifiers/Verifier.sol +++ b/contracts/verifiers/Verifier.sol @@ -97,16 +97,16 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { * @dev Modifier to check if the request exists */ modifier checkRequestGroupExistence(Request memory request, bool existence) { - uint256 groupId = request.validator.getGroupID(request.params); + IRequestValidator.RequestParams memory requestParams = request.validator.getRequestParams(request.params); - if (groupId != 0) { + if (requestParams.groupID != 0) { if (existence) { - if (!groupIdExists(groupId)) { - revert GroupIdNotFound(groupId); + if (!groupIdExists(requestParams.groupID)) { + revert GroupIdNotFound(requestParams.groupID); } } else { - if (groupIdExists(groupId)) { - revert GroupIdAlreadyExists(groupId); + if (groupIdExists(requestParams.groupID)) { + revert GroupIdAlreadyExists(requestParams.groupID); } } } @@ -220,14 +220,14 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { Request calldata request ) internal checkRequestExistence(request.requestId, false) { VerifierStorage storage s = _getVerifierStorage(); - uint256 verifierId = request.validator.getVerifierId(request.params); + IRequestValidator.RequestParams memory requestParams = request.validator.getRequestParams(request.params); s._requests[request.requestId] = IVerifier.RequestData({ metadata: request.metadata, validator: request.validator, params: request.params, creator: _msgSender(), - verifierId: verifierId + verifierId: requestParams.verifierID }); s._requestIds.push(request.requestId); } @@ -285,19 +285,17 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { /** * @dev Sets a query - * @param queryId The ID of the query * @param query The query data */ function setQuery( - uint256 queryId, IVerifier.Query calldata query - ) public virtual checkQueryExistence(queryId, false) { + ) public virtual checkQueryExistence(query.queryId, false) { VerifierStorage storage s = _getVerifierStorage(); - s._queries[queryId] = query; - s._queryIds.push(queryId); + s._queries[query.queryId] = query; + s._queryIds.push(query.queryId); // checks for all the requests in this query - _checkRequestsInQuery(queryId); + _checkRequestsInQuery(query.queryId); } /** @@ -316,10 +314,11 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { // check that all the single requests doesn't have group for (uint256 i = 0; i < requestIds.length; i++) { + IRequestValidator.RequestParams memory requestParams = s._requests[requestIds[i]].validator.getRequestParams( + s._requests[requestIds[i]].params + ); if ( - s._requests[requestIds[i]].validator.getGroupID( - s._requests[requestIds[i]].params - ) != 0 + requestParams.groupID != 0 ) { revert RequestIsAlreadyGrouped(requestIds[i]); } @@ -420,14 +419,14 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { IVerifier.Request calldata request ) internal checkRequestExistence(request.requestId, true) { VerifierStorage storage s = _getVerifierStorage(); - uint256 verifierId = request.validator.getVerifierId(request.params); - + IRequestValidator.RequestParams memory requestParams = request.validator.getRequestParams(request.params); + s._requests[request.requestId] = IVerifier.RequestData({ metadata: request.metadata, validator: request.validator, params: request.params, creator: _msgSender(), - verifierId: verifierId + verifierId: requestParams.verifierID }); } diff --git a/test/verifier/universal-verifier-multi-query.test.ts b/test/verifier/universal-verifier-multi-query.test.ts index badbc0b6..6c315f7c 100644 --- a/test/verifier/universal-verifier-multi-query.test.ts +++ b/test/verifier/universal-verifier-multi-query.test.ts @@ -227,7 +227,7 @@ describe("Universal Verifier Multi-query", function () { groupIds: [], metadata: "0x", }; - const txSetQuery = await verifier.setQuery(queryId, query); + const txSetQuery = await verifier.setQuery(query); await txSetQuery.wait(); const queryStored = await verifier.getQuery(queryId); expect(queryStored.queryId).to.be.equal(queryId); @@ -359,7 +359,7 @@ describe("Universal Verifier Multi-query", function () { groupIds: [groupId], metadata: "0x", }; - const txSetQuery = await verifier.setQuery(queryId, query); + const txSetQuery = await verifier.setQuery(query); await txSetQuery.wait(); const queryStored = await verifier.getQuery(queryId); @@ -472,7 +472,7 @@ describe("Universal Verifier Multi-query", function () { groupIds: [groupId], metadata: "0x", }; - const txSetQuery = await verifier.setQuery(queryId, query); + const txSetQuery = await verifier.setQuery(query); await txSetQuery.wait(); const { inputs, pi_a, pi_b, pi_c } = prepareInputs(proofJson);