Skip to content

Commit

Permalink
check link responses with bool
Browse files Browse the repository at this point in the history
  • Loading branch information
daveroga committed Jan 10, 2025
1 parent 034de2c commit 10eb73d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
41 changes: 31 additions & 10 deletions contracts/verifiers/Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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++) {
Expand All @@ -535,13 +541,12 @@ abstract contract Verifier is IVerifier, ContextUpgradeable {
LINKED_PROOF_KEY
);
if (requestLinkID != requestLinkIDToCompare) {
revert LinkIDNotTheSameForGroupedRequests(
requestLinkID,
requestLinkIDToCompare
);
return false;
}
}
}

return true;
}

/**
Expand All @@ -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(

Check failure on line 574 in contracts/verifiers/Verifier.sol

View workflow job for this annotation

GitHub Actions / solhint

Replace ⏎············multiRequestId,⏎············userAddress⏎········ with multiRequestId,·userAddress
multiRequestId,
userAddress
);

if (!linkedResponsesOK) {
revert LinkIDNotTheSameForGroupedRequests();
}

return requestStatus;
}
Expand All @@ -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(

Check failure on line 601 in contracts/verifiers/Verifier.sol

View workflow job for this annotation

GitHub Actions / solhint

Replace ⏎················multiRequestId,⏎················userAddress⏎············ with multiRequestId,·userAddress
multiRequestId,
userAddress
);

if (!linkedResponsesOK) {
verified = false;
}
}

Check failure on line 610 in contracts/verifiers/Verifier.sol

View workflow job for this annotation

GitHub Actions / solhint

Delete ········
return verified;
}

Expand Down
2 changes: 1 addition & 1 deletion test/verifier/universal-verifier-multi-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()",
);
});
});

0 comments on commit 10eb73d

Please sign in to comment.