Skip to content

Commit

Permalink
init: template
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVikasRushi committed Aug 1, 2024
0 parents commit 4758f20
Show file tree
Hide file tree
Showing 15 changed files with 1,372 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: tests

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install --yes \
build-essential \
libgmp-dev \
libsodium-dev \
nasm \
nlohmann-json3-dev
- name: Download Circom Binary v2.1.5\8
run: |
wget -qO /home/runner/work/circom https://github.com/iden3/circom/releases/download/v2.1.8/circom-linux-amd64
chmod +x /home/runner/work/circom
sudo mv /home/runner/work/circom /bin/circom
- name: Print Circom version
run: circom --version

- name: Install dependencies
run: yarn

- name: Run tests
run: yarn test
122 changes: 122 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# 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

# builds
build
dist

# circuit-specific powers of tau are ignored
*.ptau
# universal ptaus not ignored
!ptau/*
# temporary ptaus are ignored
tmp.ptau

# is this still a thing lol
.DS_Store

# ignore auto generated test circuits
circuits/test
ptau
7 changes: 7 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extension": ["ts"],
"require": "ts-node/register",
"spec": "tests/**/*.test.ts",
"timeout": 100000,
"exit": true
}
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
printWidth: 120,
};
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["iden3.circom"]
}
5 changes: 5 additions & 0 deletions circomkit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": "2.1.2",
"proofSystem": "groth16",
"curve": "bn128"
}
7 changes: 7 additions & 0 deletions circuits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"add_2": {
"file": "add",
"template": "Add",
"params": [2]
}
}
8 changes: 8 additions & 0 deletions circuits/add.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pragma circom 2.1.8;

template Add(n) {
signal input in[n];
signal output out;

out <== in[0] + in[1];
}
3 changes: 3 additions & 0 deletions inputs/add_2/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"in": [1, 1]
}
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"description": "Circomkit Template",
"scripts": {
"start": "npx ts-node ./src/index.ts",
"test": "npx mocha",
"compile:test": "npx circomkit compile add_2 && npx circomkit prove add_2 default && npx circomkit verify add_2 default"
},
"dependencies": {
"circomkit": "^0.0.22",
"circomlib": "^2.0.5"
},
"devDependencies": {
"@types/mocha": "^10.0.1",
"@types/node": "^20.3.0",
"mocha": "^10.2.0",
"ts-node": "^10.9.1",
"typescript": "^5.1.3"
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

21 changes: 21 additions & 0 deletions tests/add.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { WitnessTester } from "circomkit";
import { circomkit } from "./common";

describe("Add", () => {
let circuit: WitnessTester<["in"], ["out"]>;
let arr = [1, 2];
describe("Add first two number of array", () => {
before(async () => {
circuit = await circomkit.WitnessTester(`fibonacci_${arr.length}`, {
file: "add",
template: "Add",
params: [arr.length],
});
console.log("#constraints:", await circuit.getConstraintCount());
});

it("should compute correctly", async () => {
await circuit.expectPass({ in: [1, 1] }, { out: 2 });
});
});
});
5 changes: 5 additions & 0 deletions tests/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Circomkit } from "circomkit";

export const circomkit = new Circomkit({
verbose: false,
});
10 changes: 10 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"types": ["mocha", "node"],
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true
}
}
Loading

0 comments on commit 4758f20

Please sign in to comment.