From 10eb73dc27b7056ad6ad39776363e41bfb931a13 Mon Sep 17 00:00:00 2001 From: daveroga Date: Fri, 10 Jan 2025 14:38:49 +0100 Subject: [PATCH] check link responses with bool --- contracts/verifiers/Verifier.sol | 41 ++++++++++++++----- .../universal-verifier-multi-query.test.ts | 2 +- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/contracts/verifiers/Verifier.sol b/contracts/verifiers/Verifier.sol index 3018b761..a27584ce 100644 --- a/contracts/verifiers/Verifier.sol +++ b/contracts/verifiers/Verifier.sol @@ -19,7 +19,7 @@ error AuthTypeNotFound(string authType); error AuthTypeAlreadyExists(string authType); error ValidatorNotWhitelisted(address validator); error RequestIsAlreadyGrouped(uint256 requestId); -error LinkIDNotTheSameForGroupedRequests(uint256 requestLinkID, uint256 requestLinkIDToCompare); +error LinkIDNotTheSameForGroupedRequests(); error UserIDNotFound(uint256 userID); error UserIDNotLinkedToAddress(uint256 userID, address userAddress); error UserNotAuthenticated(); @@ -513,10 +513,16 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { string memory responseFieldName ) public view checkRequestExistence(requestId, true) returns (uint256) { VerifierStorage storage s = _getVerifierStorage(); - return s._proofs[requestId][sender][0].storageFields[responseFieldName]; + return + s._proofs[requestId][sender][s._proofs[requestId][sender].length - 1].storageFields[ + responseFieldName + ]; } - function _checkLinkedResponseFields(uint256 multiRequestId, address sender) internal view { + function _checkLinkedResponseFields( + uint256 multiRequestId, + address sender + ) internal view returns (bool) { VerifierStorage storage s = _getVerifierStorage(); for (uint256 i = 0; i < s._multiRequests[multiRequestId].groupIds.length; i++) { @@ -535,13 +541,12 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { LINKED_PROOF_KEY ); if (requestLinkID != requestLinkIDToCompare) { - revert LinkIDNotTheSameForGroupedRequests( - requestLinkID, - requestLinkIDToCompare - ); + return false; } } } + + return true; } /** @@ -566,7 +571,14 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { ); // 2. Check if all linked response fields are the same - _checkLinkedResponseFields(multiRequestId, userAddress); + bool linkedResponsesOK = _checkLinkedResponseFields( + multiRequestId, + userAddress + ); + + if (!linkedResponsesOK) { + revert LinkIDNotTheSameForGroupedRequests(); + } return requestStatus; } @@ -584,9 +596,18 @@ abstract contract Verifier is IVerifier, ContextUpgradeable { // 1. Check if all requests are verified for the userAddress bool verified = _isMultiRequestVerified(multiRequestId, userAddress); - // 2. Check if all linked response fields are the same - _checkLinkedResponseFields(multiRequestId, userAddress); + if (verified) { + // 2. Check if all linked response fields are the same + bool linkedResponsesOK = _checkLinkedResponseFields( + multiRequestId, + userAddress + ); + if (!linkedResponsesOK) { + verified = false; + } + } + return verified; } diff --git a/test/verifier/universal-verifier-multi-query.test.ts b/test/verifier/universal-verifier-multi-query.test.ts index 20686f55..cd8d538c 100644 --- a/test/verifier/universal-verifier-multi-query.test.ts +++ b/test/verifier/universal-verifier-multi-query.test.ts @@ -448,7 +448,7 @@ describe("Universal Verifier Multi-request", function () { await tx.wait(); await expect(verifier.getMultiRequestStatus(multiRequestId, signerAddress)).to.be.rejectedWith( - "LinkIDNotTheSameForGroupedRequests(3, 4)", + "LinkIDNotTheSameForGroupedRequests()", ); }); });