Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions circuits/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ptau
main
test
node_modules
build
1 change: 1 addition & 0 deletions circuits/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
Empty file added circuits/LICENSE
Empty file.
Empty file added circuits/README.md
Empty file.
21 changes: 21 additions & 0 deletions circuits/circomkit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"protocol": "groth16",
"prime": "bn128",
"version": "2.1.5",
"circuits": "./circuits.json",
"dirPtau": "./ptau",
"dirCircuits": "./src",
"dirInputs": "./inputs",
"dirBuild": "./build",
"optimization": 2,
"inspect": true,
"include": [
"./node_modules/circomlib/circuits/sha256",
"./node_modules/@zk-kit/binary-merkle-root.circom/src",
"./node_modules/circomlib/circuits"
],
"groth16numContributions": 1,
"groth16askForEntropy": false,
"logLevel": "INFO",
"verbose": true
}
8 changes: 8 additions & 0 deletions circuits/circuits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semaphore": {
"file": "semaphore",
"template": "Semaphore",
"pubs": ["message", "scope"],
"params": [10]
}
}
15 changes: 15 additions & 0 deletions circuits/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"scripts": {
"compile": "circomkit compile semaphore"
},
"dependencies": {
"@zk-kit/binary-merkle-root.circom": "^1.0.0",
"circomlib": "^2.0.5"
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
"devDependencies": {
"@types/mocha": "^10.0.10",
"circomkit": "^0.3.1",
"mocha": "^10.8.2"
}
}
34 changes: 34 additions & 0 deletions circuits/src/semaphore.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pragma circom 2.1.5;

include "babyjub.circom";
include "poseidon.circom";
include "binary-merkle-root.circom";
include "comparators.circom";

template Semaphore(MAX_DEPTH) {
signal input secret;
signal input merkleProofLength, merkleProofIndices[MAX_DEPTH], merkleProofSiblings[MAX_DEPTH];
signal input message;
signal input scope;

signal output merkleRoot, nullifier;

// Keep BabyJubjub curve parameters
var l = 2736030358979909402780800718157159386076813972158567259200215660948447373041;

component isLessThan = LessThan(251);
isLessThan.in <== [secret, l];
isLessThan.out === 1;

// Use existing BabyJubjub implementation
var Ax, Ay;
(Ax, Ay) = BabyPbk()(secret);

var identityCommitment = Poseidon(2)([Ax, Ay]);

merkleRoot <== BinaryMerkleRoot(MAX_DEPTH)(identityCommitment, merkleProofLength, merkleProofIndices, merkleProofSiblings);

nullifier <== Poseidon(2)([scope, secret]);

signal dummySquare <== message * message;
}
10 changes: 10 additions & 0 deletions circuits/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"esModuleInterop": true
},
"include": [
"tests/**/*"
]
}
Loading