From f94b880f24135ab0d66bfcac3bc152a26473ebb3 Mon Sep 17 00:00:00 2001 From: Khashayar Barooti Date: Thu, 28 Nov 2024 10:44:19 +0000 Subject: [PATCH 01/12] added the benchmark tooling --- .github/workflows/benchmarks.yml | 48 ++++++++++++++++++++++++++++++++ scripts/build-gates-report.sh | 33 ++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 .github/workflows/benchmarks.yml create mode 100644 scripts/build-gates-report.sh diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml new file mode 100644 index 00000000..57d8d065 --- /dev/null +++ b/.github/workflows/benchmarks.yml @@ -0,0 +1,48 @@ +name: Benchmarks + +on: + push: + branches: + - master + pull_request: + +jobs: + test: + name: Benchmark library + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install Nargo + uses: noir-lang/noirup@v0.1.3 + with: + toolchain: 0.36.0 + + - name: Install bb + run: | + npm install -g bbup + bbup -nv 0.36.0 + + - name: Build Noir benchmark programs + run: nargo export + + - name: Generate gates report + run: ./scripts/build-gates-report.sh + env: + BACKEND: /home/runner/.bb/bb + + - name: Compare gates reports + id: gates_diff + uses: noir-lang/noir-gates-diff@1931aaaa848a1a009363d6115293f7b7fc72bb87 + with: + report: gates_report.json + summaryQuantile: 0.9 # only display the 10% most significant circuit size diffs in the summary (defaults to 20%) + + - name: Add gates diff to sticky comment + if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' + uses: marocchino/sticky-pull-request-comment@v2 + with: + # delete the comment in case changes no longer impact circuit sizes + delete: ${{ !steps.gates_diff.outputs.markdown }} + message: ${{ steps.gates_diff.outputs.markdown }} \ No newline at end of file diff --git a/scripts/build-gates-report.sh b/scripts/build-gates-report.sh new file mode 100644 index 00000000..28f0a633 --- /dev/null +++ b/scripts/build-gates-report.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -e + +BACKEND=${BACKEND:-bb} + +cd $(dirname "$0")/../ + +artifacts_path="./export" +artifacts=$(ls $artifacts_path) + +echo "{\"programs\": [" > gates_report.json + +# Bound for checking where to place last parentheses +NUM_ARTIFACTS=$(ls -1q "$artifacts_path" | wc -l) + +ITER="1" +for artifact in $artifacts; do + ARTIFACT_NAME=$(basename "$artifact") + + GATES_INFO=$($BACKEND gates -b "$artifacts_path/$artifact") + MAIN_FUNCTION_INFO=$(echo $GATES_INFO | jq -r '.functions[0] | .name = "main"') + echo "{\"package_name\": \"$ARTIFACT_NAME\", \"functions\": [$MAIN_FUNCTION_INFO]" >> gates_report.json + + if (($ITER == $NUM_ARTIFACTS)); then + echo "}" >> gates_report.json + else + echo "}, " >> gates_report.json + fi + + ITER=$(( $ITER + 1 )) +done + +echo "]}" >> gates_report.json \ No newline at end of file From 187fb17649bca2507ff467ac04401762c7384922 Mon Sep 17 00:00:00 2001 From: Khashayar Barooti Date: Fri, 29 Nov 2024 11:10:08 +0000 Subject: [PATCH 02/12] changed permissions --- scripts/build-gates-report.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/build-gates-report.sh diff --git a/scripts/build-gates-report.sh b/scripts/build-gates-report.sh old mode 100644 new mode 100755 From 26bf2086db111a23d7cfc1a71b9c4298aca09fd6 Mon Sep 17 00:00:00 2001 From: Khashayar Barooti Date: Mon, 9 Dec 2024 10:50:17 +0000 Subject: [PATCH 03/12] added an empty library because of the script error --- gates_report.json | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 gates_report.json diff --git a/gates_report.json b/gates_report.json new file mode 100644 index 00000000..d2f352a7 --- /dev/null +++ b/gates_report.json @@ -0,0 +1,2 @@ +{"programs": [ +]} From 18bcc912662fe28b09b89f542b5733f804e71d14 Mon Sep 17 00:00:00 2001 From: Khashayar Barooti Date: Mon, 23 Dec 2024 17:28:34 +0000 Subject: [PATCH 04/12] dealing with the annoying dir not existing error on CI --- .github/workflows/benchmarks.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index 57d8d065..44c53157 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -3,7 +3,7 @@ name: Benchmarks on: push: branches: - - master + - main pull_request: jobs: @@ -26,6 +26,9 @@ jobs: - name: Build Noir benchmark programs run: nargo export + + - name: create the export directory + run: mkdir -p export - name: Generate gates report run: ./scripts/build-gates-report.sh From d2cb114484482bbc3a7fa960e425d5eee21edcd8 Mon Sep 17 00:00:00 2001 From: Khashayar Barooti Date: Mon, 23 Dec 2024 17:45:23 +0000 Subject: [PATCH 05/12] added a dummy test --- .gitignore | 2 ++ gates_report.json | 1 - src/benchmarks/bignum_bench.nr | 36 ++++++++++++++++++++++++++++++++++ src/benchmarks/mod.nr | 1 + src/lib.nr | 2 ++ 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/benchmarks/bignum_bench.nr create mode 100644 src/benchmarks/mod.nr diff --git a/.gitignore b/.gitignore index f99b23da..024eed6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ target .vscode/launch.json +gates_report.json +export/*.* \ No newline at end of file diff --git a/gates_report.json b/gates_report.json index d2f352a7..81c4e337 100644 --- a/gates_report.json +++ b/gates_report.json @@ -1,2 +1 @@ {"programs": [ -]} diff --git a/src/benchmarks/bignum_bench.nr b/src/benchmarks/bignum_bench.nr new file mode 100644 index 00000000..a83db391 --- /dev/null +++ b/src/benchmarks/bignum_bench.nr @@ -0,0 +1,36 @@ +use crate::utils::u60_representation::U60Repr; + +use crate::bignum::BigNum; +use crate::bignum::BigNumTrait; + +use crate::params::BigNumParams; +use crate::params::BigNumParamsGetter; + +use crate::fields::bls12_381Fq::BLS12_381_Fq_Params; +use crate::fields::bn254Fq::BN254_Fq_Params; +use crate::fields::U256::U256Params; + +struct Test2048Params {} + +// See https://github.com/noir-lang/noir/issues/6172 + +type Fq = BigNum<3, 254, BN254_Fq_Params>; +type BN256 = BigNum<3, 257, U256Params>; +type BN381 = BigNum<4, 381, BLS12_381_Fq_Params>; +type BN2048 = BigNum<18, 2048, Test2048Params>; + + + +#[export] +fn test_add_BN() { + let mut a: Fq = BigNum::modulus(); + let mut b: Fq = BigNum::modulus(); + let mut expected: Fq = BigNum::modulus(); + + a.limbs[0] -= 1; + b.limbs[0] -= 1; + expected.limbs[0] -= 2; + + let result = a + b; + assert(result == expected); +} diff --git a/src/benchmarks/mod.nr b/src/benchmarks/mod.nr new file mode 100644 index 00000000..c1eddc0d --- /dev/null +++ b/src/benchmarks/mod.nr @@ -0,0 +1 @@ +mod bignum_bench; diff --git a/src/lib.nr b/src/lib.nr index fa8840ff..58022e2a 100644 --- a/src/lib.nr +++ b/src/lib.nr @@ -21,3 +21,5 @@ pub use runtime_bignum::RuntimeBigNum; // Tests mod tests; + +mod benchmarks; \ No newline at end of file From c2766555851e2728a71d94b7efd146f52f019b92 Mon Sep 17 00:00:00 2001 From: Khashayar Barooti Date: Mon, 23 Dec 2024 17:47:55 +0000 Subject: [PATCH 06/12] formatter --- .gitignore | 2 +- src/benchmarks/bignum_bench.nr | 2 -- src/lib.nr | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 024eed6b..1e8e74ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ target .vscode/launch.json gates_report.json -export/*.* \ No newline at end of file +export/*.* diff --git a/src/benchmarks/bignum_bench.nr b/src/benchmarks/bignum_bench.nr index a83db391..0db2dada 100644 --- a/src/benchmarks/bignum_bench.nr +++ b/src/benchmarks/bignum_bench.nr @@ -19,8 +19,6 @@ type BN256 = BigNum<3, 257, U256Params>; type BN381 = BigNum<4, 381, BLS12_381_Fq_Params>; type BN2048 = BigNum<18, 2048, Test2048Params>; - - #[export] fn test_add_BN() { let mut a: Fq = BigNum::modulus(); diff --git a/src/lib.nr b/src/lib.nr index 58022e2a..f379afdd 100644 --- a/src/lib.nr +++ b/src/lib.nr @@ -22,4 +22,4 @@ pub use runtime_bignum::RuntimeBigNum; // Tests mod tests; -mod benchmarks; \ No newline at end of file +mod benchmarks; From aabeb32b36072fd0f0451a9841020376c11dca89 Mon Sep 17 00:00:00 2001 From: Khashayar Barooti Date: Mon, 23 Dec 2024 17:52:02 +0000 Subject: [PATCH 07/12] changed workflow to make the report show up on my branch --- .github/workflows/benchmarks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index 44c53157..a0b5f638 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -3,7 +3,7 @@ name: Benchmarks on: push: branches: - - main + - kb/add_benchmark_tooling pull_request: jobs: From 6e05d37339b799f2c84d84dad375dda821f9b109 Mon Sep 17 00:00:00 2001 From: Khashayar Barooti Date: Mon, 23 Dec 2024 17:54:12 +0000 Subject: [PATCH 08/12] reverting the branch followed --- .github/workflows/benchmarks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index a0b5f638..3f61d62e 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -3,7 +3,7 @@ name: Benchmarks on: push: branches: - - kb/add_benchmark_tooling + - main pull_request: jobs: From 7037e79728969deda489a123c2e58132e2e3e1f6 Mon Sep 17 00:00:00 2001 From: Khashayar Barooti Date: Mon, 23 Dec 2024 18:13:05 +0000 Subject: [PATCH 09/12] bumped the stable version --- .github/workflows/benchmarks.yml | 4 ++++ .github/workflows/test.yml | 2 +- gates_report.json | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index 3f61d62e..9f5fae37 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -34,6 +34,10 @@ jobs: run: ./scripts/build-gates-report.sh env: BACKEND: /home/runner/.bb/bb + - name: add gate count sticky comment + uses: marocchino/sticky-pull-request-comment@v2 + with: + message: ${{ steps.gates_diff.outputs.markdown }} - name: Compare gates reports id: gates_diff diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1db5d1ed..fba3f1b3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ on: env: CARGO_TERM_COLOR: always - MINIMUM_NOIR_VERSION: v0.36.0 + MINIMUM_NOIR_VERSION: v1.0.0-beta.0 jobs: noir-version-list: diff --git a/gates_report.json b/gates_report.json index 81c4e337..5d8657c4 100644 --- a/gates_report.json +++ b/gates_report.json @@ -1 +1,14 @@ {"programs": [ +{"package_name": "test_add_BN.json", "functions": [{ + "acir_opcodes": 4, + "circuit_size": 20, + "gates_per_opcode": [ + 2, + 1, + 1, + 1 + ], + "name": "main" +}] +} +]} From c0f402c9ee3fb4971a554c80e226800504e194bb Mon Sep 17 00:00:00 2001 From: Khashayar Barooti Date: Mon, 23 Dec 2024 18:14:23 +0000 Subject: [PATCH 10/12] some unsaved changes --- .github/workflows/benchmarks.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index 9f5fae37..174963ce 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -3,7 +3,7 @@ name: Benchmarks on: push: branches: - - main + - main pull_request: jobs: @@ -17,12 +17,12 @@ jobs: - name: Install Nargo uses: noir-lang/noirup@v0.1.3 with: - toolchain: 0.36.0 + toolchain: 1.0.0-beta.0 - name: Install bb run: | npm install -g bbup - bbup -nv 0.36.0 + bbup -nv v1.0.0-beta.0 - name: Build Noir benchmark programs run: nargo export @@ -34,10 +34,6 @@ jobs: run: ./scripts/build-gates-report.sh env: BACKEND: /home/runner/.bb/bb - - name: add gate count sticky comment - uses: marocchino/sticky-pull-request-comment@v2 - with: - message: ${{ steps.gates_diff.outputs.markdown }} - name: Compare gates reports id: gates_diff From d8e452c3146ceff2fda418cdf5d6561d8201bbb2 Mon Sep 17 00:00:00 2001 From: Khashayar Barooti Date: Mon, 23 Dec 2024 18:16:10 +0000 Subject: [PATCH 11/12] workflow stuff and formatter --- .github/workflows/benchmarks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index 174963ce..e8184b71 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -22,7 +22,7 @@ jobs: - name: Install bb run: | npm install -g bbup - bbup -nv v1.0.0-beta.0 + bbup -nv 1.0.0-beta.0 - name: Build Noir benchmark programs run: nargo export From 058dffc71bee0a1e8dcaffd81f8811d143742170 Mon Sep 17 00:00:00 2001 From: Khashayar Barooti Date: Mon, 23 Dec 2024 18:18:26 +0000 Subject: [PATCH 12/12] use correct formatter version --- src/bignum.nr | 3 ++- src/fns/constrained_ops.nr | 3 ++- src/runtime_bignum.nr | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/bignum.nr b/src/bignum.nr index 52002bd7..94f0e60c 100644 --- a/src/bignum.nr +++ b/src/bignum.nr @@ -6,7 +6,8 @@ use crate::fns::{ constrained_ops::{ add, assert_is_not_equal, conditional_select, derive_from_seed, div, eq, mul, neg, sub, udiv, udiv_mod, umod, validate_in_field, validate_in_range, - }, expressions::{__compute_quadratic_expression, evaluate_quadratic_expression}, + }, + expressions::{__compute_quadratic_expression, evaluate_quadratic_expression}, serialization::{from_be_bytes, to_le_bytes}, unconstrained_ops::{ __add, __batch_invert, __batch_invert_slice, __derive_from_seed, __div, __eq, __invmod, diff --git a/src/fns/constrained_ops.nr b/src/fns/constrained_ops.nr index 758e23dc..30ded4ea 100644 --- a/src/fns/constrained_ops.nr +++ b/src/fns/constrained_ops.nr @@ -5,7 +5,8 @@ use crate::fns::{ unconstrained_helpers::{ __add_with_flags, __neg_with_flags, __sub_with_flags, __validate_gt_remainder, __validate_in_field_compute_borrow_flags, - }, unconstrained_ops::{__div, __mul, __udiv_mod}, + }, + unconstrained_ops::{__div, __mul, __udiv_mod}, }; /** diff --git a/src/runtime_bignum.nr b/src/runtime_bignum.nr index 0325ca54..ec141ebd 100644 --- a/src/runtime_bignum.nr +++ b/src/runtime_bignum.nr @@ -5,7 +5,8 @@ use crate::fns::{ constrained_ops::{ add, assert_is_not_equal, conditional_select, derive_from_seed, div, eq, mul, neg, sub, udiv, udiv_mod, umod, validate_in_field, validate_in_range, - }, expressions::{__compute_quadratic_expression, evaluate_quadratic_expression}, + }, + expressions::{__compute_quadratic_expression, evaluate_quadratic_expression}, serialization::{from_be_bytes, to_le_bytes}, unconstrained_ops::{ __add, __batch_invert, __batch_invert_slice, __derive_from_seed, __div, __eq, __invmod,