Home

Awesome

npm License: MIT

Chai-zkit - Chai matchers for Circom

A user-friendly Circom Chai matchers for testing witnesses and ZK proofs

Installation

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

Usage

[!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:

Witness testing

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]]"`,
);

Proof testing

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

Constraints testing

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

Known limitations