From 34dbea028cf6e22a46413f936a487d9fcb13493b Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Sat, 30 Nov 2024 19:58:34 +0000 Subject: [PATCH] Initial commit --- .github/NIGHTLY_CANARY_DIED.md | 7 + .github/workflows/benchmark.yml | 48 ++++++ .github/workflows/nightly-canary.yml | 40 +++++ .github/workflows/pull-request-title.yml | 30 ++++ .github/workflows/release.yml | 21 +++ .github/workflows/test.yml | 67 ++++++++ .gitignore | 3 + .release-please-manifest.json | 1 + LICENSE | 201 +++++++++++++++++++++++ Nargo.toml | 7 + README.md | 43 +++++ release-please-config.json | 16 ++ scripts/build-gates-report.sh | 35 ++++ src/lib.nr | 15 ++ 14 files changed, 534 insertions(+) create mode 100644 .github/NIGHTLY_CANARY_DIED.md create mode 100644 .github/workflows/benchmark.yml create mode 100644 .github/workflows/nightly-canary.yml create mode 100644 .github/workflows/pull-request-title.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml create mode 100644 .gitignore create mode 100644 .release-please-manifest.json create mode 100644 LICENSE create mode 100644 Nargo.toml create mode 100644 README.md create mode 100644 release-please-config.json create mode 100755 scripts/build-gates-report.sh create mode 100644 src/lib.nr diff --git a/.github/NIGHTLY_CANARY_DIED.md b/.github/NIGHTLY_CANARY_DIED.md new file mode 100644 index 0000000..4b20ca0 --- /dev/null +++ b/.github/NIGHTLY_CANARY_DIED.md @@ -0,0 +1,7 @@ +--- +title: "Tests fail on latest Nargo nightly release" +--- + +The tests on this Noir project have started failing when using the latest nightly release of the Noir compiler. This likely means that there have been breaking changes for which this project needs to be updated to take into account. + +Check the [{{env.WORKFLOW_NAME}}]({{env.WORKFLOW_URL}}) workflow for details. \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 0000000..850ac38 --- /dev/null +++ b/.github/workflows/benchmark.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.34.0 + + - name: Install bb + run: | + npm install -g bbup + bbup -nv 0.34.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 }} diff --git a/.github/workflows/nightly-canary.yml b/.github/workflows/nightly-canary.yml new file mode 100644 index 0000000..4fd5ce1 --- /dev/null +++ b/.github/workflows/nightly-canary.yml @@ -0,0 +1,40 @@ +name: Noir Nightly Canary + +on: + schedule: + # Run a check at 9 AM UTC + - cron: "0 9 * * *" + +env: + CARGO_TERM_COLOR: always + +permissions: + issues: write + +jobs: + test: + name: Test on Nargo ${{matrix.toolchain}} + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install Nargo + uses: noir-lang/noirup@v0.1.3 + with: + toolchain: nightly + + - name: Run Noir tests + run: nargo test + + - name: Alert on dead links + uses: JasonEtco/create-an-issue@v2 + if: ${{ failure() }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WORKFLOW_NAME: ${{ github.workflow }} + WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + with: + update_existing: true + filename: .github/NIGHTLY_CANARY_DIED.md + \ No newline at end of file diff --git a/.github/workflows/pull-request-title.yml b/.github/workflows/pull-request-title.yml new file mode 100644 index 0000000..901d76a --- /dev/null +++ b/.github/workflows/pull-request-title.yml @@ -0,0 +1,30 @@ +name: Pull Request + +on: + merge_group: + pull_request_target: + types: + - opened + - reopened + - edited + - synchronize + +permissions: + pull-requests: read + +jobs: + conventional-title: + name: Validate PR title is Conventional Commit + runs-on: ubuntu-latest + steps: + - name: Check title + if: github.event_name == 'pull_request_target' + uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + types: | + fix + feat + chore + \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..cc4c323 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,21 @@ +name: Release + +on: + push: + branches: + - master + +jobs: + release-please: + name: Create Release + outputs: + release-pr: ${{ steps.release.outputs.pr }} + tag-name: ${{ steps.release.outputs.tag_name }} + runs-on: ubuntu-latest + steps: + - name: Run release-please + id: release + uses: google-github-actions/release-please-action@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + command: manifest \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1dec562 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,67 @@ +name: Noir tests + +on: + push: + branches: + - master + pull_request: + +env: + CARGO_TERM_COLOR: always + +jobs: + test: + name: Test on Nargo ${{matrix.toolchain}} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + toolchain: [nightly, 0.34.0] + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install Nargo + uses: noir-lang/noirup@v0.1.3 + with: + toolchain: ${{ matrix.toolchain }} + + - name: Run Noir tests + run: nargo test + + format: + 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.34.0 + + - name: Run formatter + run: nargo fmt --check + + # This is a job which depends on all test jobs and reports the overall status. + # This allows us to add/remove test jobs without having to update the required workflows. + tests-end: + name: Noir End + runs-on: ubuntu-latest + # We want this job to always run (even if the dependant jobs fail) as we want this job to fail rather than skipping. + if: ${{ always() }} + needs: + - test + - format + + steps: + - name: Report overall success + run: | + if [[ $FAIL == true ]]; then + exit 1 + else + exit 0 + fi + env: + # We treat any cancelled, skipped or failing jobs as a failure for the workflow as a whole. + FAIL: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4aacd17 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +target +export +gates_report.json diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..8d73c7b --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1 @@ +{".": "0.0.0"} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c61b663 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/Nargo.toml b/Nargo.toml new file mode 100644 index 0000000..ca37ec6 --- /dev/null +++ b/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "noir_library" +type = "lib" +authors = [""] +compiler_version = ">=0.34.0" + +[dependencies] diff --git a/README.md b/README.md new file mode 100644 index 0000000..7e63393 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# noir-library-starter + +This repository is a template used by the noir-lang org when creating internally maintained libraries. + +This provides out of the box: + +- A simple CI setup to test and format the library +- A canary flagging up compilation failures on nightly releases. +- A [release-please](https://github.com/googleapis/release-please) setup to ease creating releases for the library. + +Feel free to use this template as a starting point to create your own Noir libraries. + +--- + +# LIBRARY_NAME + +Add a brief description of the library + +## Noir version compatibility + +TODO: Update Noir version numbers tested compatible with + +This library is tested to work as of Noir version 1.0.0-beta.x. + +## Benchmarks + +TODO + + +## Installation + +In your _Nargo.toml_ file, add the version of this library you would like to install under dependency: + +``` +[dependencies] +LIBRARY = { tag = "v0.1.0", git = "https://github.com/noir-lang/LIBRARY_NAME" } +``` + +## `library` + +### Usage + +`PLACEHOLDER` diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..e33ce20 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,16 @@ +{ + "release-type": "simple", + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": true, + "pull-request-title-pattern": "chore: Release ${version}", + "group-pull-request-title-pattern": "chore: Release ${version}", + "packages": { + ".": { + "release-type": "simple", + "include-component-in-tag": false + } + }, + "plugins": [ + "sentence-case" + ] +} diff --git a/scripts/build-gates-report.sh b/scripts/build-gates-report.sh new file mode 100755 index 0000000..7e4b531 --- /dev/null +++ b/scripts/build-gates-report.sh @@ -0,0 +1,35 @@ +#!/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 + + diff --git a/src/lib.nr b/src/lib.nr new file mode 100644 index 0000000..80b968c --- /dev/null +++ b/src/lib.nr @@ -0,0 +1,15 @@ +/// This doesn't really do anything by ensures that there is a test for CI to run. +#[test] +fn smoke_test() { + assert(true); +} + +// This is an example benchmark. +// Changes to the number of constraints generated by this function will show in PRs. +#[export] +fn bench_test(mut x: Field) -> Field { + for _ in 0..100 { + x *= x; + } + x +}