Skip to content

Commit

Permalink
Add Proof testing functionality (#4)
Browse files Browse the repository at this point in the history
* Add base proof testing functions

* Update proof testing logic & clean up

* Fix unit tests

* fix readme

---------

Co-authored-by: Artem Chystiakov <[email protected]>
  • Loading branch information
Hrom131 and Arvolear authored Aug 12, 2024
1 parent 2c8b0b5 commit 3bba7f9
Show file tree
Hide file tree
Showing 19 changed files with 911 additions and 680 deletions.
35 changes: 25 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ npm install --save-dev @solarity/chai-zkit

And add the following line to your `hardhat.config`:

```js
require("@solarity/chai-zkit");
```ts
import "@solarity/chai-zkit";
```

Or if you are using TypeScript:
Or if you are using JavaScript:

```ts
import "@solarity/chai-zkit";
```js
require("@solarity/chai-zkit");
```

## Usage
Expand All @@ -36,6 +36,8 @@ import "@solarity/chai-zkit";
After installing the package, you may use the following assertions:

### Witness testing

```ts
const matrix = await zkit.getCircuit("Matrix");

Expand All @@ -49,14 +51,27 @@ await expect(matrix).with.witnessInputs({ a, b, c }).to.have.strict.witnessOutpu
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);

// `not` negation used, provided output `d` matches the obtained one
await expect(
expect(matrix).with.witnessInputs({ a, b, c }).to.not.have.witnessOutputs({ d }),
).to.be.rejectedWith(`Expected output "d" NOT to be "[[2,5,0],[17,26,0],[0,0,0]]", but it is"`);
// use generated solidity verifier to verify the proof
await expect(matrix).to.useSolidityVerifier(matrixVerifier).and.verifyProof(proof);
```

## Known limitations

- Do not use `not` chai negation prior `witnessInputs` call, this will break the typization.
- Temporarily, only the witness `input <> output` signals testing is supported.
Loading

0 comments on commit 3bba7f9

Please sign in to comment.