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

Merged
merged 115 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 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
faf0997
fix enumerable and check existence in proof response fields
daveroga Jan 16, 2025
d7c7281
fix requestId calculation
daveroga Jan 17, 2025
822c81c
remove specific multi-request test that now is included in verifier test
daveroga Jan 17, 2025
39d67f5
add test wrappers and tests for RequestDisableable, RequestOwnership …
daveroga Jan 17, 2025
e2109e6
increase coverage
daveroga Jan 17, 2025
886193c
updates from review
daveroga Jan 20, 2025
adfac38
reorganize universal verifier tests
daveroga Jan 20, 2025
70e5a5c
test all the events from universal verifier
daveroga Jan 20, 2025
001f603
add embedded verifier test
daveroga Jan 20, 2025
a80a773
some fixes and increase coverage
daveroga Jan 20, 2025
d952287
increase coverage
daveroga Jan 21, 2025
43e6e8f
Integration tests (#332)
AndriianChestnykh Jan 21, 2025
16de597
Fix lmk tests
AndriianChestnykh Jan 21, 2025
85ebc38
update multi-request integration test
daveroga Jan 23, 2025
c75baa6
check multi-request components exist
daveroga Jan 23, 2025
0e90b88
small general updates
daveroga Jan 23, 2025
45c5edc
fix solhint
daveroga Jan 23, 2025
b18c064
remove VerifierLib and move functionality to Verifier
daveroga Jan 23, 2025
109f3f8
fix solhint
daveroga Jan 24, 2025
1179c78
update missing unified addresses for validators
daveroga Jan 24, 2025
a64341a
add test to calculate create2 proxy addresses
daveroga Jan 24, 2025
bc22c56
update test script to check unified addresses for all the contracts
daveroga Jan 24, 2025
6ea8563
fix create2Calldata statelib
daveroga Jan 24, 2025
af3b57b
update unified address for some contracts
daveroga Jan 27, 2025
4458158
remove ICircuitValidator references
daveroga Jan 27, 2025
256d571
move getters for storage data back to the beginning
daveroga Jan 27, 2025
19da90c
resolve solhint warnings
daveroga Jan 28, 2025
f238b05
update from review comments
daveroga Jan 28, 2025
127c40c
update AuthV2Validator
daveroga Jan 28, 2025
374ea04
add function getResponseFields to verifier
daveroga Jan 28, 2025
f553fed
Remove unused tests and comments
AndriianChestnykh Jan 28, 2025
67bc7fe
updates from review
daveroga Jan 30, 2025
a817f35
update requestId calculation
daveroga Jan 30, 2025
569c6b6
fix solhint
daveroga Jan 30, 2025
5025be6
update RequestStatus for RequestProofStatus
daveroga Jan 31, 2025
de9d7a5
more updates from review
daveroga Jan 31, 2025
50960a8
more updates from review
daveroga Jan 31, 2025
6334aa3
change AuthType to AuthMethod
daveroga Jan 31, 2025
707a770
precalculate keccack256 of field names
daveroga Feb 1, 2025
7a5f833
Merge remote-tracking branch 'refs/remotes/origin/master' into PID-27…
AndriianChestnykh Feb 2, 2025
d46b262
solve solhint warning explicit type
daveroga Feb 3, 2025
ccd69f9
fix solhint warnings
daveroga Feb 3, 2025
0473eca
fix solhint warnings for custom errors
daveroga Feb 3, 2025
a52ebd1
fix circuitId for linkedMultiQuery10-beta.1
daveroga Feb 3, 2025
598272a
comment requestId calculation
daveroga Feb 3, 2025
a09e038
v3.0.0
daveroga Feb 4, 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
9 changes: 2 additions & 7 deletions .solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
**/lib/VerifierStateTransition.sol
**/lib/VerifierV3.sol
**/lib/VerifierV3Wrapper.sol
**/lib/groth16-verifiers/Groth16VerifierMTP.sol
**/lib/groth16-verifiers/Groth16VerifierMTPWrapper.sol
**/lib/groth16-verifiers/Groth16VerifierSig.sol
**/lib/groth16-verifiers/Groth16VerifierSigWrapper.sol
**/lib/groth16-verifiers/Groth16VerifierStateTransition.sol
**/lib/groth16-verifiers/Groth16VerifierV3.sol
**/lib/groth16-verifiers/Groth16VerifierV3Wrapper.sol
**/lib/groth16-verifiers
**/node_modules

4 changes: 3 additions & 1 deletion contracts/AlwaysRevert.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.27;

error TheContractIsDisabled();

/// @title This contract as a dummy implementation for Proxy contract if we need to revert all calls
// This can be applied to disable all methods of a proxy contract with explicit error message
contract AlwaysRevert {
fallback() external payable {
revert("The contract is disabled");
revert TheContractIsDisabled();
}
}
2 changes: 2 additions & 0 deletions contracts/Create2AddressAnchor.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.27;

/* solhint-disable no-empty-blocks */
contract Create2AddressAnchor {}
/* solhint-enable no-empty-blocks */
33 changes: 21 additions & 12 deletions contracts/cross-chain/CrossChainProofValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import {ICrossChainProofValidator} from "../interfaces/ICrossChainProofValidator
import {IState} from "../interfaces/IState.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

error IdentityStateProofInvalid();
error GlobalStateProofInvalid();
error GlobalStateProofSigningAddressInvalid(address recovered);
error IdentityStateProofSigningAddressInvalid(address recovered);
error OracleTimestampCannotBeInThePast();
error OracleReplacedAtTimestampCannotBeInTheFuture();

/**
* @dev Contract which provides proof validation from identity state
* and global state proofs from trusted oracle with signature from any network.
Expand Down Expand Up @@ -83,11 +90,12 @@ contract CrossChainProofValidator is Ownable, EIP712, ICrossChainProofValidator
gsu.globalStateMsg,
gsu.signature
);
require(isValid, "Global state proof is not valid");
require(
recovered == _oracleSigningAddress,
"Global state proof signing address is not valid"
);
if (!isValid) {
revert GlobalStateProofInvalid();
}
if (recovered != _oracleSigningAddress) {
revert GlobalStateProofSigningAddressInvalid(recovered);
}

return
IState.GlobalStateProcessResult({
Expand Down Expand Up @@ -117,11 +125,12 @@ contract CrossChainProofValidator is Ownable, EIP712, ICrossChainProofValidator
isu.idStateMsg,
isu.signature
);
require(isValid, "Identity state proof is not valid");
require(
recovered == _oracleSigningAddress,
"Identity state proof signing address is not valid"
);
if (!isValid) {
revert IdentityStateProofInvalid();
}
if (recovered != _oracleSigningAddress) {
revert IdentityStateProofSigningAddressInvalid(recovered);
}

return
IState.IdentityStateProcessResult({
Expand Down Expand Up @@ -213,13 +222,13 @@ contract CrossChainProofValidator is Ownable, EIP712, ICrossChainProofValidator
uint256 replacedAtTimestamp
) internal view returns (uint256 replacedAt) {
if (oracleTimestamp < block.timestamp - MAX_TIMESTAMP_LAG) {
revert("Oracle timestamp cannot be in the past");
revert OracleTimestampCannotBeInThePast();
}

replacedAt = replacedAtTimestamp == 0 ? oracleTimestamp : replacedAtTimestamp;

if (replacedAt > block.timestamp + MAX_REPLACED_AT_AHEAD_OF_TIME) {
revert("Oracle replacedAtTimestamp or oracle timestamp cannot be in the future");
revert OracleReplacedAtTimestampCannotBeInTheFuture();
}

// this should never happen as block.timestamp is always greater than 0
Expand Down
22 changes: 18 additions & 4 deletions contracts/identitytreestore/IdentityTreeStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import {IOnchainCredentialStatusResolver} from "../interfaces/IOnchainCredential
import {IRHSStorage} from "../interfaces/IRHSStorage.sol";
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

error NodeNotFound();
error InvalidStateNode();
error InvalidNodeType();
error UnsupportedLength();

/**
* @dev Contract which provides onchain Reverse Hash Service (RHS)
* for checking revocation status of claims.
Expand Down Expand Up @@ -40,10 +45,12 @@ contract IdentityTreeStore is Initializable, IOnchainCredentialStatusResolver, I

// keccak256(abi.encode(uint256(keccak256("iden3.storage.IdentityTreeStore.ReverseHashLibData")) - 1)) &
// ~bytes32(uint256(0xff));
// solhint-disable-next-line const-name-snakecase
bytes32 private constant ReverseHashLibDataStorageLocation =
0x0f7e3bdc6cc0e880d509aa1f6b8d1a88e5fcb7274e18dfba772424a36fe9b400;

function _getReverseHashLibDataStorage() private pure returns (ReverseHashLib.Data storage $) {
// solhint-disable-next-line no-inline-assembly
assembly {
$.slot := ReverseHashLibDataStorageLocation
}
Expand All @@ -55,6 +62,7 @@ contract IdentityTreeStore is Initializable, IOnchainCredentialStatusResolver, I
}

// keccak256(abi.encode(uint256(keccak256("iden3.storage.IdentityTreeStore.Main")) - 1)) & ~bytes32(uint256(0xff));
// solhint-disable-next-line const-name-snakecase
bytes32 private constant IdentityTreeStoreMainStorageLocation =
0x95ca427007e091a13a7ccfcb233b8a2ed19d987330a248c445b1b483a35bb800;

Expand All @@ -64,6 +72,7 @@ contract IdentityTreeStore is Initializable, IOnchainCredentialStatusResolver, I
pure
returns (IdentityTreeStoreMainStorage storage $)
{
// solhint-disable-next-line no-inline-assembly
assembly {
$.slot := IdentityTreeStoreMainStorageLocation
}
Expand Down Expand Up @@ -96,7 +105,9 @@ contract IdentityTreeStore is Initializable, IOnchainCredentialStatusResolver, I
*/
function getNode(uint256 key) public view returns (uint256[] memory) {
uint256[] memory preim = _getReverseHashLibDataStorage().getPreimage(key);
require(preim.length > 0, "Node not found");
if (preim.length == 0) {
revert NodeNotFound();
}
return preim;
}

Expand All @@ -122,6 +133,7 @@ contract IdentityTreeStore is Initializable, IOnchainCredentialStatusResolver, I
* @return CredentialStatus
*/
function getRevocationStatusByIdAndState(
// solhint-disable-next-line no-unused-vars
uint256 id,
uint256 state,
uint64 nonce
Expand All @@ -134,7 +146,9 @@ contract IdentityTreeStore is Initializable, IOnchainCredentialStatusResolver, I
uint64 nonce
) internal view returns (CredentialStatus memory) {
uint256[] memory roots = getNode(state);
require(_nodeType(roots) == NodeType.State, "Invalid state node");
if (_nodeType(roots) != NodeType.State) {
revert InvalidStateNode();
}

CredentialStatus memory status = CredentialStatus({
issuer: IdentityStateRoots({
Expand Down Expand Up @@ -200,7 +214,7 @@ contract IdentityTreeStore is Initializable, IOnchainCredentialStatusResolver, I
proof.siblings[i] = children[1];
}
} else {
revert("Invalid node type");
revert InvalidNodeType();
}
}

Expand Down Expand Up @@ -234,6 +248,6 @@ contract IdentityTreeStore is Initializable, IOnchainCredentialStatusResolver, I
if (preimage.length == 3) {
return PoseidonUnit3L.poseidon([preimage[0], preimage[1], preimage[2]]);
}
revert("Unsupported length");
revert UnsupportedLength();
}
}
4 changes: 3 additions & 1 deletion contracts/imports.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.27;

// We import these here to force Hardhat to compile them.
// This ensures that their artifacts are available for Hardhat Ignition to use.
/* solhint-disable no-unused-import */
import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
/* solhint-enable no-unused-import */
37 changes: 37 additions & 0 deletions contracts/interfaces/IAuthValidator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.27;

/**
* @dev IAuthValidator. Interface for verification of auth data.
*/
interface IAuthValidator {
/**
* @dev AuthResponseField. 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 AuthResponseField {
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 sender Sender of the proof.
* @param proof Proof packed as bytes to verify.
* @param params Request query data of the credential to verify.
* @return userID User Id for the auth proof verified and response fields.
* @return authResponseFields Additional response fields.
*/
function verify(
address sender,
bytes calldata proof,
bytes calldata params
) external returns (uint256 userID, AuthResponseField[] memory authResponseFields);
}
85 changes: 0 additions & 85 deletions contracts/interfaces/ICircuitValidator.sol

This file was deleted.

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 signals Public inputs and outputs 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 signals
) external view returns (bool r);
}
Loading
Loading