Skip to content

Commit 5002c18

Browse files
committed
add chai-zkit
1 parent a36b3d8 commit 5002c18

File tree

5 files changed

+67
-56
lines changed

5 files changed

+67
-56
lines changed

hardhat.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import "@nomicfoundation/hardhat-toolbox";
22
import "@solarity/hardhat-zkit";
3+
import "@solarity/chai-zkit";
34
import "tsconfig-paths/register";
45

56
import { HardhatUserConfig } from "hardhat/config";

package-lock.json

Lines changed: 28 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
4747
"@solarity/solidity-lib": "^2.7.11",
4848
"@solarity/hardhat-zkit": "^0.5.2",
49+
"@solarity/chai-zkit": "^0.3.0",
4950
"@typechain/ethers-v6": "^0.5.1",
5051
"@types/chai": "^4.3.14",
5152
"@types/mocha": "^10.0.9",

test/blinders/Commitment.test.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,21 @@ describe("Commitment", () => {
2424
afterEach(reverter.revert);
2525

2626
it("should return commitment and hash of nullifier", async () => {
27+
await expect(commitmentCircuit)
28+
.with.witnessInputs({
29+
nullifier: 1,
30+
secret: 2,
31+
})
32+
.to.have.witnessOutputs({
33+
commitment: "7853200120776062878684798364095072458815029376092732009249414926327459813530",
34+
nullifierHash: "18586133768512220936620570745912940619677854269274689475585506675881198879027",
35+
});
36+
2737
const proofStruct = await commitmentCircuit.generateProof({
2838
nullifier: 1,
2939
secret: 2,
3040
});
3141

32-
// Poseidon(1, 2)
33-
expect(proofStruct.publicSignals.commitment).to.equal(
34-
"7853200120776062878684798364095072458815029376092732009249414926327459813530",
35-
);
36-
// Poseidon(1)
37-
expect(proofStruct.publicSignals.nullifierHash).to.equal(
38-
"18586133768512220936620570745912940619677854269274689475585506675881198879027",
39-
);
40-
41-
const [pA, pB, pC, publicSignals] = await commitmentCircuit.generateCalldata(proofStruct);
42-
43-
expect(await commitmentVerifier.verifyProof(pA, pB, pC, publicSignals)).to.be.true;
42+
await expect(commitmentCircuit).to.useSolidityVerifier(commitmentVerifier).and.verifyProof(proofStruct);
4443
});
4544
});

test/data-structures/SparseMerkleTree.test.ts

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ describe("SparseMerkleTree", () => {
6868
isExclusion: 0,
6969
});
7070

71-
const [pA, pB, pC, publicSignals] = await smtCircuit.generateCalldata(proofStruct);
72-
73-
expect(await smtVerifier.verifyProof(pA, pB, pC, publicSignals)).to.be.true;
71+
await expect(smtCircuit).to.useSolidityVerifier(smtVerifier).and.verifyProof(proofStruct);
7472
});
7573

7674
it("should prove the tree inclusion for each depth of bamboo", async () => {
@@ -92,9 +90,7 @@ describe("SparseMerkleTree", () => {
9290
isExclusion: 0,
9391
});
9492

95-
const [pA, pB, pC, publicSignals] = await smtCircuit.generateCalldata(proofStruct);
96-
97-
expect(await smtVerifier.verifyProof(pA, pB, pC, publicSignals)).to.be.true;
93+
await expect(smtCircuit).to.useSolidityVerifier(smtVerifier).and.verifyProof(proofStruct);
9894
}
9995
});
10096

@@ -115,9 +111,7 @@ describe("SparseMerkleTree", () => {
115111
isExclusion: 0,
116112
});
117113

118-
const [pA, pB, pC, publicSignals] = await smtCircuit.generateCalldata(proofStruct);
119-
120-
expect(await smtVerifier.verifyProof(pA, pB, pC, publicSignals)).to.be.true;
114+
await expect(smtCircuit).to.useSolidityVerifier(smtVerifier).and.verifyProof(proofStruct);
121115
});
122116

123117
it("should prove the tree exclusion", async () => {
@@ -140,9 +134,7 @@ describe("SparseMerkleTree", () => {
140134
isExclusion: 1,
141135
});
142136

143-
const [pA, pB, pC, publicSignals] = await smtCircuit.generateCalldata(proofStruct);
144-
145-
expect(await smtVerifier.verifyProof(pA, pB, pC, publicSignals)).to.be.true;
137+
await expect(smtCircuit).to.useSolidityVerifier(smtVerifier).and.verifyProof(proofStruct);
146138
});
147139

148140
it("should prove the tree exclusion for each depth of bamboo", async () => {
@@ -166,9 +158,7 @@ describe("SparseMerkleTree", () => {
166158
isExclusion: 1,
167159
});
168160

169-
const [pA, pB, pC, publicSignals] = await smtCircuit.generateCalldata(proofStruct);
170-
171-
expect(await smtVerifier.verifyProof(pA, pB, pC, publicSignals)).to.be.true;
161+
await expect(smtCircuit).to.useSolidityVerifier(smtVerifier).and.verifyProof(proofStruct);
172162
}
173163
});
174164

@@ -188,9 +178,7 @@ describe("SparseMerkleTree", () => {
188178
isExclusion: 1,
189179
});
190180

191-
const [pA, pB, pC, publicSignals] = await smtCircuit.generateCalldata(proofStruct);
192-
193-
expect(await smtVerifier.verifyProof(pA, pB, pC, publicSignals)).to.be.true;
181+
await expect(smtCircuit).to.useSolidityVerifier(smtVerifier).and.verifyProof(proofStruct);
194182
});
195183

196184
describe("when data is incorrect", () => {
@@ -213,18 +201,16 @@ describe("SparseMerkleTree", () => {
213201

214202
const incorrectValue = merkleProof.value + 1n;
215203

216-
await expect(
217-
smtCircuit.generateProof({
218-
root: BigInt(merkleProof.root),
219-
siblings: merkleProof.siblings.map((e) => BigInt(e)),
220-
key: BigInt(merkleProof.key),
221-
value: BigInt(incorrectValue),
222-
auxKey: 0,
223-
auxValue: 0,
224-
auxIsEmpty: 0,
225-
isExclusion: 0,
226-
}),
227-
).to.be.rejected;
204+
await expect(smtCircuit).to.not.generateProof({
205+
root: BigInt(merkleProof.root),
206+
siblings: merkleProof.siblings.map((e) => BigInt(e)),
207+
key: BigInt(merkleProof.key),
208+
value: BigInt(incorrectValue),
209+
auxKey: 0,
210+
auxValue: 0,
211+
auxIsEmpty: 0,
212+
isExclusion: 0,
213+
});
228214
});
229215

230216
it("should revert an incorrect tree exclusion", async () => {
@@ -238,18 +224,16 @@ describe("SparseMerkleTree", () => {
238224

239225
auxIsEmpty = auxIsEmpty == 0 ? 1 : 0;
240226

241-
await expect(
242-
smtCircuit.generateProof({
243-
root: BigInt(merkleProof.root),
244-
siblings: merkleProof.siblings.map((e) => BigInt(e)),
245-
key: BigInt(merkleProof.key),
246-
value: 0,
247-
auxKey: BigInt(merkleProof.auxKey),
248-
auxValue: BigInt(merkleProof.auxValue),
249-
auxIsEmpty: auxIsEmpty,
250-
isExclusion: 1,
251-
}),
252-
).to.be.rejected;
227+
await expect(smtCircuit).to.not.generateProof({
228+
root: BigInt(merkleProof.root),
229+
siblings: merkleProof.siblings.map((e) => BigInt(e)),
230+
key: BigInt(merkleProof.key),
231+
value: 0,
232+
auxKey: BigInt(merkleProof.auxKey),
233+
auxValue: BigInt(merkleProof.auxValue),
234+
auxIsEmpty: auxIsEmpty,
235+
isExclusion: 1,
236+
});
253237
});
254238
});
255239
});

0 commit comments

Comments
 (0)