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

feat(refactor) - code refactoring and generalization #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
85 changes: 62 additions & 23 deletions demo/cli_demo.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,72 @@
### /api/generateProof
# Create DB

Send a POST request to the `/api/generateProof` endpoint with a JSON body containing the cicuit input of the desired circuit:
Instal postgresql

ProcessMessages:
```
curl \
-X POST \
-H "Content-Type: application/json" \
-d @demo/request_generateProof_ProcessMessages.json \
http://localhost:8080/api/generateProof
```bash
createdb coordinatorservice
psql coordinatorservice
CREATE ROLE coordinator WITH LOGIN PASSWORD 'maci-coordinator';
GRANT ALL PRIVILEGES ON DATABASE coordinatorservice TO coordinator;
```

TallyVotes:
```
curl \
-X POST \
-H "Content-Type: application/json" \
-d @demo/request_generateProof_TallyVotes.json \
http://localhost:8080/api/generateProof
```
Schema:

### /api/getResult
```sql
CREATE TABLE circuits (
name TEXT PRIMARY KEY,
description TEXT,
zKey_path TEXT,
wasm_path TEXT
);

```
curl http://localhost:8080/api/getResult
CREATE TABLE Proofs (
id INTEGER,
circuit_name TEXT REFERENCES circuits(name),
proof JSONB,
status TEXT,
public_inputs JSONB,
PRIMARY KEY(circuit_name, id)
);
```

## Generate Proof using snarkjs
Copy and paste it in psql.

# Generate TLS certs

```bash
openssl req -x509 -newkey rsa:4096 -keyout demo/server.key -out demo/server.crt -days 365 -nodes
```
snarkjs groth16 prove instruments/TallyVotes_6-2-3_test.0.zkey data/TallyVotes/6-2-3/witness_wasm.wtns outputs/proof_TallyVotes_6-2-3.json outputs/public_TallyVotes_6-2-3.json
```

# Run the service (without Docker)

`export JWT_SECRET=maci DB_NAME=coordinatorservice SQL_USER="coordinator" SQL_PASSWORD="maci-coordinator" && go run main.go`

Make sure to copy the JWT token printed on screen (only for dev purposes)

# register new circuit config

`curl https://localhost:8080/api/registerNewCircuit -d @demo/registerCircuitRequest.json -H "Content-Type: application/json" -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYWRtaW4iLCJ1c2VyX2lkIjoiYWRtaW4ifQ.a1XALB112S0zbkl3tE4e_QxO3PA3vutMO4bYc-mO06E" -k`

# get all circuits

`curl https://localhost:8080/api/registeredCircuits -k`

# request a proof

`curl https://localhost:8080/api/generateProof -H "Content-Type: application/json" -d @demo/requestProof.json -k`

# request multiple proofs

`curl https://localhost:8080/api/generateMultipleProofs -H "Content-Type: application/json" -d @demo/requestProofs.json -k`

# get one result

`curl 'https://localhost:8080/api/getResult?circuitName=multiplier&proofIds=0' -k`

# get multiple results

`curl https://localhost:8080/api/getResult -d @demo/getMultipleProofs.json -H "Content-Type: application/json" -k`

# get all available proofs

`curl https://localhost:8080/api/proofs/available -k`
File renamed without changes.
13 changes: 13 additions & 0 deletions demo/getMultipleProofs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"circuits":
[
{
"circuitName": "processMessages_6-8-2-3",
"proofIds": [ 0, 1 ]
},
{
"circuitName": "tallyVotes_6-2-3",
"proofIds": [ 0, 1 ]
}
]
}
5 changes: 5 additions & 0 deletions demo/registerCircuitRequest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"circuitName": "tallyVotes_6-2-3",
"zKeyURL": "https://maci-staging-ceremony-pse-p0tion-staging.s3.eu-central-1.amazonaws.com/circuits/tallyvotes_6-2-3/contributions/tallyvotes_6-2-3_final.zkey",
"wasmURL": "https://maci-staging-ceremony-pse-p0tion-staging.s3.eu-central-1.amazonaws.com/circuits/tallyvotes_6-2-3/tallyvotes_6-2-3.wasm"
}
7 changes: 7 additions & 0 deletions demo/requestProof.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"circuitName": "multiplier2",
"circuitInput": {
"in1": "4",
"in2": "10"
}
}
6,757 changes: 6,757 additions & 0 deletions demo/requestProofs.json

Large diffs are not rendered by default.

874 changes: 0 additions & 874 deletions demo/request_generateProof_ProcessMessages.json

This file was deleted.

Loading