-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c6e3dc
commit c50ac37
Showing
14 changed files
with
3,139 additions
and
4,768 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
inputs | ||
build/ | ||
!scripts/build/ | ||
node_modules/ | ||
err.log | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
source "scripts/build/common.sh" | ||
|
||
# Circuit-specific configurations | ||
CIRCUIT_TYPE="disclose" | ||
OUTPUT_DIR="build/${CIRCUIT_TYPE}" | ||
|
||
# Define circuits and their configurations | ||
# format: name:poweroftau:build_flag | ||
CIRCUITS=( | ||
"vc_and_disclose:20:true" | ||
) | ||
|
||
build_circuits "$CIRCUIT_TYPE" "$OUTPUT_DIR" "${CIRCUITS[@]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
source "scripts/build/common.sh" | ||
|
||
# Circuit-specific configurations | ||
CIRCUIT_TYPE="dsc" | ||
OUTPUT_DIR="build/${CIRCUIT_TYPE}" | ||
|
||
# Define circuits and their configurations | ||
# format: name:poweroftau:build_flag | ||
CIRCUITS=( | ||
"dsc_rsa_sha1_65537_4096:21:true" | ||
"dsc_rsa_sha256_65537_4096:21:true" | ||
"dsc_rsapss_sha256_65537_4096:22:true" | ||
) | ||
|
||
build_circuits "$CIRCUIT_TYPE" "$OUTPUT_DIR" "${CIRCUITS[@]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
|
||
source "scripts/build/common.sh" | ||
|
||
# Circuit-specific configurations | ||
CIRCUIT_TYPE="register" | ||
OUTPUT_DIR="build/${CIRCUIT_TYPE}" | ||
|
||
# Define circuits and their configurations | ||
# format: name:poweroftau:build_flag | ||
CIRCUITS=( | ||
"register_sha1_sha1_sha1_ecdsa_brainpoolP224r1:21:false" | ||
"register_sha1_sha1_sha1_ecdsa_secp256r1:21:false" | ||
"register_sha1_sha1_sha1_rsa_65537_2048:20:false" | ||
"register_sha1_sha256_sha256_rsa_65537_4096:20:false" | ||
"register_sha256_sha224_sha224_ecdsa_brainpoolP224r1:21:false" | ||
"register_sha256_sha256_sha256_ecdsa_brainpoolP224r1:21:false" | ||
"register_sha256_sha256_sha256_ecdsa_brainpoolP256r1:21:false" | ||
"register_sha256_sha256_sha256_ecdsa_secp256r1:21:false" | ||
# Unable to build | ||
"register_sha256_sha256_sha256_ecdsa_secp384r1:22:false" | ||
"register_sha256_sha256_sha256_rsa_3_4096:20:false" | ||
"register_sha256_sha256_sha256_rsa_65537_3072:20:false" | ||
"register_sha256_sha256_sha256_rsa_65537_4096:20:false" | ||
"register_sha256_sha256_sha256_rsapss_3_4096:21:false" | ||
"register_sha256_sha256_sha256_rsapss_65537_4096:21:false" | ||
"register_sha384_sha384_sha384_ecdsa_brainpoolP256r1:22:false" | ||
# Unable to build | ||
"register_sha384_sha384_sha384_ecdsa_brainpoolP384r1:22:false" | ||
# Unable to build | ||
"register_sha384_sha384_sha384_ecdsa_secp384r1:22:false" | ||
"register_sha512_sha512_sha512_ecdsa_brainpoolP256r1:22:false" | ||
# Unable to build | ||
"register_sha512_sha512_sha512_ecdsa_brainpoolP384r1:22:false" | ||
# Unable to build | ||
"register_sha512_sha512_sha512_ecdsa_brainpoolP512r1:23:false" | ||
"register_sha512_sha512_sha512_rsa_65537_4096:21:true" | ||
) | ||
|
||
build_circuits "$CIRCUIT_TYPE" "$OUTPUT_DIR" "${CIRCUITS[@]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
#!/bin/bash | ||
|
||
# Common colors for output | ||
RED='\033[0;31m' | ||
GREEN='\033[0;32m' | ||
YELLOW='\033[0;33m' | ||
BLUE='\033[0;34m' | ||
NC='\033[0m' # No Color | ||
|
||
download_ptau() { | ||
local POWEROFTAU=$1 | ||
mkdir -p build | ||
cd build | ||
if [ ! -f powersOfTau28_hez_final_${POWEROFTAU}.ptau ]; then | ||
echo -e "${YELLOW}Download power of tau....${NC}" | ||
wget https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_${POWEROFTAU}.ptau | ||
echo -e "${GREEN}Finished download!${NC}" | ||
else | ||
echo -e "${YELLOW}Powers of tau file already downloaded${NC}" | ||
fi | ||
cd .. | ||
} | ||
|
||
get_random_string() { | ||
if command -v openssl &> /dev/null; then | ||
echo $(openssl rand -hex 64) | ||
else | ||
echo $(date +%s) | ||
fi | ||
} | ||
|
||
build_circuit() { | ||
local CIRCUIT_NAME=$1 | ||
local CIRCUIT_TYPE=$2 | ||
local POWEROFTAU=$3 | ||
local OUTPUT_DIR=$4 | ||
local START_TIME=$(date +%s) | ||
|
||
echo -e "${BLUE}Compiling circuit: $CIRCUIT_NAME${NC}" | ||
|
||
# Create output directory | ||
mkdir -p ${OUTPUT_DIR}/${CIRCUIT_NAME}/ | ||
|
||
# Set circuit path based on CIRCUIT_TYPE | ||
local CIRCUIT_PATH | ||
if [ "$CIRCUIT_TYPE" = "register" ] || [ "$CIRCUIT_TYPE" = "dsc" ]; then | ||
CIRCUIT_PATH="circuits/${CIRCUIT_TYPE}/instances/${CIRCUIT_NAME}.circom" | ||
else | ||
CIRCUIT_PATH="circuits/${CIRCUIT_TYPE}/${CIRCUIT_NAME}.circom" | ||
fi | ||
|
||
# Compile circuit | ||
circom ${CIRCUIT_PATH} \ | ||
-l node_modules \ | ||
-l ./node_modules/@zk-kit/binary-merkle-root.circom/src \ | ||
-l ./node_modules/circomlib/circuits \ | ||
--r1cs --O1 --wasm -c \ | ||
--output ${OUTPUT_DIR}/${CIRCUIT_NAME}/ | ||
|
||
echo -e "${BLUE}Building zkey${NC}" | ||
NODE_OPTIONS="--max-old-space-size=40960" yarn snarkjs groth16 setup \ | ||
${OUTPUT_DIR}/${CIRCUIT_NAME}/${CIRCUIT_NAME}.r1cs \ | ||
build/powersOfTau28_hez_final_${POWEROFTAU}.ptau \ | ||
${OUTPUT_DIR}/${CIRCUIT_NAME}/${CIRCUIT_NAME}.zkey | ||
|
||
# Generate and contribute random string | ||
local RAND_STR=$(get_random_string) | ||
echo $RAND_STR | yarn snarkjs zkey contribute \ | ||
${OUTPUT_DIR}/${CIRCUIT_NAME}/${CIRCUIT_NAME}.zkey \ | ||
${OUTPUT_DIR}/${CIRCUIT_NAME}/${CIRCUIT_NAME}_final.zkey | ||
|
||
echo -e "${BLUE}Building vkey${NC}" | ||
yarn snarkjs zkey export verificationkey \ | ||
${OUTPUT_DIR}/${CIRCUIT_NAME}/${CIRCUIT_NAME}_final.zkey \ | ||
${OUTPUT_DIR}/${CIRCUIT_NAME}/${CIRCUIT_NAME}_vkey.json | ||
|
||
# Generate and copy Solidity verifier | ||
yarn snarkjs zkey export solidityverifier \ | ||
${OUTPUT_DIR}/${CIRCUIT_NAME}/${CIRCUIT_NAME}_final.zkey \ | ||
${OUTPUT_DIR}/${CIRCUIT_NAME}/Verifier_${CIRCUIT_NAME}.sol | ||
|
||
# linux | ||
sed -i "s/Groth16Verifier/Verifier_${CIRCUIT_NAME}/g" \ | ||
${OUTPUT_DIR}/${CIRCUIT_NAME}/Verifier_${CIRCUIT_NAME}.sol | ||
|
||
# mac OS | ||
# sed -i '' "s/Groth16Verifier/Verifier_${CIRCUIT_NAME}/g" \ | ||
# ${OUTPUT_DIR}/${CIRCUIT_NAME}/Verifier_${CIRCUIT_NAME}.sol | ||
|
||
# Copy verifier to contracts directory | ||
mkdir -p ../contracts/contracts/verifiers/local/${CIRCUIT_TYPE}/ | ||
cp ${OUTPUT_DIR}/${CIRCUIT_NAME}/Verifier_${CIRCUIT_NAME}.sol \ | ||
../contracts/contracts/verifiers/local/${CIRCUIT_TYPE}/Verifier_${CIRCUIT_NAME}.sol | ||
|
||
echo -e "${BLUE}Copied Verifier_${CIRCUIT_NAME}.sol to contracts${NC}" | ||
|
||
# Print build statistics | ||
echo -e "${GREEN}Build of $CIRCUIT_NAME completed in $(($(date +%s) - START_TIME)) seconds${NC}" | ||
echo -e "${BLUE}Size of ${CIRCUIT_NAME}.r1cs: $(wc -c < ${OUTPUT_DIR}/${CIRCUIT_NAME}/${CIRCUIT_NAME}.r1cs) bytes${NC}" | ||
echo -e "${BLUE}Size of ${CIRCUIT_NAME}.wasm: $(wc -c < ${OUTPUT_DIR}/${CIRCUIT_NAME}/${CIRCUIT_NAME}_js/${CIRCUIT_NAME}.wasm) bytes${NC}" | ||
echo -e "${BLUE}Size of ${CIRCUIT_NAME}_final.zkey: $(wc -c < ${OUTPUT_DIR}/${CIRCUIT_NAME}/${CIRCUIT_NAME}_final.zkey) bytes${NC}" | ||
} | ||
|
||
build_circuits() { | ||
local CIRCUITS=("$@") | ||
local CIRCUIT_TYPE="$1" | ||
local OUTPUT_DIR="$2" | ||
shift 2 | ||
local TOTAL_START_TIME=$(date +%s) | ||
|
||
# Build circuits | ||
for circuit in "${CIRCUITS[@]}"; do | ||
IFS=':' read -r CIRCUIT_NAME POWEROFTAU BUILD_FLAG <<< "$circuit" | ||
if [ "$BUILD_FLAG" = "true" ]; then | ||
# Download ptau file | ||
IFS=':' read -r _ POWEROFTAU _ <<< "$circuit" | ||
download_ptau $POWEROFTAU | ||
# Build circuit | ||
echo -e "${BLUE}Building circuit $CIRCUIT_NAME${NC}" | ||
build_circuit "$CIRCUIT_NAME" "$CIRCUIT_TYPE" "$POWEROFTAU" "$OUTPUT_DIR" | ||
else | ||
echo -e "${GRAY}Skipping build for $CIRCUIT_NAME${NC}" | ||
fi | ||
done | ||
|
||
echo -e "${GREEN}Total completed in $(($(date +%s) - TOTAL_START_TIME)) seconds${NC}" | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.