Skip to content

Commit

Permalink
update Query to MultiRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
daveroga committed Jan 8, 2025
1 parent a30dbfd commit c6077eb
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 130 deletions.
38 changes: 19 additions & 19 deletions contracts/interfaces/IVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Check failure on line 252 in contracts/interfaces/IVerifier.sol

View workflow job for this annotation

GitHub Actions / solhint

Replace uint256·multiRequestId with ⏎········uint256·multiRequestId⏎····

/**
* @dev Get the proof status for the sender and request with requestId.
Expand Down
22 changes: 11 additions & 11 deletions contracts/verifiers/UniversalVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

/**
Expand Down
126 changes: 63 additions & 63 deletions contracts/verifiers/Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
_;
Expand Down Expand Up @@ -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;

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

View workflow job for this annotation

GitHub Actions / solhint

Insert ⏎···········
}

/**
Expand Down Expand Up @@ -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) {

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

View workflow job for this annotation

GitHub Actions / solhint

Replace uint256·multiRequestId with ⏎········uint256·multiRequestId⏎····
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++) {
Expand Down Expand Up @@ -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(
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -658,30 +658,30 @@ 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
view
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;
}
}
Expand All @@ -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++) {
Expand All @@ -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,
Expand All @@ -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({

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

View workflow job for this annotation

GitHub Actions / solhint

Insert ⏎····················
requestId: requestId,

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

View workflow job for this annotation

GitHub Actions / solhint

Insert ····
isVerified: s._proofs[requestId][userID][0].isVerified,

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

View workflow job for this annotation

GitHub Actions / solhint

Insert ····
validatorVersion: s._proofs[requestId][userID][0].validatorVersion,

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

View workflow job for this annotation

GitHub Actions / solhint

Replace ···················· with ························
Expand Down
Loading

0 comments on commit c6077eb

Please sign in to comment.