Skip to content

Commit

Permalink
check storage fields in verifier using validator stub
Browse files Browse the repository at this point in the history
  • Loading branch information
daveroga committed Nov 21, 2024
1 parent e139017 commit d4f4f33
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 77 deletions.
12 changes: 10 additions & 2 deletions contracts/test-helpers/ValidatorStub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ contract ValidatorStub is ICircuitValidator, ERC165 {
bytes calldata,
address
) external pure override returns (ICircuitValidator.KeyToInputIndex[] memory) {
ICircuitValidator.KeyToInputIndex[] memory keyToInputIndexes;
ICircuitValidator.KeyToInputIndex[] memory keyToInputIndexes = new ICircuitValidator.KeyToInputIndex[](2);

Check failure on line 36 in contracts/test-helpers/ValidatorStub.sol

View workflow job for this annotation

GitHub Actions / solhint

Insert ⏎···········
keyToInputIndexes[0].key = "userID";
keyToInputIndexes[0].inputIndex = 1;

Check failure on line 38 in contracts/test-helpers/ValidatorStub.sol

View workflow job for this annotation

GitHub Actions / solhint

Delete ········
keyToInputIndexes[1].key = "issuerID";
keyToInputIndexes[1].inputIndex = 2;
return keyToInputIndexes;
}

Expand All @@ -43,7 +47,11 @@ contract ValidatorStub is ICircuitValidator, ERC165 {
address,
IState
) external pure override returns (ICircuitValidator.Signal[] memory) {
ICircuitValidator.Signal[] memory signals;
ICircuitValidator.Signal[] memory signals = new ICircuitValidator.Signal[](2);
signals[0].name = "userID";
signals[0].value = 1;
signals[1].name = "issuerID";
signals[1].value = 2;
return signals;
}

Expand Down
10 changes: 10 additions & 0 deletions test/verifier/embedded-zkp-verifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ describe("Embedded ZKP Verifier", function () {
sig = stub;
}

async function checkStorageFields(verifier: any, requestId: number) {
const fieldsToCheck = ["userID", "issuerID"];
for (const field of fieldsToCheck) {
const value = await verifier.getProofStorageField(await owner.getAddress(), requestId, field);
expect(value).to.be.greaterThan(0n);
}
}

beforeEach(async () => {
await loadFixture(deployContractsFixture);
});
Expand All @@ -61,6 +69,7 @@ describe("Embedded ZKP Verifier", function () {

const tx = await verifier.submitZKPResponse(0, inputs, pi_a, pi_b, pi_c);
const txRes = await tx.wait();
await checkStorageFields(verifier, 0);
const receipt = await ethers.provider.getTransactionReceipt(txRes.hash);

// 2 events are emitted
Expand Down Expand Up @@ -159,6 +168,7 @@ describe("Embedded ZKP Verifier", function () {
);

const txRes = await tx.wait();
await checkStorageFields(verifier, 0);

const receipt = await ethers.provider.getTransactionReceipt(txRes.hash);

Expand Down
14 changes: 14 additions & 0 deletions test/verifier/universal-verifier-submit-V2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ describe("Universal Verifier V2 MTP & SIG validators", function () {
await verifier.connect();
}

async function checkStorageFields(verifier: any, requestId: number) {
const fieldsToCheck = ["userID", "issuerID"];
for (const field of fieldsToCheck) {
const value = await verifier.getProofStorageField(
await signer.getAddress(),
requestId,
field,
);
expect(value).to.be.greaterThan(0n);
}
}

beforeEach(async () => {
await loadFixture(deployContractsFixture);
});
Expand Down Expand Up @@ -118,6 +130,7 @@ describe("Universal Verifier V2 MTP & SIG validators", function () {
);

const txRes = await tx.wait();
await checkStorageFields(verifier, requestId);
const filter = verifier.filters.ZKPResponseSubmitted;

const events = await verifier.queryFilter(filter, -1);
Expand Down Expand Up @@ -193,6 +206,7 @@ describe("Universal Verifier V2 MTP & SIG validators", function () {
expect(status.validatorVersion).to.be.equal("2.0.1-mock");
expect(status.blockNumber).to.be.equal(txRes.blockNumber);
expect(status.blockTimestamp).to.be.equal(txResTimestamp);
await checkStorageFields(verifier, requestId);
}

await expect(verifier.getProofStatus(signerAddress, nonExistingRequestId)).to.be.rejectedWith(
Expand Down
13 changes: 13 additions & 0 deletions test/verifier/universal-verifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ describe("Universal Verifier MTP & SIG validators", function () {
return { ethSigner, ethSigner2, ethSigner3, stateContract, universalVerifier, validator };
}

async function checkStorageFields(verifier: any, requestId: number) {
const fieldsToCheck = ["userID", "issuerID"];
for (const field of fieldsToCheck) {
const value = await verifier.getProofStorageField(
await signer.getAddress(),
requestId,
field,
);
expect(value).to.be.greaterThan(0n);
}
}

beforeEach(async () => {
({
ethSigner: signer,
Expand Down Expand Up @@ -113,6 +125,7 @@ describe("Universal Verifier MTP & SIG validators", function () {
const { inputs, pi_a, pi_b, pi_c } = prepareInputs(proofJson);
const tx = await verifier.submitZKPResponse(0, inputs, pi_a, pi_b, pi_c);
const txRes = await tx.wait();
await checkStorageFields(verifier, requestId);
const filter = verifier.filters.ZKPResponseSubmitted;

const events = await verifier.queryFilter(filter, -1);
Expand Down
98 changes: 23 additions & 75 deletions test/verifier/universal-verifier.v3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,27 @@ describe("Universal Verifier V3 validator", function () {
return { ethSigner, ethSigner2, stateContract, universalVerifier, validator };
}

async function checkStorageFields(verifier: any, requestId: number) {
const nonZeroFields = ["issuerID", "userID", "timestamp", "linkID"];
const zeroFields = ["nullifier"];
for (const field of nonZeroFields) {
const value = await verifier.getProofStorageField(
await signer.getAddress(),
requestId,
field,
);
expect(value).to.be.greaterThan(0n);
}
for (const field of zeroFields) {
const value = await verifier.getProofStorageField(
await signer.getAddress(),
requestId,
field,
);
expect(value).to.be.equal(0n);
}
}

before(async () => {
({
ethSigner: signer,
Expand Down Expand Up @@ -119,43 +140,7 @@ describe("Universal Verifier V3 validator", function () {

await expect(verifier.submitZKPResponse(requestId, inputs, pi_a, pi_b, pi_c)).not.to.be
.rejected;
const issuerID = await verifier.getProofStorageField(
await signer.getAddress(),
requestId,
"issuerID",
);
const userID = await verifier.getProofStorageField(
await signer.getAddress(),
requestId,
"userID",
);
const timestamp = await verifier.getProofStorageField(
await signer.getAddress(),
requestId,
"timestamp",
);
const linkID = await verifier.getProofStorageField(
await signer.getAddress(),
requestId,
"linkID",
);
const nullifier = await verifier.getProofStorageField(
await signer.getAddress(),
requestId,
"nullifier",
);

expect(issuerID).to.equal(
22057981499787921734624217749308316644136637822444794206796063681866502657n,
);
expect(userID).to.equal(
23013175891893363078841232968022302880776034013620341061794940968520126978n,
);
expect(timestamp).to.equal(1642074362n);
expect(linkID).to.equal(
19823993270096139446564592922993947503208333537792611306066620392561342309875n,
);
expect(nullifier).to.equal(0n);
await checkStorageFields(verifier, requestId);
});

it("Test submit response V2", async () => {
Expand All @@ -181,44 +166,7 @@ describe("Universal Verifier V3 validator", function () {
crossChainProofs,
),
).not.to.be.rejected;

const issuerID = await verifier.getProofStorageField(
await signer.getAddress(),
requestId,
"issuerID",
);
const userID = await verifier.getProofStorageField(
await signer.getAddress(),
requestId,
"userID",
);
const timestamp = await verifier.getProofStorageField(
await signer.getAddress(),
requestId,
"timestamp",
);
const linkID = await verifier.getProofStorageField(
await signer.getAddress(),
requestId,
"linkID",
);
const nullifier = await verifier.getProofStorageField(
await signer.getAddress(),
requestId,
"nullifier",
);

expect(issuerID).to.equal(
22057981499787921734624217749308316644136637822444794206796063681866502657n,
);
expect(userID).to.equal(
23013175891893363078841232968022302880776034013620341061794940968520126978n,
);
expect(timestamp).to.equal(1642074362n);
expect(linkID).to.equal(
19823993270096139446564592922993947503208333537792611306066620392561342309875n,
);
expect(nullifier).to.equal(0n);
await checkStorageFields(verifier, requestId);
});

it("Test submit response fails with UserID does not correspond to the sender", async () => {
Expand Down

0 comments on commit d4f4f33

Please sign in to comment.