-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Full Multi-query support onchain #321
base: master
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 12543564150Details
💛 - Coveralls |
b70f050
to
a02592c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good enough to discuss interface finalisation.
A few comments but not the full code check which is still to early to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't completed review of all the files. However, these feedback is what I have now.
*/ | ||
function verify( | ||
bytes calldata proof, | ||
bytes calldata data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename data
to param
maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to params
in both IRequestValidator
and IAuthValidator
/** | ||
* @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 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we introduce this method instead of those two?
function getGroupID(bytes calldata params) external view returns (uint256 groupID, uint256 verifierID);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created
struct RequestParams {
uint256 groupID;
uint256 verifierID;
}
function getRequestParams(bytes calldata params) external view returns (RequestParams memory);
contracts/interfaces/IVerifier.sol
Outdated
* @param queryId The ID of the query | ||
* @param query The query data | ||
*/ | ||
function setQuery(uint256 queryId, Query calldata query) external; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already queryId
inside the Query
struct, so no reason to put it separatelly
contracts/lib/VerifierLib.sol
Outdated
struct Proof { | ||
bool isVerified; | ||
mapping(string key => uint256 inputValue) storageFields; | ||
string validatorVersion; | ||
uint256 blockNumber; | ||
// TODO: discuss if we need this field | ||
// uint256 blockNumber; | ||
uint256 blockTimestamp; | ||
mapping(string key => bytes) metadata; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mapping(string key => bytes) metadata;
is not used anywhere, so let's remove it for now and use uint256[46] __gap
instead
uint256 blockTimestamp; | ||
// 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint256[46] __gap is better for round number of slots (quals to 50). Not critical but good to have
super.setRequests(singleRequests, groupedRequests); | ||
for (uint256 i = 0; i < singleRequests.length; i++) { | ||
_setRequestOwner(singleRequests[i].requestId, _msgSender()); | ||
} | ||
|
||
for (uint256 i = 0; i < groupedRequests.length; i++) { | ||
for (uint256 j = 0; j < groupedRequests[i].requests.length; j++) { | ||
_setRequestOwner(groupedRequests[i].requests[j].requestId, _msgSender()); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe overriding _setRequest
and adding _setRequestOwner(singleRequests[i].requestId, _msgSender());
to its logic may help avoid these two cycles
) public override(RequestOwnership, ValidatorWhitelist, Verifier) { | ||
super.setRequests(singleRequests, groupedRequests); | ||
|
||
for (uint256 i = 0; i < singleRequests.length; i++) { | ||
emit RequestSet( | ||
singleRequests[i].requestId, | ||
_msgSender(), | ||
singleRequests[i].metadata, | ||
address(singleRequests[i].validator), | ||
singleRequests[i].params | ||
); | ||
} | ||
|
||
for (uint256 i = 0; i < groupedRequests.length; i++) { | ||
for (uint256 j = 0; j < groupedRequests[i].requests.length; j++) { | ||
emit RequestSet( | ||
groupedRequests[i].requests[j].requestId, | ||
_msgSender(), | ||
groupedRequests[i].requests[j].metadata, | ||
address(groupedRequests[i].requests[j].validator), | ||
groupedRequests[i].requests[j].params | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same, try to override the _setRequest method itself with additional functionality
super.submitResponse(authResponses, singleResponses, groupedResponses, crossChainProofs); | ||
for (uint256 i = 0; i < authResponses.length; i++) { | ||
emit AuthResponseSubmitted(authResponses[i].authType, _msgSender()); | ||
} | ||
} | ||
|
||
/// @dev Verifies a ZKP response without updating any proof status | ||
/// @param requestId The ID of the ZKP request | ||
/// @param inputs The public inputs for the proof | ||
/// @param a The first component of the proof | ||
/// @param b The second component of the proof | ||
/// @param c The third component of the proof | ||
/// @param sender The sender on behalf of which the proof is done | ||
function verifyZKPResponse( | ||
uint64 requestId, | ||
uint256[] memory inputs, | ||
uint256[2] memory a, | ||
uint256[2][2] memory b, | ||
uint256[2] memory c, | ||
address sender | ||
) | ||
public | ||
override(RequestDisableable, ValidatorWhitelist, ZKPVerifierBase) | ||
returns (ICircuitValidator.KeyToInputIndex[] memory) | ||
{ | ||
return super.verifyZKPResponse(requestId, inputs, a, b, c, sender); | ||
for (uint256 i = 0; i < singleResponses.length; i++) { | ||
emit ResponseSubmitted(singleResponses[i].requestId, _msgSender()); | ||
} | ||
|
||
for (uint256 i = 0; i < groupedResponses.length; i++) { | ||
for (uint256 j = 0; j < groupedResponses[i].responses.length; j++) { | ||
emit ResponseSubmitted(groupedResponses[i].responses[j].requestId, _msgSender()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same note regarding overriding. Try to avoid the loops
for (uint256 i = 0; i < singleRequests.length; i++) { | ||
IRequestValidator validator = singleRequests[i].validator; | ||
if (!isWhitelistedValidator(validator)) { | ||
revert ValidatorIsNotWhitelisted(address(validator)); | ||
} | ||
} | ||
} | ||
|
||
/// @dev Verifies a ZKP response without updating any proof status | ||
/// @param requestId The ID of the ZKP request | ||
/// @param inputs The public inputs for the proof | ||
/// @param a The first component of the proof | ||
/// @param b The second component of the proof | ||
/// @param c The third component of the proof | ||
/// @param sender The sender on behalf of which the proof is done | ||
function verifyZKPResponse( | ||
uint64 requestId, | ||
uint256[] memory inputs, | ||
uint256[2] memory a, | ||
uint256[2][2] memory b, | ||
uint256[2] memory c, | ||
address sender | ||
) public virtual override returns (ICircuitValidator.KeyToInputIndex[] memory) { | ||
ICircuitValidator validator = getZKPRequest(requestId).validator; | ||
require(isWhitelistedValidator(validator), "Validator is not whitelisted"); | ||
return super.verifyZKPResponse(requestId, inputs, a, b, c, sender); | ||
for (uint256 i = 0; i < groupedRequests.length; i++) { | ||
for (uint256 j = 0; j < groupedRequests[i].requests.length; j++) { | ||
IRequestValidator validator = groupedRequests[i].requests[j].validator; | ||
if (!isWhitelistedValidator(validator)) { | ||
revert ValidatorIsNotWhitelisted(address(validator)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same. Try to avoid the loops
contracts/verifiers/ZKPVerifier.sol
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we introduce breaking change. You may just remove this file
Implement multi-query support similar to existing requests now in Universal Verifier.
Query
) independently and in the same way we are managing Requests in ZKPVerifierBase now (setQuery, getQuery, …). Avoid ZKP and generalize methods in Requests. setRequest, getRequest, submitResponse, …address user
touint256 userID
to keep identifier of the user.userAddress
anduserID
. In this first version 1 userID will have only 1 address? Review best approach or if we have to keep an array of addresses.linkID
between the Requests and Auth of the sameQuery
.uint64
touint256
.Link to Tech Spec for changes: https://www.notion.so/privado-id/Multi-query-Tech-Spec-13d4f86a875180e68fc8e3fa5362805e