Perf/contract test (#224)

This commit is contained in:
nicoshark
2025-03-04 17:03:03 -07:00
committed by GitHub
parent d24713ee8a
commit f63ee37118
19 changed files with 697 additions and 111 deletions

View File

@@ -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";

View File

@@ -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([

View File

@@ -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,

View File

@@ -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<bigint>(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", () => {

View File

@@ -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);

View File

@@ -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");
});
});

View File

@@ -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");
});
});
});

View File

@@ -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('');
}
}

View File

@@ -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<DeployedActors> {
mockPassport = genMockPassportData(
"sha256",
"sha256",
"rsa_sha256_65537_2048",
"rsa_sha256_65537_4096",
"FRA",
"940131",
"401031"
@@ -176,4 +176,4 @@ export async function deploySystemFixtures(): Promise<DeployedActors> {
user2: user2,
mockPassport: mockPassport
};
}
}

View File

@@ -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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long