Skip to content

Commit

Permalink
fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvolear committed May 15, 2024
1 parent 75c48be commit 108b7db
Showing 1 changed file with 20 additions and 43 deletions.
63 changes: 20 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
[![npm](https://img.shields.io/npm/v/@solarity/zkit.svg)](https://www.npmjs.com/package/@solarity/zkit)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

# ZKit
# ZKit - Zero Knowledge Kit

A zero knowledge kit that helps you develop circuits using Circom.
**A zero knowledge kit that helps you develop circuits using Circom.**

- Compile and interact with circuits without snarkjs hassle.
- Generate and verify ZK proofs with a single line of code.
- Render optimized Solidity verifiers.
- Forget about native dependencies - everything is in TypeScript.

## Installation

Expand All @@ -14,33 +20,9 @@ npm install --save-dev @solarity/zkit

## Usage

ZKit is an S-tier Circom assistant:

- Compile and interact with circuits without snarkjs hassle
- Generate and verify ZK proofs with a single line of code
- Render optimized Solidity verifiers
- Forget about native dependencies - everything is in TypeScript

### CircomZKit

ZKit is a configless package, which means you don't need to provide any configuration to use it.

Suppose you have the following circuit:

```circom
pragma circom 2.1.6;
template Multiplier() {
signal input a;
signal input b;
signal output out;
out <== a * b;
}
component main = Multiplier();
```

You can start work with it as follows:
ZKit is a configless package, which means you don't need to provide any configuration to use it:

```typescript
import { CircomZKit } from "@solarity/zkit";
Expand All @@ -50,14 +32,12 @@ async function main() {

const multiplier = zkit.getCircuit("Multiplier");

/// Generates artifacts in the "./zkit-artifacts" directory
// Generates artifacts in the "./zkit-artifacts" directory
await multiplier.compile();
}

main()
.catch((err) => {
process.exit(1);
});
// Generates ZK proof
const proof = await multiplier.generateProof({ a: 2, b: 3});
}
```

By default, ZKit will look for the circuit file in the `./circuits` directory. However, you can change this by providing a custom one:
Expand All @@ -74,7 +54,7 @@ You can also provide a custom path to the directory where the power-of-tau files
new CircomZKit({ ptauDir: "./my-ptau" });
```

> [!NOTE]
> [!IMPORTANT]
> Note that all the files in the `ptauDir` directory must have the `powers-of-tau-{x}.ptau` name format, where `{x}` is a maximum degree (2<sup>x</sup>) of constraints a `ptau` supports.
ZKit may also ask you for the permission to download the power-of-tau files. You can enable this by toggling off the `allowDownload` option:
Expand All @@ -87,6 +67,9 @@ new CircomZKit({ allowDownload: false });

Once you created a `CircuitZKit` instance using the `getCircuit` method, you can manage the underlying circuit using the following methods:

> [!NOTE]
> You should first compile the circuit before creating verifiers or generating proofs.
#### compile()

Compiles the circuit and generates the artifacts in the `./zkit-artifacts` or in the provided `artifactsDir` directory. The default output is `r1cs`, `zkey` and `vkey` files.
Expand All @@ -99,9 +82,6 @@ await multiplier.compile();

Creates Solidity verifier contract in the `./contracts/verifiers` or in the provided `verifiersDir` directory.

> [!NOTE]
> You should first compile the circuit before creating the verifier.
```typescript
await multiplier.createVerifier();
```
Expand All @@ -110,12 +90,9 @@ await multiplier.createVerifier();

Generates a proof for the given inputs.

> [!NOTE]
> You should first compile the circuit before generating the proof.
```typescript
/// { proof: { pi_a, pi_b, pi_c, protocol, curve }, publicSignals: [6] }
const proof = await multiplier.createVerifier({ a: 2, b: 3});
const proof = await multiplier.generateProof({ a: 2, b: 3});
```

#### verifyProof()
Expand All @@ -129,11 +106,11 @@ const isValidProof = await multiplier.verifyProof(proof);

#### generateCalldata()

Generates calldata by proof for the Solidity verifier's `verifyProof` method.
Generates calldata by proof for the Solidity verifier's `verifyProof()` method.

```typescript
/// You can use this calldata to call the verifier contract
const calldata = await multiplier.verifyProof(proof);
const calldata = await multiplier.generateCalldata(proof);
```

## Known limitations
Expand Down

0 comments on commit 108b7db

Please sign in to comment.