@solarity/zkit
TypeScript icon, indicating that this package has built-in type declarations

0.3.0-rc.0 • Public • Published

npm License: MIT

ZKit - Circom Zero Knowledge Kit

A zero knowledge kit that helps you interact with Circom circuits.

  • Generate and verify ZK proofs with a single line of code.
  • Render optimized Solidity | Vyper verifiers.
  • Build and work with ZK witnesses.

Installation

To install the package, run:

npm install --save-dev @solarity/zkit

Usage

[!IMPORTANT] The kit is not meant to be used directly as its fitness relies heavily on the environment, Circom compilation artifacts management, processing of remappings, etc. Consider using hardhat-zkit which is a complete, developer-friendly package.

CircuitZKit

CircuitZKit is a user-friendly interface for interacting with circom circuits.

To create a CircuitZKit object it is necessary to pass a config:

CircuitZKitConfig = {
  circuitName: string;
  circuitArtifactsPath: string;
  verifierDirPath: string;
  provingSystem?: VerifierProvingSystem;
};

This config contains all the information required to work with the circuit, namely:

  • circuitName - Name of the circuit file without extension
  • circuitArtifactsPath - Full path to compilation artifacts for the desired circuit
  • verifierDirPath - Full path to the directory where Solidity | Vyper verifier file will be generated
  • provingSystem - The proving system that will be used to generate the verifier contract. Right now only groth16 is supported

getTemplate()

Static CircuitZKit function that returns the contents of a template file by the passed type.

const templateContent = CircuitZKit.getTemplate("groth16", "sol");

createVerifier()

Creates a Solidity | Vyper verifier contract on verifierDirPath path, which was specified in the config.

await multiplier.createVerifier("sol");

calculateWitness()

Calculates a witness in the tmp directory and returns its json representation.

/// witness = [1n, 200n, 20n, 10n]
const witness = await multiplier.calculateWitness({ a: 10, b: 20 });

generateProof()

Generates a proof for the given inputs.

/// { proof: { pi_a, pi_b, pi_c, protocol, curve }, publicSignals: [6] }
const proof = await multiplier.generateProof({ a: 2, b: 3 });

verifyProof()

Verifies the proof.

/// true
const isValidProof = await multiplier.verifyProof(proof);

generateCalldata()

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

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

Known limitations

  • Currently, ZKit supports only the Groth16 proving system.

Readme

Keywords

Package Sidebar

Install

npm i @solarity/zkit

Weekly Downloads

98

Version

0.3.0-rc.0

License

MIT

Unpacked Size

174 kB

Total Files

66

Last publish

Collaborators

  • hrom_h
  • arvolear