From 5ed7177fa17d3c8538e6dc512fd04ecb188973ab Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Tue, 21 May 2024 14:43:00 +0000 Subject: [PATCH 01/11] chore: add bench programs --- barretenberg/acir_tests/bench_acir_tests.sh | 8 +- noir/Earthfile | 10 +- .../benchmarks/bench_poseidon_hash/Nargo.toml | 7 ++ .../bench_poseidon_hash/Prover.toml | 1 + .../bench_poseidon_hash/src/main.nr | 5 + .../bench_poseidon_hash_100/Nargo.toml | 7 ++ .../bench_poseidon_hash_100/Prover.toml | 102 ++++++++++++++++++ .../bench_poseidon_hash_100/src/main.nr | 10 ++ .../bench_poseidon_hash_30/Nargo.toml | 7 ++ .../bench_poseidon_hash_30/Prover.toml | 32 ++++++ .../bench_poseidon_hash_30/src/main.nr | 10 ++ noir/noir-repo/test_programs/rebuild.sh | 7 ++ 12 files changed, 200 insertions(+), 6 deletions(-) create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash/Nargo.toml create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash/Prover.toml create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash/src/main.nr create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/Nargo.toml create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/Prover.toml create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/Nargo.toml create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/Prover.toml create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/src/main.nr diff --git a/barretenberg/acir_tests/bench_acir_tests.sh b/barretenberg/acir_tests/bench_acir_tests.sh index 8cdc19a7c8f2..e73fea9be656 100755 --- a/barretenberg/acir_tests/bench_acir_tests.sh +++ b/barretenberg/acir_tests/bench_acir_tests.sh @@ -11,7 +11,7 @@ if [[ -z "${LOG_FILE}" ]]; then fi if [ "${#TEST_NAMES[@]}" -eq 0 ]; then - TEST_NAMES=(sha256 ecdsa_secp256k1 ecdsa_secp256r1 schnorr double_verify_proof) + TEST_NAMES=(bench_poseidon_hash bench_poseidon_hash_30 bench_poseidon_hash_100) fi for TEST in ${TEST_NAMES[@]}; do @@ -23,13 +23,13 @@ done # Build results into string with \n delimited rows and space delimited values. TABLE_DATA="" for TEST in ${TEST_NAMES[@]}; do - GATE_COUNT=$(jq -r --arg test "$TEST" 'select(.name == "gate_count" and .acir_test == $test) | .value' $BENCHMARKS | uniq) - SUBGROUP_SIZE=$(jq -r --arg test "$TEST" 'select(.name == "subgroup_size" and .acir_test == $test) | .value' $BENCHMARKS | uniq) + GATE_COUNT=$(jq -r --arg test "$TEST" 'select(.eventName == "gate_count" and .acir_test == $test) | .value' $BENCHMARKS | uniq) + SUBGROUP_SIZE=$(jq -r --arg test "$TEST" 'select(.eventName == "subgroup_size" and .acir_test == $test) | .value' $BENCHMARKS | uniq) # Name in col 1, gate count in col 2, subgroup size in col 3. TABLE_DATA+="$TEST $GATE_COUNT $SUBGROUP_SIZE" # Each thread timing in subsequent cols. for HC in "${THREADS[@]}"; do - RESULT=$(cat $BENCHMARKS | jq -r --arg test "$TEST" --argjson hc $HC 'select(.name == "proof_construction_time" and .acir_test == $test and .threads == $hc) | .value') + RESULT=$(cat $BENCHMARKS | jq -r --arg test "$TEST" --argjson hc $HC 'select(.eventName == "proof_construction_time" and .acir_test == $test and .threads == $hc) | .value') TABLE_DATA+=" $RESULT" done TABLE_DATA+=$'\n' diff --git a/noir/Earthfile b/noir/Earthfile index 88d87214d660..ec5e11de7e8b 100644 --- a/noir/Earthfile +++ b/noir/Earthfile @@ -228,11 +228,17 @@ barretenberg-acir-benches-bb: WORKDIR /usr/src/barretenberg/acir_tests +bench-acir-bb: + # This target is used for debugging the benchmarking target. + # For precise benchmarks in CI use `bench-publish-acir-bb` + FROM +barretenberg-acir-benches-bb + RUN ./bench_acir_tests.sh + export-bench-acir-bb: ARG EARTHLY_GIT_HASH FROM +barretenberg-acir-benches-bb SAVE IMAGE aztecprotocol/barretenberg-acir-benches:$EARTHLY_GIT_HASH - + bench-publish-acir-bb: ARG PULL_REQUEST ARG BRANCH @@ -249,7 +255,7 @@ bench-publish-acir-bb: END RUN mkdir -p ./log - RUN docker run -v "$(pwd)/log":/log -e LOG_FILE=/log/bench-acir.jsonl --rm aztecprotocol/barretenberg-acir-benches:$AZTEC_DOCKER_TAG ./bench_acir_tests.sh sha256 + RUN docker run -v "$(pwd)/log":/log -e LOG_FILE=/log/bench-acir.jsonl --rm aztecprotocol/barretenberg-acir-benches:$AZTEC_DOCKER_TAG ./bench_acir_tests.sh DO ../+UPLOAD_LOGS --PULL_REQUEST=$PULL_REQUEST --BRANCH=$BRANCH --COMMIT_HASH=$COMMIT_HASH diff --git a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash/Nargo.toml b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash/Nargo.toml new file mode 100644 index 000000000000..9024d9a7301b --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "bench_poseidon_hash" +version = "0.1.0" +type = "bin" +authors = [""] + +[dependencies] diff --git a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash/Prover.toml b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash/Prover.toml new file mode 100644 index 000000000000..66779dea9d7b --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash/Prover.toml @@ -0,0 +1 @@ +input = [1,2] diff --git a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash/src/main.nr b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash/src/main.nr new file mode 100644 index 000000000000..38adeef6ec75 --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash/src/main.nr @@ -0,0 +1,5 @@ +use dep::std::hash::poseidon; + +fn main(input: [Field; 2]) -> pub Field { + poseidon::bn254::hash_2(input) +} diff --git a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/Nargo.toml b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/Nargo.toml new file mode 100644 index 000000000000..b23716b2a203 --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "bench_poseidon_hash_100" +version = "0.1.0" +type = "bin" +authors = [""] + +[dependencies] diff --git a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/Prover.toml b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/Prover.toml new file mode 100644 index 000000000000..542b4a08dd6f --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/Prover.toml @@ -0,0 +1,102 @@ +input = [ + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], +] \ No newline at end of file diff --git a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr new file mode 100644 index 000000000000..266b40029e37 --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr @@ -0,0 +1,10 @@ +use dep::std::hash; + +fn main(input: [[Field; 2]; 100]) -> pub [Field; 100] { + let mut results: [Field; 100] = [0; 100]; + for i in 0..30 { + results[i] = hash::pedersen_hash(input[i]); + } + + results +} \ No newline at end of file diff --git a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/Nargo.toml b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/Nargo.toml new file mode 100644 index 000000000000..dbcbc07b1baa --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "bench_poseidon_hash_30" +version = "0.1.0" +type = "bin" +authors = [""] + +[dependencies] diff --git a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/Prover.toml b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/Prover.toml new file mode 100644 index 000000000000..7792a9ab8e36 --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/Prover.toml @@ -0,0 +1,32 @@ +input = [ + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], +] \ No newline at end of file diff --git a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/src/main.nr b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/src/main.nr new file mode 100644 index 000000000000..e31f115c8181 --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/src/main.nr @@ -0,0 +1,10 @@ +use dep::std::hash; + +fn main(input: [[Field; 2]; 30]) -> pub [Field; 30] { + let mut results: [Field; 30] = [0; 30]; + for i in 0..30 { + results[i] = hash::pedersen_hash(input[i]); + } + + results +} \ No newline at end of file diff --git a/noir/noir-repo/test_programs/rebuild.sh b/noir/noir-repo/test_programs/rebuild.sh index 4733bad10c3f..d8577449e186 100755 --- a/noir/noir-repo/test_programs/rebuild.sh +++ b/noir/noir-repo/test_programs/rebuild.sh @@ -47,6 +47,13 @@ for dir in $base_path/*; do dirs_to_process+=("$dir") done +for dir in $current_dir/benchmarks/*; do + if [[ ! -d $dir ]]; then + continue + fi + dirs_to_process+=("$dir") +done + # Process each directory in parallel pids=() if [ -z $NO_PARALLEL ]; then From c05d66c861571a788d787be1101947b5017a98ee Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Tue, 21 May 2024 14:56:25 +0000 Subject: [PATCH 02/11] chore: set error flag in bench_acir_tests --- barretenberg/acir_tests/bench_acir_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/barretenberg/acir_tests/bench_acir_tests.sh b/barretenberg/acir_tests/bench_acir_tests.sh index e73fea9be656..e0d6465add49 100755 --- a/barretenberg/acir_tests/bench_acir_tests.sh +++ b/barretenberg/acir_tests/bench_acir_tests.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -e cd "$(dirname "$0")" From 93ff47e35cb95cd5fa7fc2ed26b33cd8f928e879 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Tue, 21 May 2024 15:51:22 +0000 Subject: [PATCH 03/11] chore: fix iterations --- .../benchmarks/bench_poseidon_hash_100/src/main.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr index 266b40029e37..6acc1f504b49 100644 --- a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr +++ b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr @@ -2,7 +2,7 @@ use dep::std::hash; fn main(input: [[Field; 2]; 100]) -> pub [Field; 100] { let mut results: [Field; 100] = [0; 100]; - for i in 0..30 { + for i in 0..100 { results[i] = hash::pedersen_hash(input[i]); } From 7031f44d4c4d3e71397f78e8a523fda772aa31b1 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Tue, 21 May 2024 15:59:14 +0000 Subject: [PATCH 04/11] chore: more benchmarks --- .../benchmarks/bench_sha256/Nargo.toml | 7 ++ .../benchmarks/bench_sha256/Prover.toml | 1 + .../benchmarks/bench_sha256/src/main.nr | 5 + .../benchmarks/bench_sha256_100/Nargo.toml | 7 ++ .../benchmarks/bench_sha256_100/Prover.toml | 102 ++++++++++++++++++ .../benchmarks/bench_sha256_100/src/main.nr | 12 +++ .../benchmarks/bench_sha256_30/Nargo.toml | 7 ++ .../benchmarks/bench_sha256_30/Prover.toml | 32 ++++++ .../benchmarks/bench_sha256_30/src/main.nr | 12 +++ .../circuit-types/src/stats/metrics.ts | 30 ++++++ .../scripts/src/benchmarks/aggregate.ts | 14 ++- 11 files changed, 227 insertions(+), 2 deletions(-) create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_sha256/Nargo.toml create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_sha256/Prover.toml create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_sha256/src/main.nr create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_sha256_100/Nargo.toml create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_sha256_100/Prover.toml create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_sha256_100/src/main.nr create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_sha256_30/Nargo.toml create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_sha256_30/Prover.toml create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_sha256_30/src/main.nr diff --git a/noir/noir-repo/test_programs/benchmarks/bench_sha256/Nargo.toml b/noir/noir-repo/test_programs/benchmarks/bench_sha256/Nargo.toml new file mode 100644 index 000000000000..9024d9a7301b --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_sha256/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "bench_poseidon_hash" +version = "0.1.0" +type = "bin" +authors = [""] + +[dependencies] diff --git a/noir/noir-repo/test_programs/benchmarks/bench_sha256/Prover.toml b/noir/noir-repo/test_programs/benchmarks/bench_sha256/Prover.toml new file mode 100644 index 000000000000..66779dea9d7b --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_sha256/Prover.toml @@ -0,0 +1 @@ +input = [1,2] diff --git a/noir/noir-repo/test_programs/benchmarks/bench_sha256/src/main.nr b/noir/noir-repo/test_programs/benchmarks/bench_sha256/src/main.nr new file mode 100644 index 000000000000..c3ad2902b55b --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_sha256/src/main.nr @@ -0,0 +1,5 @@ +use dep::std; + +fn main(x: [u8; 2]) -> pub [u8; 32] { + std::hash::sha256(x) +} \ No newline at end of file diff --git a/noir/noir-repo/test_programs/benchmarks/bench_sha256_100/Nargo.toml b/noir/noir-repo/test_programs/benchmarks/bench_sha256_100/Nargo.toml new file mode 100644 index 000000000000..d0c90d75088e --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_sha256_100/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "bench_sha256_100" +version = "0.1.0" +type = "bin" +authors = [""] + +[dependencies] diff --git a/noir/noir-repo/test_programs/benchmarks/bench_sha256_100/Prover.toml b/noir/noir-repo/test_programs/benchmarks/bench_sha256_100/Prover.toml new file mode 100644 index 000000000000..542b4a08dd6f --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_sha256_100/Prover.toml @@ -0,0 +1,102 @@ +input = [ + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], +] \ No newline at end of file diff --git a/noir/noir-repo/test_programs/benchmarks/bench_sha256_100/src/main.nr b/noir/noir-repo/test_programs/benchmarks/bench_sha256_100/src/main.nr new file mode 100644 index 000000000000..d78ca8002d2d --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_sha256_100/src/main.nr @@ -0,0 +1,12 @@ +use dep::std; + +global SIZE = 100; + +fn main(input: [[u8; 2]; SIZE]) -> pub [[u8; 32]; SIZE] { + let mut results: [[u8; 32]; SIZE] = [[0; 32]; SIZE]; + for i in 0..SIZE { + results[i] = std::hash::sha256(input[i]); + } + + results +} \ No newline at end of file diff --git a/noir/noir-repo/test_programs/benchmarks/bench_sha256_30/Nargo.toml b/noir/noir-repo/test_programs/benchmarks/bench_sha256_30/Nargo.toml new file mode 100644 index 000000000000..c1dc76df3942 --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_sha256_30/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "bench_sha256_30" +version = "0.1.0" +type = "bin" +authors = [""] + +[dependencies] diff --git a/noir/noir-repo/test_programs/benchmarks/bench_sha256_30/Prover.toml b/noir/noir-repo/test_programs/benchmarks/bench_sha256_30/Prover.toml new file mode 100644 index 000000000000..7792a9ab8e36 --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_sha256_30/Prover.toml @@ -0,0 +1,32 @@ +input = [ + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], + [1,2], +] \ No newline at end of file diff --git a/noir/noir-repo/test_programs/benchmarks/bench_sha256_30/src/main.nr b/noir/noir-repo/test_programs/benchmarks/bench_sha256_30/src/main.nr new file mode 100644 index 000000000000..fa66d6265863 --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_sha256_30/src/main.nr @@ -0,0 +1,12 @@ +use dep::std; + +global SIZE = 30; + +fn main(input: [[u8; 2]; SIZE]) -> pub [[u8; 32]; SIZE] { + let mut results: [[u8; 32]; SIZE] = [[0; 32]; SIZE]; + for i in 0..SIZE { + results[i] = std::hash::sha256(input[i]); + } + + results +} \ No newline at end of file diff --git a/yarn-project/circuit-types/src/stats/metrics.ts b/yarn-project/circuit-types/src/stats/metrics.ts index 97e97abedfe1..b20585bb655e 100644 --- a/yarn-project/circuit-types/src/stats/metrics.ts +++ b/yarn-project/circuit-types/src/stats/metrics.ts @@ -32,6 +32,36 @@ export const Metrics = [ description: 'Time needed to generate a proof of an ACIR program.', events: ['proof_construction_time'], }, + { + name: 'proof_construction_time_sha256_30', + groupBy: 'threads', + description: 'Time needed to generate a proof of an ACIR program.', + events: ['proof_construction_time'], + }, + { + name: 'proof_construction_time_sha256_100', + groupBy: 'threads', + description: 'Time needed to generate a proof of an ACIR program.', + events: ['proof_construction_time'], + }, + { + name: 'proof_construction_time_poseidon_hash', + groupBy: 'threads', + description: 'Time needed to generate a proof of an ACIR program.', + events: ['proof_construction_time'], + }, + { + name: 'proof_construction_time_poseidon_hash_30', + groupBy: 'threads', + description: 'Time needed to generate a proof of an ACIR program.', + events: ['proof_construction_time'], + }, + { + name: 'proof_construction_time_poseidon_hash_100', + groupBy: 'threads', + description: 'Time needed to generate a proof of an ACIR program.', + events: ['proof_construction_time'], + }, { name: 'l1_rollup_calldata_size_in_bytes', groupBy: 'block-size', diff --git a/yarn-project/scripts/src/benchmarks/aggregate.ts b/yarn-project/scripts/src/benchmarks/aggregate.ts index caa95c220101..43c46ec0ff90 100644 --- a/yarn-project/scripts/src/benchmarks/aggregate.ts +++ b/yarn-project/scripts/src/benchmarks/aggregate.ts @@ -69,8 +69,18 @@ function append( /** Processes an entry with event name 'acir-proof-generated' and updates results */ function processAcirProofGenerated(entry: ProofConstructed, results: BenchmarkCollectedResults) { - if (entry.acir_test === 'sha256') { - append(results, `proof_construction_time_sha256`, entry.threads, entry.value); + if (entry.acir_test === 'bench_sha256') { + append(results, 'proof_construction_time_sha256', entry.threads, entry.value); + } else if (entry.acir_test === 'bench_sha256_30') { + append(results, 'proof_construction_time_sha256_30', entry.threads, entry.value); + } else if (entry.acir_test === 'bench_sha256_100') { + append(results, 'proof_construction_time_sha256_100', entry.threads, entry.value); + } else if (entry.acir_test === 'bench_poseidon_hash') { + append(results, 'proof_construction_time_poseidon_hash', entry.threads, entry.value); + } else if (entry.acir_test === 'bench_poseidon_hash_30') { + append(results, 'proof_construction_time_poseidon_hash_30', entry.threads, entry.value); + } else if (entry.acir_test === 'bench_poseidon_hash_100') { + append(results, 'proof_construction_time_poseidon_hash_100', entry.threads, entry.value); } } From 009441af5c393746b3edfe8e3273489bc848ff03 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Tue, 21 May 2024 16:19:40 +0000 Subject: [PATCH 05/11] chore: fix inputs --- .../test_programs/benchmarks/bench_sha256/src/main.nr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/noir/noir-repo/test_programs/benchmarks/bench_sha256/src/main.nr b/noir/noir-repo/test_programs/benchmarks/bench_sha256/src/main.nr index c3ad2902b55b..fc873fb4afbd 100644 --- a/noir/noir-repo/test_programs/benchmarks/bench_sha256/src/main.nr +++ b/noir/noir-repo/test_programs/benchmarks/bench_sha256/src/main.nr @@ -1,5 +1,5 @@ use dep::std; -fn main(x: [u8; 2]) -> pub [u8; 32] { - std::hash::sha256(x) +fn main(input: [u8; 2]) -> pub [u8; 32] { + std::hash::sha256(input) } \ No newline at end of file From 2009e1b9e15fbf58201eb46a4515f3a903f4ca96 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Tue, 21 May 2024 16:25:37 +0000 Subject: [PATCH 06/11] chore: fix bench --- noir/noir-repo/test_programs/benchmarks/bench_sha256/Nargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noir/noir-repo/test_programs/benchmarks/bench_sha256/Nargo.toml b/noir/noir-repo/test_programs/benchmarks/bench_sha256/Nargo.toml index 9024d9a7301b..488b94ca8586 100644 --- a/noir/noir-repo/test_programs/benchmarks/bench_sha256/Nargo.toml +++ b/noir/noir-repo/test_programs/benchmarks/bench_sha256/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "bench_poseidon_hash" +name = "bench_sha256" version = "0.1.0" type = "bin" authors = [""] From a30886d5c4bcde95a6b045ba928168881107987d Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Tue, 21 May 2024 16:48:08 +0000 Subject: [PATCH 07/11] chore: add eddsa and pull full list of benchmarks automatically --- barretenberg/acir_tests/bench_acir_tests.sh | 4 +++- .../test_programs/benchmarks/bench_eddsa/Nargo.toml | 7 +++++++ .../test_programs/benchmarks/bench_eddsa/Prover.toml | 6 ++++++ .../test_programs/benchmarks/bench_eddsa/src/main.nr | 12 ++++++++++++ yarn-project/circuit-types/src/stats/metrics.ts | 6 ++++++ yarn-project/scripts/src/benchmarks/aggregate.ts | 2 ++ 6 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_eddsa/Nargo.toml create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_eddsa/Prover.toml create mode 100644 noir/noir-repo/test_programs/benchmarks/bench_eddsa/src/main.nr diff --git a/barretenberg/acir_tests/bench_acir_tests.sh b/barretenberg/acir_tests/bench_acir_tests.sh index e0d6465add49..9f9bd1dd2e55 100755 --- a/barretenberg/acir_tests/bench_acir_tests.sh +++ b/barretenberg/acir_tests/bench_acir_tests.sh @@ -3,6 +3,8 @@ set -e cd "$(dirname "$0")" +./clone_test_vectors.sh + TEST_NAMES=("$@") THREADS=(1 4 16 32 64) BENCHMARKS=$LOG_FILE @@ -12,7 +14,7 @@ if [[ -z "${LOG_FILE}" ]]; then fi if [ "${#TEST_NAMES[@]}" -eq 0 ]; then - TEST_NAMES=(bench_poseidon_hash bench_poseidon_hash_30 bench_poseidon_hash_100) + TEST_NAMES=$(find acir_tests/bench_* -maxdepth 0 -type d -printf '%f ') fi for TEST in ${TEST_NAMES[@]}; do diff --git a/noir/noir-repo/test_programs/benchmarks/bench_eddsa/Nargo.toml b/noir/noir-repo/test_programs/benchmarks/bench_eddsa/Nargo.toml new file mode 100644 index 000000000000..4ac0f2e954ed --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_eddsa/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "bench_eddsa" +version = "0.1.0" +type = "bin" +authors = [""] + +[dependencies] diff --git a/noir/noir-repo/test_programs/benchmarks/bench_eddsa/Prover.toml b/noir/noir-repo/test_programs/benchmarks/bench_eddsa/Prover.toml new file mode 100644 index 000000000000..8cfb63cd80e0 --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_eddsa/Prover.toml @@ -0,0 +1,6 @@ +msg = 789 +pub_key_x = "0x16b051f37589e0dcf4ad3c415c090798c10d3095bedeedabfcc709ad787f3507" +pub_key_y = "0x062800ac9e60839fab9218e5ed9d541f4586e41275f4071816a975895d349a5e" +r8_x = "0x163814666f04c4d2969059a6b63ee26a0f9f0f81bd5957b0796e2e8f4a8a2f06" +r8_y = "0x1255b17d9e4bfb81831625b788f8a1665128079ac4b6c8c3cd1b857666a05a54" +s = "1230930278088778318663840827871215383007447616379808164955640681455510074924" \ No newline at end of file diff --git a/noir/noir-repo/test_programs/benchmarks/bench_eddsa/src/main.nr b/noir/noir-repo/test_programs/benchmarks/bench_eddsa/src/main.nr new file mode 100644 index 000000000000..31c2f1f2d13d --- /dev/null +++ b/noir/noir-repo/test_programs/benchmarks/bench_eddsa/src/main.nr @@ -0,0 +1,12 @@ +use dep::std::eddsa::{eddsa_poseidon_verify}; + +fn main( + msg: pub Field, + pub_key_x: Field, + pub_key_y: Field, + r8_x: Field, + r8_y: Field, + s: Field +) -> pub bool { + eddsa_poseidon_verify(pub_key_x, pub_key_y, s, r8_x, r8_y, msg) +} \ No newline at end of file diff --git a/yarn-project/circuit-types/src/stats/metrics.ts b/yarn-project/circuit-types/src/stats/metrics.ts index b20585bb655e..67646d9f70f9 100644 --- a/yarn-project/circuit-types/src/stats/metrics.ts +++ b/yarn-project/circuit-types/src/stats/metrics.ts @@ -62,6 +62,12 @@ export const Metrics = [ description: 'Time needed to generate a proof of an ACIR program.', events: ['proof_construction_time'], }, + { + name: 'proof_construction_time_eddsa', + groupBy: 'threads', + description: 'Time needed to generate a proof of an ACIR program.', + events: ['proof_construction_time'], + }, { name: 'l1_rollup_calldata_size_in_bytes', groupBy: 'block-size', diff --git a/yarn-project/scripts/src/benchmarks/aggregate.ts b/yarn-project/scripts/src/benchmarks/aggregate.ts index 43c46ec0ff90..575654e486a7 100644 --- a/yarn-project/scripts/src/benchmarks/aggregate.ts +++ b/yarn-project/scripts/src/benchmarks/aggregate.ts @@ -81,6 +81,8 @@ function processAcirProofGenerated(entry: ProofConstructed, results: BenchmarkCo append(results, 'proof_construction_time_poseidon_hash_30', entry.threads, entry.value); } else if (entry.acir_test === 'bench_poseidon_hash_100') { append(results, 'proof_construction_time_poseidon_hash_100', entry.threads, entry.value); + }else if (entry.acir_test === 'bench_eddsa') { + append(results, 'proof_construction_time_eddsa', entry.threads, entry.value); } } From af525b478181bbea5aeee8e1618982df77b1457b Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Tue, 21 May 2024 16:54:35 +0000 Subject: [PATCH 08/11] empty commit From 706d49f3f9f63005cf455390c369186e7c1e61a4 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Tue, 21 May 2024 23:50:23 +0000 Subject: [PATCH 09/11] chore: formatting fix --- yarn-project/scripts/src/benchmarks/aggregate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/scripts/src/benchmarks/aggregate.ts b/yarn-project/scripts/src/benchmarks/aggregate.ts index 575654e486a7..6f74bda6d205 100644 --- a/yarn-project/scripts/src/benchmarks/aggregate.ts +++ b/yarn-project/scripts/src/benchmarks/aggregate.ts @@ -81,7 +81,7 @@ function processAcirProofGenerated(entry: ProofConstructed, results: BenchmarkCo append(results, 'proof_construction_time_poseidon_hash_30', entry.threads, entry.value); } else if (entry.acir_test === 'bench_poseidon_hash_100') { append(results, 'proof_construction_time_poseidon_hash_100', entry.threads, entry.value); - }else if (entry.acir_test === 'bench_eddsa') { + } else if (entry.acir_test === 'bench_eddsa') { append(results, 'proof_construction_time_eddsa', entry.threads, entry.value); } } From ea293f8f53d717e7937d9d5e3ca4d15f82123ee5 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Fri, 24 May 2024 16:16:29 +0000 Subject: [PATCH 10/11] review comments --- .../Nargo.toml | 2 +- .../Prover.toml | 0 .../src/main.nr | 0 .../benchmarks/bench_poseidon_hash_100/src/main.nr | 10 ++++++---- .../benchmarks/bench_poseidon_hash_30/src/main.nr | 10 ++++++---- yarn-project/circuit-types/src/stats/metrics.ts | 14 +++++++------- yarn-project/scripts/src/benchmarks/aggregate.ts | 14 +++++++------- 7 files changed, 27 insertions(+), 23 deletions(-) rename noir/noir-repo/test_programs/benchmarks/{bench_eddsa => bench_eddsa_poseidon}/Nargo.toml (70%) rename noir/noir-repo/test_programs/benchmarks/{bench_eddsa => bench_eddsa_poseidon}/Prover.toml (100%) rename noir/noir-repo/test_programs/benchmarks/{bench_eddsa => bench_eddsa_poseidon}/src/main.nr (100%) diff --git a/noir/noir-repo/test_programs/benchmarks/bench_eddsa/Nargo.toml b/noir/noir-repo/test_programs/benchmarks/bench_eddsa_poseidon/Nargo.toml similarity index 70% rename from noir/noir-repo/test_programs/benchmarks/bench_eddsa/Nargo.toml rename to noir/noir-repo/test_programs/benchmarks/bench_eddsa_poseidon/Nargo.toml index 4ac0f2e954ed..bc2a779f7b2d 100644 --- a/noir/noir-repo/test_programs/benchmarks/bench_eddsa/Nargo.toml +++ b/noir/noir-repo/test_programs/benchmarks/bench_eddsa_poseidon/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "bench_eddsa" +name = "bench_eddsa_poseidon" version = "0.1.0" type = "bin" authors = [""] diff --git a/noir/noir-repo/test_programs/benchmarks/bench_eddsa/Prover.toml b/noir/noir-repo/test_programs/benchmarks/bench_eddsa_poseidon/Prover.toml similarity index 100% rename from noir/noir-repo/test_programs/benchmarks/bench_eddsa/Prover.toml rename to noir/noir-repo/test_programs/benchmarks/bench_eddsa_poseidon/Prover.toml diff --git a/noir/noir-repo/test_programs/benchmarks/bench_eddsa/src/main.nr b/noir/noir-repo/test_programs/benchmarks/bench_eddsa_poseidon/src/main.nr similarity index 100% rename from noir/noir-repo/test_programs/benchmarks/bench_eddsa/src/main.nr rename to noir/noir-repo/test_programs/benchmarks/bench_eddsa_poseidon/src/main.nr diff --git a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr index 6acc1f504b49..4d2d94e49463 100644 --- a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr +++ b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr @@ -1,9 +1,11 @@ use dep::std::hash; -fn main(input: [[Field; 2]; 100]) -> pub [Field; 100] { - let mut results: [Field; 100] = [0; 100]; - for i in 0..100 { - results[i] = hash::pedersen_hash(input[i]); +global SIZE = 30; + +fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] { + let mut results: [Field; SIZE] = [0; SIZE]; + for i in 0..SIZE { + results[i] = hash::poseidon::bn254::hash_2(input[i]); } results diff --git a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/src/main.nr b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/src/main.nr index e31f115c8181..4d2d94e49463 100644 --- a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/src/main.nr +++ b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_30/src/main.nr @@ -1,9 +1,11 @@ use dep::std::hash; -fn main(input: [[Field; 2]; 30]) -> pub [Field; 30] { - let mut results: [Field; 30] = [0; 30]; - for i in 0..30 { - results[i] = hash::pedersen_hash(input[i]); +global SIZE = 30; + +fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] { + let mut results: [Field; SIZE] = [0; SIZE]; + for i in 0..SIZE { + results[i] = hash::poseidon::bn254::hash_2(input[i]); } results diff --git a/yarn-project/circuit-types/src/stats/metrics.ts b/yarn-project/circuit-types/src/stats/metrics.ts index 67646d9f70f9..4b9716fcc07f 100644 --- a/yarn-project/circuit-types/src/stats/metrics.ts +++ b/yarn-project/circuit-types/src/stats/metrics.ts @@ -27,43 +27,43 @@ export interface Metric { /** Metric definitions to track from benchmarks. */ export const Metrics = [ { - name: 'proof_construction_time_sha256', + name: 'proof_construction_time_sha256_ms', groupBy: 'threads', description: 'Time needed to generate a proof of an ACIR program.', events: ['proof_construction_time'], }, { - name: 'proof_construction_time_sha256_30', + name: 'proof_construction_time_sha256_30_ms', groupBy: 'threads', description: 'Time needed to generate a proof of an ACIR program.', events: ['proof_construction_time'], }, { - name: 'proof_construction_time_sha256_100', + name: 'proof_construction_time_sha256_100_ms', groupBy: 'threads', description: 'Time needed to generate a proof of an ACIR program.', events: ['proof_construction_time'], }, { - name: 'proof_construction_time_poseidon_hash', + name: 'proof_construction_time_poseidon_hash_ms', groupBy: 'threads', description: 'Time needed to generate a proof of an ACIR program.', events: ['proof_construction_time'], }, { - name: 'proof_construction_time_poseidon_hash_30', + name: 'proof_construction_time_poseidon_hash_30_ms', groupBy: 'threads', description: 'Time needed to generate a proof of an ACIR program.', events: ['proof_construction_time'], }, { - name: 'proof_construction_time_poseidon_hash_100', + name: 'proof_construction_time_poseidon_hash_100_ms', groupBy: 'threads', description: 'Time needed to generate a proof of an ACIR program.', events: ['proof_construction_time'], }, { - name: 'proof_construction_time_eddsa', + name: 'proof_construction_time_eddsa_poseidon_ms', groupBy: 'threads', description: 'Time needed to generate a proof of an ACIR program.', events: ['proof_construction_time'], diff --git a/yarn-project/scripts/src/benchmarks/aggregate.ts b/yarn-project/scripts/src/benchmarks/aggregate.ts index 6f74bda6d205..ff259f5b0474 100644 --- a/yarn-project/scripts/src/benchmarks/aggregate.ts +++ b/yarn-project/scripts/src/benchmarks/aggregate.ts @@ -70,19 +70,19 @@ function append( /** Processes an entry with event name 'acir-proof-generated' and updates results */ function processAcirProofGenerated(entry: ProofConstructed, results: BenchmarkCollectedResults) { if (entry.acir_test === 'bench_sha256') { - append(results, 'proof_construction_time_sha256', entry.threads, entry.value); + append(results, 'proof_construction_time_sha256_ms', entry.threads, entry.value); } else if (entry.acir_test === 'bench_sha256_30') { - append(results, 'proof_construction_time_sha256_30', entry.threads, entry.value); + append(results, 'proof_construction_time_sha256_30_ms', entry.threads, entry.value); } else if (entry.acir_test === 'bench_sha256_100') { - append(results, 'proof_construction_time_sha256_100', entry.threads, entry.value); + append(results, 'proof_construction_time_sha256_100_ms', entry.threads, entry.value); } else if (entry.acir_test === 'bench_poseidon_hash') { - append(results, 'proof_construction_time_poseidon_hash', entry.threads, entry.value); + append(results, 'proof_construction_time_poseidon_hash_ms', entry.threads, entry.value); } else if (entry.acir_test === 'bench_poseidon_hash_30') { - append(results, 'proof_construction_time_poseidon_hash_30', entry.threads, entry.value); + append(results, 'proof_construction_time_poseidon_hash_30_ms', entry.threads, entry.value); } else if (entry.acir_test === 'bench_poseidon_hash_100') { - append(results, 'proof_construction_time_poseidon_hash_100', entry.threads, entry.value); + append(results, 'proof_construction_time_poseidon_hash_100_ms', entry.threads, entry.value); } else if (entry.acir_test === 'bench_eddsa') { - append(results, 'proof_construction_time_eddsa', entry.threads, entry.value); + append(results, 'proof_construction_time_eddsa_poseidon_ms', entry.threads, entry.value); } } From 592b8ebcf504d6af7e2768591907f6d4f9a29832 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Fri, 24 May 2024 18:02:33 +0100 Subject: [PATCH 11/11] Update noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr --- .../benchmarks/bench_poseidon_hash_100/src/main.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr index 4d2d94e49463..fc9a5b7a9705 100644 --- a/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr +++ b/noir/noir-repo/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr @@ -1,6 +1,6 @@ use dep::std::hash; -global SIZE = 30; +global SIZE = 100; fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] { let mut results: [Field; SIZE] = [0; SIZE];