Skip to content

Commit

Permalink
Merge pull request #9 from Rate-Limiting-Nullifier/test/remove-rln-same
Browse files Browse the repository at this point in the history
Remove rln-same from tests and build scripts
  • Loading branch information
curryrasul authored May 25, 2023
2 parents b40dfa6 + ab54159 commit f88924f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 118 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"build": "bash scripts/build-circuits.sh same && bash scripts/build-circuits.sh diff && bash scripts/build-circuits.sh withdraw",
"build": "./scripts/build-circuits.sh rln && ./scripts/build-circuits.sh withdraw",
"test": "ts-mocha --exit test/**/*.test.ts"
},
"dependencies": {
Expand Down
41 changes: 19 additions & 22 deletions scripts/build-circuits.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,18 @@ circuit_path=""
circuit_type=""
zkeydir="../zkeyFiles"

if [ "$1" = "diff" ]; then
echo -e "\033[32mUsing Diff circuit\033[0m"
circuit_name="rln-diff"
elif [ "$1" = "same" ]; then
echo -e "\033[32mUsing Same circuit\033[0m"
circuit_name="rln-same"
if [ "$1" = "rln" ]; then
echo -e "\033[32mUsing RLN circuit\033[0m"
circuit_name="rln"
elif [ "$1" = "withdraw" ]; then
echo -e "\033[32mUsing Withdraw circuit\033[0m"
circuit_name="withdraw"
else
echo -e "\033[33mUnrecognized argument, using 'same' as default.\033[0m"
circuit_name="rln-same"
echo -e "\033[33mUnrecognized argument"
exit 1
fi
circuit_path="$circuit_dir/$circuit_name.circom"
zkeypath="$zkeydir/v2/$circuit_name"
zkeypath="$zkeydir/$circuit_name"

if ! [ -x "$(command -v circom)" ]; then
echo -e '\033[31mError: circom is not installed.\033[0m' >&2
Expand All @@ -54,24 +51,24 @@ echo -e "\033[36mBuild Path: $PWD\033[0m"
circom --version
circom $circuit_path --r1cs --wasm --sym

snarkjs r1cs export json $circuit_name.r1cs $circuit_name.r1cs.json
npx snarkjs r1cs export json $circuit_name.r1cs $circuit_name.r1cs.json

echo -e "\033[36mRunning groth16 trusted setup\033[0m"

snarkjs groth16 setup $circuit_name.r1cs powersOfTau28_hez_final_14.ptau setup/rln_0000.zkey
npx snarkjs groth16 setup $circuit_name.r1cs powersOfTau28_hez_final_14.ptau setup/circuit_00000.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"
snarkjs zkey beacon setup/rln_0002.zkey setup/rln_final.zkey 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 10 -n="Final Beacon phase2"
npx snarkjs zkey contribute setup/circuit_00000.zkey setup/circuit_00001.zkey --name="First contribution" -v -e="Random entropy"
npx snarkjs zkey contribute setup/circuit_00001.zkey setup/circuit_00002.zkey --name="Second contribution" -v -e="Another random entropy"
npx snarkjs zkey beacon setup/circuit_00002.zkey setup/final.zkey 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f 10 -n="Final Beacon phase2"

echo -e "Exporting artifacts to zkeyFiles and contracts directory"

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
npx snarkjs zkey export verificationkey setup/final.zkey $zkeypath/verification_key.json
npx snarkjs zkey export solidityverifier setup/final.zkey contracts/verifier.sol

cp $circuit_name\_js/$circuit_name.wasm $zkeypath/rln.wasm
cp setup/rln_final.zkey $zkeypath/rln_final.zkey
cp $circuit_name\_js/$circuit_name.wasm $zkeypath/circuit.wasm
cp setup/final.zkey $zkeypath/final.zkey

shasumcmd="shasum -a 256"

Expand All @@ -90,11 +87,11 @@ echo -e "Compilation_Time = $(date +%s)" >> $config_path

echo -e "" >> $config_path
echo -e "[Files]" >> $config_path
echo -e "Wasm = \"rln.wasm\"" >> $config_path
wasm_sha256=$($shasumcmd $zkeypath/rln.wasm | awk '{print $1}')
echo -e "Wasm = \"circuit.wasm\"" >> $config_path
wasm_sha256=$($shasumcmd $zkeypath/circuit.wasm | awk '{print $1}')
echo -e "Wasm_SHA256SUM = \"$wasm_sha256\"" >> $config_path
echo -e "Zkey = \"rln_final.zkey\"" >> $config_path
zkey_sha256=$($shasumcmd $zkeypath/rln_final.zkey | awk '{print $1}')
echo -e "Zkey = \"final.zkey\"" >> $config_path
zkey_sha256=$($shasumcmd $zkeypath/final.zkey | awk '{print $1}')
echo -e "Zkey_SHA256SUM = \"$zkey_sha256\"" >> $config_path
echo -e "Verification_Key = \"verification_key.json\"" >> $config_path
vkey_sha256=$($shasumcmd $zkeypath/verification_key.json | awk '{print $1}')
Expand Down
2 changes: 0 additions & 2 deletions test/configs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as path from "path";

// MERKLE TREE
export const MERKLE_TREE_DEPTH = 20;
export const MERKLE_TREE_ZERO_VALUE = BigInt(0);
91 changes: 0 additions & 91 deletions test/rln-same.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions test/rln-diff.test.ts → test/rln.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import poseidon from "poseidon-lite";
import { calculateOutput, genFieldElement, genMerkleProof, getSignal } from "./utils"


const circuitPath = path.join(__dirname, "..", "circuits", "rln-diff.circom");
const circuitPath = path.join(__dirname, "..", "circuits", "rln.circom");

// ffjavascript has no types so leave circuit with untyped
type CircuitT = any;
Expand All @@ -18,7 +18,7 @@ function calculateLeaf(identitySecret: bigint, userMessageLimit: bigint) {
}


describe("Test rln-diff.circom", function () {
describe("Test rln.circom", function () {
let circuit: CircuitT;

this.timeout(30000);
Expand Down

0 comments on commit f88924f

Please sign in to comment.