-
Notifications
You must be signed in to change notification settings - Fork 1
161 lines (137 loc) · 5.72 KB
/
generate.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: Generates circuit assets
on:
workflow_dispatch:
inputs:
maxDepth:
description: 'Maximum depth of the slot tree'
default: '32'
maxSlots:
description: 'Maximum number of slots'
default: '256'
cellSize:
description: 'Cell size in bytes'
default: '2048'
blockSize:
description: 'Block size in bytes'
default: '65536'
nSamples:
description: 'Number of samples to prove'
default: '5'
seed:
description: 'Seed for creating fake data'
default: '12345'
nSlots:
description: 'Number of slots in the dataset'
default: '11'
slotIndex:
description: 'Which slot we prove (0..NSLOTS-1)'
default: '3'
nCells:
description: 'Number of cells in this slot'
default: '512'
ceremonyContribution:
description: 'Input into the circuit ceremony setup'
default: 'Let the Codex rock!'
env:
nim_version: 1.6.14
nodejs_version: 18.15
ceremony_source: https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_21.ptau
s3_bucket_path: proving-key
circuit_file: workflow/build/proof_main.zkey
constraints_file: workflow/build/proof_main.r1cs
wasm_file: workflow/build/proof_main_js/proof_main.wasm
verification_key_file: workflow/build/proof_main_verification_key.json
zip_file: workflow/build/proof_circuit.zip
storage_url: https://circuit.codex.storage
jobs:
build:
defaults:
run:
shell: bash --noprofile --norc -e -o pipefail {0}
runs-on: buildjet-16vcpu-ubuntu-2204
# runs-on: ubuntu-latest
timeout-minutes: 360
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Setup Circom
uses: baptiste0928/cargo-install@v2
with:
cache-key: 'invalid-cache-please'
crate: circom
git: https://github.com/iden3/circom.git
- name: Setup Nim
uses: jiro4989/setup-nim-action@v1
with:
nim-version: ${{ env.nim_version }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.nodejs_version }}
- name: Install SnarkJS
run: npm install -g snarkjs
- name: Setup CLI arguments
run: |
ENTROPY="${{ github.run_id }}"
echo "Entropy: $ENTROPY"
echo "CLI_ARGS=--depth=${{ github.event.inputs.maxDepth }} --maxslots=${{ github.event.inputs.maxSlots }} --cellsize=${{ github.event.inputs.cellSize }} --blocksize=${{ github.event.inputs.blockSize }} --nsamples=${{ github.event.inputs.nSamples }} --entropy="$ENTROPY" --seed=${{ github.event.inputs.seed }} --nslots=${{ github.event.inputs.nSlots }} --index=${{ github.event.inputs.slotIndex }} --ncells=${{ github.event.inputs.nCells }}" >> $GITHUB_ENV
- name: Build CLI Proof Generator
run: |
cd reference/nim/proof_input/
nimble -y build -d:release cli
cd ../../../
- name: Compile the circuit
run: |
mkdir -p workflow/build
cd workflow/build
../../reference/nim/proof_input/cli $CLI_ARGS -v --circom="proof_main.circom"
circom --r1cs --wasm --O2 -l../../circuit/lib -l../../circuit/poseidon2 -l../../circuit/codex proof_main.circom
- name: Circuit setup
run: |
cd workflow
wget -q -O ceremony.ptau ${{ env.ceremony_source }}
cd build
NODE_OPTIONS="--max-old-space-size=8192" snarkjs groth16 setup proof_main.r1cs ../ceremony.ptau proof_main_0000.zkey
NODE_OPTIONS="--max-old-space-size=8192" snarkjs zkey contribute proof_main_0000.zkey proof_main_0001.zkey --name="External Contribution" -e="${{ github.event.inputs.ceremonyContribution }}"
rm proof_main_0000.zkey
mv proof_main_0001.zkey proof_main.zkey
snarkjs zkey export verificationkey proof_main.zkey proof_main_verification_key.json
snarkjs zkey export solidityverifier proof_main.zkey verifier.sol
cd ..
- name: Generate proof
run: |
cd workflow/build/
../../reference/nim/proof_input/cli $CLI_ARGS -v --output=input.json
cd proof_main_js
node generate_witness.js proof_main.wasm ../input.json ../witness.wtns
cd ..
snarkjs groth16 prove proof_main.zkey witness.wtns proof.json public.json
- name: Upload to storage
env:
s3_endpoint: ${{ secrets.S3_ENDPOINT }}
s3_bucket: ${{ secrets.S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
run: |
# Zip
zip -qj ${{ env.zip_file }} ${{ env.circuit_file }} ${{ env.constraints_file }} ${{ env.wasm_file }} ${{ env.verification_key_file }}
# Variables
hash=($(shasum -a 256 ${{ env.zip_file }}))
[[ -z "${{ env.s3_bucket_path}}" ]] && storage_file="${hash}" || storage_file="${{ env.s3_bucket_path}}/${hash}"
echo "storage_file=${storage_file}" >>$GITHUB_ENV
# Upload
aws s3 cp ${{ env.zip_file }} s3://${{ env.s3_bucket }}/${storage_file} --endpoint-url ${{ env.s3_endpoint }}
# Add hash to the assets
echo "\"${hash}\"" > workflow/build/zkey_hash.json
- name: Show download URL
run: |
echo "Download URL: ${{ env.download_url }}"
env:
download_url: ${{ format('{0}/{1}', env.storage_url, env.storage_file) }}
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: circuit-assets
path: workflow/build
retention-days: 5