Skip to content

Commit

Permalink
circuit structure
Browse files Browse the repository at this point in the history
  • Loading branch information
nginnever committed May 13, 2024
1 parent ad9aa82 commit de34f7c
Show file tree
Hide file tree
Showing 16 changed files with 217 additions and 361 deletions.
4 changes: 4 additions & 0 deletions packages/circuits/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
artifacts
cache
coverage
24 changes: 24 additions & 0 deletions packages/circuits/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
env: {
browser: false,
es2021: true,
mocha: true,
node: true,
},
plugins: ["@typescript-eslint"],
extends: [
"standard",
"plugin:prettier/recommended",
"plugin:node/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 12,
},
rules: {
"node/no-unsupported-features/es-syntax": [
"error",
{ ignores: ["modules"] },
],
},
};
108 changes: 108 additions & 0 deletions packages/circuits/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# ZK artifacts
zk
browser

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
1 change: 1 addition & 0 deletions packages/circuits/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
pragma circom 2.0.0;

template Vote() {
// private
signal input vote;
vote === 0 || 1;
}

component main = Vote();
component main = Vote();
52 changes: 52 additions & 0 deletions packages/circuits/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "enclave-circuits",
"version": "0.1.0",
"description": "Zk circuits for the Enlcave protocol",
"main": "dist/src/index.js",
"types": "src/index.ts",
"author": "Nathan Ginnever <[email protected]>",
"files": [
"src",
"dist",
"zk",
"circuits",
"browser"
],
"scripts": {
"test": "ts-mocha -p tsconfig.json test/**/*.ts --timeout 30000 --exit",
"pretest": "tsc -p tsconfig.json",
"precompile": "scripts/prerequisites.sh && mkdir -p zk/circuits zk/zkeys zk/verifiers",
"postbuild": "cp zk/zkeys/main.zkey ../app/public && cp zk/circuits/main_js/main.wasm ../app/public",
"compile": "for circuit in circuits/*.circom; do circom $circuit --r1cs --sym --wasm -o zk/circuits;done && tsc",
"export:sample-zkey": "for circuit in zk/circuits/*.r1cs; do snarkjs groth16 setup $circuit powersOfTau28_hez_final_15.ptau zk/zkeys/$(basename -- $circuit .r1cs).zkey;done",
"export:verifier": "for zkey in zk/zkeys/*.zkey; do snarkjs zkey export solidityverifier $zkey zk/verifiers/$(basename -- $zkey .zkey | perl -nE 'say ucfirst').sol;done",
"build": "yarn compile && yarn export:sample-zkey && yarn export:verifier"
},
"license": "MIT",
"dependencies": {
"@ethersproject/abstract-signer": "^5.6.0",
"circomlib": "^2.0.3",
"circomlibjs": "^0.1.2",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.1",
"eslint-plugin-promise": "^5.2.0",
"ethers": "^5.6.4",
"snarkjs": "^0.4.16"
},
"devDependencies": {
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.0",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"chai": "^4.3.6",
"ts-mocha": "^9.0.2"
},
"engines": {
"npm": ">=7.0.0",
"node": ">=14.0.0"
}
}
7 changes: 7 additions & 0 deletions packages/circuits/scripts/prerequisites.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

if ! command -v circom &> /dev/null
then
echo "Circom could not be found. Visit https://docs.circom.io/getting-started/installation/ and install circom2"
exit 1
fi
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ export class ZKPClient {
c: [proof.pi_c[0], proof.pi_c[1]] as [bigint, bigint],
};
}
}
}
4 changes: 4 additions & 0 deletions packages/circuits/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ZKPClient, Proof } from "./client";

export { ZKPClient };
export type { Proof };
2 changes: 2 additions & 0 deletions packages/circuits/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare module "snarkjs";
declare module "circomlibjs";
13 changes: 13 additions & 0 deletions packages/circuits/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"outDir": "dist",
"skipLibCheck": true,
"allowJs": true
},
"exclude": ["./dist", "node_modules"],
"include": ["./src"]
}
Binary file removed packages/rust/circuits/vote_integrity.r1cs
Binary file not shown.
1 change: 0 additions & 1 deletion packages/rust/circuits/vote_integrity.sym

This file was deleted.

20 changes: 0 additions & 20 deletions packages/rust/circuits/vote_integrity_js/generate_witness.js

This file was deleted.

Binary file not shown.
Loading

0 comments on commit de34f7c

Please sign in to comment.