A user-friendly Circom Chai matchers for testing witnesses and ZK proofs
- Write convenient circuits tests via Chai assertions extension.
- Enjoy full TypeScript typization of input and output signals.
- Integrate smoothly with hardhat-zkit.
To install the package, run:
npm install --save-dev @solarity/chai-zkit
And add the following line to your hardhat.config
:
import "@solarity/chai-zkit";
Or if you are using JavaScript:
require("@solarity/chai-zkit");
Important
The package is meant to be used together with hardhat-zkit plugin that provides circuits objects to be tested with chai assertions.
After installing the package, you may use the following assertions:
const matrix = await zkit.getCircuit("Matrix");
// partial output assertion
await expect(matrix).with.witnessInputs({ a, b, c }).to.have.witnessOutputs({ d });
// strict assertion, all the outputs must be present
await expect(matrix).with.witnessInputs({ a, b, c }).to.have.strict.witnessOutputs({ d, e, f });
// provided output `e` doesn't match the obtained one
await expect(expect(matrix).with.witnessInputs({ a, b, c }).to.have.witnessOutputs({ e })).to.be.rejectedWith(
`Expected output "e" to be "[[2,5,0],[17,26,0],[0,0,0]]", but got "[[1,4,0],[16,25,0],[0,0,0]]"`,
);
const matrix = await zkit.getCircuit("Matrix");
// proof generation assertion
await expect(matrix).to.generateProof({ a, b, c });
await expect(matrix).to.not.generateProof({ b, c, d });
const proof = await matrix.generateProof({ a, b, c });
// proof verification assertion
await expect(matrix).to.verifyProof(proof);
await expect(matrix).to.not.verifyProof(otherProof);
// use generated solidity verifier to verify the proof
await expect(matrix).to.useSolidityVerifier(matrixVerifier).and.verifyProof(proof);
const matrix = await zkit.getCircuit("Matrix");
// constraints > 6
await expect(matrix).to.have.constraints.gt(6);
await expect(matrix).to.have.constraints.greaterThan(6);
// constraints < 10
await expect(matrix).to.have.constraints.lt(10);
await expect(matrix).to.have.constraints.lessThan(10);
- Do not use
not
chai negation priorwitnessInputs
call, this will break the typization.