ci: build all circuits and run test

This commit is contained in:
mhchia
2023-04-01 21:46:01 -06:00
parent d3a01079a4
commit 5dc4ff5295
4 changed files with 62 additions and 15 deletions

35
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,35 @@
# This workflow test if circuits can be built and the tests pass.
name: Test
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- name: Cache circom
id: cache-circom
uses: actions/cache@v3
with:
path: ~/.cargo/bin/circom
# Since the version of circom is specified in `scripts/install-circom.sh`,
# as long as the file doesn't change we can reuse the circom binary.
key: ${{ runner.os }}-circom-${{ hashFiles('./scripts/install-circom.sh') }}
- name: Install circom if not cached
run: ./scripts/install-circom.sh
- run: npm ci
- name: Build all circuits
run: npm run build
- name: Run the tests
run: npm test

View File

@@ -1,6 +1,6 @@
{
"scripts": {
"build": "bash scripts/build-circuits.sh",
"build": "bash scripts/build-circuits.sh same && bash scripts/build-circuits.sh diff && bash scripts/build-circuits.sh withdraw",
"test": "ts-mocha --exit test/**/*.test.ts"
},
"dependencies": {

View File

@@ -17,25 +17,26 @@ else
wget https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_14.ptau
fi
circuit_dir="../circuits"
circuit_path=""
circuit_type=""
zkeypath=""
zkeydir="../zkeyFiles"
if [ "$1" = "diff" ]; then
echo -e "\033[32mUsing Diff circuit\033[0m"
circuit_type="diff"
circuit_path="../circuits/rln-diff.circom"
zkeypath="../zkeyFiles/rln-v2-diff"
circuit_name="rln-diff"
elif [ "$1" = "same" ]; then
echo -e "\033[32mUsing Same circuit\033[0m"
circuit_type="same"
circuit_path="../circuits/rln-same.circom"
zkeypath="../zkeyFiles/rln-v2-same"
circuit_name="rln-same"
elif [ "$1" = "withdraw" ]; then
echo -e "\033[32mUsing Withdraw circuit\033[0m"
circuit_name="withdraw"
else
circuit_type="same"
circuit_path="../circuits/rln-same.circom"
zkeypath="../zkeyFiles/rln-v2-same"
echo -e "\033[33mUnrecognized argument, using 'same' as default.\033[0m"
circuit_name="rln-same"
fi
circuit_path="$circuit_dir/$circuit_name.circom"
zkeypath="$zkeydir/v2/$circuit_name"
if ! [ -x "$(command -v circom)" ]; then
echo -e '\033[31mError: circom is not installed.\033[0m' >&2
@@ -53,11 +54,11 @@ echo -e "\033[36mBuild Path: $PWD\033[0m"
circom --version
circom $circuit_path --r1cs --wasm --sym
snarkjs r1cs export json rln-same.r1cs rln-same.r1cs.json
snarkjs r1cs export json $circuit_name.r1cs $circuit_name.r1cs.json
echo -e "\033[36mRunning groth16 trusted setup\033[0m"
snarkjs groth16 setup rln-same.r1cs powersOfTau28_hez_final_14.ptau setup/rln_0000.zkey
snarkjs groth16 setup $circuit_name.r1cs powersOfTau28_hez_final_14.ptau setup/rln_0000.zkey
snarkjs zkey contribute setup/rln_0000.zkey setup/rln_0001.zkey --name="First contribution" -v -e="Random entropy"
snarkjs zkey contribute setup/rln_0001.zkey setup/rln_0002.zkey --name="Second contribution" -v -e="Another random entropy"
@@ -69,7 +70,7 @@ mkdir -p $zkeypath
snarkjs zkey export verificationkey setup/rln_final.zkey $zkeypath/verification_key.json
snarkjs zkey export solidityverifier setup/rln_final.zkey contracts/verifier.sol
cp rln-$circuit_type\_js/rln-$circuit_type.wasm $zkeypath/rln.wasm
cp $circuit_name\_js/$circuit_name.wasm $zkeypath/rln.wasm
cp setup/rln_final.zkey $zkeypath/rln_final.zkey
shasumcmd="shasum -a 256"
@@ -77,7 +78,7 @@ shasumcmd="shasum -a 256"
config_path="$zkeypath/circuit.config.toml"
echo -e "[Circuit_Version]" > $config_path
echo -e "RLN_Version = 2" >> $config_path
echo -e "RLN_Type = \"$circuit_type\"" >> $config_path
echo -e "RLN_Type = \"$circuit_name\"" >> $config_path
echo -e "" >> $config_path

11
scripts/install-circom.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
circom_version=v2.1.5
if ! [ -x "$(command -v circom)" ]; then
git clone https://github.com/iden3/circom.git
cd circom
git checkout $circom_version
cargo build --release
cargo install --path circom
fi