diff --git a/contracts/lib/groth16-verifiers/Groth16VerifierAuthV2Wrapper.sol b/contracts/lib/groth16-verifiers/Groth16VerifierAuthV2Wrapper.sol index 127d9cc6..89d092f8 100644 --- a/contracts/lib/groth16-verifiers/Groth16VerifierAuthV2Wrapper.sol +++ b/contracts/lib/groth16-verifiers/Groth16VerifierAuthV2Wrapper.sol @@ -4,6 +4,8 @@ pragma solidity 0.8.27; import {Groth16VerifierAuthV2} from "./Groth16VerifierAuthV2.sol"; import {IGroth16Verifier} from "../../interfaces/IGroth16Verifier.sol"; +error ExpectedArrayLenght(uint256 expected, uint256 actual); + contract Groth16VerifierAuthV2Wrapper is Groth16VerifierAuthV2, IGroth16Verifier { /** * @dev Number of public signals for atomic mtp circuit @@ -26,7 +28,9 @@ contract Groth16VerifierAuthV2Wrapper is Groth16VerifierAuthV2, IGroth16Verifier ) public view returns (bool r) { uint[PUBSIGNALS_LENGTH] memory pubSignals; - require(signals.length == PUBSIGNALS_LENGTH, "expected array length is 3"); + if (signals.length != PUBSIGNALS_LENGTH) { + revert ExpectedArrayLenght(PUBSIGNALS_LENGTH, signals.length); + } for (uint256 i = 0; i < PUBSIGNALS_LENGTH; i++) { pubSignals[i] = signals[i]; diff --git a/contracts/lib/groth16-verifiers/Groth16VerifierLinkedMultiQuery10Wrapper.sol b/contracts/lib/groth16-verifiers/Groth16VerifierLinkedMultiQuery10Wrapper.sol index 2a79f9b2..0c611638 100644 --- a/contracts/lib/groth16-verifiers/Groth16VerifierLinkedMultiQuery10Wrapper.sol +++ b/contracts/lib/groth16-verifiers/Groth16VerifierLinkedMultiQuery10Wrapper.sol @@ -4,6 +4,8 @@ pragma solidity ^0.8.10; import {IGroth16Verifier} from "../../interfaces/IGroth16Verifier.sol"; import {Groth16VerifierLinkedMultiQuery10} from "./Groth16VerifierLinkedMultiQuery10.sol"; +error ExpectedArrayLenght(uint256 expected, uint256 actual); + contract Groth16VerifierLinkedMultiQuery10Wrapper is Groth16VerifierLinkedMultiQuery10, IGroth16Verifier @@ -11,7 +13,7 @@ contract Groth16VerifierLinkedMultiQuery10Wrapper is /** * @dev Number of public signals for atomic mtp circuit */ - uint constant PUBSIGNALS_LENGTH = 22; + uint256 constant PUBSIGNALS_LENGTH = 22; /** * @dev Verify the circuit with the groth16 proof π=([πa]1,[πb]2,[πc]1). @@ -29,7 +31,9 @@ contract Groth16VerifierLinkedMultiQuery10Wrapper is ) public view returns (bool r) { uint[PUBSIGNALS_LENGTH] memory pubSignals; - require(signals.length == PUBSIGNALS_LENGTH, "expected array length is 22"); + if (signals.length != PUBSIGNALS_LENGTH) { + revert ExpectedArrayLenght(PUBSIGNALS_LENGTH, signals.length); + } for (uint256 i = 0; i < PUBSIGNALS_LENGTH; i++) { pubSignals[i] = signals[i]; diff --git a/contracts/lib/groth16-verifiers/Groth16VerifierMTPWrapper.sol b/contracts/lib/groth16-verifiers/Groth16VerifierMTPWrapper.sol index ddca6c98..8868f176 100644 --- a/contracts/lib/groth16-verifiers/Groth16VerifierMTPWrapper.sol +++ b/contracts/lib/groth16-verifiers/Groth16VerifierMTPWrapper.sol @@ -16,11 +16,13 @@ pragma solidity 0.8.27; import "./Groth16VerifierMTP.sol"; import "../../interfaces/IGroth16Verifier.sol"; +error ExpectedArrayLenght(uint256 expected, uint256 actual); + contract Groth16VerifierMTPWrapper is Groth16VerifierMTP, IGroth16Verifier { /** * @dev Number of public signals for atomic mtp circuit */ - uint constant PUBSIGNALS_LENGTH = 11; + uint256 constant PUBSIGNALS_LENGTH = 11; /** * @dev Verify the circuit with the groth16 proof π=([πa]1,[πb]2,[πc]1). @@ -38,7 +40,9 @@ contract Groth16VerifierMTPWrapper is Groth16VerifierMTP, IGroth16Verifier { ) public view returns (bool r) { uint[PUBSIGNALS_LENGTH] memory pubSignals; - require(signals.length == PUBSIGNALS_LENGTH, "expected array length is 11"); + if (signals.length != PUBSIGNALS_LENGTH) { + revert ExpectedArrayLenght(PUBSIGNALS_LENGTH, signals.length); + } for (uint256 i = 0; i < PUBSIGNALS_LENGTH; i++) { pubSignals[i] = signals[i]; diff --git a/contracts/lib/groth16-verifiers/Groth16VerifierSigWrapper.sol b/contracts/lib/groth16-verifiers/Groth16VerifierSigWrapper.sol index 13d4c39d..f65cbae7 100644 --- a/contracts/lib/groth16-verifiers/Groth16VerifierSigWrapper.sol +++ b/contracts/lib/groth16-verifiers/Groth16VerifierSigWrapper.sol @@ -16,11 +16,13 @@ pragma solidity 0.8.27; import "./Groth16VerifierSig.sol"; import "../../interfaces/IGroth16Verifier.sol"; +error ExpectedArrayLenght(uint256 expected, uint256 actual); + contract Groth16VerifierSigWrapper is Groth16VerifierSig, IGroth16Verifier { /** * @dev Number of public signals for atomic sig circuit */ - uint constant PUBSIGNALS_LENGTH = 11; + uint256 constant PUBSIGNALS_LENGTH = 11; /** * @dev Verify the circuit with the groth16 proof π=([πa]1,[πb]2,[πc]1). @@ -39,7 +41,9 @@ contract Groth16VerifierSigWrapper is Groth16VerifierSig, IGroth16Verifier { // slither-disable-next-line uninitialized-local uint[PUBSIGNALS_LENGTH] memory pubSignals; - require(signals.length == PUBSIGNALS_LENGTH, "expected array length is 11"); + if (signals.length != PUBSIGNALS_LENGTH) { + revert ExpectedArrayLenght(PUBSIGNALS_LENGTH, signals.length); + } for (uint256 i = 0; i < PUBSIGNALS_LENGTH; i++) { pubSignals[i] = signals[i]; diff --git a/contracts/lib/groth16-verifiers/Groth16VerifierV3Wrapper.sol b/contracts/lib/groth16-verifiers/Groth16VerifierV3Wrapper.sol index 081feb62..e256652b 100644 --- a/contracts/lib/groth16-verifiers/Groth16VerifierV3Wrapper.sol +++ b/contracts/lib/groth16-verifiers/Groth16VerifierV3Wrapper.sol @@ -16,11 +16,13 @@ pragma solidity 0.8.27; import "./Groth16VerifierV3.sol"; import "../../interfaces/IGroth16Verifier.sol"; +error ExpectedArrayLenght(uint256 expected, uint256 actual); + contract Groth16VerifierV3Wrapper is Groth16VerifierV3, IGroth16Verifier { /** * @dev Number of public signals for atomic V3 circuit */ - uint constant PUBSIGNALS_LENGTH = 14; + uint256 constant PUBSIGNALS_LENGTH = 14; /** * @dev Verify the circuit with the groth16 proof π=([πa]1,[πb]2,[πc]1). @@ -39,7 +41,9 @@ contract Groth16VerifierV3Wrapper is Groth16VerifierV3, IGroth16Verifier { // slither-disable-next-line uninitialized-local uint[PUBSIGNALS_LENGTH] memory pubSignals; - require(signals.length == PUBSIGNALS_LENGTH, "expected array length is 14"); + if (signals.length != PUBSIGNALS_LENGTH) { + revert ExpectedArrayLenght(PUBSIGNALS_LENGTH, signals.length); + } for (uint256 i = 0; i < PUBSIGNALS_LENGTH; i++) { pubSignals[i] = signals[i]; diff --git a/contracts/validators/request/CredentialAtomicQueryV2ValidatorBase.sol b/contracts/validators/request/CredentialAtomicQueryV2ValidatorBase.sol index ff1a945c..8316e557 100644 --- a/contracts/validators/request/CredentialAtomicQueryV2ValidatorBase.sol +++ b/contracts/validators/request/CredentialAtomicQueryV2ValidatorBase.sol @@ -5,6 +5,13 @@ import {CredentialAtomicQueryValidatorBase} from "./CredentialAtomicQueryValidat import {IGroth16Verifier} from "../../interfaces/IGroth16Verifier.sol"; import {IRequestValidator} from "../../interfaces/IRequestValidator.sol"; +error CircuitsLengthShouldBeOne(); +error VerifierAddressShouldNotBeZero(); +error ProofIsNotValid(); +error QueryHashDoesNotMatchTheRequestedOne(uint256 expected, uint256 actual); +error MerklizedValueIsNotCorrect(); +error RevocationCheckShouldMatchTheQuery(uint256 expected, uint256 actual); + /** * @dev Base contract for credential atomic query v2 validators circuits. */ @@ -107,22 +114,30 @@ abstract contract CredentialAtomicQueryV2ValidatorBase is CredentialAtomicQueryV CredentialAtomicQuery memory credAtomicQuery = abi.decode(params, (CredentialAtomicQuery)); - require(credAtomicQuery.circuitIds.length == 1, "circuitIds length is not equal to 1"); + if (credAtomicQuery.circuitIds.length != 1) { + revert CircuitsLengthShouldBeOne(); + } IGroth16Verifier g16Verifier = getVerifierByCircuitId(credAtomicQuery.circuitIds[0]); - require(g16Verifier != IGroth16Verifier(address(0)), "Verifier address should not be zero"); + if (g16Verifier == IGroth16Verifier(address(0))) { + revert VerifierAddressShouldNotBeZero(); + } // verify that zkp is valid - require(g16Verifier.verify(a, b, c, inputs), "Proof is not valid"); + if (!g16Verifier.verify(a, b, c, inputs)) { + revert ProofIsNotValid(); + } PubSignals memory pubSignals = parsePubSignals(inputs); // check circuitQueryHash - require( - pubSignals.circuitQueryHash == credAtomicQuery.queryHash, - "Query hash does not match the requested one" - ); + if (pubSignals.circuitQueryHash != credAtomicQuery.queryHash) { + revert QueryHashDoesNotMatchTheRequestedOne( + credAtomicQuery.queryHash, + pubSignals.circuitQueryHash + ); + } // TODO: add support for query to specific userID and then verifying it @@ -147,7 +162,9 @@ abstract contract CredentialAtomicQueryV2ValidatorBase is CredentialAtomicQueryV function _checkMerklized(uint256 merklized, uint256 queryClaimPathKey) internal pure { uint256 shouldBeMerklized = queryClaimPathKey != 0 ? 1 : 0; - require(merklized == shouldBeMerklized, "Merklized value is not correct"); + if (merklized != shouldBeMerklized) { + revert MerklizedValueIsNotCorrect(); + } } function _checkIsRevocationChecked( @@ -158,10 +175,12 @@ abstract contract CredentialAtomicQueryV2ValidatorBase is CredentialAtomicQueryV if (skipClaimRevocationCheck) { expectedIsRevocationChecked = 0; } - require( - isRevocationChecked == expectedIsRevocationChecked, - "Revocation check should match the query" - ); + if (isRevocationChecked != expectedIsRevocationChecked) { + revert RevocationCheckShouldMatchTheQuery( + expectedIsRevocationChecked, + isRevocationChecked + ); + } } function _getResponseFields( diff --git a/contracts/validators/request/CredentialAtomicQueryV3Validator.sol b/contracts/validators/request/CredentialAtomicQueryV3Validator.sol index 367a0bdd..3bb9f901 100644 --- a/contracts/validators/request/CredentialAtomicQueryV3Validator.sol +++ b/contracts/validators/request/CredentialAtomicQueryV3Validator.sol @@ -5,9 +5,16 @@ import {CredentialAtomicQueryValidatorBase} from "./CredentialAtomicQueryValidat import {IGroth16Verifier} from "../../interfaces/IGroth16Verifier.sol"; import {GenesisUtils} from "../../lib/GenesisUtils.sol"; import {IRequestValidator} from "../../interfaces/IRequestValidator.sol"; -import {IState} from "../../interfaces/IState.sol"; error VerifierIDNotSet(); +error QueryHashDoesNotMatchTheRequestedOne(uint256 expected, uint256 actual); +error VerifierAddressShouldNotBeZero(); +error CircuitsLengthShouldBeOne(); +error ProofIsNotValid(); +error InvalidLinkIDPubSignal(); +error ProofTypeShouldMatchTheRequestedOneInQuery(); +error InvalidNullifyPubSignal(); +error UserIDDoesNotCorrespondToTheSender(); /** * @dev CredentialAtomicQueryV3 validator @@ -213,10 +220,12 @@ contract CredentialAtomicQueryV3Validator is CredentialAtomicQueryValidatorBase _checkChallenge(pubSignals.challenge, sender); // check circuitQueryHash - require( - pubSignals.circuitQueryHash == credAtomicQuery.queryHash, - "Query hash does not match the requested one" - ); + if (pubSignals.circuitQueryHash != credAtomicQuery.queryHash) { + revert QueryHashDoesNotMatchTheRequestedOne( + credAtomicQuery.queryHash, + pubSignals.circuitQueryHash + ); + } // if operator == 16 then we have selective disclosure return (pubSignals, credAtomicQuery.operator == 16); @@ -229,42 +238,49 @@ contract CredentialAtomicQueryV3Validator is CredentialAtomicQueryValidatorBase uint256[2] memory c, CredentialAtomicQueryV3 memory credAtomicQuery ) internal view { - require(credAtomicQuery.circuitIds.length == 1, "circuitIds length is not equal to 1"); + if (credAtomicQuery.circuitIds.length != 1) { + revert CircuitsLengthShouldBeOne(); + } IGroth16Verifier g16Verifier = getVerifierByCircuitId(credAtomicQuery.circuitIds[0]); - require(g16Verifier != IGroth16Verifier(address(0)), "Verifier address should not be zero"); + if (g16Verifier == IGroth16Verifier(address(0))) { + revert VerifierAddressShouldNotBeZero(); + } // verify that zkp is valid - require(g16Verifier.verify(a, b, c, inputs), "Proof is not valid"); + if (!g16Verifier.verify(a, b, c, inputs)) { + revert ProofIsNotValid(); + } } function _checkLinkID(uint256 groupID, uint256 linkID) internal pure { - require( - (groupID == 0 && linkID == 0) || (groupID != 0 && linkID != 0), - "Invalid Link ID pub signal" - ); + if (!((groupID == 0 && linkID == 0) || (groupID != 0 && linkID != 0))) { + revert InvalidLinkIDPubSignal(); + } } function _checkProofType(uint256 queryProofType, uint256 pubSignalProofType) internal pure { - require( - queryProofType == 0 || queryProofType == pubSignalProofType, - "Proof type should match the requested one in query" - ); + if (queryProofType != 0 && queryProofType != pubSignalProofType) { + revert ProofTypeShouldMatchTheRequestedOneInQuery(); + } } function _checkNullify(uint256 nullifier, uint256 nullifierSessionID) internal pure { - require(nullifierSessionID == 0 || nullifier != 0, "Invalid nullify pub signal"); + if (nullifierSessionID != 0 && nullifier == 0) { + revert InvalidNullifyPubSignal(); + } } function _checkAuth(uint256 userID, address ethIdentityOwner) internal view { - require( - userID == - GenesisUtils.calcIdFromEthAddress( - _getState().getIdTypeIfSupported(userID), - ethIdentityOwner - ), - "UserID does not correspond to the sender" - ); + if ( + userID != + GenesisUtils.calcIdFromEthAddress( + _getState().getIdTypeIfSupported(userID), + ethIdentityOwner + ) + ) { + revert UserIDDoesNotCorrespondToTheSender(); + } } function _getResponseFields( @@ -275,7 +291,7 @@ contract CredentialAtomicQueryV3Validator is CredentialAtomicQueryValidatorBase IRequestValidator.ResponseField[] memory responseFields = new IRequestValidator.ResponseField[](numSignals); - uint i = 0; + uint256 i = 0; responseFields[i++] = IRequestValidator.ResponseField({ name: "userID", value: pubSignals.userID diff --git a/contracts/validators/request/CredentialAtomicQueryValidatorBase.sol b/contracts/validators/request/CredentialAtomicQueryValidatorBase.sol index da86a280..1255b437 100644 --- a/contracts/validators/request/CredentialAtomicQueryValidatorBase.sol +++ b/contracts/validators/request/CredentialAtomicQueryValidatorBase.sol @@ -9,6 +9,15 @@ import {IGroth16Verifier} from "../../interfaces/IGroth16Verifier.sol"; import {IState} from "../../interfaces/IState.sol"; import {PrimitiveTypeUtils} from "../../lib/PrimitiveTypeUtils.sol"; +error InputNameNotFound(); +error RequestParamNameNotFound(); +error ChallengeShouldMatchTheSender(); +error GistRootIsExpired(); +error NonRevocationStateOfIssuerIsExpired(); +error ProofGeneratedInTheFutureIsNotValid(); +error GeneratedProofIsOutdated(); +error IssuerIsNotOnTheAllowedIssuersList(); + /** * @dev Base contract for credential atomic query validators circuits. */ @@ -162,7 +171,9 @@ abstract contract CredentialAtomicQueryValidatorBase is */ function inputIndexOf(string memory name) public view virtual returns (uint256) { uint256 index = _getCredentialAtomicQueryValidatorBaseStorage()._inputNameToIndex[name]; - require(index != 0, "Input name not found"); + if (index == 0) { + revert InputNameNotFound(); + } return --index; // we save 1-based index, but return 0-based } @@ -175,7 +186,9 @@ abstract contract CredentialAtomicQueryValidatorBase is uint256 index = _getCredentialAtomicQueryValidatorBaseStorage()._requestParamNameToIndex[ name ]; - require(index != 0, "Request param name not found"); + if (index == 0) { + revert RequestParamNameNotFound(); + } return --index; // we save 1-based index, but return 0-based } @@ -213,7 +226,7 @@ abstract contract CredentialAtomicQueryValidatorBase is uint256 replacedAt = $.state.getGistRootReplacedAt(idType, _gistRoot); if (replacedAt != 0 && block.timestamp > $.gistRootExpirationTimeout + replacedAt) { - revert("Gist root is expired"); + revert GistRootIsExpired(); } } @@ -231,7 +244,7 @@ abstract contract CredentialAtomicQueryValidatorBase is uint256 replacedAt = _getState().getStateReplacedAt(_id, _claimNonRevState); if (replacedAt != 0 && block.timestamp > $.revocationStateExpirationTimeout + replacedAt) { - revert("Non-Revocation state of Issuer expired"); + revert NonRevocationStateOfIssuerIsExpired(); } } @@ -242,14 +255,14 @@ abstract contract CredentialAtomicQueryValidatorBase is https://github.com/ethereum/go-ethereum/issues/24152 */ if (_proofGenerationTimestamp > (block.timestamp + 5 minutes)) { - revert("Proof generated in the future is not valid"); + revert ProofGeneratedInTheFutureIsNotValid(); } if ( block.timestamp > _getCredentialAtomicQueryValidatorBaseStorage().proofExpirationTimeout + _proofGenerationTimestamp ) { - revert("Generated proof is outdated"); + revert GeneratedProofIsOutdated(); } } @@ -259,20 +272,19 @@ abstract contract CredentialAtomicQueryValidatorBase is return; } - for (uint i = 0; i < allowedIssuers.length; i++) { + for (uint256 i = 0; i < allowedIssuers.length; i++) { if (issuerId == allowedIssuers[i]) { return; } } - revert("Issuer is not on the Allowed Issuers list"); + revert IssuerIsNotOnTheAllowedIssuersList(); } function _checkChallenge(uint256 challenge, address sender) internal pure { - require( - PrimitiveTypeUtils.uint256LEToAddress(challenge) == sender, - "Challenge should match the sender" - ); + if (PrimitiveTypeUtils.uint256LEToAddress(challenge) != sender) { + revert ChallengeShouldMatchTheSender(); + } } function _setInputToIndex(string memory inputName, uint256 index) internal { diff --git a/contracts/validators/request/LinkedMultiQueryValidator.sol b/contracts/validators/request/LinkedMultiQueryValidator.sol index f2c5d012..9767e26d 100644 --- a/contracts/validators/request/LinkedMultiQueryValidator.sol +++ b/contracts/validators/request/LinkedMultiQueryValidator.sol @@ -4,7 +4,6 @@ pragma solidity ^0.8.10; import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol"; import {IGroth16Verifier} from "../../interfaces/IGroth16Verifier.sol"; import {IRequestValidator} from "../../interfaces/IRequestValidator.sol"; -import {IState} from "../../interfaces/IState.sol"; import {Ownable2StepUpgradeable} from "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; @@ -13,6 +12,7 @@ error InvalidQueryHash(uint256 expectedQueryHash, uint256 actualQueryHash); error InvalidGroupID(uint256 groupID); error TooManyQueries(uint256 operatorCount); error InvalidGroth16Proof(); +error RequestParamNameNotFound(); contract LinkedMultiQueryValidator is Ownable2StepUpgradeable, IRequestValidator, ERC165 { // This should be limited to the real number of queries in which operator != 0 @@ -98,6 +98,7 @@ contract LinkedMultiQueryValidator is Ownable2StepUpgradeable, IRequestValidator * @return Array of response fields as result. */ function verify( + // solhint-disable-next-line no-unused-vars address sender, bytes calldata proof, bytes calldata params @@ -156,7 +157,9 @@ contract LinkedMultiQueryValidator is Ownable2StepUpgradeable, IRequestValidator string memory name ) public view virtual override returns (uint256) { uint256 index = _getLinkedMultiQueryValidatorStorage()._requestParamNameToIndex[name]; - require(index != 0, "Request param name not found"); + if (index == 0) { + revert RequestParamNameNotFound(); + } return --index; // we save 1-based index, but return 0-based } diff --git a/test/validators/mtp/index.ts b/test/validators/mtp/index.ts index 06c7cdb4..a2a67a54 100644 --- a/test/validators/mtp/index.ts +++ b/test/validators/mtp/index.ts @@ -87,7 +87,7 @@ const testCases: any[] = [ stateTransitionDelayMs: 2000, // [1....][2....][3....][4....] - each block is 2 seconds long proofJson: require("./data/valid_mtp_user_non_genesis.json"), setRevStateExpiration: 3, // [1....][2....][3..*.][4....] <-- (*) - marks where the expiration threshold is - errorMessage: "Non-Revocation state of Issuer expired", + errorMessage: "NonRevocationStateOfIssuerIsExpired()", setProofExpiration: tenYears, }, { @@ -101,7 +101,7 @@ const testCases: any[] = [ stateTransitionDelayMs: 2000, // [1....][2....][3....][4....] - each block is 2 seconds long proofJson: require("./data/valid_mtp_user_non_genesis.json"), // generated on step 2 setGISTRootExpiration: 3, // [1....][2....][3..*.][4....] <-- (*) - marks where the expiration threshold is - errorMessage: "Gist root is expired", + errorMessage: "GistRootIsExpired()", setProofExpiration: tenYears, }, { @@ -112,7 +112,7 @@ const testCases: any[] = [ require("../common-data/issuer_next_state_transition.json"), ], proofJson: require("./data/valid_mtp_user_non_genesis.json"), - errorMessage: "Generated proof is outdated", + errorMessage: "GeneratedProofIsOutdated()", }, { name: "Validate Genesis User State. Issuer Claim IdenState is in Chain. Revocation State is in Chain", @@ -120,7 +120,7 @@ const testCases: any[] = [ proofJson: require("./data/valid_mtp_user_genesis.json"), setProofExpiration: tenYears, allowedIssuers: [123n], - errorMessage: "Issuer is not on the Allowed Issuers list", + errorMessage: "IssuerIsNotOnTheAllowedIssuersList()", }, ]; diff --git a/test/validators/sig/index.ts b/test/validators/sig/index.ts index 9684b3db..0e756690 100644 --- a/test/validators/sig/index.ts +++ b/test/validators/sig/index.ts @@ -87,7 +87,7 @@ const testCases: any[] = [ stateTransitionDelayMs: 2000, // [1....][2....][3....][4....] - each block is 2 seconds long proofJson: require("./data/valid_sig_user_non_genesis.json"), setRevStateExpiration: 3, // [1....][2....][3..*.][4....] <-- (*) - marks where the expiration threshold is - errorMessage: "Non-Revocation state of Issuer expired", + errorMessage: "NonRevocationStateOfIssuerIsExpired()", setProofExpiration: tenYears, }, { @@ -101,7 +101,7 @@ const testCases: any[] = [ stateTransitionDelayMs: 2000, // [1....][2....][3....][4....] - each block is 2 seconds long proofJson: require("./data/valid_sig_user_non_genesis.json"), // generated on step 2 setGISTRootExpiration: 3, // [1....][2....][3..*.][4....] <-- (*) - marks where the expiration threshold is - errorMessage: "Gist root is expired", + errorMessage: "GistRootIsExpired()", setProofExpiration: tenYears, }, { @@ -112,7 +112,7 @@ const testCases: any[] = [ require("../common-data/issuer_next_state_transition.json"), ], proofJson: require("./data/valid_sig_user_non_genesis.json"), - errorMessage: "Generated proof is outdated", + errorMessage: "GeneratedProofIsOutdated()", }, { name: "Validate Genesis User State. Issuer Claim IdenState is in Chain. Revocation State is in Chain", @@ -120,7 +120,7 @@ const testCases: any[] = [ proofJson: require("./data/valid_sig_user_genesis.json"), setProofExpiration: tenYears, allowedIssuers: [123n], - errorMessage: "Issuer is not on the Allowed Issuers list", + errorMessage: "IssuerIsNotOnTheAllowedIssuersList()", }, ]; diff --git a/test/validators/v3/index.ts b/test/validators/v3/index.ts index 86956b29..87635cf9 100644 --- a/test/validators/v3/index.ts +++ b/test/validators/v3/index.ts @@ -46,7 +46,7 @@ const testCases: any[] = [ require("../common-data/issuer_from_genesis_state_to_first_transition_v3.json"), ], proofJson: require("./data/invalid_bjj_user_genesis_v3.json"), - errorMessage: "Proof is not valid", + errorMessage: "ProofIsNotValid()", setProofExpiration: tenYears, sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", }, @@ -121,7 +121,7 @@ const testCases: any[] = [ stateTransitionDelayMs: 2000, // [1....][2....][3....][4....] - each block is 2 seconds long proofJson: require("./data/valid_bjj_user_second_issuer_first_v3"), setRevStateExpiration: 3, // [1....][2....][3..*.][4....] <-- (*) - marks where the expiration threshold is - errorMessage: "Non-Revocation state of Issuer expired", + errorMessage: "NonRevocationStateOfIssuerIsExpired()", setProofExpiration: tenYears, sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", }, @@ -137,7 +137,7 @@ const testCases: any[] = [ stateTransitionDelayMs: 2000, // [1....][2....][3....][4....] - each block is 2 seconds long setGISTRootExpiration: 3, // [1....][2....][3..*.][4....] <-- (*) - marks where the expiration threshold is - errorMessage: "Gist root is expired", + errorMessage: "GistRootIsExpired()", setProofExpiration: tenYears, sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", }, @@ -149,7 +149,7 @@ const testCases: any[] = [ require("../common-data/issuer_from_first_state_to_second_transition_v3.json"), ], proofJson: require("./data/valid_bjj_user_first_v3.json"), - errorMessage: "Generated proof is outdated", + errorMessage: "GeneratedProofIsOutdated()", sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", }, { @@ -160,7 +160,7 @@ const testCases: any[] = [ proofJson: require("./data/valid_bjj_user_genesis_v3.json"), setProofExpiration: tenYears, allowedIssuers: [123n], - errorMessage: "Issuer is not on the Allowed Issuers list", + errorMessage: "IssuerIsNotOnTheAllowedIssuersList()", sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", }, { @@ -228,7 +228,7 @@ const testCases: any[] = [ require("../common-data/issuer_from_genesis_state_to_first_transition_v3.json"), ], proofJson: require("./data/invalid_mtp_user_genesis_v3.json"), - errorMessage: "Proof is not valid", + errorMessage: "ProofIsNotValid()", setProofExpiration: tenYears, isMtpProof: true, sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", @@ -305,7 +305,7 @@ const testCases: any[] = [ stateTransitionDelayMs: 2000, // [1....][2....][3....][4....] - each block is 2 seconds long proofJson: require("./data/valid_mtp_user_second_issuer_first_v3.json"), setRevStateExpiration: 3, // [1....][2....][3..*.][4....] <-- (*) - marks where the expiration threshold is - errorMessage: "Non-Revocation state of Issuer expired", + errorMessage: "NonRevocationStateOfIssuerIsExpired()", setProofExpiration: tenYears, isMtpProof: true, sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", @@ -321,7 +321,7 @@ const testCases: any[] = [ proofJson: require("./data/valid_mtp_user_first_v3"), stateTransitionDelayMs: 2000, // [1....][2....][3....][4....] - each block is 2 seconds long setGISTRootExpiration: 3, // [1....][2....][3..*.][4....] <-- (*) - marks where the expiration threshold is - errorMessage: "Gist root is expired", + errorMessage: "GistRootIsExpired()", setProofExpiration: tenYears, isMtpProof: true, sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", @@ -334,7 +334,7 @@ const testCases: any[] = [ require("../common-data/issuer_from_first_state_to_second_transition_v3.json"), ], proofJson: require("./data/valid_mtp_user_first_v3.json"), - errorMessage: "Generated proof is outdated", + errorMessage: "GeneratedProofIsOutdated()", isMtpProof: true, sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", }, @@ -346,7 +346,7 @@ const testCases: any[] = [ proofJson: require("./data/valid_mtp_user_genesis_v3.json"), setProofExpiration: tenYears, allowedIssuers: [123n], - errorMessage: "Issuer is not on the Allowed Issuers list", + errorMessage: "IssuerIsNotOnTheAllowedIssuersList()", isMtpProof: true, sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", }, @@ -388,7 +388,7 @@ const testCases: any[] = [ ], proofJson: require("./data/valid_bjj_user_genesis_auth_disabled_v3_wrong_id.json"), setProofExpiration: tenYears, - errorMessage: "UserID does not correspond to the sender", + errorMessage: "UserIDDoesNotCorrespondToTheSender()", ethereumBasedUser: true, sender: "0x6edFa588aFd58803F728AbC91984c69528C00854", }, @@ -399,7 +399,7 @@ const testCases: any[] = [ ], proofJson: require("./data/valid_mtp_user_genesis_auth_disabled_v3_wrong_id.json"), setProofExpiration: tenYears, - errorMessage: "UserID does not correspond to the sender", + errorMessage: "UserIDDoesNotCorrespondToTheSender()", ethereumBasedUser: true, isMtpProof: true, sender: "0x6edFa588aFd58803F728AbC91984c69528C00854", @@ -440,7 +440,7 @@ const testCases: any[] = [ require("../common-data/user_from_genesis_state_to_first_transition_v3.json"), ], proofJson: require("./data/valid_bjj_user_first_issuer_genesis_v3.json"), - errorMessage: "Challenge should match the sender", + errorMessage: "ChallengeShouldMatchTheSender()", setProofExpiration: tenYears, sender: "0x0000000000000000000000000000000000000000", }, @@ -453,7 +453,7 @@ const testCases: any[] = [ proofJson: require("./data/valid_bjj_user_genesis_auth_disabled_v3.json"), setProofExpiration: tenYears, ethereumBasedUser: true, - errorMessage: "Invalid Link ID pub signal", + errorMessage: "InvalidLinkIDPubSignal()", sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", groupID: 0, }, @@ -466,7 +466,7 @@ const testCases: any[] = [ proofJson: require("./data/valid_bjj_user_genesis_auth_disabled_v3.json"), setProofExpiration: tenYears, ethereumBasedUser: true, - errorMessage: "Proof type should match the requested one in query", + errorMessage: "ProofTypeShouldMatchTheRequestedOneInQuery()", sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", isMtpProof: true, }, @@ -479,7 +479,7 @@ const testCases: any[] = [ proofJson: require("./data/valid_bjj_user_genesis_auth_disabled_v3.json"), setProofExpiration: tenYears, ethereumBasedUser: true, - errorMessage: "Invalid nullify pub signal", + errorMessage: "InvalidNullifyPubSignal()", sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", nullifierSessionId: "2", }, @@ -492,7 +492,8 @@ const testCases: any[] = [ proofJson: require("./data/valid_bjj_user_genesis_auth_disabled_v3.json"), setProofExpiration: tenYears, ethereumBasedUser: true, - errorMessage: "Query hash does not match the requested one", + errorMessage: + "QueryHashDoesNotMatchTheRequestedOne(0, 19185468473610285815446195195707572856383167010831244369191309337886545428382)", sender: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", queryHash: BigInt(0), },