Skip to content

Commit

Permalink
rename utxo to compressed account in readme bench.sh generate_keys.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
ananas-block committed Jun 22, 2024
1 parent 8802aae commit d014cde
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
8 changes: 4 additions & 4 deletions light-prover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ through [gnark](https://github.com/ConsenSys/gnark)).

This part explains the existing cli commands.

1. setup - builds a circuit with provided number of utxos and depth, compiles it and writes it to a file.
1. setup - builds a circuit with provided number of compressed accounts and depth, compiles it and writes it to a file.
Flags:
1. output *file path* - A path used to output a file
2. tree-depth *n* - Merkle tree depth
3. utxos *n* - Number of UTXOs
2. gen-test-params - Generates test params given the number of utxos and tree depth.
3. compressedAccounts *n* - Number of COMPRESSED_ACCOUNTs
2. gen-test-params - Generates test params given the number of compressedAccounts and tree depth.
Flags:
1. tree-depth *n* - Depth of the mock merkle tree
2. utxos *n* - Number of UTXOs
2. compressedAccounts *n* - Number of COMPRESSED_ACCOUNTs
3. start - starts a api server with /prove and /metrics endpoints
Flags:
1. config: Config file, which may contain the following fields:
Expand Down
34 changes: 17 additions & 17 deletions light-prover/bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@ gnark() {
}

generate_and_test() {
local utxos=$1
local compressedAccounts=$1
mkdir -p circuits
CIRCUIT_FILE="/tmp/circuit_${DEPTH}_${utxos}.key"
TEST_FILE="/tmp/inputs_${DEPTH}_${utxos}.json"
CIRCUIT_FILE="/tmp/circuit_${DEPTH}_${compressedAccounts}.key"
TEST_FILE="/tmp/inputs_${DEPTH}_${compressedAccounts}.json"
if [ ! -f "${CIRCUIT_FILE}" ]; then
echo "Prover setup..."
gnark setup --circuit inclusion --utxos "$utxos" --tree-depth "$DEPTH" --output "${CIRCUIT_FILE}"
gnark setup --circuit inclusion --compressedAccounts "$compressedAccounts" --tree-depth "$DEPTH" --output "${CIRCUIT_FILE}"
fi
if [ ! -f "${TEST_FILE}" ]; then
echo "Generating test inputs..."
gnark gen-test-params --utxos "$utxos" --tree-depth "$DEPTH" > "${TEST_FILE}"
gnark gen-test-params --compressedAccounts "$compressedAccounts" --tree-depth "$DEPTH" > "${TEST_FILE}"
fi
}

run_benchmark() {
local utxos=$1
echo "Benchmarking with $utxos utxos..."
TEST_FILE="/tmp/inputs_${DEPTH}_${utxos}.json"
local compressedAccounts=$1
echo "Benchmarking with $compressedAccounts compressedAccounts..."
TEST_FILE="/tmp/inputs_${DEPTH}_${compressedAccounts}.json"
curl -s -S -X POST -d @"${TEST_FILE}" "$URL" -o /dev/null
sleep 1
}

start_server() {
utxos_arr=$1
for utxos in "${utxos_arr[@]}"
compressedAccounts_arr=$1
for compressedAccounts in "${compressedAccounts_arr[@]}"
do
keys_file+="--keys-file /tmp/circuit_${DEPTH}_${utxos}.key "
keys_file+="--keys-file /tmp/circuit_${DEPTH}_${compressedAccounts}.key "
done
echo "Starting server with keys: $keys_file"
gnark start \
Expand All @@ -47,24 +47,24 @@ start_server() {
}

# Define an array containing the desired values
declare -a utxos_arr=("1" "2" "3" "4" "8")
declare -a compressedAccounts_arr=("1" "2" "3" "4" "8")

# Kill the server
killall light-prover

# Generate keys and test inputs
for utxos in "${utxos_arr[@]}"
for compressedAccounts in "${compressedAccounts_arr[@]}"
do
generate_and_test $utxos
generate_and_test $compressedAccounts
done

# Start the server
start_server "${utxos_arr[@]}"
start_server "${compressedAccounts_arr[@]}"

# Run the benchmarks
for utxos in "${utxos_arr[@]}"
for compressedAccounts in "${compressedAccounts_arr[@]}"
do
run_benchmark $utxos
run_benchmark $compressedAccounts
done
echo "Done. Benchmarking results are in log.txt."

Expand Down
46 changes: 23 additions & 23 deletions light-prover/scripts/generate_keys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,60 @@ gnark() {
}

generate() {
local INCLUSION_UTXOS=$1
local NON_INCLUSION_UTXOS=$2
local INCLUSION_COMPRESSED_ACCOUNTS=$1
local NON_INCLUSION_COMPRESSED_ACCOUNTS=$2
local CIRCUIT_TYPE=$3
mkdir -p circuits
if [ "$CIRCUIT_TYPE" == "inclusion" ]; then
UTXOS=$INCLUSION_UTXOS
COMPRESSED_ACCOUNTS=$INCLUSION_COMPRESSED_ACCOUNTS
CIRCUIT_TYPE_RS="inclusion"
elif [ "$CIRCUIT_TYPE" == "non-inclusion" ]; then
UTXOS=$NON_INCLUSION_UTXOS
COMPRESSED_ACCOUNTS=$NON_INCLUSION_COMPRESSED_ACCOUNTS
# rust file names cannot include dashes
CIRCUIT_TYPE_RS="non_inclusion"
else
UTXOS="${INCLUSION_UTXOS}_${NON_INCLUSION_UTXOS}"
COMPRESSED_ACCOUNTS="${INCLUSION_COMPRESSED_ACCOUNTS}_${NON_INCLUSION_COMPRESSED_ACCOUNTS}"
CIRCUIT_TYPE_RS="combined"
fi
CIRCUIT_FILE="./proving-keys/${CIRCUIT_TYPE}_${DEPTH}_${UTXOS}.key"
CIRCUIT_VKEY_FILE="./proving-keys/${CIRCUIT_TYPE}_${DEPTH}_${UTXOS}.vkey"
CIRCUIT_VKEY_RS_FILE="../circuit-lib/verifier/src/verifying_keys/${CIRCUIT_TYPE_RS}_${DEPTH}_${UTXOS}.rs"
CIRCUIT_FILE="./proving-keys/${CIRCUIT_TYPE}_${DEPTH}_${COMPRESSED_ACCOUNTS}.key"
CIRCUIT_VKEY_FILE="./proving-keys/${CIRCUIT_TYPE}_${DEPTH}_${COMPRESSED_ACCOUNTS}.vkey"
CIRCUIT_VKEY_RS_FILE="../circuit-lib/verifier/src/verifying_keys/${CIRCUIT_TYPE_RS}_${DEPTH}_${COMPRESSED_ACCOUNTS}.rs"

echo "Generating ${CIRCUIT_TYPE} circuit for ${UTXOS} UTXOs..."
echo "go run . setup --circuit ${CIRCUIT_TYPE} --inclusion-utxos ${INCLUSION_UTXOS} --non-inclusion-utxos ${NON_INCLUSION_UTXOS} --inclusion-tree-depth ${DEPTH} --non-inclusion-tree-depth ${DEPTH} --output ${CIRCUIT_FILE} --output-vkey ${CIRCUIT_VKEY_FILE}"
echo "Generating ${CIRCUIT_TYPE} circuit for ${COMPRESSED_ACCOUNTS} COMPRESSED_ACCOUNTs..."
echo "go run . setup --circuit ${CIRCUIT_TYPE} --inclusion-compressedAccounts ${INCLUSION_COMPRESSED_ACCOUNTS} --non-inclusion-compressedAccounts ${NON_INCLUSION_COMPRESSED_ACCOUNTS} --inclusion-tree-depth ${DEPTH} --non-inclusion-tree-depth ${DEPTH} --output ${CIRCUIT_FILE} --output-vkey ${CIRCUIT_VKEY_FILE}"

gnark setup \
--circuit "${CIRCUIT_TYPE}" \
--inclusion-utxos "$INCLUSION_UTXOS" \
--non-inclusion-utxos "$NON_INCLUSION_UTXOS" \
--inclusion-compressedAccounts "$INCLUSION_COMPRESSED_ACCOUNTS" \
--non-inclusion-compressedAccounts "$NON_INCLUSION_COMPRESSED_ACCOUNTS" \
--inclusion-tree-depth "$DEPTH" \
--non-inclusion-tree-depth "$DEPTH" \
--output "${CIRCUIT_FILE}" \
--output-vkey "${CIRCUIT_VKEY_FILE}"
cargo xtask generate-vkey-rs --input-path "${CIRCUIT_VKEY_FILE}" --output-path "${CIRCUIT_VKEY_RS_FILE}"
}

declare -a inclusion_utxos_arr=("1" "2" "3" "4" "8")
declare -a inclusion_compressedAccounts_arr=("1" "2" "3" "4" "8")

for utxos in "${inclusion_utxos_arr[@]}"
for compressedAccounts in "${inclusion_compressedAccounts_arr[@]}"
do
generate "$utxos" "0" "inclusion"
generate "$compressedAccounts" "0" "inclusion"
done

declare -a non_inclusion_utxos_arr=("1" "2")
declare -a non_inclusion_compressedAccounts_arr=("1" "2")

for utxos in "${non_inclusion_utxos_arr[@]}"
for compressedAccounts in "${non_inclusion_compressedAccounts_arr[@]}"
do
generate "0" "$utxos" "non-inclusion"
generate "0" "$compressedAccounts" "non-inclusion"
done

declare -a combined_inclusion_utxos_arr=("1" "2" "3" "4")
declare -a combined_non_inclusion_utxos_arr=("1" "2")
declare -a combined_inclusion_compressedAccounts_arr=("1" "2" "3" "4")
declare -a combined_non_inclusion_compressedAccounts_arr=("1" "2")

for i_utxos in "${combined_inclusion_utxos_arr[@]}"
for i_compressedAccounts in "${combined_inclusion_compressedAccounts_arr[@]}"
do
for ni_utxos in "${combined_non_inclusion_utxos_arr[@]}"
for ni_compressedAccounts in "${combined_non_inclusion_compressedAccounts_arr[@]}"
do
generate "$i_utxos" "$ni_utxos" "combined"
generate "$i_compressedAccounts" "$ni_compressedAccounts" "combined"
done
done

0 comments on commit d014cde

Please sign in to comment.