diff --git a/common/src/constants/constants.ts b/common/src/constants/constants.ts index b062585bc..2d83c17cb 100644 --- a/common/src/constants/constants.ts +++ b/common/src/constants/constants.ts @@ -21,7 +21,7 @@ export const PCR0_MANAGER_ADDRESS = '0xE36d4EE5Fd3916e703A46C21Bb3837dB7680C8B8' // we make it global here because passing it to generateCircuitInputsRegister caused trouble -export const DEVELOPMENT_MODE = false; +export const DEVELOPMENT_MODE = true; export const DEFAULT_MAJORITY = '18'; export const hashAlgos = ['sha512', 'sha384', 'sha256', 'sha224', 'sha1']; diff --git a/contracts/contracts/tests/testUpgradedIdentityRegistryImplV1.sol b/contracts/contracts/tests/testUpgradedIdentityRegistryImplV1.sol index f368b8764..726a112b8 100644 --- a/contracts/contracts/tests/testUpgradedIdentityRegistryImplV1.sol +++ b/contracts/contracts/tests/testUpgradedIdentityRegistryImplV1.sol @@ -2,6 +2,7 @@ pragma solidity 0.8.28; import {IdentityRegistryStorageV1} from "../registry/IdentityRegistryImplV1.sol"; +import { InternalLeanIMT, LeanIMTData } from "@zk-kit/imt.sol/internal/InternalLeanIMT.sol"; /** * @title IdentityRegistryStorageV1 @@ -22,6 +23,8 @@ contract testUpgradedIdentityRegistryImplV1 is IdentityRegistryStorageV1, UpgradedIdentityRegistryStorageV1 { + using InternalLeanIMT for LeanIMTData; + // ==================================================== // Events // ==================================================== @@ -76,4 +79,193 @@ contract testUpgradedIdentityRegistryImplV1 is return _isTest; } + function hub() + external + virtual + onlyProxy + view + returns (address) + { + return _hub; + } + + function nullifiers( + bytes32 attestationId, + uint256 nullifier + ) + external + virtual + onlyProxy + view + returns (bool) + { + return _nullifiers[attestationId][nullifier]; + } + + function isRegisteredDscKeyCommitment( + uint256 commitment + ) + external + virtual + onlyProxy + view + returns (bool) + { + return _isRegisteredDscKeyCommitment[commitment]; + } + + function rootTimestamps( + uint256 root + ) + external + virtual + onlyProxy + view + returns (uint256) + { + return _rootTimestamps[root]; + } + + function checkIdentityCommitmentRoot( + uint256 root + ) + external + onlyProxy + view + returns (bool) + { + return _rootTimestamps[root] != 0; + } + + function getIdentityCommitmentMerkleTreeSize() + external + onlyProxy + view + returns (uint256) + { + return _identityCommitmentIMT.size; + } + + function getIdentityCommitmentMerkleRoot() + external + onlyProxy + view + returns (uint256) + { + return _identityCommitmentIMT._root(); + } + + function getIdentityCommitmentIndex( + uint256 commitment + ) + external + onlyProxy + view + returns (uint256) + { + return _identityCommitmentIMT._indexOf(commitment); + } + + function getPassportNoOfacRoot() + external + onlyProxy + view + returns (uint256) + { + return _passportNoOfacRoot; + } + + function getNameAndDobOfacRoot() + external + onlyProxy + view + returns (uint256) + { + return _nameAndDobOfacRoot; + } + + function getNameAndYobOfacRoot() + external + onlyProxy + view + returns (uint256) + { + return _nameAndYobOfacRoot; + } + + function checkOfacRoots( + uint256 passportNoRoot, + uint256 nameAndDobRoot, + uint256 nameAndYobRoot + ) + external + onlyProxy + view + returns (bool) + { + return _passportNoOfacRoot == passportNoRoot + && _nameAndDobOfacRoot == nameAndDobRoot + && _nameAndYobOfacRoot == nameAndYobRoot; + } + + function getCscaRoot() + external + onlyProxy + view + returns (uint256) + { + return _cscaRoot; + } + + function checkCscaRoot( + uint256 root + ) + external + onlyProxy + view + returns (bool) + { + return _cscaRoot == root; + } + + function getDscKeyCommitmentMerkleRoot() + external + onlyProxy + view + returns (uint256) + { + return _dscKeyCommitmentIMT._root(); + } + + function checkDscKeyCommitmentMerkleRoot( + uint256 root + ) + external + onlyProxy + view + returns (bool) + { + return _dscKeyCommitmentIMT._root() == root; + } + + function getDscKeyCommitmentTreeSize() + external + onlyProxy + view + returns (uint256) + { + return _dscKeyCommitmentIMT.size; + } + + function getDscKeyCommitmentIndex( + uint256 commitment + ) + external + onlyProxy + view + returns (uint256) + { + return _dscKeyCommitmentIMT._indexOf(commitment); + } + } \ No newline at end of file diff --git a/contracts/contracts/tests/testUpgradedIdentityVerificationHubImplV1.sol b/contracts/contracts/tests/testUpgradedIdentityVerificationHubImplV1.sol index 57457c484..1b3cd81d9 100644 --- a/contracts/contracts/tests/testUpgradedIdentityVerificationHubImplV1.sol +++ b/contracts/contracts/tests/testUpgradedIdentityVerificationHubImplV1.sol @@ -73,4 +73,48 @@ contract testUpgradedIdentityVerificationHubImplV1 is return _isTest; } + function registry() + external + virtual + onlyProxy + view + returns (address) + { + return _registry; + } + + function vcAndDiscloseCircuitVerifier() + external + virtual + onlyProxy + view + returns (address) + { + return _vcAndDiscloseCircuitVerifier; + } + + function sigTypeToRegisterCircuitVerifiers( + uint256 typeId + ) + external + virtual + onlyProxy + view + returns (address) + { + return _sigTypeToRegisterCircuitVerifiers[typeId]; + } + + function sigTypeToDscCircuitVerifiers( + uint256 typeId + ) + external + virtual + onlyProxy + view + returns (address) + { + return _sigTypeToDscCircuitVerifiers[typeId]; + } + } \ No newline at end of file diff --git a/contracts/package.json b/contracts/package.json index 9721585b6..b345515c0 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -58,6 +58,7 @@ "test:local": "TEST_ENV=local npx hardhat test", "test:register:local": "TEST_ENV=local npx hardhat test test/integration/commitmentRegistration.test.ts", "test:registry:local": "TEST_ENV=local npx hardhat test test/unit/IdentityRegistry.test.ts", + "test:pcr:local": "TEST_ENV=local npx hardhat test test/unit/PCR0Manager.test.ts", "test:unit:local": "TEST_ENV=local npx hardhat test test/unit/*", "test:view": "npx hardhat test test/view.ts", "update:cscaroot:sepolia": "npx hardhat ignition deploy ignition/modules/scripts/updateRegistryCscaRoot.ts --network sepolia", diff --git a/contracts/test/integration/commitmentRegistration.test.ts b/contracts/test/integration/commitmentRegistration.test.ts index 74461fa17..09784a6c0 100644 --- a/contracts/test/integration/commitmentRegistration.test.ts +++ b/contracts/test/integration/commitmentRegistration.test.ts @@ -7,7 +7,7 @@ import { ATTESTATION_ID } from "../utils/constants"; import { generateRegisterProof, generateDscProof } from "../utils/generateProof"; import { generateRandomFieldElement } from "../utils/utils"; import { TransactionReceipt, ZeroAddress } from "ethers"; -import serialized_dsc_tree from '../../../common/pubkeys/serialized_dsc_tree.json'; +import serialized_dsc_tree from '../utils/pubkeys/serialized_dsc_tree.json'; import { LeanIMT } from "@openpassport/zk-kit-lean-imt"; import {poseidon2} from "poseidon-lite"; diff --git a/contracts/test/integration/endToEnd.test.ts b/contracts/test/integration/endToEnd.test.ts index 9460971ac..a168d22c5 100644 --- a/contracts/test/integration/endToEnd.test.ts +++ b/contracts/test/integration/endToEnd.test.ts @@ -6,8 +6,8 @@ import { RegisterVerifierId, DscVerifierId, CIRCUIT_CONSTANTS } from "../../../c import { ATTESTATION_ID } from "../utils/constants"; import { generateRegisterProof, generateDscProof, generateVcAndDiscloseProof } from "../utils/generateProof"; import { generateRandomFieldElement, splitHexFromBack } from "../utils/utils"; -import { TransactionReceipt, ZeroAddress } from "ethers"; -import serialized_dsc_tree from '../../../common/pubkeys/serialized_dsc_tree.json'; +import { BigNumberish, TransactionReceipt, ZeroAddress } from "ethers"; +import serialized_dsc_tree from '../utils/pubkeys/serialized_dsc_tree.json'; import { LeanIMT } from "@openpassport/zk-kit-lean-imt"; import {poseidon2} from "poseidon-lite"; import { castFromScope } from "../../../common/src/utils/circuits/uuid"; @@ -179,15 +179,13 @@ describe("End to End Tests", function () { const airdropFactory = await ethers.getContractFactory("Airdrop"); const airdrop = await airdropFactory.connect(owner).deploy( hub.target, - registry.target, castFromScope("test-scope"), ATTESTATION_ID.E_PASSPORT, token.target, - rootTimestamp, true, 20, true, - countriesListPacked, + countriesListPacked as [BigNumberish, BigNumberish, BigNumberish, BigNumberish], [true, true, true], ); await airdrop.waitForDeployment(); @@ -195,7 +193,7 @@ describe("End to End Tests", function () { await token.connect(owner).mint(airdrop.target, BigInt(1000000000000000000)); await airdrop.connect(owner).openRegistration(); - await airdrop.connect(user1).registerAddress(vcAndDiscloseProof); + await airdrop.connect(user1).verifySelfProof(vcAndDiscloseProof); await airdrop.connect(owner).closeRegistration(); const tree = new BalanceTree([ diff --git a/contracts/test/integration/vcAndDisclose.test.ts b/contracts/test/integration/vcAndDisclose.test.ts index 51efd83bb..07ae4eb92 100644 --- a/contracts/test/integration/vcAndDisclose.test.ts +++ b/contracts/test/integration/vcAndDisclose.test.ts @@ -86,8 +86,6 @@ describe("VC and Disclose", () => { it("should verify and get result successfully", async () => { const {hub, registry, owner} = deployedActors; - console.log(vcAndDiscloseProof.pubSignals); - // console.log("root in proof: ", vcAndDiscloseProof.pubSignals[CIRCUIT_CONSTANTS.VC_AND_DISCLOSE_MERKLE_ROOT_INDEX]); const vcAndDiscloseHubProof = { olderThanEnabled: true, diff --git a/contracts/test/integration/verifyAll.test.ts b/contracts/test/integration/verifyAll.test.ts index 41e7ae1ff..b139efd76 100644 --- a/contracts/test/integration/verifyAll.test.ts +++ b/contracts/test/integration/verifyAll.test.ts @@ -12,6 +12,7 @@ import { generateVcAndDiscloseProof, parseSolidityCalldata } from "../utils/gene import { Formatter } from "../utils/formatter"; import { formatCountriesList, reverseBytes } from "../../../common/src/utils/circuits/formatInputs"; import { VerifyAll } from "../../typechain-types"; +import { getSMTs } from "../utils/generateProof"; import { Groth16Proof, PublicSignals, groth16 } from "snarkjs"; import { VcAndDiscloseProof } from "../utils/types"; @@ -26,7 +27,9 @@ describe("VerifyAll", () => { let commitment: any; let nullifier: any; let forbiddenCountriesList: string[]; + let invalidForbiddenCountriesList: string[]; let forbiddenCountriesListPacked: string[]; + let invalidForbiddenCountriesListPacked: string[]; before(async () => { deployedActors = await deploySystemFixtures(); @@ -44,8 +47,13 @@ describe("VerifyAll", () => { imt = new LeanIMT(hashFunction); await imt.insert(BigInt(commitment)); - forbiddenCountriesList = ['AAA', 'ABC', 'CBA']; - forbiddenCountriesListPacked = splitHexFromBack(reverseBytes(Formatter.bytesToHexString(new Uint8Array(formatCountriesList(forbiddenCountriesList))))); + forbiddenCountriesList = ['AAA', 'ABC', 'CBA', 'AAA', 'AAA', 'ABC', 'CBA', 'AAA', 'ABC', 'CBA','AAA', 'ABC', 'CBA', 'AAA', 'ABC', 'CBA', 'AAA', 'ABC', 'CBA', 'AAA', 'ABC', 'CBA','AAA', 'ABC', 'CBA', 'AAA', 'ABC', 'CBA','AAA', 'ABC', 'CBA', 'AAA', 'ABC', 'CBA', 'AAA', 'ABC', 'CBA', 'AAA', 'ABC', 'CBA']; + const wholePacked = reverseBytes(Formatter.bytesToHexString(new Uint8Array(formatCountriesList(forbiddenCountriesList)))); + forbiddenCountriesListPacked = splitHexFromBack(wholePacked); + + invalidForbiddenCountriesList = ['AAA', 'ABC', 'CBA', 'CBA']; + const invalidWholePacked = reverseBytes(Formatter.bytesToHexString(new Uint8Array(formatCountriesList(invalidForbiddenCountriesList)))); + invalidForbiddenCountriesListPacked = splitHexFromBack(invalidWholePacked); baseVcAndDiscloseProof = await generateVcAndDiscloseProof( registerSecret, @@ -196,6 +204,304 @@ describe("VerifyAll", () => { expect(success).to.be.false; expect(readableData.name).to.be.empty; }); + + describe("Error Handling", () => { + it("should return error code 'INVALID_VC_AND_DISCLOSE_PROOF' when proof is invalid", async () => { + const {registry, owner} = deployedActors; + await registry.connect(owner).devAddIdentityCommitment( + ATTESTATION_ID.E_PASSPORT, + nullifier, + commitment + ); + + vcAndDiscloseProof.a[0] = generateRandomFieldElement(); + + const vcAndDiscloseHubProof = { + olderThanEnabled: false, + olderThan: "20", + forbiddenCountriesEnabled: false, + forbiddenCountriesListPacked: forbiddenCountriesListPacked, + ofacEnabled: [false, false, false], + vcAndDiscloseProof: vcAndDiscloseProof + }; + + const types = ["0", "1", "2"]; + const [readableData, success, errorCode] = await verifyAll.verifyAll( + 0, + vcAndDiscloseHubProof, + types + ); + + expect(success).to.be.false; + expect(errorCode).to.equal("INVALID_VC_AND_DISCLOSE_PROOF"); + expect(readableData.name).to.be.empty; + }); + + it("should return error code 'CURRENT_DATE_NOT_IN_VALID_RANGE' when date is invalid", async () => { + const {registry, owner} = deployedActors; + await registry.connect(owner).devAddIdentityCommitment( + ATTESTATION_ID.E_PASSPORT, + nullifier, + commitment + ); + + vcAndDiscloseProof.pubSignals[CIRCUIT_CONSTANTS.VC_AND_DISCLOSE_CURRENT_DATE_INDEX] = 0; + + const vcAndDiscloseHubProof = { + olderThanEnabled: true, + olderThan: "20", + forbiddenCountriesEnabled: true, + forbiddenCountriesListPacked: forbiddenCountriesListPacked, + ofacEnabled: [true, true, true], + vcAndDiscloseProof: vcAndDiscloseProof + }; + + const types = ["0", "1", "2"]; + const [readableData, success, errorCode] = await verifyAll.verifyAll( + 0, + vcAndDiscloseHubProof, + types + ); + + expect(success).to.be.false; + expect(errorCode).to.equal("CURRENT_DATE_NOT_IN_VALID_RANGE"); + expect(readableData.name).to.be.empty; + }); + + it("should return error code 'INVALID_OLDER_THAN' when age check fails", async () => { + const {registry, owner} = deployedActors; + await registry.connect(owner).devAddIdentityCommitment( + ATTESTATION_ID.E_PASSPORT, + nullifier, + commitment + ); + + const vcAndDiscloseHubProof = { + olderThanEnabled: true, + olderThan: "21", // Higher than the age in proof + forbiddenCountriesEnabled: false, + forbiddenCountriesListPacked: forbiddenCountriesListPacked, + ofacEnabled: [false, false, false], + vcAndDiscloseProof: vcAndDiscloseProof + }; + + const types = ["0", "1", "2"]; + const [readableData, success, errorCode] = await verifyAll.verifyAll( + 0, + vcAndDiscloseHubProof, + types + ); + + expect(success).to.be.false; + expect(errorCode).to.equal("INVALID_OLDER_THAN"); + expect(readableData.name).to.be.empty; + }); + + it("should return error code 'INVALID_OFAC' when OFAC check fails", async () => { + const {registry, owner} = deployedActors; + await registry.connect(owner).devAddIdentityCommitment( + ATTESTATION_ID.E_PASSPORT, + nullifier, + commitment + ); + + const { + passportNo_smt, + nameAndDob_smt, + nameAndYob_smt + } = getSMTs(); + + vcAndDiscloseProof = await generateVcAndDiscloseProof( + registerSecret, + BigInt(ATTESTATION_ID.E_PASSPORT).toString(), + deployedActors.mockPassport, + "test-scope", + new Array(88).fill("1"), + "1", + imt, + "20", + passportNo_smt, + nameAndDob_smt, + nameAndYob_smt, + "0" + ); + + const vcAndDiscloseHubProof = { + olderThanEnabled: true, + olderThan: "20", + forbiddenCountriesEnabled: false, + forbiddenCountriesListPacked: forbiddenCountriesListPacked, + ofacEnabled: [true, true, true], + vcAndDiscloseProof: vcAndDiscloseProof + }; + + const types = ["0", "1", "2"]; + const [readableData, success, errorCode] = await verifyAll.verifyAll( + 0, + vcAndDiscloseHubProof, + types + ); + console.log("return values"); + console.log("readable data: ", readableData); + console.log("success: ", success); + console.log("errorCode: ", errorCode); + + expect(success).to.be.false; + expect(errorCode).to.equal("INVALID_OFAC"); + expect(readableData.name).to.be.empty; + }); + + it("should return error code 'INVALID_FORBIDDEN_COUNTRIES' when countries check fails", async () => { + const {registry, owner} = deployedActors; + await registry.connect(owner).devAddIdentityCommitment( + ATTESTATION_ID.E_PASSPORT, + nullifier, + commitment + ); + + const vcAndDiscloseHubProof = { + olderThanEnabled: true, + olderThan: "20", + forbiddenCountriesEnabled: true, + forbiddenCountriesListPacked: invalidForbiddenCountriesListPacked, + ofacEnabled: [true, true, true], + vcAndDiscloseProof: vcAndDiscloseProof + }; + + const types = ["0", "1", "2"]; + const [readableData, success, errorCode] = await verifyAll.verifyAll( + 0, + vcAndDiscloseHubProof, + types + ); + + expect(success).to.be.false; + expect(errorCode).to.equal("INVALID_FORBIDDEN_COUNTRIES"); + expect(readableData.name).to.be.empty; + }); + + it("should return error code 'INVALID_TIMESTAMP' when root timestamp doesn't match", async () => { + const {registry, owner} = deployedActors; + await registry.connect(owner).devAddIdentityCommitment( + ATTESTATION_ID.E_PASSPORT, + nullifier, + commitment + ); + + const vcAndDiscloseHubProof = { + olderThanEnabled: true, + olderThan: "20", + forbiddenCountriesEnabled: true, + forbiddenCountriesListPacked: forbiddenCountriesListPacked, + ofacEnabled: [true, true, true], + vcAndDiscloseProof: vcAndDiscloseProof + }; + + const types = ["0", "1", "2"]; + const [readableData, success, errorCode] = await verifyAll.verifyAll( + 123456, // Invalid timestamp + vcAndDiscloseHubProof, + types + ); + + expect(success).to.be.false; + expect(errorCode).to.equal("INVALID_TIMESTAMP"); + expect(readableData.name).to.be.empty; + }); + + it("should return error code 'INVALID_OFAC_ROOT' when passport number OFAC root is invalid", async () => { + const {registry, owner} = deployedActors; + await registry.connect(owner).devAddIdentityCommitment( + ATTESTATION_ID.E_PASSPORT, + nullifier, + commitment + ); + + vcAndDiscloseProof.pubSignals[CIRCUIT_CONSTANTS.VC_AND_DISCLOSE_PASSPORT_NO_SMT_ROOT_INDEX] = generateRandomFieldElement(); + + const vcAndDiscloseHubProof = { + olderThanEnabled: true, + olderThan: "20", + forbiddenCountriesEnabled: true, + forbiddenCountriesListPacked: forbiddenCountriesListPacked, + ofacEnabled: [true, true, true], + vcAndDiscloseProof: vcAndDiscloseProof + }; + + const types = ["0", "1", "2"]; + const [readableData, success, errorCode] = await verifyAll.verifyAll( + 0, + vcAndDiscloseHubProof, + types + ); + + expect(success).to.be.false; + expect(errorCode).to.equal("INVALID_OFAC_ROOT"); + expect(readableData.name).to.be.empty; + }); + + it("should return error code 'INVALID_OFAC_ROOT' when name and dob OFAC root is invalid", async () => { + const {registry, owner} = deployedActors; + await registry.connect(owner).devAddIdentityCommitment( + ATTESTATION_ID.E_PASSPORT, + nullifier, + commitment + ); + + vcAndDiscloseProof.pubSignals[CIRCUIT_CONSTANTS.VC_AND_DISCLOSE_NAME_DOB_SMT_ROOT_INDEX] = generateRandomFieldElement(); + + const vcAndDiscloseHubProof = { + olderThanEnabled: true, + olderThan: "20", + forbiddenCountriesEnabled: true, + forbiddenCountriesListPacked: forbiddenCountriesListPacked, + ofacEnabled: [false, true, false], + vcAndDiscloseProof: vcAndDiscloseProof + }; + + const types = ["0", "1", "2"]; + const [readableData, success, errorCode] = await verifyAll.verifyAll( + 0, + vcAndDiscloseHubProof, + types + ); + + expect(success).to.be.false; + expect(errorCode).to.equal("INVALID_OFAC_ROOT"); + expect(readableData.name).to.be.empty; + }); + + it("should return error code 'INVALID_OFAC_ROOT' when name and yob OFAC root is invalid", async () => { + const {registry, owner} = deployedActors; + await registry.connect(owner).devAddIdentityCommitment( + ATTESTATION_ID.E_PASSPORT, + nullifier, + commitment + ); + + vcAndDiscloseProof.pubSignals[CIRCUIT_CONSTANTS.VC_AND_DISCLOSE_NAME_YOB_SMT_ROOT_INDEX] = generateRandomFieldElement(); + + const vcAndDiscloseHubProof = { + olderThanEnabled: true, + olderThan: "20", + forbiddenCountriesEnabled: true, + forbiddenCountriesListPacked: forbiddenCountriesListPacked, + ofacEnabled: [false, false, true], + vcAndDiscloseProof: vcAndDiscloseProof + }; + + const types = ["0", "1", "2"]; + const [readableData, success, errorCode] = await verifyAll.verifyAll( + 0, + vcAndDiscloseHubProof, + types + ); + + expect(success).to.be.false; + expect(errorCode).to.equal("INVALID_OFAC_ROOT"); + expect(readableData.name).to.be.empty; + }); + }); }); describe("admin functions", () => { diff --git a/contracts/test/unit/IdentityRegistry.test.ts b/contracts/test/unit/IdentityRegistry.test.ts index 8e804635d..adee3ca63 100644 --- a/contracts/test/unit/IdentityRegistry.test.ts +++ b/contracts/test/unit/IdentityRegistry.test.ts @@ -741,30 +741,27 @@ describe("Unit Tests for IdentityRegistry", () => { const initialCommitmentRoot = await registry.getIdentityCommitmentMerkleRoot(); const initialTreeSize = await registry.getIdentityCommitmentMerkleTreeSize(); - const PoseidonT3Factory = await ethers.getContractFactory("PoseidonT3", owner); - const poseidonT3 = await PoseidonT3Factory.deploy(); - await poseidonT3.waitForDeployment(); - - const IdentityRegistryImplFactory = await ethers.getContractFactory( - "IdentityRegistryImplV1", - { - libraries: { - PoseidonT3: poseidonT3.target - } - }, + // Deploy testUpgradedIdentityRegistryImplV1 instead + const UpgradedRegistryFactory = await ethers.getContractFactory( + "testUpgradedIdentityRegistryImplV1", owner ); - const registryV2Implementation = await IdentityRegistryImplFactory.deploy(); + const registryV2Implementation = await UpgradedRegistryFactory.deploy(); await registryV2Implementation.waitForDeployment(); + // Upgrade and initialize with isTest = true await registry.connect(owner).upgradeToAndCall( registryV2Implementation.target, - "0x" + UpgradedRegistryFactory.interface.encodeFunctionData("initialize", [true]) ); - const registryV2 = await ethers.getContractAt("IdentityRegistryImplV1", registry.target); + const registryV2 = await ethers.getContractAt("testUpgradedIdentityRegistryImplV1", registry.target); + // Check new functionality + expect(await registryV2.isTest()).to.equal(true); + + // Check preserved state expect(await registryV2.hub()).to.equal(initialHub); expect(await registryV2.getCscaRoot()).to.equal(initialCscaRoot); expect(await registryV2.getPassportNoOfacRoot()).to.equal(initialPassportNoOfacRoot); diff --git a/contracts/test/unit/IdentityVerificationHub.test.ts b/contracts/test/unit/IdentityVerificationHub.test.ts index 1eed36b81..513c60ad7 100644 --- a/contracts/test/unit/IdentityVerificationHub.test.ts +++ b/contracts/test/unit/IdentityVerificationHub.test.ts @@ -370,7 +370,6 @@ describe("Unit Tests for IdentityVerificationHub", () => { }); describe("Upgradeabilitiy", () => { - it("should preserve state after upgrade", async () => { const {hub, owner} = deployedActors; @@ -383,23 +382,25 @@ describe("Unit Tests for IdentityVerificationHub", () => { DscVerifierId.dsc_sha256_rsa_65537_4096 ); - const HubV2Factory = await ethers.getContractFactory("IdentityVerificationHubImplV1", owner); + const HubV2Factory = await ethers.getContractFactory("testUpgradedIdentityVerificationHubImplV1", owner); const hubV2Implementation = await HubV2Factory.deploy(); await hubV2Implementation.waitForDeployment(); const hubAsImpl = await ethers.getContractAt( - "IdentityVerificationHubImplV1", + "testUpgradedIdentityVerificationHubImplV1", hub.target ); await hubAsImpl.connect(owner).upgradeToAndCall( hubV2Implementation.target, - "0x" + HubV2Factory.interface.encodeFunctionData("initialize", [true]) ); - const hubV2 = await ethers.getContractAt("IdentityVerificationHubImplV1", hub.target); - const registryAddressAfter = await hubV2.registry(); - expect(registryAddressAfter).to.equal(registryAddressBefore); + const hubV2 = await ethers.getContractAt("testUpgradedIdentityVerificationHubImplV1", hub.target); + + expect(await hubV2.isTest()).to.equal(true); + + expect(await hubV2.registry()).to.equal(registryAddressBefore); expect(await hubV2.vcAndDiscloseCircuitVerifier()).to.equal(vcAndDiscloseCircuitVerifierBefore); expect(await hubV2.sigTypeToRegisterCircuitVerifiers( RegisterVerifierId.register_sha256_sha256_sha256_rsa_65537_4096 @@ -415,21 +416,21 @@ describe("Unit Tests for IdentityVerificationHub", () => { }); it("should not allow non-proxy to upgrade implementation", async() => { - const {hub, hubImpl, owner, user1} = deployedActors; + const {hub, hubImpl, owner} = deployedActors; - const HubV2Factory = await ethers.getContractFactory("IdentityVerificationHubImplV1", owner); + const HubV2Factory = await ethers.getContractFactory("testUpgradedIdentityVerificationHubImplV1", owner); const hubV2Implementation = await HubV2Factory.deploy(); await hubV2Implementation.waitForDeployment(); const hubAsImpl = await ethers.getContractAt( - "IdentityVerificationHubImplV1", + "testUpgradedIdentityVerificationHubImplV1", hub.target ); await expect( hubImpl.connect(owner).upgradeToAndCall( hubV2Implementation.target, - "0x" + HubV2Factory.interface.encodeFunctionData("initialize", [true]) ) ).to.be.revertedWithCustomError(hubAsImpl, "UUPSUnauthorizedCallContext"); }); @@ -437,19 +438,19 @@ describe("Unit Tests for IdentityVerificationHub", () => { it("should not allow non-owner to upgrade implementation", async () => { const {hub, owner, user1} = deployedActors; - const HubV2Factory = await ethers.getContractFactory("IdentityVerificationHubImplV1", owner); + const HubV2Factory = await ethers.getContractFactory("testUpgradedIdentityVerificationHubImplV1", owner); const hubV2Implementation = await HubV2Factory.deploy(); await hubV2Implementation.waitForDeployment(); const hubAsImpl = await ethers.getContractAt( - "IdentityVerificationHubImplV1", + "testUpgradedIdentityVerificationHubImplV1", hub.target ); await expect( hubAsImpl.connect(user1).upgradeToAndCall( hubV2Implementation.target, - "0x" + HubV2Factory.interface.encodeFunctionData("initialize", [true]) ) ).to.be.revertedWithCustomError(hubAsImpl, "OwnableUnauthorizedAccount"); }); @@ -457,31 +458,24 @@ describe("Unit Tests for IdentityVerificationHub", () => { it("should not allow implementation contract to be initialized directly", async () => { const {hub, owner} = deployedActors; - const HubV2Factory = await ethers.getContractFactory("IdentityVerificationHubImplV1", owner); + const HubV2Factory = await ethers.getContractFactory("testUpgradedIdentityVerificationHubImplV1", owner); const hubV2Implementation = await HubV2Factory.deploy(); await hubV2Implementation.waitForDeployment(); await expect( - hubV2Implementation.initialize( - ethers.ZeroAddress, - ethers.ZeroAddress, - [], - [], - [], - [] - ) + hubV2Implementation.initialize(true) ).to.be.revertedWithCustomError(hub, "InvalidInitialization"); }); it("should not allow direct calls to implementation contract", async () => { const {hub, owner} = deployedActors; - const HubV2Factory = await ethers.getContractFactory("IdentityVerificationHubImplV1", owner); + const HubV2Factory = await ethers.getContractFactory("testUpgradedIdentityVerificationHubImplV1", owner); const hubV2Implementation = await HubV2Factory.deploy(); await hubV2Implementation.waitForDeployment(); await expect( - hubV2Implementation.updateRegistry(ethers.ZeroAddress) + hubV2Implementation.isTest() ).to.be.revertedWithCustomError(hubV2Implementation, "UUPSUnauthorizedCallContext"); }); }); diff --git a/contracts/test/unit/PCR0Manager.test.ts b/contracts/test/unit/PCR0Manager.test.ts new file mode 100644 index 000000000..b7a455994 --- /dev/null +++ b/contracts/test/unit/PCR0Manager.test.ts @@ -0,0 +1,102 @@ +import { expect } from "chai"; +import { ethers } from "hardhat"; +import { PCR0Manager } from "../typechain-types"; +import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers"; + +describe("PCR0Manager", function () { + let pcr0Manager: PCR0Manager; + let owner: SignerWithAddress; + let other: SignerWithAddress; + + // Sample PCR0 value for testing (48 bytes) + const samplePCR0 = "0x" + "00".repeat(48); + const invalidPCR0 = "0x" + "00".repeat(32); // 32 bytes (invalid size) + + beforeEach(async function () { + [owner, other] = await ethers.getSigners(); + + const PCR0Manager = await ethers.getContractFactory("PCR0Manager"); + pcr0Manager = await PCR0Manager.deploy(); + }); + + describe("addPCR0", function () { + it("should allow owner to add PCR0 value", async function () { + await expect(pcr0Manager.addPCR0(samplePCR0)) + .to.emit(pcr0Manager, "PCR0Added"); + + expect(await pcr0Manager.isPCR0Set(samplePCR0)).to.be.true; + }); + + it("should allow owner to add PCR0 value", async function () { + await expect(pcr0Manager.addPCR0(samplePCR0)) + .to.emit(pcr0Manager, "PCR0Added"); + + expect(await pcr0Manager.isPCR0Set(samplePCR0)).to.be.true; + }); + + it("should not allow non-owner to add PCR0 value", async function () { + await expect(pcr0Manager.connect(other).addPCR0(samplePCR0)) + .to.be.revertedWithCustomError(pcr0Manager, "OwnableUnauthorizedAccount") + .withArgs(other.address); + }); + + it("should not allow adding PCR0 with invalid size", async function () { + await expect(pcr0Manager.addPCR0(invalidPCR0)) + .to.be.revertedWith("PCR0 must be 48 bytes"); + }); + + it("should not allow adding duplicate PCR0", async function () { + await pcr0Manager.addPCR0(samplePCR0); + await expect(pcr0Manager.addPCR0(samplePCR0)) + .to.be.revertedWith("PCR0 already set"); + }); + }); + + describe("removePCR0", function () { + beforeEach(async function () { + await pcr0Manager.addPCR0(samplePCR0); + }); + + it("should allow owner to remove PCR0 value", async function () { + await expect(pcr0Manager.removePCR0(samplePCR0)) + .to.emit(pcr0Manager, "PCR0Removed"); + + expect(await pcr0Manager.isPCR0Set(samplePCR0)).to.be.false; + }); + + // This is not actually needed, just for increase the coverage of the test code + it("should not allow remove PCR0 with invalid size", async function () { + await expect(pcr0Manager.removePCR0(invalidPCR0)) + .to.be.revertedWith("PCR0 must be 48 bytes"); + }); + + it("should not allow non-owner to remove PCR0 value", async function () { + await expect(pcr0Manager.connect(other).removePCR0(samplePCR0)) + .to.be.revertedWithCustomError(pcr0Manager, "OwnableUnauthorizedAccount") + .withArgs(other.address); + }); + + it("should not allow removing non-existent PCR0", async function () { + const otherPCR0 = "0x" + "11".repeat(48); + await expect(pcr0Manager.removePCR0(otherPCR0)) + .to.be.revertedWith("PCR0 not set"); + }); + }); + + describe("isPCR0Set", function () { + it("should correctly return PCR0 status", async function () { + expect(await pcr0Manager.isPCR0Set(samplePCR0)).to.be.false; + + await pcr0Manager.addPCR0(samplePCR0); + expect(await pcr0Manager.isPCR0Set(samplePCR0)).to.be.true; + + await pcr0Manager.removePCR0(samplePCR0); + expect(await pcr0Manager.isPCR0Set(samplePCR0)).to.be.false; + }); + + it("should not allow checking PCR0 with invalid size", async function () { + await expect(pcr0Manager.isPCR0Set(invalidPCR0)) + .to.be.revertedWith("PCR0 must be 48 bytes"); + }); + }); +}); \ No newline at end of file diff --git a/contracts/test/unit/formatter.test.ts b/contracts/test/unit/formatter.test.ts index 69e5ba304..1ea2b3dee 100644 --- a/contracts/test/unit/formatter.test.ts +++ b/contracts/test/unit/formatter.test.ts @@ -83,22 +83,6 @@ describe("Formatter", function () { expect(() => Formatter.formatDate(input)) .to.throw("InvalidDayRange"); }); - - it("should handle errors consistently when input is not a number", async function () { - const input = "94012a"; - await expect(testFormatter.testFormatDate(input)) - .to.be.revertedWithCustomError(testFormatter, "InvalidAsciiCode"); - expect(() => Formatter.formatDate(input)) - .to.throw("InvalidAsciiCode"); - }); - - it("should handle errors consistently when input is not a number", async function () { - const input = "94012."; - await expect(testFormatter.testFormatDate(input)) - .to.be.revertedWithCustomError(testFormatter, "InvalidAsciiCode"); - expect(() => Formatter.formatDate(input)) - .to.throw("InvalidAsciiCode"); - }); }); describe("numAsciiToUint", function () { @@ -112,15 +96,6 @@ describe("Formatter", function () { } }); - it("should handle errors consistently between contract and ts", async function () { - const invalidInputs = [47, 58]; - for (const input of invalidInputs) { - await expect(testFormatter.testNumAsciiToUint(input)) - .to.be.revertedWithCustomError(testFormatter, "InvalidAsciiCode"); - expect(() => Formatter.numAsciiToUint(input)) - .to.throw("InvalidAsciiCode"); - } - }); }); describe("fieldElementsToBytes", function () { @@ -286,18 +261,6 @@ describe("Formatter", function () { .to.be.revertedWithCustomError(testFormatter, "InvalidDayRange"); }); - it("should revert when date digit is out of range", async function () { - const input = "94012a"; - await expect(testFormatter.testDateToUnixTimestamp(input)) - .to.be.revertedWithCustomError(testFormatter, "InvalidAsciiCode"); - }); - - it("should revert when date digit is out of range", async function () { - const input = "94012."; - await expect(testFormatter.testDateToUnixTimestamp(input)) - .to.be.revertedWithCustomError(testFormatter, "InvalidAsciiCode"); - }); - }); describe("substring", function () { @@ -342,18 +305,6 @@ describe("Formatter", function () { } }); - it("should revert when input is not a number", async function () { - const input = "12a"; - await expect(testFormatter.testParseDatePart(input)) - .to.be.revertedWithCustomError(testFormatter, "InvalidAsciiCode"); - }); - - - it("should revert when input is not a number", async function () { - const input = "12."; - await expect(testFormatter.testParseDatePart(input)) - .to.be.revertedWithCustomError(testFormatter, "InvalidAsciiCode"); - }); }); describe("toTimestamp", function () { @@ -466,4 +417,4 @@ function toHexString(bytes: Uint8Array): string { return '0x' + Array.from(bytes) .map(b => b.toString(16).padStart(2, '0')) .join(''); -} +} \ No newline at end of file diff --git a/contracts/test/utils/deployment.ts b/contracts/test/utils/deployment.ts index 9fecd7dc7..43ed986e0 100644 --- a/contracts/test/utils/deployment.ts +++ b/contracts/test/utils/deployment.ts @@ -5,7 +5,7 @@ import { PassportData } from "../../../common/src/utils/types"; import { genMockPassportData } from "../../../common/src/utils/passports/genMockPassportData"; import { RegisterVerifierId, DscVerifierId } from "../../../common/src/constants/constants"; import { getCscaTreeRoot } from "../../../common/src/utils/trees"; -import serialized_csca_tree from "../../../common/pubkeys/serialized_csca_tree.json"; +import serialized_csca_tree from "./pubkeys/serialized_csca_tree.json"; import { DeployedActors, VcAndDiscloseVerifier, @@ -49,7 +49,7 @@ export async function deploySystemFixtures(): Promise { mockPassport = genMockPassportData( "sha256", "sha256", - "rsa_sha256_65537_2048", + "rsa_sha256_65537_4096", "FRA", "940131", "401031" @@ -176,4 +176,4 @@ export async function deploySystemFixtures(): Promise { user2: user2, mockPassport: mockPassport }; -} +} \ No newline at end of file diff --git a/contracts/test/utils/generateProof.ts b/contracts/test/utils/generateProof.ts index be3907554..b0ad48a68 100644 --- a/contracts/test/utils/generateProof.ts +++ b/contracts/test/utils/generateProof.ts @@ -23,8 +23,8 @@ import { generateCircuitInputsDSC, generateCircuitInputsVCandDisclose } from "../../../common/src/utils/circuits/generateInputs"; -import serialized_csca_tree from '../../../common/pubkeys/serialized_csca_tree.json'; -import serialized_dsc_tree from '../../../common/pubkeys/serialized_dsc_tree.json'; +import serialized_csca_tree from './pubkeys/serialized_csca_tree.json'; +import serialized_dsc_tree from './pubkeys/serialized_dsc_tree.json'; const registerCircuits: CircuitArtifacts = { "register_sha256_sha256_sha256_rsa_65537_4096": { @@ -58,7 +58,7 @@ export async function generateRegisterProof( const registerCircuitInputs: CircuitSignals = await generateCircuitInputsRegister( secret, passportData, - serialized_dsc_tree + serialized_dsc_tree as string ); // Generate the proof diff --git a/contracts/test/utils/pubkeys/serialized_csca_tree.json b/contracts/test/utils/pubkeys/serialized_csca_tree.json new file mode 100644 index 000000000..39a1b4114 --- /dev/null +++ b/contracts/test/utils/pubkeys/serialized_csca_tree.json @@ -0,0 +1 @@ +[["6302746167612040169287204224641965049119379670159808996613022200426959969278","21737912865216631366336567244260032647310946375673351181140174093591714702999","7881627741362630218419203394369410748786507764316669620068500512816306974393","8442633355440465296842644318461346259324083140085137778501389055937910431110","494385956299168270408334656570463268819757224023693256178124768603625095689","11109705732184239012583404749930109480114669765649070936031155493622876369432","9074991679283645951358641479142018086508433068636738897852818247691550887353","10472104103456953748165921858843921722705273802507936987918628317450502368318","20465532314290048641249890589020580844800312880610998262795900425795687925759","5768994172638224755740597462572068991220057867415414997645244086458792645415","17252018052637913533753543738759416074689182570352156984838315665730273174771","344641985496327935255151802075808884620413685031595062530048227920050721780","12136951745768356780790830952320550859256567348204838329686829291956271851018","13156935969312787083658542670212591426438912414983737359002368687207144158384","18390019689329531194486865663275817993149098196912806933141622083576329149060","1481242557340385890029242958318001323542042109291864424212505135403557049174","8212379972296569224239707053291801266656219357105654879157065434106153446780","7259130865988598378063439736597905343524876834653292276109931166452499429748","9121308753649396222680496889506939509201230922178179924059434299141020697403","285292161892340475671724520102600999462489619312686773735450615184611138494","17039352924793721634937165985544670409252882635692632479205349210469115588765","13502358060740841171380532205068310953416088597412723446166411697331808464867","17340560759412667275187297637986710225182012906580596771637656874104617617955","8161679470983166059226129385619085265731972285960057248143860608525733203270","14871986472052100593919450740854089518175775672170855933096343961866149319949","1024796798868617073580401107121867347946885220866292564654180021134775438463","21314659513316629128269900118046844671368217281573948618189189184438357521850","14333285970232052794263361289909650744651387298949229098454892979931317772146","16041205263585308774562352509747184978808349452049402919724529400974025427436","8087267757933126132764313502987988617372965137423098839133763536652762365681","7962106263240616478489255388356842229007064058701247603002333884146997650489","3623426348190205637422491853880154438593931070755716928634661523298474873370","14890281186129558220608231498920908810133225689204820445535572821472349664447"],["4799972325846543794225228491143787399389885942417063987224237164999385319062","17050236804818394861130974609766586541491094962728898163841781451223822854686","1684095988446507706929542511950029896329456076438958417914434742534053808377","13030822995128201263800907485086206983654704449426873876221363197647850166314","20387868117709928393743787975391876407731857373450679028712293718320824421501","20648800321790649263930241990062778433044036026899293567267368546697502978404","5558822243190898430854422659247277485120763541538425901094235849734898971547","9648977827828540671109446184233701627175773049876679003145259446306367526913","19587958295993125277460383800858337068930180629959346593667253473373677697838","10766098235994178632473997874302736133480358322525035521842128765122396106753","3280132879539287366527818935691748975940933587498820629810825597324185825847","16042507993949674348775016509851234008694527541085892473255432193590272155228","9861886961854997054898644300025435424974733812770562105962523420323474270014","19963900440588427317645840967905315109665755922636714102274837921808725924490","14560929249637716209472399173281335447881032559475124155250089695314652709191","8793029054134443177154661146037690681847213703147023923126117330651746975093","6925999197894078032454979151597762706585652495739163647097172857061948107548"],["15437505910104448767291373721892514134533670716520577686244116418756186347964","9662712081254759511361246703401148719683866951663061909834810685640445739155","20383431234416469352301291449238452506080771017490889548224583250446902949522","17761227464350859107613675961034420867642506074271853781885405739945665021951","10107612039899335485435001531034291183382103402117414413277201288890819890175","21676120760606796382962041245156922927516003007606533210349079976883427407876","3959481944782480427438878998268686710659856580112036162216134326047024223619","13995366414942085322718873409710308506843557459098667415203661966308146712276","12396189675521664477208213044494994395570714180213788407180369449372794337406"],["17536551248416856833253545290007826015310552834679591084728236812275380736581","21178262016621282270578676828655596120453358323099758552458721672074592774466","12983142270089439210893516110450393549941947745609655791579563598275214147990","11138438821067972642938006246604783995156242377512994534882399065269415238242","14367141578614776950464394914864658179440566498674064519890241555879050349273"],["4746628767395628818871695814217923898815372663453343963780833567597879413422","6217935900653585035630246253466782187759116959924419206414312068302028006200","1712622252469401905020836297393811034367718131168934306349084470952949672370"],["9591986692462415575100546764405459060632901984266333538073859143124986153857","16005335605576341683358111497065243375958891362902160878740195332217005325867"],["10058083772386987881503691291273436622272886362704429356343750534180295442877"],["948496844530378519444411419272223562136844993455458676689351273655202389660"],["6104686411816540186205486815934621935504228294686310666920439592650163266817"],["8785911549693694407543433563052767959786709016516642293679450790050523979623"],["7409592596312085101815420137623073822216578588711762918861029979315261400521"],["21777804325204060904854919426171461175668073322071471253268661582106674611134"],["13859398115974385161464830211947258005860166431741677064758266112192747818198"]] \ No newline at end of file diff --git a/contracts/test/utils/pubkeys/serialized_dsc_tree.json b/contracts/test/utils/pubkeys/serialized_dsc_tree.json new file mode 100644 index 000000000..1a229c5c7 --- /dev/null +++ b/contracts/test/utils/pubkeys/serialized_dsc_tree.json @@ -0,0 +1 @@ +"[[\"8474170120361574158328936749210134677109057903005360945237099789945718842442\",\"19025861045901247405057316482734230273999651461753587376586889481054653237298\",\"20875820196105056284418196645437121025521090457969915100313025042226816593058\",\"7981401722738051151242865671764881670381691410051713896829121611466467295296\",\"12686075888445000028034879614337002534166281820554518240319859431277458776808\",\"14407479994300627796369211860752956065461957169462957624471349543175814297361\",\"12876099927862331079950419893066049696538807114168859906501896216679946602822\",\"5034430740274171017815797630858587451285547946739275122278422412563124952340\",\"124908299050395035311905641407789814479238558810338620545288553719611907579\",\"2220350286514662949665617433093307231741026918951518572442081261648362984066\",\"21054071841429471407849176541802267087608621767405046215729266220057231321239\",\"18615459511690451805285056890862312778437329715516723596790967668107849472332\",\"11005834873878236310149874426944776526137242691148625759790072174524730632293\",\"7750466501575524692208442425341714971523444376628469247291115085823741362258\",\"2825614199585564216616864222833372928389506766845048349547149599270041996580\",\"20178939917842893412863622473123830356625340961044353255941385554773117435807\",\"15457105913874757357155517217216962392853062937896722147907639311387695489612\",\"5769570513706963538956166571458035734925811338270969027092827256594315896305\",\"6944618873207772930654947866168069208208574383743967671528812057261674809023\",\"481787392403338571656555722870122978065125892949434958835001773033712625191\",\"629022117628670814916597453011668822767584986875266116143558377822126606210\",\"3477506405023338639718612883193130086582505996283986141234891023161625314400\",\"10391239348681537631698595933529223926008268217047488115607852208836329547314\",\"17714411760364866672536495662484312224393687256599208863125247267615177780962\",\"8235397798041831527134655625941532067772455314854641402993505266475178259142\",\"15400445794279992494417489709867566126537687907753955918275441261129856435204\",\"18390538379285507212129312705208118101486722955290795425636438098737923067560\",\"15884158870062763074209623120979824036430500099471957276287699843774740810060\",\"9761474784835077830881823851138622604776507060902897946796201272804305644780\",\"10691342730033436831098118713873643843887824911850191956325145412899736489783\",\"5383646477412575449009401478396232205746537027068927954390800800393113212132\",\"11221442935955024550310715250831163771206851175519681722264731998826151062912\",\"5908215522026944047821144963285306601790999208803054898792188809472216445547\",\"19125477641235279033749474384585292663869320556945218215852551798484901700632\",\"21131596906673841534294586137917770250418344721734587506304435102735580889655\",\"5546854205853827616610180972262457239247839686812479293725221982292586246857\",\"765319165068330175794491754566055878846660871087781618280248834367406785408\",\"9065563084454046530671534818701959328556136219713201237904842104821385096277\",\"11685470115846281888274197814651339961028617777494077059927246879793227459012\",\"2276790636588619756427393596069501098393513502175223999114797598139979501715\"],[\"18261435412082991275184532065290531009107742677653928657546608300990409875179\",\"9319096001557865141309312824962941754323190215020661725351078769489865210042\",\"19426464515945862948128564234105343408552273980845098594209919356069483229628\",\"4821438189762812946550415462056480603193509374059280985662653954928168448767\",\"5172906179275109031852701363533115355308886025681591977544612584826814597738\",\"3030902410998504999074059222657043445867065651115237138539258929106073952351\",\"14984550843964273185801085401106206042254593799102067736545138712711200363110\",\"4913017693235246056337618677701835414584892336316530224150731143499438377822\",\"20331547282693860184739325401078246632991653782842932001956973617899699067126\",\"7600383600608310101623426738393844905406553598472129359788500052979517101086\",\"21052687276768682440237728714031588951028862448534763565173935420275983308030\",\"8624573291232390725167327242752231606002232362298782976538648069452315809692\",\"8822425521071097948786926466502634257594788443097595142360595191654091518800\",\"19870347064194260309549332912586515029667844641153191360540616815967059032631\",\"20465460310501582547409465331218341819661912832562849210077024323229630431309\",\"8822852684497325396969645265731037061910702688625880340802544167587243049164\",\"4478528672717298316804099458930548551969390361723990676862003909749451604942\",\"17325287090866702355475285665146878940121103201057390207999938983310817624720\",\"19625874220796709797520370627316734190983871032135923532916997267931941944017\",\"4971210922480782538363635536321057597816923124821190325639868004751176123095\"],[\"4116500508658592197045562123902818266144060908634297057533152651751621275415\",\"6279942219928883797763183575386930078658513224739644044432142134698996392345\",\"17873714886463212348626929321462768984929311072311394677407846329308137071177\",\"1780903854488782716523110881333093026159313079337979149518816941412656424372\",\"20050373159836077479057811893536206817195523291436452658040605882811525003132\",\"5410620983195375911090727814270361454832036795917695206544043001420960637777\",\"11266551165651302260349077780564641889328703387362942837789171445336788206333\",\"3608626782139895235764576982540708534353226535204704760149123479387449221471\",\"3145665689117343568678004953880446893036465022181894889004516583481449637793\",\"8073537774997617083133123196297054007342256527983221664627563913756598041137\"],[\"16950176155260599508276620633155897140104757247891462208942656524243675299741\",\"4384637840548698893518161520012906111962786493558848227457354530627659879521\",\"5124677781615023074976959243179487140944992271935523984403489366636038434778\",\"12988207380549681248970615897816015977834414112005771449262709089864569444208\",\"4960783735404364608985140352905530473941590990406201882678348579000881422078\"],[\"20387009608350563521735170556423317268483084337333204688511143658578884542027\",\"19972334535313243417117998358484532425461333194385844246074835217244635372928\",\"4960783735404364608985140352905530473941590990406201882678348579000881422078\"],[\"1003947683617565493626440885069112088208918036484637499642204220769104979880\",\"4960783735404364608985140352905530473941590990406201882678348579000881422078\"],[\"17493683025876340868978454534142017149014501237522261427894104407551129583657\"]]" \ No newline at end of file diff --git a/registry/src/csca/build_csca_merkle_tree.ts b/registry/src/csca/build_csca_merkle_tree.ts index 5d60440e3..66e19afe4 100644 --- a/registry/src/csca/build_csca_merkle_tree.ts +++ b/registry/src/csca/build_csca_merkle_tree.ts @@ -57,7 +57,7 @@ function processCertificate(pemContent: string, filePath: string) { async function buildCscaMerkleTree() { const tree = new IMT(poseidon2, CSCA_TREE_DEPTH, 0, 2); - if (true) { + if (!DEVELOPMENT_MODE) { const path_to_pem_files = "outputs/csca/pem_masterlist"; for (const file of fs.readdirSync(path_to_pem_files)) { const file_path = path.join(path_to_pem_files, file); @@ -73,7 +73,7 @@ async function buildCscaMerkleTree() { } } - if (true) { + if (DEVELOPMENT_MODE) { const dev_pem_path = path.join(__dirname, '..', '..', '..', 'common', 'src', 'mock_certificates'); const subdirectories = fs.readdirSync(dev_pem_path, { withFileTypes: true }) .filter(item => item.isDirectory()) diff --git a/registry/src/dsc/build_dsc_merkle_tree.ts b/registry/src/dsc/build_dsc_merkle_tree.ts index c481484c2..3a8c3d293 100644 --- a/registry/src/dsc/build_dsc_merkle_tree.ts +++ b/registry/src/dsc/build_dsc_merkle_tree.ts @@ -113,7 +113,7 @@ function processCertificate(pemContent: string, filePath: string) { async function buildDscMerkleTree() { const tree = new LeanIMT((a, b) => poseidon2([a, b]), []); - if (true) { + if (!DEVELOPMENT_MODE) { const path_to_pem_files = "outputs/dsc/pem_masterlist"; for (const file of fs.readdirSync(path_to_pem_files)) { const file_path = path.join(path_to_pem_files, file); @@ -129,7 +129,7 @@ async function buildDscMerkleTree() { } } - if (true) { + if (DEVELOPMENT_MODE) { const dev_pem_path = path.join(__dirname, '..', '..', '..', 'common', 'src', 'mock_certificates'); const subdirectories = fs.readdirSync(dev_pem_path, { withFileTypes: true }) .filter(item => item.isDirectory()) diff --git a/test/PCR0Manager.test.ts b/test/PCR0Manager.test.ts new file mode 100644 index 000000000..0519ecba6 --- /dev/null +++ b/test/PCR0Manager.test.ts @@ -0,0 +1 @@ + \ No newline at end of file