Skip to content
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

Draft
wants to merge 69 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
bf71699
new universal verifier multi-query
daveroga Nov 26, 2024
74b24a1
Discussion results
AndriianChestnykh Nov 26, 2024
16a8b27
Discussion results 2
AndriianChestnykh Nov 26, 2024
f05104d
update universal verifier multi query
daveroga Nov 26, 2024
779513f
remove ZKP
daveroga Nov 26, 2024
8da12c7
add auth validators
daveroga Nov 26, 2024
ba75a5d
Broader discussion results
AndriianChestnykh Nov 26, 2024
ae9cec1
Add agreed universal verifier solution
AndriianChestnykh Nov 27, 2024
790a0e3
update universal verifier multi query with agreed design
daveroga Nov 28, 2024
1858dce
query status and submit response
daveroga Nov 28, 2024
4527834
get request type from 30 byte of the requestId
daveroga Nov 28, 2024
bb82ff3
add EthIdentityValidator
daveroga Nov 28, 2024
e66a160
updates from review
daveroga Nov 28, 2024
d416b9a
Discussion result
AndriianChestnykh Nov 29, 2024
a26861c
updates from discussion
daveroga Nov 29, 2024
0c2e792
check response field values from linked response fields
daveroga Nov 29, 2024
16f8b5a
fix some errors in compilation
daveroga Dec 2, 2024
4afb814
test universal verifier multi-query
daveroga Dec 3, 2024
8f55467
different validators for sig and authv2
daveroga Dec 3, 2024
657fa6c
check specific storage values
daveroga Dec 3, 2024
46d17ab
overrides solidity compiler optimizations for specific contract
daveroga Dec 3, 2024
1e7b877
remove some methods
daveroga Dec 3, 2024
2942cdf
fix solhint
daveroga Dec 3, 2024
a91c1e7
update from discussion
daveroga Dec 4, 2024
849e790
set group of requests and check linkID
daveroga Dec 5, 2024
a02592c
fix solhint
daveroga Dec 5, 2024
6b82ff0
updates from review
daveroga Dec 6, 2024
d35e4b4
fix cyclomatic-complexity
daveroga Dec 6, 2024
3811b9c
some fixes from review
daveroga Dec 9, 2024
4030067
updates from tech spec
daveroga Dec 9, 2024
6135f84
add auth validator stub and fix test
daveroga Dec 10, 2024
b860ab0
add changes for user authentication structs
daveroga Dec 10, 2024
fc7bc91
fix solhint
daveroga Dec 10, 2024
c3bb7e3
reestructure link between userID and address and mapping for authenti…
daveroga Dec 11, 2024
14d08fb
auth proofs different structure
daveroga Dec 11, 2024
3734eb5
add custom errors to UniversalVerifierMultiQuery
daveroga Dec 11, 2024
4c8e01d
add __gap in proofs storage for future updates and array of proofs fo…
daveroga Dec 12, 2024
24888ad
param names in returned structs from solidity
daveroga Dec 12, 2024
14ca44b
Initial verifier authentication (#323)
AndriianChestnykh Dec 17, 2024
636f590
updates for iteration 2
daveroga Dec 18, 2024
88ff859
fix test multi-query
daveroga Dec 19, 2024
fb2a5b4
update verifiers tests
daveroga Dec 20, 2024
faa2d0b
fix validators tests and solhint
daveroga Dec 20, 2024
a8c8653
updates merge from master
daveroga Dec 20, 2024
6336ad5
partial changes review
daveroga Dec 30, 2024
31aa30b
override _setRequest to avoid loops and fix solhint
daveroga Jan 7, 2025
a30dbfd
remove embedded zkp verifier
daveroga Jan 7, 2025
c6077eb
update Query to MultiRequest
daveroga Jan 8, 2025
d31f2ca
update submitResponse
daveroga Jan 8, 2025
7ad4411
fix solhint
daveroga Jan 8, 2025
7005a64
address centered model instead of userID and some fixes
daveroga Jan 8, 2025
85804dd
fix solhint and custom errors
daveroga Jan 9, 2025
1d49a4e
updates from review
daveroga Jan 9, 2025
4a9e988
check grouped requests 2 requests at least
daveroga Jan 9, 2025
81fdf83
fix error cyclomatic-complexity from solhint
daveroga Jan 9, 2025
034de2c
move _state in storage
daveroga Jan 10, 2025
10eb73d
check link responses with bool
daveroga Jan 10, 2025
ca1f04f
fix solhint
daveroga Jan 10, 2025
188bb13
remove history in proofs from requests
daveroga Jan 10, 2025
ffe4e6e
check nullifierSessionID on request creation
daveroga Jan 10, 2025
f607131
fix cyclomatic-complexity in solhint
daveroga Jan 10, 2025
848e609
check verifierID in requests for V3
daveroga Jan 13, 2025
4bac7da
add test for authv2 validator
daveroga Jan 14, 2025
1e9c474
Feature/pid 2720 implement linked multi query validator (#328)
AndriianChestnykh Jan 15, 2025
d510368
update tests with updated stub validator
daveroga Jan 15, 2025
296bb68
check requestId correctness
daveroga Jan 16, 2025
78610dd
add logic from skip tests in verifier test
daveroga Jan 16, 2025
1641d15
add auth validator stub set verify results method
daveroga Jan 16, 2025
9f33dec
idType for verifier and some updates to verifier test
daveroga Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions contracts/interfaces/IAuthValidator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.27;

import {IState} from "./IState.sol";

/**
* @dev IAuthValidator. Interface for verification of auth data.
*/
interface IAuthValidator {
/**
* @dev ResponseField. Information about response fields from verification. Used in verify function.
* @param name Name of the response field
* @param value Value of the response field
*/
struct ResponseField {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we agreed, we don't need this struct in IAuthValidator

string name;
uint256 value;
}

/**
* @dev Get version of the contract
*/
function version() external view returns (string memory);

/**
* @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 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,
address sender,
IState state
) external returns (ResponseField[] memory);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just return bool, as agreed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will return uint256 userID as agreed.

}
22 changes: 22 additions & 0 deletions contracts/interfaces/IGroth16Verifier.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.27;

/**
* @dev IGroth16Verifier. Interface for verification of groth16 proofs.
*/
interface IGroth16Verifier {
/**
* @dev Verify the circuit with the groth16 proof π=([πa]1,[πb]2,[πc]1).
* @param a πa element of the groth16 proof.
* @param b πb element of the groth16 proof.
* @param c πc element of the groth16 proof.
* @param input Public inputs of the circuit.
* @return r true if the proof is verified.
*/
function verify(
uint256[2] calldata a,
uint256[2][2] calldata b,
uint256[2] calldata c,
uint256[] calldata input
) external view returns (bool r);
}
54 changes: 54 additions & 0 deletions contracts/interfaces/IRequestValidator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.27;

import {IState} from "./IState.sol";

/**
* @dev IRequestValidator. Interface for verification of request query data.
*/
interface IRequestValidator {
/**
* @dev ResponseField. Information about response fields from verification. Used in verify function.
* @param name Name of the response field
* @param value Value of the response field
*/
struct ResponseField {
string name;
uint256 value;
}

/**
* @dev Get version of the contract
*/
function version() external view returns (string memory);

/**
* @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 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,
daveroga marked this conversation as resolved.
Show resolved Hide resolved
address sender,
IState state
) external returns (ResponseField[] memory);

/**
* @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);
daveroga marked this conversation as resolved.
Show resolved Hide resolved
}
271 changes: 257 additions & 14 deletions contracts/interfaces/IVerifier.sol
Original file line number Diff line number Diff line change
@@ -1,22 +1,265 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity 0.8.27;

import {IAuthValidator} from "./IAuthValidator.sol";
import {IRequestValidator} from "./IRequestValidator.sol";

/**
* @dev IVerifier. Interface for verification of groth16 proofs.
* @dev IVerifier. Interface for verification of groth16 proofs for validators circuits.
*/
interface IVerifier {
/**
* @dev Verify the circuit with the groth16 proof π=([πa]1,[πb]2,[πc]1).
* @param a πa element of the groth16 proof.
* @param b πb element of the groth16 proof.
* @param c πc element of the groth16 proof.
* @param input Public inputs of the circuit.
* @return r true if the proof is verified.
*/
function verify(
uint256[2] calldata a,
uint256[2][2] calldata b,
uint256[2] calldata c,
uint256[] calldata input
) external view returns (bool r);
* @dev Request. Structure for request.
* @param requestId Request id.
* @param metadata Metadata of the request.
* @param validator Validator to verify the response.
* @param params Parameters data of the request.
*/
struct Request {
uint256 requestId;
string metadata;
IRequestValidator validator;
bytes params;
}

/**
* @dev Request. Structure for request for storage.
* @param metadata Metadata of the request.
* @param validator Validator circuit.
* @param params Params of the request. Proof parameters could be ZK groth16, plonk, ESDSA, EIP712, etc.
*/
struct RequestData {
string metadata;
IRequestValidator validator;
bytes params;
address creator;
uint256 verifierId;
}

/**
* @dev RequestInfo. Structure for request info.
* @param requestId Request id.
* @param metadata Metadata of the request.
* @param validator Validator to verify the response.
* @param params Parameters data of the request.
* @param creator Creator of the request.
* @param verifierId Verifier id.
* @param isVerifierAuthenticated True if the verifier is authenticated.
*/
struct RequestInfo {
uint256 requestId;
string metadata;
IRequestValidator validator;
bytes params;
address creator;
uint256 verifierId;
bool isVerifierAuthenticated;
}
/**
* @dev AuthProofStatus. Structure for auth proof status.
* @param groupId Group id of the requests.
* @param requests Requests of the group.
*/
struct GroupedRequests {
uint256 groupId;
Request[] requests;
}

/**
* @dev ProofStatus. Structure for proof status.
* @param isVerified True if the proof is verified.
* @param validatorVersion Version of the validator.
* @param blockTimestamp Block timestamp of the proof.
*/
struct ProofStatus {
bool isVerified;
string validatorVersion;
uint256 blockTimestamp;
}

/**
* @dev Response. Structure for response.
* @param requestId Request id of the request.
* @param proof proof to verify.
* @param metadata Metadata of the request.
*/
struct Response {
uint256 requestId;
bytes proof;
bytes metadata;
}
/**
* @dev GroupedResponses. Structure for grouped responses.
* @param groupId Group id of the responses.
* @param responses Responses of the group.
*/
struct GroupedResponses {
uint256 groupId;
Response[] responses;
}
/**
* @dev AuthResponse. Structure for auth response.
* @param authType Auth type of the proof response.
* @param proof proof to verify.
*/
struct AuthResponse {
string authType; //zkp-auth-v2, zkp-auth-v3, etc. will deside later
bytes proof;
}

/**
* @dev RequestProofStatus. Structure for request proof status.
* @param requestId Request id of the proof.
* @param isVerified True if the proof is verified.
* @param validatorVersion Version of the validator.
* @param timestamp Timestamp of the proof.
*/
struct RequestProofStatus {
uint256 requestId;
bool isVerified;
string validatorVersion;
uint256 timestamp;
}

struct AuthType {
string authType;
IAuthValidator validator;
bytes params;
}

/**
* @dev AuthProofStatus. Structure for auth proof status.
* @param authType Auth type of the auth proof.
* @param isVerified True if the proof is verified.
* @param validatorVersion Version of the validator.
* @param timestamp Timestamp of the proof.
*/
struct AuthProofStatus {
string authType;
bool isVerified;
string validatorVersion;
uint256 timestamp;
}

/**
* @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.
*/
struct Query {
uint256 queryId;
uint256[] requestIds;
uint256[] groupIds;
bytes metadata;
}

/**
* @dev Submits an array of responses and updates proofs status
* @param authResponses The list of auth responses including auth type and proof
* @param singleResponses The list of responses including request ID, proof and metadata for single requests
* @param groupedResponses The list of responses including request ID, proof and metadata for grouped requests
* @param crossChainProofs The list of cross chain proofs from universal resolver (oracle). This
* includes identities and global states.
*/
function submitResponse(
AuthResponse[] memory authResponses,
Response[] memory singleResponses,
GroupedResponses[] memory groupedResponses,
bytes memory crossChainProofs
) external;

/**
* @dev Sets different requests
* @param singleRequests The requests that are not in any group
* @param groupedRequests The requests that are in a group
*/
function setRequests(
Request[] calldata singleRequests,
GroupedRequests[] calldata groupedRequests
) external;

/**
* @dev Gets a specific request by ID
* @param requestId The ID of the request
* @return request The request info
*/
function getRequest(uint256 requestId) external view returns (RequestInfo memory request);

/**
* @dev Get the requests count.
* @return Requests count.
*/
function getRequestsCount() external view returns (uint256);

/**
* @dev Checks if a request ID exists
* @param requestId The ID of the request
* @return Whether the request ID exists
*/
function requestIdExists(uint256 requestId) external view returns (bool);

/**
* @dev Gets the status of the query verification
* @param queryId The ID of the query
* @param userAddress The address of the user
* @return status The status of the query. "True" if all requests are verified, "false" otherwise
*/
function getQueryStatus(
uint256 queryId,
address userAddress
) external view returns (AuthProofStatus[] memory, RequestProofStatus[] memory);

/**
* @dev Gets proof storage response field value
* @param requestId Id of the request
* @param userID Id of the user
* @param responseFieldName Name of the proof storage response field to get
*/
function getResponseFieldValue(
uint256 requestId,
uint256 userID,
string memory responseFieldName
) external view returns (uint256);

/**
* @dev Get if proof is verified for the sender and request with requestId.
* @param sender Sender of the proof.
* @param requestId Request id of the Request to verify.
* @return True if proof is verified for the sender and request id.
*/
function isProofVerified(address sender, uint256 requestId) external view returns (bool);

/**
* @dev Sets an auth type
* @param authType The auth type to add
*/
function setAuthType(AuthType calldata authType) external;

/**
* @dev Sets a query
* @param queryId The ID of the query
* @param query The query data
*/
function setQuery(uint256 queryId, Query calldata query) external;
daveroga marked this conversation as resolved.
Show resolved Hide resolved

/**
* @dev Gets a specific multi query by ID
* @param queryId The ID of the multi query
* @return query The query data
*/
function getQuery(uint256 queryId) external view returns (IVerifier.Query memory query);

/**
* @dev Get the proof status for the sender and request with requestId.
* @param sender Sender of the proof.
* @param requestId Request id of the proof.
* @return Proof status.
*/
function getProofStatus(
address sender,
uint256 requestId
) external view returns (ProofStatus memory);
Copy link
Collaborator

@AndriianChestnykh AndriianChestnykh Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add getMultiRequestStatus(), I think

}
Loading
Loading