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

[wip] semaphore proofs and groups #2

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 9 additions & 0 deletions apps/passport-client/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@ module.exports = {
compiler: {
styledComponents: true,
},
webpack: (config, { isServer }) => {
if (!isServer) {
config.resolve.fallback = {
fs: false,
};
}

return config;
},
};
9 changes: 6 additions & 3 deletions apps/passport-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
"lint": "next lint"
},
"dependencies": {
"@semaphore-protocol/group": "^3.1.0",
"@semaphore-protocol/identity": "^3.1.0",
"@semaphore-protocol/proof": "^3.1.0",
"next": "^13.1.1",
"passport-interface": "*",
"pcd-types": "*",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"styled-components": "^5.3.6",
"ui": "*",
"pcd-types": "*",
"passport-interface": "*"
"ui": "*"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand Down
8 changes: 8 additions & 0 deletions apps/passport-client/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useCallback } from "react";
import styled from "styled-components";
import { Button } from "../components/Button";
import Spacer from "../components/Spacer";
import { SemaphoreManager } from "../src/SemaphoreManager";

export default function ZuzaluApp() {
return (
Expand All @@ -27,6 +28,7 @@ export default function ZuzaluApp() {
</Form>
<Spacer h={8} />
<Button onClick={useCallback(onSyncExisting, [])}>Sync Existing</Button>
<Button onClick={useCallback(onSemaphoreTest, [])}>Test Semaphore</Button>
</Container>
);
}
Expand All @@ -52,6 +54,12 @@ function onSyncExisting(e: React.MouseEvent<HTMLButtonElement>) {
window.alert("Under construction");
}

function onSemaphoreTest(e: React.MouseEvent<HTMLButtonElement>) {
e.preventDefault();
const manager = new SemaphoreManager();
manager.test();
}

const Container = styled.div`
display: flex;
justify-content: center;
Expand Down
109 changes: 109 additions & 0 deletions apps/passport-client/public/semaphore-artifacts/16.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"protocol": "groth16",
"curve": "bn128",
"nPublic": 4,
"vk_alpha_1": [
"20491192805390485299153009773594534940189261866228447918068658471970481763042",
"9383485363053290200918347156157836566562967994039712273449902621266178545958",
"1"
],
"vk_beta_2": [
[
"6375614351688725206403948262868962793625744043794305715222011528459656738731",
"4252822878758300859123897981450591353533073413197771768651442665752259397132"
],
[
"10505242626370262277552901082094356697409835680220590971873171140371331206856",
"21847035105528745403288232691147584728191162732299865338377159692350059136679"
],
[
"1",
"0"
]
],
"vk_gamma_2": [
[
"10857046999023057135944570762232829481370756359578518086990519993285655852781",
"11559732032986387107991004021392285783925812861821192530917403151452391805634"
],
[
"8495653923123431417604973247489272438418190587263600148770280649306958101930",
"4082367875863433681332203403145435568316851327593401208105741076214120093531"
],
[
"1",
"0"
]
],
"vk_delta_2": [
[
"16243966861079634958125511652590761846958471358623040426599000904006426210032",
"13406811599156507528361773763681356312643537981039994686313383243831956396116"
],
[
"15688083679237922164673518758181461582601853873216319711156397437601833996222",
"11781596534582143578120404722739278517564025497573071755253972265891888117374"
],
[
"1",
"0"
]
],
"vk_alphabeta_12": [
[
[
"2029413683389138792403550203267699914886160938906632433982220835551125967885",
"21072700047562757817161031222997517981543347628379360635925549008442030252106"
],
[
"5940354580057074848093997050200682056184807770593307860589430076672439820312",
"12156638873931618554171829126792193045421052652279363021382169897324752428276"
],
[
"7898200236362823042373859371574133993780991612861777490112507062703164551277",
"7074218545237549455313236346927434013100842096812539264420499035217050630853"
]
],
[
[
"7077479683546002997211712695946002074877511277312570035766170199895071832130",
"10093483419865920389913245021038182291233451549023025229112148274109565435465"
],
[
"4595479056700221319381530156280926371456704509942304414423590385166031118820",
"19831328484489333784475432780421641293929726139240675179672856274388269393268"
],
[
"11934129596455521040620786944827826205713621633706285934057045369193958244500",
"8037395052364110730298837004334506829870972346962140206007064471173334027475"
]
]
],
"IC": [
[
"1964404930528116823793003656764176108669615750422202377358993070935069307720",
"2137714996673694828207437580381836490878070731768805974506391024595988817424",
"1"
],
[
"19568893707760843340848992184233194433177372925415116053368211122719346671126",
"11639469568629189918046964192305250472192697612201524135560178632824282818614",
"1"
],
[
"5317268879687484957437879782519918549127939892210247573193613900261494313825",
"528174394975085006443543773707702838726735933116136102590448357278717993744",
"1"
],
[
"14865918005176722116473730206622066845866539143554731094374354951675249722731",
"3197770568483953664363740385883457803041685902965668289308665954510373380344",
"1"
],
[
"6863358721495494421022713667808247652425178970453300712435830652679038918987",
"15025816433373311798308762709072064417001390853103872064614174594927359131281",
"1"
]
]
}
Binary file not shown.
Binary file not shown.
48 changes: 48 additions & 0 deletions apps/passport-client/src/SemaphoreManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Group } from "@semaphore-protocol/group";
import { Identity } from "@semaphore-protocol/identity";
import { generateProof, verifyProof } from "@semaphore-protocol/proof";

export class SemaphoreManager {
private identities: Identity[] = [];

public async test() {
const identity = new Identity();
this.identities.push(identity);

console.log("identity", identity);

const group = new Group(1, 16);
const groupAddStart = performance.now();
group.addMember(identity.commitment);
const groupAddEnd = performance.now();

console.log("group", group);
console.log("took ", groupAddEnd - groupAddStart, "ms");

const externalNullifier = group.root;
const signal = 1;

const proofStart = performance.now();
const fullProof = await generateProof(
identity,
group,
externalNullifier,
signal,
{
zkeyFilePath: "./semaphore-artifacts/16.zkey",
wasmFilePath: "./semaphore-artifacts/16.wasm",
}
);
const proofEnd = performance.now();

console.log("fullProof", fullProof);
console.log("took ", proofEnd - proofStart, "ms");

const verificationStart = performance.now();
const verified = await verifyProof(fullProof, 16);
const verificationEnd = performance.now();

console.log("verified", verified);
console.log("took ", verificationEnd - verificationStart, "ms");
}
}
Loading