From c03b43221d68e34bd5015a4e4ee1a0ad3299f8ef Mon Sep 17 00:00:00 2001 From: Balazs Komuves Date: Mon, 18 Dec 2023 14:31:13 +0100 Subject: [PATCH] solve the nodejs heap allocation issue (appears around 100 samples) --- workflow/README.md | 28 ++++++++++++++++++++++++++++ workflow/params.sh | 2 +- workflow/setup.sh | 10 +++++++--- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/workflow/README.md b/workflow/README.md index 331a6c9..179e920 100644 --- a/workflow/README.md +++ b/workflow/README.md @@ -14,6 +14,29 @@ To run the full workflow: NOTE: the examples below assume `bash`. In particular, it won't work with `zsh` (which is the dafault on newer macOS)! Because, you know, reasons... +### Some measurements + +Approximate time to run this on an M2 (8+4 cores), with 10 samples: + +- compiling the circuit: 8 seconds +- circuit-specific setup (with 1 contributor): 85 seconds +- size of the `.zkey` file (only 1 contributor): 110 megabytes +- proving with `snarkjs` (slow): 7.7 seconds + +Same with 50 samples: + +- compiling: 37 seconds +- circuit-specific setup: ~420 seconds +- `.zkey` file: 525 megabytes +- snarkjs prove: 34 seconds + +And with 100 samples: +- compiling: 76 seconds +- circuit-specific setup: ~1000 seconds +- `.zkey` file +- snarkjs prove: 76 seconds + + ### Preliminaries - install `circom`, `snarkjs`, `rapidsnark`: @@ -71,6 +94,11 @@ the whole process. $ snarkjs groth16 setup proof_main.r1cs ../../ceremony/powersOfTau28_hez_final_21.ptau proof_main_0000.zkey $ snarkjs zkey contribute proof_main_0000.zkey proof_main_0001.zkey --name="1st Contributor Name" +NOTE: with large circuits, javascript can run out of heap. You can increase the +heap limit with: + + $ NODE_OPTIONS="--max-old-space-size=8192" snarkjs groth16 setup <...> + You can add more contributors here if you want. Finally rename the last contributions result and export the verification key: diff --git a/workflow/params.sh b/workflow/params.sh index 5b67f6d..94ac2c4 100644 --- a/workflow/params.sh +++ b/workflow/params.sh @@ -1,6 +1,6 @@ #!/bin/bash -MAXDEPTH=16 # maximum depth of the slot tree +MAXDEPTH=32 # maximum depth of the slot tree MAXSLOTS=256 # maximum number of slots CELLSIZE=2048 # cell size in bytes BLOCKSIZE=65536 # block size in bytes diff --git a/workflow/setup.sh b/workflow/setup.sh index e38fc6e..52381f1 100755 --- a/workflow/setup.sh +++ b/workflow/setup.sh @@ -14,19 +14,23 @@ ${NIMCLI_DIR}/cli $CLI_ARGS -v --circom=${CIRCUIT_MAIN}.circom # --- compile the circuit --- -circom --r1cs --wasm --O2 -l${CIRCUIT_DIR} ${CIRCUIT_MAIN}.circom +time circom --r1cs --wasm --O2 -l${CIRCUIT_DIR} ${CIRCUIT_MAIN}.circom # --- circuit specific setup --- -snarkjs groth16 setup ${CIRCUIT_MAIN}.r1cs $PTAU_PATH ${CIRCUIT_MAIN}_0000.zkey +start=`date +%s` +NODE_OPTIONS="--max-old-space-size=8192" snarkjs groth16 setup ${CIRCUIT_MAIN}.r1cs $PTAU_PATH ${CIRCUIT_MAIN}_0000.zkey echo "some_entropy_75289v3b7rcawcsyiur" | \ -snarkjs zkey contribute ${CIRCUIT_MAIN}_0000.zkey ${CIRCUIT_MAIN}_0001.zkey --name="1st Contributor Name" +NODE_OPTIONS="--max-old-space-size=8192" snarkjs zkey contribute ${CIRCUIT_MAIN}_0000.zkey ${CIRCUIT_MAIN}_0001.zkey --name="1st Contributor Name" rm ${CIRCUIT_MAIN}_0000.zkey mv ${CIRCUIT_MAIN}_0001.zkey ${CIRCUIT_MAIN}.zkey snarkjs zkey export verificationkey ${CIRCUIT_MAIN}.zkey ${CIRCUIT_MAIN}_verification_key.json +end=`date +%s` +echo "The circuit specific setup took `expr $end - $start` seconds." + # --- finish the setup --- cd $ORIG \ No newline at end of file