Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dl-solarity/chai-zkit
Chai matchers for Circom
https://github.com/dl-solarity/chai-zkit
assertions chai chai-plugin circom solarity zk zkit
Last synced: 3 months ago
JSON representation
Chai matchers for Circom
- Host: GitHub
- URL: https://github.com/dl-solarity/chai-zkit
- Owner: dl-solarity
- License: mit
- Created: 2024-07-04T10:40:15.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2024-09-09T15:08:38.000Z (4 months ago)
- Last Synced: 2024-10-01T02:22:16.450Z (3 months ago)
- Topics: assertions, chai, chai-plugin, circom, solarity, zk, zkit
- Language: TypeScript
- Homepage: https://npmjs.com/package/@solarity/chai-zkit
- Size: 495 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![npm](https://img.shields.io/npm/v/@solarity/chai-zkit.svg)](https://www.npmjs.com/package/@solarity/chai-zkit)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)# Chai-zkit - Chai matchers for Circom
**A user-friendly Circom Chai matchers for testing witnesses and ZK proofs**
- Write convenient circuits tests via [Chai](https://www.chaijs.com/) assertions extension.
- Enjoy full TypeScript typization of input and output signals.
- Integrate smoothly with [hardhat-zkit](https://github.com/dl-solarity/hardhat-zkit).## Installation
To install the package, run:
```bash
npm install --save-dev @solarity/chai-zkit
```And add the following line to your `hardhat.config`:
```ts
import "@solarity/chai-zkit";
```Or if you are using JavaScript:
```js
require("@solarity/chai-zkit");
```## Usage
> [!IMPORTANT]
> The package is meant to be used together with [hardhat-zkit](https://github.com/dl-solarity/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
```ts
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
```ts
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
```ts
const matrix = await zkit.getCircuit("Matrix");// constraints > 6
expect(matrix).to.have.constraints.gt(6);
expect(matrix).to.have.constraints.greaterThan(6);// constraints < 10
expect(matrix).to.have.constraints.lt(10);
expect(matrix).to.have.constraints.lessThan(10);
```## Known limitations
- Do not use `not` chai negation prior `witnessInputs` call, this will break the typization.