Skip to content

Commit

Permalink
Merge pull request #1 from torsion-labs/snarkl-sudoku
Browse files Browse the repository at this point in the history
Change example to match snarkl sudoku example
  • Loading branch information
martyall authored Jan 25, 2024
2 parents d33c42e + 11e3bdc commit a1cae90
Show file tree
Hide file tree
Showing 15 changed files with 289,231 additions and 57 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ jobs:
uses: jaxxstorm/[email protected]
with:
repo: torsion-labs/arkworks-bridge
tag: v0.2.0
tag: v1.0.0-rc2


- name: Run arkworks-bridge
run: |
arkworks-bridge create-trusted-setup --r1cs ./proof-data/prog-r1cs.jsonl --proving-key ./proof-data/prog-pk --verifying-key ./proof-data/prog-vk --ethereum
arkworks-bridge generate-contract --contract ./contracts/Verifier.sol --verifying-key ./proof-data/prog-vk --inputs ./proof-data/prog-inputs.jsonl
arkworks-bridge create-proof --proof ./proof-data/prog-proof --proving-key ./proof-data/prog-pk --r1cs ./proof-data/prog-r1cs.jsonl --witness ./proof-data/prog-witness.jsonl --ethereum
arkworks-bridge create-trusted-setup --r1cs ./proof-data/sudoku-r1cs.jsonl --proving-key ./proof-data/sudoku-pk --verifying-key ./proof-data/sudoku-vk --ethereum
arkworks-bridge generate-contract --contract ./contracts/Verifier.sol --verifying-key ./proof-data/sudoku-vk --inputs ./proof-data/sudoku-assignments.jsonl
arkworks-bridge create-proof --proof ./proof-data/sudoku-proof --proving-key ./proof-data/sudoku-pk --r1cs ./proof-data/sudoku-r1cs.jsonl --witness ./proof-data/sudoku-witness.jsonl --ethereum
- name: setup node
uses: actions/setup-node@v3
Expand Down
11 changes: 6 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ package-lock.json
output
build
.psc-ide-port
.psci_modules
.vscode/

# proof-data generated files
prog-pk
prog-proof
prog-proof-eth.json
prog-vk
prog-vk-eth.json
sudoku-pk
sudoku-proof
sudoku-proof-eth.json
sudoku-vk
sudoku-vk-eth.json
contracts/Verifier.sol
src/Contracts
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
# purescript-zk

This repo contains an example of how to manage zk applications with [purescript-web3](https://github.com/f-o-a-m/purescript-web3) and [arkworks-bridge](https://github.com/torsion-labs/arkworks-bridge). The r1cs, witness, and public variable assignment artifacts correspond to the Snarkl [sudoku tutorial](https://github.com/torsion-labs/snarkl/blob/master/tutorial/sudoku/Sudoku.md).

### Requirements

You will need an [arkworks-bridge](https://github.com/torsion-labs/arkworks-bridge/releases) binary in your path in order to generate the verifying smart contract and proof.
You will need an [arkworks-bridge binary](https://github.com/torsion-labs/arkworks-bridge/releases) in your path in order to generate the verifying smart contract and proof.

We use [cliquebait](https://github.com/f-o-a-m/cliquebait) to run the tests. You can use hardhat or foundry/anvil if that suits your needs.

### Generate CRS and smart contract for R1CS

```
> arkworks-bridge create-trusted-setup --r1cs ./proof-data/prog-r1cs.jsonl --proving-key ./proof-data/prog-pk --verifying-key ./proof-data/prog-vk --ethereum
> arkworks-bridge generate-contract --contract ./contracts/Verifier.sol --verifying-key ./proof-data/prog-vk --inputs ./proof-data/prog-inputs.jsonl
> arkworks-bridge create-trusted-setup --r1cs ./proof-data/sudoku-r1cs.jsonl --proving-key ./proof-data/sudoku-pk --verifying-key ./proof-data/sudoku-vk --ethereum
> arkworks-bridge generate-contract --contract ./contracts/Verifier.sol --verifying-key ./proof-data/sudoku-vk --inputs ./proof-data/sudoku-assignments.jsonl
```

### Quickstart

```
> npm i
> npm run chanterelle-build
> arkworks-bridge create-proof --proof ./proof-data/prog-proof --proving-key ./proof-data/prog-pk --r1cs ./proof-data/prog-r1cs.jsonl --witness ./proof-data/prog-witness.jsonl --ethereum
> arkworks-bridge create-proof --proof ./proof-data/sudoku-proof --proving-key ./proof-data/sudoku-pk --r1cs ./proof-data/sudoku-r1cs.jsonl --witness ./proof-data/sudoku-witness.jsonl --ethereum
> docker run --rm -it -p 8545:8545 -d foamspace/cliquebait:latest
> npm run deploy
> npm run test
```
1 change: 0 additions & 1 deletion proof-data/prog-inputs.jsonl

This file was deleted.

2 changes: 0 additions & 2 deletions proof-data/prog-r1cs.jsonl

This file was deleted.

3 changes: 0 additions & 3 deletions proof-data/prog-witness.jsonl

This file was deleted.

163 changes: 163 additions & 0 deletions proof-data/sudoku-assignments.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{"tag":"public","value":"0","var":1}
{"tag":"public","value":"6","var":2}
{"tag":"public","value":"0","var":3}
{"tag":"public","value":"1","var":4}
{"tag":"public","value":"0","var":5}
{"tag":"public","value":"4","var":6}
{"tag":"public","value":"0","var":7}
{"tag":"public","value":"5","var":8}
{"tag":"public","value":"0","var":9}
{"tag":"public","value":"0","var":10}
{"tag":"public","value":"0","var":11}
{"tag":"public","value":"8","var":12}
{"tag":"public","value":"3","var":13}
{"tag":"public","value":"0","var":14}
{"tag":"public","value":"5","var":15}
{"tag":"public","value":"6","var":16}
{"tag":"public","value":"0","var":17}
{"tag":"public","value":"0","var":18}
{"tag":"public","value":"2","var":19}
{"tag":"public","value":"0","var":20}
{"tag":"public","value":"0","var":21}
{"tag":"public","value":"0","var":22}
{"tag":"public","value":"0","var":23}
{"tag":"public","value":"0","var":24}
{"tag":"public","value":"0","var":25}
{"tag":"public","value":"0","var":26}
{"tag":"public","value":"1","var":27}
{"tag":"public","value":"8","var":28}
{"tag":"public","value":"0","var":29}
{"tag":"public","value":"0","var":30}
{"tag":"public","value":"4","var":31}
{"tag":"public","value":"0","var":32}
{"tag":"public","value":"7","var":33}
{"tag":"public","value":"0","var":34}
{"tag":"public","value":"0","var":35}
{"tag":"public","value":"6","var":36}
{"tag":"public","value":"0","var":37}
{"tag":"public","value":"0","var":38}
{"tag":"public","value":"6","var":39}
{"tag":"public","value":"0","var":40}
{"tag":"public","value":"0","var":41}
{"tag":"public","value":"0","var":42}
{"tag":"public","value":"3","var":43}
{"tag":"public","value":"0","var":44}
{"tag":"public","value":"0","var":45}
{"tag":"public","value":"7","var":46}
{"tag":"public","value":"0","var":47}
{"tag":"public","value":"0","var":48}
{"tag":"public","value":"9","var":49}
{"tag":"public","value":"0","var":50}
{"tag":"public","value":"1","var":51}
{"tag":"public","value":"0","var":52}
{"tag":"public","value":"0","var":53}
{"tag":"public","value":"4","var":54}
{"tag":"public","value":"5","var":55}
{"tag":"public","value":"0","var":56}
{"tag":"public","value":"0","var":57}
{"tag":"public","value":"0","var":58}
{"tag":"public","value":"0","var":59}
{"tag":"public","value":"0","var":60}
{"tag":"public","value":"0","var":61}
{"tag":"public","value":"0","var":62}
{"tag":"public","value":"2","var":63}
{"tag":"public","value":"0","var":64}
{"tag":"public","value":"0","var":65}
{"tag":"public","value":"7","var":66}
{"tag":"public","value":"2","var":67}
{"tag":"public","value":"0","var":68}
{"tag":"public","value":"6","var":69}
{"tag":"public","value":"9","var":70}
{"tag":"public","value":"0","var":71}
{"tag":"public","value":"0","var":72}
{"tag":"public","value":"0","var":73}
{"tag":"public","value":"4","var":74}
{"tag":"public","value":"0","var":75}
{"tag":"public","value":"5","var":76}
{"tag":"public","value":"0","var":77}
{"tag":"public","value":"8","var":78}
{"tag":"public","value":"0","var":79}
{"tag":"public","value":"7","var":80}
{"tag":"public","value":"0","var":81}
{"name":"x_(0,0)","tag":"private","value":"9","var":82}
{"name":"x_(0,1)","tag":"private","value":"6","var":84}
{"name":"x_(0,2)","tag":"private","value":"3","var":86}
{"name":"x_(0,3)","tag":"private","value":"1","var":88}
{"name":"x_(0,4)","tag":"private","value":"7","var":90}
{"name":"x_(0,5)","tag":"private","value":"4","var":92}
{"name":"x_(0,6)","tag":"private","value":"2","var":94}
{"name":"x_(0,7)","tag":"private","value":"5","var":96}
{"name":"x_(0,8)","tag":"private","value":"8","var":98}
{"name":"x_(1,0)","tag":"private","value":"1","var":100}
{"name":"x_(1,1)","tag":"private","value":"7","var":102}
{"name":"x_(1,2)","tag":"private","value":"8","var":104}
{"name":"x_(1,3)","tag":"private","value":"3","var":106}
{"name":"x_(1,4)","tag":"private","value":"2","var":108}
{"name":"x_(1,5)","tag":"private","value":"5","var":110}
{"name":"x_(1,6)","tag":"private","value":"6","var":112}
{"name":"x_(1,7)","tag":"private","value":"4","var":114}
{"name":"x_(1,8)","tag":"private","value":"9","var":116}
{"name":"x_(2,0)","tag":"private","value":"2","var":118}
{"name":"x_(2,1)","tag":"private","value":"5","var":120}
{"name":"x_(2,2)","tag":"private","value":"4","var":122}
{"name":"x_(2,3)","tag":"private","value":"6","var":124}
{"name":"x_(2,4)","tag":"private","value":"8","var":126}
{"name":"x_(2,5)","tag":"private","value":"9","var":128}
{"name":"x_(2,6)","tag":"private","value":"7","var":130}
{"name":"x_(2,7)","tag":"private","value":"3","var":132}
{"name":"x_(2,8)","tag":"private","value":"1","var":134}
{"name":"x_(3,0)","tag":"private","value":"8","var":136}
{"name":"x_(3,1)","tag":"private","value":"2","var":138}
{"name":"x_(3,2)","tag":"private","value":"1","var":140}
{"name":"x_(3,3)","tag":"private","value":"4","var":142}
{"name":"x_(3,4)","tag":"private","value":"3","var":144}
{"name":"x_(3,5)","tag":"private","value":"7","var":146}
{"name":"x_(3,6)","tag":"private","value":"5","var":148}
{"name":"x_(3,7)","tag":"private","value":"9","var":150}
{"name":"x_(3,8)","tag":"private","value":"6","var":152}
{"name":"x_(4,0)","tag":"private","value":"4","var":154}
{"name":"x_(4,1)","tag":"private","value":"9","var":156}
{"name":"x_(4,2)","tag":"private","value":"6","var":158}
{"name":"x_(4,3)","tag":"private","value":"8","var":160}
{"name":"x_(4,4)","tag":"private","value":"5","var":162}
{"name":"x_(4,5)","tag":"private","value":"2","var":164}
{"name":"x_(4,6)","tag":"private","value":"3","var":166}
{"name":"x_(4,7)","tag":"private","value":"1","var":168}
{"name":"x_(4,8)","tag":"private","value":"7","var":170}
{"name":"x_(5,0)","tag":"private","value":"7","var":172}
{"name":"x_(5,1)","tag":"private","value":"3","var":174}
{"name":"x_(5,2)","tag":"private","value":"5","var":176}
{"name":"x_(5,3)","tag":"private","value":"9","var":178}
{"name":"x_(5,4)","tag":"private","value":"6","var":180}
{"name":"x_(5,5)","tag":"private","value":"1","var":182}
{"name":"x_(5,6)","tag":"private","value":"8","var":184}
{"name":"x_(5,7)","tag":"private","value":"2","var":186}
{"name":"x_(5,8)","tag":"private","value":"4","var":188}
{"name":"x_(6,0)","tag":"private","value":"5","var":190}
{"name":"x_(6,1)","tag":"private","value":"8","var":192}
{"name":"x_(6,2)","tag":"private","value":"9","var":194}
{"name":"x_(6,3)","tag":"private","value":"7","var":196}
{"name":"x_(6,4)","tag":"private","value":"1","var":198}
{"name":"x_(6,5)","tag":"private","value":"3","var":200}
{"name":"x_(6,6)","tag":"private","value":"4","var":202}
{"name":"x_(6,7)","tag":"private","value":"6","var":204}
{"name":"x_(6,8)","tag":"private","value":"2","var":206}
{"name":"x_(7,0)","tag":"private","value":"3","var":208}
{"name":"x_(7,1)","tag":"private","value":"1","var":210}
{"name":"x_(7,2)","tag":"private","value":"7","var":212}
{"name":"x_(7,3)","tag":"private","value":"2","var":214}
{"name":"x_(7,4)","tag":"private","value":"4","var":216}
{"name":"x_(7,5)","tag":"private","value":"6","var":218}
{"name":"x_(7,6)","tag":"private","value":"9","var":220}
{"name":"x_(7,7)","tag":"private","value":"8","var":222}
{"name":"x_(7,8)","tag":"private","value":"5","var":224}
{"name":"x_(8,0)","tag":"private","value":"6","var":226}
{"name":"x_(8,1)","tag":"private","value":"4","var":228}
{"name":"x_(8,2)","tag":"private","value":"2","var":230}
{"name":"x_(8,3)","tag":"private","value":"5","var":232}
{"name":"x_(8,4)","tag":"private","value":"9","var":234}
{"name":"x_(8,5)","tag":"private","value":"8","var":236}
{"name":"x_(8,6)","tag":"private","value":"1","var":238}
{"name":"x_(8,7)","tag":"private","value":"7","var":240}
{"name":"x_(8,8)","tag":"private","value":"3","var":242}
{"tag":"output","value":"1","var":1486}
Loading

0 comments on commit a1cae90

Please sign in to comment.