Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement zkit wrapper generation for given circuits #4

Merged
merged 22 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e65d179
Fixed a bug related to: Array could have any number of dimensions (e.…
KyrylR Jun 25, 2024
041c738
Updated versions and CHANGELOG.md
KyrylR Jun 25, 2024
0cac0c5
Refactored architecture to work as a library
KyrylR Jun 27, 2024
71b1828
Implemented Zkit wrapper generation for given circuits
KyrylR Jun 27, 2024
f153cf8
Moved to node and mocha
KyrylR Jun 28, 2024
ea5a152
Used ejs instead of ts factory to render the wrapper class
KyrylR Jun 28, 2024
6462b15
Added test to check proof generation and verification
KyrylR Jun 28, 2024
e941bca
Updated project structure
KyrylR Jun 28, 2024
0ae192d
Added generation of the hardhat runtime extension file for circuits
KyrylR Jun 28, 2024
a39f3c2
Added a helper function to return the circuit object from given name
KyrylR Jun 28, 2024
aca16d9
Changed the ArtifactGeneratorConfig to accept an array of paths to ci…
KyrylR Jun 28, 2024
04ac182
Updated CHANGELOG.md
KyrylR Jun 28, 2024
80e0b0b
Resolved an issue where inputs could have the wrong number of dimensions
KyrylR Jun 28, 2024
93f0811
Fixed tests
KyrylR Jun 28, 2024
f2455fa
Updated CHANGELOG.md
KyrylR Jun 28, 2024
5a95e88
Updated deps
KyrylR Jun 28, 2024
78c4797
Fixed tests
KyrylR Jun 28, 2024
17a698e
Updated JSDoc
KyrylR Jun 28, 2024
4d42041
Added circuit types Hardhat definition generation of all possible cir…
KyrylR Jul 2, 2024
476683d
Updated package.json
KyrylR Jul 2, 2024
bbee0de
Updated README
KyrylR Jul 2, 2024
603ab9e
Deleted automatic artifacts clean up
KyrylR Jul 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ jobs:
with:
node-version: '${{ matrix.node }}'

- uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- uses: actions/checkout@v3
- name: 'Cache node_modules'
uses: actions/cache@v3
Expand All @@ -36,7 +32,7 @@ jobs:
${{ runner.os }}-node-v${{ matrix.node }}

- name: Install Dependencies
run: bun install
run: npm install

- name: Run All Tests
run: bun run test
run: npm run test
6 changes: 6 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"require": "ts-node/register",
"file": ["test/setup.ts"],
"ignore": ["test/fixture-projects/**/*"],
"timeout": 10000
}
19 changes: 14 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
# Changelog

All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v0.2.0]

## [Unreleased]
- Resolved an issue where inputs could have the wrong number of dimensions, such as `bigint[]` when `bigint[][]` was expected.
- Refactored architecture to work as a library
- Deleted support for standalone run
- Added ability to specify where the circuit's AST files are stored
- Added ability to specify where to put generated artifacts and types
- Implemented Zkit wrapper generation for given circuits
- Used EJS instead of TS factory to render the wrapper class
- Added generation of the Hardhat runtime extension file for circuits
- Added a helper function to return the circuit object from a given name
- Changed the ArtifactGeneratorConfig to accept an array of paths to circuit ASTs.
- Deleted automatic artifacts clean up.

## [v0.1.1]

### Added

- Initial release of the ZKType package
- Support for generating TypeScript bindings for Circom circuits

[Unreleased]: https://github.com/dl-solarity/zktype/compare/master...develop
55 changes: 33 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[![npm](https://img.shields.io/npm/v/@solarity/zktype.svg)](https://www.npmjs.com/package/@solarity/zktype)
[![npm](https://img.shields.io/npm/v/@solarity/zktype.svg)](https://www.npmjs.com/package/@solarity/zktype)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

# ZKType
# ZKType - TypeScript bindings for Circom circuits

ZKType - unleash TypeScript bindings for Circom circuits.
**ZKType simplifies and makes user-friendly the process of working with Circom circuits.**

- Generate a [zkit](https://github.com/dl-solarity/zkit) wrapper for given circuits.
- Ensure that all inputs and proofs are correctly formatted.

## Installation

Expand All @@ -14,31 +18,38 @@ npm install --save-dev @solarity/zktype

## Usage

If all of your circuits are in the `circuits` folder, simply run the following command to generate TypeScript bindings
for the Circom circuits:

```bash
npx zktype
```
> [!IMPORTANT]
> ZKType is not meant to be used directly as its fitness relies heavily on the environment, e.g., on Circom compilation artifacts management. Consider using [hardhat-zkit](https://github.com/dl-solarity/hardhat-zkit), which is a complete, developer-friendly package.

By default, the script will look for circuits inside the `circuits` folder. If you wish to specify another folder
to look for circuits, you can use the following command:
### CircuitTypesGenerator

```bash
npx zktype --path ./src
```
`CircuitTypesGenerator` is an entry point for generating TypeScript bindings for a given circuit.

To learn more about available commands, run:
To create a `CircuitTypesGenerator` object, it is necessary to pass a config:

```bash
npx zktype --help
```typescript
ZKTypeConfig = {
basePath: string;
circuitsASTPaths: string[];
outputArtifactsDir?: string;
outputTypesDir?: string;
};
```

## How it works
This config contains all the information required to generate TypeScript bindings for given circuits.

Under the hood, ZKType uses the `@distributedlab/circom2` package, which contains a WASM-compiled Circom compiler.
It uses this compiler to extract ASTs from all the circuits, generate artifacts, and then generate types based on these artifacts.
- `basePath` - Path to the root directory of the project where circuits are stored.
- `circuitsASTPaths` - Array of paths to the circuits' AST files.
- `outputArtifactsDir` - Path to the directory where the generated artifacts will be stored.
- Optional. Default: `artifacts/circuits`.
- `outputTypesDir` - Path to the directory where the generated types will be stored.
- Optional. Default: `generated-types/circuits`.

## Known limitations
#### generateTypes()

* Currently, after each run, all circuits will be recompiled without checking if a circuit has changed or not.
Generates TypeScript bindings for the given circuits, based on the provided config.

```typescript
const generator = new CircuitTypesGenerator(config);
await generator.generateTypes();
```
30 changes: 0 additions & 30 deletions bin/zktype.ts

This file was deleted.

Binary file removed bun.lockb
Binary file not shown.
3 changes: 0 additions & 3 deletions bunfig.toml

This file was deleted.

Loading
Loading