diff --git a/.aztec-sync-commit b/.aztec-sync-commit new file mode 100644 index 00000000000..540b447693c --- /dev/null +++ b/.aztec-sync-commit @@ -0,0 +1 @@ +bb719200034e3bc6db09fb56538dadca4203abf4 diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 559b271bf38..00000000000 --- a/.dockerignore +++ /dev/null @@ -1,27 +0,0 @@ -Dockerfile* -.dockerignore - -# Yarn -.pnp.* -.yarn/* -!.yarn/patches -!.yarn/plugins -!.yarn/releases -!.yarn/sdks -!.yarn/versions - -packages -**/package.tgz -**/target -**/node_modules -**/outputs - -# Noir.js -tooling/noir_js/lib - -# Wasm build artifacts -compiler/wasm/nodejs -compiler/wasm/web -tooling/noirc_abi_wasm/nodejs -tooling/noirc_abi_wasm/web -tooling/noir_js/lib diff --git a/.envrc b/.envrc deleted file mode 100644 index b2f868b1898..00000000000 --- a/.envrc +++ /dev/null @@ -1,20 +0,0 @@ -# Based on https://github.com/direnv/direnv-vscode/blob/158e8302c2594cc0eaa5f8b4f0cafedd4e1c0315/.envrc - -# You can define your system-specific logic (like Git settings or GH tokens) in .envrc.local -# If that logic is usable by other people and might improve development environment, consider -# contributing it to this file! - -source_env_if_exists .envrc.local - -if [[ -z "${SKIP_NIX:-}" ]] && has nix; then - - if nix flake metadata &>/dev/null && has use_flake; then - # use flakes if possible - use flake - - else - # Otherwise fall back to pure nix - use nix - fi - -fi diff --git a/.github/ACVM_NOT_PUBLISHABLE.md b/.github/ACVM_NOT_PUBLISHABLE.md index e7eacb3b523..33230f8e8d8 100644 --- a/.github/ACVM_NOT_PUBLISHABLE.md +++ b/.github/ACVM_NOT_PUBLISHABLE.md @@ -1,9 +1,8 @@ --- title: "ACVM crates are not publishable" -assignees: TomAFrench kevaundray savio-sou +assignees: TomAFrench, Savio-Sou --- - The ACVM crates are currently unpublishable, making a release will NOT push our crates to crates.io. This is likely due to a crate we depend on bumping its MSRV above our own. Our lockfile is not taken into account when publishing to crates.io (as people downloading our crate don't use it) so we need to be able to use the most up to date versions of our dependencies (including transient dependencies) specified. diff --git a/.github/ACVM_PUBLISH_FAILED.md b/.github/ACVM_PUBLISH_FAILED.md new file mode 100644 index 00000000000..00e692a64d8 --- /dev/null +++ b/.github/ACVM_PUBLISH_FAILED.md @@ -0,0 +1,10 @@ +--- +title: "ACVM crates failed to publish" +assignees: TomAFrench, Savio-Sou +--- + +The {{env.CRATE_VERSION}} release of the ACVM crates failed. + +Check the [Publish ACVM crates]({{env.WORKFLOW_URL}}) workflow for details. + +This issue was raised by the workflow `{{env.WORKFLOW_NAME}}` diff --git a/.github/CRATES_IO_PUBLISH_FAILED.md b/.github/CRATES_IO_PUBLISH_FAILED.md index ec4de319772..5e2d4b7b77f 100644 --- a/.github/CRATES_IO_PUBLISH_FAILED.md +++ b/.github/CRATES_IO_PUBLISH_FAILED.md @@ -1,6 +1,6 @@ --- title: "ACVM crates failed to publish" -assignees: TomAFrench kevaundray savio-sou +assignees: TomAFrench, Savio-Sou --- The {{env.CRATE_VERSION}} release of the ACVM crates failed. diff --git a/.github/Cross.toml b/.github/Cross.toml index 09e6316a59c..d8516b9ae09 100644 --- a/.github/Cross.toml +++ b/.github/Cross.toml @@ -2,7 +2,6 @@ passthrough = [ "HOME", "RUST_BACKTRACE", - "BARRETENBERG_BIN_DIR" ] volumes = [ "HOME", diff --git a/.github/DEAD_LINKS_IN_DOCS.md b/.github/DEAD_LINKS_IN_DOCS.md index b1671276dcf..dcd4f44cdf2 100644 --- a/.github/DEAD_LINKS_IN_DOCS.md +++ b/.github/DEAD_LINKS_IN_DOCS.md @@ -1,6 +1,6 @@ --- title: "Docs contains dead links" -assignees: signorecello catmcgee critesjosh jzaki Savio-Sou +assignees: signorecello, catmcgee, critesjosh, jzaki, Savio-Sou labels: documentation --- diff --git a/.github/JS_PUBLISH_FAILED.md b/.github/JS_PUBLISH_FAILED.md index 5b9f79aac1f..f91af361d7d 100644 --- a/.github/JS_PUBLISH_FAILED.md +++ b/.github/JS_PUBLISH_FAILED.md @@ -1,6 +1,6 @@ --- title: "JS packages failed to publish" -assignees: TomAFrench kevaundray savio-sou +assignees: TomAFrench, Savio-Sou labels: js --- diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index e81ede7199d..dfb141e29f7 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -17,7 +17,7 @@ Resolves Check one: - [ ] No documentation needed. - [ ] Documentation included in this PR. -- [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. +- [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* diff --git a/.github/scripts/acvm_js-build.sh b/.github/scripts/acvm_js-build.sh index 95bd1efc8b9..e79967e3a8f 100755 --- a/.github/scripts/acvm_js-build.sh +++ b/.github/scripts/acvm_js-build.sh @@ -2,4 +2,5 @@ set -eu .github/scripts/wasm-bindgen-install.sh +.github/scripts/wasm-opt-install.sh yarn workspace @noir-lang/acvm_js build diff --git a/.github/scripts/noir-wasm-build.sh b/.github/scripts/noir-wasm-build.sh index f799387b6f6..6c0336ee0c5 100755 --- a/.github/scripts/noir-wasm-build.sh +++ b/.github/scripts/noir-wasm-build.sh @@ -2,4 +2,6 @@ set -eu .github/scripts/wasm-pack-install.sh +.github/scripts/wasm-opt-install.sh +yarn workspace @noir-lang/types build yarn workspace @noir-lang/noir_wasm build diff --git a/.github/scripts/noirc-abi-build.sh b/.github/scripts/noirc-abi-build.sh index 23b8393088e..99de474eb75 100755 --- a/.github/scripts/noirc-abi-build.sh +++ b/.github/scripts/noirc-abi-build.sh @@ -2,4 +2,5 @@ set -eu .github/scripts/wasm-bindgen-install.sh +.github/scripts/wasm-opt-install.sh yarn workspace @noir-lang/noirc_abi build diff --git a/.github/scripts/wasm-bindgen-install.sh b/.github/scripts/wasm-bindgen-install.sh index a548372ee2c..20908003693 100755 --- a/.github/scripts/wasm-bindgen-install.sh +++ b/.github/scripts/wasm-bindgen-install.sh @@ -6,7 +6,7 @@ cd $(dirname "$0") ./cargo-binstall-install.sh # Install wasm-bindgen-cli. -if [ "$(wasm-bindgen --version | cut -d' ' -f2)" != "0.2.86" ]; then +if [ "$(wasm-bindgen --version &> /dev/null | cut -d' ' -f2)" != "0.2.86" ]; then echo "Building wasm-bindgen..." cargo binstall wasm-bindgen-cli@0.2.86 --force --no-confirm fi diff --git a/.github/scripts/wasm-opt-install.sh b/.github/scripts/wasm-opt-install.sh index cbdeb8f2bfe..218778edac6 100755 --- a/.github/scripts/wasm-opt-install.sh +++ b/.github/scripts/wasm-opt-install.sh @@ -5,4 +5,4 @@ cd $(dirname "$0") ./cargo-binstall-install.sh -cargo-binstall wasm-opt --version 0.116.0 -y +cargo-binstall wasm-opt --version 0.116.0 -y --force diff --git a/.github/workflows/docker-test-flow.yml b/.github/workflows/docker-test-flow.yml deleted file mode 100644 index c8b4f53fadd..00000000000 --- a/.github/workflows/docker-test-flow.yml +++ /dev/null @@ -1,808 +0,0 @@ -name: Test Nargo and JS packages - -on: - push: - branches: - - 'master' - -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.ref || github.run_id }} - cancel-in-progress: true - -jobs: - build-base-nargo: - name: Build base nargo docker image - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Get current date - id: date - run: echo "date=$(date +'%Y.%m.%d.%H.%M')" >> $GITHUB_STATE - - name: prepare docker images tags - id: prep - run: | - REGISTRY="ghcr.io" - IMG_RAW="${REGISTRY}/${{ github.repository }}" - IMAGE=$(echo "$IMG_RAW" | tr '[:upper:]' '[:lower:]') - TAGS="${IMAGE}:${{ github.sha }}-nargo" - FULL_TAGS="${TAGS},${IMAGE}:latest-nargo,${IMAGE}:v${{ steps.date.outputs.date }}-nargo" - echo "tags=$FULL_TAGS" >> $GITHUB_OUTPUT - echo "image=$IMAGE" >> $GITHUB_OUTPUT - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v3 - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build nargo base dockerfile - uses: docker/build-push-action@v5 - with: - context: . - file: Dockerfile.ci - tags: ${{ steps.prep.outputs.tags }} - target: base-nargo - cache-from: type=gha - cache-to: type=gha,mode=max - push: true - - build-base-js: - name: Build base js docker image - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Get current date - id: date - run: echo "date=$(date +'%Y.%m.%d.%H.%M')" >> $GITHUB_STATE - - name: Prepare docker image tags - id: prep - run: | - REGISTRY="ghcr.io" - IMG_RAW="${REGISTRY}/${{ github.repository }}" - IMAGE=$(echo "$IMG_RAW" | tr '[:upper:]' '[:lower:]') - TAGS="${IMAGE}:${{ github.sha }}-js" - FULL_TAGS="${TAGS},${IMAGE}:latest-js,${IMAGE}:v${{ steps.date.outputs.date }}-js" - echo "tags=$FULL_TAGS" >> $GITHUB_OUTPUT - echo "image=$IMAGE" >> $GITHUB_OUTPUT - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v3 - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build js base dockerfile - uses: docker/build-push-action@v5 - with: - context: . - file: Dockerfile.ci - tags: ${{ steps.prep.outputs.tags }} - target: base-js - cache-from: type=gha - cache-to: type=gha,mode=max - push: true - - artifact-nargo: - name: Artifact nargo - runs-on: ubuntu-latest - needs: [build-base-nargo] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-nargo - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Artifact nargo - uses: actions/upload-artifact@v4 - with: - name: nargo - path: /usr/src/noir/target/release/nargo - if-no-files-found: error - compression-level: 0 - - test-nargo: - name: Test nargo - runs-on: ubuntu-latest - needs: [build-base-nargo] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-nargo - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Test - working-directory: /usr/src/noir - run: | - .github/scripts/nargo-test.sh - - build-noir-wasm: - name: Build noir wasm - runs-on: ubuntu-latest - needs: [build-base-js, build-noirc-abi] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download noirc abi - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: | - /usr/src/noir/tooling/noirc_abi_wasm - - name: Build - working-directory: /usr/src/noir - run: | - ./.github/scripts/noir-wasm-build.sh - - name: Artifact - uses: actions/upload-artifact@v4 - with: - name: noir_wasm - path: /usr/src/noir/compiler/wasm - retention-days: 10 - - test-noir-wasm: - name: Test noir wasm - runs-on: ubuntu-latest - needs: [build-base-js, artifact-nargo, build-noir-wasm] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download nargo - uses: actions/download-artifact@v4 - with: - name: nargo - path: /usr/src/noir/target/release - - name: Prep downloaded artifact - run: | - chmod +x /usr/src/noir/target/release/nargo - - name: Download noirc abi - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: | - /usr/src/noir/tooling/noirc_abi_wasm - - name: Download noir_wasm artifact - uses: actions/download-artifact@v4 - with: - name: noir_wasm - path: /usr/src/noir/compiler/wasm - - name: Test - working-directory: /usr/src/noir - run: | - ./.github/scripts/noir-wasm-test.sh - - test-noir-wasm-browser: - name: Test noir wasm browser - runs-on: ubuntu-latest - needs: [build-base-js, artifact-nargo, build-noir-wasm] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download nargo - uses: actions/download-artifact@v4 - with: - name: nargo - path: /usr/src/noir/target/release - - name: Prep downloaded artifact - run: | - chmod +x /usr/src/noir/target/release/nargo - - name: Download noirc abi - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: | - /usr/src/noir/tooling/noirc_abi_wasm - - name: Download noir_wasm artifact - uses: actions/download-artifact@v4 - with: - name: noir_wasm - path: /usr/src/noir/compiler/wasm - - name: Test - working-directory: /usr/src/noir - run: | - ./.github/scripts/noir-wasm-test-browser.sh - - build-acvm_js: - name: Build acvm js - runs-on: ubuntu-latest - needs: [build-base-js] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Build - working-directory: /usr/src/noir - run: | - ./.github/scripts/acvm_js-build.sh - - name: Artifact - uses: actions/upload-artifact@v4 - with: - name: acvm_js - path: - /usr/src/noir/acvm-repo/acvm_js/outputs/out/acvm_js - if-no-files-found: error - compression-level: 0 - - test-acvm_js: - name: Test acvm js - runs-on: ubuntu-latest - needs: [build-base-js, build-acvm_js] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download acvm js - uses: actions/download-artifact@v4 - with: - name: acvm_js - path: | - /usr/src/noir/acvm-repo/acvm_js - - name: Test - working-directory: /usr/src/noir - run: | - ./.github/scripts/acvm_js-test.sh - - test-acvm_js-browser: - name: Test acvm js browser - runs-on: ubuntu-latest - needs: [build-base-js, build-acvm_js] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download acvm js - uses: actions/download-artifact@v4 - with: - name: acvm_js - path: | - /usr/src/noir/acvm-repo/acvm_js - - name: Test - working-directory: /usr/src/noir - run: | - ./.github/scripts/acvm_js-test-browser.sh - - build-noirc-abi: - name: Build noirc abi - runs-on: ubuntu-latest - needs: [build-base-js] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Build - working-directory: /usr/src/noir - run: | - ./.github/scripts/noirc-abi-build.sh - - name: Artifact - uses: actions/upload-artifact@v4 - with: - name: noirc_abi_wasm - path: - /usr/src/noir/tooling/noirc_abi_wasm/outputs/out/noirc_abi_wasm - if-no-files-found: error - compression-level: 0 - - test-noirc-abi: - name: Test noirc abi - runs-on: ubuntu-latest - needs: [build-base-js, build-noirc-abi] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download noirc abi - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: | - /usr/src/noir/tooling/noirc_abi_wasm - - name: Test - working-directory: /usr/src/noir - run: | - ./.github/scripts/noirc-abi-test.sh - - test-noirc-abi-browser: - name: Test noirc abi browser - runs-on: ubuntu-latest - needs: [build-base-js, build-noirc-abi] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download noirc abi - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: | - /usr/src/noir/tooling/noirc_abi_wasm - - name: Test - working-directory: /usr/src/noir - run: | - ./.github/scripts/noirc-abi-test-browser.sh - - build-noir-js-types: - name: Build noir js types - runs-on: ubuntu-latest - needs: [build-base-js, build-noirc-abi] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download noirc abi - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: | - /usr/src/noir/tooling/noirc_abi_wasm - - name: Build - working-directory: /usr/src/noir - run: | - ./.github/scripts/noir-js-types-build.sh - - name: Artifact - uses: actions/upload-artifact@v4 - with: - name: noir-js-types - path: | - /usr/src/noir/tooling/noir_js_types/lib - if-no-files-found: error - compression-level: 0 - - build-barretenberg-backend: - name: Build Barretenberg backend - runs-on: ubuntu-latest - needs: [build-base-js, build-noirc-abi, build-noir-js-types] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download noirc abi - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: | - /usr/src/noir/tooling/noirc_abi_wasm - - name: Download noir js types - uses: actions/download-artifact@v4 - with: - name: noir-js-types - path: /usr/src/noir/tooling/noir_js_types/lib/ - - name: Build - working-directory: /usr/src/noir - run: | - ./.github/scripts/backend-barretenberg-build.sh - - name: Artifact - uses: actions/upload-artifact@v4 - with: - name: barretenberg-backend - path: - /usr/src/noir/tooling/noir_js_backend_barretenberg/lib - if-no-files-found: error - compression-level: 0 - - test-barretenberg-backend: - name: Test Barretenberg backend - runs-on: ubuntu-latest - needs: [build-base-js, build-noirc-abi, build-noir-js-types, build-barretenberg-backend] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download artifact - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: | - /usr/src/noir/tooling/noirc_abi_wasm - - name: Download noir js types - uses: actions/download-artifact@v4 - with: - name: noir-js-types - path: /usr/src/noir/tooling/noir_js_types/lib/ - - name: Download Backend barretenberg - uses: actions/download-artifact@v4 - with: - name: barretenberg-backend - path: - /usr/src/noir/tooling/noir_js_backend_barretenberg/lib - - name: Test - working-directory: /usr/src/noir - run: | - ./.github/scripts/backend-barretenberg-test.sh - - build-noir_js: - name: Build noirjs - runs-on: ubuntu-latest - needs: [build-base-js, artifact-nargo, build-noirc-abi, build-acvm_js, build-barretenberg-backend, build-noir-js-types] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download nargo - uses: actions/download-artifact@v4 - with: - name: nargo - path: /usr/src/noir/target/release - - name: prep downloaded artifact - run: | - chmod +x /usr/src/noir/target/release/nargo - - name: Download noirc abi - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: | - /usr/src/noir/tooling/noirc_abi_wasm - - name: Download acvm js - uses: actions/download-artifact@v4 - with: - name: acvm_js - path: | - /usr/src/noir/acvm-repo/acvm_js - - name: Download Barretenberg backend - uses: actions/download-artifact@v4 - with: - name: barretenberg-backend - path: - /usr/src/noir/tooling/noir_js_backend_barretenberg/lib - - name: Download noir js types - uses: actions/download-artifact@v4 - with: - name: noir-js-types - path: | - /usr/src/noir/tooling/noir_js_types/lib - - name: Build - working-directory: /usr/src/noir - run: | - ./.github/scripts/noir-js-build.sh - - name: Artifact - uses: actions/upload-artifact@v4 - with: - name: noir_js - path: - /usr/src/noir/tooling/noir_js/lib - - test-noir_js: - name: Test noirjs - runs-on: ubuntu-latest - needs: [ - build-base-js, - build-noirc-abi, - artifact-nargo, - build-acvm_js, - build-barretenberg-backend, - build-noir_js, - build-noir-js-types - ] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download nargo - uses: actions/download-artifact@v4 - with: - name: nargo - path: /usr/src/noir/target/release - - name: Prep downloaded artifact - run: | - chmod +x /usr/src/noir/target/release/nargo - - name: Download noirc abi - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: | - /usr/src/noir/tooling/noirc_abi_wasm - - name: Download acvm js - uses: actions/download-artifact@v4 - with: - name: acvm_js - path: | - /usr/src/noir/acvm-repo/acvm_js - - name: Download Barretenberg backend - uses: actions/download-artifact@v4 - with: - name: barretenberg-backend - path: - /usr/src/noir/tooling/noir_js_backend_barretenberg/lib - - name: Download noir js types - uses: actions/download-artifact@v4 - with: - name: noir-js-types - path: | - /usr/src/noir/tooling/noir_js_types/lib - - name: Download noir js - uses: actions/download-artifact@v4 - with: - name: noir_js - path: - /usr/src/noir/tooling/noir_js/lib - - name: Test - working-directory: /usr/src/noir - run: | - ./.github/scripts/noir-js-test.sh - - build-noir_codegen: - name: Build noir codegen - runs-on: ubuntu-latest - needs: [build-base-js, build-noirc-abi, build-acvm_js, build-noir-js-types, build-noir_js] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download nargo - uses: actions/download-artifact@v4 - with: - name: nargo - path: /usr/src/noir/target/release - - name: Prep downloaded artifact - run: | - chmod +x /usr/src/noir/target/release/nargo - - name: Download noirc abi package - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: /usr/src/noir/tooling/noirc_abi_wasm - - name: Download acvm js - uses: actions/download-artifact@v4 - with: - name: acvm_js - path: /usr/src/noir/acvm-repo/acvm_js - - name: Download noir js types - uses: actions/download-artifact@v4 - with: - name: noir-js-types - path: | - /usr/src/noir/tooling/noir_js_types/lib - - name: Download noir js - uses: actions/download-artifact@v4 - with: - name: noir_js - path: - /usr/src/noir/tooling/noir_js/lib - - name: Build - working-directory: /usr/src/noir - run: | - ./.github/scripts/noir-codegen-build.sh - - name: Artifact - uses: actions/upload-artifact@v4 - with: - name: noir_codegen - path: - /usr/src/noir/tooling/noir_codegen/lib - - test-noir_codegen: - name: Test noir codegen - runs-on: ubuntu-latest - needs: [build-base-js, artifact-nargo, build-noirc-abi, build-acvm_js, build-noir-js-types, build-noir_js, build-noir_codegen] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download nargo - uses: actions/download-artifact@v4 - with: - name: nargo - path: /usr/src/noir/target/release - - name: Prep downloaded artifact - run: | - chmod +x /usr/src/noir/target/release/nargo - - name: Download noirc abi - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: /usr/src/noir/tooling/noirc_abi_wasm - - name: Download acvm js - uses: actions/download-artifact@v4 - with: - name: acvm_js - path: /usr/src/noir/acvm-repo/acvm_js - - name: Download noir js types - uses: actions/download-artifact@v4 - with: - name: noir-js-types - path: | - /usr/src/noir/tooling/noir_js_types/lib - - name: Download noir js - uses: actions/download-artifact@v4 - with: - name: noir_js - path: - /usr/src/noir/tooling/noir_js/lib - - name: Download noir codegen - uses: actions/download-artifact@v4 - with: - name: noir_codegen - path: - /usr/src/noir/tooling/noir_codegen/lib - - name: Test - working-directory: /usr/src/noir - run: | - ./.github/scripts/noir-codegen-test.sh - - test-integration: - name: Integration test - runs-on: ubuntu-latest - needs: [ - build-base-js, - artifact-nargo, - build-noir-wasm, - build-noirc-abi, - build-acvm_js, - build-noir-js-types, - build-noir_js, - build-barretenberg-backend - ] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download nargo - uses: actions/download-artifact@v4 - with: - name: nargo - path: /usr/src/noir/target/release - - name: Prep downloaded artifact - run: | - chmod +x /usr/src/noir/target/release/nargo - - name: Download noir wasm - uses: actions/download-artifact@v4 - with: - name: noir_wasm - path: /usr/src/noir/compiler/wasm - - name: Download noirc abi - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: /usr/src/noir/tooling/noirc_abi_wasm - - name: Download acvm js - uses: actions/download-artifact@v4 - with: - name: acvm_js - path: /usr/src/noir/acvm-repo/acvm_js - - name: Download noir js types - uses: actions/download-artifact@v4 - with: - name: noir-js-types - path: | - /usr/src/noir/tooling/noir_js_types/lib - - name: Download noir js - uses: actions/download-artifact@v4 - with: - name: noir_js - path: - /usr/src/noir/tooling/noir_js/lib - - name: Download Barretenberg backend - uses: actions/download-artifact@v4 - with: - name: barretenberg-backend - path: - /usr/src/noir/tooling/noir_js_backend_barretenberg/lib - - name: Test - working-directory: /usr/src/noir - run: | - ./.github/scripts/integration-test-node.sh - - test-integration-browser: - name: Integration test browser - runs-on: ubuntu-latest - needs: [ - build-base-js, - build-noir-wasm, - build-noirc-abi, - build-acvm_js, - build-noir-js-types, - build-noir_js, - build-barretenberg-backend - ] - container: - image: ghcr.io/noir-lang/noir:${{ github.sha }}-js - credentials: - username: ${{ github.actor }} - password: ${{ secrets.github_token }} - steps: - - name: Download noir wasm - uses: actions/download-artifact@v4 - with: - name: noir_wasm - path: /usr/src/noir/compiler/wasm - - name: Download noirc abi - uses: actions/download-artifact@v4 - with: - name: noirc_abi_wasm - path: /usr/src/noir/tooling/noirc_abi_wasm - - name: Download acvm js - uses: actions/download-artifact@v4 - with: - name: acvm_js - path: /usr/src/noir/acvm-repo/acvm_js - - name: Download noir js types - uses: actions/download-artifact@v4 - with: - name: noir-js-types - path: | - /usr/src/noir/tooling/noir_js_types/lib - - name: Download noir js - uses: actions/download-artifact@v4 - with: - name: noir_js - path: - /usr/src/noir/tooling/noir_js/lib - - name: Download Barretenberg backend - uses: actions/download-artifact@v4 - with: - name: barretenberg-backend - path: - /usr/src/noir/tooling/noir_js_backend_barretenberg/lib - - name: Test - working-directory: /usr/src/noir - run: | - ./.github/scripts/integration-test-browser.sh - - tests-end: - name: End - runs-on: ubuntu-latest - if: ${{ always() }} - needs: - - test-nargo - - test-noirc-abi - - test-noirc-abi-browser - - test-noir-wasm - - test-noir-wasm-browser - - test-integration - - test-integration-browser - - test-noir_codegen - - test-acvm_js - - test-acvm_js-browser - - test-barretenberg-backend - - test-noir_js - - steps: - - name: Report overall success - run: | - if [[ $FAIL == true ]]; then - exit 1 - else - exit 0 - fi - env: - FAIL: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }} diff --git a/.github/workflows/docs-pr.yml b/.github/workflows/docs-pr.yml index 5d0b72c6ad8..1f9ccdd946b 100644 --- a/.github/workflows/docs-pr.yml +++ b/.github/workflows/docs-pr.yml @@ -75,9 +75,11 @@ jobs: run: | npm i wasm-opt -g + - name: Query active docs versions + run: yarn workspace docs version::stables + - name: Build docs - run: - yarn workspaces foreach -Rpt --from docs run build + run: yarn workspaces foreach -Rpt --from docs run build - name: Upload artifact uses: actions/upload-artifact@v4 @@ -126,4 +128,4 @@ jobs: with: message: | FYI @noir-lang/developerrelations on Noir doc changes. - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/gates_report.yml b/.github/workflows/gates_report.yml index f3f798fc5ea..ebf17f7374c 100644 --- a/.github/workflows/gates_report.yml +++ b/.github/workflows/gates_report.yml @@ -74,7 +74,7 @@ jobs: - name: Compare gates reports id: gates_diff - uses: TomAFrench/noir-gates-diff@e7cf131b7e7f044c01615f93f0b855f65ddc02d4 + uses: TomAFrench/noir-gates-diff@df05f34e2ab275ddc4f2cac065df1c88f8a05e5d with: report: gates_report.json summaryQuantile: 0.9 # only display the 10% most significant circuit size diffs in the summary (defaults to 20%) diff --git a/.github/workflows/publish-acvm.yml b/.github/workflows/publish-acvm.yml index 959cd8e4bca..d17d8f294fb 100644 --- a/.github/workflows/publish-acvm.yml +++ b/.github/workflows/publish-acvm.yml @@ -74,4 +74,4 @@ jobs: WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} with: update_existing: true - filename: .github/JS_PUBLISH_FAILED.md \ No newline at end of file + filename: .github/ACVM_PUBLISH_FAILED.md \ No newline at end of file diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index a56583b34eb..8896e613608 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -28,10 +28,11 @@ jobs: run: | npm i wasm-opt -g + - name: Query active docs versions + run: yarn workspace docs version::stables + - name: Build docs for deploying - working-directory: docs - run: - yarn workspaces foreach -Rt run build + run: yarn workspaces foreach -Rpt --from docs run build - name: Deploy to Netlify uses: nwtgck/actions-netlify@v2.1 diff --git a/.github/workflows/publish-es-packages.yml b/.github/workflows/publish-es-packages.yml index f72a97b2684..819be308169 100644 --- a/.github/workflows/publish-es-packages.yml +++ b/.github/workflows/publish-es-packages.yml @@ -20,7 +20,9 @@ jobs: steps: - name: Checkout Noir repo uses: actions/checkout@v4 - + with: + ref: ${{ inputs.noir-ref }} + - name: Setup toolchain uses: dtolnay/rust-toolchain@1.73.0 @@ -42,7 +44,9 @@ jobs: uses: actions/upload-artifact@v4 with: name: noirc_abi_wasm - path: ./tooling/noirc_abi_wasm/outputs/out/noirc_abi_wasm + path: | + ./tooling/noirc_abi_wasm/nodejs + ./tooling/noirc_abi_wasm/web retention-days: 10 build-noir_wasm: @@ -87,6 +91,8 @@ jobs: steps: - name: Checkout sources uses: actions/checkout@v4 + with: + ref: ${{ inputs.noir-ref }} - name: Setup toolchain uses: dtolnay/rust-toolchain@1.73.0 @@ -109,7 +115,9 @@ jobs: uses: actions/upload-artifact@v4 with: name: acvm-js - path: ./acvm-repo/acvm_js/outputs/out/acvm_js + path: | + ./acvm-repo/acvm_js/nodejs + ./acvm-repo/acvm_js/web retention-days: 3 publish-es-packages: @@ -164,4 +172,4 @@ jobs: WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} with: update_existing: true - filename: .github/JS_PUBLISH_FAILED.md \ No newline at end of file + filename: .github/JS_PUBLISH_FAILED.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 83e8e479181..d27fac0e039 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -79,6 +79,15 @@ jobs: - name: Install Yarn dependencies uses: ./.github/actions/setup + - name: Install wasm-bindgen-cli + uses: taiki-e/install-action@v2 + with: + tool: wasm-bindgen-cli@0.2.86 + + - name: Install wasm-opt + run: | + npm i wasm-opt -g + - name: Query new noir version id: noir-version run: | @@ -100,6 +109,39 @@ jobs: git commit -m "chore(docs): cut new docs version for tag ${{ steps.noir-version.outputs.semver }}" git push + release-end: + name: Release End + runs-on: ubuntu-latest + # We want this job to always run (even if the dependant jobs fail) as we need apply changes to the sticky comment. + if: ${{ always() }} + + needs: + - release-please + - update-acvm-workspace-package-versions + - update-docs + + env: + # We treat any 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') }} + + steps: + - name: Add warning to sticky comment + uses: marocchino/sticky-pull-request-comment@v2 + with: + # We need to specify the PR on which to make the comment as workflow is triggered by push. + number: ${{ fromJSON(needs.release-please.outputs.release-pr).number }} + # delete the comment in case failures have been fixed + delete: ${{ env.FAIL == false }} + message: "The release workflow has not completed successfully. Releasing now will result in a broken release" + + - name: Report overall success + run: | + if [[ $FAIL == true ]]; then + exit 1 + else + exit 0 + fi + build-binaries: name: Build binaries needs: [release-please] diff --git a/.github/workflows/test-js-packages.yml b/.github/workflows/test-js-packages.yml index b3908ee5d3e..06a96ee8932 100644 --- a/.github/workflows/test-js-packages.yml +++ b/.github/workflows/test-js-packages.yml @@ -66,9 +66,6 @@ jobs: - name: Install Yarn dependencies uses: ./.github/actions/setup - - name: Install wasm-opt - run: ./.github/scripts/wasm-opt-install.sh - - name: Build noirc_abi run: ./.github/scripts/noirc-abi-build.sh @@ -76,7 +73,9 @@ jobs: uses: actions/upload-artifact@v4 with: name: noirc_abi_wasm - path: ./tooling/noirc_abi_wasm/outputs/out/noirc_abi_wasm + path: | + ./tooling/noirc_abi_wasm/nodejs + ./tooling/noirc_abi_wasm/web retention-days: 10 @@ -100,9 +99,6 @@ jobs: - name: Install Yarn dependencies uses: ./.github/actions/setup - - name: Install wasm-opt - run: ./.github/scripts/wasm-opt-install.sh - - name: Build noir_js_types run: yarn workspace @noir-lang/types build @@ -138,9 +134,6 @@ jobs: - name: Install Yarn dependencies uses: ./.github/actions/setup - - name: Install wasm-opt - run: ./.github/scripts/wasm-opt-install.sh - - name: Build acvm_js run: ./.github/scripts/acvm_js-build.sh @@ -148,7 +141,9 @@ jobs: uses: actions/upload-artifact@v4 with: name: acvm-js - path: ./acvm-repo/acvm_js/outputs/out/acvm_js + path: | + ./acvm-repo/acvm_js/nodejs + ./acvm-repo/acvm_js/web retention-days: 3 test-acvm_js-node: diff --git a/.gitignore b/.gitignore index 8d02d34d463..9a829afab8b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,12 +17,6 @@ pkg/ # Noir.js tooling/noir_js/lib -# Nix stuff -**/outputs -result -.envrc.local -.direnv/ - # Nargo output *.proof *.acir @@ -50,8 +44,5 @@ tooling/noirc_abi_wasm/nodejs tooling/noirc_abi_wasm/web tooling/noir_js/lib -**/package.tgz -packages - # docs autogen build /docs/docs/noir_js/reference/ diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 8916585d7f1..d4cc095c484 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,4 +1,4 @@ { - ".": "0.24.0", - "acvm-repo": "0.40.0" + ".": "0.26.0", + "acvm-repo": "0.42.0" } \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 1fb1def7ce1..efb17cb0085 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -4,7 +4,6 @@ // List of extensions which should be recommended for users of this workspace. "recommendations": [ "mkhl.direnv", - "jnoortheen.nix-ide", "rust-lang.rust-analyzer", "redhat.vscode-yaml", "esbenp.prettier-vscode", diff --git a/.vscode/settings.json b/.vscode/settings.json index 171d36f4e04..fb8ea527881 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,17 +2,6 @@ "direnv.restart.automatic": true, "redhat.telemetry.enabled": false, "yaml.recommendations.show": false, - "nix.serverPath": "nil", - "nix.enableLanguageServer": true, - "nix.serverSettings": { - "nil": { - "formatting": { - "command": [ - "nixpkgs-fmt" - ] - } - } - }, "yaml.schemas": { "https://json.schemastore.org/github-workflow.json": "${workspaceRoot}/.github/workflows/*.yml" }, diff --git a/.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs b/.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs new file mode 100644 index 00000000000..bc2ca19f116 --- /dev/null +++ b/.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs @@ -0,0 +1,541 @@ +/* eslint-disable */ +//prettier-ignore +module.exports = { +name: "@yarnpkg/plugin-interactive-tools", +factory: function (require) { +var plugin=(()=>{var bF=Object.create;var D_=Object.defineProperty;var BF=Object.getOwnPropertyDescriptor;var UF=Object.getOwnPropertyNames;var jF=Object.getPrototypeOf,zF=Object.prototype.hasOwnProperty;var hi=(o=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(o,{get:(l,f)=>(typeof require<"u"?require:l)[f]}):o)(function(o){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+o+'" is not supported')});var nt=(o,l)=>()=>(l||o((l={exports:{}}).exports,l),l.exports),HF=(o,l)=>{for(var f in l)D_(o,f,{get:l[f],enumerable:!0})},j8=(o,l,f,h)=>{if(l&&typeof l=="object"||typeof l=="function")for(let E of UF(l))!zF.call(o,E)&&E!==f&&D_(o,E,{get:()=>l[E],enumerable:!(h=BF(l,E))||h.enumerable});return o};var V0=(o,l,f)=>(f=o!=null?bF(jF(o)):{},j8(l||!o||!o.__esModule?D_(f,"default",{value:o,enumerable:!0}):f,o)),qF=o=>j8(D_({},"__esModule",{value:!0}),o);var Py=nt((Xz,H8)=>{"use strict";var z8=Object.getOwnPropertySymbols,WF=Object.prototype.hasOwnProperty,VF=Object.prototype.propertyIsEnumerable;function GF(o){if(o==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(o)}function YF(){try{if(!Object.assign)return!1;var o=new String("abc");if(o[5]="de",Object.getOwnPropertyNames(o)[0]==="5")return!1;for(var l={},f=0;f<10;f++)l["_"+String.fromCharCode(f)]=f;var h=Object.getOwnPropertyNames(l).map(function(t){return l[t]});if(h.join("")!=="0123456789")return!1;var E={};return"abcdefghijklmnopqrst".split("").forEach(function(t){E[t]=t}),Object.keys(Object.assign({},E)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}H8.exports=YF()?Object.assign:function(o,l){for(var f,h=GF(o),E,t=1;t{"use strict";var qE=Py(),Zf=typeof Symbol=="function"&&Symbol.for,Iy=Zf?Symbol.for("react.element"):60103,KF=Zf?Symbol.for("react.portal"):60106,XF=Zf?Symbol.for("react.fragment"):60107,QF=Zf?Symbol.for("react.strict_mode"):60108,JF=Zf?Symbol.for("react.profiler"):60114,ZF=Zf?Symbol.for("react.provider"):60109,$F=Zf?Symbol.for("react.context"):60110,eP=Zf?Symbol.for("react.forward_ref"):60112,tP=Zf?Symbol.for("react.suspense"):60113,nP=Zf?Symbol.for("react.memo"):60115,rP=Zf?Symbol.for("react.lazy"):60116,q8=typeof Symbol=="function"&&Symbol.iterator;function by(o){for(var l="https://reactjs.org/docs/error-decoder.html?invariant="+o,f=1;fw_.length&&w_.push(o)}function jE(o,l,f,h){var E=typeof o;(E==="undefined"||E==="boolean")&&(o=null);var t=!1;if(o===null)t=!0;else switch(E){case"string":case"number":t=!0;break;case"object":switch(o.$$typeof){case Iy:case KF:t=!0}}if(t)return f(h,o,l===""?"."+UE(o,0):l),1;if(t=0,l=l===""?".":l+":",Array.isArray(o))for(var N=0;N{"use strict";var aP="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";tS.exports=aP});var XE=nt((Zz,oS)=>{"use strict";var KE=function(){};process.env.NODE_ENV!=="production"&&(rS=nS(),S_={},iS=Function.call.bind(Object.prototype.hasOwnProperty),KE=function(o){var l="Warning: "+o;typeof console<"u"&&console.error(l);try{throw new Error(l)}catch{}});var rS,S_,iS;function uS(o,l,f,h,E){if(process.env.NODE_ENV!=="production"){for(var t in o)if(iS(o,t)){var N;try{if(typeof o[t]!="function"){var F=Error((h||"React class")+": "+f+" type `"+t+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof o[t]+"`.");throw F.name="Invariant Violation",F}N=o[t](l,t,h,f,null,rS)}catch(x){N=x}if(N&&!(N instanceof Error)&&KE((h||"React class")+": type specification of "+f+" `"+t+"` is invalid; the type checker function must return `null` or an `Error` but returned a "+typeof N+". You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument)."),N instanceof Error&&!(N.message in S_)){S_[N.message]=!0;var k=E?E():"";KE("Failed "+f+" type: "+N.message+(k!=null?k:""))}}}}uS.resetWarningCache=function(){process.env.NODE_ENV!=="production"&&(S_={})};oS.exports=uS});var lS=nt(_u=>{"use strict";process.env.NODE_ENV!=="production"&&function(){"use strict";var o=Py(),l=XE(),f="16.13.1",h=typeof Symbol=="function"&&Symbol.for,E=h?Symbol.for("react.element"):60103,t=h?Symbol.for("react.portal"):60106,N=h?Symbol.for("react.fragment"):60107,F=h?Symbol.for("react.strict_mode"):60108,k=h?Symbol.for("react.profiler"):60114,x=h?Symbol.for("react.provider"):60109,j=h?Symbol.for("react.context"):60110,q=h?Symbol.for("react.concurrent_mode"):60111,V=h?Symbol.for("react.forward_ref"):60112,re=h?Symbol.for("react.suspense"):60113,y=h?Symbol.for("react.suspense_list"):60120,me=h?Symbol.for("react.memo"):60115,De=h?Symbol.for("react.lazy"):60116,ge=h?Symbol.for("react.block"):60121,ae=h?Symbol.for("react.fundamental"):60117,we=h?Symbol.for("react.responder"):60118,he=h?Symbol.for("react.scope"):60119,ve=typeof Symbol=="function"&&Symbol.iterator,ue="@@iterator";function Ae(Q){if(Q===null||typeof Q!="object")return null;var Se=ve&&Q[ve]||Q[ue];return typeof Se=="function"?Se:null}var ze={current:null},We={suspense:null},gt={current:null},_t=/^(.*)[\\\/]/;function Qe(Q,Se,Fe){var Le="";if(Se){var pt=Se.fileName,Yn=pt.replace(_t,"");if(/^index\./.test(Yn)){var Cn=pt.match(_t);if(Cn){var cr=Cn[1];if(cr){var Si=cr.replace(_t,"");Yn=Si+"/"+Yn}}}Le=" (at "+Yn+":"+Se.lineNumber+")"}else Fe&&(Le=" (created by "+Fe+")");return` + in `+(Q||"Unknown")+Le}var ot=1;function Ve(Q){return Q._status===ot?Q._result:null}function Pt(Q,Se,Fe){var Le=Se.displayName||Se.name||"";return Q.displayName||(Le!==""?Fe+"("+Le+")":Fe)}function Jt(Q){if(Q==null)return null;if(typeof Q.tag=="number"&&dt("Received an unexpected object in getComponentName(). This is likely a bug in React. Please file an issue."),typeof Q=="function")return Q.displayName||Q.name||null;if(typeof Q=="string")return Q;switch(Q){case N:return"Fragment";case t:return"Portal";case k:return"Profiler";case F:return"StrictMode";case re:return"Suspense";case y:return"SuspenseList"}if(typeof Q=="object")switch(Q.$$typeof){case j:return"Context.Consumer";case x:return"Context.Provider";case V:return Pt(Q,Q.render,"ForwardRef");case me:return Jt(Q.type);case ge:return Jt(Q.render);case De:{var Se=Q,Fe=Ve(Se);if(Fe)return Jt(Fe);break}}return null}var it={},J=null;function ce(Q){J=Q}it.getCurrentStack=null,it.getStackAddendum=function(){var Q="";if(J){var Se=Jt(J.type),Fe=J._owner;Q+=Qe(Se,J._source,Fe&&Jt(Fe.type))}var Le=it.getCurrentStack;return Le&&(Q+=Le()||""),Q};var Re={current:!1},le={ReactCurrentDispatcher:ze,ReactCurrentBatchConfig:We,ReactCurrentOwner:gt,IsSomeRendererActing:Re,assign:o};o(le,{ReactDebugCurrentFrame:it,ReactComponentTreeHook:{}});function He(Q){{for(var Se=arguments.length,Fe=new Array(Se>1?Se-1:0),Le=1;Le1?Se-1:0),Le=1;Le0&&typeof Fe[Fe.length-1]=="string"&&Fe[Fe.length-1].indexOf(` + in`)===0;if(!Le){var pt=le.ReactDebugCurrentFrame,Yn=pt.getStackAddendum();Yn!==""&&(Se+="%s",Fe=Fe.concat([Yn]))}var Cn=Fe.map(function(Ou){return""+Ou});Cn.unshift("Warning: "+Se),Function.prototype.apply.call(console[Q],console,Cn);try{var cr=0,Si="Warning: "+Se.replace(/%s/g,function(){return Fe[cr++]});throw new Error(Si)}catch{}}}var nn={};function an(Q,Se){{var Fe=Q.constructor,Le=Fe&&(Fe.displayName||Fe.name)||"ReactClass",pt=Le+"."+Se;if(nn[pt])return;dt("Can't call %s on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to `this.state` directly or define a `state = {};` class property with the desired state in the %s component.",Se,Le),nn[pt]=!0}}var On={isMounted:function(Q){return!1},enqueueForceUpdate:function(Q,Se,Fe){an(Q,"forceUpdate")},enqueueReplaceState:function(Q,Se,Fe,Le){an(Q,"replaceState")},enqueueSetState:function(Q,Se,Fe,Le){an(Q,"setState")}},lr={};Object.freeze(lr);function ln(Q,Se,Fe){this.props=Q,this.context=Se,this.refs=lr,this.updater=Fe||On}ln.prototype.isReactComponent={},ln.prototype.setState=function(Q,Se){if(!(typeof Q=="object"||typeof Q=="function"||Q==null))throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,Q,Se,"setState")},ln.prototype.forceUpdate=function(Q){this.updater.enqueueForceUpdate(this,Q,"forceUpdate")};{var Vt={isMounted:["isMounted","Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks."],replaceState:["replaceState","Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236)."]},Er=function(Q,Se){Object.defineProperty(ln.prototype,Q,{get:function(){He("%s(...) is deprecated in plain JavaScript React classes. %s",Se[0],Se[1])}})};for(var S in Vt)Vt.hasOwnProperty(S)&&Er(S,Vt[S])}function zt(){}zt.prototype=ln.prototype;function Xn(Q,Se,Fe){this.props=Q,this.context=Se,this.refs=lr,this.updater=Fe||On}var vr=Xn.prototype=new zt;vr.constructor=Xn,o(vr,ln.prototype),vr.isPureReactComponent=!0;function jr(){var Q={current:null};return Object.seal(Q),Q}var fr=Object.prototype.hasOwnProperty,zr={key:!0,ref:!0,__self:!0,__source:!0},Xt,Du,c0;c0={};function Ao(Q){if(fr.call(Q,"ref")){var Se=Object.getOwnPropertyDescriptor(Q,"ref").get;if(Se&&Se.isReactWarning)return!1}return Q.ref!==void 0}function Jo(Q){if(fr.call(Q,"key")){var Se=Object.getOwnPropertyDescriptor(Q,"key").get;if(Se&&Se.isReactWarning)return!1}return Q.key!==void 0}function Fs(Q,Se){var Fe=function(){Xt||(Xt=!0,dt("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://fb.me/react-special-props)",Se))};Fe.isReactWarning=!0,Object.defineProperty(Q,"key",{get:Fe,configurable:!0})}function Zo(Q,Se){var Fe=function(){Du||(Du=!0,dt("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://fb.me/react-special-props)",Se))};Fe.isReactWarning=!0,Object.defineProperty(Q,"ref",{get:Fe,configurable:!0})}function $o(Q){if(typeof Q.ref=="string"&>.current&&Q.__self&>.current.stateNode!==Q.__self){var Se=Jt(gt.current.type);c0[Se]||(dt('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://fb.me/react-strict-mode-string-ref',Jt(gt.current.type),Q.ref),c0[Se]=!0)}}var qt=function(Q,Se,Fe,Le,pt,Yn,Cn){var cr={$$typeof:E,type:Q,key:Se,ref:Fe,props:Cn,_owner:Yn};return cr._store={},Object.defineProperty(cr._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(cr,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Le}),Object.defineProperty(cr,"_source",{configurable:!1,enumerable:!1,writable:!1,value:pt}),Object.freeze&&(Object.freeze(cr.props),Object.freeze(cr)),cr};function xi(Q,Se,Fe){var Le,pt={},Yn=null,Cn=null,cr=null,Si=null;if(Se!=null){Ao(Se)&&(Cn=Se.ref,$o(Se)),Jo(Se)&&(Yn=""+Se.key),cr=Se.__self===void 0?null:Se.__self,Si=Se.__source===void 0?null:Se.__source;for(Le in Se)fr.call(Se,Le)&&!zr.hasOwnProperty(Le)&&(pt[Le]=Se[Le])}var Ou=arguments.length-2;if(Ou===1)pt.children=Fe;else if(Ou>1){for(var ju=Array(Ou),zu=0;zu1){for(var wu=Array(zu),Ti=0;Ti is not supported and will be removed in a future major release. Did you mean to render instead?")),Fe.Provider},set:function(Cn){Fe.Provider=Cn}},_currentValue:{get:function(){return Fe._currentValue},set:function(Cn){Fe._currentValue=Cn}},_currentValue2:{get:function(){return Fe._currentValue2},set:function(Cn){Fe._currentValue2=Cn}},_threadCount:{get:function(){return Fe._threadCount},set:function(Cn){Fe._threadCount=Cn}},Consumer:{get:function(){return Le||(Le=!0,dt("Rendering is not supported and will be removed in a future major release. Did you mean to render instead?")),Fe.Consumer}}}),Fe.Consumer=Yn}return Fe._currentRenderer=null,Fe._currentRenderer2=null,Fe}function Wt(Q){var Se={$$typeof:De,_ctor:Q,_status:-1,_result:null};{var Fe,Le;Object.defineProperties(Se,{defaultProps:{configurable:!0,get:function(){return Fe},set:function(pt){dt("React.lazy(...): It is not supported to assign `defaultProps` to a lazy component import. Either specify them where the component is defined, or create a wrapping component around it."),Fe=pt,Object.defineProperty(Se,"defaultProps",{enumerable:!0})}},propTypes:{configurable:!0,get:function(){return Le},set:function(pt){dt("React.lazy(...): It is not supported to assign `propTypes` to a lazy component import. Either specify them where the component is defined, or create a wrapping component around it."),Le=pt,Object.defineProperty(Se,"propTypes",{enumerable:!0})}}})}return Se}function Ru(Q){return Q!=null&&Q.$$typeof===me?dt("forwardRef requires a render function but received a `memo` component. Instead of forwardRef(memo(...)), use memo(forwardRef(...))."):typeof Q!="function"?dt("forwardRef requires a render function but was given %s.",Q===null?"null":typeof Q):Q.length!==0&&Q.length!==2&&dt("forwardRef render functions accept exactly two parameters: props and ref. %s",Q.length===1?"Did you forget to use the ref parameter?":"Any additional parameter will be undefined."),Q!=null&&(Q.defaultProps!=null||Q.propTypes!=null)&&dt("forwardRef render functions do not support propTypes or defaultProps. Did you accidentally pass a React component?"),{$$typeof:V,render:Q}}function eu(Q){return typeof Q=="string"||typeof Q=="function"||Q===N||Q===q||Q===k||Q===F||Q===re||Q===y||typeof Q=="object"&&Q!==null&&(Q.$$typeof===De||Q.$$typeof===me||Q.$$typeof===x||Q.$$typeof===j||Q.$$typeof===V||Q.$$typeof===ae||Q.$$typeof===we||Q.$$typeof===he||Q.$$typeof===ge)}function Q0(Q,Se){return eu(Q)||dt("memo: The first argument must be a component. Instead received: %s",Q===null?"null":typeof Q),{$$typeof:me,type:Q,compare:Se===void 0?null:Se}}function Yi(){var Q=ze.current;if(Q===null)throw Error(`Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: +1. You might have mismatching versions of React and the renderer (such as React DOM) +2. You might be breaking the Rules of Hooks +3. You might have more than one copy of React in the same app +See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.`);return Q}function Xl(Q,Se){var Fe=Yi();if(Se!==void 0&&dt("useContext() second argument is reserved for future use in React. Passing it is not supported. You passed: %s.%s",Se,typeof Se=="number"&&Array.isArray(arguments[2])?` + +Did you call array.map(useContext)? Calling Hooks inside a loop is not supported. Learn more at https://fb.me/rules-of-hooks`:""),Q._context!==void 0){var Le=Q._context;Le.Consumer===Q?dt("Calling useContext(Context.Consumer) is not supported, may cause bugs, and will be removed in a future major release. Did you mean to call useContext(Context) instead?"):Le.Provider===Q&&dt("Calling useContext(Context.Provider) is not supported. Did you mean to call useContext(Context) instead?")}return Fe.useContext(Q,Se)}function ko(Q){var Se=Yi();return Se.useState(Q)}function li(Q,Se,Fe){var Le=Yi();return Le.useReducer(Q,Se,Fe)}function ao(Q){var Se=Yi();return Se.useRef(Q)}function Ql(Q,Se){var Fe=Yi();return Fe.useEffect(Q,Se)}function No(Q,Se){var Fe=Yi();return Fe.useLayoutEffect(Q,Se)}function Is(Q,Se){var Fe=Yi();return Fe.useCallback(Q,Se)}function $n(Q,Se){var Fe=Yi();return Fe.useMemo(Q,Se)}function tl(Q,Se,Fe){var Le=Yi();return Le.useImperativeHandle(Q,Se,Fe)}function fo(Q,Se){{var Fe=Yi();return Fe.useDebugValue(Q,Se)}}var I0;I0=!1;function Sl(){if(gt.current){var Q=Jt(gt.current.type);if(Q)return` + +Check the render method of \``+Q+"`."}return""}function Lo(Q){if(Q!==void 0){var Se=Q.fileName.replace(/^.*[\\\/]/,""),Fe=Q.lineNumber;return` + +Check your code at `+Se+":"+Fe+"."}return""}function St(Q){return Q!=null?Lo(Q.__source):""}var Bt={};function Hn(Q){var Se=Sl();if(!Se){var Fe=typeof Q=="string"?Q:Q.displayName||Q.name;Fe&&(Se=` + +Check the top-level render call using <`+Fe+">.")}return Se}function qr(Q,Se){if(!(!Q._store||Q._store.validated||Q.key!=null)){Q._store.validated=!0;var Fe=Hn(Se);if(!Bt[Fe]){Bt[Fe]=!0;var Le="";Q&&Q._owner&&Q._owner!==gt.current&&(Le=" It was passed a child from "+Jt(Q._owner.type)+"."),ce(Q),dt('Each child in a list should have a unique "key" prop.%s%s See https://fb.me/react-warning-keys for more information.',Fe,Le),ce(null)}}}function Ki(Q,Se){if(typeof Q=="object"){if(Array.isArray(Q))for(var Fe=0;Fe",pt=" Did you accidentally export a JSX literal instead of a component?"):Cn=typeof Q,dt("React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",Cn,pt)}var cr=xi.apply(this,arguments);if(cr==null)return cr;if(Le)for(var Si=2;Si{"use strict";process.env.NODE_ENV==="production"?QE.exports=eS():QE.exports=lS()});var sS=nt((Wv,By)=>{(function(){var o,l="4.17.21",f=200,h="Unsupported core-js use. Try https://npms.io/search?q=ponyfill.",E="Expected a function",t="Invalid `variable` option passed into `_.template`",N="__lodash_hash_undefined__",F=500,k="__lodash_placeholder__",x=1,j=2,q=4,V=1,re=2,y=1,me=2,De=4,ge=8,ae=16,we=32,he=64,ve=128,ue=256,Ae=512,ze=30,We="...",gt=800,_t=16,Qe=1,ot=2,Ve=3,Pt=1/0,Jt=9007199254740991,it=17976931348623157e292,J=0/0,ce=4294967295,Re=ce-1,le=ce>>>1,He=[["ary",ve],["bind",y],["bindKey",me],["curry",ge],["curryRight",ae],["flip",Ae],["partial",we],["partialRight",he],["rearg",ue]],dt="[object Arguments]",At="[object Array]",nn="[object AsyncFunction]",an="[object Boolean]",On="[object Date]",lr="[object DOMException]",ln="[object Error]",Vt="[object Function]",Er="[object GeneratorFunction]",S="[object Map]",zt="[object Number]",Xn="[object Null]",vr="[object Object]",jr="[object Promise]",fr="[object Proxy]",zr="[object RegExp]",Xt="[object Set]",Du="[object String]",c0="[object Symbol]",Ao="[object Undefined]",Jo="[object WeakMap]",Fs="[object WeakSet]",Zo="[object ArrayBuffer]",$o="[object DataView]",qt="[object Float32Array]",xi="[object Float64Array]",lu="[object Int8Array]",vi="[object Int16Array]",Dr="[object Int32Array]",el="[object Uint8Array]",Y0="[object Uint8ClampedArray]",Bu="[object Uint16Array]",K0="[object Uint32Array]",Kr=/\b__p \+= '';/g,Oo=/\b(__p \+=) '' \+/g,Mo=/(__e\(.*?\)|\b__t\)) \+\n'';/g,F0=/&(?:amp|lt|gt|quot|#39);/g,su=/[&<>"']/g,ki=RegExp(F0.source),Ps=RegExp(su.source),Kl=/<%-([\s\S]+?)%>/g,P0=/<%([\s\S]+?)%>/g,d0=/<%=([\s\S]+?)%>/g,Hr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ri=/^\w*$/,X0=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,mi=/[\\^$.*+?()[\]{}|]/g,en=RegExp(mi.source),In=/^\s+/,Ai=/\s/,yi=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,Wt=/\{\n\/\* \[wrapped with (.+)\] \*/,Ru=/,? & /,eu=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,Q0=/[()=,{}\[\]\/\s]/,Yi=/\\(\\)?/g,Xl=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,ko=/\w*$/,li=/^[-+]0x[0-9a-f]+$/i,ao=/^0b[01]+$/i,Ql=/^\[object .+?Constructor\]$/,No=/^0o[0-7]+$/i,Is=/^(?:0|[1-9]\d*)$/,$n=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,tl=/($^)/,fo=/['\n\r\u2028\u2029\\]/g,I0="\\ud800-\\udfff",Sl="\\u0300-\\u036f",Lo="\\ufe20-\\ufe2f",St="\\u20d0-\\u20ff",Bt=Sl+Lo+St,Hn="\\u2700-\\u27bf",qr="a-z\\xdf-\\xf6\\xf8-\\xff",Ki="\\xac\\xb1\\xd7\\xf7",Xr="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",Au="\\u2000-\\u206f",p0=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",Ni="A-Z\\xc0-\\xd6\\xd8-\\xde",h0="\\ufe0e\\ufe0f",hs=Ki+Xr+Au+p0,Ct="['\u2019]",co="["+I0+"]",nl="["+hs+"]",Jl="["+Bt+"]",Uu="\\d+",vs="["+Hn+"]",b0="["+qr+"]",Q="[^"+I0+hs+Uu+Hn+qr+Ni+"]",Se="\\ud83c[\\udffb-\\udfff]",Fe="(?:"+Jl+"|"+Se+")",Le="[^"+I0+"]",pt="(?:\\ud83c[\\udde6-\\uddff]){2}",Yn="[\\ud800-\\udbff][\\udc00-\\udfff]",Cn="["+Ni+"]",cr="\\u200d",Si="(?:"+b0+"|"+Q+")",Ou="(?:"+Cn+"|"+Q+")",ju="(?:"+Ct+"(?:d|ll|m|re|s|t|ve))?",zu="(?:"+Ct+"(?:D|LL|M|RE|S|T|VE))?",wu=Fe+"?",Ti="["+h0+"]?",Fo="(?:"+cr+"(?:"+[Le,pt,Yn].join("|")+")"+Ti+wu+")*",Mu="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",po="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",Hu=Ti+wu+Fo,Pa="(?:"+[vs,pt,Yn].join("|")+")"+Hu,v0="(?:"+[Le+Jl+"?",Jl,pt,Yn,co].join("|")+")",ia=RegExp(Ct,"g"),J0=RegExp(Jl,"g"),ua=RegExp(Se+"(?="+Se+")|"+v0+Hu,"g"),Ia=RegExp([Cn+"?"+b0+"+"+ju+"(?="+[nl,Cn,"$"].join("|")+")",Ou+"+"+zu+"(?="+[nl,Cn+Si,"$"].join("|")+")",Cn+"?"+Si+"+"+ju,Cn+"+"+zu,po,Mu,Uu,Pa].join("|"),"g"),ms=RegExp("["+cr+I0+Bt+h0+"]"),S0=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,Qn=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],ac=-1,si={};si[qt]=si[xi]=si[lu]=si[vi]=si[Dr]=si[el]=si[Y0]=si[Bu]=si[K0]=!0,si[dt]=si[At]=si[Zo]=si[an]=si[$o]=si[On]=si[ln]=si[Vt]=si[S]=si[zt]=si[vr]=si[zr]=si[Xt]=si[Du]=si[Jo]=!1;var Jr={};Jr[dt]=Jr[At]=Jr[Zo]=Jr[$o]=Jr[an]=Jr[On]=Jr[qt]=Jr[xi]=Jr[lu]=Jr[vi]=Jr[Dr]=Jr[S]=Jr[zt]=Jr[vr]=Jr[zr]=Jr[Xt]=Jr[Du]=Jr[c0]=Jr[el]=Jr[Y0]=Jr[Bu]=Jr[K0]=!0,Jr[ln]=Jr[Vt]=Jr[Jo]=!1;var Zl={\u00C0:"A",\u00C1:"A",\u00C2:"A",\u00C3:"A",\u00C4:"A",\u00C5:"A",\u00E0:"a",\u00E1:"a",\u00E2:"a",\u00E3:"a",\u00E4:"a",\u00E5:"a",\u00C7:"C",\u00E7:"c",\u00D0:"D",\u00F0:"d",\u00C8:"E",\u00C9:"E",\u00CA:"E",\u00CB:"E",\u00E8:"e",\u00E9:"e",\u00EA:"e",\u00EB:"e",\u00CC:"I",\u00CD:"I",\u00CE:"I",\u00CF:"I",\u00EC:"i",\u00ED:"i",\u00EE:"i",\u00EF:"i",\u00D1:"N",\u00F1:"n",\u00D2:"O",\u00D3:"O",\u00D4:"O",\u00D5:"O",\u00D6:"O",\u00D8:"O",\u00F2:"o",\u00F3:"o",\u00F4:"o",\u00F5:"o",\u00F6:"o",\u00F8:"o",\u00D9:"U",\u00DA:"U",\u00DB:"U",\u00DC:"U",\u00F9:"u",\u00FA:"u",\u00FB:"u",\u00FC:"u",\u00DD:"Y",\u00FD:"y",\u00FF:"y",\u00C6:"Ae",\u00E6:"ae",\u00DE:"Th",\u00FE:"th",\u00DF:"ss",\u0100:"A",\u0102:"A",\u0104:"A",\u0101:"a",\u0103:"a",\u0105:"a",\u0106:"C",\u0108:"C",\u010A:"C",\u010C:"C",\u0107:"c",\u0109:"c",\u010B:"c",\u010D:"c",\u010E:"D",\u0110:"D",\u010F:"d",\u0111:"d",\u0112:"E",\u0114:"E",\u0116:"E",\u0118:"E",\u011A:"E",\u0113:"e",\u0115:"e",\u0117:"e",\u0119:"e",\u011B:"e",\u011C:"G",\u011E:"G",\u0120:"G",\u0122:"G",\u011D:"g",\u011F:"g",\u0121:"g",\u0123:"g",\u0124:"H",\u0126:"H",\u0125:"h",\u0127:"h",\u0128:"I",\u012A:"I",\u012C:"I",\u012E:"I",\u0130:"I",\u0129:"i",\u012B:"i",\u012D:"i",\u012F:"i",\u0131:"i",\u0134:"J",\u0135:"j",\u0136:"K",\u0137:"k",\u0138:"k",\u0139:"L",\u013B:"L",\u013D:"L",\u013F:"L",\u0141:"L",\u013A:"l",\u013C:"l",\u013E:"l",\u0140:"l",\u0142:"l",\u0143:"N",\u0145:"N",\u0147:"N",\u014A:"N",\u0144:"n",\u0146:"n",\u0148:"n",\u014B:"n",\u014C:"O",\u014E:"O",\u0150:"O",\u014D:"o",\u014F:"o",\u0151:"o",\u0154:"R",\u0156:"R",\u0158:"R",\u0155:"r",\u0157:"r",\u0159:"r",\u015A:"S",\u015C:"S",\u015E:"S",\u0160:"S",\u015B:"s",\u015D:"s",\u015F:"s",\u0161:"s",\u0162:"T",\u0164:"T",\u0166:"T",\u0163:"t",\u0165:"t",\u0167:"t",\u0168:"U",\u016A:"U",\u016C:"U",\u016E:"U",\u0170:"U",\u0172:"U",\u0169:"u",\u016B:"u",\u016D:"u",\u016F:"u",\u0171:"u",\u0173:"u",\u0174:"W",\u0175:"w",\u0176:"Y",\u0177:"y",\u0178:"Y",\u0179:"Z",\u017B:"Z",\u017D:"Z",\u017A:"z",\u017C:"z",\u017E:"z",\u0132:"IJ",\u0133:"ij",\u0152:"Oe",\u0153:"oe",\u0149:"'n",\u017F:"s"},oa={"&":"&","<":"<",">":">",'"':""","'":"'"},pf={"&":"&","<":"<",">":">",""":'"',"'":"'"},bs={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},ba=parseFloat,Bs=parseInt,m0=typeof global=="object"&&global&&global.Object===Object&&global,Us=typeof self=="object"&&self&&self.Object===Object&&self,zi=m0||Us||Function("return this")(),U=typeof Wv=="object"&&Wv&&!Wv.nodeType&&Wv,H=U&&typeof By=="object"&&By&&!By.nodeType&&By,Y=H&&H.exports===U,ee=Y&&m0.process,Ce=function(){try{var xe=H&&H.require&&H.require("util").types;return xe||ee&&ee.binding&&ee.binding("util")}catch{}}(),_e=Ce&&Ce.isArrayBuffer,Oe=Ce&&Ce.isDate,$=Ce&&Ce.isMap,Ne=Ce&&Ce.isRegExp,Je=Ce&&Ce.isSet,vt=Ce&&Ce.isTypedArray;function oe(xe,tt,Ke){switch(Ke.length){case 0:return xe.call(tt);case 1:return xe.call(tt,Ke[0]);case 2:return xe.call(tt,Ke[0],Ke[1]);case 3:return xe.call(tt,Ke[0],Ke[1],Ke[2])}return xe.apply(tt,Ke)}function qe(xe,tt,Ke,Yt){for(var Kt=-1,pr=xe==null?0:xe.length;++Kt-1}function rn(xe,tt,Ke){for(var Yt=-1,Kt=xe==null?0:xe.length;++Yt-1;);return Ke}function Tl(xe,tt){for(var Ke=xe.length;Ke--&&wt(tt,xe[Ke],0)>-1;);return Ke}function vf(xe,tt){for(var Ke=xe.length,Yt=0;Ke--;)xe[Ke]===tt&&++Yt;return Yt}var Io=Jn(Zl),ys=Jn(oa);function js(xe){return"\\"+bs[xe]}function bo(xe,tt){return xe==null?o:xe[tt]}function Bo(xe){return ms.test(xe)}function gs(xe){return S0.test(xe)}function Xu(xe){for(var tt,Ke=[];!(tt=xe.next()).done;)Ke.push(tt.value);return Ke}function Su(xe){var tt=-1,Ke=Array(xe.size);return xe.forEach(function(Yt,Kt){Ke[++tt]=[Kt,Yt]}),Ke}function _i(xe,tt){return function(Ke){return xe(tt(Ke))}}function C0(xe,tt){for(var Ke=-1,Yt=xe.length,Kt=0,pr=[];++Ke-1}function fa(p,m){var R=this.__data__,I=ts(R,p);return I<0?(++this.size,R.push([p,m])):R[I][1]=m,this}io.prototype.clear=Ba,io.prototype.delete=_f,io.prototype.get=fc,io.prototype.has=Ds,io.prototype.set=fa;function U0(p){var m=-1,R=p==null?0:p.length;for(this.clear();++m=m?p:m)),p}function j0(p,m,R,I,W,te){var pe,Ee=m&x,be=m&j,Dt=m&q;if(R&&(pe=W?R(p,I,W,te):R(p)),pe!==o)return pe;if(!Iu(p))return p;var Tt=tr(p);if(Tt){if(pe=Cs(p),!Ee)return iu(p,pe)}else{var Ot=Pu(p),on=Ot==Vt||Ot==Er;if(Js(p))return vc(p,Ee);if(Ot==vr||Ot==dt||on&&!W){if(pe=be||on?{}:Ec(p),!Ee)return be?ns(p,ol(pe,p)):u0(p,Ef(pe,p))}else{if(!Jr[Ot])return W?p:{};pe=Th(p,Ot,Ee)}}te||(te=new ul);var Mn=te.get(p);if(Mn)return Mn;te.set(p,pe),Pd(p)?p.forEach(function(ar){pe.add(j0(ar,m,R,ar,p,te))}):_p(p)&&p.forEach(function(ar,ri){pe.set(ri,j0(ar,m,R,ri,p,te))});var rr=Dt?be?sr:r1:be?dn:N0,br=Tt?o:rr(p);return rt(br||p,function(ar,ri){br&&(ri=ar,ar=p[ri]),Ss(pe,ri,j0(ar,m,R,ri,p,te))}),pe}function Df(p){var m=N0(p);return function(R){return Wc(R,p,m)}}function Wc(p,m,R){var I=R.length;if(p==null)return!I;for(p=bn(p);I--;){var W=R[I],te=m[W],pe=p[W];if(pe===o&&!(W in p)||!te(pe))return!1}return!0}function dc(p,m,R){if(typeof p!="function")throw new $r(E);return Qa(function(){p.apply(o,R)},m)}function Ol(p,m,R,I){var W=-1,te=sn,pe=!0,Ee=p.length,be=[],Dt=m.length;if(!Ee)return be;R&&(m=Ft(m,gi(R))),I?(te=rn,pe=!1):m.length>=f&&(te=rl,pe=!1,m=new yo(m));e:for(;++WW?0:W+R),I=I===o||I>W?W:Mr(I),I<0&&(I+=W),I=R>I?0:Dp(I);R0&&R(Ee)?m>1?Wi(Ee,m-1,R,I,W):Dn(W,Ee):I||(W[W.length]=Ee)}return W}var _=yc(),g=yc(!0);function A(p,m){return p&&_(p,m,N0)}function P(p,m){return p&&g(p,m,N0)}function B(p,m){return bt(m,function(R){return xa(p[R])})}function Z(p,m){m=Ws(m,p);for(var R=0,I=m.length;p!=null&&Rm}function Nt(p,m){return p!=null&&ui.call(p,m)}function xr(p,m){return p!=null&&m in bn(p)}function r0(p,m,R){return p>=Kn(m,R)&&p=120&&Tt.length>=120)?new yo(pe&&Tt):o}Tt=p[0];var Ot=-1,on=Ee[0];e:for(;++Ot-1;)Ee!==p&&O0.call(Ee,be,1),O0.call(p,be,1);return p}function sd(p,m){for(var R=p?m.length:0,I=R-1;R--;){var W=m[R];if(R==I||W!==te){var te=W;Do(W)?O0.call(p,W,1):x2(p,W)}}return p}function ad(p,m){return p+Es(_0()*(m-p+1))}function S2(p,m,R,I){for(var W=-1,te=ei(Zu((m-p)/(R||1)),0),pe=Ke(te);te--;)pe[I?te:++W]=p,p+=R;return pe}function Yc(p,m){var R="";if(!p||m<1||m>Jt)return R;do m%2&&(R+=p),m=Es(m/2),m&&(p+=p);while(m);return R}function Ir(p,m){return l1(L2(p,m,l0),p+"")}function fd(p){return za(Nc(p))}function cd(p,m){var R=Nc(p);return wc(R,n0(m,0,R.length))}function Ga(p,m,R,I){if(!Iu(p))return p;m=Ws(m,p);for(var W=-1,te=m.length,pe=te-1,Ee=p;Ee!=null&&++WW?0:W+m),R=R>W?W:R,R<0&&(R+=W),W=m>R?0:R-m>>>0,m>>>=0;for(var te=Ke(W);++I>>1,pe=p[te];pe!==null&&!Bl(pe)&&(R?pe<=m:pe=f){var Dt=m?null:am(p);if(Dt)return $0(Dt);pe=!1,W=rl,be=new yo}else be=m?[]:Ee;e:for(;++I=I?p:sl(p,m,R)}var Zc=_s||function(p){return zi.clearTimeout(p)};function vc(p,m){if(m)return p.slice();var R=p.length,I=qi?qi(R):new p.constructor(R);return p.copy(I),I}function mc(p){var m=new p.constructor(p.byteLength);return new A0(m).set(new A0(p)),m}function pd(p,m){var R=m?mc(p.buffer):p.buffer;return new p.constructor(R,p.byteOffset,p.byteLength)}function Eh(p){var m=new p.constructor(p.source,ko.exec(p));return m.lastIndex=p.lastIndex,m}function Tf(p){return Ar?bn(Ar.call(p)):{}}function $c(p,m){var R=m?mc(p.buffer):p.buffer;return new p.constructor(R,p.byteOffset,p.length)}function Dh(p,m){if(p!==m){var R=p!==o,I=p===null,W=p===p,te=Bl(p),pe=m!==o,Ee=m===null,be=m===m,Dt=Bl(m);if(!Ee&&!Dt&&!te&&p>m||te&&pe&&be&&!Ee&&!Dt||I&&pe&&be||!R&&be||!W)return 1;if(!I&&!te&&!Dt&&p=Ee)return be;var Dt=R[I];return be*(Dt=="desc"?-1:1)}}return p.index-m.index}function Vs(p,m,R,I){for(var W=-1,te=p.length,pe=R.length,Ee=-1,be=m.length,Dt=ei(te-pe,0),Tt=Ke(be+Dt),Ot=!I;++Ee1?R[W-1]:o,pe=W>2?R[2]:o;for(te=p.length>3&&typeof te=="function"?(W--,te):o,pe&&lo(R[0],R[1],pe)&&(te=W<3?o:te,W=1),m=bn(m);++I-1?W[te?m[pe]:pe]:o}}function t1(p){return cl(function(m){var R=m.length,I=R,W=Wr.prototype.thru;for(p&&m.reverse();I--;){var te=m[I];if(typeof te!="function")throw new $r(E);if(W&&!pe&&qo(te)=="wrapper")var pe=new Wr([],!0)}for(I=pe?I:R;++I1&&fi.reverse(),Tt&&beEe))return!1;var Dt=te.get(p),Tt=te.get(m);if(Dt&&Tt)return Dt==m&&Tt==p;var Ot=-1,on=!0,Mn=R&re?new yo:o;for(te.set(p,m),te.set(m,p);++Ot1?"& ":"")+m[I],m=m.join(R>2?", ":" "),p.replace(yi,`{ +/* [wrapped with `+m+`] */ +`)}function is(p){return tr(p)||pl(p)||!!(vo&&p&&p[vo])}function Do(p,m){var R=typeof p;return m=m==null?Jt:m,!!m&&(R=="number"||R!="symbol"&&Is.test(p))&&p>-1&&p%1==0&&p0){if(++m>=gt)return arguments[0]}else m=0;return p.apply(o,arguments)}}function wc(p,m){var R=-1,I=p.length,W=I-1;for(m=m===o?I:m;++R1?p[m-1]:o;return R=typeof R=="function"?(p.pop(),R):o,wd(p,R)});function zh(p){var m=K(p);return m.__chain__=!0,m}function Hh(p,m){return m(p),p}function g1(p,m){return m(p)}var J2=cl(function(p){var m=p.length,R=m?p[0]:0,I=this.__wrapped__,W=function(te){return qa(te,p)};return m>1||this.__actions__.length||!(I instanceof ft)||!Do(R)?this.thru(W):(I=I.slice(R,+R+(m?1:0)),I.__actions__.push({func:g1,args:[W],thisArg:o}),new Wr(I,this.__chain__).thru(function(te){return m&&!te.length&&te.push(o),te}))});function qh(){return zh(this)}function Z2(){return new Wr(this.value(),this.__chain__)}function Wh(){this.__values__===o&&(this.__values__=fv(this.value()));var p=this.__index__>=this.__values__.length,m=p?o:this.__values__[this.__index__++];return{done:p,value:m}}function _m(){return this}function Em(p){for(var m,R=this;R instanceof ni;){var I=P2(R);I.__index__=0,I.__values__=o,m?W.__wrapped__=I:m=I;var W=I;R=R.__wrapped__}return W.__wrapped__=p,m}function Pf(){var p=this.__wrapped__;if(p instanceof ft){var m=p;return this.__actions__.length&&(m=new ft(this)),m=m.reverse(),m.__actions__.push({func:g1,args:[W2],thisArg:o}),new Wr(m,this.__chain__)}return this.thru(W2)}function If(){return _h(this.__wrapped__,this.__actions__)}var Sd=Ya(function(p,m,R){ui.call(p,R)?++p[R]:Vu(p,R,1)});function Dm(p,m,R){var I=tr(p)?kt:ud;return R&&lo(p,m,R)&&(m=o),I(p,Vn(m,3))}function $2(p,m){var R=tr(p)?bt:Vc;return R(p,Vn(m,3))}var Td=Nl(U2),ep=Nl(a1);function Vh(p,m){return Wi(_1(p,m),1)}function tp(p,m){return Wi(_1(p,m),Pt)}function Gh(p,m,R){return R=R===o?1:Mr(R),Wi(_1(p,m),R)}function Yh(p,m){var R=tr(p)?rt:Ts;return R(p,Vn(m,3))}function np(p,m){var R=tr(p)?xt:da;return R(p,Vn(m,3))}var wm=Ya(function(p,m,R){ui.call(p,R)?p[R].push(m):Vu(p,R,[m])});function Sm(p,m,R,I){p=hl(p)?p:Nc(p),R=R&&!I?Mr(R):0;var W=p.length;return R<0&&(R=ei(W+R,0)),S1(p)?R<=W&&p.indexOf(m,R)>-1:!!W&&wt(p,m,R)>-1}var Tm=Ir(function(p,m,R){var I=-1,W=typeof m=="function",te=hl(p)?Ke(p.length):[];return Ts(p,function(pe){te[++I]=W?oe(m,pe,R):Ml(pe,m,R)}),te}),Kh=Ya(function(p,m,R){Vu(p,R,m)});function _1(p,m){var R=tr(p)?Ft:D2;return R(p,Vn(m,3))}function Cm(p,m,R,I){return p==null?[]:(tr(m)||(m=m==null?[]:[m]),R=I?o:R,tr(R)||(R=R==null?[]:[R]),go(p,m,R))}var rp=Ya(function(p,m,R){p[R?0:1].push(m)},function(){return[[],[]]});function ip(p,m,R){var I=tr(p)?dr:wr,W=arguments.length<3;return I(p,Vn(m,4),R,W,Ts)}function xm(p,m,R){var I=tr(p)?er:wr,W=arguments.length<3;return I(p,Vn(m,4),R,W,da)}function Rm(p,m){var R=tr(p)?bt:Vc;return R(p,Rd(Vn(m,3)))}function Xh(p){var m=tr(p)?za:fd;return m(p)}function Am(p,m,R){(R?lo(p,m,R):m===o)?m=1:m=Mr(m);var I=tr(p)?Ha:cd;return I(p,m)}function Om(p){var m=tr(p)?ca:ll;return m(p)}function up(p){if(p==null)return 0;if(hl(p))return S1(p)?tu(p):p.length;var m=Pu(p);return m==S||m==Xt?p.size:Wa(p).length}function op(p,m,R){var I=tr(p)?Cr:yh;return R&&lo(p,m,R)&&(m=o),I(p,Vn(m,3))}var Ta=Ir(function(p,m){if(p==null)return[];var R=m.length;return R>1&&lo(p,m[0],m[1])?m=[]:R>2&&lo(m[0],m[1],m[2])&&(m=[m[0]]),go(p,Wi(m,1),[])}),E1=aa||function(){return zi.Date.now()};function lp(p,m){if(typeof m!="function")throw new $r(E);return p=Mr(p),function(){if(--p<1)return m.apply(this,arguments)}}function Qh(p,m,R){return m=R?o:m,m=p&&m==null?p.length:m,hn(p,ve,o,o,o,o,m)}function Cd(p,m){var R;if(typeof m!="function")throw new $r(E);return p=Mr(p),function(){return--p>0&&(R=m.apply(this,arguments)),p<=1&&(m=o),R}}var D1=Ir(function(p,m,R){var I=y;if(R.length){var W=C0(R,yr(D1));I|=we}return hn(p,I,m,R,W)}),Jh=Ir(function(p,m,R){var I=y|me;if(R.length){var W=C0(R,yr(Jh));I|=we}return hn(m,I,p,R,W)});function sp(p,m,R){m=R?o:m;var I=hn(p,ge,o,o,o,o,o,m);return I.placeholder=sp.placeholder,I}function Zh(p,m,R){m=R?o:m;var I=hn(p,ae,o,o,o,o,o,m);return I.placeholder=Zh.placeholder,I}function ap(p,m,R){var I,W,te,pe,Ee,be,Dt=0,Tt=!1,Ot=!1,on=!0;if(typeof p!="function")throw new $r(E);m=vl(m)||0,Iu(R)&&(Tt=!!R.leading,Ot="maxWait"in R,te=Ot?ei(vl(R.maxWait)||0,m):te,on="trailing"in R?!!R.trailing:on);function Mn(s0){var Os=I,Co=W;return I=W=o,Dt=s0,pe=p.apply(Co,Os),pe}function rr(s0){return Dt=s0,Ee=Qa(ri,m),Tt?Mn(s0):pe}function br(s0){var Os=s0-be,Co=s0-Dt,kv=m-Os;return Ot?Kn(kv,te-Co):kv}function ar(s0){var Os=s0-be,Co=s0-Dt;return be===o||Os>=m||Os<0||Ot&&Co>=te}function ri(){var s0=E1();if(ar(s0))return fi(s0);Ee=Qa(ri,br(s0))}function fi(s0){return Ee=o,on&&I?Mn(s0):(I=W=o,pe)}function zl(){Ee!==o&&Zc(Ee),Dt=0,I=be=W=Ee=o}function Zi(){return Ee===o?pe:fi(E1())}function so(){var s0=E1(),Os=ar(s0);if(I=arguments,W=this,be=s0,Os){if(Ee===o)return rr(be);if(Ot)return Zc(Ee),Ee=Qa(ri,m),Mn(be)}return Ee===o&&(Ee=Qa(ri,m)),pe}return so.cancel=zl,so.flush=Zi,so}var $h=Ir(function(p,m){return dc(p,1,m)}),ev=Ir(function(p,m,R){return dc(p,vl(m)||0,R)});function fp(p){return hn(p,Ae)}function xd(p,m){if(typeof p!="function"||m!=null&&typeof m!="function")throw new $r(E);var R=function(){var I=arguments,W=m?m.apply(this,I):I[0],te=R.cache;if(te.has(W))return te.get(W);var pe=p.apply(this,I);return R.cache=te.set(W,pe)||te,pe};return R.cache=new(xd.Cache||U0),R}xd.Cache=U0;function Rd(p){if(typeof p!="function")throw new $r(E);return function(){var m=arguments;switch(m.length){case 0:return!p.call(this);case 1:return!p.call(this,m[0]);case 2:return!p.call(this,m[0],m[1]);case 3:return!p.call(this,m[0],m[1],m[2])}return!p.apply(this,m)}}function H0(p){return Cd(2,p)}var Ad=O2(function(p,m){m=m.length==1&&tr(m[0])?Ft(m[0],gi(Vn())):Ft(Wi(m,1),gi(Vn()));var R=m.length;return Ir(function(I){for(var W=-1,te=Kn(I.length,R);++W=m}),pl=i0(function(){return arguments}())?i0:function(p){return Gu(p)&&ui.call(p,"callee")&&!B0.call(p,"callee")},tr=Ke.isArray,Qs=_e?gi(_e):Ge;function hl(p){return p!=null&&Ld(p.length)&&!xa(p)}function o0(p){return Gu(p)&&hl(p)}function rv(p){return p===!0||p===!1||Gu(p)&&yt(p)==an}var Js=no||Bp,vp=Oe?gi(Oe):je;function Fm(p){return Gu(p)&&p.nodeType===1&&!Cc(p)}function iv(p){if(p==null)return!0;if(hl(p)&&(tr(p)||typeof p=="string"||typeof p.splice=="function"||Js(p)||Ra(p)||pl(p)))return!p.length;var m=Pu(p);if(m==S||m==Xt)return!p.size;if(Nf(p))return!Wa(p).length;for(var R in p)if(ui.call(p,R))return!1;return!0}function mp(p,m){return st(p,m)}function Pm(p,m,R){R=typeof R=="function"?R:o;var I=R?R(p,m):o;return I===o?st(p,m,o,R):!!I}function yp(p){if(!Gu(p))return!1;var m=yt(p);return m==ln||m==lr||typeof p.message=="string"&&typeof p.name=="string"&&!Cc(p)}function Tc(p){return typeof p=="number"&&nu(p)}function xa(p){if(!Iu(p))return!1;var m=yt(p);return m==Vt||m==Er||m==nn||m==fr}function gp(p){return typeof p=="number"&&p==Mr(p)}function Ld(p){return typeof p=="number"&&p>-1&&p%1==0&&p<=Jt}function Iu(p){var m=typeof p;return p!=null&&(m=="object"||m=="function")}function Gu(p){return p!=null&&typeof p=="object"}var _p=$?gi($):Wn;function Ep(p,m){return p===m||oi(p,m,jn(m))}function uv(p,m,R){return R=typeof R=="function"?R:o,oi(p,m,jn(m),R)}function Im(p){return ov(p)&&p!=+p}function bm(p){if(Ll(p))throw new Kt(h);return ur(p)}function Bm(p){return p===null}function Fd(p){return p==null}function ov(p){return typeof p=="number"||Gu(p)&&yt(p)==zt}function Cc(p){if(!Gu(p)||yt(p)!=vr)return!1;var m=il(p);if(m===null)return!0;var R=ui.call(m,"constructor")&&m.constructor;return typeof R=="function"&&R instanceof R&&Lu.call(R)==sa}var w1=Ne?gi(Ne):ai;function Um(p){return gp(p)&&p>=-Jt&&p<=Jt}var Pd=Je?gi(Je):Qi;function S1(p){return typeof p=="string"||!tr(p)&&Gu(p)&&yt(p)==Du}function Bl(p){return typeof p=="symbol"||Gu(p)&&yt(p)==c0}var Ra=vt?gi(vt):Vr;function lv(p){return p===o}function jm(p){return Gu(p)&&Pu(p)==Jo}function sv(p){return Gu(p)&&yt(p)==Fs}var av=md(od),zm=md(function(p,m){return p<=m});function fv(p){if(!p)return[];if(hl(p))return S1(p)?Zr(p):iu(p);if(Fu&&p[Fu])return Xu(p[Fu]());var m=Pu(p),R=m==S?Su:m==Xt?$0:Nc;return R(p)}function Aa(p){if(!p)return p===0?p:0;if(p=vl(p),p===Pt||p===-Pt){var m=p<0?-1:1;return m*it}return p===p?p:0}function Mr(p){var m=Aa(p),R=m%1;return m===m?R?m-R:m:0}function Dp(p){return p?n0(Mr(p),0,ce):0}function vl(p){if(typeof p=="number")return p;if(Bl(p))return J;if(Iu(p)){var m=typeof p.valueOf=="function"?p.valueOf():p;p=Iu(m)?m+"":m}if(typeof p!="string")return p===0?p:+p;p=Nu(p);var R=ao.test(p);return R||No.test(p)?Bs(p.slice(2),R?2:8):li.test(p)?J:+p}function yu(p){return M0(p,dn(p))}function T1(p){return p?n0(Mr(p),-Jt,Jt):p===0?p:0}function Ui(p){return p==null?"":al(p)}var wp=uo(function(p,m){if(Nf(m)||hl(m)){M0(m,N0(m),p);return}for(var R in m)ui.call(m,R)&&Ss(p,R,m[R])}),Id=uo(function(p,m){M0(m,dn(m),p)}),To=uo(function(p,m,R,I){M0(m,dn(m),p,I)}),As=uo(function(p,m,R,I){M0(m,N0(m),p,I)}),bf=cl(qa);function bd(p,m){var R=ti(p);return m==null?R:Ef(R,m)}var Sp=Ir(function(p,m){p=bn(p);var R=-1,I=m.length,W=I>2?m[2]:o;for(W&&lo(m[0],m[1],W)&&(I=1);++R1),te}),M0(p,sr(p),R),I&&(R=j0(R,x|j|q,fm));for(var W=m.length;W--;)x2(R,m[W]);return R});function A1(p,m){return ef(p,Rd(Vn(m)))}var xp=cl(function(p,m){return p==null?{}:vh(p,m)});function ef(p,m){if(p==null)return{};var R=Ft(sr(p),function(I){return[I]});return m=Vn(m),mh(p,R,function(I,W){return m(I,W[0])})}function Hm(p,m,R){m=Ws(m,p);var I=-1,W=m.length;for(W||(W=1,p=o);++Im){var I=p;p=m,m=I}if(R||p%1||m%1){var W=_0();return Kn(p+W*(m-p+ba("1e-"+((W+"").length-1))),m)}return ad(p,m)}var Wd=Cf(function(p,m,R){return m=m.toLowerCase(),p+(R?Wo(m):m)});function Wo(p){return Op(Ui(p).toLowerCase())}function Vd(p){return p=Ui(p),p&&p.replace($n,Io).replace(J0,"")}function Wm(p,m,R){p=Ui(p),m=al(m);var I=p.length;R=R===o?I:n0(Mr(R),0,I);var W=R;return R-=m.length,R>=0&&p.slice(R,W)==m}function k1(p){return p=Ui(p),p&&Ps.test(p)?p.replace(su,ys):p}function Vm(p){return p=Ui(p),p&&en.test(p)?p.replace(mi,"\\$&"):p}var Gm=Cf(function(p,m,R){return p+(R?"-":"")+m.toLowerCase()}),dv=Cf(function(p,m,R){return p+(R?" ":"")+m.toLowerCase()}),Ym=wh("toLowerCase");function pv(p,m,R){p=Ui(p),m=Mr(m);var I=m?tu(p):0;if(!m||I>=m)return p;var W=(m-I)/2;return ga(Es(W),R)+p+ga(Zu(W),R)}function Km(p,m,R){p=Ui(p),m=Mr(m);var I=m?tu(p):0;return m&&I>>0,R?(p=Ui(p),p&&(typeof m=="string"||m!=null&&!w1(m))&&(m=al(m),!m&&Bo(p))?va(Zr(p),0,R):p.split(m,R)):[]}var zf=Cf(function(p,m,R){return p+(R?" ":"")+Op(m)});function vv(p,m,R){return p=Ui(p),R=R==null?0:n0(Mr(R),0,p.length),m=al(m),p.slice(R,R+m.length)==m}function mv(p,m,R){var I=K.templateSettings;R&&lo(p,m,R)&&(m=o),p=Ui(p),m=To({},m,I,Rf);var W=To({},m.imports,I.imports,Rf),te=N0(W),pe=Po(W,te),Ee,be,Dt=0,Tt=m.interpolate||tl,Ot="__p += '",on=mu((m.escape||tl).source+"|"+Tt.source+"|"+(Tt===d0?Xl:tl).source+"|"+(m.evaluate||tl).source+"|$","g"),Mn="//# sourceURL="+(ui.call(m,"sourceURL")?(m.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++ac+"]")+` +`;p.replace(on,function(ar,ri,fi,zl,Zi,so){return fi||(fi=zl),Ot+=p.slice(Dt,so).replace(fo,js),ri&&(Ee=!0,Ot+=`' + +__e(`+ri+`) + +'`),Zi&&(be=!0,Ot+=`'; +`+Zi+`; +__p += '`),fi&&(Ot+=`' + +((__t = (`+fi+`)) == null ? '' : __t) + +'`),Dt=so+ar.length,ar}),Ot+=`'; +`;var rr=ui.call(m,"variable")&&m.variable;if(!rr)Ot=`with (obj) { +`+Ot+` +} +`;else if(Q0.test(rr))throw new Kt(t);Ot=(be?Ot.replace(Kr,""):Ot).replace(Oo,"$1").replace(Mo,"$1;"),Ot="function("+(rr||"obj")+`) { +`+(rr?"":`obj || (obj = {}); +`)+"var __t, __p = ''"+(Ee?", __e = _.escape":"")+(be?`, __j = Array.prototype.join; +function print() { __p += __j.call(arguments, '') } +`:`; +`)+Ot+`return __p +}`;var br=wv(function(){return pr(te,Mn+"return "+Ot).apply(o,pe)});if(br.source=Ot,yp(br))throw br;return br}function yv(p){return Ui(p).toLowerCase()}function Gd(p){return Ui(p).toUpperCase()}function Yd(p,m,R){if(p=Ui(p),p&&(R||m===o))return Nu(p);if(!p||!(m=al(m)))return p;var I=Zr(p),W=Zr(m),te=hf(I,W),pe=Tl(I,W)+1;return va(I,te,pe).join("")}function Ap(p,m,R){if(p=Ui(p),p&&(R||m===o))return p.slice(0,ho(p)+1);if(!p||!(m=al(m)))return p;var I=Zr(p),W=Tl(I,Zr(m))+1;return va(I,0,W).join("")}function gv(p,m,R){if(p=Ui(p),p&&(R||m===o))return p.replace(In,"");if(!p||!(m=al(m)))return p;var I=Zr(p),W=hf(I,Zr(m));return va(I,W).join("")}function Kd(p,m){var R=ze,I=We;if(Iu(m)){var W="separator"in m?m.separator:W;R="length"in m?Mr(m.length):R,I="omission"in m?al(m.omission):I}p=Ui(p);var te=p.length;if(Bo(p)){var pe=Zr(p);te=pe.length}if(R>=te)return p;var Ee=R-tu(I);if(Ee<1)return I;var be=pe?va(pe,0,Ee).join(""):p.slice(0,Ee);if(W===o)return be+I;if(pe&&(Ee+=be.length-Ee),w1(W)){if(p.slice(Ee).search(W)){var Dt,Tt=be;for(W.global||(W=mu(W.source,Ui(ko.exec(W))+"g")),W.lastIndex=0;Dt=W.exec(Tt);)var Ot=Dt.index;be=be.slice(0,Ot===o?Ee:Ot)}}else if(p.indexOf(al(W),Ee)!=Ee){var on=be.lastIndexOf(W);on>-1&&(be=be.slice(0,on))}return be+I}function _v(p){return p=Ui(p),p&&ki.test(p)?p.replace(F0,Bi):p}var Ev=Cf(function(p,m,R){return p+(R?" ":"")+m.toUpperCase()}),Op=wh("toUpperCase");function Dv(p,m,R){return p=Ui(p),m=R?o:m,m===o?gs(p)?yf(p):y0(p):p.match(m)||[]}var wv=Ir(function(p,m){try{return oe(p,o,m)}catch(R){return yp(R)?R:new Kt(R)}}),$m=cl(function(p,m){return rt(m,function(R){R=Fl(R),Vu(p,R,D1(p[R],p))}),p});function Sv(p){var m=p==null?0:p.length,R=Vn();return p=m?Ft(p,function(I){if(typeof I[1]!="function")throw new $r(E);return[R(I[0]),I[1]]}):[],Ir(function(I){for(var W=-1;++WJt)return[];var R=ce,I=Kn(p,ce);m=Vn(m),p-=ce;for(var W=T0(I,m);++R0||m<0)?new ft(R):(p<0?R=R.takeRight(-p):p&&(R=R.drop(p)),m!==o&&(m=Mr(m),R=m<0?R.dropRight(-m):R.take(m-p)),R)},ft.prototype.takeRightWhile=function(p){return this.reverse().takeWhile(p).reverse()},ft.prototype.toArray=function(){return this.take(ce)},A(ft.prototype,function(p,m){var R=/^(?:filter|find|map|reject)|While$/.test(m),I=/^(?:head|last)$/.test(m),W=K[I?"take"+(m=="last"?"Right":""):m],te=I||/^find/.test(m);!W||(K.prototype[m]=function(){var pe=this.__wrapped__,Ee=I?[1]:arguments,be=pe instanceof ft,Dt=Ee[0],Tt=be||tr(pe),Ot=function(ri){var fi=W.apply(K,Dn([ri],Ee));return I&&on?fi[0]:fi};Tt&&R&&typeof Dt=="function"&&Dt.length!=1&&(be=Tt=!1);var on=this.__chain__,Mn=!!this.__actions__.length,rr=te&&!on,br=be&&!Mn;if(!te&&Tt){pe=br?pe:new ft(this);var ar=p.apply(pe,Ee);return ar.__actions__.push({func:g1,args:[Ot],thisArg:o}),new Wr(ar,on)}return rr&&br?p.apply(this,Ee):(ar=this.thru(Ot),rr?I?ar.value()[0]:ar.value():ar)})}),rt(["pop","push","shift","sort","splice","unshift"],function(p){var m=Qr[p],R=/^(?:push|sort|unshift)$/.test(p)?"tap":"thru",I=/^(?:pop|shift)$/.test(p);K.prototype[p]=function(){var W=arguments;if(I&&!this.__chain__){var te=this.value();return m.apply(tr(te)?te:[],W)}return this[R](function(pe){return m.apply(tr(pe)?pe:[],W)})}}),A(ft.prototype,function(p,m){var R=K[m];if(R){var I=R.name+"";ui.call(An,I)||(An[I]=[]),An[I].push({name:m,func:R})}}),An[ya(o,me).name]=[{name:"wrapper",func:o}],ft.prototype.clone=Di,ft.prototype.reverse=ru,ft.prototype.value=E0,K.prototype.at=J2,K.prototype.chain=qh,K.prototype.commit=Z2,K.prototype.next=Wh,K.prototype.plant=Em,K.prototype.reverse=Pf,K.prototype.toJSON=K.prototype.valueOf=K.prototype.value=If,K.prototype.first=K.prototype.head,Fu&&(K.prototype[Fu]=_m),K},to=eo();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(zi._=to,define(function(){return to})):H?((H.exports=to)._=to,U._=to):zi._=to}).call(Wv)});var ZE=nt((tH,JE)=>{"use strict";var Pi=JE.exports;JE.exports.default=Pi;var Eu="\x1B[",Uy="\x1B]",Vv="\x07",T_=";",aS=process.env.TERM_PROGRAM==="Apple_Terminal";Pi.cursorTo=(o,l)=>{if(typeof o!="number")throw new TypeError("The `x` argument is required");return typeof l!="number"?Eu+(o+1)+"G":Eu+(l+1)+";"+(o+1)+"H"};Pi.cursorMove=(o,l)=>{if(typeof o!="number")throw new TypeError("The `x` argument is required");let f="";return o<0?f+=Eu+-o+"D":o>0&&(f+=Eu+o+"C"),l<0?f+=Eu+-l+"A":l>0&&(f+=Eu+l+"B"),f};Pi.cursorUp=(o=1)=>Eu+o+"A";Pi.cursorDown=(o=1)=>Eu+o+"B";Pi.cursorForward=(o=1)=>Eu+o+"C";Pi.cursorBackward=(o=1)=>Eu+o+"D";Pi.cursorLeft=Eu+"G";Pi.cursorSavePosition=aS?"\x1B7":Eu+"s";Pi.cursorRestorePosition=aS?"\x1B8":Eu+"u";Pi.cursorGetPosition=Eu+"6n";Pi.cursorNextLine=Eu+"E";Pi.cursorPrevLine=Eu+"F";Pi.cursorHide=Eu+"?25l";Pi.cursorShow=Eu+"?25h";Pi.eraseLines=o=>{let l="";for(let f=0;f[Uy,"8",T_,T_,l,Vv,o,Uy,"8",T_,T_,Vv].join("");Pi.image=(o,l={})=>{let f=`${Uy}1337;File=inline=1`;return l.width&&(f+=`;width=${l.width}`),l.height&&(f+=`;height=${l.height}`),l.preserveAspectRatio===!1&&(f+=";preserveAspectRatio=0"),f+":"+o.toString("base64")+Vv};Pi.iTerm={setCwd:(o=process.cwd())=>`${Uy}50;CurrentDir=${o}${Vv}`,annotation:(o,l={})=>{let f=`${Uy}1337;`,h=typeof l.x<"u",E=typeof l.y<"u";if((h||E)&&!(h&&E&&typeof l.length<"u"))throw new Error("`x`, `y` and `length` must be defined when `x` or `y` is defined");return o=o.replace(/\|/g,""),f+=l.isHidden?"AddHiddenAnnotation=":"AddAnnotation=",l.length>0?f+=(h?[o,l.length,l.x,l.y]:[l.length,o]).join("|"):f+=o,f+Vv}}});var cS=nt((nH,$E)=>{"use strict";var fS=(o,l)=>{for(let f of Reflect.ownKeys(l))Object.defineProperty(o,f,Object.getOwnPropertyDescriptor(l,f));return o};$E.exports=fS;$E.exports.default=fS});var pS=nt((rH,x_)=>{"use strict";var fP=cS(),C_=new WeakMap,dS=(o,l={})=>{if(typeof o!="function")throw new TypeError("Expected a function");let f,h=0,E=o.displayName||o.name||"",t=function(...N){if(C_.set(t,++h),h===1)f=o.apply(this,N),o=null;else if(l.throw===!0)throw new Error(`Function \`${E}\` can only be called once`);return f};return fP(t,o),C_.set(t,h),t};x_.exports=dS;x_.exports.default=dS;x_.exports.callCount=o=>{if(!C_.has(o))throw new Error(`The given function \`${o.name}\` is not wrapped by the \`onetime\` package`);return C_.get(o)}});var hS=nt((iH,R_)=>{R_.exports=["SIGABRT","SIGALRM","SIGHUP","SIGINT","SIGTERM"];process.platform!=="win32"&&R_.exports.push("SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&R_.exports.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT","SIGUNUSED")});var nD=nt((uH,Kv)=>{var w0=global.process,Jp=function(o){return o&&typeof o=="object"&&typeof o.removeListener=="function"&&typeof o.emit=="function"&&typeof o.reallyExit=="function"&&typeof o.listeners=="function"&&typeof o.kill=="function"&&typeof o.pid=="number"&&typeof o.on=="function"};Jp(w0)?(vS=hi("assert"),Gv=hS(),mS=/^win/i.test(w0.platform),jy=hi("events"),typeof jy!="function"&&(jy=jy.EventEmitter),w0.__signal_exit_emitter__?wl=w0.__signal_exit_emitter__:(wl=w0.__signal_exit_emitter__=new jy,wl.count=0,wl.emitted={}),wl.infinite||(wl.setMaxListeners(1/0),wl.infinite=!0),Kv.exports=function(o,l){if(!Jp(global.process))return function(){};vS.equal(typeof o,"function","a callback must be provided for exit handler"),Yv===!1&&eD();var f="exit";l&&l.alwaysLast&&(f="afterexit");var h=function(){wl.removeListener(f,o),wl.listeners("exit").length===0&&wl.listeners("afterexit").length===0&&A_()};return wl.on(f,o),h},A_=function(){!Yv||!Jp(global.process)||(Yv=!1,Gv.forEach(function(l){try{w0.removeListener(l,O_[l])}catch{}}),w0.emit=M_,w0.reallyExit=tD,wl.count-=1)},Kv.exports.unload=A_,Zp=function(l,f,h){wl.emitted[l]||(wl.emitted[l]=!0,wl.emit(l,f,h))},O_={},Gv.forEach(function(o){O_[o]=function(){if(!!Jp(global.process)){var f=w0.listeners(o);f.length===wl.count&&(A_(),Zp("exit",null,o),Zp("afterexit",null,o),mS&&o==="SIGHUP"&&(o="SIGINT"),w0.kill(w0.pid,o))}}}),Kv.exports.signals=function(){return Gv},Yv=!1,eD=function(){Yv||!Jp(global.process)||(Yv=!0,wl.count+=1,Gv=Gv.filter(function(l){try{return w0.on(l,O_[l]),!0}catch{return!1}}),w0.emit=gS,w0.reallyExit=yS)},Kv.exports.load=eD,tD=w0.reallyExit,yS=function(l){!Jp(global.process)||(w0.exitCode=l||0,Zp("exit",w0.exitCode,null),Zp("afterexit",w0.exitCode,null),tD.call(w0,w0.exitCode))},M_=w0.emit,gS=function(l,f){if(l==="exit"&&Jp(global.process)){f!==void 0&&(w0.exitCode=f);var h=M_.apply(this,arguments);return Zp("exit",w0.exitCode,null),Zp("afterexit",w0.exitCode,null),h}else return M_.apply(this,arguments)}):Kv.exports=function(){return function(){}};var vS,Gv,mS,jy,wl,A_,Zp,O_,Yv,eD,tD,yS,M_,gS});var ES=nt((oH,_S)=>{"use strict";var cP=pS(),dP=nD();_S.exports=cP(()=>{dP(()=>{process.stderr.write("\x1B[?25h")},{alwaysLast:!0})})});var rD=nt(Xv=>{"use strict";var pP=ES(),k_=!1;Xv.show=(o=process.stderr)=>{!o.isTTY||(k_=!1,o.write("\x1B[?25h"))};Xv.hide=(o=process.stderr)=>{!o.isTTY||(pP(),k_=!0,o.write("\x1B[?25l"))};Xv.toggle=(o,l)=>{o!==void 0&&(k_=o),k_?Xv.show(l):Xv.hide(l)}});var TS=nt(zy=>{"use strict";var SS=zy&&zy.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(zy,"__esModule",{value:!0});var DS=SS(ZE()),wS=SS(rD()),hP=(o,{showCursor:l=!1}={})=>{let f=0,h="",E=!1,t=N=>{!l&&!E&&(wS.default.hide(),E=!0);let F=N+` +`;F!==h&&(h=F,o.write(DS.default.eraseLines(f)+F),f=F.split(` +`).length)};return t.clear=()=>{o.write(DS.default.eraseLines(f)),h="",f=0},t.done=()=>{h="",f=0,l||(wS.default.show(),E=!1)},t};zy.default={create:hP}});var CS=nt((aH,vP)=>{vP.exports=[{name:"AppVeyor",constant:"APPVEYOR",env:"APPVEYOR",pr:"APPVEYOR_PULL_REQUEST_NUMBER"},{name:"Azure Pipelines",constant:"AZURE_PIPELINES",env:"SYSTEM_TEAMFOUNDATIONCOLLECTIONURI",pr:"SYSTEM_PULLREQUEST_PULLREQUESTID"},{name:"Bamboo",constant:"BAMBOO",env:"bamboo_planKey"},{name:"Bitbucket Pipelines",constant:"BITBUCKET",env:"BITBUCKET_COMMIT",pr:"BITBUCKET_PR_ID"},{name:"Bitrise",constant:"BITRISE",env:"BITRISE_IO",pr:"BITRISE_PULL_REQUEST"},{name:"Buddy",constant:"BUDDY",env:"BUDDY_WORKSPACE_ID",pr:"BUDDY_EXECUTION_PULL_REQUEST_ID"},{name:"Buildkite",constant:"BUILDKITE",env:"BUILDKITE",pr:{env:"BUILDKITE_PULL_REQUEST",ne:"false"}},{name:"CircleCI",constant:"CIRCLE",env:"CIRCLECI",pr:"CIRCLE_PULL_REQUEST"},{name:"Cirrus CI",constant:"CIRRUS",env:"CIRRUS_CI",pr:"CIRRUS_PR"},{name:"AWS CodeBuild",constant:"CODEBUILD",env:"CODEBUILD_BUILD_ARN"},{name:"Codeship",constant:"CODESHIP",env:{CI_NAME:"codeship"}},{name:"Drone",constant:"DRONE",env:"DRONE",pr:{DRONE_BUILD_EVENT:"pull_request"}},{name:"dsari",constant:"DSARI",env:"DSARI"},{name:"GitLab CI",constant:"GITLAB",env:"GITLAB_CI"},{name:"GoCD",constant:"GOCD",env:"GO_PIPELINE_LABEL"},{name:"Hudson",constant:"HUDSON",env:"HUDSON_URL"},{name:"Jenkins",constant:"JENKINS",env:["JENKINS_URL","BUILD_ID"],pr:{any:["ghprbPullId","CHANGE_ID"]}},{name:"Magnum CI",constant:"MAGNUM",env:"MAGNUM"},{name:"Netlify CI",constant:"NETLIFY",env:"NETLIFY_BUILD_BASE",pr:{env:"PULL_REQUEST",ne:"false"}},{name:"Sail CI",constant:"SAIL",env:"SAILCI",pr:"SAIL_PULL_REQUEST_NUMBER"},{name:"Semaphore",constant:"SEMAPHORE",env:"SEMAPHORE",pr:"PULL_REQUEST_NUMBER"},{name:"Shippable",constant:"SHIPPABLE",env:"SHIPPABLE",pr:{IS_PULL_REQUEST:"true"}},{name:"Solano CI",constant:"SOLANO",env:"TDDIUM",pr:"TDDIUM_PR_ID"},{name:"Strider CD",constant:"STRIDER",env:"STRIDER"},{name:"TaskCluster",constant:"TASKCLUSTER",env:["TASK_ID","RUN_ID"]},{name:"TeamCity",constant:"TEAMCITY",env:"TEAMCITY_VERSION"},{name:"Travis CI",constant:"TRAVIS",env:"TRAVIS",pr:{env:"TRAVIS_PULL_REQUEST",ne:"false"}}]});var AS=nt(Fa=>{"use strict";var RS=CS(),Uc=process.env;Object.defineProperty(Fa,"_vendors",{value:RS.map(function(o){return o.constant})});Fa.name=null;Fa.isPR=null;RS.forEach(function(o){var l=Array.isArray(o.env)?o.env:[o.env],f=l.every(function(h){return xS(h)});if(Fa[o.constant]=f,f)switch(Fa.name=o.name,typeof o.pr){case"string":Fa.isPR=!!Uc[o.pr];break;case"object":"env"in o.pr?Fa.isPR=o.pr.env in Uc&&Uc[o.pr.env]!==o.pr.ne:"any"in o.pr?Fa.isPR=o.pr.any.some(function(h){return!!Uc[h]}):Fa.isPR=xS(o.pr);break;default:Fa.isPR=null}});Fa.isCI=!!(Uc.CI||Uc.CONTINUOUS_INTEGRATION||Uc.BUILD_NUMBER||Uc.RUN_ID||Fa.name);function xS(o){return typeof o=="string"?!!Uc[o]:Object.keys(o).every(function(l){return Uc[l]===o[l]})}});var MS=nt((cH,OS)=>{"use strict";OS.exports=AS().isCI});var NS=nt((dH,kS)=>{"use strict";var mP=o=>{let l=new Set;do for(let f of Reflect.ownKeys(o))l.add([o,f]);while((o=Reflect.getPrototypeOf(o))&&o!==Object.prototype);return l};kS.exports=(o,{include:l,exclude:f}={})=>{let h=E=>{let t=N=>typeof N=="string"?E===N:N.test(E);return l?l.some(t):f?!f.some(t):!0};for(let[E,t]of mP(o.constructor.prototype)){if(t==="constructor"||!h(t))continue;let N=Reflect.getOwnPropertyDescriptor(E,t);N&&typeof N.value=="function"&&(o[t]=o[t].bind(o))}return o}});var jS=nt(ou=>{"use strict";Object.defineProperty(ou,"__esModule",{value:!0});var Jv,Wy,I_,b_,fD;typeof window>"u"||typeof MessageChannel!="function"?(Qv=null,iD=null,uD=function(){if(Qv!==null)try{var o=ou.unstable_now();Qv(!0,o),Qv=null}catch(l){throw setTimeout(uD,0),l}},LS=Date.now(),ou.unstable_now=function(){return Date.now()-LS},Jv=function(o){Qv!==null?setTimeout(Jv,0,o):(Qv=o,setTimeout(uD,0))},Wy=function(o,l){iD=setTimeout(o,l)},I_=function(){clearTimeout(iD)},b_=function(){return!1},fD=ou.unstable_forceFrameRate=function(){}):(N_=window.performance,oD=window.Date,PS=window.setTimeout,IS=window.clearTimeout,typeof console<"u"&&(bS=window.cancelAnimationFrame,typeof window.requestAnimationFrame!="function"&&console.error("This browser doesn't support requestAnimationFrame. Make sure that you load a polyfill in older browsers. https://fb.me/react-polyfills"),typeof bS!="function"&&console.error("This browser doesn't support cancelAnimationFrame. Make sure that you load a polyfill in older browsers. https://fb.me/react-polyfills")),typeof N_=="object"&&typeof N_.now=="function"?ou.unstable_now=function(){return N_.now()}:(BS=oD.now(),ou.unstable_now=function(){return oD.now()-BS}),Hy=!1,qy=null,L_=-1,lD=5,sD=0,b_=function(){return ou.unstable_now()>=sD},fD=function(){},ou.unstable_forceFrameRate=function(o){0>o||125P_(N,f))k!==void 0&&0>P_(k,N)?(o[h]=k,o[F]=f,h=F):(o[h]=N,o[t]=f,h=t);else if(k!==void 0&&0>P_(k,f))o[h]=k,o[F]=f,h=F;else break e}}return l}return null}function P_(o,l){var f=o.sortIndex-l.sortIndex;return f!==0?f:o.id-l.id}var $f=[],f2=[],yP=1,Ls=null,ds=3,U_=!1,$p=!1,Vy=!1;function j_(o){for(var l=cf(f2);l!==null;){if(l.callback===null)B_(f2);else if(l.startTime<=o)B_(f2),l.sortIndex=l.expirationTime,cD($f,l);else break;l=cf(f2)}}function dD(o){if(Vy=!1,j_(o),!$p)if(cf($f)!==null)$p=!0,Jv(pD);else{var l=cf(f2);l!==null&&Wy(dD,l.startTime-o)}}function pD(o,l){$p=!1,Vy&&(Vy=!1,I_()),U_=!0;var f=ds;try{for(j_(l),Ls=cf($f);Ls!==null&&(!(Ls.expirationTime>l)||o&&!b_());){var h=Ls.callback;if(h!==null){Ls.callback=null,ds=Ls.priorityLevel;var E=h(Ls.expirationTime<=l);l=ou.unstable_now(),typeof E=="function"?Ls.callback=E:Ls===cf($f)&&B_($f),j_(l)}else B_($f);Ls=cf($f)}if(Ls!==null)var t=!0;else{var N=cf(f2);N!==null&&Wy(dD,N.startTime-l),t=!1}return t}finally{Ls=null,ds=f,U_=!1}}function US(o){switch(o){case 1:return-1;case 2:return 250;case 5:return 1073741823;case 4:return 1e4;default:return 5e3}}var gP=fD;ou.unstable_ImmediatePriority=1;ou.unstable_UserBlockingPriority=2;ou.unstable_NormalPriority=3;ou.unstable_IdlePriority=5;ou.unstable_LowPriority=4;ou.unstable_runWithPriority=function(o,l){switch(o){case 1:case 2:case 3:case 4:case 5:break;default:o=3}var f=ds;ds=o;try{return l()}finally{ds=f}};ou.unstable_next=function(o){switch(ds){case 1:case 2:case 3:var l=3;break;default:l=ds}var f=ds;ds=l;try{return o()}finally{ds=f}};ou.unstable_scheduleCallback=function(o,l,f){var h=ou.unstable_now();if(typeof f=="object"&&f!==null){var E=f.delay;E=typeof E=="number"&&0h?(o.sortIndex=E,cD(f2,o),cf($f)===null&&o===cf(f2)&&(Vy?I_():Vy=!0,Wy(dD,E-h))):(o.sortIndex=f,cD($f,o),$p||U_||($p=!0,Jv(pD))),o};ou.unstable_cancelCallback=function(o){o.callback=null};ou.unstable_wrapCallback=function(o){var l=ds;return function(){var f=ds;ds=l;try{return o.apply(this,arguments)}finally{ds=f}}};ou.unstable_getCurrentPriorityLevel=function(){return ds};ou.unstable_shouldYield=function(){var o=ou.unstable_now();j_(o);var l=cf($f);return l!==Ls&&Ls!==null&&l!==null&&l.callback!==null&&l.startTime<=o&&l.expirationTime{"use strict";process.env.NODE_ENV!=="production"&&function(){"use strict";Object.defineProperty(Ii,"__esModule",{value:!0});var o=!1,l=!1,f=!0,h,E,t,N,F;if(typeof window>"u"||typeof MessageChannel!="function"){var k=null,x=null,j=function(){if(k!==null)try{var St=Ii.unstable_now(),Bt=!0;k(Bt,St),k=null}catch(Hn){throw setTimeout(j,0),Hn}},q=Date.now();Ii.unstable_now=function(){return Date.now()-q},h=function(St){k!==null?setTimeout(h,0,St):(k=St,setTimeout(j,0))},E=function(St,Bt){x=setTimeout(St,Bt)},t=function(){clearTimeout(x)},N=function(){return!1},F=Ii.unstable_forceFrameRate=function(){}}else{var V=window.performance,re=window.Date,y=window.setTimeout,me=window.clearTimeout;if(typeof console<"u"){var De=window.requestAnimationFrame,ge=window.cancelAnimationFrame;typeof De!="function"&&console.error("This browser doesn't support requestAnimationFrame. Make sure that you load a polyfill in older browsers. https://fb.me/react-polyfills"),typeof ge!="function"&&console.error("This browser doesn't support cancelAnimationFrame. Make sure that you load a polyfill in older browsers. https://fb.me/react-polyfills")}if(typeof V=="object"&&typeof V.now=="function")Ii.unstable_now=function(){return V.now()};else{var ae=re.now();Ii.unstable_now=function(){return re.now()-ae}}var we=!1,he=null,ve=-1,ue=5,Ae=0,ze=300,We=!1;if(l&&navigator!==void 0&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0){var gt=navigator.scheduling;N=function(){var St=Ii.unstable_now();return St>=Ae?We||gt.isInputPending()?!0:St>=ze:!1},F=function(){We=!0}}else N=function(){return Ii.unstable_now()>=Ae},F=function(){};Ii.unstable_forceFrameRate=function(St){if(St<0||St>125){console.error("forceFrameRate takes a positive int between 0 and 125, forcing framerates higher than 125 fps is not unsupported");return}St>0?ue=Math.floor(1e3/St):ue=5};var _t=function(){if(he!==null){var St=Ii.unstable_now();Ae=St+ue;var Bt=!0;try{var Hn=he(Bt,St);Hn?ot.postMessage(null):(we=!1,he=null)}catch(qr){throw ot.postMessage(null),qr}}else we=!1;We=!1},Qe=new MessageChannel,ot=Qe.port2;Qe.port1.onmessage=_t,h=function(St){he=St,we||(we=!0,ot.postMessage(null))},E=function(St,Bt){ve=y(function(){St(Ii.unstable_now())},Bt)},t=function(){me(ve),ve=-1}}function Ve(St,Bt){var Hn=St.length;St.push(Bt),it(St,Bt,Hn)}function Pt(St){var Bt=St[0];return Bt===void 0?null:Bt}function Jt(St){var Bt=St[0];if(Bt!==void 0){var Hn=St.pop();return Hn!==Bt&&(St[0]=Hn,J(St,Hn,0)),Bt}else return null}function it(St,Bt,Hn){for(var qr=Hn;;){var Ki=Math.floor((qr-1)/2),Xr=St[Ki];if(Xr!==void 0&&ce(Xr,Bt)>0)St[Ki]=Bt,St[qr]=Xr,qr=Ki;else return}}function J(St,Bt,Hn){for(var qr=Hn,Ki=St.length;qrfr){if(fr*=2,fr>jr){console.error("Scheduler Profiling: Event log exceeded maximum size. Don't forget to call `stopLoggingProfilingEvents()`."),Dr();return}var Hn=new Int32Array(fr*4);Hn.set(Xt),zr=Hn.buffer,Xt=Hn}Xt.set(St,Bt)}}function vi(){fr=vr,zr=new ArrayBuffer(fr*4),Xt=new Int32Array(zr),Du=0}function Dr(){var St=zr;return fr=0,zr=null,Xt=null,Du=0,St}function el(St,Bt){f&&(Vt[Xn]++,Xt!==null&&lu([c0,Bt*1e3,St.id,St.priorityLevel]))}function Y0(St,Bt){f&&(Vt[Er]=Re,Vt[S]=0,Vt[Xn]--,Xt!==null&&lu([Ao,Bt*1e3,St.id]))}function Bu(St,Bt){f&&(Vt[Xn]--,Xt!==null&&lu([Fs,Bt*1e3,St.id]))}function K0(St,Bt){f&&(Vt[Er]=Re,Vt[S]=0,Vt[Xn]--,Xt!==null&&lu([Jo,Bt*1e3,St.id]))}function Kr(St,Bt){f&&(an++,Vt[Er]=St.priorityLevel,Vt[S]=St.id,Vt[zt]=an,Xt!==null&&lu([Zo,Bt*1e3,St.id,an]))}function Oo(St,Bt){f&&(Vt[Er]=Re,Vt[S]=0,Vt[zt]=0,Xt!==null&&lu([$o,Bt*1e3,St.id,an]))}function Mo(St){f&&(On++,Xt!==null&&lu([qt,St*1e3,On]))}function F0(St){f&&Xt!==null&&lu([xi,St*1e3,On])}var su=1073741823,ki=-1,Ps=250,Kl=5e3,P0=1e4,d0=su,Hr=[],Ri=[],X0=1,mi=!1,en=null,In=dt,Ai=!1,yi=!1,Wt=!1;function Ru(St){for(var Bt=Pt(Ri);Bt!==null;){if(Bt.callback===null)Jt(Ri);else if(Bt.startTime<=St)Jt(Ri),Bt.sortIndex=Bt.expirationTime,Ve(Hr,Bt),f&&(el(Bt,St),Bt.isQueued=!0);else return;Bt=Pt(Ri)}}function eu(St){if(Wt=!1,Ru(St),!yi)if(Pt(Hr)!==null)yi=!0,h(Q0);else{var Bt=Pt(Ri);Bt!==null&&E(eu,Bt.startTime-St)}}function Q0(St,Bt){f&&F0(Bt),yi=!1,Wt&&(Wt=!1,t()),Ai=!0;var Hn=In;try{if(f)try{return Yi(St,Bt)}catch(Xr){if(en!==null){var qr=Ii.unstable_now();K0(en,qr),en.isQueued=!1}throw Xr}else return Yi(St,Bt)}finally{if(en=null,In=Hn,Ai=!1,f){var Ki=Ii.unstable_now();Mo(Ki)}}}function Yi(St,Bt){var Hn=Bt;for(Ru(Hn),en=Pt(Hr);en!==null&&!(o&&mi)&&!(en.expirationTime>Hn&&(!St||N()));){var qr=en.callback;if(qr!==null){en.callback=null,In=en.priorityLevel;var Ki=en.expirationTime<=Hn;Kr(en,Hn);var Xr=qr(Ki);Hn=Ii.unstable_now(),typeof Xr=="function"?(en.callback=Xr,Oo(en,Hn)):(f&&(Y0(en,Hn),en.isQueued=!1),en===Pt(Hr)&&Jt(Hr)),Ru(Hn)}else Jt(Hr);en=Pt(Hr)}if(en!==null)return!0;var Au=Pt(Ri);return Au!==null&&E(eu,Au.startTime-Hn),!1}function Xl(St,Bt){switch(St){case le:case He:case dt:case At:case nn:break;default:St=dt}var Hn=In;In=St;try{return Bt()}finally{In=Hn}}function ko(St){var Bt;switch(In){case le:case He:case dt:Bt=dt;break;default:Bt=In;break}var Hn=In;In=Bt;try{return St()}finally{In=Hn}}function li(St){var Bt=In;return function(){var Hn=In;In=Bt;try{return St.apply(this,arguments)}finally{In=Hn}}}function ao(St){switch(St){case le:return ki;case He:return Ps;case nn:return d0;case At:return P0;case dt:default:return Kl}}function Ql(St,Bt,Hn){var qr=Ii.unstable_now(),Ki,Xr;if(typeof Hn=="object"&&Hn!==null){var Au=Hn.delay;typeof Au=="number"&&Au>0?Ki=qr+Au:Ki=qr,Xr=typeof Hn.timeout=="number"?Hn.timeout:ao(St)}else Xr=ao(St),Ki=qr;var p0=Ki+Xr,Ni={id:X0++,callback:Bt,priorityLevel:St,startTime:Ki,expirationTime:p0,sortIndex:-1};return f&&(Ni.isQueued=!1),Ki>qr?(Ni.sortIndex=Ki,Ve(Ri,Ni),Pt(Hr)===null&&Ni===Pt(Ri)&&(Wt?t():Wt=!0,E(eu,Ki-qr))):(Ni.sortIndex=p0,Ve(Hr,Ni),f&&(el(Ni,qr),Ni.isQueued=!0),!yi&&!Ai&&(yi=!0,h(Q0))),Ni}function No(){mi=!0}function Is(){mi=!1,!yi&&!Ai&&(yi=!0,h(Q0))}function $n(){return Pt(Hr)}function tl(St){if(f&&St.isQueued){var Bt=Ii.unstable_now();Bu(St,Bt),St.isQueued=!1}St.callback=null}function fo(){return In}function I0(){var St=Ii.unstable_now();Ru(St);var Bt=Pt(Hr);return Bt!==en&&en!==null&&Bt!==null&&Bt.callback!==null&&Bt.startTime<=St&&Bt.expirationTime{"use strict";process.env.NODE_ENV==="production"?hD.exports=jS():hD.exports=zS()});var HS=nt((mH,Gy)=>{Gy.exports=function o(l){"use strict";var f=Py(),h=Mi(),E=z_();function t(_){for(var g="https://reactjs.org/docs/error-decoder.html?invariant="+_,A=1;AX0||(_.current=Ri[X0],Ri[X0]=null,X0--)}function en(_,g){X0++,Ri[X0]=_.current,_.current=g}var In={},Ai={current:In},yi={current:!1},Wt=In;function Ru(_,g){var A=_.type.contextTypes;if(!A)return In;var P=_.stateNode;if(P&&P.__reactInternalMemoizedUnmaskedChildContext===g)return P.__reactInternalMemoizedMaskedChildContext;var B={},Z;for(Z in A)B[Z]=g[Z];return P&&(_=_.stateNode,_.__reactInternalMemoizedUnmaskedChildContext=g,_.__reactInternalMemoizedMaskedChildContext=B),B}function eu(_){return _=_.childContextTypes,_!=null}function Q0(_){mi(yi,_),mi(Ai,_)}function Yi(_){mi(yi,_),mi(Ai,_)}function Xl(_,g,A){if(Ai.current!==In)throw Error(t(168));en(Ai,g,_),en(yi,A,_)}function ko(_,g,A){var P=_.stateNode;if(_=g.childContextTypes,typeof P.getChildContext!="function")return A;P=P.getChildContext();for(var B in P)if(!(B in _))throw Error(t(108,ze(g)||"Unknown",B));return f({},A,{},P)}function li(_){var g=_.stateNode;return g=g&&g.__reactInternalMemoizedMergedChildContext||In,Wt=Ai.current,en(Ai,g,_),en(yi,yi.current,_),!0}function ao(_,g,A){var P=_.stateNode;if(!P)throw Error(t(169));A?(g=ko(_,g,Wt),P.__reactInternalMemoizedMergedChildContext=g,mi(yi,_),mi(Ai,_),en(Ai,g,_)):mi(yi,_),en(yi,A,_)}var Ql=E.unstable_runWithPriority,No=E.unstable_scheduleCallback,Is=E.unstable_cancelCallback,$n=E.unstable_shouldYield,tl=E.unstable_requestPaint,fo=E.unstable_now,I0=E.unstable_getCurrentPriorityLevel,Sl=E.unstable_ImmediatePriority,Lo=E.unstable_UserBlockingPriority,St=E.unstable_NormalPriority,Bt=E.unstable_LowPriority,Hn=E.unstable_IdlePriority,qr={},Ki=tl!==void 0?tl:function(){},Xr=null,Au=null,p0=!1,Ni=fo(),h0=1e4>Ni?fo:function(){return fo()-Ni};function hs(){switch(I0()){case Sl:return 99;case Lo:return 98;case St:return 97;case Bt:return 96;case Hn:return 95;default:throw Error(t(332))}}function Ct(_){switch(_){case 99:return Sl;case 98:return Lo;case 97:return St;case 96:return Bt;case 95:return Hn;default:throw Error(t(332))}}function co(_,g){return _=Ct(_),Ql(_,g)}function nl(_,g,A){return _=Ct(_),No(_,g,A)}function Jl(_){return Xr===null?(Xr=[_],Au=No(Sl,vs)):Xr.push(_),qr}function Uu(){if(Au!==null){var _=Au;Au=null,Is(_)}vs()}function vs(){if(!p0&&Xr!==null){p0=!0;var _=0;try{var g=Xr;co(99,function(){for(;_=g&&(ho=!0),_.firstContext=null)}function Mu(_,g){if(Ou!==_&&g!==!1&&g!==0)if((typeof g!="number"||g===1073741823)&&(Ou=_,g=1073741823),g={context:_,observedBits:g,next:null},Si===null){if(cr===null)throw Error(t(308));Si=g,cr.dependencies={expirationTime:0,firstContext:g,responders:null}}else Si=Si.next=g;return ln?_._currentValue:_._currentValue2}var po=!1;function Hu(_){return{baseState:_,firstUpdate:null,lastUpdate:null,firstCapturedUpdate:null,lastCapturedUpdate:null,firstEffect:null,lastEffect:null,firstCapturedEffect:null,lastCapturedEffect:null}}function Pa(_){return{baseState:_.baseState,firstUpdate:_.firstUpdate,lastUpdate:_.lastUpdate,firstCapturedUpdate:null,lastCapturedUpdate:null,firstEffect:null,lastEffect:null,firstCapturedEffect:null,lastCapturedEffect:null}}function v0(_,g){return{expirationTime:_,suspenseConfig:g,tag:0,payload:null,callback:null,next:null,nextEffect:null}}function ia(_,g){_.lastUpdate===null?_.firstUpdate=_.lastUpdate=g:(_.lastUpdate.next=g,_.lastUpdate=g)}function J0(_,g){var A=_.alternate;if(A===null){var P=_.updateQueue,B=null;P===null&&(P=_.updateQueue=Hu(_.memoizedState))}else P=_.updateQueue,B=A.updateQueue,P===null?B===null?(P=_.updateQueue=Hu(_.memoizedState),B=A.updateQueue=Hu(A.memoizedState)):P=_.updateQueue=Pa(B):B===null&&(B=A.updateQueue=Pa(P));B===null||P===B?ia(P,g):P.lastUpdate===null||B.lastUpdate===null?(ia(P,g),ia(B,g)):(ia(P,g),B.lastUpdate=g)}function ua(_,g){var A=_.updateQueue;A=A===null?_.updateQueue=Hu(_.memoizedState):Ia(_,A),A.lastCapturedUpdate===null?A.firstCapturedUpdate=A.lastCapturedUpdate=g:(A.lastCapturedUpdate.next=g,A.lastCapturedUpdate=g)}function Ia(_,g){var A=_.alternate;return A!==null&&g===A.updateQueue&&(g=_.updateQueue=Pa(g)),g}function ms(_,g,A,P,B,Z){switch(A.tag){case 1:return _=A.payload,typeof _=="function"?_.call(Z,P,B):_;case 3:_.effectTag=_.effectTag&-4097|64;case 0:if(_=A.payload,B=typeof _=="function"?_.call(Z,P,B):_,B==null)break;return f({},P,B);case 2:po=!0}return P}function S0(_,g,A,P,B){po=!1,g=Ia(_,g);for(var Z=g.baseState,de=null,yt=0,Rt=g.firstUpdate,Nt=Z;Rt!==null;){var xr=Rt.expirationTime;xrai?(Qi=ur,ur=null):Qi=ur.sibling;var Vr=cu(Ge,ur,st[ai],$t);if(Vr===null){ur===null&&(ur=Qi);break}_&&ur&&Vr.alternate===null&&g(Ge,ur),je=Z(Vr,je,ai),oi===null?Wn=Vr:oi.sibling=Vr,oi=Vr,ur=Qi}if(ai===st.length)return A(Ge,ur),Wn;if(ur===null){for(;aiai?(Qi=ur,ur=null):Qi=ur.sibling;var Tu=cu(Ge,ur,Vr.value,$t);if(Tu===null){ur===null&&(ur=Qi);break}_&&ur&&Tu.alternate===null&&g(Ge,ur),je=Z(Tu,je,ai),oi===null?Wn=Tu:oi.sibling=Tu,oi=Tu,ur=Qi}if(Vr.done)return A(Ge,ur),Wn;if(ur===null){for(;!Vr.done;ai++,Vr=st.next())Vr=r0(Ge,Vr.value,$t),Vr!==null&&(je=Z(Vr,je,ai),oi===null?Wn=Vr:oi.sibling=Vr,oi=Vr);return Wn}for(ur=P(Ge,ur);!Vr.done;ai++,Vr=st.next())Vr=z0(ur,Ge,ai,Vr.value,$t),Vr!==null&&(_&&Vr.alternate!==null&&ur.delete(Vr.key===null?ai:Vr.key),je=Z(Vr,je,ai),oi===null?Wn=Vr:oi.sibling=Vr,oi=Vr);return _&&ur.forEach(function(Wa){return g(Ge,Wa)}),Wn}return function(Ge,je,st,$t){var Wn=typeof st=="object"&&st!==null&&st.type===j&&st.key===null;Wn&&(st=st.props.children);var oi=typeof st=="object"&&st!==null;if(oi)switch(st.$$typeof){case k:e:{for(oi=st.key,Wn=je;Wn!==null;){if(Wn.key===oi)if(Wn.tag===7?st.type===j:Wn.elementType===st.type){A(Ge,Wn.sibling),je=B(Wn,st.type===j?st.props.children:st.props,$t),je.ref=Us(Ge,Wn,st),je.return=Ge,Ge=je;break e}else{A(Ge,Wn);break}else g(Ge,Wn);Wn=Wn.sibling}st.type===j?(je=n0(st.props.children,Ge.mode,$t,st.key),je.return=Ge,Ge=je):($t=qa(st.type,st.key,st.props,null,Ge.mode,$t),$t.ref=Us(Ge,je,st),$t.return=Ge,Ge=$t)}return de(Ge);case x:e:{for(Wn=st.key;je!==null;){if(je.key===Wn)if(je.tag===4&&je.stateNode.containerInfo===st.containerInfo&&je.stateNode.implementation===st.implementation){A(Ge,je.sibling),je=B(je,st.children||[],$t),je.return=Ge,Ge=je;break e}else{A(Ge,je);break}else g(Ge,je);je=je.sibling}je=Df(st,Ge.mode,$t),je.return=Ge,Ge=je}return de(Ge)}if(typeof st=="string"||typeof st=="number")return st=""+st,je!==null&&je.tag===6?(A(Ge,je.sibling),je=B(je,st,$t),je.return=Ge,Ge=je):(A(Ge,je),je=j0(st,Ge.mode,$t),je.return=Ge,Ge=je),de(Ge);if(m0(st))return Ml(Ge,je,st,$t);if(ue(st))return i0(Ge,je,st,$t);if(oi&&zi(Ge,st),typeof st>"u"&&!Wn)switch(Ge.tag){case 1:case 0:throw Ge=Ge.type,Error(t(152,Ge.displayName||Ge.name||"Component"))}return A(Ge,je)}}var H=U(!0),Y=U(!1),ee={},Ce={current:ee},_e={current:ee},Oe={current:ee};function $(_){if(_===ee)throw Error(t(174));return _}function Ne(_,g){en(Oe,g,_),en(_e,_,_),en(Ce,ee,_),g=Pt(g),mi(Ce,_),en(Ce,g,_)}function Je(_){mi(Ce,_),mi(_e,_),mi(Oe,_)}function vt(_){var g=$(Oe.current),A=$(Ce.current);g=Jt(A,_.type,g),A!==g&&(en(_e,_,_),en(Ce,g,_))}function oe(_){_e.current===_&&(mi(Ce,_),mi(_e,_))}var qe={current:0};function rt(_){for(var g=_;g!==null;){if(g.tag===13){var A=g.memoizedState;if(A!==null&&(A=A.dehydrated,A===null||Kr(A)||Oo(A)))return g}else if(g.tag===19&&g.memoizedProps.revealOrder!==void 0){if((g.effectTag&64)!==0)return g}else if(g.child!==null){g.child.return=g,g=g.child;continue}if(g===_)break;for(;g.sibling===null;){if(g.return===null||g.return===_)return null;g=g.return}g.sibling.return=g.return,g=g.sibling}return null}function xt(_,g){return{responder:_,props:g}}var kt=N.ReactCurrentDispatcher,bt=N.ReactCurrentBatchConfig,sn=0,rn=null,Ft=null,Dn=null,dr=null,er=null,Cr=null,Rn=0,Nr=null,y0=0,Lr=!1,ut=null,wt=0;function et(){throw Error(t(321))}function It(_,g){if(g===null)return!1;for(var A=0;ARn&&(Rn=xr,Ua(Rn))):(cc(xr,Rt.suspenseConfig),Z=Rt.eagerReducer===_?Rt.eagerState:_(Z,Rt.action)),de=Rt,Rt=Rt.next}while(Rt!==null&&Rt!==P);Nt||(yt=de,B=Z),Fe(Z,g.memoizedState)||(ho=!0),g.memoizedState=Z,g.baseUpdate=yt,g.baseState=B,A.lastRenderedState=Z}return[g.memoizedState,A.dispatch]}function T0(_){var g=Jn();return typeof _=="function"&&(_=_()),g.memoizedState=g.baseState=_,_=g.queue={last:null,dispatch:null,lastRenderedReducer:au,lastRenderedState:_},_=_.dispatch=js.bind(null,rn,_),[g.memoizedState,_]}function Z0(_){return ku(au,_)}function Nu(_,g,A,P){return _={tag:_,create:g,destroy:A,deps:P,next:null},Nr===null?(Nr={lastEffect:null},Nr.lastEffect=_.next=_):(g=Nr.lastEffect,g===null?Nr.lastEffect=_.next=_:(A=g.next,g.next=_,_.next=A,Nr.lastEffect=_)),_}function gi(_,g,A,P){var B=Jn();y0|=_,B.memoizedState=Nu(g,A,void 0,P===void 0?null:P)}function Po(_,g,A,P){var B=wr();P=P===void 0?null:P;var Z=void 0;if(Ft!==null){var de=Ft.memoizedState;if(Z=de.destroy,P!==null&&It(P,de.deps)){Nu(0,A,Z,P);return}}y0|=_,B.memoizedState=Nu(g,A,Z,P)}function rl(_,g){return gi(516,192,_,g)}function hf(_,g){return Po(516,192,_,g)}function Tl(_,g){if(typeof g=="function")return _=_(),g(_),function(){g(null)};if(g!=null)return _=_(),g.current=_,function(){g.current=null}}function vf(){}function Io(_,g){return Jn().memoizedState=[_,g===void 0?null:g],_}function ys(_,g){var A=wr();g=g===void 0?null:g;var P=A.memoizedState;return P!==null&&g!==null&&It(g,P[1])?P[0]:(A.memoizedState=[_,g],_)}function js(_,g,A){if(!(25>wt))throw Error(t(301));var P=_.alternate;if(_===rn||P!==null&&P===rn)if(Lr=!0,_={expirationTime:sn,suspenseConfig:null,action:A,eagerReducer:null,eagerState:null,next:null},ut===null&&(ut=new Map),A=ut.get(g),A===void 0)ut.set(g,_);else{for(g=A;g.next!==null;)g=g.next;g.next=_}else{var B=E0(),Z=si.suspense;B=Un(B,_,Z),Z={expirationTime:B,suspenseConfig:Z,action:A,eagerReducer:null,eagerState:null,next:null};var de=g.last;if(de===null)Z.next=Z;else{var yt=de.next;yt!==null&&(Z.next=yt),de.next=Z}if(g.last=Z,_.expirationTime===0&&(P===null||P.expirationTime===0)&&(P=g.lastRenderedReducer,P!==null))try{var Rt=g.lastRenderedState,Nt=P(Rt,A);if(Z.eagerReducer=P,Z.eagerState=Nt,Fe(Nt,Rt))return}catch{}finally{}e0(_,B)}}var bo={readContext:Mu,useCallback:et,useContext:et,useEffect:et,useImperativeHandle:et,useLayoutEffect:et,useMemo:et,useReducer:et,useRef:et,useState:et,useDebugValue:et,useResponder:et,useDeferredValue:et,useTransition:et},Bo={readContext:Mu,useCallback:Io,useContext:Mu,useEffect:rl,useImperativeHandle:function(_,g,A){return A=A!=null?A.concat([_]):null,gi(4,36,Tl.bind(null,g,_),A)},useLayoutEffect:function(_,g){return gi(4,36,_,g)},useMemo:function(_,g){var A=Jn();return g=g===void 0?null:g,_=_(),A.memoizedState=[_,g],_},useReducer:function(_,g,A){var P=Jn();return g=A!==void 0?A(g):g,P.memoizedState=P.baseState=g,_=P.queue={last:null,dispatch:null,lastRenderedReducer:_,lastRenderedState:g},_=_.dispatch=js.bind(null,rn,_),[P.memoizedState,_]},useRef:function(_){var g=Jn();return _={current:_},g.memoizedState=_},useState:T0,useDebugValue:vf,useResponder:xt,useDeferredValue:function(_,g){var A=T0(_),P=A[0],B=A[1];return rl(function(){E.unstable_next(function(){var Z=bt.suspense;bt.suspense=g===void 0?null:g;try{B(_)}finally{bt.suspense=Z}})},[_,g]),P},useTransition:function(_){var g=T0(!1),A=g[0],P=g[1];return[Io(function(B){P(!0),E.unstable_next(function(){var Z=bt.suspense;bt.suspense=_===void 0?null:_;try{P(!1),B()}finally{bt.suspense=Z}})},[_,A]),A]}},gs={readContext:Mu,useCallback:ys,useContext:Mu,useEffect:hf,useImperativeHandle:function(_,g,A){return A=A!=null?A.concat([_]):null,Po(4,36,Tl.bind(null,g,_),A)},useLayoutEffect:function(_,g){return Po(4,36,_,g)},useMemo:function(_,g){var A=wr();g=g===void 0?null:g;var P=A.memoizedState;return P!==null&&g!==null&&It(g,P[1])?P[0]:(_=_(),A.memoizedState=[_,g],_)},useReducer:ku,useRef:function(){return wr().memoizedState},useState:Z0,useDebugValue:vf,useResponder:xt,useDeferredValue:function(_,g){var A=Z0(_),P=A[0],B=A[1];return hf(function(){E.unstable_next(function(){var Z=bt.suspense;bt.suspense=g===void 0?null:g;try{B(_)}finally{bt.suspense=Z}})},[_,g]),P},useTransition:function(_){var g=Z0(!1),A=g[0],P=g[1];return[ys(function(B){P(!0),E.unstable_next(function(){var Z=bt.suspense;bt.suspense=_===void 0?null:_;try{P(!1),B()}finally{bt.suspense=Z}})},[_,A]),A]}},Xu=null,Su=null,_i=!1;function C0(_,g){var A=Ho(5,null,null,0);A.elementType="DELETED",A.type="DELETED",A.stateNode=g,A.return=_,A.effectTag=8,_.lastEffect!==null?(_.lastEffect.nextEffect=A,_.lastEffect=A):_.firstEffect=_.lastEffect=A}function $0(_,g){switch(_.tag){case 5:return g=Bu(g,_.type,_.pendingProps),g!==null?(_.stateNode=g,!0):!1;case 6:return g=K0(g,_.pendingProps),g!==null?(_.stateNode=g,!0):!1;case 13:return!1;default:return!1}}function Uo(_){if(_i){var g=Su;if(g){var A=g;if(!$0(_,g)){if(g=Mo(A),!g||!$0(_,g)){_.effectTag=_.effectTag&-1025|2,_i=!1,Xu=_;return}C0(Xu,A)}Xu=_,Su=F0(g)}else _.effectTag=_.effectTag&-1025|2,_i=!1,Xu=_}}function la(_){for(_=_.return;_!==null&&_.tag!==5&&_.tag!==3&&_.tag!==13;)_=_.return;Xu=_}function $l(_){if(!S||_!==Xu)return!1;if(!_i)return la(_),_i=!0,!1;var g=_.type;if(_.tag!==5||g!=="head"&&g!=="body"&&!dt(g,_.memoizedProps))for(g=Su;g;)C0(_,g),g=Mo(g);if(la(_),_.tag===13){if(!S)throw Error(t(316));if(_=_.memoizedState,_=_!==null?_.dehydrated:null,!_)throw Error(t(317));Su=Ps(_)}else Su=Xu?Mo(_.stateNode):null;return!0}function tu(){S&&(Su=Xu=null,_i=!1)}var Zr=N.ReactCurrentOwner,ho=!1;function Bi(_,g,A,P){g.child=_===null?Y(g,null,A,P):H(g,_.child,A,P)}function Ci(_,g,A,P,B){A=A.render;var Z=g.ref;return Fo(g,B),P=un(_,g,A,P,Z,B),_!==null&&!ho?(g.updateQueue=_.updateQueue,g.effectTag&=-517,_.expirationTime<=B&&(_.expirationTime=0),mu(_,g,B)):(g.effectTag|=1,Bi(_,g,P,B),g.child)}function mf(_,g,A,P,B,Z){if(_===null){var de=A.type;return typeof de=="function"&&!Ef(de)&&de.defaultProps===void 0&&A.compare===null&&A.defaultProps===void 0?(g.tag=15,g.type=de,yf(_,g,de,P,B,Z)):(_=qa(A.type,null,P,null,g.mode,Z),_.ref=g.ref,_.return=g,g.child=_)}return de=_.child,Bg)&&Wr.set(_,g)))}}function ro(_,g){_.expirationTime_?g:_)}function t0(_){if(_.lastExpiredTime!==0)_.callbackExpirationTime=1073741823,_.callbackPriority=99,_.callbackNode=Jl(io.bind(null,_));else{var g=mo(_),A=_.callbackNode;if(g===0)A!==null&&(_.callbackNode=null,_.callbackExpirationTime=0,_.callbackPriority=90);else{var P=E0();if(g===1073741823?P=99:g===1||g===2?P=95:(P=10*(1073741821-g)-10*(1073741821-P),P=0>=P?99:250>=P?98:5250>=P?97:95),A!==null){var B=_.callbackPriority;if(_.callbackExpirationTime===g&&B>=P)return;A!==qr&&Is(A)}_.callbackExpirationTime=g,_.callbackPriority=P,g=g===1073741823?Jl(io.bind(null,_)):nl(P,jo.bind(null,_),{timeout:10*(1073741821-g)-h0()}),_.callbackNode=g}}}function jo(_,g){if(ru=0,g)return g=E0(),da(_,g),t0(_),null;var A=mo(_);if(A!==0){if(g=_.callbackNode,(Ln&(nu|fu))!==Rr)throw Error(t(327));if(qs(),_===fe&&A===Pe||Ds(_,A),ie!==null){var P=Ln;Ln|=nu;var B=U0(_);do try{nd();break}catch(yt){fa(_,yt)}while(1);if(ju(),Ln=P,Zu.current=B,Me===ei)throw g=at,Ds(_,A),Ol(_,A),t0(_),g;if(ie===null)switch(B=_.finishedWork=_.current.alternate,_.finishedExpirationTime=A,P=Me,fe=null,P){case Li:case ei:throw Error(t(345));case Kn:da(_,2=A){_.lastPingedTime=A,Ds(_,A);break}}if(Z=mo(_),Z!==0&&Z!==A)break;if(P!==0&&P!==A){_.lastPingedTime=P;break}_.timeoutHandle=an(Rl.bind(null,_),B);break}Rl(_);break;case g0:if(Ol(_,A),P=_.lastSuspendedTime,A===P&&(_.nextKnownPendingLevel=qc(B)),_n&&(B=_.lastPingedTime,B===0||B>=A)){_.lastPingedTime=A,Ds(_,A);break}if(B=mo(_),B!==0&&B!==A)break;if(P!==0&&P!==A){_.lastPingedTime=P;break}if(Qt!==1073741823?P=10*(1073741821-Qt)-h0():mt===1073741823?P=0:(P=10*(1073741821-mt)-5e3,B=h0(),A=10*(1073741821-A)-B,P=B-P,0>P&&(P=0),P=(120>P?120:480>P?480:1080>P?1080:1920>P?1920:3e3>P?3e3:4320>P?4320:1960*gf(P/1960))-P,A=P?P=0:(B=de.busyDelayMs|0,Z=h0()-(10*(1073741821-Z)-(de.timeoutMs|0||5e3)),P=Z<=B?0:B+P-Z),10 component higher in the tree to provide a loading indicator or placeholder to display.`+Hr(B))}Me!==_0&&(Me=Kn),Z=Cl(Z,B),Rt=P;do{switch(Rt.tag){case 3:de=Z,Rt.effectTag|=4096,Rt.expirationTime=g;var je=_s(Rt,de,g);ua(Rt,je);break e;case 1:de=Z;var st=Rt.type,$t=Rt.stateNode;if((Rt.effectTag&64)===0&&(typeof st.getDerivedStateFromError=="function"||$t!==null&&typeof $t.componentDidCatch=="function"&&(mr===null||!mr.has($t)))){Rt.effectTag|=4096,Rt.expirationTime=g;var Wn=aa(Rt,de,g);ua(Rt,Wn);break e}}Rt=Rt.return}while(Rt!==null)}ie=yo(ie)}catch(oi){g=oi;continue}break}while(1)}function U0(){var _=Zu.current;return Zu.current=bo,_===null?bo:_}function cc(_,g){_Sn&&(Sn=_)}function _2(){for(;ie!==null;)ie=rd(ie)}function nd(){for(;ie!==null&&!$n();)ie=rd(ie)}function rd(_){var g=Ha(_.alternate,_,Pe);return _.memoizedProps=_.pendingProps,g===null&&(g=yo(_)),Es.current=null,g}function yo(_){ie=_;do{var g=ie.alternate;if(_=ie.return,(ie.effectTag&2048)===0){e:{var A=g;g=ie;var P=Pe,B=g.pendingProps;switch(g.tag){case 2:break;case 16:break;case 15:case 0:break;case 1:eu(g.type)&&Q0(g);break;case 3:Je(g),Yi(g),B=g.stateNode,B.pendingContext&&(B.context=B.pendingContext,B.pendingContext=null),(A===null||A.child===null)&&$l(g)&&Qu(g),Qr(g);break;case 5:oe(g);var Z=$(Oe.current);if(P=g.type,A!==null&&g.stateNode!=null)qu(A,g,P,B,Z),A.ref!==g.ref&&(g.effectTag|=128);else if(B){if(A=$(Ce.current),$l(g)){if(B=g,!S)throw Error(t(175));A=su(B.stateNode,B.type,B.memoizedProps,Z,A,B),B.updateQueue=A,A=A!==null,A&&Qu(g)}else{var de=ce(P,B,Z,A,g);$r(de,g,!1,!1),g.stateNode=de,le(de,P,B,Z,A)&&Qu(g)}g.ref!==null&&(g.effectTag|=128)}else if(g.stateNode===null)throw Error(t(166));break;case 6:if(A&&g.stateNode!=null)xn(A,g,A.memoizedProps,B);else{if(typeof B!="string"&&g.stateNode===null)throw Error(t(166));if(A=$(Oe.current),Z=$(Ce.current),$l(g)){if(A=g,!S)throw Error(t(176));(A=ki(A.stateNode,A.memoizedProps,A))&&Qu(g)}else g.stateNode=nn(B,A,Z,g)}break;case 11:break;case 13:if(mi(qe,g),B=g.memoizedState,(g.effectTag&64)!==0){g.expirationTime=P;break e}B=B!==null,Z=!1,A===null?g.memoizedProps.fallback!==void 0&&$l(g):(P=A.memoizedState,Z=P!==null,B||P===null||(P=A.child.sibling,P!==null&&(de=g.firstEffect,de!==null?(g.firstEffect=P,P.nextEffect=de):(g.firstEffect=g.lastEffect=P,P.nextEffect=null),P.effectTag=8))),B&&!Z&&(g.mode&2)!==0&&(A===null&&g.memoizedProps.unstable_avoidThisFallback!==!0||(qe.current&1)!==0?Me===Li&&(Me=$u):((Me===Li||Me===$u)&&(Me=g0),Sn!==0&&fe!==null&&(Ol(fe,Pe),Ts(fe,Sn)))),Er&&B&&(g.effectTag|=4),Vt&&(B||Z)&&(g.effectTag|=4);break;case 7:break;case 8:break;case 12:break;case 4:Je(g),Qr(g);break;case 10:wu(g);break;case 9:break;case 14:break;case 17:eu(g.type)&&Q0(g);break;case 19:if(mi(qe,g),B=g.memoizedState,B===null)break;if(Z=(g.effectTag&64)!==0,de=B.rendering,de===null){if(Z)Lu(B,!1);else if(Me!==Li||A!==null&&(A.effectTag&64)!==0)for(A=g.child;A!==null;){if(de=rt(A),de!==null){for(g.effectTag|=64,Lu(B,!1),A=de.updateQueue,A!==null&&(g.updateQueue=A,g.effectTag|=4),B.lastEffect===null&&(g.firstEffect=null),g.lastEffect=B.lastEffect,A=P,B=g.child;B!==null;)Z=B,P=A,Z.effectTag&=2,Z.nextEffect=null,Z.firstEffect=null,Z.lastEffect=null,de=Z.alternate,de===null?(Z.childExpirationTime=0,Z.expirationTime=P,Z.child=null,Z.memoizedProps=null,Z.memoizedState=null,Z.updateQueue=null,Z.dependencies=null):(Z.childExpirationTime=de.childExpirationTime,Z.expirationTime=de.expirationTime,Z.child=de.child,Z.memoizedProps=de.memoizedProps,Z.memoizedState=de.memoizedState,Z.updateQueue=de.updateQueue,P=de.dependencies,Z.dependencies=P===null?null:{expirationTime:P.expirationTime,firstContext:P.firstContext,responders:P.responders}),B=B.sibling;en(qe,qe.current&1|2,g),g=g.child;break e}A=A.sibling}}else{if(!Z)if(A=rt(de),A!==null){if(g.effectTag|=64,Z=!0,A=A.updateQueue,A!==null&&(g.updateQueue=A,g.effectTag|=4),Lu(B,!0),B.tail===null&&B.tailMode==="hidden"&&!de.alternate){g=g.lastEffect=B.lastEffect,g!==null&&(g.nextEffect=null);break}}else h0()>B.tailExpiration&&1B&&(B=P),de>B&&(B=de),Z=Z.sibling;A.childExpirationTime=B}if(g!==null)return g;_!==null&&(_.effectTag&2048)===0&&(_.firstEffect===null&&(_.firstEffect=ie.firstEffect),ie.lastEffect!==null&&(_.lastEffect!==null&&(_.lastEffect.nextEffect=ie.firstEffect),_.lastEffect=ie.lastEffect),1_?g:_}function Rl(_){var g=hs();return co(99,ul.bind(null,_,g)),null}function ul(_,g){do qs();while(ti!==null);if((Ln&(nu|fu))!==Rr)throw Error(t(327));var A=_.finishedWork,P=_.finishedExpirationTime;if(A===null)return null;if(_.finishedWork=null,_.finishedExpirationTime=0,A===_.current)throw Error(t(177));_.callbackNode=null,_.callbackExpirationTime=0,_.callbackPriority=90,_.nextKnownPendingLevel=0;var B=qc(A);if(_.firstPendingTime=B,P<=_.lastSuspendedTime?_.firstSuspendedTime=_.lastSuspendedTime=_.nextKnownPendingLevel=0:P<=_.firstSuspendedTime&&(_.firstSuspendedTime=P-1),P<=_.lastPingedTime&&(_.lastPingedTime=0),P<=_.lastExpiredTime&&(_.lastExpiredTime=0),_===fe&&(ie=fe=null,Pe=0),1=A?Kt(_,g,A):(en(qe,qe.current&1,g),g=mu(_,g,A),g!==null?g.sibling:null);en(qe,qe.current&1,g);break;case 19:if(P=g.childExpirationTime>=A,(_.effectTag&64)!==0){if(P)return bn(_,g,A);g.effectTag|=64}if(B=g.memoizedState,B!==null&&(B.rendering=null,B.tail=null),en(qe,qe.current,g),!P)return null}return mu(_,g,A)}ho=!1}}else ho=!1;switch(g.expirationTime=0,g.tag){case 2:if(P=g.type,_!==null&&(_.alternate=null,g.alternate=null,g.effectTag|=2),_=g.pendingProps,B=Ru(g,Ai.current),Fo(g,A),B=un(null,g,P,_,B,A),g.effectTag|=1,typeof B=="object"&&B!==null&&typeof B.render=="function"&&B.$$typeof===void 0){if(g.tag=1,fn(),eu(P)){var Z=!0;li(g)}else Z=!1;g.memoizedState=B.state!==null&&B.state!==void 0?B.state:null;var de=P.getDerivedStateFromProps;typeof de=="function"&&Zl(g,P,de,_),B.updater=oa,g.stateNode=B,B._reactInternalFiber=g,Bs(g,P,_,A),g=tt(null,g,P,!0,Z,A)}else g.tag=0,Bi(null,g,B,A),g=g.child;return g;case 16:if(B=g.elementType,_!==null&&(_.alternate=null,g.alternate=null,g.effectTag|=2),_=g.pendingProps,Ae(B),B._status!==1)throw B._result;switch(B=B._result,g.type=B,Z=g.tag=ol(B),_=Yn(B,_),Z){case 0:g=to(null,g,B,_,A);break;case 1:g=xe(null,g,B,_,A);break;case 11:g=Ci(null,g,B,_,A);break;case 14:g=mf(null,g,B,Yn(B.type,_),P,A);break;default:throw Error(t(306,B,""))}return g;case 0:return P=g.type,B=g.pendingProps,B=g.elementType===P?B:Yn(P,B),to(_,g,P,B,A);case 1:return P=g.type,B=g.pendingProps,B=g.elementType===P?B:Yn(P,B),xe(_,g,P,B,A);case 3:if(Ke(g),P=g.updateQueue,P===null)throw Error(t(282));if(B=g.memoizedState,B=B!==null?B.element:null,S0(g,P,g.pendingProps,null,A),P=g.memoizedState.element,P===B)tu(),g=mu(_,g,A);else{if((B=g.stateNode.hydrate)&&(S?(Su=F0(g.stateNode.containerInfo),Xu=g,B=_i=!0):B=!1),B)for(A=Y(g,null,P,A),g.child=A;A;)A.effectTag=A.effectTag&-3|1024,A=A.sibling;else Bi(_,g,P,A),tu();g=g.child}return g;case 5:return vt(g),_===null&&Uo(g),P=g.type,B=g.pendingProps,Z=_!==null?_.memoizedProps:null,de=B.children,dt(P,B)?de=null:Z!==null&&dt(P,Z)&&(g.effectTag|=16),eo(_,g),g.mode&4&&A!==1&&At(P,B)?(g.expirationTime=g.childExpirationTime=1,g=null):(Bi(_,g,de,A),g=g.child),g;case 6:return _===null&&Uo(g),null;case 13:return Kt(_,g,A);case 4:return Ne(g,g.stateNode.containerInfo),P=g.pendingProps,_===null?g.child=H(g,null,P,A):Bi(_,g,P,A),g.child;case 11:return P=g.type,B=g.pendingProps,B=g.elementType===P?B:Yn(P,B),Ci(_,g,P,B,A);case 7:return Bi(_,g,g.pendingProps,A),g.child;case 8:return Bi(_,g,g.pendingProps.children,A),g.child;case 12:return Bi(_,g,g.pendingProps.children,A),g.child;case 10:e:{if(P=g.type._context,B=g.pendingProps,de=g.memoizedProps,Z=B.value,zu(g,Z),de!==null){var yt=de.value;if(Z=Fe(yt,Z)?0:(typeof P._calculateChangedBits=="function"?P._calculateChangedBits(yt,Z):1073741823)|0,Z===0){if(de.children===B.children&&!yi.current){g=mu(_,g,A);break e}}else for(yt=g.child,yt!==null&&(yt.return=g);yt!==null;){var Rt=yt.dependencies;if(Rt!==null){de=yt.child;for(var Nt=Rt.firstContext;Nt!==null;){if(Nt.context===P&&(Nt.observedBits&Z)!==0){yt.tag===1&&(Nt=v0(A,null),Nt.tag=2,J0(yt,Nt)),yt.expirationTime"u")return!1;var g=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(g.isDisabled||!g.supportsFiber)return!0;try{var A=g.inject(_);ca=function(P){try{g.onCommitFiberRoot(A,P,void 0,(P.current.effectTag&64)===64)}catch{}},ws=function(P){try{g.onCommitFiberUnmount(A,P)}catch{}}}catch{}return!0}function ts(_,g,A,P){this.tag=_,this.key=A,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=g,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=P,this.effectTag=0,this.lastEffect=this.firstEffect=this.nextEffect=null,this.childExpirationTime=this.expirationTime=0,this.alternate=null}function Ho(_,g,A,P){return new ts(_,g,A,P)}function Ef(_){return _=_.prototype,!(!_||!_.isReactComponent)}function ol(_){if(typeof _=="function")return Ef(_)?1:0;if(_!=null){if(_=_.$$typeof,_===De)return 11;if(_===we)return 14}return 2}function Vu(_,g){var A=_.alternate;return A===null?(A=Ho(_.tag,g,_.key,_.mode),A.elementType=_.elementType,A.type=_.type,A.stateNode=_.stateNode,A.alternate=_,_.alternate=A):(A.pendingProps=g,A.effectTag=0,A.nextEffect=null,A.firstEffect=null,A.lastEffect=null),A.childExpirationTime=_.childExpirationTime,A.expirationTime=_.expirationTime,A.child=_.child,A.memoizedProps=_.memoizedProps,A.memoizedState=_.memoizedState,A.updateQueue=_.updateQueue,g=_.dependencies,A.dependencies=g===null?null:{expirationTime:g.expirationTime,firstContext:g.firstContext,responders:g.responders},A.sibling=_.sibling,A.index=_.index,A.ref=_.ref,A}function qa(_,g,A,P,B,Z){var de=2;if(P=_,typeof _=="function")Ef(_)&&(de=1);else if(typeof _=="string")de=5;else e:switch(_){case j:return n0(A.children,B,Z,g);case me:de=8,B|=7;break;case q:de=8,B|=1;break;case V:return _=Ho(12,A,g,B|8),_.elementType=V,_.type=V,_.expirationTime=Z,_;case ge:return _=Ho(13,A,g,B),_.type=ge,_.elementType=ge,_.expirationTime=Z,_;case ae:return _=Ho(19,A,g,B),_.elementType=ae,_.expirationTime=Z,_;default:if(typeof _=="object"&&_!==null)switch(_.$$typeof){case re:de=10;break e;case y:de=9;break e;case De:de=11;break e;case we:de=14;break e;case he:de=16,P=null;break e}throw Error(t(130,_==null?_:typeof _,""))}return g=Ho(de,A,g,B),g.elementType=_,g.type=P,g.expirationTime=Z,g}function n0(_,g,A,P){return _=Ho(7,_,P,g),_.expirationTime=A,_}function j0(_,g,A){return _=Ho(6,_,null,g),_.expirationTime=A,_}function Df(_,g,A){return g=Ho(4,_.children!==null?_.children:[],_.key,g),g.expirationTime=A,g.stateNode={containerInfo:_.containerInfo,pendingChildren:null,implementation:_.implementation},g}function Wc(_,g,A){this.tag=g,this.current=null,this.containerInfo=_,this.pingCache=this.pendingChildren=null,this.finishedExpirationTime=0,this.finishedWork=null,this.timeoutHandle=lr,this.pendingContext=this.context=null,this.hydrate=A,this.callbackNode=null,this.callbackPriority=90,this.lastExpiredTime=this.lastPingedTime=this.nextKnownPendingLevel=this.lastSuspendedTime=this.firstSuspendedTime=this.firstPendingTime=0}function dc(_,g){var A=_.firstSuspendedTime;return _=_.lastSuspendedTime,A!==0&&A>=g&&_<=g}function Ol(_,g){var A=_.firstSuspendedTime,P=_.lastSuspendedTime;Ag||A===0)&&(_.lastSuspendedTime=g),g<=_.lastPingedTime&&(_.lastPingedTime=0),g<=_.lastExpiredTime&&(_.lastExpiredTime=0)}function Ts(_,g){g>_.firstPendingTime&&(_.firstPendingTime=g);var A=_.firstSuspendedTime;A!==0&&(g>=A?_.firstSuspendedTime=_.lastSuspendedTime=_.nextKnownPendingLevel=0:g>=_.lastSuspendedTime&&(_.lastSuspendedTime=g+1),g>_.nextKnownPendingLevel&&(_.nextKnownPendingLevel=g))}function da(_,g){var A=_.lastExpiredTime;(A===0||A>g)&&(_.lastExpiredTime=g)}function ud(_){var g=_._reactInternalFiber;if(g===void 0)throw typeof _.render=="function"?Error(t(188)):Error(t(268,Object.keys(_)));return _=Qe(g),_===null?null:_.stateNode}function pa(_,g){_=_.memoizedState,_!==null&&_.dehydrated!==null&&_.retryTime{"use strict";Object.defineProperty(ec,"__esModule",{value:!0});var _P=0;ec.__interactionsRef=null;ec.__subscriberRef=null;ec.unstable_clear=function(o){return o()};ec.unstable_getCurrent=function(){return null};ec.unstable_getThreadID=function(){return++_P};ec.unstable_trace=function(o,l,f){return f()};ec.unstable_wrap=function(o){return o};ec.unstable_subscribe=function(){};ec.unstable_unsubscribe=function(){}});var WS=nt(vu=>{"use strict";process.env.NODE_ENV!=="production"&&function(){"use strict";Object.defineProperty(vu,"__esModule",{value:!0});var o=!0,l=0,f=0,h=0;vu.__interactionsRef=null,vu.__subscriberRef=null,o&&(vu.__interactionsRef={current:new Set},vu.__subscriberRef={current:null});function E(ae){if(!o)return ae();var we=vu.__interactionsRef.current;vu.__interactionsRef.current=new Set;try{return ae()}finally{vu.__interactionsRef.current=we}}function t(){return o?vu.__interactionsRef.current:null}function N(){return++h}function F(ae,we,he){var ve=arguments.length>3&&arguments[3]!==void 0?arguments[3]:l;if(!o)return he();var ue={__count:1,id:f++,name:ae,timestamp:we},Ae=vu.__interactionsRef.current,ze=new Set(Ae);ze.add(ue),vu.__interactionsRef.current=ze;var We=vu.__subscriberRef.current,gt;try{We!==null&&We.onInteractionTraced(ue)}finally{try{We!==null&&We.onWorkStarted(ze,ve)}finally{try{gt=he()}finally{vu.__interactionsRef.current=Ae;try{We!==null&&We.onWorkStopped(ze,ve)}finally{ue.__count--,We!==null&&ue.__count===0&&We.onInteractionScheduledWorkCompleted(ue)}}}}return gt}function k(ae){var we=arguments.length>1&&arguments[1]!==void 0?arguments[1]:l;if(!o)return ae;var he=vu.__interactionsRef.current,ve=vu.__subscriberRef.current;ve!==null&&ve.onWorkScheduled(he,we),he.forEach(function(ze){ze.__count++});var ue=!1;function Ae(){var ze=vu.__interactionsRef.current;vu.__interactionsRef.current=he,ve=vu.__subscriberRef.current;try{var We;try{ve!==null&&ve.onWorkStarted(he,we)}finally{try{We=ae.apply(void 0,arguments)}finally{vu.__interactionsRef.current=ze,ve!==null&&ve.onWorkStopped(he,we)}}return We}finally{ue||(ue=!0,he.forEach(function(gt){gt.__count--,ve!==null&>.__count===0&&ve.onInteractionScheduledWorkCompleted(gt)}))}}return Ae.cancel=function(){ve=vu.__subscriberRef.current;try{ve!==null&&ve.onWorkCanceled(he,we)}finally{he.forEach(function(We){We.__count--,ve&&We.__count===0&&ve.onInteractionScheduledWorkCompleted(We)})}},Ae}var x=null;o&&(x=new Set);function j(ae){o&&(x.add(ae),x.size===1&&(vu.__subscriberRef.current={onInteractionScheduledWorkCompleted:re,onInteractionTraced:V,onWorkCanceled:ge,onWorkScheduled:y,onWorkStarted:me,onWorkStopped:De}))}function q(ae){o&&(x.delete(ae),x.size===0&&(vu.__subscriberRef.current=null))}function V(ae){var we=!1,he=null;if(x.forEach(function(ve){try{ve.onInteractionTraced(ae)}catch(ue){we||(we=!0,he=ue)}}),we)throw he}function re(ae){var we=!1,he=null;if(x.forEach(function(ve){try{ve.onInteractionScheduledWorkCompleted(ae)}catch(ue){we||(we=!0,he=ue)}}),we)throw he}function y(ae,we){var he=!1,ve=null;if(x.forEach(function(ue){try{ue.onWorkScheduled(ae,we)}catch(Ae){he||(he=!0,ve=Ae)}}),he)throw ve}function me(ae,we){var he=!1,ve=null;if(x.forEach(function(ue){try{ue.onWorkStarted(ae,we)}catch(Ae){he||(he=!0,ve=Ae)}}),he)throw ve}function De(ae,we){var he=!1,ve=null;if(x.forEach(function(ue){try{ue.onWorkStopped(ae,we)}catch(Ae){he||(he=!0,ve=Ae)}}),he)throw ve}function ge(ae,we){var he=!1,ve=null;if(x.forEach(function(ue){try{ue.onWorkCanceled(ae,we)}catch(Ae){he||(he=!0,ve=Ae)}}),he)throw ve}vu.unstable_clear=E,vu.unstable_getCurrent=t,vu.unstable_getThreadID=N,vu.unstable_trace=F,vu.unstable_wrap=k,vu.unstable_subscribe=j,vu.unstable_unsubscribe=q}()});var VS=nt((_H,vD)=>{"use strict";process.env.NODE_ENV==="production"?vD.exports=qS():vD.exports=WS()});var GS=nt((EH,Yy)=>{"use strict";process.env.NODE_ENV!=="production"&&(Yy.exports=function o(l){"use strict";var f=Py(),h=Mi(),E=XE(),t=z_(),N=VS(),F=0,k=1,x=2,j=3,q=4,V=5,re=6,y=7,me=8,De=9,ge=10,ae=11,we=12,he=13,ve=14,ue=15,Ae=16,ze=17,We=18,gt=19,_t=20,Qe=21,ot=function(){};ot=function(c,d){for(var D=arguments.length,C=new Array(D>2?D-2:0),O=2;O8)throw new Error("warningWithoutStack() currently supports at most 8 arguments.");if(!c){if(typeof console<"u"){var z=C.map(function(se){return""+se});z.unshift("Warning: "+d),Function.prototype.apply.call(console.error,console,z)}try{var G=0,ne="Warning: "+d.replace(/%s/g,function(){return C[G++]});throw new Error(ne)}catch{}}};var Ve=ot;function Pt(c){return c._reactInternalFiber}function Jt(c,d){c._reactInternalFiber=d}var it=h.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;it.hasOwnProperty("ReactCurrentDispatcher")||(it.ReactCurrentDispatcher={current:null}),it.hasOwnProperty("ReactCurrentBatchConfig")||(it.ReactCurrentBatchConfig={suspense:null});var J=typeof Symbol=="function"&&Symbol.for,ce=J?Symbol.for("react.element"):60103,Re=J?Symbol.for("react.portal"):60106,le=J?Symbol.for("react.fragment"):60107,He=J?Symbol.for("react.strict_mode"):60108,dt=J?Symbol.for("react.profiler"):60114,At=J?Symbol.for("react.provider"):60109,nn=J?Symbol.for("react.context"):60110,an=J?Symbol.for("react.concurrent_mode"):60111,On=J?Symbol.for("react.forward_ref"):60112,lr=J?Symbol.for("react.suspense"):60113,ln=J?Symbol.for("react.suspense_list"):60120,Vt=J?Symbol.for("react.memo"):60115,Er=J?Symbol.for("react.lazy"):60116,S=J?Symbol.for("react.fundamental"):60117,zt=J?Symbol.for("react.responder"):60118,Xn=J?Symbol.for("react.scope"):60119,vr=typeof Symbol=="function"&&Symbol.iterator,jr="@@iterator";function fr(c){if(c===null||typeof c!="object")return null;var d=vr&&c[vr]||c[jr];return typeof d=="function"?d:null}var zr=Ve;zr=function(c,d){if(!c){for(var D=it.ReactDebugCurrentFrame,C=D.getStackAddendum(),O=arguments.length,z=new Array(O>2?O-2:0),G=2;G import('./MyComponent'))`,C),c._status=Ao,c._result=O}},function(C){c._status===c0&&(c._status=Jo,c._result=C)})}}function $o(c,d,D){var C=d.displayName||d.name||"";return c.displayName||(C!==""?D+"("+C+")":D)}function qt(c){if(c==null)return null;if(typeof c.tag=="number"&&Ve(!1,"Received an unexpected object in getComponentName(). This is likely a bug in React. Please file an issue."),typeof c=="function")return c.displayName||c.name||null;if(typeof c=="string")return c;switch(c){case le:return"Fragment";case Re:return"Portal";case dt:return"Profiler";case He:return"StrictMode";case lr:return"Suspense";case ln:return"SuspenseList"}if(typeof c=="object")switch(c.$$typeof){case nn:return"Context.Consumer";case At:return"Context.Provider";case On:return $o(c,c.render,"ForwardRef");case Vt:return qt(c.type);case Er:{var d=c,D=Fs(d);if(D)return qt(D);break}}return null}var xi=0,lu=1,vi=2,Dr=4,el=6,Y0=8,Bu=16,K0=32,Kr=64,Oo=128,Mo=256,F0=512,su=1024,ki=1028,Ps=932,Kl=2047,P0=2048,d0=4096,Hr=!0,Ri=!0,X0=!0,mi=!0,en=!0,In=!0,Ai=!1,yi=!1,Wt=!1,Ru=!1,eu=!1,Q0=!0,Yi=!1,Xl=!1,ko=!1,li=!1,ao=!1,Ql=it.ReactCurrentOwner;function No(c){var d=c,D=c;if(c.alternate)for(;d.return;)d=d.return;else{var C=d;do d=C,(d.effectTag&(vi|su))!==xi&&(D=d.return),C=d.return;while(C)}return d.tag===j?D:null}function Is(c){return No(c)===c}function $n(c){{var d=Ql.current;if(d!==null&&d.tag===k){var D=d,C=D.stateNode;C._warnedAboutRefsInRender||Ve(!1,"%s is accessing isMounted inside its render() function. render() should be a pure function of props and state. It should never access something that requires stale data from the previous render, such as refs. Move this logic to componentDidMount and componentDidUpdate instead.",qt(D.type)||"A component"),C._warnedAboutRefsInRender=!0}}var O=Pt(c);return O?No(O)===O:!1}function tl(c){if(No(c)!==c)throw Error("Unable to find node on an unmounted component.")}function fo(c){var d=c.alternate;if(!d){var D=No(c);if(D===null)throw Error("Unable to find node on an unmounted component.");return D!==c?null:c}for(var C=c,O=d;;){var z=C.return;if(z===null)break;var G=z.alternate;if(G===null){var ne=z.return;if(ne!==null){C=O=ne;continue}break}if(z.child===G.child){for(var se=z.child;se;){if(se===C)return tl(z),c;if(se===O)return tl(z),d;se=se.sibling}throw Error("Unable to find node on an unmounted component.")}if(C.return!==O.return)C=z,O=G;else{for(var Ue=!1,Xe=z.child;Xe;){if(Xe===C){Ue=!0,C=z,O=G;break}if(Xe===O){Ue=!0,O=z,C=G;break}Xe=Xe.sibling}if(!Ue){for(Xe=G.child;Xe;){if(Xe===C){Ue=!0,C=G,O=z;break}if(Xe===O){Ue=!0,O=G,C=z;break}Xe=Xe.sibling}if(!Ue)throw Error("Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue.")}}if(C.alternate!==O)throw Error("Return fibers should always be each others' alternates. This error is likely caused by a bug in React. Please file an issue.")}if(C.tag!==j)throw Error("Unable to find node on an unmounted component.");return C.stateNode.current===C?c:d}function I0(c){var d=fo(c);if(!d)return null;for(var D=d;;){if(D.tag===V||D.tag===re)return D;if(D.child){D.child.return=D,D=D.child;continue}if(D===d)return null;for(;!D.sibling;){if(!D.return||D.return===d)return null;D=D.return}D.sibling.return=D.return,D=D.sibling}return null}function Sl(c){var d=fo(c);if(!d)return null;for(var D=d;;){if(D.tag===V||D.tag===re||Wt&&D.tag===_t)return D;if(D.child&&D.tag!==q){D.child.return=D,D=D.child;continue}if(D===d)return null;for(;!D.sibling;){if(!D.return||D.return===d)return null;D=D.return}D.sibling.return=D.return,D=D.sibling}return null}var Lo=l.getPublicInstance,St=l.getRootHostContext,Bt=l.getChildHostContext,Hn=l.prepareForCommit,qr=l.resetAfterCommit,Ki=l.createInstance,Xr=l.appendInitialChild,Au=l.finalizeInitialChildren,p0=l.prepareUpdate,Ni=l.shouldSetTextContent,h0=l.shouldDeprioritizeSubtree,hs=l.createTextInstance,Ct=l.setTimeout,co=l.clearTimeout,nl=l.noTimeout,Jl=l.now,Uu=l.isPrimaryRenderer,vs=l.warnsIfNotActing,b0=l.supportsMutation,Q=l.supportsPersistence,Se=l.supportsHydration,Fe=l.mountResponderInstance,Le=l.unmountResponderInstance,pt=l.getFundamentalComponentInstance,Yn=l.mountFundamentalComponent,Cn=l.shouldUpdateFundamentalComponent,cr=l.getInstanceFromNode,Si=l.appendChild,Ou=l.appendChildToContainer,ju=l.commitTextUpdate,zu=l.commitMount,wu=l.commitUpdate,Ti=l.insertBefore,Fo=l.insertInContainerBefore,Mu=l.removeChild,po=l.removeChildFromContainer,Hu=l.resetTextContent,Pa=l.hideInstance,v0=l.hideTextInstance,ia=l.unhideInstance,J0=l.unhideTextInstance,ua=l.updateFundamentalComponent,Ia=l.unmountFundamentalComponent,ms=l.cloneInstance,S0=l.createContainerChildSet,Qn=l.appendChildToContainerChildSet,ac=l.finalizeContainerChildren,si=l.replaceContainerChildren,Jr=l.cloneHiddenInstance,Zl=l.cloneHiddenTextInstance,oa=l.cloneInstance,pf=l.canHydrateInstance,bs=l.canHydrateTextInstance,ba=l.canHydrateSuspenseInstance,Bs=l.isSuspenseInstancePending,m0=l.isSuspenseInstanceFallback,Us=l.registerSuspenseInstanceRetry,zi=l.getNextHydratableSibling,U=l.getFirstHydratableChild,H=l.hydrateInstance,Y=l.hydrateTextInstance,ee=l.hydrateSuspenseInstance,Ce=l.getNextHydratableInstanceAfterSuspenseInstance,_e=l.commitHydratedContainer,Oe=l.commitHydratedSuspenseInstance,$=l.clearSuspenseBoundary,Ne=l.clearSuspenseBoundaryFromContainer,Je=l.didNotMatchHydratedContainerTextInstance,vt=l.didNotMatchHydratedTextInstance,oe=l.didNotHydrateContainerInstance,qe=l.didNotHydrateInstance,rt=l.didNotFindHydratableContainerInstance,xt=l.didNotFindHydratableContainerTextInstance,kt=l.didNotFindHydratableContainerSuspenseInstance,bt=l.didNotFindHydratableInstance,sn=l.didNotFindHydratableTextInstance,rn=l.didNotFindHydratableSuspenseInstance,Ft=/^(.*)[\\\/]/,Dn=function(c,d,D){var C="";if(d){var O=d.fileName,z=O.replace(Ft,"");if(/^index\./.test(z)){var G=O.match(Ft);if(G){var ne=G[1];if(ne){var se=ne.replace(Ft,"");z=se+"/"+z}}}C=" (at "+z+":"+d.lineNumber+")"}else D&&(C=" (created by "+D+")");return` + in `+(c||"Unknown")+C},dr=it.ReactDebugCurrentFrame;function er(c){switch(c.tag){case j:case q:case re:case y:case ge:case De:return"";default:var d=c._debugOwner,D=c._debugSource,C=qt(c.type),O=null;return d&&(O=qt(d.type)),Dn(C,D,O)}}function Cr(c){var d="",D=c;do d+=er(D),D=D.return;while(D);return d}var Rn=null,Nr=null;function y0(){{if(Rn===null)return null;var c=Rn._debugOwner;if(c!==null&&typeof c<"u")return qt(c.type)}return null}function Lr(){return Rn===null?"":Cr(Rn)}function ut(){dr.getCurrentStack=null,Rn=null,Nr=null}function wt(c){dr.getCurrentStack=Lr,Rn=c,Nr=null}function et(c){Nr=c}var It="\u269B",un="\u26D4",fn=typeof performance<"u"&&typeof performance.mark=="function"&&typeof performance.clearMarks=="function"&&typeof performance.measure=="function"&&typeof performance.clearMeasures=="function",Jn=null,wr=null,au=null,ku=!1,T0=!1,Z0=!1,Nu=0,gi=0,Po=new Set,rl=function(c){return It+" "+c},hf=function(c,d){var D=d?un+" ":It+" ",C=d?" Warning: "+d:"";return""+D+c+C},Tl=function(c){performance.mark(rl(c))},vf=function(c){performance.clearMarks(rl(c))},Io=function(c,d,D){var C=rl(d),O=hf(c,D);try{performance.measure(O,C)}catch{}performance.clearMarks(C),performance.clearMeasures(O)},ys=function(c,d){return c+" (#"+d+")"},js=function(c,d,D){return D===null?c+" ["+(d?"update":"mount")+"]":c+"."+D},bo=function(c,d){var D=qt(c.type)||"Unknown",C=c._debugID,O=c.alternate!==null,z=js(D,O,d);if(ku&&Po.has(z))return!1;Po.add(z);var G=ys(z,C);return Tl(G),!0},Bo=function(c,d){var D=qt(c.type)||"Unknown",C=c._debugID,O=c.alternate!==null,z=js(D,O,d),G=ys(z,C);vf(G)},gs=function(c,d,D){var C=qt(c.type)||"Unknown",O=c._debugID,z=c.alternate!==null,G=js(C,z,d),ne=ys(G,O);Io(G,ne,D)},Xu=function(c){switch(c.tag){case j:case V:case re:case q:case y:case ge:case De:case me:return!0;default:return!1}},Su=function(){wr!==null&&au!==null&&Bo(au,wr),au=null,wr=null,Z0=!1},_i=function(){for(var c=Jn;c;)c._debugIsCurrentlyTiming&&gs(c,null,null),c=c.return},C0=function(c){c.return!==null&&C0(c.return),c._debugIsCurrentlyTiming&&bo(c,null)},$0=function(){Jn!==null&&C0(Jn)};function Uo(){Hr&&gi++}function la(){Hr&&(ku&&(T0=!0),wr!==null&&wr!=="componentWillMount"&&wr!=="componentWillReceiveProps"&&(Z0=!0))}function $l(c){if(Hr){if(!fn||Xu(c)||(Jn=c,!bo(c,null)))return;c._debugIsCurrentlyTiming=!0}}function tu(c){if(Hr){if(!fn||Xu(c))return;c._debugIsCurrentlyTiming=!1,Bo(c,null)}}function Zr(c){if(Hr){if(!fn||Xu(c)||(Jn=c.return,!c._debugIsCurrentlyTiming))return;c._debugIsCurrentlyTiming=!1,gs(c,null,null)}}function ho(c){if(Hr){if(!fn||Xu(c)||(Jn=c.return,!c._debugIsCurrentlyTiming))return;c._debugIsCurrentlyTiming=!1;var d=c.tag===he?"Rendering was suspended":"An error was thrown inside this error boundary";gs(c,null,d)}}function Bi(c,d){if(Hr){if(!fn||(Su(),!bo(c,d)))return;au=c,wr=d}}function Ci(){if(Hr){if(!fn)return;if(wr!==null&&au!==null){var c=Z0?"Scheduled a cascading update":null;gs(au,wr,c)}wr=null,au=null}}function mf(c){if(Hr){if(Jn=c,!fn)return;Nu=0,Tl("(React Tree Reconciliation)"),$0()}}function yf(c,d){if(Hr){if(!fn)return;var D=null;if(c!==null)if(c.tag===j)D="A top-level update interrupted the previous render";else{var C=qt(c.type)||"Unknown";D="An update to "+C+" interrupted the previous render"}else Nu>1&&(D="There were cascading updates");Nu=0;var O=d?"(React Tree Reconciliation: Completed Root)":"(React Tree Reconciliation: Yielded)";_i(),Io(O,"(React Tree Reconciliation)",D)}}function eo(){if(Hr){if(!fn)return;ku=!0,T0=!1,Po.clear(),Tl("(Committing Changes)")}}function to(){if(Hr){if(!fn)return;var c=null;T0?c="Lifecycle hook scheduled a cascading update":Nu>0&&(c="Caused by a cascading update in earlier commit"),T0=!1,Nu++,ku=!1,Po.clear(),Io("(Committing Changes)","(Committing Changes)",c)}}function xe(){if(Hr){if(!fn)return;gi=0,Tl("(Committing Snapshot Effects)")}}function tt(){if(Hr){if(!fn)return;var c=gi;gi=0,Io("(Committing Snapshot Effects: "+c+" Total)","(Committing Snapshot Effects)",null)}}function Ke(){if(Hr){if(!fn)return;gi=0,Tl("(Committing Host Effects)")}}function Yt(){if(Hr){if(!fn)return;var c=gi;gi=0,Io("(Committing Host Effects: "+c+" Total)","(Committing Host Effects)",null)}}function Kt(){if(Hr){if(!fn)return;gi=0,Tl("(Calling Lifecycle Methods)")}}function pr(){if(Hr){if(!fn)return;var c=gi;gi=0,Io("(Calling Lifecycle Methods: "+c+" Total)","(Calling Lifecycle Methods)",null)}}var Ei=[],bn;bn=[];var mu=-1;function Qu(c){return{current:c}}function $r(c,d){if(mu<0){Ve(!1,"Unexpected pop.");return}d!==bn[mu]&&Ve(!1,"Unexpected Fiber popped."),c.current=Ei[mu],Ei[mu]=null,bn[mu]=null,mu--}function Qr(c,d,D){mu++,Ei[mu]=c.current,bn[mu]=D,c.current=d}var qu;qu={};var xn={};Object.freeze(xn);var x0=Qu(xn),Lu=Qu(!1),ui=xn;function Cl(c,d,D){return li?xn:D&&Xi(d)?ui:x0.current}function zs(c,d,D){if(!li){var C=c.stateNode;C.__reactInternalMemoizedUnmaskedChildContext=d,C.__reactInternalMemoizedMaskedChildContext=D}}function Wu(c,d){if(li)return xn;var D=c.type,C=D.contextTypes;if(!C)return xn;var O=c.stateNode;if(O&&O.__reactInternalMemoizedUnmaskedChildContext===d)return O.__reactInternalMemoizedMaskedChildContext;var z={};for(var G in C)z[G]=d[G];{var ne=qt(D)||"Unknown";E(C,z,"context",ne,Lr)}return O&&zs(c,d,z),z}function sa(){return li?!1:Lu.current}function Xi(c){if(li)return!1;var d=c.childContextTypes;return d!=null}function Hs(c){li||($r(Lu,c),$r(x0,c))}function R0(c){li||($r(Lu,c),$r(x0,c))}function Hi(c,d,D){if(!li){if(x0.current!==xn)throw Error("Unexpected context found on stack. This error is likely caused by a bug in React. Please file an issue.");Qr(x0,d,c),Qr(Lu,D,c)}}function A0(c,d,D){if(li)return D;var C=c.stateNode,O=d.childContextTypes;if(typeof C.getChildContext!="function"){{var z=qt(d)||"Unknown";qu[z]||(qu[z]=!0,Ve(!1,"%s.childContextTypes is specified but there is no getChildContext() method on the instance. You can either define getChildContext() on %s or remove childContextTypes from it.",z,z))}return D}var G;et("getChildContext"),Bi(c,"getChildContext"),G=C.getChildContext(),Ci(),et(null);for(var ne in G)if(!(ne in O))throw Error((qt(d)||"Unknown")+'.getChildContext(): key "'+ne+'" is not defined in childContextTypes.');{var se=qt(d)||"Unknown";E(O,G,"child context",se,Lr)}return f({},D,{},G)}function qi(c){if(li)return!1;var d=c.stateNode,D=d&&d.__reactInternalMemoizedMergedChildContext||xn;return ui=x0.current,Qr(x0,D,c),Qr(Lu,Lu.current,c),!0}function il(c,d,D){if(!li){var C=c.stateNode;if(!C)throw Error("Expected to have an instance by this point. This error is likely caused by a bug in React. Please file an issue.");if(D){var O=A0(c,d,ui);C.__reactInternalMemoizedMergedChildContext=O,$r(Lu,c),$r(x0,c),Qr(x0,O,c),Qr(Lu,D,c)}else $r(Lu,c),Qr(Lu,D,c)}}function xl(c){if(li)return xn;if(!(Is(c)&&c.tag===k))throw Error("Expected subtree parent to be a mounted class component. This error is likely caused by a bug in React. Please file an issue.");var d=c;do{switch(d.tag){case j:return d.stateNode.context;case k:{var D=d.type;if(Xi(D))return d.stateNode.__reactInternalMemoizedMergedChildContext;break}}d=d.return}while(d!==null);throw Error("Found unexpected detached subtree parent. This error is likely caused by a bug in React. Please file an issue.")}var B0=1,O0=2,vo=t.unstable_runWithPriority,Fu=t.unstable_scheduleCallback,Ju=t.unstable_cancelCallback,es=t.unstable_shouldYield,_s=t.unstable_requestPaint,aa=t.unstable_now,gf=t.unstable_getCurrentPriorityLevel,Zu=t.unstable_ImmediatePriority,Es=t.unstable_UserBlockingPriority,Rr=t.unstable_NormalPriority,no=t.unstable_LowPriority,nu=t.unstable_IdlePriority;if(In&&!(N.__interactionsRef!=null&&N.__interactionsRef.current!=null))throw Error("It is not supported to run the profiling version of a renderer (for example, `react-dom/profiling`) without also replacing the `scheduler/tracing` module with `scheduler/tracing-profiling`. Your bundler might have a setting for aliasing both modules. Learn more at http://fb.me/react-profiling");var fu={},Li=99,ei=98,Kn=97,$u=96,g0=95,_0=90,Ln=es,fe=_s!==void 0?_s:function(){},ie=null,Pe=null,Me=!1,at=aa(),mt=at<1e4?aa:function(){return aa()-at};function Qt(){switch(gf()){case Zu:return Li;case Es:return ei;case Rr:return Kn;case no:return $u;case nu:return g0;default:throw Error("Unknown priority level.")}}function An(c){switch(c){case Li:return Zu;case ei:return Es;case Kn:return Rr;case $u:return no;case g0:return nu;default:throw Error("Unknown priority level.")}}function Sn(c,d){var D=An(c);return vo(D,d)}function _n(c,d,D){var C=An(c);return Fu(C,d,D)}function Tn(c){return ie===null?(ie=[c],Pe=Fu(Zu,Fi)):ie.push(c),fu}function ir(c){c!==fu&&Ju(c)}function Ut(){if(Pe!==null){var c=Pe;Pe=null,Ju(c)}Fi()}function Fi(){if(!Me&&ie!==null){Me=!0;var c=0;try{var d=!0,D=ie;Sn(Li,function(){for(;c1?d-1:0),C=1;C2?D-2:0),O=2;O0&&(ja.forEach(function(Lt){c.add(qt(Lt.type)||"Component"),ts.add(Lt.type)}),ja=[]);var d=new Set;za.length>0&&(za.forEach(function(Lt){d.add(qt(Lt.type)||"Component"),ts.add(Lt.type)}),za=[]);var D=new Set;Ha.length>0&&(Ha.forEach(function(Lt){D.add(qt(Lt.type)||"Component"),ts.add(Lt.type)}),Ha=[]);var C=new Set;ca.length>0&&(ca.forEach(function(Lt){C.add(qt(Lt.type)||"Component"),ts.add(Lt.type)}),ca=[]);var O=new Set;ws.length>0&&(ws.forEach(function(Lt){O.add(qt(Lt.type)||"Component"),ts.add(Lt.type)}),ws=[]);var z=new Set;if(Ss.length>0&&(Ss.forEach(function(Lt){z.add(qt(Lt.type)||"Component"),ts.add(Lt.type)}),Ss=[]),d.size>0){var G=zo(d);Ve(!1,`Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code. See https://fb.me/react-unsafe-component-lifecycles for details. + +* Move code with side effects to componentDidMount, and set initial state in the constructor. + +Please update the following components: %s`,G)}if(C.size>0){var ne=zo(C);Ve(!1,`Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code. See https://fb.me/react-unsafe-component-lifecycles for details. + +* Move data fetching code or side effects to componentDidUpdate. +* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state + +Please update the following components: %s`,ne)}if(z.size>0){var se=zo(z);Ve(!1,`Using UNSAFE_componentWillUpdate in strict mode is not recommended and may indicate bugs in your code. See https://fb.me/react-unsafe-component-lifecycles for details. + +* Move data fetching code or side effects to componentDidUpdate. + +Please update the following components: %s`,se)}if(c.size>0){var Ue=zo(c);qs(!1,`componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details. + +* Move code with side effects to componentDidMount, and set initial state in the constructor. +* Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder. + +Please update the following components: %s`,Ue)}if(D.size>0){var Xe=zo(D);qs(!1,`componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details. + +* Move data fetching code or side effects to componentDidUpdate. +* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state +* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder. + +Please update the following components: %s`,Xe)}if(O.size>0){var ht=zo(O);qs(!1,`componentWillUpdate has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details. + +* Move data fetching code or side effects to componentDidUpdate. +* Rename componentWillUpdate to UNSAFE_componentWillUpdate to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run \`npx react-codemod rename-unsafe-lifecycles\` in your project source folder. + +Please update the following components: %s`,ht)}};var Ho=new Map,Ef=new Set;Al.recordLegacyContextWarning=function(c,d){var D=id(c);if(D===null){Ve(!1,"Expected to find a StrictMode component in a strict mode tree. This error is likely caused by a bug in React. Please file an issue.");return}if(!Ef.has(c.type)){var C=Ho.get(D);(c.type.contextTypes!=null||c.type.childContextTypes!=null||d!==null&&typeof d.getChildContext=="function")&&(C===void 0&&(C=[],Ho.set(D,C)),C.push(c))}},Al.flushLegacyContextWarning=function(){Ho.forEach(function(c,d){var D=new Set;c.forEach(function(z){D.add(qt(z.type)||"Component"),Ef.add(z.type)});var C=zo(D),O=Cr(d);Ve(!1,`Legacy context API has been detected within a strict-mode tree. + +The old API will be supported in all 16.x releases, but applications using it should migrate to the new version. + +Please update the following components: %s + +Learn more about this warning here: https://fb.me/react-legacy-context%s`,C,O)})},Al.discardPendingWarnings=function(){ja=[],za=[],Ha=[],ca=[],ws=[],Ss=[],Ho=new Map}}var ol=null,Vu=null,qa=function(c){ol=c};function n0(c){{if(ol===null)return c;var d=ol(c);return d===void 0?c:d.current}}function j0(c){return n0(c)}function Df(c){{if(ol===null)return c;var d=ol(c);if(d===void 0){if(c!=null&&typeof c.render=="function"){var D=n0(c.render);if(c.render!==D){var C={$$typeof:On,render:D};return c.displayName!==void 0&&(C.displayName=c.displayName),C}}return c}return d.current}}function Wc(c,d){{if(ol===null)return!1;var D=c.elementType,C=d.type,O=!1,z=typeof C=="object"&&C!==null?C.$$typeof:null;switch(c.tag){case k:{typeof C=="function"&&(O=!0);break}case F:{(typeof C=="function"||z===Er)&&(O=!0);break}case ae:{(z===On||z===Er)&&(O=!0);break}case ve:case ue:{(z===Vt||z===Er)&&(O=!0);break}default:return!1}if(O){var G=ol(D);if(G!==void 0&&G===ol(C))return!0}return!1}}function dc(c){{if(ol===null||typeof WeakSet!="function")return;Vu===null&&(Vu=new WeakSet),Vu.add(c)}}var Ol=function(c,d){{if(ol===null)return;var D=d.staleFamilies,C=d.updatedFamilies;tf(),Rp(function(){da(c.current,C,D)})}},Ts=function(c,d){{if(c.context!==xn)return;tf(),pv(function(){Xg(d,c,null,null)})}};function da(c,d,D){{var C=c.alternate,O=c.child,z=c.sibling,G=c.tag,ne=c.type,se=null;switch(G){case F:case ue:case k:se=ne;break;case ae:se=ne.render;break;default:break}if(ol===null)throw new Error("Expected resolveFamily to be set during hot reload.");var Ue=!1,Xe=!1;if(se!==null){var ht=ol(se);ht!==void 0&&(D.has(ht)?Xe=!0:d.has(ht)&&(G===k?Xe=!0:Ue=!0))}Vu!==null&&(Vu.has(c)||C!==null&&Vu.has(C))&&(Xe=!0),Xe&&(c._debugNeedsRemount=!0),(Xe||Ue)&&yl(c,Un),O!==null&&!Xe&&da(O,d,D),z!==null&&da(z,d,D)}}var ud=function(c,d){{var D=new Set,C=new Set(d.map(function(O){return O.current}));return pa(c.current,C,D),D}};function pa(c,d,D){{var C=c.child,O=c.sibling,z=c.tag,G=c.type,ne=null;switch(z){case F:case ue:case k:ne=G;break;case ae:ne=G.render;break;default:break}var se=!1;ne!==null&&d.has(ne)&&(se=!0),se?pc(c,D):C!==null&&pa(C,d,D),O!==null&&pa(O,d,D)}}function pc(c,d){{var D=Vc(c,d);if(D)return;for(var C=c;;){switch(C.tag){case V:d.add(C.stateNode);return;case q:d.add(C.stateNode.containerInfo);return;case j:d.add(C.stateNode.containerInfo);return}if(C.return===null)throw new Error("Expected to reach root first.");C=C.return}}}function Vc(c,d){for(var D=c,C=!1;;){if(D.tag===V)C=!0,d.add(D.stateNode);else if(D.child!==null){D.child.return=D,D=D.child;continue}if(D===c)return C;for(;D.sibling===null;){if(D.return===null||D.return===c)return C;D=D.return}D.sibling.return=D.return,D=D.sibling}return!1}function Wi(c,d){if(c&&c.defaultProps){var D=f({},d),C=c.defaultProps;for(var O in C)D[O]===void 0&&(D[O]=C[O]);return D}return d}function _(c){if(Zo(c),c._status!==Ao)throw c._result;return c._result}var g=Qu(null),A;A={};var P=null,B=null,Z=null,de=!1;function yt(){P=null,B=null,Z=null,de=!1}function Rt(){de=!0}function Nt(){de=!1}function xr(c,d){var D=c.type._context;Uu?(Qr(g,D._currentValue,c),D._currentValue=d,D._currentRenderer===void 0||D._currentRenderer===null||D._currentRenderer===A||Ve(!1,"Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported."),D._currentRenderer=A):(Qr(g,D._currentValue2,c),D._currentValue2=d,D._currentRenderer2===void 0||D._currentRenderer2===null||D._currentRenderer2===A||Ve(!1,"Detected multiple renderers concurrently rendering the same context provider. This is currently unsupported."),D._currentRenderer2=A)}function r0(c){var d=g.current;$r(g,c);var D=c.type._context;Uu?D._currentValue=d:D._currentValue2=d}function cu(c,d,D){if(yo(D,d))return 0;var C=typeof c._calculateChangedBits=="function"?c._calculateChangedBits(D,d):Wr;return(C&Wr)!==C&&Xt(!1,"calculateChangedBits: Expected the return value to be a 31-bit integer. Instead received: %s",C),C|0}function z0(c,d){for(var D=c;D!==null;){var C=D.alternate;if(D.childExpirationTime=d&&op(),D.firstContext=null)}}function Ge(c,d){if(de&&Xt(!1,"Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo()."),Z!==c){if(!(d===!1||d===0)){var D;typeof d!="number"||d===Wr?(Z=c,D=Wr):D=d;var C={context:c,observedBits:D,next:null};if(B===null){if(P===null)throw Error("Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo().");B=C,P.dependencies={expirationTime:ft,firstContext:C,responders:null}}else B=B.next=C}}return Uu?c._currentValue:c._currentValue2}var je=0,st=1,$t=2,Wn=3,oi=!1,ur,ai;ur=!1,ai=null;function Qi(c){var d={baseState:c,firstUpdate:null,lastUpdate:null,firstCapturedUpdate:null,lastCapturedUpdate:null,firstEffect:null,lastEffect:null,firstCapturedEffect:null,lastCapturedEffect:null};return d}function Vr(c){var d={baseState:c.baseState,firstUpdate:c.firstUpdate,lastUpdate:c.lastUpdate,firstCapturedUpdate:null,lastCapturedUpdate:null,firstEffect:null,lastEffect:null,firstCapturedEffect:null,lastCapturedEffect:null};return d}function Tu(c,d){var D={expirationTime:c,suspenseConfig:d,tag:je,payload:null,callback:null,next:null,nextEffect:null};return D.priority=Qt(),D}function Wa(c,d){c.lastUpdate===null?c.firstUpdate=c.lastUpdate=d:(c.lastUpdate.next=d,c.lastUpdate=d)}function Va(c,d){var D=c.alternate,C,O;D===null?(C=c.updateQueue,O=null,C===null&&(C=c.updateQueue=Qi(c.memoizedState))):(C=c.updateQueue,O=D.updateQueue,C===null?O===null?(C=c.updateQueue=Qi(c.memoizedState),O=D.updateQueue=Qi(D.memoizedState)):C=c.updateQueue=Vr(O):O===null&&(O=D.updateQueue=Vr(C))),O===null||C===O?Wa(C,d):C.lastUpdate===null||O.lastUpdate===null?(Wa(C,d),Wa(O,d)):(Wa(C,d),O.lastUpdate=d),c.tag===k&&(ai===C||O!==null&&ai===O)&&!ur&&(Ve(!1,"An update (setState, replaceState, or forceUpdate) was scheduled from inside an update function. Update functions should be pure, with zero side-effects. Consider using componentDidUpdate or a callback."),ur=!0)}function od(c,d){var D=c.updateQueue;D===null?D=c.updateQueue=Qi(c.memoizedState):D=D2(c,D),D.lastCapturedUpdate===null?D.firstCapturedUpdate=D.lastCapturedUpdate=d:(D.lastCapturedUpdate.next=d,D.lastCapturedUpdate=d)}function D2(c,d){var D=c.alternate;return D!==null&&d===D.updateQueue&&(d=c.updateQueue=Vr(d)),d}function w2(c,d,D,C,O,z){switch(D.tag){case st:{var G=D.payload;if(typeof G=="function"){Rt(),Ri&&c.mode&mr&&G.call(z,C,O);var ne=G.call(z,C,O);return Nt(),ne}return G}case Wn:c.effectTag=c.effectTag&~d0|Kr;case je:{var se=D.payload,Ue;return typeof se=="function"?(Rt(),Ri&&c.mode&mr&&se.call(z,C,O),Ue=se.call(z,C,O),Nt()):Ue=se,Ue==null?C:f({},C,Ue)}case $t:return oi=!0,C}return C}function wf(c,d,D,C,O){oi=!1,d=D2(c,d),ai=d;for(var z=d.baseState,G=null,ne=ft,se=d.firstUpdate,Ue=z;se!==null;){var Xe=se.expirationTime;if(Xe from render. Or maybe you meant to call this function rather than return it."))}function Eh(c){function d(lt,Mt){if(!!c){var $e=lt.lastEffect;$e!==null?($e.nextEffect=Mt,lt.lastEffect=Mt):lt.firstEffect=lt.lastEffect=Mt,Mt.nextEffect=null,Mt.effectTag=Y0}}function D(lt,Mt){if(!c)return null;for(var $e=Mt;$e!==null;)d(lt,$e),$e=$e.sibling;return null}function C(lt,Mt){for(var $e=new Map,jt=Mt;jt!==null;)jt.key!==null?$e.set(jt.key,jt):$e.set(jt.index,jt),jt=jt.sibling;return $e}function O(lt,Mt,$e){var jt=Co(lt,Mt,$e);return jt.index=0,jt.sibling=null,jt}function z(lt,Mt,$e){if(lt.index=$e,!c)return Mt;var jt=lt.alternate;if(jt!==null){var Fn=jt.index;return FnYr?(Cu=hr,hr=null):Cu=hr.sibling;var D0=Lt(lt,hr,$e[Yr],jt);if(D0===null){hr===null&&(hr=Cu);break}c&&hr&&D0.alternate===null&&d(lt,hr),pu=z(D0,pu,Yr),Yu===null?ci=D0:Yu.sibling=D0,Yu=D0,hr=Cu}if(Yr===$e.length)return D(lt,hr),ci;if(hr===null){for(;Yr<$e.length;Yr++){var W0=ht(lt,$e[Yr],jt);W0!==null&&(pu=z(W0,pu,Yr),Yu===null?ci=W0:Yu.sibling=W0,Yu=W0)}return ci}for(var Ms=C(lt,hr);Yr<$e.length;Yr++){var Ku=Gt(Ms,lt,Yr,$e[Yr],jt);Ku!==null&&(c&&Ku.alternate!==null&&Ms.delete(Ku.key===null?Yr:Ku.key),pu=z(Ku,pu,Yr),Yu===null?ci=Ku:Yu.sibling=Ku,Yu=Ku)}return c&&Ms.forEach(function(gl){return d(lt,gl)}),ci}function kr(lt,Mt,$e,jt){var Fn=fr($e);if(typeof Fn!="function")throw Error("An object is not an iterable. This error is likely caused by a bug in React. Please file an issue.");{typeof Symbol=="function"&&$e[Symbol.toStringTag]==="Generator"&&(Qc||Xt(!1,"Using Generators as children is unsupported and will likely yield unexpected results because enumerating a generator mutates it. You may convert it to an array with `Array.from()` or the `[...spread]` operator before rendering. Keep in mind you might need to polyfill these features for older browsers."),Qc=!0),$e.entries===Fn&&(dd||Xt(!1,"Using Maps as children is unsupported and will likely yield unexpected results. Convert it to a sequence/iterable of keyed ReactElements instead."),dd=!0);var vn=Fn.call($e);if(vn)for(var Vi=null,ci=vn.next();!ci.done;ci=vn.next()){var Yu=ci.value;Vi=Ht(Yu,Vi)}}var hr=Fn.call($e);if(hr==null)throw Error("An iterable object provided no iterator.");for(var pu=null,Yr=null,Cu=Mt,D0=0,W0=0,Ms=null,Ku=hr.next();Cu!==null&&!Ku.done;W0++,Ku=hr.next()){Cu.index>W0?(Ms=Cu,Cu=null):Ms=Cu.sibling;var gl=Lt(lt,Cu,Ku.value,jt);if(gl===null){Cu===null&&(Cu=Ms);break}c&&Cu&&gl.alternate===null&&d(lt,Cu),D0=z(gl,D0,W0),Yr===null?pu=gl:Yr.sibling=gl,Yr=gl,Cu=Ms}if(Ku.done)return D(lt,Cu),pu;if(Cu===null){for(;!Ku.done;W0++,Ku=hr.next()){var rf=ht(lt,Ku.value,jt);rf!==null&&(D0=z(rf,D0,W0),Yr===null?pu=rf:Yr.sibling=rf,Yr=rf)}return pu}for(var Vo=C(lt,Cu);!Ku.done;W0++,Ku=hr.next()){var ks=Gt(Vo,lt,W0,Ku.value,jt);ks!==null&&(c&&ks.alternate!==null&&Vo.delete(ks.key===null?W0:ks.key),D0=z(ks,D0,W0),Yr===null?pu=ks:Yr.sibling=ks,Yr=ks)}return c&&Vo.forEach(function(Jd){return d(lt,Jd)}),pu}function ii(lt,Mt,$e,jt){if(Mt!==null&&Mt.tag===re){D(lt,Mt.sibling);var Fn=O(Mt,$e,jt);return Fn.return=lt,Fn}D(lt,Mt);var vn=_y($e,lt.mode,jt);return vn.return=lt,vn}function Oi(lt,Mt,$e,jt){for(var Fn=$e.key,vn=Mt;vn!==null;){if(vn.key===Fn)if(vn.tag===y?$e.type===le:vn.elementType===$e.type||Wc(vn,$e)){D(lt,vn.sibling);var Vi=O(vn,$e.type===le?$e.props.children:$e.props,jt);return Vi.ref=vc(lt,vn,$e),Vi.return=lt,Vi._debugSource=$e._source,Vi._debugOwner=$e._owner,Vi}else{D(lt,vn);break}else d(lt,vn);vn=vn.sibling}if($e.type===le){var ci=nf($e.props.children,lt.mode,jt,$e.key);return ci.return=lt,ci}else{var Yu=gy($e,lt.mode,jt);return Yu.ref=vc(lt,Mt,$e),Yu.return=lt,Yu}}function L0(lt,Mt,$e,jt){for(var Fn=$e.key,vn=Mt;vn!==null;){if(vn.key===Fn)if(vn.tag===q&&vn.stateNode.containerInfo===$e.containerInfo&&vn.stateNode.implementation===$e.implementation){D(lt,vn.sibling);var Vi=O(vn,$e.children||[],jt);return Vi.return=lt,Vi}else{D(lt,vn);break}else d(lt,vn);vn=vn.sibling}var ci=Ey($e,lt.mode,jt);return ci.return=lt,ci}function $i(lt,Mt,$e,jt){var Fn=typeof $e=="object"&&$e!==null&&$e.type===le&&$e.key===null;Fn&&($e=$e.props.children);var vn=typeof $e=="object"&&$e!==null;if(vn)switch($e.$$typeof){case ce:return G(Oi(lt,Mt,$e,jt));case Re:return G(L0(lt,Mt,$e,jt))}if(typeof $e=="string"||typeof $e=="number")return G(ii(lt,Mt,""+$e,jt));if(Zc($e))return yn(lt,Mt,$e,jt);if(fr($e))return kr(lt,Mt,$e,jt);if(vn&&mc(lt,$e),typeof $e=="function"&&pd(),typeof $e>"u"&&!Fn)switch(lt.tag){case k:{var Vi=lt.stateNode;if(Vi.render._isMockFunction)break}case F:{var ci=lt.type;throw Error((ci.displayName||ci.name||"Component")+"(...): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.")}}return D(lt,Mt)}return $i}var Tf=Eh(!0),$c=Eh(!1);function Dh(c,d){if(!(c===null||d.child===c.child))throw Error("Resuming work not yet implemented.");if(d.child!==null){var D=d.child,C=Co(D,D.pendingProps,D.expirationTime);for(d.child=C,C.return=d;D.sibling!==null;)D=D.sibling,C=C.sibling=Co(D,D.pendingProps,D.expirationTime),C.return=d;C.sibling=null}}function sm(c,d){for(var D=c.child;D!==null;)kv(D,d),D=D.sibling}var Vs={},ma=Qu(Vs),iu=Qu(Vs),M0=Qu(Vs);function u0(c){if(c===Vs)throw Error("Expected host context to exist. This error is likely caused by a bug in React. Please file an issue.");return c}function ns(){var c=u0(M0.current);return c}function Ya(c,d){Qr(M0,d,c),Qr(iu,c,c),Qr(ma,Vs,c);var D=St(d);$r(ma,c),Qr(ma,D,c)}function uo(c){$r(ma,c),$r(iu,c),$r(M0,c)}function fl(){var c=u0(ma.current);return c}function yc(c){var d=u0(M0.current),D=u0(ma.current),C=Bt(D,c.type,d);D!==C&&(Qr(iu,c,c),Qr(ma,C,c))}function M2(c){iu.current===c&&($r(ma,c),$r(iu,c))}var wh=0,Cf=1,xf=1,e1=2,Nl=Qu(wh);function t1(c,d){return(c&d)!==0}function ya(c){return c&Cf}function hd(c,d){return c&Cf|d}function vd(c,d){return c|d}function Fr(c,d){Qr(Nl,d,c)}function ga(c){$r(Nl,c)}function k2(c,d){var D=c.memoizedState;if(D!==null)return D.dehydrated!==null;var C=c.memoizedProps;return C.fallback===void 0?!1:C.unstable_avoidThisFallback!==!0?!0:!d}function n1(c){for(var d=c;d!==null;){if(d.tag===he){var D=d.memoizedState;if(D!==null){var C=D.dehydrated;if(C===null||Bs(C)||m0(C))return d}}else if(d.tag===gt&&d.memoizedProps.revealOrder!==void 0){var O=(d.effectTag&Kr)!==xi;if(O)return d}else if(d.child!==null){d.child.return=d,d=d.child;continue}if(d===c)return null;for(;d.sibling===null;){if(d.return===null||d.return===c)return null;d=d.return}d.sibling.return=d.return,d=d.sibling}return null}var md={},wi=Array.isArray;function N2(c,d,D,C){return{fiber:C,props:d,responder:c,rootEventTypes:null,state:D}}function am(c,d,D,C,O){var z=md,G=c.getInitialState;G!==null&&(z=G(d));var ne=N2(c,d,z,D);if(!O)for(var se=D;se!==null;){var Ue=se.tag;if(Ue===V){O=se.stateNode;break}else if(Ue===j){O=se.stateNode.containerInfo;break}se=se.return}Fe(c,ne,d,z,O),C.set(c,ne)}function yd(c,d,D,C,O){var z,G;if(c&&(z=c.responder,G=c.props),!(z&&z.$$typeof===zt))throw Error("An invalid value was used as an event listener. Expect one or many event listeners created via React.unstable_useResponder().");var ne=G;if(D.has(z)){Xt(!1,'Duplicate event responder "%s" found in event listeners. Event listeners passed to elements cannot use the same event responder more than once.',z.displayName);return}D.add(z);var se=C.get(z);se===void 0?am(z,ne,d,C,O):(se.props=ne,se.fiber=d)}function hn(c,d,D){var C=new Set,O=d.dependencies;if(c!=null){O===null&&(O=d.dependencies={expirationTime:ft,firstContext:null,responders:new Map});var z=O.responders;if(z===null&&(z=new Map),wi(c))for(var G=0,ne=c.length;G0){var z=O.dispatch;if(Cs!==null){var G=Cs.get(O);if(G!==void 0){Cs.delete(O);var ne=C.memoizedState,se=G;do{var Ue=se.action;ne=c(ne,Ue),se=se.next}while(se!==null);return yo(ne,C.memoizedState)||op(),C.memoizedState=ne,C.baseUpdate===O.last&&(C.baseState=ne),O.lastRenderedState=ne,[ne,z]}}return[C.memoizedState,z]}var Xe=O.last,ht=C.baseUpdate,Lt=C.baseState,Gt;if(ht!==null?(Xe!==null&&(Xe.next=null),Gt=ht.next):Gt=Xe!==null?Xe.next:null,Gt!==null){var Ht=Lt,yn=null,kr=null,ii=ht,Oi=Gt,L0=!1;do{var $i=Oi.expirationTime;if($iPu&&(Pu=$i,Kd(Pu));else if(gv($i,Oi.suspenseConfig),Oi.eagerReducer===c)Ht=Oi.eagerState;else{var lt=Oi.action;Ht=c(Ht,lt)}ii=Oi,Oi=Oi.next}while(Oi!==null&&Oi!==Gt);L0||(kr=ii,yn=Ht),yo(Ht,C.memoizedState)||op(),C.memoizedState=Ht,C.baseUpdate=kr,C.baseState=yn,O.lastRenderedState=Ht}var Mt=O.dispatch;return[C.memoizedState,Mt]}function Ff(c){var d=Dc();typeof c=="function"&&(c=c()),d.memoizedState=d.baseState=c;var D=d.queue={last:null,dispatch:null,lastRenderedReducer:L2,lastRenderedState:c},C=D.dispatch=a1.bind(null,dl,D);return[d.memoizedState,C]}function o1(c){return u1(L2,c)}function Qa(c,d,D,C){var O={tag:c,create:d,destroy:D,deps:C,next:null};if(rs===null)rs=Xa(),rs.lastEffect=O.next=O;else{var z=rs.lastEffect;if(z===null)rs.lastEffect=O.next=O;else{var G=z.next;z.next=O,O.next=G,rs.lastEffect=O}}return O}function l1(c){var d=Dc(),D={current:c};return Object.seal(D),d.memoizedState=D,D}function F2(c){var d=i1();return d.memoizedState}function Dd(c,d,D,C){var O=Dc(),z=C===void 0?null:C;Mf|=c,O.memoizedState=Qa(d,D,void 0,z)}function wc(c,d,D,C){var O=i1(),z=C===void 0?null:C,G=void 0;if(jn!==null){var ne=jn.memoizedState;if(G=ne.destroy,z!==null){var se=ne.deps;if(Nf(z,se)){Qa(Af,D,G,z);return}}}Mf|=c,O.memoizedState=Qa(d,D,G,z)}function s1(c,d){return typeof jest<"u"&&Mv(dl),Dd(Dr|F0,sr|r1,c,d)}function Fl(c,d){return typeof jest<"u"&&Mv(dl),wc(Dr|F0,sr|r1,c,d)}function Ea(c,d){return Dd(Dr,Of|cl,c,d)}function Ch(c,d){return wc(Dr,Of|cl,c,d)}function P2(c,d){if(typeof d=="function"){var D=d,C=c();return D(C),function(){D(null)}}else if(d!=null){var O=d;O.hasOwnProperty("current")||Xt(!1,"Expected useImperativeHandle() first argument to either be a ref callback or React.createRef() object. Instead received: %s.","an object with keys {"+Object.keys(O).join(", ")+"}");var z=c();return O.current=z,function(){O.current=null}}}function I2(c,d,D){typeof d!="function"&&Xt(!1,"Expected useImperativeHandle() second argument to be a function that creates a handle. Instead received: %s.",d!==null?typeof d:"null");var C=D!=null?D.concat([c]):null;return Dd(Dr,Of|cl,P2.bind(null,d,c),C)}function xh(c,d,D){typeof d!="function"&&Xt(!1,"Expected useImperativeHandle() second argument to be a function that creates a handle. Instead received: %s.",d!==null?typeof d:"null");var C=D!=null?D.concat([c]):null;return wc(Dr,Of|cl,P2.bind(null,d,c),C)}function pm(c,d){}var Rh=pm;function Pl(c,d){var D=Dc(),C=d===void 0?null:d;return D.memoizedState=[c,C],c}function us(c,d){var D=i1(),C=d===void 0?null:d,O=D.memoizedState;if(O!==null&&C!==null){var z=O[1];if(Nf(C,z))return O[0]}return D.memoizedState=[c,C],c}function xs(c,d){var D=Dc(),C=d===void 0?null:d,O=c();return D.memoizedState=[O,C],O}function Gs(c,d){var D=i1(),C=d===void 0?null:d,O=D.memoizedState;if(O!==null&&C!==null){var z=O[1];if(Nf(C,z))return O[0]}var G=c();return D.memoizedState=[G,C],G}function b2(c,d){var D=Ff(c),C=D[0],O=D[1];return s1(function(){t.unstable_next(function(){var z=qo.suspense;qo.suspense=d===void 0?null:d;try{O(c)}finally{qo.suspense=z}})},[c,d]),C}function Ah(c,d){var D=o1(c),C=D[0],O=D[1];return Fl(function(){t.unstable_next(function(){var z=qo.suspense;qo.suspense=d===void 0?null:d;try{O(c)}finally{qo.suspense=z}})},[c,d]),C}function B2(c){var d=Ff(!1),D=d[0],C=d[1],O=Pl(function(z){C(!0),t.unstable_next(function(){var G=qo.suspense;qo.suspense=c===void 0?null:c;try{C(!1),z()}finally{qo.suspense=G}})},[c,D]);return[O,D]}function U2(c){var d=o1(!1),D=d[0],C=d[1],O=us(function(z){C(!0),t.unstable_next(function(){var G=qo.suspense;qo.suspense=c===void 0?null:c;try{C(!1),z()}finally{qo.suspense=G}})},[c,D]);return[O,D]}function a1(c,d,D){if(!(Ec=0){var D=c1()-d1;c.actualDuration+=D,d&&(c.selfBaseDuration=D),d1=-1}}var bl=null,Za=null,Da=!1;function q2(){Da&&Xt(!1,"We should not be hydrating here. This is a bug in React. Please file a bug.")}function W2(c){if(!Se)return!1;var d=c.stateNode.containerInfo;return Za=U(d),bl=c,Da=!0,!0}function hm(c,d){return Se?(Za=zi(d),Y2(c),Da=!0,!0):!1}function V2(c,d){switch(c.tag){case j:oe(c.stateNode.containerInfo,d);break;case V:qe(c.type,c.memoizedProps,c.stateNode,d);break}var D=U4();D.stateNode=d,D.return=c,D.effectTag=Y0,c.lastEffect!==null?(c.lastEffect.nextEffect=D,c.lastEffect=D):c.firstEffect=c.lastEffect=D}function Fh(c,d){switch(d.effectTag=d.effectTag&~su|vi,c.tag){case j:{var D=c.stateNode.containerInfo;switch(d.tag){case V:var C=d.type,O=d.pendingProps;rt(D,C,O);break;case re:var z=d.pendingProps;xt(D,z);break;case he:kt(D);break}break}case V:{var G=c.type,ne=c.memoizedProps,se=c.stateNode;switch(d.tag){case V:var Ue=d.type,Xe=d.pendingProps;bt(G,ne,se,Ue,Xe);break;case re:var ht=d.pendingProps;sn(G,ne,se,ht);break;case he:rn(G,ne,se);break}break}default:return}}function Ph(c,d){switch(c.tag){case V:{var D=c.type,C=c.pendingProps,O=pf(d,D,C);return O!==null?(c.stateNode=O,!0):!1}case re:{var z=c.pendingProps,G=bs(d,z);return G!==null?(c.stateNode=G,!0):!1}case he:{if(Ai){var ne=ba(d);if(ne!==null){var se={dehydrated:ne,retryTime:Di};c.memoizedState=se;var Ue=j4(ne);return Ue.return=c,c.child=Ue,!0}}return!1}default:return!1}}function G2(c){if(!!Da){var d=Za;if(!d){Fh(bl,c),Da=!1,bl=c;return}var D=d;if(!Ph(c,d)){if(d=zi(D),!d||!Ph(c,d)){Fh(bl,c),Da=!1,bl=c;return}V2(bl,D)}bl=c,Za=U(d)}}function vm(c,d,D){if(!Se)throw Error("Expected prepareToHydrateHostInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.");var C=c.stateNode,O=H(C,c.type,c.memoizedProps,d,D,c);return c.updateQueue=O,O!==null}function mm(c){if(!Se)throw Error("Expected prepareToHydrateHostTextInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.");var d=c.stateNode,D=c.memoizedProps,C=Y(d,D,c);if(C){var O=bl;if(O!==null)switch(O.tag){case j:{var z=O.stateNode.containerInfo;Je(z,d,D);break}case V:{var G=O.type,ne=O.memoizedProps,se=O.stateNode;vt(G,ne,se,d,D);break}}}return C}function Ih(c){if(!Se)throw Error("Expected prepareToHydrateHostSuspenseInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.");var d=c.memoizedState,D=d!==null?d.dehydrated:null;if(!D)throw Error("Expected to have a hydrated suspense instance. This error is likely caused by a bug in React. Please file an issue.");ee(D,c)}function ym(c){if(!Se)throw Error("Expected skipPastDehydratedSuspenseInstance() to never be called. This error is likely caused by a bug in React. Please file an issue.");var d=c.memoizedState,D=d!==null?d.dehydrated:null;if(!D)throw Error("Expected to have a hydrated suspense instance. This error is likely caused by a bug in React. Please file an issue.");return Ce(D)}function Y2(c){for(var d=c.return;d!==null&&d.tag!==V&&d.tag!==j&&d.tag!==he;)d=d.return;bl=d}function h1(c){if(!Se||c!==bl)return!1;if(!Da)return Y2(c),Da=!0,!1;var d=c.type;if(c.tag!==V||d!=="head"&&d!=="body"&&!Ni(d,c.memoizedProps))for(var D=Za;D;)V2(c,D),D=zi(D);return Y2(c),c.tag===he?Za=ym(c):Za=bl?zi(c.stateNode):null,!0}function v1(){!Se||(bl=null,Za=null,Da=!1)}var m1=it.ReactCurrentOwner,wa=!1,K2,Ys,Ks,Xs,X2,Sa,y1,wd,Sc,Q2;K2={},Ys={},Ks={},Xs={},X2={},Sa=!1,y1=!1,wd={},Sc={},Q2={};function wo(c,d,D,C){c===null?d.child=$c(d,null,D,C):d.child=Tf(d,c.child,D,C)}function bh(c,d,D,C){d.child=Tf(d,c.child,null,C),d.child=Tf(d,null,D,C)}function Bh(c,d,D,C,O){if(d.type!==d.elementType){var z=D.propTypes;z&&E(z,C,"prop",qt(D),Lr)}var G=D.render,ne=d.ref,se;return i0(d,O),m1.current=d,et("render"),se=Lf(c,d,G,C,ne,O),Ri&&d.mode&mr&&d.memoizedState!==null&&(se=Lf(c,d,G,C,ne,O)),et(null),c!==null&&!wa?(gd(c,d,O),Ta(c,d,O)):(d.effectTag|=lu,wo(c,d,se,O),d.child)}function Uh(c,d,D,C,O,z){if(c===null){var G=D.type;if(s0(G)&&D.compare===null&&D.defaultProps===void 0){var ne=G;return ne=n0(G),d.tag=ue,d.type=ne,$2(d,G),jh(c,d,ne,C,O,z)}{var se=G.propTypes;se&&E(se,C,"prop",qt(G),Lr)}var Ue=yy(D.type,null,C,null,d.mode,z);return Ue.ref=d.ref,Ue.return=d,d.child=Ue,Ue}{var Xe=D.type,ht=Xe.propTypes;ht&&E(ht,C,"prop",qt(Xe),Lr)}var Lt=c.child;if(O component appears to have a render method, but doesn't extend React.Component. This is likely to cause errors. Change %s to extend React.Component instead.",se,se),K2[se]=!0)}d.mode&mr&&Al.recordLegacyContextWarning(d,null),m1.current=d,ne=Lf(null,d,D,O,z,C)}if(d.effectTag|=lu,typeof ne=="object"&&ne!==null&&typeof ne.render=="function"&&ne.$$typeof===void 0){{var Ue=qt(D)||"Unknown";Ys[Ue]||(Ve(!1,"The <%s /> component appears to be a function component that returns a class instance. Change %s to a class that extends React.Component instead. If you can't use a class try assigning the prototype on the function as a workaround. `%s.prototype = React.Component.prototype`. Don't use an arrow function since it cannot be called with `new` by React.",Ue,Ue,Ue),Ys[Ue]=!0)}d.tag=k,_d();var Xe=!1;Xi(D)?(Xe=!0,qi(d)):Xe=!1,d.memoizedState=ne.state!==null&&ne.state!==void 0?ne.state:null;var ht=D.getDerivedStateFromProps;return typeof ht=="function"&&Sf(d,D,ht,O),al(d,ne),hc(d,D,O,C),Z2(null,d,D,!0,Xe,C)}else return d.tag=F,li&&D.contextTypes&&Ve(!1,"%s uses the legacy contextTypes API which is no longer supported. Use React.createContext() with React.useContext() instead.",qt(D)||"Unknown"),Ri&&d.mode&mr&&d.memoizedState!==null&&(ne=Lf(null,d,D,O,z,C)),wo(null,d,ne,C),$2(d,D),d.child}function $2(c,d){if(d&&d.childContextTypes&&Ve(!1,"%s(...): childContextTypes cannot be defined on a function component.",d.displayName||d.name||"Component"),c.ref!==null){var D="",C=y0();C&&(D+=` + +Check the render method of \``+C+"`.");var O=C||c._debugID||"",z=c._debugSource;z&&(O=z.fileName+":"+z.lineNumber),X2[O]||(X2[O]=!0,Xt(!1,"Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?%s",D))}if(Xl&&d.defaultProps!==void 0){var G=qt(d)||"Unknown";Q2[G]||(Ve(!1,"%s: Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.",G),Q2[G]=!0)}if(typeof d.getDerivedStateFromProps=="function"){var ne=qt(d)||"Unknown";Xs[ne]||(Ve(!1,"%s: Function components do not support getDerivedStateFromProps.",ne),Xs[ne]=!0)}if(typeof d.contextType=="object"&&d.contextType!==null){var se=qt(d)||"Unknown";Ks[se]||(Ve(!1,"%s: Function components do not support contextType.",se),Ks[se]=!0)}}var Td={dehydrated:null,retryTime:ft};function ep(c,d,D){return t1(c,e1)&&(d===null||d.memoizedState!==null)}function Vh(c,d,D){var C=d.mode,O=d.pendingProps;Jg(d)&&(d.effectTag|=Kr);var z=Nl.current,G=!1,ne=(d.effectTag&Kr)!==xi;if(ne||ep(z,c,d)?(G=!0,d.effectTag&=~Kr):(c===null||c.memoizedState!==null)&&O.fallback!==void 0&&O.unstable_avoidThisFallback!==!0&&(z=vd(z,xf)),z=ya(z),Fr(d,z),"maxDuration"in O&&(y1||(y1=!0,Xt(!1,"maxDuration has been removed from React. Remove the maxDuration prop."))),c===null){if(O.fallback!==void 0&&(G2(d),Ai)){var se=d.memoizedState;if(se!==null){var Ue=se.dehydrated;if(Ue!==null)return Gh(d,Ue,D)}}if(G){var Xe=O.fallback,ht=nf(null,C,ft,null);if(ht.return=d,(d.mode&K)===Ar){var Lt=d.memoizedState,Gt=Lt!==null?d.child.child:d.child;ht.child=Gt;for(var Ht=Gt;Ht!==null;)Ht.return=ht,Ht=Ht.sibling}var yn=nf(Xe,C,D,null);return yn.return=d,ht.sibling=yn,d.memoizedState=Td,d.child=ht,yn}else{var kr=O.children;return d.memoizedState=null,d.child=$c(d,null,kr,D)}}else{var ii=c.memoizedState;if(ii!==null){if(Ai){var Oi=ii.dehydrated;if(Oi!==null)if(ne){if(d.memoizedState!==null)return d.child=c.child,d.effectTag|=Kr,null;var L0=O.fallback,$i=nf(null,C,ft,null);if($i.return=d,$i.child=null,(d.mode&K)===Ar)for(var lt=$i.child=d.child;lt!==null;)lt.return=$i,lt=lt.sibling;else Tf(d,c.child,null,D);if(en&&d.mode&ni){for(var Mt=0,$e=$i.child;$e!==null;)Mt+=$e.treeBaseDuration,$e=$e.sibling;$i.treeBaseDuration=Mt}var jt=nf(L0,C,D,null);return jt.return=d,$i.sibling=jt,jt.effectTag|=vi,$i.childExpirationTime=ft,d.memoizedState=Td,d.child=$i,jt}else return Yh(c,d,Oi,ii,D)}var Fn=c.child,vn=Fn.sibling;if(G){var Vi=O.fallback,ci=Co(Fn,Fn.pendingProps,ft);if(ci.return=d,(d.mode&K)===Ar){var Yu=d.memoizedState,hr=Yu!==null?d.child.child:d.child;if(hr!==Fn.child){ci.child=hr;for(var pu=hr;pu!==null;)pu.return=ci,pu=pu.sibling}}if(en&&d.mode&ni){for(var Yr=0,Cu=ci.child;Cu!==null;)Yr+=Cu.treeBaseDuration,Cu=Cu.sibling;ci.treeBaseDuration=Yr}var D0=Co(vn,Vi,vn.expirationTime);return D0.return=d,ci.sibling=D0,ci.childExpirationTime=ft,d.memoizedState=Td,d.child=ci,D0}else{var W0=O.children,Ms=Fn.child,Ku=Tf(d,Ms,W0,D);return d.memoizedState=null,d.child=Ku}}else{var gl=c.child;if(G){var rf=O.fallback,Vo=nf(null,C,ft,null);if(Vo.return=d,Vo.child=gl,gl!==null&&(gl.return=Vo),(d.mode&K)===Ar){var ks=d.memoizedState,Jd=ks!==null?d.child.child:d.child;Vo.child=Jd;for(var Vf=Jd;Vf!==null;)Vf.return=Vo,Vf=Vf.sibling}if(en&&d.mode&ni){for(var Lc=0,Hl=Vo.child;Hl!==null;)Lc+=Hl.treeBaseDuration,Hl=Hl.sibling;Vo.treeBaseDuration=Lc}var Go=nf(rf,C,D,null);return Go.return=d,Vo.sibling=Go,Go.effectTag|=vi,Vo.childExpirationTime=ft,d.memoizedState=Td,d.child=Vo,Go}else{d.memoizedState=null;var L1=O.children;return d.child=Tf(d,gl,L1,D)}}}}function tp(c,d,D){d.memoizedState=null;var C=d.pendingProps,O=C.children;return wo(c,d,O,D),d.child}function Gh(c,d,D){if((c.mode&K)===Ar)Xt(!1,"Cannot hydrate Suspense in legacy mode. Switch from ReactDOM.hydrate(element, container) to ReactDOM.createBlockingRoot(container, { hydrate: true }).render(element) or remove the Suspense components from the server rendered components."),c.expirationTime=Un;else if(m0(d)){var C=jl(),O=Ds(C);In&&R(O),c.expirationTime=O}else c.expirationTime=Di,In&&R(Di);return null}function Yh(c,d,D,C,O){if(q2(),(d.mode&K)===Ar||m0(D))return tp(c,d,O);var z=c.childExpirationTime>=O;if(wa||z){if(O. Use lowercase "%s" instead.',c,c.toLowerCase());break}case"forward":case"backward":{Xt(!1,'"%s" is not a valid value for revealOrder on . React uses the -s suffix in the spelling. Use "%ss" instead.',c,c.toLowerCase());break}default:Xt(!1,'"%s" is not a supported revealOrder on . Did you mean "together", "forwards" or "backwards"?',c);break}else Xt(!1,'%s is not a supported value for revealOrder on . Did you mean "together", "forwards" or "backwards"?',c)}function Kh(c,d){c!==void 0&&!Sc[c]&&(c!=="collapsed"&&c!=="hidden"?(Sc[c]=!0,Xt(!1,'"%s" is not a supported value for tail on . Did you mean "collapsed" or "hidden"?',c)):d!=="forwards"&&d!=="backwards"&&(Sc[c]=!0,Xt(!1,' is only valid if revealOrder is "forwards" or "backwards". Did you mean to specify revealOrder="forwards"?',c)))}function _1(c,d){{var D=Array.isArray(c),C=!D&&typeof fr(c)=="function";if(D||C){var O=D?"array":"iterable";return Xt(!1,"A nested %s was passed to row #%s in . Wrap it in an additional SuspenseList to configure its revealOrder: ... {%s} ... ",O,d,O),!1}}return!0}function Cm(c,d){if((d==="forwards"||d==="backwards")&&c!==void 0&&c!==null&&c!==!1)if(Array.isArray(c)){for(var D=0;D. This is not useful since it needs multiple rows. Did you mean to pass multiple children or an array?',d)}}function rp(c,d,D,C,O,z){var G=c.memoizedState;G===null?c.memoizedState={isBackwards:d,rendering:null,last:C,tail:D,tailExpiration:0,tailMode:O,lastEffect:z}:(G.isBackwards=d,G.rendering=null,G.last=C,G.tail=D,G.tailExpiration=0,G.tailMode=O,G.lastEffect=z)}function ip(c,d,D){var C=d.pendingProps,O=C.revealOrder,z=C.tail,G=C.children;Tm(O),Kh(z,O),Cm(G,O),wo(c,d,G,D);var ne=Nl.current,se=t1(ne,e1);if(se)ne=hd(ne,e1),d.effectTag|=Kr;else{var Ue=c!==null&&(c.effectTag&Kr)!==xi;Ue&&wm(d,d.child,D),ne=ya(ne)}if(Fr(d,ne),(d.mode&K)===Ar)d.memoizedState=null;else switch(O){case"forwards":{var Xe=Sm(d.child),ht;Xe===null?(ht=d.child,d.child=null):(ht=Xe.sibling,Xe.sibling=null),rp(d,!1,ht,Xe,z,d.lastEffect);break}case"backwards":{var Lt=null,Gt=d.child;for(d.child=null;Gt!==null;){var Ht=Gt.alternate;if(Ht!==null&&n1(Ht)===null){d.child=Gt;break}var yn=Gt.sibling;Gt.sibling=Lt,Lt=Gt,Gt=yn}rp(d,!0,Lt,null,z,d.lastEffect);break}case"together":{rp(d,!1,null,null,void 0,d.lastEffect);break}default:d.memoizedState=null}return d.child}function xm(c,d,D){Ya(d,d.stateNode.containerInfo);var C=d.pendingProps;return c===null?d.child=Tf(d,null,C,D):wo(c,d,C,D),d.child}function Rm(c,d,D){var C=d.type,O=C._context,z=d.pendingProps,G=d.memoizedProps,ne=z.value;{var se=d.type.propTypes;se&&E(se,z,"prop","Context.Provider",Lr)}if(xr(d,ne),G!==null){var Ue=G.value,Xe=cu(O,ne,Ue);if(Xe===0){if(G.children===z.children&&!sa())return Ta(c,d,D)}else Ml(d,O,Xe,D)}var ht=z.children;return wo(c,d,ht,D),d.child}var Xh=!1;function Am(c,d,D){var C=d.type;C._context===void 0?C!==C.Consumer&&(Xh||(Xh=!0,Xt(!1,"Rendering directly is not supported and will be removed in a future major release. Did you mean to render instead?"))):C=C._context;var O=d.pendingProps,z=O.children;typeof z!="function"&&Ve(!1,"A context consumer was rendered with multiple children, or a child that isn't a function. A context consumer expects a single child that is a function. If you did pass a function, make sure there is no trailing or leading whitespace around it."),i0(d,D);var G=Ge(C,O.unstable_observedBits),ne;return m1.current=d,et("render"),ne=z(G),et(null),d.effectTag|=lu,wo(c,d,ne,D),d.child}function Om(c,d,D){var C=d.type.impl;if(C.reconcileChildren===!1)return null;var O=d.pendingProps,z=O.children;return wo(c,d,z,D),d.child}function up(c,d,D){var C=d.pendingProps,O=C.children;return wo(c,d,O,D),d.child}function op(){wa=!0}function Ta(c,d,D){tu(d),c!==null&&(d.dependencies=c.dependencies),en&&Lh(d);var C=d.expirationTime;C!==ft&&Kd(C);var O=d.childExpirationTime;return O=D;se&&(d.effectTag|=Dr)}break;case he:{var Ue=d.memoizedState;if(Ue!==null){if(Ai&&Ue.dehydrated!==null){Fr(d,ya(Nl.current)),d.effectTag|=Kr;break}var Xe=d.child,ht=Xe.childExpirationTime;if(ht!==ft&&ht>=D)return Vh(c,d,D);Fr(d,ya(Nl.current));var Lt=Ta(c,d,D);return Lt!==null?Lt.sibling:null}else Fr(d,ya(Nl.current));break}case gt:{var Gt=(c.effectTag&Kr)!==xi,Ht=d.childExpirationTime>=D;if(Gt){if(Ht)return ip(c,d,D);d.effectTag|=Kr}var yn=d.memoizedState;if(yn!==null&&(yn.rendering=null,yn.tail=null),Fr(d,Nl.current),Ht)break;return null}}return Ta(c,d,D)}else wa=!1}else wa=!1;switch(d.expirationTime=ft,d.tag){case x:return Dm(c,d,d.type,D);case Ae:{var kr=d.elementType;return If(c,d,kr,C,D)}case F:{var ii=d.type,Oi=d.pendingProps,L0=d.elementType===ii?Oi:Wi(ii,Oi);return J2(c,d,ii,L0,D)}case k:{var $i=d.type,lt=d.pendingProps,Mt=d.elementType===$i?lt:Wi($i,lt);return qh(c,d,$i,Mt,D)}case j:return _m(c,d,D);case V:return Em(c,d,D);case re:return Pf(c,d);case he:return Vh(c,d,D);case q:return xm(c,d,D);case ae:{var $e=d.type,jt=d.pendingProps,Fn=d.elementType===$e?jt:Wi($e,jt);return Bh(c,d,$e,Fn,D)}case y:return gm(c,d,D);case me:return zh(c,d,D);case we:return Hh(c,d,D);case ge:return Rm(c,d,D);case De:return Am(c,d,D);case ve:{var vn=d.type,Vi=d.pendingProps,ci=Wi(vn,Vi);if(d.type!==d.elementType){var Yu=vn.propTypes;Yu&&E(Yu,ci,"prop",qt(vn),Lr)}return ci=Wi(vn.type,ci),Uh(c,d,vn,ci,C,D)}case ue:return jh(c,d,d.type,d.pendingProps,C,D);case ze:{var hr=d.type,pu=d.pendingProps,Yr=d.elementType===hr?pu:Wi(hr,pu);return Sd(c,d,hr,Yr,D)}case gt:return ip(c,d,D);case _t:{if(Wt)return Om(c,d,D);break}case Qe:{if(Ru)return up(c,d,D);break}}throw Error("Unknown unit of work tag ("+d.tag+"). This error is likely caused by a bug in React. Please file an issue.")}function Qh(c,d,D,C){return{currentFiber:c,impl:D,instance:null,prevProps:null,props:d,state:C}}function Cd(c){return c.tag===he&&c.memoizedState!==null}function D1(c){return c.child.sibling.child}var Jh={};function sp(c,d,D){if(Ru){if(c.tag===V){var C=c.type,O=c.memoizedProps,z=c.stateNode,G=Lo(z);G!==null&&d(C,O||Jh,G)===!0&&D.push(G)}var ne=c.child;Cd(c)&&(ne=D1(c)),ne!==null&&ap(ne,d,D)}}function Zh(c,d){if(Ru){if(c.tag===V){var D=c.type,C=c.memoizedProps,O=c.stateNode,z=Lo(O);if(z!==null&&d(D,C,z)===!0)return z}var G=c.child;if(Cd(c)&&(G=D1(c)),G!==null)return $h(G,d)}return null}function ap(c,d,D){for(var C=c;C!==null;)sp(C,d,D),C=C.sibling}function $h(c,d){for(var D=c;D!==null;){var C=Zh(D,d);if(C!==null)return C;D=D.sibling}return null}function ev(c,d,D){if(xd(c,d))D.push(c.stateNode.methods);else{var C=c.child;Cd(c)&&(C=D1(c)),C!==null&&fp(C,d,D)}}function fp(c,d,D){for(var C=c;C!==null;)ev(C,d,D),C=C.sibling}function xd(c,d){return c.tag===Qe&&c.type===d&&c.stateNode!==null}function Rd(c,d){return{getChildren:function(){var D=d.fiber,C=D.child,O=[];return C!==null&&fp(C,c,O),O.length===0?null:O},getChildrenFromRoot:function(){for(var D=d.fiber,C=D;C!==null;){var O=C.return;if(O===null||(C=O,C.tag===Qe&&C.type===c))break}var z=[];return fp(C.child,c,z),z.length===0?null:z},getParent:function(){for(var D=d.fiber.return;D!==null;){if(D.tag===Qe&&D.type===c)return D.stateNode.methods;D=D.return}return null},getProps:function(){var D=d.fiber;return D.memoizedProps},queryAllNodes:function(D){var C=d.fiber,O=C.child,z=[];return O!==null&&ap(O,D,z),z.length===0?null:z},queryFirstNode:function(D){var C=d.fiber,O=C.child;return O!==null?$h(O,D):null},containsNode:function(D){for(var C=cr(D);C!==null;){if(C.tag===Qe&&C.type===c&&C.stateNode===d)return!0;C=C.return}return!1}}}function H0(c){c.effectTag|=Dr}function Ad(c){c.effectTag|=Oo}var Ca,$a,Od,Md;if(b0)Ca=function(c,d,D,C){for(var O=d.child;O!==null;){if(O.tag===V||O.tag===re)Xr(c,O.stateNode);else if(Wt&&O.tag===_t)Xr(c,O.stateNode.instance);else if(O.tag!==q){if(O.child!==null){O.child.return=O,O=O.child;continue}}if(O===d)return;for(;O.sibling===null;){if(O.return===null||O.return===d)return;O=O.return}O.sibling.return=O.return,O=O.sibling}},$a=function(c){},Od=function(c,d,D,C,O){var z=c.memoizedProps;if(z!==C){var G=d.stateNode,ne=fl(),se=p0(G,D,z,C,O,ne);d.updateQueue=se,se&&H0(d)}},Md=function(c,d,D,C){D!==C&&H0(d)};else if(Q){Ca=function(c,d,D,C){for(var O=d.child;O!==null;){e:if(O.tag===V){var z=O.stateNode;if(D&&C){var G=O.memoizedProps,ne=O.type;z=Jr(z,ne,G,O)}Xr(c,z)}else if(O.tag===re){var se=O.stateNode;if(D&&C){var Ue=O.memoizedProps;se=Zl(se,Ue,O)}Xr(c,se)}else if(Wt&&O.tag===_t){var Xe=O.stateNode.instance;if(D&&C){var ht=O.memoizedProps,Lt=O.type;Xe=Jr(Xe,Lt,ht,O)}Xr(c,Xe)}else if(O.tag!==q){if(O.tag===he){if((O.effectTag&Dr)!==xi){var Gt=O.memoizedState!==null;if(Gt){var Ht=O.child;if(Ht!==null){Ht.child!==null&&(Ht.child.return=Ht,Ca(c,Ht,!0,Gt));var yn=Ht.sibling;if(yn!==null){yn.return=O,O=yn;continue}}}}if(O.child!==null){O.child.return=O,O=O.child;continue}}else if(O.child!==null){O.child.return=O,O=O.child;continue}}if(O=O,O===d)return;for(;O.sibling===null;){if(O.return===null||O.return===d)return;O=O.return}O.sibling.return=O.return,O=O.sibling}};var cp=function(c,d,D,C){for(var O=d.child;O!==null;){e:if(O.tag===V){var z=O.stateNode;if(D&&C){var G=O.memoizedProps,ne=O.type;z=Jr(z,ne,G,O)}Qn(c,z)}else if(O.tag===re){var se=O.stateNode;if(D&&C){var Ue=O.memoizedProps;se=Zl(se,Ue,O)}Qn(c,se)}else if(Wt&&O.tag===_t){var Xe=O.stateNode.instance;if(D&&C){var ht=O.memoizedProps,Lt=O.type;Xe=Jr(Xe,Lt,ht,O)}Qn(c,Xe)}else if(O.tag!==q){if(O.tag===he){if((O.effectTag&Dr)!==xi){var Gt=O.memoizedState!==null;if(Gt){var Ht=O.child;if(Ht!==null){Ht.child!==null&&(Ht.child.return=Ht,cp(c,Ht,!0,Gt));var yn=Ht.sibling;if(yn!==null){yn.return=O,O=yn;continue}}}}if(O.child!==null){O.child.return=O,O=O.child;continue}}else if(O.child!==null){O.child.return=O,O=O.child;continue}}if(O=O,O===d)return;for(;O.sibling===null;){if(O.return===null||O.return===d)return;O=O.return}O.sibling.return=O.return,O=O.sibling}};$a=function(c){var d=c.stateNode,D=c.firstEffect===null;if(!D){var C=d.containerInfo,O=S0(C);cp(O,c,!1,!1),d.pendingChildren=O,H0(c),ac(C,O)}},Od=function(c,d,D,C,O){var z=c.stateNode,G=c.memoizedProps,ne=d.firstEffect===null;if(ne&&G===C){d.stateNode=z;return}var se=d.stateNode,Ue=fl(),Xe=null;if(G!==C&&(Xe=p0(se,D,G,C,O,Ue)),ne&&Xe===null){d.stateNode=z;return}var ht=ms(z,Xe,D,G,C,d,ne,se);Au(ht,D,C,O,Ue)&&H0(d),d.stateNode=ht,ne?H0(d):Ca(ht,d,!1,!1)},Md=function(c,d,D,C){if(D!==C){var O=ns(),z=fl();d.stateNode=hs(C,O,z,d),H0(d)}}}else $a=function(c){},Od=function(c,d,D,C,O){},Md=function(c,d,D,C){};function kd(c,d){switch(c.tailMode){case"hidden":{for(var D=c.tail,C=null;D!==null;)D.alternate!==null&&(C=D),D=D.sibling;C===null?c.tail=null:C.sibling=null;break}case"collapsed":{for(var O=c.tail,z=null;O!==null;)O.alternate!==null&&(z=O),O=O.sibling;z===null?!d&&c.tail!==null?c.tail.sibling=null:c.tail=null:z.sibling=null;break}}}function tv(c,d,D){var C=d.pendingProps;switch(d.tag){case x:break;case Ae:break;case ue:case F:break;case k:{var O=d.type;Xi(O)&&Hs(d);break}case j:{uo(d),R0(d);var z=d.stateNode;if(z.pendingContext&&(z.context=z.pendingContext,z.pendingContext=null),c===null||c.child===null){var G=h1(d);G&&H0(d)}$a(d);break}case V:{M2(d);var ne=ns(),se=d.type;if(c!==null&&d.stateNode!=null){if(Od(c,d,se,C,ne),yi){var Ue=c.memoizedProps.listeners,Xe=C.listeners;Ue!==Xe&&H0(d)}c.ref!==d.ref&&Ad(d)}else{if(!C){if(d.stateNode===null)throw Error("We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue.");break}var ht=fl(),Lt=h1(d);if(Lt){if(vm(d,ne,ht)&&H0(d),yi){var Gt=C.listeners;Gt!=null&&hn(Gt,d,ne)}}else{var Ht=Ki(se,C,ne,ht,d);if(Ca(Ht,d,!1,!1),d.stateNode=Ht,yi){var yn=C.listeners;yn!=null&&hn(yn,d,ne)}Au(Ht,se,C,ne,ht)&&H0(d)}d.ref!==null&&Ad(d)}break}case re:{var kr=C;if(c&&d.stateNode!=null){var ii=c.memoizedProps;Md(c,d,ii,kr)}else{if(typeof kr!="string"&&d.stateNode===null)throw Error("We must have new props for new mounts. This error is likely caused by a bug in React. Please file an issue.");var Oi=ns(),L0=fl(),$i=h1(d);$i?mm(d)&&H0(d):d.stateNode=hs(kr,Oi,L0,d)}break}case ae:break;case he:{ga(d);var lt=d.memoizedState;if(Ai&<!==null&<.dehydrated!==null)if(c===null){var Mt=h1(d);if(!Mt)throw Error("A dehydrated suspense component was completed without a hydrated node. This is probably a bug in React.");return Ih(d),In&&R(Di),null}else return v1(),(d.effectTag&Kr)===xi&&(d.memoizedState=null),d.effectTag|=Dr,null;if((d.effectTag&Kr)!==xi)return d.expirationTime=D,d;var $e=lt!==null,jt=!1;if(c===null)d.memoizedProps.fallback!==void 0&&h1(d);else{var Fn=c.memoizedState;if(jt=Fn!==null,!$e&&Fn!==null){var vn=c.child.sibling;if(vn!==null){var Vi=d.firstEffect;Vi!==null?(d.firstEffect=vn,vn.nextEffect=Vi):(d.firstEffect=d.lastEffect=vn,vn.nextEffect=null),vn.effectTag=Y0}}}if($e&&!jt&&(d.mode&K)!==Ar){var ci=c===null&&d.memoizedProps.unstable_avoidThisFallback!==!0;ci||t1(Nl.current,xf)?_v():Ev()}Q&&$e&&(d.effectTag|=Dr),b0&&($e||jt)&&(d.effectTag|=Dr),Yi&&d.updateQueue!==null&&d.memoizedProps.suspenseCallback!=null&&(d.effectTag|=Dr);break}case y:break;case me:break;case we:break;case q:uo(d),$a(d);break;case ge:r0(d);break;case De:break;case ve:break;case ze:{var Yu=d.type;Xi(Yu)&&Hs(d);break}case gt:{ga(d);var hr=d.memoizedState;if(hr===null)break;var pu=(d.effectTag&Kr)!==xi,Yr=hr.rendering;if(Yr===null)if(pu)kd(hr,!1);else{var Cu=Dv()&&(c===null||(c.effectTag&Kr)===xi);if(!Cu)for(var D0=d.child;D0!==null;){var W0=n1(D0);if(W0!==null){pu=!0,d.effectTag|=Kr,kd(hr,!1);var Ms=W0.updateQueue;return Ms!==null&&(d.updateQueue=Ms,d.effectTag|=Dr),hr.lastEffect===null&&(d.firstEffect=null),d.lastEffect=hr.lastEffect,sm(d,D),Fr(d,hd(Nl.current,e1)),d.child}D0=D0.sibling}}else{if(!pu){var Ku=n1(Yr);if(Ku!==null){d.effectTag|=Kr,pu=!0;var gl=Ku.updateQueue;if(gl!==null&&(d.updateQueue=gl,d.effectTag|=Dr),kd(hr,!0),hr.tail===null&&hr.tailMode==="hidden"&&!Yr.alternate){var rf=d.lastEffect=hr.lastEffect;return rf!==null&&(rf.nextEffect=null),null}}else if(mt()>hr.tailExpiration&&D>Di){d.effectTag|=Kr,pu=!0,kd(hr,!1);var Vo=D-1;d.expirationTime=d.childExpirationTime=Vo,In&&R(Vo)}}if(hr.isBackwards)Yr.sibling=d.child,d.child=Yr;else{var ks=hr.last;ks!==null?ks.sibling=Yr:d.child=Yr,hr.last=Yr}}if(hr.tail!==null){if(hr.tailExpiration===0){var Jd=500;hr.tailExpiration=mt()+Jd}var Vf=hr.tail;hr.rendering=Vf,hr.tail=Vf.sibling,hr.lastEffect=d.lastEffect,Vf.sibling=null;var Lc=Nl.current;return pu?Lc=hd(Lc,e1):Lc=ya(Lc),Fr(d,Lc),Vf}break}case _t:{if(Wt){var Hl=d.type.impl,Go=d.stateNode;if(Go===null){var L1=Hl.getInitialState,i_;L1!==void 0&&(i_=L1(C)),Go=d.stateNode=Qh(d,C,Hl,i_||{});var u_=pt(Go);if(Go.instance=u_,Hl.reconcileChildren===!1)return null;Ca(u_,d,!1,!1),Yn(Go)}else{var nE=Go.props;if(Go.prevProps=nE,Go.props=C,Go.currentFiber=d,Q){var o_=oa(Go);Go.instance=o_,Ca(o_,d,!1,!1)}var rE=Cn(Go);rE&&H0(d)}}break}case Qe:{if(Ru)if(c===null){var iE=d.type,Ry={fiber:d,methods:null};if(d.stateNode=Ry,Ry.methods=Rd(iE,Ry),yi){var l_=C.listeners;if(l_!=null){var uE=ns();hn(l_,d,uE)}}d.ref!==null&&(Ad(d),H0(d))}else{if(yi){var oE=c.memoizedProps.listeners,lE=C.listeners;(oE!==lE||d.ref!==null)&&H0(d)}else d.ref!==null&&H0(d);c.ref!==d.ref&&Ad(d)}break}default:throw Error("Unknown unit of work tag ("+d.tag+"). This error is likely caused by a bug in React. Please file an issue.")}return null}function Mm(c,d){switch(c.tag){case k:{var D=c.type;Xi(D)&&Hs(c);var C=c.effectTag;return C&d0?(c.effectTag=C&~d0|Kr,c):null}case j:{uo(c),R0(c);var O=c.effectTag;if((O&Kr)!==xi)throw Error("The root failed to unmount after an error. This is likely a bug in React. Please file an issue.");return c.effectTag=O&~d0|Kr,c}case V:return M2(c),null;case he:{if(ga(c),Ai){var z=c.memoizedState;if(z!==null&&z.dehydrated!==null){if(c.alternate===null)throw Error("Threw in newly mounted dehydrated component. This is likely a bug in React. Please file an issue.");v1()}}var G=c.effectTag;return G&d0?(c.effectTag=G&~d0|Kr,c):null}case gt:return ga(c),null;case q:return uo(c),null;case ge:return r0(c),null;default:return null}}function nv(c){switch(c.tag){case k:{var d=c.type.childContextTypes;d!=null&&Hs(c);break}case j:{uo(c),R0(c);break}case V:{M2(c);break}case q:uo(c);break;case he:ga(c);break;case gt:ga(c);break;case ge:r0(c);break;default:break}}function dp(c,d){return{value:c,source:d,stack:Cr(d)}}var pp=function(c,d,D,C,O,z,G,ne,se){var Ue=Array.prototype.slice.call(arguments,3);try{d.apply(D,Ue)}catch(Xe){this.onError(Xe)}};if(typeof window<"u"&&typeof window.dispatchEvent=="function"&&typeof document<"u"&&typeof document.createEvent=="function"){var hp=document.createElement("react"),km=function(c,d,D,C,O,z,G,ne,se){if(!(typeof document<"u"))throw Error("The `document` global was defined when React was initialized, but is not defined anymore. This can happen in a test environment if a component schedules an update from an asynchronous callback, but the test has already finished running. To solve this, you can either unmount the component at the end of your test (and ensure that any asynchronous operations get canceled in `componentWillUnmount`), or you can change the test itself to be asynchronous.");var Ue=document.createEvent("Event"),Xe=!0,ht=window.event,Lt=Object.getOwnPropertyDescriptor(window,"event"),Gt=Array.prototype.slice.call(arguments,3);function Ht(){hp.removeEventListener(L0,Ht,!1),typeof window.event<"u"&&window.hasOwnProperty("event")&&(window.event=ht),d.apply(D,Gt),Xe=!1}var yn,kr=!1,ii=!1;function Oi($i){if(yn=$i.error,kr=!0,yn===null&&$i.colno===0&&$i.lineno===0&&(ii=!0),$i.defaultPrevented&&yn!=null&&typeof yn=="object")try{yn._suppressLogging=!0}catch{}}var L0="react-"+(c||"invokeguardedcallback");window.addEventListener("error",Oi),hp.addEventListener(L0,Ht,!1),Ue.initEvent(L0,!1,!1),hp.dispatchEvent(Ue),Lt&&Object.defineProperty(window,"event",Lt),Xe&&(kr?ii&&(yn=new Error("A cross-origin error was thrown. React doesn't have access to the actual error object in development. See https://fb.me/react-crossorigin-error for more information.")):yn=new Error(`An error was thrown inside one of your components, but React doesn't know what it was. This is likely due to browser flakiness. React does its best to preserve the "Pause on exceptions" behavior of the DevTools, which requires some DEV-mode only tricks. It's possible that these don't work in your browser. Try triggering the error in production mode, or switching to a modern browser. If you suspect that this is actually an issue with React, please file an issue.`),this.onError(yn)),window.removeEventListener("error",Oi)};pp=km}var Nm=pp,So=!1,Nd=null,Lm={onError:function(c){So=!0,Nd=c}};function pl(c,d,D,C,O,z,G,ne,se){So=!1,Nd=null,Nm.apply(Lm,arguments)}function tr(){return So}function Qs(){if(So){var c=Nd;return So=!1,Nd=null,c}else throw Error("clearCaughtError was called but no error was captured. This error is likely caused by a bug in React. Please file an issue.")}function hl(c){return!0}function o0(c){var d=hl(c);if(d!==!1){var D=c.error;{var C=c.componentName,O=c.componentStack,z=c.errorBoundaryName,G=c.errorBoundaryFound,ne=c.willRetry;if(D!=null&&D._suppressLogging){if(G&&ne)return;console.error(D)}var se=C?"The above error occurred in the <"+C+"> component:":"The above error occurred in one of your React components:",Ue;G&&z?ne?Ue="React will try to recreate this component tree from scratch "+("using the error boundary you provided, "+z+"."):Ue="This error was initially handled by the error boundary "+z+`. +Recreating the tree from scratch failed so React will unmount the tree.`:Ue=`Consider adding an error boundary to your tree to customize error handling behavior. +Visit https://fb.me/react-error-boundaries to learn more about error boundaries.`;var Xe=""+se+O+` + +`+(""+Ue);console.error(Xe)}}}var rv=null;rv=new Set;var Js=typeof WeakSet=="function"?WeakSet:Set;function vp(c,d){var D=d.source,C=d.stack;C===null&&D!==null&&(C=Cr(D));var O={componentName:D!==null?qt(D.type):null,componentStack:C!==null?C:"",error:d.value,errorBoundary:null,errorBoundaryName:null,errorBoundaryFound:!1,willRetry:!1};c!==null&&c.tag===k&&(O.errorBoundary=c.stateNode,O.errorBoundaryName=qt(c.type),O.errorBoundaryFound=!0,O.willRetry=!0);try{o0(O)}catch(z){setTimeout(function(){throw z})}}var Fm=function(c,d){Bi(c,"componentWillUnmount"),d.props=c.memoizedProps,d.state=c.memoizedState,d.componentWillUnmount(),Ci()};function iv(c,d){if(pl(null,Fm,null,c,d),tr()){var D=Qs();Hf(c,D)}}function mp(c){var d=c.ref;if(d!==null)if(typeof d=="function"){if(pl(null,d,null,null),tr()){var D=Qs();Hf(c,D)}}else d.current=null}function Pm(c,d){if(pl(null,d,null),tr()){var D=Qs();Hf(c,D)}}function yp(c,d){switch(d.tag){case F:case ae:case ue:{Tc(fm,Af,d);return}case k:{if(d.effectTag&Mo&&c!==null){var D=c.memoizedProps,C=c.memoizedState;Bi(d,"getSnapshotBeforeUpdate");var O=d.stateNode;d.type===d.elementType&&!Sa&&(O.props!==d.memoizedProps&&Xt(!1,"Expected %s props to match memoized props before getSnapshotBeforeUpdate. This might either be because of a bug in React, or because a component reassigns its own `this.props`. Please file an issue.",qt(d.type)||"instance"),O.state!==d.memoizedState&&Xt(!1,"Expected %s state to match memoized state before getSnapshotBeforeUpdate. This might either be because of a bug in React, or because a component reassigns its own `this.props`. Please file an issue.",qt(d.type)||"instance"));var z=O.getSnapshotBeforeUpdate(d.elementType===d.type?D:Wi(d.type,D),C);{var G=rv;z===void 0&&!G.has(d.type)&&(G.add(d.type),Ve(!1,"%s.getSnapshotBeforeUpdate(): A snapshot value (or null) must be returned. You have returned undefined.",qt(d.type)))}O.__reactInternalSnapshotBeforeUpdate=z,Ci()}return}case j:case V:case re:case q:case ze:return;default:throw Error("This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue.")}}function Tc(c,d,D){var C=D.updateQueue,O=C!==null?C.lastEffect:null;if(O!==null){var z=O.next,G=z;do{if((G.tag&c)!==Af){var ne=G.destroy;G.destroy=void 0,ne!==void 0&&ne()}if((G.tag&d)!==Af){var se=G.create;G.destroy=se();{var Ue=G.destroy;if(Ue!==void 0&&typeof Ue!="function"){var Xe=void 0;Ue===null?Xe=" You returned null. If your effect does not require clean up, return undefined (or nothing).":typeof Ue.then=="function"?Xe=` + +It looks like you wrote useEffect(async () => ...) or returned a Promise. Instead, write the async function inside your effect and call it immediately: + +useEffect(() => { + async function fetchData() { + // You can await here + const response = await MyAPI.getData(someId); + // ... + } + fetchData(); +}, [someId]); // Or [] if effect doesn't need props or state + +Learn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching`:Xe=" You returned: "+Ue,Ve(!1,"An effect function must not return anything besides a function, which is used for clean-up.%s%s",Xe,Cr(D))}}}G=G.next}while(G!==z)}}function xa(c){if((c.effectTag&F0)!==xi)switch(c.tag){case F:case ae:case ue:{Tc(sr,Af,c),Tc(Af,r1,c);break}default:break}}function gp(c,d,D,C){switch(D.tag){case F:case ae:case ue:{Tc(cm,cl,D);break}case k:{var O=D.stateNode;if(D.effectTag&Dr)if(d===null)Bi(D,"componentDidMount"),D.type===D.elementType&&!Sa&&(O.props!==D.memoizedProps&&Xt(!1,"Expected %s props to match memoized props before componentDidMount. This might either be because of a bug in React, or because a component reassigns its own `this.props`. Please file an issue.",qt(D.type)||"instance"),O.state!==D.memoizedState&&Xt(!1,"Expected %s state to match memoized state before componentDidMount. This might either be because of a bug in React, or because a component reassigns its own `this.props`. Please file an issue.",qt(D.type)||"instance")),O.componentDidMount(),Ci();else{var z=D.elementType===D.type?d.memoizedProps:Wi(D.type,d.memoizedProps),G=d.memoizedState;Bi(D,"componentDidUpdate"),D.type===D.elementType&&!Sa&&(O.props!==D.memoizedProps&&Xt(!1,"Expected %s props to match memoized props before componentDidUpdate. This might either be because of a bug in React, or because a component reassigns its own `this.props`. Please file an issue.",qt(D.type)||"instance"),O.state!==D.memoizedState&&Xt(!1,"Expected %s state to match memoized state before componentDidUpdate. This might either be because of a bug in React, or because a component reassigns its own `this.props`. Please file an issue.",qt(D.type)||"instance")),O.componentDidUpdate(z,G,O.__reactInternalSnapshotBeforeUpdate),Ci()}var ne=D.updateQueue;ne!==null&&(D.type===D.elementType&&!Sa&&(O.props!==D.memoizedProps&&Xt(!1,"Expected %s props to match memoized props before processing the update queue. This might either be because of a bug in React, or because a component reassigns its own `this.props`. Please file an issue.",qt(D.type)||"instance"),O.state!==D.memoizedState&&Xt(!1,"Expected %s state to match memoized state before processing the update queue. This might either be because of a bug in React, or because a component reassigns its own `this.props`. Please file an issue.",qt(D.type)||"instance")),go(D,ne,O,C));return}case j:{var se=D.updateQueue;if(se!==null){var Ue=null;if(D.child!==null)switch(D.child.tag){case V:Ue=Lo(D.child.stateNode);break;case k:Ue=D.child.stateNode;break}go(D,se,Ue,C)}return}case V:{var Xe=D.stateNode;if(d===null&&D.effectTag&Dr){var ht=D.type,Lt=D.memoizedProps;zu(Xe,ht,Lt,D)}return}case re:return;case q:return;case we:{if(en){var Gt=D.memoizedProps.onRender;typeof Gt=="function"&&(In?Gt(D.memoizedProps.id,d===null?"mount":"update",D.actualDuration,D.treeBaseDuration,D.actualStartTime,Il(),c.memoizedInteractions):Gt(D.memoizedProps.id,d===null?"mount":"update",D.actualDuration,D.treeBaseDuration,D.actualStartTime,Il()))}return}case he:{Bl(c,D);return}case gt:case ze:case _t:case Qe:return;default:throw Error("This unit of work tag should not have side-effects. This error is likely caused by a bug in React. Please file an issue.")}}function Ld(c,d){if(b0)for(var D=c;;){if(D.tag===V){var C=D.stateNode;d?Pa(C):ia(D.stateNode,D.memoizedProps)}else if(D.tag===re){var O=D.stateNode;d?v0(O):J0(O,D.memoizedProps)}else if(D.tag===he&&D.memoizedState!==null&&D.memoizedState.dehydrated===null){var z=D.child.sibling;z.return=D,D=z;continue}else if(D.child!==null){D.child.return=D,D=D.child;continue}if(D===c)return;for(;D.sibling===null;){if(D.return===null||D.return===c)return;D=D.return}D.sibling.return=D.return,D=D.sibling}}function Iu(c){var d=c.ref;if(d!==null){var D=c.stateNode,C;switch(c.tag){case V:C=Lo(D);break;default:C=D}Ru&&c.tag===Qe&&(C=D.methods),typeof d=="function"?d(C):(d.hasOwnProperty("current")||Ve(!1,"Unexpected ref object provided for %s. Use either a ref-setter function or React.createRef().%s",qt(c.type),Cr(c)),d.current=C)}}function Gu(c){var d=c.ref;d!==null&&(typeof d=="function"?d(null):d.current=null)}function _p(c,d,D){switch(Mn(d),d.tag){case F:case ae:case ve:case ue:{var C=d.updateQueue;if(C!==null){var O=C.lastEffect;if(O!==null){var z=O.next,G=D>Kn?Kn:D;Sn(G,function(){var ii=z;do{var Oi=ii.destroy;Oi!==void 0&&Pm(d,Oi),ii=ii.next}while(ii!==z)})}}break}case k:{mp(d);var ne=d.stateNode;typeof ne.componentWillUnmount=="function"&&iv(d,ne);return}case V:{if(yi){var se=d.dependencies;if(se!==null){var Ue=se.responders;if(Ue!==null){for(var Xe=Array.from(Ue.values()),ht=0,Lt=Xe.length;ht component higher in the tree to provide a loading indicator or placeholder to display.`+Cr(D))}Op(),C=dp(C,D);var Lt=d;do{switch(Lt.tag){case j:{var Gt=C;Lt.effectTag|=d0,Lt.expirationTime=O;var Ht=sv(Lt,Gt,O);od(Lt,Ht);return}case k:var yn=C,kr=Lt.type,ii=Lt.stateNode;if((Lt.effectTag&Kr)===xi&&(typeof kr.getDerivedStateFromError=="function"||ii!==null&&typeof ii.componentDidCatch=="function"&&!Fp(ii))){Lt.effectTag|=d0,Lt.expirationTime=O;var Oi=av(Lt,yn,O);od(Lt,Oi);return}break;default:break}Lt=Lt.return}while(Lt!==null)}var Aa=Math.ceil,Mr=it.ReactCurrentDispatcher,Dp=it.ReactCurrentOwner,vl=it.IsSomeRendererActing,yu=0,T1=1,Ui=2,wp=4,Id=8,To=16,As=32,bf=0,bd=1,Sp=2,C1=3,x1=4,Tp=5,nr=yu,ml=null,Gn=null,q0=ft,k0=bf,Bd=null,Ul=Un,R1=Un,xc=null,Rc=ft,Ud=!1,Cp=0,N0=500,dn=null,jd=!1,zd=null,Ac=null,Oc=!1,Mc=null,A1=_0,xp=ft,ef=null,Hm=50,kc=0,Hd=null,cv=50,O1=0,Bf=null,Uf=null,M1=ft;function jl(){return(nr&(To|As))!==yu?t0(mt()):(M1!==ft||(M1=t0(mt())),M1)}function Nc(){return t0(mt())}function jf(c,d,D){var C=d.mode;if((C&K)===Ar)return Un;var O=Qt();if((C&ti)===Ar)return O===Li?Un:e0;if((nr&To)!==yu)return q0;var z;if(D!==null)z=fa(c,D.timeoutMs|0||_f);else switch(O){case Li:z=Un;break;case ei:z=Ua(c);break;case Kn:case $u:z=Ds(c);break;case g0:z=ru;break;default:throw Error("Expected a valid priority level")}return ml!==null&&z===q0&&(z-=1),z}function qm(c,d){sy(),dy(c);var D=qd(c,d);if(D===null){fy(c);return}jp(c,d),la();var C=Qt();if(d===Un?(nr&Id)!==yu&&(nr&(To|As))===yu?(W(D,d),k1(D)):(Wo(D),W(D,d),nr===yu&&Ut()):(Wo(D),W(D,d)),(nr&wp)!==yu&&(C===ei||C===Li))if(ef===null)ef=new Map([[D,d]]);else{var O=ef.get(D);(O===void 0||O>d)&&ef.set(D,d)}}var yl=qm;function qd(c,d){c.expirationTimeO?C:O}function Wo(c){var d=c.lastExpiredTime;if(d!==ft){c.callbackExpirationTime=Un,c.callbackPriority=Li,c.callbackNode=Tn(k1.bind(null,c));return}var D=Wd(c),C=c.callbackNode;if(D===ft){C!==null&&(c.callbackNode=null,c.callbackExpirationTime=ft,c.callbackPriority=_0);return}var O=jl(),z=nd(O,D);if(C!==null){var G=c.callbackPriority,ne=c.callbackExpirationTime;if(ne===D&&G>=z)return;ir(C)}c.callbackExpirationTime=D,c.callbackPriority=z;var se;D===Un?se=Tn(k1.bind(null,c)):ao?se=_n(z,Vd.bind(null,c)):se=_n(z,Vd.bind(null,c),{timeout:jo(D)-mt()}),c.callbackNode=se}function Vd(c,d){if(M1=ft,d){var D=jl();return qp(c,D),Wo(c),null}var C=Wd(c);if(C!==ft){var O=c.callbackNode;if((nr&(To|As))!==yu)throw Error("Should not already be working.");if(tf(),(c!==ml||C!==q0)&&(zf(c,C),te(c,C)),Gn!==null){var z=nr;nr|=To;var G=mv(c),ne=Gd(c);mf(Gn);do try{ey();break}catch(Xe){vv(c,Xe)}while(!0);if(yt(),nr=z,yv(G),In&&Yd(ne),k0===bd){var se=Bd;throw Up(),zf(c,C),Wf(c,C),Wo(c),se}if(Gn!==null)Up();else{Rv();var Ue=c.finishedWork=c.current.alternate;c.finishedExpirationTime=C,Wm(c,Ue,k0,C)}if(Wo(c),c.callbackNode===O)return Vd.bind(null,c)}}return null}function Wm(c,d,D,C){switch(ml=null,D){case bf:case bd:throw Error("Root did not complete. This is a bug in React.");case Sp:{qp(c,C>ru?ru:C);break}case C1:{Wf(c,C);var O=c.lastSuspendedTime;C===O&&(c.nextKnownPendingLevel=Mp(d)),p();var z=Ul===Un;if(z&&!(Q0&&qf.current)){var G=Cp+N0-mt();if(G>10){if(Ud){var ne=c.lastPingedTime;if(ne===ft||ne>=C){c.lastPingedTime=C,zf(c,C);break}}var se=Wd(c);if(se!==ft&&se!==C)break;if(O!==ft&&O!==C){c.lastPingedTime=O;break}c.timeoutHandle=Ct(l0.bind(null,c),G);break}}l0(c);break}case x1:{Wf(c,C);var Ue=c.lastSuspendedTime;if(C===Ue&&(c.nextKnownPendingLevel=Mp(d)),p(),!(Q0&&qf.current)){if(Ud){var Xe=c.lastPingedTime;if(Xe===ft||Xe>=C){c.lastPingedTime=C,zf(c,C);break}}var ht=Wd(c);if(ht!==ft&&ht!==C)break;if(Ue!==ft&&Ue!==C){c.lastPingedTime=Ue;break}var Lt;if(R1!==Un)Lt=jo(R1)-mt();else if(Ul===Un)Lt=0;else{var Gt=wv(Ul),Ht=mt(),yn=jo(C)-Ht,kr=Ht-Gt;kr<0&&(kr=0),Lt=bp(kr)-kr,yn10){c.timeoutHandle=Ct(l0.bind(null,c),Lt);break}}l0(c);break}case Tp:{if(!(Q0&&qf.current)&&Ul!==Un&&xc!==null){var ii=Bp(Ul,C,xc);if(ii>10){Wf(c,C),c.timeoutHandle=Ct(l0.bind(null,c),ii);break}}l0(c);break}default:throw Error("Unknown root exit status.")}}function k1(c){var d=c.lastExpiredTime,D=d!==ft?d:Un;if(c.finishedExpirationTime===D)l0(c);else{if((nr&(To|As))!==yu)throw Error("Should not already be working.");if(tf(),(c!==ml||D!==q0)&&(zf(c,D),te(c,D)),Gn!==null){var C=nr;nr|=To;var O=mv(c),z=Gd(c);mf(Gn);do try{Sv();break}catch(ne){vv(c,ne)}while(!0);if(yt(),nr=C,yv(O),In&&Yd(z),k0===bd){var G=Bd;throw Up(),zf(c,D),Wf(c,D),Wo(c),G}if(Gn!==null)throw Error("Cannot commit an incomplete root. This error is likely caused by a bug in React. Please file an issue.");Rv(),c.finishedWork=c.current.alternate,c.finishedExpirationTime=D,Vm(c,k0,D),Wo(c)}}return null}function Vm(c,d,D){ml=null,(d===C1||d===x1)&&p(),l0(c)}function Gm(c,d){qp(c,d),Wo(c),(nr&(To|As))===yu&&Ut()}function dv(){if((nr&(T1|To|As))!==yu){(nr&To)!==yu&&Xt(!1,"unstable_flushDiscreteUpdates: Cannot flush updates when React is already rendering.");return}Km(),tf()}function Ym(c){return Sn(Kn,c)}function pv(c,d,D,C){return Sn(Li,c.bind(null,d,D,C))}function Km(){if(ef!==null){var c=ef;ef=null,c.forEach(function(d,D){qp(D,d),Wo(D)}),Ut()}}function Xm(c,d){var D=nr;nr|=T1;try{return c(d)}finally{nr=D,nr===yu&&Ut()}}function Qm(c,d){var D=nr;nr|=Ui;try{return c(d)}finally{nr=D,nr===yu&&Ut()}}function hv(c,d,D,C){var O=nr;nr|=wp;try{return Sn(ei,c.bind(null,d,D,C))}finally{nr=O,nr===yu&&Ut()}}function Jm(c,d){var D=nr;nr&=~T1,nr|=Id;try{return c(d)}finally{nr=D,nr===yu&&Ut()}}function Rp(c,d){if((nr&(To|As))!==yu)throw Error("flushSync was called from inside a lifecycle method. It cannot be called when React is already rendering.");var D=nr;nr|=T1;try{return Sn(Li,c.bind(null,d))}finally{nr=D,Ut()}}function Zm(c){var d=nr;nr|=T1;try{Sn(Li,c)}finally{nr=d,nr===yu&&Ut()}}function zf(c,d){c.finishedWork=null,c.finishedExpirationTime=ft;var D=c.timeoutHandle;if(D!==nl&&(c.timeoutHandle=nl,co(D)),Gn!==null)for(var C=Gn.return;C!==null;)nv(C),C=C.return;ml=c,Gn=Co(c.current,null,d),q0=d,k0=bf,Bd=null,Ul=Un,R1=Un,xc=null,Rc=ft,Ud=!1,In&&(Uf=null),Al.discardPendingWarnings(),Zs=null}function vv(c,d){do{try{if(yt(),_d(),ut(),Gn===null||Gn.return===null)return k0=bd,Bd=d,null;en&&Gn.mode&ni&&p1(Gn,!0),fv(c,Gn.return,Gn,d,q0),Gn=Tv(Gn)}catch(D){d=D;continue}return}while(!0)}function mv(c){var d=Mr.current;return Mr.current=f1,d===null?f1:d}function yv(c){Mr.current=c}function Gd(c){if(In){var d=N.__interactionsRef.current;return N.__interactionsRef.current=c.memoizedInteractions,d}return null}function Yd(c){In&&(N.__interactionsRef.current=c)}function Ap(){Cp=mt()}function gv(c,d){cru&&(Ul=c),d!==null&&cru&&(R1=c,xc=d)}function Kd(c){c>Rc&&(Rc=c)}function _v(){k0===bf&&(k0=C1)}function Ev(){(k0===bf||k0===C1)&&(k0=x1),Rc!==ft&&ml!==null&&(Wf(ml,q0),Kg(ml,Rc))}function Op(){k0!==Tp&&(k0=Sp)}function Dv(){return k0===bf}function wv(c){var d=jo(c);return d-_f}function $m(c,d){var D=jo(c);return D-(d.timeoutMs|0||_f)}function Sv(){for(;Gn!==null;)Gn=Xd(Gn)}function ey(){for(;Gn!==null&&!Ln();)Gn=Xd(Gn)}function Xd(c){var d=c.alternate;$l(c),wt(c);var D;return en&&(c.mode&ni)!==Ar?(H2(c),D=N1(d,c,q0),p1(c,!0)):D=N1(d,c,q0),ut(),c.memoizedProps=c.pendingProps,D===null&&(D=Tv(c)),Dp.current=null,D}function Tv(c){Gn=c;do{var d=Gn.alternate,D=Gn.return;if((Gn.effectTag&P0)===xi){wt(Gn);var C=void 0;if(!en||(Gn.mode&ni)===Ar?C=tv(d,Gn,q0):(H2(Gn),C=tv(d,Gn,q0),p1(Gn,!1)),Zr(Gn),ut(),ty(Gn),C!==null)return C;if(D!==null&&(D.effectTag&P0)===xi){D.firstEffect===null&&(D.firstEffect=Gn.firstEffect),Gn.lastEffect!==null&&(D.lastEffect!==null&&(D.lastEffect.nextEffect=Gn.firstEffect),D.lastEffect=Gn.lastEffect);var O=Gn.effectTag;O>lu&&(D.lastEffect!==null?D.lastEffect.nextEffect=Gn:D.firstEffect=Gn,D.lastEffect=Gn)}}else{var z=Mm(Gn,q0);if(en&&(Gn.mode&ni)!==Ar){p1(Gn,!1);for(var G=Gn.actualDuration,ne=Gn.child;ne!==null;)G+=ne.actualDuration,ne=ne.sibling;Gn.actualDuration=G}if(z!==null)return ho(Gn),z.effectTag&=Kl,z;Zr(Gn),D!==null&&(D.firstEffect=D.lastEffect=null,D.effectTag|=P0)}var se=Gn.sibling;if(se!==null)return se;Gn=D}while(Gn!==null);return k0===bf&&(k0=Tp),null}function Mp(c){var d=c.expirationTime,D=c.childExpirationTime;return d>D?d:D}function ty(c){if(!(q0!==Di&&c.childExpirationTime===Di)){var d=ft;if(en&&(c.mode&ni)!==Ar){for(var D=c.actualDuration,C=c.selfBaseDuration,O=c.alternate===null||c.child!==c.alternate.child,z=c.child;z!==null;){var G=z.expirationTime,ne=z.childExpirationTime;G>d&&(d=G),ne>d&&(d=ne),O&&(D+=z.actualDuration),C+=z.treeBaseDuration,z=z.sibling}c.actualDuration=D,c.treeBaseDuration=C}else for(var se=c.child;se!==null;){var Ue=se.expirationTime,Xe=se.childExpirationTime;Ue>d&&(d=Ue),Xe>d&&(d=Xe),se=se.sibling}c.childExpirationTime=d}}function l0(c){var d=Qt();return Sn(Li,kp.bind(null,c,d)),null}function kp(c,d){do tf();while(Mc!==null);if(ay(),(nr&(To|As))!==yu)throw Error("Should not already be working.");var D=c.finishedWork,C=c.finishedExpirationTime;if(D===null)return null;if(c.finishedWork=null,c.finishedExpirationTime=ft,D===c.current)throw Error("Cannot commit the same tree as before. This error is likely caused by a bug in React. Please file an issue.");c.callbackNode=null,c.callbackExpirationTime=ft,c.callbackPriority=_0,c.nextKnownPendingLevel=ft,eo();var O=Mp(D);q4(c,C,O),c===ml&&(ml=null,Gn=null,q0=ft);var z;if(D.effectTag>lu?D.lastEffect!==null?(D.lastEffect.nextEffect=D,z=D.firstEffect):z=D:z=D.firstEffect,z!==null){var G=nr;nr|=As;var ne=Gd(c);Dp.current=null,xe(),Hn(c.containerInfo),dn=z;do if(pl(null,ny,null),tr()){if(dn===null)throw Error("Should be working on an effect.");var se=Qs();Hf(dn,se),dn=dn.nextEffect}while(dn!==null);tt(),en&&Nh(),Ke(),dn=z;do if(pl(null,ry,null,c,d),tr()){if(dn===null)throw Error("Should be working on an effect.");var Ue=Qs();Hf(dn,Ue),dn=dn.nextEffect}while(dn!==null);Yt(),qr(c.containerInfo),c.current=D,Kt(),dn=z;do if(pl(null,Np,null,c,C),tr()){if(dn===null)throw Error("Should be working on an effect.");var Xe=Qs();Hf(dn,Xe),dn=dn.nextEffect}while(dn!==null);pr(),dn=null,fe(),In&&Yd(ne),nr=G}else c.current=D,xe(),tt(),en&&Nh(),Ke(),Yt(),Kt(),pr();to();var ht=Oc;if(Oc)Oc=!1,Mc=c,xp=C,A1=d;else for(dn=z;dn!==null;){var Lt=dn.nextEffect;dn.nextEffect=null,dn=Lt}var Gt=c.firstPendingTime;if(Gt!==ft){if(In){if(Uf!==null){var Ht=Uf;Uf=null;for(var yn=0;ynKn?Kn:A1;return A1=_0,Sn(c,Lp)}}function Lp(){if(Mc===null)return!1;var c=Mc,d=xp;if(Mc=null,xp=ft,(nr&(To|As))!==yu)throw Error("Cannot flush passive effects while already rendering.");var D=nr;nr|=As;for(var C=Gd(c),O=c.current.firstEffect;O!==null;){{if(wt(O),pl(null,xa,null,O),tr()){if(O===null)throw Error("Should be working on an effect.");var z=Qs();Hf(O,z)}ut()}var G=O.nextEffect;O.nextEffect=null,O=G}return In&&(Yd(C),pe(c,d)),nr=D,Ut(),O1=Mc===null?0:O1+1,!0}function Fp(c){return Ac!==null&&Ac.has(c)}function Pp(c){Ac===null?Ac=new Set([c]):Ac.add(c)}function iy(c){jd||(jd=!0,zd=c)}var uy=iy;function Cv(c,d,D){var C=dp(D,d),O=sv(c,C,Un);Va(c,O);var z=qd(c,Un);z!==null&&(Wo(z),W(z,Un))}function Hf(c,d){if(c.tag===j){Cv(c,c,d);return}for(var D=c.return;D!==null;){if(D.tag===j){Cv(D,c,d);return}else if(D.tag===k){var C=D.type,O=D.stateNode;if(typeof C.getDerivedStateFromError=="function"||typeof O.componentDidCatch=="function"&&!Fp(O)){var z=dp(d,c),G=av(D,z,Un);Va(D,G);var ne=qd(D,Un);ne!==null&&(Wo(ne),W(ne,Un));return}}D=D.return}}function Ip(c,d,D){var C=c.pingCache;if(C!==null&&C.delete(d),ml===c&&q0===D){k0===x1||k0===C1&&Ul===Un&&mt()-CpHm)throw kc=0,Hd=null,Error("Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.");O1>cv&&(O1=0,Xt(!1,"Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render."))}function ay(){Al.flushLegacyContextWarning(),mi&&Al.flushPendingUnsafeLifecycleWarnings()}function Rv(){var c=!0;yf(Bf,c),Bf=null}function Up(){var c=!1;yf(Bf,c),Bf=null}function jp(c,d){Hr&&ml!==null&&d>q0&&(Bf=c)}var Qd=null;function fy(c){{var d=c.tag;if(d!==j&&d!==k&&d!==F&&d!==ae&&d!==ve&&d!==ue)return;var D=qt(c.type)||"ReactComponent";if(Qd!==null){if(Qd.has(D))return;Qd.add(D)}else Qd=new Set([D]);Ve(!1,"Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in %s.%s",d===k?"the componentWillUnmount method":"a useEffect cleanup function",Cr(c))}}var N1;if(X0){var cy=null;N1=function(c,d,D){var C=Gg(cy,d);try{return lp(c,d,D)}catch(z){if(z!==null&&typeof z=="object"&&typeof z.then=="function")throw z;if(yt(),_d(),nv(d),Gg(d,C),en&&d.mode&ni&&H2(d),pl(null,lp,null,c,d,D),tr()){var O=Qs();throw O}else throw z}}}else N1=lp;var Av=!1,Ov=!1;function dy(c){if(c.tag===k)switch(Nr){case"getChildContext":if(Ov)return;Ve(!1,"setState(...): Cannot call setState() inside getChildContext()"),Ov=!0;break;case"render":if(Av)return;Ve(!1,"Cannot update during an existing state transition (such as within `render`). Render methods should be a pure function of props and state."),Av=!0;break}}var qf={current:!1};function zp(c){vs===!0&&vl.current===!0&&qf.current!==!0&&Ve(!1,`It looks like you're using the wrong act() around your test interactions. +Be sure to use the matching version of act() corresponding to your renderer: + +// for react-dom: +import {act} from 'react-dom/test-utils'; +// ... +act(() => ...); + +// for react-test-renderer: +import TestRenderer from 'react-test-renderer'; +const {act} = TestRenderer; +// ... +act(() => ...);%s`,Cr(c))}function Mv(c){vs===!0&&(c.mode&mr)!==Ar&&vl.current===!1&&qf.current===!1&&Ve(!1,`An update to %s ran an effect, but was not wrapped in act(...). + +When testing, code that causes React state updates should be wrapped into act(...): + +act(() => { + /* fire events that update state */ +}); +/* assert on the output */ + +This ensures that you're testing the behavior the user would see in the browser. Learn more at https://fb.me/react-wrap-tests-with-act%s`,qt(c.type),Cr(c))}function py(c){vs===!0&&nr===yu&&vl.current===!1&&qf.current===!1&&Ve(!1,`An update to %s inside a test was not wrapped in act(...). + +When testing, code that causes React state updates should be wrapped into act(...): + +act(() => { + /* fire events that update state */ +}); +/* assert on the output */ + +This ensures that you're testing the behavior the user would see in the browser. Learn more at https://fb.me/react-wrap-tests-with-act%s`,qt(c.type),Cr(c))}var hy=py,Hp=!1;function vy(c){Hp===!1&&t.unstable_flushAllWithoutAsserting===void 0&&(c.mode&K||c.mode&ti?(Hp=!0,Ve(!1,`In Concurrent or Sync modes, the "scheduler" module needs to be mocked to guarantee consistent behaviour across tests and browsers. For example, with jest: +jest.mock('scheduler', () => require('scheduler/unstable_mock')); + +For more info, visit https://fb.me/react-mock-scheduler`)):eu===!0&&(Hp=!0,Ve(!1,`Starting from React v17, the "scheduler" module will need to be mocked to guarantee consistent behaviour across tests and browsers. For example, with jest: +jest.mock('scheduler', () => require('scheduler/unstable_mock')); + +For more info, visit https://fb.me/react-mock-scheduler`)))}var Zs=null;function my(c){{var d=Qt();if((c.mode&ti)!==xi&&(d===ei||d===Li))for(var D=c;D!==null;){var C=D.alternate;if(C!==null)switch(D.tag){case k:var O=C.updateQueue;if(O!==null)for(var z=O.firstUpdate;z!==null;){var G=z.priority;if(G===ei||G===Li){Zs===null?Zs=new Set([qt(D.type)]):Zs.add(qt(D.type));break}z=z.next}break;case F:case ae:case ue:if(D.memoizedState!==null&&D.memoizedState.baseUpdate!==null)for(var ne=D.memoizedState.baseUpdate;ne!==null;){var se=ne.priority;if(se===ei||se===Li){Zs===null?Zs=new Set([qt(D.type)]):Zs.add(qt(D.type));break}if(ne.next===D.memoizedState.baseUpdate)break;ne=ne.next}break;default:break}D=D.return}}}function p(){if(Zs!==null){var c=[];Zs.forEach(function(d){return c.push(d)}),Zs=null,c.length>0&&Ve(!1,`%s triggered a user-blocking update that suspended. + +The fix is to split the update into multiple parts: a user-blocking update to provide immediate feedback, and another update that triggers the bulk of the changes. + +Refer to the documentation for useTransition to learn how to implement this pattern.`,c.sort().join(", "))}}function m(c,d){return d*1e3+c.interactionThreadID}function R(c){!In||(Uf===null?Uf=[c]:Uf.push(c))}function I(c,d,D){if(!!In&&D.size>0){var C=c.pendingInteractionMap,O=C.get(d);O!=null?D.forEach(function(ne){O.has(ne)||ne.__count++,O.add(ne)}):(C.set(d,new Set(D)),D.forEach(function(ne){ne.__count++}));var z=N.__subscriberRef.current;if(z!==null){var G=m(c,d);z.onWorkScheduled(D,G)}}}function W(c,d){!In||I(c,d,N.__interactionsRef.current)}function te(c,d){if(!!In){var D=new Set;if(c.pendingInteractionMap.forEach(function(z,G){G>=d&&z.forEach(function(ne){return D.add(ne)})}),c.memoizedInteractions=D,D.size>0){var C=N.__subscriberRef.current;if(C!==null){var O=m(c,d);try{C.onWorkStarted(D,O)}catch(z){_n(Li,function(){throw z})}}}}}function pe(c,d){if(!!In){var D=c.firstPendingTime,C;try{if(C=N.__subscriberRef.current,C!==null&&c.memoizedInteractions.size>0){var O=m(c,d);C.onWorkStopped(c.memoizedInteractions,O)}}catch(G){_n(Li,function(){throw G})}finally{var z=c.pendingInteractionMap;z.forEach(function(G,ne){ne>D&&(z.delete(ne),G.forEach(function(se){if(se.__count--,C!==null&&se.__count===0)try{C.onInteractionScheduledWorkCompleted(se)}catch(Ue){_n(Li,function(){throw Ue})}}))})}}}var Ee=null,be=null,Dt=!1,Tt=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u";function Ot(c){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u")return!1;var d=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(d.isDisabled)return!0;if(!d.supportsFiber)return Ve(!1,"The installed version of React DevTools is too old and will not work with the current version of React. Please update React DevTools. https://fb.me/react-devtools"),!0;try{var D=d.inject(c);Ee=function(C,O){try{var z=(C.current.effectTag&Kr)===Kr;if(en){var G=Nc(),ne=nd(G,O);d.onCommitFiberRoot(D,C,ne,z)}else d.onCommitFiberRoot(D,C,void 0,z)}catch(se){Dt||(Dt=!0,Ve(!1,"React DevTools encountered an error: %s",se))}},be=function(C){try{d.onCommitFiberUnmount(D,C)}catch(O){Dt||(Dt=!0,Ve(!1,"React DevTools encountered an error: %s",O))}}}catch(C){Ve(!1,"React DevTools encountered an error: %s.",C)}return!0}function on(c,d){typeof Ee=="function"&&Ee(c,d)}function Mn(c){typeof be=="function"&&be(c)}var rr;{rr=!1;try{var br=Object.preventExtensions({}),ar=new Map([[br,null]]),ri=new Set([br]);ar.set(0,0),ri.add(0)}catch{rr=!0}}var fi=1;function zl(c,d,D,C){this.tag=c,this.key=D,this.elementType=null,this.type=null,this.stateNode=null,this.return=null,this.child=null,this.sibling=null,this.index=0,this.ref=null,this.pendingProps=d,this.memoizedProps=null,this.updateQueue=null,this.memoizedState=null,this.dependencies=null,this.mode=C,this.effectTag=xi,this.nextEffect=null,this.firstEffect=null,this.lastEffect=null,this.expirationTime=ft,this.childExpirationTime=ft,this.alternate=null,en&&(this.actualDuration=Number.NaN,this.actualStartTime=Number.NaN,this.selfBaseDuration=Number.NaN,this.treeBaseDuration=Number.NaN,this.actualDuration=0,this.actualStartTime=-1,this.selfBaseDuration=0,this.treeBaseDuration=0),Hr&&(this._debugID=fi++,this._debugIsCurrentlyTiming=!1),this._debugSource=null,this._debugOwner=null,this._debugNeedsRemount=!1,this._debugHookTypes=null,!rr&&typeof Object.preventExtensions=="function"&&Object.preventExtensions(this)}var Zi=function(c,d,D,C){return new zl(c,d,D,C)};function so(c){var d=c.prototype;return!!(d&&d.isReactComponent)}function s0(c){return typeof c=="function"&&!so(c)&&c.defaultProps===void 0}function Os(c){if(typeof c=="function")return so(c)?k:F;if(c!=null){var d=c.$$typeof;if(d===On)return ae;if(d===Vt)return ve}return x}function Co(c,d,D){var C=c.alternate;C===null?(C=Zi(c.tag,d,c.key,c.mode),C.elementType=c.elementType,C.type=c.type,C.stateNode=c.stateNode,C._debugID=c._debugID,C._debugSource=c._debugSource,C._debugOwner=c._debugOwner,C._debugHookTypes=c._debugHookTypes,C.alternate=c,c.alternate=C):(C.pendingProps=d,C.effectTag=xi,C.nextEffect=null,C.firstEffect=null,C.lastEffect=null,en&&(C.actualDuration=0,C.actualStartTime=-1)),C.childExpirationTime=c.childExpirationTime,C.expirationTime=c.expirationTime,C.child=c.child,C.memoizedProps=c.memoizedProps,C.memoizedState=c.memoizedState,C.updateQueue=c.updateQueue;var O=c.dependencies;switch(C.dependencies=O===null?null:{expirationTime:O.expirationTime,firstContext:O.firstContext,responders:O.responders},C.sibling=c.sibling,C.index=c.index,C.ref=c.ref,en&&(C.selfBaseDuration=c.selfBaseDuration,C.treeBaseDuration=c.treeBaseDuration),C._debugNeedsRemount=c._debugNeedsRemount,C.tag){case x:case F:case ue:C.type=n0(c.type);break;case k:C.type=j0(c.type);break;case ae:C.type=Df(c.type);break;default:break}return C}function kv(c,d){c.effectTag&=vi,c.nextEffect=null,c.firstEffect=null,c.lastEffect=null;var D=c.alternate;if(D===null)c.childExpirationTime=ft,c.expirationTime=d,c.child=null,c.memoizedProps=null,c.memoizedState=null,c.updateQueue=null,c.dependencies=null,en&&(c.selfBaseDuration=0,c.treeBaseDuration=0);else{c.childExpirationTime=D.childExpirationTime,c.expirationTime=D.expirationTime,c.child=D.child,c.memoizedProps=D.memoizedProps,c.memoizedState=D.memoizedState,c.updateQueue=D.updateQueue;var C=D.dependencies;c.dependencies=C===null?null:{expirationTime:C.expirationTime,firstContext:C.firstContext,responders:C.responders},en&&(c.selfBaseDuration=D.selfBaseDuration,c.treeBaseDuration=D.treeBaseDuration)}return c}function F4(c){var d;return c===O0?d=ti|K|mr:c===B0?d=K|mr:d=Ar,en&&Tt&&(d|=ni),Zi(j,null,null,d)}function yy(c,d,D,C,O,z){var G,ne=x,se=c;if(typeof c=="function")so(c)?(ne=k,se=j0(se)):se=n0(se);else if(typeof c=="string")ne=V;else{e:switch(c){case le:return nf(D.children,O,z,d);case an:ne=me,O|=ti|K|mr;break;case He:ne=me,O|=mr;break;case dt:return I4(D,O,z,d);case lr:return b4(D,O,z,d);case ln:return B4(D,O,z,d);default:{if(typeof c=="object"&&c!==null)switch(c.$$typeof){case At:ne=ge;break e;case nn:ne=De;break e;case On:ne=ae,se=Df(se);break e;case Vt:ne=ve;break e;case Er:ne=Ae,se=null;break e;case S:if(Wt)return Vg(c,D,O,z,d);break;case Xn:if(Ru)return P4(c,D,O,z,d)}var Ue="";{(c===void 0||typeof c=="object"&&c!==null&&Object.keys(c).length===0)&&(Ue+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var Xe=C?qt(C.type):null;Xe&&(Ue+=` + +Check the render method of \``+Xe+"`.")}throw Error("Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: "+(c==null?c:typeof c)+"."+Ue)}}}return G=Zi(ne,D,d,O),G.elementType=c,G.type=se,G.expirationTime=z,G}function gy(c,d,D){var C=null;C=c._owner;var O=c.type,z=c.key,G=c.props,ne=yy(O,z,G,C,d,D);return ne._debugSource=c._source,ne._debugOwner=c._owner,ne}function nf(c,d,D,C){var O=Zi(y,c,C,d);return O.expirationTime=D,O}function Vg(c,d,D,C,O){var z=Zi(_t,d,O,D);return z.elementType=c,z.type=c,z.expirationTime=C,z}function P4(c,d,D,C,O){var z=Zi(Qe,d,O,D);return z.type=c,z.elementType=c,z.expirationTime=C,z}function I4(c,d,D,C){(typeof c.id!="string"||typeof c.onRender!="function")&&Ve(!1,'Profiler must specify an "id" string and "onRender" function as props');var O=Zi(we,c,C,d|ni);return O.elementType=dt,O.type=dt,O.expirationTime=D,O}function b4(c,d,D,C){var O=Zi(he,c,C,d);return O.type=lr,O.elementType=lr,O.expirationTime=D,O}function B4(c,d,D,C){var O=Zi(gt,c,C,d);return O.type=ln,O.elementType=ln,O.expirationTime=D,O}function _y(c,d,D){var C=Zi(re,c,null,d);return C.expirationTime=D,C}function U4(){var c=Zi(V,null,null,Ar);return c.elementType="DELETED",c.type="DELETED",c}function j4(c){var d=Zi(We,null,null,Ar);return d.stateNode=c,d}function Ey(c,d,D){var C=c.children!==null?c.children:[],O=Zi(q,C,c.key,d);return O.expirationTime=D,O.stateNode={containerInfo:c.containerInfo,pendingChildren:null,implementation:c.implementation},O}function Gg(c,d){return c===null&&(c=Zi(x,null,null,Ar)),c.tag=d.tag,c.key=d.key,c.elementType=d.elementType,c.type=d.type,c.stateNode=d.stateNode,c.return=d.return,c.child=d.child,c.sibling=d.sibling,c.index=d.index,c.ref=d.ref,c.pendingProps=d.pendingProps,c.memoizedProps=d.memoizedProps,c.updateQueue=d.updateQueue,c.memoizedState=d.memoizedState,c.dependencies=d.dependencies,c.mode=d.mode,c.effectTag=d.effectTag,c.nextEffect=d.nextEffect,c.firstEffect=d.firstEffect,c.lastEffect=d.lastEffect,c.expirationTime=d.expirationTime,c.childExpirationTime=d.childExpirationTime,c.alternate=d.alternate,en&&(c.actualDuration=d.actualDuration,c.actualStartTime=d.actualStartTime,c.selfBaseDuration=d.selfBaseDuration,c.treeBaseDuration=d.treeBaseDuration),c._debugID=d._debugID,c._debugSource=d._debugSource,c._debugOwner=d._debugOwner,c._debugIsCurrentlyTiming=d._debugIsCurrentlyTiming,c._debugNeedsRemount=d._debugNeedsRemount,c._debugHookTypes=d._debugHookTypes,c}function z4(c,d,D){this.tag=d,this.current=null,this.containerInfo=c,this.pendingChildren=null,this.pingCache=null,this.finishedExpirationTime=ft,this.finishedWork=null,this.timeoutHandle=nl,this.context=null,this.pendingContext=null,this.hydrate=D,this.callbackNode=null,this.callbackPriority=_0,this.firstPendingTime=ft,this.firstSuspendedTime=ft,this.lastSuspendedTime=ft,this.nextKnownPendingLevel=ft,this.lastPingedTime=ft,this.lastExpiredTime=ft,In&&(this.interactionThreadID=N.unstable_getThreadID(),this.memoizedInteractions=new Set,this.pendingInteractionMap=new Map),Yi&&(this.hydrationCallbacks=null)}function H4(c,d,D,C){var O=new z4(c,d,D);Yi&&(O.hydrationCallbacks=C);var z=F4(d);return O.current=z,z.stateNode=O,O}function Yg(c,d){var D=c.firstSuspendedTime,C=c.lastSuspendedTime;return D!==ft&&D>=d&&C<=d}function Wf(c,d){var D=c.firstSuspendedTime,C=c.lastSuspendedTime;Dd||D===ft)&&(c.lastSuspendedTime=d),d<=c.lastPingedTime&&(c.lastPingedTime=ft),d<=c.lastExpiredTime&&(c.lastExpiredTime=ft)}function Kg(c,d){var D=c.firstPendingTime;d>D&&(c.firstPendingTime=d);var C=c.firstSuspendedTime;C!==ft&&(d>=C?c.firstSuspendedTime=c.lastSuspendedTime=c.nextKnownPendingLevel=ft:d>=c.lastSuspendedTime&&(c.lastSuspendedTime=d+1),d>c.nextKnownPendingLevel&&(c.nextKnownPendingLevel=d))}function q4(c,d,D){c.firstPendingTime=D,d<=c.lastSuspendedTime?c.firstSuspendedTime=c.lastSuspendedTime=c.nextKnownPendingLevel=ft:d<=c.firstSuspendedTime&&(c.firstSuspendedTime=d-1),d<=c.lastPingedTime&&(c.lastPingedTime=ft),d<=c.lastExpiredTime&&(c.lastExpiredTime=ft)}function qp(c,d){var D=c.lastExpiredTime;(D===ft||D>d)&&(c.lastExpiredTime=d)}var W4={debugTool:null},Nv=W4,Dy,wy;Dy=!1,wy={};function V4(c){if(!c)return xn;var d=Pt(c),D=xl(d);if(d.tag===k){var C=d.type;if(Xi(C))return A0(d,C,D)}return D}function Sy(c){var d=Pt(c);if(d===void 0)throw typeof c.render=="function"?Error("Unable to find node on an unmounted component."):Error("Argument appears to not be a ReactComponent. Keys: "+Object.keys(c));var D=I0(d);return D===null?null:D.stateNode}function G4(c,d){{var D=Pt(c);if(D===void 0)throw typeof c.render=="function"?Error("Unable to find node on an unmounted component."):Error("Argument appears to not be a ReactComponent. Keys: "+Object.keys(c));var C=I0(D);if(C===null)return null;if(C.mode&mr){var O=qt(D.type)||"Component";wy[O]||(wy[O]=!0,D.mode&mr?Ve(!1,"%s is deprecated in StrictMode. %s was passed an instance of %s which is inside StrictMode. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://fb.me/react-strict-mode-find-node%s",d,d,O,Cr(C)):Ve(!1,"%s is deprecated in StrictMode. %s was passed an instance of %s which renders StrictMode children. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://fb.me/react-strict-mode-find-node%s",d,d,O,Cr(C)))}return C.stateNode}return Sy(c)}function Y4(c,d,D,C){return H4(c,d,D,C)}function Xg(c,d,D,C){var O=d.current,z=jl();typeof jest<"u"&&(vy(O),zp(O));var G=_o(),ne=jf(z,O,G);Nv.debugTool&&(O.alternate===null?Nv.debugTool.onMountContainer(d):c===null?Nv.debugTool.onUnmountContainer(d):Nv.debugTool.onUpdateContainer(d));var se=V4(D);d.context===null?d.context=se:d.pendingContext=se,Nr==="render"&&Rn!==null&&!Dy&&(Dy=!0,Ve(!1,`Render methods should be a pure function of props and state; triggering nested component updates from render is not allowed. If necessary, trigger nested updates in componentDidUpdate. + +Check the render method of %s.`,qt(Rn.type)||"Unknown"));var Ue=Tu(ne,G);return Ue.payload={element:c},C=C===void 0?null:C,C!==null&&(typeof C!="function"&&Ve(!1,"render(...): Expected the last optional `callback` argument to be a function. Instead received: %s.",C),Ue.callback=C),Va(O,Ue),yl(O,ne),ne}function K4(c){var d=c.current;if(!d.child)return null;switch(d.child.tag){case V:return Lo(d.child.stateNode);default:return d.child.stateNode}}function X4(c){switch(c.tag){case j:var d=c.stateNode;d.hydrate&&Gm(d,d.firstPendingTime);break;case he:Rp(function(){return yl(c,Un)});var D=Ua(jl());Lv(c,D);break}}function Qg(c,d){var D=c.memoizedState;D!==null&&D.dehydrated!==null&&D.retryTime=d.length)return C;var O=d[D],z=Array.isArray(c)?c.slice():f({},c);return z[O]=xy(c[O],d,D+1,C),z},n_=function(c,d,D){return xy(c,d,0,D)};Zg=function(c,d,D,C){for(var O=c.memoizedState;O!==null&&d>0;)O=O.next,d--;if(O!==null){var z=n_(O.memoizedState,D,C);O.memoizedState=z,O.baseState=z,c.memoizedProps=f({},c.memoizedProps),yl(c,Un)}},$g=function(c,d,D){c.pendingProps=n_(c.memoizedProps,d,D),c.alternate&&(c.alternate.pendingProps=c.pendingProps),yl(c,Un)},e_=function(c){yl(c,Un)},t_=function(c){Cy=c}}function $4(c){var d=c.findFiberByHostInstance,D=it.ReactCurrentDispatcher;return Ot(f({},c,{overrideHookState:Zg,overrideProps:$g,setSuspenseHandler:t_,scheduleUpdate:e_,currentDispatcherRef:D,findHostInstanceByFiber:function(C){var O=I0(C);return O===null?null:O.stateNode},findFiberByHostInstance:function(C){return d?d(C):null},findHostInstancesForRefresh:ud,scheduleRefresh:Ol,scheduleRoot:Ts,setRefreshHandler:qa,getCurrentFiber:function(){return Rn}}))}var r_=Object.freeze({createContainer:Y4,updateContainer:Xg,batchedEventUpdates:Qm,batchedUpdates:Xm,unbatchedUpdates:Jm,deferredUpdates:Ym,syncUpdates:pv,discreteUpdates:hv,flushDiscreteUpdates:dv,flushControlled:Zm,flushSync:Rp,flushPassiveEffects:tf,IsThisRendererActing:qf,getPublicRootInstance:K4,attemptSynchronousHydration:X4,attemptUserBlockingHydration:Q4,attemptContinuousHydration:Ty,attemptHydrationAtCurrentPriority:J4,findHostInstance:Sy,findHostInstanceWithWarning:G4,findHostInstanceWithNoPortals:Z4,shouldSuspend:Jg,injectIntoDevTools:$4}),eE=r_.default||r_;Yy.exports=eE;var tE=Yy.exports;return Yy.exports=o,tE})});var YS=nt((DH,mD)=>{"use strict";process.env.NODE_ENV==="production"?mD.exports=HS():mD.exports=GS()});var XS=nt((wH,KS)=>{"use strict";var EP={ALIGN_COUNT:8,ALIGN_AUTO:0,ALIGN_FLEX_START:1,ALIGN_CENTER:2,ALIGN_FLEX_END:3,ALIGN_STRETCH:4,ALIGN_BASELINE:5,ALIGN_SPACE_BETWEEN:6,ALIGN_SPACE_AROUND:7,DIMENSION_COUNT:2,DIMENSION_WIDTH:0,DIMENSION_HEIGHT:1,DIRECTION_COUNT:3,DIRECTION_INHERIT:0,DIRECTION_LTR:1,DIRECTION_RTL:2,DISPLAY_COUNT:2,DISPLAY_FLEX:0,DISPLAY_NONE:1,EDGE_COUNT:9,EDGE_LEFT:0,EDGE_TOP:1,EDGE_RIGHT:2,EDGE_BOTTOM:3,EDGE_START:4,EDGE_END:5,EDGE_HORIZONTAL:6,EDGE_VERTICAL:7,EDGE_ALL:8,EXPERIMENTAL_FEATURE_COUNT:1,EXPERIMENTAL_FEATURE_WEB_FLEX_BASIS:0,FLEX_DIRECTION_COUNT:4,FLEX_DIRECTION_COLUMN:0,FLEX_DIRECTION_COLUMN_REVERSE:1,FLEX_DIRECTION_ROW:2,FLEX_DIRECTION_ROW_REVERSE:3,JUSTIFY_COUNT:6,JUSTIFY_FLEX_START:0,JUSTIFY_CENTER:1,JUSTIFY_FLEX_END:2,JUSTIFY_SPACE_BETWEEN:3,JUSTIFY_SPACE_AROUND:4,JUSTIFY_SPACE_EVENLY:5,LOG_LEVEL_COUNT:6,LOG_LEVEL_ERROR:0,LOG_LEVEL_WARN:1,LOG_LEVEL_INFO:2,LOG_LEVEL_DEBUG:3,LOG_LEVEL_VERBOSE:4,LOG_LEVEL_FATAL:5,MEASURE_MODE_COUNT:3,MEASURE_MODE_UNDEFINED:0,MEASURE_MODE_EXACTLY:1,MEASURE_MODE_AT_MOST:2,NODE_TYPE_COUNT:2,NODE_TYPE_DEFAULT:0,NODE_TYPE_TEXT:1,OVERFLOW_COUNT:3,OVERFLOW_VISIBLE:0,OVERFLOW_HIDDEN:1,OVERFLOW_SCROLL:2,POSITION_TYPE_COUNT:2,POSITION_TYPE_RELATIVE:0,POSITION_TYPE_ABSOLUTE:1,PRINT_OPTIONS_COUNT:3,PRINT_OPTIONS_LAYOUT:1,PRINT_OPTIONS_STYLE:2,PRINT_OPTIONS_CHILDREN:4,UNIT_COUNT:4,UNIT_UNDEFINED:0,UNIT_POINT:1,UNIT_PERCENT:2,UNIT_AUTO:3,WRAP_COUNT:3,WRAP_NO_WRAP:0,WRAP_WRAP:1,WRAP_WRAP_REVERSE:2};KS.exports=EP});var $S=nt((SH,ZS)=>{"use strict";var DP=Object.assign||function(o){for(var l=1;l"}}]),o}(),QS=function(){H_(o,null,[{key:"fromJS",value:function(f){var h=f.width,E=f.height;return new o(h,E)}}]);function o(l,f){gD(this,o),this.width=l,this.height=f}return H_(o,[{key:"fromJS",value:function(f){f(this.width,this.height)}},{key:"toString",value:function(){return""}}]),o}(),JS=function(){function o(l,f){gD(this,o),this.unit=l,this.value=f}return H_(o,[{key:"fromJS",value:function(f){f(this.unit,this.value)}},{key:"toString",value:function(){switch(this.unit){case tc.UNIT_POINT:return String(this.value);case tc.UNIT_PERCENT:return this.value+"%";case tc.UNIT_AUTO:return"auto";default:return this.value+"?"}}},{key:"valueOf",value:function(){return this.value}}]),o}();ZS.exports=function(o,l){function f(N,F,k){var x=N[F];N[F]=function(){for(var j=arguments.length,q=Array(j),V=0;V1?q-1:0),re=1;re1&&arguments[1]!==void 0?arguments[1]:NaN,k=arguments.length>2&&arguments[2]!==void 0?arguments[2]:NaN,x=arguments.length>3&&arguments[3]!==void 0?arguments[3]:tc.DIRECTION_LTR;return N.call(this,F,k,x)}),DP({Config:l.Config,Node:l.Node,Layout:o("Layout",wP),Size:o("Size",QS),Value:o("Value",JS),getInstanceCount:function(){return l.getInstanceCount.apply(l,arguments)}},tc)}});var eT=nt((exports,module)=>{(function(o,l){typeof define=="function"&&define.amd?define([],function(){return l}):typeof module=="object"&&module.exports?module.exports=l:(o.nbind=o.nbind||{}).init=l})(exports,function(Module,cb){typeof Module=="function"&&(cb=Module,Module={}),Module.onRuntimeInitialized=function(o,l){return function(){o&&o.apply(this,arguments);try{Module.ccall("nbind_init")}catch(f){l(f);return}l(null,{bind:Module._nbind_value,reflect:Module.NBind.reflect,queryType:Module.NBind.queryType,toggleLightGC:Module.toggleLightGC,lib:Module})}}(Module.onRuntimeInitialized,cb);var Module;Module||(Module=(typeof Module<"u"?Module:null)||{});var moduleOverrides={};for(var key in Module)Module.hasOwnProperty(key)&&(moduleOverrides[key]=Module[key]);var ENVIRONMENT_IS_WEB=!1,ENVIRONMENT_IS_WORKER=!1,ENVIRONMENT_IS_NODE=!1,ENVIRONMENT_IS_SHELL=!1;if(Module.ENVIRONMENT)if(Module.ENVIRONMENT==="WEB")ENVIRONMENT_IS_WEB=!0;else if(Module.ENVIRONMENT==="WORKER")ENVIRONMENT_IS_WORKER=!0;else if(Module.ENVIRONMENT==="NODE")ENVIRONMENT_IS_NODE=!0;else if(Module.ENVIRONMENT==="SHELL")ENVIRONMENT_IS_SHELL=!0;else throw new Error("The provided Module['ENVIRONMENT'] value is not valid. It must be one of: WEB|WORKER|NODE|SHELL.");else ENVIRONMENT_IS_WEB=typeof window=="object",ENVIRONMENT_IS_WORKER=typeof importScripts=="function",ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof hi=="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER,ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;if(ENVIRONMENT_IS_NODE){Module.print||(Module.print=console.log),Module.printErr||(Module.printErr=console.warn);var nodeFS,nodePath;Module.read=function(l,f){nodeFS||(nodeFS={}("")),nodePath||(nodePath={}("")),l=nodePath.normalize(l);var h=nodeFS.readFileSync(l);return f?h:h.toString()},Module.readBinary=function(l){var f=Module.read(l,!0);return f.buffer||(f=new Uint8Array(f)),assert(f.buffer),f},Module.load=function(l){globalEval(read(l))},Module.thisProgram||(process.argv.length>1?Module.thisProgram=process.argv[1].replace(/\\/g,"/"):Module.thisProgram="unknown-program"),Module.arguments=process.argv.slice(2),typeof module<"u"&&(module.exports=Module),Module.inspect=function(){return"[Emscripten Module object]"}}else if(ENVIRONMENT_IS_SHELL)Module.print||(Module.print=print),typeof printErr<"u"&&(Module.printErr=printErr),typeof read<"u"?Module.read=read:Module.read=function(){throw"no read() available"},Module.readBinary=function(l){if(typeof readbuffer=="function")return new Uint8Array(readbuffer(l));var f=read(l,"binary");return assert(typeof f=="object"),f},typeof scriptArgs<"u"?Module.arguments=scriptArgs:typeof arguments<"u"&&(Module.arguments=arguments),typeof quit=="function"&&(Module.quit=function(o,l){quit(o)});else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(Module.read=function(l){var f=new XMLHttpRequest;return f.open("GET",l,!1),f.send(null),f.responseText},ENVIRONMENT_IS_WORKER&&(Module.readBinary=function(l){var f=new XMLHttpRequest;return f.open("GET",l,!1),f.responseType="arraybuffer",f.send(null),new Uint8Array(f.response)}),Module.readAsync=function(l,f,h){var E=new XMLHttpRequest;E.open("GET",l,!0),E.responseType="arraybuffer",E.onload=function(){E.status==200||E.status==0&&E.response?f(E.response):h()},E.onerror=h,E.send(null)},typeof arguments<"u"&&(Module.arguments=arguments),typeof console<"u")Module.print||(Module.print=function(l){console.log(l)}),Module.printErr||(Module.printErr=function(l){console.warn(l)});else{var TRY_USE_DUMP=!1;Module.print||(Module.print=TRY_USE_DUMP&&typeof dump<"u"?function(o){dump(o)}:function(o){})}ENVIRONMENT_IS_WORKER&&(Module.load=importScripts),typeof Module.setWindowTitle>"u"&&(Module.setWindowTitle=function(o){document.title=o})}else throw"Unknown runtime environment. Where are we?";function globalEval(o){eval.call(null,o)}!Module.load&&Module.read&&(Module.load=function(l){globalEval(Module.read(l))}),Module.print||(Module.print=function(){}),Module.printErr||(Module.printErr=Module.print),Module.arguments||(Module.arguments=[]),Module.thisProgram||(Module.thisProgram="./this.program"),Module.quit||(Module.quit=function(o,l){throw l}),Module.print=Module.print,Module.printErr=Module.printErr,Module.preRun=[],Module.postRun=[];for(var key in moduleOverrides)moduleOverrides.hasOwnProperty(key)&&(Module[key]=moduleOverrides[key]);moduleOverrides=void 0;var Runtime={setTempRet0:function(o){return tempRet0=o,o},getTempRet0:function(){return tempRet0},stackSave:function(){return STACKTOP},stackRestore:function(o){STACKTOP=o},getNativeTypeSize:function(o){switch(o){case"i1":case"i8":return 1;case"i16":return 2;case"i32":return 4;case"i64":return 8;case"float":return 4;case"double":return 8;default:{if(o[o.length-1]==="*")return Runtime.QUANTUM_SIZE;if(o[0]==="i"){var l=parseInt(o.substr(1));return assert(l%8===0),l/8}else return 0}}},getNativeFieldSize:function(o){return Math.max(Runtime.getNativeTypeSize(o),Runtime.QUANTUM_SIZE)},STACK_ALIGN:16,prepVararg:function(o,l){return l==="double"||l==="i64"?o&7&&(assert((o&7)===4),o+=4):assert((o&3)===0),o},getAlignSize:function(o,l,f){return!f&&(o=="i64"||o=="double")?8:o?Math.min(l||(o?Runtime.getNativeFieldSize(o):0),Runtime.QUANTUM_SIZE):Math.min(l,8)},dynCall:function(o,l,f){return f&&f.length?Module["dynCall_"+o].apply(null,[l].concat(f)):Module["dynCall_"+o].call(null,l)},functionPointers:[],addFunction:function(o){for(var l=0;l>2],f=(l+o+15|0)&-16;if(HEAP32[DYNAMICTOP_PTR>>2]=f,f>=TOTAL_MEMORY){var h=enlargeMemory();if(!h)return HEAP32[DYNAMICTOP_PTR>>2]=l,0}return l},alignMemory:function(o,l){var f=o=Math.ceil(o/(l||16))*(l||16);return f},makeBigInt:function(o,l,f){var h=f?+(o>>>0)+ +(l>>>0)*4294967296:+(o>>>0)+ +(l|0)*4294967296;return h},GLOBAL_BASE:8,QUANTUM_SIZE:4,__dummy__:0};Module.Runtime=Runtime;var ABORT=0,EXITSTATUS=0;function assert(o,l){o||abort("Assertion failed: "+l)}function getCFunc(ident){var func=Module["_"+ident];if(!func)try{func=eval("_"+ident)}catch(o){}return assert(func,"Cannot call unknown function "+ident+" (perhaps LLVM optimizations or closure removed it?)"),func}var cwrap,ccall;(function(){var JSfuncs={stackSave:function(){Runtime.stackSave()},stackRestore:function(){Runtime.stackRestore()},arrayToC:function(o){var l=Runtime.stackAlloc(o.length);return writeArrayToMemory(o,l),l},stringToC:function(o){var l=0;if(o!=null&&o!==0){var f=(o.length<<2)+1;l=Runtime.stackAlloc(f),stringToUTF8(o,l,f)}return l}},toC={string:JSfuncs.stringToC,array:JSfuncs.arrayToC};ccall=function(l,f,h,E,t){var N=getCFunc(l),F=[],k=0;if(E)for(var x=0;x>0]=l;break;case"i8":HEAP8[o>>0]=l;break;case"i16":HEAP16[o>>1]=l;break;case"i32":HEAP32[o>>2]=l;break;case"i64":tempI64=[l>>>0,(tempDouble=l,+Math_abs(tempDouble)>=1?tempDouble>0?(Math_min(+Math_floor(tempDouble/4294967296),4294967295)|0)>>>0:~~+Math_ceil((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0)],HEAP32[o>>2]=tempI64[0],HEAP32[o+4>>2]=tempI64[1];break;case"float":HEAPF32[o>>2]=l;break;case"double":HEAPF64[o>>3]=l;break;default:abort("invalid type for setValue: "+f)}}Module.setValue=setValue;function getValue(o,l,f){switch(l=l||"i8",l.charAt(l.length-1)==="*"&&(l="i32"),l){case"i1":return HEAP8[o>>0];case"i8":return HEAP8[o>>0];case"i16":return HEAP16[o>>1];case"i32":return HEAP32[o>>2];case"i64":return HEAP32[o>>2];case"float":return HEAPF32[o>>2];case"double":return HEAPF64[o>>3];default:abort("invalid type for setValue: "+l)}return null}Module.getValue=getValue;var ALLOC_NORMAL=0,ALLOC_STACK=1,ALLOC_STATIC=2,ALLOC_DYNAMIC=3,ALLOC_NONE=4;Module.ALLOC_NORMAL=ALLOC_NORMAL,Module.ALLOC_STACK=ALLOC_STACK,Module.ALLOC_STATIC=ALLOC_STATIC,Module.ALLOC_DYNAMIC=ALLOC_DYNAMIC,Module.ALLOC_NONE=ALLOC_NONE;function allocate(o,l,f,h){var E,t;typeof o=="number"?(E=!0,t=o):(E=!1,t=o.length);var N=typeof l=="string"?l:null,F;if(f==ALLOC_NONE?F=h:F=[typeof _malloc=="function"?_malloc:Runtime.staticAlloc,Runtime.stackAlloc,Runtime.staticAlloc,Runtime.dynamicAlloc][f===void 0?ALLOC_STATIC:f](Math.max(t,N?1:l.length)),E){var h=F,k;for(assert((F&3)==0),k=F+(t&-4);h>2]=0;for(k=F+t;h>0]=0;return F}if(N==="i8")return o.subarray||o.slice?HEAPU8.set(o,F):HEAPU8.set(new Uint8Array(o),F),F;for(var x=0,j,q,V;x>0],f|=h,!(h==0&&!l||(E++,l&&E==l)););l||(l=E);var t="";if(f<128){for(var N=1024,F;l>0;)F=String.fromCharCode.apply(String,HEAPU8.subarray(o,o+Math.min(l,N))),t=t?t+F:F,o+=N,l-=N;return t}return Module.UTF8ToString(o)}Module.Pointer_stringify=Pointer_stringify;function AsciiToString(o){for(var l="";;){var f=HEAP8[o++>>0];if(!f)return l;l+=String.fromCharCode(f)}}Module.AsciiToString=AsciiToString;function stringToAscii(o,l){return writeAsciiToMemory(o,l,!1)}Module.stringToAscii=stringToAscii;var UTF8Decoder=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0;function UTF8ArrayToString(o,l){for(var f=l;o[f];)++f;if(f-l>16&&o.subarray&&UTF8Decoder)return UTF8Decoder.decode(o.subarray(l,f));for(var h,E,t,N,F,k,x="";;){if(h=o[l++],!h)return x;if(!(h&128)){x+=String.fromCharCode(h);continue}if(E=o[l++]&63,(h&224)==192){x+=String.fromCharCode((h&31)<<6|E);continue}if(t=o[l++]&63,(h&240)==224?h=(h&15)<<12|E<<6|t:(N=o[l++]&63,(h&248)==240?h=(h&7)<<18|E<<12|t<<6|N:(F=o[l++]&63,(h&252)==248?h=(h&3)<<24|E<<18|t<<12|N<<6|F:(k=o[l++]&63,h=(h&1)<<30|E<<24|t<<18|N<<12|F<<6|k))),h<65536)x+=String.fromCharCode(h);else{var j=h-65536;x+=String.fromCharCode(55296|j>>10,56320|j&1023)}}}Module.UTF8ArrayToString=UTF8ArrayToString;function UTF8ToString(o){return UTF8ArrayToString(HEAPU8,o)}Module.UTF8ToString=UTF8ToString;function stringToUTF8Array(o,l,f,h){if(!(h>0))return 0;for(var E=f,t=f+h-1,N=0;N=55296&&F<=57343&&(F=65536+((F&1023)<<10)|o.charCodeAt(++N)&1023),F<=127){if(f>=t)break;l[f++]=F}else if(F<=2047){if(f+1>=t)break;l[f++]=192|F>>6,l[f++]=128|F&63}else if(F<=65535){if(f+2>=t)break;l[f++]=224|F>>12,l[f++]=128|F>>6&63,l[f++]=128|F&63}else if(F<=2097151){if(f+3>=t)break;l[f++]=240|F>>18,l[f++]=128|F>>12&63,l[f++]=128|F>>6&63,l[f++]=128|F&63}else if(F<=67108863){if(f+4>=t)break;l[f++]=248|F>>24,l[f++]=128|F>>18&63,l[f++]=128|F>>12&63,l[f++]=128|F>>6&63,l[f++]=128|F&63}else{if(f+5>=t)break;l[f++]=252|F>>30,l[f++]=128|F>>24&63,l[f++]=128|F>>18&63,l[f++]=128|F>>12&63,l[f++]=128|F>>6&63,l[f++]=128|F&63}}return l[f]=0,f-E}Module.stringToUTF8Array=stringToUTF8Array;function stringToUTF8(o,l,f){return stringToUTF8Array(o,HEAPU8,l,f)}Module.stringToUTF8=stringToUTF8;function lengthBytesUTF8(o){for(var l=0,f=0;f=55296&&h<=57343&&(h=65536+((h&1023)<<10)|o.charCodeAt(++f)&1023),h<=127?++l:h<=2047?l+=2:h<=65535?l+=3:h<=2097151?l+=4:h<=67108863?l+=5:l+=6}return l}Module.lengthBytesUTF8=lengthBytesUTF8;var UTF16Decoder=typeof TextDecoder<"u"?new TextDecoder("utf-16le"):void 0;function demangle(o){var l=Module.___cxa_demangle||Module.__cxa_demangle;if(l){try{var f=o.substr(1),h=lengthBytesUTF8(f)+1,E=_malloc(h);stringToUTF8(f,E,h);var t=_malloc(4),N=l(E,0,0,t);if(getValue(t,"i32")===0&&N)return Pointer_stringify(N)}catch{}finally{E&&_free(E),t&&_free(t),N&&_free(N)}return o}return Runtime.warnOnce("warning: build with -s DEMANGLE_SUPPORT=1 to link in libcxxabi demangling"),o}function demangleAll(o){var l=/__Z[\w\d_]+/g;return o.replace(l,function(f){var h=demangle(f);return f===h?f:f+" ["+h+"]"})}function jsStackTrace(){var o=new Error;if(!o.stack){try{throw new Error(0)}catch(l){o=l}if(!o.stack)return"(no stack trace available)"}return o.stack.toString()}function stackTrace(){var o=jsStackTrace();return Module.extraStackTrace&&(o+=` +`+Module.extraStackTrace()),demangleAll(o)}Module.stackTrace=stackTrace;var HEAP,buffer,HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateGlobalBufferViews(){Module.HEAP8=HEAP8=new Int8Array(buffer),Module.HEAP16=HEAP16=new Int16Array(buffer),Module.HEAP32=HEAP32=new Int32Array(buffer),Module.HEAPU8=HEAPU8=new Uint8Array(buffer),Module.HEAPU16=HEAPU16=new Uint16Array(buffer),Module.HEAPU32=HEAPU32=new Uint32Array(buffer),Module.HEAPF32=HEAPF32=new Float32Array(buffer),Module.HEAPF64=HEAPF64=new Float64Array(buffer)}var STATIC_BASE,STATICTOP,staticSealed,STACK_BASE,STACKTOP,STACK_MAX,DYNAMIC_BASE,DYNAMICTOP_PTR;STATIC_BASE=STATICTOP=STACK_BASE=STACKTOP=STACK_MAX=DYNAMIC_BASE=DYNAMICTOP_PTR=0,staticSealed=!1;function abortOnCannotGrowMemory(){abort("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value "+TOTAL_MEMORY+", (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime but prevents some optimizations, (3) set Module.TOTAL_MEMORY to a higher value before the program runs, or (4) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ")}function enlargeMemory(){abortOnCannotGrowMemory()}var TOTAL_STACK=Module.TOTAL_STACK||5242880,TOTAL_MEMORY=Module.TOTAL_MEMORY||134217728;TOTAL_MEMORY0;){var l=o.shift();if(typeof l=="function"){l();continue}var f=l.func;typeof f=="number"?l.arg===void 0?Module.dynCall_v(f):Module.dynCall_vi(f,l.arg):f(l.arg===void 0?null:l.arg)}}var __ATPRERUN__=[],__ATINIT__=[],__ATMAIN__=[],__ATEXIT__=[],__ATPOSTRUN__=[],runtimeInitialized=!1,runtimeExited=!1;function preRun(){if(Module.preRun)for(typeof Module.preRun=="function"&&(Module.preRun=[Module.preRun]);Module.preRun.length;)addOnPreRun(Module.preRun.shift());callRuntimeCallbacks(__ATPRERUN__)}function ensureInitRuntime(){runtimeInitialized||(runtimeInitialized=!0,callRuntimeCallbacks(__ATINIT__))}function preMain(){callRuntimeCallbacks(__ATMAIN__)}function exitRuntime(){callRuntimeCallbacks(__ATEXIT__),runtimeExited=!0}function postRun(){if(Module.postRun)for(typeof Module.postRun=="function"&&(Module.postRun=[Module.postRun]);Module.postRun.length;)addOnPostRun(Module.postRun.shift());callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(o){__ATPRERUN__.unshift(o)}Module.addOnPreRun=addOnPreRun;function addOnInit(o){__ATINIT__.unshift(o)}Module.addOnInit=addOnInit;function addOnPreMain(o){__ATMAIN__.unshift(o)}Module.addOnPreMain=addOnPreMain;function addOnExit(o){__ATEXIT__.unshift(o)}Module.addOnExit=addOnExit;function addOnPostRun(o){__ATPOSTRUN__.unshift(o)}Module.addOnPostRun=addOnPostRun;function intArrayFromString(o,l,f){var h=f>0?f:lengthBytesUTF8(o)+1,E=new Array(h),t=stringToUTF8Array(o,E,0,E.length);return l&&(E.length=t),E}Module.intArrayFromString=intArrayFromString;function intArrayToString(o){for(var l=[],f=0;f255&&(h&=255),l.push(String.fromCharCode(h))}return l.join("")}Module.intArrayToString=intArrayToString;function writeStringToMemory(o,l,f){Runtime.warnOnce("writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!");var h,E;f&&(E=l+lengthBytesUTF8(o),h=HEAP8[E]),stringToUTF8(o,l,1/0),f&&(HEAP8[E]=h)}Module.writeStringToMemory=writeStringToMemory;function writeArrayToMemory(o,l){HEAP8.set(o,l)}Module.writeArrayToMemory=writeArrayToMemory;function writeAsciiToMemory(o,l,f){for(var h=0;h>0]=o.charCodeAt(h);f||(HEAP8[l>>0]=0)}if(Module.writeAsciiToMemory=writeAsciiToMemory,(!Math.imul||Math.imul(4294967295,5)!==-5)&&(Math.imul=function o(l,f){var h=l>>>16,E=l&65535,t=f>>>16,N=f&65535;return E*N+(h*N+E*t<<16)|0}),Math.imul=Math.imul,!Math.fround){var froundBuffer=new Float32Array(1);Math.fround=function(o){return froundBuffer[0]=o,froundBuffer[0]}}Math.fround=Math.fround,Math.clz32||(Math.clz32=function(o){o=o>>>0;for(var l=0;l<32;l++)if(o&1<<31-l)return l;return 32}),Math.clz32=Math.clz32,Math.trunc||(Math.trunc=function(o){return o<0?Math.ceil(o):Math.floor(o)}),Math.trunc=Math.trunc;var Math_abs=Math.abs,Math_cos=Math.cos,Math_sin=Math.sin,Math_tan=Math.tan,Math_acos=Math.acos,Math_asin=Math.asin,Math_atan=Math.atan,Math_atan2=Math.atan2,Math_exp=Math.exp,Math_log=Math.log,Math_sqrt=Math.sqrt,Math_ceil=Math.ceil,Math_floor=Math.floor,Math_pow=Math.pow,Math_imul=Math.imul,Math_fround=Math.fround,Math_round=Math.round,Math_min=Math.min,Math_clz32=Math.clz32,Math_trunc=Math.trunc,runDependencies=0,runDependencyWatcher=null,dependenciesFulfilled=null;function getUniqueRunDependency(o){return o}function addRunDependency(o){runDependencies++,Module.monitorRunDependencies&&Module.monitorRunDependencies(runDependencies)}Module.addRunDependency=addRunDependency;function removeRunDependency(o){if(runDependencies--,Module.monitorRunDependencies&&Module.monitorRunDependencies(runDependencies),runDependencies==0&&(runDependencyWatcher!==null&&(clearInterval(runDependencyWatcher),runDependencyWatcher=null),dependenciesFulfilled)){var l=dependenciesFulfilled;dependenciesFulfilled=null,l()}}Module.removeRunDependency=removeRunDependency,Module.preloadedImages={},Module.preloadedAudios={};var ASM_CONSTS=[function(o,l,f,h,E,t,N,F){return _nbind.callbackSignatureList[o].apply(this,arguments)}];function _emscripten_asm_const_iiiiiiii(o,l,f,h,E,t,N,F){return ASM_CONSTS[o](l,f,h,E,t,N,F)}function _emscripten_asm_const_iiiii(o,l,f,h,E){return ASM_CONSTS[o](l,f,h,E)}function _emscripten_asm_const_iiidddddd(o,l,f,h,E,t,N,F,k){return ASM_CONSTS[o](l,f,h,E,t,N,F,k)}function _emscripten_asm_const_iiididi(o,l,f,h,E,t,N){return ASM_CONSTS[o](l,f,h,E,t,N)}function _emscripten_asm_const_iiii(o,l,f,h){return ASM_CONSTS[o](l,f,h)}function _emscripten_asm_const_iiiid(o,l,f,h,E){return ASM_CONSTS[o](l,f,h,E)}function _emscripten_asm_const_iiiiii(o,l,f,h,E,t){return ASM_CONSTS[o](l,f,h,E,t)}STATIC_BASE=Runtime.GLOBAL_BASE,STATICTOP=STATIC_BASE+12800,__ATINIT__.push({func:function(){__GLOBAL__sub_I_Yoga_cpp()}},{func:function(){__GLOBAL__sub_I_nbind_cc()}},{func:function(){__GLOBAL__sub_I_common_cc()}},{func:function(){__GLOBAL__sub_I_Binding_cc()}}),allocate([0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,127,0,0,192,127,0,0,192,127,0,0,192,127,3,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,3,0,0,0,0,0,192,127,3,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,192,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,127,0,0,192,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,127,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,127,0,0,192,127,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,128,191,0,0,128,191,0,0,192,127,0,0,0,0,0,0,0,0,0,0,128,63,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0,1,0,0,0,2,0,0,0,0,0,0,0,190,12,0,0,200,12,0,0,208,12,0,0,216,12,0,0,230,12,0,0,242,12,0,0,1,0,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0,0,192,127,3,0,0,0,180,45,0,0,181,45,0,0,182,45,0,0,181,45,0,0,182,45,0,0,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,1,0,0,0,4,0,0,0,183,45,0,0,181,45,0,0,181,45,0,0,181,45,0,0,181,45,0,0,181,45,0,0,181,45,0,0,184,45,0,0,185,45,0,0,181,45,0,0,181,45,0,0,182,45,0,0,186,45,0,0,185,45,0,0,148,4,0,0,3,0,0,0,187,45,0,0,164,4,0,0,188,45,0,0,2,0,0,0,189,45,0,0,164,4,0,0,188,45,0,0,185,45,0,0,164,4,0,0,185,45,0,0,164,4,0,0,188,45,0,0,181,45,0,0,182,45,0,0,181,45,0,0,0,0,0,0,0,0,0,0,1,0,0,0,5,0,0,0,6,0,0,0,1,0,0,0,7,0,0,0,183,45,0,0,182,45,0,0,181,45,0,0,190,45,0,0,190,45,0,0,182,45,0,0,182,45,0,0,185,45,0,0,181,45,0,0,185,45,0,0,182,45,0,0,181,45,0,0,185,45,0,0,182,45,0,0,185,45,0,0,48,5,0,0,3,0,0,0,56,5,0,0,1,0,0,0,189,45,0,0,185,45,0,0,164,4,0,0,76,5,0,0,2,0,0,0,191,45,0,0,186,45,0,0,182,45,0,0,185,45,0,0,192,45,0,0,185,45,0,0,182,45,0,0,186,45,0,0,185,45,0,0,76,5,0,0,76,5,0,0,136,5,0,0,182,45,0,0,181,45,0,0,2,0,0,0,190,45,0,0,136,5,0,0,56,19,0,0,156,5,0,0,2,0,0,0,184,45,0,0,0,0,0,0,0,0,0,0,1,0,0,0,8,0,0,0,9,0,0,0,1,0,0,0,10,0,0,0,204,5,0,0,181,45,0,0,181,45,0,0,2,0,0,0,180,45,0,0,204,5,0,0,2,0,0,0,195,45,0,0,236,5,0,0,97,19,0,0,198,45,0,0,211,45,0,0,212,45,0,0,213,45,0,0,214,45,0,0,215,45,0,0,188,45,0,0,182,45,0,0,216,45,0,0,217,45,0,0,218,45,0,0,219,45,0,0,192,45,0,0,181,45,0,0,0,0,0,0,185,45,0,0,110,19,0,0,186,45,0,0,115,19,0,0,221,45,0,0,120,19,0,0,148,4,0,0,132,19,0,0,96,6,0,0,145,19,0,0,222,45,0,0,164,19,0,0,223,45,0,0,173,19,0,0,0,0,0,0,3,0,0,0,104,6,0,0,1,0,0,0,187,45,0,0,0,0,0,0,0,0,0,0,1,0,0,0,11,0,0,0,12,0,0,0,1,0,0,0,13,0,0,0,185,45,0,0,224,45,0,0,164,6,0,0,188,45,0,0,172,6,0,0,180,6,0,0,2,0,0,0,188,6,0,0,7,0,0,0,224,45,0,0,7,0,0,0,164,6,0,0,1,0,0,0,213,45,0,0,185,45,0,0,224,45,0,0,172,6,0,0,185,45,0,0,224,45,0,0,164,6,0,0,185,45,0,0,224,45,0,0,211,45,0,0,211,45,0,0,222,45,0,0,211,45,0,0,224,45,0,0,222,45,0,0,211,45,0,0,224,45,0,0,172,6,0,0,222,45,0,0,211,45,0,0,224,45,0,0,188,45,0,0,222,45,0,0,211,45,0,0,40,7,0,0,188,45,0,0,2,0,0,0,224,45,0,0,185,45,0,0,188,45,0,0,188,45,0,0,188,45,0,0,188,45,0,0,222,45,0,0,224,45,0,0,148,4,0,0,185,45,0,0,148,4,0,0,148,4,0,0,148,4,0,0,148,4,0,0,148,4,0,0,185,45,0,0,164,6,0,0,148,4,0,0,0,0,0,0,0,0,0,0,1,0,0,0,14,0,0,0,15,0,0,0,1,0,0,0,16,0,0,0,148,7,0,0,2,0,0,0,225,45,0,0,183,45,0,0,188,45,0,0,168,7,0,0,5,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,234,45,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,148,45,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,9,0,0,5,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,2,0,0,0,242,45,0,0,0,4,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,67,111,117,108,100,32,110,111,116,32,97,108,108,111,99,97,116,101,32,109,101,109,111,114,121,32,102,111,114,32,110,111,100,101,0,67,97,110,110,111,116,32,114,101,115,101,116,32,97,32,110,111,100,101,32,119,104,105,99,104,32,115,116,105,108,108,32,104,97,115,32,99,104,105,108,100,114,101,110,32,97,116,116,97,99,104,101,100,0,67,97,110,110,111,116,32,114,101,115,101,116,32,97,32,110,111,100,101,32,115,116,105,108,108,32,97,116,116,97,99,104,101,100,32,116,111,32,97,32,112,97,114,101,110,116,0,67,111,117,108,100,32,110,111,116,32,97,108,108,111,99,97,116,101,32,109,101,109,111,114,121,32,102,111,114,32,99,111,110,102,105,103,0,67,97,110,110,111,116,32,115,101,116,32,109,101,97,115,117,114,101,32,102,117,110,99,116,105,111,110,58,32,78,111,100,101,115,32,119,105,116,104,32,109,101,97,115,117,114,101,32,102,117,110,99,116,105,111,110,115,32,99,97,110,110,111,116,32,104,97,118,101,32,99,104,105,108,100,114,101,110,46,0,67,104,105,108,100,32,97,108,114,101,97,100,121,32,104,97,115,32,97,32,112,97,114,101,110,116,44,32,105,116,32,109,117,115,116,32,98,101,32,114,101,109,111,118,101,100,32,102,105,114,115,116,46,0,67,97,110,110,111,116,32,97,100,100,32,99,104,105,108,100,58,32,78,111,100,101,115,32,119,105,116,104,32,109,101,97,115,117,114,101,32,102,117,110,99,116,105,111,110,115,32,99,97,110,110,111,116,32,104,97,118,101,32,99,104,105,108,100,114,101,110,46,0,79,110,108,121,32,108,101,97,102,32,110,111,100,101,115,32,119,105,116,104,32,99,117,115,116,111,109,32,109,101,97,115,117,114,101,32,102,117,110,99,116,105,111,110,115,115,104,111,117,108,100,32,109,97,110,117,97,108,108,121,32,109,97,114,107,32,116,104,101,109,115,101,108,118,101,115,32,97,115,32,100,105,114,116,121,0,67,97,110,110,111,116,32,103,101,116,32,108,97,121,111,117,116,32,112,114,111,112,101,114,116,105,101,115,32,111,102,32,109,117,108,116,105,45,101,100,103,101,32,115,104,111,114,116,104,97,110,100,115,0,37,115,37,100,46,123,91,115,107,105,112,112,101,100,93,32,0,119,109,58,32,37,115,44,32,104,109,58,32,37,115,44,32,97,119,58,32,37,102,32,97,104,58,32,37,102,32,61,62,32,100,58,32,40,37,102,44,32,37,102,41,32,37,115,10,0,37,115,37,100,46,123,37,115,0,42,0,119,109,58,32,37,115,44,32,104,109,58,32,37,115,44,32,97,119,58,32,37,102,32,97,104,58,32,37,102,32,37,115,10,0,37,115,37,100,46,125,37,115,0,119,109,58,32,37,115,44,32,104,109,58,32,37,115,44,32,100,58,32,40,37,102,44,32,37,102,41,32,37,115,10,0,79,117,116,32,111,102,32,99,97,99,104,101,32,101,110,116,114,105,101,115,33,10,0,83,99,97,108,101,32,102,97,99,116,111,114,32,115,104,111,117,108,100,32,110,111,116,32,98,101,32,108,101,115,115,32,116,104,97,110,32,122,101,114,111,0,105,110,105,116,105,97,108,0,37,115,10,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,0,85,78,68,69,70,73,78,69,68,0,69,88,65,67,84,76,89,0,65,84,95,77,79,83,84,0,76,65,89,95,85,78,68,69,70,73,78,69,68,0,76,65,89,95,69,88,65,67,84,76,89,0,76,65,89,95,65,84,95,77,79,83,84,0,97,118,97,105,108,97,98,108,101,87,105,100,116,104,32,105,115,32,105,110,100,101,102,105,110,105,116,101,32,115,111,32,119,105,100,116,104,77,101,97,115,117,114,101,77,111,100,101,32,109,117,115,116,32,98,101,32,89,71,77,101,97,115,117,114,101,77,111,100,101,85,110,100,101,102,105,110,101,100,0,97,118,97,105,108,97,98,108,101,72,101,105,103,104,116,32,105,115,32,105,110,100,101,102,105,110,105,116,101,32,115,111,32,104,101,105,103,104,116,77,101,97,115,117,114,101,77,111,100,101,32,109,117,115,116,32,98,101,32,89,71,77,101,97,115,117,114,101,77,111,100,101,85,110,100,101,102,105,110,101,100,0,102,108,101,120,0,115,116,114,101,116,99,104,0,109,117,108,116,105,108,105,110,101,45,115,116,114,101,116,99,104,0,69,120,112,101,99,116,101,100,32,110,111,100,101,32,116,111,32,104,97,118,101,32,99,117,115,116,111,109,32,109,101,97,115,117,114,101,32,102,117,110,99,116,105,111,110,0,109,101,97,115,117,114,101,0,69,120,112,101,99,116,32,99,117,115,116,111,109,32,98,97,115,101,108,105,110,101,32,102,117,110,99,116,105,111,110,32,116,111,32,110,111,116,32,114,101,116,117,114,110,32,78,97,78,0,97,98,115,45,109,101,97,115,117,114,101,0,97,98,115,45,108,97,121,111,117,116,0,78,111,100,101,0,99,114,101,97,116,101,68,101,102,97,117,108,116,0,99,114,101,97,116,101,87,105,116,104,67,111,110,102,105,103,0,100,101,115,116,114,111,121,0,114,101,115,101,116,0,99,111,112,121,83,116,121,108,101,0,115,101,116,80,111,115,105,116,105,111,110,84,121,112,101,0,115,101,116,80,111,115,105,116,105,111,110,0,115,101,116,80,111,115,105,116,105,111,110,80,101,114,99,101,110,116,0,115,101,116,65,108,105,103,110,67,111,110,116,101,110,116,0,115,101,116,65,108,105,103,110,73,116,101,109,115,0,115,101,116,65,108,105,103,110,83,101,108,102,0,115,101,116,70,108,101,120,68,105,114,101,99,116,105,111,110,0,115,101,116,70,108,101,120,87,114,97,112,0,115,101,116,74,117,115,116,105,102,121,67,111,110,116,101,110,116,0,115,101,116,77,97,114,103,105,110,0,115,101,116,77,97,114,103,105,110,80,101,114,99,101,110,116,0,115,101,116,77,97,114,103,105,110,65,117,116,111,0,115,101,116,79,118,101,114,102,108,111,119,0,115,101,116,68,105,115,112,108,97,121,0,115,101,116,70,108,101,120,0,115,101,116,70,108,101,120,66,97,115,105,115,0,115,101,116,70,108,101,120,66,97,115,105,115,80,101,114,99,101,110,116,0,115,101,116,70,108,101,120,71,114,111,119,0,115,101,116,70,108,101,120,83,104,114,105,110,107,0,115,101,116,87,105,100,116,104,0,115,101,116,87,105,100,116,104,80,101,114,99,101,110,116,0,115,101,116,87,105,100,116,104,65,117,116,111,0,115,101,116,72,101,105,103,104,116,0,115,101,116,72,101,105,103,104,116,80,101,114,99,101,110,116,0,115,101,116,72,101,105,103,104,116,65,117,116,111,0,115,101,116,77,105,110,87,105,100,116,104,0,115,101,116,77,105,110,87,105,100,116,104,80,101,114,99,101,110,116,0,115,101,116,77,105,110,72,101,105,103,104,116,0,115,101,116,77,105,110,72,101,105,103,104,116,80,101,114,99,101,110,116,0,115,101,116,77,97,120,87,105,100,116,104,0,115,101,116,77,97,120,87,105,100,116,104,80,101,114,99,101,110,116,0,115,101,116,77,97,120,72,101,105,103,104,116,0,115,101,116,77,97,120,72,101,105,103,104,116,80,101,114,99,101,110,116,0,115,101,116,65,115,112,101,99,116,82,97,116,105,111,0,115,101,116,66,111,114,100,101,114,0,115,101,116,80,97,100,100,105,110,103,0,115,101,116,80,97,100,100,105,110,103,80,101,114,99,101,110,116,0,103,101,116,80,111,115,105,116,105,111,110,84,121,112,101,0,103,101,116,80,111,115,105,116,105,111,110,0,103,101,116,65,108,105,103,110,67,111,110,116,101,110,116,0,103,101,116,65,108,105,103,110,73,116,101,109,115,0,103,101,116,65,108,105,103,110,83,101,108,102,0,103,101,116,70,108,101,120,68,105,114,101,99,116,105,111,110,0,103,101,116,70,108,101,120,87,114,97,112,0,103,101,116,74,117,115,116,105,102,121,67,111,110,116,101,110,116,0,103,101,116,77,97,114,103,105,110,0,103,101,116,70,108,101,120,66,97,115,105,115,0,103,101,116,70,108,101,120,71,114,111,119,0,103,101,116,70,108,101,120,83,104,114,105,110,107,0,103,101,116,87,105,100,116,104,0,103,101,116,72,101,105,103,104,116,0,103,101,116,77,105,110,87,105,100,116,104,0,103,101,116,77,105,110,72,101,105,103,104,116,0,103,101,116,77,97,120,87,105,100,116,104,0,103,101,116,77,97,120,72,101,105,103,104,116,0,103,101,116,65,115,112,101,99,116,82,97,116,105,111,0,103,101,116,66,111,114,100,101,114,0,103,101,116,79,118,101,114,102,108,111,119,0,103,101,116,68,105,115,112,108,97,121,0,103,101,116,80,97,100,100,105,110,103,0,105,110,115,101,114,116,67,104,105,108,100,0,114,101,109,111,118,101,67,104,105,108,100,0,103,101,116,67,104,105,108,100,67,111,117,110,116,0,103,101,116,80,97,114,101,110,116,0,103,101,116,67,104,105,108,100,0,115,101,116,77,101,97,115,117,114,101,70,117,110,99,0,117,110,115,101,116,77,101,97,115,117,114,101,70,117,110,99,0,109,97,114,107,68,105,114,116,121,0,105,115,68,105,114,116,121,0,99,97,108,99,117,108,97,116,101,76,97,121,111,117,116,0,103,101,116,67,111,109,112,117,116,101,100,76,101,102,116,0,103,101,116,67,111,109,112,117,116,101,100,82,105,103,104,116,0,103,101,116,67,111,109,112,117,116,101,100,84,111,112,0,103,101,116,67,111,109,112,117,116,101,100,66,111,116,116,111,109,0,103,101,116,67,111,109,112,117,116,101,100,87,105,100,116,104,0,103,101,116,67,111,109,112,117,116,101,100,72,101,105,103,104,116,0,103,101,116,67,111,109,112,117,116,101,100,76,97,121,111,117,116,0,103,101,116,67,111,109,112,117,116,101,100,77,97,114,103,105,110,0,103,101,116,67,111,109,112,117,116,101,100,66,111,114,100,101,114,0,103,101,116,67,111,109,112,117,116,101,100,80,97,100,100,105,110,103,0,67,111,110,102,105,103,0,99,114,101,97,116,101,0,115,101,116,69,120,112,101,114,105,109,101,110,116,97,108,70,101,97,116,117,114,101,69,110,97,98,108,101,100,0,115,101,116,80,111,105,110,116,83,99,97,108,101,70,97,99,116,111,114,0,105,115,69,120,112,101,114,105,109,101,110,116,97,108,70,101,97,116,117,114,101,69,110,97,98,108,101,100,0,86,97,108,117,101,0,76,97,121,111,117,116,0,83,105,122,101,0,103,101,116,73,110,115,116,97,110,99,101,67,111,117,110,116,0,73,110,116,54,52,0,1,1,1,2,2,4,4,4,4,8,8,4,8,118,111,105,100,0,98,111,111,108,0,115,116,100,58,58,115,116,114,105,110,103,0,99,98,70,117,110,99,116,105,111,110,32,38,0,99,111,110,115,116,32,99,98,70,117,110,99,116,105,111,110,32,38,0,69,120,116,101,114,110,97,108,0,66,117,102,102,101,114,0,78,66,105,110,100,73,68,0,78,66,105,110,100,0,98,105,110,100,95,118,97,108,117,101,0,114,101,102,108,101,99,116,0,113,117,101,114,121,84,121,112,101,0,108,97,108,108,111,99,0,108,114,101,115,101,116,0,123,114,101,116,117,114,110,40,95,110,98,105,110,100,46,99,97,108,108,98,97,99,107,83,105,103,110,97,116,117,114,101,76,105,115,116,91,36,48,93,46,97,112,112,108,121,40,116,104,105,115,44,97,114,103,117,109,101,110,116,115,41,41,59,125,0,95,110,98,105,110,100,95,110,101,119,0,17,0,10,0,17,17,17,0,0,0,0,5,0,0,0,0,0,0,9,0,0,0,0,11,0,0,0,0,0,0,0,0,17,0,15,10,17,17,17,3,10,7,0,1,19,9,11,11,0,0,9,6,11,0,0,11,0,6,17,0,0,0,17,17,17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,17,0,10,10,17,17,17,0,10,0,0,2,0,9,11,0,0,0,9,0,11,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,12,0,0,0,0,9,12,0,0,0,0,0,12,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,13,0,0,0,4,13,0,0,0,0,9,14,0,0,0,0,0,14,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,0,15,0,0,0,0,9,16,0,0,0,0,0,16,0,0,16,0,0,18,0,0,0,18,18,18,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,0,0,0,18,18,18,0,0,0,0,0,0,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,10,0,0,0,0,9,11,0,0,0,0,0,11,0,0,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,12,0,0,0,0,9,12,0,0,0,0,0,12,0,0,12,0,0,45,43,32,32,32,48,88,48,120,0,40,110,117,108,108,41,0,45,48,88,43,48,88,32,48,88,45,48,120,43,48,120,32,48,120,0,105,110,102,0,73,78,70,0,110,97,110,0,78,65,78,0,48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70,46,0,84,33,34,25,13,1,2,3,17,75,28,12,16,4,11,29,18,30,39,104,110,111,112,113,98,32,5,6,15,19,20,21,26,8,22,7,40,36,23,24,9,10,14,27,31,37,35,131,130,125,38,42,43,60,61,62,63,67,71,74,77,88,89,90,91,92,93,94,95,96,97,99,100,101,102,103,105,106,107,108,114,115,116,121,122,123,124,0,73,108,108,101,103,97,108,32,98,121,116,101,32,115,101,113,117,101,110,99,101,0,68,111,109,97,105,110,32,101,114,114,111,114,0,82,101,115,117,108,116,32,110,111,116,32,114,101,112,114,101,115,101,110,116,97,98,108,101,0,78,111,116,32,97,32,116,116,121,0,80,101,114,109,105,115,115,105,111,110,32,100,101,110,105,101,100,0,79,112,101,114,97,116,105,111,110,32,110,111,116,32,112,101,114,109,105,116,116,101,100,0,78,111,32,115,117,99,104,32,102,105,108,101,32,111,114,32,100,105,114,101,99,116,111,114,121,0,78,111,32,115,117,99,104,32,112,114,111,99,101,115,115,0,70,105,108,101,32,101,120,105,115,116,115,0,86,97,108,117,101,32,116,111,111,32,108,97,114,103,101,32,102,111,114,32,100,97,116,97,32,116,121,112,101,0,78,111,32,115,112,97,99,101,32,108,101,102,116,32,111,110,32,100,101,118,105,99,101,0,79,117,116,32,111,102,32,109,101,109,111,114,121,0,82,101,115,111,117,114,99,101,32,98,117,115,121,0,73,110,116,101,114,114,117,112,116,101,100,32,115,121,115,116,101,109,32,99,97,108,108,0,82,101,115,111,117,114,99,101,32,116,101,109,112,111,114,97,114,105,108,121,32,117,110,97,118,97,105,108,97,98,108,101,0,73,110,118,97,108,105,100,32,115,101,101,107,0,67,114,111,115,115,45,100,101,118,105,99,101,32,108,105,110,107,0,82,101,97,100,45,111,110,108,121,32,102,105,108,101,32,115,121,115,116,101,109,0,68,105,114,101,99,116,111,114,121,32,110,111,116,32,101,109,112,116,121,0,67,111,110,110,101,99,116,105,111,110,32,114,101,115,101,116,32,98,121,32,112,101,101,114,0,79,112,101,114,97,116,105,111,110,32,116,105,109,101,100,32,111,117,116,0,67,111,110,110,101,99,116,105,111,110,32,114,101,102,117,115,101,100,0,72,111,115,116,32,105,115,32,100,111,119,110,0,72,111,115,116,32,105,115,32,117,110,114,101,97,99,104,97,98,108,101,0,65,100,100,114,101,115,115,32,105,110,32,117,115,101,0,66,114,111,107,101,110,32,112,105,112,101,0,73,47,79,32,101,114,114,111,114,0,78,111,32,115,117,99,104,32,100,101,118,105,99,101,32,111,114,32,97,100,100,114,101,115,115,0,66,108,111,99,107,32,100,101,118,105,99,101,32,114,101,113,117,105,114,101,100,0,78,111,32,115,117,99,104,32,100,101,118,105,99,101,0,78,111,116,32,97,32,100,105,114,101,99,116,111,114,121,0,73,115,32,97,32,100,105,114,101,99,116,111,114,121,0,84,101,120,116,32,102,105,108,101,32,98,117,115,121,0,69,120,101,99,32,102,111,114,109,97,116,32,101,114,114,111,114,0,73,110,118,97,108,105,100,32,97,114,103,117,109,101,110,116,0,65,114,103,117,109,101,110,116,32,108,105,115,116,32,116,111,111,32,108,111,110,103,0,83,121,109,98,111,108,105,99,32,108,105,110,107,32,108,111,111,112,0,70,105,108,101,110,97,109,101,32,116,111,111,32,108,111,110,103,0,84,111,111,32,109,97,110,121,32,111,112,101,110,32,102,105,108,101,115,32,105,110,32,115,121,115,116,101,109,0,78,111,32,102,105,108,101,32,100,101,115,99,114,105,112,116,111,114,115,32,97,118,97,105,108,97,98,108,101,0,66,97,100,32,102,105,108,101,32,100,101,115,99,114,105,112,116,111,114,0,78,111,32,99,104,105,108,100,32,112,114,111,99,101,115,115,0,66,97,100,32,97,100,100,114,101,115,115,0,70,105,108,101,32,116,111,111,32,108,97,114,103,101,0,84,111,111,32,109,97,110,121,32,108,105,110,107,115,0,78,111,32,108,111,99,107,115,32,97,118,97,105,108,97,98,108,101,0,82,101,115,111,117,114,99,101,32,100,101,97,100,108,111,99,107,32,119,111,117,108,100,32,111,99,99,117,114,0,83,116,97,116,101,32,110,111,116,32,114,101,99,111,118,101,114,97,98,108,101,0,80,114,101,118,105,111,117,115,32,111,119,110,101,114,32,100,105,101,100,0,79,112,101,114,97,116,105,111,110,32,99,97,110,99,101,108,101,100,0,70,117,110,99,116,105,111,110,32,110,111,116,32,105,109,112,108,101,109,101,110,116,101,100,0,78,111,32,109,101,115,115,97,103,101,32,111,102,32,100,101,115,105,114,101,100,32,116,121,112,101,0,73,100,101,110,116,105,102,105,101,114,32,114,101,109,111,118,101,100,0,68,101,118,105,99,101,32,110,111,116,32,97,32,115,116,114,101,97,109,0,78,111,32,100,97,116,97,32,97,118,97,105,108,97,98,108,101,0,68,101,118,105,99,101,32,116,105,109,101,111,117,116,0,79,117,116,32,111,102,32,115,116,114,101,97,109,115,32,114,101,115,111,117,114,99,101,115,0,76,105,110,107,32,104,97,115,32,98,101,101,110,32,115,101,118,101,114,101,100,0,80,114,111,116,111,99,111,108,32,101,114,114,111,114,0,66,97,100,32,109,101,115,115,97,103,101,0,70,105,108,101,32,100,101,115,99,114,105,112,116,111,114,32,105,110,32,98,97,100,32,115,116,97,116,101,0,78,111,116,32,97,32,115,111,99,107,101,116,0,68,101,115,116,105,110,97,116,105,111,110,32,97,100,100,114,101,115,115,32,114,101,113,117,105,114,101,100,0,77,101,115,115,97,103,101,32,116,111,111,32,108,97,114,103,101,0,80,114,111,116,111,99,111,108,32,119,114,111,110,103,32,116,121,112,101,32,102,111,114,32,115,111,99,107,101,116,0,80,114,111,116,111,99,111,108,32,110,111,116,32,97,118,97,105,108,97,98,108,101,0,80,114,111,116,111,99,111,108,32,110,111,116,32,115,117,112,112,111,114,116,101,100,0,83,111,99,107,101,116,32,116,121,112,101,32,110,111,116,32,115,117,112,112,111,114,116,101,100,0,78,111,116,32,115,117,112,112,111,114,116,101,100,0,80,114,111,116,111,99,111,108,32,102,97,109,105,108,121,32,110,111,116,32,115,117,112,112,111,114,116,101,100,0,65,100,100,114,101,115,115,32,102,97,109,105,108,121,32,110,111,116,32,115,117,112,112,111,114,116,101,100,32,98,121,32,112,114,111,116,111,99,111,108,0,65,100,100,114,101,115,115,32,110,111,116,32,97,118,97,105,108,97,98,108,101,0,78,101,116,119,111,114,107,32,105,115,32,100,111,119,110,0,78,101,116,119,111,114,107,32,117,110,114,101,97,99,104,97,98,108,101,0,67,111,110,110,101,99,116,105,111,110,32,114,101,115,101,116,32,98,121,32,110,101,116,119,111,114,107,0,67,111,110,110,101,99,116,105,111,110,32,97,98,111,114,116,101,100,0,78,111,32,98,117,102,102,101,114,32,115,112,97,99,101,32,97,118,97,105,108,97,98,108,101,0,83,111,99,107,101,116,32,105,115,32,99,111,110,110,101,99,116,101,100,0,83,111,99,107,101,116,32,110,111,116,32,99,111,110,110,101,99,116,101,100,0,67,97,110,110,111,116,32,115,101,110,100,32,97,102,116,101,114,32,115,111,99,107,101,116,32,115,104,117,116,100,111,119,110,0,79,112,101,114,97,116,105,111,110,32,97,108,114,101,97,100,121,32,105,110,32,112,114,111,103,114,101,115,115,0,79,112,101,114,97,116,105,111,110,32,105,110,32,112,114,111,103,114,101,115,115,0,83,116,97,108,101,32,102,105,108,101,32,104,97,110,100,108,101,0,82,101,109,111,116,101,32,73,47,79,32,101,114,114,111,114,0,81,117,111,116,97,32,101,120,99,101,101,100,101,100,0,78,111,32,109,101,100,105,117,109,32,102,111,117,110,100,0,87,114,111,110,103,32,109,101,100,105,117,109,32,116,121,112,101,0,78,111,32,101,114,114,111,114,32,105,110,102,111,114,109,97,116,105,111,110,0,0],"i8",ALLOC_NONE,Runtime.GLOBAL_BASE);var tempDoublePtr=STATICTOP;STATICTOP+=16;function _atexit(o,l){__ATEXIT__.unshift({func:o,arg:l})}function ___cxa_atexit(){return _atexit.apply(null,arguments)}function _abort(){Module.abort()}function __ZN8facebook4yoga14YGNodeToStringEPNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEP6YGNode14YGPrintOptionsj(){Module.printErr("missing function: _ZN8facebook4yoga14YGNodeToStringEPNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEP6YGNode14YGPrintOptionsj"),abort(-1)}function __decorate(o,l,f,h){var E=arguments.length,t=E<3?l:h===null?h=Object.getOwnPropertyDescriptor(l,f):h,N;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")t=Reflect.decorate(o,l,f,h);else for(var F=o.length-1;F>=0;F--)(N=o[F])&&(t=(E<3?N(t):E>3?N(l,f,t):N(l,f))||t);return E>3&&t&&Object.defineProperty(l,f,t),t}function _defineHidden(o){return function(l,f){Object.defineProperty(l,f,{configurable:!1,enumerable:!1,value:o,writable:!0})}}var _nbind={};function __nbind_free_external(o){_nbind.externalList[o].dereference(o)}function __nbind_reference_external(o){_nbind.externalList[o].reference()}function _llvm_stackrestore(o){var l=_llvm_stacksave,f=l.LLVM_SAVEDSTACKS[o];l.LLVM_SAVEDSTACKS.splice(o,1),Runtime.stackRestore(f)}function __nbind_register_pool(o,l,f,h){_nbind.Pool.pageSize=o,_nbind.Pool.usedPtr=l/4,_nbind.Pool.rootPtr=f,_nbind.Pool.pagePtr=h/4,HEAP32[l/4]=16909060,HEAP8[l]==1&&(_nbind.bigEndian=!0),HEAP32[l/4]=0,_nbind.makeTypeKindTbl=(t={},t[1024]=_nbind.PrimitiveType,t[64]=_nbind.Int64Type,t[2048]=_nbind.BindClass,t[3072]=_nbind.BindClassPtr,t[4096]=_nbind.SharedClassPtr,t[5120]=_nbind.ArrayType,t[6144]=_nbind.ArrayType,t[7168]=_nbind.CStringType,t[9216]=_nbind.CallbackType,t[10240]=_nbind.BindType,t),_nbind.makeTypeNameTbl={Buffer:_nbind.BufferType,External:_nbind.ExternalType,Int64:_nbind.Int64Type,_nbind_new:_nbind.CreateValueType,bool:_nbind.BooleanType,"cbFunction &":_nbind.CallbackType,"const cbFunction &":_nbind.CallbackType,"const std::string &":_nbind.StringType,"std::string":_nbind.StringType},Module.toggleLightGC=_nbind.toggleLightGC,_nbind.callUpcast=Module.dynCall_ii;var E=_nbind.makeType(_nbind.constructType,{flags:2048,id:0,name:""});E.proto=Module,_nbind.BindClass.list.push(E);var t}function _emscripten_set_main_loop_timing(o,l){if(Browser.mainLoop.timingMode=o,Browser.mainLoop.timingValue=l,!Browser.mainLoop.func)return 1;if(o==0)Browser.mainLoop.scheduler=function(){var N=Math.max(0,Browser.mainLoop.tickStartTime+l-_emscripten_get_now())|0;setTimeout(Browser.mainLoop.runner,N)},Browser.mainLoop.method="timeout";else if(o==1)Browser.mainLoop.scheduler=function(){Browser.requestAnimationFrame(Browser.mainLoop.runner)},Browser.mainLoop.method="rAF";else if(o==2){if(!window.setImmediate){let t=function(N){N.source===window&&N.data===h&&(N.stopPropagation(),f.shift()())};var E=t,f=[],h="setimmediate";window.addEventListener("message",t,!0),window.setImmediate=function(F){f.push(F),ENVIRONMENT_IS_WORKER?(Module.setImmediates===void 0&&(Module.setImmediates=[]),Module.setImmediates.push(F),window.postMessage({target:h})):window.postMessage(h,"*")}}Browser.mainLoop.scheduler=function(){window.setImmediate(Browser.mainLoop.runner)},Browser.mainLoop.method="immediate"}return 0}function _emscripten_get_now(){abort()}function _emscripten_set_main_loop(o,l,f,h,E){Module.noExitRuntime=!0,assert(!Browser.mainLoop.func,"emscripten_set_main_loop: there can only be one main loop function at once: call emscripten_cancel_main_loop to cancel the previous one before setting a new one with different parameters."),Browser.mainLoop.func=o,Browser.mainLoop.arg=h;var t;typeof h<"u"?t=function(){Module.dynCall_vi(o,h)}:t=function(){Module.dynCall_v(o)};var N=Browser.mainLoop.currentlyRunningMainloop;if(Browser.mainLoop.runner=function(){if(!ABORT){if(Browser.mainLoop.queue.length>0){var k=Date.now(),x=Browser.mainLoop.queue.shift();if(x.func(x.arg),Browser.mainLoop.remainingBlockers){var j=Browser.mainLoop.remainingBlockers,q=j%1==0?j-1:Math.floor(j);x.counted?Browser.mainLoop.remainingBlockers=q:(q=q+.5,Browser.mainLoop.remainingBlockers=(8*j+q)/9)}if(console.log('main loop blocker "'+x.name+'" took '+(Date.now()-k)+" ms"),Browser.mainLoop.updateStatus(),N1&&Browser.mainLoop.currentFrameNumber%Browser.mainLoop.timingValue!=0){Browser.mainLoop.scheduler();return}else Browser.mainLoop.timingMode==0&&(Browser.mainLoop.tickStartTime=_emscripten_get_now());Browser.mainLoop.method==="timeout"&&Module.ctx&&(Module.printErr("Looks like you are rendering without using requestAnimationFrame for the main loop. You should use 0 for the frame rate in emscripten_set_main_loop in order to use requestAnimationFrame, as that can greatly improve your frame rates!"),Browser.mainLoop.method=""),Browser.mainLoop.runIter(t),!(N0?_emscripten_set_main_loop_timing(0,1e3/l):_emscripten_set_main_loop_timing(1,1),Browser.mainLoop.scheduler()),f)throw"SimulateInfiniteLoop"}var Browser={mainLoop:{scheduler:null,method:"",currentlyRunningMainloop:0,func:null,arg:0,timingMode:0,timingValue:0,currentFrameNumber:0,queue:[],pause:function(){Browser.mainLoop.scheduler=null,Browser.mainLoop.currentlyRunningMainloop++},resume:function(){Browser.mainLoop.currentlyRunningMainloop++;var o=Browser.mainLoop.timingMode,l=Browser.mainLoop.timingValue,f=Browser.mainLoop.func;Browser.mainLoop.func=null,_emscripten_set_main_loop(f,0,!1,Browser.mainLoop.arg,!0),_emscripten_set_main_loop_timing(o,l),Browser.mainLoop.scheduler()},updateStatus:function(){if(Module.setStatus){var o=Module.statusMessage||"Please wait...",l=Browser.mainLoop.remainingBlockers,f=Browser.mainLoop.expectedBlockers;l?l"u"&&(console.log("warning: Browser does not support creating object URLs. Built-in browser image decoding will not be available."),Module.noImageDecoding=!0);var o={};o.canHandle=function(t){return!Module.noImageDecoding&&/\.(jpg|jpeg|png|bmp)$/i.test(t)},o.handle=function(t,N,F,k){var x=null;if(Browser.hasBlobConstructor)try{x=new Blob([t],{type:Browser.getMimetype(N)}),x.size!==t.length&&(x=new Blob([new Uint8Array(t).buffer],{type:Browser.getMimetype(N)}))}catch(re){Runtime.warnOnce("Blob constructor present but fails: "+re+"; falling back to blob builder")}if(!x){var j=new Browser.BlobBuilder;j.append(new Uint8Array(t).buffer),x=j.getBlob()}var q=Browser.URLObject.createObjectURL(x),V=new Image;V.onload=function(){assert(V.complete,"Image "+N+" could not be decoded");var y=document.createElement("canvas");y.width=V.width,y.height=V.height;var me=y.getContext("2d");me.drawImage(V,0,0),Module.preloadedImages[N]=y,Browser.URLObject.revokeObjectURL(q),F&&F(t)},V.onerror=function(y){console.log("Image "+q+" could not be decoded"),k&&k()},V.src=q},Module.preloadPlugins.push(o);var l={};l.canHandle=function(t){return!Module.noAudioDecoding&&t.substr(-4)in{".ogg":1,".wav":1,".mp3":1}},l.handle=function(t,N,F,k){var x=!1;function j(me){x||(x=!0,Module.preloadedAudios[N]=me,F&&F(t))}function q(){x||(x=!0,Module.preloadedAudios[N]=new Audio,k&&k())}if(Browser.hasBlobConstructor){try{var V=new Blob([t],{type:Browser.getMimetype(N)})}catch{return q()}var re=Browser.URLObject.createObjectURL(V),y=new Audio;y.addEventListener("canplaythrough",function(){j(y)},!1),y.onerror=function(De){if(x)return;console.log("warning: browser could not fully decode audio "+N+", trying slower base64 approach");function ge(ae){for(var we="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",he="=",ve="",ue=0,Ae=0,ze=0;ze=6;){var We=ue>>Ae-6&63;Ae-=6,ve+=we[We]}return Ae==2?(ve+=we[(ue&3)<<4],ve+=he+he):Ae==4&&(ve+=we[(ue&15)<<2],ve+=he),ve}y.src="data:audio/x-"+N.substr(-3)+";base64,"+ge(t),j(y)},y.src=re,Browser.safeSetTimeout(function(){j(y)},1e4)}else return q()},Module.preloadPlugins.push(l);function f(){Browser.pointerLock=document.pointerLockElement===Module.canvas||document.mozPointerLockElement===Module.canvas||document.webkitPointerLockElement===Module.canvas||document.msPointerLockElement===Module.canvas}var h=Module.canvas;h&&(h.requestPointerLock=h.requestPointerLock||h.mozRequestPointerLock||h.webkitRequestPointerLock||h.msRequestPointerLock||function(){},h.exitPointerLock=document.exitPointerLock||document.mozExitPointerLock||document.webkitExitPointerLock||document.msExitPointerLock||function(){},h.exitPointerLock=h.exitPointerLock.bind(document),document.addEventListener("pointerlockchange",f,!1),document.addEventListener("mozpointerlockchange",f,!1),document.addEventListener("webkitpointerlockchange",f,!1),document.addEventListener("mspointerlockchange",f,!1),Module.elementPointerLock&&h.addEventListener("click",function(E){!Browser.pointerLock&&Module.canvas.requestPointerLock&&(Module.canvas.requestPointerLock(),E.preventDefault())},!1))},createContext:function(o,l,f,h){if(l&&Module.ctx&&o==Module.canvas)return Module.ctx;var E,t;if(l){var N={antialias:!1,alpha:!1};if(h)for(var F in h)N[F]=h[F];t=GL.createContext(o,N),t&&(E=GL.getContext(t).GLctx)}else E=o.getContext("2d");return E?(f&&(l||assert(typeof GLctx>"u","cannot set in module if GLctx is used, but we are a non-GL context that would replace it"),Module.ctx=E,l&&GL.makeContextCurrent(t),Module.useWebGL=l,Browser.moduleContextCreatedCallbacks.forEach(function(k){k()}),Browser.init()),E):null},destroyContext:function(o,l,f){},fullscreenHandlersInstalled:!1,lockPointer:void 0,resizeCanvas:void 0,requestFullscreen:function(o,l,f){Browser.lockPointer=o,Browser.resizeCanvas=l,Browser.vrDevice=f,typeof Browser.lockPointer>"u"&&(Browser.lockPointer=!0),typeof Browser.resizeCanvas>"u"&&(Browser.resizeCanvas=!1),typeof Browser.vrDevice>"u"&&(Browser.vrDevice=null);var h=Module.canvas;function E(){Browser.isFullscreen=!1;var N=h.parentNode;(document.fullscreenElement||document.mozFullScreenElement||document.msFullscreenElement||document.webkitFullscreenElement||document.webkitCurrentFullScreenElement)===N?(h.exitFullscreen=document.exitFullscreen||document.cancelFullScreen||document.mozCancelFullScreen||document.msExitFullscreen||document.webkitCancelFullScreen||function(){},h.exitFullscreen=h.exitFullscreen.bind(document),Browser.lockPointer&&h.requestPointerLock(),Browser.isFullscreen=!0,Browser.resizeCanvas&&Browser.setFullscreenCanvasSize()):(N.parentNode.insertBefore(h,N),N.parentNode.removeChild(N),Browser.resizeCanvas&&Browser.setWindowedCanvasSize()),Module.onFullScreen&&Module.onFullScreen(Browser.isFullscreen),Module.onFullscreen&&Module.onFullscreen(Browser.isFullscreen),Browser.updateCanvasDimensions(h)}Browser.fullscreenHandlersInstalled||(Browser.fullscreenHandlersInstalled=!0,document.addEventListener("fullscreenchange",E,!1),document.addEventListener("mozfullscreenchange",E,!1),document.addEventListener("webkitfullscreenchange",E,!1),document.addEventListener("MSFullscreenChange",E,!1));var t=document.createElement("div");h.parentNode.insertBefore(t,h),t.appendChild(h),t.requestFullscreen=t.requestFullscreen||t.mozRequestFullScreen||t.msRequestFullscreen||(t.webkitRequestFullscreen?function(){t.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT)}:null)||(t.webkitRequestFullScreen?function(){t.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT)}:null),f?t.requestFullscreen({vrDisplay:f}):t.requestFullscreen()},requestFullScreen:function(o,l,f){return Module.printErr("Browser.requestFullScreen() is deprecated. Please call Browser.requestFullscreen instead."),Browser.requestFullScreen=function(h,E,t){return Browser.requestFullscreen(h,E,t)},Browser.requestFullscreen(o,l,f)},nextRAF:0,fakeRequestAnimationFrame:function(o){var l=Date.now();if(Browser.nextRAF===0)Browser.nextRAF=l+1e3/60;else for(;l+2>=Browser.nextRAF;)Browser.nextRAF+=1e3/60;var f=Math.max(Browser.nextRAF-l,0);setTimeout(o,f)},requestAnimationFrame:function o(l){typeof window>"u"?Browser.fakeRequestAnimationFrame(l):(window.requestAnimationFrame||(window.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||window.oRequestAnimationFrame||Browser.fakeRequestAnimationFrame),window.requestAnimationFrame(l))},safeCallback:function(o){return function(){if(!ABORT)return o.apply(null,arguments)}},allowAsyncCallbacks:!0,queuedAsyncCallbacks:[],pauseAsyncCallbacks:function(){Browser.allowAsyncCallbacks=!1},resumeAsyncCallbacks:function(){if(Browser.allowAsyncCallbacks=!0,Browser.queuedAsyncCallbacks.length>0){var o=Browser.queuedAsyncCallbacks;Browser.queuedAsyncCallbacks=[],o.forEach(function(l){l()})}},safeRequestAnimationFrame:function(o){return Browser.requestAnimationFrame(function(){ABORT||(Browser.allowAsyncCallbacks?o():Browser.queuedAsyncCallbacks.push(o))})},safeSetTimeout:function(o,l){return Module.noExitRuntime=!0,setTimeout(function(){ABORT||(Browser.allowAsyncCallbacks?o():Browser.queuedAsyncCallbacks.push(o))},l)},safeSetInterval:function(o,l){return Module.noExitRuntime=!0,setInterval(function(){ABORT||Browser.allowAsyncCallbacks&&o()},l)},getMimetype:function(o){return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",bmp:"image/bmp",ogg:"audio/ogg",wav:"audio/wav",mp3:"audio/mpeg"}[o.substr(o.lastIndexOf(".")+1)]},getUserMedia:function(o){window.getUserMedia||(window.getUserMedia=navigator.getUserMedia||navigator.mozGetUserMedia),window.getUserMedia(o)},getMovementX:function(o){return o.movementX||o.mozMovementX||o.webkitMovementX||0},getMovementY:function(o){return o.movementY||o.mozMovementY||o.webkitMovementY||0},getMouseWheelDelta:function(o){var l=0;switch(o.type){case"DOMMouseScroll":l=o.detail;break;case"mousewheel":l=o.wheelDelta;break;case"wheel":l=o.deltaY;break;default:throw"unrecognized mouse wheel event: "+o.type}return l},mouseX:0,mouseY:0,mouseMovementX:0,mouseMovementY:0,touches:{},lastTouches:{},calculateMouseEvent:function(o){if(Browser.pointerLock)o.type!="mousemove"&&"mozMovementX"in o?Browser.mouseMovementX=Browser.mouseMovementY=0:(Browser.mouseMovementX=Browser.getMovementX(o),Browser.mouseMovementY=Browser.getMovementY(o)),typeof SDL<"u"?(Browser.mouseX=SDL.mouseX+Browser.mouseMovementX,Browser.mouseY=SDL.mouseY+Browser.mouseMovementY):(Browser.mouseX+=Browser.mouseMovementX,Browser.mouseY+=Browser.mouseMovementY);else{var l=Module.canvas.getBoundingClientRect(),f=Module.canvas.width,h=Module.canvas.height,E=typeof window.scrollX<"u"?window.scrollX:window.pageXOffset,t=typeof window.scrollY<"u"?window.scrollY:window.pageYOffset;if(o.type==="touchstart"||o.type==="touchend"||o.type==="touchmove"){var N=o.touch;if(N===void 0)return;var F=N.pageX-(E+l.left),k=N.pageY-(t+l.top);F=F*(f/l.width),k=k*(h/l.height);var x={x:F,y:k};if(o.type==="touchstart")Browser.lastTouches[N.identifier]=x,Browser.touches[N.identifier]=x;else if(o.type==="touchend"||o.type==="touchmove"){var j=Browser.touches[N.identifier];j||(j=x),Browser.lastTouches[N.identifier]=j,Browser.touches[N.identifier]=x}return}var q=o.pageX-(E+l.left),V=o.pageY-(t+l.top);q=q*(f/l.width),V=V*(h/l.height),Browser.mouseMovementX=q-Browser.mouseX,Browser.mouseMovementY=V-Browser.mouseY,Browser.mouseX=q,Browser.mouseY=V}},asyncLoad:function(o,l,f,h){var E=h?"":"al "+o;Module.readAsync(o,function(t){assert(t,'Loading data file "'+o+'" failed (no arrayBuffer).'),l(new Uint8Array(t)),E&&removeRunDependency(E)},function(t){if(f)f();else throw'Loading data file "'+o+'" failed.'}),E&&addRunDependency(E)},resizeListeners:[],updateResizeListeners:function(){var o=Module.canvas;Browser.resizeListeners.forEach(function(l){l(o.width,o.height)})},setCanvasSize:function(o,l,f){var h=Module.canvas;Browser.updateCanvasDimensions(h,o,l),f||Browser.updateResizeListeners()},windowedWidth:0,windowedHeight:0,setFullscreenCanvasSize:function(){if(typeof SDL<"u"){var o=HEAPU32[SDL.screen+Runtime.QUANTUM_SIZE*0>>2];o=o|8388608,HEAP32[SDL.screen+Runtime.QUANTUM_SIZE*0>>2]=o}Browser.updateResizeListeners()},setWindowedCanvasSize:function(){if(typeof SDL<"u"){var o=HEAPU32[SDL.screen+Runtime.QUANTUM_SIZE*0>>2];o=o&-8388609,HEAP32[SDL.screen+Runtime.QUANTUM_SIZE*0>>2]=o}Browser.updateResizeListeners()},updateCanvasDimensions:function(o,l,f){l&&f?(o.widthNative=l,o.heightNative=f):(l=o.widthNative,f=o.heightNative);var h=l,E=f;if(Module.forcedAspectRatio&&Module.forcedAspectRatio>0&&(h/E>2];return l},getStr:function(){var o=Pointer_stringify(SYSCALLS.get());return o},get64:function(){var o=SYSCALLS.get(),l=SYSCALLS.get();return o>=0?assert(l===0):assert(l===-1),o},getZero:function(){assert(SYSCALLS.get()===0)}};function ___syscall6(o,l){SYSCALLS.varargs=l;try{var f=SYSCALLS.getStreamFromFD();return FS.close(f),0}catch(h){return(typeof FS>"u"||!(h instanceof FS.ErrnoError))&&abort(h),-h.errno}}function ___syscall54(o,l){SYSCALLS.varargs=l;try{return 0}catch(f){return(typeof FS>"u"||!(f instanceof FS.ErrnoError))&&abort(f),-f.errno}}function _typeModule(o){var l=[[0,1,"X"],[1,1,"const X"],[128,1,"X *"],[256,1,"X &"],[384,1,"X &&"],[512,1,"std::shared_ptr"],[640,1,"std::unique_ptr"],[5120,1,"std::vector"],[6144,2,"std::array"],[9216,-1,"std::function"]];function f(k,x,j,q,V,re){if(x==1){var y=q&896;(y==128||y==256||y==384)&&(k="X const")}var me;return re?me=j.replace("X",k).replace("Y",V):me=k.replace("X",j).replace("Y",V),me.replace(/([*&]) (?=[*&])/g,"$1")}function h(k,x,j,q,V){throw new Error(k+" type "+j.replace("X",x+"?")+(q?" with flag "+q:"")+" in "+V)}function E(k,x,j,q,V,re,y,me){re===void 0&&(re="X"),me===void 0&&(me=1);var De=j(k);if(De)return De;var ge=q(k),ae=ge.placeholderFlag,we=l[ae];y&&we&&(re=f(y[2],y[0],re,we[0],"?",!0));var he;ae==0&&(he="Unbound"),ae>=10&&(he="Corrupt"),me>20&&(he="Deeply nested"),he&&h(he,k,re,ae,V||"?");var ve=ge.paramList[0],ue=E(ve,x,j,q,V,re,we,me+1),Ae,ze={flags:we[0],id:k,name:"",paramList:[ue]},We=[],gt="?";switch(ge.placeholderFlag){case 1:Ae=ue.spec;break;case 2:if((ue.flags&15360)==1024&&ue.spec.ptrSize==1){ze.flags=7168;break}case 3:case 6:case 5:Ae=ue.spec,ue.flags&15360;break;case 8:gt=""+ge.paramList[1],ze.paramList.push(ge.paramList[1]);break;case 9:for(var _t=0,Qe=ge.paramList[1];_t>2]=o),o}function _llvm_stacksave(){var o=_llvm_stacksave;return o.LLVM_SAVEDSTACKS||(o.LLVM_SAVEDSTACKS=[]),o.LLVM_SAVEDSTACKS.push(Runtime.stackSave()),o.LLVM_SAVEDSTACKS.length-1}function ___syscall140(o,l){SYSCALLS.varargs=l;try{var f=SYSCALLS.getStreamFromFD(),h=SYSCALLS.get(),E=SYSCALLS.get(),t=SYSCALLS.get(),N=SYSCALLS.get(),F=E;return FS.llseek(f,F,N),HEAP32[t>>2]=f.position,f.getdents&&F===0&&N===0&&(f.getdents=null),0}catch(k){return(typeof FS>"u"||!(k instanceof FS.ErrnoError))&&abort(k),-k.errno}}function ___syscall146(o,l){SYSCALLS.varargs=l;try{var f=SYSCALLS.get(),h=SYSCALLS.get(),E=SYSCALLS.get(),t=0;___syscall146.buffer||(___syscall146.buffers=[null,[],[]],___syscall146.printChar=function(j,q){var V=___syscall146.buffers[j];assert(V),q===0||q===10?((j===1?Module.print:Module.printErr)(UTF8ArrayToString(V,0)),V.length=0):V.push(q)});for(var N=0;N>2],k=HEAP32[h+(N*8+4)>>2],x=0;x"u"||!(j instanceof FS.ErrnoError))&&abort(j),-j.errno}}function __nbind_finish(){for(var o=0,l=_nbind.BindClass.list;oo.pageSize/2||l>o.pageSize-f){var h=_nbind.typeNameTbl.NBind.proto;return h.lalloc(l)}else return HEAPU32[o.usedPtr]=f+l,o.rootPtr+f},o.lreset=function(l,f){var h=HEAPU32[o.pagePtr];if(h){var E=_nbind.typeNameTbl.NBind.proto;E.lreset(l,f)}else HEAPU32[o.usedPtr]=l},o}();_nbind.Pool=Pool;function constructType(o,l){var f=o==10240?_nbind.makeTypeNameTbl[l.name]||_nbind.BindType:_nbind.makeTypeKindTbl[o],h=new f(l);return typeIdTbl[l.id]=h,_nbind.typeNameTbl[l.name]=h,h}_nbind.constructType=constructType;function getType(o){return typeIdTbl[o]}_nbind.getType=getType;function queryType(o){var l=HEAPU8[o],f=_nbind.structureList[l][1];o/=4,f<0&&(++o,f=HEAPU32[o]+1);var h=Array.prototype.slice.call(HEAPU32.subarray(o+1,o+1+f));return l==9&&(h=[h[0],h.slice(1)]),{paramList:h,placeholderFlag:l}}_nbind.queryType=queryType;function getTypes(o,l){return o.map(function(f){return typeof f=="number"?_nbind.getComplexType(f,constructType,getType,queryType,l):_nbind.typeNameTbl[f]})}_nbind.getTypes=getTypes;function readTypeIdList(o,l){return Array.prototype.slice.call(HEAPU32,o/4,o/4+l)}_nbind.readTypeIdList=readTypeIdList;function readAsciiString(o){for(var l=o;HEAPU8[l++];);return String.fromCharCode.apply("",HEAPU8.subarray(o,l-1))}_nbind.readAsciiString=readAsciiString;function readPolicyList(o){var l={};if(o)for(;;){var f=HEAPU32[o/4];if(!f)break;l[readAsciiString(f)]=!0,o+=4}return l}_nbind.readPolicyList=readPolicyList;function getDynCall(o,l){var f={float32_t:"d",float64_t:"d",int64_t:"d",uint64_t:"d",void:"v"},h=o.map(function(t){return f[t.name]||"i"}).join(""),E=Module["dynCall_"+h];if(!E)throw new Error("dynCall_"+h+" not found for "+l+"("+o.map(function(t){return t.name}).join(", ")+")");return E}_nbind.getDynCall=getDynCall;function addMethod(o,l,f,h){var E=o[l];o.hasOwnProperty(l)&&E?((E.arity||E.arity===0)&&(E=_nbind.makeOverloader(E,E.arity),o[l]=E),E.addMethod(f,h)):(f.arity=h,o[l]=f)}_nbind.addMethod=addMethod;function throwError(o){throw new Error(o)}_nbind.throwError=throwError,_nbind.bigEndian=!1,_a=_typeModule(_typeModule),_nbind.Type=_a.Type,_nbind.makeType=_a.makeType,_nbind.getComplexType=_a.getComplexType,_nbind.structureList=_a.structureList;var BindType=function(o){__extends(l,o);function l(){var f=o!==null&&o.apply(this,arguments)||this;return f.heap=HEAPU32,f.ptrSize=4,f}return l.prototype.needsWireRead=function(f){return!!this.wireRead||!!this.makeWireRead},l.prototype.needsWireWrite=function(f){return!!this.wireWrite||!!this.makeWireWrite},l}(_nbind.Type);_nbind.BindType=BindType;var PrimitiveType=function(o){__extends(l,o);function l(f){var h=o.call(this,f)||this,E=f.flags&32?{32:HEAPF32,64:HEAPF64}:f.flags&8?{8:HEAPU8,16:HEAPU16,32:HEAPU32}:{8:HEAP8,16:HEAP16,32:HEAP32};return h.heap=E[f.ptrSize*8],h.ptrSize=f.ptrSize,h}return l.prototype.needsWireWrite=function(f){return!!f&&!!f.Strict},l.prototype.makeWireWrite=function(f,h){return h&&h.Strict&&function(E){if(typeof E=="number")return E;throw new Error("Type mismatch")}},l}(BindType);_nbind.PrimitiveType=PrimitiveType;function pushCString(o,l){if(o==null){if(l&&l.Nullable)return 0;throw new Error("Type mismatch")}if(l&&l.Strict){if(typeof o!="string")throw new Error("Type mismatch")}else o=o.toString();var f=Module.lengthBytesUTF8(o)+1,h=_nbind.Pool.lalloc(f);return Module.stringToUTF8Array(o,HEAPU8,h,f),h}_nbind.pushCString=pushCString;function popCString(o){return o===0?null:Module.Pointer_stringify(o)}_nbind.popCString=popCString;var CStringType=function(o){__extends(l,o);function l(){var f=o!==null&&o.apply(this,arguments)||this;return f.wireRead=popCString,f.wireWrite=pushCString,f.readResources=[_nbind.resources.pool],f.writeResources=[_nbind.resources.pool],f}return l.prototype.makeWireWrite=function(f,h){return function(E){return pushCString(E,h)}},l}(BindType);_nbind.CStringType=CStringType;var BooleanType=function(o){__extends(l,o);function l(){var f=o!==null&&o.apply(this,arguments)||this;return f.wireRead=function(h){return!!h},f}return l.prototype.needsWireWrite=function(f){return!!f&&!!f.Strict},l.prototype.makeWireRead=function(f){return"!!("+f+")"},l.prototype.makeWireWrite=function(f,h){return h&&h.Strict&&function(E){if(typeof E=="boolean")return E;throw new Error("Type mismatch")}||f},l}(BindType);_nbind.BooleanType=BooleanType;var Wrapper=function(){function o(){}return o.prototype.persist=function(){this.__nbindState|=1},o}();_nbind.Wrapper=Wrapper;function makeBound(o,l){var f=function(h){__extends(E,h);function E(t,N,F,k){var x=h.call(this)||this;if(!(x instanceof E))return new(Function.prototype.bind.apply(E,Array.prototype.concat.apply([null],arguments)));var j=N,q=F,V=k;if(t!==_nbind.ptrMarker){var re=x.__nbindConstructor.apply(x,arguments);j=4608,V=HEAPU32[re/4],q=HEAPU32[re/4+1]}var y={configurable:!0,enumerable:!1,value:null,writable:!1},me={__nbindFlags:j,__nbindPtr:q};V&&(me.__nbindShared=V,_nbind.mark(x));for(var De=0,ge=Object.keys(me);De>=1;var f=_nbind.valueList[o];return _nbind.valueList[o]=firstFreeValue,firstFreeValue=o,f}else{if(l)return _nbind.popShared(o,l);throw new Error("Invalid value slot "+o)}}_nbind.popValue=popValue;var valueBase=18446744073709552e3;function push64(o){return typeof o=="number"?o:pushValue(o)*4096+valueBase}function pop64(o){return o=3?N=Buffer.from(t):N=new Buffer(t),N.copy(h)}else getBuffer(h).set(t)}}_nbind.commitBuffer=commitBuffer;var dirtyList=[],gcTimer=0;function sweep(){for(var o=0,l=dirtyList;o>2]=DYNAMIC_BASE,staticSealed=!0;function invoke_viiiii(o,l,f,h,E,t){try{Module.dynCall_viiiii(o,l,f,h,E,t)}catch(N){if(typeof N!="number"&&N!=="longjmp")throw N;Module.setThrew(1,0)}}function invoke_vif(o,l,f){try{Module.dynCall_vif(o,l,f)}catch(h){if(typeof h!="number"&&h!=="longjmp")throw h;Module.setThrew(1,0)}}function invoke_vid(o,l,f){try{Module.dynCall_vid(o,l,f)}catch(h){if(typeof h!="number"&&h!=="longjmp")throw h;Module.setThrew(1,0)}}function invoke_fiff(o,l,f,h){try{return Module.dynCall_fiff(o,l,f,h)}catch(E){if(typeof E!="number"&&E!=="longjmp")throw E;Module.setThrew(1,0)}}function invoke_vi(o,l){try{Module.dynCall_vi(o,l)}catch(f){if(typeof f!="number"&&f!=="longjmp")throw f;Module.setThrew(1,0)}}function invoke_vii(o,l,f){try{Module.dynCall_vii(o,l,f)}catch(h){if(typeof h!="number"&&h!=="longjmp")throw h;Module.setThrew(1,0)}}function invoke_ii(o,l){try{return Module.dynCall_ii(o,l)}catch(f){if(typeof f!="number"&&f!=="longjmp")throw f;Module.setThrew(1,0)}}function invoke_viddi(o,l,f,h,E){try{Module.dynCall_viddi(o,l,f,h,E)}catch(t){if(typeof t!="number"&&t!=="longjmp")throw t;Module.setThrew(1,0)}}function invoke_vidd(o,l,f,h){try{Module.dynCall_vidd(o,l,f,h)}catch(E){if(typeof E!="number"&&E!=="longjmp")throw E;Module.setThrew(1,0)}}function invoke_iiii(o,l,f,h){try{return Module.dynCall_iiii(o,l,f,h)}catch(E){if(typeof E!="number"&&E!=="longjmp")throw E;Module.setThrew(1,0)}}function invoke_diii(o,l,f,h){try{return Module.dynCall_diii(o,l,f,h)}catch(E){if(typeof E!="number"&&E!=="longjmp")throw E;Module.setThrew(1,0)}}function invoke_di(o,l){try{return Module.dynCall_di(o,l)}catch(f){if(typeof f!="number"&&f!=="longjmp")throw f;Module.setThrew(1,0)}}function invoke_iid(o,l,f){try{return Module.dynCall_iid(o,l,f)}catch(h){if(typeof h!="number"&&h!=="longjmp")throw h;Module.setThrew(1,0)}}function invoke_iii(o,l,f){try{return Module.dynCall_iii(o,l,f)}catch(h){if(typeof h!="number"&&h!=="longjmp")throw h;Module.setThrew(1,0)}}function invoke_viiddi(o,l,f,h,E,t){try{Module.dynCall_viiddi(o,l,f,h,E,t)}catch(N){if(typeof N!="number"&&N!=="longjmp")throw N;Module.setThrew(1,0)}}function invoke_viiiiii(o,l,f,h,E,t,N){try{Module.dynCall_viiiiii(o,l,f,h,E,t,N)}catch(F){if(typeof F!="number"&&F!=="longjmp")throw F;Module.setThrew(1,0)}}function invoke_dii(o,l,f){try{return Module.dynCall_dii(o,l,f)}catch(h){if(typeof h!="number"&&h!=="longjmp")throw h;Module.setThrew(1,0)}}function invoke_i(o){try{return Module.dynCall_i(o)}catch(l){if(typeof l!="number"&&l!=="longjmp")throw l;Module.setThrew(1,0)}}function invoke_iiiiii(o,l,f,h,E,t){try{return Module.dynCall_iiiiii(o,l,f,h,E,t)}catch(N){if(typeof N!="number"&&N!=="longjmp")throw N;Module.setThrew(1,0)}}function invoke_viiid(o,l,f,h,E){try{Module.dynCall_viiid(o,l,f,h,E)}catch(t){if(typeof t!="number"&&t!=="longjmp")throw t;Module.setThrew(1,0)}}function invoke_viififi(o,l,f,h,E,t,N){try{Module.dynCall_viififi(o,l,f,h,E,t,N)}catch(F){if(typeof F!="number"&&F!=="longjmp")throw F;Module.setThrew(1,0)}}function invoke_viii(o,l,f,h){try{Module.dynCall_viii(o,l,f,h)}catch(E){if(typeof E!="number"&&E!=="longjmp")throw E;Module.setThrew(1,0)}}function invoke_v(o){try{Module.dynCall_v(o)}catch(l){if(typeof l!="number"&&l!=="longjmp")throw l;Module.setThrew(1,0)}}function invoke_viid(o,l,f,h){try{Module.dynCall_viid(o,l,f,h)}catch(E){if(typeof E!="number"&&E!=="longjmp")throw E;Module.setThrew(1,0)}}function invoke_idd(o,l,f){try{return Module.dynCall_idd(o,l,f)}catch(h){if(typeof h!="number"&&h!=="longjmp")throw h;Module.setThrew(1,0)}}function invoke_viiii(o,l,f,h,E){try{Module.dynCall_viiii(o,l,f,h,E)}catch(t){if(typeof t!="number"&&t!=="longjmp")throw t;Module.setThrew(1,0)}}Module.asmGlobalArg={Math,Int8Array,Int16Array,Int32Array,Uint8Array,Uint16Array,Uint32Array,Float32Array,Float64Array,NaN:NaN,Infinity:1/0},Module.asmLibraryArg={abort,assert,enlargeMemory,getTotalMemory,abortOnCannotGrowMemory,invoke_viiiii,invoke_vif,invoke_vid,invoke_fiff,invoke_vi,invoke_vii,invoke_ii,invoke_viddi,invoke_vidd,invoke_iiii,invoke_diii,invoke_di,invoke_iid,invoke_iii,invoke_viiddi,invoke_viiiiii,invoke_dii,invoke_i,invoke_iiiiii,invoke_viiid,invoke_viififi,invoke_viii,invoke_v,invoke_viid,invoke_idd,invoke_viiii,_emscripten_asm_const_iiiii,_emscripten_asm_const_iiidddddd,_emscripten_asm_const_iiiid,__nbind_reference_external,_emscripten_asm_const_iiiiiiii,_removeAccessorPrefix,_typeModule,__nbind_register_pool,__decorate,_llvm_stackrestore,___cxa_atexit,__extends,__nbind_get_value_object,__ZN8facebook4yoga14YGNodeToStringEPNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEP6YGNode14YGPrintOptionsj,_emscripten_set_main_loop_timing,__nbind_register_primitive,__nbind_register_type,_emscripten_memcpy_big,__nbind_register_function,___setErrNo,__nbind_register_class,__nbind_finish,_abort,_nbind_value,_llvm_stacksave,___syscall54,_defineHidden,_emscripten_set_main_loop,_emscripten_get_now,__nbind_register_callback_signature,_emscripten_asm_const_iiiiii,__nbind_free_external,_emscripten_asm_const_iiii,_emscripten_asm_const_iiididi,___syscall6,_atexit,___syscall140,___syscall146,DYNAMICTOP_PTR,tempDoublePtr,ABORT,STACKTOP,STACK_MAX,cttz_i8,___dso_handle};var asm=function(o,l,f){var h=new o.Int8Array(f),E=new o.Int16Array(f),t=new o.Int32Array(f),N=new o.Uint8Array(f),F=new o.Uint16Array(f),k=new o.Uint32Array(f),x=new o.Float32Array(f),j=new o.Float64Array(f),q=l.DYNAMICTOP_PTR|0,V=l.tempDoublePtr|0,re=l.ABORT|0,y=l.STACKTOP|0,me=l.STACK_MAX|0,De=l.cttz_i8|0,ge=l.___dso_handle|0,ae=0,we=0,he=0,ve=0,ue=o.NaN,Ae=o.Infinity,ze=0,We=0,gt=0,_t=0,Qe=0,ot=0,Ve=o.Math.floor,Pt=o.Math.abs,Jt=o.Math.sqrt,it=o.Math.pow,J=o.Math.cos,ce=o.Math.sin,Re=o.Math.tan,le=o.Math.acos,He=o.Math.asin,dt=o.Math.atan,At=o.Math.atan2,nn=o.Math.exp,an=o.Math.log,On=o.Math.ceil,lr=o.Math.imul,ln=o.Math.min,Vt=o.Math.max,Er=o.Math.clz32,S=o.Math.fround,zt=l.abort,Xn=l.assert,vr=l.enlargeMemory,jr=l.getTotalMemory,fr=l.abortOnCannotGrowMemory,zr=l.invoke_viiiii,Xt=l.invoke_vif,Du=l.invoke_vid,c0=l.invoke_fiff,Ao=l.invoke_vi,Jo=l.invoke_vii,Fs=l.invoke_ii,Zo=l.invoke_viddi,$o=l.invoke_vidd,qt=l.invoke_iiii,xi=l.invoke_diii,lu=l.invoke_di,vi=l.invoke_iid,Dr=l.invoke_iii,el=l.invoke_viiddi,Y0=l.invoke_viiiiii,Bu=l.invoke_dii,K0=l.invoke_i,Kr=l.invoke_iiiiii,Oo=l.invoke_viiid,Mo=l.invoke_viififi,F0=l.invoke_viii,su=l.invoke_v,ki=l.invoke_viid,Ps=l.invoke_idd,Kl=l.invoke_viiii,P0=l._emscripten_asm_const_iiiii,d0=l._emscripten_asm_const_iiidddddd,Hr=l._emscripten_asm_const_iiiid,Ri=l.__nbind_reference_external,X0=l._emscripten_asm_const_iiiiiiii,mi=l._removeAccessorPrefix,en=l._typeModule,In=l.__nbind_register_pool,Ai=l.__decorate,yi=l._llvm_stackrestore,Wt=l.___cxa_atexit,Ru=l.__extends,eu=l.__nbind_get_value_object,Q0=l.__ZN8facebook4yoga14YGNodeToStringEPNSt3__212basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEP6YGNode14YGPrintOptionsj,Yi=l._emscripten_set_main_loop_timing,Xl=l.__nbind_register_primitive,ko=l.__nbind_register_type,li=l._emscripten_memcpy_big,ao=l.__nbind_register_function,Ql=l.___setErrNo,No=l.__nbind_register_class,Is=l.__nbind_finish,$n=l._abort,tl=l._nbind_value,fo=l._llvm_stacksave,I0=l.___syscall54,Sl=l._defineHidden,Lo=l._emscripten_set_main_loop,St=l._emscripten_get_now,Bt=l.__nbind_register_callback_signature,Hn=l._emscripten_asm_const_iiiiii,qr=l.__nbind_free_external,Ki=l._emscripten_asm_const_iiii,Xr=l._emscripten_asm_const_iiididi,Au=l.___syscall6,p0=l._atexit,Ni=l.___syscall140,h0=l.___syscall146,hs=S(0);let Ct=S(0);function co(e){e=e|0;var n=0;return n=y,y=y+e|0,y=y+15&-16,n|0}function nl(){return y|0}function Jl(e){e=e|0,y=e}function Uu(e,n){e=e|0,n=n|0,y=e,me=n}function vs(e,n){e=e|0,n=n|0,ae||(ae=e,we=n)}function b0(e){e=e|0,ot=e}function Q(){return ot|0}function Se(){var e=0,n=0;gr(8104,8,400)|0,gr(8504,408,540)|0,e=9044,n=e+44|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));h[9088]=0,h[9089]=1,t[2273]=0,t[2274]=948,t[2275]=948,Wt(17,8104,ge|0)|0}function Fe(e){e=e|0,ac(e+948|0)}function Le(e){return e=S(e),((mr(e)|0)&2147483647)>>>0>2139095040|0}function pt(e,n,r){e=e|0,n=n|0,r=r|0;e:do if(t[e+(n<<3)+4>>2]|0)e=e+(n<<3)|0;else{if((n|2|0)==3&&t[e+60>>2]|0){e=e+56|0;break}switch(n|0){case 0:case 2:case 4:case 5:{if(t[e+52>>2]|0){e=e+48|0;break e}break}default:}if(t[e+68>>2]|0){e=e+64|0;break}else{e=(n|1|0)==5?948:r;break}}while(0);return e|0}function Yn(e){e=e|0;var n=0;return n=p_(1e3)|0,Cn(e,(n|0)!=0,2456),t[2276]=(t[2276]|0)+1,gr(n|0,8104,1e3)|0,h[e+2>>0]|0&&(t[n+4>>2]=2,t[n+12>>2]=4),t[n+976>>2]=e,n|0}function Cn(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0;s=y,y=y+16|0,u=s,n||(t[u>>2]=r,Cl(e,5,3197,u)),y=s}function cr(){return Yn(956)|0}function Si(e){e=e|0;var n=0;return n=pn(1e3)|0,Ou(n,e),Cn(t[e+976>>2]|0,1,2456),t[2276]=(t[2276]|0)+1,t[n+944>>2]=0,n|0}function Ou(e,n){e=e|0,n=n|0;var r=0;gr(e|0,n|0,948)|0,sa(e+948|0,n+948|0),r=e+960|0,e=n+960|0,n=r+40|0;do t[r>>2]=t[e>>2],r=r+4|0,e=e+4|0;while((r|0)<(n|0))}function ju(e){e=e|0;var n=0,r=0,u=0,s=0;if(n=e+944|0,r=t[n>>2]|0,r|0&&(zu(r+948|0,e)|0,t[n>>2]=0),r=wu(e)|0,r|0){n=0;do t[(Ti(e,n)|0)+944>>2]=0,n=n+1|0;while((n|0)!=(r|0))}r=e+948|0,u=t[r>>2]|0,s=e+952|0,n=t[s>>2]|0,(n|0)!=(u|0)&&(t[s>>2]=n+(~((n+-4-u|0)>>>2)<<2)),Fo(r),h_(e),t[2276]=(t[2276]|0)+-1}function zu(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0;u=t[e>>2]|0,w=e+4|0,r=t[w>>2]|0,a=r;e:do if((u|0)==(r|0))s=u,v=4;else for(e=u;;){if((t[e>>2]|0)==(n|0)){s=e,v=4;break e}if(e=e+4|0,(e|0)==(r|0)){e=0;break}}while(0);return(v|0)==4&&((s|0)!=(r|0)?(u=s+4|0,e=a-u|0,n=e>>2,n&&(ky(s|0,u|0,e|0)|0,r=t[w>>2]|0),e=s+(n<<2)|0,(r|0)==(e|0)||(t[w>>2]=r+(~((r+-4-e|0)>>>2)<<2)),e=1):e=0),e|0}function wu(e){return e=e|0,(t[e+952>>2]|0)-(t[e+948>>2]|0)>>2|0}function Ti(e,n){e=e|0,n=n|0;var r=0;return r=t[e+948>>2]|0,(t[e+952>>2]|0)-r>>2>>>0>n>>>0?e=t[r+(n<<2)>>2]|0:e=0,e|0}function Fo(e){e=e|0;var n=0,r=0,u=0,s=0;u=y,y=y+32|0,n=u,s=t[e>>2]|0,r=(t[e+4>>2]|0)-s|0,((t[e+8>>2]|0)-s|0)>>>0>r>>>0&&(s=r>>2,K(n,s,s,e+8|0),ti(e,n),ni(n)),y=u}function Mu(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0;L=wu(e)|0;do if(L|0){if((t[(Ti(e,0)|0)+944>>2]|0)==(e|0)){if(!(zu(e+948|0,n)|0))break;gr(n+400|0,8504,540)|0,t[n+944>>2]=0,Qn(e);break}v=t[(t[e+976>>2]|0)+12>>2]|0,w=e+948|0,T=(v|0)==0,r=0,a=0;do u=t[(t[w>>2]|0)+(a<<2)>>2]|0,(u|0)==(n|0)?Qn(e):(s=Si(u)|0,t[(t[w>>2]|0)+(r<<2)>>2]=s,t[s+944>>2]=e,T||BE[v&15](u,s,e,r),r=r+1|0),a=a+1|0;while((a|0)!=(L|0));if(r>>>0>>0){T=e+948|0,w=e+952|0,v=r,r=t[w>>2]|0;do a=(t[T>>2]|0)+(v<<2)|0,u=a+4|0,s=r-u|0,n=s>>2,n&&(ky(a|0,u|0,s|0)|0,r=t[w>>2]|0),s=r,u=a+(n<<2)|0,(s|0)!=(u|0)&&(r=s+(~((s+-4-u|0)>>>2)<<2)|0,t[w>>2]=r),v=v+1|0;while((v|0)!=(L|0))}}while(0)}function po(e){e=e|0;var n=0,r=0,u=0,s=0;Hu(e,(wu(e)|0)==0,2491),Hu(e,(t[e+944>>2]|0)==0,2545),n=e+948|0,r=t[n>>2]|0,u=e+952|0,s=t[u>>2]|0,(s|0)!=(r|0)&&(t[u>>2]=s+(~((s+-4-r|0)>>>2)<<2)),Fo(n),n=e+976|0,r=t[n>>2]|0,gr(e|0,8104,1e3)|0,h[r+2>>0]|0&&(t[e+4>>2]=2,t[e+12>>2]=4),t[n>>2]=r}function Hu(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0;s=y,y=y+16|0,u=s,n||(t[u>>2]=r,pr(e,5,3197,u)),y=s}function Pa(){return t[2276]|0}function v0(){var e=0;return e=p_(20)|0,ia((e|0)!=0,2592),t[2277]=(t[2277]|0)+1,t[e>>2]=t[239],t[e+4>>2]=t[240],t[e+8>>2]=t[241],t[e+12>>2]=t[242],t[e+16>>2]=t[243],e|0}function ia(e,n){e=e|0,n=n|0;var r=0,u=0;u=y,y=y+16|0,r=u,e||(t[r>>2]=n,pr(0,5,3197,r)),y=u}function J0(e){e=e|0,h_(e),t[2277]=(t[2277]|0)+-1}function ua(e,n){e=e|0,n=n|0;var r=0;n?(Hu(e,(wu(e)|0)==0,2629),r=1):(r=0,n=0),t[e+964>>2]=n,t[e+988>>2]=r}function Ia(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;u=y,y=y+16|0,a=u+8|0,s=u+4|0,v=u,t[s>>2]=n,Hu(e,(t[n+944>>2]|0)==0,2709),Hu(e,(t[e+964>>2]|0)==0,2763),ms(e),n=e+948|0,t[v>>2]=(t[n>>2]|0)+(r<<2),t[a>>2]=t[v>>2],S0(n,a,s)|0,t[(t[s>>2]|0)+944>>2]=e,Qn(e),y=u}function ms(e){e=e|0;var n=0,r=0,u=0,s=0,a=0,v=0,w=0;if(r=wu(e)|0,r|0&&(t[(Ti(e,0)|0)+944>>2]|0)!=(e|0)){u=t[(t[e+976>>2]|0)+12>>2]|0,s=e+948|0,a=(u|0)==0,n=0;do v=t[(t[s>>2]|0)+(n<<2)>>2]|0,w=Si(v)|0,t[(t[s>>2]|0)+(n<<2)>>2]=w,t[w+944>>2]=e,a||BE[u&15](v,w,e,n),n=n+1|0;while((n|0)!=(r|0))}}function S0(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0,Be=0,Te=0,ye=0,Ze=0,Ye=0;Ze=y,y=y+64|0,b=Ze+52|0,w=Ze+48|0,X=Ze+28|0,Be=Ze+24|0,Te=Ze+20|0,ye=Ze,u=t[e>>2]|0,a=u,n=u+((t[n>>2]|0)-a>>2<<2)|0,u=e+4|0,s=t[u>>2]|0,v=e+8|0;do if(s>>>0<(t[v>>2]|0)>>>0){if((n|0)==(s|0)){t[n>>2]=t[r>>2],t[u>>2]=(t[u>>2]|0)+4;break}Wr(e,n,s,n+4|0),n>>>0<=r>>>0&&(r=(t[u>>2]|0)>>>0>r>>>0?r+4|0:r),t[n>>2]=t[r>>2]}else{u=(s-a>>2)+1|0,s=R0(e)|0,s>>>0>>0&&di(e),M=t[e>>2]|0,L=(t[v>>2]|0)-M|0,a=L>>1,K(ye,L>>2>>>0>>1>>>0?a>>>0>>0?u:a:s,n-M>>2,e+8|0),M=ye+8|0,u=t[M>>2]|0,a=ye+12|0,L=t[a>>2]|0,v=L,T=u;do if((u|0)==(L|0)){if(L=ye+4|0,u=t[L>>2]|0,Ye=t[ye>>2]|0,s=Ye,u>>>0<=Ye>>>0){u=v-s>>1,u=(u|0)==0?1:u,K(X,u,u>>>2,t[ye+16>>2]|0),t[Be>>2]=t[L>>2],t[Te>>2]=t[M>>2],t[w>>2]=t[Be>>2],t[b>>2]=t[Te>>2],Di(X,w,b),u=t[ye>>2]|0,t[ye>>2]=t[X>>2],t[X>>2]=u,u=X+4|0,Ye=t[L>>2]|0,t[L>>2]=t[u>>2],t[u>>2]=Ye,u=X+8|0,Ye=t[M>>2]|0,t[M>>2]=t[u>>2],t[u>>2]=Ye,u=X+12|0,Ye=t[a>>2]|0,t[a>>2]=t[u>>2],t[u>>2]=Ye,ni(X),u=t[M>>2]|0;break}a=u,v=((a-s>>2)+1|0)/-2|0,w=u+(v<<2)|0,s=T-a|0,a=s>>2,a&&(ky(w|0,u|0,s|0)|0,u=t[L>>2]|0),Ye=w+(a<<2)|0,t[M>>2]=Ye,t[L>>2]=u+(v<<2),u=Ye}while(0);t[u>>2]=t[r>>2],t[M>>2]=(t[M>>2]|0)+4,n=ft(e,ye,n)|0,ni(ye)}while(0);return y=Ze,n|0}function Qn(e){e=e|0;var n=0;do{if(n=e+984|0,h[n>>0]|0)break;h[n>>0]=1,x[e+504>>2]=S(ue),e=t[e+944>>2]|0}while((e|0)!=0)}function ac(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-4-u|0)>>>2)<<2)),Et(r))}function si(e){return e=e|0,t[e+944>>2]|0}function Jr(e){e=e|0,Hu(e,(t[e+964>>2]|0)!=0,2832),Qn(e)}function Zl(e){return e=e|0,(h[e+984>>0]|0)!=0|0}function oa(e,n){e=e|0,n=n|0,vL(e,n,400)|0&&(gr(e|0,n|0,400)|0,Qn(e))}function pf(e){e=e|0;var n=Ct;return n=S(x[e+44>>2]),e=Le(n)|0,S(e?S(0):n)}function bs(e){e=e|0;var n=Ct;return n=S(x[e+48>>2]),Le(n)|0&&(n=h[(t[e+976>>2]|0)+2>>0]|0?S(1):S(0)),S(n)}function ba(e,n){e=e|0,n=n|0,t[e+980>>2]=n}function Bs(e){return e=e|0,t[e+980>>2]|0}function m0(e,n){e=e|0,n=n|0;var r=0;r=e+4|0,(t[r>>2]|0)!=(n|0)&&(t[r>>2]=n,Qn(e))}function Us(e){return e=e|0,t[e+4>>2]|0}function zi(e,n){e=e|0,n=n|0;var r=0;r=e+8|0,(t[r>>2]|0)!=(n|0)&&(t[r>>2]=n,Qn(e))}function U(e){return e=e|0,t[e+8>>2]|0}function H(e,n){e=e|0,n=n|0;var r=0;r=e+12|0,(t[r>>2]|0)!=(n|0)&&(t[r>>2]=n,Qn(e))}function Y(e){return e=e|0,t[e+12>>2]|0}function ee(e,n){e=e|0,n=n|0;var r=0;r=e+16|0,(t[r>>2]|0)!=(n|0)&&(t[r>>2]=n,Qn(e))}function Ce(e){return e=e|0,t[e+16>>2]|0}function _e(e,n){e=e|0,n=n|0;var r=0;r=e+20|0,(t[r>>2]|0)!=(n|0)&&(t[r>>2]=n,Qn(e))}function Oe(e){return e=e|0,t[e+20>>2]|0}function $(e,n){e=e|0,n=n|0;var r=0;r=e+24|0,(t[r>>2]|0)!=(n|0)&&(t[r>>2]=n,Qn(e))}function Ne(e){return e=e|0,t[e+24>>2]|0}function Je(e,n){e=e|0,n=n|0;var r=0;r=e+28|0,(t[r>>2]|0)!=(n|0)&&(t[r>>2]=n,Qn(e))}function vt(e){return e=e|0,t[e+28>>2]|0}function oe(e,n){e=e|0,n=n|0;var r=0;r=e+32|0,(t[r>>2]|0)!=(n|0)&&(t[r>>2]=n,Qn(e))}function qe(e){return e=e|0,t[e+32>>2]|0}function rt(e,n){e=e|0,n=n|0;var r=0;r=e+36|0,(t[r>>2]|0)!=(n|0)&&(t[r>>2]=n,Qn(e))}function xt(e){return e=e|0,t[e+36>>2]|0}function kt(e,n){e=e|0,n=S(n);var r=0;r=e+40|0,S(x[r>>2])!=n&&(x[r>>2]=n,Qn(e))}function bt(e,n){e=e|0,n=S(n);var r=0;r=e+44|0,S(x[r>>2])!=n&&(x[r>>2]=n,Qn(e))}function sn(e,n){e=e|0,n=S(n);var r=0;r=e+48|0,S(x[r>>2])!=n&&(x[r>>2]=n,Qn(e))}function rn(e,n){e=e|0,n=S(n);var r=0,u=0,s=0,a=0;a=Le(n)|0,r=(a^1)&1,u=e+52|0,s=e+56|0,a|S(x[u>>2])==n&&(t[s>>2]|0)==(r|0)||(x[u>>2]=n,t[s>>2]=r,Qn(e))}function Ft(e,n){e=e|0,n=S(n);var r=0,u=0;u=e+52|0,r=e+56|0,S(x[u>>2])==n&&(t[r>>2]|0)==2||(x[u>>2]=n,u=Le(n)|0,t[r>>2]=u?3:2,Qn(e))}function Dn(e,n){e=e|0,n=n|0;var r=0,u=0;u=n+52|0,r=t[u+4>>2]|0,n=e,t[n>>2]=t[u>>2],t[n+4>>2]=r}function dr(e,n,r){e=e|0,n=n|0,r=S(r);var u=0,s=0,a=0;a=Le(r)|0,u=(a^1)&1,s=e+132+(n<<3)|0,n=e+132+(n<<3)+4|0,a|S(x[s>>2])==r&&(t[n>>2]|0)==(u|0)||(x[s>>2]=r,t[n>>2]=u,Qn(e))}function er(e,n,r){e=e|0,n=n|0,r=S(r);var u=0,s=0,a=0;a=Le(r)|0,u=a?0:2,s=e+132+(n<<3)|0,n=e+132+(n<<3)+4|0,a|S(x[s>>2])==r&&(t[n>>2]|0)==(u|0)||(x[s>>2]=r,t[n>>2]=u,Qn(e))}function Cr(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=n+132+(r<<3)|0,n=t[u+4>>2]|0,r=e,t[r>>2]=t[u>>2],t[r+4>>2]=n}function Rn(e,n,r){e=e|0,n=n|0,r=S(r);var u=0,s=0,a=0;a=Le(r)|0,u=(a^1)&1,s=e+60+(n<<3)|0,n=e+60+(n<<3)+4|0,a|S(x[s>>2])==r&&(t[n>>2]|0)==(u|0)||(x[s>>2]=r,t[n>>2]=u,Qn(e))}function Nr(e,n,r){e=e|0,n=n|0,r=S(r);var u=0,s=0,a=0;a=Le(r)|0,u=a?0:2,s=e+60+(n<<3)|0,n=e+60+(n<<3)+4|0,a|S(x[s>>2])==r&&(t[n>>2]|0)==(u|0)||(x[s>>2]=r,t[n>>2]=u,Qn(e))}function y0(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=n+60+(r<<3)|0,n=t[u+4>>2]|0,r=e,t[r>>2]=t[u>>2],t[r+4>>2]=n}function Lr(e,n){e=e|0,n=n|0;var r=0;r=e+60+(n<<3)+4|0,(t[r>>2]|0)!=3&&(x[e+60+(n<<3)>>2]=S(ue),t[r>>2]=3,Qn(e))}function ut(e,n,r){e=e|0,n=n|0,r=S(r);var u=0,s=0,a=0;a=Le(r)|0,u=(a^1)&1,s=e+204+(n<<3)|0,n=e+204+(n<<3)+4|0,a|S(x[s>>2])==r&&(t[n>>2]|0)==(u|0)||(x[s>>2]=r,t[n>>2]=u,Qn(e))}function wt(e,n,r){e=e|0,n=n|0,r=S(r);var u=0,s=0,a=0;a=Le(r)|0,u=a?0:2,s=e+204+(n<<3)|0,n=e+204+(n<<3)+4|0,a|S(x[s>>2])==r&&(t[n>>2]|0)==(u|0)||(x[s>>2]=r,t[n>>2]=u,Qn(e))}function et(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=n+204+(r<<3)|0,n=t[u+4>>2]|0,r=e,t[r>>2]=t[u>>2],t[r+4>>2]=n}function It(e,n,r){e=e|0,n=n|0,r=S(r);var u=0,s=0,a=0;a=Le(r)|0,u=(a^1)&1,s=e+276+(n<<3)|0,n=e+276+(n<<3)+4|0,a|S(x[s>>2])==r&&(t[n>>2]|0)==(u|0)||(x[s>>2]=r,t[n>>2]=u,Qn(e))}function un(e,n){return e=e|0,n=n|0,S(x[e+276+(n<<3)>>2])}function fn(e,n){e=e|0,n=S(n);var r=0,u=0,s=0,a=0;a=Le(n)|0,r=(a^1)&1,u=e+348|0,s=e+352|0,a|S(x[u>>2])==n&&(t[s>>2]|0)==(r|0)||(x[u>>2]=n,t[s>>2]=r,Qn(e))}function Jn(e,n){e=e|0,n=S(n);var r=0,u=0;u=e+348|0,r=e+352|0,S(x[u>>2])==n&&(t[r>>2]|0)==2||(x[u>>2]=n,u=Le(n)|0,t[r>>2]=u?3:2,Qn(e))}function wr(e){e=e|0;var n=0;n=e+352|0,(t[n>>2]|0)!=3&&(x[e+348>>2]=S(ue),t[n>>2]=3,Qn(e))}function au(e,n){e=e|0,n=n|0;var r=0,u=0;u=n+348|0,r=t[u+4>>2]|0,n=e,t[n>>2]=t[u>>2],t[n+4>>2]=r}function ku(e,n){e=e|0,n=S(n);var r=0,u=0,s=0,a=0;a=Le(n)|0,r=(a^1)&1,u=e+356|0,s=e+360|0,a|S(x[u>>2])==n&&(t[s>>2]|0)==(r|0)||(x[u>>2]=n,t[s>>2]=r,Qn(e))}function T0(e,n){e=e|0,n=S(n);var r=0,u=0;u=e+356|0,r=e+360|0,S(x[u>>2])==n&&(t[r>>2]|0)==2||(x[u>>2]=n,u=Le(n)|0,t[r>>2]=u?3:2,Qn(e))}function Z0(e){e=e|0;var n=0;n=e+360|0,(t[n>>2]|0)!=3&&(x[e+356>>2]=S(ue),t[n>>2]=3,Qn(e))}function Nu(e,n){e=e|0,n=n|0;var r=0,u=0;u=n+356|0,r=t[u+4>>2]|0,n=e,t[n>>2]=t[u>>2],t[n+4>>2]=r}function gi(e,n){e=e|0,n=S(n);var r=0,u=0,s=0,a=0;a=Le(n)|0,r=(a^1)&1,u=e+364|0,s=e+368|0,a|S(x[u>>2])==n&&(t[s>>2]|0)==(r|0)||(x[u>>2]=n,t[s>>2]=r,Qn(e))}function Po(e,n){e=e|0,n=S(n);var r=0,u=0,s=0,a=0;a=Le(n)|0,r=a?0:2,u=e+364|0,s=e+368|0,a|S(x[u>>2])==n&&(t[s>>2]|0)==(r|0)||(x[u>>2]=n,t[s>>2]=r,Qn(e))}function rl(e,n){e=e|0,n=n|0;var r=0,u=0;u=n+364|0,r=t[u+4>>2]|0,n=e,t[n>>2]=t[u>>2],t[n+4>>2]=r}function hf(e,n){e=e|0,n=S(n);var r=0,u=0,s=0,a=0;a=Le(n)|0,r=(a^1)&1,u=e+372|0,s=e+376|0,a|S(x[u>>2])==n&&(t[s>>2]|0)==(r|0)||(x[u>>2]=n,t[s>>2]=r,Qn(e))}function Tl(e,n){e=e|0,n=S(n);var r=0,u=0,s=0,a=0;a=Le(n)|0,r=a?0:2,u=e+372|0,s=e+376|0,a|S(x[u>>2])==n&&(t[s>>2]|0)==(r|0)||(x[u>>2]=n,t[s>>2]=r,Qn(e))}function vf(e,n){e=e|0,n=n|0;var r=0,u=0;u=n+372|0,r=t[u+4>>2]|0,n=e,t[n>>2]=t[u>>2],t[n+4>>2]=r}function Io(e,n){e=e|0,n=S(n);var r=0,u=0,s=0,a=0;a=Le(n)|0,r=(a^1)&1,u=e+380|0,s=e+384|0,a|S(x[u>>2])==n&&(t[s>>2]|0)==(r|0)||(x[u>>2]=n,t[s>>2]=r,Qn(e))}function ys(e,n){e=e|0,n=S(n);var r=0,u=0,s=0,a=0;a=Le(n)|0,r=a?0:2,u=e+380|0,s=e+384|0,a|S(x[u>>2])==n&&(t[s>>2]|0)==(r|0)||(x[u>>2]=n,t[s>>2]=r,Qn(e))}function js(e,n){e=e|0,n=n|0;var r=0,u=0;u=n+380|0,r=t[u+4>>2]|0,n=e,t[n>>2]=t[u>>2],t[n+4>>2]=r}function bo(e,n){e=e|0,n=S(n);var r=0,u=0,s=0,a=0;a=Le(n)|0,r=(a^1)&1,u=e+388|0,s=e+392|0,a|S(x[u>>2])==n&&(t[s>>2]|0)==(r|0)||(x[u>>2]=n,t[s>>2]=r,Qn(e))}function Bo(e,n){e=e|0,n=S(n);var r=0,u=0,s=0,a=0;a=Le(n)|0,r=a?0:2,u=e+388|0,s=e+392|0,a|S(x[u>>2])==n&&(t[s>>2]|0)==(r|0)||(x[u>>2]=n,t[s>>2]=r,Qn(e))}function gs(e,n){e=e|0,n=n|0;var r=0,u=0;u=n+388|0,r=t[u+4>>2]|0,n=e,t[n>>2]=t[u>>2],t[n+4>>2]=r}function Xu(e,n){e=e|0,n=S(n);var r=0;r=e+396|0,S(x[r>>2])!=n&&(x[r>>2]=n,Qn(e))}function Su(e){return e=e|0,S(x[e+396>>2])}function _i(e){return e=e|0,S(x[e+400>>2])}function C0(e){return e=e|0,S(x[e+404>>2])}function $0(e){return e=e|0,S(x[e+408>>2])}function Uo(e){return e=e|0,S(x[e+412>>2])}function la(e){return e=e|0,S(x[e+416>>2])}function $l(e){return e=e|0,S(x[e+420>>2])}function tu(e,n){switch(e=e|0,n=n|0,Hu(e,(n|0)<6,2918),n|0){case 0:{n=(t[e+496>>2]|0)==2?5:4;break}case 2:{n=(t[e+496>>2]|0)==2?4:5;break}default:}return S(x[e+424+(n<<2)>>2])}function Zr(e,n){switch(e=e|0,n=n|0,Hu(e,(n|0)<6,2918),n|0){case 0:{n=(t[e+496>>2]|0)==2?5:4;break}case 2:{n=(t[e+496>>2]|0)==2?4:5;break}default:}return S(x[e+448+(n<<2)>>2])}function ho(e,n){switch(e=e|0,n=n|0,Hu(e,(n|0)<6,2918),n|0){case 0:{n=(t[e+496>>2]|0)==2?5:4;break}case 2:{n=(t[e+496>>2]|0)==2?4:5;break}default:}return S(x[e+472+(n<<2)>>2])}function Bi(e,n){e=e|0,n=n|0;var r=0,u=Ct;return r=t[e+4>>2]|0,(r|0)==(t[n+4>>2]|0)?r?(u=S(x[e>>2]),e=S(Pt(S(u-S(x[n>>2]))))>2]=0,t[u+4>>2]=0,t[u+8>>2]=0,Q0(u|0,e|0,n|0,0),pr(e,3,(h[u+11>>0]|0)<0?t[u>>2]|0:u,r),BL(u),y=r}function eo(e,n,r,u){e=S(e),n=S(n),r=r|0,u=u|0;var s=Ct;e=S(e*n),s=S(NE(e,S(1)));do if(Ci(s,S(0))|0)e=S(e-s);else{if(e=S(e-s),Ci(s,S(1))|0){e=S(e+S(1));break}if(r){e=S(e+S(1));break}u||(s>S(.5)?s=S(1):(u=Ci(s,S(.5))|0,s=S(u?1:0)),e=S(e+s))}while(0);return S(e/n)}function to(e,n,r,u,s,a,v,w,T,L,M,b,X){e=e|0,n=S(n),r=r|0,u=S(u),s=s|0,a=S(a),v=v|0,w=S(w),T=S(T),L=S(L),M=S(M),b=S(b),X=X|0;var Be=0,Te=Ct,ye=Ct,Ze=Ct,Ye=Ct,ct=Ct,ke=Ct;return T>2]),Te!=S(0))?(Ze=S(eo(n,Te,0,0)),Ye=S(eo(u,Te,0,0)),ye=S(eo(a,Te,0,0)),Te=S(eo(w,Te,0,0))):(ye=a,Ze=n,Te=w,Ye=u),(s|0)==(e|0)?Be=Ci(ye,Ze)|0:Be=0,(v|0)==(r|0)?X=Ci(Te,Ye)|0:X=0,!Be&&(ct=S(n-M),!(xe(e,ct,T)|0))&&!(tt(e,ct,s,T)|0)?Be=Ke(e,ct,s,a,T)|0:Be=1,!X&&(ke=S(u-b),!(xe(r,ke,L)|0))&&!(tt(r,ke,v,L)|0)?X=Ke(r,ke,v,w,L)|0:X=1,X=Be&X),X|0}function xe(e,n,r){return e=e|0,n=S(n),r=S(r),(e|0)==1?e=Ci(n,r)|0:e=0,e|0}function tt(e,n,r,u){return e=e|0,n=S(n),r=r|0,u=S(u),(e|0)==2&(r|0)==0?n>=u?e=1:e=Ci(n,u)|0:e=0,e|0}function Ke(e,n,r,u,s){return e=e|0,n=S(n),r=r|0,u=S(u),s=S(s),(e|0)==2&(r|0)==2&u>n?s<=n?e=1:e=Ci(n,s)|0:e=0,e|0}function Yt(e,n,r,u,s,a,v,w,T,L,M){e=e|0,n=S(n),r=S(r),u=u|0,s=s|0,a=a|0,v=S(v),w=S(w),T=T|0,L=L|0,M=M|0;var b=0,X=0,Be=0,Te=0,ye=Ct,Ze=Ct,Ye=0,ct=0,ke=0,Ie=0,Zt=0,Br=0,Pn=0,gn=0,_r=0,Pr=0,kn=0,uu=Ct,os=Ct,ls=Ct,ss=0,ea=0;kn=y,y=y+160|0,gn=kn+152|0,Pn=kn+120|0,Br=kn+104|0,ke=kn+72|0,Te=kn+56|0,Zt=kn+8|0,ct=kn,Ie=(t[2279]|0)+1|0,t[2279]=Ie,_r=e+984|0,(h[_r>>0]|0)!=0&&(t[e+512>>2]|0)!=(t[2278]|0)?Ye=4:(t[e+516>>2]|0)==(u|0)?Pr=0:Ye=4,(Ye|0)==4&&(t[e+520>>2]=0,t[e+924>>2]=-1,t[e+928>>2]=-1,x[e+932>>2]=S(-1),x[e+936>>2]=S(-1),Pr=1);e:do if(t[e+964>>2]|0)if(ye=S(Kt(e,2,v)),Ze=S(Kt(e,0,v)),b=e+916|0,ls=S(x[b>>2]),os=S(x[e+920>>2]),uu=S(x[e+932>>2]),to(s,n,a,r,t[e+924>>2]|0,ls,t[e+928>>2]|0,os,uu,S(x[e+936>>2]),ye,Ze,M)|0)Ye=22;else if(Be=t[e+520>>2]|0,!Be)Ye=21;else for(X=0;;){if(b=e+524+(X*24|0)|0,uu=S(x[b>>2]),os=S(x[e+524+(X*24|0)+4>>2]),ls=S(x[e+524+(X*24|0)+16>>2]),to(s,n,a,r,t[e+524+(X*24|0)+8>>2]|0,uu,t[e+524+(X*24|0)+12>>2]|0,os,ls,S(x[e+524+(X*24|0)+20>>2]),ye,Ze,M)|0){Ye=22;break e}if(X=X+1|0,X>>>0>=Be>>>0){Ye=21;break}}else{if(T){if(b=e+916|0,!(Ci(S(x[b>>2]),n)|0)){Ye=21;break}if(!(Ci(S(x[e+920>>2]),r)|0)){Ye=21;break}if((t[e+924>>2]|0)!=(s|0)){Ye=21;break}b=(t[e+928>>2]|0)==(a|0)?b:0,Ye=22;break}if(Be=t[e+520>>2]|0,!Be)Ye=21;else for(X=0;;){if(b=e+524+(X*24|0)|0,Ci(S(x[b>>2]),n)|0&&Ci(S(x[e+524+(X*24|0)+4>>2]),r)|0&&(t[e+524+(X*24|0)+8>>2]|0)==(s|0)&&(t[e+524+(X*24|0)+12>>2]|0)==(a|0)){Ye=22;break e}if(X=X+1|0,X>>>0>=Be>>>0){Ye=21;break}}}while(0);do if((Ye|0)==21)h[11697]|0?(b=0,Ye=28):(b=0,Ye=31);else if((Ye|0)==22){if(X=(h[11697]|0)!=0,!((b|0)!=0&(Pr^1)))if(X){Ye=28;break}else{Ye=31;break}Te=b+16|0,t[e+908>>2]=t[Te>>2],Be=b+20|0,t[e+912>>2]=t[Be>>2],(h[11698]|0)==0|X^1||(t[ct>>2]=Ei(Ie)|0,t[ct+4>>2]=Ie,pr(e,4,2972,ct),X=t[e+972>>2]|0,X|0&&P1[X&127](e),s=bn(s,T)|0,a=bn(a,T)|0,ea=+S(x[Te>>2]),ss=+S(x[Be>>2]),t[Zt>>2]=s,t[Zt+4>>2]=a,j[Zt+8>>3]=+n,j[Zt+16>>3]=+r,j[Zt+24>>3]=ea,j[Zt+32>>3]=ss,t[Zt+40>>2]=L,pr(e,4,2989,Zt))}while(0);return(Ye|0)==28&&(X=Ei(Ie)|0,t[Te>>2]=X,t[Te+4>>2]=Ie,t[Te+8>>2]=Pr?3047:11699,pr(e,4,3038,Te),X=t[e+972>>2]|0,X|0&&P1[X&127](e),Zt=bn(s,T)|0,Ye=bn(a,T)|0,t[ke>>2]=Zt,t[ke+4>>2]=Ye,j[ke+8>>3]=+n,j[ke+16>>3]=+r,t[ke+24>>2]=L,pr(e,4,3049,ke),Ye=31),(Ye|0)==31&&(mu(e,n,r,u,s,a,v,w,T,M),h[11697]|0&&(X=t[2279]|0,Zt=Ei(X)|0,t[Br>>2]=Zt,t[Br+4>>2]=X,t[Br+8>>2]=Pr?3047:11699,pr(e,4,3083,Br),X=t[e+972>>2]|0,X|0&&P1[X&127](e),Zt=bn(s,T)|0,Br=bn(a,T)|0,ss=+S(x[e+908>>2]),ea=+S(x[e+912>>2]),t[Pn>>2]=Zt,t[Pn+4>>2]=Br,j[Pn+8>>3]=ss,j[Pn+16>>3]=ea,t[Pn+24>>2]=L,pr(e,4,3092,Pn)),t[e+516>>2]=u,b||(X=e+520|0,b=t[X>>2]|0,(b|0)==16&&(h[11697]|0&&pr(e,4,3124,gn),t[X>>2]=0,b=0),T?b=e+916|0:(t[X>>2]=b+1,b=e+524+(b*24|0)|0),x[b>>2]=n,x[b+4>>2]=r,t[b+8>>2]=s,t[b+12>>2]=a,t[b+16>>2]=t[e+908>>2],t[b+20>>2]=t[e+912>>2],b=0)),T&&(t[e+416>>2]=t[e+908>>2],t[e+420>>2]=t[e+912>>2],h[e+985>>0]=1,h[_r>>0]=0),t[2279]=(t[2279]|0)+-1,t[e+512>>2]=t[2278],y=kn,Pr|(b|0)==0|0}function Kt(e,n,r){e=e|0,n=n|0,r=S(r);var u=Ct;return u=S(Hi(e,n,r)),S(u+S(A0(e,n,r)))}function pr(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0;a=y,y=y+16|0,s=a,t[s>>2]=u,e?u=t[e+976>>2]|0:u=0,zs(u,e,n,r,s),y=a}function Ei(e){return e=e|0,(e>>>0>60?3201:3201+(60-e)|0)|0}function bn(e,n){e=e|0,n=n|0;var r=0,u=0,s=0;return s=y,y=y+32|0,r=s+12|0,u=s,t[r>>2]=t[254],t[r+4>>2]=t[255],t[r+8>>2]=t[256],t[u>>2]=t[257],t[u+4>>2]=t[258],t[u+8>>2]=t[259],(e|0)>2?e=11699:e=t[(n?u:r)+(e<<2)>>2]|0,y=s,e|0}function mu(e,n,r,u,s,a,v,w,T,L){e=e|0,n=S(n),r=S(r),u=u|0,s=s|0,a=a|0,v=S(v),w=S(w),T=T|0,L=L|0;var M=0,b=0,X=0,Be=0,Te=Ct,ye=Ct,Ze=Ct,Ye=Ct,ct=Ct,ke=Ct,Ie=Ct,Zt=0,Br=0,Pn=0,gn=Ct,_r=Ct,Pr=0,kn=Ct,uu=0,os=0,ls=0,ss=0,ea=0,t2=0,n2=0,uf=0,r2=0,Fc=0,Pc=0,i2=0,u2=0,o2=0,pi=0,of=0,l2=0,Yf=0,s2=Ct,a2=Ct,Ic=Ct,bc=Ct,Kf=Ct,ql=0,La=0,Ns=0,lf=0,b1=0,B1=Ct,Bc=Ct,U1=Ct,j1=Ct,Wl=Ct,El=Ct,sf=0,hu=Ct,z1=Ct,as=Ct,Xf=Ct,fs=Ct,Qf=Ct,H1=0,q1=0,Jf=Ct,Vl=Ct,af=0,W1=0,V1=0,G1=0,Sr=Ct,bu=0,Dl=0,cs=0,Gl=0,Or=0,Bn=0,ff=0,mn=Ct,Y1=0,a0=0;ff=y,y=y+16|0,ql=ff+12|0,La=ff+8|0,Ns=ff+4|0,lf=ff,Hu(e,(s|0)==0|(Le(n)|0)^1,3326),Hu(e,(a|0)==0|(Le(r)|0)^1,3406),Dl=xl(e,u)|0,t[e+496>>2]=Dl,Or=B0(2,Dl)|0,Bn=B0(0,Dl)|0,x[e+440>>2]=S(Hi(e,Or,v)),x[e+444>>2]=S(A0(e,Or,v)),x[e+428>>2]=S(Hi(e,Bn,v)),x[e+436>>2]=S(A0(e,Bn,v)),x[e+464>>2]=S(O0(e,Or)),x[e+468>>2]=S(vo(e,Or)),x[e+452>>2]=S(O0(e,Bn)),x[e+460>>2]=S(vo(e,Bn)),x[e+488>>2]=S(Fu(e,Or,v)),x[e+492>>2]=S(Ju(e,Or,v)),x[e+476>>2]=S(Fu(e,Bn,v)),x[e+484>>2]=S(Ju(e,Bn,v));do if(t[e+964>>2]|0)es(e,n,r,s,a,v,w);else{if(cs=e+948|0,Gl=(t[e+952>>2]|0)-(t[cs>>2]|0)>>2,!Gl){_s(e,n,r,s,a,v,w);break}if(!T&&aa(e,n,r,s,a,v,w)|0)break;ms(e),of=e+508|0,h[of>>0]=0,Or=B0(t[e+4>>2]|0,Dl)|0,Bn=gf(Or,Dl)|0,bu=qi(Or)|0,l2=t[e+8>>2]|0,W1=e+28|0,Yf=(t[W1>>2]|0)!=0,fs=bu?v:w,Jf=bu?w:v,s2=S(Zu(e,Or,v)),a2=S(Es(e,Or,v)),Te=S(Zu(e,Bn,v)),Qf=S(Rr(e,Or,v)),Vl=S(Rr(e,Bn,v)),Pn=bu?s:a,af=bu?a:s,Sr=bu?Qf:Vl,ct=bu?Vl:Qf,Xf=S(Kt(e,2,v)),Ye=S(Kt(e,0,v)),ye=S(S(xn(e+364|0,v))-Sr),Ze=S(S(xn(e+380|0,v))-Sr),ke=S(S(xn(e+372|0,w))-ct),Ie=S(S(xn(e+388|0,w))-ct),Ic=bu?ye:ke,bc=bu?Ze:Ie,Xf=S(n-Xf),n=S(Xf-Sr),Le(n)|0?Sr=n:Sr=S(xu(S(Kp(n,Ze)),ye)),z1=S(r-Ye),n=S(z1-ct),Le(n)|0?as=n:as=S(xu(S(Kp(n,Ie)),ke)),ye=bu?Sr:as,hu=bu?as:Sr;e:do if((Pn|0)==1)for(u=0,b=0;;){if(M=Ti(e,b)|0,!u)S(nu(M))>S(0)&&S(fu(M))>S(0)?u=M:u=0;else if(no(M)|0){Be=0;break e}if(b=b+1|0,b>>>0>=Gl>>>0){Be=u;break}}else Be=0;while(0);Zt=Be+500|0,Br=Be+504|0,u=0,M=0,n=S(0),X=0;do{if(b=t[(t[cs>>2]|0)+(X<<2)>>2]|0,(t[b+36>>2]|0)==1)Li(b),h[b+985>>0]=1,h[b+984>>0]=0;else{Qr(b),T&&x0(b,xl(b,Dl)|0,ye,hu,Sr);do if((t[b+24>>2]|0)!=1)if((b|0)==(Be|0)){t[Zt>>2]=t[2278],x[Br>>2]=S(0);break}else{ei(e,b,Sr,s,as,Sr,as,a,Dl,L);break}else M|0&&(t[M+960>>2]=b),t[b+960>>2]=0,M=b,u=(u|0)==0?b:u;while(0);El=S(x[b+504>>2]),n=S(n+S(El+S(Kt(b,Or,Sr))))}X=X+1|0}while((X|0)!=(Gl|0));for(ls=n>ye,sf=Yf&((Pn|0)==2&ls)?1:Pn,uu=(af|0)==1,ea=uu&(T^1),t2=(sf|0)==1,n2=(sf|0)==2,uf=976+(Or<<2)|0,r2=(af|2|0)==2,o2=uu&(Yf^1),Fc=1040+(Bn<<2)|0,Pc=1040+(Or<<2)|0,i2=976+(Bn<<2)|0,u2=(af|0)!=1,ls=Yf&((Pn|0)!=0&ls),os=e+976|0,uu=uu^1,n=ye,Pr=0,ss=0,El=S(0),Kf=S(0);;){e:do if(Pr>>>0>>0)for(Br=t[cs>>2]|0,X=0,Ie=S(0),ke=S(0),Ze=S(0),ye=S(0),b=0,M=0,Be=Pr;;){if(Zt=t[Br+(Be<<2)>>2]|0,(t[Zt+36>>2]|0)!=1&&(t[Zt+940>>2]=ss,(t[Zt+24>>2]|0)!=1)){if(Ye=S(Kt(Zt,Or,Sr)),pi=t[uf>>2]|0,r=S(xn(Zt+380+(pi<<3)|0,fs)),ct=S(x[Zt+504>>2]),r=S(Kp(r,ct)),r=S(xu(S(xn(Zt+364+(pi<<3)|0,fs)),r)),Yf&(X|0)!=0&S(Ye+S(ke+r))>n){a=X,Ye=Ie,Pn=Be;break e}Ye=S(Ye+r),r=S(ke+Ye),Ye=S(Ie+Ye),no(Zt)|0&&(Ze=S(Ze+S(nu(Zt))),ye=S(ye-S(ct*S(fu(Zt))))),M|0&&(t[M+960>>2]=Zt),t[Zt+960>>2]=0,X=X+1|0,M=Zt,b=(b|0)==0?Zt:b}else Ye=Ie,r=ke;if(Be=Be+1|0,Be>>>0>>0)Ie=Ye,ke=r;else{a=X,Pn=Be;break}}else a=0,Ye=S(0),Ze=S(0),ye=S(0),b=0,Pn=Pr;while(0);pi=Ze>S(0)&ZeS(0)&yebc&((Le(bc)|0)^1))n=bc,pi=51;else if(h[(t[os>>2]|0)+3>>0]|0)pi=51;else{if(gn!=S(0)&&S(nu(e))!=S(0)){pi=53;break}n=Ye,pi=53}while(0);if((pi|0)==51&&(pi=0,Le(n)|0?pi=53:(_r=S(n-Ye),kn=n)),(pi|0)==53&&(pi=0,Ye>2]|0,Be=_rS(0),ke=S(_r/gn),Ze=S(0),Ye=S(0),n=S(0),M=b;do r=S(xn(M+380+(X<<3)|0,fs)),ye=S(xn(M+364+(X<<3)|0,fs)),ye=S(Kp(r,S(xu(ye,S(x[M+504>>2]))))),Be?(r=S(ye*S(fu(M))),r!=S(-0)&&(mn=S(ye-S(ct*r)),B1=S(Kn(M,Or,mn,kn,Sr)),mn!=B1)&&(Ze=S(Ze-S(B1-ye)),n=S(n+r))):Zt&&(Bc=S(nu(M)),Bc!=S(0))&&(mn=S(ye+S(ke*Bc)),U1=S(Kn(M,Or,mn,kn,Sr)),mn!=U1)&&(Ze=S(Ze-S(U1-ye)),Ye=S(Ye-Bc)),M=t[M+960>>2]|0;while((M|0)!=0);if(n=S(Ie+n),ye=S(_r+Ze),b1)n=S(0);else{ct=S(gn+Ye),Be=t[uf>>2]|0,Zt=yeS(0),ct=S(ye/ct),n=S(0);do{mn=S(xn(b+380+(Be<<3)|0,fs)),Ze=S(xn(b+364+(Be<<3)|0,fs)),Ze=S(Kp(mn,S(xu(Ze,S(x[b+504>>2]))))),Zt?(mn=S(Ze*S(fu(b))),ye=S(-mn),mn!=S(-0)?(mn=S(ke*ye),ye=S(Kn(b,Or,S(Ze+(Br?ye:mn)),kn,Sr))):ye=Ze):X&&(j1=S(nu(b)),j1!=S(0))?ye=S(Kn(b,Or,S(Ze+S(ct*j1)),kn,Sr)):ye=Ze,n=S(n-S(ye-Ze)),Ye=S(Kt(b,Or,Sr)),r=S(Kt(b,Bn,Sr)),ye=S(ye+Ye),x[La>>2]=ye,t[lf>>2]=1,Ze=S(x[b+396>>2]);e:do if(Le(Ze)|0){M=Le(hu)|0;do if(!M){if(ls|(qu(b,Bn,hu)|0|uu)||($u(e,b)|0)!=4||(t[(g0(b,Bn)|0)+4>>2]|0)==3||(t[(_0(b,Bn)|0)+4>>2]|0)==3)break;x[ql>>2]=hu,t[Ns>>2]=1;break e}while(0);if(qu(b,Bn,hu)|0){M=t[b+992+(t[i2>>2]<<2)>>2]|0,mn=S(r+S(xn(M,hu))),x[ql>>2]=mn,M=u2&(t[M+4>>2]|0)==2,t[Ns>>2]=((Le(mn)|0|M)^1)&1;break}else{x[ql>>2]=hu,t[Ns>>2]=M?0:2;break}}else mn=S(ye-Ye),gn=S(mn/Ze),mn=S(Ze*mn),t[Ns>>2]=1,x[ql>>2]=S(r+(bu?gn:mn));while(0);Ln(b,Or,kn,Sr,lf,La),Ln(b,Bn,hu,Sr,Ns,ql);do if(!(qu(b,Bn,hu)|0)&&($u(e,b)|0)==4){if((t[(g0(b,Bn)|0)+4>>2]|0)==3){M=0;break}M=(t[(_0(b,Bn)|0)+4>>2]|0)!=3}else M=0;while(0);mn=S(x[La>>2]),gn=S(x[ql>>2]),Y1=t[lf>>2]|0,a0=t[Ns>>2]|0,Yt(b,bu?mn:gn,bu?gn:mn,Dl,bu?Y1:a0,bu?a0:Y1,Sr,as,T&(M^1),3488,L)|0,h[of>>0]=h[of>>0]|h[b+508>>0],b=t[b+960>>2]|0}while((b|0)!=0)}}else n=S(0);if(n=S(_r+n),a0=n>0]=a0|N[of>>0],n2&n>S(0)?(M=t[uf>>2]|0,(t[e+364+(M<<3)+4>>2]|0)!=0&&(Wl=S(xn(e+364+(M<<3)|0,fs)),Wl>=S(0))?ye=S(xu(S(0),S(Wl-S(kn-n)))):ye=S(0)):ye=n,Zt=Pr>>>0>>0,Zt){Be=t[cs>>2]|0,X=Pr,M=0;do b=t[Be+(X<<2)>>2]|0,t[b+24>>2]|0||(M=((t[(g0(b,Or)|0)+4>>2]|0)==3&1)+M|0,M=M+((t[(_0(b,Or)|0)+4>>2]|0)==3&1)|0),X=X+1|0;while((X|0)!=(Pn|0));M?(Ye=S(0),r=S(0)):pi=101}else pi=101;e:do if((pi|0)==101)switch(pi=0,l2|0){case 1:{M=0,Ye=S(ye*S(.5)),r=S(0);break e}case 2:{M=0,Ye=ye,r=S(0);break e}case 3:{if(a>>>0<=1){M=0,Ye=S(0),r=S(0);break e}r=S((a+-1|0)>>>0),M=0,Ye=S(0),r=S(S(xu(ye,S(0)))/r);break e}case 5:{r=S(ye/S((a+1|0)>>>0)),M=0,Ye=r;break e}case 4:{r=S(ye/S(a>>>0)),M=0,Ye=S(r*S(.5));break e}default:{M=0,Ye=S(0),r=S(0);break e}}while(0);if(n=S(s2+Ye),Zt){Ze=S(ye/S(M|0)),X=t[cs>>2]|0,b=Pr,ye=S(0);do{M=t[X+(b<<2)>>2]|0;e:do if((t[M+36>>2]|0)!=1){switch(t[M+24>>2]|0){case 1:{if(fe(M,Or)|0){if(!T)break e;mn=S(ie(M,Or,kn)),mn=S(mn+S(O0(e,Or))),mn=S(mn+S(Hi(M,Or,Sr))),x[M+400+(t[Pc>>2]<<2)>>2]=mn;break e}break}case 0:if(a0=(t[(g0(M,Or)|0)+4>>2]|0)==3,mn=S(Ze+n),n=a0?mn:n,T&&(a0=M+400+(t[Pc>>2]<<2)|0,x[a0>>2]=S(n+S(x[a0>>2]))),a0=(t[(_0(M,Or)|0)+4>>2]|0)==3,mn=S(Ze+n),n=a0?mn:n,ea){mn=S(r+S(Kt(M,Or,Sr))),ye=hu,n=S(n+S(mn+S(x[M+504>>2])));break e}else{n=S(n+S(r+S(Pe(M,Or,Sr)))),ye=S(xu(ye,S(Pe(M,Bn,Sr))));break e}default:}T&&(mn=S(Ye+S(O0(e,Or))),a0=M+400+(t[Pc>>2]<<2)|0,x[a0>>2]=S(mn+S(x[a0>>2])))}while(0);b=b+1|0}while((b|0)!=(Pn|0))}else ye=S(0);if(r=S(a2+n),r2?Ye=S(S(Kn(e,Bn,S(Vl+ye),Jf,v))-Vl):Ye=hu,Ze=S(S(Kn(e,Bn,S(Vl+(o2?hu:ye)),Jf,v))-Vl),Zt&T){b=Pr;do{X=t[(t[cs>>2]|0)+(b<<2)>>2]|0;do if((t[X+36>>2]|0)!=1){if((t[X+24>>2]|0)==1){if(fe(X,Bn)|0){if(mn=S(ie(X,Bn,hu)),mn=S(mn+S(O0(e,Bn))),mn=S(mn+S(Hi(X,Bn,Sr))),M=t[Fc>>2]|0,x[X+400+(M<<2)>>2]=mn,!(Le(mn)|0))break}else M=t[Fc>>2]|0;mn=S(O0(e,Bn)),x[X+400+(M<<2)>>2]=S(mn+S(Hi(X,Bn,Sr)));break}M=$u(e,X)|0;do if((M|0)==4){if((t[(g0(X,Bn)|0)+4>>2]|0)==3){pi=139;break}if((t[(_0(X,Bn)|0)+4>>2]|0)==3){pi=139;break}if(qu(X,Bn,hu)|0){n=Te;break}Y1=t[X+908+(t[uf>>2]<<2)>>2]|0,t[ql>>2]=Y1,n=S(x[X+396>>2]),a0=Le(n)|0,ye=(t[V>>2]=Y1,S(x[V>>2])),a0?n=Ze:(_r=S(Kt(X,Bn,Sr)),mn=S(ye/n),n=S(n*ye),n=S(_r+(bu?mn:n))),x[La>>2]=n,x[ql>>2]=S(S(Kt(X,Or,Sr))+ye),t[Ns>>2]=1,t[lf>>2]=1,Ln(X,Or,kn,Sr,Ns,ql),Ln(X,Bn,hu,Sr,lf,La),n=S(x[ql>>2]),_r=S(x[La>>2]),mn=bu?n:_r,n=bu?_r:n,a0=((Le(mn)|0)^1)&1,Yt(X,mn,n,Dl,a0,((Le(n)|0)^1)&1,Sr,as,1,3493,L)|0,n=Te}else pi=139;while(0);e:do if((pi|0)==139){pi=0,n=S(Ye-S(Pe(X,Bn,Sr)));do if((t[(g0(X,Bn)|0)+4>>2]|0)==3){if((t[(_0(X,Bn)|0)+4>>2]|0)!=3)break;n=S(Te+S(xu(S(0),S(n*S(.5)))));break e}while(0);if((t[(_0(X,Bn)|0)+4>>2]|0)==3){n=Te;break}if((t[(g0(X,Bn)|0)+4>>2]|0)==3){n=S(Te+S(xu(S(0),n)));break}switch(M|0){case 1:{n=Te;break e}case 2:{n=S(Te+S(n*S(.5)));break e}default:{n=S(Te+n);break e}}}while(0);mn=S(El+n),a0=X+400+(t[Fc>>2]<<2)|0,x[a0>>2]=S(mn+S(x[a0>>2]))}while(0);b=b+1|0}while((b|0)!=(Pn|0))}if(El=S(El+Ze),Kf=S(xu(Kf,r)),a=ss+1|0,Pn>>>0>=Gl>>>0)break;n=kn,Pr=Pn,ss=a}do if(T){if(M=a>>>0>1,!M&&!(Me(e)|0))break;if(!(Le(hu)|0)){n=S(hu-El);e:do switch(t[e+12>>2]|0){case 3:{Te=S(Te+n),ke=S(0);break}case 2:{Te=S(Te+S(n*S(.5))),ke=S(0);break}case 4:{hu>El?ke=S(n/S(a>>>0)):ke=S(0);break}case 7:if(hu>El){Te=S(Te+S(n/S(a<<1>>>0))),ke=S(n/S(a>>>0)),ke=M?ke:S(0);break e}else{Te=S(Te+S(n*S(.5))),ke=S(0);break e}case 6:{ke=S(n/S(ss>>>0)),ke=hu>El&M?ke:S(0);break}default:ke=S(0)}while(0);if(a|0)for(Zt=1040+(Bn<<2)|0,Br=976+(Bn<<2)|0,Be=0,b=0;;){e:do if(b>>>0>>0)for(ye=S(0),Ze=S(0),n=S(0),X=b;;){M=t[(t[cs>>2]|0)+(X<<2)>>2]|0;do if((t[M+36>>2]|0)!=1&&(t[M+24>>2]|0)==0){if((t[M+940>>2]|0)!=(Be|0))break e;if(at(M,Bn)|0&&(mn=S(x[M+908+(t[Br>>2]<<2)>>2]),n=S(xu(n,S(mn+S(Kt(M,Bn,Sr)))))),($u(e,M)|0)!=5)break;Wl=S(mt(M)),Wl=S(Wl+S(Hi(M,0,Sr))),mn=S(x[M+912>>2]),mn=S(S(mn+S(Kt(M,0,Sr)))-Wl),Wl=S(xu(Ze,Wl)),mn=S(xu(ye,mn)),ye=mn,Ze=Wl,n=S(xu(n,S(Wl+mn)))}while(0);if(M=X+1|0,M>>>0>>0)X=M;else{X=M;break}}else Ze=S(0),n=S(0),X=b;while(0);if(ct=S(ke+n),r=Te,Te=S(Te+ct),b>>>0>>0){Ye=S(r+Ze),M=b;do{b=t[(t[cs>>2]|0)+(M<<2)>>2]|0;e:do if((t[b+36>>2]|0)!=1&&(t[b+24>>2]|0)==0)switch($u(e,b)|0){case 1:{mn=S(r+S(Hi(b,Bn,Sr))),x[b+400+(t[Zt>>2]<<2)>>2]=mn;break e}case 3:{mn=S(S(Te-S(A0(b,Bn,Sr)))-S(x[b+908+(t[Br>>2]<<2)>>2])),x[b+400+(t[Zt>>2]<<2)>>2]=mn;break e}case 2:{mn=S(r+S(S(ct-S(x[b+908+(t[Br>>2]<<2)>>2]))*S(.5))),x[b+400+(t[Zt>>2]<<2)>>2]=mn;break e}case 4:{if(mn=S(r+S(Hi(b,Bn,Sr))),x[b+400+(t[Zt>>2]<<2)>>2]=mn,qu(b,Bn,hu)|0||(bu?(ye=S(x[b+908>>2]),n=S(ye+S(Kt(b,Or,Sr))),Ze=ct):(Ze=S(x[b+912>>2]),Ze=S(Ze+S(Kt(b,Bn,Sr))),n=ct,ye=S(x[b+908>>2])),Ci(n,ye)|0&&Ci(Ze,S(x[b+912>>2]))|0))break e;Yt(b,n,Ze,Dl,1,1,Sr,as,1,3501,L)|0;break e}case 5:{x[b+404>>2]=S(S(Ye-S(mt(b)))+S(ie(b,0,hu)));break e}default:break e}while(0);M=M+1|0}while((M|0)!=(X|0))}if(Be=Be+1|0,(Be|0)==(a|0))break;b=X}}}while(0);if(x[e+908>>2]=S(Kn(e,2,Xf,v,v)),x[e+912>>2]=S(Kn(e,0,z1,w,v)),(sf|0)!=0&&(H1=t[e+32>>2]|0,q1=(sf|0)==2,!(q1&(H1|0)!=2))?q1&(H1|0)==2&&(n=S(Qf+kn),n=S(xu(S(Kp(n,S(Qt(e,Or,Kf,fs)))),Qf)),pi=198):(n=S(Kn(e,Or,Kf,fs,v)),pi=198),(pi|0)==198&&(x[e+908+(t[976+(Or<<2)>>2]<<2)>>2]=n),(af|0)!=0&&(V1=t[e+32>>2]|0,G1=(af|0)==2,!(G1&(V1|0)!=2))?G1&(V1|0)==2&&(n=S(Vl+hu),n=S(xu(S(Kp(n,S(Qt(e,Bn,S(Vl+El),Jf)))),Vl)),pi=204):(n=S(Kn(e,Bn,S(Vl+El),Jf,v)),pi=204),(pi|0)==204&&(x[e+908+(t[976+(Bn<<2)>>2]<<2)>>2]=n),T){if((t[W1>>2]|0)==2){b=976+(Bn<<2)|0,X=1040+(Bn<<2)|0,M=0;do Be=Ti(e,M)|0,t[Be+24>>2]|0||(Y1=t[b>>2]|0,mn=S(x[e+908+(Y1<<2)>>2]),a0=Be+400+(t[X>>2]<<2)|0,mn=S(mn-S(x[a0>>2])),x[a0>>2]=S(mn-S(x[Be+908+(Y1<<2)>>2]))),M=M+1|0;while((M|0)!=(Gl|0))}if(u|0){M=bu?sf:s;do An(e,u,Sr,M,as,Dl,L),u=t[u+960>>2]|0;while((u|0)!=0)}if(M=(Or|2|0)==3,b=(Bn|2|0)==3,M|b){u=0;do X=t[(t[cs>>2]|0)+(u<<2)>>2]|0,(t[X+36>>2]|0)!=1&&(M&&Sn(e,X,Or),b&&Sn(e,X,Bn)),u=u+1|0;while((u|0)!=(Gl|0))}}}while(0);y=ff}function Qu(e,n){e=e|0,n=S(n);var r=0;Cn(e,n>=S(0),3147),r=n==S(0),x[e+4>>2]=r?S(0):n}function $r(e,n,r,u){e=e|0,n=S(n),r=S(r),u=u|0;var s=Ct,a=Ct,v=0,w=0,T=0;t[2278]=(t[2278]|0)+1,Qr(e),qu(e,2,n)|0?(s=S(xn(t[e+992>>2]|0,n)),T=1,s=S(s+S(Kt(e,2,n)))):(s=S(xn(e+380|0,n)),s>=S(0)?T=2:(T=((Le(n)|0)^1)&1,s=n)),qu(e,0,r)|0?(a=S(xn(t[e+996>>2]|0,r)),w=1,a=S(a+S(Kt(e,0,n)))):(a=S(xn(e+388|0,r)),a>=S(0)?w=2:(w=((Le(r)|0)^1)&1,a=r)),v=e+976|0,Yt(e,s,a,u,T,w,n,r,1,3189,t[v>>2]|0)|0&&(x0(e,t[e+496>>2]|0,n,r,n),Lu(e,S(x[(t[v>>2]|0)+4>>2]),S(0),S(0)),h[11696]|0)&&mf(e,7)}function Qr(e){e=e|0;var n=0,r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0;w=y,y=y+32|0,v=w+24|0,a=w+16|0,u=w+8|0,s=w,r=0;do n=e+380+(r<<3)|0,(t[e+380+(r<<3)+4>>2]|0)!=0&&(T=n,L=t[T+4>>2]|0,M=u,t[M>>2]=t[T>>2],t[M+4>>2]=L,M=e+364+(r<<3)|0,L=t[M+4>>2]|0,T=s,t[T>>2]=t[M>>2],t[T+4>>2]=L,t[a>>2]=t[u>>2],t[a+4>>2]=t[u+4>>2],t[v>>2]=t[s>>2],t[v+4>>2]=t[s+4>>2],Bi(a,v)|0)||(n=e+348+(r<<3)|0),t[e+992+(r<<2)>>2]=n,r=r+1|0;while((r|0)!=2);y=w}function qu(e,n,r){e=e|0,n=n|0,r=S(r);var u=0;switch(e=t[e+992+(t[976+(n<<2)>>2]<<2)>>2]|0,t[e+4>>2]|0){case 0:case 3:{e=0;break}case 1:{S(x[e>>2])>2])>2]|0){case 2:{n=S(S(S(x[e>>2])*n)/S(100));break}case 1:{n=S(x[e>>2]);break}default:n=S(ue)}return S(n)}function x0(e,n,r,u,s){e=e|0,n=n|0,r=S(r),u=S(u),s=S(s);var a=0,v=Ct;n=t[e+944>>2]|0?n:1,a=B0(t[e+4>>2]|0,n)|0,n=gf(a,n)|0,r=S(Ar(e,a,r)),u=S(Ar(e,n,u)),v=S(r+S(Hi(e,a,s))),x[e+400+(t[1040+(a<<2)>>2]<<2)>>2]=v,r=S(r+S(A0(e,a,s))),x[e+400+(t[1e3+(a<<2)>>2]<<2)>>2]=r,r=S(u+S(Hi(e,n,s))),x[e+400+(t[1040+(n<<2)>>2]<<2)>>2]=r,s=S(u+S(A0(e,n,s))),x[e+400+(t[1e3+(n<<2)>>2]<<2)>>2]=s}function Lu(e,n,r,u){e=e|0,n=S(n),r=S(r),u=S(u);var s=0,a=0,v=Ct,w=Ct,T=0,L=0,M=Ct,b=0,X=Ct,Be=Ct,Te=Ct,ye=Ct;if(n!=S(0)&&(s=e+400|0,ye=S(x[s>>2]),a=e+404|0,Te=S(x[a>>2]),b=e+416|0,Be=S(x[b>>2]),L=e+420|0,v=S(x[L>>2]),X=S(ye+r),M=S(Te+u),u=S(X+Be),w=S(M+v),T=(t[e+988>>2]|0)==1,x[s>>2]=S(eo(ye,n,0,T)),x[a>>2]=S(eo(Te,n,0,T)),r=S(NE(S(Be*n),S(1))),Ci(r,S(0))|0?a=0:a=(Ci(r,S(1))|0)^1,r=S(NE(S(v*n),S(1))),Ci(r,S(0))|0?s=0:s=(Ci(r,S(1))|0)^1,ye=S(eo(u,n,T&a,T&(a^1))),x[b>>2]=S(ye-S(eo(X,n,0,T))),ye=S(eo(w,n,T&s,T&(s^1))),x[L>>2]=S(ye-S(eo(M,n,0,T))),a=(t[e+952>>2]|0)-(t[e+948>>2]|0)>>2,a|0)){s=0;do Lu(Ti(e,s)|0,n,X,M),s=s+1|0;while((s|0)!=(a|0))}}function ui(e,n,r,u,s){switch(e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,r|0){case 5:case 0:{e=v8(t[489]|0,u,s)|0;break}default:e=FL(u,s)|0}return e|0}function Cl(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0;s=y,y=y+16|0,a=s,t[a>>2]=u,zs(e,0,n,r,a),y=s}function zs(e,n,r,u,s){if(e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,e=e|0?e:956,I8[t[e+8>>2]&1](e,n,r,u,s)|0,(r|0)==5)$n();else return}function Wu(e,n,r){e=e|0,n=n|0,r=r|0,h[e+n>>0]=r&1}function sa(e,n){e=e|0,n=n|0;var r=0,u=0;t[e>>2]=0,t[e+4>>2]=0,t[e+8>>2]=0,r=n+4|0,u=(t[r>>2]|0)-(t[n>>2]|0)>>2,u|0&&(Xi(e,u),Hs(e,t[n>>2]|0,t[r>>2]|0,u))}function Xi(e,n){e=e|0,n=n|0;var r=0;if((R0(e)|0)>>>0>>0&&di(e),n>>>0>1073741823)$n();else{r=pn(n<<2)|0,t[e+4>>2]=r,t[e>>2]=r,t[e+8>>2]=r+(n<<2);return}}function Hs(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0,u=e+4|0,e=r-n|0,(e|0)>0&&(gr(t[u>>2]|0,n|0,e|0)|0,t[u>>2]=(t[u>>2]|0)+(e>>>2<<2))}function R0(e){return e=e|0,1073741823}function Hi(e,n,r){return e=e|0,n=n|0,r=S(r),qi(n)|0&&(t[e+96>>2]|0)!=0?e=e+92|0:e=pt(e+60|0,t[1040+(n<<2)>>2]|0,992)|0,S(il(e,r))}function A0(e,n,r){return e=e|0,n=n|0,r=S(r),qi(n)|0&&(t[e+104>>2]|0)!=0?e=e+100|0:e=pt(e+60|0,t[1e3+(n<<2)>>2]|0,992)|0,S(il(e,r))}function qi(e){return e=e|0,(e|1|0)==3|0}function il(e,n){return e=e|0,n=S(n),(t[e+4>>2]|0)==3?n=S(0):n=S(xn(e,n)),S(n)}function xl(e,n){return e=e|0,n=n|0,e=t[e>>2]|0,((e|0)==0?(n|0)>1?n:1:e)|0}function B0(e,n){e=e|0,n=n|0;var r=0;e:do if((n|0)==2){switch(e|0){case 2:{e=3;break e}case 3:break;default:{r=4;break e}}e=2}else r=4;while(0);return e|0}function O0(e,n){e=e|0,n=n|0;var r=Ct;return qi(n)|0&&(t[e+312>>2]|0)!=0&&(r=S(x[e+308>>2]),r>=S(0))||(r=S(xu(S(x[(pt(e+276|0,t[1040+(n<<2)>>2]|0,992)|0)>>2]),S(0)))),S(r)}function vo(e,n){e=e|0,n=n|0;var r=Ct;return qi(n)|0&&(t[e+320>>2]|0)!=0&&(r=S(x[e+316>>2]),r>=S(0))||(r=S(xu(S(x[(pt(e+276|0,t[1e3+(n<<2)>>2]|0,992)|0)>>2]),S(0)))),S(r)}function Fu(e,n,r){e=e|0,n=n|0,r=S(r);var u=Ct;return qi(n)|0&&(t[e+240>>2]|0)!=0&&(u=S(xn(e+236|0,r)),u>=S(0))||(u=S(xu(S(xn(pt(e+204|0,t[1040+(n<<2)>>2]|0,992)|0,r)),S(0)))),S(u)}function Ju(e,n,r){e=e|0,n=n|0,r=S(r);var u=Ct;return qi(n)|0&&(t[e+248>>2]|0)!=0&&(u=S(xn(e+244|0,r)),u>=S(0))||(u=S(xu(S(xn(pt(e+204|0,t[1e3+(n<<2)>>2]|0,992)|0,r)),S(0)))),S(u)}function es(e,n,r,u,s,a,v){e=e|0,n=S(n),r=S(r),u=u|0,s=s|0,a=S(a),v=S(v);var w=Ct,T=Ct,L=Ct,M=Ct,b=Ct,X=Ct,Be=0,Te=0,ye=0;ye=y,y=y+16|0,Be=ye,Te=e+964|0,Hu(e,(t[Te>>2]|0)!=0,3519),w=S(Rr(e,2,n)),T=S(Rr(e,0,n)),L=S(Kt(e,2,n)),M=S(Kt(e,0,n)),Le(n)|0?b=n:b=S(xu(S(0),S(S(n-L)-w))),Le(r)|0?X=r:X=S(xu(S(0),S(S(r-M)-T))),(u|0)==1&(s|0)==1?(x[e+908>>2]=S(Kn(e,2,S(n-L),a,a)),n=S(Kn(e,0,S(r-M),v,a))):(b8[t[Te>>2]&1](Be,e,b,u,X,s),b=S(w+S(x[Be>>2])),X=S(n-L),x[e+908>>2]=S(Kn(e,2,(u|2|0)==2?b:X,a,a)),X=S(T+S(x[Be+4>>2])),n=S(r-M),n=S(Kn(e,0,(s|2|0)==2?X:n,v,a))),x[e+912>>2]=n,y=ye}function _s(e,n,r,u,s,a,v){e=e|0,n=S(n),r=S(r),u=u|0,s=s|0,a=S(a),v=S(v);var w=Ct,T=Ct,L=Ct,M=Ct;L=S(Rr(e,2,a)),w=S(Rr(e,0,a)),M=S(Kt(e,2,a)),T=S(Kt(e,0,a)),n=S(n-M),x[e+908>>2]=S(Kn(e,2,(u|2|0)==2?L:n,a,a)),r=S(r-T),x[e+912>>2]=S(Kn(e,0,(s|2|0)==2?w:r,v,a))}function aa(e,n,r,u,s,a,v){e=e|0,n=S(n),r=S(r),u=u|0,s=s|0,a=S(a),v=S(v);var w=0,T=Ct,L=Ct;return w=(u|0)==2,!(n<=S(0)&w)&&!(r<=S(0)&(s|0)==2)&&!((u|0)==1&(s|0)==1)?e=0:(T=S(Kt(e,0,a)),L=S(Kt(e,2,a)),w=n>2]=S(Kn(e,2,w?S(0):n,a,a)),n=S(r-T),w=r>2]=S(Kn(e,0,w?S(0):n,v,a)),e=1),e|0}function gf(e,n){return e=e|0,n=n|0,_n(e)|0?e=B0(2,n)|0:e=0,e|0}function Zu(e,n,r){return e=e|0,n=n|0,r=S(r),r=S(Fu(e,n,r)),S(r+S(O0(e,n)))}function Es(e,n,r){return e=e|0,n=n|0,r=S(r),r=S(Ju(e,n,r)),S(r+S(vo(e,n)))}function Rr(e,n,r){e=e|0,n=n|0,r=S(r);var u=Ct;return u=S(Zu(e,n,r)),S(u+S(Es(e,n,r)))}function no(e){return e=e|0,t[e+24>>2]|0?e=0:S(nu(e))!=S(0)?e=1:e=S(fu(e))!=S(0),e|0}function nu(e){e=e|0;var n=Ct;if(t[e+944>>2]|0){if(n=S(x[e+44>>2]),Le(n)|0)return n=S(x[e+40>>2]),e=n>S(0)&((Le(n)|0)^1),S(e?n:S(0))}else n=S(0);return S(n)}function fu(e){e=e|0;var n=Ct,r=0,u=Ct;do if(t[e+944>>2]|0){if(n=S(x[e+48>>2]),Le(n)|0){if(r=h[(t[e+976>>2]|0)+2>>0]|0,r<<24>>24==0&&(u=S(x[e+40>>2]),u>24?S(1):S(0)}}else n=S(0);while(0);return S(n)}function Li(e){e=e|0;var n=0,r=0;if(jv(e+400|0,0,540)|0,h[e+985>>0]=1,ms(e),r=wu(e)|0,r|0){n=e+948|0,e=0;do Li(t[(t[n>>2]|0)+(e<<2)>>2]|0),e=e+1|0;while((e|0)!=(r|0))}}function ei(e,n,r,u,s,a,v,w,T,L){e=e|0,n=n|0,r=S(r),u=u|0,s=S(s),a=S(a),v=S(v),w=w|0,T=T|0,L=L|0;var M=0,b=Ct,X=0,Be=0,Te=Ct,ye=Ct,Ze=0,Ye=Ct,ct=0,ke=Ct,Ie=0,Zt=0,Br=0,Pn=0,gn=0,_r=0,Pr=0,kn=0,uu=0,os=0;uu=y,y=y+16|0,Br=uu+12|0,Pn=uu+8|0,gn=uu+4|0,_r=uu,kn=B0(t[e+4>>2]|0,T)|0,Ie=qi(kn)|0,b=S(xn(Tn(n)|0,Ie?a:v)),Zt=qu(n,2,a)|0,Pr=qu(n,0,v)|0;do if(!(Le(b)|0)&&!(Le(Ie?r:s)|0)){if(M=n+504|0,!(Le(S(x[M>>2]))|0)&&(!(ir(t[n+976>>2]|0,0)|0)||(t[n+500>>2]|0)==(t[2278]|0)))break;x[M>>2]=S(xu(b,S(Rr(n,kn,a))))}else X=7;while(0);do if((X|0)==7){if(ct=Ie^1,!(ct|Zt^1)){v=S(xn(t[n+992>>2]|0,a)),x[n+504>>2]=S(xu(v,S(Rr(n,2,a))));break}if(!(Ie|Pr^1)){v=S(xn(t[n+996>>2]|0,v)),x[n+504>>2]=S(xu(v,S(Rr(n,0,a))));break}x[Br>>2]=S(ue),x[Pn>>2]=S(ue),t[gn>>2]=0,t[_r>>2]=0,Ye=S(Kt(n,2,a)),ke=S(Kt(n,0,a)),Zt?(Te=S(Ye+S(xn(t[n+992>>2]|0,a))),x[Br>>2]=Te,t[gn>>2]=1,Be=1):(Be=0,Te=S(ue)),Pr?(b=S(ke+S(xn(t[n+996>>2]|0,v))),x[Pn>>2]=b,t[_r>>2]=1,M=1):(M=0,b=S(ue)),X=t[e+32>>2]|0,Ie&(X|0)==2?X=2:Le(Te)|0&&!(Le(r)|0)&&(x[Br>>2]=r,t[gn>>2]=2,Be=2,Te=r),!((X|0)==2&ct)&&Le(b)|0&&!(Le(s)|0)&&(x[Pn>>2]=s,t[_r>>2]=2,M=2,b=s),ye=S(x[n+396>>2]),Ze=Le(ye)|0;do if(Ze)X=Be;else{if((Be|0)==1&ct){x[Pn>>2]=S(S(Te-Ye)/ye),t[_r>>2]=1,M=1,X=1;break}Ie&(M|0)==1?(x[Br>>2]=S(ye*S(b-ke)),t[gn>>2]=1,M=1,X=1):X=Be}while(0);os=Le(r)|0,Be=($u(e,n)|0)!=4,!(Ie|Zt|((u|0)!=1|os)|(Be|(X|0)==1))&&(x[Br>>2]=r,t[gn>>2]=1,!Ze)&&(x[Pn>>2]=S(S(r-Ye)/ye),t[_r>>2]=1,M=1),!(Pr|ct|((w|0)!=1|(Le(s)|0))|(Be|(M|0)==1))&&(x[Pn>>2]=s,t[_r>>2]=1,!Ze)&&(x[Br>>2]=S(ye*S(s-ke)),t[gn>>2]=1),Ln(n,2,a,a,gn,Br),Ln(n,0,v,a,_r,Pn),r=S(x[Br>>2]),s=S(x[Pn>>2]),Yt(n,r,s,T,t[gn>>2]|0,t[_r>>2]|0,a,v,0,3565,L)|0,v=S(x[n+908+(t[976+(kn<<2)>>2]<<2)>>2]),x[n+504>>2]=S(xu(v,S(Rr(n,kn,a))))}while(0);t[n+500>>2]=t[2278],y=uu}function Kn(e,n,r,u,s){return e=e|0,n=n|0,r=S(r),u=S(u),s=S(s),u=S(Qt(e,n,r,u)),S(xu(u,S(Rr(e,n,s))))}function $u(e,n){return e=e|0,n=n|0,n=n+20|0,n=t[((t[n>>2]|0)==0?e+16|0:n)>>2]|0,(n|0)==5&&_n(t[e+4>>2]|0)|0&&(n=1),n|0}function g0(e,n){return e=e|0,n=n|0,qi(n)|0&&(t[e+96>>2]|0)!=0?n=4:n=t[1040+(n<<2)>>2]|0,e+60+(n<<3)|0}function _0(e,n){return e=e|0,n=n|0,qi(n)|0&&(t[e+104>>2]|0)!=0?n=5:n=t[1e3+(n<<2)>>2]|0,e+60+(n<<3)|0}function Ln(e,n,r,u,s,a){switch(e=e|0,n=n|0,r=S(r),u=S(u),s=s|0,a=a|0,r=S(xn(e+380+(t[976+(n<<2)>>2]<<3)|0,r)),r=S(r+S(Kt(e,n,u))),t[s>>2]|0){case 2:case 1:{s=Le(r)|0,u=S(x[a>>2]),x[a>>2]=s|u>2]=2,x[a>>2]=r);break}default:}}function fe(e,n){return e=e|0,n=n|0,e=e+132|0,qi(n)|0&&(t[(pt(e,4,948)|0)+4>>2]|0)!=0?e=1:e=(t[(pt(e,t[1040+(n<<2)>>2]|0,948)|0)+4>>2]|0)!=0,e|0}function ie(e,n,r){e=e|0,n=n|0,r=S(r);var u=0,s=0;return e=e+132|0,qi(n)|0&&(u=pt(e,4,948)|0,(t[u+4>>2]|0)!=0)?s=4:(u=pt(e,t[1040+(n<<2)>>2]|0,948)|0,t[u+4>>2]|0?s=4:r=S(0)),(s|0)==4&&(r=S(xn(u,r))),S(r)}function Pe(e,n,r){e=e|0,n=n|0,r=S(r);var u=Ct;return u=S(x[e+908+(t[976+(n<<2)>>2]<<2)>>2]),u=S(u+S(Hi(e,n,r))),S(u+S(A0(e,n,r)))}function Me(e){e=e|0;var n=0,r=0,u=0;e:do if(_n(t[e+4>>2]|0)|0)n=0;else if((t[e+16>>2]|0)!=5)if(r=wu(e)|0,!r)n=0;else for(n=0;;){if(u=Ti(e,n)|0,(t[u+24>>2]|0)==0&&(t[u+20>>2]|0)==5){n=1;break e}if(n=n+1|0,n>>>0>=r>>>0){n=0;break}}else n=1;while(0);return n|0}function at(e,n){e=e|0,n=n|0;var r=Ct;return r=S(x[e+908+(t[976+(n<<2)>>2]<<2)>>2]),r>=S(0)&((Le(r)|0)^1)|0}function mt(e){e=e|0;var n=Ct,r=0,u=0,s=0,a=0,v=0,w=0,T=Ct;if(r=t[e+968>>2]|0,r)T=S(x[e+908>>2]),n=S(x[e+912>>2]),n=S(N8[r&0](e,T,n)),Hu(e,(Le(n)|0)^1,3573);else{a=wu(e)|0;do if(a|0){for(r=0,s=0;;){if(u=Ti(e,s)|0,t[u+940>>2]|0){v=8;break}if((t[u+24>>2]|0)!=1)if(w=($u(e,u)|0)==5,w){r=u;break}else r=(r|0)==0?u:r;if(s=s+1|0,s>>>0>=a>>>0){v=8;break}}if((v|0)==8&&!r)break;return n=S(mt(r)),S(n+S(x[r+404>>2]))}while(0);n=S(x[e+912>>2])}return S(n)}function Qt(e,n,r,u){e=e|0,n=n|0,r=S(r),u=S(u);var s=Ct,a=0;return _n(n)|0?(n=1,a=3):qi(n)|0?(n=0,a=3):(u=S(ue),s=S(ue)),(a|0)==3&&(s=S(xn(e+364+(n<<3)|0,u)),u=S(xn(e+380+(n<<3)|0,u))),a=u=S(0)&((Le(u)|0)^1)),r=a?u:r,a=s>=S(0)&((Le(s)|0)^1)&r>2]|0,a)|0,Te=gf(Ze,a)|0,ye=qi(Ze)|0,b=S(Kt(n,2,r)),X=S(Kt(n,0,r)),qu(n,2,r)|0?w=S(b+S(xn(t[n+992>>2]|0,r))):fe(n,2)|0&&Ut(n,2)|0?(w=S(x[e+908>>2]),T=S(O0(e,2)),T=S(w-S(T+S(vo(e,2)))),w=S(ie(n,2,r)),w=S(Kn(n,2,S(T-S(w+S(Fi(n,2,r)))),r,r))):w=S(ue),qu(n,0,s)|0?T=S(X+S(xn(t[n+996>>2]|0,s))):fe(n,0)|0&&Ut(n,0)|0?(T=S(x[e+912>>2]),ct=S(O0(e,0)),ct=S(T-S(ct+S(vo(e,0)))),T=S(ie(n,0,s)),T=S(Kn(n,0,S(ct-S(T+S(Fi(n,0,s)))),s,r))):T=S(ue),L=Le(w)|0,M=Le(T)|0;do if(L^M&&(Be=S(x[n+396>>2]),!(Le(Be)|0)))if(L){w=S(b+S(S(T-X)*Be));break}else{ct=S(X+S(S(w-b)/Be)),T=M?ct:T;break}while(0);M=Le(w)|0,L=Le(T)|0,M|L&&(ke=(M^1)&1,u=r>S(0)&((u|0)!=0&M),w=ye?w:u?r:w,Yt(n,w,T,a,ye?ke:u?2:ke,M&(L^1)&1,w,T,0,3623,v)|0,w=S(x[n+908>>2]),w=S(w+S(Kt(n,2,r))),T=S(x[n+912>>2]),T=S(T+S(Kt(n,0,r)))),Yt(n,w,T,a,1,1,w,T,1,3635,v)|0,Ut(n,Ze)|0&&!(fe(n,Ze)|0)?(ke=t[976+(Ze<<2)>>2]|0,ct=S(x[e+908+(ke<<2)>>2]),ct=S(ct-S(x[n+908+(ke<<2)>>2])),ct=S(ct-S(vo(e,Ze))),ct=S(ct-S(A0(n,Ze,r))),ct=S(ct-S(Fi(n,Ze,ye?r:s))),x[n+400+(t[1040+(Ze<<2)>>2]<<2)>>2]=ct):Ye=21;do if((Ye|0)==21){if(!(fe(n,Ze)|0)&&(t[e+8>>2]|0)==1){ke=t[976+(Ze<<2)>>2]|0,ct=S(x[e+908+(ke<<2)>>2]),ct=S(S(ct-S(x[n+908+(ke<<2)>>2]))*S(.5)),x[n+400+(t[1040+(Ze<<2)>>2]<<2)>>2]=ct;break}!(fe(n,Ze)|0)&&(t[e+8>>2]|0)==2&&(ke=t[976+(Ze<<2)>>2]|0,ct=S(x[e+908+(ke<<2)>>2]),ct=S(ct-S(x[n+908+(ke<<2)>>2])),x[n+400+(t[1040+(Ze<<2)>>2]<<2)>>2]=ct)}while(0);Ut(n,Te)|0&&!(fe(n,Te)|0)?(ke=t[976+(Te<<2)>>2]|0,ct=S(x[e+908+(ke<<2)>>2]),ct=S(ct-S(x[n+908+(ke<<2)>>2])),ct=S(ct-S(vo(e,Te))),ct=S(ct-S(A0(n,Te,r))),ct=S(ct-S(Fi(n,Te,ye?s:r))),x[n+400+(t[1040+(Te<<2)>>2]<<2)>>2]=ct):Ye=30;do if((Ye|0)==30&&!(fe(n,Te)|0)){if(($u(e,n)|0)==2){ke=t[976+(Te<<2)>>2]|0,ct=S(x[e+908+(ke<<2)>>2]),ct=S(S(ct-S(x[n+908+(ke<<2)>>2]))*S(.5)),x[n+400+(t[1040+(Te<<2)>>2]<<2)>>2]=ct;break}ke=($u(e,n)|0)==3,ke^(t[e+28>>2]|0)==2&&(ke=t[976+(Te<<2)>>2]|0,ct=S(x[e+908+(ke<<2)>>2]),ct=S(ct-S(x[n+908+(ke<<2)>>2])),x[n+400+(t[1040+(Te<<2)>>2]<<2)>>2]=ct)}while(0)}function Sn(e,n,r){e=e|0,n=n|0,r=r|0;var u=Ct,s=0;s=t[976+(r<<2)>>2]|0,u=S(x[n+908+(s<<2)>>2]),u=S(S(x[e+908+(s<<2)>>2])-u),u=S(u-S(x[n+400+(t[1040+(r<<2)>>2]<<2)>>2])),x[n+400+(t[1e3+(r<<2)>>2]<<2)>>2]=u}function _n(e){return e=e|0,(e|1|0)==1|0}function Tn(e){e=e|0;var n=Ct;switch(t[e+56>>2]|0){case 0:case 3:{n=S(x[e+40>>2]),n>S(0)&((Le(n)|0)^1)?e=h[(t[e+976>>2]|0)+2>>0]|0?1056:992:e=1056;break}default:e=e+52|0}return e|0}function ir(e,n){return e=e|0,n=n|0,(h[e+n>>0]|0)!=0|0}function Ut(e,n){return e=e|0,n=n|0,e=e+132|0,qi(n)|0&&(t[(pt(e,5,948)|0)+4>>2]|0)!=0?e=1:e=(t[(pt(e,t[1e3+(n<<2)>>2]|0,948)|0)+4>>2]|0)!=0,e|0}function Fi(e,n,r){e=e|0,n=n|0,r=S(r);var u=0,s=0;return e=e+132|0,qi(n)|0&&(u=pt(e,5,948)|0,(t[u+4>>2]|0)!=0)?s=4:(u=pt(e,t[1e3+(n<<2)>>2]|0,948)|0,t[u+4>>2]|0?s=4:r=S(0)),(s|0)==4&&(r=S(xn(u,r))),S(r)}function Ar(e,n,r){return e=e|0,n=n|0,r=S(r),fe(e,n)|0?r=S(ie(e,n,r)):r=S(-S(Fi(e,n,r))),S(r)}function mr(e){return e=S(e),x[V>>2]=e,t[V>>2]|0|0}function K(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>1073741823)$n();else{s=pn(n<<2)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r<<2)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n<<2)}function ti(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(0-(s>>2)<<2)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function ni(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~((u+-4-n|0)>>>2)<<2)),e=t[e>>2]|0,e|0&&Et(e)}function Wr(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0;if(v=e+4|0,w=t[v>>2]|0,s=w-u|0,a=s>>2,e=n+(a<<2)|0,e>>>0>>0){u=w;do t[u>>2]=t[e>>2],e=e+4|0,u=(t[v>>2]|0)+4|0,t[v>>2]=u;while(e>>>0>>0)}a|0&&ky(w+(0-a<<2)|0,n|0,s|0)|0}function ft(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0;return w=n+4|0,T=t[w>>2]|0,s=t[e>>2]|0,v=r,a=v-s|0,u=T+(0-(a>>2)<<2)|0,t[w>>2]=u,(a|0)>0&&gr(u|0,s|0,a|0)|0,s=e+4|0,a=n+8|0,u=(t[s>>2]|0)-v|0,(u|0)>0&&(gr(t[a>>2]|0,r|0,u|0)|0,t[a>>2]=(t[a>>2]|0)+(u>>>2<<2)),v=t[e>>2]|0,t[e>>2]=t[w>>2],t[w>>2]=v,v=t[s>>2]|0,t[s>>2]=t[a>>2],t[a>>2]=v,v=e+8|0,r=n+12|0,e=t[v>>2]|0,t[v>>2]=t[r>>2],t[r>>2]=e,t[n>>2]=t[w>>2],T|0}function Di(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;if(v=t[n>>2]|0,a=t[r>>2]|0,(v|0)!=(a|0)){s=e+8|0,r=((a+-4-v|0)>>>2)+1|0,e=v,u=t[s>>2]|0;do t[u>>2]=t[e>>2],u=(t[s>>2]|0)+4|0,t[s>>2]=u,e=e+4|0;while((e|0)!=(a|0));t[n>>2]=v+(r<<2)}}function ru(){Se()}function E0(){var e=0;return e=pn(4)|0,Un(e),e|0}function Un(e){e=e|0,t[e>>2]=v0()|0}function e0(e){e=e|0,e|0&&(ro(e),Et(e))}function ro(e){e=e|0,J0(t[e>>2]|0)}function mo(e,n,r){e=e|0,n=n|0,r=r|0,Wu(t[e>>2]|0,n,r)}function t0(e,n){e=e|0,n=S(n),Qu(t[e>>2]|0,n)}function jo(e,n){return e=e|0,n=n|0,ir(t[e>>2]|0,n)|0}function io(){var e=0;return e=pn(8)|0,Ba(e,0),e|0}function Ba(e,n){e=e|0,n=n|0,n?n=Yn(t[n>>2]|0)|0:n=cr()|0,t[e>>2]=n,t[e+4>>2]=0,ba(n,e)}function _f(e){e=e|0;var n=0;return n=pn(8)|0,Ba(n,e),n|0}function fc(e){e=e|0,e|0&&(Ds(e),Et(e))}function Ds(e){e=e|0;var n=0;ju(t[e>>2]|0),n=e+4|0,e=t[n>>2]|0,t[n>>2]=0,e|0&&(fa(e),Et(e))}function fa(e){e=e|0,U0(e)}function U0(e){e=e|0,e=t[e>>2]|0,e|0&&qr(e|0)}function cc(e){return e=e|0,Bs(e)|0}function Ua(e){e=e|0;var n=0,r=0;r=e+4|0,n=t[r>>2]|0,t[r>>2]=0,n|0&&(fa(n),Et(n)),po(t[e>>2]|0)}function _2(e,n){e=e|0,n=n|0,oa(t[e>>2]|0,t[n>>2]|0)}function nd(e,n){e=e|0,n=n|0,$(t[e>>2]|0,n)}function rd(e,n,r){e=e|0,n=n|0,r=+r,dr(t[e>>2]|0,n,S(r))}function yo(e,n,r){e=e|0,n=n|0,r=+r,er(t[e>>2]|0,n,S(r))}function qc(e,n){e=e|0,n=n|0,H(t[e>>2]|0,n)}function Rl(e,n){e=e|0,n=n|0,ee(t[e>>2]|0,n)}function ul(e,n){e=e|0,n=n|0,_e(t[e>>2]|0,n)}function E2(e,n){e=e|0,n=n|0,m0(t[e>>2]|0,n)}function qs(e,n){e=e|0,n=n|0,Je(t[e>>2]|0,n)}function Al(e,n){e=e|0,n=n|0,zi(t[e>>2]|0,n)}function id(e,n,r){e=e|0,n=n|0,r=+r,Rn(t[e>>2]|0,n,S(r))}function zo(e,n,r){e=e|0,n=n|0,r=+r,Nr(t[e>>2]|0,n,S(r))}function ja(e,n){e=e|0,n=n|0,Lr(t[e>>2]|0,n)}function za(e,n){e=e|0,n=n|0,oe(t[e>>2]|0,n)}function Ha(e,n){e=e|0,n=n|0,rt(t[e>>2]|0,n)}function ca(e,n){e=e|0,n=+n,kt(t[e>>2]|0,S(n))}function ws(e,n){e=e|0,n=+n,rn(t[e>>2]|0,S(n))}function Ss(e,n){e=e|0,n=+n,Ft(t[e>>2]|0,S(n))}function ts(e,n){e=e|0,n=+n,bt(t[e>>2]|0,S(n))}function Ho(e,n){e=e|0,n=+n,sn(t[e>>2]|0,S(n))}function Ef(e,n){e=e|0,n=+n,fn(t[e>>2]|0,S(n))}function ol(e,n){e=e|0,n=+n,Jn(t[e>>2]|0,S(n))}function Vu(e){e=e|0,wr(t[e>>2]|0)}function qa(e,n){e=e|0,n=+n,ku(t[e>>2]|0,S(n))}function n0(e,n){e=e|0,n=+n,T0(t[e>>2]|0,S(n))}function j0(e){e=e|0,Z0(t[e>>2]|0)}function Df(e,n){e=e|0,n=+n,gi(t[e>>2]|0,S(n))}function Wc(e,n){e=e|0,n=+n,Po(t[e>>2]|0,S(n))}function dc(e,n){e=e|0,n=+n,hf(t[e>>2]|0,S(n))}function Ol(e,n){e=e|0,n=+n,Tl(t[e>>2]|0,S(n))}function Ts(e,n){e=e|0,n=+n,Io(t[e>>2]|0,S(n))}function da(e,n){e=e|0,n=+n,ys(t[e>>2]|0,S(n))}function ud(e,n){e=e|0,n=+n,bo(t[e>>2]|0,S(n))}function pa(e,n){e=e|0,n=+n,Bo(t[e>>2]|0,S(n))}function pc(e,n){e=e|0,n=+n,Xu(t[e>>2]|0,S(n))}function Vc(e,n,r){e=e|0,n=n|0,r=+r,It(t[e>>2]|0,n,S(r))}function Wi(e,n,r){e=e|0,n=n|0,r=+r,ut(t[e>>2]|0,n,S(r))}function _(e,n,r){e=e|0,n=n|0,r=+r,wt(t[e>>2]|0,n,S(r))}function g(e){return e=e|0,Ne(t[e>>2]|0)|0}function A(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0;u=y,y=y+16|0,s=u,Cr(s,t[n>>2]|0,r),P(e,s),y=u}function P(e,n){e=e|0,n=n|0,B(e,t[n+4>>2]|0,+S(x[n>>2]))}function B(e,n,r){e=e|0,n=n|0,r=+r,t[e>>2]=n,j[e+8>>3]=r}function Z(e){return e=e|0,Y(t[e>>2]|0)|0}function de(e){return e=e|0,Ce(t[e>>2]|0)|0}function yt(e){return e=e|0,Oe(t[e>>2]|0)|0}function Rt(e){return e=e|0,Us(t[e>>2]|0)|0}function Nt(e){return e=e|0,vt(t[e>>2]|0)|0}function xr(e){return e=e|0,U(t[e>>2]|0)|0}function r0(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0;u=y,y=y+16|0,s=u,y0(s,t[n>>2]|0,r),P(e,s),y=u}function cu(e){return e=e|0,qe(t[e>>2]|0)|0}function z0(e){return e=e|0,xt(t[e>>2]|0)|0}function Ml(e,n){e=e|0,n=n|0;var r=0,u=0;r=y,y=y+16|0,u=r,Dn(u,t[n>>2]|0),P(e,u),y=r}function i0(e){return e=e|0,+ +S(pf(t[e>>2]|0))}function Ge(e){return e=e|0,+ +S(bs(t[e>>2]|0))}function je(e,n){e=e|0,n=n|0;var r=0,u=0;r=y,y=y+16|0,u=r,au(u,t[n>>2]|0),P(e,u),y=r}function st(e,n){e=e|0,n=n|0;var r=0,u=0;r=y,y=y+16|0,u=r,Nu(u,t[n>>2]|0),P(e,u),y=r}function $t(e,n){e=e|0,n=n|0;var r=0,u=0;r=y,y=y+16|0,u=r,rl(u,t[n>>2]|0),P(e,u),y=r}function Wn(e,n){e=e|0,n=n|0;var r=0,u=0;r=y,y=y+16|0,u=r,vf(u,t[n>>2]|0),P(e,u),y=r}function oi(e,n){e=e|0,n=n|0;var r=0,u=0;r=y,y=y+16|0,u=r,js(u,t[n>>2]|0),P(e,u),y=r}function ur(e,n){e=e|0,n=n|0;var r=0,u=0;r=y,y=y+16|0,u=r,gs(u,t[n>>2]|0),P(e,u),y=r}function ai(e){return e=e|0,+ +S(Su(t[e>>2]|0))}function Qi(e,n){return e=e|0,n=n|0,+ +S(un(t[e>>2]|0,n))}function Vr(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0;u=y,y=y+16|0,s=u,et(s,t[n>>2]|0,r),P(e,s),y=u}function Tu(e,n,r){e=e|0,n=n|0,r=r|0,Ia(t[e>>2]|0,t[n>>2]|0,r)}function Wa(e,n){e=e|0,n=n|0,Mu(t[e>>2]|0,t[n>>2]|0)}function Va(e){return e=e|0,wu(t[e>>2]|0)|0}function od(e){return e=e|0,e=si(t[e>>2]|0)|0,e?e=cc(e)|0:e=0,e|0}function D2(e,n){return e=e|0,n=n|0,e=Ti(t[e>>2]|0,n)|0,e?e=cc(e)|0:e=0,e|0}function w2(e,n){e=e|0,n=n|0;var r=0,u=0;u=pn(4)|0,wf(u,n),r=e+4|0,n=t[r>>2]|0,t[r>>2]=u,n|0&&(fa(n),Et(n)),ua(t[e>>2]|0,1)}function wf(e,n){e=e|0,n=n|0,sl(e,n)}function ld(e,n,r,u,s,a){e=e|0,n=n|0,r=S(r),u=u|0,s=S(s),a=a|0;var v=0,w=0;v=y,y=y+16|0,w=v,hh(w,Bs(n)|0,+r,u,+s,a),x[e>>2]=S(+j[w>>3]),x[e+4>>2]=S(+j[w+8>>3]),y=v}function hh(e,n,r,u,s,a){e=e|0,n=n|0,r=+r,u=u|0,s=+s,a=a|0;var v=0,w=0,T=0,L=0,M=0;v=y,y=y+32|0,M=v+8|0,L=v+20|0,T=v,w=v+16|0,j[M>>3]=r,t[L>>2]=u,j[T>>3]=s,t[w>>2]=a,Gc(e,t[n+4>>2]|0,M,L,T,w),y=v}function Gc(e,n,r,u,s,a){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0;var v=0,w=0;v=y,y=y+16|0,w=v,Ma(w),n=go(n)|0,vh(e,n,+j[r>>3],t[u>>2]|0,+j[s>>3],t[a>>2]|0),ka(w),y=v}function go(e){return e=e|0,t[e>>2]|0}function vh(e,n,r,u,s,a){e=e|0,n=n|0,r=+r,u=u|0,s=+s,a=a|0;var v=0;v=_o(mh()|0)|0,r=+kl(r),u=sd(u)|0,s=+kl(s),ad(e,Xr(0,v|0,n|0,+r,u|0,+s,sd(a)|0)|0)}function mh(){var e=0;return h[7608]|0||(Kc(9120),e=7608,t[e>>2]=1,t[e+4>>2]=0),9120}function _o(e){return e=e|0,t[e+8>>2]|0}function kl(e){return e=+e,+ +Ga(e)}function sd(e){return e=e|0,cd(e)|0}function ad(e,n){e=e|0,n=n|0;var r=0,u=0,s=0;s=y,y=y+32|0,r=s,u=n,u&1?(S2(r,0),eu(u|0,r|0)|0,Yc(e,r),Ir(r)):(t[e>>2]=t[n>>2],t[e+4>>2]=t[n+4>>2],t[e+8>>2]=t[n+8>>2],t[e+12>>2]=t[n+12>>2]),y=s}function S2(e,n){e=e|0,n=n|0,fd(e,n),t[e+8>>2]=0,h[e+24>>0]=0}function Yc(e,n){e=e|0,n=n|0,n=n+8|0,t[e>>2]=t[n>>2],t[e+4>>2]=t[n+4>>2],t[e+8>>2]=t[n+8>>2],t[e+12>>2]=t[n+12>>2]}function Ir(e){e=e|0,h[e+24>>0]=0}function fd(e,n){e=e|0,n=n|0,t[e>>2]=n}function cd(e){return e=e|0,e|0}function Ga(e){return e=+e,+e}function Kc(e){e=e|0,ll(e,T2()|0,4)}function T2(){return 1064}function ll(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,t[e+4>>2]=r,t[e+8>>2]=Bt(n|0,r+1|0)|0}function sl(e,n){e=e|0,n=n|0,n=t[n>>2]|0,t[e>>2]=n,Ri(n|0)}function yh(e){e=e|0;var n=0,r=0;r=e+4|0,n=t[r>>2]|0,t[r>>2]=0,n|0&&(fa(n),Et(n)),ua(t[e>>2]|0,0)}function Sf(e){e=e|0,Jr(t[e>>2]|0)}function Xc(e){return e=e|0,Zl(t[e>>2]|0)|0}function C2(e,n,r,u){e=e|0,n=+n,r=+r,u=u|0,$r(t[e>>2]|0,S(n),S(r),u)}function gh(e){return e=e|0,+ +S(_i(t[e>>2]|0))}function al(e){return e=e|0,+ +S($0(t[e>>2]|0))}function ha(e){return e=e|0,+ +S(C0(t[e>>2]|0))}function x2(e){return e=e|0,+ +S(Uo(t[e>>2]|0))}function R2(e){return e=e|0,+ +S(la(t[e>>2]|0))}function hc(e){return e=e|0,+ +S($l(t[e>>2]|0))}function _h(e,n){e=e|0,n=n|0,j[e>>3]=+S(_i(t[n>>2]|0)),j[e+8>>3]=+S($0(t[n>>2]|0)),j[e+16>>3]=+S(C0(t[n>>2]|0)),j[e+24>>3]=+S(Uo(t[n>>2]|0)),j[e+32>>3]=+S(la(t[n>>2]|0)),j[e+40>>3]=+S($l(t[n>>2]|0))}function A2(e,n){return e=e|0,n=n|0,+ +S(tu(t[e>>2]|0,n))}function dd(e,n){return e=e|0,n=n|0,+ +S(Zr(t[e>>2]|0,n))}function Qc(e,n){return e=e|0,n=n|0,+ +S(ho(t[e>>2]|0,n))}function Jc(){return Pa()|0}function Ws(){O2(),va(),Zc(),vc(),mc(),pd()}function O2(){E7(11713,4938,1)}function va(){UA(10448)}function Zc(){EA(10408)}function vc(){qR(10324)}function mc(){nE(10096)}function pd(){Eh(9132)}function Eh(e){e=e|0;var n=0,r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0,Be=0,Te=0,ye=0,Ze=0,Ye=0,ct=0,ke=0,Ie=0,Zt=0,Br=0,Pn=0,gn=0,_r=0,Pr=0,kn=0,uu=0,os=0,ls=0,ss=0,ea=0,t2=0,n2=0,uf=0,r2=0,Fc=0,Pc=0,i2=0,u2=0,o2=0,pi=0,of=0,l2=0,Yf=0,s2=0,a2=0,Ic=0,bc=0,Kf=0,ql=0,La=0,Ns=0,lf=0,b1=0,B1=0,Bc=0,U1=0,j1=0,Wl=0,El=0,sf=0,hu=0,z1=0,as=0,Xf=0,fs=0,Qf=0,H1=0,q1=0,Jf=0,Vl=0,af=0,W1=0,V1=0,G1=0,Sr=0,bu=0,Dl=0,cs=0,Gl=0,Or=0,Bn=0,ff=0;n=y,y=y+672|0,r=n+656|0,ff=n+648|0,Bn=n+640|0,Or=n+632|0,Gl=n+624|0,cs=n+616|0,Dl=n+608|0,bu=n+600|0,Sr=n+592|0,G1=n+584|0,V1=n+576|0,W1=n+568|0,af=n+560|0,Vl=n+552|0,Jf=n+544|0,q1=n+536|0,H1=n+528|0,Qf=n+520|0,fs=n+512|0,Xf=n+504|0,as=n+496|0,z1=n+488|0,hu=n+480|0,sf=n+472|0,El=n+464|0,Wl=n+456|0,j1=n+448|0,U1=n+440|0,Bc=n+432|0,B1=n+424|0,b1=n+416|0,lf=n+408|0,Ns=n+400|0,La=n+392|0,ql=n+384|0,Kf=n+376|0,bc=n+368|0,Ic=n+360|0,a2=n+352|0,s2=n+344|0,Yf=n+336|0,l2=n+328|0,of=n+320|0,pi=n+312|0,o2=n+304|0,u2=n+296|0,i2=n+288|0,Pc=n+280|0,Fc=n+272|0,r2=n+264|0,uf=n+256|0,n2=n+248|0,t2=n+240|0,ea=n+232|0,ss=n+224|0,ls=n+216|0,os=n+208|0,uu=n+200|0,kn=n+192|0,Pr=n+184|0,_r=n+176|0,gn=n+168|0,Pn=n+160|0,Br=n+152|0,Zt=n+144|0,Ie=n+136|0,ke=n+128|0,ct=n+120|0,Ye=n+112|0,Ze=n+104|0,ye=n+96|0,Te=n+88|0,Be=n+80|0,X=n+72|0,b=n+64|0,M=n+56|0,L=n+48|0,T=n+40|0,w=n+32|0,v=n+24|0,a=n+16|0,s=n+8|0,u=n,Tf(e,3646),$c(e,3651,2)|0,Dh(e,3665,2)|0,sm(e,3682,18)|0,t[ff>>2]=19,t[ff+4>>2]=0,t[r>>2]=t[ff>>2],t[r+4>>2]=t[ff+4>>2],Vs(e,3690,r)|0,t[Bn>>2]=1,t[Bn+4>>2]=0,t[r>>2]=t[Bn>>2],t[r+4>>2]=t[Bn+4>>2],ma(e,3696,r)|0,t[Or>>2]=2,t[Or+4>>2]=0,t[r>>2]=t[Or>>2],t[r+4>>2]=t[Or+4>>2],iu(e,3706,r)|0,t[Gl>>2]=1,t[Gl+4>>2]=0,t[r>>2]=t[Gl>>2],t[r+4>>2]=t[Gl+4>>2],M0(e,3722,r)|0,t[cs>>2]=2,t[cs+4>>2]=0,t[r>>2]=t[cs>>2],t[r+4>>2]=t[cs+4>>2],M0(e,3734,r)|0,t[Dl>>2]=3,t[Dl+4>>2]=0,t[r>>2]=t[Dl>>2],t[r+4>>2]=t[Dl+4>>2],iu(e,3753,r)|0,t[bu>>2]=4,t[bu+4>>2]=0,t[r>>2]=t[bu>>2],t[r+4>>2]=t[bu+4>>2],iu(e,3769,r)|0,t[Sr>>2]=5,t[Sr+4>>2]=0,t[r>>2]=t[Sr>>2],t[r+4>>2]=t[Sr+4>>2],iu(e,3783,r)|0,t[G1>>2]=6,t[G1+4>>2]=0,t[r>>2]=t[G1>>2],t[r+4>>2]=t[G1+4>>2],iu(e,3796,r)|0,t[V1>>2]=7,t[V1+4>>2]=0,t[r>>2]=t[V1>>2],t[r+4>>2]=t[V1+4>>2],iu(e,3813,r)|0,t[W1>>2]=8,t[W1+4>>2]=0,t[r>>2]=t[W1>>2],t[r+4>>2]=t[W1+4>>2],iu(e,3825,r)|0,t[af>>2]=3,t[af+4>>2]=0,t[r>>2]=t[af>>2],t[r+4>>2]=t[af+4>>2],M0(e,3843,r)|0,t[Vl>>2]=4,t[Vl+4>>2]=0,t[r>>2]=t[Vl>>2],t[r+4>>2]=t[Vl+4>>2],M0(e,3853,r)|0,t[Jf>>2]=9,t[Jf+4>>2]=0,t[r>>2]=t[Jf>>2],t[r+4>>2]=t[Jf+4>>2],iu(e,3870,r)|0,t[q1>>2]=10,t[q1+4>>2]=0,t[r>>2]=t[q1>>2],t[r+4>>2]=t[q1+4>>2],iu(e,3884,r)|0,t[H1>>2]=11,t[H1+4>>2]=0,t[r>>2]=t[H1>>2],t[r+4>>2]=t[H1+4>>2],iu(e,3896,r)|0,t[Qf>>2]=1,t[Qf+4>>2]=0,t[r>>2]=t[Qf>>2],t[r+4>>2]=t[Qf+4>>2],u0(e,3907,r)|0,t[fs>>2]=2,t[fs+4>>2]=0,t[r>>2]=t[fs>>2],t[r+4>>2]=t[fs+4>>2],u0(e,3915,r)|0,t[Xf>>2]=3,t[Xf+4>>2]=0,t[r>>2]=t[Xf>>2],t[r+4>>2]=t[Xf+4>>2],u0(e,3928,r)|0,t[as>>2]=4,t[as+4>>2]=0,t[r>>2]=t[as>>2],t[r+4>>2]=t[as+4>>2],u0(e,3948,r)|0,t[z1>>2]=5,t[z1+4>>2]=0,t[r>>2]=t[z1>>2],t[r+4>>2]=t[z1+4>>2],u0(e,3960,r)|0,t[hu>>2]=6,t[hu+4>>2]=0,t[r>>2]=t[hu>>2],t[r+4>>2]=t[hu+4>>2],u0(e,3974,r)|0,t[sf>>2]=7,t[sf+4>>2]=0,t[r>>2]=t[sf>>2],t[r+4>>2]=t[sf+4>>2],u0(e,3983,r)|0,t[El>>2]=20,t[El+4>>2]=0,t[r>>2]=t[El>>2],t[r+4>>2]=t[El+4>>2],Vs(e,3999,r)|0,t[Wl>>2]=8,t[Wl+4>>2]=0,t[r>>2]=t[Wl>>2],t[r+4>>2]=t[Wl+4>>2],u0(e,4012,r)|0,t[j1>>2]=9,t[j1+4>>2]=0,t[r>>2]=t[j1>>2],t[r+4>>2]=t[j1+4>>2],u0(e,4022,r)|0,t[U1>>2]=21,t[U1+4>>2]=0,t[r>>2]=t[U1>>2],t[r+4>>2]=t[U1+4>>2],Vs(e,4039,r)|0,t[Bc>>2]=10,t[Bc+4>>2]=0,t[r>>2]=t[Bc>>2],t[r+4>>2]=t[Bc+4>>2],u0(e,4053,r)|0,t[B1>>2]=11,t[B1+4>>2]=0,t[r>>2]=t[B1>>2],t[r+4>>2]=t[B1+4>>2],u0(e,4065,r)|0,t[b1>>2]=12,t[b1+4>>2]=0,t[r>>2]=t[b1>>2],t[r+4>>2]=t[b1+4>>2],u0(e,4084,r)|0,t[lf>>2]=13,t[lf+4>>2]=0,t[r>>2]=t[lf>>2],t[r+4>>2]=t[lf+4>>2],u0(e,4097,r)|0,t[Ns>>2]=14,t[Ns+4>>2]=0,t[r>>2]=t[Ns>>2],t[r+4>>2]=t[Ns+4>>2],u0(e,4117,r)|0,t[La>>2]=15,t[La+4>>2]=0,t[r>>2]=t[La>>2],t[r+4>>2]=t[La+4>>2],u0(e,4129,r)|0,t[ql>>2]=16,t[ql+4>>2]=0,t[r>>2]=t[ql>>2],t[r+4>>2]=t[ql+4>>2],u0(e,4148,r)|0,t[Kf>>2]=17,t[Kf+4>>2]=0,t[r>>2]=t[Kf>>2],t[r+4>>2]=t[Kf+4>>2],u0(e,4161,r)|0,t[bc>>2]=18,t[bc+4>>2]=0,t[r>>2]=t[bc>>2],t[r+4>>2]=t[bc+4>>2],u0(e,4181,r)|0,t[Ic>>2]=5,t[Ic+4>>2]=0,t[r>>2]=t[Ic>>2],t[r+4>>2]=t[Ic+4>>2],M0(e,4196,r)|0,t[a2>>2]=6,t[a2+4>>2]=0,t[r>>2]=t[a2>>2],t[r+4>>2]=t[a2+4>>2],M0(e,4206,r)|0,t[s2>>2]=7,t[s2+4>>2]=0,t[r>>2]=t[s2>>2],t[r+4>>2]=t[s2+4>>2],M0(e,4217,r)|0,t[Yf>>2]=3,t[Yf+4>>2]=0,t[r>>2]=t[Yf>>2],t[r+4>>2]=t[Yf+4>>2],ns(e,4235,r)|0,t[l2>>2]=1,t[l2+4>>2]=0,t[r>>2]=t[l2>>2],t[r+4>>2]=t[l2+4>>2],Ya(e,4251,r)|0,t[of>>2]=4,t[of+4>>2]=0,t[r>>2]=t[of>>2],t[r+4>>2]=t[of+4>>2],ns(e,4263,r)|0,t[pi>>2]=5,t[pi+4>>2]=0,t[r>>2]=t[pi>>2],t[r+4>>2]=t[pi+4>>2],ns(e,4279,r)|0,t[o2>>2]=6,t[o2+4>>2]=0,t[r>>2]=t[o2>>2],t[r+4>>2]=t[o2+4>>2],ns(e,4293,r)|0,t[u2>>2]=7,t[u2+4>>2]=0,t[r>>2]=t[u2>>2],t[r+4>>2]=t[u2+4>>2],ns(e,4306,r)|0,t[i2>>2]=8,t[i2+4>>2]=0,t[r>>2]=t[i2>>2],t[r+4>>2]=t[i2+4>>2],ns(e,4323,r)|0,t[Pc>>2]=9,t[Pc+4>>2]=0,t[r>>2]=t[Pc>>2],t[r+4>>2]=t[Pc+4>>2],ns(e,4335,r)|0,t[Fc>>2]=2,t[Fc+4>>2]=0,t[r>>2]=t[Fc>>2],t[r+4>>2]=t[Fc+4>>2],Ya(e,4353,r)|0,t[r2>>2]=12,t[r2+4>>2]=0,t[r>>2]=t[r2>>2],t[r+4>>2]=t[r2+4>>2],uo(e,4363,r)|0,t[uf>>2]=1,t[uf+4>>2]=0,t[r>>2]=t[uf>>2],t[r+4>>2]=t[uf+4>>2],fl(e,4376,r)|0,t[n2>>2]=2,t[n2+4>>2]=0,t[r>>2]=t[n2>>2],t[r+4>>2]=t[n2+4>>2],fl(e,4388,r)|0,t[t2>>2]=13,t[t2+4>>2]=0,t[r>>2]=t[t2>>2],t[r+4>>2]=t[t2+4>>2],uo(e,4402,r)|0,t[ea>>2]=14,t[ea+4>>2]=0,t[r>>2]=t[ea>>2],t[r+4>>2]=t[ea+4>>2],uo(e,4411,r)|0,t[ss>>2]=15,t[ss+4>>2]=0,t[r>>2]=t[ss>>2],t[r+4>>2]=t[ss+4>>2],uo(e,4421,r)|0,t[ls>>2]=16,t[ls+4>>2]=0,t[r>>2]=t[ls>>2],t[r+4>>2]=t[ls+4>>2],uo(e,4433,r)|0,t[os>>2]=17,t[os+4>>2]=0,t[r>>2]=t[os>>2],t[r+4>>2]=t[os+4>>2],uo(e,4446,r)|0,t[uu>>2]=18,t[uu+4>>2]=0,t[r>>2]=t[uu>>2],t[r+4>>2]=t[uu+4>>2],uo(e,4458,r)|0,t[kn>>2]=3,t[kn+4>>2]=0,t[r>>2]=t[kn>>2],t[r+4>>2]=t[kn+4>>2],fl(e,4471,r)|0,t[Pr>>2]=1,t[Pr+4>>2]=0,t[r>>2]=t[Pr>>2],t[r+4>>2]=t[Pr+4>>2],yc(e,4486,r)|0,t[_r>>2]=10,t[_r+4>>2]=0,t[r>>2]=t[_r>>2],t[r+4>>2]=t[_r+4>>2],ns(e,4496,r)|0,t[gn>>2]=11,t[gn+4>>2]=0,t[r>>2]=t[gn>>2],t[r+4>>2]=t[gn+4>>2],ns(e,4508,r)|0,t[Pn>>2]=3,t[Pn+4>>2]=0,t[r>>2]=t[Pn>>2],t[r+4>>2]=t[Pn+4>>2],Ya(e,4519,r)|0,t[Br>>2]=4,t[Br+4>>2]=0,t[r>>2]=t[Br>>2],t[r+4>>2]=t[Br+4>>2],M2(e,4530,r)|0,t[Zt>>2]=19,t[Zt+4>>2]=0,t[r>>2]=t[Zt>>2],t[r+4>>2]=t[Zt+4>>2],wh(e,4542,r)|0,t[Ie>>2]=12,t[Ie+4>>2]=0,t[r>>2]=t[Ie>>2],t[r+4>>2]=t[Ie+4>>2],Cf(e,4554,r)|0,t[ke>>2]=13,t[ke+4>>2]=0,t[r>>2]=t[ke>>2],t[r+4>>2]=t[ke+4>>2],xf(e,4568,r)|0,t[ct>>2]=2,t[ct+4>>2]=0,t[r>>2]=t[ct>>2],t[r+4>>2]=t[ct+4>>2],e1(e,4578,r)|0,t[Ye>>2]=20,t[Ye+4>>2]=0,t[r>>2]=t[Ye>>2],t[r+4>>2]=t[Ye+4>>2],Nl(e,4587,r)|0,t[Ze>>2]=22,t[Ze+4>>2]=0,t[r>>2]=t[Ze>>2],t[r+4>>2]=t[Ze+4>>2],Vs(e,4602,r)|0,t[ye>>2]=23,t[ye+4>>2]=0,t[r>>2]=t[ye>>2],t[r+4>>2]=t[ye+4>>2],Vs(e,4619,r)|0,t[Te>>2]=14,t[Te+4>>2]=0,t[r>>2]=t[Te>>2],t[r+4>>2]=t[Te+4>>2],t1(e,4629,r)|0,t[Be>>2]=1,t[Be+4>>2]=0,t[r>>2]=t[Be>>2],t[r+4>>2]=t[Be+4>>2],ya(e,4637,r)|0,t[X>>2]=4,t[X+4>>2]=0,t[r>>2]=t[X>>2],t[r+4>>2]=t[X+4>>2],fl(e,4653,r)|0,t[b>>2]=5,t[b+4>>2]=0,t[r>>2]=t[b>>2],t[r+4>>2]=t[b+4>>2],fl(e,4669,r)|0,t[M>>2]=6,t[M+4>>2]=0,t[r>>2]=t[M>>2],t[r+4>>2]=t[M+4>>2],fl(e,4686,r)|0,t[L>>2]=7,t[L+4>>2]=0,t[r>>2]=t[L>>2],t[r+4>>2]=t[L+4>>2],fl(e,4701,r)|0,t[T>>2]=8,t[T+4>>2]=0,t[r>>2]=t[T>>2],t[r+4>>2]=t[T+4>>2],fl(e,4719,r)|0,t[w>>2]=9,t[w+4>>2]=0,t[r>>2]=t[w>>2],t[r+4>>2]=t[w+4>>2],fl(e,4736,r)|0,t[v>>2]=21,t[v+4>>2]=0,t[r>>2]=t[v>>2],t[r+4>>2]=t[v+4>>2],hd(e,4754,r)|0,t[a>>2]=2,t[a+4>>2]=0,t[r>>2]=t[a>>2],t[r+4>>2]=t[a+4>>2],yc(e,4772,r)|0,t[s>>2]=3,t[s+4>>2]=0,t[r>>2]=t[s>>2],t[r+4>>2]=t[s+4>>2],yc(e,4790,r)|0,t[u>>2]=4,t[u+4>>2]=0,t[r>>2]=t[u>>2],t[r+4>>2]=t[u+4>>2],yc(e,4808,r)|0,y=n}function Tf(e,n){e=e|0,n=n|0;var r=0;r=rf()|0,t[e>>2]=r,Vo(r,n),Zd(t[e>>2]|0)}function $c(e,n,r){return e=e|0,n=n|0,r=r|0,Mt(e,Fr(n)|0,r,0),e|0}function Dh(e,n,r){return e=e|0,n=n|0,r=r|0,d(e,Fr(n)|0,r,0),e|0}function sm(e,n,r){return e=e|0,n=n|0,r=r|0,Q4(e,Fr(n)|0,r,0),e|0}function Vs(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],H4(e,n,s),y=u,e|0}function ma(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],zl(e,n,s),y=u,e|0}function iu(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],p(e,n,s),y=u,e|0}function M0(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Rv(e,n,s),y=u,e|0}function u0(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],ny(e,n,s),y=u,e|0}function ns(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Gd(e,n,s),y=u,e|0}function Ya(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Vd(e,n,s),y=u,e|0}function uo(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],k0(e,n,s),y=u,e|0}function fl(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Dp(e,n,s),y=u,e|0}function yc(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],bm(e,n,s),y=u,e|0}function M2(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],o0(e,n,s),y=u,e|0}function wh(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Ad(e,n,s),y=u,e|0}function Cf(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Am(e,n,s),y=u,e|0}function xf(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],$2(e,n,s),y=u,e|0}function e1(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],y1(e,n,s),y=u,e|0}function Nl(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Za(e,n,s),y=u,e|0}function t1(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],B2(e,n,s),y=u,e|0}function ya(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],L2(e,n,s),y=u,e|0}function hd(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],vd(e,n,s),y=u,e|0}function vd(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],ga(e,r,s,1),y=u}function Fr(e){return e=e|0,e|0}function ga(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=k2()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=n1(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,md(a,u)|0,u),y=s}function k2(){var e=0,n=0;if(h[7616]|0||(cl(9136),Wt(24,9136,ge|0)|0,n=7616,t[n>>2]=1,t[n+4>>2]=0),!(sr(9136)|0)){e=9136,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));cl(9136)}return 9136}function n1(e){return e=e|0,0}function md(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=k2()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],Rf(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(Af(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function wi(e,n,r,u,s,a){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0;var v=0,w=0,T=0,L=0,M=0,b=0,X=0,Be=0;v=y,y=y+32|0,X=v+24|0,b=v+20|0,T=v+16|0,M=v+12|0,L=v+8|0,w=v+4|0,Be=v,t[b>>2]=n,t[T>>2]=r,t[M>>2]=u,t[L>>2]=s,t[w>>2]=a,a=e+28|0,t[Be>>2]=t[a>>2],t[X>>2]=t[Be>>2],N2(e+24|0,X,b,M,L,T,w)|0,t[a>>2]=t[t[a>>2]>>2],y=v}function N2(e,n,r,u,s,a,v){return e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0,v=v|0,e=am(n)|0,n=pn(24)|0,yd(n+4|0,t[r>>2]|0,t[u>>2]|0,t[s>>2]|0,t[a>>2]|0,t[v>>2]|0),t[n>>2]=t[e>>2],t[e>>2]=n,n|0}function am(e){return e=e|0,t[e>>2]|0}function yd(e,n,r,u,s,a){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0,t[e>>2]=n,t[e+4>>2]=r,t[e+8>>2]=u,t[e+12>>2]=s,t[e+16>>2]=a}function hn(e,n){return e=e|0,n=n|0,n|e|0}function Rf(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function Af(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=fm(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,Of(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],Rf(a,u,r),t[T>>2]=(t[T>>2]|0)+12,Sh(e,w),cm(w),y=L;return}}function fm(e){return e=e|0,357913941}function Of(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function Sh(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function cm(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function cl(e){e=e|0,qo(e)}function r1(e){e=e|0,qn(e+24|0)}function sr(e){return e=e|0,t[e>>2]|0}function qn(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function qo(e){e=e|0;var n=0;n=yr()|0,jn(e,2,3,n,Vn()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function yr(){return 9228}function Vn(){return 1140}function dl(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0;return r=y,y=y+16|0,u=r+8|0,s=r,a=Eo(e)|0,e=t[a+4>>2]|0,t[s>>2]=t[a>>2],t[s+4>>2]=e,t[u>>2]=t[s>>2],t[u+4>>2]=t[s+4>>2],n=gc(n,u)|0,y=r,n|0}function jn(e,n,r,u,s,a){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0,t[e>>2]=n,t[e+4>>2]=r,t[e+8>>2]=u,t[e+12>>2]=s,t[e+16>>2]=a}function Eo(e){return e=e|0,(t[(k2()|0)+24>>2]|0)+(e*12|0)|0}function gc(e,n){e=e|0,n=n|0;var r=0,u=0,s=0;return s=y,y=y+48|0,u=s,r=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(r=t[(t[e>>2]|0)+r>>2]|0),I1[r&31](u,e),u=oo(u)|0,y=s,u|0}function oo(e){e=e|0;var n=0,r=0,u=0,s=0;return s=y,y=y+32|0,n=s+12|0,r=s,u=Pu(Ka()|0)|0,u?(rs(n,u),Mf(r,n),_c(e,r),e=Cs(n)|0):e=Ec(e)|0,y=s,e|0}function Ka(){var e=0;return h[7632]|0||(Nf(9184),Wt(25,9184,ge|0)|0,e=7632,t[e>>2]=1,t[e+4>>2]=0),9184}function Pu(e){return e=e|0,t[e+36>>2]|0}function rs(e,n){e=e|0,n=n|0,t[e>>2]=n,t[e+4>>2]=e,t[e+8>>2]=0}function Mf(e,n){e=e|0,n=n|0,t[e>>2]=t[n>>2],t[e+4>>2]=t[n+4>>2],t[e+8>>2]=0}function _c(e,n){e=e|0,n=n|0,lo(n,e,e+8|0,e+16|0,e+24|0,e+32|0,e+40|0)|0}function Cs(e){return e=e|0,t[(t[e+4>>2]|0)+8>>2]|0}function Ec(e){e=e|0;var n=0,r=0,u=0,s=0,a=0,v=0,w=0,T=0;T=y,y=y+16|0,r=T+4|0,u=T,s=Oa(8)|0,a=s,v=pn(48)|0,w=v,n=w+48|0;do t[w>>2]=t[e>>2],w=w+4|0,e=e+4|0;while((w|0)<(n|0));return n=a+4|0,t[n>>2]=v,w=pn(8)|0,v=t[n>>2]|0,t[u>>2]=0,t[r>>2]=t[u>>2],Th(w,v,r),t[s>>2]=w,y=T,a|0}function Th(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,r=pn(16)|0,t[r+4>>2]=0,t[r+8>>2]=0,t[r>>2]=1092,t[r+12>>2]=n,t[e+4>>2]=r}function cn(e){e=e|0,Uv(e),Et(e)}function is(e){e=e|0,e=t[e+12>>2]|0,e|0&&Et(e)}function Do(e){e=e|0,Et(e)}function lo(e,n,r,u,s,a,v){return e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0,v=v|0,a=Ji(t[e>>2]|0,n,r,u,s,a,v)|0,v=e+4|0,t[(t[v>>2]|0)+8>>2]=a,t[(t[v>>2]|0)+8>>2]|0}function Ji(e,n,r,u,s,a,v){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0,v=v|0;var w=0,T=0;return w=y,y=y+16|0,T=w,Ma(T),e=go(e)|0,v=Gr(e,+j[n>>3],+j[r>>3],+j[u>>3],+j[s>>3],+j[a>>3],+j[v>>3])|0,ka(T),y=w,v|0}function Gr(e,n,r,u,s,a,v){e=e|0,n=+n,r=+r,u=+u,s=+s,a=+a,v=+v;var w=0;return w=_o(kf()|0)|0,n=+kl(n),r=+kl(r),u=+kl(u),s=+kl(s),a=+kl(a),d0(0,w|0,e|0,+n,+r,+u,+s,+a,+ +kl(v))|0}function kf(){var e=0;return h[7624]|0||(dm(9172),e=7624,t[e>>2]=1,t[e+4>>2]=0),9172}function dm(e){e=e|0,ll(e,Ll()|0,6)}function Ll(){return 1112}function Nf(e){e=e|0,Xa(e)}function Lf(e){e=e|0,gd(e+24|0),_d(e+16|0)}function gd(e){e=e|0,i1(e)}function _d(e){e=e|0,Dc(e)}function Dc(e){e=e|0;var n=0,r=0;if(n=t[e>>2]|0,n|0)do r=n,n=t[n>>2]|0,Et(r);while((n|0)!=0);t[e>>2]=0}function i1(e){e=e|0;var n=0,r=0;if(n=t[e>>2]|0,n|0)do r=n,n=t[n>>2]|0,Et(r);while((n|0)!=0);t[e>>2]=0}function Xa(e){e=e|0;var n=0;t[e+16>>2]=0,t[e+20>>2]=0,n=e+24|0,t[n>>2]=0,t[e+28>>2]=n,t[e+36>>2]=0,h[e+40>>0]=0,h[e+41>>0]=0}function L2(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Ed(e,r,s,0),y=u}function Ed(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=u1()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=Ff(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,o1(a,u)|0,u),y=s}function u1(){var e=0,n=0;if(h[7640]|0||(Fl(9232),Wt(26,9232,ge|0)|0,n=7640,t[n>>2]=1,t[n+4>>2]=0),!(sr(9232)|0)){e=9232,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));Fl(9232)}return 9232}function Ff(e){return e=e|0,0}function o1(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=u1()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],Qa(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(l1(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function Qa(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function l1(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=F2(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,Dd(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],Qa(a,u,r),t[T>>2]=(t[T>>2]|0)+12,wc(e,w),s1(w),y=L;return}}function F2(e){return e=e|0,357913941}function Dd(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function wc(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function s1(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function Fl(e){e=e|0,P2(e)}function Ea(e){e=e|0,Ch(e+24|0)}function Ch(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function P2(e){e=e|0;var n=0;n=yr()|0,jn(e,2,1,n,I2()|0,3),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function I2(){return 1144}function xh(e,n,r,u,s){e=e|0,n=n|0,r=+r,u=+u,s=s|0;var a=0,v=0,w=0,T=0;a=y,y=y+16|0,v=a+8|0,w=a,T=pm(e)|0,e=t[T+4>>2]|0,t[w>>2]=t[T>>2],t[w+4>>2]=e,t[v>>2]=t[w>>2],t[v+4>>2]=t[w+4>>2],Rh(n,v,r,u,s),y=a}function pm(e){return e=e|0,(t[(u1()|0)+24>>2]|0)+(e*12|0)|0}function Rh(e,n,r,u,s){e=e|0,n=n|0,r=+r,u=+u,s=s|0;var a=0,v=0,w=0,T=0,L=0;L=y,y=y+16|0,v=L+2|0,w=L+1|0,T=L,a=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(a=t[(t[e>>2]|0)+a>>2]|0),Pl(v,r),r=+us(v,r),Pl(w,u),u=+us(w,u),xs(T,s),T=Gs(T,s)|0,L8[a&1](e,r,u,T),y=L}function Pl(e,n){e=e|0,n=+n}function us(e,n){return e=e|0,n=+n,+ +Ah(n)}function xs(e,n){e=e|0,n=n|0}function Gs(e,n){return e=e|0,n=n|0,b2(n)|0}function b2(e){return e=e|0,e|0}function Ah(e){return e=+e,+e}function B2(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],U2(e,r,s,1),y=u}function U2(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=a1()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=f1(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,Oh(a,u)|0,u),y=s}function a1(){var e=0,n=0;if(h[7648]|0||(c1(9268),Wt(27,9268,ge|0)|0,n=7648,t[n>>2]=1,t[n+4>>2]=0),!(sr(9268)|0)){e=9268,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));c1(9268)}return 9268}function f1(e){return e=e|0,0}function Oh(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=a1()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],j2(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(z2(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function j2(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function z2(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=Rs(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,Ja(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],j2(a,u,r),t[T>>2]=(t[T>>2]|0)+12,Mh(e,w),du(w),y=L;return}}function Rs(e){return e=e|0,357913941}function Ja(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function Mh(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function du(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function c1(e){e=e|0,Il(e)}function kh(e){e=e|0,d1(e+24|0)}function d1(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function Il(e){e=e|0;var n=0;n=yr()|0,jn(e,2,4,n,Nh()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function Nh(){return 1160}function H2(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0;return r=y,y=y+16|0,u=r+8|0,s=r,a=Lh(e)|0,e=t[a+4>>2]|0,t[s>>2]=t[a>>2],t[s+4>>2]=e,t[u>>2]=t[s>>2],t[u+4>>2]=t[s+4>>2],n=p1(n,u)|0,y=r,n|0}function Lh(e){return e=e|0,(t[(a1()|0)+24>>2]|0)+(e*12|0)|0}function p1(e,n){e=e|0,n=n|0;var r=0;return r=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(r=t[(t[e>>2]|0)+r>>2]|0),bl(Qp[r&31](e)|0)|0}function bl(e){return e=e|0,e&1|0}function Za(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Da(e,r,s,0),y=u}function Da(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=q2()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=W2(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,hm(a,u)|0,u),y=s}function q2(){var e=0,n=0;if(h[7656]|0||(Ih(9304),Wt(28,9304,ge|0)|0,n=7656,t[n>>2]=1,t[n+4>>2]=0),!(sr(9304)|0)){e=9304,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));Ih(9304)}return 9304}function W2(e){return e=e|0,0}function hm(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=q2()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],V2(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(Fh(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function V2(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function Fh(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=Ph(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,G2(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],V2(a,u,r),t[T>>2]=(t[T>>2]|0)+12,vm(e,w),mm(w),y=L;return}}function Ph(e){return e=e|0,357913941}function G2(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function vm(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function mm(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function Ih(e){e=e|0,h1(e)}function ym(e){e=e|0,Y2(e+24|0)}function Y2(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function h1(e){e=e|0;var n=0;n=yr()|0,jn(e,2,5,n,v1()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function v1(){return 1164}function m1(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;u=y,y=y+16|0,s=u+8|0,a=u,v=wa(e)|0,e=t[v+4>>2]|0,t[a>>2]=t[v>>2],t[a+4>>2]=e,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],K2(n,s,r),y=u}function wa(e){return e=e|0,(t[(q2()|0)+24>>2]|0)+(e*12|0)|0}function K2(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0;a=y,y=y+16|0,s=a,u=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(u=t[(t[e>>2]|0)+u>>2]|0),Ys(s,r),r=Ks(s,r)|0,I1[u&31](e,r),Xs(s),y=a}function Ys(e,n){e=e|0,n=n|0,X2(e,n)}function Ks(e,n){return e=e|0,n=n|0,e|0}function Xs(e){e=e|0,fa(e)}function X2(e,n){e=e|0,n=n|0,Sa(e,n)}function Sa(e,n){e=e|0,n=n|0,t[e>>2]=n}function y1(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],wd(e,r,s,0),y=u}function wd(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=Sc()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=Q2(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,wo(a,u)|0,u),y=s}function Sc(){var e=0,n=0;if(h[7664]|0||(Hh(9340),Wt(29,9340,ge|0)|0,n=7664,t[n>>2]=1,t[n+4>>2]=0),!(sr(9340)|0)){e=9340,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));Hh(9340)}return 9340}function Q2(e){return e=e|0,0}function wo(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=Sc()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],bh(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(Bh(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function bh(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function Bh(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=Uh(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,jh(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],bh(a,u,r),t[T>>2]=(t[T>>2]|0)+12,gm(e,w),zh(w),y=L;return}}function Uh(e){return e=e|0,357913941}function jh(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function gm(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function zh(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function Hh(e){e=e|0,qh(e)}function g1(e){e=e|0,J2(e+24|0)}function J2(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function qh(e){e=e|0;var n=0;n=yr()|0,jn(e,2,4,n,Z2()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function Z2(){return 1180}function Wh(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=_m(e)|0,e=t[v+4>>2]|0,t[a>>2]=t[v>>2],t[a+4>>2]=e,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],r=Em(n,s,r)|0,y=u,r|0}function _m(e){return e=e|0,(t[(Sc()|0)+24>>2]|0)+(e*12|0)|0}function Em(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0;return a=y,y=y+16|0,s=a,u=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(u=t[(t[e>>2]|0)+u>>2]|0),Pf(s,r),s=If(s,r)|0,s=Sd(bE[u&15](e,s)|0)|0,y=a,s|0}function Pf(e,n){e=e|0,n=n|0}function If(e,n){return e=e|0,n=n|0,Dm(n)|0}function Sd(e){return e=e|0,e|0}function Dm(e){return e=e|0,e|0}function $2(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Td(e,r,s,0),y=u}function Td(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=ep()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=Vh(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,tp(a,u)|0,u),y=s}function ep(){var e=0,n=0;if(h[7672]|0||(Kh(9376),Wt(30,9376,ge|0)|0,n=7672,t[n>>2]=1,t[n+4>>2]=0),!(sr(9376)|0)){e=9376,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));Kh(9376)}return 9376}function Vh(e){return e=e|0,0}function tp(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=ep()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],Gh(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(Yh(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function Gh(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function Yh(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=np(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,wm(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],Gh(a,u,r),t[T>>2]=(t[T>>2]|0)+12,Sm(e,w),Tm(w),y=L;return}}function np(e){return e=e|0,357913941}function wm(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function Sm(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function Tm(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function Kh(e){e=e|0,rp(e)}function _1(e){e=e|0,Cm(e+24|0)}function Cm(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function rp(e){e=e|0;var n=0;n=yr()|0,jn(e,2,5,n,ip()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function ip(){return 1196}function xm(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0;return r=y,y=y+16|0,u=r+8|0,s=r,a=Rm(e)|0,e=t[a+4>>2]|0,t[s>>2]=t[a>>2],t[s+4>>2]=e,t[u>>2]=t[s>>2],t[u+4>>2]=t[s+4>>2],n=Xh(n,u)|0,y=r,n|0}function Rm(e){return e=e|0,(t[(ep()|0)+24>>2]|0)+(e*12|0)|0}function Xh(e,n){e=e|0,n=n|0;var r=0;return r=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(r=t[(t[e>>2]|0)+r>>2]|0),Sd(Qp[r&31](e)|0)|0}function Am(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Om(e,r,s,1),y=u}function Om(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=up()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=op(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,Ta(a,u)|0,u),y=s}function up(){var e=0,n=0;if(h[7680]|0||(sp(9412),Wt(31,9412,ge|0)|0,n=7680,t[n>>2]=1,t[n+4>>2]=0),!(sr(9412)|0)){e=9412,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));sp(9412)}return 9412}function op(e){return e=e|0,0}function Ta(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=up()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],E1(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(lp(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function E1(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function lp(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=Qh(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,Cd(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],E1(a,u,r),t[T>>2]=(t[T>>2]|0)+12,D1(e,w),Jh(w),y=L;return}}function Qh(e){return e=e|0,357913941}function Cd(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function D1(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function Jh(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function sp(e){e=e|0,$h(e)}function Zh(e){e=e|0,ap(e+24|0)}function ap(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function $h(e){e=e|0;var n=0;n=yr()|0,jn(e,2,6,n,ev()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function ev(){return 1200}function fp(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0;return r=y,y=y+16|0,u=r+8|0,s=r,a=xd(e)|0,e=t[a+4>>2]|0,t[s>>2]=t[a>>2],t[s+4>>2]=e,t[u>>2]=t[s>>2],t[u+4>>2]=t[s+4>>2],n=Rd(n,u)|0,y=r,n|0}function xd(e){return e=e|0,(t[(up()|0)+24>>2]|0)+(e*12|0)|0}function Rd(e,n){e=e|0,n=n|0;var r=0;return r=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(r=t[(t[e>>2]|0)+r>>2]|0),H0(Qp[r&31](e)|0)|0}function H0(e){return e=e|0,e|0}function Ad(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Ca(e,r,s,0),y=u}function Ca(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=$a()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=Od(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,Md(a,u)|0,u),y=s}function $a(){var e=0,n=0;if(h[7688]|0||(pp(9448),Wt(32,9448,ge|0)|0,n=7688,t[n>>2]=1,t[n+4>>2]=0),!(sr(9448)|0)){e=9448,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));pp(9448)}return 9448}function Od(e){return e=e|0,0}function Md(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=$a()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],cp(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(kd(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function cp(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function kd(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=tv(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,Mm(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],cp(a,u,r),t[T>>2]=(t[T>>2]|0)+12,nv(e,w),dp(w),y=L;return}}function tv(e){return e=e|0,357913941}function Mm(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function nv(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function dp(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function pp(e){e=e|0,Nm(e)}function hp(e){e=e|0,km(e+24|0)}function km(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function Nm(e){e=e|0;var n=0;n=yr()|0,jn(e,2,6,n,So()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function So(){return 1204}function Nd(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;u=y,y=y+16|0,s=u+8|0,a=u,v=Lm(e)|0,e=t[v+4>>2]|0,t[a>>2]=t[v>>2],t[a+4>>2]=e,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],pl(n,s,r),y=u}function Lm(e){return e=e|0,(t[($a()|0)+24>>2]|0)+(e*12|0)|0}function pl(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0;a=y,y=y+16|0,s=a,u=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(u=t[(t[e>>2]|0)+u>>2]|0),tr(s,r),s=Qs(s,r)|0,I1[u&31](e,s),y=a}function tr(e,n){e=e|0,n=n|0}function Qs(e,n){return e=e|0,n=n|0,hl(n)|0}function hl(e){return e=e|0,e|0}function o0(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],rv(e,r,s,0),y=u}function rv(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=Js()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=vp(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,Fm(a,u)|0,u),y=s}function Js(){var e=0,n=0;if(h[7696]|0||(gp(9484),Wt(33,9484,ge|0)|0,n=7696,t[n>>2]=1,t[n+4>>2]=0),!(sr(9484)|0)){e=9484,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));gp(9484)}return 9484}function vp(e){return e=e|0,0}function Fm(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=Js()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],iv(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(mp(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function iv(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function mp(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=Pm(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,yp(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],iv(a,u,r),t[T>>2]=(t[T>>2]|0)+12,Tc(e,w),xa(w),y=L;return}}function Pm(e){return e=e|0,357913941}function yp(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function Tc(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function xa(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function gp(e){e=e|0,Gu(e)}function Ld(e){e=e|0,Iu(e+24|0)}function Iu(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function Gu(e){e=e|0;var n=0;n=yr()|0,jn(e,2,1,n,_p()|0,2),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function _p(){return 1212}function Ep(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0;s=y,y=y+16|0,a=s+8|0,v=s,w=uv(e)|0,e=t[w+4>>2]|0,t[v>>2]=t[w>>2],t[v+4>>2]=e,t[a>>2]=t[v>>2],t[a+4>>2]=t[v+4>>2],Im(n,a,r,u),y=s}function uv(e){return e=e|0,(t[(Js()|0)+24>>2]|0)+(e*12|0)|0}function Im(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0;w=y,y=y+16|0,a=w+1|0,v=w,s=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(s=t[(t[e>>2]|0)+s>>2]|0),tr(a,r),a=Qs(a,r)|0,Pf(v,u),v=If(v,u)|0,Fy[s&15](e,a,v),y=w}function bm(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Bm(e,r,s,1),y=u}function Bm(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=Fd()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=ov(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,Cc(a,u)|0,u),y=s}function Fd(){var e=0,n=0;if(h[7704]|0||(lv(9520),Wt(34,9520,ge|0)|0,n=7704,t[n>>2]=1,t[n+4>>2]=0),!(sr(9520)|0)){e=9520,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));lv(9520)}return 9520}function ov(e){return e=e|0,0}function Cc(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=Fd()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],w1(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(Um(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function w1(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function Um(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=Pd(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,S1(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],w1(a,u,r),t[T>>2]=(t[T>>2]|0)+12,Bl(e,w),Ra(w),y=L;return}}function Pd(e){return e=e|0,357913941}function S1(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function Bl(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function Ra(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function lv(e){e=e|0,av(e)}function jm(e){e=e|0,sv(e+24|0)}function sv(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function av(e){e=e|0;var n=0;n=yr()|0,jn(e,2,1,n,zm()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function zm(){return 1224}function fv(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;return s=y,y=y+16|0,a=s+8|0,v=s,w=Aa(e)|0,e=t[w+4>>2]|0,t[v>>2]=t[w>>2],t[v+4>>2]=e,t[a>>2]=t[v>>2],t[a+4>>2]=t[v+4>>2],u=+Mr(n,a,r),y=s,+u}function Aa(e){return e=e|0,(t[(Fd()|0)+24>>2]|0)+(e*12|0)|0}function Mr(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return a=y,y=y+16|0,s=a,u=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(u=t[(t[e>>2]|0)+u>>2]|0),xs(s,r),s=Gs(s,r)|0,v=+Ga(+P8[u&7](e,s)),y=a,+v}function Dp(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],vl(e,r,s,1),y=u}function vl(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=yu()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=T1(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,Ui(a,u)|0,u),y=s}function yu(){var e=0,n=0;if(h[7712]|0||(Sp(9556),Wt(35,9556,ge|0)|0,n=7712,t[n>>2]=1,t[n+4>>2]=0),!(sr(9556)|0)){e=9556,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));Sp(9556)}return 9556}function T1(e){return e=e|0,0}function Ui(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=yu()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],wp(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(Id(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function wp(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function Id(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=To(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,As(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],wp(a,u,r),t[T>>2]=(t[T>>2]|0)+12,bf(e,w),bd(w),y=L;return}}function To(e){return e=e|0,357913941}function As(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function bf(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function bd(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function Sp(e){e=e|0,Tp(e)}function C1(e){e=e|0,x1(e+24|0)}function x1(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function Tp(e){e=e|0;var n=0;n=yr()|0,jn(e,2,5,n,nr()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function nr(){return 1232}function ml(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=Gn(e)|0,e=t[v+4>>2]|0,t[a>>2]=t[v>>2],t[a+4>>2]=e,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],r=+q0(n,s),y=u,+r}function Gn(e){return e=e|0,(t[(yu()|0)+24>>2]|0)+(e*12|0)|0}function q0(e,n){e=e|0,n=n|0;var r=0;return r=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(r=t[(t[e>>2]|0)+r>>2]|0),+ +Ga(+F8[r&15](e))}function k0(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Bd(e,r,s,1),y=u}function Bd(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=Ul()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=R1(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,xc(a,u)|0,u),y=s}function Ul(){var e=0,n=0;if(h[7720]|0||(zd(9592),Wt(36,9592,ge|0)|0,n=7720,t[n>>2]=1,t[n+4>>2]=0),!(sr(9592)|0)){e=9592,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));zd(9592)}return 9592}function R1(e){return e=e|0,0}function xc(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=Ul()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],Rc(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(Ud(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function Rc(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function Ud(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=Cp(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,N0(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],Rc(a,u,r),t[T>>2]=(t[T>>2]|0)+12,dn(e,w),jd(w),y=L;return}}function Cp(e){return e=e|0,357913941}function N0(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function dn(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function jd(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function zd(e){e=e|0,Mc(e)}function Ac(e){e=e|0,Oc(e+24|0)}function Oc(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function Mc(e){e=e|0;var n=0;n=yr()|0,jn(e,2,7,n,A1()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function A1(){return 1276}function xp(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0;return r=y,y=y+16|0,u=r+8|0,s=r,a=ef(e)|0,e=t[a+4>>2]|0,t[s>>2]=t[a>>2],t[s+4>>2]=e,t[u>>2]=t[s>>2],t[u+4>>2]=t[s+4>>2],n=Hm(n,u)|0,y=r,n|0}function ef(e){return e=e|0,(t[(Ul()|0)+24>>2]|0)+(e*12|0)|0}function Hm(e,n){e=e|0,n=n|0;var r=0,u=0,s=0;return s=y,y=y+16|0,u=s,r=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(r=t[(t[e>>2]|0)+r>>2]|0),I1[r&31](u,e),u=kc(u)|0,y=s,u|0}function kc(e){e=e|0;var n=0,r=0,u=0,s=0;return s=y,y=y+32|0,n=s+12|0,r=s,u=Pu(Hd()|0)|0,u?(rs(n,u),Mf(r,n),cv(e,r),e=Cs(n)|0):e=O1(e)|0,y=s,e|0}function Hd(){var e=0;return h[7736]|0||(Wo(9640),Wt(25,9640,ge|0)|0,e=7736,t[e>>2]=1,t[e+4>>2]=0),9640}function cv(e,n){e=e|0,n=n|0,Nc(n,e,e+8|0)|0}function O1(e){e=e|0;var n=0,r=0,u=0,s=0,a=0,v=0,w=0;return r=y,y=y+16|0,s=r+4|0,v=r,u=Oa(8)|0,n=u,w=pn(16)|0,t[w>>2]=t[e>>2],t[w+4>>2]=t[e+4>>2],t[w+8>>2]=t[e+8>>2],t[w+12>>2]=t[e+12>>2],a=n+4|0,t[a>>2]=w,e=pn(8)|0,a=t[a>>2]|0,t[v>>2]=0,t[s>>2]=t[v>>2],Bf(e,a,s),t[u>>2]=e,y=r,n|0}function Bf(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,r=pn(16)|0,t[r+4>>2]=0,t[r+8>>2]=0,t[r>>2]=1244,t[r+12>>2]=n,t[e+4>>2]=r}function Uf(e){e=e|0,Uv(e),Et(e)}function M1(e){e=e|0,e=t[e+12>>2]|0,e|0&&Et(e)}function jl(e){e=e|0,Et(e)}function Nc(e,n,r){return e=e|0,n=n|0,r=r|0,n=jf(t[e>>2]|0,n,r)|0,r=e+4|0,t[(t[r>>2]|0)+8>>2]=n,t[(t[r>>2]|0)+8>>2]|0}function jf(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0;return u=y,y=y+16|0,s=u,Ma(s),e=go(e)|0,r=qm(e,t[n>>2]|0,+j[r>>3])|0,ka(s),y=u,r|0}function qm(e,n,r){e=e|0,n=n|0,r=+r;var u=0;return u=_o(yl()|0)|0,n=sd(n)|0,Hr(0,u|0,e|0,n|0,+ +kl(r))|0}function yl(){var e=0;return h[7728]|0||(qd(9628),e=7728,t[e>>2]=1,t[e+4>>2]=0),9628}function qd(e){e=e|0,ll(e,Wd()|0,2)}function Wd(){return 1264}function Wo(e){e=e|0,Xa(e)}function Vd(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Wm(e,r,s,1),y=u}function Wm(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=k1()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=Vm(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,Gm(a,u)|0,u),y=s}function k1(){var e=0,n=0;if(h[7744]|0||(hv(9684),Wt(37,9684,ge|0)|0,n=7744,t[n>>2]=1,t[n+4>>2]=0),!(sr(9684)|0)){e=9684,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));hv(9684)}return 9684}function Vm(e){return e=e|0,0}function Gm(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=k1()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],dv(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(Ym(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function dv(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function Ym(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=pv(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,Km(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],dv(a,u,r),t[T>>2]=(t[T>>2]|0)+12,Xm(e,w),Qm(w),y=L;return}}function pv(e){return e=e|0,357913941}function Km(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function Xm(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function Qm(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function hv(e){e=e|0,Zm(e)}function Jm(e){e=e|0,Rp(e+24|0)}function Rp(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function Zm(e){e=e|0;var n=0;n=yr()|0,jn(e,2,5,n,zf()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function zf(){return 1280}function vv(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=mv(e)|0,e=t[v+4>>2]|0,t[a>>2]=t[v>>2],t[a+4>>2]=e,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],r=yv(n,s,r)|0,y=u,r|0}function mv(e){return e=e|0,(t[(k1()|0)+24>>2]|0)+(e*12|0)|0}function yv(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return v=y,y=y+32|0,s=v,a=v+16|0,u=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(u=t[(t[e>>2]|0)+u>>2]|0),xs(a,r),a=Gs(a,r)|0,Fy[u&15](s,e,a),a=kc(s)|0,y=v,a|0}function Gd(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Yd(e,r,s,1),y=u}function Yd(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=Ap()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=gv(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,Kd(a,u)|0,u),y=s}function Ap(){var e=0,n=0;if(h[7752]|0||(Sv(9720),Wt(38,9720,ge|0)|0,n=7752,t[n>>2]=1,t[n+4>>2]=0),!(sr(9720)|0)){e=9720,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));Sv(9720)}return 9720}function gv(e){return e=e|0,0}function Kd(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=Ap()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],_v(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(Ev(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function _v(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function Ev(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=Op(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,Dv(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],_v(a,u,r),t[T>>2]=(t[T>>2]|0)+12,wv(e,w),$m(w),y=L;return}}function Op(e){return e=e|0,357913941}function Dv(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function wv(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function $m(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function Sv(e){e=e|0,Tv(e)}function ey(e){e=e|0,Xd(e+24|0)}function Xd(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function Tv(e){e=e|0;var n=0;n=yr()|0,jn(e,2,8,n,Mp()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function Mp(){return 1288}function ty(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0;return r=y,y=y+16|0,u=r+8|0,s=r,a=l0(e)|0,e=t[a+4>>2]|0,t[s>>2]=t[a>>2],t[s+4>>2]=e,t[u>>2]=t[s>>2],t[u+4>>2]=t[s+4>>2],n=kp(n,u)|0,y=r,n|0}function l0(e){return e=e|0,(t[(Ap()|0)+24>>2]|0)+(e*12|0)|0}function kp(e,n){e=e|0,n=n|0;var r=0;return r=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(r=t[(t[e>>2]|0)+r>>2]|0),cd(Qp[r&31](e)|0)|0}function ny(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],ry(e,r,s,0),y=u}function ry(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=Np()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=tf(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,Lp(a,u)|0,u),y=s}function Np(){var e=0,n=0;if(h[7760]|0||(Ip(9756),Wt(39,9756,ge|0)|0,n=7760,t[n>>2]=1,t[n+4>>2]=0),!(sr(9756)|0)){e=9756,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));Ip(9756)}return 9756}function tf(e){return e=e|0,0}function Lp(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=Np()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],Fp(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(Pp(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function Fp(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function Pp(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=iy(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,uy(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],Fp(a,u,r),t[T>>2]=(t[T>>2]|0)+12,Cv(e,w),Hf(w),y=L;return}}function iy(e){return e=e|0,357913941}function uy(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function Cv(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function Hf(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function Ip(e){e=e|0,ly(e)}function xv(e){e=e|0,oy(e+24|0)}function oy(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function ly(e){e=e|0;var n=0;n=yr()|0,jn(e,2,8,n,bp()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function bp(){return 1292}function Bp(e,n,r){e=e|0,n=n|0,r=+r;var u=0,s=0,a=0,v=0;u=y,y=y+16|0,s=u+8|0,a=u,v=sy(e)|0,e=t[v+4>>2]|0,t[a>>2]=t[v>>2],t[a+4>>2]=e,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],ay(n,s,r),y=u}function sy(e){return e=e|0,(t[(Np()|0)+24>>2]|0)+(e*12|0)|0}function ay(e,n,r){e=e|0,n=n|0,r=+r;var u=0,s=0,a=0;a=y,y=y+16|0,s=a,u=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(u=t[(t[e>>2]|0)+u>>2]|0),Pl(s,r),r=+us(s,r),k8[u&31](e,r),y=a}function Rv(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Up(e,r,s,0),y=u}function Up(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=jp()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=Qd(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,fy(a,u)|0,u),y=s}function jp(){var e=0,n=0;if(h[7768]|0||(zp(9792),Wt(40,9792,ge|0)|0,n=7768,t[n>>2]=1,t[n+4>>2]=0),!(sr(9792)|0)){e=9792,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));zp(9792)}return 9792}function Qd(e){return e=e|0,0}function fy(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=jp()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],N1(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(cy(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function N1(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function cy(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=Av(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,Ov(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],N1(a,u,r),t[T>>2]=(t[T>>2]|0)+12,dy(e,w),qf(w),y=L;return}}function Av(e){return e=e|0,357913941}function Ov(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function dy(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function qf(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function zp(e){e=e|0,hy(e)}function Mv(e){e=e|0,py(e+24|0)}function py(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function hy(e){e=e|0;var n=0;n=yr()|0,jn(e,2,1,n,Hp()|0,2),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function Hp(){return 1300}function vy(e,n,r,u){e=e|0,n=n|0,r=r|0,u=+u;var s=0,a=0,v=0,w=0;s=y,y=y+16|0,a=s+8|0,v=s,w=Zs(e)|0,e=t[w+4>>2]|0,t[v>>2]=t[w>>2],t[v+4>>2]=e,t[a>>2]=t[v>>2],t[a+4>>2]=t[v+4>>2],my(n,a,r,u),y=s}function Zs(e){return e=e|0,(t[(jp()|0)+24>>2]|0)+(e*12|0)|0}function my(e,n,r,u){e=e|0,n=n|0,r=r|0,u=+u;var s=0,a=0,v=0,w=0;w=y,y=y+16|0,a=w+1|0,v=w,s=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(s=t[(t[e>>2]|0)+s>>2]|0),xs(a,r),a=Gs(a,r)|0,Pl(v,u),u=+us(v,u),U8[s&15](e,a,u),y=w}function p(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],m(e,r,s,0),y=u}function m(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=R()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=I(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,W(a,u)|0,u),y=s}function R(){var e=0,n=0;if(h[7776]|0||(Ot(9828),Wt(41,9828,ge|0)|0,n=7776,t[n>>2]=1,t[n+4>>2]=0),!(sr(9828)|0)){e=9828,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));Ot(9828)}return 9828}function I(e){return e=e|0,0}function W(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=R()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],te(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(pe(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function te(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function pe(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=Ee(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,be(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],te(a,u,r),t[T>>2]=(t[T>>2]|0)+12,Dt(e,w),Tt(w),y=L;return}}function Ee(e){return e=e|0,357913941}function be(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function Dt(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function Tt(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function Ot(e){e=e|0,rr(e)}function on(e){e=e|0,Mn(e+24|0)}function Mn(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function rr(e){e=e|0;var n=0;n=yr()|0,jn(e,2,7,n,br()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function br(){return 1312}function ar(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;u=y,y=y+16|0,s=u+8|0,a=u,v=ri(e)|0,e=t[v+4>>2]|0,t[a>>2]=t[v>>2],t[a+4>>2]=e,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],fi(n,s,r),y=u}function ri(e){return e=e|0,(t[(R()|0)+24>>2]|0)+(e*12|0)|0}function fi(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0;a=y,y=y+16|0,s=a,u=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(u=t[(t[e>>2]|0)+u>>2]|0),xs(s,r),s=Gs(s,r)|0,I1[u&31](e,s),y=a}function zl(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Zi(e,r,s,0),y=u}function Zi(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=so()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=s0(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,Os(a,u)|0,u),y=s}function so(){var e=0,n=0;if(h[7784]|0||(Vg(9864),Wt(42,9864,ge|0)|0,n=7784,t[n>>2]=1,t[n+4>>2]=0),!(sr(9864)|0)){e=9864,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));Vg(9864)}return 9864}function s0(e){return e=e|0,0}function Os(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=so()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],Co(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(kv(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function Co(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function kv(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=F4(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,yy(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],Co(a,u,r),t[T>>2]=(t[T>>2]|0)+12,gy(e,w),nf(w),y=L;return}}function F4(e){return e=e|0,357913941}function yy(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function gy(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function nf(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function Vg(e){e=e|0,b4(e)}function P4(e){e=e|0,I4(e+24|0)}function I4(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function b4(e){e=e|0;var n=0;n=yr()|0,jn(e,2,8,n,B4()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function B4(){return 1320}function _y(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;u=y,y=y+16|0,s=u+8|0,a=u,v=U4(e)|0,e=t[v+4>>2]|0,t[a>>2]=t[v>>2],t[a+4>>2]=e,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],j4(n,s,r),y=u}function U4(e){return e=e|0,(t[(so()|0)+24>>2]|0)+(e*12|0)|0}function j4(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0;a=y,y=y+16|0,s=a,u=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(u=t[(t[e>>2]|0)+u>>2]|0),Ey(s,r),s=Gg(s,r)|0,I1[u&31](e,s),y=a}function Ey(e,n){e=e|0,n=n|0}function Gg(e,n){return e=e|0,n=n|0,z4(n)|0}function z4(e){return e=e|0,e|0}function H4(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],Yg(e,r,s,0),y=u}function Yg(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=Wf()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=Kg(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,q4(a,u)|0,u),y=s}function Wf(){var e=0,n=0;if(h[7792]|0||(Sy(9900),Wt(43,9900,ge|0)|0,n=7792,t[n>>2]=1,t[n+4>>2]=0),!(sr(9900)|0)){e=9900,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));Sy(9900)}return 9900}function Kg(e){return e=e|0,0}function q4(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=Wf()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],qp(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(W4(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function qp(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function W4(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=Nv(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,Dy(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],qp(a,u,r),t[T>>2]=(t[T>>2]|0)+12,wy(e,w),V4(w),y=L;return}}function Nv(e){return e=e|0,357913941}function Dy(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function wy(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function V4(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function Sy(e){e=e|0,Xg(e)}function G4(e){e=e|0,Y4(e+24|0)}function Y4(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function Xg(e){e=e|0;var n=0;n=yr()|0,jn(e,2,22,n,K4()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function K4(){return 1344}function X4(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0;r=y,y=y+16|0,u=r+8|0,s=r,a=Qg(e)|0,e=t[a+4>>2]|0,t[s>>2]=t[a>>2],t[s+4>>2]=e,t[u>>2]=t[s>>2],t[u+4>>2]=t[s+4>>2],Lv(n,u),y=r}function Qg(e){return e=e|0,(t[(Wf()|0)+24>>2]|0)+(e*12|0)|0}function Lv(e,n){e=e|0,n=n|0;var r=0;r=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(r=t[(t[e>>2]|0)+r>>2]|0),P1[r&127](e)}function Q4(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0;a=t[e>>2]|0,s=Ty()|0,e=J4(r)|0,wi(a,n,s,e,Z4(r,u)|0,u)}function Ty(){var e=0,n=0;if(h[7800]|0||(xy(9936),Wt(44,9936,ge|0)|0,n=7800,t[n>>2]=1,t[n+4>>2]=0),!(sr(9936)|0)){e=9936,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));xy(9936)}return 9936}function J4(e){return e=e|0,e|0}function Z4(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0;return w=y,y=y+16|0,s=w,a=w+4|0,t[s>>2]=e,T=Ty()|0,v=T+24|0,n=hn(n,4)|0,t[a>>2]=n,r=T+28|0,u=t[r>>2]|0,u>>>0<(t[T+32>>2]|0)>>>0?(Cy(u,e,n),n=(t[r>>2]|0)+8|0,t[r>>2]=n):(Jg(v,s,a),n=t[r>>2]|0),y=w,(n-(t[v>>2]|0)>>3)+-1|0}function Cy(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,t[e+4>>2]=r}function Jg(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0;if(w=y,y=y+32|0,s=w,a=e+4|0,v=((t[a>>2]|0)-(t[e>>2]|0)>>3)+1|0,u=Zg(e)|0,u>>>0>>0)di(e);else{T=t[e>>2]|0,M=(t[e+8>>2]|0)-T|0,L=M>>2,$g(s,M>>3>>>0>>1>>>0?L>>>0>>0?v:L:u,(t[a>>2]|0)-T>>3,e+8|0),v=s+8|0,Cy(t[v>>2]|0,t[n>>2]|0,t[r>>2]|0),t[v>>2]=(t[v>>2]|0)+8,e_(e,s),t_(s),y=w;return}}function Zg(e){return e=e|0,536870911}function $g(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>536870911)$n();else{s=pn(n<<3)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r<<3)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n<<3)}function e_(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(0-(s>>3)<<3)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function t_(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~((u+-8-n|0)>>>3)<<3)),e=t[e>>2]|0,e|0&&Et(e)}function xy(e){e=e|0,r_(e)}function n_(e){e=e|0,$4(e+24|0)}function $4(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function r_(e){e=e|0;var n=0;n=yr()|0,jn(e,1,23,n,So()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function eE(e,n){e=e|0,n=n|0,c(t[(tE(e)|0)>>2]|0,n)}function tE(e){return e=e|0,(t[(Ty()|0)+24>>2]|0)+(e<<3)|0}function c(e,n){e=e|0,n=n|0;var r=0,u=0;r=y,y=y+16|0,u=r,tr(u,n),n=Qs(u,n)|0,P1[e&127](n),y=r}function d(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0;a=t[e>>2]|0,s=D()|0,e=C(r)|0,wi(a,n,s,e,O(r,u)|0,u)}function D(){var e=0,n=0;if(h[7808]|0||(ht(9972),Wt(45,9972,ge|0)|0,n=7808,t[n>>2]=1,t[n+4>>2]=0),!(sr(9972)|0)){e=9972,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));ht(9972)}return 9972}function C(e){return e=e|0,e|0}function O(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0;return w=y,y=y+16|0,s=w,a=w+4|0,t[s>>2]=e,T=D()|0,v=T+24|0,n=hn(n,4)|0,t[a>>2]=n,r=T+28|0,u=t[r>>2]|0,u>>>0<(t[T+32>>2]|0)>>>0?(z(u,e,n),n=(t[r>>2]|0)+8|0,t[r>>2]=n):(G(v,s,a),n=t[r>>2]|0),y=w,(n-(t[v>>2]|0)>>3)+-1|0}function z(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,t[e+4>>2]=r}function G(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0;if(w=y,y=y+32|0,s=w,a=e+4|0,v=((t[a>>2]|0)-(t[e>>2]|0)>>3)+1|0,u=ne(e)|0,u>>>0>>0)di(e);else{T=t[e>>2]|0,M=(t[e+8>>2]|0)-T|0,L=M>>2,se(s,M>>3>>>0>>1>>>0?L>>>0>>0?v:L:u,(t[a>>2]|0)-T>>3,e+8|0),v=s+8|0,z(t[v>>2]|0,t[n>>2]|0,t[r>>2]|0),t[v>>2]=(t[v>>2]|0)+8,Ue(e,s),Xe(s),y=w;return}}function ne(e){return e=e|0,536870911}function se(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>536870911)$n();else{s=pn(n<<3)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r<<3)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n<<3)}function Ue(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(0-(s>>3)<<3)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function Xe(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~((u+-8-n|0)>>>3)<<3)),e=t[e>>2]|0,e|0&&Et(e)}function ht(e){e=e|0,Ht(e)}function Lt(e){e=e|0,Gt(e+24|0)}function Gt(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function Ht(e){e=e|0;var n=0;n=yr()|0,jn(e,1,9,n,yn()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function yn(){return 1348}function kr(e,n){return e=e|0,n=n|0,Oi(t[(ii(e)|0)>>2]|0,n)|0}function ii(e){return e=e|0,(t[(D()|0)+24>>2]|0)+(e<<3)|0}function Oi(e,n){e=e|0,n=n|0;var r=0,u=0;return r=y,y=y+16|0,u=r,L0(u,n),n=$i(u,n)|0,n=Sd(Qp[e&31](n)|0)|0,y=r,n|0}function L0(e,n){e=e|0,n=n|0}function $i(e,n){return e=e|0,n=n|0,lt(n)|0}function lt(e){return e=e|0,e|0}function Mt(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0;a=t[e>>2]|0,s=$e()|0,e=jt(r)|0,wi(a,n,s,e,Fn(r,u)|0,u)}function $e(){var e=0,n=0;if(h[7816]|0||(Yr(10008),Wt(46,10008,ge|0)|0,n=7816,t[n>>2]=1,t[n+4>>2]=0),!(sr(10008)|0)){e=10008,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));Yr(10008)}return 10008}function jt(e){return e=e|0,e|0}function Fn(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0;return w=y,y=y+16|0,s=w,a=w+4|0,t[s>>2]=e,T=$e()|0,v=T+24|0,n=hn(n,4)|0,t[a>>2]=n,r=T+28|0,u=t[r>>2]|0,u>>>0<(t[T+32>>2]|0)>>>0?(vn(u,e,n),n=(t[r>>2]|0)+8|0,t[r>>2]=n):(Vi(v,s,a),n=t[r>>2]|0),y=w,(n-(t[v>>2]|0)>>3)+-1|0}function vn(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,t[e+4>>2]=r}function Vi(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0;if(w=y,y=y+32|0,s=w,a=e+4|0,v=((t[a>>2]|0)-(t[e>>2]|0)>>3)+1|0,u=ci(e)|0,u>>>0>>0)di(e);else{T=t[e>>2]|0,M=(t[e+8>>2]|0)-T|0,L=M>>2,Yu(s,M>>3>>>0>>1>>>0?L>>>0>>0?v:L:u,(t[a>>2]|0)-T>>3,e+8|0),v=s+8|0,vn(t[v>>2]|0,t[n>>2]|0,t[r>>2]|0),t[v>>2]=(t[v>>2]|0)+8,hr(e,s),pu(s),y=w;return}}function ci(e){return e=e|0,536870911}function Yu(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>536870911)$n();else{s=pn(n<<3)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r<<3)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n<<3)}function hr(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(0-(s>>3)<<3)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function pu(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~((u+-8-n|0)>>>3)<<3)),e=t[e>>2]|0,e|0&&Et(e)}function Yr(e){e=e|0,W0(e)}function Cu(e){e=e|0,D0(e+24|0)}function D0(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function W0(e){e=e|0;var n=0;n=yr()|0,jn(e,1,15,n,ip()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function Ms(e){return e=e|0,gl(t[(Ku(e)|0)>>2]|0)|0}function Ku(e){return e=e|0,(t[($e()|0)+24>>2]|0)+(e<<3)|0}function gl(e){return e=e|0,Sd(E_[e&7]()|0)|0}function rf(){var e=0;return h[7832]|0||(u_(10052),Wt(25,10052,ge|0)|0,e=7832,t[e>>2]=1,t[e+4>>2]=0),10052}function Vo(e,n){e=e|0,n=n|0,t[e>>2]=ks()|0,t[e+4>>2]=Jd()|0,t[e+12>>2]=n,t[e+8>>2]=Vf()|0,t[e+32>>2]=2}function ks(){return 11709}function Jd(){return 1188}function Vf(){return L1()|0}function Lc(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0,(Hl(u,896)|0)==512?r|0&&(Go(r),Et(r)):n|0&&(Ds(n),Et(n))}function Hl(e,n){return e=e|0,n=n|0,n&e|0}function Go(e){e=e|0,e=t[e+4>>2]|0,e|0&&$d(e)}function L1(){var e=0;return h[7824]|0||(t[2511]=i_()|0,t[2512]=0,e=7824,t[e>>2]=1,t[e+4>>2]=0),10044}function i_(){return 0}function u_(e){e=e|0,Xa(e)}function nE(e){e=e|0;var n=0,r=0,u=0,s=0,a=0;n=y,y=y+32|0,r=n+24|0,a=n+16|0,s=n+8|0,u=n,o_(e,4827),rE(e,4834,3)|0,iE(e,3682,47)|0,t[a>>2]=9,t[a+4>>2]=0,t[r>>2]=t[a>>2],t[r+4>>2]=t[a+4>>2],Ry(e,4841,r)|0,t[s>>2]=1,t[s+4>>2]=0,t[r>>2]=t[s>>2],t[r+4>>2]=t[s+4>>2],l_(e,4871,r)|0,t[u>>2]=10,t[u+4>>2]=0,t[r>>2]=t[u>>2],t[r+4>>2]=t[u+4>>2],uE(e,4891,r)|0,y=n}function o_(e,n){e=e|0,n=n|0;var r=0;r=PR()|0,t[e>>2]=r,IR(r,n),Zd(t[e>>2]|0)}function rE(e,n,r){return e=e|0,n=n|0,r=r|0,_R(e,Fr(n)|0,r,0),e|0}function iE(e,n,r){return e=e|0,n=n|0,r=r|0,iR(e,Fr(n)|0,r,0),e|0}function Ry(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],U9(e,n,s),y=u,e|0}function l_(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],E9(e,n,s),y=u,e|0}function uE(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=t[r+4>>2]|0,t[a>>2]=t[r>>2],t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],oE(e,n,s),y=u,e|0}function oE(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],lE(e,r,s,1),y=u}function lE(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=sE()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=o9(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,l9(a,u)|0,u),y=s}function sE(){var e=0,n=0;if(h[7840]|0||(hw(10100),Wt(48,10100,ge|0)|0,n=7840,t[n>>2]=1,t[n+4>>2]=0),!(sr(10100)|0)){e=10100,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));hw(10100)}return 10100}function o9(e){return e=e|0,0}function l9(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=sE()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],pw(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(s9(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function pw(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function s9(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=a9(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,f9(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],pw(a,u,r),t[T>>2]=(t[T>>2]|0)+12,c9(e,w),d9(w),y=L;return}}function a9(e){return e=e|0,357913941}function f9(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function c9(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function d9(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function hw(e){e=e|0,v9(e)}function p9(e){e=e|0,h9(e+24|0)}function h9(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function v9(e){e=e|0;var n=0;n=yr()|0,jn(e,2,6,n,m9()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function m9(){return 1364}function y9(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;return u=y,y=y+16|0,s=u+8|0,a=u,v=g9(e)|0,e=t[v+4>>2]|0,t[a>>2]=t[v>>2],t[a+4>>2]=e,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],r=_9(n,s,r)|0,y=u,r|0}function g9(e){return e=e|0,(t[(sE()|0)+24>>2]|0)+(e*12|0)|0}function _9(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0;return a=y,y=y+16|0,s=a,u=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(u=t[(t[e>>2]|0)+u>>2]|0),xs(s,r),s=Gs(s,r)|0,s=bl(bE[u&15](e,s)|0)|0,y=a,s|0}function E9(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],D9(e,r,s,0),y=u}function D9(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=aE()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=w9(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,S9(a,u)|0,u),y=s}function aE(){var e=0,n=0;if(h[7848]|0||(mw(10136),Wt(49,10136,ge|0)|0,n=7848,t[n>>2]=1,t[n+4>>2]=0),!(sr(10136)|0)){e=10136,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));mw(10136)}return 10136}function w9(e){return e=e|0,0}function S9(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=aE()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],vw(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(T9(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function vw(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function T9(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=C9(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,x9(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],vw(a,u,r),t[T>>2]=(t[T>>2]|0)+12,R9(e,w),A9(w),y=L;return}}function C9(e){return e=e|0,357913941}function x9(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function R9(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function A9(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function mw(e){e=e|0,k9(e)}function O9(e){e=e|0,M9(e+24|0)}function M9(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function k9(e){e=e|0;var n=0;n=yr()|0,jn(e,2,9,n,N9()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function N9(){return 1372}function L9(e,n,r){e=e|0,n=n|0,r=+r;var u=0,s=0,a=0,v=0;u=y,y=y+16|0,s=u+8|0,a=u,v=F9(e)|0,e=t[v+4>>2]|0,t[a>>2]=t[v>>2],t[a+4>>2]=e,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],P9(n,s,r),y=u}function F9(e){return e=e|0,(t[(aE()|0)+24>>2]|0)+(e*12|0)|0}function P9(e,n,r){e=e|0,n=n|0,r=+r;var u=0,s=0,a=0,v=Ct;a=y,y=y+16|0,s=a,u=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(u=t[(t[e>>2]|0)+u>>2]|0),I9(s,r),v=S(b9(s,r)),M8[u&1](e,v),y=a}function I9(e,n){e=e|0,n=+n}function b9(e,n){return e=e|0,n=+n,S(B9(n))}function B9(e){return e=+e,S(e)}function U9(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,s=u+8|0,a=u,w=t[r>>2]|0,v=t[r+4>>2]|0,r=Fr(n)|0,t[a>>2]=w,t[a+4>>2]=v,t[s>>2]=t[a>>2],t[s+4>>2]=t[a+4>>2],j9(e,r,s,0),y=u}function j9(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0,T=0,L=0,M=0;s=y,y=y+32|0,a=s+16|0,M=s+8|0,w=s,L=t[r>>2]|0,T=t[r+4>>2]|0,v=t[e>>2]|0,e=fE()|0,t[M>>2]=L,t[M+4>>2]=T,t[a>>2]=t[M>>2],t[a+4>>2]=t[M+4>>2],r=z9(a)|0,t[w>>2]=L,t[w+4>>2]=T,t[a>>2]=t[w>>2],t[a+4>>2]=t[w+4>>2],wi(v,n,e,r,H9(a,u)|0,u),y=s}function fE(){var e=0,n=0;if(h[7856]|0||(gw(10172),Wt(50,10172,ge|0)|0,n=7856,t[n>>2]=1,t[n+4>>2]=0),!(sr(10172)|0)){e=10172,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));gw(10172)}return 10172}function z9(e){return e=e|0,0}function H9(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0;return M=y,y=y+32|0,s=M+24|0,v=M+16|0,w=M,T=M+8|0,a=t[e>>2]|0,u=t[e+4>>2]|0,t[w>>2]=a,t[w+4>>2]=u,b=fE()|0,L=b+24|0,e=hn(n,4)|0,t[T>>2]=e,n=b+28|0,r=t[n>>2]|0,r>>>0<(t[b+32>>2]|0)>>>0?(t[v>>2]=a,t[v+4>>2]=u,t[s>>2]=t[v>>2],t[s+4>>2]=t[v+4>>2],yw(r,s,e),e=(t[n>>2]|0)+12|0,t[n>>2]=e):(q9(L,w,T),e=t[n>>2]|0),y=M,((e-(t[L>>2]|0)|0)/12|0)+-1|0}function yw(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=t[n+4>>2]|0,t[e>>2]=t[n>>2],t[e+4>>2]=u,t[e+8>>2]=r}function q9(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;if(L=y,y=y+48|0,u=L+32|0,v=L+24|0,w=L,T=e+4|0,s=(((t[T>>2]|0)-(t[e>>2]|0)|0)/12|0)+1|0,a=W9(e)|0,a>>>0>>0)di(e);else{M=t[e>>2]|0,X=((t[e+8>>2]|0)-M|0)/12|0,b=X<<1,V9(w,X>>>0>>1>>>0?b>>>0>>0?s:b:a,((t[T>>2]|0)-M|0)/12|0,e+8|0),T=w+8|0,a=t[T>>2]|0,s=t[n+4>>2]|0,r=t[r>>2]|0,t[v>>2]=t[n>>2],t[v+4>>2]=s,t[u>>2]=t[v>>2],t[u+4>>2]=t[v+4>>2],yw(a,u,r),t[T>>2]=(t[T>>2]|0)+12,G9(e,w),Y9(w),y=L;return}}function W9(e){return e=e|0,357913941}function V9(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>357913941)$n();else{s=pn(n*12|0)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r*12|0)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n*12|0)}function G9(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(((s|0)/-12|0)*12|0)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function Y9(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~(((u+-12-n|0)>>>0)/12|0)*12|0)),e=t[e>>2]|0,e|0&&Et(e)}function gw(e){e=e|0,Q9(e)}function K9(e){e=e|0,X9(e+24|0)}function X9(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~(((n+-12-u|0)>>>0)/12|0)*12|0)),Et(r))}function Q9(e){e=e|0;var n=0;n=yr()|0,jn(e,2,3,n,J9()|0,2),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function J9(){return 1380}function Z9(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0;s=y,y=y+16|0,a=s+8|0,v=s,w=$9(e)|0,e=t[w+4>>2]|0,t[v>>2]=t[w>>2],t[v+4>>2]=e,t[a>>2]=t[v>>2],t[a+4>>2]=t[v+4>>2],eR(n,a,r,u),y=s}function $9(e){return e=e|0,(t[(fE()|0)+24>>2]|0)+(e*12|0)|0}function eR(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0;w=y,y=y+16|0,a=w+1|0,v=w,s=t[n>>2]|0,n=t[n+4>>2]|0,e=e+(n>>1)|0,n&1&&(s=t[(t[e>>2]|0)+s>>2]|0),xs(a,r),a=Gs(a,r)|0,tR(v,u),v=nR(v,u)|0,Fy[s&15](e,a,v),y=w}function tR(e,n){e=e|0,n=n|0}function nR(e,n){return e=e|0,n=n|0,rR(n)|0}function rR(e){return e=e|0,(e|0)!=0|0}function iR(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0;a=t[e>>2]|0,s=cE()|0,e=uR(r)|0,wi(a,n,s,e,oR(r,u)|0,u)}function cE(){var e=0,n=0;if(h[7864]|0||(Ew(10208),Wt(51,10208,ge|0)|0,n=7864,t[n>>2]=1,t[n+4>>2]=0),!(sr(10208)|0)){e=10208,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));Ew(10208)}return 10208}function uR(e){return e=e|0,e|0}function oR(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0;return w=y,y=y+16|0,s=w,a=w+4|0,t[s>>2]=e,T=cE()|0,v=T+24|0,n=hn(n,4)|0,t[a>>2]=n,r=T+28|0,u=t[r>>2]|0,u>>>0<(t[T+32>>2]|0)>>>0?(_w(u,e,n),n=(t[r>>2]|0)+8|0,t[r>>2]=n):(lR(v,s,a),n=t[r>>2]|0),y=w,(n-(t[v>>2]|0)>>3)+-1|0}function _w(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,t[e+4>>2]=r}function lR(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0;if(w=y,y=y+32|0,s=w,a=e+4|0,v=((t[a>>2]|0)-(t[e>>2]|0)>>3)+1|0,u=sR(e)|0,u>>>0>>0)di(e);else{T=t[e>>2]|0,M=(t[e+8>>2]|0)-T|0,L=M>>2,aR(s,M>>3>>>0>>1>>>0?L>>>0>>0?v:L:u,(t[a>>2]|0)-T>>3,e+8|0),v=s+8|0,_w(t[v>>2]|0,t[n>>2]|0,t[r>>2]|0),t[v>>2]=(t[v>>2]|0)+8,fR(e,s),cR(s),y=w;return}}function sR(e){return e=e|0,536870911}function aR(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>536870911)$n();else{s=pn(n<<3)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r<<3)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n<<3)}function fR(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(0-(s>>3)<<3)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function cR(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~((u+-8-n|0)>>>3)<<3)),e=t[e>>2]|0,e|0&&Et(e)}function Ew(e){e=e|0,hR(e)}function dR(e){e=e|0,pR(e+24|0)}function pR(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function hR(e){e=e|0;var n=0;n=yr()|0,jn(e,1,24,n,vR()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function vR(){return 1392}function mR(e,n){e=e|0,n=n|0,gR(t[(yR(e)|0)>>2]|0,n)}function yR(e){return e=e|0,(t[(cE()|0)+24>>2]|0)+(e<<3)|0}function gR(e,n){e=e|0,n=n|0;var r=0,u=0;r=y,y=y+16|0,u=r,L0(u,n),n=$i(u,n)|0,P1[e&127](n),y=r}function _R(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0;a=t[e>>2]|0,s=dE()|0,e=ER(r)|0,wi(a,n,s,e,DR(r,u)|0,u)}function dE(){var e=0,n=0;if(h[7872]|0||(ww(10244),Wt(52,10244,ge|0)|0,n=7872,t[n>>2]=1,t[n+4>>2]=0),!(sr(10244)|0)){e=10244,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));ww(10244)}return 10244}function ER(e){return e=e|0,e|0}function DR(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0;return w=y,y=y+16|0,s=w,a=w+4|0,t[s>>2]=e,T=dE()|0,v=T+24|0,n=hn(n,4)|0,t[a>>2]=n,r=T+28|0,u=t[r>>2]|0,u>>>0<(t[T+32>>2]|0)>>>0?(Dw(u,e,n),n=(t[r>>2]|0)+8|0,t[r>>2]=n):(wR(v,s,a),n=t[r>>2]|0),y=w,(n-(t[v>>2]|0)>>3)+-1|0}function Dw(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,t[e+4>>2]=r}function wR(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0;if(w=y,y=y+32|0,s=w,a=e+4|0,v=((t[a>>2]|0)-(t[e>>2]|0)>>3)+1|0,u=SR(e)|0,u>>>0>>0)di(e);else{T=t[e>>2]|0,M=(t[e+8>>2]|0)-T|0,L=M>>2,TR(s,M>>3>>>0>>1>>>0?L>>>0>>0?v:L:u,(t[a>>2]|0)-T>>3,e+8|0),v=s+8|0,Dw(t[v>>2]|0,t[n>>2]|0,t[r>>2]|0),t[v>>2]=(t[v>>2]|0)+8,CR(e,s),xR(s),y=w;return}}function SR(e){return e=e|0,536870911}function TR(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>536870911)$n();else{s=pn(n<<3)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r<<3)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n<<3)}function CR(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(0-(s>>3)<<3)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function xR(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~((u+-8-n|0)>>>3)<<3)),e=t[e>>2]|0,e|0&&Et(e)}function ww(e){e=e|0,OR(e)}function RR(e){e=e|0,AR(e+24|0)}function AR(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function OR(e){e=e|0;var n=0;n=yr()|0,jn(e,1,16,n,MR()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function MR(){return 1400}function kR(e){return e=e|0,LR(t[(NR(e)|0)>>2]|0)|0}function NR(e){return e=e|0,(t[(dE()|0)+24>>2]|0)+(e<<3)|0}function LR(e){return e=e|0,FR(E_[e&7]()|0)|0}function FR(e){return e=e|0,e|0}function PR(){var e=0;return h[7880]|0||(HR(10280),Wt(25,10280,ge|0)|0,e=7880,t[e>>2]=1,t[e+4>>2]=0),10280}function IR(e,n){e=e|0,n=n|0,t[e>>2]=bR()|0,t[e+4>>2]=BR()|0,t[e+12>>2]=n,t[e+8>>2]=UR()|0,t[e+32>>2]=4}function bR(){return 11711}function BR(){return 1356}function UR(){return L1()|0}function jR(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0,(Hl(u,896)|0)==512?r|0&&(zR(r),Et(r)):n|0&&(ro(n),Et(n))}function zR(e){e=e|0,e=t[e+4>>2]|0,e|0&&$d(e)}function HR(e){e=e|0,Xa(e)}function qR(e){e=e|0,WR(e,4920),VR(e)|0,GR(e)|0}function WR(e,n){e=e|0,n=n|0;var r=0;r=Hd()|0,t[e>>2]=r,pA(r,n),Zd(t[e>>2]|0)}function VR(e){e=e|0;var n=0;return n=t[e>>2]|0,Wp(n,rA()|0),e|0}function GR(e){e=e|0;var n=0;return n=t[e>>2]|0,Wp(n,YR()|0),e|0}function YR(){var e=0;return h[7888]|0||(Sw(10328),Wt(53,10328,ge|0)|0,e=7888,t[e>>2]=1,t[e+4>>2]=0),sr(10328)|0||Sw(10328),10328}function Wp(e,n){e=e|0,n=n|0,wi(e,0,n,0,0,0)}function Sw(e){e=e|0,QR(e),Vp(e,10)}function KR(e){e=e|0,XR(e+24|0)}function XR(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function QR(e){e=e|0;var n=0;n=yr()|0,jn(e,5,1,n,eA()|0,2),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function JR(e,n,r){e=e|0,n=n|0,r=+r,ZR(e,n,r)}function Vp(e,n){e=e|0,n=n|0,t[e+20>>2]=n}function ZR(e,n,r){e=e|0,n=n|0,r=+r;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+16|0,a=u+8|0,w=u+13|0,s=u,v=u+12|0,xs(w,n),t[a>>2]=Gs(w,n)|0,Pl(v,r),j[s>>3]=+us(v,r),$R(e,a,s),y=u}function $R(e,n,r){e=e|0,n=n|0,r=r|0,B(e+8|0,t[n>>2]|0,+j[r>>3]),h[e+24>>0]=1}function eA(){return 1404}function tA(e,n){return e=e|0,n=+n,nA(e,n)|0}function nA(e,n){e=e|0,n=+n;var r=0,u=0,s=0,a=0,v=0,w=0,T=0;return u=y,y=y+16|0,a=u+4|0,v=u+8|0,w=u,s=Oa(8)|0,r=s,T=pn(16)|0,xs(a,e),e=Gs(a,e)|0,Pl(v,n),B(T,e,+us(v,n)),v=r+4|0,t[v>>2]=T,e=pn(8)|0,v=t[v>>2]|0,t[w>>2]=0,t[a>>2]=t[w>>2],Bf(e,v,a),t[s>>2]=e,y=u,r|0}function rA(){var e=0;return h[7896]|0||(Tw(10364),Wt(54,10364,ge|0)|0,e=7896,t[e>>2]=1,t[e+4>>2]=0),sr(10364)|0||Tw(10364),10364}function Tw(e){e=e|0,oA(e),Vp(e,55)}function iA(e){e=e|0,uA(e+24|0)}function uA(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function oA(e){e=e|0;var n=0;n=yr()|0,jn(e,5,4,n,fA()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function lA(e){e=e|0,sA(e)}function sA(e){e=e|0,aA(e)}function aA(e){e=e|0,Cw(e+8|0),h[e+24>>0]=1}function Cw(e){e=e|0,t[e>>2]=0,j[e+8>>3]=0}function fA(){return 1424}function cA(){return dA()|0}function dA(){var e=0,n=0,r=0,u=0,s=0,a=0,v=0;return n=y,y=y+16|0,s=n+4|0,v=n,r=Oa(8)|0,e=r,u=pn(16)|0,Cw(u),a=e+4|0,t[a>>2]=u,u=pn(8)|0,a=t[a>>2]|0,t[v>>2]=0,t[s>>2]=t[v>>2],Bf(u,a,s),t[r>>2]=u,y=n,e|0}function pA(e,n){e=e|0,n=n|0,t[e>>2]=hA()|0,t[e+4>>2]=vA()|0,t[e+12>>2]=n,t[e+8>>2]=mA()|0,t[e+32>>2]=5}function hA(){return 11710}function vA(){return 1416}function mA(){return s_()|0}function yA(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0,(Hl(u,896)|0)==512?r|0&&(gA(r),Et(r)):n|0&&Et(n)}function gA(e){e=e|0,e=t[e+4>>2]|0,e|0&&$d(e)}function s_(){var e=0;return h[7904]|0||(t[2600]=_A()|0,t[2601]=0,e=7904,t[e>>2]=1,t[e+4>>2]=0),10400}function _A(){return t[357]|0}function EA(e){e=e|0,DA(e,4926),wA(e)|0}function DA(e,n){e=e|0,n=n|0;var r=0;r=Ka()|0,t[e>>2]=r,LA(r,n),Zd(t[e>>2]|0)}function wA(e){e=e|0;var n=0;return n=t[e>>2]|0,Wp(n,SA()|0),e|0}function SA(){var e=0;return h[7912]|0||(xw(10412),Wt(56,10412,ge|0)|0,e=7912,t[e>>2]=1,t[e+4>>2]=0),sr(10412)|0||xw(10412),10412}function xw(e){e=e|0,xA(e),Vp(e,57)}function TA(e){e=e|0,CA(e+24|0)}function CA(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function xA(e){e=e|0;var n=0;n=yr()|0,jn(e,5,5,n,MA()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function RA(e){e=e|0,AA(e)}function AA(e){e=e|0,OA(e)}function OA(e){e=e|0;var n=0,r=0;n=e+8|0,r=n+48|0;do t[n>>2]=0,n=n+4|0;while((n|0)<(r|0));h[e+56>>0]=1}function MA(){return 1432}function kA(){return NA()|0}function NA(){var e=0,n=0,r=0,u=0,s=0,a=0,v=0,w=0;v=y,y=y+16|0,e=v+4|0,n=v,r=Oa(8)|0,u=r,s=pn(48)|0,a=s,w=a+48|0;do t[a>>2]=0,a=a+4|0;while((a|0)<(w|0));return a=u+4|0,t[a>>2]=s,w=pn(8)|0,a=t[a>>2]|0,t[n>>2]=0,t[e>>2]=t[n>>2],Th(w,a,e),t[r>>2]=w,y=v,u|0}function LA(e,n){e=e|0,n=n|0,t[e>>2]=FA()|0,t[e+4>>2]=PA()|0,t[e+12>>2]=n,t[e+8>>2]=IA()|0,t[e+32>>2]=6}function FA(){return 11704}function PA(){return 1436}function IA(){return s_()|0}function bA(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0,(Hl(u,896)|0)==512?r|0&&(BA(r),Et(r)):n|0&&Et(n)}function BA(e){e=e|0,e=t[e+4>>2]|0,e|0&&$d(e)}function UA(e){e=e|0,jA(e,4933),zA(e)|0,HA(e)|0}function jA(e,n){e=e|0,n=n|0;var r=0;r=d7()|0,t[e>>2]=r,p7(r,n),Zd(t[e>>2]|0)}function zA(e){e=e|0;var n=0;return n=t[e>>2]|0,Wp(n,n7()|0),e|0}function HA(e){e=e|0;var n=0;return n=t[e>>2]|0,Wp(n,qA()|0),e|0}function qA(){var e=0;return h[7920]|0||(Rw(10452),Wt(58,10452,ge|0)|0,e=7920,t[e>>2]=1,t[e+4>>2]=0),sr(10452)|0||Rw(10452),10452}function Rw(e){e=e|0,GA(e),Vp(e,1)}function WA(e){e=e|0,VA(e+24|0)}function VA(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function GA(e){e=e|0;var n=0;n=yr()|0,jn(e,5,1,n,QA()|0,2),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function YA(e,n,r){e=e|0,n=+n,r=+r,KA(e,n,r)}function KA(e,n,r){e=e|0,n=+n,r=+r;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+32|0,a=u+8|0,w=u+17|0,s=u,v=u+16|0,Pl(w,n),j[a>>3]=+us(w,n),Pl(v,r),j[s>>3]=+us(v,r),XA(e,a,s),y=u}function XA(e,n,r){e=e|0,n=n|0,r=r|0,Aw(e+8|0,+j[n>>3],+j[r>>3]),h[e+24>>0]=1}function Aw(e,n,r){e=e|0,n=+n,r=+r,j[e>>3]=n,j[e+8>>3]=r}function QA(){return 1472}function JA(e,n){return e=+e,n=+n,ZA(e,n)|0}function ZA(e,n){e=+e,n=+n;var r=0,u=0,s=0,a=0,v=0,w=0,T=0;return u=y,y=y+16|0,v=u+4|0,w=u+8|0,T=u,s=Oa(8)|0,r=s,a=pn(16)|0,Pl(v,e),e=+us(v,e),Pl(w,n),Aw(a,e,+us(w,n)),w=r+4|0,t[w>>2]=a,a=pn(8)|0,w=t[w>>2]|0,t[T>>2]=0,t[v>>2]=t[T>>2],Ow(a,w,v),t[s>>2]=a,y=u,r|0}function Ow(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,r=pn(16)|0,t[r+4>>2]=0,t[r+8>>2]=0,t[r>>2]=1452,t[r+12>>2]=n,t[e+4>>2]=r}function $A(e){e=e|0,Uv(e),Et(e)}function e7(e){e=e|0,e=t[e+12>>2]|0,e|0&&Et(e)}function t7(e){e=e|0,Et(e)}function n7(){var e=0;return h[7928]|0||(Mw(10488),Wt(59,10488,ge|0)|0,e=7928,t[e>>2]=1,t[e+4>>2]=0),sr(10488)|0||Mw(10488),10488}function Mw(e){e=e|0,u7(e),Vp(e,60)}function r7(e){e=e|0,i7(e+24|0)}function i7(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function u7(e){e=e|0;var n=0;n=yr()|0,jn(e,5,6,n,a7()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function o7(e){e=e|0,l7(e)}function l7(e){e=e|0,s7(e)}function s7(e){e=e|0,kw(e+8|0),h[e+24>>0]=1}function kw(e){e=e|0,t[e>>2]=0,t[e+4>>2]=0,t[e+8>>2]=0,t[e+12>>2]=0}function a7(){return 1492}function f7(){return c7()|0}function c7(){var e=0,n=0,r=0,u=0,s=0,a=0,v=0;return n=y,y=y+16|0,s=n+4|0,v=n,r=Oa(8)|0,e=r,u=pn(16)|0,kw(u),a=e+4|0,t[a>>2]=u,u=pn(8)|0,a=t[a>>2]|0,t[v>>2]=0,t[s>>2]=t[v>>2],Ow(u,a,s),t[r>>2]=u,y=n,e|0}function d7(){var e=0;return h[7936]|0||(_7(10524),Wt(25,10524,ge|0)|0,e=7936,t[e>>2]=1,t[e+4>>2]=0),10524}function p7(e,n){e=e|0,n=n|0,t[e>>2]=h7()|0,t[e+4>>2]=v7()|0,t[e+12>>2]=n,t[e+8>>2]=m7()|0,t[e+32>>2]=7}function h7(){return 11700}function v7(){return 1484}function m7(){return s_()|0}function y7(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0,(Hl(u,896)|0)==512?r|0&&(g7(r),Et(r)):n|0&&Et(n)}function g7(e){e=e|0,e=t[e+4>>2]|0,e|0&&$d(e)}function _7(e){e=e|0,Xa(e)}function E7(e,n,r){e=e|0,n=n|0,r=r|0,e=Fr(n)|0,n=D7(r)|0,r=w7(r,0)|0,Z7(e,n,r,pE()|0,0)}function D7(e){return e=e|0,e|0}function w7(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0;return w=y,y=y+16|0,s=w,a=w+4|0,t[s>>2]=e,T=pE()|0,v=T+24|0,n=hn(n,4)|0,t[a>>2]=n,r=T+28|0,u=t[r>>2]|0,u>>>0<(t[T+32>>2]|0)>>>0?(Lw(u,e,n),n=(t[r>>2]|0)+8|0,t[r>>2]=n):(O7(v,s,a),n=t[r>>2]|0),y=w,(n-(t[v>>2]|0)>>3)+-1|0}function pE(){var e=0,n=0;if(h[7944]|0||(Nw(10568),Wt(61,10568,ge|0)|0,n=7944,t[n>>2]=1,t[n+4>>2]=0),!(sr(10568)|0)){e=10568,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));Nw(10568)}return 10568}function Nw(e){e=e|0,C7(e)}function S7(e){e=e|0,T7(e+24|0)}function T7(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function C7(e){e=e|0;var n=0;n=yr()|0,jn(e,1,17,n,ev()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function x7(e){return e=e|0,A7(t[(R7(e)|0)>>2]|0)|0}function R7(e){return e=e|0,(t[(pE()|0)+24>>2]|0)+(e<<3)|0}function A7(e){return e=e|0,H0(E_[e&7]()|0)|0}function Lw(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,t[e+4>>2]=r}function O7(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0;if(w=y,y=y+32|0,s=w,a=e+4|0,v=((t[a>>2]|0)-(t[e>>2]|0)>>3)+1|0,u=M7(e)|0,u>>>0>>0)di(e);else{T=t[e>>2]|0,M=(t[e+8>>2]|0)-T|0,L=M>>2,k7(s,M>>3>>>0>>1>>>0?L>>>0>>0?v:L:u,(t[a>>2]|0)-T>>3,e+8|0),v=s+8|0,Lw(t[v>>2]|0,t[n>>2]|0,t[r>>2]|0),t[v>>2]=(t[v>>2]|0)+8,N7(e,s),L7(s),y=w;return}}function M7(e){return e=e|0,536870911}function k7(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>536870911)$n();else{s=pn(n<<3)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r<<3)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n<<3)}function N7(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(0-(s>>3)<<3)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function L7(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~((u+-8-n|0)>>>3)<<3)),e=t[e>>2]|0,e|0&&Et(e)}function F7(){P7()}function P7(){I7(10604)}function I7(e){e=e|0,b7(e,4955)}function b7(e,n){e=e|0,n=n|0;var r=0;r=B7()|0,t[e>>2]=r,U7(r,n),Zd(t[e>>2]|0)}function B7(){var e=0;return h[7952]|0||(K7(10612),Wt(25,10612,ge|0)|0,e=7952,t[e>>2]=1,t[e+4>>2]=0),10612}function U7(e,n){e=e|0,n=n|0,t[e>>2]=q7()|0,t[e+4>>2]=W7()|0,t[e+12>>2]=n,t[e+8>>2]=V7()|0,t[e+32>>2]=8}function Zd(e){e=e|0;var n=0,r=0;n=y,y=y+16|0,r=n,Fv()|0,t[r>>2]=e,j7(10608,r),y=n}function Fv(){return h[11714]|0||(t[2652]=0,Wt(62,10608,ge|0)|0,h[11714]=1),10608}function j7(e,n){e=e|0,n=n|0;var r=0;r=pn(8)|0,t[r+4>>2]=t[n>>2],t[r>>2]=t[e>>2],t[e>>2]=r}function z7(e){e=e|0,H7(e)}function H7(e){e=e|0;var n=0,r=0;if(n=t[e>>2]|0,n|0)do r=n,n=t[n>>2]|0,Et(r);while((n|0)!=0);t[e>>2]=0}function q7(){return 11715}function W7(){return 1496}function V7(){return L1()|0}function G7(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0,(Hl(u,896)|0)==512?r|0&&(Y7(r),Et(r)):n|0&&Et(n)}function Y7(e){e=e|0,e=t[e+4>>2]|0,e|0&&$d(e)}function K7(e){e=e|0,Xa(e)}function X7(e,n){e=e|0,n=n|0;var r=0,u=0;Fv()|0,r=t[2652]|0;e:do if(r|0){for(;u=t[r+4>>2]|0,!(u|0&&(h8(hE(u)|0,e)|0)==0);)if(r=t[r>>2]|0,!r)break e;Q7(u,n)}while(0)}function hE(e){return e=e|0,t[e+12>>2]|0}function Q7(e,n){e=e|0,n=n|0;var r=0;e=e+36|0,r=t[e>>2]|0,r|0&&(fa(r),Et(r)),r=pn(4)|0,wf(r,n),t[e>>2]=r}function vE(){return h[11716]|0||(t[2664]=0,Wt(63,10656,ge|0)|0,h[11716]=1),10656}function Fw(){var e=0;return h[11717]|0?e=t[2665]|0:(J7(),t[2665]=1504,h[11717]=1,e=1504),e|0}function J7(){h[11740]|0||(h[11718]=hn(hn(8,0)|0,0)|0,h[11719]=hn(hn(0,0)|0,0)|0,h[11720]=hn(hn(0,16)|0,0)|0,h[11721]=hn(hn(8,0)|0,0)|0,h[11722]=hn(hn(0,0)|0,0)|0,h[11723]=hn(hn(8,0)|0,0)|0,h[11724]=hn(hn(0,0)|0,0)|0,h[11725]=hn(hn(8,0)|0,0)|0,h[11726]=hn(hn(0,0)|0,0)|0,h[11727]=hn(hn(8,0)|0,0)|0,h[11728]=hn(hn(0,0)|0,0)|0,h[11729]=hn(hn(0,0)|0,32)|0,h[11730]=hn(hn(0,0)|0,32)|0,h[11740]=1)}function Pw(){return 1572}function Z7(e,n,r,u,s){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0;var a=0,v=0,w=0,T=0,L=0,M=0;a=y,y=y+32|0,M=a+16|0,L=a+12|0,T=a+8|0,w=a+4|0,v=a,t[M>>2]=e,t[L>>2]=n,t[T>>2]=r,t[w>>2]=u,t[v>>2]=s,vE()|0,$7(10656,M,L,T,w,v),y=a}function $7(e,n,r,u,s,a){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0;var v=0;v=pn(24)|0,yd(v+4|0,t[n>>2]|0,t[r>>2]|0,t[u>>2]|0,t[s>>2]|0,t[a>>2]|0),t[v>>2]=t[e>>2],t[e>>2]=v}function Iw(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0,Be=0,Te=0,ye=0,Ze=0,Ye=0,ct=0;if(ct=y,y=y+32|0,Te=ct+20|0,ye=ct+8|0,Ze=ct+4|0,Ye=ct,n=t[n>>2]|0,n|0){Be=Te+4|0,T=Te+8|0,L=ye+4|0,M=ye+8|0,b=ye+8|0,X=Te+8|0;do{if(v=n+4|0,w=mE(v)|0,w|0){if(s=Ay(w)|0,t[Te>>2]=0,t[Be>>2]=0,t[T>>2]=0,u=(Oy(w)|0)+1|0,eO(Te,u),u|0)for(;u=u+-1|0,Gf(ye,t[s>>2]|0),a=t[Be>>2]|0,a>>>0<(t[X>>2]|0)>>>0?(t[a>>2]=t[ye>>2],t[Be>>2]=(t[Be>>2]|0)+4):yE(Te,ye),u;)s=s+4|0;u=My(w)|0,t[ye>>2]=0,t[L>>2]=0,t[M>>2]=0;e:do if(t[u>>2]|0)for(s=0,a=0;;){if((s|0)==(a|0)?tO(ye,u):(t[s>>2]=t[u>>2],t[L>>2]=(t[L>>2]|0)+4),u=u+4|0,!(t[u>>2]|0))break e;s=t[L>>2]|0,a=t[b>>2]|0}while(0);t[Ze>>2]=a_(v)|0,t[Ye>>2]=sr(w)|0,nO(r,e,Ze,Ye,Te,ye),gE(ye),F1(Te)}n=t[n>>2]|0}while((n|0)!=0)}y=ct}function mE(e){return e=e|0,t[e+12>>2]|0}function Ay(e){return e=e|0,t[e+12>>2]|0}function Oy(e){return e=e|0,t[e+16>>2]|0}function eO(e,n){e=e|0,n=n|0;var r=0,u=0,s=0;s=y,y=y+32|0,r=s,u=t[e>>2]|0,(t[e+8>>2]|0)-u>>2>>>0>>0&&(Ww(r,n,(t[e+4>>2]|0)-u>>2,e+8|0),Vw(e,r),Gw(r)),y=s}function yE(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0;if(v=y,y=y+32|0,r=v,u=e+4|0,s=((t[u>>2]|0)-(t[e>>2]|0)>>2)+1|0,a=qw(e)|0,a>>>0>>0)di(e);else{w=t[e>>2]|0,L=(t[e+8>>2]|0)-w|0,T=L>>1,Ww(r,L>>2>>>0>>1>>>0?T>>>0>>0?s:T:a,(t[u>>2]|0)-w>>2,e+8|0),a=r+8|0,t[t[a>>2]>>2]=t[n>>2],t[a>>2]=(t[a>>2]|0)+4,Vw(e,r),Gw(r),y=v;return}}function My(e){return e=e|0,t[e+8>>2]|0}function tO(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0;if(v=y,y=y+32|0,r=v,u=e+4|0,s=((t[u>>2]|0)-(t[e>>2]|0)>>2)+1|0,a=Hw(e)|0,a>>>0>>0)di(e);else{w=t[e>>2]|0,L=(t[e+8>>2]|0)-w|0,T=L>>1,DO(r,L>>2>>>0>>1>>>0?T>>>0>>0?s:T:a,(t[u>>2]|0)-w>>2,e+8|0),a=r+8|0,t[t[a>>2]>>2]=t[n>>2],t[a>>2]=(t[a>>2]|0)+4,wO(e,r),SO(r),y=v;return}}function a_(e){return e=e|0,t[e>>2]|0}function nO(e,n,r,u,s,a){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0,rO(e,n,r,u,s,a)}function gE(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-4-u|0)>>>2)<<2)),Et(r))}function F1(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-4-u|0)>>>2)<<2)),Et(r))}function rO(e,n,r,u,s,a){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0;var v=0,w=0,T=0,L=0,M=0,b=0;v=y,y=y+48|0,M=v+40|0,w=v+32|0,b=v+24|0,T=v+12|0,L=v,Ma(w),e=go(e)|0,t[b>>2]=t[n>>2],r=t[r>>2]|0,u=t[u>>2]|0,_E(T,s),iO(L,a),t[M>>2]=t[b>>2],uO(e,M,r,u,T,L),gE(L),F1(T),ka(w),y=v}function _E(e,n){e=e|0,n=n|0;var r=0,u=0;t[e>>2]=0,t[e+4>>2]=0,t[e+8>>2]=0,r=n+4|0,u=(t[r>>2]|0)-(t[n>>2]|0)>>2,u|0&&(_O(e,u),EO(e,t[n>>2]|0,t[r>>2]|0,u))}function iO(e,n){e=e|0,n=n|0;var r=0,u=0;t[e>>2]=0,t[e+4>>2]=0,t[e+8>>2]=0,r=n+4|0,u=(t[r>>2]|0)-(t[n>>2]|0)>>2,u|0&&(yO(e,u),gO(e,t[n>>2]|0,t[r>>2]|0,u))}function uO(e,n,r,u,s,a){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0;var v=0,w=0,T=0,L=0,M=0,b=0;v=y,y=y+32|0,M=v+28|0,b=v+24|0,w=v+12|0,T=v,L=_o(oO()|0)|0,t[b>>2]=t[n>>2],t[M>>2]=t[b>>2],n=Gp(M)|0,r=bw(r)|0,u=EE(u)|0,t[w>>2]=t[s>>2],M=s+4|0,t[w+4>>2]=t[M>>2],b=s+8|0,t[w+8>>2]=t[b>>2],t[b>>2]=0,t[M>>2]=0,t[s>>2]=0,s=DE(w)|0,t[T>>2]=t[a>>2],M=a+4|0,t[T+4>>2]=t[M>>2],b=a+8|0,t[T+8>>2]=t[b>>2],t[b>>2]=0,t[M>>2]=0,t[a>>2]=0,X0(0,L|0,e|0,n|0,r|0,u|0,s|0,lO(T)|0)|0,gE(T),F1(w),y=v}function oO(){var e=0;return h[7968]|0||(vO(10708),e=7968,t[e>>2]=1,t[e+4>>2]=0),10708}function Gp(e){return e=e|0,Uw(e)|0}function bw(e){return e=e|0,Bw(e)|0}function EE(e){return e=e|0,H0(e)|0}function DE(e){return e=e|0,aO(e)|0}function lO(e){return e=e|0,sO(e)|0}function sO(e){e=e|0;var n=0,r=0,u=0;if(u=(t[e+4>>2]|0)-(t[e>>2]|0)|0,r=u>>2,u=Oa(u+4|0)|0,t[u>>2]=r,r|0){n=0;do t[u+4+(n<<2)>>2]=Bw(t[(t[e>>2]|0)+(n<<2)>>2]|0)|0,n=n+1|0;while((n|0)!=(r|0))}return u|0}function Bw(e){return e=e|0,e|0}function aO(e){e=e|0;var n=0,r=0,u=0;if(u=(t[e+4>>2]|0)-(t[e>>2]|0)|0,r=u>>2,u=Oa(u+4|0)|0,t[u>>2]=r,r|0){n=0;do t[u+4+(n<<2)>>2]=Uw((t[e>>2]|0)+(n<<2)|0)|0,n=n+1|0;while((n|0)!=(r|0))}return u|0}function Uw(e){e=e|0;var n=0,r=0,u=0,s=0;return s=y,y=y+32|0,n=s+12|0,r=s,u=Pu(jw()|0)|0,u?(rs(n,u),Mf(r,n),VN(e,r),e=Cs(n)|0):e=fO(e)|0,y=s,e|0}function jw(){var e=0;return h[7960]|0||(hO(10664),Wt(25,10664,ge|0)|0,e=7960,t[e>>2]=1,t[e+4>>2]=0),10664}function fO(e){e=e|0;var n=0,r=0,u=0,s=0,a=0,v=0,w=0;return r=y,y=y+16|0,s=r+4|0,v=r,u=Oa(8)|0,n=u,w=pn(4)|0,t[w>>2]=t[e>>2],a=n+4|0,t[a>>2]=w,e=pn(8)|0,a=t[a>>2]|0,t[v>>2]=0,t[s>>2]=t[v>>2],zw(e,a,s),t[u>>2]=e,y=r,n|0}function zw(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,r=pn(16)|0,t[r+4>>2]=0,t[r+8>>2]=0,t[r>>2]=1656,t[r+12>>2]=n,t[e+4>>2]=r}function cO(e){e=e|0,Uv(e),Et(e)}function dO(e){e=e|0,e=t[e+12>>2]|0,e|0&&Et(e)}function pO(e){e=e|0,Et(e)}function hO(e){e=e|0,Xa(e)}function vO(e){e=e|0,ll(e,mO()|0,5)}function mO(){return 1676}function yO(e,n){e=e|0,n=n|0;var r=0;if((Hw(e)|0)>>>0>>0&&di(e),n>>>0>1073741823)$n();else{r=pn(n<<2)|0,t[e+4>>2]=r,t[e>>2]=r,t[e+8>>2]=r+(n<<2);return}}function gO(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0,u=e+4|0,e=r-n|0,(e|0)>0&&(gr(t[u>>2]|0,n|0,e|0)|0,t[u>>2]=(t[u>>2]|0)+(e>>>2<<2))}function Hw(e){return e=e|0,1073741823}function _O(e,n){e=e|0,n=n|0;var r=0;if((qw(e)|0)>>>0>>0&&di(e),n>>>0>1073741823)$n();else{r=pn(n<<2)|0,t[e+4>>2]=r,t[e>>2]=r,t[e+8>>2]=r+(n<<2);return}}function EO(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0,u=e+4|0,e=r-n|0,(e|0)>0&&(gr(t[u>>2]|0,n|0,e|0)|0,t[u>>2]=(t[u>>2]|0)+(e>>>2<<2))}function qw(e){return e=e|0,1073741823}function DO(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>1073741823)$n();else{s=pn(n<<2)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r<<2)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n<<2)}function wO(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(0-(s>>2)<<2)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function SO(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~((u+-4-n|0)>>>2)<<2)),e=t[e>>2]|0,e|0&&Et(e)}function Ww(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>1073741823)$n();else{s=pn(n<<2)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r<<2)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n<<2)}function Vw(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(0-(s>>2)<<2)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function Gw(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~((u+-4-n|0)>>>2)<<2)),e=t[e>>2]|0,e|0&&Et(e)}function TO(e,n,r,u,s){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0;var a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0,Be=0,Te=0,ye=0;if(ye=y,y=y+32|0,M=ye+20|0,b=ye+12|0,L=ye+16|0,X=ye+4|0,Be=ye,Te=ye+8|0,w=Fw()|0,a=t[w>>2]|0,v=t[a>>2]|0,v|0)for(T=t[w+8>>2]|0,w=t[w+4>>2]|0;Gf(M,v),CO(e,M,w,T),a=a+4|0,v=t[a>>2]|0,v;)T=T+1|0,w=w+1|0;if(a=Pw()|0,v=t[a>>2]|0,v|0)do Gf(M,v),t[b>>2]=t[a+4>>2],xO(n,M,b),a=a+8|0,v=t[a>>2]|0;while((v|0)!=0);if(a=t[(Fv()|0)>>2]|0,a|0)do n=t[a+4>>2]|0,Gf(M,t[(Pv(n)|0)>>2]|0),t[b>>2]=hE(n)|0,RO(r,M,b),a=t[a>>2]|0;while((a|0)!=0);if(Gf(L,0),a=vE()|0,t[M>>2]=t[L>>2],Iw(M,a,s),a=t[(Fv()|0)>>2]|0,a|0){e=M+4|0,n=M+8|0,r=M+8|0;do{if(T=t[a+4>>2]|0,Gf(b,t[(Pv(T)|0)>>2]|0),AO(X,Yw(T)|0),v=t[X>>2]|0,v|0){t[M>>2]=0,t[e>>2]=0,t[n>>2]=0;do Gf(Be,t[(Pv(t[v+4>>2]|0)|0)>>2]|0),w=t[e>>2]|0,w>>>0<(t[r>>2]|0)>>>0?(t[w>>2]=t[Be>>2],t[e>>2]=(t[e>>2]|0)+4):yE(M,Be),v=t[v>>2]|0;while((v|0)!=0);OO(u,b,M),F1(M)}t[Te>>2]=t[b>>2],L=Kw(T)|0,t[M>>2]=t[Te>>2],Iw(M,L,s),_d(X),a=t[a>>2]|0}while((a|0)!=0)}y=ye}function CO(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0,zO(e,n,r,u)}function xO(e,n,r){e=e|0,n=n|0,r=r|0,jO(e,n,r)}function Pv(e){return e=e|0,e|0}function RO(e,n,r){e=e|0,n=n|0,r=r|0,IO(e,n,r)}function Yw(e){return e=e|0,e+16|0}function AO(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0;if(a=y,y=y+16|0,s=a+8|0,r=a,t[e>>2]=0,u=t[n>>2]|0,t[s>>2]=u,t[r>>2]=e,r=PO(r)|0,u|0){if(u=pn(12)|0,v=(Xw(s)|0)+4|0,e=t[v+4>>2]|0,n=u+4|0,t[n>>2]=t[v>>2],t[n+4>>2]=e,n=t[t[s>>2]>>2]|0,t[s>>2]=n,!n)e=u;else for(n=u;e=pn(12)|0,T=(Xw(s)|0)+4|0,w=t[T+4>>2]|0,v=e+4|0,t[v>>2]=t[T>>2],t[v+4>>2]=w,t[n>>2]=e,v=t[t[s>>2]>>2]|0,t[s>>2]=v,v;)n=e;t[e>>2]=t[r>>2],t[r>>2]=u}y=a}function OO(e,n,r){e=e|0,n=n|0,r=r|0,MO(e,n,r)}function Kw(e){return e=e|0,e+24|0}function MO(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+32|0,v=u+24|0,s=u+16|0,w=u+12|0,a=u,Ma(s),e=go(e)|0,t[w>>2]=t[n>>2],_E(a,r),t[v>>2]=t[w>>2],kO(e,v,a),F1(a),ka(s),y=u}function kO(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=y,y=y+32|0,v=u+16|0,w=u+12|0,s=u,a=_o(NO()|0)|0,t[w>>2]=t[n>>2],t[v>>2]=t[w>>2],n=Gp(v)|0,t[s>>2]=t[r>>2],v=r+4|0,t[s+4>>2]=t[v>>2],w=r+8|0,t[s+8>>2]=t[w>>2],t[w>>2]=0,t[v>>2]=0,t[r>>2]=0,P0(0,a|0,e|0,n|0,DE(s)|0)|0,F1(s),y=u}function NO(){var e=0;return h[7976]|0||(LO(10720),e=7976,t[e>>2]=1,t[e+4>>2]=0),10720}function LO(e){e=e|0,ll(e,FO()|0,2)}function FO(){return 1732}function PO(e){return e=e|0,t[e>>2]|0}function Xw(e){return e=e|0,t[e>>2]|0}function IO(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;u=y,y=y+32|0,a=u+16|0,s=u+8|0,v=u,Ma(s),e=go(e)|0,t[v>>2]=t[n>>2],r=t[r>>2]|0,t[a>>2]=t[v>>2],Qw(e,a,r),ka(s),y=u}function Qw(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;u=y,y=y+16|0,a=u+4|0,v=u,s=_o(bO()|0)|0,t[v>>2]=t[n>>2],t[a>>2]=t[v>>2],n=Gp(a)|0,P0(0,s|0,e|0,n|0,bw(r)|0)|0,y=u}function bO(){var e=0;return h[7984]|0||(BO(10732),e=7984,t[e>>2]=1,t[e+4>>2]=0),10732}function BO(e){e=e|0,ll(e,UO()|0,2)}function UO(){return 1744}function jO(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;u=y,y=y+32|0,a=u+16|0,s=u+8|0,v=u,Ma(s),e=go(e)|0,t[v>>2]=t[n>>2],r=t[r>>2]|0,t[a>>2]=t[v>>2],Qw(e,a,r),ka(s),y=u}function zO(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0;s=y,y=y+32|0,v=s+16|0,a=s+8|0,w=s,Ma(a),e=go(e)|0,t[w>>2]=t[n>>2],r=h[r>>0]|0,u=h[u>>0]|0,t[v>>2]=t[w>>2],HO(e,v,r,u),ka(a),y=s}function HO(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0;s=y,y=y+16|0,v=s+4|0,w=s,a=_o(qO()|0)|0,t[w>>2]=t[n>>2],t[v>>2]=t[w>>2],n=Gp(v)|0,r=Iv(r)|0,Hn(0,a|0,e|0,n|0,r|0,Iv(u)|0)|0,y=s}function qO(){var e=0;return h[7992]|0||(VO(10744),e=7992,t[e>>2]=1,t[e+4>>2]=0),10744}function Iv(e){return e=e|0,WO(e)|0}function WO(e){return e=e|0,e&255|0}function VO(e){e=e|0,ll(e,GO()|0,3)}function GO(){return 1756}function YO(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;switch(X=y,y=y+32|0,w=X+8|0,T=X+4|0,L=X+20|0,M=X,Sa(e,0),u=WN(n)|0,t[w>>2]=0,b=w+4|0,t[b>>2]=0,t[w+8>>2]=0,u<<24>>24){case 0:{h[L>>0]=0,KO(T,r,L),f_(e,T)|0,U0(T);break}case 8:{b=RE(n)|0,h[L>>0]=8,Gf(M,t[b+4>>2]|0),XO(T,r,L,M,b+8|0),f_(e,T)|0,U0(T);break}case 9:{if(a=RE(n)|0,n=t[a+4>>2]|0,n|0)for(v=w+8|0,s=a+12|0;n=n+-1|0,Gf(T,t[s>>2]|0),u=t[b>>2]|0,u>>>0<(t[v>>2]|0)>>>0?(t[u>>2]=t[T>>2],t[b>>2]=(t[b>>2]|0)+4):yE(w,T),n;)s=s+4|0;h[L>>0]=9,Gf(M,t[a+8>>2]|0),QO(T,r,L,M,w),f_(e,T)|0,U0(T);break}default:b=RE(n)|0,h[L>>0]=u,Gf(M,t[b+4>>2]|0),JO(T,r,L,M),f_(e,T)|0,U0(T)}F1(w),y=X}function KO(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0;u=y,y=y+16|0,s=u,Ma(s),n=go(n)|0,fM(e,n,h[r>>0]|0),ka(s),y=u}function f_(e,n){e=e|0,n=n|0;var r=0;return r=t[e>>2]|0,r|0&&qr(r|0),t[e>>2]=t[n>>2],t[n>>2]=0,e|0}function XO(e,n,r,u,s){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0;var a=0,v=0,w=0,T=0;a=y,y=y+32|0,w=a+16|0,v=a+8|0,T=a,Ma(v),n=go(n)|0,r=h[r>>0]|0,t[T>>2]=t[u>>2],s=t[s>>2]|0,t[w>>2]=t[T>>2],oM(e,n,r,w,s),ka(v),y=a}function QO(e,n,r,u,s){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0;var a=0,v=0,w=0,T=0,L=0;a=y,y=y+32|0,T=a+24|0,v=a+16|0,L=a+12|0,w=a,Ma(v),n=go(n)|0,r=h[r>>0]|0,t[L>>2]=t[u>>2],_E(w,s),t[T>>2]=t[L>>2],nM(e,n,r,T,w),F1(w),ka(v),y=a}function JO(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0;s=y,y=y+32|0,v=s+16|0,a=s+8|0,w=s,Ma(a),n=go(n)|0,r=h[r>>0]|0,t[w>>2]=t[u>>2],t[v>>2]=t[w>>2],ZO(e,n,r,v),ka(a),y=s}function ZO(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0,v=0,w=0;s=y,y=y+16|0,a=s+4|0,w=s,v=_o($O()|0)|0,r=Iv(r)|0,t[w>>2]=t[u>>2],t[a>>2]=t[w>>2],c_(e,P0(0,v|0,n|0,r|0,Gp(a)|0)|0),y=s}function $O(){var e=0;return h[8e3]|0||(eM(10756),e=8e3,t[e>>2]=1,t[e+4>>2]=0),10756}function c_(e,n){e=e|0,n=n|0,Sa(e,n)}function eM(e){e=e|0,ll(e,tM()|0,2)}function tM(){return 1772}function nM(e,n,r,u,s){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0;var a=0,v=0,w=0,T=0,L=0;a=y,y=y+32|0,T=a+16|0,L=a+12|0,v=a,w=_o(rM()|0)|0,r=Iv(r)|0,t[L>>2]=t[u>>2],t[T>>2]=t[L>>2],u=Gp(T)|0,t[v>>2]=t[s>>2],T=s+4|0,t[v+4>>2]=t[T>>2],L=s+8|0,t[v+8>>2]=t[L>>2],t[L>>2]=0,t[T>>2]=0,t[s>>2]=0,c_(e,Hn(0,w|0,n|0,r|0,u|0,DE(v)|0)|0),F1(v),y=a}function rM(){var e=0;return h[8008]|0||(iM(10768),e=8008,t[e>>2]=1,t[e+4>>2]=0),10768}function iM(e){e=e|0,ll(e,uM()|0,3)}function uM(){return 1784}function oM(e,n,r,u,s){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0;var a=0,v=0,w=0,T=0;a=y,y=y+16|0,w=a+4|0,T=a,v=_o(lM()|0)|0,r=Iv(r)|0,t[T>>2]=t[u>>2],t[w>>2]=t[T>>2],u=Gp(w)|0,c_(e,Hn(0,v|0,n|0,r|0,u|0,EE(s)|0)|0),y=a}function lM(){var e=0;return h[8016]|0||(sM(10780),e=8016,t[e>>2]=1,t[e+4>>2]=0),10780}function sM(e){e=e|0,ll(e,aM()|0,3)}function aM(){return 1800}function fM(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;u=_o(cM()|0)|0,c_(e,Ki(0,u|0,n|0,Iv(r)|0)|0)}function cM(){var e=0;return h[8024]|0||(dM(10792),e=8024,t[e>>2]=1,t[e+4>>2]=0),10792}function dM(e){e=e|0,ll(e,pM()|0,1)}function pM(){return 1816}function hM(){vM(),mM(),yM()}function vM(){t[2702]=T8(65536)|0}function mM(){bM(10856)}function yM(){gM(10816)}function gM(e){e=e|0,_M(e,5044),EM(e)|0}function _M(e,n){e=e|0,n=n|0;var r=0;r=jw()|0,t[e>>2]=r,kM(r,n),Zd(t[e>>2]|0)}function EM(e){e=e|0;var n=0;return n=t[e>>2]|0,Wp(n,DM()|0),e|0}function DM(){var e=0;return h[8032]|0||(Jw(10820),Wt(64,10820,ge|0)|0,e=8032,t[e>>2]=1,t[e+4>>2]=0),sr(10820)|0||Jw(10820),10820}function Jw(e){e=e|0,TM(e),Vp(e,25)}function wM(e){e=e|0,SM(e+24|0)}function SM(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function TM(e){e=e|0;var n=0;n=yr()|0,jn(e,5,18,n,AM()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function CM(e,n){e=e|0,n=n|0,xM(e,n)}function xM(e,n){e=e|0,n=n|0;var r=0,u=0,s=0;r=y,y=y+16|0,u=r,s=r+4|0,Pf(s,n),t[u>>2]=If(s,n)|0,RM(e,u),y=r}function RM(e,n){e=e|0,n=n|0,Zw(e+4|0,t[n>>2]|0),h[e+8>>0]=1}function Zw(e,n){e=e|0,n=n|0,t[e>>2]=n}function AM(){return 1824}function OM(e){return e=e|0,MM(e)|0}function MM(e){e=e|0;var n=0,r=0,u=0,s=0,a=0,v=0,w=0;return r=y,y=y+16|0,s=r+4|0,v=r,u=Oa(8)|0,n=u,w=pn(4)|0,Pf(s,e),Zw(w,If(s,e)|0),a=n+4|0,t[a>>2]=w,e=pn(8)|0,a=t[a>>2]|0,t[v>>2]=0,t[s>>2]=t[v>>2],zw(e,a,s),t[u>>2]=e,y=r,n|0}function Oa(e){e=e|0;var n=0,r=0;return e=e+7&-8,e>>>0<=32768&&(n=t[2701]|0,e>>>0<=(65536-n|0)>>>0)?(r=(t[2702]|0)+n|0,t[2701]=n+e,e=r):(e=T8(e+8|0)|0,t[e>>2]=t[2703],t[2703]=e,e=e+8|0),e|0}function kM(e,n){e=e|0,n=n|0,t[e>>2]=NM()|0,t[e+4>>2]=LM()|0,t[e+12>>2]=n,t[e+8>>2]=FM()|0,t[e+32>>2]=9}function NM(){return 11744}function LM(){return 1832}function FM(){return s_()|0}function PM(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0,(Hl(u,896)|0)==512?r|0&&(IM(r),Et(r)):n|0&&Et(n)}function IM(e){e=e|0,e=t[e+4>>2]|0,e|0&&$d(e)}function bM(e){e=e|0,BM(e,5052),UM(e)|0,jM(e,5058,26)|0,zM(e,5069,1)|0,HM(e,5077,10)|0,qM(e,5087,19)|0,WM(e,5094,27)|0}function BM(e,n){e=e|0,n=n|0;var r=0;r=IN()|0,t[e>>2]=r,bN(r,n),Zd(t[e>>2]|0)}function UM(e){e=e|0;var n=0;return n=t[e>>2]|0,Wp(n,wN()|0),e|0}function jM(e,n,r){return e=e|0,n=n|0,r=r|0,iN(e,Fr(n)|0,r,0),e|0}function zM(e,n,r){return e=e|0,n=n|0,r=r|0,qk(e,Fr(n)|0,r,0),e|0}function HM(e,n,r){return e=e|0,n=n|0,r=r|0,Dk(e,Fr(n)|0,r,0),e|0}function qM(e,n,r){return e=e|0,n=n|0,r=r|0,ok(e,Fr(n)|0,r,0),e|0}function $w(e,n){e=e|0,n=n|0;var r=0,u=0;e:for(;;){for(r=t[2703]|0;;){if((r|0)==(n|0))break e;if(u=t[r>>2]|0,t[2703]=u,!r)r=u;else break}Et(r)}t[2701]=e}function WM(e,n,r){return e=e|0,n=n|0,r=r|0,VM(e,Fr(n)|0,r,0),e|0}function VM(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0;a=t[e>>2]|0,s=wE()|0,e=GM(r)|0,wi(a,n,s,e,YM(r,u)|0,u)}function wE(){var e=0,n=0;if(h[8040]|0||(t8(10860),Wt(65,10860,ge|0)|0,n=8040,t[n>>2]=1,t[n+4>>2]=0),!(sr(10860)|0)){e=10860,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));t8(10860)}return 10860}function GM(e){return e=e|0,e|0}function YM(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0;return w=y,y=y+16|0,s=w,a=w+4|0,t[s>>2]=e,T=wE()|0,v=T+24|0,n=hn(n,4)|0,t[a>>2]=n,r=T+28|0,u=t[r>>2]|0,u>>>0<(t[T+32>>2]|0)>>>0?(e8(u,e,n),n=(t[r>>2]|0)+8|0,t[r>>2]=n):(KM(v,s,a),n=t[r>>2]|0),y=w,(n-(t[v>>2]|0)>>3)+-1|0}function e8(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,t[e+4>>2]=r}function KM(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0;if(w=y,y=y+32|0,s=w,a=e+4|0,v=((t[a>>2]|0)-(t[e>>2]|0)>>3)+1|0,u=XM(e)|0,u>>>0>>0)di(e);else{T=t[e>>2]|0,M=(t[e+8>>2]|0)-T|0,L=M>>2,QM(s,M>>3>>>0>>1>>>0?L>>>0>>0?v:L:u,(t[a>>2]|0)-T>>3,e+8|0),v=s+8|0,e8(t[v>>2]|0,t[n>>2]|0,t[r>>2]|0),t[v>>2]=(t[v>>2]|0)+8,JM(e,s),ZM(s),y=w;return}}function XM(e){return e=e|0,536870911}function QM(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>536870911)$n();else{s=pn(n<<3)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r<<3)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n<<3)}function JM(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(0-(s>>3)<<3)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function ZM(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~((u+-8-n|0)>>>3)<<3)),e=t[e>>2]|0,e|0&&Et(e)}function t8(e){e=e|0,tk(e)}function $M(e){e=e|0,ek(e+24|0)}function ek(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function tk(e){e=e|0;var n=0;n=yr()|0,jn(e,1,11,n,nk()|0,2),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function nk(){return 1840}function rk(e,n,r){e=e|0,n=n|0,r=r|0,uk(t[(ik(e)|0)>>2]|0,n,r)}function ik(e){return e=e|0,(t[(wE()|0)+24>>2]|0)+(e<<3)|0}function uk(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0;u=y,y=y+16|0,a=u+1|0,s=u,Pf(a,n),n=If(a,n)|0,Pf(s,r),r=If(s,r)|0,I1[e&31](n,r),y=u}function ok(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0;a=t[e>>2]|0,s=SE()|0,e=lk(r)|0,wi(a,n,s,e,sk(r,u)|0,u)}function SE(){var e=0,n=0;if(h[8048]|0||(r8(10896),Wt(66,10896,ge|0)|0,n=8048,t[n>>2]=1,t[n+4>>2]=0),!(sr(10896)|0)){e=10896,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));r8(10896)}return 10896}function lk(e){return e=e|0,e|0}function sk(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0;return w=y,y=y+16|0,s=w,a=w+4|0,t[s>>2]=e,T=SE()|0,v=T+24|0,n=hn(n,4)|0,t[a>>2]=n,r=T+28|0,u=t[r>>2]|0,u>>>0<(t[T+32>>2]|0)>>>0?(n8(u,e,n),n=(t[r>>2]|0)+8|0,t[r>>2]=n):(ak(v,s,a),n=t[r>>2]|0),y=w,(n-(t[v>>2]|0)>>3)+-1|0}function n8(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,t[e+4>>2]=r}function ak(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0;if(w=y,y=y+32|0,s=w,a=e+4|0,v=((t[a>>2]|0)-(t[e>>2]|0)>>3)+1|0,u=fk(e)|0,u>>>0>>0)di(e);else{T=t[e>>2]|0,M=(t[e+8>>2]|0)-T|0,L=M>>2,ck(s,M>>3>>>0>>1>>>0?L>>>0>>0?v:L:u,(t[a>>2]|0)-T>>3,e+8|0),v=s+8|0,n8(t[v>>2]|0,t[n>>2]|0,t[r>>2]|0),t[v>>2]=(t[v>>2]|0)+8,dk(e,s),pk(s),y=w;return}}function fk(e){return e=e|0,536870911}function ck(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>536870911)$n();else{s=pn(n<<3)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r<<3)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n<<3)}function dk(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(0-(s>>3)<<3)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function pk(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~((u+-8-n|0)>>>3)<<3)),e=t[e>>2]|0,e|0&&Et(e)}function r8(e){e=e|0,mk(e)}function hk(e){e=e|0,vk(e+24|0)}function vk(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function mk(e){e=e|0;var n=0;n=yr()|0,jn(e,1,11,n,yk()|0,1),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function yk(){return 1852}function gk(e,n){return e=e|0,n=n|0,Ek(t[(_k(e)|0)>>2]|0,n)|0}function _k(e){return e=e|0,(t[(SE()|0)+24>>2]|0)+(e<<3)|0}function Ek(e,n){e=e|0,n=n|0;var r=0,u=0;return r=y,y=y+16|0,u=r,Pf(u,n),n=If(u,n)|0,n=H0(Qp[e&31](n)|0)|0,y=r,n|0}function Dk(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0;a=t[e>>2]|0,s=TE()|0,e=wk(r)|0,wi(a,n,s,e,Sk(r,u)|0,u)}function TE(){var e=0,n=0;if(h[8056]|0||(u8(10932),Wt(67,10932,ge|0)|0,n=8056,t[n>>2]=1,t[n+4>>2]=0),!(sr(10932)|0)){e=10932,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));u8(10932)}return 10932}function wk(e){return e=e|0,e|0}function Sk(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0;return w=y,y=y+16|0,s=w,a=w+4|0,t[s>>2]=e,T=TE()|0,v=T+24|0,n=hn(n,4)|0,t[a>>2]=n,r=T+28|0,u=t[r>>2]|0,u>>>0<(t[T+32>>2]|0)>>>0?(i8(u,e,n),n=(t[r>>2]|0)+8|0,t[r>>2]=n):(Tk(v,s,a),n=t[r>>2]|0),y=w,(n-(t[v>>2]|0)>>3)+-1|0}function i8(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,t[e+4>>2]=r}function Tk(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0;if(w=y,y=y+32|0,s=w,a=e+4|0,v=((t[a>>2]|0)-(t[e>>2]|0)>>3)+1|0,u=Ck(e)|0,u>>>0>>0)di(e);else{T=t[e>>2]|0,M=(t[e+8>>2]|0)-T|0,L=M>>2,xk(s,M>>3>>>0>>1>>>0?L>>>0>>0?v:L:u,(t[a>>2]|0)-T>>3,e+8|0),v=s+8|0,i8(t[v>>2]|0,t[n>>2]|0,t[r>>2]|0),t[v>>2]=(t[v>>2]|0)+8,Rk(e,s),Ak(s),y=w;return}}function Ck(e){return e=e|0,536870911}function xk(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>536870911)$n();else{s=pn(n<<3)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r<<3)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n<<3)}function Rk(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(0-(s>>3)<<3)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function Ak(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~((u+-8-n|0)>>>3)<<3)),e=t[e>>2]|0,e|0&&Et(e)}function u8(e){e=e|0,kk(e)}function Ok(e){e=e|0,Mk(e+24|0)}function Mk(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function kk(e){e=e|0;var n=0;n=yr()|0,jn(e,1,7,n,Nk()|0,2),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function Nk(){return 1860}function Lk(e,n,r){return e=e|0,n=n|0,r=r|0,Pk(t[(Fk(e)|0)>>2]|0,n,r)|0}function Fk(e){return e=e|0,(t[(TE()|0)+24>>2]|0)+(e<<3)|0}function Pk(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0;return u=y,y=y+32|0,v=u+12|0,a=u+8|0,w=u,T=u+16|0,s=u+4|0,Ik(T,n),bk(w,T,n),Ys(s,r),r=Ks(s,r)|0,t[v>>2]=t[w>>2],Fy[e&15](a,v,r),r=Bk(a)|0,U0(a),Xs(s),y=u,r|0}function Ik(e,n){e=e|0,n=n|0}function bk(e,n,r){e=e|0,n=n|0,r=r|0,Uk(e,r)}function Bk(e){return e=e|0,go(e)|0}function Uk(e,n){e=e|0,n=n|0;var r=0,u=0,s=0;s=y,y=y+16|0,r=s,u=n,u&1?(jk(r,0),eu(u|0,r|0)|0,zk(e,r),Hk(r)):t[e>>2]=t[n>>2],y=s}function jk(e,n){e=e|0,n=n|0,fd(e,n),t[e+4>>2]=0,h[e+8>>0]=0}function zk(e,n){e=e|0,n=n|0,t[e>>2]=t[n+4>>2]}function Hk(e){e=e|0,h[e+8>>0]=0}function qk(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0;a=t[e>>2]|0,s=CE()|0,e=Wk(r)|0,wi(a,n,s,e,Vk(r,u)|0,u)}function CE(){var e=0,n=0;if(h[8064]|0||(l8(10968),Wt(68,10968,ge|0)|0,n=8064,t[n>>2]=1,t[n+4>>2]=0),!(sr(10968)|0)){e=10968,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));l8(10968)}return 10968}function Wk(e){return e=e|0,e|0}function Vk(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0;return w=y,y=y+16|0,s=w,a=w+4|0,t[s>>2]=e,T=CE()|0,v=T+24|0,n=hn(n,4)|0,t[a>>2]=n,r=T+28|0,u=t[r>>2]|0,u>>>0<(t[T+32>>2]|0)>>>0?(o8(u,e,n),n=(t[r>>2]|0)+8|0,t[r>>2]=n):(Gk(v,s,a),n=t[r>>2]|0),y=w,(n-(t[v>>2]|0)>>3)+-1|0}function o8(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,t[e+4>>2]=r}function Gk(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0;if(w=y,y=y+32|0,s=w,a=e+4|0,v=((t[a>>2]|0)-(t[e>>2]|0)>>3)+1|0,u=Yk(e)|0,u>>>0>>0)di(e);else{T=t[e>>2]|0,M=(t[e+8>>2]|0)-T|0,L=M>>2,Kk(s,M>>3>>>0>>1>>>0?L>>>0>>0?v:L:u,(t[a>>2]|0)-T>>3,e+8|0),v=s+8|0,o8(t[v>>2]|0,t[n>>2]|0,t[r>>2]|0),t[v>>2]=(t[v>>2]|0)+8,Xk(e,s),Qk(s),y=w;return}}function Yk(e){return e=e|0,536870911}function Kk(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>536870911)$n();else{s=pn(n<<3)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r<<3)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n<<3)}function Xk(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(0-(s>>3)<<3)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function Qk(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~((u+-8-n|0)>>>3)<<3)),e=t[e>>2]|0,e|0&&Et(e)}function l8(e){e=e|0,$k(e)}function Jk(e){e=e|0,Zk(e+24|0)}function Zk(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function $k(e){e=e|0;var n=0;n=yr()|0,jn(e,1,1,n,eN()|0,5),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function eN(){return 1872}function tN(e,n,r,u,s,a){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0,rN(t[(nN(e)|0)>>2]|0,n,r,u,s,a)}function nN(e){return e=e|0,(t[(CE()|0)+24>>2]|0)+(e<<3)|0}function rN(e,n,r,u,s,a){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0;var v=0,w=0,T=0,L=0,M=0,b=0;v=y,y=y+32|0,w=v+16|0,T=v+12|0,L=v+8|0,M=v+4|0,b=v,Ys(w,n),n=Ks(w,n)|0,Ys(T,r),r=Ks(T,r)|0,Ys(L,u),u=Ks(L,u)|0,Ys(M,s),s=Ks(M,s)|0,Ys(b,a),a=Ks(b,a)|0,O8[e&1](n,r,u,s,a),Xs(b),Xs(M),Xs(L),Xs(T),Xs(w),y=v}function iN(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0;a=t[e>>2]|0,s=xE()|0,e=uN(r)|0,wi(a,n,s,e,oN(r,u)|0,u)}function xE(){var e=0,n=0;if(h[8072]|0||(a8(11004),Wt(69,11004,ge|0)|0,n=8072,t[n>>2]=1,t[n+4>>2]=0),!(sr(11004)|0)){e=11004,n=e+36|0;do t[e>>2]=0,e=e+4|0;while((e|0)<(n|0));a8(11004)}return 11004}function uN(e){return e=e|0,e|0}function oN(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0,w=0,T=0;return w=y,y=y+16|0,s=w,a=w+4|0,t[s>>2]=e,T=xE()|0,v=T+24|0,n=hn(n,4)|0,t[a>>2]=n,r=T+28|0,u=t[r>>2]|0,u>>>0<(t[T+32>>2]|0)>>>0?(s8(u,e,n),n=(t[r>>2]|0)+8|0,t[r>>2]=n):(lN(v,s,a),n=t[r>>2]|0),y=w,(n-(t[v>>2]|0)>>3)+-1|0}function s8(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,t[e+4>>2]=r}function lN(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0;if(w=y,y=y+32|0,s=w,a=e+4|0,v=((t[a>>2]|0)-(t[e>>2]|0)>>3)+1|0,u=sN(e)|0,u>>>0>>0)di(e);else{T=t[e>>2]|0,M=(t[e+8>>2]|0)-T|0,L=M>>2,aN(s,M>>3>>>0>>1>>>0?L>>>0>>0?v:L:u,(t[a>>2]|0)-T>>3,e+8|0),v=s+8|0,s8(t[v>>2]|0,t[n>>2]|0,t[r>>2]|0),t[v>>2]=(t[v>>2]|0)+8,fN(e,s),cN(s),y=w;return}}function sN(e){return e=e|0,536870911}function aN(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0;t[e+12>>2]=0,t[e+16>>2]=u;do if(n)if(n>>>0>536870911)$n();else{s=pn(n<<3)|0;break}else s=0;while(0);t[e>>2]=s,u=s+(r<<3)|0,t[e+8>>2]=u,t[e+4>>2]=u,t[e+12>>2]=s+(n<<3)}function fN(e,n){e=e|0,n=n|0;var r=0,u=0,s=0,a=0,v=0;u=t[e>>2]|0,v=e+4|0,a=n+4|0,s=(t[v>>2]|0)-u|0,r=(t[a>>2]|0)+(0-(s>>3)<<3)|0,t[a>>2]=r,(s|0)>0?(gr(r|0,u|0,s|0)|0,u=a,r=t[a>>2]|0):u=a,a=t[e>>2]|0,t[e>>2]=r,t[u>>2]=a,a=n+8|0,s=t[v>>2]|0,t[v>>2]=t[a>>2],t[a>>2]=s,a=e+8|0,v=n+12|0,e=t[a>>2]|0,t[a>>2]=t[v>>2],t[v>>2]=e,t[n>>2]=t[u>>2]}function cN(e){e=e|0;var n=0,r=0,u=0;n=t[e+4>>2]|0,r=e+8|0,u=t[r>>2]|0,(u|0)!=(n|0)&&(t[r>>2]=u+(~((u+-8-n|0)>>>3)<<3)),e=t[e>>2]|0,e|0&&Et(e)}function a8(e){e=e|0,hN(e)}function dN(e){e=e|0,pN(e+24|0)}function pN(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function hN(e){e=e|0;var n=0;n=yr()|0,jn(e,1,12,n,vN()|0,2),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function vN(){return 1896}function mN(e,n,r){e=e|0,n=n|0,r=r|0,gN(t[(yN(e)|0)>>2]|0,n,r)}function yN(e){return e=e|0,(t[(xE()|0)+24>>2]|0)+(e<<3)|0}function gN(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0;u=y,y=y+16|0,a=u+4|0,s=u,_N(a,n),n=EN(a,n)|0,Ys(s,r),r=Ks(s,r)|0,I1[e&31](n,r),Xs(s),y=u}function _N(e,n){e=e|0,n=n|0}function EN(e,n){return e=e|0,n=n|0,DN(n)|0}function DN(e){return e=e|0,e|0}function wN(){var e=0;return h[8080]|0||(f8(11040),Wt(70,11040,ge|0)|0,e=8080,t[e>>2]=1,t[e+4>>2]=0),sr(11040)|0||f8(11040),11040}function f8(e){e=e|0,CN(e),Vp(e,71)}function SN(e){e=e|0,TN(e+24|0)}function TN(e){e=e|0;var n=0,r=0,u=0;r=t[e>>2]|0,u=r,r|0&&(e=e+4|0,n=t[e>>2]|0,(n|0)!=(r|0)&&(t[e>>2]=n+(~((n+-8-u|0)>>>3)<<3)),Et(r))}function CN(e){e=e|0;var n=0;n=yr()|0,jn(e,5,7,n,ON()|0,0),t[e+24>>2]=0,t[e+28>>2]=0,t[e+32>>2]=0}function xN(e){e=e|0,RN(e)}function RN(e){e=e|0,AN(e)}function AN(e){e=e|0,h[e+8>>0]=1}function ON(){return 1936}function MN(){return kN()|0}function kN(){var e=0,n=0,r=0,u=0,s=0,a=0,v=0;return n=y,y=y+16|0,s=n+4|0,v=n,r=Oa(8)|0,e=r,a=e+4|0,t[a>>2]=pn(1)|0,u=pn(8)|0,a=t[a>>2]|0,t[v>>2]=0,t[s>>2]=t[v>>2],NN(u,a,s),t[r>>2]=u,y=n,e|0}function NN(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]=n,r=pn(16)|0,t[r+4>>2]=0,t[r+8>>2]=0,t[r>>2]=1916,t[r+12>>2]=n,t[e+4>>2]=r}function LN(e){e=e|0,Uv(e),Et(e)}function FN(e){e=e|0,e=t[e+12>>2]|0,e|0&&Et(e)}function PN(e){e=e|0,Et(e)}function IN(){var e=0;return h[8088]|0||(qN(11076),Wt(25,11076,ge|0)|0,e=8088,t[e>>2]=1,t[e+4>>2]=0),11076}function bN(e,n){e=e|0,n=n|0,t[e>>2]=BN()|0,t[e+4>>2]=UN()|0,t[e+12>>2]=n,t[e+8>>2]=jN()|0,t[e+32>>2]=10}function BN(){return 11745}function UN(){return 1940}function jN(){return L1()|0}function zN(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0,(Hl(u,896)|0)==512?r|0&&(HN(r),Et(r)):n|0&&Et(n)}function HN(e){e=e|0,e=t[e+4>>2]|0,e|0&&$d(e)}function qN(e){e=e|0,Xa(e)}function Gf(e,n){e=e|0,n=n|0,t[e>>2]=n}function RE(e){return e=e|0,t[e>>2]|0}function WN(e){return e=e|0,h[t[e>>2]>>0]|0}function VN(e,n){e=e|0,n=n|0;var r=0,u=0;r=y,y=y+16|0,u=r,t[u>>2]=t[e>>2],GN(n,u)|0,y=r}function GN(e,n){e=e|0,n=n|0;var r=0;return r=YN(t[e>>2]|0,n)|0,n=e+4|0,t[(t[n>>2]|0)+8>>2]=r,t[(t[n>>2]|0)+8>>2]|0}function YN(e,n){e=e|0,n=n|0;var r=0,u=0;return r=y,y=y+16|0,u=r,Ma(u),e=go(e)|0,n=KN(e,t[n>>2]|0)|0,ka(u),y=r,n|0}function Ma(e){e=e|0,t[e>>2]=t[2701],t[e+4>>2]=t[2703]}function KN(e,n){e=e|0,n=n|0;var r=0;return r=_o(XN()|0)|0,Ki(0,r|0,e|0,EE(n)|0)|0}function ka(e){e=e|0,$w(t[e>>2]|0,t[e+4>>2]|0)}function XN(){var e=0;return h[8096]|0||(QN(11120),e=8096,t[e>>2]=1,t[e+4>>2]=0),11120}function QN(e){e=e|0,ll(e,JN()|0,1)}function JN(){return 1948}function ZN(){$N()}function $N(){var e=0,n=0,r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0,Be=0,Te=0,ye=0;if(Te=y,y=y+16|0,M=Te+4|0,b=Te,In(65536,10804,t[2702]|0,10812),r=Fw()|0,n=t[r>>2]|0,e=t[n>>2]|0,e|0)for(u=t[r+8>>2]|0,r=t[r+4>>2]|0;Xl(e|0,N[r>>0]|0|0,h[u>>0]|0),n=n+4|0,e=t[n>>2]|0,e;)u=u+1|0,r=r+1|0;if(e=Pw()|0,n=t[e>>2]|0,n|0)do ko(n|0,t[e+4>>2]|0),e=e+8|0,n=t[e>>2]|0;while((n|0)!=0);ko(eL()|0,5167),L=Fv()|0,e=t[L>>2]|0;e:do if(e|0){do tL(t[e+4>>2]|0),e=t[e>>2]|0;while((e|0)!=0);if(e=t[L>>2]|0,e|0){T=L;do{for(;s=e,e=t[e>>2]|0,s=t[s+4>>2]|0,!!(nL(s)|0);)if(t[b>>2]=T,t[M>>2]=t[b>>2],rL(L,M)|0,!e)break e;if(iL(s),T=t[T>>2]|0,n=c8(s)|0,a=fo()|0,v=y,y=y+((1*(n<<2)|0)+15&-16)|0,w=y,y=y+((1*(n<<2)|0)+15&-16)|0,n=t[(Yw(s)|0)>>2]|0,n|0)for(r=v,u=w;t[r>>2]=t[(Pv(t[n+4>>2]|0)|0)>>2],t[u>>2]=t[n+8>>2],n=t[n>>2]|0,n;)r=r+4|0,u=u+4|0;ye=Pv(s)|0,n=uL(s)|0,r=c8(s)|0,u=oL(s)|0,No(ye|0,n|0,v|0,w|0,r|0,u|0,hE(s)|0),yi(a|0)}while((e|0)!=0)}}while(0);if(e=t[(vE()|0)>>2]|0,e|0)do ye=e+4|0,L=mE(ye)|0,s=My(L)|0,a=Ay(L)|0,v=(Oy(L)|0)+1|0,w=d_(L)|0,T=d8(ye)|0,L=sr(L)|0,M=a_(ye)|0,b=AE(ye)|0,ao(0,s|0,a|0,v|0,w|0,T|0,L|0,M|0,b|0,OE(ye)|0),e=t[e>>2]|0;while((e|0)!=0);e=t[(Fv()|0)>>2]|0;e:do if(e|0){t:for(;;){if(n=t[e+4>>2]|0,n|0&&(X=t[(Pv(n)|0)>>2]|0,Be=t[(Kw(n)|0)>>2]|0,Be|0)){r=Be;do{n=r+4|0,u=mE(n)|0;n:do if(u|0)switch(sr(u)|0){case 0:break t;case 4:case 3:case 2:{w=My(u)|0,T=Ay(u)|0,L=(Oy(u)|0)+1|0,M=d_(u)|0,b=sr(u)|0,ye=a_(n)|0,ao(X|0,w|0,T|0,L|0,M|0,0,b|0,ye|0,AE(n)|0,OE(n)|0);break n}case 1:{v=My(u)|0,w=Ay(u)|0,T=(Oy(u)|0)+1|0,L=d_(u)|0,M=d8(n)|0,b=sr(u)|0,ye=a_(n)|0,ao(X|0,v|0,w|0,T|0,L|0,M|0,b|0,ye|0,AE(n)|0,OE(n)|0);break n}case 5:{L=My(u)|0,M=Ay(u)|0,b=(Oy(u)|0)+1|0,ye=d_(u)|0,ao(X|0,L|0,M|0,b|0,ye|0,lL(u)|0,sr(u)|0,0,0,0);break n}default:break n}while(0);r=t[r>>2]|0}while((r|0)!=0)}if(e=t[e>>2]|0,!e)break e}$n()}while(0);Is(),y=Te}function eL(){return 11703}function tL(e){e=e|0,h[e+40>>0]=0}function nL(e){return e=e|0,(h[e+40>>0]|0)!=0|0}function rL(e,n){return e=e|0,n=n|0,n=sL(n)|0,e=t[n>>2]|0,t[n>>2]=t[e>>2],Et(e),t[n>>2]|0}function iL(e){e=e|0,h[e+40>>0]=1}function c8(e){return e=e|0,t[e+20>>2]|0}function uL(e){return e=e|0,t[e+8>>2]|0}function oL(e){return e=e|0,t[e+32>>2]|0}function d_(e){return e=e|0,t[e+4>>2]|0}function d8(e){return e=e|0,t[e+4>>2]|0}function AE(e){return e=e|0,t[e+8>>2]|0}function OE(e){return e=e|0,t[e+16>>2]|0}function lL(e){return e=e|0,t[e+20>>2]|0}function sL(e){return e=e|0,t[e>>2]|0}function p_(e){e=e|0;var n=0,r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0,Be=0,Te=0,ye=0,Ze=0,Ye=0,ct=0,ke=0,Ie=0,Zt=0;Zt=y,y=y+16|0,X=Zt;do if(e>>>0<245){if(L=e>>>0<11?16:e+11&-8,e=L>>>3,b=t[2783]|0,r=b>>>e,r&3|0)return n=(r&1^1)+e|0,e=11172+(n<<1<<2)|0,r=e+8|0,u=t[r>>2]|0,s=u+8|0,a=t[s>>2]|0,(e|0)==(a|0)?t[2783]=b&~(1<>2]=e,t[r>>2]=a),Ie=n<<3,t[u+4>>2]=Ie|3,Ie=u+Ie+4|0,t[Ie>>2]=t[Ie>>2]|1,Ie=s,y=Zt,Ie|0;if(M=t[2785]|0,L>>>0>M>>>0){if(r|0)return n=2<>>12&16,n=n>>>v,r=n>>>5&8,n=n>>>r,s=n>>>2&4,n=n>>>s,e=n>>>1&2,n=n>>>e,u=n>>>1&1,u=(r|v|s|e|u)+(n>>>u)|0,n=11172+(u<<1<<2)|0,e=n+8|0,s=t[e>>2]|0,v=s+8|0,r=t[v>>2]|0,(n|0)==(r|0)?(e=b&~(1<>2]=n,t[e>>2]=r,e=b),a=(u<<3)-L|0,t[s+4>>2]=L|3,u=s+L|0,t[u+4>>2]=a|1,t[u+a>>2]=a,M|0&&(s=t[2788]|0,n=M>>>3,r=11172+(n<<1<<2)|0,n=1<>2]|0):(t[2783]=e|n,n=r,e=r+8|0),t[e>>2]=s,t[n+12>>2]=s,t[s+8>>2]=n,t[s+12>>2]=r),t[2785]=a,t[2788]=u,Ie=v,y=Zt,Ie|0;if(w=t[2784]|0,w){if(r=(w&0-w)+-1|0,v=r>>>12&16,r=r>>>v,a=r>>>5&8,r=r>>>a,T=r>>>2&4,r=r>>>T,u=r>>>1&2,r=r>>>u,e=r>>>1&1,e=t[11436+((a|v|T|u|e)+(r>>>e)<<2)>>2]|0,r=(t[e+4>>2]&-8)-L|0,u=t[e+16+(((t[e+16>>2]|0)==0&1)<<2)>>2]|0,!u)T=e,a=r;else{do v=(t[u+4>>2]&-8)-L|0,T=v>>>0>>0,r=T?v:r,e=T?u:e,u=t[u+16+(((t[u+16>>2]|0)==0&1)<<2)>>2]|0;while((u|0)!=0);T=e,a=r}if(v=T+L|0,T>>>0>>0){s=t[T+24>>2]|0,n=t[T+12>>2]|0;do if((n|0)==(T|0)){if(e=T+20|0,n=t[e>>2]|0,!n&&(e=T+16|0,n=t[e>>2]|0,!n)){r=0;break}for(;;){if(r=n+20|0,u=t[r>>2]|0,u|0){n=u,e=r;continue}if(r=n+16|0,u=t[r>>2]|0,u)n=u,e=r;else break}t[e>>2]=0,r=n}else r=t[T+8>>2]|0,t[r+12>>2]=n,t[n+8>>2]=r,r=n;while(0);do if(s|0){if(n=t[T+28>>2]|0,e=11436+(n<<2)|0,(T|0)==(t[e>>2]|0)){if(t[e>>2]=r,!r){t[2784]=w&~(1<>2]|0)!=(T|0)&1)<<2)>>2]=r,!r)break;t[r+24>>2]=s,n=t[T+16>>2]|0,n|0&&(t[r+16>>2]=n,t[n+24>>2]=r),n=t[T+20>>2]|0,n|0&&(t[r+20>>2]=n,t[n+24>>2]=r)}while(0);return a>>>0<16?(Ie=a+L|0,t[T+4>>2]=Ie|3,Ie=T+Ie+4|0,t[Ie>>2]=t[Ie>>2]|1):(t[T+4>>2]=L|3,t[v+4>>2]=a|1,t[v+a>>2]=a,M|0&&(u=t[2788]|0,n=M>>>3,r=11172+(n<<1<<2)|0,n=1<>2]|0):(t[2783]=b|n,n=r,e=r+8|0),t[e>>2]=u,t[n+12>>2]=u,t[u+8>>2]=n,t[u+12>>2]=r),t[2785]=a,t[2788]=v),Ie=T+8|0,y=Zt,Ie|0}else b=L}else b=L}else b=L}else if(e>>>0<=4294967231)if(e=e+11|0,L=e&-8,T=t[2784]|0,T){u=0-L|0,e=e>>>8,e?L>>>0>16777215?w=31:(b=(e+1048320|0)>>>16&8,ke=e<>>16&4,ke=ke<>>16&2,w=14-(M|b|w)+(ke<>>15)|0,w=L>>>(w+7|0)&1|w<<1):w=0,r=t[11436+(w<<2)>>2]|0;e:do if(!r)r=0,e=0,ke=57;else for(e=0,v=L<<((w|0)==31?0:25-(w>>>1)|0),a=0;;){if(s=(t[r+4>>2]&-8)-L|0,s>>>0>>0)if(s)e=r,u=s;else{e=r,u=0,s=r,ke=61;break e}if(s=t[r+20>>2]|0,r=t[r+16+(v>>>31<<2)>>2]|0,a=(s|0)==0|(s|0)==(r|0)?a:s,s=(r|0)==0,s){r=a,ke=57;break}else v=v<<((s^1)&1)}while(0);if((ke|0)==57){if((r|0)==0&(e|0)==0){if(e=2<>>12&16,b=b>>>v,a=b>>>5&8,b=b>>>a,w=b>>>2&4,b=b>>>w,M=b>>>1&2,b=b>>>M,r=b>>>1&1,e=0,r=t[11436+((a|v|w|M|r)+(b>>>r)<<2)>>2]|0}r?(s=r,ke=61):(w=e,v=u)}if((ke|0)==61)for(;;)if(ke=0,r=(t[s+4>>2]&-8)-L|0,b=r>>>0>>0,r=b?r:u,e=b?s:e,s=t[s+16+(((t[s+16>>2]|0)==0&1)<<2)>>2]|0,s)u=r,ke=61;else{w=e,v=r;break}if((w|0)!=0&&v>>>0<((t[2785]|0)-L|0)>>>0){if(a=w+L|0,w>>>0>=a>>>0)return Ie=0,y=Zt,Ie|0;s=t[w+24>>2]|0,n=t[w+12>>2]|0;do if((n|0)==(w|0)){if(e=w+20|0,n=t[e>>2]|0,!n&&(e=w+16|0,n=t[e>>2]|0,!n)){n=0;break}for(;;){if(r=n+20|0,u=t[r>>2]|0,u|0){n=u,e=r;continue}if(r=n+16|0,u=t[r>>2]|0,u)n=u,e=r;else break}t[e>>2]=0}else Ie=t[w+8>>2]|0,t[Ie+12>>2]=n,t[n+8>>2]=Ie;while(0);do if(s){if(e=t[w+28>>2]|0,r=11436+(e<<2)|0,(w|0)==(t[r>>2]|0)){if(t[r>>2]=n,!n){u=T&~(1<>2]|0)!=(w|0)&1)<<2)>>2]=n,!n){u=T;break}t[n+24>>2]=s,e=t[w+16>>2]|0,e|0&&(t[n+16>>2]=e,t[e+24>>2]=n),e=t[w+20>>2]|0,e&&(t[n+20>>2]=e,t[e+24>>2]=n),u=T}else u=T;while(0);do if(v>>>0>=16){if(t[w+4>>2]=L|3,t[a+4>>2]=v|1,t[a+v>>2]=v,n=v>>>3,v>>>0<256){r=11172+(n<<1<<2)|0,e=t[2783]|0,n=1<>2]|0):(t[2783]=e|n,n=r,e=r+8|0),t[e>>2]=a,t[n+12>>2]=a,t[a+8>>2]=n,t[a+12>>2]=r;break}if(n=v>>>8,n?v>>>0>16777215?n=31:(ke=(n+1048320|0)>>>16&8,Ie=n<>>16&4,Ie=Ie<>>16&2,n=14-(ct|ke|n)+(Ie<>>15)|0,n=v>>>(n+7|0)&1|n<<1):n=0,r=11436+(n<<2)|0,t[a+28>>2]=n,e=a+16|0,t[e+4>>2]=0,t[e>>2]=0,e=1<>2]=a,t[a+24>>2]=r,t[a+12>>2]=a,t[a+8>>2]=a;break}for(e=v<<((n|0)==31?0:25-(n>>>1)|0),r=t[r>>2]|0;;){if((t[r+4>>2]&-8|0)==(v|0)){ke=97;break}if(u=r+16+(e>>>31<<2)|0,n=t[u>>2]|0,n)e=e<<1,r=n;else{ke=96;break}}if((ke|0)==96){t[u>>2]=a,t[a+24>>2]=r,t[a+12>>2]=a,t[a+8>>2]=a;break}else if((ke|0)==97){ke=r+8|0,Ie=t[ke>>2]|0,t[Ie+12>>2]=a,t[ke>>2]=a,t[a+8>>2]=Ie,t[a+12>>2]=r,t[a+24>>2]=0;break}}else Ie=v+L|0,t[w+4>>2]=Ie|3,Ie=w+Ie+4|0,t[Ie>>2]=t[Ie>>2]|1;while(0);return Ie=w+8|0,y=Zt,Ie|0}else b=L}else b=L;else b=-1;while(0);if(r=t[2785]|0,r>>>0>=b>>>0)return n=r-b|0,e=t[2788]|0,n>>>0>15?(Ie=e+b|0,t[2788]=Ie,t[2785]=n,t[Ie+4>>2]=n|1,t[Ie+n>>2]=n,t[e+4>>2]=b|3):(t[2785]=0,t[2788]=0,t[e+4>>2]=r|3,Ie=e+r+4|0,t[Ie>>2]=t[Ie>>2]|1),Ie=e+8|0,y=Zt,Ie|0;if(v=t[2786]|0,v>>>0>b>>>0)return ct=v-b|0,t[2786]=ct,Ie=t[2789]|0,ke=Ie+b|0,t[2789]=ke,t[ke+4>>2]=ct|1,t[Ie+4>>2]=b|3,Ie=Ie+8|0,y=Zt,Ie|0;if(t[2901]|0?e=t[2903]|0:(t[2903]=4096,t[2902]=4096,t[2904]=-1,t[2905]=-1,t[2906]=0,t[2894]=0,e=X&-16^1431655768,t[X>>2]=e,t[2901]=e,e=4096),w=b+48|0,T=b+47|0,a=e+T|0,s=0-e|0,L=a&s,L>>>0<=b>>>0||(e=t[2893]|0,e|0&&(M=t[2891]|0,X=M+L|0,X>>>0<=M>>>0|X>>>0>e>>>0)))return Ie=0,y=Zt,Ie|0;e:do if(t[2894]&4)n=0,ke=133;else{r=t[2789]|0;t:do if(r){for(u=11580;e=t[u>>2]|0,!(e>>>0<=r>>>0&&(ye=u+4|0,(e+(t[ye>>2]|0)|0)>>>0>r>>>0));)if(e=t[u+8>>2]|0,e)u=e;else{ke=118;break t}if(n=a-v&s,n>>>0<2147483647)if(e=e2(n|0)|0,(e|0)==((t[u>>2]|0)+(t[ye>>2]|0)|0)){if((e|0)!=-1){v=n,a=e,ke=135;break e}}else u=e,ke=126;else n=0}else ke=118;while(0);do if((ke|0)==118)if(r=e2(0)|0,(r|0)!=-1&&(n=r,Be=t[2902]|0,Te=Be+-1|0,n=((Te&n|0)==0?0:(Te+n&0-Be)-n|0)+L|0,Be=t[2891]|0,Te=n+Be|0,n>>>0>b>>>0&n>>>0<2147483647)){if(ye=t[2893]|0,ye|0&&Te>>>0<=Be>>>0|Te>>>0>ye>>>0){n=0;break}if(e=e2(n|0)|0,(e|0)==(r|0)){v=n,a=r,ke=135;break e}else u=e,ke=126}else n=0;while(0);do if((ke|0)==126){if(r=0-n|0,!(w>>>0>n>>>0&(n>>>0<2147483647&(u|0)!=-1)))if((u|0)==-1){n=0;break}else{v=n,a=u,ke=135;break e}if(e=t[2903]|0,e=T-n+e&0-e,e>>>0>=2147483647){v=n,a=u,ke=135;break e}if((e2(e|0)|0)==-1){e2(r|0)|0,n=0;break}else{v=e+n|0,a=u,ke=135;break e}}while(0);t[2894]=t[2894]|4,ke=133}while(0);if((ke|0)==133&&L>>>0<2147483647&&(ct=e2(L|0)|0,ye=e2(0)|0,Ze=ye-ct|0,Ye=Ze>>>0>(b+40|0)>>>0,!((ct|0)==-1|Ye^1|ct>>>0>>0&((ct|0)!=-1&(ye|0)!=-1)^1))&&(v=Ye?Ze:n,a=ct,ke=135),(ke|0)==135){n=(t[2891]|0)+v|0,t[2891]=n,n>>>0>(t[2892]|0)>>>0&&(t[2892]=n),T=t[2789]|0;do if(T){for(n=11580;;){if(e=t[n>>2]|0,r=n+4|0,u=t[r>>2]|0,(a|0)==(e+u|0)){ke=145;break}if(s=t[n+8>>2]|0,s)n=s;else break}if((ke|0)==145&&(t[n+12>>2]&8|0)==0&&T>>>0>>0&T>>>0>=e>>>0){t[r>>2]=u+v,Ie=T+8|0,Ie=(Ie&7|0)==0?0:0-Ie&7,ke=T+Ie|0,Ie=(t[2786]|0)+(v-Ie)|0,t[2789]=ke,t[2786]=Ie,t[ke+4>>2]=Ie|1,t[ke+Ie+4>>2]=40,t[2790]=t[2905];break}for(a>>>0<(t[2787]|0)>>>0&&(t[2787]=a),r=a+v|0,n=11580;;){if((t[n>>2]|0)==(r|0)){ke=153;break}if(e=t[n+8>>2]|0,e)n=e;else break}if((ke|0)==153&&(t[n+12>>2]&8|0)==0){t[n>>2]=a,M=n+4|0,t[M>>2]=(t[M>>2]|0)+v,M=a+8|0,M=a+((M&7|0)==0?0:0-M&7)|0,n=r+8|0,n=r+((n&7|0)==0?0:0-n&7)|0,L=M+b|0,w=n-M-b|0,t[M+4>>2]=b|3;do if((n|0)!=(T|0)){if((n|0)==(t[2788]|0)){Ie=(t[2785]|0)+w|0,t[2785]=Ie,t[2788]=L,t[L+4>>2]=Ie|1,t[L+Ie>>2]=Ie;break}if(e=t[n+4>>2]|0,(e&3|0)==1){v=e&-8,u=e>>>3;e:do if(e>>>0<256)if(e=t[n+8>>2]|0,r=t[n+12>>2]|0,(r|0)==(e|0)){t[2783]=t[2783]&~(1<>2]=r,t[r+8>>2]=e;break}else{a=t[n+24>>2]|0,e=t[n+12>>2]|0;do if((e|0)==(n|0)){if(u=n+16|0,r=u+4|0,e=t[r>>2]|0,!e)if(e=t[u>>2]|0,e)r=u;else{e=0;break}for(;;){if(u=e+20|0,s=t[u>>2]|0,s|0){e=s,r=u;continue}if(u=e+16|0,s=t[u>>2]|0,s)e=s,r=u;else break}t[r>>2]=0}else Ie=t[n+8>>2]|0,t[Ie+12>>2]=e,t[e+8>>2]=Ie;while(0);if(!a)break;r=t[n+28>>2]|0,u=11436+(r<<2)|0;do if((n|0)!=(t[u>>2]|0)){if(t[a+16+(((t[a+16>>2]|0)!=(n|0)&1)<<2)>>2]=e,!e)break e}else{if(t[u>>2]=e,e|0)break;t[2784]=t[2784]&~(1<>2]=a,r=n+16|0,u=t[r>>2]|0,u|0&&(t[e+16>>2]=u,t[u+24>>2]=e),r=t[r+4>>2]|0,!r)break;t[e+20>>2]=r,t[r+24>>2]=e}while(0);n=n+v|0,s=v+w|0}else s=w;if(n=n+4|0,t[n>>2]=t[n>>2]&-2,t[L+4>>2]=s|1,t[L+s>>2]=s,n=s>>>3,s>>>0<256){r=11172+(n<<1<<2)|0,e=t[2783]|0,n=1<>2]|0):(t[2783]=e|n,n=r,e=r+8|0),t[e>>2]=L,t[n+12>>2]=L,t[L+8>>2]=n,t[L+12>>2]=r;break}n=s>>>8;do if(!n)n=0;else{if(s>>>0>16777215){n=31;break}ke=(n+1048320|0)>>>16&8,Ie=n<>>16&4,Ie=Ie<>>16&2,n=14-(ct|ke|n)+(Ie<>>15)|0,n=s>>>(n+7|0)&1|n<<1}while(0);if(u=11436+(n<<2)|0,t[L+28>>2]=n,e=L+16|0,t[e+4>>2]=0,t[e>>2]=0,e=t[2784]|0,r=1<>2]=L,t[L+24>>2]=u,t[L+12>>2]=L,t[L+8>>2]=L;break}for(e=s<<((n|0)==31?0:25-(n>>>1)|0),r=t[u>>2]|0;;){if((t[r+4>>2]&-8|0)==(s|0)){ke=194;break}if(u=r+16+(e>>>31<<2)|0,n=t[u>>2]|0,n)e=e<<1,r=n;else{ke=193;break}}if((ke|0)==193){t[u>>2]=L,t[L+24>>2]=r,t[L+12>>2]=L,t[L+8>>2]=L;break}else if((ke|0)==194){ke=r+8|0,Ie=t[ke>>2]|0,t[Ie+12>>2]=L,t[ke>>2]=L,t[L+8>>2]=Ie,t[L+12>>2]=r,t[L+24>>2]=0;break}}else Ie=(t[2786]|0)+w|0,t[2786]=Ie,t[2789]=L,t[L+4>>2]=Ie|1;while(0);return Ie=M+8|0,y=Zt,Ie|0}for(n=11580;e=t[n>>2]|0,!(e>>>0<=T>>>0&&(Ie=e+(t[n+4>>2]|0)|0,Ie>>>0>T>>>0));)n=t[n+8>>2]|0;s=Ie+-47|0,e=s+8|0,e=s+((e&7|0)==0?0:0-e&7)|0,s=T+16|0,e=e>>>0>>0?T:e,n=e+8|0,r=a+8|0,r=(r&7|0)==0?0:0-r&7,ke=a+r|0,r=v+-40-r|0,t[2789]=ke,t[2786]=r,t[ke+4>>2]=r|1,t[ke+r+4>>2]=40,t[2790]=t[2905],r=e+4|0,t[r>>2]=27,t[n>>2]=t[2895],t[n+4>>2]=t[2896],t[n+8>>2]=t[2897],t[n+12>>2]=t[2898],t[2895]=a,t[2896]=v,t[2898]=0,t[2897]=n,n=e+24|0;do ke=n,n=n+4|0,t[n>>2]=7;while((ke+8|0)>>>0>>0);if((e|0)!=(T|0)){if(a=e-T|0,t[r>>2]=t[r>>2]&-2,t[T+4>>2]=a|1,t[e>>2]=a,n=a>>>3,a>>>0<256){r=11172+(n<<1<<2)|0,e=t[2783]|0,n=1<>2]|0):(t[2783]=e|n,n=r,e=r+8|0),t[e>>2]=T,t[n+12>>2]=T,t[T+8>>2]=n,t[T+12>>2]=r;break}if(n=a>>>8,n?a>>>0>16777215?r=31:(ke=(n+1048320|0)>>>16&8,Ie=n<>>16&4,Ie=Ie<>>16&2,r=14-(ct|ke|r)+(Ie<>>15)|0,r=a>>>(r+7|0)&1|r<<1):r=0,u=11436+(r<<2)|0,t[T+28>>2]=r,t[T+20>>2]=0,t[s>>2]=0,n=t[2784]|0,e=1<>2]=T,t[T+24>>2]=u,t[T+12>>2]=T,t[T+8>>2]=T;break}for(e=a<<((r|0)==31?0:25-(r>>>1)|0),r=t[u>>2]|0;;){if((t[r+4>>2]&-8|0)==(a|0)){ke=216;break}if(u=r+16+(e>>>31<<2)|0,n=t[u>>2]|0,n)e=e<<1,r=n;else{ke=215;break}}if((ke|0)==215){t[u>>2]=T,t[T+24>>2]=r,t[T+12>>2]=T,t[T+8>>2]=T;break}else if((ke|0)==216){ke=r+8|0,Ie=t[ke>>2]|0,t[Ie+12>>2]=T,t[ke>>2]=T,t[T+8>>2]=Ie,t[T+12>>2]=r,t[T+24>>2]=0;break}}}else{Ie=t[2787]|0,(Ie|0)==0|a>>>0>>0&&(t[2787]=a),t[2895]=a,t[2896]=v,t[2898]=0,t[2792]=t[2901],t[2791]=-1,n=0;do Ie=11172+(n<<1<<2)|0,t[Ie+12>>2]=Ie,t[Ie+8>>2]=Ie,n=n+1|0;while((n|0)!=32);Ie=a+8|0,Ie=(Ie&7|0)==0?0:0-Ie&7,ke=a+Ie|0,Ie=v+-40-Ie|0,t[2789]=ke,t[2786]=Ie,t[ke+4>>2]=Ie|1,t[ke+Ie+4>>2]=40,t[2790]=t[2905]}while(0);if(n=t[2786]|0,n>>>0>b>>>0)return ct=n-b|0,t[2786]=ct,Ie=t[2789]|0,ke=Ie+b|0,t[2789]=ke,t[ke+4>>2]=ct|1,t[Ie+4>>2]=b|3,Ie=Ie+8|0,y=Zt,Ie|0}return t[(bv()|0)>>2]=12,Ie=0,y=Zt,Ie|0}function h_(e){e=e|0;var n=0,r=0,u=0,s=0,a=0,v=0,w=0,T=0;if(!!e){r=e+-8|0,s=t[2787]|0,e=t[e+-4>>2]|0,n=e&-8,T=r+n|0;do if(e&1)w=r,v=r;else{if(u=t[r>>2]|0,!(e&3)||(v=r+(0-u)|0,a=u+n|0,v>>>0>>0))return;if((v|0)==(t[2788]|0)){if(e=T+4|0,n=t[e>>2]|0,(n&3|0)!=3){w=v,n=a;break}t[2785]=a,t[e>>2]=n&-2,t[v+4>>2]=a|1,t[v+a>>2]=a;return}if(r=u>>>3,u>>>0<256)if(e=t[v+8>>2]|0,n=t[v+12>>2]|0,(n|0)==(e|0)){t[2783]=t[2783]&~(1<>2]=n,t[n+8>>2]=e,w=v,n=a;break}s=t[v+24>>2]|0,e=t[v+12>>2]|0;do if((e|0)==(v|0)){if(r=v+16|0,n=r+4|0,e=t[n>>2]|0,!e)if(e=t[r>>2]|0,e)n=r;else{e=0;break}for(;;){if(r=e+20|0,u=t[r>>2]|0,u|0){e=u,n=r;continue}if(r=e+16|0,u=t[r>>2]|0,u)e=u,n=r;else break}t[n>>2]=0}else w=t[v+8>>2]|0,t[w+12>>2]=e,t[e+8>>2]=w;while(0);if(s){if(n=t[v+28>>2]|0,r=11436+(n<<2)|0,(v|0)==(t[r>>2]|0)){if(t[r>>2]=e,!e){t[2784]=t[2784]&~(1<>2]|0)!=(v|0)&1)<<2)>>2]=e,!e){w=v,n=a;break}t[e+24>>2]=s,n=v+16|0,r=t[n>>2]|0,r|0&&(t[e+16>>2]=r,t[r+24>>2]=e),n=t[n+4>>2]|0,n?(t[e+20>>2]=n,t[n+24>>2]=e,w=v,n=a):(w=v,n=a)}else w=v,n=a}while(0);if(!(v>>>0>=T>>>0)&&(e=T+4|0,u=t[e>>2]|0,!!(u&1))){if(u&2)t[e>>2]=u&-2,t[w+4>>2]=n|1,t[v+n>>2]=n,s=n;else{if(e=t[2788]|0,(T|0)==(t[2789]|0)){if(T=(t[2786]|0)+n|0,t[2786]=T,t[2789]=w,t[w+4>>2]=T|1,(w|0)!=(e|0))return;t[2788]=0,t[2785]=0;return}if((T|0)==(e|0)){T=(t[2785]|0)+n|0,t[2785]=T,t[2788]=v,t[w+4>>2]=T|1,t[v+T>>2]=T;return}s=(u&-8)+n|0,r=u>>>3;do if(u>>>0<256)if(n=t[T+8>>2]|0,e=t[T+12>>2]|0,(e|0)==(n|0)){t[2783]=t[2783]&~(1<>2]=e,t[e+8>>2]=n;break}else{a=t[T+24>>2]|0,e=t[T+12>>2]|0;do if((e|0)==(T|0)){if(r=T+16|0,n=r+4|0,e=t[n>>2]|0,!e)if(e=t[r>>2]|0,e)n=r;else{r=0;break}for(;;){if(r=e+20|0,u=t[r>>2]|0,u|0){e=u,n=r;continue}if(r=e+16|0,u=t[r>>2]|0,u)e=u,n=r;else break}t[n>>2]=0,r=e}else r=t[T+8>>2]|0,t[r+12>>2]=e,t[e+8>>2]=r,r=e;while(0);if(a|0){if(e=t[T+28>>2]|0,n=11436+(e<<2)|0,(T|0)==(t[n>>2]|0)){if(t[n>>2]=r,!r){t[2784]=t[2784]&~(1<>2]|0)!=(T|0)&1)<<2)>>2]=r,!r)break;t[r+24>>2]=a,e=T+16|0,n=t[e>>2]|0,n|0&&(t[r+16>>2]=n,t[n+24>>2]=r),e=t[e+4>>2]|0,e|0&&(t[r+20>>2]=e,t[e+24>>2]=r)}}while(0);if(t[w+4>>2]=s|1,t[v+s>>2]=s,(w|0)==(t[2788]|0)){t[2785]=s;return}}if(e=s>>>3,s>>>0<256){r=11172+(e<<1<<2)|0,n=t[2783]|0,e=1<>2]|0):(t[2783]=n|e,e=r,n=r+8|0),t[n>>2]=w,t[e+12>>2]=w,t[w+8>>2]=e,t[w+12>>2]=r;return}e=s>>>8,e?s>>>0>16777215?e=31:(v=(e+1048320|0)>>>16&8,T=e<>>16&4,T=T<>>16&2,e=14-(a|v|e)+(T<>>15)|0,e=s>>>(e+7|0)&1|e<<1):e=0,u=11436+(e<<2)|0,t[w+28>>2]=e,t[w+20>>2]=0,t[w+16>>2]=0,n=t[2784]|0,r=1<>>1)|0),r=t[u>>2]|0;;){if((t[r+4>>2]&-8|0)==(s|0)){e=73;break}if(u=r+16+(n>>>31<<2)|0,e=t[u>>2]|0,e)n=n<<1,r=e;else{e=72;break}}if((e|0)==72){t[u>>2]=w,t[w+24>>2]=r,t[w+12>>2]=w,t[w+8>>2]=w;break}else if((e|0)==73){v=r+8|0,T=t[v>>2]|0,t[T+12>>2]=w,t[v>>2]=w,t[w+8>>2]=T,t[w+12>>2]=r,t[w+24>>2]=0;break}}else t[2784]=n|r,t[u>>2]=w,t[w+24>>2]=u,t[w+12>>2]=w,t[w+8>>2]=w;while(0);if(T=(t[2791]|0)+-1|0,t[2791]=T,!T)e=11588;else return;for(;e=t[e>>2]|0,e;)e=e+8|0;t[2791]=-1}}}function aL(){return 11628}function fL(e){e=e|0;var n=0,r=0;return n=y,y=y+16|0,r=n,t[r>>2]=pL(t[e+60>>2]|0)|0,e=v_(Au(6,r|0)|0)|0,y=n,e|0}function p8(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0,Be=0;b=y,y=y+48|0,L=b+16|0,a=b,s=b+32|0,w=e+28|0,u=t[w>>2]|0,t[s>>2]=u,T=e+20|0,u=(t[T>>2]|0)-u|0,t[s+4>>2]=u,t[s+8>>2]=n,t[s+12>>2]=r,u=u+r|0,v=e+60|0,t[a>>2]=t[v>>2],t[a+4>>2]=s,t[a+8>>2]=2,a=v_(h0(146,a|0)|0)|0;e:do if((u|0)!=(a|0)){for(n=2;!((a|0)<0);)if(u=u-a|0,Be=t[s+4>>2]|0,X=a>>>0>Be>>>0,s=X?s+8|0:s,n=(X<<31>>31)+n|0,Be=a-(X?Be:0)|0,t[s>>2]=(t[s>>2]|0)+Be,X=s+4|0,t[X>>2]=(t[X>>2]|0)-Be,t[L>>2]=t[v>>2],t[L+4>>2]=s,t[L+8>>2]=n,a=v_(h0(146,L|0)|0)|0,(u|0)==(a|0)){M=3;break e}t[e+16>>2]=0,t[w>>2]=0,t[T>>2]=0,t[e>>2]=t[e>>2]|32,(n|0)==2?r=0:r=r-(t[s+4>>2]|0)|0}else M=3;while(0);return(M|0)==3&&(Be=t[e+44>>2]|0,t[e+16>>2]=Be+(t[e+48>>2]|0),t[w>>2]=Be,t[T>>2]=Be),y=b,r|0}function cL(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0;return s=y,y=y+32|0,a=s,u=s+20|0,t[a>>2]=t[e+60>>2],t[a+4>>2]=0,t[a+8>>2]=n,t[a+12>>2]=u,t[a+16>>2]=r,(v_(Ni(140,a|0)|0)|0)<0?(t[u>>2]=-1,e=-1):e=t[u>>2]|0,y=s,e|0}function v_(e){return e=e|0,e>>>0>4294963200&&(t[(bv()|0)>>2]=0-e,e=-1),e|0}function bv(){return(dL()|0)+64|0}function dL(){return ME()|0}function ME(){return 2084}function pL(e){return e=e|0,e|0}function hL(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0;return s=y,y=y+32|0,u=s,t[e+36>>2]=1,(t[e>>2]&64|0)==0&&(t[u>>2]=t[e+60>>2],t[u+4>>2]=21523,t[u+8>>2]=s+16,I0(54,u|0)|0)&&(h[e+75>>0]=-1),u=p8(e,n,r)|0,y=s,u|0}function h8(e,n){e=e|0,n=n|0;var r=0,u=0;if(r=h[e>>0]|0,u=h[n>>0]|0,r<<24>>24==0||r<<24>>24!=u<<24>>24)e=u;else{do e=e+1|0,n=n+1|0,r=h[e>>0]|0,u=h[n>>0]|0;while(!(r<<24>>24==0||r<<24>>24!=u<<24>>24));e=u}return(r&255)-(e&255)|0}function vL(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0;e:do if(!r)e=0;else{for(;u=h[e>>0]|0,s=h[n>>0]|0,u<<24>>24==s<<24>>24;)if(r=r+-1|0,r)e=e+1|0,n=n+1|0;else{e=0;break e}e=(u&255)-(s&255)|0}while(0);return e|0}function v8(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0,Be=0,Te=0,ye=0;ye=y,y=y+224|0,M=ye+120|0,b=ye+80|0,Be=ye,Te=ye+136|0,u=b,s=u+40|0;do t[u>>2]=0,u=u+4|0;while((u|0)<(s|0));return t[M>>2]=t[r>>2],(kE(0,n,M,Be,b)|0)<0?r=-1:((t[e+76>>2]|0)>-1?X=mL(e)|0:X=0,r=t[e>>2]|0,L=r&32,(h[e+74>>0]|0)<1&&(t[e>>2]=r&-33),u=e+48|0,t[u>>2]|0?r=kE(e,n,M,Be,b)|0:(s=e+44|0,a=t[s>>2]|0,t[s>>2]=Te,v=e+28|0,t[v>>2]=Te,w=e+20|0,t[w>>2]=Te,t[u>>2]=80,T=e+16|0,t[T>>2]=Te+80,r=kE(e,n,M,Be,b)|0,a&&(__[t[e+36>>2]&7](e,0,0)|0,r=(t[w>>2]|0)==0?-1:r,t[s>>2]=a,t[u>>2]=0,t[T>>2]=0,t[v>>2]=0,t[w>>2]=0)),u=t[e>>2]|0,t[e>>2]=u|L,X|0&&yL(e),r=(u&32|0)==0?r:-1),y=ye,r|0}function kE(e,n,r,u,s){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0;var a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0,Be=0,Te=0,ye=0,Ze=0,Ye=0,ct=0,ke=0,Ie=0,Zt=0,Br=0,Pn=0,gn=0,_r=0,Pr=0,kn=0;kn=y,y=y+64|0,Pn=kn+16|0,gn=kn,Zt=kn+24|0,_r=kn+8|0,Pr=kn+20|0,t[Pn>>2]=n,ct=(e|0)!=0,ke=Zt+40|0,Ie=ke,Zt=Zt+39|0,Br=_r+4|0,v=0,a=0,M=0;e:for(;;){do if((a|0)>-1)if((v|0)>(2147483647-a|0)){t[(bv()|0)>>2]=75,a=-1;break}else{a=v+a|0;break}while(0);if(v=h[n>>0]|0,v<<24>>24)w=n;else{Ye=87;break}t:for(;;){switch(v<<24>>24){case 37:{v=w,Ye=9;break t}case 0:{v=w;break t}default:}Ze=w+1|0,t[Pn>>2]=Ze,v=h[Ze>>0]|0,w=Ze}t:do if((Ye|0)==9)for(;;){if(Ye=0,(h[w+1>>0]|0)!=37)break t;if(v=v+1|0,w=w+2|0,t[Pn>>2]=w,(h[w>>0]|0)==37)Ye=9;else break}while(0);if(v=v-n|0,ct&&Yo(e,n,v),v|0){n=w;continue}T=w+1|0,v=(h[T>>0]|0)+-48|0,v>>>0<10?(Ze=(h[w+2>>0]|0)==36,ye=Ze?v:-1,M=Ze?1:M,T=Ze?w+3|0:T):ye=-1,t[Pn>>2]=T,v=h[T>>0]|0,w=(v<<24>>24)+-32|0;t:do if(w>>>0<32)for(L=0,b=v;;){if(v=1<>2]=T,v=h[T>>0]|0,w=(v<<24>>24)+-32|0,w>>>0>=32)break;b=v}else L=0;while(0);if(v<<24>>24==42){if(w=T+1|0,v=(h[w>>0]|0)+-48|0,v>>>0<10&&(h[T+2>>0]|0)==36)t[s+(v<<2)>>2]=10,v=t[u+((h[w>>0]|0)+-48<<3)>>2]|0,M=1,T=T+3|0;else{if(M|0){a=-1;break}ct?(M=(t[r>>2]|0)+(4-1)&~(4-1),v=t[M>>2]|0,t[r>>2]=M+4,M=0,T=w):(v=0,M=0,T=w)}t[Pn>>2]=T,Ze=(v|0)<0,v=Ze?0-v|0:v,L=Ze?L|8192:L}else{if(v=m8(Pn)|0,(v|0)<0){a=-1;break}T=t[Pn>>2]|0}do if((h[T>>0]|0)==46){if((h[T+1>>0]|0)!=42){t[Pn>>2]=T+1,w=m8(Pn)|0,T=t[Pn>>2]|0;break}if(b=T+2|0,w=(h[b>>0]|0)+-48|0,w>>>0<10&&(h[T+3>>0]|0)==36){t[s+(w<<2)>>2]=10,w=t[u+((h[b>>0]|0)+-48<<3)>>2]|0,T=T+4|0,t[Pn>>2]=T;break}if(M|0){a=-1;break e}ct?(Ze=(t[r>>2]|0)+(4-1)&~(4-1),w=t[Ze>>2]|0,t[r>>2]=Ze+4):w=0,t[Pn>>2]=b,T=b}else w=-1;while(0);for(Te=0;;){if(((h[T>>0]|0)+-65|0)>>>0>57){a=-1;break e}if(Ze=T+1|0,t[Pn>>2]=Ze,b=h[(h[T>>0]|0)+-65+(5178+(Te*58|0))>>0]|0,X=b&255,(X+-1|0)>>>0<8)Te=X,T=Ze;else break}if(!(b<<24>>24)){a=-1;break}Be=(ye|0)>-1;do if(b<<24>>24==19)if(Be){a=-1;break e}else Ye=49;else{if(Be){t[s+(ye<<2)>>2]=X,Be=u+(ye<<3)|0,ye=t[Be+4>>2]|0,Ye=gn,t[Ye>>2]=t[Be>>2],t[Ye+4>>2]=ye,Ye=49;break}if(!ct){a=0;break e}y8(gn,X,r)}while(0);if((Ye|0)==49&&(Ye=0,!ct)){v=0,n=Ze;continue}T=h[T>>0]|0,T=(Te|0)!=0&(T&15|0)==3?T&-33:T,Be=L&-65537,ye=(L&8192|0)==0?L:Be;t:do switch(T|0){case 110:switch((Te&255)<<24>>24){case 0:{t[t[gn>>2]>>2]=a,v=0,n=Ze;continue e}case 1:{t[t[gn>>2]>>2]=a,v=0,n=Ze;continue e}case 2:{v=t[gn>>2]|0,t[v>>2]=a,t[v+4>>2]=((a|0)<0)<<31>>31,v=0,n=Ze;continue e}case 3:{E[t[gn>>2]>>1]=a,v=0,n=Ze;continue e}case 4:{h[t[gn>>2]>>0]=a,v=0,n=Ze;continue e}case 6:{t[t[gn>>2]>>2]=a,v=0,n=Ze;continue e}case 7:{v=t[gn>>2]|0,t[v>>2]=a,t[v+4>>2]=((a|0)<0)<<31>>31,v=0,n=Ze;continue e}default:{v=0,n=Ze;continue e}}case 112:{T=120,w=w>>>0>8?w:8,n=ye|8,Ye=61;break}case 88:case 120:{n=ye,Ye=61;break}case 111:{T=gn,n=t[T>>2]|0,T=t[T+4>>2]|0,X=_L(n,T,ke)|0,Be=Ie-X|0,L=0,b=5642,w=(ye&8|0)==0|(w|0)>(Be|0)?w:Be+1|0,Be=ye,Ye=67;break}case 105:case 100:if(T=gn,n=t[T>>2]|0,T=t[T+4>>2]|0,(T|0)<0){n=m_(0,0,n|0,T|0)|0,T=ot,L=gn,t[L>>2]=n,t[L+4>>2]=T,L=1,b=5642,Ye=66;break t}else{L=(ye&2049|0)!=0&1,b=(ye&2048|0)==0?(ye&1|0)==0?5642:5644:5643,Ye=66;break t}case 117:{T=gn,L=0,b=5642,n=t[T>>2]|0,T=t[T+4>>2]|0,Ye=66;break}case 99:{h[Zt>>0]=t[gn>>2],n=Zt,L=0,b=5642,X=ke,T=1,w=Be;break}case 109:{T=EL(t[(bv()|0)>>2]|0)|0,Ye=71;break}case 115:{T=t[gn>>2]|0,T=T|0?T:5652,Ye=71;break}case 67:{t[_r>>2]=t[gn>>2],t[Br>>2]=0,t[gn>>2]=_r,X=-1,T=_r,Ye=75;break}case 83:{n=t[gn>>2]|0,w?(X=w,T=n,Ye=75):(_l(e,32,v,0,ye),n=0,Ye=84);break}case 65:case 71:case 70:case 69:case 97:case 103:case 102:case 101:{v=wL(e,+j[gn>>3],v,w,ye,T)|0,n=Ze;continue e}default:L=0,b=5642,X=ke,T=w,w=ye}while(0);t:do if((Ye|0)==61)ye=gn,Te=t[ye>>2]|0,ye=t[ye+4>>2]|0,X=gL(Te,ye,ke,T&32)|0,b=(n&8|0)==0|(Te|0)==0&(ye|0)==0,L=b?0:2,b=b?5642:5642+(T>>4)|0,Be=n,n=Te,T=ye,Ye=67;else if((Ye|0)==66)X=Bv(n,T,ke)|0,Be=ye,Ye=67;else if((Ye|0)==71)Ye=0,ye=DL(T,0,w)|0,Te=(ye|0)==0,n=T,L=0,b=5642,X=Te?T+w|0:ye,T=Te?w:ye-T|0,w=Be;else if((Ye|0)==75){for(Ye=0,b=T,n=0,w=0;L=t[b>>2]|0,!(!L||(w=g8(Pr,L)|0,(w|0)<0|w>>>0>(X-n|0)>>>0));)if(n=w+n|0,X>>>0>n>>>0)b=b+4|0;else break;if((w|0)<0){a=-1;break e}if(_l(e,32,v,n,ye),!n)n=0,Ye=84;else for(L=0;;){if(w=t[T>>2]|0,!w){Ye=84;break t}if(w=g8(Pr,w)|0,L=w+L|0,(L|0)>(n|0)){Ye=84;break t}if(Yo(e,Pr,w),L>>>0>=n>>>0){Ye=84;break}else T=T+4|0}}while(0);if((Ye|0)==67)Ye=0,T=(n|0)!=0|(T|0)!=0,ye=(w|0)!=0|T,T=((T^1)&1)+(Ie-X)|0,n=ye?X:ke,X=ke,T=ye?(w|0)>(T|0)?w:T:w,w=(w|0)>-1?Be&-65537:Be;else if((Ye|0)==84){Ye=0,_l(e,32,v,n,ye^8192),v=(v|0)>(n|0)?v:n,n=Ze;continue}Te=X-n|0,Be=(T|0)<(Te|0)?Te:T,ye=Be+L|0,v=(v|0)<(ye|0)?ye:v,_l(e,32,v,ye,w),Yo(e,b,L),_l(e,48,v,ye,w^65536),_l(e,48,Be,Te,0),Yo(e,n,Te),_l(e,32,v,ye,w^8192),n=Ze}e:do if((Ye|0)==87&&!e)if(!M)a=0;else{for(a=1;n=t[s+(a<<2)>>2]|0,!!n;)if(y8(u+(a<<3)|0,n,r),a=a+1|0,(a|0)>=10){a=1;break e}for(;;){if(t[s+(a<<2)>>2]|0){a=-1;break e}if(a=a+1|0,(a|0)>=10){a=1;break}}}while(0);return y=kn,a|0}function mL(e){return e=e|0,0}function yL(e){e=e|0}function Yo(e,n,r){e=e|0,n=n|0,r=r|0,t[e>>2]&32||kL(n,r,e)|0}function m8(e){e=e|0;var n=0,r=0,u=0;if(r=t[e>>2]|0,u=(h[r>>0]|0)+-48|0,u>>>0<10){n=0;do n=u+(n*10|0)|0,r=r+1|0,t[e>>2]=r,u=(h[r>>0]|0)+-48|0;while(u>>>0<10)}else n=0;return n|0}function y8(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0;e:do if(n>>>0<=20)do switch(n|0){case 9:{u=(t[r>>2]|0)+(4-1)&~(4-1),n=t[u>>2]|0,t[r>>2]=u+4,t[e>>2]=n;break e}case 10:{u=(t[r>>2]|0)+(4-1)&~(4-1),n=t[u>>2]|0,t[r>>2]=u+4,u=e,t[u>>2]=n,t[u+4>>2]=((n|0)<0)<<31>>31;break e}case 11:{u=(t[r>>2]|0)+(4-1)&~(4-1),n=t[u>>2]|0,t[r>>2]=u+4,u=e,t[u>>2]=n,t[u+4>>2]=0;break e}case 12:{u=(t[r>>2]|0)+(8-1)&~(8-1),n=u,s=t[n>>2]|0,n=t[n+4>>2]|0,t[r>>2]=u+8,u=e,t[u>>2]=s,t[u+4>>2]=n;break e}case 13:{s=(t[r>>2]|0)+(4-1)&~(4-1),u=t[s>>2]|0,t[r>>2]=s+4,u=(u&65535)<<16>>16,s=e,t[s>>2]=u,t[s+4>>2]=((u|0)<0)<<31>>31;break e}case 14:{s=(t[r>>2]|0)+(4-1)&~(4-1),u=t[s>>2]|0,t[r>>2]=s+4,s=e,t[s>>2]=u&65535,t[s+4>>2]=0;break e}case 15:{s=(t[r>>2]|0)+(4-1)&~(4-1),u=t[s>>2]|0,t[r>>2]=s+4,u=(u&255)<<24>>24,s=e,t[s>>2]=u,t[s+4>>2]=((u|0)<0)<<31>>31;break e}case 16:{s=(t[r>>2]|0)+(4-1)&~(4-1),u=t[s>>2]|0,t[r>>2]=s+4,s=e,t[s>>2]=u&255,t[s+4>>2]=0;break e}case 17:{s=(t[r>>2]|0)+(8-1)&~(8-1),a=+j[s>>3],t[r>>2]=s+8,j[e>>3]=a;break e}case 18:{s=(t[r>>2]|0)+(8-1)&~(8-1),a=+j[s>>3],t[r>>2]=s+8,j[e>>3]=a;break e}default:break e}while(0);while(0)}function gL(e,n,r,u){if(e=e|0,n=n|0,r=r|0,u=u|0,!((e|0)==0&(n|0)==0))do r=r+-1|0,h[r>>0]=N[5694+(e&15)>>0]|0|u,e=y_(e|0,n|0,4)|0,n=ot;while(!((e|0)==0&(n|0)==0));return r|0}function _L(e,n,r){if(e=e|0,n=n|0,r=r|0,!((e|0)==0&(n|0)==0))do r=r+-1|0,h[r>>0]=e&7|48,e=y_(e|0,n|0,3)|0,n=ot;while(!((e|0)==0&(n|0)==0));return r|0}function Bv(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;if(n>>>0>0|(n|0)==0&e>>>0>4294967295){for(;u=PE(e|0,n|0,10,0)|0,r=r+-1|0,h[r>>0]=u&255|48,u=e,e=FE(e|0,n|0,10,0)|0,n>>>0>9|(n|0)==9&u>>>0>4294967295;)n=ot;n=e}else n=e;if(n)for(;r=r+-1|0,h[r>>0]=(n>>>0)%10|0|48,!(n>>>0<10);)n=(n>>>0)/10|0;return r|0}function EL(e){return e=e|0,RL(e,t[(xL()|0)+188>>2]|0)|0}function DL(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;a=n&255,u=(r|0)!=0;e:do if(u&(e&3|0)!=0)for(s=n&255;;){if((h[e>>0]|0)==s<<24>>24){v=6;break e}if(e=e+1|0,r=r+-1|0,u=(r|0)!=0,!(u&(e&3|0)!=0)){v=5;break}}else v=5;while(0);(v|0)==5&&(u?v=6:r=0);e:do if((v|0)==6&&(s=n&255,(h[e>>0]|0)!=s<<24>>24)){u=lr(a,16843009)|0;t:do if(r>>>0>3){for(;a=t[e>>2]^u,!((a&-2139062144^-2139062144)&a+-16843009|0);)if(e=e+4|0,r=r+-4|0,r>>>0<=3){v=11;break t}}else v=11;while(0);if((v|0)==11&&!r){r=0;break}for(;;){if((h[e>>0]|0)==s<<24>>24)break e;if(e=e+1|0,r=r+-1|0,!r){r=0;break}}}while(0);return(r|0?e:0)|0}function _l(e,n,r,u,s){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0;var a=0,v=0;if(v=y,y=y+256|0,a=v,(r|0)>(u|0)&(s&73728|0)==0){if(s=r-u|0,jv(a|0,n|0,(s>>>0<256?s:256)|0)|0,s>>>0>255){n=r-u|0;do Yo(e,a,256),s=s+-256|0;while(s>>>0>255);s=n&255}Yo(e,a,s)}y=v}function g8(e,n){return e=e|0,n=n|0,e?e=TL(e,n,0)|0:e=0,e|0}function wL(e,n,r,u,s,a){e=e|0,n=+n,r=r|0,u=u|0,s=s|0,a=a|0;var v=0,w=0,T=0,L=0,M=0,b=0,X=0,Be=0,Te=0,ye=0,Ze=0,Ye=0,ct=0,ke=0,Ie=0,Zt=0,Br=0,Pn=0,gn=0,_r=0,Pr=0,kn=0,uu=0;uu=y,y=y+560|0,T=uu+8|0,Ze=uu,kn=uu+524|0,Pr=kn,L=uu+512|0,t[Ze>>2]=0,_r=L+12|0,_8(n)|0,(ot|0)<0?(n=-n,Pn=1,Br=5659):(Pn=(s&2049|0)!=0&1,Br=(s&2048|0)==0?(s&1|0)==0?5660:5665:5662),_8(n)|0,gn=ot&2146435072;do if(gn>>>0<2146435072|(gn|0)==2146435072&0<0){if(Be=+SL(n,Ze)*2,v=Be!=0,v&&(t[Ze>>2]=(t[Ze>>2]|0)+-1),ct=a|32,(ct|0)==97){Te=a&32,X=(Te|0)==0?Br:Br+9|0,b=Pn|2,v=12-u|0;do if(u>>>0>11|(v|0)==0)n=Be;else{n=8;do v=v+-1|0,n=n*16;while((v|0)!=0);if((h[X>>0]|0)==45){n=-(n+(-Be-n));break}else{n=Be+n-n;break}}while(0);w=t[Ze>>2]|0,v=(w|0)<0?0-w|0:w,v=Bv(v,((v|0)<0)<<31>>31,_r)|0,(v|0)==(_r|0)&&(v=L+11|0,h[v>>0]=48),h[v+-1>>0]=(w>>31&2)+43,M=v+-2|0,h[M>>0]=a+15,L=(u|0)<1,T=(s&8|0)==0,v=kn;do gn=~~n,w=v+1|0,h[v>>0]=N[5694+gn>>0]|Te,n=(n-+(gn|0))*16,(w-Pr|0)==1&&!(T&(L&n==0))?(h[w>>0]=46,v=v+2|0):v=w;while(n!=0);gn=v-Pr|0,Pr=_r-M|0,_r=(u|0)!=0&(gn+-2|0)<(u|0)?u+2|0:gn,v=Pr+b+_r|0,_l(e,32,r,v,s),Yo(e,X,b),_l(e,48,r,v,s^65536),Yo(e,kn,gn),_l(e,48,_r-gn|0,0,0),Yo(e,M,Pr),_l(e,32,r,v,s^8192);break}w=(u|0)<0?6:u,v?(v=(t[Ze>>2]|0)+-28|0,t[Ze>>2]=v,n=Be*268435456):(n=Be,v=t[Ze>>2]|0),gn=(v|0)<0?T:T+288|0,T=gn;do Ie=~~n>>>0,t[T>>2]=Ie,T=T+4|0,n=(n-+(Ie>>>0))*1e9;while(n!=0);if((v|0)>0)for(L=gn,b=T;;){if(M=(v|0)<29?v:29,v=b+-4|0,v>>>0>=L>>>0){T=0;do ke=C8(t[v>>2]|0,0,M|0)|0,ke=LE(ke|0,ot|0,T|0,0)|0,Ie=ot,Ye=PE(ke|0,Ie|0,1e9,0)|0,t[v>>2]=Ye,T=FE(ke|0,Ie|0,1e9,0)|0,v=v+-4|0;while(v>>>0>=L>>>0);T&&(L=L+-4|0,t[L>>2]=T)}for(T=b;!(T>>>0<=L>>>0);)if(v=T+-4|0,!(t[v>>2]|0))T=v;else break;if(v=(t[Ze>>2]|0)-M|0,t[Ze>>2]=v,(v|0)>0)b=T;else break}else L=gn;if((v|0)<0){u=((w+25|0)/9|0)+1|0,ye=(ct|0)==102;do{if(Te=0-v|0,Te=(Te|0)<9?Te:9,L>>>0>>0){M=(1<>>Te,X=0,v=L;do Ie=t[v>>2]|0,t[v>>2]=(Ie>>>Te)+X,X=lr(Ie&M,b)|0,v=v+4|0;while(v>>>0>>0);v=(t[L>>2]|0)==0?L+4|0:L,X?(t[T>>2]=X,L=v,v=T+4|0):(L=v,v=T)}else L=(t[L>>2]|0)==0?L+4|0:L,v=T;T=ye?gn:L,T=(v-T>>2|0)>(u|0)?T+(u<<2)|0:v,v=(t[Ze>>2]|0)+Te|0,t[Ze>>2]=v}while((v|0)<0);v=L,u=T}else v=L,u=T;if(Ie=gn,v>>>0>>0){if(T=(Ie-v>>2)*9|0,M=t[v>>2]|0,M>>>0>=10){L=10;do L=L*10|0,T=T+1|0;while(M>>>0>=L>>>0)}}else T=0;if(ye=(ct|0)==103,Ye=(w|0)!=0,L=w-((ct|0)!=102?T:0)+((Ye&ye)<<31>>31)|0,(L|0)<(((u-Ie>>2)*9|0)+-9|0)){if(L=L+9216|0,Te=gn+4+(((L|0)/9|0)+-1024<<2)|0,L=((L|0)%9|0)+1|0,(L|0)<9){M=10;do M=M*10|0,L=L+1|0;while((L|0)!=9)}else M=10;if(b=t[Te>>2]|0,X=(b>>>0)%(M>>>0)|0,L=(Te+4|0)==(u|0),L&(X|0)==0)L=Te;else if(Be=(((b>>>0)/(M>>>0)|0)&1|0)==0?9007199254740992:9007199254740994,ke=(M|0)/2|0,n=X>>>0>>0?.5:L&(X|0)==(ke|0)?1:1.5,Pn&&(ke=(h[Br>>0]|0)==45,n=ke?-n:n,Be=ke?-Be:Be),L=b-X|0,t[Te>>2]=L,Be+n!=Be){if(ke=L+M|0,t[Te>>2]=ke,ke>>>0>999999999)for(T=Te;L=T+-4|0,t[T>>2]=0,L>>>0>>0&&(v=v+-4|0,t[v>>2]=0),ke=(t[L>>2]|0)+1|0,t[L>>2]=ke,ke>>>0>999999999;)T=L;else L=Te;if(T=(Ie-v>>2)*9|0,b=t[v>>2]|0,b>>>0>=10){M=10;do M=M*10|0,T=T+1|0;while(b>>>0>=M>>>0)}}else L=Te;L=L+4|0,L=u>>>0>L>>>0?L:u,ke=v}else L=u,ke=v;for(ct=L;;){if(ct>>>0<=ke>>>0){Ze=0;break}if(v=ct+-4|0,!(t[v>>2]|0))ct=v;else{Ze=1;break}}u=0-T|0;do if(ye)if(v=((Ye^1)&1)+w|0,(v|0)>(T|0)&(T|0)>-5?(M=a+-1|0,w=v+-1-T|0):(M=a+-2|0,w=v+-1|0),v=s&8,v)Te=v;else{if(Ze&&(Zt=t[ct+-4>>2]|0,(Zt|0)!=0))if((Zt>>>0)%10|0)L=0;else{L=0,v=10;do v=v*10|0,L=L+1|0;while(!((Zt>>>0)%(v>>>0)|0|0))}else L=9;if(v=((ct-Ie>>2)*9|0)+-9|0,(M|32|0)==102){Te=v-L|0,Te=(Te|0)>0?Te:0,w=(w|0)<(Te|0)?w:Te,Te=0;break}else{Te=v+T-L|0,Te=(Te|0)>0?Te:0,w=(w|0)<(Te|0)?w:Te,Te=0;break}}else M=a,Te=s&8;while(0);if(ye=w|Te,b=(ye|0)!=0&1,X=(M|32|0)==102,X)Ye=0,v=(T|0)>0?T:0;else{if(v=(T|0)<0?u:T,v=Bv(v,((v|0)<0)<<31>>31,_r)|0,L=_r,(L-v|0)<2)do v=v+-1|0,h[v>>0]=48;while((L-v|0)<2);h[v+-1>>0]=(T>>31&2)+43,v=v+-2|0,h[v>>0]=M,Ye=v,v=L-v|0}if(v=Pn+1+w+b+v|0,_l(e,32,r,v,s),Yo(e,Br,Pn),_l(e,48,r,v,s^65536),X){M=ke>>>0>gn>>>0?gn:ke,Te=kn+9|0,b=Te,X=kn+8|0,L=M;do{if(T=Bv(t[L>>2]|0,0,Te)|0,(L|0)==(M|0))(T|0)==(Te|0)&&(h[X>>0]=48,T=X);else if(T>>>0>kn>>>0){jv(kn|0,48,T-Pr|0)|0;do T=T+-1|0;while(T>>>0>kn>>>0)}Yo(e,T,b-T|0),L=L+4|0}while(L>>>0<=gn>>>0);if(ye|0&&Yo(e,5710,1),L>>>0>>0&(w|0)>0)for(;;){if(T=Bv(t[L>>2]|0,0,Te)|0,T>>>0>kn>>>0){jv(kn|0,48,T-Pr|0)|0;do T=T+-1|0;while(T>>>0>kn>>>0)}if(Yo(e,T,(w|0)<9?w:9),L=L+4|0,T=w+-9|0,L>>>0>>0&(w|0)>9)w=T;else{w=T;break}}_l(e,48,w+9|0,9,0)}else{if(ye=Ze?ct:ke+4|0,(w|0)>-1){Ze=kn+9|0,Te=(Te|0)==0,u=Ze,b=0-Pr|0,X=kn+8|0,M=ke;do{T=Bv(t[M>>2]|0,0,Ze)|0,(T|0)==(Ze|0)&&(h[X>>0]=48,T=X);do if((M|0)==(ke|0)){if(L=T+1|0,Yo(e,T,1),Te&(w|0)<1){T=L;break}Yo(e,5710,1),T=L}else{if(T>>>0<=kn>>>0)break;jv(kn|0,48,T+b|0)|0;do T=T+-1|0;while(T>>>0>kn>>>0)}while(0);Pr=u-T|0,Yo(e,T,(w|0)>(Pr|0)?Pr:w),w=w-Pr|0,M=M+4|0}while(M>>>0>>0&(w|0)>-1)}_l(e,48,w+18|0,18,0),Yo(e,Ye,_r-Ye|0)}_l(e,32,r,v,s^8192)}else kn=(a&32|0)!=0,v=Pn+3|0,_l(e,32,r,v,s&-65537),Yo(e,Br,Pn),Yo(e,n!=n|!1?kn?5686:5690:kn?5678:5682,3),_l(e,32,r,v,s^8192);while(0);return y=uu,((v|0)<(r|0)?r:v)|0}function _8(e){e=+e;var n=0;return j[V>>3]=e,n=t[V>>2]|0,ot=t[V+4>>2]|0,n|0}function SL(e,n){return e=+e,n=n|0,+ +E8(e,n)}function E8(e,n){e=+e,n=n|0;var r=0,u=0,s=0;switch(j[V>>3]=e,r=t[V>>2]|0,u=t[V+4>>2]|0,s=y_(r|0,u|0,52)|0,s&2047){case 0:{e!=0?(e=+E8(e*18446744073709552e3,n),r=(t[n>>2]|0)+-64|0):r=0,t[n>>2]=r;break}case 2047:break;default:t[n>>2]=(s&2047)+-1022,t[V>>2]=r,t[V+4>>2]=u&-2146435073|1071644672,e=+j[V>>3]}return+e}function TL(e,n,r){e=e|0,n=n|0,r=r|0;do if(e){if(n>>>0<128){h[e>>0]=n,e=1;break}if(!(t[t[(CL()|0)+188>>2]>>2]|0))if((n&-128|0)==57216){h[e>>0]=n,e=1;break}else{t[(bv()|0)>>2]=84,e=-1;break}if(n>>>0<2048){h[e>>0]=n>>>6|192,h[e+1>>0]=n&63|128,e=2;break}if(n>>>0<55296|(n&-8192|0)==57344){h[e>>0]=n>>>12|224,h[e+1>>0]=n>>>6&63|128,h[e+2>>0]=n&63|128,e=3;break}if((n+-65536|0)>>>0<1048576){h[e>>0]=n>>>18|240,h[e+1>>0]=n>>>12&63|128,h[e+2>>0]=n>>>6&63|128,h[e+3>>0]=n&63|128,e=4;break}else{t[(bv()|0)>>2]=84,e=-1;break}}else e=1;while(0);return e|0}function CL(){return ME()|0}function xL(){return ME()|0}function RL(e,n){e=e|0,n=n|0;var r=0,u=0;for(u=0;;){if((N[5712+u>>0]|0)==(e|0)){e=2;break}if(r=u+1|0,(r|0)==87){r=5800,u=87,e=5;break}else u=r}if((e|0)==2&&(u?(r=5800,e=5):r=5800),(e|0)==5)for(;;){do e=r,r=r+1|0;while((h[e>>0]|0)!=0);if(u=u+-1|0,u)e=5;else break}return AL(r,t[n+20>>2]|0)|0}function AL(e,n){return e=e|0,n=n|0,OL(e,n)|0}function OL(e,n){return e=e|0,n=n|0,n?n=ML(t[n>>2]|0,t[n+4>>2]|0,e)|0:n=0,(n|0?n:e)|0}function ML(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0;X=(t[e>>2]|0)+1794895138|0,a=Yp(t[e+8>>2]|0,X)|0,u=Yp(t[e+12>>2]|0,X)|0,s=Yp(t[e+16>>2]|0,X)|0;e:do if(a>>>0>>2>>>0&&(b=n-(a<<2)|0,u>>>0>>0&s>>>0>>0)&&((s|u)&3|0)==0){for(b=u>>>2,M=s>>>2,L=0;;){if(w=a>>>1,T=L+w|0,v=T<<1,s=v+b|0,u=Yp(t[e+(s<<2)>>2]|0,X)|0,s=Yp(t[e+(s+1<<2)>>2]|0,X)|0,!(s>>>0>>0&u>>>0<(n-s|0)>>>0)){u=0;break e}if(h[e+(s+u)>>0]|0){u=0;break e}if(u=h8(r,e+s|0)|0,!u)break;if(u=(u|0)<0,(a|0)==1){u=0;break e}else L=u?L:T,a=u?w:a-w|0}u=v+M|0,s=Yp(t[e+(u<<2)>>2]|0,X)|0,u=Yp(t[e+(u+1<<2)>>2]|0,X)|0,u>>>0>>0&s>>>0<(n-u|0)>>>0?u=(h[e+(u+s)>>0]|0)==0?e+u|0:0:u=0}else u=0;while(0);return u|0}function Yp(e,n){e=e|0,n=n|0;var r=0;return r=A8(e|0)|0,((n|0)==0?e:r)|0}function kL(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0,w=0;u=r+16|0,s=t[u>>2]|0,s?a=5:NL(r)|0?u=0:(s=t[u>>2]|0,a=5);e:do if((a|0)==5){if(w=r+20|0,v=t[w>>2]|0,u=v,(s-v|0)>>>0>>0){u=__[t[r+36>>2]&7](r,e,n)|0;break}t:do if((h[r+75>>0]|0)>-1){for(v=n;;){if(!v){a=0,s=e;break t}if(s=v+-1|0,(h[e+s>>0]|0)==10)break;v=s}if(u=__[t[r+36>>2]&7](r,e,v)|0,u>>>0>>0)break e;a=v,s=e+v|0,n=n-v|0,u=t[w>>2]|0}else a=0,s=e;while(0);gr(u|0,s|0,n|0)|0,t[w>>2]=(t[w>>2]|0)+n,u=a+n|0}while(0);return u|0}function NL(e){e=e|0;var n=0,r=0;return n=e+74|0,r=h[n>>0]|0,h[n>>0]=r+255|r,n=t[e>>2]|0,n&8?(t[e>>2]=n|32,e=-1):(t[e+8>>2]=0,t[e+4>>2]=0,r=t[e+44>>2]|0,t[e+28>>2]=r,t[e+20>>2]=r,t[e+16>>2]=r+(t[e+48>>2]|0),e=0),e|0}function xu(e,n){e=S(e),n=S(n);var r=0,u=0;r=D8(e)|0;do if((r&2147483647)>>>0<=2139095040){if(u=D8(n)|0,(u&2147483647)>>>0<=2139095040)if((u^r|0)<0){e=(r|0)<0?n:e;break}else{e=e>2]=e,t[V>>2]|0|0}function Kp(e,n){e=S(e),n=S(n);var r=0,u=0;r=w8(e)|0;do if((r&2147483647)>>>0<=2139095040){if(u=w8(n)|0,(u&2147483647)>>>0<=2139095040)if((u^r|0)<0){e=(r|0)<0?e:n;break}else{e=e>2]=e,t[V>>2]|0|0}function NE(e,n){e=S(e),n=S(n);var r=0,u=0,s=0,a=0,v=0,w=0,T=0,L=0;a=(x[V>>2]=e,t[V>>2]|0),w=(x[V>>2]=n,t[V>>2]|0),r=a>>>23&255,v=w>>>23&255,T=a&-2147483648,s=w<<1;e:do if((s|0)!=0&&!((r|0)==255|((LL(n)|0)&2147483647)>>>0>2139095040)){if(u=a<<1,u>>>0<=s>>>0)return n=S(e*S(0)),S((u|0)==(s|0)?n:e);if(r)u=a&8388607|8388608;else{if(r=a<<9,(r|0)>-1){u=r,r=0;do r=r+-1|0,u=u<<1;while((u|0)>-1)}else r=0;u=a<<1-r}if(v)w=w&8388607|8388608;else{if(a=w<<9,(a|0)>-1){s=0;do s=s+-1|0,a=a<<1;while((a|0)>-1)}else s=0;v=s,w=w<<1-s}s=u-w|0,a=(s|0)>-1;t:do if((r|0)>(v|0)){for(;;){if(a)if(s)u=s;else break;if(u=u<<1,r=r+-1|0,s=u-w|0,a=(s|0)>-1,(r|0)<=(v|0))break t}n=S(e*S(0));break e}while(0);if(a)if(s)u=s;else{n=S(e*S(0));break}if(u>>>0<8388608)do u=u<<1,r=r+-1|0;while(u>>>0<8388608);(r|0)>0?r=u+-8388608|r<<23:r=u>>>(1-r|0),n=(t[V>>2]=r|T,S(x[V>>2]))}else L=3;while(0);return(L|0)==3&&(n=S(e*n),n=S(n/n)),S(n)}function LL(e){return e=S(e),x[V>>2]=e,t[V>>2]|0|0}function FL(e,n){return e=e|0,n=n|0,v8(t[582]|0,e,n)|0}function di(e){e=e|0,$n()}function Uv(e){e=e|0}function PL(e,n){return e=e|0,n=n|0,0}function IL(e){return e=e|0,(S8(e+4|0)|0)==-1?(P1[t[(t[e>>2]|0)+8>>2]&127](e),e=1):e=0,e|0}function S8(e){e=e|0;var n=0;return n=t[e>>2]|0,t[e>>2]=n+-1,n+-1|0}function $d(e){e=e|0,IL(e)|0&&bL(e)}function bL(e){e=e|0;var n=0;n=e+8|0,(t[n>>2]|0)!=0&&(S8(n)|0)!=-1||P1[t[(t[e>>2]|0)+16>>2]&127](e)}function pn(e){e=e|0;var n=0;for(n=(e|0)==0?1:e;e=p_(n)|0,!(e|0);){if(e=UL()|0,!e){e=0;break}B8[e&0]()}return e|0}function T8(e){return e=e|0,pn(e)|0}function Et(e){e=e|0,h_(e)}function BL(e){e=e|0,(h[e+11>>0]|0)<0&&Et(t[e>>2]|0)}function UL(){var e=0;return e=t[2923]|0,t[2923]=e+0,e|0}function jL(){}function m_(e,n,r,u){return e=e|0,n=n|0,r=r|0,u=u|0,u=n-u-(r>>>0>e>>>0|0)>>>0,ot=u,e-r>>>0|0|0}function LE(e,n,r,u){return e=e|0,n=n|0,r=r|0,u=u|0,r=e+r>>>0,ot=n+u+(r>>>0>>0|0)>>>0,r|0|0}function jv(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0,v=0;if(a=e+r|0,n=n&255,(r|0)>=67){for(;e&3;)h[e>>0]=n,e=e+1|0;for(u=a&-4|0,s=u-64|0,v=n|n<<8|n<<16|n<<24;(e|0)<=(s|0);)t[e>>2]=v,t[e+4>>2]=v,t[e+8>>2]=v,t[e+12>>2]=v,t[e+16>>2]=v,t[e+20>>2]=v,t[e+24>>2]=v,t[e+28>>2]=v,t[e+32>>2]=v,t[e+36>>2]=v,t[e+40>>2]=v,t[e+44>>2]=v,t[e+48>>2]=v,t[e+52>>2]=v,t[e+56>>2]=v,t[e+60>>2]=v,e=e+64|0;for(;(e|0)<(u|0);)t[e>>2]=v,e=e+4|0}for(;(e|0)<(a|0);)h[e>>0]=n,e=e+1|0;return a-r|0}function C8(e,n,r){return e=e|0,n=n|0,r=r|0,(r|0)<32?(ot=n<>>32-r,e<>>r,e>>>r|(n&(1<>>r-32|0)}function gr(e,n,r){e=e|0,n=n|0,r=r|0;var u=0,s=0,a=0;if((r|0)>=8192)return li(e|0,n|0,r|0)|0;if(a=e|0,s=e+r|0,(e&3)==(n&3)){for(;e&3;){if(!r)return a|0;h[e>>0]=h[n>>0]|0,e=e+1|0,n=n+1|0,r=r-1|0}for(r=s&-4|0,u=r-64|0;(e|0)<=(u|0);)t[e>>2]=t[n>>2],t[e+4>>2]=t[n+4>>2],t[e+8>>2]=t[n+8>>2],t[e+12>>2]=t[n+12>>2],t[e+16>>2]=t[n+16>>2],t[e+20>>2]=t[n+20>>2],t[e+24>>2]=t[n+24>>2],t[e+28>>2]=t[n+28>>2],t[e+32>>2]=t[n+32>>2],t[e+36>>2]=t[n+36>>2],t[e+40>>2]=t[n+40>>2],t[e+44>>2]=t[n+44>>2],t[e+48>>2]=t[n+48>>2],t[e+52>>2]=t[n+52>>2],t[e+56>>2]=t[n+56>>2],t[e+60>>2]=t[n+60>>2],e=e+64|0,n=n+64|0;for(;(e|0)<(r|0);)t[e>>2]=t[n>>2],e=e+4|0,n=n+4|0}else for(r=s-4|0;(e|0)<(r|0);)h[e>>0]=h[n>>0]|0,h[e+1>>0]=h[n+1>>0]|0,h[e+2>>0]=h[n+2>>0]|0,h[e+3>>0]=h[n+3>>0]|0,e=e+4|0,n=n+4|0;for(;(e|0)<(s|0);)h[e>>0]=h[n>>0]|0,e=e+1|0,n=n+1|0;return a|0}function x8(e){e=e|0;var n=0;return n=h[De+(e&255)>>0]|0,(n|0)<8?n|0:(n=h[De+(e>>8&255)>>0]|0,(n|0)<8?n+8|0:(n=h[De+(e>>16&255)>>0]|0,(n|0)<8?n+16|0:(h[De+(e>>>24)>>0]|0)+24|0))}function R8(e,n,r,u,s){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0;var a=0,v=0,w=0,T=0,L=0,M=0,b=0,X=0,Be=0,Te=0;if(M=e,T=n,L=T,v=r,X=u,w=X,!L)return a=(s|0)!=0,w?a?(t[s>>2]=e|0,t[s+4>>2]=n&0,X=0,s=0,ot=X,s|0):(X=0,s=0,ot=X,s|0):(a&&(t[s>>2]=(M>>>0)%(v>>>0),t[s+4>>2]=0),X=0,s=(M>>>0)/(v>>>0)>>>0,ot=X,s|0);a=(w|0)==0;do if(v){if(!a){if(a=(Er(w|0)|0)-(Er(L|0)|0)|0,a>>>0<=31){b=a+1|0,w=31-a|0,n=a-31>>31,v=b,e=M>>>(b>>>0)&n|L<>>(b>>>0)&n,a=0,w=M<>2]=e|0,t[s+4>>2]=T|n&0,X=0,s=0,ot=X,s|0):(X=0,s=0,ot=X,s|0)}if(a=v-1|0,a&v|0){w=(Er(v|0)|0)+33-(Er(L|0)|0)|0,Te=64-w|0,b=32-w|0,T=b>>31,Be=w-32|0,n=Be>>31,v=w,e=b-1>>31&L>>>(Be>>>0)|(L<>>(w>>>0))&n,n=n&L>>>(w>>>0),a=M<>>(Be>>>0))&T|M<>31;break}return s|0&&(t[s>>2]=a&M,t[s+4>>2]=0),(v|0)==1?(Be=T|n&0,Te=e|0|0,ot=Be,Te|0):(Te=x8(v|0)|0,Be=L>>>(Te>>>0)|0,Te=L<<32-Te|M>>>(Te>>>0)|0,ot=Be,Te|0)}else{if(a)return s|0&&(t[s>>2]=(L>>>0)%(v>>>0),t[s+4>>2]=0),Be=0,Te=(L>>>0)/(v>>>0)>>>0,ot=Be,Te|0;if(!M)return s|0&&(t[s>>2]=0,t[s+4>>2]=(L>>>0)%(w>>>0)),Be=0,Te=(L>>>0)/(w>>>0)>>>0,ot=Be,Te|0;if(a=w-1|0,!(a&w))return s|0&&(t[s>>2]=e|0,t[s+4>>2]=a&L|n&0),Be=0,Te=L>>>((x8(w|0)|0)>>>0),ot=Be,Te|0;if(a=(Er(w|0)|0)-(Er(L|0)|0)|0,a>>>0<=30){n=a+1|0,w=31-a|0,v=n,e=L<>>(n>>>0),n=L>>>(n>>>0),a=0,w=M<>2]=e|0,t[s+4>>2]=T|n&0,Be=0,Te=0,ot=Be,Te|0):(Be=0,Te=0,ot=Be,Te|0)}while(0);if(!v)L=w,T=0,w=0;else{b=r|0|0,M=X|u&0,L=LE(b|0,M|0,-1,-1)|0,r=ot,T=w,w=0;do u=T,T=a>>>31|T<<1,a=w|a<<1,u=e<<1|u>>>31|0,X=e>>>31|n<<1|0,m_(L|0,r|0,u|0,X|0)|0,Te=ot,Be=Te>>31|((Te|0)<0?-1:0)<<1,w=Be&1,e=m_(u|0,X|0,Be&b|0,(((Te|0)<0?-1:0)>>31|((Te|0)<0?-1:0)<<1)&M|0)|0,n=ot,v=v-1|0;while((v|0)!=0);L=T,T=0}return v=0,s|0&&(t[s>>2]=e,t[s+4>>2]=n),Be=(a|0)>>>31|(L|v)<<1|(v<<1|a>>>31)&0|T,Te=(a<<1|0>>>31)&-2|w,ot=Be,Te|0}function FE(e,n,r,u){return e=e|0,n=n|0,r=r|0,u=u|0,R8(e,n,r,u,0)|0}function e2(e){e=e|0;var n=0,r=0;return r=e+15&-16|0,n=t[q>>2]|0,e=n+r|0,(r|0)>0&(e|0)<(n|0)|(e|0)<0?(fr()|0,Ql(12),-1):(t[q>>2]=e,(e|0)>(jr()|0)&&(vr()|0)==0?(t[q>>2]=n,Ql(12),-1):n|0)}function ky(e,n,r){e=e|0,n=n|0,r=r|0;var u=0;if((n|0)<(e|0)&(e|0)<(n+r|0)){for(u=e,n=n+r|0,e=e+r|0;(r|0)>0;)e=e-1|0,n=n-1|0,r=r-1|0,h[e>>0]=h[n>>0]|0;e=u}else gr(e,n,r)|0;return e|0}function PE(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0;var s=0,a=0;return a=y,y=y+16|0,s=a|0,R8(e,n,r,u,s)|0,y=a,ot=t[s+4>>2]|0,t[s>>2]|0|0}function A8(e){return e=e|0,(e&255)<<24|(e>>8&255)<<16|(e>>16&255)<<8|e>>>24|0}function zL(e,n,r,u,s,a){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0,O8[e&1](n|0,r|0,u|0,s|0,a|0)}function HL(e,n,r){e=e|0,n=n|0,r=S(r),M8[e&1](n|0,S(r))}function qL(e,n,r){e=e|0,n=n|0,r=+r,k8[e&31](n|0,+r)}function WL(e,n,r,u){return e=e|0,n=n|0,r=S(r),u=S(u),S(N8[e&0](n|0,S(r),S(u)))}function VL(e,n){e=e|0,n=n|0,P1[e&127](n|0)}function YL(e,n,r){e=e|0,n=n|0,r=r|0,I1[e&31](n|0,r|0)}function KL(e,n){return e=e|0,n=n|0,Qp[e&31](n|0)|0}function XL(e,n,r,u,s){e=e|0,n=n|0,r=+r,u=+u,s=s|0,L8[e&1](n|0,+r,+u,s|0)}function QL(e,n,r,u){e=e|0,n=n|0,r=+r,u=+u,MF[e&1](n|0,+r,+u)}function JL(e,n,r,u){return e=e|0,n=n|0,r=r|0,u=u|0,__[e&7](n|0,r|0,u|0)|0}function ZL(e,n,r,u){return e=e|0,n=n|0,r=r|0,u=u|0,+kF[e&1](n|0,r|0,u|0)}function $L(e,n){return e=e|0,n=n|0,+F8[e&15](n|0)}function eF(e,n,r){return e=e|0,n=n|0,r=+r,NF[e&1](n|0,+r)|0}function tF(e,n,r){return e=e|0,n=n|0,r=r|0,bE[e&15](n|0,r|0)|0}function nF(e,n,r,u,s,a){e=e|0,n=n|0,r=r|0,u=+u,s=+s,a=a|0,LF[e&1](n|0,r|0,+u,+s,a|0)}function rF(e,n,r,u,s,a,v){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0,v=v|0,FF[e&1](n|0,r|0,u|0,s|0,a|0,v|0)}function iF(e,n,r){return e=e|0,n=n|0,r=r|0,+P8[e&7](n|0,r|0)}function uF(e){return e=e|0,E_[e&7]()|0}function oF(e,n,r,u,s,a){return e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0,I8[e&1](n|0,r|0,u|0,s|0,a|0)|0}function lF(e,n,r,u,s){e=e|0,n=n|0,r=r|0,u=u|0,s=+s,PF[e&1](n|0,r|0,u|0,+s)}function sF(e,n,r,u,s,a,v){e=e|0,n=n|0,r=r|0,u=S(u),s=s|0,a=S(a),v=v|0,b8[e&1](n|0,r|0,S(u),s|0,S(a),v|0)}function aF(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0,Fy[e&15](n|0,r|0,u|0)}function fF(e){e=e|0,B8[e&0]()}function cF(e,n,r,u){e=e|0,n=n|0,r=r|0,u=+u,U8[e&15](n|0,r|0,+u)}function dF(e,n,r){return e=e|0,n=+n,r=+r,IF[e&1](+n,+r)|0}function pF(e,n,r,u,s){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,BE[e&15](n|0,r|0,u|0,s|0)}function hF(e,n,r,u,s){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,zt(0)}function vF(e,n){e=e|0,n=S(n),zt(1)}function $s(e,n){e=e|0,n=+n,zt(2)}function mF(e,n,r){return e=e|0,n=S(n),r=S(r),zt(3),Ct}function Zn(e){e=e|0,zt(4)}function Ny(e,n){e=e|0,n=n|0,zt(5)}function Na(e){return e=e|0,zt(6),0}function yF(e,n,r,u){e=e|0,n=+n,r=+r,u=u|0,zt(7)}function gF(e,n,r){e=e|0,n=+n,r=+r,zt(8)}function _F(e,n,r){return e=e|0,n=n|0,r=r|0,zt(9),0}function EF(e,n,r){return e=e|0,n=n|0,r=r|0,zt(10),0}function Xp(e){return e=e|0,zt(11),0}function DF(e,n){return e=e|0,n=+n,zt(12),0}function Ly(e,n){return e=e|0,n=n|0,zt(13),0}function wF(e,n,r,u,s){e=e|0,n=n|0,r=+r,u=+u,s=s|0,zt(14)}function SF(e,n,r,u,s,a){e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,a=a|0,zt(15)}function IE(e,n){return e=e|0,n=n|0,zt(16),0}function TF(){return zt(17),0}function CF(e,n,r,u,s){return e=e|0,n=n|0,r=r|0,u=u|0,s=s|0,zt(18),0}function xF(e,n,r,u){e=e|0,n=n|0,r=r|0,u=+u,zt(19)}function RF(e,n,r,u,s,a){e=e|0,n=n|0,r=S(r),u=u|0,s=S(s),a=a|0,zt(20)}function g_(e,n,r){e=e|0,n=n|0,r=r|0,zt(21)}function AF(){zt(22)}function zv(e,n,r){e=e|0,n=n|0,r=+r,zt(23)}function OF(e,n){return e=+e,n=+n,zt(24),0}function Hv(e,n,r,u){e=e|0,n=n|0,r=r|0,u=u|0,zt(25)}var O8=[hF,TO],M8=[vF,t0],k8=[$s,ca,ws,Ss,ts,Ho,Ef,ol,qa,n0,Df,Wc,dc,Ol,Ts,da,ud,pa,pc,$s,$s,$s,$s,$s,$s,$s,$s,$s,$s,$s,$s,$s],N8=[mF],P1=[Zn,Uv,cn,is,Do,Uf,M1,jl,$A,e7,t7,cO,dO,pO,LN,FN,PN,Fe,fc,Ua,Vu,j0,yh,Sf,r1,Lf,Ea,kh,ym,g1,_1,Zh,hp,Ld,jm,C1,Ac,Jm,ey,xv,Mv,on,P4,G4,n_,Lt,Cu,e0,p9,O9,K9,dR,RR,KR,iA,lA,TA,RA,WA,r7,o7,S7,z7,gd,wM,$M,hk,Ok,Jk,dN,SN,xN,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn,Zn],I1=[Ny,_2,nd,qc,Rl,ul,E2,qs,Al,ja,za,Ha,Ml,je,st,$t,Wn,oi,ur,Wa,w2,_h,X4,eE,mR,CM,X7,$w,Ny,Ny,Ny,Ny],Qp=[Na,fL,_f,g,Z,de,yt,Rt,Nt,xr,cu,z0,Va,od,Xc,Ms,kR,x7,OM,Oa,Na,Na,Na,Na,Na,Na,Na,Na,Na,Na,Na,Na],L8=[yF,C2],MF=[gF,YA],__=[_F,p8,cL,hL,Wh,vv,y9,Lk],kF=[EF,fv],F8=[Xp,i0,Ge,ai,gh,al,ha,x2,R2,hc,Xp,Xp,Xp,Xp,Xp,Xp],NF=[DF,tA],bE=[Ly,PL,D2,dl,H2,xm,fp,xp,ty,kr,jo,gk,Ly,Ly,Ly,Ly],LF=[wF,xh],FF=[SF,tN],P8=[IE,Qi,A2,dd,Qc,ml,IE,IE],E_=[TF,Jc,io,E0,cA,kA,f7,MN],I8=[CF,ui],PF=[xF,vy],b8=[RF,ld],Fy=[g_,A,r0,Vr,Tu,m1,Nd,ar,_y,mo,YO,rk,mN,g_,g_,g_],B8=[AF],U8=[zv,rd,yo,id,zo,Vc,Wi,_,Bp,L9,JR,zv,zv,zv,zv,zv],IF=[OF,JA],BE=[Hv,Ep,Lc,Z9,jR,yA,bA,y7,G7,PM,zN,Hv,Hv,Hv,Hv,Hv];return{_llvm_bswap_i32:A8,dynCall_idd:dF,dynCall_i:uF,_i64Subtract:m_,___udivdi3:FE,dynCall_vif:HL,setThrew:vs,dynCall_viii:aF,_bitshift64Lshr:y_,_bitshift64Shl:C8,dynCall_vi:VL,dynCall_viiddi:nF,dynCall_diii:ZL,dynCall_iii:tF,_memset:jv,_sbrk:e2,_memcpy:gr,__GLOBAL__sub_I_Yoga_cpp:ru,dynCall_vii:YL,___uremdi3:PE,dynCall_vid:qL,stackAlloc:co,_nbind_init:ZN,getTempRet0:Q,dynCall_di:$L,dynCall_iid:eF,setTempRet0:b0,_i64Add:LE,dynCall_fiff:WL,dynCall_iiii:JL,_emscripten_get_global_libc:aL,dynCall_viid:cF,dynCall_viiid:lF,dynCall_viififi:sF,dynCall_ii:KL,__GLOBAL__sub_I_Binding_cc:hM,dynCall_viiii:pF,dynCall_iiiiii:oF,stackSave:nl,dynCall_viiiii:zL,__GLOBAL__sub_I_nbind_cc:Ws,dynCall_vidd:QL,_free:h_,runPostSets:jL,dynCall_viiiiii:rF,establishStackSpace:Uu,_memmove:ky,stackRestore:Jl,_malloc:p_,__GLOBAL__sub_I_common_cc:F7,dynCall_viddi:XL,dynCall_dii:iF,dynCall_v:fF}}(Module.asmGlobalArg,Module.asmLibraryArg,buffer),_llvm_bswap_i32=Module._llvm_bswap_i32=asm._llvm_bswap_i32,getTempRet0=Module.getTempRet0=asm.getTempRet0,___udivdi3=Module.___udivdi3=asm.___udivdi3,setThrew=Module.setThrew=asm.setThrew,_bitshift64Lshr=Module._bitshift64Lshr=asm._bitshift64Lshr,_bitshift64Shl=Module._bitshift64Shl=asm._bitshift64Shl,_memset=Module._memset=asm._memset,_sbrk=Module._sbrk=asm._sbrk,_memcpy=Module._memcpy=asm._memcpy,stackAlloc=Module.stackAlloc=asm.stackAlloc,___uremdi3=Module.___uremdi3=asm.___uremdi3,_nbind_init=Module._nbind_init=asm._nbind_init,_i64Subtract=Module._i64Subtract=asm._i64Subtract,setTempRet0=Module.setTempRet0=asm.setTempRet0,_i64Add=Module._i64Add=asm._i64Add,_emscripten_get_global_libc=Module._emscripten_get_global_libc=asm._emscripten_get_global_libc,__GLOBAL__sub_I_Yoga_cpp=Module.__GLOBAL__sub_I_Yoga_cpp=asm.__GLOBAL__sub_I_Yoga_cpp,__GLOBAL__sub_I_Binding_cc=Module.__GLOBAL__sub_I_Binding_cc=asm.__GLOBAL__sub_I_Binding_cc,stackSave=Module.stackSave=asm.stackSave,__GLOBAL__sub_I_nbind_cc=Module.__GLOBAL__sub_I_nbind_cc=asm.__GLOBAL__sub_I_nbind_cc,_free=Module._free=asm._free,runPostSets=Module.runPostSets=asm.runPostSets,establishStackSpace=Module.establishStackSpace=asm.establishStackSpace,_memmove=Module._memmove=asm._memmove,stackRestore=Module.stackRestore=asm.stackRestore,_malloc=Module._malloc=asm._malloc,__GLOBAL__sub_I_common_cc=Module.__GLOBAL__sub_I_common_cc=asm.__GLOBAL__sub_I_common_cc,dynCall_viiiii=Module.dynCall_viiiii=asm.dynCall_viiiii,dynCall_vif=Module.dynCall_vif=asm.dynCall_vif,dynCall_vid=Module.dynCall_vid=asm.dynCall_vid,dynCall_fiff=Module.dynCall_fiff=asm.dynCall_fiff,dynCall_vi=Module.dynCall_vi=asm.dynCall_vi,dynCall_vii=Module.dynCall_vii=asm.dynCall_vii,dynCall_ii=Module.dynCall_ii=asm.dynCall_ii,dynCall_viddi=Module.dynCall_viddi=asm.dynCall_viddi,dynCall_vidd=Module.dynCall_vidd=asm.dynCall_vidd,dynCall_iiii=Module.dynCall_iiii=asm.dynCall_iiii,dynCall_diii=Module.dynCall_diii=asm.dynCall_diii,dynCall_di=Module.dynCall_di=asm.dynCall_di,dynCall_iid=Module.dynCall_iid=asm.dynCall_iid,dynCall_iii=Module.dynCall_iii=asm.dynCall_iii,dynCall_viiddi=Module.dynCall_viiddi=asm.dynCall_viiddi,dynCall_viiiiii=Module.dynCall_viiiiii=asm.dynCall_viiiiii,dynCall_dii=Module.dynCall_dii=asm.dynCall_dii,dynCall_i=Module.dynCall_i=asm.dynCall_i,dynCall_iiiiii=Module.dynCall_iiiiii=asm.dynCall_iiiiii,dynCall_viiid=Module.dynCall_viiid=asm.dynCall_viiid,dynCall_viififi=Module.dynCall_viififi=asm.dynCall_viififi,dynCall_viii=Module.dynCall_viii=asm.dynCall_viii,dynCall_v=Module.dynCall_v=asm.dynCall_v,dynCall_viid=Module.dynCall_viid=asm.dynCall_viid,dynCall_idd=Module.dynCall_idd=asm.dynCall_idd,dynCall_viiii=Module.dynCall_viiii=asm.dynCall_viiii;Runtime.stackAlloc=Module.stackAlloc,Runtime.stackSave=Module.stackSave,Runtime.stackRestore=Module.stackRestore,Runtime.establishStackSpace=Module.establishStackSpace,Runtime.setTempRet0=Module.setTempRet0,Runtime.getTempRet0=Module.getTempRet0,Module.asm=asm;function ExitStatus(o){this.name="ExitStatus",this.message="Program terminated with exit("+o+")",this.status=o}ExitStatus.prototype=new Error,ExitStatus.prototype.constructor=ExitStatus;var initialStackTop,preloadStartTime=null,calledMain=!1;dependenciesFulfilled=function o(){Module.calledRun||run(),Module.calledRun||(dependenciesFulfilled=o)},Module.callMain=Module.callMain=function o(l){l=l||[],ensureInitRuntime();var f=l.length+1;function h(){for(var k=0;k<4-1;k++)E.push(0)}var E=[allocate(intArrayFromString(Module.thisProgram),"i8",ALLOC_NORMAL)];h();for(var t=0;t0||(preRun(),runDependencies>0)||Module.calledRun)return;function l(){Module.calledRun||(Module.calledRun=!0,!ABORT&&(ensureInitRuntime(),preMain(),Module.onRuntimeInitialized&&Module.onRuntimeInitialized(),Module._main&&shouldRunNow&&Module.callMain(o),postRun()))}Module.setStatus?(Module.setStatus("Running..."),setTimeout(function(){setTimeout(function(){Module.setStatus("")},1),l()},1)):l()}Module.run=Module.run=run;function exit(o,l){l&&Module.noExitRuntime||(Module.noExitRuntime||(ABORT=!0,EXITSTATUS=o,STACKTOP=initialStackTop,exitRuntime(),Module.onExit&&Module.onExit(o)),ENVIRONMENT_IS_NODE&&process.exit(o),Module.quit(o,new ExitStatus(o)))}Module.exit=Module.exit=exit;var abortDecorators=[];function abort(o){Module.onAbort&&Module.onAbort(o),o!==void 0?(Module.print(o),Module.printErr(o),o=JSON.stringify(o)):o="",ABORT=!0,EXITSTATUS=1;var l=` +If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.`,f="abort("+o+") at "+stackTrace()+l;throw abortDecorators&&abortDecorators.forEach(function(h){f=h(f,o)}),f}if(Module.abort=Module.abort=abort,Module.preInit)for(typeof Module.preInit=="function"&&(Module.preInit=[Module.preInit]);Module.preInit.length>0;)Module.preInit.pop()();var shouldRunNow=!0;Module.noInitialRun&&(shouldRunNow=!1),run()})});var eh=nt((CH,tT)=>{"use strict";var SP=$S(),TP=eT(),_D=!1,ED=null;TP({},function(o,l){if(!_D){if(_D=!0,o)throw o;ED=l}});if(!_D)throw new Error("Failed to load the yoga module - it needed to be loaded synchronously, but didn't");tT.exports=SP(ED.bind,ED.lib)});var rT=nt((xH,nT)=>{"use strict";nT.exports=({onlyFirst:o=!1}={})=>{let l=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(l,o?void 0:"g")}});var DD=nt((RH,iT)=>{"use strict";var CP=rT();iT.exports=o=>typeof o=="string"?o.replace(CP(),""):o});var SD=nt((AH,wD)=>{"use strict";var uT=o=>Number.isNaN(o)?!1:o>=4352&&(o<=4447||o===9001||o===9002||11904<=o&&o<=12871&&o!==12351||12880<=o&&o<=19903||19968<=o&&o<=42182||43360<=o&&o<=43388||44032<=o&&o<=55203||63744<=o&&o<=64255||65040<=o&&o<=65049||65072<=o&&o<=65131||65281<=o&&o<=65376||65504<=o&&o<=65510||110592<=o&&o<=110593||127488<=o&&o<=127569||131072<=o&&o<=262141);wD.exports=uT;wD.exports.default=uT});var lT=nt((OH,oT)=>{"use strict";oT.exports=function(){return/\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F|\uD83D\uDC68(?:\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68\uD83C\uDFFB|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C[\uDFFB-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)\uD83C\uDFFB|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB\uDFFC])|\uD83D\uDC69(?:\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D\uD83D\uDC69)(?:\uD83C[\uDFFB-\uDFFD])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|(?:(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)\uFE0F|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620)\uFE0F|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF4\uD83C\uDDF2|\uD83C\uDDF6\uD83C\uDDE6|[#\*0-9]\uFE0F\u20E3|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83D\uDC69(?:\uD83C[\uDFFB-\uDFFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC70\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD36\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5\uDEEB\uDEEC\uDEF4-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFA\uDFE0-\uDFEB]|\uD83E[\uDD0D-\uDD3A\uDD3C-\uDD45\uDD47-\uDD71\uDD73-\uDD76\uDD7A-\uDDA2\uDDA5-\uDDAA\uDDAE-\uDDCA\uDDCD-\uDDFF\uDE70-\uDE73\uDE78-\uDE7A\uDE80-\uDE82\uDE90-\uDE95])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g}});var q_=nt((MH,TD)=>{"use strict";var xP=DD(),RP=SD(),AP=lT(),sT=o=>{if(typeof o!="string"||o.length===0||(o=xP(o),o.length===0))return 0;o=o.replace(AP()," ");let l=0;for(let f=0;f=127&&h<=159||h>=768&&h<=879||(h>65535&&f++,l+=RP(h)?2:1)}return l};TD.exports=sT;TD.exports.default=sT});var xD=nt((kH,CD)=>{"use strict";var OP=q_(),aT=o=>{let l=0;for(let f of o.split(` +`))l=Math.max(l,OP(f));return l};CD.exports=aT;CD.exports.default=aT});var fT=nt(Ky=>{"use strict";var MP=Ky&&Ky.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(Ky,"__esModule",{value:!0});var kP=MP(xD()),RD={};Ky.default=o=>{if(o.length===0)return{width:0,height:0};if(RD[o])return RD[o];let l=kP.default(o),f=o.split(` +`).length;return RD[o]={width:l,height:f},{width:l,height:f}}});var cT=nt(Xy=>{"use strict";var NP=Xy&&Xy.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(Xy,"__esModule",{value:!0});var Gi=NP(eh()),LP=(o,l)=>{"position"in l&&o.setPositionType(l.position==="absolute"?Gi.default.POSITION_TYPE_ABSOLUTE:Gi.default.POSITION_TYPE_RELATIVE)},FP=(o,l)=>{"marginLeft"in l&&o.setMargin(Gi.default.EDGE_START,l.marginLeft||0),"marginRight"in l&&o.setMargin(Gi.default.EDGE_END,l.marginRight||0),"marginTop"in l&&o.setMargin(Gi.default.EDGE_TOP,l.marginTop||0),"marginBottom"in l&&o.setMargin(Gi.default.EDGE_BOTTOM,l.marginBottom||0)},PP=(o,l)=>{"paddingLeft"in l&&o.setPadding(Gi.default.EDGE_LEFT,l.paddingLeft||0),"paddingRight"in l&&o.setPadding(Gi.default.EDGE_RIGHT,l.paddingRight||0),"paddingTop"in l&&o.setPadding(Gi.default.EDGE_TOP,l.paddingTop||0),"paddingBottom"in l&&o.setPadding(Gi.default.EDGE_BOTTOM,l.paddingBottom||0)},IP=(o,l)=>{var f;"flexGrow"in l&&o.setFlexGrow((f=l.flexGrow)!==null&&f!==void 0?f:0),"flexShrink"in l&&o.setFlexShrink(typeof l.flexShrink=="number"?l.flexShrink:1),"flexDirection"in l&&(l.flexDirection==="row"&&o.setFlexDirection(Gi.default.FLEX_DIRECTION_ROW),l.flexDirection==="row-reverse"&&o.setFlexDirection(Gi.default.FLEX_DIRECTION_ROW_REVERSE),l.flexDirection==="column"&&o.setFlexDirection(Gi.default.FLEX_DIRECTION_COLUMN),l.flexDirection==="column-reverse"&&o.setFlexDirection(Gi.default.FLEX_DIRECTION_COLUMN_REVERSE)),"flexBasis"in l&&(typeof l.flexBasis=="number"?o.setFlexBasis(l.flexBasis):typeof l.flexBasis=="string"?o.setFlexBasisPercent(Number.parseInt(l.flexBasis,10)):o.setFlexBasis(NaN)),"alignItems"in l&&((l.alignItems==="stretch"||!l.alignItems)&&o.setAlignItems(Gi.default.ALIGN_STRETCH),l.alignItems==="flex-start"&&o.setAlignItems(Gi.default.ALIGN_FLEX_START),l.alignItems==="center"&&o.setAlignItems(Gi.default.ALIGN_CENTER),l.alignItems==="flex-end"&&o.setAlignItems(Gi.default.ALIGN_FLEX_END)),"alignSelf"in l&&((l.alignSelf==="auto"||!l.alignSelf)&&o.setAlignSelf(Gi.default.ALIGN_AUTO),l.alignSelf==="flex-start"&&o.setAlignSelf(Gi.default.ALIGN_FLEX_START),l.alignSelf==="center"&&o.setAlignSelf(Gi.default.ALIGN_CENTER),l.alignSelf==="flex-end"&&o.setAlignSelf(Gi.default.ALIGN_FLEX_END)),"justifyContent"in l&&((l.justifyContent==="flex-start"||!l.justifyContent)&&o.setJustifyContent(Gi.default.JUSTIFY_FLEX_START),l.justifyContent==="center"&&o.setJustifyContent(Gi.default.JUSTIFY_CENTER),l.justifyContent==="flex-end"&&o.setJustifyContent(Gi.default.JUSTIFY_FLEX_END),l.justifyContent==="space-between"&&o.setJustifyContent(Gi.default.JUSTIFY_SPACE_BETWEEN),l.justifyContent==="space-around"&&o.setJustifyContent(Gi.default.JUSTIFY_SPACE_AROUND))},bP=(o,l)=>{var f,h;"width"in l&&(typeof l.width=="number"?o.setWidth(l.width):typeof l.width=="string"?o.setWidthPercent(Number.parseInt(l.width,10)):o.setWidthAuto()),"height"in l&&(typeof l.height=="number"?o.setHeight(l.height):typeof l.height=="string"?o.setHeightPercent(Number.parseInt(l.height,10)):o.setHeightAuto()),"minWidth"in l&&(typeof l.minWidth=="string"?o.setMinWidthPercent(Number.parseInt(l.minWidth,10)):o.setMinWidth((f=l.minWidth)!==null&&f!==void 0?f:0)),"minHeight"in l&&(typeof l.minHeight=="string"?o.setMinHeightPercent(Number.parseInt(l.minHeight,10)):o.setMinHeight((h=l.minHeight)!==null&&h!==void 0?h:0))},BP=(o,l)=>{"display"in l&&o.setDisplay(l.display==="flex"?Gi.default.DISPLAY_FLEX:Gi.default.DISPLAY_NONE)},UP=(o,l)=>{if("borderStyle"in l){let f=typeof l.borderStyle=="string"?1:0;o.setBorder(Gi.default.EDGE_TOP,f),o.setBorder(Gi.default.EDGE_BOTTOM,f),o.setBorder(Gi.default.EDGE_LEFT,f),o.setBorder(Gi.default.EDGE_RIGHT,f)}};Xy.default=(o,l={})=>{LP(o,l),FP(o,l),PP(o,l),IP(o,l),bP(o,l),BP(o,l),UP(o,l)}});var pT=nt((FH,dT)=>{"use strict";dT.exports={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}});var AD=nt((PH,vT)=>{var Qy=pT(),hT={};for(let o of Object.keys(Qy))hT[Qy[o]]=o;var zn={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};vT.exports=zn;for(let o of Object.keys(zn)){if(!("channels"in zn[o]))throw new Error("missing channels property: "+o);if(!("labels"in zn[o]))throw new Error("missing channel labels property: "+o);if(zn[o].labels.length!==zn[o].channels)throw new Error("channel and label counts mismatch: "+o);let{channels:l,labels:f}=zn[o];delete zn[o].channels,delete zn[o].labels,Object.defineProperty(zn[o],"channels",{value:l}),Object.defineProperty(zn[o],"labels",{value:f})}zn.rgb.hsl=function(o){let l=o[0]/255,f=o[1]/255,h=o[2]/255,E=Math.min(l,f,h),t=Math.max(l,f,h),N=t-E,F,k;t===E?F=0:l===t?F=(f-h)/N:f===t?F=2+(h-l)/N:h===t&&(F=4+(l-f)/N),F=Math.min(F*60,360),F<0&&(F+=360);let x=(E+t)/2;return t===E?k=0:x<=.5?k=N/(t+E):k=N/(2-t-E),[F,k*100,x*100]};zn.rgb.hsv=function(o){let l,f,h,E,t,N=o[0]/255,F=o[1]/255,k=o[2]/255,x=Math.max(N,F,k),j=x-Math.min(N,F,k),q=function(V){return(x-V)/6/j+1/2};return j===0?(E=0,t=0):(t=j/x,l=q(N),f=q(F),h=q(k),N===x?E=h-f:F===x?E=1/3+l-h:k===x&&(E=2/3+f-l),E<0?E+=1:E>1&&(E-=1)),[E*360,t*100,x*100]};zn.rgb.hwb=function(o){let l=o[0],f=o[1],h=o[2],E=zn.rgb.hsl(o)[0],t=1/255*Math.min(l,Math.min(f,h));return h=1-1/255*Math.max(l,Math.max(f,h)),[E,t*100,h*100]};zn.rgb.cmyk=function(o){let l=o[0]/255,f=o[1]/255,h=o[2]/255,E=Math.min(1-l,1-f,1-h),t=(1-l-E)/(1-E)||0,N=(1-f-E)/(1-E)||0,F=(1-h-E)/(1-E)||0;return[t*100,N*100,F*100,E*100]};function jP(o,l){return(o[0]-l[0])**2+(o[1]-l[1])**2+(o[2]-l[2])**2}zn.rgb.keyword=function(o){let l=hT[o];if(l)return l;let f=1/0,h;for(let E of Object.keys(Qy)){let t=Qy[E],N=jP(o,t);N.04045?((l+.055)/1.055)**2.4:l/12.92,f=f>.04045?((f+.055)/1.055)**2.4:f/12.92,h=h>.04045?((h+.055)/1.055)**2.4:h/12.92;let E=l*.4124+f*.3576+h*.1805,t=l*.2126+f*.7152+h*.0722,N=l*.0193+f*.1192+h*.9505;return[E*100,t*100,N*100]};zn.rgb.lab=function(o){let l=zn.rgb.xyz(o),f=l[0],h=l[1],E=l[2];f/=95.047,h/=100,E/=108.883,f=f>.008856?f**(1/3):7.787*f+16/116,h=h>.008856?h**(1/3):7.787*h+16/116,E=E>.008856?E**(1/3):7.787*E+16/116;let t=116*h-16,N=500*(f-h),F=200*(h-E);return[t,N,F]};zn.hsl.rgb=function(o){let l=o[0]/360,f=o[1]/100,h=o[2]/100,E,t,N;if(f===0)return N=h*255,[N,N,N];h<.5?E=h*(1+f):E=h+f-h*f;let F=2*h-E,k=[0,0,0];for(let x=0;x<3;x++)t=l+1/3*-(x-1),t<0&&t++,t>1&&t--,6*t<1?N=F+(E-F)*6*t:2*t<1?N=E:3*t<2?N=F+(E-F)*(2/3-t)*6:N=F,k[x]=N*255;return k};zn.hsl.hsv=function(o){let l=o[0],f=o[1]/100,h=o[2]/100,E=f,t=Math.max(h,.01);h*=2,f*=h<=1?h:2-h,E*=t<=1?t:2-t;let N=(h+f)/2,F=h===0?2*E/(t+E):2*f/(h+f);return[l,F*100,N*100]};zn.hsv.rgb=function(o){let l=o[0]/60,f=o[1]/100,h=o[2]/100,E=Math.floor(l)%6,t=l-Math.floor(l),N=255*h*(1-f),F=255*h*(1-f*t),k=255*h*(1-f*(1-t));switch(h*=255,E){case 0:return[h,k,N];case 1:return[F,h,N];case 2:return[N,h,k];case 3:return[N,F,h];case 4:return[k,N,h];case 5:return[h,N,F]}};zn.hsv.hsl=function(o){let l=o[0],f=o[1]/100,h=o[2]/100,E=Math.max(h,.01),t,N;N=(2-f)*h;let F=(2-f)*E;return t=f*E,t/=F<=1?F:2-F,t=t||0,N/=2,[l,t*100,N*100]};zn.hwb.rgb=function(o){let l=o[0]/360,f=o[1]/100,h=o[2]/100,E=f+h,t;E>1&&(f/=E,h/=E);let N=Math.floor(6*l),F=1-h;t=6*l-N,(N&1)!==0&&(t=1-t);let k=f+t*(F-f),x,j,q;switch(N){default:case 6:case 0:x=F,j=k,q=f;break;case 1:x=k,j=F,q=f;break;case 2:x=f,j=F,q=k;break;case 3:x=f,j=k,q=F;break;case 4:x=k,j=f,q=F;break;case 5:x=F,j=f,q=k;break}return[x*255,j*255,q*255]};zn.cmyk.rgb=function(o){let l=o[0]/100,f=o[1]/100,h=o[2]/100,E=o[3]/100,t=1-Math.min(1,l*(1-E)+E),N=1-Math.min(1,f*(1-E)+E),F=1-Math.min(1,h*(1-E)+E);return[t*255,N*255,F*255]};zn.xyz.rgb=function(o){let l=o[0]/100,f=o[1]/100,h=o[2]/100,E,t,N;return E=l*3.2406+f*-1.5372+h*-.4986,t=l*-.9689+f*1.8758+h*.0415,N=l*.0557+f*-.204+h*1.057,E=E>.0031308?1.055*E**(1/2.4)-.055:E*12.92,t=t>.0031308?1.055*t**(1/2.4)-.055:t*12.92,N=N>.0031308?1.055*N**(1/2.4)-.055:N*12.92,E=Math.min(Math.max(0,E),1),t=Math.min(Math.max(0,t),1),N=Math.min(Math.max(0,N),1),[E*255,t*255,N*255]};zn.xyz.lab=function(o){let l=o[0],f=o[1],h=o[2];l/=95.047,f/=100,h/=108.883,l=l>.008856?l**(1/3):7.787*l+16/116,f=f>.008856?f**(1/3):7.787*f+16/116,h=h>.008856?h**(1/3):7.787*h+16/116;let E=116*f-16,t=500*(l-f),N=200*(f-h);return[E,t,N]};zn.lab.xyz=function(o){let l=o[0],f=o[1],h=o[2],E,t,N;t=(l+16)/116,E=f/500+t,N=t-h/200;let F=t**3,k=E**3,x=N**3;return t=F>.008856?F:(t-16/116)/7.787,E=k>.008856?k:(E-16/116)/7.787,N=x>.008856?x:(N-16/116)/7.787,E*=95.047,t*=100,N*=108.883,[E,t,N]};zn.lab.lch=function(o){let l=o[0],f=o[1],h=o[2],E;E=Math.atan2(h,f)*360/2/Math.PI,E<0&&(E+=360);let N=Math.sqrt(f*f+h*h);return[l,N,E]};zn.lch.lab=function(o){let l=o[0],f=o[1],E=o[2]/360*2*Math.PI,t=f*Math.cos(E),N=f*Math.sin(E);return[l,t,N]};zn.rgb.ansi16=function(o,l=null){let[f,h,E]=o,t=l===null?zn.rgb.hsv(o)[2]:l;if(t=Math.round(t/50),t===0)return 30;let N=30+(Math.round(E/255)<<2|Math.round(h/255)<<1|Math.round(f/255));return t===2&&(N+=60),N};zn.hsv.ansi16=function(o){return zn.rgb.ansi16(zn.hsv.rgb(o),o[2])};zn.rgb.ansi256=function(o){let l=o[0],f=o[1],h=o[2];return l===f&&f===h?l<8?16:l>248?231:Math.round((l-8)/247*24)+232:16+36*Math.round(l/255*5)+6*Math.round(f/255*5)+Math.round(h/255*5)};zn.ansi16.rgb=function(o){let l=o%10;if(l===0||l===7)return o>50&&(l+=3.5),l=l/10.5*255,[l,l,l];let f=(~~(o>50)+1)*.5,h=(l&1)*f*255,E=(l>>1&1)*f*255,t=(l>>2&1)*f*255;return[h,E,t]};zn.ansi256.rgb=function(o){if(o>=232){let t=(o-232)*10+8;return[t,t,t]}o-=16;let l,f=Math.floor(o/36)/5*255,h=Math.floor((l=o%36)/6)/5*255,E=l%6/5*255;return[f,h,E]};zn.rgb.hex=function(o){let f=(((Math.round(o[0])&255)<<16)+((Math.round(o[1])&255)<<8)+(Math.round(o[2])&255)).toString(16).toUpperCase();return"000000".substring(f.length)+f};zn.hex.rgb=function(o){let l=o.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!l)return[0,0,0];let f=l[0];l[0].length===3&&(f=f.split("").map(F=>F+F).join(""));let h=parseInt(f,16),E=h>>16&255,t=h>>8&255,N=h&255;return[E,t,N]};zn.rgb.hcg=function(o){let l=o[0]/255,f=o[1]/255,h=o[2]/255,E=Math.max(Math.max(l,f),h),t=Math.min(Math.min(l,f),h),N=E-t,F,k;return N<1?F=t/(1-N):F=0,N<=0?k=0:E===l?k=(f-h)/N%6:E===f?k=2+(h-l)/N:k=4+(l-f)/N,k/=6,k%=1,[k*360,N*100,F*100]};zn.hsl.hcg=function(o){let l=o[1]/100,f=o[2]/100,h=f<.5?2*l*f:2*l*(1-f),E=0;return h<1&&(E=(f-.5*h)/(1-h)),[o[0],h*100,E*100]};zn.hsv.hcg=function(o){let l=o[1]/100,f=o[2]/100,h=l*f,E=0;return h<1&&(E=(f-h)/(1-h)),[o[0],h*100,E*100]};zn.hcg.rgb=function(o){let l=o[0]/360,f=o[1]/100,h=o[2]/100;if(f===0)return[h*255,h*255,h*255];let E=[0,0,0],t=l%1*6,N=t%1,F=1-N,k=0;switch(Math.floor(t)){case 0:E[0]=1,E[1]=N,E[2]=0;break;case 1:E[0]=F,E[1]=1,E[2]=0;break;case 2:E[0]=0,E[1]=1,E[2]=N;break;case 3:E[0]=0,E[1]=F,E[2]=1;break;case 4:E[0]=N,E[1]=0,E[2]=1;break;default:E[0]=1,E[1]=0,E[2]=F}return k=(1-f)*h,[(f*E[0]+k)*255,(f*E[1]+k)*255,(f*E[2]+k)*255]};zn.hcg.hsv=function(o){let l=o[1]/100,f=o[2]/100,h=l+f*(1-l),E=0;return h>0&&(E=l/h),[o[0],E*100,h*100]};zn.hcg.hsl=function(o){let l=o[1]/100,h=o[2]/100*(1-l)+.5*l,E=0;return h>0&&h<.5?E=l/(2*h):h>=.5&&h<1&&(E=l/(2*(1-h))),[o[0],E*100,h*100]};zn.hcg.hwb=function(o){let l=o[1]/100,f=o[2]/100,h=l+f*(1-l);return[o[0],(h-l)*100,(1-h)*100]};zn.hwb.hcg=function(o){let l=o[1]/100,h=1-o[2]/100,E=h-l,t=0;return E<1&&(t=(h-E)/(1-E)),[o[0],E*100,t*100]};zn.apple.rgb=function(o){return[o[0]/65535*255,o[1]/65535*255,o[2]/65535*255]};zn.rgb.apple=function(o){return[o[0]/255*65535,o[1]/255*65535,o[2]/255*65535]};zn.gray.rgb=function(o){return[o[0]/100*255,o[0]/100*255,o[0]/100*255]};zn.gray.hsl=function(o){return[0,0,o[0]]};zn.gray.hsv=zn.gray.hsl;zn.gray.hwb=function(o){return[0,100,o[0]]};zn.gray.cmyk=function(o){return[0,0,0,o[0]]};zn.gray.lab=function(o){return[o[0],0,0]};zn.gray.hex=function(o){let l=Math.round(o[0]/100*255)&255,h=((l<<16)+(l<<8)+l).toString(16).toUpperCase();return"000000".substring(h.length)+h};zn.rgb.gray=function(o){return[(o[0]+o[1]+o[2])/3/255*100]}});var yT=nt((IH,mT)=>{var W_=AD();function zP(){let o={},l=Object.keys(W_);for(let f=l.length,h=0;h{var OD=AD(),VP=yT(),Zv={},GP=Object.keys(OD);function YP(o){let l=function(...f){let h=f[0];return h==null?h:(h.length>1&&(f=h),o(f))};return"conversion"in o&&(l.conversion=o.conversion),l}function KP(o){let l=function(...f){let h=f[0];if(h==null)return h;h.length>1&&(f=h);let E=o(f);if(typeof E=="object")for(let t=E.length,N=0;N{Zv[o]={},Object.defineProperty(Zv[o],"channels",{value:OD[o].channels}),Object.defineProperty(Zv[o],"labels",{value:OD[o].labels});let l=VP(o);Object.keys(l).forEach(h=>{let E=l[h];Zv[o][h]=KP(E),Zv[o][h].raw=YP(E)})});gT.exports=Zv});var G_=nt((BH,TT)=>{"use strict";var ET=(o,l)=>(...f)=>`\x1B[${o(...f)+l}m`,DT=(o,l)=>(...f)=>{let h=o(...f);return`\x1B[${38+l};5;${h}m`},wT=(o,l)=>(...f)=>{let h=o(...f);return`\x1B[${38+l};2;${h[0]};${h[1]};${h[2]}m`},V_=o=>o,ST=(o,l,f)=>[o,l,f],$v=(o,l,f)=>{Object.defineProperty(o,l,{get:()=>{let h=f();return Object.defineProperty(o,l,{value:h,enumerable:!0,configurable:!0}),h},enumerable:!0,configurable:!0})},MD,em=(o,l,f,h)=>{MD===void 0&&(MD=_T());let E=h?10:0,t={};for(let[N,F]of Object.entries(MD)){let k=N==="ansi16"?"ansi":N;N===l?t[k]=o(f,E):typeof F=="object"&&(t[k]=o(F[l],E))}return t};function XP(){let o=new Map,l={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};l.color.gray=l.color.blackBright,l.bgColor.bgGray=l.bgColor.bgBlackBright,l.color.grey=l.color.blackBright,l.bgColor.bgGrey=l.bgColor.bgBlackBright;for(let[f,h]of Object.entries(l)){for(let[E,t]of Object.entries(h))l[E]={open:`\x1B[${t[0]}m`,close:`\x1B[${t[1]}m`},h[E]=l[E],o.set(t[0],t[1]);Object.defineProperty(l,f,{value:h,enumerable:!1})}return Object.defineProperty(l,"codes",{value:o,enumerable:!1}),l.color.close="\x1B[39m",l.bgColor.close="\x1B[49m",$v(l.color,"ansi",()=>em(ET,"ansi16",V_,!1)),$v(l.color,"ansi256",()=>em(DT,"ansi256",V_,!1)),$v(l.color,"ansi16m",()=>em(wT,"rgb",ST,!1)),$v(l.bgColor,"ansi",()=>em(ET,"ansi16",V_,!0)),$v(l.bgColor,"ansi256",()=>em(DT,"ansi256",V_,!0)),$v(l.bgColor,"ansi16m",()=>em(wT,"rgb",ST,!0)),l}Object.defineProperty(TT,"exports",{enumerable:!0,get:XP})});var RT=nt((UH,xT)=>{"use strict";var Jy=q_(),QP=DD(),JP=G_(),ND=new Set(["\x1B","\x9B"]),ZP=39,CT=o=>`${ND.values().next().value}[${o}m`,$P=o=>o.split(" ").map(l=>Jy(l)),kD=(o,l,f)=>{let h=[...l],E=!1,t=Jy(QP(o[o.length-1]));for(let[N,F]of h.entries()){let k=Jy(F);if(t+k<=f?o[o.length-1]+=F:(o.push(F),t=0),ND.has(F))E=!0;else if(E&&F==="m"){E=!1;continue}E||(t+=k,t===f&&N0&&o.length>1&&(o[o.length-2]+=o.pop())},eI=o=>{let l=o.split(" "),f=l.length;for(;f>0&&!(Jy(l[f-1])>0);)f--;return f===l.length?o:l.slice(0,f).join(" ")+l.slice(f).join("")},tI=(o,l,f={})=>{if(f.trim!==!1&&o.trim()==="")return"";let h="",E="",t,N=$P(o),F=[""];for(let[k,x]of o.split(" ").entries()){f.trim!==!1&&(F[F.length-1]=F[F.length-1].trimLeft());let j=Jy(F[F.length-1]);if(k!==0&&(j>=l&&(f.wordWrap===!1||f.trim===!1)&&(F.push(""),j=0),(j>0||f.trim===!1)&&(F[F.length-1]+=" ",j++)),f.hard&&N[k]>l){let q=l-j,V=1+Math.floor((N[k]-q-1)/l);Math.floor((N[k]-1)/l)l&&j>0&&N[k]>0){if(f.wordWrap===!1&&jl&&f.wordWrap===!1){kD(F,x,l);continue}F[F.length-1]+=x}f.trim!==!1&&(F=F.map(eI)),h=F.join(` +`);for(let[k,x]of[...h].entries()){if(E+=x,ND.has(x)){let q=parseFloat(/\d[^m]*/.exec(h.slice(k,k+4)));t=q===ZP?null:q}let j=JP.codes.get(Number(t));t&&j&&(h[k+1]===` +`?E+=CT(j):x===` +`&&(E+=CT(t)))}return E};xT.exports=(o,l,f)=>String(o).normalize().replace(/\r\n/g,` +`).split(` +`).map(h=>tI(h,l,f)).join(` +`)});var MT=nt((jH,OT)=>{"use strict";var AT="[\uD800-\uDBFF][\uDC00-\uDFFF]",nI=o=>o&&o.exact?new RegExp(`^${AT}$`):new RegExp(AT,"g");OT.exports=nI});var LD=nt((zH,FT)=>{"use strict";var rI=SD(),iI=MT(),kT=G_(),LT=["\x1B","\x9B"],Y_=o=>`${LT[0]}[${o}m`,NT=(o,l,f)=>{let h=[];o=[...o];for(let E of o){let t=E;E.match(";")&&(E=E.split(";")[0][0]+"0");let N=kT.codes.get(parseInt(E,10));if(N){let F=o.indexOf(N.toString());F>=0?o.splice(F,1):h.push(Y_(l?N:t))}else if(l){h.push(Y_(0));break}else h.push(Y_(t))}if(l&&(h=h.filter((E,t)=>h.indexOf(E)===t),f!==void 0)){let E=Y_(kT.codes.get(parseInt(f,10)));h=h.reduce((t,N)=>N===E?[N,...t]:[...t,N],[])}return h.join("")};FT.exports=(o,l,f)=>{let h=[...o.normalize()],E=[];f=typeof f=="number"?f:h.length;let t=!1,N,F=0,k="";for(let[x,j]of h.entries()){let q=!1;if(LT.includes(j)){let V=/\d[^m]*/.exec(o.slice(x,x+18));N=V&&V.length>0?V[0]:void 0,Fl&&F<=f)k+=j;else if(F===l&&!t&&N!==void 0)k=NT(E);else if(F>=f){k+=NT(E,!0,N);break}}return k}});var IT=nt((HH,PT)=>{"use strict";var c2=LD(),uI=q_();function K_(o,l,f){if(o.charAt(l)===" ")return l;for(let h=1;h<=3;h++)if(f){if(o.charAt(l+h)===" ")return l+h}else if(o.charAt(l-h)===" ")return l-h;return l}PT.exports=(o,l,f)=>{f={position:"end",preferTruncationOnSpace:!1,...f};let{position:h,space:E,preferTruncationOnSpace:t}=f,N="\u2026",F=1;if(typeof o!="string")throw new TypeError(`Expected \`input\` to be a string, got ${typeof o}`);if(typeof l!="number")throw new TypeError(`Expected \`columns\` to be a number, got ${typeof l}`);if(l<1)return"";if(l===1)return N;let k=uI(o);if(k<=l)return o;if(h==="start"){if(t){let x=K_(o,k-l+1,!0);return N+c2(o,x,k).trim()}return E===!0&&(N+=" ",F=2),N+c2(o,k-l+F,k)}if(h==="middle"){E===!0&&(N=" "+N+" ",F=3);let x=Math.floor(l/2);if(t){let j=K_(o,x),q=K_(o,k-(l-x)+1,!0);return c2(o,0,j)+N+c2(o,q,k).trim()}return c2(o,0,x)+N+c2(o,k-(l-x)+F,k)}if(h==="end"){if(t){let x=K_(o,l-1);return c2(o,0,x)+N}return E===!0&&(N=" "+N,F=2),c2(o,0,l-F)+N}throw new Error(`Expected \`options.position\` to be either \`start\`, \`middle\` or \`end\`, got ${h}`)}});var PD=nt(Zy=>{"use strict";var bT=Zy&&Zy.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(Zy,"__esModule",{value:!0});var oI=bT(RT()),lI=bT(IT()),FD={};Zy.default=(o,l,f)=>{let h=o+String(l)+String(f);if(FD[h])return FD[h];let E=o;if(f==="wrap"&&(E=oI.default(o,l,{trim:!1,hard:!0})),f.startsWith("truncate")){let t="end";f==="truncate-middle"&&(t="middle"),f==="truncate-start"&&(t="start"),E=lI.default(o,l,{position:t})}return FD[h]=E,E}});var bD=nt(ID=>{"use strict";Object.defineProperty(ID,"__esModule",{value:!0});var BT=o=>{let l="";if(o.childNodes.length>0)for(let f of o.childNodes){let h="";f.nodeName==="#text"?h=f.nodeValue:((f.nodeName==="ink-text"||f.nodeName==="ink-virtual-text")&&(h=BT(f)),h.length>0&&typeof f.internal_transform=="function"&&(h=f.internal_transform(h))),l+=h}return l};ID.default=BT});var BD=nt(f0=>{"use strict";var $y=f0&&f0.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(f0,"__esModule",{value:!0});f0.setTextNodeValue=f0.createTextNode=f0.setStyle=f0.setAttribute=f0.removeChildNode=f0.insertBeforeNode=f0.appendChildNode=f0.createNode=f0.TEXT_NAME=void 0;var sI=$y(eh()),UT=$y(fT()),aI=$y(cT()),fI=$y(PD()),cI=$y(bD());f0.TEXT_NAME="#text";f0.createNode=o=>{var l;let f={nodeName:o,style:{},attributes:{},childNodes:[],parentNode:null,yogaNode:o==="ink-virtual-text"?void 0:sI.default.Node.create()};return o==="ink-text"&&((l=f.yogaNode)===null||l===void 0||l.setMeasureFunc(dI.bind(null,f))),f};f0.appendChildNode=(o,l)=>{var f;l.parentNode&&f0.removeChildNode(l.parentNode,l),l.parentNode=o,o.childNodes.push(l),l.yogaNode&&((f=o.yogaNode)===null||f===void 0||f.insertChild(l.yogaNode,o.yogaNode.getChildCount())),(o.nodeName==="ink-text"||o.nodeName==="ink-virtual-text")&&X_(o)};f0.insertBeforeNode=(o,l,f)=>{var h,E;l.parentNode&&f0.removeChildNode(l.parentNode,l),l.parentNode=o;let t=o.childNodes.indexOf(f);if(t>=0){o.childNodes.splice(t,0,l),l.yogaNode&&((h=o.yogaNode)===null||h===void 0||h.insertChild(l.yogaNode,t));return}o.childNodes.push(l),l.yogaNode&&((E=o.yogaNode)===null||E===void 0||E.insertChild(l.yogaNode,o.yogaNode.getChildCount())),(o.nodeName==="ink-text"||o.nodeName==="ink-virtual-text")&&X_(o)};f0.removeChildNode=(o,l)=>{var f,h;l.yogaNode&&((h=(f=l.parentNode)===null||f===void 0?void 0:f.yogaNode)===null||h===void 0||h.removeChild(l.yogaNode)),l.parentNode=null;let E=o.childNodes.indexOf(l);E>=0&&o.childNodes.splice(E,1),(o.nodeName==="ink-text"||o.nodeName==="ink-virtual-text")&&X_(o)};f0.setAttribute=(o,l,f)=>{o.attributes[l]=f};f0.setStyle=(o,l)=>{o.style=l,o.yogaNode&&aI.default(o.yogaNode,l)};f0.createTextNode=o=>{let l={nodeName:"#text",nodeValue:o,yogaNode:void 0,parentNode:null,style:{}};return f0.setTextNodeValue(l,o),l};var dI=function(o,l){var f,h;let E=o.nodeName==="#text"?o.nodeValue:cI.default(o),t=UT.default(E);if(t.width<=l||t.width>=1&&l>0&&l<1)return t;let N=(h=(f=o.style)===null||f===void 0?void 0:f.textWrap)!==null&&h!==void 0?h:"wrap",F=fI.default(E,l,N);return UT.default(F)},jT=o=>{var l;if(!(!o||!o.parentNode))return(l=o.yogaNode)!==null&&l!==void 0?l:jT(o.parentNode)},X_=o=>{let l=jT(o);l==null||l.markDirty()};f0.setTextNodeValue=(o,l)=>{typeof l!="string"&&(l=String(l)),o.nodeValue=l,X_(o)}});var th=nt((GH,zT)=>{"use strict";zT.exports={BINARY_TYPES:["nodebuffer","arraybuffer","fragments"],GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),EMPTY_BUFFER:Buffer.alloc(0),NOOP:()=>{}}});var eg=nt((YH,UD)=>{"use strict";var{EMPTY_BUFFER:pI}=th();function HT(o,l){if(o.length===0)return pI;if(o.length===1)return o[0];let f=Buffer.allocUnsafe(l),h=0;for(let E=0;E{"use strict";var GT=Symbol("kDone"),jD=Symbol("kRun"),zD=class{constructor(l){this[GT]=()=>{this.pending--,this[jD]()},this.concurrency=l||1/0,this.jobs=[],this.pending=0}add(l){this.jobs.push(l),this[jD]()}[jD](){if(this.pending!==this.concurrency&&this.jobs.length){let l=this.jobs.shift();this.pending++,l(this[GT])}}};YT.exports=zD});var rg=nt((XH,ZT)=>{"use strict";var tg=hi("zlib"),XT=eg(),hI=KT(),{kStatusCode:QT,NOOP:vI}=th(),mI=Buffer.from([0,0,255,255]),Z_=Symbol("permessage-deflate"),X1=Symbol("total-length"),ng=Symbol("callback"),d2=Symbol("buffers"),HD=Symbol("error"),J_,qD=class{constructor(l,f,h){if(this._maxPayload=h|0,this._options=l||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._isServer=!!f,this._deflate=null,this._inflate=null,this.params=null,!J_){let E=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;J_=new hI(E)}}static get extensionName(){return"permessage-deflate"}offer(){let l={};return this._options.serverNoContextTakeover&&(l.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(l.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(l.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?l.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(l.client_max_window_bits=!0),l}accept(l){return l=this.normalizeParams(l),this.params=this._isServer?this.acceptAsServer(l):this.acceptAsClient(l),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let l=this._deflate[ng];this._deflate.close(),this._deflate=null,l&&l(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(l){let f=this._options,h=l.find(E=>!(f.serverNoContextTakeover===!1&&E.server_no_context_takeover||E.server_max_window_bits&&(f.serverMaxWindowBits===!1||typeof f.serverMaxWindowBits=="number"&&f.serverMaxWindowBits>E.server_max_window_bits)||typeof f.clientMaxWindowBits=="number"&&!E.client_max_window_bits));if(!h)throw new Error("None of the extension offers can be accepted");return f.serverNoContextTakeover&&(h.server_no_context_takeover=!0),f.clientNoContextTakeover&&(h.client_no_context_takeover=!0),typeof f.serverMaxWindowBits=="number"&&(h.server_max_window_bits=f.serverMaxWindowBits),typeof f.clientMaxWindowBits=="number"?h.client_max_window_bits=f.clientMaxWindowBits:(h.client_max_window_bits===!0||f.clientMaxWindowBits===!1)&&delete h.client_max_window_bits,h}acceptAsClient(l){let f=l[0];if(this._options.clientNoContextTakeover===!1&&f.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!f.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(f.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&f.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return f}normalizeParams(l){return l.forEach(f=>{Object.keys(f).forEach(h=>{let E=f[h];if(E.length>1)throw new Error(`Parameter "${h}" must have only a single value`);if(E=E[0],h==="client_max_window_bits"){if(E!==!0){let t=+E;if(!Number.isInteger(t)||t<8||t>15)throw new TypeError(`Invalid value for parameter "${h}": ${E}`);E=t}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${h}": ${E}`)}else if(h==="server_max_window_bits"){let t=+E;if(!Number.isInteger(t)||t<8||t>15)throw new TypeError(`Invalid value for parameter "${h}": ${E}`);E=t}else if(h==="client_no_context_takeover"||h==="server_no_context_takeover"){if(E!==!0)throw new TypeError(`Invalid value for parameter "${h}": ${E}`)}else throw new Error(`Unknown parameter "${h}"`);f[h]=E})}),l}decompress(l,f,h){J_.add(E=>{this._decompress(l,f,(t,N)=>{E(),h(t,N)})})}compress(l,f,h){J_.add(E=>{this._compress(l,f,(t,N)=>{E(),h(t,N)})})}_decompress(l,f,h){let E=this._isServer?"client":"server";if(!this._inflate){let t=`${E}_max_window_bits`,N=typeof this.params[t]!="number"?tg.Z_DEFAULT_WINDOWBITS:this.params[t];this._inflate=tg.createInflateRaw({...this._options.zlibInflateOptions,windowBits:N}),this._inflate[Z_]=this,this._inflate[X1]=0,this._inflate[d2]=[],this._inflate.on("error",gI),this._inflate.on("data",JT)}this._inflate[ng]=h,this._inflate.write(l),f&&this._inflate.write(mI),this._inflate.flush(()=>{let t=this._inflate[HD];if(t){this._inflate.close(),this._inflate=null,h(t);return}let N=XT.concat(this._inflate[d2],this._inflate[X1]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[X1]=0,this._inflate[d2]=[],f&&this.params[`${E}_no_context_takeover`]&&this._inflate.reset()),h(null,N)})}_compress(l,f,h){let E=this._isServer?"server":"client";if(!this._deflate){let t=`${E}_max_window_bits`,N=typeof this.params[t]!="number"?tg.Z_DEFAULT_WINDOWBITS:this.params[t];this._deflate=tg.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:N}),this._deflate[X1]=0,this._deflate[d2]=[],this._deflate.on("error",vI),this._deflate.on("data",yI)}this._deflate[ng]=h,this._deflate.write(l),this._deflate.flush(tg.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let t=XT.concat(this._deflate[d2],this._deflate[X1]);f&&(t=t.slice(0,t.length-4)),this._deflate[ng]=null,this._deflate[X1]=0,this._deflate[d2]=[],f&&this.params[`${E}_no_context_takeover`]&&this._deflate.reset(),h(null,t)})}};ZT.exports=qD;function yI(o){this[d2].push(o),this[X1]+=o.length}function JT(o){if(this[X1]+=o.length,this[Z_]._maxPayload<1||this[X1]<=this[Z_]._maxPayload){this[d2].push(o);return}this[HD]=new RangeError("Max payload size exceeded"),this[HD][QT]=1009,this.removeListener("data",JT),this.reset()}function gI(o){this[Z_]._inflate=null,o[QT]=1007,this[ng](o)}});var VD=nt((QH,WD)=>{"use strict";function $T(o){return o>=1e3&&o<=1014&&o!==1004&&o!==1005&&o!==1006||o>=3e3&&o<=4999}function eC(o){let l=o.length,f=0;for(;f=l||(o[f+1]&192)!==128||(o[f+2]&192)!==128||o[f]===224&&(o[f+1]&224)===128||o[f]===237&&(o[f+1]&224)===160)return!1;f+=3}else if((o[f]&248)===240){if(f+3>=l||(o[f+1]&192)!==128||(o[f+2]&192)!==128||(o[f+3]&192)!==128||o[f]===240&&(o[f+1]&240)===128||o[f]===244&&o[f+1]>143||o[f]>244)return!1;f+=4}else return!1;return!0}try{let o=hi("utf-8-validate");typeof o=="object"&&(o=o.Validation.isValidUTF8),WD.exports={isValidStatusCode:$T,isValidUTF8(l){return l.length<150?eC(l):o(l)}}}catch{WD.exports={isValidStatusCode:$T,isValidUTF8:eC}}});var XD=nt((JH,oC)=>{"use strict";var{Writable:_I}=hi("stream"),tC=rg(),{BINARY_TYPES:EI,EMPTY_BUFFER:DI,kStatusCode:wI,kWebSocket:SI}=th(),{concat:GD,toArrayBuffer:TI,unmask:CI}=eg(),{isValidStatusCode:xI,isValidUTF8:nC}=VD(),ig=0,rC=1,iC=2,uC=3,YD=4,RI=5,KD=class extends _I{constructor(l,f,h,E){super(),this._binaryType=l||EI[0],this[SI]=void 0,this._extensions=f||{},this._isServer=!!h,this._maxPayload=E|0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._state=ig,this._loop=!1}_write(l,f,h){if(this._opcode===8&&this._state==ig)return h();this._bufferedBytes+=l.length,this._buffers.push(l),this.startLoop(h)}consume(l){if(this._bufferedBytes-=l,l===this._buffers[0].length)return this._buffers.shift();if(l=h.length?f.set(this._buffers.shift(),E):(f.set(new Uint8Array(h.buffer,h.byteOffset,l),E),this._buffers[0]=h.slice(l)),l-=h.length}while(l>0);return f}startLoop(l){let f;this._loop=!0;do switch(this._state){case ig:f=this.getInfo();break;case rC:f=this.getPayloadLength16();break;case iC:f=this.getPayloadLength64();break;case uC:this.getMask();break;case YD:f=this.getData(l);break;default:this._loop=!1;return}while(this._loop);l(f)}getInfo(){if(this._bufferedBytes<2){this._loop=!1;return}let l=this.consume(2);if((l[0]&48)!==0)return this._loop=!1,Ko(RangeError,"RSV2 and RSV3 must be clear",!0,1002);let f=(l[0]&64)===64;if(f&&!this._extensions[tC.extensionName])return this._loop=!1,Ko(RangeError,"RSV1 must be clear",!0,1002);if(this._fin=(l[0]&128)===128,this._opcode=l[0]&15,this._payloadLength=l[1]&127,this._opcode===0){if(f)return this._loop=!1,Ko(RangeError,"RSV1 must be clear",!0,1002);if(!this._fragmented)return this._loop=!1,Ko(RangeError,"invalid opcode 0",!0,1002);this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented)return this._loop=!1,Ko(RangeError,`invalid opcode ${this._opcode}`,!0,1002);this._compressed=f}else if(this._opcode>7&&this._opcode<11){if(!this._fin)return this._loop=!1,Ko(RangeError,"FIN must be set",!0,1002);if(f)return this._loop=!1,Ko(RangeError,"RSV1 must be clear",!0,1002);if(this._payloadLength>125)return this._loop=!1,Ko(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002)}else return this._loop=!1,Ko(RangeError,`invalid opcode ${this._opcode}`,!0,1002);if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(l[1]&128)===128,this._isServer){if(!this._masked)return this._loop=!1,Ko(RangeError,"MASK must be set",!0,1002)}else if(this._masked)return this._loop=!1,Ko(RangeError,"MASK must be clear",!0,1002);if(this._payloadLength===126)this._state=rC;else if(this._payloadLength===127)this._state=iC;else return this.haveLength()}getPayloadLength16(){if(this._bufferedBytes<2){this._loop=!1;return}return this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength()}getPayloadLength64(){if(this._bufferedBytes<8){this._loop=!1;return}let l=this.consume(8),f=l.readUInt32BE(0);return f>Math.pow(2,53-32)-1?(this._loop=!1,Ko(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009)):(this._payloadLength=f*Math.pow(2,32)+l.readUInt32BE(4),this.haveLength())}haveLength(){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0))return this._loop=!1,Ko(RangeError,"Max payload size exceeded",!1,1009);this._masked?this._state=uC:this._state=YD}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=YD}getData(l){let f=DI;if(this._payloadLength){if(this._bufferedBytes7)return this.controlMessage(f);if(this._compressed){this._state=RI,this.decompress(f,l);return}return f.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(f)),this.dataMessage()}decompress(l,f){this._extensions[tC.extensionName].decompress(l,this._fin,(E,t)=>{if(E)return f(E);if(t.length){if(this._messageLength+=t.length,this._messageLength>this._maxPayload&&this._maxPayload>0)return f(Ko(RangeError,"Max payload size exceeded",!1,1009));this._fragments.push(t)}let N=this.dataMessage();if(N)return f(N);this.startLoop(f)})}dataMessage(){if(this._fin){let l=this._messageLength,f=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let h;this._binaryType==="nodebuffer"?h=GD(f,l):this._binaryType==="arraybuffer"?h=TI(GD(f,l)):h=f,this.emit("message",h)}else{let h=GD(f,l);if(!nC(h))return this._loop=!1,Ko(Error,"invalid UTF-8 sequence",!0,1007);this.emit("message",h.toString())}}this._state=ig}controlMessage(l){if(this._opcode===8)if(this._loop=!1,l.length===0)this.emit("conclude",1005,""),this.end();else{if(l.length===1)return Ko(RangeError,"invalid payload length 1",!0,1002);{let f=l.readUInt16BE(0);if(!xI(f))return Ko(RangeError,`invalid status code ${f}`,!0,1002);let h=l.slice(2);if(!nC(h))return Ko(Error,"invalid UTF-8 sequence",!0,1007);this.emit("conclude",f,h.toString()),this.end()}}else this._opcode===9?this.emit("ping",l):this.emit("pong",l);this._state=ig}};oC.exports=KD;function Ko(o,l,f,h){let E=new o(f?`Invalid WebSocket frame: ${l}`:l);return Error.captureStackTrace(E,Ko),E[wI]=h,E}});var QD=nt((ZH,aC)=>{"use strict";var{randomFillSync:AI}=hi("crypto"),lC=rg(),{EMPTY_BUFFER:OI}=th(),{isValidStatusCode:MI}=VD(),{mask:sC,toBuffer:Q1}=eg(),nh=Buffer.alloc(4),jc=class{constructor(l,f){this._extensions=f||{},this._socket=l,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._deflating=!1,this._queue=[]}static frame(l,f){let h=f.mask&&f.readOnly,E=f.mask?6:2,t=l.length;l.length>=65536?(E+=8,t=127):l.length>125&&(E+=2,t=126);let N=Buffer.allocUnsafe(h?l.length+E:E);return N[0]=f.fin?f.opcode|128:f.opcode,f.rsv1&&(N[0]|=64),N[1]=t,t===126?N.writeUInt16BE(l.length,2):t===127&&(N.writeUInt32BE(0,2),N.writeUInt32BE(l.length,6)),f.mask?(AI(nh,0,4),N[1]|=128,N[E-4]=nh[0],N[E-3]=nh[1],N[E-2]=nh[2],N[E-1]=nh[3],h?(sC(l,nh,N,E,l.length),[N]):(sC(l,nh,l,0,l.length),[N,l])):[N,l]}close(l,f,h,E){let t;if(l===void 0)t=OI;else{if(typeof l!="number"||!MI(l))throw new TypeError("First argument must be a valid error code number");if(f===void 0||f==="")t=Buffer.allocUnsafe(2),t.writeUInt16BE(l,0);else{let N=Buffer.byteLength(f);if(N>123)throw new RangeError("The message must not be greater than 123 bytes");t=Buffer.allocUnsafe(2+N),t.writeUInt16BE(l,0),t.write(f,2)}}this._deflating?this.enqueue([this.doClose,t,h,E]):this.doClose(t,h,E)}doClose(l,f,h){this.sendFrame(jc.frame(l,{fin:!0,rsv1:!1,opcode:8,mask:f,readOnly:!1}),h)}ping(l,f,h){let E=Q1(l);if(E.length>125)throw new RangeError("The data size must not be greater than 125 bytes");this._deflating?this.enqueue([this.doPing,E,f,Q1.readOnly,h]):this.doPing(E,f,Q1.readOnly,h)}doPing(l,f,h,E){this.sendFrame(jc.frame(l,{fin:!0,rsv1:!1,opcode:9,mask:f,readOnly:h}),E)}pong(l,f,h){let E=Q1(l);if(E.length>125)throw new RangeError("The data size must not be greater than 125 bytes");this._deflating?this.enqueue([this.doPong,E,f,Q1.readOnly,h]):this.doPong(E,f,Q1.readOnly,h)}doPong(l,f,h,E){this.sendFrame(jc.frame(l,{fin:!0,rsv1:!1,opcode:10,mask:f,readOnly:h}),E)}send(l,f,h){let E=Q1(l),t=this._extensions[lC.extensionName],N=f.binary?2:1,F=f.compress;if(this._firstFragment?(this._firstFragment=!1,F&&t&&(F=E.length>=t._threshold),this._compress=F):(F=!1,N=0),f.fin&&(this._firstFragment=!0),t){let k={fin:f.fin,rsv1:F,opcode:N,mask:f.mask,readOnly:Q1.readOnly};this._deflating?this.enqueue([this.dispatch,E,this._compress,k,h]):this.dispatch(E,this._compress,k,h)}else this.sendFrame(jc.frame(E,{fin:f.fin,rsv1:!1,opcode:N,mask:f.mask,readOnly:Q1.readOnly}),h)}dispatch(l,f,h,E){if(!f){this.sendFrame(jc.frame(l,h),E);return}let t=this._extensions[lC.extensionName];this._bufferedBytes+=l.length,this._deflating=!0,t.compress(l,h.fin,(N,F)=>{if(this._socket.destroyed){let k=new Error("The socket was closed while data was being compressed");typeof E=="function"&&E(k);for(let x=0;x{"use strict";var tm=class{constructor(l,f){this.target=f,this.type=l}},JD=class extends tm{constructor(l,f){super("message",f),this.data=l}},ZD=class extends tm{constructor(l,f,h){super("close",h),this.wasClean=h._closeFrameReceived&&h._closeFrameSent,this.reason=f,this.code=l}},$D=class extends tm{constructor(l){super("open",l)}},e3=class extends tm{constructor(l,f){super("error",f),this.message=l.message,this.error=l}},kI={addEventListener(o,l,f){if(typeof l!="function")return;function h(k){l.call(this,new JD(k,this))}function E(k,x){l.call(this,new ZD(k,x,this))}function t(k){l.call(this,new e3(k,this))}function N(){l.call(this,new $D(this))}let F=f&&f.once?"once":"on";o==="message"?(h._listener=l,this[F](o,h)):o==="close"?(E._listener=l,this[F](o,E)):o==="error"?(t._listener=l,this[F](o,t)):o==="open"?(N._listener=l,this[F](o,N)):this[F](o,l)},removeEventListener(o,l){let f=this.listeners(o);for(let h=0;h{"use strict";var ug=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function zc(o,l,f){o[l]===void 0?o[l]=[f]:o[l].push(f)}function NI(o){let l=Object.create(null);if(o===void 0||o==="")return l;let f=Object.create(null),h=!1,E=!1,t=!1,N,F,k=-1,x=-1,j=0;for(;j{let f=o[l];return Array.isArray(f)||(f=[f]),f.map(h=>[l].concat(Object.keys(h).map(E=>{let t=h[E];return Array.isArray(t)||(t=[t]),t.map(N=>N===!0?E:`${E}=${N}`).join("; ")})).join("; ")).join(", ")}).join(", ")}dC.exports={format:LI,parse:NI}});var o3=nt((tq,wC)=>{"use strict";var FI=hi("events"),PI=hi("https"),II=hi("http"),vC=hi("net"),bI=hi("tls"),{randomBytes:BI,createHash:UI}=hi("crypto"),{URL:n3}=hi("url"),p2=rg(),jI=XD(),zI=QD(),{BINARY_TYPES:pC,EMPTY_BUFFER:r3,GUID:HI,kStatusCode:qI,kWebSocket:ta,NOOP:mC}=th(),{addEventListener:WI,removeEventListener:VI}=cC(),{format:GI,parse:YI}=t3(),{toBuffer:KI}=eg(),yC=["CONNECTING","OPEN","CLOSING","CLOSED"],i3=[8,13],XI=30*1e3,ji=class extends FI{constructor(l,f,h){super(),this._binaryType=pC[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage="",this._closeTimer=null,this._extensions={},this._protocol="",this._readyState=ji.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,l!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,Array.isArray(f)?f=f.join(", "):typeof f=="object"&&f!==null&&(h=f,f=void 0),gC(this,l,f,h)):this._isServer=!0}get binaryType(){return this._binaryType}set binaryType(l){!pC.includes(l)||(this._binaryType=l,this._receiver&&(this._receiver._binaryType=l))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(l,f,h){let E=new jI(this.binaryType,this._extensions,this._isServer,h);this._sender=new zI(l,this._extensions),this._receiver=E,this._socket=l,E[ta]=this,l[ta]=this,E.on("conclude",ZI),E.on("drain",$I),E.on("error",eb),E.on("message",tb),E.on("ping",nb),E.on("pong",rb),l.setTimeout(0),l.setNoDelay(),f.length>0&&l.unshift(f),l.on("close",_C),l.on("data",$_),l.on("end",EC),l.on("error",DC),this._readyState=ji.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=ji.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[p2.extensionName]&&this._extensions[p2.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=ji.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(l,f){if(this.readyState!==ji.CLOSED){if(this.readyState===ji.CONNECTING){let h="WebSocket was closed before the connection was established";return J1(this,this._req,h)}if(this.readyState===ji.CLOSING){this._closeFrameSent&&this._closeFrameReceived&&this._socket.end();return}this._readyState=ji.CLOSING,this._sender.close(l,f,!this._isServer,h=>{h||(this._closeFrameSent=!0,this._closeFrameReceived&&this._socket.end())}),this._closeTimer=setTimeout(this._socket.destroy.bind(this._socket),XI)}}ping(l,f,h){if(this.readyState===ji.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof l=="function"?(h=l,l=f=void 0):typeof f=="function"&&(h=f,f=void 0),typeof l=="number"&&(l=l.toString()),this.readyState!==ji.OPEN){u3(this,l,h);return}f===void 0&&(f=!this._isServer),this._sender.ping(l||r3,f,h)}pong(l,f,h){if(this.readyState===ji.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof l=="function"?(h=l,l=f=void 0):typeof f=="function"&&(h=f,f=void 0),typeof l=="number"&&(l=l.toString()),this.readyState!==ji.OPEN){u3(this,l,h);return}f===void 0&&(f=!this._isServer),this._sender.pong(l||r3,f,h)}send(l,f,h){if(this.readyState===ji.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof f=="function"&&(h=f,f={}),typeof l=="number"&&(l=l.toString()),this.readyState!==ji.OPEN){u3(this,l,h);return}let E={binary:typeof l!="string",mask:!this._isServer,compress:!0,fin:!0,...f};this._extensions[p2.extensionName]||(E.compress=!1),this._sender.send(l||r3,E,h)}terminate(){if(this.readyState!==ji.CLOSED){if(this.readyState===ji.CONNECTING){let l="WebSocket was closed before the connection was established";return J1(this,this._req,l)}this._socket&&(this._readyState=ji.CLOSING,this._socket.destroy())}}};yC.forEach((o,l)=>{let f={enumerable:!0,value:l};Object.defineProperty(ji.prototype,o,f),Object.defineProperty(ji,o,f)});["binaryType","bufferedAmount","extensions","protocol","readyState","url"].forEach(o=>{Object.defineProperty(ji.prototype,o,{enumerable:!0})});["open","error","close","message"].forEach(o=>{Object.defineProperty(ji.prototype,`on${o}`,{configurable:!0,enumerable:!0,get(){let l=this.listeners(o);for(let f=0;f{J1(o,V,"Opening handshake has timed out")}),V.on("error",re=>{V===null||V.aborted||(V=o._req=null,o._readyState=ji.CLOSING,o.emit("error",re),o.emitClose())}),V.on("response",re=>{let y=re.headers.location,me=re.statusCode;if(y&&E.followRedirects&&me>=300&&me<400){if(++o._redirects>E.maxRedirects){J1(o,V,"Maximum redirects exceeded");return}V.abort();let De=new n3(y,l);gC(o,De,f,h)}else o.emit("unexpected-response",V,re)||J1(o,V,`Unexpected server response: ${re.statusCode}`)}),V.on("upgrade",(re,y,me)=>{if(o.emit("upgrade",re),o.readyState!==ji.CONNECTING)return;V=o._req=null;let De=UI("sha1").update(x+HI).digest("base64");if(re.headers["sec-websocket-accept"]!==De){J1(o,y,"Invalid Sec-WebSocket-Accept header");return}let ge=re.headers["sec-websocket-protocol"],ae=(f||"").split(/, */),we;if(!f&&ge?we="Server sent a subprotocol but none was requested":f&&!ge?we="Server sent no subprotocol":ge&&!ae.includes(ge)&&(we="Server sent an invalid subprotocol"),we){J1(o,y,we);return}if(ge&&(o._protocol=ge),q)try{let he=YI(re.headers["sec-websocket-extensions"]);he[p2.extensionName]&&(q.accept(he[p2.extensionName]),o._extensions[p2.extensionName]=q)}catch{J1(o,y,"Invalid Sec-WebSocket-Extensions header");return}o.setSocket(y,me,E.maxPayload)})}function QI(o){return o.path=o.socketPath,vC.connect(o)}function JI(o){return o.path=void 0,!o.servername&&o.servername!==""&&(o.servername=vC.isIP(o.host)?"":o.host),bI.connect(o)}function J1(o,l,f){o._readyState=ji.CLOSING;let h=new Error(f);Error.captureStackTrace(h,J1),l.setHeader?(l.abort(),l.socket&&!l.socket.destroyed&&l.socket.destroy(),l.once("abort",o.emitClose.bind(o)),o.emit("error",h)):(l.destroy(h),l.once("error",o.emit.bind(o,"error")),l.once("close",o.emitClose.bind(o)))}function u3(o,l,f){if(l){let h=KI(l).length;o._socket?o._sender._bufferedBytes+=h:o._bufferedAmount+=h}if(f){let h=new Error(`WebSocket is not open: readyState ${o.readyState} (${yC[o.readyState]})`);f(h)}}function ZI(o,l){let f=this[ta];f._socket.removeListener("data",$_),f._socket.resume(),f._closeFrameReceived=!0,f._closeMessage=l,f._closeCode=o,o===1005?f.close():f.close(o,l)}function $I(){this[ta]._socket.resume()}function eb(o){let l=this[ta];l._socket.removeListener("data",$_),l._readyState=ji.CLOSING,l._closeCode=o[qI],l.emit("error",o),l._socket.destroy()}function hC(){this[ta].emitClose()}function tb(o){this[ta].emit("message",o)}function nb(o){let l=this[ta];l.pong(o,!l._isServer,mC),l.emit("ping",o)}function rb(o){this[ta].emit("pong",o)}function _C(){let o=this[ta];this.removeListener("close",_C),this.removeListener("end",EC),o._readyState=ji.CLOSING,o._socket.read(),o._receiver.end(),this.removeListener("data",$_),this[ta]=void 0,clearTimeout(o._closeTimer),o._receiver._writableState.finished||o._receiver._writableState.errorEmitted?o.emitClose():(o._receiver.on("error",hC),o._receiver.on("finish",hC))}function $_(o){this[ta]._receiver.write(o)||this.pause()}function EC(){let o=this[ta];o._readyState=ji.CLOSING,o._receiver.end(),this.end()}function DC(){let o=this[ta];this.removeListener("error",DC),this.on("error",mC),o&&(o._readyState=ji.CLOSING,this.destroy())}});var xC=nt((nq,CC)=>{"use strict";var{Duplex:ib}=hi("stream");function SC(o){o.emit("close")}function ub(){!this.destroyed&&this._writableState.finished&&this.destroy()}function TC(o){this.removeListener("error",TC),this.destroy(),this.listenerCount("error")===0&&this.emit("error",o)}function ob(o,l){let f=!0;function h(){f&&o._socket.resume()}o.readyState===o.CONNECTING?o.once("open",function(){o._receiver.removeAllListeners("drain"),o._receiver.on("drain",h)}):(o._receiver.removeAllListeners("drain"),o._receiver.on("drain",h));let E=new ib({...l,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return o.on("message",function(N){E.push(N)||(f=!1,o._socket.pause())}),o.once("error",function(N){E.destroyed||E.destroy(N)}),o.once("close",function(){E.destroyed||E.push(null)}),E._destroy=function(t,N){if(o.readyState===o.CLOSED){N(t),process.nextTick(SC,E);return}let F=!1;o.once("error",function(x){F=!0,N(x)}),o.once("close",function(){F||N(t),process.nextTick(SC,E)}),o.terminate()},E._final=function(t){if(o.readyState===o.CONNECTING){o.once("open",function(){E._final(t)});return}o._socket!==null&&(o._socket._writableState.finished?(t(),E._readableState.endEmitted&&E.destroy()):(o._socket.once("finish",function(){t()}),o.close()))},E._read=function(){o.readyState===o.OPEN&&!f&&(f=!0,o._receiver._writableState.needDrain||o._socket.resume())},E._write=function(t,N,F){if(o.readyState===o.CONNECTING){o.once("open",function(){E._write(t,N,F)});return}o.send(t,F)},E.on("end",ub),E.on("error",TC),E}CC.exports=ob});var AC=nt((rq,RC)=>{"use strict";var lb=hi("events"),{createHash:sb}=hi("crypto"),{createServer:ab,STATUS_CODES:l3}=hi("http"),rh=rg(),fb=o3(),{format:db,parse:pb}=t3(),{GUID:hb,kWebSocket:vb}=th(),mb=/^[+/0-9A-Za-z]{22}==$/,s3=class extends lb{constructor(l,f){if(super(),l={maxPayload:100*1024*1024,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,...l},l.port==null&&!l.server&&!l.noServer)throw new TypeError('One of the "port", "server", or "noServer" options must be specified');if(l.port!=null?(this._server=ab((h,E)=>{let t=l3[426];E.writeHead(426,{"Content-Length":t.length,"Content-Type":"text/plain"}),E.end(t)}),this._server.listen(l.port,l.host,l.backlog,f)):l.server&&(this._server=l.server),this._server){let h=this.emit.bind(this,"connection");this._removeListeners=yb(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(E,t,N)=>{this.handleUpgrade(E,t,N,h)}})}l.perMessageDeflate===!0&&(l.perMessageDeflate={}),l.clientTracking&&(this.clients=new Set),this.options=l}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(l){if(l&&this.once("close",l),this.clients)for(let h of this.clients)h.terminate();let f=this._server;if(f&&(this._removeListeners(),this._removeListeners=this._server=null,this.options.port!=null)){f.close(()=>this.emit("close"));return}process.nextTick(gb,this)}shouldHandle(l){if(this.options.path){let f=l.url.indexOf("?");if((f!==-1?l.url.slice(0,f):l.url)!==this.options.path)return!1}return!0}handleUpgrade(l,f,h,E){f.on("error",a3);let t=l.headers["sec-websocket-key"]!==void 0?l.headers["sec-websocket-key"].trim():!1,N=+l.headers["sec-websocket-version"],F={};if(l.method!=="GET"||l.headers.upgrade.toLowerCase()!=="websocket"||!t||!mb.test(t)||N!==8&&N!==13||!this.shouldHandle(l))return e4(f,400);if(this.options.perMessageDeflate){let k=new rh(this.options.perMessageDeflate,!0,this.options.maxPayload);try{let x=pb(l.headers["sec-websocket-extensions"]);x[rh.extensionName]&&(k.accept(x[rh.extensionName]),F[rh.extensionName]=k)}catch{return e4(f,400)}}if(this.options.verifyClient){let k={origin:l.headers[`${N===8?"sec-websocket-origin":"origin"}`],secure:!!(l.socket.authorized||l.socket.encrypted),req:l};if(this.options.verifyClient.length===2){this.options.verifyClient(k,(x,j,q,V)=>{if(!x)return e4(f,j||401,q,V);this.completeUpgrade(t,F,l,f,h,E)});return}if(!this.options.verifyClient(k))return e4(f,401)}this.completeUpgrade(t,F,l,f,h,E)}completeUpgrade(l,f,h,E,t,N){if(!E.readable||!E.writable)return E.destroy();if(E[vb])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");let k=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${sb("sha1").update(l+hb).digest("base64")}`],x=new fb(null),j=h.headers["sec-websocket-protocol"];if(j&&(j=j.split(",").map(_b),this.options.handleProtocols?j=this.options.handleProtocols(j,h):j=j[0],j&&(k.push(`Sec-WebSocket-Protocol: ${j}`),x._protocol=j)),f[rh.extensionName]){let q=f[rh.extensionName].params,V=db({[rh.extensionName]:[q]});k.push(`Sec-WebSocket-Extensions: ${V}`),x._extensions=f}this.emit("headers",k,h),E.write(k.concat(`\r +`).join(`\r +`)),E.removeListener("error",a3),x.setSocket(E,t,this.options.maxPayload),this.clients&&(this.clients.add(x),x.on("close",()=>this.clients.delete(x))),N(x,h)}};RC.exports=s3;function yb(o,l){for(let f of Object.keys(l))o.on(f,l[f]);return function(){for(let h of Object.keys(l))o.removeListener(h,l[h])}}function gb(o){o.emit("close")}function a3(){this.destroy()}function e4(o,l,f,h){o.writable&&(f=f||l3[l],h={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(f),...h},o.write(`HTTP/1.1 ${l} ${l3[l]}\r +`+Object.keys(h).map(E=>`${E}: ${h[E]}`).join(`\r +`)+`\r +\r +`+f)),o.removeListener("error",a3),o.destroy()}function _b(o){return o.trim()}});var MC=nt((iq,OC)=>{"use strict";var og=o3();og.createWebSocketStream=xC();og.Server=AC();og.Receiver=XD();og.Sender=QD();OC.exports=og});var kC=nt(t4=>{"use strict";var Eb=t4&&t4.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(t4,"__esModule",{value:!0});var Db=Eb(MC()),lg=global;lg.WebSocket||(lg.WebSocket=Db.default);lg.window||(lg.window=global);lg.window.__REACT_DEVTOOLS_COMPONENT_FILTERS__=[{type:1,value:7,isEnabled:!0},{type:2,value:"InternalApp",isEnabled:!0,isValid:!0},{type:2,value:"InternalAppContext",isEnabled:!0,isValid:!0},{type:2,value:"InternalStdoutContext",isEnabled:!0,isValid:!0},{type:2,value:"InternalStderrContext",isEnabled:!0,isValid:!0},{type:2,value:"InternalStdinContext",isEnabled:!0,isValid:!0},{type:2,value:"InternalFocusContext",isEnabled:!0,isValid:!0}]});var NC=nt((n4,f3)=>{(function(o,l){typeof n4=="object"&&typeof f3=="object"?f3.exports=l():typeof define=="function"&&define.amd?define([],l):typeof n4=="object"?n4.ReactDevToolsBackend=l():o.ReactDevToolsBackend=l()})(window,function(){return function(o){var l={};function f(h){if(l[h])return l[h].exports;var E=l[h]={i:h,l:!1,exports:{}};return o[h].call(E.exports,E,E.exports,f),E.l=!0,E.exports}return f.m=o,f.c=l,f.d=function(h,E,t){f.o(h,E)||Object.defineProperty(h,E,{enumerable:!0,get:t})},f.r=function(h){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(h,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(h,"__esModule",{value:!0})},f.t=function(h,E){if(1&E&&(h=f(h)),8&E||4&E&&typeof h=="object"&&h&&h.__esModule)return h;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:h}),2&E&&typeof h!="string")for(var N in h)f.d(t,N,function(F){return h[F]}.bind(null,N));return t},f.n=function(h){var E=h&&h.__esModule?function(){return h.default}:function(){return h};return f.d(E,"a",E),E},f.o=function(h,E){return Object.prototype.hasOwnProperty.call(h,E)},f.p="",f(f.s=20)}([function(o,l,f){"use strict";o.exports=f(12)},function(o,l,f){"use strict";var h=Object.getOwnPropertySymbols,E=Object.prototype.hasOwnProperty,t=Object.prototype.propertyIsEnumerable;function N(F){if(F==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(F)}o.exports=function(){try{if(!Object.assign)return!1;var F=new String("abc");if(F[5]="de",Object.getOwnPropertyNames(F)[0]==="5")return!1;for(var k={},x=0;x<10;x++)k["_"+String.fromCharCode(x)]=x;if(Object.getOwnPropertyNames(k).map(function(q){return k[q]}).join("")!=="0123456789")return!1;var j={};return"abcdefghijklmnopqrst".split("").forEach(function(q){j[q]=q}),Object.keys(Object.assign({},j)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}()?Object.assign:function(F,k){for(var x,j,q=N(F),V=1;V"u"?"undefined":E(self))=="object"&&self&&self.Object===Object&&self,V=j||q||Function("return this")(),re=Object.prototype.toString,y=Math.max,me=Math.min,De=function(){return V.Date.now()};function ge(ve,ue,Ae){var ze,We,gt,_t,Qe,ot,Ve=0,Pt=!1,Jt=!1,it=!0;if(typeof ve!="function")throw new TypeError("Expected a function");function J(At){var nn=ze,an=We;return ze=We=void 0,Ve=At,_t=ve.apply(an,nn)}function ce(At){return Ve=At,Qe=setTimeout(le,ue),Pt?J(At):_t}function Re(At){var nn=At-ot;return ot===void 0||nn>=ue||nn<0||Jt&&At-Ve>=gt}function le(){var At=De();if(Re(At))return He(At);Qe=setTimeout(le,function(nn){var an=ue-(nn-ot);return Jt?me(an,gt-(nn-Ve)):an}(At))}function He(At){return Qe=void 0,it&&ze?J(At):(ze=We=void 0,_t)}function dt(){var At=De(),nn=Re(At);if(ze=arguments,We=this,ot=At,nn){if(Qe===void 0)return ce(ot);if(Jt)return Qe=setTimeout(le,ue),J(ot)}return Qe===void 0&&(Qe=setTimeout(le,ue)),_t}return ue=he(ue)||0,ae(Ae)&&(Pt=!!Ae.leading,gt=(Jt="maxWait"in Ae)?y(he(Ae.maxWait)||0,ue):gt,it="trailing"in Ae?!!Ae.trailing:it),dt.cancel=function(){Qe!==void 0&&clearTimeout(Qe),Ve=0,ze=ot=We=Qe=void 0},dt.flush=function(){return Qe===void 0?_t:He(De())},dt}function ae(ve){var ue=E(ve);return!!ve&&(ue=="object"||ue=="function")}function we(ve){return E(ve)=="symbol"||function(ue){return!!ue&&E(ue)=="object"}(ve)&&re.call(ve)=="[object Symbol]"}function he(ve){if(typeof ve=="number")return ve;if(we(ve))return NaN;if(ae(ve)){var ue=typeof ve.valueOf=="function"?ve.valueOf():ve;ve=ae(ue)?ue+"":ue}if(typeof ve!="string")return ve===0?ve:+ve;ve=ve.replace(t,"");var Ae=F.test(ve);return Ae||k.test(ve)?x(ve.slice(2),Ae?2:8):N.test(ve)?NaN:+ve}o.exports=function(ve,ue,Ae){var ze=!0,We=!0;if(typeof ve!="function")throw new TypeError("Expected a function");return ae(Ae)&&(ze="leading"in Ae?!!Ae.leading:ze,We="trailing"in Ae?!!Ae.trailing:We),ge(ve,ue,{leading:ze,maxWait:ue,trailing:We})}}).call(this,f(4))},function(o,l,f){(function(h){function E(J){return(E=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(ce){return typeof ce}:function(ce){return ce&&typeof Symbol=="function"&&ce.constructor===Symbol&&ce!==Symbol.prototype?"symbol":typeof ce})(J)}var t;l=o.exports=y,t=(h===void 0?"undefined":E(h))==="object"&&h.env&&h.env.NODE_DEBUG&&/\bsemver\b/i.test(h.env.NODE_DEBUG)?function(){var J=Array.prototype.slice.call(arguments,0);J.unshift("SEMVER"),console.log.apply(console,J)}:function(){},l.SEMVER_SPEC_VERSION="2.0.0";var N=Number.MAX_SAFE_INTEGER||9007199254740991,F=l.re=[],k=l.src=[],x=l.tokens={},j=0;function q(J){x[J]=j++}q("NUMERICIDENTIFIER"),k[x.NUMERICIDENTIFIER]="0|[1-9]\\d*",q("NUMERICIDENTIFIERLOOSE"),k[x.NUMERICIDENTIFIERLOOSE]="[0-9]+",q("NONNUMERICIDENTIFIER"),k[x.NONNUMERICIDENTIFIER]="\\d*[a-zA-Z-][a-zA-Z0-9-]*",q("MAINVERSION"),k[x.MAINVERSION]="("+k[x.NUMERICIDENTIFIER]+")\\.("+k[x.NUMERICIDENTIFIER]+")\\.("+k[x.NUMERICIDENTIFIER]+")",q("MAINVERSIONLOOSE"),k[x.MAINVERSIONLOOSE]="("+k[x.NUMERICIDENTIFIERLOOSE]+")\\.("+k[x.NUMERICIDENTIFIERLOOSE]+")\\.("+k[x.NUMERICIDENTIFIERLOOSE]+")",q("PRERELEASEIDENTIFIER"),k[x.PRERELEASEIDENTIFIER]="(?:"+k[x.NUMERICIDENTIFIER]+"|"+k[x.NONNUMERICIDENTIFIER]+")",q("PRERELEASEIDENTIFIERLOOSE"),k[x.PRERELEASEIDENTIFIERLOOSE]="(?:"+k[x.NUMERICIDENTIFIERLOOSE]+"|"+k[x.NONNUMERICIDENTIFIER]+")",q("PRERELEASE"),k[x.PRERELEASE]="(?:-("+k[x.PRERELEASEIDENTIFIER]+"(?:\\."+k[x.PRERELEASEIDENTIFIER]+")*))",q("PRERELEASELOOSE"),k[x.PRERELEASELOOSE]="(?:-?("+k[x.PRERELEASEIDENTIFIERLOOSE]+"(?:\\."+k[x.PRERELEASEIDENTIFIERLOOSE]+")*))",q("BUILDIDENTIFIER"),k[x.BUILDIDENTIFIER]="[0-9A-Za-z-]+",q("BUILD"),k[x.BUILD]="(?:\\+("+k[x.BUILDIDENTIFIER]+"(?:\\."+k[x.BUILDIDENTIFIER]+")*))",q("FULL"),q("FULLPLAIN"),k[x.FULLPLAIN]="v?"+k[x.MAINVERSION]+k[x.PRERELEASE]+"?"+k[x.BUILD]+"?",k[x.FULL]="^"+k[x.FULLPLAIN]+"$",q("LOOSEPLAIN"),k[x.LOOSEPLAIN]="[v=\\s]*"+k[x.MAINVERSIONLOOSE]+k[x.PRERELEASELOOSE]+"?"+k[x.BUILD]+"?",q("LOOSE"),k[x.LOOSE]="^"+k[x.LOOSEPLAIN]+"$",q("GTLT"),k[x.GTLT]="((?:<|>)?=?)",q("XRANGEIDENTIFIERLOOSE"),k[x.XRANGEIDENTIFIERLOOSE]=k[x.NUMERICIDENTIFIERLOOSE]+"|x|X|\\*",q("XRANGEIDENTIFIER"),k[x.XRANGEIDENTIFIER]=k[x.NUMERICIDENTIFIER]+"|x|X|\\*",q("XRANGEPLAIN"),k[x.XRANGEPLAIN]="[v=\\s]*("+k[x.XRANGEIDENTIFIER]+")(?:\\.("+k[x.XRANGEIDENTIFIER]+")(?:\\.("+k[x.XRANGEIDENTIFIER]+")(?:"+k[x.PRERELEASE]+")?"+k[x.BUILD]+"?)?)?",q("XRANGEPLAINLOOSE"),k[x.XRANGEPLAINLOOSE]="[v=\\s]*("+k[x.XRANGEIDENTIFIERLOOSE]+")(?:\\.("+k[x.XRANGEIDENTIFIERLOOSE]+")(?:\\.("+k[x.XRANGEIDENTIFIERLOOSE]+")(?:"+k[x.PRERELEASELOOSE]+")?"+k[x.BUILD]+"?)?)?",q("XRANGE"),k[x.XRANGE]="^"+k[x.GTLT]+"\\s*"+k[x.XRANGEPLAIN]+"$",q("XRANGELOOSE"),k[x.XRANGELOOSE]="^"+k[x.GTLT]+"\\s*"+k[x.XRANGEPLAINLOOSE]+"$",q("COERCE"),k[x.COERCE]="(^|[^\\d])(\\d{1,16})(?:\\.(\\d{1,16}))?(?:\\.(\\d{1,16}))?(?:$|[^\\d])",q("COERCERTL"),F[x.COERCERTL]=new RegExp(k[x.COERCE],"g"),q("LONETILDE"),k[x.LONETILDE]="(?:~>?)",q("TILDETRIM"),k[x.TILDETRIM]="(\\s*)"+k[x.LONETILDE]+"\\s+",F[x.TILDETRIM]=new RegExp(k[x.TILDETRIM],"g"),q("TILDE"),k[x.TILDE]="^"+k[x.LONETILDE]+k[x.XRANGEPLAIN]+"$",q("TILDELOOSE"),k[x.TILDELOOSE]="^"+k[x.LONETILDE]+k[x.XRANGEPLAINLOOSE]+"$",q("LONECARET"),k[x.LONECARET]="(?:\\^)",q("CARETTRIM"),k[x.CARETTRIM]="(\\s*)"+k[x.LONECARET]+"\\s+",F[x.CARETTRIM]=new RegExp(k[x.CARETTRIM],"g"),q("CARET"),k[x.CARET]="^"+k[x.LONECARET]+k[x.XRANGEPLAIN]+"$",q("CARETLOOSE"),k[x.CARETLOOSE]="^"+k[x.LONECARET]+k[x.XRANGEPLAINLOOSE]+"$",q("COMPARATORLOOSE"),k[x.COMPARATORLOOSE]="^"+k[x.GTLT]+"\\s*("+k[x.LOOSEPLAIN]+")$|^$",q("COMPARATOR"),k[x.COMPARATOR]="^"+k[x.GTLT]+"\\s*("+k[x.FULLPLAIN]+")$|^$",q("COMPARATORTRIM"),k[x.COMPARATORTRIM]="(\\s*)"+k[x.GTLT]+"\\s*("+k[x.LOOSEPLAIN]+"|"+k[x.XRANGEPLAIN]+")",F[x.COMPARATORTRIM]=new RegExp(k[x.COMPARATORTRIM],"g"),q("HYPHENRANGE"),k[x.HYPHENRANGE]="^\\s*("+k[x.XRANGEPLAIN]+")\\s+-\\s+("+k[x.XRANGEPLAIN]+")\\s*$",q("HYPHENRANGELOOSE"),k[x.HYPHENRANGELOOSE]="^\\s*("+k[x.XRANGEPLAINLOOSE]+")\\s+-\\s+("+k[x.XRANGEPLAINLOOSE]+")\\s*$",q("STAR"),k[x.STAR]="(<|>)?=?\\s*\\*";for(var V=0;V256||!(ce.loose?F[x.LOOSE]:F[x.FULL]).test(J))return null;try{return new y(J,ce)}catch{return null}}function y(J,ce){if(ce&&E(ce)==="object"||(ce={loose:!!ce,includePrerelease:!1}),J instanceof y){if(J.loose===ce.loose)return J;J=J.version}else if(typeof J!="string")throw new TypeError("Invalid Version: "+J);if(J.length>256)throw new TypeError("version is longer than 256 characters");if(!(this instanceof y))return new y(J,ce);t("SemVer",J,ce),this.options=ce,this.loose=!!ce.loose;var Re=J.trim().match(ce.loose?F[x.LOOSE]:F[x.FULL]);if(!Re)throw new TypeError("Invalid Version: "+J);if(this.raw=J,this.major=+Re[1],this.minor=+Re[2],this.patch=+Re[3],this.major>N||this.major<0)throw new TypeError("Invalid major version");if(this.minor>N||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>N||this.patch<0)throw new TypeError("Invalid patch version");Re[4]?this.prerelease=Re[4].split(".").map(function(le){if(/^[0-9]+$/.test(le)){var He=+le;if(He>=0&&He=0;)typeof this.prerelease[Re]=="number"&&(this.prerelease[Re]++,Re=-2);Re===-1&&this.prerelease.push(0)}ce&&(this.prerelease[0]===ce?isNaN(this.prerelease[1])&&(this.prerelease=[ce,0]):this.prerelease=[ce,0]);break;default:throw new Error("invalid increment argument: "+J)}return this.format(),this.raw=this.version,this},l.inc=function(J,ce,Re,le){typeof Re=="string"&&(le=Re,Re=void 0);try{return new y(J,Re).inc(ce,le).version}catch{return null}},l.diff=function(J,ce){if(he(J,ce))return null;var Re=re(J),le=re(ce),He="";if(Re.prerelease.length||le.prerelease.length){He="pre";var dt="prerelease"}for(var At in Re)if((At==="major"||At==="minor"||At==="patch")&&Re[At]!==le[At])return He+At;return dt},l.compareIdentifiers=De;var me=/^[0-9]+$/;function De(J,ce){var Re=me.test(J),le=me.test(ce);return Re&&le&&(J=+J,ce=+ce),J===ce?0:Re&&!le?-1:le&&!Re?1:J0}function we(J,ce,Re){return ge(J,ce,Re)<0}function he(J,ce,Re){return ge(J,ce,Re)===0}function ve(J,ce,Re){return ge(J,ce,Re)!==0}function ue(J,ce,Re){return ge(J,ce,Re)>=0}function Ae(J,ce,Re){return ge(J,ce,Re)<=0}function ze(J,ce,Re,le){switch(ce){case"===":return E(J)==="object"&&(J=J.version),E(Re)==="object"&&(Re=Re.version),J===Re;case"!==":return E(J)==="object"&&(J=J.version),E(Re)==="object"&&(Re=Re.version),J!==Re;case"":case"=":case"==":return he(J,Re,le);case"!=":return ve(J,Re,le);case">":return ae(J,Re,le);case">=":return ue(J,Re,le);case"<":return we(J,Re,le);case"<=":return Ae(J,Re,le);default:throw new TypeError("Invalid operator: "+ce)}}function We(J,ce){if(ce&&E(ce)==="object"||(ce={loose:!!ce,includePrerelease:!1}),J instanceof We){if(J.loose===!!ce.loose)return J;J=J.value}if(!(this instanceof We))return new We(J,ce);t("comparator",J,ce),this.options=ce,this.loose=!!ce.loose,this.parse(J),this.semver===gt?this.value="":this.value=this.operator+this.semver.version,t("comp",this)}l.rcompareIdentifiers=function(J,ce){return De(ce,J)},l.major=function(J,ce){return new y(J,ce).major},l.minor=function(J,ce){return new y(J,ce).minor},l.patch=function(J,ce){return new y(J,ce).patch},l.compare=ge,l.compareLoose=function(J,ce){return ge(J,ce,!0)},l.compareBuild=function(J,ce,Re){var le=new y(J,Re),He=new y(ce,Re);return le.compare(He)||le.compareBuild(He)},l.rcompare=function(J,ce,Re){return ge(ce,J,Re)},l.sort=function(J,ce){return J.sort(function(Re,le){return l.compareBuild(Re,le,ce)})},l.rsort=function(J,ce){return J.sort(function(Re,le){return l.compareBuild(le,Re,ce)})},l.gt=ae,l.lt=we,l.eq=he,l.neq=ve,l.gte=ue,l.lte=Ae,l.cmp=ze,l.Comparator=We;var gt={};function _t(J,ce){if(ce&&E(ce)==="object"||(ce={loose:!!ce,includePrerelease:!1}),J instanceof _t)return J.loose===!!ce.loose&&J.includePrerelease===!!ce.includePrerelease?J:new _t(J.raw,ce);if(J instanceof We)return new _t(J.value,ce);if(!(this instanceof _t))return new _t(J,ce);if(this.options=ce,this.loose=!!ce.loose,this.includePrerelease=!!ce.includePrerelease,this.raw=J,this.set=J.split(/\s*\|\|\s*/).map(function(Re){return this.parseRange(Re.trim())},this).filter(function(Re){return Re.length}),!this.set.length)throw new TypeError("Invalid SemVer Range: "+J);this.format()}function Qe(J,ce){for(var Re=!0,le=J.slice(),He=le.pop();Re&&le.length;)Re=le.every(function(dt){return He.intersects(dt,ce)}),He=le.pop();return Re}function ot(J){return!J||J.toLowerCase()==="x"||J==="*"}function Ve(J,ce,Re,le,He,dt,At,nn,an,On,lr,ln,Vt){return((ce=ot(Re)?"":ot(le)?">="+Re+".0.0":ot(He)?">="+Re+"."+le+".0":">="+ce)+" "+(nn=ot(an)?"":ot(On)?"<"+(+an+1)+".0.0":ot(lr)?"<"+an+"."+(+On+1)+".0":ln?"<="+an+"."+On+"."+lr+"-"+ln:"<="+nn)).trim()}function Pt(J,ce,Re){for(var le=0;le0){var He=J[le].semver;if(He.major===ce.major&&He.minor===ce.minor&&He.patch===ce.patch)return!0}return!1}return!0}function Jt(J,ce,Re){try{ce=new _t(ce,Re)}catch{return!1}return ce.test(J)}function it(J,ce,Re,le){var He,dt,At,nn,an;switch(J=new y(J,le),ce=new _t(ce,le),Re){case">":He=ae,dt=Ae,At=we,nn=">",an=">=";break;case"<":He=we,dt=ue,At=ae,nn="<",an="<=";break;default:throw new TypeError('Must provide a hilo val of "<" or ">"')}if(Jt(J,ce,le))return!1;for(var On=0;On=0.0.0")),ln=ln||Er,Vt=Vt||Er,He(Er.semver,ln.semver,le)?ln=Er:At(Er.semver,Vt.semver,le)&&(Vt=Er)}),ln.operator===nn||ln.operator===an||(!Vt.operator||Vt.operator===nn)&&dt(J,Vt.semver)||Vt.operator===an&&At(J,Vt.semver))return!1}return!0}We.prototype.parse=function(J){var ce=this.options.loose?F[x.COMPARATORLOOSE]:F[x.COMPARATOR],Re=J.match(ce);if(!Re)throw new TypeError("Invalid comparator: "+J);this.operator=Re[1]!==void 0?Re[1]:"",this.operator==="="&&(this.operator=""),Re[2]?this.semver=new y(Re[2],this.options.loose):this.semver=gt},We.prototype.toString=function(){return this.value},We.prototype.test=function(J){if(t("Comparator.test",J,this.options.loose),this.semver===gt||J===gt)return!0;if(typeof J=="string")try{J=new y(J,this.options)}catch{return!1}return ze(J,this.operator,this.semver,this.options)},We.prototype.intersects=function(J,ce){if(!(J instanceof We))throw new TypeError("a Comparator is required");var Re;if(ce&&E(ce)==="object"||(ce={loose:!!ce,includePrerelease:!1}),this.operator==="")return this.value===""||(Re=new _t(J.value,ce),Jt(this.value,Re,ce));if(J.operator==="")return J.value===""||(Re=new _t(this.value,ce),Jt(J.semver,Re,ce));var le=!(this.operator!==">="&&this.operator!==">"||J.operator!==">="&&J.operator!==">"),He=!(this.operator!=="<="&&this.operator!=="<"||J.operator!=="<="&&J.operator!=="<"),dt=this.semver.version===J.semver.version,At=!(this.operator!==">="&&this.operator!=="<="||J.operator!==">="&&J.operator!=="<="),nn=ze(this.semver,"<",J.semver,ce)&&(this.operator===">="||this.operator===">")&&(J.operator==="<="||J.operator==="<"),an=ze(this.semver,">",J.semver,ce)&&(this.operator==="<="||this.operator==="<")&&(J.operator===">="||J.operator===">");return le||He||dt&&At||nn||an},l.Range=_t,_t.prototype.format=function(){return this.range=this.set.map(function(J){return J.join(" ").trim()}).join("||").trim(),this.range},_t.prototype.toString=function(){return this.range},_t.prototype.parseRange=function(J){var ce=this.options.loose;J=J.trim();var Re=ce?F[x.HYPHENRANGELOOSE]:F[x.HYPHENRANGE];J=J.replace(Re,Ve),t("hyphen replace",J),J=J.replace(F[x.COMPARATORTRIM],"$1$2$3"),t("comparator trim",J,F[x.COMPARATORTRIM]),J=(J=(J=J.replace(F[x.TILDETRIM],"$1~")).replace(F[x.CARETTRIM],"$1^")).split(/\s+/).join(" ");var le=ce?F[x.COMPARATORLOOSE]:F[x.COMPARATOR],He=J.split(" ").map(function(dt){return function(At,nn){return t("comp",At,nn),At=function(an,On){return an.trim().split(/\s+/).map(function(lr){return function(ln,Vt){t("caret",ln,Vt);var Er=Vt.loose?F[x.CARETLOOSE]:F[x.CARET];return ln.replace(Er,function(S,zt,Xn,vr,jr){var fr;return t("caret",ln,S,zt,Xn,vr,jr),ot(zt)?fr="":ot(Xn)?fr=">="+zt+".0.0 <"+(+zt+1)+".0.0":ot(vr)?fr=zt==="0"?">="+zt+"."+Xn+".0 <"+zt+"."+(+Xn+1)+".0":">="+zt+"."+Xn+".0 <"+(+zt+1)+".0.0":jr?(t("replaceCaret pr",jr),fr=zt==="0"?Xn==="0"?">="+zt+"."+Xn+"."+vr+"-"+jr+" <"+zt+"."+Xn+"."+(+vr+1):">="+zt+"."+Xn+"."+vr+"-"+jr+" <"+zt+"."+(+Xn+1)+".0":">="+zt+"."+Xn+"."+vr+"-"+jr+" <"+(+zt+1)+".0.0"):(t("no pr"),fr=zt==="0"?Xn==="0"?">="+zt+"."+Xn+"."+vr+" <"+zt+"."+Xn+"."+(+vr+1):">="+zt+"."+Xn+"."+vr+" <"+zt+"."+(+Xn+1)+".0":">="+zt+"."+Xn+"."+vr+" <"+(+zt+1)+".0.0"),t("caret return",fr),fr})}(lr,On)}).join(" ")}(At,nn),t("caret",At),At=function(an,On){return an.trim().split(/\s+/).map(function(lr){return function(ln,Vt){var Er=Vt.loose?F[x.TILDELOOSE]:F[x.TILDE];return ln.replace(Er,function(S,zt,Xn,vr,jr){var fr;return t("tilde",ln,S,zt,Xn,vr,jr),ot(zt)?fr="":ot(Xn)?fr=">="+zt+".0.0 <"+(+zt+1)+".0.0":ot(vr)?fr=">="+zt+"."+Xn+".0 <"+zt+"."+(+Xn+1)+".0":jr?(t("replaceTilde pr",jr),fr=">="+zt+"."+Xn+"."+vr+"-"+jr+" <"+zt+"."+(+Xn+1)+".0"):fr=">="+zt+"."+Xn+"."+vr+" <"+zt+"."+(+Xn+1)+".0",t("tilde return",fr),fr})}(lr,On)}).join(" ")}(At,nn),t("tildes",At),At=function(an,On){return t("replaceXRanges",an,On),an.split(/\s+/).map(function(lr){return function(ln,Vt){ln=ln.trim();var Er=Vt.loose?F[x.XRANGELOOSE]:F[x.XRANGE];return ln.replace(Er,function(S,zt,Xn,vr,jr,fr){t("xRange",ln,S,zt,Xn,vr,jr,fr);var zr=ot(Xn),Xt=zr||ot(vr),Du=Xt||ot(jr),c0=Du;return zt==="="&&c0&&(zt=""),fr=Vt.includePrerelease?"-0":"",zr?S=zt===">"||zt==="<"?"<0.0.0-0":"*":zt&&c0?(Xt&&(vr=0),jr=0,zt===">"?(zt=">=",Xt?(Xn=+Xn+1,vr=0,jr=0):(vr=+vr+1,jr=0)):zt==="<="&&(zt="<",Xt?Xn=+Xn+1:vr=+vr+1),S=zt+Xn+"."+vr+"."+jr+fr):Xt?S=">="+Xn+".0.0"+fr+" <"+(+Xn+1)+".0.0"+fr:Du&&(S=">="+Xn+"."+vr+".0"+fr+" <"+Xn+"."+(+vr+1)+".0"+fr),t("xRange return",S),S})}(lr,On)}).join(" ")}(At,nn),t("xrange",At),At=function(an,On){return t("replaceStars",an,On),an.trim().replace(F[x.STAR],"")}(At,nn),t("stars",At),At}(dt,this.options)},this).join(" ").split(/\s+/);return this.options.loose&&(He=He.filter(function(dt){return!!dt.match(le)})),He=He.map(function(dt){return new We(dt,this.options)},this)},_t.prototype.intersects=function(J,ce){if(!(J instanceof _t))throw new TypeError("a Range is required");return this.set.some(function(Re){return Qe(Re,ce)&&J.set.some(function(le){return Qe(le,ce)&&Re.every(function(He){return le.every(function(dt){return He.intersects(dt,ce)})})})})},l.toComparators=function(J,ce){return new _t(J,ce).set.map(function(Re){return Re.map(function(le){return le.value}).join(" ").trim().split(" ")})},_t.prototype.test=function(J){if(!J)return!1;if(typeof J=="string")try{J=new y(J,this.options)}catch{return!1}for(var ce=0;ce":dt.prerelease.length===0?dt.patch++:dt.prerelease.push(0),dt.raw=dt.format();case"":case">=":Re&&!ae(Re,dt)||(Re=dt);break;case"<":case"<=":break;default:throw new Error("Unexpected operation: "+He.operator)}});return Re&&J.test(Re)?Re:null},l.validRange=function(J,ce){try{return new _t(J,ce).range||"*"}catch{return null}},l.ltr=function(J,ce,Re){return it(J,ce,"<",Re)},l.gtr=function(J,ce,Re){return it(J,ce,">",Re)},l.outside=it,l.prerelease=function(J,ce){var Re=re(J,ce);return Re&&Re.prerelease.length?Re.prerelease:null},l.intersects=function(J,ce,Re){return J=new _t(J,Re),ce=new _t(ce,Re),J.intersects(ce)},l.coerce=function(J,ce){if(J instanceof y)return J;if(typeof J=="number"&&(J=String(J)),typeof J!="string")return null;var Re=null;if((ce=ce||{}).rtl){for(var le;(le=F[x.COERCERTL].exec(J))&&(!Re||Re.index+Re[0].length!==J.length);)Re&&le.index+le[0].length===Re.index+Re[0].length||(Re=le),F[x.COERCERTL].lastIndex=le.index+le[1].length+le[2].length;F[x.COERCERTL].lastIndex=-1}else Re=J.match(F[x.COERCE]);return Re===null?null:re(Re[2]+"."+(Re[3]||"0")+"."+(Re[4]||"0"),ce)}}).call(this,f(5))},function(o,l){function f(E){return(f=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(E)}var h;h=function(){return this}();try{h=h||new Function("return this")()}catch{(typeof window>"u"?"undefined":f(window))==="object"&&(h=window)}o.exports=h},function(o,l){var f,h,E=o.exports={};function t(){throw new Error("setTimeout has not been defined")}function N(){throw new Error("clearTimeout has not been defined")}function F(De){if(f===setTimeout)return setTimeout(De,0);if((f===t||!f)&&setTimeout)return f=setTimeout,setTimeout(De,0);try{return f(De,0)}catch{try{return f.call(null,De,0)}catch{return f.call(this,De,0)}}}(function(){try{f=typeof setTimeout=="function"?setTimeout:t}catch{f=t}try{h=typeof clearTimeout=="function"?clearTimeout:N}catch{h=N}})();var k,x=[],j=!1,q=-1;function V(){j&&k&&(j=!1,k.length?x=k.concat(x):q=-1,x.length&&re())}function re(){if(!j){var De=F(V);j=!0;for(var ge=x.length;ge;){for(k=x,x=[];++q1)for(var ae=1;aethis[N])return ve(this,this[y].get(Qe)),!1;var it=this[y].get(Qe).value;return this[q]&&(this[V]||this[q](Qe,it.value)),it.now=Pt,it.maxAge=Ve,it.value=ot,this[F]+=Jt-it.length,it.length=Jt,this.get(Qe),he(this),!0}var J=new ue(Qe,ot,Jt,Pt,Ve);return J.length>this[N]?(this[q]&&this[q](Qe,ot),!1):(this[F]+=J.length,this[re].unshift(J),this[y].set(Qe,this[re].head),he(this),!0)}},{key:"has",value:function(Qe){if(!this[y].has(Qe))return!1;var ot=this[y].get(Qe).value;return!we(this,ot)}},{key:"get",value:function(Qe){return ae(this,Qe,!0)}},{key:"peek",value:function(Qe){return ae(this,Qe,!1)}},{key:"pop",value:function(){var Qe=this[re].tail;return Qe?(ve(this,Qe),Qe.value):null}},{key:"del",value:function(Qe){ve(this,this[y].get(Qe))}},{key:"load",value:function(Qe){this.reset();for(var ot=Date.now(),Ve=Qe.length-1;Ve>=0;Ve--){var Pt=Qe[Ve],Jt=Pt.e||0;if(Jt===0)this.set(Pt.k,Pt.v);else{var it=Jt-ot;it>0&&this.set(Pt.k,Pt.v,it)}}}},{key:"prune",value:function(){var Qe=this;this[y].forEach(function(ot,Ve){return ae(Qe,Ve,!1)})}},{key:"max",set:function(Qe){if(typeof Qe!="number"||Qe<0)throw new TypeError("max must be a non-negative number");this[N]=Qe||1/0,he(this)},get:function(){return this[N]}},{key:"allowStale",set:function(Qe){this[x]=!!Qe},get:function(){return this[x]}},{key:"maxAge",set:function(Qe){if(typeof Qe!="number")throw new TypeError("maxAge must be a non-negative number");this[j]=Qe,he(this)},get:function(){return this[j]}},{key:"lengthCalculator",set:function(Qe){var ot=this;typeof Qe!="function"&&(Qe=De),Qe!==this[k]&&(this[k]=Qe,this[F]=0,this[re].forEach(function(Ve){Ve.length=ot[k](Ve.value,Ve.key),ot[F]+=Ve.length})),he(this)},get:function(){return this[k]}},{key:"length",get:function(){return this[F]}},{key:"itemCount",get:function(){return this[re].length}}])&&E(We.prototype,gt),_t&&E(We,_t),ze}(),ae=function(ze,We,gt){var _t=ze[y].get(We);if(_t){var Qe=_t.value;if(we(ze,Qe)){if(ve(ze,_t),!ze[x])return}else gt&&(ze[me]&&(_t.value.now=Date.now()),ze[re].unshiftNode(_t));return Qe.value}},we=function(ze,We){if(!We||!We.maxAge&&!ze[j])return!1;var gt=Date.now()-We.now;return We.maxAge?gt>We.maxAge:ze[j]&>>ze[j]},he=function(ze){if(ze[F]>ze[N])for(var We=ze[re].tail;ze[F]>ze[N]&&We!==null;){var gt=We.prev;ve(ze,We),We=gt}},ve=function(ze,We){if(We){var gt=We.value;ze[q]&&ze[q](gt.key,gt.value),ze[F]-=gt.length,ze[y].delete(gt.key),ze[re].removeNode(We)}},ue=function ze(We,gt,_t,Qe,ot){h(this,ze),this.key=We,this.value=gt,this.length=_t,this.now=Qe,this.maxAge=ot||0},Ae=function(ze,We,gt,_t){var Qe=gt.value;we(ze,Qe)&&(ve(ze,gt),ze[x]||(Qe=void 0)),Qe&&We.call(_t,Qe.value,Qe.key,ze)};o.exports=ge},function(o,l,f){(function(h){function E(t){return(E=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(N){return typeof N}:function(N){return N&&typeof Symbol=="function"&&N.constructor===Symbol&&N!==Symbol.prototype?"symbol":typeof N})(t)}o.exports=function(){if(typeof document>"u"||!document.addEventListener)return null;var t,N,F,k={};return k.copy=function(){var x=!1,j=null,q=!1;function V(){x=!1,j=null,q&&window.getSelection().removeAllRanges(),q=!1}return document.addEventListener("copy",function(re){if(x){for(var y in j)re.clipboardData.setData(y,j[y]);re.preventDefault()}}),function(re){return new Promise(function(y,me){x=!0,typeof re=="string"?j={"text/plain":re}:re instanceof Node?j={"text/html":new XMLSerializer().serializeToString(re)}:re instanceof Object?j=re:me("Invalid data type. Must be string, DOM node, or an object mapping MIME types to strings."),function De(ge){try{if(document.execCommand("copy"))V(),y();else{if(ge)throw V(),new Error("Unable to copy. Perhaps it's not available in your browser?");(function(){var ae=document.getSelection();if(!document.queryCommandEnabled("copy")&&ae.isCollapsed){var we=document.createRange();we.selectNodeContents(document.body),ae.removeAllRanges(),ae.addRange(we),q=!0}})(),De(!0)}}catch(ae){V(),me(ae)}}(!1)})}}(),k.paste=(F=!1,document.addEventListener("paste",function(x){if(F){F=!1,x.preventDefault();var j=t;t=null,j(x.clipboardData.getData(N))}}),function(x){return new Promise(function(j,q){F=!0,t=j,N=x||"text/plain";try{document.execCommand("paste")||(F=!1,q(new Error("Unable to paste. Pasting only works in Internet Explorer at the moment.")))}catch(V){F=!1,q(new Error(V))}})}),typeof ClipboardEvent>"u"&&window.clipboardData!==void 0&&window.clipboardData.setData!==void 0&&(function(x){function j(he,ve){return function(){he.apply(ve,arguments)}}function q(he){if(E(this)!="object")throw new TypeError("Promises must be constructed via new");if(typeof he!="function")throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],ge(he,j(re,this),j(y,this))}function V(he){var ve=this;return this._state===null?void this._deferreds.push(he):void ae(function(){var ue=ve._state?he.onFulfilled:he.onRejected;if(ue!==null){var Ae;try{Ae=ue(ve._value)}catch(ze){return void he.reject(ze)}he.resolve(Ae)}else(ve._state?he.resolve:he.reject)(ve._value)})}function re(he){try{if(he===this)throw new TypeError("A promise cannot be resolved with itself.");if(he&&(E(he)=="object"||typeof he=="function")){var ve=he.then;if(typeof ve=="function")return void ge(j(ve,he),j(re,this),j(y,this))}this._state=!0,this._value=he,me.call(this)}catch(ue){y.call(this,ue)}}function y(he){this._state=!1,this._value=he,me.call(this)}function me(){for(var he=0,ve=this._deferreds.length;ve>he;he++)V.call(this,this._deferreds[he]);this._deferreds=null}function De(he,ve,ue,Ae){this.onFulfilled=typeof he=="function"?he:null,this.onRejected=typeof ve=="function"?ve:null,this.resolve=ue,this.reject=Ae}function ge(he,ve,ue){var Ae=!1;try{he(function(ze){Ae||(Ae=!0,ve(ze))},function(ze){Ae||(Ae=!0,ue(ze))})}catch(ze){if(Ae)return;Ae=!0,ue(ze)}}var ae=q.immediateFn||typeof h=="function"&&h||function(he){setTimeout(he,1)},we=Array.isArray||function(he){return Object.prototype.toString.call(he)==="[object Array]"};q.prototype.catch=function(he){return this.then(null,he)},q.prototype.then=function(he,ve){var ue=this;return new q(function(Ae,ze){V.call(ue,new De(he,ve,Ae,ze))})},q.all=function(){var he=Array.prototype.slice.call(arguments.length===1&&we(arguments[0])?arguments[0]:arguments);return new q(function(ve,ue){function Ae(gt,_t){try{if(_t&&(E(_t)=="object"||typeof _t=="function")){var Qe=_t.then;if(typeof Qe=="function")return void Qe.call(_t,function(ot){Ae(gt,ot)},ue)}he[gt]=_t,--ze==0&&ve(he)}catch(ot){ue(ot)}}if(he.length===0)return ve([]);for(var ze=he.length,We=0;WeAe;Ae++)he[Ae].then(ve,ue)})},o.exports?o.exports=q:x.Promise||(x.Promise=q)}(this),k.copy=function(x){return new Promise(function(j,q){if(typeof x!="string"&&!("text/plain"in x))throw new Error("You must provide a text/plain type.");var V=typeof x=="string"?x:x["text/plain"];window.clipboardData.setData("Text",V)?j():q(new Error("Copying was rejected."))})},k.paste=function(){return new Promise(function(x,j){var q=window.clipboardData.getData("Text");q?x(q):j(new Error("Pasting was rejected."))})}),k}()}).call(this,f(13).setImmediate)},function(o,l,f){"use strict";o.exports=f(15)},function(o,l,f){"use strict";f.r(l),l.default=`:root { + /** + * IMPORTANT: When new theme variables are added below\u2013 also add them to SettingsContext updateThemeVariables() + */ + + /* Light theme */ + --light-color-attribute-name: #ef6632; + --light-color-attribute-name-not-editable: #23272f; + --light-color-attribute-name-inverted: rgba(255, 255, 255, 0.7); + --light-color-attribute-value: #1a1aa6; + --light-color-attribute-value-inverted: #ffffff; + --light-color-attribute-editable-value: #1a1aa6; + --light-color-background: #ffffff; + --light-color-background-hover: rgba(0, 136, 250, 0.1); + --light-color-background-inactive: #e5e5e5; + --light-color-background-invalid: #fff0f0; + --light-color-background-selected: #0088fa; + --light-color-button-background: #ffffff; + --light-color-button-background-focus: #ededed; + --light-color-button: #5f6673; + --light-color-button-disabled: #cfd1d5; + --light-color-button-active: #0088fa; + --light-color-button-focus: #23272f; + --light-color-button-hover: #23272f; + --light-color-border: #eeeeee; + --light-color-commit-did-not-render-fill: #cfd1d5; + --light-color-commit-did-not-render-fill-text: #000000; + --light-color-commit-did-not-render-pattern: #cfd1d5; + --light-color-commit-did-not-render-pattern-text: #333333; + --light-color-commit-gradient-0: #37afa9; + --light-color-commit-gradient-1: #63b19e; + --light-color-commit-gradient-2: #80b393; + --light-color-commit-gradient-3: #97b488; + --light-color-commit-gradient-4: #abb67d; + --light-color-commit-gradient-5: #beb771; + --light-color-commit-gradient-6: #cfb965; + --light-color-commit-gradient-7: #dfba57; + --light-color-commit-gradient-8: #efbb49; + --light-color-commit-gradient-9: #febc38; + --light-color-commit-gradient-text: #000000; + --light-color-component-name: #6a51b2; + --light-color-component-name-inverted: #ffffff; + --light-color-component-badge-background: rgba(0, 0, 0, 0.1); + --light-color-component-badge-background-inverted: rgba(255, 255, 255, 0.25); + --light-color-component-badge-count: #777d88; + --light-color-component-badge-count-inverted: rgba(255, 255, 255, 0.7); + --light-color-context-background: rgba(0,0,0,.9); + --light-color-context-background-hover: rgba(255, 255, 255, 0.1); + --light-color-context-background-selected: #178fb9; + --light-color-context-border: #3d424a; + --light-color-context-text: #ffffff; + --light-color-context-text-selected: #ffffff; + --light-color-dim: #777d88; + --light-color-dimmer: #cfd1d5; + --light-color-dimmest: #eff0f1; + --light-color-error-background: hsl(0, 100%, 97%); + --light-color-error-border: hsl(0, 100%, 92%); + --light-color-error-text: #ff0000; + --light-color-expand-collapse-toggle: #777d88; + --light-color-link: #0000ff; + --light-color-modal-background: rgba(255, 255, 255, 0.75); + --light-color-record-active: #fc3a4b; + --light-color-record-hover: #3578e5; + --light-color-record-inactive: #0088fa; + --light-color-scroll-thumb: #c2c2c2; + --light-color-scroll-track: #fafafa; + --light-color-search-match: yellow; + --light-color-search-match-current: #f7923b; + --light-color-selected-tree-highlight-active: rgba(0, 136, 250, 0.1); + --light-color-selected-tree-highlight-inactive: rgba(0, 0, 0, 0.05); + --light-color-shadow: rgba(0, 0, 0, 0.25); + --light-color-tab-selected-border: #0088fa; + --light-color-text: #000000; + --light-color-text-invalid: #ff0000; + --light-color-text-selected: #ffffff; + --light-color-toggle-background-invalid: #fc3a4b; + --light-color-toggle-background-on: #0088fa; + --light-color-toggle-background-off: #cfd1d5; + --light-color-toggle-text: #ffffff; + --light-color-tooltip-background: rgba(0, 0, 0, 0.9); + --light-color-tooltip-text: #ffffff; + + /* Dark theme */ + --dark-color-attribute-name: #9d87d2; + --dark-color-attribute-name-not-editable: #ededed; + --dark-color-attribute-name-inverted: #282828; + --dark-color-attribute-value: #cedae0; + --dark-color-attribute-value-inverted: #ffffff; + --dark-color-attribute-editable-value: yellow; + --dark-color-background: #282c34; + --dark-color-background-hover: rgba(255, 255, 255, 0.1); + --dark-color-background-inactive: #3d424a; + --dark-color-background-invalid: #5c0000; + --dark-color-background-selected: #178fb9; + --dark-color-button-background: #282c34; + --dark-color-button-background-focus: #3d424a; + --dark-color-button: #afb3b9; + --dark-color-button-active: #61dafb; + --dark-color-button-disabled: #4f5766; + --dark-color-button-focus: #a2e9fc; + --dark-color-button-hover: #ededed; + --dark-color-border: #3d424a; + --dark-color-commit-did-not-render-fill: #777d88; + --dark-color-commit-did-not-render-fill-text: #000000; + --dark-color-commit-did-not-render-pattern: #666c77; + --dark-color-commit-did-not-render-pattern-text: #ffffff; + --dark-color-commit-gradient-0: #37afa9; + --dark-color-commit-gradient-1: #63b19e; + --dark-color-commit-gradient-2: #80b393; + --dark-color-commit-gradient-3: #97b488; + --dark-color-commit-gradient-4: #abb67d; + --dark-color-commit-gradient-5: #beb771; + --dark-color-commit-gradient-6: #cfb965; + --dark-color-commit-gradient-7: #dfba57; + --dark-color-commit-gradient-8: #efbb49; + --dark-color-commit-gradient-9: #febc38; + --dark-color-commit-gradient-text: #000000; + --dark-color-component-name: #61dafb; + --dark-color-component-name-inverted: #282828; + --dark-color-component-badge-background: rgba(255, 255, 255, 0.25); + --dark-color-component-badge-background-inverted: rgba(0, 0, 0, 0.25); + --dark-color-component-badge-count: #8f949d; + --dark-color-component-badge-count-inverted: rgba(255, 255, 255, 0.7); + --dark-color-context-background: rgba(255,255,255,.9); + --dark-color-context-background-hover: rgba(0, 136, 250, 0.1); + --dark-color-context-background-selected: #0088fa; + --dark-color-context-border: #eeeeee; + --dark-color-context-text: #000000; + --dark-color-context-text-selected: #ffffff; + --dark-color-dim: #8f949d; + --dark-color-dimmer: #777d88; + --dark-color-dimmest: #4f5766; + --dark-color-error-background: #200; + --dark-color-error-border: #900; + --dark-color-error-text: #f55; + --dark-color-expand-collapse-toggle: #8f949d; + --dark-color-link: #61dafb; + --dark-color-modal-background: rgba(0, 0, 0, 0.75); + --dark-color-record-active: #fc3a4b; + --dark-color-record-hover: #a2e9fc; + --dark-color-record-inactive: #61dafb; + --dark-color-scroll-thumb: #afb3b9; + --dark-color-scroll-track: #313640; + --dark-color-search-match: yellow; + --dark-color-search-match-current: #f7923b; + --dark-color-selected-tree-highlight-active: rgba(23, 143, 185, 0.15); + --dark-color-selected-tree-highlight-inactive: rgba(255, 255, 255, 0.05); + --dark-color-shadow: rgba(0, 0, 0, 0.5); + --dark-color-tab-selected-border: #178fb9; + --dark-color-text: #ffffff; + --dark-color-text-invalid: #ff8080; + --dark-color-text-selected: #ffffff; + --dark-color-toggle-background-invalid: #fc3a4b; + --dark-color-toggle-background-on: #178fb9; + --dark-color-toggle-background-off: #777d88; + --dark-color-toggle-text: #ffffff; + --dark-color-tooltip-background: rgba(255, 255, 255, 0.9); + --dark-color-tooltip-text: #000000; + + /* Font smoothing */ + --light-font-smoothing: auto; + --dark-font-smoothing: antialiased; + --font-smoothing: auto; + + /* Compact density */ + --compact-font-size-monospace-small: 9px; + --compact-font-size-monospace-normal: 11px; + --compact-font-size-monospace-large: 15px; + --compact-font-size-sans-small: 10px; + --compact-font-size-sans-normal: 12px; + --compact-font-size-sans-large: 14px; + --compact-line-height-data: 18px; + --compact-root-font-size: 16px; + + /* Comfortable density */ + --comfortable-font-size-monospace-small: 10px; + --comfortable-font-size-monospace-normal: 13px; + --comfortable-font-size-monospace-large: 17px; + --comfortable-font-size-sans-small: 12px; + --comfortable-font-size-sans-normal: 14px; + --comfortable-font-size-sans-large: 16px; + --comfortable-line-height-data: 22px; + --comfortable-root-font-size: 20px; + + /* GitHub.com system fonts */ + --font-family-monospace: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, + Courier, monospace; + --font-family-sans: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, + Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol; + + /* Constant values shared between JS and CSS */ + --interaction-commit-size: 10px; + --interaction-label-width: 200px; +} +`},function(o,l,f){"use strict";function h(k){var x=this;if(x instanceof h||(x=new h),x.tail=null,x.head=null,x.length=0,k&&typeof k.forEach=="function")k.forEach(function(V){x.push(V)});else if(arguments.length>0)for(var j=0,q=arguments.length;j1)j=x;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");q=this.head.next,j=this.head.value}for(var V=0;q!==null;V++)j=k(j,q.value,V),q=q.next;return j},h.prototype.reduceReverse=function(k,x){var j,q=this.tail;if(arguments.length>1)j=x;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");q=this.tail.prev,j=this.tail.value}for(var V=this.length-1;q!==null;V--)j=k(j,q.value,V),q=q.prev;return j},h.prototype.toArray=function(){for(var k=new Array(this.length),x=0,j=this.head;j!==null;x++)k[x]=j.value,j=j.next;return k},h.prototype.toArrayReverse=function(){for(var k=new Array(this.length),x=0,j=this.tail;j!==null;x++)k[x]=j.value,j=j.prev;return k},h.prototype.slice=function(k,x){(x=x||this.length)<0&&(x+=this.length),(k=k||0)<0&&(k+=this.length);var j=new h;if(xthis.length&&(x=this.length);for(var q=0,V=this.head;V!==null&&qthis.length&&(x=this.length);for(var q=this.length,V=this.tail;V!==null&&q>x;q--)V=V.prev;for(;V!==null&&q>k;q--,V=V.prev)j.push(V.value);return j},h.prototype.splice=function(k,x){k>this.length&&(k=this.length-1),k<0&&(k=this.length+k);for(var j=0,q=this.head;q!==null&&j=0&&(F._idleTimeoutId=setTimeout(function(){F._onTimeout&&F._onTimeout()},k))},f(14),l.setImmediate=typeof self<"u"&&self.setImmediate||h!==void 0&&h.setImmediate||this&&this.setImmediate,l.clearImmediate=typeof self<"u"&&self.clearImmediate||h!==void 0&&h.clearImmediate||this&&this.clearImmediate}).call(this,f(4))},function(o,l,f){(function(h,E){(function(t,N){"use strict";if(!t.setImmediate){var F,k,x,j,q,V=1,re={},y=!1,me=t.document,De=Object.getPrototypeOf&&Object.getPrototypeOf(t);De=De&&De.setTimeout?De:t,{}.toString.call(t.process)==="[object process]"?F=function(we){E.nextTick(function(){ae(we)})}:function(){if(t.postMessage&&!t.importScripts){var we=!0,he=t.onmessage;return t.onmessage=function(){we=!1},t.postMessage("","*"),t.onmessage=he,we}}()?(j="setImmediate$"+Math.random()+"$",q=function(we){we.source===t&&typeof we.data=="string"&&we.data.indexOf(j)===0&&ae(+we.data.slice(j.length))},t.addEventListener?t.addEventListener("message",q,!1):t.attachEvent("onmessage",q),F=function(we){t.postMessage(j+we,"*")}):t.MessageChannel?((x=new MessageChannel).port1.onmessage=function(we){ae(we.data)},F=function(we){x.port2.postMessage(we)}):me&&"onreadystatechange"in me.createElement("script")?(k=me.documentElement,F=function(we){var he=me.createElement("script");he.onreadystatechange=function(){ae(we),he.onreadystatechange=null,k.removeChild(he),he=null},k.appendChild(he)}):F=function(we){setTimeout(ae,0,we)},De.setImmediate=function(we){typeof we!="function"&&(we=new Function(""+we));for(var he=new Array(arguments.length-1),ve=0;ve"u"?h===void 0?this:h:self)}).call(this,f(4),f(5))},function(o,l,f){"use strict";function h(ue){return(h=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(Ae){return typeof Ae}:function(Ae){return Ae&&typeof Symbol=="function"&&Ae.constructor===Symbol&&Ae!==Symbol.prototype?"symbol":typeof Ae})(ue)}var E=f(1),t=f(16),N=f(18).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,F=60128;if(typeof Symbol=="function"&&Symbol.for){var k=Symbol.for;F=k("react.opaque.id")}var x=[],j=null,q=null;function V(){if(j===null){var ue=new Map;try{me.useContext({_currentValue:null}),me.useState(null),me.useReducer(function(gt){return gt},null),me.useRef(null),me.useLayoutEffect(function(){}),me.useEffect(function(){}),me.useImperativeHandle(void 0,function(){return null}),me.useDebugValue(null),me.useCallback(function(){}),me.useMemo(function(){return null})}finally{var Ae=x;x=[]}for(var ze=0;zece;ce++)if((J=ge(it,Pt,ce))!==-1){De=ce,Pt=J;break e}Pt=-1}}e:{if(it=Jt,(J=V().get(Ve.primitive))!==void 0){for(ce=0;cePt-it?null:Jt.slice(it,Pt-1))!==null){if(Pt=0,We!==null){for(;PtPt;We--)gt=Qe.pop()}for(We=Jt.length-Pt-1;1<=We;We--)Pt=[],gt.push({id:null,isStateEditable:!1,name:we(Jt[We-1].functionName),value:void 0,subHooks:Pt}),Qe.push(gt),gt=Pt;We=Jt}Pt=(Jt=Ve.primitive)==="Context"||Jt==="DebugValue"?null:_t++,gt.push({id:Pt,isStateEditable:Jt==="Reducer"||Jt==="State",name:Jt,value:Ve.value,subHooks:[]})}return function Re(le,He){for(var dt=[],At=0;At-1&&(re=re.replace(/eval code/g,"eval").replace(/(\(eval at [^()]*)|(\),.*$)/g,""));var y=re.replace(/^\s+/,"").replace(/\(eval code/g,"("),me=y.match(/ (\((.+):(\d+):(\d+)\)$)/),De=(y=me?y.replace(me[0],""):y).split(/\s+/).slice(1),ge=this.extractLocation(me?me[1]:De.pop()),ae=De.join(" ")||void 0,we=["eval",""].indexOf(ge[0])>-1?void 0:ge[0];return new k({functionName:ae,fileName:we,lineNumber:ge[1],columnNumber:ge[2],source:re})},this)},parseFFOrSafari:function(V){return V.stack.split(` +`).filter(function(re){return!re.match(q)},this).map(function(re){if(re.indexOf(" > eval")>-1&&(re=re.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,":$1")),re.indexOf("@")===-1&&re.indexOf(":")===-1)return new k({functionName:re});var y=/((.*".+"[^@]*)?[^@]*)(?:@)/,me=re.match(y),De=me&&me[1]?me[1]:void 0,ge=this.extractLocation(re.replace(y,""));return new k({functionName:De,fileName:ge[0],lineNumber:ge[1],columnNumber:ge[2],source:re})},this)},parseOpera:function(V){return!V.stacktrace||V.message.indexOf(` +`)>-1&&V.message.split(` +`).length>V.stacktrace.split(` +`).length?this.parseOpera9(V):V.stack?this.parseOpera11(V):this.parseOpera10(V)},parseOpera9:function(V){for(var re=/Line (\d+).*script (?:in )?(\S+)/i,y=V.message.split(` +`),me=[],De=2,ge=y.length;De/,"$2").replace(/\([^)]*\)/g,"")||void 0;ge.match(/\(([^)]*)\)/)&&(y=ge.replace(/^[^(]+\(([^)]*)\)$/,"$1"));var we=y===void 0||y==="[arguments not available]"?void 0:y.split(",");return new k({functionName:ae,args:we,fileName:De[0],lineNumber:De[1],columnNumber:De[2],source:re})},this)}}})=="function"?h.apply(l,E):h)===void 0||(o.exports=t)})()},function(o,l,f){var h,E,t;(function(N,F){"use strict";E=[],(t=typeof(h=function(){function k(ae){return ae.charAt(0).toUpperCase()+ae.substring(1)}function x(ae){return function(){return this[ae]}}var j=["isConstructor","isEval","isNative","isToplevel"],q=["columnNumber","lineNumber"],V=["fileName","functionName","source"],re=j.concat(q,V,["args"]);function y(ae){if(ae)for(var we=0;we1?Oe-1:0),Ne=1;Ne=0&&Oe.splice($,1)}}}])&&h(H.prototype,Y),ee&&h(H,ee),U}(),t=f(2),N=f.n(t);try{var F=f(9).default,k=function(U){var H=new RegExp("".concat(U,": ([0-9]+)")),Y=F.match(H);return parseInt(Y[1],10)};k("comfortable-line-height-data"),k("compact-line-height-data")}catch{}function x(U){try{return sessionStorage.getItem(U)}catch{return null}}function j(U){try{sessionStorage.removeItem(U)}catch{}}function q(U,H){try{return sessionStorage.setItem(U,H)}catch{}}var V=function(U,H){return U===H},re=f(1),y=f.n(re);function me(U){return U.ownerDocument?U.ownerDocument.defaultView:null}function De(U){var H=me(U);return H?H.frameElement:null}function ge(U){var H=he(U);return ae([U.getBoundingClientRect(),{top:H.borderTop,left:H.borderLeft,bottom:H.borderBottom,right:H.borderRight,width:0,height:0}])}function ae(U){return U.reduce(function(H,Y){return H==null?Y:{top:H.top+Y.top,left:H.left+Y.left,width:H.width,height:H.height,bottom:H.bottom+Y.bottom,right:H.right+Y.right}})}function we(U,H){var Y=De(U);if(Y&&Y!==H){for(var ee=[U.getBoundingClientRect()],Ce=Y,_e=!1;Ce;){var Oe=ge(Ce);if(ee.push(Oe),Ce=De(Ce),_e)break;Ce&&me(Ce)===H&&(_e=!0)}return ae(ee)}return U.getBoundingClientRect()}function he(U){var H=window.getComputedStyle(U);return{borderLeft:parseInt(H.borderLeftWidth,10),borderRight:parseInt(H.borderRightWidth,10),borderTop:parseInt(H.borderTopWidth,10),borderBottom:parseInt(H.borderBottomWidth,10),marginLeft:parseInt(H.marginLeft,10),marginRight:parseInt(H.marginRight,10),marginTop:parseInt(H.marginTop,10),marginBottom:parseInt(H.marginBottom,10),paddingLeft:parseInt(H.paddingLeft,10),paddingRight:parseInt(H.paddingRight,10),paddingTop:parseInt(H.paddingTop,10),paddingBottom:parseInt(H.paddingBottom,10)}}function ve(U,H){var Y;if(typeof Symbol>"u"||U[Symbol.iterator]==null){if(Array.isArray(U)||(Y=function(Ne,Je){if(!!Ne){if(typeof Ne=="string")return ue(Ne,Je);var vt=Object.prototype.toString.call(Ne).slice(8,-1);if(vt==="Object"&&Ne.constructor&&(vt=Ne.constructor.name),vt==="Map"||vt==="Set")return Array.from(Ne);if(vt==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(vt))return ue(Ne,Je)}}(U))||H&&U&&typeof U.length=="number"){Y&&(U=Y);var ee=0,Ce=function(){};return{s:Ce,n:function(){return ee>=U.length?{done:!0}:{done:!1,value:U[ee++]}},e:function(Ne){throw Ne},f:Ce}}throw new TypeError(`Invalid attempt to iterate non-iterable instance. +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var _e,Oe=!0,$=!1;return{s:function(){Y=U[Symbol.iterator]()},n:function(){var Ne=Y.next();return Oe=Ne.done,Ne},e:function(Ne){$=!0,_e=Ne},f:function(){try{Oe||Y.return==null||Y.return()}finally{if($)throw _e}}}}function ue(U,H){(H==null||H>U.length)&&(H=U.length);for(var Y=0,ee=new Array(H);YOe.left+Oe.width&&(oe=Oe.left+Oe.width-vt-5),{style:{top:Ne+="px",left:oe+="px"}}}(H,Y,{width:ee.width,height:ee.height});y()(this.tip.style,Ce.style)}}]),U}(),Qe=function(){function U(){Ae(this,U);var H=window.__REACT_DEVTOOLS_TARGET_WINDOW__||window;this.window=H;var Y=window.__REACT_DEVTOOLS_TARGET_WINDOW__||window;this.tipBoundsWindow=Y;var ee=H.document;this.container=ee.createElement("div"),this.container.style.zIndex="10000000",this.tip=new _t(ee,this.container),this.rects=[],ee.body.appendChild(this.container)}return We(U,[{key:"remove",value:function(){this.tip.remove(),this.rects.forEach(function(H){H.remove()}),this.rects.length=0,this.container.parentNode&&this.container.parentNode.removeChild(this.container)}},{key:"inspect",value:function(H,Y){for(var ee=this,Ce=H.filter(function(xt){return xt.nodeType===Node.ELEMENT_NODE});this.rects.length>Ce.length;)this.rects.pop().remove();if(Ce.length!==0){for(;this.rects.length1&&arguments[1]!==void 0?arguments[1]:V,rt=void 0,xt=[],kt=void 0,bt=!1,sn=function(Ft,Dn){return qe(Ft,xt[Dn])},rn=function(){for(var Ft=arguments.length,Dn=Array(Ft),dr=0;dr"u"?"undefined":At(performance))==="object"&&typeof performance.now=="function"?function(){return performance.now()}:function(){return Date.now()},an=new Map,On=null,lr=!1,ln=null;function Vt(U){(lr=U)||(an.clear(),On!==null&&(cancelAnimationFrame(On),On=null),ln!==null&&(clearTimeout(ln),ln=null),He!==null&&(He.parentNode!=null&&He.parentNode.removeChild(He),He=null))}function Er(U){lr&&(U.forEach(function(H){var Y=an.get(H),ee=nn(),Ce=Y!=null?Y.lastMeasuredAt:0,_e=Y!=null?Y.rect:null;(_e===null||Ce+2505&&arguments[5]!==void 0?arguments[5]:0,$=Mo(U);switch($){case"html_element":return H.push(ee),{inspectable:!1,preview_short:ki(U,!1),preview_long:ki(U,!0),name:U.tagName,type:$};case"function":return H.push(ee),{inspectable:!1,preview_short:ki(U,!1),preview_long:ki(U,!0),name:typeof U.name!="function"&&U.name?U.name:"function",type:$};case"string":return U.length<=500?U:U.slice(0,500)+"...";case"bigint":case"symbol":return H.push(ee),{inspectable:!1,preview_short:ki(U,!1),preview_long:ki(U,!0),name:U.toString(),type:$};case"react_element":return H.push(ee),{inspectable:!1,preview_short:ki(U,!1),preview_long:ki(U,!0),name:F0(U)||"Unknown",type:$};case"array_buffer":case"data_view":return H.push(ee),{inspectable:!1,preview_short:ki(U,!1),preview_long:ki(U,!0),name:$==="data_view"?"DataView":"ArrayBuffer",size:U.byteLength,type:$};case"array":return _e=Ce(ee),Oe>=2&&!_e?c0($,!0,U,H,ee):U.map(function(vt,oe){return Ao(vt,H,Y,ee.concat([oe]),Ce,_e?1:Oe+1)});case"html_all_collection":case"typed_array":case"iterator":if(_e=Ce(ee),Oe>=2&&!_e)return c0($,!0,U,H,ee);var Ne={unserializable:!0,type:$,readonly:!0,size:$==="typed_array"?U.length:void 0,preview_short:ki(U,!1),preview_long:ki(U,!0),name:U.constructor&&U.constructor.name!=="Object"?U.constructor.name:""};return Xt(U[Symbol.iterator])&&Array.from(U).forEach(function(vt,oe){return Ne[oe]=Ao(vt,H,Y,ee.concat([oe]),Ce,_e?1:Oe+1)}),Y.push(ee),Ne;case"opaque_iterator":return H.push(ee),{inspectable:!1,preview_short:ki(U,!1),preview_long:ki(U,!0),name:U[Symbol.toStringTag],type:$};case"date":case"regexp":return H.push(ee),{inspectable:!1,preview_short:ki(U,!1),preview_long:ki(U,!0),name:U.toString(),type:$};case"object":if(_e=Ce(ee),Oe>=2&&!_e)return c0($,!0,U,H,ee);var Je={};return lu(U).forEach(function(vt){var oe=vt.toString();Je[oe]=Ao(U[vt],H,Y,ee.concat([oe]),Ce,_e?1:Oe+1)}),Je;case"infinity":case"nan":case"undefined":return H.push(ee),{type:$};default:return U}}function Jo(U){return(Jo=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(H){return typeof H}:function(H){return H&&typeof Symbol=="function"&&H.constructor===Symbol&&H!==Symbol.prototype?"symbol":typeof H})(U)}function Fs(U){return function(H){if(Array.isArray(H))return Zo(H)}(U)||function(H){if(typeof Symbol<"u"&&Symbol.iterator in Object(H))return Array.from(H)}(U)||function(H,Y){if(!!H){if(typeof H=="string")return Zo(H,Y);var ee=Object.prototype.toString.call(H).slice(8,-1);if(ee==="Object"&&H.constructor&&(ee=H.constructor.name),ee==="Map"||ee==="Set")return Array.from(H);if(ee==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(ee))return Zo(H,Y)}}(U)||function(){throw new TypeError(`Invalid attempt to spread non-iterable instance. +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}()}function Zo(U,H){(H==null||H>U.length)&&(H=U.length);for(var Y=0,ee=new Array(H);YH.toString()?1:H.toString()>U.toString()?-1:0}function lu(U){for(var H=[],Y=U,ee=function(){var Ce=[].concat(Fs(Object.keys(Y)),Fs(Object.getOwnPropertySymbols(Y))),_e=Object.getOwnPropertyDescriptors(Y);Ce.forEach(function(Oe){_e[Oe].enumerable&&H.push(Oe)}),Y=Object.getPrototypeOf(Y)};Y!=null;)ee();return H}function vi(U){var H=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"Anonymous",Y=$o.get(U);if(Y!=null)return Y;var ee=H;return typeof U.displayName=="string"?ee=U.displayName:typeof U.name=="string"&&U.name!==""&&(ee=U.name),$o.set(U,ee),ee}var Dr=0;function el(){return++Dr}function Y0(U){var H=qt.get(U);if(H!==void 0)return H;for(var Y=new Array(U.length),ee=0;ee1&&arguments[1]!==void 0?arguments[1]:50;return U.length>H?U.substr(0,H)+"\u2026":U}function ki(U,H){if(U!=null&&hasOwnProperty.call(U,Du.type))return H?U[Du.preview_long]:U[Du.preview_short];switch(Mo(U)){case"html_element":return"<".concat(su(U.tagName.toLowerCase())," />");case"function":return su("\u0192 ".concat(typeof U.name=="function"?"":U.name,"() {}"));case"string":return'"'.concat(U,'"');case"bigint":return su(U.toString()+"n");case"regexp":case"symbol":return su(U.toString());case"react_element":return"<".concat(su(F0(U)||"Unknown")," />");case"array_buffer":return"ArrayBuffer(".concat(U.byteLength,")");case"data_view":return"DataView(".concat(U.buffer.byteLength,")");case"array":if(H){for(var Y="",ee=0;ee0&&(Y+=", "),!((Y+=ki(U[ee],!1)).length>50));ee++);return"[".concat(su(Y),"]")}var Ce=hasOwnProperty.call(U,Du.size)?U[Du.size]:U.length;return"Array(".concat(Ce,")");case"typed_array":var _e="".concat(U.constructor.name,"(").concat(U.length,")");if(H){for(var Oe="",$=0;$0&&(Oe+=", "),!((Oe+=U[$]).length>50));$++);return"".concat(_e," [").concat(su(Oe),"]")}return _e;case"iterator":var Ne=U.constructor.name;if(H){for(var Je=Array.from(U),vt="",oe=0;oe0&&(vt+=", "),Array.isArray(qe)){var rt=ki(qe[0],!0),xt=ki(qe[1],!1);vt+="".concat(rt," => ").concat(xt)}else vt+=ki(qe,!1);if(vt.length>50)break}return"".concat(Ne,"(").concat(U.size,") {").concat(su(vt),"}")}return"".concat(Ne,"(").concat(U.size,")");case"opaque_iterator":return U[Symbol.toStringTag];case"date":return U.toString();case"object":if(H){for(var kt=lu(U).sort(xi),bt="",sn=0;sn0&&(bt+=", "),(bt+="".concat(rn.toString(),": ").concat(ki(U[rn],!1))).length>50)break}return"{".concat(su(bt),"}")}return"{\u2026}";case"boolean":case"number":case"infinity":case"nan":case"null":case"undefined":return U;default:try{return su(""+U)}catch{return"unserializable"}}}var Ps=f(7);function Kl(U){return(Kl=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(H){return typeof H}:function(H){return H&&typeof Symbol=="function"&&H.constructor===Symbol&&H!==Symbol.prototype?"symbol":typeof H})(U)}function P0(U,H){var Y=Object.keys(U);if(Object.getOwnPropertySymbols){var ee=Object.getOwnPropertySymbols(U);H&&(ee=ee.filter(function(Ce){return Object.getOwnPropertyDescriptor(U,Ce).enumerable})),Y.push.apply(Y,ee)}return Y}function d0(U){for(var H=1;H2&&arguments[2]!==void 0?arguments[2]:[];if(U!==null){var ee=[],Ce=[],_e=Ao(U,ee,Ce,Y,H);return{data:_e,cleaned:ee,unserializable:Ce}}return null}function X0(U){var H,Y,ee=(H=U,Y=new Set,JSON.stringify(H,function(Oe,$){if(Kl($)==="object"&&$!==null){if(Y.has($))return;Y.add($)}return typeof $=="bigint"?$.toString()+"n":$})),Ce=ee===void 0?"undefined":ee,_e=window.__REACT_DEVTOOLS_GLOBAL_HOOK__.clipboardCopyText;typeof _e=="function"?_e(Ce).catch(function(Oe){}):Object(Ps.copy)(Ce)}function mi(U,H){var Y=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0,ee=H[Y],Ce=Array.isArray(U)?U.slice():d0({},U);return Y+1===H.length?Array.isArray(Ce)?Ce.splice(ee,1):delete Ce[ee]:Ce[ee]=mi(U[ee],H,Y+1),Ce}function en(U,H,Y){var ee=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0,Ce=H[ee],_e=Array.isArray(U)?U.slice():d0({},U);if(ee+1===H.length){var Oe=Y[ee];_e[Oe]=_e[Ce],Array.isArray(_e)?_e.splice(Ce,1):delete _e[Ce]}else _e[Ce]=en(U[Ce],H,Y,ee+1);return _e}function In(U,H,Y){var ee=arguments.length>3&&arguments[3]!==void 0?arguments[3]:0;if(ee>=H.length)return Y;var Ce=H[ee],_e=Array.isArray(U)?U.slice():d0({},U);return _e[Ce]=In(U[Ce],H,Y,ee+1),_e}var Ai=f(8);function yi(U,H){var Y=Object.keys(U);if(Object.getOwnPropertySymbols){var ee=Object.getOwnPropertySymbols(U);H&&(ee=ee.filter(function(Ce){return Object.getOwnPropertyDescriptor(U,Ce).enumerable})),Y.push.apply(Y,ee)}return Y}function Wt(U){for(var H=1;H"u"||!(Symbol.iterator in Object(Y)))){var Ce=[],_e=!0,Oe=!1,$=void 0;try{for(var Ne,Je=Y[Symbol.iterator]();!(_e=(Ne=Je.next()).done)&&(Ce.push(Ne.value),!ee||Ce.length!==ee);_e=!0);}catch(vt){Oe=!0,$=vt}finally{try{_e||Je.return==null||Je.return()}finally{if(Oe)throw $}}return Ce}}(U,H)||Xl(U,H)||function(){throw new TypeError(`Invalid attempt to destructure non-iterable instance. +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}()}function Yi(U,H){var Y;if(typeof Symbol>"u"||U[Symbol.iterator]==null){if(Array.isArray(U)||(Y=Xl(U))||H&&U&&typeof U.length=="number"){Y&&(U=Y);var ee=0,Ce=function(){};return{s:Ce,n:function(){return ee>=U.length?{done:!0}:{done:!1,value:U[ee++]}},e:function(Ne){throw Ne},f:Ce}}throw new TypeError(`Invalid attempt to iterate non-iterable instance. +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var _e,Oe=!0,$=!1;return{s:function(){Y=U[Symbol.iterator]()},n:function(){var Ne=Y.next();return Oe=Ne.done,Ne},e:function(Ne){$=!0,_e=Ne},f:function(){try{Oe||Y.return==null||Y.return()}finally{if($)throw _e}}}}function Xl(U,H){if(U){if(typeof U=="string")return ko(U,H);var Y=Object.prototype.toString.call(U).slice(8,-1);return Y==="Object"&&U.constructor&&(Y=U.constructor.name),Y==="Map"||Y==="Set"?Array.from(U):Y==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(Y)?ko(U,H):void 0}}function ko(U,H){(H==null||H>U.length)&&(H=U.length);for(var Y=0,ee=new Array(H);Y"u"?"undefined":li(performance))==="object"&&typeof performance.now=="function"?function(){return performance.now()}:function(){return Date.now()};function No(U){var H=null;function Y(rn){var Ft=li(rn)==="object"&&rn!==null?rn.$$typeof:rn;return li(Ft)==="symbol"?Ft.toString():Ft}var ee=H=Object(zt.gte)(U,"17.0.0-alpha")?{Block:22,ClassComponent:1,ContextConsumer:9,ContextProvider:10,CoroutineComponent:-1,CoroutineHandlerPhase:-1,DehydratedSuspenseComponent:18,ForwardRef:11,Fragment:7,FunctionComponent:0,HostComponent:5,HostPortal:4,HostRoot:3,HostText:6,IncompleteClassComponent:17,IndeterminateComponent:2,LazyComponent:16,MemoComponent:14,Mode:8,OffscreenComponent:23,Profiler:12,SimpleMemoComponent:15,SuspenseComponent:13,SuspenseListComponent:19,YieldComponent:-1}:Object(zt.gte)(U,"16.6.0-beta.0")?{Block:22,ClassComponent:1,ContextConsumer:9,ContextProvider:10,CoroutineComponent:-1,CoroutineHandlerPhase:-1,DehydratedSuspenseComponent:18,ForwardRef:11,Fragment:7,FunctionComponent:0,HostComponent:5,HostPortal:4,HostRoot:3,HostText:6,IncompleteClassComponent:17,IndeterminateComponent:2,LazyComponent:16,MemoComponent:14,Mode:8,OffscreenComponent:-1,Profiler:12,SimpleMemoComponent:15,SuspenseComponent:13,SuspenseListComponent:19,YieldComponent:-1}:Object(zt.gte)(U,"16.4.3-alpha")?{Block:-1,ClassComponent:2,ContextConsumer:11,ContextProvider:12,CoroutineComponent:-1,CoroutineHandlerPhase:-1,DehydratedSuspenseComponent:-1,ForwardRef:13,Fragment:9,FunctionComponent:0,HostComponent:7,HostPortal:6,HostRoot:5,HostText:8,IncompleteClassComponent:-1,IndeterminateComponent:4,LazyComponent:-1,MemoComponent:-1,Mode:10,OffscreenComponent:-1,Profiler:15,SimpleMemoComponent:-1,SuspenseComponent:16,SuspenseListComponent:-1,YieldComponent:-1}:{Block:-1,ClassComponent:2,ContextConsumer:12,ContextProvider:13,CoroutineComponent:7,CoroutineHandlerPhase:8,DehydratedSuspenseComponent:-1,ForwardRef:14,Fragment:10,FunctionComponent:1,HostComponent:5,HostPortal:4,HostRoot:3,HostText:6,IncompleteClassComponent:-1,IndeterminateComponent:0,LazyComponent:-1,MemoComponent:-1,Mode:11,OffscreenComponent:-1,Profiler:15,SimpleMemoComponent:-1,SuspenseComponent:16,SuspenseListComponent:-1,YieldComponent:9},Ce=ee.ClassComponent,_e=ee.IncompleteClassComponent,Oe=ee.FunctionComponent,$=ee.IndeterminateComponent,Ne=ee.ForwardRef,Je=ee.HostRoot,vt=ee.HostComponent,oe=ee.HostPortal,qe=ee.HostText,rt=ee.Fragment,xt=ee.MemoComponent,kt=ee.SimpleMemoComponent,bt=ee.SuspenseComponent,sn=ee.SuspenseListComponent;return{getDisplayNameForFiber:function(rn){var Ft=rn.type,Dn=rn.tag,dr=Ft;li(Ft)==="object"&&Ft!==null&&(dr=function Cr(Rn){switch(Y(Rn)){case 60115:case"Symbol(react.memo)":return Cr(Rn.type);case 60112:case"Symbol(react.forward_ref)":return Rn.render;default:return Rn}}(Ft));var er=null;switch(Dn){case Ce:case _e:return vi(dr);case Oe:case $:return vi(dr);case Ne:return Ft&&Ft.displayName||vi(dr,"Anonymous");case Je:return null;case vt:return Ft;case oe:case qe:case rt:return null;case xt:case kt:return vi(dr,"Anonymous");case bt:return"Suspense";case sn:return"SuspenseList";default:switch(Y(Ft)){case 60111:case"Symbol(react.concurrent_mode)":case"Symbol(react.async_mode)":return null;case 60109:case"Symbol(react.provider)":return er=rn.type._context||rn.type.context,"".concat(er.displayName||"Context",".Provider");case 60110:case"Symbol(react.context)":return er=rn.type._context||rn.type,"".concat(er.displayName||"Context",".Consumer");case 60108:case"Symbol(react.strict_mode)":return null;case 60114:case"Symbol(react.profiler)":return"Profiler(".concat(rn.memoizedProps.id,")");case 60119:case"Symbol(react.scope)":return"Scope";default:return null}}},getTypeSymbol:Y,ReactPriorityLevels:{ImmediatePriority:99,UserBlockingPriority:98,NormalPriority:97,LowPriority:96,IdlePriority:95,NoPriority:90},ReactTypeOfWork:H,ReactTypeOfSideEffect:{NoFlags:0,PerformedWork:1,Placement:2}}}function Is(U,H,Y,ee){var Ce=No(Y.version),_e=Ce.getDisplayNameForFiber,Oe=Ce.getTypeSymbol,$=Ce.ReactPriorityLevels,Ne=Ce.ReactTypeOfWork,Je=Ce.ReactTypeOfSideEffect,vt=Je.NoFlags,oe=Je.PerformedWork,qe=Je.Placement,rt=Ne.FunctionComponent,xt=Ne.ClassComponent,kt=Ne.ContextConsumer,bt=Ne.DehydratedSuspenseComponent,sn=Ne.Fragment,rn=Ne.ForwardRef,Ft=Ne.HostRoot,Dn=Ne.HostPortal,dr=Ne.HostComponent,er=Ne.HostText,Cr=Ne.IncompleteClassComponent,Rn=Ne.IndeterminateComponent,Nr=Ne.MemoComponent,y0=Ne.OffscreenComponent,Lr=Ne.SimpleMemoComponent,ut=Ne.SuspenseComponent,wt=Ne.SuspenseListComponent,et=$.ImmediatePriority,It=$.UserBlockingPriority,un=$.NormalPriority,fn=$.LowPriority,Jn=$.IdlePriority,wr=$.NoPriority,au=Y.overrideHookState,ku=Y.overrideHookStateDeletePath,T0=Y.overrideHookStateRenamePath,Z0=Y.overrideProps,Nu=Y.overridePropsDeletePath,gi=Y.overridePropsRenamePath,Po=Y.setSuspenseHandler,rl=Y.scheduleUpdate,hf=typeof Po=="function"&&typeof rl=="function";co(Y);var Tl=window.__REACT_DEVTOOLS_APPEND_COMPONENT_STACK__!==!1,vf=window.__REACT_DEVTOOLS_BREAK_ON_CONSOLE_ERRORS__===!0;(Tl||vf)&&Jl({appendComponentStack:Tl,breakOnConsoleErrors:vf});var Io=new Set,ys=new Set,js=new Set,bo=!1,Bo=new Set;function gs(fe){js.clear(),Io.clear(),ys.clear(),fe.forEach(function(ie){if(ie.isEnabled)switch(ie.type){case 2:ie.isValid&&ie.value!==""&&Io.add(new RegExp(ie.value,"i"));break;case 1:js.add(ie.value);break;case 3:ie.isValid&&ie.value!==""&&ys.add(new RegExp(ie.value,"i"));break;case 4:Io.add(new RegExp("\\("));break;default:console.warn('Invalid component filter type "'.concat(ie.type,'"'))}})}function Xu(fe){var ie=fe._debugSource,Pe=fe.tag,Me=fe.type;switch(Pe){case bt:return!0;case Dn:case er:case sn:case y0:return!0;case Ft:return!1;default:switch(Oe(Me)){case 60111:case"Symbol(react.concurrent_mode)":case"Symbol(react.async_mode)":case 60108:case"Symbol(react.strict_mode)":return!0}}var at=Su(fe);if(js.has(at))return!0;if(Io.size>0){var mt=_e(fe);if(mt!=null){var Qt,An=Yi(Io);try{for(An.s();!(Qt=An.n()).done;)if(Qt.value.test(mt))return!0}catch(ir){An.e(ir)}finally{An.f()}}}if(ie!=null&&ys.size>0){var Sn,_n=ie.fileName,Tn=Yi(ys);try{for(Tn.s();!(Sn=Tn.n()).done;)if(Sn.value.test(_n))return!0}catch(ir){Tn.e(ir)}finally{Tn.f()}}return!1}function Su(fe){var ie=fe.type;switch(fe.tag){case xt:case Cr:return 1;case rt:case Rn:return 5;case rn:return 6;case Ft:return 11;case dr:return 7;case Dn:case er:case sn:return 9;case Nr:case Lr:return 8;case ut:return 12;case wt:return 13;default:switch(Oe(ie)){case 60111:case"Symbol(react.concurrent_mode)":case"Symbol(react.async_mode)":return 9;case 60109:case"Symbol(react.provider)":return 2;case 60110:case"Symbol(react.context)":return 2;case 60108:case"Symbol(react.strict_mode)":return 9;case 60114:case"Symbol(react.profiler)":return 10;default:return 9}}}function _i(fe){if(Uo.has(fe))return fe;var ie=fe.alternate;return ie!=null&&Uo.has(ie)?ie:(Uo.add(fe),fe)}window.__REACT_DEVTOOLS_COMPONENT_FILTERS__!=null?gs(window.__REACT_DEVTOOLS_COMPONENT_FILTERS__):gs([{type:1,value:7,isEnabled:!0}]);var C0=new Map,$0=new Map,Uo=new Set,la=new Map,$l=new Map,tu=-1;function Zr(fe){if(!C0.has(fe)){var ie=el();C0.set(fe,ie),$0.set(ie,fe)}return C0.get(fe)}function ho(fe){switch(Su(fe)){case 1:if(B0!==null){var ie=Zr(_i(fe)),Pe=Ci(fe);Pe!==null&&B0.set(ie,Pe)}}}var Bi={};function Ci(fe){switch(Su(fe)){case 1:var ie=fe.stateNode,Pe=Bi,Me=Bi;return ie!=null&&(ie.constructor&&ie.constructor.contextType!=null?Me=ie.context:(Pe=ie.context)&&Object.keys(Pe).length===0&&(Pe=Bi)),[Pe,Me];default:return null}}function mf(fe){switch(Su(fe)){case 1:if(B0!==null){var ie=Zr(_i(fe)),Pe=B0.has(ie)?B0.get(ie):null,Me=Ci(fe);if(Pe==null||Me==null)return null;var at=Q0(Pe,2),mt=at[0],Qt=at[1],An=Q0(Me,2),Sn=An[0],_n=An[1];if(Sn!==Bi)return eo(mt,Sn);if(_n!==Bi)return Qt!==_n}}return null}function yf(fe,ie){if(fe==null||ie==null)return!1;if(ie.hasOwnProperty("baseState")&&ie.hasOwnProperty("memoizedState")&&ie.hasOwnProperty("next")&&ie.hasOwnProperty("queue"))for(;ie!==null;){if(ie.memoizedState!==fe.memoizedState)return!0;ie=ie.next,fe=fe.next}return!1}function eo(fe,ie){if(fe==null||ie==null||ie.hasOwnProperty("baseState")&&ie.hasOwnProperty("memoizedState")&&ie.hasOwnProperty("next")&&ie.hasOwnProperty("queue"))return null;var Pe,Me=[],at=Yi(new Set([].concat(eu(Object.keys(fe)),eu(Object.keys(ie)))));try{for(at.s();!(Pe=at.n()).done;){var mt=Pe.value;fe[mt]!==ie[mt]&&Me.push(mt)}}catch(Qt){at.e(Qt)}finally{at.f()}return Me}function to(fe,ie){switch(ie.tag){case xt:case rt:case kt:case Nr:case Lr:return(ao(ie)&oe)===oe;default:return fe.memoizedProps!==ie.memoizedProps||fe.memoizedState!==ie.memoizedState||fe.ref!==ie.ref}}var xe=[],tt=[],Ke=[],Yt=[],Kt=new Map,pr=0,Ei=null;function bn(fe){xe.push(fe)}function mu(fe){if(xe.length!==0||tt.length!==0||Ke.length!==0||Ei!==null||Fu){var ie=tt.length+Ke.length+(Ei===null?0:1),Pe=new Array(3+pr+(ie>0?2+ie:0)+xe.length),Me=0;if(Pe[Me++]=H,Pe[Me++]=tu,Pe[Me++]=pr,Kt.forEach(function(An,Sn){Pe[Me++]=Sn.length;for(var _n=Y0(Sn),Tn=0;Tn<_n.length;Tn++)Pe[Me+Tn]=_n[Tn];Me+=Sn.length}),ie>0){Pe[Me++]=2,Pe[Me++]=ie;for(var at=tt.length-1;at>=0;at--)Pe[Me++]=tt[at];for(var mt=0;mt0?fe.forEach(function(ie){U.emit("operations",ie)}):(Rr!==null&&(fu=!0),U.getFiberRoots(H).forEach(function(ie){$u(tu=Zr(_i(ie.current)),ie.current),Fu&&ie.memoizedInteractions!=null&&(il={changeDescriptions:es?new Map:null,durations:[],commitTime:Ql()-Ju,interactions:Array.from(ie.memoizedInteractions).map(function(Pe){return Wt(Wt({},Pe),{},{timestamp:Pe.timestamp-Ju})}),maxActualDuration:0,priorityLevel:null}),Qr(ie.current,null,!1,!1),mu(),tu=-1}))},getBestMatchForTrackedPath:function(){if(Rr===null||no===null)return null;for(var fe=no;fe!==null&&Xu(fe);)fe=fe.return;return fe===null?null:{id:Zr(_i(fe)),isFullMatch:nu===Rr.length-1}},getDisplayNameForFiberID:function(fe){var ie=$0.get(fe);return ie!=null?_e(ie):null},getFiberIDForNative:function(fe){var ie=arguments.length>1&&arguments[1]!==void 0&&arguments[1],Pe=Y.findFiberByHostInstance(fe);if(Pe!=null){if(ie)for(;Pe!==null&&Xu(Pe);)Pe=Pe.return;return Zr(_i(Pe))}return null},getInstanceAndStyle:function(fe){var ie=null,Pe=null,Me=Wu(fe);return Me!==null&&(ie=Me.stateNode,Me.memoizedProps!==null&&(Pe=Me.memoizedProps.style)),{instance:ie,style:Pe}},getOwnersList:function(fe){var ie=Wu(fe);if(ie==null)return null;var Pe=ie._debugOwner,Me=[{displayName:_e(ie)||"Anonymous",id:fe,type:Su(ie)}];if(Pe)for(var at=Pe;at!==null;)Me.unshift({displayName:_e(at)||"Anonymous",id:Zr(_i(at)),type:Su(at)}),at=at._debugOwner||null;return Me},getPathForElement:function(fe){var ie=$0.get(fe);if(ie==null)return null;for(var Pe=[];ie!==null;)Pe.push(_0(ie)),ie=ie.return;return Pe.reverse(),Pe},getProfilingData:function(){var fe=[];if(_s===null)throw Error("getProfilingData() called before any profiling data was recorded");return _s.forEach(function(ie,Pe){var Me=[],at=[],mt=new Map,Qt=new Map,An=xl!==null&&xl.get(Pe)||"Unknown";O0!=null&&O0.forEach(function(Sn,_n){vo!=null&&vo.get(_n)===Pe&&at.push([_n,Sn])}),ie.forEach(function(Sn,_n){var Tn=Sn.changeDescriptions,ir=Sn.durations,Ut=Sn.interactions,Fi=Sn.maxActualDuration,Ar=Sn.priorityLevel,mr=Sn.commitTime,K=[];Ut.forEach(function(Di){mt.has(Di.id)||mt.set(Di.id,Di),K.push(Di.id);var ru=Qt.get(Di.id);ru!=null?ru.push(_n):Qt.set(Di.id,[_n])});for(var ti=[],ni=[],Wr=0;Wr1?Kn.set(Tn,ir-1):Kn.delete(Tn),ei.delete(Sn)}(tu),$r(Pe,!1))}else $u(tu,Pe),Qr(Pe,null,!1,!1);if(Fu&&at){var An=_s.get(tu);An!=null?An.push(il):_s.set(tu,[il])}mu(),bo&&U.emit("traceUpdates",Bo),tu=-1},handleCommitFiberUnmount:function(fe){$r(fe,!1)},inspectElement:function(fe,ie){if(Hi(fe)){if(ie!=null){A0(ie);var Pe=null;return ie[0]==="hooks"&&(Pe="hooks"),{id:fe,type:"hydrated-path",path:ie,value:Ri(Bu(Xi,ie),qi(null,Pe),ie)}}return{id:fe,type:"no-change"}}if(Hs=!1,Xi!==null&&Xi.id===fe||(R0={}),(Xi=sa(fe))===null)return{id:fe,type:"not-found"};ie!=null&&A0(ie),function(at){var mt=at.hooks,Qt=at.id,An=at.props,Sn=$0.get(Qt);if(Sn!=null){var _n=Sn.elementType,Tn=Sn.stateNode,ir=Sn.tag,Ut=Sn.type;switch(ir){case xt:case Cr:case Rn:ee.$r=Tn;break;case rt:ee.$r={hooks:mt,props:An,type:Ut};break;case rn:ee.$r={props:An,type:Ut.render};break;case Nr:case Lr:ee.$r={props:An,type:_n!=null&&_n.type!=null?_n.type:Ut};break;default:ee.$r=null}}else console.warn('Could not find Fiber with id "'.concat(Qt,'"'))}(Xi);var Me=Wt({},Xi);return Me.context=Ri(Me.context,qi("context",null)),Me.hooks=Ri(Me.hooks,qi("hooks","hooks")),Me.props=Ri(Me.props,qi("props",null)),Me.state=Ri(Me.state,qi("state",null)),{id:fe,type:"full-data",value:Me}},logElementToConsole:function(fe){var ie=Hi(fe)?Xi:sa(fe);if(ie!==null){var Pe=typeof console.groupCollapsed=="function";Pe&&console.groupCollapsed("[Click to expand] %c<".concat(ie.displayName||"Component"," />"),"color: var(--dom-tag-name-color); font-weight: normal;"),ie.props!==null&&console.log("Props:",ie.props),ie.state!==null&&console.log("State:",ie.state),ie.hooks!==null&&console.log("Hooks:",ie.hooks);var Me=Cl(fe);Me!==null&&console.log("Nodes:",Me),ie.source!==null&&console.log("Location:",ie.source),(window.chrome||/firefox/i.test(navigator.userAgent))&&console.log("Right-click any value to save it as a global variable for further inspection."),Pe&&console.groupEnd()}else console.warn('Could not find Fiber with id "'.concat(fe,'"'))},prepareViewAttributeSource:function(fe,ie){Hi(fe)&&(window.$attribute=Bu(Xi,ie))},prepareViewElementSource:function(fe){var ie=$0.get(fe);if(ie!=null){var Pe=ie.elementType,Me=ie.tag,at=ie.type;switch(Me){case xt:case Cr:case Rn:case rt:ee.$type=at;break;case rn:ee.$type=at.render;break;case Nr:case Lr:ee.$type=Pe!=null&&Pe.type!=null?Pe.type:at;break;default:ee.$type=null}}else console.warn('Could not find Fiber with id "'.concat(fe,'"'))},overrideSuspense:function(fe,ie){if(typeof Po!="function"||typeof rl!="function")throw new Error("Expected overrideSuspense() to not get called for earlier React versions.");ie?(Zu.add(fe),Zu.size===1&&Po(Es)):(Zu.delete(fe),Zu.size===0&&Po(gf));var Pe=$0.get(fe);Pe!=null&&rl(Pe)},overrideValueAtPath:function(fe,ie,Pe,Me,at){var mt=Wu(ie);if(mt!==null){var Qt=mt.stateNode;switch(fe){case"context":switch(Me=Me.slice(1),mt.tag){case xt:Me.length===0?Qt.context=at:Oo(Qt.context,Me,at),Qt.forceUpdate()}break;case"hooks":typeof au=="function"&&au(mt,Pe,Me,at);break;case"props":switch(mt.tag){case xt:mt.pendingProps=In(Qt.props,Me,at),Qt.forceUpdate();break;default:typeof Z0=="function"&&Z0(mt,Me,at)}break;case"state":switch(mt.tag){case xt:Oo(Qt.state,Me,at),Qt.forceUpdate()}}}},renamePath:function(fe,ie,Pe,Me,at){var mt=Wu(ie);if(mt!==null){var Qt=mt.stateNode;switch(fe){case"context":switch(Me=Me.slice(1),at=at.slice(1),mt.tag){case xt:Me.length===0||Kr(Qt.context,Me,at),Qt.forceUpdate()}break;case"hooks":typeof T0=="function"&&T0(mt,Pe,Me,at);break;case"props":Qt===null?typeof gi=="function"&&gi(mt,Me,at):(mt.pendingProps=en(Qt.props,Me,at),Qt.forceUpdate());break;case"state":Kr(Qt.state,Me,at),Qt.forceUpdate()}}},renderer:Y,setTraceUpdatesEnabled:function(fe){bo=fe},setTrackedPath:Li,startProfiling:aa,stopProfiling:function(){Fu=!1,es=!1},storeAsGlobal:function(fe,ie,Pe){if(Hi(fe)){var Me=Bu(Xi,ie),at="$reactTemp".concat(Pe);window[at]=Me,console.log(at),console.log(Me)}},updateComponentFilters:function(fe){if(Fu)throw Error("Cannot modify filter preferences while profiling");U.getFiberRoots(H).forEach(function(ie){tu=Zr(_i(ie.current)),qu(ie.current),$r(ie.current,!1),tu=-1}),gs(fe),Kn.clear(),U.getFiberRoots(H).forEach(function(ie){$u(tu=Zr(_i(ie.current)),ie.current),Qr(ie.current,null,!1,!1),mu(ie),tu=-1})}}}var $n;function tl(U){return(tl=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(H){return typeof H}:function(H){return H&&typeof Symbol=="function"&&H.constructor===Symbol&&H!==Symbol.prototype?"symbol":typeof H})(U)}function fo(U,H,Y){if($n===void 0)try{throw Error()}catch(Ce){var ee=Ce.stack.trim().match(/\n( *(at )?)/);$n=ee&&ee[1]||""}return` +`+$n+U}var I0=!1;function Sl(U,H,Y){if(!U||I0)return"";var ee,Ce=Error.prepareStackTrace;Error.prepareStackTrace=void 0,I0=!0;var _e=Y.current;Y.current=null;try{if(H){var Oe=function(){throw Error()};if(Object.defineProperty(Oe.prototype,"props",{set:function(){throw Error()}}),(typeof Reflect>"u"?"undefined":tl(Reflect))==="object"&&Reflect.construct){try{Reflect.construct(Oe,[])}catch(qe){ee=qe}Reflect.construct(U,[],Oe)}else{try{Oe.call()}catch(qe){ee=qe}U.call(Oe.prototype)}}else{try{throw Error()}catch(qe){ee=qe}U()}}catch(qe){if(qe&&ee&&typeof qe.stack=="string"){for(var $=qe.stack.split(` +`),Ne=ee.stack.split(` +`),Je=$.length-1,vt=Ne.length-1;Je>=1&&vt>=0&&$[Je]!==Ne[vt];)vt--;for(;Je>=1&&vt>=0;Je--,vt--)if($[Je]!==Ne[vt]){if(Je!==1||vt!==1)do if(Je--,--vt<0||$[Je]!==Ne[vt])return` +`+$[Je].replace(" at new "," at ");while(Je>=1&&vt>=0);break}}}finally{I0=!1,Error.prepareStackTrace=Ce,Y.current=_e}var oe=U?U.displayName||U.name:"";return oe?fo(oe):""}function Lo(U,H,Y,ee){return Sl(U,!1,ee)}function St(U,H,Y){var ee=U.HostComponent,Ce=U.LazyComponent,_e=U.SuspenseComponent,Oe=U.SuspenseListComponent,$=U.FunctionComponent,Ne=U.IndeterminateComponent,Je=U.SimpleMemoComponent,vt=U.ForwardRef,oe=U.Block,qe=U.ClassComponent;switch(H.tag){case ee:return fo(H.type);case Ce:return fo("Lazy");case _e:return fo("Suspense");case Oe:return fo("SuspenseList");case $:case Ne:case Je:return Lo(H.type,0,0,Y);case vt:return Lo(H.type.render,0,0,Y);case oe:return Lo(H.type._render,0,0,Y);case qe:return function(rt,xt,kt,bt){return Sl(rt,!0,bt)}(H.type,0,0,Y);default:return""}}function Bt(U,H,Y){try{var ee="",Ce=H;do ee+=St(U,Ce,Y),Ce=Ce.return;while(Ce);return ee}catch(_e){return` +Error generating stack: `+_e.message+` +`+_e.stack}}function Hn(U,H){var Y;if(typeof Symbol>"u"||U[Symbol.iterator]==null){if(Array.isArray(U)||(Y=function(Ne,Je){if(!!Ne){if(typeof Ne=="string")return qr(Ne,Je);var vt=Object.prototype.toString.call(Ne).slice(8,-1);if(vt==="Object"&&Ne.constructor&&(vt=Ne.constructor.name),vt==="Map"||vt==="Set")return Array.from(Ne);if(vt==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(vt))return qr(Ne,Je)}}(U))||H&&U&&typeof U.length=="number"){Y&&(U=Y);var ee=0,Ce=function(){};return{s:Ce,n:function(){return ee>=U.length?{done:!0}:{done:!1,value:U[ee++]}},e:function(Ne){throw Ne},f:Ce}}throw new TypeError(`Invalid attempt to iterate non-iterable instance. +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var _e,Oe=!0,$=!1;return{s:function(){Y=U[Symbol.iterator]()},n:function(){var Ne=Y.next();return Oe=Ne.done,Ne},e:function(Ne){$=!0,_e=Ne},f:function(){try{Oe||Y.return==null||Y.return()}finally{if($)throw _e}}}}function qr(U,H){(H==null||H>U.length)&&(H=U.length);for(var Y=0,ee=new Array(H);Y0?Je[Je.length-1]:null,qe=oe!==null&&(Xr.test(oe)||Au.test(oe));if(!qe){var rt,xt=Hn(p0.values());try{for(xt.s();!(rt=xt.n()).done;){var kt=rt.value,bt=kt.currentDispatcherRef,sn=kt.getCurrentFiber,rn=kt.workTagMap,Ft=sn();if(Ft!=null){var Dn=Bt(rn,Ft,bt);Dn!==""&&Je.push(Dn);break}}}catch(dr){xt.e(dr)}finally{xt.f()}}}catch{}_e.apply(void 0,Je)};Oe.__REACT_DEVTOOLS_ORIGINAL_METHOD__=_e,Ni[Ce]=Oe}catch{}})}}function Uu(U){return(Uu=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(H){return typeof H}:function(H){return H&&typeof Symbol=="function"&&H.constructor===Symbol&&H!==Symbol.prototype?"symbol":typeof H})(U)}function vs(U,H){for(var Y=0;Y"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}();return function(){var Y,ee=Le(U);if(H){var Ce=Le(this).constructor;Y=Reflect.construct(ee,arguments,Ce)}else Y=ee.apply(this,arguments);return Se(this,Y)}}function Se(U,H){return!H||Uu(H)!=="object"&&typeof H!="function"?Fe(U):H}function Fe(U){if(U===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return U}function Le(U){return(Le=Object.setPrototypeOf?Object.getPrototypeOf:function(H){return H.__proto__||Object.getPrototypeOf(H)})(U)}function pt(U,H,Y){return H in U?Object.defineProperty(U,H,{value:Y,enumerable:!0,configurable:!0,writable:!0}):U[H]=Y,U}var Yn=function(U){(function(Oe,$){if(typeof $!="function"&&$!==null)throw new TypeError("Super expression must either be null or a function");Oe.prototype=Object.create($&&$.prototype,{constructor:{value:Oe,writable:!0,configurable:!0}}),$&&b0(Oe,$)})(_e,U);var H,Y,ee,Ce=Q(_e);function _e(Oe){var $;(function(oe,qe){if(!(oe instanceof qe))throw new TypeError("Cannot call a class as a function")})(this,_e),pt(Fe($=Ce.call(this)),"_isProfiling",!1),pt(Fe($),"_recordChangeDescriptions",!1),pt(Fe($),"_rendererInterfaces",{}),pt(Fe($),"_persistedSelection",null),pt(Fe($),"_persistedSelectionMatch",null),pt(Fe($),"_traceUpdatesEnabled",!1),pt(Fe($),"copyElementPath",function(oe){var qe=oe.id,rt=oe.path,xt=oe.rendererID,kt=$._rendererInterfaces[xt];kt==null?console.warn('Invalid renderer id "'.concat(xt,'" for element "').concat(qe,'"')):kt.copyElementPath(qe,rt)}),pt(Fe($),"deletePath",function(oe){var qe=oe.hookID,rt=oe.id,xt=oe.path,kt=oe.rendererID,bt=oe.type,sn=$._rendererInterfaces[kt];sn==null?console.warn('Invalid renderer id "'.concat(kt,'" for element "').concat(rt,'"')):sn.deletePath(bt,rt,qe,xt)}),pt(Fe($),"getProfilingData",function(oe){var qe=oe.rendererID,rt=$._rendererInterfaces[qe];rt==null&&console.warn('Invalid renderer id "'.concat(qe,'"')),$._bridge.send("profilingData",rt.getProfilingData())}),pt(Fe($),"getProfilingStatus",function(){$._bridge.send("profilingStatus",$._isProfiling)}),pt(Fe($),"getOwnersList",function(oe){var qe=oe.id,rt=oe.rendererID,xt=$._rendererInterfaces[rt];if(xt==null)console.warn('Invalid renderer id "'.concat(rt,'" for element "').concat(qe,'"'));else{var kt=xt.getOwnersList(qe);$._bridge.send("ownersList",{id:qe,owners:kt})}}),pt(Fe($),"inspectElement",function(oe){var qe=oe.id,rt=oe.path,xt=oe.rendererID,kt=$._rendererInterfaces[xt];kt==null?console.warn('Invalid renderer id "'.concat(xt,'" for element "').concat(qe,'"')):($._bridge.send("inspectedElement",kt.inspectElement(qe,rt)),$._persistedSelectionMatch!==null&&$._persistedSelectionMatch.id===qe||($._persistedSelection=null,$._persistedSelectionMatch=null,kt.setTrackedPath(null),$._throttledPersistSelection(xt,qe)))}),pt(Fe($),"logElementToConsole",function(oe){var qe=oe.id,rt=oe.rendererID,xt=$._rendererInterfaces[rt];xt==null?console.warn('Invalid renderer id "'.concat(rt,'" for element "').concat(qe,'"')):xt.logElementToConsole(qe)}),pt(Fe($),"overrideSuspense",function(oe){var qe=oe.id,rt=oe.rendererID,xt=oe.forceFallback,kt=$._rendererInterfaces[rt];kt==null?console.warn('Invalid renderer id "'.concat(rt,'" for element "').concat(qe,'"')):kt.overrideSuspense(qe,xt)}),pt(Fe($),"overrideValueAtPath",function(oe){var qe=oe.hookID,rt=oe.id,xt=oe.path,kt=oe.rendererID,bt=oe.type,sn=oe.value,rn=$._rendererInterfaces[kt];rn==null?console.warn('Invalid renderer id "'.concat(kt,'" for element "').concat(rt,'"')):rn.overrideValueAtPath(bt,rt,qe,xt,sn)}),pt(Fe($),"overrideContext",function(oe){var qe=oe.id,rt=oe.path,xt=oe.rendererID,kt=oe.wasForwarded,bt=oe.value;kt||$.overrideValueAtPath({id:qe,path:rt,rendererID:xt,type:"context",value:bt})}),pt(Fe($),"overrideHookState",function(oe){var qe=oe.id,rt=(oe.hookID,oe.path),xt=oe.rendererID,kt=oe.wasForwarded,bt=oe.value;kt||$.overrideValueAtPath({id:qe,path:rt,rendererID:xt,type:"hooks",value:bt})}),pt(Fe($),"overrideProps",function(oe){var qe=oe.id,rt=oe.path,xt=oe.rendererID,kt=oe.wasForwarded,bt=oe.value;kt||$.overrideValueAtPath({id:qe,path:rt,rendererID:xt,type:"props",value:bt})}),pt(Fe($),"overrideState",function(oe){var qe=oe.id,rt=oe.path,xt=oe.rendererID,kt=oe.wasForwarded,bt=oe.value;kt||$.overrideValueAtPath({id:qe,path:rt,rendererID:xt,type:"state",value:bt})}),pt(Fe($),"reloadAndProfile",function(oe){q("React::DevTools::reloadAndProfile","true"),q("React::DevTools::recordChangeDescriptions",oe?"true":"false"),$._bridge.send("reloadAppForProfiling")}),pt(Fe($),"renamePath",function(oe){var qe=oe.hookID,rt=oe.id,xt=oe.newPath,kt=oe.oldPath,bt=oe.rendererID,sn=oe.type,rn=$._rendererInterfaces[bt];rn==null?console.warn('Invalid renderer id "'.concat(bt,'" for element "').concat(rt,'"')):rn.renamePath(sn,rt,qe,kt,xt)}),pt(Fe($),"setTraceUpdatesEnabled",function(oe){for(var qe in $._traceUpdatesEnabled=oe,Vt(oe),$._rendererInterfaces)$._rendererInterfaces[qe].setTraceUpdatesEnabled(oe)}),pt(Fe($),"syncSelectionFromNativeElementsPanel",function(){var oe=window.__REACT_DEVTOOLS_GLOBAL_HOOK__.$0;oe!=null&&$.selectNode(oe)}),pt(Fe($),"shutdown",function(){$.emit("shutdown")}),pt(Fe($),"startProfiling",function(oe){for(var qe in $._recordChangeDescriptions=oe,$._isProfiling=!0,$._rendererInterfaces)$._rendererInterfaces[qe].startProfiling(oe);$._bridge.send("profilingStatus",$._isProfiling)}),pt(Fe($),"stopProfiling",function(){for(var oe in $._isProfiling=!1,$._recordChangeDescriptions=!1,$._rendererInterfaces)$._rendererInterfaces[oe].stopProfiling();$._bridge.send("profilingStatus",$._isProfiling)}),pt(Fe($),"storeAsGlobal",function(oe){var qe=oe.count,rt=oe.id,xt=oe.path,kt=oe.rendererID,bt=$._rendererInterfaces[kt];bt==null?console.warn('Invalid renderer id "'.concat(kt,'" for element "').concat(rt,'"')):bt.storeAsGlobal(rt,xt,qe)}),pt(Fe($),"updateConsolePatchSettings",function(oe){var qe=oe.appendComponentStack,rt=oe.breakOnConsoleErrors;qe||rt?Jl({appendComponentStack:qe,breakOnConsoleErrors:rt}):Ct!==null&&(Ct(),Ct=null)}),pt(Fe($),"updateComponentFilters",function(oe){for(var qe in $._rendererInterfaces)$._rendererInterfaces[qe].updateComponentFilters(oe)}),pt(Fe($),"viewAttributeSource",function(oe){var qe=oe.id,rt=oe.path,xt=oe.rendererID,kt=$._rendererInterfaces[xt];kt==null?console.warn('Invalid renderer id "'.concat(xt,'" for element "').concat(qe,'"')):kt.prepareViewAttributeSource(qe,rt)}),pt(Fe($),"viewElementSource",function(oe){var qe=oe.id,rt=oe.rendererID,xt=$._rendererInterfaces[rt];xt==null?console.warn('Invalid renderer id "'.concat(rt,'" for element "').concat(qe,'"')):xt.prepareViewElementSource(qe)}),pt(Fe($),"onTraceUpdates",function(oe){$.emit("traceUpdates",oe)}),pt(Fe($),"onHookOperations",function(oe){if($._bridge.send("operations",oe),$._persistedSelection!==null){var qe=oe[0];if($._persistedSelection.rendererID===qe){var rt=$._rendererInterfaces[qe];if(rt==null)console.warn('Invalid renderer id "'.concat(qe,'"'));else{var xt=$._persistedSelectionMatch,kt=rt.getBestMatchForTrackedPath();$._persistedSelectionMatch=kt;var bt=xt!==null?xt.id:null,sn=kt!==null?kt.id:null;bt!==sn&&sn!==null&&$._bridge.send("selectFiber",sn),kt!==null&&kt.isFullMatch&&($._persistedSelection=null,$._persistedSelectionMatch=null,rt.setTrackedPath(null))}}}}),pt(Fe($),"_throttledPersistSelection",N()(function(oe,qe){var rt=$._rendererInterfaces[oe],xt=rt!=null?rt.getPathForElement(qe):null;xt!==null?q("React::DevTools::lastSelection",JSON.stringify({rendererID:oe,path:xt})):j("React::DevTools::lastSelection")},1e3)),x("React::DevTools::reloadAndProfile")==="true"&&($._recordChangeDescriptions=x("React::DevTools::recordChangeDescriptions")==="true",$._isProfiling=!0,j("React::DevTools::recordChangeDescriptions"),j("React::DevTools::reloadAndProfile"));var Ne=x("React::DevTools::lastSelection");Ne!=null&&($._persistedSelection=JSON.parse(Ne)),$._bridge=Oe,Oe.addListener("copyElementPath",$.copyElementPath),Oe.addListener("deletePath",$.deletePath),Oe.addListener("getProfilingData",$.getProfilingData),Oe.addListener("getProfilingStatus",$.getProfilingStatus),Oe.addListener("getOwnersList",$.getOwnersList),Oe.addListener("inspectElement",$.inspectElement),Oe.addListener("logElementToConsole",$.logElementToConsole),Oe.addListener("overrideSuspense",$.overrideSuspense),Oe.addListener("overrideValueAtPath",$.overrideValueAtPath),Oe.addListener("reloadAndProfile",$.reloadAndProfile),Oe.addListener("renamePath",$.renamePath),Oe.addListener("setTraceUpdatesEnabled",$.setTraceUpdatesEnabled),Oe.addListener("startProfiling",$.startProfiling),Oe.addListener("stopProfiling",$.stopProfiling),Oe.addListener("storeAsGlobal",$.storeAsGlobal),Oe.addListener("syncSelectionFromNativeElementsPanel",$.syncSelectionFromNativeElementsPanel),Oe.addListener("shutdown",$.shutdown),Oe.addListener("updateConsolePatchSettings",$.updateConsolePatchSettings),Oe.addListener("updateComponentFilters",$.updateComponentFilters),Oe.addListener("viewAttributeSource",$.viewAttributeSource),Oe.addListener("viewElementSource",$.viewElementSource),Oe.addListener("overrideContext",$.overrideContext),Oe.addListener("overrideHookState",$.overrideHookState),Oe.addListener("overrideProps",$.overrideProps),Oe.addListener("overrideState",$.overrideState),$._isProfiling&&Oe.send("profilingStatus",!0);var Je,vt=!1;try{localStorage.getItem("test"),vt=!0}catch{}return Oe.send("isBackendStorageAPISupported",vt),Re(Oe,Fe($)),Je=Fe($),Je.addListener("traceUpdates",Er),$}return H=_e,(Y=[{key:"getInstanceAndStyle",value:function(Oe){var $=Oe.id,Ne=Oe.rendererID,Je=this._rendererInterfaces[Ne];return Je==null?(console.warn('Invalid renderer id "'.concat(Ne,'"')),null):Je.getInstanceAndStyle($)}},{key:"getIDForNode",value:function(Oe){for(var $ in this._rendererInterfaces){var Ne=this._rendererInterfaces[$];try{var Je=Ne.getFiberIDForNative(Oe,!0);if(Je!==null)return Je}catch{}}return null}},{key:"selectNode",value:function(Oe){var $=this.getIDForNode(Oe);$!==null&&this._bridge.send("selectFiber",$)}},{key:"setRendererInterface",value:function(Oe,$){this._rendererInterfaces[Oe]=$,this._isProfiling&&$.startProfiling(this._recordChangeDescriptions),$.setTraceUpdatesEnabled(this._traceUpdatesEnabled);var Ne=this._persistedSelection;Ne!==null&&Ne.rendererID===Oe&&$.setTrackedPath(Ne.path)}},{key:"onUnsupportedRenderer",value:function(Oe){this._bridge.send("unsupportedRendererVersion",Oe)}},{key:"rendererInterfaces",get:function(){return this._rendererInterfaces}}])&&vs(H.prototype,Y),ee&&vs(H,ee),_e}(E);function Cn(U){return(Cn=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(H){return typeof H}:function(H){return H&&typeof Symbol=="function"&&H.constructor===Symbol&&H!==Symbol.prototype?"symbol":typeof H})(U)}function cr(U){return function(H){if(Array.isArray(H))return Si(H)}(U)||function(H){if(typeof Symbol<"u"&&Symbol.iterator in Object(H))return Array.from(H)}(U)||function(H,Y){if(!!H){if(typeof H=="string")return Si(H,Y);var ee=Object.prototype.toString.call(H).slice(8,-1);if(ee==="Object"&&H.constructor&&(ee=H.constructor.name),ee==="Map"||ee==="Set")return Array.from(H);if(ee==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(ee))return Si(H,Y)}}(U)||function(){throw new TypeError(`Invalid attempt to spread non-iterable instance. +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}()}function Si(U,H){(H==null||H>U.length)&&(H=U.length);for(var Y=0,ee=new Array(H);Y"u"||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy=="function")return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch{return!1}}();return function(){var Y,ee=Fo(U);if(H){var Ce=Fo(this).constructor;Y=Reflect.construct(ee,arguments,Ce)}else Y=ee.apply(this,arguments);return wu(this,Y)}}function wu(U,H){return!H||Cn(H)!=="object"&&typeof H!="function"?Ti(U):H}function Ti(U){if(U===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return U}function Fo(U){return(Fo=Object.setPrototypeOf?Object.getPrototypeOf:function(H){return H.__proto__||Object.getPrototypeOf(H)})(U)}function Mu(U,H,Y){return H in U?Object.defineProperty(U,H,{value:Y,enumerable:!0,configurable:!0,writable:!0}):U[H]=Y,U}var po=function(U){(function(Oe,$){if(typeof $!="function"&&$!==null)throw new TypeError("Super expression must either be null or a function");Oe.prototype=Object.create($&&$.prototype,{constructor:{value:Oe,writable:!0,configurable:!0}}),$&&ju(Oe,$)})(_e,U);var H,Y,ee,Ce=zu(_e);function _e(Oe){var $;return function(Ne,Je){if(!(Ne instanceof Je))throw new TypeError("Cannot call a class as a function")}(this,_e),Mu(Ti($=Ce.call(this)),"_isShutdown",!1),Mu(Ti($),"_messageQueue",[]),Mu(Ti($),"_timeoutID",null),Mu(Ti($),"_wallUnlisten",null),Mu(Ti($),"_flush",function(){if($._timeoutID!==null&&(clearTimeout($._timeoutID),$._timeoutID=null),$._messageQueue.length){for(var Ne=0;Ne<$._messageQueue.length;Ne+=2){var Je;(Je=$._wall).send.apply(Je,[$._messageQueue[Ne]].concat(cr($._messageQueue[Ne+1])))}$._messageQueue.length=0,$._timeoutID=setTimeout($._flush,100)}}),Mu(Ti($),"overrideValueAtPath",function(Ne){var Je=Ne.id,vt=Ne.path,oe=Ne.rendererID,qe=Ne.type,rt=Ne.value;switch(qe){case"context":$.send("overrideContext",{id:Je,path:vt,rendererID:oe,wasForwarded:!0,value:rt});break;case"hooks":$.send("overrideHookState",{id:Je,path:vt,rendererID:oe,wasForwarded:!0,value:rt});break;case"props":$.send("overrideProps",{id:Je,path:vt,rendererID:oe,wasForwarded:!0,value:rt});break;case"state":$.send("overrideState",{id:Je,path:vt,rendererID:oe,wasForwarded:!0,value:rt})}}),$._wall=Oe,$._wallUnlisten=Oe.listen(function(Ne){Ti($).emit(Ne.event,Ne.payload)})||null,$.addListener("overrideValueAtPath",$.overrideValueAtPath),$}return H=_e,(Y=[{key:"send",value:function(Oe){if(this._isShutdown)console.warn('Cannot send message "'.concat(Oe,'" through a Bridge that has been shutdown.'));else{for(var $=arguments.length,Ne=new Array($>1?$-1:0),Je=1;Je<$;Je++)Ne[Je-1]=arguments[Je];this._messageQueue.push(Oe,Ne),this._timeoutID||(this._timeoutID=setTimeout(this._flush,0))}}},{key:"shutdown",value:function(){if(this._isShutdown)console.warn("Bridge was already shutdown.");else{this.send("shutdown"),this._isShutdown=!0,this.addListener=function(){},this.emit=function(){},this.removeAllListeners();var Oe=this._wallUnlisten;Oe&&Oe();do this._flush();while(this._messageQueue.length);this._timeoutID!==null&&(clearTimeout(this._timeoutID),this._timeoutID=null)}}},{key:"wall",get:function(){return this._wall}}])&&Ou(H.prototype,Y),ee&&Ou(H,ee),_e}(E);function Hu(U,H,Y){var ee=U[H];return U[H]=function(Ce){return Y.call(this,ee,arguments)},ee}function Pa(U,H){for(var Y in H)U[Y]=H[Y]}function v0(U){typeof U.forceUpdate=="function"?U.forceUpdate():U.updater!=null&&typeof U.updater.enqueueForceUpdate=="function"&&U.updater.enqueueForceUpdate(this,function(){},"forceUpdate")}function ia(U,H){var Y=Object.keys(U);if(Object.getOwnPropertySymbols){var ee=Object.getOwnPropertySymbols(U);H&&(ee=ee.filter(function(Ce){return Object.getOwnPropertyDescriptor(U,Ce).enumerable})),Y.push.apply(Y,ee)}return Y}function J0(U){for(var H=1;H0?oe[oe.length-1]:0),oe.push(un),$.set(et,Je(It._topLevelWrapper));try{var fn=ut.apply(this,wt);return oe.pop(),fn}catch(wr){throw oe=[],wr}finally{if(oe.length===0){var Jn=$.get(et);if(Jn===void 0)throw new Error("Expected to find root ID.");dr(Jn)}}},performUpdateIfNecessary:function(ut,wt){var et=wt[0];if(S0(et)===9)return ut.apply(this,wt);var It=Je(et);oe.push(It);var un=Qn(et);try{var fn=ut.apply(this,wt),Jn=Qn(et);return vt(un,Jn)||xt(et,It,Jn),oe.pop(),fn}catch(au){throw oe=[],au}finally{if(oe.length===0){var wr=$.get(et);if(wr===void 0)throw new Error("Expected to find root ID.");dr(wr)}}},receiveComponent:function(ut,wt){var et=wt[0];if(S0(et)===9)return ut.apply(this,wt);var It=Je(et);oe.push(It);var un=Qn(et);try{var fn=ut.apply(this,wt),Jn=Qn(et);return vt(un,Jn)||xt(et,It,Jn),oe.pop(),fn}catch(au){throw oe=[],au}finally{if(oe.length===0){var wr=$.get(et);if(wr===void 0)throw new Error("Expected to find root ID.");dr(wr)}}},unmountComponent:function(ut,wt){var et=wt[0];if(S0(et)===9)return ut.apply(this,wt);var It=Je(et);oe.push(It);try{var un=ut.apply(this,wt);return oe.pop(),function(Jn,wr){rn.push(wr),_e.delete(wr)}(0,It),un}catch(Jn){throw oe=[],Jn}finally{if(oe.length===0){var fn=$.get(et);if(fn===void 0)throw new Error("Expected to find root ID.");dr(fn)}}}}));var bt=[],sn=new Map,rn=[],Ft=0,Dn=null;function dr(ut){if(bt.length!==0||rn.length!==0||Dn!==null){var wt=rn.length+(Dn===null?0:1),et=new Array(3+Ft+(wt>0?2+wt:0)+bt.length),It=0;if(et[It++]=H,et[It++]=ut,et[It++]=Ft,sn.forEach(function(Jn,wr){et[It++]=wr.length;for(var au=Y0(wr),ku=0;ku0){et[It++]=2,et[It++]=wt;for(var un=0;un"),"color: var(--dom-tag-name-color); font-weight: normal;"),wt.props!==null&&console.log("Props:",wt.props),wt.state!==null&&console.log("State:",wt.state),wt.context!==null&&console.log("Context:",wt.context);var It=Ce(ut);It!==null&&console.log("Node:",It),(window.chrome||/firefox/i.test(navigator.userAgent))&&console.log("Right-click any value to save it as a global variable for further inspection."),et&&console.groupEnd()}else console.warn('Could not find element with id "'.concat(ut,'"'))},overrideSuspense:function(){throw new Error("overrideSuspense not supported by this renderer")},overrideValueAtPath:function(ut,wt,et,It,un){var fn=_e.get(wt);if(fn!=null){var Jn=fn._instance;if(Jn!=null)switch(ut){case"context":Oo(Jn.context,It,un),v0(Jn);break;case"hooks":throw new Error("Hooks not supported by this renderer");case"props":var wr=fn._currentElement;fn._currentElement=J0(J0({},wr),{},{props:In(wr.props,It,un)}),v0(Jn);break;case"state":Oo(Jn.state,It,un),v0(Jn)}}},renamePath:function(ut,wt,et,It,un){var fn=_e.get(wt);if(fn!=null){var Jn=fn._instance;if(Jn!=null)switch(ut){case"context":Kr(Jn.context,It,un),v0(Jn);break;case"hooks":throw new Error("Hooks not supported by this renderer");case"props":var wr=fn._currentElement;fn._currentElement=J0(J0({},wr),{},{props:en(wr.props,It,un)}),v0(Jn);break;case"state":Kr(Jn.state,It,un),v0(Jn)}}},prepareViewAttributeSource:function(ut,wt){var et=Lr(ut);et!==null&&(window.$attribute=Bu(et,wt))},prepareViewElementSource:function(ut){var wt=_e.get(ut);if(wt!=null){var et=wt._currentElement;et!=null?ee.$type=et.type:console.warn('Could not find element with id "'.concat(ut,'"'))}else console.warn('Could not find instance with id "'.concat(ut,'"'))},renderer:Y,setTraceUpdatesEnabled:function(ut){},setTrackedPath:function(ut){},startProfiling:function(){},stopProfiling:function(){},storeAsGlobal:function(ut,wt,et){var It=Lr(ut);if(It!==null){var un=Bu(It,wt),fn="$reactTemp".concat(et);window[fn]=un,console.log(fn),console.log(un)}},updateComponentFilters:function(ut){}}}function si(U,H){var Y=!1,ee={bottom:0,left:0,right:0,top:0},Ce=H[U];if(Ce!=null){for(var _e=0,Oe=Object.keys(ee);_e0?"development":"production";var bt=Function.prototype.toString;if(kt.Mount&&kt.Mount._renderNewRootComponent){var sn=bt.call(kt.Mount._renderNewRootComponent);return sn.indexOf("function")!==0?"production":sn.indexOf("storedMeasure")!==-1?"development":sn.indexOf("should be a pure function")!==-1?sn.indexOf("NODE_ENV")!==-1||sn.indexOf("development")!==-1||sn.indexOf("true")!==-1?"development":sn.indexOf("nextElement")!==-1||sn.indexOf("nextComponent")!==-1?"unminified":"development":sn.indexOf("nextElement")!==-1||sn.indexOf("nextComponent")!==-1?"unminified":"outdated"}}catch{}return"production"}(Ne);try{var oe=window.__REACT_DEVTOOLS_APPEND_COMPONENT_STACK__!==!1,qe=window.__REACT_DEVTOOLS_BREAK_ON_CONSOLE_ERRORS__===!0;(oe||qe)&&(co(Ne),Jl({appendComponentStack:oe,breakOnConsoleErrors:qe}))}catch{}var rt=U.__REACT_DEVTOOLS_ATTACH__;if(typeof rt=="function"){var xt=rt($,Je,Ne,U);$.rendererInterfaces.set(Je,xt)}return $.emit("renderer",{id:Je,renderer:Ne,reactBuildType:vt}),Je},on:function(Ne,Je){_e[Ne]||(_e[Ne]=[]),_e[Ne].push(Je)},off:function(Ne,Je){if(_e[Ne]){var vt=_e[Ne].indexOf(Je);vt!==-1&&_e[Ne].splice(vt,1),_e[Ne].length||delete _e[Ne]}},sub:function(Ne,Je){return $.on(Ne,Je),function(){return $.off(Ne,Je)}},supportsFiber:!0,checkDCE:function(Ne){try{Function.prototype.toString.call(Ne).indexOf("^_^")>-1&&(Y=!0,setTimeout(function(){throw new Error("React is running in production mode, but dead code elimination has not been applied. Read how to correctly configure React for production: https://reactjs.org/link/perf-use-production-build")}))}catch{}},onCommitFiberUnmount:function(Ne,Je){var vt=Ce.get(Ne);vt!=null&&vt.handleCommitFiberUnmount(Je)},onCommitFiberRoot:function(Ne,Je,vt){var oe=$.getFiberRoots(Ne),qe=Je.current,rt=oe.has(Je),xt=qe.memoizedState==null||qe.memoizedState.element==null;rt||xt?rt&&xt&&oe.delete(Je):oe.add(Je);var kt=Ce.get(Ne);kt!=null&&kt.handleCommitFiberRoot(Je,vt)}};Object.defineProperty(U,"__REACT_DEVTOOLS_GLOBAL_HOOK__",{configurable:!1,enumerable:!1,get:function(){return $}})})(window);var m0=window.__REACT_DEVTOOLS_GLOBAL_HOOK__,Us=[{type:1,value:7,isEnabled:!0}];function zi(U){if(m0!=null){var H=U||{},Y=H.host,ee=Y===void 0?"localhost":Y,Ce=H.nativeStyleEditorValidAttributes,_e=H.useHttps,Oe=_e!==void 0&&_e,$=H.port,Ne=$===void 0?8097:$,Je=H.websocket,vt=H.resolveRNStyle,oe=vt===void 0?null:vt,qe=H.isAppActive,rt=Oe?"wss":"ws",xt=null;if((qe===void 0?function(){return!0}:qe)()){var kt=null,bt=[],sn=rt+"://"+ee+":"+Ne,rn=Je||new window.WebSocket(sn);rn.onclose=function(){kt!==null&&kt.emit("shutdown"),Ft()},rn.onerror=function(){Ft()},rn.onmessage=function(Dn){var dr;try{if(typeof Dn.data!="string")throw Error();dr=JSON.parse(Dn.data)}catch{return void console.error("[React DevTools] Failed to parse JSON: "+Dn.data)}bt.forEach(function(er){try{er(dr)}catch(Cr){throw console.log("[React DevTools] Error calling listener",dr),console.log("error:",Cr),Cr}})},rn.onopen=function(){(kt=new po({listen:function(Rn){return bt.push(Rn),function(){var Nr=bt.indexOf(Rn);Nr>=0&&bt.splice(Nr,1)}},send:function(Rn,Nr,y0){rn.readyState===rn.OPEN?rn.send(JSON.stringify({event:Rn,payload:Nr})):(kt!==null&&kt.shutdown(),Ft())}})).addListener("inspectElement",function(Rn){var Nr=Rn.id,y0=Rn.rendererID,Lr=Dn.rendererInterfaces[y0];if(Lr!=null){var ut=Lr.findNativeNodesForFiberID(Nr);ut!=null&&ut[0]!=null&&Dn.emit("showNativeHighlight",ut[0])}}),kt.addListener("updateComponentFilters",function(Rn){Us=Rn}),window.__REACT_DEVTOOLS_COMPONENT_FILTERS__==null&&kt.send("overrideComponentFilters",Us);var Dn=new Yn(kt);if(Dn.addListener("shutdown",function(){m0.emit("shutdown")}),function(Rn,Nr,y0){if(Rn==null)return function(){};var Lr=[Rn.sub("renderer-attached",function(et){var It=et.id,un=(et.renderer,et.rendererInterface);Nr.setRendererInterface(It,un),un.flushInitialOperations()}),Rn.sub("unsupported-renderer-version",function(et){Nr.onUnsupportedRenderer(et)}),Rn.sub("operations",Nr.onHookOperations),Rn.sub("traceUpdates",Nr.onTraceUpdates)],ut=function(et,It){var un=Rn.rendererInterfaces.get(et);un==null&&(typeof It.findFiberByHostInstance=="function"?un=Is(Rn,et,It,y0):It.ComponentTree&&(un=ac(Rn,et,It,y0)),un!=null&&Rn.rendererInterfaces.set(et,un)),un!=null?Rn.emit("renderer-attached",{id:et,renderer:It,rendererInterface:un}):Rn.emit("unsupported-renderer-version",et)};Rn.renderers.forEach(function(et,It){ut(It,et)}),Lr.push(Rn.sub("renderer",function(et){var It=et.id,un=et.renderer;ut(It,un)})),Rn.emit("react-devtools",Nr),Rn.reactDevtoolsAgent=Nr;var wt=function(){Lr.forEach(function(et){return et()}),Rn.rendererInterfaces.forEach(function(et){et.cleanup()}),Rn.reactDevtoolsAgent=null};Nr.addListener("shutdown",wt),Lr.push(function(){Nr.removeListener("shutdown",wt)})}(m0,Dn,window),oe!=null||m0.resolveRNStyle!=null)oa(kt,Dn,oe||m0.resolveRNStyle,Ce||m0.nativeStyleEditorValidAttributes||null);else{var dr,er,Cr=function(){kt!==null&&oa(kt,Dn,dr,er)};m0.hasOwnProperty("resolveRNStyle")||Object.defineProperty(m0,"resolveRNStyle",{enumerable:!1,get:function(){return dr},set:function(Rn){dr=Rn,Cr()}}),m0.hasOwnProperty("nativeStyleEditorValidAttributes")||Object.defineProperty(m0,"nativeStyleEditorValidAttributes",{enumerable:!1,get:function(){return er},set:function(Rn){er=Rn,Cr()}})}}}else Ft()}function Ft(){xt===null&&(xt=setTimeout(function(){return zi(U)},2e3))}}}])})});var FC=nt(LC=>{"use strict";Object.defineProperty(LC,"__esModule",{value:!0});kC();var wb=NC();wb.connectToDevTools()});var UC=nt(sg=>{"use strict";var BC=sg&&sg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(sg,"__esModule",{value:!0});var PC=z_(),Sb=BC(YS()),IC=BC(eh()),ps=BD();process.env.DEV==="true"&&FC();var bC=o=>{o==null||o.unsetMeasureFunc(),o==null||o.freeRecursive()};sg.default=Sb.default({schedulePassiveEffects:PC.unstable_scheduleCallback,cancelPassiveEffects:PC.unstable_cancelCallback,now:Date.now,getRootHostContext:()=>({isInsideText:!1}),prepareForCommit:()=>{},resetAfterCommit:o=>{if(o.isStaticDirty){o.isStaticDirty=!1,typeof o.onImmediateRender=="function"&&o.onImmediateRender();return}typeof o.onRender=="function"&&o.onRender()},getChildHostContext:(o,l)=>{let f=o.isInsideText,h=l==="ink-text"||l==="ink-virtual-text";return f===h?o:{isInsideText:h}},shouldSetTextContent:()=>!1,createInstance:(o,l,f,h)=>{if(h.isInsideText&&o==="ink-box")throw new Error(" can\u2019t be nested inside component");let E=o==="ink-text"&&h.isInsideText?"ink-virtual-text":o,t=ps.createNode(E);for(let[N,F]of Object.entries(l))N!=="children"&&(N==="style"?ps.setStyle(t,F):N==="internal_transform"?t.internal_transform=F:N==="internal_static"?t.internal_static=!0:ps.setAttribute(t,N,F));return t},createTextInstance:(o,l,f)=>{if(!f.isInsideText)throw new Error(`Text string "${o}" must be rendered inside component`);return ps.createTextNode(o)},resetTextContent:()=>{},hideTextInstance:o=>{ps.setTextNodeValue(o,"")},unhideTextInstance:(o,l)=>{ps.setTextNodeValue(o,l)},getPublicInstance:o=>o,hideInstance:o=>{var l;(l=o.yogaNode)===null||l===void 0||l.setDisplay(IC.default.DISPLAY_NONE)},unhideInstance:o=>{var l;(l=o.yogaNode)===null||l===void 0||l.setDisplay(IC.default.DISPLAY_FLEX)},appendInitialChild:ps.appendChildNode,appendChild:ps.appendChildNode,insertBefore:ps.insertBeforeNode,finalizeInitialChildren:(o,l,f,h)=>(o.internal_static&&(h.isStaticDirty=!0,h.staticNode=o),!1),supportsMutation:!0,appendChildToContainer:ps.appendChildNode,insertInContainerBefore:ps.insertBeforeNode,removeChildFromContainer:(o,l)=>{ps.removeChildNode(o,l),bC(l.yogaNode)},prepareUpdate:(o,l,f,h,E)=>{o.internal_static&&(E.isStaticDirty=!0);let t={},N=Object.keys(h);for(let F of N)if(h[F]!==f[F]){if(F==="style"&&typeof h.style=="object"&&typeof f.style=="object"){let x=h.style,j=f.style,q=Object.keys(x);for(let V of q){if(V==="borderStyle"||V==="borderColor"){if(typeof t.style!="object"){let re={};t.style=re}t.style.borderStyle=x.borderStyle,t.style.borderColor=x.borderColor}if(x[V]!==j[V]){if(typeof t.style!="object"){let re={};t.style=re}t.style[V]=x[V]}}continue}t[F]=h[F]}return t},commitUpdate:(o,l)=>{for(let[f,h]of Object.entries(l))f!=="children"&&(f==="style"?ps.setStyle(o,h):f==="internal_transform"?o.internal_transform=h:f==="internal_static"?o.internal_static=!0:ps.setAttribute(o,f,h))},commitTextUpdate:(o,l,f)=>{ps.setTextNodeValue(o,f)},removeChild:(o,l)=>{ps.removeChildNode(o,l),bC(l.yogaNode)}})});var zC=nt((sq,jC)=>{"use strict";jC.exports=(o,l=1,f)=>{if(f={indent:" ",includeEmptyLines:!1,...f},typeof o!="string")throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof o}\``);if(typeof l!="number")throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof l}\``);if(typeof f.indent!="string")throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof f.indent}\``);if(l===0)return o;let h=f.includeEmptyLines?/^/gm:/^(?!\s*$)/gm;return o.replace(h,f.indent.repeat(l))}});var HC=nt(ag=>{"use strict";var Tb=ag&&ag.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(ag,"__esModule",{value:!0});var r4=Tb(eh());ag.default=o=>o.getComputedWidth()-o.getComputedPadding(r4.default.EDGE_LEFT)-o.getComputedPadding(r4.default.EDGE_RIGHT)-o.getComputedBorder(r4.default.EDGE_LEFT)-o.getComputedBorder(r4.default.EDGE_RIGHT)});var qC=nt((fq,Cb)=>{Cb.exports={single:{topLeft:"\u250C",topRight:"\u2510",bottomRight:"\u2518",bottomLeft:"\u2514",vertical:"\u2502",horizontal:"\u2500"},double:{topLeft:"\u2554",topRight:"\u2557",bottomRight:"\u255D",bottomLeft:"\u255A",vertical:"\u2551",horizontal:"\u2550"},round:{topLeft:"\u256D",topRight:"\u256E",bottomRight:"\u256F",bottomLeft:"\u2570",vertical:"\u2502",horizontal:"\u2500"},bold:{topLeft:"\u250F",topRight:"\u2513",bottomRight:"\u251B",bottomLeft:"\u2517",vertical:"\u2503",horizontal:"\u2501"},singleDouble:{topLeft:"\u2553",topRight:"\u2556",bottomRight:"\u255C",bottomLeft:"\u2559",vertical:"\u2551",horizontal:"\u2500"},doubleSingle:{topLeft:"\u2552",topRight:"\u2555",bottomRight:"\u255B",bottomLeft:"\u2558",vertical:"\u2502",horizontal:"\u2550"},classic:{topLeft:"+",topRight:"+",bottomRight:"+",bottomLeft:"+",vertical:"|",horizontal:"-"}}});var VC=nt((cq,c3)=>{"use strict";var WC=qC();c3.exports=WC;c3.exports.default=WC});var YC=nt((dq,GC)=>{"use strict";GC.exports=(o,l=process.argv)=>{let f=o.startsWith("-")?"":o.length===1?"-":"--",h=l.indexOf(f+o),E=l.indexOf("--");return h!==-1&&(E===-1||h{"use strict";var xb=hi("os"),KC=hi("tty"),df=YC(),{env:Xo}=process,h2;df("no-color")||df("no-colors")||df("color=false")||df("color=never")?h2=0:(df("color")||df("colors")||df("color=true")||df("color=always"))&&(h2=1);"FORCE_COLOR"in Xo&&(Xo.FORCE_COLOR==="true"?h2=1:Xo.FORCE_COLOR==="false"?h2=0:h2=Xo.FORCE_COLOR.length===0?1:Math.min(parseInt(Xo.FORCE_COLOR,10),3));function d3(o){return o===0?!1:{level:o,hasBasic:!0,has256:o>=2,has16m:o>=3}}function p3(o,l){if(h2===0)return 0;if(df("color=16m")||df("color=full")||df("color=truecolor"))return 3;if(df("color=256"))return 2;if(o&&!l&&h2===void 0)return 0;let f=h2||0;if(Xo.TERM==="dumb")return f;if(process.platform==="win32"){let h=xb.release().split(".");return Number(h[0])>=10&&Number(h[2])>=10586?Number(h[2])>=14931?3:2:1}if("CI"in Xo)return["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI"].some(h=>h in Xo)||Xo.CI_NAME==="codeship"?1:f;if("TEAMCITY_VERSION"in Xo)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(Xo.TEAMCITY_VERSION)?1:0;if("GITHUB_ACTIONS"in Xo)return 1;if(Xo.COLORTERM==="truecolor")return 3;if("TERM_PROGRAM"in Xo){let h=parseInt((Xo.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(Xo.TERM_PROGRAM){case"iTerm.app":return h>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(Xo.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(Xo.TERM)||"COLORTERM"in Xo?1:f}function Rb(o){let l=p3(o,o&&o.isTTY);return d3(l)}XC.exports={supportsColor:Rb,stdout:d3(p3(!0,KC.isatty(1))),stderr:d3(p3(!0,KC.isatty(2)))}});var ZC=nt((hq,JC)=>{"use strict";var Ab=(o,l,f)=>{let h=o.indexOf(l);if(h===-1)return o;let E=l.length,t=0,N="";do N+=o.substr(t,h-t)+l+f,t=h+E,h=o.indexOf(l,t);while(h!==-1);return N+=o.substr(t),N},Ob=(o,l,f,h)=>{let E=0,t="";do{let N=o[h-1]==="\r";t+=o.substr(E,(N?h-1:h)-E)+l+(N?`\r +`:` +`)+f,E=h+1,h=o.indexOf(` +`,E)}while(h!==-1);return t+=o.substr(E),t};JC.exports={stringReplaceAll:Ab,stringEncaseCRLFWithFirstIndex:Ob}});var r6=nt((vq,n6)=>{"use strict";var Mb=/(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi,$C=/(?:^|\.)(\w+)(?:\(([^)]*)\))?/g,kb=/^(['"])((?:\\.|(?!\1)[^\\])*)\1$/,Nb=/\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi,Lb=new Map([["n",` +`],["r","\r"],["t"," "],["b","\b"],["f","\f"],["v","\v"],["0","\0"],["\\","\\"],["e","\x1B"],["a","\x07"]]);function t6(o){let l=o[0]==="u",f=o[1]==="{";return l&&!f&&o.length===5||o[0]==="x"&&o.length===3?String.fromCharCode(parseInt(o.slice(1),16)):l&&f?String.fromCodePoint(parseInt(o.slice(2,-1),16)):Lb.get(o)||o}function Fb(o,l){let f=[],h=l.trim().split(/\s*,\s*/g),E;for(let t of h){let N=Number(t);if(!Number.isNaN(N))f.push(N);else if(E=t.match(kb))f.push(E[2].replace(Nb,(F,k,x)=>k?t6(k):x));else throw new Error(`Invalid Chalk template style argument: ${t} (in style '${o}')`)}return f}function Pb(o){$C.lastIndex=0;let l=[],f;for(;(f=$C.exec(o))!==null;){let h=f[1];if(f[2]){let E=Fb(h,f[2]);l.push([h].concat(E))}else l.push([h])}return l}function e6(o,l){let f={};for(let E of l)for(let t of E.styles)f[t[0]]=E.inverse?null:t.slice(1);let h=o;for(let[E,t]of Object.entries(f))if(!!Array.isArray(t)){if(!(E in h))throw new Error(`Unknown Chalk style: ${E}`);h=t.length>0?h[E](...t):h[E]}return h}n6.exports=(o,l)=>{let f=[],h=[],E=[];if(l.replace(Mb,(t,N,F,k,x,j)=>{if(N)E.push(t6(N));else if(k){let q=E.join("");E=[],h.push(f.length===0?q:e6(o,f)(q)),f.push({inverse:F,styles:Pb(k)})}else if(x){if(f.length===0)throw new Error("Found extraneous } in Chalk template literal");h.push(e6(o,f)(E.join(""))),E=[],f.pop()}else E.push(j)}),h.push(E.join("")),f.length>0){let t=`Chalk template literal is missing ${f.length} closing bracket${f.length===1?"":"s"} (\`}\`)`;throw new Error(t)}return h.join("")}});var s4=nt((mq,a6)=>{"use strict";var fg=G_(),{stdout:v3,stderr:m3}=QC(),{stringReplaceAll:Ib,stringEncaseCRLFWithFirstIndex:bb}=ZC(),{isArray:i4}=Array,u6=["ansi","ansi","ansi256","ansi16m"],nm=Object.create(null),Bb=(o,l={})=>{if(l.level&&!(Number.isInteger(l.level)&&l.level>=0&&l.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let f=v3?v3.level:0;o.level=l.level===void 0?f:l.level},y3=class{constructor(l){return o6(l)}},o6=o=>{let l={};return Bb(l,o),l.template=(...f)=>s6(l.template,...f),Object.setPrototypeOf(l,u4.prototype),Object.setPrototypeOf(l.template,l),l.template.constructor=()=>{throw new Error("`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.")},l.template.Instance=y3,l.template};function u4(o){return o6(o)}for(let[o,l]of Object.entries(fg))nm[o]={get(){let f=o4(this,g3(l.open,l.close,this._styler),this._isEmpty);return Object.defineProperty(this,o,{value:f}),f}};nm.visible={get(){let o=o4(this,this._styler,!0);return Object.defineProperty(this,"visible",{value:o}),o}};var l6=["rgb","hex","keyword","hsl","hsv","hwb","ansi","ansi256"];for(let o of l6)nm[o]={get(){let{level:l}=this;return function(...f){let h=g3(fg.color[u6[l]][o](...f),fg.color.close,this._styler);return o4(this,h,this._isEmpty)}}};for(let o of l6){let l="bg"+o[0].toUpperCase()+o.slice(1);nm[l]={get(){let{level:f}=this;return function(...h){let E=g3(fg.bgColor[u6[f]][o](...h),fg.bgColor.close,this._styler);return o4(this,E,this._isEmpty)}}}}var Ub=Object.defineProperties(()=>{},{...nm,level:{enumerable:!0,get(){return this._generator.level},set(o){this._generator.level=o}}}),g3=(o,l,f)=>{let h,E;return f===void 0?(h=o,E=l):(h=f.openAll+o,E=l+f.closeAll),{open:o,close:l,openAll:h,closeAll:E,parent:f}},o4=(o,l,f)=>{let h=(...E)=>i4(E[0])&&i4(E[0].raw)?i6(h,s6(h,...E)):i6(h,E.length===1?""+E[0]:E.join(" "));return Object.setPrototypeOf(h,Ub),h._generator=o,h._styler=l,h._isEmpty=f,h},i6=(o,l)=>{if(o.level<=0||!l)return o._isEmpty?"":l;let f=o._styler;if(f===void 0)return l;let{openAll:h,closeAll:E}=f;if(l.indexOf("\x1B")!==-1)for(;f!==void 0;)l=Ib(l,f.close,f.open),f=f.parent;let t=l.indexOf(` +`);return t!==-1&&(l=bb(l,E,h,t)),h+l+E},h3,s6=(o,...l)=>{let[f]=l;if(!i4(f)||!i4(f.raw))return l.join(" ");let h=l.slice(1),E=[f.raw[0]];for(let t=1;t{"use strict";var jb=dg&&dg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(dg,"__esModule",{value:!0});var cg=jb(s4()),zb=/^(rgb|hsl|hsv|hwb)\(\s?(\d+),\s?(\d+),\s?(\d+)\s?\)$/,Hb=/^(ansi|ansi256)\(\s?(\d+)\s?\)$/,a4=(o,l)=>l==="foreground"?o:"bg"+o[0].toUpperCase()+o.slice(1);dg.default=(o,l,f)=>{if(!l)return o;if(l in cg.default){let E=a4(l,f);return cg.default[E](o)}if(l.startsWith("#")){let E=a4("hex",f);return cg.default[E](l)(o)}if(l.startsWith("ansi")){let E=Hb.exec(l);if(!E)return o;let t=a4(E[1],f),N=Number(E[2]);return cg.default[t](N)(o)}if(l.startsWith("rgb")||l.startsWith("hsl")||l.startsWith("hsv")||l.startsWith("hwb")){let E=zb.exec(l);if(!E)return o;let t=a4(E[1],f),N=Number(E[2]),F=Number(E[3]),k=Number(E[4]);return cg.default[t](N,F,k)(o)}return o}});var c6=nt(pg=>{"use strict";var f6=pg&&pg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(pg,"__esModule",{value:!0});var qb=f6(VC()),E3=f6(_3());pg.default=(o,l,f,h)=>{if(typeof f.style.borderStyle=="string"){let E=f.yogaNode.getComputedWidth(),t=f.yogaNode.getComputedHeight(),N=f.style.borderColor,F=qb.default[f.style.borderStyle],k=E3.default(F.topLeft+F.horizontal.repeat(E-2)+F.topRight,N,"foreground"),x=(E3.default(F.vertical,N,"foreground")+` +`).repeat(t-2),j=E3.default(F.bottomLeft+F.horizontal.repeat(E-2)+F.bottomRight,N,"foreground");h.write(o,l,k,{transformers:[]}),h.write(o,l+1,x,{transformers:[]}),h.write(o+E-1,l+1,x,{transformers:[]}),h.write(o,l+t-1,j,{transformers:[]})}}});var p6=nt(hg=>{"use strict";var ih=hg&&hg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(hg,"__esModule",{value:!0});var Wb=ih(eh()),Vb=ih(xD()),Gb=ih(zC()),Yb=ih(PD()),Kb=ih(HC()),Xb=ih(bD()),Qb=ih(c6()),Jb=(o,l)=>{var f;let h=(f=o.childNodes[0])===null||f===void 0?void 0:f.yogaNode;if(h){let E=h.getComputedLeft(),t=h.getComputedTop();l=` +`.repeat(t)+Gb.default(l,E)}return l},d6=(o,l,f)=>{var h;let{offsetX:E=0,offsetY:t=0,transformers:N=[],skipStaticElements:F}=f;if(F&&o.internal_static)return;let{yogaNode:k}=o;if(k){if(k.getDisplay()===Wb.default.DISPLAY_NONE)return;let x=E+k.getComputedLeft(),j=t+k.getComputedTop(),q=N;if(typeof o.internal_transform=="function"&&(q=[o.internal_transform,...N]),o.nodeName==="ink-text"){let V=Xb.default(o);if(V.length>0){let re=Vb.default(V),y=Kb.default(k);if(re>y){let me=(h=o.style.textWrap)!==null&&h!==void 0?h:"wrap";V=Yb.default(V,y,me)}V=Jb(o,V),l.write(x,j,V,{transformers:q})}return}if(o.nodeName==="ink-box"&&Qb.default(x,j,o,l),o.nodeName==="ink-root"||o.nodeName==="ink-box")for(let V of o.childNodes)d6(V,l,{offsetX:x,offsetY:j,transformers:q,skipStaticElements:F})}};hg.default=d6});var v6=nt((Eq,h6)=>{"use strict";h6.exports=o=>{o=Object.assign({onlyFirst:!1},o);let l=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(l,o.onlyFirst?void 0:"g")}});var y6=nt((Dq,D3)=>{"use strict";var Zb=v6(),m6=o=>typeof o=="string"?o.replace(Zb(),""):o;D3.exports=m6;D3.exports.default=m6});var E6=nt((wq,_6)=>{"use strict";var g6="[\uD800-\uDBFF][\uDC00-\uDFFF]";_6.exports=o=>o&&o.exact?new RegExp(`^${g6}$`):new RegExp(g6,"g")});var w6=nt((Sq,w3)=>{"use strict";var $b=y6(),eB=E6(),D6=o=>$b(o).replace(eB()," ").length;w3.exports=D6;w3.exports.default=D6});var C6=nt(vg=>{"use strict";var T6=vg&&vg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(vg,"__esModule",{value:!0});var S6=T6(LD()),tB=T6(w6()),S3=class{constructor(l){this.writes=[];let{width:f,height:h}=l;this.width=f,this.height=h}write(l,f,h,E){let{transformers:t}=E;!h||this.writes.push({x:l,y:f,text:h,transformers:t})}get(){let l=[];for(let h=0;hh.trimRight()).join(` +`),height:l.length}}};vg.default=S3});var A6=nt(mg=>{"use strict";var T3=mg&&mg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(mg,"__esModule",{value:!0});var nB=T3(eh()),x6=T3(p6()),R6=T3(C6());mg.default=(o,l)=>{var f;if(o.yogaNode.setWidth(l),o.yogaNode){o.yogaNode.calculateLayout(void 0,void 0,nB.default.DIRECTION_LTR);let h=new R6.default({width:o.yogaNode.getComputedWidth(),height:o.yogaNode.getComputedHeight()});x6.default(o,h,{skipStaticElements:!0});let E;!((f=o.staticNode)===null||f===void 0)&&f.yogaNode&&(E=new R6.default({width:o.staticNode.yogaNode.getComputedWidth(),height:o.staticNode.yogaNode.getComputedHeight()}),x6.default(o.staticNode,E,{skipStaticElements:!1}));let{output:t,height:N}=h.get();return{output:t,outputHeight:N,staticOutput:E?`${E.get().output} +`:""}}return{output:"",outputHeight:0,staticOutput:""}}});var N6=nt((xq,k6)=>{"use strict";var O6=hi("stream"),M6=["assert","count","countReset","debug","dir","dirxml","error","group","groupCollapsed","groupEnd","info","log","table","time","timeEnd","timeLog","trace","warn"],C3={},rB=o=>{let l=new O6.PassThrough,f=new O6.PassThrough;l.write=E=>o("stdout",E),f.write=E=>o("stderr",E);let h=new console.Console(l,f);for(let E of M6)C3[E]=console[E],console[E]=h[E];return()=>{for(let E of M6)console[E]=C3[E];C3={}}};k6.exports=rB});var R3=nt(x3=>{"use strict";Object.defineProperty(x3,"__esModule",{value:!0});x3.default=new WeakMap});var O3=nt(A3=>{"use strict";Object.defineProperty(A3,"__esModule",{value:!0});var iB=Mi(),L6=iB.createContext({exit:()=>{}});L6.displayName="InternalAppContext";A3.default=L6});var k3=nt(M3=>{"use strict";Object.defineProperty(M3,"__esModule",{value:!0});var uB=Mi(),F6=uB.createContext({stdin:void 0,setRawMode:()=>{},isRawModeSupported:!1,internal_exitOnCtrlC:!0});F6.displayName="InternalStdinContext";M3.default=F6});var L3=nt(N3=>{"use strict";Object.defineProperty(N3,"__esModule",{value:!0});var oB=Mi(),P6=oB.createContext({stdout:void 0,write:()=>{}});P6.displayName="InternalStdoutContext";N3.default=P6});var P3=nt(F3=>{"use strict";Object.defineProperty(F3,"__esModule",{value:!0});var lB=Mi(),I6=lB.createContext({stderr:void 0,write:()=>{}});I6.displayName="InternalStderrContext";F3.default=I6});var f4=nt(I3=>{"use strict";Object.defineProperty(I3,"__esModule",{value:!0});var sB=Mi(),b6=sB.createContext({activeId:void 0,add:()=>{},remove:()=>{},activate:()=>{},deactivate:()=>{},enableFocus:()=>{},disableFocus:()=>{},focusNext:()=>{},focusPrevious:()=>{}});b6.displayName="InternalFocusContext";I3.default=b6});var U6=nt((Lq,B6)=>{"use strict";var aB=/[|\\{}()[\]^$+*?.-]/g;B6.exports=o=>{if(typeof o!="string")throw new TypeError("Expected a string");return o.replace(aB,"\\$&")}});var q6=nt((Fq,H6)=>{"use strict";var fB=U6(),z6=[].concat(hi("module").builtinModules,"bootstrap_node","node").map(o=>new RegExp(`(?:\\(${o}\\.js:\\d+:\\d+\\)$|^\\s*at ${o}\\.js:\\d+:\\d+$)`));z6.push(/\(internal\/[^:]+:\d+:\d+\)$/,/\s*at internal\/[^:]+:\d+:\d+$/,/\/\.node-spawn-wrap-\w+-\w+\/node:\d+:\d+\)?$/);var yg=class{constructor(l){l={ignoredPackages:[],...l},"internals"in l||(l.internals=yg.nodeInternals()),"cwd"in l||(l.cwd=process.cwd()),this._cwd=l.cwd.replace(/\\/g,"/"),this._internals=[].concat(l.internals,cB(l.ignoredPackages)),this._wrapCallSite=l.wrapCallSite||!1}static nodeInternals(){return[...z6]}clean(l,f=0){f=" ".repeat(f),Array.isArray(l)||(l=l.split(` +`)),!/^\s*at /.test(l[0])&&/^\s*at /.test(l[1])&&(l=l.slice(1));let h=!1,E=null,t=[];return l.forEach(N=>{if(N=N.replace(/\\/g,"/"),this._internals.some(k=>k.test(N)))return;let F=/^\s*at /.test(N);h?N=N.trimEnd().replace(/^(\s+)at /,"$1"):(N=N.trim(),F&&(N=N.slice(3))),N=N.replace(`${this._cwd}/`,""),N&&(F?(E&&(t.push(E),E=null),t.push(N)):(h=!0,E=N))}),t.map(N=>`${f}${N} +`).join("")}captureString(l,f=this.captureString){typeof l=="function"&&(f=l,l=1/0);let{stackTraceLimit:h}=Error;l&&(Error.stackTraceLimit=l);let E={};Error.captureStackTrace(E,f);let{stack:t}=E;return Error.stackTraceLimit=h,this.clean(t)}capture(l,f=this.capture){typeof l=="function"&&(f=l,l=1/0);let{prepareStackTrace:h,stackTraceLimit:E}=Error;Error.prepareStackTrace=(F,k)=>this._wrapCallSite?k.map(this._wrapCallSite):k,l&&(Error.stackTraceLimit=l);let t={};Error.captureStackTrace(t,f);let{stack:N}=t;return Object.assign(Error,{prepareStackTrace:h,stackTraceLimit:E}),N}at(l=this.at){let[f]=this.capture(1,l);if(!f)return{};let h={line:f.getLineNumber(),column:f.getColumnNumber()};j6(h,f.getFileName(),this._cwd),f.isConstructor()&&(h.constructor=!0),f.isEval()&&(h.evalOrigin=f.getEvalOrigin()),f.isNative()&&(h.native=!0);let E;try{E=f.getTypeName()}catch{}E&&E!=="Object"&&E!=="[object Object]"&&(h.type=E);let t=f.getFunctionName();t&&(h.function=t);let N=f.getMethodName();return N&&t!==N&&(h.method=N),h}parseLine(l){let f=l&&l.match(dB);if(!f)return null;let h=f[1]==="new",E=f[2],t=f[3],N=f[4],F=Number(f[5]),k=Number(f[6]),x=f[7],j=f[8],q=f[9],V=f[10]==="native",re=f[11]===")",y,me={};if(j&&(me.line=Number(j)),q&&(me.column=Number(q)),re&&x){let De=0;for(let ge=x.length-1;ge>0;ge--)if(x.charAt(ge)===")")De++;else if(x.charAt(ge)==="("&&x.charAt(ge-1)===" "&&(De--,De===-1&&x.charAt(ge-1)===" ")){let ae=x.slice(0,ge-1);x=x.slice(ge+1),E+=` (${ae}`;break}}if(E){let De=E.match(pB);De&&(E=De[1],y=De[2])}return j6(me,x,this._cwd),h&&(me.constructor=!0),t&&(me.evalOrigin=t,me.evalLine=F,me.evalColumn=k,me.evalFile=N&&N.replace(/\\/g,"/")),V&&(me.native=!0),E&&(me.function=E),y&&E!==y&&(me.method=y),me}};function j6(o,l,f){l&&(l=l.replace(/\\/g,"/"),l.startsWith(`${f}/`)&&(l=l.slice(f.length+1)),o.file=l)}function cB(o){if(o.length===0)return[];let l=o.map(f=>fB(f));return new RegExp(`[/\\\\]node_modules[/\\\\](?:${l.join("|")})[/\\\\][^:]+:\\d+:\\d+`)}var dB=new RegExp("^(?:\\s*at )?(?:(new) )?(?:(.*?) \\()?(?:eval at ([^ ]+) \\((.+?):(\\d+):(\\d+)\\), )?(?:(.+?):(\\d+):(\\d+)|(native))(\\)?)$"),pB=/^(.*?) \[as (.*?)\]$/;H6.exports=yg});var V6=nt((Pq,W6)=>{"use strict";W6.exports=(o,l)=>o.replace(/^\t+/gm,f=>" ".repeat(f.length*(l||2)))});var Y6=nt((Iq,G6)=>{"use strict";var hB=V6(),vB=(o,l)=>{let f=[],h=o-l,E=o+l;for(let t=h;t<=E;t++)f.push(t);return f};G6.exports=(o,l,f)=>{if(typeof o!="string")throw new TypeError("Source code is missing.");if(!l||l<1)throw new TypeError("Line number must start from `1`.");if(o=hB(o).split(/\r?\n/),!(l>o.length))return f={around:3,...f},vB(l,f.around).filter(h=>o[h-1]!==void 0).map(h=>({line:h,value:o[h-1]}))}});var c4=nt(nc=>{"use strict";var mB=nc&&nc.__createBinding||(Object.create?function(o,l,f,h){h===void 0&&(h=f),Object.defineProperty(o,h,{enumerable:!0,get:function(){return l[f]}})}:function(o,l,f,h){h===void 0&&(h=f),o[h]=l[f]}),yB=nc&&nc.__setModuleDefault||(Object.create?function(o,l){Object.defineProperty(o,"default",{enumerable:!0,value:l})}:function(o,l){o.default=l}),gB=nc&&nc.__importStar||function(o){if(o&&o.__esModule)return o;var l={};if(o!=null)for(var f in o)f!=="default"&&Object.hasOwnProperty.call(o,f)&&mB(l,o,f);return yB(l,o),l},_B=nc&&nc.__rest||function(o,l){var f={};for(var h in o)Object.prototype.hasOwnProperty.call(o,h)&&l.indexOf(h)<0&&(f[h]=o[h]);if(o!=null&&typeof Object.getOwnPropertySymbols=="function")for(var E=0,h=Object.getOwnPropertySymbols(o);E{var{children:f}=o,h=_B(o,["children"]);let E=Object.assign(Object.assign({},h),{marginLeft:h.marginLeft||h.marginX||h.margin||0,marginRight:h.marginRight||h.marginX||h.margin||0,marginTop:h.marginTop||h.marginY||h.margin||0,marginBottom:h.marginBottom||h.marginY||h.margin||0,paddingLeft:h.paddingLeft||h.paddingX||h.padding||0,paddingRight:h.paddingRight||h.paddingX||h.padding||0,paddingTop:h.paddingTop||h.paddingY||h.padding||0,paddingBottom:h.paddingBottom||h.paddingY||h.padding||0});return K6.default.createElement("ink-box",{ref:l,style:E},f)});b3.displayName="Box";b3.defaultProps={flexDirection:"row",flexGrow:0,flexShrink:1};nc.default=b3});var j3=nt(gg=>{"use strict";var B3=gg&&gg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(gg,"__esModule",{value:!0});var EB=B3(Mi()),rm=B3(s4()),X6=B3(_3()),U3=({color:o,backgroundColor:l,dimColor:f,bold:h,italic:E,underline:t,strikethrough:N,inverse:F,wrap:k,children:x})=>{if(x==null)return null;let j=q=>(f&&(q=rm.default.dim(q)),o&&(q=X6.default(q,o,"foreground")),l&&(q=X6.default(q,l,"background")),h&&(q=rm.default.bold(q)),E&&(q=rm.default.italic(q)),t&&(q=rm.default.underline(q)),N&&(q=rm.default.strikethrough(q)),F&&(q=rm.default.inverse(q)),q);return EB.default.createElement("ink-text",{style:{flexGrow:0,flexShrink:1,flexDirection:"row",textWrap:k},internal_transform:j},x)};U3.displayName="Text";U3.defaultProps={dimColor:!1,bold:!1,italic:!1,underline:!1,strikethrough:!1,wrap:"wrap"};gg.default=U3});var $6=nt(rc=>{"use strict";var DB=rc&&rc.__createBinding||(Object.create?function(o,l,f,h){h===void 0&&(h=f),Object.defineProperty(o,h,{enumerable:!0,get:function(){return l[f]}})}:function(o,l,f,h){h===void 0&&(h=f),o[h]=l[f]}),wB=rc&&rc.__setModuleDefault||(Object.create?function(o,l){Object.defineProperty(o,"default",{enumerable:!0,value:l})}:function(o,l){o.default=l}),SB=rc&&rc.__importStar||function(o){if(o&&o.__esModule)return o;var l={};if(o!=null)for(var f in o)f!=="default"&&Object.hasOwnProperty.call(o,f)&&DB(l,o,f);return wB(l,o),l},_g=rc&&rc.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(rc,"__esModule",{value:!0});var Q6=SB(hi("fs")),Qo=_g(Mi()),J6=_g(q6()),TB=_g(Y6()),Z1=_g(c4()),Hc=_g(j3()),Z6=new J6.default({cwd:process.cwd(),internals:J6.default.nodeInternals()}),CB=({error:o})=>{let l=o.stack?o.stack.split(` +`).slice(1):void 0,f=l?Z6.parseLine(l[0]):void 0,h,E=0;if((f==null?void 0:f.file)&&(f==null?void 0:f.line)&&Q6.existsSync(f.file)){let t=Q6.readFileSync(f.file,"utf8");if(h=TB.default(t,f.line),h)for(let{line:N}of h)E=Math.max(E,String(N).length)}return Qo.default.createElement(Z1.default,{flexDirection:"column",padding:1},Qo.default.createElement(Z1.default,null,Qo.default.createElement(Hc.default,{backgroundColor:"red",color:"white"}," ","ERROR"," "),Qo.default.createElement(Hc.default,null," ",o.message)),f&&Qo.default.createElement(Z1.default,{marginTop:1},Qo.default.createElement(Hc.default,{dimColor:!0},f.file,":",f.line,":",f.column)),f&&h&&Qo.default.createElement(Z1.default,{marginTop:1,flexDirection:"column"},h.map(({line:t,value:N})=>Qo.default.createElement(Z1.default,{key:t},Qo.default.createElement(Z1.default,{width:E+1},Qo.default.createElement(Hc.default,{dimColor:t!==f.line,backgroundColor:t===f.line?"red":void 0,color:t===f.line?"white":void 0},String(t).padStart(E," "),":")),Qo.default.createElement(Hc.default,{key:t,backgroundColor:t===f.line?"red":void 0,color:t===f.line?"white":void 0}," "+N)))),o.stack&&Qo.default.createElement(Z1.default,{marginTop:1,flexDirection:"column"},o.stack.split(` +`).slice(1).map(t=>{let N=Z6.parseLine(t);return N?Qo.default.createElement(Z1.default,{key:t},Qo.default.createElement(Hc.default,{dimColor:!0},"- "),Qo.default.createElement(Hc.default,{dimColor:!0,bold:!0},N.function),Qo.default.createElement(Hc.default,{dimColor:!0,color:"gray"}," ","(",N.file,":",N.line,":",N.column,")")):Qo.default.createElement(Z1.default,{key:t},Qo.default.createElement(Hc.default,{dimColor:!0},"- "),Qo.default.createElement(Hc.default,{dimColor:!0,bold:!0},t))})))};rc.default=CB});var tx=nt(ic=>{"use strict";var xB=ic&&ic.__createBinding||(Object.create?function(o,l,f,h){h===void 0&&(h=f),Object.defineProperty(o,h,{enumerable:!0,get:function(){return l[f]}})}:function(o,l,f,h){h===void 0&&(h=f),o[h]=l[f]}),RB=ic&&ic.__setModuleDefault||(Object.create?function(o,l){Object.defineProperty(o,"default",{enumerable:!0,value:l})}:function(o,l){o.default=l}),AB=ic&&ic.__importStar||function(o){if(o&&o.__esModule)return o;var l={};if(o!=null)for(var f in o)f!=="default"&&Object.hasOwnProperty.call(o,f)&&xB(l,o,f);return RB(l,o),l},oh=ic&&ic.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(ic,"__esModule",{value:!0});var uh=AB(Mi()),ex=oh(rD()),OB=oh(O3()),MB=oh(k3()),kB=oh(L3()),NB=oh(P3()),LB=oh(f4()),FB=oh($6()),PB=" ",IB="\x1B[Z",bB="\x1B",d4=class extends uh.PureComponent{constructor(){super(...arguments),this.state={isFocusEnabled:!0,activeFocusId:void 0,focusables:[],error:void 0},this.rawModeEnabledCount=0,this.handleSetRawMode=l=>{let{stdin:f}=this.props;if(!this.isRawModeSupported())throw f===process.stdin?new Error(`Raw mode is not supported on the current process.stdin, which Ink uses as input stream by default. +Read about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported`):new Error(`Raw mode is not supported on the stdin provided to Ink. +Read about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported`);if(f.setEncoding("utf8"),l){this.rawModeEnabledCount===0&&(f.addListener("data",this.handleInput),f.resume(),f.setRawMode(!0)),this.rawModeEnabledCount++;return}--this.rawModeEnabledCount===0&&(f.setRawMode(!1),f.removeListener("data",this.handleInput),f.pause())},this.handleInput=l=>{l===""&&this.props.exitOnCtrlC&&this.handleExit(),l===bB&&this.state.activeFocusId&&this.setState({activeFocusId:void 0}),this.state.isFocusEnabled&&this.state.focusables.length>0&&(l===PB&&this.focusNext(),l===IB&&this.focusPrevious())},this.handleExit=l=>{this.isRawModeSupported()&&this.handleSetRawMode(!1),this.props.onExit(l)},this.enableFocus=()=>{this.setState({isFocusEnabled:!0})},this.disableFocus=()=>{this.setState({isFocusEnabled:!1})},this.focusNext=()=>{this.setState(l=>{let f=l.focusables[0].id;return{activeFocusId:this.findNextFocusable(l)||f}})},this.focusPrevious=()=>{this.setState(l=>{let f=l.focusables[l.focusables.length-1].id;return{activeFocusId:this.findPreviousFocusable(l)||f}})},this.addFocusable=(l,{autoFocus:f})=>{this.setState(h=>{let E=h.activeFocusId;return!E&&f&&(E=l),{activeFocusId:E,focusables:[...h.focusables,{id:l,isActive:!0}]}})},this.removeFocusable=l=>{this.setState(f=>({activeFocusId:f.activeFocusId===l?void 0:f.activeFocusId,focusables:f.focusables.filter(h=>h.id!==l)}))},this.activateFocusable=l=>{this.setState(f=>({focusables:f.focusables.map(h=>h.id!==l?h:{id:l,isActive:!0})}))},this.deactivateFocusable=l=>{this.setState(f=>({activeFocusId:f.activeFocusId===l?void 0:f.activeFocusId,focusables:f.focusables.map(h=>h.id!==l?h:{id:l,isActive:!1})}))},this.findNextFocusable=l=>{let f=l.focusables.findIndex(h=>h.id===l.activeFocusId);for(let h=f+1;h{let f=l.focusables.findIndex(h=>h.id===l.activeFocusId);for(let h=f-1;h>=0;h--)if(l.focusables[h].isActive)return l.focusables[h].id}}static getDerivedStateFromError(l){return{error:l}}isRawModeSupported(){return this.props.stdin.isTTY}render(){return uh.default.createElement(OB.default.Provider,{value:{exit:this.handleExit}},uh.default.createElement(MB.default.Provider,{value:{stdin:this.props.stdin,setRawMode:this.handleSetRawMode,isRawModeSupported:this.isRawModeSupported(),internal_exitOnCtrlC:this.props.exitOnCtrlC}},uh.default.createElement(kB.default.Provider,{value:{stdout:this.props.stdout,write:this.props.writeToStdout}},uh.default.createElement(NB.default.Provider,{value:{stderr:this.props.stderr,write:this.props.writeToStderr}},uh.default.createElement(LB.default.Provider,{value:{activeId:this.state.activeFocusId,add:this.addFocusable,remove:this.removeFocusable,activate:this.activateFocusable,deactivate:this.deactivateFocusable,enableFocus:this.enableFocus,disableFocus:this.disableFocus,focusNext:this.focusNext,focusPrevious:this.focusPrevious}},this.state.error?uh.default.createElement(FB.default,{error:this.state.error}):this.props.children)))))}componentDidMount(){ex.default.hide(this.props.stdout)}componentWillUnmount(){ex.default.show(this.props.stdout),this.isRawModeSupported()&&this.handleSetRawMode(!1)}componentDidCatch(l){this.handleExit(l)}};ic.default=d4;d4.displayName="InternalApp"});var ix=nt(uc=>{"use strict";var BB=uc&&uc.__createBinding||(Object.create?function(o,l,f,h){h===void 0&&(h=f),Object.defineProperty(o,h,{enumerable:!0,get:function(){return l[f]}})}:function(o,l,f,h){h===void 0&&(h=f),o[h]=l[f]}),UB=uc&&uc.__setModuleDefault||(Object.create?function(o,l){Object.defineProperty(o,"default",{enumerable:!0,value:l})}:function(o,l){o.default=l}),jB=uc&&uc.__importStar||function(o){if(o&&o.__esModule)return o;var l={};if(o!=null)for(var f in o)f!=="default"&&Object.hasOwnProperty.call(o,f)&&BB(l,o,f);return UB(l,o),l},oc=uc&&uc.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(uc,"__esModule",{value:!0});var zB=oc(Mi()),nx=sS(),HB=oc(TS()),qB=oc(ZE()),WB=oc(MS()),VB=oc(NS()),p4=oc(UC()),GB=oc(A6()),YB=oc(nD()),KB=oc(N6()),XB=jB(BD()),QB=oc(R3()),JB=oc(tx()),im=process.env.CI==="false"?!1:WB.default,rx=()=>{},z3=class{constructor(l){this.resolveExitPromise=()=>{},this.rejectExitPromise=()=>{},this.unsubscribeExit=()=>{},this.onRender=()=>{if(this.isUnmounted)return;let{output:f,outputHeight:h,staticOutput:E}=GB.default(this.rootNode,this.options.stdout.columns||80),t=E&&E!==` +`;if(this.options.debug){t&&(this.fullStaticOutput+=E),this.options.stdout.write(this.fullStaticOutput+f);return}if(im){t&&this.options.stdout.write(E),this.lastOutput=f;return}if(t&&(this.fullStaticOutput+=E),h>=this.options.stdout.rows){this.options.stdout.write(qB.default.clearTerminal+this.fullStaticOutput+f),this.lastOutput=f;return}t&&(this.log.clear(),this.options.stdout.write(E),this.log(f)),!t&&f!==this.lastOutput&&this.throttledLog(f),this.lastOutput=f},VB.default(this),this.options=l,this.rootNode=XB.createNode("ink-root"),this.rootNode.onRender=l.debug?this.onRender:nx.throttle(this.onRender,32,{leading:!0,trailing:!0}),this.rootNode.onImmediateRender=this.onRender,this.log=HB.default.create(l.stdout),this.throttledLog=l.debug?this.log:nx.throttle(this.log,void 0,{leading:!0,trailing:!0}),this.isUnmounted=!1,this.lastOutput="",this.fullStaticOutput="",this.container=p4.default.createContainer(this.rootNode,!1,!1),this.unsubscribeExit=YB.default(this.unmount,{alwaysLast:!1}),process.env.DEV==="true"&&p4.default.injectIntoDevTools({bundleType:0,version:"16.13.1",rendererPackageName:"ink"}),l.patchConsole&&this.patchConsole(),im||(l.stdout.on("resize",this.onRender),this.unsubscribeResize=()=>{l.stdout.off("resize",this.onRender)})}render(l){let f=zB.default.createElement(JB.default,{stdin:this.options.stdin,stdout:this.options.stdout,stderr:this.options.stderr,writeToStdout:this.writeToStdout,writeToStderr:this.writeToStderr,exitOnCtrlC:this.options.exitOnCtrlC,onExit:this.unmount},l);p4.default.updateContainer(f,this.container,null,rx)}writeToStdout(l){if(!this.isUnmounted){if(this.options.debug){this.options.stdout.write(l+this.fullStaticOutput+this.lastOutput);return}if(im){this.options.stdout.write(l);return}this.log.clear(),this.options.stdout.write(l),this.log(this.lastOutput)}}writeToStderr(l){if(!this.isUnmounted){if(this.options.debug){this.options.stderr.write(l),this.options.stdout.write(this.fullStaticOutput+this.lastOutput);return}if(im){this.options.stderr.write(l);return}this.log.clear(),this.options.stderr.write(l),this.log(this.lastOutput)}}unmount(l){this.isUnmounted||(this.onRender(),this.unsubscribeExit(),typeof this.restoreConsole=="function"&&this.restoreConsole(),typeof this.unsubscribeResize=="function"&&this.unsubscribeResize(),im?this.options.stdout.write(this.lastOutput+` +`):this.options.debug||this.log.done(),this.isUnmounted=!0,p4.default.updateContainer(null,this.container,null,rx),QB.default.delete(this.options.stdout),l instanceof Error?this.rejectExitPromise(l):this.resolveExitPromise())}waitUntilExit(){return this.exitPromise||(this.exitPromise=new Promise((l,f)=>{this.resolveExitPromise=l,this.rejectExitPromise=f})),this.exitPromise}clear(){!im&&!this.options.debug&&this.log.clear()}patchConsole(){this.options.debug||(this.restoreConsole=KB.default((l,f)=>{l==="stdout"&&this.writeToStdout(f),l==="stderr"&&(f.startsWith("The above error occurred")||this.writeToStderr(f))}))}};uc.default=z3});var ox=nt(Eg=>{"use strict";var ux=Eg&&Eg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(Eg,"__esModule",{value:!0});var ZB=ux(ix()),h4=ux(R3()),$B=hi("stream"),eU=(o,l)=>{let f=Object.assign({stdout:process.stdout,stdin:process.stdin,stderr:process.stderr,debug:!1,exitOnCtrlC:!0,patchConsole:!0},tU(l)),h=nU(f.stdout,()=>new ZB.default(f));return h.render(o),{rerender:h.render,unmount:()=>h.unmount(),waitUntilExit:h.waitUntilExit,cleanup:()=>h4.default.delete(f.stdout),clear:h.clear}};Eg.default=eU;var tU=(o={})=>o instanceof $B.Stream?{stdout:o,stdin:process.stdin}:o,nU=(o,l)=>{let f;return h4.default.has(o)?f=h4.default.get(o):(f=l(),h4.default.set(o,f)),f}});var sx=nt($1=>{"use strict";var rU=$1&&$1.__createBinding||(Object.create?function(o,l,f,h){h===void 0&&(h=f),Object.defineProperty(o,h,{enumerable:!0,get:function(){return l[f]}})}:function(o,l,f,h){h===void 0&&(h=f),o[h]=l[f]}),iU=$1&&$1.__setModuleDefault||(Object.create?function(o,l){Object.defineProperty(o,"default",{enumerable:!0,value:l})}:function(o,l){o.default=l}),uU=$1&&$1.__importStar||function(o){if(o&&o.__esModule)return o;var l={};if(o!=null)for(var f in o)f!=="default"&&Object.hasOwnProperty.call(o,f)&&rU(l,o,f);return iU(l,o),l};Object.defineProperty($1,"__esModule",{value:!0});var Dg=uU(Mi()),lx=o=>{let{items:l,children:f,style:h}=o,[E,t]=Dg.useState(0),N=Dg.useMemo(()=>l.slice(E),[l,E]);Dg.useLayoutEffect(()=>{t(l.length)},[l.length]);let F=N.map((x,j)=>f(x,E+j)),k=Dg.useMemo(()=>Object.assign({position:"absolute",flexDirection:"column"},h),[h]);return Dg.default.createElement("ink-box",{internal_static:!0,style:k},F)};lx.displayName="Static";$1.default=lx});var fx=nt(wg=>{"use strict";var oU=wg&&wg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(wg,"__esModule",{value:!0});var lU=oU(Mi()),ax=({children:o,transform:l})=>o==null?null:lU.default.createElement("ink-text",{style:{flexGrow:0,flexShrink:1,flexDirection:"row"},internal_transform:l},o);ax.displayName="Transform";wg.default=ax});var dx=nt(Sg=>{"use strict";var sU=Sg&&Sg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(Sg,"__esModule",{value:!0});var aU=sU(Mi()),cx=({count:o=1})=>aU.default.createElement("ink-text",null,` +`.repeat(o));cx.displayName="Newline";Sg.default=cx});var vx=nt(Tg=>{"use strict";var px=Tg&&Tg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(Tg,"__esModule",{value:!0});var fU=px(Mi()),cU=px(c4()),hx=()=>fU.default.createElement(cU.default,{flexGrow:1});hx.displayName="Spacer";Tg.default=hx});var v4=nt(Cg=>{"use strict";var dU=Cg&&Cg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(Cg,"__esModule",{value:!0});var pU=Mi(),hU=dU(k3()),vU=()=>pU.useContext(hU.default);Cg.default=vU});var yx=nt(xg=>{"use strict";var mU=xg&&xg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(xg,"__esModule",{value:!0});var mx=Mi(),yU=mU(v4()),gU=(o,l={})=>{let{stdin:f,setRawMode:h,internal_exitOnCtrlC:E}=yU.default();mx.useEffect(()=>{if(l.isActive!==!1)return h(!0),()=>{h(!1)}},[l.isActive,h]),mx.useEffect(()=>{if(l.isActive===!1)return;let t=N=>{let F=String(N),k={upArrow:F==="\x1B[A",downArrow:F==="\x1B[B",leftArrow:F==="\x1B[D",rightArrow:F==="\x1B[C",pageDown:F==="\x1B[6~",pageUp:F==="\x1B[5~",return:F==="\r",escape:F==="\x1B",ctrl:!1,shift:!1,tab:F===" "||F==="\x1B[Z",backspace:F==="\b",delete:F==="\x7F"||F==="\x1B[3~",meta:!1};F<=""&&!k.return&&(F=String.fromCharCode(F.charCodeAt(0)+"a".charCodeAt(0)-1),k.ctrl=!0),F.startsWith("\x1B")&&(F=F.slice(1),k.meta=!0);let x=F>="A"&&F<="Z",j=F>="\u0410"&&F<="\u042F";F.length===1&&(x||j)&&(k.shift=!0),k.tab&&F==="[Z"&&(k.shift=!0),(k.tab||k.backspace||k.delete)&&(F=""),(!(F==="c"&&k.ctrl)||!E)&&o(F,k)};return f==null||f.on("data",t),()=>{f==null||f.off("data",t)}},[l.isActive,f,E,o])};xg.default=gU});var gx=nt(Rg=>{"use strict";var _U=Rg&&Rg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(Rg,"__esModule",{value:!0});var EU=Mi(),DU=_U(O3()),wU=()=>EU.useContext(DU.default);Rg.default=wU});var _x=nt(Ag=>{"use strict";var SU=Ag&&Ag.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(Ag,"__esModule",{value:!0});var TU=Mi(),CU=SU(L3()),xU=()=>TU.useContext(CU.default);Ag.default=xU});var Ex=nt(Og=>{"use strict";var RU=Og&&Og.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(Og,"__esModule",{value:!0});var AU=Mi(),OU=RU(P3()),MU=()=>AU.useContext(OU.default);Og.default=MU});var wx=nt(kg=>{"use strict";var Dx=kg&&kg.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(kg,"__esModule",{value:!0});var Mg=Mi(),kU=Dx(f4()),NU=Dx(v4()),LU=({isActive:o=!0,autoFocus:l=!1}={})=>{let{isRawModeSupported:f,setRawMode:h}=NU.default(),{activeId:E,add:t,remove:N,activate:F,deactivate:k}=Mg.useContext(kU.default),x=Mg.useMemo(()=>Math.random().toString().slice(2,7),[]);return Mg.useEffect(()=>(t(x,{autoFocus:l}),()=>{N(x)}),[x,l]),Mg.useEffect(()=>{o?F(x):k(x)},[o,x]),Mg.useEffect(()=>{if(!(!f||!o))return h(!0),()=>{h(!1)}},[o]),{isFocused:Boolean(x)&&E===x}};kg.default=LU});var Sx=nt(Ng=>{"use strict";var FU=Ng&&Ng.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(Ng,"__esModule",{value:!0});var PU=Mi(),IU=FU(f4()),bU=()=>{let o=PU.useContext(IU.default);return{enableFocus:o.enableFocus,disableFocus:o.disableFocus,focusNext:o.focusNext,focusPrevious:o.focusPrevious}};Ng.default=bU});var Tx=nt(H3=>{"use strict";Object.defineProperty(H3,"__esModule",{value:!0});H3.default=o=>{var l,f,h,E;return{width:(f=(l=o.yogaNode)===null||l===void 0?void 0:l.getComputedWidth())!==null&&f!==void 0?f:0,height:(E=(h=o.yogaNode)===null||h===void 0?void 0:h.getComputedHeight())!==null&&E!==void 0?E:0}}});var lc=nt(Yl=>{"use strict";Object.defineProperty(Yl,"__esModule",{value:!0});var BU=ox();Object.defineProperty(Yl,"render",{enumerable:!0,get:function(){return BU.default}});var UU=c4();Object.defineProperty(Yl,"Box",{enumerable:!0,get:function(){return UU.default}});var jU=j3();Object.defineProperty(Yl,"Text",{enumerable:!0,get:function(){return jU.default}});var zU=sx();Object.defineProperty(Yl,"Static",{enumerable:!0,get:function(){return zU.default}});var HU=fx();Object.defineProperty(Yl,"Transform",{enumerable:!0,get:function(){return HU.default}});var qU=dx();Object.defineProperty(Yl,"Newline",{enumerable:!0,get:function(){return qU.default}});var WU=vx();Object.defineProperty(Yl,"Spacer",{enumerable:!0,get:function(){return WU.default}});var VU=yx();Object.defineProperty(Yl,"useInput",{enumerable:!0,get:function(){return VU.default}});var GU=gx();Object.defineProperty(Yl,"useApp",{enumerable:!0,get:function(){return GU.default}});var YU=v4();Object.defineProperty(Yl,"useStdin",{enumerable:!0,get:function(){return YU.default}});var KU=_x();Object.defineProperty(Yl,"useStdout",{enumerable:!0,get:function(){return KU.default}});var XU=Ex();Object.defineProperty(Yl,"useStderr",{enumerable:!0,get:function(){return XU.default}});var QU=wx();Object.defineProperty(Yl,"useFocus",{enumerable:!0,get:function(){return QU.default}});var JU=Sx();Object.defineProperty(Yl,"useFocusManager",{enumerable:!0,get:function(){return JU.default}});var ZU=Tx();Object.defineProperty(Yl,"measureElement",{enumerable:!0,get:function(){return ZU.default}})});var Fx=nt(Lg=>{"use strict";Object.defineProperty(Lg,"__esModule",{value:!0});Lg.UncontrolledTextInput=void 0;var Nx=Mi(),V3=Mi(),kx=lc(),ah=s4(),Lx=({value:o,placeholder:l="",focus:f=!0,mask:h,highlightPastedText:E=!1,showCursor:t=!0,onChange:N,onSubmit:F})=>{let[{cursorOffset:k,cursorWidth:x},j]=V3.useState({cursorOffset:(o||"").length,cursorWidth:0});V3.useEffect(()=>{j(me=>{if(!f||!t)return me;let De=o||"";return me.cursorOffset>De.length-1?{cursorOffset:De.length,cursorWidth:0}:me})},[o,f,t]);let q=E?x:0,V=h?h.repeat(o.length):o,re=V,y=l?ah.grey(l):void 0;if(t&&f){y=l.length>0?ah.inverse(l[0])+ah.grey(l.slice(1)):ah.inverse(" "),re=V.length>0?"":ah.inverse(" ");let me=0;for(let De of V)me>=k-q&&me<=k?re+=ah.inverse(De):re+=De,me++;V.length>0&&k===V.length&&(re+=ah.inverse(" "))}return kx.useInput((me,De)=>{if(De.upArrow||De.downArrow||De.ctrl&&me==="c"||De.tab||De.shift&&De.tab)return;if(De.return){F&&F(o);return}let ge=k,ae=o,we=0;De.leftArrow?t&&ge--:De.rightArrow?t&&ge++:De.backspace||De.delete?k>0&&(ae=o.slice(0,k-1)+o.slice(k,o.length),ge--):(ae=o.slice(0,k)+me+o.slice(k,o.length),ge+=me.length,me.length>1&&(we=me.length)),k<0&&(ge=0),k>o.length&&(ge=o.length),j({cursorOffset:ge,cursorWidth:we}),ae!==o&&N(ae)},{isActive:f}),Nx.createElement(kx.Text,null,l?V.length>0?re:y:re)};Lg.default=Lx;Lg.UncontrolledTextInput=o=>{let[l,f]=V3.useState("");return Nx.createElement(Lx,Object.assign({},o,{value:l,onChange:f}))}});var Ix=nt(S4=>{"use strict";Object.defineProperty(S4,"__esModule",{value:!0});function Fg(o){let l=[...o.caches],f=l.shift();return f===void 0?Px():{get(h,E,t={miss:()=>Promise.resolve()}){return f.get(h,E,t).catch(()=>Fg({caches:l}).get(h,E,t))},set(h,E){return f.set(h,E).catch(()=>Fg({caches:l}).set(h,E))},delete(h){return f.delete(h).catch(()=>Fg({caches:l}).delete(h))},clear(){return f.clear().catch(()=>Fg({caches:l}).clear())}}}function Px(){return{get(o,l,f={miss:()=>Promise.resolve()}){return l().then(E=>Promise.all([E,f.miss(E)])).then(([E])=>E)},set(o,l){return Promise.resolve(l)},delete(o){return Promise.resolve()},clear(){return Promise.resolve()}}}S4.createFallbackableCache=Fg;S4.createNullCache=Px});var Bx=nt((EW,bx)=>{bx.exports=Ix()});var Ux=nt(G3=>{"use strict";Object.defineProperty(G3,"__esModule",{value:!0});function $U(o={serializable:!0}){let l={};return{get(f,h,E={miss:()=>Promise.resolve()}){let t=JSON.stringify(f);if(t in l)return Promise.resolve(o.serializable?JSON.parse(l[t]):l[t]);let N=h(),F=E&&E.miss||(()=>Promise.resolve());return N.then(k=>F(k)).then(()=>N)},set(f,h){return l[JSON.stringify(f)]=o.serializable?JSON.stringify(h):h,Promise.resolve(h)},delete(f){return delete l[JSON.stringify(f)],Promise.resolve()},clear(){return l={},Promise.resolve()}}}G3.createInMemoryCache=$U});var zx=nt((wW,jx)=>{jx.exports=Ux()});var qx=nt(sc=>{"use strict";Object.defineProperty(sc,"__esModule",{value:!0});function ej(o,l,f){let h={"x-algolia-api-key":f,"x-algolia-application-id":l};return{headers(){return o===Y3.WithinHeaders?h:{}},queryParameters(){return o===Y3.WithinQueryParameters?h:{}}}}function tj(o){let l=0,f=()=>(l++,new Promise(h=>{setTimeout(()=>{h(o(f))},Math.min(100*l,1e3))}));return o(f)}function Hx(o,l=(f,h)=>Promise.resolve()){return Object.assign(o,{wait(f){return Hx(o.then(h=>Promise.all([l(h,f),h])).then(h=>h[1]))}})}function nj(o){let l=o.length-1;for(l;l>0;l--){let f=Math.floor(Math.random()*(l+1)),h=o[l];o[l]=o[f],o[f]=h}return o}function rj(o,l){return Object.keys(l!==void 0?l:{}).forEach(f=>{o[f]=l[f](o)}),o}function ij(o,...l){let f=0;return o.replace(/%s/g,()=>encodeURIComponent(l[f++]))}var uj="4.2.0",oj=o=>()=>o.transporter.requester.destroy(),Y3={WithinQueryParameters:0,WithinHeaders:1};sc.AuthMode=Y3;sc.addMethods=rj;sc.createAuth=ej;sc.createRetryablePromise=tj;sc.createWaitablePromise=Hx;sc.destroy=oj;sc.encode=ij;sc.shuffle=nj;sc.version=uj});var Pg=nt((TW,Wx)=>{Wx.exports=qx()});var Vx=nt(K3=>{"use strict";Object.defineProperty(K3,"__esModule",{value:!0});var lj={Delete:"DELETE",Get:"GET",Post:"POST",Put:"PUT"};K3.MethodEnum=lj});var Ig=nt((xW,Gx)=>{Gx.exports=Vx()});var l5=nt(G0=>{"use strict";Object.defineProperty(G0,"__esModule",{value:!0});var Kx=Ig();function X3(o,l){let f=o||{},h=f.data||{};return Object.keys(f).forEach(E=>{["timeout","headers","queryParameters","data","cacheable"].indexOf(E)===-1&&(h[E]=f[E])}),{data:Object.entries(h).length>0?h:void 0,timeout:f.timeout||l,headers:f.headers||{},queryParameters:f.queryParameters||{},cacheable:f.cacheable}}var T4={Read:1,Write:2,Any:3},um={Up:1,Down:2,Timeouted:3},Xx=2*60*1e3;function J3(o,l=um.Up){return{...o,status:l,lastUpdate:Date.now()}}function Qx(o){return o.status===um.Up||Date.now()-o.lastUpdate>Xx}function Jx(o){return o.status===um.Timeouted&&Date.now()-o.lastUpdate<=Xx}function Z3(o){return{protocol:o.protocol||"https",url:o.url,accept:o.accept||T4.Any}}function sj(o,l){return Promise.all(l.map(f=>o.get(f,()=>Promise.resolve(J3(f))))).then(f=>{let h=f.filter(F=>Qx(F)),E=f.filter(F=>Jx(F)),t=[...h,...E],N=t.length>0?t.map(F=>Z3(F)):l;return{getTimeout(F,k){return(E.length===0&&F===0?1:E.length+3+F)*k},statelessHosts:N}})}var aj=({isTimedOut:o,status:l})=>!o&&~~l===0,fj=o=>{let l=o.status;return o.isTimedOut||aj(o)||~~(l/100)!==2&&~~(l/100)!==4},cj=({status:o})=>~~(o/100)===2,dj=(o,l)=>fj(o)?l.onRetry(o):cj(o)?l.onSucess(o):l.onFail(o);function Yx(o,l,f,h){let E=[],t=n5(f,h),N=r5(o,h),F=f.method,k=f.method!==Kx.MethodEnum.Get?{}:{...f.data,...h.data},x={"x-algolia-agent":o.userAgent.value,...o.queryParameters,...k,...h.queryParameters},j=0,q=(V,re)=>{let y=V.pop();if(y===void 0)throw o5(Q3(E));let me={data:t,headers:N,method:F,url:e5(y,f.path,x),connectTimeout:re(j,o.timeouts.connect),responseTimeout:re(j,h.timeout)},De=ae=>{let we={request:me,response:ae,host:y,triesLeft:V.length};return E.push(we),we},ge={onSucess:ae=>Zx(ae),onRetry(ae){let we=De(ae);return ae.isTimedOut&&j++,Promise.all([o.logger.info("Retryable failure",$3(we)),o.hostsCache.set(y,J3(y,ae.isTimedOut?um.Timeouted:um.Down))]).then(()=>q(V,re))},onFail(ae){throw De(ae),$x(ae,Q3(E))}};return o.requester.send(me).then(ae=>dj(ae,ge))};return sj(o.hostsCache,l).then(V=>q([...V.statelessHosts].reverse(),V.getTimeout))}function pj(o){let{hostsCache:l,logger:f,requester:h,requestsCache:E,responsesCache:t,timeouts:N,userAgent:F,hosts:k,queryParameters:x,headers:j}=o,q={hostsCache:l,logger:f,requester:h,requestsCache:E,responsesCache:t,timeouts:N,userAgent:F,headers:j,queryParameters:x,hosts:k.map(V=>Z3(V)),read(V,re){let y=X3(re,q.timeouts.read),me=()=>Yx(q,q.hosts.filter(ae=>(ae.accept&T4.Read)!==0),V,y);if((y.cacheable!==void 0?y.cacheable:V.cacheable)!==!0)return me();let ge={request:V,mappedRequestOptions:y,transporter:{queryParameters:q.queryParameters,headers:q.headers}};return q.responsesCache.get(ge,()=>q.requestsCache.get(ge,()=>q.requestsCache.set(ge,me()).then(ae=>Promise.all([q.requestsCache.delete(ge),ae]),ae=>Promise.all([q.requestsCache.delete(ge),Promise.reject(ae)])).then(([ae,we])=>we)),{miss:ae=>q.responsesCache.set(ge,ae)})},write(V,re){return Yx(q,q.hosts.filter(y=>(y.accept&T4.Write)!==0),V,X3(re,q.timeouts.write))}};return q}function hj(o){let l={value:`Algolia for JavaScript (${o})`,add(f){let h=`; ${f.segment}${f.version!==void 0?` (${f.version})`:""}`;return l.value.indexOf(h)===-1&&(l.value=`${l.value}${h}`),l}};return l}function Zx(o){try{return JSON.parse(o.content)}catch(l){throw u5(l.message,o)}}function $x({content:o,status:l},f){let h=o;try{h=JSON.parse(o).message}catch{}return i5(h,l,f)}function vj(o,...l){let f=0;return o.replace(/%s/g,()=>encodeURIComponent(l[f++]))}function e5(o,l,f){let h=t5(f),E=`${o.protocol}://${o.url}/${l.charAt(0)==="/"?l.substr(1):l}`;return h.length&&(E+=`?${h}`),E}function t5(o){let l=f=>Object.prototype.toString.call(f)==="[object Object]"||Object.prototype.toString.call(f)==="[object Array]";return Object.keys(o).map(f=>vj("%s=%s",f,l(o[f])?JSON.stringify(o[f]):o[f])).join("&")}function n5(o,l){if(o.method===Kx.MethodEnum.Get||o.data===void 0&&l.data===void 0)return;let f=Array.isArray(o.data)?o.data:{...o.data,...l.data};return JSON.stringify(f)}function r5(o,l){let f={...o.headers,...l.headers},h={};return Object.keys(f).forEach(E=>{let t=f[E];h[E.toLowerCase()]=t}),h}function Q3(o){return o.map(l=>$3(l))}function $3(o){let l=o.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return{...o,request:{...o.request,headers:{...o.request.headers,...l}}}}function i5(o,l,f){return{name:"ApiError",message:o,status:l,transporterStackTrace:f}}function u5(o,l){return{name:"DeserializationError",message:o,response:l}}function o5(o){return{name:"RetryError",message:"Unreachable hosts - your application id may be incorrect. If the error persists, contact support@algolia.com.",transporterStackTrace:o}}G0.CallEnum=T4;G0.HostStatusEnum=um;G0.createApiError=i5;G0.createDeserializationError=u5;G0.createMappedRequestOptions=X3;G0.createRetryError=o5;G0.createStatefulHost=J3;G0.createStatelessHost=Z3;G0.createTransporter=pj;G0.createUserAgent=hj;G0.deserializeFailure=$x;G0.deserializeSuccess=Zx;G0.isStatefulHostTimeouted=Jx;G0.isStatefulHostUp=Qx;G0.serializeData=n5;G0.serializeHeaders=r5;G0.serializeQueryParameters=t5;G0.serializeUrl=e5;G0.stackFrameWithoutCredentials=$3;G0.stackTraceWithoutCredentials=Q3});var bg=nt((AW,s5)=>{s5.exports=l5()});var a5=nt(y2=>{"use strict";Object.defineProperty(y2,"__esModule",{value:!0});var om=Pg(),mj=bg(),Bg=Ig(),yj=o=>{let l=o.region||"us",f=om.createAuth(om.AuthMode.WithinHeaders,o.appId,o.apiKey),h=mj.createTransporter({hosts:[{url:`analytics.${l}.algolia.com`}],...o,headers:{...f.headers(),"content-type":"application/json",...o.headers},queryParameters:{...f.queryParameters(),...o.queryParameters}}),E=o.appId;return om.addMethods({appId:E,transporter:h},o.methods)},gj=o=>(l,f)=>o.transporter.write({method:Bg.MethodEnum.Post,path:"2/abtests",data:l},f),_j=o=>(l,f)=>o.transporter.write({method:Bg.MethodEnum.Delete,path:om.encode("2/abtests/%s",l)},f),Ej=o=>(l,f)=>o.transporter.read({method:Bg.MethodEnum.Get,path:om.encode("2/abtests/%s",l)},f),Dj=o=>l=>o.transporter.read({method:Bg.MethodEnum.Get,path:"2/abtests"},l),wj=o=>(l,f)=>o.transporter.write({method:Bg.MethodEnum.Post,path:om.encode("2/abtests/%s/stop",l)},f);y2.addABTest=gj;y2.createAnalyticsClient=yj;y2.deleteABTest=_j;y2.getABTest=Ej;y2.getABTests=Dj;y2.stopABTest=wj});var c5=nt((MW,f5)=>{f5.exports=a5()});var p5=nt(Ug=>{"use strict";Object.defineProperty(Ug,"__esModule",{value:!0});var ew=Pg(),Sj=bg(),d5=Ig(),Tj=o=>{let l=o.region||"us",f=ew.createAuth(ew.AuthMode.WithinHeaders,o.appId,o.apiKey),h=Sj.createTransporter({hosts:[{url:`recommendation.${l}.algolia.com`}],...o,headers:{...f.headers(),"content-type":"application/json",...o.headers},queryParameters:{...f.queryParameters(),...o.queryParameters}});return ew.addMethods({appId:o.appId,transporter:h},o.methods)},Cj=o=>l=>o.transporter.read({method:d5.MethodEnum.Get,path:"1/strategies/personalization"},l),xj=o=>(l,f)=>o.transporter.write({method:d5.MethodEnum.Post,path:"1/strategies/personalization",data:l},f);Ug.createRecommendationClient=Tj;Ug.getPersonalizationStrategy=Cj;Ug.setPersonalizationStrategy=xj});var v5=nt((NW,h5)=>{h5.exports=p5()});var A5=nt(tn=>{"use strict";Object.defineProperty(tn,"__esModule",{value:!0});var Nn=Pg(),ra=bg(),Ur=Ig(),Rj=hi("crypto");function C4(o){let l=f=>o.request(f).then(h=>{if(o.batch!==void 0&&o.batch(h.hits),!o.shouldStop(h))return h.cursor?l({cursor:h.cursor}):l({page:(f.page||0)+1})});return l({})}var Aj=o=>{let l=o.appId,f=Nn.createAuth(o.authMode!==void 0?o.authMode:Nn.AuthMode.WithinHeaders,l,o.apiKey),h=ra.createTransporter({hosts:[{url:`${l}-dsn.algolia.net`,accept:ra.CallEnum.Read},{url:`${l}.algolia.net`,accept:ra.CallEnum.Write}].concat(Nn.shuffle([{url:`${l}-1.algolianet.com`},{url:`${l}-2.algolianet.com`},{url:`${l}-3.algolianet.com`}])),...o,headers:{...f.headers(),"content-type":"application/x-www-form-urlencoded",...o.headers},queryParameters:{...f.queryParameters(),...o.queryParameters}}),E={transporter:h,appId:l,addAlgoliaAgent(t,N){h.userAgent.add({segment:t,version:N})},clearCache(){return Promise.all([h.requestsCache.clear(),h.responsesCache.clear()]).then(()=>{})}};return Nn.addMethods(E,o.methods)};function m5(){return{name:"MissingObjectIDError",message:"All objects must have an unique objectID (like a primary key) to be valid. Algolia is also able to generate objectIDs automatically but *it's not recommended*. To do it, use the `{'autoGenerateObjectIDIfNotExist': true}` option."}}function y5(){return{name:"ObjectNotFoundError",message:"Object not found."}}function g5(){return{name:"ValidUntilNotFoundError",message:"ValidUntil not found in given secured api key."}}var Oj=o=>(l,f)=>{let{queryParameters:h,...E}=f||{},t={acl:l,...h!==void 0?{queryParameters:h}:{}},N=(F,k)=>Nn.createRetryablePromise(x=>jg(o)(F.key,k).catch(j=>{if(j.status!==404)throw j;return x()}));return Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Post,path:"1/keys",data:t},E),N)},Mj=o=>(l,f,h)=>{let E=ra.createMappedRequestOptions(h);return E.queryParameters["X-Algolia-User-ID"]=l,o.transporter.write({method:Ur.MethodEnum.Post,path:"1/clusters/mapping",data:{cluster:f}},E)},kj=o=>(l,f,h)=>o.transporter.write({method:Ur.MethodEnum.Post,path:"1/clusters/mapping/batch",data:{users:l,cluster:f}},h),x4=o=>(l,f,h)=>{let E=(t,N)=>zg(o)(l,{methods:{waitTask:xo}}).waitTask(t.taskID,N);return Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/operation",l),data:{operation:"copy",destination:f}},h),E)},Nj=o=>(l,f,h)=>x4(o)(l,f,{...h,scope:[A4.Rules]}),Lj=o=>(l,f,h)=>x4(o)(l,f,{...h,scope:[A4.Settings]}),Fj=o=>(l,f,h)=>x4(o)(l,f,{...h,scope:[A4.Synonyms]}),Pj=o=>(l,f)=>{let h=(E,t)=>Nn.createRetryablePromise(N=>jg(o)(l,t).then(N).catch(F=>{if(F.status!==404)throw F}));return Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Delete,path:Nn.encode("1/keys/%s",l)},f),h)},Ij=()=>(o,l)=>{let f=ra.serializeQueryParameters(l),h=Rj.createHmac("sha256",o).update(f).digest("hex");return Buffer.from(h+f).toString("base64")},jg=o=>(l,f)=>o.transporter.read({method:Ur.MethodEnum.Get,path:Nn.encode("1/keys/%s",l)},f),bj=o=>l=>o.transporter.read({method:Ur.MethodEnum.Get,path:"1/logs"},l),Bj=()=>o=>{let l=Buffer.from(o,"base64").toString("ascii"),f=/validUntil=(\d+)/,h=l.match(f);if(h===null)throw g5();return parseInt(h[1],10)-Math.round(new Date().getTime()/1e3)},Uj=o=>l=>o.transporter.read({method:Ur.MethodEnum.Get,path:"1/clusters/mapping/top"},l),jj=o=>(l,f)=>o.transporter.read({method:Ur.MethodEnum.Get,path:Nn.encode("1/clusters/mapping/%s",l)},f),zj=o=>l=>{let{retrieveMappings:f,...h}=l||{};return f===!0&&(h.getClusters=!0),o.transporter.read({method:Ur.MethodEnum.Get,path:"1/clusters/mapping/pending"},h)},zg=o=>(l,f={})=>{let h={transporter:o.transporter,appId:o.appId,indexName:l};return Nn.addMethods(h,f.methods)},Hj=o=>l=>o.transporter.read({method:Ur.MethodEnum.Get,path:"1/keys"},l),qj=o=>l=>o.transporter.read({method:Ur.MethodEnum.Get,path:"1/clusters"},l),Wj=o=>l=>o.transporter.read({method:Ur.MethodEnum.Get,path:"1/indexes"},l),Vj=o=>l=>o.transporter.read({method:Ur.MethodEnum.Get,path:"1/clusters/mapping"},l),Gj=o=>(l,f,h)=>{let E=(t,N)=>zg(o)(l,{methods:{waitTask:xo}}).waitTask(t.taskID,N);return Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/operation",l),data:{operation:"move",destination:f}},h),E)},Yj=o=>(l,f)=>{let h=(E,t)=>Promise.all(Object.keys(E.taskID).map(N=>zg(o)(N,{methods:{waitTask:xo}}).waitTask(E.taskID[N],t)));return Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Post,path:"1/indexes/*/batch",data:{requests:l}},f),h)},Kj=o=>(l,f)=>o.transporter.read({method:Ur.MethodEnum.Post,path:"1/indexes/*/objects",data:{requests:l}},f),Xj=o=>(l,f)=>{let h=l.map(E=>({...E,params:ra.serializeQueryParameters(E.params||{})}));return o.transporter.read({method:Ur.MethodEnum.Post,path:"1/indexes/*/queries",data:{requests:h},cacheable:!0},f)},Qj=o=>(l,f)=>Promise.all(l.map(h=>{let{facetName:E,facetQuery:t,...N}=h.params;return zg(o)(h.indexName,{methods:{searchForFacetValues:C5}}).searchForFacetValues(E,t,{...f,...N})})),Jj=o=>(l,f)=>{let h=ra.createMappedRequestOptions(f);return h.queryParameters["X-Algolia-User-ID"]=l,o.transporter.write({method:Ur.MethodEnum.Delete,path:"1/clusters/mapping"},h)},Zj=o=>(l,f)=>{let h=(E,t)=>Nn.createRetryablePromise(N=>jg(o)(l,t).catch(F=>{if(F.status!==404)throw F;return N()}));return Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Post,path:Nn.encode("1/keys/%s/restore",l)},f),h)},$j=o=>(l,f)=>o.transporter.read({method:Ur.MethodEnum.Post,path:"1/clusters/mapping/search",data:{query:l}},f),ez=o=>(l,f)=>{let h=Object.assign({},f),{queryParameters:E,...t}=f||{},N=E?{queryParameters:E}:{},F=["acl","indexes","referers","restrictSources","queryParameters","description","maxQueriesPerIPPerHour","maxHitsPerQuery"],k=j=>Object.keys(h).filter(q=>F.indexOf(q)!==-1).every(q=>j[q]===h[q]),x=(j,q)=>Nn.createRetryablePromise(V=>jg(o)(l,q).then(re=>k(re)?Promise.resolve():V()));return Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Put,path:Nn.encode("1/keys/%s",l),data:N},t),x)},_5=o=>(l,f)=>{let h=(E,t)=>xo(o)(E.taskID,t);return Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/batch",o.indexName),data:{requests:l}},f),h)},tz=o=>l=>C4({...l,shouldStop:f=>f.cursor===void 0,request:f=>o.transporter.read({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/browse",o.indexName),data:f},l)}),nz=o=>l=>{let f={hitsPerPage:1e3,...l};return C4({...f,shouldStop:h=>h.hits.length({...E,hits:E.hits.map(t=>(delete t._highlightResult,t))}))}})},rz=o=>l=>{let f={hitsPerPage:1e3,...l};return C4({...f,shouldStop:h=>h.hits.length({...E,hits:E.hits.map(t=>(delete t._highlightResult,t))}))}})},R4=o=>(l,f,h)=>{let{batchSize:E,...t}=h||{},N={taskIDs:[],objectIDs:[]},F=(k=0)=>{let x=[],j;for(j=k;j({action:f,body:q})),t).then(q=>(N.objectIDs=N.objectIDs.concat(q.objectIDs),N.taskIDs.push(q.taskID),j++,F(j)))};return Nn.createWaitablePromise(F(),(k,x)=>Promise.all(k.taskIDs.map(j=>xo(o)(j,x))))},iz=o=>l=>Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/clear",o.indexName)},l),(f,h)=>xo(o)(f.taskID,h)),uz=o=>l=>{let{forwardToReplicas:f,...h}=l||{},E=ra.createMappedRequestOptions(h);return f&&(E.queryParameters.forwardToReplicas=1),Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/rules/clear",o.indexName)},E),(t,N)=>xo(o)(t.taskID,N))},oz=o=>l=>{let{forwardToReplicas:f,...h}=l||{},E=ra.createMappedRequestOptions(h);return f&&(E.queryParameters.forwardToReplicas=1),Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/synonyms/clear",o.indexName)},E),(t,N)=>xo(o)(t.taskID,N))},lz=o=>(l,f)=>Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/deleteByQuery",o.indexName),data:l},f),(h,E)=>xo(o)(h.taskID,E)),sz=o=>l=>Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Delete,path:Nn.encode("1/indexes/%s",o.indexName)},l),(f,h)=>xo(o)(f.taskID,h)),az=o=>(l,f)=>Nn.createWaitablePromise(E5(o)([l],f).then(h=>({taskID:h.taskIDs[0]})),(h,E)=>xo(o)(h.taskID,E)),E5=o=>(l,f)=>{let h=l.map(E=>({objectID:E}));return R4(o)(h,fh.DeleteObject,f)},fz=o=>(l,f)=>{let{forwardToReplicas:h,...E}=f||{},t=ra.createMappedRequestOptions(E);return h&&(t.queryParameters.forwardToReplicas=1),Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Delete,path:Nn.encode("1/indexes/%s/rules/%s",o.indexName,l)},t),(N,F)=>xo(o)(N.taskID,F))},cz=o=>(l,f)=>{let{forwardToReplicas:h,...E}=f||{},t=ra.createMappedRequestOptions(E);return h&&(t.queryParameters.forwardToReplicas=1),Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Delete,path:Nn.encode("1/indexes/%s/synonyms/%s",o.indexName,l)},t),(N,F)=>xo(o)(N.taskID,F))},dz=o=>l=>D5(o)(l).then(()=>!0).catch(f=>{if(f.status!==404)throw f;return!1}),pz=o=>(l,f)=>{let{query:h,paginate:E,...t}=f||{},N=0,F=()=>T5(o)(h||"",{...t,page:N}).then(k=>{for(let[x,j]of Object.entries(k.hits))if(l(j))return{object:j,position:parseInt(x,10),page:N};if(N++,E===!1||N>=k.nbPages)throw y5();return F()});return F()},hz=o=>(l,f)=>o.transporter.read({method:Ur.MethodEnum.Get,path:Nn.encode("1/indexes/%s/%s",o.indexName,l)},f),vz=()=>(o,l)=>{for(let[f,h]of Object.entries(o.hits))if(h.objectID===l)return parseInt(f,10);return-1},mz=o=>(l,f)=>{let{attributesToRetrieve:h,...E}=f||{},t=l.map(N=>({indexName:o.indexName,objectID:N,...h?{attributesToRetrieve:h}:{}}));return o.transporter.read({method:Ur.MethodEnum.Post,path:"1/indexes/*/objects",data:{requests:t}},E)},yz=o=>(l,f)=>o.transporter.read({method:Ur.MethodEnum.Get,path:Nn.encode("1/indexes/%s/rules/%s",o.indexName,l)},f),D5=o=>l=>o.transporter.read({method:Ur.MethodEnum.Get,path:Nn.encode("1/indexes/%s/settings",o.indexName),data:{getVersion:2}},l),gz=o=>(l,f)=>o.transporter.read({method:Ur.MethodEnum.Get,path:Nn.encode("1/indexes/%s/synonyms/%s",o.indexName,l)},f),w5=o=>(l,f)=>o.transporter.read({method:Ur.MethodEnum.Get,path:Nn.encode("1/indexes/%s/task/%s",o.indexName,l.toString())},f),_z=o=>(l,f)=>Nn.createWaitablePromise(S5(o)([l],f).then(h=>({objectID:h.objectIDs[0],taskID:h.taskIDs[0]})),(h,E)=>xo(o)(h.taskID,E)),S5=o=>(l,f)=>{let{createIfNotExists:h,...E}=f||{},t=h?fh.PartialUpdateObject:fh.PartialUpdateObjectNoCreate;return R4(o)(l,t,E)},Ez=o=>(l,f)=>{let{safe:h,autoGenerateObjectIDIfNotExist:E,batchSize:t,...N}=f||{},F=(y,me,De,ge)=>Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/operation",y),data:{operation:De,destination:me}},ge),(ae,we)=>xo(o)(ae.taskID,we)),k=Math.random().toString(36).substring(7),x=`${o.indexName}_tmp_${k}`,j=tw({appId:o.appId,transporter:o.transporter,indexName:x}),q=[],V=F(o.indexName,x,"copy",{...N,scope:["settings","synonyms","rules"]});q.push(V);let re=(h?V.wait(N):V).then(()=>{let y=j(l,{...N,autoGenerateObjectIDIfNotExist:E,batchSize:t});return q.push(y),h?y.wait(N):y}).then(()=>{let y=F(x,o.indexName,"move",N);return q.push(y),h?y.wait(N):y}).then(()=>Promise.all(q)).then(([y,me,De])=>({objectIDs:me.objectIDs,taskIDs:[y.taskID,...me.taskIDs,De.taskID]}));return Nn.createWaitablePromise(re,(y,me)=>Promise.all(q.map(De=>De.wait(me))))},Dz=o=>(l,f)=>nw(o)(l,{...f,clearExistingRules:!0}),wz=o=>(l,f)=>rw(o)(l,{...f,replaceExistingSynonyms:!0}),Sz=o=>(l,f)=>Nn.createWaitablePromise(tw(o)([l],f).then(h=>({objectID:h.objectIDs[0],taskID:h.taskIDs[0]})),(h,E)=>xo(o)(h.taskID,E)),tw=o=>(l,f)=>{let{autoGenerateObjectIDIfNotExist:h,...E}=f||{},t=h?fh.AddObject:fh.UpdateObject;if(t===fh.UpdateObject){for(let N of l)if(N.objectID===void 0)return Nn.createWaitablePromise(Promise.reject(m5()))}return R4(o)(l,t,E)},Tz=o=>(l,f)=>nw(o)([l],f),nw=o=>(l,f)=>{let{forwardToReplicas:h,clearExistingRules:E,...t}=f||{},N=ra.createMappedRequestOptions(t);return h&&(N.queryParameters.forwardToReplicas=1),E&&(N.queryParameters.clearExistingRules=1),Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/rules/batch",o.indexName),data:l},N),(F,k)=>xo(o)(F.taskID,k))},Cz=o=>(l,f)=>rw(o)([l],f),rw=o=>(l,f)=>{let{forwardToReplicas:h,replaceExistingSynonyms:E,...t}=f||{},N=ra.createMappedRequestOptions(t);return h&&(N.queryParameters.forwardToReplicas=1),E&&(N.queryParameters.replaceExistingSynonyms=1),Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/synonyms/batch",o.indexName),data:l},N),(F,k)=>xo(o)(F.taskID,k))},T5=o=>(l,f)=>o.transporter.read({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/query",o.indexName),data:{query:l},cacheable:!0},f),C5=o=>(l,f,h)=>o.transporter.read({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/facets/%s/query",o.indexName,l),data:{facetQuery:f},cacheable:!0},h),x5=o=>(l,f)=>o.transporter.read({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/rules/search",o.indexName),data:{query:l}},f),R5=o=>(l,f)=>o.transporter.read({method:Ur.MethodEnum.Post,path:Nn.encode("1/indexes/%s/synonyms/search",o.indexName),data:{query:l}},f),xz=o=>(l,f)=>{let{forwardToReplicas:h,...E}=f||{},t=ra.createMappedRequestOptions(E);return h&&(t.queryParameters.forwardToReplicas=1),Nn.createWaitablePromise(o.transporter.write({method:Ur.MethodEnum.Put,path:Nn.encode("1/indexes/%s/settings",o.indexName),data:l},t),(N,F)=>xo(o)(N.taskID,F))},xo=o=>(l,f)=>Nn.createRetryablePromise(h=>w5(o)(l,f).then(E=>E.status!=="published"?h():void 0)),Rz={AddObject:"addObject",Analytics:"analytics",Browser:"browse",DeleteIndex:"deleteIndex",DeleteObject:"deleteObject",EditSettings:"editSettings",ListIndexes:"listIndexes",Logs:"logs",Recommendation:"recommendation",Search:"search",SeeUnretrievableAttributes:"seeUnretrievableAttributes",Settings:"settings",Usage:"usage"},fh={AddObject:"addObject",UpdateObject:"updateObject",PartialUpdateObject:"partialUpdateObject",PartialUpdateObjectNoCreate:"partialUpdateObjectNoCreate",DeleteObject:"deleteObject"},A4={Settings:"settings",Synonyms:"synonyms",Rules:"rules"},Az={None:"none",StopIfEnoughMatches:"stopIfEnoughMatches"},Oz={Synonym:"synonym",OneWaySynonym:"oneWaySynonym",AltCorrection1:"altCorrection1",AltCorrection2:"altCorrection2",Placeholder:"placeholder"};tn.ApiKeyACLEnum=Rz;tn.BatchActionEnum=fh;tn.ScopeEnum=A4;tn.StrategyEnum=Az;tn.SynonymEnum=Oz;tn.addApiKey=Oj;tn.assignUserID=Mj;tn.assignUserIDs=kj;tn.batch=_5;tn.browseObjects=tz;tn.browseRules=nz;tn.browseSynonyms=rz;tn.chunkedBatch=R4;tn.clearObjects=iz;tn.clearRules=uz;tn.clearSynonyms=oz;tn.copyIndex=x4;tn.copyRules=Nj;tn.copySettings=Lj;tn.copySynonyms=Fj;tn.createBrowsablePromise=C4;tn.createMissingObjectIDError=m5;tn.createObjectNotFoundError=y5;tn.createSearchClient=Aj;tn.createValidUntilNotFoundError=g5;tn.deleteApiKey=Pj;tn.deleteBy=lz;tn.deleteIndex=sz;tn.deleteObject=az;tn.deleteObjects=E5;tn.deleteRule=fz;tn.deleteSynonym=cz;tn.exists=dz;tn.findObject=pz;tn.generateSecuredApiKey=Ij;tn.getApiKey=jg;tn.getLogs=bj;tn.getObject=hz;tn.getObjectPosition=vz;tn.getObjects=mz;tn.getRule=yz;tn.getSecuredApiKeyRemainingValidity=Bj;tn.getSettings=D5;tn.getSynonym=gz;tn.getTask=w5;tn.getTopUserIDs=Uj;tn.getUserID=jj;tn.hasPendingMappings=zj;tn.initIndex=zg;tn.listApiKeys=Hj;tn.listClusters=qj;tn.listIndices=Wj;tn.listUserIDs=Vj;tn.moveIndex=Gj;tn.multipleBatch=Yj;tn.multipleGetObjects=Kj;tn.multipleQueries=Xj;tn.multipleSearchForFacetValues=Qj;tn.partialUpdateObject=_z;tn.partialUpdateObjects=S5;tn.removeUserID=Jj;tn.replaceAllObjects=Ez;tn.replaceAllRules=Dz;tn.replaceAllSynonyms=wz;tn.restoreApiKey=Zj;tn.saveObject=Sz;tn.saveObjects=tw;tn.saveRule=Tz;tn.saveRules=nw;tn.saveSynonym=Cz;tn.saveSynonyms=rw;tn.search=T5;tn.searchForFacetValues=C5;tn.searchRules=x5;tn.searchSynonyms=R5;tn.searchUserIDs=$j;tn.setSettings=xz;tn.updateApiKey=ez;tn.waitTask=xo});var M5=nt((FW,O5)=>{O5.exports=A5()});var k5=nt(O4=>{"use strict";Object.defineProperty(O4,"__esModule",{value:!0});function Mz(){return{debug(o,l){return Promise.resolve()},info(o,l){return Promise.resolve()},error(o,l){return Promise.resolve()}}}var kz={Debug:1,Info:2,Error:3};O4.LogLevelEnum=kz;O4.createNullLogger=Mz});var L5=nt((IW,N5)=>{N5.exports=k5()});var I5=nt(iw=>{"use strict";Object.defineProperty(iw,"__esModule",{value:!0});var F5=hi("http"),P5=hi("https"),Nz=hi("url");function Lz(){let o={keepAlive:!0},l=new F5.Agent(o),f=new P5.Agent(o);return{send(h){return new Promise(E=>{let t=Nz.parse(h.url),N=t.query===null?t.pathname:`${t.pathname}?${t.query}`,F={agent:t.protocol==="https:"?f:l,hostname:t.hostname,path:N,method:h.method,headers:h.headers,...t.port!==void 0?{port:t.port||""}:{}},k=(t.protocol==="https:"?P5:F5).request(F,V=>{let re="";V.on("data",y=>re+=y),V.on("end",()=>{clearTimeout(j),clearTimeout(q),E({status:V.statusCode||0,content:re,isTimedOut:!1})})}),x=(V,re)=>setTimeout(()=>{k.abort(),E({status:0,content:re,isTimedOut:!0})},V*1e3),j=x(h.connectTimeout,"Connection timeout"),q;k.on("error",V=>{clearTimeout(j),clearTimeout(q),E({status:0,content:V.message,isTimedOut:!1})}),k.once("response",()=>{clearTimeout(j),q=x(h.responseTimeout,"Socket timeout")}),h.data!==void 0&&k.write(h.data),k.end()})},destroy(){return l.destroy(),f.destroy(),Promise.resolve()}}}iw.createNodeHttpRequester=Lz});var B5=nt((BW,b5)=>{b5.exports=I5()});var H5=nt((UW,z5)=>{"use strict";var U5=Bx(),Fz=zx(),lm=c5(),ow=Pg(),uw=v5(),wn=M5(),Pz=L5(),Iz=B5(),bz=bg();function j5(o,l,f){let h={appId:o,apiKey:l,timeouts:{connect:2,read:5,write:30},requester:Iz.createNodeHttpRequester(),logger:Pz.createNullLogger(),responsesCache:U5.createNullCache(),requestsCache:U5.createNullCache(),hostsCache:Fz.createInMemoryCache(),userAgent:bz.createUserAgent(ow.version).add({segment:"Node.js",version:process.versions.node})};return wn.createSearchClient({...h,...f,methods:{search:wn.multipleQueries,searchForFacetValues:wn.multipleSearchForFacetValues,multipleBatch:wn.multipleBatch,multipleGetObjects:wn.multipleGetObjects,multipleQueries:wn.multipleQueries,copyIndex:wn.copyIndex,copySettings:wn.copySettings,copyRules:wn.copyRules,copySynonyms:wn.copySynonyms,moveIndex:wn.moveIndex,listIndices:wn.listIndices,getLogs:wn.getLogs,listClusters:wn.listClusters,multipleSearchForFacetValues:wn.multipleSearchForFacetValues,getApiKey:wn.getApiKey,addApiKey:wn.addApiKey,listApiKeys:wn.listApiKeys,updateApiKey:wn.updateApiKey,deleteApiKey:wn.deleteApiKey,restoreApiKey:wn.restoreApiKey,assignUserID:wn.assignUserID,assignUserIDs:wn.assignUserIDs,getUserID:wn.getUserID,searchUserIDs:wn.searchUserIDs,listUserIDs:wn.listUserIDs,getTopUserIDs:wn.getTopUserIDs,removeUserID:wn.removeUserID,hasPendingMappings:wn.hasPendingMappings,generateSecuredApiKey:wn.generateSecuredApiKey,getSecuredApiKeyRemainingValidity:wn.getSecuredApiKeyRemainingValidity,destroy:ow.destroy,initIndex:E=>t=>wn.initIndex(E)(t,{methods:{batch:wn.batch,delete:wn.deleteIndex,getObject:wn.getObject,getObjects:wn.getObjects,saveObject:wn.saveObject,saveObjects:wn.saveObjects,search:wn.search,searchForFacetValues:wn.searchForFacetValues,waitTask:wn.waitTask,setSettings:wn.setSettings,getSettings:wn.getSettings,partialUpdateObject:wn.partialUpdateObject,partialUpdateObjects:wn.partialUpdateObjects,deleteObject:wn.deleteObject,deleteObjects:wn.deleteObjects,deleteBy:wn.deleteBy,clearObjects:wn.clearObjects,browseObjects:wn.browseObjects,getObjectPosition:wn.getObjectPosition,findObject:wn.findObject,exists:wn.exists,saveSynonym:wn.saveSynonym,saveSynonyms:wn.saveSynonyms,getSynonym:wn.getSynonym,searchSynonyms:wn.searchSynonyms,browseSynonyms:wn.browseSynonyms,deleteSynonym:wn.deleteSynonym,clearSynonyms:wn.clearSynonyms,replaceAllObjects:wn.replaceAllObjects,replaceAllSynonyms:wn.replaceAllSynonyms,searchRules:wn.searchRules,getRule:wn.getRule,deleteRule:wn.deleteRule,saveRule:wn.saveRule,saveRules:wn.saveRules,replaceAllRules:wn.replaceAllRules,browseRules:wn.browseRules,clearRules:wn.clearRules}}),initAnalytics:()=>E=>lm.createAnalyticsClient({...h,...E,methods:{addABTest:lm.addABTest,getABTest:lm.getABTest,getABTests:lm.getABTests,stopABTest:lm.stopABTest,deleteABTest:lm.deleteABTest}}),initRecommendation:()=>E=>uw.createRecommendationClient({...h,...E,methods:{getPersonalizationStrategy:uw.getPersonalizationStrategy,setPersonalizationStrategy:uw.setPersonalizationStrategy}})}})}j5.version=ow.version;z5.exports=j5});var W5=nt((jW,lw)=>{var q5=H5();lw.exports=q5;lw.exports.default=q5});var Yz={};HF(Yz,{default:()=>Gz});var G5=hi("@yarnpkg/cli"),ch=hi("@yarnpkg/core");var Cx=V0(lc()),lh=V0(Mi()),m4=(0,lh.memo)(({active:o})=>{let l=(0,lh.useMemo)(()=>o?"\u25C9":"\u25EF",[o]),f=(0,lh.useMemo)(()=>o?"green":"yellow",[o]);return lh.default.createElement(Cx.Text,{color:f},l)});var m2=V0(lc()),na=V0(Mi());var xx=V0(lc()),y4=V0(Mi());function v2({active:o},l,f){let{stdin:h}=(0,xx.useStdin)(),E=(0,y4.useCallback)((t,N)=>l(t,N),f);(0,y4.useEffect)(()=>{if(!(!o||!h))return h.on("keypress",E),()=>{h.off("keypress",E)}},[o,E,h])}var Rx=function({active:o},l,f){v2({active:o},(h,E)=>{E.name==="tab"&&(E.shift?l("before"):l("after"))},f)};var g4=function(o,l,{active:f,minus:h,plus:E,set:t,loop:N=!0}){v2({active:f},(F,k)=>{let x=l.indexOf(o);switch(k.name){case h:{let j=x-1;if(N){t(l[(l.length+j)%l.length]);return}if(j<0)return;t(l[j])}break;case E:{let j=x+1;if(N){t(l[j%l.length]);return}if(j>=l.length)return;t(l[j])}break}},[l,o,E,t,N])};var _4=({active:o=!0,children:l=[],radius:f=10,size:h=1,loop:E=!0,onFocusRequest:t,willReachEnd:N})=>{let F=De=>{if(De.key===null)throw new Error("Expected all children to have a key");return De.key},k=na.default.Children.map(l,De=>F(De)),x=k[0],[j,q]=(0,na.useState)(x),V=k.indexOf(j);(0,na.useEffect)(()=>{k.includes(j)||q(x)},[l]),(0,na.useEffect)(()=>{N&&V>=k.length-2&&N()},[V]),Rx({active:o&&!!t},De=>{t==null||t(De)},[t]),g4(j,k,{active:o,minus:"up",plus:"down",set:q,loop:E});let re=V-f,y=V+f;y>k.length&&(re-=y-k.length,y=k.length),re<0&&(y+=-re,re=0),y>=k.length&&(y=k.length-1);let me=[];for(let De=re;De<=y;++De){let ge=k[De],ae=o&&ge===j;me.push(na.default.createElement(m2.Box,{key:ge,height:h},na.default.createElement(m2.Box,{marginLeft:1,marginRight:1},na.default.createElement(m2.Text,null,ae?na.default.createElement(m2.Text,{color:"cyan",bold:!0},">"):" ")),na.default.createElement(m2.Box,null,na.default.cloneElement(l[De],{active:ae}))))}return na.default.createElement(m2.Box,{flexDirection:"column",width:"100%"},me)};var E4=V0(Mi());var Ax=V0(lc()),ed=V0(Mi()),Ox=hi("readline"),q3=ed.default.createContext(null),Mx=({children:o})=>{let{stdin:l,setRawMode:f}=(0,Ax.useStdin)();(0,ed.useEffect)(()=>{f&&f(!0),l&&(0,Ox.emitKeypressEvents)(l)},[l,f]);let[h,E]=(0,ed.useState)(new Map),t=(0,ed.useMemo)(()=>({getAll:()=>h,get:N=>h.get(N),set:(N,F)=>E(new Map([...h,[N,F]]))}),[h,E]);return ed.default.createElement(q3.Provider,{value:t,children:o})};function sh(o,l){let f=(0,E4.useContext)(q3);if(f===null)throw new Error("Expected this hook to run with a ministore context attached");if(typeof o>"u")return f.getAll();let h=(0,E4.useCallback)(t=>{f.set(o,t)},[o,f.set]),E=f.get(o);return typeof E>"u"&&(E=l),[E,h]}var D4=V0(lc()),W3=V0(Mi());async function w4(o,l,{stdin:f,stdout:h,stderr:E}={}){let t,N=k=>{let{exit:x}=(0,D4.useApp)();v2({active:!0},(j,q)=>{q.name==="return"&&(t=k,x())},[x,k])},{waitUntilExit:F}=(0,D4.render)(W3.default.createElement(Mx,null,W3.default.createElement(o,{...l,useSubmit:N})),{stdin:f,stdout:h,stderr:E});return await F(),t}var Y5=hi("clipanion"),K5=V0(Fx()),or=V0(lc()),En=V0(Mi());var V5=V0(W5()),sw={appId:"OFCNCOG2CU",apiKey:"6fe4476ee5a1832882e326b506d14126",indexName:"npm-search"},Bz=(0,V5.default)(sw.appId,sw.apiKey).initIndex(sw.indexName),aw=async(o,l=0)=>await Bz.search(o,{analyticsTags:["yarn-plugin-interactive-tools"],attributesToRetrieve:["name","version","owner","repository","humanDownloadsLast30Days"],page:l,hitsPerPage:10});var Hg=["regular","dev","peer"],dh=class extends G5.BaseCommand{async execute(){let l=await ch.Configuration.find(this.context.cwd,this.context.plugins),f=()=>En.default.createElement(or.Box,{flexDirection:"row"},En.default.createElement(or.Box,{flexDirection:"column",width:48},En.default.createElement(or.Box,null,En.default.createElement(or.Text,null,"Press ",En.default.createElement(or.Text,{bold:!0,color:"cyanBright"},""),"/",En.default.createElement(or.Text,{bold:!0,color:"cyanBright"},"")," to move between packages.")),En.default.createElement(or.Box,null,En.default.createElement(or.Text,null,"Press ",En.default.createElement(or.Text,{bold:!0,color:"cyanBright"},"")," to select a package.")),En.default.createElement(or.Box,null,En.default.createElement(or.Text,null,"Press ",En.default.createElement(or.Text,{bold:!0,color:"cyanBright"},"")," again to change the target."))),En.default.createElement(or.Box,{flexDirection:"column"},En.default.createElement(or.Box,{marginLeft:1},En.default.createElement(or.Text,null,"Press ",En.default.createElement(or.Text,{bold:!0,color:"cyanBright"},"")," to install the selected packages.")),En.default.createElement(or.Box,{marginLeft:1},En.default.createElement(or.Text,null,"Press ",En.default.createElement(or.Text,{bold:!0,color:"cyanBright"},"")," to abort.")))),h=()=>En.default.createElement(En.default.Fragment,null,En.default.createElement(or.Box,{width:15},En.default.createElement(or.Text,{bold:!0,underline:!0,color:"gray"},"Owner")),En.default.createElement(or.Box,{width:11},En.default.createElement(or.Text,{bold:!0,underline:!0,color:"gray"},"Version")),En.default.createElement(or.Box,{width:10},En.default.createElement(or.Text,{bold:!0,underline:!0,color:"gray"},"Downloads"))),E=()=>En.default.createElement(or.Box,{width:17},En.default.createElement(or.Text,{bold:!0,underline:!0,color:"gray"},"Target")),t=({hit:re,active:y})=>{let[me,De]=sh(re.name,null);v2({active:y},(we,he)=>{if(he.name!=="space")return;if(!me){De(Hg[0]);return}let ve=Hg.indexOf(me)+1;ve===Hg.length?De(null):De(Hg[ve])},[me,De]);let ge=ch.structUtils.parseIdent(re.name),ae=ch.structUtils.prettyIdent(l,ge);return En.default.createElement(or.Box,null,En.default.createElement(or.Box,{width:45},En.default.createElement(or.Text,{bold:!0,wrap:"wrap"},ae)),En.default.createElement(or.Box,{width:14,marginLeft:1},En.default.createElement(or.Text,{bold:!0,wrap:"truncate"},re.owner.name)),En.default.createElement(or.Box,{width:10,marginLeft:1},En.default.createElement(or.Text,{italic:!0,wrap:"truncate"},re.version)),En.default.createElement(or.Box,{width:16,marginLeft:1},En.default.createElement(or.Text,null,re.humanDownloadsLast30Days)))},N=({name:re,active:y})=>{let[me]=sh(re,null),De=ch.structUtils.parseIdent(re);return En.default.createElement(or.Box,null,En.default.createElement(or.Box,{width:47},En.default.createElement(or.Text,{bold:!0}," - ",ch.structUtils.prettyIdent(l,De))),Hg.map(ge=>En.default.createElement(or.Box,{key:ge,width:14,marginLeft:1},En.default.createElement(or.Text,null," ",En.default.createElement(m4,{active:me===ge})," ",En.default.createElement(or.Text,{bold:!0},ge)))))},F=()=>En.default.createElement(or.Box,{marginTop:1},En.default.createElement(or.Text,null,"Powered by Algolia.")),x=await w4(({useSubmit:re})=>{let y=sh();re(y);let me=Array.from(y.keys()).filter(We=>y.get(We)!==null),[De,ge]=(0,En.useState)(""),[ae,we]=(0,En.useState)(0),[he,ve]=(0,En.useState)([]),ue=We=>{We.match(/\t| /)||ge(We)},Ae=async()=>{we(0);let We=await aw(De);We.query===De&&ve(We.hits)},ze=async()=>{let We=await aw(De,ae+1);We.query===De&&We.page-1===ae&&(we(We.page),ve([...he,...We.hits]))};return(0,En.useEffect)(()=>{De?Ae():ve([])},[De]),En.default.createElement(or.Box,{flexDirection:"column"},En.default.createElement(f,null),En.default.createElement(or.Box,{flexDirection:"row",marginTop:1},En.default.createElement(or.Text,{bold:!0},"Search: "),En.default.createElement(or.Box,{width:41},En.default.createElement(K5.default,{value:De,onChange:ue,placeholder:"i.e. babel, webpack, react...",showCursor:!1})),En.default.createElement(h,null)),he.length?En.default.createElement(_4,{radius:2,loop:!1,children:he.map(We=>En.default.createElement(t,{key:We.name,hit:We,active:!1})),willReachEnd:ze}):En.default.createElement(or.Text,{color:"gray"},"Start typing..."),En.default.createElement(or.Box,{flexDirection:"row",marginTop:1},En.default.createElement(or.Box,{width:49},En.default.createElement(or.Text,{bold:!0},"Selected:")),En.default.createElement(E,null)),me.length?me.map(We=>En.default.createElement(N,{key:We,name:We,active:!1})):En.default.createElement(or.Text,{color:"gray"},"No selected packages..."),En.default.createElement(F,null))},{},{stdin:this.context.stdin,stdout:this.context.stdout,stderr:this.context.stderr});if(typeof x>"u")return 1;let j=Array.from(x.keys()).filter(re=>x.get(re)==="regular"),q=Array.from(x.keys()).filter(re=>x.get(re)==="dev"),V=Array.from(x.keys()).filter(re=>x.get(re)==="peer");return j.length&&await this.cli.run(["add",...j]),q.length&&await this.cli.run(["add","--dev",...q]),V&&await this.cli.run(["add","--peer",...V]),0}};dh.paths=[["search"]],dh.usage=Y5.Command.Usage({category:"Interactive commands",description:"open the search interface",details:` + This command opens a fullscreen terminal interface where you can search for and install packages from the npm registry. + `,examples:[["Open the search window","yarn search"]]});var N4=hi("@yarnpkg/cli"),Ro=hi("@yarnpkg/core");var qg=V0(lc()),g2=V0(Mi());var X5=V0(lc()),Q5=V0(Mi()),M4=({length:o,active:l})=>{if(o===0)return null;let f=o>1?` ${"-".repeat(o-1)}`:" ";return Q5.default.createElement(X5.Text,{dimColor:!l},f)};var J5=function({active:o,skewer:l,options:f,value:h,onChange:E,sizes:t=[]}){let N=f.filter(({label:k})=>!!k).map(({value:k})=>k),F=f.findIndex(k=>k.value===h&&k.label!="");return g4(h,N,{active:o,minus:"left",plus:"right",set:E}),g2.default.createElement(g2.default.Fragment,null,f.map(({label:k},x)=>{let j=x===F,q=t[x]-1||0,V=k.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,""),re=Math.max(0,q-V.length-2);return k?g2.default.createElement(qg.Box,{key:k,width:q,marginLeft:1},g2.default.createElement(qg.Text,{wrap:"truncate"},g2.default.createElement(m4,{active:j})," ",k),l?g2.default.createElement(M4,{active:o,length:re}):null):g2.default.createElement(qg.Box,{key:`spacer-${x}`,width:q,marginLeft:1})}))};var r9=hi("@yarnpkg/plugin-essentials"),L4=hi("clipanion");function td(){}td.prototype={diff:function(l,f){var h=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},E=h.callback;typeof h=="function"&&(E=h,h={}),this.options=h;var t=this;function N(me){return E?(setTimeout(function(){E(void 0,me)},0),!0):me}l=this.castInput(l),f=this.castInput(f),l=this.removeEmpty(this.tokenize(l)),f=this.removeEmpty(this.tokenize(f));var F=f.length,k=l.length,x=1,j=F+k;h.maxEditLength&&(j=Math.min(j,h.maxEditLength));var q=[{newPos:-1,components:[]}],V=this.extractCommon(q[0],f,l,0);if(q[0].newPos+1>=F&&V+1>=k)return N([{value:this.join(f),count:f.length}]);function re(){for(var me=-1*x;me<=x;me+=2){var De=void 0,ge=q[me-1],ae=q[me+1],we=(ae?ae.newPos:0)-me;ge&&(q[me-1]=void 0);var he=ge&&ge.newPos+1=F&&we+1>=k)return N(Uz(t,De.components,f,l,t.useLongestToken));q[me]=De}x++}if(E)(function me(){setTimeout(function(){if(x>j)return E();re()||me()},0)})();else for(;x<=j;){var y=re();if(y)return y}},pushComponent:function(l,f,h){var E=l[l.length-1];E&&E.added===f&&E.removed===h?l[l.length-1]={count:E.count+1,added:f,removed:h}:l.push({count:1,added:f,removed:h})},extractCommon:function(l,f,h,E){for(var t=f.length,N=h.length,F=l.newPos,k=F-E,x=0;F+1re.length?me:re}),x.value=o.join(j)}else x.value=o.join(f.slice(F,F+x.count));F+=x.count,x.added||(k+=x.count)}}var V=l[N-1];return N>1&&typeof V.value=="string"&&(V.added||V.removed)&&o.equals("",V.value)&&(l[N-2].value+=V.value,l.pop()),l}function jz(o){return{newPos:o.newPos,components:o.components.slice(0)}}var rV=new td;function zz(o,l){if(typeof o=="function")l.callback=o;else if(o)for(var f in o)o.hasOwnProperty(f)&&(l[f]=o[f]);return l}var Z5=/^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/,$5=/\S/,dw=new td;dw.equals=function(o,l){return this.options.ignoreCase&&(o=o.toLowerCase(),l=l.toLowerCase()),o===l||this.options.ignoreWhitespace&&!$5.test(o)&&!$5.test(l)};dw.tokenize=function(o){for(var l=o.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/),f=0;f"u"?f:N}:h;return typeof o=="string"?o:JSON.stringify(fw(o,null,null,E),E," ")};Wg.equals=function(o,l){return td.prototype.equals.call(Wg,o.replace(/,([\r\n])/g,"$1"),l.replace(/,([\r\n])/g,"$1"))};function fw(o,l,f,h,E){l=l||[],f=f||[],h&&(o=h(E,o));var t;for(t=0;t=?)?)([0-9]+)(\.[0-9]+)(\.[0-9]+)((?:-\S+)?)$/,u9=(o,l)=>o.length>0?[o.slice(0,l)].concat(u9(o.slice(l),l)):[],ph=class extends N4.BaseCommand{async execute(){if(!this.context.stdout.isTTY)throw new L4.UsageError("This command can only be run in a TTY environment");let l=await Ro.Configuration.find(this.context.cwd,this.context.plugins),{project:f,workspace:h}=await Ro.Project.find(l,this.context.cwd),E=await Ro.Cache.find(l);if(!h)throw new N4.WorkspaceRequiredError(f.cwd,this.context.cwd);await f.restoreInstallState({restoreResolutions:!1});let t=this.context.stdout.rows-7,N=(ae,we)=>{let he=e9(ae,we),ve="";for(let ue of he)ue.added?ve+=Ro.formatUtils.pretty(l,ue.value,"green"):ue.removed||(ve+=ue.value);return ve},F=(ae,we)=>{if(ae===we)return we;let he=Ro.structUtils.parseRange(ae),ve=Ro.structUtils.parseRange(we),ue=he.selector.match(n9),Ae=ve.selector.match(n9);if(!ue||!Ae)return N(ae,we);let ze=["gray","red","yellow","green","magenta"],We=null,gt="";for(let _t=1;_t{let ve=await r9.suggestUtils.fetchDescriptorFrom(ae,he,{project:f,cache:E,preserveModifier:we,workspace:h});return ve!==null?ve.range:ae.range},x=async ae=>{let we=i9.default.valid(ae.range)?`^${ae.range}`:ae.range,[he,ve]=await Promise.all([k(ae,ae.range,we).catch(()=>null),k(ae,ae.range,"latest").catch(()=>null)]),ue=[{value:null,label:ae.range}];return he&&he!==ae.range?ue.push({value:he,label:F(ae.range,he)}):ue.push({value:null,label:""}),ve&&ve!==he&&ve!==ae.range?ue.push({value:ve,label:F(ae.range,ve)}):ue.push({value:null,label:""}),ue},j=()=>Tr.default.createElement(bi.Box,{flexDirection:"row"},Tr.default.createElement(bi.Box,{flexDirection:"column",width:49},Tr.default.createElement(bi.Box,{marginLeft:1},Tr.default.createElement(bi.Text,null,"Press ",Tr.default.createElement(bi.Text,{bold:!0,color:"cyanBright"},""),"/",Tr.default.createElement(bi.Text,{bold:!0,color:"cyanBright"},"")," to select packages.")),Tr.default.createElement(bi.Box,{marginLeft:1},Tr.default.createElement(bi.Text,null,"Press ",Tr.default.createElement(bi.Text,{bold:!0,color:"cyanBright"},""),"/",Tr.default.createElement(bi.Text,{bold:!0,color:"cyanBright"},"")," to select versions."))),Tr.default.createElement(bi.Box,{flexDirection:"column"},Tr.default.createElement(bi.Box,{marginLeft:1},Tr.default.createElement(bi.Text,null,"Press ",Tr.default.createElement(bi.Text,{bold:!0,color:"cyanBright"},"")," to install.")),Tr.default.createElement(bi.Box,{marginLeft:1},Tr.default.createElement(bi.Text,null,"Press ",Tr.default.createElement(bi.Text,{bold:!0,color:"cyanBright"},"")," to abort.")))),q=()=>Tr.default.createElement(bi.Box,{flexDirection:"row",paddingTop:1,paddingBottom:1},Tr.default.createElement(bi.Box,{width:50},Tr.default.createElement(bi.Text,{bold:!0},Tr.default.createElement(bi.Text,{color:"greenBright"},"?")," Pick the packages you want to upgrade.")),Tr.default.createElement(bi.Box,{width:17},Tr.default.createElement(bi.Text,{bold:!0,underline:!0,color:"gray"},"Current")),Tr.default.createElement(bi.Box,{width:17},Tr.default.createElement(bi.Text,{bold:!0,underline:!0,color:"gray"},"Range")),Tr.default.createElement(bi.Box,{width:17},Tr.default.createElement(bi.Text,{bold:!0,underline:!0,color:"gray"},"Latest"))),V=({active:ae,descriptor:we,suggestions:he})=>{let[ve,ue]=sh(we.descriptorHash,null),Ae=Ro.structUtils.stringifyIdent(we),ze=Math.max(0,45-Ae.length);return Tr.default.createElement(Tr.default.Fragment,null,Tr.default.createElement(bi.Box,null,Tr.default.createElement(bi.Box,{width:45},Tr.default.createElement(bi.Text,{bold:!0},Ro.structUtils.prettyIdent(l,we)),Tr.default.createElement(M4,{active:ae,length:ze})),Tr.default.createElement(J5,{active:ae,options:he,value:ve,skewer:!0,onChange:ue,sizes:[17,17,17]})))},re=({dependencies:ae})=>{let[we,he]=(0,Tr.useState)(ae.map(()=>null)),ve=(0,Tr.useRef)(!0),ue=async Ae=>{let ze=await x(Ae);return ze.filter(We=>We.label!=="").length<=1?null:{descriptor:Ae,suggestions:ze}};return(0,Tr.useEffect)(()=>()=>{ve.current=!1},[]),(0,Tr.useEffect)(()=>{let Ae=Math.trunc(t*1.75),ze=ae.slice(0,Ae),We=ae.slice(Ae),gt=u9(We,t),_t=ze.map(ue).reduce(async(Qe,ot)=>{await Qe;let Ve=await ot;Ve!==null&&(!ve.current||he(Pt=>{let Jt=Pt.findIndex(J=>J===null),it=[...Pt];return it[Jt]=Ve,it}))},Promise.resolve());gt.reduce((Qe,ot)=>Promise.all(ot.map(Ve=>Promise.resolve().then(()=>ue(Ve)))).then(async Ve=>{Ve=Ve.filter(Pt=>Pt!==null),await Qe,ve.current&&he(Pt=>{let Jt=Pt.findIndex(it=>it===null);return Pt.slice(0,Jt).concat(Ve).concat(Pt.slice(Jt+Ve.length))})}),_t).then(()=>{ve.current&&he(Qe=>Qe.filter(ot=>ot!==null))})},[]),we.length?Tr.default.createElement(_4,{radius:t>>1,children:we.map((Ae,ze)=>Ae!==null?Tr.default.createElement(V,{key:ze,active:!1,descriptor:Ae.descriptor,suggestions:Ae.suggestions}):Tr.default.createElement(bi.Text,{key:ze},"Loading..."))}):Tr.default.createElement(bi.Text,null,"No upgrades found")},me=await w4(({useSubmit:ae})=>{ae(sh());let we=new Map;for(let ve of f.workspaces)for(let ue of["dependencies","devDependencies"])for(let Ae of ve.manifest[ue].values())f.tryWorkspaceByDescriptor(Ae)===null&&(Ae.range.startsWith("link:")||we.set(Ae.descriptorHash,Ae));let he=Ro.miscUtils.sortMap(we.values(),ve=>Ro.structUtils.stringifyDescriptor(ve));return Tr.default.createElement(bi.Box,{flexDirection:"column"},Tr.default.createElement(j,null),Tr.default.createElement(q,null),Tr.default.createElement(re,{dependencies:he}))},{},{stdin:this.context.stdin,stdout:this.context.stdout,stderr:this.context.stderr});if(typeof me>"u")return 1;let De=!1;for(let ae of f.workspaces)for(let we of["dependencies","devDependencies"]){let he=ae.manifest[we];for(let ve of he.values()){let ue=me.get(ve.descriptorHash);typeof ue<"u"&&ue!==null&&(he.set(ve.identHash,Ro.structUtils.makeDescriptor(ve,ue)),De=!0)}}return De?(await Ro.StreamReport.start({configuration:l,stdout:this.context.stdout,includeLogs:!this.context.quiet},async ae=>{await f.install({cache:E,report:ae})})).exitCode():0}};ph.paths=[["upgrade-interactive"]],ph.usage=L4.Command.Usage({category:"Interactive commands",description:"open the upgrade interface",details:` + This command opens a fullscreen terminal interface where you can see any out of date packages used by your application, their status compared to the latest versions available on the remote registry, and select packages to upgrade. + `,examples:[["Open the upgrade window","yarn upgrade-interactive"]]});var Vz={commands:[dh,ph]},Gz=Vz;return qF(Yz);})(); +/* +object-assign +(c) Sindre Sorhus +@license MIT +*/ +/** + * @license + * Lodash + * Copyright OpenJS Foundation and other contributors + * Released under MIT license + * Based on Underscore.js 1.8.3 + * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + */ +/** @license React v0.0.0-experimental-51a3aa6af + * react-debug-tools.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +/** @license React v0.0.0-experimental-51a3aa6af + * react-is.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +/** @license React v0.0.0-experimental-51a3aa6af + * react.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +/** @license React v0.18.0 + * scheduler-tracing.development.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +/** @license React v0.18.0 + * scheduler-tracing.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +/** @license React v0.18.0 + * scheduler.development.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +/** @license React v0.18.0 + * scheduler.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +/** @license React v0.24.0 + * react-reconciler.development.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +/** @license React v0.24.0 + * react-reconciler.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +/** @license React v16.13.1 + * react.development.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +/** @license React v16.13.1 + * react.production.min.js + * + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +return plugin; +} +}; diff --git a/.yarnrc.yml b/.yarnrc.yml index 6d27afaac27..c513a5dbaaa 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -1,3 +1,7 @@ +logFilters: + - code: YN0013 + level: discard + nodeLinker: node-modules plugins: @@ -5,8 +9,7 @@ plugins: spec: "@yarnpkg/plugin-typescript" - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs spec: "@yarnpkg/plugin-workspace-tools" + - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs + spec: "@yarnpkg/plugin-interactive-tools" yarnPath: .yarn/releases/yarn-3.6.3.cjs -logFilters: - - code: YN0013 - level: discard diff --git a/CHANGELOG.md b/CHANGELOG.md index e9b2dfb48a5..7c4bcad5840 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,144 @@ # Changelog +## [0.26.0](https://github.com/noir-lang/noir/compare/v0.25.0...v0.26.0) (2024-03-25) + + +### ⚠ BREAKING CHANGES + +* **acir:** Program and witness stack structure (https://github.com/AztecProtocol/aztec-packages/pull/5149) +* automatic NoteInterface and NoteGetterOptions auto select (https://github.com/AztecProtocol/aztec-packages/pull/4508) +* separating out array and slice types in the AST ([#4504](https://github.com/noir-lang/noir/issues/4504)) +* Acir call opcode (https://github.com/AztecProtocol/aztec-packages/pull/4773) +* Support contracts with no constructor (https://github.com/AztecProtocol/aztec-packages/pull/5175) +* Remove open keyword from Noir (https://github.com/AztecProtocol/aztec-packages/pull/4967) + +### Features + +* Acir call opcode (https://github.com/AztecProtocol/aztec-packages/pull/4773) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* **acir:** Program and witness stack structure (https://github.com/AztecProtocol/aztec-packages/pull/5149) ([13eb71b](https://github.com/noir-lang/noir/commit/13eb71b8de44eb6aad9c37943ad06fc73db589f5)) +* Add `break` and `continue` in unconstrained code ([#4569](https://github.com/noir-lang/noir/issues/4569)) ([f2f827d](https://github.com/noir-lang/noir/commit/f2f827d51e6fe99fa3d17f125b22743da25e25be)) +* Add `nargo compile --watch` command ([#4464](https://github.com/noir-lang/noir/issues/4464)) ([44e60b6](https://github.com/noir-lang/noir/commit/44e60b67469de88f20842c4eead64d736f7bd4a0)) +* Add as_slice builtin function, add execution test ([#4523](https://github.com/noir-lang/noir/issues/4523)) ([6a9ea35](https://github.com/noir-lang/noir/commit/6a9ea35c4f1578058179aa08eedf44eb18bad4a1)) +* Add checks for bit size consistency on brillig gen ([#4542](https://github.com/noir-lang/noir/issues/4542)) ([f3243b7](https://github.com/noir-lang/noir/commit/f3243b763c0b15ae90beb8e35630df27f3d314c0)) +* Add CMOV instruction to brillig and brillig gen (https://github.com/AztecProtocol/aztec-packages/pull/5308) ([13eb71b](https://github.com/noir-lang/noir/commit/13eb71b8de44eb6aad9c37943ad06fc73db589f5)) +* Add experimental `quote` expression to parser ([#4595](https://github.com/noir-lang/noir/issues/4595)) ([4c3a30b](https://github.com/noir-lang/noir/commit/4c3a30b4991a329d3c52e1dfa59d854d7e6910db)) +* Add more impls on Option ([#4549](https://github.com/noir-lang/noir/issues/4549)) ([4cf700b](https://github.com/noir-lang/noir/commit/4cf700bcfe157ebc82cdf7321a16959b7a4add57)) +* Add specific error for attempting `string[x] = ".."` ([#4611](https://github.com/noir-lang/noir/issues/4611)) ([ff95fd9](https://github.com/noir-lang/noir/commit/ff95fd93451b2053360a16b7d3204ca251199296)) +* Allow usage of noir `#[test]` syntax in stdlib ([#4553](https://github.com/noir-lang/noir/issues/4553)) ([a8b7cdb](https://github.com/noir-lang/noir/commit/a8b7cdb8a3698bc8923b6fa8714deebb8bf3923f)) +* Automatic NoteInterface and NoteGetterOptions auto select (https://github.com/AztecProtocol/aztec-packages/pull/4508) ([13eb71b](https://github.com/noir-lang/noir/commit/13eb71b8de44eb6aad9c37943ad06fc73db589f5)) +* **avm:** Brillig CONST of size > u128 (https://github.com/AztecProtocol/aztec-packages/pull/5217) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Brillig IR refactor (https://github.com/AztecProtocol/aztec-packages/pull/5233) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Check initialization arguments in constructors (https://github.com/AztecProtocol/aztec-packages/pull/5144) ([d4213a0](https://github.com/noir-lang/noir/commit/d4213a03c9f77ee8e7663fc965a825258d90a368)) +* Check initializer msg.sender matches deployer from address preimage (https://github.com/AztecProtocol/aztec-packages/pull/5222) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Initial Earthly CI (https://github.com/AztecProtocol/aztec-packages/pull/5069) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Integrated native ACVM (https://github.com/AztecProtocol/aztec-packages/pull/4903) ([a6016b4](https://github.com/noir-lang/noir/commit/a6016b46abf6da6de4566cf6d35a675d805dd9b5)) +* Make brillig-gen more AVM-friendly (https://github.com/AztecProtocol/aztec-packages/pull/5091) ([a6016b4](https://github.com/noir-lang/noir/commit/a6016b46abf6da6de4566cf6d35a675d805dd9b5)) +* New brillig field operations and refactor of binary operations (https://github.com/AztecProtocol/aztec-packages/pull/5208) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Optimize sha2 implementation ([#4441](https://github.com/noir-lang/noir/issues/4441)) ([80373d6](https://github.com/noir-lang/noir/commit/80373d612c023e3e165b49b6d1729486b0ba3b4b)) +* RC optimization pass ([#4560](https://github.com/noir-lang/noir/issues/4560)) ([dfa5126](https://github.com/noir-lang/noir/commit/dfa5126f2c65843c34701cacddf2cbcfb0d7ff11)) +* Remove curly braces with fmt ([#4529](https://github.com/noir-lang/noir/issues/4529)) ([fe9a437](https://github.com/noir-lang/noir/commit/fe9a437b6d7ddc3f78665df1a576236555880c51)) +* Separating out array and slice types in the AST ([#4504](https://github.com/noir-lang/noir/issues/4504)) ([9a241f9](https://github.com/noir-lang/noir/commit/9a241f9622b342cd9d56bf8481219cfc374c0510)) +* Signed integer division and modulus in brillig gen (https://github.com/AztecProtocol/aztec-packages/pull/5279) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Support contracts with no constructor (https://github.com/AztecProtocol/aztec-packages/pull/5175) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Sync from noir (https://github.com/AztecProtocol/aztec-packages/pull/5234) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Sync from noir (https://github.com/AztecProtocol/aztec-packages/pull/5286) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Visible aliases for nargo commands ([#4453](https://github.com/noir-lang/noir/issues/4453)) ([773cf19](https://github.com/noir-lang/noir/commit/773cf190ee21381d826ba80391a5d7d5efae9174)) + + +### Bug Fixes + +* **acir_gen:** More granular element sizes array check ([#4528](https://github.com/noir-lang/noir/issues/4528)) ([f93d16e](https://github.com/noir-lang/noir/commit/f93d16e3e89c5df358c982deae4f3c2d4c82b77f)) +* Added error messages for passing oracles and references from unconstrained to constrained functions ([#4570](https://github.com/noir-lang/noir/issues/4570)) ([265bd8b](https://github.com/noir-lang/noir/commit/265bd8b284e5acd572a3812a94a99fc102227ff2)) +* Allow non-integer globals to reference struct methods ([#4490](https://github.com/noir-lang/noir/issues/4490)) ([00d6494](https://github.com/noir-lang/noir/commit/00d6494ae70b10e1872d96fb4e57ecb0b5f01787)) +* Dynamic assert messages in brillig ([#4531](https://github.com/noir-lang/noir/issues/4531)) ([e24d3fc](https://github.com/noir-lang/noir/commit/e24d3fc5a084610d9511e3c5421275cb9c84a548)) +* Evaluate operators in globals in types ([#4537](https://github.com/noir-lang/noir/issues/4537)) ([c8aa16b](https://github.com/noir-lang/noir/commit/c8aa16bc7e78456cce1736fac82496996a8761f4)) +* Make `nargo` the default binary for cargo run ([#4554](https://github.com/noir-lang/noir/issues/4554)) ([de4986e](https://github.com/noir-lang/noir/commit/de4986eb74b28b2e1065fa6b413d02457ddf61b0)) +* Signed integer comparisons in brillig ([#4579](https://github.com/noir-lang/noir/issues/4579)) ([938d5e8](https://github.com/noir-lang/noir/commit/938d5e85eda00a05de5014e64d3dc9fc7c24936d)) +* **ssa:** Use accurate type during SSA AsSlice simplficiation ([#4610](https://github.com/noir-lang/noir/issues/4610)) ([0473497](https://github.com/noir-lang/noir/commit/04734976e92475b1ab94257e30bc3438c7358681)) +* Substitute generics when checking the field count of a type ([#4547](https://github.com/noir-lang/noir/issues/4547)) ([eeeebac](https://github.com/noir-lang/noir/commit/eeeebacd10698e847f773e26dac8a4a5eb8e84ed)) + + +### Miscellaneous Chores + +* Remove open keyword from Noir (https://github.com/AztecProtocol/aztec-packages/pull/4967) ([a6016b4](https://github.com/noir-lang/noir/commit/a6016b46abf6da6de4566cf6d35a675d805dd9b5)) + +## [0.25.0](https://github.com/noir-lang/noir/compare/v0.24.0...v0.25.0) (2024-03-11) + + +### ⚠ BREAKING CHANGES + +* Internal as a macro (https://github.com/AztecProtocol/aztec-packages/pull/4898) +* reserve `unchecked` keyword ([#4432](https://github.com/noir-lang/noir/issues/4432)) +* Remove empty value from bounded vec ([#4431](https://github.com/noir-lang/noir/issues/4431)) +* Ban Fields in for loop indices and bitwise ops ([#4376](https://github.com/noir-lang/noir/issues/4376)) +* bump msrv to 1.73.0 ([#4406](https://github.com/noir-lang/noir/issues/4406)) +* **ci:** Bump MSRV to 1.72.1 and enforce that ACVM can be published using updated lockfile ([#4385](https://github.com/noir-lang/noir/issues/4385)) +* Restrict bit sizes ([#4235](https://github.com/noir-lang/noir/issues/4235)) +* move noir out of yarn-project (https://github.com/AztecProtocol/aztec-packages/pull/4479) +* note type ids (https://github.com/AztecProtocol/aztec-packages/pull/4500) + +### Features + +* Add eddsa_poseidon_to_pub function to stdlib with test + docs ([#4473](https://github.com/noir-lang/noir/issues/4473)) ([00d2c32](https://github.com/noir-lang/noir/commit/00d2c32e58176cc5de3574c8435a54d415c4a5fa)) +* Add HashMap to the stdlib ([#4242](https://github.com/noir-lang/noir/issues/4242)) ([650ffc5](https://github.com/noir-lang/noir/commit/650ffc5053cdca4b6ad2e027fa1f4fd90ef64871)) +* Add option to set max memory for bb.js ([#4227](https://github.com/noir-lang/noir/issues/4227)) ([8a6b131](https://github.com/noir-lang/noir/commit/8a6b131402892a570bc2de6f5869de73b0bd979e)) +* Add overflow and underflow checks for unsigned integers in brillig ([#4445](https://github.com/noir-lang/noir/issues/4445)) ([21fc4b8](https://github.com/noir-lang/noir/commit/21fc4b85763dccae6dce0a46a318718c3c913471)) +* Add poseidon2 opcode implementation for acvm/brillig, and Noir ([#4398](https://github.com/noir-lang/noir/issues/4398)) ([10e8292](https://github.com/noir-lang/noir/commit/10e82920798380f50046e52db4a20ca205191ab7)) +* Added cast opcode and cast calldata (https://github.com/AztecProtocol/aztec-packages/pull/4423) ([78ef013](https://github.com/noir-lang/noir/commit/78ef0134b82e76a73dadb6c7975def22290e3a1a)) +* Allow type aliases to reference other aliases ([#4353](https://github.com/noir-lang/noir/issues/4353)) ([c44ef14](https://github.com/noir-lang/noir/commit/c44ef14847a436733206b6dd9590a7ab214ecd97)) +* Backpropagate constants in ACIR during optimization ([#3926](https://github.com/noir-lang/noir/issues/3926)) ([aad0da0](https://github.com/noir-lang/noir/commit/aad0da024c69663f42e6913e674682d5864b26ae)) +* **ci:** Use wasm-opt when compiling wasm packages ([#4334](https://github.com/noir-lang/noir/issues/4334)) ([e382921](https://github.com/noir-lang/noir/commit/e3829213d8411f84e117a14b43816967925095e0)) +* DAP Preflight and debugger compilation options ([#4185](https://github.com/noir-lang/noir/issues/4185)) ([e0ad0b2](https://github.com/noir-lang/noir/commit/e0ad0b2b31f6d46be75d23aec6a82850a9c4bd75)) +* Expose separate functions to compile programs vs contracts in `noir_wasm` ([#4413](https://github.com/noir-lang/noir/issues/4413)) ([7cd5fdb](https://github.com/noir-lang/noir/commit/7cd5fdb3d2a53475b7c8681231d517cab30f9f9b)) +* Internal as a macro (https://github.com/AztecProtocol/aztec-packages/pull/4898) ([5f57ebb](https://github.com/noir-lang/noir/commit/5f57ebb7ff4b810802f90699a10f4325ef904f2e)) +* Note type ids (https://github.com/AztecProtocol/aztec-packages/pull/4500) ([78ef013](https://github.com/noir-lang/noir/commit/78ef0134b82e76a73dadb6c7975def22290e3a1a)) +* Restrict bit sizes ([#4235](https://github.com/noir-lang/noir/issues/4235)) ([1048f81](https://github.com/noir-lang/noir/commit/1048f815abb1f27e9c84ab5b9568a3673c12a50a)) +* Run tests in parallel in `nargo test` ([#4484](https://github.com/noir-lang/noir/issues/4484)) ([761734e](https://github.com/noir-lang/noir/commit/761734e6cb3ff5911aa85d0cee96ad26092b4905)) +* Skip redundant range checks in brillig ([#4460](https://github.com/noir-lang/noir/issues/4460)) ([cb4c1c5](https://github.com/noir-lang/noir/commit/cb4c1c5264b95d01f69d99f916ced71ad9cdc9d1)) +* Sync from aztec-packages ([#4483](https://github.com/noir-lang/noir/issues/4483)) ([fe8f277](https://github.com/noir-lang/noir/commit/fe8f2776ccfde29209a2c3fc162311c99e4f59be)) +* Track stack frames and their variables in the debugger ([#4188](https://github.com/noir-lang/noir/issues/4188)) ([ae1a9d9](https://github.com/noir-lang/noir/commit/ae1a9d923998177516919bbba6ff4b0584fa1e9f)) +* TypeVariableKind for just Integers ([#4118](https://github.com/noir-lang/noir/issues/4118)) ([c956be8](https://github.com/noir-lang/noir/commit/c956be870fb47403a6da6585fce6bea2d40ee268)) +* Update error message when trying to load workspace as dependency ([#4393](https://github.com/noir-lang/noir/issues/4393)) ([d2585e7](https://github.com/noir-lang/noir/commit/d2585e738a63208fca3c9e26242e896d7f1df1e4)) + + +### Bug Fixes + +* **acir:** Array dynamic flatten ([#4351](https://github.com/noir-lang/noir/issues/4351)) ([b2aaeab](https://github.com/noir-lang/noir/commit/b2aaeab319a0c66c431a7db6852f743eccde8e98)) +* **acir:** Use types on dynamic arrays ([#4364](https://github.com/noir-lang/noir/issues/4364)) ([ba2c541](https://github.com/noir-lang/noir/commit/ba2c541ec45de92bba98de34771b73cbb7865c93)) +* Add `follow_bindings` to follow `Type::Alias` links ([#4521](https://github.com/noir-lang/noir/issues/4521)) ([b94adb9](https://github.com/noir-lang/noir/commit/b94adb92657e2b4a51dc7216a88e080aed1cf8b0)) +* Add handling to `noir_wasm` for projects without dependencies ([#4344](https://github.com/noir-lang/noir/issues/4344)) ([4982251](https://github.com/noir-lang/noir/commit/49822511710a7f1c42b8ed343e80456f8e6db2d9)) +* Allow type aliases in main ([#4505](https://github.com/noir-lang/noir/issues/4505)) ([8a5359c](https://github.com/noir-lang/noir/commit/8a5359c012579e54c2766de1074482a36ecada32)) +* Ban Fields in for loop indices and bitwise ops ([#4376](https://github.com/noir-lang/noir/issues/4376)) ([601fd9a](https://github.com/noir-lang/noir/commit/601fd9afc502236af1db0c4492698ba2298c7501)) +* Brillig range check with consistent bit size ([#4357](https://github.com/noir-lang/noir/issues/4357)) ([ea47d4a](https://github.com/noir-lang/noir/commit/ea47d4a67c6a18e4a7d3a49079d9eb24a1026a25)) +* Build noir_codegen when publishing ([#4448](https://github.com/noir-lang/noir/issues/4448)) ([cb1ceee](https://github.com/noir-lang/noir/commit/cb1ceee58b11b0ce6f8845361af3418d13c506bd)) +* Consistent bit size for truncate ([#4370](https://github.com/noir-lang/noir/issues/4370)) ([dcd7a1e](https://github.com/noir-lang/noir/commit/dcd7a1e561a68504b9038ffbb3c80f5c981f9f0c)) +* Correct formatting for databus visibility types ([#4423](https://github.com/noir-lang/noir/issues/4423)) ([cd796de](https://github.com/noir-lang/noir/commit/cd796dea4937dd1a261f154e5f2e599bbc649165)) +* Correct invalid brillig codegen for `EmbeddedCurvePoint.add` ([#4382](https://github.com/noir-lang/noir/issues/4382)) ([5051ec4](https://github.com/noir-lang/noir/commit/5051ec4d434a9e5cf405c68357faaf213e68de9e)) +* **docs:** Update install versions ([#4396](https://github.com/noir-lang/noir/issues/4396)) ([b283637](https://github.com/noir-lang/noir/commit/b283637e092038eb296c468168aec2d41e1c2734)) +* **docs:** Update noirjs_app for 0.23 ([#4378](https://github.com/noir-lang/noir/issues/4378)) ([f77f702](https://github.com/noir-lang/noir/commit/f77f702e0cfb81dcce4dd97e274b831e887ba5d2)) +* Enforce matching types of binary ops in SSA ([#4391](https://github.com/noir-lang/noir/issues/4391)) ([70866ae](https://github.com/noir-lang/noir/commit/70866aea976d59dbcbd4af34067fdd8f46555673)) +* Fix brillig slowdown when assigning arrays in loops ([#4472](https://github.com/noir-lang/noir/issues/4472)) ([2a53545](https://github.com/noir-lang/noir/commit/2a53545f4238c9b8535e6bc5b0720fa15f44f946)) +* **flake:** Stop flake.nix removing ignored-tests.txt ([#4455](https://github.com/noir-lang/noir/issues/4455)) ([ebaf05a](https://github.com/noir-lang/noir/commit/ebaf05ab10834dd10e04c7ea5130f96c6cdf98ed)) +* Force src impl for == on slices ([#4507](https://github.com/noir-lang/noir/issues/4507)) ([1691274](https://github.com/noir-lang/noir/commit/169127444e8b16a8aad4acfe29ba812894fd897c)) +* Handling of gh deps in noir_wasm ([#4499](https://github.com/noir-lang/noir/issues/4499)) ([1d65370](https://github.com/noir-lang/noir/commit/1d653704715bf9999eb6a40ed7500e752e2c73b7)) +* Iterative flattening pass ([#4492](https://github.com/noir-lang/noir/issues/4492)) ([33c1ef7](https://github.com/noir-lang/noir/commit/33c1ef70e7859fdee7babfb5d38191f53e73a0df)) +* Noir test incorrect reporting (https://github.com/AztecProtocol/aztec-packages/pull/4925) ([5f57ebb](https://github.com/noir-lang/noir/commit/5f57ebb7ff4b810802f90699a10f4325ef904f2e)) +* Only add `.nr` files to file manager ([#4380](https://github.com/noir-lang/noir/issues/4380)) ([8536c7c](https://github.com/noir-lang/noir/commit/8536c7c8ea8fc6b740b2ae6d1aef3bc7e1907b8c)) +* Remove panic when generic array length is not resolvable ([#4408](https://github.com/noir-lang/noir/issues/4408)) ([00ab3db](https://github.com/noir-lang/noir/commit/00ab3db86b06111d144516e862902b8604284611)) +* Remove print from monomorphization pass ([#4417](https://github.com/noir-lang/noir/issues/4417)) ([27c66b3](https://github.com/noir-lang/noir/commit/27c66b3d0741e68ed591ae8a16b47b30bc87175f)) +* **ssa:** Handle mergers of slices returned from calls ([#4496](https://github.com/noir-lang/noir/issues/4496)) ([f988d02](https://github.com/noir-lang/noir/commit/f988d020e43cdf36a38613f2052d4518de39193a)) +* Use correct type for numeric generics ([#4386](https://github.com/noir-lang/noir/issues/4386)) ([0a1d109](https://github.com/noir-lang/noir/commit/0a1d109f478c997da5c43876fd12464af638bb15)) +* Variables from trait constraints being permanently bound over when used within a trait impl ([#4450](https://github.com/noir-lang/noir/issues/4450)) ([ac60ef5](https://github.com/noir-lang/noir/commit/ac60ef5e12fcfb907fbdcff709d7cbad05f2b939)) + + +### Miscellaneous Chores + +* Bump msrv to 1.73.0 ([#4406](https://github.com/noir-lang/noir/issues/4406)) ([b5e5c30](https://github.com/noir-lang/noir/commit/b5e5c30f4db52c79ef556e80660f39db369b1911)) +* **ci:** Bump MSRV to 1.72.1 and enforce that ACVM can be published using updated lockfile ([#4385](https://github.com/noir-lang/noir/issues/4385)) ([2fc95d2](https://github.com/noir-lang/noir/commit/2fc95d2d82b3220267ce7d5815e7073e00ef1360)) +* Move noir out of yarn-project (https://github.com/AztecProtocol/aztec-packages/pull/4479) ([78ef013](https://github.com/noir-lang/noir/commit/78ef0134b82e76a73dadb6c7975def22290e3a1a)) +* Remove empty value from bounded vec ([#4431](https://github.com/noir-lang/noir/issues/4431)) ([b9384fb](https://github.com/noir-lang/noir/commit/b9384fb23abf4ab15e880fb7e03c21509a9fa8a6)) +* Reserve `unchecked` keyword ([#4432](https://github.com/noir-lang/noir/issues/4432)) ([9544813](https://github.com/noir-lang/noir/commit/9544813fabbd18a87dd88456e6a5b781bd0cf008)) + ## [0.24.0](https://github.com/noir-lang/noir/compare/v0.23.0...v0.24.0) (2024-02-12) diff --git a/Cargo.lock b/Cargo.lock index c0438eaf81f..170b23be189 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "acir" -version = "0.40.0" +version = "0.42.0" dependencies = [ "acir_field", "base64 0.21.2", @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "acir_field" -version = "0.40.0" +version = "0.42.0" dependencies = [ "ark-bls12-381", "ark-bn254", @@ -37,7 +37,7 @@ dependencies = [ [[package]] name = "acvm" -version = "0.40.0" +version = "0.42.0" dependencies = [ "acir", "acvm_blackbox_solver", @@ -53,7 +53,7 @@ dependencies = [ [[package]] name = "acvm_blackbox_solver" -version = "0.40.0" +version = "0.42.0" dependencies = [ "acir", "blake2", @@ -67,13 +67,32 @@ dependencies = [ ] [[package]] -name = "acvm_js" +name = "acvm_cli" version = "0.40.0" +dependencies = [ + "acir", + "acvm", + "bn254_blackbox_solver", + "clap", + "color-eyre", + "const_format", + "nargo", + "paste", + "proptest", + "rand 0.8.5", + "thiserror", + "toml 0.7.6", + "tracing-appender", + "tracing-subscriber", +] + +[[package]] +name = "acvm_js" +version = "0.42.0" dependencies = [ "acvm", "bn254_blackbox_solver", "build-data", - "cfg-if 1.0.0", "console_error_panic_hook", "const-str", "gloo-utils", @@ -104,9 +123,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" dependencies = [ "getrandom 0.2.10", "once_cell", @@ -115,9 +134,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.6" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if 1.0.0", "getrandom 0.2.10", @@ -212,7 +231,7 @@ checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" [[package]] name = "arena" -version = "0.24.0" +version = "0.26.0" [[package]] name = "ark-bls12-381" @@ -391,7 +410,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138985dd8aefbefeaa66b01b7f5b2b6b4c333fcef1cc5f32c63a2aabe37d6de3" dependencies = [ - "futures 0.3.28", + "futures 0.3.30", "lsp-types 0.94.1", "pin-project-lite", "rustix", @@ -413,12 +432,13 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "aztec_macros" -version = "0.24.0" +version = "0.26.0" dependencies = [ "convert_case 0.6.0", "iter-extended", "noirc_errors", "noirc_frontend", + "regex", ] [[package]] @@ -521,9 +541,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.3.3" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "bitmaps" @@ -579,22 +599,18 @@ dependencies = [ [[package]] name = "bn254_blackbox_solver" -version = "0.39.0" +version = "0.42.0" dependencies = [ "acir", "acvm_blackbox_solver", "ark-ec", "ark-ff", - "flate2", + "cfg-if 1.0.0", "getrandom 0.2.10", "js-sys", "noir_grumpkin", "num-bigint", "num-traits", - "pkg-config", - "reqwest", - "rust-embed", - "tar", "thiserror", "wasm-bindgen-futures", "wasmer", @@ -602,7 +618,7 @@ dependencies = [ [[package]] name = "brillig" -version = "0.40.0" +version = "0.42.0" dependencies = [ "acir_field", "serde", @@ -610,12 +626,13 @@ dependencies = [ [[package]] name = "brillig_vm" -version = "0.40.0" +version = "0.42.0" dependencies = [ "acir", "acvm_blackbox_solver", "num-bigint", "num-traits", + "thiserror", ] [[package]] @@ -767,9 +784,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.30" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "defd4e7873dbddba6c7c91e199c7fcb946abc4a6a4ac3195400bcfb01b5de877" +checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" dependencies = [ "android-tzdata", "iana-time-zone", @@ -777,7 +794,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets 0.48.1", + "windows-targets 0.52.4", ] [[package]] @@ -947,14 +964,14 @@ checksum = "55b672471b4e9f9e95499ea597ff64941a309b2cdbffcc46f2cc5e2d971fd335" [[package]] name = "console" -version = "0.15.7" +version = "0.15.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" dependencies = [ "encode_unicode 0.3.6", "lazy_static", "libc", - "windows-sys 0.45.0", + "windows-sys 0.52.0", ] [[package]] @@ -1022,9 +1039,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "corosensei" @@ -1585,12 +1602,12 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.5" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1655,6 +1672,15 @@ dependencies = [ "rayon", ] +[[package]] +name = "file-id" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6584280525fb2059cba3db2c04abf947a1a29a45ddae89f3870f8281704fafc9" +dependencies = [ + "windows-sys 0.48.0", +] + [[package]] name = "filetime" version = "0.2.22" @@ -1706,7 +1732,7 @@ dependencies = [ [[package]] name = "fm" -version = "0.24.0" +version = "0.26.0" dependencies = [ "codespan-reporting", "iter-extended", @@ -1729,6 +1755,15 @@ dependencies = [ "percent-encoding 2.3.0", ] +[[package]] +name = "fsevent-sys" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" +dependencies = [ + "libc", +] + [[package]] name = "funty" version = "2.0.0" @@ -1743,9 +1778,9 @@ checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" [[package]] name = "futures" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" dependencies = [ "futures-channel", "futures-core", @@ -1758,9 +1793,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -1768,15 +1803,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -1786,15 +1821,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-macro" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", @@ -1803,21 +1838,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures 0.1.31", "futures-channel", @@ -1948,9 +1983,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.24" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" dependencies = [ "bytes", "fnv", @@ -1961,7 +1996,7 @@ dependencies = [ "indexmap 2.0.0", "slab", "tokio", - "tokio-util 0.7.8", + "tokio-util 0.7.10", "tracing", ] @@ -1977,7 +2012,7 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" dependencies = [ - "ahash 0.7.7", + "ahash 0.7.8", ] [[package]] @@ -1986,7 +2021,7 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ - "ahash 0.7.7", + "ahash 0.7.8", ] [[package]] @@ -1995,7 +2030,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.6", + "ahash 0.8.11", ] [[package]] @@ -2076,9 +2111,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "hyper" -version = "0.14.27" +version = "0.14.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" dependencies = [ "bytes", "futures-channel", @@ -2091,7 +2126,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.9", + "socket2", "tokio", "tower-service", "tracing", @@ -2100,9 +2135,9 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.24.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d78e1e73ec14cf7375674f74d7dde185c8206fd9dea6fb6295e8a98098aaa97" +checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", "http", @@ -2258,7 +2293,7 @@ version = "0.11.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fb7c1b80a1dfa604bb4a649a5c5aeef3d913f7c520cb42b40e534e8a61bcdfc" dependencies = [ - "ahash 0.8.6", + "ahash 0.8.11", "indexmap 1.9.3", "is-terminal", "itoa", @@ -2270,6 +2305,26 @@ dependencies = [ "str_stack", ] +[[package]] +name = "inotify" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" +dependencies = [ + "bitflags 1.3.2", + "inotify-sys", + "libc", +] + +[[package]] +name = "inotify-sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" +dependencies = [ + "libc", +] + [[package]] name = "instant" version = "0.1.12" @@ -2298,7 +2353,7 @@ dependencies = [ [[package]] name = "iter-extended" -version = "0.24.0" +version = "0.26.0" [[package]] name = "itertools" @@ -2343,7 +2398,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2b99d4207e2a04fb4581746903c2bb7eb376f88de9c699d0f3e10feeac0cd3a" dependencies = [ "derive_more", - "futures 0.3.28", + "futures 0.3.30", "jsonrpc-core", "jsonrpc-pubsub", "log", @@ -2358,7 +2413,7 @@ version = "18.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14f7f76aef2d054868398427f6c54943cf3d1caa9a7ec7d0c38d69df97a965eb" dependencies = [ - "futures 0.3.28", + "futures 0.3.30", "futures-executor", "futures-util", "log", @@ -2373,7 +2428,7 @@ version = "18.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b51da17abecbdab3e3d4f26b01c5ec075e88d3abe3ab3b05dc9aa69392764ec0" dependencies = [ - "futures 0.3.28", + "futures 0.3.30", "jsonrpc-client-transports", ] @@ -2395,7 +2450,7 @@ version = "18.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1dea6e07251d9ce6a552abfb5d7ad6bc290a4596c8dcc3d795fae2bbdc1f3ff" dependencies = [ - "futures 0.3.28", + "futures 0.3.30", "hyper", "jsonrpc-core", "jsonrpc-server-utils", @@ -2411,7 +2466,7 @@ version = "18.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240f87695e6c6f62fb37f05c02c04953cf68d6408b8c1c89de85c7a0125b1011" dependencies = [ - "futures 0.3.28", + "futures 0.3.30", "jsonrpc-core", "lazy_static", "log", @@ -2427,7 +2482,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa4fdea130485b572c39a460d50888beb00afb3e35de23ccd7fad8ff19f0e0d4" dependencies = [ "bytes", - "futures 0.3.28", + "futures 0.3.30", "globset", "jsonrpc-core", "lazy_static", @@ -2459,6 +2514,26 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "kqueue" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" +dependencies = [ + "kqueue-sys", + "libc", +] + +[[package]] +name = "kqueue-sys" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" +dependencies = [ + "bitflags 1.3.2", + "libc", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -2483,11 +2558,22 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" +[[package]] +name = "libredox" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607" +dependencies = [ + "bitflags 2.4.2", + "libc", + "redox_syscall 0.4.1", +] + [[package]] name = "linux-raw-sys" -version = "0.4.3" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" @@ -2566,9 +2652,9 @@ checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "memmap2" @@ -2634,11 +2720,12 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", + "log", "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.48.0", ] @@ -2651,7 +2738,7 @@ checksum = "7843ec2de400bcbc6a6328c958dc38e5359da6e93e72e37bc5246bf1ae776389" [[package]] name = "nargo" -version = "0.24.0" +version = "0.26.0" dependencies = [ "acvm", "codespan-reporting", @@ -2678,7 +2765,7 @@ dependencies = [ [[package]] name = "nargo_cli" -version = "0.24.0" +version = "0.26.0" dependencies = [ "acvm", "assert_cmd", @@ -2707,6 +2794,8 @@ dependencies = [ "noirc_driver", "noirc_errors", "noirc_frontend", + "notify", + "notify-debouncer-full", "paste", "pprof", "predicates 2.1.5", @@ -2718,10 +2807,11 @@ dependencies = [ "similar-asserts", "tempfile", "termcolor", + "termion", "test-binary", "thiserror", "tokio", - "tokio-util 0.7.8", + "tokio-util 0.7.10", "toml 0.7.6", "tower", "tracing-appender", @@ -2730,7 +2820,7 @@ dependencies = [ [[package]] name = "nargo_fmt" -version = "0.24.0" +version = "0.26.0" dependencies = [ "bytecount", "noirc_frontend", @@ -2742,7 +2832,7 @@ dependencies = [ [[package]] name = "nargo_toml" -version = "0.24.0" +version = "0.26.0" dependencies = [ "dirs", "fm", @@ -2815,7 +2905,7 @@ dependencies = [ [[package]] name = "noir_debugger" -version = "0.24.0" +version = "0.26.0" dependencies = [ "acvm", "assert_cmd", @@ -2850,7 +2940,7 @@ dependencies = [ [[package]] name = "noir_lsp" -version = "0.24.0" +version = "0.26.0" dependencies = [ "acvm", "async-lsp", @@ -2876,7 +2966,7 @@ dependencies = [ [[package]] name = "noir_wasm" -version = "0.24.0" +version = "0.26.0" dependencies = [ "acvm", "build-data", @@ -2899,7 +2989,7 @@ dependencies = [ [[package]] name = "noirc_abi" -version = "0.24.0" +version = "0.26.0" dependencies = [ "acvm", "iter-extended", @@ -2916,7 +3006,7 @@ dependencies = [ [[package]] name = "noirc_abi_wasm" -version = "0.24.0" +version = "0.26.0" dependencies = [ "acvm", "build-data", @@ -2933,7 +3023,7 @@ dependencies = [ [[package]] name = "noirc_driver" -version = "0.24.0" +version = "0.26.0" dependencies = [ "acvm", "aztec_macros", @@ -2946,7 +3036,6 @@ dependencies = [ "noirc_errors", "noirc_evaluator", "noirc_frontend", - "noirc_macros", "rust-embed", "serde", "thiserror", @@ -2955,7 +3044,7 @@ dependencies = [ [[package]] name = "noirc_errors" -version = "0.24.0" +version = "0.26.0" dependencies = [ "acvm", "base64 0.21.2", @@ -2973,9 +3062,10 @@ dependencies = [ [[package]] name = "noirc_evaluator" -version = "0.24.0" +version = "0.26.0" dependencies = [ "acvm", + "chrono", "fxhash", "im", "iter-extended", @@ -2989,10 +3079,11 @@ dependencies = [ [[package]] name = "noirc_frontend" -version = "0.24.0" +version = "0.26.0" dependencies = [ "acvm", "arena", + "base64 0.21.2", "chumsky", "fm", "iter-extended", @@ -3012,17 +3103,9 @@ dependencies = [ "tracing", ] -[[package]] -name = "noirc_macros" -version = "0.24.0" -dependencies = [ - "iter-extended", - "noirc_frontend", -] - [[package]] name = "noirc_printable_type" -version = "0.24.0" +version = "0.26.0" dependencies = [ "acvm", "iter-extended", @@ -3039,6 +3122,39 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" +[[package]] +name = "notify" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" +dependencies = [ + "bitflags 2.4.2", + "crossbeam-channel", + "filetime", + "fsevent-sys", + "inotify", + "kqueue", + "libc", + "log", + "mio", + "walkdir", + "windows-sys 0.48.0", +] + +[[package]] +name = "notify-debouncer-full" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f5dab59c348b9b50cf7f261960a20e389feb2713636399cd9082cd4b536154" +dependencies = [ + "crossbeam-channel", + "file-id", + "log", + "notify", + "parking_lot 0.12.1", + "walkdir", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -3100,6 +3216,12 @@ dependencies = [ "libc", ] +[[package]] +name = "numtoa" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" + [[package]] name = "object" version = "0.31.1" @@ -3460,7 +3582,7 @@ checksum = "7c003ac8c77cb07bb74f5f198bce836a689bcd5a42574612bf14d17bfd08c20e" dependencies = [ "bit-set", "bit-vec", - "bitflags 2.3.3", + "bitflags 2.4.2", "lazy_static", "num-traits", "rand 0.8.5", @@ -3659,6 +3781,21 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_termios" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20145670ba436b55d91fc92d25e71160fbfbdd57831631c8d7d36377a476f1cb" + [[package]] name = "redox_users" version = "0.4.3" @@ -3684,14 +3821,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.1" +version = "1.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.3", - "regex-syntax 0.7.4", + "regex-automata 0.4.5", + "regex-syntax 0.8.2", ] [[package]] @@ -3708,10 +3845,16 @@ name = "regex-automata" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310" + +[[package]] +name = "regex-automata" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.4", + "regex-syntax 0.8.2", ] [[package]] @@ -3726,6 +3869,12 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "region" version = "3.0.0" @@ -3883,7 +4032,6 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "shellexpand", "syn 2.0.32", "walkdir", ] @@ -3894,7 +4042,6 @@ version = "7.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d38ff6bf570dc3bb7100fce9f7b60c33fa71d80e88da3f2580df4ff2bdded74" dependencies = [ - "globset", "sha2", "walkdir", ] @@ -3922,15 +4069,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.4" +version = "0.38.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" dependencies = [ - "bitflags 2.3.3", + "bitflags 2.4.2", "errno", "libc", "linux-raw-sys", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -4301,9 +4448,9 @@ dependencies = [ [[package]] name = "shared-buffer" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cf61602ee61e2f83dd016b3e6387245291cf728ea071c378b35088125b4d995" +checksum = "f6c99835bad52957e7aa241d3975ed17c1e5f8c92026377d117a606f36b84b16" dependencies = [ "bytes", "memmap2 0.6.2", @@ -4315,15 +4462,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" -[[package]] -name = "shellexpand" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" -dependencies = [ - "dirs", -] - [[package]] name = "signature" version = "1.6.4" @@ -4402,9 +4540,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.0" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smawk" @@ -4421,16 +4559,6 @@ dependencies = [ "serde", ] -[[package]] -name = "socket2" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "socket2" version = "0.5.5" @@ -4607,6 +4735,18 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "termion" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417813675a504dfbbf21bfde32c03e5bf9f2413999962b479023c02848c1c7a5" +dependencies = [ + "libc", + "libredox", + "numtoa", + "redox_termios", +] + [[package]] name = "termtree" version = "0.4.1" @@ -4732,9 +4872,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.0" +version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841d45b238a16291a4e1584e61820b8ae57d696cc5015c459c229ccc6990cc1c" +checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" dependencies = [ "backtrace", "bytes", @@ -4742,7 +4882,7 @@ dependencies = [ "mio", "num_cpus", "pin-project-lite", - "socket2 0.5.5", + "socket2", "tokio-macros", "windows-sys 0.48.0", ] @@ -4770,9 +4910,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" dependencies = [ "futures-core", "pin-project-lite", @@ -4795,9 +4935,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.8" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", @@ -5258,9 +5398,9 @@ dependencies = [ [[package]] name = "wasmer" -version = "4.2.4" +version = "4.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce45cc009177ca345a6d041f9062305ad467d15e7d41494f5b81ab46d62d7a58" +checksum = "5c15724dc25d1ee57962334aea8e41ade2675e5ea2ac6b8d42da6051b0face66" dependencies = [ "bytes", "cfg-if 1.0.0", @@ -5274,23 +5414,23 @@ dependencies = [ "shared-buffer", "target-lexicon", "thiserror", + "tracing", "wasm-bindgen", "wasmer-compiler", "wasmer-compiler-cranelift", "wasmer-derive", "wasmer-types", "wasmer-vm", - "wasmparser 0.83.0", - "wasmparser 0.95.0", + "wasmparser", "wat", "winapi", ] [[package]] name = "wasmer-compiler" -version = "4.2.4" +version = "4.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e044f6140c844602b920deb4526aea3cc9c0d7cf23f00730bb9b2034669f522a" +checksum = "55a7f3b3a96f8d844c25e2c032af9572306dd63fa93dc17bcca4c5458ac569bd" dependencies = [ "backtrace", "bytes", @@ -5309,15 +5449,15 @@ dependencies = [ "thiserror", "wasmer-types", "wasmer-vm", - "wasmparser 0.95.0", + "wasmparser", "winapi", ] [[package]] name = "wasmer-compiler-cranelift" -version = "4.2.4" +version = "4.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32ce02358eb44a149d791c1d6648fb7f8b2f99cd55e3c4eef0474653ec8cc889" +checksum = "102e2c5bacac69495c4025767e2fa26797ffb27f242dccb7cf57d9cefd944386" dependencies = [ "cranelift-codegen", "cranelift-entity", @@ -5334,9 +5474,9 @@ dependencies = [ [[package]] name = "wasmer-derive" -version = "4.2.4" +version = "4.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c782d80401edb08e1eba206733f7859db6c997fc5a7f5fb44edc3ecd801468f6" +checksum = "0ea737fa08f95d6abc4459f42a70a9833e8974b814e74971d77ef473814f4d4c" dependencies = [ "proc-macro-error", "proc-macro2", @@ -5346,9 +5486,9 @@ dependencies = [ [[package]] name = "wasmer-types" -version = "4.2.4" +version = "4.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd09e80d4d74bb9fd0ce6c3c106b1ceba1a050f9948db9d9b78ae53c172d6157" +checksum = "b0689110e291b0f07fc665f2824e5ff81df120848e8a9acfbf1a9bf7990773f9" dependencies = [ "bytecheck", "enum-iterator", @@ -5362,9 +5502,9 @@ dependencies = [ [[package]] name = "wasmer-vm" -version = "4.2.4" +version = "4.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdcd8a4fd36414a7b6a003dbfbd32393bce3e155d715dd877c05c1b7a41d224d" +checksum = "4cd41f822a1ac4242d478754e8ceba2806a00ea5072803622e1fe91e8e28b2a1" dependencies = [ "backtrace", "cc", @@ -5390,18 +5530,13 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.83.0" +version = "0.121.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" - -[[package]] -name = "wasmparser" -version = "0.95.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ea896273ea99b15132414be1da01ab0d8836415083298ecaffbe308eaac87a" +checksum = "9dbe55c8f9d0dbd25d9447a5a889ff90c0cc3feaa7395310d3d826b2c703eaab" dependencies = [ - "indexmap 1.9.3", - "url 2.4.0", + "bitflags 2.4.2", + "indexmap 2.0.0", + "semver", ] [[package]] @@ -5494,15 +5629,6 @@ dependencies = [ "windows_x86_64_msvc 0.33.0", ] -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - [[package]] name = "windows-sys" version = "0.48.0" @@ -5513,18 +5639,12 @@ dependencies = [ ] [[package]] -name = "windows-targets" -version = "0.42.2" +name = "windows-sys" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", + "windows-targets 0.52.4", ] [[package]] @@ -5543,10 +5663,19 @@ dependencies = [ ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" +name = "windows-targets" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", +] [[package]] name = "windows_aarch64_gnullvm" @@ -5554,6 +5683,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + [[package]] name = "windows_aarch64_msvc" version = "0.33.0" @@ -5562,15 +5697,15 @@ checksum = "cd761fd3eb9ab8cc1ed81e56e567f02dd82c4c837e48ac3b2181b9ffc5060807" [[package]] name = "windows_aarch64_msvc" -version = "0.42.2" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" [[package]] name = "windows_i686_gnu" @@ -5580,15 +5715,15 @@ checksum = "cab0cf703a96bab2dc0c02c0fa748491294bf9b7feb27e1f4f96340f208ada0e" [[package]] name = "windows_i686_gnu" -version = "0.42.2" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" [[package]] name = "windows_i686_msvc" @@ -5598,15 +5733,15 @@ checksum = "8cfdbe89cc9ad7ce618ba34abc34bbb6c36d99e96cae2245b7943cd75ee773d0" [[package]] name = "windows_i686_msvc" -version = "0.42.2" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" [[package]] name = "windows_x86_64_gnu" @@ -5616,27 +5751,27 @@ checksum = "b4dd9b0c0e9ece7bb22e84d70d01b71c6d6248b81a3c60d11869451b4cb24784" [[package]] name = "windows_x86_64_gnu" -version = "0.42.2" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.2" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" [[package]] name = "windows_x86_64_msvc" @@ -5646,15 +5781,15 @@ checksum = "ff1e4aa646495048ec7f3ffddc411e1d829c026a2ec62b39da15c1055e406eaa" [[package]] name = "windows_x86_64_msvc" -version = "0.42.2" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[package]] name = "winnow" diff --git a/Cargo.toml b/Cargo.toml index 7d5da7b00d0..46ccb401fbd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,8 @@ [workspace] members = [ - # Macros crates for metaprogramming + # Aztec Macro crate for metaprogramming "aztec_macros", - "noirc_macros", # Compiler crates "compiler/noirc_evaluator", "compiler/noirc_frontend", @@ -26,6 +25,7 @@ members = [ "tooling/nargo_toml", "tooling/noirc_abi", "tooling/noirc_abi_wasm", + "tooling/acvm_cli", # ACVM "acvm-repo/acir_field", "acvm-repo/acir", @@ -36,12 +36,12 @@ members = [ "acvm-repo/blackbox_solver", "acvm-repo/bn254_blackbox_solver", ] -default-members = ["tooling/nargo_cli"] +default-members = ["tooling/nargo_cli", "tooling/acvm_cli"] resolver = "2" [workspace.package] # x-release-please-start-version -version = "0.24.0" +version = "0.26.0" # x-release-please-end authors = ["The Noir Team "] edition = "2021" @@ -52,13 +52,13 @@ repository = "https://github.com/noir-lang/noir/" [workspace.dependencies] # ACVM workspace dependencies -acir_field = { version = "0.40.0", path = "acvm-repo/acir_field", default-features = false } -acir = { version = "0.40.0", path = "acvm-repo/acir", default-features = false } -acvm = { version = "0.40.0", path = "acvm-repo/acvm" } -brillig = { version = "0.40.0", path = "acvm-repo/brillig", default-features = false } -brillig_vm = { version = "0.40.0", path = "acvm-repo/brillig_vm", default-features = false } -acvm_blackbox_solver = { version = "0.40.0", path = "acvm-repo/blackbox_solver", default-features = false } -bn254_blackbox_solver = { version = "0.39.0", path = "acvm-repo/bn254_blackbox_solver", default-features = false } +acir_field = { version = "0.42.0", path = "acvm-repo/acir_field", default-features = false } +acir = { version = "0.42.0", path = "acvm-repo/acir", default-features = false } +acvm = { version = "0.42.0", path = "acvm-repo/acvm" } +brillig = { version = "0.42.0", path = "acvm-repo/brillig", default-features = false } +brillig_vm = { version = "0.42.0", path = "acvm-repo/brillig_vm", default-features = false } +acvm_blackbox_solver = { version = "0.42.0", path = "acvm-repo/blackbox_solver", default-features = false } +bn254_blackbox_solver = { version = "0.42.0", path = "acvm-repo/bn254_blackbox_solver", default-features = false } # Noir compiler workspace dependencies arena = { path = "compiler/utils/arena" } @@ -78,6 +78,7 @@ noir_lsp = { path = "tooling/lsp" } noir_debugger = { path = "tooling/debugger" } noirc_abi = { path = "tooling/noirc_abi" } bb_abstraction_leaks = { path = "tooling/bb_abstraction_leaks" } +acvm_cli = { path = "tooling/acvm_cli" } # LSP async-lsp = { version = "0.1.0", default-features = false } diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 3a478c3f95a..00000000000 --- a/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM rust:bullseye -WORKDIR /usr/src/noir -COPY . . -RUN ./scripts/bootstrap_native.sh - -# When running the container, mount the users home directory to same location. -FROM ubuntu:focal -# Install Tini as nargo doesn't handle signals properly. -# Install git as nargo needs it to clone. -RUN apt-get update && apt-get install -y git tini && rm -rf /var/lib/apt/lists/* && apt-get clean -COPY --from=0 /usr/src/noir/target/release/nargo /usr/src/noir/target/release/nargo -ENTRYPOINT ["/usr/bin/tini", "--", "/usr/src/noir/target/release/nargo"] diff --git a/Dockerfile.ci b/Dockerfile.ci deleted file mode 100644 index e0dc030980c..00000000000 --- a/Dockerfile.ci +++ /dev/null @@ -1,30 +0,0 @@ -FROM rust:1.73.0-slim-bookworm as base -RUN apt-get update && apt-get upgrade -y && apt-get install build-essential git -y -WORKDIR /usr/src/noir -ENV PATH="${PATH}:/usr/src/noir/target/release" - -FROM base as base-nargo -COPY . . -RUN .github/scripts/nargo-build.sh - -FROM base as base-js -RUN apt-get install -y ca-certificates curl gnupg -RUN mkdir -p /etc/apt/keyrings -RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg -RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list -RUN apt-get update && apt-get install nodejs -y -RUN corepack enable -RUN apt-get install -y jq -COPY yarn.lock package.json .yarnrc.yml ./ -COPY .yarn/ ./.yarn/ -COPY ./acvm-repo/acvm_js/package.json ./acvm-repo/acvm_js/ -COPY ./tooling/noirc_abi_wasm/package.json ./tooling/noirc_abi_wasm/ -COPY ./compiler/wasm/package.json ./compiler/wasm/ -COPY ./tooling/noir_js_types/package.json ./tooling/noir_js_types/ -COPY ./tooling/noir_js_backend_barretenberg/package.json ./tooling/noir_js_backend_barretenberg/ -COPY ./tooling/noir_js/package.json ./tooling/noir_js/ -COPY ./tooling/noir_codegen/package.json ./tooling/noir_codegen/ -COPY ./compiler/integration-tests/package.json ./compiler/integration-tests/ -COPY ./docs/package.json ./docs/ -RUN yarn --immutable -COPY . . diff --git a/Dockerfile.packages b/Dockerfile.packages deleted file mode 100644 index f40670c19e4..00000000000 --- a/Dockerfile.packages +++ /dev/null @@ -1,22 +0,0 @@ -FROM rust:alpine3.17 -RUN apk update \ - && apk upgrade \ - && apk add --no-cache \ - build-base \ - pkgconfig \ - openssl-dev \ - npm \ - yarn \ - bash \ - jq \ - git \ - curl - -WORKDIR /usr/src/noir -COPY . . -RUN ./scripts/bootstrap_packages.sh - -FROM scratch -COPY --from=0 /usr/src/noir/packages /usr/src/noir/packages -# For some unknown reason, on alpine only, we need this to exist. -COPY --from=0 /usr/src/noir/node_modules/@noir-lang /usr/src/noir/node_modules/@noir-lang diff --git a/README.md b/README.md index 5c93512ae26..adf68b290ef 100644 --- a/README.md +++ b/README.md @@ -56,26 +56,6 @@ Concretely the following items are on the road map: This crate's minimum supported rustc version is 1.73.0. -## Working on this project - -This project uses [Nix](https://nixos.org/) and [direnv](https://direnv.net/) to streamline the development experience. Please follow [our guidelines](https://noir-lang.org/docs/getting_started/installation/other_install_methods#option-3-compile-from-source) to setup your environment for working on the project. - -### Building against a different local/remote version of Barretenberg - -If you are working on this project and want a different version of Barretenberg (instead of the version this project is pinned against), you'll want to replace the lockfile version with your version. This can be done by running: - -```sh -nix flake lock --override-input barretenberg /absolute/path/to/your/barretenberg -``` - -You can also point at a fork and/or branch on GitHub using: - -```sh -nix flake lock --override-input barretenberg github:username/barretenberg/branch_name -``` - -__Note:__ You don't want to commit the updated lockfile, as it will fail in CI! - ## License Noir is free and open source. It is distributed under a dual license. (MIT/APACHE) diff --git a/acvm-repo/CHANGELOG.md b/acvm-repo/CHANGELOG.md index acb465e5cc9..33cc83d7dd9 100644 --- a/acvm-repo/CHANGELOG.md +++ b/acvm-repo/CHANGELOG.md @@ -5,6 +5,151 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.42.0](https://github.com/noir-lang/noir/compare/v0.41.0...v0.42.0) (2024-03-25) + + +### ⚠ BREAKING CHANGES + +* **acir:** Program and witness stack structure (https://github.com/AztecProtocol/aztec-packages/pull/5149) +* automatic NoteInterface and NoteGetterOptions auto select (https://github.com/AztecProtocol/aztec-packages/pull/4508) +* Acir call opcode (https://github.com/AztecProtocol/aztec-packages/pull/4773) +* Support contracts with no constructor (https://github.com/AztecProtocol/aztec-packages/pull/5175) +* Internal as a macro (https://github.com/AztecProtocol/aztec-packages/pull/4898) +* move noir out of yarn-project (https://github.com/AztecProtocol/aztec-packages/pull/4479) +* note type ids (https://github.com/AztecProtocol/aztec-packages/pull/4500) +* rename bigint_neg into bigint_sub (https://github.com/AztecProtocol/aztec-packages/pull/4420) +* Add expression width into acir (https://github.com/AztecProtocol/aztec-packages/pull/4014) +* init storage macro (https://github.com/AztecProtocol/aztec-packages/pull/4200) +* **acir:** Move `is_recursive` flag to be part of the circuit definition (https://github.com/AztecProtocol/aztec-packages/pull/4221) +* Sync commits from `aztec-packages` ([#4144](https://github.com/noir-lang/noir/issues/4144)) +* Breaking changes from aztec-packages ([#3955](https://github.com/noir-lang/noir/issues/3955)) +* Rename Arithmetic opcode to AssertZero ([#3840](https://github.com/noir-lang/noir/issues/3840)) +* Remove unused methods on ACIR opcodes ([#3841](https://github.com/noir-lang/noir/issues/3841)) +* Remove partial backend feature ([#3805](https://github.com/noir-lang/noir/issues/3805)) + +### Features + +* Acir call opcode (https://github.com/AztecProtocol/aztec-packages/pull/4773) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* **acir:** Program and witness stack structure (https://github.com/AztecProtocol/aztec-packages/pull/5149) ([13eb71b](https://github.com/noir-lang/noir/commit/13eb71b8de44eb6aad9c37943ad06fc73db589f5)) +* Add bit size to const opcode (https://github.com/AztecProtocol/aztec-packages/pull/4385) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* Add CMOV instruction to brillig and brillig gen (https://github.com/AztecProtocol/aztec-packages/pull/5308) ([13eb71b](https://github.com/noir-lang/noir/commit/13eb71b8de44eb6aad9c37943ad06fc73db589f5)) +* Add expression width into acir (https://github.com/AztecProtocol/aztec-packages/pull/4014) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* Add instrumentation for tracking variables in debugging ([#4122](https://github.com/noir-lang/noir/issues/4122)) ([c58d691](https://github.com/noir-lang/noir/commit/c58d69141b54a918cd1675400c00bfd48720f896)) +* Add poseidon2 opcode implementation for acvm/brillig, and Noir ([#4398](https://github.com/noir-lang/noir/issues/4398)) ([10e8292](https://github.com/noir-lang/noir/commit/10e82920798380f50046e52db4a20ca205191ab7)) +* Add support for overriding expression width ([#4117](https://github.com/noir-lang/noir/issues/4117)) ([c8026d5](https://github.com/noir-lang/noir/commit/c8026d557d535b10fe455165d6445076df7a03de)) +* Added cast opcode and cast calldata (https://github.com/AztecProtocol/aztec-packages/pull/4423) ([78ef013](https://github.com/noir-lang/noir/commit/78ef0134b82e76a73dadb6c7975def22290e3a1a)) +* Allow brillig to read arrays directly from memory (https://github.com/AztecProtocol/aztec-packages/pull/4460) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* Allow nested arrays and vectors in Brillig foreign calls (https://github.com/AztecProtocol/aztec-packages/pull/4478) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* Allow variables and stack trace inspection in the debugger ([#4184](https://github.com/noir-lang/noir/issues/4184)) ([bf263fc](https://github.com/noir-lang/noir/commit/bf263fc8d843940f328a90f6366edd2671fb2682)) +* Automatic NoteInterface and NoteGetterOptions auto select (https://github.com/AztecProtocol/aztec-packages/pull/4508) ([13eb71b](https://github.com/noir-lang/noir/commit/13eb71b8de44eb6aad9c37943ad06fc73db589f5)) +* **avm:** Back in avm context with macro - refactor context (https://github.com/AztecProtocol/aztec-packages/pull/4438) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* **avm:** Brillig CONST of size > u128 (https://github.com/AztecProtocol/aztec-packages/pull/5217) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* **aztec-nr:** Initial work for aztec public vm macro (https://github.com/AztecProtocol/aztec-packages/pull/4400) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* Aztec-packages ([#3754](https://github.com/noir-lang/noir/issues/3754)) ([c043265](https://github.com/noir-lang/noir/commit/c043265e550b59bd4296504826fe15d3ce3e9ad2)) +* Backpropagate constants in ACIR during optimization ([#3926](https://github.com/noir-lang/noir/issues/3926)) ([aad0da0](https://github.com/noir-lang/noir/commit/aad0da024c69663f42e6913e674682d5864b26ae)) +* Breaking changes from aztec-packages ([#3955](https://github.com/noir-lang/noir/issues/3955)) ([5be049e](https://github.com/noir-lang/noir/commit/5be049eee6c342649462282ee04f6411e6ea392c)) +* Brillig IR refactor (https://github.com/AztecProtocol/aztec-packages/pull/5233) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Check initializer msg.sender matches deployer from address preimage (https://github.com/AztecProtocol/aztec-packages/pull/5222) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Evaluation of dynamic assert messages ([#4101](https://github.com/noir-lang/noir/issues/4101)) ([c284e01](https://github.com/noir-lang/noir/commit/c284e01bfe20ceae4414dc123624b5cbb8b66d09)) +* Init storage macro (https://github.com/AztecProtocol/aztec-packages/pull/4200) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* Initial Earthly CI (https://github.com/AztecProtocol/aztec-packages/pull/5069) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Internal as a macro (https://github.com/AztecProtocol/aztec-packages/pull/4898) ([5f57ebb](https://github.com/noir-lang/noir/commit/5f57ebb7ff4b810802f90699a10f4325ef904f2e)) +* New brillig field operations and refactor of binary operations (https://github.com/AztecProtocol/aztec-packages/pull/5208) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Note type ids (https://github.com/AztecProtocol/aztec-packages/pull/4500) ([78ef013](https://github.com/noir-lang/noir/commit/78ef0134b82e76a73dadb6c7975def22290e3a1a)) +* Remove range constraints from witnesses which are constrained to be constants ([#3928](https://github.com/noir-lang/noir/issues/3928)) ([afe9c7a](https://github.com/noir-lang/noir/commit/afe9c7a38bb9d4245205d3aa46d4ce23d70a5671)) +* Remove replacement of boolean range opcodes with `AssertZero` opcodes ([#4107](https://github.com/noir-lang/noir/issues/4107)) ([dac0e87](https://github.com/noir-lang/noir/commit/dac0e87ee3be3446b92bbb12ef4832fd493fcee3)) +* Signed integer division and modulus in brillig gen (https://github.com/AztecProtocol/aztec-packages/pull/5279) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Speed up transformation of debug messages ([#3815](https://github.com/noir-lang/noir/issues/3815)) ([2a8af1e](https://github.com/noir-lang/noir/commit/2a8af1e4141ffff61547ee1c2837a6392bd5db48)) +* Support contracts with no constructor (https://github.com/AztecProtocol/aztec-packages/pull/5175) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Sync `aztec-packages` ([#4011](https://github.com/noir-lang/noir/issues/4011)) ([fee2452](https://github.com/noir-lang/noir/commit/fee24523c427c27f0bdaf98ea09a852a2da3e94c)) +* Sync commits from `aztec-packages` ([#4068](https://github.com/noir-lang/noir/issues/4068)) ([7a8f3a3](https://github.com/noir-lang/noir/commit/7a8f3a33b57875e681e3d81e667e3570a1cdbdcc)) +* Sync commits from `aztec-packages` ([#4144](https://github.com/noir-lang/noir/issues/4144)) ([0205d3b](https://github.com/noir-lang/noir/commit/0205d3b4ad0cf5ffd775a43eb5af273a772cf138)) +* Sync from aztec-packages ([#4483](https://github.com/noir-lang/noir/issues/4483)) ([fe8f277](https://github.com/noir-lang/noir/commit/fe8f2776ccfde29209a2c3fc162311c99e4f59be)) +* Sync from noir (https://github.com/AztecProtocol/aztec-packages/pull/5234) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) +* Sync from noir (https://github.com/AztecProtocol/aztec-packages/pull/5286) ([c3c9e19](https://github.com/noir-lang/noir/commit/c3c9e19a20d61272a04b95fd6c7d34cc4cb96e45)) + + +### Bug Fixes + +* Deserialize odd length hex literals ([#3747](https://github.com/noir-lang/noir/issues/3747)) ([4000fb2](https://github.com/noir-lang/noir/commit/4000fb279221eb07187d657bfaa7f1c7b311abf2)) +* Noir test incorrect reporting (https://github.com/AztecProtocol/aztec-packages/pull/4925) ([5f57ebb](https://github.com/noir-lang/noir/commit/5f57ebb7ff4b810802f90699a10f4325ef904f2e)) +* Remove panic from `init_log_level` in `acvm_js` ([#4195](https://github.com/noir-lang/noir/issues/4195)) ([2e26530](https://github.com/noir-lang/noir/commit/2e26530bf53006c1ed4fee310bcaa905c95dd95b)) +* Return error rather instead of panicking on invalid circuit ([#3976](https://github.com/noir-lang/noir/issues/3976)) ([67201bf](https://github.com/noir-lang/noir/commit/67201bfc21a9c8858aa86be9cd47d463fb78d925)) + + +### Miscellaneous Chores + +* **acir:** Move `is_recursive` flag to be part of the circuit definition (https://github.com/AztecProtocol/aztec-packages/pull/4221) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* Move noir out of yarn-project (https://github.com/AztecProtocol/aztec-packages/pull/4479) ([78ef013](https://github.com/noir-lang/noir/commit/78ef0134b82e76a73dadb6c7975def22290e3a1a)) +* Remove partial backend feature ([#3805](https://github.com/noir-lang/noir/issues/3805)) ([0383100](https://github.com/noir-lang/noir/commit/0383100853a80a5b28b797cdfeae0d271f1b7805)) +* Remove unused methods on ACIR opcodes ([#3841](https://github.com/noir-lang/noir/issues/3841)) ([9e5d0e8](https://github.com/noir-lang/noir/commit/9e5d0e813d61a0bfb5ee68174ed287c5a20f1579)) +* Rename Arithmetic opcode to AssertZero ([#3840](https://github.com/noir-lang/noir/issues/3840)) ([836f171](https://github.com/noir-lang/noir/commit/836f17145c2901060706294461c2d282dd121b3e)) +* Rename bigint_neg into bigint_sub (https://github.com/AztecProtocol/aztec-packages/pull/4420) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) + +## [0.41.0](https://github.com/noir-lang/noir/compare/v0.40.0...v0.41.0) (2024-03-11) + + +### ⚠ BREAKING CHANGES + +* Internal as a macro (https://github.com/AztecProtocol/aztec-packages/pull/4898) +* move noir out of yarn-project (https://github.com/AztecProtocol/aztec-packages/pull/4479) +* note type ids (https://github.com/AztecProtocol/aztec-packages/pull/4500) +* rename bigint_neg into bigint_sub (https://github.com/AztecProtocol/aztec-packages/pull/4420) +* Add expression width into acir (https://github.com/AztecProtocol/aztec-packages/pull/4014) +* init storage macro (https://github.com/AztecProtocol/aztec-packages/pull/4200) +* **acir:** Move `is_recursive` flag to be part of the circuit definition (https://github.com/AztecProtocol/aztec-packages/pull/4221) +* Sync commits from `aztec-packages` ([#4144](https://github.com/noir-lang/noir/issues/4144)) +* Breaking changes from aztec-packages ([#3955](https://github.com/noir-lang/noir/issues/3955)) +* Rename Arithmetic opcode to AssertZero ([#3840](https://github.com/noir-lang/noir/issues/3840)) +* Remove unused methods on ACIR opcodes ([#3841](https://github.com/noir-lang/noir/issues/3841)) +* Remove partial backend feature ([#3805](https://github.com/noir-lang/noir/issues/3805)) + +### Features + +* Add bit size to const opcode (https://github.com/AztecProtocol/aztec-packages/pull/4385) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* Add expression width into acir (https://github.com/AztecProtocol/aztec-packages/pull/4014) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* Add instrumentation for tracking variables in debugging ([#4122](https://github.com/noir-lang/noir/issues/4122)) ([c58d691](https://github.com/noir-lang/noir/commit/c58d69141b54a918cd1675400c00bfd48720f896)) +* Add poseidon2 opcode implementation for acvm/brillig, and Noir ([#4398](https://github.com/noir-lang/noir/issues/4398)) ([10e8292](https://github.com/noir-lang/noir/commit/10e82920798380f50046e52db4a20ca205191ab7)) +* Add support for overriding expression width ([#4117](https://github.com/noir-lang/noir/issues/4117)) ([c8026d5](https://github.com/noir-lang/noir/commit/c8026d557d535b10fe455165d6445076df7a03de)) +* Added cast opcode and cast calldata (https://github.com/AztecProtocol/aztec-packages/pull/4423) ([78ef013](https://github.com/noir-lang/noir/commit/78ef0134b82e76a73dadb6c7975def22290e3a1a)) +* Allow brillig to read arrays directly from memory (https://github.com/AztecProtocol/aztec-packages/pull/4460) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* Allow nested arrays and vectors in Brillig foreign calls (https://github.com/AztecProtocol/aztec-packages/pull/4478) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* Allow variables and stack trace inspection in the debugger ([#4184](https://github.com/noir-lang/noir/issues/4184)) ([bf263fc](https://github.com/noir-lang/noir/commit/bf263fc8d843940f328a90f6366edd2671fb2682)) +* **avm:** Back in avm context with macro - refactor context (https://github.com/AztecProtocol/aztec-packages/pull/4438) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* **aztec-nr:** Initial work for aztec public vm macro (https://github.com/AztecProtocol/aztec-packages/pull/4400) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* Aztec-packages ([#3754](https://github.com/noir-lang/noir/issues/3754)) ([c043265](https://github.com/noir-lang/noir/commit/c043265e550b59bd4296504826fe15d3ce3e9ad2)) +* Backpropagate constants in ACIR during optimization ([#3926](https://github.com/noir-lang/noir/issues/3926)) ([aad0da0](https://github.com/noir-lang/noir/commit/aad0da024c69663f42e6913e674682d5864b26ae)) +* Breaking changes from aztec-packages ([#3955](https://github.com/noir-lang/noir/issues/3955)) ([5be049e](https://github.com/noir-lang/noir/commit/5be049eee6c342649462282ee04f6411e6ea392c)) +* Evaluation of dynamic assert messages ([#4101](https://github.com/noir-lang/noir/issues/4101)) ([c284e01](https://github.com/noir-lang/noir/commit/c284e01bfe20ceae4414dc123624b5cbb8b66d09)) +* Init storage macro (https://github.com/AztecProtocol/aztec-packages/pull/4200) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* Internal as a macro (https://github.com/AztecProtocol/aztec-packages/pull/4898) ([5f57ebb](https://github.com/noir-lang/noir/commit/5f57ebb7ff4b810802f90699a10f4325ef904f2e)) +* Note type ids (https://github.com/AztecProtocol/aztec-packages/pull/4500) ([78ef013](https://github.com/noir-lang/noir/commit/78ef0134b82e76a73dadb6c7975def22290e3a1a)) +* Remove range constraints from witnesses which are constrained to be constants ([#3928](https://github.com/noir-lang/noir/issues/3928)) ([afe9c7a](https://github.com/noir-lang/noir/commit/afe9c7a38bb9d4245205d3aa46d4ce23d70a5671)) +* Remove replacement of boolean range opcodes with `AssertZero` opcodes ([#4107](https://github.com/noir-lang/noir/issues/4107)) ([dac0e87](https://github.com/noir-lang/noir/commit/dac0e87ee3be3446b92bbb12ef4832fd493fcee3)) +* Speed up transformation of debug messages ([#3815](https://github.com/noir-lang/noir/issues/3815)) ([2a8af1e](https://github.com/noir-lang/noir/commit/2a8af1e4141ffff61547ee1c2837a6392bd5db48)) +* Sync `aztec-packages` ([#4011](https://github.com/noir-lang/noir/issues/4011)) ([fee2452](https://github.com/noir-lang/noir/commit/fee24523c427c27f0bdaf98ea09a852a2da3e94c)) +* Sync commits from `aztec-packages` ([#4068](https://github.com/noir-lang/noir/issues/4068)) ([7a8f3a3](https://github.com/noir-lang/noir/commit/7a8f3a33b57875e681e3d81e667e3570a1cdbdcc)) +* Sync commits from `aztec-packages` ([#4144](https://github.com/noir-lang/noir/issues/4144)) ([0205d3b](https://github.com/noir-lang/noir/commit/0205d3b4ad0cf5ffd775a43eb5af273a772cf138)) +* Sync from aztec-packages ([#4483](https://github.com/noir-lang/noir/issues/4483)) ([fe8f277](https://github.com/noir-lang/noir/commit/fe8f2776ccfde29209a2c3fc162311c99e4f59be)) + + +### Bug Fixes + +* Deserialize odd length hex literals ([#3747](https://github.com/noir-lang/noir/issues/3747)) ([4000fb2](https://github.com/noir-lang/noir/commit/4000fb279221eb07187d657bfaa7f1c7b311abf2)) +* Noir test incorrect reporting (https://github.com/AztecProtocol/aztec-packages/pull/4925) ([5f57ebb](https://github.com/noir-lang/noir/commit/5f57ebb7ff4b810802f90699a10f4325ef904f2e)) +* Remove panic from `init_log_level` in `acvm_js` ([#4195](https://github.com/noir-lang/noir/issues/4195)) ([2e26530](https://github.com/noir-lang/noir/commit/2e26530bf53006c1ed4fee310bcaa905c95dd95b)) +* Return error rather instead of panicking on invalid circuit ([#3976](https://github.com/noir-lang/noir/issues/3976)) ([67201bf](https://github.com/noir-lang/noir/commit/67201bfc21a9c8858aa86be9cd47d463fb78d925)) + + +### Miscellaneous Chores + +* **acir:** Move `is_recursive` flag to be part of the circuit definition (https://github.com/AztecProtocol/aztec-packages/pull/4221) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) +* Move noir out of yarn-project (https://github.com/AztecProtocol/aztec-packages/pull/4479) ([78ef013](https://github.com/noir-lang/noir/commit/78ef0134b82e76a73dadb6c7975def22290e3a1a)) +* Remove partial backend feature ([#3805](https://github.com/noir-lang/noir/issues/3805)) ([0383100](https://github.com/noir-lang/noir/commit/0383100853a80a5b28b797cdfeae0d271f1b7805)) +* Remove unused methods on ACIR opcodes ([#3841](https://github.com/noir-lang/noir/issues/3841)) ([9e5d0e8](https://github.com/noir-lang/noir/commit/9e5d0e813d61a0bfb5ee68174ed287c5a20f1579)) +* Rename Arithmetic opcode to AssertZero ([#3840](https://github.com/noir-lang/noir/issues/3840)) ([836f171](https://github.com/noir-lang/noir/commit/836f17145c2901060706294461c2d282dd121b3e)) +* Rename bigint_neg into bigint_sub (https://github.com/AztecProtocol/aztec-packages/pull/4420) ([158c8ce](https://github.com/noir-lang/noir/commit/158c8cec7f0dc698042e9512001dd2c9d6b40bcc)) + ## [0.40.0](https://github.com/noir-lang/noir/compare/v0.39.0...v0.40.0) (2024-02-12) diff --git a/acvm-repo/acir/Cargo.toml b/acvm-repo/acir/Cargo.toml index 7021333486f..368f49258f9 100644 --- a/acvm-repo/acir/Cargo.toml +++ b/acvm-repo/acir/Cargo.toml @@ -2,7 +2,7 @@ name = "acir" description = "ACIR is the IR that the VM processes, it is analogous to LLVM IR" # x-release-please-start-version -version = "0.40.0" +version = "0.42.0" # x-release-please-end authors.workspace = true edition.workspace = true diff --git a/acvm-repo/acir/codegen/acir.cpp b/acvm-repo/acir/codegen/acir.cpp index 0fc84d47a0f..d7ef849ab75 100644 --- a/acvm-repo/acir/codegen/acir.cpp +++ b/acvm-repo/acir/codegen/acir.cpp @@ -3,174 +3,67 @@ #include "serde.hpp" #include "bincode.hpp" -namespace Circuit { +namespace Program { - struct BinaryFieldOp { - - struct Add { - friend bool operator==(const Add&, const Add&); - std::vector bincodeSerialize() const; - static Add bincodeDeserialize(std::vector); - }; - - struct Sub { - friend bool operator==(const Sub&, const Sub&); - std::vector bincodeSerialize() const; - static Sub bincodeDeserialize(std::vector); - }; - - struct Mul { - friend bool operator==(const Mul&, const Mul&); - std::vector bincodeSerialize() const; - static Mul bincodeDeserialize(std::vector); - }; - - struct Div { - friend bool operator==(const Div&, const Div&); - std::vector bincodeSerialize() const; - static Div bincodeDeserialize(std::vector); - }; - - struct Equals { - friend bool operator==(const Equals&, const Equals&); - std::vector bincodeSerialize() const; - static Equals bincodeDeserialize(std::vector); - }; - - std::variant value; + struct Witness { + uint32_t value; - friend bool operator==(const BinaryFieldOp&, const BinaryFieldOp&); + friend bool operator==(const Witness&, const Witness&); std::vector bincodeSerialize() const; - static BinaryFieldOp bincodeDeserialize(std::vector); + static Witness bincodeDeserialize(std::vector); }; - struct BinaryIntOp { - - struct Add { - friend bool operator==(const Add&, const Add&); - std::vector bincodeSerialize() const; - static Add bincodeDeserialize(std::vector); - }; - - struct Sub { - friend bool operator==(const Sub&, const Sub&); - std::vector bincodeSerialize() const; - static Sub bincodeDeserialize(std::vector); - }; - - struct Mul { - friend bool operator==(const Mul&, const Mul&); - std::vector bincodeSerialize() const; - static Mul bincodeDeserialize(std::vector); - }; - - struct SignedDiv { - friend bool operator==(const SignedDiv&, const SignedDiv&); - std::vector bincodeSerialize() const; - static SignedDiv bincodeDeserialize(std::vector); - }; - - struct UnsignedDiv { - friend bool operator==(const UnsignedDiv&, const UnsignedDiv&); - std::vector bincodeSerialize() const; - static UnsignedDiv bincodeDeserialize(std::vector); - }; + struct FunctionInput { + Program::Witness witness; + uint32_t num_bits; - struct Equals { - friend bool operator==(const Equals&, const Equals&); - std::vector bincodeSerialize() const; - static Equals bincodeDeserialize(std::vector); - }; + friend bool operator==(const FunctionInput&, const FunctionInput&); + std::vector bincodeSerialize() const; + static FunctionInput bincodeDeserialize(std::vector); + }; - struct LessThan { - friend bool operator==(const LessThan&, const LessThan&); - std::vector bincodeSerialize() const; - static LessThan bincodeDeserialize(std::vector); - }; + struct BlackBoxFuncCall { - struct LessThanEquals { - friend bool operator==(const LessThanEquals&, const LessThanEquals&); - std::vector bincodeSerialize() const; - static LessThanEquals bincodeDeserialize(std::vector); - }; + struct AND { + Program::FunctionInput lhs; + Program::FunctionInput rhs; + Program::Witness output; - struct And { - friend bool operator==(const And&, const And&); + friend bool operator==(const AND&, const AND&); std::vector bincodeSerialize() const; - static And bincodeDeserialize(std::vector); + static AND bincodeDeserialize(std::vector); }; - struct Or { - friend bool operator==(const Or&, const Or&); - std::vector bincodeSerialize() const; - static Or bincodeDeserialize(std::vector); - }; + struct XOR { + Program::FunctionInput lhs; + Program::FunctionInput rhs; + Program::Witness output; - struct Xor { - friend bool operator==(const Xor&, const Xor&); + friend bool operator==(const XOR&, const XOR&); std::vector bincodeSerialize() const; - static Xor bincodeDeserialize(std::vector); + static XOR bincodeDeserialize(std::vector); }; - struct Shl { - friend bool operator==(const Shl&, const Shl&); - std::vector bincodeSerialize() const; - static Shl bincodeDeserialize(std::vector); - }; + struct RANGE { + Program::FunctionInput input; - struct Shr { - friend bool operator==(const Shr&, const Shr&); + friend bool operator==(const RANGE&, const RANGE&); std::vector bincodeSerialize() const; - static Shr bincodeDeserialize(std::vector); + static RANGE bincodeDeserialize(std::vector); }; - std::variant value; - - friend bool operator==(const BinaryIntOp&, const BinaryIntOp&); - std::vector bincodeSerialize() const; - static BinaryIntOp bincodeDeserialize(std::vector); - }; - - struct MemoryAddress { - uint64_t value; - - friend bool operator==(const MemoryAddress&, const MemoryAddress&); - std::vector bincodeSerialize() const; - static MemoryAddress bincodeDeserialize(std::vector); - }; - - struct HeapArray { - Circuit::MemoryAddress pointer; - uint64_t size; - - friend bool operator==(const HeapArray&, const HeapArray&); - std::vector bincodeSerialize() const; - static HeapArray bincodeDeserialize(std::vector); - }; - - struct HeapVector { - Circuit::MemoryAddress pointer; - Circuit::MemoryAddress size; - - friend bool operator==(const HeapVector&, const HeapVector&); - std::vector bincodeSerialize() const; - static HeapVector bincodeDeserialize(std::vector); - }; - - struct BlackBoxOp { - - struct Sha256 { - Circuit::HeapVector message; - Circuit::HeapArray output; + struct SHA256 { + std::vector inputs; + std::vector outputs; - friend bool operator==(const Sha256&, const Sha256&); + friend bool operator==(const SHA256&, const SHA256&); std::vector bincodeSerialize() const; - static Sha256 bincodeDeserialize(std::vector); + static SHA256 bincodeDeserialize(std::vector); }; struct Blake2s { - Circuit::HeapVector message; - Circuit::HeapArray output; + std::vector inputs; + std::vector outputs; friend bool operator==(const Blake2s&, const Blake2s&); std::vector bincodeSerialize() const; @@ -178,38 +71,52 @@ namespace Circuit { }; struct Blake3 { - Circuit::HeapVector message; - Circuit::HeapArray output; + std::vector inputs; + std::vector outputs; friend bool operator==(const Blake3&, const Blake3&); std::vector bincodeSerialize() const; static Blake3 bincodeDeserialize(std::vector); }; - struct Keccak256 { - Circuit::HeapVector message; - Circuit::HeapArray output; + struct SchnorrVerify { + Program::FunctionInput public_key_x; + Program::FunctionInput public_key_y; + std::vector signature; + std::vector message; + Program::Witness output; - friend bool operator==(const Keccak256&, const Keccak256&); + friend bool operator==(const SchnorrVerify&, const SchnorrVerify&); std::vector bincodeSerialize() const; - static Keccak256 bincodeDeserialize(std::vector); + static SchnorrVerify bincodeDeserialize(std::vector); }; - struct Keccakf1600 { - Circuit::HeapVector message; - Circuit::HeapArray output; + struct PedersenCommitment { + std::vector inputs; + uint32_t domain_separator; + std::array outputs; - friend bool operator==(const Keccakf1600&, const Keccakf1600&); + friend bool operator==(const PedersenCommitment&, const PedersenCommitment&); std::vector bincodeSerialize() const; - static Keccakf1600 bincodeDeserialize(std::vector); + static PedersenCommitment bincodeDeserialize(std::vector); + }; + + struct PedersenHash { + std::vector inputs; + uint32_t domain_separator; + Program::Witness output; + + friend bool operator==(const PedersenHash&, const PedersenHash&); + std::vector bincodeSerialize() const; + static PedersenHash bincodeDeserialize(std::vector); }; struct EcdsaSecp256k1 { - Circuit::HeapVector hashed_msg; - Circuit::HeapArray public_key_x; - Circuit::HeapArray public_key_y; - Circuit::HeapArray signature; - Circuit::MemoryAddress result; + std::vector public_key_x; + std::vector public_key_y; + std::vector signature; + std::vector hashed_message; + Program::Witness output; friend bool operator==(const EcdsaSecp256k1&, const EcdsaSecp256k1&); std::vector bincodeSerialize() const; @@ -217,75 +124,82 @@ namespace Circuit { }; struct EcdsaSecp256r1 { - Circuit::HeapVector hashed_msg; - Circuit::HeapArray public_key_x; - Circuit::HeapArray public_key_y; - Circuit::HeapArray signature; - Circuit::MemoryAddress result; + std::vector public_key_x; + std::vector public_key_y; + std::vector signature; + std::vector hashed_message; + Program::Witness output; friend bool operator==(const EcdsaSecp256r1&, const EcdsaSecp256r1&); std::vector bincodeSerialize() const; static EcdsaSecp256r1 bincodeDeserialize(std::vector); }; - struct SchnorrVerify { - Circuit::MemoryAddress public_key_x; - Circuit::MemoryAddress public_key_y; - Circuit::HeapVector message; - Circuit::HeapVector signature; - Circuit::MemoryAddress result; + struct FixedBaseScalarMul { + Program::FunctionInput low; + Program::FunctionInput high; + std::array outputs; - friend bool operator==(const SchnorrVerify&, const SchnorrVerify&); + friend bool operator==(const FixedBaseScalarMul&, const FixedBaseScalarMul&); std::vector bincodeSerialize() const; - static SchnorrVerify bincodeDeserialize(std::vector); + static FixedBaseScalarMul bincodeDeserialize(std::vector); }; - struct PedersenCommitment { - Circuit::HeapVector inputs; - Circuit::MemoryAddress domain_separator; - Circuit::HeapArray output; + struct EmbeddedCurveAdd { + Program::FunctionInput input1_x; + Program::FunctionInput input1_y; + Program::FunctionInput input2_x; + Program::FunctionInput input2_y; + std::array outputs; - friend bool operator==(const PedersenCommitment&, const PedersenCommitment&); + friend bool operator==(const EmbeddedCurveAdd&, const EmbeddedCurveAdd&); std::vector bincodeSerialize() const; - static PedersenCommitment bincodeDeserialize(std::vector); + static EmbeddedCurveAdd bincodeDeserialize(std::vector); }; - struct PedersenHash { - Circuit::HeapVector inputs; - Circuit::MemoryAddress domain_separator; - Circuit::MemoryAddress output; + struct Keccak256 { + std::vector inputs; + std::vector outputs; - friend bool operator==(const PedersenHash&, const PedersenHash&); + friend bool operator==(const Keccak256&, const Keccak256&); std::vector bincodeSerialize() const; - static PedersenHash bincodeDeserialize(std::vector); + static Keccak256 bincodeDeserialize(std::vector); }; - struct FixedBaseScalarMul { - Circuit::MemoryAddress low; - Circuit::MemoryAddress high; - Circuit::HeapArray result; + struct Keccak256VariableLength { + std::vector inputs; + Program::FunctionInput var_message_size; + std::vector outputs; - friend bool operator==(const FixedBaseScalarMul&, const FixedBaseScalarMul&); + friend bool operator==(const Keccak256VariableLength&, const Keccak256VariableLength&); std::vector bincodeSerialize() const; - static FixedBaseScalarMul bincodeDeserialize(std::vector); + static Keccak256VariableLength bincodeDeserialize(std::vector); }; - struct EmbeddedCurveAdd { - Circuit::MemoryAddress input1_x; - Circuit::MemoryAddress input1_y; - Circuit::MemoryAddress input2_x; - Circuit::MemoryAddress input2_y; - Circuit::HeapArray result; + struct Keccakf1600 { + std::vector inputs; + std::vector outputs; - friend bool operator==(const EmbeddedCurveAdd&, const EmbeddedCurveAdd&); + friend bool operator==(const Keccakf1600&, const Keccakf1600&); std::vector bincodeSerialize() const; - static EmbeddedCurveAdd bincodeDeserialize(std::vector); + static Keccakf1600 bincodeDeserialize(std::vector); + }; + + struct RecursiveAggregation { + std::vector verification_key; + std::vector proof; + std::vector public_inputs; + Program::FunctionInput key_hash; + + friend bool operator==(const RecursiveAggregation&, const RecursiveAggregation&); + std::vector bincodeSerialize() const; + static RecursiveAggregation bincodeDeserialize(std::vector); }; struct BigIntAdd { - Circuit::MemoryAddress lhs; - Circuit::MemoryAddress rhs; - Circuit::MemoryAddress output; + uint32_t lhs; + uint32_t rhs; + uint32_t output; friend bool operator==(const BigIntAdd&, const BigIntAdd&); std::vector bincodeSerialize() const; @@ -293,9 +207,9 @@ namespace Circuit { }; struct BigIntSub { - Circuit::MemoryAddress lhs; - Circuit::MemoryAddress rhs; - Circuit::MemoryAddress output; + uint32_t lhs; + uint32_t rhs; + uint32_t output; friend bool operator==(const BigIntSub&, const BigIntSub&); std::vector bincodeSerialize() const; @@ -303,9 +217,9 @@ namespace Circuit { }; struct BigIntMul { - Circuit::MemoryAddress lhs; - Circuit::MemoryAddress rhs; - Circuit::MemoryAddress output; + uint32_t lhs; + uint32_t rhs; + uint32_t output; friend bool operator==(const BigIntMul&, const BigIntMul&); std::vector bincodeSerialize() const; @@ -313,9 +227,9 @@ namespace Circuit { }; struct BigIntDiv { - Circuit::MemoryAddress lhs; - Circuit::MemoryAddress rhs; - Circuit::MemoryAddress output; + uint32_t lhs; + uint32_t rhs; + uint32_t output; friend bool operator==(const BigIntDiv&, const BigIntDiv&); std::vector bincodeSerialize() const; @@ -323,9 +237,9 @@ namespace Circuit { }; struct BigIntFromLeBytes { - Circuit::HeapVector inputs; - Circuit::HeapVector modulus; - Circuit::MemoryAddress output; + std::vector inputs; + std::vector modulus; + uint32_t output; friend bool operator==(const BigIntFromLeBytes&, const BigIntFromLeBytes&); std::vector bincodeSerialize() const; @@ -333,8 +247,8 @@ namespace Circuit { }; struct BigIntToLeBytes { - Circuit::MemoryAddress input; - Circuit::HeapVector output; + uint32_t input; + std::vector outputs; friend bool operator==(const BigIntToLeBytes&, const BigIntToLeBytes&); std::vector bincodeSerialize() const; @@ -342,9 +256,9 @@ namespace Circuit { }; struct Poseidon2Permutation { - Circuit::HeapVector message; - Circuit::HeapArray output; - Circuit::MemoryAddress len; + std::vector inputs; + std::vector outputs; + uint32_t len; friend bool operator==(const Poseidon2Permutation&, const Poseidon2Permutation&); std::vector bincodeSerialize() const; @@ -352,320 +266,251 @@ namespace Circuit { }; struct Sha256Compression { - Circuit::HeapVector input; - Circuit::HeapVector hash_values; - Circuit::HeapArray output; + std::vector inputs; + std::vector hash_values; + std::vector outputs; friend bool operator==(const Sha256Compression&, const Sha256Compression&); std::vector bincodeSerialize() const; static Sha256Compression bincodeDeserialize(std::vector); }; - std::variant value; + std::variant value; - friend bool operator==(const BlackBoxOp&, const BlackBoxOp&); + friend bool operator==(const BlackBoxFuncCall&, const BlackBoxFuncCall&); std::vector bincodeSerialize() const; - static BlackBoxOp bincodeDeserialize(std::vector); + static BlackBoxFuncCall bincodeDeserialize(std::vector); }; - struct HeapValueType; + struct BlockId { + uint32_t value; - struct HeapValueType { + friend bool operator==(const BlockId&, const BlockId&); + std::vector bincodeSerialize() const; + static BlockId bincodeDeserialize(std::vector); + }; - struct Simple { - friend bool operator==(const Simple&, const Simple&); + struct Expression { + std::vector> mul_terms; + std::vector> linear_combinations; + std::string q_c; + + friend bool operator==(const Expression&, const Expression&); + std::vector bincodeSerialize() const; + static Expression bincodeDeserialize(std::vector); + }; + + struct BrilligInputs { + + struct Single { + Program::Expression value; + + friend bool operator==(const Single&, const Single&); std::vector bincodeSerialize() const; - static Simple bincodeDeserialize(std::vector); + static Single bincodeDeserialize(std::vector); }; struct Array { - std::vector value_types; - uint64_t size; + std::vector value; friend bool operator==(const Array&, const Array&); std::vector bincodeSerialize() const; static Array bincodeDeserialize(std::vector); }; - struct Vector { - std::vector value_types; + struct MemoryArray { + Program::BlockId value; - friend bool operator==(const Vector&, const Vector&); + friend bool operator==(const MemoryArray&, const MemoryArray&); std::vector bincodeSerialize() const; - static Vector bincodeDeserialize(std::vector); + static MemoryArray bincodeDeserialize(std::vector); }; - std::variant value; - - friend bool operator==(const HeapValueType&, const HeapValueType&); - std::vector bincodeSerialize() const; - static HeapValueType bincodeDeserialize(std::vector); - }; - - struct Value { - std::string inner; + std::variant value; - friend bool operator==(const Value&, const Value&); + friend bool operator==(const BrilligInputs&, const BrilligInputs&); std::vector bincodeSerialize() const; - static Value bincodeDeserialize(std::vector); + static BrilligInputs bincodeDeserialize(std::vector); }; - struct ValueOrArray { - - struct MemoryAddress { - Circuit::MemoryAddress value; + struct BinaryFieldOp { - friend bool operator==(const MemoryAddress&, const MemoryAddress&); + struct Add { + friend bool operator==(const Add&, const Add&); std::vector bincodeSerialize() const; - static MemoryAddress bincodeDeserialize(std::vector); + static Add bincodeDeserialize(std::vector); }; - struct HeapArray { - Circuit::HeapArray value; - - friend bool operator==(const HeapArray&, const HeapArray&); + struct Sub { + friend bool operator==(const Sub&, const Sub&); std::vector bincodeSerialize() const; - static HeapArray bincodeDeserialize(std::vector); + static Sub bincodeDeserialize(std::vector); }; - struct HeapVector { - Circuit::HeapVector value; - - friend bool operator==(const HeapVector&, const HeapVector&); + struct Mul { + friend bool operator==(const Mul&, const Mul&); std::vector bincodeSerialize() const; - static HeapVector bincodeDeserialize(std::vector); + static Mul bincodeDeserialize(std::vector); }; - std::variant value; - - friend bool operator==(const ValueOrArray&, const ValueOrArray&); - std::vector bincodeSerialize() const; - static ValueOrArray bincodeDeserialize(std::vector); - }; - - struct BrilligOpcode { - - struct BinaryFieldOp { - Circuit::MemoryAddress destination; - Circuit::BinaryFieldOp op; - Circuit::MemoryAddress lhs; - Circuit::MemoryAddress rhs; - - friend bool operator==(const BinaryFieldOp&, const BinaryFieldOp&); + struct Div { + friend bool operator==(const Div&, const Div&); std::vector bincodeSerialize() const; - static BinaryFieldOp bincodeDeserialize(std::vector); + static Div bincodeDeserialize(std::vector); }; - struct BinaryIntOp { - Circuit::MemoryAddress destination; - Circuit::BinaryIntOp op; - uint32_t bit_size; - Circuit::MemoryAddress lhs; - Circuit::MemoryAddress rhs; - - friend bool operator==(const BinaryIntOp&, const BinaryIntOp&); + struct IntegerDiv { + friend bool operator==(const IntegerDiv&, const IntegerDiv&); std::vector bincodeSerialize() const; - static BinaryIntOp bincodeDeserialize(std::vector); + static IntegerDiv bincodeDeserialize(std::vector); }; - struct Cast { - Circuit::MemoryAddress destination; - Circuit::MemoryAddress source; - uint32_t bit_size; - - friend bool operator==(const Cast&, const Cast&); + struct Equals { + friend bool operator==(const Equals&, const Equals&); std::vector bincodeSerialize() const; - static Cast bincodeDeserialize(std::vector); + static Equals bincodeDeserialize(std::vector); }; - struct JumpIfNot { - Circuit::MemoryAddress condition; - uint64_t location; - - friend bool operator==(const JumpIfNot&, const JumpIfNot&); + struct LessThan { + friend bool operator==(const LessThan&, const LessThan&); std::vector bincodeSerialize() const; - static JumpIfNot bincodeDeserialize(std::vector); + static LessThan bincodeDeserialize(std::vector); }; - struct JumpIf { - Circuit::MemoryAddress condition; - uint64_t location; - - friend bool operator==(const JumpIf&, const JumpIf&); + struct LessThanEquals { + friend bool operator==(const LessThanEquals&, const LessThanEquals&); std::vector bincodeSerialize() const; - static JumpIf bincodeDeserialize(std::vector); + static LessThanEquals bincodeDeserialize(std::vector); }; - struct Jump { - uint64_t location; + std::variant value; - friend bool operator==(const Jump&, const Jump&); - std::vector bincodeSerialize() const; - static Jump bincodeDeserialize(std::vector); - }; + friend bool operator==(const BinaryFieldOp&, const BinaryFieldOp&); + std::vector bincodeSerialize() const; + static BinaryFieldOp bincodeDeserialize(std::vector); + }; - struct CalldataCopy { - Circuit::MemoryAddress destination_address; - uint64_t size; - uint64_t offset; + struct BinaryIntOp { - friend bool operator==(const CalldataCopy&, const CalldataCopy&); + struct Add { + friend bool operator==(const Add&, const Add&); std::vector bincodeSerialize() const; - static CalldataCopy bincodeDeserialize(std::vector); + static Add bincodeDeserialize(std::vector); }; - struct Call { - uint64_t location; - - friend bool operator==(const Call&, const Call&); + struct Sub { + friend bool operator==(const Sub&, const Sub&); std::vector bincodeSerialize() const; - static Call bincodeDeserialize(std::vector); + static Sub bincodeDeserialize(std::vector); }; - struct Const { - Circuit::MemoryAddress destination; - uint32_t bit_size; - Circuit::Value value; - - friend bool operator==(const Const&, const Const&); + struct Mul { + friend bool operator==(const Mul&, const Mul&); std::vector bincodeSerialize() const; - static Const bincodeDeserialize(std::vector); + static Mul bincodeDeserialize(std::vector); }; - struct Return { - friend bool operator==(const Return&, const Return&); + struct Div { + friend bool operator==(const Div&, const Div&); std::vector bincodeSerialize() const; - static Return bincodeDeserialize(std::vector); + static Div bincodeDeserialize(std::vector); }; - struct ForeignCall { - std::string function; - std::vector destinations; - std::vector destination_value_types; - std::vector inputs; - std::vector input_value_types; - - friend bool operator==(const ForeignCall&, const ForeignCall&); + struct Equals { + friend bool operator==(const Equals&, const Equals&); std::vector bincodeSerialize() const; - static ForeignCall bincodeDeserialize(std::vector); + static Equals bincodeDeserialize(std::vector); }; - struct Mov { - Circuit::MemoryAddress destination; - Circuit::MemoryAddress source; - - friend bool operator==(const Mov&, const Mov&); + struct LessThan { + friend bool operator==(const LessThan&, const LessThan&); std::vector bincodeSerialize() const; - static Mov bincodeDeserialize(std::vector); + static LessThan bincodeDeserialize(std::vector); }; - struct Load { - Circuit::MemoryAddress destination; - Circuit::MemoryAddress source_pointer; - - friend bool operator==(const Load&, const Load&); + struct LessThanEquals { + friend bool operator==(const LessThanEquals&, const LessThanEquals&); std::vector bincodeSerialize() const; - static Load bincodeDeserialize(std::vector); + static LessThanEquals bincodeDeserialize(std::vector); }; - struct Store { - Circuit::MemoryAddress destination_pointer; - Circuit::MemoryAddress source; - - friend bool operator==(const Store&, const Store&); + struct And { + friend bool operator==(const And&, const And&); std::vector bincodeSerialize() const; - static Store bincodeDeserialize(std::vector); + static And bincodeDeserialize(std::vector); }; - struct BlackBox { - Circuit::BlackBoxOp value; - - friend bool operator==(const BlackBox&, const BlackBox&); + struct Or { + friend bool operator==(const Or&, const Or&); std::vector bincodeSerialize() const; - static BlackBox bincodeDeserialize(std::vector); + static Or bincodeDeserialize(std::vector); }; - struct Trap { - friend bool operator==(const Trap&, const Trap&); + struct Xor { + friend bool operator==(const Xor&, const Xor&); std::vector bincodeSerialize() const; - static Trap bincodeDeserialize(std::vector); + static Xor bincodeDeserialize(std::vector); }; - struct Stop { - uint64_t return_data_offset; - uint64_t return_data_size; + struct Shl { + friend bool operator==(const Shl&, const Shl&); + std::vector bincodeSerialize() const; + static Shl bincodeDeserialize(std::vector); + }; - friend bool operator==(const Stop&, const Stop&); + struct Shr { + friend bool operator==(const Shr&, const Shr&); std::vector bincodeSerialize() const; - static Stop bincodeDeserialize(std::vector); + static Shr bincodeDeserialize(std::vector); }; - std::variant value; + std::variant value; - friend bool operator==(const BrilligOpcode&, const BrilligOpcode&); + friend bool operator==(const BinaryIntOp&, const BinaryIntOp&); std::vector bincodeSerialize() const; - static BrilligOpcode bincodeDeserialize(std::vector); + static BinaryIntOp bincodeDeserialize(std::vector); }; - struct Witness { - uint32_t value; + struct MemoryAddress { + uint64_t value; - friend bool operator==(const Witness&, const Witness&); + friend bool operator==(const MemoryAddress&, const MemoryAddress&); std::vector bincodeSerialize() const; - static Witness bincodeDeserialize(std::vector); + static MemoryAddress bincodeDeserialize(std::vector); }; - struct FunctionInput { - Circuit::Witness witness; - uint32_t num_bits; + struct HeapArray { + Program::MemoryAddress pointer; + uint64_t size; - friend bool operator==(const FunctionInput&, const FunctionInput&); + friend bool operator==(const HeapArray&, const HeapArray&); std::vector bincodeSerialize() const; - static FunctionInput bincodeDeserialize(std::vector); + static HeapArray bincodeDeserialize(std::vector); }; - struct BlackBoxFuncCall { - - struct AND { - Circuit::FunctionInput lhs; - Circuit::FunctionInput rhs; - Circuit::Witness output; - - friend bool operator==(const AND&, const AND&); - std::vector bincodeSerialize() const; - static AND bincodeDeserialize(std::vector); - }; - - struct XOR { - Circuit::FunctionInput lhs; - Circuit::FunctionInput rhs; - Circuit::Witness output; - - friend bool operator==(const XOR&, const XOR&); - std::vector bincodeSerialize() const; - static XOR bincodeDeserialize(std::vector); - }; + struct HeapVector { + Program::MemoryAddress pointer; + Program::MemoryAddress size; - struct RANGE { - Circuit::FunctionInput input; + friend bool operator==(const HeapVector&, const HeapVector&); + std::vector bincodeSerialize() const; + static HeapVector bincodeDeserialize(std::vector); + }; - friend bool operator==(const RANGE&, const RANGE&); - std::vector bincodeSerialize() const; - static RANGE bincodeDeserialize(std::vector); - }; + struct BlackBoxOp { - struct SHA256 { - std::vector inputs; - std::vector outputs; + struct Sha256 { + Program::HeapVector message; + Program::HeapArray output; - friend bool operator==(const SHA256&, const SHA256&); + friend bool operator==(const Sha256&, const Sha256&); std::vector bincodeSerialize() const; - static SHA256 bincodeDeserialize(std::vector); + static Sha256 bincodeDeserialize(std::vector); }; struct Blake2s { - std::vector inputs; - std::vector outputs; + Program::HeapVector message; + Program::HeapArray output; friend bool operator==(const Blake2s&, const Blake2s&); std::vector bincodeSerialize() const; @@ -673,52 +518,38 @@ namespace Circuit { }; struct Blake3 { - std::vector inputs; - std::vector outputs; + Program::HeapVector message; + Program::HeapArray output; friend bool operator==(const Blake3&, const Blake3&); std::vector bincodeSerialize() const; static Blake3 bincodeDeserialize(std::vector); }; - struct SchnorrVerify { - Circuit::FunctionInput public_key_x; - Circuit::FunctionInput public_key_y; - std::vector signature; - std::vector message; - Circuit::Witness output; - - friend bool operator==(const SchnorrVerify&, const SchnorrVerify&); - std::vector bincodeSerialize() const; - static SchnorrVerify bincodeDeserialize(std::vector); - }; - - struct PedersenCommitment { - std::vector inputs; - uint32_t domain_separator; - std::array outputs; + struct Keccak256 { + Program::HeapVector message; + Program::HeapArray output; - friend bool operator==(const PedersenCommitment&, const PedersenCommitment&); + friend bool operator==(const Keccak256&, const Keccak256&); std::vector bincodeSerialize() const; - static PedersenCommitment bincodeDeserialize(std::vector); + static Keccak256 bincodeDeserialize(std::vector); }; - struct PedersenHash { - std::vector inputs; - uint32_t domain_separator; - Circuit::Witness output; + struct Keccakf1600 { + Program::HeapVector message; + Program::HeapArray output; - friend bool operator==(const PedersenHash&, const PedersenHash&); + friend bool operator==(const Keccakf1600&, const Keccakf1600&); std::vector bincodeSerialize() const; - static PedersenHash bincodeDeserialize(std::vector); + static Keccakf1600 bincodeDeserialize(std::vector); }; struct EcdsaSecp256k1 { - std::vector public_key_x; - std::vector public_key_y; - std::vector signature; - std::vector hashed_message; - Circuit::Witness output; + Program::HeapVector hashed_msg; + Program::HeapArray public_key_x; + Program::HeapArray public_key_y; + Program::HeapArray signature; + Program::MemoryAddress result; friend bool operator==(const EcdsaSecp256k1&, const EcdsaSecp256k1&); std::vector bincodeSerialize() const; @@ -726,82 +557,75 @@ namespace Circuit { }; struct EcdsaSecp256r1 { - std::vector public_key_x; - std::vector public_key_y; - std::vector signature; - std::vector hashed_message; - Circuit::Witness output; + Program::HeapVector hashed_msg; + Program::HeapArray public_key_x; + Program::HeapArray public_key_y; + Program::HeapArray signature; + Program::MemoryAddress result; friend bool operator==(const EcdsaSecp256r1&, const EcdsaSecp256r1&); std::vector bincodeSerialize() const; static EcdsaSecp256r1 bincodeDeserialize(std::vector); }; - struct FixedBaseScalarMul { - Circuit::FunctionInput low; - Circuit::FunctionInput high; - std::array outputs; - - friend bool operator==(const FixedBaseScalarMul&, const FixedBaseScalarMul&); - std::vector bincodeSerialize() const; - static FixedBaseScalarMul bincodeDeserialize(std::vector); - }; - - struct EmbeddedCurveAdd { - Circuit::FunctionInput input1_x; - Circuit::FunctionInput input1_y; - Circuit::FunctionInput input2_x; - Circuit::FunctionInput input2_y; - std::array outputs; + struct SchnorrVerify { + Program::MemoryAddress public_key_x; + Program::MemoryAddress public_key_y; + Program::HeapVector message; + Program::HeapVector signature; + Program::MemoryAddress result; - friend bool operator==(const EmbeddedCurveAdd&, const EmbeddedCurveAdd&); + friend bool operator==(const SchnorrVerify&, const SchnorrVerify&); std::vector bincodeSerialize() const; - static EmbeddedCurveAdd bincodeDeserialize(std::vector); + static SchnorrVerify bincodeDeserialize(std::vector); }; - struct Keccak256 { - std::vector inputs; - std::vector outputs; + struct PedersenCommitment { + Program::HeapVector inputs; + Program::MemoryAddress domain_separator; + Program::HeapArray output; - friend bool operator==(const Keccak256&, const Keccak256&); + friend bool operator==(const PedersenCommitment&, const PedersenCommitment&); std::vector bincodeSerialize() const; - static Keccak256 bincodeDeserialize(std::vector); + static PedersenCommitment bincodeDeserialize(std::vector); }; - struct Keccak256VariableLength { - std::vector inputs; - Circuit::FunctionInput var_message_size; - std::vector outputs; + struct PedersenHash { + Program::HeapVector inputs; + Program::MemoryAddress domain_separator; + Program::MemoryAddress output; - friend bool operator==(const Keccak256VariableLength&, const Keccak256VariableLength&); + friend bool operator==(const PedersenHash&, const PedersenHash&); std::vector bincodeSerialize() const; - static Keccak256VariableLength bincodeDeserialize(std::vector); + static PedersenHash bincodeDeserialize(std::vector); }; - struct Keccakf1600 { - std::vector inputs; - std::vector outputs; + struct FixedBaseScalarMul { + Program::MemoryAddress low; + Program::MemoryAddress high; + Program::HeapArray result; - friend bool operator==(const Keccakf1600&, const Keccakf1600&); + friend bool operator==(const FixedBaseScalarMul&, const FixedBaseScalarMul&); std::vector bincodeSerialize() const; - static Keccakf1600 bincodeDeserialize(std::vector); + static FixedBaseScalarMul bincodeDeserialize(std::vector); }; - struct RecursiveAggregation { - std::vector verification_key; - std::vector proof; - std::vector public_inputs; - Circuit::FunctionInput key_hash; + struct EmbeddedCurveAdd { + Program::MemoryAddress input1_x; + Program::MemoryAddress input1_y; + Program::MemoryAddress input2_x; + Program::MemoryAddress input2_y; + Program::HeapArray result; - friend bool operator==(const RecursiveAggregation&, const RecursiveAggregation&); + friend bool operator==(const EmbeddedCurveAdd&, const EmbeddedCurveAdd&); std::vector bincodeSerialize() const; - static RecursiveAggregation bincodeDeserialize(std::vector); + static EmbeddedCurveAdd bincodeDeserialize(std::vector); }; struct BigIntAdd { - uint32_t lhs; - uint32_t rhs; - uint32_t output; + Program::MemoryAddress lhs; + Program::MemoryAddress rhs; + Program::MemoryAddress output; friend bool operator==(const BigIntAdd&, const BigIntAdd&); std::vector bincodeSerialize() const; @@ -809,9 +633,9 @@ namespace Circuit { }; struct BigIntSub { - uint32_t lhs; - uint32_t rhs; - uint32_t output; + Program::MemoryAddress lhs; + Program::MemoryAddress rhs; + Program::MemoryAddress output; friend bool operator==(const BigIntSub&, const BigIntSub&); std::vector bincodeSerialize() const; @@ -819,9 +643,9 @@ namespace Circuit { }; struct BigIntMul { - uint32_t lhs; - uint32_t rhs; - uint32_t output; + Program::MemoryAddress lhs; + Program::MemoryAddress rhs; + Program::MemoryAddress output; friend bool operator==(const BigIntMul&, const BigIntMul&); std::vector bincodeSerialize() const; @@ -829,9 +653,9 @@ namespace Circuit { }; struct BigIntDiv { - uint32_t lhs; - uint32_t rhs; - uint32_t output; + Program::MemoryAddress lhs; + Program::MemoryAddress rhs; + Program::MemoryAddress output; friend bool operator==(const BigIntDiv&, const BigIntDiv&); std::vector bincodeSerialize() const; @@ -839,9 +663,9 @@ namespace Circuit { }; struct BigIntFromLeBytes { - std::vector inputs; - std::vector modulus; - uint32_t output; + Program::HeapVector inputs; + Program::HeapVector modulus; + Program::MemoryAddress output; friend bool operator==(const BigIntFromLeBytes&, const BigIntFromLeBytes&); std::vector bincodeSerialize() const; @@ -849,8 +673,8 @@ namespace Circuit { }; struct BigIntToLeBytes { - uint32_t input; - std::vector outputs; + Program::MemoryAddress input; + Program::HeapVector output; friend bool operator==(const BigIntToLeBytes&, const BigIntToLeBytes&); std::vector bincodeSerialize() const; @@ -858,87 +682,280 @@ namespace Circuit { }; struct Poseidon2Permutation { - std::vector inputs; - std::vector outputs; - uint32_t len; + Program::HeapVector message; + Program::HeapArray output; + Program::MemoryAddress len; friend bool operator==(const Poseidon2Permutation&, const Poseidon2Permutation&); std::vector bincodeSerialize() const; static Poseidon2Permutation bincodeDeserialize(std::vector); }; - struct Sha256Compression { - std::vector inputs; - std::vector hash_values; - std::vector outputs; + struct Sha256Compression { + Program::HeapVector input; + Program::HeapVector hash_values; + Program::HeapArray output; + + friend bool operator==(const Sha256Compression&, const Sha256Compression&); + std::vector bincodeSerialize() const; + static Sha256Compression bincodeDeserialize(std::vector); + }; + + std::variant value; + + friend bool operator==(const BlackBoxOp&, const BlackBoxOp&); + std::vector bincodeSerialize() const; + static BlackBoxOp bincodeDeserialize(std::vector); + }; + + struct HeapValueType; + + struct HeapValueType { + + struct Simple { + uint32_t value; + + friend bool operator==(const Simple&, const Simple&); + std::vector bincodeSerialize() const; + static Simple bincodeDeserialize(std::vector); + }; + + struct Array { + std::vector value_types; + uint64_t size; + + friend bool operator==(const Array&, const Array&); + std::vector bincodeSerialize() const; + static Array bincodeDeserialize(std::vector); + }; + + struct Vector { + std::vector value_types; + + friend bool operator==(const Vector&, const Vector&); + std::vector bincodeSerialize() const; + static Vector bincodeDeserialize(std::vector); + }; + + std::variant value; + + friend bool operator==(const HeapValueType&, const HeapValueType&); + std::vector bincodeSerialize() const; + static HeapValueType bincodeDeserialize(std::vector); + }; + + struct ValueOrArray { + + struct MemoryAddress { + Program::MemoryAddress value; + + friend bool operator==(const MemoryAddress&, const MemoryAddress&); + std::vector bincodeSerialize() const; + static MemoryAddress bincodeDeserialize(std::vector); + }; + + struct HeapArray { + Program::HeapArray value; + + friend bool operator==(const HeapArray&, const HeapArray&); + std::vector bincodeSerialize() const; + static HeapArray bincodeDeserialize(std::vector); + }; + + struct HeapVector { + Program::HeapVector value; + + friend bool operator==(const HeapVector&, const HeapVector&); + std::vector bincodeSerialize() const; + static HeapVector bincodeDeserialize(std::vector); + }; + + std::variant value; + + friend bool operator==(const ValueOrArray&, const ValueOrArray&); + std::vector bincodeSerialize() const; + static ValueOrArray bincodeDeserialize(std::vector); + }; + + struct BrilligOpcode { + + struct BinaryFieldOp { + Program::MemoryAddress destination; + Program::BinaryFieldOp op; + Program::MemoryAddress lhs; + Program::MemoryAddress rhs; + + friend bool operator==(const BinaryFieldOp&, const BinaryFieldOp&); + std::vector bincodeSerialize() const; + static BinaryFieldOp bincodeDeserialize(std::vector); + }; + + struct BinaryIntOp { + Program::MemoryAddress destination; + Program::BinaryIntOp op; + uint32_t bit_size; + Program::MemoryAddress lhs; + Program::MemoryAddress rhs; + + friend bool operator==(const BinaryIntOp&, const BinaryIntOp&); + std::vector bincodeSerialize() const; + static BinaryIntOp bincodeDeserialize(std::vector); + }; + + struct Cast { + Program::MemoryAddress destination; + Program::MemoryAddress source; + uint32_t bit_size; + + friend bool operator==(const Cast&, const Cast&); + std::vector bincodeSerialize() const; + static Cast bincodeDeserialize(std::vector); + }; + + struct JumpIfNot { + Program::MemoryAddress condition; + uint64_t location; + + friend bool operator==(const JumpIfNot&, const JumpIfNot&); + std::vector bincodeSerialize() const; + static JumpIfNot bincodeDeserialize(std::vector); + }; + + struct JumpIf { + Program::MemoryAddress condition; + uint64_t location; + + friend bool operator==(const JumpIf&, const JumpIf&); + std::vector bincodeSerialize() const; + static JumpIf bincodeDeserialize(std::vector); + }; + + struct Jump { + uint64_t location; + + friend bool operator==(const Jump&, const Jump&); + std::vector bincodeSerialize() const; + static Jump bincodeDeserialize(std::vector); + }; + + struct CalldataCopy { + Program::MemoryAddress destination_address; + uint64_t size; + uint64_t offset; + + friend bool operator==(const CalldataCopy&, const CalldataCopy&); + std::vector bincodeSerialize() const; + static CalldataCopy bincodeDeserialize(std::vector); + }; + + struct Call { + uint64_t location; + + friend bool operator==(const Call&, const Call&); + std::vector bincodeSerialize() const; + static Call bincodeDeserialize(std::vector); + }; + + struct Const { + Program::MemoryAddress destination; + uint32_t bit_size; + std::string value; + + friend bool operator==(const Const&, const Const&); + std::vector bincodeSerialize() const; + static Const bincodeDeserialize(std::vector); + }; + + struct Return { + friend bool operator==(const Return&, const Return&); + std::vector bincodeSerialize() const; + static Return bincodeDeserialize(std::vector); + }; + + struct ForeignCall { + std::string function; + std::vector destinations; + std::vector destination_value_types; + std::vector inputs; + std::vector input_value_types; + + friend bool operator==(const ForeignCall&, const ForeignCall&); + std::vector bincodeSerialize() const; + static ForeignCall bincodeDeserialize(std::vector); + }; + + struct Mov { + Program::MemoryAddress destination; + Program::MemoryAddress source; - friend bool operator==(const Sha256Compression&, const Sha256Compression&); + friend bool operator==(const Mov&, const Mov&); std::vector bincodeSerialize() const; - static Sha256Compression bincodeDeserialize(std::vector); + static Mov bincodeDeserialize(std::vector); }; - std::variant value; - - friend bool operator==(const BlackBoxFuncCall&, const BlackBoxFuncCall&); - std::vector bincodeSerialize() const; - static BlackBoxFuncCall bincodeDeserialize(std::vector); - }; + struct ConditionalMov { + Program::MemoryAddress destination; + Program::MemoryAddress source_a; + Program::MemoryAddress source_b; + Program::MemoryAddress condition; - struct BlockId { - uint32_t value; + friend bool operator==(const ConditionalMov&, const ConditionalMov&); + std::vector bincodeSerialize() const; + static ConditionalMov bincodeDeserialize(std::vector); + }; - friend bool operator==(const BlockId&, const BlockId&); - std::vector bincodeSerialize() const; - static BlockId bincodeDeserialize(std::vector); - }; + struct Load { + Program::MemoryAddress destination; + Program::MemoryAddress source_pointer; - struct Expression { - std::vector> mul_terms; - std::vector> linear_combinations; - std::string q_c; + friend bool operator==(const Load&, const Load&); + std::vector bincodeSerialize() const; + static Load bincodeDeserialize(std::vector); + }; - friend bool operator==(const Expression&, const Expression&); - std::vector bincodeSerialize() const; - static Expression bincodeDeserialize(std::vector); - }; + struct Store { + Program::MemoryAddress destination_pointer; + Program::MemoryAddress source; - struct BrilligInputs { + friend bool operator==(const Store&, const Store&); + std::vector bincodeSerialize() const; + static Store bincodeDeserialize(std::vector); + }; - struct Single { - Circuit::Expression value; + struct BlackBox { + Program::BlackBoxOp value; - friend bool operator==(const Single&, const Single&); + friend bool operator==(const BlackBox&, const BlackBox&); std::vector bincodeSerialize() const; - static Single bincodeDeserialize(std::vector); + static BlackBox bincodeDeserialize(std::vector); }; - struct Array { - std::vector value; - - friend bool operator==(const Array&, const Array&); + struct Trap { + friend bool operator==(const Trap&, const Trap&); std::vector bincodeSerialize() const; - static Array bincodeDeserialize(std::vector); + static Trap bincodeDeserialize(std::vector); }; - struct MemoryArray { - Circuit::BlockId value; + struct Stop { + uint64_t return_data_offset; + uint64_t return_data_size; - friend bool operator==(const MemoryArray&, const MemoryArray&); + friend bool operator==(const Stop&, const Stop&); std::vector bincodeSerialize() const; - static MemoryArray bincodeDeserialize(std::vector); + static Stop bincodeDeserialize(std::vector); }; - std::variant value; + std::variant value; - friend bool operator==(const BrilligInputs&, const BrilligInputs&); + friend bool operator==(const BrilligOpcode&, const BrilligOpcode&); std::vector bincodeSerialize() const; - static BrilligInputs bincodeDeserialize(std::vector); + static BrilligOpcode bincodeDeserialize(std::vector); }; struct BrilligOutputs { struct Simple { - Circuit::Witness value; + Program::Witness value; friend bool operator==(const Simple&, const Simple&); std::vector bincodeSerialize() const; @@ -946,7 +963,7 @@ namespace Circuit { }; struct Array { - std::vector value; + std::vector value; friend bool operator==(const Array&, const Array&); std::vector bincodeSerialize() const; @@ -961,10 +978,10 @@ namespace Circuit { }; struct Brillig { - std::vector inputs; - std::vector outputs; - std::vector bytecode; - std::optional predicate; + std::vector inputs; + std::vector outputs; + std::vector bytecode; + std::optional predicate; friend bool operator==(const Brillig&, const Brillig&); std::vector bincodeSerialize() const; @@ -974,8 +991,8 @@ namespace Circuit { struct Directive { struct ToLeRadix { - Circuit::Expression a; - std::vector b; + Program::Expression a; + std::vector b; uint32_t radix; friend bool operator==(const ToLeRadix&, const ToLeRadix&); @@ -991,9 +1008,9 @@ namespace Circuit { }; struct MemOp { - Circuit::Expression operation; - Circuit::Expression index; - Circuit::Expression value; + Program::Expression operation; + Program::Expression index; + Program::Expression value; friend bool operator==(const MemOp&, const MemOp&); std::vector bincodeSerialize() const; @@ -1003,7 +1020,7 @@ namespace Circuit { struct Opcode { struct AssertZero { - Circuit::Expression value; + Program::Expression value; friend bool operator==(const AssertZero&, const AssertZero&); std::vector bincodeSerialize() const; @@ -1011,7 +1028,7 @@ namespace Circuit { }; struct BlackBoxFuncCall { - Circuit::BlackBoxFuncCall value; + Program::BlackBoxFuncCall value; friend bool operator==(const BlackBoxFuncCall&, const BlackBoxFuncCall&); std::vector bincodeSerialize() const; @@ -1019,7 +1036,7 @@ namespace Circuit { }; struct Directive { - Circuit::Directive value; + Program::Directive value; friend bool operator==(const Directive&, const Directive&); std::vector bincodeSerialize() const; @@ -1027,7 +1044,7 @@ namespace Circuit { }; struct Brillig { - Circuit::Brillig value; + Program::Brillig value; friend bool operator==(const Brillig&, const Brillig&); std::vector bincodeSerialize() const; @@ -1035,9 +1052,9 @@ namespace Circuit { }; struct MemoryOp { - Circuit::BlockId block_id; - Circuit::MemOp op; - std::optional predicate; + Program::BlockId block_id; + Program::MemOp op; + std::optional predicate; friend bool operator==(const MemoryOp&, const MemoryOp&); std::vector bincodeSerialize() const; @@ -1045,15 +1062,25 @@ namespace Circuit { }; struct MemoryInit { - Circuit::BlockId block_id; - std::vector init; + Program::BlockId block_id; + std::vector init; friend bool operator==(const MemoryInit&, const MemoryInit&); std::vector bincodeSerialize() const; static MemoryInit bincodeDeserialize(std::vector); }; - std::variant value; + struct Call { + uint32_t id; + std::vector inputs; + std::vector outputs; + + friend bool operator==(const Call&, const Call&); + std::vector bincodeSerialize() const; + static Call bincodeDeserialize(std::vector); + }; + + std::variant value; friend bool operator==(const Opcode&, const Opcode&); std::vector bincodeSerialize() const; @@ -1110,7 +1137,7 @@ namespace Circuit { }; struct PublicInputs { - std::vector value; + std::vector value; friend bool operator==(const PublicInputs&, const PublicInputs&); std::vector bincodeSerialize() const; @@ -1119,12 +1146,12 @@ namespace Circuit { struct Circuit { uint32_t current_witness_index; - std::vector opcodes; - Circuit::ExpressionWidth expression_width; - std::vector private_parameters; - Circuit::PublicInputs public_parameters; - Circuit::PublicInputs return_values; - std::vector> assert_messages; + std::vector opcodes; + Program::ExpressionWidth expression_width; + std::vector private_parameters; + Program::PublicInputs public_parameters; + Program::PublicInputs return_values; + std::vector> assert_messages; bool recursive; friend bool operator==(const Circuit&, const Circuit&); @@ -1132,10 +1159,18 @@ namespace Circuit { static Circuit bincodeDeserialize(std::vector); }; -} // end of namespace Circuit + struct Program { + std::vector functions; + + friend bool operator==(const Program&, const Program&); + std::vector bincodeSerialize() const; + static Program bincodeDeserialize(std::vector); + }; + +} // end of namespace Program -namespace Circuit { +namespace Program { inline bool operator==(const BinaryFieldOp &lhs, const BinaryFieldOp &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -1157,11 +1192,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryFieldOp &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryFieldOp &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -1169,15 +1204,15 @@ void serde::Serializable::serialize(const Circuit::Binar template <> template -Circuit::BinaryFieldOp serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::BinaryFieldOp serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::BinaryFieldOp obj; + Program::BinaryFieldOp obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryFieldOp::Add &lhs, const BinaryFieldOp::Add &rhs) { return true; @@ -1198,21 +1233,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryFieldOp::Add &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryFieldOp::Add &obj, Serializer &serializer) { } template <> template -Circuit::BinaryFieldOp::Add serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryFieldOp::Add obj; +Program::BinaryFieldOp::Add serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryFieldOp::Add obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryFieldOp::Sub &lhs, const BinaryFieldOp::Sub &rhs) { return true; @@ -1233,21 +1268,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryFieldOp::Sub &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryFieldOp::Sub &obj, Serializer &serializer) { } template <> template -Circuit::BinaryFieldOp::Sub serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryFieldOp::Sub obj; +Program::BinaryFieldOp::Sub serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryFieldOp::Sub obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryFieldOp::Mul &lhs, const BinaryFieldOp::Mul &rhs) { return true; @@ -1268,21 +1303,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryFieldOp::Mul &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryFieldOp::Mul &obj, Serializer &serializer) { } template <> template -Circuit::BinaryFieldOp::Mul serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryFieldOp::Mul obj; +Program::BinaryFieldOp::Mul serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryFieldOp::Mul obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryFieldOp::Div &lhs, const BinaryFieldOp::Div &rhs) { return true; @@ -1303,21 +1338,56 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program + +template <> +template +void serde::Serializable::serialize(const Program::BinaryFieldOp::Div &obj, Serializer &serializer) { +} + +template <> +template +Program::BinaryFieldOp::Div serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryFieldOp::Div obj; + return obj; +} + +namespace Program { + + inline bool operator==(const BinaryFieldOp::IntegerDiv &lhs, const BinaryFieldOp::IntegerDiv &rhs) { + return true; + } + + inline std::vector BinaryFieldOp::IntegerDiv::bincodeSerialize() const { + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); + } + + inline BinaryFieldOp::IntegerDiv BinaryFieldOp::IntegerDiv::bincodeDeserialize(std::vector input) { + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw serde::deserialization_error("Some input bytes were not read"); + } + return value; + } + +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryFieldOp::Div &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryFieldOp::IntegerDiv &obj, Serializer &serializer) { } template <> template -Circuit::BinaryFieldOp::Div serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryFieldOp::Div obj; +Program::BinaryFieldOp::IntegerDiv serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryFieldOp::IntegerDiv obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryFieldOp::Equals &lhs, const BinaryFieldOp::Equals &rhs) { return true; @@ -1338,21 +1408,91 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program + +template <> +template +void serde::Serializable::serialize(const Program::BinaryFieldOp::Equals &obj, Serializer &serializer) { +} + +template <> +template +Program::BinaryFieldOp::Equals serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryFieldOp::Equals obj; + return obj; +} + +namespace Program { + + inline bool operator==(const BinaryFieldOp::LessThan &lhs, const BinaryFieldOp::LessThan &rhs) { + return true; + } + + inline std::vector BinaryFieldOp::LessThan::bincodeSerialize() const { + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); + } + + inline BinaryFieldOp::LessThan BinaryFieldOp::LessThan::bincodeDeserialize(std::vector input) { + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw serde::deserialization_error("Some input bytes were not read"); + } + return value; + } + +} // end of namespace Program + +template <> +template +void serde::Serializable::serialize(const Program::BinaryFieldOp::LessThan &obj, Serializer &serializer) { +} + +template <> +template +Program::BinaryFieldOp::LessThan serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryFieldOp::LessThan obj; + return obj; +} + +namespace Program { + + inline bool operator==(const BinaryFieldOp::LessThanEquals &lhs, const BinaryFieldOp::LessThanEquals &rhs) { + return true; + } + + inline std::vector BinaryFieldOp::LessThanEquals::bincodeSerialize() const { + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); + } + + inline BinaryFieldOp::LessThanEquals BinaryFieldOp::LessThanEquals::bincodeDeserialize(std::vector input) { + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw serde::deserialization_error("Some input bytes were not read"); + } + return value; + } + +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryFieldOp::Equals &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryFieldOp::LessThanEquals &obj, Serializer &serializer) { } template <> template -Circuit::BinaryFieldOp::Equals serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryFieldOp::Equals obj; +Program::BinaryFieldOp::LessThanEquals serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryFieldOp::LessThanEquals obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryIntOp &lhs, const BinaryIntOp &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -1374,11 +1514,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryIntOp &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryIntOp &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -1386,15 +1526,15 @@ void serde::Serializable::serialize(const Circuit::BinaryI template <> template -Circuit::BinaryIntOp serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::BinaryIntOp serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::BinaryIntOp obj; + Program::BinaryIntOp obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryIntOp::Add &lhs, const BinaryIntOp::Add &rhs) { return true; @@ -1415,21 +1555,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryIntOp::Add &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryIntOp::Add &obj, Serializer &serializer) { } template <> template -Circuit::BinaryIntOp::Add serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryIntOp::Add obj; +Program::BinaryIntOp::Add serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryIntOp::Add obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryIntOp::Sub &lhs, const BinaryIntOp::Sub &rhs) { return true; @@ -1450,21 +1590,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryIntOp::Sub &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryIntOp::Sub &obj, Serializer &serializer) { } template <> template -Circuit::BinaryIntOp::Sub serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryIntOp::Sub obj; +Program::BinaryIntOp::Sub serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryIntOp::Sub obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryIntOp::Mul &lhs, const BinaryIntOp::Mul &rhs) { return true; @@ -1485,91 +1625,56 @@ namespace Circuit { return value; } -} // end of namespace Circuit - -template <> -template -void serde::Serializable::serialize(const Circuit::BinaryIntOp::Mul &obj, Serializer &serializer) { -} - -template <> -template -Circuit::BinaryIntOp::Mul serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryIntOp::Mul obj; - return obj; -} - -namespace Circuit { - - inline bool operator==(const BinaryIntOp::SignedDiv &lhs, const BinaryIntOp::SignedDiv &rhs) { - return true; - } - - inline std::vector BinaryIntOp::SignedDiv::bincodeSerialize() const { - auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); - return std::move(serializer).bytes(); - } - - inline BinaryIntOp::SignedDiv BinaryIntOp::SignedDiv::bincodeDeserialize(std::vector input) { - auto deserializer = serde::BincodeDeserializer(input); - auto value = serde::Deserializable::deserialize(deserializer); - if (deserializer.get_buffer_offset() < input.size()) { - throw serde::deserialization_error("Some input bytes were not read"); - } - return value; - } - -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryIntOp::SignedDiv &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryIntOp::Mul &obj, Serializer &serializer) { } template <> template -Circuit::BinaryIntOp::SignedDiv serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryIntOp::SignedDiv obj; +Program::BinaryIntOp::Mul serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryIntOp::Mul obj; return obj; } -namespace Circuit { +namespace Program { - inline bool operator==(const BinaryIntOp::UnsignedDiv &lhs, const BinaryIntOp::UnsignedDiv &rhs) { + inline bool operator==(const BinaryIntOp::Div &lhs, const BinaryIntOp::Div &rhs) { return true; } - inline std::vector BinaryIntOp::UnsignedDiv::bincodeSerialize() const { + inline std::vector BinaryIntOp::Div::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } - inline BinaryIntOp::UnsignedDiv BinaryIntOp::UnsignedDiv::bincodeDeserialize(std::vector input) { + inline BinaryIntOp::Div BinaryIntOp::Div::bincodeDeserialize(std::vector input) { auto deserializer = serde::BincodeDeserializer(input); - auto value = serde::Deserializable::deserialize(deserializer); + auto value = serde::Deserializable::deserialize(deserializer); if (deserializer.get_buffer_offset() < input.size()) { throw serde::deserialization_error("Some input bytes were not read"); } return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryIntOp::UnsignedDiv &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryIntOp::Div &obj, Serializer &serializer) { } template <> template -Circuit::BinaryIntOp::UnsignedDiv serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryIntOp::UnsignedDiv obj; +Program::BinaryIntOp::Div serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryIntOp::Div obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryIntOp::Equals &lhs, const BinaryIntOp::Equals &rhs) { return true; @@ -1590,21 +1695,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryIntOp::Equals &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryIntOp::Equals &obj, Serializer &serializer) { } template <> template -Circuit::BinaryIntOp::Equals serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryIntOp::Equals obj; +Program::BinaryIntOp::Equals serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryIntOp::Equals obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryIntOp::LessThan &lhs, const BinaryIntOp::LessThan &rhs) { return true; @@ -1625,21 +1730,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryIntOp::LessThan &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryIntOp::LessThan &obj, Serializer &serializer) { } template <> template -Circuit::BinaryIntOp::LessThan serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryIntOp::LessThan obj; +Program::BinaryIntOp::LessThan serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryIntOp::LessThan obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryIntOp::LessThanEquals &lhs, const BinaryIntOp::LessThanEquals &rhs) { return true; @@ -1660,21 +1765,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryIntOp::LessThanEquals &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryIntOp::LessThanEquals &obj, Serializer &serializer) { } template <> template -Circuit::BinaryIntOp::LessThanEquals serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryIntOp::LessThanEquals obj; +Program::BinaryIntOp::LessThanEquals serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryIntOp::LessThanEquals obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryIntOp::And &lhs, const BinaryIntOp::And &rhs) { return true; @@ -1695,21 +1800,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryIntOp::And &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryIntOp::And &obj, Serializer &serializer) { } template <> template -Circuit::BinaryIntOp::And serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryIntOp::And obj; +Program::BinaryIntOp::And serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryIntOp::And obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryIntOp::Or &lhs, const BinaryIntOp::Or &rhs) { return true; @@ -1730,21 +1835,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryIntOp::Or &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryIntOp::Or &obj, Serializer &serializer) { } template <> template -Circuit::BinaryIntOp::Or serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryIntOp::Or obj; +Program::BinaryIntOp::Or serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryIntOp::Or obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryIntOp::Xor &lhs, const BinaryIntOp::Xor &rhs) { return true; @@ -1765,21 +1870,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryIntOp::Xor &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryIntOp::Xor &obj, Serializer &serializer) { } template <> template -Circuit::BinaryIntOp::Xor serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryIntOp::Xor obj; +Program::BinaryIntOp::Xor serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryIntOp::Xor obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryIntOp::Shl &lhs, const BinaryIntOp::Shl &rhs) { return true; @@ -1800,21 +1905,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryIntOp::Shl &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryIntOp::Shl &obj, Serializer &serializer) { } template <> template -Circuit::BinaryIntOp::Shl serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryIntOp::Shl obj; +Program::BinaryIntOp::Shl serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryIntOp::Shl obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BinaryIntOp::Shr &lhs, const BinaryIntOp::Shr &rhs) { return true; @@ -1835,21 +1940,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BinaryIntOp::Shr &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BinaryIntOp::Shr &obj, Serializer &serializer) { } template <> template -Circuit::BinaryIntOp::Shr serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BinaryIntOp::Shr obj; +Program::BinaryIntOp::Shr serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BinaryIntOp::Shr obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall &lhs, const BlackBoxFuncCall &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -1871,11 +1976,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -1883,15 +1988,15 @@ void serde::Serializable::serialize(const Circuit::Bl template <> template -Circuit::BlackBoxFuncCall serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::BlackBoxFuncCall serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::BlackBoxFuncCall obj; + Program::BlackBoxFuncCall obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::AND &lhs, const BlackBoxFuncCall::AND &rhs) { if (!(lhs.lhs == rhs.lhs)) { return false; } @@ -1915,11 +2020,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::AND &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::AND &obj, Serializer &serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -1927,15 +2032,15 @@ void serde::Serializable::serialize(const Circui template <> template -Circuit::BlackBoxFuncCall::AND serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::AND obj; +Program::BlackBoxFuncCall::AND serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::AND obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::XOR &lhs, const BlackBoxFuncCall::XOR &rhs) { if (!(lhs.lhs == rhs.lhs)) { return false; } @@ -1959,11 +2064,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::XOR &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::XOR &obj, Serializer &serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -1971,15 +2076,15 @@ void serde::Serializable::serialize(const Circui template <> template -Circuit::BlackBoxFuncCall::XOR serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::XOR obj; +Program::BlackBoxFuncCall::XOR serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::XOR obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::RANGE &lhs, const BlackBoxFuncCall::RANGE &rhs) { if (!(lhs.input == rhs.input)) { return false; } @@ -2001,23 +2106,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::RANGE &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::RANGE &obj, Serializer &serializer) { serde::Serializable::serialize(obj.input, serializer); } template <> template -Circuit::BlackBoxFuncCall::RANGE serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::RANGE obj; +Program::BlackBoxFuncCall::RANGE serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::RANGE obj; obj.input = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::SHA256 &lhs, const BlackBoxFuncCall::SHA256 &rhs) { if (!(lhs.inputs == rhs.inputs)) { return false; } @@ -2040,25 +2145,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::SHA256 &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::SHA256 &obj, Serializer &serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.outputs, serializer); } template <> template -Circuit::BlackBoxFuncCall::SHA256 serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::SHA256 obj; +Program::BlackBoxFuncCall::SHA256 serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::SHA256 obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::Blake2s &lhs, const BlackBoxFuncCall::Blake2s &rhs) { if (!(lhs.inputs == rhs.inputs)) { return false; } @@ -2081,25 +2186,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::Blake2s &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::Blake2s &obj, Serializer &serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.outputs, serializer); } template <> template -Circuit::BlackBoxFuncCall::Blake2s serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::Blake2s obj; +Program::BlackBoxFuncCall::Blake2s serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::Blake2s obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::Blake3 &lhs, const BlackBoxFuncCall::Blake3 &rhs) { if (!(lhs.inputs == rhs.inputs)) { return false; } @@ -2122,25 +2227,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::Blake3 &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::Blake3 &obj, Serializer &serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.outputs, serializer); } template <> template -Circuit::BlackBoxFuncCall::Blake3 serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::Blake3 obj; +Program::BlackBoxFuncCall::Blake3 serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::Blake3 obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::SchnorrVerify &lhs, const BlackBoxFuncCall::SchnorrVerify &rhs) { if (!(lhs.public_key_x == rhs.public_key_x)) { return false; } @@ -2166,11 +2271,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::SchnorrVerify &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::SchnorrVerify &obj, Serializer &serializer) { serde::Serializable::serialize(obj.public_key_x, serializer); serde::Serializable::serialize(obj.public_key_y, serializer); serde::Serializable::serialize(obj.signature, serializer); @@ -2180,8 +2285,8 @@ void serde::Serializable::serialize(co template <> template -Circuit::BlackBoxFuncCall::SchnorrVerify serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::SchnorrVerify obj; +Program::BlackBoxFuncCall::SchnorrVerify serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::SchnorrVerify obj; obj.public_key_x = serde::Deserializable::deserialize(deserializer); obj.public_key_y = serde::Deserializable::deserialize(deserializer); obj.signature = serde::Deserializable::deserialize(deserializer); @@ -2190,7 +2295,7 @@ Circuit::BlackBoxFuncCall::SchnorrVerify serde::Deserializable template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::PedersenCommitment &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::PedersenCommitment &obj, Serializer &serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.domain_separator, serializer); serde::Serializable::serialize(obj.outputs, serializer); @@ -2226,15 +2331,15 @@ void serde::Serializable::seriali template <> template -Circuit::BlackBoxFuncCall::PedersenCommitment serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::PedersenCommitment obj; +Program::BlackBoxFuncCall::PedersenCommitment serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::PedersenCommitment obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.domain_separator = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::PedersenHash &lhs, const BlackBoxFuncCall::PedersenHash &rhs) { if (!(lhs.inputs == rhs.inputs)) { return false; } @@ -2258,11 +2363,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::PedersenHash &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::PedersenHash &obj, Serializer &serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.domain_separator, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -2270,15 +2375,15 @@ void serde::Serializable::serialize(con template <> template -Circuit::BlackBoxFuncCall::PedersenHash serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::PedersenHash obj; +Program::BlackBoxFuncCall::PedersenHash serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::PedersenHash obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.domain_separator = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::EcdsaSecp256k1 &lhs, const BlackBoxFuncCall::EcdsaSecp256k1 &rhs) { if (!(lhs.public_key_x == rhs.public_key_x)) { return false; } @@ -2304,11 +2409,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::EcdsaSecp256k1 &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::EcdsaSecp256k1 &obj, Serializer &serializer) { serde::Serializable::serialize(obj.public_key_x, serializer); serde::Serializable::serialize(obj.public_key_y, serializer); serde::Serializable::serialize(obj.signature, serializer); @@ -2318,8 +2423,8 @@ void serde::Serializable::serialize(c template <> template -Circuit::BlackBoxFuncCall::EcdsaSecp256k1 serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::EcdsaSecp256k1 obj; +Program::BlackBoxFuncCall::EcdsaSecp256k1 serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::EcdsaSecp256k1 obj; obj.public_key_x = serde::Deserializable::deserialize(deserializer); obj.public_key_y = serde::Deserializable::deserialize(deserializer); obj.signature = serde::Deserializable::deserialize(deserializer); @@ -2328,7 +2433,7 @@ Circuit::BlackBoxFuncCall::EcdsaSecp256k1 serde::Deserializable template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::EcdsaSecp256r1 &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::EcdsaSecp256r1 &obj, Serializer &serializer) { serde::Serializable::serialize(obj.public_key_x, serializer); serde::Serializable::serialize(obj.public_key_y, serializer); serde::Serializable::serialize(obj.signature, serializer); @@ -2368,8 +2473,8 @@ void serde::Serializable::serialize(c template <> template -Circuit::BlackBoxFuncCall::EcdsaSecp256r1 serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::EcdsaSecp256r1 obj; +Program::BlackBoxFuncCall::EcdsaSecp256r1 serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::EcdsaSecp256r1 obj; obj.public_key_x = serde::Deserializable::deserialize(deserializer); obj.public_key_y = serde::Deserializable::deserialize(deserializer); obj.signature = serde::Deserializable::deserialize(deserializer); @@ -2378,7 +2483,7 @@ Circuit::BlackBoxFuncCall::EcdsaSecp256r1 serde::Deserializable template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::FixedBaseScalarMul &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::FixedBaseScalarMul &obj, Serializer &serializer) { serde::Serializable::serialize(obj.low, serializer); serde::Serializable::serialize(obj.high, serializer); serde::Serializable::serialize(obj.outputs, serializer); @@ -2414,15 +2519,15 @@ void serde::Serializable::seriali template <> template -Circuit::BlackBoxFuncCall::FixedBaseScalarMul serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::FixedBaseScalarMul obj; +Program::BlackBoxFuncCall::FixedBaseScalarMul serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::FixedBaseScalarMul obj; obj.low = serde::Deserializable::deserialize(deserializer); obj.high = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::EmbeddedCurveAdd &lhs, const BlackBoxFuncCall::EmbeddedCurveAdd &rhs) { if (!(lhs.input1_x == rhs.input1_x)) { return false; } @@ -2448,11 +2553,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::EmbeddedCurveAdd &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::EmbeddedCurveAdd &obj, Serializer &serializer) { serde::Serializable::serialize(obj.input1_x, serializer); serde::Serializable::serialize(obj.input1_y, serializer); serde::Serializable::serialize(obj.input2_x, serializer); @@ -2462,8 +2567,8 @@ void serde::Serializable::serialize template <> template -Circuit::BlackBoxFuncCall::EmbeddedCurveAdd serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::EmbeddedCurveAdd obj; +Program::BlackBoxFuncCall::EmbeddedCurveAdd serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::EmbeddedCurveAdd obj; obj.input1_x = serde::Deserializable::deserialize(deserializer); obj.input1_y = serde::Deserializable::deserialize(deserializer); obj.input2_x = serde::Deserializable::deserialize(deserializer); @@ -2472,7 +2577,7 @@ Circuit::BlackBoxFuncCall::EmbeddedCurveAdd serde::Deserializable template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::Keccak256 &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::Keccak256 &obj, Serializer &serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.outputs, serializer); } template <> template -Circuit::BlackBoxFuncCall::Keccak256 serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::Keccak256 obj; +Program::BlackBoxFuncCall::Keccak256 serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::Keccak256 obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::Keccak256VariableLength &lhs, const BlackBoxFuncCall::Keccak256VariableLength &rhs) { if (!(lhs.inputs == rhs.inputs)) { return false; } @@ -2537,11 +2642,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::Keccak256VariableLength &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::Keccak256VariableLength &obj, Serializer &serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.var_message_size, serializer); serde::Serializable::serialize(obj.outputs, serializer); @@ -2549,15 +2654,15 @@ void serde::Serializable::se template <> template -Circuit::BlackBoxFuncCall::Keccak256VariableLength serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::Keccak256VariableLength obj; +Program::BlackBoxFuncCall::Keccak256VariableLength serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::Keccak256VariableLength obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.var_message_size = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::Keccakf1600 &lhs, const BlackBoxFuncCall::Keccakf1600 &rhs) { if (!(lhs.inputs == rhs.inputs)) { return false; } @@ -2580,25 +2685,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::Keccakf1600 &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::Keccakf1600 &obj, Serializer &serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.outputs, serializer); } template <> template -Circuit::BlackBoxFuncCall::Keccakf1600 serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::Keccakf1600 obj; +Program::BlackBoxFuncCall::Keccakf1600 serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::Keccakf1600 obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::RecursiveAggregation &lhs, const BlackBoxFuncCall::RecursiveAggregation &rhs) { if (!(lhs.verification_key == rhs.verification_key)) { return false; } @@ -2623,11 +2728,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::RecursiveAggregation &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::RecursiveAggregation &obj, Serializer &serializer) { serde::Serializable::serialize(obj.verification_key, serializer); serde::Serializable::serialize(obj.proof, serializer); serde::Serializable::serialize(obj.public_inputs, serializer); @@ -2636,8 +2741,8 @@ void serde::Serializable::seria template <> template -Circuit::BlackBoxFuncCall::RecursiveAggregation serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::RecursiveAggregation obj; +Program::BlackBoxFuncCall::RecursiveAggregation serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::RecursiveAggregation obj; obj.verification_key = serde::Deserializable::deserialize(deserializer); obj.proof = serde::Deserializable::deserialize(deserializer); obj.public_inputs = serde::Deserializable::deserialize(deserializer); @@ -2645,7 +2750,7 @@ Circuit::BlackBoxFuncCall::RecursiveAggregation serde::Deserializable template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::BigIntAdd &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::BigIntAdd &obj, Serializer &serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -2681,15 +2786,15 @@ void serde::Serializable::serialize(const template <> template -Circuit::BlackBoxFuncCall::BigIntAdd serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::BigIntAdd obj; +Program::BlackBoxFuncCall::BigIntAdd serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::BigIntAdd obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::BigIntSub &lhs, const BlackBoxFuncCall::BigIntSub &rhs) { if (!(lhs.lhs == rhs.lhs)) { return false; } @@ -2713,11 +2818,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::BigIntSub &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::BigIntSub &obj, Serializer &serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -2725,15 +2830,15 @@ void serde::Serializable::serialize(const template <> template -Circuit::BlackBoxFuncCall::BigIntSub serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::BigIntSub obj; +Program::BlackBoxFuncCall::BigIntSub serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::BigIntSub obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::BigIntMul &lhs, const BlackBoxFuncCall::BigIntMul &rhs) { if (!(lhs.lhs == rhs.lhs)) { return false; } @@ -2757,11 +2862,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::BigIntMul &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::BigIntMul &obj, Serializer &serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -2769,15 +2874,15 @@ void serde::Serializable::serialize(const template <> template -Circuit::BlackBoxFuncCall::BigIntMul serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::BigIntMul obj; +Program::BlackBoxFuncCall::BigIntMul serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::BigIntMul obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::BigIntDiv &lhs, const BlackBoxFuncCall::BigIntDiv &rhs) { if (!(lhs.lhs == rhs.lhs)) { return false; } @@ -2801,11 +2906,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::BigIntDiv &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::BigIntDiv &obj, Serializer &serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -2813,15 +2918,15 @@ void serde::Serializable::serialize(const template <> template -Circuit::BlackBoxFuncCall::BigIntDiv serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::BigIntDiv obj; +Program::BlackBoxFuncCall::BigIntDiv serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::BigIntDiv obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::BigIntFromLeBytes &lhs, const BlackBoxFuncCall::BigIntFromLeBytes &rhs) { if (!(lhs.inputs == rhs.inputs)) { return false; } @@ -2845,11 +2950,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::BigIntFromLeBytes &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::BigIntFromLeBytes &obj, Serializer &serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.modulus, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -2857,15 +2962,15 @@ void serde::Serializable::serializ template <> template -Circuit::BlackBoxFuncCall::BigIntFromLeBytes serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::BigIntFromLeBytes obj; +Program::BlackBoxFuncCall::BigIntFromLeBytes serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::BigIntFromLeBytes obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.modulus = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::BigIntToLeBytes &lhs, const BlackBoxFuncCall::BigIntToLeBytes &rhs) { if (!(lhs.input == rhs.input)) { return false; } @@ -2888,25 +2993,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::BigIntToLeBytes &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::BigIntToLeBytes &obj, Serializer &serializer) { serde::Serializable::serialize(obj.input, serializer); serde::Serializable::serialize(obj.outputs, serializer); } template <> template -Circuit::BlackBoxFuncCall::BigIntToLeBytes serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::BigIntToLeBytes obj; +Program::BlackBoxFuncCall::BigIntToLeBytes serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::BigIntToLeBytes obj; obj.input = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::Poseidon2Permutation &lhs, const BlackBoxFuncCall::Poseidon2Permutation &rhs) { if (!(lhs.inputs == rhs.inputs)) { return false; } @@ -2930,11 +3035,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::Poseidon2Permutation &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::Poseidon2Permutation &obj, Serializer &serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.outputs, serializer); serde::Serializable::serialize(obj.len, serializer); @@ -2942,15 +3047,15 @@ void serde::Serializable::seria template <> template -Circuit::BlackBoxFuncCall::Poseidon2Permutation serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::Poseidon2Permutation obj; +Program::BlackBoxFuncCall::Poseidon2Permutation serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::Poseidon2Permutation obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); obj.len = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxFuncCall::Sha256Compression &lhs, const BlackBoxFuncCall::Sha256Compression &rhs) { if (!(lhs.inputs == rhs.inputs)) { return false; } @@ -2974,11 +3079,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxFuncCall::Sha256Compression &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxFuncCall::Sha256Compression &obj, Serializer &serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.hash_values, serializer); serde::Serializable::serialize(obj.outputs, serializer); @@ -2986,15 +3091,15 @@ void serde::Serializable::serializ template <> template -Circuit::BlackBoxFuncCall::Sha256Compression serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxFuncCall::Sha256Compression obj; +Program::BlackBoxFuncCall::Sha256Compression serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxFuncCall::Sha256Compression obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.hash_values = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp &lhs, const BlackBoxOp &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -3016,11 +3121,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -3028,15 +3133,15 @@ void serde::Serializable::serialize(const Circuit::BlackBox template <> template -Circuit::BlackBoxOp serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::BlackBoxOp serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::BlackBoxOp obj; + Program::BlackBoxOp obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::Sha256 &lhs, const BlackBoxOp::Sha256 &rhs) { if (!(lhs.message == rhs.message)) { return false; } @@ -3059,25 +3164,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::Sha256 &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::Sha256 &obj, Serializer &serializer) { serde::Serializable::serialize(obj.message, serializer); serde::Serializable::serialize(obj.output, serializer); } template <> template -Circuit::BlackBoxOp::Sha256 serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::Sha256 obj; +Program::BlackBoxOp::Sha256 serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::Sha256 obj; obj.message = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::Blake2s &lhs, const BlackBoxOp::Blake2s &rhs) { if (!(lhs.message == rhs.message)) { return false; } @@ -3100,25 +3205,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::Blake2s &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::Blake2s &obj, Serializer &serializer) { serde::Serializable::serialize(obj.message, serializer); serde::Serializable::serialize(obj.output, serializer); } template <> template -Circuit::BlackBoxOp::Blake2s serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::Blake2s obj; +Program::BlackBoxOp::Blake2s serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::Blake2s obj; obj.message = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::Blake3 &lhs, const BlackBoxOp::Blake3 &rhs) { if (!(lhs.message == rhs.message)) { return false; } @@ -3141,25 +3246,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::Blake3 &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::Blake3 &obj, Serializer &serializer) { serde::Serializable::serialize(obj.message, serializer); serde::Serializable::serialize(obj.output, serializer); } template <> template -Circuit::BlackBoxOp::Blake3 serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::Blake3 obj; +Program::BlackBoxOp::Blake3 serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::Blake3 obj; obj.message = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::Keccak256 &lhs, const BlackBoxOp::Keccak256 &rhs) { if (!(lhs.message == rhs.message)) { return false; } @@ -3182,25 +3287,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::Keccak256 &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::Keccak256 &obj, Serializer &serializer) { serde::Serializable::serialize(obj.message, serializer); serde::Serializable::serialize(obj.output, serializer); } template <> template -Circuit::BlackBoxOp::Keccak256 serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::Keccak256 obj; +Program::BlackBoxOp::Keccak256 serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::Keccak256 obj; obj.message = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::Keccakf1600 &lhs, const BlackBoxOp::Keccakf1600 &rhs) { if (!(lhs.message == rhs.message)) { return false; } @@ -3223,25 +3328,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::Keccakf1600 &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::Keccakf1600 &obj, Serializer &serializer) { serde::Serializable::serialize(obj.message, serializer); serde::Serializable::serialize(obj.output, serializer); } template <> template -Circuit::BlackBoxOp::Keccakf1600 serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::Keccakf1600 obj; +Program::BlackBoxOp::Keccakf1600 serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::Keccakf1600 obj; obj.message = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::EcdsaSecp256k1 &lhs, const BlackBoxOp::EcdsaSecp256k1 &rhs) { if (!(lhs.hashed_msg == rhs.hashed_msg)) { return false; } @@ -3267,11 +3372,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::EcdsaSecp256k1 &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::EcdsaSecp256k1 &obj, Serializer &serializer) { serde::Serializable::serialize(obj.hashed_msg, serializer); serde::Serializable::serialize(obj.public_key_x, serializer); serde::Serializable::serialize(obj.public_key_y, serializer); @@ -3281,8 +3386,8 @@ void serde::Serializable::serialize(const C template <> template -Circuit::BlackBoxOp::EcdsaSecp256k1 serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::EcdsaSecp256k1 obj; +Program::BlackBoxOp::EcdsaSecp256k1 serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::EcdsaSecp256k1 obj; obj.hashed_msg = serde::Deserializable::deserialize(deserializer); obj.public_key_x = serde::Deserializable::deserialize(deserializer); obj.public_key_y = serde::Deserializable::deserialize(deserializer); @@ -3291,7 +3396,7 @@ Circuit::BlackBoxOp::EcdsaSecp256k1 serde::Deserializable template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::EcdsaSecp256r1 &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::EcdsaSecp256r1 &obj, Serializer &serializer) { serde::Serializable::serialize(obj.hashed_msg, serializer); serde::Serializable::serialize(obj.public_key_x, serializer); serde::Serializable::serialize(obj.public_key_y, serializer); @@ -3331,8 +3436,8 @@ void serde::Serializable::serialize(const C template <> template -Circuit::BlackBoxOp::EcdsaSecp256r1 serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::EcdsaSecp256r1 obj; +Program::BlackBoxOp::EcdsaSecp256r1 serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::EcdsaSecp256r1 obj; obj.hashed_msg = serde::Deserializable::deserialize(deserializer); obj.public_key_x = serde::Deserializable::deserialize(deserializer); obj.public_key_y = serde::Deserializable::deserialize(deserializer); @@ -3341,7 +3446,7 @@ Circuit::BlackBoxOp::EcdsaSecp256r1 serde::Deserializable template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::SchnorrVerify &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::SchnorrVerify &obj, Serializer &serializer) { serde::Serializable::serialize(obj.public_key_x, serializer); serde::Serializable::serialize(obj.public_key_y, serializer); serde::Serializable::serialize(obj.message, serializer); @@ -3381,8 +3486,8 @@ void serde::Serializable::serialize(const Ci template <> template -Circuit::BlackBoxOp::SchnorrVerify serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::SchnorrVerify obj; +Program::BlackBoxOp::SchnorrVerify serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::SchnorrVerify obj; obj.public_key_x = serde::Deserializable::deserialize(deserializer); obj.public_key_y = serde::Deserializable::deserialize(deserializer); obj.message = serde::Deserializable::deserialize(deserializer); @@ -3391,7 +3496,7 @@ Circuit::BlackBoxOp::SchnorrVerify serde::Deserializable template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::PedersenCommitment &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::PedersenCommitment &obj, Serializer &serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.domain_separator, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -3427,15 +3532,15 @@ void serde::Serializable::serialize(con template <> template -Circuit::BlackBoxOp::PedersenCommitment serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::PedersenCommitment obj; +Program::BlackBoxOp::PedersenCommitment serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::PedersenCommitment obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.domain_separator = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::PedersenHash &lhs, const BlackBoxOp::PedersenHash &rhs) { if (!(lhs.inputs == rhs.inputs)) { return false; } @@ -3459,11 +3564,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::PedersenHash &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::PedersenHash &obj, Serializer &serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.domain_separator, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -3471,15 +3576,15 @@ void serde::Serializable::serialize(const Cir template <> template -Circuit::BlackBoxOp::PedersenHash serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::PedersenHash obj; +Program::BlackBoxOp::PedersenHash serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::PedersenHash obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.domain_separator = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::FixedBaseScalarMul &lhs, const BlackBoxOp::FixedBaseScalarMul &rhs) { if (!(lhs.low == rhs.low)) { return false; } @@ -3503,11 +3608,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::FixedBaseScalarMul &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::FixedBaseScalarMul &obj, Serializer &serializer) { serde::Serializable::serialize(obj.low, serializer); serde::Serializable::serialize(obj.high, serializer); serde::Serializable::serialize(obj.result, serializer); @@ -3515,15 +3620,15 @@ void serde::Serializable::serialize(con template <> template -Circuit::BlackBoxOp::FixedBaseScalarMul serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::FixedBaseScalarMul obj; +Program::BlackBoxOp::FixedBaseScalarMul serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::FixedBaseScalarMul obj; obj.low = serde::Deserializable::deserialize(deserializer); obj.high = serde::Deserializable::deserialize(deserializer); obj.result = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::EmbeddedCurveAdd &lhs, const BlackBoxOp::EmbeddedCurveAdd &rhs) { if (!(lhs.input1_x == rhs.input1_x)) { return false; } @@ -3549,11 +3654,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::EmbeddedCurveAdd &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::EmbeddedCurveAdd &obj, Serializer &serializer) { serde::Serializable::serialize(obj.input1_x, serializer); serde::Serializable::serialize(obj.input1_y, serializer); serde::Serializable::serialize(obj.input2_x, serializer); @@ -3563,8 +3668,8 @@ void serde::Serializable::serialize(const template <> template -Circuit::BlackBoxOp::EmbeddedCurveAdd serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::EmbeddedCurveAdd obj; +Program::BlackBoxOp::EmbeddedCurveAdd serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::EmbeddedCurveAdd obj; obj.input1_x = serde::Deserializable::deserialize(deserializer); obj.input1_y = serde::Deserializable::deserialize(deserializer); obj.input2_x = serde::Deserializable::deserialize(deserializer); @@ -3573,7 +3678,7 @@ Circuit::BlackBoxOp::EmbeddedCurveAdd serde::Deserializable template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::BigIntAdd &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::BigIntAdd &obj, Serializer &serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -3609,15 +3714,15 @@ void serde::Serializable::serialize(const Circui template <> template -Circuit::BlackBoxOp::BigIntAdd serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::BigIntAdd obj; +Program::BlackBoxOp::BigIntAdd serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::BigIntAdd obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::BigIntSub &lhs, const BlackBoxOp::BigIntSub &rhs) { if (!(lhs.lhs == rhs.lhs)) { return false; } @@ -3641,11 +3746,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::BigIntSub &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::BigIntSub &obj, Serializer &serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -3653,15 +3758,15 @@ void serde::Serializable::serialize(const Circui template <> template -Circuit::BlackBoxOp::BigIntSub serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::BigIntSub obj; +Program::BlackBoxOp::BigIntSub serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::BigIntSub obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::BigIntMul &lhs, const BlackBoxOp::BigIntMul &rhs) { if (!(lhs.lhs == rhs.lhs)) { return false; } @@ -3685,11 +3790,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::BigIntMul &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::BigIntMul &obj, Serializer &serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -3697,15 +3802,15 @@ void serde::Serializable::serialize(const Circui template <> template -Circuit::BlackBoxOp::BigIntMul serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::BigIntMul obj; +Program::BlackBoxOp::BigIntMul serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::BigIntMul obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::BigIntDiv &lhs, const BlackBoxOp::BigIntDiv &rhs) { if (!(lhs.lhs == rhs.lhs)) { return false; } @@ -3729,11 +3834,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::BigIntDiv &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::BigIntDiv &obj, Serializer &serializer) { serde::Serializable::serialize(obj.lhs, serializer); serde::Serializable::serialize(obj.rhs, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -3741,15 +3846,15 @@ void serde::Serializable::serialize(const Circui template <> template -Circuit::BlackBoxOp::BigIntDiv serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::BigIntDiv obj; +Program::BlackBoxOp::BigIntDiv serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::BigIntDiv obj; obj.lhs = serde::Deserializable::deserialize(deserializer); obj.rhs = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::BigIntFromLeBytes &lhs, const BlackBoxOp::BigIntFromLeBytes &rhs) { if (!(lhs.inputs == rhs.inputs)) { return false; } @@ -3773,11 +3878,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::BigIntFromLeBytes &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::BigIntFromLeBytes &obj, Serializer &serializer) { serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.modulus, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -3785,15 +3890,15 @@ void serde::Serializable::serialize(cons template <> template -Circuit::BlackBoxOp::BigIntFromLeBytes serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::BigIntFromLeBytes obj; +Program::BlackBoxOp::BigIntFromLeBytes serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::BigIntFromLeBytes obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.modulus = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::BigIntToLeBytes &lhs, const BlackBoxOp::BigIntToLeBytes &rhs) { if (!(lhs.input == rhs.input)) { return false; } @@ -3816,25 +3921,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::BigIntToLeBytes &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::BigIntToLeBytes &obj, Serializer &serializer) { serde::Serializable::serialize(obj.input, serializer); serde::Serializable::serialize(obj.output, serializer); } template <> template -Circuit::BlackBoxOp::BigIntToLeBytes serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::BigIntToLeBytes obj; +Program::BlackBoxOp::BigIntToLeBytes serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::BigIntToLeBytes obj; obj.input = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::Poseidon2Permutation &lhs, const BlackBoxOp::Poseidon2Permutation &rhs) { if (!(lhs.message == rhs.message)) { return false; } @@ -3858,11 +3963,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::Poseidon2Permutation &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::Poseidon2Permutation &obj, Serializer &serializer) { serde::Serializable::serialize(obj.message, serializer); serde::Serializable::serialize(obj.output, serializer); serde::Serializable::serialize(obj.len, serializer); @@ -3870,15 +3975,15 @@ void serde::Serializable::serialize(c template <> template -Circuit::BlackBoxOp::Poseidon2Permutation serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::Poseidon2Permutation obj; +Program::BlackBoxOp::Poseidon2Permutation serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::Poseidon2Permutation obj; obj.message = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); obj.len = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlackBoxOp::Sha256Compression &lhs, const BlackBoxOp::Sha256Compression &rhs) { if (!(lhs.input == rhs.input)) { return false; } @@ -3902,11 +4007,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlackBoxOp::Sha256Compression &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlackBoxOp::Sha256Compression &obj, Serializer &serializer) { serde::Serializable::serialize(obj.input, serializer); serde::Serializable::serialize(obj.hash_values, serializer); serde::Serializable::serialize(obj.output, serializer); @@ -3914,15 +4019,15 @@ void serde::Serializable::serialize(cons template <> template -Circuit::BlackBoxOp::Sha256Compression serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BlackBoxOp::Sha256Compression obj; +Program::BlackBoxOp::Sha256Compression serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BlackBoxOp::Sha256Compression obj; obj.input = serde::Deserializable::deserialize(deserializer); obj.hash_values = serde::Deserializable::deserialize(deserializer); obj.output = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BlockId &lhs, const BlockId &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -3944,11 +4049,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BlockId &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BlockId &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -3956,15 +4061,15 @@ void serde::Serializable::serialize(const Circuit::BlockId &ob template <> template -Circuit::BlockId serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::BlockId serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::BlockId obj; + Program::BlockId obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const Brillig &lhs, const Brillig &rhs) { if (!(lhs.inputs == rhs.inputs)) { return false; } @@ -3989,11 +4094,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::Brillig &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::Brillig &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.inputs, serializer); serde::Serializable::serialize(obj.outputs, serializer); @@ -4004,9 +4109,9 @@ void serde::Serializable::serialize(const Circuit::Brillig &ob template <> template -Circuit::Brillig serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::Brillig serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::Brillig obj; + Program::Brillig obj; obj.inputs = serde::Deserializable::deserialize(deserializer); obj.outputs = serde::Deserializable::deserialize(deserializer); obj.bytecode = serde::Deserializable::deserialize(deserializer); @@ -4015,7 +4120,7 @@ Circuit::Brillig serde::Deserializable::deserialize(Deserializ return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligInputs &lhs, const BrilligInputs &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -4037,11 +4142,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligInputs &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligInputs &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -4049,15 +4154,15 @@ void serde::Serializable::serialize(const Circuit::Brill template <> template -Circuit::BrilligInputs serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::BrilligInputs serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::BrilligInputs obj; + Program::BrilligInputs obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligInputs::Single &lhs, const BrilligInputs::Single &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -4079,23 +4184,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligInputs::Single &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligInputs::Single &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::BrilligInputs::Single serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligInputs::Single obj; +Program::BrilligInputs::Single serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligInputs::Single obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligInputs::Array &lhs, const BrilligInputs::Array &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -4117,23 +4222,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligInputs::Array &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligInputs::Array &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::BrilligInputs::Array serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligInputs::Array obj; +Program::BrilligInputs::Array serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligInputs::Array obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligInputs::MemoryArray &lhs, const BrilligInputs::MemoryArray &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -4155,23 +4260,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligInputs::MemoryArray &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligInputs::MemoryArray &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::BrilligInputs::MemoryArray serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligInputs::MemoryArray obj; +Program::BrilligInputs::MemoryArray serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligInputs::MemoryArray obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOpcode &lhs, const BrilligOpcode &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -4193,11 +4298,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -4205,15 +4310,15 @@ void serde::Serializable::serialize(const Circuit::Brill template <> template -Circuit::BrilligOpcode serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::BrilligOpcode serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::BrilligOpcode obj; + Program::BrilligOpcode obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOpcode::BinaryFieldOp &lhs, const BrilligOpcode::BinaryFieldOp &rhs) { if (!(lhs.destination == rhs.destination)) { return false; } @@ -4238,11 +4343,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::BinaryFieldOp &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::BinaryFieldOp &obj, Serializer &serializer) { serde::Serializable::serialize(obj.destination, serializer); serde::Serializable::serialize(obj.op, serializer); serde::Serializable::serialize(obj.lhs, serializer); @@ -4251,8 +4356,8 @@ void serde::Serializable::serialize(const template <> template -Circuit::BrilligOpcode::BinaryFieldOp serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::BinaryFieldOp obj; +Program::BrilligOpcode::BinaryFieldOp serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::BinaryFieldOp obj; obj.destination = serde::Deserializable::deserialize(deserializer); obj.op = serde::Deserializable::deserialize(deserializer); obj.lhs = serde::Deserializable::deserialize(deserializer); @@ -4260,7 +4365,7 @@ Circuit::BrilligOpcode::BinaryFieldOp serde::Deserializable template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::BinaryIntOp &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::BinaryIntOp &obj, Serializer &serializer) { serde::Serializable::serialize(obj.destination, serializer); serde::Serializable::serialize(obj.op, serializer); serde::Serializable::serialize(obj.bit_size, serializer); @@ -4300,8 +4405,8 @@ void serde::Serializable::serialize(const C template <> template -Circuit::BrilligOpcode::BinaryIntOp serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::BinaryIntOp obj; +Program::BrilligOpcode::BinaryIntOp serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::BinaryIntOp obj; obj.destination = serde::Deserializable::deserialize(deserializer); obj.op = serde::Deserializable::deserialize(deserializer); obj.bit_size = serde::Deserializable::deserialize(deserializer); @@ -4310,7 +4415,7 @@ Circuit::BrilligOpcode::BinaryIntOp serde::Deserializable template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::Cast &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::Cast &obj, Serializer &serializer) { serde::Serializable::serialize(obj.destination, serializer); serde::Serializable::serialize(obj.source, serializer); serde::Serializable::serialize(obj.bit_size, serializer); @@ -4346,15 +4451,15 @@ void serde::Serializable::serialize(const Circuit: template <> template -Circuit::BrilligOpcode::Cast serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::Cast obj; +Program::BrilligOpcode::Cast serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::Cast obj; obj.destination = serde::Deserializable::deserialize(deserializer); obj.source = serde::Deserializable::deserialize(deserializer); obj.bit_size = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOpcode::JumpIfNot &lhs, const BrilligOpcode::JumpIfNot &rhs) { if (!(lhs.condition == rhs.condition)) { return false; } @@ -4377,25 +4482,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::JumpIfNot &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::JumpIfNot &obj, Serializer &serializer) { serde::Serializable::serialize(obj.condition, serializer); serde::Serializable::serialize(obj.location, serializer); } template <> template -Circuit::BrilligOpcode::JumpIfNot serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::JumpIfNot obj; +Program::BrilligOpcode::JumpIfNot serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::JumpIfNot obj; obj.condition = serde::Deserializable::deserialize(deserializer); obj.location = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOpcode::JumpIf &lhs, const BrilligOpcode::JumpIf &rhs) { if (!(lhs.condition == rhs.condition)) { return false; } @@ -4418,25 +4523,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::JumpIf &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::JumpIf &obj, Serializer &serializer) { serde::Serializable::serialize(obj.condition, serializer); serde::Serializable::serialize(obj.location, serializer); } template <> template -Circuit::BrilligOpcode::JumpIf serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::JumpIf obj; +Program::BrilligOpcode::JumpIf serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::JumpIf obj; obj.condition = serde::Deserializable::deserialize(deserializer); obj.location = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOpcode::Jump &lhs, const BrilligOpcode::Jump &rhs) { if (!(lhs.location == rhs.location)) { return false; } @@ -4458,23 +4563,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::Jump &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::Jump &obj, Serializer &serializer) { serde::Serializable::serialize(obj.location, serializer); } template <> template -Circuit::BrilligOpcode::Jump serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::Jump obj; +Program::BrilligOpcode::Jump serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::Jump obj; obj.location = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOpcode::CalldataCopy &lhs, const BrilligOpcode::CalldataCopy &rhs) { if (!(lhs.destination_address == rhs.destination_address)) { return false; } @@ -4498,11 +4603,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::CalldataCopy &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::CalldataCopy &obj, Serializer &serializer) { serde::Serializable::serialize(obj.destination_address, serializer); serde::Serializable::serialize(obj.size, serializer); serde::Serializable::serialize(obj.offset, serializer); @@ -4510,15 +4615,15 @@ void serde::Serializable::serialize(const template <> template -Circuit::BrilligOpcode::CalldataCopy serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::CalldataCopy obj; +Program::BrilligOpcode::CalldataCopy serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::CalldataCopy obj; obj.destination_address = serde::Deserializable::deserialize(deserializer); obj.size = serde::Deserializable::deserialize(deserializer); obj.offset = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOpcode::Call &lhs, const BrilligOpcode::Call &rhs) { if (!(lhs.location == rhs.location)) { return false; } @@ -4540,23 +4645,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::Call &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::Call &obj, Serializer &serializer) { serde::Serializable::serialize(obj.location, serializer); } template <> template -Circuit::BrilligOpcode::Call serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::Call obj; +Program::BrilligOpcode::Call serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::Call obj; obj.location = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOpcode::Const &lhs, const BrilligOpcode::Const &rhs) { if (!(lhs.destination == rhs.destination)) { return false; } @@ -4580,11 +4685,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::Const &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::Const &obj, Serializer &serializer) { serde::Serializable::serialize(obj.destination, serializer); serde::Serializable::serialize(obj.bit_size, serializer); serde::Serializable::serialize(obj.value, serializer); @@ -4592,15 +4697,15 @@ void serde::Serializable::serialize(const Circuit template <> template -Circuit::BrilligOpcode::Const serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::Const obj; +Program::BrilligOpcode::Const serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::Const obj; obj.destination = serde::Deserializable::deserialize(deserializer); obj.bit_size = serde::Deserializable::deserialize(deserializer); obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOpcode::Return &lhs, const BrilligOpcode::Return &rhs) { return true; @@ -4621,21 +4726,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::Return &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::Return &obj, Serializer &serializer) { } template <> template -Circuit::BrilligOpcode::Return serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::Return obj; +Program::BrilligOpcode::Return serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::Return obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOpcode::ForeignCall &lhs, const BrilligOpcode::ForeignCall &rhs) { if (!(lhs.function == rhs.function)) { return false; } @@ -4661,11 +4766,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::ForeignCall &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::ForeignCall &obj, Serializer &serializer) { serde::Serializable::serialize(obj.function, serializer); serde::Serializable::serialize(obj.destinations, serializer); serde::Serializable::serialize(obj.destination_value_types, serializer); @@ -4675,8 +4780,8 @@ void serde::Serializable::serialize(const C template <> template -Circuit::BrilligOpcode::ForeignCall serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::ForeignCall obj; +Program::BrilligOpcode::ForeignCall serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::ForeignCall obj; obj.function = serde::Deserializable::deserialize(deserializer); obj.destinations = serde::Deserializable::deserialize(deserializer); obj.destination_value_types = serde::Deserializable::deserialize(deserializer); @@ -4685,7 +4790,7 @@ Circuit::BrilligOpcode::ForeignCall serde::Deserializable template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::Mov &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::Mov &obj, Serializer &serializer) { serde::Serializable::serialize(obj.destination, serializer); serde::Serializable::serialize(obj.source, serializer); } template <> template -Circuit::BrilligOpcode::Mov serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::Mov obj; +Program::BrilligOpcode::Mov serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::Mov obj; obj.destination = serde::Deserializable::deserialize(deserializer); obj.source = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { + + inline bool operator==(const BrilligOpcode::ConditionalMov &lhs, const BrilligOpcode::ConditionalMov &rhs) { + if (!(lhs.destination == rhs.destination)) { return false; } + if (!(lhs.source_a == rhs.source_a)) { return false; } + if (!(lhs.source_b == rhs.source_b)) { return false; } + if (!(lhs.condition == rhs.condition)) { return false; } + return true; + } + + inline std::vector BrilligOpcode::ConditionalMov::bincodeSerialize() const { + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); + } + + inline BrilligOpcode::ConditionalMov BrilligOpcode::ConditionalMov::bincodeDeserialize(std::vector input) { + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw serde::deserialization_error("Some input bytes were not read"); + } + return value; + } + +} // end of namespace Program + +template <> +template +void serde::Serializable::serialize(const Program::BrilligOpcode::ConditionalMov &obj, Serializer &serializer) { + serde::Serializable::serialize(obj.destination, serializer); + serde::Serializable::serialize(obj.source_a, serializer); + serde::Serializable::serialize(obj.source_b, serializer); + serde::Serializable::serialize(obj.condition, serializer); +} + +template <> +template +Program::BrilligOpcode::ConditionalMov serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::ConditionalMov obj; + obj.destination = serde::Deserializable::deserialize(deserializer); + obj.source_a = serde::Deserializable::deserialize(deserializer); + obj.source_b = serde::Deserializable::deserialize(deserializer); + obj.condition = serde::Deserializable::deserialize(deserializer); + return obj; +} + +namespace Program { inline bool operator==(const BrilligOpcode::Load &lhs, const BrilligOpcode::Load &rhs) { if (!(lhs.destination == rhs.destination)) { return false; } @@ -4749,25 +4901,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::Load &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::Load &obj, Serializer &serializer) { serde::Serializable::serialize(obj.destination, serializer); serde::Serializable::serialize(obj.source_pointer, serializer); } template <> template -Circuit::BrilligOpcode::Load serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::Load obj; +Program::BrilligOpcode::Load serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::Load obj; obj.destination = serde::Deserializable::deserialize(deserializer); obj.source_pointer = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOpcode::Store &lhs, const BrilligOpcode::Store &rhs) { if (!(lhs.destination_pointer == rhs.destination_pointer)) { return false; } @@ -4790,25 +4942,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::Store &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::Store &obj, Serializer &serializer) { serde::Serializable::serialize(obj.destination_pointer, serializer); serde::Serializable::serialize(obj.source, serializer); } template <> template -Circuit::BrilligOpcode::Store serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::Store obj; +Program::BrilligOpcode::Store serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::Store obj; obj.destination_pointer = serde::Deserializable::deserialize(deserializer); obj.source = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOpcode::BlackBox &lhs, const BrilligOpcode::BlackBox &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -4830,23 +4982,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::BlackBox &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::BlackBox &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::BrilligOpcode::BlackBox serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::BlackBox obj; +Program::BrilligOpcode::BlackBox serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::BlackBox obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOpcode::Trap &lhs, const BrilligOpcode::Trap &rhs) { return true; @@ -4867,21 +5019,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::Trap &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::Trap &obj, Serializer &serializer) { } template <> template -Circuit::BrilligOpcode::Trap serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::Trap obj; +Program::BrilligOpcode::Trap serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::Trap obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOpcode::Stop &lhs, const BrilligOpcode::Stop &rhs) { if (!(lhs.return_data_offset == rhs.return_data_offset)) { return false; } @@ -4904,25 +5056,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOpcode::Stop &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOpcode::Stop &obj, Serializer &serializer) { serde::Serializable::serialize(obj.return_data_offset, serializer); serde::Serializable::serialize(obj.return_data_size, serializer); } template <> template -Circuit::BrilligOpcode::Stop serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOpcode::Stop obj; +Program::BrilligOpcode::Stop serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::Stop obj; obj.return_data_offset = serde::Deserializable::deserialize(deserializer); obj.return_data_size = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOutputs &lhs, const BrilligOutputs &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -4944,11 +5096,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOutputs &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOutputs &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -4956,15 +5108,15 @@ void serde::Serializable::serialize(const Circuit::Bril template <> template -Circuit::BrilligOutputs serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::BrilligOutputs serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::BrilligOutputs obj; + Program::BrilligOutputs obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOutputs::Simple &lhs, const BrilligOutputs::Simple &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -4986,23 +5138,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOutputs::Simple &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOutputs::Simple &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::BrilligOutputs::Simple serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOutputs::Simple obj; +Program::BrilligOutputs::Simple serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOutputs::Simple obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const BrilligOutputs::Array &lhs, const BrilligOutputs::Array &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -5024,23 +5176,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::BrilligOutputs::Array &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::BrilligOutputs::Array &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::BrilligOutputs::Array serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::BrilligOutputs::Array obj; +Program::BrilligOutputs::Array serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOutputs::Array obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const Circuit &lhs, const Circuit &rhs) { if (!(lhs.current_witness_index == rhs.current_witness_index)) { return false; } @@ -5069,11 +5221,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::Circuit &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::Circuit &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.current_witness_index, serializer); serde::Serializable::serialize(obj.opcodes, serializer); @@ -5088,9 +5240,9 @@ void serde::Serializable::serialize(const Circuit::Circuit &ob template <> template -Circuit::Circuit serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::Circuit serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::Circuit obj; + Program::Circuit obj; obj.current_witness_index = serde::Deserializable::deserialize(deserializer); obj.opcodes = serde::Deserializable::deserialize(deserializer); obj.expression_width = serde::Deserializable::deserialize(deserializer); @@ -5103,7 +5255,7 @@ Circuit::Circuit serde::Deserializable::deserialize(Deserializ return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const Directive &lhs, const Directive &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -5125,11 +5277,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::Directive &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::Directive &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -5137,15 +5289,15 @@ void serde::Serializable::serialize(const Circuit::Directive template <> template -Circuit::Directive serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::Directive serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::Directive obj; + Program::Directive obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const Directive::ToLeRadix &lhs, const Directive::ToLeRadix &rhs) { if (!(lhs.a == rhs.a)) { return false; } @@ -5169,11 +5321,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::Directive::ToLeRadix &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::Directive::ToLeRadix &obj, Serializer &serializer) { serde::Serializable::serialize(obj.a, serializer); serde::Serializable::serialize(obj.b, serializer); serde::Serializable::serialize(obj.radix, serializer); @@ -5181,15 +5333,15 @@ void serde::Serializable::serialize(const Circuit template <> template -Circuit::Directive::ToLeRadix serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::Directive::ToLeRadix obj; +Program::Directive::ToLeRadix serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::Directive::ToLeRadix obj; obj.a = serde::Deserializable::deserialize(deserializer); obj.b = serde::Deserializable::deserialize(deserializer); obj.radix = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const Expression &lhs, const Expression &rhs) { if (!(lhs.mul_terms == rhs.mul_terms)) { return false; } @@ -5213,11 +5365,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::Expression &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::Expression &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.mul_terms, serializer); serde::Serializable::serialize(obj.linear_combinations, serializer); @@ -5227,9 +5379,9 @@ void serde::Serializable::serialize(const Circuit::Expressi template <> template -Circuit::Expression serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::Expression serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::Expression obj; + Program::Expression obj; obj.mul_terms = serde::Deserializable::deserialize(deserializer); obj.linear_combinations = serde::Deserializable::deserialize(deserializer); obj.q_c = serde::Deserializable::deserialize(deserializer); @@ -5237,7 +5389,7 @@ Circuit::Expression serde::Deserializable::deserialize(Dese return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const ExpressionWidth &lhs, const ExpressionWidth &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -5259,11 +5411,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::ExpressionWidth &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::ExpressionWidth &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -5271,15 +5423,15 @@ void serde::Serializable::serialize(const Circuit::Exp template <> template -Circuit::ExpressionWidth serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::ExpressionWidth serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::ExpressionWidth obj; + Program::ExpressionWidth obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const ExpressionWidth::Unbounded &lhs, const ExpressionWidth::Unbounded &rhs) { return true; @@ -5300,21 +5452,21 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::ExpressionWidth::Unbounded &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::ExpressionWidth::Unbounded &obj, Serializer &serializer) { } template <> template -Circuit::ExpressionWidth::Unbounded serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::ExpressionWidth::Unbounded obj; +Program::ExpressionWidth::Unbounded serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::ExpressionWidth::Unbounded obj; return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const ExpressionWidth::Bounded &lhs, const ExpressionWidth::Bounded &rhs) { if (!(lhs.width == rhs.width)) { return false; } @@ -5336,23 +5488,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::ExpressionWidth::Bounded &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::ExpressionWidth::Bounded &obj, Serializer &serializer) { serde::Serializable::serialize(obj.width, serializer); } template <> template -Circuit::ExpressionWidth::Bounded serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::ExpressionWidth::Bounded obj; +Program::ExpressionWidth::Bounded serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::ExpressionWidth::Bounded obj; obj.width = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const FunctionInput &lhs, const FunctionInput &rhs) { if (!(lhs.witness == rhs.witness)) { return false; } @@ -5375,11 +5527,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::FunctionInput &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::FunctionInput &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.witness, serializer); serde::Serializable::serialize(obj.num_bits, serializer); @@ -5388,16 +5540,16 @@ void serde::Serializable::serialize(const Circuit::Funct template <> template -Circuit::FunctionInput serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::FunctionInput serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::FunctionInput obj; + Program::FunctionInput obj; obj.witness = serde::Deserializable::deserialize(deserializer); obj.num_bits = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const HeapArray &lhs, const HeapArray &rhs) { if (!(lhs.pointer == rhs.pointer)) { return false; } @@ -5420,11 +5572,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::HeapArray &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::HeapArray &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.pointer, serializer); serde::Serializable::serialize(obj.size, serializer); @@ -5433,16 +5585,16 @@ void serde::Serializable::serialize(const Circuit::HeapArray template <> template -Circuit::HeapArray serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::HeapArray serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::HeapArray obj; + Program::HeapArray obj; obj.pointer = serde::Deserializable::deserialize(deserializer); obj.size = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const HeapValueType &lhs, const HeapValueType &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -5464,11 +5616,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::HeapValueType &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::HeapValueType &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -5476,17 +5628,18 @@ void serde::Serializable::serialize(const Circuit::HeapV template <> template -Circuit::HeapValueType serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::HeapValueType serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::HeapValueType obj; + Program::HeapValueType obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const HeapValueType::Simple &lhs, const HeapValueType::Simple &rhs) { + if (!(lhs.value == rhs.value)) { return false; } return true; } @@ -5505,21 +5658,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::HeapValueType::Simple &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::HeapValueType::Simple &obj, Serializer &serializer) { + serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::HeapValueType::Simple serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::HeapValueType::Simple obj; +Program::HeapValueType::Simple serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::HeapValueType::Simple obj; + obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const HeapValueType::Array &lhs, const HeapValueType::Array &rhs) { if (!(lhs.value_types == rhs.value_types)) { return false; } @@ -5542,25 +5697,25 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::HeapValueType::Array &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::HeapValueType::Array &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value_types, serializer); serde::Serializable::serialize(obj.size, serializer); } template <> template -Circuit::HeapValueType::Array serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::HeapValueType::Array obj; +Program::HeapValueType::Array serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::HeapValueType::Array obj; obj.value_types = serde::Deserializable::deserialize(deserializer); obj.size = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const HeapValueType::Vector &lhs, const HeapValueType::Vector &rhs) { if (!(lhs.value_types == rhs.value_types)) { return false; } @@ -5582,23 +5737,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::HeapValueType::Vector &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::HeapValueType::Vector &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value_types, serializer); } template <> template -Circuit::HeapValueType::Vector serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::HeapValueType::Vector obj; +Program::HeapValueType::Vector serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::HeapValueType::Vector obj; obj.value_types = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const HeapVector &lhs, const HeapVector &rhs) { if (!(lhs.pointer == rhs.pointer)) { return false; } @@ -5621,11 +5776,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::HeapVector &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::HeapVector &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.pointer, serializer); serde::Serializable::serialize(obj.size, serializer); @@ -5634,16 +5789,16 @@ void serde::Serializable::serialize(const Circuit::HeapVect template <> template -Circuit::HeapVector serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::HeapVector serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::HeapVector obj; + Program::HeapVector obj; obj.pointer = serde::Deserializable::deserialize(deserializer); obj.size = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const MemOp &lhs, const MemOp &rhs) { if (!(lhs.operation == rhs.operation)) { return false; } @@ -5667,11 +5822,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::MemOp &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::MemOp &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.operation, serializer); serde::Serializable::serialize(obj.index, serializer); @@ -5681,9 +5836,9 @@ void serde::Serializable::serialize(const Circuit::MemOp &obj, S template <> template -Circuit::MemOp serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::MemOp serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::MemOp obj; + Program::MemOp obj; obj.operation = serde::Deserializable::deserialize(deserializer); obj.index = serde::Deserializable::deserialize(deserializer); obj.value = serde::Deserializable::deserialize(deserializer); @@ -5691,7 +5846,7 @@ Circuit::MemOp serde::Deserializable::deserialize(Deserializer & return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const MemoryAddress &lhs, const MemoryAddress &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -5713,11 +5868,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::MemoryAddress &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::MemoryAddress &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -5725,15 +5880,15 @@ void serde::Serializable::serialize(const Circuit::Memor template <> template -Circuit::MemoryAddress serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::MemoryAddress serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::MemoryAddress obj; + Program::MemoryAddress obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const Opcode &lhs, const Opcode &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -5755,11 +5910,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::Opcode &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::Opcode &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -5767,15 +5922,15 @@ void serde::Serializable::serialize(const Circuit::Opcode &obj, template <> template -Circuit::Opcode serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::Opcode serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::Opcode obj; + Program::Opcode obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const Opcode::AssertZero &lhs, const Opcode::AssertZero &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -5797,23 +5952,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::Opcode::AssertZero &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::Opcode::AssertZero &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::Opcode::AssertZero serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::Opcode::AssertZero obj; +Program::Opcode::AssertZero serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::Opcode::AssertZero obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const Opcode::BlackBoxFuncCall &lhs, const Opcode::BlackBoxFuncCall &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -5835,23 +5990,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::Opcode::BlackBoxFuncCall &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::Opcode::BlackBoxFuncCall &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::Opcode::BlackBoxFuncCall serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::Opcode::BlackBoxFuncCall obj; +Program::Opcode::BlackBoxFuncCall serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::Opcode::BlackBoxFuncCall obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const Opcode::Directive &lhs, const Opcode::Directive &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -5873,23 +6028,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::Opcode::Directive &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::Opcode::Directive &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::Opcode::Directive serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::Opcode::Directive obj; +Program::Opcode::Directive serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::Opcode::Directive obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const Opcode::Brillig &lhs, const Opcode::Brillig &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -5911,23 +6066,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::Opcode::Brillig &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::Opcode::Brillig &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::Opcode::Brillig serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::Opcode::Brillig obj; +Program::Opcode::Brillig serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::Opcode::Brillig obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const Opcode::MemoryOp &lhs, const Opcode::MemoryOp &rhs) { if (!(lhs.block_id == rhs.block_id)) { return false; } @@ -5951,11 +6106,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::Opcode::MemoryOp &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::Opcode::MemoryOp &obj, Serializer &serializer) { serde::Serializable::serialize(obj.block_id, serializer); serde::Serializable::serialize(obj.op, serializer); serde::Serializable::serialize(obj.predicate, serializer); @@ -5963,15 +6118,15 @@ void serde::Serializable::serialize(const Circuit::Op template <> template -Circuit::Opcode::MemoryOp serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::Opcode::MemoryOp obj; +Program::Opcode::MemoryOp serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::Opcode::MemoryOp obj; obj.block_id = serde::Deserializable::deserialize(deserializer); obj.op = serde::Deserializable::deserialize(deserializer); obj.predicate = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const Opcode::MemoryInit &lhs, const Opcode::MemoryInit &rhs) { if (!(lhs.block_id == rhs.block_id)) { return false; } @@ -5994,25 +6149,69 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::Opcode::MemoryInit &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::Opcode::MemoryInit &obj, Serializer &serializer) { serde::Serializable::serialize(obj.block_id, serializer); serde::Serializable::serialize(obj.init, serializer); } template <> template -Circuit::Opcode::MemoryInit serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::Opcode::MemoryInit obj; +Program::Opcode::MemoryInit serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::Opcode::MemoryInit obj; obj.block_id = serde::Deserializable::deserialize(deserializer); obj.init = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { + + inline bool operator==(const Opcode::Call &lhs, const Opcode::Call &rhs) { + if (!(lhs.id == rhs.id)) { return false; } + if (!(lhs.inputs == rhs.inputs)) { return false; } + if (!(lhs.outputs == rhs.outputs)) { return false; } + return true; + } + + inline std::vector Opcode::Call::bincodeSerialize() const { + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); + } + + inline Opcode::Call Opcode::Call::bincodeDeserialize(std::vector input) { + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw serde::deserialization_error("Some input bytes were not read"); + } + return value; + } + +} // end of namespace Program + +template <> +template +void serde::Serializable::serialize(const Program::Opcode::Call &obj, Serializer &serializer) { + serde::Serializable::serialize(obj.id, serializer); + serde::Serializable::serialize(obj.inputs, serializer); + serde::Serializable::serialize(obj.outputs, serializer); +} + +template <> +template +Program::Opcode::Call serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::Opcode::Call obj; + obj.id = serde::Deserializable::deserialize(deserializer); + obj.inputs = serde::Deserializable::deserialize(deserializer); + obj.outputs = serde::Deserializable::deserialize(deserializer); + return obj; +} + +namespace Program { inline bool operator==(const OpcodeLocation &lhs, const OpcodeLocation &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -6034,11 +6233,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::OpcodeLocation &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::OpcodeLocation &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -6046,15 +6245,15 @@ void serde::Serializable::serialize(const Circuit::Opco template <> template -Circuit::OpcodeLocation serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::OpcodeLocation serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::OpcodeLocation obj; + Program::OpcodeLocation obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const OpcodeLocation::Acir &lhs, const OpcodeLocation::Acir &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -6076,23 +6275,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::OpcodeLocation::Acir &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::OpcodeLocation::Acir &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::OpcodeLocation::Acir serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::OpcodeLocation::Acir obj; +Program::OpcodeLocation::Acir serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::OpcodeLocation::Acir obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const OpcodeLocation::Brillig &lhs, const OpcodeLocation::Brillig &rhs) { if (!(lhs.acir_index == rhs.acir_index)) { return false; } @@ -6115,109 +6314,109 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::OpcodeLocation::Brillig &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::OpcodeLocation::Brillig &obj, Serializer &serializer) { serde::Serializable::serialize(obj.acir_index, serializer); serde::Serializable::serialize(obj.brillig_index, serializer); } template <> template -Circuit::OpcodeLocation::Brillig serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::OpcodeLocation::Brillig obj; +Program::OpcodeLocation::Brillig serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::OpcodeLocation::Brillig obj; obj.acir_index = serde::Deserializable::deserialize(deserializer); obj.brillig_index = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { - inline bool operator==(const PublicInputs &lhs, const PublicInputs &rhs) { - if (!(lhs.value == rhs.value)) { return false; } + inline bool operator==(const Program &lhs, const Program &rhs) { + if (!(lhs.functions == rhs.functions)) { return false; } return true; } - inline std::vector PublicInputs::bincodeSerialize() const { + inline std::vector Program::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } - inline PublicInputs PublicInputs::bincodeDeserialize(std::vector input) { + inline Program Program::bincodeDeserialize(std::vector input) { auto deserializer = serde::BincodeDeserializer(input); - auto value = serde::Deserializable::deserialize(deserializer); + auto value = serde::Deserializable::deserialize(deserializer); if (deserializer.get_buffer_offset() < input.size()) { throw serde::deserialization_error("Some input bytes were not read"); } return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::PublicInputs &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::Program &obj, Serializer &serializer) { serializer.increase_container_depth(); - serde::Serializable::serialize(obj.value, serializer); + serde::Serializable::serialize(obj.functions, serializer); serializer.decrease_container_depth(); } template <> template -Circuit::PublicInputs serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::Program serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::PublicInputs obj; - obj.value = serde::Deserializable::deserialize(deserializer); + Program::Program obj; + obj.functions = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { - inline bool operator==(const Value &lhs, const Value &rhs) { - if (!(lhs.inner == rhs.inner)) { return false; } + inline bool operator==(const PublicInputs &lhs, const PublicInputs &rhs) { + if (!(lhs.value == rhs.value)) { return false; } return true; } - inline std::vector Value::bincodeSerialize() const { + inline std::vector PublicInputs::bincodeSerialize() const { auto serializer = serde::BincodeSerializer(); - serde::Serializable::serialize(*this, serializer); + serde::Serializable::serialize(*this, serializer); return std::move(serializer).bytes(); } - inline Value Value::bincodeDeserialize(std::vector input) { + inline PublicInputs PublicInputs::bincodeDeserialize(std::vector input) { auto deserializer = serde::BincodeDeserializer(input); - auto value = serde::Deserializable::deserialize(deserializer); + auto value = serde::Deserializable::deserialize(deserializer); if (deserializer.get_buffer_offset() < input.size()) { throw serde::deserialization_error("Some input bytes were not read"); } return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::Value &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::PublicInputs &obj, Serializer &serializer) { serializer.increase_container_depth(); - serde::Serializable::serialize(obj.inner, serializer); + serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); } template <> template -Circuit::Value serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::PublicInputs serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::Value obj; - obj.inner = serde::Deserializable::deserialize(deserializer); + Program::PublicInputs obj; + obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const ValueOrArray &lhs, const ValueOrArray &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -6239,11 +6438,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::ValueOrArray &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::ValueOrArray &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -6251,15 +6450,15 @@ void serde::Serializable::serialize(const Circuit::ValueO template <> template -Circuit::ValueOrArray serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::ValueOrArray serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::ValueOrArray obj; + Program::ValueOrArray obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const ValueOrArray::MemoryAddress &lhs, const ValueOrArray::MemoryAddress &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -6281,23 +6480,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::ValueOrArray::MemoryAddress &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::ValueOrArray::MemoryAddress &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::ValueOrArray::MemoryAddress serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::ValueOrArray::MemoryAddress obj; +Program::ValueOrArray::MemoryAddress serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::ValueOrArray::MemoryAddress obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const ValueOrArray::HeapArray &lhs, const ValueOrArray::HeapArray &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -6319,23 +6518,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::ValueOrArray::HeapArray &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::ValueOrArray::HeapArray &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::ValueOrArray::HeapArray serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::ValueOrArray::HeapArray obj; +Program::ValueOrArray::HeapArray serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::ValueOrArray::HeapArray obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const ValueOrArray::HeapVector &lhs, const ValueOrArray::HeapVector &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -6357,23 +6556,23 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::ValueOrArray::HeapVector &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::ValueOrArray::HeapVector &obj, Serializer &serializer) { serde::Serializable::serialize(obj.value, serializer); } template <> template -Circuit::ValueOrArray::HeapVector serde::Deserializable::deserialize(Deserializer &deserializer) { - Circuit::ValueOrArray::HeapVector obj; +Program::ValueOrArray::HeapVector serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::ValueOrArray::HeapVector obj; obj.value = serde::Deserializable::deserialize(deserializer); return obj; } -namespace Circuit { +namespace Program { inline bool operator==(const Witness &lhs, const Witness &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -6395,11 +6594,11 @@ namespace Circuit { return value; } -} // end of namespace Circuit +} // end of namespace Program template <> template -void serde::Serializable::serialize(const Circuit::Witness &obj, Serializer &serializer) { +void serde::Serializable::serialize(const Program::Witness &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -6407,9 +6606,9 @@ void serde::Serializable::serialize(const Circuit::Witness &ob template <> template -Circuit::Witness serde::Deserializable::deserialize(Deserializer &deserializer) { +Program::Witness serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - Circuit::Witness obj; + Program::Witness obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; diff --git a/acvm-repo/acir/codegen/witness.cpp b/acvm-repo/acir/codegen/witness.cpp index 118d4ca7ac5..ad2b0550db2 100644 --- a/acvm-repo/acir/codegen/witness.cpp +++ b/acvm-repo/acir/codegen/witness.cpp @@ -3,7 +3,7 @@ #include "serde.hpp" #include "bincode.hpp" -namespace WitnessMap { +namespace WitnessStack { struct Witness { uint32_t value; @@ -14,17 +14,79 @@ namespace WitnessMap { }; struct WitnessMap { - std::map value; + std::map value; friend bool operator==(const WitnessMap&, const WitnessMap&); std::vector bincodeSerialize() const; static WitnessMap bincodeDeserialize(std::vector); }; -} // end of namespace WitnessMap + struct StackItem { + uint32_t index; + WitnessStack::WitnessMap witness; + friend bool operator==(const StackItem&, const StackItem&); + std::vector bincodeSerialize() const; + static StackItem bincodeDeserialize(std::vector); + }; + + struct WitnessStack { + std::vector stack; + + friend bool operator==(const WitnessStack&, const WitnessStack&); + std::vector bincodeSerialize() const; + static WitnessStack bincodeDeserialize(std::vector); + }; + +} // end of namespace WitnessStack + + +namespace WitnessStack { + + inline bool operator==(const StackItem &lhs, const StackItem &rhs) { + if (!(lhs.index == rhs.index)) { return false; } + if (!(lhs.witness == rhs.witness)) { return false; } + return true; + } + + inline std::vector StackItem::bincodeSerialize() const { + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); + } + + inline StackItem StackItem::bincodeDeserialize(std::vector input) { + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw serde::deserialization_error("Some input bytes were not read"); + } + return value; + } + +} // end of namespace WitnessStack + +template <> +template +void serde::Serializable::serialize(const WitnessStack::StackItem &obj, Serializer &serializer) { + serializer.increase_container_depth(); + serde::Serializable::serialize(obj.index, serializer); + serde::Serializable::serialize(obj.witness, serializer); + serializer.decrease_container_depth(); +} + +template <> +template +WitnessStack::StackItem serde::Deserializable::deserialize(Deserializer &deserializer) { + deserializer.increase_container_depth(); + WitnessStack::StackItem obj; + obj.index = serde::Deserializable::deserialize(deserializer); + obj.witness = serde::Deserializable::deserialize(deserializer); + deserializer.decrease_container_depth(); + return obj; +} -namespace WitnessMap { +namespace WitnessStack { inline bool operator==(const Witness &lhs, const Witness &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -46,11 +108,11 @@ namespace WitnessMap { return value; } -} // end of namespace WitnessMap +} // end of namespace WitnessStack template <> template -void serde::Serializable::serialize(const WitnessMap::Witness &obj, Serializer &serializer) { +void serde::Serializable::serialize(const WitnessStack::Witness &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -58,15 +120,15 @@ void serde::Serializable::serialize(const WitnessMap::Witne template <> template -WitnessMap::Witness serde::Deserializable::deserialize(Deserializer &deserializer) { +WitnessStack::Witness serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - WitnessMap::Witness obj; + WitnessStack::Witness obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } -namespace WitnessMap { +namespace WitnessStack { inline bool operator==(const WitnessMap &lhs, const WitnessMap &rhs) { if (!(lhs.value == rhs.value)) { return false; } @@ -88,11 +150,11 @@ namespace WitnessMap { return value; } -} // end of namespace WitnessMap +} // end of namespace WitnessStack template <> template -void serde::Serializable::serialize(const WitnessMap::WitnessMap &obj, Serializer &serializer) { +void serde::Serializable::serialize(const WitnessStack::WitnessMap &obj, Serializer &serializer) { serializer.increase_container_depth(); serde::Serializable::serialize(obj.value, serializer); serializer.decrease_container_depth(); @@ -100,10 +162,52 @@ void serde::Serializable::serialize(const WitnessMap::Wi template <> template -WitnessMap::WitnessMap serde::Deserializable::deserialize(Deserializer &deserializer) { +WitnessStack::WitnessMap serde::Deserializable::deserialize(Deserializer &deserializer) { deserializer.increase_container_depth(); - WitnessMap::WitnessMap obj; + WitnessStack::WitnessMap obj; obj.value = serde::Deserializable::deserialize(deserializer); deserializer.decrease_container_depth(); return obj; } + +namespace WitnessStack { + + inline bool operator==(const WitnessStack &lhs, const WitnessStack &rhs) { + if (!(lhs.stack == rhs.stack)) { return false; } + return true; + } + + inline std::vector WitnessStack::bincodeSerialize() const { + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); + } + + inline WitnessStack WitnessStack::bincodeDeserialize(std::vector input) { + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw serde::deserialization_error("Some input bytes were not read"); + } + return value; + } + +} // end of namespace WitnessStack + +template <> +template +void serde::Serializable::serialize(const WitnessStack::WitnessStack &obj, Serializer &serializer) { + serializer.increase_container_depth(); + serde::Serializable::serialize(obj.stack, serializer); + serializer.decrease_container_depth(); +} + +template <> +template +WitnessStack::WitnessStack serde::Deserializable::deserialize(Deserializer &deserializer) { + deserializer.increase_container_depth(); + WitnessStack::WitnessStack obj; + obj.stack = serde::Deserializable::deserialize(deserializer); + deserializer.decrease_container_depth(); + return obj; +} diff --git a/acvm-repo/acir/src/circuit/mod.rs b/acvm-repo/acir/src/circuit/mod.rs index 7e6cbf23803..cb846bdaffa 100644 --- a/acvm-repo/acir/src/circuit/mod.rs +++ b/acvm-repo/acir/src/circuit/mod.rs @@ -32,6 +32,13 @@ pub enum ExpressionWidth { }, } +/// A program represented by multiple ACIR circuits. The execution trace of these +/// circuits is dictated by construction of the [crate::native_types::WitnessStack]. +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Default)] +pub struct Program { + pub functions: Vec, +} + #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Default)] pub struct Circuit { // current_witness_index is the highest witness index in the circuit. The next witness to be added to this circuit @@ -152,7 +159,9 @@ impl Circuit { self.public_parameters.0.union(&self.return_values.0).cloned().collect(); PublicInputs(public_inputs) } +} +impl Program { fn write(&self, writer: W) -> std::io::Result<()> { let buf = bincode::serialize(self).unwrap(); let mut encoder = flate2::write::GzEncoder::new(writer, Compression::default()); @@ -169,36 +178,36 @@ impl Circuit { .map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidInput, err)) } - pub fn serialize_circuit(circuit: &Circuit) -> Vec { - let mut circuit_bytes: Vec = Vec::new(); - circuit.write(&mut circuit_bytes).expect("expected circuit to be serializable"); - circuit_bytes + pub fn serialize_program(program: &Program) -> Vec { + let mut program_bytes: Vec = Vec::new(); + program.write(&mut program_bytes).expect("expected circuit to be serializable"); + program_bytes } - pub fn deserialize_circuit(serialized_circuit: &[u8]) -> std::io::Result { - Circuit::read(serialized_circuit) + pub fn deserialize_program(serialized_circuit: &[u8]) -> std::io::Result { + Program::read(serialized_circuit) } - // Serialize and base64 encode circuit - pub fn serialize_circuit_base64(circuit: &Circuit, s: S) -> Result + // Serialize and base64 encode program + pub fn serialize_program_base64(program: &Program, s: S) -> Result where S: Serializer, { - let circuit_bytes = Circuit::serialize_circuit(circuit); - let encoded_b64 = base64::engine::general_purpose::STANDARD.encode(circuit_bytes); + let program_bytes = Program::serialize_program(program); + let encoded_b64 = base64::engine::general_purpose::STANDARD.encode(program_bytes); s.serialize_str(&encoded_b64) } - // Deserialize and base64 decode circuit - pub fn deserialize_circuit_base64<'de, D>(deserializer: D) -> Result + // Deserialize and base64 decode program + pub fn deserialize_program_base64<'de, D>(deserializer: D) -> Result where D: Deserializer<'de>, { let bytecode_b64: String = serde::Deserialize::deserialize(deserializer)?; - let circuit_bytes = base64::engine::general_purpose::STANDARD + let program_bytes = base64::engine::general_purpose::STANDARD .decode(bytecode_b64) .map_err(D::Error::custom)?; - let circuit = Self::deserialize_circuit(&circuit_bytes).map_err(D::Error::custom)?; + let circuit = Self::deserialize_program(&program_bytes).map_err(D::Error::custom)?; Ok(circuit) } } @@ -207,25 +216,33 @@ impl std::fmt::Display for Circuit { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!(f, "current witness index : {}", self.current_witness_index)?; - let write_public_inputs = |f: &mut std::fmt::Formatter<'_>, - public_inputs: &PublicInputs| - -> Result<(), std::fmt::Error> { - write!(f, "[")?; - let public_input_indices = public_inputs.indices(); - for (index, public_input) in public_input_indices.iter().enumerate() { - write!(f, "{public_input}")?; - if index != public_input_indices.len() - 1 { - write!(f, ", ")?; + let write_witness_indices = + |f: &mut std::fmt::Formatter<'_>, indices: &[u32]| -> Result<(), std::fmt::Error> { + write!(f, "[")?; + for (index, witness_index) in indices.iter().enumerate() { + write!(f, "{witness_index}")?; + if index != indices.len() - 1 { + write!(f, ", ")?; + } } - } - writeln!(f, "]") - }; + writeln!(f, "]") + }; + + write!(f, "private parameters indices : ")?; + write_witness_indices( + f, + &self + .private_parameters + .iter() + .map(|witness| witness.witness_index()) + .collect::>(), + )?; write!(f, "public parameters indices : ")?; - write_public_inputs(f, &self.public_parameters)?; + write_witness_indices(f, &self.public_parameters.indices())?; write!(f, "return value indices : ")?; - write_public_inputs(f, &self.return_values)?; + write_witness_indices(f, &self.return_values.indices())?; for opcode in &self.opcodes { writeln!(f, "{opcode}")?; @@ -240,6 +257,22 @@ impl std::fmt::Debug for Circuit { } } +impl std::fmt::Display for Program { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + for (func_index, function) in self.functions.iter().enumerate() { + writeln!(f, "func {}", func_index)?; + writeln!(f, "{}", function)?; + } + Ok(()) + } +} + +impl std::fmt::Debug for Program { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self, f) + } +} + #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)] pub struct PublicInputs(pub BTreeSet); @@ -262,7 +295,10 @@ mod tests { opcodes::{BlackBoxFuncCall, FunctionInput}, Circuit, Compression, Opcode, PublicInputs, }; - use crate::{circuit::ExpressionWidth, native_types::Witness}; + use crate::{ + circuit::{ExpressionWidth, Program}, + native_types::Witness, + }; use acir_field::FieldElement; fn and_opcode() -> Opcode { @@ -348,14 +384,15 @@ mod tests { assert_messages: Default::default(), recursive: false, }; + let program = Program { functions: vec![circuit] }; - fn read_write(circuit: Circuit) -> (Circuit, Circuit) { - let bytes = Circuit::serialize_circuit(&circuit); - let got_circuit = Circuit::deserialize_circuit(&bytes).unwrap(); - (circuit, got_circuit) + fn read_write(program: Program) -> (Program, Program) { + let bytes = Program::serialize_program(&program); + let got_program = Program::deserialize_program(&bytes).unwrap(); + (program, got_program) } - let (circ, got_circ) = read_write(circuit); + let (circ, got_circ) = read_write(program); assert_eq!(circ, got_circ); } @@ -380,11 +417,12 @@ mod tests { assert_messages: Default::default(), recursive: false, }; + let program = Program { functions: vec![circuit] }; - let json = serde_json::to_string_pretty(&circuit).unwrap(); + let json = serde_json::to_string_pretty(&program).unwrap(); let deserialized = serde_json::from_str(&json).unwrap(); - assert_eq!(circuit, deserialized); + assert_eq!(program, deserialized); } #[test] @@ -400,7 +438,7 @@ mod tests { encoder.write_all(bad_circuit).unwrap(); encoder.finish().unwrap(); - let deserialization_result = Circuit::deserialize_circuit(&zipped_bad_circuit); + let deserialization_result = Program::deserialize_program(&zipped_bad_circuit); assert!(deserialization_result.is_err()); } } diff --git a/acvm-repo/acir/src/circuit/opcodes.rs b/acvm-repo/acir/src/circuit/opcodes.rs index f725ba8c32a..68d28b287e6 100644 --- a/acvm-repo/acir/src/circuit/opcodes.rs +++ b/acvm-repo/acir/src/circuit/opcodes.rs @@ -29,6 +29,17 @@ pub enum Opcode { block_id: BlockId, init: Vec, }, + /// Calls to functions represented as a separate circuit. A call opcode allows us + /// to build a call stack when executing the outer-most circuit. + Call { + /// Id for the function being called. It is the responsibility of the executor + /// to fetch the appropriate circuit from this id. + id: u32, + /// Inputs to the function call + inputs: Vec, + /// Outputs of the function call + outputs: Vec, + }, } impl std::fmt::Display for Opcode { @@ -86,6 +97,11 @@ impl std::fmt::Display for Opcode { write!(f, "INIT ")?; write!(f, "(id: {}, len: {}) ", block_id.0, init.len()) } + Opcode::Call { id, inputs, outputs } => { + write!(f, "CALL func {}: ", id)?; + write!(f, "inputs: {:?}, ", inputs)?; + write!(f, "outputs: {:?}", outputs) + } } } } diff --git a/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs b/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs index f73417a4b5b..c955e435b37 100644 --- a/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs +++ b/acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs @@ -10,12 +10,6 @@ pub struct FunctionInput { pub num_bits: u32, } -impl FunctionInput { - pub fn dummy() -> Self { - Self { witness: Witness(0), num_bits: 0 } - } -} - #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum BlackBoxFuncCall { AND { @@ -217,8 +211,10 @@ impl BlackBoxFuncCall { | BlackBoxFuncCall::PedersenCommitment { inputs, .. } | BlackBoxFuncCall::PedersenHash { inputs, .. } | BlackBoxFuncCall::BigIntFromLeBytes { inputs, .. } - | BlackBoxFuncCall::Poseidon2Permutation { inputs, .. } - | BlackBoxFuncCall::Sha256Compression { inputs, .. } => inputs.to_vec(), + | BlackBoxFuncCall::Poseidon2Permutation { inputs, .. } => inputs.to_vec(), + BlackBoxFuncCall::Sha256Compression { inputs, hash_values, .. } => { + inputs.iter().chain(hash_values).copied().collect() + } BlackBoxFuncCall::AND { lhs, rhs, .. } | BlackBoxFuncCall::XOR { lhs, rhs, .. } => { vec![*lhs, *rhs] } diff --git a/acvm-repo/acir/src/lib.rs b/acvm-repo/acir/src/lib.rs index c7be5026850..d14159f34a1 100644 --- a/acvm-repo/acir/src/lib.rs +++ b/acvm-repo/acir/src/lib.rs @@ -42,9 +42,9 @@ mod reflection { brillig::{BrilligInputs, BrilligOutputs}, directives::Directive, opcodes::BlackBoxFuncCall, - Circuit, ExpressionWidth, Opcode, OpcodeLocation, + Circuit, ExpressionWidth, Opcode, OpcodeLocation, Program, }, - native_types::{Witness, WitnessMap}, + native_types::{Witness, WitnessMap, WitnessStack}, }; #[test] @@ -59,6 +59,7 @@ mod reflection { }; let mut tracer = Tracer::new(TracerConfig::default()); + tracer.trace_simple_type::().unwrap(); tracer.trace_simple_type::().unwrap(); tracer.trace_simple_type::().unwrap(); tracer.trace_simple_type::().unwrap(); @@ -78,7 +79,7 @@ mod reflection { // Create C++ class definitions. let mut source = Vec::new(); - let config = serde_generate::CodeGeneratorConfig::new("Circuit".to_string()) + let config = serde_generate::CodeGeneratorConfig::new("Program".to_string()) .with_encodings(vec![serde_generate::Encoding::Bincode]); let generator = serde_generate::cpp::CodeGenerator::new(&config); generator.output(&mut source, ®istry).unwrap(); @@ -106,12 +107,13 @@ mod reflection { let mut tracer = Tracer::new(TracerConfig::default()); tracer.trace_simple_type::().unwrap(); tracer.trace_simple_type::().unwrap(); + tracer.trace_simple_type::().unwrap(); let registry = tracer.registry().unwrap(); // Create C++ class definitions. let mut source = Vec::new(); - let config = serde_generate::CodeGeneratorConfig::new("WitnessMap".to_string()) + let config = serde_generate::CodeGeneratorConfig::new("WitnessStack".to_string()) .with_encodings(vec![serde_generate::Encoding::Bincode]); let generator = serde_generate::cpp::CodeGenerator::new(&config); generator.output(&mut source, ®istry).unwrap(); diff --git a/acvm-repo/acir/src/native_types/mod.rs b/acvm-repo/acir/src/native_types/mod.rs index 66c822bfff8..eb9d1f6fd03 100644 --- a/acvm-repo/acir/src/native_types/mod.rs +++ b/acvm-repo/acir/src/native_types/mod.rs @@ -1,8 +1,10 @@ mod expression; mod witness; mod witness_map; +mod witness_stack; pub use expression::Expression; pub use witness::Witness; pub use witness_map::WitnessMap; -pub use witness_map::WitnessMapError; +pub use witness_stack::WitnessStack; +pub use witness_stack::WitnessStackError; diff --git a/acvm-repo/acir/src/native_types/witness_stack.rs b/acvm-repo/acir/src/native_types/witness_stack.rs new file mode 100644 index 00000000000..7c79e3db431 --- /dev/null +++ b/acvm-repo/acir/src/native_types/witness_stack.rs @@ -0,0 +1,82 @@ +use std::io::Read; + +use flate2::bufread::GzDecoder; +use flate2::bufread::GzEncoder; +use flate2::Compression; +use serde::{Deserialize, Serialize}; +use thiserror::Error; + +use super::WitnessMap; + +#[derive(Debug, Error)] +enum SerializationError { + #[error(transparent)] + Deflate(#[from] std::io::Error), +} + +#[derive(Debug, Error)] +#[error(transparent)] +pub struct WitnessStackError(#[from] SerializationError); + +/// An ordered set of witness maps for separate circuits +#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Serialize, Deserialize)] +pub struct WitnessStack { + stack: Vec, +} + +#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Serialize, Deserialize)] +pub struct StackItem { + /// Index into a [crate::circuit::Program] function list for which we have an associated witness + pub index: u32, + /// A full witness for the respective constraint system specified by the index + pub witness: WitnessMap, +} + +impl WitnessStack { + pub fn push(&mut self, index: u32, witness: WitnessMap) { + self.stack.push(StackItem { index, witness }); + } + + pub fn pop(&mut self) -> Option { + self.stack.pop() + } + + pub fn peek(&self) -> Option<&StackItem> { + self.stack.last() + } + + pub fn length(&self) -> usize { + self.stack.len() + } +} + +impl From for WitnessStack { + fn from(witness: WitnessMap) -> Self { + let stack = vec![StackItem { index: 0, witness }]; + Self { stack } + } +} + +impl TryFrom for Vec { + type Error = WitnessStackError; + + fn try_from(val: WitnessStack) -> Result { + let buf = bincode::serialize(&val).unwrap(); + let mut deflater = GzEncoder::new(buf.as_slice(), Compression::best()); + let mut buf_c = Vec::new(); + deflater.read_to_end(&mut buf_c).map_err(|err| WitnessStackError(err.into()))?; + Ok(buf_c) + } +} + +impl TryFrom<&[u8]> for WitnessStack { + type Error = WitnessStackError; + + fn try_from(bytes: &[u8]) -> Result { + let mut deflater = GzDecoder::new(bytes); + let mut buf_d = Vec::new(); + deflater.read_to_end(&mut buf_d).map_err(|err| WitnessStackError(err.into()))?; + let witness_stack = bincode::deserialize(&buf_d).unwrap(); + Ok(witness_stack) + } +} diff --git a/acvm-repo/acir/tests/test_program_serialization.rs b/acvm-repo/acir/tests/test_program_serialization.rs index 2c8ad2b9986..a5b683c15e1 100644 --- a/acvm-repo/acir/tests/test_program_serialization.rs +++ b/acvm-repo/acir/tests/test_program_serialization.rs @@ -1,13 +1,13 @@ //! This integration test defines a set of circuits which are used in order to test the acvm_js package. //! -//! The acvm_js test suite contains serialized [circuits][`Circuit`] which must be kept in sync with the format +//! The acvm_js test suite contains serialized program [circuits][`Program`] which must be kept in sync with the format //! outputted from the [ACIR crate][acir]. //! Breaking changes to the serialization format then require refreshing acvm_js's test suite. //! This file contains Rust definitions of these circuits and outputs the updated serialized format. //! //! These tests also check this circuit serialization against an expected value, erroring if the serialization changes. //! Generally in this situation we just need to refresh the `expected_serialization` variables to match the -//! actual output, **HOWEVER** note that this results in a breaking change to the ACIR format. +//! actual output, **HOWEVER** note that this results in a breaking change to the backend ACIR format. use std::collections::BTreeSet; @@ -15,7 +15,7 @@ use acir::{ circuit::{ brillig::{Brillig, BrilligInputs, BrilligOutputs}, opcodes::{BlackBoxFuncCall, BlockId, FunctionInput, MemOp}, - Circuit, Opcode, PublicInputs, + Circuit, Opcode, Program, PublicInputs, }, native_types::{Expression, Witness}, }; @@ -41,16 +41,17 @@ fn addition_circuit() { return_values: PublicInputs([Witness(3)].into()), ..Circuit::default() }; + let program = Program { functions: vec![circuit] }; - let bytes = Circuit::serialize_circuit(&circuit); + let bytes = Program::serialize_program(&program); let expected_serialization: Vec = vec![ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 208, 49, 14, 192, 32, 8, 5, 80, 212, 30, 8, 4, 20, - 182, 94, 165, 166, 122, 255, 35, 52, 77, 28, 76, 58, 214, 191, 124, 166, 23, 242, 15, 0, 8, - 240, 77, 154, 125, 206, 198, 127, 161, 176, 209, 138, 139, 197, 88, 68, 122, 205, 157, 152, - 46, 204, 222, 76, 81, 180, 21, 35, 35, 53, 189, 179, 49, 119, 19, 171, 222, 188, 162, 147, - 112, 167, 161, 206, 99, 98, 105, 223, 95, 248, 26, 113, 90, 97, 185, 97, 217, 56, 173, 35, - 63, 243, 81, 87, 163, 125, 1, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 144, 75, 14, 128, 32, 12, 68, 249, 120, 160, 150, + 182, 208, 238, 188, 138, 68, 184, 255, 17, 212, 200, 130, 196, 165, 188, 164, 153, 174, 94, + 38, 227, 221, 203, 118, 159, 119, 95, 226, 200, 125, 36, 252, 3, 253, 66, 87, 152, 92, 4, + 153, 185, 149, 212, 144, 240, 128, 100, 85, 5, 88, 106, 86, 84, 20, 149, 51, 41, 81, 83, + 214, 98, 213, 10, 24, 50, 53, 236, 98, 212, 135, 44, 174, 235, 5, 143, 35, 12, 151, 159, + 126, 55, 109, 28, 231, 145, 47, 245, 105, 191, 143, 133, 1, 0, 0, ]; assert_eq!(bytes, expected_serialization) @@ -71,13 +72,14 @@ fn fixed_base_scalar_mul_circuit() { return_values: PublicInputs(BTreeSet::from_iter(vec![Witness(3), Witness(4)])), ..Circuit::default() }; + let program = Program { functions: vec![circuit] }; - let bytes = Circuit::serialize_circuit(&circuit); + let bytes = Program::serialize_program(&program); let expected_serialization: Vec = vec![ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 138, 91, 10, 0, 32, 16, 2, 109, 171, 175, 46, 221, - 209, 247, 229, 130, 130, 140, 200, 92, 0, 11, 157, 228, 35, 127, 212, 200, 29, 61, 116, 76, - 220, 217, 250, 171, 91, 113, 160, 66, 104, 242, 97, 0, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 138, 81, 10, 0, 48, 8, 66, 87, 219, 190, 118, 233, + 29, 61, 43, 3, 5, 121, 34, 207, 86, 231, 162, 198, 157, 124, 228, 71, 157, 220, 232, 161, + 227, 226, 206, 214, 95, 221, 74, 0, 116, 58, 13, 182, 105, 0, 0, 0, ]; assert_eq!(bytes, expected_serialization) @@ -98,13 +100,14 @@ fn pedersen_circuit() { return_values: PublicInputs(BTreeSet::from_iter(vec![Witness(2), Witness(3)])), ..Circuit::default() }; + let program = Program { functions: vec![circuit] }; - let bytes = Circuit::serialize_circuit(&circuit); + let bytes = Program::serialize_program(&program); let expected_serialization: Vec = vec![ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 74, 135, 9, 0, 48, 8, 75, 171, 224, 255, 15, 139, - 27, 196, 64, 200, 100, 0, 15, 133, 80, 57, 89, 219, 127, 39, 173, 126, 235, 236, 247, 151, - 48, 224, 71, 90, 33, 97, 0, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 74, 7, 6, 0, 0, 8, 108, 209, 255, 63, 156, 54, 233, + 56, 55, 17, 26, 18, 196, 241, 169, 250, 178, 141, 167, 32, 159, 254, 234, 238, 255, 87, + 112, 52, 63, 63, 101, 105, 0, 0, 0, ]; assert_eq!(bytes, expected_serialization) @@ -139,26 +142,27 @@ fn schnorr_verify_circuit() { return_values: PublicInputs(BTreeSet::from([output])), ..Circuit::default() }; + let program = Program { functions: vec![circuit] }; - let bytes = Circuit::serialize_circuit(&circuit); + let bytes = Program::serialize_program(&program); let expected_serialization: Vec = vec![ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 210, 7, 74, 3, 1, 20, 69, 209, 177, 247, 222, 123, - 239, 189, 119, 141, 93, 99, 220, 133, 251, 95, 130, 152, 103, 78, 32, 3, 195, 33, 4, 66, - 248, 239, 254, 20, 69, 209, 84, 212, 158, 216, 206, 223, 234, 219, 204, 146, 239, 91, 170, - 111, 103, 245, 109, 101, 27, 219, 217, 193, 250, 219, 197, 110, 246, 176, 151, 125, 236, - 231, 0, 7, 57, 196, 97, 142, 112, 148, 99, 28, 231, 4, 39, 57, 197, 105, 206, 112, 150, - 115, 156, 231, 2, 23, 185, 196, 101, 174, 112, 149, 107, 92, 231, 6, 55, 185, 197, 109, - 238, 112, 151, 123, 220, 231, 1, 15, 121, 196, 99, 158, 240, 148, 103, 60, 231, 5, 47, 121, - 197, 107, 222, 240, 150, 119, 188, 231, 3, 75, 124, 228, 83, 195, 142, 121, 158, 125, 126, - 225, 43, 223, 248, 206, 15, 126, 178, 204, 47, 86, 248, 237, 119, 43, 76, 127, 105, 47, - 189, 165, 181, 116, 150, 198, 234, 125, 117, 249, 47, 233, 41, 45, 165, 163, 52, 148, 126, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 210, 7, 78, 2, 1, 20, 69, 81, 236, 189, 247, 222, + 123, 239, 93, 177, 33, 34, 238, 194, 253, 47, 193, 200, 147, 67, 194, 36, 147, 163, 33, 33, + 228, 191, 219, 82, 168, 63, 63, 181, 183, 197, 223, 177, 147, 191, 181, 183, 149, 69, 159, + 183, 213, 222, 238, 218, 219, 206, 14, 118, 178, 139, 141, 183, 135, 189, 236, 99, 63, 7, + 56, 200, 33, 14, 115, 132, 163, 28, 227, 56, 39, 56, 201, 41, 78, 115, 134, 179, 156, 227, + 60, 23, 184, 200, 37, 46, 115, 133, 171, 92, 227, 58, 55, 184, 201, 45, 110, 115, 135, 187, + 220, 227, 62, 15, 120, 200, 35, 30, 243, 132, 167, 60, 227, 57, 47, 120, 201, 43, 94, 243, + 134, 183, 188, 227, 61, 31, 248, 200, 39, 22, 249, 204, 151, 166, 29, 243, 188, 250, 255, + 141, 239, 44, 241, 131, 101, 126, 178, 194, 47, 86, 249, 237, 123, 171, 76, 127, 105, 47, + 189, 165, 181, 116, 150, 198, 26, 125, 245, 248, 45, 233, 41, 45, 165, 163, 52, 148, 126, 210, 78, 186, 73, 51, 233, 37, 173, 164, 147, 52, 146, 62, 210, 70, 186, 72, 19, 233, 33, - 45, 164, 131, 52, 144, 253, 23, 139, 218, 238, 217, 60, 123, 103, 235, 236, 156, 141, 179, - 239, 166, 93, 183, 237, 185, 107, 199, 125, 251, 29, 218, 237, 216, 94, 167, 118, 58, 183, - 207, 165, 93, 174, 237, 113, 107, 135, 123, 247, 47, 185, 251, 147, 59, 191, 184, 239, 155, - 187, 126, 184, 103, 217, 29, 235, 55, 171, 223, 173, 104, 184, 231, 255, 243, 7, 236, 52, - 239, 128, 225, 3, 0, 0, + 45, 164, 131, 52, 144, 253, 151, 11, 245, 221, 179, 121, 246, 206, 214, 217, 57, 27, 103, + 223, 109, 187, 238, 218, 115, 223, 142, 135, 246, 59, 182, 219, 169, 189, 206, 237, 116, + 105, 159, 107, 187, 220, 218, 227, 222, 14, 143, 238, 95, 116, 247, 23, 119, 126, 115, 223, + 146, 187, 150, 221, 179, 226, 142, 141, 155, 53, 238, 86, 104, 186, 231, 255, 243, 7, 100, + 141, 232, 192, 233, 3, 0, 0, ]; assert_eq!(bytes, expected_serialization) @@ -186,9 +190,9 @@ fn simple_brillig_foreign_call() { brillig::Opcode::ForeignCall { function: "invert".into(), destinations: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(0))], - destination_value_types: vec![HeapValueType::Simple], + destination_value_types: vec![HeapValueType::field()], inputs: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(0))], - input_value_types: vec![HeapValueType::Simple], + input_value_types: vec![HeapValueType::field()], }, brillig::Opcode::Stop { return_data_offset: 0, return_data_size: 1 }, ], @@ -202,15 +206,16 @@ fn simple_brillig_foreign_call() { private_parameters: BTreeSet::from([Witness(1), Witness(2)]), ..Circuit::default() }; + let program = Program { functions: vec![circuit] }; - let bytes = Circuit::serialize_circuit(&circuit); + let bytes = Program::serialize_program(&program); let expected_serialization: Vec = vec![ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 143, 177, 10, 192, 32, 16, 67, 227, 21, 74, 233, - 212, 79, 177, 127, 208, 159, 233, 224, 226, 32, 226, 247, 139, 168, 16, 68, 93, 244, 45, - 119, 228, 142, 144, 92, 0, 20, 50, 7, 237, 76, 213, 190, 50, 245, 26, 175, 218, 231, 165, - 57, 175, 148, 14, 137, 179, 147, 191, 114, 211, 221, 216, 240, 59, 63, 107, 221, 115, 104, - 181, 103, 244, 43, 36, 10, 38, 68, 108, 25, 253, 238, 136, 1, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 144, 61, 10, 192, 48, 8, 133, 53, 133, 82, 186, + 245, 38, 233, 13, 122, 153, 14, 93, 58, 132, 144, 227, 135, 252, 41, 56, 36, 46, 201, 7, + 162, 168, 200, 123, 34, 52, 142, 28, 72, 245, 38, 106, 9, 247, 30, 202, 118, 142, 27, 215, + 221, 178, 82, 175, 33, 15, 133, 189, 163, 159, 57, 197, 252, 251, 195, 235, 188, 230, 186, + 16, 65, 255, 12, 239, 92, 131, 89, 149, 198, 77, 3, 10, 9, 119, 8, 198, 242, 152, 1, 0, 0, ]; assert_eq!(bytes, expected_serialization) @@ -259,8 +264,8 @@ fn complex_brillig_foreign_call() { }, brillig::Opcode::Const { destination: MemoryAddress(0), - value: brillig::Value::from(32_usize), - bit_size: 32, + value: FieldElement::from(32_usize), + bit_size: 64, }, brillig::Opcode::CalldataCopy { destination_address: MemoryAddress(1), @@ -275,8 +280,8 @@ fn complex_brillig_foreign_call() { ValueOrArray::MemoryAddress(MemoryAddress::from(1)), ], input_value_types: vec![ - HeapValueType::Array { size: 3, value_types: vec![HeapValueType::Simple] }, - HeapValueType::Simple, + HeapValueType::Array { size: 3, value_types: vec![HeapValueType::field()] }, + HeapValueType::field(), ], destinations: vec![ ValueOrArray::HeapArray(HeapArray { pointer: 0.into(), size: 3 }), @@ -284,9 +289,9 @@ fn complex_brillig_foreign_call() { ValueOrArray::MemoryAddress(MemoryAddress::from(36)), ], destination_value_types: vec![ - HeapValueType::Array { size: 3, value_types: vec![HeapValueType::Simple] }, - HeapValueType::Simple, - HeapValueType::Simple, + HeapValueType::Array { size: 3, value_types: vec![HeapValueType::field()] }, + HeapValueType::field(), + HeapValueType::field(), ], }, brillig::Opcode::Stop { return_data_offset: 32, return_data_size: 5 }, @@ -301,19 +306,20 @@ fn complex_brillig_foreign_call() { private_parameters: BTreeSet::from([Witness(1), Witness(2), Witness(3)]), ..Circuit::default() }; + let program = Program { functions: vec![circuit] }; - let bytes = Circuit::serialize_circuit(&circuit); + let bytes = Program::serialize_program(&program); let expected_serialization: Vec = vec![ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 84, 75, 10, 132, 48, 12, 125, 177, 163, 35, 179, - 154, 35, 8, 51, 7, 232, 204, 9, 188, 139, 184, 83, 116, 233, 241, 173, 152, 98, 12, 213, - 141, 21, 244, 65, 232, 39, 175, 233, 35, 73, 155, 3, 32, 204, 48, 206, 18, 158, 19, 175, - 37, 60, 175, 228, 209, 30, 195, 143, 226, 197, 178, 103, 105, 76, 110, 160, 209, 156, 160, - 209, 247, 195, 69, 235, 29, 179, 46, 81, 243, 103, 2, 239, 231, 225, 44, 117, 150, 241, - 250, 201, 99, 206, 251, 96, 95, 161, 242, 14, 193, 243, 40, 162, 105, 253, 219, 12, 75, 47, - 146, 186, 251, 37, 116, 86, 93, 219, 55, 245, 96, 20, 85, 75, 253, 136, 249, 87, 249, 105, - 231, 220, 4, 249, 237, 132, 56, 20, 224, 109, 113, 223, 88, 82, 153, 34, 64, 34, 14, 164, - 69, 172, 48, 2, 23, 243, 6, 31, 25, 5, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 84, 93, 10, 131, 48, 12, 78, 218, 233, 100, 111, + 187, 193, 96, 59, 64, 231, 9, 188, 139, 248, 166, 232, 163, 167, 23, 11, 126, 197, 24, 250, + 34, 86, 208, 64, 72, 218, 252, 125, 36, 105, 153, 22, 42, 60, 51, 116, 235, 217, 64, 103, + 156, 37, 5, 191, 10, 210, 29, 163, 63, 167, 203, 229, 206, 194, 104, 110, 128, 209, 158, + 128, 49, 236, 195, 69, 231, 157, 114, 46, 73, 251, 103, 35, 239, 231, 225, 57, 243, 156, + 227, 252, 132, 44, 112, 79, 176, 125, 84, 223, 73, 248, 145, 152, 69, 149, 4, 107, 233, + 114, 90, 119, 145, 85, 237, 151, 192, 89, 247, 221, 208, 54, 163, 85, 174, 26, 234, 87, + 232, 63, 101, 103, 21, 55, 169, 216, 73, 72, 249, 5, 197, 234, 132, 123, 179, 35, 247, 155, + 214, 246, 102, 20, 73, 204, 72, 168, 123, 191, 161, 25, 66, 136, 159, 187, 53, 5, 0, 0, ]; assert_eq!(bytes, expected_serialization) @@ -342,14 +348,110 @@ fn memory_op_circuit() { return_values: PublicInputs([Witness(4)].into()), ..Circuit::default() }; - let bytes = Circuit::serialize_circuit(&circuit); + let program = Program { functions: vec![circuit] }; + + let bytes = Program::serialize_program(&program); let expected_serialization: Vec = vec![ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 145, 187, 17, 0, 32, 8, 67, 195, 111, 31, 220, 192, - 253, 167, 178, 144, 2, 239, 236, 132, 194, 52, 129, 230, 93, 8, 6, 64, 176, 101, 225, 28, - 78, 49, 43, 238, 154, 225, 254, 166, 209, 205, 165, 98, 174, 212, 177, 188, 187, 92, 255, - 173, 92, 173, 190, 93, 82, 80, 78, 123, 14, 127, 60, 97, 1, 210, 144, 46, 242, 19, 3, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 81, 201, 13, 0, 32, 8, 147, 195, 125, 112, 3, 247, + 159, 74, 141, 60, 106, 226, 79, 120, 216, 132, 180, 124, 154, 82, 168, 108, 212, 57, 2, + 122, 129, 157, 201, 181, 150, 59, 186, 179, 189, 161, 101, 251, 82, 176, 175, 196, 121, 89, + 118, 185, 246, 91, 185, 26, 125, 187, 64, 80, 134, 29, 195, 31, 79, 24, 2, 250, 167, 252, + 27, 3, 0, 0, ]; assert_eq!(bytes, expected_serialization) } + +#[test] +fn nested_acir_call_circuit() { + // Circuit for the following program: + // fn main(x: Field, y: pub Field) { + // let z = nested_call(x, y); + // let z2 = nested_call(x, y); + // assert(z == z2); + // } + // #[fold] + // fn nested_call(x: Field, y: Field) -> Field { + // inner_call(x + 2, y) + // } + // #[fold] + // fn inner_call(x: Field, y: Field) -> Field { + // assert(x == y); + // x + // } + let nested_call = + Opcode::Call { id: 1, inputs: vec![Witness(0), Witness(1)], outputs: vec![Witness(2)] }; + let nested_call_two = + Opcode::Call { id: 1, inputs: vec![Witness(0), Witness(1)], outputs: vec![Witness(3)] }; + + let assert_nested_call_results = Opcode::AssertZero(Expression { + mul_terms: Vec::new(), + linear_combinations: vec![ + (FieldElement::one(), Witness(2)), + (-FieldElement::one(), Witness(3)), + ], + q_c: FieldElement::zero(), + }); + + let main = Circuit { + current_witness_index: 3, + private_parameters: BTreeSet::from([Witness(0)]), + public_parameters: PublicInputs([Witness(1)].into()), + opcodes: vec![nested_call, nested_call_two, assert_nested_call_results], + ..Circuit::default() + }; + + let call_parameter_addition = Opcode::AssertZero(Expression { + mul_terms: Vec::new(), + linear_combinations: vec![ + (FieldElement::one(), Witness(0)), + (-FieldElement::one(), Witness(2)), + ], + q_c: FieldElement::one() + FieldElement::one(), + }); + let call = + Opcode::Call { id: 2, inputs: vec![Witness(2), Witness(1)], outputs: vec![Witness(3)] }; + + let nested_call = Circuit { + current_witness_index: 3, + private_parameters: BTreeSet::from([Witness(0), Witness(1)]), + return_values: PublicInputs([Witness(3)].into()), + opcodes: vec![call_parameter_addition, call], + ..Circuit::default() + }; + + let assert_param_equality = Opcode::AssertZero(Expression { + mul_terms: Vec::new(), + linear_combinations: vec![ + (FieldElement::one(), Witness(0)), + (-FieldElement::one(), Witness(1)), + ], + q_c: FieldElement::zero(), + }); + + let inner_call = Circuit { + current_witness_index: 1, + private_parameters: BTreeSet::from([Witness(0), Witness(1)]), + return_values: PublicInputs([Witness(0)].into()), + opcodes: vec![assert_param_equality], + ..Circuit::default() + }; + + let program = Program { functions: vec![main, nested_call, inner_call] }; + + let bytes = Program::serialize_program(&program); + + let expected_serialization: Vec = vec![ + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 205, 146, 97, 10, 195, 32, 12, 133, 163, 66, 207, 147, + 24, 109, 227, 191, 93, 101, 50, 123, 255, 35, 172, 99, 25, 83, 17, 250, 99, 14, 250, 224, + 97, 144, 16, 146, 143, 231, 224, 45, 167, 126, 105, 57, 108, 14, 91, 248, 202, 168, 65, + 255, 207, 122, 28, 180, 250, 244, 221, 244, 197, 223, 68, 182, 154, 197, 184, 134, 80, 54, + 95, 136, 233, 142, 62, 101, 137, 24, 98, 94, 133, 132, 162, 196, 135, 23, 230, 34, 65, 182, + 148, 211, 134, 137, 2, 23, 218, 99, 226, 93, 135, 185, 121, 123, 33, 84, 12, 234, 218, 192, + 64, 174, 3, 248, 47, 88, 48, 17, 150, 157, 183, 151, 95, 244, 86, 91, 221, 61, 10, 81, 31, + 178, 190, 110, 194, 102, 96, 76, 251, 202, 80, 13, 204, 77, 224, 25, 176, 70, 79, 197, 128, + 18, 64, 3, 4, 0, 0, + ]; + assert_eq!(bytes, expected_serialization); +} diff --git a/acvm-repo/acir_field/Cargo.toml b/acvm-repo/acir_field/Cargo.toml index 6f4971770bd..d63a885bfd8 100644 --- a/acvm-repo/acir_field/Cargo.toml +++ b/acvm-repo/acir_field/Cargo.toml @@ -2,7 +2,7 @@ name = "acir_field" description = "The field implementation being used by ACIR." # x-release-please-start-version -version = "0.40.0" +version = "0.42.0" # x-release-please-end authors.workspace = true edition.workspace = true diff --git a/acvm-repo/acvm/Cargo.toml b/acvm-repo/acvm/Cargo.toml index fce9a8e8e8b..d0ea52e859d 100644 --- a/acvm-repo/acvm/Cargo.toml +++ b/acvm-repo/acvm/Cargo.toml @@ -2,7 +2,7 @@ name = "acvm" description = "The virtual machine that processes ACIR given a backend/proof system." # x-release-please-start-version -version = "0.40.0" +version = "0.42.0" # x-release-please-end authors.workspace = true edition.workspace = true diff --git a/acvm-repo/acvm/src/compiler/optimizers/constant_backpropagation.rs b/acvm-repo/acvm/src/compiler/optimizers/constant_backpropagation.rs new file mode 100644 index 00000000000..0e7d28104da --- /dev/null +++ b/acvm-repo/acvm/src/compiler/optimizers/constant_backpropagation.rs @@ -0,0 +1,331 @@ +use std::collections::{BTreeMap, BTreeSet, HashMap}; + +use crate::{ + compiler::optimizers::GeneralOptimizer, + pwg::{ + arithmetic::ExpressionSolver, blackbox::solve_range_opcode, directives::solve_directives, + BrilligSolver, BrilligSolverStatus, + }, +}; +use acir::{ + circuit::{ + brillig::{Brillig, BrilligInputs, BrilligOutputs}, + directives::Directive, + opcodes::BlackBoxFuncCall, + Circuit, Opcode, + }, + native_types::{Expression, Witness, WitnessMap}, +}; +use acvm_blackbox_solver::StubbedBlackBoxSolver; + +/// `ConstantBackpropagationOptimizer` will attempt to determine any constant witnesses within the program. +/// It does this by attempting to solve the program without any inputs (i.e. using an empty witness map), +/// any values which it can determine are then enforced to be constant values. +/// +/// The optimizer will then replace any witnesses wherever they appear within the circuit with these constant values. +/// This is repeated until the circuit stabilizes. +pub(crate) struct ConstantBackpropagationOptimizer { + circuit: Circuit, +} + +impl ConstantBackpropagationOptimizer { + /// Creates a new `ConstantBackpropagationOptimizer` + pub(crate) fn new(circuit: Circuit) -> Self { + Self { circuit } + } + + fn gather_known_witnesses(&self) -> (WitnessMap, BTreeSet) { + // We do not want to affect the circuit's interface so avoid optimizing away these witnesses. + let mut required_witnesses: BTreeSet = self + .circuit + .private_parameters + .union(&self.circuit.public_parameters.0) + .chain(&self.circuit.return_values.0) + .copied() + .collect(); + + for opcode in &self.circuit.opcodes { + match &opcode { + Opcode::BlackBoxFuncCall(func_call) => { + required_witnesses.extend( + func_call.get_inputs_vec().into_iter().map(|func_input| func_input.witness), + ); + required_witnesses.extend(func_call.get_outputs_vec()); + } + + Opcode::MemoryInit { init, .. } => { + required_witnesses.extend(init); + } + + Opcode::MemoryOp { op, .. } => { + required_witnesses.insert(op.index.to_witness().unwrap()); + required_witnesses.insert(op.value.to_witness().unwrap()); + } + + _ => (), + }; + } + + let mut known_witnesses = WitnessMap::new(); + for opcode in self.circuit.opcodes.iter().rev() { + if let Opcode::AssertZero(expr) = opcode { + let solve_result = ExpressionSolver::solve(&mut known_witnesses, expr); + // It doesn't matter what the result is. We expect most opcodes to not be solved successfully so we discard errors. + // At the same time, if the expression can be solved then we track this by the updates to `known_witnesses` + drop(solve_result); + } + } + + // We want to retain any references to required witnesses so we "forget" these assignments. + let known_witnesses: BTreeMap<_, _> = known_witnesses + .into_iter() + .filter(|(witness, _)| !required_witnesses.contains(witness)) + .collect(); + + (known_witnesses.into(), required_witnesses) + } + + /// Returns a `Circuit` where with any constant witnesses replaced with the constant they resolve to. + #[tracing::instrument(level = "trace", skip_all)] + pub(crate) fn backpropagate_constants( + circuit: Circuit, + order_list: Vec, + ) -> (Circuit, Vec) { + let old_circuit_size = circuit.opcodes.len(); + + let optimizer = Self::new(circuit); + let (circuit, order_list) = optimizer.backpropagate_constants_iteration(order_list); + + let new_circuit_size = circuit.opcodes.len(); + if new_circuit_size < old_circuit_size { + Self::backpropagate_constants(circuit, order_list) + } else { + (circuit, order_list) + } + } + + /// Applies a single round of constant backpropagation to a `Circuit`. + pub(crate) fn backpropagate_constants_iteration( + mut self, + order_list: Vec, + ) -> (Circuit, Vec) { + let (mut known_witnesses, required_witnesses) = self.gather_known_witnesses(); + + let opcodes = std::mem::take(&mut self.circuit.opcodes); + + fn remap_expression(known_witnesses: &WitnessMap, expression: Expression) -> Expression { + GeneralOptimizer::optimize(ExpressionSolver::evaluate(&expression, known_witnesses)) + } + + let mut new_order_list = Vec::with_capacity(order_list.len()); + let mut new_opcodes = Vec::with_capacity(opcodes.len()); + for (idx, opcode) in opcodes.into_iter().enumerate() { + let new_opcode = match opcode { + Opcode::AssertZero(expression) => { + let new_expr = remap_expression(&known_witnesses, expression); + if new_expr.is_zero() { + continue; + } + + // Attempt to solve the opcode to see if we can determine the value of any witnesses in the expression. + // We only do this _after_ we apply any simplifications to create the new opcode as we want to + // keep the constraint on the witness which we are solving for here. + let solve_result = ExpressionSolver::solve(&mut known_witnesses, &new_expr); + // It doesn't matter what the result is. We expect most opcodes to not be solved successfully so we discard errors. + // At the same time, if the expression can be solved then we track this by the updates to `known_witnesses` + drop(solve_result); + + Opcode::AssertZero(new_expr) + } + Opcode::Brillig(brillig) => { + let remapped_inputs = brillig + .inputs + .into_iter() + .map(|input| match input { + BrilligInputs::Single(expr) => { + BrilligInputs::Single(remap_expression(&known_witnesses, expr)) + } + BrilligInputs::Array(expr_array) => { + let new_input: Vec<_> = expr_array + .into_iter() + .map(|expr| remap_expression(&known_witnesses, expr)) + .collect(); + + BrilligInputs::Array(new_input) + } + input @ BrilligInputs::MemoryArray(_) => input, + }) + .collect(); + + let remapped_predicate = brillig + .predicate + .map(|predicate| remap_expression(&known_witnesses, predicate)); + + let new_brillig = Brillig { + inputs: remapped_inputs, + predicate: remapped_predicate, + ..brillig + }; + + let brillig_output_is_required_witness = + new_brillig.outputs.iter().any(|output| match output { + BrilligOutputs::Simple(witness) => required_witnesses.contains(witness), + BrilligOutputs::Array(witness_array) => witness_array + .iter() + .any(|witness| required_witnesses.contains(witness)), + }); + + if brillig_output_is_required_witness { + // If one of the brillig opcode's outputs is a required witness then we can't remove the opcode. In this case we can't replace + // all of the uses of this witness with the calculated constant so we'll be attempting to use an uninitialized witness. + // + // We then do not attempt execution of this opcode and just simplify the inputs. + Opcode::Brillig(new_brillig) + } else if let Ok(mut solver) = BrilligSolver::new( + &known_witnesses, + &HashMap::new(), + &new_brillig, + &StubbedBlackBoxSolver, + idx, + ) { + match solver.solve() { + Ok(BrilligSolverStatus::Finished) => { + // Write execution outputs + match solver.finalize(&mut known_witnesses, &new_brillig) { + Ok(()) => { + // If we've managed to execute the brillig opcode at compile time, we can now just write in the + // results as constants for the rest of the circuit. + continue; + } + _ => Opcode::Brillig(new_brillig), + } + } + Ok(BrilligSolverStatus::InProgress) => unreachable!( + "Solver should either finish, block on foreign call, or error." + ), + Ok(BrilligSolverStatus::ForeignCallWait(_)) | Err(_) => { + Opcode::Brillig(new_brillig) + } + } + } else { + Opcode::Brillig(new_brillig) + } + } + + Opcode::Directive(Directive::ToLeRadix { a, b, radix }) => { + if b.iter().all(|output| known_witnesses.contains_key(output)) { + continue; + } else if b.iter().any(|witness| required_witnesses.contains(witness)) { + // If one of the brillig opcode's outputs is a required witness then we can't remove the opcode. In this case we can't replace + // all of the uses of this witness with the calculated constant so we'll be attempting to use an uninitialized witness. + // + // We then do not attempt execution of this opcode and just simplify the inputs. + Opcode::Directive(Directive::ToLeRadix { + a: remap_expression(&known_witnesses, a), + b, + radix, + }) + } else { + let directive = Directive::ToLeRadix { + a: remap_expression(&known_witnesses, a), + b, + radix, + }; + let result = solve_directives(&mut known_witnesses, &directive); + + match result { + Ok(()) => continue, + Err(_) => Opcode::Directive(directive), + } + } + } + + Opcode::BlackBoxFuncCall(BlackBoxFuncCall::RANGE { input }) => { + if solve_range_opcode(&known_witnesses, &input).is_ok() { + continue; + } else { + opcode + } + } + + Opcode::BlackBoxFuncCall(_) + | Opcode::MemoryOp { .. } + | Opcode::MemoryInit { .. } => opcode, + }; + + new_opcodes.push(new_opcode); + new_order_list.push(order_list[idx]); + } + + self.circuit.opcodes = new_opcodes; + + (self.circuit, new_order_list) + } +} + +#[cfg(test)] +mod tests { + use std::collections::BTreeSet; + + use crate::compiler::optimizers::constant_backpropagation::ConstantBackpropagationOptimizer; + use acir::{ + brillig::MemoryAddress, + circuit::{ + brillig::{Brillig, BrilligOutputs}, + opcodes::{BlackBoxFuncCall, FunctionInput}, + Circuit, ExpressionWidth, Opcode, PublicInputs, + }, + native_types::Witness, + }; + use brillig_vm::brillig::Opcode as BrilligOpcode; + + fn test_circuit(opcodes: Vec) -> Circuit { + Circuit { + current_witness_index: 1, + expression_width: ExpressionWidth::Bounded { width: 3 }, + opcodes, + private_parameters: BTreeSet::new(), + public_parameters: PublicInputs::default(), + return_values: PublicInputs::default(), + assert_messages: Default::default(), + recursive: false, + } + } + + #[test] + fn retain_brillig_with_required_witness_outputs() { + let brillig_opcode = Opcode::Brillig(Brillig { + inputs: Vec::new(), + outputs: vec![BrilligOutputs::Simple(Witness(1))], + bytecode: vec![ + BrilligOpcode::Const { + destination: MemoryAddress(0), + bit_size: 32, + value: 1u128.into(), + }, + BrilligOpcode::Stop { return_data_offset: 0, return_data_size: 1 }, + ], + predicate: None, + }); + let blackbox_opcode = Opcode::BlackBoxFuncCall(BlackBoxFuncCall::AND { + lhs: FunctionInput { witness: Witness(1), num_bits: 64 }, + rhs: FunctionInput { witness: Witness(2), num_bits: 64 }, + output: Witness(3), + }); + + let opcodes = vec![brillig_opcode, blackbox_opcode]; + // The optimizer should keep the lowest bit size range constraint + let circuit = test_circuit(opcodes); + let acir_opcode_positions = circuit.opcodes.iter().enumerate().map(|(i, _)| i).collect(); + let optimizer = ConstantBackpropagationOptimizer::new(circuit); + + let (optimized_circuit, _) = + optimizer.backpropagate_constants_iteration(acir_opcode_positions); + + assert_eq!( + optimized_circuit.opcodes.len(), + 2, + "The brillig opcode should not be removed as the output is needed as a witness" + ); + } +} diff --git a/acvm-repo/acvm/src/compiler/optimizers/general.rs b/acvm-repo/acvm/src/compiler/optimizers/general.rs index 2bd781f7bb5..a48a590a05e 100644 --- a/acvm-repo/acvm/src/compiler/optimizers/general.rs +++ b/acvm-repo/acvm/src/compiler/optimizers/general.rs @@ -13,7 +13,8 @@ impl GeneralOptimizer { pub(crate) fn optimize(opcode: Expression) -> Expression { // XXX: Perhaps this optimization can be done on the fly let opcode = remove_zero_coefficients(opcode); - simplify_mul_terms(opcode) + let opcode = simplify_mul_terms(opcode); + simplify_linear_terms(opcode) } } @@ -42,3 +43,20 @@ fn simplify_mul_terms(mut gate: Expression) -> Expression { gate.mul_terms = hash_map.into_iter().map(|((w_l, w_r), scale)| (scale, w_l, w_r)).collect(); gate } + +// Simplifies all linear terms with the same variables +fn simplify_linear_terms(mut gate: Expression) -> Expression { + let mut hash_map: IndexMap = IndexMap::new(); + + // Canonicalize the ordering of the terms, lets just order by variable name + for (scale, witness) in gate.linear_combinations.into_iter() { + *hash_map.entry(witness).or_insert_with(FieldElement::zero) += scale; + } + + gate.linear_combinations = hash_map + .into_iter() + .filter(|(_, scale)| scale != &FieldElement::zero()) + .map(|(witness, scale)| (scale, witness)) + .collect(); + gate +} diff --git a/acvm-repo/acvm/src/compiler/optimizers/mod.rs b/acvm-repo/acvm/src/compiler/optimizers/mod.rs index 923756580b3..04d3f99a408 100644 --- a/acvm-repo/acvm/src/compiler/optimizers/mod.rs +++ b/acvm-repo/acvm/src/compiler/optimizers/mod.rs @@ -1,5 +1,6 @@ use acir::circuit::{Circuit, Opcode}; +// mod constant_backpropagation; mod general; mod redundant_range; mod unused_memory; @@ -8,6 +9,7 @@ pub(crate) use general::GeneralOptimizer; pub(crate) use redundant_range::RangeOptimizer; use tracing::info; +// use self::constant_backpropagation::ConstantBackpropagationOptimizer; use self::unused_memory::UnusedMemoryOptimizer; use super::{transform_assert_messages, AcirTransformationMap}; @@ -26,6 +28,15 @@ pub fn optimize(acir: Circuit) -> (Circuit, AcirTransformationMap) { /// Applies [`ProofSystemCompiler`][crate::ProofSystemCompiler] independent optimizations to a [`Circuit`]. #[tracing::instrument(level = "trace", name = "optimize_acir" skip(acir))] pub(super) fn optimize_internal(acir: Circuit) -> (Circuit, Vec) { + // Track original acir opcode positions throughout the transformation passes of the compilation + // by applying the modifications done to the circuit opcodes and also to the opcode_positions (delete and insert) + let acir_opcode_positions = (0..acir.opcodes.len()).collect(); + + if acir.opcodes.len() == 1 && matches!(acir.opcodes[0], Opcode::Brillig(_)) { + info!("Program is fully unconstrained, skipping optimization pass"); + return (acir, acir_opcode_positions); + } + info!("Number of opcodes before: {}", acir.opcodes.len()); // General optimizer pass @@ -42,20 +53,22 @@ pub(super) fn optimize_internal(acir: Circuit) -> (Circuit, Vec) { .collect(); let acir = Circuit { opcodes, ..acir }; - // Track original acir opcode positions throughout the transformation passes of the compilation - // by applying the modifications done to the circuit opcodes and also to the opcode_positions (delete and insert) - let acir_opcode_positions = (0..acir.opcodes.len()).collect(); - // Unused memory optimization pass let memory_optimizer = UnusedMemoryOptimizer::new(acir); let (acir, acir_opcode_positions) = memory_optimizer.remove_unused_memory_initializations(acir_opcode_positions); + // let (acir, acir_opcode_positions) = + // ConstantBackpropagationOptimizer::backpropagate_constants(acir, acir_opcode_positions); + // Range optimization pass let range_optimizer = RangeOptimizer::new(acir); let (acir, acir_opcode_positions) = range_optimizer.replace_redundant_ranges(acir_opcode_positions); + // let (acir, acir_opcode_positions) = + // ConstantBackpropagationOptimizer::backpropagate_constants(acir, acir_opcode_positions); + info!("Number of opcodes after: {}", acir.opcodes.len()); (acir, acir_opcode_positions) diff --git a/acvm-repo/acvm/src/compiler/transformers/mod.rs b/acvm-repo/acvm/src/compiler/transformers/mod.rs index 214243d9360..003cd4279a1 100644 --- a/acvm-repo/acvm/src/compiler/transformers/mod.rs +++ b/acvm-repo/acvm/src/compiler/transformers/mod.rs @@ -6,10 +6,8 @@ use acir::{ use indexmap::IndexMap; mod csat; -mod r1cs; pub(crate) use csat::CSatTransformer; -pub(crate) use r1cs::R1CSTransformer; use super::{transform_assert_messages, AcirTransformationMap}; @@ -43,8 +41,7 @@ pub(super) fn transform_internal( ) -> (Circuit, Vec) { let mut transformer = match &expression_width { ExpressionWidth::Unbounded => { - let transformer = R1CSTransformer::new(acir); - return (transformer.transform(), acir_opcode_positions); + return (acir, acir_opcode_positions); } ExpressionWidth::Bounded { width } => { let mut csat = CSatTransformer::new(*width); @@ -145,6 +142,16 @@ pub(super) fn transform_internal( new_acir_opcode_positions.push(acir_opcode_positions[index]); transformed_opcodes.push(opcode); } + Opcode::Call { ref outputs, .. } => { + for witness in outputs { + transformer.mark_solvable(*witness); + } + + // `Call` does not write values to the `WitnessMap` + // A separate ACIR function should have its own respective `WitnessMap` + new_acir_opcode_positions.push(acir_opcode_positions[index]); + transformed_opcodes.push(opcode); + } } } diff --git a/acvm-repo/acvm/src/compiler/transformers/r1cs.rs b/acvm-repo/acvm/src/compiler/transformers/r1cs.rs deleted file mode 100644 index 3bdd29c9c53..00000000000 --- a/acvm-repo/acvm/src/compiler/transformers/r1cs.rs +++ /dev/null @@ -1,16 +0,0 @@ -use acir::circuit::Circuit; - -/// Currently a "noop" transformer. -pub(crate) struct R1CSTransformer { - acir: Circuit, -} - -impl R1CSTransformer { - pub(crate) fn new(acir: Circuit) -> Self { - Self { acir } - } - // TODO: We could possibly make sure that all polynomials are at most degree-2 - pub(crate) fn transform(self) -> Circuit { - self.acir - } -} diff --git a/acvm-repo/acvm/src/pwg/arithmetic.rs b/acvm-repo/acvm/src/pwg/arithmetic.rs index 81462ea495e..dc9e13d44b6 100644 --- a/acvm-repo/acvm/src/pwg/arithmetic.rs +++ b/acvm-repo/acvm/src/pwg/arithmetic.rs @@ -7,7 +7,7 @@ use super::{insert_value, ErrorLocation, OpcodeNotSolvable, OpcodeResolutionErro /// An Expression solver will take a Circuit's assert-zero opcodes with witness assignments /// and create the other witness variables -pub(super) struct ExpressionSolver; +pub(crate) struct ExpressionSolver; #[allow(clippy::enum_variant_names)] pub(super) enum OpcodeStatus { @@ -24,13 +24,18 @@ pub(crate) enum MulTerm { impl ExpressionSolver { /// Derives the rest of the witness based on the initial low level variables - pub(super) fn solve( + pub(crate) fn solve( initial_witness: &mut WitnessMap, opcode: &Expression, ) -> Result<(), OpcodeResolutionError> { let opcode = &ExpressionSolver::evaluate(opcode, initial_witness); // Evaluate multiplication term - let mul_result = ExpressionSolver::solve_mul_term(opcode, initial_witness); + let mul_result = + ExpressionSolver::solve_mul_term(opcode, initial_witness).map_err(|_| { + OpcodeResolutionError::OpcodeNotSolvable( + OpcodeNotSolvable::ExpressionHasTooManyUnknowns(opcode.clone()), + ) + })?; // Evaluate the fan-in terms let opcode_status = ExpressionSolver::solve_fan_in_term(opcode, initial_witness); @@ -54,9 +59,7 @@ impl ExpressionSolver { } } else { let assignment = -total_sum / (q + b); - // Add this into the witness assignments - insert_value(&w1, assignment, initial_witness)?; - Ok(()) + insert_value(&w1, assignment, initial_witness) } } else { // TODO: can we be more specific with this error? @@ -84,9 +87,7 @@ impl ExpressionSolver { } } else { let assignment = -(total_sum / partial_prod); - // Add this into the witness assignments - insert_value(&unknown_var, assignment, initial_witness)?; - Ok(()) + insert_value(&unknown_var, assignment, initial_witness) } } (MulTerm::Solved(a), OpcodeStatus::OpcodeSatisfied(b)) => { @@ -118,9 +119,7 @@ impl ExpressionSolver { } } else { let assignment = -(total_sum / coeff); - // Add this into the witness assignments - insert_value(&unknown_var, assignment, initial_witness)?; - Ok(()) + insert_value(&unknown_var, assignment, initial_witness) } } } @@ -130,16 +129,19 @@ impl ExpressionSolver { /// If the witness values are not known, then the function returns a None /// XXX: Do we need to account for the case where 5xy + 6x = 0 ? We do not know y, but it can be solved given x . But I believe x can be solved with another opcode /// XXX: What about making a mul opcode = a constant 5xy + 7 = 0 ? This is the same as the above. - fn solve_mul_term(arith_opcode: &Expression, witness_assignments: &WitnessMap) -> MulTerm { + fn solve_mul_term( + arith_opcode: &Expression, + witness_assignments: &WitnessMap, + ) -> Result { // First note that the mul term can only contain one/zero term // We are assuming it has been optimized. match arith_opcode.mul_terms.len() { - 0 => MulTerm::Solved(FieldElement::zero()), - 1 => ExpressionSolver::solve_mul_term_helper( + 0 => Ok(MulTerm::Solved(FieldElement::zero())), + 1 => Ok(ExpressionSolver::solve_mul_term_helper( &arith_opcode.mul_terms[0], witness_assignments, - ), - _ => panic!("Mul term in the assert-zero opcode must contain either zero or one term"), + )), + _ => Err(OpcodeStatus::OpcodeUnsolvable), } } @@ -209,7 +211,7 @@ impl ExpressionSolver { } // Partially evaluate the opcode using the known witnesses - pub(super) fn evaluate(expr: &Expression, initial_witness: &WitnessMap) -> Expression { + pub(crate) fn evaluate(expr: &Expression, initial_witness: &WitnessMap) -> Expression { let mut result = Expression::default(); for &(c, w1, w2) in &expr.mul_terms { let mul_result = ExpressionSolver::solve_mul_term_helper(&(c, w1, w2), initial_witness); diff --git a/acvm-repo/acvm/src/pwg/blackbox/hash.rs b/acvm-repo/acvm/src/pwg/blackbox/hash.rs index 1bc26f06188..24c835a636a 100644 --- a/acvm-repo/acvm/src/pwg/blackbox/hash.rs +++ b/acvm-repo/acvm/src/pwg/blackbox/hash.rs @@ -143,12 +143,22 @@ pub(crate) fn solve_poseidon2_permutation_opcode( return Err(OpcodeResolutionError::BlackBoxFunctionFailed( acir::BlackBoxFunc::Poseidon2Permutation, format!( - "the number of inputs does not match specified length. {} > {}", + "the number of inputs does not match specified length. {} != {}", inputs.len(), len ), )); } + if len as usize != outputs.len() { + return Err(OpcodeResolutionError::BlackBoxFunctionFailed( + acir::BlackBoxFunc::Poseidon2Permutation, + format!( + "the number of outputs does not match specified length. {} != {}", + outputs.len(), + len + ), + )); + } // Read witness assignments let mut state = Vec::new(); diff --git a/acvm-repo/acvm/src/pwg/blackbox/mod.rs b/acvm-repo/acvm/src/pwg/blackbox/mod.rs index 4309cad1b2e..6ee926043cd 100644 --- a/acvm-repo/acvm/src/pwg/blackbox/mod.rs +++ b/acvm-repo/acvm/src/pwg/blackbox/mod.rs @@ -25,7 +25,7 @@ use fixed_base_scalar_mul::{embedded_curve_add, fixed_base_scalar_mul}; use hash::{solve_generic_256_hash_opcode, solve_sha_256_permutation_opcode}; use logic::{and, xor}; use pedersen::pedersen; -use range::solve_range_opcode; +pub(crate) use range::solve_range_opcode; use signature::{ ecdsa::{secp256k1_prehashed, secp256r1_prehashed}, schnorr::schnorr_verify, diff --git a/acvm-repo/acvm/src/pwg/blackbox/range.rs b/acvm-repo/acvm/src/pwg/blackbox/range.rs index 1b976e30ed5..2afe820b636 100644 --- a/acvm-repo/acvm/src/pwg/blackbox/range.rs +++ b/acvm-repo/acvm/src/pwg/blackbox/range.rs @@ -4,7 +4,7 @@ use crate::{ }; use acir::{circuit::opcodes::FunctionInput, native_types::WitnessMap}; -pub(super) fn solve_range_opcode( +pub(crate) fn solve_range_opcode( initial_witness: &WitnessMap, input: &FunctionInput, ) -> Result<(), OpcodeResolutionError> { diff --git a/acvm-repo/acvm/src/pwg/brillig.rs b/acvm-repo/acvm/src/pwg/brillig.rs index b0fb7469fd9..bcf736cd926 100644 --- a/acvm-repo/acvm/src/pwg/brillig.rs +++ b/acvm-repo/acvm/src/pwg/brillig.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use acir::{ - brillig::{ForeignCallParam, ForeignCallResult, Value}, + brillig::{ForeignCallParam, ForeignCallResult}, circuit::{ brillig::{Brillig, BrilligInputs, BrilligOutputs}, opcodes::BlockId, @@ -11,7 +11,7 @@ use acir::{ FieldElement, }; use acvm_blackbox_solver::BlackBoxFunctionSolver; -use brillig_vm::{VMStatus, VM}; +use brillig_vm::{MemoryValue, VMStatus, VM}; use crate::{pwg::OpcodeNotSolvable, OpcodeResolutionError}; @@ -65,7 +65,7 @@ impl<'b, B: BlackBoxFunctionSolver> BrilligSolver<'b, B> { /// Constructs a solver for a Brillig block given the bytecode and initial /// witness. - pub(super) fn new( + pub(crate) fn new( initial_witness: &WitnessMap, memory: &HashMap, brillig: &'b Brillig, @@ -73,7 +73,7 @@ impl<'b, B: BlackBoxFunctionSolver> BrilligSolver<'b, B> { acir_index: usize, ) -> Result { // Set input values - let mut calldata: Vec = Vec::new(); + let mut calldata: Vec = Vec::new(); // Each input represents an expression or array of expressions to evaluate. // Iterate over each input and evaluate the expression(s) associated with it. // Push the results into memory. @@ -81,7 +81,7 @@ impl<'b, B: BlackBoxFunctionSolver> BrilligSolver<'b, B> { for input in &brillig.inputs { match input { BrilligInputs::Single(expr) => match get_value(expr, initial_witness) { - Ok(value) => calldata.push(value.into()), + Ok(value) => calldata.push(value), Err(_) => { return Err(OpcodeResolutionError::OpcodeNotSolvable( OpcodeNotSolvable::ExpressionHasTooManyUnknowns(expr.clone()), @@ -92,7 +92,7 @@ impl<'b, B: BlackBoxFunctionSolver> BrilligSolver<'b, B> { // Attempt to fetch all array input values for expr in expr_arr.iter() { match get_value(expr, initial_witness) { - Ok(value) => calldata.push(value.into()), + Ok(value) => calldata.push(value), Err(_) => { return Err(OpcodeResolutionError::OpcodeNotSolvable( OpcodeNotSolvable::ExpressionHasTooManyUnknowns(expr.clone()), @@ -110,7 +110,7 @@ impl<'b, B: BlackBoxFunctionSolver> BrilligSolver<'b, B> { .block_value .get(&memory_index) .expect("All memory is initialized on creation"); - calldata.push((*memory_value).into()); + calldata.push(*memory_value); } } } @@ -122,11 +122,11 @@ impl<'b, B: BlackBoxFunctionSolver> BrilligSolver<'b, B> { Ok(Self { vm, acir_index }) } - pub fn get_memory(&self) -> &[Value] { + pub fn get_memory(&self) -> &[MemoryValue] { self.vm.get_memory() } - pub fn write_memory_at(&mut self, ptr: usize, value: Value) { + pub fn write_memory_at(&mut self, ptr: usize, value: MemoryValue) { self.vm.write_memory_at(ptr, value); } @@ -134,7 +134,7 @@ impl<'b, B: BlackBoxFunctionSolver> BrilligSolver<'b, B> { self.vm.get_call_stack() } - pub(super) fn solve(&mut self) -> Result { + pub(crate) fn solve(&mut self) -> Result { let status = self.vm.process_opcodes(); self.handle_vm_status(status) } @@ -177,7 +177,7 @@ impl<'b, B: BlackBoxFunctionSolver> BrilligSolver<'b, B> { } } - pub(super) fn finalize( + pub(crate) fn finalize( self, witness: &mut WitnessMap, brillig: &Brillig, @@ -206,13 +206,13 @@ impl<'b, B: BlackBoxFunctionSolver> BrilligSolver<'b, B> { for output in brillig.outputs.iter() { match output { BrilligOutputs::Simple(witness) => { - insert_value(witness, memory[current_ret_data_idx].to_field(), witness_map)?; + insert_value(witness, memory[current_ret_data_idx].value, witness_map)?; current_ret_data_idx += 1; } BrilligOutputs::Array(witness_arr) => { for witness in witness_arr.iter() { let value = memory[current_ret_data_idx]; - insert_value(witness, value.to_field(), witness_map)?; + insert_value(witness, value.value, witness_map)?; current_ret_data_idx += 1; } } diff --git a/acvm-repo/acvm/src/pwg/directives/mod.rs b/acvm-repo/acvm/src/pwg/directives/mod.rs index 07226c85b27..ee544521fc7 100644 --- a/acvm-repo/acvm/src/pwg/directives/mod.rs +++ b/acvm-repo/acvm/src/pwg/directives/mod.rs @@ -11,7 +11,7 @@ use super::{get_value, insert_value, ErrorLocation}; /// Returns `Ok(OpcodeResolution)` to signal whether the directive was successful solved. /// /// Returns `Err(OpcodeResolutionError)` if a circuit constraint is unsatisfied. -pub(super) fn solve_directives( +pub(crate) fn solve_directives( initial_witness: &mut WitnessMap, directive: &Directive, ) -> Result<(), OpcodeResolutionError> { diff --git a/acvm-repo/acvm/src/pwg/memory_op.rs b/acvm-repo/acvm/src/pwg/memory_op.rs index 49ec652289e..e51797707a7 100644 --- a/acvm-repo/acvm/src/pwg/memory_op.rs +++ b/acvm-repo/acvm/src/pwg/memory_op.rs @@ -13,7 +13,7 @@ type MemoryIndex = u32; /// Maintains the state for solving [`MemoryInit`][`acir::circuit::Opcode::MemoryInit`] and [`MemoryOp`][`acir::circuit::Opcode::MemoryOp`] opcodes. #[derive(Default)] -pub(super) struct MemoryOpSolver { +pub(crate) struct MemoryOpSolver { pub(super) block_value: HashMap, pub(super) block_len: u32, } diff --git a/acvm-repo/acvm/src/pwg/mod.rs b/acvm-repo/acvm/src/pwg/mod.rs index 2ee39a289e7..3cedcfc0399 100644 --- a/acvm-repo/acvm/src/pwg/mod.rs +++ b/acvm-repo/acvm/src/pwg/mod.rs @@ -21,11 +21,11 @@ use thiserror::Error; // arithmetic pub(crate) mod arithmetic; // Brillig bytecode -mod brillig; +pub(crate) mod brillig; // Directives -mod directives; +pub(crate) mod directives; // black box functions -mod blackbox; +pub(crate) mod blackbox; mod memory_op; pub use self::brillig::{BrilligSolver, BrilligSolverStatus}; @@ -49,6 +49,12 @@ pub enum ACVMStatus { /// /// Once this is done, the ACVM can be restarted to solve the remaining opcodes. RequiresForeignCall(ForeignCallWaitInfo), + + /// The ACVM has encountered a request for an ACIR [call][acir::circuit::Opcode] + /// to execute a separate ACVM instance. The result of the ACIR call must be passd back to the ACVM. + /// + /// Once this is done, the ACVM can be restarted to solve the remaining opcodes. + RequiresAcirCall(AcirCallWaitInfo), } impl std::fmt::Display for ACVMStatus { @@ -58,6 +64,7 @@ impl std::fmt::Display for ACVMStatus { ACVMStatus::InProgress => write!(f, "In progress"), ACVMStatus::Failure(_) => write!(f, "Execution failure"), ACVMStatus::RequiresForeignCall(_) => write!(f, "Waiting on foreign call"), + ACVMStatus::RequiresAcirCall(_) => write!(f, "Waiting on acir call"), } } } @@ -117,6 +124,10 @@ pub enum OpcodeResolutionError { BlackBoxFunctionFailed(BlackBoxFunc, String), #[error("Failed to solve brillig function, reason: {message}")] BrilligFunctionFailed { message: String, call_stack: Vec }, + #[error("Attempted to call `main` with a `Call` opcode")] + AcirMainCallAttempted { opcode_location: ErrorLocation }, + #[error("{results_size:?} result values were provided for {outputs_size:?} call output witnesses, most likely due to bad ACIR codegen")] + AcirCallOutputsMismatch { opcode_location: ErrorLocation, results_size: u32, outputs_size: u32 }, } impl From for OpcodeResolutionError { @@ -147,6 +158,13 @@ pub struct ACVM<'a, B: BlackBoxFunctionSolver> { witness_map: WitnessMap, brillig_solver: Option>, + + /// A counter maintained throughout an ACVM process that determines + /// whether the caller has resolved the results of an ACIR [call][Opcode::Call]. + acir_call_counter: usize, + /// Represents the outputs of all ACIR calls during an ACVM process + /// List is appended onto by the caller upon reaching a [ACVMStatus::RequiresAcirCall] + acir_call_results: Vec>, } impl<'a, B: BlackBoxFunctionSolver> ACVM<'a, B> { @@ -161,6 +179,8 @@ impl<'a, B: BlackBoxFunctionSolver> ACVM<'a, B> { instruction_pointer: 0, witness_map: initial_witness, brillig_solver: None, + acir_call_counter: 0, + acir_call_results: Vec::default(), } } @@ -244,6 +264,29 @@ impl<'a, B: BlackBoxFunctionSolver> ACVM<'a, B> { self.status(ACVMStatus::InProgress); } + /// Sets the status of the VM to `RequiresAcirCall` + /// Indicating that the VM is now waiting for an ACIR call to be resolved + fn wait_for_acir_call(&mut self, acir_call: AcirCallWaitInfo) -> ACVMStatus { + self.status(ACVMStatus::RequiresAcirCall(acir_call)) + } + + /// Resolves an ACIR call's result (simply a list of fields) using a result calculated by a separate ACVM instance. + /// + /// The current ACVM instance can then be restarted to solve the remaining ACIR opcodes. + pub fn resolve_pending_acir_call(&mut self, call_result: Vec) { + if !matches!(self.status, ACVMStatus::RequiresAcirCall(_)) { + panic!("ACVM is not expecting an ACIR call response as no call was made"); + } + + if self.acir_call_counter < self.acir_call_results.len() { + panic!("No unresolved ACIR calls"); + } + self.acir_call_results.push(call_result); + + // Now that the ACIR call has been resolved then we can resume execution. + self.status(ACVMStatus::InProgress); + } + /// Executes the ACVM's circuit until execution halts. /// /// Execution can halt due to three reasons: @@ -281,6 +324,10 @@ impl<'a, B: BlackBoxFunctionSolver> ACVM<'a, B> { Ok(Some(foreign_call)) => return self.wait_for_foreign_call(foreign_call), res => res.map(|_| ()), }, + Opcode::Call { .. } => match self.solve_call_opcode() { + Ok(Some(input_values)) => return self.wait_for_acir_call(input_values), + res => res.map(|_| ()), + }, }; self.handle_opcode_resolution(resolution) } @@ -399,6 +446,46 @@ impl<'a, B: BlackBoxFunctionSolver> ACVM<'a, B> { self.brillig_solver = Some(solver); self.solve_opcode() } + + pub fn solve_call_opcode(&mut self) -> Result, OpcodeResolutionError> { + let Opcode::Call { id, inputs, outputs } = &self.opcodes[self.instruction_pointer] else { + unreachable!("Not executing a Call opcode"); + }; + if *id == 0 { + return Err(OpcodeResolutionError::AcirMainCallAttempted { + opcode_location: ErrorLocation::Resolved(OpcodeLocation::Acir( + self.instruction_pointer(), + )), + }); + } + + if self.acir_call_counter >= self.acir_call_results.len() { + let mut initial_witness = WitnessMap::default(); + for (i, input_witness) in inputs.iter().enumerate() { + let input_value = *witness_to_value(&self.witness_map, *input_witness)?; + initial_witness.insert(Witness(i as u32), input_value); + } + return Ok(Some(AcirCallWaitInfo { id: *id, initial_witness })); + } + + let result_values = &self.acir_call_results[self.acir_call_counter]; + if outputs.len() != result_values.len() { + return Err(OpcodeResolutionError::AcirCallOutputsMismatch { + opcode_location: ErrorLocation::Resolved(OpcodeLocation::Acir( + self.instruction_pointer(), + )), + results_size: result_values.len() as u32, + outputs_size: outputs.len() as u32, + }); + } + + for (output_witness, result_value) in outputs.iter().zip(result_values) { + insert_value(output_witness, *result_value, &mut self.witness_map)?; + } + + self.acir_call_counter += 1; + Ok(None) + } } // Returns the concrete value for a particular witness @@ -468,3 +555,11 @@ fn any_witness_from_expression(expr: &Expression) -> Option { Some(expr.linear_combinations[0].1) } } + +#[derive(Debug, Clone, PartialEq)] +pub struct AcirCallWaitInfo { + /// Index in the list of ACIR function's that should be called + pub id: u32, + /// Initial witness for the given circuit to be called + pub initial_witness: WitnessMap, +} diff --git a/acvm-repo/acvm/tests/solver.rs b/acvm-repo/acvm/tests/solver.rs index b267c3005a8..a708db5b030 100644 --- a/acvm-repo/acvm/tests/solver.rs +++ b/acvm-repo/acvm/tests/solver.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use acir::{ - brillig::{BinaryFieldOp, MemoryAddress, Opcode as BrilligOpcode, Value, ValueOrArray}, + brillig::{BinaryFieldOp, MemoryAddress, Opcode as BrilligOpcode, ValueOrArray}, circuit::{ brillig::{Brillig, BrilligInputs, BrilligOutputs}, opcodes::{BlockId, MemOp}, @@ -70,9 +70,9 @@ fn inversion_brillig_oracle_equivalence() { BrilligOpcode::ForeignCall { function: "invert".into(), destinations: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(1))], - destination_value_types: vec![HeapValueType::Simple], + destination_value_types: vec![HeapValueType::field()], inputs: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(0))], - input_value_types: vec![HeapValueType::Simple], + input_value_types: vec![HeapValueType::field()], }, BrilligOpcode::Stop { return_data_offset: 0, return_data_size: 3 }, ], @@ -120,8 +120,7 @@ fn inversion_brillig_oracle_equivalence() { assert_eq!(foreign_call_wait_info.inputs.len(), 1, "Should be waiting for a single input"); // As caller of VM, need to resolve foreign calls - let foreign_call_result = - Value::from(foreign_call_wait_info.inputs[0].unwrap_value().to_field().inverse()); + let foreign_call_result = foreign_call_wait_info.inputs[0].unwrap_field().inverse(); // Alter Brillig oracle opcode with foreign call resolution acvm.resolve_pending_foreign_call(foreign_call_result.into()); @@ -199,16 +198,16 @@ fn double_inversion_brillig_oracle() { BrilligOpcode::ForeignCall { function: "invert".into(), destinations: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(1))], - destination_value_types: vec![HeapValueType::Simple], + destination_value_types: vec![HeapValueType::field()], inputs: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(0))], - input_value_types: vec![HeapValueType::Simple], + input_value_types: vec![HeapValueType::field()], }, BrilligOpcode::ForeignCall { function: "invert".into(), destinations: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(3))], - destination_value_types: vec![HeapValueType::Simple], + destination_value_types: vec![HeapValueType::field()], inputs: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(2))], - input_value_types: vec![HeapValueType::Simple], + input_value_types: vec![HeapValueType::field()], }, BrilligOpcode::Stop { return_data_offset: 0, return_data_size: 5 }, ], @@ -257,8 +256,7 @@ fn double_inversion_brillig_oracle() { acvm.get_pending_foreign_call().expect("should have a brillig foreign call request"); assert_eq!(foreign_call_wait_info.inputs.len(), 1, "Should be waiting for a single input"); - let x_plus_y_inverse = - Value::from(foreign_call_wait_info.inputs[0].unwrap_value().to_field().inverse()); + let x_plus_y_inverse = foreign_call_wait_info.inputs[0].unwrap_field().inverse(); // Resolve Brillig foreign call acvm.resolve_pending_foreign_call(x_plus_y_inverse.into()); @@ -275,8 +273,7 @@ fn double_inversion_brillig_oracle() { acvm.get_pending_foreign_call().expect("should have a brillig foreign call request"); assert_eq!(foreign_call_wait_info.inputs.len(), 1, "Should be waiting for a single input"); - let i_plus_j_inverse = - Value::from(foreign_call_wait_info.inputs[0].unwrap_value().to_field().inverse()); + let i_plus_j_inverse = foreign_call_wait_info.inputs[0].unwrap_field().inverse(); assert_ne!(x_plus_y_inverse, i_plus_j_inverse); // Alter Brillig oracle opcode @@ -334,16 +331,16 @@ fn oracle_dependent_execution() { BrilligOpcode::ForeignCall { function: "invert".into(), destinations: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(1))], - destination_value_types: vec![HeapValueType::Simple], + destination_value_types: vec![HeapValueType::field()], inputs: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(0))], - input_value_types: vec![HeapValueType::Simple], + input_value_types: vec![HeapValueType::field()], }, BrilligOpcode::ForeignCall { function: "invert".into(), destinations: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(3))], - destination_value_types: vec![HeapValueType::Simple], + destination_value_types: vec![HeapValueType::field()], inputs: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(2))], - input_value_types: vec![HeapValueType::Simple], + input_value_types: vec![HeapValueType::field()], }, BrilligOpcode::Stop { return_data_offset: 0, return_data_size: 4 }, ], @@ -389,8 +386,7 @@ fn oracle_dependent_execution() { assert_eq!(foreign_call_wait_info.inputs.len(), 1, "Should be waiting for a single input"); // Resolve Brillig foreign call - let x_inverse = - Value::from(foreign_call_wait_info.inputs[0].unwrap_value().to_field().inverse()); + let x_inverse = foreign_call_wait_info.inputs[0].unwrap_field().inverse(); acvm.resolve_pending_foreign_call(x_inverse.into()); // After filling data request, continue solving @@ -406,8 +402,7 @@ fn oracle_dependent_execution() { assert_eq!(foreign_call_wait_info.inputs.len(), 1, "Should be waiting for a single input"); // Resolve Brillig foreign call - let y_inverse = - Value::from(foreign_call_wait_info.inputs[0].unwrap_value().to_field().inverse()); + let y_inverse = foreign_call_wait_info.inputs[0].unwrap_field().inverse(); acvm.resolve_pending_foreign_call(y_inverse.into()); // We've resolved all the brillig foreign calls so we should be able to complete execution now. @@ -464,9 +459,9 @@ fn brillig_oracle_predicate() { BrilligOpcode::ForeignCall { function: "invert".into(), destinations: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(1))], - destination_value_types: vec![HeapValueType::Simple], + destination_value_types: vec![HeapValueType::field()], inputs: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(0))], - input_value_types: vec![HeapValueType::Simple], + input_value_types: vec![HeapValueType::field()], }, ], predicate: Some(Expression::default()), diff --git a/acvm-repo/acvm_js/Cargo.toml b/acvm-repo/acvm_js/Cargo.toml index 7ec814a72e5..8319c38aee2 100644 --- a/acvm-repo/acvm_js/Cargo.toml +++ b/acvm-repo/acvm_js/Cargo.toml @@ -2,7 +2,7 @@ name = "acvm_js" description = "Typescript wrapper around the ACVM allowing execution of ACIR code" # x-release-please-start-version -version = "0.40.0" +version = "0.42.0" # x-release-please-end authors.workspace = true edition.workspace = true @@ -16,20 +16,17 @@ repository.workspace = true crate-type = ["cdylib"] [dependencies] -cfg-if = "1.0.0" - -[target.'cfg(target_arch = "wasm32")'.dependencies] acvm.workspace = true bn254_blackbox_solver = { workspace = true, optional = true } wasm-bindgen.workspace = true wasm-bindgen-futures.workspace = true console_error_panic_hook.workspace = true gloo-utils.workspace = true -js-sys.workspace = true +js-sys.workspace = true +serde.workspace = true tracing-subscriber.workspace = true tracing-web.workspace = true -serde = { version = "1.0.136", features = ["derive"] } const-str = "0.5.5" [build-dependencies] diff --git a/acvm-repo/acvm_js/build.sh b/acvm-repo/acvm_js/build.sh index 24af149bcea..fe0b4dcbfff 100755 --- a/acvm-repo/acvm_js/build.sh +++ b/acvm-repo/acvm_js/build.sh @@ -6,13 +6,6 @@ function require_command { exit 1 fi } -function check_installed { - if ! command -v "$1" >/dev/null 2>&1; then - echo "$1 is not installed. Please install it." >&2 - return 1 - fi - return 0 -} function run_or_fail { "$@" local status=$? @@ -25,23 +18,29 @@ function run_or_fail { require_command jq require_command cargo require_command wasm-bindgen -check_installed wasm-opt +require_command wasm-opt self_path=$(dirname "$(readlink -f "$0")") -export pname=$(cargo read-manifest | jq -r '.name') -export CARGO_TARGET_DIR=$self_path/target +pname=$(cargo read-manifest | jq -r '.name') -rm -rf $self_path/outputs >/dev/null 2>&1 -rm -rf $self_path/result >/dev/null 2>&1 +NODE_DIR=$self_path/nodejs +BROWSER_DIR=$self_path/web -if [ -n "$out" ]; then - echo "Will install package to $out (defined outside installPhase.sh script)" -else - export out="$self_path/outputs/out" - echo "Will install package to $out" +# Clear out the existing build artifacts as these aren't automatically removed by wasm-bindgen. +if [ -d ./pkg/ ]; then + rm -r $NODE_DIR + rm -r $BROWSER_DIR fi -run_or_fail $self_path/buildPhaseCargoCommand.sh -run_or_fail $self_path/installPhase.sh +TARGET=wasm32-unknown-unknown +WASM_BINARY=${self_path}/../../target/$TARGET/release/${pname}.wasm + +NODE_WASM=${NODE_DIR}/${pname}_bg.wasm +BROWSER_WASM=${BROWSER_DIR}/${pname}_bg.wasm -ln -s $out $self_path/result +# Build the new wasm package +run_or_fail cargo build --lib --release --target $TARGET --package ${pname} +run_or_fail wasm-bindgen $WASM_BINARY --out-dir $NODE_DIR --typescript --target nodejs +run_or_fail wasm-bindgen $WASM_BINARY --out-dir $BROWSER_DIR --typescript --target web +run_or_fail wasm-opt $NODE_WASM -o $NODE_WASM -O +run_or_fail wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O diff --git a/acvm-repo/acvm_js/buildPhaseCargoCommand.sh b/acvm-repo/acvm_js/buildPhaseCargoCommand.sh deleted file mode 100755 index 6c710bc938f..00000000000 --- a/acvm-repo/acvm_js/buildPhaseCargoCommand.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash - -function run_or_fail { - "$@" - local status=$? - if [ $status -ne 0 ]; then - echo "Command '$*' failed with exit code $status" >&2 - exit $status - fi -} -function run_if_available { - if command -v "$1" >/dev/null 2>&1; then - "$@" - else - echo "$1 is not installed. Please install it to use this feature." >&2 - fi -} - -export self_path=$(dirname "$(readlink -f "$0")") - - -NODE_DIR=$self_path/nodejs/ -BROWSER_DIR=$self_path/web/ - -# Clear out the existing build artifacts as these aren't automatically removed by wasm-pack. -if [ -d ./pkg/ ]; then - rm -r $NODE_DIR - rm -r $BROWSER_DIR -fi - -TARGET=wasm32-unknown-unknown -WASM_BINARY=$CARGO_TARGET_DIR/$TARGET/release/${pname}.wasm - -NODE_WASM=${NODE_DIR}/${pname}_bg.wasm -BROWSER_WASM=${BROWSER_DIR}/${pname}_bg.wasm - -# Build the new wasm package -run_or_fail cargo build --lib --release --target $TARGET --package ${pname} -run_or_fail wasm-bindgen $WASM_BINARY --out-dir $NODE_DIR --typescript --target nodejs -run_or_fail wasm-bindgen $WASM_BINARY --out-dir $BROWSER_DIR --typescript --target web -run_if_available wasm-opt $NODE_WASM -o $NODE_WASM -O -run_if_available wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O diff --git a/acvm-repo/acvm_js/installPhase.sh b/acvm-repo/acvm_js/installPhase.sh deleted file mode 100755 index 34ddb8155e1..00000000000 --- a/acvm-repo/acvm_js/installPhase.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -export self_path=$(dirname "$(readlink -f "$0")") - -export out_path=$out/acvm_js - -mkdir -p $out_path -cp $self_path/README.md $out_path/ -cp $self_path/package.json $out_path/ -cp -r $self_path/nodejs $out_path/ -cp -r $self_path/web $out_path/ diff --git a/acvm-repo/acvm_js/package.json b/acvm-repo/acvm_js/package.json index 876db9ccb62..44d99f13c31 100644 --- a/acvm-repo/acvm_js/package.json +++ b/acvm-repo/acvm_js/package.json @@ -1,6 +1,6 @@ { "name": "@noir-lang/acvm_js", - "version": "0.40.0", + "version": "0.42.0", "publishConfig": { "access": "public" }, @@ -34,21 +34,19 @@ "lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0", "publish": "echo 📡 publishing `$npm_package_name` && yarn npm publish", "nightly:version": "jq --arg new_version \"-$(git rev-parse --short HEAD)$1\" '.version = .version + $new_version' package.json > package-tmp.json && mv package-tmp.json package.json", - "clean": "chmod u+w web nodejs || true && rm -rf web nodejs", - "build:nix": "nix build -L .#acvm_js", - "install:from:nix": "yarn clean && yarn build:nix && cp -rL ./result/acvm_js/nodejs ./ && cp -rL ./result/acvm_js/web ./" + "clean": "chmod u+w web nodejs || true && rm -rf web nodejs" }, "devDependencies": { "@esm-bundle/chai": "^4.3.4-fix.0", "@web/dev-server-esbuild": "^0.3.6", - "@web/test-runner": "^0.15.3", + "@web/test-runner": "^0.18.1", "@web/test-runner-playwright": "^0.10.0", - "chai": "^4.3.7", - "eslint": "^8.56.0", - "eslint-plugin-prettier": "^5.0.0", + "chai": "^4.4.1", + "eslint": "^8.57.0", + "eslint-plugin-prettier": "^5.1.3", "mocha": "^10.2.0", - "prettier": "3.0.3", + "prettier": "3.2.5", "ts-node": "^10.9.1", - "typescript": "^5.0.4" + "typescript": "^5.4.2" } } diff --git a/acvm-repo/acvm_js/src/black_box_solvers.rs b/acvm-repo/acvm_js/src/black_box_solvers.rs index fc0e3b28ebf..188e5334ed5 100644 --- a/acvm-repo/acvm_js/src/black_box_solvers.rs +++ b/acvm-repo/acvm_js/src/black_box_solvers.rs @@ -59,7 +59,6 @@ pub fn ecdsa_secp256k1_verify( signature, ) .unwrap() - .into() } /// Verifies a ECDSA signature over the secp256r1 curve. @@ -81,5 +80,4 @@ pub fn ecdsa_secp256r1_verify( signature, ) .unwrap() - .into() } diff --git a/acvm-repo/acvm_js/src/compression.rs b/acvm-repo/acvm_js/src/compression.rs index fedaa514bf0..8114e0d57d2 100644 --- a/acvm-repo/acvm_js/src/compression.rs +++ b/acvm-repo/acvm_js/src/compression.rs @@ -1,25 +1,27 @@ -use acvm::acir::native_types::WitnessMap; +use acvm::acir::native_types::{WitnessMap, WitnessStack}; use js_sys::JsString; use wasm_bindgen::prelude::wasm_bindgen; -use crate::JsWitnessMap; +use crate::{JsWitnessMap, JsWitnessStack}; /// Compresses a `WitnessMap` into the binary format outputted by Nargo. /// -/// @param {Uint8Array} compressed_witness - A witness map. -/// @returns {WitnessMap} A compressed witness map +/// @param {WitnessMap} witness_map - A witness map. +/// @returns {Uint8Array} A compressed witness map #[wasm_bindgen(js_name = compressWitness, skip_jsdoc)] pub fn compress_witness(witness_map: JsWitnessMap) -> Result, JsString> { console_error_panic_hook::set_once(); let witness_map = WitnessMap::from(witness_map); - let compressed_witness_map: Vec = - Vec::::try_from(witness_map).map_err(|err| err.to_string())?; + let witness_stack = WitnessStack::from(witness_map); + let compressed_witness_stack: Vec = + Vec::::try_from(witness_stack).map_err(|err| err.to_string())?; - Ok(compressed_witness_map) + Ok(compressed_witness_stack) } /// Decompresses a compressed witness as outputted by Nargo into a `WitnessMap`. +/// This should be used to only fetch the witness map for the main function. /// /// @param {Uint8Array} compressed_witness - A compressed witness. /// @returns {WitnessMap} The decompressed witness map. @@ -27,8 +29,39 @@ pub fn compress_witness(witness_map: JsWitnessMap) -> Result, JsString> pub fn decompress_witness(compressed_witness: Vec) -> Result { console_error_panic_hook::set_once(); - let witness_map = - WitnessMap::try_from(compressed_witness.as_slice()).map_err(|err| err.to_string())?; + let mut witness_stack = + WitnessStack::try_from(compressed_witness.as_slice()).map_err(|err| err.to_string())?; - Ok(witness_map.into()) + let witness = + witness_stack.pop().expect("Should have at least one witness on the stack").witness; + Ok(witness.into()) +} + +/// Compresses a `WitnessStack` into the binary format outputted by Nargo. +/// +/// @param {WitnessStack} witness_stack - A witness stack. +/// @returns {Uint8Array} A compressed witness stack +#[wasm_bindgen(js_name = compressWitnessStack, skip_jsdoc)] +pub fn compress_witness_stack(witness_stack: JsWitnessStack) -> Result, JsString> { + console_error_panic_hook::set_once(); + + let witness_stack = WitnessStack::from(witness_stack); + let compressed_witness_stack: Vec = + Vec::::try_from(witness_stack).map_err(|err| err.to_string())?; + + Ok(compressed_witness_stack) +} + +/// Decompresses a compressed witness stack as outputted by Nargo into a `WitnessStack`. +/// +/// @param {Uint8Array} compressed_witness - A compressed witness. +/// @returns {WitnessStack} The decompressed witness stack. +#[wasm_bindgen(js_name = decompressWitnessStack, skip_jsdoc)] +pub fn decompress_witness_stack(compressed_witness: Vec) -> Result { + console_error_panic_hook::set_once(); + + let witness_stack = + WitnessStack::try_from(compressed_witness.as_slice()).map_err(|err| err.to_string())?; + + Ok(witness_stack.into()) } diff --git a/acvm-repo/acvm_js/src/execute.rs b/acvm-repo/acvm_js/src/execute.rs index 3f691e1abf2..0e58ccf039c 100644 --- a/acvm-repo/acvm_js/src/execute.rs +++ b/acvm-repo/acvm_js/src/execute.rs @@ -1,5 +1,9 @@ +use std::{future::Future, pin::Pin}; + +use acvm::BlackBoxFunctionSolver; use acvm::{ - acir::circuit::Circuit, + acir::circuit::{Circuit, Program}, + acir::native_types::{WitnessMap, WitnessStack}, pwg::{ACVMStatus, ErrorLocation, OpcodeResolutionError, ACVM}, }; use bn254_blackbox_solver::Bn254BlackBoxSolver; @@ -9,7 +13,7 @@ use wasm_bindgen::prelude::wasm_bindgen; use crate::{ foreign_call::{resolve_brillig, ForeignCallHandler}, - JsExecutionError, JsWitnessMap, + JsExecutionError, JsWitnessMap, JsWitnessStack, }; #[wasm_bindgen] @@ -34,7 +38,7 @@ pub async fn create_black_box_solver() -> WasmBlackBoxFunctionSolver { /// @returns {WitnessMap} The solved witness calculated by executing the circuit on the provided inputs. #[wasm_bindgen(js_name = executeCircuit, skip_jsdoc)] pub async fn execute_circuit( - circuit: Vec, + program: Vec, initial_witness: JsWitnessMap, foreign_call_handler: ForeignCallHandler, ) -> Result { @@ -42,8 +46,16 @@ pub async fn execute_circuit( let solver = WasmBlackBoxFunctionSolver::initialize().await; - execute_circuit_with_black_box_solver(&solver, circuit, initial_witness, foreign_call_handler) - .await + let mut witness_stack = execute_program_with_native_type_return( + &solver, + program, + initial_witness, + &foreign_call_handler, + ) + .await?; + let witness_map = + witness_stack.pop().expect("Should have at least one witness on the stack").witness; + Ok(witness_map.into()) } /// Executes an ACIR circuit to generate the solved witness from the initial witness. @@ -56,58 +68,175 @@ pub async fn execute_circuit( #[wasm_bindgen(js_name = executeCircuitWithBlackBoxSolver, skip_jsdoc)] pub async fn execute_circuit_with_black_box_solver( solver: &WasmBlackBoxFunctionSolver, - circuit: Vec, + program: Vec, initial_witness: JsWitnessMap, foreign_call_handler: ForeignCallHandler, ) -> Result { console_error_panic_hook::set_once(); - let circuit: Circuit = Circuit::deserialize_circuit(&circuit) - .map_err(|_| JsExecutionError::new("Failed to deserialize circuit. This is likely due to differing serialization formats between ACVM_JS and your compiler".to_string(), None))?; - let mut acvm = ACVM::new(&solver.0, &circuit.opcodes, initial_witness.into()); + let mut witness_stack = execute_program_with_native_type_return( + solver, + program, + initial_witness, + &foreign_call_handler, + ) + .await?; + let witness_map = + witness_stack.pop().expect("Should have at least one witness on the stack").witness; + Ok(witness_map.into()) +} - loop { - let solver_status = acvm.solve(); +#[wasm_bindgen(js_name = executeProgram, skip_jsdoc)] +pub async fn execute_program( + program: Vec, + initial_witness: JsWitnessMap, + foreign_call_handler: ForeignCallHandler, +) -> Result { + console_error_panic_hook::set_once(); - match solver_status { - ACVMStatus::Solved => break, - ACVMStatus::InProgress => { - unreachable!("Execution should not stop while in `InProgress` state.") - } - ACVMStatus::Failure(error) => { - let (assert_message, call_stack) = match &error { - OpcodeResolutionError::UnsatisfiedConstrain { - opcode_location: ErrorLocation::Resolved(opcode_location), - } - | OpcodeResolutionError::IndexOutOfBounds { - opcode_location: ErrorLocation::Resolved(opcode_location), - .. - } => { - (circuit.get_assert_message(*opcode_location), Some(vec![*opcode_location])) + let solver = WasmBlackBoxFunctionSolver::initialize().await; + + execute_program_with_black_box_solver(&solver, program, initial_witness, &foreign_call_handler) + .await +} + +#[wasm_bindgen(js_name = executeProgramWithBlackBoxSolver, skip_jsdoc)] +pub async fn execute_program_with_black_box_solver( + solver: &WasmBlackBoxFunctionSolver, + program: Vec, + initial_witness: JsWitnessMap, + foreign_call_executor: &ForeignCallHandler, +) -> Result { + let witness_stack = execute_program_with_native_type_return( + solver, + program, + initial_witness, + foreign_call_executor, + ) + .await?; + + Ok(witness_stack.into()) +} + +async fn execute_program_with_native_type_return( + solver: &WasmBlackBoxFunctionSolver, + program: Vec, + initial_witness: JsWitnessMap, + foreign_call_executor: &ForeignCallHandler, +) -> Result { + let program: Program = Program::deserialize_program(&program) + .map_err(|_| JsExecutionError::new("Failed to deserialize circuit. This is likely due to differing serialization formats between ACVM_JS and your compiler".to_string(), None))?; + + let executor = ProgramExecutor::new(&program.functions, &solver.0, foreign_call_executor); + let witness_stack = executor.execute(initial_witness.into()).await?; + + Ok(witness_stack) +} + +struct ProgramExecutor<'a, B: BlackBoxFunctionSolver> { + functions: &'a [Circuit], + + blackbox_solver: &'a B, + + foreign_call_handler: &'a ForeignCallHandler, +} + +impl<'a, B: BlackBoxFunctionSolver> ProgramExecutor<'a, B> { + fn new( + functions: &'a [Circuit], + blackbox_solver: &'a B, + foreign_call_handler: &'a ForeignCallHandler, + ) -> Self { + ProgramExecutor { functions, blackbox_solver, foreign_call_handler } + } + + async fn execute(&self, initial_witness: WitnessMap) -> Result { + let main = &self.functions[0]; + + let mut witness_stack = WitnessStack::default(); + let main_witness = self.execute_circuit(main, initial_witness, &mut witness_stack).await?; + witness_stack.push(0, main_witness); + Ok(witness_stack) + } + + fn execute_circuit( + &'a self, + circuit: &'a Circuit, + initial_witness: WitnessMap, + witness_stack: &'a mut WitnessStack, + ) -> Pin> + 'a>> { + Box::pin(async { + let mut acvm = ACVM::new(self.blackbox_solver, &circuit.opcodes, initial_witness); + + loop { + let solver_status = acvm.solve(); + + match solver_status { + ACVMStatus::Solved => break, + ACVMStatus::InProgress => { + unreachable!("Execution should not stop while in `InProgress` state.") } - OpcodeResolutionError::BrilligFunctionFailed { call_stack, .. } => { - let failing_opcode = - call_stack.last().expect("Brillig error call stacks cannot be empty"); - (circuit.get_assert_message(*failing_opcode), Some(call_stack.clone())) + ACVMStatus::Failure(error) => { + let (assert_message, call_stack) = match &error { + OpcodeResolutionError::UnsatisfiedConstrain { + opcode_location: ErrorLocation::Resolved(opcode_location), + } + | OpcodeResolutionError::IndexOutOfBounds { + opcode_location: ErrorLocation::Resolved(opcode_location), + .. + } => ( + circuit.get_assert_message(*opcode_location), + Some(vec![*opcode_location]), + ), + OpcodeResolutionError::BrilligFunctionFailed { call_stack, .. } => { + let failing_opcode = call_stack + .last() + .expect("Brillig error call stacks cannot be empty"); + ( + circuit.get_assert_message(*failing_opcode), + Some(call_stack.clone()), + ) + } + _ => (None, None), + }; + + let error_string = match &assert_message { + Some(assert_message) => format!("Assertion failed: {}", assert_message), + None => error.to_string(), + }; + + return Err(JsExecutionError::new(error_string, call_stack).into()); } - _ => (None, None), - }; - - let error_string = match &assert_message { - Some(assert_message) => format!("Assertion failed: {}", assert_message), - None => error.to_string(), - }; + ACVMStatus::RequiresForeignCall(foreign_call) => { + let result = + resolve_brillig(self.foreign_call_handler, &foreign_call).await?; - return Err(JsExecutionError::new(error_string.into(), call_stack).into()); + acvm.resolve_pending_foreign_call(result); + } + ACVMStatus::RequiresAcirCall(call_info) => { + let acir_to_call = &self.functions[call_info.id as usize]; + let initial_witness = call_info.initial_witness; + let call_solved_witness = self + .execute_circuit(acir_to_call, initial_witness, witness_stack) + .await?; + let mut call_resolved_outputs = Vec::new(); + for return_witness_index in acir_to_call.return_values.indices() { + if let Some(return_value) = + call_solved_witness.get_index(return_witness_index) + { + call_resolved_outputs.push(*return_value); + } else { + // TODO: look at changing this call stack from None + return Err(JsExecutionError::new(format!("Failed to read from solved witness of ACIR call at witness {}", return_witness_index), None).into()); + } + } + acvm.resolve_pending_acir_call(call_resolved_outputs); + witness_stack.push(call_info.id, call_solved_witness.clone()); + } + } } - ACVMStatus::RequiresForeignCall(foreign_call) => { - let result = resolve_brillig(&foreign_call_handler, &foreign_call).await?; - acvm.resolve_pending_foreign_call(result); - } - } + Ok(acvm.finalize()) + }) } - - let witness_map = acvm.finalize(); - Ok(witness_map.into()) } diff --git a/acvm-repo/acvm_js/src/foreign_call/inputs.rs b/acvm-repo/acvm_js/src/foreign_call/inputs.rs index 728fc2d3d2f..ebd29fb7d58 100644 --- a/acvm-repo/acvm_js/src/foreign_call/inputs.rs +++ b/acvm-repo/acvm_js/src/foreign_call/inputs.rs @@ -8,8 +8,8 @@ pub(super) fn encode_foreign_call_inputs( let inputs = js_sys::Array::default(); for input in foreign_call_inputs { let input_array = js_sys::Array::default(); - for value in input.values() { - let hex_js_string = field_element_to_js_string(&value.to_field()); + for value in input.fields() { + let hex_js_string = field_element_to_js_string(&value); input_array.push(&hex_js_string); } inputs.push(&input_array); diff --git a/acvm-repo/acvm_js/src/foreign_call/outputs.rs b/acvm-repo/acvm_js/src/foreign_call/outputs.rs index 630b1afb6fd..78fa520aa15 100644 --- a/acvm-repo/acvm_js/src/foreign_call/outputs.rs +++ b/acvm-repo/acvm_js/src/foreign_call/outputs.rs @@ -1,18 +1,18 @@ -use acvm::brillig_vm::brillig::{ForeignCallParam, ForeignCallResult, Value}; +use acvm::brillig_vm::brillig::{ForeignCallParam, ForeignCallResult}; use wasm_bindgen::JsValue; use crate::js_witness_map::js_value_to_field_element; fn decode_foreign_call_output(output: JsValue) -> Result { if output.is_string() { - let value = Value::from(js_value_to_field_element(output)?); + let value = js_value_to_field_element(output)?; Ok(ForeignCallParam::Single(value)) } else if output.is_array() { let output = js_sys::Array::from(&output); - let mut values: Vec = Vec::with_capacity(output.length() as usize); + let mut values: Vec<_> = Vec::with_capacity(output.length() as usize); for elem in output.iter() { - values.push(Value::from(js_value_to_field_element(elem)?)); + values.push(js_value_to_field_element(elem)?); } Ok(ForeignCallParam::Array(values)) } else { diff --git a/acvm-repo/acvm_js/src/js_witness_stack.rs b/acvm-repo/acvm_js/src/js_witness_stack.rs new file mode 100644 index 00000000000..59f2dbc051e --- /dev/null +++ b/acvm-repo/acvm_js/src/js_witness_stack.rs @@ -0,0 +1,71 @@ +use acvm::acir::native_types::WitnessStack; +use js_sys::{Array, Map, Object}; +use wasm_bindgen::prelude::{wasm_bindgen, JsValue}; + +use crate::JsWitnessMap; + +#[wasm_bindgen(typescript_custom_section)] +const WITNESS_STACK: &'static str = r#" +export type StackItem = { + index: number; + witness: WitnessMap; +} + +export type WitnessStack = Array; +"#; + +// WitnessStack +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(extends = Array, js_name = "WitnessStack", typescript_type = "WitnessStack")] + #[derive(Clone, Debug, PartialEq, Eq)] + pub type JsWitnessStack; + + #[wasm_bindgen(constructor, js_class = "Array")] + pub fn new() -> JsWitnessStack; + + #[wasm_bindgen(extends = Object, js_name = "StackItem", typescript_type = "StackItem")] + #[derive(Clone, Debug, PartialEq, Eq)] + pub type JsStackItem; + + #[wasm_bindgen(constructor, js_class = "Object")] + pub fn new() -> JsStackItem; +} + +impl Default for JsWitnessStack { + fn default() -> Self { + Self::new() + } +} + +impl From for JsWitnessStack { + fn from(mut witness_stack: WitnessStack) -> Self { + let js_witness_stack = JsWitnessStack::new(); + while let Some(stack_item) = witness_stack.pop() { + let js_map = JsWitnessMap::from(stack_item.witness); + let js_index = JsValue::from_f64(stack_item.index.into()); + + let entry_map = Map::new(); + entry_map.set(&JsValue::from_str("index"), &js_index); + entry_map.set(&JsValue::from_str("witness"), &js_map); + let stack_item = Object::from_entries(&entry_map).unwrap(); + + js_witness_stack.push(&stack_item); + } + // `reverse()` returns an `Array` so we have to wrap it + JsWitnessStack { obj: js_witness_stack.reverse() } + } +} + +impl From for WitnessStack { + fn from(js_witness_stack: JsWitnessStack) -> Self { + let mut witness_stack = WitnessStack::default(); + js_witness_stack.for_each(&mut |stack_item, _, _| { + let values_array = Object::values(&Object::from(stack_item)); + let index = values_array.get(0).as_f64().unwrap() as u32; + let js_witness_map: JsWitnessMap = values_array.get(1).into(); + witness_stack.push(index, js_witness_map.into()); + }); + witness_stack + } +} diff --git a/acvm-repo/acvm_js/src/lib.rs b/acvm-repo/acvm_js/src/lib.rs index 88afd1767c9..d7ecc0ae192 100644 --- a/acvm-repo/acvm_js/src/lib.rs +++ b/acvm-repo/acvm_js/src/lib.rs @@ -1,31 +1,31 @@ -#![forbid(unsafe_code)] #![warn(unreachable_pub)] #![warn(clippy::semicolon_if_nothing_returned)] #![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))] -// TODO: Absence of per package targets -// https://doc.rust-lang.org/cargo/reference/unstable.html#per-package-target -// otherwise could be reorganized to make this file more pretty. +mod black_box_solvers; +mod build_info; +mod compression; +mod execute; +mod foreign_call; +mod js_execution_error; +mod js_witness_map; +mod js_witness_stack; +mod logging; +mod public_witness; -cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { - mod build_info; - mod compression; - mod execute; - mod foreign_call; - mod js_witness_map; - mod logging; - mod public_witness; - mod js_execution_error; - mod black_box_solvers; - - pub use black_box_solvers::{and, xor, sha256, blake2s256, keccak256, ecdsa_secp256k1_verify, ecdsa_secp256r1_verify}; - pub use build_info::build_info; - pub use compression::{compress_witness, decompress_witness}; - pub use execute::{execute_circuit, execute_circuit_with_black_box_solver, create_black_box_solver}; - pub use js_witness_map::JsWitnessMap; - pub use logging::init_log_level; - pub use public_witness::{get_public_parameters_witness, get_public_witness, get_return_witness}; - pub use js_execution_error::JsExecutionError; - } -} +pub use black_box_solvers::{ + and, blake2s256, ecdsa_secp256k1_verify, ecdsa_secp256r1_verify, keccak256, sha256, xor, +}; +pub use build_info::build_info; +pub use compression::{ + compress_witness, compress_witness_stack, decompress_witness, decompress_witness_stack, +}; +pub use execute::{ + create_black_box_solver, execute_circuit, execute_circuit_with_black_box_solver, + execute_program, execute_program_with_black_box_solver, +}; +pub use js_execution_error::JsExecutionError; +pub use js_witness_map::JsWitnessMap; +pub use js_witness_stack::JsWitnessStack; +pub use logging::init_log_level; +pub use public_witness::{get_public_parameters_witness, get_public_witness, get_return_witness}; diff --git a/acvm-repo/acvm_js/src/public_witness.rs b/acvm-repo/acvm_js/src/public_witness.rs index 8dc66c435b3..a0d5b5f8be2 100644 --- a/acvm-repo/acvm_js/src/public_witness.rs +++ b/acvm-repo/acvm_js/src/public_witness.rs @@ -1,5 +1,5 @@ use acvm::acir::{ - circuit::Circuit, + circuit::Program, native_types::{Witness, WitnessMap}, }; use js_sys::JsString; @@ -26,16 +26,25 @@ fn extract_indices(witness_map: &WitnessMap, indices: Vec) -> Result, + // TODO(https://github.com/noir-lang/noir/issues/4428): These need to be updated to match the same interfaces + // as the native ACVM executor. Right now native execution still only handles one circuit so I do not feel the need + // to break the JS interface just yet. + program: Vec, witness_map: JsWitnessMap, ) -> Result { console_error_panic_hook::set_once(); - let circuit: Circuit = - Circuit::deserialize_circuit(&circuit).expect("Failed to deserialize circuit"); + let program: Program = + Program::deserialize_program(&program).expect("Failed to deserialize circuit"); + let circuit = match program.functions.len() { + 0 => return Ok(JsWitnessMap::from(WitnessMap::new())), + 1 => &program.functions[0], + _ => return Err(JsString::from("Program contains multiple circuits however ACVM currently only supports programs containing a single circuit")) + }; + let witness_map = WitnessMap::from(witness_map); let return_witness = - extract_indices(&witness_map, circuit.return_values.0.into_iter().collect())?; + extract_indices(&witness_map, circuit.return_values.0.clone().into_iter().collect())?; Ok(JsWitnessMap::from(return_witness)) } @@ -47,16 +56,22 @@ pub fn get_return_witness( /// @returns {WitnessMap} A witness map containing the circuit's public parameters. #[wasm_bindgen(js_name = getPublicParametersWitness)] pub fn get_public_parameters_witness( - circuit: Vec, + program: Vec, solved_witness: JsWitnessMap, ) -> Result { console_error_panic_hook::set_once(); - let circuit: Circuit = - Circuit::deserialize_circuit(&circuit).expect("Failed to deserialize circuit"); + let program: Program = + Program::deserialize_program(&program).expect("Failed to deserialize circuit"); + let circuit = match program.functions.len() { + 0 => return Ok(JsWitnessMap::from(WitnessMap::new())), + 1 => &program.functions[0], + _ => return Err(JsString::from("Program contains multiple circuits however ACVM currently only supports programs containing a single circuit")) + }; + let witness_map = WitnessMap::from(solved_witness); let public_params_witness = - extract_indices(&witness_map, circuit.public_parameters.0.into_iter().collect())?; + extract_indices(&witness_map, circuit.public_parameters.0.clone().into_iter().collect())?; Ok(JsWitnessMap::from(public_params_witness)) } @@ -68,16 +83,22 @@ pub fn get_public_parameters_witness( /// @returns {WitnessMap} A witness map containing the circuit's public inputs. #[wasm_bindgen(js_name = getPublicWitness)] pub fn get_public_witness( - circuit: Vec, + program: Vec, solved_witness: JsWitnessMap, ) -> Result { console_error_panic_hook::set_once(); - let circuit: Circuit = - Circuit::deserialize_circuit(&circuit).expect("Failed to deserialize circuit"); + let program: Program = + Program::deserialize_program(&program).expect("Failed to deserialize circuit"); + let circuit = match program.functions.len() { + 0 => return Ok(JsWitnessMap::from(WitnessMap::new())), + 1 => &program.functions[0], + _ => return Err(JsString::from("Program contains multiple circuits however ACVM currently only supports programs containing a single circuit")) + }; + let witness_map = WitnessMap::from(solved_witness); let public_witness = - extract_indices(&witness_map, circuit.public_inputs().0.into_iter().collect())?; + extract_indices(&witness_map, circuit.public_inputs().0.clone().into_iter().collect())?; Ok(JsWitnessMap::from(public_witness)) } diff --git a/acvm-repo/acvm_js/test/node/build_info.test.ts b/acvm-repo/acvm_js/test/node/build_info.test.ts index 23100505011..014bb6f422d 100644 --- a/acvm-repo/acvm_js/test/node/build_info.test.ts +++ b/acvm-repo/acvm_js/test/node/build_info.test.ts @@ -3,12 +3,20 @@ import { BuildInfo, buildInfo } from '@noir-lang/acvm_js'; import child_process from 'child_process'; import pkg from '../../package.json'; -it('returns the correct build into', () => { +it('returns the correct build info', () => { + let revision: string; + + try { + revision = child_process.execSync('git rev-parse HEAD').toString().trim(); + } catch (error) { + console.log('Failed to get revision, skipping test.'); + return; + } + const info: BuildInfo = buildInfo(); // TODO: enforce that `package.json` and `Cargo.toml` are consistent. expect(info.version).to.be.eq(pkg.version); - const revision = child_process.execSync('git rev-parse HEAD').toString().trim(); expect(info.gitHash).to.be.eq(revision); }); diff --git a/acvm-repo/acvm_js/test/node/execute_circuit.test.ts b/acvm-repo/acvm_js/test/node/execute_circuit.test.ts index adee3c15312..32487f8bbba 100644 --- a/acvm-repo/acvm_js/test/node/execute_circuit.test.ts +++ b/acvm-repo/acvm_js/test/node/execute_circuit.test.ts @@ -6,6 +6,9 @@ import { WasmBlackBoxFunctionSolver, WitnessMap, ForeignCallHandler, + executeProgram, + WitnessStack, + StackItem, } from '@noir-lang/acvm_js'; it('successfully executes circuit and extracts return value', async () => { @@ -157,3 +160,37 @@ it('successfully executes 500 circuits with same backend', async function () { expect(solvedWitness).to.be.deep.eq(expectedWitnessMap); } }); + +/** + * Below are all the same tests as above but using `executeProgram` + * TODO: also add a couple tests for executing multiple circuits + */ +it('executeProgram: successfully executes program and extracts return value', async () => { + const { bytecode, initialWitnessMap, resultWitness, expectedResult } = await import('../shared/addition'); + + const witnessStack: WitnessStack = await executeProgram(bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); + + const solvedStackItem: StackItem = witnessStack[0]; + expect(solvedStackItem.index).to.be.eq(0); + const solvedWitnessMap: WitnessMap = solvedStackItem.witness; + + // Witness stack should be consistent with initial witness + initialWitnessMap.forEach((value, key) => { + expect(solvedWitnessMap.get(key) as string).to.be.eq(value); + }); + + // Solved witness should contain expected return value + expect(solvedWitnessMap.get(resultWitness)).to.be.eq(expectedResult); +}); + +it('executeProgram: successfully process a program of acir functions with a nested call', async () => { + const { bytecode, initialWitnessMap, expectedWitnessStack } = await import('../shared/nested_acir_call'); + + const witnessStack: WitnessStack = await executeProgram(bytecode, initialWitnessMap, () => { + throw Error('unexpected oracle'); + }); + + expect(witnessStack).to.be.deep.eq(expectedWitnessStack); +}); diff --git a/acvm-repo/acvm_js/test/node/witness_conversion.test.ts b/acvm-repo/acvm_js/test/node/witness_conversion.test.ts index 41291c894ea..c6dccb4c83d 100644 --- a/acvm-repo/acvm_js/test/node/witness_conversion.test.ts +++ b/acvm-repo/acvm_js/test/node/witness_conversion.test.ts @@ -1,6 +1,7 @@ import { expect } from 'chai'; -import { compressWitness, decompressWitness } from '@noir-lang/acvm_js'; +import { compressWitness, decompressWitness, compressWitnessStack, decompressWitnessStack } from '@noir-lang/acvm_js'; import { expectedCompressedWitnessMap, expectedWitnessMap } from '../shared/witness_compression'; +import { expectedCompressedWitnessStack, expectedWitnessStack } from '../shared/nested_acir_call'; it('successfully compresses the witness', () => { const compressedWitnessMap = compressWitness(expectedWitnessMap); @@ -13,3 +14,15 @@ it('successfully decompresses the witness', () => { expect(witnessMap).to.be.deep.eq(expectedWitnessMap); }); + +it('successfully compresses the witness stack', () => { + const compressedWitnessStack = compressWitnessStack(expectedWitnessStack); + + expect(compressedWitnessStack).to.be.deep.eq(expectedCompressedWitnessStack); +}); + +it('successfully decompresses the witness stack', () => { + const witnessStack = decompressWitnessStack(expectedCompressedWitnessStack); + + expect(witnessStack).to.be.deep.eq(expectedWitnessStack); +}); diff --git a/acvm-repo/acvm_js/test/shared/addition.ts b/acvm-repo/acvm_js/test/shared/addition.ts index 217902bdea6..b56a4286878 100644 --- a/acvm-repo/acvm_js/test/shared/addition.ts +++ b/acvm-repo/acvm_js/test/shared/addition.ts @@ -2,11 +2,11 @@ import { WitnessMap } from '@noir-lang/acvm_js'; // See `addition_circuit` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 208, 49, 14, 192, 32, 8, 5, 80, 212, 30, 8, 4, 20, 182, 94, 165, 166, 122, - 255, 35, 52, 77, 28, 76, 58, 214, 191, 124, 166, 23, 242, 15, 0, 8, 240, 77, 154, 125, 206, 198, 127, 161, 176, 209, - 138, 139, 197, 88, 68, 122, 205, 157, 152, 46, 204, 222, 76, 81, 180, 21, 35, 35, 53, 189, 179, 49, 119, 19, 171, 222, - 188, 162, 147, 112, 167, 161, 206, 99, 98, 105, 223, 95, 248, 26, 113, 90, 97, 185, 97, 217, 56, 173, 35, 63, 243, 81, - 87, 163, 125, 1, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 144, 75, 14, 128, 32, 12, 68, 249, 120, 160, 150, 182, 208, 238, 188, 138, 68, + 184, 255, 17, 212, 200, 130, 196, 165, 188, 164, 153, 174, 94, 38, 227, 221, 203, 118, 159, 119, 95, 226, 200, 125, + 36, 252, 3, 253, 66, 87, 152, 92, 4, 153, 185, 149, 212, 144, 240, 128, 100, 85, 5, 88, 106, 86, 84, 20, 149, 51, 41, + 81, 83, 214, 98, 213, 10, 24, 50, 53, 236, 98, 212, 135, 44, 174, 235, 5, 143, 35, 12, 151, 159, 126, 55, 109, 28, + 231, 145, 47, 245, 105, 191, 143, 133, 1, 0, 0, ]); export const initialWitnessMap: WitnessMap = new Map([ diff --git a/acvm-repo/acvm_js/test/shared/complex_foreign_call.ts b/acvm-repo/acvm_js/test/shared/complex_foreign_call.ts index 27abd72305f..e074cf1ad38 100644 --- a/acvm-repo/acvm_js/test/shared/complex_foreign_call.ts +++ b/acvm-repo/acvm_js/test/shared/complex_foreign_call.ts @@ -2,13 +2,13 @@ import { WitnessMap } from '@noir-lang/acvm_js'; // See `complex_brillig_foreign_call` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 84, 75, 10, 132, 48, 12, 125, 177, 163, 35, 179, 154, 35, 8, 51, 7, 232, 204, - 9, 188, 139, 184, 83, 116, 233, 241, 173, 152, 98, 12, 213, 141, 21, 244, 65, 232, 39, 175, 233, 35, 73, 155, 3, 32, - 204, 48, 206, 18, 158, 19, 175, 37, 60, 175, 228, 209, 30, 195, 143, 226, 197, 178, 103, 105, 76, 110, 160, 209, 156, - 160, 209, 247, 195, 69, 235, 29, 179, 46, 81, 243, 103, 2, 239, 231, 225, 44, 117, 150, 241, 250, 201, 99, 206, 251, - 96, 95, 161, 242, 14, 193, 243, 40, 162, 105, 253, 219, 12, 75, 47, 146, 186, 251, 37, 116, 86, 93, 219, 55, 245, 96, - 20, 85, 75, 253, 136, 249, 87, 249, 105, 231, 220, 4, 249, 237, 132, 56, 20, 224, 109, 113, 223, 88, 82, 153, 34, 64, - 34, 14, 164, 69, 172, 48, 2, 23, 243, 6, 31, 25, 5, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 84, 93, 10, 131, 48, 12, 78, 218, 233, 100, 111, 187, 193, 96, 59, 64, 231, 9, + 188, 139, 248, 166, 232, 163, 167, 23, 11, 126, 197, 24, 250, 34, 86, 208, 64, 72, 218, 252, 125, 36, 105, 153, 22, + 42, 60, 51, 116, 235, 217, 64, 103, 156, 37, 5, 191, 10, 210, 29, 163, 63, 167, 203, 229, 206, 194, 104, 110, 128, + 209, 158, 128, 49, 236, 195, 69, 231, 157, 114, 46, 73, 251, 103, 35, 239, 231, 225, 57, 243, 156, 227, 252, 132, 44, + 112, 79, 176, 125, 84, 223, 73, 248, 145, 152, 69, 149, 4, 107, 233, 114, 90, 119, 145, 85, 237, 151, 192, 89, 247, + 221, 208, 54, 163, 85, 174, 26, 234, 87, 232, 63, 101, 103, 21, 55, 169, 216, 73, 72, 249, 5, 197, 234, 132, 123, 179, + 35, 247, 155, 214, 246, 102, 20, 73, 204, 72, 168, 123, 191, 161, 25, 66, 136, 159, 187, 53, 5, 0, 0, ]); export const initialWitnessMap: WitnessMap = new Map([ [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], diff --git a/acvm-repo/acvm_js/test/shared/fixed_base_scalar_mul.ts b/acvm-repo/acvm_js/test/shared/fixed_base_scalar_mul.ts index c0859f50135..5aef521f231 100644 --- a/acvm-repo/acvm_js/test/shared/fixed_base_scalar_mul.ts +++ b/acvm-repo/acvm_js/test/shared/fixed_base_scalar_mul.ts @@ -1,8 +1,8 @@ // See `fixed_base_scalar_mul_circuit` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 138, 91, 10, 0, 32, 16, 2, 109, 171, 175, 46, 221, 209, 247, 229, 130, 130, - 140, 200, 92, 0, 11, 157, 228, 35, 127, 212, 200, 29, 61, 116, 76, 220, 217, 250, 171, 91, 113, 160, 66, 104, 242, 97, - 0, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 138, 81, 10, 0, 48, 8, 66, 87, 219, 190, 118, 233, 29, 61, 43, 3, 5, 121, 34, + 207, 86, 231, 162, 198, 157, 124, 228, 71, 157, 220, 232, 161, 227, 226, 206, 214, 95, 221, 74, 0, 116, 58, 13, 182, + 105, 0, 0, 0, ]); export const initialWitnessMap = new Map([ [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], diff --git a/acvm-repo/acvm_js/test/shared/foreign_call.ts b/acvm-repo/acvm_js/test/shared/foreign_call.ts index 0be8937b57d..eb14cb2e9f1 100644 --- a/acvm-repo/acvm_js/test/shared/foreign_call.ts +++ b/acvm-repo/acvm_js/test/shared/foreign_call.ts @@ -2,10 +2,10 @@ import { WitnessMap } from '@noir-lang/acvm_js'; // See `simple_brillig_foreign_call` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 143, 177, 10, 192, 32, 16, 67, 227, 21, 74, 233, 212, 79, 177, 127, 208, 159, - 233, 224, 226, 32, 226, 247, 139, 168, 16, 68, 93, 244, 45, 119, 228, 142, 144, 92, 0, 20, 50, 7, 237, 76, 213, 190, - 50, 245, 26, 175, 218, 231, 165, 57, 175, 148, 14, 137, 179, 147, 191, 114, 211, 221, 216, 240, 59, 63, 107, 221, 115, - 104, 181, 103, 244, 43, 36, 10, 38, 68, 108, 25, 253, 238, 136, 1, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 144, 61, 10, 192, 48, 8, 133, 53, 133, 82, 186, 245, 38, 233, 13, 122, 153, + 14, 93, 58, 132, 144, 227, 135, 252, 41, 56, 36, 46, 201, 7, 162, 168, 200, 123, 34, 52, 142, 28, 72, 245, 38, 106, 9, + 247, 30, 202, 118, 142, 27, 215, 221, 178, 82, 175, 33, 15, 133, 189, 163, 159, 57, 197, 252, 251, 195, 235, 188, 230, + 186, 16, 65, 255, 12, 239, 92, 131, 89, 149, 198, 77, 3, 10, 9, 119, 8, 198, 242, 152, 1, 0, 0, ]); export const initialWitnessMap: WitnessMap = new Map([ [1, '0x0000000000000000000000000000000000000000000000000000000000000005'], diff --git a/acvm-repo/acvm_js/test/shared/memory_op.ts b/acvm-repo/acvm_js/test/shared/memory_op.ts index b5ab64b3447..1d0e06b3c8a 100644 --- a/acvm-repo/acvm_js/test/shared/memory_op.ts +++ b/acvm-repo/acvm_js/test/shared/memory_op.ts @@ -1,9 +1,9 @@ // See `memory_op_circuit` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 145, 187, 17, 0, 32, 8, 67, 195, 111, 31, 220, 192, 253, 167, 178, 144, 2, - 239, 236, 132, 194, 52, 129, 230, 93, 8, 6, 64, 176, 101, 225, 28, 78, 49, 43, 238, 154, 225, 254, 166, 209, 205, 165, - 98, 174, 212, 177, 188, 187, 92, 255, 173, 92, 173, 190, 93, 82, 80, 78, 123, 14, 127, 60, 97, 1, 210, 144, 46, 242, - 19, 3, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 81, 201, 13, 0, 32, 8, 147, 195, 125, 112, 3, 247, 159, 74, 141, 60, 106, 226, + 79, 120, 216, 132, 180, 124, 154, 82, 168, 108, 212, 57, 2, 122, 129, 157, 201, 181, 150, 59, 186, 179, 189, 161, 101, + 251, 82, 176, 175, 196, 121, 89, 118, 185, 246, 91, 185, 26, 125, 187, 64, 80, 134, 29, 195, 31, 79, 24, 2, 250, 167, + 252, 27, 3, 0, 0, ]); export const initialWitnessMap = new Map([ diff --git a/acvm-repo/acvm_js/test/shared/nested_acir_call.ts b/acvm-repo/acvm_js/test/shared/nested_acir_call.ts new file mode 100644 index 00000000000..ce91282a681 --- /dev/null +++ b/acvm-repo/acvm_js/test/shared/nested_acir_call.ts @@ -0,0 +1,59 @@ +import { WitnessMap, StackItem, WitnessStack } from '@noir-lang/acvm_js'; + +// See `nested_acir_call_circuit` integration test in `acir/tests/test_program_serialization.rs`. +export const bytecode = Uint8Array.from([ + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 205, 146, 97, 10, 195, 32, 12, 133, 163, 66, 207, 147, 24, 109, 227, 191, 93, 101, + 50, 123, 255, 35, 172, 99, 25, 83, 17, 250, 99, 14, 250, 224, 97, 144, 16, 146, 143, 231, 224, 45, 167, 126, 105, 57, + 108, 14, 91, 248, 202, 168, 65, 255, 207, 122, 28, 180, 250, 244, 221, 244, 197, 223, 68, 182, 154, 197, 184, 134, 80, + 54, 95, 136, 233, 142, 62, 101, 137, 24, 98, 94, 133, 132, 162, 196, 135, 23, 230, 34, 65, 182, 148, 211, 134, 137, 2, + 23, 218, 99, 226, 93, 135, 185, 121, 123, 33, 84, 12, 234, 218, 192, 64, 174, 3, 248, 47, 88, 48, 17, 150, 157, 183, + 151, 95, 244, 86, 91, 221, 61, 10, 81, 31, 178, 190, 110, 194, 102, 96, 76, 251, 202, 80, 13, 204, 77, 224, 25, 176, + 70, 79, 197, 128, 18, 64, 3, 4, 0, 0, +]); + +export const initialWitnessMap: WitnessMap = new Map([ + [0, '0x0000000000000000000000000000000000000000000000000000000000000008'], + [1, '0x000000000000000000000000000000000000000000000000000000000000000a'], +]); + +const inner_call_witness: StackItem = { + index: 2, + witness: new Map([ + [0, '0x000000000000000000000000000000000000000000000000000000000000000a'], + [1, '0x000000000000000000000000000000000000000000000000000000000000000a'], + ]), +}; + +const nested_call_witness: StackItem = { + index: 1, + witness: new Map([ + [0, '0x0000000000000000000000000000000000000000000000000000000000000008'], + [1, '0x000000000000000000000000000000000000000000000000000000000000000a'], + [2, '0x000000000000000000000000000000000000000000000000000000000000000a'], + [3, '0x000000000000000000000000000000000000000000000000000000000000000a'], + ]), +}; + +const main_witness: StackItem = { + index: 0, + witness: new Map([ + [0, '0x0000000000000000000000000000000000000000000000000000000000000008'], + [1, '0x000000000000000000000000000000000000000000000000000000000000000a'], + [2, '0x000000000000000000000000000000000000000000000000000000000000000a'], + [3, '0x000000000000000000000000000000000000000000000000000000000000000a'], + ]), +}; + +export const expectedWitnessStack: WitnessStack = [ + inner_call_witness, + nested_call_witness, + inner_call_witness, + nested_call_witness, + main_witness, +]; + +export const expectedCompressedWitnessStack = Uint8Array.from([ + 31, 139, 8, 0, 0, 0, 0, 0, 2, 255, 237, 145, 177, 13, 0, 32, 8, 4, 17, 117, 31, 75, 75, 87, 113, 255, 37, 44, 196, 5, + 228, 42, 194, 39, 132, 238, 114, 249, 239, 114, 163, 118, 47, 203, 254, 240, 101, 23, 152, 213, 120, 199, 73, 58, 42, + 200, 170, 176, 87, 238, 27, 119, 95, 201, 238, 190, 89, 7, 37, 195, 196, 176, 4, 5, 0, 0, +]); diff --git a/acvm-repo/acvm_js/test/shared/pedersen.ts b/acvm-repo/acvm_js/test/shared/pedersen.ts index 5150d24131c..00d207053d8 100644 --- a/acvm-repo/acvm_js/test/shared/pedersen.ts +++ b/acvm-repo/acvm_js/test/shared/pedersen.ts @@ -1,7 +1,7 @@ // See `pedersen_circuit` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 74, 135, 9, 0, 48, 8, 75, 171, 224, 255, 15, 139, 27, 196, 64, 200, 100, 0, 15, - 133, 80, 57, 89, 219, 127, 39, 173, 126, 235, 236, 247, 151, 48, 224, 71, 90, 33, 97, 0, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 93, 74, 7, 6, 0, 0, 8, 108, 209, 255, 63, 156, 54, 233, 56, 55, 17, 26, 18, 196, + 241, 169, 250, 178, 141, 167, 32, 159, 254, 234, 238, 255, 87, 112, 52, 63, 63, 101, 105, 0, 0, 0, ]); export const initialWitnessMap = new Map([[1, '0x0000000000000000000000000000000000000000000000000000000000000001']]); diff --git a/acvm-repo/acvm_js/test/shared/schnorr_verify.ts b/acvm-repo/acvm_js/test/shared/schnorr_verify.ts index 2127de66f69..14c32c615c8 100644 --- a/acvm-repo/acvm_js/test/shared/schnorr_verify.ts +++ b/acvm-repo/acvm_js/test/shared/schnorr_verify.ts @@ -1,17 +1,17 @@ // See `schnorr_verify_circuit` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 210, 7, 74, 3, 1, 20, 69, 209, 177, 247, 222, 123, 239, 189, 119, 141, 93, 99, - 220, 133, 251, 95, 130, 152, 103, 78, 32, 3, 195, 33, 4, 66, 248, 239, 254, 20, 69, 209, 84, 212, 158, 216, 206, 223, - 234, 219, 204, 146, 239, 91, 170, 111, 103, 245, 109, 101, 27, 219, 217, 193, 250, 219, 197, 110, 246, 176, 151, 125, - 236, 231, 0, 7, 57, 196, 97, 142, 112, 148, 99, 28, 231, 4, 39, 57, 197, 105, 206, 112, 150, 115, 156, 231, 2, 23, - 185, 196, 101, 174, 112, 149, 107, 92, 231, 6, 55, 185, 197, 109, 238, 112, 151, 123, 220, 231, 1, 15, 121, 196, 99, - 158, 240, 148, 103, 60, 231, 5, 47, 121, 197, 107, 222, 240, 150, 119, 188, 231, 3, 75, 124, 228, 83, 195, 142, 121, - 158, 125, 126, 225, 43, 223, 248, 206, 15, 126, 178, 204, 47, 86, 248, 237, 119, 43, 76, 127, 105, 47, 189, 165, 181, - 116, 150, 198, 234, 125, 117, 249, 47, 233, 41, 45, 165, 163, 52, 148, 126, 210, 78, 186, 73, 51, 233, 37, 173, 164, - 147, 52, 146, 62, 210, 70, 186, 72, 19, 233, 33, 45, 164, 131, 52, 144, 253, 23, 139, 218, 238, 217, 60, 123, 103, - 235, 236, 156, 141, 179, 239, 166, 93, 183, 237, 185, 107, 199, 125, 251, 29, 218, 237, 216, 94, 167, 118, 58, 183, - 207, 165, 93, 174, 237, 113, 107, 135, 123, 247, 47, 185, 251, 147, 59, 191, 184, 239, 155, 187, 126, 184, 103, 217, - 29, 235, 55, 171, 223, 173, 104, 184, 231, 255, 243, 7, 236, 52, 239, 128, 225, 3, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 77, 210, 7, 78, 2, 1, 20, 69, 81, 236, 189, 247, 222, 123, 239, 93, 177, 33, 34, + 238, 194, 253, 47, 193, 200, 147, 67, 194, 36, 147, 163, 33, 33, 228, 191, 219, 82, 168, 63, 63, 181, 183, 197, 223, + 177, 147, 191, 181, 183, 149, 69, 159, 183, 213, 222, 238, 218, 219, 206, 14, 118, 178, 139, 141, 183, 135, 189, 236, + 99, 63, 7, 56, 200, 33, 14, 115, 132, 163, 28, 227, 56, 39, 56, 201, 41, 78, 115, 134, 179, 156, 227, 60, 23, 184, + 200, 37, 46, 115, 133, 171, 92, 227, 58, 55, 184, 201, 45, 110, 115, 135, 187, 220, 227, 62, 15, 120, 200, 35, 30, + 243, 132, 167, 60, 227, 57, 47, 120, 201, 43, 94, 243, 134, 183, 188, 227, 61, 31, 248, 200, 39, 22, 249, 204, 151, + 166, 29, 243, 188, 250, 255, 141, 239, 44, 241, 131, 101, 126, 178, 194, 47, 86, 249, 237, 123, 171, 76, 127, 105, 47, + 189, 165, 181, 116, 150, 198, 26, 125, 245, 248, 45, 233, 41, 45, 165, 163, 52, 148, 126, 210, 78, 186, 73, 51, 233, + 37, 173, 164, 147, 52, 146, 62, 210, 70, 186, 72, 19, 233, 33, 45, 164, 131, 52, 144, 253, 151, 11, 245, 221, 179, + 121, 246, 206, 214, 217, 57, 27, 103, 223, 109, 187, 238, 218, 115, 223, 142, 135, 246, 59, 182, 219, 169, 189, 206, + 237, 116, 105, 159, 107, 187, 220, 218, 227, 222, 14, 143, 238, 95, 116, 247, 23, 119, 126, 115, 223, 146, 187, 150, + 221, 179, 226, 142, 141, 155, 53, 238, 86, 104, 186, 231, 255, 243, 7, 100, 141, 232, 192, 233, 3, 0, 0, ]); export const initialWitnessMap = new Map([ diff --git a/acvm-repo/acvm_js/test/shared/witness_compression.ts b/acvm-repo/acvm_js/test/shared/witness_compression.ts index 36b9a0284af..d2326c1b11b 100644 --- a/acvm-repo/acvm_js/test/shared/witness_compression.ts +++ b/acvm-repo/acvm_js/test/shared/witness_compression.ts @@ -4,19 +4,21 @@ // assert(x != y); // x + y // } +// +// Regenerate this byte array by going to the Noir integration tests and running `/test_programs/execution_success/witness_compression` +// after recompiling Noir to print the witness byte array to be written to file after execution export const expectedCompressedWitnessMap = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 2, 255, 173, 208, 187, 13, 128, 48, 12, 4, 80, 190, 153, 199, 142, 237, 196, 238, 88, 133, - 8, 103, 255, 17, 64, 34, 5, 61, 62, 233, 164, 171, 94, 113, 105, 122, 51, 63, 61, 198, 134, 127, 193, 37, 206, 202, - 235, 199, 34, 40, 204, 94, 179, 35, 225, 9, 217, 154, 10, 176, 180, 162, 168, 40, 42, 87, 86, 34, 87, 214, 106, 205, - 42, 24, 50, 57, 118, 49, 234, 3, 219, 2, 173, 61, 240, 175, 20, 103, 209, 13, 151, 252, 77, 33, 208, 1, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 2, 255, 173, 206, 185, 13, 0, 48, 8, 67, 209, 144, 107, 30, 146, 44, 144, 253, 167, 162, + 65, 130, 158, 239, 198, 174, 158, 44, 45, 178, 211, 254, 222, 90, 203, 17, 206, 186, 29, 252, 53, 64, 107, 114, 150, + 46, 206, 122, 6, 24, 73, 44, 193, 220, 1, 0, 0, ]); export const expectedWitnessMap = new Map([ - [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], - [2, '0x0000000000000000000000000000000000000000000000000000000000000002'], - [3, '0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000'], - [4, '0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000'], - [5, '0x0000000000000000000000000000000000000000000000000000000000000001'], - [6, '0x0000000000000000000000000000000000000000000000000000000000000003'], + [0, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [1, '0x0000000000000000000000000000000000000000000000000000000000000002'], + [2, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [3, '0x0000000000000000000000000000000000000000000000000000000000000001'], + [4, '0x0000000000000000000000000000000000000000000000000000000000000000'], + [5, '0x0000000000000000000000000000000000000000000000000000000000000003'], ]); diff --git a/acvm-repo/blackbox_solver/Cargo.toml b/acvm-repo/blackbox_solver/Cargo.toml index 0794b2dbe7e..8f5ff862360 100644 --- a/acvm-repo/blackbox_solver/Cargo.toml +++ b/acvm-repo/blackbox_solver/Cargo.toml @@ -2,7 +2,7 @@ name = "acvm_blackbox_solver" description = "A solver for the blackbox functions found in ACIR and Brillig" # x-release-please-start-version -version = "0.40.0" +version = "0.42.0" # x-release-please-end authors.workspace = true edition.workspace = true diff --git a/acvm-repo/blackbox_solver/src/ecdsa/mod.rs b/acvm-repo/blackbox_solver/src/ecdsa/mod.rs new file mode 100644 index 00000000000..cb3134bf0ab --- /dev/null +++ b/acvm-repo/blackbox_solver/src/ecdsa/mod.rs @@ -0,0 +1,22 @@ +use crate::BlackBoxResolutionError; + +mod secp256k1; +mod secp256r1; + +pub fn ecdsa_secp256k1_verify( + hashed_msg: &[u8], + public_key_x: &[u8; 32], + public_key_y: &[u8; 32], + signature: &[u8; 64], +) -> Result { + Ok(secp256k1::verify_signature(hashed_msg, public_key_x, public_key_y, signature)) +} + +pub fn ecdsa_secp256r1_verify( + hashed_msg: &[u8], + public_key_x: &[u8; 32], + public_key_y: &[u8; 32], + signature: &[u8; 64], +) -> Result { + Ok(secp256r1::verify_signature(hashed_msg, public_key_x, public_key_y, signature)) +} diff --git a/acvm-repo/blackbox_solver/src/ecdsa/secp256k1.rs b/acvm-repo/blackbox_solver/src/ecdsa/secp256k1.rs new file mode 100644 index 00000000000..17c51353f7f --- /dev/null +++ b/acvm-repo/blackbox_solver/src/ecdsa/secp256k1.rs @@ -0,0 +1,137 @@ +use k256::elliptic_curve::sec1::FromEncodedPoint; +use k256::elliptic_curve::PrimeField; + +use blake2::digest::generic_array::GenericArray; +use k256::{ecdsa::Signature, Scalar}; +use k256::{ + elliptic_curve::{ + sec1::{Coordinates, ToEncodedPoint}, + IsHigh, + }, + AffinePoint, EncodedPoint, ProjectivePoint, PublicKey, +}; + +pub(super) fn verify_signature( + hashed_msg: &[u8], + public_key_x_bytes: &[u8; 32], + public_key_y_bytes: &[u8; 32], + signature: &[u8; 64], +) -> bool { + // Convert the inputs into k256 data structures + let Ok(signature) = Signature::try_from(signature.as_slice()) else { + // Signature `r` and `s` are forbidden from being zero. + return false; + }; + + let point = EncodedPoint::from_affine_coordinates( + public_key_x_bytes.into(), + public_key_y_bytes.into(), + true, + ); + + let pubkey = PublicKey::from_encoded_point(&point); + let pubkey = if pubkey.is_some().into() { + pubkey.unwrap() + } else { + // Public key must sit on the Secp256k1 curve. + return false; + }; + + // Note: This is incorrect as it will panic if `hashed_msg >= k256::Secp256k1::ORDER`. + // In this scenario we should just take the leftmost bits from `hashed_msg` up to the group order length. + let z = Scalar::from_repr(*GenericArray::from_slice(hashed_msg)).unwrap(); + + // Finished converting bytes into data structures + + let r = signature.r(); + let s = signature.s(); + + // Ensure signature is "low S" normalized ala BIP 0062 + if s.is_high().into() { + return false; + } + + let s_inv = s.invert().unwrap(); + let u1 = z * s_inv; + let u2 = *r * s_inv; + + #[allow(non_snake_case)] + let R: AffinePoint = ((ProjectivePoint::GENERATOR * u1) + + (ProjectivePoint::from(*pubkey.as_affine()) * u2)) + .to_affine(); + + match R.to_encoded_point(false).coordinates() { + Coordinates::Uncompressed { x, y: _ } => Scalar::from_repr(*x).unwrap().eq(&r), + _ => unreachable!("Point is uncompressed"), + } +} + +#[cfg(test)] +mod secp256k1_tests { + use super::verify_signature; + + // 0x3a73f4123a5cd2121f21cd7e8d358835476949d035d9c2da6806b4633ac8c1e2, + const HASHED_MESSAGE: [u8; 32] = [ + 0x3a, 0x73, 0xf4, 0x12, 0x3a, 0x5c, 0xd2, 0x12, 0x1f, 0x21, 0xcd, 0x7e, 0x8d, 0x35, 0x88, + 0x35, 0x47, 0x69, 0x49, 0xd0, 0x35, 0xd9, 0xc2, 0xda, 0x68, 0x06, 0xb4, 0x63, 0x3a, 0xc8, + 0xc1, 0xe2, + ]; + // 0xa0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7 + const PUB_KEY_X: [u8; 32] = [ + 0xa0, 0x43, 0x4d, 0x9e, 0x47, 0xf3, 0xc8, 0x62, 0x35, 0x47, 0x7c, 0x7b, 0x1a, 0xe6, 0xae, + 0x5d, 0x34, 0x42, 0xd4, 0x9b, 0x19, 0x43, 0xc2, 0xb7, 0x52, 0xa6, 0x8e, 0x2a, 0x47, 0xe2, + 0x47, 0xc7, + ]; + // 0x893aba425419bc27a3b6c7e693a24c696f794c2ed877a1593cbee53b037368d7 + const PUB_KEY_Y: [u8; 32] = [ + 0x89, 0x3a, 0xba, 0x42, 0x54, 0x19, 0xbc, 0x27, 0xa3, 0xb6, 0xc7, 0xe6, 0x93, 0xa2, 0x4c, + 0x69, 0x6f, 0x79, 0x4c, 0x2e, 0xd8, 0x77, 0xa1, 0x59, 0x3c, 0xbe, 0xe5, 0x3b, 0x03, 0x73, + 0x68, 0xd7, + ]; + // 0xe5081c80ab427dc370346f4a0e31aa2bad8d9798c38061db9ae55a4e8df454fd28119894344e71b78770cc931d61f480ecbb0b89d6eb69690161e49a715fcd55 + const SIGNATURE: [u8; 64] = [ + 0xe5, 0x08, 0x1c, 0x80, 0xab, 0x42, 0x7d, 0xc3, 0x70, 0x34, 0x6f, 0x4a, 0x0e, 0x31, 0xaa, + 0x2b, 0xad, 0x8d, 0x97, 0x98, 0xc3, 0x80, 0x61, 0xdb, 0x9a, 0xe5, 0x5a, 0x4e, 0x8d, 0xf4, + 0x54, 0xfd, 0x28, 0x11, 0x98, 0x94, 0x34, 0x4e, 0x71, 0xb7, 0x87, 0x70, 0xcc, 0x93, 0x1d, + 0x61, 0xf4, 0x80, 0xec, 0xbb, 0x0b, 0x89, 0xd6, 0xeb, 0x69, 0x69, 0x01, 0x61, 0xe4, 0x9a, + 0x71, 0x5f, 0xcd, 0x55, + ]; + + #[test] + fn verifies_valid_signature_with_low_s_value() { + let valid = verify_signature(&HASHED_MESSAGE, &PUB_KEY_X, &PUB_KEY_Y, &SIGNATURE); + + assert!(valid); + } + + #[test] + fn rejects_invalid_signature() { + // This signature is invalid as ECDSA specifies that `r` and `s` must be non-zero. + let invalid_signature: [u8; 64] = [0x00; 64]; + + let valid = verify_signature(&HASHED_MESSAGE, &PUB_KEY_X, &PUB_KEY_Y, &invalid_signature); + assert!(!valid); + } + + #[test] + fn rejects_invalid_public_key() { + let invalid_pub_key_x: [u8; 32] = [0xff; 32]; + let invalid_pub_key_y: [u8; 32] = [0xff; 32]; + + let valid = + verify_signature(&HASHED_MESSAGE, &invalid_pub_key_x, &invalid_pub_key_y, &SIGNATURE); + + assert!(!valid); + } + + #[test] + #[ignore = "ECDSA verification does not currently handle long hashes correctly"] + fn trims_overly_long_hashes_to_correct_length() { + let mut long_hashed_message = HASHED_MESSAGE.to_vec(); + long_hashed_message.push(0xff); + + let valid = verify_signature(&long_hashed_message, &PUB_KEY_X, &PUB_KEY_Y, &SIGNATURE); + + assert!(valid); + } +} diff --git a/acvm-repo/blackbox_solver/src/ecdsa/secp256r1.rs b/acvm-repo/blackbox_solver/src/ecdsa/secp256r1.rs new file mode 100644 index 00000000000..54559d7c774 --- /dev/null +++ b/acvm-repo/blackbox_solver/src/ecdsa/secp256r1.rs @@ -0,0 +1,133 @@ +use p256::elliptic_curve::sec1::FromEncodedPoint; +use p256::elliptic_curve::PrimeField; + +use blake2::digest::generic_array::GenericArray; +use p256::{ecdsa::Signature, Scalar}; +use p256::{ + elliptic_curve::{ + sec1::{Coordinates, ToEncodedPoint}, + IsHigh, + }, + AffinePoint, EncodedPoint, ProjectivePoint, PublicKey, +}; + +pub(super) fn verify_signature( + hashed_msg: &[u8], + public_key_x_bytes: &[u8; 32], + public_key_y_bytes: &[u8; 32], + signature: &[u8; 64], +) -> bool { + // Convert the inputs into k256 data structures + let Ok(signature) = Signature::try_from(signature.as_slice()) else { + // Signature `r` and `s` are forbidden from being zero. + return false; + }; + + let point = EncodedPoint::from_affine_coordinates( + public_key_x_bytes.into(), + public_key_y_bytes.into(), + true, + ); + + let pubkey = PublicKey::from_encoded_point(&point); + let pubkey = if pubkey.is_some().into() { + pubkey.unwrap() + } else { + // Public key must sit on the Secp256r1 curve. + return false; + }; + + // Note: This is incorrect as it will panic if `hashed_msg >= p256::NistP256::ORDER`. + // In this scenario we should just take the leftmost bits from `hashed_msg` up to the group order length. + let z = Scalar::from_repr(*GenericArray::from_slice(hashed_msg)).unwrap(); + + // Finished converting bytes into data structures + + let r = signature.r(); + let s = signature.s(); + + // Ensure signature is "low S" normalized ala BIP 0062 + if s.is_high().into() { + return false; + } + + let s_inv = s.invert().unwrap(); + let u1 = z * s_inv; + let u2 = *r * s_inv; + + #[allow(non_snake_case)] + let R: AffinePoint = ((ProjectivePoint::GENERATOR * u1) + + (ProjectivePoint::from(*pubkey.as_affine()) * u2)) + .to_affine(); + + match R.to_encoded_point(false).coordinates() { + Coordinates::Uncompressed { x, y: _ } => Scalar::from_repr(*x).unwrap().eq(&r), + _ => unreachable!("Point is uncompressed"), + } +} + +#[cfg(test)] +mod secp256r1_tests { + use super::verify_signature; + + // 0x54705ba3baafdbdfba8c5f9a70f7a89bee98d906b53e31074da7baecdc0da9ad + const HASHED_MESSAGE: [u8; 32] = [ + 84, 112, 91, 163, 186, 175, 219, 223, 186, 140, 95, 154, 112, 247, 168, 155, 238, 152, 217, + 6, 181, 62, 49, 7, 77, 167, 186, 236, 220, 13, 169, 173, + ]; + // 0x550f471003f3df97c3df506ac797f6721fb1a1fb7b8f6f83d224498a65c88e24 + const PUB_KEY_X: [u8; 32] = [ + 85, 15, 71, 16, 3, 243, 223, 151, 195, 223, 80, 106, 199, 151, 246, 114, 31, 177, 161, 251, + 123, 143, 111, 131, 210, 36, 73, 138, 101, 200, 142, 36, + ]; + // 0x136093d7012e509a73715cbd0b00a3cc0ff4b5c01b3ffa196ab1fb327036b8e6 + const PUB_KEY_Y: [u8; 32] = [ + 19, 96, 147, 215, 1, 46, 80, 154, 115, 113, 92, 189, 11, 0, 163, 204, 15, 244, 181, 192, + 27, 63, 250, 25, 106, 177, 251, 50, 112, 54, 184, 230, + ]; + // 0x2c70a8d084b62bfc5ce03641caf9f72ad4da8c81bfe6ec9487bb5e1bef62a13218ad9ee29eaf351fdc50f1520c425e9b908a07278b43b0ec7b872778c14e0784 + const SIGNATURE: [u8; 64] = [ + 44, 112, 168, 208, 132, 182, 43, 252, 92, 224, 54, 65, 202, 249, 247, 42, 212, 218, 140, + 129, 191, 230, 236, 148, 135, 187, 94, 27, 239, 98, 161, 50, 24, 173, 158, 226, 158, 175, + 53, 31, 220, 80, 241, 82, 12, 66, 94, 155, 144, 138, 7, 39, 139, 67, 176, 236, 123, 135, + 39, 120, 193, 78, 7, 132, + ]; + + #[test] + fn verifies_valid_signature_with_low_s_value() { + let valid = verify_signature(&HASHED_MESSAGE, &PUB_KEY_X, &PUB_KEY_Y, &SIGNATURE); + + assert!(valid); + } + + #[test] + fn rejects_invalid_signature() { + // This signature is invalid as ECDSA specifies that `r` and `s` must be non-zero. + let invalid_signature: [u8; 64] = [0x00; 64]; + + let valid = verify_signature(&HASHED_MESSAGE, &PUB_KEY_X, &PUB_KEY_Y, &invalid_signature); + assert!(!valid); + } + + #[test] + fn rejects_invalid_public_key() { + let invalid_pub_key_x: [u8; 32] = [0xff; 32]; + let invalid_pub_key_y: [u8; 32] = [0xff; 32]; + + let valid = + verify_signature(&HASHED_MESSAGE, &invalid_pub_key_x, &invalid_pub_key_y, &SIGNATURE); + + assert!(!valid); + } + + #[test] + #[ignore = "ECDSA verification does not currently handle long hashes correctly"] + fn trims_overly_long_hashes_to_correct_length() { + let mut long_hashed_message = HASHED_MESSAGE.to_vec(); + long_hashed_message.push(0xff); + + let valid = verify_signature(&long_hashed_message, &PUB_KEY_X, &PUB_KEY_Y, &SIGNATURE); + + assert!(valid); + } +} diff --git a/acvm-repo/blackbox_solver/src/hash.rs b/acvm-repo/blackbox_solver/src/hash.rs new file mode 100644 index 00000000000..ac56029b436 --- /dev/null +++ b/acvm-repo/blackbox_solver/src/hash.rs @@ -0,0 +1,126 @@ +use acir::BlackBoxFunc; +use blake2::digest::generic_array::GenericArray; +use blake2::{Blake2s256, Digest}; +use sha2::Sha256; +use sha3::Keccak256; + +use crate::BlackBoxResolutionError; + +/// Does a generic hash of the inputs returning the resulting 32 bytes separately. +fn generic_hash_256(message: &[u8]) -> Result<[u8; 32], String> { + let output_bytes: [u8; 32] = + D::digest(message).as_slice().try_into().map_err(|_| "digest should be 256 bits")?; + + Ok(output_bytes) +} + +pub fn sha256(inputs: &[u8]) -> Result<[u8; 32], BlackBoxResolutionError> { + generic_hash_256::(inputs) + .map_err(|err| BlackBoxResolutionError::Failed(BlackBoxFunc::SHA256, err)) +} + +pub fn blake2s(inputs: &[u8]) -> Result<[u8; 32], BlackBoxResolutionError> { + generic_hash_256::(inputs) + .map_err(|err| BlackBoxResolutionError::Failed(BlackBoxFunc::Blake2s, err)) +} + +pub fn blake3(inputs: &[u8]) -> Result<[u8; 32], BlackBoxResolutionError> { + Ok(blake3::hash(inputs).into()) +} + +pub fn keccak256(inputs: &[u8]) -> Result<[u8; 32], BlackBoxResolutionError> { + generic_hash_256::(inputs) + .map_err(|err| BlackBoxResolutionError::Failed(BlackBoxFunc::Keccak256, err)) +} + +pub fn sha256compression(state: &mut [u32; 8], msg_blocks: &[u32; 16]) { + let mut blocks = [0_u8; 64]; + for (i, block) in msg_blocks.iter().enumerate() { + let bytes = block.to_be_bytes(); + blocks[i * 4..i * 4 + 4].copy_from_slice(&bytes); + } + let blocks: GenericArray = blocks.into(); + sha2::compress256(state, &[blocks]); +} + +const KECCAK_LANES: usize = 25; + +pub fn keccakf1600( + mut state: [u64; KECCAK_LANES], +) -> Result<[u64; KECCAK_LANES], BlackBoxResolutionError> { + keccak::f1600(&mut state); + Ok(state) +} + +#[cfg(test)] +mod keccakf1600_tests { + use super::keccakf1600; + + #[test] + fn sanity_check() { + // Test vectors are copied from XKCP (eXtended Keccak Code Package) + // https://github.com/XKCP/XKCP/blob/master/tests/TestVectors/KeccakF-1600-IntermediateValues.txt + let zero_state = [0u64; 25]; + + let expected_state_first = [ + 0xF1258F7940E1DDE7, + 0x84D5CCF933C0478A, + 0xD598261EA65AA9EE, + 0xBD1547306F80494D, + 0x8B284E056253D057, + 0xFF97A42D7F8E6FD4, + 0x90FEE5A0A44647C4, + 0x8C5BDA0CD6192E76, + 0xAD30A6F71B19059C, + 0x30935AB7D08FFC64, + 0xEB5AA93F2317D635, + 0xA9A6E6260D712103, + 0x81A57C16DBCF555F, + 0x43B831CD0347C826, + 0x01F22F1A11A5569F, + 0x05E5635A21D9AE61, + 0x64BEFEF28CC970F2, + 0x613670957BC46611, + 0xB87C5A554FD00ECB, + 0x8C3EE88A1CCF32C8, + 0x940C7922AE3A2614, + 0x1841F924A2C509E4, + 0x16F53526E70465C2, + 0x75F644E97F30A13B, + 0xEAF1FF7B5CECA249, + ]; + let expected_state_second = [ + 0x2D5C954DF96ECB3C, + 0x6A332CD07057B56D, + 0x093D8D1270D76B6C, + 0x8A20D9B25569D094, + 0x4F9C4F99E5E7F156, + 0xF957B9A2DA65FB38, + 0x85773DAE1275AF0D, + 0xFAF4F247C3D810F7, + 0x1F1B9EE6F79A8759, + 0xE4FECC0FEE98B425, + 0x68CE61B6B9CE68A1, + 0xDEEA66C4BA8F974F, + 0x33C43D836EAFB1F5, + 0xE00654042719DBD9, + 0x7CF8A9F009831265, + 0xFD5449A6BF174743, + 0x97DDAD33D8994B40, + 0x48EAD5FC5D0BE774, + 0xE3B8C8EE55B7B03C, + 0x91A0226E649E42E9, + 0x900E3129E7BADD7B, + 0x202A9EC5FAA3CCE8, + 0x5B3402464E1C3DB6, + 0x609F4E62A44C1059, + 0x20D06CD26A8FBF5C, + ]; + + let state_first = keccakf1600(zero_state).unwrap(); + let state_second = keccakf1600(state_first).unwrap(); + + assert_eq!(state_first, expected_state_first); + assert_eq!(state_second, expected_state_second); + } +} diff --git a/acvm-repo/blackbox_solver/src/lib.rs b/acvm-repo/blackbox_solver/src/lib.rs index e033344fefa..dc798bdab32 100644 --- a/acvm-repo/blackbox_solver/src/lib.rs +++ b/acvm-repo/blackbox_solver/src/lib.rs @@ -8,456 +8,18 @@ //! For functions that have a reference implementation, such as [keccak256], this crate exports the reference implementation directly. use acir::BlackBoxFunc; -use blake2::digest::generic_array::GenericArray; -use blake2::{Blake2s256, Digest}; -use sha2::Sha256; -use sha3::Keccak256; use thiserror::Error; mod curve_specific_solver; +mod ecdsa; +mod hash; pub use curve_specific_solver::{BlackBoxFunctionSolver, StubbedBlackBoxSolver}; +pub use ecdsa::{ecdsa_secp256k1_verify, ecdsa_secp256r1_verify}; +pub use hash::{blake2s, blake3, keccak256, keccakf1600, sha256, sha256compression}; #[derive(Clone, PartialEq, Eq, Debug, Error)] pub enum BlackBoxResolutionError { #[error("failed to solve blackbox function: {0}, reason: {1}")] Failed(BlackBoxFunc, String), } - -pub fn sha256(inputs: &[u8]) -> Result<[u8; 32], BlackBoxResolutionError> { - generic_hash_256::(inputs) - .map_err(|err| BlackBoxResolutionError::Failed(BlackBoxFunc::SHA256, err)) -} - -pub fn blake2s(inputs: &[u8]) -> Result<[u8; 32], BlackBoxResolutionError> { - generic_hash_256::(inputs) - .map_err(|err| BlackBoxResolutionError::Failed(BlackBoxFunc::Blake2s, err)) -} - -pub fn blake3(inputs: &[u8]) -> Result<[u8; 32], BlackBoxResolutionError> { - Ok(blake3::hash(inputs).into()) -} - -pub fn keccak256(inputs: &[u8]) -> Result<[u8; 32], BlackBoxResolutionError> { - generic_hash_256::(inputs) - .map_err(|err| BlackBoxResolutionError::Failed(BlackBoxFunc::Keccak256, err)) -} - -pub fn sha256compression(state: &mut [u32; 8], msg_blocks: &[u32; 16]) { - let mut blocks = [0_u8; 64]; - for (i, block) in msg_blocks.iter().enumerate() { - let bytes = block.to_be_bytes(); - blocks[i * 4..i * 4 + 4].copy_from_slice(&bytes); - } - let blocks: GenericArray = blocks.into(); - sha2::compress256(state, &[blocks]); -} - -const KECCAK_LANES: usize = 25; - -pub fn keccakf1600( - mut state: [u64; KECCAK_LANES], -) -> Result<[u64; KECCAK_LANES], BlackBoxResolutionError> { - keccak::f1600(&mut state); - Ok(state) -} - -pub fn ecdsa_secp256k1_verify( - hashed_msg: &[u8], - public_key_x: &[u8; 32], - public_key_y: &[u8; 32], - signature: &[u8; 64], -) -> Result { - Ok(verify_secp256k1_ecdsa_signature(hashed_msg, public_key_x, public_key_y, signature)) -} - -pub fn ecdsa_secp256r1_verify( - hashed_msg: &[u8], - public_key_x: &[u8; 32], - public_key_y: &[u8; 32], - signature: &[u8; 64], -) -> Result { - Ok(verify_secp256r1_ecdsa_signature(hashed_msg, public_key_x, public_key_y, signature)) -} - -/// Does a generic hash of the inputs returning the resulting 32 bytes separately. -fn generic_hash_256(message: &[u8]) -> Result<[u8; 32], String> { - let output_bytes: [u8; 32] = - D::digest(message).as_slice().try_into().map_err(|_| "digest should be 256 bits")?; - - Ok(output_bytes) -} - -fn verify_secp256k1_ecdsa_signature( - hashed_msg: &[u8], - public_key_x_bytes: &[u8; 32], - public_key_y_bytes: &[u8; 32], - signature: &[u8; 64], -) -> bool { - use k256::elliptic_curve::sec1::FromEncodedPoint; - use k256::elliptic_curve::PrimeField; - - use k256::{ecdsa::Signature, Scalar}; - use k256::{ - elliptic_curve::{ - sec1::{Coordinates, ToEncodedPoint}, - IsHigh, - }, - AffinePoint, EncodedPoint, ProjectivePoint, PublicKey, - }; - // Convert the inputs into k256 data structures - - let Ok(signature) = Signature::try_from(signature.as_slice()) else { - // Signature `r` and `s` are forbidden from being zero. - return false; - }; - - let point = EncodedPoint::from_affine_coordinates( - public_key_x_bytes.into(), - public_key_y_bytes.into(), - true, - ); - - let pubkey = PublicKey::from_encoded_point(&point); - let pubkey = if pubkey.is_some().into() { - pubkey.unwrap() - } else { - // Public key must sit on the Secp256k1 curve. - return false; - }; - - // Note: This is incorrect as it will panic if `hashed_msg >= k256::Secp256k1::ORDER`. - // In this scenario we should just take the leftmost bits from `hashed_msg` up to the group order length. - let z = Scalar::from_repr(*GenericArray::from_slice(hashed_msg)).unwrap(); - - // Finished converting bytes into data structures - - let r = signature.r(); - let s = signature.s(); - - // Ensure signature is "low S" normalized ala BIP 0062 - if s.is_high().into() { - return false; - } - - let s_inv = s.invert().unwrap(); - let u1 = z * s_inv; - let u2 = *r * s_inv; - - #[allow(non_snake_case)] - let R: AffinePoint = ((ProjectivePoint::GENERATOR * u1) - + (ProjectivePoint::from(*pubkey.as_affine()) * u2)) - .to_affine(); - - match R.to_encoded_point(false).coordinates() { - Coordinates::Uncompressed { x, y: _ } => Scalar::from_repr(*x).unwrap().eq(&r), - _ => unreachable!("Point is uncompressed"), - } -} - -fn verify_secp256r1_ecdsa_signature( - hashed_msg: &[u8], - public_key_x_bytes: &[u8; 32], - public_key_y_bytes: &[u8; 32], - signature: &[u8; 64], -) -> bool { - use p256::elliptic_curve::sec1::FromEncodedPoint; - use p256::elliptic_curve::PrimeField; - - use p256::{ecdsa::Signature, Scalar}; - use p256::{ - elliptic_curve::{ - sec1::{Coordinates, ToEncodedPoint}, - IsHigh, - }, - AffinePoint, EncodedPoint, ProjectivePoint, PublicKey, - }; - - // Convert the inputs into k256 data structures - - let Ok(signature) = Signature::try_from(signature.as_slice()) else { - // Signature `r` and `s` are forbidden from being zero. - return false; - }; - - let point = EncodedPoint::from_affine_coordinates( - public_key_x_bytes.into(), - public_key_y_bytes.into(), - true, - ); - - let pubkey = PublicKey::from_encoded_point(&point); - let pubkey = if pubkey.is_some().into() { - pubkey.unwrap() - } else { - // Public key must sit on the Secp256r1 curve. - return false; - }; - - // Note: This is incorrect as it will panic if `hashed_msg >= p256::NistP256::ORDER`. - // In this scenario we should just take the leftmost bits from `hashed_msg` up to the group order length. - let z = Scalar::from_repr(*GenericArray::from_slice(hashed_msg)).unwrap(); - - // Finished converting bytes into data structures - - let r = signature.r(); - let s = signature.s(); - - // Ensure signature is "low S" normalized ala BIP 0062 - if s.is_high().into() { - return false; - } - - let s_inv = s.invert().unwrap(); - let u1 = z * s_inv; - let u2 = *r * s_inv; - - #[allow(non_snake_case)] - let R: AffinePoint = ((ProjectivePoint::GENERATOR * u1) - + (ProjectivePoint::from(*pubkey.as_affine()) * u2)) - .to_affine(); - - match R.to_encoded_point(false).coordinates() { - Coordinates::Uncompressed { x, y: _ } => Scalar::from_repr(*x).unwrap().eq(&r), - _ => unreachable!("Point is uncompressed"), - } -} - -#[cfg(test)] -mod keccakf1600_tests { - use crate::keccakf1600; - - #[test] - fn sanity_check() { - // Test vectors are copied from XKCP (eXtended Keccak Code Package) - // https://github.com/XKCP/XKCP/blob/master/tests/TestVectors/KeccakF-1600-IntermediateValues.txt - let zero_state = [0u64; 25]; - - let expected_state_first = [ - 0xF1258F7940E1DDE7, - 0x84D5CCF933C0478A, - 0xD598261EA65AA9EE, - 0xBD1547306F80494D, - 0x8B284E056253D057, - 0xFF97A42D7F8E6FD4, - 0x90FEE5A0A44647C4, - 0x8C5BDA0CD6192E76, - 0xAD30A6F71B19059C, - 0x30935AB7D08FFC64, - 0xEB5AA93F2317D635, - 0xA9A6E6260D712103, - 0x81A57C16DBCF555F, - 0x43B831CD0347C826, - 0x01F22F1A11A5569F, - 0x05E5635A21D9AE61, - 0x64BEFEF28CC970F2, - 0x613670957BC46611, - 0xB87C5A554FD00ECB, - 0x8C3EE88A1CCF32C8, - 0x940C7922AE3A2614, - 0x1841F924A2C509E4, - 0x16F53526E70465C2, - 0x75F644E97F30A13B, - 0xEAF1FF7B5CECA249, - ]; - let expected_state_second = [ - 0x2D5C954DF96ECB3C, - 0x6A332CD07057B56D, - 0x093D8D1270D76B6C, - 0x8A20D9B25569D094, - 0x4F9C4F99E5E7F156, - 0xF957B9A2DA65FB38, - 0x85773DAE1275AF0D, - 0xFAF4F247C3D810F7, - 0x1F1B9EE6F79A8759, - 0xE4FECC0FEE98B425, - 0x68CE61B6B9CE68A1, - 0xDEEA66C4BA8F974F, - 0x33C43D836EAFB1F5, - 0xE00654042719DBD9, - 0x7CF8A9F009831265, - 0xFD5449A6BF174743, - 0x97DDAD33D8994B40, - 0x48EAD5FC5D0BE774, - 0xE3B8C8EE55B7B03C, - 0x91A0226E649E42E9, - 0x900E3129E7BADD7B, - 0x202A9EC5FAA3CCE8, - 0x5B3402464E1C3DB6, - 0x609F4E62A44C1059, - 0x20D06CD26A8FBF5C, - ]; - - let state_first = keccakf1600(zero_state).unwrap(); - let state_second = keccakf1600(state_first).unwrap(); - - assert_eq!(state_first, expected_state_first); - assert_eq!(state_second, expected_state_second); - } -} - -#[cfg(test)] -mod secp256k1_tests { - use super::verify_secp256k1_ecdsa_signature; - - // 0x3a73f4123a5cd2121f21cd7e8d358835476949d035d9c2da6806b4633ac8c1e2, - const HASHED_MESSAGE: [u8; 32] = [ - 0x3a, 0x73, 0xf4, 0x12, 0x3a, 0x5c, 0xd2, 0x12, 0x1f, 0x21, 0xcd, 0x7e, 0x8d, 0x35, 0x88, - 0x35, 0x47, 0x69, 0x49, 0xd0, 0x35, 0xd9, 0xc2, 0xda, 0x68, 0x06, 0xb4, 0x63, 0x3a, 0xc8, - 0xc1, 0xe2, - ]; - // 0xa0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7 - const PUB_KEY_X: [u8; 32] = [ - 0xa0, 0x43, 0x4d, 0x9e, 0x47, 0xf3, 0xc8, 0x62, 0x35, 0x47, 0x7c, 0x7b, 0x1a, 0xe6, 0xae, - 0x5d, 0x34, 0x42, 0xd4, 0x9b, 0x19, 0x43, 0xc2, 0xb7, 0x52, 0xa6, 0x8e, 0x2a, 0x47, 0xe2, - 0x47, 0xc7, - ]; - // 0x893aba425419bc27a3b6c7e693a24c696f794c2ed877a1593cbee53b037368d7 - const PUB_KEY_Y: [u8; 32] = [ - 0x89, 0x3a, 0xba, 0x42, 0x54, 0x19, 0xbc, 0x27, 0xa3, 0xb6, 0xc7, 0xe6, 0x93, 0xa2, 0x4c, - 0x69, 0x6f, 0x79, 0x4c, 0x2e, 0xd8, 0x77, 0xa1, 0x59, 0x3c, 0xbe, 0xe5, 0x3b, 0x03, 0x73, - 0x68, 0xd7, - ]; - // 0xe5081c80ab427dc370346f4a0e31aa2bad8d9798c38061db9ae55a4e8df454fd28119894344e71b78770cc931d61f480ecbb0b89d6eb69690161e49a715fcd55 - const SIGNATURE: [u8; 64] = [ - 0xe5, 0x08, 0x1c, 0x80, 0xab, 0x42, 0x7d, 0xc3, 0x70, 0x34, 0x6f, 0x4a, 0x0e, 0x31, 0xaa, - 0x2b, 0xad, 0x8d, 0x97, 0x98, 0xc3, 0x80, 0x61, 0xdb, 0x9a, 0xe5, 0x5a, 0x4e, 0x8d, 0xf4, - 0x54, 0xfd, 0x28, 0x11, 0x98, 0x94, 0x34, 0x4e, 0x71, 0xb7, 0x87, 0x70, 0xcc, 0x93, 0x1d, - 0x61, 0xf4, 0x80, 0xec, 0xbb, 0x0b, 0x89, 0xd6, 0xeb, 0x69, 0x69, 0x01, 0x61, 0xe4, 0x9a, - 0x71, 0x5f, 0xcd, 0x55, - ]; - - #[test] - fn verifies_valid_signature_with_low_s_value() { - let valid = - verify_secp256k1_ecdsa_signature(&HASHED_MESSAGE, &PUB_KEY_X, &PUB_KEY_Y, &SIGNATURE); - - assert!(valid); - } - - #[test] - fn rejects_invalid_signature() { - // This signature is invalid as ECDSA specifies that `r` and `s` must be non-zero. - let invalid_signature: [u8; 64] = [0x00; 64]; - - let valid = verify_secp256k1_ecdsa_signature( - &HASHED_MESSAGE, - &PUB_KEY_X, - &PUB_KEY_Y, - &invalid_signature, - ); - assert!(!valid); - } - - #[test] - fn rejects_invalid_public_key() { - let invalid_pub_key_x: [u8; 32] = [0xff; 32]; - let invalid_pub_key_y: [u8; 32] = [0xff; 32]; - - let valid = verify_secp256k1_ecdsa_signature( - &HASHED_MESSAGE, - &invalid_pub_key_x, - &invalid_pub_key_y, - &SIGNATURE, - ); - - assert!(!valid); - } - - #[test] - #[ignore = "ECDSA verification does not currently handle long hashes correctly"] - fn trims_overly_long_hashes_to_correct_length() { - let mut long_hashed_message = HASHED_MESSAGE.to_vec(); - long_hashed_message.push(0xff); - - let valid = verify_secp256k1_ecdsa_signature( - &long_hashed_message, - &PUB_KEY_X, - &PUB_KEY_Y, - &SIGNATURE, - ); - - assert!(valid); - } -} - -#[cfg(test)] -mod secp256r1_tests { - use super::verify_secp256r1_ecdsa_signature; - - // 0x54705ba3baafdbdfba8c5f9a70f7a89bee98d906b53e31074da7baecdc0da9ad - const HASHED_MESSAGE: [u8; 32] = [ - 84, 112, 91, 163, 186, 175, 219, 223, 186, 140, 95, 154, 112, 247, 168, 155, 238, 152, 217, - 6, 181, 62, 49, 7, 77, 167, 186, 236, 220, 13, 169, 173, - ]; - // 0x550f471003f3df97c3df506ac797f6721fb1a1fb7b8f6f83d224498a65c88e24 - const PUB_KEY_X: [u8; 32] = [ - 85, 15, 71, 16, 3, 243, 223, 151, 195, 223, 80, 106, 199, 151, 246, 114, 31, 177, 161, 251, - 123, 143, 111, 131, 210, 36, 73, 138, 101, 200, 142, 36, - ]; - // 0x136093d7012e509a73715cbd0b00a3cc0ff4b5c01b3ffa196ab1fb327036b8e6 - const PUB_KEY_Y: [u8; 32] = [ - 19, 96, 147, 215, 1, 46, 80, 154, 115, 113, 92, 189, 11, 0, 163, 204, 15, 244, 181, 192, - 27, 63, 250, 25, 106, 177, 251, 50, 112, 54, 184, 230, - ]; - // 0x2c70a8d084b62bfc5ce03641caf9f72ad4da8c81bfe6ec9487bb5e1bef62a13218ad9ee29eaf351fdc50f1520c425e9b908a07278b43b0ec7b872778c14e0784 - const SIGNATURE: [u8; 64] = [ - 44, 112, 168, 208, 132, 182, 43, 252, 92, 224, 54, 65, 202, 249, 247, 42, 212, 218, 140, - 129, 191, 230, 236, 148, 135, 187, 94, 27, 239, 98, 161, 50, 24, 173, 158, 226, 158, 175, - 53, 31, 220, 80, 241, 82, 12, 66, 94, 155, 144, 138, 7, 39, 139, 67, 176, 236, 123, 135, - 39, 120, 193, 78, 7, 132, - ]; - - #[test] - fn verifies_valid_signature_with_low_s_value() { - let valid = - verify_secp256r1_ecdsa_signature(&HASHED_MESSAGE, &PUB_KEY_X, &PUB_KEY_Y, &SIGNATURE); - - assert!(valid); - } - - #[test] - fn rejects_invalid_signature() { - // This signature is invalid as ECDSA specifies that `r` and `s` must be non-zero. - let invalid_signature: [u8; 64] = [0x00; 64]; - - let valid = verify_secp256r1_ecdsa_signature( - &HASHED_MESSAGE, - &PUB_KEY_X, - &PUB_KEY_Y, - &invalid_signature, - ); - assert!(!valid); - } - - #[test] - fn rejects_invalid_public_key() { - let invalid_pub_key_x: [u8; 32] = [0xff; 32]; - let invalid_pub_key_y: [u8; 32] = [0xff; 32]; - - let valid = verify_secp256r1_ecdsa_signature( - &HASHED_MESSAGE, - &invalid_pub_key_x, - &invalid_pub_key_y, - &SIGNATURE, - ); - - assert!(!valid); - } - - #[test] - #[ignore = "ECDSA verification does not currently handle long hashes correctly"] - fn trims_overly_long_hashes_to_correct_length() { - let mut long_hashed_message = HASHED_MESSAGE.to_vec(); - long_hashed_message.push(0xff); - - let valid = verify_secp256r1_ecdsa_signature( - &long_hashed_message, - &PUB_KEY_X, - &PUB_KEY_Y, - &SIGNATURE, - ); - - assert!(valid); - } -} diff --git a/acvm-repo/bn254_blackbox_solver/Cargo.toml b/acvm-repo/bn254_blackbox_solver/Cargo.toml index ea601a6b80f..1ad5103d2cb 100644 --- a/acvm-repo/bn254_blackbox_solver/Cargo.toml +++ b/acvm-repo/bn254_blackbox_solver/Cargo.toml @@ -2,7 +2,7 @@ name = "bn254_blackbox_solver" description = "Solvers for black box functions which are specific for the bn254 curve" # x-release-please-start-version -version = "0.39.0" +version = "0.42.0" # x-release-please-end authors.workspace = true edition.workspace = true @@ -17,22 +17,16 @@ acir.workspace = true acvm_blackbox_solver.workspace = true thiserror.workspace = true num-traits.workspace = true +cfg-if = "1.0.0" -rust-embed = { version = "6.6.0", features = [ - "debug-embed", - "interpolate-folder-path", - "include-exclude", -] } - -grumpkin = { version = "0.1.0", package = "noir_grumpkin", features = [ - "std", -] } # BN254 fixed base scalar multiplication solver +# BN254 fixed base scalar multiplication solver +grumpkin = { version = "0.1.0", package = "noir_grumpkin", features = ["std"] } ark-ec = { version = "^0.4.0", default-features = false } ark-ff = { version = "^0.4.0", default-features = false } num-bigint.workspace = true [target.'cfg(target_arch = "wasm32")'.dependencies] -wasmer = { version = "4.2.3", default-features = false, features = [ +wasmer = { version = "4.2.6", default-features = false, features = [ "js-default", ] } @@ -42,16 +36,7 @@ js-sys.workspace = true [target.'cfg(not(target_arch = "wasm32"))'.dependencies] getrandom.workspace = true -wasmer = "4.2.3" - -[build-dependencies] -pkg-config = "0.3" -tar = "~0.4.15" -flate2 = "~1.0.1" -reqwest = { version = "0.11.20", default-features = false, features = [ - "rustls-tls", - "blocking", -] } +wasmer = "4.2.6" [features] default = ["bn254"] diff --git a/acvm-repo/bn254_blackbox_solver/build.rs b/acvm-repo/bn254_blackbox_solver/build.rs deleted file mode 100644 index 4269c86aba0..00000000000 --- a/acvm-repo/bn254_blackbox_solver/build.rs +++ /dev/null @@ -1,14 +0,0 @@ -use std::path::PathBuf; - -const BARRETENBERG_BIN_DIR: &str = "BARRETENBERG_BIN_DIR"; - -fn main() -> Result<(), String> { - let out_dir = std::env::var("OUT_DIR").unwrap(); - - let dest_path = PathBuf::from(out_dir.clone()).join("acvm_backend.wasm"); - - println!("cargo:rustc-env={BARRETENBERG_BIN_DIR}={out_dir}"); - std::fs::copy("./src/acvm_backend.wasm", dest_path).unwrap(); - - Ok(()) -} diff --git a/acvm-repo/bn254_blackbox_solver/src/lib.rs b/acvm-repo/bn254_blackbox_solver/src/lib.rs index be0e60ada96..231594170e3 100644 --- a/acvm-repo/bn254_blackbox_solver/src/lib.rs +++ b/acvm-repo/bn254_blackbox_solver/src/lib.rs @@ -20,10 +20,17 @@ pub struct Bn254BlackBoxSolver { } impl Bn254BlackBoxSolver { - #[cfg(target_arch = "wasm32")] pub async fn initialize() -> Bn254BlackBoxSolver { - let blackbox_vendor = Barretenberg::initialize().await; - Bn254BlackBoxSolver { blackbox_vendor } + // We fallback to the sync initialization of barretenberg on non-wasm targets. + // This ensures that wasm packages consuming this still build on the default target (useful for linting, etc.) + cfg_if::cfg_if! { + if #[cfg(target_arch = "wasm32")] { + let blackbox_vendor = Barretenberg::initialize().await; + Bn254BlackBoxSolver { blackbox_vendor } + } else { + Bn254BlackBoxSolver::new() + } + } } #[cfg(not(target_arch = "wasm32"))] diff --git a/acvm-repo/bn254_blackbox_solver/src/acvm_backend.wasm b/acvm-repo/bn254_blackbox_solver/src/wasm/acvm_backend.wasm similarity index 100% rename from acvm-repo/bn254_blackbox_solver/src/acvm_backend.wasm rename to acvm-repo/bn254_blackbox_solver/src/wasm/acvm_backend.wasm diff --git a/acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs b/acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs index 10b1ab22a8d..f4f6f56aa99 100644 --- a/acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs +++ b/acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs @@ -45,7 +45,7 @@ pub(crate) struct BackendError(#[from] Error); impl From for BackendError { fn from(value: FeatureError) -> Self { - value.into() + BackendError(Error::FromFeature(value)) } } @@ -76,10 +76,7 @@ use wasmer::{ pub(super) const WASM_SCRATCH_BYTES: usize = 1024; /// Embed the Barretenberg WASM file -#[derive(rust_embed::RustEmbed)] -#[folder = "$BARRETENBERG_BIN_DIR"] -#[include = "acvm_backend.wasm"] -struct Wasm; +const WASM_BIN: &[u8] = include_bytes!("./acvm_backend.wasm"); impl Barretenberg { #[cfg(not(target_arch = "wasm32"))] @@ -287,7 +284,7 @@ fn instance_load() -> (Instance, Memory, Store) { let (memory, mut store, custom_imports) = init_memory_and_state(); - let module = Module::new(&store, Wasm::get("acvm_backend.wasm").unwrap().data).unwrap(); + let module = Module::new(&store, WASM_BIN).unwrap(); (Instance::new(&mut store, &module, &custom_imports).unwrap(), memory, store) } @@ -299,9 +296,7 @@ async fn instance_load() -> (Instance, Memory, Store) { let (memory, mut store, custom_imports) = init_memory_and_state(); - let wasm_binary = Wasm::get("acvm_backend.wasm").unwrap().data; - - let js_bytes = unsafe { js_sys::Uint8Array::view(&wasm_binary) }; + let js_bytes = unsafe { js_sys::Uint8Array::view(&WASM_BIN) }; let js_module_promise = WebAssembly::compile(&js_bytes); let js_module: js_sys::WebAssembly::Module = wasm_bindgen_futures::JsFuture::from(js_module_promise).await.unwrap().into(); @@ -309,7 +304,7 @@ async fn instance_load() -> (Instance, Memory, Store) { let js_instance_promise = WebAssembly::instantiate_module(&js_module, &custom_imports.as_jsvalue(&store).into()); let js_instance = wasm_bindgen_futures::JsFuture::from(js_instance_promise).await.unwrap(); - let module: wasmer::Module = (js_module, wasm_binary).into(); + let module = wasmer::Module::from((js_module, WASM_BIN)); let instance: wasmer::Instance = Instance::from_jsvalue(&mut store, &module, &js_instance) .map_err(|_| "Error while creating BlackBox Functions vendor instance") .unwrap(); diff --git a/acvm-repo/brillig/Cargo.toml b/acvm-repo/brillig/Cargo.toml index 8d91d19e117..d3f082fda86 100644 --- a/acvm-repo/brillig/Cargo.toml +++ b/acvm-repo/brillig/Cargo.toml @@ -2,7 +2,7 @@ name = "brillig" description = "Brillig is the bytecode ACIR uses for non-determinism." # x-release-please-start-version -version = "0.40.0" +version = "0.42.0" # x-release-please-end authors.workspace = true edition.workspace = true diff --git a/acvm-repo/brillig/src/foreign_call.rs b/acvm-repo/brillig/src/foreign_call.rs index 3f124a9a0a7..e547b99f0eb 100644 --- a/acvm-repo/brillig/src/foreign_call.rs +++ b/acvm-repo/brillig/src/foreign_call.rs @@ -1,34 +1,34 @@ -use crate::value::Value; +use acir_field::FieldElement; use serde::{Deserialize, Serialize}; /// Single output of a [foreign call][crate::Opcode::ForeignCall]. #[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)] pub enum ForeignCallParam { - Single(Value), - Array(Vec), + Single(FieldElement), + Array(Vec), } -impl From for ForeignCallParam { - fn from(value: Value) -> Self { +impl From for ForeignCallParam { + fn from(value: FieldElement) -> Self { ForeignCallParam::Single(value) } } -impl From> for ForeignCallParam { - fn from(values: Vec) -> Self { +impl From> for ForeignCallParam { + fn from(values: Vec) -> Self { ForeignCallParam::Array(values) } } impl ForeignCallParam { - pub fn values(&self) -> Vec { + pub fn fields(&self) -> Vec { match self { ForeignCallParam::Single(value) => vec![*value], ForeignCallParam::Array(values) => values.clone(), } } - pub fn unwrap_value(&self) -> Value { + pub fn unwrap_field(&self) -> FieldElement { match self { ForeignCallParam::Single(value) => *value, ForeignCallParam::Array(_) => panic!("Expected single value, found array"), @@ -43,14 +43,14 @@ pub struct ForeignCallResult { pub values: Vec, } -impl From for ForeignCallResult { - fn from(value: Value) -> Self { +impl From for ForeignCallResult { + fn from(value: FieldElement) -> Self { ForeignCallResult { values: vec![value.into()] } } } -impl From> for ForeignCallResult { - fn from(values: Vec) -> Self { +impl From> for ForeignCallResult { + fn from(values: Vec) -> Self { ForeignCallResult { values: vec![values.into()] } } } diff --git a/acvm-repo/brillig/src/lib.rs b/acvm-repo/brillig/src/lib.rs index 0661e794360..40f2e15acfe 100644 --- a/acvm-repo/brillig/src/lib.rs +++ b/acvm-repo/brillig/src/lib.rs @@ -13,7 +13,6 @@ mod black_box; mod foreign_call; mod opcodes; -mod value; pub use black_box::BlackBoxOp; pub use foreign_call::{ForeignCallParam, ForeignCallResult}; @@ -21,5 +20,3 @@ pub use opcodes::{ BinaryFieldOp, BinaryIntOp, HeapArray, HeapValueType, HeapVector, MemoryAddress, ValueOrArray, }; pub use opcodes::{BrilligOpcode as Opcode, Label}; -pub use value::Typ; -pub use value::Value; diff --git a/acvm-repo/brillig/src/opcodes.rs b/acvm-repo/brillig/src/opcodes.rs index 51df1f90941..d1345351986 100644 --- a/acvm-repo/brillig/src/opcodes.rs +++ b/acvm-repo/brillig/src/opcodes.rs @@ -1,4 +1,5 @@ -use crate::{black_box::BlackBoxOp, Value}; +use crate::black_box::BlackBoxOp; +use acir_field::FieldElement; use serde::{Deserialize, Serialize}; pub type Label = usize; @@ -22,8 +23,8 @@ impl From for MemoryAddress { /// Describes the memory layout for an array/vector element #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] pub enum HeapValueType { - // A single field element is enough to represent the value - Simple, + // A single field element is enough to represent the value with a given bit size + Simple(u32), // The value read should be interpreted as a pointer to a heap array, which // consists of a pointer to a slice of memory of size elements, and a // reference count @@ -36,7 +37,11 @@ pub enum HeapValueType { impl HeapValueType { pub fn all_simple(types: &[HeapValueType]) -> bool { - types.iter().all(|typ| matches!(typ, HeapValueType::Simple)) + types.iter().all(|typ| matches!(typ, HeapValueType::Simple(_))) + } + + pub fn field() -> HeapValueType { + HeapValueType::Simple(FieldElement::max_num_bits()) } } @@ -131,7 +136,7 @@ pub enum BrilligOpcode { Const { destination: MemoryAddress, bit_size: u32, - value: Value, + value: FieldElement, }, Return, /// Used to get data from an outside source. @@ -156,6 +161,13 @@ pub enum BrilligOpcode { destination: MemoryAddress, source: MemoryAddress, }, + /// destination = condition > 0 ? source_a : source_b + ConditionalMov { + destination: MemoryAddress, + source_a: MemoryAddress, + source_b: MemoryAddress, + condition: MemoryAddress, + }, Load { destination: MemoryAddress, source_pointer: MemoryAddress, @@ -180,9 +192,16 @@ pub enum BinaryFieldOp { Add, Sub, Mul, + /// Field division Div, + /// Integer division + IntegerDiv, /// (==) equal Equals, + /// (<) Field less than + LessThan, + /// (<=) field less or equal + LessThanEquals, } /// Binary fixed-length integer expressions @@ -191,8 +210,7 @@ pub enum BinaryIntOp { Add, Sub, Mul, - SignedDiv, - UnsignedDiv, + Div, /// (==) equal Equals, /// (<) Field less than diff --git a/acvm-repo/brillig/src/value.rs b/acvm-repo/brillig/src/value.rs deleted file mode 100644 index 5a532cbc1a7..00000000000 --- a/acvm-repo/brillig/src/value.rs +++ /dev/null @@ -1,103 +0,0 @@ -use acir_field::FieldElement; -use serde::{Deserialize, Serialize}; -use std::ops::{Add, Div, Mul, Neg, Sub}; - -/// Types of values allowed in the VM -#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, PartialOrd, Ord)] -pub enum Typ { - Field, - Unsigned { bit_size: u32 }, - Signed { bit_size: u32 }, -} - -/// `Value` represents the base descriptor for a value in the VM. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] -pub struct Value { - inner: FieldElement, -} - -impl Value { - /// Returns `true` if the `Value` represents `zero` - pub fn is_zero(&self) -> bool { - self.inner.is_zero() - } - - /// Converts `Value` into a `FieldElement`. - pub fn to_field(&self) -> FieldElement { - self.inner - } - - /// Converts `Value` into a `u128`. - // TODO: Check what happens if `Value` cannot fit into a u128 - pub fn to_u128(&self) -> u128 { - self.to_field().to_u128() - } - - /// Converts `Value` into a u64 and then casts it into a usize. - /// Panics: If `Value` cannot fit into a u64 or `Value` does - //// not fit into a usize. - pub fn to_usize(&self) -> usize { - usize::try_from(self.inner.try_to_u64().expect("value does not fit into u64")) - .expect("value does not fit into usize") - } -} - -impl From for Value { - fn from(value: usize) -> Self { - Value { inner: FieldElement::from(value as u128) } - } -} - -impl From for Value { - fn from(value: u128) -> Self { - Value { inner: FieldElement::from(value) } - } -} - -impl From for Value { - fn from(value: FieldElement) -> Self { - Value { inner: value } - } -} - -impl From for Value { - fn from(value: bool) -> Self { - Value { inner: FieldElement::from(value) } - } -} - -impl Add for Value { - type Output = Value; - - fn add(self, rhs: Self) -> Self::Output { - Value { inner: self.inner + rhs.inner } - } -} -impl Sub for Value { - type Output = Value; - - fn sub(self, rhs: Self) -> Self::Output { - Value { inner: self.inner - rhs.inner } - } -} -impl Mul for Value { - type Output = Value; - - fn mul(self, rhs: Self) -> Self::Output { - Value { inner: self.inner * rhs.inner } - } -} -impl Div for Value { - type Output = Value; - - fn div(self, rhs: Self) -> Self::Output { - Value { inner: self.inner / rhs.inner } - } -} -impl Neg for Value { - type Output = Value; - - fn neg(self) -> Self::Output { - Value { inner: -self.inner } - } -} diff --git a/acvm-repo/brillig_vm/Cargo.toml b/acvm-repo/brillig_vm/Cargo.toml index 272e8389413..95675469479 100644 --- a/acvm-repo/brillig_vm/Cargo.toml +++ b/acvm-repo/brillig_vm/Cargo.toml @@ -2,7 +2,7 @@ name = "brillig_vm" description = "The virtual machine that processes Brillig bytecode, used to introduce non-determinism to the ACVM" # x-release-please-start-version -version = "0.40.0" +version = "0.42.0" # x-release-please-end authors.workspace = true edition.workspace = true @@ -17,6 +17,7 @@ acir.workspace = true acvm_blackbox_solver.workspace = true num-bigint.workspace = true num-traits.workspace = true +thiserror.workspace = true [features] default = ["bn254"] diff --git a/acvm-repo/brillig_vm/src/arithmetic.rs b/acvm-repo/brillig_vm/src/arithmetic.rs index 9d7b6fe8f02..3d77982ffb1 100644 --- a/acvm-repo/brillig_vm/src/arithmetic.rs +++ b/acvm-repo/brillig_vm/src/arithmetic.rs @@ -1,59 +1,100 @@ use acir::brillig::{BinaryFieldOp, BinaryIntOp}; use acir::FieldElement; -use num_bigint::{BigInt, BigUint}; +use num_bigint::BigUint; use num_traits::{One, ToPrimitive, Zero}; -/// Evaluate a binary operation on two FieldElements and return the result as a FieldElement. +use crate::memory::MemoryValue; + +#[derive(Debug, thiserror::Error)] +pub(crate) enum BrilligArithmeticError { + #[error("Bit size for lhs {lhs_bit_size} does not match op bit size {op_bit_size}")] + MismatchedLhsBitSize { lhs_bit_size: u32, op_bit_size: u32 }, + #[error("Bit size for rhs {rhs_bit_size} does not match op bit size {op_bit_size}")] + MismatchedRhsBitSize { rhs_bit_size: u32, op_bit_size: u32 }, + #[error("Shift with bit size {op_bit_size} is invalid")] + InvalidShift { op_bit_size: u32 }, +} + +/// Evaluate a binary operation on two FieldElement memory values. pub(crate) fn evaluate_binary_field_op( op: &BinaryFieldOp, - a: FieldElement, - b: FieldElement, -) -> FieldElement { - match op { + lhs: MemoryValue, + rhs: MemoryValue, +) -> Result { + if lhs.bit_size != FieldElement::max_num_bits() { + return Err(BrilligArithmeticError::MismatchedLhsBitSize { + lhs_bit_size: lhs.bit_size, + op_bit_size: FieldElement::max_num_bits(), + }); + } + if rhs.bit_size != FieldElement::max_num_bits() { + return Err(BrilligArithmeticError::MismatchedRhsBitSize { + rhs_bit_size: rhs.bit_size, + op_bit_size: FieldElement::max_num_bits(), + }); + } + + let a = lhs.value; + let b = rhs.value; + Ok(match op { // Perform addition, subtraction, multiplication, and division based on the BinaryOp variant. - BinaryFieldOp::Add => a + b, - BinaryFieldOp::Sub => a - b, - BinaryFieldOp::Mul => a * b, - BinaryFieldOp::Div => a / b, + BinaryFieldOp::Add => (a + b).into(), + BinaryFieldOp::Sub => (a - b).into(), + BinaryFieldOp::Mul => (a * b).into(), + BinaryFieldOp::Div => (a / b).into(), + BinaryFieldOp::IntegerDiv => { + let a_big = BigUint::from_bytes_be(&a.to_be_bytes()); + let b_big = BigUint::from_bytes_be(&b.to_be_bytes()); + + let result = a_big / b_big; + FieldElement::from_be_bytes_reduce(&result.to_bytes_be()).into() + } BinaryFieldOp::Equals => (a == b).into(), - } + BinaryFieldOp::LessThan => (a < b).into(), + BinaryFieldOp::LessThanEquals => (a <= b).into(), + }) } -/// Evaluate a binary operation on two unsigned big integers with a given bit size and return the result as a big integer. -pub(crate) fn evaluate_binary_bigint_op( +/// Evaluate a binary operation on two unsigned big integers with a given bit size. +pub(crate) fn evaluate_binary_int_op( op: &BinaryIntOp, - a: BigUint, - b: BigUint, + lhs: MemoryValue, + rhs: MemoryValue, bit_size: u32, -) -> Result { +) -> Result { + if lhs.bit_size != bit_size { + return Err(BrilligArithmeticError::MismatchedLhsBitSize { + lhs_bit_size: lhs.bit_size, + op_bit_size: bit_size, + }); + } + if rhs.bit_size != bit_size { + return Err(BrilligArithmeticError::MismatchedRhsBitSize { + rhs_bit_size: rhs.bit_size, + op_bit_size: bit_size, + }); + } + + let lhs = BigUint::from_bytes_be(&lhs.value.to_be_bytes()); + let rhs = BigUint::from_bytes_be(&rhs.value.to_be_bytes()); + let bit_modulo = &(BigUint::one() << bit_size); let result = match op { // Perform addition, subtraction, and multiplication, applying a modulo operation to keep the result within the bit size. - BinaryIntOp::Add => (a + b) % bit_modulo, - BinaryIntOp::Sub => (bit_modulo + a - b) % bit_modulo, - BinaryIntOp::Mul => (a * b) % bit_modulo, + BinaryIntOp::Add => (lhs + rhs) % bit_modulo, + BinaryIntOp::Sub => (bit_modulo + lhs - rhs) % bit_modulo, + BinaryIntOp::Mul => (lhs * rhs) % bit_modulo, // Perform unsigned division using the modulo operation on a and b. - BinaryIntOp::UnsignedDiv => { - let b_mod = b % bit_modulo; - if b_mod.is_zero() { - BigUint::zero() - } else { - (a % bit_modulo) / b_mod - } - } - // Perform signed division by first converting a and b to signed integers and then back to unsigned after the operation. - BinaryIntOp::SignedDiv => { - let b_signed = to_big_signed(b, bit_size); - if b_signed.is_zero() { + BinaryIntOp::Div => { + if rhs.is_zero() { BigUint::zero() } else { - let signed_div = to_big_signed(a, bit_size) / b_signed; - to_big_unsigned(signed_div, bit_size) + lhs / rhs } } // Perform a == operation, returning 0 or 1 BinaryIntOp::Equals => { - if (a % bit_modulo) == (b % bit_modulo) { + if lhs == rhs { BigUint::one() } else { BigUint::zero() @@ -61,7 +102,7 @@ pub(crate) fn evaluate_binary_bigint_op( } // Perform a < operation, returning 0 or 1 BinaryIntOp::LessThan => { - if (a % bit_modulo) < (b % bit_modulo) { + if lhs < rhs { BigUint::one() } else { BigUint::zero() @@ -69,46 +110,40 @@ pub(crate) fn evaluate_binary_bigint_op( } // Perform a <= operation, returning 0 or 1 BinaryIntOp::LessThanEquals => { - if (a % bit_modulo) <= (b % bit_modulo) { + if lhs <= rhs { BigUint::one() } else { BigUint::zero() } } // Perform bitwise AND, OR, XOR, left shift, and right shift operations, applying a modulo operation to keep the result within the bit size. - BinaryIntOp::And => (a & b) % bit_modulo, - BinaryIntOp::Or => (a | b) % bit_modulo, - BinaryIntOp::Xor => (a ^ b) % bit_modulo, + BinaryIntOp::And => lhs & rhs, + BinaryIntOp::Or => lhs | rhs, + BinaryIntOp::Xor => lhs ^ rhs, BinaryIntOp::Shl => { - assert!(bit_size <= 128, "unsupported bit size for right shift"); - let b = b.to_u128().unwrap(); - (a << b) % bit_modulo + if bit_size > 128 { + return Err(BrilligArithmeticError::InvalidShift { op_bit_size: bit_size }); + } + let rhs = rhs.to_u128().unwrap(); + (lhs << rhs) % bit_modulo } BinaryIntOp::Shr => { - assert!(bit_size <= 128, "unsupported bit size for right shift"); - let b = b.to_u128().unwrap(); - (a >> b) % bit_modulo + if bit_size > 128 { + return Err(BrilligArithmeticError::InvalidShift { op_bit_size: bit_size }); + } + let rhs = rhs.to_u128().unwrap(); + lhs >> rhs } }; - Ok(result) -} - -fn to_big_signed(a: BigUint, bit_size: u32) -> BigInt { - let pow_2 = BigUint::from(2_u32).pow(bit_size - 1); - if a < pow_2 { - BigInt::from(a) - } else { - BigInt::from(a) - 2 * BigInt::from(pow_2) - } -} + let result_as_field = FieldElement::from_be_bytes_reduce(&result.to_bytes_be()); -fn to_big_unsigned(a: BigInt, bit_size: u32) -> BigUint { - if a >= BigInt::zero() { - BigUint::from_bytes_le(&a.to_bytes_le().1) - } else { - BigUint::from(2_u32).pow(bit_size) - BigUint::from_bytes_le(&a.to_bytes_le().1) - } + Ok(match op { + BinaryIntOp::Equals | BinaryIntOp::LessThan | BinaryIntOp::LessThanEquals => { + MemoryValue::new(result_as_field, 1) + } + _ => MemoryValue::new(result_as_field, bit_size), + }) } #[cfg(test)] @@ -122,30 +157,15 @@ mod tests { } fn evaluate_u128(op: &BinaryIntOp, a: u128, b: u128, bit_size: u32) -> u128 { - // Convert to big integers - let lhs_big = BigUint::from(a); - let rhs_big = BigUint::from(b); - let result_value = evaluate_binary_bigint_op(op, lhs_big, rhs_big, bit_size).unwrap(); + let result_value = evaluate_binary_int_op( + op, + MemoryValue::new(a.into(), bit_size), + MemoryValue::new(b.into(), bit_size), + bit_size, + ) + .unwrap(); // Convert back to u128 - result_value.to_u128().unwrap() - } - - fn to_signed(a: u128, bit_size: u32) -> i128 { - assert!(bit_size < 128); - let pow_2 = 2_u128.pow(bit_size - 1); - if a < pow_2 { - a as i128 - } else { - (a.wrapping_sub(2 * pow_2)) as i128 - } - } - - fn to_unsigned(a: i128, bit_size: u32) -> u128 { - if a >= 0 { - a as u128 - } else { - (a + 2_i128.pow(bit_size)) as u128 - } + result_value.value.to_u128() } fn to_negative(a: u128, bit_size: u32) -> u128 { @@ -224,26 +244,6 @@ mod tests { let test_ops = vec![TestParams { a: 5, b: 3, result: 1 }, TestParams { a: 5, b: 10, result: 0 }]; - evaluate_int_ops(test_ops, BinaryIntOp::UnsignedDiv, bit_size); - } - - #[test] - fn to_signed_roundtrip() { - let bit_size = 32; - let minus_one = 2_u128.pow(bit_size) - 1; - assert_eq!(to_unsigned(to_signed(minus_one, bit_size), bit_size), minus_one); - } - - #[test] - fn signed_div_test() { - let bit_size = 32; - - let test_ops = vec![ - TestParams { a: 5, b: to_negative(10, bit_size), result: 0 }, - TestParams { a: 5, b: to_negative(1, bit_size), result: to_negative(5, bit_size) }, - TestParams { a: to_negative(5, bit_size), b: to_negative(1, bit_size), result: 5 }, - ]; - - evaluate_int_ops(test_ops, BinaryIntOp::SignedDiv, bit_size); + evaluate_int_ops(test_ops, BinaryIntOp::Div, bit_size); } } diff --git a/acvm-repo/brillig_vm/src/black_box.rs b/acvm-repo/brillig_vm/src/black_box.rs index 73b57b907f3..bd33b5ee8fc 100644 --- a/acvm-repo/brillig_vm/src/black_box.rs +++ b/acvm-repo/brillig_vm/src/black_box.rs @@ -1,33 +1,33 @@ -use acir::brillig::{BlackBoxOp, HeapArray, HeapVector, Value}; +use acir::brillig::{BlackBoxOp, HeapArray, HeapVector}; use acir::{BlackBoxFunc, FieldElement}; use acvm_blackbox_solver::{ blake2s, blake3, ecdsa_secp256k1_verify, ecdsa_secp256r1_verify, keccak256, keccakf1600, sha256, sha256compression, BlackBoxFunctionSolver, BlackBoxResolutionError, }; +use crate::memory::MemoryValue; use crate::Memory; -fn read_heap_vector<'a>(memory: &'a Memory, vector: &HeapVector) -> &'a [Value] { - memory.read_slice(memory.read_ref(vector.pointer), memory.read(vector.size).to_usize()) +fn read_heap_vector<'a>(memory: &'a Memory, vector: &HeapVector) -> &'a [MemoryValue] { + let size = memory.read(vector.size); + memory.read_slice(memory.read_ref(vector.pointer), size.to_usize()) } -fn read_heap_array<'a>(memory: &'a Memory, array: &HeapArray) -> &'a [Value] { +fn read_heap_array<'a>(memory: &'a Memory, array: &HeapArray) -> &'a [MemoryValue] { memory.read_slice(memory.read_ref(array.pointer), array.size) } /// Extracts the last byte of every value -fn to_u8_vec(inputs: &[Value]) -> Vec { +fn to_u8_vec(inputs: &[MemoryValue]) -> Vec { let mut result = Vec::with_capacity(inputs.len()); - for input in inputs { - let field_bytes = input.to_field().to_be_bytes(); - let byte = field_bytes.last().unwrap(); - result.push(*byte); + for &input in inputs { + result.push(input.try_into().unwrap()); } result } -fn to_value_vec(input: &[u8]) -> Vec { - input.iter().map(|x| Value::from(*x as usize)).collect() +fn to_value_vec(input: &[u8]) -> Vec { + input.iter().map(|&x| x.into()).collect() } pub(crate) fn evaluate_black_box( @@ -63,14 +63,13 @@ pub(crate) fn evaluate_black_box( BlackBoxOp::Keccakf1600 { message, output } => { let state_vec: Vec = read_heap_vector(memory, message) .iter() - .map(|value| value.to_field().try_to_u64().unwrap()) + .map(|&memory_value| memory_value.try_into().unwrap()) .collect(); let state: [u64; 25] = state_vec.try_into().unwrap(); let new_state = keccakf1600(state)?; - let new_state: Vec = - new_state.into_iter().map(|x| Value::from(x as usize)).collect(); + let new_state: Vec = new_state.into_iter().map(|x| x.into()).collect(); memory.write_slice(memory.read_ref(output.pointer), &new_state); Ok(()) } @@ -125,8 +124,8 @@ pub(crate) fn evaluate_black_box( Ok(()) } BlackBoxOp::SchnorrVerify { public_key_x, public_key_y, message, signature, result } => { - let public_key_x = memory.read(*public_key_x).to_field(); - let public_key_y = memory.read(*public_key_y).to_field(); + let public_key_x = memory.read(*public_key_x).try_into().unwrap(); + let public_key_y = memory.read(*public_key_y).try_into().unwrap(); let message: Vec = to_u8_vec(read_heap_vector(memory, message)); let signature: Vec = to_u8_vec(read_heap_vector(memory, signature)); let verified = @@ -135,26 +134,26 @@ pub(crate) fn evaluate_black_box( Ok(()) } BlackBoxOp::FixedBaseScalarMul { low, high, result } => { - let low = memory.read(*low).to_field(); - let high = memory.read(*high).to_field(); + let low = memory.read(*low).try_into().unwrap(); + let high = memory.read(*high).try_into().unwrap(); let (x, y) = solver.fixed_base_scalar_mul(&low, &high)?; memory.write_slice(memory.read_ref(result.pointer), &[x.into(), y.into()]); Ok(()) } BlackBoxOp::EmbeddedCurveAdd { input1_x, input1_y, input2_x, input2_y, result } => { - let input1_x = memory.read(*input1_x).to_field(); - let input1_y = memory.read(*input1_y).to_field(); - let input2_x = memory.read(*input2_x).to_field(); - let input2_y = memory.read(*input2_y).to_field(); + let input1_x = memory.read(*input1_x).try_into().unwrap(); + let input1_y = memory.read(*input1_y).try_into().unwrap(); + let input2_x = memory.read(*input2_x).try_into().unwrap(); + let input2_y = memory.read(*input2_y).try_into().unwrap(); let (x, y) = solver.ec_add(&input1_x, &input1_y, &input2_x, &input2_y)?; memory.write_slice(memory.read_ref(result.pointer), &[x.into(), y.into()]); Ok(()) } BlackBoxOp::PedersenCommitment { inputs, domain_separator, output } => { let inputs: Vec = - read_heap_vector(memory, inputs).iter().map(|x| x.to_field()).collect(); + read_heap_vector(memory, inputs).iter().map(|&x| x.try_into().unwrap()).collect(); let domain_separator: u32 = - memory.read(*domain_separator).to_u128().try_into().map_err(|_| { + memory.read(*domain_separator).try_into().map_err(|_| { BlackBoxResolutionError::Failed( BlackBoxFunc::PedersenCommitment, "Invalid signature length".to_string(), @@ -166,9 +165,9 @@ pub(crate) fn evaluate_black_box( } BlackBoxOp::PedersenHash { inputs, domain_separator, output } => { let inputs: Vec = - read_heap_vector(memory, inputs).iter().map(|x| x.to_field()).collect(); + read_heap_vector(memory, inputs).iter().map(|&x| x.try_into().unwrap()).collect(); let domain_separator: u32 = - memory.read(*domain_separator).to_u128().try_into().map_err(|_| { + memory.read(*domain_separator).try_into().map_err(|_| { BlackBoxResolutionError::Failed( BlackBoxFunc::PedersenCommitment, "Invalid signature length".to_string(), @@ -186,12 +185,12 @@ pub(crate) fn evaluate_black_box( BlackBoxOp::BigIntToLeBytes { .. } => todo!(), BlackBoxOp::Poseidon2Permutation { message, output, len } => { let input = read_heap_vector(memory, message); - let input: Vec = input.iter().map(|x| x.to_field()).collect(); - let len = memory.read(*len).to_u128() as u32; + let input: Vec = input.iter().map(|&x| x.try_into().unwrap()).collect(); + let len = memory.read(*len).try_into().unwrap(); let result = solver.poseidon2_permutation(&input, len)?; let mut values = Vec::new(); for i in result { - values.push(Value::from(i)); + values.push(i.into()); } memory.write_slice(memory.read_ref(output.pointer), &values); Ok(()) @@ -205,8 +204,8 @@ pub(crate) fn evaluate_black_box( format!("Expected 16 inputs but encountered {}", &inputs.len()), )); } - for (i, input) in inputs.iter().enumerate() { - message[i] = input.to_u128() as u32; + for (i, &input) in inputs.iter().enumerate() { + message[i] = input.try_into().unwrap(); } let mut state = [0; 8]; let values = read_heap_vector(memory, hash_values); @@ -216,12 +215,12 @@ pub(crate) fn evaluate_black_box( format!("Expected 8 values but encountered {}", &values.len()), )); } - for (i, value) in values.iter().enumerate() { - state[i] = value.to_u128() as u32; + for (i, &value) in values.iter().enumerate() { + state[i] = value.try_into().unwrap(); } sha256compression(&mut state, &message); - let state = state.map(|x| Value::from(x as u128)); + let state = state.map(|x| x.into()); memory.write_slice(memory.read_ref(output.pointer), &state); Ok(()) @@ -257,10 +256,11 @@ fn black_box_function_from_op(op: &BlackBoxOp) -> BlackBoxFunc { #[cfg(test)] mod test { use acir::brillig::{BlackBoxOp, MemoryAddress}; + use acvm_blackbox_solver::StubbedBlackBoxSolver; use crate::{ black_box::{evaluate_black_box, to_u8_vec, to_value_vec}, - DummyBlackBoxSolver, HeapArray, HeapVector, Memory, + HeapArray, HeapVector, Memory, }; #[test] @@ -281,7 +281,7 @@ mod test { output: HeapArray { pointer: 2.into(), size: 32 }, }; - evaluate_black_box(&op, &DummyBlackBoxSolver, &mut memory).unwrap(); + evaluate_black_box(&op, &StubbedBlackBoxSolver, &mut memory).unwrap(); let result = memory.read_slice(MemoryAddress(result_pointer), 32); diff --git a/acvm-repo/brillig_vm/src/lib.rs b/acvm-repo/brillig_vm/src/lib.rs index c7bf014f068..65654e24720 100644 --- a/acvm-repo/brillig_vm/src/lib.rs +++ b/acvm-repo/brillig_vm/src/lib.rs @@ -13,23 +13,22 @@ use acir::brillig::{ BinaryFieldOp, BinaryIntOp, ForeignCallParam, ForeignCallResult, HeapArray, HeapValueType, - HeapVector, MemoryAddress, Opcode, Value, ValueOrArray, + HeapVector, MemoryAddress, Opcode, ValueOrArray, }; use acir::FieldElement; +use acvm_blackbox_solver::BlackBoxFunctionSolver; +use arithmetic::{evaluate_binary_field_op, evaluate_binary_int_op, BrilligArithmeticError}; +use black_box::evaluate_black_box; +use num_bigint::BigUint; + // Re-export `brillig`. pub use acir::brillig; +pub use memory::{Memory, MemoryValue, MEMORY_ADDRESSING_BIT_SIZE}; mod arithmetic; mod black_box; mod memory; -use acvm_blackbox_solver::{BlackBoxFunctionSolver, BlackBoxResolutionError}; -use arithmetic::{evaluate_binary_bigint_op, evaluate_binary_field_op}; -use black_box::evaluate_black_box; - -pub use memory::Memory; -use num_bigint::BigUint; - /// The error call stack contains the opcode indexes of the call stack at the time of failure, plus the index of the opcode that failed. pub type ErrorCallStack = Vec; @@ -63,7 +62,7 @@ pub enum VMStatus { /// VM encapsulates the state of the Brillig VM during execution. pub struct VM<'a, B: BlackBoxFunctionSolver> { /// Calldata to the brillig function - calldata: Vec, + calldata: Vec, /// Instruction pointer program_counter: usize, /// A counter maintained throughout a Brillig process that determines @@ -79,7 +78,7 @@ pub struct VM<'a, B: BlackBoxFunctionSolver> { /// Memory of the VM memory: Memory, /// Call stack - call_stack: Vec, + call_stack: Vec, /// The solver for blackbox functions black_box_solver: &'a B, } @@ -87,7 +86,7 @@ pub struct VM<'a, B: BlackBoxFunctionSolver> { impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { /// Constructs a new VM instance pub fn new( - calldata: Vec, + calldata: Vec, bytecode: &'a [Opcode], foreign_call_results: Vec, black_box_solver: &'a B, @@ -143,8 +142,7 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { /// Indicating that the VM encountered a `Trap` Opcode /// or an invalid state. fn fail(&mut self, message: String) -> VMStatus { - let mut error_stack: Vec<_> = - self.call_stack.iter().map(|value| value.to_usize()).collect(); + let mut error_stack: Vec<_> = self.call_stack.clone(); error_stack.push(self.program_counter); self.status(VMStatus::Failure { call_stack: error_stack, message }); self.status.clone() @@ -159,22 +157,18 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { self.status.clone() } - pub fn get_memory(&self) -> &[Value] { + pub fn get_memory(&self) -> &[MemoryValue] { self.memory.values() } - pub fn write_memory_at(&mut self, ptr: usize, value: Value) { + pub fn write_memory_at(&mut self, ptr: usize, value: MemoryValue) { self.memory.write(MemoryAddress(ptr), value); } /// Returns the VM's current call stack, including the actual program /// counter in the last position of the returned vector. pub fn get_call_stack(&self) -> Vec { - self.call_stack - .iter() - .map(|program_counter| program_counter.to_usize()) - .chain(std::iter::once(self.program_counter)) - .collect() + self.call_stack.iter().copied().chain(std::iter::once(self.program_counter)).collect() } /// Process a single opcode and modify the program counter. @@ -182,13 +176,16 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { let opcode = &self.bytecode[self.program_counter]; match opcode { Opcode::BinaryFieldOp { op, lhs, rhs, destination: result } => { - self.process_binary_field_op(*op, *lhs, *rhs, *result); - self.increment_program_counter() + if let Err(error) = self.process_binary_field_op(*op, *lhs, *rhs, *result) { + self.fail(error.to_string()) + } else { + self.increment_program_counter() + } } Opcode::BinaryIntOp { op, bit_size, lhs, rhs, destination: result } => { if let Err(error) = self.process_binary_int_op(*op, *bit_size, *lhs, *rhs, *result) { - self.fail(error) + self.fail(error.to_string()) } else { self.increment_program_counter() } @@ -204,26 +201,29 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { // Check if condition is true // We use 0 to mean false and any other value to mean true let condition_value = self.memory.read(*condition); - if !condition_value.is_zero() { + if condition_value.try_into().expect("condition value is not a boolean") { return self.set_program_counter(*destination); } self.increment_program_counter() } Opcode::JumpIfNot { condition, location: destination } => { let condition_value = self.memory.read(*condition); - if condition_value.is_zero() { - return self.set_program_counter(*destination); + if condition_value.try_into().expect("condition value is not a boolean") { + return self.increment_program_counter(); } - self.increment_program_counter() + self.set_program_counter(*destination) } Opcode::CalldataCopy { destination_address, size, offset } => { - let values = &self.calldata[*offset..(*offset + size)]; - self.memory.write_slice(*destination_address, values); + let values: Vec<_> = self.calldata[*offset..(*offset + size)] + .iter() + .map(|value| MemoryValue::new_field(*value)) + .collect(); + self.memory.write_slice(*destination_address, &values); self.increment_program_counter() } Opcode::Return => { if let Some(return_location) = self.call_stack.pop() { - self.set_program_counter(return_location.to_usize() + 1) + self.set_program_counter(return_location + 1) } else { self.fail("return opcode hit, but callstack already empty".to_string()) } @@ -254,81 +254,14 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { return self.wait_for_foreign_call(function.clone(), resolved_inputs); } - let values = &self.foreign_call_results[self.foreign_call_counter].values; - - let mut invalid_foreign_call_result = false; - for ((destination, value_type), output) in - destinations.iter().zip(destination_value_types).zip(values) - { - match (destination, value_type) { - (ValueOrArray::MemoryAddress(value_index), HeapValueType::Simple) => { - match output { - ForeignCallParam::Single(value) => { - self.memory.write(*value_index, *value); - } - _ => unreachable!( - "Function result size does not match brillig bytecode. Expected 1 result but got {output:?}" - ), - } - } - ( - ValueOrArray::HeapArray(HeapArray { pointer: pointer_index, size }), - HeapValueType::Array { value_types, size: type_size }, - ) if size == type_size => { - if HeapValueType::all_simple(value_types) { - match output { - ForeignCallParam::Array(values) => { - if values.len() != *size { - invalid_foreign_call_result = true; - break; - } - // Convert the destination pointer to a usize - let destination = self.memory.read_ref(*pointer_index); - // Write to our destination memory - self.memory.write_slice(destination, values); - } - _ => { - unreachable!("Function result size does not match brillig bytecode size") - } - } - } else { - unimplemented!("deflattening heap arrays from foreign calls"); - } - } - ( - ValueOrArray::HeapVector(HeapVector {pointer: pointer_index, size: size_index }), - HeapValueType::Vector { value_types }, - ) => { - if HeapValueType::all_simple(value_types) { - match output { - ForeignCallParam::Array(values) => { - // Set our size in the size address - self.memory.write(*size_index, Value::from(values.len())); - // Convert the destination pointer to a usize - let destination = self.memory.read_ref(*pointer_index); - // Write to our destination memory - self.memory.write_slice(destination, values); - } - _ => { - unreachable!("Function result size does not match brillig bytecode size") - } - } - } else { - unimplemented!("deflattening heap vectors from foreign calls"); - } - } - _ => { - unreachable!("Unexpected value type {value_type:?} for destination {destination:?}"); - } - } - } + let write_result = self.write_foreign_call_result( + destinations, + destination_value_types, + self.foreign_call_counter, + ); - // These checks must come after resolving the foreign call outputs as `fail` uses a mutable reference - if destinations.len() != values.len() { - self.fail(format!("{} output values were provided as a foreign call result for {} destination slots", values.len(), destinations.len())); - } - if invalid_foreign_call_result { - self.fail("Function result size does not match brillig bytecode".to_owned()); + if let Err(e) = write_result { + return self.fail(e); } self.foreign_call_counter += 1; @@ -339,6 +272,15 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { self.memory.write(*destination_address, source_value); self.increment_program_counter() } + Opcode::ConditionalMov { destination, source_a, source_b, condition } => { + let condition_value = self.memory.read(*condition); + if condition_value.try_into().expect("condition value is not a boolean") { + self.memory.write(*destination, self.memory.read(*source_a)); + } else { + self.memory.write(*destination, self.memory.read(*source_b)); + } + self.increment_program_counter() + } Opcode::Trap => self.fail("explicit trap hit in brillig".to_string()), Opcode::Stop { return_data_offset, return_data_size } => { self.finish(*return_data_offset, *return_data_size) @@ -360,11 +302,12 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { } Opcode::Call { location } => { // Push a return location - self.call_stack.push(Value::from(self.program_counter)); + self.call_stack.push(self.program_counter); self.set_program_counter(*location) } - Opcode::Const { destination, value, bit_size: _ } => { - self.memory.write(*destination, *value); + Opcode::Const { destination, value, bit_size } => { + // Consts are not checked in runtime to fit in the bit size, since they can safely be checked statically. + self.memory.write(*destination, MemoryValue::new(*value, *bit_size)); self.increment_program_counter() } Opcode::BlackBox(black_box_op) => { @@ -404,15 +347,19 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { value_type: &HeapValueType, ) -> ForeignCallParam { match (input, value_type) { - (ValueOrArray::MemoryAddress(value_index), HeapValueType::Simple) => { - self.memory.read(value_index).into() + (ValueOrArray::MemoryAddress(value_index), HeapValueType::Simple(_)) => { + self.memory.read(value_index).value.into() } ( ValueOrArray::HeapArray(HeapArray { pointer: pointer_index, size }), HeapValueType::Array { value_types, size: type_size }, ) if *type_size == size => { let start = self.memory.read_ref(pointer_index); - self.read_slice_of_values_from_memory(start, size, value_types).into() + self.read_slice_of_values_from_memory(start, size, value_types) + .into_iter() + .map(|mem_value| mem_value.value) + .collect::>() + .into() } ( ValueOrArray::HeapVector(HeapVector { pointer: pointer_index, size: size_index }), @@ -420,7 +367,11 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { ) => { let start = self.memory.read_ref(pointer_index); let size = self.memory.read(size_index).to_usize(); - self.read_slice_of_values_from_memory(start, size, value_types).into() + self.read_slice_of_values_from_memory(start, size, value_types) + .into_iter() + .map(|mem_value| mem_value.value) + .collect::>() + .into() } _ => { unreachable!("Unexpected value type {value_type:?} for input {input:?}"); @@ -435,7 +386,7 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { start: MemoryAddress, size: usize, value_types: &[HeapValueType], - ) -> Vec { + ) -> Vec { if HeapValueType::all_simple(value_types) { self.memory.read_slice(start, size).to_vec() } else { @@ -450,9 +401,8 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { .flat_map(|(i, value_type)| { let value_address: MemoryAddress = (start.to_usize() + i).into(); match value_type { - HeapValueType::Simple => { - let value = self.memory.read(value_address); - vec![value] + HeapValueType::Simple(_) => { + vec![self.memory.read(value_address)] } HeapValueType::Array { value_types, size } => { let array_address = self.memory.read_ref(value_address); @@ -477,6 +427,124 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { } } + fn write_foreign_call_result( + &mut self, + destinations: &[ValueOrArray], + destination_value_types: &[HeapValueType], + foreign_call_index: usize, + ) -> Result<(), String> { + let values = &self.foreign_call_results[foreign_call_index].values; + + if destinations.len() != values.len() { + return Err(format!( + "{} output values were provided as a foreign call result for {} destination slots", + values.len(), + destinations.len() + )); + } + + for ((destination, value_type), output) in + destinations.iter().zip(destination_value_types).zip(values) + { + match (destination, value_type) { + (ValueOrArray::MemoryAddress(value_index), HeapValueType::Simple(bit_size)) => { + match output { + ForeignCallParam::Single(value) => { + let memory_value = MemoryValue::new_checked(*value, *bit_size); + if let Some(memory_value) = memory_value { + self.memory.write(*value_index, memory_value); + } else { + return Err(format!( + "Foreign call result value {} does not fit in bit size {}", + value, + bit_size + )); + } + } + _ => return Err(format!( + "Function result size does not match brillig bytecode. Expected 1 result but got {output:?}") + ), + } + } + ( + ValueOrArray::HeapArray(HeapArray { pointer: pointer_index, size }), + HeapValueType::Array { value_types, size: type_size }, + ) if size == type_size => { + if HeapValueType::all_simple(value_types) { + let bit_sizes_iterator = value_types.iter().map(|typ| match typ { + HeapValueType::Simple(bit_size) => *bit_size, + _ => unreachable!("Expected simple value type"), + }).cycle(); + match output { + ForeignCallParam::Array(values) => { + if values.len() != *size { + return Err("Foreign call result array doesn't match expected size".to_string()); + } + // Convert the destination pointer to a usize + let destination = self.memory.read_ref(*pointer_index); + // Write to our destination memory + let memory_values: Option> = values.iter().zip(bit_sizes_iterator).map( + |(value, bit_size)| MemoryValue::new_checked(*value, bit_size)).collect(); + if let Some(memory_values) = memory_values { + self.memory.write_slice(destination, &memory_values); + } else { + return Err(format!( + "Foreign call result values {:?} do not match expected bit sizes", + values, + )); + } + } + _ => { + return Err("Function result size does not match brillig bytecode size".to_string()); + } + } + } else { + unimplemented!("deflattening heap arrays from foreign calls"); + } + } + ( + ValueOrArray::HeapVector(HeapVector {pointer: pointer_index, size: size_index }), + HeapValueType::Vector { value_types }, + ) => { + if HeapValueType::all_simple(value_types) { + let bit_sizes_iterator = value_types.iter().map(|typ| match typ { + HeapValueType::Simple(bit_size) => *bit_size, + _ => unreachable!("Expected simple value type"), + }).cycle(); + match output { + ForeignCallParam::Array(values) => { + // Set our size in the size address + self.memory.write(*size_index, values.len().into()); + // Convert the destination pointer to a usize + let destination = self.memory.read_ref(*pointer_index); + // Write to our destination memory + let memory_values: Option> = values.iter().zip(bit_sizes_iterator).map(|(value, bit_size)| MemoryValue::new_checked(*value, bit_size)).collect(); + if let Some(memory_values) = memory_values { + self.memory.write_slice(destination, &memory_values); + }else{ + return Err(format!( + "Foreign call result values {:?} do not match expected bit sizes", + values, + )); + } + } + _ => { + return Err("Function result size does not match brillig bytecode size".to_string()); + } + } + } else { + unimplemented!("deflattening heap vectors from foreign calls"); + } + } + _ => { + return Err(format!("Unexpected value type {value_type:?} for destination {destination:?}")); + } + } + } + + Ok(()) + } + /// Process a binary operation. /// This method will not modify the program counter. fn process_binary_field_op( @@ -485,14 +553,15 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { lhs: MemoryAddress, rhs: MemoryAddress, result: MemoryAddress, - ) { + ) -> Result<(), BrilligArithmeticError> { let lhs_value = self.memory.read(lhs); let rhs_value = self.memory.read(rhs); - let result_value = - evaluate_binary_field_op(&op, lhs_value.to_field(), rhs_value.to_field()); + let result_value = evaluate_binary_field_op(&op, lhs_value, rhs_value)?; + + self.memory.write(result, result_value); - self.memory.write(result, result_value.into()); + Ok(()) } /// Process a binary operation. @@ -504,86 +573,35 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> { lhs: MemoryAddress, rhs: MemoryAddress, result: MemoryAddress, - ) -> Result<(), String> { + ) -> Result<(), BrilligArithmeticError> { let lhs_value = self.memory.read(lhs); let rhs_value = self.memory.read(rhs); - // Convert to big integers - let lhs_big = BigUint::from_bytes_be(&lhs_value.to_field().to_be_bytes()); - let rhs_big = BigUint::from_bytes_be(&rhs_value.to_field().to_be_bytes()); - let result_value = evaluate_binary_bigint_op(&op, lhs_big, rhs_big, bit_size)?; - // Convert back to field element - self.memory - .write(result, FieldElement::from_be_bytes_reduce(&result_value.to_bytes_be()).into()); + let result_value = evaluate_binary_int_op(&op, lhs_value, rhs_value, bit_size)?; + self.memory.write(result, result_value); Ok(()) } /// Casts a value to a different bit size. - fn cast(&self, bit_size: u32, value: Value) -> Value { - let lhs_big = BigUint::from_bytes_be(&value.to_field().to_be_bytes()); + fn cast(&self, bit_size: u32, source_value: MemoryValue) -> MemoryValue { + let lhs_big = BigUint::from_bytes_be(&source_value.value.to_be_bytes()); let mask = BigUint::from(2_u32).pow(bit_size) - 1_u32; - FieldElement::from_be_bytes_reduce(&(lhs_big & mask).to_bytes_be()).into() - } -} - -pub(crate) struct DummyBlackBoxSolver; - -impl BlackBoxFunctionSolver for DummyBlackBoxSolver { - fn schnorr_verify( - &self, - _public_key_x: &FieldElement, - _public_key_y: &FieldElement, - _signature: &[u8], - _message: &[u8], - ) -> Result { - Ok(true) - } - fn pedersen_commitment( - &self, - _inputs: &[FieldElement], - _domain_separator: u32, - ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { - Ok((2_u128.into(), 3_u128.into())) - } - fn pedersen_hash( - &self, - _inputs: &[FieldElement], - _domain_separator: u32, - ) -> Result { - Ok(6_u128.into()) - } - fn fixed_base_scalar_mul( - &self, - _low: &FieldElement, - _high: &FieldElement, - ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { - Ok((4_u128.into(), 5_u128.into())) - } - fn ec_add( - &self, - _input1_x: &FieldElement, - _input1_y: &FieldElement, - _input2_x: &FieldElement, - _input2_y: &FieldElement, - ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { - Ok((5_u128.into(), 6_u128.into())) - } - fn poseidon2_permutation( - &self, - _input: &[FieldElement], - len: u32, - ) -> Result, BlackBoxResolutionError> { - Ok(vec![0_u128.into(); len as usize]) + MemoryValue { + value: FieldElement::from_be_bytes_reduce(&(lhs_big & mask).to_bytes_be()), + bit_size, + } } } #[cfg(test)] mod tests { + use acvm_blackbox_solver::StubbedBlackBoxSolver; + use super::*; #[test] fn add_single_step_smoke() { - let calldata = vec![Value::from(27u128)]; + let calldata = vec![FieldElement::from(27u128)]; // Add opcode to add the value in address `0` and `1` // and place the output in address `2` @@ -595,7 +613,7 @@ mod tests { // Start VM let opcodes = [calldata_copy]; - let mut vm = VM::new(calldata, &opcodes, vec![], &DummyBlackBoxSolver); + let mut vm = VM::new(calldata, &opcodes, vec![], &StubbedBlackBoxSolver); // Process a single VM opcode // @@ -609,7 +627,7 @@ mod tests { let VM { memory, .. } = vm; let output_value = memory.read(MemoryAddress::from(0)); - assert_eq!(output_value, Value::from(27u128)); + assert_eq!(output_value.value, FieldElement::from(27u128)); } #[test] @@ -618,12 +636,12 @@ mod tests { let mut opcodes = vec![]; let lhs = { - calldata.push(Value::from(2u128)); + calldata.push(2u128.into()); MemoryAddress::from(calldata.len() - 1) }; let rhs = { - calldata.push(Value::from(2u128)); + calldata.push(2u128.into()); MemoryAddress::from(calldata.len() - 1) }; @@ -634,13 +652,12 @@ mod tests { size: 2, offset: 0, }); - let equal_cmp_opcode = - Opcode::BinaryIntOp { op: BinaryIntOp::Equals, bit_size: 1, lhs, rhs, destination }; - opcodes.push(equal_cmp_opcode); + + opcodes.push(Opcode::BinaryFieldOp { destination, op: BinaryFieldOp::Equals, lhs, rhs }); opcodes.push(Opcode::Jump { location: 3 }); - opcodes.push(Opcode::JumpIf { condition: MemoryAddress::from(2), location: 4 }); + opcodes.push(Opcode::JumpIf { condition: destination, location: 4 }); - let mut vm = VM::new(calldata, &opcodes, vec![], &DummyBlackBoxSolver); + let mut vm = VM::new(calldata, &opcodes, vec![], &StubbedBlackBoxSolver); let status = vm.process_opcode(); assert_eq!(status, VMStatus::InProgress); @@ -648,8 +665,8 @@ mod tests { let status = vm.process_opcode(); assert_eq!(status, VMStatus::InProgress); - let output_cmp_value = vm.memory.read(MemoryAddress::from(2)); - assert_eq!(output_cmp_value, Value::from(true)); + let output_cmp_value = vm.memory.read(destination); + assert_eq!(output_cmp_value.value, true.into()); let status = vm.process_opcode(); assert_eq!(status, VMStatus::InProgress); @@ -660,7 +677,7 @@ mod tests { #[test] fn jmpifnot_opcode() { - let calldata = vec![Value::from(1u128), Value::from(2u128)]; + let calldata = vec![1u128.into(), 2u128.into()]; let calldata_copy = Opcode::CalldataCopy { destination_address: MemoryAddress::from(0), @@ -697,7 +714,7 @@ mod tests { jump_if_not_opcode, add_opcode, ]; - let mut vm = VM::new(calldata, &opcodes, vec![], &DummyBlackBoxSolver); + let mut vm = VM::new(calldata, &opcodes, vec![], &StubbedBlackBoxSolver); let status = vm.process_opcode(); assert_eq!(status, VMStatus::InProgress); @@ -708,7 +725,7 @@ mod tests { assert_eq!(status, VMStatus::InProgress); let output_cmp_value = vm.memory.read(MemoryAddress::from(2)); - assert_eq!(output_cmp_value, Value::from(false)); + assert_eq!(output_cmp_value.value, false.into()); let status = vm.process_opcode(); assert_eq!(status, VMStatus::InProgress); @@ -725,12 +742,12 @@ mod tests { // The address at index `2` should have not changed as we jumped over the add opcode let VM { memory, .. } = vm; let output_value = memory.read(MemoryAddress::from(2)); - assert_eq!(output_value, Value::from(false)); + assert_eq!(output_value.value, false.into()); } #[test] fn cast_opcode() { - let calldata = vec![Value::from((2_u128.pow(32)) - 1)]; + let calldata = vec![((2_u128.pow(32)) - 1).into()]; let opcodes = &[ Opcode::CalldataCopy { @@ -745,7 +762,7 @@ mod tests { }, Opcode::Stop { return_data_offset: 1, return_data_size: 1 }, ]; - let mut vm = VM::new(calldata, opcodes, vec![], &DummyBlackBoxSolver); + let mut vm = VM::new(calldata, opcodes, vec![], &StubbedBlackBoxSolver); let status = vm.process_opcode(); assert_eq!(status, VMStatus::InProgress); @@ -759,12 +776,12 @@ mod tests { let VM { memory, .. } = vm; let casted_value = memory.read(MemoryAddress::from(1)); - assert_eq!(casted_value, Value::from(2_u128.pow(8) - 1)); + assert_eq!(casted_value.value, (2_u128.pow(8) - 1).into()); } #[test] fn mov_opcode() { - let calldata = vec![Value::from(1u128), Value::from(2u128), Value::from(3u128)]; + let calldata = vec![(1u128).into(), (2u128).into(), (3u128).into()]; let calldata_copy = Opcode::CalldataCopy { destination_address: MemoryAddress::from(0), @@ -776,7 +793,7 @@ mod tests { Opcode::Mov { destination: MemoryAddress::from(2), source: MemoryAddress::from(0) }; let opcodes = &[calldata_copy, mov_opcode]; - let mut vm = VM::new(calldata, opcodes, vec![], &DummyBlackBoxSolver); + let mut vm = VM::new(calldata, opcodes, vec![], &StubbedBlackBoxSolver); let status = vm.process_opcode(); assert_eq!(status, VMStatus::InProgress); @@ -787,22 +804,83 @@ mod tests { let VM { memory, .. } = vm; let destination_value = memory.read(MemoryAddress::from(2)); - assert_eq!(destination_value, Value::from(1u128)); + assert_eq!(destination_value.value, (1u128).into()); let source_value = memory.read(MemoryAddress::from(0)); - assert_eq!(source_value, Value::from(1u128)); + assert_eq!(source_value.value, (1u128).into()); + } + + #[test] + fn cmov_opcode() { + let calldata = vec![(0u128).into(), (1u128).into(), (2u128).into(), (3u128).into()]; + + let calldata_copy = Opcode::CalldataCopy { + destination_address: MemoryAddress::from(0), + size: 4, + offset: 0, + }; + + let cast_zero = Opcode::Cast { + destination: MemoryAddress::from(0), + source: MemoryAddress::from(0), + bit_size: 1, + }; + + let cast_one = Opcode::Cast { + destination: MemoryAddress::from(1), + source: MemoryAddress::from(1), + bit_size: 1, + }; + + let opcodes = &[ + calldata_copy, + cast_zero, + cast_one, + Opcode::ConditionalMov { + destination: MemoryAddress(4), // Sets 3_u128 to memory address 4 + source_a: MemoryAddress(2), + source_b: MemoryAddress(3), + condition: MemoryAddress(0), + }, + Opcode::ConditionalMov { + destination: MemoryAddress(5), // Sets 2_u128 to memory address 5 + source_a: MemoryAddress(2), + source_b: MemoryAddress(3), + condition: MemoryAddress(1), + }, + ]; + let mut vm = VM::new(calldata, opcodes, vec![], &StubbedBlackBoxSolver); + + let status = vm.process_opcode(); + assert_eq!(status, VMStatus::InProgress); + + let status = vm.process_opcode(); + assert_eq!(status, VMStatus::InProgress); + + let status = vm.process_opcode(); + assert_eq!(status, VMStatus::InProgress); + + let status = vm.process_opcode(); + assert_eq!(status, VMStatus::InProgress); + + let status = vm.process_opcode(); + assert_eq!(status, VMStatus::Finished { return_data_offset: 0, return_data_size: 0 }); + + let VM { memory, .. } = vm; + + let destination_value = memory.read(MemoryAddress::from(4)); + assert_eq!(destination_value.value, (3_u128).into()); + + let source_value = memory.read(MemoryAddress::from(5)); + assert_eq!(source_value.value, (2_u128).into()); } #[test] fn cmp_binary_ops() { let bit_size = 32; - let calldata = vec![ - Value::from(2u128), - Value::from(2u128), - Value::from(0u128), - Value::from(5u128), - Value::from(6u128), - ]; + let calldata = + vec![(2u128).into(), (2u128).into(), (0u128).into(), (5u128).into(), (6u128).into()]; + let calldata_size = calldata.len(); let calldata_copy = Opcode::CalldataCopy { destination_address: MemoryAddress::from(0), @@ -810,6 +888,14 @@ mod tests { offset: 0, }; + let cast_opcodes: Vec<_> = (0..calldata_size) + .map(|index| Opcode::Cast { + destination: MemoryAddress::from(index), + source: MemoryAddress::from(index), + bit_size, + }) + .collect(); + let equal_opcode = Opcode::BinaryIntOp { bit_size, op: BinaryIntOp::Equals, @@ -842,42 +928,47 @@ mod tests { destination: MemoryAddress::from(2), }; - let opcodes = [ - calldata_copy, - equal_opcode, - not_equal_opcode, - less_than_opcode, - less_than_equal_opcode, - ]; - let mut vm = VM::new(calldata, &opcodes, vec![], &DummyBlackBoxSolver); + let opcodes: Vec<_> = std::iter::once(calldata_copy) + .chain(cast_opcodes) + .chain([equal_opcode, not_equal_opcode, less_than_opcode, less_than_equal_opcode]) + .collect(); + let mut vm = VM::new(calldata, &opcodes, vec![], &StubbedBlackBoxSolver); + // Calldata copy let status = vm.process_opcode(); assert_eq!(status, VMStatus::InProgress); + for _ in 0..calldata_size { + let status = vm.process_opcode(); + assert_eq!(status, VMStatus::InProgress); + } + + // Equals let status = vm.process_opcode(); assert_eq!(status, VMStatus::InProgress); let output_eq_value = vm.memory.read(MemoryAddress::from(2)); - assert_eq!(output_eq_value, Value::from(true)); + assert_eq!(output_eq_value, true.into()); let status = vm.process_opcode(); assert_eq!(status, VMStatus::InProgress); let output_neq_value = vm.memory.read(MemoryAddress::from(2)); - assert_eq!(output_neq_value, Value::from(false)); + assert_eq!(output_neq_value, false.into()); let status = vm.process_opcode(); assert_eq!(status, VMStatus::InProgress); let lt_value = vm.memory.read(MemoryAddress::from(2)); - assert_eq!(lt_value, Value::from(true)); + assert_eq!(lt_value, true.into()); let status = vm.process_opcode(); assert_eq!(status, VMStatus::Finished { return_data_offset: 0, return_data_size: 0 }); let lte_value = vm.memory.read(MemoryAddress::from(2)); - assert_eq!(lte_value, Value::from(true)); + assert_eq!(lte_value, true.into()); } + #[test] fn store_opcode() { /// Brillig code for the following: @@ -887,8 +978,8 @@ mod tests { /// memory[i] = i as Value; /// i += 1; /// } - fn brillig_write_memory(item_count: usize) -> Vec { - let bit_size = 32; + fn brillig_write_memory(item_count: usize) -> Vec { + let bit_size = 64; let r_i = MemoryAddress::from(0); let r_len = MemoryAddress::from(1); let r_tmp = MemoryAddress::from(2); @@ -896,21 +987,17 @@ mod tests { let start = [ // i = 0 - Opcode::Const { destination: r_i, value: 0u128.into(), bit_size: 32 }, + Opcode::Const { destination: r_i, value: 0u128.into(), bit_size }, // len = memory.len() (approximation) - Opcode::Const { - destination: r_len, - value: Value::from(item_count as u128), - bit_size: 32, - }, + Opcode::Const { destination: r_len, value: item_count.into(), bit_size }, // pointer = free_memory_ptr - Opcode::Const { destination: r_pointer, value: 4u128.into(), bit_size: 32 }, + Opcode::Const { destination: r_pointer, value: 4u128.into(), bit_size }, ]; let loop_body = [ // *i = i Opcode::Store { destination_pointer: r_pointer, source: r_i }, // tmp = 1 - Opcode::Const { destination: r_tmp, value: 1u128.into(), bit_size: 32 }, + Opcode::Const { destination: r_tmp, value: 1u128.into(), bit_size }, // i = i + 1 (tmp) Opcode::BinaryIntOp { destination: r_i, @@ -945,17 +1032,12 @@ mod tests { } let memory = brillig_write_memory(5); - let expected = vec![ - Value::from(0u128), - Value::from(1u128), - Value::from(2u128), - Value::from(3u128), - Value::from(4u128), - ]; + let expected = + vec![(0u64).into(), (1u64).into(), (2u64).into(), (3u64).into(), (4u64).into()]; assert_eq!(memory, expected); let memory = brillig_write_memory(1024); - let expected: Vec = (0..1024).map(|i| Value::from(i as u128)).collect(); + let expected: Vec<_> = (0..1024).map(|i: u64| i.into()).collect(); assert_eq!(memory, expected); } @@ -969,8 +1051,8 @@ mod tests { /// sum += memory[i]; /// i += 1; /// } - fn brillig_sum_memory(memory: Vec) -> Value { - let bit_size = 32; + fn brillig_sum_memory(memory: Vec) -> FieldElement { + let bit_size = 64; let r_i = MemoryAddress::from(0); let r_len = MemoryAddress::from(1); let r_sum = MemoryAddress::from(2); @@ -979,17 +1061,17 @@ mod tests { let start = [ // sum = 0 - Opcode::Const { destination: r_sum, value: 0u128.into(), bit_size: 32 }, - // i = 0 - Opcode::Const { destination: r_i, value: 0u128.into(), bit_size: 32 }, - // len = array.len() (approximation) Opcode::Const { - destination: r_len, - value: Value::from(memory.len() as u128), - bit_size: 32, + destination: r_sum, + value: 0u128.into(), + bit_size: FieldElement::max_num_bits(), }, + // i = 0 + Opcode::Const { destination: r_i, value: 0u128.into(), bit_size }, + // len = array.len() (approximation) + Opcode::Const { destination: r_len, value: memory.len().into(), bit_size }, // pointer = array_ptr - Opcode::Const { destination: r_pointer, value: 5u128.into(), bit_size: 32 }, + Opcode::Const { destination: r_pointer, value: 5u128.into(), bit_size }, Opcode::CalldataCopy { destination_address: MemoryAddress(5), size: memory.len(), @@ -1000,15 +1082,14 @@ mod tests { // tmp = *i Opcode::Load { destination: r_tmp, source_pointer: r_pointer }, // sum = sum + tmp - Opcode::BinaryIntOp { + Opcode::BinaryFieldOp { destination: r_sum, lhs: r_sum, - op: BinaryIntOp::Add, + op: BinaryFieldOp::Add, rhs: r_tmp, - bit_size, }, // tmp = 1 - Opcode::Const { destination: r_tmp, value: 1u128.into(), bit_size: 32 }, + Opcode::Const { destination: r_tmp, value: 1u128.into(), bit_size }, // i = i + 1 (tmp) Opcode::BinaryIntOp { destination: r_i, @@ -1039,20 +1120,20 @@ mod tests { let opcodes = [&start[..], &loop_body[..]].concat(); let vm = brillig_execute_and_get_vm(memory, &opcodes); - vm.memory.read(r_sum) + vm.memory.read(r_sum).value } assert_eq!( brillig_sum_memory(vec![ - Value::from(1u128), - Value::from(2u128), - Value::from(3u128), - Value::from(4u128), - Value::from(5u128), + (1u128).into(), + (2u128).into(), + (3u128).into(), + (4u128).into(), + (5u128).into(), ]), - Value::from(15u128) + (15u128).into() ); - assert_eq!(brillig_sum_memory(vec![Value::from(1u128); 1024]), Value::from(1024u128)); + assert_eq!(brillig_sum_memory(vec![(1u128).into(); 1024]), (1024u128).into()); } #[test] @@ -1066,8 +1147,8 @@ mod tests { /// recursive_write(memory, i + 1, len); /// } /// Note we represent a 100% in-stack optimized form in brillig - fn brillig_recursive_write_memory(size: usize) -> Vec { - let bit_size = 32; + fn brillig_recursive_write_memory(size: usize) -> Vec { + let bit_size = 64; let r_i = MemoryAddress::from(0); let r_len = MemoryAddress::from(1); let r_tmp = MemoryAddress::from(2); @@ -1075,15 +1156,15 @@ mod tests { let start = [ // i = 0 - Opcode::Const { destination: r_i, value: 0u128.into(), bit_size: 32 }, + Opcode::Const { destination: r_i, value: 0u128.into(), bit_size }, // len = size - Opcode::Const { destination: r_len, value: size.into(), bit_size: 32 }, + Opcode::Const { destination: r_len, value: size.into(), bit_size }, // pointer = free_memory_ptr - Opcode::Const { destination: r_pointer, value: 4u128.into(), bit_size: 32 }, + Opcode::Const { destination: r_pointer, value: 4u128.into(), bit_size }, // call recursive_fn Opcode::Call { - location: 5, // Call after 'start' - }, + location: 5, // Call after 'start' + }, // end program by jumping to end Opcode::Jump { location: 100 }, ]; @@ -1105,7 +1186,7 @@ mod tests { // *i = i Opcode::Store { destination_pointer: r_pointer, source: r_i }, // tmp = 1 - Opcode::Const { destination: r_tmp, value: 1u128.into(), bit_size: 32 }, + Opcode::Const { destination: r_tmp, value: 1u128.into(), bit_size }, // i = i + 1 (tmp) Opcode::BinaryIntOp { destination: r_i, @@ -1133,32 +1214,27 @@ mod tests { } let memory = brillig_recursive_write_memory(5); - let expected = vec![ - Value::from(0u128), - Value::from(1u128), - Value::from(2u128), - Value::from(3u128), - Value::from(4u128), - ]; + let expected = + vec![(0u64).into(), (1u64).into(), (2u64).into(), (3u64).into(), (4u64).into()]; assert_eq!(memory, expected); let memory = brillig_recursive_write_memory(1024); - let expected: Vec = (0..1024).map(|i| Value::from(i as u128)).collect(); + let expected: Vec<_> = (0..1024).map(|i: u64| i.into()).collect(); assert_eq!(memory, expected); } /// Helper to execute brillig code fn brillig_execute_and_get_vm( - calldata: Vec, + calldata: Vec, opcodes: &[Opcode], - ) -> VM<'_, DummyBlackBoxSolver> { - let mut vm = VM::new(calldata, opcodes, vec![], &DummyBlackBoxSolver); + ) -> VM<'_, StubbedBlackBoxSolver> { + let mut vm = VM::new(calldata, opcodes, vec![], &StubbedBlackBoxSolver); brillig_execute(&mut vm); assert_eq!(vm.call_stack, vec![]); vm } - fn brillig_execute(vm: &mut VM) { + fn brillig_execute(vm: &mut VM) { loop { let status = vm.process_opcode(); if matches!(status, VMStatus::Finished { .. } | VMStatus::ForeignCallWait { .. }) { @@ -1175,14 +1251,14 @@ mod tests { let double_program = vec![ // Load input address with value 5 - Opcode::Const { destination: r_input, value: Value::from(5u128), bit_size: 32 }, + Opcode::Const { destination: r_input, value: (5u128).into(), bit_size: 32 }, // Call foreign function "double" with the input address Opcode::ForeignCall { function: "double".into(), destinations: vec![ValueOrArray::MemoryAddress(r_result)], - destination_value_types: vec![HeapValueType::Simple], + destination_value_types: vec![HeapValueType::Simple(32)], inputs: vec![ValueOrArray::MemoryAddress(r_input)], - input_value_types: vec![HeapValueType::Simple], + input_value_types: vec![HeapValueType::Simple(32)], }, ]; @@ -1193,13 +1269,13 @@ mod tests { vm.status, VMStatus::ForeignCallWait { function: "double".into(), - inputs: vec![Value::from(5u128).into()] + inputs: vec![FieldElement::from(5usize).into()] } ); // Push result we're waiting for vm.resolve_foreign_call( - Value::from(10u128).into(), // Result of doubling 5u128 + FieldElement::from(10u128).into(), // Result of doubling 5u128 ); // Resume VM @@ -1210,7 +1286,7 @@ mod tests { // Check result address let result_value = vm.memory.read(r_result); - assert_eq!(result_value, Value::from(10u128)); + assert_eq!(result_value, (10u32).into()); // Ensure the foreign call counter has been incremented assert_eq!(vm.foreign_call_counter, 1); @@ -1222,12 +1298,11 @@ mod tests { let r_output = MemoryAddress::from(1); // Define a simple 2x2 matrix in memory - let initial_matrix = - vec![Value::from(1u128), Value::from(2u128), Value::from(3u128), Value::from(4u128)]; + let initial_matrix = vec![(1u128).into(), (2u128).into(), (3u128).into(), (4u128).into()]; // Transpose of the matrix (but arbitrary for this test, the 'correct value') - let expected_result = - vec![Value::from(1u128), Value::from(3u128), Value::from(2u128), Value::from(4u128)]; + let expected_result: Vec = + vec![(1u128).into(), (3u128).into(), (2u128).into(), (4u128).into()]; let invert_program = vec![ Opcode::CalldataCopy { @@ -1236,9 +1311,9 @@ mod tests { offset: 0, }, // input = 0 - Opcode::Const { destination: r_input, value: 2_usize.into(), bit_size: 32 }, + Opcode::Const { destination: r_input, value: 2_usize.into(), bit_size: 64 }, // output = 0 - Opcode::Const { destination: r_output, value: 2_usize.into(), bit_size: 32 }, + Opcode::Const { destination: r_output, value: 2_usize.into(), bit_size: 64 }, // *output = matrix_2x2_transpose(*input) Opcode::ForeignCall { function: "matrix_2x2_transpose".into(), @@ -1248,14 +1323,14 @@ mod tests { })], destination_value_types: vec![HeapValueType::Array { size: initial_matrix.len(), - value_types: vec![HeapValueType::Simple], + value_types: vec![HeapValueType::field()], }], inputs: vec![ValueOrArray::HeapArray(HeapArray { pointer: r_input, size: initial_matrix.len(), })], input_value_types: vec![HeapValueType::Array { - value_types: vec![HeapValueType::Simple], + value_types: vec![HeapValueType::field()], size: initial_matrix.len(), }], }, @@ -1283,7 +1358,10 @@ mod tests { // Check result in memory let result_values = vm.memory.read_slice(MemoryAddress(2), 4).to_vec(); - assert_eq!(result_values, expected_result); + assert_eq!( + result_values.into_iter().map(|mem_value| mem_value.value).collect::>(), + expected_result + ); // Ensure the foreign call counter has been incremented assert_eq!(vm.foreign_call_counter, 1); @@ -1299,10 +1377,10 @@ mod tests { let r_output_size = MemoryAddress::from(3); // Our first string to use the identity function with - let input_string = - vec![Value::from(1u128), Value::from(2u128), Value::from(3u128), Value::from(4u128)]; + let input_string: Vec = + vec![(1u128).into(), (2u128).into(), (3u128).into(), (4u128).into()]; // Double the string (concatenate it with itself) - let mut output_string: Vec = + let mut output_string: Vec<_> = input_string.iter().cloned().chain(input_string.clone()).collect(); // Reverse the concatenated string output_string.reverse(); @@ -1315,24 +1393,24 @@ mod tests { offset: 0, }, // input_pointer = 4 - Opcode::Const { destination: r_input_pointer, value: Value::from(4u128), bit_size: 32 }, + Opcode::Const { destination: r_input_pointer, value: (4u128).into(), bit_size: 64 }, // input_size = input_string.len() (constant here) Opcode::Const { destination: r_input_size, - value: Value::from(input_string.len()), - bit_size: 32, + value: input_string.len().into(), + bit_size: 64, }, // output_pointer = 4 + input_size Opcode::Const { destination: r_output_pointer, - value: Value::from(4 + input_string.len()), - bit_size: 32, + value: (4 + input_string.len()).into(), + bit_size: 64, }, // output_size = input_size * 2 Opcode::Const { destination: r_output_size, - value: Value::from(input_string.len() * 2), - bit_size: 32, + value: (input_string.len() * 2).into(), + bit_size: 64, }, // output_pointer[0..output_size] = string_double(input_pointer[0...input_size]) Opcode::ForeignCall { @@ -1342,14 +1420,14 @@ mod tests { size: r_output_size, })], destination_value_types: vec![HeapValueType::Vector { - value_types: vec![HeapValueType::Simple], + value_types: vec![HeapValueType::field()], }], inputs: vec![ValueOrArray::HeapVector(HeapVector { pointer: r_input_pointer, size: r_input_size, })], input_value_types: vec![HeapValueType::Vector { - value_types: vec![HeapValueType::Simple], + value_types: vec![HeapValueType::field()], }], }, ]; @@ -1377,10 +1455,12 @@ mod tests { assert_eq!(vm.status, VMStatus::Finished { return_data_offset: 0, return_data_size: 0 }); // Check result in memory - let result_values = vm + let result_values: Vec<_> = vm .memory .read_slice(MemoryAddress(4 + input_string.len()), output_string.len()) - .to_vec(); + .iter() + .map(|mem_val| mem_val.value) + .collect(); assert_eq!(result_values, output_string); // Ensure the foreign call counter has been incremented @@ -1393,12 +1473,11 @@ mod tests { let r_output = MemoryAddress::from(1); // Define a simple 2x2 matrix in memory - let initial_matrix = - vec![Value::from(1u128), Value::from(2u128), Value::from(3u128), Value::from(4u128)]; + let initial_matrix = vec![(1u128).into(), (2u128).into(), (3u128).into(), (4u128).into()]; // Transpose of the matrix (but arbitrary for this test, the 'correct value') - let expected_result = - vec![Value::from(1u128), Value::from(3u128), Value::from(2u128), Value::from(4u128)]; + let expected_result: Vec = + vec![(1u128).into(), (3u128).into(), (2u128).into(), (4u128).into()]; let invert_program = vec![ Opcode::CalldataCopy { @@ -1407,9 +1486,9 @@ mod tests { offset: 0, }, // input = 0 - Opcode::Const { destination: r_input, value: Value::from(2u128), bit_size: 32 }, + Opcode::Const { destination: r_input, value: (2u128).into(), bit_size: 64 }, // output = 0 - Opcode::Const { destination: r_output, value: Value::from(6u128), bit_size: 32 }, + Opcode::Const { destination: r_output, value: (6u128).into(), bit_size: 64 }, // *output = matrix_2x2_transpose(*input) Opcode::ForeignCall { function: "matrix_2x2_transpose".into(), @@ -1419,7 +1498,7 @@ mod tests { })], destination_value_types: vec![HeapValueType::Array { size: initial_matrix.len(), - value_types: vec![HeapValueType::Simple], + value_types: vec![HeapValueType::field()], }], inputs: vec![ValueOrArray::HeapArray(HeapArray { pointer: r_input, @@ -1427,7 +1506,7 @@ mod tests { })], input_value_types: vec![HeapValueType::Array { size: initial_matrix.len(), - value_types: vec![HeapValueType::Simple], + value_types: vec![HeapValueType::field()], }], }, ]; @@ -1453,11 +1532,13 @@ mod tests { assert_eq!(vm.status, VMStatus::Finished { return_data_offset: 0, return_data_size: 0 }); // Check initial memory still in place - let initial_values = vm.memory.read_slice(MemoryAddress(2), 4).to_vec(); + let initial_values: Vec<_> = + vm.memory.read_slice(MemoryAddress(2), 4).iter().map(|mem_val| mem_val.value).collect(); assert_eq!(initial_values, initial_matrix); // Check result in memory - let result_values = vm.memory.read_slice(MemoryAddress(6), 4).to_vec(); + let result_values: Vec<_> = + vm.memory.read_slice(MemoryAddress(6), 4).iter().map(|mem_val| mem_val.value).collect(); assert_eq!(result_values, expected_result); // Ensure the foreign call counter has been incremented @@ -1471,23 +1552,13 @@ mod tests { let r_output = MemoryAddress::from(2); // Define a simple 2x2 matrix in memory - let matrix_a = - vec![Value::from(1u128), Value::from(2u128), Value::from(3u128), Value::from(4u128)]; - - let matrix_b = vec![ - Value::from(10u128), - Value::from(11u128), - Value::from(12u128), - Value::from(13u128), - ]; + let matrix_a = vec![(1u128).into(), (2u128).into(), (3u128).into(), (4u128).into()]; + + let matrix_b = vec![(10u128).into(), (11u128).into(), (12u128).into(), (13u128).into()]; // Transpose of the matrix (but arbitrary for this test, the 'correct value') - let expected_result = vec![ - Value::from(34u128), - Value::from(37u128), - Value::from(78u128), - Value::from(85u128), - ]; + let expected_result: Vec = + vec![(34u128).into(), (37u128).into(), (78u128).into(), (85u128).into()]; let matrix_mul_program = vec![ Opcode::CalldataCopy { @@ -1496,11 +1567,11 @@ mod tests { offset: 0, }, // input = 3 - Opcode::Const { destination: r_input_a, value: Value::from(3u128), bit_size: 32 }, + Opcode::Const { destination: r_input_a, value: (3u128).into(), bit_size: 64 }, // input = 7 - Opcode::Const { destination: r_input_b, value: Value::from(7u128), bit_size: 32 }, + Opcode::Const { destination: r_input_b, value: (7u128).into(), bit_size: 64 }, // output = 0 - Opcode::Const { destination: r_output, value: Value::from(0u128), bit_size: 32 }, + Opcode::Const { destination: r_output, value: (0u128).into(), bit_size: 64 }, // *output = matrix_2x2_transpose(*input) Opcode::ForeignCall { function: "matrix_2x2_transpose".into(), @@ -1510,7 +1581,7 @@ mod tests { })], destination_value_types: vec![HeapValueType::Array { size: matrix_a.len(), - value_types: vec![HeapValueType::Simple], + value_types: vec![HeapValueType::field()], }], inputs: vec![ ValueOrArray::HeapArray(HeapArray { pointer: r_input_a, size: matrix_a.len() }), @@ -1519,11 +1590,11 @@ mod tests { input_value_types: vec![ HeapValueType::Array { size: matrix_a.len(), - value_types: vec![HeapValueType::Simple], + value_types: vec![HeapValueType::field()], }, HeapValueType::Array { size: matrix_b.len(), - value_types: vec![HeapValueType::Simple], + value_types: vec![HeapValueType::field()], }, ], }, @@ -1551,7 +1622,8 @@ mod tests { assert_eq!(vm.status, VMStatus::Finished { return_data_offset: 0, return_data_size: 0 }); // Check result in memory - let result_values = vm.memory.read_slice(MemoryAddress(0), 4).to_vec(); + let result_values: Vec<_> = + vm.memory.read_slice(MemoryAddress(0), 4).iter().map(|mem_val| mem_val.value).collect(); assert_eq!(result_values, expected_result); // Ensure the foreign call counter has been incremented @@ -1562,47 +1634,54 @@ mod tests { fn foreign_call_opcode_nested_arrays_and_slices_input() { // [(1, <2,3>, [4]), (5, <6,7,8>, [9])] - let v2 = vec![Value::from(2u128), Value::from(3u128)]; - let a4 = vec![Value::from(4u128)]; - let v6 = vec![Value::from(6u128), Value::from(7u128), Value::from(8u128)]; - let a9 = vec![Value::from(9u128)]; + let v2: Vec = vec![ + MemoryValue::from(FieldElement::from(2u128)), + MemoryValue::from(FieldElement::from(3u128)), + ]; + let a4: Vec = vec![FieldElement::from(4u128).into()]; + let v6: Vec = vec![ + MemoryValue::from(FieldElement::from(6u128)), + MemoryValue::from(FieldElement::from(7u128)), + MemoryValue::from(FieldElement::from(8u128)), + ]; + let a9: Vec = vec![FieldElement::from(9u128).into()]; // construct memory by declaring all inner arrays/vectors first - let v2_ptr = 0u128; + let v2_ptr: usize = 0usize; let mut memory = v2.clone(); let v2_start = memory.len(); - memory.extend(vec![Value::from(v2_ptr), Value::from(v2.len()), Value::from(1u128)]); + memory.extend(vec![MemoryValue::from(v2_ptr), v2.len().into(), MemoryValue::from(1_usize)]); let a4_ptr = memory.len(); memory.extend(a4.clone()); let a4_start = memory.len(); - memory.extend(vec![Value::from(a4_ptr), Value::from(1u128)]); + memory.extend(vec![MemoryValue::from(a4_ptr), MemoryValue::from(1_usize)]); let v6_ptr = memory.len(); memory.extend(v6.clone()); let v6_start = memory.len(); - memory.extend(vec![Value::from(v6_ptr), Value::from(v6.len()), Value::from(1u128)]); + memory.extend(vec![MemoryValue::from(v6_ptr), v6.len().into(), MemoryValue::from(1_usize)]); let a9_ptr = memory.len(); memory.extend(a9.clone()); let a9_start = memory.len(); - memory.extend(vec![Value::from(a9_ptr), Value::from(1u128)]); + memory.extend(vec![MemoryValue::from(a9_ptr), MemoryValue::from(1_usize)]); // finally we add the contents of the outer array let outer_ptr = memory.len(); let outer_array = vec![ - Value::from(1u128), - Value::from(v2.len()), - Value::from(v2_start), - Value::from(a4_start), - Value::from(5u128), - Value::from(v6.len()), - Value::from(v6_start), - Value::from(a9_start), + MemoryValue::from(FieldElement::from(1u128)), + MemoryValue::from(v2.len()), + MemoryValue::from(v2_start), + MemoryValue::from(a4_start), + MemoryValue::from(FieldElement::from(5u128)), + MemoryValue::from(v6.len()), + MemoryValue::from(v6_start), + MemoryValue::from(a9_start), ]; memory.extend(outer_array.clone()); - let input_array_value_types = vec![ - HeapValueType::Simple, - HeapValueType::Simple, // size of following vector - HeapValueType::Vector { value_types: vec![HeapValueType::Simple] }, - HeapValueType::Array { value_types: vec![HeapValueType::Simple], size: 1 }, + let input_array_value_types: Vec = vec![ + HeapValueType::field(), + HeapValueType::Simple(64), // size of following vector + HeapValueType::Vector { value_types: vec![HeapValueType::field()] }, + HeapValueType::Array { value_types: vec![HeapValueType::field()], size: 1 }, ]; // memory address of the end of the above data structures @@ -1611,19 +1690,24 @@ mod tests { let r_input = MemoryAddress::from(r_ptr); let r_output = MemoryAddress::from(r_ptr + 1); - let program = vec![ - Opcode::CalldataCopy { - destination_address: MemoryAddress::from(0), - size: memory.len(), - offset: 0, - }, + let program: Vec<_> = std::iter::once(Opcode::CalldataCopy { + destination_address: MemoryAddress::from(0), + size: memory.len(), + offset: 0, + }) + .chain(memory.iter().enumerate().map(|(index, mem_value)| Opcode::Cast { + destination: MemoryAddress(index), + source: MemoryAddress(index), + bit_size: mem_value.bit_size, + })) + .chain(vec![ // input = 0 - Opcode::Const { destination: r_input, value: Value::from(outer_ptr), bit_size: 32 }, + Opcode::Const { destination: r_input, value: (outer_ptr).into(), bit_size: 64 }, // some_function(input) Opcode::ForeignCall { function: "flat_sum".into(), destinations: vec![ValueOrArray::MemoryAddress(r_output)], - destination_value_types: vec![HeapValueType::Simple], + destination_value_types: vec![HeapValueType::field()], inputs: vec![ValueOrArray::HeapArray(HeapArray { pointer: r_input, size: outer_array.len(), @@ -1633,9 +1717,13 @@ mod tests { size: outer_array.len(), }], }, - ]; + ]) + .collect(); - let mut vm = brillig_execute_and_get_vm(memory, &program); + let mut vm = brillig_execute_and_get_vm( + memory.into_iter().map(|mem_value| mem_value.value).collect(), + &program, + ); // Check that VM is waiting assert_eq!( @@ -1643,23 +1731,23 @@ mod tests { VMStatus::ForeignCallWait { function: "flat_sum".into(), inputs: vec![ForeignCallParam::Array(vec![ - Value::from(1u128), - Value::from(2u128), // size of following vector - Value::from(2u128), - Value::from(3u128), - Value::from(4u128), - Value::from(5u128), - Value::from(3u128), // size of following vector - Value::from(6u128), - Value::from(7u128), - Value::from(8u128), - Value::from(9u128), + (1u128).into(), + (2u128).into(), // size of following vector + (2u128).into(), + (3u128).into(), + (4u128).into(), + (5u128).into(), + (3u128).into(), // size of following vector + (6u128).into(), + (7u128).into(), + (8u128).into(), + (9u128).into(), ])], } ); // Push result we're waiting for - vm.resolve_foreign_call(Value::from(45u128).into()); + vm.resolve_foreign_call(FieldElement::from(45u128).into()); // Resume VM brillig_execute(&mut vm); @@ -1669,7 +1757,7 @@ mod tests { // Check result let result_value = vm.memory.read(r_output); - assert_eq!(result_value, Value::from(45u128)); + assert_eq!(result_value, MemoryValue::from(FieldElement::from(45u128))); // Ensure the foreign call counter has been incremented assert_eq!(vm.foreign_call_counter, 1); diff --git a/acvm-repo/brillig_vm/src/memory.rs b/acvm-repo/brillig_vm/src/memory.rs index d1c81447170..d563e13be2e 100644 --- a/acvm-repo/brillig_vm/src/memory.rs +++ b/acvm-repo/brillig_vm/src/memory.rs @@ -1,30 +1,182 @@ use acir::{brillig::MemoryAddress, FieldElement}; -use crate::Value; +pub const MEMORY_ADDRESSING_BIT_SIZE: u32 = 64; + +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub struct MemoryValue { + pub value: FieldElement, + pub bit_size: u32, +} + +#[derive(Debug, thiserror::Error)] +pub enum MemoryTypeError { + #[error("Bit size for value {value_bit_size} does not match the expected bit size {expected_bit_size}")] + MismatchedBitSize { value_bit_size: u32, expected_bit_size: u32 }, +} + +impl MemoryValue { + pub fn new(value: FieldElement, bit_size: u32) -> Self { + MemoryValue { value, bit_size } + } + + pub fn new_checked(value: FieldElement, bit_size: u32) -> Option { + if value.num_bits() > bit_size { + return None; + } + + Some(MemoryValue::new(value, bit_size)) + } + + pub fn new_field(value: FieldElement) -> Self { + MemoryValue { value, bit_size: FieldElement::max_num_bits() } + } + + pub fn to_usize(&self) -> usize { + assert!(self.bit_size == MEMORY_ADDRESSING_BIT_SIZE, "value is not typed as brillig usize"); + self.value.to_u128() as usize + } + + pub fn expect_bit_size(&self, expected_bit_size: u32) -> Result<(), MemoryTypeError> { + if self.bit_size != expected_bit_size { + return Err(MemoryTypeError::MismatchedBitSize { + value_bit_size: self.bit_size, + expected_bit_size, + }); + } + Ok(()) + } +} + +impl std::fmt::Display for MemoryValue { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> { + let typ = match self.bit_size { + 0 => "null".to_string(), + 1 => "bool".to_string(), + _ if self.bit_size == FieldElement::max_num_bits() => "field".to_string(), + _ => format!("u{}", self.bit_size), + }; + f.write_str(format!("{}: {}", self.value, typ).as_str()) + } +} + +impl Default for MemoryValue { + fn default() -> Self { + MemoryValue::new(FieldElement::zero(), 0) + } +} + +impl From for MemoryValue { + fn from(field: FieldElement) -> Self { + MemoryValue::new_field(field) + } +} + +impl From for MemoryValue { + fn from(value: usize) -> Self { + MemoryValue::new(value.into(), MEMORY_ADDRESSING_BIT_SIZE) + } +} + +impl From for MemoryValue { + fn from(value: u64) -> Self { + MemoryValue::new((value as u128).into(), 64) + } +} + +impl From for MemoryValue { + fn from(value: u32) -> Self { + MemoryValue::new((value as u128).into(), 32) + } +} + +impl From for MemoryValue { + fn from(value: u8) -> Self { + MemoryValue::new((value as u128).into(), 8) + } +} + +impl From for MemoryValue { + fn from(value: bool) -> Self { + MemoryValue::new(value.into(), 1) + } +} + +impl TryFrom for FieldElement { + type Error = MemoryTypeError; + + fn try_from(memory_value: MemoryValue) -> Result { + memory_value.expect_bit_size(FieldElement::max_num_bits())?; + Ok(memory_value.value) + } +} + +impl TryFrom for u64 { + type Error = MemoryTypeError; + + fn try_from(memory_value: MemoryValue) -> Result { + memory_value.expect_bit_size(64)?; + Ok(memory_value.value.to_u128() as u64) + } +} + +impl TryFrom for u32 { + type Error = MemoryTypeError; + + fn try_from(memory_value: MemoryValue) -> Result { + memory_value.expect_bit_size(32)?; + Ok(memory_value.value.to_u128() as u32) + } +} + +impl TryFrom for u8 { + type Error = MemoryTypeError; + + fn try_from(memory_value: MemoryValue) -> Result { + memory_value.expect_bit_size(8)?; + + Ok(memory_value.value.to_u128() as u8) + } +} + +impl TryFrom for bool { + type Error = MemoryTypeError; + + fn try_from(memory_value: MemoryValue) -> Result { + memory_value.expect_bit_size(1)?; + + if memory_value.value == FieldElement::zero() { + Ok(false) + } else if memory_value.value == FieldElement::one() { + Ok(true) + } else { + unreachable!("value typed as bool is greater than one") + } + } +} #[derive(Debug, Clone, Default, PartialEq, Eq)] pub struct Memory { // Memory is a vector of values. // We grow the memory when values past the end are set, extending with 0s. - inner: Vec, + inner: Vec, } impl Memory { /// Gets the value at pointer - pub fn read(&self, ptr: MemoryAddress) -> Value { - self.inner.get(ptr.to_usize()).copied().unwrap_or(0_u128.into()) + pub fn read(&self, ptr: MemoryAddress) -> MemoryValue { + self.inner.get(ptr.to_usize()).copied().unwrap_or_default() } pub fn read_ref(&self, ptr: MemoryAddress) -> MemoryAddress { MemoryAddress(self.read(ptr).to_usize()) } - pub fn read_slice(&self, addr: MemoryAddress, len: usize) -> &[Value] { + pub fn read_slice(&self, addr: MemoryAddress, len: usize) -> &[MemoryValue] { &self.inner[addr.to_usize()..(addr.to_usize() + len)] } /// Sets the value at pointer `ptr` to `value` - pub fn write(&mut self, ptr: MemoryAddress, value: Value) { + pub fn write(&mut self, ptr: MemoryAddress, value: MemoryValue) { self.resize_to_fit(ptr.to_usize() + 1); self.inner[ptr.to_usize()] = value; } @@ -33,17 +185,17 @@ impl Memory { // Calculate new memory size let new_size = std::cmp::max(self.inner.len(), size); // Expand memory to new size with default values if needed - self.inner.resize(new_size, Value::from(FieldElement::zero())); + self.inner.resize(new_size, MemoryValue::default()); } /// Sets the values after pointer `ptr` to `values` - pub fn write_slice(&mut self, ptr: MemoryAddress, values: &[Value]) { + pub fn write_slice(&mut self, ptr: MemoryAddress, values: &[MemoryValue]) { self.resize_to_fit(ptr.to_usize() + values.len()); self.inner[ptr.to_usize()..(ptr.to_usize() + values.len())].copy_from_slice(values); } /// Returns the values of the memory - pub fn values(&self) -> &[Value] { + pub fn values(&self) -> &[MemoryValue] { &self.inner } } diff --git a/aztec_macros/Cargo.toml b/aztec_macros/Cargo.toml index ed9821fabcf..355036d28a7 100644 --- a/aztec_macros/Cargo.toml +++ b/aztec_macros/Cargo.toml @@ -14,3 +14,5 @@ noirc_frontend.workspace = true noirc_errors.workspace = true iter-extended.workspace = true convert_case = "0.6.0" +regex = "1.10" + diff --git a/aztec_macros/src/lib.rs b/aztec_macros/src/lib.rs index 0ccc421d3bc..3ee6f9c21b9 100644 --- a/aztec_macros/src/lib.rs +++ b/aztec_macros/src/lib.rs @@ -1,27 +1,31 @@ -use std::borrow::{Borrow, BorrowMut}; -use std::vec; +mod transforms; +mod utils; + +use transforms::{ + compute_note_hash_and_nullifier::inject_compute_note_hash_and_nullifier, + events::{generate_selector_impl, transform_events}, + functions::{transform_function, transform_unconstrained}, + note_interface::generate_note_interface_impl, + storage::{ + assign_storage_slots, check_for_storage_definition, check_for_storage_implementation, + generate_storage_implementation, + }, +}; + +use noirc_frontend::{ + hir::def_collector::dc_crate::{UnresolvedFunctions, UnresolvedTraitImpl}, + macros_api::{ + CrateId, FileId, HirContext, MacroError, MacroProcessor, SecondaryAttribute, SortedModule, + Span, + }, +}; -use convert_case::{Case, Casing}; -use iter_extended::vecmap; -use noirc_errors::Location; -use noirc_frontend::hir::def_collector::dc_crate::{UnresolvedFunctions, UnresolvedTraitImpl}; -use noirc_frontend::hir::def_map::{LocalModuleId, ModuleId}; -use noirc_frontend::macros_api::parse_program; -use noirc_frontend::macros_api::FieldElement; -use noirc_frontend::macros_api::{ - BlockExpression, CallExpression, CastExpression, Distinctness, Expression, ExpressionKind, - ForLoopStatement, ForRange, FunctionDefinition, FunctionReturnType, FunctionVisibility, - HirContext, HirExpression, HirLiteral, HirStatement, Ident, ImportStatement, IndexExpression, - LetStatement, Literal, MemberAccessExpression, MethodCallExpression, NoirFunction, NoirStruct, - Param, Path, PathKind, Pattern, PrefixExpression, SecondaryAttribute, Signedness, Span, - Statement, StatementKind, StructType, Type, TypeImpl, UnaryOp, UnresolvedType, - UnresolvedTypeData, Visibility, +use utils::{ + ast_utils::is_custom_attribute, + checks::{check_for_aztec_dependency, has_aztec_dependency}, + constants::MAX_CONTRACT_PRIVATE_FUNCTIONS, + errors::AztecMacroError, }; -use noirc_frontend::macros_api::{CrateId, FileId}; -use noirc_frontend::macros_api::{MacroError, MacroProcessor}; -use noirc_frontend::macros_api::{ModuleDefId, NodeInterner, SortedModule, StructId}; -use noirc_frontend::node_interner::{FuncId, TraitId, TraitImplId, TraitImplKind}; -use noirc_frontend::Lambda; pub struct AztecMacro; impl MacroProcessor for AztecMacro { @@ -29,28 +33,20 @@ impl MacroProcessor for AztecMacro { &self, ast: SortedModule, crate_id: &CrateId, + file_id: FileId, context: &HirContext, ) -> Result { - transform(ast, crate_id, context) + transform(ast, crate_id, file_id, context) } - fn process_unresolved_traits_impls( + fn process_collected_defs( &self, crate_id: &CrateId, context: &mut HirContext, - unresolved_traits_impls: &[UnresolvedTraitImpl], - collected_functions: &mut Vec, + collected_trait_impls: &[UnresolvedTraitImpl], + collected_functions: &mut [UnresolvedFunctions], ) -> Result<(), (MacroError, FileId)> { - if has_aztec_dependency(crate_id, context) { - inject_compute_note_hash_and_nullifier( - crate_id, - context, - unresolved_traits_impls, - collected_functions, - ) - } else { - Ok(()) - } + transform_collected_defs(crate_id, context, collected_trait_impls, collected_functions) } fn process_typed_ast( @@ -62,215 +58,6 @@ impl MacroProcessor for AztecMacro { } } -const FUNCTION_TREE_HEIGHT: u32 = 5; -const MAX_CONTRACT_FUNCTIONS: usize = 2_usize.pow(FUNCTION_TREE_HEIGHT); - -#[derive(Debug, Clone)] -pub enum AztecMacroError { - AztecDepNotFound, - ContractHasTooManyFunctions { span: Span }, - ContractConstructorMissing { span: Span }, - UnsupportedFunctionArgumentType { span: Span, typ: UnresolvedTypeData }, - UnsupportedStorageType { span: Option, typ: UnresolvedTypeData }, - CouldNotAssignStorageSlots { secondary_message: Option }, - EventError { span: Span, message: String }, -} - -impl From for MacroError { - fn from(err: AztecMacroError) -> Self { - match err { - AztecMacroError::AztecDepNotFound {} => MacroError { - primary_message: "Aztec dependency not found. Please add aztec as a dependency in your Cargo.toml. For more information go to https://docs.aztec.network/developers/debugging/aztecnr-errors#aztec-dependency-not-found-please-add-aztec-as-a-dependency-in-your-nargotoml".to_owned(), - secondary_message: None, - span: None, - }, - AztecMacroError::ContractHasTooManyFunctions { span } => MacroError { - primary_message: format!("Contract can only have a maximum of {} functions", MAX_CONTRACT_FUNCTIONS), - secondary_message: None, - span: Some(span), - }, - AztecMacroError::ContractConstructorMissing { span } => MacroError { - primary_message: "Contract must have a constructor function".to_owned(), - secondary_message: None, - span: Some(span), - }, - AztecMacroError::UnsupportedFunctionArgumentType { span, typ } => MacroError { - primary_message: format!("Provided parameter type `{typ:?}` is not supported in Aztec contract interface"), - secondary_message: None, - span: Some(span), - }, - AztecMacroError::UnsupportedStorageType { span, typ } => MacroError { - primary_message: format!("Provided storage type `{typ:?}` is not directly supported in Aztec. Please provide a custom storage implementation"), - secondary_message: None, - span, - }, - AztecMacroError::CouldNotAssignStorageSlots { secondary_message } => MacroError { - primary_message: "Could not assign storage slots, please provide a custom storage implementation".to_string(), - secondary_message, - span: None, - }, - AztecMacroError::EventError { span, message } => MacroError { - primary_message: message, - secondary_message: None, - span: Some(span), - }, - } - } -} - -// -// Helper macros for creating noir ast nodes -// -fn ident(name: &str) -> Ident { - Ident::new(name.to_string(), Span::default()) -} - -fn ident_path(name: &str) -> Path { - Path::from_ident(ident(name)) -} - -fn path(ident: Ident) -> Path { - Path::from_ident(ident) -} - -fn expression(kind: ExpressionKind) -> Expression { - Expression::new(kind, Span::default()) -} - -fn variable(name: &str) -> Expression { - expression(ExpressionKind::Variable(ident_path(name))) -} - -fn variable_ident(identifier: Ident) -> Expression { - expression(ExpressionKind::Variable(path(identifier))) -} - -fn variable_path(path: Path) -> Expression { - expression(ExpressionKind::Variable(path)) -} - -fn method_call(object: Expression, method_name: &str, arguments: Vec) -> Expression { - expression(ExpressionKind::MethodCall(Box::new(MethodCallExpression { - object, - method_name: ident(method_name), - arguments, - }))) -} - -fn call(func: Expression, arguments: Vec) -> Expression { - expression(ExpressionKind::Call(Box::new(CallExpression { func: Box::new(func), arguments }))) -} - -fn pattern(name: &str) -> Pattern { - Pattern::Identifier(ident(name)) -} - -fn mutable(name: &str) -> Pattern { - Pattern::Mutable(Box::new(pattern(name)), Span::default(), true) -} - -fn mutable_assignment(name: &str, assigned_to: Expression) -> Statement { - make_statement(StatementKind::Let(LetStatement { - pattern: mutable(name), - r#type: make_type(UnresolvedTypeData::Unspecified), - expression: assigned_to, - })) -} - -fn mutable_reference(variable_name: &str) -> Expression { - expression(ExpressionKind::Prefix(Box::new(PrefixExpression { - operator: UnaryOp::MutableReference, - rhs: variable(variable_name), - }))) -} - -fn assignment(name: &str, assigned_to: Expression) -> Statement { - make_statement(StatementKind::Let(LetStatement { - pattern: pattern(name), - r#type: make_type(UnresolvedTypeData::Unspecified), - expression: assigned_to, - })) -} - -fn member_access(lhs: &str, rhs: &str) -> Expression { - expression(ExpressionKind::MemberAccess(Box::new(MemberAccessExpression { - lhs: variable(lhs), - rhs: ident(rhs), - }))) -} - -fn return_type(path: Path) -> FunctionReturnType { - let ty = make_type(UnresolvedTypeData::Named(path, vec![], true)); - FunctionReturnType::Ty(ty) -} - -fn lambda(parameters: Vec<(Pattern, UnresolvedType)>, body: Expression) -> Expression { - expression(ExpressionKind::Lambda(Box::new(Lambda { - parameters, - return_type: UnresolvedType { - typ: UnresolvedTypeData::Unspecified, - span: Some(Span::default()), - }, - body, - }))) -} - -macro_rules! chained_path { - ( $base:expr ) => { - { - ident_path($base) - } - }; - ( $base:expr $(, $tail:expr)* ) => { - { - let mut base_path = ident_path($base); - $( - base_path.segments.push(ident($tail)); - )* - base_path - } - } -} - -macro_rules! chained_dep { - ( $base:expr $(, $tail:expr)* ) => { - { - let mut base_path = ident_path($base); - base_path.kind = PathKind::Dep; - $( - base_path.segments.push(ident($tail)); - )* - base_path - } - } -} - -fn cast(lhs: Expression, ty: UnresolvedTypeData) -> Expression { - expression(ExpressionKind::Cast(Box::new(CastExpression { lhs, r#type: make_type(ty) }))) -} - -fn make_type(typ: UnresolvedTypeData) -> UnresolvedType { - UnresolvedType { typ, span: Some(Span::default()) } -} - -fn index_array(array: Ident, index: &str) -> Expression { - expression(ExpressionKind::Index(Box::new(IndexExpression { - collection: variable_path(path(array)), - index: variable(index), - }))) -} - -fn index_array_variable(array: Expression, index: &str) -> Expression { - expression(ExpressionKind::Index(Box::new(IndexExpression { - collection: array, - index: variable(index), - }))) -} - -fn import(path: Path) -> ImportStatement { - ImportStatement { path, alias: None } -} - // // Create AST Nodes for Aztec // @@ -280,146 +67,34 @@ fn import(path: Path) -> ImportStatement { fn transform( mut ast: SortedModule, crate_id: &CrateId, + file_id: FileId, context: &HirContext, ) -> Result { // Usage -> mut ast -> aztec_library::transform(&mut ast) - // Covers all functions in the ast for submodule in ast.submodules.iter_mut().filter(|submodule| submodule.is_contract) { - if transform_module(&mut submodule.contents, crate_id, context) - .map_err(|(err, file_id)| (err.into(), file_id))? - { + if transform_module(&mut submodule.contents).map_err(|err| (err.into(), file_id))? { check_for_aztec_dependency(crate_id, context)?; - include_relevant_imports(&mut submodule.contents); } } - Ok(ast) -} - -// -// Transform Hir Nodes for Aztec -// - -/// Completes the Hir with data gathered from type resolution -fn transform_hir( - crate_id: &CrateId, - context: &mut HirContext, -) -> Result<(), (AztecMacroError, FileId)> { - transform_events(crate_id, context)?; - assign_storage_slots(crate_id, context) -} - -/// Includes an import to the aztec library if it has not been included yet -fn include_relevant_imports(ast: &mut SortedModule) { - // Create the aztec import path using the assumed chained_dep! macro - let aztec_import_path = import(chained_dep!("aztec")); - // Check if the aztec import already exists - let is_aztec_imported = - ast.imports.iter().any(|existing_import| existing_import.path == aztec_import_path.path); + generate_note_interface_impl(&mut ast).map_err(|err| (err.into(), file_id))?; - // If aztec is not imported, add the import at the beginning - if !is_aztec_imported { - ast.imports.insert(0, aztec_import_path); - } -} - -/// Creates an error alerting the user that they have not downloaded the Aztec-noir library -fn check_for_aztec_dependency( - crate_id: &CrateId, - context: &HirContext, -) -> Result<(), (MacroError, FileId)> { - if has_aztec_dependency(crate_id, context) { - Ok(()) - } else { - Err((AztecMacroError::AztecDepNotFound.into(), context.crate_graph[crate_id].root_file_id)) - } -} - -fn has_aztec_dependency(crate_id: &CrateId, context: &HirContext) -> bool { - context.crate_graph[crate_id].dependencies.iter().any(|dep| dep.as_name() == "aztec") -} - -// Check to see if the user has defined a storage struct -fn check_for_storage_definition(module: &SortedModule) -> bool { - module.types.iter().any(|r#struct| r#struct.name.0.contents == "Storage") -} - -// Check to see if the user has defined a storage struct -fn check_for_storage_implementation(module: &SortedModule) -> bool { - module.impls.iter().any(|r#impl| match &r#impl.object_type.typ { - UnresolvedTypeData::Named(path, _, _) => { - path.segments.last().is_some_and(|segment| segment.0.contents == "Storage") - } - _ => false, - }) -} - -// Check if "compute_note_hash_and_nullifier(AztecAddress,Field,Field,Field,[Field; N]) -> [Field; 4]" is defined -fn check_for_compute_note_hash_and_nullifier_definition( - functions_data: &[(LocalModuleId, FuncId, NoirFunction)], - module_id: LocalModuleId, -) -> bool { - functions_data.iter().filter(|func_data| func_data.0 == module_id).any(|func_data| { - func_data.2.def.name.0.contents == "compute_note_hash_and_nullifier" - && func_data.2.def.parameters.len() == 5 - && match &func_data.2.def.parameters[0].typ.typ { - UnresolvedTypeData::Named(path, _, _) => path.segments.last().unwrap().0.contents == "AztecAddress", - _ => false, - } - && func_data.2.def.parameters[1].typ.typ == UnresolvedTypeData::FieldElement - && func_data.2.def.parameters[2].typ.typ == UnresolvedTypeData::FieldElement - && func_data.2.def.parameters[3].typ.typ == UnresolvedTypeData::FieldElement - // checks if the 5th parameter is an array and the Box in - // Array(Option, Box) contains only fields - && match &func_data.2.def.parameters[4].typ.typ { - UnresolvedTypeData::Array(_, inner_type) => { - matches!(inner_type.typ, UnresolvedTypeData::FieldElement) - }, - _ => false, - } - // We check the return type the same way as we did the 5th parameter - && match &func_data.2.def.return_type { - FunctionReturnType::Default(_) => false, - FunctionReturnType::Ty(unresolved_type) => { - match &unresolved_type.typ { - UnresolvedTypeData::Array(_, inner_type) => { - matches!(inner_type.typ, UnresolvedTypeData::FieldElement) - }, - _ => false, - } - } - } - }) -} - -/// Checks if an attribute is a custom attribute with a specific name -fn is_custom_attribute(attr: &SecondaryAttribute, attribute_name: &str) -> bool { - if let SecondaryAttribute::Custom(custom_attr) = attr { - custom_attr.as_str() == attribute_name - } else { - false - } + Ok(ast) } /// Determines if ast nodes are annotated with aztec attributes. /// For annotated functions it calls the `transform` function which will perform the required transformations. /// Returns true if an annotated node is found, false otherwise -fn transform_module( - module: &mut SortedModule, - crate_id: &CrateId, - context: &HirContext, -) -> Result { +fn transform_module(module: &mut SortedModule) -> Result { let mut has_transformed_module = false; // Check for a user defined storage struct let storage_defined = check_for_storage_definition(module); let storage_implemented = check_for_storage_implementation(module); - let crate_graph = &context.crate_graph[crate_id]; - if storage_defined && !storage_implemented { - generate_storage_implementation(module).map_err(|err| (err, crate_graph.root_file_id))?; + generate_storage_implementation(module)?; } for structure in module.types.iter() { @@ -429,25 +104,57 @@ fn transform_module( } } + let has_initializer = module.functions.iter().any(|func| { + func.def + .attributes + .secondary + .iter() + .any(|attr| is_custom_attribute(attr, "aztec(initializer)")) + }); + for func in module.functions.iter_mut() { + let mut is_private = false; + let mut is_public = false; + let mut is_public_vm = false; + let mut is_initializer = false; + let mut is_internal = false; + let mut insert_init_check = has_initializer; + for secondary_attribute in func.def.attributes.secondary.clone() { - let crate_graph = &context.crate_graph[crate_id]; if is_custom_attribute(&secondary_attribute, "aztec(private)") { - transform_function("Private", func, storage_defined) - .map_err(|err| (err, crate_graph.root_file_id))?; - has_transformed_module = true; + is_private = true; + } else if is_custom_attribute(&secondary_attribute, "aztec(initializer)") { + is_initializer = true; + insert_init_check = false; + } else if is_custom_attribute(&secondary_attribute, "aztec(noinitcheck)") { + insert_init_check = false; + } else if is_custom_attribute(&secondary_attribute, "aztec(internal)") { + is_internal = true; } else if is_custom_attribute(&secondary_attribute, "aztec(public)") { - transform_function("Public", func, storage_defined) - .map_err(|err| (err, crate_graph.root_file_id))?; - has_transformed_module = true; + is_public = true; } else if is_custom_attribute(&secondary_attribute, "aztec(public-vm)") { - transform_vm_function(func, storage_defined) - .map_err(|err| (err, crate_graph.root_file_id))?; - has_transformed_module = true; + is_public_vm = true; } } - // Add the storage struct to the beginning of the function if it is unconstrained in an aztec contract - if storage_defined && func.def.is_unconstrained { + + // Apply transformations to the function based on collected attributes + if is_private || is_public || is_public_vm { + transform_function( + if is_private { + "Private" + } else if is_public_vm { + "Avm" + } else { + "Public" + }, + func, + storage_defined, + is_initializer, + insert_init_check, + is_internal, + )?; + has_transformed_module = true; + } else if storage_defined && func.def.is_unconstrained { transform_unconstrained(func); has_transformed_module = true; } @@ -456,1353 +163,55 @@ fn transform_module( if has_transformed_module { // We only want to run these checks if the macro processor has found the module to be an Aztec contract. - if module.functions.len() > MAX_CONTRACT_FUNCTIONS { - let crate_graph = &context.crate_graph[crate_id]; - return Err(( - AztecMacroError::ContractHasTooManyFunctions { span: Span::default() }, - crate_graph.root_file_id, - )); - } - - let constructor_defined = module.functions.iter().any(|func| func.name() == "constructor"); - if !constructor_defined { - let crate_graph = &context.crate_graph[crate_id]; - return Err(( - AztecMacroError::ContractConstructorMissing { span: Span::default() }, - crate_graph.root_file_id, - )); - } - } - - Ok(has_transformed_module) -} - -/// Auxiliary function to generate the storage constructor for a given field, using -/// the Storage definition as a reference. Supports nesting. -fn generate_storage_field_constructor( - (type_ident, unresolved_type): &(Ident, UnresolvedType), - slot: Expression, -) -> Result { - let typ = &unresolved_type.typ; - match typ { - UnresolvedTypeData::Named(path, generics, _) => { - let mut new_path = path.clone().to_owned(); - new_path.segments.push(ident("new")); - match path.segments.last().unwrap().0.contents.as_str() { - "Map" => Ok(call( - variable_path(new_path), - vec![ - variable("context"), - slot, - lambda( - vec![ - ( - pattern("context"), - make_type(UnresolvedTypeData::Named( - chained_path!("aztec", "context", "Context"), - vec![], - true, - )), - ), - ( - Pattern::Identifier(ident("slot")), - make_type(UnresolvedTypeData::FieldElement), - ), - ], - generate_storage_field_constructor( - &(type_ident.clone(), generics.iter().last().unwrap().clone()), - variable("slot"), - )?, - ), - ], - )), - _ => Ok(call(variable_path(new_path), vec![variable("context"), slot])), - } - } - _ => Err(AztecMacroError::UnsupportedStorageType { - typ: typ.clone(), - span: Some(type_ident.span()), - }), - } -} - -// Generates the Storage implementation block from the Storage struct definition if it does not exist -/// From: -/// -/// struct Storage { -/// a_map: Map>, -/// a_nested_map: Map>>, -/// a_field: SomeStoragePrimitive, -/// } -/// -/// To: -/// -/// impl Storage { -/// fn init(context: Context) -> Self { -/// Storage { -/// a_map: Map::new(context, 0, |context, slot| { -/// SomeStoragePrimitive::new(context, slot) -/// }), -/// a_nested_map: Map::new(context, 0, |context, slot| { -/// Map::new(context, slot, |context, slot| { -/// SomeStoragePrimitive::new(context, slot) -/// }) -/// }), -/// a_field: SomeStoragePrimitive::new(context, 0), -/// } -/// } -/// } -/// -/// Storage slots are generated as 0 and will be populated using the information from the HIR -/// at a later stage. -fn generate_storage_implementation(module: &mut SortedModule) -> Result<(), AztecMacroError> { - let definition = - module.types.iter().find(|r#struct| r#struct.name.0.contents == "Storage").unwrap(); - - let slot_zero = expression(ExpressionKind::Literal(Literal::Integer( - FieldElement::from(i128::from(0)), - false, - ))); - - let field_constructors = definition - .fields - .iter() - .flat_map(|field| { - generate_storage_field_constructor(field, slot_zero.clone()) - .map(|expression| (field.0.clone(), expression)) - }) - .collect(); - - let storage_constructor_statement = make_statement(StatementKind::Expression(expression( - ExpressionKind::constructor((chained_path!("Storage"), field_constructors)), - ))); - - let init = NoirFunction::normal(FunctionDefinition::normal( - &ident("init"), - &vec![], - &[( - ident("context"), - make_type(UnresolvedTypeData::Named( - chained_path!("aztec", "context", "Context"), - vec![], - true, - )), - )], - &BlockExpression(vec![storage_constructor_statement]), - &[], - &return_type(chained_path!("Self")), - )); - - let storage_impl = TypeImpl { - object_type: UnresolvedType { - typ: UnresolvedTypeData::Named(chained_path!("Storage"), vec![], true), - span: Some(Span::default()), - }, - type_span: Span::default(), - generics: vec![], - methods: vec![(init, Span::default())], - }; - module.impls.push(storage_impl); - - Ok(()) -} - -/// If it does, it will insert the following things: -/// - A new Input that is provided for a kernel app circuit, named: {Public/Private}ContextInputs -/// - Hashes all of the function input variables -/// - This instantiates a helper function -fn transform_function( - ty: &str, - func: &mut NoirFunction, - storage_defined: bool, -) -> Result<(), AztecMacroError> { - let context_name = format!("{}Context", ty); - let inputs_name = format!("{}ContextInputs", ty); - let return_type_name = format!("{}CircuitPublicInputs", ty); - - // Add access to the storage struct - if storage_defined { - let storage_def = abstract_storage(&ty.to_lowercase(), false); - func.def.body.0.insert(0, storage_def); - } - - // Insert the context creation as the first action - let create_context = create_context(&context_name, &func.def.parameters)?; - func.def.body.0.splice(0..0, (create_context).iter().cloned()); - - // Add the inputs to the params - let input = create_inputs(&inputs_name); - func.def.parameters.insert(0, input); - - // Abstract return types such that they get added to the kernel's return_values - if let Some(return_values) = abstract_return_values(func) { - func.def.body.0.push(return_values); - } - - // Push the finish method call to the end of the function - let finish_def = create_context_finish(); - func.def.body.0.push(finish_def); - - let return_type = create_return_type(&return_type_name); - func.def.return_type = return_type; - func.def.return_visibility = Visibility::Public; - - // Distinct return types are only required for private functions - // Public functions should have open auto-inferred - match ty { - "Private" => func.def.return_distinctness = Distinctness::Distinct, - "Public" => func.def.is_open = true, - _ => (), - } - - Ok(()) -} - -/// Transform a function to work with AVM bytecode -fn transform_vm_function( - func: &mut NoirFunction, - _storage_defined: bool, -) -> Result<(), AztecMacroError> { - // Push Avm context creation to the beginning of the function - let create_context = create_avm_context()?; - func.def.body.0.insert(0, create_context); - - // We want the function to be seen as a public function - func.def.is_open = true; - - // NOTE: the line below is a temporary hack to trigger external transpilation tools - // It will be removed once the transpiler is integrated into the Noir compiler - func.def.name.0.contents = format!("avm_{}", func.def.name.0.contents); - Ok(()) -} - -/// Transform Unconstrained -/// -/// Inserts the following code at the beginning of an unconstrained function -/// ```noir -/// let storage = Storage::init(Context::none()); -/// ``` -/// -/// This will allow developers to access their contract' storage struct in unconstrained functions -fn transform_unconstrained(func: &mut NoirFunction) { - func.def.body.0.insert(0, abstract_storage("Unconstrained", true)); -} - -fn collect_crate_structs(crate_id: &CrateId, context: &HirContext) -> Vec { - context - .def_map(crate_id) - .expect("ICE: Missing crate in def_map") - .modules() - .iter() - .flat_map(|(_, module)| { - module.type_definitions().filter_map(|typ| { - if let ModuleDefId::TypeId(struct_id) = typ { - Some(struct_id) - } else { - None - } - }) - }) - .collect() -} - -fn collect_traits(context: &HirContext) -> Vec { - let crates = context.crates(); - crates - .flat_map(|crate_id| context.def_map(&crate_id).map(|def_map| def_map.modules())) - .flatten() - .flat_map(|module| { - module.type_definitions().filter_map(|typ| { - if let ModuleDefId::TraitId(struct_id) = typ { - Some(struct_id) - } else { - None - } + let private_functions_count = module + .functions + .iter() + .filter(|func| { + func.def + .attributes + .secondary + .iter() + .any(|attr| is_custom_attribute(attr, "aztec(private)")) }) - }) - .collect() -} - -/// Substitutes the signature literal that was introduced in the selector method previously with the actual signature. -fn transform_event( - struct_id: StructId, - interner: &mut NodeInterner, -) -> Result<(), (AztecMacroError, FileId)> { - let struct_type = interner.get_struct(struct_id); - let selector_id = interner - .lookup_method(&Type::Struct(struct_type.clone(), vec![]), struct_id, "selector", false) - .ok_or_else(|| { - let error = AztecMacroError::EventError { - span: struct_type.borrow().location.span, - message: "Selector method not found".to_owned(), - }; - (error, struct_type.borrow().location.file) - })?; - let selector_function = interner.function(&selector_id); - - let compute_selector_statement = interner.statement( - selector_function.block(interner).statements().first().ok_or_else(|| { - let error = AztecMacroError::EventError { - span: struct_type.borrow().location.span, - message: "Compute selector statement not found".to_owned(), - }; - (error, struct_type.borrow().location.file) - })?, - ); - - let compute_selector_expression = match compute_selector_statement { - HirStatement::Expression(expression_id) => match interner.expression(&expression_id) { - HirExpression::Call(hir_call_expression) => Some(hir_call_expression), - _ => None, - }, - _ => None, - } - .ok_or_else(|| { - let error = AztecMacroError::EventError { - span: struct_type.borrow().location.span, - message: "Compute selector statement is not a call expression".to_owned(), - }; - (error, struct_type.borrow().location.file) - })?; - - let first_arg_id = compute_selector_expression.arguments.first().ok_or_else(|| { - let error = AztecMacroError::EventError { - span: struct_type.borrow().location.span, - message: "Compute selector statement is not a call expression".to_owned(), - }; - (error, struct_type.borrow().location.file) - })?; - - match interner.expression(first_arg_id) { - HirExpression::Literal(HirLiteral::Str(signature)) - if signature == SIGNATURE_PLACEHOLDER => - { - let selector_literal_id = *first_arg_id; + .count(); - let structure = interner.get_struct(struct_id); - let signature = event_signature(&structure.borrow()); - interner.update_expression(selector_literal_id, |expr| { - *expr = HirExpression::Literal(HirLiteral::Str(signature.clone())); + if private_functions_count > MAX_CONTRACT_PRIVATE_FUNCTIONS { + return Err(AztecMacroError::ContractHasTooManyPrivateFunctions { + span: Span::default(), }); - - // Also update the type! It might have a different length now than the placeholder. - interner.push_expr_type( - selector_literal_id, - Type::String(Box::new(Type::Constant(signature.len() as u64))), - ); - Ok(()) - } - _ => Err(( - AztecMacroError::EventError { - span: struct_type.borrow().location.span, - message: "Signature placeholder literal does not match".to_owned(), - }, - struct_type.borrow().location.file, - )), - } -} - -fn transform_events( - crate_id: &CrateId, - context: &mut HirContext, -) -> Result<(), (AztecMacroError, FileId)> { - for struct_id in collect_crate_structs(crate_id, context) { - let attributes = context.def_interner.struct_attributes(&struct_id); - if attributes.iter().any(|attr| matches!(attr, SecondaryAttribute::Event)) { - transform_event(struct_id, &mut context.def_interner)?; - } - } - Ok(()) -} - -/// Obtains the serialized length of a type that implements the Serialize trait. -fn get_serialized_length( - traits: &[TraitId], - typ: &Type, - interner: &NodeInterner, -) -> Result { - let (struct_name, maybe_stored_in_state) = match typ { - Type::Struct(struct_type, generics) => { - Ok((struct_type.borrow().name.0.contents.clone(), generics.first())) } - _ => Err(AztecMacroError::CouldNotAssignStorageSlots { - secondary_message: Some("State storage variable must be a struct".to_string()), - }), - }?; - let stored_in_state = - maybe_stored_in_state.ok_or(AztecMacroError::CouldNotAssignStorageSlots { - secondary_message: Some("State storage variable must be generic".to_string()), - })?; - - let is_note = traits.iter().any(|&trait_id| { - let r#trait = interner.get_trait(trait_id); - r#trait.name.0.contents == "NoteInterface" - && !interner.lookup_all_trait_implementations(stored_in_state, trait_id).is_empty() - }); - - // Maps and (private) Notes always occupy a single slot. Someone could store a Note in PublicMutable for whatever reason though. - if struct_name == "Map" || (is_note && struct_name != "PublicMutable") { - return Ok(1); } - let serialized_trait_impl_kind = traits - .iter() - .find_map(|&trait_id| { - let r#trait = interner.get_trait(trait_id); - if r#trait.borrow().name.0.contents == "Serialize" - && r#trait.borrow().generics.len() == 1 - { - interner - .lookup_all_trait_implementations(stored_in_state, trait_id) - .into_iter() - .next() - } else { - None - } - }) - .ok_or(AztecMacroError::CouldNotAssignStorageSlots { - secondary_message: Some("Stored data must implement Serialize trait".to_string()), - })?; - - let serialized_trait_impl_id = match serialized_trait_impl_kind { - TraitImplKind::Normal(trait_impl_id) => Ok(trait_impl_id), - _ => Err(AztecMacroError::CouldNotAssignStorageSlots { secondary_message: None }), - }?; - - let serialized_trait_impl_shared = interner.get_trait_implementation(*serialized_trait_impl_id); - let serialized_trait_impl = serialized_trait_impl_shared.borrow(); - - match serialized_trait_impl.trait_generics.first().unwrap() { - Type::Constant(value) => Ok(*value), - _ => Err(AztecMacroError::CouldNotAssignStorageSlots { secondary_message: None }), - } + Ok(has_transformed_module) } -/// Assigns storage slots to the storage struct fields based on the serialized length of the types. This automatic assignment -/// will only trigger if the assigned storage slot is invalid (0 as generated by generate_storage_implementation) -fn assign_storage_slots( +fn transform_collected_defs( crate_id: &CrateId, context: &mut HirContext, -) -> Result<(), (AztecMacroError, FileId)> { - let traits: Vec<_> = collect_traits(context); - for struct_id in collect_crate_structs(crate_id, context) { - let interner: &mut NodeInterner = context.def_interner.borrow_mut(); - let r#struct = interner.get_struct(struct_id); - let file_id = r#struct.borrow().location.file; - if r#struct.borrow().name.0.contents == "Storage" && r#struct.borrow().id.krate().is_root() - { - let init_id = interner - .lookup_method( - &Type::Struct(interner.get_struct(struct_id), vec![]), - struct_id, - "init", - false, - ) - .ok_or(( - AztecMacroError::CouldNotAssignStorageSlots { - secondary_message: Some( - "Storage struct must have an init function".to_string(), - ), - }, - file_id, - ))?; - let init_function = interner.function(&init_id).block(interner); - let init_function_statement_id = init_function.statements().first().ok_or(( - AztecMacroError::CouldNotAssignStorageSlots { - secondary_message: Some("Init storage statement not found".to_string()), - }, - file_id, - ))?; - let storage_constructor_statement = interner.statement(init_function_statement_id); - - let storage_constructor_expression = match storage_constructor_statement { - HirStatement::Expression(expression_id) => { - match interner.expression(&expression_id) { - HirExpression::Constructor(hir_constructor_expression) => { - Ok(hir_constructor_expression) - } - _ => Err((AztecMacroError::CouldNotAssignStorageSlots { - secondary_message: Some( - "Storage constructor statement must be a constructor expression" - .to_string(), - ), - }, file_id)) - } - } - _ => Err(( - AztecMacroError::CouldNotAssignStorageSlots { - secondary_message: Some( - "Storage constructor statement must be an expression".to_string(), - ), - }, - file_id, - )), - }?; - - let mut storage_slot: u64 = 1; - for (index, (_, expr_id)) in storage_constructor_expression.fields.iter().enumerate() { - let fields = r#struct.borrow().get_fields(&[]); - let (_, field_type) = fields.get(index).unwrap(); - let new_call_expression = match interner.expression(expr_id) { - HirExpression::Call(hir_call_expression) => Ok(hir_call_expression), - _ => Err(( - AztecMacroError::CouldNotAssignStorageSlots { - secondary_message: Some( - "Storage field initialization expression is not a call expression" - .to_string(), - ), - }, - file_id, - )), - }?; - - let slot_arg_expression = interner.expression(&new_call_expression.arguments[1]); - - let current_storage_slot = match slot_arg_expression { - HirExpression::Literal(HirLiteral::Integer(slot, _)) => Ok(slot.to_u128()), - _ => Err(( - AztecMacroError::CouldNotAssignStorageSlots { - secondary_message: Some( - "Storage slot argument expression must be a literal integer" - .to_string(), - ), - }, - file_id, - )), - }?; - - if current_storage_slot != 0 { - continue; - } - - let type_serialized_len = get_serialized_length(&traits, field_type, interner) - .map_err(|err| (err, file_id))?; - interner.update_expression(new_call_expression.arguments[1], |expr| { - *expr = HirExpression::Literal(HirLiteral::Integer( - FieldElement::from(u128::from(storage_slot)), - false, - )); - }); - - storage_slot += type_serialized_len; - } - } - } - Ok(()) -} - -const SIGNATURE_PLACEHOLDER: &str = "SIGNATURE_PLACEHOLDER"; - -/// Generates the impl for an event selector -/// -/// Inserts the following code: -/// ```noir -/// impl SomeStruct { -/// fn selector() -> FunctionSelector { -/// aztec::protocol_types::abis::function_selector::FunctionSelector::from_signature("SIGNATURE_PLACEHOLDER") -/// } -/// } -/// ``` -/// -/// This allows developers to emit events without having to write the signature of the event every time they emit it. -/// The signature cannot be known at this point since types are not resolved yet, so we use a signature placeholder. -/// It'll get resolved after by transforming the HIR. -fn generate_selector_impl(structure: &NoirStruct) -> TypeImpl { - let struct_type = - make_type(UnresolvedTypeData::Named(path(structure.name.clone()), vec![], true)); - - let selector_path = - chained_path!("aztec", "protocol_types", "abis", "function_selector", "FunctionSelector"); - let mut from_signature_path = selector_path.clone(); - from_signature_path.segments.push(ident("from_signature")); - - let selector_fun_body = BlockExpression(vec![make_statement(StatementKind::Expression(call( - variable_path(from_signature_path), - vec![expression(ExpressionKind::Literal(Literal::Str(SIGNATURE_PLACEHOLDER.to_string())))], - )))]); - - // Define `FunctionSelector` return type - let return_type = - FunctionReturnType::Ty(make_type(UnresolvedTypeData::Named(selector_path, vec![], true))); - - let mut selector_fn_def = FunctionDefinition::normal( - &ident("selector"), - &vec![], - &[], - &selector_fun_body, - &[], - &return_type, - ); - - selector_fn_def.visibility = FunctionVisibility::Public; - - // Seems to be necessary on contract modules - selector_fn_def.return_visibility = Visibility::Public; - - TypeImpl { - object_type: struct_type, - type_span: structure.span, - generics: vec![], - methods: vec![(NoirFunction::normal(selector_fn_def), Span::default())], - } -} - -/// Helper function that returns what the private context would look like in the ast -/// This should make it available to be consumed within aztec private annotated functions. -/// -/// The replaced code: -/// ```noir -/// /// Before -/// fn foo(inputs: PrivateContextInputs) { -/// // ... -/// } -/// -/// /// After -/// #[aztec(private)] -/// fn foo() { -/// // ... -/// } -fn create_inputs(ty: &str) -> Param { - let context_ident = ident("inputs"); - let context_pattern = Pattern::Identifier(context_ident); - - let path_snippet = ty.to_case(Case::Snake); // e.g. private_context_inputs - let type_path = chained_path!("aztec", "context", "inputs", &path_snippet, ty); - - let context_type = make_type(UnresolvedTypeData::Named(type_path, vec![], true)); - let visibility = Visibility::Private; - - Param { pattern: context_pattern, typ: context_type, visibility, span: Span::default() } -} - -/// Creates the private context object to be accessed within the function, the parameters need to be extracted to be -/// appended into the args hash object. -/// -/// The replaced code: -/// ```noir -/// #[aztec(private)] -/// fn foo(structInput: SomeStruct, arrayInput: [u8; 10], fieldInput: Field) -> Field { -/// // Create the hasher object -/// let mut hasher = Hasher::new(); -/// -/// // struct inputs call serialize on them to add an array of fields -/// hasher.add_multiple(structInput.serialize()); -/// -/// // Array inputs are iterated over and each element is added to the hasher (as a field) -/// for i in 0..arrayInput.len() { -/// hasher.add(arrayInput[i] as Field); -/// } -/// // Field inputs are added to the hasher -/// hasher.add({ident}); -/// -/// // Create the context -/// // The inputs (injected by this `create_inputs`) and completed hash object are passed to the context -/// let mut context = PrivateContext::new(inputs, hasher.hash()); -/// } -/// ``` -fn create_context(ty: &str, params: &[Param]) -> Result, AztecMacroError> { - let mut injected_expressions: Vec = vec![]; - - // `let mut hasher = Hasher::new();` - let let_hasher = mutable_assignment( - "hasher", // Assigned to - call( - variable_path(chained_path!("aztec", "hasher", "Hasher", "new")), // Path - vec![], // args - ), - ); - - // Completes: `let mut hasher = Hasher::new();` - injected_expressions.push(let_hasher); - - // Iterate over each of the function parameters, adding to them to the hasher - for Param { pattern, typ, span, .. } in params { - match pattern { - Pattern::Identifier(identifier) => { - // Match the type to determine the padding to do - let unresolved_type = &typ.typ; - let expression = match unresolved_type { - // `hasher.add_multiple({ident}.serialize())` - UnresolvedTypeData::Named(..) => add_struct_to_hasher(identifier), - UnresolvedTypeData::Array(_, arr_type) => { - add_array_to_hasher(identifier, arr_type) - } - // `hasher.add({ident})` - UnresolvedTypeData::FieldElement => add_field_to_hasher(identifier), - // Add the integer to the hasher, casted to a field - // `hasher.add({ident} as Field)` - UnresolvedTypeData::Integer(..) | UnresolvedTypeData::Bool => { - add_cast_to_hasher(identifier) - } - UnresolvedTypeData::String(..) => { - let (var_bytes, id) = str_to_bytes(identifier); - injected_expressions.push(var_bytes); - add_array_to_hasher( - &id, - &UnresolvedType { - typ: UnresolvedTypeData::Integer( - Signedness::Unsigned, - noirc_frontend::IntegerBitSize::ThirtyTwo, - ), - span: None, - }, - ) - } - _ => { - return Err(AztecMacroError::UnsupportedFunctionArgumentType { - typ: unresolved_type.clone(), - span: *span, - }) - } - }; - injected_expressions.push(expression); - } - _ => todo!(), // Maybe unreachable? - } - } - - // Create the inputs to the context - let inputs_expression = variable("inputs"); - // `hasher.hash()` - let hash_call = method_call( - variable("hasher"), // variable - "hash", // method name - vec![], // args - ); - - let path_snippet = ty.to_case(Case::Snake); // e.g. private_context - - // let mut context = {ty}::new(inputs, hash); - let let_context = mutable_assignment( - "context", // Assigned to - call( - variable_path(chained_path!("aztec", "context", &path_snippet, ty, "new")), // Path - vec![inputs_expression, hash_call], // args - ), - ); - injected_expressions.push(let_context); - - // Return all expressions that will be injected by the hasher - Ok(injected_expressions) -} - -/// Creates an mutable avm context -/// -/// ```noir -/// /// Before -/// #[aztec(public-vm)] -/// fn foo() -> Field { -/// let mut context = aztec::context::AVMContext::new(); -/// let timestamp = context.timestamp(); -/// // ... -/// } -/// -/// /// After -/// #[aztec(private)] -/// fn foo() -> Field { -/// let mut timestamp = context.timestamp(); -/// // ... -/// } -fn create_avm_context() -> Result { - let let_context = mutable_assignment( - "context", // Assigned to - call( - variable_path(chained_path!("aztec", "context", "AVMContext", "new")), // Path - vec![], // args - ), - ); - - Ok(let_context) -} - -/// Abstract Return Type -/// -/// This function intercepts the function's current return type and replaces it with pushes -/// To the kernel -/// -/// The replaced code: -/// ```noir -/// /// Before -/// #[aztec(private)] -/// fn foo() -> protocol_types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs { -/// // ... -/// let my_return_value: Field = 10; -/// context.return_values.push(my_return_value); -/// } -/// -/// /// After -/// #[aztec(private)] -/// fn foo() -> Field { -/// // ... -/// let my_return_value: Field = 10; -/// my_return_value -/// } -/// ``` -/// Similarly; Structs will be pushed to the context, after serialize() is called on them. -/// Arrays will be iterated over and each element will be pushed to the context. -/// Any primitive type that can be cast will be casted to a field and pushed to the context. -fn abstract_return_values(func: &NoirFunction) -> Option { - let current_return_type = func.return_type().typ; - let len = func.def.body.len(); - let last_statement = &func.def.body.0[len - 1]; - - // TODO: (length, type) => We can limit the size of the array returned to be limited by kernel size - // Doesn't need done until we have settled on a kernel size - // TODO: support tuples here and in inputs -> convert into an issue - - // Check if the return type is an expression, if it is, we can handle it - match last_statement { - Statement { kind: StatementKind::Expression(expression), .. } => { - match current_return_type { - // Call serialize on structs, push the whole array, calling push_array - UnresolvedTypeData::Named(..) => Some(make_struct_return_type(expression.clone())), - UnresolvedTypeData::Array(..) => Some(make_array_return_type(expression.clone())), - // Cast these types to a field before pushing - UnresolvedTypeData::Bool | UnresolvedTypeData::Integer(..) => { - Some(make_castable_return_type(expression.clone())) - } - UnresolvedTypeData::FieldElement => Some(make_return_push(expression.clone())), - _ => None, - } - } - _ => None, - } -} - -/// Abstract storage -/// -/// For private functions: -/// ```noir -/// #[aztec(private)] -/// fn lol() { -/// let storage = Storage::init(Context::private(context)); -/// } -/// ``` -/// -/// For public functions: -/// ```noir -/// #[aztec(public)] -/// fn lol() { -/// let storage = Storage::init(Context::public(context)); -/// } -/// ``` -/// -/// For unconstrained functions: -/// ```noir -/// unconstrained fn lol() { -/// let storage = Storage::init(Context::none()); -/// } -fn abstract_storage(typ: &str, unconstrained: bool) -> Statement { - let init_context_call = if unconstrained { - call( - variable_path(chained_path!("aztec", "context", "Context", "none")), // Path - vec![], // args + collected_trait_impls: &[UnresolvedTraitImpl], + collected_functions: &mut [UnresolvedFunctions], +) -> Result<(), (MacroError, FileId)> { + if has_aztec_dependency(crate_id, context) { + inject_compute_note_hash_and_nullifier( + crate_id, + context, + collected_trait_impls, + collected_functions, ) } else { - call( - variable_path(chained_path!("aztec", "context", "Context", typ)), // Path - vec![mutable_reference("context")], // args - ) - }; - - assignment( - "storage", // Assigned to - call( - variable_path(chained_path!("Storage", "init")), // Path - vec![init_context_call], // args - ), - ) -} - -/// Context Return Values -/// -/// Creates an instance to the context return values -/// ```noir -/// `context.return_values` -/// ``` -fn context_return_values() -> Expression { - member_access("context", "return_values") -} - -fn make_statement(kind: StatementKind) -> Statement { - Statement { span: Span::default(), kind } -} - -/// Make return Push -/// -/// Translates to: -/// `context.return_values.push({push_value})` -fn make_return_push(push_value: Expression) -> Statement { - make_statement(StatementKind::Semi(method_call( - context_return_values(), - "push", - vec![push_value], - ))) -} - -/// Make Return push array -/// -/// Translates to: -/// `context.return_values.extend_from_array({push_value})` -fn make_return_extend_from_array(push_value: Expression) -> Statement { - make_statement(StatementKind::Semi(method_call( - context_return_values(), - "extend_from_array", - vec![push_value], - ))) -} - -/// Make struct return type -/// -/// Translates to: -/// ```noir -/// `context.return_values.extend_from_array({push_value}.serialize())` -fn make_struct_return_type(expression: Expression) -> Statement { - let serialized_call = method_call( - expression, // variable - "serialize", // method name - vec![], // args - ); - make_return_extend_from_array(serialized_call) -} - -/// Make array return type -/// -/// Translates to: -/// ```noir -/// for i in 0..{ident}.len() { -/// context.return_values.push({ident}[i] as Field) -/// } -/// ``` -fn make_array_return_type(expression: Expression) -> Statement { - let inner_cast_expression = - cast(index_array_variable(expression.clone(), "i"), UnresolvedTypeData::FieldElement); - let assignment = make_statement(StatementKind::Semi(method_call( - context_return_values(), // variable - "push", // method name - vec![inner_cast_expression], - ))); - - create_loop_over(expression, vec![assignment]) -} - -/// Castable return type -/// -/// Translates to: -/// ```noir -/// context.return_values.push({ident} as Field) -/// ``` -fn make_castable_return_type(expression: Expression) -> Statement { - // Cast these types to a field before pushing - let cast_expression = cast(expression, UnresolvedTypeData::FieldElement); - make_return_push(cast_expression) -} - -/// Create Return Type -/// -/// Public functions return protocol_types::abis::public_circuit_public_inputs::PublicCircuitPublicInputs while -/// private functions return protocol_types::abis::private_circuit_public_inputs::::PrivateCircuitPublicInputs -/// -/// This call constructs an ast token referencing the above types -/// The name is set in the function above `transform`, hence the -/// whole token name is passed in -/// -/// The replaced code: -/// ```noir -/// -/// /// Before -/// fn foo() -> protocol_types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs { -/// // ... -/// } -/// -/// /// After -/// #[aztec(private)] -/// fn foo() { -/// // ... -/// } -fn create_return_type(ty: &str) -> FunctionReturnType { - let path_snippet = ty.to_case(Case::Snake); // e.g. private_circuit_public_inputs or public_circuit_public_inputs - let return_path = chained_path!("aztec", "protocol_types", "abis", &path_snippet, ty); - return_type(return_path) -} - -/// Create Context Finish -/// -/// Each aztec function calls `context.finish()` at the end of a function -/// to return values required by the kernel. -/// -/// The replaced code: -/// ```noir -/// /// Before -/// fn foo() -> protocol_types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs { -/// // ... -/// context.finish() -/// } -/// -/// /// After -/// #[aztec(private)] -/// fn foo() { -/// // ... -/// } -fn create_context_finish() -> Statement { - let method_call = method_call( - variable("context"), // variable - "finish", // method name - vec![], // args - ); - make_statement(StatementKind::Expression(method_call)) + Ok(()) + } } // -// Methods to create hasher inputs +// Transform Hir Nodes for Aztec // -fn add_struct_to_hasher(identifier: &Ident) -> Statement { - // If this is a struct, we call serialize and add the array to the hasher - let serialized_call = method_call( - variable_path(path(identifier.clone())), // variable - "serialize", // method name - vec![], // args - ); - - make_statement(StatementKind::Semi(method_call( - variable("hasher"), // variable - "add_multiple", // method name - vec![serialized_call], // args - ))) -} - -fn str_to_bytes(identifier: &Ident) -> (Statement, Ident) { - // let identifier_as_bytes = identifier.as_bytes(); - let var = variable_ident(identifier.clone()); - let contents = if let ExpressionKind::Variable(p) = &var.kind { - p.segments.first().cloned().unwrap_or_else(|| panic!("No segments")).0.contents - } else { - panic!("Unexpected identifier type") - }; - let bytes_name = format!("{}_bytes", contents); - let var_bytes = assignment(&bytes_name, method_call(var, "as_bytes", vec![])); - let id = Ident::new(bytes_name, Span::default()); - - (var_bytes, id) -} - -fn create_loop_over(var: Expression, loop_body: Vec) -> Statement { - // If this is an array of primitive types (integers / fields) we can add them each to the hasher - // casted to a field - let span = var.span; - - // `array.len()` - let end_range_expression = method_call( - var, // variable - "len", // method name - vec![], // args - ); - - // What will be looped over - // - `hasher.add({ident}[i] as Field)` - let for_loop_block = expression(ExpressionKind::Block(BlockExpression(loop_body))); - - // `for i in 0..{ident}.len()` - make_statement(StatementKind::For(ForLoopStatement { - range: ForRange::Range( - expression(ExpressionKind::Literal(Literal::Integer( - FieldElement::from(i128::from(0)), - false, - ))), - end_range_expression, - ), - identifier: ident("i"), - block: for_loop_block, - span, - })) -} - -fn add_array_to_hasher(identifier: &Ident, arr_type: &UnresolvedType) -> Statement { - // If this is an array of primitive types (integers / fields) we can add them each to the hasher - // casted to a field - - // Wrap in the semi thing - does that mean ended with semi colon? - // `hasher.add({ident}[i] as Field)` - - let arr_index = index_array(identifier.clone(), "i"); - let (add_expression, hasher_method_name) = match arr_type.typ { - UnresolvedTypeData::Named(..) => { - let hasher_method_name = "add_multiple".to_owned(); - let call = method_call( - // All serialize on each element - arr_index, // variable - "serialize", // method name - vec![], // args - ); - (call, hasher_method_name) - } - _ => { - let hasher_method_name = "add".to_owned(); - let call = cast( - arr_index, // lhs - `ident[i]` - UnresolvedTypeData::FieldElement, // cast to - `as Field` - ); - (call, hasher_method_name) - } - }; - - let block_statement = make_statement(StatementKind::Semi(method_call( - variable("hasher"), // variable - &hasher_method_name, // method name - vec![add_expression], - ))); - - create_loop_over(variable_ident(identifier.clone()), vec![block_statement]) -} - -fn add_field_to_hasher(identifier: &Ident) -> Statement { - // `hasher.add({ident})` - let ident = variable_path(path(identifier.clone())); - make_statement(StatementKind::Semi(method_call( - variable("hasher"), // variable - "add", // method name - vec![ident], // args - ))) -} - -fn add_cast_to_hasher(identifier: &Ident) -> Statement { - // `hasher.add({ident} as Field)` - // `{ident} as Field` - let cast_operation = cast( - variable_path(path(identifier.clone())), // lhs - UnresolvedTypeData::FieldElement, // rhs - ); - - // `hasher.add({ident} as Field)` - make_statement(StatementKind::Semi(method_call( - variable("hasher"), // variable - "add", // method name - vec![cast_operation], // args - ))) -} - -/// Computes the aztec signature for a resolved type. -fn signature_of_type(typ: &Type) -> String { - match typ { - Type::Integer(Signedness::Signed, bit_size) => format!("i{}", bit_size), - Type::Integer(Signedness::Unsigned, bit_size) => format!("u{}", bit_size), - Type::FieldElement => "Field".to_owned(), - Type::Bool => "bool".to_owned(), - Type::Array(len, typ) => { - if let Type::Constant(len) = **len { - format!("[{};{len}]", signature_of_type(typ)) - } else { - unimplemented!("Cannot generate signature for array with length type {:?}", typ) - } - } - Type::Struct(def, args) => { - let fields = def.borrow().get_fields(args); - let fields = vecmap(fields, |(_, typ)| signature_of_type(&typ)); - format!("({})", fields.join(",")) - } - Type::Tuple(types) => { - let fields = vecmap(types, signature_of_type); - format!("({})", fields.join(",")) - } - _ => unimplemented!("Cannot generate signature for type {:?}", typ), - } -} - -/// Computes the signature for a resolved event type. -/// It has the form 'EventName(Field,(Field),[u8;2])' -fn event_signature(event: &StructType) -> String { - let fields = vecmap(event.get_fields(&[]), |(_, typ)| signature_of_type(&typ)); - format!("{}({})", event.name.0.contents, fields.join(",")) -} - -fn inject_compute_note_hash_and_nullifier( +/// Completes the Hir with data gathered from type resolution +fn transform_hir( crate_id: &CrateId, context: &mut HirContext, - unresolved_traits_impls: &[UnresolvedTraitImpl], - collected_functions: &mut [UnresolvedFunctions], -) -> Result<(), (MacroError, FileId)> { - // We first fetch modules in this crate which correspond to contracts, along with their file id. - let contract_module_file_ids: Vec<(LocalModuleId, FileId)> = context - .def_map(crate_id) - .expect("ICE: Missing crate in def_map") - .modules() - .iter() - .filter(|(_, module)| module.is_contract) - .map(|(idx, module)| (LocalModuleId(idx), module.location.file)) - .collect(); - - // If the current crate does not contain a contract module we simply skip it. - if contract_module_file_ids.is_empty() { - return Ok(()); - } else if contract_module_file_ids.len() != 1 { - panic!("Found multiple contracts in the same crate"); - } - - let (module_id, file_id) = contract_module_file_ids[0]; - - // If compute_note_hash_and_nullifier is already defined by the user, we skip auto-generation in order to provide an - // escape hatch for this mechanism. - // TODO(#4647): improve this diagnosis and error messaging. - if collected_functions.iter().any(|coll_funcs_data| { - check_for_compute_note_hash_and_nullifier_definition(&coll_funcs_data.functions, module_id) - }) { - return Ok(()); - } - - // In order to implement compute_note_hash_and_nullifier, we need to know all of the different note types the - // contract might use. These are the types that implement the NoteInterface trait, which provides the - // get_note_type_id function. - let note_types = fetch_struct_trait_impls(context, unresolved_traits_impls, "NoteInterface"); - - // We can now generate a version of compute_note_hash_and_nullifier tailored for the contract in this crate. - let func = generate_compute_note_hash_and_nullifier(¬e_types); - - // And inject the newly created function into the contract. - - // TODO(#4373): We don't have a reasonable location for the source code of this autogenerated function, so we simply - // pass an empty span. This function should not produce errors anyway so this should not matter. - let location = Location::new(Span::empty(0), file_id); - - // These are the same things the ModCollector does when collecting functions: we push the function to the - // NodeInterner, declare it in the module (which checks for duplicate definitions), and finally add it to the list - // on collected but unresolved functions. - - let func_id = context.def_interner.push_empty_fn(); - context.def_interner.push_function( - func_id, - &func.def, - ModuleId { krate: *crate_id, local_id: module_id }, - location, - ); - - context.def_map_mut(crate_id).unwrap() - .modules_mut()[module_id.0] - .declare_function( - func.name_ident().clone(), func_id - ).expect( - "Failed to declare the autogenerated compute_note_hash_and_nullifier function, likely due to a duplicate definition. See https://github.com/AztecProtocol/aztec-packages/issues/4647." - ); - - collected_functions - .iter_mut() - .find(|fns| fns.file_id == file_id) - .expect("ICE: no functions found in contract file") - .push_fn(module_id, func_id, func.clone()); - - Ok(()) -} - -// Fetches the name of all structs that implement trait_name, both in the current crate and all of its dependencies. -fn fetch_struct_trait_impls( - context: &mut HirContext, - unresolved_traits_impls: &[UnresolvedTraitImpl], - trait_name: &str, -) -> Vec { - let mut struct_typenames: Vec = Vec::new(); - - // These structs can be declared in either external crates or the current one. External crates that contain - // dependencies have already been processed and resolved, but are available here via the NodeInterner. Note that - // crates on which the current crate does not depend on may not have been processed, and will be ignored. - for trait_impl_id in 0..context.def_interner.next_trait_impl_id().0 { - let trait_impl = &context.def_interner.get_trait_implementation(TraitImplId(trait_impl_id)); - - if trait_impl.borrow().ident.0.contents == *trait_name { - if let Type::Struct(s, _) = &trait_impl.borrow().typ { - struct_typenames.push(s.borrow().name.0.contents.clone()); - } else { - panic!("Found impl for {} on non-Struct", trait_name); - } - } - } - - // This crate's traits and impls have not yet been resolved, so we look for impls in unresolved_trait_impls. - struct_typenames.extend( - unresolved_traits_impls - .iter() - .filter(|trait_impl| { - trait_impl - .trait_path - .segments - .last() - .expect("ICE: empty trait_impl path") - .0 - .contents - == *trait_name - }) - .filter_map(|trait_impl| match &trait_impl.object_type.typ { - UnresolvedTypeData::Named(path, _, _) => { - Some(path.segments.last().unwrap().0.contents.clone()) - } - _ => None, - }), - ); - - struct_typenames -} - -fn generate_compute_note_hash_and_nullifier(note_types: &Vec) -> NoirFunction { - let function_source = generate_compute_note_hash_and_nullifier_source(note_types); - - let (function_ast, errors) = parse_program(&function_source); - if !errors.is_empty() { - dbg!(errors.clone()); - } - assert_eq!(errors.len(), 0, "Failed to parse Noir macro code. This is either a bug in the compiler or the Noir macro code"); - - let mut function_ast = function_ast.into_sorted(); - function_ast.functions.remove(0) -} - -fn generate_compute_note_hash_and_nullifier_source(note_types: &Vec) -> String { - // TODO(#4649): The serialized_note parameter is a fixed-size array, but we don't know what length it should have. - // For now we hardcode it to 20, which is the same as MAX_NOTE_FIELDS_LENGTH. - - if note_types.is_empty() { - // TODO(#4520): Even if the contract does not include any notes, other parts of the stack expect for this - // function to exist, so we include a dummy version. We likely should error out here instead. - " - unconstrained fn compute_note_hash_and_nullifier( - contract_address: AztecAddress, - nonce: Field, - storage_slot: Field, - note_type_id: Field, - serialized_note: [Field; 20] - ) -> pub [Field; 4] { - [0, 0, 0, 0] - }" - .to_string() - } else { - // For contracts that include notes we do a simple if-else chain comparing note_type_id with the different - // get_note_type_id of each of the note types. - - let if_statements: Vec = note_types.iter().map(|note_type| format!( - "if (note_type_id == {0}::get_note_type_id()) {{ - note_utils::compute_note_hash_and_nullifier({0}::deserialize_content, note_header, serialized_note) - }}" - , note_type)).collect(); - - // TODO(#4520): error out on the else instead of returning a zero array - let full_if_statement = if_statements.join(" else ") - + " - else { - [0, 0, 0, 0] - }"; - - format!( - " - unconstrained fn compute_note_hash_and_nullifier( - contract_address: AztecAddress, - nonce: Field, - storage_slot: Field, - note_type_id: Field, - serialized_note: [Field; 20] - ) -> pub [Field; 4] {{ - let note_header = NoteHeader::new(contract_address, nonce, storage_slot); - - {} - }}", - full_if_statement - ) - } +) -> Result<(), (AztecMacroError, FileId)> { + transform_events(crate_id, context)?; + assign_storage_slots(crate_id, context) } diff --git a/aztec_macros/src/transforms/compute_note_hash_and_nullifier.rs b/aztec_macros/src/transforms/compute_note_hash_and_nullifier.rs new file mode 100644 index 00000000000..1f5681ed470 --- /dev/null +++ b/aztec_macros/src/transforms/compute_note_hash_and_nullifier.rs @@ -0,0 +1,195 @@ +use noirc_errors::{Location, Span}; +use noirc_frontend::{ + graph::CrateId, + hir::{ + def_collector::dc_crate::{UnresolvedFunctions, UnresolvedTraitImpl}, + def_map::{LocalModuleId, ModuleId}, + }, + macros_api::{FileId, HirContext, MacroError}, + node_interner::FuncId, + parse_program, FunctionReturnType, ItemVisibility, NoirFunction, UnresolvedTypeData, +}; + +use crate::utils::hir_utils::fetch_struct_trait_impls; + +// Check if "compute_note_hash_and_nullifier(AztecAddress,Field,Field,Field,[Field; N]) -> [Field; 4]" is defined +fn check_for_compute_note_hash_and_nullifier_definition( + functions_data: &[(LocalModuleId, FuncId, NoirFunction)], + module_id: LocalModuleId, +) -> bool { + functions_data.iter().filter(|func_data| func_data.0 == module_id).any(|func_data| { + func_data.2.def.name.0.contents == "compute_note_hash_and_nullifier" + && func_data.2.def.parameters.len() == 5 + && match &func_data.2.def.parameters[0].typ.typ { + UnresolvedTypeData::Named(path, _, _) => path.segments.last().unwrap().0.contents == "AztecAddress", + _ => false, + } + && func_data.2.def.parameters[1].typ.typ == UnresolvedTypeData::FieldElement + && func_data.2.def.parameters[2].typ.typ == UnresolvedTypeData::FieldElement + && func_data.2.def.parameters[3].typ.typ == UnresolvedTypeData::FieldElement + // checks if the 5th parameter is an array and the Box in + // Array(Option, Box) contains only fields + && match &func_data.2.def.parameters[4].typ.typ { + UnresolvedTypeData::Array(_, inner_type) => { + matches!(inner_type.typ, UnresolvedTypeData::FieldElement) + }, + _ => false, + } + // We check the return type the same way as we did the 5th parameter + && match &func_data.2.def.return_type { + FunctionReturnType::Default(_) => false, + FunctionReturnType::Ty(unresolved_type) => { + match &unresolved_type.typ { + UnresolvedTypeData::Array(_, inner_type) => { + matches!(inner_type.typ, UnresolvedTypeData::FieldElement) + }, + _ => false, + } + } + } + }) +} + +pub fn inject_compute_note_hash_and_nullifier( + crate_id: &CrateId, + context: &mut HirContext, + unresolved_traits_impls: &[UnresolvedTraitImpl], + collected_functions: &mut [UnresolvedFunctions], +) -> Result<(), (MacroError, FileId)> { + // We first fetch modules in this crate which correspond to contracts, along with their file id. + let contract_module_file_ids: Vec<(LocalModuleId, FileId)> = context + .def_map(crate_id) + .expect("ICE: Missing crate in def_map") + .modules() + .iter() + .filter(|(_, module)| module.is_contract) + .map(|(idx, module)| (LocalModuleId(idx), module.location.file)) + .collect(); + + // If the current crate does not contain a contract module we simply skip it. + if contract_module_file_ids.is_empty() { + return Ok(()); + } else if contract_module_file_ids.len() != 1 { + panic!("Found multiple contracts in the same crate"); + } + + let (module_id, file_id) = contract_module_file_ids[0]; + + // If compute_note_hash_and_nullifier is already defined by the user, we skip auto-generation in order to provide an + // escape hatch for this mechanism. + // TODO(#4647): improve this diagnosis and error messaging. + if collected_functions.iter().any(|coll_funcs_data| { + check_for_compute_note_hash_and_nullifier_definition(&coll_funcs_data.functions, module_id) + }) { + return Ok(()); + } + + // In order to implement compute_note_hash_and_nullifier, we need to know all of the different note types the + // contract might use. These are the types that implement the NoteInterface trait, which provides the + // get_note_type_id function. + let note_types = fetch_struct_trait_impls(context, unresolved_traits_impls, "NoteInterface"); + + // We can now generate a version of compute_note_hash_and_nullifier tailored for the contract in this crate. + let func = generate_compute_note_hash_and_nullifier(¬e_types); + + // And inject the newly created function into the contract. + + // TODO(#4373): We don't have a reasonable location for the source code of this autogenerated function, so we simply + // pass an empty span. This function should not produce errors anyway so this should not matter. + let location = Location::new(Span::empty(0), file_id); + + // These are the same things the ModCollector does when collecting functions: we push the function to the + // NodeInterner, declare it in the module (which checks for duplicate definitions), and finally add it to the list + // on collected but unresolved functions. + + let func_id = context.def_interner.push_empty_fn(); + context.def_interner.push_function( + func_id, + &func.def, + ModuleId { krate: *crate_id, local_id: module_id }, + location, + ); + + context.def_map_mut(crate_id).unwrap() + .modules_mut()[module_id.0] + .declare_function( + func.name_ident().clone(), ItemVisibility::Public, func_id + ).expect( + "Failed to declare the autogenerated compute_note_hash_and_nullifier function, likely due to a duplicate definition. See https://github.com/AztecProtocol/aztec-packages/issues/4647." + ); + + collected_functions + .iter_mut() + .find(|fns| fns.file_id == file_id) + .expect("ICE: no functions found in contract file") + .push_fn(module_id, func_id, func.clone()); + + Ok(()) +} + +fn generate_compute_note_hash_and_nullifier(note_types: &[String]) -> NoirFunction { + let function_source = generate_compute_note_hash_and_nullifier_source(note_types); + + let (function_ast, errors) = parse_program(&function_source); + if !errors.is_empty() { + dbg!(errors.clone()); + } + assert_eq!(errors.len(), 0, "Failed to parse Noir macro code. This is either a bug in the compiler or the Noir macro code"); + + let mut function_ast = function_ast.into_sorted(); + function_ast.functions.remove(0) +} + +fn generate_compute_note_hash_and_nullifier_source(note_types: &[String]) -> String { + // TODO(#4649): The serialized_note parameter is a fixed-size array, but we don't know what length it should have. + // For now we hardcode it to 20, which is the same as MAX_NOTE_FIELDS_LENGTH. + + if note_types.is_empty() { + // Even if the contract does not include any notes, other parts of the stack expect for this function to exist, + // so we include a dummy version. + " + unconstrained fn compute_note_hash_and_nullifier( + contract_address: AztecAddress, + nonce: Field, + storage_slot: Field, + note_type_id: Field, + serialized_note: [Field; 20] + ) -> pub [Field; 4] { + assert(false, \"This contract does not use private notes\"); + [0, 0, 0, 0] + }" + .to_string() + } else { + // For contracts that include notes we do a simple if-else chain comparing note_type_id with the different + // get_note_type_id of each of the note types. + + let if_statements: Vec = note_types.iter().map(|note_type| format!( + "if (note_type_id == {0}::get_note_type_id()) {{ + dep::aztec::note::utils::compute_note_hash_and_nullifier({0}::deserialize_content, note_header, serialized_note) + }}" + , note_type)).collect(); + + let full_if_statement = if_statements.join(" else ") + + " + else { + assert(false, \"Unknown note type ID\"); + [0, 0, 0, 0] + }"; + + format!( + " + unconstrained fn compute_note_hash_and_nullifier( + contract_address: AztecAddress, + nonce: Field, + storage_slot: Field, + note_type_id: Field, + serialized_note: [Field; 20] + ) -> pub [Field; 4] {{ + let note_header = dep::aztec::prelude::NoteHeader::new(contract_address, nonce, storage_slot); + + {} + }}", + full_if_statement + ) + } +} diff --git a/aztec_macros/src/transforms/events.rs b/aztec_macros/src/transforms/events.rs new file mode 100644 index 00000000000..e7e39ed29ba --- /dev/null +++ b/aztec_macros/src/transforms/events.rs @@ -0,0 +1,182 @@ +use iter_extended::vecmap; +use noirc_errors::Span; +use noirc_frontend::{ + graph::CrateId, + macros_api::{ + BlockExpression, FileId, HirContext, HirExpression, HirLiteral, HirStatement, NodeInterner, + NoirStruct, PathKind, StatementKind, StructId, StructType, Type, TypeImpl, + UnresolvedTypeData, + }, + token::SecondaryAttribute, + ExpressionKind, FunctionDefinition, FunctionReturnType, ItemVisibility, Literal, NoirFunction, + Visibility, +}; + +use crate::{ + chained_dep, + utils::{ + ast_utils::{ + call, expression, ident, ident_path, make_statement, make_type, path, variable_path, + }, + constants::SIGNATURE_PLACEHOLDER, + errors::AztecMacroError, + hir_utils::{collect_crate_structs, signature_of_type}, + }, +}; + +/// Generates the impl for an event selector +/// +/// Inserts the following code: +/// ```noir +/// impl SomeStruct { +/// fn selector() -> FunctionSelector { +/// aztec::protocol_types::abis::function_selector::FunctionSelector::from_signature("SIGNATURE_PLACEHOLDER") +/// } +/// } +/// ``` +/// +/// This allows developers to emit events without having to write the signature of the event every time they emit it. +/// The signature cannot be known at this point since types are not resolved yet, so we use a signature placeholder. +/// It'll get resolved after by transforming the HIR. +pub fn generate_selector_impl(structure: &NoirStruct) -> TypeImpl { + let struct_type = + make_type(UnresolvedTypeData::Named(path(structure.name.clone()), vec![], true)); + + let selector_path = + chained_dep!("aztec", "protocol_types", "abis", "function_selector", "FunctionSelector"); + let mut from_signature_path = selector_path.clone(); + from_signature_path.segments.push(ident("from_signature")); + + let selector_fun_body = BlockExpression { + statements: vec![make_statement(StatementKind::Expression(call( + variable_path(from_signature_path), + vec![expression(ExpressionKind::Literal(Literal::Str( + SIGNATURE_PLACEHOLDER.to_string(), + )))], + )))], + }; + + // Define `FunctionSelector` return type + let return_type = + FunctionReturnType::Ty(make_type(UnresolvedTypeData::Named(selector_path, vec![], true))); + + let mut selector_fn_def = FunctionDefinition::normal( + &ident("selector"), + &vec![], + &[], + &selector_fun_body, + &[], + &return_type, + ); + + selector_fn_def.visibility = ItemVisibility::Public; + + // Seems to be necessary on contract modules + selector_fn_def.return_visibility = Visibility::Public; + + TypeImpl { + object_type: struct_type, + type_span: structure.span, + generics: vec![], + methods: vec![(NoirFunction::normal(selector_fn_def), Span::default())], + } +} + +/// Computes the signature for a resolved event type. +/// It has the form 'EventName(Field,(Field),[u8;2])' +fn event_signature(event: &StructType) -> String { + let fields = vecmap(event.get_fields(&[]), |(_, typ)| signature_of_type(&typ)); + format!("{}({})", event.name.0.contents, fields.join(",")) +} + +/// Substitutes the signature literal that was introduced in the selector method previously with the actual signature. +fn transform_event( + struct_id: StructId, + interner: &mut NodeInterner, +) -> Result<(), (AztecMacroError, FileId)> { + let struct_type = interner.get_struct(struct_id); + let selector_id = interner + .lookup_method(&Type::Struct(struct_type.clone(), vec![]), struct_id, "selector", false) + .ok_or_else(|| { + let error = AztecMacroError::EventError { + span: struct_type.borrow().location.span, + message: "Selector method not found".to_owned(), + }; + (error, struct_type.borrow().location.file) + })?; + let selector_function = interner.function(&selector_id); + + let compute_selector_statement = interner.statement( + selector_function.block(interner).statements().first().ok_or_else(|| { + let error = AztecMacroError::EventError { + span: struct_type.borrow().location.span, + message: "Compute selector statement not found".to_owned(), + }; + (error, struct_type.borrow().location.file) + })?, + ); + + let compute_selector_expression = match compute_selector_statement { + HirStatement::Expression(expression_id) => match interner.expression(&expression_id) { + HirExpression::Call(hir_call_expression) => Some(hir_call_expression), + _ => None, + }, + _ => None, + } + .ok_or_else(|| { + let error = AztecMacroError::EventError { + span: struct_type.borrow().location.span, + message: "Compute selector statement is not a call expression".to_owned(), + }; + (error, struct_type.borrow().location.file) + })?; + + let first_arg_id = compute_selector_expression.arguments.first().ok_or_else(|| { + let error = AztecMacroError::EventError { + span: struct_type.borrow().location.span, + message: "Compute selector statement is not a call expression".to_owned(), + }; + (error, struct_type.borrow().location.file) + })?; + + match interner.expression(first_arg_id) { + HirExpression::Literal(HirLiteral::Str(signature)) + if signature == SIGNATURE_PLACEHOLDER => + { + let selector_literal_id = *first_arg_id; + + let structure = interner.get_struct(struct_id); + let signature = event_signature(&structure.borrow()); + interner.update_expression(selector_literal_id, |expr| { + *expr = HirExpression::Literal(HirLiteral::Str(signature.clone())); + }); + + // Also update the type! It might have a different length now than the placeholder. + interner.push_expr_type( + selector_literal_id, + Type::String(Box::new(Type::Constant(signature.len() as u64))), + ); + Ok(()) + } + _ => Err(( + AztecMacroError::EventError { + span: struct_type.borrow().location.span, + message: "Signature placeholder literal does not match".to_owned(), + }, + struct_type.borrow().location.file, + )), + } +} + +pub fn transform_events( + crate_id: &CrateId, + context: &mut HirContext, +) -> Result<(), (AztecMacroError, FileId)> { + for struct_id in collect_crate_structs(crate_id, context) { + let attributes = context.def_interner.struct_attributes(&struct_id); + if attributes.iter().any(|attr| matches!(attr, SecondaryAttribute::Event)) { + transform_event(struct_id, &mut context.def_interner)?; + } + } + Ok(()) +} diff --git a/aztec_macros/src/transforms/functions.rs b/aztec_macros/src/transforms/functions.rs new file mode 100644 index 00000000000..9844abc30fe --- /dev/null +++ b/aztec_macros/src/transforms/functions.rs @@ -0,0 +1,722 @@ +use convert_case::{Case, Casing}; +use noirc_errors::Span; +use noirc_frontend::{ + macros_api::FieldElement, BlockExpression, ConstrainKind, ConstrainStatement, Distinctness, + Expression, ExpressionKind, ForLoopStatement, ForRange, FunctionReturnType, Ident, Literal, + NoirFunction, Param, PathKind, Pattern, Signedness, Statement, StatementKind, UnresolvedType, + UnresolvedTypeData, Visibility, +}; + +use crate::{ + chained_dep, chained_path, + utils::{ + ast_utils::{ + assignment, call, cast, expression, ident, ident_path, index_array, + index_array_variable, make_eq, make_statement, make_type, member_access, method_call, + mutable_assignment, mutable_reference, path, return_type, variable, variable_ident, + variable_path, + }, + errors::AztecMacroError, + }, +}; + +// If it does, it will insert the following things: +/// - A new Input that is provided for a kernel app circuit, named: {Public/Private}ContextInputs +/// - Hashes all of the function input variables +/// - This instantiates a helper function +pub fn transform_function( + ty: &str, + func: &mut NoirFunction, + storage_defined: bool, + is_initializer: bool, + insert_init_check: bool, + is_internal: bool, +) -> Result<(), AztecMacroError> { + let context_name = format!("{}Context", ty); + let inputs_name = format!("{}ContextInputs", ty); + let return_type_name = format!("{}CircuitPublicInputs", ty); + let is_avm = ty == "Avm"; + + // Add check that msg sender equals this address and flag function as internal + if is_internal { + let is_internal_check = create_internal_check(func.name()); + func.def.body.statements.insert(0, is_internal_check); + } + + // Add initialization check + if insert_init_check { + let init_check = create_init_check(); + func.def.body.statements.insert(0, init_check); + } + + // Add assertion for initialization arguments and sender + if is_initializer { + func.def.body.statements.insert(0, create_assert_initializer()); + } + + // Add access to the storage struct + if storage_defined { + let storage_def = abstract_storage(&ty.to_lowercase(), false); + func.def.body.statements.insert(0, storage_def); + } + + // Insert the context creation as the first action + let create_context = if !is_avm { + create_context(&context_name, &func.def.parameters)? + } else { + create_context_avm()? + }; + func.def.body.statements.splice(0..0, (create_context).iter().cloned()); + + // Add the inputs to the params + let input = create_inputs(&inputs_name); + func.def.parameters.insert(0, input); + + // Abstract return types such that they get added to the kernel's return_values + if !is_avm { + if let Some(return_values) = abstract_return_values(func) { + // In case we are pushing return values to the context, we remove the statement that originated it + // This avoids running duplicate code, since blocks like if/else can be value returning statements + func.def.body.statements.pop(); + // Add the new return statement + func.def.body.statements.push(return_values); + } + } + + // Before returning mark the contract as initialized + if is_initializer { + let mark_initialized = create_mark_as_initialized(); + func.def.body.statements.push(mark_initialized); + } + + // Push the finish method call to the end of the function + if !is_avm { + let finish_def = create_context_finish(); + func.def.body.statements.push(finish_def); + } + + // The AVM doesn't need a return type yet. + if !is_avm { + let return_type = create_return_type(&return_type_name); + func.def.return_type = return_type; + func.def.return_visibility = Visibility::Public; + } + + // Distinct return types are only required for private functions + // Public functions should have unconstrained auto-inferred + match ty { + "Private" => func.def.return_distinctness = Distinctness::Distinct, + "Public" | "Avm" => func.def.is_unconstrained = true, + _ => (), + } + + Ok(()) +} + +/// Transform Unconstrained +/// +/// Inserts the following code at the beginning of an unconstrained function +/// ```noir +/// let storage = Storage::init(Context::none()); +/// ``` +/// +/// This will allow developers to access their contract' storage struct in unconstrained functions +pub fn transform_unconstrained(func: &mut NoirFunction) { + func.def.body.statements.insert(0, abstract_storage("Unconstrained", true)); +} + +/// Helper function that returns what the private context would look like in the ast +/// This should make it available to be consumed within aztec private annotated functions. +/// +/// The replaced code: +/// ```noir +/// /// Before +/// fn foo(inputs: PrivateContextInputs) { +/// // ... +/// } +/// +/// /// After +/// #[aztec(private)] +/// fn foo() { +/// // ... +/// } +fn create_inputs(ty: &str) -> Param { + let context_ident = ident("inputs"); + let context_pattern = Pattern::Identifier(context_ident); + + let path_snippet = ty.to_case(Case::Snake); // e.g. private_context_inputs + let type_path = chained_dep!("aztec", "context", "inputs", &path_snippet, ty); + + let context_type = make_type(UnresolvedTypeData::Named(type_path, vec![], true)); + let visibility = Visibility::Private; + + Param { pattern: context_pattern, typ: context_type, visibility, span: Span::default() } +} + +/// Creates an initialization check to ensure that the contract has been initialized, meant to +/// be injected as the first statement of any function after the context has been created. +/// +/// ```noir +/// assert_is_initialized(&mut context); +/// ``` +fn create_init_check() -> Statement { + make_statement(StatementKind::Expression(call( + variable_path(chained_dep!("aztec", "initializer", "assert_is_initialized")), + vec![mutable_reference("context")], + ))) +} + +/// Creates a call to mark_as_initialized which emits the initialization nullifier, meant to +/// be injected as the last statement before returning in a constructor. +/// +/// ```noir +/// mark_as_initialized(&mut context); +/// ``` +fn create_mark_as_initialized() -> Statement { + make_statement(StatementKind::Expression(call( + variable_path(chained_dep!("aztec", "initializer", "mark_as_initialized")), + vec![mutable_reference("context")], + ))) +} + +/// Creates a check for internal functions ensuring that the caller is self. +/// +/// ```noir +/// assert(context.msg_sender() == context.this_address(), "Function can only be called internally"); +/// ``` +fn create_internal_check(fname: &str) -> Statement { + make_statement(StatementKind::Constrain(ConstrainStatement( + make_eq( + method_call(variable("context"), "msg_sender", vec![]), + method_call(variable("context"), "this_address", vec![]), + ), + Some(expression(ExpressionKind::Literal(Literal::Str(format!( + "Function {} can only be called internally", + fname + ))))), + ConstrainKind::Assert, + ))) +} + +/// Creates a call to assert_initialization_matches_address_preimage to be inserted +/// in the initializer. Checks that the args and sender to the initializer match the +/// commitments from the address preimage. +/// +/// ```noir +/// assert_initialization_matches_address_preimage(context); +/// ``` +fn create_assert_initializer() -> Statement { + make_statement(StatementKind::Expression(call( + variable_path(chained_dep!( + "aztec", + "initializer", + "assert_initialization_matches_address_preimage" + )), + vec![variable("context")], + ))) +} + +/// Creates the private context object to be accessed within the function, the parameters need to be extracted to be +/// appended into the args hash object. +/// +/// The replaced code: +/// ```noir +/// #[aztec(private)] +/// fn foo(structInput: SomeStruct, arrayInput: [u8; 10], fieldInput: Field) -> Field { +/// // Create the bounded vec object +/// let mut serialized_args = BoundedVec::new(); +/// +/// // struct inputs call serialize on them to add an array of fields +/// serialized_args.extend_from_array(structInput.serialize()); +/// +/// // Array inputs are iterated over and each element is added to the bounded vec (as a field) +/// for i in 0..arrayInput.len() { +/// serialized_args.push(arrayInput[i] as Field); +/// } +/// // Field inputs are added to the bounded vec +/// serialized_args.push({ident}); +/// +/// // Create the context +/// // The inputs (injected by this `create_inputs`) and completed hash object are passed to the context +/// let mut context = PrivateContext::new(inputs, hash_args(serialized_args)); +/// } +/// ``` +fn create_context(ty: &str, params: &[Param]) -> Result, AztecMacroError> { + let mut injected_expressions: Vec = vec![]; + + // `let mut serialized_args = BoundedVec::new();` + let let_serialized_args = mutable_assignment( + "serialized_args", // Assigned to + call( + variable_path(chained_dep!("std", "collections", "bounded_vec", "BoundedVec", "new")), // Path + vec![], // args + ), + ); + + // Completes: `let mut serialized_args = BoundedVec::new();` + injected_expressions.push(let_serialized_args); + + // Iterate over each of the function parameters, adding to them to the bounded vec + for Param { pattern, typ, span, .. } in params { + match pattern { + Pattern::Identifier(identifier) => { + // Match the type to determine the padding to do + let unresolved_type = &typ.typ; + let expression = match unresolved_type { + // `serialized_args.extend_from_array({ident}.serialize())` + UnresolvedTypeData::Named(..) => add_struct_to_serialized_args(identifier), + UnresolvedTypeData::Array(_, arr_type) => { + add_array_to_serialized_args(identifier, arr_type) + } + // `serialized_args.push({ident})` + UnresolvedTypeData::FieldElement => add_field_to_serialized_args(identifier), + // Add the integer to the serialized args, casted to a field + // `serialized_args.push({ident} as Field)` + UnresolvedTypeData::Integer(..) | UnresolvedTypeData::Bool => { + add_cast_to_serialized_args(identifier) + } + UnresolvedTypeData::String(..) => { + let (var_bytes, id) = str_to_bytes(identifier); + injected_expressions.push(var_bytes); + add_array_to_serialized_args( + &id, + &UnresolvedType { + typ: UnresolvedTypeData::Integer( + Signedness::Unsigned, + noirc_frontend::IntegerBitSize::ThirtyTwo, + ), + span: None, + }, + ) + } + _ => { + return Err(AztecMacroError::UnsupportedFunctionArgumentType { + typ: unresolved_type.clone(), + span: *span, + }) + } + }; + injected_expressions.push(expression); + } + _ => todo!(), // Maybe unreachable? + } + } + + // Create the inputs to the context + let inputs_expression = variable("inputs"); + // `hash_args(serialized_args)` + let hash_call = call( + variable_path(chained_dep!("aztec", "hash", "hash_args")), // variable + vec![variable("serialized_args")], // args + ); + + let path_snippet = ty.to_case(Case::Snake); // e.g. private_context + + // let mut context = {ty}::new(inputs, hash); + let let_context = mutable_assignment( + "context", // Assigned to + call( + variable_path(chained_dep!("aztec", "context", &path_snippet, ty, "new")), // Path + vec![inputs_expression, hash_call], // args + ), + ); + injected_expressions.push(let_context); + + // Return all expressions that will be injected by the hasher + Ok(injected_expressions) +} + +/// Creates the private context object to be accessed within the function, the parameters need to be extracted to be +/// appended into the args hash object. +/// +/// The replaced code: +/// ```noir +/// #[aztec(public-vm)] +/// fn foo(inputs: AvmContextInputs, ...) -> Field { +/// let mut context = AvmContext::new(inputs); +/// } +/// ``` +fn create_context_avm() -> Result, AztecMacroError> { + let mut injected_expressions: Vec = vec![]; + + // Create the inputs to the context + let ty = "AvmContext"; + let inputs_expression = variable("inputs"); + let path_snippet = ty.to_case(Case::Snake); // e.g. private_context + + // let mut context = {ty}::new(inputs, hash); + let let_context = mutable_assignment( + "context", // Assigned to + call( + variable_path(chained_dep!("aztec", "context", &path_snippet, ty, "new")), // Path + vec![inputs_expression], // args + ), + ); + injected_expressions.push(let_context); + + // Return all expressions that will be injected by the hasher + Ok(injected_expressions) +} + +/// Abstract Return Type +/// +/// This function intercepts the function's current return type and replaces it with pushes +/// To the kernel +/// +/// The replaced code: +/// ```noir +/// /// Before +/// #[aztec(private)] +/// fn foo() -> protocol_types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs { +/// // ... +/// let my_return_value: Field = 10; +/// context.return_values.push(my_return_value); +/// } +/// +/// /// After +/// #[aztec(private)] +/// fn foo() -> Field { +/// // ... +/// let my_return_value: Field = 10; +/// my_return_value +/// } +/// ``` +/// Similarly; Structs will be pushed to the context, after serialize() is called on them. +/// Arrays will be iterated over and each element will be pushed to the context. +/// Any primitive type that can be cast will be casted to a field and pushed to the context. +fn abstract_return_values(func: &NoirFunction) -> Option { + let current_return_type = func.return_type().typ; + let last_statement = func.def.body.statements.last()?; + + // TODO: (length, type) => We can limit the size of the array returned to be limited by kernel size + // Doesn't need done until we have settled on a kernel size + // TODO: support tuples here and in inputs -> convert into an issue + // Check if the return type is an expression, if it is, we can handle it + match last_statement { + Statement { kind: StatementKind::Expression(expression), .. } => { + match current_return_type { + // Call serialize on structs, push the whole array, calling push_array + UnresolvedTypeData::Named(..) => Some(make_struct_return_type(expression.clone())), + UnresolvedTypeData::Array(..) => Some(make_array_return_type(expression.clone())), + // Cast these types to a field before pushing + UnresolvedTypeData::Bool | UnresolvedTypeData::Integer(..) => { + Some(make_castable_return_type(expression.clone())) + } + UnresolvedTypeData::FieldElement => Some(make_return_push(expression.clone())), + _ => None, + } + } + _ => None, + } +} + +/// Abstract storage +/// +/// For private functions: +/// ```noir +/// #[aztec(private)] +/// fn lol() { +/// let storage = Storage::init(Context::private(context)); +/// } +/// ``` +/// +/// For public functions: +/// ```noir +/// #[aztec(public)] +/// fn lol() { +/// let storage = Storage::init(Context::public(context)); +/// } +/// ``` +/// +/// For unconstrained functions: +/// ```noir +/// unconstrained fn lol() { +/// let storage = Storage::init(Context::none()); +/// } +fn abstract_storage(typ: &str, unconstrained: bool) -> Statement { + let init_context_call = if unconstrained { + call( + variable_path(chained_dep!("aztec", "context", "Context", "none")), // Path + vec![], // args + ) + } else { + call( + variable_path(chained_dep!("aztec", "context", "Context", typ)), // Path + vec![mutable_reference("context")], // args + ) + }; + + assignment( + "storage", // Assigned to + call( + variable_path(chained_path!("Storage", "init")), // Path + vec![init_context_call], // args + ), + ) +} + +/// Context Return Values +/// +/// Creates an instance to the context return values +/// ```noir +/// `context.return_values` +/// ``` +fn context_return_values() -> Expression { + member_access("context", "return_values") +} + +/// Make return Push +/// +/// Translates to: +/// `context.return_values.push({push_value})` +fn make_return_push(push_value: Expression) -> Statement { + make_statement(StatementKind::Semi(method_call( + context_return_values(), + "push", + vec![push_value], + ))) +} + +/// Make Return push array +/// +/// Translates to: +/// `context.return_values.extend_from_array({push_value})` +fn make_return_extend_from_array(push_value: Expression) -> Statement { + make_statement(StatementKind::Semi(method_call( + context_return_values(), + "extend_from_array", + vec![push_value], + ))) +} + +/// Make struct return type +/// +/// Translates to: +/// ```noir +/// `context.return_values.extend_from_array({push_value}.serialize())` +fn make_struct_return_type(expression: Expression) -> Statement { + let serialized_call = method_call( + expression, // variable + "serialize", // method name + vec![], // args + ); + make_return_extend_from_array(serialized_call) +} + +/// Make array return type +/// +/// Translates to: +/// ```noir +/// for i in 0..{ident}.len() { +/// context.return_values.push({ident}[i] as Field) +/// } +/// ``` +fn make_array_return_type(expression: Expression) -> Statement { + let inner_cast_expression = + cast(index_array_variable(expression.clone(), "i"), UnresolvedTypeData::FieldElement); + let assignment = make_statement(StatementKind::Semi(method_call( + context_return_values(), // variable + "push", // method name + vec![inner_cast_expression], + ))); + + create_loop_over(expression, vec![assignment]) +} + +/// Castable return type +/// +/// Translates to: +/// ```noir +/// context.return_values.push({ident} as Field) +/// ``` +fn make_castable_return_type(expression: Expression) -> Statement { + // Cast these types to a field before pushing + let cast_expression = cast(expression, UnresolvedTypeData::FieldElement); + make_return_push(cast_expression) +} + +/// Create Return Type +/// +/// Public functions return protocol_types::abis::public_circuit_public_inputs::PublicCircuitPublicInputs while +/// private functions return protocol_types::abis::private_circuit_public_inputs::::PrivateCircuitPublicInputs +/// +/// This call constructs an ast token referencing the above types +/// The name is set in the function above `transform`, hence the +/// whole token name is passed in +/// +/// The replaced code: +/// ```noir +/// +/// /// Before +/// fn foo() -> protocol_types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs { +/// // ... +/// } +/// +/// /// After +/// #[aztec(private)] +/// fn foo() { +/// // ... +/// } +fn create_return_type(ty: &str) -> FunctionReturnType { + let path_snippet = ty.to_case(Case::Snake); // e.g. private_circuit_public_inputs or public_circuit_public_inputs + let return_path = chained_dep!("aztec", "protocol_types", "abis", &path_snippet, ty); + return_type(return_path) +} + +/// Create Context Finish +/// +/// Each aztec function calls `context.finish()` at the end of a function +/// to return values required by the kernel. +/// +/// The replaced code: +/// ```noir +/// /// Before +/// fn foo() -> protocol_types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs { +/// // ... +/// context.finish() +/// } +/// +/// /// After +/// #[aztec(private)] +/// fn foo() { +/// // ... +/// } +fn create_context_finish() -> Statement { + let method_call = method_call( + variable("context"), // variable + "finish", // method name + vec![], // args + ); + make_statement(StatementKind::Expression(method_call)) +} + +// +// Methods to create hash_args inputs +// + +fn add_struct_to_serialized_args(identifier: &Ident) -> Statement { + // If this is a struct, we call serialize and add the array to the serialized args + let serialized_call = method_call( + variable_path(path(identifier.clone())), // variable + "serialize", // method name + vec![], // args + ); + + make_statement(StatementKind::Semi(method_call( + variable("serialized_args"), // variable + "extend_from_array", // method name + vec![serialized_call], // args + ))) +} + +fn str_to_bytes(identifier: &Ident) -> (Statement, Ident) { + // let identifier_as_bytes = identifier.as_bytes(); + let var = variable_ident(identifier.clone()); + let contents = if let ExpressionKind::Variable(p) = &var.kind { + p.segments.first().cloned().unwrap_or_else(|| panic!("No segments")).0.contents + } else { + panic!("Unexpected identifier type") + }; + let bytes_name = format!("{}_bytes", contents); + let var_bytes = assignment(&bytes_name, method_call(var, "as_bytes", vec![])); + let id = Ident::new(bytes_name, Span::default()); + + (var_bytes, id) +} + +fn create_loop_over(var: Expression, loop_body: Vec) -> Statement { + // If this is an array of primitive types (integers / fields) we can add them each to the serialized args + // casted to a field + let span = var.span; + + // `array.len()` + let end_range_expression = method_call( + var, // variable + "len", // method name + vec![], // args + ); + + // What will be looped over + + // - `serialized_args.push({ident}[i] as Field)` + let for_loop_block = + expression(ExpressionKind::Block(BlockExpression { statements: loop_body })); + + // `for i in 0..{ident}.len()` + make_statement(StatementKind::For(ForLoopStatement { + range: ForRange::Range( + expression(ExpressionKind::Literal(Literal::Integer( + FieldElement::from(i128::from(0)), + false, + ))), + end_range_expression, + ), + identifier: ident("i"), + block: for_loop_block, + span, + })) +} + +fn add_array_to_serialized_args(identifier: &Ident, arr_type: &UnresolvedType) -> Statement { + // If this is an array of primitive types (integers / fields) we can add them each to the serialized_args + // casted to a field + + // Wrap in the semi thing - does that mean ended with semi colon? + // `serialized_args.push({ident}[i] as Field)` + + let arr_index = index_array(identifier.clone(), "i"); + let (add_expression, vec_method_name) = match arr_type.typ { + UnresolvedTypeData::Named(..) => { + let vec_method_name = "extend_from_array".to_owned(); + let call = method_call( + // All serialize on each element + arr_index, // variable + "serialize", // method name + vec![], // args + ); + (call, vec_method_name) + } + _ => { + let vec_method_name = "push".to_owned(); + let call = cast( + arr_index, // lhs - `ident[i]` + UnresolvedTypeData::FieldElement, // cast to - `as Field` + ); + (call, vec_method_name) + } + }; + + let block_statement = make_statement(StatementKind::Semi(method_call( + variable("serialized_args"), // variable + &vec_method_name, // method name + vec![add_expression], + ))); + + create_loop_over(variable_ident(identifier.clone()), vec![block_statement]) +} + +fn add_field_to_serialized_args(identifier: &Ident) -> Statement { + // `serialized_args.push({ident})` + let ident = variable_path(path(identifier.clone())); + make_statement(StatementKind::Semi(method_call( + variable("serialized_args"), // variable + "push", // method name + vec![ident], // args + ))) +} + +fn add_cast_to_serialized_args(identifier: &Ident) -> Statement { + // `serialized_args.push({ident} as Field)` + // `{ident} as Field` + let cast_operation = cast( + variable_path(path(identifier.clone())), // lhs + UnresolvedTypeData::FieldElement, // rhs + ); + + // `serialized_args.push({ident} as Field)` + make_statement(StatementKind::Semi(method_call( + variable("serialized_args"), // variable + "push", // method name + vec![cast_operation], // args + ))) +} diff --git a/aztec_macros/src/transforms/mod.rs b/aztec_macros/src/transforms/mod.rs new file mode 100644 index 00000000000..5a454c75148 --- /dev/null +++ b/aztec_macros/src/transforms/mod.rs @@ -0,0 +1,5 @@ +pub mod compute_note_hash_and_nullifier; +pub mod events; +pub mod functions; +pub mod note_interface; +pub mod storage; diff --git a/aztec_macros/src/transforms/note_interface.rs b/aztec_macros/src/transforms/note_interface.rs new file mode 100644 index 00000000000..01d0272088b --- /dev/null +++ b/aztec_macros/src/transforms/note_interface.rs @@ -0,0 +1,583 @@ +use noirc_errors::Span; +use noirc_frontend::{ + parse_program, parser::SortedModule, ItemVisibility, NoirFunction, NoirStruct, PathKind, + TraitImplItem, TypeImpl, UnresolvedTypeData, UnresolvedTypeExpression, +}; +use regex::Regex; + +use crate::{ + chained_dep, + utils::{ + ast_utils::{ + check_trait_method_implemented, ident, ident_path, is_custom_attribute, make_type, + }, + errors::AztecMacroError, + }, +}; + +// Automatic implementation of most of the methods in the NoteInterface trait, guiding the user with meaningful error messages in case some +// methods must be implemented manually. +pub fn generate_note_interface_impl(module: &mut SortedModule) -> Result<(), AztecMacroError> { + // Find structs annotated with #[aztec(note)] + let annotated_note_structs = module + .types + .iter_mut() + .filter(|typ| typ.attributes.iter().any(|attr| is_custom_attribute(attr, "aztec(note)"))); + + let mut note_properties_structs = vec![]; + + for note_struct in annotated_note_structs { + // Look for the NoteInterface trait implementation for the note + let trait_impl = module + .trait_impls + .iter_mut() + .find(|trait_impl| { + if let UnresolvedTypeData::Named(struct_path, _, _) = &trait_impl.object_type.typ { + struct_path.last_segment() == note_struct.name + && trait_impl.trait_name.last_segment().0.contents == "NoteInterface" + } else { + false + } + }) + .ok_or(AztecMacroError::CouldNotImplementNoteInterface { + span: Some(note_struct.name.span()), + secondary_message: Some(format!( + "Could not find NoteInterface trait implementation for note: {}", + note_struct.name.0.contents + )), + })?; + let note_interface_impl_span: Option = trait_impl.object_type.span; + // Look for the note struct implementation, generate a default one if it doesn't exist (in order to append methods to it) + let existing_impl = module.impls.iter_mut().find(|r#impl| match &r#impl.object_type.typ { + UnresolvedTypeData::Named(path, _, _) => path.last_segment().eq(¬e_struct.name), + _ => false, + }); + let note_impl = if let Some(note_impl) = existing_impl { + note_impl + } else { + let default_impl = TypeImpl { + object_type: trait_impl.object_type.clone(), + type_span: note_struct.name.span(), + generics: vec![], + methods: vec![], + }; + module.impls.push(default_impl.clone()); + module.impls.last_mut().unwrap() + }; + // Identify the note type (struct name), its fields and its serialized length (generic param of NoteInterface trait impl) + let note_type = note_struct.name.0.contents.to_string(); + let mut note_fields = vec![]; + let note_serialized_len = match &trait_impl.trait_generics[0].typ { + UnresolvedTypeData::Named(path, _, _) => Ok(path.last_segment().0.contents.to_string()), + UnresolvedTypeData::Expression(UnresolvedTypeExpression::Constant(val, _)) => { + Ok(val.to_string()) + } + _ => Err(AztecMacroError::CouldNotImplementNoteInterface { + span: trait_impl.object_type.span, + secondary_message: Some(format!( + "Cannot find note serialization length for: {}", + note_type + )), + }), + }?; + + // Automatically inject the header field if it's not present + let (header_field_name, _) = if let Some(existing_header) = + note_struct.fields.iter().find(|(_, field_type)| match &field_type.typ { + UnresolvedTypeData::Named(path, _, _) => { + path.last_segment().0.contents == "NoteHeader" + } + _ => false, + }) { + existing_header.clone() + } else { + let generated_header = ( + ident("header"), + make_type(UnresolvedTypeData::Named( + chained_dep!("aztec", "note", "note_header", "NoteHeader"), + vec![], + false, + )), + ); + note_struct.fields.push(generated_header.clone()); + generated_header + }; + + for (field_ident, field_type) in note_struct.fields.iter() { + note_fields.push(( + field_ident.0.contents.to_string(), + field_type.typ.to_string().replace("plain::", ""), + )); + } + + if !check_trait_method_implemented(trait_impl, "serialize_content") + && !check_trait_method_implemented(trait_impl, "deserialize_content") + && !note_impl.methods.iter().any(|(func, _)| func.def.name.0.contents == "properties") + { + let note_serialize_content_fn = generate_note_serialize_content( + ¬e_type, + ¬e_fields, + ¬e_serialized_len, + &header_field_name.0.contents, + note_interface_impl_span, + )?; + trait_impl.items.push(TraitImplItem::Function(note_serialize_content_fn)); + + let note_deserialize_content_fn = generate_note_deserialize_content( + ¬e_type, + ¬e_fields, + ¬e_serialized_len, + &header_field_name.0.contents, + note_interface_impl_span, + )?; + trait_impl.items.push(TraitImplItem::Function(note_deserialize_content_fn)); + + let note_properties_struct = generate_note_properties_struct( + ¬e_type, + ¬e_fields, + &header_field_name.0.contents, + note_interface_impl_span, + )?; + note_properties_structs.push(note_properties_struct); + let note_properties_fn = generate_note_properties_fn( + ¬e_type, + ¬e_fields, + &header_field_name.0.contents, + note_interface_impl_span, + )?; + note_impl.methods.push((note_properties_fn, note_impl.type_span)); + } + + if !check_trait_method_implemented(trait_impl, "get_header") { + let get_header_fn = generate_note_get_header( + ¬e_type, + &header_field_name.0.contents, + note_interface_impl_span, + )?; + trait_impl.items.push(TraitImplItem::Function(get_header_fn)); + } + if !check_trait_method_implemented(trait_impl, "set_header") { + let set_header_fn = generate_note_set_header( + ¬e_type, + &header_field_name.0.contents, + note_interface_impl_span, + )?; + trait_impl.items.push(TraitImplItem::Function(set_header_fn)); + } + + if !check_trait_method_implemented(trait_impl, "get_note_type_id") { + let get_note_type_id_fn = + generate_note_get_type_id(¬e_type, note_interface_impl_span)?; + trait_impl.items.push(TraitImplItem::Function(get_note_type_id_fn)); + } + + if !check_trait_method_implemented(trait_impl, "compute_note_content_hash") { + let get_header_fn = + generate_compute_note_content_hash(¬e_type, note_interface_impl_span)?; + trait_impl.items.push(TraitImplItem::Function(get_header_fn)); + } + } + + module.types.extend(note_properties_structs); + Ok(()) +} + +fn generate_note_get_header( + note_type: &String, + note_header_field_name: &String, + impl_span: Option, +) -> Result { + let function_source = format!( + " + fn get_header(note: {}) -> dep::aztec::note::note_header::NoteHeader {{ + note.{} + }} + ", + note_type, note_header_field_name + ) + .to_string(); + + let (function_ast, errors) = parse_program(&function_source); + if !errors.is_empty() { + return Err(AztecMacroError::CouldNotImplementNoteInterface { + secondary_message: Some("Failed to parse Noir macro code (fn get_header). This is either a bug in the compiler or the Noir macro code".to_string()), + span: impl_span + }); + } + + let mut function_ast = function_ast.into_sorted(); + let mut noir_fn = function_ast.functions.remove(0); + noir_fn.def.span = impl_span.unwrap(); + noir_fn.def.visibility = ItemVisibility::Public; + Ok(noir_fn) +} + +fn generate_note_set_header( + note_type: &String, + note_header_field_name: &String, + impl_span: Option, +) -> Result { + let function_source = format!( + " + fn set_header(self: &mut {}, header: dep::aztec::note::note_header::NoteHeader) {{ + self.{} = header; + }} + ", + note_type, note_header_field_name + ); + + let (function_ast, errors) = parse_program(&function_source); + if !errors.is_empty() { + dbg!(errors); + return Err(AztecMacroError::CouldNotImplementNoteInterface { + secondary_message: Some("Failed to parse Noir macro code (fn set_header). This is either a bug in the compiler or the Noir macro code".to_string()), + span: impl_span + }); + } + + let mut function_ast = function_ast.into_sorted(); + let mut noir_fn = function_ast.functions.remove(0); + noir_fn.def.span = impl_span.unwrap(); + noir_fn.def.visibility = ItemVisibility::Public; + Ok(noir_fn) +} + +// Automatically generate the note type id getter method. The id itself its calculated as the concatenation +// of the conversion of the characters in the note's struct name to unsigned integers. +fn generate_note_get_type_id( + note_type: &str, + impl_span: Option, +) -> Result { + // TODO(#4519) Improve automatic note id generation and assignment + let note_id = + note_type.chars().map(|c| (c as u32).to_string()).collect::>().join(""); + let function_source = format!( + " + fn get_note_type_id() -> Field {{ + {} + }} + ", + note_id + ) + .to_string(); + + let (function_ast, errors) = parse_program(&function_source); + if !errors.is_empty() { + dbg!(errors); + return Err(AztecMacroError::CouldNotImplementNoteInterface { + secondary_message: Some("Failed to parse Noir macro code (fn get_note_type_id). This is either a bug in the compiler or the Noir macro code".to_string()), + span: impl_span + }); + } + + let mut function_ast = function_ast.into_sorted(); + let mut noir_fn = function_ast.functions.remove(0); + noir_fn.def.span = impl_span.unwrap(); + noir_fn.def.visibility = ItemVisibility::Public; + Ok(noir_fn) +} + +// Automatically generate a struct that represents the note's serialization metadata, as +// +// NoteTypeFields { +// field1: PropertySelector { index: 0, offset: 0, length: 32 }, +// field2: PropertySelector { index: 1, offset: 0, length: 32 }, +// ... +// } +// +// It assumes each field occupies an entire field and its serialized in definition order +fn generate_note_properties_struct( + note_type: &str, + note_fields: &[(String, String)], + note_header_field_name: &String, + impl_span: Option, +) -> Result { + let struct_source = + generate_note_properties_struct_source(note_type, note_fields, note_header_field_name); + + let (struct_ast, errors) = parse_program(&struct_source); + if !errors.is_empty() { + dbg!(errors); + return Err(AztecMacroError::CouldNotImplementNoteInterface { + secondary_message: Some(format!("Failed to parse Noir macro code (struct {}Properties). This is either a bug in the compiler or the Noir macro code", note_type)), + span: impl_span + }); + } + + let mut struct_ast = struct_ast.into_sorted(); + Ok(struct_ast.types.remove(0)) +} + +// Generate the deserialize_content method as +// +// fn deserialize_content(serialized_note: [Field; NOTE_SERILIZED_LEN]) -> Self { +// NoteType { +// note_field1: serialized_note[0] as Field, +// note_field2: NoteFieldType2::from_field(serialized_note[1])... +// } +// } +// It assumes every note field is stored in an individual serialized field, +// and can be converted to the original type via the from_field() trait (structs) or cast as Field (integers) +fn generate_note_deserialize_content( + note_type: &str, + note_fields: &[(String, String)], + note_serialize_len: &String, + note_header_field_name: &String, + impl_span: Option, +) -> Result { + let function_source = generate_note_deserialize_content_source( + note_type, + note_fields, + note_serialize_len, + note_header_field_name, + ); + + let (function_ast, errors) = parse_program(&function_source); + if !errors.is_empty() { + dbg!(errors); + return Err(AztecMacroError::CouldNotImplementNoteInterface { + secondary_message: Some("Failed to parse Noir macro code (fn deserialize_content). This is either a bug in the compiler or the Noir macro code".to_string()), + span: impl_span + }); + } + + let mut function_ast = function_ast.into_sorted(); + let mut noir_fn = function_ast.functions.remove(0); + noir_fn.def.span = impl_span.unwrap(); + noir_fn.def.visibility = ItemVisibility::Public; + Ok(noir_fn) +} + +// Generate the serialize_content method as +// +// fn serialize_content(self: {}) -> [Field; NOTE_SERIALIZED_LEN] { +// [self.note_field1 as Field, self.note_field2.to_field()...] +// } +// +// It assumes every struct field can be converted either via the to_field() trait (structs) or cast as Field (integers) +fn generate_note_serialize_content( + note_type: &str, + note_fields: &[(String, String)], + note_serialize_len: &String, + note_header_field_name: &String, + impl_span: Option, +) -> Result { + let function_source = generate_note_serialize_content_source( + note_type, + note_fields, + note_serialize_len, + note_header_field_name, + ); + + let (function_ast, errors) = parse_program(&function_source); + if !errors.is_empty() { + dbg!(errors); + return Err(AztecMacroError::CouldNotImplementNoteInterface { + secondary_message: Some("Failed to parse Noir macro code (fn serialize_content). This is either a bug in the compiler or the Noir macro code".to_string()), + span: impl_span + }); + } + + let mut function_ast = function_ast.into_sorted(); + let mut noir_fn = function_ast.functions.remove(0); + noir_fn.def.span = impl_span.unwrap(); + noir_fn.def.visibility = ItemVisibility::Public; + Ok(noir_fn) +} + +// Automatically generate a function in the Note's impl that returns the note's fields metadata +fn generate_note_properties_fn( + note_type: &str, + note_fields: &[(String, String)], + note_header_field_name: &String, + impl_span: Option, +) -> Result { + let function_source = + generate_note_properties_fn_source(note_type, note_fields, note_header_field_name); + let (function_ast, errors) = parse_program(&function_source); + if !errors.is_empty() { + dbg!(errors); + return Err(AztecMacroError::CouldNotImplementNoteInterface { + secondary_message: Some("Failed to parse Noir macro code (fn properties). This is either a bug in the compiler or the Noir macro code".to_string()), + span: impl_span + }); + } + let mut function_ast = function_ast.into_sorted(); + let mut noir_fn = function_ast.functions.remove(0); + noir_fn.def.span = impl_span.unwrap(); + noir_fn.def.visibility = ItemVisibility::Public; + Ok(noir_fn) +} + +// Automatically generate the method to compute the note's content hash as: +// fn compute_note_content_hash(self: NoteType) -> Field { +// // TODO(#1205) Should use a non-zero generator index. +// dep::aztec::hash::pedersen_hash(self.serialize_content(), 0) +// } +// +fn generate_compute_note_content_hash( + note_type: &String, + impl_span: Option, +) -> Result { + let function_source = format!( + " + fn compute_note_content_hash(self: {}) -> Field {{ + // TODO(#1205) Should use a non-zero generator index. + dep::aztec::hash::pedersen_hash(self.serialize_content(), 0) + }} + ", + note_type + ); + let (function_ast, errors) = parse_program(&function_source); + if !errors.is_empty() { + dbg!(errors); + return Err(AztecMacroError::CouldNotImplementNoteInterface { + secondary_message: Some("Failed to parse Noir macro code (fn compute_note_content_hash). This is either a bug in the compiler or the Noir macro code".to_string()), + span: impl_span + }); + } + let mut function_ast = function_ast.into_sorted(); + let mut noir_fn = function_ast.functions.remove(0); + noir_fn.def.span = impl_span.unwrap(); + noir_fn.def.visibility = ItemVisibility::Public; + Ok(noir_fn) +} + +// Source code generator functions. These utility methods produce Noir code as strings, that are then parsed and added to the AST. + +fn generate_note_properties_struct_source( + note_type: &str, + note_fields: &[(String, String)], + note_header_field_name: &String, +) -> String { + let note_property_selectors = note_fields + .iter() + .filter_map(|(field_name, _)| { + if field_name != note_header_field_name { + Some(format!( + "{}: dep::aztec::note::note_getter_options::PropertySelector", + field_name + )) + } else { + None + } + }) + .collect::>() + .join(",\n"); + format!( + " + struct {}Properties {{ + {} + }}", + note_type, note_property_selectors + ) + .to_string() +} + +fn generate_note_properties_fn_source( + note_type: &str, + note_fields: &[(String, String)], + note_header_field_name: &String, +) -> String { + let note_property_selectors = note_fields + .iter() + .enumerate() + .filter_map(|(index, (field_name, _))| { + if field_name != note_header_field_name { + Some(format!( + "{}: dep::aztec::note::note_getter_options::PropertySelector {{ index: {}, offset: 0, length: 32 }}", + field_name, + index + )) + } else { + None + } + }) + .collect::>() + .join(", "); + format!( + " + pub fn properties() -> {}Properties {{ + {}Properties {{ + {} + }} + }}", + note_type, note_type, note_property_selectors + ) + .to_string() +} + +fn generate_note_serialize_content_source( + note_type: &str, + note_fields: &[(String, String)], + note_serialize_len: &String, + note_header_field_name: &String, +) -> String { + let note_fields = note_fields + .iter() + .filter_map(|(field_name, field_type)| { + if field_name != note_header_field_name { + if field_type == "Field" { + Some(format!("self.{}", field_name)) + } else { + Some(format!("self.{}.to_field()", field_name)) + } + } else { + None + } + }) + .collect::>() + .join(", "); + format!( + " + fn serialize_content(self: {}) -> [Field; {}] {{ + [{}] + }}", + note_type, note_serialize_len, note_fields + ) + .to_string() +} + +fn generate_note_deserialize_content_source( + note_type: &str, + note_fields: &[(String, String)], + note_serialize_len: &String, + note_header_field_name: &String, +) -> String { + let note_fields = note_fields + .iter() + .enumerate() + .map(|(index, (field_name, field_type))| { + if field_name != note_header_field_name { + // TODO: Simplify this when https://github.com/noir-lang/noir/issues/4463 is fixed + if field_type.eq("Field") + || Regex::new(r"u[0-9]+").unwrap().is_match(field_type) + || field_type.eq("bool") + { + format!("{}: serialized_note[{}] as {},", field_name, index, field_type) + } else { + format!( + "{}: {}::from_field(serialized_note[{}]),", + field_name, field_type, index + ) + } + } else { + format!( + "{}: dep::aztec::note::note_header::NoteHeader::empty()", + note_header_field_name + ) + } + }) + .collect::>() + .join("\n"); + format!( + " + fn deserialize_content(serialized_note: [Field; {}]) -> Self {{ + {} {{ + {} + }} + }}", + note_serialize_len, note_type, note_fields + ) + .to_string() +} diff --git a/aztec_macros/src/transforms/storage.rs b/aztec_macros/src/transforms/storage.rs new file mode 100644 index 00000000000..10f44d01bb4 --- /dev/null +++ b/aztec_macros/src/transforms/storage.rs @@ -0,0 +1,346 @@ +use std::borrow::{Borrow, BorrowMut}; + +use noirc_errors::Span; +use noirc_frontend::{ + graph::CrateId, + macros_api::{ + FieldElement, FileId, HirContext, HirExpression, HirLiteral, HirStatement, NodeInterner, + }, + node_interner::{TraitId, TraitImplKind}, + parser::SortedModule, + BlockExpression, Expression, ExpressionKind, FunctionDefinition, Ident, Literal, NoirFunction, + PathKind, Pattern, StatementKind, Type, TypeImpl, UnresolvedType, UnresolvedTypeData, +}; + +use crate::{ + chained_dep, chained_path, + utils::{ + ast_utils::{ + call, expression, ident, ident_path, lambda, make_statement, make_type, pattern, + return_type, variable, variable_path, + }, + errors::AztecMacroError, + hir_utils::{collect_crate_structs, collect_traits}, + }, +}; + +// Check to see if the user has defined a storage struct +pub fn check_for_storage_definition(module: &SortedModule) -> bool { + module.types.iter().any(|r#struct| r#struct.name.0.contents == "Storage") +} + +// Check to see if the user has defined a storage struct +pub fn check_for_storage_implementation(module: &SortedModule) -> bool { + module.impls.iter().any(|r#impl| match &r#impl.object_type.typ { + UnresolvedTypeData::Named(path, _, _) => { + path.segments.last().is_some_and(|segment| segment.0.contents == "Storage") + } + _ => false, + }) +} + +/// Auxiliary function to generate the storage constructor for a given field, using +/// the Storage definition as a reference. Supports nesting. +pub fn generate_storage_field_constructor( + (type_ident, unresolved_type): &(Ident, UnresolvedType), + slot: Expression, +) -> Result { + let typ = &unresolved_type.typ; + match typ { + UnresolvedTypeData::Named(path, generics, _) => { + let mut new_path = path.clone().to_owned(); + new_path.segments.push(ident("new")); + match path.segments.last().unwrap().0.contents.as_str() { + "Map" => Ok(call( + variable_path(new_path), + vec![ + variable("context"), + slot, + lambda( + vec![ + ( + pattern("context"), + make_type(UnresolvedTypeData::Named( + chained_dep!("aztec", "context", "Context"), + vec![], + true, + )), + ), + ( + Pattern::Identifier(ident("slot")), + make_type(UnresolvedTypeData::FieldElement), + ), + ], + generate_storage_field_constructor( + &(type_ident.clone(), generics.iter().last().unwrap().clone()), + variable("slot"), + )?, + ), + ], + )), + _ => Ok(call(variable_path(new_path), vec![variable("context"), slot])), + } + } + _ => Err(AztecMacroError::UnsupportedStorageType { + typ: typ.clone(), + span: Some(type_ident.span()), + }), + } +} + +// Generates the Storage implementation block from the Storage struct definition if it does not exist +/// From: +/// +/// struct Storage { +/// a_map: Map>, +/// a_nested_map: Map>>, +/// a_field: SomeStoragePrimitive, +/// } +/// +/// To: +/// +/// impl Storage { +/// fn init(context: Context) -> Self { +/// Storage { +/// a_map: Map::new(context, 0, |context, slot| { +/// SomeStoragePrimitive::new(context, slot) +/// }), +/// a_nested_map: Map::new(context, 0, |context, slot| { +/// Map::new(context, slot, |context, slot| { +/// SomeStoragePrimitive::new(context, slot) +/// }) +/// }), +/// a_field: SomeStoragePrimitive::new(context, 0), +/// } +/// } +/// } +/// +/// Storage slots are generated as 0 and will be populated using the information from the HIR +/// at a later stage. +pub fn generate_storage_implementation(module: &mut SortedModule) -> Result<(), AztecMacroError> { + let definition = + module.types.iter().find(|r#struct| r#struct.name.0.contents == "Storage").unwrap(); + + let slot_zero = expression(ExpressionKind::Literal(Literal::Integer( + FieldElement::from(i128::from(0)), + false, + ))); + + let field_constructors = definition + .fields + .iter() + .flat_map(|field| { + generate_storage_field_constructor(field, slot_zero.clone()) + .map(|expression| (field.0.clone(), expression)) + }) + .collect(); + + let storage_constructor_statement = make_statement(StatementKind::Expression(expression( + ExpressionKind::constructor((chained_path!("Storage"), field_constructors)), + ))); + + let init = NoirFunction::normal(FunctionDefinition::normal( + &ident("init"), + &vec![], + &[( + ident("context"), + make_type(UnresolvedTypeData::Named( + chained_dep!("aztec", "context", "Context"), + vec![], + true, + )), + )], + &BlockExpression { statements: vec![storage_constructor_statement] }, + &[], + &return_type(chained_path!("Self")), + )); + + let storage_impl = TypeImpl { + object_type: UnresolvedType { + typ: UnresolvedTypeData::Named(chained_path!("Storage"), vec![], true), + span: Some(Span::default()), + }, + type_span: Span::default(), + generics: vec![], + methods: vec![(init, Span::default())], + }; + module.impls.push(storage_impl); + + Ok(()) +} + +/// Obtains the serialized length of a type that implements the Serialize trait. +fn get_serialized_length( + traits: &[TraitId], + typ: &Type, + interner: &NodeInterner, +) -> Result { + let (struct_name, maybe_stored_in_state) = match typ { + Type::Struct(struct_type, generics) => { + Ok((struct_type.borrow().name.0.contents.clone(), generics.first())) + } + _ => Err(AztecMacroError::CouldNotAssignStorageSlots { + secondary_message: Some("State storage variable must be a struct".to_string()), + }), + }?; + let stored_in_state = + maybe_stored_in_state.ok_or(AztecMacroError::CouldNotAssignStorageSlots { + secondary_message: Some("State storage variable must be generic".to_string()), + })?; + + let is_note = traits.iter().any(|&trait_id| { + let r#trait = interner.get_trait(trait_id); + r#trait.name.0.contents == "NoteInterface" + && !interner.lookup_all_trait_implementations(stored_in_state, trait_id).is_empty() + }); + + // Maps and (private) Notes always occupy a single slot. Someone could store a Note in PublicMutable for whatever reason though. + if struct_name == "Map" || (is_note && struct_name != "PublicMutable") { + return Ok(1); + } + + let serialized_trait_impl_kind = traits + .iter() + .find_map(|&trait_id| { + let r#trait = interner.get_trait(trait_id); + if r#trait.borrow().name.0.contents == "Serialize" + && r#trait.borrow().generics.len() == 1 + { + interner + .lookup_all_trait_implementations(stored_in_state, trait_id) + .into_iter() + .next() + } else { + None + } + }) + .ok_or(AztecMacroError::CouldNotAssignStorageSlots { + secondary_message: Some("Stored data must implement Serialize trait".to_string()), + })?; + + let serialized_trait_impl_id = match serialized_trait_impl_kind { + TraitImplKind::Normal(trait_impl_id) => Ok(trait_impl_id), + _ => Err(AztecMacroError::CouldNotAssignStorageSlots { secondary_message: None }), + }?; + + let serialized_trait_impl_shared = interner.get_trait_implementation(*serialized_trait_impl_id); + let serialized_trait_impl = serialized_trait_impl_shared.borrow(); + + match serialized_trait_impl.trait_generics.first().unwrap() { + Type::Constant(value) => Ok(*value), + _ => Err(AztecMacroError::CouldNotAssignStorageSlots { secondary_message: None }), + } +} + +/// Assigns storage slots to the storage struct fields based on the serialized length of the types. This automatic assignment +/// will only trigger if the assigned storage slot is invalid (0 as generated by generate_storage_implementation) +pub fn assign_storage_slots( + crate_id: &CrateId, + context: &mut HirContext, +) -> Result<(), (AztecMacroError, FileId)> { + let traits: Vec<_> = collect_traits(context); + for struct_id in collect_crate_structs(crate_id, context) { + let interner: &mut NodeInterner = context.def_interner.borrow_mut(); + let r#struct = interner.get_struct(struct_id); + let file_id = r#struct.borrow().location.file; + if r#struct.borrow().name.0.contents == "Storage" && r#struct.borrow().id.krate().is_root() + { + let init_id = interner + .lookup_method( + &Type::Struct(interner.get_struct(struct_id), vec![]), + struct_id, + "init", + false, + ) + .ok_or(( + AztecMacroError::CouldNotAssignStorageSlots { + secondary_message: Some( + "Storage struct must have an init function".to_string(), + ), + }, + file_id, + ))?; + let init_function = interner.function(&init_id).block(interner); + let init_function_statement_id = init_function.statements().first().ok_or(( + AztecMacroError::CouldNotAssignStorageSlots { + secondary_message: Some("Init storage statement not found".to_string()), + }, + file_id, + ))?; + let storage_constructor_statement = interner.statement(init_function_statement_id); + + let storage_constructor_expression = match storage_constructor_statement { + HirStatement::Expression(expression_id) => { + match interner.expression(&expression_id) { + HirExpression::Constructor(hir_constructor_expression) => { + Ok(hir_constructor_expression) + } + _ => Err((AztecMacroError::CouldNotAssignStorageSlots { + secondary_message: Some( + "Storage constructor statement must be a constructor expression" + .to_string(), + ), + }, file_id)) + } + } + _ => Err(( + AztecMacroError::CouldNotAssignStorageSlots { + secondary_message: Some( + "Storage constructor statement must be an expression".to_string(), + ), + }, + file_id, + )), + }?; + + let mut storage_slot: u64 = 1; + for (index, (_, expr_id)) in storage_constructor_expression.fields.iter().enumerate() { + let fields = r#struct.borrow().get_fields(&[]); + let (_, field_type) = fields.get(index).unwrap(); + let new_call_expression = match interner.expression(expr_id) { + HirExpression::Call(hir_call_expression) => Ok(hir_call_expression), + _ => Err(( + AztecMacroError::CouldNotAssignStorageSlots { + secondary_message: Some( + "Storage field initialization expression is not a call expression" + .to_string(), + ), + }, + file_id, + )), + }?; + + let slot_arg_expression = interner.expression(&new_call_expression.arguments[1]); + + let current_storage_slot = match slot_arg_expression { + HirExpression::Literal(HirLiteral::Integer(slot, _)) => Ok(slot.to_u128()), + _ => Err(( + AztecMacroError::CouldNotAssignStorageSlots { + secondary_message: Some( + "Storage slot argument expression must be a literal integer" + .to_string(), + ), + }, + file_id, + )), + }?; + + if current_storage_slot != 0 { + continue; + } + + let type_serialized_len = get_serialized_length(&traits, field_type, interner) + .map_err(|err| (err, file_id))?; + interner.update_expression(new_call_expression.arguments[1], |expr| { + *expr = HirExpression::Literal(HirLiteral::Integer( + FieldElement::from(u128::from(storage_slot)), + false, + )); + }); + + storage_slot += type_serialized_len; + } + } + } + Ok(()) +} diff --git a/aztec_macros/src/utils/ast_utils.rs b/aztec_macros/src/utils/ast_utils.rs new file mode 100644 index 00000000000..bdcbad646c2 --- /dev/null +++ b/aztec_macros/src/utils/ast_utils.rs @@ -0,0 +1,191 @@ +use noirc_errors::{Span, Spanned}; +use noirc_frontend::{ + token::SecondaryAttribute, BinaryOpKind, CallExpression, CastExpression, Expression, + ExpressionKind, FunctionReturnType, Ident, IndexExpression, InfixExpression, Lambda, + LetStatement, MemberAccessExpression, MethodCallExpression, NoirTraitImpl, Path, Pattern, + PrefixExpression, Statement, StatementKind, TraitImplItem, UnaryOp, UnresolvedType, + UnresolvedTypeData, +}; + +// +// Helper macros for creating noir ast nodes +// +pub fn ident(name: &str) -> Ident { + Ident::new(name.to_string(), Span::default()) +} + +pub fn ident_path(name: &str) -> Path { + Path::from_ident(ident(name)) +} + +pub fn path(ident: Ident) -> Path { + Path::from_ident(ident) +} + +pub fn expression(kind: ExpressionKind) -> Expression { + Expression::new(kind, Span::default()) +} + +pub fn variable(name: &str) -> Expression { + expression(ExpressionKind::Variable(ident_path(name))) +} + +pub fn variable_ident(identifier: Ident) -> Expression { + expression(ExpressionKind::Variable(path(identifier))) +} + +pub fn variable_path(path: Path) -> Expression { + expression(ExpressionKind::Variable(path)) +} + +pub fn method_call( + object: Expression, + method_name: &str, + arguments: Vec, +) -> Expression { + expression(ExpressionKind::MethodCall(Box::new(MethodCallExpression { + object, + method_name: ident(method_name), + arguments, + }))) +} + +pub fn call(func: Expression, arguments: Vec) -> Expression { + expression(ExpressionKind::Call(Box::new(CallExpression { func: Box::new(func), arguments }))) +} + +pub fn pattern(name: &str) -> Pattern { + Pattern::Identifier(ident(name)) +} + +pub fn mutable(name: &str) -> Pattern { + Pattern::Mutable(Box::new(pattern(name)), Span::default(), true) +} + +pub fn mutable_assignment(name: &str, assigned_to: Expression) -> Statement { + make_statement(StatementKind::Let(LetStatement { + pattern: mutable(name), + r#type: make_type(UnresolvedTypeData::Unspecified), + expression: assigned_to, + })) +} + +pub fn mutable_reference(variable_name: &str) -> Expression { + expression(ExpressionKind::Prefix(Box::new(PrefixExpression { + operator: UnaryOp::MutableReference, + rhs: variable(variable_name), + }))) +} + +pub fn assignment(name: &str, assigned_to: Expression) -> Statement { + make_statement(StatementKind::Let(LetStatement { + pattern: pattern(name), + r#type: make_type(UnresolvedTypeData::Unspecified), + expression: assigned_to, + })) +} + +pub fn member_access(lhs: &str, rhs: &str) -> Expression { + expression(ExpressionKind::MemberAccess(Box::new(MemberAccessExpression { + lhs: variable(lhs), + rhs: ident(rhs), + }))) +} + +pub fn return_type(path: Path) -> FunctionReturnType { + let ty = make_type(UnresolvedTypeData::Named(path, vec![], true)); + FunctionReturnType::Ty(ty) +} + +pub fn lambda(parameters: Vec<(Pattern, UnresolvedType)>, body: Expression) -> Expression { + expression(ExpressionKind::Lambda(Box::new(Lambda { + parameters, + return_type: UnresolvedType { + typ: UnresolvedTypeData::Unspecified, + span: Some(Span::default()), + }, + body, + }))) +} + +pub fn make_eq(lhs: Expression, rhs: Expression) -> Expression { + expression(ExpressionKind::Infix(Box::new(InfixExpression { + lhs, + rhs, + operator: Spanned::from(Span::default(), BinaryOpKind::Equal), + }))) +} + +pub fn make_statement(kind: StatementKind) -> Statement { + Statement { span: Span::default(), kind } +} + +#[macro_export] +macro_rules! chained_path { + ( $base:expr ) => { + { + ident_path($base) + } + }; + ( $base:expr $(, $tail:expr)* ) => { + { + let mut base_path = ident_path($base); + $( + base_path.segments.push(ident($tail)); + )* + base_path + } + } +} + +#[macro_export] +macro_rules! chained_dep { + ( $base:expr $(, $tail:expr)* ) => { + { + let mut base_path = ident_path($base); + base_path.kind = PathKind::Dep; + $( + base_path.segments.push(ident($tail)); + )* + base_path + } + } +} + +pub fn cast(lhs: Expression, ty: UnresolvedTypeData) -> Expression { + expression(ExpressionKind::Cast(Box::new(CastExpression { lhs, r#type: make_type(ty) }))) +} + +pub fn make_type(typ: UnresolvedTypeData) -> UnresolvedType { + UnresolvedType { typ, span: Some(Span::default()) } +} + +pub fn index_array(array: Ident, index: &str) -> Expression { + expression(ExpressionKind::Index(Box::new(IndexExpression { + collection: variable_path(path(array)), + index: variable(index), + }))) +} + +pub fn index_array_variable(array: Expression, index: &str) -> Expression { + expression(ExpressionKind::Index(Box::new(IndexExpression { + collection: array, + index: variable(index), + }))) +} + +pub fn check_trait_method_implemented(trait_impl: &NoirTraitImpl, method_name: &str) -> bool { + trait_impl.items.iter().any(|item| match item { + TraitImplItem::Function(func) => func.def.name.0.contents == method_name, + _ => false, + }) +} + +/// Checks if an attribute is a custom attribute with a specific name +pub fn is_custom_attribute(attr: &SecondaryAttribute, attribute_name: &str) -> bool { + if let SecondaryAttribute::Custom(custom_attr) = attr { + custom_attr.as_str() == attribute_name + } else { + false + } +} diff --git a/aztec_macros/src/utils/checks.rs b/aztec_macros/src/utils/checks.rs new file mode 100644 index 00000000000..5232f67ae87 --- /dev/null +++ b/aztec_macros/src/utils/checks.rs @@ -0,0 +1,22 @@ +use noirc_frontend::{ + graph::CrateId, + macros_api::{FileId, HirContext, MacroError}, +}; + +use super::errors::AztecMacroError; + +/// Creates an error alerting the user that they have not downloaded the Aztec-noir library +pub fn check_for_aztec_dependency( + crate_id: &CrateId, + context: &HirContext, +) -> Result<(), (MacroError, FileId)> { + if has_aztec_dependency(crate_id, context) { + Ok(()) + } else { + Err((AztecMacroError::AztecDepNotFound.into(), context.crate_graph[crate_id].root_file_id)) + } +} + +pub fn has_aztec_dependency(crate_id: &CrateId, context: &HirContext) -> bool { + context.crate_graph[crate_id].dependencies.iter().any(|dep| dep.as_name() == "aztec") +} diff --git a/aztec_macros/src/utils/constants.rs b/aztec_macros/src/utils/constants.rs new file mode 100644 index 00000000000..464cd10e2c7 --- /dev/null +++ b/aztec_macros/src/utils/constants.rs @@ -0,0 +1,3 @@ +pub const FUNCTION_TREE_HEIGHT: u32 = 5; +pub const MAX_CONTRACT_PRIVATE_FUNCTIONS: usize = 2_usize.pow(FUNCTION_TREE_HEIGHT); +pub const SIGNATURE_PLACEHOLDER: &str = "SIGNATURE_PLACEHOLDER"; diff --git a/aztec_macros/src/utils/errors.rs b/aztec_macros/src/utils/errors.rs new file mode 100644 index 00000000000..48186555eff --- /dev/null +++ b/aztec_macros/src/utils/errors.rs @@ -0,0 +1,63 @@ +use noirc_errors::Span; +use noirc_frontend::{macros_api::MacroError, UnresolvedTypeData}; + +use super::constants::MAX_CONTRACT_PRIVATE_FUNCTIONS; + +#[derive(Debug, Clone)] +pub enum AztecMacroError { + AztecDepNotFound, + ContractHasTooManyPrivateFunctions { span: Span }, + UnsupportedFunctionArgumentType { span: Span, typ: UnresolvedTypeData }, + UnsupportedStorageType { span: Option, typ: UnresolvedTypeData }, + CouldNotAssignStorageSlots { secondary_message: Option }, + CouldNotImplementNoteInterface { span: Option, secondary_message: Option }, + EventError { span: Span, message: String }, + UnsupportedAttributes { span: Span, secondary_message: Option }, +} + +impl From for MacroError { + fn from(err: AztecMacroError) -> Self { + match err { + AztecMacroError::AztecDepNotFound {} => MacroError { + primary_message: "Aztec dependency not found. Please add aztec as a dependency in your Cargo.toml. For more information go to https://docs.aztec.network/developers/debugging/aztecnr-errors#aztec-dependency-not-found-please-add-aztec-as-a-dependency-in-your-nargotoml".to_owned(), + secondary_message: None, + span: None, + }, + AztecMacroError::ContractHasTooManyPrivateFunctions { span } => MacroError { + primary_message: format!("Contract can only have a maximum of {} private functions", MAX_CONTRACT_PRIVATE_FUNCTIONS), + secondary_message: None, + span: Some(span), + }, + AztecMacroError::UnsupportedFunctionArgumentType { span, typ } => MacroError { + primary_message: format!("Provided parameter type `{typ:?}` is not supported in Aztec contract interface"), + secondary_message: None, + span: Some(span), + }, + AztecMacroError::UnsupportedStorageType { span, typ } => MacroError { + primary_message: format!("Provided storage type `{typ:?}` is not directly supported in Aztec. Please provide a custom storage implementation"), + secondary_message: None, + span, + }, + AztecMacroError::CouldNotAssignStorageSlots { secondary_message } => MacroError { + primary_message: "Could not assign storage slots, please provide a custom storage implementation".to_string(), + secondary_message, + span: None, + }, + AztecMacroError::CouldNotImplementNoteInterface { span, secondary_message } => MacroError { + primary_message: "Could not implement automatic methods for note, please provide an implementation of the NoteInterface trait".to_string(), + secondary_message, + span, + }, + AztecMacroError::EventError { span, message } => MacroError { + primary_message: message, + secondary_message: None, + span: Some(span), + }, + AztecMacroError::UnsupportedAttributes { span, secondary_message } => MacroError { + primary_message: "Unsupported attributes in contract function".to_string(), + secondary_message, + span: Some(span), + }, + } + } +} diff --git a/aztec_macros/src/utils/hir_utils.rs b/aztec_macros/src/utils/hir_utils.rs new file mode 100644 index 00000000000..f31a0584261 --- /dev/null +++ b/aztec_macros/src/utils/hir_utils.rs @@ -0,0 +1,118 @@ +use iter_extended::vecmap; +use noirc_frontend::{ + graph::CrateId, + hir::def_collector::dc_crate::UnresolvedTraitImpl, + macros_api::{HirContext, ModuleDefId, StructId}, + node_interner::{TraitId, TraitImplId}, + Signedness, Type, UnresolvedTypeData, +}; + +pub fn collect_crate_structs(crate_id: &CrateId, context: &HirContext) -> Vec { + context + .def_map(crate_id) + .expect("ICE: Missing crate in def_map") + .modules() + .iter() + .flat_map(|(_, module)| { + module.type_definitions().filter_map(|typ| { + if let ModuleDefId::TypeId(struct_id) = typ { + Some(struct_id) + } else { + None + } + }) + }) + .collect() +} + +pub fn collect_traits(context: &HirContext) -> Vec { + let crates = context.crates(); + crates + .flat_map(|crate_id| context.def_map(&crate_id).map(|def_map| def_map.modules())) + .flatten() + .flat_map(|module| { + module.type_definitions().filter_map(|typ| { + if let ModuleDefId::TraitId(struct_id) = typ { + Some(struct_id) + } else { + None + } + }) + }) + .collect() +} + +/// Computes the aztec signature for a resolved type. +pub fn signature_of_type(typ: &Type) -> String { + match typ { + Type::Integer(Signedness::Signed, bit_size) => format!("i{}", bit_size), + Type::Integer(Signedness::Unsigned, bit_size) => format!("u{}", bit_size), + Type::FieldElement => "Field".to_owned(), + Type::Bool => "bool".to_owned(), + Type::Array(len, typ) => { + if let Type::Constant(len) = **len { + format!("[{};{len}]", signature_of_type(typ)) + } else { + unimplemented!("Cannot generate signature for array with length type {:?}", typ) + } + } + Type::Struct(def, args) => { + let fields = def.borrow().get_fields(args); + let fields = vecmap(fields, |(_, typ)| signature_of_type(&typ)); + format!("({})", fields.join(",")) + } + Type::Tuple(types) => { + let fields = vecmap(types, signature_of_type); + format!("({})", fields.join(",")) + } + _ => unimplemented!("Cannot generate signature for type {:?}", typ), + } +} + +// Fetches the name of all structs that implement trait_name, both in the current crate and all of its dependencies. +pub fn fetch_struct_trait_impls( + context: &mut HirContext, + unresolved_traits_impls: &[UnresolvedTraitImpl], + trait_name: &str, +) -> Vec { + let mut struct_typenames: Vec = Vec::new(); + + // These structs can be declared in either external crates or the current one. External crates that contain + // dependencies have already been processed and resolved, but are available here via the NodeInterner. Note that + // crates on which the current crate does not depend on may not have been processed, and will be ignored. + for trait_impl_id in 0..context.def_interner.next_trait_impl_id().0 { + let trait_impl = &context.def_interner.get_trait_implementation(TraitImplId(trait_impl_id)); + + if trait_impl.borrow().ident.0.contents == *trait_name { + if let Type::Struct(s, _) = &trait_impl.borrow().typ { + struct_typenames.push(s.borrow().name.0.contents.clone()); + } else { + panic!("Found impl for {} on non-Struct", trait_name); + } + } + } + + // This crate's traits and impls have not yet been resolved, so we look for impls in unresolved_trait_impls. + struct_typenames.extend( + unresolved_traits_impls + .iter() + .filter(|trait_impl| { + trait_impl + .trait_path + .segments + .last() + .expect("ICE: empty trait_impl path") + .0 + .contents + == *trait_name + }) + .filter_map(|trait_impl| match &trait_impl.object_type.typ { + UnresolvedTypeData::Named(path, _, _) => { + Some(path.segments.last().unwrap().0.contents.clone()) + } + _ => None, + }), + ); + + struct_typenames +} diff --git a/aztec_macros/src/utils/mod.rs b/aztec_macros/src/utils/mod.rs new file mode 100644 index 00000000000..c8914f83025 --- /dev/null +++ b/aztec_macros/src/utils/mod.rs @@ -0,0 +1,5 @@ +pub mod ast_utils; +pub mod checks; +pub mod constants; +pub mod errors; +pub mod hir_utils; diff --git a/bootstrap.sh b/bootstrap.sh deleted file mode 100755 index 54129c3d61a..00000000000 --- a/bootstrap.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -set -eu - -cd $(dirname "$0") - -CMD=${1:-} - -if [ -n "$CMD" ]; then - if [ "$CMD" = "clean" ]; then - git clean -fdx - exit 0 - else - echo "Unknown command: $CMD" - exit 1 - fi -fi - -# Attempt to just pull artefacts from CI and exit on success. -[ -n "${USE_CACHE:-}" ] && ./bootstrap_cache.sh && exit - -./scripts/bootstrap_native.sh -./scripts/bootstrap_packages.sh diff --git a/bootstrap_cache.sh b/bootstrap_cache.sh deleted file mode 100755 index d06aa493662..00000000000 --- a/bootstrap_cache.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -set -eu - -[ -z "${NO_CACHE:-}" ] && type docker &> /dev/null && [ -f ~/.aws/credentials ] || exit 1 - -cd "$(dirname "$0")" -source ../build-system/scripts/setup_env '' '' mainframe_$USER > /dev/null - -echo -e "\033[1mRetrieving noir packages from remote cache...\033[0m" -extract_repo noir-packages /usr/src/noir/packages ./ -echo -e "\033[1mRetrieving nargo from remote cache...\033[0m" -extract_repo noir /usr/src/noir/target/release ./target/ - -remove_old_images noir-packages -remove_old_images noir diff --git a/compiler/integration-tests/package.json b/compiler/integration-tests/package.json index 2e75ebc201e..431fe408a8b 100644 --- a/compiler/integration-tests/package.json +++ b/compiler/integration-tests/package.json @@ -19,13 +19,14 @@ "@nomicfoundation/hardhat-chai-matchers": "^2.0.0", "@nomicfoundation/hardhat-ethers": "^3.0.0", "@web/dev-server-esbuild": "^0.3.6", - "@web/test-runner": "^0.15.3", + "@web/dev-server-import-maps": "^0.2.0", + "@web/test-runner": "^0.18.1", "@web/test-runner-playwright": "^0.10.0", - "eslint": "^8.56.0", - "eslint-plugin-prettier": "^5.0.0", + "eslint": "^8.57.0", + "eslint-plugin-prettier": "^5.1.3", "ethers": "^6.7.1", "hardhat": "^2.17.4", - "prettier": "3.0.3", + "prettier": "3.2.5", "smol-toml": "^1.1.2", "toml": "^3.0.0", "tslog": "^4.9.2" diff --git a/compiler/integration-tests/test/mocks/os.js b/compiler/integration-tests/test/mocks/os.js new file mode 100644 index 00000000000..32333568316 --- /dev/null +++ b/compiler/integration-tests/test/mocks/os.js @@ -0,0 +1 @@ +export const os = { cpus: () => new Array(4) }; diff --git a/compiler/integration-tests/web-test-runner.config.mjs b/compiler/integration-tests/web-test-runner.config.mjs index 665ea262f99..4dfc96dd0a6 100644 --- a/compiler/integration-tests/web-test-runner.config.mjs +++ b/compiler/integration-tests/web-test-runner.config.mjs @@ -2,7 +2,8 @@ import { defaultReporter } from '@web/test-runner'; import { summaryReporter } from '@web/test-runner'; import { fileURLToPath } from 'url'; import { esbuildPlugin } from '@web/dev-server-esbuild'; -import { playwrightLauncher } from "@web/test-runner-playwright"; +import { playwrightLauncher } from '@web/test-runner-playwright'; +import { importMapsPlugin } from '@web/dev-server-import-maps'; let reporter = summaryReporter(); const debugPlugins = []; @@ -21,7 +22,7 @@ if (process.env.CI !== 'true' || process.env.RUNNER_DEBUG === '1') { export default { browsers: [ - playwrightLauncher({ product: "chromium" }), + playwrightLauncher({ product: 'chromium' }), // playwrightLauncher({ product: "webkit" }), // playwrightLauncher({ product: "firefox" }), ], @@ -29,6 +30,16 @@ export default { esbuildPlugin({ ts: true, }), + importMapsPlugin({ + inject: { + importMap: { + imports: { + // mock os module + os: '/test/mocks/os.js', + }, + }, + }, + }), ...debugPlugins, ], files: ['test/browser/**/*.test.ts'], diff --git a/compiler/noirc_driver/Cargo.toml b/compiler/noirc_driver/Cargo.toml index 681976735f3..a7fe0b4b610 100644 --- a/compiler/noirc_driver/Cargo.toml +++ b/compiler/noirc_driver/Cargo.toml @@ -26,4 +26,3 @@ tracing.workspace = true thiserror.workspace = true aztec_macros = { path = "../../aztec_macros" } -noirc_macros = { path = "../../noirc_macros" } diff --git a/compiler/noirc_driver/build.rs b/compiler/noirc_driver/build.rs index 73a56142075..2ed109398a4 100644 --- a/compiler/noirc_driver/build.rs +++ b/compiler/noirc_driver/build.rs @@ -2,8 +2,7 @@ const GIT_COMMIT: &&str = &"GIT_COMMIT"; use std::path::Path; fn main() { - // Only use build_data if the environment variable isn't set - // The environment variable is always set when working via Nix + // Only use build_data if the environment variable isn't set. if std::env::var(GIT_COMMIT).is_err() { build_data::set_GIT_COMMIT(); build_data::set_GIT_DIRTY(); diff --git a/compiler/noirc_driver/src/contract.rs b/compiler/noirc_driver/src/contract.rs index 5f4b66e7dd2..bd78cb23cdc 100644 --- a/compiler/noirc_driver/src/contract.rs +++ b/compiler/noirc_driver/src/contract.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; -use acvm::acir::circuit::Circuit; +use acvm::acir::circuit::Program; use fm::FileId; use noirc_abi::{Abi, ContractEvent}; use noirc_errors::debug_info::DebugInfo; @@ -9,23 +9,6 @@ use noirc_evaluator::errors::SsaReport; use super::debug::DebugFile; -/// Describes the types of smart contract functions that are allowed. -/// Unlike the similar enum in noirc_frontend, 'open' and 'unconstrained' -/// are mutually exclusive here. In the case a function is both, 'unconstrained' -/// takes precedence. -#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq)] -pub enum ContractFunctionType { - /// This function will be executed in a private - /// context. - Secret, - /// This function will be executed in a public - /// context. - Open, - /// This function cannot constrain any values and can use nondeterministic features - /// like arrays of a dynamic size. - Unconstrained, -} - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct CompiledContract { pub noir_version: String, @@ -55,27 +38,20 @@ pub struct CompiledContract { pub struct ContractFunction { pub name: String, - pub function_type: ContractFunctionType, + pub is_unconstrained: bool, - pub is_internal: bool, + pub custom_attributes: Vec, pub abi: Abi, #[serde( - serialize_with = "Circuit::serialize_circuit_base64", - deserialize_with = "Circuit::deserialize_circuit_base64" + serialize_with = "Program::serialize_program_base64", + deserialize_with = "Program::deserialize_program_base64" )] - pub bytecode: Circuit, + pub bytecode: Program, pub debug: DebugInfo, -} -impl ContractFunctionType { - pub(super) fn new(kind: noirc_frontend::ContractFunctionType, is_unconstrained: bool) -> Self { - match (kind, is_unconstrained) { - (_, true) => Self::Unconstrained, - (noirc_frontend::ContractFunctionType::Secret, false) => Self::Secret, - (noirc_frontend::ContractFunctionType::Open, false) => Self::Open, - } - } + /// Names of the functions in the program. These are used for more informative debugging and benchmarking. + pub names: Vec, } diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 11f53cdb749..8fa2d9680c8 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -9,15 +9,19 @@ use fm::{FileId, FileManager}; use iter_extended::vecmap; use noirc_abi::{AbiParameter, AbiType, ContractEvent}; use noirc_errors::{CustomDiagnostic, FileDiagnostic}; -use noirc_evaluator::create_circuit; +use noirc_evaluator::create_program; use noirc_evaluator::errors::RuntimeError; +use noirc_evaluator::ssa::SsaProgramArtifact; use noirc_frontend::debug::build_debug_crate_file; use noirc_frontend::graph::{CrateId, CrateName}; use noirc_frontend::hir::def_map::{Contract, CrateDefMap}; use noirc_frontend::hir::Context; use noirc_frontend::macros_api::MacroProcessor; -use noirc_frontend::monomorphization::{monomorphize, monomorphize_debug, MonomorphizationError}; +use noirc_frontend::monomorphization::{ + errors::MonomorphizationError, monomorphize, monomorphize_debug, +}; use noirc_frontend::node_interner::FuncId; +use noirc_frontend::token::SecondaryAttribute; use std::path::Path; use thiserror::Error; use tracing::info; @@ -30,7 +34,7 @@ mod stdlib; use debug::filter_relevant_files; -pub use contract::{CompiledContract, ContractFunction, ContractFunctionType}; +pub use contract::{CompiledContract, ContractFunction}; pub use debug::DebugFile; pub use program::CompiledProgram; @@ -67,6 +71,10 @@ pub struct CompileOptions { #[arg(long)] pub print_acir: bool, + /// Pretty print benchmark times of each code generation pass + #[arg(long, hide = true)] + pub benchmark_codegen: bool, + /// Treat all warnings as errors #[arg(long, conflicts_with = "silence_warnings")] pub deny_warnings: bool, @@ -237,14 +245,8 @@ pub fn check_crate( deny_warnings: bool, disable_macros: bool, ) -> CompilationResult<()> { - let macros: Vec<&dyn MacroProcessor> = if disable_macros { - vec![&noirc_macros::AssertMessageMacro as &dyn MacroProcessor] - } else { - vec![ - &aztec_macros::AztecMacro as &dyn MacroProcessor, - &noirc_macros::AssertMessageMacro as &dyn MacroProcessor, - ] - }; + let macros: &[&dyn MacroProcessor] = + if disable_macros { &[] } else { &[&aztec_macros::AztecMacro as &dyn MacroProcessor] }; let mut errors = vec![]; let diagnostics = CrateDefMap::collect_defs(crate_id, context, macros); @@ -303,7 +305,7 @@ pub fn compile_main( if options.print_acir { println!("Compiled ACIR for main (unoptimized):"); - println!("{}", compiled_program.circuit); + println!("{}", compiled_program.program); } Ok((compiled_program, warnings)) @@ -404,19 +406,25 @@ fn compile_contract_inner( }; warnings.extend(function.warnings); let modifiers = context.def_interner.function_modifiers(&function_id); - let func_type = modifiers - .contract_function_type - .expect("Expected contract function to have a contract visibility"); - let function_type = ContractFunctionType::new(func_type, modifiers.is_unconstrained); + let custom_attributes = modifiers + .attributes + .secondary + .iter() + .filter_map( + |attr| if let SecondaryAttribute::Custom(tag) = attr { Some(tag) } else { None }, + ) + .cloned() + .collect(); functions.push(ContractFunction { name, - function_type, - is_internal: modifiers.is_internal.unwrap_or(false), + custom_attributes, abi: function.abi, - bytecode: function.circuit, + bytecode: function.program, debug: function.debug, + is_unconstrained: modifiers.is_unconstrained, + names: function.names, }); } @@ -478,20 +486,44 @@ pub fn compile_no_check( return Ok(cached_program.expect("cache must exist for hashes to match")); } let visibility = program.return_visibility; - let (circuit, debug, input_witnesses, return_witnesses, warnings) = - create_circuit(program, options.show_ssa, options.show_brillig, options.force_brillig)?; - let abi = - abi_gen::gen_abi(context, &main_function, input_witnesses, return_witnesses, visibility); - let file_map = filter_relevant_files(&[debug.clone()], &context.file_manager); + let SsaProgramArtifact { + program, + debug, + warnings, + main_input_witnesses, + main_return_witnesses, + names, + } = create_program( + program, + options.show_ssa, + options.show_brillig, + options.force_brillig, + options.benchmark_codegen, + )?; + + let abi = abi_gen::gen_abi( + context, + &main_function, + main_input_witnesses, + main_return_witnesses, + visibility, + ); + let file_map = filter_relevant_files(&debug, &context.file_manager); Ok(CompiledProgram { hash, - circuit, - debug, + // TODO(https://github.com/noir-lang/noir/issues/4428) + program, + // TODO(https://github.com/noir-lang/noir/issues/4428) + // Debug info is only relevant for errors at execution time which is not yet supported + // The CompileProgram `debug` field is used in multiple places and is better + // left to be updated once execution of multiple ACIR functions is enabled + debug: debug[0].clone(), abi, file_map, noir_version: NOIR_ARTIFACT_VERSION_STRING.to_string(), warnings, + names, }) } diff --git a/compiler/noirc_driver/src/program.rs b/compiler/noirc_driver/src/program.rs index 8d509d3bf68..9ffd2d70dda 100644 --- a/compiler/noirc_driver/src/program.rs +++ b/compiler/noirc_driver/src/program.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use acvm::acir::circuit::Circuit; +use acvm::acir::circuit::Program; use fm::FileId; use noirc_errors::debug_info::DebugInfo; @@ -19,12 +19,14 @@ pub struct CompiledProgram { pub hash: u64, #[serde( - serialize_with = "Circuit::serialize_circuit_base64", - deserialize_with = "Circuit::deserialize_circuit_base64" + serialize_with = "Program::serialize_program_base64", + deserialize_with = "Program::deserialize_program_base64" )] - pub circuit: Circuit, + pub program: Program, pub abi: noirc_abi::Abi, pub debug: DebugInfo, pub file_map: BTreeMap, pub warnings: Vec, + /// Names of the functions in the program. These are used for more informative debugging and benchmarking. + pub names: Vec, } diff --git a/compiler/noirc_errors/src/debug_info.rs b/compiler/noirc_errors/src/debug_info.rs index 67ec851d46d..09117bdc3b7 100644 --- a/compiler/noirc_errors/src/debug_info.rs +++ b/compiler/noirc_errors/src/debug_info.rs @@ -24,6 +24,9 @@ use serde::{ #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, Deserialize, Serialize)] pub struct DebugVarId(pub u32); +#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, Deserialize, Serialize)] +pub struct DebugFnId(pub u32); + #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, Deserialize, Serialize)] pub struct DebugTypeId(pub u32); @@ -33,7 +36,14 @@ pub struct DebugVariable { pub debug_type_id: DebugTypeId, } +#[derive(Debug, Clone, Hash, Deserialize, Serialize)] +pub struct DebugFunction { + pub name: String, + pub arg_names: Vec, +} + pub type DebugVariables = BTreeMap; +pub type DebugFunctions = BTreeMap; pub type DebugTypes = BTreeMap; #[serde_as] @@ -45,6 +55,7 @@ pub struct DebugInfo { #[serde_as(as = "BTreeMap")] pub locations: BTreeMap>, pub variables: DebugVariables, + pub functions: DebugFunctions, pub types: DebugTypes, } @@ -60,9 +71,10 @@ impl DebugInfo { pub fn new( locations: BTreeMap>, variables: DebugVariables, + functions: DebugFunctions, types: DebugTypes, ) -> Self { - Self { locations, variables, types } + Self { locations, variables, functions, types } } /// Updates the locations map when the [`Circuit`][acvm::acir::circuit::Circuit] is modified. diff --git a/compiler/noirc_evaluator/Cargo.toml b/compiler/noirc_evaluator/Cargo.toml index a8f0e8d83a9..fad7c3c309e 100644 --- a/compiler/noirc_evaluator/Cargo.toml +++ b/compiler/noirc_evaluator/Cargo.toml @@ -17,4 +17,5 @@ thiserror.workspace = true num-bigint = "0.4" im = { version = "15.1", features = ["serde"] } serde.workspace = true -tracing.workspace = true \ No newline at end of file +tracing.workspace = true +chrono = "0.4.37" \ No newline at end of file diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs index d542240a40c..36b5f8793cb 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs @@ -1,7 +1,7 @@ use acvm::acir::{brillig::BlackBoxOp, BlackBoxFunc}; use crate::brillig::brillig_ir::{ - brillig_variable::{BrilligVariable, BrilligVector}, + brillig_variable::{BrilligVariable, BrilligVector, SingleAddrVariable}, BrilligContext, }; @@ -56,17 +56,23 @@ pub(crate) fn convert_black_box_call( } BlackBoxFunc::Keccak256 => { if let ( - [message, BrilligVariable::SingleAddr(array_size)], + [message, BrilligVariable::SingleAddr(message_size)], [BrilligVariable::BrilligArray(result_array)], ) = (function_arguments, function_results) { let mut message_vector = convert_array_or_vector(brillig_context, message, bb_func); - message_vector.size = array_size.address; + let message_size_as_usize = + SingleAddrVariable::new_usize(brillig_context.allocate_register()); + // Message_size is not usize + brillig_context.cast_instruction(message_size_as_usize, *message_size); + + message_vector.size = message_size_as_usize.address; brillig_context.black_box_op_instruction(BlackBoxOp::Keccak256 { message: message_vector.to_heap_vector(), output: result_array.to_heap_array(), }); + brillig_context.deallocate_single_addr(message_size_as_usize); } else { unreachable!("ICE: Keccak256 expects message, message size and result array") } @@ -167,7 +173,7 @@ pub(crate) fn convert_black_box_call( ) = (function_arguments, function_results) { let message_hash = convert_array_or_vector(brillig_context, message, bb_func); - let signature = brillig_context.array_to_vector(signature); + let signature = brillig_context.array_to_vector_instruction(signature); brillig_context.black_box_op_instruction(BlackBoxOp::SchnorrVerify { public_key_x: public_key_x.address, public_key_y: public_key_y.address, @@ -240,7 +246,7 @@ pub(crate) fn convert_black_box_call( }); } else { unreachable!( - "ICE: EmbeddedCurveAdd expects two register arguments and one array result" + "ICE: BigIntAdd expects two register arguments and one result register" ) } } @@ -257,7 +263,7 @@ pub(crate) fn convert_black_box_call( }); } else { unreachable!( - "ICE: EmbeddedCurveAdd expects two register arguments and one array result" + "ICE: BigIntSub expects two register arguments and one result register" ) } } @@ -274,7 +280,7 @@ pub(crate) fn convert_black_box_call( }); } else { unreachable!( - "ICE: EmbeddedCurveAdd expects two register arguments and one array result" + "ICE: BigIntMul expects two register arguments and one result register" ) } } @@ -291,7 +297,7 @@ pub(crate) fn convert_black_box_call( }); } else { unreachable!( - "ICE: EmbeddedCurveAdd expects two register arguments and one array result" + "ICE: BigIntDiv expects two register arguments and one result register" ) } } @@ -308,7 +314,7 @@ pub(crate) fn convert_black_box_call( }); } else { unreachable!( - "ICE: EmbeddedCurveAdd expects two register arguments and one array result" + "ICE: BigIntFromLeBytes expects two register arguments and one result register" ) } } @@ -324,7 +330,7 @@ pub(crate) fn convert_black_box_call( }); } else { unreachable!( - "ICE: EmbeddedCurveAdd expects two register arguments and one array result" + "ICE: BigIntToLeBytes expects one register argument and one array result" ) } } @@ -368,7 +374,7 @@ fn convert_array_or_vector( bb_func: &BlackBoxFunc, ) -> BrilligVector { match array_or_vector { - BrilligVariable::BrilligArray(array) => brillig_context.array_to_vector(array), + BrilligVariable::BrilligArray(array) => brillig_context.array_to_vector_instruction(array), BrilligVariable::BrilligVector(vector) => *vector, _ => unreachable!( "ICE: {} expected an array or a vector, but got {:?}", diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs index f01f60252f6..cf2501ab1c0 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs @@ -2,7 +2,7 @@ use crate::brillig::brillig_ir::brillig_variable::{ type_to_heap_value_type, BrilligArray, BrilligVariable, BrilligVector, SingleAddrVariable, }; use crate::brillig::brillig_ir::{ - BrilligBinaryOp, BrilligContext, BRILLIG_INTEGER_ARITHMETIC_BIT_SIZE, + BrilligBinaryOp, BrilligContext, BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, }; use crate::ssa::ir::dfg::CallStack; use crate::ssa::ir::instruction::ConstrainError; @@ -16,7 +16,7 @@ use crate::ssa::ir::{ types::{NumericType, Type}, value::{Value, ValueId}, }; -use acvm::acir::brillig::{BinaryFieldOp, BinaryIntOp, MemoryAddress, ValueOrArray}; +use acvm::acir::brillig::{MemoryAddress, ValueOrArray}; use acvm::brillig_vm::brillig::HeapVector; use acvm::FieldElement; use fxhash::{FxHashMap as HashMap, FxHashSet as HashSet}; @@ -25,7 +25,7 @@ use num_bigint::BigUint; use super::brillig_black_box::convert_black_box_call; use super::brillig_block_variables::BlockVariables; -use super::brillig_fn::{get_bit_size_from_ssa_type, FunctionContext}; +use super::brillig_fn::FunctionContext; /// Generate the compilation artifacts for compiling a function into brillig bytecode. pub(crate) struct BrilligBlock<'block> { @@ -155,7 +155,7 @@ impl<'block> BrilligBlock<'block> { return_variable.extract_registers() }) .collect(); - self.brillig_context.return_instruction(&return_registers); + self.brillig_context.codegen_return(&return_registers); } } } @@ -227,9 +227,7 @@ impl<'block> BrilligBlock<'block> { dfg, ); } - _ => { - todo!("ICE: Param type not supported") - } + Type::Function => todo!("ICE: Type::Function Param not supported"), } } } @@ -250,17 +248,6 @@ impl<'block> BrilligBlock<'block> { self.convert_ssa_binary(binary, dfg, result_var); } Instruction::Constrain(lhs, rhs, assert_message) => { - let condition = SingleAddrVariable { - address: self.brillig_context.allocate_register(), - bit_size: 1, - }; - - self.convert_ssa_binary( - &Binary { lhs: *lhs, rhs: *rhs, operator: BinaryOp::Eq }, - dfg, - condition, - ); - let assert_message = if let Some(error) = assert_message { match error.as_ref() { ConstrainError::Static(string) => Some(string.clone()), @@ -284,8 +271,19 @@ impl<'block> BrilligBlock<'block> { None }; - self.brillig_context.constrain_instruction(condition.address, assert_message); - self.brillig_context.deallocate_register(condition.address); + let condition = SingleAddrVariable { + address: self.brillig_context.allocate_register(), + bit_size: 1, + }; + + self.convert_ssa_binary( + &Binary { lhs: *lhs, rhs: *rhs, operator: BinaryOp::Eq }, + dfg, + condition, + ); + + self.brillig_context.constrain_instruction(condition, assert_message); + self.brillig_context.deallocate_single_addr(condition); } Instruction::Allocate => { let result_value = dfg.instruction_results(instruction_id)[0]; @@ -299,16 +297,15 @@ impl<'block> BrilligBlock<'block> { Type::Reference(element) => match *element { Type::Array(..) => { self.brillig_context - .allocate_array_reference_instruction(address_register.address); + .codegen_allocate_array_reference(address_register.address); } Type::Slice(..) => { self.brillig_context - .allocate_vector_reference_instruction(address_register.address); + .codegen_allocate_vector_reference(address_register.address); } _ => { - self.brillig_context.allocate_single_addr_reference_instruction( - address_register.address, - ); + self.brillig_context + .codegen_allocate_single_addr_reference(address_register.address); } }, _ => { @@ -320,8 +317,7 @@ impl<'block> BrilligBlock<'block> { let address_var = self.convert_ssa_single_addr_value(*address, dfg); let source_variable = self.convert_ssa_value(*value, dfg); - self.brillig_context - .store_variable_instruction(address_var.address, source_variable); + self.brillig_context.codegen_store_variable(address_var.address, source_variable); } Instruction::Load { address } => { let target_variable = self.variables.define_variable( @@ -334,7 +330,7 @@ impl<'block> BrilligBlock<'block> { let address_variable = self.convert_ssa_single_addr_value(*address, dfg); self.brillig_context - .load_variable_instruction(target_variable, address_variable.address); + .codegen_load_variable(target_variable, address_variable.address); } Instruction::Not(value) => { let condition_register = self.convert_ssa_single_addr_value(*value, dfg); @@ -376,16 +372,16 @@ impl<'block> BrilligBlock<'block> { if let ValueOrArray::HeapVector(HeapVector { size, .. }) = output_register { // Update the stack pointer so that we do not overwrite // dynamic memory returned from other external calls - self.brillig_context.update_stack_pointer(*size); + self.brillig_context.increase_free_memory_pointer_instruction(*size); // Update the dynamic slice length maintained in SSA if let ValueOrArray::MemoryAddress(len_index) = output_registers[i - 1] { let element_size = dfg[result_ids[i]].get_type().element_size(); self.brillig_context.mov_instruction(len_index, *size); - self.brillig_context.usize_op_in_place( + self.brillig_context.codegen_usize_op_in_place( len_index, - BinaryIntOp::UnsignedDiv, + BrilligBinaryOp::UnsignedDiv, element_size, ); } else { @@ -455,6 +451,29 @@ impl<'block> BrilligBlock<'block> { self.convert_ssa_array_len(arguments[0], result_variable.address, dfg); } } + Value::Intrinsic(Intrinsic::AsSlice) => { + let source_variable = self.convert_ssa_value(arguments[0], dfg); + let result_ids = dfg.instruction_results(instruction_id); + let destination_len_variable = self.variables.define_single_addr_variable( + self.function_context, + self.brillig_context, + result_ids[0], + dfg, + ); + let destination_variable = self.variables.define_variable( + self.function_context, + self.brillig_context, + result_ids[1], + dfg, + ); + let source_size_as_register = + self.convert_ssa_array_set(source_variable, destination_variable, None); + + // we need to explicitly set the destination_len_variable + self.brillig_context + .mov_instruction(destination_len_variable.address, source_size_as_register); + self.brillig_context.deallocate_register(source_size_as_register); + } Value::Intrinsic( Intrinsic::SlicePushBack | Intrinsic::SlicePopBack @@ -495,14 +514,15 @@ impl<'block> BrilligBlock<'block> { .extract_vector(); // Update the user-facing slice length - self.brillig_context.mov_instruction(target_len.address, limb_count.address); + self.brillig_context.cast_instruction(target_len, limb_count); - self.brillig_context.radix_instruction( - source.address, + self.brillig_context.codegen_to_radix( + source, target_vector, - radix.address, - limb_count.address, + radix, + limb_count, matches!(endianness, Endian::Big), + 8, ); } Value::Intrinsic(Intrinsic::ToBits(endianness)) => { @@ -526,28 +546,27 @@ impl<'block> BrilligBlock<'block> { dfg, ) { BrilligVariable::BrilligArray(array) => { - self.brillig_context.array_to_vector(&array) + self.brillig_context.array_to_vector_instruction(&array) } BrilligVariable::BrilligVector(vector) => vector, BrilligVariable::SingleAddr(..) => unreachable!("ICE: ToBits on non-array"), }; - let radix = self - .brillig_context - .make_constant(2_usize.into(), FieldElement::max_num_bits()); + let radix = self.brillig_context.make_constant_instruction(2_usize.into(), 32); // Update the user-facing slice length - self.brillig_context.mov_instruction(target_len.address, limb_count.address); + self.brillig_context.cast_instruction(target_len, limb_count); - self.brillig_context.radix_instruction( - source.address, + self.brillig_context.codegen_to_radix( + source, target_vector, radix, - limb_count.address, + limb_count, matches!(endianness, Endian::Big), + 1, ); - self.brillig_context.deallocate_register(radix); + self.brillig_context.deallocate_single_addr(radix); } _ => { unreachable!("unsupported function call type {:?}", dfg[*func]) @@ -562,7 +581,7 @@ impl<'block> BrilligBlock<'block> { dfg, ); let source_register = self.convert_ssa_single_addr_value(*value, dfg); - self.brillig_context.truncate_instruction( + self.brillig_context.codegen_truncate( destination_register, source_register, *bit_size, @@ -599,7 +618,7 @@ impl<'block> BrilligBlock<'block> { self.validate_array_index(array_variable, index_variable); self.retrieve_variable_from_array( array_pointer, - index_variable.address, + index_variable, destination_variable, ); } @@ -616,57 +635,74 @@ impl<'block> BrilligBlock<'block> { dfg, ); self.validate_array_index(source_variable, index_register); - - self.convert_ssa_array_set( + let source_size_as_register = self.convert_ssa_array_set( source_variable, destination_variable, - index_register.address, - value_variable, + Some((index_register.address, value_variable)), ); + self.brillig_context.deallocate_register(source_size_as_register); } Instruction::RangeCheck { value, max_bit_size, assert_message } => { let value = self.convert_ssa_single_addr_value(*value, dfg); - // Cast original value to field - let left = SingleAddrVariable { - address: self.brillig_context.allocate_register(), - bit_size: FieldElement::max_num_bits(), - }; - self.convert_cast(left, value); + // SSA generates redundant range checks. A range check with a max bit size >= value.bit_size will always pass. + if value.bit_size > *max_bit_size { + // Cast original value to field + let left = SingleAddrVariable { + address: self.brillig_context.allocate_register(), + bit_size: FieldElement::max_num_bits(), + }; + self.convert_cast(left, value); - // Create a field constant with the max - let max = BigUint::from(2_u128).pow(*max_bit_size) - BigUint::from(1_u128); - let right = self.brillig_context.make_constant( - FieldElement::from_be_bytes_reduce(&max.to_bytes_be()).into(), - FieldElement::max_num_bits(), - ); + // Create a field constant with the max + let max = BigUint::from(2_u128).pow(*max_bit_size) - BigUint::from(1_u128); + let right = self.brillig_context.make_constant_instruction( + FieldElement::from_be_bytes_reduce(&max.to_bytes_be()), + FieldElement::max_num_bits(), + ); - // Check if lte max - let brillig_binary_op = BrilligBinaryOp::Integer { - op: BinaryIntOp::LessThanEquals, - bit_size: FieldElement::max_num_bits(), - }; - let condition = self.brillig_context.allocate_register(); - self.brillig_context.binary_instruction( - left.address, - right, - condition, - brillig_binary_op, - ); + // Check if lte max + let condition = + SingleAddrVariable::new(self.brillig_context.allocate_register(), 1); + self.brillig_context.binary_instruction( + left, + right, + condition, + BrilligBinaryOp::LessThanEquals, + ); - self.brillig_context.constrain_instruction(condition, assert_message.clone()); - self.brillig_context.deallocate_register(condition); - self.brillig_context.deallocate_register(left.address); - self.brillig_context.deallocate_register(right); + self.brillig_context.constrain_instruction(condition, assert_message.clone()); + self.brillig_context.deallocate_single_addr(condition); + self.brillig_context.deallocate_single_addr(left); + self.brillig_context.deallocate_single_addr(right); + } } Instruction::IncrementRc { value } => { let rc_register = match self.convert_ssa_value(*value, dfg) { BrilligVariable::BrilligArray(BrilligArray { rc, .. }) | BrilligVariable::BrilligVector(BrilligVector { rc, .. }) => rc, - _ => unreachable!("ICE: increment rc on non-array"), + other => unreachable!("ICE: increment rc on non-array: {other:?}"), }; - self.brillig_context.usize_op_in_place(rc_register, BinaryIntOp::Add, 1); + self.brillig_context.codegen_usize_op_in_place( + rc_register, + BrilligBinaryOp::Add, + 1, + ); + } + Instruction::DecrementRc { value } => { + let rc_register = match self.convert_ssa_value(*value, dfg) { + BrilligVariable::BrilligArray(BrilligArray { rc, .. }) + | BrilligVariable::BrilligVector(BrilligVector { rc, .. }) => rc, + other => unreachable!("ICE: decrement rc on non-array: {other:?}"), + }; + self.brillig_context.codegen_usize_op_in_place( + rc_register, + BrilligBinaryOp::Sub, + 1, + ); + } + Instruction::EnableSideEffects { .. } => { + todo!("enable_side_effects not supported by brillig") } - _ => todo!("ICE: Instruction not supported {instruction:?}"), }; let dead_variables = self @@ -704,7 +740,7 @@ impl<'block> BrilligBlock<'block> { let saved_registers = self .brillig_context - .pre_call_save_registers_prep_args(&argument_registers, &variables_to_save); + .codegen_pre_call_save_registers_prep_args(&argument_registers, &variables_to_save); // We don't save and restore constants, so we dump them before a external call since the callee might use the registers where they are allocated. self.variables.dump_constants(); @@ -738,7 +774,7 @@ impl<'block> BrilligBlock<'block> { // puts the returns into the returned_registers and restores saved_registers self.brillig_context - .post_call_prep_returns_load_registers(&returned_registers, &saved_registers); + .codegen_post_call_prep_returns_load_registers(&returned_registers, &saved_registers); } fn validate_array_index( @@ -748,48 +784,50 @@ impl<'block> BrilligBlock<'block> { ) { let (size_as_register, should_deallocate_size) = match array_variable { BrilligVariable::BrilligArray(BrilligArray { size, .. }) => { - (self.brillig_context.make_usize_constant(size.into()), true) + (self.brillig_context.make_usize_constant_instruction(size.into()), true) + } + BrilligVariable::BrilligVector(BrilligVector { size, .. }) => { + (SingleAddrVariable::new_usize(size), false) } - BrilligVariable::BrilligVector(BrilligVector { size, .. }) => (size, false), _ => unreachable!("ICE: validate array index on non-array"), }; - let condition = self.brillig_context.allocate_register(); + let condition = SingleAddrVariable::new(self.brillig_context.allocate_register(), 1); - self.brillig_context.memory_op( + self.brillig_context.memory_op_instruction( index_register.address, - size_as_register, - condition, - BinaryIntOp::LessThan, + size_as_register.address, + condition.address, + BrilligBinaryOp::LessThan, ); self.brillig_context .constrain_instruction(condition, Some("Array index out of bounds".to_owned())); if should_deallocate_size { - self.brillig_context.deallocate_register(size_as_register); + self.brillig_context.deallocate_single_addr(size_as_register); } - self.brillig_context.deallocate_register(condition); + self.brillig_context.deallocate_single_addr(condition); } pub(crate) fn retrieve_variable_from_array( &mut self, array_pointer: MemoryAddress, - index_register: MemoryAddress, + index_var: SingleAddrVariable, destination_variable: BrilligVariable, ) { match destination_variable { BrilligVariable::SingleAddr(destination_register) => { - self.brillig_context.array_get( + self.brillig_context.codegen_array_get( array_pointer, - index_register, + index_var, destination_register.address, ); } BrilligVariable::BrilligArray(..) | BrilligVariable::BrilligVector(..) => { let reference = self.brillig_context.allocate_register(); - self.brillig_context.array_get(array_pointer, index_register, reference); - self.brillig_context.load_variable_instruction(destination_variable, reference); + self.brillig_context.codegen_array_get(array_pointer, index_var, reference); + self.brillig_context.codegen_load_variable(destination_variable, reference); self.brillig_context.deallocate_register(reference); } } @@ -797,29 +835,31 @@ impl<'block> BrilligBlock<'block> { /// Array set operation in SSA returns a new array or slice that is a copy of the parameter array or slice /// With a specific value changed. + /// + /// Returns `source_size_as_register`, which is expected to be deallocated with: + /// `self.brillig_context.deallocate_register(source_size_as_register)` fn convert_ssa_array_set( &mut self, source_variable: BrilligVariable, destination_variable: BrilligVariable, - index_register: MemoryAddress, - value_variable: BrilligVariable, - ) { + opt_index_and_value: Option<(MemoryAddress, BrilligVariable)>, + ) -> MemoryAddress { let destination_pointer = match destination_variable { BrilligVariable::BrilligArray(BrilligArray { pointer, .. }) => pointer, BrilligVariable::BrilligVector(BrilligVector { pointer, .. }) => pointer, - _ => unreachable!("ICE: array set returns non-array"), + _ => unreachable!("ICE: array_set SSA returns non-array"), }; let reference_count = match source_variable { BrilligVariable::BrilligArray(BrilligArray { rc, .. }) | BrilligVariable::BrilligVector(BrilligVector { rc, .. }) => rc, - _ => unreachable!("ICE: array set on non-array"), + _ => unreachable!("ICE: array_set SSA on non-array"), }; let (source_pointer, source_size_as_register) = match source_variable { BrilligVariable::BrilligArray(BrilligArray { size, pointer, rc: _ }) => { let source_size_register = self.brillig_context.allocate_register(); - self.brillig_context.usize_const(source_size_register, size.into()); + self.brillig_context.usize_const_instruction(source_size_register, size.into()); (pointer, source_size_register) } BrilligVariable::BrilligVector(BrilligVector { size, pointer, rc: _ }) => { @@ -827,38 +867,40 @@ impl<'block> BrilligBlock<'block> { self.brillig_context.mov_instruction(source_size_register, size); (pointer, source_size_register) } - _ => unreachable!("ICE: array set on non-array"), + _ => unreachable!("ICE: array_set SSA on non-array"), }; - let one = self.brillig_context.make_usize_constant(1_usize.into()); + // Here we want to compare the reference count against 1. + let one = self.brillig_context.make_usize_constant_instruction(1_usize.into()); let condition = self.brillig_context.allocate_register(); - - self.brillig_context.binary_instruction( + self.brillig_context.memory_op_instruction( reference_count, - one, + one.address, condition, - BrilligBinaryOp::Field { op: BinaryFieldOp::Equals }, + BrilligBinaryOp::Equals, ); - - self.brillig_context.branch_instruction(condition, |ctx, cond| { + self.brillig_context.codegen_branch(condition, |ctx, cond| { if cond { // Reference count is 1, we can mutate the array directly ctx.mov_instruction(destination_pointer, source_pointer); } else { // First issue a array copy to the destination - ctx.allocate_array_instruction(destination_pointer, source_size_as_register); + ctx.codegen_allocate_array(destination_pointer, source_size_as_register); - ctx.copy_array_instruction( + ctx.codegen_copy_array( source_pointer, destination_pointer, - source_size_as_register, + SingleAddrVariable::new( + source_size_as_register, + BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, + ), ); } }); match destination_variable { BrilligVariable::BrilligArray(BrilligArray { rc: target_rc, .. }) => { - self.brillig_context.usize_const(target_rc, 1_usize.into()); + self.brillig_context.usize_const_instruction(target_rc, 1_usize.into()); } BrilligVariable::BrilligVector(BrilligVector { size: target_size, @@ -866,41 +908,46 @@ impl<'block> BrilligBlock<'block> { .. }) => { self.brillig_context.mov_instruction(target_size, source_size_as_register); - self.brillig_context.usize_const(target_rc, 1_usize.into()); + self.brillig_context.usize_const_instruction(target_rc, 1_usize.into()); } - _ => unreachable!("ICE: array set on non-array"), + _ => unreachable!("ICE: array_set SSA on non-array"), } - // Then set the value in the newly created array - self.store_variable_in_array(destination_pointer, index_register, value_variable); + if let Some((index_register, value_variable)) = opt_index_and_value { + // Then set the value in the newly created array + self.store_variable_in_array( + destination_pointer, + SingleAddrVariable::new_usize(index_register), + value_variable, + ); + } - self.brillig_context.deallocate_register(source_size_as_register); - self.brillig_context.deallocate_register(one); self.brillig_context.deallocate_register(condition); + source_size_as_register } pub(crate) fn store_variable_in_array_with_ctx( ctx: &mut BrilligContext, destination_pointer: MemoryAddress, - index_register: MemoryAddress, + index_register: SingleAddrVariable, value_variable: BrilligVariable, ) { match value_variable { BrilligVariable::SingleAddr(value_variable) => { - ctx.array_set(destination_pointer, index_register, value_variable.address); + ctx.codegen_array_set(destination_pointer, index_register, value_variable.address); } BrilligVariable::BrilligArray(_) => { let reference: MemoryAddress = ctx.allocate_register(); - ctx.allocate_array_reference_instruction(reference); - ctx.store_variable_instruction(reference, value_variable); - ctx.array_set(destination_pointer, index_register, reference); + ctx.codegen_allocate_array_reference(reference); + ctx.codegen_store_variable(reference, value_variable); + ctx.codegen_array_set(destination_pointer, index_register, reference); ctx.deallocate_register(reference); } BrilligVariable::BrilligVector(_) => { let reference = ctx.allocate_register(); - ctx.allocate_vector_reference_instruction(reference); - ctx.store_variable_instruction(reference, value_variable); - ctx.array_set(destination_pointer, index_register, reference); + ctx.codegen_allocate_vector_reference(reference); + ctx.codegen_store_variable(reference, value_variable); + ctx.codegen_array_set(destination_pointer, index_register, reference); ctx.deallocate_register(reference); } } @@ -909,13 +956,13 @@ impl<'block> BrilligBlock<'block> { pub(crate) fn store_variable_in_array( &mut self, destination_pointer: MemoryAddress, - index_register: MemoryAddress, + index_variable: SingleAddrVariable, value_variable: BrilligVariable, ) { Self::store_variable_in_array_with_ctx( self.brillig_context, destination_pointer, - index_register, + index_variable, value_variable, ); } @@ -958,7 +1005,12 @@ impl<'block> BrilligBlock<'block> { self.convert_ssa_value(*arg, dfg) }); - self.update_slice_length(target_len.address, arguments[0], dfg, BinaryIntOp::Add); + self.update_slice_length( + target_len.address, + arguments[0], + dfg, + BrilligBinaryOp::Add, + ); self.slice_push_back_operation(target_vector, source_vector, &item_values); } @@ -984,7 +1036,12 @@ impl<'block> BrilligBlock<'block> { self.convert_ssa_value(*arg, dfg) }); - self.update_slice_length(target_len.address, arguments[0], dfg, BinaryIntOp::Add); + self.update_slice_length( + target_len.address, + arguments[0], + dfg, + BrilligBinaryOp::Add, + ); self.slice_push_front_operation(target_vector, source_vector, &item_values); } @@ -1017,7 +1074,12 @@ impl<'block> BrilligBlock<'block> { ) }); - self.update_slice_length(target_len.address, arguments[0], dfg, BinaryIntOp::Sub); + self.update_slice_length( + target_len.address, + arguments[0], + dfg, + BrilligBinaryOp::Sub, + ); self.slice_pop_back_operation(target_vector, source_vector, &pop_variables); } @@ -1049,7 +1111,12 @@ impl<'block> BrilligBlock<'block> { ); let target_vector = target_variable.extract_vector(); - self.update_slice_length(target_len.address, arguments[0], dfg, BinaryIntOp::Sub); + self.update_slice_length( + target_len.address, + arguments[0], + dfg, + BrilligBinaryOp::Sub, + ); self.slice_pop_front_operation(target_vector, source_vector, &pop_variables); } @@ -1078,23 +1145,29 @@ impl<'block> BrilligBlock<'block> { // https://github.com/noir-lang/noir/issues/1889#issuecomment-1668048587 let user_index = self.convert_ssa_single_addr_value(arguments[2], dfg); - let converted_index = self.brillig_context.make_usize_constant(element_size.into()); + let converted_index = + self.brillig_context.make_usize_constant_instruction(element_size.into()); - self.brillig_context.memory_op( - converted_index, + self.brillig_context.memory_op_instruction( + converted_index.address, user_index.address, - converted_index, - BinaryIntOp::Mul, + converted_index.address, + BrilligBinaryOp::Mul, ); let items = vecmap(&arguments[3..element_size + 3], |arg| { self.convert_ssa_value(*arg, dfg) }); - self.update_slice_length(target_len.address, arguments[0], dfg, BinaryIntOp::Add); + self.update_slice_length( + target_len.address, + arguments[0], + dfg, + BrilligBinaryOp::Add, + ); self.slice_insert_operation(target_vector, source_vector, converted_index, &items); - self.brillig_context.deallocate_register(converted_index); + self.brillig_context.deallocate_single_addr(converted_index); } Value::Intrinsic(Intrinsic::SliceRemove) => { let target_len = match self.variables.define_variable( @@ -1121,12 +1194,13 @@ impl<'block> BrilligBlock<'block> { // https://github.com/noir-lang/noir/issues/1889#issuecomment-1668048587 let user_index = self.convert_ssa_single_addr_value(arguments[2], dfg); - let converted_index = self.brillig_context.make_usize_constant(element_size.into()); - self.brillig_context.memory_op( - converted_index, + let converted_index = + self.brillig_context.make_usize_constant_instruction(element_size.into()); + self.brillig_context.memory_op_instruction( + converted_index.address, user_index.address, - converted_index, - BinaryIntOp::Mul, + converted_index.address, + BrilligBinaryOp::Mul, ); let removed_items = vecmap(&results[2..element_size + 2], |result| { @@ -1138,7 +1212,12 @@ impl<'block> BrilligBlock<'block> { ) }); - self.update_slice_length(target_len.address, arguments[0], dfg, BinaryIntOp::Sub); + self.update_slice_length( + target_len.address, + arguments[0], + dfg, + BrilligBinaryOp::Sub, + ); self.slice_remove_operation( target_vector, @@ -1147,7 +1226,7 @@ impl<'block> BrilligBlock<'block> { &removed_items, ); - self.brillig_context.deallocate_register(converted_index); + self.brillig_context.deallocate_single_addr(converted_index); } _ => unreachable!("ICE: Slice operation not supported"), } @@ -1167,12 +1246,12 @@ impl<'block> BrilligBlock<'block> { target_len: MemoryAddress, source_value: ValueId, dfg: &DataFlowGraph, - binary_op: BinaryIntOp, + binary_op: BrilligBinaryOp, ) { let source_len_variable = self.convert_ssa_value(source_value, dfg); let source_len = source_len_variable.extract_single_addr(); - self.brillig_context.usize_op(source_len.address, target_len, binary_op, 1); + self.brillig_context.codegen_usize_op(source_len.address, target_len, binary_op, 1); } /// Converts an SSA cast to a sequence of Brillig opcodes. @@ -1197,15 +1276,292 @@ impl<'block> BrilligBlock<'block> { let left = self.convert_ssa_single_addr_value(binary.lhs, dfg); let right = self.convert_ssa_single_addr_value(binary.rhs, dfg); - let brillig_binary_op = - convert_ssa_binary_op_to_brillig_binary_op(binary.operator, &binary_type); + let (is_field, is_signed) = match binary_type { + Type::Numeric(numeric_type) => match numeric_type { + NumericType::Signed { .. } => (false, true), + NumericType::Unsigned { .. } => (false, false), + NumericType::NativeField => (true, false), + }, + _ => unreachable!("only numeric types are allowed in binary operations. References are handled separately"), + }; + + let brillig_binary_op = match binary.operator { + BinaryOp::Div => { + if is_signed { + self.convert_signed_division(left, right, result_variable); + return; + } else if is_field { + BrilligBinaryOp::FieldDiv + } else { + BrilligBinaryOp::UnsignedDiv + } + } + BinaryOp::Mod => { + if is_signed { + self.convert_signed_modulo(left, right, result_variable); + return; + } else { + BrilligBinaryOp::Modulo + } + } + BinaryOp::Add => BrilligBinaryOp::Add, + BinaryOp::Sub => BrilligBinaryOp::Sub, + BinaryOp::Mul => BrilligBinaryOp::Mul, + BinaryOp::Eq => BrilligBinaryOp::Equals, + BinaryOp::Lt => { + if is_signed { + self.convert_signed_less_than(left, right, result_variable); + return; + } else { + BrilligBinaryOp::LessThan + } + } + BinaryOp::And => BrilligBinaryOp::And, + BinaryOp::Or => BrilligBinaryOp::Or, + BinaryOp::Xor => BrilligBinaryOp::Xor, + BinaryOp::Shl => BrilligBinaryOp::Shl, + BinaryOp::Shr => BrilligBinaryOp::Shr, + }; + + self.brillig_context.binary_instruction(left, right, result_variable, brillig_binary_op); + + self.add_overflow_check(brillig_binary_op, left, right, result_variable, is_signed); + } + + /// Splits a two's complement signed integer in the sign bit and the absolute value. + /// For example, -6 i8 (11111010) is split to 00000110 (6, absolute value) and 1 (is_negative). + fn absolute_value( + &mut self, + num: SingleAddrVariable, + absolute_value: SingleAddrVariable, + result_is_negative: SingleAddrVariable, + ) { + let max_positive = self + .brillig_context + .make_constant_instruction(((1_u128 << (num.bit_size - 1)) - 1).into(), num.bit_size); + + // Compute if num is negative + self.brillig_context.binary_instruction( + max_positive, + num, + result_is_negative, + BrilligBinaryOp::LessThan, + ); + + // Two's complement of num + let zero = self.brillig_context.make_constant_instruction(0_usize.into(), num.bit_size); + let twos_complement = + SingleAddrVariable::new(self.brillig_context.allocate_register(), num.bit_size); + self.brillig_context.binary_instruction(zero, num, twos_complement, BrilligBinaryOp::Sub); + + // absolute_value = result_is_negative ? twos_complement : num + self.brillig_context.conditional_mov_instruction( + absolute_value.address, + result_is_negative.address, + twos_complement.address, + num.address, + ); + + self.brillig_context.deallocate_single_addr(zero); + self.brillig_context.deallocate_single_addr(max_positive); + self.brillig_context.deallocate_single_addr(twos_complement); + } + + fn convert_signed_division( + &mut self, + left: SingleAddrVariable, + right: SingleAddrVariable, + result: SingleAddrVariable, + ) { + let left_is_negative = SingleAddrVariable::new(self.brillig_context.allocate_register(), 1); + let left_abs_value = + SingleAddrVariable::new(self.brillig_context.allocate_register(), left.bit_size); + + let right_is_negative = + SingleAddrVariable::new(self.brillig_context.allocate_register(), 1); + let right_abs_value = + SingleAddrVariable::new(self.brillig_context.allocate_register(), right.bit_size); + + let result_is_negative = + SingleAddrVariable::new(self.brillig_context.allocate_register(), 1); + + // Compute both absolute values + self.absolute_value(left, left_abs_value, left_is_negative); + self.absolute_value(right, right_abs_value, right_is_negative); + + // Perform the division on the absolute values + self.brillig_context.binary_instruction( + left_abs_value, + right_abs_value, + result, + BrilligBinaryOp::UnsignedDiv, + ); + + // Compute result sign + self.brillig_context.binary_instruction( + left_is_negative, + right_is_negative, + result_is_negative, + BrilligBinaryOp::Xor, + ); + + // If result has to be negative, perform two's complement + self.brillig_context.codegen_if(result_is_negative.address, |ctx| { + let zero = ctx.make_constant_instruction(0_usize.into(), result.bit_size); + ctx.binary_instruction(zero, result, result, BrilligBinaryOp::Sub); + ctx.deallocate_single_addr(zero); + }); + + self.brillig_context.deallocate_single_addr(left_is_negative); + self.brillig_context.deallocate_single_addr(left_abs_value); + self.brillig_context.deallocate_single_addr(right_is_negative); + self.brillig_context.deallocate_single_addr(right_abs_value); + self.brillig_context.deallocate_single_addr(result_is_negative); + } + + fn convert_signed_modulo( + &mut self, + left: SingleAddrVariable, + right: SingleAddrVariable, + result: SingleAddrVariable, + ) { + let scratch_var_i = + SingleAddrVariable::new(self.brillig_context.allocate_register(), left.bit_size); + let scratch_var_j = + SingleAddrVariable::new(self.brillig_context.allocate_register(), left.bit_size); + + // i = left / right + self.convert_signed_division(left, right, scratch_var_i); + // j = i * right self.brillig_context.binary_instruction( - left.address, - right.address, - result_variable.address, - brillig_binary_op, + scratch_var_i, + right, + scratch_var_j, + BrilligBinaryOp::Mul, ); + + // result_register = left - j + self.brillig_context.binary_instruction(left, scratch_var_j, result, BrilligBinaryOp::Sub); + // Free scratch registers + self.brillig_context.deallocate_single_addr(scratch_var_i); + self.brillig_context.deallocate_single_addr(scratch_var_j); + } + + fn convert_signed_less_than( + &mut self, + left: SingleAddrVariable, + right: SingleAddrVariable, + result: SingleAddrVariable, + ) { + let biased_left = + SingleAddrVariable::new(self.brillig_context.allocate_register(), left.bit_size); + let biased_right = + SingleAddrVariable::new(self.brillig_context.allocate_register(), right.bit_size); + + let bias = self + .brillig_context + .make_constant_instruction((1_u128 << (left.bit_size - 1)).into(), left.bit_size); + + self.brillig_context.binary_instruction(left, bias, biased_left, BrilligBinaryOp::Add); + self.brillig_context.binary_instruction(right, bias, biased_right, BrilligBinaryOp::Add); + + self.brillig_context.binary_instruction( + biased_left, + biased_right, + result, + BrilligBinaryOp::LessThan, + ); + + self.brillig_context.deallocate_single_addr(biased_left); + self.brillig_context.deallocate_single_addr(biased_right); + self.brillig_context.deallocate_single_addr(bias); + } + + fn add_overflow_check( + &mut self, + binary_operation: BrilligBinaryOp, + left: SingleAddrVariable, + right: SingleAddrVariable, + result: SingleAddrVariable, + is_signed: bool, + ) { + let bit_size = left.bit_size; + + if bit_size == FieldElement::max_num_bits() { + return; + } + + match (binary_operation, is_signed) { + (BrilligBinaryOp::Add, false) => { + let condition = + SingleAddrVariable::new(self.brillig_context.allocate_register(), 1); + // Check that lhs <= result + self.brillig_context.binary_instruction( + left, + result, + condition, + BrilligBinaryOp::LessThanEquals, + ); + self.brillig_context.constrain_instruction( + condition, + Some("attempt to add with overflow".to_string()), + ); + self.brillig_context.deallocate_single_addr(condition); + } + (BrilligBinaryOp::Sub, false) => { + let condition = + SingleAddrVariable::new(self.brillig_context.allocate_register(), 1); + // Check that rhs <= lhs + self.brillig_context.binary_instruction( + right, + left, + condition, + BrilligBinaryOp::LessThanEquals, + ); + self.brillig_context.constrain_instruction( + condition, + Some("attempt to subtract with overflow".to_string()), + ); + self.brillig_context.deallocate_single_addr(condition); + } + (BrilligBinaryOp::Mul, false) => { + // Multiplication overflow is only possible for bit sizes > 1 + if bit_size > 1 { + let is_right_zero = + SingleAddrVariable::new(self.brillig_context.allocate_register(), 1); + let zero = + self.brillig_context.make_constant_instruction(0_usize.into(), bit_size); + self.brillig_context.binary_instruction( + zero, + right, + is_right_zero, + BrilligBinaryOp::Equals, + ); + self.brillig_context.codegen_if_not(is_right_zero.address, |ctx| { + let condition = SingleAddrVariable::new(ctx.allocate_register(), 1); + let division = SingleAddrVariable::new(ctx.allocate_register(), bit_size); + // Check that result / rhs == lhs + ctx.binary_instruction( + result, + right, + division, + BrilligBinaryOp::UnsignedDiv, + ); + ctx.binary_instruction(division, left, condition, BrilligBinaryOp::Equals); + ctx.constrain_instruction( + condition, + Some("attempt to multiply with overflow".to_string()), + ); + ctx.deallocate_single_addr(condition); + ctx.deallocate_single_addr(division); + }); + self.brillig_context.deallocate_single_addr(is_right_zero); + self.brillig_context.deallocate_single_addr(zero); + } + } + _ => {} + } } /// Converts an SSA `ValueId` into a `RegisterOrMemory`. Initializes if necessary. @@ -1217,9 +1573,10 @@ impl<'block> BrilligBlock<'block> { Value::Param { .. } | Value::Instruction { .. } => { // All block parameters and instruction results should have already been // converted to registers so we fetch from the cache. + self.variables.get_allocation(self.function_context, value_id, dfg) } - Value::NumericConstant { constant, typ } => { + Value::NumericConstant { constant, .. } => { // Constants might have been converted previously or not, so we get or create and // (re)initialize the value inside. if let Some(variable) = self.variables.get_constant(value_id, dfg) { @@ -1227,13 +1584,9 @@ impl<'block> BrilligBlock<'block> { } else { let new_variable = self.variables.allocate_constant(self.brillig_context, value_id, dfg); - let register_index = new_variable.extract_single_addr(); - self.brillig_context.const_instruction( - register_index.address, - (*constant).into(), - get_bit_size_from_ssa_type(typ), - ); + self.brillig_context + .const_instruction(new_variable.extract_single_addr(), *constant); new_variable } } @@ -1247,17 +1600,21 @@ impl<'block> BrilligBlock<'block> { // Initialize the variable let pointer = match new_variable { BrilligVariable::BrilligArray(brillig_array) => { + self.brillig_context.codegen_allocate_fixed_length_array( + brillig_array.pointer, + array.len(), + ); self.brillig_context - .allocate_fixed_length_array(brillig_array.pointer, array.len()); - self.brillig_context.usize_const(brillig_array.rc, 1_usize.into()); + .usize_const_instruction(brillig_array.rc, 1_usize.into()); brillig_array.pointer } BrilligVariable::BrilligVector(vector) => { - self.brillig_context.usize_const(vector.size, array.len().into()); self.brillig_context - .allocate_array_instruction(vector.pointer, vector.size); - self.brillig_context.usize_const(vector.rc, 1_usize.into()); + .usize_const_instruction(vector.size, array.len().into()); + self.brillig_context + .codegen_allocate_array(vector.pointer, vector.size); + self.brillig_context.usize_const_instruction(vector.rc, 1_usize.into()); vector.pointer } @@ -1270,21 +1627,21 @@ impl<'block> BrilligBlock<'block> { // Allocate a register for the iterator let iterator_register = - self.brillig_context.make_usize_constant(0_usize.into()); + self.brillig_context.make_usize_constant_instruction(0_usize.into()); for element_id in array.iter() { let element_variable = self.convert_ssa_value(*element_id, dfg); // Store the item in memory self.store_variable_in_array(pointer, iterator_register, element_variable); // Increment the iterator - self.brillig_context.usize_op_in_place( - iterator_register, - BinaryIntOp::Add, + self.brillig_context.codegen_usize_op_in_place( + iterator_register.address, + BrilligBinaryOp::Add, 1, ); } - self.brillig_context.deallocate_register(iterator_register); + self.brillig_context.deallocate_single_addr(iterator_register); new_variable } @@ -1296,12 +1653,10 @@ impl<'block> BrilligBlock<'block> { // value. let new_variable = self.variables.allocate_constant(self.brillig_context, value_id, dfg); - let register_index = new_variable.extract_single_addr(); self.brillig_context.const_instruction( - register_index.address, + new_variable.extract_single_addr(), value_id.to_usize().into(), - 32, ); new_variable } @@ -1343,8 +1698,8 @@ impl<'block> BrilligBlock<'block> { dfg, ); let array = variable.extract_array(); - self.brillig_context.allocate_fixed_length_array(array.pointer, array.size); - self.brillig_context.usize_const(array.rc, 1_usize.into()); + self.brillig_context.codegen_allocate_fixed_length_array(array.pointer, array.size); + self.brillig_context.usize_const_instruction(array.rc, 1_usize.into()); variable } @@ -1360,8 +1715,8 @@ impl<'block> BrilligBlock<'block> { // Set the pointer to the current stack frame // The stack pointer will then be updated by the caller of this method // once the external call is resolved and the array size is known - self.brillig_context.set_array_pointer(vector.pointer); - self.brillig_context.usize_const(vector.rc, 1_usize.into()); + self.brillig_context.load_free_memory_pointer_instruction(vector.pointer); + self.brillig_context.usize_const_instruction(vector.rc, 1_usize.into()); variable } @@ -1385,13 +1740,14 @@ impl<'block> BrilligBlock<'block> { match array_variable { BrilligVariable::BrilligArray(BrilligArray { size, .. }) => { - self.brillig_context.usize_const(result_register, (size / element_size).into()); + self.brillig_context + .usize_const_instruction(result_register, (size / element_size).into()); } BrilligVariable::BrilligVector(BrilligVector { size, .. }) => { - self.brillig_context.usize_op( + self.brillig_context.codegen_usize_op( size, result_register, - BinaryIntOp::UnsignedDiv, + BrilligBinaryOp::UnsignedDiv, element_size, ); } @@ -1403,8 +1759,6 @@ impl<'block> BrilligBlock<'block> { } /// Returns the type of the operation considering the types of the operands -/// TODO: SSA issues binary operations between fields and integers. -/// This probably should be explicitly casted in SSA to avoid having to coerce at this level. pub(crate) fn type_of_binary_operation(lhs_type: &Type, rhs_type: &Type) -> Type { match (lhs_type, rhs_type) { (_, Type::Function) | (Type::Function, _) => { @@ -1419,10 +1773,6 @@ pub(crate) fn type_of_binary_operation(lhs_type: &Type, rhs_type: &Type) -> Type (_, Type::Slice(..)) | (Type::Slice(..), _) => { unreachable!("Arrays are invalid in binary operations") } - // If either side is a Field constant then, we coerce into the type - // of the other operand - (Type::Numeric(NumericType::NativeField), typ) - | (typ, Type::Numeric(NumericType::NativeField)) => typ.clone(), // If both sides are numeric type, then we expect their types to be // the same. (Type::Numeric(lhs_type), Type::Numeric(rhs_type)) => { @@ -1434,73 +1784,3 @@ pub(crate) fn type_of_binary_operation(lhs_type: &Type, rhs_type: &Type) -> Type } } } - -/// Convert an SSA binary operation into: -/// - Brillig Binary Integer Op, if it is a integer type -/// - Brillig Binary Field Op, if it is a field type -pub(crate) fn convert_ssa_binary_op_to_brillig_binary_op( - ssa_op: BinaryOp, - typ: &Type, -) -> BrilligBinaryOp { - // First get the bit size and whether its a signed integer, if it is a numeric type - // if it is not,then we return None, indicating that - // it is a Field. - let bit_size_signedness = match typ { - Type::Numeric(numeric_type) => match numeric_type { - NumericType::Signed { bit_size } => Some((bit_size, true)), - NumericType::Unsigned { bit_size } => Some((bit_size, false)), - NumericType::NativeField => None, - }, - _ => unreachable!("only numeric types are allowed in binary operations. References are handled separately"), - }; - - fn binary_op_to_field_op(op: BinaryOp) -> BrilligBinaryOp { - match op { - BinaryOp::Add => BrilligBinaryOp::Field { op: BinaryFieldOp::Add }, - BinaryOp::Sub => BrilligBinaryOp::Field { op: BinaryFieldOp::Sub }, - BinaryOp::Mul => BrilligBinaryOp::Field { op: BinaryFieldOp::Mul }, - BinaryOp::Div => BrilligBinaryOp::Field { op: BinaryFieldOp::Div }, - BinaryOp::Eq => BrilligBinaryOp::Field { op: BinaryFieldOp::Equals }, - BinaryOp::Lt => BrilligBinaryOp::Integer { - op: BinaryIntOp::LessThan, - bit_size: BRILLIG_INTEGER_ARITHMETIC_BIT_SIZE, - }, - _ => unreachable!( - "Field type cannot be used with {op}. This should have been caught by the frontend" - ), - } - } - - fn binary_op_to_int_op(op: BinaryOp, bit_size: u32, is_signed: bool) -> BrilligBinaryOp { - let operation = match op { - BinaryOp::Add => BinaryIntOp::Add, - BinaryOp::Sub => BinaryIntOp::Sub, - BinaryOp::Mul => BinaryIntOp::Mul, - BinaryOp::Div => { - if is_signed { - BinaryIntOp::SignedDiv - } else { - BinaryIntOp::UnsignedDiv - } - } - BinaryOp::Mod => { - return BrilligBinaryOp::Modulo { is_signed_integer: is_signed, bit_size } - } - BinaryOp::Eq => BinaryIntOp::Equals, - BinaryOp::Lt => BinaryIntOp::LessThan, - BinaryOp::And => BinaryIntOp::And, - BinaryOp::Or => BinaryIntOp::Or, - BinaryOp::Xor => BinaryIntOp::Xor, - BinaryOp::Shl => BinaryIntOp::Shl, - BinaryOp::Shr => BinaryIntOp::Shr, - }; - - BrilligBinaryOp::Integer { op: operation, bit_size } - } - - // If bit size is available then it is a binary integer operation - match bit_size_signedness { - Some((bit_size, is_signed)) => binary_op_to_int_op(ssa_op, *bit_size, is_signed), - None => binary_op_to_field_op(ssa_op), - } -} diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block_variables.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block_variables.rs index f463bd4de4d..892e82d771a 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block_variables.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block_variables.rs @@ -2,8 +2,11 @@ use fxhash::{FxHashMap as HashMap, FxHashSet as HashSet}; use crate::{ brillig::brillig_ir::{ - brillig_variable::{BrilligArray, BrilligVariable, BrilligVector, SingleAddrVariable}, - BrilligContext, BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, + brillig_variable::{ + get_bit_size_from_ssa_type, BrilligArray, BrilligVariable, BrilligVector, + SingleAddrVariable, + }, + BrilligContext, }, ssa::ir::{ basic_block::BasicBlockId, @@ -189,21 +192,10 @@ pub(crate) fn allocate_value( let typ = dfg.type_of_value(value_id); match typ { - Type::Numeric(numeric_type) => BrilligVariable::SingleAddr(SingleAddrVariable { - address: brillig_context.allocate_register(), - bit_size: numeric_type.bit_size(), - }), - Type::Reference(_) => BrilligVariable::SingleAddr(SingleAddrVariable { - address: brillig_context.allocate_register(), - bit_size: BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, - }), - Type::Function => { - // NB. function references are converted to a constant when - // translating from SSA to Brillig (to allow for debugger - // instrumentation to work properly) + Type::Numeric(_) | Type::Reference(_) | Type::Function => { BrilligVariable::SingleAddr(SingleAddrVariable { address: brillig_context.allocate_register(), - bit_size: 32, + bit_size: get_bit_size_from_ssa_type(&typ), }) } Type::Array(item_typ, elem_count) => { diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_directive.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_directive.rs index 93c4b1a5042..15a2a531e78 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_directive.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_directive.rs @@ -1,5 +1,5 @@ use acvm::{ - acir::brillig::{BinaryFieldOp, BinaryIntOp, MemoryAddress, Opcode as BrilligOpcode, Value}, + acir::brillig::{BinaryFieldOp, BinaryIntOp, MemoryAddress, Opcode as BrilligOpcode}, FieldElement, }; @@ -16,18 +16,32 @@ pub(crate) fn directive_invert() -> GeneratedBrillig { // We store the result in this register too. let input = MemoryAddress::from(0); let one_const = MemoryAddress::from(1); + let zero_const = MemoryAddress::from(2); + let input_is_zero = MemoryAddress::from(3); // Location of the stop opcode - let stop_location = 3; + let stop_location = 6; GeneratedBrillig { byte_code: vec![ BrilligOpcode::CalldataCopy { destination_address: input, size: 1, offset: 0 }, + // Put value zero in register (2) + BrilligOpcode::Const { + destination: zero_const, + value: FieldElement::from(0_usize), + bit_size: FieldElement::max_num_bits(), + }, + BrilligOpcode::BinaryFieldOp { + op: BinaryFieldOp::Equals, + lhs: input, + rhs: zero_const, + destination: input_is_zero, + }, // If the input is zero, then we jump to the stop opcode - BrilligOpcode::JumpIfNot { condition: input, location: stop_location }, + BrilligOpcode::JumpIf { condition: input_is_zero, location: stop_location }, // Put value one in register (1) BrilligOpcode::Const { destination: one_const, - value: Value::from(1_usize), + value: FieldElement::from(1_usize), bit_size: FieldElement::max_num_bits(), }, // Divide 1 by the input, and set the result of the division into register (0) @@ -53,9 +67,12 @@ pub(crate) fn directive_invert() -> GeneratedBrillig { /// (a/b, a-a/b*b) /// } /// ``` -pub(crate) fn directive_quotient(bit_size: u32) -> GeneratedBrillig { +pub(crate) fn directive_quotient(mut bit_size: u32) -> GeneratedBrillig { // `a` is (0) (i.e register index 0) // `b` is (1) + if bit_size > FieldElement::max_num_bits() { + bit_size = FieldElement::max_num_bits(); + } GeneratedBrillig { byte_code: vec![ BrilligOpcode::CalldataCopy { @@ -63,9 +80,19 @@ pub(crate) fn directive_quotient(bit_size: u32) -> GeneratedBrillig { size: 2, offset: 0, }, + BrilligOpcode::Cast { + destination: MemoryAddress(0), + source: MemoryAddress(0), + bit_size, + }, + BrilligOpcode::Cast { + destination: MemoryAddress(1), + source: MemoryAddress(1), + bit_size, + }, //q = a/b is set into register (2) BrilligOpcode::BinaryIntOp { - op: BinaryIntOp::UnsignedDiv, + op: BinaryIntOp::Div, lhs: MemoryAddress::from(0), rhs: MemoryAddress::from(1), destination: MemoryAddress::from(2), diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_fn.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_fn.rs index b5da8296ba5..617e400b92f 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_fn.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_fn.rs @@ -1,17 +1,16 @@ -use acvm::FieldElement; use iter_extended::vecmap; use crate::{ brillig::brillig_ir::{ artifact::{BrilligParameter, Label}, - brillig_variable::BrilligVariable, - BrilligContext, BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, + brillig_variable::{get_bit_size_from_ssa_type, BrilligVariable}, + BrilligContext, }, ssa::ir::{ basic_block::BasicBlockId, function::{Function, FunctionId}, post_order::PostOrder, - types::{NumericType, Type}, + types::Type, value::ValueId, }, }; @@ -71,7 +70,7 @@ impl FunctionContext { function_id.to_string() } - fn ssa_type_to_parameter(typ: &Type) -> BrilligParameter { + pub(crate) fn ssa_type_to_parameter(typ: &Type) -> BrilligParameter { match typ { Type::Numeric(_) | Type::Reference(_) => { BrilligParameter::SingleAddr(get_bit_size_from_ssa_type(typ)) @@ -82,26 +81,13 @@ impl FunctionContext { }), *size, ), - Type::Slice(item_type) => { - BrilligParameter::Slice(vecmap(item_type.iter(), |item_typ| { - FunctionContext::ssa_type_to_parameter(item_typ) - })) + Type::Slice(_) => { + panic!("ICE: Slice parameters cannot be derived from type information") } _ => unimplemented!("Unsupported function parameter/return type {typ:?}"), } } - /// Collects the parameters of a given function - pub(crate) fn parameters(func: &Function) -> Vec { - func.parameters() - .iter() - .map(|&value_id| { - let typ = func.dfg.type_of_value(value_id); - FunctionContext::ssa_type_to_parameter(&typ) - }) - .collect() - } - /// Collects the return values of a given function pub(crate) fn return_values(func: &Function) -> Vec { func.returns() @@ -113,14 +99,3 @@ impl FunctionContext { .collect() } } - -pub(crate) fn get_bit_size_from_ssa_type(typ: &Type) -> u32 { - match typ { - Type::Numeric(num_type) => match num_type { - NumericType::Signed { bit_size } | NumericType::Unsigned { bit_size } => *bit_size, - NumericType::NativeField => FieldElement::max_num_bits(), - }, - Type::Reference(_) => BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, - _ => unreachable!("ICE bitwise not on a non numeric type"), - } -} diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_slice_ops.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_slice_ops.rs index 3fc0e981165..b93693d9c79 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_slice_ops.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_slice_ops.rs @@ -1,6 +1,7 @@ -use acvm::brillig_vm::brillig::{BinaryIntOp, MemoryAddress}; - -use crate::brillig::brillig_ir::brillig_variable::{BrilligVariable, BrilligVector}; +use crate::brillig::brillig_ir::{ + brillig_variable::{BrilligVariable, BrilligVector, SingleAddrVariable}, + BrilligBinaryOp, +}; use super::brillig_block::BrilligBlock; @@ -12,33 +13,33 @@ impl<'block> BrilligBlock<'block> { variables_to_insert: &[BrilligVariable], ) { // First we need to allocate the target vector incrementing the size by variables_to_insert.len() - self.brillig_context.usize_op( + self.brillig_context.codegen_usize_op( source_vector.size, target_vector.size, - BinaryIntOp::Add, + BrilligBinaryOp::Add, variables_to_insert.len(), ); - self.brillig_context.allocate_array_instruction(target_vector.pointer, target_vector.size); + self.brillig_context.codegen_allocate_array(target_vector.pointer, target_vector.size); // We initialize the RC of the target vector to 1 - self.brillig_context.usize_const(target_vector.rc, 1_usize.into()); + self.brillig_context.usize_const_instruction(target_vector.rc, 1_usize.into()); // Now we copy the source vector into the target vector - self.brillig_context.copy_array_instruction( + self.brillig_context.codegen_copy_array( source_vector.pointer, target_vector.pointer, - source_vector.size, + SingleAddrVariable::new_usize(source_vector.size), ); for (index, variable) in variables_to_insert.iter().enumerate() { - let target_index = self.brillig_context.make_usize_constant(index.into()); - self.brillig_context.memory_op( - target_index, + let target_index = self.brillig_context.make_usize_constant_instruction(index.into()); + self.brillig_context.memory_op_instruction( + target_index.address, source_vector.size, - target_index, - BinaryIntOp::Add, + target_index.address, + BrilligBinaryOp::Add, ); self.store_variable_in_array(target_vector.pointer, target_index, *variable); - self.brillig_context.deallocate_register(target_index); + self.brillig_context.deallocate_single_addr(target_index); } } @@ -49,37 +50,37 @@ impl<'block> BrilligBlock<'block> { variables_to_insert: &[BrilligVariable], ) { // First we need to allocate the target vector incrementing the size by variables_to_insert.len() - self.brillig_context.usize_op( + self.brillig_context.codegen_usize_op( source_vector.size, target_vector.size, - BinaryIntOp::Add, + BrilligBinaryOp::Add, variables_to_insert.len(), ); - self.brillig_context.allocate_array_instruction(target_vector.pointer, target_vector.size); + self.brillig_context.codegen_allocate_array(target_vector.pointer, target_vector.size); // We initialize the RC of the target vector to 1 - self.brillig_context.usize_const(target_vector.rc, 1_usize.into()); + self.brillig_context.usize_const_instruction(target_vector.rc, 1_usize.into()); // Now we offset the target pointer by variables_to_insert.len() let destination_copy_pointer = self.brillig_context.allocate_register(); - self.brillig_context.usize_op( + self.brillig_context.codegen_usize_op( target_vector.pointer, destination_copy_pointer, - BinaryIntOp::Add, + BrilligBinaryOp::Add, variables_to_insert.len(), ); // Now we copy the source vector into the target vector starting at index variables_to_insert.len() - self.brillig_context.copy_array_instruction( + self.brillig_context.codegen_copy_array( source_vector.pointer, destination_copy_pointer, - source_vector.size, + SingleAddrVariable::new_usize(source_vector.size), ); // Then we write the items to insert at the start for (index, variable) in variables_to_insert.iter().enumerate() { - let target_index = self.brillig_context.make_usize_constant(index.into()); + let target_index = self.brillig_context.make_usize_constant_instruction(index.into()); self.store_variable_in_array(target_vector.pointer, target_index, *variable); - self.brillig_context.deallocate_register(target_index); + self.brillig_context.deallocate_single_addr(target_index); } self.brillig_context.deallocate_register(destination_copy_pointer); @@ -92,36 +93,36 @@ impl<'block> BrilligBlock<'block> { removed_items: &[BrilligVariable], ) { // First we need to allocate the target vector decrementing the size by removed_items.len() - self.brillig_context.usize_op( + self.brillig_context.codegen_usize_op( source_vector.size, target_vector.size, - BinaryIntOp::Sub, + BrilligBinaryOp::Sub, removed_items.len(), ); - self.brillig_context.allocate_array_instruction(target_vector.pointer, target_vector.size); + self.brillig_context.codegen_allocate_array(target_vector.pointer, target_vector.size); // We initialize the RC of the target vector to 1 - self.brillig_context.usize_const(target_vector.rc, 1_usize.into()); + self.brillig_context.usize_const_instruction(target_vector.rc, 1_usize.into()); // Now we offset the source pointer by removed_items.len() let source_copy_pointer = self.brillig_context.allocate_register(); - self.brillig_context.usize_op( + self.brillig_context.codegen_usize_op( source_vector.pointer, source_copy_pointer, - BinaryIntOp::Add, + BrilligBinaryOp::Add, removed_items.len(), ); // Now we copy the source vector starting at index removed_items.len() into the target vector - self.brillig_context.copy_array_instruction( + self.brillig_context.codegen_copy_array( source_copy_pointer, target_vector.pointer, - target_vector.size, + SingleAddrVariable::new_usize(target_vector.size), ); for (index, variable) in removed_items.iter().enumerate() { - let target_index = self.brillig_context.make_usize_constant(index.into()); + let target_index = self.brillig_context.make_usize_constant_instruction(index.into()); self.retrieve_variable_from_array(source_vector.pointer, target_index, *variable); - self.brillig_context.deallocate_register(target_index); + self.brillig_context.deallocate_single_addr(target_index); } self.brillig_context.deallocate_register(source_copy_pointer); @@ -134,33 +135,33 @@ impl<'block> BrilligBlock<'block> { removed_items: &[BrilligVariable], ) { // First we need to allocate the target vector decrementing the size by removed_items.len() - self.brillig_context.usize_op( + self.brillig_context.codegen_usize_op( source_vector.size, target_vector.size, - BinaryIntOp::Sub, + BrilligBinaryOp::Sub, removed_items.len(), ); - self.brillig_context.allocate_array_instruction(target_vector.pointer, target_vector.size); + self.brillig_context.codegen_allocate_array(target_vector.pointer, target_vector.size); // We initialize the RC of the target vector to 1 - self.brillig_context.usize_const(target_vector.rc, 1_usize.into()); + self.brillig_context.usize_const_instruction(target_vector.rc, 1_usize.into()); // Now we copy all elements except the last items into the target vector - self.brillig_context.copy_array_instruction( + self.brillig_context.codegen_copy_array( source_vector.pointer, target_vector.pointer, - target_vector.size, + SingleAddrVariable::new_usize(target_vector.size), ); for (index, variable) in removed_items.iter().enumerate() { - let target_index = self.brillig_context.make_usize_constant(index.into()); - self.brillig_context.memory_op( - target_index, + let target_index = self.brillig_context.make_usize_constant_instruction(index.into()); + self.brillig_context.memory_op_instruction( + target_index.address, target_vector.size, - target_index, - BinaryIntOp::Add, + target_index.address, + BrilligBinaryOp::Add, ); self.retrieve_variable_from_array(source_vector.pointer, target_index, *variable); - self.brillig_context.deallocate_register(target_index); + self.brillig_context.deallocate_single_addr(target_index); } } @@ -168,22 +169,22 @@ impl<'block> BrilligBlock<'block> { &mut self, target_vector: BrilligVector, source_vector: BrilligVector, - index: MemoryAddress, + index: SingleAddrVariable, items: &[BrilligVariable], ) { // First we need to allocate the target vector incrementing the size by items.len() - self.brillig_context.usize_op( + self.brillig_context.codegen_usize_op( source_vector.size, target_vector.size, - BinaryIntOp::Add, + BrilligBinaryOp::Add, items.len(), ); - self.brillig_context.allocate_array_instruction(target_vector.pointer, target_vector.size); + self.brillig_context.codegen_allocate_array(target_vector.pointer, target_vector.size); // We initialize the RC of the target vector to 1 - self.brillig_context.usize_const(target_vector.rc, 1_usize.into()); + self.brillig_context.usize_const_instruction(target_vector.rc, 1_usize.into()); // Copy the elements to the left of the index - self.brillig_context.copy_array_instruction( + self.brillig_context.codegen_copy_array( source_vector.pointer, target_vector.pointer, index, @@ -191,44 +192,55 @@ impl<'block> BrilligBlock<'block> { // Compute the source pointer just at the index let source_pointer_at_index = self.brillig_context.allocate_register(); - self.brillig_context.memory_op( + self.brillig_context.memory_op_instruction( source_vector.pointer, - index, + index.address, source_pointer_at_index, - BinaryIntOp::Add, + BrilligBinaryOp::Add, ); // Compute the target pointer after the inserted elements let target_pointer_after_index = self.brillig_context.allocate_register(); - self.brillig_context.memory_op( + self.brillig_context.memory_op_instruction( target_vector.pointer, - index, + index.address, target_pointer_after_index, - BinaryIntOp::Add, + BrilligBinaryOp::Add, ); - self.brillig_context.usize_op_in_place( + self.brillig_context.codegen_usize_op_in_place( target_pointer_after_index, - BinaryIntOp::Add, + BrilligBinaryOp::Add, items.len(), ); // Compute the number of elements to the right of the index let item_count = self.brillig_context.allocate_register(); - self.brillig_context.memory_op(source_vector.size, index, item_count, BinaryIntOp::Sub); + self.brillig_context.memory_op_instruction( + source_vector.size, + index.address, + item_count, + BrilligBinaryOp::Sub, + ); // Copy the elements to the right of the index - self.brillig_context.copy_array_instruction( + self.brillig_context.codegen_copy_array( source_pointer_at_index, target_pointer_after_index, - item_count, + SingleAddrVariable::new_usize(item_count), ); // Write the items to insert starting at the index for (subitem_index, variable) in items.iter().enumerate() { - let target_index = self.brillig_context.make_usize_constant(subitem_index.into()); - self.brillig_context.memory_op(target_index, index, target_index, BinaryIntOp::Add); + let target_index = + self.brillig_context.make_usize_constant_instruction(subitem_index.into()); + self.brillig_context.memory_op_instruction( + target_index.address, + index.address, + target_index.address, + BrilligBinaryOp::Add, + ); self.store_variable_in_array(target_vector.pointer, target_index, *variable); - self.brillig_context.deallocate_register(target_index); + self.brillig_context.deallocate_single_addr(target_index); } self.brillig_context.deallocate_register(source_pointer_at_index); @@ -240,22 +252,22 @@ impl<'block> BrilligBlock<'block> { &mut self, target_vector: BrilligVector, source_vector: BrilligVector, - index: MemoryAddress, + index: SingleAddrVariable, removed_items: &[BrilligVariable], ) { // First we need to allocate the target vector decrementing the size by removed_items.len() - self.brillig_context.usize_op( + self.brillig_context.codegen_usize_op( source_vector.size, target_vector.size, - BinaryIntOp::Sub, + BrilligBinaryOp::Sub, removed_items.len(), ); - self.brillig_context.allocate_array_instruction(target_vector.pointer, target_vector.size); + self.brillig_context.codegen_allocate_array(target_vector.pointer, target_vector.size); // We initialize the RC of the target vector to 1 - self.brillig_context.usize_const(target_vector.rc, 1_usize.into()); + self.brillig_context.usize_const_instruction(target_vector.rc, 1_usize.into()); // Copy the elements to the left of the index - self.brillig_context.copy_array_instruction( + self.brillig_context.codegen_copy_array( source_vector.pointer, target_vector.pointer, index, @@ -263,45 +275,60 @@ impl<'block> BrilligBlock<'block> { // Compute the source pointer after the removed items let source_pointer_after_index = self.brillig_context.allocate_register(); - self.brillig_context.memory_op( + self.brillig_context.memory_op_instruction( source_vector.pointer, - index, + index.address, source_pointer_after_index, - BinaryIntOp::Add, + BrilligBinaryOp::Add, ); - self.brillig_context.usize_op_in_place( + self.brillig_context.codegen_usize_op_in_place( source_pointer_after_index, - BinaryIntOp::Add, + BrilligBinaryOp::Add, removed_items.len(), ); // Compute the target pointer at the index let target_pointer_at_index = self.brillig_context.allocate_register(); - self.brillig_context.memory_op( + self.brillig_context.memory_op_instruction( target_vector.pointer, - index, + index.address, target_pointer_at_index, - BinaryIntOp::Add, + BrilligBinaryOp::Add, ); // Compute the number of elements to the right of the index let item_count = self.brillig_context.allocate_register(); - self.brillig_context.memory_op(source_vector.size, index, item_count, BinaryIntOp::Sub); - self.brillig_context.usize_op_in_place(item_count, BinaryIntOp::Sub, removed_items.len()); + self.brillig_context.memory_op_instruction( + source_vector.size, + index.address, + item_count, + BrilligBinaryOp::Sub, + ); + self.brillig_context.codegen_usize_op_in_place( + item_count, + BrilligBinaryOp::Sub, + removed_items.len(), + ); // Copy the elements to the right of the index - self.brillig_context.copy_array_instruction( + self.brillig_context.codegen_copy_array( source_pointer_after_index, target_pointer_at_index, - item_count, + SingleAddrVariable::new_usize(item_count), ); // Get the removed items for (subitem_index, variable) in removed_items.iter().enumerate() { - let target_index = self.brillig_context.make_usize_constant(subitem_index.into()); - self.brillig_context.memory_op(target_index, index, target_index, BinaryIntOp::Add); + let target_index = + self.brillig_context.make_usize_constant_instruction(subitem_index.into()); + self.brillig_context.memory_op_instruction( + target_index.address, + index.address, + target_index.address, + BrilligBinaryOp::Add, + ); self.retrieve_variable_from_array(source_vector.pointer, target_index, *variable); - self.brillig_context.deallocate_register(target_index); + self.brillig_context.deallocate_single_addr(target_index); } self.brillig_context.deallocate_register(source_pointer_after_index); @@ -316,7 +343,7 @@ impl<'block> BrilligBlock<'block> { match source_variable { BrilligVariable::BrilligVector(source_vector) => source_vector, BrilligVariable::BrilligArray(source_array) => { - self.brillig_context.array_to_vector(&source_array) + self.brillig_context.array_to_vector_instruction(&source_array) } _ => unreachable!("ICE: unsupported slice push back source {:?}", source_variable), } @@ -327,7 +354,7 @@ impl<'block> BrilligBlock<'block> { mod tests { use std::vec; - use acvm::acir::brillig::Value; + use acvm::FieldElement; use crate::brillig::brillig_gen::brillig_block::BrilligBlock; use crate::brillig::brillig_gen::brillig_block_variables::BlockVariables; @@ -346,8 +373,9 @@ mod tests { use crate::ssa::ssa_gen::Ssa; fn create_test_environment() -> (Ssa, FunctionContext, BrilligContext) { - let builder = - FunctionBuilder::new("main".to_string(), Id::test_new(0), RuntimeType::Brillig); + let mut builder = FunctionBuilder::new("main".to_string(), Id::test_new(0)); + builder.set_runtime(RuntimeType::Brillig); + let ssa = builder.finish(); let mut brillig_context = create_context(); @@ -373,9 +401,9 @@ mod tests { fn test_slice_push_operation() { fn test_case_push( push_back: bool, - array: Vec, - item_to_push: Value, - expected_return: Vec, + array: Vec, + item_to_push: FieldElement, + expected_return: Vec, ) { let arguments = vec![ BrilligParameter::Array( @@ -403,7 +431,7 @@ mod tests { }; // Cast the source array to a vector - let source_vector = context.array_to_vector(&array_variable); + let source_vector = context.array_to_vector_instruction(&array_variable); // Allocate the results let target_vector = BrilligVector { @@ -428,51 +456,72 @@ mod tests { ); } - context.return_instruction(&[target_vector.pointer, target_vector.rc]); + context.codegen_return(&[target_vector.pointer, target_vector.rc]); let bytecode = create_entry_point_bytecode(context, arguments, returns).byte_code; let (vm, return_data_offset, return_data_size) = create_and_run_vm(array.into_iter().chain(vec![item_to_push]).collect(), &bytecode); assert_eq!(return_data_size, expected_return.len()); assert_eq!( - vm.get_memory()[return_data_offset..(return_data_offset + expected_return.len())], + vm.get_memory()[return_data_offset..(return_data_offset + expected_return.len())] + .iter() + .map(|mem_val| mem_val.value) + .collect::>(), expected_return ); } test_case_push( true, - vec![Value::from(1_usize), Value::from(2_usize), Value::from(3_usize)], - Value::from(27_usize), vec![ - Value::from(1_usize), - Value::from(2_usize), - Value::from(3_usize), - Value::from(27_usize), + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + ], + FieldElement::from(27_usize), + vec![ + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + FieldElement::from(27_usize), ], ); - test_case_push(true, vec![], Value::from(27_usize), vec![Value::from(27_usize)]); + test_case_push( + true, + vec![], + FieldElement::from(27_usize), + vec![FieldElement::from(27_usize)], + ); test_case_push( false, - vec![Value::from(1_usize), Value::from(2_usize), Value::from(3_usize)], - Value::from(27_usize), vec![ - Value::from(27_usize), - Value::from(1_usize), - Value::from(2_usize), - Value::from(3_usize), + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + ], + FieldElement::from(27_usize), + vec![ + FieldElement::from(27_usize), + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), ], ); - test_case_push(false, vec![], Value::from(27_usize), vec![Value::from(27_usize)]); + test_case_push( + false, + vec![], + FieldElement::from(27_usize), + vec![FieldElement::from(27_usize)], + ); } #[test] fn test_slice_pop_back_operation() { fn test_case_pop( pop_back: bool, - array: Vec, - expected_return_array: Vec, - expected_return_item: Value, + array: Vec, + expected_return_array: Vec, + expected_return_item: FieldElement, ) { let arguments = vec![BrilligParameter::Array( vec![BrilligParameter::SingleAddr(BRILLIG_MEMORY_ADDRESSING_BIT_SIZE)], @@ -496,7 +545,7 @@ mod tests { }; // Cast the source array to a vector - let source_vector = context.array_to_vector(&array_variable); + let source_vector = context.array_to_vector_instruction(&array_variable); // Allocate the results let target_vector = BrilligVector { @@ -525,7 +574,7 @@ mod tests { ); } - context.return_instruction(&[ + context.codegen_return(&[ target_vector.pointer, target_vector.rc, removed_item.address, @@ -539,33 +588,44 @@ mod tests { assert_eq!(return_data_size, expected_return.len()); assert_eq!( - vm.get_memory()[return_data_offset..(return_data_offset + expected_return.len())], + vm.get_memory()[return_data_offset..(return_data_offset + expected_return.len())] + .iter() + .map(|mem_val| mem_val.value) + .collect::>(), expected_return ); } test_case_pop( true, - vec![Value::from(1_usize), Value::from(2_usize), Value::from(3_usize)], - vec![Value::from(1_usize), Value::from(2_usize)], - Value::from(3_usize), + vec![ + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + ], + vec![FieldElement::from(1_usize), FieldElement::from(2_usize)], + FieldElement::from(3_usize), ); - test_case_pop(true, vec![Value::from(1_usize)], vec![], Value::from(1_usize)); + test_case_pop(true, vec![FieldElement::from(1_usize)], vec![], FieldElement::from(1_usize)); test_case_pop( false, - vec![Value::from(1_usize), Value::from(2_usize), Value::from(3_usize)], - vec![Value::from(2_usize), Value::from(3_usize)], - Value::from(1_usize), + vec![ + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + ], + vec![FieldElement::from(2_usize), FieldElement::from(3_usize)], + FieldElement::from(1_usize), ); } #[test] fn test_slice_insert_operation() { fn test_case_insert( - array: Vec, - item: Value, - index: Value, - expected_return: Vec, + array: Vec, + item: FieldElement, + index: FieldElement, + expected_return: Vec, ) { let arguments = vec![ BrilligParameter::Array( @@ -592,10 +652,13 @@ mod tests { address: context.allocate_register(), bit_size: BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, }; - let index_to_insert = context.allocate_register(); + let index_to_insert = SingleAddrVariable::new( + context.allocate_register(), + BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, + ); // Cast the source array to a vector - let source_vector = context.array_to_vector(&array_variable); + let source_vector = context.array_to_vector_instruction(&array_variable); // Allocate the results let target_vector = BrilligVector { @@ -613,7 +676,7 @@ mod tests { &[BrilligVariable::SingleAddr(item_to_insert)], ); - context.return_instruction(&[target_vector.pointer, target_vector.rc]); + context.codegen_return(&[target_vector.pointer, target_vector.rc]); let calldata = array.into_iter().chain(vec![item]).chain(vec![index]).collect(); let bytecode = create_entry_point_bytecode(context, arguments, returns).byte_code; @@ -621,71 +684,90 @@ mod tests { assert_eq!(return_data_size, expected_return.len()); assert_eq!( - vm.get_memory()[return_data_offset..(return_data_offset + expected_return.len())], + vm.get_memory()[return_data_offset..(return_data_offset + expected_return.len())] + .iter() + .map(|mem_val| mem_val.value) + .collect::>(), expected_return ); } test_case_insert( - vec![Value::from(1_usize), Value::from(2_usize), Value::from(3_usize)], - Value::from(27_usize), - Value::from(1_usize), vec![ - Value::from(1_usize), - Value::from(27_usize), - Value::from(2_usize), - Value::from(3_usize), + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + ], + FieldElement::from(27_usize), + FieldElement::from(1_usize), + vec![ + FieldElement::from(1_usize), + FieldElement::from(27_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), ], ); test_case_insert( - vec![Value::from(1_usize), Value::from(2_usize), Value::from(3_usize)], - Value::from(27_usize), - Value::from(0_usize), vec![ - Value::from(27_usize), - Value::from(1_usize), - Value::from(2_usize), - Value::from(3_usize), + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + ], + FieldElement::from(27_usize), + FieldElement::from(0_usize), + vec![ + FieldElement::from(27_usize), + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), ], ); test_case_insert( - vec![Value::from(1_usize), Value::from(2_usize), Value::from(3_usize)], - Value::from(27_usize), - Value::from(2_usize), vec![ - Value::from(1_usize), - Value::from(2_usize), - Value::from(27_usize), - Value::from(3_usize), + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + ], + FieldElement::from(27_usize), + FieldElement::from(2_usize), + vec![ + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(27_usize), + FieldElement::from(3_usize), ], ); test_case_insert( - vec![Value::from(1_usize), Value::from(2_usize), Value::from(3_usize)], - Value::from(27_usize), - Value::from(3_usize), vec![ - Value::from(1_usize), - Value::from(2_usize), - Value::from(3_usize), - Value::from(27_usize), + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + ], + FieldElement::from(27_usize), + FieldElement::from(3_usize), + vec![ + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + FieldElement::from(27_usize), ], ); test_case_insert( vec![], - Value::from(27_usize), - Value::from(0_usize), - vec![Value::from(27_usize)], + FieldElement::from(27_usize), + FieldElement::from(0_usize), + vec![FieldElement::from(27_usize)], ); } #[test] fn test_slice_remove_operation() { fn test_case_remove( - array: Vec, - index: Value, - expected_array: Vec, - expected_removed_item: Value, + array: Vec, + index: FieldElement, + expected_array: Vec, + expected_removed_item: FieldElement, ) { let arguments = vec![ BrilligParameter::Array( @@ -710,10 +792,13 @@ mod tests { size: array.len(), rc: context.allocate_register(), }; - let index_to_insert = context.allocate_register(); + let index_to_insert = SingleAddrVariable::new( + context.allocate_register(), + BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, + ); // Cast the source array to a vector - let source_vector = context.array_to_vector(&array_variable); + let source_vector = context.array_to_vector_instruction(&array_variable); // Allocate the results let target_vector = BrilligVector { @@ -735,7 +820,7 @@ mod tests { &[BrilligVariable::SingleAddr(removed_item)], ); - context.return_instruction(&[ + context.codegen_return(&[ target_vector.pointer, target_vector.size, removed_item.address, @@ -751,36 +836,51 @@ mod tests { assert_eq!(return_data_size, expected_return.len()); assert_eq!( - vm.get_memory()[return_data_offset..(return_data_offset + expected_return.len())], + vm.get_memory()[return_data_offset..(return_data_offset + expected_return.len())] + .iter() + .map(|mem_val| mem_val.value) + .collect::>(), expected_return ); } test_case_remove( - vec![Value::from(1_usize), Value::from(2_usize), Value::from(3_usize)], - Value::from(0_usize), - vec![Value::from(2_usize), Value::from(3_usize)], - Value::from(1_usize), + vec![ + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + ], + FieldElement::from(0_usize), + vec![FieldElement::from(2_usize), FieldElement::from(3_usize)], + FieldElement::from(1_usize), ); test_case_remove( - vec![Value::from(1_usize), Value::from(2_usize), Value::from(3_usize)], - Value::from(1_usize), - vec![Value::from(1_usize), Value::from(3_usize)], - Value::from(2_usize), + vec![ + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + ], + FieldElement::from(1_usize), + vec![FieldElement::from(1_usize), FieldElement::from(3_usize)], + FieldElement::from(2_usize), ); test_case_remove( - vec![Value::from(1_usize), Value::from(2_usize), Value::from(3_usize)], - Value::from(2_usize), - vec![Value::from(1_usize), Value::from(2_usize)], - Value::from(3_usize), + vec![ + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + ], + FieldElement::from(2_usize), + vec![FieldElement::from(1_usize), FieldElement::from(2_usize)], + FieldElement::from(3_usize), ); test_case_remove( - vec![Value::from(1_usize)], - Value::from(0_usize), + vec![FieldElement::from(1_usize)], + FieldElement::from(0_usize), vec![], - Value::from(1_usize), + FieldElement::from(1_usize), ); } } diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/variable_liveness.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/variable_liveness.rs index 05978c2c6ab..c9f1cd1e247 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/variable_liveness.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/variable_liveness.rs @@ -323,7 +323,8 @@ mod test { // } let main_id = Id::test_new(1); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Brillig); + let mut builder = FunctionBuilder::new("main".into(), main_id); + builder.set_runtime(RuntimeType::Brillig); let b1 = builder.insert_block(); let b2 = builder.insert_block(); @@ -425,7 +426,8 @@ mod test { // } let main_id = Id::test_new(1); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Brillig); + let mut builder = FunctionBuilder::new("main".into(), main_id); + builder.set_runtime(RuntimeType::Brillig); let b1 = builder.insert_block(); let b2 = builder.insert_block(); diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir.rs index 90608974f98..e5c731be679 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_ir.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir.rs @@ -4,51 +4,41 @@ //! `brillig_gen` is therefore the module which combines both //! ssa types and types in this module. //! A similar paradigm can be seen with the `acir_ir` module. +//! +//! The brillig ir provides instructions and codegens. +//! The instructions are low level operations that are printed via debug_show. +//! They should emit few opcodes. Codegens on the other hand orchestrate the +//! low level instructions to emit the desired high level operation. pub(crate) mod artifact; pub(crate) mod brillig_variable; pub(crate) mod debug_show; pub(crate) mod registers; +mod codegen_binary; +mod codegen_calls; +mod codegen_control_flow; +mod codegen_intrinsic; +mod codegen_memory; +mod codegen_stack; mod entry_point; +mod instructions; -use crate::ssa::ir::dfg::CallStack; +pub(crate) use instructions::BrilligBinaryOp; -use self::{ - artifact::{BrilligArtifact, UnresolvedJumpLocation}, - brillig_variable::{BrilligArray, BrilligVariable, BrilligVector, SingleAddrVariable}, - registers::BrilligRegistersContext, -}; -use acvm::{ - acir::brillig::{ - BinaryFieldOp, BinaryIntOp, BlackBoxOp, MemoryAddress, Opcode as BrilligOpcode, Value, - ValueOrArray, - }, - brillig_vm::brillig::HeapValueType, - FieldElement, -}; +use self::{artifact::BrilligArtifact, registers::BrilligRegistersContext}; +use crate::ssa::ir::dfg::CallStack; +use acvm::acir::brillig::{MemoryAddress, Opcode as BrilligOpcode}; use debug_show::DebugShow; -use num_bigint::BigUint; -/// Integer arithmetic in Brillig is limited to 127 bit -/// integers. -/// -/// We could lift this in the future and have Brillig -/// do big integer arithmetic when it exceeds the field size -/// or we could have users re-implement big integer arithmetic -/// in Brillig. -/// Since constrained functions do not have this property, it -/// would mean that unconstrained functions will differ from -/// constrained functions in terms of syntax compatibility. -pub(crate) const BRILLIG_INTEGER_ARITHMETIC_BIT_SIZE: u32 = 127; /// The Brillig VM does not apply a limit to the memory address space, /// As a convention, we take use 64 bits. This means that we assume that /// memory has 2^64 memory slots. -pub(crate) const BRILLIG_MEMORY_ADDRESSING_BIT_SIZE: u32 = 32; +pub(crate) const BRILLIG_MEMORY_ADDRESSING_BIT_SIZE: u32 = 64; // Registers reserved in runtime for special purposes. pub(crate) enum ReservedRegisters { - /// This register stores the stack pointer. Allocations must be done after this pointer. - StackPointer = 0, + /// This register stores the free memory pointer. Allocations must be done after this pointer. + FreeMemoryPointer = 0, /// This register stores the previous stack pointer. The registers of the caller are stored here. PreviousStackPointer = 1, } @@ -65,9 +55,9 @@ impl ReservedRegisters { Self::NUM_RESERVED_REGISTERS } - /// Returns the stack pointer register. This will get used to allocate memory in runtime. - pub(crate) fn stack_pointer() -> MemoryAddress { - MemoryAddress::from(ReservedRegisters::StackPointer as usize) + /// Returns the free memory pointer register. This will get used to allocate memory in runtime. + pub(crate) fn free_memory_pointer() -> MemoryAddress { + MemoryAddress::from(ReservedRegisters::FreeMemoryPointer as usize) } /// Returns the previous stack pointer register. This will be used to restore the registers after a fn call. @@ -111,12 +101,8 @@ impl BrilligContext { } } - pub(crate) fn set_allocated_registers(&mut self, allocated_registers: Vec) { - self.registers = BrilligRegistersContext::from_preallocated_registers(allocated_registers); - } - /// Adds a brillig instruction to the brillig byte code - pub(crate) fn push_opcode(&mut self, opcode: BrilligOpcode) { + fn push_opcode(&mut self, opcode: BrilligOpcode) { self.obj.push_opcode(opcode); } @@ -125,985 +111,24 @@ impl BrilligContext { self.obj } - /// Allocates an array of size `size` and stores the pointer to the array - /// in `pointer_register` - pub(crate) fn allocate_fixed_length_array( - &mut self, - pointer_register: MemoryAddress, - size: usize, - ) { - // debug_show handled by allocate_array_instruction - let size_register = self.make_usize_constant(size.into()); - self.allocate_array_instruction(pointer_register, size_register); - self.deallocate_register(size_register); - } - - /// Allocates an array of size contained in size_register and stores the - /// pointer to the array in `pointer_register` - pub(crate) fn allocate_array_instruction( - &mut self, - pointer_register: MemoryAddress, - size_register: MemoryAddress, - ) { - self.debug_show.allocate_array_instruction(pointer_register, size_register); - self.set_array_pointer(pointer_register); - self.update_stack_pointer(size_register); - } - - pub(crate) fn set_array_pointer(&mut self, pointer_register: MemoryAddress) { - self.debug_show.mov_instruction(pointer_register, ReservedRegisters::stack_pointer()); - self.push_opcode(BrilligOpcode::Mov { - destination: pointer_register, - source: ReservedRegisters::stack_pointer(), - }); - } - - pub(crate) fn update_stack_pointer(&mut self, size_register: MemoryAddress) { - self.memory_op( - ReservedRegisters::stack_pointer(), - size_register, - ReservedRegisters::stack_pointer(), - BinaryIntOp::Add, - ); - } - - /// Allocates a variable in memory and stores the - /// pointer to the array in `pointer_register` - fn allocate_variable_reference_instruction( - &mut self, - pointer_register: MemoryAddress, - size: usize, - ) { - self.debug_show.allocate_instruction(pointer_register); - // A variable can be stored in up to three values, so we reserve three values for that. - let size_register = self.make_usize_constant(size.into()); - self.push_opcode(BrilligOpcode::Mov { - destination: pointer_register, - source: ReservedRegisters::stack_pointer(), - }); - self.memory_op( - ReservedRegisters::stack_pointer(), - size_register, - ReservedRegisters::stack_pointer(), - BinaryIntOp::Add, - ); - self.deallocate_register(size_register); - } - - pub(crate) fn allocate_single_addr_reference_instruction( - &mut self, - pointer_register: MemoryAddress, - ) { - self.allocate_variable_reference_instruction(pointer_register, 1); - } - - pub(crate) fn allocate_array_reference_instruction(&mut self, pointer_register: MemoryAddress) { - self.allocate_variable_reference_instruction( - pointer_register, - BrilligArray::registers_count(), - ); - } - - pub(crate) fn allocate_vector_reference_instruction( - &mut self, - pointer_register: MemoryAddress, - ) { - self.allocate_variable_reference_instruction( - pointer_register, - BrilligVector::registers_count(), - ); - } - - /// Gets the value in the array at index `index` and stores it in `result` - pub(crate) fn array_get( - &mut self, - array_ptr: MemoryAddress, - index: MemoryAddress, - result: MemoryAddress, - ) { - self.debug_show.array_get(array_ptr, index, result); - // Computes array_ptr + index, ie array[index] - let index_of_element_in_memory = self.allocate_register(); - self.binary_instruction( - array_ptr, - index, - index_of_element_in_memory, - BrilligBinaryOp::Field { op: BinaryFieldOp::Add }, - ); - - self.load_instruction(result, index_of_element_in_memory); - // Free up temporary register - self.deallocate_register(index_of_element_in_memory); - } - - /// Sets the item in the array at index `index` to `value` - pub(crate) fn array_set( - &mut self, - array_ptr: MemoryAddress, - index: MemoryAddress, - value: MemoryAddress, - ) { - self.debug_show.array_set(array_ptr, index, value); - // Computes array_ptr + index, ie array[index] - let index_of_element_in_memory = self.allocate_register(); - self.binary_instruction( - array_ptr, - index, - index_of_element_in_memory, - BrilligBinaryOp::Field { op: BinaryFieldOp::Add }, - ); - - self.store_instruction(index_of_element_in_memory, value); - // Free up temporary register - self.deallocate_register(index_of_element_in_memory); - } - - /// Copies the values of an array pointed by source with length stored in `num_elements_register` - /// Into the array pointed by destination - pub(crate) fn copy_array_instruction( - &mut self, - source_pointer: MemoryAddress, - destination_pointer: MemoryAddress, - num_elements_register: MemoryAddress, - ) { - self.debug_show.copy_array_instruction( - source_pointer, - destination_pointer, - num_elements_register, - ); - - let value_register = self.allocate_register(); - - self.loop_instruction(num_elements_register, |ctx, iterator| { - ctx.array_get(source_pointer, iterator, value_register); - ctx.array_set(destination_pointer, iterator, value_register); - }); - - self.deallocate_register(value_register); - } - - /// This instruction will issue a loop that will iterate iteration_count times - /// The body of the loop should be issued by the caller in the on_iteration closure. - pub(crate) fn loop_instruction(&mut self, iteration_count: MemoryAddress, on_iteration: F) - where - F: FnOnce(&mut BrilligContext, MemoryAddress), - { - let iterator_register = self.make_usize_constant(0_u128.into()); - - let (loop_section, loop_label) = self.reserve_next_section_label(); - self.enter_section(loop_section); - - // Loop body - - // Check if iterator < iteration_count - let iterator_less_than_iterations = - SingleAddrVariable { address: self.allocate_register(), bit_size: 1 }; - - self.memory_op( - iterator_register, - iteration_count, - iterator_less_than_iterations.address, - BinaryIntOp::LessThan, - ); - - let (exit_loop_section, exit_loop_label) = self.reserve_next_section_label(); - - self.not_instruction(iterator_less_than_iterations, iterator_less_than_iterations); - - self.jump_if_instruction(iterator_less_than_iterations.address, exit_loop_label); - - // Call the on iteration function - on_iteration(self, iterator_register); - - // Increment the iterator register - self.usize_op_in_place(iterator_register, BinaryIntOp::Add, 1); - - self.jump_instruction(loop_label); - - // Exit the loop - self.enter_section(exit_loop_section); - - // Deallocate our temporary registers - self.deallocate_register(iterator_less_than_iterations.address); - self.deallocate_register(iterator_register); - } - - /// This instruction will issue an if-then branch that will check if the condition is true - /// and if so, perform the instructions given in `f(self, true)` and otherwise perform the - /// instructions given in `f(self, false)`. A boolean is passed instead of two separate - /// functions to allow the given function to mutably alias its environment. - pub(crate) fn branch_instruction( - &mut self, - condition: MemoryAddress, - mut f: impl FnMut(&mut BrilligContext, bool), - ) { - // Reserve 3 sections - let (then_section, then_label) = self.reserve_next_section_label(); - let (otherwise_section, otherwise_label) = self.reserve_next_section_label(); - let (end_section, end_label) = self.reserve_next_section_label(); - - self.jump_if_instruction(condition, then_label.clone()); - self.jump_instruction(otherwise_label.clone()); - - self.enter_section(then_section); - f(self, true); - self.jump_instruction(end_label.clone()); - - self.enter_section(otherwise_section); - f(self, false); - self.jump_instruction(end_label.clone()); - - self.enter_section(end_section); - } - - /// Adds a label to the next opcode - pub(crate) fn enter_context(&mut self, label: T) { - self.debug_show.enter_context(label.to_string()); - self.context_label = label.to_string(); - self.section_label = 0; - // Add a context label to the next opcode - self.obj.add_label_at_position(label.to_string(), self.obj.index_of_next_opcode()); - // Add a section label to the next opcode - self.obj - .add_label_at_position(self.current_section_label(), self.obj.index_of_next_opcode()); - } - - /// Enter the given section - fn enter_section(&mut self, section: usize) { - self.section_label = section; - self.obj - .add_label_at_position(self.current_section_label(), self.obj.index_of_next_opcode()); - } - - /// Create, reserve, and return a new section label. - fn reserve_next_section_label(&mut self) -> (usize, String) { - let section = self.next_section; - self.next_section += 1; - (section, self.compute_section_label(section)) - } - - /// Internal function used to compute the section labels - fn compute_section_label(&self, section: usize) -> String { - format!("{}-{}", self.context_label, section) - } - - /// Returns the current section label - fn current_section_label(&self) -> String { - self.compute_section_label(self.section_label) - } - - /// Adds a unresolved `Jump` instruction to the bytecode. - pub(crate) fn jump_instruction(&mut self, target_label: T) { - self.debug_show.jump_instruction(target_label.to_string()); - self.add_unresolved_jump(BrilligOpcode::Jump { location: 0 }, target_label.to_string()); - } - - /// Adds a unresolved `JumpIf` instruction to the bytecode. - pub(crate) fn jump_if_instruction( - &mut self, - condition: MemoryAddress, - target_label: T, - ) { - self.debug_show.jump_if_instruction(condition, target_label.to_string()); - self.add_unresolved_jump( - BrilligOpcode::JumpIf { condition, location: 0 }, - target_label.to_string(), - ); - } - - /// Adds a unresolved `Jump` instruction to the bytecode. - fn add_unresolved_jump( - &mut self, - jmp_instruction: BrilligOpcode, - destination: UnresolvedJumpLocation, - ) { - self.obj.add_unresolved_jump(jmp_instruction, destination); - } - - /// Allocates an unused register. - pub(crate) fn allocate_register(&mut self) -> MemoryAddress { - self.registers.allocate_register() - } - - /// Push a register to the deallocation list, ready for reuse. - /// TODO(AD): currently, register deallocation is only done with immediate values. - /// TODO(AD): See https://github.com/noir-lang/noir/issues/1720 - pub(crate) fn deallocate_register(&mut self, register_index: MemoryAddress) { - self.registers.deallocate_register(register_index); - } -} - -impl BrilligContext { - /// Emits brillig bytecode to jump to a trap condition if `condition` - /// is false. - pub(crate) fn constrain_instruction( - &mut self, - condition: MemoryAddress, - assert_message: Option, - ) { - self.debug_show.constrain_instruction(condition); - let (next_section, next_label) = self.reserve_next_section_label(); - self.add_unresolved_jump(BrilligOpcode::JumpIf { condition, location: 0 }, next_label); - self.push_opcode(BrilligOpcode::Trap); - if let Some(assert_message) = assert_message { - self.obj.add_assert_message_to_last_opcode(assert_message); - } - self.enter_section(next_section); - } - - /// Processes a return instruction. - /// - /// For Brillig, the return is implicit, since there is no explicit return instruction. - /// The caller will take `N` values from the Register starting at register index 0. - /// `N` indicates the number of return values expected. - /// - /// Brillig does not have an explicit return instruction, so this - /// method will move all register values to the first `N` values in - /// the VM. - pub(crate) fn return_instruction(&mut self, return_registers: &[MemoryAddress]) { - self.debug_show.return_instruction(return_registers); - let mut sources = Vec::with_capacity(return_registers.len()); - let mut destinations = Vec::with_capacity(return_registers.len()); - - for (destination_index, return_register) in return_registers.iter().enumerate() { - // In case we have fewer return registers than indices to write to, ensure we've allocated this register - let destination_register = ReservedRegisters::user_register_index(destination_index); - self.registers.ensure_register_is_allocated(destination_register); - sources.push(*return_register); - destinations.push(destination_register); - } - destinations - .iter() - .for_each(|destination| self.registers.ensure_register_is_allocated(*destination)); - self.mov_registers_to_registers_instruction(sources, destinations); - self.stop_instruction(); - } - - /// This function moves values from a set of registers to another set of registers. - /// It first moves all sources to new allocated registers to avoid overwriting. - pub(crate) fn mov_registers_to_registers_instruction( - &mut self, - sources: Vec, - destinations: Vec, - ) { - let new_sources: Vec<_> = sources - .iter() - .map(|source| { - let new_source = self.allocate_register(); - self.mov_instruction(new_source, *source); - new_source - }) - .collect(); - for (new_source, destination) in new_sources.iter().zip(destinations.iter()) { - self.mov_instruction(*destination, *new_source); - self.deallocate_register(*new_source); - } - } - - /// Emits a `mov` instruction. - /// - /// Copies the value at `source` into `destination` - pub(crate) fn mov_instruction(&mut self, destination: MemoryAddress, source: MemoryAddress) { - self.debug_show.mov_instruction(destination, source); - self.push_opcode(BrilligOpcode::Mov { destination, source }); - } - - /// Cast truncates the value to the given bit size and converts the type of the value in memory to that bit size. - pub(crate) fn cast_instruction( - &mut self, - destination: SingleAddrVariable, - source: SingleAddrVariable, - ) { - self.debug_show.cast_instruction(destination.address, source.address, destination.bit_size); - self.push_opcode(BrilligOpcode::Cast { - destination: destination.address, - source: source.address, - bit_size: destination.bit_size, - }); - } - - /// Processes a binary instruction according `operation`. - /// - /// This method will compute lhs rhs - /// and store the result in the `result` register. - pub(crate) fn binary_instruction( - &mut self, - lhs: MemoryAddress, - rhs: MemoryAddress, - result: MemoryAddress, - operation: BrilligBinaryOp, - ) { - self.debug_show.binary_instruction(lhs, rhs, result, operation.clone()); - match operation { - BrilligBinaryOp::Field { op } => { - let opcode = BrilligOpcode::BinaryFieldOp { op, destination: result, lhs, rhs }; - self.push_opcode(opcode); - } - BrilligBinaryOp::Integer { op, bit_size } => { - let opcode = - BrilligOpcode::BinaryIntOp { op, destination: result, bit_size, lhs, rhs }; - self.push_opcode(opcode); - } - BrilligBinaryOp::Modulo { is_signed_integer, bit_size } => { - self.modulo_instruction(result, lhs, rhs, bit_size, is_signed_integer); - } - } - } - - /// Stores the value of `constant` in the `result` register - pub(crate) fn const_instruction( - &mut self, - result: MemoryAddress, - constant: Value, - bit_size: u32, - ) { - self.debug_show.const_instruction(result, constant); - self.push_opcode(BrilligOpcode::Const { destination: result, value: constant, bit_size }); - } - - pub(crate) fn usize_const(&mut self, result: MemoryAddress, constant: Value) { - self.const_instruction(result, constant, BRILLIG_MEMORY_ADDRESSING_BIT_SIZE); - } - - /// Processes a not instruction. - /// - /// Not is computed using a subtraction operation as there is no native not instruction - /// in Brillig. - pub(crate) fn not_instruction( - &mut self, - input: SingleAddrVariable, - result: SingleAddrVariable, - ) { - self.debug_show.not_instruction(input.address, input.bit_size, result.address); - // Compile !x as ((-1) - x) - let u_max = FieldElement::from(2_i128).pow(&FieldElement::from(input.bit_size as i128)) - - FieldElement::one(); - let max = self.make_constant(Value::from(u_max), input.bit_size); - let opcode = BrilligOpcode::BinaryIntOp { - destination: result.address, - op: BinaryIntOp::Sub, - bit_size: input.bit_size, - lhs: max, - rhs: input.address, - }; - self.push_opcode(opcode); - self.deallocate_register(max); - } - - /// Processes a foreign call instruction. - /// - /// Note: the function being called is external and will - /// not be linked during brillig generation. - pub(crate) fn foreign_call_instruction( - &mut self, - func_name: String, - inputs: &[ValueOrArray], - input_value_types: &[HeapValueType], - outputs: &[ValueOrArray], - output_value_types: &[HeapValueType], - ) { - assert!(inputs.len() == input_value_types.len()); - assert!(outputs.len() == output_value_types.len()); - self.debug_show.foreign_call_instruction(func_name.clone(), inputs, outputs); - let opcode = BrilligOpcode::ForeignCall { - function: func_name, - destinations: outputs.to_vec(), - destination_value_types: output_value_types.to_vec(), - inputs: inputs.to_vec(), - input_value_types: input_value_types.to_vec(), - }; - self.push_opcode(opcode); - } - - /// Emits a load instruction - pub(crate) fn load_instruction( - &mut self, - destination: MemoryAddress, - source_pointer: MemoryAddress, - ) { - self.debug_show.load_instruction(destination, source_pointer); - self.push_opcode(BrilligOpcode::Load { destination, source_pointer }); - } - - /// Loads a variable stored previously - pub(crate) fn load_variable_instruction( - &mut self, - destination: BrilligVariable, - variable_pointer: MemoryAddress, - ) { - match destination { - BrilligVariable::SingleAddr(single_addr) => { - self.load_instruction(single_addr.address, variable_pointer); - } - BrilligVariable::BrilligArray(BrilligArray { pointer, size: _, rc }) => { - self.load_instruction(pointer, variable_pointer); - - let rc_pointer = self.allocate_register(); - self.mov_instruction(rc_pointer, variable_pointer); - self.usize_op_in_place(rc_pointer, BinaryIntOp::Add, 1_usize); - - self.load_instruction(rc, rc_pointer); - self.deallocate_register(rc_pointer); - } - BrilligVariable::BrilligVector(BrilligVector { pointer, size, rc }) => { - self.load_instruction(pointer, variable_pointer); - - let size_pointer = self.allocate_register(); - self.mov_instruction(size_pointer, variable_pointer); - self.usize_op_in_place(size_pointer, BinaryIntOp::Add, 1_usize); - - self.load_instruction(size, size_pointer); - self.deallocate_register(size_pointer); - - let rc_pointer = self.allocate_register(); - self.mov_instruction(rc_pointer, variable_pointer); - self.usize_op_in_place(rc_pointer, BinaryIntOp::Add, 2_usize); - - self.load_instruction(rc, rc_pointer); - self.deallocate_register(rc_pointer); - } - } - } - - /// Emits a store instruction - pub(crate) fn store_instruction( - &mut self, - destination_pointer: MemoryAddress, - source: MemoryAddress, - ) { - self.debug_show.store_instruction(destination_pointer, source); - self.push_opcode(BrilligOpcode::Store { destination_pointer, source }); - } - - /// Stores a variable by saving its registers to memory - pub(crate) fn store_variable_instruction( - &mut self, - variable_pointer: MemoryAddress, - source: BrilligVariable, - ) { - match source { - BrilligVariable::SingleAddr(single_addr) => { - self.store_instruction(variable_pointer, single_addr.address); - } - BrilligVariable::BrilligArray(BrilligArray { pointer, size: _, rc }) => { - self.store_instruction(variable_pointer, pointer); - - let rc_pointer: MemoryAddress = self.allocate_register(); - self.mov_instruction(rc_pointer, variable_pointer); - self.usize_op_in_place(rc_pointer, BinaryIntOp::Add, 1_usize); - self.store_instruction(rc_pointer, rc); - self.deallocate_register(rc_pointer); - } - BrilligVariable::BrilligVector(BrilligVector { pointer, size, rc }) => { - self.store_instruction(variable_pointer, pointer); - - let size_pointer = self.allocate_register(); - self.mov_instruction(size_pointer, variable_pointer); - self.usize_op_in_place(size_pointer, BinaryIntOp::Add, 1_usize); - self.store_instruction(size_pointer, size); - - let rc_pointer: MemoryAddress = self.allocate_register(); - self.mov_instruction(rc_pointer, variable_pointer); - self.usize_op_in_place(rc_pointer, BinaryIntOp::Add, 2_usize); - self.store_instruction(rc_pointer, rc); - - self.deallocate_register(size_pointer); - self.deallocate_register(rc_pointer); - } - } - } - - /// Emits a truncate instruction. - /// - /// Note: Truncation is used as an optimization in the SSA IR - /// for the ACIR generation pass; ACIR gen does not overflow - /// on every integer operation since it would be in-efficient. - /// Instead truncation instructions are emitted as to when a - /// truncation should be done. - /// For Brillig, all integer operations will overflow as its cheap. - pub(crate) fn truncate_instruction( - &mut self, - destination_of_truncated_value: SingleAddrVariable, - value_to_truncate: SingleAddrVariable, - bit_size: u32, - ) { - self.debug_show.truncate_instruction( - destination_of_truncated_value.address, - value_to_truncate.address, - bit_size, - ); - assert!( - bit_size <= value_to_truncate.bit_size, - "tried to truncate to a bit size {} greater than the variable size {}", - bit_size, - value_to_truncate.bit_size - ); - - let mask = BigUint::from(2_u32).pow(bit_size) - BigUint::from(1_u32); - let mask_constant = self.make_constant( - FieldElement::from_be_bytes_reduce(&mask.to_bytes_be()).into(), - value_to_truncate.bit_size, - ); - - self.binary_instruction( - value_to_truncate.address, - mask_constant, - destination_of_truncated_value.address, - BrilligBinaryOp::Integer { op: BinaryIntOp::And, bit_size: value_to_truncate.bit_size }, - ); - - self.deallocate_register(mask_constant); - } - - /// Emits a stop instruction - pub(crate) fn stop_instruction(&mut self) { - self.debug_show.stop_instruction(); - self.push_opcode(BrilligOpcode::Stop { return_data_offset: 0, return_data_size: 0 }); - } - - /// Returns a register which holds the value of a constant - pub(crate) fn make_constant(&mut self, constant: Value, bit_size: u32) -> MemoryAddress { - let register = self.allocate_register(); - self.const_instruction(register, constant, bit_size); - register - } - - /// Returns a register which holds the value of an usize constant - pub(crate) fn make_usize_constant(&mut self, constant: Value) -> MemoryAddress { - let register = self.allocate_register(); - self.usize_const(register, constant); - register - } - - /// Computes left % right by emitting the necessary Brillig opcodes. - /// - /// This is done by using the following formula: - /// - /// a % b = a - (b * (a / b)) - /// - /// Brillig does not have an explicit modulo operation, - /// so we must emit multiple opcodes and process it differently - /// to other binary instructions. - pub(crate) fn modulo_instruction( - &mut self, - result_register: MemoryAddress, - left: MemoryAddress, - right: MemoryAddress, - bit_size: u32, - signed: bool, - ) { - // no debug_show, shown in binary instruction - let scratch_register_i = self.allocate_register(); - let scratch_register_j = self.allocate_register(); - - // i = left / right - self.push_opcode(BrilligOpcode::BinaryIntOp { - op: match signed { - true => BinaryIntOp::SignedDiv, - false => BinaryIntOp::UnsignedDiv, - }, - destination: scratch_register_i, - bit_size, - lhs: left, - rhs: right, - }); - - // j = i * right - self.push_opcode(BrilligOpcode::BinaryIntOp { - op: BinaryIntOp::Mul, - destination: scratch_register_j, - bit_size, - lhs: scratch_register_i, - rhs: right, - }); - - // result_register = left - j - self.push_opcode(BrilligOpcode::BinaryIntOp { - op: BinaryIntOp::Sub, - destination: result_register, - bit_size, - lhs: left, - rhs: scratch_register_j, - }); - // Free scratch registers - self.deallocate_register(scratch_register_i); - self.deallocate_register(scratch_register_j); - } - - /// Adds a unresolved external `Call` instruction to the bytecode. - /// This calls into another function compiled into this brillig artifact. - pub(crate) fn add_external_call_instruction(&mut self, func_label: T) { - self.debug_show.add_external_call_instruction(func_label.to_string()); - self.obj.add_unresolved_external_call( - BrilligOpcode::Call { location: 0 }, - func_label.to_string(), - ); - } - - /// Returns the i'th register after the reserved ones - pub(crate) fn register(&self, i: usize) -> MemoryAddress { - MemoryAddress::from(ReservedRegisters::NUM_RESERVED_REGISTERS + i) - } - - /// Saves all of the registers that have been used up until this point. - fn save_registers_of_vars(&mut self, vars: &[BrilligVariable]) -> Vec { - // Save all of the used registers at this point in memory - // because the function call will/may overwrite them. - // - // Note that here it is important that the stack pointer register is at register 0, - // as after the first register save we add to the pointer. - let mut used_registers: Vec<_> = - vars.iter().flat_map(|var| var.extract_registers()).collect(); - - // Also dump the previous stack pointer - used_registers.push(ReservedRegisters::previous_stack_pointer()); - for register in used_registers.iter() { - self.store_instruction(ReservedRegisters::stack_pointer(), *register); - // Add one to our stack pointer - self.usize_op_in_place(ReservedRegisters::stack_pointer(), BinaryIntOp::Add, 1); - } - - // Store the location of our registers in the previous stack pointer - self.mov_instruction( - ReservedRegisters::previous_stack_pointer(), - ReservedRegisters::stack_pointer(), - ); - used_registers - } - - /// Loads all of the registers that have been save by save_all_used_registers. - fn load_all_saved_registers(&mut self, used_registers: &[MemoryAddress]) { - // Load all of the used registers that we saved. - // We do all the reverse operations of save_all_used_registers. - // Iterate our registers in reverse - let iterator_register = self.allocate_register(); - self.mov_instruction(iterator_register, ReservedRegisters::previous_stack_pointer()); - - for register in used_registers.iter().rev() { - // Subtract one from our stack pointer - self.usize_op_in_place(iterator_register, BinaryIntOp::Sub, 1); - self.load_instruction(*register, iterator_register); - } - } - - /// Utility method to perform a binary instruction with a constant value in place - pub(crate) fn usize_op_in_place( - &mut self, - destination: MemoryAddress, - op: BinaryIntOp, - constant: usize, - ) { - self.usize_op(destination, destination, op, constant); - } - - /// Utility method to perform a binary instruction with a constant value - pub(crate) fn usize_op( - &mut self, - operand: MemoryAddress, - destination: MemoryAddress, - op: BinaryIntOp, - constant: usize, - ) { - let const_register = self.make_usize_constant(Value::from(constant)); - self.memory_op(operand, const_register, destination, op); - // Mark as no longer used for this purpose, frees for reuse - self.deallocate_register(const_register); - } - - /// Utility method to perform a binary instruction with a memory address - pub(crate) fn memory_op( - &mut self, - lhs: MemoryAddress, - rhs: MemoryAddress, - destination: MemoryAddress, - op: BinaryIntOp, - ) { - self.binary_instruction( - lhs, - rhs, - destination, - BrilligBinaryOp::Integer { op, bit_size: BRILLIG_MEMORY_ADDRESSING_BIT_SIZE }, - ); - } - - // Used before a call instruction. - // Save all the registers we have used to the stack. - // Move argument values to the front of the register indices. - pub(crate) fn pre_call_save_registers_prep_args( - &mut self, - arguments: &[MemoryAddress], - variables_to_save: &[BrilligVariable], - ) -> Vec { - // Save all the registers we have used to the stack. - let saved_registers = self.save_registers_of_vars(variables_to_save); - - // Move argument values to the front of the registers - // - // This means that the arguments will be in the first `n` registers after - // the number of reserved registers. - let (sources, destinations): (Vec<_>, Vec<_>) = - arguments.iter().enumerate().map(|(i, argument)| (*argument, self.register(i))).unzip(); - destinations - .iter() - .for_each(|destination| self.registers.ensure_register_is_allocated(*destination)); - self.mov_registers_to_registers_instruction(sources, destinations); - saved_registers - } - - // Used after a call instruction. - // Move return values to the front of the register indices. - // Load all the registers we have previous saved in save_registers_prep_args. - pub(crate) fn post_call_prep_returns_load_registers( - &mut self, - result_registers: &[MemoryAddress], - saved_registers: &[MemoryAddress], - ) { - // Allocate our result registers and write into them - // We assume the return values of our call are held in 0..num results register indices - let (sources, destinations): (Vec<_>, Vec<_>) = result_registers - .iter() - .enumerate() - .map(|(i, result_register)| (self.register(i), *result_register)) - .unzip(); - sources.iter().for_each(|source| self.registers.ensure_register_is_allocated(*source)); - self.mov_registers_to_registers_instruction(sources, destinations); - - // Restore all the same registers we have, in exact reverse order. - // Note that we have allocated some registers above, which we will not be handling here, - // only restoring registers that were used prior to the call finishing. - // After the call instruction, the stack frame pointer should be back to where we left off, - // so we do our instructions in reverse order. - self.load_all_saved_registers(saved_registers); - } - - /// Utility method to transform a HeapArray to a HeapVector by making a runtime constant with the size. - pub(crate) fn array_to_vector(&mut self, array: &BrilligArray) -> BrilligVector { - let size_register = self.make_usize_constant(array.size.into()); - BrilligVector { size: size_register, pointer: array.pointer, rc: array.rc } - } - - /// Issues a blackbox operation. - pub(crate) fn black_box_op_instruction(&mut self, op: BlackBoxOp) { - self.debug_show.black_box_op_instruction(&op); - self.push_opcode(BrilligOpcode::BlackBox(op)); - } - - /// Issues a to_radix instruction. This instruction will write the modulus of the source register - /// And the radix register limb_count times to the target vector. - pub(crate) fn radix_instruction( - &mut self, - source: MemoryAddress, - target_vector: BrilligVector, - radix: MemoryAddress, - limb_count: MemoryAddress, - big_endian: bool, - ) { - self.mov_instruction(target_vector.size, limb_count); - self.usize_const(target_vector.rc, 1_usize.into()); - self.allocate_array_instruction(target_vector.pointer, target_vector.size); - - let shifted_register = self.allocate_register(); - self.mov_instruction(shifted_register, source); - - let modulus_register: MemoryAddress = self.allocate_register(); - - self.loop_instruction(target_vector.size, |ctx, iterator_register| { - // Compute the modulus - ctx.modulo_instruction( - modulus_register, - shifted_register, - radix, - FieldElement::max_num_bits(), - false, - ); - // Write it - ctx.array_set(target_vector.pointer, iterator_register, modulus_register); - // Integer div the field - ctx.binary_instruction( - shifted_register, - radix, - shifted_register, - BrilligBinaryOp::Integer { - op: BinaryIntOp::UnsignedDiv, - bit_size: FieldElement::max_num_bits(), - }, - ); - }); - - // Deallocate our temporary registers - self.deallocate_register(shifted_register); - self.deallocate_register(modulus_register); - - if big_endian { - self.reverse_vector_in_place_instruction(target_vector); - } - } - - /// This instruction will reverse the order of the elements in a vector. - pub(crate) fn reverse_vector_in_place_instruction(&mut self, vector: BrilligVector) { - let iteration_count = self.allocate_register(); - self.usize_op(vector.size, iteration_count, BinaryIntOp::UnsignedDiv, 2); - - let start_value_register = self.allocate_register(); - let index_at_end_of_array = self.allocate_register(); - let end_value_register = self.allocate_register(); - - self.loop_instruction(iteration_count, |ctx, iterator_register| { - // Load both values - ctx.array_get(vector.pointer, iterator_register, start_value_register); - - // The index at the end of array is size - 1 - iterator - ctx.mov_instruction(index_at_end_of_array, vector.size); - ctx.usize_op_in_place(index_at_end_of_array, BinaryIntOp::Sub, 1); - ctx.memory_op( - index_at_end_of_array, - iterator_register, - index_at_end_of_array, - BinaryIntOp::Sub, - ); - - ctx.array_get(vector.pointer, index_at_end_of_array, end_value_register); - - // Write both values - ctx.array_set(vector.pointer, iterator_register, end_value_register); - ctx.array_set(vector.pointer, index_at_end_of_array, start_value_register); - }); - - self.deallocate_register(iteration_count); - self.deallocate_register(start_value_register); - self.deallocate_register(end_value_register); - self.deallocate_register(index_at_end_of_array); - } - /// Sets a current call stack that the next pushed opcodes will be associated with. pub(crate) fn set_call_stack(&mut self, call_stack: CallStack) { self.obj.set_call_stack(call_stack); } } -/// Type to encapsulate the binary operation types in Brillig -#[derive(Clone)] -pub(crate) enum BrilligBinaryOp { - Field { op: BinaryFieldOp }, - Integer { op: BinaryIntOp, bit_size: u32 }, - // Modulo operation requires more than one opcode - // Brillig. - Modulo { is_signed_integer: bool, bit_size: u32 }, -} - #[cfg(test)] pub(crate) mod tests { use std::vec; use acvm::acir::brillig::{ - BinaryIntOp, ForeignCallParam, ForeignCallResult, HeapVector, MemoryAddress, Value, - ValueOrArray, + ForeignCallParam, ForeignCallResult, HeapVector, MemoryAddress, ValueOrArray, }; use acvm::brillig_vm::brillig::HeapValueType; use acvm::brillig_vm::{VMStatus, VM}; use acvm::{BlackBoxFunctionSolver, BlackBoxResolutionError, FieldElement}; - use crate::brillig::brillig_ir::BrilligContext; + use crate::brillig::brillig_ir::{BrilligBinaryOp, BrilligContext}; use super::artifact::{BrilligParameter, GeneratedBrillig}; use super::{BrilligOpcode, ReservedRegisters}; @@ -1180,7 +205,7 @@ pub(crate) mod tests { } pub(crate) fn create_and_run_vm( - calldata: Vec, + calldata: Vec, bytecode: &[BrilligOpcode], ) -> (VM<'_, DummyBlackBoxSolver>, usize, usize) { let mut vm = VM::new(calldata, bytecode, vec![], &DummyBlackBoxSolver); @@ -1207,27 +232,32 @@ pub(crate) mod tests { // assert(the_sequence.len() == 12); // } let mut context = BrilligContext::new(true); - let r_stack = ReservedRegisters::stack_pointer(); + let r_stack = ReservedRegisters::free_memory_pointer(); // Start stack pointer at 0 - context.usize_const(r_stack, Value::from(ReservedRegisters::len() + 3)); + context.usize_const_instruction(r_stack, FieldElement::from(ReservedRegisters::len() + 3)); let r_input_size = MemoryAddress::from(ReservedRegisters::len()); let r_array_ptr = MemoryAddress::from(ReservedRegisters::len() + 1); let r_output_size = MemoryAddress::from(ReservedRegisters::len() + 2); let r_equality = MemoryAddress::from(ReservedRegisters::len() + 3); - context.usize_const(r_input_size, Value::from(12_usize)); + context.usize_const_instruction(r_input_size, FieldElement::from(12_usize)); // copy our stack frame to r_array_ptr context.mov_instruction(r_array_ptr, r_stack); context.foreign_call_instruction( "make_number_sequence".into(), &[ValueOrArray::MemoryAddress(r_input_size)], - &[HeapValueType::Simple], + &[HeapValueType::Simple(32)], &[ValueOrArray::HeapVector(HeapVector { pointer: r_stack, size: r_output_size })], - &[HeapValueType::Vector { value_types: vec![HeapValueType::Simple] }], + &[HeapValueType::Vector { value_types: vec![HeapValueType::Simple(32)] }], ); // push stack frame by r_returned_size - context.memory_op(r_stack, r_output_size, r_stack, BinaryIntOp::Add); + context.memory_op_instruction(r_stack, r_output_size, r_stack, BrilligBinaryOp::Add); // check r_input_size == r_output_size - context.memory_op(r_input_size, r_output_size, r_equality, BinaryIntOp::Equals); + context.memory_op_instruction( + r_input_size, + r_output_size, + r_equality, + BrilligBinaryOp::Equals, + ); // We push a JumpIf and Trap opcode directly as the constrain instruction // uses unresolved jumps which requires a block to be constructed in SSA and // we don't need this for Brillig IR tests @@ -1236,8 +266,9 @@ pub(crate) mod tests { context.stop_instruction(); - let bytecode = context.artifact().finish().byte_code; - let number_sequence: Vec = (0_usize..12_usize).map(Value::from).collect(); + let bytecode: Vec = context.artifact().finish().byte_code; + let number_sequence: Vec = + (0_usize..12_usize).map(FieldElement::from).collect(); let mut vm = VM::new( vec![], &bytecode, diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/artifact.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/artifact.rs index d10dcf13d9f..8ce15ba4e73 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_ir/artifact.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/artifact.rs @@ -3,7 +3,7 @@ use std::collections::{BTreeMap, HashMap}; use crate::ssa::ir::dfg::CallStack; -/// Represents a parameter or a return value of a function. +/// Represents a parameter or a return value of an entry point function. #[derive(Debug, Clone)] pub(crate) enum BrilligParameter { /// A single address parameter or return value. Holds the bit size of the parameter. @@ -11,7 +11,8 @@ pub(crate) enum BrilligParameter { /// An array parameter or return value. Holds the type of an array item and its size. Array(Vec, usize), /// A slice parameter or return value. Holds the type of a slice item. - Slice(Vec), + /// Only known-length slices can be passed to brillig entry points, so the size is available as well. + Slice(Vec, usize), } /// The result of compiling and linking brillig artifacts. @@ -108,7 +109,7 @@ impl BrilligArtifact { self.byte_code.append(&mut byte_code); // Remove all resolved external calls and transform them to jumps - let is_resolved = |label: &Label| self.labels.get(label).is_some(); + let is_resolved = |label: &Label| self.labels.contains_key(label); let resolved_external_calls = self .unresolved_external_call_labels diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/brillig_variable.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/brillig_variable.rs index 48ad3c5bae4..bbfdbb69f7c 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_ir/brillig_variable.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/brillig_variable.rs @@ -1,16 +1,33 @@ -use acvm::brillig_vm::brillig::{ - HeapArray, HeapValueType, HeapVector, MemoryAddress, ValueOrArray, +use acvm::{ + brillig_vm::brillig::{HeapArray, HeapValueType, HeapVector, MemoryAddress, ValueOrArray}, + FieldElement, }; use serde::{Deserialize, Serialize}; use crate::ssa::ir::types::Type; +use super::BRILLIG_MEMORY_ADDRESSING_BIT_SIZE; + #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy)] pub(crate) struct SingleAddrVariable { pub(crate) address: MemoryAddress, pub(crate) bit_size: u32, } +impl SingleAddrVariable { + pub(crate) fn new(address: MemoryAddress, bit_size: u32) -> Self { + SingleAddrVariable { address, bit_size } + } + + pub(crate) fn new_usize(address: MemoryAddress) -> Self { + SingleAddrVariable { address, bit_size: BRILLIG_MEMORY_ADDRESSING_BIT_SIZE } + } + + pub(crate) fn new_field(address: MemoryAddress) -> Self { + SingleAddrVariable { address, bit_size: FieldElement::max_num_bits() } + } +} + /// The representation of a noir array in the Brillig IR #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Copy)] pub(crate) struct BrilligArray { @@ -108,7 +125,9 @@ impl BrilligVariable { pub(crate) fn type_to_heap_value_type(typ: &Type) -> HeapValueType { match typ { - Type::Numeric(_) | Type::Reference(_) | Type::Function => HeapValueType::Simple, + Type::Numeric(_) | Type::Reference(_) | Type::Function => { + HeapValueType::Simple(get_bit_size_from_ssa_type(typ)) + } Type::Array(elem_type, size) => HeapValueType::Array { value_types: elem_type.as_ref().iter().map(type_to_heap_value_type).collect(), size: typ.element_size() * size, @@ -118,3 +137,14 @@ pub(crate) fn type_to_heap_value_type(typ: &Type) -> HeapValueType { }, } } + +pub(crate) fn get_bit_size_from_ssa_type(typ: &Type) -> u32 { + match typ { + Type::Reference(_) => BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, + // NB. function references are converted to a constant when + // translating from SSA to Brillig (to allow for debugger + // instrumentation to work properly) + Type::Function => 32, + typ => typ.bit_size(), + } +} diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_binary.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_binary.rs new file mode 100644 index 00000000000..4ef279bd532 --- /dev/null +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_binary.rs @@ -0,0 +1,29 @@ +use acvm::{acir::brillig::MemoryAddress, FieldElement}; + +use super::{instructions::BrilligBinaryOp, BrilligContext}; + +impl BrilligContext { + /// Utility method to perform a binary instruction with a constant value in place + pub(crate) fn codegen_usize_op_in_place( + &mut self, + destination: MemoryAddress, + op: BrilligBinaryOp, + constant: usize, + ) { + self.codegen_usize_op(destination, destination, op, constant); + } + + /// Utility method to perform a binary instruction with a constant value + pub(crate) fn codegen_usize_op( + &mut self, + operand: MemoryAddress, + destination: MemoryAddress, + op: BrilligBinaryOp, + constant: usize, + ) { + let const_register = self.make_usize_constant_instruction(FieldElement::from(constant)); + self.memory_op_instruction(operand, const_register.address, destination, op); + // Mark as no longer used for this purpose, frees for reuse + self.deallocate_single_addr(const_register); + } +} diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_calls.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_calls.rs new file mode 100644 index 00000000000..db65849a6b8 --- /dev/null +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_calls.rs @@ -0,0 +1,102 @@ +use acvm::acir::brillig::MemoryAddress; + +use super::{ + brillig_variable::BrilligVariable, BrilligBinaryOp, BrilligContext, ReservedRegisters, +}; + +impl BrilligContext { + /// Saves all of the registers that have been used up until this point. + fn codegen_save_registers_of_vars(&mut self, vars: &[BrilligVariable]) -> Vec { + // Save all of the used registers at this point in memory + // because the function call will/may overwrite them. + // + // Note that here it is important that the stack pointer register is at register 0, + // as after the first register save we add to the pointer. + let mut used_registers: Vec<_> = + vars.iter().flat_map(|var| var.extract_registers()).collect(); + + // Also dump the previous stack pointer + used_registers.push(ReservedRegisters::previous_stack_pointer()); + for register in used_registers.iter() { + self.store_instruction(ReservedRegisters::free_memory_pointer(), *register); + // Add one to our stack pointer + self.codegen_usize_op_in_place( + ReservedRegisters::free_memory_pointer(), + BrilligBinaryOp::Add, + 1, + ); + } + + // Store the location of our registers in the previous stack pointer + self.mov_instruction( + ReservedRegisters::previous_stack_pointer(), + ReservedRegisters::free_memory_pointer(), + ); + used_registers + } + + /// Loads all of the registers that have been save by save_all_used_registers. + fn codegen_load_all_saved_registers(&mut self, used_registers: &[MemoryAddress]) { + // Load all of the used registers that we saved. + // We do all the reverse operations of save_all_used_registers. + // Iterate our registers in reverse + let iterator_register = self.allocate_register(); + self.mov_instruction(iterator_register, ReservedRegisters::previous_stack_pointer()); + + for register in used_registers.iter().rev() { + // Subtract one from our stack pointer + self.codegen_usize_op_in_place(iterator_register, BrilligBinaryOp::Sub, 1); + self.load_instruction(*register, iterator_register); + } + } + + // Used before a call instruction. + // Save all the registers we have used to the stack. + // Move argument values to the front of the register indices. + pub(crate) fn codegen_pre_call_save_registers_prep_args( + &mut self, + arguments: &[MemoryAddress], + variables_to_save: &[BrilligVariable], + ) -> Vec { + // Save all the registers we have used to the stack. + let saved_registers = self.codegen_save_registers_of_vars(variables_to_save); + + // Move argument values to the front of the registers + // + // This means that the arguments will be in the first `n` registers after + // the number of reserved registers. + let (sources, destinations): (Vec<_>, Vec<_>) = + arguments.iter().enumerate().map(|(i, argument)| (*argument, self.register(i))).unzip(); + destinations + .iter() + .for_each(|destination| self.registers.ensure_register_is_allocated(*destination)); + self.codegen_mov_registers_to_registers(sources, destinations); + saved_registers + } + + // Used after a call instruction. + // Move return values to the front of the register indices. + // Load all the registers we have previous saved in save_registers_prep_args. + pub(crate) fn codegen_post_call_prep_returns_load_registers( + &mut self, + result_registers: &[MemoryAddress], + saved_registers: &[MemoryAddress], + ) { + // Allocate our result registers and write into them + // We assume the return values of our call are held in 0..num results register indices + let (sources, destinations): (Vec<_>, Vec<_>) = result_registers + .iter() + .enumerate() + .map(|(i, result_register)| (self.register(i), *result_register)) + .unzip(); + sources.iter().for_each(|source| self.registers.ensure_register_is_allocated(*source)); + self.codegen_mov_registers_to_registers(sources, destinations); + + // Restore all the same registers we have, in exact reverse order. + // Note that we have allocated some registers above, which we will not be handling here, + // only restoring registers that were used prior to the call finishing. + // After the call instruction, the stack frame pointer should be back to where we left off, + // so we do our instructions in reverse order. + self.codegen_load_all_saved_registers(saved_registers); + } +} diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_control_flow.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_control_flow.rs new file mode 100644 index 00000000000..116eaa5103f --- /dev/null +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_control_flow.rs @@ -0,0 +1,141 @@ +use acvm::acir::brillig::MemoryAddress; + +use super::{ + brillig_variable::SingleAddrVariable, BrilligBinaryOp, BrilligContext, ReservedRegisters, +}; + +impl BrilligContext { + /// Codegens a return from the current function. + /// + /// For Brillig, the return is implicit, since there is no explicit return instruction. + /// The caller will take `N` values from the Register starting at register index 0. + /// `N` indicates the number of return values expected. + /// + /// Brillig does not have an explicit return instruction, so this + /// method will move all register values to the first `N` values in + /// the VM. + pub(crate) fn codegen_return(&mut self, return_registers: &[MemoryAddress]) { + let mut sources = Vec::with_capacity(return_registers.len()); + let mut destinations = Vec::with_capacity(return_registers.len()); + + for (destination_index, return_register) in return_registers.iter().enumerate() { + // In case we have fewer return registers than indices to write to, ensure we've allocated this register + let destination_register = ReservedRegisters::user_register_index(destination_index); + self.registers.ensure_register_is_allocated(destination_register); + sources.push(*return_register); + destinations.push(destination_register); + } + destinations + .iter() + .for_each(|destination| self.registers.ensure_register_is_allocated(*destination)); + self.codegen_mov_registers_to_registers(sources, destinations); + self.stop_instruction(); + } + + /// This codegen will issue a loop that will iterate iteration_count times + /// The body of the loop should be issued by the caller in the on_iteration closure. + pub(crate) fn codegen_loop(&mut self, iteration_count: MemoryAddress, on_iteration: F) + where + F: FnOnce(&mut BrilligContext, SingleAddrVariable), + { + let iterator_register = self.make_usize_constant_instruction(0_u128.into()); + + let (loop_section, loop_label) = self.reserve_next_section_label(); + self.enter_section(loop_section); + + // Loop body + + // Check if iterator < iteration_count + let iterator_less_than_iterations = + SingleAddrVariable { address: self.allocate_register(), bit_size: 1 }; + + self.memory_op_instruction( + iterator_register.address, + iteration_count, + iterator_less_than_iterations.address, + BrilligBinaryOp::LessThan, + ); + + let (exit_loop_section, exit_loop_label) = self.reserve_next_section_label(); + + self.not_instruction(iterator_less_than_iterations, iterator_less_than_iterations); + + self.jump_if_instruction(iterator_less_than_iterations.address, exit_loop_label); + + // Call the on iteration function + on_iteration(self, iterator_register); + + // Increment the iterator register + self.codegen_usize_op_in_place(iterator_register.address, BrilligBinaryOp::Add, 1); + + self.jump_instruction(loop_label); + + // Exit the loop + self.enter_section(exit_loop_section); + + // Deallocate our temporary registers + self.deallocate_single_addr(iterator_less_than_iterations); + self.deallocate_single_addr(iterator_register); + } + + /// This codegen will issue an if-then branch that will check if the condition is true + /// and if so, perform the instructions given in `f(self, true)` and otherwise perform the + /// instructions given in `f(self, false)`. A boolean is passed instead of two separate + /// functions to allow the given function to mutably alias its environment. + pub(crate) fn codegen_branch( + &mut self, + condition: MemoryAddress, + mut f: impl FnMut(&mut BrilligContext, bool), + ) { + // Reserve 3 sections + let (then_section, then_label) = self.reserve_next_section_label(); + let (otherwise_section, otherwise_label) = self.reserve_next_section_label(); + let (end_section, end_label) = self.reserve_next_section_label(); + + self.jump_if_instruction(condition, then_label.clone()); + self.jump_instruction(otherwise_label.clone()); + + self.enter_section(then_section); + f(self, true); + self.jump_instruction(end_label.clone()); + + self.enter_section(otherwise_section); + f(self, false); + self.jump_instruction(end_label.clone()); + + self.enter_section(end_section); + } + + /// This codegen issues a branch that jumps over the code generated by the given function if the condition is false + pub(crate) fn codegen_if( + &mut self, + condition: MemoryAddress, + f: impl FnOnce(&mut BrilligContext), + ) { + let (end_section, end_label) = self.reserve_next_section_label(); + let (then_section, then_label) = self.reserve_next_section_label(); + + self.jump_if_instruction(condition, then_label.clone()); + self.jump_instruction(end_label.clone()); + + self.enter_section(then_section); + f(self); + + self.enter_section(end_section); + } + + /// This codegen issues a branch that jumps over the code generated by the given function if the condition is truthy + pub(crate) fn codegen_if_not( + &mut self, + condition: MemoryAddress, + f: impl FnOnce(&mut BrilligContext), + ) { + let (end_section, end_label) = self.reserve_next_section_label(); + + self.jump_if_instruction(condition, end_label.clone()); + + f(self); + + self.enter_section(end_section); + } +} diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_intrinsic.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_intrinsic.rs new file mode 100644 index 00000000000..ab756217bcd --- /dev/null +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_intrinsic.rs @@ -0,0 +1,95 @@ +use acvm::FieldElement; + +use crate::brillig::brillig_ir::BrilligBinaryOp; + +use super::{ + brillig_variable::{BrilligVector, SingleAddrVariable}, + BrilligContext, +}; + +impl BrilligContext { + /// Codegens a truncation of a value to the given bit size + pub(crate) fn codegen_truncate( + &mut self, + destination_of_truncated_value: SingleAddrVariable, + value_to_truncate: SingleAddrVariable, + bit_size: u32, + ) { + assert!( + bit_size <= value_to_truncate.bit_size, + "tried to truncate to a bit size {} greater than the variable size {}", + bit_size, + value_to_truncate.bit_size + ); + + // We cast back and forth to ensure that the value is truncated. + let intermediate_register = + SingleAddrVariable { address: self.allocate_register(), bit_size }; + self.cast_instruction(intermediate_register, value_to_truncate); + self.cast_instruction(destination_of_truncated_value, intermediate_register); + self.deallocate_single_addr(intermediate_register); + } + + /// Issues a to_radix instruction. This instruction will write the modulus of the source register + /// And the radix register limb_count times to the target vector. + pub(crate) fn codegen_to_radix( + &mut self, + source_field: SingleAddrVariable, + target_vector: BrilligVector, + radix: SingleAddrVariable, + limb_count: SingleAddrVariable, + big_endian: bool, + limb_bit_size: u32, + ) { + assert!(source_field.bit_size == FieldElement::max_num_bits()); + assert!(radix.bit_size == 32); + assert!(limb_count.bit_size == 32); + let radix_as_field = + SingleAddrVariable::new(self.allocate_register(), FieldElement::max_num_bits()); + self.cast_instruction(radix_as_field, radix); + + self.cast_instruction(SingleAddrVariable::new_usize(target_vector.size), limb_count); + self.usize_const_instruction(target_vector.rc, 1_usize.into()); + self.codegen_allocate_array(target_vector.pointer, target_vector.size); + + let shifted_field = + SingleAddrVariable::new(self.allocate_register(), FieldElement::max_num_bits()); + self.mov_instruction(shifted_field.address, source_field.address); + + let limb_field = + SingleAddrVariable::new(self.allocate_register(), FieldElement::max_num_bits()); + + let limb_casted = SingleAddrVariable::new(self.allocate_register(), limb_bit_size); + + self.codegen_loop(target_vector.size, |ctx, iterator_register| { + // Compute the modulus + ctx.binary_instruction( + shifted_field, + radix_as_field, + limb_field, + BrilligBinaryOp::Modulo, + ); + // Cast it + ctx.cast_instruction(limb_casted, limb_field); + // Write it + ctx.codegen_array_set(target_vector.pointer, iterator_register, limb_casted.address); + // Integer div the field + ctx.binary_instruction( + shifted_field, + radix_as_field, + shifted_field, + BrilligBinaryOp::UnsignedDiv, + ); + }); + + // Deallocate our temporary registers + self.deallocate_single_addr(shifted_field); + self.deallocate_single_addr(limb_field); + self.deallocate_single_addr(limb_casted); + self.deallocate_single_addr(radix_as_field); + + if big_endian { + self.codegen_reverse_vector_in_place(target_vector); + } + } +} diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_memory.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_memory.rs new file mode 100644 index 00000000000..15761113f51 --- /dev/null +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_memory.rs @@ -0,0 +1,255 @@ +use acvm::acir::brillig::MemoryAddress; + +use crate::brillig::brillig_ir::BrilligBinaryOp; + +use super::{ + brillig_variable::{BrilligArray, BrilligVariable, BrilligVector, SingleAddrVariable}, + BrilligContext, ReservedRegisters, BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, +}; + +impl BrilligContext { + /// Allocates an array of size `size` and stores the pointer to the array + /// in `pointer_register` + pub(crate) fn codegen_allocate_fixed_length_array( + &mut self, + pointer_register: MemoryAddress, + size: usize, + ) { + let size_register = self.make_usize_constant_instruction(size.into()); + self.codegen_allocate_array(pointer_register, size_register.address); + self.deallocate_single_addr(size_register); + } + + /// Allocates an array of size contained in size_register and stores the + /// pointer to the array in `pointer_register` + pub(crate) fn codegen_allocate_array( + &mut self, + pointer_register: MemoryAddress, + size_register: MemoryAddress, + ) { + self.load_free_memory_pointer_instruction(pointer_register); + self.increase_free_memory_pointer_instruction(size_register); + } + + /// Allocates a variable in memory and stores the + /// pointer to the array in `pointer_register` + fn codegen_allocate_variable_reference( + &mut self, + pointer_register: MemoryAddress, + size: usize, + ) { + // A variable can be stored in up to three values, so we reserve three values for that. + let size_register = self.make_usize_constant_instruction(size.into()); + self.mov_instruction(pointer_register, ReservedRegisters::free_memory_pointer()); + self.memory_op_instruction( + ReservedRegisters::free_memory_pointer(), + size_register.address, + ReservedRegisters::free_memory_pointer(), + BrilligBinaryOp::Add, + ); + self.deallocate_single_addr(size_register); + } + + pub(crate) fn codegen_allocate_single_addr_reference( + &mut self, + pointer_register: MemoryAddress, + ) { + self.codegen_allocate_variable_reference(pointer_register, 1); + } + + pub(crate) fn codegen_allocate_array_reference(&mut self, pointer_register: MemoryAddress) { + self.codegen_allocate_variable_reference(pointer_register, BrilligArray::registers_count()); + } + + pub(crate) fn codegen_allocate_vector_reference(&mut self, pointer_register: MemoryAddress) { + self.codegen_allocate_variable_reference( + pointer_register, + BrilligVector::registers_count(), + ); + } + + /// Gets the value in the array at index `index` and stores it in `result` + pub(crate) fn codegen_array_get( + &mut self, + array_ptr: MemoryAddress, + index: SingleAddrVariable, + result: MemoryAddress, + ) { + assert!(index.bit_size == BRILLIG_MEMORY_ADDRESSING_BIT_SIZE); + // Computes array_ptr + index, ie array[index] + let index_of_element_in_memory = self.allocate_register(); + self.memory_op_instruction( + array_ptr, + index.address, + index_of_element_in_memory, + BrilligBinaryOp::Add, + ); + self.load_instruction(result, index_of_element_in_memory); + // Free up temporary register + self.deallocate_register(index_of_element_in_memory); + } + + /// Sets the item in the array at index `index` to `value` + pub(crate) fn codegen_array_set( + &mut self, + array_ptr: MemoryAddress, + index: SingleAddrVariable, + value: MemoryAddress, + ) { + assert!(index.bit_size == BRILLIG_MEMORY_ADDRESSING_BIT_SIZE); + // Computes array_ptr + index, ie array[index] + let index_of_element_in_memory = self.allocate_register(); + self.binary_instruction( + SingleAddrVariable::new_usize(array_ptr), + index, + SingleAddrVariable::new_usize(index_of_element_in_memory), + BrilligBinaryOp::Add, + ); + + self.store_instruction(index_of_element_in_memory, value); + // Free up temporary register + self.deallocate_register(index_of_element_in_memory); + } + + /// Copies the values of an array pointed by source with length stored in `num_elements_register` + /// Into the array pointed by destination + pub(crate) fn codegen_copy_array( + &mut self, + source_pointer: MemoryAddress, + destination_pointer: MemoryAddress, + num_elements_variable: SingleAddrVariable, + ) { + assert!(num_elements_variable.bit_size == BRILLIG_MEMORY_ADDRESSING_BIT_SIZE); + + let value_register = self.allocate_register(); + + self.codegen_loop(num_elements_variable.address, |ctx, iterator| { + ctx.codegen_array_get(source_pointer, iterator, value_register); + ctx.codegen_array_set(destination_pointer, iterator, value_register); + }); + + self.deallocate_register(value_register); + } + + /// Loads a variable stored previously + pub(crate) fn codegen_load_variable( + &mut self, + destination: BrilligVariable, + variable_pointer: MemoryAddress, + ) { + match destination { + BrilligVariable::SingleAddr(single_addr) => { + self.load_instruction(single_addr.address, variable_pointer); + } + BrilligVariable::BrilligArray(BrilligArray { pointer, size: _, rc }) => { + self.load_instruction(pointer, variable_pointer); + + let rc_pointer = self.allocate_register(); + self.mov_instruction(rc_pointer, variable_pointer); + self.codegen_usize_op_in_place(rc_pointer, BrilligBinaryOp::Add, 1_usize); + + self.load_instruction(rc, rc_pointer); + self.deallocate_register(rc_pointer); + } + BrilligVariable::BrilligVector(BrilligVector { pointer, size, rc }) => { + self.load_instruction(pointer, variable_pointer); + + let size_pointer = self.allocate_register(); + self.mov_instruction(size_pointer, variable_pointer); + self.codegen_usize_op_in_place(size_pointer, BrilligBinaryOp::Add, 1_usize); + + self.load_instruction(size, size_pointer); + self.deallocate_register(size_pointer); + + let rc_pointer = self.allocate_register(); + self.mov_instruction(rc_pointer, variable_pointer); + self.codegen_usize_op_in_place(rc_pointer, BrilligBinaryOp::Add, 2_usize); + + self.load_instruction(rc, rc_pointer); + self.deallocate_register(rc_pointer); + } + } + } + + /// Stores a variable by saving its registers to memory + pub(crate) fn codegen_store_variable( + &mut self, + variable_pointer: MemoryAddress, + source: BrilligVariable, + ) { + match source { + BrilligVariable::SingleAddr(single_addr) => { + self.store_instruction(variable_pointer, single_addr.address); + } + BrilligVariable::BrilligArray(BrilligArray { pointer, size: _, rc }) => { + self.store_instruction(variable_pointer, pointer); + + let rc_pointer: MemoryAddress = self.allocate_register(); + self.mov_instruction(rc_pointer, variable_pointer); + self.codegen_usize_op_in_place(rc_pointer, BrilligBinaryOp::Add, 1_usize); + self.store_instruction(rc_pointer, rc); + self.deallocate_register(rc_pointer); + } + BrilligVariable::BrilligVector(BrilligVector { pointer, size, rc }) => { + self.store_instruction(variable_pointer, pointer); + + let size_pointer = self.allocate_register(); + self.mov_instruction(size_pointer, variable_pointer); + self.codegen_usize_op_in_place(size_pointer, BrilligBinaryOp::Add, 1_usize); + self.store_instruction(size_pointer, size); + + let rc_pointer: MemoryAddress = self.allocate_register(); + self.mov_instruction(rc_pointer, variable_pointer); + self.codegen_usize_op_in_place(rc_pointer, BrilligBinaryOp::Add, 2_usize); + self.store_instruction(rc_pointer, rc); + + self.deallocate_register(size_pointer); + self.deallocate_register(rc_pointer); + } + } + } + + /// This instruction will reverse the order of the elements in a vector. + pub(crate) fn codegen_reverse_vector_in_place(&mut self, vector: BrilligVector) { + let iteration_count = self.allocate_register(); + self.codegen_usize_op(vector.size, iteration_count, BrilligBinaryOp::UnsignedDiv, 2); + + let start_value_register = self.allocate_register(); + let index_at_end_of_array = self.allocate_register(); + let end_value_register = self.allocate_register(); + + self.codegen_loop(iteration_count, |ctx, iterator_register| { + // Load both values + ctx.codegen_array_get(vector.pointer, iterator_register, start_value_register); + + // The index at the end of array is size - 1 - iterator + ctx.mov_instruction(index_at_end_of_array, vector.size); + ctx.codegen_usize_op_in_place(index_at_end_of_array, BrilligBinaryOp::Sub, 1); + ctx.memory_op_instruction( + index_at_end_of_array, + iterator_register.address, + index_at_end_of_array, + BrilligBinaryOp::Sub, + ); + + ctx.codegen_array_get( + vector.pointer, + SingleAddrVariable::new_usize(index_at_end_of_array), + end_value_register, + ); + + // Write both values + ctx.codegen_array_set(vector.pointer, iterator_register, end_value_register); + ctx.codegen_array_set( + vector.pointer, + SingleAddrVariable::new_usize(index_at_end_of_array), + start_value_register, + ); + }); + + self.deallocate_register(iteration_count); + self.deallocate_register(start_value_register); + self.deallocate_register(end_value_register); + self.deallocate_register(index_at_end_of_array); + } +} diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_stack.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_stack.rs new file mode 100644 index 00000000000..1c30f0f848f --- /dev/null +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_stack.rs @@ -0,0 +1,26 @@ +use acvm::acir::brillig::MemoryAddress; + +use super::BrilligContext; + +impl BrilligContext { + /// This function moves values from a set of registers to another set of registers. + /// It first moves all sources to new allocated registers to avoid overwriting. + pub(crate) fn codegen_mov_registers_to_registers( + &mut self, + sources: Vec, + destinations: Vec, + ) { + let new_sources: Vec<_> = sources + .iter() + .map(|source| { + let new_source = self.allocate_register(); + self.mov_instruction(new_source, *source); + new_source + }) + .collect(); + for (new_source, destination) in new_sources.iter().zip(destinations.iter()) { + self.mov_instruction(*destination, *new_source); + self.deallocate_register(*new_source); + } + } +} diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs index dd57f0c4426..4ca1144b6a4 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/debug_show.rs @@ -1,10 +1,10 @@ //! This module contains functions for producing a higher level view disassembler of Brillig. use super::BrilligBinaryOp; -use crate::brillig::brillig_ir::{ReservedRegisters, BRILLIG_MEMORY_ADDRESSING_BIT_SIZE}; -use acvm::acir::brillig::{ - BinaryFieldOp, BinaryIntOp, BlackBoxOp, HeapArray, HeapVector, MemoryAddress, Value, - ValueOrArray, +use crate::brillig::brillig_ir::ReservedRegisters; +use acvm::{ + acir::brillig::{BlackBoxOp, HeapArray, HeapVector, MemoryAddress, ValueOrArray}, + FieldElement, }; /// Trait for converting values into debug-friendly strings. @@ -26,8 +26,8 @@ default_to_string_impl! { str usize u32 } impl DebugToString for MemoryAddress { fn debug_to_string(&self) -> String { - if *self == ReservedRegisters::stack_pointer() { - "Stack".into() + if *self == ReservedRegisters::free_memory_pointer() { + "FreeMem".into() } else if *self == ReservedRegisters::previous_stack_pointer() { "PrevStack".into() } else { @@ -48,66 +48,30 @@ impl DebugToString for HeapVector { } } -impl DebugToString for BinaryFieldOp { - fn debug_to_string(&self) -> String { - match self { - BinaryFieldOp::Add => "f+".into(), - BinaryFieldOp::Sub => "f-".into(), - BinaryFieldOp::Mul => "f*".into(), - BinaryFieldOp::Div => "f/".into(), - BinaryFieldOp::Equals => "f==".into(), - } - } -} - -impl DebugToString for BinaryIntOp { - fn debug_to_string(&self) -> String { - match self { - BinaryIntOp::Add => "+".into(), - BinaryIntOp::Sub => "-".into(), - BinaryIntOp::Mul => "*".into(), - BinaryIntOp::Equals => "==".into(), - BinaryIntOp::SignedDiv => "/".into(), - BinaryIntOp::UnsignedDiv => "//".into(), - BinaryIntOp::LessThan => "<".into(), - BinaryIntOp::LessThanEquals => "<=".into(), - BinaryIntOp::And => "&&".into(), - BinaryIntOp::Or => "||".into(), - BinaryIntOp::Xor => "^".into(), - BinaryIntOp::Shl => "<<".into(), - BinaryIntOp::Shr => ">>".into(), - } - } -} - impl DebugToString for BrilligBinaryOp { fn debug_to_string(&self) -> String { match self { - BrilligBinaryOp::Field { op } => op.debug_to_string(), - BrilligBinaryOp::Integer { op, bit_size } => { - // rationale: if there's >= 64 bits, we should not bother with this detail - if *bit_size >= BRILLIG_MEMORY_ADDRESSING_BIT_SIZE { - op.debug_to_string() - } else { - format!("i{}::{}", bit_size, op.debug_to_string()) - } - } - BrilligBinaryOp::Modulo { is_signed_integer, bit_size } => { - let op = if *is_signed_integer { "%" } else { "%%" }; - // rationale: if there's >= 64 bits, we should not bother with this detail - if *bit_size >= BRILLIG_MEMORY_ADDRESSING_BIT_SIZE { - op.into() - } else { - format!("{op}:{bit_size}") - } - } + BrilligBinaryOp::Add => "+".into(), + BrilligBinaryOp::Sub => "-".into(), + BrilligBinaryOp::Mul => "*".into(), + BrilligBinaryOp::Equals => "==".into(), + BrilligBinaryOp::FieldDiv => "f/".into(), + BrilligBinaryOp::UnsignedDiv => "/".into(), + BrilligBinaryOp::LessThan => "<".into(), + BrilligBinaryOp::LessThanEquals => "<=".into(), + BrilligBinaryOp::And => "&&".into(), + BrilligBinaryOp::Or => "||".into(), + BrilligBinaryOp::Xor => "^".into(), + BrilligBinaryOp::Shl => "<<".into(), + BrilligBinaryOp::Shr => ">>".into(), + BrilligBinaryOp::Modulo => "%".into(), } } } -impl DebugToString for Value { +impl DebugToString for FieldElement { fn debug_to_string(&self) -> String { - self.to_usize().to_string() + self.to_string() } } @@ -155,22 +119,29 @@ impl DebugShow { debug_println!(self.enable_debug_trace, " ASSERT {} != 0", condition); } - /// Processes a return instruction. - pub(crate) fn return_instruction(&self, return_registers: &[MemoryAddress]) { - let registers_string = return_registers - .iter() - .map(MemoryAddress::debug_to_string) - .collect::>() - .join(", "); - - debug_println!(self.enable_debug_trace, " // return {};", registers_string); - } - /// Emits a `mov` instruction. pub(crate) fn mov_instruction(&self, destination: MemoryAddress, source: MemoryAddress) { debug_println!(self.enable_debug_trace, " MOV {}, {}", destination, source); } + /// Emits a conditional `mov` instruction. + pub(crate) fn conditional_mov_instruction( + &self, + destination: MemoryAddress, + condition: MemoryAddress, + source_a: MemoryAddress, + source_b: MemoryAddress, + ) { + debug_println!( + self.enable_debug_trace, + " CMOV {} = {}? {} : {}", + destination, + condition, + source_a, + source_b + ); + } + /// Emits a `cast` instruction. pub(crate) fn cast_instruction( &self, @@ -199,7 +170,7 @@ impl DebugShow { } /// Stores the value of `constant` in the `result` register - pub(crate) fn const_instruction(&self, result: MemoryAddress, constant: Value) { + pub(crate) fn const_instruction(&self, result: MemoryAddress, constant: FieldElement) { debug_println!(self.enable_debug_trace, " CONST {} = {}", result, constant); } @@ -252,64 +223,17 @@ impl DebugShow { debug_println!(self.enable_debug_trace, " STOP"); } - /// Debug function for allocate_array_instruction - pub(crate) fn allocate_array_instruction( - &self, - pointer_register: MemoryAddress, - size_register: MemoryAddress, - ) { - debug_println!( - self.enable_debug_trace, - " ALLOCATE_ARRAY {} SIZE {}", - pointer_register, - size_register - ); - } - - /// Debug function for allocate_instruction - pub(crate) fn allocate_instruction(&self, pointer_register: MemoryAddress) { - debug_println!(self.enable_debug_trace, " ALLOCATE {} ", pointer_register); - } - - /// Debug function for array_get - pub(crate) fn array_get( + /// Emits a external stop instruction (returns data) + pub(crate) fn external_stop_instruction( &self, - array_ptr: MemoryAddress, - index: MemoryAddress, - result: MemoryAddress, + return_data_offset: usize, + return_data_size: usize, ) { debug_println!( self.enable_debug_trace, - " ARRAY_GET {}[{}] -> {}", - array_ptr, - index, - result - ); - } - - /// Debug function for array_set - pub(crate) fn array_set( - &self, - array_ptr: MemoryAddress, - index: MemoryAddress, - value: MemoryAddress, - ) { - debug_println!(self.enable_debug_trace, " ARRAY_SET {}[{}] = {}", array_ptr, index, value); - } - - /// Debug function for copy_array_instruction - pub(crate) fn copy_array_instruction( - &self, - source: MemoryAddress, - destination: MemoryAddress, - num_elements_register: MemoryAddress, - ) { - debug_println!( - self.enable_debug_trace, - " COPY_ARRAY {} -> {} ({} ELEMENTS)", - source, - destination, - num_elements_register + " EXT_STOP {}..{}", + return_data_offset, + return_data_offset + return_data_size ); } @@ -340,22 +264,6 @@ impl DebugShow { ); } - /// Debug function for cast_instruction - pub(crate) fn truncate_instruction( - &self, - destination: MemoryAddress, - source: MemoryAddress, - target_bit_size: u32, - ) { - debug_println!( - self.enable_debug_trace, - " TRUNCATE {} FROM {} TO {} BITS", - destination, - source, - target_bit_size - ); - } - /// Debug function for black_box_op pub(crate) fn black_box_op_instruction(&self, op: &BlackBoxOp) { match op { @@ -541,4 +449,20 @@ impl DebugShow { pub(crate) fn add_external_call_instruction(&self, func_label: String) { debug_println!(self.enable_debug_trace, " CALL {}", func_label); } + + /// Debug function for calldata_copy + pub(crate) fn calldata_copy_instruction( + &self, + destination: MemoryAddress, + calldata_size: usize, + offset: usize, + ) { + debug_println!( + self.enable_debug_trace, + " CALLDATA_COPY {} {}..{}", + destination, + offset, + offset + calldata_size + ); + } } diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/entry_point.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/entry_point.rs index 9d186f9bc60..db872487fcc 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_ir/entry_point.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/entry_point.rs @@ -1,14 +1,11 @@ use super::{ artifact::{BrilligArtifact, BrilligParameter}, - brillig_variable::{BrilligArray, BrilligVariable, SingleAddrVariable}, + brillig_variable::{BrilligArray, BrilligVariable, BrilligVector, SingleAddrVariable}, debug_show::DebugShow, registers::BrilligRegistersContext, - BrilligContext, ReservedRegisters, BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, -}; -use acvm::{ - acir::brillig::{MemoryAddress, Opcode as BrilligOpcode}, - FieldElement, + BrilligBinaryOp, BrilligContext, ReservedRegisters, }; +use acvm::{acir::brillig::MemoryAddress, FieldElement}; pub(crate) const MAX_STACK_SIZE: usize = 1024; @@ -28,18 +25,18 @@ impl BrilligContext { debug_show: DebugShow::new(false), }; - context.entry_point_instruction(&arguments, &return_parameters); + context.codegen_entry_point(&arguments, &return_parameters); context.add_external_call_instruction(target_function); - context.exit_point_instruction(&arguments, &return_parameters); + context.codegen_exit_point(&arguments, &return_parameters); context.artifact() } /// Adds the instructions needed to handle entry point parameters /// The runtime will leave the parameters in calldata. /// Arrays will be passed flattened. - fn entry_point_instruction( + fn codegen_entry_point( &mut self, arguments: &[BrilligParameter], return_parameters: &[BrilligParameter], @@ -48,11 +45,10 @@ impl BrilligContext { let return_data_size = BrilligContext::flattened_tuple_size(return_parameters); // Set initial value of stack pointer: MAX_STACK_SIZE + calldata_size + return_data_size - self.push_opcode(BrilligOpcode::Const { - destination: ReservedRegisters::stack_pointer(), - value: (MAX_STACK_SIZE + calldata_size + return_data_size).into(), - bit_size: BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, - }); + self.const_instruction( + SingleAddrVariable::new_usize(ReservedRegisters::free_memory_pointer()), + (MAX_STACK_SIZE + calldata_size + return_data_size).into(), + ); // Copy calldata self.copy_and_cast_calldata(arguments); @@ -75,66 +71,93 @@ impl BrilligContext { } BrilligParameter::Array(_, _) => { let pointer_to_the_array_in_calldata = - self.make_usize_constant(current_calldata_pointer.into()); - let rc_register = self.make_usize_constant(1_usize.into()); + self.make_usize_constant_instruction(current_calldata_pointer.into()); + let rc_register = self.make_usize_constant_instruction(1_usize.into()); let flattened_size = BrilligContext::flattened_size(argument); let var = BrilligVariable::BrilligArray(BrilligArray { - pointer: pointer_to_the_array_in_calldata, + pointer: pointer_to_the_array_in_calldata.address, size: flattened_size, - rc: rc_register, + rc: rc_register.address, + }); + + current_calldata_pointer += flattened_size; + var + } + BrilligParameter::Slice(_, _) => { + let pointer_to_the_array_in_calldata = + self.make_usize_constant_instruction(current_calldata_pointer.into()); + + let flattened_size = BrilligContext::flattened_size(argument); + let size_register = self.make_usize_constant_instruction(flattened_size.into()); + let rc_register = self.make_usize_constant_instruction(1_usize.into()); + + let var = BrilligVariable::BrilligVector(BrilligVector { + pointer: pointer_to_the_array_in_calldata.address, + size: size_register.address, + rc: rc_register.address, }); current_calldata_pointer += flattened_size; var } - BrilligParameter::Slice(_) => unimplemented!("Unsupported slices as parameter"), }) .collect(); // Deflatten arrays for (argument_variable, argument) in argument_variables.iter_mut().zip(arguments) { - if let ( - BrilligVariable::BrilligArray(array), - BrilligParameter::Array(item_type, item_count), - ) = (argument_variable, argument) - { - if BrilligContext::has_nested_arrays(item_type) { + match (argument_variable, argument) { + ( + BrilligVariable::BrilligArray(array), + BrilligParameter::Array(item_type, item_count), + ) => { let deflattened_address = self.deflatten_array(item_type, array.size, array.pointer); self.mov_instruction(array.pointer, deflattened_address); array.size = item_type.len() * item_count; self.deallocate_register(deflattened_address); } + ( + BrilligVariable::BrilligVector(vector), + BrilligParameter::Slice(item_type, item_count), + ) => { + let flattened_size = BrilligContext::flattened_size(argument); + + let deflattened_address = + self.deflatten_array(item_type, flattened_size, vector.pointer); + self.mov_instruction(vector.pointer, deflattened_address); + self.usize_const_instruction( + vector.size, + (item_type.len() * item_count).into(), + ); + + self.deallocate_register(deflattened_address); + } + _ => {} } } } fn copy_and_cast_calldata(&mut self, arguments: &[BrilligParameter]) { let calldata_size = BrilligContext::flattened_tuple_size(arguments); - self.push_opcode(BrilligOpcode::CalldataCopy { - destination_address: MemoryAddress(MAX_STACK_SIZE), - size: calldata_size, - offset: 0, - }); + self.calldata_copy_instruction(MemoryAddress(MAX_STACK_SIZE), calldata_size, 0); fn flat_bit_sizes(param: &BrilligParameter) -> Box + '_> { match param { BrilligParameter::SingleAddr(bit_size) => Box::new(std::iter::once(*bit_size)), - BrilligParameter::Array(item_types, item_count) => Box::new( + BrilligParameter::Array(item_types, item_count) + | BrilligParameter::Slice(item_types, item_count) => Box::new( (0..*item_count).flat_map(move |_| item_types.iter().flat_map(flat_bit_sizes)), ), - BrilligParameter::Slice(..) => unimplemented!("Unsupported slices as parameter"), } } for (i, bit_size) in arguments.iter().flat_map(flat_bit_sizes).enumerate() { // Calldatacopy tags everything with field type, so when downcast when necessary if bit_size < FieldElement::max_num_bits() { - self.push_opcode(BrilligOpcode::Cast { - destination: MemoryAddress(MAX_STACK_SIZE + i), - source: MemoryAddress(MAX_STACK_SIZE + i), - bit_size, - }); + self.cast_instruction( + SingleAddrVariable::new(MemoryAddress(MAX_STACK_SIZE + i), bit_size), + SingleAddrVariable::new_field(MemoryAddress(MAX_STACK_SIZE + i)), + ); } } } @@ -143,13 +166,11 @@ impl BrilligContext { fn flattened_size(param: &BrilligParameter) -> usize { match param { BrilligParameter::SingleAddr(_) => 1, - BrilligParameter::Array(item_types, item_count) => { + BrilligParameter::Array(item_types, item_count) + | BrilligParameter::Slice(item_types, item_count) => { let item_size: usize = item_types.iter().map(BrilligContext::flattened_size).sum(); item_count * item_size } - BrilligParameter::Slice(_) => { - unreachable!("ICE: Slices cannot be passed as entry point arguments") - } } } @@ -178,7 +199,7 @@ impl BrilligContext { let target_item_size = item_type.len(); let source_item_size = BrilligContext::flattened_tuple_size(item_type); - self.allocate_fixed_length_array( + self.codegen_allocate_fixed_length_array( deflattened_array_pointer, item_count * target_item_size, ); @@ -190,20 +211,22 @@ impl BrilligContext { let mut source_offset = 0; for (subitem_index, subitem) in item_type.iter().enumerate() { - let source_index = - self.make_usize_constant((source_item_base_index + source_offset).into()); + let source_index = self.make_usize_constant_instruction( + (source_item_base_index + source_offset).into(), + ); - let target_index = - self.make_usize_constant((target_item_base_index + subitem_index).into()); + let target_index = self.make_usize_constant_instruction( + (target_item_base_index + subitem_index).into(), + ); match subitem { BrilligParameter::SingleAddr(_) => { - self.array_get( + self.codegen_array_get( flattened_array_pointer, source_index, movement_register, ); - self.array_set( + self.codegen_array_set( deflattened_array_pointer, target_index, movement_register, @@ -216,11 +239,11 @@ impl BrilligContext { ) => { let nested_array_pointer = self.allocate_register(); self.mov_instruction(nested_array_pointer, flattened_array_pointer); - self.memory_op( + self.memory_op_instruction( nested_array_pointer, - source_index, + source_index.address, nested_array_pointer, - acvm::brillig_vm::brillig::BinaryIntOp::Add, + BrilligBinaryOp::Add, ); let deflattened_nested_array_pointer = self.deflatten_array( nested_array_item_type, @@ -229,17 +252,21 @@ impl BrilligContext { ); let reference = self.allocate_register(); let rc = self.allocate_register(); - self.usize_const(rc, 1_usize.into()); + self.usize_const_instruction(rc, 1_usize.into()); - self.allocate_array_reference_instruction(reference); + self.codegen_allocate_array_reference(reference); let array_variable = BrilligVariable::BrilligArray(BrilligArray { pointer: deflattened_nested_array_pointer, size: nested_array_item_type.len() * nested_array_item_count, rc, }); - self.store_variable_instruction(reference, array_variable); + self.codegen_store_variable(reference, array_variable); - self.array_set(deflattened_array_pointer, target_index, reference); + self.codegen_array_set( + deflattened_array_pointer, + target_index, + reference, + ); self.deallocate_register(nested_array_pointer); self.deallocate_register(reference); @@ -253,8 +280,8 @@ impl BrilligContext { BrilligParameter::Slice(..) => unreachable!("ICE: Cannot deflatten slices"), } - self.deallocate_register(source_index); - self.deallocate_register(target_index); + self.deallocate_single_addr(source_index); + self.deallocate_single_addr(target_index); } } @@ -272,7 +299,7 @@ impl BrilligContext { /// The runtime expects the results in a contiguous memory region. /// Arrays are expected to be returned with all the nested arrays flattened. /// However, the function called returns variables (that have extra data) and the returned arrays are deflattened. - fn exit_point_instruction( + fn codegen_exit_point( &mut self, arguments: &[BrilligParameter], return_parameters: &[BrilligParameter], @@ -318,16 +345,17 @@ impl BrilligContext { } BrilligParameter::Array(item_type, item_count) => { let returned_pointer = returned_variable.extract_array().pointer; - let pointer_to_return_data = self.make_usize_constant(return_data_index.into()); + let pointer_to_return_data = + self.make_usize_constant_instruction(return_data_index.into()); self.flatten_array( item_type, *item_count, - pointer_to_return_data, + pointer_to_return_data.address, returned_pointer, ); - self.deallocate_register(pointer_to_return_data); + self.deallocate_single_addr(pointer_to_return_data); return_data_index += BrilligContext::flattened_size(return_param); } BrilligParameter::Slice(..) => { @@ -336,7 +364,7 @@ impl BrilligContext { } } - self.push_opcode(BrilligOpcode::Stop { return_data_offset, return_data_size }); + self.external_stop_instruction(return_data_offset, return_data_size); } // Flattens an array by recursively copying nested arrays and regular items. @@ -361,19 +389,21 @@ impl BrilligContext { let mut target_offset = 0; for (subitem_index, subitem) in item_type.iter().enumerate() { - let source_index = - self.make_usize_constant((source_item_base_index + subitem_index).into()); - let target_index = - self.make_usize_constant((target_item_base_index + target_offset).into()); + let source_index = self.make_usize_constant_instruction( + (source_item_base_index + subitem_index).into(), + ); + let target_index = self.make_usize_constant_instruction( + (target_item_base_index + target_offset).into(), + ); match subitem { BrilligParameter::SingleAddr(_) => { - self.array_get( + self.codegen_array_get( deflattened_array_pointer, source_index, movement_register, ); - self.array_set( + self.codegen_array_set( flattened_array_pointer, target_index, movement_register, @@ -385,7 +415,7 @@ impl BrilligContext { nested_array_item_count, ) => { let nested_array_reference = self.allocate_register(); - self.array_get( + self.codegen_array_get( deflattened_array_pointer, source_index, nested_array_reference, @@ -398,7 +428,7 @@ impl BrilligContext { rc: self.allocate_register(), }); - self.load_variable_instruction( + self.codegen_load_variable( nested_array_variable, nested_array_reference, ); @@ -410,11 +440,11 @@ impl BrilligContext { flattened_array_pointer, ); - self.memory_op( + self.memory_op_instruction( flattened_nested_array_pointer, - target_index, + target_index.address, flattened_nested_array_pointer, - acvm::brillig_vm::brillig::BinaryIntOp::Add, + BrilligBinaryOp::Add, ); self.flatten_array( @@ -436,43 +466,41 @@ impl BrilligContext { BrilligParameter::Slice(..) => unreachable!("ICE: Cannot flatten slices"), } - self.deallocate_register(source_index); - self.deallocate_register(target_index); + self.deallocate_single_addr(source_index); + self.deallocate_single_addr(target_index); } } self.deallocate_register(movement_register); } else { - let item_count = self.make_usize_constant((item_count * item_type.len()).into()); - self.copy_array_instruction( - deflattened_array_pointer, - flattened_array_pointer, - item_count, - ); - self.deallocate_register(item_count); + let item_count = + self.make_usize_constant_instruction((item_count * item_type.len()).into()); + self.codegen_copy_array(deflattened_array_pointer, flattened_array_pointer, item_count); + self.deallocate_single_addr(item_count); } } } #[cfg(test)] mod tests { - use acvm::brillig_vm::brillig::Value; + + use acvm::FieldElement; use crate::brillig::brillig_ir::{ - artifact::BrilligParameter, brillig_variable::BrilligArray, + entry_point::BrilligParameter, tests::{create_and_run_vm, create_context, create_entry_point_bytecode}, }; #[test] fn entry_point_with_nested_array_parameter() { let calldata = vec![ - Value::from(1_usize), - Value::from(2_usize), - Value::from(3_usize), - Value::from(4_usize), - Value::from(5_usize), - Value::from(6_usize), + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + FieldElement::from(4_usize), + FieldElement::from(5_usize), + FieldElement::from(6_usize), ]; let arguments = vec![BrilligParameter::Array( vec![ @@ -493,24 +521,24 @@ mod tests { context.load_instruction(array_pointer, array_pointer); context.load_instruction(array_value, array_pointer); - context.return_instruction(&[array_value]); + context.codegen_return(&[array_value]); let bytecode = create_entry_point_bytecode(context, arguments, returns).byte_code; let (vm, return_data_offset, return_data_size) = create_and_run_vm(calldata.clone(), &bytecode); assert_eq!(return_data_size, 1, "Return data size is incorrect"); - assert_eq!(vm.get_memory()[return_data_offset], Value::from(1_usize)); + assert_eq!(vm.get_memory()[return_data_offset].value, FieldElement::from(1_usize)); } #[test] fn entry_point_with_nested_array_return() { let flattened_array = vec![ - Value::from(1_usize), - Value::from(2_usize), - Value::from(3_usize), - Value::from(4_usize), - Value::from(5_usize), - Value::from(6_usize), + FieldElement::from(1_usize), + FieldElement::from(2_usize), + FieldElement::from(3_usize), + FieldElement::from(4_usize), + FieldElement::from(5_usize), + FieldElement::from(6_usize), ]; let array_param = BrilligParameter::Array( vec![ @@ -531,7 +559,7 @@ mod tests { rc: context.allocate_register(), }; - context.return_instruction(&brillig_array.extract_registers()); + context.codegen_return(&brillig_array.extract_registers()); let bytecode = create_entry_point_bytecode(context, arguments, returns).byte_code; let (vm, return_data_pointer, return_data_size) = @@ -539,7 +567,10 @@ mod tests { let memory = vm.get_memory(); assert_eq!( - memory[return_data_pointer..(return_data_pointer + flattened_array.len())], + memory[return_data_pointer..(return_data_pointer + flattened_array.len())] + .iter() + .map(|mem_val| mem_val.value) + .collect::>(), flattened_array ); assert_eq!(return_data_size, flattened_array.len()); diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/instructions.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/instructions.rs new file mode 100644 index 00000000000..f305eb81b01 --- /dev/null +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/instructions.rs @@ -0,0 +1,547 @@ +use acvm::{ + acir::brillig::{ + BinaryFieldOp, BinaryIntOp, BlackBoxOp, HeapValueType, MemoryAddress, + Opcode as BrilligOpcode, ValueOrArray, + }, + FieldElement, +}; + +use super::{ + artifact::UnresolvedJumpLocation, + brillig_variable::{BrilligArray, BrilligVector, SingleAddrVariable}, + BrilligContext, ReservedRegisters, BRILLIG_MEMORY_ADDRESSING_BIT_SIZE, +}; + +/// Low level instructions of the brillig IR, used by the brillig ir codegens and brillig_gen +/// Printed using debug_slow +impl BrilligContext { + /// Processes a binary instruction according `operation`. + /// + /// This method will compute lhs rhs + /// and store the result in the `result` register. + pub(crate) fn binary_instruction( + &mut self, + lhs: SingleAddrVariable, + rhs: SingleAddrVariable, + result: SingleAddrVariable, + operation: BrilligBinaryOp, + ) { + self.debug_show.binary_instruction(lhs.address, rhs.address, result.address, operation); + self.binary(lhs, rhs, result, operation); + } + + /// Processes a not instruction. + /// + /// Not is computed using a subtraction operation as there is no native not instruction + /// in Brillig. + pub(crate) fn not_instruction( + &mut self, + input: SingleAddrVariable, + result: SingleAddrVariable, + ) { + self.debug_show.not_instruction(input.address, input.bit_size, result.address); + // Compile !x as ((-1) - x) + let u_max = FieldElement::from(2_i128).pow(&FieldElement::from(input.bit_size as i128)) + - FieldElement::one(); + let max = self.make_constant(u_max, input.bit_size); + + self.binary(max, input, result, BrilligBinaryOp::Sub); + self.deallocate_single_addr(max); + } + + /// Utility method to perform a binary instruction with a memory address + pub(crate) fn memory_op_instruction( + &mut self, + lhs: MemoryAddress, + rhs: MemoryAddress, + destination: MemoryAddress, + op: BrilligBinaryOp, + ) { + self.binary_instruction( + SingleAddrVariable::new_usize(lhs), + SingleAddrVariable::new_usize(rhs), + SingleAddrVariable::new( + destination, + BrilligContext::binary_result_bit_size(op, BRILLIG_MEMORY_ADDRESSING_BIT_SIZE), + ), + op, + ); + } + + fn binary( + &mut self, + lhs: SingleAddrVariable, + rhs: SingleAddrVariable, + result: SingleAddrVariable, + operation: BrilligBinaryOp, + ) { + assert!( + lhs.bit_size == rhs.bit_size, + "Not equal bit size for lhs and rhs: lhs {}, rhs {}", + lhs.bit_size, + rhs.bit_size + ); + let is_field_op = lhs.bit_size == FieldElement::max_num_bits(); + let expected_result_bit_size = + BrilligContext::binary_result_bit_size(operation, lhs.bit_size); + assert!( + result.bit_size == expected_result_bit_size, + "Expected result bit size to be {}, got {} for operation {:?}", + expected_result_bit_size, + result.bit_size, + operation + ); + + if let BrilligBinaryOp::Modulo = operation { + self.modulo(result, lhs, rhs); + } else if is_field_op { + self.push_opcode(BrilligOpcode::BinaryFieldOp { + op: operation.into(), + destination: result.address, + lhs: lhs.address, + rhs: rhs.address, + }); + } else { + self.push_opcode(BrilligOpcode::BinaryIntOp { + op: operation.into(), + destination: result.address, + bit_size: lhs.bit_size, + lhs: lhs.address, + rhs: rhs.address, + }); + } + } + + /// Computes left % right by emitting the necessary Brillig opcodes. + /// + /// This is done by using the following formula: + /// + /// a % b = a - (b * (a / b)) + /// + /// Brillig does not have an explicit modulo operation, + /// so we must emit multiple opcodes and process it differently + /// to other binary instructions. + fn modulo( + &mut self, + result: SingleAddrVariable, + left: SingleAddrVariable, + right: SingleAddrVariable, + ) { + assert!( + left.bit_size == right.bit_size, + "Not equal bitsize: lhs {}, rhs {}", + left.bit_size, + right.bit_size + ); + let bit_size = left.bit_size; + + let scratch_var_i = SingleAddrVariable::new(self.allocate_register(), bit_size); + let scratch_var_j = SingleAddrVariable::new(self.allocate_register(), bit_size); + + // i = left / right + self.binary(left, right, scratch_var_i, BrilligBinaryOp::UnsignedDiv); + + // j = i * right + self.binary(scratch_var_i, right, scratch_var_j, BrilligBinaryOp::Mul); + + // result_register = left - j + self.binary(left, scratch_var_j, result, BrilligBinaryOp::Sub); + // Free scratch registers + self.deallocate_single_addr(scratch_var_i); + self.deallocate_single_addr(scratch_var_j); + } + + fn binary_result_bit_size(operation: BrilligBinaryOp, arguments_bit_size: u32) -> u32 { + match operation { + BrilligBinaryOp::Equals + | BrilligBinaryOp::LessThan + | BrilligBinaryOp::LessThanEquals => 1, + _ => arguments_bit_size, + } + } + + /// Processes a foreign call instruction. + /// + /// Note: the function being called is external and will + /// not be linked during brillig generation. + pub(crate) fn foreign_call_instruction( + &mut self, + func_name: String, + inputs: &[ValueOrArray], + input_value_types: &[HeapValueType], + outputs: &[ValueOrArray], + output_value_types: &[HeapValueType], + ) { + self.debug_show.foreign_call_instruction(func_name.clone(), inputs, outputs); + + assert!(inputs.len() == input_value_types.len()); + assert!(outputs.len() == output_value_types.len()); + + self.push_opcode(BrilligOpcode::ForeignCall { + function: func_name, + destinations: outputs.to_vec(), + destination_value_types: output_value_types.to_vec(), + inputs: inputs.to_vec(), + input_value_types: input_value_types.to_vec(), + }); + } + + /// Adds a unresolved external `Call` instruction to the bytecode. + /// This calls into another function compiled into this brillig artifact. + pub(crate) fn add_external_call_instruction(&mut self, func_label: T) { + self.debug_show.add_external_call_instruction(func_label.to_string()); + self.obj.add_unresolved_external_call( + BrilligOpcode::Call { location: 0 }, + func_label.to_string(), + ); + } + + /// Adds a unresolved `Jump` instruction to the bytecode. + pub(crate) fn jump_instruction(&mut self, target_label: T) { + self.debug_show.jump_instruction(target_label.to_string()); + self.add_unresolved_jump(BrilligOpcode::Jump { location: 0 }, target_label.to_string()); + } + + /// Adds a unresolved `JumpIf` instruction to the bytecode. + pub(crate) fn jump_if_instruction( + &mut self, + condition: MemoryAddress, + target_label: T, + ) { + self.debug_show.jump_if_instruction(condition, target_label.to_string()); + self.add_unresolved_jump( + BrilligOpcode::JumpIf { condition, location: 0 }, + target_label.to_string(), + ); + } + + /// Emits brillig bytecode to jump to a trap condition if `condition` + /// is false. + pub(crate) fn constrain_instruction( + &mut self, + condition: SingleAddrVariable, + assert_message: Option, + ) { + self.debug_show.constrain_instruction(condition.address); + + assert!(condition.bit_size == 1); + + let (next_section, next_label) = self.reserve_next_section_label(); + self.add_unresolved_jump( + BrilligOpcode::JumpIf { condition: condition.address, location: 0 }, + next_label, + ); + self.push_opcode(BrilligOpcode::Trap); + if let Some(assert_message) = assert_message { + self.obj.add_assert_message_to_last_opcode(assert_message); + } + self.enter_section(next_section); + } + + /// Adds a unresolved `Jump` to the bytecode. + fn add_unresolved_jump( + &mut self, + jmp_instruction: BrilligOpcode, + destination: UnresolvedJumpLocation, + ) { + self.obj.add_unresolved_jump(jmp_instruction, destination); + } + + /// Adds a label to the next opcode + pub(crate) fn enter_context(&mut self, label: T) { + self.debug_show.enter_context(label.to_string()); + self.context_label = label.to_string(); + self.section_label = 0; + // Add a context label to the next opcode + self.obj.add_label_at_position(label.to_string(), self.obj.index_of_next_opcode()); + // Add a section label to the next opcode + self.obj + .add_label_at_position(self.current_section_label(), self.obj.index_of_next_opcode()); + } + + /// Enter the given section + pub(super) fn enter_section(&mut self, section: usize) { + self.section_label = section; + self.obj + .add_label_at_position(self.current_section_label(), self.obj.index_of_next_opcode()); + } + + /// Create, reserve, and return a new section label. + pub(super) fn reserve_next_section_label(&mut self) -> (usize, String) { + let section = self.next_section; + self.next_section += 1; + (section, self.compute_section_label(section)) + } + + /// Internal function used to compute the section labels + fn compute_section_label(&self, section: usize) -> String { + format!("{}-{}", self.context_label, section) + } + + /// Returns the current section label + fn current_section_label(&self) -> String { + self.compute_section_label(self.section_label) + } + + /// Emits a stop instruction + pub(crate) fn stop_instruction(&mut self) { + self.debug_show.stop_instruction(); + self.push_opcode(BrilligOpcode::Stop { return_data_offset: 0, return_data_size: 0 }); + } + + /// Emits a external stop instruction (returns data) + pub(crate) fn external_stop_instruction( + &mut self, + return_data_offset: usize, + return_data_size: usize, + ) { + self.debug_show.external_stop_instruction(return_data_offset, return_data_size); + self.push_opcode(BrilligOpcode::Stop { return_data_offset, return_data_size }); + } + + /// Issues a blackbox operation. + pub(crate) fn black_box_op_instruction(&mut self, op: BlackBoxOp) { + self.debug_show.black_box_op_instruction(&op); + self.push_opcode(BrilligOpcode::BlackBox(op)); + } + + pub(crate) fn load_free_memory_pointer_instruction(&mut self, pointer_register: MemoryAddress) { + self.debug_show.mov_instruction(pointer_register, ReservedRegisters::free_memory_pointer()); + self.push_opcode(BrilligOpcode::Mov { + destination: pointer_register, + source: ReservedRegisters::free_memory_pointer(), + }); + } + + pub(crate) fn increase_free_memory_pointer_instruction( + &mut self, + size_register: MemoryAddress, + ) { + self.memory_op_instruction( + ReservedRegisters::free_memory_pointer(), + size_register, + ReservedRegisters::free_memory_pointer(), + BrilligBinaryOp::Add, + ); + } + + /// Emits a store instruction + pub(crate) fn store_instruction( + &mut self, + destination_pointer: MemoryAddress, + source: MemoryAddress, + ) { + self.debug_show.store_instruction(destination_pointer, source); + self.push_opcode(BrilligOpcode::Store { destination_pointer, source }); + } + + /// Utility method to transform a HeapArray to a HeapVector by making a runtime constant with the size. + pub(crate) fn array_to_vector_instruction(&mut self, array: &BrilligArray) -> BrilligVector { + let size_register = self.make_usize_constant_instruction(array.size.into()); + BrilligVector { size: size_register.address, pointer: array.pointer, rc: array.rc } + } + + /// Emits a load instruction + pub(crate) fn load_instruction( + &mut self, + destination: MemoryAddress, + source_pointer: MemoryAddress, + ) { + self.debug_show.load_instruction(destination, source_pointer); + self.push_opcode(BrilligOpcode::Load { destination, source_pointer }); + } + + /// Emits a `mov` instruction. + /// + /// Copies the value at `source` into `destination` + pub(crate) fn mov_instruction(&mut self, destination: MemoryAddress, source: MemoryAddress) { + self.debug_show.mov_instruction(destination, source); + self.push_opcode(BrilligOpcode::Mov { destination, source }); + } + + /// Emits a conditional `mov` instruction. + /// + /// Copies the value at `source` into `destination` + pub(crate) fn conditional_mov_instruction( + &mut self, + destination: MemoryAddress, + condition: MemoryAddress, + source_a: MemoryAddress, + source_b: MemoryAddress, + ) { + self.debug_show.conditional_mov_instruction(destination, condition, source_a, source_b); + self.push_opcode(BrilligOpcode::ConditionalMov { + destination, + source_a, + source_b, + condition, + }); + } + + /// Cast truncates the value to the given bit size and converts the type of the value in memory to that bit size. + pub(crate) fn cast_instruction( + &mut self, + destination: SingleAddrVariable, + source: SingleAddrVariable, + ) { + self.debug_show.cast_instruction(destination.address, source.address, destination.bit_size); + self.cast(destination, source); + } + + pub(crate) fn cast(&mut self, destination: SingleAddrVariable, source: SingleAddrVariable) { + self.push_opcode(BrilligOpcode::Cast { + destination: destination.address, + source: source.address, + bit_size: destination.bit_size, + }); + } + + /// Stores the value of `constant` in the `result` register + pub(crate) fn const_instruction(&mut self, result: SingleAddrVariable, constant: FieldElement) { + self.debug_show.const_instruction(result.address, constant); + self.constant(result, constant); + } + + fn constant(&mut self, result: SingleAddrVariable, constant: FieldElement) { + assert!( + result.bit_size >= constant.num_bits(), + "Constant {} does not fit in bit size {}", + constant, + result.bit_size + ); + if result.bit_size > 128 && !constant.fits_in_u128() { + let high = FieldElement::from_be_bytes_reduce( + constant.to_be_bytes().get(0..16).expect("FieldElement::to_be_bytes() too short!"), + ); + let low = FieldElement::from(constant.to_u128()); + let high_register = SingleAddrVariable::new(self.allocate_register(), 254); + let low_register = SingleAddrVariable::new(self.allocate_register(), 254); + let intermediate_register = SingleAddrVariable::new(self.allocate_register(), 254); + self.constant(high_register, high); + self.constant(low_register, low); + // I want to multiply high by 2^128, but I can't get that big constant in. + // So I'll multiply by 2^64 twice. + self.constant(intermediate_register, FieldElement::from(1_u128 << 64)); + self.binary(high_register, intermediate_register, high_register, BrilligBinaryOp::Mul); + self.binary(high_register, intermediate_register, high_register, BrilligBinaryOp::Mul); + // Now we can add. + self.binary(high_register, low_register, intermediate_register, BrilligBinaryOp::Add); + self.cast(result, intermediate_register); + self.deallocate_single_addr(high_register); + self.deallocate_single_addr(low_register); + self.deallocate_single_addr(intermediate_register); + } else { + self.push_opcode(BrilligOpcode::Const { + destination: result.address, + value: constant, + bit_size: result.bit_size, + }); + } + } + + pub(crate) fn usize_const_instruction( + &mut self, + result: MemoryAddress, + constant: FieldElement, + ) { + self.const_instruction(SingleAddrVariable::new_usize(result), constant); + } + + /// Returns a register which holds the value of a constant + pub(crate) fn make_constant_instruction( + &mut self, + constant: FieldElement, + bit_size: u32, + ) -> SingleAddrVariable { + let var = SingleAddrVariable::new(self.allocate_register(), bit_size); + self.const_instruction(var, constant); + var + } + + fn make_constant(&mut self, constant: FieldElement, bit_size: u32) -> SingleAddrVariable { + let var = SingleAddrVariable::new(self.allocate_register(), bit_size); + self.constant(var, constant); + var + } + + /// Returns a register which holds the value of an usize constant + pub(crate) fn make_usize_constant_instruction( + &mut self, + constant: FieldElement, + ) -> SingleAddrVariable { + let register = self.allocate_register(); + self.usize_const_instruction(register, constant); + SingleAddrVariable::new_usize(register) + } + + pub(super) fn calldata_copy_instruction( + &mut self, + destination: MemoryAddress, + calldata_size: usize, + offset: usize, + ) { + self.debug_show.calldata_copy_instruction(destination, calldata_size, offset); + + self.push_opcode(BrilligOpcode::CalldataCopy { + destination_address: destination, + size: calldata_size, + offset, + }); + } +} + +/// Type to encapsulate the binary operation types in Brillig +#[derive(Clone, Copy, Debug)] +pub(crate) enum BrilligBinaryOp { + Add, + Sub, + Mul, + FieldDiv, + UnsignedDiv, + Equals, + LessThan, + LessThanEquals, + And, + Or, + Xor, + Shl, + Shr, + // Modulo operation requires more than one brillig opcode + Modulo, +} + +impl From for BinaryFieldOp { + fn from(operation: BrilligBinaryOp) -> BinaryFieldOp { + match operation { + BrilligBinaryOp::Add => BinaryFieldOp::Add, + BrilligBinaryOp::Sub => BinaryFieldOp::Sub, + BrilligBinaryOp::Mul => BinaryFieldOp::Mul, + BrilligBinaryOp::FieldDiv => BinaryFieldOp::Div, + BrilligBinaryOp::UnsignedDiv => BinaryFieldOp::IntegerDiv, + BrilligBinaryOp::Equals => BinaryFieldOp::Equals, + BrilligBinaryOp::LessThan => BinaryFieldOp::LessThan, + BrilligBinaryOp::LessThanEquals => BinaryFieldOp::LessThanEquals, + _ => panic!("Unsupported operation: {:?} on a field", operation), + } + } +} + +impl From for BinaryIntOp { + fn from(operation: BrilligBinaryOp) -> BinaryIntOp { + match operation { + BrilligBinaryOp::Add => BinaryIntOp::Add, + BrilligBinaryOp::Sub => BinaryIntOp::Sub, + BrilligBinaryOp::Mul => BinaryIntOp::Mul, + BrilligBinaryOp::UnsignedDiv => BinaryIntOp::Div, + BrilligBinaryOp::Equals => BinaryIntOp::Equals, + BrilligBinaryOp::LessThan => BinaryIntOp::LessThan, + BrilligBinaryOp::LessThanEquals => BinaryIntOp::LessThanEquals, + BrilligBinaryOp::And => BinaryIntOp::And, + BrilligBinaryOp::Or => BinaryIntOp::Or, + BrilligBinaryOp::Xor => BinaryIntOp::Xor, + BrilligBinaryOp::Shl => BinaryIntOp::Shl, + BrilligBinaryOp::Shr => BinaryIntOp::Shr, + _ => panic!("Unsupported operation: {:?} on an integer", operation), + } + } +} diff --git a/compiler/noirc_evaluator/src/brillig/brillig_ir/registers.rs b/compiler/noirc_evaluator/src/brillig/brillig_ir/registers.rs index 8c0e36215a9..f756f06aa69 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_ir/registers.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_ir/registers.rs @@ -2,7 +2,7 @@ use acvm::acir::brillig::MemoryAddress; use crate::brillig::brillig_ir::entry_point::MAX_STACK_SIZE; -use super::ReservedRegisters; +use super::{brillig_variable::SingleAddrVariable, BrilligContext, ReservedRegisters}; /// Every brillig stack frame/call context has its own view of register space. /// This is maintained by copying these registers to the stack during calls and reading them back. @@ -81,3 +81,29 @@ impl BrilligRegistersContext { self.deallocated_registers.push(register_index); } } + +impl BrilligContext { + /// Returns the i'th register after the reserved ones + pub(crate) fn register(&self, i: usize) -> MemoryAddress { + MemoryAddress::from(ReservedRegisters::NUM_RESERVED_REGISTERS + i) + } + + /// Allocates an unused register. + pub(crate) fn allocate_register(&mut self) -> MemoryAddress { + self.registers.allocate_register() + } + + pub(crate) fn set_allocated_registers(&mut self, allocated_registers: Vec) { + self.registers = BrilligRegistersContext::from_preallocated_registers(allocated_registers); + } + + /// Push a register to the deallocation list, ready for reuse. + pub(crate) fn deallocate_register(&mut self, register_index: MemoryAddress) { + self.registers.deallocate_register(register_index); + } + + /// Deallocates the address where the single address variable is stored + pub(crate) fn deallocate_single_addr(&mut self, var: SingleAddrVariable) { + self.deallocate_register(var.address); + } +} diff --git a/compiler/noirc_evaluator/src/errors.rs b/compiler/noirc_evaluator/src/errors.rs index 40f4336e0b5..b3e838e708e 100644 --- a/compiler/noirc_evaluator/src/errors.rs +++ b/compiler/noirc_evaluator/src/errors.rs @@ -48,6 +48,8 @@ pub enum RuntimeError { BigIntModulus { call_stack: CallStack }, #[error("Slices cannot be returned from an unconstrained runtime to a constrained runtime")] UnconstrainedSliceReturnToConstrained { call_stack: CallStack }, + #[error("All `oracle` methods should be wrapped in an unconstrained fn")] + UnconstrainedOracleReturnToConstrained { call_stack: CallStack }, } // We avoid showing the actual lhs and rhs since most of the time they are just 0 @@ -138,7 +140,8 @@ impl RuntimeError { | RuntimeError::UnsupportedIntegerSize { call_stack, .. } | RuntimeError::NestedSlice { call_stack, .. } | RuntimeError::BigIntModulus { call_stack, .. } - | RuntimeError::UnconstrainedSliceReturnToConstrained { call_stack } => call_stack, + | RuntimeError::UnconstrainedSliceReturnToConstrained { call_stack } + | RuntimeError::UnconstrainedOracleReturnToConstrained { call_stack } => call_stack, } } } diff --git a/compiler/noirc_evaluator/src/lib.rs b/compiler/noirc_evaluator/src/lib.rs index 70751d3e541..54376963338 100644 --- a/compiler/noirc_evaluator/src/lib.rs +++ b/compiler/noirc_evaluator/src/lib.rs @@ -11,4 +11,4 @@ pub mod ssa; pub mod brillig; -pub use ssa::create_circuit; +pub use ssa::create_program; diff --git a/compiler/noirc_evaluator/src/ssa.rs b/compiler/noirc_evaluator/src/ssa.rs index 0bb81efe977..fac7a7c0829 100644 --- a/compiler/noirc_evaluator/src/ssa.rs +++ b/compiler/noirc_evaluator/src/ssa.rs @@ -14,11 +14,11 @@ use crate::{ errors::{RuntimeError, SsaReport}, }; use acvm::acir::{ - circuit::{Circuit, ExpressionWidth, PublicInputs}, + circuit::{Circuit, ExpressionWidth, Program as AcirProgram, PublicInputs}, native_types::Witness, }; -use noirc_errors::debug_info::DebugInfo; +use noirc_errors::debug_info::{DebugFunctions, DebugInfo, DebugTypes, DebugVariables}; use noirc_frontend::{ hir_def::function::FunctionSignature, monomorphization::ast::Program, Visibility, @@ -38,19 +38,22 @@ pub mod ssa_gen; /// convert the final SSA into ACIR and return it. pub(crate) fn optimize_into_acir( program: Program, - print_ssa_passes: bool, + print_passes: bool, print_brillig_trace: bool, force_brillig_output: bool, -) -> Result { + print_timings: bool, +) -> Result, RuntimeError> { let abi_distinctness = program.return_distinctness; let ssa_gen_span = span!(Level::TRACE, "ssa_generation"); let ssa_gen_span_guard = ssa_gen_span.enter(); - let ssa = SsaBuilder::new(program, print_ssa_passes, force_brillig_output)? + let ssa = SsaBuilder::new(program, print_passes, force_brillig_output, print_timings)? .run_pass(Ssa::defunctionalize, "After Defunctionalization:") + .run_pass(Ssa::remove_paired_rc, "After Removing Paired rc_inc & rc_decs:") .run_pass(Ssa::inline_functions, "After Inlining:") // Run mem2reg with the CFG separated into blocks .run_pass(Ssa::mem2reg, "After Mem2Reg:") + .run_pass(Ssa::as_slice_optimization, "After `as_slice` optimization") .try_run_pass(Ssa::evaluate_assert_constant, "After Assert Constant:")? .try_run_pass(Ssa::unroll_loops, "After Unrolling:")? .run_pass(Ssa::simplify_cfg, "After Simplifying:") @@ -59,43 +62,124 @@ pub(crate) fn optimize_into_acir( // Run mem2reg once more with the flattened CFG to catch any remaining loads/stores .run_pass(Ssa::mem2reg, "After Mem2Reg:") .run_pass(Ssa::fold_constants, "After Constant Folding:") - .run_pass( - Ssa::fold_constants_using_constraints, - "After Constant Folding With Constraint Info:", - ) + .run_pass(Ssa::remove_enable_side_effects, "After EnableSideEffects removal:") + .run_pass(Ssa::fold_constants_using_constraints, "After Constraint Folding:") .run_pass(Ssa::dead_instruction_elimination, "After Dead Instruction Elimination:") + .run_pass(Ssa::array_set_optimization, "After Array Set Optimizations:") .finish(); - let brillig = ssa.to_brillig(print_brillig_trace); + let brillig = time("SSA to Brillig", print_timings, || ssa.to_brillig(print_brillig_trace)); drop(ssa_gen_span_guard); - let last_array_uses = ssa.find_last_array_uses(); + time("SSA to ACIR", print_timings, || ssa.into_acir(&brillig, abi_distinctness)) +} + +// Helper to time SSA passes +fn time(name: &str, print_timings: bool, f: impl FnOnce() -> T) -> T { + let start_time = chrono::Utc::now().time(); + let result = f(); + + if print_timings { + let end_time = chrono::Utc::now().time(); + println!("{name}: {} ms", (end_time - start_time).num_milliseconds()); + } + + result +} + +#[derive(Default)] +pub struct SsaProgramArtifact { + pub program: AcirProgram, + pub debug: Vec, + pub warnings: Vec, + pub main_input_witnesses: Vec, + pub main_return_witnesses: Vec, + pub names: Vec, +} - ssa.into_acir(brillig, abi_distinctness, &last_array_uses) +impl SsaProgramArtifact { + fn add_circuit(&mut self, mut circuit_artifact: SsaCircuitArtifact, is_main: bool) { + self.program.functions.push(circuit_artifact.circuit); + self.debug.push(circuit_artifact.debug_info); + self.warnings.append(&mut circuit_artifact.warnings); + if is_main { + self.main_input_witnesses = circuit_artifact.input_witnesses; + self.main_return_witnesses = circuit_artifact.return_witnesses; + } + self.names.push(circuit_artifact.name); + } } -/// Compiles the [`Program`] into [`ACIR`][acvm::acir::circuit::Circuit]. +/// Compiles the [`Program`] into [`ACIR``][acvm::acir::circuit::Program]. /// /// The output ACIR is is backend-agnostic and so must go through a transformation pass before usage in proof generation. #[allow(clippy::type_complexity)] #[tracing::instrument(level = "trace", skip_all)] -pub fn create_circuit( +pub fn create_program( program: Program, enable_ssa_logging: bool, enable_brillig_logging: bool, force_brillig_output: bool, -) -> Result<(Circuit, DebugInfo, Vec, Vec, Vec), RuntimeError> { + print_codegen_timings: bool, +) -> Result { let debug_variables = program.debug_variables.clone(); let debug_types = program.debug_types.clone(); - let func_sig = program.main_function_signature.clone(); + let debug_functions = program.debug_functions.clone(); + + let func_sigs = program.function_signatures.clone(); + let recursive = program.recursive; - let mut generated_acir = optimize_into_acir( + let generated_acirs = optimize_into_acir( program, enable_ssa_logging, enable_brillig_logging, force_brillig_output, + print_codegen_timings, )?; + assert_eq!( + generated_acirs.len(), + func_sigs.len(), + "The generated ACIRs should match the supplied function signatures" + ); + + let mut program_artifact = SsaProgramArtifact::default(); + // For setting up the ABI we need separately specify main's input and return witnesses + let mut is_main = true; + for (acir, func_sig) in generated_acirs.into_iter().zip(func_sigs) { + let circuit_artifact = convert_generated_acir_into_circuit( + acir, + func_sig, + recursive, + // TODO: get rid of these clones + debug_variables.clone(), + debug_functions.clone(), + debug_types.clone(), + ); + program_artifact.add_circuit(circuit_artifact, is_main); + is_main = false; + } + + Ok(program_artifact) +} + +pub struct SsaCircuitArtifact { + name: String, + circuit: Circuit, + debug_info: DebugInfo, + warnings: Vec, + input_witnesses: Vec, + return_witnesses: Vec, +} + +fn convert_generated_acir_into_circuit( + mut generated_acir: GeneratedAcir, + func_sig: FunctionSignature, + recursive: bool, + debug_variables: DebugVariables, + debug_functions: DebugFunctions, + debug_types: DebugTypes, +) -> SsaCircuitArtifact { let opcodes = generated_acir.take_opcodes(); let current_witness_index = generated_acir.current_witness_index().0; let GeneratedAcir { @@ -104,6 +188,7 @@ pub fn create_circuit( input_witnesses, assert_messages, warnings, + name, .. } = generated_acir; @@ -130,13 +215,20 @@ pub fn create_circuit( .map(|(index, locations)| (index, locations.into_iter().collect())) .collect(); - let mut debug_info = DebugInfo::new(locations, debug_variables, debug_types); + let mut debug_info = DebugInfo::new(locations, debug_variables, debug_functions, debug_types); // Perform any ACIR-level optimizations let (optimized_circuit, transformation_map) = acvm::compiler::optimize(circuit); debug_info.update_acir(transformation_map); - Ok((optimized_circuit, debug_info, input_witnesses, return_witnesses, warnings)) + SsaCircuitArtifact { + name, + circuit: optimized_circuit, + debug_info, + warnings, + input_witnesses, + return_witnesses, + } } // Takes each function argument and partitions the circuit's inputs witnesses according to its visibility. @@ -177,6 +269,7 @@ fn split_public_and_private_inputs( struct SsaBuilder { ssa: Ssa, print_ssa_passes: bool, + print_codegen_timings: bool, } impl SsaBuilder { @@ -184,9 +277,10 @@ impl SsaBuilder { program: Program, print_ssa_passes: bool, force_brillig_runtime: bool, + print_codegen_timings: bool, ) -> Result { let ssa = ssa_gen::generate_ssa(program, force_brillig_runtime)?; - Ok(SsaBuilder { print_ssa_passes, ssa }.print("Initial SSA:")) + Ok(SsaBuilder { print_ssa_passes, print_codegen_timings, ssa }.print("Initial SSA:")) } fn finish(self) -> Ssa { @@ -195,7 +289,7 @@ impl SsaBuilder { /// Runs the given SSA pass and prints the SSA afterward if `print_ssa_passes` is true. fn run_pass(mut self, pass: fn(Ssa) -> Ssa, msg: &str) -> Self { - self.ssa = pass(self.ssa); + self.ssa = time(msg, self.print_codegen_timings, || pass(self.ssa)); self.print(msg) } @@ -205,7 +299,7 @@ impl SsaBuilder { pass: fn(Ssa) -> Result, msg: &str, ) -> Result { - self.ssa = pass(self.ssa)?; + self.ssa = time(msg, self.print_codegen_timings, || pass(self.ssa))?; Ok(self.print(msg)) } diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index fb11bae556c..bcd62e3b062 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -11,7 +11,7 @@ use acvm::acir::circuit::brillig::{BrilligInputs, BrilligOutputs}; use acvm::acir::circuit::opcodes::{BlockId, MemOp}; use acvm::acir::circuit::Opcode; use acvm::blackbox_solver; -use acvm::brillig_vm::{brillig::Value, VMStatus, VM}; +use acvm::brillig_vm::{MemoryValue, VMStatus, VM}; use acvm::{ acir::{ brillig::Opcode as BrilligOpcode, @@ -1623,7 +1623,7 @@ impl AcirContext { let outputs_var = vecmap(outputs_types.iter(), |output| match output { AcirType::NumericType(_) => { let var = self.add_data(AcirVarData::Const( - memory.next().expect("Missing return data").to_field(), + memory.next().expect("Missing return data").value, )); AcirValue::Var(var, output.clone()) } @@ -1640,7 +1640,7 @@ impl AcirContext { &mut self, element_types: &[AcirType], size: usize, - memory_iter: &mut impl Iterator, + memory_iter: &mut impl Iterator, ) -> AcirValue { let mut array_values = im::Vector::new(); for _ in 0..size { @@ -1657,7 +1657,7 @@ impl AcirContext { AcirType::NumericType(_) => { let memory_value = memory_iter.next().expect("ICE: Unexpected end of memory"); - let var = self.add_data(AcirVarData::Const(memory_value.to_field())); + let var = self.add_data(AcirVarData::Const(memory_value.value)); array_values.push_back(AcirValue::Var(var, element_type.clone())); } } @@ -1757,6 +1757,30 @@ impl AcirContext { } Ok(()) } + + pub(crate) fn call_acir_function( + &mut self, + id: u32, + inputs: Vec, + output_count: usize, + ) -> Result, RuntimeError> { + let inputs = self.prepare_inputs_for_black_box_func_call(inputs)?; + let inputs = inputs + .iter() + .flat_map(|input| vecmap(input, |input| input.witness)) + .collect::>(); + let outputs = vecmap(0..output_count, |_| self.acir_ir.next_witness_index()); + + // Convert `Witness` values which are now constrained to be the output of the + // ACIR function call into `AcirVar`s. + // Similar to black box functions, we do not apply range information on the output of the function. + // See issue https://github.com/noir-lang/noir/issues/1439 + let results = + vecmap(&outputs, |witness_index| self.add_data(AcirVarData::Witness(*witness_index))); + + self.acir_ir.push_opcode(Opcode::Call { id, inputs, outputs }); + Ok(results) + } } /// Enum representing the possible values that a @@ -1839,21 +1863,21 @@ pub(crate) struct AcirVar(usize); /// Returns the finished state of the Brillig VM if execution can complete. /// /// Returns `None` if complete execution of the Brillig bytecode is not possible. -fn execute_brillig(code: &[BrilligOpcode], inputs: &[BrilligInputs]) -> Option> { +fn execute_brillig(code: &[BrilligOpcode], inputs: &[BrilligInputs]) -> Option> { // Set input values - let mut calldata: Vec = Vec::new(); + let mut calldata: Vec = Vec::new(); // Each input represents a constant or array of constants. // Iterate over each input and push it into registers and/or memory. for input in inputs { match input { BrilligInputs::Single(expr) => { - calldata.push(expr.to_const()?.into()); + calldata.push(expr.to_const()?); } BrilligInputs::Array(expr_arr) => { // Attempt to fetch all array input values for expr in expr_arr.iter() { - calldata.push(expr.to_const()?.into()); + calldata.push(expr.to_const()?); } } BrilligInputs::MemoryArray(_) => { diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs index 1d05e998b13..b43110b2f5b 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs @@ -25,7 +25,7 @@ use iter_extended::vecmap; use num_bigint::BigUint; #[derive(Debug, Default)] -/// The output of the Acir-gen pass +/// The output of the Acir-gen pass, which should only be produced for entry point Acir functions pub(crate) struct GeneratedAcir { /// The next witness index that may be declared. /// If witness index is `None` then we have not yet created a witness @@ -58,6 +58,10 @@ pub(crate) struct GeneratedAcir { pub(crate) assert_messages: BTreeMap, pub(crate) warnings: Vec, + + /// Name for the corresponding entry point represented by this Acir-gen output. + /// Only used for debugging and benchmarking purposes + pub(crate) name: String, } impl GeneratedAcir { diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs index 8d4d0668534..9e597dc8e9a 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs @@ -21,10 +21,11 @@ use super::{ }, ssa_gen::Ssa, }; -use crate::brillig::brillig_ir::artifact::GeneratedBrillig; +use crate::brillig::brillig_ir::artifact::{BrilligParameter, GeneratedBrillig}; use crate::brillig::brillig_ir::BrilligContext; use crate::brillig::{brillig_gen::brillig_fn::FunctionContext as BrilligFunctionContext, Brillig}; use crate::errors::{InternalError, InternalWarning, RuntimeError, SsaReport}; +use crate::ssa::ir::function::InlineType; pub(crate) use acir_ir::generated_acir::GeneratedAcir; use acvm::acir::native_types::Witness; @@ -178,31 +179,45 @@ impl Ssa { #[tracing::instrument(level = "trace", skip_all)] pub(crate) fn into_acir( self, - brillig: Brillig, + brillig: &Brillig, abi_distinctness: Distinctness, - last_array_uses: &HashMap, - ) -> Result { - let context = Context::new(); - let mut generated_acir = context.convert_ssa(self, brillig, last_array_uses)?; + ) -> Result, RuntimeError> { + let mut acirs = Vec::new(); + // TODO: can we parallelise this? + for function in self.functions.values() { + let context = Context::new(); + if let Some(mut generated_acir) = + context.convert_ssa_function(&self, function, brillig)? + { + generated_acir.name = function.name().to_owned(); + acirs.push(generated_acir); + } + } + // TODO: check whether doing this for a single circuit's return witnesses is correct. + // We probably need it for all foldable circuits, as any circuit being folded is essentially an entry point. However, I do not know how that + // plays a part when we potentially want not inlined functions normally as part of the compiler. + // Also at the moment we specify Distinctness as part of the ABI exclusively rather than the function itself + // so this will need to be updated. + let main_func_acir = &mut acirs[0]; match abi_distinctness { Distinctness::Distinct => { // Create a witness for each return witness we have // to guarantee that the return witnesses are distinct - let distinct_return_witness: Vec<_> = generated_acir + let distinct_return_witness: Vec<_> = main_func_acir .return_witnesses .clone() .into_iter() .map(|return_witness| { - generated_acir + main_func_acir .create_witness_for_expression(&Expression::from(return_witness)) }) .collect(); - generated_acir.return_witnesses = distinct_return_witness; - Ok(generated_acir) + main_func_acir.return_witnesses = distinct_return_witness; + Ok(acirs) } - Distinctness::DuplicationAllowed => Ok(generated_acir), + Distinctness::DuplicationAllowed => Ok(acirs), } } } @@ -225,17 +240,32 @@ impl Context { } } - /// Converts SSA into ACIR - fn convert_ssa( + fn convert_ssa_function( self, - ssa: Ssa, - brillig: Brillig, - last_array_uses: &HashMap, - ) -> Result { - let main_func = ssa.main(); - match main_func.runtime() { - RuntimeType::Acir => self.convert_acir_main(main_func, &ssa, brillig, last_array_uses), - RuntimeType::Brillig => self.convert_brillig_main(main_func, brillig), + ssa: &Ssa, + function: &Function, + brillig: &Brillig, + ) -> Result, RuntimeError> { + match function.runtime() { + RuntimeType::Acir(inline_type) => { + match inline_type { + InlineType::Fold => {} + InlineType::Inline => { + if function.id() != ssa.main_id { + panic!("ACIR function should have been inlined earlier if not marked otherwise"); + } + } + } + // We only want to convert entry point functions. This being `main` and those marked with `InlineType::Fold` + Ok(Some(self.convert_acir_main(function, ssa, brillig)?)) + } + RuntimeType::Brillig => { + if function.id() == ssa.main_id { + Ok(Some(self.convert_brillig_main(function, brillig)?)) + } else { + Ok(None) + } + } } } @@ -243,8 +273,7 @@ impl Context { mut self, main_func: &Function, ssa: &Ssa, - brillig: Brillig, - last_array_uses: &HashMap, + brillig: &Brillig, ) -> Result { let dfg = &main_func.dfg; let entry_block = &dfg[main_func.entry_block()]; @@ -253,13 +282,7 @@ impl Context { self.data_bus = dfg.data_bus.to_owned(); let mut warnings = Vec::new(); for instruction_id in entry_block.instructions() { - warnings.extend(self.convert_ssa_instruction( - *instruction_id, - dfg, - ssa, - &brillig, - last_array_uses, - )?); + warnings.extend(self.convert_ssa_instruction(*instruction_id, dfg, ssa, brillig)?); } warnings.extend(self.convert_ssa_return(entry_block.unwrap_terminator(), dfg)?); @@ -269,7 +292,7 @@ impl Context { fn convert_brillig_main( mut self, main_func: &Function, - brillig: Brillig, + brillig: &Brillig, ) -> Result { let dfg = &main_func.dfg; @@ -277,12 +300,14 @@ impl Context { let typ = dfg.type_of_value(*param_id); self.create_value_from_type(&typ, &mut |this, _| Ok(this.acir_context.add_variable())) })?; + let arguments = self.gen_brillig_parameters(dfg[main_func.entry_block()].parameters(), dfg); + let witness_inputs = self.acir_context.extract_witness(&inputs); let outputs: Vec = vecmap(main_func.returns(), |result_id| dfg.type_of_value(*result_id).into()); - let code = self.gen_brillig_for(main_func, &brillig)?; + let code = self.gen_brillig_for(main_func, arguments, brillig)?; // We specifically do not attempt execution of the brillig code being generated as this can result in it being // replaced with constraints on witnesses to the program outputs. @@ -432,7 +457,6 @@ impl Context { dfg: &DataFlowGraph, ssa: &Ssa, brillig: &Brillig, - last_array_uses: &HashMap, ) -> Result, RuntimeError> { let instruction = &dfg[instruction_id]; self.acir_context.set_call_stack(dfg.get_call_stack(instruction_id)); @@ -492,7 +516,7 @@ impl Context { self.current_side_effects_enabled_var = acir_var; } Instruction::ArrayGet { .. } | Instruction::ArraySet { .. } => { - self.handle_array_operation(instruction_id, dfg, last_array_uses)?; + self.handle_array_operation(instruction_id, dfg)?; } Instruction::Allocate => { unreachable!("Expected all allocate instructions to be removed before acir_gen") @@ -503,7 +527,7 @@ impl Context { Instruction::Load { .. } => { unreachable!("Expected all load instructions to be removed before acir_gen") } - Instruction::IncrementRc { .. } => { + Instruction::IncrementRc { .. } | Instruction::DecrementRc { .. } => { // Do nothing. Only Brillig needs to worry about reference counted arrays } Instruction::RangeCheck { value, max_bit_size, assert_message } => { @@ -537,38 +561,65 @@ impl Context { Value::Function(id) => { let func = &ssa.functions[id]; match func.runtime() { - RuntimeType::Acir => unimplemented!( - "expected an intrinsic/brillig call, but found {func:?}. All ACIR methods should be inlined" - ), + RuntimeType::Acir(inline_type) => { + assert!(!matches!(inline_type, InlineType::Inline), "ICE: Got an ACIR function named {} that should have already been inlined", func.name()); + + let inputs = vecmap(arguments, |arg| self.convert_value(*arg, dfg)); + // TODO(https://github.com/noir-lang/noir/issues/4608): handle complex return types from ACIR functions + let output_count = + result_ids.iter().fold(0usize, |sum, result_id| { + sum + dfg.try_get_array_length(*result_id).unwrap_or(1) + }); + + let acir_program_id = ssa + .id_to_index + .get(id) + .expect("ICE: should have an associated final index"); + let output_vars = self.acir_context.call_acir_function( + *acir_program_id, + inputs, + output_count, + )?; + let output_values = + self.convert_vars_to_values(output_vars, dfg, result_ids); + + self.handle_ssa_call_outputs(result_ids, output_values, dfg)?; + } RuntimeType::Brillig => { - // Check that we are not attempting to return a slice from + // Check that we are not attempting to return a slice from // an unconstrained runtime to a constrained runtime for result_id in result_ids { if dfg.type_of_value(*result_id).contains_slice_element() { - return Err(RuntimeError::UnconstrainedSliceReturnToConstrained { call_stack: self.acir_context.get_call_stack() }) + return Err( + RuntimeError::UnconstrainedSliceReturnToConstrained { + call_stack: self.acir_context.get_call_stack(), + }, + ); } } let inputs = vecmap(arguments, |arg| self.convert_value(*arg, dfg)); + let arguments = self.gen_brillig_parameters(arguments, dfg); - let code = self.gen_brillig_for(func, brillig)?; + let code = self.gen_brillig_for(func, arguments, brillig)?; - let outputs: Vec = vecmap(result_ids, |result_id| dfg.type_of_value(*result_id).into()); + let outputs: Vec = vecmap(result_ids, |result_id| { + dfg.type_of_value(*result_id).into() + }); - let output_values = self.acir_context.brillig(self.current_side_effects_enabled_var, code, inputs, outputs, true, false)?; + let output_values = self.acir_context.brillig( + self.current_side_effects_enabled_var, + code, + inputs, + outputs, + true, + false, + )?; // Compiler sanity check assert_eq!(result_ids.len(), output_values.len(), "ICE: The number of Brillig output values should match the result ids in SSA"); - for result in result_ids.iter().zip(output_values) { - if let AcirValue::Array(_) = &result.1 { - let array_id = dfg.resolve(*result.0); - let block_id = self.block_id(&array_id); - let array_typ = dfg.type_of_value(array_id); - self.initialize_array(block_id, array_typ.flattened_size(), Some(result.1.clone()))?; - } - self.ssa_values.insert(*result.0, result.1); - } + self.handle_ssa_call_outputs(result_ids, output_values, dfg)?; } } } @@ -587,34 +638,13 @@ impl Context { // Issue #1438 causes this check to fail with intrinsics that return 0 // results but the ssa form instead creates 1 unit result value. // assert_eq!(result_ids.len(), outputs.len()); - - for (result, output) in result_ids.iter().zip(outputs) { - match &output { - // We need to make sure we initialize arrays returned from intrinsic calls - // or else they will fail if accessed with a dynamic index - AcirValue::Array(_) => { - let block_id = self.block_id(result); - let array_typ = dfg.type_of_value(*result); - let len = if matches!(array_typ, Type::Array(_, _)) { - array_typ.flattened_size() - } else { - Self::flattened_value_size(&output) - }; - self.initialize_array(block_id, len, Some(output.clone()))?; - } - AcirValue::DynamicArray(_) => { - // Do nothing as a dynamic array returned from a slice intrinsic should already be initialized - } - AcirValue::Var(_, _) => { - // Do nothing - } - } - self.ssa_values.insert(*result, output); - } + self.handle_ssa_call_outputs(result_ids, outputs, dfg)?; + } + Value::ForeignFunction(_) => { + return Err(RuntimeError::UnconstrainedOracleReturnToConstrained { + call_stack: self.acir_context.get_call_stack(), + }) } - Value::ForeignFunction(_) => unreachable!( - "All `oracle` methods should be wrapped in an unconstrained fn" - ), _ => unreachable!("expected calling a function but got {function_value:?}"), } } @@ -623,14 +653,75 @@ impl Context { Ok(warnings) } + fn handle_ssa_call_outputs( + &mut self, + result_ids: &[ValueId], + output_values: Vec, + dfg: &DataFlowGraph, + ) -> Result<(), RuntimeError> { + for (result_id, output) in result_ids.iter().zip(output_values) { + if let AcirValue::Array(_) = &output { + let array_id = dfg.resolve(*result_id); + let block_id = self.block_id(&array_id); + let array_typ = dfg.type_of_value(array_id); + let len = if matches!(array_typ, Type::Array(_, _)) { + array_typ.flattened_size() + } else { + Self::flattened_value_size(&output) + }; + self.initialize_array(block_id, len, Some(output.clone()))?; + } + // Do nothing for AcirValue::DynamicArray and AcirValue::Var + // A dynamic array returned from a function call should already be initialized + // and a single variable does not require any extra initialization. + self.ssa_values.insert(*result_id, output); + } + Ok(()) + } + + fn gen_brillig_parameters( + &self, + values: &[ValueId], + dfg: &DataFlowGraph, + ) -> Vec { + values + .iter() + .map(|&value_id| { + let typ = dfg.type_of_value(value_id); + if let Type::Slice(item_types) = typ { + let len = match self + .ssa_values + .get(&value_id) + .expect("ICE: Unknown slice input to brillig") + { + AcirValue::DynamicArray(AcirDynamicArray { len, .. }) => *len, + AcirValue::Array(array) => array.len(), + _ => unreachable!("ICE: Slice value is not an array"), + }; + + BrilligParameter::Slice( + item_types + .iter() + .map(BrilligFunctionContext::ssa_type_to_parameter) + .collect(), + len / item_types.len(), + ) + } else { + BrilligFunctionContext::ssa_type_to_parameter(&typ) + } + }) + .collect() + } + fn gen_brillig_for( &self, func: &Function, + arguments: Vec, brillig: &Brillig, ) -> Result { // Create the entry point artifact let mut entry_point = BrilligContext::new_entry_point_artifact( - BrilligFunctionContext::parameters(func), + arguments, BrilligFunctionContext::return_values(func), BrilligFunctionContext::function_id_to_function_label(func.id()), ); @@ -659,12 +750,16 @@ impl Context { &mut self, instruction: InstructionId, dfg: &DataFlowGraph, - last_array_uses: &HashMap, ) -> Result<(), RuntimeError> { + let mut mutable_array_set = false; + // Pass the instruction between array methods rather than the internal fields themselves let (array, index, store_value) = match dfg[instruction] { Instruction::ArrayGet { array, index } => (array, index, None), - Instruction::ArraySet { array, index, value, .. } => (array, index, Some(value)), + Instruction::ArraySet { array, index, value, mutable } => { + mutable_array_set = mutable; + (array, index, Some(value)) + } _ => { return Err(InternalError::Unexpected { expected: "Instruction should be an ArrayGet or ArraySet".to_owned(), @@ -682,11 +777,8 @@ impl Context { let (new_index, new_value) = self.convert_array_operation_inputs(array, dfg, index, store_value)?; - let resolved_array = dfg.resolve(array); - let map_array = last_array_uses.get(&resolved_array) == Some(&instruction); - if let Some(new_value) = new_value { - self.array_set(instruction, new_index, new_value, dfg, map_array)?; + self.array_set(instruction, new_index, new_value, dfg, mutable_array_set)?; } else { self.array_get(instruction, array, new_index, dfg)?; } @@ -966,16 +1058,18 @@ impl Context { } } - /// Copy the array and generates a write opcode on the new array - /// - /// Note: Copying the array is inefficient and is not the way we want to do it in the end. + /// If `mutate_array` is: + /// - true: Mutate the array directly + /// - false: Copy the array and generates a write opcode on the new array. This is + /// generally very inefficient and should be avoided if possible. Currently + /// this is controlled by SSA's array set optimization pass. fn array_set( &mut self, instruction: InstructionId, mut var_index: AcirVar, store_value: AcirValue, dfg: &DataFlowGraph, - map_array: bool, + mutate_array: bool, ) -> Result<(), RuntimeError> { // Pass the instruction between array methods rather than the internal fields themselves let array = match dfg[instruction] { @@ -1013,7 +1107,7 @@ impl Context { .first() .expect("Array set does not have one result"); let result_block_id; - if map_array { + if mutate_array { self.memory_blocks.insert(*result_id, block_id); result_block_id = block_id; } else { @@ -1025,7 +1119,13 @@ impl Context { self.array_set_value(&store_value, result_block_id, &mut var_index)?; let element_type_sizes = if !can_omit_element_sizes_array(&array_typ) { - Some(self.init_element_type_sizes_array(&array_typ, array_id, None, dfg)?) + let acir_value = self.convert_value(array_id, dfg); + Some(self.init_element_type_sizes_array( + &array_typ, + array_id, + Some(&acir_value), + dfg, + )?) } else { None }; @@ -1246,7 +1346,8 @@ impl Context { let read = self.acir_context.read_from_memory(source, &index_var)?; Ok::(AcirValue::Var(read, AcirType::field())) })?; - self.initialize_array(destination, array_len, Some(AcirValue::Array(init_values.into())))?; + let array: im::Vector = init_values.into(); + self.initialize_array(destination, array_len, Some(AcirValue::Array(array)))?; Ok(()) } @@ -1364,6 +1465,7 @@ impl Context { TerminatorInstruction::Return { return_values, call_stack } => { (return_values, call_stack) } + // TODO(https://github.com/noir-lang/noir/issues/4616): Enable recursion on foldable/non-inlined ACIR functions _ => unreachable!("ICE: Program must have a singular return"), }; @@ -1663,6 +1765,49 @@ impl Context { }; Ok(vec![AcirValue::Var(self.acir_context.add_constant(len), AcirType::field())]) } + Intrinsic::AsSlice => { + let (slice_contents, slice_typ, block_id) = + self.check_array_is_initialized(arguments[0], dfg)?; + assert!(!slice_typ.is_nested_slice(), "ICE: Nested slice used in ACIR generation"); + + let result_block_id = self.block_id(&result_ids[1]); + let acir_value = self.convert_value(slice_contents, dfg); + + let array_len = if !slice_typ.contains_slice_element() { + slice_typ.flattened_size() + } else { + self.flattened_slice_size(slice_contents, dfg) + }; + let slice_length = self.acir_context.add_constant(array_len); + self.copy_dynamic_array(block_id, result_block_id, array_len)?; + + let element_type_sizes = if !can_omit_element_sizes_array(&slice_typ) { + Some(self.init_element_type_sizes_array( + &slice_typ, + slice_contents, + Some(&acir_value), + dfg, + )?) + } else { + None + }; + + let value_types = self.convert_value(slice_contents, dfg).flat_numeric_types(); + assert!( + array_len == value_types.len(), + "AsSlice: unexpected length difference: {:?} != {:?}", + array_len, + value_types.len() + ); + + let result = AcirValue::DynamicArray(AcirDynamicArray { + block_id: result_block_id, + len: value_types.len(), + value_types, + element_type_sizes, + }); + Ok(vec![AcirValue::Var(slice_length, AcirType::field()), result]) + } Intrinsic::SlicePushBack => { // arguments = [slice_length, slice_contents, ...elements_to_push] let slice_length = self.convert_value(arguments[0], dfg).into_var()?; @@ -2268,12 +2413,329 @@ impl Context { // We can omit the element size array for arrays which don't contain arrays or slices. fn can_omit_element_sizes_array(array_typ: &Type) -> bool { - if array_typ.contains_slice_element() { - return false; - } - let Type::Array(types, _) = array_typ else { - panic!("ICE: expected array type"); + let types = match array_typ { + Type::Array(types, _) | Type::Slice(types) => types, + _ => panic!("ICE: expected array or slice type"), }; !types.iter().any(|typ| typ.contains_an_array()) } + +#[cfg(test)] +mod test { + use acvm::{ + acir::{circuit::Opcode, native_types::Witness}, + FieldElement, + }; + + use crate::{ + brillig::Brillig, + ssa::{ + function_builder::FunctionBuilder, + ir::{ + function::{FunctionId, InlineType}, + instruction::BinaryOp, + map::Id, + types::Type, + }, + }, + }; + + fn build_basic_foo_with_return(builder: &mut FunctionBuilder, foo_id: FunctionId) { + // acir(fold) fn foo f1 { + // b0(v0: Field, v1: Field): + // v2 = eq v0, v1 + // constrain v2 == u1 0 + // return v0 + // } + builder.new_function("foo".into(), foo_id, InlineType::Fold); + let foo_v0 = builder.add_parameter(Type::field()); + let foo_v1 = builder.add_parameter(Type::field()); + + let foo_equality_check = builder.insert_binary(foo_v0, BinaryOp::Eq, foo_v1); + let zero = builder.field_constant(0u128); + builder.insert_constrain(foo_equality_check, zero, None); + builder.terminate_with_return(vec![foo_v0]); + } + + #[test] + fn basic_call_with_outputs_assert() { + // acir(inline) fn main f0 { + // b0(v0: Field, v1: Field): + // v2 = call f1(v0, v1) + // v3 = call f1(v0, v1) + // constrain v2 == v3 + // return + // } + // acir(fold) fn foo f1 { + // b0(v0: Field, v1: Field): + // v2 = eq v0, v1 + // constrain v2 == u1 0 + // return v0 + // } + let foo_id = Id::test_new(0); + let mut builder = FunctionBuilder::new("main".into(), foo_id); + let main_v0 = builder.add_parameter(Type::field()); + let main_v1 = builder.add_parameter(Type::field()); + + let foo_id = Id::test_new(1); + let foo = builder.import_function(foo_id); + let main_call1_results = + builder.insert_call(foo, vec![main_v0, main_v1], vec![Type::field()]).to_vec(); + let main_call2_results = + builder.insert_call(foo, vec![main_v0, main_v1], vec![Type::field()]).to_vec(); + builder.insert_constrain(main_call1_results[0], main_call2_results[0], None); + builder.terminate_with_return(vec![]); + + build_basic_foo_with_return(&mut builder, foo_id); + + let ssa = builder.finish(); + + let acir_functions = ssa + .into_acir(&Brillig::default(), noirc_frontend::Distinctness::Distinct) + .expect("Should compile manually written SSA into ACIR"); + // Expected result: + // main f0 + // GeneratedAcir { + // ... + // opcodes: [ + // CALL func 1: inputs: [Witness(0), Witness(1)], outputs: [Witness(2)], + // CALL func 1: inputs: [Witness(0), Witness(1)], outputs: [Witness(3)], + // EXPR [ (1, _2) (-1, _3) 0 ], + // ], + // return_witnesses: [], + // input_witnesses: [ + // Witness( + // 0, + // ), + // Witness( + // 1, + // ), + // ], + // ... + // } + // foo f1 + // GeneratedAcir { + // ... + // opcodes: [ + // Same as opcodes as the expected result of `basic_call_codegen` + // ], + // return_witnesses: [ + // Witness( + // 0, + // ), + // ], + // input_witnesses: [ + // Witness( + // 0, + // ), + // Witness( + // 1, + // ), + // ], + // ... + // }, + + let main_acir = &acir_functions[0]; + let main_opcodes = main_acir.opcodes(); + assert_eq!(main_opcodes.len(), 3, "Should have two calls to `foo`"); + + check_call_opcode(&main_opcodes[0], 1, vec![Witness(0), Witness(1)], vec![Witness(2)]); + check_call_opcode(&main_opcodes[1], 1, vec![Witness(0), Witness(1)], vec![Witness(3)]); + + if let Opcode::AssertZero(expr) = &main_opcodes[2] { + assert_eq!(expr.linear_combinations[0].0, FieldElement::from(1u128)); + assert_eq!(expr.linear_combinations[0].1, Witness(2)); + + assert_eq!(expr.linear_combinations[1].0, FieldElement::from(-1i128)); + assert_eq!(expr.linear_combinations[1].1, Witness(3)); + assert_eq!(expr.q_c, FieldElement::from(0u128)); + } + } + + #[test] + fn call_output_as_next_call_input() { + // acir(inline) fn main f0 { + // b0(v0: Field, v1: Field): + // v3 = call f1(v0, v1) + // v4 = call f1(v3, v1) + // constrain v3 == v4 + // return + // } + // acir(fold) fn foo f1 { + // b0(v0: Field, v1: Field): + // v2 = eq v0, v1 + // constrain v2 == u1 0 + // return v0 + // } + let foo_id = Id::test_new(0); + let mut builder = FunctionBuilder::new("main".into(), foo_id); + let main_v0 = builder.add_parameter(Type::field()); + let main_v1 = builder.add_parameter(Type::field()); + + let foo_id = Id::test_new(1); + let foo = builder.import_function(foo_id); + let main_call1_results = + builder.insert_call(foo, vec![main_v0, main_v1], vec![Type::field()]).to_vec(); + let main_call2_results = builder + .insert_call(foo, vec![main_call1_results[0], main_v1], vec![Type::field()]) + .to_vec(); + builder.insert_constrain(main_call1_results[0], main_call2_results[0], None); + builder.terminate_with_return(vec![]); + + build_basic_foo_with_return(&mut builder, foo_id); + + let ssa = builder.finish(); + + let acir_functions = ssa + .into_acir(&Brillig::default(), noirc_frontend::Distinctness::Distinct) + .expect("Should compile manually written SSA into ACIR"); + // The expected result should look very similar to the abvoe test expect that the input witnesses of the `Call` + // opcodes will be different. The changes can discerned from the checks below. + + let main_acir = &acir_functions[0]; + let main_opcodes = main_acir.opcodes(); + assert_eq!(main_opcodes.len(), 3, "Should have two calls to `foo` and an assert"); + + check_call_opcode(&main_opcodes[0], 1, vec![Witness(0), Witness(1)], vec![Witness(2)]); + // The output of the first call should be the input of the second call + check_call_opcode(&main_opcodes[1], 1, vec![Witness(2), Witness(1)], vec![Witness(3)]); + } + + #[test] + fn basic_nested_call() { + // SSA for the following Noir program: + // fn main(x: Field, y: pub Field) { + // let z = func_with_nested_foo_call(x, y); + // let z2 = func_with_nested_foo_call(x, y); + // assert(z == z2); + // } + // #[fold] + // fn func_with_nested_foo_call(x: Field, y: Field) -> Field { + // nested_call(x + 2, y) + // } + // #[fold] + // fn foo(x: Field, y: Field) -> Field { + // assert(x != y); + // x + // } + // + // SSA: + // acir(inline) fn main f0 { + // b0(v0: Field, v1: Field): + // v3 = call f1(v0, v1) + // v4 = call f1(v0, v1) + // constrain v3 == v4 + // return + // } + // acir(fold) fn func_with_nested_foo_call f1 { + // b0(v0: Field, v1: Field): + // v3 = add v0, Field 2 + // v5 = call f2(v3, v1) + // return v5 + // } + // acir(fold) fn foo f2 { + // b0(v0: Field, v1: Field): + // v2 = eq v0, v1 + // constrain v2 == Field 0 + // return v0 + // } + let foo_id = Id::test_new(0); + let mut builder = FunctionBuilder::new("main".into(), foo_id); + let main_v0 = builder.add_parameter(Type::field()); + let main_v1 = builder.add_parameter(Type::field()); + + let func_with_nested_foo_call_id = Id::test_new(1); + let func_with_nested_foo_call = builder.import_function(func_with_nested_foo_call_id); + let main_call1_results = builder + .insert_call(func_with_nested_foo_call, vec![main_v0, main_v1], vec![Type::field()]) + .to_vec(); + let main_call2_results = builder + .insert_call(func_with_nested_foo_call, vec![main_v0, main_v1], vec![Type::field()]) + .to_vec(); + builder.insert_constrain(main_call1_results[0], main_call2_results[0], None); + builder.terminate_with_return(vec![]); + + builder.new_function( + "func_with_nested_foo_call".into(), + func_with_nested_foo_call_id, + InlineType::Fold, + ); + let func_with_nested_call_v0 = builder.add_parameter(Type::field()); + let func_with_nested_call_v1 = builder.add_parameter(Type::field()); + + let two = builder.field_constant(2u128); + let v0_plus_two = builder.insert_binary(func_with_nested_call_v0, BinaryOp::Add, two); + + let foo_id = Id::test_new(2); + let foo_call = builder.import_function(foo_id); + let foo_call = builder + .insert_call(foo_call, vec![v0_plus_two, func_with_nested_call_v1], vec![Type::field()]) + .to_vec(); + builder.terminate_with_return(vec![foo_call[0]]); + + build_basic_foo_with_return(&mut builder, foo_id); + + let ssa = builder.finish(); + + let acir_functions = ssa + .into_acir(&Brillig::default(), noirc_frontend::Distinctness::Distinct) + .expect("Should compile manually written SSA into ACIR"); + + assert_eq!(acir_functions.len(), 3, "Should have three ACIR functions"); + + let main_acir = &acir_functions[0]; + let main_opcodes = main_acir.opcodes(); + assert_eq!(main_opcodes.len(), 3, "Should have two calls to `foo` and an assert"); + + // Both of these should call func_with_nested_foo_call f1 + check_call_opcode(&main_opcodes[0], 1, vec![Witness(0), Witness(1)], vec![Witness(2)]); + // The output of the first call should be the input of the second call + check_call_opcode(&main_opcodes[1], 1, vec![Witness(0), Witness(1)], vec![Witness(3)]); + + let func_with_nested_call_acir = &acir_functions[1]; + let func_with_nested_call_opcodes = func_with_nested_call_acir.opcodes(); + assert_eq!( + func_with_nested_call_opcodes.len(), + 2, + "Should have an expression and a call to a nested `foo`" + ); + // Should call foo f2 + check_call_opcode( + &func_with_nested_call_opcodes[1], + 2, + vec![Witness(2), Witness(1)], + vec![Witness(3)], + ); + } + + fn check_call_opcode( + opcode: &Opcode, + expected_id: u32, + expected_inputs: Vec, + expected_outputs: Vec, + ) { + match opcode { + Opcode::Call { id, inputs, outputs } => { + assert_eq!( + *id, expected_id, + "Main was expected to call {expected_id} but got {}", + *id + ); + for (expected_input, input) in expected_inputs.iter().zip(inputs) { + assert_eq!( + expected_input, input, + "Expected witness {expected_input:?} but got {input:?}" + ); + } + for (expected_output, output) in expected_outputs.iter().zip(outputs) { + assert_eq!( + expected_output, output, + "Expected witness {expected_output:?} but got {output:?}" + ); + } + } + _ => panic!("Expected only Call opcode"), + } + } +} diff --git a/compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs b/compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs index cbaeb2477d6..e785212f8d2 100644 --- a/compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs +++ b/compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs @@ -92,7 +92,7 @@ impl FunctionBuilder { let index = self .current_function .dfg - .make_constant(FieldElement::from(i as i128), Type::field()); + .make_constant(FieldElement::from(i as i128), Type::length_type()); let element = self.insert_array_get(value, index, typ[0].clone()); self.add_to_data_bus(element, databus); } diff --git a/compiler/noirc_evaluator/src/ssa/function_builder/mod.rs b/compiler/noirc_evaluator/src/ssa/function_builder/mod.rs index 9d27554dcaa..d3e5e506111 100644 --- a/compiler/noirc_evaluator/src/ssa/function_builder/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/function_builder/mod.rs @@ -17,7 +17,7 @@ use super::{ ir::{ basic_block::BasicBlock, dfg::{CallStack, InsertInstructionResult}, - function::RuntimeType, + function::{InlineType, RuntimeType}, instruction::{ConstrainError, InstructionId, Intrinsic}, }, ssa_gen::Ssa, @@ -42,23 +42,26 @@ impl FunctionBuilder { /// /// This creates the new function internally so there is no need to call .new_function() /// right after constructing a new FunctionBuilder. - pub(crate) fn new( - function_name: String, - function_id: FunctionId, - runtime: RuntimeType, - ) -> Self { - let mut new_function = Function::new(function_name, function_id); - new_function.set_runtime(runtime); - let current_block = new_function.entry_block(); + pub(crate) fn new(function_name: String, function_id: FunctionId) -> Self { + let new_function = Function::new(function_name, function_id); Self { + current_block: new_function.entry_block(), current_function: new_function, - current_block, finished_functions: Vec::new(), call_stack: CallStack::new(), } } + /// Set the runtime of the initial function that is created internally after constructing + /// the FunctionBuilder. A function's default runtime type is `RuntimeType::Acir(InlineType::Inline)`. + /// This should only be used immediately following construction of a FunctionBuilder + /// and will panic if there are any already finished functions. + pub(crate) fn set_runtime(&mut self, runtime: RuntimeType) { + assert_eq!(self.finished_functions.len(), 0, "Attempted to set runtime on a FunctionBuilder with finished functions. A FunctionBuilder's runtime should only be set on its initial function"); + self.current_function.set_runtime(runtime); + } + /// Finish the current function and create a new function. /// /// A FunctionBuilder can always only work on one function at a time, so care @@ -79,8 +82,13 @@ impl FunctionBuilder { } /// Finish the current function and create a new ACIR function. - pub(crate) fn new_function(&mut self, name: String, function_id: FunctionId) { - self.new_function_with_type(name, function_id, RuntimeType::Acir); + pub(crate) fn new_function( + &mut self, + name: String, + function_id: FunctionId, + inline_type: InlineType, + ) { + self.new_function_with_type(name, function_id, RuntimeType::Acir(inline_type)); } /// Finish the current function and create a new unconstrained function. @@ -153,9 +161,10 @@ impl FunctionBuilder { instruction: Instruction, ctrl_typevars: Option>, ) -> InsertInstructionResult { + let block = self.current_block(); self.current_function.dfg.insert_instruction_and_results( instruction, - self.current_block, + block, ctrl_typevars, self.call_stack.clone(), ) @@ -195,12 +204,9 @@ impl FunctionBuilder { self.call_stack.clone() } - /// Insert a Load instruction at the end of the current block, loading from the given offset - /// of the given address which should point to a previous Allocate instruction. Note that - /// this is limited to loading a single value. Loading multiple values (such as a tuple) - /// will require multiple loads. - /// 'offset' is in units of FieldElements here. So loading the fourth FieldElement stored in - /// an array will have an offset of 3. + /// Insert a Load instruction at the end of the current block, loading from the given address + /// which should point to a previous Allocate instruction. Note that this is limited to loading + /// a single value. Loading multiple values (such as a tuple) will require multiple loads. /// Returns the element that was loaded. pub(crate) fn insert_load(&mut self, address: ValueId, type_to_load: Type) -> ValueId { self.insert_instruction(Instruction::Load { address }, Some(vec![type_to_load])).first() @@ -221,11 +227,9 @@ impl FunctionBuilder { operator: BinaryOp, rhs: ValueId, ) -> ValueId { - assert_eq!( - self.type_of_value(lhs), - self.type_of_value(rhs), - "ICE - Binary instruction operands must have the same type" - ); + let lhs_type = self.type_of_value(lhs); + let rhs_type = self.type_of_value(rhs); + assert_eq!(lhs_type, rhs_type, "ICE - Binary instruction operands must have the same type"); let instruction = Instruction::Binary(Binary { lhs, rhs, operator }); self.insert_instruction(instruction, None).first() } @@ -306,12 +310,28 @@ impl FunctionBuilder { index: ValueId, value: ValueId, ) -> ValueId { - self.insert_instruction(Instruction::ArraySet { array, index, value }, None).first() + self.insert_instruction(Instruction::ArraySet { array, index, value, mutable: false }, None) + .first() + } + + /// Insert an instruction to increment an array's reference count. This only has an effect + /// in unconstrained code where arrays are reference counted and copy on write. + pub(crate) fn insert_inc_rc(&mut self, value: ValueId) { + self.insert_instruction(Instruction::IncrementRc { value }, None); + } + + /// Insert an instruction to decrement an array's reference count. This only has an effect + /// in unconstrained code where arrays are reference counted and copy on write. + pub(crate) fn insert_dec_rc(&mut self, value: ValueId) { + self.insert_instruction(Instruction::DecrementRc { value }, None); } /// Terminates the current block with the given terminator instruction + /// if the current block does not already have a terminator instruction. fn terminate_block_with(&mut self, terminator: TerminatorInstruction) { - self.current_function.dfg.set_block_terminator(self.current_block, terminator); + if self.current_function.dfg[self.current_block].terminator().is_none() { + self.current_function.dfg.set_block_terminator(self.current_block, terminator); + } } /// Terminate the current block with a jmp instruction to jmp to the given @@ -384,19 +404,67 @@ impl FunctionBuilder { /// within the given value. If the given value is not an array and does not contain /// any arrays, this does nothing. pub(crate) fn increment_array_reference_count(&mut self, value: ValueId) { + self.update_array_reference_count(value, true, None); + } + + /// Insert instructions to decrement the reference count of any array(s) stored + /// within the given value. If the given value is not an array and does not contain + /// any arrays, this does nothing. + pub(crate) fn decrement_array_reference_count(&mut self, value: ValueId) { + self.update_array_reference_count(value, false, None); + } + + /// Increment or decrement the given value's reference count if it is an array. + /// If it is not an array, this does nothing. Note that inc_rc and dec_rc instructions + /// are ignored outside of unconstrained code. + fn update_array_reference_count( + &mut self, + value: ValueId, + increment: bool, + load_address: Option, + ) { match self.type_of_value(value) { Type::Numeric(_) => (), Type::Function => (), Type::Reference(element) => { if element.contains_an_array() { - let value = self.insert_load(value, element.as_ref().clone()); - self.increment_array_reference_count(value); + let reference = value; + let value = self.insert_load(reference, element.as_ref().clone()); + self.update_array_reference_count(value, increment, Some(reference)); } } - Type::Array(..) | Type::Slice(..) => { - self.insert_instruction(Instruction::IncrementRc { value }, None); + typ @ Type::Array(..) | typ @ Type::Slice(..) => { // If there are nested arrays or slices, we wait until ArrayGet // is issued to increment the count of that array. + let update_rc = |this: &mut Self, value| { + if increment { + this.insert_inc_rc(value); + } else { + this.insert_dec_rc(value); + } + }; + + update_rc(self, value); + let dfg = &self.current_function.dfg; + + // This is a bit odd, but in brillig the inc_rc instruction operates on + // a copy of the array's metadata, so we need to re-store a loaded array + // even if there have been no other changes to it. + if let Some(address) = load_address { + // If we already have a load from the Type::Reference case, avoid inserting + // another load and rc update. + self.insert_store(address, value); + } else if let Value::Instruction { instruction, .. } = &dfg[value] { + let instruction = &dfg[*instruction]; + if let Instruction::Load { address } = instruction { + // We can't re-use `value` in case the original address was stored + // to again in the meantime. So introduce another load. + let address = *address; + let new_load = self.insert_load(address, typ); + update_rc(self, new_load); + self.insert_store(address, new_load); + } + } } } } @@ -433,7 +501,6 @@ mod tests { use acvm::FieldElement; use crate::ssa::ir::{ - function::RuntimeType, instruction::{Endian, Intrinsic}, map::Id, types::Type, @@ -448,7 +515,7 @@ mod tests { // let x = 7; // let bits = x.to_le_bits(8); let func_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("func".into(), func_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("func".into(), func_id); let one = builder.numeric_constant(FieldElement::one(), Type::bool()); let zero = builder.numeric_constant(FieldElement::zero(), Type::bool()); diff --git a/compiler/noirc_evaluator/src/ssa/ir/cfg.rs b/compiler/noirc_evaluator/src/ssa/ir/cfg.rs index ebfbf003ec4..5a3f07cd673 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/cfg.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/cfg.rs @@ -95,10 +95,6 @@ impl ControlFlowGraph { ); predecessor_node.successors.insert(to); let successor_node = self.data.entry(to).or_default(); - assert!( - successor_node.predecessors.len() < 2, - "ICE: A cfg node cannot have more than two predecessors" - ); successor_node.predecessors.insert(from); } diff --git a/compiler/noirc_evaluator/src/ssa/ir/dfg.rs b/compiler/noirc_evaluator/src/ssa/ir/dfg.rs index 870b5e602f1..6b950c327cf 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/dfg.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/dfg.rs @@ -378,6 +378,30 @@ impl DataFlowGraph { value_id } + /// Replaces an instruction result with a fresh id. + pub(crate) fn replace_result( + &mut self, + instruction_id: InstructionId, + prev_value_id: ValueId, + ) -> ValueId { + let typ = self.type_of_value(prev_value_id); + let results = self.results.get_mut(&instruction_id).unwrap(); + let res_position = results + .iter() + .position(|&id| id == prev_value_id) + .expect("Result id not found while replacing"); + + let value_id = self.values.insert(Value::Instruction { + typ, + position: res_position, + instruction: instruction_id, + }); + + // Replace the value in list of results for this instruction + results[res_position] = value_id; + value_id + } + /// Returns the number of instructions /// inserted into functions. pub(crate) fn num_instructions(&self) -> usize { diff --git a/compiler/noirc_evaluator/src/ssa/ir/dom.rs b/compiler/noirc_evaluator/src/ssa/ir/dom.rs index c1df0428c64..15fa3bad38d 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/dom.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/dom.rs @@ -249,13 +249,8 @@ mod tests { use crate::ssa::{ function_builder::FunctionBuilder, ir::{ - basic_block::BasicBlockId, - dfg::CallStack, - dom::DominatorTree, - function::{Function, RuntimeType}, - instruction::TerminatorInstruction, - map::Id, - types::Type, + basic_block::BasicBlockId, dfg::CallStack, dom::DominatorTree, function::Function, + instruction::TerminatorInstruction, map::Id, types::Type, }, }; @@ -286,7 +281,7 @@ mod tests { // return () // } let func_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("func".into(), func_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("func".into(), func_id); let cond = builder.add_parameter(Type::unsigned(1)); let block1_id = builder.insert_block(); @@ -395,7 +390,7 @@ mod tests { // jump block1() // } let func_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("func".into(), func_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("func".into(), func_id); let block1_id = builder.insert_block(); let block2_id = builder.insert_block(); diff --git a/compiler/noirc_evaluator/src/ssa/ir/function.rs b/compiler/noirc_evaluator/src/ssa/ir/function.rs index 360f5710113..011bee36661 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/function.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/function.rs @@ -12,11 +12,39 @@ use super::value::ValueId; #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] pub(crate) enum RuntimeType { // A noir function, to be compiled in ACIR and executed by ACVM - Acir, + Acir(InlineType), // Unconstrained function, to be compiled to brillig and executed by the Brillig VM Brillig, } +/// Represents how a RuntimeType::Acir function should be inlined. +/// This type is only relevant for ACIR functions as we do not inline any Brillig functions +#[derive(Default, Clone, Copy, PartialEq, Eq, Debug, Hash)] +pub(crate) enum InlineType { + /// The most basic entry point can expect all its functions to be inlined. + /// All function calls are expected to be inlined into a single ACIR. + #[default] + Inline, + /// Functions marked as foldable will not be inlined and compiled separately into ACIR + Fold, +} + +impl RuntimeType { + /// Returns whether the runtime type represents an entry point. + /// We return `false` for InlineType::Inline on default, which is true + /// in all cases except for main. `main` should be supported with special + /// handling in any places where this function determines logic. + pub(crate) fn is_entry_point(&self) -> bool { + match self { + RuntimeType::Acir(inline_type) => match inline_type { + InlineType::Inline => false, + InlineType::Fold => true, + }, + RuntimeType::Brillig => true, + } + } +} + /// A function holds a list of instructions. /// These instructions are further grouped into Basic blocks /// @@ -47,7 +75,7 @@ impl Function { pub(crate) fn new(name: String, id: FunctionId) -> Self { let mut dfg = DataFlowGraph::default(); let entry_block = dfg.make_block(); - Self { name, id, entry_block, dfg, runtime: RuntimeType::Acir } + Self { name, id, entry_block, dfg, runtime: RuntimeType::Acir(InlineType::default()) } } /// The name of the function. @@ -129,12 +157,21 @@ impl Function { impl std::fmt::Display for RuntimeType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - RuntimeType::Acir => write!(f, "acir"), + RuntimeType::Acir(inline_type) => write!(f, "acir({inline_type})"), RuntimeType::Brillig => write!(f, "brillig"), } } } +impl std::fmt::Display for InlineType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + InlineType::Inline => write!(f, "inline"), + InlineType::Fold => write!(f, "fold"), + } + } +} + /// FunctionId is a reference for a function /// /// This Id is how each function refers to other functions diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs index 0b6c7074e45..2b23cc1c1e8 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs @@ -37,6 +37,7 @@ pub(crate) type InstructionId = Id; #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub(crate) enum Intrinsic { ArrayLen, + AsSlice, AssertConstant, SlicePushBack, SlicePushFront, @@ -57,6 +58,7 @@ impl std::fmt::Display for Intrinsic { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Intrinsic::ArrayLen => write!(f, "array_len"), + Intrinsic::AsSlice => write!(f, "as_slice"), Intrinsic::AssertConstant => write!(f, "assert_constant"), Intrinsic::SlicePushBack => write!(f, "slice_push_back"), Intrinsic::SlicePushFront => write!(f, "slice_push_front"), @@ -89,6 +91,7 @@ impl Intrinsic { Intrinsic::ToBits(_) | Intrinsic::ToRadix(_) => true, Intrinsic::ArrayLen + | Intrinsic::AsSlice | Intrinsic::SlicePushBack | Intrinsic::SlicePushFront | Intrinsic::SlicePopBack @@ -109,6 +112,7 @@ impl Intrinsic { pub(crate) fn lookup(name: &str) -> Option { match name { "array_len" => Some(Intrinsic::ArrayLen), + "as_slice" => Some(Intrinsic::AsSlice), "assert_constant" => Some(Intrinsic::AssertConstant), "apply_range_constraint" => Some(Intrinsic::ApplyRangeConstraint), "slice_push_back" => Some(Intrinsic::SlicePushBack), @@ -185,8 +189,9 @@ pub(crate) enum Instruction { ArrayGet { array: ValueId, index: ValueId }, /// Creates a new array with the new value at the given index. All other elements are identical - /// to those in the given array. This will not modify the original array. - ArraySet { array: ValueId, index: ValueId, value: ValueId }, + /// to those in the given array. This will not modify the original array unless `mutable` is + /// set. This flag is off by default and only enabled when optimizations determine it is safe. + ArraySet { array: ValueId, index: ValueId, value: ValueId, mutable: bool }, /// An instruction to increment the reference count of a value. /// @@ -194,6 +199,13 @@ pub(crate) enum Instruction { /// implemented via reference counting. In ACIR code this is done with im::Vector and these /// IncrementRc instructions are ignored. IncrementRc { value: ValueId }, + + /// An instruction to decrement the reference count of a value. + /// + /// This currently only has an effect in Brillig code where array sharing and copy on write is + /// implemented via reference counting. In ACIR code this is done with im::Vector and these + /// DecrementRc instructions are ignored. + DecrementRc { value: ValueId }, } impl Instruction { @@ -214,6 +226,7 @@ impl Instruction { Instruction::Constrain(..) | Instruction::Store { .. } | Instruction::IncrementRc { .. } + | Instruction::DecrementRc { .. } | Instruction::RangeCheck { .. } | Instruction::EnableSideEffects { .. } => InstructionResultType::None, Instruction::Allocate { .. } @@ -250,6 +263,7 @@ impl Instruction { | Load { .. } | Store { .. } | IncrementRc { .. } + | DecrementRc { .. } | RangeCheck { .. } => false, Call { func, .. } => match dfg[*func] { @@ -285,6 +299,7 @@ impl Instruction { | Store { .. } | EnableSideEffects { .. } | IncrementRc { .. } + | DecrementRc { .. } | RangeCheck { .. } => true, // Some `Intrinsic`s have side effects so we must check what kind of `Call` this is. @@ -349,10 +364,14 @@ impl Instruction { Instruction::ArrayGet { array, index } => { Instruction::ArrayGet { array: f(*array), index: f(*index) } } - Instruction::ArraySet { array, index, value } => { - Instruction::ArraySet { array: f(*array), index: f(*index), value: f(*value) } - } + Instruction::ArraySet { array, index, value, mutable } => Instruction::ArraySet { + array: f(*array), + index: f(*index), + value: f(*value), + mutable: *mutable, + }, Instruction::IncrementRc { value } => Instruction::IncrementRc { value: f(*value) }, + Instruction::DecrementRc { value } => Instruction::DecrementRc { value: f(*value) }, Instruction::RangeCheck { value, max_bit_size, assert_message } => { Instruction::RangeCheck { value: f(*value), @@ -401,7 +420,7 @@ impl Instruction { f(*array); f(*index); } - Instruction::ArraySet { array, index, value } => { + Instruction::ArraySet { array, index, value, mutable: _ } => { f(*array); f(*index); f(*value); @@ -409,7 +428,9 @@ impl Instruction { Instruction::EnableSideEffects { condition } => { f(*condition); } - Instruction::IncrementRc { value } | Instruction::RangeCheck { value, .. } => { + Instruction::IncrementRc { value } + | Instruction::DecrementRc { value } + | Instruction::RangeCheck { value, .. } => { f(*value); } } @@ -554,13 +575,14 @@ impl Instruction { Instruction::Load { .. } => None, Instruction::Store { .. } => None, Instruction::IncrementRc { .. } => None, + Instruction::DecrementRc { .. } => None, Instruction::RangeCheck { value, max_bit_size, .. } => { - if let Some(numeric_constant) = dfg.get_numeric_constant(*value) { - if numeric_constant.num_bits() < *max_bit_size { - return Remove; - } + let max_potential_bits = dfg.get_value_max_num_bits(*value); + if max_potential_bits < *max_bit_size { + Remove + } else { + None } - None } } } diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs index 36f3ae8620b..9099268ace9 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs @@ -130,6 +130,12 @@ impl Binary { let zero = dfg.make_constant(FieldElement::zero(), operand_type); return SimplifyResult::SimplifiedTo(zero); } + if dfg.resolve(self.lhs) == dfg.resolve(self.rhs) + && dfg.get_value_max_num_bits(self.lhs) == 1 + { + // Squaring a boolean value is a noop. + return SimplifyResult::SimplifiedTo(self.lhs); + } } BinaryOp::Div => { if rhs_is_one { @@ -164,6 +170,7 @@ impl Binary { let one = dfg.make_constant(FieldElement::one(), Type::bool()); return SimplifyResult::SimplifiedTo(one); } + if operand_type == Type::bool() { // Simplify forms of `(boolean == true)` into `boolean` if lhs_is_one { diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs index 9349d58c4d9..1187ea8cb07 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs @@ -84,6 +84,17 @@ pub(super) fn simplify_call( SimplifyResult::None } } + Intrinsic::AsSlice => { + let array = dfg.get_array_constant(arguments[0]); + if let Some((array, array_type)) = array { + let slice_length = dfg.make_constant(array.len().into(), Type::length_type()); + let inner_element_types = array_type.element_types(); + let new_slice = dfg.make_array(array, Type::Slice(inner_element_types)); + SimplifyResult::SimplifiedToMultiple(vec![slice_length, new_slice]) + } else { + SimplifyResult::None + } + } Intrinsic::SlicePushBack => { let slice = dfg.get_array_constant(arguments[1]); if let Some((mut slice, element_type)) = slice { @@ -229,11 +240,16 @@ pub(super) fn simplify_call( let max_bit_size = dfg.get_numeric_constant(arguments[1]); if let Some(max_bit_size) = max_bit_size { let max_bit_size = max_bit_size.to_u128() as u32; - SimplifyResult::SimplifiedToInstruction(Instruction::RangeCheck { - value, - max_bit_size, - assert_message: Some("call to assert_max_bit_size".to_owned()), - }) + let max_potential_bits = dfg.get_value_max_num_bits(value); + if max_potential_bits < max_bit_size { + SimplifyResult::Remove + } else { + SimplifyResult::SimplifiedToInstruction(Instruction::RangeCheck { + value, + max_bit_size, + assert_message: Some("call to assert_max_bit_size".to_owned()), + }) + } } else { SimplifyResult::None } @@ -323,8 +339,13 @@ fn simplify_slice_push_back( let element_size = element_type.element_size(); let new_slice = dfg.make_array(slice, element_type); - let set_last_slice_value_instr = - Instruction::ArraySet { array: new_slice, index: arguments[0], value: arguments[2] }; + let set_last_slice_value_instr = Instruction::ArraySet { + array: new_slice, + index: arguments[0], + value: arguments[2], + mutable: false, + }; + let set_last_slice_value = dfg .insert_instruction_and_results(set_last_slice_value_instr, block, None, call_stack) .first(); diff --git a/compiler/noirc_evaluator/src/ssa/ir/post_order.rs b/compiler/noirc_evaluator/src/ssa/ir/post_order.rs index 3cae86829ed..d95ec451779 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/post_order.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/post_order.rs @@ -73,12 +73,7 @@ impl PostOrder { mod tests { use crate::ssa::{ function_builder::FunctionBuilder, - ir::{ - function::{Function, RuntimeType}, - map::Id, - post_order::PostOrder, - types::Type, - }, + ir::{function::Function, map::Id, post_order::PostOrder, types::Type}, }; #[test] @@ -112,7 +107,7 @@ mod tests { // D, F, E, B, A, (C dropped as unreachable) let func_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("func".into(), func_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("func".into(), func_id); let block_b_id = builder.insert_block(); let block_c_id = builder.insert_block(); let block_d_id = builder.insert_block(); diff --git a/compiler/noirc_evaluator/src/ssa/ir/printer.rs b/compiler/noirc_evaluator/src/ssa/ir/printer.rs index 9bd43fab1ff..fc13ab7307a 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/printer.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/printer.rs @@ -176,18 +176,19 @@ fn display_instruction_inner( Instruction::ArrayGet { array, index } => { writeln!(f, "array_get {}, index {}", show(*array), show(*index)) } - Instruction::ArraySet { array, index, value } => { - writeln!( - f, - "array_set {}, index {}, value {}", - show(*array), - show(*index), - show(*value) - ) + Instruction::ArraySet { array, index, value, mutable } => { + let array = show(*array); + let index = show(*index); + let value = show(*value); + let mutable = if *mutable { " mut" } else { "" }; + writeln!(f, "array_set{mutable} {array}, index {index}, value {value}",) } Instruction::IncrementRc { value } => { writeln!(f, "inc_rc {}", show(*value)) } + Instruction::DecrementRc { value } => { + writeln!(f, "dec_rc {}", show(*value)) + } Instruction::RangeCheck { value, max_bit_size, .. } => { writeln!(f, "range_check {} to {} bits", show(*value), *max_bit_size,) } diff --git a/compiler/noirc_evaluator/src/ssa/ir/types.rs b/compiler/noirc_evaluator/src/ssa/ir/types.rs index ea3f5393245..48036580d29 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/types.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/types.rs @@ -159,6 +159,13 @@ impl Type { Type::Reference(element) => element.contains_an_array(), } } + + pub(crate) fn element_types(self) -> Rc> { + match self { + Type::Array(element_types, _) | Type::Slice(element_types) => element_types, + other => panic!("element_types: Expected array or slice, found {other}"), + } + } } /// Composite Types are essentially flattened struct or tuple types. diff --git a/compiler/noirc_evaluator/src/ssa/opt/array_set.rs b/compiler/noirc_evaluator/src/ssa/opt/array_set.rs new file mode 100644 index 00000000000..cf61d7fd73f --- /dev/null +++ b/compiler/noirc_evaluator/src/ssa/opt/array_set.rs @@ -0,0 +1,104 @@ +use crate::ssa::{ + ir::{ + basic_block::BasicBlockId, + dfg::DataFlowGraph, + instruction::{Instruction, InstructionId}, + types::Type::{Array, Slice}, + }, + ssa_gen::Ssa, +}; +use fxhash::{FxHashMap as HashMap, FxHashSet}; + +impl Ssa { + /// Map arrays with the last instruction that uses it + /// For this we simply process all the instructions in execution order + /// and update the map whenever there is a match + #[tracing::instrument(level = "trace", skip(self))] + pub(crate) fn array_set_optimization(mut self) -> Self { + for func in self.functions.values_mut() { + if !func.runtime().is_entry_point() { + let mut reachable_blocks = func.reachable_blocks(); + assert_eq!(reachable_blocks.len(), 1, "Expected there to be 1 block remaining in Acir function for array_set optimization"); + + let block = reachable_blocks.pop_first().unwrap(); + let instructions_to_update = analyze_last_uses(&func.dfg, block); + make_mutable(&mut func.dfg, block, instructions_to_update); + } + } + self + } +} + +/// Returns the set of ArraySet instructions that can be made mutable +/// because their input value is unused elsewhere afterward. +fn analyze_last_uses(dfg: &DataFlowGraph, block_id: BasicBlockId) -> FxHashSet { + let block = &dfg[block_id]; + let mut array_to_last_use = HashMap::default(); + let mut instructions_that_can_be_made_mutable = FxHashSet::default(); + + for instruction_id in block.instructions() { + match &dfg[*instruction_id] { + Instruction::ArrayGet { array, .. } => { + let array = dfg.resolve(*array); + + if let Some(existing) = array_to_last_use.insert(array, *instruction_id) { + instructions_that_can_be_made_mutable.remove(&existing); + } + } + Instruction::ArraySet { array, .. } => { + let array = dfg.resolve(*array); + + if let Some(existing) = array_to_last_use.insert(array, *instruction_id) { + instructions_that_can_be_made_mutable.remove(&existing); + } + instructions_that_can_be_made_mutable.insert(*instruction_id); + } + Instruction::Call { arguments, .. } => { + for argument in arguments { + if matches!(dfg.type_of_value(*argument), Array { .. } | Slice { .. }) { + let argument = dfg.resolve(*argument); + + if let Some(existing) = array_to_last_use.insert(argument, *instruction_id) + { + instructions_that_can_be_made_mutable.remove(&existing); + } + } + } + } + _ => (), + } + } + + instructions_that_can_be_made_mutable +} + +/// Make each ArraySet instruction in `instructions_to_update` mutable. +fn make_mutable( + dfg: &mut DataFlowGraph, + block_id: BasicBlockId, + instructions_to_update: FxHashSet, +) { + if instructions_to_update.is_empty() { + return; + } + + // Take the instructions temporarily so we can mutate the DFG while we iterate through them + let block = &mut dfg[block_id]; + let instructions = block.take_instructions(); + + for instruction in &instructions { + if instructions_to_update.contains(instruction) { + let instruction = &mut dfg[*instruction]; + + if let Instruction::ArraySet { mutable, .. } = instruction { + *mutable = true; + } else { + unreachable!( + "Non-ArraySet instruction in instructions_to_update!\n{instruction:?}" + ); + } + } + } + + *dfg[block_id].instructions_mut() = instructions; +} diff --git a/compiler/noirc_evaluator/src/ssa/opt/array_use.rs b/compiler/noirc_evaluator/src/ssa/opt/array_use.rs deleted file mode 100644 index 0bb8b0112b6..00000000000 --- a/compiler/noirc_evaluator/src/ssa/opt/array_use.rs +++ /dev/null @@ -1,57 +0,0 @@ -use crate::ssa::{ - ir::{ - basic_block::BasicBlockId, - dfg::DataFlowGraph, - instruction::{Instruction, InstructionId}, - post_order::PostOrder, - value::{Value, ValueId}, - }, - ssa_gen::Ssa, -}; -use fxhash::FxHashMap as HashMap; - -impl Ssa { - /// Map arrays with the last instruction that uses it - /// For this we simply process all the instructions in execution order - /// and update the map whenever there is a match - #[tracing::instrument(level = "trace", skip(self))] - pub(crate) fn find_last_array_uses(&self) -> HashMap { - let mut array_use = HashMap::default(); - for func in self.functions.values() { - let mut reverse_post_order = PostOrder::with_function(func).into_vec(); - reverse_post_order.reverse(); - for block in reverse_post_order { - last_use(block, &func.dfg, &mut array_use); - } - } - array_use - } -} - -/// Updates the array_def map when an instructions is using an array -fn last_use( - block_id: BasicBlockId, - dfg: &DataFlowGraph, - array_def: &mut HashMap, -) { - let block = &dfg[block_id]; - for instruction_id in block.instructions() { - match &dfg[*instruction_id] { - Instruction::ArrayGet { array, .. } | Instruction::ArraySet { array, .. } => { - let array = dfg.resolve(*array); - array_def.insert(array, *instruction_id); - } - Instruction::Call { arguments, .. } => { - for argument in arguments { - let resolved_arg = dfg.resolve(*argument); - if matches!(dfg[resolved_arg], Value::Array { .. }) { - array_def.insert(resolved_arg, *instruction_id); - } - } - } - _ => { - // Nothing to do - } - } - } -} diff --git a/compiler/noirc_evaluator/src/ssa/opt/as_slice_length.rs b/compiler/noirc_evaluator/src/ssa/opt/as_slice_length.rs new file mode 100644 index 00000000000..69eab1da0ed --- /dev/null +++ b/compiler/noirc_evaluator/src/ssa/opt/as_slice_length.rs @@ -0,0 +1,71 @@ +use crate::ssa::{ + ir::{ + function::Function, + instruction::{Instruction, InstructionId, Intrinsic}, + types::Type, + value::Value, + }, + ssa_gen::Ssa, +}; +use fxhash::FxHashMap as HashMap; + +impl Ssa { + /// A simple SSA pass to find any calls to `Intrinsic::AsSlice` and replacing any references to the length of the + /// resulting slice with the length of the array from which it was generated. + /// + /// This allows the length of a slice generated from an array to be used in locations where a constant value is + /// necessary when the value of the array is unknown. + /// + /// Note that this pass must be placed before loop unrolling to be useful. + #[tracing::instrument(level = "trace", skip(self))] + pub(crate) fn as_slice_optimization(mut self) -> Self { + for func in self.functions.values_mut() { + let known_slice_lengths = known_slice_lengths(func); + replace_known_slice_lengths(func, known_slice_lengths); + } + self + } +} + +fn known_slice_lengths(func: &Function) -> HashMap { + let mut known_slice_lengths = HashMap::default(); + for block_id in func.reachable_blocks() { + let block = &func.dfg[block_id]; + for instruction_id in block.instructions() { + let (target_func, arguments) = match &func.dfg[*instruction_id] { + Instruction::Call { func, arguments } => (func, arguments), + _ => continue, + }; + + match &func.dfg[*target_func] { + Value::Intrinsic(Intrinsic::AsSlice) => { + let array_typ = func.dfg.type_of_value(arguments[0]); + if let Type::Array(_, length) = array_typ { + known_slice_lengths.insert(*instruction_id, length); + } else { + unreachable!("AsSlice called with non-array {}", array_typ); + } + } + _ => continue, + }; + } + } + known_slice_lengths +} + +fn replace_known_slice_lengths( + func: &mut Function, + known_slice_lengths: HashMap, +) { + known_slice_lengths.into_iter().for_each(|(instruction_id, known_length)| { + let call_returns = func.dfg.instruction_results(instruction_id); + let original_slice_length = call_returns[0]; + + // We won't use the new id for the original unknown length. + // This isn't strictly necessary as a new result will be defined the next time for which the instruction + // is reinserted but this avoids leaving the program in an invalid state. + func.dfg.replace_result(instruction_id, original_slice_length); + let known_length = func.dfg.make_constant(known_length.into(), Type::length_type()); + func.dfg.set_value_from_id(original_slice_length, known_length); + }); +} diff --git a/compiler/noirc_evaluator/src/ssa/opt/bubble_up_constrains.rs b/compiler/noirc_evaluator/src/ssa/opt/bubble_up_constrains.rs index b737c51d145..0409f0e6a49 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/bubble_up_constrains.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/bubble_up_constrains.rs @@ -77,7 +77,6 @@ mod test { use crate::ssa::{ function_builder::FunctionBuilder, ir::{ - function::RuntimeType, instruction::{Binary, BinaryOp, Instruction}, map::Id, types::Type, @@ -100,7 +99,7 @@ mod test { let main_id = Id::test_new(0); // Compiling main - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let v0 = builder.add_parameter(Type::field()); let one = builder.field_constant(1u128); diff --git a/compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs b/compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs index 06ae4bf5202..6cac8c91bc3 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs @@ -283,7 +283,6 @@ mod test { use crate::ssa::{ function_builder::FunctionBuilder, ir::{ - function::RuntimeType, instruction::{Binary, BinaryOp, Instruction, TerminatorInstruction}, map::Id, types::Type, @@ -305,7 +304,7 @@ mod test { let main_id = Id::test_new(0); // Compiling main - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let v0 = builder.add_parameter(Type::field()); let one = builder.field_constant(1u128); @@ -361,7 +360,7 @@ mod test { let main_id = Id::test_new(0); // Compiling main - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let v0 = builder.add_parameter(Type::unsigned(16)); let v1 = builder.add_parameter(Type::unsigned(16)); @@ -415,7 +414,7 @@ mod test { let main_id = Id::test_new(0); // Compiling main - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let v0 = builder.add_parameter(Type::unsigned(16)); let v1 = builder.add_parameter(Type::unsigned(16)); @@ -471,7 +470,7 @@ mod test { let main_id = Id::test_new(0); // Compiling main - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let v0 = builder.add_parameter(Type::field()); let one = builder.field_constant(1u128); let v1 = builder.insert_binary(v0, BinaryOp::Add, one); @@ -518,7 +517,7 @@ mod test { let main_id = Id::test_new(0); // Compiling main - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let v0 = builder.add_parameter(Type::unsigned(16)); let v1 = builder.insert_cast(v0, Type::unsigned(32)); @@ -562,7 +561,7 @@ mod test { let main_id = Id::test_new(0); // Compiling main - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let v0 = builder.add_parameter(Type::bool()); let v1 = builder.add_parameter(Type::bool()); let v2 = builder.add_parameter(Type::bool()); diff --git a/compiler/noirc_evaluator/src/ssa/opt/defunctionalize.rs b/compiler/noirc_evaluator/src/ssa/opt/defunctionalize.rs index 1f09a132132..ca6527eb0ec 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/defunctionalize.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/defunctionalize.rs @@ -13,7 +13,7 @@ use crate::ssa::{ function_builder::FunctionBuilder, ir::{ basic_block::BasicBlockId, - function::{Function, FunctionId, RuntimeType, Signature}, + function::{Function, FunctionId, Signature}, instruction::{BinaryOp, ConstrainError, Instruction}, types::{NumericType, Type}, value::{Value, ValueId}, @@ -304,7 +304,7 @@ fn create_apply_function( ) -> FunctionId { assert!(!function_ids.is_empty()); ssa.add_fn(|id| { - let mut function_builder = FunctionBuilder::new("apply".to_string(), id, RuntimeType::Acir); + let mut function_builder = FunctionBuilder::new("apply".to_string(), id); let target_id = function_builder.add_parameter(Type::field()); let params_ids = vecmap(signature.params, |typ| function_builder.add_parameter(typ)); diff --git a/compiler/noirc_evaluator/src/ssa/opt/die.rs b/compiler/noirc_evaluator/src/ssa/opt/die.rs index f7d8adb5275..d1b3e1e83f5 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/die.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/die.rs @@ -44,7 +44,7 @@ fn dead_instruction_elimination(function: &mut Function) { context.remove_unused_instructions_in_block(function, *block); } - context.remove_increment_rc_instructions(&mut function.dfg); + context.remove_rc_instructions(&mut function.dfg); } /// Per function context for tracking unused values and which instructions to remove. @@ -53,10 +53,10 @@ struct Context { used_values: HashSet, instructions_to_remove: HashSet, - /// IncrementRc instructions must be revisited after the main DIE pass since + /// IncrementRc & DecrementRc instructions must be revisited after the main DIE pass since /// they technically contain side-effects but we still want to remove them if their /// `value` parameter is not used elsewhere. - increment_rc_instructions: Vec<(InstructionId, BasicBlockId)>, + rc_instructions: Vec<(InstructionId, BasicBlockId)>, } impl Context { @@ -85,8 +85,9 @@ impl Context { } else { let instruction = &function.dfg[*instruction_id]; - if let Instruction::IncrementRc { .. } = instruction { - self.increment_rc_instructions.push((*instruction_id, block_id)); + use Instruction::*; + if matches!(instruction, IncrementRc { .. } | DecrementRc { .. }) { + self.rc_instructions.push((*instruction_id, block_id)); } else { instruction.for_each_value(|value| { self.mark_used_instruction_results(&function.dfg, value); @@ -145,16 +146,19 @@ impl Context { } } - fn remove_increment_rc_instructions(self, dfg: &mut DataFlowGraph) { - for (increment_rc, block) in self.increment_rc_instructions { - let value = match &dfg[increment_rc] { + fn remove_rc_instructions(self, dfg: &mut DataFlowGraph) { + for (rc, block) in self.rc_instructions { + let value = match &dfg[rc] { Instruction::IncrementRc { value } => *value, - other => unreachable!("Expected IncrementRc instruction, found {other:?}"), + Instruction::DecrementRc { value } => *value, + other => { + unreachable!("Expected IncrementRc or DecrementRc instruction, found {other:?}") + } }; - // This could be more efficient if we have to remove multiple IncrementRcs in a single block + // This could be more efficient if we have to remove multiple instructions in a single block if !self.used_values.contains(&value) { - dfg[block].instructions_mut().retain(|instruction| *instruction != increment_rc); + dfg[block].instructions_mut().retain(|instruction| *instruction != rc); } } } @@ -165,7 +169,6 @@ mod test { use crate::ssa::{ function_builder::FunctionBuilder, ir::{ - function::RuntimeType, instruction::{BinaryOp, Intrinsic}, map::Id, types::Type, @@ -195,7 +198,7 @@ mod test { let main_id = Id::test_new(0); // Compiling main - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let v0 = builder.add_parameter(Type::field()); let b1 = builder.insert_block(); diff --git a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs index 943a57c1bc0..07771397ce8 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs @@ -167,7 +167,9 @@ impl Ssa { /// For more information, see the module-level comment at the top of this file. #[tracing::instrument(level = "trace", skip(self))] pub(crate) fn flatten_cfg(mut self) -> Ssa { - flatten_function_cfg(self.main_mut()); + for function in self.functions.values_mut() { + flatten_function_cfg(function); + } self } } @@ -199,22 +201,47 @@ struct Context<'f> { /// found, the top of this conditions stack is popped since we are no longer under that /// condition. If we are under multiple conditions (a nested if), the topmost condition is /// the most recent condition combined with all previous conditions via `And` instructions. - conditions: Vec<(BasicBlockId, ValueId)>, + condition_stack: Vec, /// Maps SSA array values with a slice type to their size. /// This is maintained by appropriate calls to the `SliceCapacityTracker` and is used by the `ValueMerger`. slice_sizes: HashMap, + + /// Stack of block arguments + /// When processing a block, we pop this stack to get its arguments + /// and at the end we push the arguments for his successor + arguments_stack: Vec>, } +#[derive(Clone)] pub(crate) struct Store { old_value: ValueId, new_value: ValueId, } -struct Branch { - condition: ValueId, +#[derive(Clone)] +struct ConditionalBranch { + // Contains the last processed block during the processing of the branch. last_block: BasicBlockId, + // The unresolved condition of the branch + old_condition: ValueId, + // The condition of the branch + condition: ValueId, + // The store values accumulated when processing the branch store_values: HashMap, + // The allocations accumulated when processing the branch + local_allocations: HashSet, +} + +struct ConditionalContext { + // Condition from the conditional statement + condition: ValueId, + // Block containing the conditional statement + entry_block: BasicBlockId, + // First block of the then branch + then_branch: ConditionalBranch, + // First block of the else branch + else_branch: Option, } fn flatten_function_cfg(function: &mut Function) { @@ -233,90 +260,117 @@ fn flatten_function_cfg(function: &mut Function) { store_values: HashMap::default(), local_allocations: HashSet::new(), branch_ends, - conditions: Vec::new(), slice_sizes: HashMap::default(), + condition_stack: Vec::new(), + arguments_stack: Vec::new(), }; context.flatten(); } impl<'f> Context<'f> { fn flatten(&mut self) { - // Start with following the terminator of the entry block since we don't - // need to flatten the entry block into itself. - self.handle_terminator(self.inserter.function.entry_block()); + // Flatten the CFG by inlining all instructions from the queued blocks + // until all blocks have been flattened. + // We follow the terminator of each block to determine which blocks to + // process next + let mut queue = vec![self.inserter.function.entry_block()]; + while let Some(block) = queue.pop() { + self.inline_block(block); + let to_process = self.handle_terminator(block, &queue); + for incoming_block in to_process { + if !queue.contains(&incoming_block) { + queue.push(incoming_block); + } + } + } } - /// Check the terminator of the given block and recursively inline any blocks reachable from - /// it. Since each block from a jmpif terminator is inlined successively, we must handle - /// instructions with side effects like constrain and store specially to preserve correctness. - /// For these instructions we must keep track of what the current condition is and modify - /// the instructions according to the module-level comment at the top of this file. Note that - /// the current condition is all the jmpif conditions required to reach the current block, - /// combined via `And` instructions. - /// - /// Returns the last block to be inlined. This is either the return block of the function or, - /// if self.conditions is not empty, the end block of the most recent condition. - fn handle_terminator(&mut self, block: BasicBlockId) -> BasicBlockId { - // As we recursively flatten inner blocks, we need to track the slice information - // for the outer block before we start recursively inlining - let outer_block_instructions = self.inserter.function.dfg[block].instructions(); - let mut capacity_tracker = SliceCapacityTracker::new(&self.inserter.function.dfg); - for instruction in outer_block_instructions { - let results = self.inserter.function.dfg.instruction_results(*instruction); - let instruction = &self.inserter.function.dfg[*instruction]; + /// Returns the updated condition so that + /// it is 'AND-ed' with the previous condition (if any) + fn link_condition(&mut self, condition: ValueId) -> ValueId { + // Retrieve the previous condition + if let Some(context) = self.condition_stack.last() { + let previous_branch = context.else_branch.as_ref().unwrap_or(&context.then_branch); + let and = Instruction::binary(BinaryOp::And, previous_branch.condition, condition); + self.insert_instruction(and, CallStack::new()) + } else { + condition + } + } + + /// Returns the current condition + fn get_last_condition(&self) -> Option { + self.condition_stack.last().map(|context| match &context.else_branch { + Some(else_branch) => else_branch.condition, + None => context.then_branch.condition, + }) + } + + // Inline all instructions from the given block into the entry block, and track slice capacities + fn inline_block(&mut self, block: BasicBlockId) { + if self.inserter.function.entry_block() == block { + // we do not inline the entry block into itself + // for the outer block before we start inlining + let outer_block_instructions = self.inserter.function.dfg[block].instructions(); + let mut capacity_tracker = SliceCapacityTracker::new(&self.inserter.function.dfg); + for instruction in outer_block_instructions { + let results = self.inserter.function.dfg.instruction_results(*instruction); + let instruction = &self.inserter.function.dfg[*instruction]; + capacity_tracker.collect_slice_information( + instruction, + &mut self.slice_sizes, + results.to_vec(), + ); + } + + return; + } + + let arguments = self.arguments_stack.pop().unwrap(); + self.inserter.remember_block_params(block, &arguments); + + // If this is not a separate variable, clippy gets confused and says the to_vec is + // unnecessary, when removing it actually causes an aliasing/mutability error. + let instructions = self.inserter.function.dfg[block].instructions().to_vec(); + for instruction in instructions.iter() { + let results = self.push_instruction(*instruction); + let (instruction, _) = self.inserter.map_instruction(*instruction); + let mut capacity_tracker = SliceCapacityTracker::new(&self.inserter.function.dfg); capacity_tracker.collect_slice_information( - instruction, + &instruction, &mut self.slice_sizes, - results.to_vec(), + results, ); } + } - match self.inserter.function.dfg[block].unwrap_terminator() { + /// Returns the list of blocks that need to be processed after the given block + /// For a normal block, it would be its successor + /// For blocks related to a conditional statement, we ensure to process + /// the 'then-branch', then the 'else-branch' (if it exists), and finally the end block + fn handle_terminator( + &mut self, + block: BasicBlockId, + work_list: &[BasicBlockId], + ) -> Vec { + let terminator = self.inserter.function.dfg[block].unwrap_terminator().clone(); + match &terminator { TerminatorInstruction::JmpIf { condition, then_destination, else_destination } => { - let old_condition = *condition; - let then_block = *then_destination; - let else_block = *else_destination; - let then_condition = self.inserter.resolve(old_condition); - - let one = FieldElement::one(); - let then_branch = - self.inline_branch(block, then_block, old_condition, then_condition, one); - - let else_condition = - self.insert_instruction(Instruction::Not(then_condition), CallStack::new()); - let zero = FieldElement::zero(); - - // Make sure the else branch sees the previous values of each store - // rather than any values created in the 'then' branch. - self.undo_stores_in_then_branch(&then_branch); - - let else_branch = - self.inline_branch(block, else_block, old_condition, else_condition, zero); - - // We must remember to reset whether side effects are enabled when both branches - // end, in addition to resetting the value of old_condition since it is set to - // known to be true/false within the then/else branch respectively. - self.insert_current_side_effects_enabled(); - - // We must map back to `then_condition` here. Mapping `old_condition` to itself would - // lose any previous mappings. - self.inserter.map_value(old_condition, then_condition); - - // While there is a condition on the stack we don't compile outside the condition - // until it is popped. This ensures we inline the full then and else branches - // before continuing from the end of the conditional here where they can be merged properly. - let end = self.branch_ends[&block]; - self.inline_branch_end(end, then_branch, else_branch) + self.arguments_stack.push(vec![]); + self.if_start(condition, then_destination, else_destination, &block) } TerminatorInstruction::Jmp { destination, arguments, call_stack: _ } => { - if let Some((end_block, _)) = self.conditions.last() { - if destination == end_block { - return block; + let arguments = vecmap(arguments.clone(), |value| self.inserter.resolve(value)); + self.arguments_stack.push(arguments); + if work_list.contains(destination) { + if work_list.last() == Some(destination) { + self.else_stop(&block) + } else { + self.then_stop(&block) } + } else { + vec![*destination] } - let destination = *destination; - let arguments = vecmap(arguments.clone(), |value| self.inserter.resolve(value)); - self.inline_block(destination, &arguments) } TerminatorInstruction::Return { return_values, call_stack } => { let call_stack = call_stack.clone(); @@ -326,133 +380,133 @@ impl<'f> Context<'f> { let entry = self.inserter.function.entry_block(); self.inserter.function.dfg.set_block_terminator(entry, new_return); - block + vec![] } } } - /// Push a condition to the stack of conditions. - /// - /// This condition should be present while we're inlining each block reachable from the 'then' - /// branch of a jmpif instruction, until the branches eventually join back together. Likewise, - /// !condition should be present while we're inlining each block reachable from the 'else' - /// branch of a jmpif instruction until the join block. - fn push_condition(&mut self, start_block: BasicBlockId, condition: ValueId) { - let end_block = self.branch_ends[&start_block]; - - if let Some((_, previous_condition)) = self.conditions.last() { - let and = Instruction::binary(BinaryOp::And, *previous_condition, condition); - let new_condition = self.insert_instruction(and, CallStack::new()); - self.conditions.push((end_block, new_condition)); - } else { - self.conditions.push((end_block, condition)); + /// Process a conditional statement + fn if_start( + &mut self, + condition: &ValueId, + then_destination: &BasicBlockId, + else_destination: &BasicBlockId, + if_entry: &BasicBlockId, + ) -> Vec { + // manage conditions + let old_condition = *condition; + let then_condition = self.inserter.resolve(old_condition); + + let one = FieldElement::one(); + let old_stores = std::mem::take(&mut self.store_values); + let old_allocations = std::mem::take(&mut self.local_allocations); + let branch = ConditionalBranch { + old_condition, + condition: self.link_condition(then_condition), + store_values: old_stores, + local_allocations: old_allocations, + last_block: *then_destination, + }; + let cond_context = ConditionalContext { + condition: then_condition, + entry_block: *if_entry, + then_branch: branch, + else_branch: None, + }; + self.condition_stack.push(cond_context); + self.insert_current_side_effects_enabled(); + // Optimization: within the then branch we know the condition to be true, so replace + // any references of it within this branch with true. Likewise, do the same with false + // with the else branch. We must be careful not to replace the condition if it is a + // known constant, otherwise we can end up setting 1 = 0 or vice-versa. + if self.inserter.function.dfg.get_numeric_constant(old_condition).is_none() { + let known_value = self.inserter.function.dfg.make_constant(one, Type::bool()); + + self.inserter.map_value(old_condition, known_value); } + vec![self.branch_ends[if_entry], *else_destination, *then_destination] } - /// Insert a new instruction into the function's entry block. - /// Unlike push_instruction, this function will not map any ValueIds. - /// within the given instruction, nor will it modify self.values in any way. - fn insert_instruction(&mut self, instruction: Instruction, call_stack: CallStack) -> ValueId { - let block = self.inserter.function.entry_block(); - self.inserter - .function - .dfg - .insert_instruction_and_results(instruction, block, None, call_stack) - .first() + /// Switch context to the 'else-branch' + fn then_stop(&mut self, block: &BasicBlockId) -> Vec { + let mut cond_context = self.condition_stack.pop().unwrap(); + cond_context.then_branch.last_block = *block; + + let else_condition = + self.insert_instruction(Instruction::Not(cond_context.condition), CallStack::new()); + let else_condition = self.link_condition(else_condition); + + let zero = FieldElement::zero(); + // Make sure the else branch sees the previous values of each store + // rather than any values created in the 'then' branch. + let old_stores = std::mem::take(&mut cond_context.then_branch.store_values); + cond_context.then_branch.store_values = std::mem::take(&mut self.store_values); + self.undo_stores_in_then_branch(&cond_context.then_branch.store_values); + + let old_allocations = std::mem::take(&mut self.local_allocations); + let else_branch = ConditionalBranch { + old_condition: cond_context.then_branch.old_condition, + condition: else_condition, + store_values: old_stores, + local_allocations: old_allocations, + last_block: *block, + }; + let old_condition = else_branch.old_condition; + cond_context.then_branch.local_allocations.clear(); + cond_context.else_branch = Some(else_branch); + self.condition_stack.push(cond_context); + + self.insert_current_side_effects_enabled(); + // Optimization: within the then branch we know the condition to be true, so replace + // any references of it within this branch with true. Likewise, do the same with false + // with the else branch. We must be careful not to replace the condition if it is a + // known constant, otherwise we can end up setting 1 = 0 or vice-versa. + if self.inserter.function.dfg.get_numeric_constant(old_condition).is_none() { + let known_value = self.inserter.function.dfg.make_constant(zero, Type::bool()); + + self.inserter.map_value(old_condition, known_value); + } + assert_eq!(self.cfg.successors(*block).len(), 1); + vec![self.cfg.successors(*block).next().unwrap()] } - /// Inserts a new instruction into the function's entry block, using the given - /// control type variables to specify result types if needed. - /// Unlike push_instruction, this function will not map any ValueIds. - /// within the given instruction, nor will it modify self.values in any way. - fn insert_instruction_with_typevars( - &mut self, - instruction: Instruction, - ctrl_typevars: Option>, - ) -> InsertInstructionResult { - let block = self.inserter.function.entry_block(); - self.inserter.function.dfg.insert_instruction_and_results( - instruction, - block, - ctrl_typevars, - CallStack::new(), - ) - } + /// Process the 'exit' block of a conditional statement + fn else_stop(&mut self, block: &BasicBlockId) -> Vec { + let mut cond_context = self.condition_stack.pop().unwrap(); + if cond_context.else_branch.is_none() { + // then_stop() has not been called, this means that the conditional statement has no else branch + // so we simply do the then_stop() now + self.condition_stack.push(cond_context); + self.then_stop(block); + cond_context = self.condition_stack.pop().unwrap(); + } - /// Checks the branch condition on the top of the stack and uses it to build and insert an - /// `EnableSideEffects` instruction into the entry block. - /// - /// If the stack is empty, a "true" u1 constant is taken to be the active condition. This is - /// necessary for re-enabling side-effects when re-emerging to a branch depth of 0. - fn insert_current_side_effects_enabled(&mut self) { - let condition = match self.conditions.last() { - Some((_, cond)) => *cond, - None => { - self.inserter.function.dfg.make_constant(FieldElement::one(), Type::unsigned(1)) - } - }; - let enable_side_effects = Instruction::EnableSideEffects { condition }; - self.insert_instruction_with_typevars(enable_side_effects, None); - } + let mut else_branch = cond_context.else_branch.unwrap(); + let stores_in_branch = std::mem::replace(&mut self.store_values, else_branch.store_values); + self.local_allocations = std::mem::take(&mut else_branch.local_allocations); + else_branch.last_block = *block; + else_branch.store_values = stores_in_branch; + cond_context.else_branch = Some(else_branch); - /// Inline one branch of a jmpif instruction. - /// - /// This will continue inlining recursively until the next end block is reached where each branch - /// of the jmpif instruction is joined back into a single block. - /// - /// Within a branch of a jmpif instruction, we can assume the condition of the jmpif to be - /// always true or false, depending on which branch we're in. - /// - /// Returns the ending block / join block of this branch. - fn inline_branch( - &mut self, - jmpif_block: BasicBlockId, - destination: BasicBlockId, - old_condition: ValueId, - new_condition: ValueId, - condition_value: FieldElement, - ) -> Branch { - if destination == self.branch_ends[&jmpif_block] { - // If the branch destination is the same as the end of the branch, this must be the - // 'else' case of an if with no else - so there is no else branch. - Branch { - condition: new_condition, - // The last block here is somewhat arbitrary. It only matters that it has no Jmp - // args that will be merged by inline_branch_end. Since jmpifs don't have - // block arguments, it is safe to use the jmpif block here. - last_block: jmpif_block, - store_values: HashMap::default(), - } - } else { - self.push_condition(jmpif_block, new_condition); - self.insert_current_side_effects_enabled(); - let old_stores = std::mem::take(&mut self.store_values); - let old_allocations = std::mem::take(&mut self.local_allocations); - - // Optimization: within the then branch we know the condition to be true, so replace - // any references of it within this branch with true. Likewise, do the same with false - // with the else branch. We must be careful not to replace the condition if it is a - // known constant, otherwise we can end up setting 1 = 0 or vice-versa. - if self.inserter.function.dfg.get_numeric_constant(old_condition).is_none() { - let known_value = - self.inserter.function.dfg.make_constant(condition_value, Type::bool()); - - self.inserter.map_value(old_condition, known_value); - } + // We must remember to reset whether side effects are enabled when both branches + // end, in addition to resetting the value of old_condition since it is set to + // known to be true/false within the then/else branch respectively. + self.insert_current_side_effects_enabled(); - let final_block = self.inline_block(destination, &[]); + // We must map back to `then_condition` here. Mapping `old_condition` to itself would + // lose any previous mappings. + self.inserter + .map_value(cond_context.then_branch.old_condition, cond_context.then_branch.condition); - self.conditions.pop(); + // While there is a condition on the stack we don't compile outside the condition + // until it is popped. This ensures we inline the full then and else branches + // before continuing from the end of the conditional here where they can be merged properly. + let end = self.branch_ends[&cond_context.entry_block]; - let stores_in_branch = std::mem::replace(&mut self.store_values, old_stores); - self.local_allocations = old_allocations; + // Merge arguments and stores from the else/end branches + self.inline_branch_end(end, cond_context); - Branch { - condition: new_condition, - last_block: final_block, - store_values: stores_in_branch, - } - } + vec![self.cfg.successors(*block).next().unwrap()] } /// Inline the ending block of a branch, the point where all blocks from a jmpif instruction @@ -467,15 +521,17 @@ impl<'f> Context<'f> { fn inline_branch_end( &mut self, destination: BasicBlockId, - then_branch: Branch, - else_branch: Branch, + cond_context: ConditionalContext, ) -> BasicBlockId { assert_eq!(self.cfg.predecessors(destination).len(), 2); + let last_then = cond_context.then_branch.last_block; + let mut else_args = Vec::new(); + if cond_context.else_branch.is_some() { + let last_else = cond_context.else_branch.clone().unwrap().last_block; + else_args = self.inserter.function.dfg[last_else].terminator_arguments().to_vec(); + } - let then_args = - self.inserter.function.dfg[then_branch.last_block].terminator_arguments().to_vec(); - let else_args = - self.inserter.function.dfg[else_branch.last_block].terminator_arguments().to_vec(); + let then_args = self.inserter.function.dfg[last_then].terminator_arguments().to_vec(); let params = self.inserter.function.dfg.block_parameters(destination); assert_eq!(params.len(), then_args.len()); @@ -500,17 +556,64 @@ impl<'f> Context<'f> { // Cannot include this in the previous vecmap since it requires exclusive access to self let args = vecmap(args, |(then_arg, else_arg)| { value_merger.merge_values( - then_branch.condition, - else_branch.condition, + cond_context.then_branch.condition, + cond_context.else_branch.clone().unwrap().condition, then_arg, else_arg, ) }); - self.merge_stores(then_branch, else_branch); + self.merge_stores(cond_context.then_branch, cond_context.else_branch); + self.arguments_stack.pop(); + self.arguments_stack.pop(); + self.arguments_stack.push(args); + destination + } + + /// Insert a new instruction into the function's entry block. + /// Unlike push_instruction, this function will not map any ValueIds. + /// within the given instruction, nor will it modify self.values in any way. + fn insert_instruction(&mut self, instruction: Instruction, call_stack: CallStack) -> ValueId { + let block = self.inserter.function.entry_block(); + self.inserter + .function + .dfg + .insert_instruction_and_results(instruction, block, None, call_stack) + .first() + } + + /// Inserts a new instruction into the function's entry block, using the given + /// control type variables to specify result types if needed. + /// Unlike push_instruction, this function will not map any ValueIds. + /// within the given instruction, nor will it modify self.values in any way. + fn insert_instruction_with_typevars( + &mut self, + instruction: Instruction, + ctrl_typevars: Option>, + ) -> InsertInstructionResult { + let block = self.inserter.function.entry_block(); + self.inserter.function.dfg.insert_instruction_and_results( + instruction, + block, + ctrl_typevars, + CallStack::new(), + ) + } - // insert merge instruction - self.inline_block(destination, &args) + /// Checks the branch condition on the top of the stack and uses it to build and insert an + /// `EnableSideEffects` instruction into the entry block. + /// + /// If the stack is empty, a "true" u1 constant is taken to be the active condition. This is + /// necessary for re-enabling side-effects when re-emerging to a branch depth of 0. + fn insert_current_side_effects_enabled(&mut self) { + let condition = match self.get_last_condition() { + Some(cond) => cond, + None => { + self.inserter.function.dfg.make_constant(FieldElement::one(), Type::unsigned(1)) + } + }; + let enable_side_effects = Instruction::EnableSideEffects { condition }; + self.insert_instruction_with_typevars(enable_side_effects, None); } /// Merge any store instructions found in each branch. @@ -518,7 +621,11 @@ impl<'f> Context<'f> { /// This function relies on the 'then' branch being merged before the 'else' branch of a jmpif /// instruction. If this ordering is changed, the ordering that store values are merged within /// this function also needs to be changed to reflect that. - fn merge_stores(&mut self, then_branch: Branch, else_branch: Branch) { + fn merge_stores( + &mut self, + then_branch: ConditionalBranch, + else_branch: Option, + ) { // Address -> (then_value, else_value, value_before_the_if) let mut new_map = BTreeMap::new(); @@ -526,11 +633,13 @@ impl<'f> Context<'f> { new_map.insert(address, (store.new_value, store.old_value, store.old_value)); } - for (address, store) in else_branch.store_values { - if let Some(entry) = new_map.get_mut(&address) { - entry.1 = store.new_value; - } else { - new_map.insert(address, (store.old_value, store.new_value, store.old_value)); + if else_branch.is_some() { + for (address, store) in else_branch.clone().unwrap().store_values { + if let Some(entry) = new_map.get_mut(&address) { + entry.1 = store.new_value; + } else { + new_map.insert(address, (store.old_value, store.new_value, store.old_value)); + } } } @@ -544,8 +653,11 @@ impl<'f> Context<'f> { } let then_condition = then_branch.condition; - let else_condition = else_branch.condition; - + let else_condition = if let Some(branch) = else_branch { + branch.condition + } else { + self.inserter.function.dfg.make_constant(FieldElement::zero(), Type::bool()) + }; let block = self.inserter.function.entry_block(); let mut value_merger = @@ -607,35 +719,6 @@ impl<'f> Context<'f> { } } - /// Inline all instructions from the given destination block into the entry block. - /// Afterwards, check the block's terminator and continue inlining recursively. - /// - /// Returns the final block that was inlined. - /// - /// Expects that the `arguments` given are already translated via self.inserter.resolve. - /// If they are not, it is possible some values which no longer exist, such as block - /// parameters, will be kept in the program. - fn inline_block(&mut self, destination: BasicBlockId, arguments: &[ValueId]) -> BasicBlockId { - self.inserter.remember_block_params(destination, arguments); - - // If this is not a separate variable, clippy gets confused and says the to_vec is - // unnecessary, when removing it actually causes an aliasing/mutability error. - let instructions = self.inserter.function.dfg[destination].instructions().to_vec(); - - for instruction in instructions.iter() { - let results = self.push_instruction(*instruction); - let (instruction, _) = self.inserter.map_instruction(*instruction); - let mut capacity_tracker = SliceCapacityTracker::new(&self.inserter.function.dfg); - capacity_tracker.collect_slice_information( - &instruction, - &mut self.slice_sizes, - results, - ); - } - - self.handle_terminator(destination) - } - /// Push the given instruction to the end of the entry block of the current function. /// /// Note that each ValueId of the instruction will be mapped via self.inserter.resolve. @@ -666,7 +749,7 @@ impl<'f> Context<'f> { instruction: Instruction, call_stack: CallStack, ) -> Instruction { - if let Some((_, condition)) = self.conditions.last().copied() { + if let Some(condition) = self.get_last_condition() { match instruction { Instruction::Constrain(lhs, rhs, message) => { // Replace constraint `lhs == rhs` with `condition * lhs == condition * rhs`. @@ -741,8 +824,8 @@ impl<'f> Context<'f> { } } - fn undo_stores_in_then_branch(&mut self, then_branch: &Branch) { - for (address, store) in &then_branch.store_values { + fn undo_stores_in_then_branch(&mut self, store_values: &HashMap) { + for (address, store) in store_values { let address = *address; let value = store.old_value; self.insert_instruction_with_typevars(Instruction::Store { address, value }, None); @@ -758,7 +841,7 @@ mod test { function_builder::FunctionBuilder, ir::{ dfg::DataFlowGraph, - function::{Function, RuntimeType}, + function::Function, instruction::{BinaryOp, Instruction, Intrinsic, TerminatorInstruction}, map::Id, types::Type, @@ -779,7 +862,7 @@ mod test { // return v1 // } let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let b1 = builder.insert_block(); let b2 = builder.insert_block(); @@ -833,7 +916,7 @@ mod test { // return // } let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let b1 = builder.insert_block(); let b2 = builder.insert_block(); @@ -882,7 +965,7 @@ mod test { // return // } let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let b1 = builder.insert_block(); let b2 = builder.insert_block(); @@ -943,7 +1026,7 @@ mod test { // return // } let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let b1 = builder.insert_block(); let b2 = builder.insert_block(); @@ -1033,7 +1116,7 @@ mod test { // ↘ ↙ // b9 let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let b1 = builder.insert_block(); let b2 = builder.insert_block(); @@ -1190,7 +1273,7 @@ mod test { // before the first store to allocate, which loaded an uninitialized value. // In this test we assert the ordering is strictly Allocate then Store then Load. let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let b1 = builder.insert_block(); let b2 = builder.insert_block(); @@ -1289,7 +1372,7 @@ mod test { // return // } let main_id = Id::test_new(1); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); builder.insert_block(); // entry @@ -1342,7 +1425,7 @@ mod test { // jmp b3() // } let main_id = Id::test_new(1); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); builder.insert_block(); // b0 let b1 = builder.insert_block(); @@ -1452,7 +1535,7 @@ mod test { // jmp b5() // } let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let b1 = builder.insert_block(); let b2 = builder.insert_block(); diff --git a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/branch_analysis.rs b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/branch_analysis.rs index 59bee00936a..ce54bb533f7 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/branch_analysis.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/branch_analysis.rs @@ -114,7 +114,7 @@ mod test { use crate::ssa::{ function_builder::FunctionBuilder, - ir::{cfg::ControlFlowGraph, function::RuntimeType, map::Id, types::Type}, + ir::{cfg::ControlFlowGraph, map::Id, types::Type}, opt::flatten_cfg::branch_analysis::find_branch_ends, }; @@ -134,7 +134,7 @@ mod test { // ↘ ↙ // b9 let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let b1 = builder.insert_block(); let b2 = builder.insert_block(); @@ -195,7 +195,7 @@ mod test { // ↘ ↙ // b15 let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let b1 = builder.insert_block(); let b2 = builder.insert_block(); diff --git a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/capacity_tracker.rs b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/capacity_tracker.rs index 7cd0fe3084e..93e52542278 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/capacity_tracker.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/capacity_tracker.rs @@ -5,6 +5,7 @@ use crate::ssa::ir::{ value::{Value, ValueId}, }; +use acvm::FieldElement; use fxhash::FxHashMap as HashMap; pub(crate) struct SliceCapacityTracker<'a> { @@ -62,43 +63,72 @@ impl<'a> SliceCapacityTracker<'a> { | Intrinsic::SlicePushFront | Intrinsic::SlicePopBack | Intrinsic::SliceInsert - | Intrinsic::SliceRemove => (1, 1), + | Intrinsic::SliceRemove => (Some(1), 1), // `pop_front` returns the popped element, and then the respective slice. // This means in the case of a slice with structs, the result index of the popped slice // will change depending on the number of elements in the struct. // For example, a slice with four elements will look as such in SSA: // v3, v4, v5, v6, v7, v8 = call slice_pop_front(v1, v2) // where v7 is the slice length and v8 is the popped slice itself. - Intrinsic::SlicePopFront => (1, results.len() - 1), + Intrinsic::SlicePopFront => (Some(1), results.len() - 1), + // The slice capacity of these intrinsics is not determined by the arguments of the function. + Intrinsic::ToBits(_) | Intrinsic::ToRadix(_) => (None, 1), + Intrinsic::AsSlice => (Some(0), 1), _ => return, }; - let slice_contents = arguments[argument_index]; + let result_slice = results[result_index]; match intrinsic { Intrinsic::SlicePushBack | Intrinsic::SlicePushFront | Intrinsic::SliceInsert => { + let argument_index = argument_index + .expect("ICE: Should have an argument index for slice intrinsics"); + let slice_contents = arguments[argument_index]; + for arg in &arguments[(argument_index + 1)..] { let element_typ = self.dfg.type_of_value(*arg); if element_typ.contains_slice_element() { self.compute_slice_capacity(*arg, slice_sizes); } } + if let Some(contents_capacity) = slice_sizes.get(&slice_contents) { let new_capacity = *contents_capacity + 1; - slice_sizes.insert(results[result_index], new_capacity); + slice_sizes.insert(result_slice, new_capacity); } } Intrinsic::SlicePopBack | Intrinsic::SliceRemove | Intrinsic::SlicePopFront => { - // We do not decrement the size on intrinsics that could remove values from a slice. - // This is because we could potentially go back to the smaller slice and not fill in dummies. - // This pass should be tracking the potential max that a slice ***could be*** + let argument_index = argument_index + .expect("ICE: Should have an argument index for slice intrinsics"); + let slice_contents = arguments[argument_index]; + if let Some(contents_capacity) = slice_sizes.get(&slice_contents) { let new_capacity = *contents_capacity - 1; - slice_sizes.insert(results[result_index], new_capacity); + slice_sizes.insert(result_slice, new_capacity); } } + Intrinsic::ToBits(_) => { + // Compiler sanity check + assert!(matches!(self.dfg.type_of_value(result_slice), Type::Slice(_))); + slice_sizes.insert(result_slice, FieldElement::max_num_bits() as usize); + } + Intrinsic::ToRadix(_) => { + // Compiler sanity check + assert!(matches!(self.dfg.type_of_value(result_slice), Type::Slice(_))); + slice_sizes + .insert(result_slice, FieldElement::max_num_bytes() as usize); + } + Intrinsic::AsSlice => { + let argument_index = argument_index + .expect("ICE: Should have an argument index for AsSlice builtin"); + let array_size = self + .dfg + .try_get_array_length(arguments[argument_index]) + .expect("ICE: Should be have an array length for AsSlice input"); + slice_sizes.insert(result_slice, array_size); + } _ => {} } } diff --git a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/value_merger.rs b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/value_merger.rs index 6b923a2e42d..0a351148fa3 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/value_merger.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/flatten_cfg/value_merger.rs @@ -234,9 +234,9 @@ impl<'a> ValueMerger<'a> { /// such as with dynamic indexing of non-homogenous slices. fn make_slice_dummy_data(&mut self, typ: &Type) -> ValueId { match typ { - Type::Numeric(_) => { + Type::Numeric(numeric_type) => { let zero = FieldElement::zero(); - self.dfg.make_constant(zero, Type::field()) + self.dfg.make_constant(zero, Type::Numeric(*numeric_type)) } Type::Array(element_types, len) => { let mut array = im::Vector::new(); diff --git a/compiler/noirc_evaluator/src/ssa/opt/inlining.rs b/compiler/noirc_evaluator/src/ssa/opt/inlining.rs index 776f22b2877..ead3cac071c 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/inlining.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/inlining.rs @@ -11,7 +11,7 @@ use crate::ssa::{ ir::{ basic_block::BasicBlockId, dfg::{CallStack, InsertInstructionResult}, - function::{Function, FunctionId, RuntimeType}, + function::{Function, FunctionId}, instruction::{Instruction, InstructionId, TerminatorInstruction}, value::{Value, ValueId}, }, @@ -94,12 +94,13 @@ struct PerFunctionContext<'function> { } /// The entry point functions are each function we should inline into - and each function that -/// should be left in the final program. This is usually just `main` but also includes any -/// brillig functions used. +/// should be left in the final program. +/// This is the `main` function, any Acir functions with a [fold inline type][InlineType::Fold], +/// and any brillig functions used. fn get_entry_point_functions(ssa: &Ssa) -> BTreeSet { let functions = ssa.functions.iter(); let mut entry_points = functions - .filter(|(_, function)| function.runtime() == RuntimeType::Brillig) + .filter(|(_, function)| function.runtime().is_entry_point()) .map(|(id, _)| *id) .collect::>(); @@ -115,7 +116,8 @@ impl InlineContext { /// that could not be inlined calling it. fn new(ssa: &Ssa, entry_point: FunctionId) -> InlineContext { let source = &ssa.functions[&entry_point]; - let builder = FunctionBuilder::new(source.name().to_owned(), entry_point, source.runtime()); + let mut builder = FunctionBuilder::new(source.name().to_owned(), entry_point); + builder.set_runtime(source.runtime()); Self { builder, recursion_level: 0, entry_point, call_stack: CallStack::new() } } @@ -349,10 +351,13 @@ impl<'function> PerFunctionContext<'function> { for id in block.instructions() { match &self.source_function.dfg[*id] { Instruction::Call { func, arguments } => match self.get_function(*func) { - Some(function) => match ssa.functions[&function].runtime() { - RuntimeType::Acir => self.inline_function(ssa, *id, function, arguments), - RuntimeType::Brillig => self.push_instruction(*id), - }, + Some(function) => { + if ssa.functions[&function].runtime().is_entry_point() { + self.push_instruction(*id); + } else { + self.inline_function(ssa, *id, function, arguments); + } + } None => self.push_instruction(*id), }, _ => self.push_instruction(*id), @@ -487,6 +492,13 @@ impl<'function> PerFunctionContext<'function> { } TerminatorInstruction::Return { return_values, call_stack } => { let return_values = vecmap(return_values, |value| self.translate_value(*value)); + + // Note that `translate_block` would take us back to the point at which the + // inlining of this source block began. Since additional blocks may have been + // inlined since, we are interested in the block representing the current program + // point, obtained via `current_block`. + let block_id = self.context.builder.current_block(); + if self.inlining_entry { let mut new_call_stack = self.context.call_stack.clone(); new_call_stack.append(call_stack.clone()); @@ -495,11 +507,7 @@ impl<'function> PerFunctionContext<'function> { .set_call_stack(new_call_stack) .terminate_with_return(return_values.clone()); } - // Note that `translate_block` would take us back to the point at which the - // inlining of this source block began. Since additional blocks may have been - // inlined since, we are interested in the block representing the current program - // point, obtained via `current_block`. - let block_id = self.context.builder.current_block(); + Some((block_id, return_values)) } } @@ -514,7 +522,7 @@ mod test { function_builder::FunctionBuilder, ir::{ basic_block::BasicBlockId, - function::RuntimeType, + function::InlineType, instruction::{BinaryOp, Intrinsic, TerminatorInstruction}, map::Id, types::Type, @@ -533,14 +541,14 @@ mod test { // return 72 // } let foo_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("foo".into(), foo_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("foo".into(), foo_id); let bar_id = Id::test_new(1); let bar = builder.import_function(bar_id); let results = builder.insert_call(bar, Vec::new(), vec![Type::field()]).to_vec(); builder.terminate_with_return(results); - builder.new_function("bar".into(), bar_id); + builder.new_function("bar".into(), bar_id, InlineType::default()); let expected_return = 72u128; let seventy_two = builder.field_constant(expected_return); builder.terminate_with_return(vec![seventy_two]); @@ -582,7 +590,7 @@ mod test { let id2_id = Id::test_new(3); // Compiling main - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let main_v0 = builder.add_parameter(Type::field()); let main_f1 = builder.import_function(square_id); @@ -595,18 +603,18 @@ mod test { builder.terminate_with_return(vec![main_v16]); // Compiling square f1 - builder.new_function("square".into(), square_id); + builder.new_function("square".into(), square_id, InlineType::default()); let square_v0 = builder.add_parameter(Type::field()); let square_v2 = builder.insert_binary(square_v0, BinaryOp::Mul, square_v0); builder.terminate_with_return(vec![square_v2]); // Compiling id1 f2 - builder.new_function("id1".into(), id1_id); + builder.new_function("id1".into(), id1_id, InlineType::default()); let id1_v0 = builder.add_parameter(Type::Function); builder.terminate_with_return(vec![id1_v0]); // Compiling id2 f3 - builder.new_function("id2".into(), id2_id); + builder.new_function("id2".into(), id2_id, InlineType::default()); let id2_v0 = builder.add_parameter(Type::Function); builder.terminate_with_return(vec![id2_v0]); @@ -638,7 +646,7 @@ mod test { // return v4 // } let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let factorial_id = Id::test_new(1); let factorial = builder.import_function(factorial_id); @@ -647,7 +655,7 @@ mod test { let results = builder.insert_call(factorial, vec![five], vec![Type::field()]).to_vec(); builder.terminate_with_return(results); - builder.new_function("factorial".into(), factorial_id); + builder.new_function("factorial".into(), factorial_id, InlineType::default()); let b1 = builder.insert_block(); let b2 = builder.insert_block(); @@ -738,7 +746,7 @@ mod test { // jmp b3(Field 2) // } let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let main_cond = builder.add_parameter(Type::bool()); let inner1_id = Id::test_new(1); @@ -748,14 +756,14 @@ mod test { builder.insert_call(assert_constant, vec![main_v2], vec![]); builder.terminate_with_return(vec![]); - builder.new_function("inner1".into(), inner1_id); + builder.new_function("inner1".into(), inner1_id, InlineType::default()); let inner1_cond = builder.add_parameter(Type::bool()); let inner2_id = Id::test_new(2); let inner2 = builder.import_function(inner2_id); let inner1_v2 = builder.insert_call(inner2, vec![inner1_cond], vec![Type::field()])[0]; builder.terminate_with_return(vec![inner1_v2]); - builder.new_function("inner2".into(), inner2_id); + builder.new_function("inner2".into(), inner2_id, InlineType::default()); let inner2_cond = builder.add_parameter(Type::bool()); let then_block = builder.insert_block(); let else_block = builder.insert_block(); diff --git a/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs b/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs index 0a49ca4ecca..7b87142d824 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs @@ -414,7 +414,6 @@ mod tests { ir::{ basic_block::BasicBlockId, dfg::DataFlowGraph, - function::RuntimeType, instruction::{BinaryOp, Instruction, Intrinsic, TerminatorInstruction}, map::Id, types::Type, @@ -433,7 +432,7 @@ mod tests { // } let func_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("func".into(), func_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("func".into(), func_id); let v0 = builder.insert_allocate(Type::Array(Rc::new(vec![Type::field()]), 2)); let one = builder.field_constant(FieldElement::one()); let two = builder.field_constant(FieldElement::one()); @@ -474,7 +473,7 @@ mod tests { // } let func_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("func".into(), func_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("func".into(), func_id); let v0 = builder.insert_allocate(Type::field()); let one = builder.field_constant(FieldElement::one()); builder.insert_store(v0, one); @@ -508,7 +507,7 @@ mod tests { // } let func_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("func".into(), func_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("func".into(), func_id); let v0 = builder.insert_allocate(Type::field()); let const_one = builder.field_constant(FieldElement::one()); builder.insert_store(v0, const_one); @@ -567,7 +566,7 @@ mod tests { // return v2, v3, v4 // } let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let v0 = builder.insert_allocate(Type::field()); @@ -647,7 +646,7 @@ mod tests { // return // } let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let v0 = builder.insert_allocate(Type::field()); diff --git a/compiler/noirc_evaluator/src/ssa/opt/mod.rs b/compiler/noirc_evaluator/src/ssa/opt/mod.rs index a315695f7db..4452840a28c 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/mod.rs @@ -3,7 +3,8 @@ //! Each pass is generally expected to mutate the SSA IR into a gradually //! simpler form until the IR only has a single function remaining with 1 block within it. //! Generally, these passes are also expected to minimize the final amount of instructions. -mod array_use; +mod array_set; +mod as_slice_length; mod assert_constant; mod bubble_up_constrains; mod constant_folding; @@ -12,6 +13,8 @@ mod die; pub(crate) mod flatten_cfg; mod inlining; mod mem2reg; +mod rc; mod remove_bit_shifts; +mod remove_enable_side_effects; mod simplify_cfg; mod unrolling; diff --git a/compiler/noirc_evaluator/src/ssa/opt/rc.rs b/compiler/noirc_evaluator/src/ssa/opt/rc.rs new file mode 100644 index 00000000000..1561547e32e --- /dev/null +++ b/compiler/noirc_evaluator/src/ssa/opt/rc.rs @@ -0,0 +1,328 @@ +use std::collections::{HashMap, HashSet}; + +use crate::ssa::{ + ir::{ + basic_block::BasicBlockId, + function::Function, + instruction::{Instruction, InstructionId, TerminatorInstruction}, + types::Type, + value::ValueId, + }, + ssa_gen::Ssa, +}; + +impl Ssa { + /// This pass removes `inc_rc` and `dec_rc` instructions + /// as long as there are no `array_set` instructions to an array + /// of the same type in between. + /// + /// Note that this pass is very conservative since the array_set + /// instruction does not need to be to the same array. This is because + /// the given array may alias another array (e.g. function parameters or + /// a `load`ed array from a reference). + #[tracing::instrument(level = "trace", skip(self))] + pub(crate) fn remove_paired_rc(mut self) -> Ssa { + for function in self.functions.values_mut() { + remove_paired_rc(function); + } + self + } +} + +#[derive(Default)] +struct Context { + // All inc_rc instructions encountered without a corresponding dec_rc. + // These are only searched for in the first block of a function. + // + // The type of the array being operated on is recorded. + // If an array_set to that array type is encountered, that is also recorded. + inc_rcs: HashMap>, +} + +struct IncRc { + id: InstructionId, + array: ValueId, + possibly_mutated: bool, +} + +/// This function is very simplistic for now. It takes advantage of the fact that dec_rc +/// instructions are currently issued only at the end of a function for parameters and will +/// only check the first and last block for inc & dec rc instructions to be removed. The rest +/// of the function is still checked for array_set instructions. +/// +/// This restriction lets this function largely ignore merging intermediate results from other +/// blocks and handling loops. +fn remove_paired_rc(function: &mut Function) { + // `dec_rc` is only issued for parameters currently so we can speed things + // up a bit by skipping any functions without them. + if !contains_array_parameter(function) { + return; + } + + let mut context = Context::default(); + + context.find_rcs_in_entry_block(function); + context.scan_for_array_sets(function); + let to_remove = context.find_rcs_to_remove(function); + remove_instructions(to_remove, function); +} + +fn contains_array_parameter(function: &mut Function) -> bool { + let mut parameters = function.parameters().iter(); + parameters.any(|parameter| function.dfg.type_of_value(*parameter).contains_an_array()) +} + +impl Context { + fn find_rcs_in_entry_block(&mut self, function: &Function) { + let entry = function.entry_block(); + + for instruction in function.dfg[entry].instructions() { + if let Instruction::IncrementRc { value } = &function.dfg[*instruction] { + let typ = function.dfg.type_of_value(*value); + + // We assume arrays aren't mutated until we find an array_set + let inc_rc = IncRc { id: *instruction, array: *value, possibly_mutated: false }; + self.inc_rcs.entry(typ).or_default().push(inc_rc); + } + } + } + + /// Find each array_set instruction in the function and mark any arrays used + /// by the inc_rc instructions as possibly mutated if they're the same type. + fn scan_for_array_sets(&mut self, function: &Function) { + for block in function.reachable_blocks() { + for instruction in function.dfg[block].instructions() { + if let Instruction::ArraySet { array, .. } = function.dfg[*instruction] { + let typ = function.dfg.type_of_value(array); + if let Some(inc_rcs) = self.inc_rcs.get_mut(&typ) { + for inc_rc in inc_rcs { + inc_rc.possibly_mutated = true; + } + } + } + } + } + } + + /// Find each dec_rc instruction and if the most recent inc_rc instruction for the same value + /// is not possibly mutated, then we can remove them both. Returns each such pair. + fn find_rcs_to_remove(&mut self, function: &Function) -> HashSet { + let last_block = Self::find_last_block(function); + let mut to_remove = HashSet::new(); + + for instruction in function.dfg[last_block].instructions() { + if let Instruction::DecrementRc { value } = &function.dfg[*instruction] { + if let Some(inc_rc) = self.pop_rc_for(*value, function) { + if !inc_rc.possibly_mutated { + to_remove.insert(inc_rc.id); + to_remove.insert(*instruction); + } + } + } + } + + to_remove + } + + /// Finds the block of the function with the Return instruction + fn find_last_block(function: &Function) -> BasicBlockId { + for block in function.reachable_blocks() { + if matches!( + function.dfg[block].terminator(), + Some(TerminatorInstruction::Return { .. }) + ) { + return block; + } + } + + unreachable!("SSA Function {} has no reachable return instruction!", function.id()) + } + + /// Finds and pops the IncRc for the given array value if possible. + fn pop_rc_for(&mut self, value: ValueId, function: &Function) -> Option { + let typ = function.dfg.type_of_value(value); + + let rcs = self.inc_rcs.get_mut(&typ)?; + let position = rcs.iter().position(|inc_rc| inc_rc.array == value)?; + + Some(rcs.remove(position)) + } +} + +fn remove_instructions(to_remove: HashSet, function: &mut Function) { + if !to_remove.is_empty() { + for block in function.reachable_blocks() { + function.dfg[block] + .instructions_mut() + .retain(|instruction| !to_remove.contains(instruction)); + } + } +} + +#[cfg(test)] +mod test { + use std::rc::Rc; + + use crate::ssa::{ + function_builder::FunctionBuilder, + ir::{ + basic_block::BasicBlockId, dfg::DataFlowGraph, function::RuntimeType, + instruction::Instruction, map::Id, types::Type, + }, + }; + + fn count_inc_rcs(block: BasicBlockId, dfg: &DataFlowGraph) -> usize { + dfg[block] + .instructions() + .iter() + .filter(|instruction_id| { + matches!(dfg[**instruction_id], Instruction::IncrementRc { .. }) + }) + .count() + } + + fn count_dec_rcs(block: BasicBlockId, dfg: &DataFlowGraph) -> usize { + dfg[block] + .instructions() + .iter() + .filter(|instruction_id| { + matches!(dfg[**instruction_id], Instruction::DecrementRc { .. }) + }) + .count() + } + + #[test] + fn single_block_fn_return_array() { + // This is the output for the program with a function: + // unconstrained fn foo(x: [Field; 2]) -> [[Field; 2]; 1] { + // [array] + // } + // + // fn foo { + // b0(v0: [Field; 2]): + // inc_rc v0 + // inc_rc v0 + // dec_rc v0 + // return [v0] + // } + let main_id = Id::test_new(0); + let mut builder = FunctionBuilder::new("foo".into(), main_id); + builder.set_runtime(RuntimeType::Brillig); + + let inner_array_type = Type::Array(Rc::new(vec![Type::field()]), 2); + let v0 = builder.add_parameter(inner_array_type.clone()); + + builder.insert_inc_rc(v0); + builder.insert_inc_rc(v0); + builder.insert_dec_rc(v0); + + let outer_array_type = Type::Array(Rc::new(vec![inner_array_type]), 1); + let array = builder.array_constant(vec![v0].into(), outer_array_type); + builder.terminate_with_return(vec![array]); + + let ssa = builder.finish().remove_paired_rc(); + let main = ssa.main(); + let entry = main.entry_block(); + + assert_eq!(count_inc_rcs(entry, &main.dfg), 1); + assert_eq!(count_dec_rcs(entry, &main.dfg), 0); + } + + #[test] + fn single_block_mutation() { + // fn mutator(mut array: [Field; 2]) { + // array[0] = 5; + // } + // + // fn mutator { + // b0(v0: [Field; 2]): + // v1 = allocate + // store v0 at v1 + // inc_rc v0 + // v2 = load v1 + // v7 = array_set v2, index u64 0, value Field 5 + // store v7 at v1 + // dec_rc v0 + // return + // } + let main_id = Id::test_new(0); + let mut builder = FunctionBuilder::new("mutator".into(), main_id); + + let array_type = Type::Array(Rc::new(vec![Type::field()]), 2); + let v0 = builder.add_parameter(array_type.clone()); + + let v1 = builder.insert_allocate(array_type.clone()); + builder.insert_store(v1, v0); + builder.insert_inc_rc(v0); + let v2 = builder.insert_load(v1, array_type); + + let zero = builder.numeric_constant(0u128, Type::unsigned(64)); + let five = builder.field_constant(5u128); + let v7 = builder.insert_array_set(v2, zero, five); + + builder.insert_store(v1, v7); + builder.insert_dec_rc(v0); + builder.terminate_with_return(vec![]); + + let ssa = builder.finish().remove_paired_rc(); + let main = ssa.main(); + let entry = main.entry_block(); + + // No changes, the array is possibly mutated + assert_eq!(count_inc_rcs(entry, &main.dfg), 1); + assert_eq!(count_dec_rcs(entry, &main.dfg), 1); + } + + // Similar to single_block_mutation but for a function which + // uses a mutable reference parameter. + #[test] + fn single_block_mutation_through_reference() { + // fn mutator2(array: &mut [Field; 2]) { + // array[0] = 5; + // } + // + // fn mutator2 { + // b0(v0: &mut [Field; 2]): + // v1 = load v0 + // inc_rc v1 + // store v1 at v0 + // v2 = load v0 + // v7 = array_set v2, index u64 0, value Field 5 + // store v7 at v0 + // v8 = load v0 + // dec_rc v8 + // store v8 at v0 + // return + // } + let main_id = Id::test_new(0); + let mut builder = FunctionBuilder::new("mutator2".into(), main_id); + + let array_type = Type::Array(Rc::new(vec![Type::field()]), 2); + let reference_type = Type::Reference(Rc::new(array_type.clone())); + + let v0 = builder.add_parameter(reference_type); + + let v1 = builder.insert_load(v0, array_type.clone()); + builder.insert_inc_rc(v1); + builder.insert_store(v0, v1); + + let v2 = builder.insert_load(v1, array_type.clone()); + let zero = builder.numeric_constant(0u128, Type::unsigned(64)); + let five = builder.field_constant(5u128); + let v7 = builder.insert_array_set(v2, zero, five); + + builder.insert_store(v0, v7); + let v8 = builder.insert_load(v0, array_type); + builder.insert_dec_rc(v8); + builder.insert_store(v0, v8); + builder.terminate_with_return(vec![]); + + let ssa = builder.finish().remove_paired_rc(); + let main = ssa.main(); + let entry = main.entry_block(); + + // No changes, the array is possibly mutated + assert_eq!(count_inc_rcs(entry, &main.dfg), 1); + assert_eq!(count_dec_rcs(entry, &main.dfg), 1); + } +} diff --git a/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs b/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs index a71a42d5757..1eb1e20d41d 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/remove_bit_shifts.rs @@ -20,7 +20,9 @@ impl Ssa { /// See [`constant_folding`][self] module for more information. #[tracing::instrument(level = "trace", skip(self))] pub(crate) fn remove_bit_shifts(mut self) -> Ssa { - remove_bit_shifts(self.main_mut()); + for function in self.functions.values_mut() { + remove_bit_shifts(function); + } self } } diff --git a/compiler/noirc_evaluator/src/ssa/opt/remove_enable_side_effects.rs b/compiler/noirc_evaluator/src/ssa/opt/remove_enable_side_effects.rs new file mode 100644 index 00000000000..8535dc2661f --- /dev/null +++ b/compiler/noirc_evaluator/src/ssa/opt/remove_enable_side_effects.rs @@ -0,0 +1,167 @@ +//! The goal of the "remove enable side effects" optimization pass is to delay any [Instruction::EnableSideEffects] +//! instructions such that they cover the minimum number of instructions possible. +//! +//! The pass works as follows: +//! - Insert instructions until an [Instruction::EnableSideEffects] is encountered, save this [InstructionId]. +//! - Continue inserting instructions until either +//! - Another [Instruction::EnableSideEffects] is encountered, if so then drop the previous [InstructionId] in favour +//! of this one. +//! - An [Instruction] with side-effects is encountered, if so then insert the currently saved [Instruction::EnableSideEffects] +//! before the [Instruction]. Continue inserting instructions until the next [Instruction::EnableSideEffects] is encountered. +use std::collections::HashSet; + +use acvm::FieldElement; + +use crate::ssa::{ + ir::{ + basic_block::BasicBlockId, + dfg::DataFlowGraph, + function::Function, + instruction::{BinaryOp, Instruction, Intrinsic}, + value::Value, + }, + ssa_gen::Ssa, +}; + +impl Ssa { + /// See [`remove_enable_side_effects`][self] module for more information. + #[tracing::instrument(level = "trace", skip(self))] + pub(crate) fn remove_enable_side_effects(mut self) -> Ssa { + for function in self.functions.values_mut() { + remove_enable_side_effects(function); + } + self + } +} + +fn remove_enable_side_effects(function: &mut Function) { + let mut context = Context::default(); + context.block_queue.push(function.entry_block()); + + while let Some(block) = context.block_queue.pop() { + if context.visited_blocks.contains(&block) { + continue; + } + + context.visited_blocks.insert(block); + context.remove_enable_side_effects_in_block(function, block); + } +} + +#[derive(Default)] +struct Context { + visited_blocks: HashSet, + block_queue: Vec, +} + +impl Context { + fn remove_enable_side_effects_in_block( + &mut self, + function: &mut Function, + block: BasicBlockId, + ) { + let instructions = function.dfg[block].take_instructions(); + + let mut last_side_effects_enabled_instruction = None; + + let mut new_instructions = Vec::with_capacity(instructions.len()); + for instruction_id in instructions { + let instruction = &function.dfg[instruction_id]; + + // If we run into another `Instruction::EnableSideEffects` before encountering any + // instructions with side effects then we can drop the instruction we're holding and + // continue with the new `Instruction::EnableSideEffects`. + if let Instruction::EnableSideEffects { condition } = instruction { + // If we're seeing an `enable_side_effects u1 1` then we want to insert it immediately. + // This is because we want to maximize the effect it will have. + if function + .dfg + .get_numeric_constant(*condition) + .map_or(false, |condition| condition.is_one()) + { + new_instructions.push(instruction_id); + last_side_effects_enabled_instruction = None; + continue; + } + + last_side_effects_enabled_instruction = Some(instruction_id); + continue; + } + + // If we hit an instruction which is affected by the side effects var then we must insert the + // `Instruction::EnableSideEffects` before we insert this new instruction. + if Self::responds_to_side_effects_var(&function.dfg, instruction) { + if let Some(enable_side_effects_instruction_id) = + last_side_effects_enabled_instruction.take() + { + new_instructions.push(enable_side_effects_instruction_id); + } + } + new_instructions.push(instruction_id); + } + + *function.dfg[block].instructions_mut() = new_instructions; + + self.block_queue.extend(function.dfg[block].successors()); + } + + fn responds_to_side_effects_var(dfg: &DataFlowGraph, instruction: &Instruction) -> bool { + use Instruction::*; + match instruction { + Binary(binary) => { + if matches!(binary.operator, BinaryOp::Div | BinaryOp::Mod) { + if let Some(rhs) = dfg.get_numeric_constant(binary.rhs) { + rhs == FieldElement::zero() + } else { + true + } + } else { + false + } + } + + Cast(_, _) + | Not(_) + | Truncate { .. } + | Constrain(..) + | RangeCheck { .. } + | IncrementRc { .. } + | DecrementRc { .. } => false, + + EnableSideEffects { .. } + | ArrayGet { .. } + | ArraySet { .. } + | Allocate + | Store { .. } + | Load { .. } => true, + + // Some `Intrinsic`s have side effects so we must check what kind of `Call` this is. + Call { func, .. } => match dfg[*func] { + Value::Intrinsic(intrinsic) => match intrinsic { + Intrinsic::SlicePushBack + | Intrinsic::SlicePushFront + | Intrinsic::SlicePopBack + | Intrinsic::SlicePopFront + | Intrinsic::SliceInsert + | Intrinsic::SliceRemove => true, + + Intrinsic::ArrayLen + | Intrinsic::AssertConstant + | Intrinsic::ApplyRangeConstraint + | Intrinsic::StrAsBytes + | Intrinsic::ToBits(_) + | Intrinsic::ToRadix(_) + | Intrinsic::BlackBox(_) + | Intrinsic::FromField + | Intrinsic::AsField + | Intrinsic::AsSlice => false, + }, + + // We must assume that functions contain a side effect as we cannot inspect more deeply. + Value::Function(_) => true, + + _ => false, + }, + } + } +} diff --git a/compiler/noirc_evaluator/src/ssa/opt/simplify_cfg.rs b/compiler/noirc_evaluator/src/ssa/opt/simplify_cfg.rs index a31def8fd98..f524b10f1f2 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/simplify_cfg.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/simplify_cfg.rs @@ -154,7 +154,6 @@ mod test { use crate::ssa::{ function_builder::FunctionBuilder, ir::{ - function::RuntimeType, instruction::{BinaryOp, TerminatorInstruction}, map::Id, types::Type, @@ -172,7 +171,7 @@ mod test { // return v1 // } let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let b1 = builder.insert_block(); let b2 = builder.insert_block(); @@ -228,7 +227,7 @@ mod test { // return Field 2 // } let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let v0 = builder.add_parameter(Type::bool()); let b1 = builder.insert_block(); diff --git a/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs b/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs index 645adb6b350..8110e3469f1 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs @@ -48,7 +48,7 @@ impl Ssa { // This check is always true with the addition of the above guard, but I'm // keeping it in case the guard on brillig functions is ever removed. - let abort_on_error = function.runtime() == RuntimeType::Acir; + let abort_on_error = matches!(function.runtime(), RuntimeType::Acir(_)); find_all_loops(function).unroll_each_loop(function, abort_on_error)?; } Ok(self) @@ -464,7 +464,7 @@ impl<'f> LoopIteration<'f> { mod tests { use crate::ssa::{ function_builder::FunctionBuilder, - ir::{function::RuntimeType, instruction::BinaryOp, map::Id, types::Type}, + ir::{instruction::BinaryOp, map::Id, types::Type}, }; #[test] @@ -503,7 +503,7 @@ mod tests { let main_id = Id::test_new(0); // Compiling main - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let b1 = builder.insert_block(); let b2 = builder.insert_block(); @@ -605,7 +605,7 @@ mod tests { // return Field 0 // } let main_id = Id::test_new(0); - let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir); + let mut builder = FunctionBuilder::new("main".into(), main_id); let b1 = builder.insert_block(); let b2 = builder.insert_block(); diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs index 9c760c013a9..569e543ce40 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs @@ -10,9 +10,10 @@ use noirc_frontend::{BinaryOpKind, Signedness}; use crate::errors::RuntimeError; use crate::ssa::function_builder::FunctionBuilder; +use crate::ssa::ir::basic_block::BasicBlockId; use crate::ssa::ir::dfg::DataFlowGraph; -use crate::ssa::ir::function::FunctionId as IrFunctionId; use crate::ssa::ir::function::{Function, RuntimeType}; +use crate::ssa::ir::function::{FunctionId as IrFunctionId, InlineType}; use crate::ssa::ir::instruction::BinaryOp; use crate::ssa::ir::instruction::Instruction; use crate::ssa::ir::map::AtomicCounter; @@ -38,6 +39,11 @@ pub(super) struct FunctionContext<'a> { pub(super) builder: FunctionBuilder, shared_context: &'a SharedContext, + + /// Contains any loops we're currently in the middle of translating. + /// These are ordered such that an inner loop is at the end of the vector and + /// outer loops are at the beginning. When a loop is finished, it is popped. + loops: Vec, } /// Shared context for all functions during ssa codegen. This is the only @@ -71,6 +77,13 @@ pub(super) struct SharedContext { pub(super) program: Program, } +#[derive(Copy, Clone)] +pub(super) struct Loop { + pub(super) loop_entry: BasicBlockId, + pub(super) loop_index: ValueId, + pub(super) loop_end: BasicBlockId, +} + /// The queue of functions remaining to compile type FunctionQueue = Vec<(ast::FuncId, IrFunctionId)>; @@ -95,8 +108,10 @@ impl<'a> FunctionContext<'a> { .expect("No function in queue for the FunctionContext to compile") .1; - let builder = FunctionBuilder::new(function_name, function_id, runtime); - let mut this = Self { definitions: HashMap::default(), builder, shared_context }; + let mut builder = FunctionBuilder::new(function_name, function_id); + builder.set_runtime(runtime); + let definitions = HashMap::default(); + let mut this = Self { definitions, builder, shared_context, loops: Vec::new() }; this.add_parameters_to_scope(parameters); this } @@ -111,7 +126,8 @@ impl<'a> FunctionContext<'a> { if func.unconstrained { self.builder.new_brillig_function(func.name.clone(), id); } else { - self.builder.new_function(func.name.clone(), id); + let inline_type = if func.should_fold { InlineType::Fold } else { InlineType::Inline }; + self.builder.new_function(func.name.clone(), id, inline_type); } self.add_parameters_to_scope(&func.parameters); } @@ -1022,6 +1038,54 @@ impl<'a> FunctionContext<'a> { } } } + + /// Increments the reference count of all parameters. Returns the entry block of the function. + /// + /// This is done on parameters rather than call arguments so that we can optimize out + /// paired inc/dec instructions within brillig functions more easily. + pub(crate) fn increment_parameter_rcs(&mut self) -> BasicBlockId { + let entry = self.builder.current_function.entry_block(); + let parameters = self.builder.current_function.dfg.block_parameters(entry).to_vec(); + + for parameter in parameters { + self.builder.increment_array_reference_count(parameter); + } + + entry + } + + /// Ends a local scope of a function. + /// This will issue DecrementRc instructions for any arrays in the given starting scope + /// block's parameters. Arrays that are also used in terminator instructions for the scope are + /// ignored. + pub(crate) fn end_scope(&mut self, scope: BasicBlockId, terminator_args: &[ValueId]) { + let mut dropped_parameters = + self.builder.current_function.dfg.block_parameters(scope).to_vec(); + + dropped_parameters.retain(|parameter| !terminator_args.contains(parameter)); + + for parameter in dropped_parameters { + self.builder.decrement_array_reference_count(parameter); + } + } + + pub(crate) fn enter_loop( + &mut self, + loop_entry: BasicBlockId, + loop_index: ValueId, + loop_end: BasicBlockId, + ) { + self.loops.push(Loop { loop_entry, loop_index, loop_end }); + } + + pub(crate) fn exit_loop(&mut self) { + self.loops.pop(); + } + + pub(crate) fn current_loop(&self) -> Loop { + // The frontend should ensure break/continue are never used outside a loop + *self.loops.last().expect("current_loop: not in a loop!") + } } /// True if the given operator cannot be encoded directly and needs diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs index d95295ae3c9..3fe52f7f0e5 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs @@ -14,7 +14,10 @@ use noirc_frontend::{ use crate::{ errors::{InternalError, RuntimeError}, - ssa::{function_builder::data_bus::DataBusBuilder, ir::instruction::Intrinsic}, + ssa::{ + function_builder::data_bus::DataBusBuilder, + ir::{function::InlineType, instruction::Intrinsic}, + }, }; use self::{ @@ -52,14 +55,15 @@ pub(crate) fn generate_ssa( // Queue the main function for compilation context.get_or_queue_function(main_id); - let mut function_context = FunctionContext::new( main.name.clone(), &main.parameters, if force_brillig_runtime || main.unconstrained { RuntimeType::Brillig } else { - RuntimeType::Acir + let main_inline_type = + if main.should_fold { InlineType::Fold } else { InlineType::Inline }; + RuntimeType::Acir(main_inline_type) }, &context, ); @@ -121,8 +125,11 @@ impl<'a> FunctionContext<'a> { /// Codegen a function's body and set its return value to that of its last parameter. /// For functions returning nothing, this will be an empty list. fn codegen_function_body(&mut self, body: &Expression) -> Result<(), RuntimeError> { + let entry_block = self.increment_parameter_rcs(); let return_value = self.codegen_expression(body)?; let results = return_value.into_value_list(self); + self.end_scope(entry_block, &results); + self.builder.terminate_with_return(results); Ok(()) } @@ -149,6 +156,8 @@ impl<'a> FunctionContext<'a> { } Expression::Assign(assign) => self.codegen_assign(assign), Expression::Semi(semi) => self.codegen_semi(semi), + Expression::Break => Ok(self.codegen_break()), + Expression::Continue => Ok(self.codegen_continue()), } } @@ -194,6 +203,15 @@ impl<'a> FunctionContext<'a> { ast::Type::Array(_, _) => { self.codegen_array_checked(elements, typ[0].clone())? } + _ => unreachable!("ICE: unexpected array literal type, got {}", array.typ), + }) + } + ast::Literal::Slice(array) => { + let elements = + try_vecmap(&array.contents, |element| self.codegen_expression(element))?; + + let typ = Self::convert_type(&array.typ).flatten(); + Ok(match array.typ { ast::Type::Slice(_) => { let slice_length = self.builder.length_constant(array.contents.len() as u128); @@ -201,10 +219,7 @@ impl<'a> FunctionContext<'a> { self.codegen_array_checked(elements, typ[1].clone())?; Tree::Branch(vec![slice_length.into(), slice_contents]) } - _ => unreachable!( - "ICE: array literal type must be an array or a slice, but got {}", - array.typ - ), + _ => unreachable!("ICE: unexpected slice literal type, got {}", array.typ), }) } ast::Literal::Integer(value, typ, location) => { @@ -474,6 +489,10 @@ impl<'a> FunctionContext<'a> { let index_type = Self::convert_non_tuple_type(&for_expr.index_type); let loop_index = self.builder.add_block_parameter(loop_entry, index_type); + // Remember the blocks and variable used in case there are break/continue instructions + // within the loop which need to jump to them. + self.enter_loop(loop_entry, loop_index, loop_end); + self.builder.set_location(for_expr.start_range_location); let start_index = self.codegen_non_tuple_expression(&for_expr.start_range)?; @@ -504,6 +523,7 @@ impl<'a> FunctionContext<'a> { // Finish by switching back to the end of the loop self.builder.switch_to_block(loop_end); + self.exit_loop(); Ok(Self::unit_value()) } @@ -595,10 +615,8 @@ impl<'a> FunctionContext<'a> { arguments.append(&mut values); } - // If an array is passed as an argument we increase its reference count - for argument in &arguments { - self.builder.increment_array_reference_count(*argument); - } + // Don't need to increment array reference counts when passed in as arguments + // since it is done within the function to each parameter already. self.codegen_intrinsic_call_checks(function, &arguments, call.location); Ok(self.insert_call(function, arguments, &call.return_type, call.location)) @@ -722,6 +740,11 @@ impl<'a> FunctionContext<'a> { let lhs = self.extract_current_value(&assign.lvalue)?; let rhs = self.codegen_expression(&assign.expression)?; + rhs.clone().for_each(|value| { + let value = value.eval(self); + self.builder.increment_array_reference_count(value); + }); + self.assign_new_value(lhs, rhs); Ok(Self::unit_value()) } @@ -730,4 +753,19 @@ impl<'a> FunctionContext<'a> { self.codegen_expression(expr)?; Ok(Self::unit_value()) } + + fn codegen_break(&mut self) -> Values { + let loop_end = self.current_loop().loop_end; + self.builder.terminate_with_jmp(loop_end, Vec::new()); + Self::unit_value() + } + + fn codegen_continue(&mut self) -> Values { + let loop_ = self.current_loop(); + + // Must remember to increment i before jumping + let new_loop_index = self.make_offset(loop_.loop_index, 1); + self.builder.terminate_with_jmp(loop_.loop_entry, vec![new_loop_index]); + Self::unit_value() + } } diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/program.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/program.rs index 509f778f3b0..9995c031145 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/program.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/program.rs @@ -12,6 +12,7 @@ pub(crate) struct Ssa { pub(crate) functions: BTreeMap, pub(crate) main_id: FunctionId, pub(crate) next_id: AtomicCounter, + pub(crate) id_to_index: BTreeMap, } impl Ssa { @@ -26,7 +27,9 @@ impl Ssa { (f.id(), f) }); - Self { functions, main_id, next_id: AtomicCounter::starting_after(max_id) } + let id_to_index = btree_map(functions.iter().enumerate(), |(i, (id, _))| (*id, i as u32)); + + Self { functions, main_id, next_id: AtomicCounter::starting_after(max_id), id_to_index } } /// Returns the entry-point function of the program diff --git a/compiler/noirc_frontend/Cargo.toml b/compiler/noirc_frontend/Cargo.toml index a3a8d460572..03b92e15032 100644 --- a/compiler/noirc_frontend/Cargo.toml +++ b/compiler/noirc_frontend/Cargo.toml @@ -26,6 +26,7 @@ tracing.workspace = true petgraph = "0.6" [dev-dependencies] +base64.workspace = true strum = "0.24" strum_macros = "0.24" tempfile.workspace = true diff --git a/compiler/noirc_frontend/src/ast/expression.rs b/compiler/noirc_frontend/src/ast/expression.rs index 2a252633a29..0e5919bf7db 100644 --- a/compiler/noirc_frontend/src/ast/expression.rs +++ b/compiler/noirc_frontend/src/ast/expression.rs @@ -3,7 +3,7 @@ use std::fmt::Display; use crate::token::{Attributes, Token}; use crate::{ - Distinctness, FunctionVisibility, Ident, Path, Pattern, Recoverable, Statement, StatementKind, + Distinctness, Ident, ItemVisibility, Path, Pattern, Recoverable, Statement, StatementKind, UnresolvedTraitConstraint, UnresolvedType, UnresolvedTypeData, Visibility, }; use acvm::FieldElement; @@ -27,6 +27,7 @@ pub enum ExpressionKind { Tuple(Vec), Lambda(Box), Parenthesized(Box), + Quote(BlockExpression), Error, } @@ -70,6 +71,17 @@ impl ExpressionKind { })) } + pub fn slice(contents: Vec) -> ExpressionKind { + ExpressionKind::Literal(Literal::Slice(ArrayLiteral::Standard(contents))) + } + + pub fn repeated_slice(repeated_element: Expression, length: Expression) -> ExpressionKind { + ExpressionKind::Literal(Literal::Slice(ArrayLiteral::Repeated { + repeated_element: Box::new(repeated_element), + length: Box::new(length), + })) + } + pub fn integer(contents: FieldElement) -> ExpressionKind { ExpressionKind::Literal(Literal::Integer(contents, false)) } @@ -180,16 +192,18 @@ impl Expression { // with tuples without calling them. E.g. `if c { t } else { e }(a, b)` is interpreted // as a sequence of { if, tuple } rather than a function call. This behavior matches rust. let kind = if matches!(&lhs.kind, ExpressionKind::If(..)) { - ExpressionKind::Block(BlockExpression(vec![ - Statement { kind: StatementKind::Expression(lhs), span }, - Statement { - kind: StatementKind::Expression(Expression::new( - ExpressionKind::Tuple(arguments), + ExpressionKind::Block(BlockExpression { + statements: vec![ + Statement { kind: StatementKind::Expression(lhs), span }, + Statement { + kind: StatementKind::Expression(Expression::new( + ExpressionKind::Tuple(arguments), + span, + )), span, - )), - span, - }, - ])) + }, + ], + }) } else { ExpressionKind::Call(Box::new(CallExpression { func: Box::new(lhs), arguments })) }; @@ -319,6 +333,7 @@ impl UnaryOp { #[derive(Debug, PartialEq, Eq, Clone)] pub enum Literal { Array(ArrayLiteral), + Slice(ArrayLiteral), Bool(bool), Integer(FieldElement, /*sign*/ bool), // false for positive integer and true for negative Str(String), @@ -369,16 +384,11 @@ pub struct FunctionDefinition { // and `secondary` attributes (ones that do not change the function kind) pub attributes: Attributes, - /// True if this function was defined with the 'open' keyword - pub is_open: bool, - - pub is_internal: bool, - /// True if this function was defined with the 'unconstrained' keyword pub is_unconstrained: bool, /// Indicate if this function was defined with the 'pub' keyword - pub visibility: FunctionVisibility, + pub visibility: ItemVisibility, pub generics: UnresolvedGenerics, pub parameters: Vec, @@ -406,18 +416,6 @@ pub enum FunctionReturnType { Ty(UnresolvedType), } -/// Describes the types of smart contract functions that are allowed. -/// - All Noir programs in the non-contract context can be seen as `Secret`. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum ContractFunctionType { - /// This function will be executed in a private - /// context. - Secret, - /// This function will be executed in a public - /// context. - Open, -} - #[derive(Debug, PartialEq, Eq, Clone)] pub enum ArrayLiteral { Standard(Vec), @@ -456,19 +454,21 @@ pub struct IndexExpression { } #[derive(Debug, PartialEq, Eq, Clone)] -pub struct BlockExpression(pub Vec); +pub struct BlockExpression { + pub statements: Vec, +} impl BlockExpression { pub fn pop(&mut self) -> Option { - self.0.pop().map(|stmt| stmt.kind) + self.statements.pop().map(|stmt| stmt.kind) } pub fn len(&self) -> usize { - self.0.len() + self.statements.len() } pub fn is_empty(&self) -> bool { - self.0.is_empty() + self.statements.is_empty() } } @@ -500,6 +500,7 @@ impl Display for ExpressionKind { } Lambda(lambda) => lambda.fmt(f), Parenthesized(sub_expr) => write!(f, "({sub_expr})"), + Quote(block) => write!(f, "quote {block}"), Error => write!(f, "Error"), } } @@ -515,6 +516,13 @@ impl Display for Literal { Literal::Array(ArrayLiteral::Repeated { repeated_element, length }) => { write!(f, "[{repeated_element}; {length}]") } + Literal::Slice(ArrayLiteral::Standard(elements)) => { + let contents = vecmap(elements, ToString::to_string); + write!(f, "&[{}]", contents.join(", ")) + } + Literal::Slice(ArrayLiteral::Repeated { repeated_element, length }) => { + write!(f, "&[{repeated_element}; {length}]") + } Literal::Bool(boolean) => write!(f, "{}", if *boolean { "true" } else { "false" }), Literal::Integer(integer, sign) => { if *sign { @@ -538,7 +546,7 @@ impl Display for Literal { impl Display for BlockExpression { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!(f, "{{")?; - for statement in &self.0 { + for statement in &self.statements { let statement = statement.kind.to_string(); for line in statement.lines() { writeln!(f, " {line}")?; @@ -674,10 +682,8 @@ impl FunctionDefinition { FunctionDefinition { name: name.clone(), attributes: Attributes::empty(), - is_open: false, - is_internal: false, is_unconstrained: false, - visibility: FunctionVisibility::Private, + visibility: ItemVisibility::Private, generics: generics.clone(), parameters: p, body: body.clone(), diff --git a/compiler/noirc_frontend/src/ast/function.rs b/compiler/noirc_frontend/src/ast/function.rs index 46f0ac0fa0f..10d962a23f7 100644 --- a/compiler/noirc_frontend/src/ast/function.rs +++ b/compiler/noirc_frontend/src/ast/function.rs @@ -83,7 +83,7 @@ impl NoirFunction { &mut self.def } pub fn number_of_statements(&self) -> usize { - self.def.body.0.len() + self.def.body.statements.len() } pub fn span(&self) -> Span { self.def.span @@ -108,6 +108,7 @@ impl From for NoirFunction { Some(FunctionAttribute::Test { .. }) => FunctionKind::Normal, Some(FunctionAttribute::Oracle(_)) => FunctionKind::Oracle, Some(FunctionAttribute::Recursive) => FunctionKind::Recursive, + Some(FunctionAttribute::Fold) => FunctionKind::Normal, None => FunctionKind::Normal, }; diff --git a/compiler/noirc_frontend/src/ast/mod.rs b/compiler/noirc_frontend/src/ast/mod.rs index 29edbaca594..4547dc2a176 100644 --- a/compiler/noirc_frontend/src/ast/mod.rs +++ b/compiler/noirc_frontend/src/ast/mod.rs @@ -83,7 +83,8 @@ impl core::fmt::Display for IntegerBitSize { #[derive(Debug, PartialEq, Eq, Clone, Hash)] pub enum UnresolvedTypeData { FieldElement, - Array(Option, Box), // [4]Witness = Array(4, Witness) + Array(UnresolvedTypeExpression, Box), // [Field; 4] = Array(4, Field) + Slice(Box), Integer(Signedness, IntegerBitSize), // u32 = Integer(unsigned, ThirtyTwo) Bool, Expression(UnresolvedTypeExpression), @@ -151,10 +152,8 @@ impl std::fmt::Display for UnresolvedTypeData { use UnresolvedTypeData::*; match self { FieldElement => write!(f, "Field"), - Array(len, typ) => match len { - None => write!(f, "[{typ}]"), - Some(len) => write!(f, "[{typ}; {len}]"), - }, + Array(len, typ) => write!(f, "[{typ}; {len}]"), + Slice(typ) => write!(f, "[{typ}]"), Integer(sign, num_bits) => match sign { Signedness::Signed => write!(f, "i{num_bits}"), Signedness::Unsigned => write!(f, "u{num_bits}"), @@ -354,8 +353,8 @@ impl UnresolvedTypeExpression { } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -/// Represents whether the function can be called outside its module/crate -pub enum FunctionVisibility { +/// Represents whether the definition can be referenced outside its module/crate +pub enum ItemVisibility { Public, Private, PublicCrate, diff --git a/compiler/noirc_frontend/src/ast/statement.rs b/compiler/noirc_frontend/src/ast/statement.rs index f39b71405d3..dea9fc0f3d3 100644 --- a/compiler/noirc_frontend/src/ast/statement.rs +++ b/compiler/noirc_frontend/src/ast/statement.rs @@ -35,6 +35,8 @@ pub enum StatementKind { Expression(Expression), Assign(AssignStatement), For(ForLoopStatement), + Break, + Continue, // This is an expression with a trailing semi-colon Semi(Expression), // This statement is the result of a recovered parse error. @@ -59,6 +61,8 @@ impl Statement { | StatementKind::Constrain(_) | StatementKind::Assign(_) | StatementKind::Semi(_) + | StatementKind::Break + | StatementKind::Continue | StatementKind::Error => { // To match rust, statements always require a semicolon, even at the end of a block if semi.is_none() { @@ -116,7 +120,7 @@ impl StatementKind { // Desugar `a = b` to `a = a b`. This relies on the evaluation of `a` having no side effects, // which is currently enforced by the restricted syntax of LValues. if operator != Token::Assign { - let lvalue_expr = lvalue.as_expression(span); + let lvalue_expr = lvalue.as_expression(); let error_msg = "Token passed to Statement::assign is not a binary operator"; let infix = crate::InfixExpression { @@ -240,6 +244,17 @@ pub trait Recoverable { fn error(span: Span) -> Self; } +#[derive(Debug, PartialEq, Eq, Clone)] +pub struct ModuleDeclaration { + pub ident: Ident, +} + +impl std::fmt::Display for ModuleDeclaration { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "mod {}", self.ident) + } +} + #[derive(Debug, PartialEq, Eq, Clone)] pub struct ImportStatement { pub path: Path, @@ -410,9 +425,9 @@ pub struct AssignStatement { #[derive(Debug, PartialEq, Eq, Clone)] pub enum LValue { Ident(Ident), - MemberAccess { object: Box, field_name: Ident }, - Index { array: Box, index: Expression }, - Dereference(Box), + MemberAccess { object: Box, field_name: Ident, span: Span }, + Index { array: Box, index: Expression, span: Span }, + Dereference(Box, Span), } #[derive(Debug, PartialEq, Eq, Clone)] @@ -469,28 +484,40 @@ impl Recoverable for Pattern { } impl LValue { - fn as_expression(&self, span: Span) -> Expression { + fn as_expression(&self) -> Expression { let kind = match self { LValue::Ident(ident) => ExpressionKind::Variable(Path::from_ident(ident.clone())), - LValue::MemberAccess { object, field_name } => { + LValue::MemberAccess { object, field_name, span: _ } => { ExpressionKind::MemberAccess(Box::new(MemberAccessExpression { - lhs: object.as_expression(span), + lhs: object.as_expression(), rhs: field_name.clone(), })) } - LValue::Index { array, index } => ExpressionKind::Index(Box::new(IndexExpression { - collection: array.as_expression(span), - index: index.clone(), - })), - LValue::Dereference(lvalue) => { + LValue::Index { array, index, span: _ } => { + ExpressionKind::Index(Box::new(IndexExpression { + collection: array.as_expression(), + index: index.clone(), + })) + } + LValue::Dereference(lvalue, _span) => { ExpressionKind::Prefix(Box::new(crate::PrefixExpression { operator: crate::UnaryOp::Dereference { implicitly_added: false }, - rhs: lvalue.as_expression(span), + rhs: lvalue.as_expression(), })) } }; + let span = self.span(); Expression::new(kind, span) } + + pub fn span(&self) -> Span { + match self { + LValue::Ident(ident) => ident.span(), + LValue::MemberAccess { span, .. } + | LValue::Index { span, .. } + | LValue::Dereference(_, span) => *span, + } + } } #[derive(Debug, PartialEq, Eq, Clone)] @@ -588,10 +615,12 @@ impl ForRange { }; let block_span = block.span; - let new_block = BlockExpression(vec![ - let_elem, - Statement { kind: StatementKind::Expression(block), span: block_span }, - ]); + let new_block = BlockExpression { + statements: vec![ + let_elem, + Statement { kind: StatementKind::Expression(block), span: block_span }, + ], + }; let new_block = Expression::new(ExpressionKind::Block(new_block), block_span); let for_loop = Statement { kind: StatementKind::For(ForLoopStatement { @@ -603,7 +632,9 @@ impl ForRange { span: for_loop_span, }; - let block = ExpressionKind::Block(BlockExpression(vec![let_array, for_loop])); + let block = ExpressionKind::Block(BlockExpression { + statements: vec![let_array, for_loop], + }); StatementKind::Expression(Expression::new(block, for_loop_span)) } } @@ -626,6 +657,8 @@ impl Display for StatementKind { StatementKind::Expression(expression) => expression.fmt(f), StatementKind::Assign(assign) => assign.fmt(f), StatementKind::For(for_loop) => for_loop.fmt(f), + StatementKind::Break => write!(f, "break"), + StatementKind::Continue => write!(f, "continue"), StatementKind::Semi(semi) => write!(f, "{semi};"), StatementKind::Error => write!(f, "Error"), } @@ -654,9 +687,11 @@ impl Display for LValue { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { LValue::Ident(ident) => ident.fmt(f), - LValue::MemberAccess { object, field_name } => write!(f, "{object}.{field_name}"), - LValue::Index { array, index } => write!(f, "{array}[{index}]"), - LValue::Dereference(lvalue) => write!(f, "*{lvalue}"), + LValue::MemberAccess { object, field_name, span: _ } => { + write!(f, "{object}.{field_name}") + } + LValue::Index { array, index, span: _ } => write!(f, "{array}[{index}]"), + LValue::Dereference(lvalue, _span) => write!(f, "*{lvalue}"), } } } diff --git a/compiler/noirc_frontend/src/debug/mod.rs b/compiler/noirc_frontend/src/debug/mod.rs index a88567fcaf9..71e0d44b478 100644 --- a/compiler/noirc_frontend/src/debug/mod.rs +++ b/compiler/noirc_frontend/src/debug/mod.rs @@ -4,9 +4,11 @@ use crate::{ ast::{Path, PathKind}, parser::{Item, ItemKind}, }; +use noirc_errors::debug_info::{DebugFnId, DebugFunction}; use noirc_errors::{Span, Spanned}; use std::collections::HashMap; use std::collections::VecDeque; +use std::mem::take; const MAX_MEMBER_ASSIGN_DEPTH: usize = 8; @@ -26,8 +28,12 @@ pub struct DebugInstrumenter { // all field names referenced when assigning to a member of a variable pub field_names: HashMap, + // all collected function metadata (name + argument names) + pub functions: HashMap, + next_var_id: u32, next_field_name_id: u32, + next_fn_id: u32, // last seen variable names and their IDs grouped by scope scope: Vec>, @@ -38,9 +44,11 @@ impl Default for DebugInstrumenter { Self { variables: HashMap::default(), field_names: HashMap::default(), + functions: HashMap::default(), scope: vec![], next_var_id: 0, next_field_name_id: 1, + next_fn_id: 0, } } } @@ -76,10 +84,22 @@ impl DebugInstrumenter { field_name_id } + fn insert_function(&mut self, fn_name: String, arguments: Vec) -> DebugFnId { + let fn_id = DebugFnId(self.next_fn_id); + self.next_fn_id += 1; + self.functions.insert(fn_id, DebugFunction { name: fn_name, arg_names: arguments }); + fn_id + } + fn walk_fn(&mut self, func: &mut ast::FunctionDefinition) { + let func_name = func.name.0.contents.clone(); + let func_args = + func.parameters.iter().map(|param| pattern_to_string(¶m.pattern)).collect(); + let fn_id = self.insert_function(func_name, func_args); + let enter_stmt = build_debug_call_stmt("enter", fn_id, func.span); self.scope.push(HashMap::default()); - let set_fn_params = func + let set_fn_params: Vec<_> = func .parameters .iter() .flat_map(|param| { @@ -93,10 +113,21 @@ impl DebugInstrumenter { }) .collect(); - self.walk_scope(&mut func.body.0, func.span); + let func_body = &mut func.body.statements; + let mut statements = take(func_body); + + self.walk_scope(&mut statements, func.span); + + // walk_scope ensures that the last statement is the return value of the function + let last_stmt = statements.pop().expect("at least one statement after walk_scope"); + let exit_stmt = build_debug_call_stmt("exit", fn_id, last_stmt.span); - // prepend fn params: - func.body.0 = [set_fn_params, func.body.0.clone()].concat(); + // rebuild function body + func_body.push(enter_stmt); + func_body.extend(set_fn_params); + func_body.extend(statements); + func_body.push(exit_stmt); + func_body.push(last_stmt); } // Modify a vector of statements in-place, adding instrumentation for sets and drops. @@ -212,7 +243,9 @@ impl DebugInstrumenter { pattern: ast::Pattern::Tuple(vars_pattern, let_stmt.pattern.span()), r#type: ast::UnresolvedType::unspecified(), expression: ast::Expression { - kind: ast::ExpressionKind::Block(ast::BlockExpression(block_stmts)), + kind: ast::ExpressionKind::Block(ast::BlockExpression { + statements: block_stmts, + }), span: let_stmt.expression.span, }, }), @@ -249,7 +282,7 @@ impl DebugInstrumenter { .unwrap_or_else(|| panic!("var lookup failed for var_name={}", &id.0.contents)); build_assign_var_stmt(var_id, id_expr(&ident("__debug_expr", id.span()))) } - ast::LValue::Dereference(_lv) => { + ast::LValue::Dereference(_lv, span) => { // TODO: this is a dummy statement for now, but we should // somehow track the derefence and update the pointed to // variable @@ -270,16 +303,16 @@ impl DebugInstrumenter { }); break; } - ast::LValue::MemberAccess { object, field_name } => { + ast::LValue::MemberAccess { object, field_name, span } => { cursor = object; let field_name_id = self.insert_field_name(&field_name.0.contents); - indexes.push(sint_expr(-(field_name_id.0 as i128), expression_span)); + indexes.push(sint_expr(-(field_name_id.0 as i128), *span)); } - ast::LValue::Index { index, array } => { + ast::LValue::Index { index, array, span: _ } => { cursor = array; indexes.push(index.clone()); } - ast::LValue::Dereference(_ref) => { + ast::LValue::Dereference(_ref, _span) => { unimplemented![] } } @@ -299,11 +332,13 @@ impl DebugInstrumenter { kind: ast::StatementKind::Assign(ast::AssignStatement { lvalue: assign_stmt.lvalue.clone(), expression: ast::Expression { - kind: ast::ExpressionKind::Block(ast::BlockExpression(vec![ - ast::Statement { kind: let_kind, span: expression_span }, - new_assign_stmt, - ast::Statement { kind: ret_kind, span: expression_span }, - ])), + kind: ast::ExpressionKind::Block(ast::BlockExpression { + statements: vec![ + ast::Statement { kind: let_kind, span: expression_span }, + new_assign_stmt, + ast::Statement { kind: ret_kind, span: expression_span }, + ], + }), span: expression_span, }, }), @@ -313,7 +348,7 @@ impl DebugInstrumenter { fn walk_expr(&mut self, expr: &mut ast::Expression) { match &mut expr.kind { - ast::ExpressionKind::Block(ast::BlockExpression(ref mut statements)) => { + ast::ExpressionKind::Block(ast::BlockExpression { ref mut statements, .. }) => { self.scope.push(HashMap::default()); self.walk_scope(statements, expr.span); } @@ -384,14 +419,16 @@ impl DebugInstrumenter { self.walk_expr(&mut for_stmt.block); for_stmt.block = ast::Expression { - kind: ast::ExpressionKind::Block(ast::BlockExpression(vec![ - set_stmt, - ast::Statement { - kind: ast::StatementKind::Semi(for_stmt.block.clone()), - span: for_stmt.block.span, - }, - drop_stmt, - ])), + kind: ast::ExpressionKind::Block(ast::BlockExpression { + statements: vec![ + set_stmt, + ast::Statement { + kind: ast::StatementKind::Semi(for_stmt.block.clone()), + span: for_stmt.block.span, + }, + drop_stmt, + ], + }), span: for_stmt.span, }; } @@ -427,6 +464,8 @@ impl DebugInstrumenter { use dep::__debug::{{ __debug_var_assign, __debug_var_drop, + __debug_fn_enter, + __debug_fn_exit, __debug_dereference_assign, {member_assigns}, }};"# @@ -451,14 +490,32 @@ pub fn build_debug_crate_file() -> String { } #[oracle(__debug_var_drop)] - unconstrained fn __debug_var_drop_oracle(_var_id: u32) {} - unconstrained fn __debug_var_drop_inner(var_id: u32) { + unconstrained fn __debug_var_drop_oracle(_var_id: u32) {} + unconstrained fn __debug_var_drop_inner(var_id: u32) { __debug_var_drop_oracle(var_id); } - pub fn __debug_var_drop(var_id: u32) { + pub fn __debug_var_drop(var_id: u32) { __debug_var_drop_inner(var_id); } + #[oracle(__debug_fn_enter)] + unconstrained fn __debug_fn_enter_oracle(_fn_id: u32) {} + unconstrained fn __debug_fn_enter_inner(fn_id: u32) { + __debug_fn_enter_oracle(fn_id); + } + pub fn __debug_fn_enter(fn_id: u32) { + __debug_fn_enter_inner(fn_id); + } + + #[oracle(__debug_fn_exit)] + unconstrained fn __debug_fn_exit_oracle(_fn_id: u32) {} + unconstrained fn __debug_fn_exit_inner(fn_id: u32) { + __debug_fn_exit_oracle(fn_id); + } + pub fn __debug_fn_exit(fn_id: u32) { + __debug_fn_exit_inner(fn_id); + } + #[oracle(__debug_dereference_assign)] unconstrained fn __debug_dereference_assign_oracle(_var_id: u32, _value: T) {} unconstrained fn __debug_dereference_assign_inner(var_id: u32, value: T) { @@ -561,6 +618,21 @@ fn build_assign_member_stmt( ast::Statement { kind: ast::StatementKind::Semi(ast::Expression { kind, span }), span } } +fn build_debug_call_stmt(fname: &str, fn_id: DebugFnId, span: Span) -> ast::Statement { + let kind = ast::ExpressionKind::Call(Box::new(ast::CallExpression { + func: Box::new(ast::Expression { + kind: ast::ExpressionKind::Variable(ast::Path { + segments: vec![ident(&format!["__debug_fn_{fname}"], span)], + kind: PathKind::Plain, + span, + }), + span, + }), + arguments: vec![uint_expr(fn_id.0 as u128, span)], + })); + ast::Statement { kind: ast::StatementKind::Semi(ast::Expression { kind, span }), span } +} + fn pattern_vars(pattern: &ast::Pattern) -> Vec<(ast::Ident, bool)> { let mut vars = vec![]; let mut stack = VecDeque::from([(pattern, false)]); @@ -585,6 +657,30 @@ fn pattern_vars(pattern: &ast::Pattern) -> Vec<(ast::Ident, bool)> { vars } +fn pattern_to_string(pattern: &ast::Pattern) -> String { + match pattern { + ast::Pattern::Identifier(id) => id.0.contents.clone(), + ast::Pattern::Mutable(mpat, _, _) => format!("mut {}", pattern_to_string(mpat.as_ref())), + ast::Pattern::Tuple(elements, _) => format!( + "({})", + elements.iter().map(pattern_to_string).collect::>().join(", ") + ), + ast::Pattern::Struct(name, fields, _) => { + format!( + "{} {{ {} }}", + name, + fields + .iter() + .map(|(field_ident, field_pattern)| { + format!("{}: {}", &field_ident.0.contents, pattern_to_string(field_pattern)) + }) + .collect::>() + .join(", "), + ) + } + } +} + fn ident(s: &str, span: Span) -> ast::Ident { ast::Ident(Spanned::from(span, s.to_string())) } diff --git a/compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs b/compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs index 7f36af5b30e..90aa4baee7c 100644 --- a/compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs +++ b/compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs @@ -4,14 +4,15 @@ use crate::graph::CrateId; use crate::hir::def_map::{CrateDefMap, LocalModuleId, ModuleId}; use crate::hir::resolution::errors::ResolverError; -use crate::hir::resolution::import::{resolve_import, ImportDirective}; -use crate::hir::resolution::resolver::Resolver; +use crate::hir::resolution::import::{resolve_import, ImportDirective, PathResolution}; use crate::hir::resolution::{ collect_impls, collect_trait_impls, path_resolver, resolve_free_functions, resolve_globals, resolve_impls, resolve_structs, resolve_trait_by_path, resolve_trait_impls, resolve_traits, resolve_type_aliases, }; -use crate::hir::type_check::{type_check_func, TypeCheckError, TypeChecker}; +use crate::hir::type_check::{ + check_trait_impl_method_matches_declaration, type_check_func, TypeCheckError, TypeChecker, +}; use crate::hir::Context; use crate::macros_api::{MacroError, MacroProcessor}; @@ -20,8 +21,7 @@ use crate::node_interner::{FuncId, GlobalId, NodeInterner, StructId, TraitId, Ty use crate::parser::{ParserError, SortedModule}; use crate::{ ExpressionKind, Ident, LetStatement, Literal, NoirFunction, NoirStruct, NoirTrait, - NoirTypeAlias, Path, PathKind, Type, TypeBindings, UnresolvedGenerics, - UnresolvedTraitConstraint, UnresolvedType, + NoirTypeAlias, Path, PathKind, UnresolvedGenerics, UnresolvedTraitConstraint, UnresolvedType, }; use fm::FileId; use iter_extended::vecmap; @@ -56,8 +56,11 @@ impl UnresolvedFunctions { for bound in &mut func.def.where_clause { match resolve_trait_by_path(def_maps, module, bound.trait_bound.trait_path.clone()) { - Ok(trait_id) => { + Ok((trait_id, warning)) => { bound.trait_bound.trait_id = Some(trait_id); + if let Some(warning) = warning { + errors.push(DefCollectorErrorKind::PathResolutionError(warning)); + } } Err(err) => { errors.push(err); @@ -207,7 +210,7 @@ impl DefCollector { context: &mut Context, ast: SortedModule, root_file_id: FileId, - macro_processors: Vec<&dyn MacroProcessor>, + macro_processors: &[&dyn MacroProcessor], ) -> Vec<(CompilationError, FileId)> { let mut errors: Vec<(CompilationError, FileId)> = vec![]; let crate_id = def_map.krate; @@ -220,11 +223,7 @@ impl DefCollector { let crate_graph = &context.crate_graph[crate_id]; for dep in crate_graph.dependencies.clone() { - errors.extend(CrateDefMap::collect_defs( - dep.crate_id, - context, - macro_processors.clone(), - )); + errors.extend(CrateDefMap::collect_defs(dep.crate_id, context, macro_processors)); let dep_def_root = context.def_map(&dep.crate_id).expect("ice: def map was just created").root; @@ -250,6 +249,7 @@ impl DefCollector { crate_root, crate_id, context, + macro_processors, )); let submodules = vecmap(def_collector.def_map.modules().iter(), |(index, _)| index); @@ -257,9 +257,9 @@ impl DefCollector { context.def_maps.insert(crate_id, def_collector.def_map); // TODO(#4653): generalize this function - for macro_processor in ¯o_processors { + for macro_processor in macro_processors { macro_processor - .process_unresolved_traits_impls( + .process_collected_defs( &crate_id, context, &def_collector.collected_traits_impls, @@ -282,8 +282,15 @@ impl DefCollector { // Resolve unresolved imports collected from the crate, one by one. for collected_import in def_collector.collected_imports { - match resolve_import(crate_id, collected_import, &context.def_maps) { + match resolve_import(crate_id, &collected_import, &context.def_maps) { Ok(resolved_import) => { + if let Some(error) = resolved_import.error { + errors.push(( + DefCollectorErrorKind::PathResolutionError(error).into(), + root_file_id, + )); + } + // Populate module namespaces according to the imports used let current_def_map = context.def_maps.get_mut(&crate_id).unwrap(); @@ -302,9 +309,9 @@ impl DefCollector { } } } - Err((error, module_id)) => { + Err(error) => { let current_def_map = context.def_maps.get(&crate_id).unwrap(); - let file_id = current_def_map.file_id(module_id); + let file_id = current_def_map.file_id(collected_import.module_id); let error = DefCollectorErrorKind::PathResolutionError(error); errors.push((error.into(), file_id)); } @@ -331,11 +338,6 @@ impl DefCollector { // Must resolve structs before we resolve globals. errors.extend(resolve_structs(context, def_collector.collected_types, crate_id)); - // We must wait to resolve non-integer globals until after we resolve structs since struct - // globals will need to reference the struct type they're initialized to to ensure they are valid. - resolved_globals.extend(resolve_globals(context, other_globals, crate_id)); - errors.extend(resolved_globals.errors); - // Bind trait impls to their trait. Collect trait functions, that have a // default implementation, which hasn't been overridden. errors.extend(collect_trait_impls( @@ -353,6 +355,11 @@ impl DefCollector { // over trait methods if there are name conflicts. errors.extend(collect_impls(context, crate_id, &def_collector.collected_impls)); + // We must wait to resolve non-integer globals until after we resolve structs since struct + // globals will need to reference the struct type they're initialized to to ensure they are valid. + resolved_globals.extend(resolve_globals(context, other_globals, crate_id)); + errors.extend(resolved_globals.errors); + // Resolve each function in the crate. This is now possible since imports have been resolved let mut functions = Vec::new(); functions.extend(resolve_free_functions( @@ -372,12 +379,12 @@ impl DefCollector { &mut errors, )); - functions.extend(resolve_trait_impls( + let impl_functions = resolve_trait_impls( context, def_collector.collected_traits_impls, crate_id, &mut errors, - )); + ); for macro_processor in macro_processors { macro_processor.process_typed_ast(&crate_id, context).unwrap_or_else( @@ -391,6 +398,8 @@ impl DefCollector { errors.extend(type_check_globals(&mut context.def_interner, resolved_globals.globals)); errors.extend(type_check_functions(&mut context.def_interner, functions)); + errors.extend(type_check_trait_impl_signatures(&mut context.def_interner, &impl_functions)); + errors.extend(type_check_functions(&mut context.def_interner, impl_functions)); errors } } @@ -410,12 +419,13 @@ fn inject_prelude( Path { segments: segments.clone(), kind: crate::PathKind::Dep, span: Span::default() }; if !crate_id.is_stdlib() { - if let Ok(module_def) = path_resolver::resolve_path( + if let Ok(PathResolution { module_def_id, error }) = path_resolver::resolve_path( &context.def_maps, ModuleId { krate: crate_id, local_id: crate_root }, path, ) { - let module_id = module_def.as_module().expect("std::prelude should be a module"); + assert!(error.is_none(), "Tried to add private item to prelude"); + let module_id = module_def_id.as_module().expect("std::prelude should be a module"); let prelude = context.module(module_id).scope().names(); for path in prelude { @@ -472,158 +482,24 @@ fn type_check_functions( .into_iter() .flat_map(|(file, func)| { type_check_func(interner, func) - .iter() - .cloned() + .into_iter() .map(|e| (e.into(), file)) .collect::>() }) .collect() } -// TODO(vitkov): Move this out of here and into type_check -#[allow(clippy::too_many_arguments)] -pub(crate) fn check_methods_signatures( - resolver: &mut Resolver, - impl_methods: &[(FileId, FuncId)], - trait_id: TraitId, - trait_name_span: Span, - // These are the generics on the trait itself from the impl. - // E.g. in `impl Foo for Bar`, this is `vec![A, B]`. - trait_generics: Vec, - trait_impl_generic_count: usize, - file_id: FileId, - errors: &mut Vec<(CompilationError, FileId)>, -) { - let self_type = resolver.get_self_type().expect("trait impl must have a Self type").clone(); - let trait_generics = vecmap(trait_generics, |typ| resolver.resolve_type(typ)); - - // Temporarily bind the trait's Self type to self_type so we can type check - let the_trait = resolver.interner.get_trait_mut(trait_id); - the_trait.self_type_typevar.bind(self_type); - - if trait_generics.len() != the_trait.generics.len() { - let error = DefCollectorErrorKind::MismatchGenericCount { - actual_generic_count: trait_generics.len(), - expected_generic_count: the_trait.generics.len(), - // Preferring to use 'here' over a more precise term like 'this reference' - // to try to make the error easier to understand for newer users. - location: "here it", - origin: the_trait.name.to_string(), - span: trait_name_span, - }; - errors.push((error.into(), file_id)); - } - - // We also need to bind the traits generics to the trait's generics on the impl - for (generic, binding) in the_trait.generics.iter().zip(trait_generics) { - generic.bind(binding); - } - - // Temporarily take the trait's methods so we can use both them and a mutable reference - // to the interner within the loop. - let trait_methods = std::mem::take(&mut the_trait.methods); - - for (file_id, func_id) in impl_methods { - let func_name = resolver.interner.function_name(func_id).to_owned(); - - // This is None in the case where the impl block has a method that's not part of the trait. - // If that's the case, a `MethodNotInTrait` error has already been thrown, and we can ignore - // the impl method, since there's nothing in the trait to match its signature against. - if let Some(trait_method) = - trait_methods.iter().find(|method| method.name.0.contents == func_name) - { - let impl_method = resolver.interner.function_meta(func_id); - - let impl_method_generic_count = - impl_method.typ.generic_count() - trait_impl_generic_count; - - // We subtract 1 here to account for the implicit generic `Self` type that is on all - // traits (and thus trait methods) but is not required (or allowed) for users to specify. - let the_trait = resolver.interner.get_trait(trait_id); - let trait_method_generic_count = - trait_method.generics().len() - 1 - the_trait.generics.len(); - - if impl_method_generic_count != trait_method_generic_count { - let trait_name = resolver.interner.get_trait(trait_id).name.clone(); - - let error = DefCollectorErrorKind::MismatchGenericCount { - actual_generic_count: impl_method_generic_count, - expected_generic_count: trait_method_generic_count, - origin: format!("{}::{}", trait_name, func_name), - location: "this method", - span: impl_method.location.span, - }; - errors.push((error.into(), *file_id)); - } - - // This instantiation is technically not needed. We could bind each generic in the - // trait function to the impl's corresponding generic but to do so we'd have to rely - // on the trait function's generics being first in the generic list, since the same - // list also contains the generic `Self` variable, and any generics on the trait itself. - // - // Instantiating the impl method's generics here instead is a bit less precise but - // doesn't rely on any orderings that may be changed. - let impl_function_type = impl_method.typ.instantiate(resolver.interner).0; - - let mut bindings = TypeBindings::new(); - let mut typecheck_errors = Vec::new(); - - if let Type::Function(impl_params, impl_return, _) = impl_function_type.as_monotype() { - if trait_method.arguments().len() != impl_params.len() { - let error = DefCollectorErrorKind::MismatchTraitImplementationNumParameters { - actual_num_parameters: impl_method.parameters.0.len(), - expected_num_parameters: trait_method.arguments().len(), - trait_name: resolver.interner.get_trait(trait_id).name.to_string(), - method_name: func_name.to_string(), - span: impl_method.location.span, - }; - errors.push((error.into(), *file_id)); - } - - // Check the parameters of the impl method against the parameters of the trait method - let args = trait_method.arguments().iter(); - let args_and_params = args.zip(impl_params).zip(&impl_method.parameters.0); - - for (parameter_index, ((expected, actual), (hir_pattern, _, _))) in - args_and_params.enumerate() - { - if expected.try_unify(actual, &mut bindings).is_err() { - typecheck_errors.push(TypeCheckError::TraitMethodParameterTypeMismatch { - method_name: func_name.to_string(), - expected_typ: expected.to_string(), - actual_typ: actual.to_string(), - parameter_span: hir_pattern.span(), - parameter_index: parameter_index + 1, - }); - } - } - - if trait_method.return_type().try_unify(impl_return, &mut bindings).is_err() { - let impl_method = resolver.interner.function_meta(func_id); - let ret_type_span = impl_method.return_type.get_type().span; - let expr_span = ret_type_span.expect("return type must always have a span"); - - let expected_typ = trait_method.return_type().to_string(); - let expr_typ = impl_method.return_type().to_string(); - let error = TypeCheckError::TypeMismatch { expr_typ, expected_typ, expr_span }; - typecheck_errors.push(error); - } - } else { - unreachable!( - "impl_function_type is not a function type, it is: {impl_function_type}" - ); - } - - errors.extend(typecheck_errors.iter().cloned().map(|e| (e.into(), *file_id))); - } - } - - // Now unbind `Self` and the trait's generics - let the_trait = resolver.interner.get_trait_mut(trait_id); - the_trait.set_methods(trait_methods); - the_trait.self_type_typevar.unbind(the_trait.self_type_typevar_id); - - for generic in &the_trait.generics { - generic.unbind(generic.id()); - } +fn type_check_trait_impl_signatures( + interner: &mut NodeInterner, + file_func_ids: &[(FileId, FuncId)], +) -> Vec<(CompilationError, fm::FileId)> { + file_func_ids + .iter() + .flat_map(|(file, func)| { + check_trait_impl_method_matches_declaration(interner, *func) + .into_iter() + .map(|e| (e.into(), *file)) + .collect::>() + }) + .collect() } diff --git a/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs b/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs index 77224cc311c..fcb20c740c7 100644 --- a/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs +++ b/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs @@ -7,10 +7,11 @@ use noirc_errors::Location; use crate::{ graph::CrateId, hir::def_collector::dc_crate::{UnresolvedStruct, UnresolvedTrait}, + macros_api::MacroProcessor, node_interner::{FunctionModifiers, TraitId, TypeAliasId}, parser::{SortedModule, SortedSubModule}, - FunctionDefinition, Ident, LetStatement, NoirFunction, NoirStruct, NoirTrait, NoirTraitImpl, - NoirTypeAlias, TraitImplItem, TraitItem, TypeImpl, + FunctionDefinition, Ident, ItemVisibility, LetStatement, ModuleDeclaration, NoirFunction, + NoirStruct, NoirTrait, NoirTraitImpl, NoirTypeAlias, TraitImplItem, TraitItem, TypeImpl, }; use super::{ @@ -41,16 +42,28 @@ pub fn collect_defs( module_id: LocalModuleId, crate_id: CrateId, context: &mut Context, + macro_processors: &[&dyn MacroProcessor], ) -> Vec<(CompilationError, FileId)> { let mut collector = ModCollector { def_collector, file_id, module_id }; let mut errors: Vec<(CompilationError, FileId)> = vec![]; // First resolve the module declarations for decl in ast.module_decls { - errors.extend(collector.parse_module_declaration(context, &decl, crate_id)); + errors.extend(collector.parse_module_declaration( + context, + &decl, + crate_id, + macro_processors, + )); } - errors.extend(collector.collect_submodules(context, crate_id, ast.submodules, file_id)); + errors.extend(collector.collect_submodules( + context, + crate_id, + ast.submodules, + file_id, + macro_processors, + )); // Then add the imports to defCollector to resolve once all modules in the hierarchy have been resolved for import in ast.imports { @@ -219,6 +232,7 @@ impl<'a> ModCollector<'a> { let name = function.name_ident().clone(); let func_id = context.def_interner.push_empty_fn(); + let visibility = function.def.visibility; // First create dummy function in the DefInterner // So that we can get a FuncId @@ -235,7 +249,7 @@ impl<'a> ModCollector<'a> { // Add function to scope/ns of the module let result = self.def_collector.def_map.modules[self.module_id.0] - .declare_function(name, func_id); + .declare_function(name, visibility, func_id); if let Err((first_def, second_def)) = result { let error = DefCollectorErrorKind::Duplicate { @@ -394,12 +408,10 @@ impl<'a> ModCollector<'a> { let modifiers = FunctionModifiers { name: name.to_string(), - visibility: crate::FunctionVisibility::Public, + visibility: ItemVisibility::Public, // TODO(Maddiaa): Investigate trait implementations with attributes see: https://github.com/noir-lang/noir/issues/2629 attributes: crate::token::Attributes::empty(), is_unconstrained: false, - contract_function_type: None, - is_internal: None, }; let location = Location::new(name.span(), self.file_id); @@ -408,7 +420,7 @@ impl<'a> ModCollector<'a> { .push_function_definition(func_id, modifiers, trait_id.0, location); match self.def_collector.def_map.modules[trait_id.0.local_id.0] - .declare_function(name.clone(), func_id) + .declare_function(name.clone(), ItemVisibility::Public, func_id) { Ok(()) => { if let Some(body) = body { @@ -494,6 +506,7 @@ impl<'a> ModCollector<'a> { crate_id: CrateId, submodules: Vec, file_id: FileId, + macro_processors: &[&dyn MacroProcessor], ) -> Vec<(CompilationError, FileId)> { let mut errors: Vec<(CompilationError, FileId)> = vec![]; for submodule in submodules { @@ -506,6 +519,7 @@ impl<'a> ModCollector<'a> { child, crate_id, context, + macro_processors, )); } Err(error) => { @@ -522,15 +536,16 @@ impl<'a> ModCollector<'a> { fn parse_module_declaration( &mut self, context: &mut Context, - mod_name: &Ident, + mod_decl: &ModuleDeclaration, crate_id: CrateId, + macro_processors: &[&dyn MacroProcessor], ) -> Vec<(CompilationError, FileId)> { let mut errors: Vec<(CompilationError, FileId)> = vec![]; let child_file_id = - match find_module(&context.file_manager, self.file_id, &mod_name.0.contents) { + match find_module(&context.file_manager, self.file_id, &mod_decl.ident.0.contents) { Ok(child_file_id) => child_file_id, Err(expected_path) => { - let mod_name = mod_name.clone(); + let mod_name = mod_decl.ident.clone(); let err = DefCollectorErrorKind::UnresolvedModuleDecl { mod_name, expected_path }; errors.push((err.into(), self.file_id)); @@ -538,17 +553,17 @@ impl<'a> ModCollector<'a> { } }; - let location = Location { file: self.file_id, span: mod_name.span() }; + let location = Location { file: self.file_id, span: mod_decl.ident.span() }; if let Some(old_location) = context.visited_files.get(&child_file_id) { let error = DefCollectorErrorKind::ModuleAlreadyPartOfCrate { - mod_name: mod_name.clone(), + mod_name: mod_decl.ident.clone(), span: location.span, }; errors.push((error.into(), location.file)); let error = DefCollectorErrorKind::ModuleOriginallyDefined { - mod_name: mod_name.clone(), + mod_name: mod_decl.ident.clone(), span: old_location.span, }; errors.push((error.into(), old_location.file)); @@ -559,14 +574,31 @@ impl<'a> ModCollector<'a> { // Parse the AST for the module we just found and then recursively look for it's defs let (ast, parsing_errors) = context.parsed_file_results(child_file_id); - let ast = ast.into_sorted(); + let mut ast = ast.into_sorted(); + + for macro_processor in macro_processors { + match macro_processor.process_untyped_ast( + ast.clone(), + &crate_id, + child_file_id, + context, + ) { + Ok(processed_ast) => { + ast = processed_ast; + } + Err((error, file_id)) => { + let def_error = DefCollectorErrorKind::MacroError(error); + errors.push((def_error.into(), file_id)); + } + } + } errors.extend( parsing_errors.iter().map(|e| (e.clone().into(), child_file_id)).collect::>(), ); // Add module into def collector and get a ModuleId - match self.push_child_module(mod_name, child_file_id, true, false) { + match self.push_child_module(&mod_decl.ident, child_file_id, true, false) { Ok(child_mod_id) => { errors.extend(collect_defs( self.def_collector, @@ -575,6 +607,7 @@ impl<'a> ModCollector<'a> { child_mod_id, crate_id, context, + macro_processors, )); } Err(error) => { diff --git a/compiler/noirc_frontend/src/hir/def_collector/errors.rs b/compiler/noirc_frontend/src/hir/def_collector/errors.rs index de45be48c4e..29daf5d6369 100644 --- a/compiler/noirc_frontend/src/hir/def_collector/errors.rs +++ b/compiler/noirc_frontend/src/hir/def_collector/errors.rs @@ -41,14 +41,6 @@ pub enum DefCollectorErrorKind { OverlappingImplNote { span: Span }, #[error("Cannot `impl` a type defined outside the current crate")] ForeignImpl { span: Span, type_name: String }, - #[error("Mismatched number of parameters in trait implementation")] - MismatchTraitImplementationNumParameters { - actual_num_parameters: usize, - expected_num_parameters: usize, - trait_name: String, - method_name: String, - span: Span, - }, #[error("Mismatched number of generics in {location}")] MismatchGenericCount { actual_generic_count: usize, @@ -176,18 +168,6 @@ impl From for Diagnostic { "".to_string(), trait_path.span(), ), - DefCollectorErrorKind::MismatchTraitImplementationNumParameters { - expected_num_parameters, - actual_num_parameters, - trait_name, - method_name, - span, - } => { - let plural = if expected_num_parameters == 1 { "" } else { "s" }; - let primary_message = format!( - "`{trait_name}::{method_name}` expects {expected_num_parameters} parameter{plural}, but this method has {actual_num_parameters}"); - Diagnostic::simple_error(primary_message, "".to_string(), span) - } DefCollectorErrorKind::MismatchGenericCount { actual_generic_count, expected_generic_count, diff --git a/compiler/noirc_frontend/src/hir/def_map/item_scope.rs b/compiler/noirc_frontend/src/hir/def_map/item_scope.rs index 523def89518..cd4eafdf669 100644 --- a/compiler/noirc_frontend/src/hir/def_map/item_scope.rs +++ b/compiler/noirc_frontend/src/hir/def_map/item_scope.rs @@ -1,16 +1,11 @@ use super::{namespace::PerNs, ModuleDefId, ModuleId}; use crate::{ node_interner::{FuncId, TraitId}, - Ident, + Ident, ItemVisibility, }; use std::collections::{hash_map::Entry, HashMap}; -type Scope = HashMap, (ModuleDefId, Visibility, bool /*is_prelude*/)>; - -#[derive(Debug, PartialEq, Eq, Copy, Clone)] -pub enum Visibility { - Public, -} +type Scope = HashMap, (ModuleDefId, ItemVisibility, bool /*is_prelude*/)>; #[derive(Default, Debug, PartialEq, Eq)] pub struct ItemScope { @@ -24,10 +19,11 @@ impl ItemScope { pub fn add_definition( &mut self, name: Ident, + visibility: ItemVisibility, mod_def: ModuleDefId, trait_id: Option, ) -> Result<(), (Ident, Ident)> { - self.add_item_to_namespace(name, mod_def, trait_id, false)?; + self.add_item_to_namespace(name, visibility, mod_def, trait_id, false)?; self.defs.push(mod_def); Ok(()) } @@ -38,6 +34,7 @@ impl ItemScope { pub fn add_item_to_namespace( &mut self, name: Ident, + visibility: ItemVisibility, mod_def: ModuleDefId, trait_id: Option, is_prelude: bool, @@ -46,6 +43,11 @@ impl ItemScope { if let Entry::Occupied(mut o) = map.entry(name.clone()) { let trait_hashmap = o.get_mut(); if let Entry::Occupied(mut n) = trait_hashmap.entry(trait_id) { + // Generally we want to reject having two of the same ident in the same namespace. + // The exception to this is when we're explicitly importing something + // which exists in the Noir stdlib prelude. + // + // In this case we ignore the prelude and favour the explicit import. let is_prelude = std::mem::replace(&mut n.get_mut().2, is_prelude); let old_ident = o.key(); @@ -55,12 +57,12 @@ impl ItemScope { Err((old_ident.clone(), name)) } } else { - trait_hashmap.insert(trait_id, (mod_def, Visibility::Public, is_prelude)); + trait_hashmap.insert(trait_id, (mod_def, visibility, is_prelude)); Ok(()) } } else { let mut trait_hashmap = HashMap::new(); - trait_hashmap.insert(trait_id, (mod_def, Visibility::Public, is_prelude)); + trait_hashmap.insert(trait_id, (mod_def, visibility, is_prelude)); map.insert(name, trait_hashmap); Ok(()) } diff --git a/compiler/noirc_frontend/src/hir/def_map/mod.rs b/compiler/noirc_frontend/src/hir/def_map/mod.rs index 8721bdb6c3c..157227f763e 100644 --- a/compiler/noirc_frontend/src/hir/def_map/mod.rs +++ b/compiler/noirc_frontend/src/hir/def_map/mod.rs @@ -73,7 +73,7 @@ impl CrateDefMap { pub fn collect_defs( crate_id: CrateId, context: &mut Context, - macro_processors: Vec<&dyn MacroProcessor>, + macro_processors: &[&dyn MacroProcessor], ) -> Vec<(CompilationError, FileId)> { // Check if this Crate has already been compiled // XXX: There is probably a better alternative for this. @@ -90,8 +90,9 @@ impl CrateDefMap { let (ast, parsing_errors) = context.parsed_file_results(root_file_id); let mut ast = ast.into_sorted(); - for macro_processor in ¯o_processors { - match macro_processor.process_untyped_ast(ast.clone(), &crate_id, context) { + for macro_processor in macro_processors { + match macro_processor.process_untyped_ast(ast.clone(), &crate_id, root_file_id, context) + { Ok(processed_ast) => { ast = processed_ast; } @@ -115,13 +116,7 @@ impl CrateDefMap { }; // Now we want to populate the CrateDefMap using the DefCollector - errors.extend(DefCollector::collect( - def_map, - context, - ast, - root_file_id, - macro_processors.clone(), - )); + errors.extend(DefCollector::collect(def_map, context, ast, root_file_id, macro_processors)); errors.extend( parsing_errors.iter().map(|e| (e.clone().into(), root_file_id)).collect::>(), diff --git a/compiler/noirc_frontend/src/hir/def_map/module_data.rs b/compiler/noirc_frontend/src/hir/def_map/module_data.rs index 309618dd011..4dd38f0e3e5 100644 --- a/compiler/noirc_frontend/src/hir/def_map/module_data.rs +++ b/compiler/noirc_frontend/src/hir/def_map/module_data.rs @@ -4,7 +4,7 @@ use noirc_errors::Location; use crate::{ node_interner::{FuncId, GlobalId, StructId, TraitId, TypeAliasId}, - Ident, + Ident, ItemVisibility, }; use super::{ItemScope, LocalModuleId, ModuleDefId, ModuleId, PerNs}; @@ -48,18 +48,24 @@ impl ModuleData { fn declare( &mut self, name: Ident, + visibility: ItemVisibility, item_id: ModuleDefId, trait_id: Option, ) -> Result<(), (Ident, Ident)> { - self.scope.add_definition(name.clone(), item_id, trait_id)?; + self.scope.add_definition(name.clone(), visibility, item_id, trait_id)?; // definitions is a subset of self.scope so it is expected if self.scope.define_func_def // returns without error, so will self.definitions.define_func_def. - self.definitions.add_definition(name, item_id, trait_id) + self.definitions.add_definition(name, visibility, item_id, trait_id) } - pub fn declare_function(&mut self, name: Ident, id: FuncId) -> Result<(), (Ident, Ident)> { - self.declare(name, id.into(), None) + pub fn declare_function( + &mut self, + name: Ident, + visibility: ItemVisibility, + id: FuncId, + ) -> Result<(), (Ident, Ident)> { + self.declare(name, visibility, id.into(), None) } pub fn declare_trait_function( @@ -68,7 +74,7 @@ impl ModuleData { id: FuncId, trait_id: TraitId, ) -> Result<(), (Ident, Ident)> { - self.declare(name, id.into(), Some(trait_id)) + self.declare(name, ItemVisibility::Public, id.into(), Some(trait_id)) } pub fn remove_function(&mut self, name: &Ident) { @@ -77,11 +83,11 @@ impl ModuleData { } pub fn declare_global(&mut self, name: Ident, id: GlobalId) -> Result<(), (Ident, Ident)> { - self.declare(name, id.into(), None) + self.declare(name, ItemVisibility::Public, id.into(), None) } pub fn declare_struct(&mut self, name: Ident, id: StructId) -> Result<(), (Ident, Ident)> { - self.declare(name, ModuleDefId::TypeId(id), None) + self.declare(name, ItemVisibility::Public, ModuleDefId::TypeId(id), None) } pub fn declare_type_alias( @@ -89,11 +95,11 @@ impl ModuleData { name: Ident, id: TypeAliasId, ) -> Result<(), (Ident, Ident)> { - self.declare(name, id.into(), None) + self.declare(name, ItemVisibility::Public, id.into(), None) } pub fn declare_trait(&mut self, name: Ident, id: TraitId) -> Result<(), (Ident, Ident)> { - self.declare(name, ModuleDefId::TraitId(id), None) + self.declare(name, ItemVisibility::Public, ModuleDefId::TraitId(id), None) } pub fn declare_child_module( @@ -101,7 +107,7 @@ impl ModuleData { name: Ident, child_id: ModuleId, ) -> Result<(), (Ident, Ident)> { - self.declare(name, child_id.into(), None) + self.declare(name, ItemVisibility::Public, child_id.into(), None) } pub fn find_func_with_name(&self, name: &Ident) -> Option { @@ -114,7 +120,7 @@ impl ModuleData { id: ModuleDefId, is_prelude: bool, ) -> Result<(), (Ident, Ident)> { - self.scope.add_item_to_namespace(name, id, None, is_prelude) + self.scope.add_item_to_namespace(name, ItemVisibility::Public, id, None, is_prelude) } pub fn find_name(&self, name: &Ident) -> PerNs { diff --git a/compiler/noirc_frontend/src/hir/def_map/namespace.rs b/compiler/noirc_frontend/src/hir/def_map/namespace.rs index ca14d9f8617..5e349f46e14 100644 --- a/compiler/noirc_frontend/src/hir/def_map/namespace.rs +++ b/compiler/noirc_frontend/src/hir/def_map/namespace.rs @@ -1,15 +1,16 @@ -use super::{item_scope::Visibility, ModuleDefId}; +use super::ModuleDefId; +use crate::ItemVisibility; // This works exactly the same as in r-a, just simplified #[derive(Debug, PartialEq, Eq, Copy, Clone)] pub struct PerNs { - pub types: Option<(ModuleDefId, Visibility, bool)>, - pub values: Option<(ModuleDefId, Visibility, bool)>, + pub types: Option<(ModuleDefId, ItemVisibility, bool)>, + pub values: Option<(ModuleDefId, ItemVisibility, bool)>, } impl PerNs { pub fn types(t: ModuleDefId) -> PerNs { - PerNs { types: Some((t, Visibility::Public, false)), values: None } + PerNs { types: Some((t, ItemVisibility::Public, false)), values: None } } pub fn take_types(self) -> Option { @@ -24,7 +25,7 @@ impl PerNs { self.types.map(|it| it.0).into_iter().chain(self.values.map(|it| it.0)) } - pub fn iter_items(self) -> impl Iterator { + pub fn iter_items(self) -> impl Iterator { self.types.into_iter().chain(self.values) } diff --git a/compiler/noirc_frontend/src/hir/resolution/errors.rs b/compiler/noirc_frontend/src/hir/resolution/errors.rs index d2fe67da38c..d5b0c612f90 100644 --- a/compiler/noirc_frontend/src/hir/resolution/errors.rs +++ b/compiler/noirc_frontend/src/hir/resolution/errors.rs @@ -25,7 +25,7 @@ pub enum ResolverError { #[error("path is not an identifier")] PathIsNotIdent { span: Span }, #[error("could not resolve path")] - PathResolutionError(PathResolutionError), + PathResolutionError(#[from] PathResolutionError), #[error("Expected")] Expected { span: Span, expected: String, got: String }, #[error("Duplicate field in constructor")] @@ -64,24 +64,14 @@ pub enum ResolverError { IncorrectGenericCount { span: Span, item_name: String, actual: usize, expected: usize }, #[error("{0}")] ParserError(Box), - #[error("Function is not defined in a contract yet sets its contract visibility")] - ContractFunctionTypeInNormalFunction { span: Span }, #[error("Cannot create a mutable reference to {variable}, it was declared to be immutable")] MutableReferenceToImmutableVariable { variable: String, span: Span }, #[error("Mutable references to array indices are unsupported")] MutableReferenceToArrayElement { span: Span }, - #[error("Function is not defined in a contract yet sets is_internal")] - ContractFunctionInternalInNormalFunction { span: Span }, #[error("Numeric constants should be printed without formatting braces")] NumericConstantInFormatString { name: String, span: Span }, #[error("Closure environment must be a tuple or unit type")] InvalidClosureEnvironment { typ: Type, span: Span }, - #[error("{name} is private and not visible from the current module")] - PrivateFunctionCalled { name: String, span: Span }, - #[error("{name} is not visible from the current crate")] - NonCrateFunctionCalled { name: String, span: Span }, - #[error("Only sized types may be used in the entry point to a program")] - InvalidTypeForEntryPoint { span: Span }, #[error("Nested slices are not supported")] NestedSlices { span: Span }, #[error("#[recursive] attribute is only allowed on entry points to a program")] @@ -90,6 +80,10 @@ pub enum ResolverError { LowLevelFunctionOutsideOfStdlib { ident: Ident }, #[error("Dependency cycle found, '{item}' recursively depends on itself: {cycle} ")] DependencyCycle { span: Span, item: String, cycle: String }, + #[error("break/continue are only allowed in unconstrained functions")] + JumpInConstrainedFn { is_break: bool, span: Span }, + #[error("break/continue are only allowed within loops")] + JumpOutsideLoop { is_break: bool, span: Span }, } impl ResolverError { @@ -278,22 +272,12 @@ impl From for Diagnostic { ) } ResolverError::ParserError(error) => (*error).into(), - ResolverError::ContractFunctionTypeInNormalFunction { span } => Diagnostic::simple_error( - "Only functions defined within contracts can set their contract function type".into(), - "Non-contract functions cannot be 'open'".into(), - span, - ), ResolverError::MutableReferenceToImmutableVariable { variable, span } => { Diagnostic::simple_error(format!("Cannot mutably reference the immutable variable {variable}"), format!("{variable} is immutable"), span) }, ResolverError::MutableReferenceToArrayElement { span } => { Diagnostic::simple_error("Mutable references to array elements are currently unsupported".into(), "Try storing the element in a fresh variable first".into(), span) }, - ResolverError::ContractFunctionInternalInNormalFunction { span } => Diagnostic::simple_error( - "Only functions defined within contracts can set their functions to be internal".into(), - "Non-contract functions cannot be 'internal'".into(), - span, - ), ResolverError::NumericConstantInFormatString { name, span } => Diagnostic::simple_error( format!("cannot find `{name}` in this scope "), "Numeric constants should be printed without formatting braces".to_string(), @@ -302,16 +286,6 @@ impl From for Diagnostic { ResolverError::InvalidClosureEnvironment { span, typ } => Diagnostic::simple_error( format!("{typ} is not a valid closure environment type"), "Closure environment must be a tuple or unit type".to_string(), span), - // This will be upgraded to an error in future versions - ResolverError::PrivateFunctionCalled { span, name } => Diagnostic::simple_warning( - format!("{name} is private and not visible from the current module"), - format!("{name} is private"), span), - ResolverError::NonCrateFunctionCalled { span, name } => Diagnostic::simple_warning( - format!("{name} is not visible from the current crate"), - format!("{name} is only visible within its crate"), span), - ResolverError::InvalidTypeForEntryPoint { span } => Diagnostic::simple_error( - "Only sized types may be used in the entry point to a program".to_string(), - "Slices, references, or any type containing them may not be used in main or a contract function".to_string(), span), ResolverError::NestedSlices { span } => Diagnostic::simple_error( "Nested slices are not supported".into(), "Try to use a constant sized array instead".into(), @@ -341,6 +315,22 @@ impl From for Diagnostic { span, ) }, + ResolverError::JumpInConstrainedFn { is_break, span } => { + let item = if is_break { "break" } else { "continue" }; + Diagnostic::simple_error( + format!("{item} is only allowed in unconstrained functions"), + "Constrained code must always have a known number of loop iterations".into(), + span, + ) + }, + ResolverError::JumpOutsideLoop { is_break, span } => { + let item = if is_break { "break" } else { "continue" }; + Diagnostic::simple_error( + format!("{item} is only allowed within loops"), + "".into(), + span, + ) + }, } } } diff --git a/compiler/noirc_frontend/src/hir/resolution/impls.rs b/compiler/noirc_frontend/src/hir/resolution/impls.rs index 4aa70f00cfc..72f6adc3770 100644 --- a/compiler/noirc_frontend/src/hir/resolution/impls.rs +++ b/compiler/noirc_frontend/src/hir/resolution/impls.rs @@ -13,7 +13,7 @@ use crate::{ Context, }, node_interner::{FuncId, NodeInterner}, - Type, + ItemVisibility, Type, }; use super::{ @@ -67,7 +67,14 @@ pub(crate) fn collect_impls( // be accessed with the `TypeName::method` syntax. We'll check later whether the // object types in each method overlap or not. If they do, we issue an error. // If not, that is specialization which is allowed. - if module.declare_function(method.name_ident().clone(), *method_id).is_err() { + if module + .declare_function( + method.name_ident().clone(), + ItemVisibility::Public, + *method_id, + ) + .is_err() + { module.remove_function(method.name_ident()); } } diff --git a/compiler/noirc_frontend/src/hir/resolution/import.rs b/compiler/noirc_frontend/src/hir/resolution/import.rs index e6ac33053a0..ade97e2cf42 100644 --- a/compiler/noirc_frontend/src/hir/resolution/import.rs +++ b/compiler/noirc_frontend/src/hir/resolution/import.rs @@ -1,10 +1,11 @@ use noirc_errors::{CustomDiagnostic, Span}; +use thiserror::Error; use crate::graph::CrateId; use std::collections::BTreeMap; use crate::hir::def_map::{CrateDefMap, LocalModuleId, ModuleDefId, ModuleId, PerNs}; -use crate::{Ident, Path, PathKind}; +use crate::{Ident, ItemVisibility, Path, PathKind}; #[derive(Debug, Clone)] pub struct ImportDirective { @@ -14,12 +15,30 @@ pub struct ImportDirective { pub is_prelude: bool, } -pub type PathResolution = Result; +struct NamespaceResolution { + module_id: ModuleId, + namespace: PerNs, + error: Option, +} + +type NamespaceResolutionResult = Result; + +pub struct PathResolution { + pub module_def_id: ModuleDefId, + + pub error: Option, +} + +pub(crate) type PathResolutionResult = Result; -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, Error)] pub enum PathResolutionError { + #[error("Could not resolve '{0}' in path")] Unresolved(Ident), + #[error("Contract variable '{0}' referenced from outside the contract")] ExternalContractUsed(Ident), + #[error("{0} is private and not visible from the current module")] + Private(Ident), } #[derive(Debug)] @@ -31,50 +50,77 @@ pub struct ResolvedImport { // The module which we must add the resolved namespace to pub module_scope: LocalModuleId, pub is_prelude: bool, + pub error: Option, } impl From for CustomDiagnostic { fn from(error: PathResolutionError) -> Self { - match error { - PathResolutionError::Unresolved(ident) => CustomDiagnostic::simple_error( - format!("Could not resolve '{ident}' in path"), - String::new(), - ident.span(), - ), + match &error { + PathResolutionError::Unresolved(ident) => { + CustomDiagnostic::simple_error(error.to_string(), String::new(), ident.span()) + } PathResolutionError::ExternalContractUsed(ident) => CustomDiagnostic::simple_error( - format!("Contract variable '{ident}' referenced from outside the contract"), + error.to_string(), "Contracts may only be referenced from within a contract".to_string(), ident.span(), ), + // This will be upgraded to an error in future versions + PathResolutionError::Private(ident) => CustomDiagnostic::simple_warning( + error.to_string(), + format!("{ident} is private"), + ident.span(), + ), } } } pub fn resolve_import( crate_id: CrateId, - import_directive: ImportDirective, + import_directive: &ImportDirective, def_maps: &BTreeMap, -) -> Result { - let def_map = &def_maps[&crate_id]; - +) -> Result { let allow_contracts = allow_referencing_contracts(def_maps, crate_id, import_directive.module_id); let module_scope = import_directive.module_id; - let resolved_namespace = - resolve_path_to_ns(&import_directive, def_map, def_maps, allow_contracts) - .map_err(|error| (error, module_scope))?; + let NamespaceResolution { + module_id: resolved_module, + namespace: resolved_namespace, + mut error, + } = resolve_path_to_ns(import_directive, crate_id, crate_id, def_maps, allow_contracts)?; + + let name = resolve_path_name(import_directive); + + let visibility = resolved_namespace + .values + .or(resolved_namespace.types) + .map(|(_, visibility, _)| visibility) + .expect("Found empty namespace"); + + error = error.or_else(|| { + if can_reference_module_id( + def_maps, + crate_id, + import_directive.module_id, + resolved_module, + visibility, + ) { + None + } else { + Some(PathResolutionError::Private(name.clone())) + } + }); - let name = resolve_path_name(&import_directive); Ok(ResolvedImport { name, resolved_namespace, module_scope, is_prelude: import_directive.is_prelude, + error, }) } -pub(super) fn allow_referencing_contracts( +fn allow_referencing_contracts( def_maps: &BTreeMap, krate: CrateId, local_id: LocalModuleId, @@ -82,27 +128,40 @@ pub(super) fn allow_referencing_contracts( ModuleId { krate, local_id }.module(def_maps).is_contract } -pub fn resolve_path_to_ns( +fn resolve_path_to_ns( import_directive: &ImportDirective, - def_map: &CrateDefMap, + crate_id: CrateId, + importing_crate: CrateId, def_maps: &BTreeMap, allow_contracts: bool, -) -> PathResolution { +) -> NamespaceResolutionResult { let import_path = &import_directive.path.segments; + let def_map = &def_maps[&crate_id]; match import_directive.path.kind { crate::ast::PathKind::Crate => { // Resolve from the root of the crate - resolve_path_from_crate_root(def_map, import_path, def_maps, allow_contracts) - } - crate::ast::PathKind::Dep => { - resolve_external_dep(def_map, import_directive, def_maps, allow_contracts) + resolve_path_from_crate_root( + crate_id, + importing_crate, + import_path, + def_maps, + allow_contracts, + ) } + crate::ast::PathKind::Dep => resolve_external_dep( + def_map, + import_directive, + def_maps, + allow_contracts, + importing_crate, + ), crate::ast::PathKind::Plain => { // Plain paths are only used to import children modules. It's possible to allow import of external deps, but maybe this distinction is better? // In Rust they can also point to external Dependencies, if no children can be found with the specified name resolve_name_in_module( - def_map, + crate_id, + importing_crate, import_path, import_directive.module_id, def_maps, @@ -113,45 +172,60 @@ pub fn resolve_path_to_ns( } fn resolve_path_from_crate_root( - def_map: &CrateDefMap, + crate_id: CrateId, + importing_crate: CrateId, + import_path: &[Ident], def_maps: &BTreeMap, allow_contracts: bool, -) -> PathResolution { - resolve_name_in_module(def_map, import_path, def_map.root, def_maps, allow_contracts) +) -> NamespaceResolutionResult { + resolve_name_in_module( + crate_id, + importing_crate, + import_path, + def_maps[&crate_id].root, + def_maps, + allow_contracts, + ) } fn resolve_name_in_module( - def_map: &CrateDefMap, + krate: CrateId, + importing_crate: CrateId, import_path: &[Ident], starting_mod: LocalModuleId, def_maps: &BTreeMap, allow_contracts: bool, -) -> PathResolution { - let mut current_mod = &def_map.modules[starting_mod.0]; +) -> NamespaceResolutionResult { + let def_map = &def_maps[&krate]; + let mut current_mod_id = ModuleId { krate, local_id: starting_mod }; + let mut current_mod = &def_map.modules[current_mod_id.local_id.0]; // There is a possibility that the import path is empty // In that case, early return if import_path.is_empty() { - let mod_id = ModuleId { krate: def_map.krate, local_id: starting_mod }; - return Ok(PerNs::types(mod_id.into())); + return Ok(NamespaceResolution { + module_id: current_mod_id, + namespace: PerNs::types(current_mod_id.into()), + error: None, + }); } - let mut import_path = import_path.iter(); - let first_segment = import_path.next().expect("ice: could not fetch first segment"); + let first_segment = import_path.first().expect("ice: could not fetch first segment"); let mut current_ns = current_mod.find_name(first_segment); if current_ns.is_none() { return Err(PathResolutionError::Unresolved(first_segment.clone())); } - for segment in import_path { - let typ = match current_ns.take_types() { - None => return Err(PathResolutionError::Unresolved(segment.clone())), - Some(typ) => typ, + let mut warning: Option = None; + for (last_segment, current_segment) in import_path.iter().zip(import_path.iter().skip(1)) { + let (typ, visibility) = match current_ns.types { + None => return Err(PathResolutionError::Unresolved(last_segment.clone())), + Some((typ, visibility, _)) => (typ, visibility), }; // In the type namespace, only Mod can be used in a path. - let new_module_id = match typ { + current_mod_id = match typ { ModuleDefId::ModuleId(id) => id, ModuleDefId::FunctionId(_) => panic!("functions cannot be in the type namespace"), // TODO: If impls are ever implemented, types can be used in a path @@ -161,22 +235,37 @@ fn resolve_name_in_module( ModuleDefId::GlobalId(_) => panic!("globals cannot be in the type namespace"), }; - current_mod = &def_maps[&new_module_id.krate].modules[new_module_id.local_id.0]; + warning = warning.or_else(|| { + if can_reference_module_id( + def_maps, + importing_crate, + starting_mod, + current_mod_id, + visibility, + ) { + None + } else { + Some(PathResolutionError::Private(last_segment.clone())) + } + }); + + current_mod = &def_maps[¤t_mod_id.krate].modules[current_mod_id.local_id.0]; // Check if namespace - let found_ns = current_mod.find_name(segment); + let found_ns = current_mod.find_name(current_segment); if found_ns.is_none() { - return Err(PathResolutionError::Unresolved(segment.clone())); + return Err(PathResolutionError::Unresolved(current_segment.clone())); } + // Check if it is a contract and we're calling from a non-contract context if current_mod.is_contract && !allow_contracts { - return Err(PathResolutionError::ExternalContractUsed(segment.clone())); + return Err(PathResolutionError::ExternalContractUsed(current_segment.clone())); } current_ns = found_ns; } - Ok(current_ns) + Ok(NamespaceResolution { module_id: current_mod_id, namespace: current_ns, error: warning }) } fn resolve_path_name(import_directive: &ImportDirective) -> Ident { @@ -191,11 +280,11 @@ fn resolve_external_dep( directive: &ImportDirective, def_maps: &BTreeMap, allow_contracts: bool, -) -> PathResolution { + importing_crate: CrateId, +) -> NamespaceResolutionResult { // Use extern_prelude to get the dep - // let path = &directive.path.segments; - // + // Fetch the root module from the prelude let crate_name = path.first().unwrap(); let dep_module = current_def_map @@ -218,7 +307,49 @@ fn resolve_external_dep( is_prelude: false, }; - let dep_def_map = def_maps.get(&dep_module.krate).unwrap(); + resolve_path_to_ns(&dep_directive, dep_module.krate, importing_crate, def_maps, allow_contracts) +} + +// Issue an error if the given private function is being called from a non-child module, or +// if the given pub(crate) function is being called from another crate +fn can_reference_module_id( + def_maps: &BTreeMap, + importing_crate: CrateId, + current_module: LocalModuleId, + target_module: ModuleId, + visibility: ItemVisibility, +) -> bool { + // Note that if the target module is in a different crate from the current module then we will either + // return true as the target module is public or return false as it is private without looking at the `CrateDefMap` in either case. + let same_crate = target_module.krate == importing_crate; + let target_crate_def_map = &def_maps[&target_module.krate]; + + match visibility { + ItemVisibility::Public => true, + ItemVisibility::PublicCrate => same_crate, + ItemVisibility::Private => { + same_crate + && module_descendent_of_target( + target_crate_def_map, + target_module.local_id, + current_module, + ) + } + } +} + +// Returns true if `current` is a (potentially nested) child module of `target`. +// This is also true if `current == target`. +fn module_descendent_of_target( + def_map: &CrateDefMap, + target: LocalModuleId, + current: LocalModuleId, +) -> bool { + if current == target { + return true; + } - resolve_path_to_ns(&dep_directive, dep_def_map, def_maps, allow_contracts) + def_map.modules[current.0] + .parent + .map_or(false, |parent| module_descendent_of_target(def_map, target, parent)) } diff --git a/compiler/noirc_frontend/src/hir/resolution/path_resolver.rs b/compiler/noirc_frontend/src/hir/resolution/path_resolver.rs index 4c5fa3bceef..e19af3c732f 100644 --- a/compiler/noirc_frontend/src/hir/resolution/path_resolver.rs +++ b/compiler/noirc_frontend/src/hir/resolution/path_resolver.rs @@ -1,11 +1,9 @@ -use super::import::{ - allow_referencing_contracts, resolve_path_to_ns, ImportDirective, PathResolutionError, -}; +use super::import::{resolve_import, ImportDirective, PathResolution, PathResolutionResult}; use crate::Path; use std::collections::BTreeMap; use crate::graph::CrateId; -use crate::hir::def_map::{CrateDefMap, LocalModuleId, ModuleDefId, ModuleId}; +use crate::hir::def_map::{CrateDefMap, LocalModuleId, ModuleId}; pub trait PathResolver { /// Resolve the given path returning the resolved ModuleDefId. @@ -13,7 +11,7 @@ pub trait PathResolver { &self, def_maps: &BTreeMap, path: Path, - ) -> Result; + ) -> PathResolutionResult; fn local_module_id(&self) -> LocalModuleId; @@ -36,7 +34,7 @@ impl PathResolver for StandardPathResolver { &self, def_maps: &BTreeMap, path: Path, - ) -> Result { + ) -> PathResolutionResult { resolve_path(def_maps, self.module_id, path) } @@ -55,17 +53,15 @@ pub fn resolve_path( def_maps: &BTreeMap, module_id: ModuleId, path: Path, -) -> Result { +) -> PathResolutionResult { // lets package up the path into an ImportDirective and resolve it using that let import = ImportDirective { module_id: module_id.local_id, path, alias: None, is_prelude: false }; - let allow_referencing_contracts = - allow_referencing_contracts(def_maps, module_id.krate, module_id.local_id); + let resolved_import = resolve_import(module_id.krate, &import, def_maps)?; - let def_map = &def_maps[&module_id.krate]; - let ns = resolve_path_to_ns(&import, def_map, def_maps, allow_referencing_contracts)?; + let namespace = resolved_import.resolved_namespace; + let id = + namespace.values.or(namespace.types).map(|(id, _, _)| id).expect("Found empty namespace"); - let function = ns.values.map(|(id, _, _)| id); - let id = function.or_else(|| ns.types.map(|(id, _, _)| id)); - Ok(id.expect("Found empty namespace")) + Ok(PathResolution { module_def_id: id, error: resolved_import.error }) } diff --git a/compiler/noirc_frontend/src/hir/resolution/resolver.rs b/compiler/noirc_frontend/src/hir/resolution/resolver.rs index 7f9e48353a7..f2b8212db7a 100644 --- a/compiler/noirc_frontend/src/hir/resolution/resolver.rs +++ b/compiler/noirc_frontend/src/hir/resolution/resolver.rs @@ -25,7 +25,7 @@ use std::collections::{BTreeMap, HashSet}; use std::rc::Rc; use crate::graph::CrateId; -use crate::hir::def_map::{LocalModuleId, ModuleDefId, TryFromModuleDefId, MAIN_FUNCTION}; +use crate::hir::def_map::{ModuleDefId, TryFromModuleDefId, MAIN_FUNCTION}; use crate::hir_def::stmt::{HirAssignStatement, HirForStatement, HirLValue, HirPattern}; use crate::node_interner::{ DefinitionId, DefinitionKind, DependencyId, ExprId, FuncId, GlobalId, NodeInterner, StmtId, @@ -37,10 +37,10 @@ use crate::{ StatementKind, }; use crate::{ - ArrayLiteral, ContractFunctionType, Distinctness, ForRange, FunctionDefinition, - FunctionReturnType, FunctionVisibility, Generics, LValue, NoirStruct, NoirTypeAlias, Param, - Path, PathKind, Pattern, Shared, StructType, Type, TypeAlias, TypeVariable, TypeVariableKind, - UnaryOp, UnresolvedGenerics, UnresolvedTraitConstraint, UnresolvedType, UnresolvedTypeData, + ArrayLiteral, BinaryOpKind, Distinctness, ForRange, FunctionDefinition, FunctionReturnType, + Generics, ItemVisibility, LValue, NoirStruct, NoirTypeAlias, Param, Path, PathKind, Pattern, + Shared, Statement, StructType, Type, TypeAlias, TypeVariable, TypeVariableKind, UnaryOp, + UnresolvedGenerics, UnresolvedTraitConstraint, UnresolvedType, UnresolvedTypeData, UnresolvedTypeExpression, Visibility, ERROR_IDENT, }; use fm::FileId; @@ -56,6 +56,7 @@ use crate::hir_def::{ }; use super::errors::{PubPosition, ResolverError}; +use super::import::PathResolution; const SELF_TYPE_NAME: &str = "Self"; @@ -115,6 +116,13 @@ pub struct Resolver<'a> { /// that are captured. We do this in order to create the hidden environment /// parameter for the lambda function. lambda_stack: Vec, + + /// True if we're currently resolving an unconstrained function + in_unconstrained_fn: bool, + + /// How many loops we're currently within. + /// This increases by 1 at the start of a loop, and decreases by 1 when it ends. + nested_loops: u32, } /// ResolverMetas are tagged onto each definition to track how many times they are used @@ -155,6 +163,8 @@ impl<'a> Resolver<'a> { current_item: None, file, in_contract, + in_unconstrained_fn: false, + nested_loops: 0, } } @@ -217,6 +227,7 @@ impl<'a> Resolver<'a> { pub fn resolve_trait_function( &mut self, name: &Ident, + generics: &UnresolvedGenerics, parameters: &[(Ident, UnresolvedType)], return_type: &FunctionReturnType, where_clause: &[UnresolvedTraitConstraint], @@ -233,18 +244,16 @@ impl<'a> Resolver<'a> { let def = FunctionDefinition { name: name.clone(), attributes: Attributes::empty(), - is_open: false, - is_internal: false, is_unconstrained: false, - visibility: FunctionVisibility::Public, // Trait functions are always public - generics: Vec::new(), // self.generics should already be set + visibility: ItemVisibility::Public, // Trait functions are always public + generics: generics.clone(), parameters: vecmap(parameters, |(name, typ)| Param { visibility: Visibility::Private, pattern: Pattern::Identifier(name.clone()), typ: typ.clone(), span: name.span(), }), - body: BlockExpression(Vec::new()), + body: BlockExpression { statements: Vec::new() }, span: name.span(), where_clause: where_clause.to_vec(), return_type: return_type.clone(), @@ -417,6 +426,11 @@ impl<'a> Resolver<'a> { fn intern_function(&mut self, func: NoirFunction, id: FuncId) -> (HirFunction, FuncMeta) { let func_meta = self.extract_meta(&func, id); + + if func.def.is_unconstrained { + self.in_unconstrained_fn = true; + } + let hir_func = match func.kind { FunctionKind::Builtin | FunctionKind::LowLevel | FunctionKind::Oracle => { HirFunction::empty() @@ -468,13 +482,13 @@ impl<'a> Resolver<'a> { FieldElement => Type::FieldElement, Array(size, elem) => { let elem = Box::new(self.resolve_type_inner(*elem, new_variables)); - let size = if size.is_none() { - Type::NotConstant - } else { - self.resolve_array_size(size, new_variables) - }; + let size = self.resolve_array_size(Some(size), new_variables); Type::Array(Box::new(size), elem) } + Slice(elem) => { + let elem = Box::new(self.resolve_type_inner(*elem, new_variables)); + Type::Slice(elem) + } Expression(expr) => self.convert_expression_type(expr), Integer(sign, bits) => Type::Integer(sign, bits), Bool => Type::Bool, @@ -664,10 +678,14 @@ impl<'a> Resolver<'a> { // If we cannot find a local generic of the same name, try to look up a global match self.path_resolver.resolve(self.def_maps, path.clone()) { - Ok(ModuleDefId::GlobalId(id)) => { + Ok(PathResolution { module_def_id: ModuleDefId::GlobalId(id), error }) => { if let Some(current_item) = self.current_item { self.interner.add_global_dependency(current_item, id); } + + if let Some(error) = error { + self.push_err(error.into()); + } Some(Type::Constant(self.eval_global_as_array_length(id, path))) } _ => None, @@ -911,10 +929,6 @@ impl<'a> Resolver<'a> { }); } - if self.is_entry_point_function(func) { - self.verify_type_valid_for_program_input(&typ); - } - let pattern = self.resolve_pattern(pattern, DefinitionKind::Local(None)); let typ = self.resolve_type_inner(typ, &mut generics); @@ -933,7 +947,7 @@ impl<'a> Resolver<'a> { }); } let is_low_level_function = - func.attributes().function.as_ref().map_or(false, |func| func.is_low_level()); + attributes.function.as_ref().map_or(false, |func| func.is_low_level()); if !self.path_resolver.module_id().krate.is_stdlib() && is_low_level_function { let error = ResolverError::LowLevelFunctionOutsideOfStdlib { ident: func.name_ident().clone() }; @@ -976,14 +990,20 @@ impl<'a> Resolver<'a> { self.interner.push_definition_type(name_ident.id, typ.clone()); - self.handle_function_type(&func_id); - self.handle_is_function_internal(&func_id); + let direct_generics = func.def.generics.iter(); + let direct_generics = direct_generics + .filter_map(|generic| self.find_generic(&generic.0.contents)) + .map(|(name, typevar, _span)| (name.clone(), typevar.clone())) + .collect(); + + let should_fold = attributes.is_foldable(); FuncMeta { name: name_ident, kind: func.kind, location, typ, + direct_generics, trait_impl: self.current_trait_impl, parameters: parameters.into(), return_type: func.def.return_type.clone(), @@ -991,6 +1011,8 @@ impl<'a> Resolver<'a> { return_distinctness: func.def.return_distinctness, has_body: !func.def.body.is_empty(), trait_constraints: self.resolve_trait_constraints(&func.def.where_clause), + is_entry_point: self.is_entry_point_function(func), + should_fold, } } @@ -1018,34 +1040,14 @@ impl<'a> Resolver<'a> { /// True if the `distinct` keyword is allowed on a function's return type fn distinct_allowed(&self, func: &NoirFunction) -> bool { if self.in_contract { - // "open" and "unconstrained" functions are compiled to brillig and thus duplication of + // "unconstrained" functions are compiled to brillig and thus duplication of // witness indices in their abis is not a concern. - !func.def.is_unconstrained && !func.def.is_open + !func.def.is_unconstrained } else { func.name() == MAIN_FUNCTION } } - fn handle_function_type(&mut self, function: &FuncId) { - let function_type = self.interner.function_modifiers(function).contract_function_type; - - if !self.in_contract && function_type == Some(ContractFunctionType::Open) { - let span = self.interner.function_ident(function).span(); - self.errors.push(ResolverError::ContractFunctionTypeInNormalFunction { span }); - self.interner.function_modifiers_mut(function).contract_function_type = None; - } - } - - fn handle_is_function_internal(&mut self, function: &FuncId) { - if !self.in_contract { - if self.interner.function_modifiers(function).is_internal == Some(true) { - let span = self.interner.function_ident(function).span(); - self.push_err(ResolverError::ContractFunctionInternalInNormalFunction { span }); - } - self.interner.function_modifiers_mut(function).is_internal = None; - } - } - fn declare_numeric_generics(&mut self, params: &[Type], return_type: &Type) { if self.generics.is_empty() { return; @@ -1090,8 +1092,8 @@ impl<'a> Resolver<'a> { | Type::TypeVariable(_, _) | Type::Constant(_) | Type::NamedGeneric(_, _) - | Type::NotConstant | Type::TraitAsType(..) + | Type::Code | Type::Forall(_, _) => (), Type::Array(length, element_type) => { @@ -1101,6 +1103,10 @@ impl<'a> Resolver<'a> { Self::find_numeric_generics_in_type(element_type, found); } + Type::Slice(element_type) => { + Self::find_numeric_generics_in_type(element_type, found); + } + Type::Tuple(fields) => { for field in fields { Self::find_numeric_generics_in_type(field, found); @@ -1168,7 +1174,7 @@ impl<'a> Resolver<'a> { }) } - pub fn resolve_stmt(&mut self, stmt: StatementKind) -> HirStatement { + pub fn resolve_stmt(&mut self, stmt: StatementKind, span: Span) -> HirStatement { match stmt { StatementKind::Let(let_stmt) => { let expression = self.resolve_expression(let_stmt.expression); @@ -1208,6 +1214,8 @@ impl<'a> Resolver<'a> { let end_range = self.resolve_expression(end_range); let (identifier, block) = (for_loop.identifier, for_loop.block); + self.nested_loops += 1; + // TODO: For loop variables are currently mutable by default since we haven't // yet implemented syntax for them to be optionally mutable. let (identifier, block) = self.in_new_scope(|this| { @@ -1220,6 +1228,8 @@ impl<'a> Resolver<'a> { (decl, this.resolve_expression(block)) }); + self.nested_loops -= 1; + HirStatement::For(HirForStatement { start_range, end_range, @@ -1230,10 +1240,18 @@ impl<'a> Resolver<'a> { range @ ForRange::Array(_) => { let for_stmt = range.into_for(for_loop.identifier, for_loop.block, for_loop.span); - self.resolve_stmt(for_stmt) + self.resolve_stmt(for_stmt, for_loop.span) } } } + StatementKind::Break => { + self.check_break_continue(true, span); + HirStatement::Break + } + StatementKind::Continue => { + self.check_break_continue(false, span); + HirStatement::Continue + } StatementKind::Error => HirStatement::Error, } } @@ -1256,13 +1274,17 @@ impl<'a> Resolver<'a> { let is_in_stdlib = self.path_resolver.module_id().krate.is_stdlib(); let assert_msg_call_path = if is_in_stdlib { ExpressionKind::Variable(Path { - segments: vec![Ident::from("resolve_assert_message")], + segments: vec![Ident::from("internal"), Ident::from("resolve_assert_message")], kind: PathKind::Crate, span, }) } else { ExpressionKind::Variable(Path { - segments: vec![Ident::from("std"), Ident::from("resolve_assert_message")], + segments: vec![ + Ident::from("std"), + Ident::from("internal"), + Ident::from("resolve_assert_message"), + ], kind: PathKind::Dep, span, }) @@ -1276,8 +1298,8 @@ impl<'a> Resolver<'a> { Some(self.resolve_expression(assert_msg_call_expr)) } - pub fn intern_stmt(&mut self, stmt: StatementKind) -> StmtId { - let hir_stmt = self.resolve_stmt(stmt); + pub fn intern_stmt(&mut self, stmt: Statement) -> StmtId { + let hir_stmt = self.resolve_stmt(stmt.kind, stmt.span); self.interner.push_stmt(hir_stmt) } @@ -1289,75 +1311,27 @@ impl<'a> Resolver<'a> { HirLValue::Ident(ident.0, Type::Error) } - LValue::MemberAccess { object, field_name } => { - let object = Box::new(self.resolve_lvalue(*object)); - HirLValue::MemberAccess { object, field_name, field_index: None, typ: Type::Error } - } - LValue::Index { array, index } => { + LValue::MemberAccess { object, field_name, span } => HirLValue::MemberAccess { + object: Box::new(self.resolve_lvalue(*object)), + field_name, + location: Location::new(span, self.file), + field_index: None, + typ: Type::Error, + }, + LValue::Index { array, index, span } => { let array = Box::new(self.resolve_lvalue(*array)); let index = self.resolve_expression(index); - HirLValue::Index { array, index, typ: Type::Error } + let location = Location::new(span, self.file); + HirLValue::Index { array, index, location, typ: Type::Error } } - LValue::Dereference(lvalue) => { + LValue::Dereference(lvalue, span) => { let lvalue = Box::new(self.resolve_lvalue(*lvalue)); - HirLValue::Dereference { lvalue, element_type: Type::Error } - } - } - } - - // Issue an error if the given private function is being called from a non-child module, or - // if the given pub(crate) function is being called from another crate - fn check_can_reference_function( - &mut self, - func: FuncId, - span: Span, - visibility: FunctionVisibility, - ) { - let function_module = self.interner.function_module(func); - let current_module = self.path_resolver.module_id(); - - let same_crate = function_module.krate == current_module.krate; - let krate = function_module.krate; - let current_module = current_module.local_id; - let name = self.interner.function_name(&func).to_string(); - match visibility { - FunctionVisibility::Public => (), - FunctionVisibility::Private => { - if !same_crate - || !self.module_descendent_of_target( - krate, - function_module.local_id, - current_module, - ) - { - self.errors.push(ResolverError::PrivateFunctionCalled { span, name }); - } - } - FunctionVisibility::PublicCrate => { - if !same_crate { - self.errors.push(ResolverError::NonCrateFunctionCalled { span, name }); - } + let location = Location::new(span, self.file); + HirLValue::Dereference { lvalue, location, element_type: Type::Error } } } } - // Returns true if `current` is a (potentially nested) child module of `target`. - // This is also true if `current == target`. - fn module_descendent_of_target( - &self, - krate: CrateId, - target: LocalModuleId, - current: LocalModuleId, - ) -> bool { - if current == target { - return true; - } - - self.def_maps[&krate].modules[current.0] - .parent - .map_or(false, |parent| self.module_descendent_of_target(krate, target, parent)) - } - fn resolve_local_variable(&mut self, hir_ident: HirIdent, var_scope_index: usize) { let mut transitive_capture_index: Option = None; @@ -1392,27 +1366,37 @@ impl<'a> Resolver<'a> { } } + fn resolve_array_literal(&mut self, array_literal: ArrayLiteral) -> HirArrayLiteral { + match array_literal { + ArrayLiteral::Standard(elements) => { + let elements = vecmap(elements, |elem| self.resolve_expression(elem)); + HirArrayLiteral::Standard(elements) + } + ArrayLiteral::Repeated { repeated_element, length } => { + let span = length.span; + let length = + UnresolvedTypeExpression::from_expr(*length, span).unwrap_or_else(|error| { + self.errors.push(ResolverError::ParserError(Box::new(error))); + UnresolvedTypeExpression::Constant(0, span) + }); + + let length = self.convert_expression_type(length); + let repeated_element = self.resolve_expression(*repeated_element); + + HirArrayLiteral::Repeated { repeated_element, length } + } + } + } + pub fn resolve_expression(&mut self, expr: Expression) -> ExprId { let hir_expr = match expr.kind { ExpressionKind::Literal(literal) => HirExpression::Literal(match literal { Literal::Bool(b) => HirLiteral::Bool(b), - Literal::Array(ArrayLiteral::Standard(elements)) => { - let elements = vecmap(elements, |elem| self.resolve_expression(elem)); - HirLiteral::Array(HirArrayLiteral::Standard(elements)) + Literal::Array(array_literal) => { + HirLiteral::Array(self.resolve_array_literal(array_literal)) } - Literal::Array(ArrayLiteral::Repeated { repeated_element, length }) => { - let span = length.span; - let length = UnresolvedTypeExpression::from_expr(*length, span).unwrap_or_else( - |error| { - self.errors.push(ResolverError::ParserError(Box::new(error))); - UnresolvedTypeExpression::Constant(0, span) - }, - ); - - let length = self.convert_expression_type(length); - let repeated_element = self.resolve_expression(*repeated_element); - - HirLiteral::Array(HirArrayLiteral::Repeated { repeated_element, length }) + Literal::Slice(array_literal) => { + HirLiteral::Slice(self.resolve_array_literal(array_literal)) } Literal::Integer(integer, sign) => HirLiteral::Integer(integer, sign), Literal::Str(str) => HirLiteral::Str(str), @@ -1441,17 +1425,6 @@ impl<'a> Resolver<'a> { if let Some(current_item) = self.current_item { self.interner.add_function_dependency(current_item, id); } - - if self.interner.function_visibility(id) - != FunctionVisibility::Public - { - let span = hir_ident.location.span; - self.check_can_reference_function( - id, - span, - self.interner.function_visibility(id), - ); - } } DefinitionKind::Global(global_id) => { if let Some(current_item) = self.current_item { @@ -1599,6 +1572,9 @@ impl<'a> Resolver<'a> { }) }), ExpressionKind::Parenthesized(sub_expr) => return self.resolve_expression(*sub_expr), + + // The quoted expression isn't resolved since we don't want errors if variables aren't defined + ExpressionKind::Quote(block) => HirExpression::Quote(block), }; // If these lines are ever changed, make sure to change the early return @@ -1887,7 +1863,7 @@ impl<'a> Resolver<'a> { } if let Ok(ModuleDefId::TraitId(trait_id)) = - self.path_resolver.resolve(self.def_maps, trait_bound.trait_path.clone()) + self.resolve_path(trait_bound.trait_path.clone()) { let the_trait = self.interner.get_trait(trait_id); if let Some(method) = @@ -1922,13 +1898,19 @@ impl<'a> Resolver<'a> { } fn resolve_path(&mut self, path: Path) -> Result { - self.path_resolver.resolve(self.def_maps, path).map_err(ResolverError::PathResolutionError) + let path_resolution = self.path_resolver.resolve(self.def_maps, path)?; + + if let Some(error) = path_resolution.error { + self.push_err(error.into()); + } + + Ok(path_resolution.module_def_id) } fn resolve_block(&mut self, block_expr: BlockExpression) -> HirExpression { let statements = - self.in_new_scope(|this| vecmap(block_expr.0, |stmt| this.intern_stmt(stmt.kind))); - HirExpression::Block(HirBlockExpression(statements)) + self.in_new_scope(|this| vecmap(block_expr.statements, |stmt| this.intern_stmt(stmt))); + HirExpression::Block(HirBlockExpression { statements }) } pub fn intern_block(&mut self, block: BlockExpression) -> ExprId { @@ -1961,10 +1943,65 @@ impl<'a> Resolver<'a> { rhs: ExprId, span: Span, ) -> Result> { + // Arbitrary amount of recursive calls to try before giving up + let fuel = 100; + self.try_eval_array_length_id_with_fuel(rhs, span, fuel) + } + + fn try_eval_array_length_id_with_fuel( + &self, + rhs: ExprId, + span: Span, + fuel: u32, + ) -> Result> { + if fuel == 0 { + // If we reach here, it is likely from evaluating cyclic globals. We expect an error to + // be issued for them after name resolution so issue no error now. + return Err(None); + } + match self.interner.expression(&rhs) { HirExpression::Literal(HirLiteral::Integer(int, false)) => { int.try_into_u128().ok_or(Some(ResolverError::IntegerTooLarge { span })) } + HirExpression::Ident(ident) => { + let definition = self.interner.definition(ident.id); + match definition.kind { + DefinitionKind::Global(global_id) => { + let let_statement = self.interner.get_global_let_statement(global_id); + if let Some(let_statement) = let_statement { + let expression = let_statement.expression; + self.try_eval_array_length_id_with_fuel(expression, span, fuel - 1) + } else { + Err(Some(ResolverError::InvalidArrayLengthExpr { span })) + } + } + _ => Err(Some(ResolverError::InvalidArrayLengthExpr { span })), + } + } + HirExpression::Infix(infix) => { + let lhs = self.try_eval_array_length_id_with_fuel(infix.lhs, span, fuel - 1)?; + let rhs = self.try_eval_array_length_id_with_fuel(infix.rhs, span, fuel - 1)?; + + match infix.operator.kind { + BinaryOpKind::Add => Ok(lhs + rhs), + BinaryOpKind::Subtract => Ok(lhs - rhs), + BinaryOpKind::Multiply => Ok(lhs * rhs), + BinaryOpKind::Divide => Ok(lhs / rhs), + BinaryOpKind::Equal => Ok((lhs == rhs) as u128), + BinaryOpKind::NotEqual => Ok((lhs != rhs) as u128), + BinaryOpKind::Less => Ok((lhs < rhs) as u128), + BinaryOpKind::LessEqual => Ok((lhs <= rhs) as u128), + BinaryOpKind::Greater => Ok((lhs > rhs) as u128), + BinaryOpKind::GreaterEqual => Ok((lhs >= rhs) as u128), + BinaryOpKind::And => Ok(lhs & rhs), + BinaryOpKind::Or => Ok(lhs | rhs), + BinaryOpKind::Xor => Ok(lhs ^ rhs), + BinaryOpKind::ShiftRight => Ok(lhs >> rhs), + BinaryOpKind::ShiftLeft => Ok(lhs << rhs), + BinaryOpKind::Modulo => Ok(lhs % rhs), + } + } _other => Err(Some(ResolverError::InvalidArrayLengthExpr { span })), } } @@ -2000,86 +2037,12 @@ impl<'a> Resolver<'a> { HirLiteral::FmtStr(str, fmt_str_idents) } - /// Only sized types are valid to be used as main's parameters or the parameters to a contract - /// function. If the given type is not sized (e.g. contains a slice or NamedGeneric type), an - /// error is issued. - fn verify_type_valid_for_program_input(&mut self, typ: &UnresolvedType) { - match &typ.typ { - UnresolvedTypeData::FieldElement - | UnresolvedTypeData::Integer(_, _) - | UnresolvedTypeData::Bool - | UnresolvedTypeData::Unit - | UnresolvedTypeData::Error => (), - - UnresolvedTypeData::MutableReference(_) - | UnresolvedTypeData::Function(_, _, _) - | UnresolvedTypeData::FormatString(_, _) - | UnresolvedTypeData::TraitAsType(..) - | UnresolvedTypeData::Unspecified => { - let span = typ.span.expect("Function parameters should always have spans"); - self.push_err(ResolverError::InvalidTypeForEntryPoint { span }); - } - - UnresolvedTypeData::Array(length, element) => { - if let Some(length) = length { - self.verify_type_expression_valid_for_program_input(length); - } else { - let span = typ.span.expect("Function parameters should always have spans"); - self.push_err(ResolverError::InvalidTypeForEntryPoint { span }); - } - self.verify_type_valid_for_program_input(element); - } - UnresolvedTypeData::Expression(expression) => { - self.verify_type_expression_valid_for_program_input(expression); - } - UnresolvedTypeData::String(length) => { - if let Some(length) = length { - self.verify_type_expression_valid_for_program_input(length); - } else { - let span = typ.span.expect("Function parameters should always have spans"); - self.push_err(ResolverError::InvalidTypeForEntryPoint { span }); - } - } - UnresolvedTypeData::Named(path, generics, _) => { - // Since the type is named, we need to resolve it to see what it actually refers to - // in order to check whether it is valid. Since resolving it may lead to a - // resolution error, we have to truncate our error count to the previous count just - // in case. This is to ensure resolution errors are not issued twice when this type - // is later resolved properly. - let error_count = self.errors.len(); - let resolved = self.resolve_named_type(path.clone(), generics.clone(), &mut vec![]); - self.errors.truncate(error_count); - - if !resolved.is_valid_for_program_input() { - let span = typ.span.expect("Function parameters should always have spans"); - self.push_err(ResolverError::InvalidTypeForEntryPoint { span }); - } - } - UnresolvedTypeData::Tuple(elements) => { - for element in elements { - self.verify_type_valid_for_program_input(element); - } - } - UnresolvedTypeData::Parenthesized(typ) => self.verify_type_valid_for_program_input(typ), + fn check_break_continue(&mut self, is_break: bool, span: Span) { + if !self.in_unconstrained_fn { + self.push_err(ResolverError::JumpInConstrainedFn { is_break, span }); } - } - - fn verify_type_expression_valid_for_program_input(&mut self, expr: &UnresolvedTypeExpression) { - match expr { - UnresolvedTypeExpression::Constant(_, _) => (), - UnresolvedTypeExpression::Variable(path) => { - let error_count = self.errors.len(); - let resolved = self.resolve_named_type(path.clone(), vec![], &mut vec![]); - self.errors.truncate(error_count); - - if !resolved.is_valid_for_program_input() { - self.push_err(ResolverError::InvalidTypeForEntryPoint { span: path.span() }); - } - } - UnresolvedTypeExpression::BinaryOperation(lhs, _, rhs, _) => { - self.verify_type_expression_valid_for_program_input(lhs); - self.verify_type_expression_valid_for_program_input(rhs); - } + if self.nested_loops == 0 { + self.push_err(ResolverError::JumpOutsideLoop { is_break, span }); } } } diff --git a/compiler/noirc_frontend/src/hir/resolution/traits.rs b/compiler/noirc_frontend/src/hir/resolution/traits.rs index 8f966be312b..a7669f57e33 100644 --- a/compiler/noirc_frontend/src/hir/resolution/traits.rs +++ b/compiler/noirc_frontend/src/hir/resolution/traits.rs @@ -8,9 +8,7 @@ use crate::{ graph::CrateId, hir::{ def_collector::{ - dc_crate::{ - check_methods_signatures, CompilationError, UnresolvedTrait, UnresolvedTraitImpl, - }, + dc_crate::{CompilationError, UnresolvedTrait, UnresolvedTraitImpl}, errors::{DefCollectorErrorKind, DuplicateType}, }, def_map::{CrateDefMap, ModuleDefId, ModuleId}, @@ -18,11 +16,12 @@ use crate::{ }, hir_def::traits::{TraitConstant, TraitFunction, TraitImpl, TraitType}, node_interner::{FuncId, NodeInterner, TraitId}, - Generics, Path, Shared, TraitItem, Type, TypeVariable, TypeVariableKind, + Generics, ItemVisibility, Path, Shared, TraitItem, Type, TypeVariable, TypeVariableKind, }; use super::{ functions, get_module_mut, get_struct_type, + import::{PathResolution, PathResolutionError}, path_resolver::{PathResolver, StandardPathResolver}, resolver::Resolver, take_errors, @@ -131,6 +130,7 @@ fn resolve_trait_methods( let func_id = unresolved_trait.method_ids[&name.0.contents]; let (_, func_meta) = resolver.resolve_trait_function( name, + generics, parameters, return_type, where_clause, @@ -275,7 +275,15 @@ fn collect_trait_impl( let module = ModuleId { local_id: trait_impl.module_id, krate: crate_id }; trait_impl.trait_id = match resolve_trait_by_path(def_maps, module, trait_impl.trait_path.clone()) { - Ok(trait_id) => Some(trait_id), + Ok((trait_id, warning)) => { + if let Some(warning) = warning { + errors.push(( + DefCollectorErrorKind::PathResolutionError(warning).into(), + trait_impl.file_id, + )); + } + Some(trait_id) + } Err(error) => { errors.push((error.into(), trait_impl.file_id)); None @@ -302,7 +310,14 @@ fn collect_trait_impl( // be accessed with the `TypeName::method` syntax. We'll check later whether the // object types in each method overlap or not. If they do, we issue an error. // If not, that is specialization which is allowed. - if module.declare_function(method.name_ident().clone(), *method_id).is_err() { + if module + .declare_function( + method.name_ident().clone(), + ItemVisibility::Public, + *method_id, + ) + .is_err() + { module.remove_function(method.name_ident()); } } @@ -356,15 +371,18 @@ pub(crate) fn resolve_trait_by_path( def_maps: &BTreeMap, module: ModuleId, path: Path, -) -> Result { +) -> Result<(TraitId, Option), DefCollectorErrorKind> { let path_resolver = StandardPathResolver::new(module); match path_resolver.resolve(def_maps, path.clone()) { - Ok(ModuleDefId::TraitId(trait_id)) => Ok(trait_id), + Ok(PathResolution { module_def_id: ModuleDefId::TraitId(trait_id), error }) => { + Ok((trait_id, error)) + } Ok(_) => Err(DefCollectorErrorKind::NotATrait { not_a_trait_name: path }), Err(_) => Err(DefCollectorErrorKind::TraitNotFound { trait_path: path }), } } + pub(crate) fn resolve_trait_impls( context: &mut Context, traits: Vec, @@ -424,17 +442,6 @@ pub(crate) fn resolve_trait_impls( new_resolver.set_self_type(Some(self_type.clone())); if let Some(trait_id) = maybe_trait_id { - check_methods_signatures( - &mut new_resolver, - &impl_methods, - trait_id, - trait_impl.trait_path.span(), - trait_impl.trait_generics, - trait_impl.generics.len(), - trait_impl.file_id, - errors, - ); - let where_clause = trait_impl .where_clause .into_iter() diff --git a/compiler/noirc_frontend/src/hir/type_check/errors.rs b/compiler/noirc_frontend/src/hir/type_check/errors.rs index 96d30100d8b..6c28aabe0fb 100644 --- a/compiler/noirc_frontend/src/hir/type_check/errors.rs +++ b/compiler/noirc_frontend/src/hir/type_check/errors.rs @@ -44,7 +44,7 @@ pub enum TypeCheckError { #[error("Expected type {expected} is not the same as {actual}")] TypeMismatchWithSource { expected: Type, actual: Type, span: Span, source: Source }, #[error("Expected {expected:?} found {found:?}")] - ArityMisMatch { expected: u16, found: u16, span: Span }, + ArityMisMatch { expected: usize, found: usize, span: Span }, #[error("Return type in a function cannot be public")] PublicReturnType { typ: Type, span: Span }, #[error("Cannot cast type {from}, 'as' is only for primitive field or integer types")] @@ -53,8 +53,10 @@ pub enum TypeCheckError { ExpectedFunction { found: Type, span: Span }, #[error("Type {lhs_type} has no member named {field_name}")] AccessUnknownMember { lhs_type: Type, field_name: String, span: Span }, - #[error("Function expects {expected} parameters but {found} given")] + #[error("Function expects {expected} parameters but {found} were given")] ParameterCountMismatch { expected: usize, found: usize, span: Span }, + #[error("{item} expects {expected} generics but {found} were given")] + GenericCountMismatch { item: String, expected: usize, found: usize, span: Span }, #[error("Only integer and Field types may be casted to")] UnsupportedCast { span: Span }, #[error("Index {index} is out of bounds for this tuple {lhs_type} of length {length}")] @@ -63,8 +65,6 @@ pub enum TypeCheckError { VariableMustBeMutable { name: String, span: Span }, #[error("No method named '{method_name}' found for type '{object_type}'")] UnresolvedMethodCall { method_name: String, object_type: Type, span: Span }, - #[error("Comparisons are invalid on Field types. Try casting the operands to a sized integer type first")] - InvalidComparisonOnField { span: Span }, #[error("Integers must have the same signedness LHS is {sign_x:?}, RHS is {sign_y:?}")] IntegerSignedness { sign_x: Signedness, sign_y: Signedness, span: Span }, #[error("Integers must have the same bit width LHS is {bit_width_x}, RHS is {bit_width_y}")] @@ -74,7 +74,7 @@ pub enum TypeCheckError { #[error("{kind} cannot be used in a unary operation")] InvalidUnaryOp { kind: String, span: Span }, #[error("Bitwise operations are invalid on Field types. Try casting the operands to a sized integer type first.")] - InvalidBitwiseOperationOnField { span: Span }, + FieldBitwiseOp { span: Span }, #[error("Integer cannot be used with type {typ}")] IntegerTypeMismatch { typ: Type, span: Span }, #[error("Cannot use an integer and a Field in a binary operation, try converting the Field into an integer first")] @@ -120,8 +120,26 @@ pub enum TypeCheckError { "Cannot pass a mutable reference from a constrained runtime to an unconstrained runtime" )] ConstrainedReferenceToUnconstrained { span: Span }, + #[error( + "Cannot pass a mutable reference from a unconstrained runtime to an constrained runtime" + )] + UnconstrainedReferenceToConstrained { span: Span }, #[error("Slices cannot be returned from an unconstrained runtime to a constrained runtime")] UnconstrainedSliceReturnToConstrained { span: Span }, + #[error("Slices must have constant length")] + NonConstantSliceLength { span: Span }, + #[error("Only sized types may be used in the entry point to a program")] + InvalidTypeForEntryPoint { span: Span }, + #[error("Mismatched number of parameters in trait implementation")] + MismatchTraitImplNumParameters { + actual_num_parameters: usize, + expected_num_parameters: usize, + trait_name: String, + method_name: String, + span: Span, + }, + #[error("Strings do not support indexed assignment")] + StringIndexAssign { span: Span }, } impl TypeCheckError { @@ -191,6 +209,12 @@ impl From for Diagnostic { let msg = format!("Function expects {expected} parameter{empty_or_s} but {found} {was_or_were} given"); Diagnostic::simple_error(msg, String::new(), span) } + TypeCheckError::GenericCountMismatch { item, expected, found, span } => { + let empty_or_s = if expected == 1 { "" } else { "s" }; + let was_or_were = if found == 1 { "was" } else { "were" }; + let msg = format!("{item} expects {expected} generic{empty_or_s} but {found} {was_or_were} given"); + Diagnostic::simple_error(msg, String::new(), span) + } TypeCheckError::InvalidCast { span, .. } | TypeCheckError::ExpectedFunction { span, .. } | TypeCheckError::AccessUnknownMember { span, .. } @@ -198,12 +222,11 @@ impl From for Diagnostic { | TypeCheckError::TupleIndexOutOfBounds { span, .. } | TypeCheckError::VariableMustBeMutable { span, .. } | TypeCheckError::UnresolvedMethodCall { span, .. } - | TypeCheckError::InvalidComparisonOnField { span } | TypeCheckError::IntegerSignedness { span, .. } | TypeCheckError::IntegerBitWidth { span, .. } | TypeCheckError::InvalidInfixOp { span, .. } | TypeCheckError::InvalidUnaryOp { span, .. } - | TypeCheckError::InvalidBitwiseOperationOnField { span, .. } + | TypeCheckError::FieldBitwiseOp { span, .. } | TypeCheckError::IntegerTypeMismatch { span, .. } | TypeCheckError::FieldComparison { span, .. } | TypeCheckError::AmbiguousBitWidth { span, .. } @@ -211,7 +234,10 @@ impl From for Diagnostic { | TypeCheckError::OverflowingAssignment { span, .. } | TypeCheckError::FieldModulo { span } | TypeCheckError::ConstrainedReferenceToUnconstrained { span } - | TypeCheckError::UnconstrainedSliceReturnToConstrained { span } => { + | TypeCheckError::UnconstrainedReferenceToConstrained { span } + | TypeCheckError::UnconstrainedSliceReturnToConstrained { span } + | TypeCheckError::NonConstantSliceLength { span } + | TypeCheckError::StringIndexAssign { span } => { Diagnostic::simple_error(error.to_string(), String::new(), span) } TypeCheckError::PublicReturnType { typ, span } => Diagnostic::simple_error( @@ -284,6 +310,21 @@ impl From for Diagnostic { let msg = format!("Constraint for `{typ}: {trait_name}` is not needed, another matching impl is already in scope"); Diagnostic::simple_warning(msg, "Unnecessary trait constraint in where clause".into(), span) } + TypeCheckError::InvalidTypeForEntryPoint { span } => Diagnostic::simple_error( + "Only sized types may be used in the entry point to a program".to_string(), + "Slices, references, or any type containing them may not be used in main, contract functions, or foldable functions".to_string(), span), + TypeCheckError::MismatchTraitImplNumParameters { + expected_num_parameters, + actual_num_parameters, + trait_name, + method_name, + span, + } => { + let plural = if expected_num_parameters == 1 { "" } else { "s" }; + let primary_message = format!( + "`{trait_name}::{method_name}` expects {expected_num_parameters} parameter{plural}, but this method has {actual_num_parameters}"); + Diagnostic::simple_error(primary_message, "".to_string(), span) + } } } } diff --git a/compiler/noirc_frontend/src/hir/type_check/expr.rs b/compiler/noirc_frontend/src/hir/type_check/expr.rs index b78f07c88f2..b56e2dce2a9 100644 --- a/compiler/noirc_frontend/src/hir/type_check/expr.rs +++ b/compiler/noirc_frontend/src/hir/type_check/expr.rs @@ -48,6 +48,49 @@ impl<'interner> TypeChecker<'interner> { false } + fn check_hir_array_literal( + &mut self, + hir_array_literal: HirArrayLiteral, + ) -> (Result>, Box) { + match hir_array_literal { + HirArrayLiteral::Standard(arr) => { + let elem_types = vecmap(&arr, |arg| self.check_expression(arg)); + + let first_elem_type = elem_types + .first() + .cloned() + .unwrap_or_else(|| self.interner.next_type_variable()); + + // Check if the array is homogeneous + for (index, elem_type) in elem_types.iter().enumerate().skip(1) { + let location = self.interner.expr_location(&arr[index]); + + elem_type.unify(&first_elem_type, &mut self.errors, || { + TypeCheckError::NonHomogeneousArray { + first_span: self.interner.expr_location(&arr[0]).span, + first_type: first_elem_type.to_string(), + first_index: index, + second_span: location.span, + second_type: elem_type.to_string(), + second_index: index + 1, + } + .add_context("elements in an array must have the same type") + }); + } + + (Ok(arr.len() as u64), Box::new(first_elem_type.clone())) + } + HirArrayLiteral::Repeated { repeated_element, length } => { + let elem_type = self.check_expression(&repeated_element); + let length = match length { + Type::Constant(length) => Ok(length), + other => Err(Box::new(other)), + }; + (length, Box::new(elem_type)) + } + } + } + /// Infers a type for a given expression, and return this type. /// As a side-effect, this function will also remember this type in the NodeInterner /// for the given expr_id key. @@ -59,64 +102,42 @@ impl<'interner> TypeChecker<'interner> { pub(crate) fn check_expression(&mut self, expr_id: &ExprId) -> Type { let typ = match self.interner.expression(expr_id) { HirExpression::Ident(ident) => self.check_ident(ident, expr_id), - HirExpression::Literal(literal) => { - match literal { - HirLiteral::Array(HirArrayLiteral::Standard(arr)) => { - let elem_types = vecmap(&arr, |arg| self.check_expression(arg)); - - let first_elem_type = elem_types - .first() - .cloned() - .unwrap_or_else(|| self.interner.next_type_variable()); - - let arr_type = Type::Array( - Box::new(Type::constant_variable(arr.len() as u64, self.interner)), - Box::new(first_elem_type.clone()), - ); - - // Check if the array is homogeneous - for (index, elem_type) in elem_types.iter().enumerate().skip(1) { - let location = self.interner.expr_location(&arr[index]); - - elem_type.unify(&first_elem_type, &mut self.errors, || { - TypeCheckError::NonHomogeneousArray { - first_span: self.interner.expr_location(&arr[0]).span, - first_type: first_elem_type.to_string(), - first_index: index, - second_span: location.span, - second_type: elem_type.to_string(), - second_index: index + 1, - } - .add_context("elements in an array must have the same type") + HirExpression::Literal(literal) => match literal { + HirLiteral::Array(hir_array_literal) => { + let (length, elem_type) = self.check_hir_array_literal(hir_array_literal); + Type::Array( + length.map_or_else( + |typ| typ, + |constant| Box::new(Type::constant_variable(constant, self.interner)), + ), + elem_type, + ) + } + HirLiteral::Slice(hir_array_literal) => { + let (length_type, elem_type) = self.check_hir_array_literal(hir_array_literal); + match length_type { + Ok(_length) => Type::Slice(elem_type), + Err(_non_constant) => { + self.errors.push(TypeCheckError::NonConstantSliceLength { + span: self.interner.expr_span(expr_id), }); + Type::Error } - - arr_type - } - HirLiteral::Array(HirArrayLiteral::Repeated { repeated_element, length }) => { - let elem_type = self.check_expression(&repeated_element); - let length = match length { - Type::Constant(length) => { - Type::constant_variable(length, self.interner) - } - other => other, - }; - Type::Array(Box::new(length), Box::new(elem_type)) } - HirLiteral::Bool(_) => Type::Bool, - HirLiteral::Integer(_, _) => Type::polymorphic_integer_or_field(self.interner), - HirLiteral::Str(string) => { - let len = Type::Constant(string.len() as u64); - Type::String(Box::new(len)) - } - HirLiteral::FmtStr(string, idents) => { - let len = Type::Constant(string.len() as u64); - let types = vecmap(&idents, |elem| self.check_expression(elem)); - Type::FmtString(Box::new(len), Box::new(Type::Tuple(types))) - } - HirLiteral::Unit => Type::Unit, } - } + HirLiteral::Bool(_) => Type::Bool, + HirLiteral::Integer(_, _) => self.polymorphic_integer_or_field(), + HirLiteral::Str(string) => { + let len = Type::Constant(string.len() as u64); + Type::String(Box::new(len)) + } + HirLiteral::FmtStr(string, idents) => { + let len = Type::Constant(string.len() as u64); + let types = vecmap(&idents, |elem| self.check_expression(elem)); + Type::FmtString(Box::new(len), Box::new(Type::Tuple(types))) + } + HirLiteral::Unit => Type::Unit, + }, HirExpression::Infix(infix_expr) => { // The type of the infix expression must be looked up from a type table let lhs_type = self.check_expression(&infix_expr.lhs); @@ -131,14 +152,16 @@ impl<'interner> TypeChecker<'interner> { Ok((typ, use_impl)) => { if use_impl { let id = infix_expr.trait_method_id; - // Assume operators have no trait generics - self.verify_trait_constraint( - &lhs_type, - id.trait_id, - &[], - *expr_id, - span, - ); + + // Delay checking the trait constraint until the end of the function. + // Checking it now could bind an unbound type variable to any type + // that implements the trait. + let constraint = crate::hir_def::traits::TraitConstraint { + typ: lhs_type.clone(), + trait_id: id.trait_id, + trait_generics: Vec::new(), + }; + self.trait_constraints.push((constraint, *expr_id)); self.typecheck_operator_method(*expr_id, id, &lhs_type, span); } typ @@ -184,15 +207,19 @@ impl<'interner> TypeChecker<'interner> { let return_type = self.bind_function_type(function, args, span); // Check that we are not passing a slice from an unconstrained runtime to a constrained runtime - if is_current_func_constrained - && is_unconstrained_call - && return_type.contains_slice() - { - self.errors.push(TypeCheckError::UnconstrainedSliceReturnToConstrained { - span: self.interner.expr_span(expr_id), - }); - return Type::Error; - } + if is_current_func_constrained && is_unconstrained_call { + if return_type.contains_slice() { + self.errors.push(TypeCheckError::UnconstrainedSliceReturnToConstrained { + span: self.interner.expr_span(expr_id), + }); + return Type::Error; + } else if matches!(&return_type.follow_bindings(), Type::MutableReference(_)) { + self.errors.push(TypeCheckError::UnconstrainedReferenceToConstrained { + span: self.interner.expr_span(expr_id), + }); + return Type::Error; + } + }; return_type } @@ -307,6 +334,7 @@ impl<'interner> TypeChecker<'interner> { Type::Function(params, Box::new(lambda.return_type), Box::new(env_type)) } + HirExpression::Quote(_) => Type::Code, }; self.interner.push_expr_type(*expr_id, typ.clone()); @@ -326,7 +354,10 @@ impl<'interner> TypeChecker<'interner> { assert_eq!(the_trait.generics.len(), constraint.trait_generics.len()); for (param, arg) in the_trait.generics.iter().zip(&constraint.trait_generics) { - bindings.insert(param.id(), (param.clone(), arg.clone())); + // Avoid binding t = t + if !arg.occurs(param.id()) { + bindings.insert(param.id(), (param.clone(), arg.clone())); + } } } @@ -387,23 +418,28 @@ impl<'interner> TypeChecker<'interner> { self.interner.select_impl_for_expression(function_ident_id, impl_kind); } Err(erroring_constraints) => { - // Don't show any errors where try_get_trait returns None. - // This can happen if a trait is used that was never declared. - let constraints = erroring_constraints - .into_iter() - .map(|constraint| { - let r#trait = self.interner.try_get_trait(constraint.trait_id)?; - let mut name = r#trait.name.to_string(); - if !constraint.trait_generics.is_empty() { - let generics = vecmap(&constraint.trait_generics, ToString::to_string); - name += &format!("<{}>", generics.join(", ")); - } - Some((constraint.typ, name)) - }) - .collect::>>(); + if erroring_constraints.is_empty() { + self.errors.push(TypeCheckError::TypeAnnotationsNeeded { span }); + } else { + // Don't show any errors where try_get_trait returns None. + // This can happen if a trait is used that was never declared. + let constraints = erroring_constraints + .into_iter() + .map(|constraint| { + let r#trait = self.interner.try_get_trait(constraint.trait_id)?; + let mut name = r#trait.name.to_string(); + if !constraint.trait_generics.is_empty() { + let generics = + vecmap(&constraint.trait_generics, ToString::to_string); + name += &format!("<{}>", generics.join(", ")); + } + Some((constraint.typ, name)) + }) + .collect::>>(); - if let Some(constraints) = constraints { - self.errors.push(TypeCheckError::NoMatchingImplFound { constraints, span }); + if let Some(constraints) = constraints { + self.errors.push(TypeCheckError::NoMatchingImplFound { constraints, span }); + } } } } @@ -529,15 +565,13 @@ impl<'interner> TypeChecker<'interner> { let index_type = self.check_expression(&index_expr.index); let span = self.interner.expr_span(&index_expr.index); - index_type.unify( - &Type::polymorphic_integer_or_field(self.interner), - &mut self.errors, - || TypeCheckError::TypeMismatch { + index_type.unify(&self.polymorphic_integer_or_field(), &mut self.errors, || { + TypeCheckError::TypeMismatch { expected_typ: "an integer".to_owned(), expr_typ: index_type.to_string(), expr_span: span, - }, - ); + } + }); // When writing `a[i]`, if `a : &mut ...` then automatically dereference `a` as many // times as needed to get the underlying array. @@ -550,6 +584,7 @@ impl<'interner> TypeChecker<'interner> { // XXX: We can check the array bounds here also, but it may be better to constant fold first // and have ConstId instead of ExprId for constants Type::Array(_, base_type) => *base_type, + Type::Slice(base_type) => *base_type, Type::Error => Type::Error, typ => { let span = self.interner.expr_span(&new_lhs); @@ -806,6 +841,10 @@ impl<'interner> TypeChecker<'interner> { match (lhs_type, rhs_type) { // Avoid reporting errors multiple times (Error, _) | (_, Error) => Ok((Bool, false)), + (Alias(alias, args), other) | (other, Alias(alias, args)) => { + let alias = alias.borrow().get_type(args); + self.comparator_operand_type_rules(&alias, other, op, span) + } // Matches on TypeVariable must be first to follow any type // bindings. @@ -814,12 +853,8 @@ impl<'interner> TypeChecker<'interner> { return self.comparator_operand_type_rules(other, binding, op, span); } - self.bind_type_variables_for_infix(lhs_type, op, rhs_type, span); - Ok((Bool, false)) - } - (Alias(alias, args), other) | (other, Alias(alias, args)) => { - let alias = alias.borrow().get_type(args); - self.comparator_operand_type_rules(&alias, other, op, span) + let use_impl = self.bind_type_variables_for_infix(lhs_type, op, rhs_type, span); + Ok((Bool, use_impl)) } (Integer(sign_x, bit_width_x), Integer(sign_y, bit_width_y)) => { if sign_x != sign_y { @@ -860,7 +895,13 @@ impl<'interner> TypeChecker<'interner> { span: op.location.span, }); - self.comparator_operand_type_rules(x_type, y_type, op, span) + let (_, use_impl) = self.comparator_operand_type_rules(x_type, y_type, op, span)?; + + // If the size is not constant, we must fall back to a user-provided impl for + // equality on slices. + let size = x_size.follow_bindings(); + let use_impl = use_impl || size.evaluate_to_u64().is_none(); + Ok((Bool, use_impl)) } (String(x_size), String(y_size)) => { @@ -1031,9 +1072,9 @@ impl<'interner> TypeChecker<'interner> { } ret } + // ignoring env for subtype on purpose Type::Function(parameters, ret, _env) => { - // ignoring env for subtype on purpose - self.bind_function_type_impl(parameters.as_ref(), ret.as_ref(), args.as_ref(), span) + self.bind_function_type_impl(¶meters, &ret, &args, span) } Type::Error => Type::Error, found => { @@ -1043,13 +1084,16 @@ impl<'interner> TypeChecker<'interner> { } } + /// Handles the TypeVariable case for checking binary operators. + /// Returns true if we should use the impl for the operator instead of the primitive + /// version of it. fn bind_type_variables_for_infix( &mut self, lhs_type: &Type, op: &HirBinaryOp, rhs_type: &Type, span: Span, - ) { + ) -> bool { self.unify(lhs_type, rhs_type, || TypeCheckError::TypeMismatchWithSource { expected: lhs_type.clone(), actual: rhs_type.clone(), @@ -1057,22 +1101,26 @@ impl<'interner> TypeChecker<'interner> { span, }); - // In addition to unifying both types, we also have to bind either - // the lhs or rhs to an integer type variable. This ensures if both lhs - // and rhs are type variables, that they will have the correct integer - // type variable kind instead of TypeVariableKind::Normal. - let target = if op.kind.is_valid_for_field_type() { - Type::polymorphic_integer_or_field(self.interner) - } else { - Type::polymorphic_integer(self.interner) - }; + let use_impl = !lhs_type.is_numeric(); + + // If this operator isn't valid for fields we have to possibly narrow + // TypeVariableKind::IntegerOrField to TypeVariableKind::Integer. + // Doing so also ensures a type error if Field is used. + // The is_numeric check is to allow impls for custom types to bypass this. + if !op.kind.is_valid_for_field_type() && lhs_type.is_numeric() { + let target = Type::polymorphic_integer(self.interner); + + use BinaryOpKind::*; + use TypeCheckError::*; + self.unify(lhs_type, &target, || match op.kind { + Less | LessEqual | Greater | GreaterEqual => FieldComparison { span }, + And | Or | Xor | ShiftRight | ShiftLeft => FieldBitwiseOp { span }, + Modulo => FieldModulo { span }, + other => unreachable!("Operator {other:?} should be valid for Field"), + }); + } - self.unify(lhs_type, &target, || TypeCheckError::TypeMismatchWithSource { - expected: lhs_type.clone(), - actual: rhs_type.clone(), - source: Source::Binary, - span, - }); + use_impl } // Given a binary operator and another type. This method will produce the output type @@ -1094,6 +1142,10 @@ impl<'interner> TypeChecker<'interner> { match (lhs_type, rhs_type) { // An error type on either side will always return an error (Error, _) | (_, Error) => Ok((Error, false)), + (Alias(alias, args), other) | (other, Alias(alias, args)) => { + let alias = alias.borrow().get_type(args); + self.infix_operand_type_rules(&alias, op, other, span) + } // Matches on TypeVariable must be first so that we follow any type // bindings. @@ -1102,14 +1154,8 @@ impl<'interner> TypeChecker<'interner> { return self.infix_operand_type_rules(binding, op, other, span); } - self.bind_type_variables_for_infix(lhs_type, op, rhs_type, span); - - // Both types are unified so the choice of which to return is arbitrary - Ok((other.clone(), false)) - } - (Alias(alias, args), other) | (other, Alias(alias, args)) => { - let alias = alias.borrow().get_type(args); - self.infix_operand_type_rules(&alias, op, other, span) + let use_impl = self.bind_type_variables_for_infix(lhs_type, op, rhs_type, span); + Ok((other.clone(), use_impl)) } (Integer(sign_x, bit_width_x), Integer(sign_y, bit_width_y)) => { if sign_x != sign_y { @@ -1134,7 +1180,7 @@ impl<'interner> TypeChecker<'interner> { if op.kind == BinaryOpKind::Modulo { return Err(TypeCheckError::FieldModulo { span }); } else { - return Err(TypeCheckError::InvalidBitwiseOperationOnField { span }); + return Err(TypeCheckError::FieldBitwiseOp { span }); } } Ok((FieldElement, false)) @@ -1175,7 +1221,7 @@ impl<'interner> TypeChecker<'interner> { self.errors .push(TypeCheckError::InvalidUnaryOp { kind: rhs_type.to_string(), span }); } - let expected = Type::polymorphic_integer_or_field(self.interner); + let expected = self.polymorphic_integer_or_field(); rhs_type.unify(&expected, &mut self.errors, || TypeCheckError::InvalidUnaryOp { kind: rhs_type.to_string(), span, diff --git a/compiler/noirc_frontend/src/hir/type_check/mod.rs b/compiler/noirc_frontend/src/hir/type_check/mod.rs index 21d1c75a0f2..926dac30bcd 100644 --- a/compiler/noirc_frontend/src/hir/type_check/mod.rs +++ b/compiler/noirc_frontend/src/hir/type_check/mod.rs @@ -12,11 +12,17 @@ mod expr; mod stmt; pub use errors::TypeCheckError; +use noirc_errors::Span; use crate::{ - hir_def::{expr::HirExpression, stmt::HirStatement, traits::TraitConstraint}, + hir_def::{ + expr::HirExpression, + function::{Param, Parameters}, + stmt::HirStatement, + traits::TraitConstraint, + }, node_interner::{ExprId, FuncId, GlobalId, NodeInterner}, - Type, + Type, TypeBindings, }; use self::errors::Source; @@ -31,6 +37,11 @@ pub struct TypeChecker<'interner> { /// on each variable, but it is only until function calls when the types /// needed for the trait constraint may become known. trait_constraints: Vec<(TraitConstraint, ExprId)>, + + /// All type variables created in the current function. + /// This map is used to default any integer type variables at the end of + /// a function (before checking trait constraints) if a type wasn't already chosen. + type_variables: Vec, } /// Type checks a function and assigns the @@ -74,36 +85,19 @@ pub fn type_check_func(interner: &mut NodeInterner, func_id: FuncId) -> Vec Vec Vec Vec, + func_id: FuncId, + param: &Param, + errors: &mut Vec, +) { + let meta = type_checker.interner.function_meta(&func_id); + if (meta.is_entry_point || meta.should_fold) && !param.1.is_valid_for_program_input() { + let span = param.0.span(); + errors.push(TypeCheckError::InvalidTypeForEntryPoint { span }); + } +} + fn function_info(interner: &NodeInterner, function_body_id: &ExprId) -> (noirc_errors::Span, bool) { let (expr_span, empty_function) = if let HirExpression::Block(block) = interner.expression(function_body_id) { @@ -162,9 +198,163 @@ fn function_info(interner: &NodeInterner, function_body_id: &ExprId) -> (noirc_e (expr_span, empty_function) } +/// Checks that the type of a function in a trait impl matches the type +/// of the corresponding function declaration in the trait itself. +/// +/// To do this, given a trait such as: +/// `trait Foo { fn foo(...); }` +/// +/// And an impl such as: +/// `impl Foo for Bar { fn foo(...); } ` +/// +/// We have to substitute: +/// - Self for Bar +/// - A for D +/// - B for F +/// +/// Before we can type check. Finally, we must also check that the unification +/// result does not introduce any new bindings. This can happen if the impl +/// function's type is more general than that of the trait function. E.g. +/// `fn baz(a: A, b: B)` when the impl required `fn baz(a: A, b: A)`. +/// +/// This does not type check the body of the impl function. +pub(crate) fn check_trait_impl_method_matches_declaration( + interner: &mut NodeInterner, + function: FuncId, +) -> Vec { + let meta = interner.function_meta(&function); + let method_name = interner.function_name(&function); + let mut errors = Vec::new(); + + let definition_type = meta.typ.as_monotype(); + + let impl_ = + meta.trait_impl.expect("Trait impl function should have a corresponding trait impl"); + let impl_ = interner.get_trait_implementation(impl_); + let impl_ = impl_.borrow(); + let trait_info = interner.get_trait(impl_.trait_id); + + let mut bindings = TypeBindings::new(); + bindings.insert( + trait_info.self_type_typevar_id, + (trait_info.self_type_typevar.clone(), impl_.typ.clone()), + ); + + if trait_info.generics.len() != impl_.trait_generics.len() { + let expected = trait_info.generics.len(); + let found = impl_.trait_generics.len(); + let span = impl_.ident.span(); + let item = trait_info.name.to_string(); + errors.push(TypeCheckError::GenericCountMismatch { item, expected, found, span }); + } + + // Substitute each generic on the trait with the corresponding generic on the impl + for (generic, arg) in trait_info.generics.iter().zip(&impl_.trait_generics) { + bindings.insert(generic.id(), (generic.clone(), arg.clone())); + } + + // If this is None, the trait does not have the corresponding function. + // This error should have been caught in name resolution already so we don't + // issue an error for it here. + if let Some(trait_fn_id) = trait_info.method_ids.get(method_name) { + let trait_fn_meta = interner.function_meta(trait_fn_id); + + if trait_fn_meta.direct_generics.len() != meta.direct_generics.len() { + let expected = trait_fn_meta.direct_generics.len(); + let found = meta.direct_generics.len(); + let span = meta.name.location.span; + let item = method_name.to_string(); + errors.push(TypeCheckError::GenericCountMismatch { item, expected, found, span }); + } + + // Substitute each generic on the trait function with the corresponding generic on the impl function + for ((_, trait_fn_generic), (name, impl_fn_generic)) in + trait_fn_meta.direct_generics.iter().zip(&meta.direct_generics) + { + let arg = Type::NamedGeneric(impl_fn_generic.clone(), name.clone()); + bindings.insert(trait_fn_generic.id(), (trait_fn_generic.clone(), arg)); + } + + let (declaration_type, _) = trait_fn_meta.typ.instantiate_with_bindings(bindings, interner); + + check_function_type_matches_expected_type( + &declaration_type, + definition_type, + method_name, + &meta.parameters, + meta.name.location.span, + &trait_info.name.0.contents, + &mut errors, + ); + } + + errors +} + +fn check_function_type_matches_expected_type( + expected: &Type, + actual: &Type, + method_name: &str, + actual_parameters: &Parameters, + span: Span, + trait_name: &str, + errors: &mut Vec, +) { + let mut bindings = TypeBindings::new(); + // Shouldn't need to unify envs, they should always be equal since they're both free functions + if let (Type::Function(params_a, ret_a, _env_a), Type::Function(params_b, ret_b, _env_b)) = + (expected, actual) + { + if params_a.len() == params_b.len() { + for (i, (a, b)) in params_a.iter().zip(params_b.iter()).enumerate() { + if a.try_unify(b, &mut bindings).is_err() { + errors.push(TypeCheckError::TraitMethodParameterTypeMismatch { + method_name: method_name.to_string(), + expected_typ: a.to_string(), + actual_typ: b.to_string(), + parameter_span: actual_parameters.0[i].0.span(), + parameter_index: i + 1, + }); + } + } + + if ret_b.try_unify(ret_a, &mut bindings).is_err() { + errors.push(TypeCheckError::TypeMismatch { + expected_typ: ret_a.to_string(), + expr_typ: ret_b.to_string(), + expr_span: span, + }); + } + } else { + errors.push(TypeCheckError::MismatchTraitImplNumParameters { + actual_num_parameters: params_b.len(), + expected_num_parameters: params_a.len(), + trait_name: trait_name.to_string(), + method_name: method_name.to_string(), + span, + }); + } + } + + // If result bindings is not empty, a type variable was bound which means the two + // signatures were not a perfect match. Note that this relies on us already binding + // all the expected generics to each other prior to this check. + if !bindings.is_empty() { + let expected_typ = expected.to_string(); + let expr_typ = actual.to_string(); + errors.push(TypeCheckError::TypeMismatch { expected_typ, expr_typ, expr_span: span }); + } +} + impl<'interner> TypeChecker<'interner> { fn new(interner: &'interner mut NodeInterner) -> Self { - Self { interner, errors: Vec::new(), trait_constraints: Vec::new(), current_function: None } + Self { + interner, + errors: Vec::new(), + trait_constraints: Vec::new(), + type_variables: Vec::new(), + current_function: None, + } } fn check_function_body(&mut self, body: &ExprId) -> Type { @@ -179,6 +369,7 @@ impl<'interner> TypeChecker<'interner> { interner, errors: Vec::new(), trait_constraints: Vec::new(), + type_variables: Vec::new(), current_function: None, }; let statement = this.interner.get_global(id).let_statement; @@ -212,6 +403,22 @@ impl<'interner> TypeChecker<'interner> { make_error, ); } + + /// Return a fresh integer or field type variable and log it + /// in self.type_variables to default it later. + fn polymorphic_integer_or_field(&mut self) -> Type { + let typ = Type::polymorphic_integer_or_field(self.interner); + self.type_variables.push(typ.clone()); + typ + } + + /// Return a fresh integer type variable and log it + /// in self.type_variables to default it later. + fn polymorphic_integer(&mut self) -> Type { + let typ = Type::polymorphic_integer(self.interner); + self.type_variables.push(typ.clone()); + typ + } } // XXX: These tests are all manual currently. @@ -227,7 +434,9 @@ mod test { use crate::graph::CrateId; use crate::hir::def_map::{ModuleData, ModuleId}; - use crate::hir::resolution::import::PathResolutionError; + use crate::hir::resolution::import::{ + PathResolution, PathResolutionError, PathResolutionResult, + }; use crate::hir_def::expr::HirIdent; use crate::hir_def::stmt::HirLetStatement; use crate::hir_def::stmt::HirPattern::Identifier; @@ -297,7 +506,8 @@ mod test { expression: expr_id, }; let stmt_id = interner.push_stmt(HirStatement::Let(let_stmt)); - let expr_id = interner.push_expr(HirExpression::Block(HirBlockExpression(vec![stmt_id]))); + let expr_id = interner + .push_expr(HirExpression::Block(HirBlockExpression { statements: vec![stmt_id] })); interner.push_expr_location(expr_id, Span::single_char(0), file); // Create function to enclose the let statement @@ -329,6 +539,9 @@ mod test { trait_impl: None, return_type: FunctionReturnType::Default(Span::default()), trait_constraints: Vec::new(), + direct_generics: Vec::new(), + is_entry_point: true, + should_fold: false, }; interner.push_fn_meta(func_meta, func_id); @@ -387,12 +600,7 @@ mod test { "#; - let expected_num_errors = 0; - type_check_src_code_errors_expected( - src, - expected_num_errors, - vec![String::from("main"), String::from("foo")], - ); + type_check_src_code(src, vec![String::from("main"), String::from("foo")]); } #[test] fn basic_closure() { @@ -417,6 +625,19 @@ mod test { type_check_src_code(src, vec![String::from("main")]); } + + #[test] + fn fold_entry_point() { + let src = r#" + #[fold] + fn fold(x: &mut Field) -> Field { + *x + } + "#; + + type_check_src_code_errors_expected(src, vec![String::from("fold")], 1); + } + // This is the same Stub that is in the resolver, maybe we can pull this out into a test module and re-use? struct TestPathResolver(HashMap); @@ -425,12 +646,13 @@ mod test { &self, _def_maps: &BTreeMap, path: Path, - ) -> Result { + ) -> PathResolutionResult { // Not here that foo::bar and hello::foo::bar would fetch the same thing let name = path.segments.last().unwrap(); self.0 .get(&name.0.contents) .cloned() + .map(|module_def_id| PathResolution { module_def_id, error: None }) .ok_or_else(move || PathResolutionError::Unresolved(name.clone())) } @@ -450,15 +672,15 @@ mod test { } fn type_check_src_code(src: &str, func_namespace: Vec) { - type_check_src_code_errors_expected(src, 0, func_namespace); + type_check_src_code_errors_expected(src, func_namespace, 0); } // This function assumes that there is only one function and this is the // func id that is returned fn type_check_src_code_errors_expected( src: &str, - expected_number_errors: usize, func_namespace: Vec, + expected_num_type_check_errs: usize, ) { let (program, errors) = parse_program(src); let mut interner = NodeInterner::default(); @@ -466,9 +688,8 @@ mod test { assert_eq!( errors.len(), - expected_number_errors, - "expected {} errors, but got {}, errors: {:?}", - expected_number_errors, + 0, + "expected 0 parser errors, but got {}, errors: {:?}", errors.len(), errors ); @@ -514,6 +735,13 @@ mod test { // Type check section let errors = super::type_check_func(&mut interner, func_ids.first().cloned().unwrap()); - assert_eq!(errors, vec![]); + assert_eq!( + errors.len(), + expected_num_type_check_errs, + "expected {} type check errors, but got {}, errors: {:?}", + expected_num_type_check_errs, + errors.len(), + errors + ); } } diff --git a/compiler/noirc_frontend/src/hir/type_check/stmt.rs b/compiler/noirc_frontend/src/hir/type_check/stmt.rs index 358bea86922..fb57aa75f89 100644 --- a/compiler/noirc_frontend/src/hir/type_check/stmt.rs +++ b/compiler/noirc_frontend/src/hir/type_check/stmt.rs @@ -1,5 +1,5 @@ use iter_extended::vecmap; -use noirc_errors::{Location, Span}; +use noirc_errors::Span; use crate::hir_def::expr::{HirExpression, HirIdent, HirLiteral}; use crate::hir_def::stmt::{ @@ -51,7 +51,7 @@ impl<'interner> TypeChecker<'interner> { HirStatement::Constrain(constrain_stmt) => self.check_constrain_stmt(constrain_stmt), HirStatement::Assign(assign_stmt) => self.check_assign_stmt(assign_stmt, stmt_id), HirStatement::For(for_loop) => self.check_for_loop(for_loop), - HirStatement::Error => (), + HirStatement::Break | HirStatement::Continue | HirStatement::Error => (), } Type::Unit } @@ -71,7 +71,7 @@ impl<'interner> TypeChecker<'interner> { expr_span: range_span, }); - let expected_type = Type::polymorphic_integer(self.interner); + let expected_type = self.polymorphic_integer(); self.unify(&start_range_type, &expected_type, || TypeCheckError::TypeCannotBeUsed { typ: start_range_type.clone(), @@ -195,51 +195,51 @@ impl<'interner> TypeChecker<'interner> { (typ.clone(), HirLValue::Ident(ident.clone(), typ), mutable) } - HirLValue::MemberAccess { object, field_name, .. } => { + HirLValue::MemberAccess { object, field_name, location, .. } => { let (lhs_type, object, mut mutable) = self.check_lvalue(object, assign_span); let mut object = Box::new(object); - let span = field_name.span(); let field_name = field_name.clone(); let object_ref = &mut object; let mutable_ref = &mut mutable; + let location = *location; let dereference_lhs = move |_: &mut Self, _, element_type| { // We must create a temporary value first to move out of object_ref before // we eventually reassign to it. let id = DefinitionId::dummy_id(); - let location = Location::new(span, fm::FileId::dummy()); let ident = HirIdent::non_trait_method(id, location); let tmp_value = HirLValue::Ident(ident, Type::Error); let lvalue = std::mem::replace(object_ref, Box::new(tmp_value)); - *object_ref = Box::new(HirLValue::Dereference { lvalue, element_type }); + *object_ref = + Box::new(HirLValue::Dereference { lvalue, element_type, location }); *mutable_ref = true; }; let name = &field_name.0.contents; let (object_type, field_index) = self - .check_field_access(&lhs_type, name, span, Some(dereference_lhs)) + .check_field_access(&lhs_type, name, field_name.span(), Some(dereference_lhs)) .unwrap_or((Type::Error, 0)); let field_index = Some(field_index); let typ = object_type.clone(); - let lvalue = HirLValue::MemberAccess { object, field_name, field_index, typ }; + let lvalue = + HirLValue::MemberAccess { object, field_name, field_index, typ, location }; (object_type, lvalue, mutable) } - HirLValue::Index { array, index, .. } => { + HirLValue::Index { array, index, location, .. } => { let index_type = self.check_expression(index); let expr_span = self.interner.expr_span(index); + let location = *location; - index_type.unify( - &Type::polymorphic_integer_or_field(self.interner), - &mut self.errors, - || TypeCheckError::TypeMismatch { + index_type.unify(&self.polymorphic_integer_or_field(), &mut self.errors, || { + TypeCheckError::TypeMismatch { expected_typ: "an integer".to_owned(), expr_typ: index_type.to_string(), expr_span, - }, - ); + } + }); let (mut lvalue_type, mut lvalue, mut mutable) = self.check_lvalue(array, assign_span); @@ -248,7 +248,8 @@ impl<'interner> TypeChecker<'interner> { // as needed to unwrap any &mut wrappers. while let Type::MutableReference(element) = lvalue_type.follow_bindings() { let element_type = element.as_ref().clone(); - lvalue = HirLValue::Dereference { lvalue: Box::new(lvalue), element_type }; + lvalue = + HirLValue::Dereference { lvalue: Box::new(lvalue), element_type, location }; lvalue_type = *element; // We know this value to be mutable now since we found an `&mut` mutable = true; @@ -256,7 +257,13 @@ impl<'interner> TypeChecker<'interner> { let typ = match lvalue_type.follow_bindings() { Type::Array(_, elem_type) => *elem_type, + Type::Slice(elem_type) => *elem_type, Type::Error => Type::Error, + Type::String(_) => { + let (_lvalue_name, lvalue_span) = self.get_lvalue_name_and_span(&lvalue); + self.errors.push(TypeCheckError::StringIndexAssign { span: lvalue_span }); + Type::Error + } other => { // TODO: Need a better span here self.errors.push(TypeCheckError::TypeMismatch { @@ -269,11 +276,12 @@ impl<'interner> TypeChecker<'interner> { }; let array = Box::new(lvalue); - (typ.clone(), HirLValue::Index { array, index: *index, typ }, mutable) + (typ.clone(), HirLValue::Index { array, index: *index, typ, location }, mutable) } - HirLValue::Dereference { lvalue, element_type: _ } => { + HirLValue::Dereference { lvalue, element_type: _, location } => { let (reference_type, lvalue, _) = self.check_lvalue(lvalue, assign_span); let lvalue = Box::new(lvalue); + let location = *location; let element_type = Type::type_variable(self.interner.next_type_variable_id()); let expected_type = Type::MutableReference(Box::new(element_type.clone())); @@ -285,7 +293,11 @@ impl<'interner> TypeChecker<'interner> { }); // Dereferences are always mutable since we already type checked against a &mut T - (element_type.clone(), HirLValue::Dereference { lvalue, element_type }, true) + ( + element_type.clone(), + HirLValue::Dereference { lvalue, element_type, location }, + true, + ) } } } diff --git a/compiler/noirc_frontend/src/hir_def/expr.rs b/compiler/noirc_frontend/src/hir_def/expr.rs index b4c590de491..c2f6031bf6d 100644 --- a/compiler/noirc_frontend/src/hir_def/expr.rs +++ b/compiler/noirc_frontend/src/hir_def/expr.rs @@ -31,12 +31,13 @@ pub enum HirExpression { Tuple(Vec), Lambda(HirLambda), Error, + Quote(crate::BlockExpression), } impl HirExpression { /// Returns an empty block expression pub const fn empty_block() -> HirExpression { - HirExpression::Block(HirBlockExpression(vec![])) + HirExpression::Block(HirBlockExpression { statements: vec![] }) } } @@ -99,6 +100,7 @@ impl HirBinaryOp { #[derive(Debug, Clone)] pub enum HirLiteral { Array(HirArrayLiteral), + Slice(HirArrayLiteral), Bool(bool), Integer(FieldElement, bool), //true for negative integer and false for positive Str(String), @@ -247,11 +249,13 @@ pub struct HirIndexExpression { } #[derive(Debug, Clone)] -pub struct HirBlockExpression(pub Vec); +pub struct HirBlockExpression { + pub statements: Vec, +} impl HirBlockExpression { pub fn statements(&self) -> &[StmtId] { - &self.0 + &self.statements } } diff --git a/compiler/noirc_frontend/src/hir_def/function.rs b/compiler/noirc_frontend/src/hir_def/function.rs index d3ab2a9393b..a3bbc9445a8 100644 --- a/compiler/noirc_frontend/src/hir_def/function.rs +++ b/compiler/noirc_frontend/src/hir_def/function.rs @@ -1,12 +1,14 @@ use iter_extended::vecmap; use noirc_errors::{Location, Span}; +use std::rc::Rc; + use super::expr::{HirBlockExpression, HirExpression, HirIdent}; use super::stmt::HirPattern; use super::traits::TraitConstraint; use crate::node_interner::{ExprId, NodeInterner, TraitImplId}; use crate::FunctionKind; -use crate::{Distinctness, FunctionReturnType, Type, Visibility}; +use crate::{Distinctness, FunctionReturnType, Type, TypeVariable, Visibility}; /// A Hir function is a block expression /// with a list of statements @@ -103,6 +105,12 @@ pub struct FuncMeta { /// or a Type::Forall for generic functions. pub typ: Type, + /// The set of generics that are declared directly on this function in the source code. + /// This does not include generics from an outer scope, like those introduced by + /// an `impl` block. This also does not include implicit generics added by the compiler + /// such as a trait's `Self` type variable. + pub direct_generics: Vec<(Rc, TypeVariable)>, + pub location: Location, // This flag is needed for the attribute check pass @@ -112,6 +120,14 @@ pub struct FuncMeta { /// The trait impl this function belongs to, if any pub trait_impl: Option, + + /// True if this function is an entry point to the program. + /// For non-contracts, this means the function is `main`. + pub is_entry_point: bool, + + /// True if this function is marked with an attribute + /// that indicates it should not be inlined, such as for folding. + pub should_fold: bool, } impl FuncMeta { diff --git a/compiler/noirc_frontend/src/hir_def/stmt.rs b/compiler/noirc_frontend/src/hir_def/stmt.rs index b910be1fdda..c5e287b393c 100644 --- a/compiler/noirc_frontend/src/hir_def/stmt.rs +++ b/compiler/noirc_frontend/src/hir_def/stmt.rs @@ -14,6 +14,8 @@ pub enum HirStatement { Constrain(HirConstrainStatement), Assign(HirAssignStatement), For(HirForStatement), + Break, + Continue, Expression(ExprId), Semi(ExprId), Error, @@ -97,6 +99,15 @@ impl HirPattern { | HirPattern::Struct(_, _, location) => location.span, } } + + pub(crate) fn location(&self) -> Location { + match self { + HirPattern::Identifier(ident) => ident.location, + HirPattern::Mutable(_, location) + | HirPattern::Tuple(_, location) + | HirPattern::Struct(_, _, location) => *location, + } + } } /// Represents an Ast form that can be assigned to. These @@ -109,14 +120,17 @@ pub enum HirLValue { field_name: Ident, field_index: Option, typ: Type, + location: Location, }, Index { array: Box, index: ExprId, typ: Type, + location: Location, }, Dereference { lvalue: Box, element_type: Type, + location: Location, }, } diff --git a/compiler/noirc_frontend/src/hir_def/types.rs b/compiler/noirc_frontend/src/hir_def/types.rs index e105da1ccf0..ec8b54c33b8 100644 --- a/compiler/noirc_frontend/src/hir_def/types.rs +++ b/compiler/noirc_frontend/src/hir_def/types.rs @@ -27,6 +27,9 @@ pub enum Type { /// is either a type variable of some kind or a Type::Constant. Array(Box, Box), + /// Slice(E) is a slice of elements of type E. + Slice(Box), + /// A primitive integer type with the given sign and bit count. /// E.g. `u32` would be `Integer(Unsigned, ThirtyTwo)` Integer(Signedness, IntegerBitSize), @@ -98,10 +101,8 @@ pub enum Type { /// bind to an integer without special checks to bind it to a non-type. Constant(u64), - /// The type of a slice is an array of size NotConstant. - /// The size of an array literal is resolved to this if it ever uses operations - /// involving slices. - NotConstant, + /// The type of quoted code in macros. This is always a comptime-only type + Code, /// The result of some type error. Remembering type errors as their own type variant lets /// us avoid issuing repeat type errors for the same item. For example, a lambda with @@ -127,11 +128,7 @@ impl Type { let fields = struct_type.get_fields(args); fields.iter().fold(0, |acc, (_, field_type)| acc + field_type.field_count()) } - Type::Alias(def, _) => { - // It is safe to access `typ` without instantiating generics here since generics - // cannot change the number of fields in `typ`. - def.borrow().typ.field_count() - } + Type::Alias(def, generics) => def.borrow().get_type(generics).field_count(), Type::Tuple(fields) => { fields.iter().fold(0, |acc, field_typ| acc + field_typ.field_count()) } @@ -150,27 +147,24 @@ impl Type { | Type::MutableReference(_) | Type::Forall(_, _) | Type::Constant(_) - | Type::NotConstant + | Type::Code + | Type::Slice(_) | Type::Error => unreachable!("This type cannot exist as a parameter to main"), } } pub(crate) fn is_nested_slice(&self) -> bool { match self { - Type::Array(size, elem) => { - if let Type::NotConstant = size.as_ref() { - elem.as_ref().contains_slice() - } else { - false - } - } + Type::Slice(elem) => elem.as_ref().contains_slice(), + Type::Array(_, elem) => elem.as_ref().contains_slice(), + Type::Alias(alias, generics) => alias.borrow().get_type(generics).is_nested_slice(), _ => false, } } pub(crate) fn contains_slice(&self) -> bool { match self { - Type::Array(size, _) => matches!(size.as_ref(), Type::NotConstant), + Type::Slice(_) => true, Type::Struct(struct_typ, generics) => { let fields = struct_typ.borrow().get_fields(generics); for field in fields.iter() { @@ -457,7 +451,7 @@ pub enum TypeVariableKind { /// that can only be bound to Type::Integer, or other polymorphic integers. Integer, - /// A potentially constant array size. This will only bind to itself, Type::NotConstant, or + /// A potentially constant array size. This will only bind to itself or /// Type::Constant(n) with a matching size. This defaults to Type::Constant(n) if still unbound /// during monomorphization. Constant(u64), @@ -549,11 +543,11 @@ impl TypeBinding { pub struct TypeVariableId(pub usize); impl Type { - pub fn default_int_type() -> Type { + pub fn default_int_or_field_type() -> Type { Type::FieldElement } - pub fn default_range_loop_type() -> Type { + pub fn default_int_type() -> Type { Type::Integer(Signedness::Unsigned, IntegerBitSize::SixtyFour) } @@ -595,6 +589,7 @@ impl Type { TypeBinding::Bound(binding) => binding.is_bindable(), TypeBinding::Unbound(_) => true, }, + Type::Alias(alias, args) => alias.borrow().get_type(args).is_bindable(), _ => false, } } @@ -611,6 +606,15 @@ impl Type { matches!(self.follow_bindings(), Type::Integer(Signedness::Unsigned, _)) } + pub fn is_numeric(&self) -> bool { + use Type::*; + use TypeVariableKind as K; + matches!( + self.follow_bindings(), + FieldElement | Integer(..) | Bool | TypeVariable(_, K::Integer | K::IntegerOrField) + ) + } + fn contains_numeric_typevar(&self, target_id: TypeVariableId) -> bool { // True if the given type is a NamedGeneric with the target_id let named_generic_id_matches_target = |typ: &Type| { @@ -635,14 +639,14 @@ impl Type { | Type::TypeVariable(_, _) | Type::Constant(_) | Type::NamedGeneric(_, _) - | Type::NotConstant | Type::Forall(_, _) + | Type::Code | Type::TraitAsType(..) => false, Type::Array(length, elem) => { elem.contains_numeric_typevar(target_id) || named_generic_id_matches_target(length) } - + Type::Slice(elem) => elem.contains_numeric_typevar(target_id), Type::Tuple(fields) => { fields.iter().any(|field| field.contains_numeric_typevar(target_id)) } @@ -700,13 +704,14 @@ impl Type { | Type::Function(_, _, _) | Type::MutableReference(_) | Type::Forall(_, _) - | Type::TraitAsType(..) - | Type::NotConstant => false, + | Type::Code + | Type::Slice(_) + | Type::TraitAsType(..) => false, - // This function is called during name resolution before we've verified aliases - // are not cyclic. As a result, it wouldn't be safe to check this alias' definition - // to see if the aliased type is valid. - Type::Alias(..) => false, + Type::Alias(alias, generics) => { + let alias = alias.borrow(); + alias.get_type(generics).is_valid_for_program_input() + } Type::Array(length, element) => { length.is_valid_for_program_input() && element.is_valid_for_program_input() @@ -770,11 +775,10 @@ impl std::fmt::Display for Type { write!(f, "Field") } Type::Array(len, typ) => { - if matches!(len.follow_bindings(), Type::NotConstant) { - write!(f, "[{typ}]") - } else { - write!(f, "[{typ}; {len}]") - } + write!(f, "[{typ}; {len}]") + } + Type::Slice(typ) => { + write!(f, "[{typ}]") } Type::Integer(sign, num_bits) => match sign { Signedness::Signed => write!(f, "i{num_bits}"), @@ -783,7 +787,7 @@ impl std::fmt::Display for Type { Type::TypeVariable(var, TypeVariableKind::Normal) => write!(f, "{}", var.borrow()), Type::TypeVariable(binding, TypeVariableKind::Integer) => { if let TypeBinding::Unbound(_) = &*binding.borrow() { - write!(f, "{}", TypeVariableKind::Integer.default_type()) + write!(f, "{}", Type::default_int_type()) } else { write!(f, "{}", binding.borrow()) } @@ -864,7 +868,7 @@ impl std::fmt::Display for Type { Type::MutableReference(element) => { write!(f, "&mut {element}") } - Type::NotConstant => write!(f, "_"), + Type::Code => write!(f, "Code"), } } } @@ -920,10 +924,6 @@ impl Type { bindings.insert(target_id, (var.clone(), this)); Ok(()) } - Type::NotConstant => { - bindings.insert(target_id, (var.clone(), Type::NotConstant)); - Ok(()) - } // A TypeVariable is less specific than a MaybeConstant, so we bind // to the other type variable instead. Type::TypeVariable(new_var, kind) => { @@ -951,14 +951,8 @@ impl Type { bindings.insert(*new_target_id, (new_var.clone(), clone)); Ok(()) } - // The lengths don't match, but neither are set in stone so we can - // just set them both to NotConstant. See issue 2370 - TypeVariableKind::Constant(_) => { - // *length != target_length - bindings.insert(target_id, (var.clone(), Type::NotConstant)); - bindings.insert(*new_target_id, (new_var.clone(), Type::NotConstant)); - Ok(()) - } + // *length != target_length + TypeVariableKind::Constant(_) => Err(UnificationError), TypeVariableKind::IntegerOrField => Err(UnificationError), TypeVariableKind::Integer => Err(UnificationError), }, @@ -1168,6 +1162,8 @@ impl Type { elem_a.try_unify(elem_b, bindings) } + (Slice(elem_a), Slice(elem_b)) => elem_a.try_unify(elem_b, bindings), + (String(len_a), String(len_b)) => len_a.try_unify(len_b, bindings), (FmtString(len_a, elements_a), FmtString(len_b, elements_b)) => { @@ -1312,20 +1308,14 @@ impl Type { let this = self.follow_bindings(); let target = target.follow_bindings(); - if let (Type::Array(size1, element1), Type::Array(size2, element2)) = (&this, &target) { - let size1 = size1.follow_bindings(); - let size2 = size2.follow_bindings(); - - // If we have an array and our target is a slice - if matches!(size1, Type::Constant(_)) && matches!(size2, Type::NotConstant) { - // Still have to ensure the element types match. - // Don't need to issue an error here if not, it will be done in unify_with_coercions - let mut bindings = TypeBindings::new(); - if element1.try_unify(element2, &mut bindings).is_ok() { - convert_array_expression_to_slice(expression, this, target, interner); - Self::apply_type_bindings(bindings); - return true; - } + if let (Type::Array(_size, element1), Type::Slice(element2)) = (&this, &target) { + // Still have to ensure the element types match. + // Don't need to issue an error here if not, it will be done in unify_with_coercions + let mut bindings = TypeBindings::new(); + if element1.try_unify(element2, &mut bindings).is_ok() { + convert_array_expression_to_slice(expression, this, target, interner); + Self::apply_type_bindings(bindings); + return true; } } false @@ -1493,6 +1483,10 @@ impl Type { let element = element.substitute_helper(type_bindings, substitute_bound_typevars); Type::Array(Box::new(size), Box::new(element)) } + Type::Slice(element) => { + let element = element.substitute_helper(type_bindings, substitute_bound_typevars); + Type::Slice(Box::new(element)) + } Type::String(size) => { let size = size.substitute_helper(type_bindings, substitute_bound_typevars); Type::String(Box::new(size)) @@ -1552,15 +1546,16 @@ impl Type { | Type::Constant(_) | Type::TraitAsType(..) | Type::Error - | Type::NotConstant + | Type::Code | Type::Unit => self.clone(), } } /// True if the given TypeVariableId is free anywhere within self - fn occurs(&self, target_id: TypeVariableId) -> bool { + pub fn occurs(&self, target_id: TypeVariableId) -> bool { match self { Type::Array(len, elem) => len.occurs(target_id) || elem.occurs(target_id), + Type::Slice(elem) => elem.occurs(target_id), Type::String(len) => len.occurs(target_id), Type::FmtString(len, fields) => { let len_occurs = len.occurs(target_id); @@ -1593,7 +1588,7 @@ impl Type { | Type::Constant(_) | Type::TraitAsType(..) | Type::Error - | Type::NotConstant + | Type::Code | Type::Unit => false, } } @@ -1610,6 +1605,7 @@ impl Type { Array(size, elem) => { Array(Box::new(size.follow_bindings()), Box::new(elem.follow_bindings())) } + Slice(elem) => Slice(Box::new(elem.follow_bindings())), String(size) => String(Box::new(size.follow_bindings())), FmtString(size, args) => { let size = Box::new(size.follow_bindings()); @@ -1650,8 +1646,8 @@ impl Type { | Bool | Constant(_) | Unit - | Error - | NotConstant => self.clone(), + | Code + | Error => self.clone(), } } @@ -1676,14 +1672,19 @@ fn convert_array_expression_to_slice( let as_slice = HirExpression::Ident(HirIdent::non_trait_method(as_slice_id, location)); let func = interner.push_expr(as_slice); - let arguments = vec![expression]; + // Copy the expression and give it a new ExprId. The old one + // will be mutated in place into a Call expression. + let argument = interner.expression(&expression); + let argument = interner.push_expr(argument); + interner.push_expr_type(argument, array_type.clone()); + interner.push_expr_location(argument, location.span, location.file); + + let arguments = vec![argument]; let call = HirExpression::Call(HirCallExpression { func, arguments, location }); - let call = interner.push_expr(call); + interner.replace_expr(&expression, call); - interner.push_expr_location(call, location.span, location.file); interner.push_expr_location(func, location.span, location.file); - - interner.push_expr_type(call, target_type.clone()); + interner.push_expr_type(expression, target_type.clone()); let func_type = Type::Function(vec![array_type], Box::new(target_type), Box::new(Type::Unit)); interner.push_expr_type(func, func_type); @@ -1705,11 +1706,12 @@ impl BinaryTypeOperator { impl TypeVariableKind { /// Returns the default type this type variable should be bound to if it is still unbound /// during monomorphization. - pub(crate) fn default_type(&self) -> Type { + pub(crate) fn default_type(&self) -> Option { match self { - TypeVariableKind::IntegerOrField | TypeVariableKind::Normal => Type::default_int_type(), - TypeVariableKind::Integer => Type::default_range_loop_type(), - TypeVariableKind::Constant(length) => Type::Constant(*length), + TypeVariableKind::IntegerOrField => Some(Type::default_int_or_field_type()), + TypeVariableKind::Integer => Some(Type::default_int_type()), + TypeVariableKind::Constant(length) => Some(Type::Constant(*length)), + TypeVariableKind::Normal => None, } } } @@ -1731,6 +1733,10 @@ impl From<&Type> for PrintableType { let typ = typ.as_ref(); PrintableType::Array { length, typ: Box::new(typ.into()) } } + Type::Slice(typ) => { + let typ = typ.as_ref(); + PrintableType::Slice { typ: Box::new(typ.into()) } + } Type::Integer(sign, bit_width) => match sign { Signedness::Unsigned => { PrintableType::UnsignedInteger { width: (*bit_width).into() } @@ -1739,12 +1745,12 @@ impl From<&Type> for PrintableType { }, Type::TypeVariable(binding, TypeVariableKind::Integer) => match &*binding.borrow() { TypeBinding::Bound(typ) => typ.into(), - TypeBinding::Unbound(_) => Type::default_range_loop_type().into(), + TypeBinding::Unbound(_) => Type::default_int_type().into(), }, Type::TypeVariable(binding, TypeVariableKind::IntegerOrField) => { match &*binding.borrow() { TypeBinding::Bound(typ) => typ.into(), - TypeBinding::Unbound(_) => Type::default_int_type().into(), + TypeBinding::Unbound(_) => Type::default_int_or_field_type().into(), } } Type::Bool => PrintableType::Boolean, @@ -1768,13 +1774,15 @@ impl From<&Type> for PrintableType { Type::TypeVariable(_, _) => unreachable!(), Type::NamedGeneric(..) => unreachable!(), Type::Forall(..) => unreachable!(), - Type::Function(_, _, env) => { - PrintableType::Function { env: Box::new(env.as_ref().into()) } - } + Type::Function(arguments, return_type, env) => PrintableType::Function { + arguments: arguments.iter().map(|arg| arg.into()).collect(), + return_type: Box::new(return_type.as_ref().into()), + env: Box::new(env.as_ref().into()), + }, Type::MutableReference(typ) => { PrintableType::MutableReference { typ: Box::new(typ.as_ref().into()) } } - Type::NotConstant => unreachable!(), + Type::Code => unreachable!(), } } } @@ -1786,11 +1794,10 @@ impl std::fmt::Debug for Type { write!(f, "Field") } Type::Array(len, typ) => { - if matches!(len.follow_bindings(), Type::NotConstant) { - write!(f, "[{typ:?}]") - } else { - write!(f, "[{typ:?}; {len:?}]") - } + write!(f, "[{typ:?}; {len:?}]") + } + Type::Slice(typ) => { + write!(f, "[{typ:?}]") } Type::Integer(sign, num_bits) => match sign { Signedness::Signed => write!(f, "i{num_bits}"), @@ -1860,7 +1867,7 @@ impl std::fmt::Debug for Type { Type::MutableReference(element) => { write!(f, "&mut {element:?}") } - Type::NotConstant => write!(f, "NotConstant"), + Type::Code => write!(f, "Code"), } } } diff --git a/compiler/noirc_frontend/src/lexer/blns/LICENSE b/compiler/noirc_frontend/src/lexer/blns/LICENSE new file mode 100644 index 00000000000..4ab5bbd793b --- /dev/null +++ b/compiler/noirc_frontend/src/lexer/blns/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015-2020 Max Woolf + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/compiler/noirc_frontend/src/lexer/blns/README.md b/compiler/noirc_frontend/src/lexer/blns/README.md new file mode 100644 index 00000000000..201ed68aef0 --- /dev/null +++ b/compiler/noirc_frontend/src/lexer/blns/README.md @@ -0,0 +1,9 @@ +# BLNS + +[Big List of Naughty Strings](https://github.com/minimaxir/big-list-of-naughty-strings) + +## Updating + +```bash +wget -O blns.base64.json "https://raw.githubusercontent.com/minimaxir/big-list-of-naughty-strings/master/blns.base64.json" +``` diff --git a/compiler/noirc_frontend/src/lexer/blns/blns.base64.json b/compiler/noirc_frontend/src/lexer/blns/blns.base64.json new file mode 100644 index 00000000000..18e61c0d2c4 --- /dev/null +++ b/compiler/noirc_frontend/src/lexer/blns/blns.base64.json @@ -0,0 +1,679 @@ +[ + "", + "dW5kZWZpbmVk", + "dW5kZWY=", + "bnVsbA==", + "TlVMTA==", + "KG51bGwp", + "bmls", + "TklM", + "dHJ1ZQ==", + "ZmFsc2U=", + "VHJ1ZQ==", + "RmFsc2U=", + "VFJVRQ==", + "RkFMU0U=", + "Tm9uZQ==", + "aGFzT3duUHJvcGVydHk=", + "XA==", + "MA==", + "MQ==", + "MS4wMA==", + "JDEuMDA=", + "MS8y", + "MUUy", + "MUUwMg==", + "MUUrMDI=", + "LTE=", + "LTEuMDA=", + "LSQxLjAw", + "LTEvMg==", + "LTFFMg==", + "LTFFMDI=", + "LTFFKzAy", + "MS8w", + "MC8w", + "LTIxNDc0ODM2NDgvLTE=", + "LTkyMjMzNzIwMzY4NTQ3NzU4MDgvLTE=", + "LTA=", + "LTAuMA==", + "KzA=", + "KzAuMA==", + "MC4wMA==", + "MC4uMA==", + "Lg==", + "MC4wLjA=", + "MCwwMA==", + "MCwsMA==", + "LA==", + "MCwwLDA=", + "MC4wLzA=", + "MS4wLzAuMA==", + "MC4wLzAuMA==", + "MSwwLzAsMA==", + "MCwwLzAsMA==", + "LS0x", + "LQ==", + "LS4=", + "LSw=", + "OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5", + "OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5OTk5", + "TmFO", + "SW5maW5pdHk=", + "LUluZmluaXR5", + "SU5G", + "MSNJTkY=", + "LTEjSU5E", + "MSNRTkFO", + "MSNTTkFO", + "MSNJTkQ=", + "MHgw", + "MHhmZmZmZmZmZg==", + "MHhmZmZmZmZmZmZmZmZmZmZm", + "MHhhYmFkMWRlYQ==", + "MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5", + "MSwwMDAuMDA=", + "MSAwMDAuMDA=", + "MScwMDAuMDA=", + "MSwwMDAsMDAwLjAw", + "MSAwMDAgMDAwLjAw", + "MScwMDAnMDAwLjAw", + "MS4wMDAsMDA=", + "MSAwMDAsMDA=", + "MScwMDAsMDA=", + "MS4wMDAuMDAwLDAw", + "MSAwMDAgMDAwLDAw", + "MScwMDAnMDAwLDAw", + "MDEwMDA=", + "MDg=", + "MDk=", + "Mi4yMjUwNzM4NTg1MDcyMDExZS0zMDg=", + "LC4vOydbXS09", + "PD4/OiJ7fXxfKw==", + "IUAjJCVeJiooKWB+", + "AQIDBAUGBwgODxAREhMUFRYXGBkaGxwdHh9/", + "woDCgcKCwoPChMKGwofCiMKJworCi8KMwo3CjsKPwpDCkcKSwpPClMKVwpbCl8KYwpnCmsKbwpzC", + "ncKewp8=", + "CwwgwoXCoOGagOKAgOKAgeKAguKAg+KAhOKAheKAhuKAh+KAiOKAieKAiuKAi+KAqOKAqeKAr+KB", + "n+OAgA==", + "wq3YgNiB2ILYg9iE2IXYnNud3I/hoI7igIvigIzigI3igI7igI/igKrigKvigKzigK3igK7igaDi", + "gaHigaLigaPigaTigabigafigajiganigarigavigaziga3iga7iga/vu7/vv7nvv7rvv7vwkYK9", + "8JuyoPCbsqHwm7Ki8Juyo/CdhbPwnYW08J2FtfCdhbbwnYW38J2FuPCdhbnwnYW686CAgfOggKDz", + "oICh86CAovOggKPzoICk86CApfOggKbzoICn86CAqPOggKnzoICq86CAq/OggKzzoICt86CArvOg", + "gK/zoICw86CAsfOggLLzoICz86CAtPOggLXzoIC286CAt/OggLjzoIC586CAuvOggLvzoIC886CA", + "vfOggL7zoIC/86CBgPOggYHzoIGC86CBg/OggYTzoIGF86CBhvOggYfzoIGI86CBifOggYrzoIGL", + "86CBjPOggY3zoIGO86CBj/OggZDzoIGR86CBkvOggZPzoIGU86CBlfOggZbzoIGX86CBmPOggZnz", + "oIGa86CBm/OggZzzoIGd86CBnvOggZ/zoIGg86CBofOggaLzoIGj86CBpPOggaXzoIGm86CBp/Og", + "gajzoIGp86CBqvOggavzoIGs86CBrfOgga7zoIGv86CBsPOggbHzoIGy86CBs/OggbTzoIG186CB", + "tvOggbfzoIG486CBufOggbrzoIG786CBvPOggb3zoIG+86CBvw==", + "77u/", + "77++", + "zqniiYjDp+KImuKIq8ucwrXiiaTiiaXDtw==", + "w6XDn+KIgsaSwqnLmeKIhsuawqzigKbDpg==", + "xZPiiJHCtMKu4oCgwqXCqMuGw7jPgOKAnOKAmA==", + "wqHihKLCo8Ki4oiewqfCtuKAosKqwrrigJPiiaA=", + "wrjLm8OH4peKxLHLnMOCwq/LmMK/", + "w4XDjcOOw4/LncOTw5Tvo7/DksOaw4bimIM=", + "xZLigJ7CtOKAsMuHw4HCqMuGw5jiiI/igJ3igJk=", + "YOKBhOKCrOKAueKAuu+sge+sguKAocKwwrfigJrigJTCsQ==", + "4oWb4oWc4oWd4oWe", + "0IHQgtCD0ITQhdCG0IfQiNCJ0IrQi9CM0I3QjtCP0JDQkdCS0JPQlNCV0JbQl9CY0JnQmtCb0JzQ", + "ndCe0J/QoNCh0KLQo9Ck0KXQptCn0KjQqdCq0KvQrNCt0K7Qr9Cw0LHQstCz0LTQtdC20LfQuNC5", + "0LrQu9C80L3QvtC/0YDRgdGC0YPRhNGF0YbRh9GI0YnRitGL0YzRjdGO0Y8=", + "2aDZodmi2aPZpNml2abZp9mo2ak=", + "4oGw4oG04oG1", + "4oKA4oKB4oKC", + "4oGw4oG04oG14oKA4oKB4oKC", + "4LiU4LmJ4LmJ4LmJ4LmJ4LmJ4LmH4LmH4LmH4LmH4LmH4LmJ4LmJ4LmJ4LmJ4LmJ4LmH4LmH4LmH", + "4LmH4LmH4LmJ4LmJ4LmJ4LmJ4LmJ4LmJ4LmJ4LmJ4LmH4LmH4LmH4LmH4LmH4LmJ4LmJ4LmJ4LmJ", + "4LmJ4LmH4LmH4LmH4LmH4LmH4LmJ4LmJ4LmJ4LmJ4LmJ4LmJ4LmJ4LmJ4LmH4LmH4LmH4LmH4LmH", + "4LmJ4LmJ4LmJ4LmJ4LmJ4LmH4LmH4LmH4LmH4LmH4LmJ4LmJ4LmJ4LmJ4LmJ4LmJ4LmJ4LmJ4LmH", + "4LmH4LmH4LmH4LmH4LmJ4LmJ4LmJ4LmJ4LmJ4LmH4LmH4LmH4LmHIOC4lOC5ieC5ieC5ieC5ieC5", + "ieC5h+C5h+C5h+C5h+C5h+C5ieC5ieC5ieC5ieC5ieC5h+C5h+C5h+C5h+C5h+C5ieC5ieC5ieC5", + "ieC5ieC5ieC5ieC5ieC5h+C5h+C5h+C5h+C5h+C5ieC5ieC5ieC5ieC5ieC5h+C5h+C5h+C5h+C5", + "h+C5ieC5ieC5ieC5ieC5ieC5ieC5ieC5ieC5h+C5h+C5h+C5h+C5h+C5ieC5ieC5ieC5ieC5ieC5", + "h+C5h+C5h+C5h+C5h+C5ieC5ieC5ieC5ieC5ieC5ieC5ieC5ieC5h+C5h+C5h+C5h+C5h+C5ieC5", + "ieC5ieC5ieC5ieC5h+C5h+C5h+C5hyDguJTguYnguYnguYnguYnguYnguYfguYfguYfguYfguYfg", + "uYnguYnguYnguYnguYnguYfguYfguYfguYfguYfguYnguYnguYnguYnguYnguYnguYnguYnguYfg", + "uYfguYfguYfguYfguYnguYnguYnguYnguYnguYfguYfguYfguYfguYfguYnguYnguYnguYnguYng", + "uYnguYnguYnguYfguYfguYfguYfguYfguYnguYnguYnguYnguYnguYfguYfguYfguYfguYfguYng", + "uYnguYnguYnguYnguYnguYnguYnguYfguYfguYfguYfguYfguYnguYnguYnguYnguYnguYfguYfg", + "uYfguYc=", + "Jw==", + "Ig==", + "Jyc=", + "IiI=", + "JyIn", + "IicnJyciJyI=", + "IiciJyInJycnIg==", + "PGZvbyB2YWw94oCcYmFy4oCdIC8+", + "PGZvbyB2YWw94oCcYmFy4oCdIC8+", + "PGZvbyB2YWw94oCdYmFy4oCcIC8+", + "PGZvbyB2YWw9YGJhcicgLz4=", + "55Sw5Lit44GV44KT44Gr44GC44GS44Gm5LiL44GV44GE", + "44OR44O844OG44Kj44O844G46KGM44GL44Gq44GE44GL", + "5ZKM6KO95ryi6Kqe", + "6YOo6JC95qC8", + "7IKs7ZqM6rO87ZWZ7JuQIOyWtO2VmeyXsOq1rOyGjA==", + "7LCm7LCo66W8IO2DgOqzoCDsmKgg7Y6y7Iuc66eo6rO8IOyRm+uLpOumrCDrmKDrsKnqsIHtlZg=", + "56S+5pyD56eR5a246Zmi6Kqe5a2456CU56m25omA", + "7Jq4656A67CU7Yag66W0", + "8KCcjvCgnLHwoJ258KCxk/CgsbjwoLKW8KCzjw==", + "6KGo44Od44GCQem3l8WSw6nvvKLpgI3DnMOfwqrEhcOx5LiC45CA8KCAgA==", + "44O94Ly84LqI2YTNnOC6iOC8ve++iSDjg73gvLzguojZhM2c4LqI4Ly9776J", + "KO+9oeKXlSDiiIAg4peV772hKQ==", + "772A772oKMK04oiA772A4oip", + "X1/vvpsoLF8sKik=", + "44O7KO+/o+KIgO+/oynjg7s6Kjo=", + "776f772l4py/44O+4pWyKO+9oeKXleKAv+KXle+9oSnilbHinL/vvaXvvp8=", + "LOOAguODuzoqOuODu+OCnOKAmSgg4pi7IM+JIOKYuyAp44CC44O7Oio644O744Kc4oCZ", + "KOKVr8Kw4pahwrDvvInila/vuLUg4pS74pSB4pS7KQ==", + "KO++ieCypeebiuCype+8ie++ie+7vyDilLvilIHilLs=", + "4pSs4pSA4pSs44OOKCDCuiBfIMK644OOKQ==", + "KCDNocKwIM2cypYgzaHCsCk=", + "8J+YjQ==", + "8J+RqfCfj70=", + "8J+RqOKAjfCfprAg8J+RqPCfj7/igI3wn6awIPCfkajigI3wn6axIPCfkajwn4+/4oCN8J+msSDwn6a58J+Pv+KAjeKZgu+4jw==", + "8J+RviDwn5mHIPCfkoEg8J+ZhSDwn5mGIPCfmYsg8J+ZjiDwn5mN", + "8J+QtSDwn5mIIPCfmYkg8J+Zig==", + "4p2k77iPIPCfkpQg8J+SjCDwn5KVIPCfkp4g8J+SkyDwn5KXIPCfkpYg8J+SmCDwn5KdIPCfkp8g", + "8J+SnCDwn5KbIPCfkpog8J+SmQ==", + "4pyL8J+PvyDwn5Kq8J+PvyDwn5GQ8J+PvyDwn5mM8J+PvyDwn5GP8J+PvyDwn5mP8J+Pvw==", + "8J+aviDwn4aSIPCfhpMg8J+GlSDwn4aWIPCfhpcg8J+GmSDwn4+n", + "MO+4j+KDoyAx77iP4oOjIDLvuI/ig6MgM++4j+KDoyA077iP4oOjIDXvuI/ig6MgNu+4j+KDoyA3", + "77iP4oOjIDjvuI/ig6MgOe+4j+KDoyDwn5Sf", + "8J+HuvCfh7jwn4e38J+HuvCfh7gg8J+HpvCfh6vwn4em8J+HsvCfh7g=", + "8J+HuvCfh7jwn4e38J+HuvCfh7jwn4em8J+Hq/Cfh6bwn4ey", + "8J+HuvCfh7jwn4e38J+HuvCfh7jwn4em", + "77yR77yS77yT", + "2aHZotmj", + "2KvZhSDZhtmB2LMg2LPZgti32Kog2YjYqNin2YTYqtit2K/Zitiv2IwsINis2LLZitix2KrZiiDY", + "qNin2LPYqtiu2K/Yp9mFINij2YYg2K/ZhtmILiDYpdiwINmH2YbYp9ifINin2YTYs9iq2KfYsSDZ", + "iNiq2YbYtdmK2Kgg2YPYp9mGLiDYo9mH2ZHZhCDYp9mK2LfYp9mE2YrYp9iMINio2LHZiti32KfZ", + "htmK2Kct2YHYsdmG2LPYpyDZgtivINij2K7YsC4g2LPZhNmK2YXYp9mG2Iwg2KXYqtmB2KfZgtmK", + "2Kkg2KjZitmGINmF2KcsINmK2LDZg9ixINin2YTYrdiv2YjYryDYo9mKINio2LnYrywg2YXYudin", + "2YXZhNipINio2YjZhNmG2K/Yp9iMINin2YTYpdi32YTYp9mCINi52YQg2KXZitmILg==", + "15HWsNa816jWtdeQ16nWtNeB15nXqiwg15HWuNa816jWuNeQINeQ1rHXnNa515TWtNeZ150sINeQ", + "1rXXqiDXlNa316nWuNa814HXnta315nWtNedLCDXldaw15DWtdeqINeU1rjXkNa416jWttel", + "15TWuNeZ1rDXqta415R0ZXN02KfZhNi12YHYrdin2Kog2KfZhNiq2ZHYrdmI2YQ=", + "77e9", + "77e6", + "2YXZj9mG2Y7Yp9mC2Y7YtNmO2KnZjyDYs9mP2KjZj9mE2ZAg2KfZkNiz2ZLYqtmQ2K7Zktiv2Y7Y", + "p9mF2ZAg2KfZhNmE2ZHZj9i62Y7YqdmQINmB2ZDZiiDYp9mE2YbZkdmP2LjZj9mF2ZAg2KfZhNmS", + "2YLZjtin2KbZkNmF2Y7YqdmQINmI2Y7ZgdmQ2YrZhSDZitmO2K7Zj9i12ZHZjiDYp9mE2KrZkdmO", + "2LfZktio2ZDZitmC2Y7Yp9iq2Y8g2KfZhNmS2K3Yp9iz2Y/ZiNio2ZDZitmR2Y7YqdmP2Iw=", + "4Zqb4ZqE4ZqT4ZqQ4ZqL4ZqS4ZqE4ZqA4ZqR4ZqE4ZqC4ZqR4ZqP4ZqF4Zqc", + "4Zqb4ZqA4ZqA4ZqA4ZqA4ZqA4ZqA4ZqA4ZqA4ZqA4ZqA4ZqA4ZqA4ZqA4ZqA4ZqA4ZqA4ZqA4ZqcCg==", + "4oCq4oCqdGVzdOKAqg==", + "4oCrdGVzdOKAqw==", + "4oCpdGVzdOKAqQ==", + "dGVzdOKBoHRlc3TigKs=", + "4oGmdGVzdOKBpw==", + "4bmwzLrMusyVb82eIMy3acyyzKzNh8yqzZluzJ3Ml82VdsyfzJzMmMymzZ9vzLbMmcywzKBrw6jN", + "msyuzLrMqsy5zLHMpCDMlnTMnc2VzLPMo8y7zKrNnmjMvM2TzLLMpsyzzJjMsmXNh8yjzLDMpsys", + "zY4gzKLMvMy7zLHMmGjNms2OzZnMnMyjzLLNhWnMpsyyzKPMsMykdsy7zY1lzLrMrcyzzKrMsC1t", + "zKJpzYVuzJbMusyezLLMr8ywZMy1zLzMn82ZzKnMvMyYzLMgzJ7MpcyxzLPMrXLMm8yXzJhlzZlw", + "zaByzLzMnsy7zK3Ml2XMusygzKPNn3PMmM2HzLPNjcydzYllzYnMpcyvzJ7Mss2azKzNnMe5zKzN", + "js2OzJ/Mls2HzKR0zY3MrMykzZPMvMytzZjNhWnMqsyxbs2gZ8y0zYkgzY/Nic2FY8yszJ9ozaFh", + "zKvMu8yvzZhvzKvMn8yWzY3MmcydzYlzzJfMpsyyLsyozLnNiMyj", + "zKHNk8yezYVJzJfMmMymzZ1uzYfNh82ZdsyuzKtva8yyzKvMmc2IacyWzZnMrcy5zKDMnm7Mocy7", + "zK7Mo8y6Z8yyzYjNmcytzZnMrM2OIMywdM2UzKZozJ7MsmXMosykIM2NzKzMss2WZsy0zJjNlcyj", + "w6jNluG6ucylzKlszZbNlM2aac2TzZrMps2gbs2WzY3Ml82TzLPMrmfNjSDMqG/NmsyqzaFmzJjM", + "o8ysIMyWzJjNlsyfzZnMrmPSic2UzKvNls2TzYfNls2FaMy1zKTMo82azZTDocyXzLzNlc2Fb8y8", + "zKPMpXPMsc2IzLrMlsymzLvNoi7Mm8yWzJ7MoMyrzLA=", + "zJfMus2WzLnMr82T4bmuzKTNjcylzYfNiGjMssyBZc2PzZPMvMyXzJnMvMyjzZQgzYfMnMyxzKDN", + "k82NzYVOzZXNoGXMl8yxesyYzJ3MnMy6zZlwzKTMusy5zY3Mr82aZcygzLvMoM2ccsyozKTNjcy6", + "zJbNlMyWzJZkzKDMn8ytzKzMnc2facymzZbMqc2TzZTMpGHMoMyXzKzNicyZbs2azZwgzLvMnsyw", + "zZrNhWjMtc2JacyzzJ52zKLNh+G4mc2OzZ8t0onMrcypzLzNlG3MpMytzKtpzZXNh8ydzKZuzJfN", + "meG4jcyfIMyvzLLNlc2ex6vMn8yvzLDMss2ZzLvMnWYgzKrMsMywzJfMlsytzJjNmGPMps2NzLLM", + "ns2NzKnMmeG4pc2aYcyuzY7Mn8yZzZzGocypzLnNjnPMpC7MncydINKJWsyhzJbMnM2WzLDMo82J", + "zJxhzZbMsM2ZzKzNoWzMssyrzLPNjcypZ8yhzJ/MvMyxzZrMnsyszYVvzJfNnC7Mnw==", + "zKZIzKzMpMyXzKTNnWXNnCDMnMylzJ3Mu82NzJ/MgXfMlWjMlsyvzZNvzJ3NmcyWzY7MscyuINKJ", + "zLrMmcyezJ/NiFfMt8y8zK1hzLrMqs2NxK/NiM2VzK3NmcyvzJx0zLbMvMyuc8yYzZnNlsyVIMyg", + "zKvMoELMu82NzZnNicyzzYVlzLVozLXMrM2HzKvNmWnMuc2TzLPMs8yuzY7Mq8yVbs2fZMy0zKrM", + "nMyWIMywzYnMqc2HzZnMss2ezYVUzZbMvM2TzKrNomjNj82TzK7Mu2XMrMydzJ/NhSDMpMy5zJ1X", + "zZnMnsydzZTNh82dzYVhzY/Nk82UzLnMvMyjbMy0zZTMsMykzJ/NlOG4vcyrLs2V", + "WsyuzJ7MoM2ZzZTNheG4gMyXzJ7NiMy7zJfhuLbNmc2OzK/MucyezZNHzLtPzK3Ml8yu", + "y5nJkG5i4bSJbMmQIMmQdcaDyZDJryDHncm5b2xvcCDKh8edIMedyblvccmQbCDKh24gyod1bnDh", + "tIlw4bSJyZR14bSJIMm5b2TJr8edyocgcG/Jr3Nu4bSJx50gb3AgcMedcyAnyofhtIlsx50gxoN1", + "4bSJyZRz4bSJZOG0iXDJkCDJuW7Kh8edyofJlMedc3VvyZQgJ8qHx53Jr8mQIMqH4bSJcyDJuW9s", + "b3Agya9uc2ThtIkgya/Hncm5b8ul", + "MDDLmcaWJC0=", + "77y0772I772FIO+9ke+9le+9ie+9g++9iyDvvYLvvZLvvY/vvZfvvY4g772G772P772YIO+9iu+9", + "le+9je+9kO+9kyDvvY/vvZbvvYXvvZIg772U772I772FIO+9jO+9ge+9mu+9mSDvvYTvvY/vvYc=", + "8J2Qk/CdkKHwnZCeIPCdkKrwnZCu8J2QovCdkJzwnZCkIPCdkJvwnZCr8J2QqPCdkLDwnZCnIPCd", + "kJ/wnZCo8J2QsSDwnZCj8J2QrvCdkKbwnZCp8J2QrCDwnZCo8J2Qr/CdkJ7wnZCrIPCdkK3wnZCh", + "8J2QniDwnZCl8J2QmvCdkLPwnZCyIPCdkJ3wnZCo8J2QoA==", + "8J2Vv/Cdlo3wnZaKIPCdlpbwnZaa8J2WjvCdlojwnZaQIPCdlofwnZaX8J2WlPCdlpzwnZaTIPCd", + "lovwnZaU8J2WnSDwnZaP8J2WmvCdlpLwnZaV8J2WmCDwnZaU8J2Wm/CdlorwnZaXIPCdlpnwnZaN", + "8J2WiiDwnZaR8J2WhvCdlp/wnZaeIPCdlonwnZaU8J2WjA==", + "8J2Ru/CdkonwnZKGIPCdkpLwnZKW8J2SivCdkoTwnZKMIPCdkoPwnZKT8J2SkPCdkpjwnZKPIPCd", + "kofwnZKQ8J2SmSDwnZKL8J2SlvCdko7wnZKR8J2SlCDwnZKQ8J2Sl/CdkobwnZKTIPCdkpXwnZKJ", + "8J2ShiDwnZKN8J2SgvCdkpvwnZKaIPCdkoXwnZKQ8J2SiA==", + "8J2To/Cdk7HwnZOuIPCdk7rwnZO+8J2TsvCdk6zwnZO0IPCdk6vwnZO78J2TuPCdlIDwnZO3IPCd", + "k6/wnZO48J2UgSDwnZOz8J2TvvCdk7bwnZO58J2TvCDwnZO48J2Tv/Cdk67wnZO7IPCdk73wnZOx", + "8J2TriDwnZO18J2TqvCdlIPwnZSCIPCdk63wnZO48J2TsA==", + "8J2Vi/CdlZnwnZWWIPCdlaLwnZWm8J2VmvCdlZTwnZWcIPCdlZPwnZWj8J2VoPCdlajwnZWfIPCd", + "lZfwnZWg8J2VqSDwnZWb8J2VpvCdlZ7wnZWh8J2VpCDwnZWg8J2Vp/CdlZbwnZWjIPCdlaXwnZWZ", + "8J2VliDwnZWd8J2VkvCdlavwnZWqIPCdlZXwnZWg8J2VmA==", + "8J2ag/CdmpHwnZqOIPCdmprwnZqe8J2akvCdmozwnZqUIPCdmovwnZqb8J2amPCdmqDwnZqXIPCd", + "mo/wnZqY8J2aoSDwnZqT8J2anvCdmpbwnZqZ8J2anCDwnZqY8J2an/Cdmo7wnZqbIPCdmp3wnZqR", + "8J2ajiDwnZqV8J2aivCdmqPwnZqiIPCdmo3wnZqY8J2akA==", + "4pKv4pKj4pKgIOKSrOKSsOKSpOKSnuKSpiDikp3ikq3ikqrikrLikqkg4pKh4pKq4pKzIOKSpeKS", + "sOKSqOKSq+KSriDikqrikrHikqDikq0g4pKv4pKj4pKgIOKSp+KSnOKSteKStCDikp/ikqrikqI=", + "PHNjcmlwdD5hbGVydCgxMjMpPC9zY3JpcHQ+", + "Jmx0O3NjcmlwdCZndDthbGVydCgmIzM5OzEyMyYjMzk7KTsmbHQ7L3NjcmlwdCZndDs=", + "PGltZyBzcmM9eCBvbmVycm9yPWFsZXJ0KDEyMykgLz4=", + "PHN2Zz48c2NyaXB0PjEyMzwxPmFsZXJ0KDEyMyk8L3NjcmlwdD4=", + "Ij48c2NyaXB0PmFsZXJ0KDEyMyk8L3NjcmlwdD4=", + "Jz48c2NyaXB0PmFsZXJ0KDEyMyk8L3NjcmlwdD4=", + "PjxzY3JpcHQ+YWxlcnQoMTIzKTwvc2NyaXB0Pg==", + "PC9zY3JpcHQ+PHNjcmlwdD5hbGVydCgxMjMpPC9zY3JpcHQ+", + "PCAvIHNjcmlwdCA+PCBzY3JpcHQgPmFsZXJ0KDEyMyk8IC8gc2NyaXB0ID4=", + "b25mb2N1cz1KYVZhU0NyaXB0OmFsZXJ0KDEyMykgYXV0b2ZvY3Vz", + "IiBvbmZvY3VzPUphVmFTQ3JpcHQ6YWxlcnQoMTIzKSBhdXRvZm9jdXM=", + "JyBvbmZvY3VzPUphVmFTQ3JpcHQ6YWxlcnQoMTIzKSBhdXRvZm9jdXM=", + "77ycc2NyaXB077yeYWxlcnQoMTIzKe+8nC9zY3JpcHTvvJ4=", + "PHNjPHNjcmlwdD5yaXB0PmFsZXJ0KDEyMyk8L3NjPC9zY3JpcHQ+cmlwdD4=", + "LS0+PHNjcmlwdD5hbGVydCgxMjMpPC9zY3JpcHQ+", + "IjthbGVydCgxMjMpO3Q9Ig==", + "JzthbGVydCgxMjMpO3Q9Jw==", + "SmF2YVNDcmlwdDphbGVydCgxMjMp", + "O2FsZXJ0KDEyMyk7", + "c3JjPUphVmFTQ3JpcHQ6cHJvbXB0KDEzMik=", + "Ij48c2NyaXB0PmFsZXJ0KDEyMyk7PC9zY3JpcHQgeD0i", + "Jz48c2NyaXB0PmFsZXJ0KDEyMyk7PC9zY3JpcHQgeD0n", + "PjxzY3JpcHQ+YWxlcnQoMTIzKTs8L3NjcmlwdCB4PQ==", + "IiBhdXRvZm9jdXMgb25rZXl1cD0iamF2YXNjcmlwdDphbGVydCgxMjMp", + "JyBhdXRvZm9jdXMgb25rZXl1cD0namF2YXNjcmlwdDphbGVydCgxMjMp", + "PHNjcmlwdHgyMHR5cGU9InRleHQvamF2YXNjcmlwdCI+amF2YXNjcmlwdDphbGVydCgxKTs8L3Nj", + "cmlwdD4=", + "PHNjcmlwdHgzRXR5cGU9InRleHQvamF2YXNjcmlwdCI+amF2YXNjcmlwdDphbGVydCgxKTs8L3Nj", + "cmlwdD4=", + "PHNjcmlwdHgwRHR5cGU9InRleHQvamF2YXNjcmlwdCI+amF2YXNjcmlwdDphbGVydCgxKTs8L3Nj", + "cmlwdD4=", + "PHNjcmlwdHgwOXR5cGU9InRleHQvamF2YXNjcmlwdCI+amF2YXNjcmlwdDphbGVydCgxKTs8L3Nj", + "cmlwdD4=", + "PHNjcmlwdHgwQ3R5cGU9InRleHQvamF2YXNjcmlwdCI+amF2YXNjcmlwdDphbGVydCgxKTs8L3Nj", + "cmlwdD4=", + "PHNjcmlwdHgyRnR5cGU9InRleHQvamF2YXNjcmlwdCI+amF2YXNjcmlwdDphbGVydCgxKTs8L3Nj", + "cmlwdD4=", + "PHNjcmlwdHgwQXR5cGU9InRleHQvamF2YXNjcmlwdCI+amF2YXNjcmlwdDphbGVydCgxKTs8L3Nj", + "cmlwdD4=", + "J2AiPjx4M0NzY3JpcHQ+amF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "J2AiPjx4MDBzY3JpcHQ+amF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "QUJDPGRpdiBzdHlsZT0ieHgzQWV4cHJlc3Npb24oamF2YXNjcmlwdDphbGVydCgxKSI+REVG", + "QUJDPGRpdiBzdHlsZT0ieDpleHByZXNzaW9ueDVDKGphdmFzY3JpcHQ6YWxlcnQoMSkiPkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDpleHByZXNzaW9ueDAwKGphdmFzY3JpcHQ6YWxlcnQoMSkiPkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDpleHB4MDByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSkiPkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDpleHB4NUNyZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSkiPkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4MEFleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSkiPkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4MDlleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSkiPkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4RTN4ODB4ODBleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSki", + "PkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4RTJ4ODB4ODRleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSki", + "PkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4QzJ4QTBleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSkiPkRF", + "Rg==", + "QUJDPGRpdiBzdHlsZT0ieDp4RTJ4ODB4ODBleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSki", + "PkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4RTJ4ODB4OEFleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSki", + "PkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4MERleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSkiPkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4MENleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSkiPkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4RTJ4ODB4ODdleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSki", + "PkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4RUZ4QkJ4QkZleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSki", + "PkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4MjBleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSkiPkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4RTJ4ODB4ODhleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSki", + "PkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4MDBleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSkiPkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4RTJ4ODB4OEJleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSki", + "PkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4RTJ4ODB4ODZleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSki", + "PkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4RTJ4ODB4ODVleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSki", + "PkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4RTJ4ODB4ODJleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSki", + "PkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4MEJleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSkiPkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4RTJ4ODB4ODFleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSki", + "PkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4RTJ4ODB4ODNleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSki", + "PkRFRg==", + "QUJDPGRpdiBzdHlsZT0ieDp4RTJ4ODB4ODlleHByZXNzaW9uKGphdmFzY3JpcHQ6YWxlcnQoMSki", + "PkRFRg==", + "PGEgaHJlZj0ieDBCamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDBGamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEMyeEEwamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVs", + "ZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDA1amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUxeEEweDhFamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDE4amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDExamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgweDg4amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgweDg5amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgweDgwamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDE3amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDAzamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDBFamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDFBamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDAwamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDEwamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgweDgyamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDIwamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDEzamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDA5amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgweDhBamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDE0amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDE5amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgweEFGamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDFGamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgweDgxamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDFEamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgweDg3amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDA3amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUxeDlBeDgwamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgweDgzamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDA0amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDAxamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDA4amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgweDg0amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgweDg2amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUzeDgweDgwamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDEyamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDBEamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDBBamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDBDamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDE1amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgweEE4amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDE2amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDAyamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDFCamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDA2amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgweEE5amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgweDg1amF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDFFamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieEUyeDgxeDlGamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6", + "emVsZW1lbnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0ieDFDamF2YXNjcmlwdDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0iamF2YXNjcmlwdHgwMDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0iamF2YXNjcmlwdHgzQTpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0iamF2YXNjcmlwdHgwOTpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0iamF2YXNjcmlwdHgwRDpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "PGEgaHJlZj0iamF2YXNjcmlwdHgwQTpqYXZhc2NyaXB0OmFsZXJ0KDEpIiBpZD0iZnV6emVsZW1l", + "bnQxIj50ZXN0PC9hPg==", + "YCInPjxpbWcgc3JjPXh4eDp4IHgwQW9uZXJyb3I9amF2YXNjcmlwdDphbGVydCgxKT4=", + "YCInPjxpbWcgc3JjPXh4eDp4IHgyMm9uZXJyb3I9amF2YXNjcmlwdDphbGVydCgxKT4=", + "YCInPjxpbWcgc3JjPXh4eDp4IHgwQm9uZXJyb3I9amF2YXNjcmlwdDphbGVydCgxKT4=", + "YCInPjxpbWcgc3JjPXh4eDp4IHgwRG9uZXJyb3I9amF2YXNjcmlwdDphbGVydCgxKT4=", + "YCInPjxpbWcgc3JjPXh4eDp4IHgyRm9uZXJyb3I9amF2YXNjcmlwdDphbGVydCgxKT4=", + "YCInPjxpbWcgc3JjPXh4eDp4IHgwOW9uZXJyb3I9amF2YXNjcmlwdDphbGVydCgxKT4=", + "YCInPjxpbWcgc3JjPXh4eDp4IHgwQ29uZXJyb3I9amF2YXNjcmlwdDphbGVydCgxKT4=", + "YCInPjxpbWcgc3JjPXh4eDp4IHgwMG9uZXJyb3I9amF2YXNjcmlwdDphbGVydCgxKT4=", + "YCInPjxpbWcgc3JjPXh4eDp4IHgyN29uZXJyb3I9amF2YXNjcmlwdDphbGVydCgxKT4=", + "YCInPjxpbWcgc3JjPXh4eDp4IHgyMG9uZXJyb3I9amF2YXNjcmlwdDphbGVydCgxKT4=", + "ImAnPjxzY3JpcHQ+eDNCamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eDBEamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEVGeEJCeEJGamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweDgxamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweDg0amF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUzeDgweDgwamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eDA5amF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweDg5amF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweDg1amF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweDg4amF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eDAwamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweEE4amF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweDhBamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUxeDlBeDgwamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eDBDamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eDJCamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEYweDkweDk2eDlBamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+LWphdmFzY3JpcHQ6YWxlcnQoMSk8L3NjcmlwdD4=", + "ImAnPjxzY3JpcHQ+eDBBamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweEFGamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eDdFamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweDg3amF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgxeDlGamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweEE5amF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEMyeDg1amF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEVGeEJGeEFFamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweDgzamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweDhCamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEVGeEJGeEJFamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweDgwamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eDIxamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweDgyamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUyeDgweDg2amF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEUxeEEweDhFamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eDBCamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eDIwamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "ImAnPjxzY3JpcHQ+eEMyeEEwamF2YXNjcmlwdDphbGVydCgxKTwvc2NyaXB0Pg==", + "PGltZyB4MDBzcmM9eCBvbmVycm9yPSJhbGVydCgxKSI+", + "PGltZyB4NDdzcmM9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyB4MTFzcmM9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyB4MTJzcmM9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZ3g0N3NyYz14IG9uZXJyb3I9ImphdmFzY3JpcHQ6YWxlcnQoMSkiPg==", + "PGltZ3gxMHNyYz14IG9uZXJyb3I9ImphdmFzY3JpcHQ6YWxlcnQoMSkiPg==", + "PGltZ3gxM3NyYz14IG9uZXJyb3I9ImphdmFzY3JpcHQ6YWxlcnQoMSkiPg==", + "PGltZ3gzMnNyYz14IG9uZXJyb3I9ImphdmFzY3JpcHQ6YWxlcnQoMSkiPg==", + "PGltZ3g0N3NyYz14IG9uZXJyb3I9ImphdmFzY3JpcHQ6YWxlcnQoMSkiPg==", + "PGltZ3gxMXNyYz14IG9uZXJyb3I9ImphdmFzY3JpcHQ6YWxlcnQoMSkiPg==", + "PGltZyB4NDdzcmM9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyB4MzRzcmM9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyB4MzlzcmM9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyB4MDBzcmM9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyBzcmN4MDk9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyBzcmN4MTA9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyBzcmN4MTM9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyBzcmN4MzI9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyBzcmN4MTI9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyBzcmN4MTE9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyBzcmN4MDA9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyBzcmN4NDc9eCBvbmVycm9yPSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyBzcmM9eHgwOW9uZXJyb3I9ImphdmFzY3JpcHQ6YWxlcnQoMSkiPg==", + "PGltZyBzcmM9eHgxMG9uZXJyb3I9ImphdmFzY3JpcHQ6YWxlcnQoMSkiPg==", + "PGltZyBzcmM9eHgxMW9uZXJyb3I9ImphdmFzY3JpcHQ6YWxlcnQoMSkiPg==", + "PGltZyBzcmM9eHgxMm9uZXJyb3I9ImphdmFzY3JpcHQ6YWxlcnQoMSkiPg==", + "PGltZyBzcmM9eHgxM29uZXJyb3I9ImphdmFzY3JpcHQ6YWxlcnQoMSkiPg==", + "PGltZ1thXVtiXVtjXXNyY1tkXT14W2Vdb25lcnJvcj1bZl0iYWxlcnQoMSkiPg==", + "PGltZyBzcmM9eCBvbmVycm9yPXgwOSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyBzcmM9eCBvbmVycm9yPXgxMCJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyBzcmM9eCBvbmVycm9yPXgxMSJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyBzcmM9eCBvbmVycm9yPXgxMiJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyBzcmM9eCBvbmVycm9yPXgzMiJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGltZyBzcmM9eCBvbmVycm9yPXgwMCJqYXZhc2NyaXB0OmFsZXJ0KDEpIj4=", + "PGEgaHJlZj1qYXZhJiMxJiMyJiMzJiM0JiM1JiM2JiM3JiM4JiMxMSYjMTJzY3JpcHQ6amF2YXNj", + "cmlwdDphbGVydCgxKT5YWFg8L2E+", + "PGltZyBzcmM9InhgIGA8c2NyaXB0PmphdmFzY3JpcHQ6YWxlcnQoMSk8L3NjcmlwdD4iYCBgPg==", + "PGltZyBzcmMgb25lcnJvciAvIiAnIj0gYWx0PWphdmFzY3JpcHQ6YWxlcnQoMSkvLyI+", + "PHRpdGxlIG9ucHJvcGVydHljaGFuZ2U9amF2YXNjcmlwdDphbGVydCgxKT48L3RpdGxlPjx0aXRs", + "ZSB0aXRsZT0+", + "PGEgaHJlZj1odHRwOi8vZm9vLmJhci8jeD1geT48L2E+PGltZyBhbHQ9ImA+PGltZyBzcmM9eDp4", + "IG9uZXJyb3I9amF2YXNjcmlwdDphbGVydCgxKT48L2E+Ij4=", + "PCEtLVtpZl0+PHNjcmlwdD5qYXZhc2NyaXB0OmFsZXJ0KDEpPC9zY3JpcHQgLS0+", + "PCEtLVtpZjxpbWcgc3JjPXggb25lcnJvcj1qYXZhc2NyaXB0OmFsZXJ0KDEpLy9dPiAtLT4=", + "PHNjcmlwdCBzcmM9Ii8lKGpzY3JpcHQpcyI+PC9zY3JpcHQ+", + "PHNjcmlwdCBzcmM9IlwlKGpzY3JpcHQpcyI+PC9zY3JpcHQ+", + "PElNRyAiIiI+PFNDUklQVD5hbGVydCgiWFNTIik8L1NDUklQVD4iPg==", + "PElNRyBTUkM9amF2YXNjcmlwdDphbGVydChTdHJpbmcuZnJvbUNoYXJDb2RlKDg4LDgzLDgzKSk+", + "PElNRyBTUkM9IyBvbm1vdXNlb3Zlcj0iYWxlcnQoJ3h4cycpIj4=", + "PElNRyBTUkM9IG9ubW91c2VvdmVyPSJhbGVydCgneHhzJykiPg==", + "PElNRyBvbm1vdXNlb3Zlcj0iYWxlcnQoJ3h4cycpIj4=", + "PElNRyBTUkM9JiMxMDY7JiM5NzsmIzExODsmIzk3OyYjMTE1OyYjOTk7JiMxMTQ7JiMxMDU7JiMx", + "MTI7JiMxMTY7JiM1ODsmIzk3OyYjMTA4OyYjMTAxOyYjMTE0OyYjMTE2OyYjNDA7JiMzOTsmIzg4", + "OyYjODM7JiM4MzsmIzM5OyYjNDE7Pg==", + "PElNRyBTUkM9JiMwMDAwMTA2JiMwMDAwMDk3JiMwMDAwMTE4JiMwMDAwMDk3JiMwMDAwMTE1JiMw", + "MDAwMDk5JiMwMDAwMTE0JiMwMDAwMTA1JiMwMDAwMTEyJiMwMDAwMTE2JiMwMDAwMDU4JiMwMDAw", + "MDk3JiMwMDAwMTA4JiMwMDAwMTAxJiMwMDAwMTE0JiMwMDAwMTE2JiMwMDAwMDQwJiMwMDAwMDM5", + "JiMwMDAwMDg4JiMwMDAwMDgzJiMwMDAwMDgzJiMwMDAwMDM5JiMwMDAwMDQxPg==", + "PElNRyBTUkM9JiN4NkEmI3g2MSYjeDc2JiN4NjEmI3g3MyYjeDYzJiN4NzImI3g2OSYjeDcwJiN4", + "NzQmI3gzQSYjeDYxJiN4NkMmI3g2NSYjeDcyJiN4NzQmI3gyOCYjeDI3JiN4NTgmI3g1MyYjeDUz", + "JiN4MjcmI3gyOT4=", + "PElNRyBTUkM9ImphdiBhc2NyaXB0OmFsZXJ0KCdYU1MnKTsiPg==", + "PElNRyBTUkM9ImphdiYjeDA5O2FzY3JpcHQ6YWxlcnQoJ1hTUycpOyI+", + "PElNRyBTUkM9ImphdiYjeDBBO2FzY3JpcHQ6YWxlcnQoJ1hTUycpOyI+", + "PElNRyBTUkM9ImphdiYjeDBEO2FzY3JpcHQ6YWxlcnQoJ1hTUycpOyI+", + "cGVybCAtZSAncHJpbnQgIjxJTUcgU1JDPWphdmEwc2NyaXB0OmFsZXJ0KCJYU1MiKT4iOycgPiBv", + "dXQ=", + "PElNRyBTUkM9IiAmIzE0OyBqYXZhc2NyaXB0OmFsZXJ0KCdYU1MnKTsiPg==", + "PFNDUklQVC9YU1MgU1JDPSJodHRwOi8vaGEuY2tlcnMub3JnL3hzcy5qcyI+PC9TQ1JJUFQ+", + "PEJPRFkgb25sb2FkISMkJSYoKSp+Ky1fLiw6Oz9AWy98XV5gPWFsZXJ0KCJYU1MiKT4=", + "PFNDUklQVC9TUkM9Imh0dHA6Ly9oYS5ja2Vycy5vcmcveHNzLmpzIj48L1NDUklQVD4=", + "PDxTQ1JJUFQ+YWxlcnQoIlhTUyIpOy8vPDwvU0NSSVBUPg==", + "PFNDUklQVCBTUkM9aHR0cDovL2hhLmNrZXJzLm9yZy94c3MuanM/PCBCID4=", + "PFNDUklQVCBTUkM9Ly9oYS5ja2Vycy5vcmcvLmo+", + "PElNRyBTUkM9ImphdmFzY3JpcHQ6YWxlcnQoJ1hTUycpIg==", + "PGlmcmFtZSBzcmM9aHR0cDovL2hhLmNrZXJzLm9yZy9zY3JpcHRsZXQuaHRtbCA8", + "IjthbGVydCgnWFNTJyk7Ly8=", + "PHUgb25jb3B5PWFsZXJ0KCk+IENvcHkgbWU8L3U+", + "PGkgb253aGVlbD1hbGVydCgxKT4gU2Nyb2xsIG92ZXIgbWUgPC9pPg==", + "PHBsYWludGV4dD4=", + "aHR0cDovL2EvJSUzMCUzMA==", + "PC90ZXh0YXJlYT48c2NyaXB0PmFsZXJ0KDEyMyk8L3NjcmlwdD4=", + "MTtEUk9QIFRBQkxFIHVzZXJz", + "MSc7IERST1AgVEFCTEUgdXNlcnMtLSAx", + "JyBPUiAxPTEgLS0gMQ==", + "JyBPUiAnMSc9JzE=", + "JQ==", + "Xw==", + "LQ==", + "LS0=", + "LS12ZXJzaW9u", + "LS1oZWxw", + "JFVTRVI=", + "L2Rldi9udWxsOyB0b3VjaCAvdG1wL2JsbnMuZmFpbCA7IGVjaG8=", + "YHRvdWNoIC90bXAvYmxucy5mYWlsYA==", + "JCh0b3VjaCAvdG1wL2JsbnMuZmFpbCk=", + "QHtbc3lzdGVtICJ0b3VjaCAvdG1wL2JsbnMuZmFpbCJdfQ==", + "ZXZhbCgicHV0cyAnaGVsbG8gd29ybGQnIik=", + "U3lzdGVtKCJscyAtYWwgLyIp", + "YGxzIC1hbCAvYA==", + "S2VybmVsLmV4ZWMoImxzIC1hbCAvIik=", + "S2VybmVsLmV4aXQoMSk=", + "JXgoJ2xzIC1hbCAvJyk=", + "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iSVNPLTg4NTktMSI/PjwhRE9DVFlQRSBmb28g", + "WyA8IUVMRU1FTlQgZm9vIEFOWSA+PCFFTlRJVFkgeHhlIFNZU1RFTSAiZmlsZTovLy9ldGMvcGFz", + "c3dkIiA+XT48Zm9vPiZ4eGU7PC9mb28+", + "JEhPTUU=", + "JEVOVnsnSE9NRSd9", + "JWQ=", + "JXM=", + "ezB9", + "JSouKnM=", + "Li4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vZXRjL3Bhc3N3ZCUwMA==", + "Li4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vZXRjL2hvc3Rz", + "KCkgeyAwOyB9OyB0b3VjaCAvdG1wL2JsbnMuc2hlbGxzaG9jazEuZmFpbDs=", + "KCkgeyBfOyB9ID5fWyQoJCgpKV0geyB0b3VjaCAvdG1wL2JsbnMuc2hlbGxzaG9jazIuZmFpbDsg", + "fQ==", + "PDw8ICVzKHVuPSclcycpID0gJXU=", + "KysrQVRIMA==", + "Q09O", + "UFJO", + "QVVY", + "Q0xPQ0sk", + "TlVM", + "QTo=", + "Wlo6", + "Q09NMQ==", + "TFBUMQ==", + "TFBUMg==", + "TFBUMw==", + "Q09NMg==", + "Q09NMw==", + "Q09NNA==", + "RENDIFNFTkQgU1RBUlRLRVlMT0dHRVIgMCAwIDA=", + "U2N1bnRob3JwZSBHZW5lcmFsIEhvc3BpdGFs", + "UGVuaXN0b25lIENvbW11bml0eSBDaHVyY2g=", + "TGlnaHR3YXRlciBDb3VudHJ5IFBhcms=", + "SmltbXkgQ2xpdGhlcm9l", + "SG9ybmltYW4gTXVzZXVt", + "c2hpdGFrZSBtdXNocm9vbXM=", + "Um9tYW5zSW5TdXNzZXguY28udWs=", + "aHR0cDovL3d3dy5jdW0ucWMuY2Ev", + "Q3JhaWcgQ29ja2J1cm4sIFNvZnR3YXJlIFNwZWNpYWxpc3Q=", + "TGluZGEgQ2FsbGFoYW4=", + "RHIuIEhlcm1hbiBJLiBMaWJzaGl0eg==", + "bWFnbmEgY3VtIGxhdWRl", + "U3VwZXIgQm93bCBYWFg=", + "bWVkaWV2YWwgZXJlY3Rpb24gb2YgcGFyYXBldHM=", + "ZXZhbHVhdGU=", + "bW9jaGE=", + "ZXhwcmVzc2lvbg==", + "QXJzZW5hbCBjYW5hbA==", + "Y2xhc3NpYw==", + "VHlzb24gR2F5", + "RGljayBWYW4gRHlrZQ==", + "YmFzZW1lbnQ=", + "SWYgeW91J3JlIHJlYWRpbmcgdGhpcywgeW91J3ZlIGJlZW4gaW4gYSBjb21hIGZvciBhbG1vc3Qg", + "MjAgeWVhcnMgbm93LiBXZSdyZSB0cnlpbmcgYSBuZXcgdGVjaG5pcXVlLiBXZSBkb24ndCBrbm93", + "IHdoZXJlIHRoaXMgbWVzc2FnZSB3aWxsIGVuZCB1cCBpbiB5b3VyIGRyZWFtLCBidXQgd2UgaG9w", + "ZSBpdCB3b3Jrcy4gUGxlYXNlIHdha2UgdXAsIHdlIG1pc3MgeW91Lg==", + "Um9zZXMgYXJlIBtbMDszMW1yZWQbWzBtLCB2aW9sZXRzIGFyZSAbWzA7MzRtYmx1ZS4gSG9wZSB5", + "b3UgZW5qb3kgdGVybWluYWwgaHVl", + "QnV0IG5vdy4uLhtbMjBDZm9yIG15IGdyZWF0ZXN0IHRyaWNrLi4uG1s4bQ==", + "VGhlIHF1aWMICAgICAhrIGJyb3duIGZvBwcHBwcHBwcHBwd4Li4uIFtCZWVlZXBd", + "UG93ZXLZhNmP2YTZj9i12ZHYqNmP2YTZj9mE2LXZkdio2Y/Ysdix2Ysg4KWjIOClo2gg4KWjIOCl", + "o+WGlw==", + "2q/ahtm+2pg=", + "eyUgcHJpbnQgJ3gnICogNjQgKiAxMDI0KiozICV9", + "e3sgIiIuX19jbGFzc19fLl9fbXJvX19bMl0uX19zdWJjbGFzc2VzX18oKVs0MF0oIi9ldGMvcGFz", + "c3dkIikucmVhZCgpIH19" +] + diff --git a/compiler/noirc_frontend/src/lexer/lexer.rs b/compiler/noirc_frontend/src/lexer/lexer.rs index cf66ece0c30..265b9e4b5a3 100644 --- a/compiler/noirc_frontend/src/lexer/lexer.rs +++ b/compiler/noirc_frontend/src/lexer/lexer.rs @@ -726,6 +726,16 @@ mod tests { ); } + #[test] + fn fold_attribute() { + let input = r#"#[fold]"#; + + let mut lexer = Lexer::new(input); + let token = lexer.next_token().unwrap(); + + assert_eq!(token.token(), &Token::Attribute(Attribute::Function(FunctionAttribute::Fold))); + } + #[test] fn contract_library_method_attribute() { let input = r#"#[contract_library_method]"#; @@ -1087,4 +1097,114 @@ mod tests { assert_eq!(got, token); } } + + // returns a vector of: + // (expected_token_discriminator, strings_to_lex) + // expected_token_discriminator matches a given token when + // std::mem::discriminant returns the same discriminant for both. + fn blns_base64_to_statements(base64_str: String) -> Vec<(Option, Vec)> { + use base64::engine::general_purpose; + use std::borrow::Cow; + use std::io::Cursor; + use std::io::Read; + + let mut wrapped_reader = Cursor::new(base64_str); + let mut decoder = + base64::read::DecoderReader::new(&mut wrapped_reader, &general_purpose::STANDARD); + let mut base64_decoded = Vec::new(); + decoder.read_to_end(&mut base64_decoded).unwrap(); + + // NOTE: when successful, this is the same conversion method as used in + // noirc_driver::stdlib::stdlib_paths_with_source, viz. + // + // let source = std::str::from_utf8(..).unwrap().to_string(); + let s: Cow<'_, str> = match std::str::from_utf8(&base64_decoded) { + Ok(s) => std::borrow::Cow::Borrowed(s), + Err(_err) => { + // recover as much of the string as possible + // when str::from_utf8 fails + String::from_utf8_lossy(&base64_decoded) + } + }; + + vec![ + // Token::Ident(_) + (None, vec![format!("let \"{s}\" = ();")]), + (Some(Token::Str("".to_string())), vec![format!("let s = \"{s}\";")]), + ( + Some(Token::RawStr("".to_string(), 0)), + vec![ + // let s = r"Hello world"; + format!("let s = r\"{s}\";"), + // let s = r#"Simon says "hello world""#; + format!("let s = r#\"{s}\"#;"), + // // Any number of hashes may be used (>= 1) as long as the string also terminates with the same number of hashes + // let s = r#####"One "#, Two "##, Three "###, Four "####, Five will end the string."#####; + format!("let s = r##\"{s}\"##;"), + format!("let s = r###\"{s}\"###;"), + format!("let s = r####\"{s}\"####; "), + format!("let s = r#####\"{s}\"#####;"), + ], + ), + (Some(Token::FmtStr("".to_string())), vec![format!("assert(x == y, f\"{s}\");")]), + // expected token not found + // (Some(Token::LineComment("".to_string(), None)), vec![ + (None, vec![format!("//{s}"), format!("// {s}")]), + // expected token not found + // (Some(Token::BlockComment("".to_string(), None)), vec![ + (None, vec![format!("/*{s}*/"), format!("/* {s} */"), format!("/*\n{s}\n*/")]), + ] + } + + #[test] + fn test_big_list_of_naughty_strings() { + use std::mem::discriminant; + + let blns_contents = include_str!("./blns/blns.base64.json"); + let blns_base64: Vec = + serde_json::from_str(blns_contents).expect("BLNS json invalid"); + for blns_base64_str in blns_base64 { + let statements = blns_base64_to_statements(blns_base64_str); + for (token_discriminator_opt, blns_program_strs) in statements { + for blns_program_str in blns_program_strs { + let mut expected_token_found = false; + let mut lexer = Lexer::new(&blns_program_str); + let mut result_tokens = Vec::new(); + loop { + match lexer.next_token() { + Ok(next_token) => { + result_tokens.push(next_token.clone()); + expected_token_found |= token_discriminator_opt + .as_ref() + .map(|token_discriminator| { + discriminant(token_discriminator) + == discriminant(next_token.token()) + }) + .unwrap_or(true); + + if next_token == Token::EOF { + assert!(lexer.done, "lexer not done when EOF emitted!"); + break; + } + } + + Err(LexerErrorKind::InvalidIntegerLiteral { .. }) + | Err(LexerErrorKind::UnexpectedCharacter { .. }) + | Err(LexerErrorKind::UnterminatedBlockComment { .. }) => { + expected_token_found = true; + } + Err(err) => { + panic!("Unexpected lexer error found: {:?}", err) + } + } + } + + assert!( + expected_token_found, + "expected token not found: {token_discriminator_opt:?}\noutput:\n{result_tokens:?}", + ); + } + } + } + } } diff --git a/compiler/noirc_frontend/src/lexer/token.rs b/compiler/noirc_frontend/src/lexer/token.rs index 9741acd2c0a..0511bb963e3 100644 --- a/compiler/noirc_frontend/src/lexer/token.rs +++ b/compiler/noirc_frontend/src/lexer/token.rs @@ -427,6 +427,10 @@ impl Attributes { } None } + + pub fn is_foldable(&self) -> bool { + self.function.as_ref().map_or(false, |func_attribute| func_attribute.is_foldable()) + } } /// An Attribute can be either a Primary Attribute or a Secondary Attribute @@ -486,6 +490,7 @@ impl Attribute { } ["test"] => Attribute::Function(FunctionAttribute::Test(TestScope::None)), ["recursive"] => Attribute::Function(FunctionAttribute::Recursive), + ["fold"] => Attribute::Function(FunctionAttribute::Fold), ["test", name] => { validate(name)?; let malformed_scope = @@ -537,6 +542,7 @@ pub enum FunctionAttribute { Oracle(String), Test(TestScope), Recursive, + Fold, } impl FunctionAttribute { @@ -565,6 +571,10 @@ impl FunctionAttribute { pub fn is_low_level(&self) -> bool { matches!(self, FunctionAttribute::Foreign(_) | FunctionAttribute::Builtin(_)) } + + pub fn is_foldable(&self) -> bool { + matches!(self, FunctionAttribute::Fold) + } } impl fmt::Display for FunctionAttribute { @@ -575,6 +585,7 @@ impl fmt::Display for FunctionAttribute { FunctionAttribute::Builtin(ref k) => write!(f, "#[builtin({k})]"), FunctionAttribute::Oracle(ref k) => write!(f, "#[oracle({k})]"), FunctionAttribute::Recursive => write!(f, "#[recursive]"), + FunctionAttribute::Fold => write!(f, "#[fold]"), } } } @@ -619,6 +630,7 @@ impl AsRef for FunctionAttribute { FunctionAttribute::Oracle(string) => string, FunctionAttribute::Test { .. } => "", FunctionAttribute::Recursive => "", + FunctionAttribute::Fold => "", } } } @@ -644,10 +656,12 @@ pub enum Keyword { Assert, AssertEq, Bool, + Break, CallData, Char, CompTime, Constrain, + Continue, Contract, Crate, Dep, @@ -661,18 +675,18 @@ pub enum Keyword { If, Impl, In, - Internal, Let, Mod, Mut, - Open, Pub, + Quote, Return, ReturnData, String, Struct, Trait, Type, + Unchecked, Unconstrained, Use, Where, @@ -686,10 +700,12 @@ impl fmt::Display for Keyword { Keyword::Assert => write!(f, "assert"), Keyword::AssertEq => write!(f, "assert_eq"), Keyword::Bool => write!(f, "bool"), + Keyword::Break => write!(f, "break"), Keyword::Char => write!(f, "char"), Keyword::CallData => write!(f, "call_data"), Keyword::CompTime => write!(f, "comptime"), Keyword::Constrain => write!(f, "constrain"), + Keyword::Continue => write!(f, "continue"), Keyword::Contract => write!(f, "contract"), Keyword::Crate => write!(f, "crate"), Keyword::Dep => write!(f, "dep"), @@ -703,18 +719,18 @@ impl fmt::Display for Keyword { Keyword::If => write!(f, "if"), Keyword::Impl => write!(f, "impl"), Keyword::In => write!(f, "in"), - Keyword::Internal => write!(f, "internal"), Keyword::Let => write!(f, "let"), Keyword::Mod => write!(f, "mod"), Keyword::Mut => write!(f, "mut"), - Keyword::Open => write!(f, "open"), Keyword::Pub => write!(f, "pub"), + Keyword::Quote => write!(f, "quote"), Keyword::Return => write!(f, "return"), Keyword::ReturnData => write!(f, "return_data"), Keyword::String => write!(f, "str"), Keyword::Struct => write!(f, "struct"), Keyword::Trait => write!(f, "trait"), Keyword::Type => write!(f, "type"), + Keyword::Unchecked => write!(f, "unchecked"), Keyword::Unconstrained => write!(f, "unconstrained"), Keyword::Use => write!(f, "use"), Keyword::Where => write!(f, "where"), @@ -731,10 +747,12 @@ impl Keyword { "assert" => Keyword::Assert, "assert_eq" => Keyword::AssertEq, "bool" => Keyword::Bool, + "break" => Keyword::Break, "call_data" => Keyword::CallData, "char" => Keyword::Char, "comptime" => Keyword::CompTime, "constrain" => Keyword::Constrain, + "continue" => Keyword::Continue, "contract" => Keyword::Contract, "crate" => Keyword::Crate, "dep" => Keyword::Dep, @@ -752,18 +770,18 @@ impl Keyword { "if" => Keyword::If, "impl" => Keyword::Impl, "in" => Keyword::In, - "internal" => Keyword::Internal, "let" => Keyword::Let, "mod" => Keyword::Mod, "mut" => Keyword::Mut, - "open" => Keyword::Open, "pub" => Keyword::Pub, + "quote" => Keyword::Quote, "return" => Keyword::Return, "return_data" => Keyword::ReturnData, "str" => Keyword::String, "struct" => Keyword::Struct, "trait" => Keyword::Trait, "type" => Keyword::Type, + "unchecked" => Keyword::Unchecked, "unconstrained" => Keyword::Unconstrained, "use" => Keyword::Use, "where" => Keyword::Where, diff --git a/compiler/noirc_frontend/src/lib.rs b/compiler/noirc_frontend/src/lib.rs index be007929fc4..6ce6f4325e4 100644 --- a/compiler/noirc_frontend/src/lib.rs +++ b/compiler/noirc_frontend/src/lib.rs @@ -56,14 +56,13 @@ pub mod macros_api { pub use crate::hir::def_map::ModuleDefId; pub use crate::{ hir::Context as HirContext, BlockExpression, CallExpression, CastExpression, Distinctness, - Expression, ExpressionKind, FunctionReturnType, Ident, IndexExpression, LetStatement, - Literal, MemberAccessExpression, MethodCallExpression, NoirFunction, Path, PathKind, - Pattern, Statement, UnresolvedType, UnresolvedTypeData, Visibility, + Expression, ExpressionKind, FunctionReturnType, Ident, IndexExpression, ItemVisibility, + LetStatement, Literal, MemberAccessExpression, MethodCallExpression, NoirFunction, Path, + PathKind, Pattern, Statement, UnresolvedType, UnresolvedTypeData, Visibility, }; pub use crate::{ - ForLoopStatement, ForRange, FunctionDefinition, FunctionVisibility, ImportStatement, - NoirStruct, Param, PrefixExpression, Signedness, StatementKind, StructType, Type, TypeImpl, - UnaryOp, + ForLoopStatement, ForRange, FunctionDefinition, ImportStatement, NoirStruct, Param, + PrefixExpression, Signedness, StatementKind, StructType, Type, TypeImpl, UnaryOp, }; /// Methods to process the AST before and after type checking @@ -73,16 +72,17 @@ pub mod macros_api { &self, ast: SortedModule, crate_id: &CrateId, + file_id: FileId, context: &HirContext, ) -> Result; // TODO(#4653): generalize this function - fn process_unresolved_traits_impls( + fn process_collected_defs( &self, _crate_id: &CrateId, _context: &mut HirContext, - _unresolved_traits_impls: &[UnresolvedTraitImpl], - _collected_functions: &mut Vec, + _collected_trait_impls: &[UnresolvedTraitImpl], + _collected_functions: &mut [UnresolvedFunctions], ) -> Result<(), (MacroError, FileId)>; /// Function to manipulate the AST after type checking has been completed. diff --git a/compiler/noirc_frontend/src/monomorphization/ast.rs b/compiler/noirc_frontend/src/monomorphization/ast.rs index e4e619d5d92..7d20c2bcfee 100644 --- a/compiler/noirc_frontend/src/monomorphization/ast.rs +++ b/compiler/noirc_frontend/src/monomorphization/ast.rs @@ -1,7 +1,7 @@ use acvm::FieldElement; use iter_extended::vecmap; use noirc_errors::{ - debug_info::{DebugTypes, DebugVariables}, + debug_info::{DebugFunctions, DebugTypes, DebugVariables}, Location, }; @@ -38,6 +38,8 @@ pub enum Expression { Constrain(Box, Location, Option>), Assign(Assign), Semi(Box), + Break, + Continue, } /// A definition is either a local (variable), function, or is a built-in @@ -87,6 +89,7 @@ pub struct For { #[derive(Debug, Clone, Hash)] pub enum Literal { Array(ArrayLiteral), + Slice(ArrayLiteral), Integer(FieldElement, Type, Location), Bool(bool), Str(String), @@ -208,6 +211,8 @@ pub struct Function { pub return_type: Type, pub unconstrained: bool, + pub should_fold: bool, + pub func_sig: FunctionSignature, } /// Compared to hir_def::types::Type, this monomorphized Type has: @@ -242,6 +247,7 @@ impl Type { #[derive(Debug, Clone, Hash)] pub struct Program { pub functions: Vec, + pub function_signatures: Vec, pub main_function_signature: FunctionSignature, /// Indicates whether witness indices are allowed to reoccur in the ABI of the resulting ACIR. /// @@ -253,6 +259,7 @@ pub struct Program { /// Indicates to a backend whether a SNARK-friendly prover should be used. pub recursive: bool, pub debug_variables: DebugVariables, + pub debug_functions: DebugFunctions, pub debug_types: DebugTypes, } @@ -260,22 +267,26 @@ impl Program { #[allow(clippy::too_many_arguments)] pub fn new( functions: Vec, + function_signatures: Vec, main_function_signature: FunctionSignature, return_distinctness: Distinctness, return_location: Option, return_visibility: Visibility, recursive: bool, debug_variables: DebugVariables, + debug_functions: DebugFunctions, debug_types: DebugTypes, ) -> Program { Program { functions, + function_signatures, main_function_signature, return_distinctness, return_location, return_visibility, recursive, debug_variables, + debug_functions, debug_types, } } diff --git a/compiler/noirc_frontend/src/monomorphization/debug.rs b/compiler/noirc_frontend/src/monomorphization/debug.rs index a8ff4399f99..88943be727f 100644 --- a/compiler/noirc_frontend/src/monomorphization/debug.rs +++ b/compiler/noirc_frontend/src/monomorphization/debug.rs @@ -76,7 +76,7 @@ impl<'interner> Monomorphizer<'interner> { let var_type = self.interner.id_type(call.arguments[DEBUG_VALUE_ARG_SLOT]); let source_var_id = source_var_id.to_u128().into(); // then update the ID used for tracking at runtime - let var_id = self.debug_type_tracker.insert_var(source_var_id, var_type); + let var_id = self.debug_type_tracker.insert_var(source_var_id, &var_type); let interned_var_id = self.intern_var_id(var_id, &call.location); arguments[DEBUG_VAR_ID_ARG_SLOT] = self.expr(interned_var_id)?; Ok(()) @@ -192,11 +192,12 @@ impl<'interner> Monomorphizer<'interner> { fn element_type_at_index(ptype: &PrintableType, i: usize) -> &PrintableType { match ptype { PrintableType::Array { length: _length, typ } => typ.as_ref(), + PrintableType::Slice { typ } => typ.as_ref(), PrintableType::Tuple { types } => &types[i], PrintableType::Struct { name: _name, fields } => &fields[i].1, PrintableType::String { length: _length } => &PrintableType::UnsignedInteger { width: 8 }, - _ => { - panic!["expected type with sub-fields, found terminal type"] + other => { + panic!["expected type with sub-fields, found terminal type: {other:?}"] } } } diff --git a/compiler/noirc_frontend/src/monomorphization/debug_types.rs b/compiler/noirc_frontend/src/monomorphization/debug_types.rs index fea073d394f..16b82d1e7b9 100644 --- a/compiler/noirc_frontend/src/monomorphization/debug_types.rs +++ b/compiler/noirc_frontend/src/monomorphization/debug_types.rs @@ -3,7 +3,8 @@ use crate::{ hir_def::types::Type, }; use noirc_errors::debug_info::{ - DebugTypeId, DebugTypes, DebugVarId, DebugVariable, DebugVariables, + DebugFnId, DebugFunction, DebugFunctions, DebugTypeId, DebugTypes, DebugVarId, DebugVariable, + DebugVariables, }; use noirc_printable_type::PrintableType; use std::collections::HashMap; @@ -30,7 +31,10 @@ pub struct DebugTypeTracker { // All instances of tracked variables variables: HashMap, - // Types of tracked variables + // Function metadata collected during instrumentation injection + functions: HashMap, + + // Types of tracked variables and functions types: HashMap, types_reverse: HashMap, @@ -43,34 +47,29 @@ impl DebugTypeTracker { DebugTypeTracker { source_variables: instrumenter.variables.clone(), source_field_names: instrumenter.field_names.clone(), + functions: instrumenter.functions.clone(), ..DebugTypeTracker::default() } } - pub fn extract_vars_and_types(&self) -> (DebugVariables, DebugTypes) { + pub fn extract_vars_and_types(&self) -> (DebugVariables, DebugFunctions, DebugTypes) { let debug_variables = self .variables .clone() .into_iter() .map(|(var_id, (source_var_id, type_id))| { - ( - var_id, - DebugVariable { - name: self.source_variables.get(&source_var_id).cloned().unwrap_or_else( - || { - unreachable!( - "failed to retrieve variable name for {source_var_id:?}" - ); - }, - ), - debug_type_id: type_id, - }, - ) + let var_name = + self.source_variables.get(&source_var_id).cloned().unwrap_or_else(|| { + unreachable!("failed to retrieve variable name for {source_var_id:?}"); + }); + (var_id, DebugVariable { name: var_name, debug_type_id: type_id }) }) .collect(); + + let debug_functions = self.functions.clone().into_iter().collect(); let debug_types = self.types.clone().into_iter().collect(); - (debug_variables, debug_types) + (debug_variables, debug_functions, debug_types) } pub fn resolve_field_index( @@ -83,19 +82,24 @@ impl DebugTypeTracker { .and_then(|field_name| get_field(cursor_type, field_name)) } - pub fn insert_var(&mut self, source_var_id: SourceVarId, var_type: Type) -> DebugVarId { - if !self.source_variables.contains_key(&source_var_id) { - unreachable!("cannot find source debug variable {source_var_id:?}"); - } - - let ptype: PrintableType = var_type.follow_bindings().into(); - let type_id = self.types_reverse.get(&ptype).copied().unwrap_or_else(|| { + fn insert_type(&mut self, the_type: &Type) -> DebugTypeId { + let ptype: PrintableType = the_type.follow_bindings().into(); + self.types_reverse.get(&ptype).copied().unwrap_or_else(|| { let type_id = DebugTypeId(self.next_type_id); self.next_type_id += 1; self.types_reverse.insert(ptype.clone(), type_id); self.types.insert(type_id, ptype); type_id - }); + }) + } + + pub fn insert_var(&mut self, source_var_id: SourceVarId, var_type: &Type) -> DebugVarId { + if !self.source_variables.contains_key(&source_var_id) { + unreachable!("cannot find source debug variable {source_var_id:?}"); + } + + let type_id = self.insert_type(var_type); + // check if we need to instantiate the var with a new type let existing_var_id = self.source_to_debug_vars.get(&source_var_id).and_then(|var_id| { let (_, existing_type_id) = self.variables.get(var_id).unwrap(); diff --git a/compiler/noirc_frontend/src/monomorphization/errors.rs b/compiler/noirc_frontend/src/monomorphization/errors.rs new file mode 100644 index 00000000000..3011c26cffe --- /dev/null +++ b/compiler/noirc_frontend/src/monomorphization/errors.rs @@ -0,0 +1,39 @@ +use thiserror::Error; + +use noirc_errors::{CustomDiagnostic, FileDiagnostic, Location}; + +#[derive(Debug, Error)] +pub enum MonomorphizationError { + #[error("Length of generic array could not be determined.")] + UnknownArrayLength { location: Location }, + + #[error("Type annotations needed")] + TypeAnnotationsNeeded { location: Location }, +} + +impl MonomorphizationError { + fn location(&self) -> Location { + match self { + MonomorphizationError::UnknownArrayLength { location } + | MonomorphizationError::TypeAnnotationsNeeded { location } => *location, + } + } +} + +impl From for FileDiagnostic { + fn from(error: MonomorphizationError) -> FileDiagnostic { + let location = error.location(); + let call_stack = vec![location]; + let diagnostic = error.into_diagnostic(); + diagnostic.in_file(location.file).with_call_stack(call_stack) + } +} + +impl MonomorphizationError { + fn into_diagnostic(self) -> CustomDiagnostic { + let message = self.to_string(); + let location = self.location(); + + CustomDiagnostic::simple_error(message, String::new(), location.span) + } +} diff --git a/compiler/noirc_frontend/src/monomorphization/mod.rs b/compiler/noirc_frontend/src/monomorphization/mod.rs index ce880401d77..6aa0abce152 100644 --- a/compiler/noirc_frontend/src/monomorphization/mod.rs +++ b/compiler/noirc_frontend/src/monomorphization/mod.rs @@ -8,16 +8,6 @@ //! //! The entry point to this pass is the `monomorphize` function which, starting from a given //! function, will monomorphize the entire reachable program. -use acvm::FieldElement; -use iter_extended::{btree_map, try_vecmap, vecmap}; -use noirc_errors::{CustomDiagnostic, FileDiagnostic, Location}; -use noirc_printable_type::PrintableType; -use std::{ - collections::{BTreeMap, HashMap, VecDeque}, - unreachable, -}; -use thiserror::Error; - use crate::{ debug::DebugInstrumenter, hir_def::{ @@ -28,16 +18,28 @@ use crate::{ }, node_interner::{self, DefinitionKind, NodeInterner, StmtId, TraitImplKind, TraitMethodId}, token::FunctionAttribute, - ContractFunctionType, FunctionKind, IntegerBitSize, Signedness, Type, TypeBinding, - TypeBindings, TypeVariable, TypeVariableKind, UnaryOp, Visibility, + FunctionKind, IntegerBitSize, Signedness, Type, TypeBinding, TypeBindings, TypeVariable, + TypeVariableKind, UnaryOp, Visibility, +}; +use acvm::FieldElement; +use iter_extended::{btree_map, try_vecmap, vecmap}; +use noirc_errors::Location; +use noirc_printable_type::PrintableType; +use std::{ + collections::{BTreeMap, HashMap, VecDeque}, + unreachable, }; -use self::ast::{Definition, FuncId, Function, LocalId, Program}; use self::debug_types::DebugTypeTracker; +use self::{ + ast::{Definition, FuncId, Function, LocalId, Program}, + errors::MonomorphizationError, +}; pub mod ast; mod debug; pub mod debug_types; +pub mod errors; pub mod printer; struct LambdaContext { @@ -88,40 +90,6 @@ struct Monomorphizer<'interner> { type HirType = crate::Type; -#[derive(Debug, Error)] -pub enum MonomorphizationError { - #[error("Length of generic array could not be determined.")] - UnknownArrayLength { location: Location }, -} - -impl MonomorphizationError { - fn call_stack(&self) -> Vec { - match self { - MonomorphizationError::UnknownArrayLength { location } => vec![*location], - } - } -} - -impl From for FileDiagnostic { - fn from(error: MonomorphizationError) -> FileDiagnostic { - let call_stack = error.call_stack(); - let file_id = call_stack.last().map(|location| location.file).unwrap_or_default(); - let diagnostic = error.into_diagnostic(); - diagnostic.in_file(file_id).with_call_stack(call_stack) - } -} - -impl MonomorphizationError { - fn into_diagnostic(self) -> CustomDiagnostic { - CustomDiagnostic::simple_error( - "Internal Consistency Evaluators Errors: \n - This is likely a bug. Consider opening an issue at https://github.com/noir-lang/noir/issues".to_owned(), - self.to_string(), - noirc_errors::Span::inclusive(0, 0) - ) - } -} - /// Starting from the given `main` function, monomorphize the entire program, /// replacing all references to type variables and NamedGenerics with concrete /// types, duplicating definitions as necessary to do so. @@ -161,19 +129,34 @@ pub fn monomorphize_debug( undo_instantiation_bindings(bindings); } + let func_sigs = monomorphizer + .finished_functions + .iter() + .flat_map(|(_, f)| { + if f.should_fold || f.id == Program::main_id() { + Some(f.func_sig.clone()) + } else { + None + } + }) + .collect(); + let functions = vecmap(monomorphizer.finished_functions, |(_, f)| f); let FuncMeta { return_distinctness, return_visibility, kind, .. } = monomorphizer.interner.function_meta(&main); - let (debug_variables, debug_types) = monomorphizer.debug_type_tracker.extract_vars_and_types(); + let (debug_variables, debug_functions, debug_types) = + monomorphizer.debug_type_tracker.extract_vars_and_types(); let program = Program::new( functions, + func_sigs, function_sig, *return_distinctness, monomorphizer.return_location, *return_visibility, *kind == FunctionKind::Recursive, debug_variables, + debug_functions, debug_types, ); Ok(program) @@ -301,21 +284,35 @@ impl<'interner> Monomorphizer<'interner> { } let meta = self.interner.function_meta(&f).clone(); + let func_sig = meta.function_signature(); + let modifiers = self.interner.function_modifiers(&f); let name = self.interner.function_name(&f).to_owned(); let body_expr_id = *self.interner.function(&f).as_expr(); let body_return_type = self.interner.id_type(body_expr_id); - let return_type = self.convert_type(match meta.return_type() { + let return_type = match meta.return_type() { Type::TraitAsType(..) => &body_return_type, - _ => meta.return_type(), - }); - let unconstrained = modifiers.is_unconstrained - || matches!(modifiers.contract_function_type, Some(ContractFunctionType::Open)); + other => other, + }; + + let return_type = Self::convert_type(return_type, meta.location)?; + let unconstrained = modifiers.is_unconstrained; - let parameters = self.parameters(&meta.parameters); + let should_fold = meta.should_fold; + + let parameters = self.parameters(&meta.parameters)?; let body = self.expr(body_expr_id)?; - let function = ast::Function { id, name, parameters, body, return_type, unconstrained }; + let function = ast::Function { + id, + name, + parameters, + body, + return_type, + unconstrained, + should_fold, + func_sig, + }; self.push_function(id, function); Ok(()) @@ -328,12 +325,15 @@ impl<'interner> Monomorphizer<'interner> { /// Monomorphize each parameter, expanding tuple/struct patterns into multiple parameters /// and binding any generic types found. - fn parameters(&mut self, params: &Parameters) -> Vec<(ast::LocalId, bool, String, ast::Type)> { + fn parameters( + &mut self, + params: &Parameters, + ) -> Result, MonomorphizationError> { let mut new_params = Vec::with_capacity(params.len()); for (parameter, typ, _) in ¶ms.0 { - self.parameter(parameter, typ, &mut new_params); + self.parameter(parameter, typ, &mut new_params)?; } - new_params + Ok(new_params) } fn parameter( @@ -341,21 +341,22 @@ impl<'interner> Monomorphizer<'interner> { param: &HirPattern, typ: &HirType, new_params: &mut Vec<(ast::LocalId, bool, String, ast::Type)>, - ) { + ) -> Result<(), MonomorphizationError> { match param { HirPattern::Identifier(ident) => { let new_id = self.next_local_id(); let definition = self.interner.definition(ident.id); let name = definition.name.clone(); - new_params.push((new_id, definition.mutable, name, self.convert_type(typ))); + let typ = Self::convert_type(typ, ident.location)?; + new_params.push((new_id, definition.mutable, name, typ)); self.define_local(ident.id, new_id); } - HirPattern::Mutable(pattern, _) => self.parameter(pattern, typ, new_params), + HirPattern::Mutable(pattern, _) => self.parameter(pattern, typ, new_params)?, HirPattern::Tuple(fields, _) => { let tuple_field_types = unwrap_tuple_type(typ); for (field, typ) in fields.iter().zip(tuple_field_types) { - self.parameter(field, &typ, new_params); + self.parameter(field, &typ, new_params)?; } } HirPattern::Struct(_, fields, _) => { @@ -372,10 +373,11 @@ impl<'interner> Monomorphizer<'interner> { unreachable!("Expected a field named '{field_name}' in the struct pattern") }); - self.parameter(field, &field_type, new_params); + self.parameter(field, &field_type, new_params)?; } } } + Ok(()) } fn expr( @@ -398,9 +400,10 @@ impl<'interner> Monomorphizer<'interner> { } HirExpression::Literal(HirLiteral::Bool(value)) => Literal(Bool(value)), HirExpression::Literal(HirLiteral::Integer(value, sign)) => { + let location = self.interner.id_location(expr); + let typ = Self::convert_type(&self.interner.id_type(expr), location)?; + if sign { - let typ = self.convert_type(&self.interner.id_type(expr)); - let location = self.interner.id_location(expr); match typ { ast::Type::Field => Literal(Integer(-value, typ, location)), ast::Type::Integer(_, bit_size) => { @@ -411,26 +414,30 @@ impl<'interner> Monomorphizer<'interner> { _ => unreachable!("Integer literal must be numeric"), } } else { - let typ = self.convert_type(&self.interner.id_type(expr)); - let location = self.interner.id_location(expr); Literal(Integer(value, typ, location)) } } HirExpression::Literal(HirLiteral::Array(array)) => match array { - HirArrayLiteral::Standard(array) => self.standard_array(expr, array)?, + HirArrayLiteral::Standard(array) => self.standard_array(expr, array, false)?, HirArrayLiteral::Repeated { repeated_element, length } => { - self.repeated_array(expr, repeated_element, length)? + self.repeated_array(expr, repeated_element, length, false)? + } + }, + HirExpression::Literal(HirLiteral::Slice(array)) => match array { + HirArrayLiteral::Standard(array) => self.standard_array(expr, array, true)?, + HirArrayLiteral::Repeated { repeated_element, length } => { + self.repeated_array(expr, repeated_element, length, true)? } }, HirExpression::Literal(HirLiteral::Unit) => ast::Expression::Block(vec![]), - HirExpression::Block(block) => self.block(block.0)?, + HirExpression::Block(block) => self.block(block.statements)?, HirExpression::Prefix(prefix) => { let location = self.interner.expr_location(&expr); ast::Expression::Unary(ast::Unary { operator: prefix.operator, rhs: Box::new(self.expr(prefix.rhs)?), - result_type: self.convert_type(&self.interner.id_type(expr)), + result_type: Self::convert_type(&self.interner.id_type(expr), location)?, location, }) } @@ -459,8 +466,8 @@ impl<'interner> Monomorphizer<'interner> { let function_type = Type::Function(args, Box::new(ret.clone()), env); let method = infix.trait_method_id; - let func = self.resolve_trait_method_reference(expr, function_type, method); - self.create_operator_impl_call(func, lhs, infix.operator, rhs, ret, location) + let func = self.resolve_trait_method_reference(expr, function_type, method)?; + self.create_operator_impl_call(func, lhs, infix.operator, rhs, ret, location)? } else { let lhs = Box::new(lhs); let rhs = Box::new(rhs); @@ -478,23 +485,22 @@ impl<'interner> Monomorphizer<'interner> { HirExpression::Call(call) => self.function_call(call, expr)?, - HirExpression::Cast(cast) => ast::Expression::Cast(ast::Cast { - lhs: Box::new(self.expr(cast.lhs)?), - r#type: self.convert_type(&cast.r#type), - location: self.interner.expr_location(&expr), - }), + HirExpression::Cast(cast) => { + let location = self.interner.expr_location(&expr); + let typ = Self::convert_type(&cast.r#type, location)?; + let lhs = Box::new(self.expr(cast.lhs)?); + ast::Expression::Cast(ast::Cast { lhs, r#type: typ, location }) + } HirExpression::If(if_expr) => { - let cond = self.expr(if_expr.condition)?; - let then = self.expr(if_expr.consequence)?; + let condition = Box::new(self.expr(if_expr.condition)?); + let consequence = Box::new(self.expr(if_expr.consequence)?); let else_ = if_expr.alternative.map(|alt| self.expr(alt)).transpose()?.map(Box::new); - ast::Expression::If(ast::If { - condition: Box::new(cond), - consequence: Box::new(then), - alternative: else_, - typ: self.convert_type(&self.interner.id_type(expr)), - }) + + let location = self.interner.expr_location(&expr); + let typ = Self::convert_type(&self.interner.id_type(expr), location)?; + ast::Expression::If(ast::If { condition, consequence, alternative: else_, typ }) } HirExpression::Tuple(fields) => { @@ -509,6 +515,7 @@ impl<'interner> Monomorphizer<'interner> { unreachable!("Encountered HirExpression::MethodCall during monomorphization {hir_method_call:?}") } HirExpression::Error => unreachable!("Encountered Error node during monomorphization"), + HirExpression::Quote(_) => unreachable!("quote expression remaining in runtime code"), }; Ok(expr) @@ -518,10 +525,16 @@ impl<'interner> Monomorphizer<'interner> { &mut self, array: node_interner::ExprId, array_elements: Vec, + is_slice: bool, ) -> Result { - let typ = self.convert_type(&self.interner.id_type(array)); + let location = self.interner.expr_location(&array); + let typ = Self::convert_type(&self.interner.id_type(array), location)?; let contents = try_vecmap(array_elements, |id| self.expr(id))?; - Ok(ast::Expression::Literal(ast::Literal::Array(ast::ArrayLiteral { contents, typ }))) + if is_slice { + Ok(ast::Expression::Literal(ast::Literal::Slice(ast::ArrayLiteral { contents, typ }))) + } else { + Ok(ast::Expression::Literal(ast::Literal::Array(ast::ArrayLiteral { contents, typ }))) + } } fn repeated_array( @@ -529,8 +542,10 @@ impl<'interner> Monomorphizer<'interner> { array: node_interner::ExprId, repeated_element: node_interner::ExprId, length: HirType, + is_slice: bool, ) -> Result { - let typ = self.convert_type(&self.interner.id_type(array)); + let location = self.interner.expr_location(&array); + let typ = Self::convert_type(&self.interner.id_type(array), location)?; let length = length.evaluate_to_u64().ok_or_else(|| { let location = self.interner.expr_location(&array); @@ -538,7 +553,11 @@ impl<'interner> Monomorphizer<'interner> { })?; let contents = try_vecmap(0..length, |_| self.expr(repeated_element))?; - Ok(ast::Expression::Literal(ast::Literal::Array(ast::ArrayLiteral { contents, typ }))) + if is_slice { + Ok(ast::Expression::Literal(ast::Literal::Slice(ast::ArrayLiteral { contents, typ }))) + } else { + Ok(ast::Expression::Literal(ast::Literal::Array(ast::ArrayLiteral { contents, typ }))) + } } fn index( @@ -546,7 +565,8 @@ impl<'interner> Monomorphizer<'interner> { id: node_interner::ExprId, index: HirIndexExpression, ) -> Result { - let element_type = self.convert_type(&self.interner.id_type(id)); + let location = self.interner.expr_location(&id); + let element_type = Self::convert_type(&self.interner.id_type(id), location)?; let collection = Box::new(self.expr(index.collection)?); let index = Box::new(self.expr(index.index)?); @@ -577,11 +597,14 @@ impl<'interner> Monomorphizer<'interner> { self.define_local(for_loop.identifier.id, index_variable); let block = Box::new(self.expr(for_loop.block)?); + let index_location = for_loop.identifier.location; + let index_type = self.interner.id_type(for_loop.start_range); + let index_type = Self::convert_type(&index_type, index_location)?; Ok(ast::Expression::For(ast::For { index_variable, index_name: self.interner.definition_name(for_loop.identifier.id).to_owned(), - index_type: self.convert_type(&self.interner.id_type(for_loop.start_range)), + index_type, start_range: Box::new(start), end_range: Box::new(end), start_range_location: self.interner.expr_location(&for_loop.start_range), @@ -593,6 +616,8 @@ impl<'interner> Monomorphizer<'interner> { HirStatement::Semi(expr) => { self.expr(expr).map(|expr| ast::Expression::Semi(Box::new(expr))) } + HirStatement::Break => Ok(ast::Expression::Break), + HirStatement::Continue => Ok(ast::Expression::Continue), HirStatement::Error => unreachable!(), } } @@ -603,7 +628,7 @@ impl<'interner> Monomorphizer<'interner> { ) -> Result { let expr = self.expr(let_statement.expression)?; let expected_type = self.interner.id_type(let_statement.expression); - Ok(self.unpack_pattern(let_statement.pattern, expr, &expected_type)) + self.unpack_pattern(let_statement.pattern, expr, &expected_type) } fn constructor( @@ -624,7 +649,8 @@ impl<'interner> Monomorphizer<'interner> { for (field_name, expr_id) in constructor.fields { let new_id = self.next_local_id(); let field_type = field_type_map.get(&field_name.0.contents).unwrap(); - let typ = self.convert_type(field_type); + let location = self.interner.expr_location(&expr_id); + let typ = Self::convert_type(field_type, location)?; field_vars.insert(field_name.0.contents.clone(), (new_id, typ)); let expression = Box::new(self.expr(expr_id)?); @@ -668,19 +694,19 @@ impl<'interner> Monomorphizer<'interner> { pattern: HirPattern, value: ast::Expression, typ: &HirType, - ) -> ast::Expression { + ) -> Result { match pattern { HirPattern::Identifier(ident) => { let new_id = self.next_local_id(); self.define_local(ident.id, new_id); let definition = self.interner.definition(ident.id); - ast::Expression::Let(ast::Let { + Ok(ast::Expression::Let(ast::Let { id: new_id, mutable: definition.mutable, name: definition.name.clone(), expression: Box::new(value), - }) + })) } HirPattern::Mutable(pattern, _) => self.unpack_pattern(*pattern, value, typ), HirPattern::Tuple(patterns, _) => { @@ -709,7 +735,7 @@ impl<'interner> Monomorphizer<'interner> { &mut self, value: ast::Expression, fields: impl Iterator, - ) -> ast::Expression { + ) -> Result { let fresh_id = self.next_local_id(); let mut definitions = vec![ast::Expression::Let(ast::Let { @@ -720,21 +746,22 @@ impl<'interner> Monomorphizer<'interner> { })]; for (i, (field_pattern, field_type)) in fields.into_iter().enumerate() { - let location = None; + let location = field_pattern.location(); let mutable = false; let definition = Definition::Local(fresh_id); let name = i.to_string(); - let typ = self.convert_type(&field_type); + let typ = Self::convert_type(&field_type, location)?; + let location = Some(location); let new_rhs = ast::Expression::Ident(ast::Ident { location, mutable, definition, name, typ }); let new_rhs = ast::Expression::ExtractTupleField(Box::new(new_rhs), i); - let new_expr = self.unpack_pattern(field_pattern, new_rhs, &field_type); + let new_expr = self.unpack_pattern(field_pattern, new_rhs, &field_type)?; definitions.push(new_expr); } - ast::Expression::Block(definitions) + Ok(ast::Expression::Block(definitions)) } /// Find a captured variable in the innermost closure, and construct an expression @@ -760,15 +787,20 @@ impl<'interner> Monomorphizer<'interner> { } /// A local (ie non-global) ident only - fn local_ident(&mut self, ident: &HirIdent) -> Option { + fn local_ident( + &mut self, + ident: &HirIdent, + ) -> Result, MonomorphizationError> { let definition = self.interner.definition(ident.id); let name = definition.name.clone(); let mutable = definition.mutable; - let definition = self.lookup_local(ident.id)?; - let typ = self.convert_type(&self.interner.definition_type(ident.id)); + let Some(definition) = self.lookup_local(ident.id) else { + return Ok(None); + }; - Some(ast::Ident { location: Some(ident.location), mutable, definition, name, typ }) + let typ = Self::convert_type(&self.interner.definition_type(ident.id), ident.location)?; + Ok(Some(ast::Ident { location: Some(ident.location), mutable, definition, name, typ })) } fn ident( @@ -779,7 +811,7 @@ impl<'interner> Monomorphizer<'interner> { let typ = self.interner.id_type(expr_id); if let ImplKind::TraitMethod(method, _, _) = ident.impl_kind { - return Ok(self.resolve_trait_method_reference(expr_id, typ, method)); + return self.resolve_trait_method_reference(expr_id, typ, method); } let definition = self.interner.definition(ident.id); @@ -789,7 +821,7 @@ impl<'interner> Monomorphizer<'interner> { let location = Some(ident.location); let name = definition.name.clone(); let definition = self.lookup_function(*func_id, expr_id, &typ, None); - let typ = self.convert_type(&typ); + let typ = Self::convert_type(&typ, ident.location)?; let ident = ast::Ident { location, mutable, definition, name, typ: typ.clone() }; let ident_expression = ast::Expression::Ident(ident); if self.is_function_closure_type(&typ) { @@ -812,10 +844,13 @@ impl<'interner> Monomorphizer<'interner> { }; self.expr(let_.expression)? } - DefinitionKind::Local(_) => self.lookup_captured_expr(ident.id).unwrap_or_else(|| { - let ident = self.local_ident(&ident).unwrap(); - ast::Expression::Ident(ident) - }), + DefinitionKind::Local(_) => match self.lookup_captured_expr(ident.id) { + Some(expr) => expr, + None => { + let ident = self.local_ident(&ident)?.unwrap(); + ast::Expression::Ident(ident) + } + }, DefinitionKind::GenericType(type_variable) => { let value = match &*type_variable.borrow() { TypeBinding::Unbound(_) => { @@ -828,7 +863,7 @@ impl<'interner> Monomorphizer<'interner> { let value = FieldElement::from(value as u128); let location = self.interner.id_location(expr_id); - let typ = self.convert_type(&typ); + let typ = Self::convert_type(&typ, ident.location)?; ast::Expression::Literal(ast::Literal::Integer(value, typ, location)) } }; @@ -837,81 +872,82 @@ impl<'interner> Monomorphizer<'interner> { } /// Convert a non-tuple/struct type to a monomorphized type - fn convert_type(&self, typ: &HirType) -> ast::Type { - match typ { + fn convert_type(typ: &HirType, location: Location) -> Result { + Ok(match typ { HirType::FieldElement => ast::Type::Field, HirType::Integer(sign, bits) => ast::Type::Integer(*sign, *bits), HirType::Bool => ast::Type::Bool, HirType::String(size) => ast::Type::String(size.evaluate_to_u64().unwrap_or(0)), HirType::FmtString(size, fields) => { let size = size.evaluate_to_u64().unwrap_or(0); - let fields = Box::new(self.convert_type(fields.as_ref())); + let fields = Box::new(Self::convert_type(fields.as_ref(), location)?); ast::Type::FmtString(size, fields) } HirType::Unit => ast::Type::Unit, HirType::Array(length, element) => { - let element = Box::new(self.convert_type(element.as_ref())); - - if let Some(length) = length.evaluate_to_u64() { - ast::Type::Array(length, element) - } else { - ast::Type::Slice(element) - } + let element = Box::new(Self::convert_type(element.as_ref(), location)?); + let length = match length.evaluate_to_u64() { + Some(length) => length, + None => return Err(MonomorphizationError::TypeAnnotationsNeeded { location }), + }; + ast::Type::Array(length, element) + } + HirType::Slice(element) => { + let element = Box::new(Self::convert_type(element.as_ref(), location)?); + ast::Type::Slice(element) } HirType::TraitAsType(..) => { unreachable!("All TraitAsType should be replaced before calling convert_type"); } HirType::NamedGeneric(binding, _) => { if let TypeBinding::Bound(binding) = &*binding.borrow() { - return self.convert_type(binding); + return Self::convert_type(binding, location); } // Default any remaining unbound type variables. // This should only happen if the variable in question is unused // and within a larger generic type. - binding.bind(HirType::default_int_type()); + binding.bind(HirType::default_int_or_field_type()); ast::Type::Field } HirType::TypeVariable(binding, kind) => { if let TypeBinding::Bound(binding) = &*binding.borrow() { - return self.convert_type(binding); + return Self::convert_type(binding, location); } // Default any remaining unbound type variables. // This should only happen if the variable in question is unused // and within a larger generic type. - let default = if self.is_range_loop - && (matches!(kind, TypeVariableKind::IntegerOrField) - || matches!(kind, TypeVariableKind::Integer)) - { - Type::default_range_loop_type() - } else { - kind.default_type() + let default = match kind.default_type() { + Some(typ) => typ, + None => return Err(MonomorphizationError::TypeAnnotationsNeeded { location }), }; - let monomorphized_default = self.convert_type(&default); + let monomorphized_default = Self::convert_type(&default, location)?; binding.bind(default); monomorphized_default } HirType::Struct(def, args) => { let fields = def.borrow().get_fields(args); - let fields = vecmap(fields, |(_, field)| self.convert_type(&field)); + let fields = try_vecmap(fields, |(_, field)| Self::convert_type(&field, location))?; ast::Type::Tuple(fields) } - HirType::Alias(def, args) => self.convert_type(&def.borrow().get_type(args)), + HirType::Alias(def, args) => { + Self::convert_type(&def.borrow().get_type(args), location)? + } HirType::Tuple(fields) => { - let fields = vecmap(fields, |x| self.convert_type(x)); + let fields = try_vecmap(fields, |x| Self::convert_type(x, location))?; ast::Type::Tuple(fields) } HirType::Function(args, ret, env) => { - let args = vecmap(args, |x| self.convert_type(x)); - let ret = Box::new(self.convert_type(ret)); - let env = self.convert_type(env); + let args = try_vecmap(args, |x| Self::convert_type(x, location))?; + let ret = Box::new(Self::convert_type(ret, location)?); + let env = Self::convert_type(env, location)?; match &env { ast::Type::Unit => ast::Type::Function(args, ret, Box::new(env)), ast::Type::Tuple(_elements) => ast::Type::Tuple(vec![ @@ -927,17 +963,15 @@ impl<'interner> Monomorphizer<'interner> { } HirType::MutableReference(element) => { - let element = self.convert_type(element); + let element = Self::convert_type(element, location)?; ast::Type::MutableReference(Box::new(element)) } - HirType::Forall(_, _) - | HirType::Constant(_) - | HirType::NotConstant - | HirType::Error => { + HirType::Forall(_, _) | HirType::Constant(_) | HirType::Error => { unreachable!("Unexpected type {} found", typ) } - } + HirType::Code => unreachable!("Tried to translate Code type into runtime code"), + }) } fn is_function_closure(&self, t: ast::Type) -> bool { @@ -968,7 +1002,7 @@ impl<'interner> Monomorphizer<'interner> { expr_id: node_interner::ExprId, function_type: HirType, method: TraitMethodId, - ) -> ast::Expression { + ) -> Result { let trait_impl = self .interner .get_selected_impl_for_expression(expr_id) @@ -995,7 +1029,12 @@ impl<'interner> Monomorphizer<'interner> { Err(constraints) => { let failed_constraints = vecmap(constraints, |constraint| { let id = constraint.trait_id; - let name = self.interner.get_trait(id).name.to_string(); + let mut name = self.interner.get_trait(id).name.to_string(); + if !constraint.trait_generics.is_empty() { + let types = + vecmap(&constraint.trait_generics, |t| format!("{t:?}")); + name += &format!("<{}>", types.join(", ")); + } format!(" {}: {name}", constraint.typ) }) .join("\n"); @@ -1012,13 +1051,15 @@ impl<'interner> Monomorphizer<'interner> { }; let the_trait = self.interner.get_trait(method.trait_id); - ast::Expression::Ident(ast::Ident { + let location = self.interner.expr_location(&expr_id); + + Ok(ast::Expression::Ident(ast::Ident { definition: Definition::Function(func_id), mutable: false, location: None, name: the_trait.methods[method.method_index].name.0.contents.clone(), - typ: self.convert_type(&function_type), - }) + typ: Self::convert_type(&function_type, location)?, + })) } fn function_call( @@ -1033,7 +1074,8 @@ impl<'interner> Monomorphizer<'interner> { self.patch_debug_instrumentation_call(&call, &mut arguments)?; let return_type = self.interner.id_type(id); - let return_type = self.convert_type(&return_type); + let location = self.interner.expr_location(&id); + let return_type = Self::convert_type(&return_type, location)?; let location = call.location; @@ -1053,7 +1095,7 @@ impl<'interner> Monomorphizer<'interner> { let mut block_expressions = vec![]; let func_type = self.interner.id_type(call.func); - let func_type = self.convert_type(&func_type); + let func_type = Self::convert_type(&func_type, location)?; let is_closure = self.is_function_closure(func_type); let func = if is_closure { @@ -1075,7 +1117,7 @@ impl<'interner> Monomorphizer<'interner> { definition: Definition::Local(local_id), mutable: false, name: "tmp".to_string(), - typ: self.convert_type(&self.interner.id_type(call.func)), + typ: Self::convert_type(&self.interner.id_type(call.func), location)?, }); let env_argument = @@ -1149,11 +1191,7 @@ impl<'interner> Monomorphizer<'interner> { fn append_printable_type_info_inner(typ: &Type, arguments: &mut Vec) { // Disallow printing slices and mutable references for consistency, // since they cannot be passed from ACIR into Brillig - if let HirType::Array(size, _) = typ { - if let HirType::NotConstant = **size { - unreachable!("println and format strings do not support slices. Convert the slice to an array before passing it to println"); - } - } else if matches!(typ, HirType::MutableReference(_)) { + if matches!(typ, HirType::MutableReference(_)) { unreachable!("println and format strings do not support mutable references."); } @@ -1221,6 +1259,7 @@ impl<'interner> Monomorphizer<'interner> { location: Location, ) -> ast::Expression { use ast::*; + let int_type = Type::Integer(crate::Signedness::Unsigned, arr_elem_bits); let bytes_as_expr = vecmap(bytes, |byte| { @@ -1277,24 +1316,24 @@ impl<'interner> Monomorphizer<'interner> { fn lvalue(&mut self, lvalue: HirLValue) -> Result { let value = match lvalue { - HirLValue::Ident(ident, _) => self - .lookup_captured_lvalue(ident.id) - .unwrap_or_else(|| ast::LValue::Ident(self.local_ident(&ident).unwrap())), + HirLValue::Ident(ident, _) => match self.lookup_captured_lvalue(ident.id) { + Some(value) => value, + None => ast::LValue::Ident(self.local_ident(&ident)?.unwrap()), + }, HirLValue::MemberAccess { object, field_index, .. } => { let field_index = field_index.unwrap(); let object = Box::new(self.lvalue(*object)?); ast::LValue::MemberAccess { object, field_index } } - HirLValue::Index { array, index, typ } => { - let location = self.interner.expr_location(&index); + HirLValue::Index { array, index, typ, location } => { let array = Box::new(self.lvalue(*array)?); let index = Box::new(self.expr(index)?); - let element_type = self.convert_type(&typ); + let element_type = Self::convert_type(&typ, location)?; ast::LValue::Index { array, index, element_type, location } } - HirLValue::Dereference { lvalue, element_type } => { + HirLValue::Dereference { lvalue, element_type, location } => { let reference = Box::new(self.lvalue(*lvalue)?); - let element_type = self.convert_type(&element_type); + let element_type = Self::convert_type(&element_type, location)?; ast::LValue::Dereference { reference, element_type } } }; @@ -1308,7 +1347,7 @@ impl<'interner> Monomorphizer<'interner> { expr: node_interner::ExprId, ) -> Result { if lambda.captures.is_empty() { - self.lambda_no_capture(lambda) + self.lambda_no_capture(lambda, expr) } else { let (setup, closure_variable) = self.lambda_with_setup(lambda, expr)?; Ok(ast::Expression::Block(vec![setup, closure_variable])) @@ -1318,16 +1357,19 @@ impl<'interner> Monomorphizer<'interner> { fn lambda_no_capture( &mut self, lambda: HirLambda, + expr: node_interner::ExprId, ) -> Result { - let ret_type = self.convert_type(&lambda.return_type); + let location = self.interner.expr_location(&expr); + let ret_type = Self::convert_type(&lambda.return_type, location)?; let lambda_name = "lambda"; - let parameter_types = vecmap(&lambda.parameters, |(_, typ)| self.convert_type(typ)); + let parameter_types = + try_vecmap(&lambda.parameters, |(_, typ)| Self::convert_type(typ, location))?; // Manually convert to Parameters type so we can reuse the self.parameters method let parameters = vecmap(lambda.parameters, |(pattern, typ)| (pattern, typ, Visibility::Private)).into(); - let parameters = self.parameters(¶meters); + let parameters = self.parameters(¶meters)?; let body = self.expr(lambda.body)?; let id = self.next_function_id(); @@ -1335,7 +1377,16 @@ impl<'interner> Monomorphizer<'interner> { let name = lambda_name.to_owned(); let unconstrained = false; - let function = ast::Function { id, name, parameters, body, return_type, unconstrained }; + let function = ast::Function { + id, + name, + parameters, + body, + return_type, + unconstrained, + should_fold: false, + func_sig: FunctionSignature::default(), + }; self.push_function(id, function); let typ = @@ -1370,15 +1421,17 @@ impl<'interner> Monomorphizer<'interner> { // patterns in the resulting tree, // which seems more fragile, we directly reuse the return parameters // of this function in those cases - let ret_type = self.convert_type(&lambda.return_type); + let location = self.interner.expr_location(&expr); + let ret_type = Self::convert_type(&lambda.return_type, location)?; let lambda_name = "lambda"; - let parameter_types = vecmap(&lambda.parameters, |(_, typ)| self.convert_type(typ)); + let parameter_types = + try_vecmap(&lambda.parameters, |(_, typ)| Self::convert_type(typ, location))?; // Manually convert to Parameters type so we can reuse the self.parameters method let parameters = vecmap(lambda.parameters, |(pattern, typ)| (pattern, typ, Visibility::Private)).into(); - let mut converted_parameters = self.parameters(¶meters); + let mut converted_parameters = self.parameters(¶meters)?; let id = self.next_function_id(); let name = lambda_name.to_owned(); @@ -1386,26 +1439,27 @@ impl<'interner> Monomorphizer<'interner> { let env_local_id = self.next_local_id(); let env_name = "env"; - let env_tuple = ast::Expression::Tuple(vecmap(&lambda.captures, |capture| { - match capture.transitive_capture_index { - Some(field_index) => match self.lambda_envs_stack.last() { - Some(lambda_ctx) => ast::Expression::ExtractTupleField( - Box::new(ast::Expression::Ident(lambda_ctx.env_ident.clone())), - field_index, - ), - None => unreachable!( - "Expected to find a parent closure environment, but found none" - ), - }, - None => { - let ident = self.local_ident(&capture.ident).unwrap(); - ast::Expression::Ident(ident) + let env_tuple = + ast::Expression::Tuple(try_vecmap(&lambda.captures, |capture| { + match capture.transitive_capture_index { + Some(field_index) => { + let lambda_ctx = self.lambda_envs_stack.last().expect( + "Expected to find a parent closure environment, but found none", + ); + + let ident = Box::new(ast::Expression::Ident(lambda_ctx.env_ident.clone())); + Ok(ast::Expression::ExtractTupleField(ident, field_index)) + } + None => { + let ident = self.local_ident(&capture.ident)?.unwrap(); + Ok(ast::Expression::Ident(ident)) + } } - } - })); + })?); + let expr_type = self.interner.id_type(expr); let env_typ = if let types::Type::Function(_, _, function_env_type) = expr_type { - self.convert_type(&function_env_type) + Self::convert_type(&function_env_type, location)? } else { unreachable!("expected a Function type for a Lambda node") }; @@ -1449,7 +1503,16 @@ impl<'interner> Monomorphizer<'interner> { parameters.append(&mut converted_parameters); let unconstrained = false; - let function = ast::Function { id, name, parameters, body, return_type, unconstrained }; + let function = ast::Function { + id, + name, + parameters, + body, + return_type, + unconstrained, + should_fold: false, + func_sig: FunctionSignature::default(), + }; self.push_function(id, function); let lambda_value = @@ -1567,7 +1630,16 @@ impl<'interner> Monomorphizer<'interner> { let name = lambda_name.to_owned(); let unconstrained = false; - let function = ast::Function { id, name, parameters, body, return_type, unconstrained }; + let function = ast::Function { + id, + name, + parameters, + body, + return_type, + unconstrained, + should_fold: false, + func_sig: FunctionSignature::default(), + }; self.push_function(id, function); ast::Expression::Ident(ast::Ident { @@ -1596,10 +1668,10 @@ impl<'interner> Monomorphizer<'interner> { rhs: ast::Expression, ret: Type, location: Location, - ) -> ast::Expression { + ) -> Result { let arguments = vec![lhs, rhs]; let func = Box::new(func); - let return_type = self.convert_type(&ret); + let return_type = Self::convert_type(&ret, location)?; let mut result = ast::Expression::Call(ast::Call { func, arguments, return_type, location }); @@ -1644,7 +1716,7 @@ impl<'interner> Monomorphizer<'interner> { _ => (), } - result + Ok(result) } /// Call sites are instantiated against the trait method, but when an impl is later selected, @@ -1689,23 +1761,15 @@ impl<'interner> Monomorphizer<'interner> { } fn unwrap_tuple_type(typ: &HirType) -> Vec { - match typ { + match typ.follow_bindings() { HirType::Tuple(fields) => fields.clone(), - HirType::TypeVariable(binding, TypeVariableKind::Normal) => match &*binding.borrow() { - TypeBinding::Bound(binding) => unwrap_tuple_type(binding), - TypeBinding::Unbound(_) => unreachable!(), - }, other => unreachable!("unwrap_tuple_type: expected tuple, found {:?}", other), } } fn unwrap_struct_type(typ: &HirType) -> Vec<(String, HirType)> { - match typ { - HirType::Struct(def, args) => def.borrow().get_fields(args), - HirType::TypeVariable(binding, TypeVariableKind::Normal) => match &*binding.borrow() { - TypeBinding::Bound(binding) => unwrap_struct_type(binding), - TypeBinding::Unbound(_) => unreachable!(), - }, + match typ.follow_bindings() { + HirType::Struct(def, args) => def.borrow().get_fields(&args), other => unreachable!("unwrap_struct_type: expected struct, found {:?}", other), } } diff --git a/compiler/noirc_frontend/src/monomorphization/printer.rs b/compiler/noirc_frontend/src/monomorphization/printer.rs index 7aec2193494..c253bfe7930 100644 --- a/compiler/noirc_frontend/src/monomorphization/printer.rs +++ b/compiler/noirc_frontend/src/monomorphization/printer.rs @@ -73,6 +73,8 @@ impl AstPrinter { self.print_expr(expr, f)?; write!(f, ";") } + Expression::Break => write!(f, "break"), + Expression::Continue => write!(f, "continue"), } } @@ -95,6 +97,11 @@ impl AstPrinter { self.print_comma_separated(&array.contents, f)?; write!(f, "]") } + super::ast::Literal::Slice(array) => { + write!(f, "&[")?; + self.print_comma_separated(&array.contents, f)?; + write!(f, "]") + } super::ast::Literal::Integer(x, _, _) => x.fmt(f), super::ast::Literal::Bool(x) => x.fmt(f), super::ast::Literal::Str(s) => s.fmt(f), diff --git a/compiler/noirc_frontend/src/node_interner.rs b/compiler/noirc_frontend/src/node_interner.rs index 5de43e59254..dcfceccdb57 100644 --- a/compiler/noirc_frontend/src/node_interner.rs +++ b/compiler/noirc_frontend/src/node_interner.rs @@ -28,8 +28,8 @@ use crate::hir_def::{ }; use crate::token::{Attributes, SecondaryAttribute}; use crate::{ - BinaryOpKind, ContractFunctionType, FunctionDefinition, FunctionVisibility, Generics, Shared, - TypeAlias, TypeBindings, TypeVariable, TypeVariableId, TypeVariableKind, + BinaryOpKind, FunctionDefinition, Generics, ItemVisibility, Shared, TypeAlias, TypeBindings, + TypeVariable, TypeVariableId, TypeVariableKind, }; /// An arbitrary number to limit the recursion depth when searching for trait impls. @@ -236,20 +236,11 @@ pub struct FunctionModifiers { pub name: String, /// Whether the function is `pub` or not. - pub visibility: FunctionVisibility, + pub visibility: ItemVisibility, pub attributes: Attributes, pub is_unconstrained: bool, - - /// This function's type in its contract. - /// If this function is not in a contract, this is always 'Secret'. - pub contract_function_type: Option, - - /// This function's contract visibility. - /// If this function is internal can only be called by itself. - /// Will be None if not in contract. - pub is_internal: Option, } impl FunctionModifiers { @@ -259,11 +250,9 @@ impl FunctionModifiers { pub fn new() -> Self { Self { name: String::new(), - visibility: FunctionVisibility::Public, + visibility: ItemVisibility::Public, attributes: Attributes::empty(), is_unconstrained: false, - is_internal: None, - contract_function_type: None, } } } @@ -759,17 +748,11 @@ impl NodeInterner { module: ModuleId, location: Location, ) -> DefinitionId { - use ContractFunctionType::*; - - // We're filling in contract_function_type and is_internal now, but these will be verified - // later during name resolution. let modifiers = FunctionModifiers { name: function.name.0.contents.clone(), visibility: function.visibility, attributes: function.attributes.clone(), is_unconstrained: function.is_unconstrained, - contract_function_type: Some(if function.is_open { Open } else { Secret }), - is_internal: Some(function.is_internal), }; self.push_function_definition(id, modifiers, module, location) } @@ -799,7 +782,7 @@ impl NodeInterner { /// /// The underlying function_visibilities map is populated during def collection, /// so this function can be called anytime afterward. - pub fn function_visibility(&self, func: FuncId) -> FunctionVisibility { + pub fn function_visibility(&self, func: FuncId) -> ItemVisibility { self.function_modifiers[&func].visibility } @@ -1096,6 +1079,7 @@ impl NodeInterner { /// constraint, but when where clauses are involved, the failing constraint may be several /// constraints deep. In this case, all of the constraints are returned, starting with the /// failing one. + /// If this list of failing constraints is empty, this means type annotations are required. pub fn lookup_trait_implementation( &self, object_type: &Type, @@ -1138,6 +1122,10 @@ impl NodeInterner { } /// Similar to `lookup_trait_implementation` but does not apply any type bindings on success. + /// On error returns either: + /// - 1+ failing trait constraints, including the original. + /// Each constraint after the first represents a `where` clause that was followed. + /// - 0 trait constraints indicating type annotations are needed to choose an impl. pub fn try_lookup_trait_implementation( &self, object_type: &Type, @@ -1155,6 +1143,11 @@ impl NodeInterner { Ok((impl_kind, bindings)) } + /// Returns the trait implementation if found. + /// On error returns either: + /// - 1+ failing trait constraints, including the original. + /// Each constraint after the first represents a `where` clause that was followed. + /// - 0 trait constraints indicating type annotations are needed to choose an impl. fn lookup_trait_implementation_helper( &self, object_type: &Type, @@ -1173,15 +1166,22 @@ impl NodeInterner { let object_type = object_type.substitute(type_bindings); + // If the object type isn't known, just return an error saying type annotations are needed. + if object_type.is_bindable() { + return Err(Vec::new()); + } + let impls = self.trait_implementation_map.get(&trait_id).ok_or_else(|| vec![make_constraint()])?; + let mut matching_impls = Vec::new(); + for (existing_object_type2, impl_kind) in impls { // Bug: We're instantiating only the object type's generics here, not all of the trait's generics like we need to let (existing_object_type, instantiation_bindings) = existing_object_type2.instantiate(self); - let mut fresh_bindings = TypeBindings::new(); + let mut fresh_bindings = type_bindings.clone(); let mut check_trait_generics = |impl_generics: &[Type]| { trait_generics.iter().zip(impl_generics).all(|(trait_generic, impl_generic2)| { @@ -1206,16 +1206,13 @@ impl NodeInterner { } if object_type.try_unify(&existing_object_type, &mut fresh_bindings).is_ok() { - // The unification was successful so we can append fresh_bindings to our bindings list - type_bindings.extend(fresh_bindings); - if let TraitImplKind::Normal(impl_id) = impl_kind { let trait_impl = self.get_trait_implementation(*impl_id); let trait_impl = trait_impl.borrow(); if let Err(mut errors) = self.validate_where_clause( &trait_impl.where_clause, - type_bindings, + &mut fresh_bindings, &instantiation_bindings, recursion_limit, ) { @@ -1224,11 +1221,20 @@ impl NodeInterner { } } - return Ok(impl_kind.clone()); + matching_impls.push((impl_kind.clone(), fresh_bindings)); } } - Err(vec![make_constraint()]) + if matching_impls.len() == 1 { + let (impl_, fresh_bindings) = matching_impls.pop().unwrap(); + *type_bindings = fresh_bindings; + Ok(impl_) + } else if matching_impls.is_empty() { + Err(vec![make_constraint()]) + } else { + // multiple matching impls, type annotations needed + Err(vec![]) + } } /// Verifies that each constraint in the given where clause is valid. @@ -1244,12 +1250,11 @@ impl NodeInterner { // Instantiation bindings are generally safe to force substitute into the same type. // This is needed here to undo any bindings done to trait methods by monomorphization. // Otherwise, an impl for (A, B) could get narrowed to only an impl for e.g. (u8, u16). - let constraint_type = constraint.typ.force_substitute(instantiation_bindings); - let constraint_type = constraint_type.substitute(type_bindings); + let constraint_type = + constraint.typ.force_substitute(instantiation_bindings).substitute(type_bindings); let trait_generics = vecmap(&constraint.trait_generics, |generic| { - let generic = generic.force_substitute(instantiation_bindings); - generic.substitute(type_bindings) + generic.force_substitute(instantiation_bindings).substitute(type_bindings) }); self.lookup_trait_implementation_helper( @@ -1258,10 +1263,11 @@ impl NodeInterner { &trait_generics, // Use a fresh set of type bindings here since the constraint_type originates from // our impl list, which we don't want to bind to. - &mut TypeBindings::new(), + type_bindings, recursion_limit - 1, )?; } + Ok(()) } @@ -1681,6 +1687,7 @@ enum TypeMethodKey { /// accept only fields or integers, it is just that their names may not clash. FieldOrInt, Array, + Slice, Bool, String, FmtString, @@ -1688,6 +1695,7 @@ enum TypeMethodKey { Tuple, Function, Generic, + Code, } fn get_type_method_key(typ: &Type) -> Option { @@ -1696,6 +1704,7 @@ fn get_type_method_key(typ: &Type) -> Option { match &typ { Type::FieldElement => Some(FieldOrInt), Type::Array(_, _) => Some(Array), + Type::Slice(_) => Some(Slice), Type::Integer(_, _) => Some(FieldOrInt), Type::TypeVariable(_, TypeVariableKind::IntegerOrField) => Some(FieldOrInt), Type::TypeVariable(_, TypeVariableKind::Integer) => Some(FieldOrInt), @@ -1706,6 +1715,7 @@ fn get_type_method_key(typ: &Type) -> Option { Type::Tuple(_) => Some(Tuple), Type::Function(_, _, _) => Some(Function), Type::NamedGeneric(_, _) => Some(Generic), + Type::Code => Some(Code), Type::MutableReference(element) => get_type_method_key(element), Type::Alias(alias, _) => get_type_method_key(&alias.borrow().typ), @@ -1714,7 +1724,6 @@ fn get_type_method_key(typ: &Type) -> Option { | Type::Forall(_, _) | Type::Constant(_) | Type::Error - | Type::NotConstant | Type::Struct(_, _) | Type::TraitAsType(..) => None, } diff --git a/compiler/noirc_frontend/src/parser/mod.rs b/compiler/noirc_frontend/src/parser/mod.rs index 0ff7819c00f..ea96dee8a47 100644 --- a/compiler/noirc_frontend/src/parser/mod.rs +++ b/compiler/noirc_frontend/src/parser/mod.rs @@ -14,8 +14,8 @@ mod parser; use crate::token::{Keyword, Token}; use crate::{ast::ImportStatement, Expression, NoirStruct}; use crate::{ - Ident, LetStatement, NoirFunction, NoirTrait, NoirTraitImpl, NoirTypeAlias, Recoverable, - StatementKind, TypeImpl, UseTree, + Ident, LetStatement, ModuleDeclaration, NoirFunction, NoirTrait, NoirTraitImpl, NoirTypeAlias, + Recoverable, StatementKind, TypeImpl, UseTree, }; use chumsky::prelude::*; @@ -28,7 +28,7 @@ pub use parser::parse_program; #[derive(Debug, Clone)] pub(crate) enum TopLevelStatement { Function(NoirFunction), - Module(Ident), + Module(ModuleDeclaration), Import(UseTree), Struct(NoirStruct), Trait(NoirTrait), @@ -220,7 +220,7 @@ pub struct SortedModule { pub globals: Vec, /// Module declarations like `mod foo;` - pub module_decls: Vec, + pub module_decls: Vec, /// Full submodules as in `mod foo { ... definitions ... }` pub submodules: Vec, @@ -229,7 +229,7 @@ pub struct SortedModule { impl std::fmt::Display for SortedModule { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { for decl in &self.module_decls { - writeln!(f, "mod {decl};")?; + writeln!(f, "{decl};")?; } for import in &self.imports { @@ -309,7 +309,7 @@ pub enum ItemKind { Impl(TypeImpl), TypeAlias(NoirTypeAlias), Global(LetStatement), - ModuleDecl(Ident), + ModuleDecl(ModuleDeclaration), Submodules(ParsedSubModule), } @@ -380,8 +380,8 @@ impl SortedModule { self.imports.extend(import_stmt.desugar(None)); } - fn push_module_decl(&mut self, mod_name: Ident) { - self.module_decls.push(mod_name); + fn push_module_decl(&mut self, mod_decl: ModuleDeclaration) { + self.module_decls.push(mod_decl); } fn push_submodule(&mut self, submodule: SortedSubModule) { @@ -474,7 +474,7 @@ impl std::fmt::Display for TopLevelStatement { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { TopLevelStatement::Function(fun) => fun.fmt(f), - TopLevelStatement::Module(m) => write!(f, "mod {m}"), + TopLevelStatement::Module(m) => m.fmt(f), TopLevelStatement::Import(tree) => write!(f, "use {tree}"), TopLevelStatement::Trait(t) => t.fmt(f), TopLevelStatement::TraitImpl(i) => i.fmt(f), diff --git a/compiler/noirc_frontend/src/parser/parser.rs b/compiler/noirc_frontend/src/parser/parser.rs index 1cb81e26a0a..cdfa16400ae 100644 --- a/compiler/noirc_frontend/src/parser/parser.rs +++ b/compiler/noirc_frontend/src/parser/parser.rs @@ -23,6 +23,8 @@ //! prevent other parsers from being tried afterward since there is no longer an error. Thus, they should //! be limited to cases like the above `fn` example where it is clear we shouldn't back out of the //! current parser to try alternative parsers in a `choice` expression. +use self::primitives::{keyword, mutable_reference, variable}; + use super::{ foldl_with_span, labels::ParsingRuleLabel, parameter_name_recovery, parameter_recovery, parenthesized, then_commit, then_commit_ignore, top_level_statement_recovery, ExprParser, @@ -35,20 +37,35 @@ use crate::ast::{ }; use crate::lexer::Lexer; use crate::parser::{force, ignore_then_commit, statement_recovery}; -use crate::token::{Attribute, Attributes, Keyword, SecondaryAttribute, Token, TokenKind}; +use crate::token::{Keyword, Token, TokenKind}; use crate::{ - BinaryOp, BinaryOpKind, BlockExpression, ConstrainKind, ConstrainStatement, Distinctness, - ForLoopStatement, ForRange, FunctionDefinition, FunctionReturnType, FunctionVisibility, Ident, - IfExpression, InfixExpression, LValue, Lambda, Literal, NoirFunction, NoirStruct, NoirTrait, - NoirTraitImpl, NoirTypeAlias, Param, Path, PathKind, Pattern, Recoverable, Statement, - TraitBound, TraitImplItem, TraitItem, TypeImpl, UnaryOp, UnresolvedTraitConstraint, - UnresolvedTypeExpression, UseTree, UseTreeKind, Visibility, + BinaryOp, BinaryOpKind, BlockExpression, Distinctness, ForLoopStatement, ForRange, + FunctionReturnType, Ident, IfExpression, InfixExpression, LValue, Literal, ModuleDeclaration, + NoirTypeAlias, Param, Path, Pattern, Recoverable, Statement, TraitBound, TypeImpl, + UnresolvedTraitConstraint, UnresolvedTypeExpression, UseTree, UseTreeKind, Visibility, }; use chumsky::prelude::*; use iter_extended::vecmap; use noirc_errors::{Span, Spanned}; +mod assertion; +mod attributes; +mod function; +mod lambdas; +mod literals; +mod path; +mod primitives; +mod structs; +mod traits; + +#[cfg(test)] +mod test_helpers; + +use literals::literal; +use path::{maybe_empty_path, path}; +use primitives::{dereference, ident, negation, not, nothing, right_shift_operator, token_kind}; + /// Entry function for the parser - also handles lexing internally. /// /// Given a source_program string, return the ParsedModule Ast representation @@ -109,10 +126,10 @@ fn top_level_statement( module_parser: impl NoirParser, ) -> impl NoirParser { choice(( - function_definition(false).map(TopLevelStatement::Function), - struct_definition(), - trait_definition(), - trait_implementation(), + function::function_definition(false).map(TopLevelStatement::Function), + structs::struct_definition(), + traits::trait_definition(), + traits::trait_implementation(), implementation(), type_alias_definition().then_ignore(force(just(Token::Semicolon))), submodule(module_parser.clone()), @@ -124,6 +141,21 @@ fn top_level_statement( .recover_via(top_level_statement_recovery()) } +/// Parses a non-trait implementation, adding a set of methods to a type. +/// +/// implementation: 'impl' generics type '{' function_definition ... '}' +fn implementation() -> impl NoirParser { + keyword(Keyword::Impl) + .ignore_then(function::generics()) + .then(parse_type().map_with_span(|typ, span| (typ, span))) + .then_ignore(just(Token::LeftBrace)) + .then(spanned(function::function_definition(true)).repeated()) + .then_ignore(just(Token::RightBrace)) + .map(|((generics, (object_type, type_span)), methods)| { + TopLevelStatement::Impl(TypeImpl { generics, object_type, type_span, methods }) + }) +} + /// global_declaration: 'global' ident global_type_annotation '=' literal fn global_declaration() -> impl NoirParser { let p = ignore_then_commit( @@ -160,121 +192,11 @@ fn contract(module_parser: impl NoirParser) -> impl NoirParser impl NoirParser { - attributes() - .then(function_modifiers()) - .then_ignore(keyword(Keyword::Fn)) - .then(ident()) - .then(generics()) - .then(parenthesized(function_parameters(allow_self))) - .then(function_return_type()) - .then(where_clause()) - .then(spanned(block(fresh_statement()))) - .validate(|(((args, ret), where_clause), (body, body_span)), span, emit| { - let ((((attributes, modifiers), name), generics), parameters) = args; - - // Validate collected attributes, filtering them into function and secondary variants - let attributes = validate_attributes(attributes, span, emit); - FunctionDefinition { - span: body_span, - name, - attributes, - is_unconstrained: modifiers.0, - is_open: modifiers.2, - is_internal: modifiers.3, - visibility: if modifiers.1 { - FunctionVisibility::PublicCrate - } else if modifiers.4 { - FunctionVisibility::Public - } else { - FunctionVisibility::Private - }, - generics, - parameters, - body, - where_clause, - return_type: ret.1, - return_visibility: ret.0 .1, - return_distinctness: ret.0 .0, - } - .into() - }) -} - -/// function_modifiers: 'unconstrained'? 'pub(crate)'? 'pub'? 'open'? 'internal'? -/// -/// returns (is_unconstrained, is_pub_crate, is_open, is_internal, is_pub) for whether each keyword was present -fn function_modifiers() -> impl NoirParser<(bool, bool, bool, bool, bool)> { - keyword(Keyword::Unconstrained) - .or_not() - .then(is_pub_crate()) - .then(keyword(Keyword::Pub).or_not()) - .then(keyword(Keyword::Open).or_not()) - .then(keyword(Keyword::Internal).or_not()) - .map(|((((unconstrained, pub_crate), public), open), internal)| { - ( - unconstrained.is_some(), - pub_crate, - open.is_some(), - internal.is_some(), - public.is_some(), - ) - }) -} - -fn is_pub_crate() -> impl NoirParser { - (keyword(Keyword::Pub) - .then_ignore(just(Token::LeftParen)) - .then_ignore(keyword(Keyword::Crate)) - .then_ignore(just(Token::RightParen))) - .or_not() - .map(|a| a.is_some()) -} - -/// non_empty_ident_list: ident ',' non_empty_ident_list -/// | ident -/// -/// generics: '<' non_empty_ident_list '>' -/// | %empty -fn generics() -> impl NoirParser> { - ident() - .separated_by(just(Token::Comma)) - .allow_trailing() - .at_least(1) - .delimited_by(just(Token::Less), just(Token::Greater)) - .or_not() - .map(|opt| opt.unwrap_or_default()) -} - -fn struct_definition() -> impl NoirParser { - use self::Keyword::Struct; - use Token::*; - - let fields = struct_fields() - .delimited_by(just(LeftBrace), just(RightBrace)) - .recover_with(nested_delimiters( - LeftBrace, - RightBrace, - [(LeftParen, RightParen), (LeftBracket, RightBracket)], - |_| vec![], - )) - .or(just(Semicolon).to(Vec::new())); - - attributes().then_ignore(keyword(Struct)).then(ident()).then(generics()).then(fields).validate( - |(((raw_attributes, name), generics), fields), span, emit| { - let attributes = validate_struct_attributes(raw_attributes, span, emit); - TopLevelStatement::Struct(NoirStruct { name, attributes, generics, fields, span }) - }, - ) -} - fn type_alias_definition() -> impl NoirParser { use self::Keyword::Type; let p = ignore_then_commit(keyword(Type), ident()); - let p = then_commit(p, generics()); + let p = then_commit(p, function::generics()); let p = then_commit_ignore(p, just(Token::Assign)); let p = then_commit(p, parse_type()); @@ -283,13 +205,6 @@ fn type_alias_definition() -> impl NoirParser { }) } -fn lambda_return_type() -> impl NoirParser { - just(Token::Arrow) - .ignore_then(parse_type()) - .or_not() - .map(|ret| ret.unwrap_or_else(UnresolvedType::unspecified)) -} - fn function_return_type() -> impl NoirParser<((Distinctness, Visibility), FunctionReturnType)> { just(Token::Arrow) .ignore_then(optional_distinctness()) @@ -305,69 +220,6 @@ fn function_return_type() -> impl NoirParser<((Distinctness, Visibility), Functi }) } -fn attribute() -> impl NoirParser { - token_kind(TokenKind::Attribute).map(|token| match token { - Token::Attribute(attribute) => attribute, - _ => unreachable!("Parser should have already errored due to token not being an attribute"), - }) -} - -fn attributes() -> impl NoirParser> { - attribute().repeated() -} - -fn struct_fields() -> impl NoirParser> { - ident() - .then_ignore(just(Token::Colon)) - .then(parse_type()) - .separated_by(just(Token::Comma)) - .allow_trailing() -} - -fn lambda_parameters() -> impl NoirParser> { - let typ = parse_type().recover_via(parameter_recovery()); - let typ = just(Token::Colon).ignore_then(typ); - - let parameter = pattern() - .recover_via(parameter_name_recovery()) - .then(typ.or_not().map(|typ| typ.unwrap_or_else(UnresolvedType::unspecified))); - - parameter - .separated_by(just(Token::Comma)) - .allow_trailing() - .labelled(ParsingRuleLabel::Parameter) -} - -fn function_parameters<'a>(allow_self: bool) -> impl NoirParser> + 'a { - let typ = parse_type().recover_via(parameter_recovery()); - - let full_parameter = pattern() - .recover_via(parameter_name_recovery()) - .then_ignore(just(Token::Colon)) - .then(optional_visibility()) - .then(typ) - .map_with_span(|((pattern, visibility), typ), span| Param { - visibility, - pattern, - typ, - span, - }); - - let self_parameter = if allow_self { self_parameter().boxed() } else { nothing().boxed() }; - - let parameter = full_parameter.or(self_parameter); - - parameter - .separated_by(just(Token::Comma)) - .allow_trailing() - .labelled(ParsingRuleLabel::Parameter) -} - -/// This parser always parses no input and fails -fn nothing() -> impl NoirParser { - one_of([]).map(|_| unreachable!("parser should always error")) -} - fn self_parameter() -> impl NoirParser { let mut_ref_pattern = just(Token::Ampersand).then_ignore(keyword(Keyword::Mut)); let mut_pattern = keyword(Keyword::Mut); @@ -401,111 +253,6 @@ fn self_parameter() -> impl NoirParser { }) } -fn trait_definition() -> impl NoirParser { - keyword(Keyword::Trait) - .ignore_then(ident()) - .then(generics()) - .then(where_clause()) - .then_ignore(just(Token::LeftBrace)) - .then(trait_body()) - .then_ignore(just(Token::RightBrace)) - .map_with_span(|(((name, generics), where_clause), items), span| { - TopLevelStatement::Trait(NoirTrait { name, generics, where_clause, span, items }) - }) -} - -fn trait_body() -> impl NoirParser> { - trait_function_declaration() - .or(trait_type_declaration()) - .or(trait_constant_declaration()) - .repeated() -} - -fn optional_default_value() -> impl NoirParser> { - ignore_then_commit(just(Token::Assign), expression()).or_not() -} - -fn trait_constant_declaration() -> impl NoirParser { - keyword(Keyword::Let) - .ignore_then(ident()) - .then_ignore(just(Token::Colon)) - .then(parse_type()) - .then(optional_default_value()) - .then_ignore(just(Token::Semicolon)) - .validate(|((name, typ), default_value), span, emit| { - emit(ParserError::with_reason( - ParserErrorReason::ExperimentalFeature("Associated constants"), - span, - )); - TraitItem::Constant { name, typ, default_value } - }) -} - -/// trait_function_declaration: 'fn' ident generics '(' declaration_parameters ')' function_return_type -fn trait_function_declaration() -> impl NoirParser { - let trait_function_body_or_semicolon = - block(fresh_statement()).map(Option::from).or(just(Token::Semicolon).to(Option::None)); - - keyword(Keyword::Fn) - .ignore_then(ident()) - .then(generics()) - .then(parenthesized(function_declaration_parameters())) - .then(function_return_type().map(|(_, typ)| typ)) - .then(where_clause()) - .then(trait_function_body_or_semicolon) - .map(|(((((name, generics), parameters), return_type), where_clause), body)| { - TraitItem::Function { name, generics, parameters, return_type, where_clause, body } - }) -} - -fn validate_attributes( - attributes: Vec, - span: Span, - emit: &mut dyn FnMut(ParserError), -) -> Attributes { - let mut primary = None; - let mut secondary = Vec::new(); - - for attribute in attributes { - match attribute { - Attribute::Function(attr) => { - if primary.is_some() { - emit(ParserError::with_reason( - ParserErrorReason::MultipleFunctionAttributesFound, - span, - )); - } - primary = Some(attr); - } - Attribute::Secondary(attr) => secondary.push(attr), - } - } - - Attributes { function: primary, secondary } -} - -fn validate_struct_attributes( - attributes: Vec, - span: Span, - emit: &mut dyn FnMut(ParserError), -) -> Vec { - let mut struct_attributes = vec![]; - - for attribute in attributes { - match attribute { - Attribute::Function(..) => { - emit(ParserError::with_reason( - ParserErrorReason::NoFunctionAttributesAllowedOnStruct, - span, - )); - } - Attribute::Secondary(attr) => struct_attributes.push(attr), - } - } - - struct_attributes -} - /// Function declaration parameters differ from other parameters in that parameter /// patterns are not allowed in declarations. All parameters must be identifiers. fn function_declaration_parameters() -> impl NoirParser> { @@ -536,89 +283,6 @@ fn function_declaration_parameters() -> impl NoirParser impl NoirParser { - keyword(Keyword::Type).ignore_then(ident()).then_ignore(just(Token::Semicolon)).validate( - |name, span, emit| { - emit(ParserError::with_reason( - ParserErrorReason::ExperimentalFeature("Associated types"), - span, - )); - TraitItem::Type { name } - }, - ) -} - -/// Parses a non-trait implementation, adding a set of methods to a type. -/// -/// implementation: 'impl' generics type '{' function_definition ... '}' -fn implementation() -> impl NoirParser { - keyword(Keyword::Impl) - .ignore_then(generics()) - .then(parse_type().map_with_span(|typ, span| (typ, span))) - .then_ignore(just(Token::LeftBrace)) - .then(spanned(function_definition(true)).repeated()) - .then_ignore(just(Token::RightBrace)) - .map(|((generics, (object_type, type_span)), methods)| { - TopLevelStatement::Impl(TypeImpl { generics, object_type, type_span, methods }) - }) -} - -/// Parses a trait implementation, implementing a particular trait for a type. -/// This has a similar syntax to `implementation`, but the `for type` clause is required, -/// and an optional `where` clause is also useable. -/// -/// trait_implementation: 'impl' generics ident generic_args for type '{' trait_implementation_body '}' -fn trait_implementation() -> impl NoirParser { - keyword(Keyword::Impl) - .ignore_then(generics()) - .then(path()) - .then(generic_type_args(parse_type())) - .then_ignore(keyword(Keyword::For)) - .then(parse_type()) - .then(where_clause()) - .then_ignore(just(Token::LeftBrace)) - .then(trait_implementation_body()) - .then_ignore(just(Token::RightBrace)) - .map(|args| { - let ((other_args, where_clause), items) = args; - let (((impl_generics, trait_name), trait_generics), object_type) = other_args; - - TopLevelStatement::TraitImpl(NoirTraitImpl { - impl_generics, - trait_name, - trait_generics, - object_type, - items, - where_clause, - }) - }) -} - -fn trait_implementation_body() -> impl NoirParser> { - let function = function_definition(true).validate(|mut f, span, emit| { - if f.def().is_internal - || f.def().is_unconstrained - || f.def().is_open - || f.def().visibility != FunctionVisibility::Private - { - emit(ParserError::with_reason(ParserErrorReason::TraitImplFunctionModifiers, span)); - } - // Trait impl functions are always public - f.def_mut().visibility = FunctionVisibility::Public; - TraitImplItem::Function(f) - }); - - let alias = keyword(Keyword::Type) - .ignore_then(ident()) - .then_ignore(just(Token::Assign)) - .then(parse_type()) - .then_ignore(just(Token::Semicolon)) - .map(|(name, alias)| TraitImplItem::Type { name, alias }); - - function.or(alias).repeated() -} - fn where_clause() -> impl NoirParser> { struct MultiTraitConstraint { typ: UnresolvedType, @@ -683,7 +347,7 @@ fn block<'a>( [(LeftParen, RightParen), (LeftBracket, RightBracket)], |span| vec![Statement { kind: StatementKind::Error, span }], )) - .map(BlockExpression) + .map(|statements| BlockExpression { statements }) } fn check_statements_require_semicolon( @@ -706,52 +370,15 @@ fn optional_type_annotation<'a>() -> impl NoirParser + 'a { } fn module_declaration() -> impl NoirParser { - keyword(Keyword::Mod).ignore_then(ident()).map(TopLevelStatement::Module) + keyword(Keyword::Mod) + .ignore_then(ident()) + .map(|ident| TopLevelStatement::Module(ModuleDeclaration { ident })) } fn use_statement() -> impl NoirParser { keyword(Keyword::Use).ignore_then(use_tree()).map(TopLevelStatement::Import) } -fn keyword(keyword: Keyword) -> impl NoirParser { - just(Token::Keyword(keyword)) -} - -fn token_kind(token_kind: TokenKind) -> impl NoirParser { - filter_map(move |span, found: Token| { - if found.kind() == token_kind { - Ok(found) - } else { - Err(ParserError::expected_label( - ParsingRuleLabel::TokenKind(token_kind.clone()), - found, - span, - )) - } - }) -} - -fn path() -> impl NoirParser { - let idents = || ident().separated_by(just(Token::DoubleColon)).at_least(1); - let make_path = |kind| move |segments, span| Path { segments, kind, span }; - - let prefix = |key| keyword(key).ignore_then(just(Token::DoubleColon)); - let path_kind = |key, kind| prefix(key).ignore_then(idents()).map_with_span(make_path(kind)); - - choice(( - path_kind(Keyword::Crate, PathKind::Crate), - path_kind(Keyword::Dep, PathKind::Dep), - idents().map_with_span(make_path(PathKind::Plain)), - )) -} - -fn empty_path() -> impl NoirParser { - let make_path = |kind| move |_, span| Path { segments: Vec::new(), kind, span }; - let path_kind = |key, kind| keyword(key).map_with_span(make_path(kind)); - - choice((path_kind(Keyword::Crate, PathKind::Crate), path_kind(Keyword::Dep, PathKind::Dep))) -} - fn rename() -> impl NoirParser> { ignore_then_commit(keyword(Keyword::As), ident()).or_not() } @@ -764,7 +391,7 @@ fn use_tree() -> impl NoirParser { }); let list = { - let prefix = path().or(empty_path()).then_ignore(just(Token::DoubleColon)); + let prefix = maybe_empty_path().then_ignore(just(Token::DoubleColon)); let tree = use_tree .separated_by(just(Token::Comma)) .allow_trailing() @@ -778,10 +405,6 @@ fn use_tree() -> impl NoirParser { }) } -fn ident() -> impl NoirParser { - token_kind(TokenKind::Ident).map_with_span(Ident::from_token) -} - fn statement<'a, P, P2>( expr_parser: P, expr_no_constructors: P2, @@ -792,12 +415,14 @@ where { recursive(|statement| { choice(( - constrain(expr_parser.clone()), - assertion(expr_parser.clone()), - assertion_eq(expr_parser.clone()), + assertion::constrain(expr_parser.clone()), + assertion::assertion(expr_parser.clone()), + assertion::assertion_eq(expr_parser.clone()), declaration(expr_parser.clone()), assignment(expr_parser.clone()), for_loop(expr_no_constructors, statement), + break_statement(), + continue_statement(), return_statement(expr_parser.clone()), expr_parser.map(StatementKind::Expression), )) @@ -808,62 +433,12 @@ fn fresh_statement() -> impl NoirParser { statement(expression(), expression_no_constructors(expression())) } -fn constrain<'a, P>(expr_parser: P) -> impl NoirParser + 'a -where - P: ExprParser + 'a, -{ - ignore_then_commit( - keyword(Keyword::Constrain).labelled(ParsingRuleLabel::Statement), - expr_parser, - ) - .map(|expr| StatementKind::Constrain(ConstrainStatement(expr, None, ConstrainKind::Constrain))) - .validate(|expr, span, emit| { - emit(ParserError::with_reason(ParserErrorReason::ConstrainDeprecated, span)); - expr - }) -} - -fn assertion<'a, P>(expr_parser: P) -> impl NoirParser + 'a -where - P: ExprParser + 'a, -{ - let argument_parser = - expr_parser.separated_by(just(Token::Comma)).allow_trailing().at_least(1).at_most(2); - - ignore_then_commit(keyword(Keyword::Assert), parenthesized(argument_parser)) - .labelled(ParsingRuleLabel::Statement) - .validate(|expressions, span, _| { - let condition = expressions.first().unwrap_or(&Expression::error(span)).clone(); - let message = expressions.get(1).cloned(); - StatementKind::Constrain(ConstrainStatement(condition, message, ConstrainKind::Assert)) - }) +fn break_statement() -> impl NoirParser { + keyword(Keyword::Break).to(StatementKind::Break) } -fn assertion_eq<'a, P>(expr_parser: P) -> impl NoirParser + 'a -where - P: ExprParser + 'a, -{ - let argument_parser = - expr_parser.separated_by(just(Token::Comma)).allow_trailing().at_least(2).at_most(3); - - ignore_then_commit(keyword(Keyword::AssertEq), parenthesized(argument_parser)) - .labelled(ParsingRuleLabel::Statement) - .validate(|exprs: Vec, span, _| { - let predicate = Expression::new( - ExpressionKind::Infix(Box::new(InfixExpression { - lhs: exprs.first().unwrap_or(&Expression::error(span)).clone(), - rhs: exprs.get(1).unwrap_or(&Expression::error(span)).clone(), - operator: Spanned::from(span, BinaryOpKind::Equal), - })), - span, - ); - let message = exprs.get(2).cloned(); - StatementKind::Constrain(ConstrainStatement( - predicate, - message, - ConstrainKind::AssertEq, - )) - }) +fn continue_statement() -> impl NoirParser { + keyword(Keyword::Continue).to(StatementKind::Continue) } fn declaration<'a, P>(expr_parser: P) -> impl NoirParser + 'a @@ -951,8 +526,8 @@ fn assign_operator() -> impl NoirParser { } enum LValueRhs { - MemberAccess(Ident), - Index(Expression), + MemberAccess(Ident, Span), + Index(Expression, Span), } fn lvalue<'a, P>(expr_parser: P) -> impl NoirParser + 'a @@ -964,23 +539,28 @@ where let dereferences = just(Token::Star) .ignore_then(lvalue.clone()) - .map(|lvalue| LValue::Dereference(Box::new(lvalue))); + .map_with_span(|lvalue, span| LValue::Dereference(Box::new(lvalue), span)); let parenthesized = lvalue.delimited_by(just(Token::LeftParen), just(Token::RightParen)); let term = choice((parenthesized, dereferences, l_ident)); - let l_member_rhs = just(Token::Dot).ignore_then(field_name()).map(LValueRhs::MemberAccess); + let l_member_rhs = + just(Token::Dot).ignore_then(field_name()).map_with_span(LValueRhs::MemberAccess); let l_index = expr_parser .delimited_by(just(Token::LeftBracket), just(Token::RightBracket)) - .map(LValueRhs::Index); + .map_with_span(LValueRhs::Index); term.then(l_member_rhs.or(l_index).repeated()).foldl(|lvalue, rhs| match rhs { - LValueRhs::MemberAccess(field_name) => { - LValue::MemberAccess { object: Box::new(lvalue), field_name } + LValueRhs::MemberAccess(field_name, span) => { + let span = lvalue.span().merge(span); + LValue::MemberAccess { object: Box::new(lvalue), field_name, span } + } + LValueRhs::Index(index, span) => { + let span = lvalue.span().merge(span); + LValue::Index { array: Box::new(lvalue), index, span } } - LValueRhs::Index(index) => LValue::Index { array: Box::new(lvalue), index }, }) }) } @@ -1000,6 +580,7 @@ fn parse_type_inner( format_string_type(recursive_type_parser.clone()), named_type(recursive_type_parser.clone()), named_trait(recursive_type_parser.clone()), + slice_type(recursive_type_parser.clone()), array_type(recursive_type_parser.clone()), parenthesized_type(recursive_type_parser.clone()), tuple_type(recursive_type_parser.clone()), @@ -1136,13 +717,22 @@ fn generic_type_args( fn array_type(type_parser: impl NoirParser) -> impl NoirParser { just(Token::LeftBracket) .ignore_then(type_parser) - .then(just(Token::Semicolon).ignore_then(type_expression()).or_not()) + .then(just(Token::Semicolon).ignore_then(type_expression())) .then_ignore(just(Token::RightBracket)) .map_with_span(|(element_type, size), span| { UnresolvedTypeData::Array(size, Box::new(element_type)).with_span(span) }) } +fn slice_type(type_parser: impl NoirParser) -> impl NoirParser { + just(Token::LeftBracket) + .ignore_then(type_parser) + .then_ignore(just(Token::RightBracket)) + .map_with_span(|element_type, span| { + UnresolvedTypeData::Slice(Box::new(element_type)).with_span(span) + }) +} + fn type_expression() -> impl NoirParser { recursive(|expr| { expression_with_precedence( @@ -1308,13 +898,6 @@ fn create_infix_expression(lhs: Expression, (operator, rhs): (BinaryOp, Expressi Expression { span, kind: ExpressionKind::Infix(infix) } } -// Right-shift (>>) is issued as two separate > tokens by the lexer as this makes it easier -// to parse nested generic types. For normal expressions however, it means we have to manually -// parse two greater-than tokens as a single right-shift here. -fn right_shift_operator() -> impl NoirParser { - just(Token::Greater).then(just(Token::Greater)).to(Token::ShiftRight) -} - fn operator_with_precedence(precedence: Precedence) -> impl NoirParser> { right_shift_operator() .or(any()) // Parse any single token, we're validating it as an operator next @@ -1437,10 +1020,12 @@ where // Wrap the inner `if` expression in a block expression. // i.e. rewrite the sugared form `if cond1 {} else if cond2 {}` as `if cond1 {} else { if cond2 {} }`. let if_expression = Expression::new(kind, span); - let desugared_else = BlockExpression(vec![Statement { - kind: StatementKind::Expression(if_expression), - span, - }]); + let desugared_else = BlockExpression { + statements: vec![Statement { + kind: StatementKind::Expression(if_expression), + span, + }], + }; Expression::new(ExpressionKind::Block(desugared_else), span) })); @@ -1454,18 +1039,6 @@ where }) } -fn lambda<'a>( - expr_parser: impl NoirParser + 'a, -) -> impl NoirParser + 'a { - lambda_parameters() - .delimited_by(just(Token::Pipe), just(Token::Pipe)) - .then(lambda_return_type()) - .then(expr_parser) - .map(|((parameters, return_type), body)| { - ExpressionKind::Lambda(Box::new(Lambda { parameters, return_type, body })) - }) -} - fn for_loop<'a, P, S>(expr_no_constructors: P, statement: S) -> impl NoirParser + 'a where P: ExprParser + 'a, @@ -1523,46 +1096,41 @@ where .map(|(lhs, count)| ExpressionKind::repeated_array(lhs, count)) } -fn expression_list

(expr_parser: P) -> impl NoirParser> +fn slice_expr

(expr_parser: P) -> impl NoirParser where P: ExprParser, { - expr_parser.separated_by(just(Token::Comma)).allow_trailing() -} - -fn not

(term_parser: P) -> impl NoirParser -where - P: ExprParser, -{ - just(Token::Bang).ignore_then(term_parser).map(|rhs| ExpressionKind::prefix(UnaryOp::Not, rhs)) + just(Token::Ampersand) + .ignore_then(standard_slice(expr_parser.clone()).or(slice_sugar(expr_parser))) } -fn negation

(term_parser: P) -> impl NoirParser +/// &[a, b, c, ...] +fn standard_slice

(expr_parser: P) -> impl NoirParser where P: ExprParser, { - just(Token::Minus) - .ignore_then(term_parser) - .map(|rhs| ExpressionKind::prefix(UnaryOp::Minus, rhs)) + expression_list(expr_parser) + .delimited_by(just(Token::LeftBracket), just(Token::RightBracket)) + .validate(|elements, _span, _emit| ExpressionKind::slice(elements)) } -fn mutable_reference

(term_parser: P) -> impl NoirParser +/// &[a; N] +fn slice_sugar

(expr_parser: P) -> impl NoirParser where P: ExprParser, { - just(Token::Ampersand) - .ignore_then(keyword(Keyword::Mut)) - .ignore_then(term_parser) - .map(|rhs| ExpressionKind::prefix(UnaryOp::MutableReference, rhs)) + expr_parser + .clone() + .then(just(Token::Semicolon).ignore_then(expr_parser)) + .delimited_by(just(Token::LeftBracket), just(Token::RightBracket)) + .map(|(lhs, count)| ExpressionKind::repeated_slice(lhs, count)) } -fn dereference

(term_parser: P) -> impl NoirParser +fn expression_list

(expr_parser: P) -> impl NoirParser> where P: ExprParser, { - just(Token::Star) - .ignore_then(term_parser) - .map(|rhs| ExpressionKind::prefix(UnaryOp::Dereference { implicitly_added: false }, rhs)) + expr_parser.separated_by(just(Token::Comma)).allow_trailing() } /// Atoms are parameterized on whether constructor expressions are allowed or not. @@ -1581,14 +1149,16 @@ where { choice(( if_expr(expr_no_constructors, statement.clone()), + slice_expr(expr_parser.clone()), array_expr(expr_parser.clone()), if allow_constructors { constructor(expr_parser.clone()).boxed() } else { nothing().boxed() }, - lambda(expr_parser.clone()), - block(statement).map(ExpressionKind::Block), + lambdas::lambda(expr_parser.clone()), + block(statement.clone()).map(ExpressionKind::Block), + quote(statement), variable(), literal(), )) @@ -1613,6 +1183,19 @@ where .labelled(ParsingRuleLabel::Atom) } +fn quote<'a, P>(statement: P) -> impl NoirParser + 'a +where + P: NoirParser + 'a, +{ + keyword(Keyword::Quote).ignore_then(block(statement)).validate(|block, span, emit| { + emit(ParserError::with_reason( + ParserErrorReason::ExperimentalFeature("quoted expressions"), + span, + )); + ExpressionKind::Quote(block) + }) +} + fn tuple

(expr_parser: P) -> impl NoirParser where P: ExprParser, @@ -1655,166 +1238,11 @@ where long_form.or(short_form) } -fn variable() -> impl NoirParser { - path().map(ExpressionKind::Variable) -} - -fn literal() -> impl NoirParser { - token_kind(TokenKind::Literal).map(|token| match token { - Token::Int(x) => ExpressionKind::integer(x), - Token::Bool(b) => ExpressionKind::boolean(b), - Token::Str(s) => ExpressionKind::string(s), - Token::RawStr(s, hashes) => ExpressionKind::raw_string(s, hashes), - Token::FmtStr(s) => ExpressionKind::format_string(s), - unexpected => unreachable!("Non-literal {} parsed as a literal", unexpected), - }) -} - #[cfg(test)] mod test { - use noirc_errors::CustomDiagnostic; - + use super::test_helpers::*; use super::*; - use crate::{ArrayLiteral, Literal}; - - fn parse_with(parser: P, program: &str) -> Result> - where - P: NoirParser, - { - let (tokens, lexer_errors) = Lexer::lex(program); - if !lexer_errors.is_empty() { - return Err(vecmap(lexer_errors, Into::into)); - } - parser - .then_ignore(just(Token::EOF)) - .parse(tokens) - .map_err(|errors| vecmap(errors, Into::into)) - } - - fn parse_recover(parser: P, program: &str) -> (Option, Vec) - where - P: NoirParser, - { - let (tokens, lexer_errors) = Lexer::lex(program); - let (opt, errs) = parser.then_ignore(force(just(Token::EOF))).parse_recovery(tokens); - - let mut errors = vecmap(lexer_errors, Into::into); - errors.extend(errs.into_iter().map(Into::into)); - - (opt, errors) - } - - fn parse_all(parser: P, programs: Vec<&str>) -> Vec - where - P: NoirParser, - { - vecmap(programs, move |program| { - let message = format!("Failed to parse:\n{program}"); - let (op_t, diagnostics) = parse_recover(&parser, program); - diagnostics.iter().for_each(|diagnostic| { - if diagnostic.is_error() { - panic!("{} with error {}", &message, diagnostic); - } - }); - op_t.expect(&message) - }) - } - - fn parse_all_failing(parser: P, programs: Vec<&str>) -> Vec - where - P: NoirParser, - T: std::fmt::Display, - { - programs - .into_iter() - .flat_map(|program| match parse_with(&parser, program) { - Ok(expr) => { - unreachable!( - "Expected this input to fail:\n{}\nYet it successfully parsed as:\n{}", - program, expr - ) - } - Err(diagnostics) => { - if diagnostics.iter().all(|diagnostic: &CustomDiagnostic| diagnostic.is_warning()) { - unreachable!( - "Expected at least one error when parsing:\n{}\nYet it successfully parsed without errors:\n", - program - ) - }; - diagnostics - } - }) - .collect() - } - - #[derive(Copy, Clone)] - struct Case { - source: &'static str, - errors: usize, - expect: &'static str, - } - - fn check_cases_with_errors(cases: &[Case], parser: P) - where - P: NoirParser + Clone, - T: std::fmt::Display, - { - let show_errors = |v| vecmap(&v, ToString::to_string).join("\n"); - - let results = vecmap(cases, |&case| { - let (opt, errors) = parse_recover(parser.clone(), case.source); - let actual = opt.map(|ast| ast.to_string()); - let actual = if let Some(s) = &actual { s.to_string() } else { "(none)".to_string() }; - - let result = ((errors.len(), actual.clone()), (case.errors, case.expect.to_string())); - if result.0 != result.1 { - let num_errors = errors.len(); - let shown_errors = show_errors(errors); - eprintln!( - concat!( - "\nExpected {expected_errors} error(s) and got {num_errors}:", - "\n\n{shown_errors}", - "\n\nFrom input: {src}", - "\nExpected AST: {expected_result}", - "\nActual AST: {actual}\n", - ), - expected_errors = case.errors, - num_errors = num_errors, - shown_errors = shown_errors, - src = case.source, - expected_result = case.expect, - actual = actual, - ); - } - result - }); - - assert_eq!(vecmap(&results, |t| t.0.clone()), vecmap(&results, |t| t.1.clone()),); - } - - #[test] - fn regression_skip_comment() { - parse_all( - function_definition(false), - vec![ - "fn main( - // This comment should be skipped - x : Field, - // And this one - y : Field, - ) { - }", - "fn main(x : Field, y : Field,) { - foo::bar( - // Comment for x argument - x, - // Comment for y argument - y - ) - }", - ], - ); - } + use crate::ArrayLiteral; #[test] fn parse_infix() { @@ -1927,6 +1355,50 @@ mod test { parse_all_failing(array_expr(expression()), invalid); } + fn expr_to_slice(expr: ExpressionKind) -> ArrayLiteral { + let lit = match expr { + ExpressionKind::Literal(literal) => literal, + _ => unreachable!("expected a literal"), + }; + + match lit { + Literal::Slice(arr) => arr, + _ => unreachable!("expected a slice: {:?}", lit), + } + } + + #[test] + fn parse_slice() { + let valid = vec![ + "&[0, 1, 2,3, 4]", + "&[0,1,2,3,4,]", // Trailing commas are valid syntax + "&[0;5]", + ]; + + for expr in parse_all(slice_expr(expression()), valid) { + match expr_to_slice(expr) { + ArrayLiteral::Standard(elements) => assert_eq!(elements.len(), 5), + ArrayLiteral::Repeated { length, .. } => { + assert_eq!(length.kind, ExpressionKind::integer(5i128.into())); + } + } + } + + parse_all_failing( + slice_expr(expression()), + vec!["0,1,2,3,4]", "&[[0,1,2,3,4]", "&[0,1,2,,]", "&[0,1,2,3,4"], + ); + } + + #[test] + fn parse_slice_sugar() { + let valid = vec!["&[0;7]", "&[(1, 2); 4]", "&[0;Four]", "&[2;1+3-a]"]; + parse_all(slice_expr(expression()), valid); + + let invalid = vec!["&[0;;4]", "&[1, 2; 3]"]; + parse_all_failing(slice_expr(expression()), invalid); + } + #[test] fn parse_block() { parse_with(block(fresh_statement()), "{ [0,1,2,3,4] }").unwrap(); @@ -1934,13 +1406,13 @@ mod test { // Regression for #1310: this should be parsed as a block and not a function call let res = parse_with(block(fresh_statement()), "{ if true { 1 } else { 2 } (3, 4) }").unwrap(); - match unwrap_expr(&res.0.last().unwrap().kind) { + match unwrap_expr(&res.statements.last().unwrap().kind) { // The `if` followed by a tuple is currently creates a block around both in case // there was none to start with, so there is an extra block here. ExpressionKind::Block(block) => { - assert_eq!(block.0.len(), 2); - assert!(matches!(unwrap_expr(&block.0[0].kind), ExpressionKind::If(_))); - assert!(matches!(unwrap_expr(&block.0[1].kind), ExpressionKind::Tuple(_))); + assert_eq!(block.statements.len(), 2); + assert!(matches!(unwrap_expr(&block.statements[0].kind), ExpressionKind::If(_))); + assert!(matches!(unwrap_expr(&block.statements[1].kind), ExpressionKind::Tuple(_))); } _ => unreachable!(), } @@ -1966,142 +1438,6 @@ mod test { } } - /// Deprecated constrain usage test - #[test] - fn parse_constrain() { - let errors = parse_with(constrain(expression()), "constrain x == y").unwrap_err(); - assert_eq!(errors.len(), 1); - assert!(format!("{}", errors.first().unwrap()).contains("deprecated")); - - // Currently we disallow constrain statements where the outer infix operator - // produces a value. This would require an implicit `==` which - // may not be intuitive to the user. - // - // If this is deemed useful, one would either apply a transformation - // or interpret it with an `==` in the evaluator - let disallowed_operators = vec![ - BinaryOpKind::And, - BinaryOpKind::Subtract, - BinaryOpKind::Divide, - BinaryOpKind::Multiply, - BinaryOpKind::Or, - ]; - - for operator in disallowed_operators { - let src = format!("constrain x {} y;", operator.as_string()); - let errors = parse_with(constrain(expression()), &src).unwrap_err(); - assert_eq!(errors.len(), 2); - assert!(format!("{}", errors.first().unwrap()).contains("deprecated")); - } - - // These are general cases which should always work. - // - // The first case is the most noteworthy. It contains two `==` - // The first (inner) `==` is a predicate which returns 0/1 - // The outer layer is an infix `==` which is - // associated with the Constrain statement - let errors = parse_all_failing( - constrain(expression()), - vec![ - "constrain ((x + y) == k) + z == y", - "constrain (x + !y) == y", - "constrain (x ^ y) == y", - "constrain (x ^ y) == (y + m)", - "constrain x + x ^ x == y | m", - ], - ); - assert_eq!(errors.len(), 5); - assert!(errors - .iter() - .all(|err| { err.is_error() && err.to_string().contains("deprecated") })); - } - - /// This is the standard way to declare an assert statement - #[test] - fn parse_assert() { - parse_with(assertion(expression()), "assert(x == y)").unwrap(); - - // Currently we disallow constrain statements where the outer infix operator - // produces a value. This would require an implicit `==` which - // may not be intuitive to the user. - // - // If this is deemed useful, one would either apply a transformation - // or interpret it with an `==` in the evaluator - let disallowed_operators = vec![ - BinaryOpKind::And, - BinaryOpKind::Subtract, - BinaryOpKind::Divide, - BinaryOpKind::Multiply, - BinaryOpKind::Or, - ]; - - for operator in disallowed_operators { - let src = format!("assert(x {} y);", operator.as_string()); - parse_with(assertion(expression()), &src).unwrap_err(); - } - - // These are general cases which should always work. - // - // The first case is the most noteworthy. It contains two `==` - // The first (inner) `==` is a predicate which returns 0/1 - // The outer layer is an infix `==` which is - // associated with the Constrain statement - parse_all( - assertion(expression()), - vec![ - "assert(((x + y) == k) + z == y)", - "assert((x + !y) == y)", - "assert((x ^ y) == y)", - "assert((x ^ y) == (y + m))", - "assert(x + x ^ x == y | m)", - ], - ); - - match parse_with(assertion(expression()), "assert(x == y, \"assertion message\")").unwrap() - { - StatementKind::Constrain(ConstrainStatement(_, message, _)) => { - let message = message.unwrap(); - match message.kind { - ExpressionKind::Literal(Literal::Str(message_string)) => { - assert_eq!(message_string, "assertion message".to_owned()); - } - _ => unreachable!(), - } - } - _ => unreachable!(), - } - } - - /// This is the standard way to assert that two expressions are equivalent - #[test] - fn parse_assert_eq() { - parse_all( - assertion_eq(expression()), - vec![ - "assert_eq(x, y)", - "assert_eq(((x + y) == k) + z, y)", - "assert_eq(x + !y, y)", - "assert_eq(x ^ y, y)", - "assert_eq(x ^ y, y + m)", - "assert_eq(x + x ^ x, y | m)", - ], - ); - match parse_with(assertion_eq(expression()), "assert_eq(x, y, \"assertion message\")") - .unwrap() - { - StatementKind::Constrain(ConstrainStatement(_, message, _)) => { - let message = message.unwrap(); - match message.kind { - ExpressionKind::Literal(Literal::Str(message_string)) => { - assert_eq!(message_string, "assertion message".to_owned()); - } - _ => unreachable!(), - } - } - _ => unreachable!(), - } - } - #[test] fn parse_let() { // Why is it valid to specify a let declaration as having type u8? @@ -2135,84 +1471,6 @@ mod test { ); } - #[test] - fn parse_function() { - parse_all( - function_definition(false), - vec![ - "fn func_name() {}", - "fn f(foo: pub u8, y : pub Field) -> u8 { x + a }", - "fn f(f: pub Field, y : Field, z : Field) -> u8 { x + a }", - "fn func_name(f: Field, y : pub Field, z : pub [u8;5],) {}", - "fn f(f: pub Field, y : Field, z : Field) -> u8 { x + a }", - "fn f(f: pub Field, y : T, z : Field) -> u8 { x + a }", - "fn func_name(x: [Field], y : [Field;2],y : pub [Field;2], z : pub [u8;5]) {}", - "fn main(x: pub u8, y: pub u8) -> distinct pub [u8; 2] { [x, y] }", - "fn f(f: pub Field, y : Field, z : comptime Field) -> u8 { x + a }", - "fn f(f: pub Field, y : T, z : comptime Field) -> u8 { x + a }", - "fn func_name(f: Field, y : T) where T: SomeTrait {}", - "fn func_name(f: Field, y : T) where T: SomeTrait + SomeTrait2 {}", - "fn func_name(f: Field, y : T) where T: SomeTrait, T: SomeTrait2 {}", - "fn func_name(f: Field, y : T) where T: SomeTrait + SomeTrait2 {}", - "fn func_name(f: Field, y : T) where T: SomeTrait + SomeTrait2 {}", - "fn func_name(f: Field, y : T) where T: SomeTrait + SomeTrait2 {}", - "fn func_name(f: Field, y : T) where T: SomeTrait + SomeTrait2 {}", - "fn func_name(f: Field, y : T) where T: SomeTrait + SomeTrait2 + TraitY {}", - "fn func_name(f: Field, y : T, z : U) where SomeStruct: SomeTrait {}", - // 'where u32: SomeTrait' is allowed in Rust. - // It will result in compiler error in case SomeTrait isn't implemented for u32. - "fn func_name(f: Field, y : T) where u32: SomeTrait {}", - // A trailing plus is allowed by Rust, so we support it as well. - "fn func_name(f: Field, y : T) where T: SomeTrait + {}", - // The following should produce compile error on later stage. From the parser's perspective it's fine - "fn func_name(f: Field, y : Field, z : Field) where T: SomeTrait {}", - ], - ); - - parse_all_failing( - function_definition(false), - vec![ - "fn x2( f: []Field,,) {}", - "fn ( f: []Field) {}", - "fn ( f: []Field) {}", - // TODO: Check for more specific error messages - "fn func_name(f: Field, y : pub Field, z : pub [u8;5],) where T: {}", - "fn func_name(f: Field, y : pub Field, z : pub [u8;5],) where SomeTrait {}", - "fn func_name(f: Field, y : pub Field, z : pub [u8;5],) SomeTrait {}", - // A leading plus is not allowed. - "fn func_name(f: Field, y : T) where T: + SomeTrait {}", - "fn func_name(f: Field, y : T) where T: TraitX + {}", - ], - ); - } - - #[test] - fn parse_trait() { - parse_all( - trait_definition(), - vec![ - // Empty traits are legal in Rust and sometimes used as a way to whitelist certain types - // for a particular operation. Also known as `tag` or `marker` traits: - // https://stackoverflow.com/questions/71895489/what-is-the-purpose-of-defining-empty-impl-in-rust - "trait Empty {}", - "trait TraitWithDefaultBody { fn foo(self) {} }", - "trait TraitAcceptingMutableRef { fn foo(&mut self); }", - "trait TraitWithTypeBoundOperation { fn identity() -> Self; }", - "trait TraitWithAssociatedType { type Element; fn item(self, index: Field) -> Self::Element; }", - "trait TraitWithAssociatedConstant { let Size: Field; }", - "trait TraitWithAssociatedConstantWithDefaultValue { let Size: Field = 10; }", - "trait GenericTrait { fn elem(&mut self, index: Field) -> T; }", - "trait GenericTraitWithConstraints where T: SomeTrait { fn elem(self, index: Field) -> T; }", - "trait TraitWithMultipleGenericParams where A: SomeTrait, B: AnotherTrait { let Size: Field; fn zero() -> Self; }", - ], - ); - - parse_all_failing( - trait_definition(), - vec!["trait MissingBody", "trait WrongDelimiter { fn foo() -> u8, fn bar() -> u8 }"], - ); - } - #[test] fn parse_parenthesized_expression() { parse_all( @@ -2243,104 +1501,12 @@ mod test { ); } - fn expr_to_lit(expr: ExpressionKind) -> Literal { - match expr { - ExpressionKind::Literal(literal) => literal, - _ => unreachable!("expected a literal"), - } - } - - #[test] - fn parse_int() { - let int = parse_with(literal(), "5").unwrap(); - let hex = parse_with(literal(), "0x05").unwrap(); - - match (expr_to_lit(int), expr_to_lit(hex)) { - (Literal::Integer(int, false), Literal::Integer(hex, false)) => assert_eq!(int, hex), - _ => unreachable!(), - } - } - - #[test] - fn parse_string() { - let expr = parse_with(literal(), r#""hello""#).unwrap(); - match expr_to_lit(expr) { - Literal::Str(s) => assert_eq!(s, "hello"), - _ => unreachable!(), - }; - } - - #[test] - fn parse_bool() { - let expr_true = parse_with(literal(), "true").unwrap(); - let expr_false = parse_with(literal(), "false").unwrap(); - - match (expr_to_lit(expr_true), expr_to_lit(expr_false)) { - (Literal::Bool(t), Literal::Bool(f)) => { - assert!(t); - assert!(!f); - } - _ => unreachable!(), - }; - } - #[test] fn parse_module_declaration() { parse_with(module_declaration(), "mod foo").unwrap(); parse_with(module_declaration(), "mod 1").unwrap_err(); } - #[test] - fn parse_path() { - let cases = vec![ - ("std", vec!["std"]), - ("std::hash", vec!["std", "hash"]), - ("std::hash::collections", vec!["std", "hash", "collections"]), - ("dep::foo::bar", vec!["foo", "bar"]), - ("crate::std::hash", vec!["std", "hash"]), - ]; - - for (src, expected_segments) in cases { - let path: Path = parse_with(path(), src).unwrap(); - for (segment, expected) in path.segments.into_iter().zip(expected_segments) { - assert_eq!(segment.0.contents, expected); - } - } - - parse_all_failing(path(), vec!["std::", "::std", "std::hash::", "foo::1"]); - } - - #[test] - fn parse_path_kinds() { - let cases = vec![ - ("std", PathKind::Plain), - ("dep::hash::collections", PathKind::Dep), - ("crate::std::hash", PathKind::Crate), - ]; - - for (src, expected_path_kind) in cases { - let path = parse_with(path(), src).unwrap(); - assert_eq!(path.kind, expected_path_kind); - } - - parse_all_failing( - path(), - vec!["dep", "crate", "crate::std::crate", "foo::bar::crate", "foo::dep"], - ); - } - - #[test] - fn parse_unary() { - parse_all( - term(expression(), expression_no_constructors(expression()), fresh_statement(), true), - vec!["!hello", "-hello", "--hello", "-!hello", "!-hello"], - ); - parse_all_failing( - term(expression(), expression_no_constructors(expression()), fresh_statement(), true), - vec!["+hello", "/hello"], - ); - } - #[test] fn parse_use() { parse_all( @@ -2372,26 +1538,6 @@ mod test { ); } - #[test] - fn parse_structs() { - let cases = vec![ - "struct Foo;", - "struct Foo { }", - "struct Bar { ident: Field, }", - "struct Baz { ident: Field, other: Field }", - "#[attribute] struct Baz { ident: Field, other: Field }", - ]; - parse_all(struct_definition(), cases); - - let failing = vec![ - "struct { }", - "struct Foo { bar: pub Field }", - "struct Foo { bar: pub Field }", - "#[oracle(some)] struct Foo { bar: Field }", - ]; - parse_all_failing(struct_definition(), failing); - } - #[test] fn parse_type_aliases() { let cases = vec!["type foo = u8", "type bar = String", "type baz = Vec"]; @@ -2563,79 +1709,4 @@ mod test { check_cases_with_errors(&cases[..], block(fresh_statement())); } - - #[test] - fn parse_raw_string_expr() { - let cases = vec![ - Case { source: r#" r"foo" "#, expect: r#"r"foo""#, errors: 0 }, - Case { source: r##" r#"foo"# "##, expect: r##"r#"foo"#"##, errors: 0 }, - // backslash - Case { source: r#" r"\\" "#, expect: r#"r"\\""#, errors: 0 }, - Case { source: r##" r#"\"# "##, expect: r##"r#"\"#"##, errors: 0 }, - Case { source: r##" r#"\\"# "##, expect: r##"r#"\\"#"##, errors: 0 }, - Case { source: r##" r#"\\\"# "##, expect: r##"r#"\\\"#"##, errors: 0 }, - // escape sequence - Case { - source: r##" r#"\t\n\\t\\n\\\t\\\n\\\\"# "##, - expect: r##"r#"\t\n\\t\\n\\\t\\\n\\\\"#"##, - errors: 0, - }, - Case { source: r##" r#"\\\\\\\\"# "##, expect: r##"r#"\\\\\\\\"#"##, errors: 0 }, - // mismatch - errors: - Case { source: r###" r#"foo"## "###, expect: r##"r#"foo"#"##, errors: 1 }, - Case { source: r##" r##"foo"# "##, expect: "(none)", errors: 2 }, - // mismatch: short: - Case { source: r##" r"foo"# "##, expect: r#"r"foo""#, errors: 1 }, - Case { source: r#" r#"foo" "#, expect: "(none)", errors: 2 }, - // empty string - Case { source: r#"r"""#, expect: r#"r"""#, errors: 0 }, - Case { source: r####"r###""###"####, expect: r####"r###""###"####, errors: 0 }, - // miscellaneous - Case { source: r##" r#\"foo\"# "##, expect: "plain::r", errors: 2 }, - Case { source: r#" r\"foo\" "#, expect: "plain::r", errors: 1 }, - Case { source: r##" r##"foo"# "##, expect: "(none)", errors: 2 }, - // missing 'r' letter - Case { source: r##" ##"foo"# "##, expect: r#""foo""#, errors: 2 }, - Case { source: r#" #"foo" "#, expect: "plain::foo", errors: 2 }, - // whitespace - Case { source: r##" r #"foo"# "##, expect: "plain::r", errors: 2 }, - Case { source: r##" r# "foo"# "##, expect: "plain::r", errors: 3 }, - Case { source: r#" r#"foo" # "#, expect: "(none)", errors: 2 }, - // after identifier - Case { source: r##" bar#"foo"# "##, expect: "plain::bar", errors: 2 }, - // nested - Case { - source: r###"r##"foo r#"bar"# r"baz" ### bye"##"###, - expect: r###"r##"foo r#"bar"# r"baz" ### bye"##"###, - errors: 0, - }, - ]; - - check_cases_with_errors(&cases[..], expression()); - } - - #[test] - fn parse_raw_string_lit() { - let lit_cases = vec![ - Case { source: r#" r"foo" "#, expect: r#"r"foo""#, errors: 0 }, - Case { source: r##" r#"foo"# "##, expect: r##"r#"foo"#"##, errors: 0 }, - // backslash - Case { source: r#" r"\\" "#, expect: r#"r"\\""#, errors: 0 }, - Case { source: r##" r#"\"# "##, expect: r##"r#"\"#"##, errors: 0 }, - Case { source: r##" r#"\\"# "##, expect: r##"r#"\\"#"##, errors: 0 }, - Case { source: r##" r#"\\\"# "##, expect: r##"r#"\\\"#"##, errors: 0 }, - // escape sequence - Case { - source: r##" r#"\t\n\\t\\n\\\t\\\n\\\\"# "##, - expect: r##"r#"\t\n\\t\\n\\\t\\\n\\\\"#"##, - errors: 0, - }, - Case { source: r##" r#"\\\\\\\\"# "##, expect: r##"r#"\\\\\\\\"#"##, errors: 0 }, - // mismatch - errors: - Case { source: r###" r#"foo"## "###, expect: r##"r#"foo"#"##, errors: 1 }, - Case { source: r##" r##"foo"# "##, expect: "(none)", errors: 2 }, - ]; - - check_cases_with_errors(&lit_cases[..], literal()); - } } diff --git a/compiler/noirc_frontend/src/parser/parser/assertion.rs b/compiler/noirc_frontend/src/parser/parser/assertion.rs new file mode 100644 index 00000000000..f9c8d7aa46b --- /dev/null +++ b/compiler/noirc_frontend/src/parser/parser/assertion.rs @@ -0,0 +1,219 @@ +use crate::ast::{Expression, ExpressionKind, StatementKind}; +use crate::parser::{ + ignore_then_commit, labels::ParsingRuleLabel, parenthesized, ExprParser, NoirParser, + ParserError, ParserErrorReason, +}; + +use crate::token::{Keyword, Token}; +use crate::{BinaryOpKind, ConstrainKind, ConstrainStatement, InfixExpression, Recoverable}; + +use chumsky::prelude::*; +use noirc_errors::Spanned; + +use super::keyword; + +pub(super) fn constrain<'a, P>(expr_parser: P) -> impl NoirParser + 'a +where + P: ExprParser + 'a, +{ + ignore_then_commit( + keyword(Keyword::Constrain).labelled(ParsingRuleLabel::Statement), + expr_parser, + ) + .map(|expr| StatementKind::Constrain(ConstrainStatement(expr, None, ConstrainKind::Constrain))) + .validate(|expr, span, emit| { + emit(ParserError::with_reason(ParserErrorReason::ConstrainDeprecated, span)); + expr + }) +} + +pub(super) fn assertion<'a, P>(expr_parser: P) -> impl NoirParser + 'a +where + P: ExprParser + 'a, +{ + let argument_parser = + expr_parser.separated_by(just(Token::Comma)).allow_trailing().at_least(1).at_most(2); + + ignore_then_commit(keyword(Keyword::Assert), parenthesized(argument_parser)) + .labelled(ParsingRuleLabel::Statement) + .validate(|expressions, span, _| { + let condition = expressions.first().unwrap_or(&Expression::error(span)).clone(); + let message = expressions.get(1).cloned(); + StatementKind::Constrain(ConstrainStatement(condition, message, ConstrainKind::Assert)) + }) +} + +pub(super) fn assertion_eq<'a, P>(expr_parser: P) -> impl NoirParser + 'a +where + P: ExprParser + 'a, +{ + let argument_parser = + expr_parser.separated_by(just(Token::Comma)).allow_trailing().at_least(2).at_most(3); + + ignore_then_commit(keyword(Keyword::AssertEq), parenthesized(argument_parser)) + .labelled(ParsingRuleLabel::Statement) + .validate(|exprs: Vec, span, _| { + let predicate = Expression::new( + ExpressionKind::Infix(Box::new(InfixExpression { + lhs: exprs.first().unwrap_or(&Expression::error(span)).clone(), + rhs: exprs.get(1).unwrap_or(&Expression::error(span)).clone(), + operator: Spanned::from(span, BinaryOpKind::Equal), + })), + span, + ); + let message = exprs.get(2).cloned(); + StatementKind::Constrain(ConstrainStatement( + predicate, + message, + ConstrainKind::AssertEq, + )) + }) +} + +#[cfg(test)] +mod test { + use super::*; + use crate::{ + parser::parser::{ + expression, + test_helpers::{parse_all, parse_all_failing, parse_with}, + }, + Literal, + }; + + /// Deprecated constrain usage test + #[test] + fn parse_constrain() { + let errors = parse_with(constrain(expression()), "constrain x == y").unwrap_err(); + assert_eq!(errors.len(), 1); + assert!(format!("{}", errors.first().unwrap()).contains("deprecated")); + + // Currently we disallow constrain statements where the outer infix operator + // produces a value. This would require an implicit `==` which + // may not be intuitive to the user. + // + // If this is deemed useful, one would either apply a transformation + // or interpret it with an `==` in the evaluator + let disallowed_operators = vec![ + BinaryOpKind::And, + BinaryOpKind::Subtract, + BinaryOpKind::Divide, + BinaryOpKind::Multiply, + BinaryOpKind::Or, + ]; + + for operator in disallowed_operators { + let src = format!("constrain x {} y;", operator.as_string()); + let errors = parse_with(constrain(expression()), &src).unwrap_err(); + assert_eq!(errors.len(), 2); + assert!(format!("{}", errors.first().unwrap()).contains("deprecated")); + } + + // These are general cases which should always work. + // + // The first case is the most noteworthy. It contains two `==` + // The first (inner) `==` is a predicate which returns 0/1 + // The outer layer is an infix `==` which is + // associated with the Constrain statement + let errors = parse_all_failing( + constrain(expression()), + vec![ + "constrain ((x + y) == k) + z == y", + "constrain (x + !y) == y", + "constrain (x ^ y) == y", + "constrain (x ^ y) == (y + m)", + "constrain x + x ^ x == y | m", + ], + ); + assert_eq!(errors.len(), 5); + assert!(errors + .iter() + .all(|err| { err.is_error() && err.to_string().contains("deprecated") })); + } + + /// This is the standard way to declare an assert statement + #[test] + fn parse_assert() { + parse_with(assertion(expression()), "assert(x == y)").unwrap(); + + // Currently we disallow constrain statements where the outer infix operator + // produces a value. This would require an implicit `==` which + // may not be intuitive to the user. + // + // If this is deemed useful, one would either apply a transformation + // or interpret it with an `==` in the evaluator + let disallowed_operators = vec![ + BinaryOpKind::And, + BinaryOpKind::Subtract, + BinaryOpKind::Divide, + BinaryOpKind::Multiply, + BinaryOpKind::Or, + ]; + + for operator in disallowed_operators { + let src = format!("assert(x {} y);", operator.as_string()); + parse_with(assertion(expression()), &src).unwrap_err(); + } + + // These are general cases which should always work. + // + // The first case is the most noteworthy. It contains two `==` + // The first (inner) `==` is a predicate which returns 0/1 + // The outer layer is an infix `==` which is + // associated with the Constrain statement + parse_all( + assertion(expression()), + vec![ + "assert(((x + y) == k) + z == y)", + "assert((x + !y) == y)", + "assert((x ^ y) == y)", + "assert((x ^ y) == (y + m))", + "assert(x + x ^ x == y | m)", + ], + ); + + match parse_with(assertion(expression()), "assert(x == y, \"assertion message\")").unwrap() + { + StatementKind::Constrain(ConstrainStatement(_, message, _)) => { + let message = message.unwrap(); + match message.kind { + ExpressionKind::Literal(Literal::Str(message_string)) => { + assert_eq!(message_string, "assertion message".to_owned()); + } + _ => unreachable!(), + } + } + _ => unreachable!(), + } + } + + /// This is the standard way to assert that two expressions are equivalent + #[test] + fn parse_assert_eq() { + parse_all( + assertion_eq(expression()), + vec![ + "assert_eq(x, y)", + "assert_eq(((x + y) == k) + z, y)", + "assert_eq(x + !y, y)", + "assert_eq(x ^ y, y)", + "assert_eq(x ^ y, y + m)", + "assert_eq(x + x ^ x, y | m)", + ], + ); + match parse_with(assertion_eq(expression()), "assert_eq(x, y, \"assertion message\")") + .unwrap() + { + StatementKind::Constrain(ConstrainStatement(_, message, _)) => { + let message = message.unwrap(); + match message.kind { + ExpressionKind::Literal(Literal::Str(message_string)) => { + assert_eq!(message_string, "assertion message".to_owned()); + } + _ => unreachable!(), + } + } + _ => unreachable!(), + } + } +} diff --git a/compiler/noirc_frontend/src/parser/parser/attributes.rs b/compiler/noirc_frontend/src/parser/parser/attributes.rs new file mode 100644 index 00000000000..4b256a95c8b --- /dev/null +++ b/compiler/noirc_frontend/src/parser/parser/attributes.rs @@ -0,0 +1,46 @@ +use chumsky::Parser; +use noirc_errors::Span; + +use crate::{ + parser::{NoirParser, ParserError, ParserErrorReason}, + token::{Attribute, Attributes, Token, TokenKind}, +}; + +use super::primitives::token_kind; + +fn attribute() -> impl NoirParser { + token_kind(TokenKind::Attribute).map(|token| match token { + Token::Attribute(attribute) => attribute, + _ => unreachable!("Parser should have already errored due to token not being an attribute"), + }) +} + +pub(super) fn attributes() -> impl NoirParser> { + attribute().repeated() +} + +pub(super) fn validate_attributes( + attributes: Vec, + span: Span, + emit: &mut dyn FnMut(ParserError), +) -> Attributes { + let mut primary = None; + let mut secondary = Vec::new(); + + for attribute in attributes { + match attribute { + Attribute::Function(attr) => { + if primary.is_some() { + emit(ParserError::with_reason( + ParserErrorReason::MultipleFunctionAttributesFound, + span, + )); + } + primary = Some(attr); + } + Attribute::Secondary(attr) => secondary.push(attr), + } + } + + Attributes { function: primary, secondary } +} diff --git a/compiler/noirc_frontend/src/parser/parser/function.rs b/compiler/noirc_frontend/src/parser/parser/function.rs new file mode 100644 index 00000000000..06e1a958eb1 --- /dev/null +++ b/compiler/noirc_frontend/src/parser/parser/function.rs @@ -0,0 +1,211 @@ +use super::{ + attributes::{attributes, validate_attributes}, + block, fresh_statement, ident, keyword, nothing, optional_distinctness, optional_visibility, + parameter_name_recovery, parameter_recovery, parenthesized, parse_type, pattern, + self_parameter, where_clause, NoirParser, +}; +use crate::parser::labels::ParsingRuleLabel; +use crate::parser::spanned; +use crate::token::{Keyword, Token}; +use crate::{ + Distinctness, FunctionDefinition, FunctionReturnType, Ident, ItemVisibility, NoirFunction, + Param, Visibility, +}; + +use chumsky::prelude::*; + +/// function_definition: attribute function_modifiers 'fn' ident generics '(' function_parameters ')' function_return_type block +/// function_modifiers 'fn' ident generics '(' function_parameters ')' function_return_type block +pub(super) fn function_definition(allow_self: bool) -> impl NoirParser { + attributes() + .then(function_modifiers()) + .then_ignore(keyword(Keyword::Fn)) + .then(ident()) + .then(generics()) + .then(parenthesized(function_parameters(allow_self))) + .then(function_return_type()) + .then(where_clause()) + .then(spanned(block(fresh_statement()))) + .validate(|(((args, ret), where_clause), (body, body_span)), span, emit| { + let ((((attributes, modifiers), name), generics), parameters) = args; + + // Validate collected attributes, filtering them into function and secondary variants + let attributes = validate_attributes(attributes, span, emit); + FunctionDefinition { + span: body_span, + name, + attributes, + is_unconstrained: modifiers.0, + visibility: modifiers.1, + generics, + parameters, + body, + where_clause, + return_type: ret.1, + return_visibility: ret.0 .1, + return_distinctness: ret.0 .0, + } + .into() + }) +} + +/// visibility_modifier: 'pub(crate)'? 'pub'? '' +fn visibility_modifier() -> impl NoirParser { + let is_pub_crate = (keyword(Keyword::Pub) + .then_ignore(just(Token::LeftParen)) + .then_ignore(keyword(Keyword::Crate)) + .then_ignore(just(Token::RightParen))) + .map(|_| ItemVisibility::PublicCrate); + + let is_pub = keyword(Keyword::Pub).map(|_| ItemVisibility::Public); + + let is_private = empty().map(|_| ItemVisibility::Private); + + choice((is_pub_crate, is_pub, is_private)) +} + +/// function_modifiers: 'unconstrained'? (visibility)? +/// +/// returns (is_unconstrained, visibility) for whether each keyword was present +fn function_modifiers() -> impl NoirParser<(bool, ItemVisibility)> { + keyword(Keyword::Unconstrained) + .or_not() + .then(visibility_modifier()) + .map(|(unconstrained, visibility)| (unconstrained.is_some(), visibility)) +} + +/// non_empty_ident_list: ident ',' non_empty_ident_list +/// | ident +/// +/// generics: '<' non_empty_ident_list '>' +/// | %empty +pub(super) fn generics() -> impl NoirParser> { + ident() + .separated_by(just(Token::Comma)) + .allow_trailing() + .at_least(1) + .delimited_by(just(Token::Less), just(Token::Greater)) + .or_not() + .map(|opt| opt.unwrap_or_default()) +} + +fn function_return_type() -> impl NoirParser<((Distinctness, Visibility), FunctionReturnType)> { + just(Token::Arrow) + .ignore_then(optional_distinctness()) + .then(optional_visibility()) + .then(spanned(parse_type())) + .or_not() + .map_with_span(|ret, span| match ret { + Some((head, (ty, _))) => (head, FunctionReturnType::Ty(ty)), + None => ( + (Distinctness::DuplicationAllowed, Visibility::Private), + FunctionReturnType::Default(span), + ), + }) +} + +fn function_parameters<'a>(allow_self: bool) -> impl NoirParser> + 'a { + let typ = parse_type().recover_via(parameter_recovery()); + + let full_parameter = pattern() + .recover_via(parameter_name_recovery()) + .then_ignore(just(Token::Colon)) + .then(optional_visibility()) + .then(typ) + .map_with_span(|((pattern, visibility), typ), span| Param { + visibility, + pattern, + typ, + span, + }); + + let self_parameter = if allow_self { self_parameter().boxed() } else { nothing().boxed() }; + + let parameter = full_parameter.or(self_parameter); + + parameter + .separated_by(just(Token::Comma)) + .allow_trailing() + .labelled(ParsingRuleLabel::Parameter) +} + +#[cfg(test)] +mod test { + use super::*; + use crate::parser::parser::test_helpers::*; + + #[test] + fn regression_skip_comment() { + parse_all( + function_definition(false), + vec![ + "fn main( + // This comment should be skipped + x : Field, + // And this one + y : Field, + ) { + }", + "fn main(x : Field, y : Field,) { + foo::bar( + // Comment for x argument + x, + // Comment for y argument + y + ) + }", + ], + ); + } + + #[test] + fn parse_function() { + parse_all( + function_definition(false), + vec![ + "fn func_name() {}", + "fn f(foo: pub u8, y : pub Field) -> u8 { x + a }", + "fn f(f: pub Field, y : Field, z : Field) -> u8 { x + a }", + "fn func_name(f: Field, y : pub Field, z : pub [u8;5],) {}", + "fn f(f: pub Field, y : Field, z : Field) -> u8 { x + a }", + "fn f(f: pub Field, y : T, z : Field) -> u8 { x + a }", + "fn func_name(x: [Field], y : [Field;2],y : pub [Field;2], z : pub [u8;5]) {}", + "fn main(x: pub u8, y: pub u8) -> distinct pub [u8; 2] { [x, y] }", + "fn f(f: pub Field, y : Field, z : comptime Field) -> u8 { x + a }", + "fn f(f: pub Field, y : T, z : comptime Field) -> u8 { x + a }", + "fn func_name(f: Field, y : T) where T: SomeTrait {}", + "fn func_name(f: Field, y : T) where T: SomeTrait + SomeTrait2 {}", + "fn func_name(f: Field, y : T) where T: SomeTrait, T: SomeTrait2 {}", + "fn func_name(f: Field, y : T) where T: SomeTrait + SomeTrait2 {}", + "fn func_name(f: Field, y : T) where T: SomeTrait + SomeTrait2 {}", + "fn func_name(f: Field, y : T) where T: SomeTrait + SomeTrait2 {}", + "fn func_name(f: Field, y : T) where T: SomeTrait + SomeTrait2 {}", + "fn func_name(f: Field, y : T) where T: SomeTrait + SomeTrait2 + TraitY {}", + "fn func_name(f: Field, y : T, z : U) where SomeStruct: SomeTrait {}", + // 'where u32: SomeTrait' is allowed in Rust. + // It will result in compiler error in case SomeTrait isn't implemented for u32. + "fn func_name(f: Field, y : T) where u32: SomeTrait {}", + // A trailing plus is allowed by Rust, so we support it as well. + "fn func_name(f: Field, y : T) where T: SomeTrait + {}", + // The following should produce compile error on later stage. From the parser's perspective it's fine + "fn func_name(f: Field, y : Field, z : Field) where T: SomeTrait {}", + ], + ); + + parse_all_failing( + function_definition(false), + vec![ + "fn x2( f: []Field,,) {}", + "fn ( f: []Field) {}", + "fn ( f: []Field) {}", + // TODO: Check for more specific error messages + "fn func_name(f: Field, y : pub Field, z : pub [u8;5],) where T: {}", + "fn func_name(f: Field, y : pub Field, z : pub [u8;5],) where SomeTrait {}", + "fn func_name(f: Field, y : pub Field, z : pub [u8;5],) SomeTrait {}", + // A leading plus is not allowed. + "fn func_name(f: Field, y : T) where T: + SomeTrait {}", + "fn func_name(f: Field, y : T) where T: TraitX + {}", + ], + ); + } +} diff --git a/compiler/noirc_frontend/src/parser/parser/lambdas.rs b/compiler/noirc_frontend/src/parser/parser/lambdas.rs new file mode 100644 index 00000000000..48ddd41ab44 --- /dev/null +++ b/compiler/noirc_frontend/src/parser/parser/lambdas.rs @@ -0,0 +1,42 @@ +use chumsky::{primitive::just, Parser}; + +use crate::{ + parser::{labels::ParsingRuleLabel, parameter_name_recovery, parameter_recovery, NoirParser}, + token::Token, + Expression, ExpressionKind, Lambda, Pattern, UnresolvedType, +}; + +use super::{parse_type, pattern}; + +pub(super) fn lambda<'a>( + expr_parser: impl NoirParser + 'a, +) -> impl NoirParser + 'a { + lambda_parameters() + .delimited_by(just(Token::Pipe), just(Token::Pipe)) + .then(lambda_return_type()) + .then(expr_parser) + .map(|((parameters, return_type), body)| { + ExpressionKind::Lambda(Box::new(Lambda { parameters, return_type, body })) + }) +} + +fn lambda_parameters() -> impl NoirParser> { + let typ = parse_type().recover_via(parameter_recovery()); + let typ = just(Token::Colon).ignore_then(typ); + + let parameter = pattern() + .recover_via(parameter_name_recovery()) + .then(typ.or_not().map(|typ| typ.unwrap_or_else(UnresolvedType::unspecified))); + + parameter + .separated_by(just(Token::Comma)) + .allow_trailing() + .labelled(ParsingRuleLabel::Parameter) +} + +fn lambda_return_type() -> impl NoirParser { + just(Token::Arrow) + .ignore_then(parse_type()) + .or_not() + .map(|ret| ret.unwrap_or_else(UnresolvedType::unspecified)) +} diff --git a/compiler/noirc_frontend/src/parser/parser/literals.rs b/compiler/noirc_frontend/src/parser/parser/literals.rs new file mode 100644 index 00000000000..83d7b832d27 --- /dev/null +++ b/compiler/noirc_frontend/src/parser/parser/literals.rs @@ -0,0 +1,158 @@ +use chumsky::Parser; + +use crate::{ + parser::NoirParser, + token::{Token, TokenKind}, + ExpressionKind, +}; + +use super::primitives::token_kind; + +pub(super) fn literal() -> impl NoirParser { + token_kind(TokenKind::Literal).map(|token| match token { + Token::Int(x) => ExpressionKind::integer(x), + Token::Bool(b) => ExpressionKind::boolean(b), + Token::Str(s) => ExpressionKind::string(s), + Token::RawStr(s, hashes) => ExpressionKind::raw_string(s, hashes), + Token::FmtStr(s) => ExpressionKind::format_string(s), + unexpected => unreachable!("Non-literal {} parsed as a literal", unexpected), + }) +} + +#[cfg(test)] +mod test { + use super::*; + use crate::parser::parser::{ + expression, expression_no_constructors, fresh_statement, term, test_helpers::*, + }; + use crate::Literal; + + fn expr_to_lit(expr: ExpressionKind) -> Literal { + match expr { + ExpressionKind::Literal(literal) => literal, + _ => unreachable!("expected a literal"), + } + } + + #[test] + fn parse_int() { + let int = parse_with(literal(), "5").unwrap(); + let hex = parse_with(literal(), "0x05").unwrap(); + + match (expr_to_lit(int), expr_to_lit(hex)) { + (Literal::Integer(int, false), Literal::Integer(hex, false)) => assert_eq!(int, hex), + _ => unreachable!(), + } + } + + #[test] + fn parse_string() { + let expr = parse_with(literal(), r#""hello""#).unwrap(); + match expr_to_lit(expr) { + Literal::Str(s) => assert_eq!(s, "hello"), + _ => unreachable!(), + }; + } + + #[test] + fn parse_bool() { + let expr_true = parse_with(literal(), "true").unwrap(); + let expr_false = parse_with(literal(), "false").unwrap(); + + match (expr_to_lit(expr_true), expr_to_lit(expr_false)) { + (Literal::Bool(t), Literal::Bool(f)) => { + assert!(t); + assert!(!f); + } + _ => unreachable!(), + }; + } + + #[test] + fn parse_unary() { + parse_all( + term(expression(), expression_no_constructors(expression()), fresh_statement(), true), + vec!["!hello", "-hello", "--hello", "-!hello", "!-hello"], + ); + parse_all_failing( + term(expression(), expression_no_constructors(expression()), fresh_statement(), true), + vec!["+hello", "/hello"], + ); + } + + #[test] + fn parse_raw_string_expr() { + let cases = vec![ + Case { source: r#" r"foo" "#, expect: r#"r"foo""#, errors: 0 }, + Case { source: r##" r#"foo"# "##, expect: r##"r#"foo"#"##, errors: 0 }, + // backslash + Case { source: r#" r"\\" "#, expect: r#"r"\\""#, errors: 0 }, + Case { source: r##" r#"\"# "##, expect: r##"r#"\"#"##, errors: 0 }, + Case { source: r##" r#"\\"# "##, expect: r##"r#"\\"#"##, errors: 0 }, + Case { source: r##" r#"\\\"# "##, expect: r##"r#"\\\"#"##, errors: 0 }, + // escape sequence + Case { + source: r##" r#"\t\n\\t\\n\\\t\\\n\\\\"# "##, + expect: r##"r#"\t\n\\t\\n\\\t\\\n\\\\"#"##, + errors: 0, + }, + Case { source: r##" r#"\\\\\\\\"# "##, expect: r##"r#"\\\\\\\\"#"##, errors: 0 }, + // mismatch - errors: + Case { source: r###" r#"foo"## "###, expect: r##"r#"foo"#"##, errors: 1 }, + Case { source: r##" r##"foo"# "##, expect: "(none)", errors: 2 }, + // mismatch: short: + Case { source: r##" r"foo"# "##, expect: r#"r"foo""#, errors: 1 }, + Case { source: r#" r#"foo" "#, expect: "(none)", errors: 2 }, + // empty string + Case { source: r#"r"""#, expect: r#"r"""#, errors: 0 }, + #[allow(clippy::needless_raw_string_hashes)] + Case { source: r####"r###""###"####, expect: r####"r###""###"####, errors: 0 }, + // miscellaneous + Case { source: r##" r#\"foo\"# "##, expect: "plain::r", errors: 2 }, + Case { source: r#" r\"foo\" "#, expect: "plain::r", errors: 1 }, + Case { source: r##" r##"foo"# "##, expect: "(none)", errors: 2 }, + // missing 'r' letter + Case { source: r##" ##"foo"# "##, expect: r#""foo""#, errors: 2 }, + Case { source: r#" #"foo" "#, expect: "plain::foo", errors: 2 }, + // whitespace + Case { source: r##" r #"foo"# "##, expect: "plain::r", errors: 2 }, + Case { source: r##" r# "foo"# "##, expect: "plain::r", errors: 3 }, + Case { source: r#" r#"foo" # "#, expect: "(none)", errors: 2 }, + // after identifier + Case { source: r##" bar#"foo"# "##, expect: "plain::bar", errors: 2 }, + // nested + Case { + source: r###"r##"foo r#"bar"# r"baz" ### bye"##"###, + expect: r###"r##"foo r#"bar"# r"baz" ### bye"##"###, + errors: 0, + }, + ]; + + check_cases_with_errors(&cases[..], expression()); + } + + #[test] + fn parse_raw_string_lit() { + let lit_cases = vec![ + Case { source: r#" r"foo" "#, expect: r#"r"foo""#, errors: 0 }, + Case { source: r##" r#"foo"# "##, expect: r##"r#"foo"#"##, errors: 0 }, + // backslash + Case { source: r#" r"\\" "#, expect: r#"r"\\""#, errors: 0 }, + Case { source: r##" r#"\"# "##, expect: r##"r#"\"#"##, errors: 0 }, + Case { source: r##" r#"\\"# "##, expect: r##"r#"\\"#"##, errors: 0 }, + Case { source: r##" r#"\\\"# "##, expect: r##"r#"\\\"#"##, errors: 0 }, + // escape sequence + Case { + source: r##" r#"\t\n\\t\\n\\\t\\\n\\\\"# "##, + expect: r##"r#"\t\n\\t\\n\\\t\\\n\\\\"#"##, + errors: 0, + }, + Case { source: r##" r#"\\\\\\\\"# "##, expect: r##"r#"\\\\\\\\"#"##, errors: 0 }, + // mismatch - errors: + Case { source: r###" r#"foo"## "###, expect: r##"r#"foo"#"##, errors: 1 }, + Case { source: r##" r##"foo"# "##, expect: "(none)", errors: 2 }, + ]; + + check_cases_with_errors(&lit_cases[..], literal()); + } +} diff --git a/compiler/noirc_frontend/src/parser/parser/path.rs b/compiler/noirc_frontend/src/parser/parser/path.rs new file mode 100644 index 00000000000..ab812c07dce --- /dev/null +++ b/compiler/noirc_frontend/src/parser/parser/path.rs @@ -0,0 +1,78 @@ +use crate::parser::NoirParser; +use crate::{Path, PathKind}; + +use crate::token::{Keyword, Token}; + +use chumsky::prelude::*; + +use super::{ident, keyword}; + +pub(super) fn path() -> impl NoirParser { + let idents = || ident().separated_by(just(Token::DoubleColon)).at_least(1); + let make_path = |kind| move |segments, span| Path { segments, kind, span }; + + let prefix = |key| keyword(key).ignore_then(just(Token::DoubleColon)); + let path_kind = |key, kind| prefix(key).ignore_then(idents()).map_with_span(make_path(kind)); + + choice(( + path_kind(Keyword::Crate, PathKind::Crate), + path_kind(Keyword::Dep, PathKind::Dep), + idents().map_with_span(make_path(PathKind::Plain)), + )) +} + +fn empty_path() -> impl NoirParser { + let make_path = |kind| move |_, span| Path { segments: Vec::new(), kind, span }; + let path_kind = |key, kind| keyword(key).map_with_span(make_path(kind)); + + choice((path_kind(Keyword::Crate, PathKind::Crate), path_kind(Keyword::Dep, PathKind::Dep))) +} + +pub(super) fn maybe_empty_path() -> impl NoirParser { + path().or(empty_path()) +} + +#[cfg(test)] +mod test { + use super::*; + use crate::parser::parser::test_helpers::{parse_all_failing, parse_with}; + + #[test] + fn parse_path() { + let cases = vec![ + ("std", vec!["std"]), + ("std::hash", vec!["std", "hash"]), + ("std::hash::collections", vec!["std", "hash", "collections"]), + ("dep::foo::bar", vec!["foo", "bar"]), + ("crate::std::hash", vec!["std", "hash"]), + ]; + + for (src, expected_segments) in cases { + let path: Path = parse_with(path(), src).unwrap(); + for (segment, expected) in path.segments.into_iter().zip(expected_segments) { + assert_eq!(segment.0.contents, expected); + } + } + + parse_all_failing(path(), vec!["std::", "::std", "std::hash::", "foo::1"]); + } + + #[test] + fn parse_path_kinds() { + let cases = vec![ + ("std", PathKind::Plain), + ("dep::hash::collections", PathKind::Dep), + ("crate::std::hash", PathKind::Crate), + ]; + + for (src, expected_path_kind) in cases { + let path = parse_with(path(), src).unwrap(); + assert_eq!(path.kind, expected_path_kind); + } + + parse_all_failing( + path(), + vec!["dep", "crate", "crate::std::crate", "foo::bar::crate", "foo::dep"], + ); + } +} diff --git a/compiler/noirc_frontend/src/parser/parser/primitives.rs b/compiler/noirc_frontend/src/parser/parser/primitives.rs new file mode 100644 index 00000000000..34927278038 --- /dev/null +++ b/compiler/noirc_frontend/src/parser/parser/primitives.rs @@ -0,0 +1,101 @@ +use chumsky::prelude::*; + +use crate::{ + parser::{labels::ParsingRuleLabel, ExprParser, NoirParser, ParserError}, + token::{Keyword, Token, TokenKind}, + ExpressionKind, Ident, UnaryOp, +}; + +use super::path; + +/// This parser always parses no input and fails +pub(super) fn nothing() -> impl NoirParser { + one_of([]).map(|_| unreachable!("parser should always error")) +} + +pub(super) fn keyword(keyword: Keyword) -> impl NoirParser { + just(Token::Keyword(keyword)) +} + +pub(super) fn token_kind(token_kind: TokenKind) -> impl NoirParser { + filter_map(move |span, found: Token| { + if found.kind() == token_kind { + Ok(found) + } else { + Err(ParserError::expected_label( + ParsingRuleLabel::TokenKind(token_kind.clone()), + found, + span, + )) + } + }) +} + +pub(super) fn ident() -> impl NoirParser { + token_kind(TokenKind::Ident).map_with_span(Ident::from_token) +} + +// Right-shift (>>) is issued as two separate > tokens by the lexer as this makes it easier +// to parse nested generic types. For normal expressions however, it means we have to manually +// parse two greater-than tokens as a single right-shift here. +pub(super) fn right_shift_operator() -> impl NoirParser { + just(Token::Greater).then(just(Token::Greater)).to(Token::ShiftRight) +} + +pub(super) fn not

(term_parser: P) -> impl NoirParser +where + P: ExprParser, +{ + just(Token::Bang).ignore_then(term_parser).map(|rhs| ExpressionKind::prefix(UnaryOp::Not, rhs)) +} + +pub(super) fn negation

(term_parser: P) -> impl NoirParser +where + P: ExprParser, +{ + just(Token::Minus) + .ignore_then(term_parser) + .map(|rhs| ExpressionKind::prefix(UnaryOp::Minus, rhs)) +} + +pub(super) fn mutable_reference

(term_parser: P) -> impl NoirParser +where + P: ExprParser, +{ + just(Token::Ampersand) + .ignore_then(keyword(Keyword::Mut)) + .ignore_then(term_parser) + .map(|rhs| ExpressionKind::prefix(UnaryOp::MutableReference, rhs)) +} + +pub(super) fn dereference

(term_parser: P) -> impl NoirParser +where + P: ExprParser, +{ + just(Token::Star) + .ignore_then(term_parser) + .map(|rhs| ExpressionKind::prefix(UnaryOp::Dereference { implicitly_added: false }, rhs)) +} + +pub(super) fn variable() -> impl NoirParser { + path().map(ExpressionKind::Variable) +} + +#[cfg(test)] +mod test { + use crate::parser::parser::{ + expression, expression_no_constructors, fresh_statement, term, test_helpers::*, + }; + + #[test] + fn parse_unary() { + parse_all( + term(expression(), expression_no_constructors(expression()), fresh_statement(), true), + vec!["!hello", "-hello", "--hello", "-!hello", "!-hello"], + ); + parse_all_failing( + term(expression(), expression_no_constructors(expression()), fresh_statement(), true), + vec!["+hello", "/hello"], + ); + } +} diff --git a/compiler/noirc_frontend/src/parser/parser/structs.rs b/compiler/noirc_frontend/src/parser/parser/structs.rs new file mode 100644 index 00000000000..0212f56783f --- /dev/null +++ b/compiler/noirc_frontend/src/parser/parser/structs.rs @@ -0,0 +1,97 @@ +use chumsky::prelude::*; +use noirc_errors::Span; + +use crate::{ + macros_api::SecondaryAttribute, + parser::{ + parser::{ + attributes::attributes, + function, parse_type, + primitives::{ident, keyword}, + }, + NoirParser, ParserError, ParserErrorReason, TopLevelStatement, + }, + token::{Attribute, Keyword, Token}, + Ident, NoirStruct, UnresolvedType, +}; + +pub(super) fn struct_definition() -> impl NoirParser { + use self::Keyword::Struct; + use Token::*; + + let fields = struct_fields() + .delimited_by(just(LeftBrace), just(RightBrace)) + .recover_with(nested_delimiters( + LeftBrace, + RightBrace, + [(LeftParen, RightParen), (LeftBracket, RightBracket)], + |_| vec![], + )) + .or(just(Semicolon).to(Vec::new())); + + attributes() + .then_ignore(keyword(Struct)) + .then(ident()) + .then(function::generics()) + .then(fields) + .validate(|(((raw_attributes, name), generics), fields), span, emit| { + let attributes = validate_struct_attributes(raw_attributes, span, emit); + TopLevelStatement::Struct(NoirStruct { name, attributes, generics, fields, span }) + }) +} + +fn struct_fields() -> impl NoirParser> { + ident() + .then_ignore(just(Token::Colon)) + .then(parse_type()) + .separated_by(just(Token::Comma)) + .allow_trailing() +} + +fn validate_struct_attributes( + attributes: Vec, + span: Span, + emit: &mut dyn FnMut(ParserError), +) -> Vec { + let mut struct_attributes = vec![]; + + for attribute in attributes { + match attribute { + Attribute::Function(..) => { + emit(ParserError::with_reason( + ParserErrorReason::NoFunctionAttributesAllowedOnStruct, + span, + )); + } + Attribute::Secondary(attr) => struct_attributes.push(attr), + } + } + + struct_attributes +} + +#[cfg(test)] +mod test { + use super::*; + use crate::parser::parser::test_helpers::*; + + #[test] + fn parse_structs() { + let cases = vec![ + "struct Foo;", + "struct Foo { }", + "struct Bar { ident: Field, }", + "struct Baz { ident: Field, other: Field }", + "#[attribute] struct Baz { ident: Field, other: Field }", + ]; + parse_all(struct_definition(), cases); + + let failing = vec![ + "struct { }", + "struct Foo { bar: pub Field }", + "struct Foo { bar: pub Field }", + "#[oracle(some)] struct Foo { bar: Field }", + ]; + parse_all_failing(struct_definition(), failing); + } +} diff --git a/compiler/noirc_frontend/src/parser/parser/test_helpers.rs b/compiler/noirc_frontend/src/parser/parser/test_helpers.rs new file mode 100644 index 00000000000..6b8cb80a0a0 --- /dev/null +++ b/compiler/noirc_frontend/src/parser/parser/test_helpers.rs @@ -0,0 +1,122 @@ +use chumsky::primitive::just; +use chumsky::Parser; +use iter_extended::vecmap; +use noirc_errors::CustomDiagnostic; + +use crate::{ + lexer::Lexer, + parser::{force, NoirParser}, + token::Token, +}; + +pub(crate) fn parse_with(parser: P, program: &str) -> Result> +where + P: NoirParser, +{ + let (tokens, lexer_errors) = Lexer::lex(program); + if !lexer_errors.is_empty() { + return Err(vecmap(lexer_errors, Into::into)); + } + parser.then_ignore(just(Token::EOF)).parse(tokens).map_err(|errors| vecmap(errors, Into::into)) +} + +pub(crate) fn parse_recover(parser: P, program: &str) -> (Option, Vec) +where + P: NoirParser, +{ + let (tokens, lexer_errors) = Lexer::lex(program); + let (opt, errs) = parser.then_ignore(force(just(Token::EOF))).parse_recovery(tokens); + + let mut errors = vecmap(lexer_errors, Into::into); + errors.extend(errs.into_iter().map(Into::into)); + + (opt, errors) +} + +pub(crate) fn parse_all(parser: P, programs: Vec<&str>) -> Vec +where + P: NoirParser, +{ + vecmap(programs, move |program| { + let message = format!("Failed to parse:\n{program}"); + let (op_t, diagnostics) = parse_recover(&parser, program); + diagnostics.iter().for_each(|diagnostic| { + if diagnostic.is_error() { + panic!("{} with error {}", &message, diagnostic); + } + }); + op_t.expect(&message) + }) +} + +pub(crate) fn parse_all_failing(parser: P, programs: Vec<&str>) -> Vec +where + P: NoirParser, + T: std::fmt::Display, +{ + programs + .into_iter() + .flat_map(|program| match parse_with(&parser, program) { + Ok(expr) => { + unreachable!( + "Expected this input to fail:\n{}\nYet it successfully parsed as:\n{}", + program, expr + ) + } + Err(diagnostics) => { + if diagnostics.iter().all(|diagnostic: &CustomDiagnostic| diagnostic.is_warning()) { + unreachable!( + "Expected at least one error when parsing:\n{}\nYet it successfully parsed without errors:\n", + program + ) + }; + diagnostics + } + }) + .collect() +} + +#[derive(Copy, Clone)] +pub(crate) struct Case { + pub(crate) source: &'static str, + pub(crate) errors: usize, + pub(crate) expect: &'static str, +} + +pub(crate) fn check_cases_with_errors(cases: &[Case], parser: P) +where + P: NoirParser + Clone, + T: std::fmt::Display, +{ + let show_errors = |v| vecmap(&v, ToString::to_string).join("\n"); + + let results = vecmap(cases, |&case| { + let (opt, errors) = parse_recover(parser.clone(), case.source); + let actual = opt.map(|ast| ast.to_string()); + let actual = if let Some(s) = &actual { s.to_string() } else { "(none)".to_string() }; + + let result = ((errors.len(), actual.clone()), (case.errors, case.expect.to_string())); + if result.0 != result.1 { + let num_errors = errors.len(); + let shown_errors = show_errors(errors); + eprintln!( + concat!( + "\nExpected {expected_errors} error(s) and got {num_errors}:", + "\n\n{shown_errors}", + "\n\nFrom input: {src}", + "\nExpected AST: {expected_result}", + "\nActual AST: {actual}\n", + ), + expected_errors = case.errors, + num_errors = num_errors, + shown_errors = shown_errors, + src = case.source, + expected_result = case.expect, + actual = actual, + ); + } + result + }); + + assert_eq!(vecmap(&results, |t| t.0.clone()), vecmap(&results, |t| t.1.clone()),); +} diff --git a/compiler/noirc_frontend/src/parser/parser/traits.rs b/compiler/noirc_frontend/src/parser/parser/traits.rs new file mode 100644 index 00000000000..1e2a6b4d65d --- /dev/null +++ b/compiler/noirc_frontend/src/parser/parser/traits.rs @@ -0,0 +1,213 @@ +use chumsky::prelude::*; + +use super::{ + block, expression, fresh_statement, function, function_declaration_parameters, + function_return_type, +}; + +use crate::{ + parser::{ + ignore_then_commit, parenthesized, parser::primitives::keyword, NoirParser, ParserError, + ParserErrorReason, TopLevelStatement, + }, + token::{Keyword, Token}, + Expression, ItemVisibility, NoirTrait, NoirTraitImpl, TraitBound, TraitImplItem, TraitItem, + UnresolvedTraitConstraint, UnresolvedType, +}; + +use super::{generic_type_args, parse_type, path, primitives::ident}; + +pub(super) fn trait_definition() -> impl NoirParser { + keyword(Keyword::Trait) + .ignore_then(ident()) + .then(function::generics()) + .then(where_clause()) + .then_ignore(just(Token::LeftBrace)) + .then(trait_body()) + .then_ignore(just(Token::RightBrace)) + .map_with_span(|(((name, generics), where_clause), items), span| { + TopLevelStatement::Trait(NoirTrait { name, generics, where_clause, span, items }) + }) +} + +fn trait_body() -> impl NoirParser> { + trait_function_declaration() + .or(trait_type_declaration()) + .or(trait_constant_declaration()) + .repeated() +} + +fn optional_default_value() -> impl NoirParser> { + ignore_then_commit(just(Token::Assign), expression()).or_not() +} + +fn trait_constant_declaration() -> impl NoirParser { + keyword(Keyword::Let) + .ignore_then(ident()) + .then_ignore(just(Token::Colon)) + .then(parse_type()) + .then(optional_default_value()) + .then_ignore(just(Token::Semicolon)) + .validate(|((name, typ), default_value), span, emit| { + emit(ParserError::with_reason( + ParserErrorReason::ExperimentalFeature("Associated constants"), + span, + )); + TraitItem::Constant { name, typ, default_value } + }) +} + +/// trait_function_declaration: 'fn' ident generics '(' declaration_parameters ')' function_return_type +fn trait_function_declaration() -> impl NoirParser { + let trait_function_body_or_semicolon = + block(fresh_statement()).map(Option::from).or(just(Token::Semicolon).to(Option::None)); + + keyword(Keyword::Fn) + .ignore_then(ident()) + .then(function::generics()) + .then(parenthesized(function_declaration_parameters())) + .then(function_return_type().map(|(_, typ)| typ)) + .then(where_clause()) + .then(trait_function_body_or_semicolon) + .map(|(((((name, generics), parameters), return_type), where_clause), body)| { + TraitItem::Function { name, generics, parameters, return_type, where_clause, body } + }) +} + +/// trait_type_declaration: 'type' ident generics +fn trait_type_declaration() -> impl NoirParser { + keyword(Keyword::Type).ignore_then(ident()).then_ignore(just(Token::Semicolon)).validate( + |name, span, emit| { + emit(ParserError::with_reason( + ParserErrorReason::ExperimentalFeature("Associated types"), + span, + )); + TraitItem::Type { name } + }, + ) +} + +/// Parses a trait implementation, implementing a particular trait for a type. +/// This has a similar syntax to `implementation`, but the `for type` clause is required, +/// and an optional `where` clause is also useable. +/// +/// trait_implementation: 'impl' generics ident generic_args for type '{' trait_implementation_body '}' +pub(super) fn trait_implementation() -> impl NoirParser { + keyword(Keyword::Impl) + .ignore_then(function::generics()) + .then(path()) + .then(generic_type_args(parse_type())) + .then_ignore(keyword(Keyword::For)) + .then(parse_type()) + .then(where_clause()) + .then_ignore(just(Token::LeftBrace)) + .then(trait_implementation_body()) + .then_ignore(just(Token::RightBrace)) + .map(|args| { + let ((other_args, where_clause), items) = args; + let (((impl_generics, trait_name), trait_generics), object_type) = other_args; + + TopLevelStatement::TraitImpl(NoirTraitImpl { + impl_generics, + trait_name, + trait_generics, + object_type, + items, + where_clause, + }) + }) +} + +fn trait_implementation_body() -> impl NoirParser> { + let function = function::function_definition(true).validate(|mut f, span, emit| { + if f.def().is_unconstrained || f.def().visibility != ItemVisibility::Private { + emit(ParserError::with_reason(ParserErrorReason::TraitImplFunctionModifiers, span)); + } + // Trait impl functions are always public + f.def_mut().visibility = ItemVisibility::Public; + TraitImplItem::Function(f) + }); + + let alias = keyword(Keyword::Type) + .ignore_then(ident()) + .then_ignore(just(Token::Assign)) + .then(parse_type()) + .then_ignore(just(Token::Semicolon)) + .map(|(name, alias)| TraitImplItem::Type { name, alias }); + + function.or(alias).repeated() +} + +fn where_clause() -> impl NoirParser> { + struct MultiTraitConstraint { + typ: UnresolvedType, + trait_bounds: Vec, + } + + let constraints = parse_type() + .then_ignore(just(Token::Colon)) + .then(trait_bounds()) + .map(|(typ, trait_bounds)| MultiTraitConstraint { typ, trait_bounds }); + + keyword(Keyword::Where) + .ignore_then(constraints.separated_by(just(Token::Comma))) + .or_not() + .map(|option| option.unwrap_or_default()) + .map(|x: Vec| { + let mut result: Vec = Vec::new(); + for constraint in x { + for bound in constraint.trait_bounds { + result.push(UnresolvedTraitConstraint { + typ: constraint.typ.clone(), + trait_bound: bound, + }); + } + } + result + }) +} + +fn trait_bounds() -> impl NoirParser> { + trait_bound().separated_by(just(Token::Plus)).at_least(1).allow_trailing() +} + +fn trait_bound() -> impl NoirParser { + path().then(generic_type_args(parse_type())).map(|(trait_path, trait_generics)| TraitBound { + trait_path, + trait_generics, + trait_id: None, + }) +} + +#[cfg(test)] +mod test { + use super::*; + use crate::parser::parser::test_helpers::*; + + #[test] + fn parse_trait() { + parse_all( + trait_definition(), + vec![ + // Empty traits are legal in Rust and sometimes used as a way to whitelist certain types + // for a particular operation. Also known as `tag` or `marker` traits: + // https://stackoverflow.com/questions/71895489/what-is-the-purpose-of-defining-empty-impl-in-rust + "trait Empty {}", + "trait TraitWithDefaultBody { fn foo(self) {} }", + "trait TraitAcceptingMutableRef { fn foo(&mut self); }", + "trait TraitWithTypeBoundOperation { fn identity() -> Self; }", + "trait TraitWithAssociatedType { type Element; fn item(self, index: Field) -> Self::Element; }", + "trait TraitWithAssociatedConstant { let Size: Field; }", + "trait TraitWithAssociatedConstantWithDefaultValue { let Size: Field = 10; }", + "trait GenericTrait { fn elem(&mut self, index: Field) -> T; }", + "trait GenericTraitWithConstraints where T: SomeTrait { fn elem(self, index: Field) -> T; }", + "trait TraitWithMultipleGenericParams where A: SomeTrait, B: AnotherTrait { let Size: Field; fn zero() -> Self; }", + ], + ); + + parse_all_failing( + trait_definition(), + vec!["trait MissingBody", "trait WrongDelimiter { fn foo() -> u8, fn bar() -> u8 }"], + ); + } +} diff --git a/compiler/noirc_frontend/src/parser/parser/types.rs b/compiler/noirc_frontend/src/parser/parser/types.rs new file mode 100644 index 00000000000..d8a63d161b9 --- /dev/null +++ b/compiler/noirc_frontend/src/parser/parser/types.rs @@ -0,0 +1,183 @@ +use super::{ + expression_with_precedence, keyword, nothing, parenthesized, NoirParser, ParserError, + ParserErrorReason, Precedence, +}; +use crate::ast::{UnresolvedType, UnresolvedTypeData}; + +use crate::parser::labels::ParsingRuleLabel; +use crate::token::{Keyword, Token}; +use crate::{Recoverable, UnresolvedTypeExpression}; + +use chumsky::prelude::*; +use noirc_errors::Span; + +fn maybe_comp_time() -> impl NoirParser<()> { + keyword(Keyword::CompTime).or_not().validate(|opt, span, emit| { + if opt.is_some() { + emit(ParserError::with_reason(ParserErrorReason::ComptimeDeprecated, span)); + } + }) +} + +pub(super) fn parenthesized_type( + recursive_type_parser: impl NoirParser, +) -> impl NoirParser { + recursive_type_parser + .delimited_by(just(Token::LeftParen), just(Token::RightParen)) + .map_with_span(|typ, span| UnresolvedType { + typ: UnresolvedTypeData::Parenthesized(Box::new(typ)), + span: span.into(), + }) +} + +pub(super) fn field_type() -> impl NoirParser { + maybe_comp_time() + .then_ignore(keyword(Keyword::Field)) + .map_with_span(|_, span| UnresolvedTypeData::FieldElement.with_span(span)) +} + +pub(super) fn bool_type() -> impl NoirParser { + maybe_comp_time() + .then_ignore(keyword(Keyword::Bool)) + .map_with_span(|_, span| UnresolvedTypeData::Bool.with_span(span)) +} + +pub(super) fn string_type() -> impl NoirParser { + keyword(Keyword::String) + .ignore_then( + type_expression().delimited_by(just(Token::Less), just(Token::Greater)).or_not(), + ) + .map_with_span(|expr, span| UnresolvedTypeData::String(expr).with_span(span)) +} + +pub(super) fn format_string_type( + type_parser: impl NoirParser, +) -> impl NoirParser { + keyword(Keyword::FormatString) + .ignore_then( + type_expression() + .then_ignore(just(Token::Comma)) + .then(type_parser) + .delimited_by(just(Token::Less), just(Token::Greater)), + ) + .map_with_span(|(size, fields), span| { + UnresolvedTypeData::FormatString(size, Box::new(fields)).with_span(span) + }) +} + +pub(super) fn int_type() -> impl NoirParser { + maybe_comp_time() + .then(filter_map(|span, token: Token| match token { + Token::IntType(int_type) => Ok(int_type), + unexpected => { + Err(ParserError::expected_label(ParsingRuleLabel::IntegerType, unexpected, span)) + } + })) + .validate(|(_, token), span, emit| { + UnresolvedTypeData::from_int_token(token) + .map(|data| data.with_span(span)) + .unwrap_or_else(|err| { + emit(ParserError::with_reason(ParserErrorReason::InvalidBitSize(err.0), span)); + UnresolvedType::error(span) + }) + }) +} + +pub(super) fn array_type( + type_parser: impl NoirParser, +) -> impl NoirParser { + just(Token::LeftBracket) + .ignore_then(type_parser) + .then(just(Token::Semicolon).ignore_then(type_expression())) + .then_ignore(just(Token::RightBracket)) + .map_with_span(|(element_type, size), span| { + UnresolvedTypeData::Array(size, Box::new(element_type)).with_span(span) + }) +} + +pub(super) fn slice_type( + type_parser: impl NoirParser, +) -> impl NoirParser { + just(Token::LeftBracket) + .ignore_then(type_parser) + .then_ignore(just(Token::RightBracket)) + .map_with_span(|element_type, span| { + UnresolvedTypeData::Slice(Box::new(element_type)).with_span(span) + }) +} + +pub(super) fn type_expression() -> impl NoirParser { + recursive(|expr| { + expression_with_precedence( + Precedence::lowest_type_precedence(), + expr, + nothing(), + nothing(), + true, + false, + ) + }) + .labelled(ParsingRuleLabel::TypeExpression) + .try_map(UnresolvedTypeExpression::from_expr) +} + +pub(super) fn tuple_type(type_parser: T) -> impl NoirParser +where + T: NoirParser, +{ + let fields = type_parser.separated_by(just(Token::Comma)).allow_trailing(); + parenthesized(fields).map_with_span(|fields, span| { + if fields.is_empty() { + UnresolvedTypeData::Unit.with_span(span) + } else { + UnresolvedTypeData::Tuple(fields).with_span(span) + } + }) +} + +pub(super) fn function_type(type_parser: T) -> impl NoirParser +where + T: NoirParser, +{ + let args = parenthesized(type_parser.clone().separated_by(just(Token::Comma)).allow_trailing()); + + let env = just(Token::LeftBracket) + .ignore_then(type_parser.clone()) + .then_ignore(just(Token::RightBracket)) + .or_not() + .map_with_span(|t, span| { + t.unwrap_or_else(|| UnresolvedTypeData::Unit.with_span(Span::empty(span.end()))) + }); + + keyword(Keyword::Fn) + .ignore_then(env) + .then(args) + .then_ignore(just(Token::Arrow)) + .then(type_parser) + .map_with_span(|((env, args), ret), span| { + UnresolvedTypeData::Function(args, Box::new(ret), Box::new(env)).with_span(span) + }) +} + +pub(super) fn mutable_reference_type(type_parser: T) -> impl NoirParser +where + T: NoirParser, +{ + just(Token::Ampersand) + .ignore_then(keyword(Keyword::Mut)) + .ignore_then(type_parser) + .map_with_span(|element, span| { + UnresolvedTypeData::MutableReference(Box::new(element)).with_span(span) + }) +} + +#[cfg(test)] +mod test { + use super::*; + use crate::parser::parser::test_helpers::*; + + #[test] + fn parse_type_expression() { + parse_all(type_expression(), vec!["(123)", "123", "(1 + 1)", "(1 + (1))"]); + } +} diff --git a/compiler/noirc_frontend/src/tests.rs b/compiler/noirc_frontend/src/tests.rs index c661cc92eef..c4f0a8d67ba 100644 --- a/compiler/noirc_frontend/src/tests.rs +++ b/compiler/noirc_frontend/src/tests.rs @@ -81,7 +81,7 @@ mod test { &mut context, program.clone().into_sorted(), root_file_id, - Vec::new(), // No macro processors + &[], // No macro processors )); } (program, context, errors) @@ -535,15 +535,13 @@ mod test { assert!(errors.len() == 1, "Expected 1 error, got: {:?}", errors); for (err, _file_id) in errors { match &err { - CompilationError::DefinitionError( - DefCollectorErrorKind::MismatchTraitImplementationNumParameters { - actual_num_parameters, - expected_num_parameters, - trait_name, - method_name, - .. - }, - ) => { + CompilationError::TypeError(TypeCheckError::MismatchTraitImplNumParameters { + actual_num_parameters, + expected_num_parameters, + trait_name, + method_name, + .. + }) => { assert_eq!(actual_num_parameters, &1_usize); assert_eq!(expected_num_parameters, &2_usize); assert_eq!(method_name, "default"); @@ -780,6 +778,8 @@ mod test { HirStatement::Semi(semi_expr) => semi_expr, HirStatement::For(for_loop) => for_loop.block, HirStatement::Error => panic!("Invalid HirStatement!"), + HirStatement::Break => panic!("Unexpected break"), + HirStatement::Continue => panic!("Unexpected continue"), }; let expr = interner.expression(&expr_id); @@ -1033,19 +1033,19 @@ mod test { fn resolve_complex_closures() { let src = r#" fn main(x: Field) -> pub Field { - let closure_without_captures = |x| x + x; + let closure_without_captures = |x: Field| -> Field { x + x }; let a = closure_without_captures(1); - let closure_capturing_a_param = |y| y + x; + let closure_capturing_a_param = |y: Field| -> Field { y + x }; let b = closure_capturing_a_param(2); - let closure_capturing_a_local_var = |y| y + b; + let closure_capturing_a_local_var = |y: Field| -> Field { y + b }; let c = closure_capturing_a_local_var(3); - let closure_with_transitive_captures = |y| { + let closure_with_transitive_captures = |y: Field| -> Field { let d = 5; - let nested_closure = |z| { - let doubly_nested_closure = |w| w + x + b; + let nested_closure = |z: Field| -> Field { + let doubly_nested_closure = |w: Field| -> Field { w + x + b }; a + z + y + d + x + doubly_nested_closure(4) + x + y }; let res = nested_closure(5); @@ -1206,4 +1206,79 @@ fn lambda$f1(mut env$l1: (Field)) -> Field { "#; assert_eq!(get_program_errors(src).len(), 1); } + + #[test] + fn type_aliases_in_entry_point() { + let src = r#" + type Foo = u8; + fn main(_x: Foo) {} + "#; + assert_eq!(get_program_errors(src).len(), 0); + } + + #[test] + fn operators_in_global_used_in_type() { + let src = r#" + global ONE = 1; + global COUNT = ONE + 2; + fn main() { + let _array: [Field; COUNT] = [1, 2, 3]; + } + "#; + assert_eq!(get_program_errors(src).len(), 0); + } + + #[test] + fn break_and_continue_in_constrained_fn() { + let src = r#" + fn main() { + for i in 0 .. 10 { + if i == 2 { + continue; + } + if i == 5 { + break; + } + } + } + "#; + assert_eq!(get_program_errors(src).len(), 2); + } + + #[test] + fn break_and_continue_outside_loop() { + let src = r#" + unconstrained fn main() { + continue; + break; + } + "#; + assert_eq!(get_program_errors(src).len(), 2); + } + + // Regression for #2540 + #[test] + fn for_loop_over_array() { + let src = r#" + fn hello(_array: [u1; N]) { + for _ in 0..N {} + } + + fn main() { + let array: [u1; 2] = [0, 1]; + hello(array); + } + "#; + assert_eq!(get_program_errors(src).len(), 0); + } + + // Regression for #4545 + #[test] + fn type_aliases_in_main() { + let src = r#" + type Outer = [u8; N]; + fn main(_arg: Outer<1>) {} + "#; + assert_eq!(get_program_errors(src).len(), 0); + } } diff --git a/compiler/noirc_printable_type/src/lib.rs b/compiler/noirc_printable_type/src/lib.rs index 24f4f275a14..b9240203a5e 100644 --- a/compiler/noirc_printable_type/src/lib.rs +++ b/compiler/noirc_printable_type/src/lib.rs @@ -15,6 +15,10 @@ pub enum PrintableType { #[serde(rename = "type")] typ: Box, }, + Slice { + #[serde(rename = "type")] + typ: Box, + }, Tuple { types: Vec, }, @@ -33,6 +37,8 @@ pub enum PrintableType { length: u64, }, Function { + arguments: Vec, + return_type: Box, env: Box, }, MutableReference { @@ -48,7 +54,7 @@ pub enum PrintableType { pub enum PrintableValue { Field(FieldElement), String(String), - Vec(Vec), + Vec { array_elements: Vec, is_slice: bool }, Struct(BTreeMap), Other, } @@ -82,7 +88,7 @@ impl TryFrom<&[ForeignCallParam]> for PrintableValueDisplay { let (is_fmt_str, foreign_call_inputs) = foreign_call_inputs.split_last().ok_or(ForeignCallError::MissingForeignCallInputs)?; - if is_fmt_str.unwrap_value().to_field().is_one() { + if is_fmt_str.unwrap_field().is_one() { convert_fmt_string_inputs(foreign_call_inputs) } else { convert_string_inputs(foreign_call_inputs) @@ -100,8 +106,7 @@ fn convert_string_inputs( let printable_type = fetch_printable_type(printable_type_as_values)?; // We must use a flat map here as each value in a struct will be in a separate input value - let mut input_values_as_fields = - input_values.iter().flat_map(|param| vecmap(param.values(), |value| value.to_field())); + let mut input_values_as_fields = input_values.iter().flat_map(|param| param.fields()); let value = decode_value(&mut input_values_as_fields, &printable_type); @@ -114,7 +119,7 @@ fn convert_fmt_string_inputs( let (message, input_and_printable_types) = foreign_call_inputs.split_first().ok_or(ForeignCallError::MissingForeignCallInputs)?; - let message_as_fields = vecmap(message.values(), |value| value.to_field()); + let message_as_fields = message.fields(); let message_as_string = decode_string_value(&message_as_fields); let (num_values, input_and_printable_types) = input_and_printable_types @@ -122,12 +127,11 @@ fn convert_fmt_string_inputs( .ok_or(ForeignCallError::MissingForeignCallInputs)?; let mut output = Vec::new(); - let num_values = num_values.unwrap_value().to_field().to_u128() as usize; + let num_values = num_values.unwrap_field().to_u128() as usize; let types_start_at = input_and_printable_types.len() - num_values; - let mut input_iter = input_and_printable_types[0..types_start_at] - .iter() - .flat_map(|param| vecmap(param.values(), |value| value.to_field())); + let mut input_iter = + input_and_printable_types[0..types_start_at].iter().flat_map(|param| param.fields()); for printable_type in input_and_printable_types.iter().skip(types_start_at) { let printable_type = fetch_printable_type(printable_type)?; let value = decode_value(&mut input_iter, &printable_type); @@ -141,7 +145,7 @@ fn convert_fmt_string_inputs( fn fetch_printable_type( printable_type: &ForeignCallParam, ) -> Result { - let printable_type_as_fields = vecmap(printable_type.values(), |value| value.to_field()); + let printable_type_as_fields = printable_type.fields(); let printable_type_as_string = decode_string_value(&printable_type_as_fields); let printable_type: PrintableType = serde_json::from_str(&printable_type_as_string)?; @@ -176,15 +180,18 @@ fn to_string(value: &PrintableValue, typ: &PrintableType) -> Option { output.push_str("false"); } } - (PrintableValue::Field(_), PrintableType::Function { .. }) => { - output.push_str("<>"); + (PrintableValue::Field(_), PrintableType::Function { arguments, return_type, .. }) => { + output.push_str(&format!("< {:?}>>", arguments, return_type,)); } (_, PrintableType::MutableReference { .. }) => { output.push_str("<>"); } - (PrintableValue::Vec(vector), PrintableType::Array { typ, .. }) => { + (PrintableValue::Vec { array_elements, is_slice }, PrintableType::Array { typ, .. }) => { + if *is_slice { + output.push('&') + } output.push('['); - let mut values = vector.iter().peekable(); + let mut values = array_elements.iter().peekable(); while let Some(value) = values.next() { output.push_str(&format!( "{}", @@ -219,9 +226,9 @@ fn to_string(value: &PrintableValue, typ: &PrintableType) -> Option { output.push_str(" }"); } - (PrintableValue::Vec(values), PrintableType::Tuple { types }) => { + (PrintableValue::Vec { array_elements, .. }, PrintableType::Tuple { types }) => { output.push('('); - let mut elems = values.iter().zip(types).peekable(); + let mut elems = array_elements.iter().zip(types).peekable(); while let Some((value, typ)) = elems.next() { output.push_str( &PrintableValueDisplay::Plain(value.clone(), typ.clone()).to_string(), @@ -320,7 +327,7 @@ pub fn decode_value( array_elements.push(decode_value(field_iterator, typ)); } - PrintableValue::Vec(array_elements) + PrintableValue::Vec { array_elements, is_slice: false } } PrintableType::Array { length: Some(length), typ } => { let length = *length as usize; @@ -329,11 +336,24 @@ pub fn decode_value( array_elements.push(decode_value(field_iterator, typ)); } - PrintableValue::Vec(array_elements) + PrintableValue::Vec { array_elements, is_slice: false } } - PrintableType::Tuple { types } => { - PrintableValue::Vec(vecmap(types, |typ| decode_value(field_iterator, typ))) + PrintableType::Slice { typ } => { + let length = field_iterator + .next() + .expect("not enough data to decode variable array length") + .to_u128() as usize; + let mut array_elements = Vec::with_capacity(length); + for _ in 0..length { + array_elements.push(decode_value(field_iterator, typ)); + } + + PrintableValue::Vec { array_elements, is_slice: true } } + PrintableType::Tuple { types } => PrintableValue::Vec { + array_elements: vecmap(types, |typ| decode_value(field_iterator, typ)), + is_slice: false, + }, PrintableType::String { length } => { let field_elements: Vec = field_iterator.take(*length as usize).collect(); @@ -350,7 +370,7 @@ pub fn decode_value( PrintableValue::Struct(struct_map) } - PrintableType::Function { env } => { + PrintableType::Function { env, .. } => { let field_element = field_iterator.next().unwrap(); let func_ref = PrintableValue::Field(field_element); // we want to consume the fields from the environment, but for now they are not actually printed diff --git a/compiler/wasm/README.md b/compiler/wasm/README.md index 52f7e83e19e..fd534722622 100644 --- a/compiler/wasm/README.md +++ b/compiler/wasm/README.md @@ -26,17 +26,3 @@ for (const path of files) { } const myCompiledCode = await compile(fm); ``` - -## Building from source - -Outside of the [noir repo](https://github.com/noir-lang/noir), this package can be built using the command below: - -```bash -nix build -L github:noir-lang/noir/master#noir_wasm -``` - -If you are within the noir repo and would like to build local changes, you can use: - -```bash -nix build -L #noir_wasm -``` diff --git a/compiler/wasm/package.json b/compiler/wasm/package.json index 67584a2def1..6d11a5ba5c8 100644 --- a/compiler/wasm/package.json +++ b/compiler/wasm/package.json @@ -3,7 +3,7 @@ "contributors": [ "The Noir Team " ], - "version": "0.24.0", + "version": "0.26.0", "license": "(MIT OR Apache-2.0)", "main": "dist/main.js", "types": "./dist/types/src/index.d.cts", @@ -55,27 +55,27 @@ "@types/sinon": "^17", "@wasm-tool/wasm-pack-plugin": "^1.7.0", "@web/dev-server-esbuild": "^0.3.6", - "@web/test-runner": "^0.18.0", + "@web/test-runner": "^0.18.1", "@web/test-runner-playwright": "^0.11.0", "adm-zip": "^0.5.0", "assert": "^2.1.0", "browserify-fs": "^1.0.0", - "chai": "^4.3.10", + "chai": "^4.4.1", "copy-webpack-plugin": "^12.0.2", - "eslint": "^8.56.0", - "eslint-plugin-prettier": "^5.0.0", + "eslint": "^8.57.0", + "eslint-plugin-prettier": "^5.1.3", "html-webpack-plugin": "^5.6.0", "memfs": "^4.6.0", "mocha": "^10.2.0", "mocha-each": "^2.0.1", "path-browserify": "^1.0.1", - "prettier": "3.0.3", + "prettier": "3.2.5", "process": "^0.11.10", "readable-stream": "^4.4.2", "sinon": "^17.0.1", "ts-loader": "^9.5.1", "ts-node": "^10.9.1", - "typescript": "~5.2.2", + "typescript": "^5.4.2", "unzipit": "^1.4.3", "url": "^0.11.3", "webpack": "^5.90.1", diff --git a/compiler/wasm/scripts/build-fixtures.sh b/compiler/wasm/scripts/build-fixtures.sh index 3a2330d4726..4c0505ef519 100755 --- a/compiler/wasm/scripts/build-fixtures.sh +++ b/compiler/wasm/scripts/build-fixtures.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash nargo compile --program-dir ./test/fixtures/simple -nargo compile --program-dir ./test/fixtures/with-deps +nargo compile --program-dir ./test/fixtures/with-deps nargo compile --program-dir ./test/fixtures/noir-contract \ No newline at end of file diff --git a/compiler/wasm/src/noir/dependencies/github-dependency-resolver.ts b/compiler/wasm/src/noir/dependencies/github-dependency-resolver.ts index 8b08b6f0dd8..39ad0d802fb 100644 --- a/compiler/wasm/src/noir/dependencies/github-dependency-resolver.ts +++ b/compiler/wasm/src/noir/dependencies/github-dependency-resolver.ts @@ -12,10 +12,12 @@ import { LogData } from '../../utils'; */ export class GithubDependencyResolver implements DependencyResolver { #fm: FileManager; + #fetch: typeof fetch; #log; - constructor(fm: FileManager) { + constructor(fm: FileManager, fetcher: typeof fetch) { this.#fm = fm; + this.#fetch = fetcher; this.#log = (msg: string, _data?: LogData) => { console.log(msg); }; @@ -56,7 +58,7 @@ export class GithubDependencyResolver implements DependencyResolver { return localArchivePath; } - const response = await fetch(url, { + const response = await this.#fetch(url, { method: 'GET', }); diff --git a/compiler/wasm/src/noir/noir-wasm-compiler.ts b/compiler/wasm/src/noir/noir-wasm-compiler.ts index 1ec3af1fd65..1fe3c79eae7 100644 --- a/compiler/wasm/src/noir/noir-wasm-compiler.ts +++ b/compiler/wasm/src/noir/noir-wasm-compiler.ts @@ -72,7 +72,8 @@ export class NoirWasmCompiler { const dependencyManager = new DependencyManager( [ new LocalDependencyResolver(fileManager), - new GithubCodeArchiveDependencyResolver(fileManager), + // use node's global fetch + new GithubCodeArchiveDependencyResolver(fileManager, fetch), // TODO support actual Git repositories ], noirPackage, diff --git a/compiler/wasm/src/noir/package.ts b/compiler/wasm/src/noir/package.ts index 81178e6ae96..2856798273a 100644 --- a/compiler/wasm/src/noir/package.ts +++ b/compiler/wasm/src/noir/package.ts @@ -105,7 +105,12 @@ export class Package { handles .filter((handle) => SOURCE_EXTENSIONS.find((ext) => handle.endsWith(ext))) .map(async (file) => { - const suffix = file.replace(this.#srcPath, ''); + // Github deps are directly added to the file manager, which causes them to be missing the absolute path to the source file + // and only include the extraction directory relative to the fm root directory + // This regexp ensures we remove the "real" source path for all dependencies, providing the compiler with what it expects for each source file: + // -> for bin/contract packages + // -> for libs + const suffix = file.replace(new RegExp(`.*${this.#srcPath}`), ''); return { path: this.getType() === 'lib' ? `${alias ? alias : this.#config.package.name}${suffix}` : file, source: (await fm.readFile(file, 'utf-8')).toString(), diff --git a/compiler/wasm/src/types/noir_artifact.ts b/compiler/wasm/src/types/noir_artifact.ts index 832a6ed9bf9..935c99043da 100644 --- a/compiler/wasm/src/types/noir_artifact.ts +++ b/compiler/wasm/src/types/noir_artifact.ts @@ -32,19 +32,16 @@ export interface EventAbi { fields: ABIVariable[]; } -/** The Noir function types. */ -export type NoirFunctionType = 'Open' | 'Secret' | 'Unconstrained'; - /** * The compilation result of an Noir function. */ export interface NoirFunctionEntry { /** The name of the function. */ name: string; - /** The type of the function. */ - function_type: NoirFunctionType; - /** Whether the function is internal. */ - is_internal: boolean; + /** Whether the function is unconstrained. */ + is_unconstrained: boolean; + /** The custom attributes applied to the function. */ + custom_attributes: string[]; /** The ABI of the function. */ abi: Abi; /** The bytecode of the function in base64. */ diff --git a/compiler/wasm/test/dependencies/github-dependency-resolver.test.ts b/compiler/wasm/test/dependencies/github-dependency-resolver.test.ts index e7fae8afe8e..505b2269cd2 100644 --- a/compiler/wasm/test/dependencies/github-dependency-resolver.test.ts +++ b/compiler/wasm/test/dependencies/github-dependency-resolver.test.ts @@ -31,7 +31,7 @@ describe('GithubDependencyResolver', () => { let fetchStub: SinonStub | undefined; beforeEach(() => { - fetchStub = Sinon.stub(globalThis, 'fetch'); + fetchStub = Sinon.stub(); fm = createMemFSFileManager(createFsFromVolume(new Volume()), '/'); libDependency = { @@ -50,16 +50,12 @@ describe('GithubDependencyResolver', () => { }, }); - resolver = new GithubDependencyResolver(fm); + resolver = new GithubDependencyResolver(fm, fetchStub); // cut off outside access fetchStub.onCall(0).throws(new Error()); }); - afterEach(() => { - fetchStub?.restore(); - }); - it("returns null if it can't resolve a dependency", async () => { const dep = await resolver.resolveDependency(pkg, { path: '/lib-c', diff --git a/compiler/wasm/test/fixtures/deps/lib-c/src/lib.nr b/compiler/wasm/test/fixtures/deps/lib-c/src/lib.nr index 5c0b5a621e0..144bcec0532 100644 --- a/compiler/wasm/test/fixtures/deps/lib-c/src/lib.nr +++ b/compiler/wasm/test/fixtures/deps/lib-c/src/lib.nr @@ -1 +1 @@ -mod module; \ No newline at end of file +mod module; diff --git a/compiler/wasm/test/fixtures/deps/lib-c/src/module.nr b/compiler/wasm/test/fixtures/deps/lib-c/src/module.nr index 2746c97edf0..f4ad3bff5c9 100644 --- a/compiler/wasm/test/fixtures/deps/lib-c/src/module.nr +++ b/compiler/wasm/test/fixtures/deps/lib-c/src/module.nr @@ -1 +1 @@ -mod foo; \ No newline at end of file +mod foo; diff --git a/compiler/wasm/test/fixtures/deps/lib-c/src/module/foo.nr b/compiler/wasm/test/fixtures/deps/lib-c/src/module/foo.nr index e0c82fb1960..0376cd4cb87 100644 --- a/compiler/wasm/test/fixtures/deps/lib-c/src/module/foo.nr +++ b/compiler/wasm/test/fixtures/deps/lib-c/src/module/foo.nr @@ -1,3 +1,3 @@ pub fn bar(param: Field) -> Field { - dep::std::hash::pedersen_hash([param]) + dep::std::hash::pedersen_hash([param]) } diff --git a/compiler/wasm/test/fixtures/noir-contract/src/main.nr b/compiler/wasm/test/fixtures/noir-contract/src/main.nr index b980af369cf..fc1dc8a5a17 100644 --- a/compiler/wasm/test/fixtures/noir-contract/src/main.nr +++ b/compiler/wasm/test/fixtures/noir-contract/src/main.nr @@ -5,8 +5,7 @@ contract TestContract { [foo::bar(param), param + pub_param] } - open fn openFunction() -> pub Field { + fn someFunction() -> pub Field { 42 } - } diff --git a/cspell.json b/cspell.json index 23659b39c68..16de9757fb8 100644 --- a/cspell.json +++ b/cspell.json @@ -6,6 +6,7 @@ "words": [ "aarch", "acir", + "acirs", "acvm", "aeiou", "appender", @@ -13,6 +14,8 @@ "arithmetization", "arity", "arkworks", + "backpropagate", + "Backpropagation", "barebones", "barretenberg", "bincode", @@ -34,6 +37,7 @@ "castable", "catmcgee", "Celo", + "chrono", "chumsky", "codegen", "codegenned", @@ -50,6 +54,7 @@ "csat", "curvegroup", "databus", + "debouncer", "deflater", "deflatten", "deflattened", @@ -137,6 +142,7 @@ "plonkc", "PLONKish", "pprof", + "preimage", "preprocess", "prettytable", "printstd", @@ -152,6 +158,8 @@ "sdiv", "secp256k1", "secp256r1", + "Secpk", + "Secpr", "signedness", "signorecello", "smol", diff --git a/default.nix b/default.nix deleted file mode 100644 index 9e230590a61..00000000000 --- a/default.nix +++ /dev/null @@ -1,13 +0,0 @@ -let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - flakeCompatRev = lock.nodes.flake-compat.locked.rev; - flakeCompatHash = lock.nodes.flake-compat.locked.narHash; - flakeCompat = fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${flakeCompatRev}.tar.gz"; - sha256 = flakeCompatHash; - }; - compat = import flakeCompat { - src = ./.; - }; -in -compat.defaultNix diff --git a/deny.toml b/deny.toml index 72150f08a3c..eff233687e8 100644 --- a/deny.toml +++ b/deny.toml @@ -2,11 +2,13 @@ # More documentation for the advisories section can be found here: # https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html [advisories] -vulnerability = "deny" -unmaintained = "warn" -unsound = "warn" +version = 2 yanked = "warn" -notice = "warn" + +ignore = [ + "RUSTSEC-2020-0168", # mach unmaintained + "RUSTSEC-2020-0016" # net2 unmaintained +] # This section is considered when running `cargo deny check bans`. # More documentation about the 'bans' section can be found here: @@ -32,9 +34,8 @@ skip = [] skip-tree = [] [licenses] -unlicensed = "deny" +version = 2 confidence-threshold = 0.9 -# copyleft = "deny" # List of explicitly allowed licenses # See https://spdx.org/licenses/ for list of possible licenses @@ -68,6 +69,7 @@ exceptions = [ # https://tldrlegal.com/license/creative-commons-cc0-1.0-universal { allow = ["CC0-1.0"], name = "more-asserts" }, { allow = ["CC0-1.0"], name = "jsonrpc" }, + { allow = ["CC0-1.0"], name = "notify" }, { allow = ["MPL-2.0"], name = "sized-chunks" }, { allow = ["MPL-2.0"], name = "webpki-roots" }, diff --git a/docs/.markdownlint.json b/docs/.markdownlint.json new file mode 100644 index 00000000000..40896b4542f --- /dev/null +++ b/docs/.markdownlint.json @@ -0,0 +1,3 @@ +{ + "no-missing-space-atx": false +} diff --git a/docs/docs/getting_started/installation/other_install_methods.md b/docs/docs/getting_started/installation/other_install_methods.md index a35e34aaf9c..3634723562b 100644 --- a/docs/docs/getting_started/installation/other_install_methods.md +++ b/docs/docs/getting_started/installation/other_install_methods.md @@ -1,6 +1,6 @@ --- -title: Alternative Install Methods -description: There are different ways to install Nargo, the one-stop shop and command-line tool for developing Noir programs. This guide explains other methods that don't rely on noirup, such as compiling from source, installing from binaries, and using WSL for windows +title: Alternative Installations +description: There are different ways to install Nargo, the one-stop shop and command-line tool for developing Noir programs. This guide explains how to specify which version to install when using noirup, and using WSL for windows. keywords: [ Installation Nargo @@ -12,10 +12,7 @@ keywords: [ Linux Nix Direnv - Shell & editor experience - Building and testing Uninstalling Nargo - Noir vs code extension, ] sidebar_position: 1 --- @@ -86,146 +83,7 @@ With `noirup`, you can easily switch between different Nargo versions, including noirup --path ./path/to/local/source ``` -## Alternate Installation Methods (No Longer Recommended) - -While the following methods are available, they are no longer recommended. We advise using noirup for a more efficient and flexible installation experience. - -However, there are other methods for installing Nargo: - -- [Binaries](#option-1-installing-from-binaries) -- [Compiling from Source](#option-2-compile-from-source) -- [WSL for Windows](#option-3-wsl-for-windows) - -### Option 1: Installing from Binaries - -See [GitHub Releases](https://github.com/noir-lang/noir/releases) for the latest and previous -platform specific binaries. - -#### Step 1 - -Paste and run the following in the terminal to extract and install the binary: - -> **macOS / Linux:** If you are prompted with `Permission denied` when running commands, prepend -> `sudo` and re-run it. - -##### macOS (Apple Silicon) - -```bash -mkdir -p $HOME/.nargo/bin && \ -curl -o $HOME/.nargo/bin/nargo-aarch64-apple-darwin.tar.gz -L https://github.com/noir-lang/noir/releases/download/v0.24.0/nargo-aarch64-apple-darwin.tar.gz && \ -tar -xvf $HOME/.nargo/bin/nargo-aarch64-apple-darwin.tar.gz -C $HOME/.nargo/bin/ && \ -echo '\nexport PATH=$PATH:$HOME/.nargo/bin' >> ~/.zshrc && \ -source ~/.zshrc -``` - -##### macOS (Intel) - -```bash -mkdir -p $HOME/.nargo/bin && \ -curl -o $HOME/.nargo/bin/nargo-x86_64-apple-darwin.tar.gz -L https://github.com/noir-lang/noir/releases/download/v0.24.0/nargo-x86_64-apple-darwin.tar.gz && \ -tar -xvf $HOME/.nargo/bin/nargo-x86_64-apple-darwin.tar.gz -C $HOME/.nargo/bin/ && \ -echo '\nexport PATH=$PATH:$HOME/.nargo/bin' >> ~/.zshrc && \ -source ~/.zshrc -``` - -##### Linux (Bash) - -```bash -mkdir -p $HOME/.nargo/bin && \ -curl -o $HOME/.nargo/bin/nargo-x86_64-unknown-linux-gnu.tar.gz -L https://github.com/noir-lang/noir/releases/download/v0.24.0/nargo-x86_64-unknown-linux-gnu.tar.gz && \ -tar -xvf $HOME/.nargo/bin/nargo-x86_64-unknown-linux-gnu.tar.gz -C $HOME/.nargo/bin/ && \ -echo -e '\nexport PATH=$PATH:$HOME/.nargo/bin' >> ~/.bashrc && \ -source ~/.bashrc -``` - -#### Step 2 - -Check if the installation was successful by running `nargo --version`. You should get a version number. - -> **macOS:** If you are prompted with an OS alert, right-click and open the _nargo_ executable from -> Finder. Close the new terminal popped up and `nargo` should now be accessible. - -### Option 2: Compile from Source - -Due to the large number of native dependencies, Noir projects uses [Nix](https://nixos.org/) and [direnv](https://direnv.net/) to streamline the development experience. It helps mitigating issues commonly associated with dependency management, such as conflicts between required package versions for different projects (often referred to as "dependency hell"). - -Combined with direnv, which automatically sets or clears environment variables based on the directory, it further simplifies the development process by seamlessly integrating with the developer's shell, facilitating an efficient and reliable workflow for managing and deploying Noir projects with multiple dependencies. - -#### Setting up your environment - -For the best experience, please follow these instructions to setup your environment: - -1. Install Nix following [their guide](https://nixos.org/download.html) for your operating system. -2. Create the file `~/.config/nix/nix.conf` with the contents: - -```ini -experimental-features = nix-command -extra-experimental-features = flakes -``` - -3. Install direnv into your Nix profile by running: - -```sh -nix profile install nixpkgs#direnv -``` - -4. Add direnv to your shell following [their guide](https://direnv.net/docs/hook.html). - 1. For bash or zshell, add `eval "$(direnv hook bash)"` or `eval "$(direnv hook zsh)"` to your ~/.bashrc or ~/.zshrc file, respectively. -5. Restart your shell. - -#### Shell & editor experience - -Now that your environment is set up, you can get to work on the project. - -1. Clone the repository, such as: - -```sh -git clone git@github.com:noir-lang/noir -``` - -> Replacing `noir` with whichever repository you want to work on. - -2. Navigate to the directory: - -```sh -cd noir -``` - -> Replacing `noir` with whichever repository you cloned. - -3. You should see a **direnv error** because projects aren't allowed by default. Make sure you've reviewed and trust our `.envrc` file, then you need to run: - -```sh -direnv allow -``` - -4. Now, wait awhile for all the native dependencies to be built. This will take some time and direnv will warn you that it is taking a long time, but we just need to let it run. - -5. Once you are presented with your prompt again, you can start your editor within the project directory (we recommend [VSCode](https://code.visualstudio.com/)): - -```sh -code . -``` - -6. (Recommended) When launching VSCode for the first time, you should be prompted to install our recommended plugins. We highly recommend installing these for the best development experience. - -#### Building and testing - -Assuming you are using `direnv` to populate your environment, building and testing the project can be done -with the typical `cargo build`, `cargo test`, and `cargo clippy` commands. You'll notice that the `cargo` version matches the version we specify in `rust-toolchain.toml`, which is 1.73.0 at the time of this writing. - -If you want to build the entire project in an isolated sandbox, you can use Nix commands: - -1. `nix build .` (or `nix build . -L` for verbose output) to build the project in a Nix sandbox. -2. `nix flake check` (or `nix flake check -L` for verbose output) to run clippy and tests in a Nix sandbox. - -#### Without `direnv` - -If you have hesitations with using direnv, you can launch a subshell with `nix develop` and then launch your editor from within the subshell. However, if VSCode was already launched in the project directory, the environment won't be updated. - -Advanced: If you aren't using direnv nor launching your editor within the subshell, you can try to install Barretenberg and other global dependencies the package needs. This is an advanced workflow and likely won't receive support! - -### Option 3: WSL (for Windows) +## Installation on Windows The default backend for Noir (Barretenberg) doesn't provide Windows binaries at this time. For that reason, Noir cannot be installed natively. However, it is available by using Windows Subsystem for Linux (WSL). @@ -235,20 +93,10 @@ step 2: Follow the [Noirup instructions](#encouraged-installation-method-noirup) ## Uninstalling Nargo -### Noirup - -If you installed Nargo with `noirup` or through directly downloading binaries, you can uninstall Nargo by removing the files in `~/.nargo`, `~/nargo`, and `~/noir_cache`. This ensures that all installed binaries, configurations, and cache related to Nargo are fully removed from your system. +If you installed Nargo with `noirup`, you can uninstall Nargo by removing the files in `~/.nargo`, `~/nargo`, and `~/noir_cache`. This ensures that all installed binaries, configurations, and cache related to Nargo are fully removed from your system. ```bash rm -r ~/.nargo rm -r ~/nargo rm -r ~/noir_cache ``` - -### Nix - -If you installed Nargo with Nix or compiled it from source, you can remove the binary located at `~/.nix-profile/bin/nargo`. - -```bash -rm ~/.nix-profile/bin/nargo -``` diff --git a/docs/docs/getting_started/tooling/noir_codegen.md b/docs/docs/getting_started/tooling/noir_codegen.md new file mode 100644 index 00000000000..d65151da0ab --- /dev/null +++ b/docs/docs/getting_started/tooling/noir_codegen.md @@ -0,0 +1,113 @@ +--- +title: Noir Codegen for TypeScript +description: Learn how to use Noir codegen to generate TypeScript bindings +keywords: [Nargo, Noir, compile, TypeScript] +sidebar_position: 2 +--- + +When using TypeScript, it is extra work to interpret Noir program outputs in a type-safe way. Third party libraries may exist for popular Noir programs, but they are either hard to find or unmaintained. + +Now you can generate TypeScript bindings for your Noir programs in two steps: +1. Exporting Noir functions using `nargo export` +2. Using the TypeScript module `noir_codegen` to generate TypeScript binding + +**Note:** you can only export functions from a Noir *library* (not binary or contract program types). + +## Installation + +### Your TypeScript project + +If you don't already have a TypeScript project you can add the module with `yarn` (or `npm`), then initialize it: + +```bash +yarn add typescript -D +npx tsc --init +``` + +### Add TypeScript module - `noir_codegen` + +The following command will add the module to your project's devDependencies: + +```bash +yarn add @noir-lang/noir_codegen -D +``` + +### Nargo library +Make sure you have Nargo, v0.25.0 or greater, installed. If you don't, follow the [installation guide](../installation/index.md). + +If you're in a new project, make a `circuits` folder and create a new Noir library: + +```bash +mkdir circuits && cd circuits +nargo new --lib myNoirLib +``` + +## Usage + +### Export ABI of specified functions + +First go to the `.nr` files in your Noir library, and add the `#[export]` macro to each function that you want to use in TypeScript. + +```rust +#[export] +fn your_function(... +``` + +From your Noir library (where `Nargo.toml` is), run the following command: + +```bash +nargo export +``` + +You will now have an `export` directory with a .json file per exported function. + +You can also specify the directory of Noir programs using `--program-dir`, for example: + +```bash +nargo export --program-dir=./circuits/myNoirLib +``` + +### Generate TypeScript bindings from exported functions + +To use the `noir-codegen` package we added to the TypeScript project: + +```bash +yarn noir-codegen ./export/your_function.json +``` + +This creates an `exports` directory with an `index.ts` file containing all exported functions. + +**Note:** adding `--out-dir` allows you to specify an output dir for your TypeScript bindings to go. Eg: + +```bash +yarn noir-codegen ./export/*.json --out-dir ./path/to/output/dir +``` + +## Example .nr function to .ts output + +Consider a Noir library with this function: + +```rust +#[export] +fn not_equal(x: Field, y: Field) -> bool { + x != y +} +``` + +After the export and codegen steps, you should have an `index.ts` like: + +```typescript +export type Field = string; + + +export const is_equal_circuit: CompiledCircuit = {"abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"private"},{"name":"y","type":{"kind":"field"},"visibility":"private"}],"param_witnesses":{"x":[{"start":0,"end":1}],"y":[{"start":1,"end":2}]},"return_type":{"abi_type":{"kind":"boolean"},"visibility":"private"},"return_witnesses":[4]},"bytecode":"H4sIAAAAAAAA/7WUMQ7DIAxFQ0Krrr2JjSGYLVcpKrn/CaqqDQN12WK+hPBgmWd/wEyHbF1SS923uhOs3pfoChI+wKXMAXzIKyNj4PB0TFTYc0w5RUjoqeAeEu1wqK0F54RGkWvW44LPzExnlkbMEs4JNZmN8PxS42uHv82T8a3Jeyn2Ks+VLPcO558HmyLMCDOXAXXtpPt4R/Rt9T36ss6dS9HGPx/eG17nGegKBQAA"}; + +export async function is_equal(x: Field, y: Field, foreignCallHandler?: ForeignCallHandler): Promise { + const program = new Noir(is_equal_circuit); + const args: InputMap = { x, y }; + const { returnValue } = await program.execute(args, foreignCallHandler); + return returnValue as boolean; +} +``` + +Now the `is_equal()` function and relevant types are readily available for use in TypeScript. diff --git a/docs/docs/how_to/how-to-oracles.md b/docs/docs/how_to/how-to-oracles.md index 0d84d992320..8cf8035a5c4 100644 --- a/docs/docs/how_to/how-to-oracles.md +++ b/docs/docs/how_to/how-to-oracles.md @@ -138,8 +138,8 @@ Now, we will add our `getSqrt` method, as expected by the `#[oracle(getSqrt)]` d ```js server.addMethod("getSqrt", async (params) => { - const values = params[0].Array.map(({ inner }) => { - return { inner: `${Math.sqrt(parseInt(inner, 16))}` }; + const values = params[0].Array.map((field) => { + return `${Math.sqrt(parseInt(field, 16))}`; }); return { values: [{ Array: values }] }; }); @@ -147,27 +147,23 @@ server.addMethod("getSqrt", async (params) => { :::tip -Brillig expects an object with an array of values. Each value is an object declaring to be `Single` or `Array` and returning a `inner` property *as a string*. For example: +Brillig expects an object with an array of values. Each value is an object declaring to be `Single` or `Array` and returning a field element *as a string*. For example: ```json -{ "values": [{ "Array": [{ "inner": "1" }, { "inner": "2"}]}]} -{ "values": [{ "Single": { "inner": "1" }}]} -{ "values": [{ "Single": { "inner": "1" }}, { "Array": [{ "inner": "1", { "inner": "2" }}]}]} +{ "values": [{ "Array": ["1", "2"] }]} +{ "values": [{ "Single": "1" }]} +{ "values": [{ "Single": "1" }, { "Array": ["1", "2"] }]} ``` If you're using Typescript, the following types may be helpful in understanding the expected return value and making sure they're easy to follow: ```js -interface Value { - inner: string, -} - interface SingleForeignCallParam { - Single: Value, + Single: string, } interface ArrayForeignCallParam { - Array: Value[], + Array: string[], } type ForeignCallParam = SingleForeignCallParam | ArrayForeignCallParam; @@ -198,7 +194,7 @@ For example, if your Noir program expects the host machine to provide CPU pseudo ```js const foreignCallHandler = (name, inputs) => crypto.randomBytes(16) // etc -await noir.generateFinalProof(inputs, foreignCallHandler) +await noir.generateProof(inputs, foreignCallHandler) ``` As one can see, in NoirJS, the [`foreignCallHandler`](../reference/NoirJS/noir_js/type-aliases/ForeignCallHandler.md) function simply means "a callback function that returns a value of type [`ForeignCallOutput`](../reference/NoirJS/noir_js/type-aliases/ForeignCallOutput.md). It doesn't have to be an RPC call like in the case for Nargo. @@ -243,9 +239,9 @@ const foreignCallHandler = async (name, input) => { // notice that the "inputs" parameter contains *all* the inputs // in this case we to make the RPC request with the first parameter "numbers", which would be input[0] const oracleReturn = await client.request(name, [ - { Array: input[0].map((i) => ({ inner: i.toString("hex") })) }, + { Array: input[0].map((i) => i.toString("hex")) }, ]); - return [oracleReturn.values[0].Array.map((x) => x.inner)]; + return [oracleReturn.values[0].Array]; }; // the rest of your NoirJS code diff --git a/docs/docs/how_to/merkle-proof.mdx b/docs/docs/how_to/merkle-proof.mdx index 34074659ac1..003c7019a93 100644 --- a/docs/docs/how_to/merkle-proof.mdx +++ b/docs/docs/how_to/merkle-proof.mdx @@ -14,7 +14,7 @@ in a merkle tree. use dep::std; fn main(message : [Field; 62], index : Field, hashpath : [Field; 40], root : Field) { - let leaf = std::hash::hash_to_field(message); + let leaf = std::hash::hash_to_field(message.as_slice()); let merkle_root = std::merkle::compute_merkle_root(leaf, index, hashpath); assert(merkle_root == root); } @@ -27,7 +27,7 @@ random oracle. If only collision resistance is needed, then one can call `std::h instead. ```rust -let leaf = std::hash::hash_to_field(message); +let leaf = std::hash::hash_to_field(message.as_slice()); ``` The leaf is then passed to a compute_merkle_root function with the root, index and hashpath. The returned root can then be asserted to be the same as the provided root. diff --git a/docs/docs/noir/concepts/control_flow.md b/docs/docs/noir/concepts/control_flow.md index 4ce65236db3..045d3c3a5f5 100644 --- a/docs/docs/noir/concepts/control_flow.md +++ b/docs/docs/noir/concepts/control_flow.md @@ -7,21 +7,6 @@ keywords: [Noir programming language, loops, for loop, if-else statements, Rust sidebar_position: 2 --- -## Loops - -Noir has one kind of loop: the `for` loop. `for` loops allow you to repeat a block of code multiple -times. - -The following block of code between the braces is run 10 times. - -```rust -for i in 0..10 { - // do something -}; -``` - -The index for loops is of type `u64`. - ## If Expressions Noir supports `if-else` statements. The syntax is most similar to Rust's where it is not required @@ -43,3 +28,50 @@ if a == 0 { } assert(x == 2); ``` + +## Loops + +Noir has one kind of loop: the `for` loop. `for` loops allow you to repeat a block of code multiple +times. + +The following block of code between the braces is run 10 times. + +```rust +for i in 0..10 { + // do something +} +``` + +The index for loops is of type `u64`. + +### Break and Continue + +In unconstrained code, `break` and `continue` are also allowed in `for` loops. These are only allowed +in unconstrained code since normal constrained code requires that Noir knows exactly how many iterations +a loop may have. `break` and `continue` can be used like so: + +```rust +for i in 0 .. 10 { + println("Iteration start") + + if i == 2 { + continue; + } + + if i == 5 { + break; + } + + println(i); +} +println("Loop end") +``` + +When used, `break` will end the current loop early and jump to the statement after the for loop. In the example +above, the `break` will stop the loop and jump to the `println("Loop end")`. + +`continue` will stop the current iteration of the loop, and jump to the start of the next iteration. In the example +above, `continue` will jump to `println("Iteration start")` when used. Note that the loop continues as normal after this. +The iteration variable `i` is still increased by one as normal when `continue` is used. + +`break` and `continue` cannot currently be used to jump out of more than a single loop at a time. diff --git a/docs/docs/noir/concepts/data_types/arrays.md b/docs/docs/noir/concepts/data_types/arrays.md index a8bd338e736..efce3e95d32 100644 --- a/docs/docs/noir/concepts/data_types/arrays.md +++ b/docs/docs/noir/concepts/data_types/arrays.md @@ -72,7 +72,7 @@ let element = array[0][0]; ``` However, multidimensional slices are not supported. For example, the following code will error at compile time: ```rust -let slice : [[Field]] = []; +let slice : [[Field]] = &[]; ``` ## Types diff --git a/docs/docs/noir/concepts/data_types/fields.md b/docs/docs/noir/concepts/data_types/fields.md index 99b4aa63549..a10a4810788 100644 --- a/docs/docs/noir/concepts/data_types/fields.md +++ b/docs/docs/noir/concepts/data_types/fields.md @@ -42,7 +42,7 @@ After declaring a Field, you can use these common methods on it: Transforms the field into an array of bits, Little Endian. ```rust -fn to_le_bits(_x : Field, _bit_size: u32) -> [u1; N] +fn to_le_bits(_x : Field, _bit_size: u32) -> [u1] ``` example: @@ -59,7 +59,7 @@ fn main() { Transforms the field into an array of bits, Big Endian. ```rust -fn to_be_bits(_x : Field, _bit_size: u32) -> [u1; N] +fn to_be_bits(_x : Field, _bit_size: u32) -> [u1] ``` example: diff --git a/docs/docs/noir/concepts/data_types/index.md b/docs/docs/noir/concepts/data_types/index.md index 97b3b2cb094..357813c147a 100644 --- a/docs/docs/noir/concepts/data_types/index.md +++ b/docs/docs/noir/concepts/data_types/index.md @@ -79,7 +79,7 @@ fn main() { } ``` -Type aliases can also be used with [generics](@site/docs/noir/concepts/generics.md): +Type aliases can also be used with [generics](../generics.md): ```rust type Id = Size; diff --git a/docs/docs/noir/concepts/data_types/integers.md b/docs/docs/noir/concepts/data_types/integers.md index 4d58d96fed5..1c6b375db49 100644 --- a/docs/docs/noir/concepts/data_types/integers.md +++ b/docs/docs/noir/concepts/data_types/integers.md @@ -51,7 +51,7 @@ The built-in structure `U128` allows you to use 128-bit unsigned integers almost - You cannot cast between a native integer and `U128` - There is a higher performance cost when using `U128`, compared to a native type. -Conversion between unsigned integer types and U128 are done through the use of `from_integer` and `to_integer` functions. +Conversion between unsigned integer types and U128 are done through the use of `from_integer` and `to_integer` functions. `from_integer` also accepts the `Field` type as input. ```rust fn main() { diff --git a/docs/docs/noir/concepts/data_types/slices.mdx b/docs/docs/noir/concepts/data_types/slices.mdx index 4a6ee816aa2..828faf4a8f8 100644 --- a/docs/docs/noir/concepts/data_types/slices.mdx +++ b/docs/docs/noir/concepts/data_types/slices.mdx @@ -15,13 +15,19 @@ A slice is a dynamically-sized view into a sequence of elements. They can be res use dep::std::slice; fn main() -> pub Field { - let mut slice: [Field] = [0; 2]; + let mut slice: [Field] = &[0; 2]; let mut new_slice = slice.push_back(6); new_slice.len() } ``` +To write a slice literal, use a preceeding ampersand as in: `&[0; 2]` or +`&[1, 2, 3]`. + +It is important to note that slices are not references to arrays. In Noir, +`&[..]` is more similar to an immutable, growable vector. + View the corresponding test file [here][test-file]. [test-file]: https://github.com/noir-lang/noir/blob/f387ec1475129732f72ba294877efdf6857135ac/crates/nargo_cli/tests/test_data_ssa_refactor/slices/src/main.nr @@ -42,7 +48,7 @@ example: ```rust fn main() -> pub Field { - let mut slice: [Field] = [0; 2]; + let mut slice: [Field] = &[0; 2]; let mut new_slice = slice.push_back(6); new_slice.len() @@ -62,7 +68,7 @@ fn push_front(_self: Self, _elem: T) -> Self Example: ```rust -let mut new_slice: [Field] = []; +let mut new_slice: [Field] = &[]; new_slice = new_slice.push_front(20); assert(new_slice[0] == 20); // returns true ``` @@ -112,7 +118,7 @@ fn append(mut self, other: Self) -> Self Example: ```rust -let append = [1, 2].append([3, 4, 5]); +let append = &[1, 2].append(&[3, 4, 5]); ``` ### insert @@ -145,3 +151,20 @@ Example: ```rust let (remove_slice, removed_elem) = slice.remove(3); ``` + +### len + +Returns the length of a slice + +```rust +fn len(self) -> Field +``` + +Example: + +```rust +fn main() { + let slice = &[42, 42]; + assert(slice.len() == 2); +} +``` diff --git a/docs/docs/noir/concepts/functions.md b/docs/docs/noir/concepts/functions.md index 48aba9cd058..2c9bc33fdfc 100644 --- a/docs/docs/noir/concepts/functions.md +++ b/docs/docs/noir/concepts/functions.md @@ -71,7 +71,7 @@ fn main(x : [Field]) { #[test] fn test_one() { - main([1, 2]); + main(&[1, 2]); } ``` diff --git a/docs/docs/noir/concepts/unconstrained.md b/docs/docs/noir/concepts/unconstrained.md index 89d12c1c971..b8e71fe65f0 100644 --- a/docs/docs/noir/concepts/unconstrained.md +++ b/docs/docs/noir/concepts/unconstrained.md @@ -93,3 +93,7 @@ Backend circuit size: 2902 This ends up taking off another ~250 gates from our circuit! We've ended up with more ACIR opcodes than before but they're easier for the backend to prove (resulting in fewer gates). Generally we want to use brillig whenever there's something that's easy to verify but hard to compute within the circuit. For example, if you wanted to calculate a square root of a number it'll be a much better idea to calculate this in brillig and then assert that if you square the result you get back your number. + +## Break and Continue + +In addition to loops over runtime bounds, `break` and `continue` are also available in unconstrained code. See [break and continue](../concepts/control_flow/#break-and-continue) diff --git a/docs/docs/noir/standard_library/bigint.md b/docs/docs/noir/standard_library/bigint.md new file mode 100644 index 00000000000..9aa4fb77112 --- /dev/null +++ b/docs/docs/noir/standard_library/bigint.md @@ -0,0 +1,102 @@ +--- +title: Big Integers +description: How to use big integers from Noir standard library +keywords: + [ + Big Integer, + Noir programming language, + Noir libraries, + ] +--- + +The BigInt module in the standard library exposes some class of integers which do not fit (well) into a Noir native field. It implements modulo arithmetic, modulo a 'big' prime number. + +:::note + +The module can currently be considered as `Field`s with fixed modulo sizes used by a set of elliptic curves, in addition to just the native curve. [More work](https://github.com/noir-lang/noir/issues/510) is needed to achieve arbitrarily sized big integers. + +::: + +Currently 6 classes of integers (i.e 'big' prime numbers) are available in the module, namely: + +- BN254 Fq: Bn254Fq +- BN254 Fr: Bn254Fr +- Secp256k1 Fq: Secpk1Fq +- Secp256k1 Fr: Secpk1Fr +- Secp256r1 Fr: Secpr1Fr +- Secp256r1 Fq: Secpr1Fq + +Where XXX Fq and XXX Fr denote respectively the order of the base and scalar field of the (usual) elliptic curve XXX. +For instance the big integer 'Secpk1Fq' in the standard library refers to integers modulo $2^{256}-2^{32}-977$. + +Feel free to explore the source code for the other primes: + +#include_code big_int_definition noir_stdlib/src/bigint.nr rust + +## Example usage + +A common use-case is when constructing a big integer from its bytes representation, and performing arithmetic operations on it: + +#include_code big_int_example test_programs/execution_success/bigint/src/main.nr rust + +## Methods + +The available operations for each big integer are: + +### from_le_bytes + +Construct a big integer from its little-endian bytes representation. Example: + +```rust + let a = Secpk1Fq::from_le_bytes(&[x, y, 0, 45, 2]); + ``` + +Sure, here's the formatted version of the remaining methods: + +### to_le_bytes + +Return the little-endian bytes representation of a big integer. Example: + +```rust +let bytes = a.to_le_bytes(); +``` + +### add + +Add two big integers. Example: + +```rust +let sum = a + b; +``` + +### sub + +Subtract two big integers. Example: + +```rust +let difference = a - b; +``` + +### mul + +Multiply two big integers. Example: + +```rust +let product = a * b; +``` + +### div + +Divide two big integers. Note that division is field division and not euclidean division. Example: + +```rust +let quotient = a / b; +``` + +### eq + +Compare two big integers. Example: + +```rust +let are_equal = a == b; +``` diff --git a/docs/docs/noir/standard_library/black_box_fns.md b/docs/docs/noir/standard_library/black_box_fns.md index eae8744abf0..be8c65679c3 100644 --- a/docs/docs/noir/standard_library/black_box_fns.md +++ b/docs/docs/noir/standard_library/black_box_fns.md @@ -12,18 +12,18 @@ The ACVM spec defines a set of blackbox functions which backends will be expecte Here is a list of the current black box functions: -- [SHA256](./cryptographic_primitives/hashes#sha256) -- [Schnorr signature verification](./cryptographic_primitives/schnorr) -- [Blake2s](./cryptographic_primitives/hashes#blake2s) -- [Blake3](./cryptographic_primitives/hashes#blake3) -- [Pedersen Hash](./cryptographic_primitives/hashes#pedersen_hash) -- [Pedersen Commitment](./cryptographic_primitives/hashes#pedersen_commitment) -- [ECDSA signature verification](./cryptographic_primitives/ecdsa_sig_verification) -- [Fixed base scalar multiplication](./cryptographic_primitives/scalar) +- [SHA256](./cryptographic_primitives/hashes.mdx#sha256) +- [Schnorr signature verification](./cryptographic_primitives/schnorr.mdx) +- [Blake2s](./cryptographic_primitives/hashes.mdx#blake2s) +- [Blake3](./cryptographic_primitives/hashes.mdx#blake3) +- [Pedersen Hash](./cryptographic_primitives/hashes.mdx#pedersen_hash) +- [Pedersen Commitment](./cryptographic_primitives/hashes.mdx#pedersen_commitment) +- [ECDSA signature verification](./cryptographic_primitives/ecdsa_sig_verification.mdx) +- [Fixed base scalar multiplication](./cryptographic_primitives/scalar.mdx) - AND - XOR - RANGE -- [Keccak256](./cryptographic_primitives/hashes#keccak256) +- [Keccak256](./cryptographic_primitives/hashes.mdx#keccak256) - [Recursive proof verification](./recursion) Most black box functions are included as part of the Noir standard library, however `AND`, `XOR` and `RANGE` are used as part of the Noir language syntax. For instance, using the bitwise operator `&` will invoke the `AND` black box function. diff --git a/docs/docs/noir/standard_library/containers/boundedvec.md b/docs/docs/noir/standard_library/containers/boundedvec.md new file mode 100644 index 00000000000..cd0f725f870 --- /dev/null +++ b/docs/docs/noir/standard_library/containers/boundedvec.md @@ -0,0 +1,210 @@ +--- +title: Bounded Vectors +keywords: [noir, vector, bounded vector, slice] +sidebar_position: 1 +--- + +A `BoundedVec` is a growable storage similar to a `Vec` except that it +is bounded with a maximum possible length. Unlike `Vec`, `BoundedVec` is not implemented +via slices and thus is not subject to the same restrictions slices are (notably, nested +slices - and thus nested vectors as well - are disallowed). + +Since a BoundedVec is backed by a normal array under the hood, growing the BoundedVec by +pushing an additional element is also more efficient - the length only needs to be increased +by one. + +For these reasons `BoundedVec` should generally be preferred over `Vec` when there +is a reasonable maximum bound that can be placed on the vector. + +Example: + +```rust +let mut vector: BoundedVec = BoundedVec::new(); +for i in 0..5 { + vector.push(i); +} +assert(vector.len() == 5); +assert(vector.max_len() == 10); +``` + +## Methods + +### new + +```rust +pub fn new() -> Self +``` + +Creates a new, empty vector of length zero. + +Since this container is backed by an array internally, it still needs an initial value +to give each element. To resolve this, each element is zeroed internally. This value +is guaranteed to be inaccessible unless `get_unchecked` is used. + +Example: + +```rust +let empty_vector: BoundedVec = BoundedVec::new(); +assert(empty_vector.len() == 0); +``` + +Note that whenever calling `new` the maximum length of the vector should always be specified +via a type signature: + +#include_code new_example test_programs/noir_test_success/bounded_vec/src/main.nr rust + +This defaulting of `MaxLen` (and numeric generics in general) to zero may change in future noir versions +but for now make sure to use type annotations when using bounded vectors. Otherwise, you will receive a constraint failure at runtime when the vec is pushed to. + +### get + +```rust +pub fn get(mut self: Self, index: u64) -> T { +``` + +Retrieves an element from the vector at the given index, starting from zero. + +If the given index is equal to or greater than the length of the vector, this +will issue a constraint failure. + +Example: + +```rust +fn foo(v: BoundedVec) { + let first = v.get(0); + let last = v.get(v.len() - 1); + assert(first != last); +} +``` + +### get_unchecked + +```rust +pub fn get_unchecked(mut self: Self, index: u64) -> T { +``` + +Retrieves an element from the vector at the given index, starting from zero, without +performing a bounds check. + +Since this function does not perform a bounds check on length before accessing the element, +it is unsafe! Use at your own risk! + +Example: + +#include_code get_unchecked_example test_programs/noir_test_success/bounded_vec/src/main.nr rust + + +### push + +```rust +pub fn push(&mut self, elem: T) { +``` + +Pushes an element to the end of the vector. This increases the length +of the vector by one. + +Panics if the new length of the vector will be greater than the max length. + +Example: + +#include_code bounded-vec-push-example test_programs/noir_test_success/bounded_vec/src/main.nr rust + +### pop + +```rust +pub fn pop(&mut self) -> T +``` + +Pops the element at the end of the vector. This will decrease the length +of the vector by one. + +Panics if the vector is empty. + +Example: + +#include_code bounded-vec-pop-example test_programs/noir_test_success/bounded_vec/src/main.nr rust + +### len + +```rust +pub fn len(self) -> u64 { +``` + +Returns the current length of this vector + +Example: + +#include_code bounded-vec-len-example test_programs/noir_test_success/bounded_vec/src/main.nr rust + +### max_len + +```rust +pub fn max_len(_self: BoundedVec) -> u64 { +``` + +Returns the maximum length of this vector. This is always +equal to the `MaxLen` parameter this vector was initialized with. + +Example: + +#include_code bounded-vec-max-len-example test_programs/noir_test_success/bounded_vec/src/main.nr rust + +### storage + +```rust +pub fn storage(self) -> [T; MaxLen] { +``` + +Returns the internal array within this vector. +Since arrays in Noir are immutable, mutating the returned storage array will not mutate +the storage held internally by this vector. + +Note that uninitialized elements may be zeroed out! + +Example: + +#include_code bounded-vec-storage-example test_programs/noir_test_success/bounded_vec/src/main.nr rust + +### extend_from_array + +```rust +pub fn extend_from_array(&mut self, array: [T; Len]) +``` + +Pushes each element from the given array to this vector. + +Panics if pushing each element would cause the length of this vector +to exceed the maximum length. + +Example: + +#include_code bounded-vec-extend-from-array-example test_programs/noir_test_success/bounded_vec/src/main.nr rust + +### extend_from_bounded_vec + +```rust +pub fn extend_from_bounded_vec(&mut self, vec: BoundedVec) +``` + +Pushes each element from the other vector to this vector. The length of +the other vector is left unchanged. + +Panics if pushing each element would cause the length of this vector +to exceed the maximum length. + +Example: + +#include_code bounded-vec-extend-from-bounded-vec-example test_programs/noir_test_success/bounded_vec/src/main.nr rust + +### any + +```rust +pub fn any(self, predicate: fn[Env](T) -> bool) -> bool +``` + +Returns true if the given predicate returns true for any element +in this vector. + +Example: + +#include_code bounded-vec-any-example test_programs/noir_test_success/bounded_vec/src/main.nr rust diff --git a/docs/docs/noir/standard_library/containers/hashmap.md b/docs/docs/noir/standard_library/containers/hashmap.md new file mode 100644 index 00000000000..093b6d38d11 --- /dev/null +++ b/docs/docs/noir/standard_library/containers/hashmap.md @@ -0,0 +1,270 @@ +--- +title: HashMap +keywords: [noir, map, hash, hashmap] +sidebar_position: 1 +--- + +`HashMap` is used to efficiently store and look up key-value pairs. + +`HashMap` is a bounded type which can store anywhere from zero to `MaxLen` total elements. +Note that due to hash collisions, the actual maximum number of elements stored by any particular +hashmap is likely lower than `MaxLen`. This is true even with cryptographic hash functions since +every hash value will be performed modulo `MaxLen`. + +When creating `HashMap`s, the `MaxLen` generic should always be specified if it is not already +known. Otherwise, the compiler may infer a different value for `MaxLen` (such as zero), which +will likely change the result of the program. This behavior is set to become an error in future +versions instead. + +Example: + +```rust +// Create a mapping from Fields to u32s with a maximum length of 12 +// using a pedersen hash +let mut map: HashMap> = HashMap::default(); + +map.insert(1, 2); +map.insert(3, 4); + +let two = map.get(1).unwrap(); +``` + +## Methods + +### default + +#include_code default noir_stdlib/src/collections/map.nr rust + +Creates a fresh, empty HashMap. + +When using this function, always make sure to specify the maximum size of the hash map. + +This is the same `default` from the `Default` implementation given further below. It is +repeated here for convenience since it is the recommended way to create a hashmap. + +Example: + +#include_code default_example test_programs/execution_success/hashmap/src/main.nr rust + +Because `HashMap` has so many generic arguments that are likely to be the same throughout +your program, it may be helpful to create a type alias: + +#include_code type_alias test_programs/execution_success/hashmap/src/main.nr rust + +### with_hasher + +#include_code with_hasher noir_stdlib/src/collections/map.nr rust + +Creates a hashmap with an existing `BuildHasher`. This can be used to ensure multiple +hashmaps are created with the same hasher instance. + +Example: + +#include_code with_hasher_example test_programs/execution_success/hashmap/src/main.nr rust + +### get + +#include_code get noir_stdlib/src/collections/map.nr rust + +Retrieves a value from the hashmap, returning `Option::none()` if it was not found. + +Example: + +#include_code get_example test_programs/execution_success/hashmap/src/main.nr rust + +### insert + +#include_code insert noir_stdlib/src/collections/map.nr rust + +Inserts a new key-value pair into the map. If the key was already in the map, its +previous value will be overridden with the newly provided one. + +Example: + +#include_code insert_example test_programs/execution_success/hashmap/src/main.nr rust + +### remove + +#include_code remove noir_stdlib/src/collections/map.nr rust + +Removes the given key-value pair from the map. If the key was not already present +in the map, this does nothing. + +Example: + +#include_code remove_example test_programs/execution_success/hashmap/src/main.nr rust + +### is_empty + +#include_code is_empty noir_stdlib/src/collections/map.nr rust + +True if the length of the hash map is empty. + +Example: + +#include_code is_empty_example test_programs/execution_success/hashmap/src/main.nr rust + +### len + +#include_code len noir_stdlib/src/collections/map.nr rust + +Returns the current length of this hash map. + +Example: + +#include_code len_example test_programs/execution_success/hashmap/src/main.nr rust + +### capacity + +#include_code capacity noir_stdlib/src/collections/map.nr rust + +Returns the maximum capacity of this hashmap. This is always equal to the capacity +specified in the hashmap's type. + +Unlike hashmaps in general purpose programming languages, hashmaps in Noir have a +static capacity that does not increase as the map grows larger. Thus, this capacity +is also the maximum possible element count that can be inserted into the hashmap. +Due to hash collisions (modulo the hashmap length), it is likely the actual maximum +element count will be lower than the full capacity. + +Example: + +#include_code capacity_example test_programs/execution_success/hashmap/src/main.nr rust + +### clear + +#include_code clear noir_stdlib/src/collections/map.nr rust + +Clears the hashmap, removing all key-value pairs from it. + +Example: + +#include_code clear_example test_programs/execution_success/hashmap/src/main.nr rust + +### contains_key + +#include_code contains_key noir_stdlib/src/collections/map.nr rust + +True if the hashmap contains the given key. Unlike `get`, this will not also return +the value associated with the key. + +Example: + +#include_code contains_key_example test_programs/execution_success/hashmap/src/main.nr rust + +### entries + +#include_code entries noir_stdlib/src/collections/map.nr rust + +Returns a vector of each key-value pair present in the hashmap. + +The length of the returned vector is always equal to the length of the hashmap. + +Example: + +#include_code entries_example test_programs/execution_success/hashmap/src/main.nr rust + +### keys + +#include_code keys noir_stdlib/src/collections/map.nr rust + +Returns a vector of each key present in the hashmap. + +The length of the returned vector is always equal to the length of the hashmap. + +Example: + +#include_code keys_example test_programs/execution_success/hashmap/src/main.nr rust + +### values + +#include_code values noir_stdlib/src/collections/map.nr rust + +Returns a vector of each value present in the hashmap. + +The length of the returned vector is always equal to the length of the hashmap. + +Example: + +#include_code values_example test_programs/execution_success/hashmap/src/main.nr rust + +### iter_mut + +#include_code iter_mut noir_stdlib/src/collections/map.nr rust + +Iterates through each key-value pair of the HashMap, setting each key-value pair to the +result returned from the given function. + +Note that since keys can be mutated, the HashMap needs to be rebuilt as it is iterated +through. If this is not desired, use `iter_values_mut` if only values need to be mutated, +or `entries` if neither keys nor values need to be mutated. + +The iteration order is left unspecified. As a result, if two keys are mutated to become +equal, which of the two values that will be present for the key in the resulting map is also unspecified. + +Example: + +#include_code iter_mut_example test_programs/execution_success/hashmap/src/main.nr rust + +### iter_keys_mut + +#include_code iter_keys_mut noir_stdlib/src/collections/map.nr rust + +Iterates through the HashMap, mutating each key to the result returned from +the given function. + +Note that since keys can be mutated, the HashMap needs to be rebuilt as it is iterated +through. If only iteration is desired and the keys are not intended to be mutated, +prefer using `entries` instead. + +The iteration order is left unspecified. As a result, if two keys are mutated to become +equal, which of the two values that will be present for the key in the resulting map is also unspecified. + +Example: + +#include_code iter_keys_mut_example test_programs/execution_success/hashmap/src/main.nr rust + +### iter_values_mut + +#include_code iter_values_mut noir_stdlib/src/collections/map.nr rust + +Iterates through the HashMap, applying the given function to each value and mutating the +value to equal the result. This function is more efficient than `iter_mut` and `iter_keys_mut` +because the keys are untouched and the underlying hashmap thus does not need to be reordered. + +Example: + +#include_code iter_values_mut_example test_programs/execution_success/hashmap/src/main.nr rust + +### retain + +#include_code retain noir_stdlib/src/collections/map.nr rust + +Retains only the key-value pairs for which the given function returns true. +Any key-value pairs for which the function returns false will be removed from the map. + +Example: + +#include_code retain_example test_programs/execution_success/hashmap/src/main.nr rust + +## Trait Implementations + +### default + +#include_code default noir_stdlib/src/collections/map.nr rust + +Constructs an empty HashMap. + +Example: + +#include_code default_example test_programs/execution_success/hashmap/src/main.nr rust + +### eq + +#include_code eq noir_stdlib/src/collections/map.nr rust + +Checks if two HashMaps are equal. + +Example: + +#include_code eq_example test_programs/execution_success/hashmap/src/main.nr rust diff --git a/docs/docs/noir/standard_library/containers/index.md b/docs/docs/noir/standard_library/containers/index.md new file mode 100644 index 00000000000..ea84c6d5c21 --- /dev/null +++ b/docs/docs/noir/standard_library/containers/index.md @@ -0,0 +1,5 @@ +--- +title: Containers +description: Container types provided by Noir's standard library for storing and retrieving data +keywords: [containers, data types, vec, hashmap] +--- diff --git a/docs/docs/noir/standard_library/containers/vec.mdx b/docs/docs/noir/standard_library/containers/vec.mdx index 1954f05bc76..fcfd7e07aa0 100644 --- a/docs/docs/noir/standard_library/containers/vec.mdx +++ b/docs/docs/noir/standard_library/containers/vec.mdx @@ -49,8 +49,8 @@ pub fn from_slice(slice: [T]) -> Self Example: ```rust -let arr: [Field] = [1, 2, 3]; -let vector_from_slice = Vec::from_slice(arr); +let slice: [Field] = &[1, 2, 3]; +let vector_from_slice = Vec::from_slice(slice); assert(vector_from_slice.len() == 3); ``` @@ -80,7 +80,7 @@ pub fn get(self, index: Field) -> T Example: ```rust -let vector: Vec = Vec::from_slice([10, 20, 30]); +let vector: Vec = Vec::from_slice(&[10, 20, 30]); assert(vector.get(1) == 20); ``` @@ -111,7 +111,7 @@ pub fn pop(&mut self) -> T Example: ```rust -let mut vector = Vec::from_slice([10, 20]); +let mut vector = Vec::from_slice(&[10, 20]); let popped_elem = vector.pop(); assert(popped_elem == 20); assert(vector.len() == 1); @@ -128,7 +128,7 @@ pub fn insert(&mut self, index: Field, elem: T) Example: ```rust -let mut vector = Vec::from_slice([10, 30]); +let mut vector = Vec::from_slice(&[10, 30]); vector.insert(1, 20); assert(vector.get(1) == 20); ``` @@ -144,7 +144,7 @@ pub fn remove(&mut self, index: Field) -> T Example: ```rust -let mut vector = Vec::from_slice([10, 20, 30]); +let mut vector = Vec::from_slice(&[10, 20, 30]); let removed_elem = vector.remove(1); assert(removed_elem == 20); assert(vector.len() == 2); diff --git a/docs/docs/noir/standard_library/cryptographic_primitives/ecdsa_sig_verification.mdx b/docs/docs/noir/standard_library/cryptographic_primitives/ecdsa_sig_verification.mdx index d67a1ac94df..6787c9f46a1 100644 --- a/docs/docs/noir/standard_library/cryptographic_primitives/ecdsa_sig_verification.mdx +++ b/docs/docs/noir/standard_library/cryptographic_primitives/ecdsa_sig_verification.mdx @@ -11,7 +11,8 @@ Noir supports ECDSA signatures verification over the secp256k1 and secp256r1 cur ## ecdsa_secp256k1::verify_signature -Verifier for ECDSA Secp256k1 signatures +Verifier for ECDSA Secp256k1 signatures. +See ecdsa_secp256k1::verify_signature_slice for a version that accepts slices directly. #include_code ecdsa_secp256k1 noir_stdlib/src/ecdsa_secp256k1.nr rust @@ -24,9 +25,20 @@ fn main(hashed_message : [u8;32], pub_key_x : [u8;32], pub_key_y : [u8;32], sign } ``` + + +## ecdsa_secp256k1::verify_signature_slice + +Verifier for ECDSA Secp256k1 signatures where the message is a slice. + +#include_code ecdsa_secp256k1_slice noir_stdlib/src/ecdsa_secp256k1.nr rust + + + ## ecdsa_secp256r1::verify_signature -Verifier for ECDSA Secp256r1 signatures +Verifier for ECDSA Secp256r1 signatures. +See ecdsa_secp256r1::verify_signature_slice for a version that accepts slices directly. #include_code ecdsa_secp256r1 noir_stdlib/src/ecdsa_secp256r1.nr rust @@ -40,3 +52,11 @@ fn main(hashed_message : [u8;32], pub_key_x : [u8;32], pub_key_y : [u8;32], sign ``` + +## ecdsa_secp256r1::verify_signature + +Verifier for ECDSA Secp256r1 signatures where the message is a slice. + +#include_code ecdsa_secp256r1_slice noir_stdlib/src/ecdsa_secp256r1.nr rust + + diff --git a/docs/docs/noir/standard_library/cryptographic_primitives/eddsa.mdx b/docs/docs/noir/standard_library/cryptographic_primitives/eddsa.mdx index a9c10da6c06..c2c0624dfad 100644 --- a/docs/docs/noir/standard_library/cryptographic_primitives/eddsa.mdx +++ b/docs/docs/noir/standard_library/cryptographic_primitives/eddsa.mdx @@ -15,4 +15,23 @@ Verifier for EdDSA signatures fn eddsa_poseidon_verify(public_key_x : Field, public_key_y : Field, signature_s: Field, signature_r8_x: Field, signature_r8_y: Field, message: Field) -> bool ``` +It is also possible to specify the hash algorithm used for the signature by using the `eddsa_verify_with_hasher` function with a parameter implementing the Hasher trait. For instance, if you want to use Poseidon2 instead, you can do the following: +```rust +use dep::std::hash::poseidon2::Poseidon2Hasher; + +let mut hasher = Poseidon2Hasher::default(); +eddsa_verify_with_hasher(pub_key_a.x, pub_key_a.y, s_a, r8_a.x, r8_a.y, msg, &mut hasher); +``` + + +## eddsa::eddsa_to_pub + +Private to public key conversion. + +Returns `(pub_key_x, pub_key_y)` + +```rust +fn eddsa_to_pub(secret : Field) -> (Field, Field) +``` + diff --git a/docs/docs/noir/standard_library/cryptographic_primitives/hashes.mdx b/docs/docs/noir/standard_library/cryptographic_primitives/hashes.mdx index b9239f822e8..f98c90a97c8 100644 --- a/docs/docs/noir/standard_library/cryptographic_primitives/hashes.mdx +++ b/docs/docs/noir/standard_library/cryptographic_primitives/hashes.mdx @@ -13,6 +13,7 @@ import BlackBoxInfo from '@site/src/components/Notes/_blackbox.mdx'; ## sha256 Given an array of bytes, returns the resulting sha256 hash. +See sha256_slice for a version that works directly on slices. #include_code sha256 noir_stdlib/src/hash.nr rust @@ -27,9 +28,18 @@ fn main() { +## sha256_slice + +A version of sha256 specialized to slices: + +#include_code sha256_slice noir_stdlib/src/hash.nr rust + + + ## blake2s Given an array of bytes, returns an array with the Blake2 hash +See blake2s_slice for a version that works directly on slices. #include_code blake2s noir_stdlib/src/hash.nr rust @@ -44,9 +54,18 @@ fn main() { +## blake2s_slice + +A version of blake2s specialized to slices: + +#include_code blake2s_slice noir_stdlib/src/hash.nr rust + + + ## blake3 Given an array of bytes, returns an array with the Blake3 hash +See blake3_slice for a version that works directly on slices. #include_code blake3 noir_stdlib/src/hash.nr rust @@ -61,9 +80,18 @@ fn main() { +## blake3_slice + +A version of blake3 specialized to slices: + +#include_code blake3_slice noir_stdlib/src/hash.nr rust + + + ## pedersen_hash Given an array of Fields, returns the Pedersen hash. +See pedersen_hash_slice for a version that works directly on slices. #include_code pedersen_hash noir_stdlib/src/hash.nr rust @@ -73,10 +101,18 @@ example: +## pedersen_hash_slice + +Given a slice of Fields, returns the Pedersen hash. + +#include_code pedersen_hash_slice noir_stdlib/src/hash.nr rust + + ## pedersen_commitment Given an array of Fields, returns the Pedersen commitment. +See pedersen_commitment_slice for a version that works directly on slices. #include_code pedersen_commitment noir_stdlib/src/hash.nr rust @@ -86,11 +122,20 @@ example: +## pedersen_commitment_slice + +Given a slice of Fields, returns the Pedersen commitment. + +#include_code pedersen_commitment_slice noir_stdlib/src/hash.nr rust + + + ## keccak256 -Given an array of bytes (`u8`), returns the resulting keccak hash as an array of 32 bytes -(`[u8; 32]`). Specify a message_size to hash only the first `message_size` bytes -of the input. +Given an array of bytes (`u8`), returns the resulting keccak hash as an array of +32 bytes (`[u8; 32]`). Specify a message_size to hash only the first +`message_size` bytes of the input. See keccak256_slice for a version that works +directly on slices. #include_code keccak256 noir_stdlib/src/hash.nr rust @@ -100,6 +145,15 @@ example: +## keccak256_slice + +Given a slice of bytes (`u8`), returns the resulting keccak hash as an array of +32 bytes (`[u8; 32]`). + +#include_code keccak256_slice noir_stdlib/src/hash.nr rust + + + ## poseidon Given an array of Fields, returns a new Field with the Poseidon Hash. Mind that you need to specify @@ -156,7 +210,7 @@ fn main() { ## hash_to_field ```rust -fn hash_to_field(_input : [Field; N]) -> Field {} +fn hash_to_field(_input : [Field]) -> Field {} ``` Calculates the `blake2s` hash of the inputs and returns the hash modulo the field modulus to return diff --git a/docs/docs/noir/standard_library/cryptographic_primitives/schnorr.mdx b/docs/docs/noir/standard_library/cryptographic_primitives/schnorr.mdx index 0e0c358c6e1..2c9eb18cd34 100644 --- a/docs/docs/noir/standard_library/cryptographic_primitives/schnorr.mdx +++ b/docs/docs/noir/standard_library/cryptographic_primitives/schnorr.mdx @@ -10,6 +10,7 @@ import BlackBoxInfo from '@site/src/components/Notes/_blackbox.mdx'; ## schnorr::verify_signature Verifier for Schnorr signatures over the embedded curve (for BN254 it is Grumpkin). +See schnorr::verify_signature_slice for a version that works directly on slices. #include_code schnorr_verify noir_stdlib/src/schnorr.nr rust @@ -34,3 +35,12 @@ const signature = Array.from( ``` + +## schnorr::verify_signature_slice + +Verifier for Schnorr signatures over the embedded curve (for BN254 it is Grumpkin) +where the message is a slice. + +#include_code schnorr_verify_slice noir_stdlib/src/schnorr.nr rust + + diff --git a/docs/docs/noir/standard_library/merkle_trees.md b/docs/docs/noir/standard_library/merkle_trees.md index fa488677884..6a9ebf72ada 100644 --- a/docs/docs/noir/standard_library/merkle_trees.md +++ b/docs/docs/noir/standard_library/merkle_trees.md @@ -42,9 +42,9 @@ fn main(index: Field, priv_key: Field, secret: Field, note_hash_path: [Field; 3] let pubkey = std::scalar_mul::fixed_base_embedded_curve(priv_key); let pubkey_x = pubkey[0]; let pubkey_y = pubkey[1]; - let note_commitment = std::hash::pedersen([pubkey_x, pubkey_y, secret]); + let note_commitment = std::hash::pedersen(&[pubkey_x, pubkey_y, secret]); - let root = std::merkle::compute_merkle_root(note_commitment[0], index, note_hash_path); + let root = std::merkle::compute_merkle_root(note_commitment[0], index, note_hash_path.as_slice()); println(root); } ``` diff --git a/docs/docs/noir/standard_library/recursion.md b/docs/docs/noir/standard_library/recursion.md index 9337499dac8..a93894043dc 100644 --- a/docs/docs/noir/standard_library/recursion.md +++ b/docs/docs/noir/standard_library/recursion.md @@ -29,8 +29,8 @@ By incorporating this attribute directly in the circuit's definition, tooling li ## Verifying Recursive Proofs ```rust -#[foreign(verify_proof)] -fn verify_proof(_verification_key : [Field], _proof : [Field], _public_input : Field, _key_hash : Field) {} +#[foreign(recursive_aggregation)] +pub fn verify_proof(verification_key: [Field], proof: [Field], public_inputs: [Field], key_hash: Field) {} ``` :::info diff --git a/docs/docs/noir/standard_library/traits.md b/docs/docs/noir/standard_library/traits.md index fb6d5ae1c48..e6e7e6d40cb 100644 --- a/docs/docs/noir/standard_library/traits.md +++ b/docs/docs/noir/standard_library/traits.md @@ -32,6 +32,8 @@ impl Default for bool { .. } impl Default for [T; N] where T: Default { .. } +impl Default for [T] { .. } + impl Default for (A, B) where A: Default, B: Default { .. } @@ -46,7 +48,8 @@ impl Default for (A, B, C, D, E) ``` For primitive integer types, the return value of `default` is `0`. Container -types such as arrays are filled with default values of their element type. +types such as arrays are filled with default values of their element type, +except slices whose length is unknown and thus defaulted to zero. ## `std::convert` @@ -112,6 +115,9 @@ impl Eq for bool { .. } impl Eq for [T; N] where T: Eq { .. } +impl Eq for [T] + where T: Eq { .. } + impl Eq for (A, B) where A: Eq, B: Eq { .. } @@ -154,6 +160,9 @@ impl Ord for bool { .. } impl Ord for [T; N] where T: Ord { .. } +impl Ord for [T] + where T: Ord { .. } + impl Ord for (A, B) where A: Ord, B: Ord { .. } diff --git a/docs/docs/noir/standard_library/zeroed.md b/docs/docs/noir/standard_library/zeroed.md index 97dab02dac2..f450fecdd36 100644 --- a/docs/docs/noir/standard_library/zeroed.md +++ b/docs/docs/noir/standard_library/zeroed.md @@ -18,6 +18,7 @@ This function currently supports the following types: - Bool - Uint - Array +- Slice - String - Tuple - Function diff --git a/docs/docs/tutorials/noirjs_app.md b/docs/docs/tutorials/noirjs_app.md index ad76dd255cc..12beb476994 100644 --- a/docs/docs/tutorials/noirjs_app.md +++ b/docs/docs/tutorials/noirjs_app.md @@ -243,7 +243,7 @@ Now we're ready to prove stuff! Let's feed some inputs to our circuit and calcul await setup(); // let's squeeze our wasm inits here display('logs', 'Generating proof... ⌛'); -const proof = await noir.generateFinalProof(input); +const proof = await noir.generateProof(input); display('logs', 'Generating proof... ✅'); display('results', proof.proof); ``` @@ -264,7 +264,7 @@ Time to celebrate, yes! But we shouldn't trust machines so blindly. Let's add th ```js display('logs', 'Verifying proof... ⌛'); -const verification = await noir.verifyFinalProof(proof); +const verification = await noir.verifyProof(proof); if (verification) display('logs', 'Verifying proof... ✅'); ``` diff --git a/docs/package.json b/docs/package.json index 146c2a9800c..f9e95fc02f8 100644 --- a/docs/package.json +++ b/docs/package.json @@ -3,12 +3,13 @@ "version": "0.0.0", "private": true, "scripts": { - "preprocess": "./scripts/codegen_nargo_reference.sh && yarn node ./scripts/preprocess/index.js", + "preprocess": "yarn workspace @noir-lang/acvm_js build && ./scripts/codegen_nargo_reference.sh && yarn node ./scripts/preprocess/index.js", "start": "yarn preprocess && docusaurus start", - "build": "yarn preprocess && yarn version::stables && docusaurus build", + "build": "yarn preprocess && docusaurus build", + "clean": "rm -rf ./processed-docs ./processed-docs ./build", "version::stables": "ts-node ./scripts/setStable.ts", "serve": "serve build", - "version": "yarn preprocess && docusaurus docs:version" + "version": "yarn version::stables && ./scripts/cut_version.sh" }, "dependencies": { "@docusaurus/core": "^3.0.1", @@ -34,15 +35,15 @@ "@docusaurus/types": "^3.0.1", "@types/prettier": "^3", "docusaurus-plugin-typedoc": "1.0.0-next.18", - "eslint-plugin-prettier": "^5.0.0", - "prettier": "3.0.3", + "eslint-plugin-prettier": "^5.1.3", + "prettier": "3.2.5", "serve": "^14.2.1", "ts-node": "^10.9.1", "typedoc": "^0.25.0", "typedoc-plugin-frontmatter": "^0.0.2", "typedoc-plugin-markdown": "4.0.0-next.25", "typedoc-plugin-merge-modules": "^5.1.0", - "typescript": "~5.2.2" + "typescript": "^5.4.2" }, "browserslist": { "production": [ diff --git a/docs/scripts/codegen_nargo_reference.sh b/docs/scripts/codegen_nargo_reference.sh index 4ff7d43d142..6a9fda9420b 100755 --- a/docs/scripts/codegen_nargo_reference.sh +++ b/docs/scripts/codegen_nargo_reference.sh @@ -30,4 +30,4 @@ sidebar_position: 0 --- " > $NARGO_REFERENCE -cargo run -F codegen-docs -- info >> $NARGO_REFERENCE +cargo run --bin nargo -F codegen-docs -- info >> $NARGO_REFERENCE diff --git a/docs/scripts/cut_version.sh b/docs/scripts/cut_version.sh new file mode 100755 index 00000000000..4000707328c --- /dev/null +++ b/docs/scripts/cut_version.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -eu + +cd $(dirname "$0")/.. + +VERSION=$1 + +# We assume that the new release tag has been made on github, so setStable.ts will add this to `versions.json`. +# We don't have a version of the docs for this release however (that's what we're doing right now!) so we need to remove it. +jq 'map(select(. != "'"$VERSION"'"))' versions.json > tmp.json && mv tmp.json versions.json + +# We need to build the docs in order to perform all necessary preprocessing. +yarn build + +# Finally cut the actual new docs version. +yarn docusaurus docs:version $VERSION diff --git a/docs/versioned_docs/version-v0.17.0/modules_packages_crates/crates_and_packages.md b/docs/versioned_docs/version-v0.17.0/modules_packages_crates/crates_and_packages.md index 744de72bb2c..23f60855c30 100644 --- a/docs/versioned_docs/version-v0.17.0/modules_packages_crates/crates_and_packages.md +++ b/docs/versioned_docs/version-v0.17.0/modules_packages_crates/crates_and_packages.md @@ -23,7 +23,7 @@ _Library crates_ don't have a `main` function and they don't compile down to ACI #### Contracts -Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/noir-contracts/contracts). +Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts). ### Crate Root diff --git a/docs/versioned_docs/version-v0.19.0/language_concepts/06_generics.md b/docs/versioned_docs/version-v0.19.0/language_concepts/06_generics.md index b700bd5bc5b..a932d7b47c2 100644 --- a/docs/versioned_docs/version-v0.19.0/language_concepts/06_generics.md +++ b/docs/versioned_docs/version-v0.19.0/language_concepts/06_generics.md @@ -107,7 +107,3 @@ fn main() { let array = [MyStruct::new(), MyStruct::new()]; assert(array_eq(array, array, MyStruct::eq)); } -``` - -You can see an example of generics in the tests -[here](https://github.com/noir-lang/noir/blob/master/crates/nargo_cli/tests/test_data/generics/src/main.nr). diff --git a/docs/versioned_docs/version-v0.19.0/modules_packages_crates/crates_and_packages.md b/docs/versioned_docs/version-v0.19.0/modules_packages_crates/crates_and_packages.md index 744de72bb2c..23f60855c30 100644 --- a/docs/versioned_docs/version-v0.19.0/modules_packages_crates/crates_and_packages.md +++ b/docs/versioned_docs/version-v0.19.0/modules_packages_crates/crates_and_packages.md @@ -23,7 +23,7 @@ _Library crates_ don't have a `main` function and they don't compile down to ACI #### Contracts -Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/noir-contracts/contracts). +Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts). ### Crate Root diff --git a/docs/versioned_docs/version-v0.19.1/modules_packages_crates/crates_and_packages.md b/docs/versioned_docs/version-v0.19.1/modules_packages_crates/crates_and_packages.md index 744de72bb2c..23f60855c30 100644 --- a/docs/versioned_docs/version-v0.19.1/modules_packages_crates/crates_and_packages.md +++ b/docs/versioned_docs/version-v0.19.1/modules_packages_crates/crates_and_packages.md @@ -23,7 +23,7 @@ _Library crates_ don't have a `main` function and they don't compile down to ACI #### Contracts -Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/noir-contracts/contracts). +Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts). ### Crate Root diff --git a/docs/versioned_docs/version-v0.19.2/modules_packages_crates/crates_and_packages.md b/docs/versioned_docs/version-v0.19.2/modules_packages_crates/crates_and_packages.md index 744de72bb2c..23f60855c30 100644 --- a/docs/versioned_docs/version-v0.19.2/modules_packages_crates/crates_and_packages.md +++ b/docs/versioned_docs/version-v0.19.2/modules_packages_crates/crates_and_packages.md @@ -23,7 +23,7 @@ _Library crates_ don't have a `main` function and they don't compile down to ACI #### Contracts -Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/noir-contracts/contracts). +Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts). ### Crate Root diff --git a/docs/versioned_docs/version-v0.19.3/modules_packages_crates/crates_and_packages.md b/docs/versioned_docs/version-v0.19.3/modules_packages_crates/crates_and_packages.md index 744de72bb2c..23f60855c30 100644 --- a/docs/versioned_docs/version-v0.19.3/modules_packages_crates/crates_and_packages.md +++ b/docs/versioned_docs/version-v0.19.3/modules_packages_crates/crates_and_packages.md @@ -23,7 +23,7 @@ _Library crates_ don't have a `main` function and they don't compile down to ACI #### Contracts -Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/noir-contracts/contracts). +Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts). ### Crate Root diff --git a/docs/versioned_docs/version-v0.19.4/modules_packages_crates/crates_and_packages.md b/docs/versioned_docs/version-v0.19.4/modules_packages_crates/crates_and_packages.md index 744de72bb2c..23f60855c30 100644 --- a/docs/versioned_docs/version-v0.19.4/modules_packages_crates/crates_and_packages.md +++ b/docs/versioned_docs/version-v0.19.4/modules_packages_crates/crates_and_packages.md @@ -23,7 +23,7 @@ _Library crates_ don't have a `main` function and they don't compile down to ACI #### Contracts -Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/noir-contracts/contracts). +Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts). ### Crate Root diff --git a/docs/versioned_docs/version-v0.22.0/noir/modules_packages_crates/crates_and_packages.md b/docs/versioned_docs/version-v0.22.0/noir/modules_packages_crates/crates_and_packages.md index 760a463094c..95ee9f52ab2 100644 --- a/docs/versioned_docs/version-v0.22.0/noir/modules_packages_crates/crates_and_packages.md +++ b/docs/versioned_docs/version-v0.22.0/noir/modules_packages_crates/crates_and_packages.md @@ -24,7 +24,7 @@ _Library crates_ don't have a `main` function and they don't compile down to ACI #### Contracts -Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/noir-contracts/contracts). +Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts). ### Crate Root diff --git a/docs/versioned_docs/version-v0.23.0/noir/concepts/data_types/index.md b/docs/versioned_docs/version-v0.23.0/noir/concepts/data_types/index.md index 3c9cd4c2437..f09bca0ee04 100644 --- a/docs/versioned_docs/version-v0.23.0/noir/concepts/data_types/index.md +++ b/docs/versioned_docs/version-v0.23.0/noir/concepts/data_types/index.md @@ -79,7 +79,7 @@ fn main() { } ``` -Type aliases can also be used with [generics](@site/docs/noir/concepts/generics.md): +Type aliases can also be used with [generics](../generics.md): ```rust type Id = Size; diff --git a/docs/versioned_docs/version-v0.23.0/noir/modules_packages_crates/crates_and_packages.md b/docs/versioned_docs/version-v0.23.0/noir/modules_packages_crates/crates_and_packages.md index 760a463094c..95ee9f52ab2 100644 --- a/docs/versioned_docs/version-v0.23.0/noir/modules_packages_crates/crates_and_packages.md +++ b/docs/versioned_docs/version-v0.23.0/noir/modules_packages_crates/crates_and_packages.md @@ -24,7 +24,7 @@ _Library crates_ don't have a `main` function and they don't compile down to ACI #### Contracts -Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/noir-contracts/contracts). +Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts). ### Crate Root diff --git a/docs/versioned_docs/version-v0.24.0/how_to/how-to-oracles.md b/docs/versioned_docs/version-v0.24.0/how_to/how-to-oracles.md index 0d84d992320..ab225b9421f 100644 --- a/docs/versioned_docs/version-v0.24.0/how_to/how-to-oracles.md +++ b/docs/versioned_docs/version-v0.24.0/how_to/how-to-oracles.md @@ -198,7 +198,7 @@ For example, if your Noir program expects the host machine to provide CPU pseudo ```js const foreignCallHandler = (name, inputs) => crypto.randomBytes(16) // etc -await noir.generateFinalProof(inputs, foreignCallHandler) +await noir.generateProof(inputs, foreignCallHandler) ``` As one can see, in NoirJS, the [`foreignCallHandler`](../reference/NoirJS/noir_js/type-aliases/ForeignCallHandler.md) function simply means "a callback function that returns a value of type [`ForeignCallOutput`](../reference/NoirJS/noir_js/type-aliases/ForeignCallOutput.md). It doesn't have to be an RPC call like in the case for Nargo. diff --git a/docs/versioned_docs/version-v0.24.0/noir/concepts/data_types/index.md b/docs/versioned_docs/version-v0.24.0/noir/concepts/data_types/index.md index 3c9cd4c2437..f09bca0ee04 100644 --- a/docs/versioned_docs/version-v0.24.0/noir/concepts/data_types/index.md +++ b/docs/versioned_docs/version-v0.24.0/noir/concepts/data_types/index.md @@ -79,7 +79,7 @@ fn main() { } ``` -Type aliases can also be used with [generics](@site/docs/noir/concepts/generics.md): +Type aliases can also be used with [generics](../generics.md): ```rust type Id = Size; diff --git a/docs/versioned_docs/version-v0.24.0/noir/modules_packages_crates/crates_and_packages.md b/docs/versioned_docs/version-v0.24.0/noir/modules_packages_crates/crates_and_packages.md index 760a463094c..95ee9f52ab2 100644 --- a/docs/versioned_docs/version-v0.24.0/noir/modules_packages_crates/crates_and_packages.md +++ b/docs/versioned_docs/version-v0.24.0/noir/modules_packages_crates/crates_and_packages.md @@ -24,7 +24,7 @@ _Library crates_ don't have a `main` function and they don't compile down to ACI #### Contracts -Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/noir-contracts/contracts). +Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts). ### Crate Root diff --git a/docs/versioned_docs/version-v0.24.0/noir/standard_library/black_box_fns.md b/docs/versioned_docs/version-v0.24.0/noir/standard_library/black_box_fns.md index eae8744abf0..be8c65679c3 100644 --- a/docs/versioned_docs/version-v0.24.0/noir/standard_library/black_box_fns.md +++ b/docs/versioned_docs/version-v0.24.0/noir/standard_library/black_box_fns.md @@ -12,18 +12,18 @@ The ACVM spec defines a set of blackbox functions which backends will be expecte Here is a list of the current black box functions: -- [SHA256](./cryptographic_primitives/hashes#sha256) -- [Schnorr signature verification](./cryptographic_primitives/schnorr) -- [Blake2s](./cryptographic_primitives/hashes#blake2s) -- [Blake3](./cryptographic_primitives/hashes#blake3) -- [Pedersen Hash](./cryptographic_primitives/hashes#pedersen_hash) -- [Pedersen Commitment](./cryptographic_primitives/hashes#pedersen_commitment) -- [ECDSA signature verification](./cryptographic_primitives/ecdsa_sig_verification) -- [Fixed base scalar multiplication](./cryptographic_primitives/scalar) +- [SHA256](./cryptographic_primitives/hashes.mdx#sha256) +- [Schnorr signature verification](./cryptographic_primitives/schnorr.mdx) +- [Blake2s](./cryptographic_primitives/hashes.mdx#blake2s) +- [Blake3](./cryptographic_primitives/hashes.mdx#blake3) +- [Pedersen Hash](./cryptographic_primitives/hashes.mdx#pedersen_hash) +- [Pedersen Commitment](./cryptographic_primitives/hashes.mdx#pedersen_commitment) +- [ECDSA signature verification](./cryptographic_primitives/ecdsa_sig_verification.mdx) +- [Fixed base scalar multiplication](./cryptographic_primitives/scalar.mdx) - AND - XOR - RANGE -- [Keccak256](./cryptographic_primitives/hashes#keccak256) +- [Keccak256](./cryptographic_primitives/hashes.mdx#keccak256) - [Recursive proof verification](./recursion) Most black box functions are included as part of the Noir standard library, however `AND`, `XOR` and `RANGE` are used as part of the Noir language syntax. For instance, using the bitwise operator `&` will invoke the `AND` black box function. diff --git a/docs/versioned_docs/version-v0.24.0/tutorials/noirjs_app.md b/docs/versioned_docs/version-v0.24.0/tutorials/noirjs_app.md index ad76dd255cc..12beb476994 100644 --- a/docs/versioned_docs/version-v0.24.0/tutorials/noirjs_app.md +++ b/docs/versioned_docs/version-v0.24.0/tutorials/noirjs_app.md @@ -243,7 +243,7 @@ Now we're ready to prove stuff! Let's feed some inputs to our circuit and calcul await setup(); // let's squeeze our wasm inits here display('logs', 'Generating proof... ⌛'); -const proof = await noir.generateFinalProof(input); +const proof = await noir.generateProof(input); display('logs', 'Generating proof... ✅'); display('results', proof.proof); ``` @@ -264,7 +264,7 @@ Time to celebrate, yes! But we shouldn't trust machines so blindly. Let's add th ```js display('logs', 'Verifying proof... ⌛'); -const verification = await noir.verifyFinalProof(proof); +const verification = await noir.verifyProof(proof); if (verification) display('logs', 'Verifying proof... ✅'); ``` diff --git a/docs/versioned_docs/version-v0.25.0/explainers/explainer-oracle.md b/docs/versioned_docs/version-v0.25.0/explainers/explainer-oracle.md new file mode 100644 index 00000000000..b84ca5dd986 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/explainers/explainer-oracle.md @@ -0,0 +1,57 @@ +--- +title: Oracles +description: This guide provides an in-depth understanding of how Oracles work in Noir programming. Learn how to use outside calculations in your programs, constrain oracles, and understand their uses and limitations. +keywords: + - Noir Programming + - Oracles + - JSON-RPC + - Foreign Call Handlers + - Constrained Functions + - Blockchain Programming +sidebar_position: 1 +--- + +If you've seen "The Matrix" you may recall "The Oracle" as Gloria Foster smoking cigarettes and baking cookies. While she appears to "know things", she is actually providing a calculation of a pre-determined future. Noir Oracles are similar, in a way. They don't calculate the future (yet), but they allow you to use outside calculations in your programs. + +![matrix oracle prediction](@site/static/img/memes/matrix_oracle.jpeg) + +A Noir program is usually self-contained. You can pass certain inputs to it, and it will generate a deterministic output for those inputs. But what if you wanted to defer some calculation to an outside process or source? + +Oracles are functions that provide this feature. + +## Use cases + +An example usage for Oracles is proving something on-chain. For example, proving that the ETH-USDC quote was below a certain target at a certain block time. Or even making more complex proofs like proving the ownership of an NFT as an anonymous login method. + +Another interesting use case is to defer expensive calculations to be made outside of the Noir program, and then constraining the result; similar to the use of [unconstrained functions](../noir/concepts//unconstrained.md). + +In short, anything that can be constrained in a Noir program but needs to be fetched from an external source is a great candidate to be used in oracles. + +## Constraining oracles + +Just like in The Matrix, Oracles are powerful. But with great power, comes great responsibility. Just because you're using them in a Noir program doesn't mean they're true. Noir has no superpowers. If you want to prove that Portugal won the Euro Cup 2016, you're still relying on potentially untrusted information. + +To give a concrete example, Alice wants to login to the [NounsDAO](https://nouns.wtf/) forum with her username "noir_nouner" by proving she owns a noun without revealing her ethereum address. Her Noir program could have a oracle call like this: + +```rust +#[oracle(getNoun)] +unconstrained fn get_noun(address: Field) -> Field +``` + +This oracle could naively resolve with the number of Nouns she possesses. However, it is useless as a trusted source, as the oracle could resolve to anything Alice wants. In order to make this oracle call actually useful, Alice would need to constrain the response from the oracle, by proving her address and the noun count belongs to the state tree of the contract. + +In short, **Oracles don't prove anything. Your Noir program does.** + +:::danger + +If you don't constrain the return of your oracle, you could be clearly opening an attack vector on your Noir program. Make double-triple sure that the return of an oracle call is constrained! + +::: + +## How to use Oracles + +On CLI, Nargo resolves oracles by making JSON RPC calls, which means it would require an RPC node to be running. + +In JavaScript, NoirJS accepts and resolves arbitrary call handlers (that is, not limited to JSON) as long as they matches the expected types the developer defines. Refer to [Foreign Call Handler](../reference/NoirJS/noir_js/type-aliases/ForeignCallHandler.md) to learn more about NoirJS's call handling. + +If you want to build using oracles, follow through to the [oracle guide](../how_to/how-to-oracles.md) for a simple example on how to do that. diff --git a/docs/versioned_docs/version-v0.25.0/explainers/explainer-recursion.md b/docs/versioned_docs/version-v0.25.0/explainers/explainer-recursion.md new file mode 100644 index 00000000000..18846176ca7 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/explainers/explainer-recursion.md @@ -0,0 +1,176 @@ +--- +title: Recursive proofs +description: Explore the concept of recursive proofs in Zero-Knowledge programming. Understand how recursion works in Noir, a language for writing smart contracts on the EVM blockchain. Learn through practical examples like Alice and Bob's guessing game, Charlie's recursive merkle tree, and Daniel's reusable components. Discover how to use recursive proofs to optimize computational resources and improve efficiency. + +keywords: + [ + "Recursive Proofs", + "Zero-Knowledge Programming", + "Noir", + "EVM Blockchain", + "Smart Contracts", + "Recursion in Noir", + "Alice and Bob Guessing Game", + "Recursive Merkle Tree", + "Reusable Components", + "Optimizing Computational Resources", + "Improving Efficiency", + "Verification Key", + "Aggregation", + "Recursive zkSNARK schemes", + "PLONK", + "Proving and Verification Keys" + ] +sidebar_position: 1 +pagination_next: how_to/how-to-recursion +--- + +In programming, we tend to think of recursion as something calling itself. A classic example would be the calculation of the factorial of a number: + +```js +function factorial(n) { + if (n === 0 || n === 1) { + return 1; + } else { + return n * factorial(n - 1); + } +} +``` + +In this case, while `n` is not `1`, this function will keep calling itself until it hits the base case, bubbling up the result on the call stack: + +```md + Is `n` 1? <--------- + /\ / + / \ n = n -1 + / \ / + Yes No -------- +``` + +In Zero-Knowledge, recursion has some similarities. + +It is not a Noir function calling itself, but a proof being used as an input to another circuit. In short, you verify one proof *inside* another proof, returning the proof that both proofs are valid. + +This means that, given enough computational resources, you can prove the correctness of any arbitrary number of proofs in a single proof. This could be useful to design state channels (for which a common example would be [Bitcoin's Lightning Network](https://en.wikipedia.org/wiki/Lightning_Network)), to save on gas costs by settling one proof on-chain, or simply to make business logic less dependent on a consensus mechanism. + +## Examples + +Let us look at some of these examples + +### Alice and Bob - Guessing game + +Alice and Bob are friends, and they like guessing games. They want to play a guessing game online, but for that, they need a trusted third-party that knows both of their secrets and finishes the game once someone wins. + +So, they use zero-knowledge proofs. Alice tries to guess Bob's number, and Bob will generate a ZK proof stating whether she succeeded or failed. + +This ZK proof can go on a smart contract, revealing the winner and even giving prizes. However, this means every turn needs to be verified on-chain. This incurs some cost and waiting time that may simply make the game too expensive or time-consuming to be worth it. + +As a solution, Alice proposes the following: "what if Bob generates his proof, and instead of sending it on-chain, I verify it *within* my own proof before playing my own turn?". + +She can then generate a proof that she verified his proof, and so on. + +```md + Did you fail? <-------------------------- + / \ / + / \ n = n -1 + / \ / + Yes No / + | | / + | | / + | You win / + | / + | / +Generate proof of that / + + / + my own guess ---------------- +``` + +### Charlie - Recursive merkle tree + +Charlie is a concerned citizen, and wants to be sure his vote in an election is accounted for. He votes with a ZK proof, but he has no way of knowing that his ZK proof was included in the total vote count! + +If the vote collector puts all of the votes into a [Merkle tree](https://en.wikipedia.org/wiki/Merkle_tree), everyone can prove the verification of two proofs within one proof, as such: + +```md + abcd + __________|______________ + | | + ab cd + _____|_____ ______|______ + | | | | + alice bob charlie daniel +``` + +Doing this recursively allows us to arrive on a final proof `abcd` which if true, verifies the correctness of all the votes. + +### Daniel - Reusable components + +Daniel has a big circuit and a big headache. A part of his circuit is a setup phase that finishes with some assertions that need to be made. But that section alone takes most of the proving time, and is largely independent of the rest of the circuit. + +He might find it more efficient to generate a proof for that setup phase separately, and verify that proof recursively in the actual business logic section of his circuit. This will allow for parallelization of both proofs, which results in a considerable speedup. + +## What params do I need + +As you can see in the [recursion reference](noir/standard_library/recursion.md), a simple recursive proof requires: + +- The proof to verify +- The Verification Key of the circuit that generated the proof +- A hash of this verification key, as it's needed for some backends +- The public inputs for the proof + +:::info + +Recursive zkSNARK schemes do not necessarily "verify a proof" in the sense that you expect a true or false to be spit out by the verifier. Rather an aggregation object is built over the public inputs. + +So, taking the example of Alice and Bob and their guessing game: + +- Alice makes her guess. Her proof is *not* recursive: it doesn't verify any proof within it! It's just a standard `assert(x != y)` circuit +- Bob verifies Alice's proof and makes his own guess. In this circuit, he doesn't exactly *prove* the verification of Alice's proof. Instead, he *aggregates* his proof to Alice's proof. The actual verification is done when the full proof is verified, for example when using `nargo verify` or through the verifier smart contract. + +We can imagine recursive proofs a [relay race](https://en.wikipedia.org/wiki/Relay_race). The first runner doesn't have to receive the baton from anyone else, as he/she already starts with it. But when his/her turn is over, the next runner needs to receive it, run a bit more, and pass it along. Even though every runner could theoretically verify the baton mid-run (why not? 🏃🔍), only at the end of the race does the referee verify that the whole race is valid. + +::: + +## Some architecture + +As with everything in computer science, there's no one-size-fits all. But there are some patterns that could help understanding and implementing them. To give three examples: + +### Adding some logic to a proof verification + +This would be an approach for something like our guessing game, where proofs are sent back and forth and are verified by each opponent. This circuit would be divided in two sections: + +- A `recursive verification` section, which would be just the call to `std::verify_proof`, and that would be skipped on the first move (since there's no proof to verify) +- A `guessing` section, which is basically the logic part where the actual guessing happens + +In such a situation, and assuming Alice is first, she would skip the first part and try to guess Bob's number. Bob would then verify her proof on the first section of his run, and try to guess Alice's number on the second part, and so on. + +### Aggregating proofs + +In some one-way interaction situations, recursion would allow for aggregation of simple proofs that don't need to be immediately verified on-chain or elsewhere. + +To give a practical example, a barman wouldn't need to verify a "proof-of-age" on-chain every time he serves alcohol to a customer. Instead, the architecture would comprise two circuits: + +- A `main`, non-recursive circuit with some logic +- A `recursive` circuit meant to verify two proofs in one proof + +The customer's proofs would be intermediate, and made on their phones, and the barman could just verify them locally. He would then aggregate them into a final proof sent on-chain (or elsewhere) at the end of the day. + +### Recursively verifying different circuits + +Nothing prevents you from verifying different circuits in a recursive proof, for example: + +- A `circuit1` circuit +- A `circuit2` circuit +- A `recursive` circuit + +In this example, a regulator could verify that taxes were paid for a specific purchase by aggregating both a `payer` circuit (proving that a purchase was made and taxes were paid), and a `receipt` circuit (proving that the payment was received) + +## How fast is it + +At the time of writing, verifying recursive proofs is surprisingly fast. This is because most of the time is spent on generating the verification key that will be used to generate the next proof. So you are able to cache the verification key and reuse it later. + +Currently, Noir JS packages don't expose the functionality of loading proving and verification keys, but that feature exists in the underlying `bb.js` package. + +## How can I try it + +Learn more about using recursion in Nargo and NoirJS in the [how-to guide](../how_to/how-to-recursion.md) and see a full example in [noir-examples](https://github.com/noir-lang/noir-examples). diff --git a/docs/versioned_docs/version-v0.25.0/getting_started/_category_.json b/docs/versioned_docs/version-v0.25.0/getting_started/_category_.json new file mode 100644 index 00000000000..5d694210bbf --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/getting_started/_category_.json @@ -0,0 +1,5 @@ +{ + "position": 0, + "collapsible": true, + "collapsed": true +} diff --git a/docs/versioned_docs/version-v0.25.0/getting_started/hello_noir/_category_.json b/docs/versioned_docs/version-v0.25.0/getting_started/hello_noir/_category_.json new file mode 100644 index 00000000000..23b560f610b --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/getting_started/hello_noir/_category_.json @@ -0,0 +1,5 @@ +{ + "position": 1, + "collapsible": true, + "collapsed": true +} diff --git a/docs/versioned_docs/version-v0.25.0/getting_started/hello_noir/index.md b/docs/versioned_docs/version-v0.25.0/getting_started/hello_noir/index.md new file mode 100644 index 00000000000..743c4d8d634 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/getting_started/hello_noir/index.md @@ -0,0 +1,142 @@ +--- +title: Creating a Project +description: + Learn how to create and verify your first Noir program using Nargo, a programming language for + zero-knowledge proofs. +keywords: + [ + Nargo, + Noir, + zero-knowledge proofs, + programming language, + create Noir program, + verify Noir program, + step-by-step guide, + ] +sidebar_position: 1 + +--- + +Now that we have installed Nargo, it is time to make our first hello world program! + +## Create a Project Directory + +Noir code can live anywhere on your computer. Let us create a _projects_ folder in the home +directory to house our Noir programs. + +For Linux, macOS, and Windows PowerShell, create the directory and change directory into it by +running: + +```sh +mkdir ~/projects +cd ~/projects +``` + +## Create Our First Nargo Project + +Now that we are in the projects directory, create a new Nargo project by running: + +```sh +nargo new hello_world +``` + +> **Note:** `hello_world` can be any arbitrary project name, we are simply using `hello_world` for +> demonstration. +> +> In production, the common practice is to name the project folder as `circuits` for better +> identifiability when sitting alongside other folders in the codebase (e.g. `contracts`, `scripts`, +> `test`). + +A `hello_world` folder would be created. Similar to Rust, the folder houses _src/main.nr_ and +_Nargo.toml_ which contain the source code and environmental options of your Noir program +respectively. + +### Intro to Noir Syntax + +Let us take a closer look at _main.nr_. The default _main.nr_ generated should look like this: + +```rust +fn main(x : Field, y : pub Field) { + assert(x != y); +} +``` + +The first line of the program specifies the program's inputs: + +```rust +x : Field, y : pub Field +``` + +Program inputs in Noir are private by default (e.g. `x`), but can be labeled public using the +keyword `pub` (e.g. `y`). To learn more about private and public values, check the +[Data Types](../../noir/concepts/data_types/index.md) section. + +The next line of the program specifies its body: + +```rust +assert(x != y); +``` + +The Noir syntax `assert` can be interpreted as something similar to constraints in other zk-contract languages. + +For more Noir syntax, check the [Language Concepts](../../noir/concepts/comments.md) chapter. + +## Build In/Output Files + +Change directory into _hello_world_ and build in/output files for your Noir program by running: + +```sh +cd hello_world +nargo check +``` + +Two additional files would be generated in your project directory: + +_Prover.toml_ houses input values, and _Verifier.toml_ houses public values. + +## Prove Our Noir Program + +Now that the project is set up, we can create a proof of correct execution of our Noir program. + +Fill in input values for execution in the _Prover.toml_ file. For example: + +```toml +x = "1" +y = "2" +``` + +Prove the valid execution of your Noir program: + +```sh +nargo prove +``` + +A new folder _proofs_ would then be generated in your project directory, containing the proof file +`.proof`, where the project name is defined in Nargo.toml. + +The _Verifier.toml_ file would also be updated with the public values computed from program +execution (in this case the value of `y`): + +```toml +y = "0x0000000000000000000000000000000000000000000000000000000000000002" +``` + +> **Note:** Values in _Verifier.toml_ are computed as 32-byte hex values. + +## Verify Our Noir Program + +Once a proof is generated, we can verify correct execution of our Noir program by verifying the +proof file. + +Verify your proof by running: + +```sh +nargo verify +``` + +The verification will complete in silence if it is successful. If it fails, it will log the +corresponding error instead. + +Congratulations, you have now created and verified a proof for your very first Noir program! + +In the [next section](./project_breakdown.md), we will go into more detail on each step performed. diff --git a/docs/versioned_docs/version-v0.25.0/getting_started/hello_noir/project_breakdown.md b/docs/versioned_docs/version-v0.25.0/getting_started/hello_noir/project_breakdown.md new file mode 100644 index 00000000000..6160a102c6c --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/getting_started/hello_noir/project_breakdown.md @@ -0,0 +1,199 @@ +--- +title: Project Breakdown +description: + Learn about the anatomy of a Nargo project, including the purpose of the Prover and Verifier TOML + files, and how to prove and verify your program. +keywords: + [Nargo, Nargo project, Prover.toml, Verifier.toml, proof verification, private asset transfer] +sidebar_position: 2 +--- + +This section breaks down our hello world program from the previous section. We elaborate on the project +structure and what the `prove` and `verify` commands did. + +## Anatomy of a Nargo Project + +Upon creating a new project with `nargo new` and building the in/output files with `nargo check` +commands, you would get a minimal Nargo project of the following structure: + + - src + - Prover.toml + - Verifier.toml + - Nargo.toml + +The source directory _src_ holds the source code for your Noir program. By default only a _main.nr_ +file will be generated within it. + +### Prover.toml + +_Prover.toml_ is used for specifying the input values for executing and proving the program. You can specify `toml` files with different names by using the `--prover-name` or `-p` flags, see the [Prover](#provertoml) section below. Optionally you may specify expected output values for prove-time checking as well. + +### Verifier.toml + +_Verifier.toml_ contains public in/output values computed when executing the Noir program. + +### Nargo.toml + +_Nargo.toml_ contains the environmental options of your project. It contains a "package" section and a "dependencies" section. + +Example Nargo.toml: + +```toml +[package] +name = "noir_starter" +type = "bin" +authors = ["Alice"] +compiler_version = "0.9.0" +description = "Getting started with Noir" +entry = "circuit/main.nr" +license = "MIT" + +[dependencies] +ecrecover = {tag = "v0.9.0", git = "https://github.com/colinnielsen/ecrecover-noir.git"} +``` + +Nargo.toml for a [workspace](../../noir/modules_packages_crates/workspaces.md) will look a bit different. For example: + +```toml +[workspace] +members = ["crates/a", "crates/b"] +default-member = "crates/a" +``` + +#### Package section + +The package section defines a number of fields including: + +- `name` (**required**) - the name of the package +- `type` (**required**) - can be "bin", "lib", or "contract" to specify whether its a binary, library or Aztec contract +- `authors` (optional) - authors of the project +- `compiler_version` - specifies the version of the compiler to use. This is enforced by the compiler and follow's [Rust's versioning](https://doc.rust-lang.org/cargo/reference/manifest.html#the-version-field), so a `compiler_version = 0.18.0` will enforce Nargo version 0.18.0, `compiler_version = ^0.18.0` will enforce anything above 0.18.0 but below 0.19.0, etc. For more information, see how [Rust handles these operators](https://docs.rs/semver/latest/semver/enum.Op.html) +- `description` (optional) +- `entry` (optional) - a relative filepath to use as the entry point into your package (overrides the default of `src/lib.nr` or `src/main.nr`) +- `backend` (optional) +- `license` (optional) + +#### Dependencies section + +This is where you will specify any dependencies for your project. See the [Dependencies page](../../noir/modules_packages_crates/dependencies.md) for more info. + +`./proofs/` and `./contract/` directories will not be immediately visible until you create a proof or +verifier contract respectively. + +### main.nr + +The _main.nr_ file contains a `main` method, this method is the entry point into your Noir program. + +In our sample program, _main.nr_ looks like this: + +```rust +fn main(x : Field, y : Field) { + assert(x != y); +} +``` + +The parameters `x` and `y` can be seen as the API for the program and must be supplied by the +prover. Since neither `x` nor `y` is marked as public, the verifier does not supply any inputs, when +verifying the proof. + +The prover supplies the values for `x` and `y` in the _Prover.toml_ file. + +As for the program body, `assert` ensures that the condition to be satisfied (e.g. `x != y`) is +constrained by the proof of the execution of said program (i.e. if the condition was not met, the +verifier would reject the proof as an invalid proof). + +### Prover.toml + +The _Prover.toml_ file is a file which the prover uses to supply his witness values(both private and +public). + +In our hello world program the _Prover.toml_ file looks like this: + +```toml +x = "1" +y = "2" +``` + +When the command `nargo prove` is executed, two processes happen: + +1. Noir creates a proof that `x`, which holds the value of `1`, and `y`, which holds the value of `2`, + is not equal. This inequality constraint is due to the line `assert(x != y)`. + +2. Noir creates and stores the proof of this statement in the _proofs_ directory in a file called your-project.proof. So if your project is named "private_voting" (defined in the project Nargo.toml), the proof will be saved at `./proofs/private_voting.proof`. Opening this file will display the proof in hex format. + +#### Arrays of Structs + +The following code shows how to pass an array of structs to a Noir program to generate a proof. + +```rust +// main.nr +struct Foo { + bar: Field, + baz: Field, +} + +fn main(foos: [Foo; 3]) -> pub Field { + foos[2].bar + foos[2].baz +} +``` + +Prover.toml: + +```toml +[[foos]] # foos[0] +bar = 0 +baz = 0 + +[[foos]] # foos[1] +bar = 0 +baz = 0 + +[[foos]] # foos[2] +bar = 1 +baz = 2 +``` + +#### Custom toml files + +You can specify a `toml` file with a different name to use for proving by using the `--prover-name` or `-p` flags. + +This command looks for proof inputs in the default **Prover.toml** and generates the proof and saves it at `./proofs/.proof`: + +```bash +nargo prove +``` + +This command looks for proof inputs in the custom **OtherProver.toml** and generates proof and saves it at `./proofs/.proof`: + +```bash +nargo prove -p OtherProver +``` + +## Verifying a Proof + +When the command `nargo verify` is executed, two processes happen: + +1. Noir checks in the _proofs_ directory for a proof file with the project name (eg. test_project.proof) + +2. If that file is found, the proof's validity is checked + +> **Note:** The validity of the proof is linked to the current Noir program; if the program is +> changed and the verifier verifies the proof, it will fail because the proof is not valid for the +> _modified_ Noir program. + +In production, the prover and the verifier are usually two separate entities. A prover would +retrieve the necessary inputs, execute the Noir program, generate a proof and pass it to the +verifier. The verifier would then retrieve the public inputs, usually from external sources, and +verify the validity of the proof against it. + +Take a private asset transfer as an example: + +A person using a browser as the prover would retrieve private inputs locally (e.g. the user's private key) and +public inputs (e.g. the user's encrypted balance on-chain), compute the transfer, generate a proof +and submit it to the verifier smart contract. + +The verifier contract would then draw the user's encrypted balance directly from the blockchain and +verify the proof submitted against it. If the verification passes, additional functions in the +verifier contract could trigger (e.g. approve the asset transfer). + +Now that you understand the concepts, you'll probably want some editor feedback while you are writing more complex code. diff --git a/docs/versioned_docs/version-v0.25.0/getting_started/installation/_category_.json b/docs/versioned_docs/version-v0.25.0/getting_started/installation/_category_.json new file mode 100644 index 00000000000..0c02fb5d4d7 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/getting_started/installation/_category_.json @@ -0,0 +1,6 @@ +{ + "position": 0, + "label": "Install Nargo", + "collapsible": true, + "collapsed": true +} diff --git a/docs/versioned_docs/version-v0.25.0/getting_started/installation/index.md b/docs/versioned_docs/version-v0.25.0/getting_started/installation/index.md new file mode 100644 index 00000000000..4ef86aa5914 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/getting_started/installation/index.md @@ -0,0 +1,48 @@ +--- +title: Nargo Installation +description: + nargo is a command line tool for interacting with Noir programs. This page is a quick guide on how to install Nargo through the most common and easy method, noirup +keywords: [ + Nargo + Noir + Rust + Cargo + Noirup + Installation + Terminal Commands + Version Check + Nightlies + Specific Versions + Branches + Noirup Repository +] +pagination_next: getting_started/hello_noir/index +--- + +`nargo` is the one-stop-shop for almost everything related with Noir. The name comes from our love for Rust and its package manager `cargo`. + +With `nargo`, you can start new projects, compile, execute, prove, verify, test, generate solidity contracts, and do pretty much all that is available in Noir. + +Similarly to `rustup`, we also maintain an easy installation method that covers most machines: `noirup`. + +## Installing Noirup + +Open a terminal on your machine, and write: + +```bash +curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash +``` + +Close the terminal, open another one, and run + +```bash +noirup +``` + +Done. That's it. You should have the latest version working. You can check with `nargo --version`. + +You can also install nightlies, specific versions +or branches. Check out the [noirup repository](https://github.com/noir-lang/noirup) for more +information. + +Now we're ready to start working on [our first Noir program!](../hello_noir/index.md) diff --git a/docs/versioned_docs/version-v0.25.0/getting_started/installation/other_install_methods.md b/docs/versioned_docs/version-v0.25.0/getting_started/installation/other_install_methods.md new file mode 100644 index 00000000000..a35e34aaf9c --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/getting_started/installation/other_install_methods.md @@ -0,0 +1,254 @@ +--- +title: Alternative Install Methods +description: There are different ways to install Nargo, the one-stop shop and command-line tool for developing Noir programs. This guide explains other methods that don't rely on noirup, such as compiling from source, installing from binaries, and using WSL for windows +keywords: [ + Installation + Nargo + Noirup + Binaries + Compiling from Source + WSL for Windows + macOS + Linux + Nix + Direnv + Shell & editor experience + Building and testing + Uninstalling Nargo + Noir vs code extension, + ] +sidebar_position: 1 +--- + +## Encouraged Installation Method: Noirup + +Noirup is the endorsed method for installing Nargo, streamlining the process of fetching binaries or compiling from source. It supports a range of options to cater to your specific needs, from nightly builds and specific versions to compiling from various sources. + +### Installing Noirup + +First, ensure you have `noirup` installed: + +```sh +curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash +``` + +### Fetching Binaries + +With `noirup`, you can easily switch between different Nargo versions, including nightly builds: + +- **Nightly Version**: Install the latest nightly build. + + ```sh + noirup --version nightly + ``` + +- **Specific Version**: Install a specific version of Nargo. + ```sh + noirup --version + ``` + +### Compiling from Source + +`noirup` also enables compiling Nargo from various sources: + +- **From a Specific Branch**: Install from the latest commit on a branch. + + ```sh + noirup --branch + ``` + +- **From a Fork**: Install from the main branch of a fork. + + ```sh + noirup --repo + ``` + +- **From a Specific Branch in a Fork**: Install from a specific branch in a fork. + + ```sh + noirup --repo --branch + ``` + +- **From a Specific Pull Request**: Install from a specific PR. + + ```sh + noirup --pr + ``` + +- **From a Specific Commit**: Install from a specific commit. + + ```sh + noirup -C + ``` + +- **From Local Source**: Compile and install from a local directory. + ```sh + noirup --path ./path/to/local/source + ``` + +## Alternate Installation Methods (No Longer Recommended) + +While the following methods are available, they are no longer recommended. We advise using noirup for a more efficient and flexible installation experience. + +However, there are other methods for installing Nargo: + +- [Binaries](#option-1-installing-from-binaries) +- [Compiling from Source](#option-2-compile-from-source) +- [WSL for Windows](#option-3-wsl-for-windows) + +### Option 1: Installing from Binaries + +See [GitHub Releases](https://github.com/noir-lang/noir/releases) for the latest and previous +platform specific binaries. + +#### Step 1 + +Paste and run the following in the terminal to extract and install the binary: + +> **macOS / Linux:** If you are prompted with `Permission denied` when running commands, prepend +> `sudo` and re-run it. + +##### macOS (Apple Silicon) + +```bash +mkdir -p $HOME/.nargo/bin && \ +curl -o $HOME/.nargo/bin/nargo-aarch64-apple-darwin.tar.gz -L https://github.com/noir-lang/noir/releases/download/v0.24.0/nargo-aarch64-apple-darwin.tar.gz && \ +tar -xvf $HOME/.nargo/bin/nargo-aarch64-apple-darwin.tar.gz -C $HOME/.nargo/bin/ && \ +echo '\nexport PATH=$PATH:$HOME/.nargo/bin' >> ~/.zshrc && \ +source ~/.zshrc +``` + +##### macOS (Intel) + +```bash +mkdir -p $HOME/.nargo/bin && \ +curl -o $HOME/.nargo/bin/nargo-x86_64-apple-darwin.tar.gz -L https://github.com/noir-lang/noir/releases/download/v0.24.0/nargo-x86_64-apple-darwin.tar.gz && \ +tar -xvf $HOME/.nargo/bin/nargo-x86_64-apple-darwin.tar.gz -C $HOME/.nargo/bin/ && \ +echo '\nexport PATH=$PATH:$HOME/.nargo/bin' >> ~/.zshrc && \ +source ~/.zshrc +``` + +##### Linux (Bash) + +```bash +mkdir -p $HOME/.nargo/bin && \ +curl -o $HOME/.nargo/bin/nargo-x86_64-unknown-linux-gnu.tar.gz -L https://github.com/noir-lang/noir/releases/download/v0.24.0/nargo-x86_64-unknown-linux-gnu.tar.gz && \ +tar -xvf $HOME/.nargo/bin/nargo-x86_64-unknown-linux-gnu.tar.gz -C $HOME/.nargo/bin/ && \ +echo -e '\nexport PATH=$PATH:$HOME/.nargo/bin' >> ~/.bashrc && \ +source ~/.bashrc +``` + +#### Step 2 + +Check if the installation was successful by running `nargo --version`. You should get a version number. + +> **macOS:** If you are prompted with an OS alert, right-click and open the _nargo_ executable from +> Finder. Close the new terminal popped up and `nargo` should now be accessible. + +### Option 2: Compile from Source + +Due to the large number of native dependencies, Noir projects uses [Nix](https://nixos.org/) and [direnv](https://direnv.net/) to streamline the development experience. It helps mitigating issues commonly associated with dependency management, such as conflicts between required package versions for different projects (often referred to as "dependency hell"). + +Combined with direnv, which automatically sets or clears environment variables based on the directory, it further simplifies the development process by seamlessly integrating with the developer's shell, facilitating an efficient and reliable workflow for managing and deploying Noir projects with multiple dependencies. + +#### Setting up your environment + +For the best experience, please follow these instructions to setup your environment: + +1. Install Nix following [their guide](https://nixos.org/download.html) for your operating system. +2. Create the file `~/.config/nix/nix.conf` with the contents: + +```ini +experimental-features = nix-command +extra-experimental-features = flakes +``` + +3. Install direnv into your Nix profile by running: + +```sh +nix profile install nixpkgs#direnv +``` + +4. Add direnv to your shell following [their guide](https://direnv.net/docs/hook.html). + 1. For bash or zshell, add `eval "$(direnv hook bash)"` or `eval "$(direnv hook zsh)"` to your ~/.bashrc or ~/.zshrc file, respectively. +5. Restart your shell. + +#### Shell & editor experience + +Now that your environment is set up, you can get to work on the project. + +1. Clone the repository, such as: + +```sh +git clone git@github.com:noir-lang/noir +``` + +> Replacing `noir` with whichever repository you want to work on. + +2. Navigate to the directory: + +```sh +cd noir +``` + +> Replacing `noir` with whichever repository you cloned. + +3. You should see a **direnv error** because projects aren't allowed by default. Make sure you've reviewed and trust our `.envrc` file, then you need to run: + +```sh +direnv allow +``` + +4. Now, wait awhile for all the native dependencies to be built. This will take some time and direnv will warn you that it is taking a long time, but we just need to let it run. + +5. Once you are presented with your prompt again, you can start your editor within the project directory (we recommend [VSCode](https://code.visualstudio.com/)): + +```sh +code . +``` + +6. (Recommended) When launching VSCode for the first time, you should be prompted to install our recommended plugins. We highly recommend installing these for the best development experience. + +#### Building and testing + +Assuming you are using `direnv` to populate your environment, building and testing the project can be done +with the typical `cargo build`, `cargo test`, and `cargo clippy` commands. You'll notice that the `cargo` version matches the version we specify in `rust-toolchain.toml`, which is 1.73.0 at the time of this writing. + +If you want to build the entire project in an isolated sandbox, you can use Nix commands: + +1. `nix build .` (or `nix build . -L` for verbose output) to build the project in a Nix sandbox. +2. `nix flake check` (or `nix flake check -L` for verbose output) to run clippy and tests in a Nix sandbox. + +#### Without `direnv` + +If you have hesitations with using direnv, you can launch a subshell with `nix develop` and then launch your editor from within the subshell. However, if VSCode was already launched in the project directory, the environment won't be updated. + +Advanced: If you aren't using direnv nor launching your editor within the subshell, you can try to install Barretenberg and other global dependencies the package needs. This is an advanced workflow and likely won't receive support! + +### Option 3: WSL (for Windows) + +The default backend for Noir (Barretenberg) doesn't provide Windows binaries at this time. For that reason, Noir cannot be installed natively. However, it is available by using Windows Subsystem for Linux (WSL). + +Step 1: Follow the instructions [here](https://learn.microsoft.com/en-us/windows/wsl/install) to install and run WSL. + +step 2: Follow the [Noirup instructions](#encouraged-installation-method-noirup). + +## Uninstalling Nargo + +### Noirup + +If you installed Nargo with `noirup` or through directly downloading binaries, you can uninstall Nargo by removing the files in `~/.nargo`, `~/nargo`, and `~/noir_cache`. This ensures that all installed binaries, configurations, and cache related to Nargo are fully removed from your system. + +```bash +rm -r ~/.nargo +rm -r ~/nargo +rm -r ~/noir_cache +``` + +### Nix + +If you installed Nargo with Nix or compiled it from source, you can remove the binary located at `~/.nix-profile/bin/nargo`. + +```bash +rm ~/.nix-profile/bin/nargo +``` diff --git a/docs/versioned_docs/version-v0.25.0/getting_started/tooling/_category_.json b/docs/versioned_docs/version-v0.25.0/getting_started/tooling/_category_.json new file mode 100644 index 00000000000..55804c03a71 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/getting_started/tooling/_category_.json @@ -0,0 +1,6 @@ +{ + "position": 2, + "label": "Tooling", + "collapsible": true, + "collapsed": true +} diff --git a/docs/versioned_docs/version-v0.25.0/getting_started/tooling/index.mdx b/docs/versioned_docs/version-v0.25.0/getting_started/tooling/index.mdx new file mode 100644 index 00000000000..ac480f3c9f5 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/getting_started/tooling/index.mdx @@ -0,0 +1,38 @@ +--- +title: Tooling +Description: This section provides information about the various tools and utilities available for Noir development. It covers the Noir playground, IDE tools, Codespaces, and community projects. +Keywords: [Noir, Development, Playground, IDE Tools, Language Service Provider, VS Code Extension, Codespaces, noir-starter, Community Projects, Awesome Noir Repository, Developer Tooling] +--- + +Noir is meant to be easy to develop with. For that reason, a number of utilities have been put together to ease the development process as much as feasible in the zero-knowledge world. + +## Playground + +The Noir playground is an easy way to test small ideas, share snippets, and integrate in other websites. You can access it at [play.noir-lang.org](https://play.noir-lang.org). + +## IDE tools + +When you install Nargo, you're also installing a Language Service Provider (LSP), which can be used by IDEs to provide syntax highlighting, codelens, warnings, and more. + +The easiest way to use these tools is by installing the [Noir VS Code extension](https://marketplace.visualstudio.com/items?itemName=noir-lang.vscode-noir). + +## Codespaces + +Some Noir repos have leveraged Codespaces in order to ease the development process. You can visit the [noir-starter](https://github.com/noir-lang/noir-starter) for an example. + + + +## GitHub Actions + +You can use `noirup` with GitHub Actions for CI/CD and automated testing. It is as simple as +installing `noirup` and running tests in your GitHub Action `yml` file. + +See the +[config file in the Noir repo](https://github.com/TomAFrench/noir-hashes/blob/master/.github/workflows/noir.yml) for an example usage. + +## Community projects + +As an open-source project, Noir has received many contributions over time. Some of them are related with developer tooling, and you can see some of them in [Awesome Noir repository](https://github.com/noir-lang/awesome-noir#dev-tools) diff --git a/docs/versioned_docs/version-v0.25.0/getting_started/tooling/language_server.md b/docs/versioned_docs/version-v0.25.0/getting_started/tooling/language_server.md new file mode 100644 index 00000000000..81e0356ef8a --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/getting_started/tooling/language_server.md @@ -0,0 +1,43 @@ +--- +title: Language Server +description: Learn about the Noir Language Server, how to install the components, and configuration that may be required. +keywords: [Nargo, Language Server, LSP, VSCode, Visual Studio Code] +sidebar_position: 0 +--- + +This section helps you install and configure the Noir Language Server. + +The Language Server Protocol (LSP) has two components, the [Server](#language-server) and the [Client](#language-client). Below we describe each in the context of Noir. + +## Language Server + +The Server component is provided by the Nargo command line tool that you installed at the beginning of this guide. +As long as Nargo is installed and you've used it to run other commands in this guide, it should be good to go! + +If you'd like to verify that the `nargo lsp` command is available, you can run `nargo --help` and look for `lsp` in the list of commands. If you see it, you're using a version of Noir with LSP support. + +## Language Client + +The Client component is usually an editor plugin that launches the Server. It communicates LSP messages between the editor and the Server. For example, when you save a file, the Client will alert the Server, so it can try to compile the project and report any errors. + +Currently, Noir provides a Language Client for Visual Studio Code via the [vscode-noir](https://github.com/noir-lang/vscode-noir) extension. You can install it via the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=noir-lang.vscode-noir). + +> **Note:** Noir's Language Server Protocol support currently assumes users' VSCode workspace root to be the same as users' Noir project root (i.e. where Nargo.toml lies). +> +> If LSP features seem to be missing / malfunctioning, make sure you are opening your Noir project directly (instead of as a sub-folder) in your VSCode instance. + +When your language server is running correctly and the VSCode plugin is installed, you should see handy codelens buttons for compilation, measuring circuit size, execution, and tests: + +![Compile and Execute](@site/static/img/codelens_compile_execute.png) +![Run test](@site/static/img/codelens_run_test.png) + +You should also see your tests in the `testing` panel: + +![Testing panel](@site/static/img/codelens_testing_panel.png) + +### Configuration + +- **Noir: Enable LSP** - If checked, the extension will launch the Language Server via `nargo lsp` and communicate with it. +- **Noir: Nargo Flags** - Additional flags may be specified if you require them to be added when the extension calls `nargo lsp`. +- **Noir: Nargo Path** - An absolute path to a Nargo binary with the `lsp` command. This may be useful if Nargo is not within the `PATH` of your editor. +- **Noir > Trace: Server** - Setting this to `"messages"` or `"verbose"` will log LSP messages between the Client and Server. Useful for debugging. diff --git a/docs/versioned_docs/version-v0.25.0/getting_started/tooling/testing.md b/docs/versioned_docs/version-v0.25.0/getting_started/tooling/testing.md new file mode 100644 index 00000000000..d3e0c522473 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/getting_started/tooling/testing.md @@ -0,0 +1,62 @@ +--- +title: Testing in Noir +description: Learn how to use Nargo to test your Noir program in a quick and easy way +keywords: [Nargo, testing, Noir, compile, test] +sidebar_position: 1 +--- + +You can test your Noir programs using Noir circuits. + +Nargo will automatically compile and run any functions which have the decorator `#[test]` on them if +you run `nargo test`. + +For example if you have a program like: + +```rust +fn add(x: u64, y: u64) -> u64 { + x + y +} +#[test] +fn test_add() { + assert(add(2,2) == 4); + assert(add(0,1) == 1); + assert(add(1,0) == 1); +} +``` + +Running `nargo test` will test that the `test_add` function can be executed while satisfying all +the constraints which allows you to test that add returns the expected values. Test functions can't +have any arguments currently. + +### Test fail + +You can write tests that are expected to fail by using the decorator `#[test(should_fail)]`. For example: + +```rust +fn add(x: u64, y: u64) -> u64 { + x + y +} +#[test(should_fail)] +fn test_add() { + assert(add(2,2) == 5); +} +``` + +You can be more specific and make it fail with a specific reason by using `should_fail_with = "`: + +```rust +fn main(african_swallow_avg_speed : Field) { + assert(african_swallow_avg_speed == 65, "What is the airspeed velocity of an unladen swallow"); +} + +#[test] +fn test_king_arthur() { + main(65); +} + +#[test(should_fail_with = "What is the airspeed velocity of an unladen swallow")] +fn test_bridgekeeper() { + main(32); +} + +``` diff --git a/docs/versioned_docs/version-v0.25.0/how_to/_category_.json b/docs/versioned_docs/version-v0.25.0/how_to/_category_.json new file mode 100644 index 00000000000..23b560f610b --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/how_to/_category_.json @@ -0,0 +1,5 @@ +{ + "position": 1, + "collapsible": true, + "collapsed": true +} diff --git a/docs/versioned_docs/version-v0.25.0/how_to/how-to-oracles.md b/docs/versioned_docs/version-v0.25.0/how_to/how-to-oracles.md new file mode 100644 index 00000000000..ab225b9421f --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/how_to/how-to-oracles.md @@ -0,0 +1,280 @@ +--- +title: How to use Oracles +description: Learn how to use oracles in your Noir program with examples in both Nargo and NoirJS. This guide also covers writing a JSON RPC server and providing custom foreign call handlers for NoirJS. +keywords: + - Noir Programming + - Oracles + - Nargo + - NoirJS + - JSON RPC Server + - Foreign Call Handlers +sidebar_position: 1 +--- + +This guide shows you how to use oracles in your Noir program. For the sake of clarity, it assumes that: + +- You have read the [explainer on Oracles](../explainers/explainer-oracle.md) and are comfortable with the concept. +- You have a Noir program to add oracles to. You can create one using the [vite-hardhat starter](https://github.com/noir-lang/noir-starter/tree/main/vite-hardhat) as a boilerplate. +- You understand the concept of a JSON-RPC server. Visit the [JSON-RPC website](https://www.jsonrpc.org/) if you need a refresher. +- You are comfortable with server-side JavaScript (e.g. Node.js, managing packages, etc.). + +For reference, you can find the snippets used in this tutorial on the [Aztec DevRel Repository](https://github.com/AztecProtocol/dev-rel/tree/main/code-snippets/how-to-oracles). + +## Rundown + +This guide has 3 major steps: + +1. How to modify our Noir program to make use of oracle calls as unconstrained functions +2. How to write a JSON RPC Server to resolve these oracle calls with Nargo +3. How to use them in Nargo and how to provide a custom resolver in NoirJS + +## Step 1 - Modify your Noir program + +An oracle is defined in a Noir program by defining two methods: + +- An unconstrained method - This tells the compiler that it is executing an [unconstrained functions](../noir/concepts//unconstrained.md). +- A decorated oracle method - This tells the compiler that this method is an RPC call. + +An example of an oracle that returns a `Field` would be: + +```rust +#[oracle(getSqrt)] +unconstrained fn sqrt(number: Field) -> Field { } + +unconstrained fn get_sqrt(number: Field) -> Field { + sqrt(number) +} +``` + +In this example, we're wrapping our oracle function in a unconstrained method, and decorating it with `oracle(getSqrt)`. We can then call the unconstrained function as we would call any other function: + +```rust +fn main(input: Field) { + let sqrt = get_sqrt(input); +} +``` + +In the next section, we will make this `getSqrt` (defined on the `sqrt` decorator) be a method of the RPC server Noir will use. + +:::danger + +As explained in the [Oracle Explainer](../explainers/explainer-oracle.md), this `main` function is unsafe unless you constrain its return value. For example: + +```rust +fn main(input: Field) { + let sqrt = get_sqrt(input); + assert(sqrt.pow_32(2) as u64 == input as u64); // <---- constrain the return of an oracle! +} +``` + +::: + +:::info + +Currently, oracles only work with single params or array params. For example: + +```rust +#[oracle(getSqrt)] +unconstrained fn sqrt([Field; 2]) -> [Field; 2] { } +``` + +::: + +## Step 2 - Write an RPC server + +Brillig will call *one* RPC server. Most likely you will have to write your own, and you can do it in whatever language you prefer. In this guide, we will do it in Javascript. + +Let's use the above example of an oracle that consumes an array with two `Field` and returns their square roots: + +```rust +#[oracle(getSqrt)] +unconstrained fn sqrt(input: [Field; 2]) -> [Field; 2] { } + +unconstrained fn get_sqrt(input: [Field; 2]) -> [Field; 2] { + sqrt(input) +} + +fn main(input: [Field; 2]) { + let sqrt = get_sqrt(input); + assert(sqrt[0].pow_32(2) as u64 == input[0] as u64); + assert(sqrt[1].pow_32(2) as u64 == input[1] as u64); +} +``` + +:::info + +Why square root? + +In general, computing square roots is computationally more expensive than multiplications, which takes a toll when speaking about ZK applications. In this case, instead of calculating the square root in Noir, we are using our oracle to offload that computation to be made in plain. In our circuit we can simply multiply the two values. + +::: + +Now, we should write the correspondent RPC server, starting with the [default JSON-RPC 2.0 boilerplate](https://www.npmjs.com/package/json-rpc-2.0#example): + +```js +import { JSONRPCServer } from "json-rpc-2.0"; +import express from "express"; +import bodyParser from "body-parser"; + +const app = express(); +app.use(bodyParser.json()); + +const server = new JSONRPCServer(); +app.post("/", (req, res) => { + const jsonRPCRequest = req.body; + server.receive(jsonRPCRequest).then((jsonRPCResponse) => { + if (jsonRPCResponse) { + res.json(jsonRPCResponse); + } else { + res.sendStatus(204); + } + }); +}); + +app.listen(5555); +``` + +Now, we will add our `getSqrt` method, as expected by the `#[oracle(getSqrt)]` decorator in our Noir code. It maps through the params array and returns their square roots: + +```js +server.addMethod("getSqrt", async (params) => { + const values = params[0].Array.map(({ inner }) => { + return { inner: `${Math.sqrt(parseInt(inner, 16))}` }; + }); + return { values: [{ Array: values }] }; +}); +``` + +:::tip + +Brillig expects an object with an array of values. Each value is an object declaring to be `Single` or `Array` and returning a `inner` property *as a string*. For example: + +```json +{ "values": [{ "Array": [{ "inner": "1" }, { "inner": "2"}]}]} +{ "values": [{ "Single": { "inner": "1" }}]} +{ "values": [{ "Single": { "inner": "1" }}, { "Array": [{ "inner": "1", { "inner": "2" }}]}]} +``` + +If you're using Typescript, the following types may be helpful in understanding the expected return value and making sure they're easy to follow: + +```js +interface Value { + inner: string, +} + +interface SingleForeignCallParam { + Single: Value, +} + +interface ArrayForeignCallParam { + Array: Value[], +} + +type ForeignCallParam = SingleForeignCallParam | ArrayForeignCallParam; + +interface ForeignCallResult { + values: ForeignCallParam[], +} +``` + +::: + +## Step 3 - Usage with Nargo + +Using the [`nargo` CLI tool](../getting_started/installation/index.md), you can use oracles in the `nargo test`, `nargo execute` and `nargo prove` commands by passing a value to `--oracle-resolver`. For example: + +```bash +nargo test --oracle-resolver http://localhost:5555 +``` + +This tells `nargo` to use your RPC Server URL whenever it finds an oracle decorator. + +## Step 4 - Usage with NoirJS + +In a JS environment, an RPC server is not strictly necessary, as you may want to resolve your oracles without needing any JSON call at all. NoirJS simply expects that you pass a callback function when you generate proofs, and that callback function can be anything. + +For example, if your Noir program expects the host machine to provide CPU pseudo-randomness, you could simply pass it as the `foreignCallHandler`. You don't strictly need to create an RPC server to serve pseudo-randomness, as you may as well get it directly in your app: + +```js +const foreignCallHandler = (name, inputs) => crypto.randomBytes(16) // etc + +await noir.generateProof(inputs, foreignCallHandler) +``` + +As one can see, in NoirJS, the [`foreignCallHandler`](../reference/NoirJS/noir_js/type-aliases/ForeignCallHandler.md) function simply means "a callback function that returns a value of type [`ForeignCallOutput`](../reference/NoirJS/noir_js/type-aliases/ForeignCallOutput.md). It doesn't have to be an RPC call like in the case for Nargo. + +:::tip + +Does this mean you don't have to write an RPC server like in [Step #2](#step-2---write-an-rpc-server)? + +You don't technically have to, but then how would you run `nargo test` or `nargo prove`? To use both `Nargo` and `NoirJS` in your development flow, you will have to write a JSON RPC server. + +::: + +In this case, let's make `foreignCallHandler` call the JSON RPC Server we created in [Step #2](#step-2---write-an-rpc-server), by making it a JSON RPC Client. + +For example, using the same `getSqrt` program in [Step #1](#step-1---modify-your-noir-program) (comments in the code): + +```js +import { JSONRPCClient } from "json-rpc-2.0"; + +// declaring the JSONRPCClient +const client = new JSONRPCClient((jsonRPCRequest) => { +// hitting the same JSON RPC Server we coded above + return fetch("http://localhost:5555", { + method: "POST", + headers: { + "content-type": "application/json", + }, + body: JSON.stringify(jsonRPCRequest), + }).then((response) => { + if (response.status === 200) { + return response + .json() + .then((jsonRPCResponse) => client.receive(jsonRPCResponse)); + } else if (jsonRPCRequest.id !== undefined) { + return Promise.reject(new Error(response.statusText)); + } + }); +}); + +// declaring a function that takes the name of the foreign call (getSqrt) and the inputs +const foreignCallHandler = async (name, input) => { + // notice that the "inputs" parameter contains *all* the inputs + // in this case we to make the RPC request with the first parameter "numbers", which would be input[0] + const oracleReturn = await client.request(name, [ + { Array: input[0].map((i) => ({ inner: i.toString("hex") })) }, + ]); + return [oracleReturn.values[0].Array.map((x) => x.inner)]; +}; + +// the rest of your NoirJS code +const input = { input: [4, 16] }; +const { witness } = await noir.execute(numbers, foreignCallHandler); +``` + +:::tip + +If you're in a NoirJS environment running your RPC server together with a frontend app, you'll probably hit a familiar problem in full-stack development: requests being blocked by [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) policy. For development only, you can simply install and use the [`cors` npm package](https://www.npmjs.com/package/cors) to get around the problem: + +```bash +yarn add cors +``` + +and use it as a middleware: + +```js +import cors from "cors"; + +const app = express(); +app.use(cors()) +``` + +::: + +## Conclusion + +Hopefully by the end of this guide, you should be able to: + +- Write your own logic around Oracles and how to write a JSON RPC server to make them work with your Nargo commands. +- Provide custom foreign call handlers for NoirJS. diff --git a/docs/versioned_docs/version-v0.25.0/how_to/how-to-recursion.md b/docs/versioned_docs/version-v0.25.0/how_to/how-to-recursion.md new file mode 100644 index 00000000000..4c45bb87ae2 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/how_to/how-to-recursion.md @@ -0,0 +1,179 @@ +--- +title: How to use recursion on NoirJS +description: Learn how to implement recursion with NoirJS, a powerful tool for creating smart contracts on the EVM blockchain. This guide assumes familiarity with NoirJS, solidity verifiers, and the Barretenberg proving backend. Discover how to generate both final and intermediate proofs using `noir_js` and `backend_barretenberg`. +keywords: + [ + "NoirJS", + "EVM blockchain", + "smart contracts", + "recursion", + "solidity verifiers", + "Barretenberg backend", + "noir_js", + "backend_barretenberg", + "intermediate proofs", + "final proofs", + "nargo compile", + "json import", + "recursive circuit", + "recursive app" + ] +sidebar_position: 1 +--- + +This guide shows you how to use recursive proofs in your NoirJS app. For the sake of clarity, it is assumed that: + +- You already have a NoirJS app. If you don't, please visit the [NoirJS tutorial](../tutorials/noirjs_app.md) and the [reference](../reference/NoirJS/noir_js/index.md). +- You are familiar with what are recursive proofs and you have read the [recursion explainer](../explainers/explainer-recursion.md) +- You already built a recursive circuit following [the reference](../noir/standard_library/recursion.md), and understand how it works. + +It is also assumed that you're not using `noir_wasm` for compilation, and instead you've used [`nargo compile`](../reference/nargo_commands.md) to generate the `json` you're now importing into your project. However, the guide should work just the same if you're using `noir_wasm`. + +:::info + +As you've read in the [explainer](../explainers/explainer-recursion.md), a recursive proof is an intermediate proof. This means that it doesn't necessarily generate the final step that makes it verifiable in a smart contract. However, it is easy to verify within another circuit. + +While "standard" usage of NoirJS packages abstracts final proofs, it currently lacks the necessary interface to abstract away intermediate proofs. This means that these proofs need to be created by using the backend directly. + +In short: + +- `noir_js` generates *only* final proofs +- `backend_barretenberg` generates both types of proofs + +::: + +In a standard recursive app, you're also dealing with at least two circuits. For the purpose of this guide, we will assume the following: + +- `main`: a circuit of type `assert(x != y)`, where `main` is marked with a `#[recursive]` attribute. This attribute states that the backend should generate proofs that are friendly for verification within another circuit. +- `recursive`: a circuit that verifies `main` + +For a full example on how recursive proofs work, please refer to the [noir-examples](https://github.com/noir-lang/noir-examples) repository. We will *not* be using it as a reference for this guide. + +## Step 1: Setup + +In a common NoirJS app, you need to instantiate a backend with something like `const backend = new Backend(circuit)`. Then you feed it to the `noir_js` interface. + +For recursion, this doesn't happen, and the only need for `noir_js` is only to `execute` a circuit and get its witness and return value. Everything else is not interfaced, so it needs to happen on the `backend` object. + +It is also recommended that you instantiate the backend with as many threads as possible, to allow for maximum concurrency: + +```js +const backend = new Backend(circuit, { threads: 8 }) +``` + +:::tip +You can use the [`os.cpus()`](https://nodejs.org/api/os.html#oscpus) object in `nodejs` or [`navigator.hardwareConcurrency`](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/hardwareConcurrency) on the browser to make the most out of those glorious cpu cores +::: + +## Step 2: Generating the witness and the proof for `main` + +After instantiating the backend, you should also instantiate `noir_js`. We will use it to execute the circuit and get the witness. + +```js +const noir = new Noir(circuit, backend) +const { witness } = noir.execute(input) +``` + +With this witness, you are now able to generate the intermediate proof for the main circuit: + +```js +const { proof, publicInputs } = await backend.generateProof(witness) +``` + +:::warning + +Always keep in mind what is actually happening on your development process, otherwise you'll quickly become confused about what circuit we are actually running and why! + +In this case, you can imagine that Alice (running the `main` circuit) is proving something to Bob (running the `recursive` circuit), and Bob is verifying her proof within his proof. + +With this in mind, it becomes clear that our intermediate proof is the one *meant to be verified within another circuit*, so it must be Alice's. Actually, the only final proof in this theoretical scenario would be the last one, sent on-chain. + +::: + +## Step 3 - Verification and proof artifacts + +Optionally, you are able to verify the intermediate proof: + +```js +const verified = await backend.verifyProof({ proof, publicInputs }) +``` + +This can be useful to make sure our intermediate proof was correctly generated. But the real goal is to do it within another circuit. For that, we need to generate recursive proof artifacts that will be passed to the circuit that is verifying the proof we just generated. Instead of passing the proof and verification key as a byte array, we pass them as fields which makes it cheaper to verify in a circuit: + +```js +const { proofAsFields, vkAsFields, vkHash } = await backend.generateRecursiveProofArtifacts( { publicInputs, proof }, publicInputsCount) +``` + +This call takes the public inputs and the proof, but also the public inputs count. While this is easily retrievable by simply counting the `publicInputs` length, the backend interface doesn't currently abstract it away. + +:::info + +The `proofAsFields` has a constant size `[Field; 93]` and verification keys in Barretenberg are always `[Field; 114]`. + +::: + +:::warning + +One common mistake is to forget *who* makes this call. + +In a situation where Alice is generating the `main` proof, if she generates the proof artifacts and sends them to Bob, which gladly takes them as true, this would mean Alice could prove anything! + +Instead, Bob needs to make sure *he* extracts the proof artifacts, using his own instance of the `main` circuit backend. This way, Alice has to provide a valid proof for the correct `main` circuit. + +::: + +## Step 4 - Recursive proof generation + +With the artifacts, generating a recursive proof is no different from a normal proof. You simply use the `backend` (with the recursive circuit) to generate it: + +```js +const recursiveInputs = { + verification_key: vkAsFields, // array of length 114 + proof: proofAsFields, // array of length 93 + size of public inputs + publicInputs: [mainInput.y], // using the example above, where `y` is the only public input + key_hash: vkHash, +} + +const { witness, returnValue } = noir.execute(recursiveInputs) // we're executing the recursive circuit now! +const { proof, publicInputs } = backend.generateProof(witness) +const verified = backend.verifyProof({ proof, publicInputs }) +``` + +You can obviously chain this proof into another proof. In fact, if you're using recursive proofs, you're probably interested of using them this way! + +:::tip + +Managing circuits and "who does what" can be confusing. To make sure your naming is consistent, you can keep them in an object. For example: + +```js +const circuits = { + main: mainJSON, + recursive: recursiveJSON +} +const backends = { + main: new BarretenbergBackend(circuits.main), + recursive: new BarretenbergBackend(circuits.recursive) +} +const noir_programs = { + main: new Noir(circuits.main, backends.main), + recursive: new Noir(circuits.recursive, backends.recursive) +} +``` + +This allows you to neatly call exactly the method you want without conflicting names: + +```js +// Alice runs this 👇 +const { witness: mainWitness } = await noir_programs.main.execute(input) +const proof = await backends.main.generateProof(mainWitness) + +// Bob runs this 👇 +const verified = await backends.main.verifyProof(proof) +const { proofAsFields, vkAsFields, vkHash } = await backends.main.generateRecursiveProofArtifacts( + proof, + numPublicInputs, +); +const recursiveProof = await noir_programs.recursive.generateProof(recursiveInputs) +``` + +::: diff --git a/docs/versioned_docs/version-v0.25.0/how_to/how-to-solidity-verifier.md b/docs/versioned_docs/version-v0.25.0/how_to/how-to-solidity-verifier.md new file mode 100644 index 00000000000..e3c7c1065da --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/how_to/how-to-solidity-verifier.md @@ -0,0 +1,231 @@ +--- +title: Generate a Solidity Verifier +description: + Learn how to run the verifier as a smart contract on the blockchain. Compile a Solidity verifier + contract for your Noir program and deploy it on any EVM blockchain acting as a verifier smart + contract. Read more to find out +keywords: + [ + solidity verifier, + smart contract, + blockchain, + compiler, + plonk_vk.sol, + EVM blockchain, + verifying Noir programs, + proving backend, + Barretenberg, + ] +sidebar_position: 0 +pagination_next: tutorials/noirjs_app +--- + +Noir has the ability to generate a verifier contract in Solidity, which can be deployed in many EVM-compatible blockchains such as Ethereum. + +This allows for a powerful feature set, as one can make use of the conciseness and the privacy provided by Noir in an immutable ledger. Applications can range from simple P2P guessing games, to complex private DeFi interactions. + +This guide shows you how to generate a Solidity Verifier and deploy it on the [Remix IDE](https://remix.ethereum.org/). It is assumed that: + +- You are comfortable with the Solidity programming language and understand how contracts are deployed on the Ethereum network +- You have Noir installed and you have a Noir program. If you don't, [get started](../getting_started/installation/index.md) with Nargo and the example Hello Noir circuit +- You are comfortable navigating RemixIDE. If you aren't or you need a refresher, you can find some video tutorials [here](https://www.youtube.com/channel/UCjTUPyFEr2xDGN6Cg8nKDaA) that could help you. + +## Rundown + +Generating a Solidity Verifier contract is actually a one-command process. However, compiling it and deploying it can have some caveats. Here's the rundown of this guide: + +1. How to generate a solidity smart contract +2. How to compile the smart contract in the RemixIDE +3. How to deploy it to a testnet + +## Step 1 - Generate a contract + +This is by far the most straight-forward step. Just run: + +```sh +nargo codegen-verifier +``` + +A new `contract` folder would then be generated in your project directory, containing the Solidity +file `plonk_vk.sol`. It can be deployed to any EVM blockchain acting as a verifier smart contract. + +:::info + +It is possible to generate verifier contracts of Noir programs for other smart contract platforms as long as the proving backend supplies an implementation. + +Barretenberg, the default proving backend for Nargo, supports generation of verifier contracts, for the time being these are only in Solidity. +::: + +## Step 2 - Compiling + +We will mostly skip the details of RemixIDE, as the UI can change from version to version. For now, we can just open +Remix and create a blank workspace. + +![Create Workspace](@site/static/img/how-tos/solidity_verifier_1.png) + +We will create a new file to contain the contract Nargo generated, and copy-paste its content. + +:::warning + +You'll likely see a warning advising you to not trust pasted code. While it is an important warning, it is irrelevant in the context of this guide and can be ignored. We will not be deploying anywhere near a mainnet. + +::: + +To compile our the verifier, we can navigate to the compilation tab: + +![Compilation Tab](@site/static/img/how-tos/solidity_verifier_2.png) + +Remix should automatically match a suitable compiler version. However, hitting the "Compile" button will most likely generate a "Stack too deep" error: + +![Stack too deep](@site/static/img/how-tos/solidity_verifier_3.png) + +This is due to the verify function needing to put many variables on the stack, but enabling the optimizer resolves the issue. To do this, let's open the "Advanced Configurations" tab and enable optimization. The default 200 runs will suffice. + +:::info + +This time we will see a warning about an unused function parameter. This is expected, as the `verify` function doesn't use the `_proof` parameter inside a solidity block, it is loaded from calldata and used in assembly. + +::: + +![Compilation success](@site/static/img/how-tos/solidity_verifier_4.png) + +## Step 3 - Deploying + +At this point we should have a compiled contract read to deploy. If we navigate to the deploy section in Remix, we will see many different environments we can deploy to. The steps to deploy on each environment would be out-of-scope for this guide, so we will just use the default Remix VM. + +Looking closely, we will notice that our "Solidity Verifier" is actually three contracts working together: + +- An `UltraVerificationKey` library which simply stores the verification key for our circuit. +- An abstract contract `BaseUltraVerifier` containing most of the verifying logic. +- A main `UltraVerifier` contract that inherits from the Base and uses the Key contract. + +Remix will take care of the dependencies for us so we can simply deploy the UltraVerifier contract by selecting it and hitting "deploy": + +![Deploying UltraVerifier](@site/static/img/how-tos/solidity_verifier_5.png) + +A contract will show up in the "Deployed Contracts" section, where we can retrieve the Verification Key Hash. This is particularly useful for double-checking the deployer contract is the correct one. + +:::note + +Why "UltraVerifier"? + +To be precise, the Noir compiler (`nargo`) doesn't generate the verifier contract directly. It compiles the Noir code into an intermediate language (ACIR), which is then executed by the backend. So it is the backend that returns the verifier smart contract, not Noir. + +In this case, the Barretenberg Backend uses the UltraPlonk proving system, hence the "UltraVerifier" name. + +::: + +## Step 4 - Verifying + +To verify a proof using the Solidity verifier contract, we call the `verify` function in this extended contract: + +```solidity +function verify(bytes calldata _proof, bytes32[] calldata _publicInputs) external view returns (bool) +``` + +When using the default example in the [Hello Noir](../getting_started/hello_noir/index.md) guide, the easiest way to confirm that the verifier contract is doing its job is by calling the `verify` function via remix with the required parameters. For `_proof`, run `nargo prove` and use the string in `proof/.proof` (adding the hex `0x` prefix). We can also copy the public input from `Verifier.toml`, as it will be properly formatted as 32-byte strings: + +``` +0x...... , [0x0000.....02] +``` + +A programmatic example of how the `verify` function is called can be seen in the example zk voting application [here](https://github.com/noir-lang/noir-examples/blob/33e598c257e2402ea3a6b68dd4c5ad492bce1b0a/foundry-voting/src/zkVote.sol#L35): + +```solidity +function castVote(bytes calldata proof, uint proposalId, uint vote, bytes32 nullifierHash) public returns (bool) { + // ... + bytes32[] memory publicInputs = new bytes32[](4); + publicInputs[0] = merkleRoot; + publicInputs[1] = bytes32(proposalId); + publicInputs[2] = bytes32(vote); + publicInputs[3] = nullifierHash; + require(verifier.verify(proof, publicInputs), "Invalid proof"); +``` + +:::info[Return Values] + +A circuit doesn't have the concept of a return value. Return values are just syntactic sugar in +Noir. + +Under the hood, the return value is passed as an input to the circuit and is checked at the end of +the circuit program. + +For example, if you have Noir program like this: + +```rust +fn main( + // Public inputs + pubkey_x: pub Field, + pubkey_y: pub Field, + // Private inputs + priv_key: Field, +) -> pub Field +``` + +the `verify` function will expect the public inputs array (second function parameter) to be of length 3, the two inputs and the return value. Like before, these values are populated in Verifier.toml after running `nargo prove`. + +Passing only two inputs will result in an error such as `PUBLIC_INPUT_COUNT_INVALID(3, 2)`. + +In this case, the inputs parameter to `verify` would be an array ordered as `[pubkey_x, pubkey_y, return]`. + +::: + +:::tip[Structs] + +You can pass structs to the verifier contract. They will be flattened so that the array of inputs is 1-dimensional array. + +For example, consider the following program: + +```rust +struct Type1 { + val1: Field, + val2: Field, +} + +struct Nested { + t1: Type1, + is_true: bool, +} + +fn main(x: pub Field, nested: pub Nested, y: pub Field) { + //... +} +``` + +The order of these inputs would be flattened to: `[x, nested.t1.val1, nested.t1.val2, nested.is_true, y]` + +::: + +The other function you can call is our entrypoint `verify` function, as defined above. + +:::tip + +It's worth noticing that the `verify` function is actually a `view` function. A `view` function does not alter the blockchain state, so it doesn't need to be distributed (i.e. it will run only on the executing node), and therefore doesn't cost any gas. + +This can be particularly useful in some situations. If Alice generated a proof and wants Bob to verify its correctness, Bob doesn't need to run Nargo, NoirJS, or any Noir specific infrastructure. He can simply make a call to the blockchain with the proof and verify it is correct without paying any gas. + +It would be incorrect to say that a Noir proof verification costs any gas at all. However, most of the time the result of `verify` is used to modify state (for example, to update a balance, a game state, etc). In that case the whole network needs to execute it, which does incur gas costs (calldata and execution, but not storage). + +::: + +## A Note on EVM chains + +ZK-SNARK verification depends on some precompiled cryptographic primitives such as Elliptic Curve Pairings (if you like complex math, you can read about EC Pairings [here](https://medium.com/@VitalikButerin/exploring-elliptic-curve-pairings-c73c1864e627)). Not all EVM chains support EC Pairings, notably some of the ZK-EVMs. This means that you won't be able to use the verifier contract in all of them. + +For example, chains like `zkSync ERA` and `Polygon zkEVM` do not currently support these precompiles, so proof verification via Solidity verifier contracts won't work. Here's a quick list of EVM chains that have been tested and are known to work: + +- Optimism +- Arbitrum +- Polygon PoS +- Scroll +- Celo + +If you test any other chains, please open a PR on this page to update the list. See [this doc](https://github.com/noir-lang/noir-starter/tree/main/with-foundry#testing-on-chain) for more info about testing verifier contracts on different EVM chains. + +## What's next + +Now that you know how to call a Noir Solidity Verifier on a smart contract using Remix, you should be comfortable with using it with some programmatic frameworks, such as [hardhat](https://github.com/noir-lang/noir-starter/tree/main/vite-hardhat) and [foundry](https://github.com/noir-lang/noir-starter/tree/main/with-foundry). + +You can find other tools, examples, boilerplates and libraries in the [awesome-noir](https://github.com/noir-lang/awesome-noir) repository. + +You should also be ready to write and deploy your first NoirJS app and start generating proofs on websites, phones, and NodeJS environments! Head on to the [NoirJS tutorial](../tutorials/noirjs_app.md) to learn how to do that. diff --git a/docs/versioned_docs/version-v0.25.0/how_to/merkle-proof.mdx b/docs/versioned_docs/version-v0.25.0/how_to/merkle-proof.mdx new file mode 100644 index 00000000000..34074659ac1 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/how_to/merkle-proof.mdx @@ -0,0 +1,48 @@ +--- +title: Prove Merkle Tree Membership +description: + Learn how to use merkle membership proof in Noir to prove that a given leaf is a member of a + merkle tree with a specified root, at a given index. +keywords: + [merkle proof, merkle membership proof, Noir, rust, hash function, Pedersen, sha256, merkle tree] +--- + +Let's walk through an example of a merkle membership proof in Noir that proves that a given leaf is +in a merkle tree. + +```rust +use dep::std; + +fn main(message : [Field; 62], index : Field, hashpath : [Field; 40], root : Field) { + let leaf = std::hash::hash_to_field(message); + let merkle_root = std::merkle::compute_merkle_root(leaf, index, hashpath); + assert(merkle_root == root); +} + +``` + +The message is hashed using `hash_to_field`. The specific hash function that is being used is chosen +by the backend. The only requirement is that this hash function can heuristically be used as a +random oracle. If only collision resistance is needed, then one can call `std::hash::pedersen_hash` +instead. + +```rust +let leaf = std::hash::hash_to_field(message); +``` + +The leaf is then passed to a compute_merkle_root function with the root, index and hashpath. The returned root can then be asserted to be the same as the provided root. + +```rust +let merkle_root = std::merkle::compute_merkle_root(leaf, index, hashpath); +assert (merkle_root == root); +``` + +> **Note:** It is possible to re-implement the merkle tree implementation without standard library. +> However, for most usecases, it is enough. In general, the standard library will always opt to be +> as conservative as possible, while striking a balance with efficiency. + +An example, the merkle membership proof, only requires a hash function that has collision +resistance, hence a hash function like Pedersen is allowed, which in most cases is more efficient +than the even more conservative sha256. + +[View an example on the starter repo](https://github.com/noir-lang/noir-examples/blob/3ea09545cabfa464124ec2f3ea8e60c608abe6df/stealthdrop/circuits/src/main.nr#L20) diff --git a/docs/versioned_docs/version-v0.25.0/how_to/using-devcontainers.mdx b/docs/versioned_docs/version-v0.25.0/how_to/using-devcontainers.mdx new file mode 100644 index 00000000000..727ec6ca667 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/how_to/using-devcontainers.mdx @@ -0,0 +1,110 @@ +--- +title: Developer Containers and Codespaces +description: "Learn how to set up a devcontainer in your GitHub repository for a seamless coding experience with Codespaces. Follow our easy 8-step guide to create your own Noir environment without installing Nargo locally." +keywords: ["Devcontainer", "Codespaces", "GitHub", "Noir Environment", "Docker Image", "Development Environment", "Remote Coding", "GitHub Codespaces", "Noir Programming", "Nargo", "VSCode Extensions", "Noirup"] +sidebar_position: 1 +--- + +Adding a developer container configuration file to your Noir project is one of the easiest way to unlock coding in browser. + +## What's a devcontainer after all? + +A [Developer Container](https://containers.dev/) (devcontainer for short) is a Docker image that comes preloaded with tools, extensions, and other tools you need to quickly get started or continue a project, without having to install Nargo locally. Think of it as a development environment in a box. + +There are many advantages to this: + +- It's platform and architecture agnostic +- You don't need to have an IDE installed, or Nargo, or use a terminal at all +- It's safer for using on a public machine or public network + +One of the best ways of using devcontainers is... not using your machine at all, for maximum control, performance, and ease of use. +Enter Codespaces. + +## Codespaces + +If a devcontainer is just a Docker image, then what stops you from provisioning a `p3dn.24xlarge` AWS EC2 instance with 92 vCPUs and 768 GiB RAM and using it to prove your 10-gate SNARK proof? + +Nothing! Except perhaps the 30-40$ per hour it will cost you. + +The problem is that provisioning takes time, and I bet you don't want to see the AWS console every time you want to code something real quick. + +Fortunately, there's an easy and free way to get a decent remote machine ready and loaded in less than 2 minutes: Codespaces. [Codespaces is a Github feature](https://github.com/features/codespaces) that allows you to code in a remote machine by using devcontainers, and it's pretty cool: + +- You can start coding Noir in less than a minute +- It uses the resources of a remote machine, so you can code on your grandma's phone if needed be +- It makes it easy to share work with your frens +- It's fully reusable, you can stop and restart whenever you need to + +:::info + +Don't take out your wallet just yet. Free GitHub accounts get about [15-60 hours of coding](https://github.com/features/codespaces) for free per month, depending on the size of your provisioned machine. + +::: + +## Tell me it's _actually_ easy + +It is! + +Github comes with a default codespace and you can use it to code your own devcontainer. That's exactly what we will be doing in this guide. + + + +8 simple steps: + +#### 1. Create a new repository on GitHub. + +#### 2. Click "Start coding with Codespaces". This will use the default image. + +#### 3. Create a folder called `.devcontainer` in the root of your repository. + +#### 4. Create a Dockerfile in that folder, and paste the following code: + +```docker +FROM --platform=linux/amd64 node:lts-bookworm-slim +SHELL ["/bin/bash", "-c"] +RUN apt update && apt install -y curl bash git tar gzip libc++-dev +RUN curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash +ENV PATH="/root/.nargo/bin:$PATH" +RUN noirup +ENTRYPOINT ["nargo"] +``` +#### 5. Create a file called `devcontainer.json` in the same folder, and paste the following code: + +```json +{ + "name": "Noir on Codespaces", + "build": { + "context": ".", + "dockerfile": "Dockerfile" + }, + "customizations": { + "vscode": { + "extensions": ["noir-lang.vscode-noir"] + } + } +} +``` +#### 6. Commit and push your changes + +This will pull the new image and build it, so it could take a minute or so + +#### 8. Done! +Just wait for the build to finish, and there's your easy Noir environment. + + +Refer to [noir-starter](https://github.com/noir-lang/noir-starter/) as an example of how devcontainers can be used together with codespaces. + + + +## How do I use it? + +Using the codespace is obviously much easier than setting it up. +Just navigate to your repository and click "Code" -> "Open with Codespaces". It should take a few seconds to load, and you're ready to go. + +:::info + +If you really like the experience, you can add a badge to your readme, links to existing codespaces, and more. +Check out the [official docs](https://docs.github.com/en/codespaces/setting-up-your-project-for-codespaces/setting-up-your-repository/facilitating-quick-creation-and-resumption-of-codespaces) for more info. diff --git a/docs/versioned_docs/version-v0.25.0/index.mdx b/docs/versioned_docs/version-v0.25.0/index.mdx new file mode 100644 index 00000000000..75086ddcdde --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/index.mdx @@ -0,0 +1,67 @@ +--- +title: Noir Lang +hide_title: true +description: + Learn about the public alpha release of Noir, a domain specific language heavily influenced by Rust that compiles to + an intermediate language which can be compiled to an arithmetic circuit or a rank-1 constraint system. +keywords: + [Noir, + Domain Specific Language, + Rust, + Intermediate Language, + Arithmetic Circuit, + Rank-1 Constraint System, + Ethereum Developers, + Protocol Developers, + Blockchain Developers, + Proving System, + Smart Contract Language] +sidebar_position: 0 +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +Noir Logo + +Noir is a Domain-Specific Language for SNARK proving systems developed by [Aztec Labs](https://aztec.network/). It allows you to generate complex Zero-Knowledge Programs (ZKP) by using simple and flexible syntax, requiring no previous knowledge on the underlying mathematics or cryptography. + +ZK programs are programs that can generate short proofs of a certain statement without revealing some details about it. You can read more about ZKPs [here](https://dev.to/spalladino/a-beginners-intro-to-coding-zero-knowledge-proofs-c56). + +## What's new about Noir? + +Noir works differently from most ZK languages by taking a two-pronged path. First, it compiles the program to an adaptable intermediate language known as ACIR. From there, depending on a given project's needs, ACIR can be further compiled into an arithmetic circuit for integration with the proving backend. + +:::info + +Noir is backend agnostic, which means it makes no assumptions on which proving backend powers the ZK proof. Being the language that powers [Aztec Contracts](https://docs.aztec.network/developers/contracts/main), it defaults to Aztec's Barretenberg proving backend. + +However, the ACIR output can be transformed to be compatible with other PLONK-based backends, or into a [rank-1 constraint system](https://www.rareskills.io/post/rank-1-constraint-system) suitable for backends such as Arkwork's Marlin. + +::: + +## Who is Noir for? + +Noir can be used both in complex cloud-based backends and in user's smartphones, requiring no knowledge on the underlying math or cryptography. From authorization systems that keep a password in the user's device, to complex on-chain verification of recursive proofs, Noir is designed to abstract away complexity without any significant overhead. Here are some examples of situations where Noir can be used: + + + + Noir Logo + + Aztec Contracts leverage Noir to allow for the storage and execution of private information. Writing an Aztec Contract is as easy as writing Noir, and Aztec developers can easily interact with the network storage and execution through the [Aztec.nr](https://docs.aztec.network/developers/contracts/main) library. + + + Soliditry Verifier Example + Noir can auto-generate Solidity verifier contracts that verify Noir proofs. This allows for non-interactive verification of proofs containing private information in an immutable system. This feature powers a multitude of use-case scenarios, from P2P chess tournaments, to [Aztec Layer-2 Blockchain](https://docs.aztec.network/) + + + Aztec Labs developed NoirJS, an easy interface to generate and verify Noir proofs in a Javascript environment. This allows for Noir to be used in webpages, mobile apps, games, and any other environment supporting JS execution in a standalone manner. + + + + +## Libraries + +Noir is meant to be easy to extend by simply importing Noir libraries just like in Rust. +The [awesome-noir repo](https://github.com/noir-lang/awesome-noir#libraries) is a collection of libraries developed by the Noir community. +Writing a new library is easy and makes code be composable and easy to reuse. See the section on [dependencies](noir/modules_packages_crates/dependencies.md) for more information. diff --git a/docs/versioned_docs/version-v0.25.0/migration_notes.md b/docs/versioned_docs/version-v0.25.0/migration_notes.md new file mode 100644 index 00000000000..6bd740024e5 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/migration_notes.md @@ -0,0 +1,105 @@ +--- +title: Migration notes +description: Read about migration notes from previous versions, which could solve problems while updating +keywords: [Noir, notes, migration, updating, upgrading] +--- + +Noir is in full-speed development. Things break fast, wild, and often. This page attempts to leave some notes on errors you might encounter when upgrading and how to resolve them until proper patches are built. + +### `backend encountered an error: libc++.so.1` + +Depending on your OS, you may encounter the following error when running `nargo prove` for the first time: + +```text +The backend encountered an error: "/home/codespace/.nargo/backends/acvm-backend-barretenberg/backend_binary: error while loading shared libraries: libc++.so.1: cannot open shared object file: No such file or directory\n" +``` + +Install the `libc++-dev` library with: + +```bash +sudo apt install libc++-dev +``` + +## ≥0.19 + +### Enforcing `compiler_version` + +From this version on, the compiler will check for the `compiler_version` field in `Nargo.toml`, and will error if it doesn't match the current Nargo version in use. + +To update, please make sure this field in `Nargo.toml` matches the output of `nargo --version`. + +## ≥0.14 + +The index of the [for loops](noir/concepts/control_flow.md#loops) is now of type `u64` instead of `Field`. An example refactor would be: + +```rust +for i in 0..10 { + let i = i as Field; +} +``` + +## ≥v0.11.0 and Nargo backend + +From this version onwards, Nargo starts managing backends through the `nargo backend` command. Upgrading to the versions per usual steps might lead to: + +### `backend encountered an error` + +This is likely due to the existing locally installed version of proving backend (e.g. barretenberg) is incompatible with the version of Nargo in use. + +To fix the issue: + +1. Uninstall the existing backend + +```bash +nargo backend uninstall acvm-backend-barretenberg +``` + +You may replace _acvm-backend-barretenberg_ with the name of your backend listed in `nargo backend ls` or in ~/.nargo/backends. + +2. Reinstall a compatible version of the proving backend. + +If you are using the default barretenberg backend, simply run: + +``` +nargo prove +``` + +with your Noir program. + +This will trigger the download and installation of the latest version of barretenberg compatible with your Nargo in use. + +### `backend encountered an error: illegal instruction` + +On certain Intel-based systems, an `illegal instruction` error may arise due to incompatibility of barretenberg with certain CPU instructions. + +To fix the issue: + +1. Uninstall the existing backend + +```bash +nargo backend uninstall acvm-backend-barretenberg +``` + +You may replace _acvm-backend-barretenberg_ with the name of your backend listed in `nargo backend ls` or in ~/.nargo/backends. + +2. Reinstall a compatible version of the proving backend. + +If you are using the default barretenberg backend, simply run: + +``` +nargo backend install acvm-backend-barretenberg https://github.com/noir-lang/barretenberg-js-binary/raw/master/run-bb.tar.gz +``` + +This downloads and installs a specific bb.js based version of barretenberg binary from GitHub. + +The gzipped file is running [this bash script](https://github.com/noir-lang/barretenberg-js-binary/blob/master/run-bb-js.sh), where we need to gzip it as the Nargo currently expect the backend to be zipped up. + +Then run: + +``` +DESIRED_BINARY_VERSION=0.8.1 nargo info +``` + +This overrides the bb native binary with a bb.js node application instead, which should be compatible with most if not all hardware. This does come with the drawback of being generally slower than native binary. + +0.8.1 indicates bb.js version 0.8.1, so if you change that it will update to a different version or the default version in the script if none was supplied. diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/_category_.json b/docs/versioned_docs/version-v0.25.0/noir/concepts/_category_.json new file mode 100644 index 00000000000..7da08f8a8c5 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/_category_.json @@ -0,0 +1,6 @@ +{ + "label": "Concepts", + "position": 0, + "collapsible": true, + "collapsed": true +} \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/assert.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/assert.md new file mode 100644 index 00000000000..bcff613a695 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/assert.md @@ -0,0 +1,45 @@ +--- +title: Assert Function +description: + Learn about the assert function in Noir, which can be used to explicitly constrain the predicate or + comparison expression that follows to be true, and what happens if the expression is false at + runtime. +keywords: [Noir programming language, assert statement, predicate expression, comparison expression] +sidebar_position: 4 +--- + +Noir includes a special `assert` function which will explicitly constrain the predicate/comparison +expression that follows to be true. If this expression is false at runtime, the program will fail to +be proven. Example: + +```rust +fn main(x : Field, y : Field) { + assert(x == y); +} +``` + +> Assertions only work for predicate operations, such as `==`. If there's any ambiguity on the operation, the program will fail to compile. For example, it is unclear if `assert(x + y)` would check for `x + y == 0` or simply would return `true`. + +You can optionally provide a message to be logged when the assertion fails: + +```rust +assert(x == y, "x and y are not equal"); +``` + +Aside string literals, the optional message can be a format string or any other type supported as input for Noir's [print](../standard_library/logging.md) functions. This feature lets you incorporate runtime variables into your failed assertion logs: + +```rust +assert(x == y, f"Expected x == y, but got {x} == {y}"); +``` + +Using a variable as an assertion message directly: + +```rust +struct myStruct { + myField: Field +} + +let s = myStruct { myField: y }; +assert(s.myField == x, s); +``` + diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/comments.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/comments.md new file mode 100644 index 00000000000..b51a85f5c94 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/comments.md @@ -0,0 +1,33 @@ +--- +title: Comments +description: + Learn how to write comments in Noir programming language. A comment is a line of code that is + ignored by the compiler, but it can be read by programmers. Single-line and multi-line comments + are supported in Noir. +keywords: [Noir programming language, comments, single-line comments, multi-line comments] +sidebar_position: 10 +--- + +A comment is a line in your codebase which the compiler ignores, however it can be read by +programmers. + +Here is a single line comment: + +```rust +// This is a comment and is ignored +``` + +`//` is used to tell the compiler to ignore the rest of the line. + +Noir also supports multi-line block comments. Start a block comment with `/*` and end the block with `*/`. + +Noir does not natively support doc comments. You may be able to use [Rust doc comments](https://doc.rust-lang.org/reference/comments.html) in your code to leverage some Rust documentation build tools with Noir code. + +```rust +/* + This is a block comment describing a complex function. +*/ +fn main(x : Field, y : pub Field) { + assert(x != y); +} +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/control_flow.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/control_flow.md new file mode 100644 index 00000000000..4ce65236db3 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/control_flow.md @@ -0,0 +1,45 @@ +--- +title: Control Flow +description: + Learn how to use loops and if expressions in the Noir programming language. Discover the syntax + and examples for for loops and if-else statements. +keywords: [Noir programming language, loops, for loop, if-else statements, Rust syntax] +sidebar_position: 2 +--- + +## Loops + +Noir has one kind of loop: the `for` loop. `for` loops allow you to repeat a block of code multiple +times. + +The following block of code between the braces is run 10 times. + +```rust +for i in 0..10 { + // do something +}; +``` + +The index for loops is of type `u64`. + +## If Expressions + +Noir supports `if-else` statements. The syntax is most similar to Rust's where it is not required +for the statement's conditional to be surrounded by parentheses. + +```rust +let a = 0; +let mut x: u32 = 0; + +if a == 0 { + if a != 0 { + x = 6; + } else { + x = 2; + } +} else { + x = 5; + assert(x == 5); +} +assert(x == 2); +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/data_bus.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_bus.md new file mode 100644 index 00000000000..e54fc861257 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_bus.md @@ -0,0 +1,21 @@ +--- +title: Data Bus +sidebar_position: 13 +--- +**Disclaimer** this feature is experimental, do not use it! + +The data bus is an optimization that the backend can use to make recursion more efficient. +In order to use it, you must define some inputs of the program entry points (usually the `main()` +function) with the `call_data` modifier, and the return values with the `return_data` modifier. +These modifiers are incompatible with `pub` and `mut` modifiers. + +## Example + +```rust +fn main(mut x: u32, y: call_data u32, z: call_data [u32;4] ) -> return_data u32 { + let a = z[x]; + a+y +} +``` + +As a result, both call_data and return_data will be treated as private inputs and encapsulated into a read-only array each, for the backend to process. diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/_category_.json b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/_category_.json new file mode 100644 index 00000000000..5d694210bbf --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/_category_.json @@ -0,0 +1,5 @@ +{ + "position": 0, + "collapsible": true, + "collapsed": true +} diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/arrays.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/arrays.md new file mode 100644 index 00000000000..a8bd338e736 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/arrays.md @@ -0,0 +1,251 @@ +--- +title: Arrays +description: + Dive into the Array data type in Noir. Grasp its methods, practical examples, and best practices for efficiently using Arrays in your Noir code. +keywords: + [ + noir, + array type, + methods, + examples, + indexing, + ] +sidebar_position: 4 +--- + +An array is one way of grouping together values into one compound type. Array types can be inferred +or explicitly specified via the syntax `[; ]`: + +```rust +fn main(x : Field, y : Field) { + let my_arr = [x, y]; + let your_arr: [Field; 2] = [x, y]; +} +``` + +Here, both `my_arr` and `your_arr` are instantiated as an array containing two `Field` elements. + +Array elements can be accessed using indexing: + +```rust +fn main() { + let a = [1, 2, 3, 4, 5]; + + let first = a[0]; + let second = a[1]; +} +``` + +All elements in an array must be of the same type (i.e. homogeneous). That is, an array cannot group +a `Field` value and a `u8` value together for example. + +You can write mutable arrays, like: + +```rust +fn main() { + let mut arr = [1, 2, 3, 4, 5]; + assert(arr[0] == 1); + + arr[0] = 42; + assert(arr[0] == 42); +} +``` + +You can instantiate a new array of a fixed size with the same value repeated for each element. The following example instantiates an array of length 32 where each element is of type Field and has the value 0. + +```rust +let array: [Field; 32] = [0; 32]; +``` + +Like in Rust, arrays in Noir are a fixed size. However, if you wish to convert an array to a [slice](./slices), you can just call `as_slice` on your array: + +```rust +let array: [Field; 32] = [0; 32]; +let sl = array.as_slice() +``` + +You can define multidimensional arrays: + +```rust +let array : [[Field; 2]; 2]; +let element = array[0][0]; +``` +However, multidimensional slices are not supported. For example, the following code will error at compile time: +```rust +let slice : [[Field]] = []; +``` + +## Types + +You can create arrays of primitive types or structs. There is not yet support for nested arrays +(arrays of arrays) or arrays of structs that contain arrays. + +## Methods + +For convenience, the STD provides some ready-to-use, common methods for arrays. +Each of these functions are located within the generic impl `impl [T; N] {`. +So anywhere `self` appears, it refers to the variable `self: [T; N]`. + +### len + +Returns the length of an array + +```rust +fn len(self) -> Field +``` + +example + +```rust +fn main() { + let array = [42, 42]; + assert(array.len() == 2); +} +``` + +### sort + +Returns a new sorted array. The original array remains untouched. Notice that this function will +only work for arrays of fields or integers, not for any arbitrary type. This is because the sorting +logic it uses internally is optimized specifically for these values. If you need a sort function to +sort any type, you should use the function `sort_via` described below. + +```rust +fn sort(self) -> [T; N] +``` + +example + +```rust +fn main() { + let arr = [42, 32]; + let sorted = arr.sort(); + assert(sorted == [32, 42]); +} +``` + +### sort_via + +Sorts the array with a custom comparison function + +```rust +fn sort_via(self, ordering: fn(T, T) -> bool) -> [T; N] +``` + +example + +```rust +fn main() { + let arr = [42, 32] + let sorted_ascending = arr.sort_via(|a, b| a < b); + assert(sorted_ascending == [32, 42]); // verifies + + let sorted_descending = arr.sort_via(|a, b| a > b); + assert(sorted_descending == [32, 42]); // does not verify +} +``` + +### map + +Applies a function to each element of the array, returning a new array containing the mapped elements. + +```rust +fn map(self, f: fn(T) -> U) -> [U; N] +``` + +example + +```rust +let a = [1, 2, 3]; +let b = a.map(|a| a * 2); // b is now [2, 4, 6] +``` + +### fold + +Applies a function to each element of the array, returning the final accumulated value. The first +parameter is the initial value. + +```rust +fn fold(self, mut accumulator: U, f: fn(U, T) -> U) -> U +``` + +This is a left fold, so the given function will be applied to the accumulator and first element of +the array, then the second, and so on. For a given call the expected result would be equivalent to: + +```rust +let a1 = [1]; +let a2 = [1, 2]; +let a3 = [1, 2, 3]; + +let f = |a, b| a - b; +a1.fold(10, f) //=> f(10, 1) +a2.fold(10, f) //=> f(f(10, 1), 2) +a3.fold(10, f) //=> f(f(f(10, 1), 2), 3) +``` + +example: + +```rust + +fn main() { + let arr = [2, 2, 2, 2, 2]; + let folded = arr.fold(0, |a, b| a + b); + assert(folded == 10); +} + +``` + +### reduce + +Same as fold, but uses the first element as starting element. + +```rust +fn reduce(self, f: fn(T, T) -> T) -> T +``` + +example: + +```rust +fn main() { + let arr = [2, 2, 2, 2, 2]; + let reduced = arr.reduce(|a, b| a + b); + assert(reduced == 10); +} +``` + +### all + +Returns true if all the elements satisfy the given predicate + +```rust +fn all(self, predicate: fn(T) -> bool) -> bool +``` + +example: + +```rust +fn main() { + let arr = [2, 2, 2, 2, 2]; + let all = arr.all(|a| a == 2); + assert(all); +} +``` + +### any + +Returns true if any of the elements satisfy the given predicate + +```rust +fn any(self, predicate: fn(T) -> bool) -> bool +``` + +example: + +```rust +fn main() { + let arr = [2, 2, 2, 2, 5]; + let any = arr.any(|a| a == 5); + assert(any); +} + +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/booleans.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/booleans.md new file mode 100644 index 00000000000..69826fcd724 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/booleans.md @@ -0,0 +1,31 @@ +--- +title: Booleans +description: + Delve into the Boolean data type in Noir. Understand its methods, practical examples, and best practices for using Booleans in your Noir programs. +keywords: + [ + noir, + boolean type, + methods, + examples, + logical operations, + ] +sidebar_position: 2 +--- + + +The `bool` type in Noir has two possible values: `true` and `false`: + +```rust +fn main() { + let t = true; + let f: bool = false; +} +``` + +> **Note:** When returning a boolean value, it will show up as a value of 1 for `true` and 0 for +> `false` in _Verifier.toml_. + +The boolean type is most commonly used in conditionals like `if` expressions and `assert` +statements. More about conditionals is covered in the [Control Flow](../control_flow) and +[Assert Function](../assert) sections. diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/fields.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/fields.md new file mode 100644 index 00000000000..99b4aa63549 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/fields.md @@ -0,0 +1,192 @@ +--- +title: Fields +description: + Dive deep into the Field data type in Noir. Understand its methods, practical examples, and best practices to effectively use Fields in your Noir programs. +keywords: + [ + noir, + field type, + methods, + examples, + best practices, + ] +sidebar_position: 0 +--- + +The field type corresponds to the native field type of the proving backend. + +The size of a Noir field depends on the elliptic curve's finite field for the proving backend +adopted. For example, a field would be a 254-bit integer when paired with the default backend that +spans the Grumpkin curve. + +Fields support integer arithmetic and are often used as the default numeric type in Noir: + +```rust +fn main(x : Field, y : Field) { + let z = x + y; +} +``` + +`x`, `y` and `z` are all private fields in this example. Using the `let` keyword we defined a new +private value `z` constrained to be equal to `x + y`. + +If proving efficiency is of priority, fields should be used as a default for solving problems. +Smaller integer types (e.g. `u64`) incur extra range constraints. + +## Methods + +After declaring a Field, you can use these common methods on it: + +### to_le_bits + +Transforms the field into an array of bits, Little Endian. + +```rust +fn to_le_bits(_x : Field, _bit_size: u32) -> [u1; N] +``` + +example: + +```rust +fn main() { + let field = 2; + let bits = field.to_le_bits(32); +} +``` + +### to_be_bits + +Transforms the field into an array of bits, Big Endian. + +```rust +fn to_be_bits(_x : Field, _bit_size: u32) -> [u1; N] +``` + +example: + +```rust +fn main() { + let field = 2; + let bits = field.to_be_bits(32); +} +``` + +### to_le_bytes + +Transforms into an array of bytes, Little Endian + +```rust +fn to_le_bytes(_x : Field, byte_size: u32) -> [u8] +``` + +example: + +```rust +fn main() { + let field = 2; + let bytes = field.to_le_bytes(4); +} +``` + +### to_be_bytes + +Transforms into an array of bytes, Big Endian + +```rust +fn to_be_bytes(_x : Field, byte_size: u32) -> [u8] +``` + +example: + +```rust +fn main() { + let field = 2; + let bytes = field.to_be_bytes(4); +} +``` + +### to_le_radix + +Decomposes into a vector over the specified base, Little Endian + +```rust +fn to_le_radix(_x : Field, _radix: u32, _result_len: u32) -> [u8] +``` + +example: + +```rust +fn main() { + let field = 2; + let radix = field.to_le_radix(256, 4); +} +``` + +### to_be_radix + +Decomposes into a vector over the specified base, Big Endian + +```rust +fn to_be_radix(_x : Field, _radix: u32, _result_len: u32) -> [u8] +``` + +example: + +```rust +fn main() { + let field = 2; + let radix = field.to_be_radix(256, 4); +} +``` + +### pow_32 + +Returns the value to the power of the specified exponent + +```rust +fn pow_32(self, exponent: Field) -> Field +``` + +example: + +```rust +fn main() { + let field = 2 + let pow = field.pow_32(4); + assert(pow == 16); +} +``` + +### assert_max_bit_size + +Adds a constraint to specify that the field can be represented with `bit_size` number of bits + +```rust +fn assert_max_bit_size(self, bit_size: u32) +``` + +example: + +```rust +fn main() { + let field = 2 + field.assert_max_bit_size(32); +} +``` + +### sgn0 + +Parity of (prime) Field element, i.e. sgn0(x mod p) = 0 if x ∈ \{0, ..., p-1\} is even, otherwise sgn0(x mod p) = 1. + +```rust +fn sgn0(self) -> u1 +``` + + +### lt + +Returns true if the field is less than the other field + +```rust +pub fn lt(self, another: Field) -> bool +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/function_types.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/function_types.md new file mode 100644 index 00000000000..f6121af17e2 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/function_types.md @@ -0,0 +1,26 @@ +--- +title: Function types +sidebar_position: 10 +--- + +Noir supports higher-order functions. The syntax for a function type is as follows: + +```rust +fn(arg1_type, arg2_type, ...) -> return_type +``` + +Example: + +```rust +fn assert_returns_100(f: fn() -> Field) { // f takes no args and returns a Field + assert(f() == 100); +} + +fn main() { + assert_returns_100(|| 100); // ok + assert_returns_100(|| 150); // fails +} +``` + +A function type also has an optional capture environment - this is necessary to support closures. +See [Lambdas](../lambdas.md) for more details. diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/index.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/index.md new file mode 100644 index 00000000000..357813c147a --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/index.md @@ -0,0 +1,110 @@ +--- +title: Data Types +description: + Get a clear understanding of the two categories of Noir data types - primitive types and compound + types. Learn about their characteristics, differences, and how to use them in your Noir + programming. +keywords: + [ + noir, + data types, + primitive types, + compound types, + private types, + public types, + ] +--- + +Every value in Noir has a type, which determines which operations are valid for it. + +All values in Noir are fundamentally composed of `Field` elements. For a more approachable +developing experience, abstractions are added on top to introduce different data types in Noir. + +Noir has two category of data types: primitive types (e.g. `Field`, integers, `bool`) and compound +types that group primitive types (e.g. arrays, tuples, structs). Each value can either be private or +public. + +## Private & Public Types + +A **private value** is known only to the Prover, while a **public value** is known by both the +Prover and Verifier. Mark values as `private` when the value should only be known to the prover. All +primitive types (including individual fields of compound types) in Noir are private by default, and +can be marked public when certain values are intended to be revealed to the Verifier. + +> **Note:** For public values defined in Noir programs paired with smart contract verifiers, once +> the proofs are verified on-chain the values can be considered known to everyone that has access to +> that blockchain. + +Public data types are treated no differently to private types apart from the fact that their values +will be revealed in proofs generated. Simply changing the value of a public type will not change the +circuit (where the same goes for changing values of private types as well). + +_Private values_ are also referred to as _witnesses_ sometimes. + +> **Note:** The terms private and public when applied to a type (e.g. `pub Field`) have a different +> meaning than when applied to a function (e.g. `pub fn foo() {}`). +> +> The former is a visibility modifier for the Prover to interpret if a value should be made known to +> the Verifier, while the latter is a visibility modifier for the compiler to interpret if a +> function should be made accessible to external Noir programs like in other languages. + +### pub Modifier + +All data types in Noir are private by default. Types are explicitly declared as public using the +`pub` modifier: + +```rust +fn main(x : Field, y : pub Field) -> pub Field { + x + y +} +``` + +In this example, `x` is **private** while `y` and `x + y` (the return value) are **public**. Note +that visibility is handled **per variable**, so it is perfectly valid to have one input that is +private and another that is public. + +> **Note:** Public types can only be declared through parameters on `main`. + +## Type Aliases + +A type alias is a new name for an existing type. Type aliases are declared with the keyword `type`: + +```rust +type Id = u8; + +fn main() { + let id: Id = 1; + let zero: u8 = 0; + assert(zero + 1 == id); +} +``` + +Type aliases can also be used with [generics](../generics.md): + +```rust +type Id = Size; + +fn main() { + let id: Id = 1; + let zero: u32 = 0; + assert(zero + 1 == id); +} +``` + +Type aliases can even refer to other aliases. An error will be issued if they form a cycle: + +```rust +// Ok! +type A = B; +type B = Field; + +type Bad1 = Bad2; + +// error: Dependency cycle found +type Bad2 = Bad1; +// ^^^^^^^^^^^ 'Bad2' recursively depends on itself: Bad2 -> Bad1 -> Bad2 +``` + +### BigInt + +You can achieve BigInt functionality using the [Noir BigInt](https://github.com/shuklaayush/noir-bigint) library. diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/integers.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/integers.md new file mode 100644 index 00000000000..4d58d96fed5 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/integers.md @@ -0,0 +1,155 @@ +--- +title: Integers +description: Explore the Integer data type in Noir. Learn about its methods, see real-world examples, and grasp how to efficiently use Integers in your Noir code. +keywords: [noir, integer types, methods, examples, arithmetic] +sidebar_position: 1 +--- + +An integer type is a range constrained field type. The Noir frontend supports both unsigned and signed integer types. The allowed sizes are 1, 8, 32 and 64 bits. + +:::info + +When an integer is defined in Noir without a specific type, it will default to `Field`. + +The one exception is for loop indices which default to `u64` since comparisons on `Field`s are not possible. + +::: + +## Unsigned Integers + +An unsigned integer type is specified first with the letter `u` (indicating its unsigned nature) followed by its bit size (e.g. `8`): + +```rust +fn main() { + let x: u8 = 1; + let y: u8 = 1; + let z = x + y; + assert (z == 2); +} +``` + +The bit size determines the maximum value the integer type can store. For example, a `u8` variable can store a value in the range of 0 to 255 (i.e. $\\2^{8}-1\\$). + +## Signed Integers + +A signed integer type is specified first with the letter `i` (which stands for integer) followed by its bit size (e.g. `8`): + +```rust +fn main() { + let x: i8 = -1; + let y: i8 = -1; + let z = x + y; + assert (z == -2); +} +``` + +The bit size determines the maximum and minimum range of value the integer type can store. For example, an `i8` variable can store a value in the range of -128 to 127 (i.e. $\\-2^{7}\\$ to $\\2^{7}-1\\$). + +## 128 bits Unsigned Integers + +The built-in structure `U128` allows you to use 128-bit unsigned integers almost like a native integer type. However, there are some differences to keep in mind: +- You cannot cast between a native integer and `U128` +- There is a higher performance cost when using `U128`, compared to a native type. + +Conversion between unsigned integer types and U128 are done through the use of `from_integer` and `to_integer` functions. + +```rust +fn main() { + let x = U128::from_integer(23); + let y = U128::from_hex("0x7"); + let z = x + y; + assert(z.to_integer() == 30); +} +``` + +`U128` is implemented with two 64 bits limbs, representing the low and high bits, which explains the performance cost. You should expect `U128` to be twice more costly for addition and four times more costly for multiplication. +You can construct a U128 from its limbs: +```rust +fn main(x: u64, y: u64) { + let x = U128::from_u64s_be(x,y); + assert(z.hi == x as Field); + assert(z.lo == y as Field); +} +``` + +Note that the limbs are stored as Field elements in order to avoid unnecessary conversions. +Apart from this, most operations will work as usual: + +```rust +fn main(x: U128, y: U128) { + // multiplication + let c = x * y; + // addition and subtraction + let c = c - x + y; + // division + let c = x / y; + // bit operation; + let c = x & y | y; + // bit shift + let c = x << y; + // comparisons; + let c = x < y; + let c = x == y; +} +``` + +## Overflows + +Computations that exceed the type boundaries will result in overflow errors. This happens with both signed and unsigned integers. For example, attempting to prove: + +```rust +fn main(x: u8, y: u8) { + let z = x + y; +} +``` + +With: + +```toml +x = "255" +y = "1" +``` + +Would result in: + +``` +$ nargo prove +error: Assertion failed: 'attempt to add with overflow' +┌─ ~/src/main.nr:9:13 +│ +│ let z = x + y; +│ ----- +│ += Call stack: + ... +``` + +A similar error would happen with signed integers: + +```rust +fn main() { + let x: i8 = -118; + let y: i8 = -11; + let z = x + y; +} +``` + +### Wrapping methods + +Although integer overflow is expected to error, some use-cases rely on wrapping. For these use-cases, the standard library provides `wrapping` variants of certain common operations: + +```rust +fn wrapping_add(x: T, y: T) -> T; +fn wrapping_sub(x: T, y: T) -> T; +fn wrapping_mul(x: T, y: T) -> T; +``` + +Example of how it is used: + +```rust +use dep::std; + +fn main(x: u8, y: u8) -> pub u8 { + std::wrapping_add(x, y) +} +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/references.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/references.md new file mode 100644 index 00000000000..a5293d11cfb --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/references.md @@ -0,0 +1,23 @@ +--- +title: References +sidebar_position: 9 +--- + +Noir supports first-class references. References are a bit like pointers: they point to a specific address that can be followed to access the data stored at that address. You can use Rust-like syntax to use pointers in Noir: the `&` operator references the variable, the `*` operator dereferences it. + +Example: + +```rust +fn main() { + let mut x = 2; + + // you can reference x as &mut and pass it to multiplyBy2 + multiplyBy2(&mut x); +} + +// you can access &mut here +fn multiplyBy2(x: &mut Field) { + // and dereference it with * + *x = *x * 2; +} +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/slices.mdx b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/slices.mdx new file mode 100644 index 00000000000..4a6ee816aa2 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/slices.mdx @@ -0,0 +1,147 @@ +--- +title: Slices +description: Explore the Slice data type in Noir. Understand its methods, see real-world examples, and learn how to effectively use Slices in your Noir programs. +keywords: [noir, slice type, methods, examples, subarrays] +sidebar_position: 5 +--- + +import Experimental from '@site/src/components/Notes/_experimental.mdx'; + + + +A slice is a dynamically-sized view into a sequence of elements. They can be resized at runtime, but because they don't own the data, they cannot be returned from a circuit. You can treat slices as arrays without a constrained size. + +```rust +use dep::std::slice; + +fn main() -> pub Field { + let mut slice: [Field] = [0; 2]; + + let mut new_slice = slice.push_back(6); + new_slice.len() +} +``` + +View the corresponding test file [here][test-file]. + +[test-file]: https://github.com/noir-lang/noir/blob/f387ec1475129732f72ba294877efdf6857135ac/crates/nargo_cli/tests/test_data_ssa_refactor/slices/src/main.nr + +## Methods + +For convenience, the STD provides some ready-to-use, common methods for slices: + +### push_back + +Pushes a new element to the end of the slice, returning a new slice with a length one greater than the original unmodified slice. + +```rust +fn push_back(_self: [T], _elem: T) -> [T] +``` + +example: + +```rust +fn main() -> pub Field { + let mut slice: [Field] = [0; 2]; + + let mut new_slice = slice.push_back(6); + new_slice.len() +} +``` + +View the corresponding test file [here][test-file]. + +### push_front + +Returns a new array with the specified element inserted at index 0. The existing elements indexes are incremented by 1. + +```rust +fn push_front(_self: Self, _elem: T) -> Self +``` + +Example: + +```rust +let mut new_slice: [Field] = []; +new_slice = new_slice.push_front(20); +assert(new_slice[0] == 20); // returns true +``` + +View the corresponding test file [here][test-file]. + +### pop_front + +Returns a tuple of two items, the first element of the array and the rest of the array. + +```rust +fn pop_front(_self: Self) -> (T, Self) +``` + +Example: + +```rust +let (first_elem, rest_of_slice) = slice.pop_front(); +``` + +View the corresponding test file [here][test-file]. + +### pop_back + +Returns a tuple of two items, the beginning of the array with the last element omitted and the last element. + +```rust +fn pop_back(_self: Self) -> (Self, T) +``` + +Example: + +```rust +let (popped_slice, last_elem) = slice.pop_back(); +``` + +View the corresponding test file [here][test-file]. + +### append + +Loops over a slice and adds it to the end of another. + +```rust +fn append(mut self, other: Self) -> Self +``` + +Example: + +```rust +let append = [1, 2].append([3, 4, 5]); +``` + +### insert + +Inserts an element at a specified index and shifts all following elements by 1. + +```rust +fn insert(_self: Self, _index: Field, _elem: T) -> Self +``` + +Example: + +```rust +new_slice = rest_of_slice.insert(2, 100); +assert(new_slice[2] == 100); +``` + +View the corresponding test file [here][test-file]. + +### remove + +Remove an element at a specified index, shifting all elements after it to the left, returning the altered slice and the removed element. + +```rust +fn remove(_self: Self, _index: Field) -> (Self, T) +``` + +Example: + +```rust +let (remove_slice, removed_elem) = slice.remove(3); +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/strings.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/strings.md new file mode 100644 index 00000000000..311dfd64416 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/strings.md @@ -0,0 +1,80 @@ +--- +title: Strings +description: + Discover the String data type in Noir. Learn about its methods, see real-world examples, and understand how to effectively manipulate and use Strings in Noir. +keywords: + [ + noir, + string type, + methods, + examples, + concatenation, + ] +sidebar_position: 3 +--- + + +The string type is a fixed length value defined with `str`. + +You can use strings in `assert()` functions or print them with +`println()`. See more about [Logging](../../standard_library/logging). + +```rust +use dep::std; + +fn main(message : pub str<11>, hex_as_string : str<4>) { + println(message); + assert(message == "hello world"); + assert(hex_as_string == "0x41"); +} +``` + +You can convert a `str` to a byte array by calling `as_bytes()` +or a vector by calling `as_bytes_vec()`. + +```rust +fn main() { + let message = "hello world"; + let message_bytes = message.as_bytes(); + let mut message_vec = message.as_bytes_vec(); + assert(message_bytes.len() == 11); + assert(message_bytes[0] == 104); + assert(message_bytes[0] == message_vec.get(0)); +} +``` + +## Escape characters + +You can use escape characters for your strings: + +| Escape Sequence | Description | +|-----------------|-----------------| +| `\r` | Carriage Return | +| `\n` | Newline | +| `\t` | Tab | +| `\0` | Null Character | +| `\"` | Double Quote | +| `\\` | Backslash | + +Example: + +```rust +let s = "Hello \"world" // prints "Hello "world" +let s = "hey \tyou"; // prints "hey you" +``` + +## Raw strings + +A raw string begins with the letter `r` and is optionally delimited by a number of hashes `#`. + +Escape characters are *not* processed within raw strings. All contents are interpreted literally. + +Example: + +```rust +let s = r"Hello world"; +let s = r#"Simon says "hello world""#; + +// Any number of hashes may be used (>= 1) as long as the string also terminates with the same number of hashes +let s = r#####"One "#, Two "##, Three "###, Four "####, Five will end the string."#####; +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/structs.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/structs.md new file mode 100644 index 00000000000..dbf68c99813 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/structs.md @@ -0,0 +1,70 @@ +--- +title: Structs +description: + Explore the Struct data type in Noir. Learn about its methods, see real-world examples, and grasp how to effectively define and use Structs in your Noir programs. +keywords: + [ + noir, + struct type, + methods, + examples, + data structures, + ] +sidebar_position: 8 +--- + +A struct also allows for grouping multiple values of different types. Unlike tuples, we can also +name each field. + +> **Note:** The usage of _field_ here refers to each element of the struct and is unrelated to the +> field type of Noir. + +Defining a struct requires giving it a name and listing each field within as `: ` pairs: + +```rust +struct Animal { + hands: Field, + legs: Field, + eyes: u8, +} +``` + +An instance of a struct can then be created with actual values in `: ` pairs in any +order. Struct fields are accessible using their given names: + +```rust +fn main() { + let legs = 4; + + let dog = Animal { + eyes: 2, + hands: 0, + legs, + }; + + let zero = dog.hands; +} +``` + +Structs can also be destructured in a pattern, binding each field to a new variable: + +```rust +fn main() { + let Animal { hands, legs: feet, eyes } = get_octopus(); + + let ten = hands + feet + eyes as u8; +} + +fn get_octopus() -> Animal { + let octopus = Animal { + hands: 0, + legs: 8, + eyes: 2, + }; + + octopus +} +``` + +The new variables can be bound with names different from the original struct field names, as +showcased in the `legs --> feet` binding in the example above. diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/tuples.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/tuples.md new file mode 100644 index 00000000000..2ec5c9c4113 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/data_types/tuples.md @@ -0,0 +1,48 @@ +--- +title: Tuples +description: + Dive into the Tuple data type in Noir. Understand its methods, practical examples, and best practices for efficiently using Tuples in your Noir code. +keywords: + [ + noir, + tuple type, + methods, + examples, + multi-value containers, + ] +sidebar_position: 7 +--- + +A tuple collects multiple values like an array, but with the added ability to collect values of +different types: + +```rust +fn main() { + let tup: (u8, u64, Field) = (255, 500, 1000); +} +``` + +One way to access tuple elements is via destructuring using pattern matching: + +```rust +fn main() { + let tup = (1, 2); + + let (one, two) = tup; + + let three = one + two; +} +``` + +Another way to access tuple elements is via direct member access, using a period (`.`) followed by +the index of the element we want to access. Index `0` corresponds to the first tuple element, `1` to +the second and so on: + +```rust +fn main() { + let tup = (5, 6, 7, 8); + + let five = tup.0; + let eight = tup.3; +} +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/distinct.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/distinct.md new file mode 100644 index 00000000000..6c993b8b5e0 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/distinct.md @@ -0,0 +1,64 @@ +--- +title: Distinct Witnesses +sidebar_position: 11 +--- + +The `distinct` keyword prevents repetitions of witness indices in the program's ABI. This ensures +that the witnesses being returned as public inputs are all unique. + +The `distinct` keyword is only used for return values on program entry points (usually the `main()` +function). + +When using `distinct` and `pub` simultaneously, `distinct` comes first. See the example below. + +You can read more about the problem this solves +[here](https://github.com/noir-lang/noir/issues/1183). + +## Example + +Without the `distinct` keyword, the following program + +```rust +fn main(x : pub Field, y : pub Field) -> pub [Field; 4] { + let a = 1; + let b = 1; + [x + 1, y, a, b] +} +``` + +compiles to + +```json +{ + //... + "abi": { + //... + "param_witnesses": { "x": [1], "y": [2] }, + "return_witnesses": [3, 2, 4, 4] + } +} +``` + +Whereas (with the `distinct` keyword) + +```rust +fn main(x : pub Field, y : pub Field) -> distinct pub [Field; 4] { + let a = 1; + let b = 1; + [x + 1, y, a, b] +} +``` + +compiles to + +```json +{ + //... + "abi": { + //... + "param_witnesses": { "x": [1], "y": [2] }, + //... + "return_witnesses": [3, 4, 5, 6] + } +} +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/functions.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/functions.md new file mode 100644 index 00000000000..48aba9cd058 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/functions.md @@ -0,0 +1,226 @@ +--- +title: Functions +description: + Learn how to declare functions and methods in Noir, a programming language with Rust semantics. + This guide covers parameter declaration, return types, call expressions, and more. +keywords: [Noir, Rust, functions, methods, parameter declaration, return types, call expressions] +sidebar_position: 1 +--- + +Functions in Noir follow the same semantics of Rust, though Noir does not support early returns. + +To declare a function the `fn` keyword is used. + +```rust +fn foo() {} +``` + +By default, functions are visible only within the package they are defined. To make them visible outside of that package (for example, as part of a [library](../modules_packages_crates/crates_and_packages.md#libraries)), you should mark them as `pub`: + +```rust +pub fn foo() {} +``` + +You can also restrict the visibility of the function to only the crate it was defined in, by specifying `pub(crate)`: + +```rust +pub(crate) fn foo() {} //foo can only be called within its crate +``` + +All parameters in a function must have a type and all types are known at compile time. The parameter +is pre-pended with a colon and the parameter type. Multiple parameters are separated using a comma. + +```rust +fn foo(x : Field, y : Field){} +``` + +The return type of a function can be stated by using the `->` arrow notation. The function below +states that the foo function must return a `Field`. If the function returns no value, then the arrow +is omitted. + +```rust +fn foo(x : Field, y : Field) -> Field { + x + y +} +``` + +Note that a `return` keyword is unneeded in this case - the last expression in a function's body is +returned. + +## Main function + +If you're writing a binary, the `main` function is the starting point of your program. You can pass all types of expressions to it, as long as they have a fixed size at compile time: + +```rust +fn main(x : Field) // this is fine: passing a Field +fn main(x : [Field; 2]) // this is also fine: passing a Field with known size at compile-time +fn main(x : (Field, bool)) // 👌: passing a (Field, bool) tuple means size 2 +fn main(x : str<5>) // this is fine, as long as you pass a string of size 5 + +fn main(x : Vec) // can't compile, has variable size +fn main(x : [Field]) // can't compile, has variable size +fn main(....// i think you got it by now +``` + +Keep in mind [tests](../../getting_started/tooling/testing.md) don't differentiate between `main` and any other function. The following snippet passes tests, but won't compile or prove: + +```rust +fn main(x : [Field]) { + assert(x[0] == 1); +} + +#[test] +fn test_one() { + main([1, 2]); +} +``` + +```bash +$ nargo test +[testing] Running 1 test functions +[testing] Testing test_one... ok +[testing] All tests passed + +$ nargo check +The application panicked (crashed). +Message: Cannot have variable sized arrays as a parameter to main +``` + +## Call Expressions + +Calling a function in Noir is executed by using the function name and passing in the necessary +arguments. + +Below we show how to call the `foo` function from the `main` function using a call expression: + +```rust +fn main(x : Field, y : Field) { + let z = foo(x); +} + +fn foo(x : Field) -> Field { + x + x +} +``` + +## Methods + +You can define methods in Noir on any struct type in scope. + +```rust +struct MyStruct { + foo: Field, + bar: Field, +} + +impl MyStruct { + fn new(foo: Field) -> MyStruct { + MyStruct { + foo, + bar: 2, + } + } + + fn sum(self) -> Field { + self.foo + self.bar + } +} + +fn main() { + let s = MyStruct::new(40); + assert(s.sum() == 42); +} +``` + +Methods are just syntactic sugar for functions, so if we wanted to we could also call `sum` as +follows: + +```rust +assert(MyStruct::sum(s) == 42); +``` + +It is also possible to specialize which method is chosen depending on the [generic](./generics.md) type that is used. In this example, the `foo` function returns different values depending on its type: + +```rust +struct Foo {} + +impl Foo { + fn foo(self) -> Field { 1 } +} + +impl Foo { + fn foo(self) -> Field { 2 } +} + +fn main() { + let f1: Foo = Foo{}; + let f2: Foo = Foo{}; + assert(f1.foo() + f2.foo() == 3); +} +``` + +Also note that impls with the same method name defined in them cannot overlap. For example, if we already have `foo` defined for `Foo` and `Foo` like we do above, we cannot also define `foo` in an `impl Foo` since it would be ambiguous which version of `foo` to choose. + +```rust +// Including this impl in the same project as the above snippet would +// cause an overlapping impls error +impl Foo { + fn foo(self) -> Field { 3 } +} +``` + +## Lambdas + +Lambdas are anonymous functions. They follow the syntax of Rust - `|arg1, arg2, ..., argN| return_expression`. + +```rust +let add_50 = |val| val + 50; +assert(add_50(100) == 150); +``` + +See [Lambdas](./lambdas.md) for more details. + +## Attributes + +Attributes are metadata that can be applied to a function, using the following syntax: `#[attribute(value)]`. + +Supported attributes include: + +- **builtin**: the function is implemented by the compiler, for efficiency purposes. +- **deprecated**: mark the function as _deprecated_. Calling the function will generate a warning: `warning: use of deprecated function` +- **field**: Used to enable conditional compilation of code depending on the field size. See below for more details +- **oracle**: mark the function as _oracle_; meaning it is an external unconstrained function, implemented in noir_js. See [Unconstrained](./unconstrained.md) and [NoirJS](../../reference/NoirJS/noir_js/index.md) for more details. +- **test**: mark the function as unit tests. See [Tests](../../getting_started/tooling/testing.md) for more details + +### Field Attribute + +The field attribute defines which field the function is compatible for. The function is conditionally compiled, under the condition that the field attribute matches the Noir native field. +The field can be defined implicitly, by using the name of the elliptic curve usually associated to it - for instance bn254, bls12_381 - or explicitly by using the field (prime) order, in decimal or hexadecimal form. +As a result, it is possible to define multiple versions of a function with each version specialized for a different field attribute. This can be useful when a function requires different parameters depending on the underlying elliptic curve. + +Example: we define the function `foo()` three times below. Once for the default Noir bn254 curve, once for the field $\mathbb F_{23}$, which will normally never be used by Noir, and once again for the bls12_381 curve. + +```rust +#[field(bn254)] +fn foo() -> u32 { + 1 +} + +#[field(23)] +fn foo() -> u32 { + 2 +} + +// This commented code would not compile as foo would be defined twice because it is the same field as bn254 +// #[field(21888242871839275222246405745257275088548364400416034343698204186575808495617)] +// fn foo() -> u32 { +// 2 +// } + +#[field(bls12_381)] +fn foo() -> u32 { + 3 +} +``` + +If the field name is not known to Noir, it will discard the function. Field names are case insensitive. diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/generics.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/generics.md new file mode 100644 index 00000000000..ddd42bf1f9b --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/generics.md @@ -0,0 +1,106 @@ +--- +title: Generics +description: Learn how to use Generics in Noir +keywords: [Noir, Rust, generics, functions, structs] +sidebar_position: 7 +--- + +Generics allow you to use the same functions with multiple different concrete data types. You can +read more about the concept of generics in the Rust documentation +[here](https://doc.rust-lang.org/book/ch10-01-syntax.html). + +Here is a trivial example showing the identity function that supports any type. In Rust, it is +common to refer to the most general type as `T`. We follow the same convention in Noir. + +```rust +fn id(x: T) -> T { + x +} +``` + +## In Structs + +Generics are useful for specifying types in structs. For example, we can specify that a field in a +struct will be of a certain generic type. In this case `value` is of type `T`. + +```rust +struct RepeatedValue { + value: T, + count: Field, +} + +impl RepeatedValue { + fn print(self) { + for _i in 0 .. self.count { + println(self.value); + } + } +} + +fn main() { + let repeated = RepeatedValue { value: "Hello!", count: 2 }; + repeated.print(); +} +``` + +The `print` function will print `Hello!` an arbitrary number of times, twice in this case. + +If we want to be generic over array lengths (which are type-level integers), we can use numeric +generics. Using these looks just like using regular generics, but these generics can resolve to +integers at compile-time, rather than resolving to types. Here's an example of a struct that is +generic over the size of the array it contains internally: + +```rust +struct BigInt { + limbs: [u32; N], +} + +impl BigInt { + // `N` is in scope of all methods in the impl + fn first(first: BigInt, second: BigInt) -> Self { + assert(first.limbs != second.limbs); + first + + fn second(first: BigInt, second: Self) -> Self { + assert(first.limbs != second.limbs); + second + } +} +``` + +## Calling functions on generic parameters + +Since a generic type `T` can represent any type, how can we call functions on the underlying type? +In other words, how can we go from "any type `T`" to "any type `T` that has certain methods available?" + +This is what [traits](../concepts/traits) are for in Noir. Here's an example of a function generic over +any type `T` that implements the `Eq` trait for equality: + +```rust +fn first_element_is_equal(array1: [T; N], array2: [T; N]) -> bool + where T: Eq +{ + if (array1.len() == 0) | (array2.len() == 0) { + true + } else { + array1[0] == array2[0] + } +} + +fn main() { + assert(first_element_is_equal([1, 2, 3], [1, 5, 6])); + + // We can use first_element_is_equal for arrays of any type + // as long as we have an Eq impl for the types we pass in + let array = [MyStruct::new(), MyStruct::new()]; + assert(array_eq(array, array, MyStruct::eq)); +} + +impl Eq for MyStruct { + fn eq(self, other: MyStruct) -> bool { + self.foo == other.foo + } +} +``` + +You can find more details on traits and trait implementations on the [traits page](../concepts/traits). diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/globals.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/globals.md new file mode 100644 index 00000000000..063a3d89248 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/globals.md @@ -0,0 +1,72 @@ +--- +title: Global Variables +description: + Learn about global variables in Noir. Discover how + to declare, modify, and use them in your programs. +keywords: [noir programming language, globals, global variables, constants] +sidebar_position: 8 +--- + +## Globals + + +Noir supports global variables. The global's type can be inferred by the compiler entirely: + +```rust +global N = 5; // Same as `global N: Field = 5` + +global TUPLE = (3, 2); + +fn main() { + assert(N == 5); + assert(N == TUPLE.0 + TUPLE.1); +} +``` + +:::info + +Globals can be defined as any expression, so long as they don't depend on themselves - otherwise there would be a dependency cycle! For example: + +```rust +global T = foo(T); // dependency error +``` + +::: + + +If they are initialized to a literal integer, globals can be used to specify an array's length: + +```rust +global N: Field = 2; + +fn main(y : [Field; N]) { + assert(y[0] == y[1]) +} +``` + +A global from another module can be imported or referenced externally like any other name: + +```rust +global N = 20; + +fn main() { + assert(my_submodule::N != N); +} + +mod my_submodule { + global N: Field = 10; +} +``` + +When a global is used, Noir replaces the name with its definition on each occurrence. +This means globals defined using function calls will repeat the call each time they're used: + +```rust +global RESULT = foo(); + +fn foo() -> [Field; 100] { ... } +``` + +This is usually fine since Noir will generally optimize any function call that does not +refer to a program input into a constant. It should be kept in mind however, if the called +function performs side-effects like `println`, as these will still occur on each use. diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/lambdas.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/lambdas.md new file mode 100644 index 00000000000..be3c7e0b5ca --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/lambdas.md @@ -0,0 +1,81 @@ +--- +title: Lambdas +description: Learn how to use anonymous functions in Noir programming language. +keywords: [Noir programming language, lambda, closure, function, anonymous function] +sidebar_position: 9 +--- + +## Introduction + +Lambdas are anonymous functions. The syntax is `|arg1, arg2, ..., argN| return_expression`. + +```rust +let add_50 = |val| val + 50; +assert(add_50(100) == 150); +``` + +A block can be used as the body of a lambda, allowing you to declare local variables inside it: + +```rust +let cool = || { + let x = 100; + let y = 100; + x + y +} + +assert(cool() == 200); +``` + +## Closures + +Inside the body of a lambda, you can use variables defined in the enclosing function. Such lambdas are called **closures**. In this example `x` is defined inside `main` and is accessed from within the lambda: + +```rust +fn main() { + let x = 100; + let closure = || x + 150; + assert(closure() == 250); +} +``` + +## Passing closures to higher-order functions + +It may catch you by surprise that the following code fails to compile: + +```rust +fn foo(f: fn () -> Field) -> Field { + f() +} + +fn main() { + let (x, y) = (50, 50); + assert(foo(|| x + y) == 100); // error :( +} +``` + +The reason is that the closure's capture environment affects its type - we have a closure that captures two Fields and `foo` +expects a regular function as an argument - those are incompatible. +:::note + +Variables contained within the `||` are the closure's parameters, and the expression that follows it is the closure's body. The capture environment is comprised of any variables used in the closure's body that are not parameters. + +E.g. in |x| x + y, y would be a captured variable, but x would not be, since it is a parameter of the closure. + +::: +The syntax for the type of a closure is `fn[env](args) -> ret_type`, where `env` is the capture environment of the closure - +in this example that's `(Field, Field)`. + +The best solution in our case is to make `foo` generic over the environment type of its parameter, so that it can be called +with closures with any environment, as well as with regular functions: + +```rust +fn foo(f: fn[Env]() -> Field) -> Field { + f() +} + +fn main() { + let (x, y) = (50, 50); + assert(foo(|| x + y) == 100); // compiles fine + assert(foo(|| 60) == 60); // compiles fine +} +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/mutability.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/mutability.md new file mode 100644 index 00000000000..fdeef6a87c5 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/mutability.md @@ -0,0 +1,121 @@ +--- +title: Mutability +description: + Learn about mutable variables in Noir. Discover how + to declare, modify, and use them in your programs. +keywords: [noir programming language, mutability in noir, mutable variables] +sidebar_position: 8 +--- + +Variables in noir can be declared mutable via the `mut` keyword. Mutable variables can be reassigned +to via an assignment expression. + +```rust +let x = 2; +x = 3; // error: x must be mutable to be assigned to + +let mut y = 3; +let y = 4; // OK +``` + +The `mut` modifier can also apply to patterns: + +```rust +let (a, mut b) = (1, 2); +a = 11; // error: a must be mutable to be assigned to +b = 12; // OK + +let mut (c, d) = (3, 4); +c = 13; // OK +d = 14; // OK + +// etc. +let MyStruct { x: mut y } = MyStruct { x: a }; +// y is now in scope +``` + +Note that mutability in noir is local and everything is passed by value, so if a called function +mutates its parameters then the parent function will keep the old value of the parameters. + +```rust +fn main() -> pub Field { + let x = 3; + helper(x); + x // x is still 3 +} + +fn helper(mut x: i32) { + x = 4; +} +``` + +## Non-local mutability + +Non-local mutability can be achieved through the mutable reference type `&mut T`: + +```rust +fn set_to_zero(x: &mut Field) { + *x = 0; +} + +fn main() { + let mut y = 42; + set_to_zero(&mut y); + assert(*y == 0); +} +``` + +When creating a mutable reference, the original variable being referred to (`y` in this +example) must also be mutable. Since mutable references are a reference type, they must +be explicitly dereferenced via `*` to retrieve the underlying value. Note that this yields +a copy of the value, so mutating this copy will not change the original value behind the +reference: + +```rust +fn main() { + let mut x = 1; + let x_ref = &mut x; + + let mut y = *x_ref; + let y_ref = &mut y; + + x = 2; + *x_ref = 3; + + y = 4; + *y_ref = 5; + + assert(x == 3); + assert(*x_ref == 3); + assert(y == 5); + assert(*y_ref == 5); +} +``` + +Note that types in Noir are actually deeply immutable so the copy that occurs when +dereferencing is only a conceptual copy - no additional constraints will occur. + +Mutable references can also be stored within structs. Note that there is also +no lifetime parameter on these unlike rust. This is because the allocated memory +always lasts the entire program - as if it were an array of one element. + +```rust +struct Foo { + x: &mut Field +} + +impl Foo { + fn incr(mut self) { + *self.x += 1; + } +} + +fn main() { + let foo = Foo { x: &mut 0 }; + foo.incr(); + assert(*foo.x == 1); +} +``` + +In general, you should avoid non-local & shared mutability unless it is needed. Sticking +to only local mutability will improve readability and potentially improve compiler optimizations as well. diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/ops.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/ops.md new file mode 100644 index 00000000000..60425cb8994 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/ops.md @@ -0,0 +1,98 @@ +--- +title: Logical Operations +description: + Learn about the supported arithmetic and logical operations in the Noir programming language. + Discover how to perform operations on private input types, integers, and booleans. +keywords: + [ + Noir programming language, + supported operations, + arithmetic operations, + logical operations, + predicate operators, + bitwise operations, + short-circuiting, + backend, + ] +sidebar_position: 3 +--- + +# Operations + +## Table of Supported Operations + +| Operation | Description | Requirements | +| :-------- | :------------------------------------------------------------: | -------------------------------------: | +| + | Adds two private input types together | Types must be private input | +| - | Subtracts two private input types together | Types must be private input | +| \* | Multiplies two private input types together | Types must be private input | +| / | Divides two private input types together | Types must be private input | +| ^ | XOR two private input types together | Types must be integer | +| & | AND two private input types together | Types must be integer | +| \| | OR two private input types together | Types must be integer | +| \<\< | Left shift an integer by another integer amount | Types must be integer | +| >> | Right shift an integer by another integer amount | Types must be integer | +| ! | Bitwise not of a value | Type must be integer or boolean | +| \< | returns a bool if one value is less than the other | Upper bound must have a known bit size | +| \<= | returns a bool if one value is less than or equal to the other | Upper bound must have a known bit size | +| > | returns a bool if one value is more than the other | Upper bound must have a known bit size | +| >= | returns a bool if one value is more than or equal to the other | Upper bound must have a known bit size | +| == | returns a bool if one value is equal to the other | Both types must not be constants | +| != | returns a bool if one value is not equal to the other | Both types must not be constants | + +### Predicate Operators + +`<,<=, !=, == , >, >=` are known as predicate/comparison operations because they compare two values. +This differs from the operations such as `+` where the operands are used in _computation_. + +### Bitwise Operations Example + +```rust +fn main(x : Field) { + let y = x as u32; + let z = y & y; +} +``` + +`z` is implicitly constrained to be the result of `y & y`. The `&` operand is used to denote bitwise +`&`. + +> `x & x` would not compile as `x` is a `Field` and not an integer type. + +### Logical Operators + +Noir has no support for the logical operators `||` and `&&`. This is because encoding the +short-circuiting that these operators require can be inefficient for Noir's backend. Instead you can +use the bitwise operators `|` and `&` which operate identically for booleans, just without the +short-circuiting. + +```rust +let my_val = 5; + +let mut flag = 1; +if (my_val > 6) | (my_val == 0) { + flag = 0; +} +assert(flag == 1); + +if (my_val != 10) & (my_val < 50) { + flag = 0; +} +assert(flag == 0); +``` + +### Shorthand operators + +Noir shorthand operators for most of the above operators, namely `+=, -=, *=, /=, %=, &=, |=, ^=, <<=`, and `>>=`. These allow for more concise syntax. For example: + +```rust +let mut i = 0; +i = i + 1; +``` + +could be written as: + +```rust +let mut i = 0; +i += 1; +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/oracles.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/oracles.md new file mode 100644 index 00000000000..2e6a6818d48 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/oracles.md @@ -0,0 +1,23 @@ +--- +title: Oracles +description: Dive into how Noir supports Oracles via RPC calls, and learn how to declare an Oracle in Noir with our comprehensive guide. +keywords: + - Noir + - Oracles + - RPC Calls + - Unconstrained Functions + - Programming + - Blockchain +sidebar_position: 6 +--- + +Noir has support for Oracles via RPC calls. This means Noir will make an RPC call and use the return value for proof generation. + +Since Oracles are not resolved by Noir, they are [`unconstrained` functions](./unconstrained.md) + +You can declare an Oracle through the `#[oracle()]` flag. Example: + +```rust +#[oracle(get_number_sequence)] +unconstrained fn get_number_sequence(_size: Field) -> [Field] {} +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/shadowing.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/shadowing.md new file mode 100644 index 00000000000..5ce6130d201 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/shadowing.md @@ -0,0 +1,44 @@ +--- +title: Shadowing +sidebar_position: 12 +--- + +Noir allows for inheriting variables' values and re-declaring them with the same name similar to Rust, known as shadowing. + +For example, the following function is valid in Noir: + +```rust +fn main() { + let x = 5; + + { + let x = x * 2; + assert (x == 10); + } + + assert (x == 5); +} +``` + +In this example, a variable x is first defined with the value 5. + +The local scope that follows shadows the original x, i.e. creates a local mutable x based on the value of the original x. It is given a value of 2 times the original x. + +When we return to the main scope, x once again refers to just the original x, which stays at the value of 5. + +## Temporal mutability + +One way that shadowing is useful, in addition to ergonomics across scopes, is for temporarily mutating variables. + +```rust +fn main() { + let age = 30; + // age = age + 5; // Would error as `age` is immutable by default. + + let mut age = age + 5; // Temporarily mutates `age` with a new value. + + let age = age; // Locks `age`'s mutability again. + + assert (age == 35); +} +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/traits.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/traits.md new file mode 100644 index 00000000000..ef1445a5907 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/traits.md @@ -0,0 +1,389 @@ +--- +title: Traits +description: + Traits in Noir can be used to abstract out a common interface for functions across + several data types. +keywords: [noir programming language, traits, interfaces, generic, protocol] +sidebar_position: 14 +--- + +## Overview + +Traits in Noir are a useful abstraction similar to interfaces or protocols in other languages. Each trait defines +the interface of several methods contained within the trait. Types can then implement this trait by providing +implementations for these methods. For example in the program: + +```rust +struct Rectangle { + width: Field, + height: Field, +} + +impl Rectangle { + fn area(self) -> Field { + self.width * self.height + } +} + +fn log_area(r: Rectangle) { + println(r.area()); +} +``` + +We have a function `log_area` to log the area of a `Rectangle`. Now how should we change the program if we want this +function to work on `Triangle`s as well?: + +```rust +struct Triangle { + width: Field, + height: Field, +} + +impl Triangle { + fn area(self) -> Field { + self.width * self.height / 2 + } +} +``` + +Making `log_area` generic over all types `T` would be invalid since not all types have an `area` method. Instead, we can +introduce a new `Area` trait and make `log_area` generic over all types `T` that implement `Area`: + +```rust +trait Area { + fn area(self) -> Field; +} + +fn log_area(shape: T) where T: Area { + println(shape.area()); +} +``` + +We also need to explicitly implement `Area` for `Rectangle` and `Triangle`. We can do that by changing their existing +impls slightly. Note that the parameter types and return type of each of our `area` methods must match those defined +by the `Area` trait. + +```rust +impl Area for Rectangle { + fn area(self) -> Field { + self.width * self.height + } +} + +impl Area for Triangle { + fn area(self) -> Field { + self.width * self.height / 2 + } +} +``` + +Now we have a working program that is generic over any type of Shape that is used! Others can even use this program +as a library with their own types - such as `Circle` - as long as they also implement `Area` for these types. + +## Where Clauses + +As seen in `log_area` above, when we want to create a function or method that is generic over any type that implements +a trait, we can add a where clause to the generic function. + +```rust +fn log_area(shape: T) where T: Area { + println(shape.area()); +} +``` + +It is also possible to apply multiple trait constraints on the same variable at once by combining traits with the `+` +operator. Similarly, we can have multiple trait constraints by separating each with a comma: + +```rust +fn foo(elements: [T], thing: U) where + T: Default + Add + Eq, + U: Bar, +{ + let mut sum = T::default(); + + for element in elements { + sum += element; + } + + if sum == T::default() { + thing.bar(); + } +} +``` + +## Generic Implementations + +You can add generics to a trait implementation by adding the generic list after the `impl` keyword: + +```rust +trait Second { + fn second(self) -> Field; +} + +impl Second for (T, Field) { + fn second(self) -> Field { + self.1 + } +} +``` + +You can also implement a trait for every type this way: + +```rust +trait Debug { + fn debug(self); +} + +impl Debug for T { + fn debug(self) { + println(self); + } +} + +fn main() { + 1.debug(); +} +``` + +### Generic Trait Implementations With Where Clauses + +Where clauses can also be placed on trait implementations themselves to restrict generics in a similar way. +For example, while `impl Foo for T` implements the trait `Foo` for every type, `impl Foo for T where T: Bar` +will implement `Foo` only for types that also implement `Bar`. This is often used for implementing generic types. +For example, here is the implementation for array equality: + +```rust +impl Eq for [T; N] where T: Eq { + // Test if two arrays have the same elements. + // Because both arrays must have length N, we know their lengths already match. + fn eq(self, other: Self) -> bool { + let mut result = true; + + for i in 0 .. self.len() { + // The T: Eq constraint is needed to call == on the array elements here + result &= self[i] == other[i]; + } + + result + } +} +``` + +## Generic Traits + +Traits themselves can also be generic by placing the generic arguments after the trait name. These generics are in +scope of every item within the trait. + +```rust +trait Into { + // Convert `self` to type `T` + fn into(self) -> T; +} +``` + +When implementing generic traits the generic arguments of the trait must be specified. This is also true anytime +when referencing a generic trait (e.g. in a `where` clause). + +```rust +struct MyStruct { + array: [Field; 2], +} + +impl Into<[Field; 2]> for MyStruct { + fn into(self) -> [Field; 2] { + self.array + } +} + +fn as_array(x: T) -> [Field; 2] + where T: Into<[Field; 2]> +{ + x.into() +} + +fn main() { + let array = [1, 2]; + let my_struct = MyStruct { array }; + + assert_eq(as_array(my_struct), array); +} +``` + +## Trait Methods With No `self` + +A trait can contain any number of methods, each of which have access to the `Self` type which represents each type +that eventually implements the trait. Similarly, the `self` variable is available as well but is not required to be used. +For example, we can define a trait to create a default value for a type. This trait will need to return the `Self` type +but doesn't need to take any parameters: + +```rust +trait Default { + fn default() -> Self; +} +``` + +Implementing this trait can be done similarly to any other trait: + +```rust +impl Default for Field { + fn default() -> Field { + 0 + } +} + +struct MyType {} + +impl Default for MyType { + fn default() -> Field { + MyType {} + } +} +``` + +However, since there is no `self` parameter, we cannot call it via the method call syntax `object.method()`. +Instead, we'll need to refer to the function directly. This can be done either by referring to the +specific impl `MyType::default()` or referring to the trait itself `Default::default()`. In the later +case, type inference determines the impl that is selected. + +```rust +let my_struct = MyStruct::default(); + +let x: Field = Default::default(); +let result = x + Default::default(); +``` + +:::warning + +```rust +let _ = Default::default(); +``` + +If type inference cannot select which impl to use because of an ambiguous `Self` type, an impl will be +arbitrarily selected. This occurs most often when the result of a trait function call with no parameters +is unused. To avoid this, when calling a trait function with no `self` or `Self` parameters or return type, +always refer to it via the implementation type's namespace - e.g. `MyType::default()`. +This is set to change to an error in future Noir versions. + +::: + +## Default Method Implementations + +A trait can also have default implementations of its methods by giving a body to the desired functions. +Note that this body must be valid for all types that may implement the trait. As a result, the only +valid operations on `self` will be operations valid for any type or other operations on the trait itself. + +```rust +trait Numeric { + fn add(self, other: Self) -> Self; + + // Default implementation of double is (self + self) + fn double(self) -> Self { + self.add(self) + } +} +``` + +When implementing a trait with default functions, a type may choose to implement only the required functions: + +```rust +impl Numeric for Field { + fn add(self, other: Field) -> Field { + self + other + } +} +``` + +Or it may implement the optional methods as well: + +```rust +impl Numeric for u32 { + fn add(self, other: u32) -> u32 { + self + other + } + + fn double(self) -> u32 { + self * 2 + } +} +``` + +## Impl Specialization + +When implementing traits for a generic type it is possible to implement the trait for only a certain combination +of generics. This can be either as an optimization or because those specific generics are required to implement the trait. + +```rust +trait Sub { + fn sub(self, other: Self) -> Self; +} + +struct NonZero { + value: T, +} + +impl Sub for NonZero { + fn sub(self, other: Self) -> Self { + let value = self.value - other.value; + assert(value != 0); + NonZero { value } + } +} +``` + +## Overlapping Implementations + +Overlapping implementations are disallowed by Noir to ensure Noir's decision on which impl to select is never ambiguous. +This means if a trait `Foo` is already implemented +by a type `Bar` for all `T`, then we cannot also have a separate impl for `Bar` (or any other +type argument). Similarly, if there is an impl for all `T` such as `impl Debug for T`, we cannot create +any more impls to `Debug` for other types since it would be ambiguous which impl to choose for any given +method call. + +```rust +trait Trait {} + +// Previous impl defined here +impl Trait for (A, B) {} + +// error: Impl for type `(Field, Field)` overlaps with existing impl +impl Trait for (Field, Field) {} +``` + +## Trait Coherence + +Another restriction on trait implementations is coherence. This restriction ensures other crates cannot create +impls that may overlap with other impls, even if several unrelated crates are used as dependencies in the same +program. + +The coherence restriction is: to implement a trait, either the trait itself or the object type must be declared +in the crate the impl is in. + +In practice this often comes up when using types provided by libraries. If a library provides a type `Foo` that does +not implement a trait in the standard library such as `Default`, you may not `impl Default for Foo` in your own crate. +While restrictive, this prevents later issues or silent changes in the program if the `Foo` library later added its +own impl for `Default`. If you are a user of the `Foo` library in this scenario and need a trait not implemented by the +library your choices are to either submit a patch to the library or use the newtype pattern. + +### The Newtype Pattern + +The newtype pattern gets around the coherence restriction by creating a new wrapper type around the library type +that we cannot create `impl`s for. Since the new wrapper type is defined in our current crate, we can create +impls for any trait we need on it. + +```rust +struct Wrapper { + foo: dep::some_library::Foo, +} + +impl Default for Wrapper { + fn default() -> Wrapper { + Wrapper { + foo: dep::some_library::Foo::new(), + } + } +} +``` + +Since we have an impl for our own type, the behavior of this code will not change even if `some_library` is updated +to provide its own `impl Default for Foo`. The downside of this pattern is that it requires extra wrapping and +unwrapping of values when converting to and from the `Wrapper` and `Foo` types. diff --git a/docs/versioned_docs/version-v0.25.0/noir/concepts/unconstrained.md b/docs/versioned_docs/version-v0.25.0/noir/concepts/unconstrained.md new file mode 100644 index 00000000000..89d12c1c971 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/concepts/unconstrained.md @@ -0,0 +1,95 @@ +--- +title: Unconstrained Functions +description: "Learn about what unconstrained functions in Noir are, how to use them and when you'd want to." + +keywords: [Noir programming language, unconstrained, open] +sidebar_position: 5 +--- + +Unconstrained functions are functions which do not constrain any of the included computation and allow for non-deterministic computation. + +## Why? + +Zero-knowledge (ZK) domain-specific languages (DSL) enable developers to generate ZK proofs from their programs by compiling code down to the constraints of an NP complete language (such as R1CS or PLONKish languages). However, the hard bounds of a constraint system can be very limiting to the functionality of a ZK DSL. + +Enabling a circuit language to perform unconstrained execution is a powerful tool. Said another way, unconstrained execution lets developers generate witnesses from code that does not generate any constraints. Being able to execute logic outside of a circuit is critical for both circuit performance and constructing proofs on information that is external to a circuit. + +Fetching information from somewhere external to a circuit can also be used to enable developers to improve circuit efficiency. + +A ZK DSL does not just prove computation, but proves that some computation was handled correctly. Thus, it is necessary that when we switch from performing some operation directly inside of a circuit to inside of an unconstrained environment that the appropriate constraints are still laid down elsewhere in the circuit. + +## Example + +An in depth example might help drive the point home. This example comes from the excellent [post](https://discord.com/channels/1113924620781883405/1124022445054111926/1128747641853972590) by Tom in the Noir Discord. + +Let's look at how we can optimize a function to turn a `u72` into an array of `u8`s. + +```rust +fn main(num: u72) -> pub [u8; 8] { + let mut out: [u8; 8] = [0; 8]; + for i in 0..8 { + out[i] = (num >> (56 - (i * 8)) as u72 & 0xff) as u8; + } + + out +} +``` + +``` +Total ACIR opcodes generated for language PLONKCSat { width: 3 }: 91 +Backend circuit size: 3619 +``` + +A lot of the operations in this function are optimized away by the compiler (all the bit-shifts turn into divisions by constants). However we can save a bunch of gates by casting to u8 a bit earlier. This automatically truncates the bit-shifted value to fit in a u8 which allows us to remove the AND against 0xff. This saves us ~480 gates in total. + +```rust +fn main(num: u72) -> pub [u8; 8] { + let mut out: [u8; 8] = [0; 8]; + for i in 0..8 { + out[i] = (num >> (56 - (i * 8)) as u8; + } + + out +} +``` + +``` +Total ACIR opcodes generated for language PLONKCSat { width: 3 }: 75 +Backend circuit size: 3143 +``` + +Those are some nice savings already but we can do better. This code is all constrained so we're proving every step of calculating out using num, but we don't actually care about how we calculate this, just that it's correct. This is where brillig comes in. + +It turns out that truncating a u72 into a u8 is hard to do inside a snark, each time we do as u8 we lay down 4 ACIR opcodes which get converted into multiple gates. It's actually much easier to calculate num from out than the other way around. All we need to do is multiply each element of out by a constant and add them all together, both relatively easy operations inside a snark. + +We can then run u72_to_u8 as unconstrained brillig code in order to calculate out, then use that result in our constrained function and assert that if we were to do the reverse calculation we'd get back num. This looks a little like the below: + +```rust +fn main(num: u72) -> pub [u8; 8] { + let out = u72_to_u8(num); + + let mut reconstructed_num: u72 = 0; + for i in 0..8 { + reconstructed_num += (out[i] as u72 << (56 - (8 * i))); + } + assert(num == reconstructed_num); + out +} + +unconstrained fn u72_to_u8(num: u72) -> [u8; 8] { + let mut out: [u8; 8] = [0; 8]; + for i in 0..8 { + out[i] = (num >> (56 - (i * 8))) as u8; + } + out +} +``` + +``` +Total ACIR opcodes generated for language PLONKCSat { width: 3 }: 78 +Backend circuit size: 2902 +``` + +This ends up taking off another ~250 gates from our circuit! We've ended up with more ACIR opcodes than before but they're easier for the backend to prove (resulting in fewer gates). + +Generally we want to use brillig whenever there's something that's easy to verify but hard to compute within the circuit. For example, if you wanted to calculate a square root of a number it'll be a much better idea to calculate this in brillig and then assert that if you square the result you get back your number. diff --git a/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/_category_.json b/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/_category_.json new file mode 100644 index 00000000000..1debcfe7675 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/_category_.json @@ -0,0 +1,6 @@ +{ + "label": "Modules, Packages and Crates", + "position": 2, + "collapsible": true, + "collapsed": true +} diff --git a/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/crates_and_packages.md b/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/crates_and_packages.md new file mode 100644 index 00000000000..95ee9f52ab2 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/crates_and_packages.md @@ -0,0 +1,43 @@ +--- +title: Crates and Packages +description: Learn how to use Crates and Packages in your Noir project +keywords: [Nargo, dependencies, package management, crates, package] +sidebar_position: 0 +--- + +## Crates + +A crate is the smallest amount of code that the Noir compiler considers at a time. +Crates can contain modules, and the modules may be defined in other files that get compiled with the crate, as we’ll see in the coming sections. + +### Crate Types + +A Noir crate can come in several forms: binaries, libraries or contracts. + +#### Binaries + +_Binary crates_ are programs which you can compile to an ACIR circuit which you can then create proofs against. Each must have a function called `main` that defines the ACIR circuit which is to be proved. + +#### Libraries + +_Library crates_ don't have a `main` function and they don't compile down to ACIR. Instead they define functionality intended to be shared with multiple projects, and eventually included in a binary crate. + +#### Contracts + +Contract crates are similar to binary crates in that they compile to ACIR which you can create proofs against. They are different in that they do not have a single `main` function, but are a collection of functions to be deployed to the [Aztec network](https://aztec.network). You can learn more about the technical details of Aztec in the [monorepo](https://github.com/AztecProtocol/aztec-packages) or contract [examples](https://github.com/AztecProtocol/aztec-packages/tree/master/noir-projects/noir-contracts/contracts). + +### Crate Root + +Every crate has a root, which is the source file that the compiler starts, this is also known as the root module. The Noir compiler does not enforce any conditions on the name of the file which is the crate root, however if you are compiling via Nargo the crate root must be called `lib.nr` or `main.nr` for library or binary crates respectively. + +## Packages + +A Nargo _package_ is a collection of one of more crates that provides a set of functionality. A package must include a Nargo.toml file. + +A package _must_ contain either a library or a binary crate, but not both. + +### Differences from Cargo Packages + +One notable difference between Rust's Cargo and Noir's Nargo is that while Cargo allows a package to contain an unlimited number of binary crates and a single library crate, Nargo currently only allows a package to contain a single crate. + +In future this restriction may be lifted to allow a Nargo package to contain both a binary and library crate or multiple binary crates. diff --git a/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/dependencies.md b/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/dependencies.md new file mode 100644 index 00000000000..04c1703d929 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/dependencies.md @@ -0,0 +1,124 @@ +--- +title: Dependencies +description: + Learn how to specify and manage dependencies in Nargo, allowing you to upload packages to GitHub + and use them easily in your project. +keywords: [Nargo, dependencies, GitHub, package management, versioning] +sidebar_position: 1 +--- + +Nargo allows you to upload packages to GitHub and use them as dependencies. + +## Specifying a dependency + +Specifying a dependency requires a tag to a specific commit and the git url to the url containing +the package. + +Currently, there are no requirements on the tag contents. If requirements are added, it would follow +semver 2.0 guidelines. + +> Note: Without a `tag` , there would be no versioning and dependencies would change each time you +> compile your project. + +For example, to add the [ecrecover-noir library](https://github.com/colinnielsen/ecrecover-noir) to your project, add it to `Nargo.toml`: + +```toml +# Nargo.toml + +[dependencies] +ecrecover = {tag = "v0.8.0", git = "https://github.com/colinnielsen/ecrecover-noir"} +``` + +If the module is in a subdirectory, you can define a subdirectory in your git repository, for example: + +```toml +# Nargo.toml + +[dependencies] +easy_private_token_contract = {tag ="v0.1.0-alpha62", git = "https://github.com/AztecProtocol/aztec-packages", directory = "noir-contracts/contracts/easy_private_token_contract"} +``` + +## Specifying a local dependency + +You can also specify dependencies that are local to your machine. + +For example, this file structure has a library and binary crate + +```tree +├── binary_crate +│   ├── Nargo.toml +│   └── src +│   └── main.nr +└── lib_a + ├── Nargo.toml + └── src + └── lib.nr +``` + +Inside of the binary crate, you can specify: + +```toml +# Nargo.toml + +[dependencies] +lib_a = { path = "../lib_a" } +``` + +## Importing dependencies + +You can import a dependency to a Noir file using the following syntax. For example, to import the +ecrecover-noir library and local lib_a referenced above: + +```rust +use dep::ecrecover; +use dep::lib_a; +``` + +You can also import only the specific parts of dependency that you want to use, like so: + +```rust +use dep::std::hash::sha256; +use dep::std::scalar_mul::fixed_base_embedded_curve; +``` + +Lastly, as demonstrated in the +[elliptic curve example](../standard_library/cryptographic_primitives/ec_primitives#examples), you +can import multiple items in the same line by enclosing them in curly braces: + +```rust +use dep::std::ec::tecurve::affine::{Curve, Point}; +``` + +We don't have a way to consume libraries from inside a [workspace](./workspaces) as external dependencies right now. + +Inside a workspace, these are consumed as `{ path = "../to_lib" }` dependencies in Nargo.toml. + +## Dependencies of Dependencies + +Note that when you import a dependency, you also get access to all of the dependencies of that package. + +For example, the [phy_vector](https://github.com/resurgencelabs/phy_vector) library imports an [fraction](https://github.com/resurgencelabs/fraction) library. If you're importing the phy_vector library, then you can access the functions in fractions library like so: + +```rust +use dep::phy_vector; + +fn main(x : Field, y : pub Field) { + //... + let f = phy_vector::fraction::toFraction(true, 2, 1); + //... +} +``` + +## Available Libraries + +Noir does not currently have an official package manager. You can find a list of available Noir libraries in the [awesome-noir repo here](https://github.com/noir-lang/awesome-noir#libraries). + +Some libraries that are available today include: + +- [Standard Library](https://github.com/noir-lang/noir/tree/master/noir_stdlib) - the Noir Standard Library +- [Ethereum Storage Proof Verification](https://github.com/aragonzkresearch/noir-trie-proofs) - a library that contains the primitives necessary for RLP decoding (in the form of look-up table construction) and Ethereum state and storage proof verification (or verification of any trie proof involving 32-byte long keys) +- [BigInt](https://github.com/shuklaayush/noir-bigint) - a library that provides a custom BigUint56 data type, allowing for computations on large unsigned integers +- [ECrecover](https://github.com/colinnielsen/ecrecover-noir/tree/main) - a library to verify an ECDSA signature and return the source Ethereum address +- [Sparse Merkle Tree Verifier](https://github.com/vocdoni/smtverifier-noir/tree/main) - a library for verification of sparse Merkle trees +- [Signed Int](https://github.com/resurgencelabs/signed_int) - a library for accessing a custom Signed Integer data type, allowing access to negative numbers on Noir +- [Fraction](https://github.com/resurgencelabs/fraction) - a library for accessing fractional number data type in Noir, allowing results that aren't whole numbers diff --git a/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/modules.md b/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/modules.md new file mode 100644 index 00000000000..ae822a1cff4 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/modules.md @@ -0,0 +1,105 @@ +--- +title: Modules +description: + Learn how to organize your files using modules in Noir, following the same convention as Rust's + module system. Examples included. +keywords: [Noir, Rust, modules, organizing files, sub-modules] +sidebar_position: 2 +--- + +Noir's module system follows the same convention as the _newer_ version of Rust's module system. + +## Purpose of Modules + +Modules are used to organize files. Without modules all of your code would need to live in a single +file. In Noir, the compiler does not automatically scan all of your files to detect modules. This +must be done explicitly by the developer. + +## Examples + +### Importing a module in the crate root + +Filename : `src/main.nr` + +```rust +mod foo; + +fn main() { + foo::hello_world(); +} +``` + +Filename : `src/foo.nr` + +```rust +fn from_foo() {} +``` + +In the above snippet, the crate root is the `src/main.nr` file. The compiler sees the module +declaration `mod foo` which prompts it to look for a foo.nr file. + +Visually this module hierarchy looks like the following : + +``` +crate + ├── main + │ + └── foo + └── from_foo + +``` + +### Importing a module throughout the tree + +All modules are accessible from the `crate::` namespace. + +``` +crate + ├── bar + ├── foo + └── main + +``` + +In the above snippet, if `bar` would like to use functions in `foo`, it can do so by `use crate::foo::function_name`. + +### Sub-modules + +Filename : `src/main.nr` + +```rust +mod foo; + +fn main() { + foo::from_foo(); +} +``` + +Filename : `src/foo.nr` + +```rust +mod bar; +fn from_foo() {} +``` + +Filename : `src/foo/bar.nr` + +```rust +fn from_bar() {} +``` + +In the above snippet, we have added an extra module to the module tree; `bar`. `bar` is a submodule +of `foo` hence we declare bar in `foo.nr` with `mod bar`. Since `foo` is not the crate root, the +compiler looks for the file associated with the `bar` module in `src/foo/bar.nr` + +Visually the module hierarchy looks as follows: + +``` +crate + ├── main + │ + └── foo + ├── from_foo + └── bar + └── from_bar +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/workspaces.md b/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/workspaces.md new file mode 100644 index 00000000000..67a1dafa372 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/modules_packages_crates/workspaces.md @@ -0,0 +1,40 @@ +--- +title: Workspaces +sidebar_position: 3 +--- + +Workspaces are a feature of nargo that allow you to manage multiple related Noir packages in a single repository. A workspace is essentially a group of related projects that share common build output directories and configurations. + +Each Noir project (with it's own Nargo.toml file) can be thought of as a package. Each package is expected to contain exactly one "named circuit", being the "name" defined in Nargo.toml with the program logic defined in `./src/main.nr`. + +For a project with the following structure: + +```tree +├── crates +│   ├── a +│   │   ├── Nargo.toml +│   │   └── src +│   │   └── main.nr +│   └── b +│   ├── Nargo.toml +│   └── src +│   └── main.nr +├── Nargo.toml +└── Prover.toml +``` + +You can define a workspace in Nargo.toml like so: + +```toml +[workspace] +members = ["crates/a", "crates/b"] +default-member = "crates/a" +``` + +`members` indicates which packages are included in the workspace. As such, all member packages of a workspace will be processed when the `--workspace` flag is used with various commands or if a `default-member` is not specified. + +`default-member` indicates which package various commands process by default. + +Libraries can be defined in a workspace. Inside a workspace, these are consumed as `{ path = "../to_lib" }` dependencies in Nargo.toml. + +Inside a workspace, these are consumed as `{ path = "../to_lib" }` dependencies in Nargo.toml. diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/_category_.json b/docs/versioned_docs/version-v0.25.0/noir/standard_library/_category_.json new file mode 100644 index 00000000000..af04c0933fd --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/_category_.json @@ -0,0 +1,6 @@ +{ + "label": "Standard Library", + "position": 1, + "collapsible": true, + "collapsed": true +} diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/black_box_fns.md b/docs/versioned_docs/version-v0.25.0/noir/standard_library/black_box_fns.md new file mode 100644 index 00000000000..be8c65679c3 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/black_box_fns.md @@ -0,0 +1,31 @@ +--- +title: Black Box Functions +description: Black box functions are functions in Noir that rely on backends implementing support for specialized constraints. +keywords: [noir, black box functions] +--- + +Black box functions are functions in Noir that rely on backends implementing support for specialized constraints. This makes certain zk-snark unfriendly computations cheaper than if they were implemented in Noir. + +The ACVM spec defines a set of blackbox functions which backends will be expected to implement. This allows backends to use optimized implementations of these constraints if they have them, however they may also fallback to less efficient naive implementations if not. + +## Function list + +Here is a list of the current black box functions: + +- [SHA256](./cryptographic_primitives/hashes.mdx#sha256) +- [Schnorr signature verification](./cryptographic_primitives/schnorr.mdx) +- [Blake2s](./cryptographic_primitives/hashes.mdx#blake2s) +- [Blake3](./cryptographic_primitives/hashes.mdx#blake3) +- [Pedersen Hash](./cryptographic_primitives/hashes.mdx#pedersen_hash) +- [Pedersen Commitment](./cryptographic_primitives/hashes.mdx#pedersen_commitment) +- [ECDSA signature verification](./cryptographic_primitives/ecdsa_sig_verification.mdx) +- [Fixed base scalar multiplication](./cryptographic_primitives/scalar.mdx) +- AND +- XOR +- RANGE +- [Keccak256](./cryptographic_primitives/hashes.mdx#keccak256) +- [Recursive proof verification](./recursion) + +Most black box functions are included as part of the Noir standard library, however `AND`, `XOR` and `RANGE` are used as part of the Noir language syntax. For instance, using the bitwise operator `&` will invoke the `AND` black box function. + +You can view the black box functions defined in the ACVM code [here](https://github.com/noir-lang/noir/blob/master/acvm-repo/acir/src/circuit/black_box_functions.rs). diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/bn254.md b/docs/versioned_docs/version-v0.25.0/noir/standard_library/bn254.md new file mode 100644 index 00000000000..3294f005dbb --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/bn254.md @@ -0,0 +1,46 @@ +--- +title: Bn254 Field Library +--- + +Noir provides a module in standard library with some optimized functions for bn254 Fr in `std::field::bn254`. + +## decompose + +```rust +fn decompose(x: Field) -> (Field, Field) {} +``` + +Decomposes a single field into two fields, low and high. The low field contains the lower 16 bytes of the input field and the high field contains the upper 16 bytes of the input field. Both field results are range checked to 128 bits. + + +## assert_gt + +```rust +fn assert_gt(a: Field, b: Field) {} +``` + +Asserts that a > b. This will generate less constraints than using `assert(gt(a, b))`. + +## assert_lt + +```rust +fn assert_lt(a: Field, b: Field) {} +``` + +Asserts that a < b. This will generate less constraints than using `assert(lt(a, b))`. + +## gt + +```rust +fn gt(a: Field, b: Field) -> bool {} +``` + +Returns true if a > b. + +## lt + +```rust +fn lt(a: Field, b: Field) -> bool {} +``` + +Returns true if a < b. \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/containers/boundedvec.md b/docs/versioned_docs/version-v0.25.0/noir/standard_library/containers/boundedvec.md new file mode 100644 index 00000000000..ce4529f6e57 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/containers/boundedvec.md @@ -0,0 +1,326 @@ +--- +title: Bounded Vectors +keywords: [noir, vector, bounded vector, slice] +sidebar_position: 1 +--- + +A `BoundedVec` is a growable storage similar to a `Vec` except that it +is bounded with a maximum possible length. Unlike `Vec`, `BoundedVec` is not implemented +via slices and thus is not subject to the same restrictions slices are (notably, nested +slices - and thus nested vectors as well - are disallowed). + +Since a BoundedVec is backed by a normal array under the hood, growing the BoundedVec by +pushing an additional element is also more efficient - the length only needs to be increased +by one. + +For these reasons `BoundedVec` should generally be preferred over `Vec` when there +is a reasonable maximum bound that can be placed on the vector. + +Example: + +```rust +let mut vector: BoundedVec = BoundedVec::new(); +for i in 0..5 { + vector.push(i); +} +assert(vector.len() == 5); +assert(vector.max_len() == 10); +``` + +## Methods + +### new + +```rust +pub fn new() -> Self +``` + +Creates a new, empty vector of length zero. + +Since this container is backed by an array internally, it still needs an initial value +to give each element. To resolve this, each element is zeroed internally. This value +is guaranteed to be inaccessible unless `get_unchecked` is used. + +Example: + +```rust +let empty_vector: BoundedVec = BoundedVec::new(); +assert(empty_vector.len() == 0); +``` + +Note that whenever calling `new` the maximum length of the vector should always be specified +via a type signature: + +```rust title="new_example" showLineNumbers +fn foo() -> BoundedVec { + // Ok! MaxLen is specified with a type annotation + let v1: BoundedVec = BoundedVec::new(); + let v2 = BoundedVec::new(); + + // Ok! MaxLen is known from the type of foo's return value + v2 +} + +fn bad() { + let mut v3 = BoundedVec::new(); + + // Not Ok! We don't know if v3's MaxLen is at least 1, and the compiler often infers 0 by default. + v3.push(5); +} +``` +> Source code: test_programs/noir_test_success/bounded_vec/src/main.nr#L11-L27 + + +This defaulting of `MaxLen` (and numeric generics in general) to zero may change in future noir versions +but for now make sure to use type annotations when using bounded vectors. Otherwise, you will receive a constraint failure at runtime when the vec is pushed to. + +### get + +```rust +pub fn get(mut self: Self, index: u64) -> T { +``` + +Retrieves an element from the vector at the given index, starting from zero. + +If the given index is equal to or greater than the length of the vector, this +will issue a constraint failure. + +Example: + +```rust +fn foo(v: BoundedVec) { + let first = v.get(0); + let last = v.get(v.len() - 1); + assert(first != last); +} +``` + +### get_unchecked + +```rust +pub fn get_unchecked(mut self: Self, index: u64) -> T { +``` + +Retrieves an element from the vector at the given index, starting from zero, without +performing a bounds check. + +Since this function does not perform a bounds check on length before accessing the element, +it is unsafe! Use at your own risk! + +Example: + +```rust title="get_unchecked_example" showLineNumbers +fn sum_of_first_three(v: BoundedVec) -> u32 { + // Always ensure the length is larger than the largest + // index passed to get_unchecked + assert(v.len() > 2); + let first = v.get_unchecked(0); + let second = v.get_unchecked(1); + let third = v.get_unchecked(2); + first + second + third +} +``` +> Source code: test_programs/noir_test_success/bounded_vec/src/main.nr#L54-L64 + + + +### push + +```rust +pub fn push(&mut self, elem: T) { +``` + +Pushes an element to the end of the vector. This increases the length +of the vector by one. + +Panics if the new length of the vector will be greater than the max length. + +Example: + +```rust title="bounded-vec-push-example" showLineNumbers +let mut v: BoundedVec = BoundedVec::new(); + + v.push(1); + v.push(2); + + // Panics with failed assertion "push out of bounds" + v.push(3); +``` +> Source code: test_programs/noir_test_success/bounded_vec/src/main.nr#L68-L76 + + +### pop + +```rust +pub fn pop(&mut self) -> T +``` + +Pops the element at the end of the vector. This will decrease the length +of the vector by one. + +Panics if the vector is empty. + +Example: + +```rust title="bounded-vec-pop-example" showLineNumbers +let mut v: BoundedVec = BoundedVec::new(); + v.push(1); + v.push(2); + + let two = v.pop(); + let one = v.pop(); + + assert(two == 2); + assert(one == 1); + // error: cannot pop from an empty vector + // let _ = v.pop(); +``` +> Source code: test_programs/noir_test_success/bounded_vec/src/main.nr#L81-L93 + + +### len + +```rust +pub fn len(self) -> u64 { +``` + +Returns the current length of this vector + +Example: + +```rust title="bounded-vec-len-example" showLineNumbers +let mut v: BoundedVec = BoundedVec::new(); + assert(v.len() == 0); + + v.push(100); + assert(v.len() == 1); + + v.push(200); + v.push(300); + v.push(400); + assert(v.len() == 4); + + let _ = v.pop(); + let _ = v.pop(); + assert(v.len() == 2); +``` +> Source code: test_programs/noir_test_success/bounded_vec/src/main.nr#L98-L113 + + +### max_len + +```rust +pub fn max_len(_self: BoundedVec) -> u64 { +``` + +Returns the maximum length of this vector. This is always +equal to the `MaxLen` parameter this vector was initialized with. + +Example: + +```rust title="bounded-vec-max-len-example" showLineNumbers +let mut v: BoundedVec = BoundedVec::new(); + + assert(v.max_len() == 5); + v.push(10); + assert(v.max_len() == 5); +``` +> Source code: test_programs/noir_test_success/bounded_vec/src/main.nr#L118-L124 + + +### storage + +```rust +pub fn storage(self) -> [T; MaxLen] { +``` + +Returns the internal array within this vector. +Since arrays in Noir are immutable, mutating the returned storage array will not mutate +the storage held internally by this vector. + +Note that uninitialized elements may be zeroed out! + +Example: + +```rust title="bounded-vec-storage-example" showLineNumbers +let mut v: BoundedVec = BoundedVec::new(); + + assert(v.storage() == [0, 0, 0, 0, 0]); + + v.push(57); + assert(v.storage() == [57, 0, 0, 0, 0]); +``` +> Source code: test_programs/noir_test_success/bounded_vec/src/main.nr#L129-L136 + + +### extend_from_array + +```rust +pub fn extend_from_array(&mut self, array: [T; Len]) +``` + +Pushes each element from the given array to this vector. + +Panics if pushing each element would cause the length of this vector +to exceed the maximum length. + +Example: + +```rust title="bounded-vec-extend-from-array-example" showLineNumbers +let mut vec: BoundedVec = BoundedVec::new(); + vec.extend_from_array([2, 4]); + + assert(vec.len == 2); + assert(vec.get(0) == 2); + assert(vec.get(1) == 4); +``` +> Source code: test_programs/noir_test_success/bounded_vec/src/main.nr#L141-L148 + + +### extend_from_bounded_vec + +```rust +pub fn extend_from_bounded_vec(&mut self, vec: BoundedVec) +``` + +Pushes each element from the other vector to this vector. The length of +the other vector is left unchanged. + +Panics if pushing each element would cause the length of this vector +to exceed the maximum length. + +Example: + +```rust title="bounded-vec-extend-from-bounded-vec-example" showLineNumbers +let mut v1: BoundedVec = BoundedVec::new(); + let mut v2: BoundedVec = BoundedVec::new(); + + v2.extend_from_array([1, 2, 3]); + v1.extend_from_bounded_vec(v2); + + assert(v1.storage() == [1, 2, 3, 0, 0]); + assert(v2.storage() == [1, 2, 3, 0, 0, 0, 0]); +``` +> Source code: test_programs/noir_test_success/bounded_vec/src/main.nr#L153-L162 + + +### any + +```rust +pub fn any(self, predicate: fn[Env](T) -> bool) -> bool +``` + +Returns true if the given predicate returns true for any element +in this vector. + +Example: + +```rust title="bounded-vec-any-example" showLineNumbers +let mut v: BoundedVec = BoundedVec::new(); + v.extend_from_array([2, 4, 6]); + + let all_even = !v.any(|elem: u32| elem % 2 != 0); + assert(all_even); +``` +> Source code: test_programs/noir_test_success/bounded_vec/src/main.nr#L229-L235 + diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/containers/hashmap.md b/docs/versioned_docs/version-v0.25.0/noir/standard_library/containers/hashmap.md new file mode 100644 index 00000000000..91604af765d --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/containers/hashmap.md @@ -0,0 +1,569 @@ +--- +title: HashMap +keywords: [noir, map, hash, hashmap] +sidebar_position: 1 +--- + +`HashMap` is used to efficiently store and look up key-value pairs. + +`HashMap` is a bounded type which can store anywhere from zero to `MaxLen` total elements. +Note that due to hash collisions, the actual maximum number of elements stored by any particular +hashmap is likely lower than `MaxLen`. This is true even with cryptographic hash functions since +every hash value will be performed modulo `MaxLen`. + +When creating `HashMap`s, the `MaxLen` generic should always be specified if it is not already +known. Otherwise, the compiler may infer a different value for `MaxLen` (such as zero), which +will likely change the result of the program. This behavior is set to become an error in future +versions instead. + +Example: + +```rust +// Create a mapping from Fields to u32s with a maximum length of 12 +// using a pedersen hash +let mut map: HashMap> = HashMap::default(); + +map.insert(1, 2); +map.insert(3, 4); + +let two = map.get(1).unwrap(); +``` + +## Methods + +### default + +```rust title="default" showLineNumbers +impl Default for HashMap +where + B: BuildHasher + Default, + H: Hasher + Default +{ + fn default() -> Self { +``` +> Source code: noir_stdlib/src/collections/map.nr#L462-L469 + + +Creates a fresh, empty HashMap. + +When using this function, always make sure to specify the maximum size of the hash map. + +This is the same `default` from the `Default` implementation given further below. It is +repeated here for convenience since it is the recommended way to create a hashmap. + +Example: + +```rust title="default_example" showLineNumbers +let hashmap: HashMap> = HashMap::default(); + assert(hashmap.is_empty()); +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L202-L205 + + +Because `HashMap` has so many generic arguments that are likely to be the same throughout +your program, it may be helpful to create a type alias: + +```rust title="type_alias" showLineNumbers +type MyMap = HashMap>; +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L196-L198 + + +### with_hasher + +```rust title="with_hasher" showLineNumbers +pub fn with_hasher(_build_hasher: B) -> Self + where + B: BuildHasher { +``` +> Source code: noir_stdlib/src/collections/map.nr#L82-L86 + + +Creates a hashmap with an existing `BuildHasher`. This can be used to ensure multiple +hashmaps are created with the same hasher instance. + +Example: + +```rust title="with_hasher_example" showLineNumbers +let my_hasher: BuildHasherDefault = Default::default(); + let hashmap: HashMap> = HashMap::with_hasher(my_hasher); + assert(hashmap.is_empty()); +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L207-L211 + + +### get + +```rust title="get" showLineNumbers +pub fn get( + self, + key: K + ) -> Option + where + K: Eq + Hash, + B: BuildHasher, + H: Hasher { +``` +> Source code: noir_stdlib/src/collections/map.nr#L278-L287 + + +Retrieves a value from the hashmap, returning `Option::none()` if it was not found. + +Example: + +```rust title="get_example" showLineNumbers +fn get_example(map: HashMap>) { + let x = map.get(12); + + if x.is_some() { + assert(x.unwrap() == 42); + } +} +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L299-L307 + + +### insert + +```rust title="insert" showLineNumbers +pub fn insert( + &mut self, + key: K, + value: V + ) + where + K: Eq + Hash, + B: BuildHasher, + H: Hasher { +``` +> Source code: noir_stdlib/src/collections/map.nr#L313-L323 + + +Inserts a new key-value pair into the map. If the key was already in the map, its +previous value will be overridden with the newly provided one. + +Example: + +```rust title="insert_example" showLineNumbers +let mut map: HashMap> = HashMap::default(); + map.insert(12, 42); + assert(map.len() == 1); +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L213-L217 + + +### remove + +```rust title="remove" showLineNumbers +pub fn remove( + &mut self, + key: K + ) + where + K: Eq + Hash, + B: BuildHasher, + H: Hasher { +``` +> Source code: noir_stdlib/src/collections/map.nr#L356-L365 + + +Removes the given key-value pair from the map. If the key was not already present +in the map, this does nothing. + +Example: + +```rust title="remove_example" showLineNumbers +map.remove(12); + assert(map.is_empty()); + + // If a key was not present in the map, remove does nothing + map.remove(12); + assert(map.is_empty()); +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L221-L228 + + +### is_empty + +```rust title="is_empty" showLineNumbers +pub fn is_empty(self) -> bool { +``` +> Source code: noir_stdlib/src/collections/map.nr#L115-L117 + + +True if the length of the hash map is empty. + +Example: + +```rust title="is_empty_example" showLineNumbers +assert(map.is_empty()); + + map.insert(1, 2); + assert(!map.is_empty()); + + map.remove(1); + assert(map.is_empty()); +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L230-L238 + + +### len + +```rust title="len" showLineNumbers +pub fn len(self) -> u64 { +``` +> Source code: noir_stdlib/src/collections/map.nr#L264-L266 + + +Returns the current length of this hash map. + +Example: + +```rust title="len_example" showLineNumbers +// This is equivalent to checking map.is_empty() + assert(map.len() == 0); + + map.insert(1, 2); + map.insert(3, 4); + map.insert(5, 6); + assert(map.len() == 3); + + // 3 was already present as a key in the hash map, so the length is unchanged + map.insert(3, 7); + assert(map.len() == 3); + + map.remove(1); + assert(map.len() == 2); +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L240-L255 + + +### capacity + +```rust title="capacity" showLineNumbers +pub fn capacity(_self: Self) -> u64 { +``` +> Source code: noir_stdlib/src/collections/map.nr#L271-L273 + + +Returns the maximum capacity of this hashmap. This is always equal to the capacity +specified in the hashmap's type. + +Unlike hashmaps in general purpose programming languages, hashmaps in Noir have a +static capacity that does not increase as the map grows larger. Thus, this capacity +is also the maximum possible element count that can be inserted into the hashmap. +Due to hash collisions (modulo the hashmap length), it is likely the actual maximum +element count will be lower than the full capacity. + +Example: + +```rust title="capacity_example" showLineNumbers +let empty_map: HashMap> = HashMap::default(); + assert(empty_map.len() == 0); + assert(empty_map.capacity() == 42); +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L257-L261 + + +### clear + +```rust title="clear" showLineNumbers +pub fn clear(&mut self) { +``` +> Source code: noir_stdlib/src/collections/map.nr#L93-L95 + + +Clears the hashmap, removing all key-value pairs from it. + +Example: + +```rust title="clear_example" showLineNumbers +assert(!map.is_empty()); + map.clear(); + assert(map.is_empty()); +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L263-L267 + + +### contains_key + +```rust title="contains_key" showLineNumbers +pub fn contains_key( + self, + key: K + ) -> bool + where + K: Hash + Eq, + B: BuildHasher, + H: Hasher { +``` +> Source code: noir_stdlib/src/collections/map.nr#L101-L110 + + +True if the hashmap contains the given key. Unlike `get`, this will not also return +the value associated with the key. + +Example: + +```rust title="contains_key_example" showLineNumbers +if map.contains_key(7) { + let value = map.get(7); + assert(value.is_some()); + } else { + println("No value for key 7!"); + } +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L269-L276 + + +### entries + +```rust title="entries" showLineNumbers +pub fn entries(self) -> BoundedVec<(K, V), N> { +``` +> Source code: noir_stdlib/src/collections/map.nr#L123-L125 + + +Returns a vector of each key-value pair present in the hashmap. + +The length of the returned vector is always equal to the length of the hashmap. + +Example: + +```rust title="entries_example" showLineNumbers +let entries = map.entries(); + + // The length of a hashmap may not be compile-time known, so we + // need to loop over its capacity instead + for i in 0..map.capacity() { + if i < entries.len() { + let (key, value) = entries.get(i); + println(f"{key} -> {value}"); + } + } +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L310-L321 + + +### keys + +```rust title="keys" showLineNumbers +pub fn keys(self) -> BoundedVec { +``` +> Source code: noir_stdlib/src/collections/map.nr#L144-L146 + + +Returns a vector of each key present in the hashmap. + +The length of the returned vector is always equal to the length of the hashmap. + +Example: + +```rust title="keys_example" showLineNumbers +let keys = map.keys(); + + for i in 0..keys.max_len() { + if i < keys.len() { + let key = keys.get_unchecked(i); + let value = map.get(key).unwrap_unchecked(); + println(f"{key} -> {value}"); + } + } +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L323-L333 + + +### values + +```rust title="values" showLineNumbers +pub fn values(self) -> BoundedVec { +``` +> Source code: noir_stdlib/src/collections/map.nr#L164-L166 + + +Returns a vector of each value present in the hashmap. + +The length of the returned vector is always equal to the length of the hashmap. + +Example: + +```rust title="values_example" showLineNumbers +let values = map.values(); + + for i in 0..values.max_len() { + if i < values.len() { + let value = values.get_unchecked(i); + println(f"Found value {value}"); + } + } +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L335-L344 + + +### iter_mut + +```rust title="iter_mut" showLineNumbers +pub fn iter_mut( + &mut self, + f: fn(K, V) -> (K, V) + ) + where + K: Eq + Hash, + B: BuildHasher, + H: Hasher { +``` +> Source code: noir_stdlib/src/collections/map.nr#L183-L192 + + +Iterates through each key-value pair of the HashMap, setting each key-value pair to the +result returned from the given function. + +Note that since keys can be mutated, the HashMap needs to be rebuilt as it is iterated +through. If this is not desired, use `iter_values_mut` if only values need to be mutated, +or `entries` if neither keys nor values need to be mutated. + +The iteration order is left unspecified. As a result, if two keys are mutated to become +equal, which of the two values that will be present for the key in the resulting map is also unspecified. + +Example: + +```rust title="iter_mut_example" showLineNumbers +// Add 1 to each key in the map, and double the value associated with that key. + map.iter_mut(|k, v| (k + 1, v * 2)); +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L348-L351 + + +### iter_keys_mut + +```rust title="iter_keys_mut" showLineNumbers +pub fn iter_keys_mut( + &mut self, + f: fn(K) -> K + ) + where + K: Eq + Hash, + B: BuildHasher, + H: Hasher { +``` +> Source code: noir_stdlib/src/collections/map.nr#L208-L217 + + +Iterates through the HashMap, mutating each key to the result returned from +the given function. + +Note that since keys can be mutated, the HashMap needs to be rebuilt as it is iterated +through. If only iteration is desired and the keys are not intended to be mutated, +prefer using `entries` instead. + +The iteration order is left unspecified. As a result, if two keys are mutated to become +equal, which of the two values that will be present for the key in the resulting map is also unspecified. + +Example: + +```rust title="iter_keys_mut_example" showLineNumbers +// Double each key, leaving the value associated with that key untouched + map.iter_keys_mut(|k| k * 2); +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L353-L356 + + +### iter_values_mut + +```rust title="iter_values_mut" showLineNumbers +pub fn iter_values_mut(&mut self, f: fn(V) -> V) { +``` +> Source code: noir_stdlib/src/collections/map.nr#L233-L235 + + +Iterates through the HashMap, applying the given function to each value and mutating the +value to equal the result. This function is more efficient than `iter_mut` and `iter_keys_mut` +because the keys are untouched and the underlying hashmap thus does not need to be reordered. + +Example: + +```rust title="iter_values_mut_example" showLineNumbers +// Halve each value + map.iter_values_mut(|v| v / 2); +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L358-L361 + + +### retain + +```rust title="retain" showLineNumbers +pub fn retain(&mut self, f: fn(K, V) -> bool) { +``` +> Source code: noir_stdlib/src/collections/map.nr#L247-L249 + + +Retains only the key-value pairs for which the given function returns true. +Any key-value pairs for which the function returns false will be removed from the map. + +Example: + +```rust title="retain_example" showLineNumbers +map.retain(|k, v| (k != 0) & (v != 0)); +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L281-L283 + + +## Trait Implementations + +### default + +```rust title="default" showLineNumbers +impl Default for HashMap +where + B: BuildHasher + Default, + H: Hasher + Default +{ + fn default() -> Self { +``` +> Source code: noir_stdlib/src/collections/map.nr#L462-L469 + + +Constructs an empty HashMap. + +Example: + +```rust title="default_example" showLineNumbers +let hashmap: HashMap> = HashMap::default(); + assert(hashmap.is_empty()); +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L202-L205 + + +### eq + +```rust title="eq" showLineNumbers +impl Eq for HashMap +where + K: Eq + Hash, + V: Eq, + B: BuildHasher, + H: Hasher +{ + fn eq(self, other: HashMap) -> bool { +``` +> Source code: noir_stdlib/src/collections/map.nr#L426-L435 + + +Checks if two HashMaps are equal. + +Example: + +```rust title="eq_example" showLineNumbers +let mut map1: HashMap> = HashMap::default(); + let mut map2: HashMap> = HashMap::default(); + + map1.insert(1, 2); + map1.insert(3, 4); + + map2.insert(3, 4); + map2.insert(1, 2); + + assert(map1 == map2); +``` +> Source code: test_programs/execution_success/hashmap/src/main.nr#L285-L296 + diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/containers/index.md b/docs/versioned_docs/version-v0.25.0/noir/standard_library/containers/index.md new file mode 100644 index 00000000000..ea84c6d5c21 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/containers/index.md @@ -0,0 +1,5 @@ +--- +title: Containers +description: Container types provided by Noir's standard library for storing and retrieving data +keywords: [containers, data types, vec, hashmap] +--- diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/containers/vec.mdx b/docs/versioned_docs/version-v0.25.0/noir/standard_library/containers/vec.mdx new file mode 100644 index 00000000000..1954f05bc76 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/containers/vec.mdx @@ -0,0 +1,151 @@ +--- +title: Vectors +description: Delve into the Vec data type in Noir. Learn about its methods, practical examples, and best practices for using Vectors in your Noir code. +keywords: [noir, vector type, methods, examples, dynamic arrays] +sidebar_position: 6 +--- + +import Experimental from '@site/src/components/Notes/_experimental.mdx'; + + + +A vector is a collection type similar to Rust's `Vec` type. In Noir, it is a convenient way to use slices as mutable arrays. + +Example: + +```rust +let mut vector: Vec = Vec::new(); +for i in 0..5 { + vector.push(i); +} +assert(vector.len() == 5); +``` + +## Methods + +### new + +Creates a new, empty vector. + +```rust +pub fn new() -> Self +``` + +Example: + +```rust +let empty_vector: Vec = Vec::new(); +assert(empty_vector.len() == 0); +``` + +### from_slice + +Creates a vector containing each element from a given slice. Mutations to the resulting vector will not affect the original slice. + +```rust +pub fn from_slice(slice: [T]) -> Self +``` + +Example: + +```rust +let arr: [Field] = [1, 2, 3]; +let vector_from_slice = Vec::from_slice(arr); +assert(vector_from_slice.len() == 3); +``` + +### len + +Returns the number of elements in the vector. + +```rust +pub fn len(self) -> Field +``` + +Example: + +```rust +let empty_vector: Vec = Vec::new(); +assert(empty_vector.len() == 0); +``` + +### get + +Retrieves an element from the vector at a given index. Panics if the index points beyond the vector's end. + +```rust +pub fn get(self, index: Field) -> T +``` + +Example: + +```rust +let vector: Vec = Vec::from_slice([10, 20, 30]); +assert(vector.get(1) == 20); +``` + +### push + +Adds a new element to the vector's end, returning a new vector with a length one greater than the original unmodified vector. + +```rust +pub fn push(&mut self, elem: T) +``` + +Example: + +```rust +let mut vector: Vec = Vec::new(); +vector.push(10); +assert(vector.len() == 1); +``` + +### pop + +Removes an element from the vector's end, returning a new vector with a length one less than the original vector, along with the removed element. Panics if the vector's length is zero. + +```rust +pub fn pop(&mut self) -> T +``` + +Example: + +```rust +let mut vector = Vec::from_slice([10, 20]); +let popped_elem = vector.pop(); +assert(popped_elem == 20); +assert(vector.len() == 1); +``` + +### insert + +Inserts an element at a specified index, shifting subsequent elements to the right. + +```rust +pub fn insert(&mut self, index: Field, elem: T) +``` + +Example: + +```rust +let mut vector = Vec::from_slice([10, 30]); +vector.insert(1, 20); +assert(vector.get(1) == 20); +``` + +### remove + +Removes an element at a specified index, shifting subsequent elements to the left, and returns the removed element. + +```rust +pub fn remove(&mut self, index: Field) -> T +``` + +Example: + +```rust +let mut vector = Vec::from_slice([10, 20, 30]); +let removed_elem = vector.remove(1); +assert(removed_elem == 20); +assert(vector.len() == 2); +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/_category_.json b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/_category_.json new file mode 100644 index 00000000000..5d694210bbf --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/_category_.json @@ -0,0 +1,5 @@ +{ + "position": 0, + "collapsible": true, + "collapsed": true +} diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/ec_primitives.md b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/ec_primitives.md new file mode 100644 index 00000000000..d2b42d67b7c --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/ec_primitives.md @@ -0,0 +1,102 @@ +--- +title: Elliptic Curve Primitives +keywords: [cryptographic primitives, Noir project] +sidebar_position: 4 +--- + +Data structures and methods on them that allow you to carry out computations involving elliptic +curves over the (mathematical) field corresponding to `Field`. For the field currently at our +disposal, applications would involve a curve embedded in BN254, e.g. the +[Baby Jubjub curve](https://eips.ethereum.org/EIPS/eip-2494). + +## Data structures + +### Elliptic curve configurations + +(`std::ec::{tecurve,montcurve,swcurve}::{affine,curvegroup}::Curve`), i.e. the specific elliptic +curve you want to use, which would be specified using any one of the methods +`std::ec::{tecurve,montcurve,swcurve}::{affine,curvegroup}::new` which take the coefficients in the +defining equation together with a generator point as parameters. You can find more detail in the +comments in +[`noir_stdlib/src/ec.nr`](https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/ec.nr), but +the gist of it is that the elliptic curves of interest are usually expressed in one of the standard +forms implemented here (Twisted Edwards, Montgomery and Short Weierstraß), and in addition to that, +you could choose to use `affine` coordinates (Cartesian coordinates - the usual (x,y) - possibly +together with a point at infinity) or `curvegroup` coordinates (some form of projective coordinates +requiring more coordinates but allowing for more efficient implementations of elliptic curve +operations). Conversions between all of these forms are provided, and under the hood these +conversions are done whenever an operation is more efficient in a different representation (or a +mixed coordinate representation is employed). + +### Points + +(`std::ec::{tecurve,montcurve,swcurve}::{affine,curvegroup}::Point`), i.e. points lying on the +elliptic curve. For a curve configuration `c` and a point `p`, it may be checked that `p` +does indeed lie on `c` by calling `c.contains(p1)`. + +## Methods + +(given a choice of curve representation, e.g. use `std::ec::tecurve::affine::Curve` and use +`std::ec::tecurve::affine::Point`) + +- The **zero element** is given by `Point::zero()`, and we can verify whether a point `p: Point` is + zero by calling `p.is_zero()`. +- **Equality**: Points `p1: Point` and `p2: Point` may be checked for equality by calling + `p1.eq(p2)`. +- **Addition**: For `c: Curve` and points `p1: Point` and `p2: Point` on the curve, adding these two + points is accomplished by calling `c.add(p1,p2)`. +- **Negation**: For a point `p: Point`, `p.negate()` is its negation. +- **Subtraction**: For `c` and `p1`, `p2` as above, subtracting `p2` from `p1` is accomplished by + calling `c.subtract(p1,p2)`. +- **Scalar multiplication**: For `c` as above, `p: Point` a point on the curve and `n: Field`, + scalar multiplication is given by `c.mul(n,p)`. If instead `n :: [u1; N]`, i.e. `n` is a bit + array, the `bit_mul` method may be used instead: `c.bit_mul(n,p)` +- **Multi-scalar multiplication**: For `c` as above and arrays `n: [Field; N]` and `p: [Point; N]`, + multi-scalar multiplication is given by `c.msm(n,p)`. +- **Coordinate representation conversions**: The `into_group` method converts a point or curve + configuration in the affine representation to one in the CurveGroup representation, and + `into_affine` goes in the other direction. +- **Curve representation conversions**: `tecurve` and `montcurve` curves and points are equivalent + and may be converted between one another by calling `into_montcurve` or `into_tecurve` on their + configurations or points. `swcurve` is more general and a curve c of one of the other two types + may be converted to this representation by calling `c.into_swcurve()`, whereas a point `p` lying + on the curve given by `c` may be mapped to its corresponding `swcurve` point by calling + `c.map_into_swcurve(p)`. +- **Map-to-curve methods**: The Elligator 2 method of mapping a field element `n: Field` into a + `tecurve` or `montcurve` with configuration `c` may be called as `c.elligator2_map(n)`. For all of + the curve configurations, the SWU map-to-curve method may be called as `c.swu_map(z,n)`, where + `z: Field` depends on `Field` and `c` and must be chosen by the user (the conditions it needs to + satisfy are specified in the comments + [here](https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/ec.nr)). + +## Examples + +The +[ec_baby_jubjub test](https://github.com/noir-lang/noir/blob/master/test_programs/compile_success_empty/ec_baby_jubjub/src/main.nr) +illustrates all of the above primitives on various forms of the Baby Jubjub curve. A couple of more +interesting examples in Noir would be: + +Public-key cryptography: Given an elliptic curve and a 'base point' on it, determine the public key +from the private key. This is a matter of using scalar multiplication. In the case of Baby Jubjub, +for example, this code would do: + +```rust +use dep::std::ec::tecurve::affine::{Curve, Point}; + +fn bjj_pub_key(priv_key: Field) -> Point +{ + + let bjj = Curve::new(168700, 168696, G::new(995203441582195749578291179787384436505546430278305826713579947235728471134,5472060717959818805561601436314318772137091100104008585924551046643952123905)); + + let base_pt = Point::new(5299619240641551281634865583518297030282874472190772894086521144482721001553, 16950150798460657717958625567821834550301663161624707787222815936182638968203); + + bjj.mul(priv_key,base_pt) +} +``` + +This would come in handy in a Merkle proof. + +- EdDSA signature verification: This is a matter of combining these primitives with a suitable hash + function. See + [feat(stdlib): EdDSA sig verification noir#1136](https://github.com/noir-lang/noir/pull/1136) for + the case of Baby Jubjub and the Poseidon hash function. diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/ecdsa_sig_verification.mdx b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/ecdsa_sig_verification.mdx new file mode 100644 index 00000000000..4bf09cef178 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/ecdsa_sig_verification.mdx @@ -0,0 +1,60 @@ +--- +title: ECDSA Signature Verification +description: Learn about the cryptographic primitives regarding ECDSA over the secp256k1 and secp256r1 curves +keywords: [cryptographic primitives, Noir project, ecdsa, secp256k1, secp256r1, signatures] +sidebar_position: 3 +--- + +import BlackBoxInfo from '@site/src/components/Notes/_blackbox.mdx'; + +Noir supports ECDSA signatures verification over the secp256k1 and secp256r1 curves. + +## ecdsa_secp256k1::verify_signature + +Verifier for ECDSA Secp256k1 signatures + +```rust title="ecdsa_secp256k1" showLineNumbers +pub fn verify_signature( + public_key_x: [u8; 32], + public_key_y: [u8; 32], + signature: [u8; 64], + message_hash: [u8; N] +) -> bool +``` +> Source code: noir_stdlib/src/ecdsa_secp256k1.nr#L2-L9 + + +example: + +```rust +fn main(hashed_message : [u8;32], pub_key_x : [u8;32], pub_key_y : [u8;32], signature : [u8;64]) { + let valid_signature = std::ecdsa_secp256k1::verify_signature(pub_key_x, pub_key_y, signature, hashed_message); + assert(valid_signature); +} +``` + +## ecdsa_secp256r1::verify_signature + +Verifier for ECDSA Secp256r1 signatures + +```rust title="ecdsa_secp256r1" showLineNumbers +pub fn verify_signature( + public_key_x: [u8; 32], + public_key_y: [u8; 32], + signature: [u8; 64], + message_hash: [u8; N] +) -> bool +``` +> Source code: noir_stdlib/src/ecdsa_secp256r1.nr#L2-L9 + + +example: + +```rust +fn main(hashed_message : [u8;32], pub_key_x : [u8;32], pub_key_y : [u8;32], signature : [u8;64]) { + let valid_signature = std::ecdsa_secp256r1::verify_signature(pub_key_x, pub_key_y, signature, hashed_message); + assert(valid_signature); +} +``` + + diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/eddsa.mdx b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/eddsa.mdx new file mode 100644 index 00000000000..c2c0624dfad --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/eddsa.mdx @@ -0,0 +1,37 @@ +--- +title: EdDSA Verification +description: Learn about the cryptographic primitives regarding EdDSA +keywords: [cryptographic primitives, Noir project, eddsa, signatures] +sidebar_position: 5 +--- + +import BlackBoxInfo from '@site/src/components/Notes/_blackbox.mdx'; + +## eddsa::eddsa_poseidon_verify + +Verifier for EdDSA signatures + +```rust +fn eddsa_poseidon_verify(public_key_x : Field, public_key_y : Field, signature_s: Field, signature_r8_x: Field, signature_r8_y: Field, message: Field) -> bool +``` + +It is also possible to specify the hash algorithm used for the signature by using the `eddsa_verify_with_hasher` function with a parameter implementing the Hasher trait. For instance, if you want to use Poseidon2 instead, you can do the following: +```rust +use dep::std::hash::poseidon2::Poseidon2Hasher; + +let mut hasher = Poseidon2Hasher::default(); +eddsa_verify_with_hasher(pub_key_a.x, pub_key_a.y, s_a, r8_a.x, r8_a.y, msg, &mut hasher); +``` + + + +## eddsa::eddsa_to_pub + +Private to public key conversion. + +Returns `(pub_key_x, pub_key_y)` + +```rust +fn eddsa_to_pub(secret : Field) -> (Field, Field) +``` + diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/hashes.mdx b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/hashes.mdx new file mode 100644 index 00000000000..119d8ccc70e --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/hashes.mdx @@ -0,0 +1,251 @@ +--- +title: Hash methods +description: + Learn about the cryptographic primitives ready to use for any Noir project, including sha256, + blake2s, pedersen, mimc_bn254 and mimc +keywords: + [cryptographic primitives, Noir project, sha256, blake2s, pedersen, mimc_bn254, mimc, hash] +sidebar_position: 0 +--- + +import BlackBoxInfo from '@site/src/components/Notes/_blackbox.mdx'; + +## sha256 + +Given an array of bytes, returns the resulting sha256 hash. + +```rust title="sha256" showLineNumbers +pub fn sha256(input: [u8; N]) -> [u8; 32] +``` +> Source code: noir_stdlib/src/hash.nr#L9-L11 + + +example: + +```rust +fn main() { + let x = [163, 117, 178, 149]; // some random bytes + let hash = std::hash::sha256(x); +} +``` + + + +## blake2s + +Given an array of bytes, returns an array with the Blake2 hash + +```rust title="blake2s" showLineNumbers +pub fn blake2s(input: [u8; N]) -> [u8; 32] +``` +> Source code: noir_stdlib/src/hash.nr#L15-L17 + + +example: + +```rust +fn main() { + let x = [163, 117, 178, 149]; // some random bytes + let hash = std::hash::blake2s(x); +} +``` + + + +## blake3 + +Given an array of bytes, returns an array with the Blake3 hash + +```rust title="blake3" showLineNumbers +pub fn blake3(input: [u8; N]) -> [u8; 32] +``` +> Source code: noir_stdlib/src/hash.nr#L21-L23 + + +example: + +```rust +fn main() { + let x = [163, 117, 178, 149]; // some random bytes + let hash = std::hash::blake3(x); +} +``` + + + +## pedersen_hash + +Given an array of Fields, returns the Pedersen hash. + +```rust title="pedersen_hash" showLineNumbers +pub fn pedersen_hash(input: [Field; N]) -> Field +``` +> Source code: noir_stdlib/src/hash.nr#L46-L48 + + +example: + +```rust title="pedersen-hash" showLineNumbers +use dep::std; + +fn main(x: Field, y: Field, expected_hash: Field) { + let hash = std::hash::pedersen_hash([x, y]); + assert_eq(hash, expected_hash); +} +``` +> Source code: test_programs/execution_success/pedersen_hash/src/main.nr#L1-L8 + + + + + +## pedersen_commitment + +Given an array of Fields, returns the Pedersen commitment. + +```rust title="pedersen_commitment" showLineNumbers +struct PedersenPoint { + x : Field, + y : Field, +} + +pub fn pedersen_commitment(input: [Field; N]) -> PedersenPoint +``` +> Source code: noir_stdlib/src/hash.nr#L26-L33 + + +example: + +```rust title="pedersen-commitment" showLineNumbers +use dep::std; + +fn main(x: Field, y: Field, expected_commitment: std::hash::PedersenPoint) { + let commitment = std::hash::pedersen_commitment([x, y]); + assert_eq(commitment.x, expected_commitment.x); + assert_eq(commitment.y, expected_commitment.y); +} +``` +> Source code: test_programs/execution_success/pedersen_commitment/src/main.nr#L1-L9 + + + + +## keccak256 + +Given an array of bytes (`u8`), returns the resulting keccak hash as an array of 32 bytes +(`[u8; 32]`). Specify a message_size to hash only the first `message_size` bytes +of the input. + +```rust title="keccak256" showLineNumbers +pub fn keccak256(input: [u8; N], message_size: u32) -> [u8; 32] +``` +> Source code: noir_stdlib/src/hash.nr#L71-L73 + + +example: + +```rust title="keccak256" showLineNumbers +use dep::std; + +fn main(x: Field, result: [u8; 32]) { + // We use the `as` keyword here to denote the fact that we want to take just the first byte from the x Field + // The padding is taken care of by the program + let digest = std::hash::keccak256([x as u8], 1); + assert(digest == result); + + //#1399: variable message size + let message_size = 4; + let hash_a = std::hash::keccak256([1, 2, 3, 4], message_size); + let hash_b = std::hash::keccak256([1, 2, 3, 4, 0, 0, 0, 0], message_size); + + assert(hash_a == hash_b); + + let message_size_big = 8; + let hash_c = std::hash::keccak256([1, 2, 3, 4, 0, 0, 0, 0], message_size_big); + + assert(hash_a != hash_c); +} +``` +> Source code: test_programs/execution_success/keccak256/src/main.nr#L1-L22 + + + + +## poseidon + +Given an array of Fields, returns a new Field with the Poseidon Hash. Mind that you need to specify +how many inputs are there to your Poseidon function. + +```rust +// example for hash_1, hash_2 accepts an array of length 2, etc +fn hash_1(input: [Field; 1]) -> Field +``` + +example: + +```rust title="poseidon" showLineNumbers +use dep::std::hash::poseidon; +use dep::std::hash::poseidon2; + +fn main(x1: [Field; 2], y1: pub Field, x2: [Field; 4], y2: pub Field, x3: [Field; 4], y3: Field) { + let hash1 = poseidon::bn254::hash_2(x1); + assert(hash1 == y1); + + let hash2 = poseidon::bn254::hash_4(x2); + assert(hash2 == y2); + + let hash3 = poseidon2::Poseidon2::hash(x3, x3.len()); + assert(hash3 == y3); +} +``` +> Source code: test_programs/execution_success/poseidon_bn254_hash/src/main.nr#L1-L15 + + +## poseidon 2 + +Given an array of Fields, returns a new Field with the Poseidon2 Hash. Contrary to the Poseidon +function, there is only one hash and you can specify a message_size to hash only the first +`message_size` bytes of the input, + +```rust +// example for hashing the first three elements of the input +Poseidon2::hash(input, 3); +``` + +The above example for Poseidon also includes Poseidon2. + +## mimc_bn254 and mimc + +`mimc_bn254` is `mimc`, but with hardcoded parameters for the BN254 curve. You can use it by +providing an array of Fields, and it returns a Field with the hash. You can use the `mimc` method if +you're willing to input your own constants: + +```rust +fn mimc(x: Field, k: Field, constants: [Field; N], exp : Field) -> Field +``` + +otherwise, use the `mimc_bn254` method: + +```rust +fn mimc_bn254(array: [Field; N]) -> Field +``` + +example: + +```rust + +fn main() { + let x = [163, 117, 178, 149]; // some random bytes + let hash = std::hash::mimc::mimc_bn254(x); +} +``` + +## hash_to_field + +```rust +fn hash_to_field(_input : [Field; N]) -> Field {} +``` + +Calculates the `blake2s` hash of the inputs and returns the hash modulo the field modulus to return +a value which can be represented as a `Field`. + diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/index.md b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/index.md new file mode 100644 index 00000000000..650f30165d5 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/index.md @@ -0,0 +1,14 @@ +--- +title: Cryptographic Primitives +description: + Learn about the cryptographic primitives ready to use for any Noir project +keywords: + [ + cryptographic primitives, + Noir project, + ] +--- + +The Noir team is progressively adding new cryptographic primitives to the standard library. Reach out for news or if you would be interested in adding more of these calculations in Noir. + +Some methods are available thanks to the Aztec backend, not being performed using Noir. When using other backends, these methods may or may not be supplied. diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/scalar.mdx b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/scalar.mdx new file mode 100644 index 00000000000..df411ca5443 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/scalar.mdx @@ -0,0 +1,33 @@ +--- +title: Scalar multiplication +description: See how you can perform scalar multiplications over a fixed base in Noir +keywords: [cryptographic primitives, Noir project, scalar multiplication] +sidebar_position: 1 +--- + +import BlackBoxInfo from '@site/src/components/Notes/_blackbox.mdx'; + +## scalar_mul::fixed_base_embedded_curve + +Performs scalar multiplication over the embedded curve whose coordinates are defined by the +configured noir field. For the BN254 scalar field, this is BabyJubJub or Grumpkin. + +```rust title="fixed_base_embedded_curve" showLineNumbers +pub fn fixed_base_embedded_curve( + low: Field, + high: Field +) -> [Field; 2] +``` +> Source code: noir_stdlib/src/scalar_mul.nr#L27-L32 + + +example + +```rust +fn main(x : Field) { + let scal = std::scalar_mul::fixed_base_embedded_curve(x); + println(scal); +} +``` + + diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/schnorr.mdx b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/schnorr.mdx new file mode 100644 index 00000000000..ae12e6c12dc --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/cryptographic_primitives/schnorr.mdx @@ -0,0 +1,45 @@ +--- +title: Schnorr Signatures +description: Learn how you can verify Schnorr signatures using Noir +keywords: [cryptographic primitives, Noir project, schnorr, signatures] +sidebar_position: 2 +--- + +import BlackBoxInfo from '@site/src/components/Notes/_blackbox.mdx'; + +## schnorr::verify_signature + +Verifier for Schnorr signatures over the embedded curve (for BN254 it is Grumpkin). + +```rust title="schnorr_verify" showLineNumbers +pub fn verify_signature( + public_key_x: Field, + public_key_y: Field, + signature: [u8; 64], + message: [u8; N] +) -> bool +``` +> Source code: noir_stdlib/src/schnorr.nr#L2-L9 + + +where `_signature` can be generated like so using the npm package +[@noir-lang/barretenberg](https://www.npmjs.com/package/@noir-lang/barretenberg) + +```js +const { BarretenbergWasm } = require('@noir-lang/barretenberg/dest/wasm'); +const { Schnorr } = require('@noir-lang/barretenberg/dest/crypto/schnorr'); + +... + +const barretenberg = await BarretenbergWasm.new(); +const schnorr = new Schnorr(barretenberg); +const pubKey = schnorr.computePublicKey(privateKey); +const message = ... +const signature = Array.from( + schnorr.constructSignature(hash, privateKey).toBuffer() +); + +... +``` + + diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/logging.md b/docs/versioned_docs/version-v0.25.0/noir/standard_library/logging.md new file mode 100644 index 00000000000..db75ef9f86f --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/logging.md @@ -0,0 +1,78 @@ +--- +title: Logging +description: + Learn how to use the println statement for debugging in Noir with this tutorial. Understand the + basics of logging in Noir and how to implement it in your code. +keywords: + [ + noir logging, + println statement, + print statement, + debugging in noir, + noir std library, + logging tutorial, + basic logging in noir, + noir logging implementation, + noir debugging techniques, + rust, + ] +--- + +The standard library provides two familiar statements you can use: `println` and `print`. Despite being a limited implementation of rust's `println!` and `print!` macros, these constructs can be useful for debugging. + +You can print the output of both statements in your Noir code by using the `nargo execute` command or the `--show-output` flag when using `nargo test` (provided there are print statements in your tests). + +It is recommended to use `nargo execute` if you want to debug failing constraints with `println` or `print` statements. This is due to every input in a test being a constant rather than a witness, so we issue an error during compilation while we only print during execution (which comes after compilation). Neither `println`, nor `print` are callable for failed constraints caught at compile time. + +Both `print` and `println` are generic functions which can work on integers, fields, strings, and even structs or expressions. Note however, that slices are currently unsupported. For example: + +```rust +struct Person { + age: Field, + height: Field, +} + +fn main(age: Field, height: Field) { + let person = Person { + age: age, + height: height, + }; + println(person); + println(age + height); + println("Hello world!"); +} +``` + +You can print different types in the same statement (including strings) with a type called `fmtstr`. It can be specified in the same way as a normal string, just prepended with an "f" character: + +```rust + let fmt_str = f"i: {i}, j: {j}"; + println(fmt_str); + + let s = myStruct { y: x, x: y }; + println(s); + + println(f"i: {i}, s: {s}"); + + println(x); + println([x, y]); + + let foo = fooStruct { my_struct: s, foo: 15 }; + println(f"s: {s}, foo: {foo}"); + + println(15); // prints 0x0f, implicit Field + println(-1 as u8); // prints 255 + println(-1 as i8); // prints -1 +``` + +Examples shown above are interchangeable between the two `print` statements: + +```rust +let person = Person { age : age, height : height }; + +println(person); +print(person); + +println("Hello world!"); // Prints with a newline at the end of the input +print("Hello world!"); // Prints the input and keeps cursor on the same line +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/merkle_trees.md b/docs/versioned_docs/version-v0.25.0/noir/standard_library/merkle_trees.md new file mode 100644 index 00000000000..fa488677884 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/merkle_trees.md @@ -0,0 +1,58 @@ +--- +title: Merkle Trees +description: Learn about Merkle Trees in Noir with this tutorial. Explore the basics of computing a merkle root using a proof, with examples. +keywords: + [ + Merkle trees in Noir, + Noir programming language, + check membership, + computing root from leaf, + Noir Merkle tree implementation, + Merkle tree tutorial, + Merkle tree code examples, + Noir libraries, + pedersen hash., + ] +--- + +## compute_merkle_root + +Returns the root of the tree from the provided leaf and its hash path, using a [Pedersen hash](./cryptographic_primitives/hashes.mdx#pedersen_hash). + +```rust +fn compute_merkle_root(leaf : Field, index : Field, hash_path: [Field]) -> Field +``` + +example: + +```rust +/** + // these values are for this example only + index = "0" + priv_key = "0x000000000000000000000000000000000000000000000000000000616c696365" + secret = "0x1929ea3ab8d9106a899386883d9428f8256cfedb3c4f6b66bf4aa4d28a79988f" + note_hash_path = [ + "0x1e61bdae0f027b1b2159e1f9d3f8d00fa668a952dddd822fda80dc745d6f65cc", + "0x0e4223f3925f98934393c74975142bd73079ab0621f4ee133cee050a3c194f1a", + "0x2fd7bb412155bf8693a3bd2a3e7581a679c95c68a052f835dddca85fa1569a40" + ] + */ +fn main(index: Field, priv_key: Field, secret: Field, note_hash_path: [Field; 3]) { + + let pubkey = std::scalar_mul::fixed_base_embedded_curve(priv_key); + let pubkey_x = pubkey[0]; + let pubkey_y = pubkey[1]; + let note_commitment = std::hash::pedersen([pubkey_x, pubkey_y, secret]); + + let root = std::merkle::compute_merkle_root(note_commitment[0], index, note_hash_path); + println(root); +} +``` + +To check merkle tree membership: + +1. Include a merkle root as a program input. +2. Compute the merkle root of a given leaf, index and hash path. +3. Assert the merkle roots are equal. + +For more info about merkle trees, see the Wikipedia [page](https://en.wikipedia.org/wiki/Merkle_tree). diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/options.md b/docs/versioned_docs/version-v0.25.0/noir/standard_library/options.md new file mode 100644 index 00000000000..a1bd4e1de5f --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/options.md @@ -0,0 +1,101 @@ +--- +title: Option Type +--- + +The `Option` type is a way to express that a value might be present (`Some(T))` or absent (`None`). It's a safer way to handle potential absence of values, compared to using nulls in many other languages. + +```rust +struct Option { + None, + Some(T), +} +``` + +The `Option` type, already imported into your Noir program, can be used directly: + +```rust +fn main() { + let none = Option::none(); + let some = Option::some(3); +} +``` + +See [this test](https://github.com/noir-lang/noir/blob/5cbfb9c4a06c8865c98ff2b594464b037d821a5c/crates/nargo_cli/tests/test_data/option/src/main.nr) for a more comprehensive set of examples of each of the methods described below. + +## Methods + +### none + +Constructs a none value. + +### some + +Constructs a some wrapper around a given value. + +### is_none + +Returns true if the Option is None. + +### is_some + +Returns true of the Option is Some. + +### unwrap + +Asserts `self.is_some()` and returns the wrapped value. + +### unwrap_unchecked + +Returns the inner value without asserting `self.is_some()`. This method can be useful within an if condition when we already know that `option.is_some()`. If the option is None, there is no guarantee what value will be returned, only that it will be of type T for an `Option`. + +### unwrap_or + +Returns the wrapped value if `self.is_some()`. Otherwise, returns the given default value. + +### unwrap_or_else + +Returns the wrapped value if `self.is_some()`. Otherwise, calls the given function to return a default value. + +### expect + +Asserts `self.is_some()` with a provided custom message and returns the contained `Some` value. The custom message is expected to be a format string. + +### map + +If self is `Some(x)`, this returns `Some(f(x))`. Otherwise, this returns `None`. + +### map_or + +If self is `Some(x)`, this returns `f(x)`. Otherwise, this returns the given default value. + +### map_or_else + +If self is `Some(x)`, this returns `f(x)`. Otherwise, this returns `default()`. + +### and + +Returns None if self is None. Otherwise, this returns `other`. + +### and_then + +If self is None, this returns None. Otherwise, this calls the given function with the Some value contained within self, and returns the result of that call. In some languages this function is called `flat_map` or `bind`. + +### or + +If self is Some, return self. Otherwise, return `other`. + +### or_else + +If self is Some, return self. Otherwise, return `default()`. + +### xor + +If only one of the two Options is Some, return that option. Otherwise, if both options are Some or both are None, None is returned. + +### filter + +Returns `Some(x)` if self is `Some(x)` and `predicate(x)` is true. Otherwise, this returns `None`. + +### flatten + +Flattens an `Option>` into a `Option`. This returns `None` if the outer Option is None. Otherwise, this returns the inner Option. diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/recursion.md b/docs/versioned_docs/version-v0.25.0/noir/standard_library/recursion.md new file mode 100644 index 00000000000..9337499dac8 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/recursion.md @@ -0,0 +1,88 @@ +--- +title: Recursive Proofs +description: Learn about how to write recursive proofs in Noir. +keywords: [recursion, recursive proofs, verification_key, verify_proof] +--- + +Noir supports recursively verifying proofs, meaning you verify the proof of a Noir program in another Noir program. This enables creating proofs of arbitrary size by doing step-wise verification of smaller components of a large proof. + +Read [the explainer on recursion](../../explainers/explainer-recursion.md) to know more about this function and the [guide on how to use it.](../../how_to/how-to-recursion.md) + +## The `#[recursive]` Attribute + +In Noir, the `#[recursive]` attribute is used to indicate that a circuit is designed for recursive proof generation. When applied, it informs the compiler and the tooling that the circuit should be compiled in a way that makes its proofs suitable for recursive verification. This attribute eliminates the need for manual flagging of recursion at the tooling level, streamlining the proof generation process for recursive circuits. + +### Example usage with `#[recursive]` + +```rust +#[recursive] +fn main(x: Field, y: pub Field) { + assert(x == y, "x and y are not equal"); +} + +// This marks the circuit as recursion-friendly and indicates that proofs generated from this circuit +// are intended for recursive verification. +``` + +By incorporating this attribute directly in the circuit's definition, tooling like Nargo and NoirJS can automatically execute recursive-specific duties for Noir programs (e.g. recursive-friendly proof artifact generation) without additional flags or configurations. + +## Verifying Recursive Proofs + +```rust +#[foreign(verify_proof)] +fn verify_proof(_verification_key : [Field], _proof : [Field], _public_input : Field, _key_hash : Field) {} +``` + +:::info + +This is a black box function. Read [this section](./black_box_fns) to learn more about black box functions in Noir. + +::: + +## Example usage + +```rust +use dep::std; + +fn main( + verification_key : [Field; 114], + proof : [Field; 93], + public_inputs : [Field; 1], + key_hash : Field, + proof_b : [Field; 93], +) { + std::verify_proof( + verification_key.as_slice(), + proof.as_slice(), + public_inputs.as_slice(), + key_hash + ); + + std::verify_proof( + verification_key.as_slice(), + proof_b.as_slice(), + public_inputs.as_slice(), + key_hash + ); +} +``` + +You can see a full example of recursive proofs in [this example recursion demo repo](https://github.com/noir-lang/noir-examples/tree/master/recursion). + +## Parameters + +### `verification_key` + +The verification key for the zk program that is being verified. + +### `proof` + +The proof for the zk program that is being verified. + +### `public_inputs` + +These represent the public inputs of the proof we are verifying. + +### `key_hash` + +A key hash is used to check the validity of the verification key. The circuit implementing this opcode can use this hash to ensure that the key provided to the circuit matches the key produced by the circuit creator. diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/traits.md b/docs/versioned_docs/version-v0.25.0/noir/standard_library/traits.md new file mode 100644 index 00000000000..ba9fa2ee841 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/traits.md @@ -0,0 +1,399 @@ +--- +title: Traits +description: Noir's stdlib provides a few commonly used traits. +keywords: [traits, trait, interface, protocol, default, add, eq] +--- + +## `std::default` + +### `std::default::Default` + +```rust title="default-trait" showLineNumbers +trait Default { + fn default() -> Self; +} +``` +> Source code: noir_stdlib/src/default.nr#L1-L5 + + +Constructs a default value of a type. + +Implementations: +```rust +impl Default for Field { .. } + +impl Default for i8 { .. } +impl Default for i16 { .. } +impl Default for i32 { .. } +impl Default for i64 { .. } + +impl Default for u8 { .. } +impl Default for u16 { .. } +impl Default for u32 { .. } +impl Default for u64 { .. } + +impl Default for () { .. } +impl Default for bool { .. } + +impl Default for [T; N] + where T: Default { .. } + +impl Default for (A, B) + where A: Default, B: Default { .. } + +impl Default for (A, B, C) + where A: Default, B: Default, C: Default { .. } + +impl Default for (A, B, C, D) + where A: Default, B: Default, C: Default, D: Default { .. } + +impl Default for (A, B, C, D, E) + where A: Default, B: Default, C: Default, D: Default, E: Default { .. } +``` + +For primitive integer types, the return value of `default` is `0`. Container +types such as arrays are filled with default values of their element type. + + +## `std::convert` + +### `std::convert::From` + +```rust title="from-trait" showLineNumbers +trait From { + fn from(input: T) -> Self; +} +``` +> Source code: noir_stdlib/src/convert.nr#L1-L5 + + +The `From` trait defines how to convert from a given type `T` to the type on which the trait is implemented. + +The Noir standard library provides a number of implementations of `From` between primitive types. +```rust title="from-impls" showLineNumbers +// Unsigned integers + +impl From for u32 { fn from(value: u8) -> u32 { value as u32 } } + +impl From for u64 { fn from(value: u8) -> u64 { value as u64 } } +impl From for u64 { fn from(value: u32) -> u64 { value as u64 } } + +impl From for Field { fn from(value: u8) -> Field { value as Field } } +impl From for Field { fn from(value: u32) -> Field { value as Field } } +impl From for Field { fn from(value: u64) -> Field { value as Field } } + +// Signed integers + +impl From for i32 { fn from(value: i8) -> i32 { value as i32 } } + +impl From for i64 { fn from(value: i8) -> i64 { value as i64 } } +impl From for i64 { fn from(value: i32) -> i64 { value as i64 } } + +// Booleans +impl From for u8 { fn from(value: bool) -> u8 { value as u8 } } +impl From for u32 { fn from(value: bool) -> u32 { value as u32 } } +impl From for u64 { fn from(value: bool) -> u64 { value as u64 } } +impl From for i8 { fn from(value: bool) -> i8 { value as i8 } } +impl From for i32 { fn from(value: bool) -> i32 { value as i32 } } +impl From for i64 { fn from(value: bool) -> i64 { value as i64 } } +impl From for Field { fn from(value: bool) -> Field { value as Field } } +``` +> Source code: noir_stdlib/src/convert.nr#L25-L52 + + +#### When to implement `From` + +As a general rule of thumb, `From` may be implemented in the [situations where it would be suitable in Rust](https://doc.rust-lang.org/std/convert/trait.From.html#when-to-implement-from): + +- The conversion is *infallible*: Noir does not provide an equivalent to Rust's `TryFrom`, if the conversion can fail then provide a named method instead. +- The conversion is *lossless*: semantically, it should not lose or discard information. For example, `u32: From` can losslessly convert any `u16` into a valid `u32` such that the original `u16` can be recovered. On the other hand, `u16: From` should not be implemented as `2**16` is a `u32` which cannot be losslessly converted into a `u16`. +- The conversion is *value-preserving*: the conceptual kind and meaning of the resulting value is the same, even though the Noir type and technical representation might be different. While it's possible to infallibly and losslessly convert a `u8` into a `str<2>` hex representation, `4u8` and `"04"` are too different for `str<2>: From` to be implemented. +- The conversion is *obvious*: it's the only reasonable conversion between the two types. If there's ambiguity on how to convert between them such that the same input could potentially map to two different values then a named method should be used. For instance rather than implementing `U128: From<[u8; 16]>`, the methods `U128::from_le_bytes` and `U128::from_be_bytes` are used as otherwise the endianness of the array would be ambiguous, resulting in two potential values of `U128` from the same byte array. + +One additional recommendation specific to Noir is: +- The conversion is *efficient*: it's relatively cheap to convert between the two types. Due to being a ZK DSL, it's more important to avoid unnecessary computation compared to Rust. If the implementation of `From` would encourage users to perform unnecessary conversion, resulting in additional proving time, then it may be preferable to expose functionality such that this conversion may be avoided. + +### `std::convert::Into` + +The `Into` trait is defined as the reciprocal of `From`. It should be easy to convince yourself that if we can convert to type `A` from type `B`, then it's possible to convert type `B` into type `A`. + +For this reason, implementing `From` on a type will automatically generate a matching `Into` implementation. One should always prefer implementing `From` over `Into` as implementing `Into` will not generate a matching `From` implementation. + +```rust title="into-trait" showLineNumbers +trait Into { + fn into(input: Self) -> T; +} + +impl Into for U where T: From { + fn into(input: U) -> T { + T::from(input) + } +} +``` +> Source code: noir_stdlib/src/convert.nr#L13-L23 + + +`Into` is most useful when passing function arguments where the types don't quite match up with what the function expects. In this case, the compiler has enough type information to perform the necessary conversion by just appending `.into()` onto the arguments in question. + + +## `std::cmp` + +### `std::cmp::Eq` + +```rust title="eq-trait" showLineNumbers +trait Eq { + fn eq(self, other: Self) -> bool; +} +``` +> Source code: noir_stdlib/src/cmp.nr#L1-L5 + + +Returns `true` if `self` is equal to `other`. Implementing this trait on a type +allows the type to be used with `==` and `!=`. + +Implementations: +```rust +impl Eq for Field { .. } + +impl Eq for i8 { .. } +impl Eq for i16 { .. } +impl Eq for i32 { .. } +impl Eq for i64 { .. } + +impl Eq for u8 { .. } +impl Eq for u16 { .. } +impl Eq for u32 { .. } +impl Eq for u64 { .. } + +impl Eq for () { .. } +impl Eq for bool { .. } + +impl Eq for [T; N] + where T: Eq { .. } + +impl Eq for (A, B) + where A: Eq, B: Eq { .. } + +impl Eq for (A, B, C) + where A: Eq, B: Eq, C: Eq { .. } + +impl Eq for (A, B, C, D) + where A: Eq, B: Eq, C: Eq, D: Eq { .. } + +impl Eq for (A, B, C, D, E) + where A: Eq, B: Eq, C: Eq, D: Eq, E: Eq { .. } +``` + +### `std::cmp::Ord` + +```rust title="ord-trait" showLineNumbers +trait Ord { + fn cmp(self, other: Self) -> Ordering; +} +``` +> Source code: noir_stdlib/src/cmp.nr#L92-L96 + + +`a.cmp(b)` compares two values returning `Ordering::less()` if `a < b`, +`Ordering::equal()` if `a == b`, or `Ordering::greater()` if `a > b`. +Implementing this trait on a type allows `<`, `<=`, `>`, and `>=` to be +used on values of the type. + +Implementations: + +```rust +impl Ord for u8 { .. } +impl Ord for u16 { .. } +impl Ord for u32 { .. } +impl Ord for u64 { .. } + +impl Ord for i8 { .. } +impl Ord for i16 { .. } +impl Ord for i32 { .. } + +impl Ord for i64 { .. } + +impl Ord for () { .. } +impl Ord for bool { .. } + +impl Ord for [T; N] + where T: Ord { .. } + +impl Ord for (A, B) + where A: Ord, B: Ord { .. } + +impl Ord for (A, B, C) + where A: Ord, B: Ord, C: Ord { .. } + +impl Ord for (A, B, C, D) + where A: Ord, B: Ord, C: Ord, D: Ord { .. } + +impl Ord for (A, B, C, D, E) + where A: Ord, B: Ord, C: Ord, D: Ord, E: Ord { .. } +``` + +## `std::ops` + +### `std::ops::Add`, `std::ops::Sub`, `std::ops::Mul`, and `std::ops::Div` + +These traits abstract over addition, subtraction, multiplication, and division respectively. +Implementing these traits for a given type will also allow that type to be used with the corresponding operator +for that trait (`+` for Add, etc) in addition to the normal method names. + +```rust title="add-trait" showLineNumbers +trait Add { + fn add(self, other: Self) -> Self; +} +``` +> Source code: noir_stdlib/src/ops.nr#L1-L5 + +```rust title="sub-trait" showLineNumbers +trait Sub { + fn sub(self, other: Self) -> Self; +} +``` +> Source code: noir_stdlib/src/ops.nr#L17-L21 + +```rust title="mul-trait" showLineNumbers +trait Mul { + fn mul(self, other: Self) -> Self; +} +``` +> Source code: noir_stdlib/src/ops.nr#L33-L37 + +```rust title="div-trait" showLineNumbers +trait Div { + fn div(self, other: Self) -> Self; +} +``` +> Source code: noir_stdlib/src/ops.nr#L49-L53 + + +The implementations block below is given for the `Add` trait, but the same types that implement +`Add` also implement `Sub`, `Mul`, and `Div`. + +Implementations: +```rust +impl Add for Field { .. } + +impl Add for i8 { .. } +impl Add for i16 { .. } +impl Add for i32 { .. } +impl Add for i64 { .. } + +impl Add for u8 { .. } +impl Add for u16 { .. } +impl Add for u32 { .. } +impl Add for u64 { .. } +``` + +### `std::ops::Rem` + +```rust title="rem-trait" showLineNumbers +trait Rem{ + fn rem(self, other: Self) -> Self; +} +``` +> Source code: noir_stdlib/src/ops.nr#L65-L69 + + +`Rem::rem(a, b)` is the remainder function returning the result of what is +left after dividing `a` and `b`. Implementing `Rem` allows the `%` operator +to be used with the implementation type. + +Unlike other numeric traits, `Rem` is not implemented for `Field`. + +Implementations: +```rust +impl Rem for u8 { fn rem(self, other: u8) -> u8 { self % other } } +impl Rem for u16 { fn rem(self, other: u16) -> u16 { self % other } } +impl Rem for u32 { fn rem(self, other: u32) -> u32 { self % other } } +impl Rem for u64 { fn rem(self, other: u64) -> u64 { self % other } } + +impl Rem for i8 { fn rem(self, other: i8) -> i8 { self % other } } +impl Rem for i16 { fn rem(self, other: i16) -> i16 { self % other } } +impl Rem for i32 { fn rem(self, other: i32) -> i32 { self % other } } +impl Rem for i64 { fn rem(self, other: i64) -> i64 { self % other } } +``` + +### `std::ops::{ BitOr, BitAnd, BitXor }` + +```rust title="bitor-trait" showLineNumbers +trait BitOr { + fn bitor(self, other: Self) -> Self; +} +``` +> Source code: noir_stdlib/src/ops.nr#L79-L83 + +```rust title="bitand-trait" showLineNumbers +trait BitAnd { + fn bitand(self, other: Self) -> Self; +} +``` +> Source code: noir_stdlib/src/ops.nr#L95-L99 + +```rust title="bitxor-trait" showLineNumbers +trait BitXor { + fn bitxor(self, other: Self) -> Self; +} +``` +> Source code: noir_stdlib/src/ops.nr#L111-L115 + + +Traits for the bitwise operations `|`, `&`, and `^`. + +Implementing `BitOr`, `BitAnd` or `BitXor` for a type allows the `|`, `&`, or `^` operator respectively +to be used with the type. + +The implementations block below is given for the `BitOr` trait, but the same types that implement +`BitOr` also implement `BitAnd` and `BitXor`. + +Implementations: +```rust +impl BitOr for bool { fn bitor(self, other: bool) -> bool { self | other } } + +impl BitOr for u8 { fn bitor(self, other: u8) -> u8 { self | other } } +impl BitOr for u16 { fn bitor(self, other: u16) -> u16 { self | other } } +impl BitOr for u32 { fn bitor(self, other: u32) -> u32 { self | other } } +impl BitOr for u64 { fn bitor(self, other: u64) -> u64 { self | other } } + +impl BitOr for i8 { fn bitor(self, other: i8) -> i8 { self | other } } +impl BitOr for i16 { fn bitor(self, other: i16) -> i16 { self | other } } +impl BitOr for i32 { fn bitor(self, other: i32) -> i32 { self | other } } +impl BitOr for i64 { fn bitor(self, other: i64) -> i64 { self | other } } +``` + +### `std::ops::{ Shl, Shr }` + +```rust title="shl-trait" showLineNumbers +trait Shl { + fn shl(self, other: Self) -> Self; +} +``` +> Source code: noir_stdlib/src/ops.nr#L127-L131 + +```rust title="shr-trait" showLineNumbers +trait Shr { + fn shr(self, other: Self) -> Self; +} +``` +> Source code: noir_stdlib/src/ops.nr#L142-L146 + + +Traits for a bit shift left and bit shift right. + +Implementing `Shl` for a type allows the left shift operator (`<<`) to be used with the implementation type. +Similarly, implementing `Shr` allows the right shift operator (`>>`) to be used with the type. + +Note that bit shifting is not currently implemented for signed types. + +The implementations block below is given for the `Shl` trait, but the same types that implement +`Shl` also implement `Shr`. + +Implementations: +```rust +impl Shl for u8 { fn shl(self, other: u8) -> u8 { self << other } } +impl Shl for u16 { fn shl(self, other: u16) -> u16 { self << other } } +impl Shl for u32 { fn shl(self, other: u32) -> u32 { self << other } } +impl Shl for u64 { fn shl(self, other: u64) -> u64 { self << other } } +``` diff --git a/docs/versioned_docs/version-v0.25.0/noir/standard_library/zeroed.md b/docs/versioned_docs/version-v0.25.0/noir/standard_library/zeroed.md new file mode 100644 index 00000000000..97dab02dac2 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/noir/standard_library/zeroed.md @@ -0,0 +1,25 @@ +--- +title: Zeroed Function +description: + The zeroed function returns a zeroed value of any type. +keywords: + [ + zeroed + ] +--- + +Implements `fn zeroed() -> T` to return a zeroed value of any type. This function is generally unsafe to use as the zeroed bit pattern is not guaranteed to be valid for all types. It can however, be useful in cases when the value is guaranteed not to be used such as in a BoundedVec library implementing a growable vector, up to a certain length, backed by an array. The array can be initialized with zeroed values which are guaranteed to be inaccessible until the vector is pushed to. Similarly, enumerations in noir can be implemented using this method by providing zeroed values for the unused variants. + +You can access the function at `std::unsafe::zeroed`. + +This function currently supports the following types: + +- Field +- Bool +- Uint +- Array +- String +- Tuple +- Function + +Using it on other types could result in unexpected behavior. diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/.nojekyll b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/.nojekyll new file mode 100644 index 00000000000..e2ac6616add --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/.nojekyll @@ -0,0 +1 @@ +TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/classes/BarretenbergBackend.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/classes/BarretenbergBackend.md new file mode 100644 index 00000000000..d60940df3ea --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/classes/BarretenbergBackend.md @@ -0,0 +1,127 @@ +# BarretenbergBackend + +## Implements + +- [`Backend`](../interfaces/Backend.md) + +## Constructors + +### new BarretenbergBackend(acirCircuit, options) + +```ts +new BarretenbergBackend(acirCircuit, options): BarretenbergBackend +``` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `acirCircuit` | [`CompiledCircuit`](../type-aliases/CompiledCircuit.md) | +| `options` | [`BackendOptions`](../type-aliases/BackendOptions.md) | + +#### Returns + +[`BarretenbergBackend`](BarretenbergBackend.md) + +## Methods + +### destroy() + +```ts +destroy(): Promise +``` + +#### Returns + +`Promise`\<`void`\> + +#### Implementation of + +[`Backend`](../interfaces/Backend.md).[`destroy`](../interfaces/Backend.md#destroy) + +#### Description + +Destroys the backend + +*** + +### generateProof() + +```ts +generateProof(compressedWitness): Promise +``` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `compressedWitness` | `Uint8Array` | + +#### Returns + +`Promise`\<[`ProofData`](../type-aliases/ProofData.md)\> + +#### Description + +Generates a proof + +*** + +### generateRecursiveProofArtifacts() + +```ts +generateRecursiveProofArtifacts(proofData, numOfPublicInputs): Promise +``` + +Generates artifacts that will be passed to a circuit that will verify this proof. + +Instead of passing the proof and verification key as a byte array, we pass them +as fields which makes it cheaper to verify in a circuit. + +The proof that is passed here will have been created using a circuit +that has the #[recursive] attribute on its `main` method. + +The number of public inputs denotes how many public inputs are in the inner proof. + +#### Parameters + +| Parameter | Type | Default value | +| :------ | :------ | :------ | +| `proofData` | [`ProofData`](../type-aliases/ProofData.md) | `undefined` | +| `numOfPublicInputs` | `number` | `0` | + +#### Returns + +`Promise`\<`object`\> + +#### Example + +```typescript +const artifacts = await backend.generateRecursiveProofArtifacts(proof, numOfPublicInputs); +``` + +*** + +### verifyProof() + +```ts +verifyProof(proofData): Promise +``` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `proofData` | [`ProofData`](../type-aliases/ProofData.md) | + +#### Returns + +`Promise`\<`boolean`\> + +#### Description + +Verifies a proof + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/index.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/index.md new file mode 100644 index 00000000000..e32501acb71 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/index.md @@ -0,0 +1,46 @@ +# backend_barretenberg + +## Exports + +### Classes + +| Class | Description | +| :------ | :------ | +| [BarretenbergBackend](classes/BarretenbergBackend.md) | - | + +### Interfaces + +| Interface | Description | +| :------ | :------ | +| [Backend](interfaces/Backend.md) | - | + +### Type Aliases + +| Type alias | Description | +| :------ | :------ | +| [BackendOptions](type-aliases/BackendOptions.md) | - | +| [CompiledCircuit](type-aliases/CompiledCircuit.md) | - | +| [ProofData](type-aliases/ProofData.md) | - | + +## Functions + +### publicInputsToWitnessMap() + +```ts +publicInputsToWitnessMap(publicInputs, abi): WitnessMap +``` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `publicInputs` | `string`[] | +| `abi` | `Abi` | + +#### Returns + +`WitnessMap` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/interfaces/Backend.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/interfaces/Backend.md new file mode 100644 index 00000000000..3eb9645c8d2 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/interfaces/Backend.md @@ -0,0 +1,132 @@ +# Backend + +## Methods + +### destroy() + +```ts +destroy(): Promise +``` + +#### Returns + +`Promise`\<`void`\> + +#### Description + +Destroys the backend + +*** + +### generateFinalProof() + +```ts +generateFinalProof(decompressedWitness): Promise +``` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `decompressedWitness` | `Uint8Array` | + +#### Returns + +`Promise`\<[`ProofData`](../type-aliases/ProofData.md)\> + +#### Description + +Generates a final proof (not meant to be verified in another circuit) + +*** + +### generateIntermediateProof() + +```ts +generateIntermediateProof(decompressedWitness): Promise +``` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `decompressedWitness` | `Uint8Array` | + +#### Returns + +`Promise`\<[`ProofData`](../type-aliases/ProofData.md)\> + +#### Description + +Generates an intermediate proof (meant to be verified in another circuit) + +*** + +### generateIntermediateProofArtifacts() + +```ts +generateIntermediateProofArtifacts(proofData, numOfPublicInputs): Promise +``` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `proofData` | [`ProofData`](../type-aliases/ProofData.md) | +| `numOfPublicInputs` | `number` | + +#### Returns + +`Promise`\<`object`\> + +#### Description + +Retrieves the artifacts from a proof in the Field format + +*** + +### verifyFinalProof() + +```ts +verifyFinalProof(proofData): Promise +``` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `proofData` | [`ProofData`](../type-aliases/ProofData.md) | + +#### Returns + +`Promise`\<`boolean`\> + +#### Description + +Verifies a final proof + +*** + +### verifyIntermediateProof() + +```ts +verifyIntermediateProof(proofData): Promise +``` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `proofData` | [`ProofData`](../type-aliases/ProofData.md) | + +#### Returns + +`Promise`\<`boolean`\> + +#### Description + +Verifies an intermediate proof + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/type-aliases/BackendOptions.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/type-aliases/BackendOptions.md new file mode 100644 index 00000000000..b49a479f4f4 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/type-aliases/BackendOptions.md @@ -0,0 +1,21 @@ +# BackendOptions + +```ts +type BackendOptions: object; +``` + +## Description + +An options object, currently only used to specify the number of threads to use. + +## Type declaration + +| Member | Type | Description | +| :------ | :------ | :------ | +| `memory` | `object` | - | +| `memory.maximum` | `number` | - | +| `threads` | `number` | **Description**

Number of threads | + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/type-aliases/CompiledCircuit.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/type-aliases/CompiledCircuit.md new file mode 100644 index 00000000000..34e0dd04205 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/type-aliases/CompiledCircuit.md @@ -0,0 +1,20 @@ +# CompiledCircuit + +```ts +type CompiledCircuit: object; +``` + +## Description + +The representation of a compiled circuit + +## Type declaration + +| Member | Type | Description | +| :------ | :------ | :------ | +| `abi` | `Abi` | **Description**

ABI representation of the circuit | +| `bytecode` | `string` | **Description**

The bytecode of the circuit | + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/type-aliases/ProofData.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/type-aliases/ProofData.md new file mode 100644 index 00000000000..05cebbc4e94 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/type-aliases/ProofData.md @@ -0,0 +1,20 @@ +# ProofData + +```ts +type ProofData: object; +``` + +## Description + +The representation of a proof + +## Type declaration + +| Member | Type | Description | +| :------ | :------ | :------ | +| `proof` | `Uint8Array` | **Description**

An byte array representing the proof | +| `publicInputs` | `string`[] | **Description**

Public inputs of a proof | + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/typedoc-sidebar.cjs b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/typedoc-sidebar.cjs new file mode 100644 index 00000000000..2aaa55bccf6 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/backend_barretenberg/typedoc-sidebar.cjs @@ -0,0 +1,4 @@ +// @ts-check +/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ +const typedocSidebar = { items: [{"type":"category","label":"Classes","items":[{"type":"doc","id":"reference/NoirJS/backend_barretenberg/classes/BarretenbergBackend","label":"BarretenbergBackend"}]},{"type":"category","label":"Interfaces","items":[{"type":"doc","id":"reference/NoirJS/backend_barretenberg/interfaces/Backend","label":"Backend"}]},{"type":"category","label":"Type Aliases","items":[{"type":"doc","id":"reference/NoirJS/backend_barretenberg/type-aliases/BackendOptions","label":"BackendOptions"},{"type":"doc","id":"reference/NoirJS/backend_barretenberg/type-aliases/CompiledCircuit","label":"CompiledCircuit"},{"type":"doc","id":"reference/NoirJS/backend_barretenberg/type-aliases/ProofData","label":"ProofData"}]}]}; +module.exports = typedocSidebar.items; \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/.nojekyll b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/.nojekyll new file mode 100644 index 00000000000..e2ac6616add --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/.nojekyll @@ -0,0 +1 @@ +TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/classes/Noir.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/classes/Noir.md new file mode 100644 index 00000000000..421d274fff8 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/classes/Noir.md @@ -0,0 +1,132 @@ +# Noir + +## Constructors + +### new Noir(circuit, backend) + +```ts +new Noir(circuit, backend?): Noir +``` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `circuit` | [`CompiledCircuit`](../type-aliases/CompiledCircuit.md) | +| `backend`? | `Backend` | + +#### Returns + +[`Noir`](Noir.md) + +## Methods + +### destroy() + +```ts +destroy(): Promise +``` + +#### Returns + +`Promise`\<`void`\> + +#### Description + +Destroys the underlying backend instance. + +#### Example + +```typescript +await noir.destroy(); +``` + +*** + +### execute() + +```ts +execute(inputs, foreignCallHandler?): Promise +``` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `inputs` | [`InputMap`](../type-aliases/InputMap.md) | +| `foreignCallHandler`? | [`ForeignCallHandler`](../type-aliases/ForeignCallHandler.md) | + +#### Returns + +`Promise`\<`object`\> + +#### Description + +Allows to execute a circuit to get its witness and return value. + +#### Example + +```typescript +async execute(inputs) +``` + +*** + +### generateProof() + +```ts +generateProof(inputs, foreignCallHandler?): Promise +``` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `inputs` | [`InputMap`](../type-aliases/InputMap.md) | +| `foreignCallHandler`? | [`ForeignCallHandler`](../type-aliases/ForeignCallHandler.md) | + +#### Returns + +`Promise`\<[`ProofData`](../type-aliases/ProofData.md)\> + +#### Description + +Generates a witness and a proof given an object as input. + +#### Example + +```typescript +async generateProof(input) +``` + +*** + +### verifyProof() + +```ts +verifyProof(proofData): Promise +``` + +#### Parameters + +| Parameter | Type | +| :------ | :------ | +| `proofData` | [`ProofData`](../type-aliases/ProofData.md) | + +#### Returns + +`Promise`\<`boolean`\> + +#### Description + +Instantiates the verification key and verifies a proof. + +#### Example + +```typescript +async verifyProof(proof) +``` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/and.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/and.md new file mode 100644 index 00000000000..c783283e396 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/and.md @@ -0,0 +1,22 @@ +# and() + +```ts +and(lhs, rhs): string +``` + +Performs a bitwise AND operation between `lhs` and `rhs` + +## Parameters + +| Parameter | Type | Description | +| :------ | :------ | :------ | +| `lhs` | `string` | | +| `rhs` | `string` | | + +## Returns + +`string` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/blake2s256.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/blake2s256.md new file mode 100644 index 00000000000..7882d0da8d5 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/blake2s256.md @@ -0,0 +1,21 @@ +# blake2s256() + +```ts +blake2s256(inputs): Uint8Array +``` + +Calculates the Blake2s256 hash of the input bytes + +## Parameters + +| Parameter | Type | Description | +| :------ | :------ | :------ | +| `inputs` | `Uint8Array` | | + +## Returns + +`Uint8Array` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/ecdsa_secp256k1_verify.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/ecdsa_secp256k1_verify.md new file mode 100644 index 00000000000..5e3cd53e9d3 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/ecdsa_secp256k1_verify.md @@ -0,0 +1,28 @@ +# ecdsa\_secp256k1\_verify() + +```ts +ecdsa_secp256k1_verify( + hashed_msg, + public_key_x_bytes, + public_key_y_bytes, + signature): boolean +``` + +Verifies a ECDSA signature over the secp256k1 curve. + +## Parameters + +| Parameter | Type | Description | +| :------ | :------ | :------ | +| `hashed_msg` | `Uint8Array` | | +| `public_key_x_bytes` | `Uint8Array` | | +| `public_key_y_bytes` | `Uint8Array` | | +| `signature` | `Uint8Array` | | + +## Returns + +`boolean` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/ecdsa_secp256r1_verify.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/ecdsa_secp256r1_verify.md new file mode 100644 index 00000000000..0b20ff68957 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/ecdsa_secp256r1_verify.md @@ -0,0 +1,28 @@ +# ecdsa\_secp256r1\_verify() + +```ts +ecdsa_secp256r1_verify( + hashed_msg, + public_key_x_bytes, + public_key_y_bytes, + signature): boolean +``` + +Verifies a ECDSA signature over the secp256r1 curve. + +## Parameters + +| Parameter | Type | Description | +| :------ | :------ | :------ | +| `hashed_msg` | `Uint8Array` | | +| `public_key_x_bytes` | `Uint8Array` | | +| `public_key_y_bytes` | `Uint8Array` | | +| `signature` | `Uint8Array` | | + +## Returns + +`boolean` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/keccak256.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/keccak256.md new file mode 100644 index 00000000000..d10f155ce86 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/keccak256.md @@ -0,0 +1,21 @@ +# keccak256() + +```ts +keccak256(inputs): Uint8Array +``` + +Calculates the Keccak256 hash of the input bytes + +## Parameters + +| Parameter | Type | Description | +| :------ | :------ | :------ | +| `inputs` | `Uint8Array` | | + +## Returns + +`Uint8Array` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/sha256.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/sha256.md new file mode 100644 index 00000000000..6ba4ecac022 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/sha256.md @@ -0,0 +1,21 @@ +# sha256() + +```ts +sha256(inputs): Uint8Array +``` + +Calculates the SHA256 hash of the input bytes + +## Parameters + +| Parameter | Type | Description | +| :------ | :------ | :------ | +| `inputs` | `Uint8Array` | | + +## Returns + +`Uint8Array` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/xor.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/xor.md new file mode 100644 index 00000000000..8d762b895d3 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/functions/xor.md @@ -0,0 +1,22 @@ +# xor() + +```ts +xor(lhs, rhs): string +``` + +Performs a bitwise XOR operation between `lhs` and `rhs` + +## Parameters + +| Parameter | Type | Description | +| :------ | :------ | :------ | +| `lhs` | `string` | | +| `rhs` | `string` | | + +## Returns + +`string` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/index.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/index.md new file mode 100644 index 00000000000..d600e21b299 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/index.md @@ -0,0 +1,37 @@ +# noir_js + +## Exports + +### Classes + +| Class | Description | +| :------ | :------ | +| [Noir](classes/Noir.md) | - | + +### Type Aliases + +| Type alias | Description | +| :------ | :------ | +| [CompiledCircuit](type-aliases/CompiledCircuit.md) | - | +| [ForeignCallHandler](type-aliases/ForeignCallHandler.md) | A callback which performs an foreign call and returns the response. | +| [ForeignCallInput](type-aliases/ForeignCallInput.md) | - | +| [ForeignCallOutput](type-aliases/ForeignCallOutput.md) | - | +| [InputMap](type-aliases/InputMap.md) | - | +| [ProofData](type-aliases/ProofData.md) | - | +| [WitnessMap](type-aliases/WitnessMap.md) | - | + +### Functions + +| Function | Description | +| :------ | :------ | +| [and](functions/and.md) | Performs a bitwise AND operation between `lhs` and `rhs` | +| [blake2s256](functions/blake2s256.md) | Calculates the Blake2s256 hash of the input bytes | +| [ecdsa\_secp256k1\_verify](functions/ecdsa_secp256k1_verify.md) | Verifies a ECDSA signature over the secp256k1 curve. | +| [ecdsa\_secp256r1\_verify](functions/ecdsa_secp256r1_verify.md) | Verifies a ECDSA signature over the secp256r1 curve. | +| [keccak256](functions/keccak256.md) | Calculates the Keccak256 hash of the input bytes | +| [sha256](functions/sha256.md) | Calculates the SHA256 hash of the input bytes | +| [xor](functions/xor.md) | Performs a bitwise XOR operation between `lhs` and `rhs` | + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/CompiledCircuit.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/CompiledCircuit.md new file mode 100644 index 00000000000..34e0dd04205 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/CompiledCircuit.md @@ -0,0 +1,20 @@ +# CompiledCircuit + +```ts +type CompiledCircuit: object; +``` + +## Description + +The representation of a compiled circuit + +## Type declaration + +| Member | Type | Description | +| :------ | :------ | :------ | +| `abi` | `Abi` | **Description**

ABI representation of the circuit | +| `bytecode` | `string` | **Description**

The bytecode of the circuit | + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/ForeignCallHandler.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/ForeignCallHandler.md new file mode 100644 index 00000000000..812b8b16481 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/ForeignCallHandler.md @@ -0,0 +1,24 @@ +# ForeignCallHandler + +```ts +type ForeignCallHandler: (name, inputs) => Promise; +``` + +A callback which performs an foreign call and returns the response. + +## Parameters + +| Parameter | Type | Description | +| :------ | :------ | :------ | +| `name` | `string` | The identifier for the type of foreign call being performed. | +| `inputs` | [`ForeignCallInput`](ForeignCallInput.md)[] | An array of hex encoded inputs to the foreign call. | + +## Returns + +`Promise`\<[`ForeignCallOutput`](ForeignCallOutput.md)[]\> + +outputs - An array of hex encoded outputs containing the results of the foreign call. + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/ForeignCallInput.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/ForeignCallInput.md new file mode 100644 index 00000000000..dd95809186a --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/ForeignCallInput.md @@ -0,0 +1,9 @@ +# ForeignCallInput + +```ts +type ForeignCallInput: string[]; +``` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/ForeignCallOutput.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/ForeignCallOutput.md new file mode 100644 index 00000000000..b71fb78a946 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/ForeignCallOutput.md @@ -0,0 +1,9 @@ +# ForeignCallOutput + +```ts +type ForeignCallOutput: string | string[]; +``` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/InputMap.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/InputMap.md new file mode 100644 index 00000000000..c714e999d93 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/InputMap.md @@ -0,0 +1,13 @@ +# InputMap + +```ts +type InputMap: object; +``` + +## Index signature + + \[`key`: `string`\]: `InputValue` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/ProofData.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/ProofData.md new file mode 100644 index 00000000000..05cebbc4e94 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/ProofData.md @@ -0,0 +1,20 @@ +# ProofData + +```ts +type ProofData: object; +``` + +## Description + +The representation of a proof + +## Type declaration + +| Member | Type | Description | +| :------ | :------ | :------ | +| `proof` | `Uint8Array` | **Description**

An byte array representing the proof | +| `publicInputs` | `string`[] | **Description**

Public inputs of a proof | + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/WitnessMap.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/WitnessMap.md new file mode 100644 index 00000000000..258c46f9d0c --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/type-aliases/WitnessMap.md @@ -0,0 +1,9 @@ +# WitnessMap + +```ts +type WitnessMap: Map; +``` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/typedoc-sidebar.cjs b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/typedoc-sidebar.cjs new file mode 100644 index 00000000000..fe2629ddc9f --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_js/typedoc-sidebar.cjs @@ -0,0 +1,4 @@ +// @ts-check +/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ +const typedocSidebar = { items: [{"type":"category","label":"Classes","items":[{"type":"doc","id":"reference/NoirJS/noir_js/classes/Noir","label":"Noir"}]},{"type":"category","label":"Type Aliases","items":[{"type":"doc","id":"reference/NoirJS/noir_js/type-aliases/CompiledCircuit","label":"CompiledCircuit"},{"type":"doc","id":"reference/NoirJS/noir_js/type-aliases/ForeignCallHandler","label":"ForeignCallHandler"},{"type":"doc","id":"reference/NoirJS/noir_js/type-aliases/ForeignCallInput","label":"ForeignCallInput"},{"type":"doc","id":"reference/NoirJS/noir_js/type-aliases/ForeignCallOutput","label":"ForeignCallOutput"},{"type":"doc","id":"reference/NoirJS/noir_js/type-aliases/InputMap","label":"InputMap"},{"type":"doc","id":"reference/NoirJS/noir_js/type-aliases/ProofData","label":"ProofData"},{"type":"doc","id":"reference/NoirJS/noir_js/type-aliases/WitnessMap","label":"WitnessMap"}]},{"type":"category","label":"Functions","items":[{"type":"doc","id":"reference/NoirJS/noir_js/functions/and","label":"and"},{"type":"doc","id":"reference/NoirJS/noir_js/functions/blake2s256","label":"blake2s256"},{"type":"doc","id":"reference/NoirJS/noir_js/functions/ecdsa_secp256k1_verify","label":"ecdsa_secp256k1_verify"},{"type":"doc","id":"reference/NoirJS/noir_js/functions/ecdsa_secp256r1_verify","label":"ecdsa_secp256r1_verify"},{"type":"doc","id":"reference/NoirJS/noir_js/functions/keccak256","label":"keccak256"},{"type":"doc","id":"reference/NoirJS/noir_js/functions/sha256","label":"sha256"},{"type":"doc","id":"reference/NoirJS/noir_js/functions/xor","label":"xor"}]}]}; +module.exports = typedocSidebar.items; \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/.nojekyll b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/.nojekyll new file mode 100644 index 00000000000..e2ac6616add --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/.nojekyll @@ -0,0 +1 @@ +TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/functions/compile.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/functions/compile.md new file mode 100644 index 00000000000..6faf763b37f --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/functions/compile.md @@ -0,0 +1,51 @@ +# compile() + +```ts +compile( + fileManager, + projectPath?, + logFn?, +debugLogFn?): Promise +``` + +Compiles a Noir project + +## Parameters + +| Parameter | Type | Description | +| :------ | :------ | :------ | +| `fileManager` | `FileManager` | The file manager to use | +| `projectPath`? | `string` | The path to the project inside the file manager. Defaults to the root of the file manager | +| `logFn`? | `LogFn` | A logging function. If not provided, console.log will be used | +| `debugLogFn`? | `LogFn` | A debug logging function. If not provided, logFn will be used | + +## Returns + +`Promise`\<[`ProgramCompilationArtifacts`](../index.md#programcompilationartifacts)\> + +## Example + +```typescript +// Node.js + +import { compile_program, createFileManager } from '@noir-lang/noir_wasm'; + +const fm = createFileManager(myProjectPath); +const myCompiledCode = await compile_program(fm); +``` + +```typescript +// Browser + +import { compile_program, createFileManager } from '@noir-lang/noir_wasm'; + +const fm = createFileManager('/'); +for (const path of files) { + await fm.writeFile(path, await getFileAsStream(path)); +} +const myCompiledCode = await compile_program(fm); +``` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/functions/compile_contract.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/functions/compile_contract.md new file mode 100644 index 00000000000..7d0b39a43ef --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/functions/compile_contract.md @@ -0,0 +1,51 @@ +# compile\_contract() + +```ts +compile_contract( + fileManager, + projectPath?, + logFn?, +debugLogFn?): Promise +``` + +Compiles a Noir project + +## Parameters + +| Parameter | Type | Description | +| :------ | :------ | :------ | +| `fileManager` | `FileManager` | The file manager to use | +| `projectPath`? | `string` | The path to the project inside the file manager. Defaults to the root of the file manager | +| `logFn`? | `LogFn` | A logging function. If not provided, console.log will be used | +| `debugLogFn`? | `LogFn` | A debug logging function. If not provided, logFn will be used | + +## Returns + +`Promise`\<[`ContractCompilationArtifacts`](../index.md#contractcompilationartifacts)\> + +## Example + +```typescript +// Node.js + +import { compile_contract, createFileManager } from '@noir-lang/noir_wasm'; + +const fm = createFileManager(myProjectPath); +const myCompiledCode = await compile_contract(fm); +``` + +```typescript +// Browser + +import { compile_contract, createFileManager } from '@noir-lang/noir_wasm'; + +const fm = createFileManager('/'); +for (const path of files) { + await fm.writeFile(path, await getFileAsStream(path)); +} +const myCompiledCode = await compile_contract(fm); +``` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/functions/createFileManager.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/functions/createFileManager.md new file mode 100644 index 00000000000..7e65c1d69c7 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/functions/createFileManager.md @@ -0,0 +1,21 @@ +# createFileManager() + +```ts +createFileManager(dataDir): FileManager +``` + +Creates a new FileManager instance based on fs in node and memfs in the browser (via webpack alias) + +## Parameters + +| Parameter | Type | Description | +| :------ | :------ | :------ | +| `dataDir` | `string` | root of the file system | + +## Returns + +`FileManager` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/functions/inflateDebugSymbols.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/functions/inflateDebugSymbols.md new file mode 100644 index 00000000000..fcea9275341 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/functions/inflateDebugSymbols.md @@ -0,0 +1,21 @@ +# inflateDebugSymbols() + +```ts +inflateDebugSymbols(debugSymbols): any +``` + +Decompresses and decodes the debug symbols + +## Parameters + +| Parameter | Type | Description | +| :------ | :------ | :------ | +| `debugSymbols` | `string` | The base64 encoded debug symbols | + +## Returns + +`any` + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/index.md b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/index.md new file mode 100644 index 00000000000..b6e0f9d1bc0 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/index.md @@ -0,0 +1,49 @@ +# noir_wasm + +## Exports + +### Functions + +| Function | Description | +| :------ | :------ | +| [compile](functions/compile.md) | Compiles a Noir project | +| [compile\_contract](functions/compile_contract.md) | Compiles a Noir project | +| [createFileManager](functions/createFileManager.md) | Creates a new FileManager instance based on fs in node and memfs in the browser (via webpack alias) | +| [inflateDebugSymbols](functions/inflateDebugSymbols.md) | Decompresses and decodes the debug symbols | + +## References + +### compile\_program + +Renames and re-exports [compile](functions/compile.md) + +## Interfaces + +### ContractCompilationArtifacts + +The compilation artifacts of a given contract. + +#### Properties + +| Property | Type | Description | +| :------ | :------ | :------ | +| `contract` | `ContractArtifact` | The compiled contract. | +| `warnings` | `unknown`[] | Compilation warnings. | + +*** + +### ProgramCompilationArtifacts + +The compilation artifacts of a given program. + +#### Properties + +| Property | Type | Description | +| :------ | :------ | :------ | +| `name` | `string` | not part of the compilation output, injected later | +| `program` | `ProgramArtifact` | The compiled contract. | +| `warnings` | `unknown`[] | Compilation warnings. | + +*** + +Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/typedoc-sidebar.cjs b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/typedoc-sidebar.cjs new file mode 100644 index 00000000000..e0870710349 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/NoirJS/noir_wasm/typedoc-sidebar.cjs @@ -0,0 +1,4 @@ +// @ts-check +/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ +const typedocSidebar = { items: [{"type":"doc","id":"reference/NoirJS/noir_wasm/index","label":"API"},{"type":"category","label":"Functions","items":[{"type":"doc","id":"reference/NoirJS/noir_wasm/functions/compile","label":"compile"},{"type":"doc","id":"reference/NoirJS/noir_wasm/functions/compile_contract","label":"compile_contract"},{"type":"doc","id":"reference/NoirJS/noir_wasm/functions/createFileManager","label":"createFileManager"},{"type":"doc","id":"reference/NoirJS/noir_wasm/functions/inflateDebugSymbols","label":"inflateDebugSymbols"}]}]}; +module.exports = typedocSidebar.items; \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.25.0/reference/_category_.json b/docs/versioned_docs/version-v0.25.0/reference/_category_.json new file mode 100644 index 00000000000..5b6a20a609a --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/_category_.json @@ -0,0 +1,5 @@ +{ + "position": 4, + "collapsible": true, + "collapsed": true +} diff --git a/docs/versioned_docs/version-v0.25.0/reference/nargo_commands.md b/docs/versioned_docs/version-v0.25.0/reference/nargo_commands.md new file mode 100644 index 00000000000..8a309ef4e7e --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/reference/nargo_commands.md @@ -0,0 +1,380 @@ +--- +title: Nargo +description: + Noir CLI Commands for Noir Prover and Verifier to create, execute, prove and verify programs, + generate Solidity verifier smart contract and compile into JSON file containing ACIR + representation and ABI of circuit. +keywords: + [ + Nargo, + Noir CLI, + Noir Prover, + Noir Verifier, + generate Solidity verifier, + compile JSON file, + ACIR representation, + ABI of circuit, + TypeScript, + ] +sidebar_position: 0 +--- + +# Command-Line Help for `nargo` + +This document contains the help content for the `nargo` command-line program. + +**Command Overview:** + +* [`nargo`↴](#nargo) +* [`nargo backend`↴](#nargo-backend) +* [`nargo backend current`↴](#nargo-backend-current) +* [`nargo backend ls`↴](#nargo-backend-ls) +* [`nargo backend use`↴](#nargo-backend-use) +* [`nargo backend install`↴](#nargo-backend-install) +* [`nargo backend uninstall`↴](#nargo-backend-uninstall) +* [`nargo check`↴](#nargo-check) +* [`nargo fmt`↴](#nargo-fmt) +* [`nargo codegen-verifier`↴](#nargo-codegen-verifier) +* [`nargo compile`↴](#nargo-compile) +* [`nargo new`↴](#nargo-new) +* [`nargo init`↴](#nargo-init) +* [`nargo execute`↴](#nargo-execute) +* [`nargo prove`↴](#nargo-prove) +* [`nargo verify`↴](#nargo-verify) +* [`nargo test`↴](#nargo-test) +* [`nargo info`↴](#nargo-info) +* [`nargo lsp`↴](#nargo-lsp) + +## `nargo` + +Noir's package manager + +**Usage:** `nargo ` + +###### **Subcommands:** + +* `backend` — Install and select custom backends used to generate and verify proofs +* `check` — Checks the constraint system for errors +* `fmt` — Format the Noir files in a workspace +* `codegen-verifier` — Generates a Solidity verifier smart contract for the program +* `compile` — Compile the program and its secret execution trace into ACIR format +* `new` — Create a Noir project in a new directory +* `init` — Create a Noir project in the current directory +* `execute` — Executes a circuit to calculate its return value +* `prove` — Create proof for this program. The proof is returned as a hex encoded string +* `verify` — Given a proof and a program, verify whether the proof is valid +* `test` — Run the tests for this program +* `info` — Provides detailed information on a circuit +* `lsp` — Starts the Noir LSP server + +###### **Options:** + + + + +## `nargo backend` + +Install and select custom backends used to generate and verify proofs + +**Usage:** `nargo backend ` + +###### **Subcommands:** + +* `current` — Prints the name of the currently active backend +* `ls` — Prints the list of currently installed backends +* `use` — Select the backend to use +* `install` — Install a new backend from a URL +* `uninstall` — Uninstalls a backend + + + +## `nargo backend current` + +Prints the name of the currently active backend + +**Usage:** `nargo backend current` + + + +## `nargo backend ls` + +Prints the list of currently installed backends + +**Usage:** `nargo backend ls` + + + +## `nargo backend use` + +Select the backend to use + +**Usage:** `nargo backend use ` + +###### **Arguments:** + +* `` + + + +## `nargo backend install` + +Install a new backend from a URL + +**Usage:** `nargo backend install ` + +###### **Arguments:** + +* `` — The name of the backend to install +* `` — The URL from which to download the backend + + + +## `nargo backend uninstall` + +Uninstalls a backend + +**Usage:** `nargo backend uninstall ` + +###### **Arguments:** + +* `` — The name of the backend to uninstall + + + +## `nargo check` + +Checks the constraint system for errors + +**Usage:** `nargo check [OPTIONS]` + +###### **Options:** + +* `--package ` — The name of the package to check +* `--workspace` — Check all packages in the workspace +* `--expression-width ` — Override the expression width requested by the backend +* `--force` — Force a full recompilation +* `--print-acir` — Display the ACIR for compiled circuit +* `--deny-warnings` — Treat all warnings as errors +* `--silence-warnings` — Suppress warnings + + + +## `nargo fmt` + +Format the Noir files in a workspace + +**Usage:** `nargo fmt [OPTIONS]` + +###### **Options:** + +* `--check` — Run noirfmt in check mode + + + +## `nargo codegen-verifier` + +Generates a Solidity verifier smart contract for the program + +**Usage:** `nargo codegen-verifier [OPTIONS]` + +###### **Options:** + +* `--package ` — The name of the package to codegen +* `--workspace` — Codegen all packages in the workspace +* `--expression-width ` — Override the expression width requested by the backend +* `--force` — Force a full recompilation +* `--print-acir` — Display the ACIR for compiled circuit +* `--deny-warnings` — Treat all warnings as errors +* `--silence-warnings` — Suppress warnings + + + +## `nargo compile` + +Compile the program and its secret execution trace into ACIR format + +**Usage:** `nargo compile [OPTIONS]` + +###### **Options:** + +* `--package ` — The name of the package to compile +* `--workspace` — Compile all packages in the workspace +* `--expression-width ` — Override the expression width requested by the backend +* `--force` — Force a full recompilation +* `--print-acir` — Display the ACIR for compiled circuit +* `--deny-warnings` — Treat all warnings as errors +* `--silence-warnings` — Suppress warnings + + + +## `nargo new` + +Create a Noir project in a new directory + +**Usage:** `nargo new [OPTIONS] ` + +###### **Arguments:** + +* `` — The path to save the new project + +###### **Options:** + +* `--name ` — Name of the package [default: package directory name] +* `--lib` — Use a library template +* `--bin` — Use a binary template [default] +* `--contract` — Use a contract template + + + +## `nargo init` + +Create a Noir project in the current directory + +**Usage:** `nargo init [OPTIONS]` + +###### **Options:** + +* `--name ` — Name of the package [default: current directory name] +* `--lib` — Use a library template +* `--bin` — Use a binary template [default] +* `--contract` — Use a contract template + + + +## `nargo execute` + +Executes a circuit to calculate its return value + +**Usage:** `nargo execute [OPTIONS] [WITNESS_NAME]` + +###### **Arguments:** + +* `` — Write the execution witness to named file + +###### **Options:** + +* `-p`, `--prover-name ` — The name of the toml file which contains the inputs for the prover + + Default value: `Prover` +* `--package ` — The name of the package to execute +* `--workspace` — Execute all packages in the workspace +* `--expression-width ` — Override the expression width requested by the backend +* `--force` — Force a full recompilation +* `--print-acir` — Display the ACIR for compiled circuit +* `--deny-warnings` — Treat all warnings as errors +* `--silence-warnings` — Suppress warnings +* `--oracle-resolver ` — JSON RPC url to solve oracle calls + + + +## `nargo prove` + +Create proof for this program. The proof is returned as a hex encoded string + +**Usage:** `nargo prove [OPTIONS]` + +###### **Options:** + +* `-p`, `--prover-name ` — The name of the toml file which contains the inputs for the prover + + Default value: `Prover` +* `-v`, `--verifier-name ` — The name of the toml file which contains the inputs for the verifier + + Default value: `Verifier` +* `--verify` — Verify proof after proving +* `--package ` — The name of the package to prove +* `--workspace` — Prove all packages in the workspace +* `--expression-width ` — Override the expression width requested by the backend +* `--force` — Force a full recompilation +* `--print-acir` — Display the ACIR for compiled circuit +* `--deny-warnings` — Treat all warnings as errors +* `--silence-warnings` — Suppress warnings +* `--oracle-resolver ` — JSON RPC url to solve oracle calls + + + +## `nargo verify` + +Given a proof and a program, verify whether the proof is valid + +**Usage:** `nargo verify [OPTIONS]` + +###### **Options:** + +* `-v`, `--verifier-name ` — The name of the toml file which contains the inputs for the verifier + + Default value: `Verifier` +* `--package ` — The name of the package verify +* `--workspace` — Verify all packages in the workspace +* `--expression-width ` — Override the expression width requested by the backend +* `--force` — Force a full recompilation +* `--print-acir` — Display the ACIR for compiled circuit +* `--deny-warnings` — Treat all warnings as errors +* `--silence-warnings` — Suppress warnings + + + +## `nargo test` + +Run the tests for this program + +**Usage:** `nargo test [OPTIONS] [TEST_NAME]` + +###### **Arguments:** + +* `` — If given, only tests with names containing this string will be run + +###### **Options:** + +* `--show-output` — Display output of `println` statements +* `--exact` — Only run tests that match exactly +* `--package ` — The name of the package to test +* `--workspace` — Test all packages in the workspace +* `--expression-width ` — Override the expression width requested by the backend +* `--force` — Force a full recompilation +* `--print-acir` — Display the ACIR for compiled circuit +* `--deny-warnings` — Treat all warnings as errors +* `--silence-warnings` — Suppress warnings +* `--oracle-resolver ` — JSON RPC url to solve oracle calls + + + +## `nargo info` + +Provides detailed information on a circuit + +Current information provided: 1. The number of ACIR opcodes 2. Counts the final number gates in the circuit used by a backend + +**Usage:** `nargo info [OPTIONS]` + +###### **Options:** + +* `--package ` — The name of the package to detail +* `--workspace` — Detail all packages in the workspace +* `--expression-width ` — Override the expression width requested by the backend +* `--force` — Force a full recompilation +* `--print-acir` — Display the ACIR for compiled circuit +* `--deny-warnings` — Treat all warnings as errors +* `--silence-warnings` — Suppress warnings + + + +## `nargo lsp` + +Starts the Noir LSP server + +Starts an LSP server which allows IDEs such as VS Code to display diagnostics in Noir source. + +VS Code Noir Language Support: https://marketplace.visualstudio.com/items?itemName=noir-lang.vscode-noir + +**Usage:** `nargo lsp` + + + +
+ + + This document was generated automatically by + clap-markdown. + + diff --git a/docs/versioned_docs/version-v0.25.0/tutorials/noirjs_app.md b/docs/versioned_docs/version-v0.25.0/tutorials/noirjs_app.md new file mode 100644 index 00000000000..12beb476994 --- /dev/null +++ b/docs/versioned_docs/version-v0.25.0/tutorials/noirjs_app.md @@ -0,0 +1,279 @@ +--- +title: Building a web app with NoirJS +description: Learn how to setup a new app that uses Noir to generate and verify zero-knowledge SNARK proofs in a typescript or javascript environment. +keywords: [how to, guide, javascript, typescript, noir, barretenberg, zero-knowledge, proofs, app] +sidebar_position: 0 +pagination_next: noir/concepts/data_types/index +--- + +NoirJS is a set of packages meant to work both in a browser and a server environment. In this tutorial, we will build a simple web app using them. From here, you should get an idea on how to proceed with your own Noir projects! + +You can find the complete app code for this guide [here](https://github.com/noir-lang/tiny-noirjs-app). + +## Setup + +:::note + +Feel free to use whatever versions, just keep in mind that Nargo and the NoirJS packages are meant to be in sync. For example, Nargo 0.19.x matches `noir_js@0.19.x`, etc. + +In this guide, we will be pinned to 0.19.4. + +::: + +Before we start, we want to make sure we have Node and Nargo installed. + +We start by opening a terminal and executing `node --version`. If we don't get an output like `v20.10.0`, that means node is not installed. Let's do that by following the handy [nvm guide](https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script). + +As for `Nargo`, we can follow the the [Nargo guide](../getting_started/installation/index.md) to install it. If you're lazy, just paste this on a terminal and run `noirup`: + +```sh +curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash +``` + +Easy enough. Onwards! + +## Our project + +ZK is a powerful technology. An app that doesn't reveal one of the inputs to *anyone* is almost unbelievable, yet Noir makes it as easy as a single line of code. + +In fact, it's so simple that it comes nicely packaged in `nargo`. Let's do that! + +### Nargo + +Run: + +```nargo new circuit``` + +And... That's about it. Your program is ready to be compiled and run. + +To compile, let's `cd` into the `circuit` folder to enter our project, and call: + +```nargo compile``` + +This compiles our circuit into `json` format and add it to a new `target` folder. + +:::info + +At this point in the tutorial, your folder structure should look like this: + +```tree +. +└── circuit <---- our working directory + ├── Nargo.toml + ├── src + │ └── main.nr + └── target + └── circuit.json +``` + +::: + +### Node and Vite + +If you want to explore Nargo, feel free to go on a side-quest now and follow the steps in the +[getting started](../getting_started/hello_noir/index.md) guide. However, we want our app to run on the browser, so we need Vite. + +Vite is a powerful tool to generate static websites. While it provides all kinds of features, let's just go barebones with some good old vanilla JS. + +To do this this, go back to the previous folder (`cd ..`) and create a new vite project by running `npm create vite` and choosing "Vanilla" and "Javascript". + +You should see `vite-project` appear in your root folder. This seems like a good time to `cd` into it and install our NoirJS packages: + +```bash +npm i @noir-lang/backend_barretenberg@0.19.4 @noir-lang/noir_js@0.19.4 +``` + +:::info + +At this point in the tutorial, your folder structure should look like this: + +```tree +. +└── circuit + └── ...etc... +└── vite-project <---- our working directory + └── ...etc... +``` + +::: + +#### Some cleanup + +`npx create vite` is amazing but it creates a bunch of files we don't really need for our simple example. Actually, let's just delete everything except for `index.html`, `main.js` and `package.json`. I feel lighter already. + +![my heart is ready for you, noir.js](@site/static/img/memes/titanic.jpeg) + +## HTML + +Our app won't run like this, of course. We need some working HTML, at least. Let's open our broken-hearted `index.html` and replace everything with this code snippet: + +```html + + + + + + +

Noir app

+
+ + +
+
+

Logs

+

Proof

+
+ + +``` + +It *could* be a beautiful UI... Depending on which universe you live in. + +## Some good old vanilla Javascript + +Our love for Noir needs undivided attention, so let's just open `main.js` and delete everything (this is where the romantic scenery becomes a bit creepy). + +Start by pasting in this boilerplate code: + +```js +const setup = async () => { + await Promise.all([ + import("@noir-lang/noirc_abi").then(module => + module.default(new URL("@noir-lang/noirc_abi/web/noirc_abi_wasm_bg.wasm", import.meta.url).toString()) + ), + import("@noir-lang/acvm_js").then(module => + module.default(new URL("@noir-lang/acvm_js/web/acvm_js_bg.wasm", import.meta.url).toString()) + ) + ]); +} + +function display(container, msg) { + const c = document.getElementById(container); + const p = document.createElement('p'); + p.textContent = msg; + c.appendChild(p); +} + +document.getElementById('submitGuess').addEventListener('click', async () => { + try { + // here's where love happens + } catch(err) { + display("logs", "Oh 💔 Wrong guess") + } +}); + +``` + +The display function doesn't do much. We're simply manipulating our website to see stuff happening. For example, if the proof fails, it will simply log a broken heart 😢 + +As for the `setup` function, it's just a sad reminder that dealing with `wasm` on the browser is not as easy as it should. Just copy, paste, and forget. + +:::info + +At this point in the tutorial, your folder structure should look like this: + +```tree +. +└── circuit + └── ...same as above +└── vite-project + ├── main.js + ├── package.json + └── index.html +``` + +You'll see other files and folders showing up (like `package-lock.json`, `node_modules`) but you shouldn't have to care about those. + +::: + +## Some NoirJS + +We're starting with the good stuff now. If you've compiled the circuit as described above, you should have a `json` file we want to import at the very top of our `main.js` file: + +```ts +import circuit from '../circuit/target/circuit.json'; +``` + +[Noir is backend-agnostic](../index.mdx#whats-new-about-noir). We write Noir, but we also need a proving backend. That's why we need to import and instantiate the two dependencies we installed above: `BarretenbergBackend` and `Noir`. Let's import them right below: + +```js +import { BarretenbergBackend } from '@noir-lang/backend_barretenberg'; +import { Noir } from '@noir-lang/noir_js'; +``` + +And instantiate them inside our try-catch block: + +```ts +// try { +const backend = new BarretenbergBackend(circuit); +const noir = new Noir(circuit, backend); +// } +``` + +:::note + +For the remainder of the tutorial, everything will be happening inside the `try` block + +::: + +## Our app + +Now for the app itself. We're capturing whatever is in the input when people press the submit button. Just add this: + +```js +const x = parseInt(document.getElementById('guessInput').value); +const input = { x, y: 2 }; +``` + +Now we're ready to prove stuff! Let's feed some inputs to our circuit and calculate the proof: + +```js +await setup(); // let's squeeze our wasm inits here + +display('logs', 'Generating proof... ⌛'); +const proof = await noir.generateProof(input); +display('logs', 'Generating proof... ✅'); +display('results', proof.proof); +``` + +You're probably eager to see stuff happening, so go and run your app now! + +From your terminal, run `npm run dev`. If it doesn't open a browser for you, just visit `localhost:5173`. You should now see the worst UI ever, with an ugly input. + +![Getting Started 0](@site/static/img/noir_getting_started_1.png) + +Now, our circuit says `fn main(x: Field, y: pub Field)`. This means only the `y` value is public, and it's hardcoded above: `input = { x, y: 2 }`. In other words, you won't need to send your secret`x` to the verifier! + +By inputting any number other than 2 in the input box and clicking "submit", you should get a valid proof. Otherwise the proof won't even generate correctly. By the way, if you're human, you shouldn't be able to understand anything on the "proof" box. That's OK. We like you, human ❤️. + +## Verifying + +Time to celebrate, yes! But we shouldn't trust machines so blindly. Let's add these lines to see our proof being verified: + +```js +display('logs', 'Verifying proof... ⌛'); +const verification = await noir.verifyProof(proof); +if (verification) display('logs', 'Verifying proof... ✅'); +``` + +You have successfully generated a client-side Noir web app! + +![coded app without math knowledge](@site/static/img/memes/flextape.jpeg) + +## Further Reading + +You can see how noirjs is used in a full stack Next.js hardhat application in the [noir-starter repo here](https://github.com/noir-lang/noir-starter/tree/main/vite-hardhat). The example shows how to calculate a proof in the browser and verify it with a deployed Solidity verifier contract from noirjs. + +You should also check out the more advanced examples in the [noir-examples repo](https://github.com/noir-lang/noir-examples), where you'll find reference usage for some cool apps. diff --git a/docs/versioned_sidebars/version-v0.25.0-sidebars.json b/docs/versioned_sidebars/version-v0.25.0-sidebars.json new file mode 100644 index 00000000000..b16f79cc176 --- /dev/null +++ b/docs/versioned_sidebars/version-v0.25.0-sidebars.json @@ -0,0 +1,83 @@ +{ + "sidebar": [ + { + "type": "doc", + "id": "index" + }, + { + "type": "category", + "label": "Getting Started", + "items": [ + { + "type": "autogenerated", + "dirName": "getting_started" + } + ] + }, + { + "type": "category", + "label": "The Noir Language", + "items": [ + { + "type": "autogenerated", + "dirName": "noir" + } + ] + }, + { + "type": "html", + "value": "
", + "defaultStyle": true + }, + { + "type": "category", + "label": "How To Guides", + "items": [ + { + "type": "autogenerated", + "dirName": "how_to" + } + ] + }, + { + "type": "category", + "label": "Explainers", + "items": [ + { + "type": "autogenerated", + "dirName": "explainers" + } + ] + }, + { + "type": "category", + "label": "Tutorials", + "items": [ + { + "type": "autogenerated", + "dirName": "tutorials" + } + ] + }, + { + "type": "category", + "label": "Reference", + "items": [ + { + "type": "autogenerated", + "dirName": "reference" + } + ] + }, + { + "type": "html", + "value": "
", + "defaultStyle": true + }, + { + "type": "doc", + "id": "migration_notes", + "label": "Migration notes" + } + ] +} diff --git a/flake.nix b/flake.nix deleted file mode 100644 index 4c5db8bfaae..00000000000 --- a/flake.nix +++ /dev/null @@ -1,260 +0,0 @@ -{ - description = "Build the Noir programming language"; - - # All of these inputs (a.k.a. dependencies) need to align with inputs we - # use so they use the `inputs.*.follows` syntax to reference our inputs - inputs = { - nixpkgs = { - url = "github:NixOS/nixpkgs/nixos-23.05"; - }; - - flake-utils = { - url = "github:numtide/flake-utils"; - }; - - flake-compat = { - url = "github:edolstra/flake-compat"; - flake = false; - }; - - fenix = { - url = "github:nix-community/fenix"; - inputs = { - nixpkgs.follows = "nixpkgs"; - }; - }; - - crane = { - url = "github:ipetkov/crane"; - inputs = { - nixpkgs.follows = "nixpkgs"; - flake-utils.follows = "flake-utils"; - flake-compat.follows = "flake-compat"; - }; - }; - }; - - outputs = - { self, nixpkgs, crane, flake-utils, fenix, ... }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { - inherit system; - }; - - rustToolchain = fenix.packages.${system}.fromToolchainFile { - file = ./rust-toolchain.toml; - sha256 = "sha256-rLP8+fTxnPHoR96ZJiCa/5Ans1OojI7MLsmSqR2ip8o="; - }; - - craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; - - # The `self.rev` property is only available when the working tree is not dirty - GIT_COMMIT = if (self ? rev) then self.rev else "unknown"; - GIT_DIRTY = if (self ? rev) then "false" else "true"; - - extraBuildInputs = [ ] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ - # Need libiconv and apple Security on Darwin. See https://github.com/ipetkov/crane/issues/156 - pkgs.libiconv - pkgs.darwin.apple_sdk.frameworks.Security - ]; - - environment = { - # We enable backtraces on any failure for help with debugging - RUST_BACKTRACE = "1"; - - # We download the Wasm version of `acvm_backend` in the barretenberg releases for the ACVM `blackbox_solver` - BARRETENBERG_ARCHIVE = pkgs.fetchurl { - url = "https://github.com/AztecProtocol/barretenberg/releases/download/barretenberg-v0.4.5/acvm_backend.wasm.tar.gz"; - sha256 = "sha256-xONt5pTKWf/YbVnX/NXl/VNBbtKd+CP7CLkB1jf0RHw="; - }; - }; - - # Configuration shared between builds - config = { - # x-release-please-start-version - version = "0.24.0"; - # x-release-please-end - - src = pkgs.lib.cleanSourceWith { - src = craneLib.path ./.; - # Custom filter with various file extensions that we rely upon to build packages - # Currently: `.nr`, `.sol`, `.sh`, `.json`, `.md` and `.wasm` - filter = path: type: - (builtins.match ".*\.(nr|sol|sh|json|md|wasm)$" path != null) || (craneLib.filterCargoSources path type); - }; - - # TODO(#1198): It'd be nice to include these flags when running `cargo clippy` in a devShell. - cargoClippyExtraArgs = "--all-targets -- -D warnings"; - - # TODO(#1198): It'd be nice to include this flag when running `cargo test` in a devShell. - cargoTestExtraArgs = "--workspace"; - }; - - # Combine the environment and other configuration needed for Crane to build our Rust packages - nativeConfig = environment // config // { - nativeBuildInputs = [ ]; - - buildInputs = [ ] ++ extraBuildInputs; - }; - - # Combine the environmnet and other configuration needed for Crane to build our Wasm packages - wasmConfig = environment // config // { - CARGO_TARGET_DIR = "./target"; - - nativeBuildInputs = with pkgs; [ - which - git - jq - rustToolchain - wasm-bindgen-cli - binaryen - ]; - - buildInputs = [ ] ++ extraBuildInputs; - }; - - # Build *just* the cargo dependencies, so we can reuse all of that work between runs - native-cargo-artifacts = craneLib.buildDepsOnly (nativeConfig // { - pname = "nargo"; - }); - noirc-abi-wasm-cargo-artifacts = craneLib.buildDepsOnly (wasmConfig // { - pname = "noirc_abi_wasm"; - }); - acvm-js-cargo-artifacts = craneLib.buildDepsOnly (wasmConfig // { - pname = "acvm_js"; - }); - - nargo = craneLib.buildPackage (nativeConfig // { - pname = "nargo"; - - inherit GIT_COMMIT GIT_DIRTY; - - cargoArtifacts = native-cargo-artifacts; - - # We don't want to run tests because they don't work in the Nix sandbox - doCheck = false; - }); - - noirc_abi_wasm = craneLib.buildPackage (wasmConfig // rec { - pname = "noirc_abi_wasm"; - - inherit GIT_COMMIT GIT_DIRTY; - - cargoArtifacts = noirc-abi-wasm-cargo-artifacts; - - cargoExtraArgs = "--package ${pname} --target wasm32-unknown-unknown"; - - buildPhaseCargoCommand = '' - bash tooling/noirc_abi_wasm/buildPhaseCargoCommand.sh release - ''; - - installPhase = '' - bash tooling/noirc_abi_wasm/installPhase.sh - ''; - - # We don't want to run tests because they don't work in the Nix sandbox - doCheck = false; - }); - - acvm_js = craneLib.buildPackage (wasmConfig // rec { - pname = "acvm_js"; - - inherit GIT_COMMIT GIT_DIRTY; - - cargoArtifacts = acvm-js-cargo-artifacts; - - cargoExtraArgs = "--package ${pname} --target wasm32-unknown-unknown"; - - buildPhaseCargoCommand = '' - bash acvm-repo/acvm_js/buildPhaseCargoCommand.sh release - ''; - - installPhase = '' - bash acvm-repo/acvm_js/installPhase.sh - ''; - - # We don't want to run tests because they don't work in the Nix sandbox - doCheck = false; - }); - - wasm-bindgen-cli = pkgs.callPackage ./wasm-bindgen-cli.nix { - rustPlatform = pkgs.makeRustPlatform { - rustc = rustToolchain; - cargo = rustToolchain; - }; - }; - in - { - # We use `checks` to run `cargo clippy` and `cargo fmt` since we disable checks in the primary derivations - checks = { - cargo-clippy = craneLib.cargoClippy (nativeConfig // { - pname = "noir"; - - inherit GIT_COMMIT GIT_DIRTY; - - cargoArtifacts = native-cargo-artifacts; - }); - - cargo-fmt = craneLib.cargoFmt (nativeConfig // { - pname = "noir"; - - inherit GIT_COMMIT GIT_DIRTY; - - cargoArtifacts = native-cargo-artifacts; - }); - }; - - packages = { - default = nargo; - - # Nix flakes cannot build more than one derivation in one command (see https://github.com/NixOS/nix/issues/5591) - # so we use `symlinkJoin` to build everything as the "all" package. - all = pkgs.symlinkJoin { name = "all"; paths = [ nargo noirc_abi_wasm acvm_js ]; }; - all_wasm = pkgs.symlinkJoin { name = "all_wasm"; paths = [ noirc_abi_wasm acvm_js ]; }; - - # We also export individual packages to enable `nix build .#nargo -L`, etc. - inherit nargo; - inherit noirc_abi_wasm; - inherit acvm_js; - - # We expose the `*-cargo-artifacts` derivations so we can cache our cargo dependencies in CI - inherit native-cargo-artifacts; - inherit noirc-abi-wasm-cargo-artifacts; - inherit acvm-js-cargo-artifacts; - }; - - # Setup the environment to match the environment settings, the inputs from our checks derivations, - # and extra tooling via `nativeBuildInputs` - devShells.default = pkgs.mkShell (environment // { - inputsFrom = [ - nargo - noirc_abi_wasm - acvm_js - ]; - - # Additional tools that weren't included as `nativeBuildInputs` of any of the derivations in `inputsFrom` - nativeBuildInputs = with pkgs; [ - # Rust toolchain - rustToolchain - # Other tools - starship - yarn - nodejs-18_x - # Used by the `bb` binary - curl - gzip - # This ensures the right lldb is in the environment for running rust-lldb - llvmPackages.lldb - # Nix tools - nil - nixpkgs-fmt - ]; - - shellHook = '' - eval "$(starship init bash)" - ''; - }); - }); -} - diff --git a/noir_stdlib/src/array.nr b/noir_stdlib/src/array.nr index 3da4b649174..8a8a1fad01c 100644 --- a/noir_stdlib/src/array.nr +++ b/noir_stdlib/src/array.nr @@ -1,4 +1,4 @@ -use crate::cmp::{Ord}; +use crate::cmp::Ord; // TODO: Once we fully move to the new SSA pass this module can be removed and replaced // by the methods in the `slice` module @@ -52,14 +52,8 @@ impl [T; N] { result } - // Converts an array into a slice. - pub fn as_slice(self) -> [T] { - let mut slice = []; - for elem in self { - slice = slice.push_back(elem); - } - slice - } + #[builtin(as_slice)] + pub fn as_slice(self) -> [T] {} // Apply a function to each element of an array, returning a new array // containing the mapped elements. diff --git a/noir_stdlib/src/bigint.nr b/noir_stdlib/src/bigint.nr index 98237a54779..39ec40a1480 100644 --- a/noir_stdlib/src/bigint.nr +++ b/noir_stdlib/src/bigint.nr @@ -1,23 +1,24 @@ use crate::ops::{Add, Sub, Mul, Div}; use crate::cmp::Eq; -global bn254_fq = [0x47, 0xFD, 0x7C, 0xD8, 0x16, 0x8C, 0x20, 0x3C, 0x8d, 0xca, 0x71, 0x68, 0x91, 0x6a, 0x81, 0x97, - 0x5d, 0x58, 0x81, 0x81, 0xb6, 0x45, 0x50, 0xb8, 0x29, 0xa0, 0x31, 0xe1, 0x72, 0x4e, 0x64, 0x30]; -global bn254_fr = [0x01, 0x00, 0x00, 0x00, 0x3F, 0x59, 0x1F, 0x43, 0x09, 0x97, 0xB9, 0x79, 0x48, 0xE8, 0x33, 0x28, - 0x5D, 0x58, 0x81, 0x81, 0xB6, 0x45, 0x50, 0xB8, 0x29, 0xA0, 0x31, 0xE1, 0x72, 0x4E, 0x64, 0x30]; -global secpk1_fr = [0x41, 0x41, 0x36, 0xD0, 0x8C, 0x5E, 0xD2, 0xBF, 0x3B, 0xA0, 0x48, 0xAF, 0xE6, 0xDC, 0xAE, 0xBA, - 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]; -global secpk1_fq = [0x2F, 0xFC, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]; -global secpr1_fq = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF]; -global secpr1_fr = [0x51, 0x25, 0x63, 0xFC, 0xC2, 0xCA, 0xB9, 0xF3, 0x84, 0x9E, 0x17, 0xA7, 0xAD, 0xFA, 0xE6, 0xBC, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,0xFF, 0xFF, 0xFF, 0xFF]; - +global bn254_fq = &[0x47, 0xFD, 0x7C, 0xD8, 0x16, 0x8C, 0x20, 0x3C, 0x8d, 0xca, 0x71, 0x68, 0x91, 0x6a, 0x81, 0x97, + 0x5d, 0x58, 0x81, 0x81, 0xb6, 0x45, 0x50, 0xb8, 0x29, 0xa0, 0x31, 0xe1, 0x72, 0x4e, 0x64, 0x30]; +global bn254_fr = &[0x01, 0x00, 0x00, 0x00, 0x3F, 0x59, 0x1F, 0x43, 0x09, 0x97, 0xB9, 0x79, 0x48, 0xE8, 0x33, 0x28, + 0x5D, 0x58, 0x81, 0x81, 0xB6, 0x45, 0x50, 0xB8, 0x29, 0xA0, 0x31, 0xE1, 0x72, 0x4E, 0x64, 0x30]; +global secpk1_fr = &[0x41, 0x41, 0x36, 0xD0, 0x8C, 0x5E, 0xD2, 0xBF, 0x3B, 0xA0, 0x48, 0xAF, 0xE6, 0xDC, 0xAE, 0xBA, + 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]; +global secpk1_fq = &[0x2F, 0xFC, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]; +global secpr1_fq = &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF]; +global secpr1_fr = &[0x51, 0x25, 0x63, 0xFC, 0xC2, 0xCA, 0xB9, 0xF3, 0x84, 0x9E, 0x17, 0xA7, 0xAD, 0xFA, 0xE6, 0xBC, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,0xFF, 0xFF, 0xFF, 0xFF]; +// docs:start:big_int_definition struct BigInt { pointer: u32, modulus: u32, } +// docs:end:big_int_definition impl BigInt { #[builtin(bigint_add)] diff --git a/noir_stdlib/src/cmp.nr b/noir_stdlib/src/cmp.nr index 38316e5d6a8..dde29d7ee87 100644 --- a/noir_stdlib/src/cmp.nr +++ b/noir_stdlib/src/cmp.nr @@ -6,10 +6,10 @@ trait Eq { impl Eq for Field { fn eq(self, other: Field) -> bool { self == other } } -impl Eq for u1 { fn eq(self, other: u1) -> bool { self == other } } -impl Eq for u8 { fn eq(self, other: u8) -> bool { self == other } } -impl Eq for u32 { fn eq(self, other: u32) -> bool { self == other } } impl Eq for u64 { fn eq(self, other: u64) -> bool { self == other } } +impl Eq for u32 { fn eq(self, other: u32) -> bool { self == other } } +impl Eq for u8 { fn eq(self, other: u8) -> bool { self == other } } +impl Eq for u1 { fn eq(self, other: u1) -> bool { self == other } } impl Eq for i8 { fn eq(self, other: i8) -> bool { self == other } } impl Eq for i32 { fn eq(self, other: i32) -> bool { self == other } } @@ -28,6 +28,16 @@ impl Eq for [T; N] where T: Eq { } } +impl Eq for [T] where T: Eq { + fn eq(self, other: [T]) -> bool { + let mut result = self.len() == other.len(); + for i in 0 .. self.len() { + result &= self[i].eq(other[i]); + } + result + } +} + impl Eq for str { fn eq(self, other: str) -> bool { let self_bytes = self.as_bytes(); @@ -97,8 +107,8 @@ trait Ord { // Note: Field deliberately does not implement Ord -impl Ord for u8 { - fn cmp(self, other: u8) -> Ordering { +impl Ord for u64 { + fn cmp(self, other: u64) -> Ordering { if self < other { Ordering::less() } else if self > other { @@ -121,8 +131,8 @@ impl Ord for u32 { } } -impl Ord for u64 { - fn cmp(self, other: u64) -> Ordering { +impl Ord for u8 { + fn cmp(self, other: u8) -> Ordering { if self < other { Ordering::less() } else if self > other { @@ -213,6 +223,26 @@ impl Ord for [T; N] where T: Ord { } } +impl Ord for [T] where T: Ord { + // The first non-equal element of both arrays determines + // the ordering for the whole array. + fn cmp(self, other: [T]) -> Ordering { + let mut result = self.len().cmp(other.len()); + for i in 0 .. self.len() { + if result == Ordering::equal() { + let result_i = self[i].cmp(other[i]); + + if result_i == Ordering::less() { + result = result_i; + } else if result_i == Ordering::greater() { + result = result_i; + } + } + } + result + } +} + impl Ord for (A, B) where A: Ord, B: Ord { fn cmp(self, other: (A, B)) -> Ordering { let result = self.0.cmp(other.0); diff --git a/noir_stdlib/src/collections/bounded_vec.nr b/noir_stdlib/src/collections/bounded_vec.nr index 752b96d6591..6d5fbd44247 100644 --- a/noir_stdlib/src/collections/bounded_vec.nr +++ b/noir_stdlib/src/collections/bounded_vec.nr @@ -48,6 +48,15 @@ impl BoundedVec { self.len = new_len; } + pub fn extend_from_slice(&mut self, slice: [T]) { + let new_len = self.len + slice.len(); + assert(new_len as u64 <= MaxLen as u64, "extend_from_slice out of bounds"); + for i in 0..slice.len() { + self.storage[self.len + i] = slice[i]; + } + self.len = new_len; + } + pub fn extend_from_bounded_vec(&mut self, vec: BoundedVec) { let append_len = vec.len(); let new_len = self.len + append_len; diff --git a/noir_stdlib/src/collections/map.nr b/noir_stdlib/src/collections/map.nr index d9eb83ff5dc..5f8cc6dab62 100644 --- a/noir_stdlib/src/collections/map.nr +++ b/noir_stdlib/src/collections/map.nr @@ -3,6 +3,7 @@ use crate::collections::vec::Vec; use crate::option::Option; use crate::default::Default; use crate::hash::{Hash, Hasher, BuildHasher}; +use crate::collections::bounded_vec::BoundedVec; // We use load factor α_max = 0.75. // Upon exceeding it, assert will fail in order to inform the user @@ -78,21 +79,26 @@ impl Slot { // it is very unlikely to be after - performance will be heavily degraded. impl HashMap { // Creates a new instance of HashMap with specified BuildHasher. + // docs:start:with_hasher pub fn with_hasher(_build_hasher: B) -> Self where B: BuildHasher { + // docs:end:with_hasher let _table = [Slot::default(); N]; let _len = 0; Self { _table, _len, _build_hasher } } // Clears the map, removing all key-value entries. + // docs:start:clear pub fn clear(&mut self) { + // docs:end:clear self._table = [Slot::default(); N]; self._len = 0; } // Returns true if the map contains a value for the specified key. + // docs:start:contains_key pub fn contains_key( self, key: K @@ -101,89 +107,80 @@ impl HashMap { K: Hash + Eq, B: BuildHasher, H: Hasher { + // docs:end:contains_key self.get(key).is_some() } // Returns true if the map contains no elements. + // docs:start:is_empty pub fn is_empty(self) -> bool { + // docs:end:is_empty self._len == 0 } - // Get the Option<(K, V) array of valid entries - // with a length of map capacity. First len() elements - // are safe to unwrap_unchecked(), whilst remaining - // are guaranteed to be Option::none(). - // - // This design is reasoned by compile-time limitations and - // temporary nested slices ban. - pub fn entries(self) -> [Option<(K, V)>; N] { - let mut entries = [Option::none(); N]; - let mut valid_amount = 0; + // Returns a BoundedVec of all valid entries in this HashMap. + // The length of the returned vector will always match the length of this HashMap. + // docs:start:entries + pub fn entries(self) -> BoundedVec<(K, V), N> { + // docs:end:entries + let mut entries = BoundedVec::new(); for slot in self._table { if slot.is_valid() { - entries[valid_amount] = slot.key_value(); - valid_amount += 1; + // SAFETY: slot.is_valid() should ensure there is a valid key-value pairing here + let key_value = slot.key_value().unwrap_unchecked(); + entries.push(key_value); } } - let msg = f"Amount of valid elements should have been {self._len} times, but got {valid_amount}."; - assert(valid_amount == self._len, msg); + let msg = f"Amount of valid elements should have been {self._len} times, but got {entries.len()}."; + assert(entries.len() == self._len, msg); entries } - // Get the Option array of valid keys - // with a length of map capacity. First len() elements - // are safe to unwrap_unchecked(), whilst remaining - // are guaranteed to be Option::none(). - // - // This design is reasoned by compile-time limitations and - // temporary nested slices ban. - pub fn keys(self) -> [Option; N] { - let mut keys = [Option::none(); N]; - let mut valid_amount = 0; + // Returns a BoundedVec containing all the keys within this HashMap. + // The length of the returned vector will always match the length of this HashMap. + // docs:start:keys + pub fn keys(self) -> BoundedVec { + // docs:end:keys + let mut keys = BoundedVec::new(); for slot in self._table { if slot.is_valid() { let (key, _) = slot.key_value_unchecked(); - keys[valid_amount] = Option::some(key); - valid_amount += 1; + keys.push(key); } } - let msg = f"Amount of valid elements should have been {self._len} times, but got {valid_amount}."; - assert(valid_amount == self._len, msg); + let msg = f"Amount of valid elements should have been {self._len} times, but got {keys.len()}."; + assert(keys.len() == self._len, msg); keys } - // Get the Option array of valid values - // with a length of map capacity. First len() elements - // are safe to unwrap_unchecked(), whilst remaining - // are guaranteed to be Option::none(). - // - // This design is reasoned by compile-time limitations and - // temporary nested slices ban. - pub fn values(self) -> [Option; N] { - let mut values = [Option::none(); N]; - let mut valid_amount = 0; + // Returns a BoundedVec containing all the values within this HashMap. + // The length of the returned vector will always match the length of this HashMap. + // docs:start:values + pub fn values(self) -> BoundedVec { + // docs:end:values + let mut values = BoundedVec::new(); for slot in self._table { if slot.is_valid() { let (_, value) = slot.key_value_unchecked(); - values[valid_amount] = Option::some(value); - valid_amount += 1; + values.push(value); } } - let msg = f"Amount of valid elements should have been {self._len} times, but got {valid_amount}."; - assert(valid_amount == self._len, msg); + let msg = f"Amount of valid elements should have been {self._len} times, but got {values.len()}."; + assert(values.len() == self._len, msg); values } // For each key-value entry applies mutator function. + // docs:start:iter_mut pub fn iter_mut( &mut self, f: fn(K, V) -> (K, V) @@ -192,12 +189,13 @@ impl HashMap { K: Eq + Hash, B: BuildHasher, H: Hasher { + // docs:end:iter_mut let mut entries = self.entries(); let mut new_map = HashMap::with_hasher(self._build_hasher); for i in 0..N { if i < self._len { - let entry = entries[i].unwrap_unchecked(); + let entry = entries.get_unchecked(i); let (key, value) = f(entry.0, entry.1); new_map.insert(key, value); } @@ -207,6 +205,7 @@ impl HashMap { } // For each key applies mutator function. + // docs:start:iter_keys_mut pub fn iter_keys_mut( &mut self, f: fn(K) -> K @@ -215,12 +214,13 @@ impl HashMap { K: Eq + Hash, B: BuildHasher, H: Hasher { + // docs:end:iter_keys_mut let mut entries = self.entries(); let mut new_map = HashMap::with_hasher(self._build_hasher); for i in 0..N { if i < self._len { - let entry = entries[i].unwrap_unchecked(); + let entry = entries.get_unchecked(i); let (key, value) = (f(entry.0), entry.1); new_map.insert(key, value); } @@ -230,7 +230,9 @@ impl HashMap { } // For each value applies mutator function. + // docs:start:iter_values_mut pub fn iter_values_mut(&mut self, f: fn(V) -> V) { + // docs:end:iter_values_mut for i in 0..N { let mut slot = self._table[i]; if slot.is_valid() { @@ -242,7 +244,9 @@ impl HashMap { } // Retains only the elements specified by the predicate. + // docs:start:retain pub fn retain(&mut self, f: fn(K, V) -> bool) { + // docs:end:retain for index in 0..N { let mut slot = self._table[index]; if slot.is_valid() { @@ -257,16 +261,21 @@ impl HashMap { } // Amount of active key-value entries. + // docs:start:len pub fn len(self) -> u64 { + // docs:end:len self._len } // Get the compile-time map capacity. + // docs:start:capacity pub fn capacity(_self: Self) -> u64 { + // docs:end:capacity N } // Get the value by key. If it does not exist, returns none(). + // docs:start:get pub fn get( self, key: K @@ -275,13 +284,14 @@ impl HashMap { K: Eq + Hash, B: BuildHasher, H: Hasher { + // docs:end:get let mut result = Option::none(); let hash = self.hash(key); - let mut break = false; + let mut should_break = false; for attempt in 0..N { - if !break { + if !should_break { let index = self.quadratic_probe(hash, attempt as u64); let slot = self._table[index]; @@ -290,7 +300,7 @@ impl HashMap { let (current_key, value) = slot.key_value_unchecked(); if current_key == key { result = Option::some(value); - break = true; + should_break = true; } } } @@ -300,6 +310,7 @@ impl HashMap { } // Insert key-value entry. In case key was already present, value is overridden. + // docs:start:insert pub fn insert( &mut self, key: K, @@ -309,13 +320,14 @@ impl HashMap { K: Eq + Hash, B: BuildHasher, H: Hasher { + // docs:end:insert self.assert_load_factor(); let hash = self.hash(key); - let mut break = false; + let mut should_break = false; for attempt in 0..N { - if !break { + if !should_break { let index = self.quadratic_probe(hash, attempt as u64); let mut slot = self._table[index]; let mut insert = false; @@ -334,13 +346,14 @@ impl HashMap { if insert { slot.set(key, value); self._table[index] = slot; - break = true; + should_break = true; } } } } - // Remove key-value entry. If key is not present, HashMap remains unchanged. + // Removes a key-value entry. If key is not present, HashMap remains unchanged. + // docs:start:remove pub fn remove( &mut self, key: K @@ -349,11 +362,12 @@ impl HashMap { K: Eq + Hash, B: BuildHasher, H: Hasher { + // docs:end:remove let hash = self.hash(key); - let mut break = false; + let mut should_break = false; for attempt in 0..N { - if !break { + if !should_break { let index = self.quadratic_probe(hash, attempt as u64); let mut slot = self._table[index]; @@ -364,7 +378,7 @@ impl HashMap { slot.mark_deleted(); self._table[index] = slot; self._len -= 1; - break = true; + should_break = true; } } } @@ -400,7 +414,7 @@ impl HashMap { // n * MAX_LOAD_FACTOR_DEN0MINATOR >= m * MAX_LOAD_FACTOR_NUMERATOR fn assert_load_factor(self) { let lhs = self._len * MAX_LOAD_FACTOR_DEN0MINATOR; - let rhs = self._table.len() as u64 * MAX_LOAD_FACTOR_NUMERATOR; + let rhs = self._table.len() * MAX_LOAD_FACTOR_NUMERATOR; let exceeded = lhs >= rhs; assert(!exceeded, "Load factor is exceeded, consider increasing the capacity."); } @@ -409,6 +423,7 @@ impl HashMap { // Equality class on HashMap has to test that they have // equal sets of key-value entries, // thus one is a subset of the other and vice versa. +// docs:start:eq impl Eq for HashMap where K: Eq + Hash, @@ -416,7 +431,8 @@ where B: BuildHasher, H: Hasher { - fn eq(self, other: HashMap) -> bool{ + fn eq(self, other: HashMap) -> bool { +// docs:end:eq let mut equal = false; if self.len() == other.len(){ @@ -443,12 +459,14 @@ where } } +// docs:start:default impl Default for HashMap where B: BuildHasher + Default, H: Hasher + Default { - fn default() -> Self{ + fn default() -> Self { +// docs:end:default let _build_hasher = B::default(); let map: HashMap = HashMap::with_hasher(_build_hasher); map diff --git a/noir_stdlib/src/collections/vec.nr b/noir_stdlib/src/collections/vec.nr index deec98185ff..56354438c89 100644 --- a/noir_stdlib/src/collections/vec.nr +++ b/noir_stdlib/src/collections/vec.nr @@ -5,7 +5,7 @@ struct Vec { // A separate type is technically not needed but helps differentiate which operations are mutable. impl Vec { pub fn new() -> Self { - Self { slice: [] } + Self { slice: &[] } } // Create a Vec containing each element from the given slice. diff --git a/noir_stdlib/src/default.nr b/noir_stdlib/src/default.nr index 32c4f3f3b48..bd2f1ce0cd2 100644 --- a/noir_stdlib/src/default.nr +++ b/noir_stdlib/src/default.nr @@ -23,6 +23,12 @@ impl Default for [T; N] where T: Default { } } +impl Default for [T] { + fn default() -> [T] { + &[] + } +} + impl Default for (A, B) where A: Default, B: Default { fn default() -> (A, B) { (A::default(), B::default()) diff --git a/noir_stdlib/src/ecdsa_secp256k1.nr b/noir_stdlib/src/ecdsa_secp256k1.nr index b72a1acd041..f84e2221f57 100644 --- a/noir_stdlib/src/ecdsa_secp256k1.nr +++ b/noir_stdlib/src/ecdsa_secp256k1.nr @@ -8,3 +8,15 @@ pub fn verify_signature( ) -> bool // docs:end:ecdsa_secp256k1 {} + +#[foreign(ecdsa_secp256k1)] +// docs:start:ecdsa_secp256k1_slice +pub fn verify_signature_slice( + public_key_x: [u8; 32], + public_key_y: [u8; 32], + signature: [u8; 64], + message_hash: [u8] +) -> bool +// docs:end:ecdsa_secp256k1_slice +{} + diff --git a/noir_stdlib/src/ecdsa_secp256r1.nr b/noir_stdlib/src/ecdsa_secp256r1.nr index ef92bf24ae4..76e68aeeafa 100644 --- a/noir_stdlib/src/ecdsa_secp256r1.nr +++ b/noir_stdlib/src/ecdsa_secp256r1.nr @@ -8,3 +8,14 @@ pub fn verify_signature( ) -> bool // docs:end:ecdsa_secp256r1 {} + +#[foreign(ecdsa_secp256r1)] +// docs:start:ecdsa_secp256r1_slice +pub fn verify_signature_slice( + public_key_x: [u8; 32], + public_key_y: [u8; 32], + signature: [u8; 64], + message_hash: [u8] +) -> bool +// docs:end:ecdsa_secp256r1_slice +{} diff --git a/noir_stdlib/src/eddsa.nr b/noir_stdlib/src/eddsa.nr index cb9ffc5322f..6a657f450c1 100644 --- a/noir_stdlib/src/eddsa.nr +++ b/noir_stdlib/src/eddsa.nr @@ -1,6 +1,8 @@ use crate::hash::poseidon; use crate::ec::consts::te::baby_jubjub; use crate::ec::tecurve::affine::Point as TEPoint; +use crate::hash::{Hash, Hasher, BuildHasher, BuildHasherDefault}; +use crate::hash::poseidon::PoseidonHasher; // Returns true if signature is valid pub fn eddsa_poseidon_verify( @@ -11,6 +13,28 @@ pub fn eddsa_poseidon_verify( signature_r8_y: field, message: field ) -> bool { + let mut hasher = PoseidonHasher::default(); + eddsa_verify_with_hasher( + pub_key_x, + pub_key_y, + signature_s, + signature_r8_x, + signature_r8_y, + message, + &mut hasher + ) +} + +pub fn eddsa_verify_with_hasher( + pub_key_x: Field, + pub_key_y: Field, + signature_s: Field, + signature_r8_x: Field, + signature_r8_y: Field, + message: Field, + hasher: &mut H +) -> bool +where H: Hasher { // Verifies by testing: // S * B8 = R8 + H(R8, A, m) * A8 let bjj = baby_jubjub(); @@ -23,7 +47,12 @@ pub fn eddsa_poseidon_verify( // Ensure S < Subgroup Order assert(signature_s.lt(bjj.suborder)); // Calculate the h = H(R, A, msg) - let hash: Field = poseidon::bn254::hash_5([signature_r8_x, signature_r8_y, pub_key_x, pub_key_y, message]); + signature_r8_x.hash(hasher); + signature_r8_y.hash(hasher); + pub_key_x.hash(hasher); + pub_key_y.hash(hasher); + message.hash(hasher); + let hash: Field = (*hasher).finish(); // Calculate second part of the right side: right2 = h*8*A // Multiply by 8 by doubling 3 times. This also ensures that the result is in the subgroup. let pub_key_mul_2 = bjj.curve.add(pub_key, pub_key); @@ -38,3 +67,10 @@ pub fn eddsa_poseidon_verify( left.eq(right) } + +// Returns the public key of the given secret key as (pub_key_x, pub_key_y) +pub fn eddsa_to_pub(secret: Field) -> (Field, Field) { + let bjj = baby_jubjub(); + let pub_key = bjj.curve.mul(secret, bjj.curve.gen); + (pub_key.x, pub_key.y) +} diff --git a/noir_stdlib/src/field_element.nr b/noir_stdlib/src/field_element.nr index 5aa99c0d308..e09398338a4 100644 --- a/noir_stdlib/src/field_element.nr +++ b/noir_stdlib/src/field_element.nr @@ -97,7 +97,8 @@ pub fn modulus_be_bytes() -> [u8] {} #[builtin(modulus_le_bytes)] pub fn modulus_le_bytes() -> [u8] {} -// Convert a 32 byte array to a field element + +// Convert a 32 byte array to a field element by modding pub fn bytes32_to_field(bytes32: [u8; 32]) -> field { // Convert it to a field element let mut v = 1; diff --git a/noir_stdlib/src/field_element/bn254.nr b/noir_stdlib/src/field_element/bn254.nr index c021ab5567f..c3c1c3ef609 100644 --- a/noir_stdlib/src/field_element/bn254.nr +++ b/noir_stdlib/src/field_element/bn254.nr @@ -21,11 +21,23 @@ unconstrained fn decompose_unsafe(x: field) -> (field, field) { (low, high) } +// Assert that (alo > blo && ahi >= bhi) || (alo <= blo && ahi > bhi) +fn assert_gt_limbs(a: (field, field), b: (field, field)) { + let (alo, ahi) = a; + let (blo, bhi) = b; + let borrow = lte_unsafe(alo, blo, 16); + + let rlo = alo - blo - 1 + (borrow as field) * TWO_POW_128; + let rhi = ahi - bhi - (borrow as field); + + rlo.assert_max_bit_size(128); + rhi.assert_max_bit_size(128); +} + /// Decompose a single field into two 16 byte fields. pub fn decompose(x: field) -> (field, field) { // Take hints of the decomposition let (xlo, xhi) = decompose_unsafe(x); - let borrow = lt_unsafe(PLO, xlo, 16); // Range check the limbs xlo.assert_max_bit_size(128); @@ -34,13 +46,8 @@ pub fn decompose(x: field) -> (field, field) { // Check that the decomposition is correct assert_eq(x, xlo + TWO_POW_128 * xhi); - // Check that (xlo < plo && xhi <= phi) || (xlo >= plo && xhi < phi) - let rlo = PLO - xlo + (borrow as field) * TWO_POW_128; - let rhi = PHI - xhi - (borrow as field); - - rlo.assert_max_bit_size(128); - rhi.assert_max_bit_size(128); - + // Assert that the decomposition of P is greater than the decomposition of x + assert_gt_limbs((PLO, PHI), (xlo, xhi)); (xlo, xhi) } @@ -69,17 +76,11 @@ unconstrained fn lte_unsafe(x: field, y: field, num_bytes: u32) -> bool { pub fn assert_gt(a: field, b: field) { // Decompose a and b - let (alo, ahi) = decompose(a); - let (blo, bhi) = decompose(b); - - let borrow = lte_unsafe(alo, blo, 16); + let a_limbs = decompose(a); + let b_limbs = decompose(b); - // Assert that (alo > blo && ahi >= bhi) || (alo <= blo && ahi > bhi) - let rlo = alo - blo - 1 + (borrow as field) * TWO_POW_128; - let rhi = ahi - bhi - (borrow as field); - - rlo.assert_max_bit_size(128); - rhi.assert_max_bit_size(128); + // Assert that a_limbs is greater than b_limbs + assert_gt_limbs(a_limbs, b_limbs) } pub fn assert_lt(a: field, b: field) { @@ -101,3 +102,81 @@ pub fn gt(a: field, b: field) -> bool { pub fn lt(a: field, b: field) -> bool { gt(b, a) } + +mod tests { + // TODO: Allow imports from "super" + use crate::field::bn254::{decompose_unsafe, decompose, lt_unsafe, assert_gt, gt, lt, TWO_POW_128, lte_unsafe, PLO, PHI}; + + #[test] + fn check_decompose_unsafe() { + assert_eq(decompose_unsafe(TWO_POW_128), (0, 1)); + assert_eq(decompose_unsafe(TWO_POW_128 + 0x1234567890), (0x1234567890, 1)); + assert_eq(decompose_unsafe(0x1234567890), (0x1234567890, 0)); + } + + #[test] + fn check_decompose() { + assert_eq(decompose(TWO_POW_128), (0, 1)); + assert_eq(decompose(TWO_POW_128 + 0x1234567890), (0x1234567890, 1)); + assert_eq(decompose(0x1234567890), (0x1234567890, 0)); + } + + #[test] + fn check_lt_unsafe() { + assert(lt_unsafe(0, 1, 16)); + assert(lt_unsafe(0, 0x100, 16)); + assert(lt_unsafe(0x100, TWO_POW_128 - 1, 16)); + assert(!lt_unsafe(0, TWO_POW_128, 16)); + } + + #[test] + fn check_lte_unsafe() { + assert(lte_unsafe(0, 1, 16)); + assert(lte_unsafe(0, 0x100, 16)); + assert(lte_unsafe(0x100, TWO_POW_128 - 1, 16)); + assert(!lte_unsafe(0, TWO_POW_128, 16)); + + assert(lte_unsafe(0, 0, 16)); + assert(lte_unsafe(0x100, 0x100, 16)); + assert(lte_unsafe(TWO_POW_128 - 1, TWO_POW_128 - 1, 16)); + assert(lte_unsafe(TWO_POW_128, TWO_POW_128, 16)); + } + + #[test] + fn check_assert_gt() { + assert_gt(1, 0); + assert_gt(0x100, 0); + assert_gt((0 - 1), (0 - 2)); + assert_gt(TWO_POW_128, 0); + assert_gt(0 - 1, 0); + } + + #[test] + fn check_gt() { + assert(gt(1, 0)); + assert(gt(0x100, 0)); + assert(gt((0 - 1), (0 - 2))); + assert(gt(TWO_POW_128, 0)); + assert(!gt(0, 0)); + assert(!gt(0, 0x100)); + assert(gt(0 - 1, 0 - 2)); + assert(!gt(0 - 2, 0 - 1)); + } + + #[test] + fn check_plo_phi() { + assert_eq(PLO + PHI * TWO_POW_128, 0); + let p_bytes = crate::field::modulus_le_bytes(); + let mut p_low: Field = 0; + let mut p_high: Field = 0; + + let mut offset = 1; + for i in 0..16 { + p_low += (p_bytes[i] as Field) * offset; + p_high += (p_bytes[i + 16] as Field) * offset; + offset *= 256; + } + assert_eq(p_low, PLO); + assert_eq(p_high, PHI); + } +} diff --git a/noir_stdlib/src/hash.nr b/noir_stdlib/src/hash.nr index aba733ff355..9def4939ab3 100644 --- a/noir_stdlib/src/hash.nr +++ b/noir_stdlib/src/hash.nr @@ -4,6 +4,7 @@ mod poseidon2; mod pedersen; use crate::default::Default; +use crate::uint128::U128; #[foreign(sha256)] // docs:start:sha256 @@ -11,38 +12,69 @@ pub fn sha256(input: [u8; N]) -> [u8; 32] // docs:end:sha256 {} +#[foreign(sha256)] +// docs:start:sha256_slice +pub fn sha256_slice(input: [u8]) -> [u8; 32] +// docs:end:sha256_slice +{} + #[foreign(blake2s)] // docs:start:blake2s pub fn blake2s(input: [u8; N]) -> [u8; 32] // docs:end:blake2s {} +#[foreign(blake2s)] +// docs:start:blake2s_slice +pub fn blake2s_slice(input: [u8]) -> [u8; 32] +// docs:end:blake2s_slice +{} + #[foreign(blake3)] // docs:start:blake3 pub fn blake3(input: [u8; N]) -> [u8; 32] // docs:end:blake3 {} +#[foreign(blake3)] +// docs:start:blake3_slice +pub fn blake3_slice(input: [u8]) -> [u8; 32] +// docs:end:blake3_slice +{} + // docs:start:pedersen_commitment struct PedersenPoint { x : Field, y : Field, } -pub fn pedersen_commitment(input: [field; N]) -> PedersenPoint -// docs:end:pedersen_commitment -{ +pub fn pedersen_commitment(input: [field; N]) -> PedersenPoint { + // docs:end:pedersen_commitment pedersen_commitment_with_separator(input, 0) } +// docs:start:pedersen_commitment_slice +pub fn pedersen_commitment_slice(input: [Field]) -> PedersenPoint { + pedersen_commitment_with_separator_slice(input, 0) +} +// docs:end:pedersen_commitment_slice + #[foreign(pedersen_commitment)] pub fn __pedersen_commitment_with_separator(input: [field; N], separator: u32) -> [field; 2] {} +#[foreign(pedersen_commitment)] +pub fn __pedersen_commitment_with_separator_slice(input: [field], separator: u32) -> [field; 2] {} + pub fn pedersen_commitment_with_separator(input: [field; N], separator: u32) -> PedersenPoint { let values = __pedersen_commitment_with_separator(input, separator); PedersenPoint { x: values[0], y: values[1] } } +pub fn pedersen_commitment_with_separator_slice(input: [field], separator: u32) -> PedersenPoint { + let values = __pedersen_commitment_with_separator_slice(input, separator); + PedersenPoint { x: values[0], y: values[1] } +} + // docs:start:pedersen_hash pub fn pedersen_hash(input: [field; N]) -> field // docs:end:pedersen_hash @@ -50,20 +82,30 @@ pub fn pedersen_hash(input: [field; N]) -> field pedersen_hash_with_separator(input, 0) } +// docs:start:pedersen_hash_slice +pub fn pedersen_hash_slice(input: [Field]) -> Field +// docs:end:pedersen_hash_slice +{ + pedersen_hash_with_separator_slice(input, 0) +} + #[foreign(pedersen_hash)] pub fn pedersen_hash_with_separator(input: [field; N], separator: u32) -> field {} -pub fn hash_to_field(input: [field; N]) -> field { - let mut inputs_as_bytes = []; +#[foreign(pedersen_hash)] +pub fn pedersen_hash_with_separator_slice(input: [field], separator: u32) -> field {} + +pub fn hash_to_field(inputs: [field]) -> field { + let mut inputs_as_bytes = &[]; - for i in 0..N { - let input_bytes = input[i].to_le_bytes(32); + for input in inputs { + let input_bytes = input.to_le_bytes(32); for i in 0..32 { inputs_as_bytes = inputs_as_bytes.push_back(input_bytes[i]); } } - let hashed_input = blake2s(inputs_as_bytes); + let hashed_input = blake2s_slice(inputs_as_bytes); crate::field_element::bytes32_to_field(hashed_input) } @@ -73,6 +115,12 @@ pub fn keccak256(input: [u8; N], message_size: u32) -> [u8; 32] // docs:end:keccak256 {} +#[foreign(keccak256)] +// docs:start:keccak256_slice +pub fn keccak256_slice(input: [u8], message_size: u32) -> [u8; 32] +// docs:end:keccak256_slice +{} + #[foreign(poseidon2_permutation)] pub fn poseidon2_permutation(_input: [field; N], _state_length: u32) -> [field; N] {} @@ -120,10 +168,111 @@ where } } -// TODO: add implementations for the remainder of primitive types. -impl Hash for Field{ +impl Hash for Field { + fn hash(self, state: &mut H) where H: Hasher{ + H::write(state, &[self]); + } +} + +impl Hash for u8 { + fn hash(self, state: &mut H) where H: Hasher{ + H::write(state, &[self as Field]); + } +} + +impl Hash for u32 { + fn hash(self, state: &mut H) where H: Hasher{ + H::write(state, &[self as Field]); + } +} + +impl Hash for u64 { + fn hash(self, state: &mut H) where H: Hasher{ + H::write(state, &[self as Field]); + } +} + +impl Hash for i8 { + fn hash(self, state: &mut H) where H: Hasher{ + H::write(state, &[self as Field]); + } +} + +impl Hash for i32 { + fn hash(self, state: &mut H) where H: Hasher{ + H::write(state, &[self as Field]); + } +} + +impl Hash for i64 { + fn hash(self, state: &mut H) where H: Hasher{ + H::write(state, &[self as Field]); + } +} + +impl Hash for bool { + fn hash(self, state: &mut H) where H: Hasher{ + H::write(state, &[self as Field]); + } +} + +impl Hash for () { + fn hash(_self: Self, _state: &mut H) where H: Hasher {} +} + +impl Hash for U128 { + fn hash(self, state: &mut H) where H: Hasher{ + H::write(state, &[self.lo as Field, self.hi as Field]); + } +} + +impl Hash for [T; N] where T: Hash { + fn hash(self, state: &mut H) where H: Hasher{ + for elem in self { + elem.hash(state); + } + } +} + +impl Hash for [T] where T: Hash { + fn hash(self, state: &mut H) where H: Hasher{ + self.len().hash(state); + for elem in self { + elem.hash(state); + } + } +} + +impl Hash for (A, B) where A: Hash, B: Hash { + fn hash(self, state: &mut H) where H: Hasher{ + self.0.hash(state); + self.1.hash(state); + } +} + +impl Hash for (A, B, C) where A: Hash, B: Hash, C: Hash { + fn hash(self, state: &mut H) where H: Hasher{ + self.0.hash(state); + self.1.hash(state); + self.2.hash(state); + } +} + +impl Hash for (A, B, C, D) where A: Hash, B: Hash, C: Hash, D: Hash { + fn hash(self, state: &mut H) where H: Hasher{ + self.0.hash(state); + self.1.hash(state); + self.2.hash(state); + self.3.hash(state); + } +} + +impl Hash for (A, B, C, D, E) where A: Hash, B: Hash, C: Hash, D: Hash, E: Hash { fn hash(self, state: &mut H) where H: Hasher{ - let input: [Field] = [self]; - H::write(state, input); + self.0.hash(state); + self.1.hash(state); + self.2.hash(state); + self.3.hash(state); + self.4.hash(state); } } diff --git a/noir_stdlib/src/hash/mimc.nr b/noir_stdlib/src/hash/mimc.nr index 592895ad820..62061339a20 100644 --- a/noir_stdlib/src/hash/mimc.nr +++ b/noir_stdlib/src/hash/mimc.nr @@ -1,3 +1,6 @@ +use crate::hash::Hasher; +use crate::default::Default; + // mimc-p/p implementation // constants are (publicly generated) random numbers, for instance using keccak as a ROM. // You must use constants generated for the native field @@ -16,13 +19,8 @@ fn mimc(x: field, k: field, constants: [field; N], exp: field) -> field { } global MIMC_BN254_ROUNDS = 91; -//mimc implementation with hardcoded parameters for BN254 curve. -#[field(bn254)] -pub fn mimc_bn254(array: [field; N]) -> field { - //mimc parameters - let exponent = 7; - //generated from seed "mimc" using keccak256 - let constants: [Field; MIMC_BN254_ROUNDS] = [ +//generated from seed "mimc" using keccak256 +global MIMC_BN254_CONSTANTS: [field; MIMC_BN254_ROUNDS] = [ 0, 20888961410941983456478427210666206549300505294776164667214940546594746570981, 15265126113435022738560151911929040668591755459209400716467504685752745317193, @@ -116,10 +114,46 @@ pub fn mimc_bn254(array: [field; N]) -> field { 13602139229813231349386885113156901793661719180900395818909719758150455500533 ]; +//mimc implementation with hardcoded parameters for BN254 curve. +#[field(bn254)] +pub fn mimc_bn254(array: [Field; N]) -> Field { + let exponent = 7; let mut r = 0; for elem in array { - let h = mimc(elem, r, constants, exponent); + let h = mimc(elem, r, MIMC_BN254_CONSTANTS, exponent); r = r + elem + h; } r } + +struct MimcHasher{ + _state: [Field], + _len: u64, +} + +impl Hasher for MimcHasher { + #[field(bn254)] + fn finish(self) -> Field { + let exponent = 7; + let mut r = 0; + for i in 0..self._len { + let h = mimc(self._state[i], r, MIMC_BN254_CONSTANTS, exponent); + r = r + self._state[i] + h; + } + r + } + + fn write(&mut self, input: [Field]){ + self._state = self._state.append(input); + self._len += input.len(); + } +} + +impl Default for MimcHasher{ + fn default() -> Self{ + MimcHasher{ + _state: &[], + _len: 0, + } + } +} diff --git a/noir_stdlib/src/hash/pedersen.nr b/noir_stdlib/src/hash/pedersen.nr index ace6851099d..ad21e728945 100644 --- a/noir_stdlib/src/hash/pedersen.nr +++ b/noir_stdlib/src/hash/pedersen.nr @@ -1,4 +1,4 @@ -use crate::hash::{Hasher, pedersen_hash}; +use crate::hash::{Hasher, pedersen_hash_slice}; use crate::default::Default; struct PedersenHasher{ @@ -7,7 +7,7 @@ struct PedersenHasher{ impl Hasher for PedersenHasher { fn finish(self) -> Field { - pedersen_hash(self._state) + pedersen_hash_slice(self._state) } fn write(&mut self, input: [Field]){ @@ -18,7 +18,7 @@ impl Hasher for PedersenHasher { impl Default for PedersenHasher{ fn default() -> Self{ PedersenHasher{ - _state: [] + _state: &[] } } } diff --git a/noir_stdlib/src/hash/poseidon.nr b/noir_stdlib/src/hash/poseidon.nr index ce57b64048d..abfc07d7f30 100644 --- a/noir_stdlib/src/hash/poseidon.nr +++ b/noir_stdlib/src/hash/poseidon.nr @@ -1,5 +1,7 @@ mod bn254; // Instantiations of Poseidon for prime field of the same order as BN254 use crate::field_element::modulus_num_bits; +use crate::hash::Hasher; +use crate::default::Default; struct PoseidonConfig { t: Field, // Width, i.e. state size @@ -100,3 +102,77 @@ fn apply_matrix(a: [field; M], x: [field; N]) -> [field; N] { y } + +struct PoseidonHasher{ + _state: [Field], + _len: u64, +} + +impl Hasher for PoseidonHasher { + #[field(bn254)] + fn finish(self) -> Field { + let mut result = 0; + assert(self._len < 16); + if self._len == 1 { + result = bn254::hash_1([self._state[0]]); + } + if self._len == 2 { + result = bn254::hash_2([self._state[0],self._state[1]]); + } + if self._len == 3 { + result = bn254::hash_3([self._state[0],self._state[1],self._state[2]]); + } + if self._len == 4 { + result = bn254::hash_4([self._state[0],self._state[1],self._state[2],self._state[3]]); + } + if self._len == 5 { + result = bn254::hash_5([self._state[0],self._state[1],self._state[2],self._state[3],self._state[4]]); + } + if self._len == 6 { + result = bn254::hash_6([self._state[0],self._state[1],self._state[2],self._state[3],self._state[4], self._state[5]]); + } + if self._len == 7 { + result = bn254::hash_7([self._state[0],self._state[1],self._state[2],self._state[3],self._state[4], self._state[5], self._state[6]]); + } + if self._len == 8 { + result = bn254::hash_8([self._state[0],self._state[1],self._state[2],self._state[3],self._state[4], self._state[5], self._state[6], self._state[7]]); + } + if self._len == 9 { + result = bn254::hash_9([self._state[0],self._state[1],self._state[2],self._state[3],self._state[4], self._state[5], self._state[6], self._state[7], self._state[8]]); + } + if self._len == 10 { + result = bn254::hash_10([self._state[0],self._state[1],self._state[2],self._state[3],self._state[4], self._state[5], self._state[6], self._state[7], self._state[8], self._state[9]]); + } + if self._len == 11 { + result = bn254::hash_11([self._state[0],self._state[1],self._state[2],self._state[3],self._state[4], self._state[5], self._state[6], self._state[7], self._state[8], self._state[9], self._state[10]]); + } + if self._len == 12 { + result = bn254::hash_12([self._state[0],self._state[1],self._state[2],self._state[3],self._state[4], self._state[5], self._state[6], self._state[7], self._state[8], self._state[9], self._state[10], self._state[11]]); + } + if self._len == 13 { + result = bn254::hash_13([self._state[0],self._state[1],self._state[2],self._state[3],self._state[4], self._state[5], self._state[6], self._state[7], self._state[8], self._state[9], self._state[10], self._state[11], self._state[12]]); + } + if self._len == 14 { + result = bn254::hash_14([self._state[0],self._state[1],self._state[2],self._state[3],self._state[4], self._state[5], self._state[6], self._state[7], self._state[8], self._state[9], self._state[10], self._state[11], self._state[12], self._state[13]]); + } + if self._len == 15 { + result = bn254::hash_15([self._state[0],self._state[1],self._state[2],self._state[3],self._state[4], self._state[5], self._state[6], self._state[7], self._state[8], self._state[9], self._state[10], self._state[11], self._state[12], self._state[13], self._state[14]]); + } + + result + } + + fn write(&mut self, input: [Field]){ + self._state = self._state.append(input); + self._len += input.len(); + } +} + +impl Default for PoseidonHasher{ + fn default() -> Self{ + PoseidonHasher{ + _state: &[], + _len: 0, + } + } +} diff --git a/noir_stdlib/src/hash/poseidon2.nr b/noir_stdlib/src/hash/poseidon2.nr index e576a0f2c30..8737ed7705a 100644 --- a/noir_stdlib/src/hash/poseidon2.nr +++ b/noir_stdlib/src/hash/poseidon2.nr @@ -1,4 +1,7 @@ -global RATE = 3; +use crate::hash::Hasher; +use crate::default::Default; + +global RATE: u32 = 3; struct Poseidon2 { cache: [Field;3], @@ -9,7 +12,7 @@ struct Poseidon2 { impl Poseidon2 { - pub fn hash(input: [field; N], message_size: u32) -> field { + pub fn hash(input: [field; N], message_size: u64) -> field { if message_size == N { Poseidon2::hash_internal(input, N, false) } else { @@ -92,11 +95,12 @@ impl Poseidon2 { result } - fn hash_internal(input: [field; N], in_len: u32, is_variable_length: bool) -> field { - let iv : Field = (in_len as field) * 18446744073709551616; + fn hash_internal(input: [field; N], in_len: u64, is_variable_length: bool) -> field { + let two_pow_64 = 18446744073709551616; + let iv : Field = (in_len as Field) * two_pow_64; let mut sponge = Poseidon2::new(iv); for i in 0..input.len() { - if i as u32 < in_len { + if i < in_len { sponge.absorb(input[i]); } } @@ -110,3 +114,33 @@ impl Poseidon2 { sponge.squeeze() } } + +struct Poseidon2Hasher{ + _state: [Field], + _len: u64, +} + +impl Hasher for Poseidon2Hasher { + fn finish(self) -> Field { + let iv : Field = (self._state.len() as Field)*18446744073709551616; // iv = (self._state.len() << 64) + let mut sponge = Poseidon2::new(iv); + for i in 0..self._len { + sponge.absorb(self._state[i]); + } + sponge.squeeze() + } + + fn write(&mut self, input: [Field]){ + self._state = self._state.append(input); + self._len += input.len(); + } +} + +impl Default for Poseidon2Hasher{ + fn default() -> Self{ + Poseidon2Hasher{ + _state: &[], + _len: 0, + } + } +} diff --git a/noir_stdlib/src/internal.nr b/noir_stdlib/src/internal.nr new file mode 100644 index 00000000000..8d5c01dda7f --- /dev/null +++ b/noir_stdlib/src/internal.nr @@ -0,0 +1,12 @@ +// This file contains functions which should only be used in calls injected by the Noir compiler. +// These functions should not be called manually in user code. +// +// Changes to this file will not be considered breaking. + +#[oracle(assert_message)] +unconstrained fn assert_message_oracle(_input: T) {} +unconstrained pub fn resolve_assert_message(input: T, condition: bool) { + if !condition { + assert_message_oracle(input); + } +} diff --git a/noir_stdlib/src/lib.nr b/noir_stdlib/src/lib.nr index 8b77d065a78..d39097a6eb4 100644 --- a/noir_stdlib/src/lib.nr +++ b/noir_stdlib/src/lib.nr @@ -26,6 +26,7 @@ mod default; mod prelude; mod uint128; mod bigint; +mod internal; // Oracle calls are required to be wrapped in an unconstrained function // Thus, the only argument to the `println` oracle is expected to always be an ident diff --git a/noir_stdlib/src/ops.nr b/noir_stdlib/src/ops.nr index e561265629e..d855e794fb4 100644 --- a/noir_stdlib/src/ops.nr +++ b/noir_stdlib/src/ops.nr @@ -6,9 +6,9 @@ trait Add { impl Add for Field { fn add(self, other: Field) -> Field { self + other } } -impl Add for u8 { fn add(self, other: u8) -> u8 { self + other } } -impl Add for u32 { fn add(self, other: u32) -> u32 { self + other } } impl Add for u64 { fn add(self, other: u64) -> u64 { self + other } } +impl Add for u32 { fn add(self, other: u32) -> u32 { self + other } } +impl Add for u8 { fn add(self, other: u8) -> u8 { self + other } } impl Add for i8 { fn add(self, other: i8) -> i8 { self + other } } impl Add for i32 { fn add(self, other: i32) -> i32 { self + other } } @@ -22,9 +22,9 @@ trait Sub { impl Sub for Field { fn sub(self, other: Field) -> Field { self - other } } -impl Sub for u8 { fn sub(self, other: u8) -> u8 { self - other } } -impl Sub for u32 { fn sub(self, other: u32) -> u32 { self - other } } impl Sub for u64 { fn sub(self, other: u64) -> u64 { self - other } } +impl Sub for u32 { fn sub(self, other: u32) -> u32 { self - other } } +impl Sub for u8 { fn sub(self, other: u8) -> u8 { self - other } } impl Sub for i8 { fn sub(self, other: i8) -> i8 { self - other } } impl Sub for i32 { fn sub(self, other: i32) -> i32 { self - other } } @@ -38,9 +38,9 @@ trait Mul { impl Mul for Field { fn mul(self, other: Field) -> Field { self * other } } -impl Mul for u8 { fn mul(self, other: u8) -> u8 { self * other } } -impl Mul for u32 { fn mul(self, other: u32) -> u32 { self * other } } impl Mul for u64 { fn mul(self, other: u64) -> u64 { self * other } } +impl Mul for u32 { fn mul(self, other: u32) -> u32 { self * other } } +impl Mul for u8 { fn mul(self, other: u8) -> u8 { self * other } } impl Mul for i8 { fn mul(self, other: i8) -> i8 { self * other } } impl Mul for i32 { fn mul(self, other: i32) -> i32 { self * other } } @@ -54,9 +54,9 @@ trait Div { impl Div for Field { fn div(self, other: Field) -> Field { self / other } } -impl Div for u8 { fn div(self, other: u8) -> u8 { self / other } } -impl Div for u32 { fn div(self, other: u32) -> u32 { self / other } } impl Div for u64 { fn div(self, other: u64) -> u64 { self / other } } +impl Div for u32 { fn div(self, other: u32) -> u32 { self / other } } +impl Div for u8 { fn div(self, other: u8) -> u8 { self / other } } impl Div for i8 { fn div(self, other: i8) -> i8 { self / other } } impl Div for i32 { fn div(self, other: i32) -> i32 { self / other } } @@ -68,9 +68,9 @@ trait Rem{ } // docs:end:rem-trait -impl Rem for u8 { fn rem(self, other: u8) -> u8 { self % other } } -impl Rem for u32 { fn rem(self, other: u32) -> u32 { self % other } } impl Rem for u64 { fn rem(self, other: u64) -> u64 { self % other } } +impl Rem for u32 { fn rem(self, other: u32) -> u32 { self % other } } +impl Rem for u8 { fn rem(self, other: u8) -> u8 { self % other } } impl Rem for i8 { fn rem(self, other: i8) -> i8 { self % other } } impl Rem for i32 { fn rem(self, other: i32) -> i32 { self % other } } @@ -84,9 +84,9 @@ trait BitOr { impl BitOr for bool { fn bitor(self, other: bool) -> bool { self | other } } -impl BitOr for u8 { fn bitor(self, other: u8) -> u8 { self | other } } -impl BitOr for u32 { fn bitor(self, other: u32) -> u32 { self | other } } impl BitOr for u64 { fn bitor(self, other: u64) -> u64 { self | other } } +impl BitOr for u32 { fn bitor(self, other: u32) -> u32 { self | other } } +impl BitOr for u8 { fn bitor(self, other: u8) -> u8 { self | other } } impl BitOr for i8 { fn bitor(self, other: i8) -> i8 { self | other } } impl BitOr for i32 { fn bitor(self, other: i32) -> i32 { self | other } } @@ -100,9 +100,9 @@ trait BitAnd { impl BitAnd for bool { fn bitand(self, other: bool) -> bool { self & other } } -impl BitAnd for u8 { fn bitand(self, other: u8) -> u8 { self & other } } -impl BitAnd for u32 { fn bitand(self, other: u32) -> u32 { self & other } } impl BitAnd for u64 { fn bitand(self, other: u64) -> u64 { self & other } } +impl BitAnd for u32 { fn bitand(self, other: u32) -> u32 { self & other } } +impl BitAnd for u8 { fn bitand(self, other: u8) -> u8 { self & other } } impl BitAnd for i8 { fn bitand(self, other: i8) -> i8 { self & other } } impl BitAnd for i32 { fn bitand(self, other: i32) -> i32 { self & other } } @@ -116,9 +116,9 @@ trait BitXor { impl BitXor for bool { fn bitxor(self, other: bool) -> bool { self ^ other } } -impl BitXor for u8 { fn bitxor(self, other: u8) -> u8 { self ^ other } } -impl BitXor for u32 { fn bitxor(self, other: u32) -> u32 { self ^ other } } impl BitXor for u64 { fn bitxor(self, other: u64) -> u64 { self ^ other } } +impl BitXor for u32 { fn bitxor(self, other: u32) -> u32 { self ^ other } } +impl BitXor for u8 { fn bitxor(self, other: u8) -> u8 { self ^ other } } impl BitXor for i8 { fn bitxor(self, other: i8) -> i8 { self ^ other } } impl BitXor for i32 { fn bitxor(self, other: i32) -> i32 { self ^ other } } @@ -130,14 +130,14 @@ trait Shl { } // docs:end:shl-trait -impl Shl for u8 { fn shl(self, other: u8) -> u8 { self << other } } impl Shl for u32 { fn shl(self, other: u32) -> u32 { self << other } } impl Shl for u64 { fn shl(self, other: u64) -> u64 { self << other } } +impl Shl for u8 { fn shl(self, other: u8) -> u8 { self << other } } +impl Shl for u1 { fn shl(self, other: u1) -> u1 { self << other } } -// Bit shifting is not currently supported for signed integer types -// impl Shl for i8 { fn shl(self, other: i8) -> i8 { self << other } } -// impl Shl for i32 { fn shl(self, other: i32) -> i32 { self << other } } -// impl Shl for i64 { fn shl(self, other: i64) -> i64 { self << other } } +impl Shl for i8 { fn shl(self, other: i8) -> i8 { self << other } } +impl Shl for i32 { fn shl(self, other: i32) -> i32 { self << other } } +impl Shl for i64 { fn shl(self, other: i64) -> i64 { self << other } } // docs:start:shr-trait trait Shr { @@ -145,11 +145,11 @@ trait Shr { } // docs:end:shr-trait -impl Shr for u8 { fn shr(self, other: u8) -> u8 { self >> other } } -impl Shr for u32 { fn shr(self, other: u32) -> u32 { self >> other } } impl Shr for u64 { fn shr(self, other: u64) -> u64 { self >> other } } +impl Shr for u32 { fn shr(self, other: u32) -> u32 { self >> other } } +impl Shr for u8 { fn shr(self, other: u8) -> u8 { self >> other } } +impl Shr for u1 { fn shr(self, other: u1) -> u1 { self >> other } } -// Bit shifting is not currently supported for signed integer types -// impl Shr for i8 { fn shr(self, other: i8) -> i8 { self >> other } } -// impl Shr for i32 { fn shr(self, other: i32) -> i32 { self >> other } } -// impl Shr for i64 { fn shr(self, other: i64) -> i64 { self >> other } } +impl Shr for i8 { fn shr(self, other: i8) -> i8 { self >> other } } +impl Shr for i32 { fn shr(self, other: i32) -> i32 { self >> other } } +impl Shr for i64 { fn shr(self, other: i64) -> i64 { self >> other } } diff --git a/noir_stdlib/src/option.nr b/noir_stdlib/src/option.nr index 1c32f758af7..c94a1cf836e 100644 --- a/noir_stdlib/src/option.nr +++ b/noir_stdlib/src/option.nr @@ -1,3 +1,7 @@ +use crate::hash::{Hash, Hasher}; +use crate::cmp::{Ordering, Ord, Eq}; +use crate::default::Default; + struct Option { _is_some: bool, _value: T, @@ -152,3 +156,51 @@ impl Option { } } } + +impl Default for Option { + fn default() -> Self { + Option::none() + } +} + +impl Eq for Option where T: Eq { + fn eq(self, other: Self) -> bool { + if self._is_some == other._is_some { + if self._is_some { + self._value == other._value + } else { + true + } + } else { + false + } + } +} + +impl Hash for Option where T: Hash { + fn hash(self, state: &mut H) where H: Hasher { + self._is_some.hash(state); + if self._is_some { + self._value.hash(state); + } + } +} + +// For this impl we're declaring Option::none < Option::some +impl Ord for Option where T: Ord { + fn cmp(self, other: Self) -> Ordering { + if self._is_some { + if other._is_some { + self._value.cmp(other._value) + } else { + Ordering::greater() + } + } else { + if other._is_some { + Ordering::less() + } else { + Ordering::equal() + } + } + } +} diff --git a/noir_stdlib/src/schnorr.nr b/noir_stdlib/src/schnorr.nr index f5a3076528f..f262df11a71 100644 --- a/noir_stdlib/src/schnorr.nr +++ b/noir_stdlib/src/schnorr.nr @@ -8,3 +8,15 @@ pub fn verify_signature( ) -> bool // docs:end:schnorr_verify {} + +#[foreign(schnorr_verify)] +// docs:start:schnorr_verify_slice +pub fn verify_signature_slice( + public_key_x: Field, + public_key_y: Field, + signature: [u8; 64], + message: [u8] +) -> bool +// docs:end:schnorr_verify_slice +{} + diff --git a/noir_stdlib/src/sha256.nr b/noir_stdlib/src/sha256.nr index 6bcc5ea74c6..8ca6808568d 100644 --- a/noir_stdlib/src/sha256.nr +++ b/noir_stdlib/src/sha256.nr @@ -6,9 +6,11 @@ fn msg_u8_to_u32(msg: [u8; 64]) -> [u32; 16] { let mut msg32: [u32; 16] = [0; 16]; for i in 0..16 { + let mut msg_field: Field = 0; for j in 0..4 { - msg32[15 - i] = (msg32[15 - i] << 8) + msg[64 - 4*(i + 1) + j] as u32; + msg_field = msg_field * 256 + msg[64 - 4*(i + 1) + j] as Field; } + msg32[15 - i] = msg_field as u32; } msg32 @@ -21,7 +23,7 @@ pub fn digest(msg: [u8; N]) -> [u8; 32] { let mut i: u64 = 0; // Message byte pointer for k in 0..N { // Populate msg_block - msg_block[i as Field] = msg[k]; + msg_block[i] = msg[k]; i = i + 1; if i == 64 { // Enough to hash block @@ -32,7 +34,7 @@ pub fn digest(msg: [u8; N]) -> [u8; 32] { } // Pad the rest such that we have a [u32; 2] block at the end representing the length // of the message, and a block of 1 0 ... 0 following the message (i.e. [1 << 7, 0, ..., 0]). - msg_block[i as Field] = 1 << 7; + msg_block[i] = 1 << 7; i = i + 1; // If i >= 57, there aren't enough bits in the current message block to accomplish this, so // the 1 and 0s fill up the current block, which we then compress accordingly. @@ -41,7 +43,7 @@ pub fn digest(msg: [u8; N]) -> [u8; 32] { if i < 64 { for _i in 57..64 { if i <= 63 { - msg_block[i as Field] = 0; + msg_block[i] = 0; i += 1; } } @@ -51,16 +53,16 @@ pub fn digest(msg: [u8; N]) -> [u8; 32] { i = 0; } + let len = 8 * msg.len(); + let len_bytes = (len as Field).to_le_bytes(8); for _i in 0..64 { // In any case, fill blocks up with zeros until the last 64 (i.e. until i = 56). if i < 56 { - msg_block[i as Field] = 0; + msg_block[i] = 0; i = i + 1; } else if i < 64 { - let mut len = 8 * msg.len() as u64; for j in 0..8 { - msg_block[63 - j] = len as u8; - len >>= 8; + msg_block[63 - j] = len_bytes[j]; } i += 8; } @@ -70,9 +72,9 @@ pub fn digest(msg: [u8; N]) -> [u8; 32] { // Return final hash as byte array for j in 0..8 { + let h_bytes = (h[7 - j] as Field).to_le_bytes(4); for k in 0..4 { - out_h[31 - 4*j - k] = h[7 - j] as u8; - h[7-j] >>= 8; + out_h[31 - 4*j - k] = h_bytes[k]; } } diff --git a/noir_stdlib/src/sha512.nr b/noir_stdlib/src/sha512.nr index 155ba593bba..a766ae50d55 100644 --- a/noir_stdlib/src/sha512.nr +++ b/noir_stdlib/src/sha512.nr @@ -77,9 +77,11 @@ fn msg_u8_to_u64(msg: [u8; 128]) -> [u64; 16] { let mut msg64: [u64; 16] = [0; 16]; for i in 0..16 { + let mut msg_field: Field = 0; for j in 0..8 { - msg64[15 - i] = (msg64[15 - i] << 8) + msg[128 - 8*(i + 1) + j] as u64; + msg_field = msg_field * 256 + msg[128 - 8*(i + 1) + j] as Field; } + msg64[15 - i] = msg_field as u64; } msg64 @@ -94,7 +96,7 @@ pub fn digest(msg: [u8; N]) -> [u8; 64] { let mut i: u64 = 0; // Message byte pointer for k in 0..msg.len() { // Populate msg_block - msg_block[i as Field] = msg[k]; + msg_block[i] = msg[k]; i = i + 1; if i == 128 { // Enough to hash block @@ -108,7 +110,7 @@ pub fn digest(msg: [u8; N]) -> [u8; 64] { } // Pad the rest such that we have a [u64; 2] block at the end representing the length // of the message, and a block of 1 0 ... 0 following the message (i.e. [1 << 7, 0, ..., 0]). - msg_block[i as Field] = 1 << 7; + msg_block[i] = 1 << 7; i += 1; // If i >= 113, there aren't enough bits in the current message block to accomplish this, so // the 1 and 0s fill up the current block, which we then compress accordingly. @@ -117,7 +119,7 @@ pub fn digest(msg: [u8; N]) -> [u8; 64] { if i < 128 { for _i in 113..128 { if i <= 127 { - msg_block[i as Field] = 0; + msg_block[i] = 0; i += 1; } } @@ -130,16 +132,16 @@ pub fn digest(msg: [u8; N]) -> [u8; 64] { i = 0; } + let len = 8 * msg.len(); + let len_bytes = (len as Field).to_le_bytes(16); for _i in 0..128 { // In any case, fill blocks up with zeros until the last 128 (i.e. until i = 112). if i < 112 { - msg_block[i as Field] = 0; + msg_block[i] = 0; i += 1; } else if i < 128 { - let mut len = 8 * msg.len() as u64; // u128 unsupported for j in 0..16 { - msg_block[127 - j] = len as u8; - len >>= 8; + msg_block[127 - j] = len_bytes[j]; } i += 16; // Done. } @@ -151,9 +153,9 @@ pub fn digest(msg: [u8; N]) -> [u8; 64] { } // Return final hash as byte array for j in 0..8 { + let h_bytes = (h[7 - j] as Field).to_le_bytes(8); for k in 0..8 { - out_h[63 - 8*j - k] = h[7 - j] as u8; - h[7-j] >>= 8; + out_h[63 - 8*j - k] = h_bytes[k]; } } diff --git a/noir_stdlib/src/slice.nr b/noir_stdlib/src/slice.nr index ea8d09d14ce..164b4f96cf6 100644 --- a/noir_stdlib/src/slice.nr +++ b/noir_stdlib/src/slice.nr @@ -1,4 +1,7 @@ impl [T] { + #[builtin(array_len)] + pub fn len(self) -> u64 {} + /// Push a new element to the end of the slice, returning a /// new slice with a length one greater than the /// original unmodified slice. diff --git a/noirc_macros/Cargo.toml b/noirc_macros/Cargo.toml deleted file mode 100644 index 699e6b01cae..00000000000 --- a/noirc_macros/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "noirc_macros" -version.workspace = true -authors.workspace = true -edition.workspace = true -rust-version.workspace = true -license.workspace = true -repository.workspace = true - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -noirc_frontend.workspace = true -iter-extended.workspace = true \ No newline at end of file diff --git a/noirc_macros/src/lib.rs b/noirc_macros/src/lib.rs deleted file mode 100644 index 9a916843200..00000000000 --- a/noirc_macros/src/lib.rs +++ /dev/null @@ -1,73 +0,0 @@ -use noirc_frontend::hir::def_collector::dc_crate::UnresolvedFunctions; -use noirc_frontend::hir::def_collector::dc_crate::UnresolvedTraitImpl; -use noirc_frontend::macros_api::parse_program; -use noirc_frontend::macros_api::HirContext; -use noirc_frontend::macros_api::SortedModule; -use noirc_frontend::macros_api::{CrateId, FileId}; -use noirc_frontend::macros_api::{MacroError, MacroProcessor}; - -pub struct AssertMessageMacro; - -impl MacroProcessor for AssertMessageMacro { - fn process_untyped_ast( - &self, - ast: SortedModule, - crate_id: &CrateId, - _context: &HirContext, - ) -> Result { - transform(ast, crate_id) - } - - fn process_unresolved_traits_impls( - &self, - _crate_id: &CrateId, - _context: &mut HirContext, - _unresolved_traits_impls: &[UnresolvedTraitImpl], - _collected_functions: &mut Vec, - ) -> Result<(), (MacroError, FileId)> { - Ok(()) - } - - // This macro does not need to process any information after name resolution - fn process_typed_ast( - &self, - _crate_id: &CrateId, - _context: &mut HirContext, - ) -> Result<(), (MacroError, FileId)> { - Ok(()) - } -} - -fn transform(ast: SortedModule, crate_id: &CrateId) -> Result { - let ast = add_resolve_assert_message_funcs(ast, crate_id)?; - - Ok(ast) -} - -fn add_resolve_assert_message_funcs( - mut ast: SortedModule, - crate_id: &CrateId, -) -> Result { - if !crate_id.is_stdlib() { - return Ok(ast); - } - let assert_message_oracles = " - #[oracle(assert_message)] - unconstrained fn assert_message_oracle(_input: T) {} - unconstrained pub fn resolve_assert_message(input: T, condition: bool) { - if !condition { - assert_message_oracle(input); - } - }"; - - let (assert_msg_funcs_ast, errors) = parse_program(assert_message_oracles); - assert_eq!(errors.len(), 0, "Failed to parse Noir macro code. This is either a bug in the compiler or the Noir macro code"); - - let assert_msg_funcs_ast = assert_msg_funcs_ast.into_sorted(); - - for func in assert_msg_funcs_ast.functions { - ast.functions.push(func) - } - - Ok(ast) -} diff --git a/package.json b/package.json index f460b3db711..3cffdf4c802 100644 --- a/package.json +++ b/package.json @@ -14,36 +14,29 @@ ], "scripts": { "build": "yarn workspaces foreach --parallel --topological-dev --verbose run build", - "test": "yarn workspaces foreach run test", + "test": "yarn workspaces foreach --parallel --verbose run test", "test:integration": "yarn workspace integration-tests test", "clean:workspaces": "yarn workspaces foreach --exclude @noir-lang/root run clean", - "clean:root": "rm -rf ./result ./target ./packages", + "clean:root": "rm -rf ./target ./packages", "clean": "yarn clean:workspaces && yarn clean:root", "lint": "yarn workspaces foreach --verbose run lint", "spellcheck": "cspell '**/*.{md,rs}' -c ./cspell.json", - "install:acvm_js": "yarn workspace @noir-lang/acvm_js run install:from:nix", - "install:noir_wasm": "yarn workspace @noir-lang/noir_wasm run install:from:nix", - "install:noirc_abi_wasm": "yarn workspace @noir-lang/noirc_abi run install:from:nix", - "install:from:nix": "yarn install:acvm_js && yarn install:noir_wasm && yarn install:noirc_abi_wasm", - "build:types": "yarn workspace @noir-lang/types run build", - "build:backend_barretenberg": "yarn workspace @noir-lang/backend_barretenberg run build", - "build:noir_js": "yarn workspace @noir-lang/noir_js run build", - "build:js:only": "yarn build:types && yarn build:backend_barretenberg && yarn build:noir_js", - "prepare:publish": "yarn clean && yarn install:from:nix && yarn build:js:only", + "prepare:publish": "yarn clean && yarn build", + "build:js:only": "yarn workspaces foreach -vtp --exclude \"{@noir-lang/acvm_js,@noir-lang/noirc_abi,@noir-lang/noir_wasm,docs,@noir-lang/root}\" run build", "nightly:version": "yarn workspaces foreach run nightly:version", "publish:all": "yarn install && yarn workspaces foreach run publish" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^6.7.3", "@typescript-eslint/parser": "^6.7.3", - "chai": "^4.3.7", + "chai": "^4.4.1", "cspell": "^8.3.2", - "eslint": "^8.56.0", - "eslint-plugin-prettier": "^5.0.0", + "eslint": "^8.57.0", + "eslint-plugin-prettier": "^5.1.3", "mocha": "^10.2.0", - "prettier": "3.0.3", + "prettier": "3.2.5", "ts-node": "^10.9.1", - "typescript": "^5.0.4" + "typescript": "^5.4.2" }, "packageManager": "yarn@3.6.4" } diff --git a/release-please-config.json b/release-please-config.json index e73993ca974..0ba192754a0 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -13,7 +13,6 @@ "include-component-in-tag": false, "extra-files": [ "Cargo.toml", - "flake.nix", { "type": "json", "path": "compiler/wasm/package.json", @@ -61,8 +60,8 @@ "acir_field/Cargo.toml", "acvm/Cargo.toml", "acvm_js/Cargo.toml", - "barretenberg_blackbox_solver/Cargo.toml", "blackbox_solver/Cargo.toml", + "bn254_blackbox_solver/Cargo.toml", "brillig/Cargo.toml", "brillig_vm/Cargo.toml", { @@ -82,4 +81,4 @@ "sentence-case" ], "bootstrap-sha": "690cfc0468de0b9aee53ccfe832c71c16e61e5fc" -} \ No newline at end of file +} diff --git a/scripts/bootstrap_native.sh b/scripts/bootstrap_native.sh deleted file mode 100755 index 974f0edcfec..00000000000 --- a/scripts/bootstrap_native.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -set -eu - -cd $(dirname "$0")/.. - -# If this project has been subrepod into another project, set build data manually. -export SOURCE_DATE_EPOCH=$(date +%s) -export GIT_DIRTY=false -if [ -f ".gitrepo" ]; then - export GIT_COMMIT=$(awk '/commit =/ {print $3}' .gitrepo) -else - export GIT_COMMIT=$(git rev-parse --verify HEAD) -fi - -# Check if the 'cargo' command is available in the system -if ! command -v cargo > /dev/null; then - echo "Cargo is not installed. Please install Cargo and the Rust toolchain." - exit 1 -fi - -# Build native. -if [ -n "${DEBUG:-}" ]; then - cargo build -else - cargo build --release -fi diff --git a/scripts/bootstrap_packages.sh b/scripts/bootstrap_packages.sh deleted file mode 100755 index 47ffe12beec..00000000000 --- a/scripts/bootstrap_packages.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash -set -eu - -cd $(dirname "$0")/.. - -./.github/scripts/wasm-bindgen-install.sh - -# If this project has been subrepod into another project, set build data manually. -export SOURCE_DATE_EPOCH=$(date +%s) -export GIT_DIRTY=false -if [ -f ".gitrepo" ]; then - export GIT_COMMIT=$(awk '/commit =/ {print $3}' .gitrepo) -else - export GIT_COMMIT=$(git rev-parse --verify HEAD) -fi - -yarn --immutable -yarn build - -# We create a folder called packages, that contains each package as it would be published to npm, named correctly. -# These can be useful for testing, or portaling into other projects. -yarn workspaces foreach pack - -rm -rf packages && mkdir -p packages -tar zxfv acvm-repo/acvm_js/package.tgz -C packages && mv packages/package packages/acvm_js -tar zxfv compiler/wasm/package.tgz -C packages && mv packages/package packages/noir_wasm -tar zxfv tooling/noir_codegen/package.tgz -C packages && mv packages/package packages/noir_codegen -tar zxfv tooling/noir_js/package.tgz -C packages && mv packages/package packages/noir_js -tar zxfv tooling/noir_js_backend_barretenberg/package.tgz -C packages && mv packages/package packages/backend_barretenberg -tar zxfv tooling/noir_js_types/package.tgz -C packages && mv packages/package packages/types -tar zxfv tooling/noirc_abi_wasm/package.tgz -C packages && mv packages/package packages/noirc_abi diff --git a/scripts/test_js_packages.sh b/scripts/test_js_packages.sh deleted file mode 100755 index e1e10c543e0..00000000000 --- a/scripts/test_js_packages.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -set -eu - -cd $(dirname "$0")/.. - -./.github/scripts/wasm-bindgen-install.sh - -# If this project has been subrepod into another project, set build data manually. -export SOURCE_DATE_EPOCH=$(date +%s) -export GIT_DIRTY=false -if [ -f ".gitrepo" ]; then - export GIT_COMMIT=$(awk '/commit =/ {print $3}' .gitrepo) -else - export GIT_COMMIT=$(git rev-parse --verify HEAD) -fi - -cargo build --release -export PATH="${PATH}:/usr/src/noir/target/release/" - -yarn --immutable -yarn build -./.github/scripts/playwright-install.sh - -./scripts/test.sh -yarn test diff --git a/scripts/test_native.sh b/scripts/test_native.sh deleted file mode 100755 index 9b9aa0ce4d7..00000000000 --- a/scripts/test_native.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -set -eu - -cd $(dirname "$0")/.. - -# If this project has been subrepod into another project, set build data manually. -export SOURCE_DATE_EPOCH=$(date +%s) -export GIT_DIRTY=false -if [ -f ".gitrepo" ]; then - export GIT_COMMIT=$(awk '/commit =/ {print $3}' .gitrepo) -else - export GIT_COMMIT=$(git rev-parse --verify HEAD) -fi - -cargo fmt --all --check -cargo clippy --workspace --locked --release -cargo test --workspace --locked --release diff --git a/shell.nix b/shell.nix deleted file mode 100644 index b72d4a4697b..00000000000 --- a/shell.nix +++ /dev/null @@ -1,13 +0,0 @@ -let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - flakeCompatRev = lock.nodes.flake-compat.locked.rev; - flakeCompatHash = lock.nodes.flake-compat.locked.narHash; - flakeCompat = fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${flakeCompatRev}.tar.gz"; - sha256 = flakeCompatHash; - }; - compat = import flakeCompat { - src = ./.; - }; -in -compat.shellNix diff --git a/test_programs/.gitignore b/test_programs/.gitignore index e98a2fb38b6..6da0100814a 100644 --- a/test_programs/.gitignore +++ b/test_programs/.gitignore @@ -1,3 +1,3 @@ acir_artifacts execution_success/**/crs -Nargo.toml +./Nargo.toml diff --git a/test_programs/compile_failure/array_length_defaulting/Nargo.toml b/test_programs/compile_failure/array_length_defaulting/Nargo.toml new file mode 100644 index 00000000000..fa376596ee2 --- /dev/null +++ b/test_programs/compile_failure/array_length_defaulting/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "array_length_defaulting" +type = "bin" +authors = [""] +compiler_version = ">=0.26.0" + +[dependencies] diff --git a/test_programs/compile_failure/array_length_defaulting/src/main.nr b/test_programs/compile_failure/array_length_defaulting/src/main.nr new file mode 100644 index 00000000000..216a9ae3f0c --- /dev/null +++ b/test_programs/compile_failure/array_length_defaulting/src/main.nr @@ -0,0 +1,10 @@ +fn main() { + let x = dep::std::unsafe::zeroed(); + foo(x); +} + +fn foo(array: [Field; N]) { + for elem in array { + println(elem); + } +} diff --git a/test_programs/compile_failure/brillig_mut_ref_from_acir/src/main.nr b/test_programs/compile_failure/brillig_mut_ref_from_acir/src/main.nr index cf3279cac0d..473ad8e8d6a 100644 --- a/test_programs/compile_failure/brillig_mut_ref_from_acir/src/main.nr +++ b/test_programs/compile_failure/brillig_mut_ref_from_acir/src/main.nr @@ -5,4 +5,4 @@ unconstrained fn mut_ref_identity(value: &mut Field) -> Field { fn main(mut x: Field, y: pub Field) { let returned_x = mut_ref_identity(&mut x); assert(returned_x == x); -} \ No newline at end of file +} diff --git a/test_programs/compile_failure/brillig_nested_slices/Prover.toml b/test_programs/compile_failure/brillig_nested_slices/Prover.toml deleted file mode 100644 index c52564de922..00000000000 --- a/test_programs/compile_failure/brillig_nested_slices/Prover.toml +++ /dev/null @@ -1,2 +0,0 @@ -a = "5" -b = "10" diff --git a/test_programs/compile_failure/dep_impl_primitive/Prover.toml b/test_programs/compile_failure/dep_impl_primitive/Prover.toml deleted file mode 100644 index 7d4290a117a..00000000000 --- a/test_programs/compile_failure/dep_impl_primitive/Prover.toml +++ /dev/null @@ -1 +0,0 @@ -x = 1 diff --git a/test_programs/compile_failure/depend_on_bin/Prover.toml b/test_programs/compile_failure/depend_on_bin/Prover.toml deleted file mode 100644 index 7d4290a117a..00000000000 --- a/test_programs/compile_failure/depend_on_bin/Prover.toml +++ /dev/null @@ -1 +0,0 @@ -x = 1 diff --git a/test_programs/compile_failure/dup_trait_implementation_5/Prover.toml b/test_programs/compile_failure/dup_trait_implementation_5/Prover.toml deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test_programs/compile_failure/dup_trait_items_1/Prover.toml b/test_programs/compile_failure/dup_trait_items_1/Prover.toml deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test_programs/compile_failure/dup_trait_items_2/Prover.toml b/test_programs/compile_failure/dup_trait_items_2/Prover.toml deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test_programs/compile_failure/dup_trait_items_3/Prover.toml b/test_programs/compile_failure/dup_trait_items_3/Prover.toml deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test_programs/compile_failure/dup_trait_items_4/Prover.toml b/test_programs/compile_failure/dup_trait_items_4/Prover.toml deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test_programs/compile_failure/dup_trait_items_5/Prover.toml b/test_programs/compile_failure/dup_trait_items_5/Prover.toml deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test_programs/compile_failure/dup_trait_items_6/Prover.toml b/test_programs/compile_failure/dup_trait_items_6/Prover.toml deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test_programs/compile_failure/hashmap_load_factor/Prover.toml b/test_programs/compile_failure/hashmap_load_factor/Prover.toml deleted file mode 100644 index e54319c61e9..00000000000 --- a/test_programs/compile_failure/hashmap_load_factor/Prover.toml +++ /dev/null @@ -1,26 +0,0 @@ -# Expected 6 key-value entries for hashmap capacity of 8. -# These must be distinct (both key-to-key, and value-to-value) for correct testing. - -[[input]] -key = 2 -value = 17 - -[[input]] -key = 3 -value = 19 - -[[input]] -key = 5 -value = 23 - -[[input]] -key = 7 -value = 29 - -[[input]] -key = 11 -value = 31 - -[[input]] -key = 41 -value = 43 \ No newline at end of file diff --git a/test_programs/compile_failure/negate_unsigned/Prover.toml b/test_programs/compile_failure/negate_unsigned/Prover.toml deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test_programs/compile_failure/orphaned_trait_impl/Prover.toml b/test_programs/compile_failure/orphaned_trait_impl/Prover.toml deleted file mode 100644 index 2c1854573a4..00000000000 --- a/test_programs/compile_failure/orphaned_trait_impl/Prover.toml +++ /dev/null @@ -1,2 +0,0 @@ -x = 1 -y = 2 diff --git a/test_programs/compile_failure/typevar_default/Nargo.toml b/test_programs/compile_failure/typevar_default/Nargo.toml new file mode 100644 index 00000000000..b3cd08bb8fe --- /dev/null +++ b/test_programs/compile_failure/typevar_default/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "typevar_default" +type = "bin" +authors = [""] +compiler_version = ">=0.26.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_failure/typevar_default/src/main.nr b/test_programs/compile_failure/typevar_default/src/main.nr new file mode 100644 index 00000000000..1eb9cf63de3 --- /dev/null +++ b/test_programs/compile_failure/typevar_default/src/main.nr @@ -0,0 +1,12 @@ +fn main() { + // Expecting error: type annotations needed (N not known) + let _ = slice_to_array(&[1, 2, 3]); +} + +fn slice_to_array(slice: [Field]) -> [Field; N] { + let mut array = [0; N]; + for i in 0 .. N { + array[i] = slice[i]; + } + array +} diff --git a/test_programs/compile_failure/unconstrained_oracle/Nargo.toml b/test_programs/compile_failure/unconstrained_oracle/Nargo.toml new file mode 100644 index 00000000000..7c3fb8766bf --- /dev/null +++ b/test_programs/compile_failure/unconstrained_oracle/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "unconstrained_oracle" +type = "bin" +authors = [""] +compiler_version = ">=0.25.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_failure/unconstrained_oracle/src/main.nr b/test_programs/compile_failure/unconstrained_oracle/src/main.nr new file mode 100644 index 00000000000..abc7bf51ab8 --- /dev/null +++ b/test_programs/compile_failure/unconstrained_oracle/src/main.nr @@ -0,0 +1,9 @@ +#[oracle(getNoun)] +unconstrained fn external_fn() -> Field { + 100 / 5 +} + +fn main() { + let x = anon(); + assert(x * 5 == 100); +} diff --git a/test_programs/compile_failure/unconstrained_ref/Nargo.toml b/test_programs/compile_failure/unconstrained_ref/Nargo.toml new file mode 100644 index 00000000000..c03aaea5fca --- /dev/null +++ b/test_programs/compile_failure/unconstrained_ref/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "unconstrained_ref" +type = "bin" +authors = [""] +compiler_version = ">=0.25.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_failure/unconstrained_ref/src/main.nr b/test_programs/compile_failure/unconstrained_ref/src/main.nr new file mode 100644 index 00000000000..1491badaa49 --- /dev/null +++ b/test_programs/compile_failure/unconstrained_ref/src/main.nr @@ -0,0 +1,8 @@ +unconstrained fn uncon_ref() -> &mut Field { + let lr = &mut 7; + lr +} + +fn main() { + let e = uncon_ref(); +} diff --git a/test_programs/compile_failure/workspace_missing_toml/crates/b/Prover.toml b/test_programs/compile_failure/workspace_missing_toml/crates/b/Prover.toml deleted file mode 100644 index a0397e89477..00000000000 --- a/test_programs/compile_failure/workspace_missing_toml/crates/b/Prover.toml +++ /dev/null @@ -1,2 +0,0 @@ -x = "1" -y = "0" diff --git a/test_programs/compile_success_contract/contract_with_impl/src/main.nr b/test_programs/compile_success_contract/contract_with_impl/src/main.nr index ddcb5d54d78..1c6b6c217c4 100644 --- a/test_programs/compile_success_contract/contract_with_impl/src/main.nr +++ b/test_programs/compile_success_contract/contract_with_impl/src/main.nr @@ -2,6 +2,6 @@ contract Foo { struct T { x: [Field] } impl T { - fn t(self){} + fn t(self) {} } } diff --git a/test_programs/compile_success_contract/fold_non_contract_method/Nargo.toml b/test_programs/compile_success_contract/fold_non_contract_method/Nargo.toml new file mode 100644 index 00000000000..ff64bbb6f1b --- /dev/null +++ b/test_programs/compile_success_contract/fold_non_contract_method/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "fold_non_contract_method" +type = "contract" +authors = [""] +compiler_version = ">=0.26.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_success_contract/fold_non_contract_method/src/main.nr b/test_programs/compile_success_contract/fold_non_contract_method/src/main.nr new file mode 100644 index 00000000000..2e00ffa1381 --- /dev/null +++ b/test_programs/compile_success_contract/fold_non_contract_method/src/main.nr @@ -0,0 +1,18 @@ +contract Foo { + use crate::times_10; + + fn double(x: Field) -> pub Field { + x * 2 + } + fn triple(x: Field) -> pub Field { + x * 3 + } + fn times_40(x: Field) -> pub Field { + times_10(x) * 4 + } +} + +#[fold] +fn times_10(x: Field) -> Field { + x * 10 +} diff --git a/test_programs/compile_success_contract/simple_contract/src/main.nr b/test_programs/compile_success_contract/simple_contract/src/main.nr index fea0ae08c22..7412e1386bf 100644 --- a/test_programs/compile_success_contract/simple_contract/src/main.nr +++ b/test_programs/compile_success_contract/simple_contract/src/main.nr @@ -5,15 +5,12 @@ contract Foo { fn triple(x: Field) -> pub Field { x * 3 } - internal fn quadruple(x: Field) -> pub Field { + fn quadruple(x: Field) -> pub Field { x * 4 } - open internal fn skibbidy(x: Field) -> pub Field { - x * 5 - } // Regression for issue #3344 #[contract_library_method] - fn foo(x : u8) -> u8 { + fn foo(x: u8) -> u8 { x } } diff --git a/test_programs/compile_success_empty/field_comparisons/Prover.toml b/test_programs/compile_success_empty/field_comparisons/Prover.toml deleted file mode 100644 index 8b137891791..00000000000 --- a/test_programs/compile_success_empty/field_comparisons/Prover.toml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test_programs/compile_success_empty/field_comparisons/src/main.nr b/test_programs/compile_success_empty/field_comparisons/src/main.nr deleted file mode 100644 index ed71093698d..00000000000 --- a/test_programs/compile_success_empty/field_comparisons/src/main.nr +++ /dev/null @@ -1,86 +0,0 @@ -use dep::std::field_element::bn254::{PLO, PHI, TWO_POW_128, decompose, decompose_unsafe, lt_unsafe, lte_unsafe, assert_gt, gt}; - -fn check_plo_phi() { - assert_eq(PLO + PHI * TWO_POW_128, 0); - let p_bytes = dep::std::field_element::modulus_le_bytes(); - let mut p_low: Field = 0; - let mut p_high: Field = 0; - - let mut offset = 1; - for i in 0..16 { - p_low += (p_bytes[i] as Field) * offset; - p_high += (p_bytes[i + 16] as Field) * offset; - offset *= 256; - } - assert_eq(p_low, PLO); - assert_eq(p_high, PHI); -} - -fn check_decompose_unsafe() { - assert_eq(decompose_unsafe(TWO_POW_128), (0, 1)); - assert_eq(decompose_unsafe(TWO_POW_128 + 0x1234567890), (0x1234567890, 1)); - assert_eq(decompose_unsafe(0x1234567890), (0x1234567890, 0)); -} - -fn check_decompose() { - assert_eq(decompose(TWO_POW_128), (0, 1)); - assert_eq(decompose(TWO_POW_128 + 0x1234567890), (0x1234567890, 1)); - assert_eq(decompose(0x1234567890), (0x1234567890, 0)); -} - -fn check_lt_unsafe() { - assert(lt_unsafe(0, 1, 16)); - assert(lt_unsafe(0, 0x100, 16)); - assert(lt_unsafe(0x100, TWO_POW_128 - 1, 16)); - assert(!lt_unsafe(0, TWO_POW_128, 16)); -} - -fn check_lte_unsafe() { - assert(lte_unsafe(0, 1, 16)); - assert(lte_unsafe(0, 0x100, 16)); - assert(lte_unsafe(0x100, TWO_POW_128 - 1, 16)); - assert(!lte_unsafe(0, TWO_POW_128, 16)); - - assert(lte_unsafe(0, 0, 16)); - assert(lte_unsafe(0x100, 0x100, 16)); - assert(lte_unsafe(TWO_POW_128 - 1, TWO_POW_128 - 1, 16)); - assert(lte_unsafe(TWO_POW_128, TWO_POW_128, 16)); -} - -fn check_assert_gt() { - assert_gt(1, 0); - assert_gt(0x100, 0); - assert_gt((0 - 1), (0 - 2)); - assert_gt(TWO_POW_128, 0); - assert_gt(0 - 1, 0); -} - -fn check_gt() { - assert(gt(1, 0)); - assert(gt(0x100, 0)); - assert(gt((0 - 1), (0 - 2))); - assert(gt(TWO_POW_128, 0)); - assert(!gt(0, 0)); - assert(!gt(0, 0x100)); - assert(gt(0 - 1, 0 - 2)); - assert(!gt(0 - 2, 0 - 1)); -} - -fn checks() { - check_plo_phi(); - check_decompose_unsafe(); - check_decompose(); - check_lt_unsafe(); - check_lte_unsafe(); - check_assert_gt(); - check_gt(); -} - -unconstrained fn checks_in_brillig() { - checks(); -} - -fn main() { - checks(); - checks_in_brillig(); -} diff --git a/test_programs/compile_success_empty/option/src/main.nr b/test_programs/compile_success_empty/option/src/main.nr index 989c8f65bf4..c5f321256b1 100644 --- a/test_programs/compile_success_empty/option/src/main.nr +++ b/test_programs/compile_success_empty/option/src/main.nr @@ -39,9 +39,9 @@ fn main() { let add1_u64 = |value: Field| Option::some(value as u64 + 1); - assert(none.and_then(|_value| Option::none()).is_none()); + assert(none.and_then(|_value| none).is_none()); assert(none.and_then(add1_u64).is_none()); - assert(some.and_then(|_value| Option::none()).is_none()); + assert(some.and_then(|_value| none).is_none()); assert(some.and_then(add1_u64).unwrap() == 4); assert(some.and_then(|x| Option::some(x + ten)).unwrap() == 13); diff --git a/test_programs/compile_success_empty/regression_4635/Nargo.toml b/test_programs/compile_success_empty/regression_4635/Nargo.toml new file mode 100644 index 00000000000..563e262410f --- /dev/null +++ b/test_programs/compile_success_empty/regression_4635/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "regression_4635" +type = "bin" +authors = [""] +compiler_version = ">=0.26.0" + +[dependencies] diff --git a/test_programs/compile_success_empty/regression_4635/src/main.nr b/test_programs/compile_success_empty/regression_4635/src/main.nr new file mode 100644 index 00000000000..23918e30785 --- /dev/null +++ b/test_programs/compile_success_empty/regression_4635/src/main.nr @@ -0,0 +1,59 @@ +trait FromField { + fn from_field(field: Field) -> Self; +} + +impl FromField for Field { + fn from_field(value: Field) -> Self { + value + } +} + +trait Deserialize { + fn deserialize(fields: [Field; N]) -> Self; +} + +global AZTEC_ADDRESS_LENGTH = 1; + +struct AztecAddress { + inner : Field +} + +impl FromField for AztecAddress { + fn from_field(value: Field) -> Self { + Self { inner: value } + } +} + +impl Deserialize for AztecAddress { + fn deserialize(fields: [Field; AZTEC_ADDRESS_LENGTH]) -> Self { + AztecAddress::from_field(fields[0]) + } +} + +impl Eq for AztecAddress { + fn eq(self, other: Self) -> bool { + self.inner == other.inner + } +} + +// Custom code + +struct MyStruct { + a: T +} + +impl Deserialize<1> for MyStruct { + fn deserialize(fields: [Field; 1]) -> Self where T: FromField { + Self{ a: FromField::from_field(fields[0]) } + } +} + +fn main() { + let fields = [5; 1]; + let foo = MyStruct::deserialize(fields); // Note I don't specify T here (the type of `foo.a`) + + let bar = AztecAddress { inner: 5 }; + + // Here `T` is apparently inferred to be `AztecAddress`, presumably because of the comparison. + assert(foo.a == bar); +} diff --git a/test_programs/compile_success_empty/vectors/src/main.nr b/test_programs/compile_success_empty/vectors/src/main.nr index cc026ba38fc..0365a473805 100644 --- a/test_programs/compile_success_empty/vectors/src/main.nr +++ b/test_programs/compile_success_empty/vectors/src/main.nr @@ -26,7 +26,7 @@ fn main(x: field, y: pub field) { assert(vector.get(3) == 3); assert(vector.len() == 4); - let mut inputs_vector = Vec::from_slice([x, y]); + let mut inputs_vector = Vec::from_slice(&[x, y]); assert(inputs_vector.get(0) == x); assert(inputs_vector.get(1) == y); } diff --git a/test_programs/compile_failure/assert_msg_runtime/Nargo.toml b/test_programs/execution_failure/assert_msg_runtime/Nargo.toml similarity index 100% rename from test_programs/compile_failure/assert_msg_runtime/Nargo.toml rename to test_programs/execution_failure/assert_msg_runtime/Nargo.toml diff --git a/test_programs/compile_failure/assert_msg_runtime/Prover.toml b/test_programs/execution_failure/assert_msg_runtime/Prover.toml similarity index 100% rename from test_programs/compile_failure/assert_msg_runtime/Prover.toml rename to test_programs/execution_failure/assert_msg_runtime/Prover.toml diff --git a/test_programs/compile_failure/assert_msg_runtime/src/main.nr b/test_programs/execution_failure/assert_msg_runtime/src/main.nr similarity index 99% rename from test_programs/compile_failure/assert_msg_runtime/src/main.nr rename to test_programs/execution_failure/assert_msg_runtime/src/main.nr index bec3082550a..fa21442e816 100644 --- a/test_programs/compile_failure/assert_msg_runtime/src/main.nr +++ b/test_programs/execution_failure/assert_msg_runtime/src/main.nr @@ -4,4 +4,4 @@ fn main(x: Field, y: pub Field) { let z = x + y; assert(z != y, f"Expected z != y, but got both equal {z}"); assert_eq(x, y, f"Expected x == y, but x is {x} and y is {y}"); -} \ No newline at end of file +} diff --git a/test_programs/compile_failure/brillig_assert_fail/Nargo.toml b/test_programs/execution_failure/brillig_assert_fail/Nargo.toml similarity index 100% rename from test_programs/compile_failure/brillig_assert_fail/Nargo.toml rename to test_programs/execution_failure/brillig_assert_fail/Nargo.toml diff --git a/test_programs/compile_failure/brillig_assert_fail/Prover.toml b/test_programs/execution_failure/brillig_assert_fail/Prover.toml similarity index 100% rename from test_programs/compile_failure/brillig_assert_fail/Prover.toml rename to test_programs/execution_failure/brillig_assert_fail/Prover.toml diff --git a/test_programs/compile_failure/brillig_assert_fail/src/main.nr b/test_programs/execution_failure/brillig_assert_fail/src/main.nr similarity index 100% rename from test_programs/compile_failure/brillig_assert_fail/src/main.nr rename to test_programs/execution_failure/brillig_assert_fail/src/main.nr diff --git a/test_programs/compile_failure/brillig_assert_msg_runtime/Nargo.toml b/test_programs/execution_failure/brillig_assert_msg_runtime/Nargo.toml similarity index 100% rename from test_programs/compile_failure/brillig_assert_msg_runtime/Nargo.toml rename to test_programs/execution_failure/brillig_assert_msg_runtime/Nargo.toml diff --git a/test_programs/compile_failure/brillig_assert_msg_runtime/Prover.toml b/test_programs/execution_failure/brillig_assert_msg_runtime/Prover.toml similarity index 100% rename from test_programs/compile_failure/brillig_assert_msg_runtime/Prover.toml rename to test_programs/execution_failure/brillig_assert_msg_runtime/Prover.toml diff --git a/test_programs/compile_failure/brillig_assert_msg_runtime/src/main.nr b/test_programs/execution_failure/brillig_assert_msg_runtime/src/main.nr similarity index 99% rename from test_programs/compile_failure/brillig_assert_msg_runtime/src/main.nr rename to test_programs/execution_failure/brillig_assert_msg_runtime/src/main.nr index 428b2006363..bd77551e304 100644 --- a/test_programs/compile_failure/brillig_assert_msg_runtime/src/main.nr +++ b/test_programs/execution_failure/brillig_assert_msg_runtime/src/main.nr @@ -7,4 +7,4 @@ unconstrained fn conditional(x: Field) -> Field { assert_eq(z, 25, f"Expected 25 but got {z}"); assert(x == 10, f"Expected x to equal 10, but got {x}"); 1 -} \ No newline at end of file +} diff --git a/test_programs/compile_failure/div_by_zero_constants/Nargo.toml b/test_programs/execution_failure/div_by_zero_constants/Nargo.toml similarity index 100% rename from test_programs/compile_failure/div_by_zero_constants/Nargo.toml rename to test_programs/execution_failure/div_by_zero_constants/Nargo.toml diff --git a/test_programs/compile_failure/cyclic_dep/Prover.toml b/test_programs/execution_failure/div_by_zero_constants/Prover.toml similarity index 100% rename from test_programs/compile_failure/cyclic_dep/Prover.toml rename to test_programs/execution_failure/div_by_zero_constants/Prover.toml diff --git a/test_programs/compile_failure/div_by_zero_constants/src/main.nr b/test_programs/execution_failure/div_by_zero_constants/src/main.nr similarity index 100% rename from test_programs/compile_failure/div_by_zero_constants/src/main.nr rename to test_programs/execution_failure/div_by_zero_constants/src/main.nr diff --git a/test_programs/compile_failure/div_by_zero_modulo/Nargo.toml b/test_programs/execution_failure/div_by_zero_modulo/Nargo.toml similarity index 100% rename from test_programs/compile_failure/div_by_zero_modulo/Nargo.toml rename to test_programs/execution_failure/div_by_zero_modulo/Nargo.toml diff --git a/test_programs/compile_failure/div_by_zero_constants/Prover.toml b/test_programs/execution_failure/div_by_zero_modulo/Prover.toml similarity index 100% rename from test_programs/compile_failure/div_by_zero_constants/Prover.toml rename to test_programs/execution_failure/div_by_zero_modulo/Prover.toml diff --git a/test_programs/compile_failure/div_by_zero_modulo/src/main.nr b/test_programs/execution_failure/div_by_zero_modulo/src/main.nr similarity index 100% rename from test_programs/compile_failure/div_by_zero_modulo/src/main.nr rename to test_programs/execution_failure/div_by_zero_modulo/src/main.nr diff --git a/test_programs/compile_failure/div_by_zero_numerator_witness/Nargo.toml b/test_programs/execution_failure/div_by_zero_numerator_witness/Nargo.toml similarity index 100% rename from test_programs/compile_failure/div_by_zero_numerator_witness/Nargo.toml rename to test_programs/execution_failure/div_by_zero_numerator_witness/Nargo.toml diff --git a/test_programs/compile_failure/div_by_zero_numerator_witness/Prover.toml b/test_programs/execution_failure/div_by_zero_numerator_witness/Prover.toml similarity index 100% rename from test_programs/compile_failure/div_by_zero_numerator_witness/Prover.toml rename to test_programs/execution_failure/div_by_zero_numerator_witness/Prover.toml diff --git a/test_programs/compile_failure/div_by_zero_numerator_witness/src/main.nr b/test_programs/execution_failure/div_by_zero_numerator_witness/src/main.nr similarity index 100% rename from test_programs/compile_failure/div_by_zero_numerator_witness/src/main.nr rename to test_programs/execution_failure/div_by_zero_numerator_witness/src/main.nr diff --git a/test_programs/compile_failure/div_by_zero_witness/Nargo.toml b/test_programs/execution_failure/div_by_zero_witness/Nargo.toml similarity index 100% rename from test_programs/compile_failure/div_by_zero_witness/Nargo.toml rename to test_programs/execution_failure/div_by_zero_witness/Nargo.toml diff --git a/test_programs/compile_failure/div_by_zero_witness/Prover.toml b/test_programs/execution_failure/div_by_zero_witness/Prover.toml similarity index 100% rename from test_programs/compile_failure/div_by_zero_witness/Prover.toml rename to test_programs/execution_failure/div_by_zero_witness/Prover.toml diff --git a/test_programs/compile_failure/div_by_zero_witness/src/main.nr b/test_programs/execution_failure/div_by_zero_witness/src/main.nr similarity index 100% rename from test_programs/compile_failure/div_by_zero_witness/src/main.nr rename to test_programs/execution_failure/div_by_zero_witness/src/main.nr diff --git a/test_programs/compile_failure/dyn_index_fail_nested_array/Nargo.toml b/test_programs/execution_failure/dyn_index_fail_nested_array/Nargo.toml similarity index 100% rename from test_programs/compile_failure/dyn_index_fail_nested_array/Nargo.toml rename to test_programs/execution_failure/dyn_index_fail_nested_array/Nargo.toml diff --git a/test_programs/compile_failure/dyn_index_fail_nested_array/Prover.toml b/test_programs/execution_failure/dyn_index_fail_nested_array/Prover.toml similarity index 100% rename from test_programs/compile_failure/dyn_index_fail_nested_array/Prover.toml rename to test_programs/execution_failure/dyn_index_fail_nested_array/Prover.toml diff --git a/test_programs/compile_failure/dyn_index_fail_nested_array/src/main.nr b/test_programs/execution_failure/dyn_index_fail_nested_array/src/main.nr similarity index 100% rename from test_programs/compile_failure/dyn_index_fail_nested_array/src/main.nr rename to test_programs/execution_failure/dyn_index_fail_nested_array/src/main.nr diff --git a/test_programs/compile_failure/dynamic_index_failure/Nargo.toml b/test_programs/execution_failure/dynamic_index_failure/Nargo.toml similarity index 100% rename from test_programs/compile_failure/dynamic_index_failure/Nargo.toml rename to test_programs/execution_failure/dynamic_index_failure/Nargo.toml diff --git a/test_programs/compile_failure/dynamic_index_failure/Prover.toml b/test_programs/execution_failure/dynamic_index_failure/Prover.toml similarity index 100% rename from test_programs/compile_failure/dynamic_index_failure/Prover.toml rename to test_programs/execution_failure/dynamic_index_failure/Prover.toml diff --git a/test_programs/compile_failure/dynamic_index_failure/src/main.nr b/test_programs/execution_failure/dynamic_index_failure/src/main.nr similarity index 100% rename from test_programs/compile_failure/dynamic_index_failure/src/main.nr rename to test_programs/execution_failure/dynamic_index_failure/src/main.nr diff --git a/test_programs/compile_failure/hashmap_load_factor/Nargo.toml b/test_programs/execution_failure/hashmap_load_factor/Nargo.toml similarity index 100% rename from test_programs/compile_failure/hashmap_load_factor/Nargo.toml rename to test_programs/execution_failure/hashmap_load_factor/Nargo.toml diff --git a/test_programs/execution_failure/hashmap_load_factor/Prover.toml b/test_programs/execution_failure/hashmap_load_factor/Prover.toml new file mode 100644 index 00000000000..6d72cab47fa --- /dev/null +++ b/test_programs/execution_failure/hashmap_load_factor/Prover.toml @@ -0,0 +1,23 @@ +[[input]] +key = 1 +value = 0 + +[[input]] +key = 2 +value = 0 + +[[input]] +key = 3 +value = 0 + +[[input]] +key = 4 +value = 0 + +[[input]] +key = 5 +value = 0 + +[[input]] +key = 6 +value = 0 diff --git a/test_programs/compile_failure/hashmap_load_factor/src/main.nr b/test_programs/execution_failure/hashmap_load_factor/src/main.nr similarity index 100% rename from test_programs/compile_failure/hashmap_load_factor/src/main.nr rename to test_programs/execution_failure/hashmap_load_factor/src/main.nr diff --git a/test_programs/compile_failure/option_expect/Nargo.toml b/test_programs/execution_failure/option_expect/Nargo.toml similarity index 100% rename from test_programs/compile_failure/option_expect/Nargo.toml rename to test_programs/execution_failure/option_expect/Nargo.toml diff --git a/test_programs/compile_failure/option_expect/src/main.nr b/test_programs/execution_failure/option_expect/src/main.nr similarity index 100% rename from test_programs/compile_failure/option_expect/src/main.nr rename to test_programs/execution_failure/option_expect/src/main.nr diff --git a/test_programs/compile_failure/slice_access_failure/Nargo.toml b/test_programs/execution_failure/slice_access_failure/Nargo.toml similarity index 100% rename from test_programs/compile_failure/slice_access_failure/Nargo.toml rename to test_programs/execution_failure/slice_access_failure/Nargo.toml diff --git a/test_programs/compile_failure/radix_non_constant_length/Prover.toml b/test_programs/execution_failure/slice_access_failure/Prover.toml similarity index 100% rename from test_programs/compile_failure/radix_non_constant_length/Prover.toml rename to test_programs/execution_failure/slice_access_failure/Prover.toml diff --git a/test_programs/compile_failure/slice_access_failure/src/main.nr b/test_programs/execution_failure/slice_access_failure/src/main.nr similarity index 100% rename from test_programs/compile_failure/slice_access_failure/src/main.nr rename to test_programs/execution_failure/slice_access_failure/src/main.nr diff --git a/test_programs/compile_failure/slice_insert_failure/Nargo.toml b/test_programs/execution_failure/slice_insert_failure/Nargo.toml similarity index 100% rename from test_programs/compile_failure/slice_insert_failure/Nargo.toml rename to test_programs/execution_failure/slice_insert_failure/Nargo.toml diff --git a/test_programs/compile_failure/slice_access_failure/Prover.toml b/test_programs/execution_failure/slice_insert_failure/Prover.toml similarity index 100% rename from test_programs/compile_failure/slice_access_failure/Prover.toml rename to test_programs/execution_failure/slice_insert_failure/Prover.toml diff --git a/test_programs/compile_failure/slice_insert_failure/src/main.nr b/test_programs/execution_failure/slice_insert_failure/src/main.nr similarity index 100% rename from test_programs/compile_failure/slice_insert_failure/src/main.nr rename to test_programs/execution_failure/slice_insert_failure/src/main.nr diff --git a/test_programs/compile_failure/slice_remove_failure/Nargo.toml b/test_programs/execution_failure/slice_remove_failure/Nargo.toml similarity index 100% rename from test_programs/compile_failure/slice_remove_failure/Nargo.toml rename to test_programs/execution_failure/slice_remove_failure/Nargo.toml diff --git a/test_programs/compile_failure/slice_insert_failure/Prover.toml b/test_programs/execution_failure/slice_remove_failure/Prover.toml similarity index 100% rename from test_programs/compile_failure/slice_insert_failure/Prover.toml rename to test_programs/execution_failure/slice_remove_failure/Prover.toml diff --git a/test_programs/compile_failure/slice_remove_failure/src/main.nr b/test_programs/execution_failure/slice_remove_failure/src/main.nr similarity index 100% rename from test_programs/compile_failure/slice_remove_failure/src/main.nr rename to test_programs/execution_failure/slice_remove_failure/src/main.nr diff --git a/test_programs/compile_failure/workspace_fail/Nargo.toml b/test_programs/execution_failure/workspace_fail/Nargo.toml similarity index 100% rename from test_programs/compile_failure/workspace_fail/Nargo.toml rename to test_programs/execution_failure/workspace_fail/Nargo.toml diff --git a/test_programs/compile_failure/workspace_fail/crates/a/Nargo.toml b/test_programs/execution_failure/workspace_fail/crates/a/Nargo.toml similarity index 100% rename from test_programs/compile_failure/workspace_fail/crates/a/Nargo.toml rename to test_programs/execution_failure/workspace_fail/crates/a/Nargo.toml diff --git a/test_programs/compile_failure/workspace_fail/crates/a/Prover.toml b/test_programs/execution_failure/workspace_fail/crates/a/Prover.toml similarity index 100% rename from test_programs/compile_failure/workspace_fail/crates/a/Prover.toml rename to test_programs/execution_failure/workspace_fail/crates/a/Prover.toml diff --git a/test_programs/compile_failure/workspace_fail/crates/a/src/main.nr b/test_programs/execution_failure/workspace_fail/crates/a/src/main.nr similarity index 100% rename from test_programs/compile_failure/workspace_fail/crates/a/src/main.nr rename to test_programs/execution_failure/workspace_fail/crates/a/src/main.nr diff --git a/test_programs/compile_failure/workspace_fail/crates/b/Nargo.toml b/test_programs/execution_failure/workspace_fail/crates/b/Nargo.toml similarity index 100% rename from test_programs/compile_failure/workspace_fail/crates/b/Nargo.toml rename to test_programs/execution_failure/workspace_fail/crates/b/Nargo.toml diff --git a/test_programs/compile_failure/workspace_fail/crates/b/Prover.toml b/test_programs/execution_failure/workspace_fail/crates/b/Prover.toml similarity index 100% rename from test_programs/compile_failure/workspace_fail/crates/b/Prover.toml rename to test_programs/execution_failure/workspace_fail/crates/b/Prover.toml diff --git a/test_programs/compile_failure/workspace_fail/crates/b/src/main.nr b/test_programs/execution_failure/workspace_fail/crates/b/src/main.nr similarity index 100% rename from test_programs/compile_failure/workspace_fail/crates/b/src/main.nr rename to test_programs/execution_failure/workspace_fail/crates/b/src/main.nr diff --git a/test_programs/execution_success/array_to_slice/Nargo.toml b/test_programs/execution_success/array_to_slice/Nargo.toml new file mode 100644 index 00000000000..90c67b07b2b --- /dev/null +++ b/test_programs/execution_success/array_to_slice/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "array_to_slice" +type = "bin" +authors = [""] +compiler_version = ">=0.24.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_failure/workspace_missing_toml/crates/a/Prover.toml b/test_programs/execution_success/array_to_slice/Prover.toml similarity index 50% rename from test_programs/compile_failure/workspace_missing_toml/crates/a/Prover.toml rename to test_programs/execution_success/array_to_slice/Prover.toml index 465ef562de4..26fdbc19975 100644 --- a/test_programs/compile_failure/workspace_missing_toml/crates/a/Prover.toml +++ b/test_programs/execution_success/array_to_slice/Prover.toml @@ -1,2 +1,2 @@ -x = "1" +x = "0" y = "1" diff --git a/test_programs/execution_success/array_to_slice/src/main.nr b/test_programs/execution_success/array_to_slice/src/main.nr new file mode 100644 index 00000000000..0d0f9562d7b --- /dev/null +++ b/test_programs/execution_success/array_to_slice/src/main.nr @@ -0,0 +1,56 @@ +// Converts an array into a slice. +fn as_slice_push(xs: [T; N]) -> [T] { + let mut slice = &[]; + for elem in xs { + slice = slice.push_back(elem); + } + slice +} + +// Expected that x == 0 and y == 1 +fn main(x: Field, y: pub Field) { + let xs: [Field; 0] = []; + let ys: [Field; 1] = [1]; + let zs: [Field; 2] = [1, 2]; + let ws: [Field; 3] = [1; 3]; + let qs: [Field; 4] = [3, 2, 1, 0]; + + let mut dynamic: [Field; 4] = [3, 2, 1, 0]; + let dynamic_expected: [Field; 4] = [1000, 2, 1, 0]; + dynamic[x] = 1000; + + assert(x != y); + assert(xs.as_slice() == as_slice_push(xs)); + assert(ys.as_slice() == as_slice_push(ys)); + assert(zs.as_slice() == as_slice_push(zs)); + assert(ws.as_slice() == as_slice_push(ws)); + assert(qs.as_slice() == as_slice_push(qs)); + + assert(dynamic.as_slice()[0] == dynamic_expected[0]); + assert(dynamic.as_slice()[1] == dynamic_expected[1]); + assert(dynamic.as_slice()[2] == dynamic_expected[2]); + assert(dynamic.as_slice()[3] == dynamic_expected[3]); + assert(dynamic.as_slice().len() == 4); + + regression_4609_append_slices(x, y); + regression_4609_append_dynamic_slices(x, y); +} + +fn regression_4609_append_slices(x: Field, y: Field) { + let sl = [x, 1, 2, 3].as_slice(); + let sl2 = [y, 5, 6].as_slice(); + let sl3 = sl.append(sl2); + assert(sl3[0] == x); + assert(sl3[4] == y); +} + +fn regression_4609_append_dynamic_slices(x: Field, y: Field) { + let mut sl = [x, 1, 2, 3].as_slice(); + sl[x] = x + 10; + let mut sl2 = [y, 5, 6].as_slice(); + sl2[y] = y + 5; + let sl3 = sl.append(sl2); + assert(sl3[0] == 10); + assert(sl3[4] == y); + assert(sl3[5] == 6); +} diff --git a/test_programs/execution_success/array_to_slice_constant_length/Nargo.toml b/test_programs/execution_success/array_to_slice_constant_length/Nargo.toml new file mode 100644 index 00000000000..b338cf9b6ae --- /dev/null +++ b/test_programs/execution_success/array_to_slice_constant_length/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "array_to_slice_constant_length" +type = "bin" +authors = [""] +compiler_version = ">=0.26.0" + +[dependencies] diff --git a/test_programs/execution_success/array_to_slice_constant_length/Prover.toml b/test_programs/execution_success/array_to_slice_constant_length/Prover.toml new file mode 100644 index 00000000000..a52e9d3c46a --- /dev/null +++ b/test_programs/execution_success/array_to_slice_constant_length/Prover.toml @@ -0,0 +1 @@ +val = "42" diff --git a/test_programs/execution_success/array_to_slice_constant_length/src/main.nr b/test_programs/execution_success/array_to_slice_constant_length/src/main.nr new file mode 100644 index 00000000000..e81dd4a0c5f --- /dev/null +++ b/test_programs/execution_success/array_to_slice_constant_length/src/main.nr @@ -0,0 +1,10 @@ +// Regression test for https://github.com/noir-lang/noir/issues/4722 + +unconstrained fn return_array(val: Field) -> [Field; 1] { + [val; 1] +} + +fn main(val: Field) { + let array = return_array(val); + assert_constant(array.as_slice().len()); +} diff --git a/test_programs/execution_success/bigint/src/main.nr b/test_programs/execution_success/bigint/src/main.nr index b93fec370e5..db269d63ac0 100644 --- a/test_programs/execution_success/bigint/src/main.nr +++ b/test_programs/execution_success/bigint/src/main.nr @@ -1,8 +1,9 @@ use dep::std::bigint; +use dep::std::{bigint::Secpk1Fq, println}; fn main(mut x: [u8; 5], y: [u8; 5]) { - let a = bigint::Secpk1Fq::from_le_bytes([x[0], x[1], x[2], x[3], x[4]]); - let b = bigint::Secpk1Fq::from_le_bytes([y[0], y[1], y[2], y[3], y[4]]); + let a = bigint::Secpk1Fq::from_le_bytes(&[x[0], x[1], x[2], x[3], x[4]]); + let b = bigint::Secpk1Fq::from_le_bytes(&[y[0], y[1], y[2], y[3], y[4]]); let a_bytes = a.to_le_bytes(); let b_bytes = b.to_le_bytes(); for i in 0..5 { @@ -13,4 +14,15 @@ fn main(mut x: [u8; 5], y: [u8; 5]) { let d = a * b - b; let d1 = bigint::Secpk1Fq::from_le_bytes(597243850900842442924.to_le_bytes(10)); assert(d1 == d); + // big_int_example(x[0], x[1]); } + +// docs:start:big_int_example +fn big_int_example(x: u8, y: u8) { + let a = Secpk1Fq::from_le_bytes(&[x, y, 0, 45, 2]); + let b = Secpk1Fq::from_le_bytes(&[y, x, 9]); + let c = (a + b) * b / a; + let d = c.to_le_bytes(); + println(d[0]); +} +// docs:end:big_int_example diff --git a/test_programs/execution_success/bit_shifts_runtime/src/main.nr b/test_programs/execution_success/bit_shifts_runtime/src/main.nr index 28b3ef656c1..ff424c9fbf6 100644 --- a/test_programs/execution_success/bit_shifts_runtime/src/main.nr +++ b/test_programs/execution_success/bit_shifts_runtime/src/main.nr @@ -7,7 +7,7 @@ fn main(x: u64, y: u64) { assert(x >> y == 32); // Bit-shift with signed integers - let mut a :i8 = y as i8; + let mut a: i8 = y as i8; let mut b: i8 = x as i8; assert(b << 1 == -128); assert(b >> 2 == 16); diff --git a/test_programs/execution_success/break_and_continue/Nargo.toml b/test_programs/execution_success/break_and_continue/Nargo.toml new file mode 100644 index 00000000000..483602478ba --- /dev/null +++ b/test_programs/execution_success/break_and_continue/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "break_and_continue" +type = "bin" +authors = [""] +compiler_version = ">=0.24.0" + +[dependencies] diff --git a/test_programs/execution_success/break_and_continue/src/main.nr b/test_programs/execution_success/break_and_continue/src/main.nr new file mode 100644 index 00000000000..67dce03ac64 --- /dev/null +++ b/test_programs/execution_success/break_and_continue/src/main.nr @@ -0,0 +1,15 @@ +unconstrained fn main() { + let mut count = 0; + + for i in 0..10 { + if i == 2 { + continue; + } + if i == 5 { + break; + } + count += 1; + } + + assert(count == 4); +} diff --git a/test_programs/execution_success/brillig_array_to_slice/Nargo.toml b/test_programs/execution_success/brillig_array_to_slice/Nargo.toml new file mode 100644 index 00000000000..58157c38c26 --- /dev/null +++ b/test_programs/execution_success/brillig_array_to_slice/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "brillig_array_to_slice" +type = "bin" +authors = [""] +compiler_version = ">=0.25.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/execution_success/brillig_array_to_slice/Prover.toml b/test_programs/execution_success/brillig_array_to_slice/Prover.toml new file mode 100644 index 00000000000..11497a473bc --- /dev/null +++ b/test_programs/execution_success/brillig_array_to_slice/Prover.toml @@ -0,0 +1 @@ +x = "0" diff --git a/test_programs/execution_success/brillig_array_to_slice/src/main.nr b/test_programs/execution_success/brillig_array_to_slice/src/main.nr new file mode 100644 index 00000000000..8f7fcf24bae --- /dev/null +++ b/test_programs/execution_success/brillig_array_to_slice/src/main.nr @@ -0,0 +1,18 @@ +unconstrained fn brillig_as_slice(x: Field) -> (u64, Field, Field) { + let mut dynamic: [Field; 1] = [1]; + dynamic[x] = 2; + assert(dynamic[0] == 2); + + let brillig_slice = dynamic.as_slice(); + assert(brillig_slice.len() == 1); + + (brillig_slice.len(), dynamic[0], brillig_slice[0]) +} + +fn main(x: Field) { + let (slice_len, dynamic_0, slice_0) = brillig_as_slice(x); + assert(slice_len == 1); + assert(dynamic_0 == 2); + assert(slice_0 == 2); +} + diff --git a/test_programs/execution_success/brillig_cow_assign/Nargo.toml b/test_programs/execution_success/brillig_cow_assign/Nargo.toml new file mode 100644 index 00000000000..a878566a372 --- /dev/null +++ b/test_programs/execution_success/brillig_cow_assign/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "brillig_cow_assign" +type = "bin" +authors = [""] +compiler_version = ">=0.23.0" + +[dependencies] diff --git a/test_programs/execution_success/brillig_cow_assign/Prover.toml b/test_programs/execution_success/brillig_cow_assign/Prover.toml new file mode 100644 index 00000000000..882c73b83f8 --- /dev/null +++ b/test_programs/execution_success/brillig_cow_assign/Prover.toml @@ -0,0 +1,2 @@ +items_to_update = 10 +index = 6 diff --git a/test_programs/execution_success/brillig_cow_assign/src/main.nr b/test_programs/execution_success/brillig_cow_assign/src/main.nr new file mode 100644 index 00000000000..e5c3e2bd2f5 --- /dev/null +++ b/test_programs/execution_success/brillig_cow_assign/src/main.nr @@ -0,0 +1,23 @@ +global N = 10; + +unconstrained fn main() { + let mut arr = [0; N]; + let mut mid_change = arr; + + for i in 0..N { + if i == N / 2 { + mid_change = arr; + } + arr[i] = 27; + } + + // Expect: + // arr = [27, 27, 27, 27, 27, 27, 27, 27, 27, 27] + // mid_change = [27, 27, 27, 27, 27, 0, 0, 0, 0, 0] + + let modified_i = N / 2 + 1; + assert_eq(arr[modified_i], 27); + + // Fail here! + assert(mid_change[modified_i] != 27); +} diff --git a/test_programs/execution_success/brillig_cow_regression/src/main.nr b/test_programs/execution_success/brillig_cow_regression/src/main.nr index e638459bef0..04cb4765690 100644 --- a/test_programs/execution_success/brillig_cow_regression/src/main.nr +++ b/test_programs/execution_success/brillig_cow_regression/src/main.nr @@ -8,9 +8,9 @@ global MAX_NEW_CONTRACTS_PER_TX: u64 = 1; global NUM_ENCRYPTED_LOGS_HASHES_PER_TX: u64 = 1; global NUM_UNENCRYPTED_LOGS_HASHES_PER_TX: u64 = 1; global NUM_FIELDS_PER_SHA256 = 2; -global CALLDATA_HASH_INPUT_SIZE = 169; -global CALL_DATA_HASH_LOG_FIELDS = 4; -global CALL_DATA_HASH_FULL_FIELDS = 165; +global TX_EFFECT_HASH_INPUT_SIZE = 169; +global TX_EFFECT_HASH_LOG_FIELDS = 4; +global TX_EFFECT_HASH_FULL_FIELDS = 165; struct PublicDataUpdateRequest { leaf_slot : Field, @@ -99,7 +99,7 @@ impl U256 { } unconstrained fn main(kernel_data: DataToHash) -> pub [field; NUM_FIELDS_PER_SHA256] { - let mut calldata_hash_inputs = [0; CALLDATA_HASH_INPUT_SIZE]; + let mut tx_effects_hash_inputs = [0; TX_EFFECT_HASH_INPUT_SIZE]; let new_note_hashes = kernel_data.new_note_hashes; let new_nullifiers = kernel_data.new_nullifiers; @@ -111,65 +111,65 @@ unconstrained fn main(kernel_data: DataToHash) -> pub [field; NUM_FIELDS_PER_SHA let mut offset = 0; for j in 0..MAX_NEW_NOTE_HASHES_PER_TX { - calldata_hash_inputs[offset + j] = new_note_hashes[j]; + tx_effects_hash_inputs[offset + j] = new_note_hashes[j]; } offset += MAX_NEW_NOTE_HASHES_PER_TX ; for j in 0..MAX_NEW_NULLIFIERS_PER_TX { - calldata_hash_inputs[offset + j] = new_nullifiers[j]; + tx_effects_hash_inputs[offset + j] = new_nullifiers[j]; } offset += MAX_NEW_NULLIFIERS_PER_TX ; for j in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX { - calldata_hash_inputs[offset + j * 2] = + tx_effects_hash_inputs[offset + j * 2] = public_data_update_requests[j].leaf_slot; - calldata_hash_inputs[offset + j * 2 + 1] = + tx_effects_hash_inputs[offset + j * 2 + 1] = public_data_update_requests[j].new_value; } offset += MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * 2; for j in 0..MAX_NEW_L2_TO_L1_MSGS_PER_TX { - calldata_hash_inputs[offset + j] = newL2ToL1msgs[j]; + tx_effects_hash_inputs[offset + j] = newL2ToL1msgs[j]; } offset += MAX_NEW_L2_TO_L1_MSGS_PER_TX; let contract_leaf = kernel_data.new_contracts[0]; - calldata_hash_inputs[offset] = contract_leaf.hash(); + tx_effects_hash_inputs[offset] = contract_leaf.hash(); offset += MAX_NEW_CONTRACTS_PER_TX; let new_contracts = kernel_data.new_contracts; - calldata_hash_inputs[offset] = new_contracts[0].contract_address; + tx_effects_hash_inputs[offset] = new_contracts[0].contract_address; - calldata_hash_inputs[offset + 1] = new_contracts[0].portal_contract_address; + tx_effects_hash_inputs[offset + 1] = new_contracts[0].portal_contract_address; offset += MAX_NEW_CONTRACTS_PER_TX * 2; for j in 0..NUM_FIELDS_PER_SHA256 { - calldata_hash_inputs[offset + j] = encryptedLogsHash[j]; + tx_effects_hash_inputs[offset + j] = encryptedLogsHash[j]; } offset += NUM_ENCRYPTED_LOGS_HASHES_PER_TX * NUM_FIELDS_PER_SHA256; for j in 0..NUM_FIELDS_PER_SHA256 { - calldata_hash_inputs[offset + j] = unencryptedLogsHash[j]; + tx_effects_hash_inputs[offset + j] = unencryptedLogsHash[j]; } offset += NUM_UNENCRYPTED_LOGS_HASHES_PER_TX * NUM_FIELDS_PER_SHA256; - assert_eq(offset, CALLDATA_HASH_INPUT_SIZE); // Sanity check + assert_eq(offset, TX_EFFECT_HASH_INPUT_SIZE); // Sanity check - let mut hash_input_flattened = [0; CALL_DATA_HASH_FULL_FIELDS * 32 + CALL_DATA_HASH_LOG_FIELDS * 16]; - for offset in 0..CALL_DATA_HASH_FULL_FIELDS { - let input_as_bytes = calldata_hash_inputs[offset].to_be_bytes(32); + let mut hash_input_flattened = [0; TX_EFFECT_HASH_FULL_FIELDS * 32 + TX_EFFECT_HASH_LOG_FIELDS * 16]; + for offset in 0..TX_EFFECT_HASH_FULL_FIELDS { + let input_as_bytes = tx_effects_hash_inputs[offset].to_be_bytes(32); for byte_index in 0..32 { hash_input_flattened[offset * 32 + byte_index] = input_as_bytes[byte_index]; } } - for log_field_index in 0..CALL_DATA_HASH_LOG_FIELDS { - let input_as_bytes = calldata_hash_inputs[CALL_DATA_HASH_FULL_FIELDS + log_field_index].to_be_bytes(16); + for log_field_index in 0..TX_EFFECT_HASH_LOG_FIELDS { + let input_as_bytes = tx_effects_hash_inputs[TX_EFFECT_HASH_FULL_FIELDS + log_field_index].to_be_bytes(16); for byte_index in 0..16 { - hash_input_flattened[CALL_DATA_HASH_FULL_FIELDS * 32 + log_field_index * 16 + byte_index] = input_as_bytes[byte_index]; + hash_input_flattened[TX_EFFECT_HASH_FULL_FIELDS * 32 + log_field_index * 16 + byte_index] = input_as_bytes[byte_index]; } } diff --git a/test_programs/execution_success/brillig_fns_as_values/Prover.toml b/test_programs/execution_success/brillig_fns_as_values/Prover.toml index 11497a473bc..4dd6b405159 100644 --- a/test_programs/execution_success/brillig_fns_as_values/Prover.toml +++ b/test_programs/execution_success/brillig_fns_as_values/Prover.toml @@ -1 +1 @@ -x = "0" +x = "1" diff --git a/test_programs/execution_success/brillig_fns_as_values/src/main.nr b/test_programs/execution_success/brillig_fns_as_values/src/main.nr index ea3148915b8..9248bff2f4c 100644 --- a/test_programs/execution_success/brillig_fns_as_values/src/main.nr +++ b/test_programs/execution_success/brillig_fns_as_values/src/main.nr @@ -7,9 +7,9 @@ struct MyStruct { fn main(x: u32) { assert(wrapper(increment, x) == x + 1); assert(wrapper(increment_acir, x) == x + 1); - assert(wrapper(decrement, x) == std::wrapping_sub(x, 1)); + assert(wrapper(decrement, x) == x - 1); assert(wrapper_with_struct(MyStruct { operation: increment }, x) == x + 1); - assert(wrapper_with_struct(MyStruct { operation: decrement }, x) == std::wrapping_sub(x, 1)); + assert(wrapper_with_struct(MyStruct { operation: decrement }, x) == x - 1); // https://github.com/noir-lang/noir/issues/1975 assert(increment(x) == x + 1); } diff --git a/test_programs/execution_success/brillig_hash_to_field/src/main.nr b/test_programs/execution_success/brillig_hash_to_field/src/main.nr index 952ed90f0fe..06a101b612a 100644 --- a/test_programs/execution_success/brillig_hash_to_field/src/main.nr +++ b/test_programs/execution_success/brillig_hash_to_field/src/main.nr @@ -7,5 +7,5 @@ fn main(input: field) -> pub field { } unconstrained fn hash_to_field(input: field) -> field { - std::hash::hash_to_field([input]) + std::hash::hash_to_field(&[input]) } diff --git a/test_programs/execution_success/brillig_keccak/src/main.nr b/test_programs/execution_success/brillig_keccak/src/main.nr index 41725125aba..0de00faafbd 100644 --- a/test_programs/execution_success/brillig_keccak/src/main.nr +++ b/test_programs/execution_success/brillig_keccak/src/main.nr @@ -7,7 +7,7 @@ fn main(x: field, result: [u8; 32]) { // The padding is taken care of by the program let digest = keccak256([x as u8], 1); assert(digest == result); - //#1399: variable meesage size + //#1399: variable message size let message_size = 4; let hash_a = keccak256([1, 2, 3, 4], message_size); let hash_b = keccak256([1, 2, 3, 4, 0, 0, 0, 0], message_size); diff --git a/test_programs/execution_success/brillig_schnorr/src/main.nr b/test_programs/execution_success/brillig_schnorr/src/main.nr index 4f17d4fa0fe..9b036c9f5b5 100644 --- a/test_programs/execution_success/brillig_schnorr/src/main.nr +++ b/test_programs/execution_success/brillig_schnorr/src/main.nr @@ -17,7 +17,7 @@ unconstrained fn main( // Is there ever a situation where someone would want // to ensure that a signature was invalid? // Check that passing a slice as the message is valid - let valid_signature = std::schnorr::verify_signature(pub_key_x, pub_key_y, signature, message_field_bytes); + let valid_signature = std::schnorr::verify_signature_slice(pub_key_x, pub_key_y, signature, message_field_bytes); assert(valid_signature); // Check that passing an array as the message is valid let valid_signature = std::schnorr::verify_signature(pub_key_x, pub_key_y, signature, message); diff --git a/test_programs/execution_success/brillig_signed_cmp/Nargo.toml b/test_programs/execution_success/brillig_signed_cmp/Nargo.toml new file mode 100644 index 00000000000..3f485df4a82 --- /dev/null +++ b/test_programs/execution_success/brillig_signed_cmp/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "brillig_signed_cmp" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/execution_success/brillig_signed_cmp/Prover.toml b/test_programs/execution_success/brillig_signed_cmp/Prover.toml new file mode 100644 index 00000000000..4b719f83c16 --- /dev/null +++ b/test_programs/execution_success/brillig_signed_cmp/Prover.toml @@ -0,0 +1 @@ +minus_one = 255 diff --git a/test_programs/execution_success/brillig_signed_cmp/src/main.nr b/test_programs/execution_success/brillig_signed_cmp/src/main.nr new file mode 100644 index 00000000000..3e3ea0f4b0f --- /dev/null +++ b/test_programs/execution_success/brillig_signed_cmp/src/main.nr @@ -0,0 +1,8 @@ +unconstrained fn main(minus_one: i8) { + assert(minus_one < 0); + assert(0 < minus_one as u8); + assert(0 > minus_one); + let most_negative_number = minus_one * 127 - 1; + assert(most_negative_number < 0); + assert(127 > most_negative_number); +} diff --git a/test_programs/execution_success/brillig_signed_div/Nargo.toml b/test_programs/execution_success/brillig_signed_div/Nargo.toml new file mode 100644 index 00000000000..4bb9c5ecc1c --- /dev/null +++ b/test_programs/execution_success/brillig_signed_div/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "brillig_signed_div" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/execution_success/brillig_signed_div/Prover.toml b/test_programs/execution_success/brillig_signed_div/Prover.toml new file mode 100644 index 00000000000..be93fec5cc3 --- /dev/null +++ b/test_programs/execution_success/brillig_signed_div/Prover.toml @@ -0,0 +1,75 @@ +[[ops]] +lhs = 4 +rhs = 255 # -1 +result = 252 # -4 + +[[ops]] +lhs = 4 +rhs = 254 # -2 +result = 254 # -2 + +[[ops]] +lhs = 4 +rhs = 253 # -3 +result = 255 # -1 + +[[ops]] +lhs = 4 +rhs = 252 # -4 +result = 255 # -1 + +[[ops]] +lhs = 4 +rhs = 251 # -5 +result = 0 + +[[ops]] +lhs = 252 # -4 +rhs = 255 # -1 +result = 4 + +[[ops]] +lhs = 252 # -4 +rhs = 254 # -2 +result = 2 + +[[ops]] +lhs = 252 # -4 +rhs = 253 # -3 +result = 1 + +[[ops]] +lhs = 252 # -4 +rhs = 252 # -4 +result = 1 + +[[ops]] +lhs = 252 # -4 +rhs = 251 # -5 +result = 0 + + +[[ops]] +lhs = 4 +rhs = 1 +result = 4 + +[[ops]] +lhs = 4 +rhs = 2 +result = 2 + +[[ops]] +lhs = 4 +rhs = 3 +result = 1 + +[[ops]] +lhs = 4 +rhs = 4 +result = 1 + +[[ops]] +lhs = 4 +rhs = 5 +result = 0 diff --git a/test_programs/execution_success/brillig_signed_div/src/main.nr b/test_programs/execution_success/brillig_signed_div/src/main.nr new file mode 100644 index 00000000000..bc3f5c3bdc0 --- /dev/null +++ b/test_programs/execution_success/brillig_signed_div/src/main.nr @@ -0,0 +1,11 @@ +struct SignedDivOp { + lhs: i8, + rhs: i8, + result: i8, +} + +unconstrained fn main(ops: [SignedDivOp; 15]) { + for i in 0..15 { + assert_eq(ops[i].lhs / ops[i].rhs, ops[i].result); + } +} diff --git a/test_programs/execution_success/brillig_slice_input/Nargo.toml b/test_programs/execution_success/brillig_slice_input/Nargo.toml new file mode 100644 index 00000000000..a1c8cc3242b --- /dev/null +++ b/test_programs/execution_success/brillig_slice_input/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "brillig_slice_input" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/execution_success/brillig_slice_input/src/main.nr b/test_programs/execution_success/brillig_slice_input/src/main.nr new file mode 100644 index 00000000000..09a9d9aef9d --- /dev/null +++ b/test_programs/execution_success/brillig_slice_input/src/main.nr @@ -0,0 +1,40 @@ +struct Point { + x: Field, + y: Field, +} + +unconstrained fn sum_slice(slice: [[Point; 2]]) -> Field { + let mut sum = 0; + for i in 0..slice.len() { + for j in 0..slice[i].len() { + sum += slice[i][j].x + slice[i][j].y; + } + } + sum +} + +fn main() { + let mut slice = &[]; + slice = slice.push_back([ + Point { + x: 13, + y: 14, + }, + Point { + x: 20, + y: 8, + } + ]); + slice = slice.push_back([ + Point { + x: 15, + y: 5, + }, + Point { + x: 12, + y: 13, + } + ]); + let brillig_sum = sum_slice(slice); + assert_eq(brillig_sum, 100); +} diff --git a/test_programs/execution_success/brillig_slices/src/main.nr b/test_programs/execution_success/brillig_slices/src/main.nr index bc31cdc8075..71cbed7a8da 100644 --- a/test_programs/execution_success/brillig_slices/src/main.nr +++ b/test_programs/execution_success/brillig_slices/src/main.nr @@ -1,6 +1,6 @@ use dep::std::slice; unconstrained fn main(x: field, y: field) { - let mut slice: [Field] = [y, x]; + let mut slice: [Field] = &[y, x]; assert(slice.len() == 2); slice = slice.push_back(7); diff --git a/test_programs/compile_success_empty/field_comparisons/Nargo.toml b/test_programs/execution_success/brillig_wrapping/Nargo.toml similarity index 66% rename from test_programs/compile_success_empty/field_comparisons/Nargo.toml rename to test_programs/execution_success/brillig_wrapping/Nargo.toml index e8b06655c58..a52246ba908 100644 --- a/test_programs/compile_success_empty/field_comparisons/Nargo.toml +++ b/test_programs/execution_success/brillig_wrapping/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "field_comparisons" +name = "brillig_wrapping" type = "bin" authors = [""] diff --git a/test_programs/execution_success/brillig_wrapping/Prover.toml b/test_programs/execution_success/brillig_wrapping/Prover.toml new file mode 100644 index 00000000000..346fd2764a7 --- /dev/null +++ b/test_programs/execution_success/brillig_wrapping/Prover.toml @@ -0,0 +1,2 @@ +x = 0 +y = 255 diff --git a/test_programs/execution_success/brillig_wrapping/src/main.nr b/test_programs/execution_success/brillig_wrapping/src/main.nr new file mode 100644 index 00000000000..4153a466057 --- /dev/null +++ b/test_programs/execution_success/brillig_wrapping/src/main.nr @@ -0,0 +1,8 @@ +use dep::std; + +unconstrained fn main(x: u8, y: u8) { + assert(std::wrapping_sub(x, 1) == y); + assert(std::wrapping_add(y, 1) == x); + assert(std::wrapping_mul(y, y) == 1); +} + diff --git a/test_programs/execution_success/double_verify_nested_proof/src/main.nr b/test_programs/execution_success/double_verify_nested_proof/src/main.nr index 1bd749bfc11..9baa29d3c90 100644 --- a/test_programs/execution_success/double_verify_nested_proof/src/main.nr +++ b/test_programs/execution_success/double_verify_nested_proof/src/main.nr @@ -1,10 +1,18 @@ use dep::std; +// This circuit aggregates two recursive proofs from `double_verify_proof_recursive`. +// Recursive aggregation is a backend-specific process and it is expected for backends +// to attach any extra data they may need (e.g. aggregation objects) to their proofs. +// Whether the proof we are verifying itself contains a recursive proof is expected to be +// a circuit constant by the barretenberg. Barretenberg hides this circuit constant in the +// proof serialization. Thus, we must have separate circuits for verifying a normal proof and a recursive proof +// with two different proof sizes. fn main( verification_key: [field; 114], - // This is the proof without public inputs attached. - // - // This means: the size of this does not change with the number of public inputs. + // This is the proof without user-specified public inputs attached. + // + // This means: the size of this does not change with the number of public inputs unless + // they have been attached by the backend. proof: [field; 109], public_inputs: pub [field; 1], // This is currently not public. It is fine given that the vk is a part of the circuit definition. diff --git a/test_programs/execution_success/double_verify_proof/Nargo.toml b/test_programs/execution_success/double_verify_proof/Nargo.toml index a4edd2e4288..c5954f54bdb 100644 --- a/test_programs/execution_success/double_verify_proof/Nargo.toml +++ b/test_programs/execution_success/double_verify_proof/Nargo.toml @@ -2,4 +2,6 @@ name = "double_verify_proof" type = "bin" authors = [""] -[dependencies] +compiler_version = ">=0.24.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/execution_success/double_verify_proof/src/main.nr b/test_programs/execution_success/double_verify_proof/src/main.nr index db088a766b9..011f32df9c8 100644 --- a/test_programs/execution_success/double_verify_proof/src/main.nr +++ b/test_programs/execution_success/double_verify_proof/src/main.nr @@ -1,6 +1,6 @@ use dep::std; -#[recursive] +// This circuit aggregates two proofs from `assert_statement_recursive`. fn main( verification_key: [field; 114], // This is the proof without public inputs attached. diff --git a/test_programs/execution_success/double_verify_proof_recursive/Nargo.toml b/test_programs/execution_success/double_verify_proof_recursive/Nargo.toml new file mode 100644 index 00000000000..b7688b33bfd --- /dev/null +++ b/test_programs/execution_success/double_verify_proof_recursive/Nargo.toml @@ -0,0 +1,5 @@ +[package] +name = "double_verify_proof_recursive" +type = "bin" +authors = [""] +[dependencies] diff --git a/test_programs/execution_success/double_verify_proof_recursive/Prover.toml b/test_programs/execution_success/double_verify_proof_recursive/Prover.toml new file mode 100644 index 00000000000..dff48212e50 --- /dev/null +++ b/test_programs/execution_success/double_verify_proof_recursive/Prover.toml @@ -0,0 +1,5 @@ +key_hash = "0x096129b1c6e108252fc5c829c4cc9b7e8f0d1fd9f29c2532b563d6396645e08f" +proof = ["0x000000000000000000000000000000d62b795bec274279129a71195796825fcc","0x00000000000000000000000000000000000793ab763140f20a68a6bd2721fd74","0x00000000000000000000000000000053141d06d3307b36153f321511199e579c","0x00000000000000000000000000000000000a4b55d6c21f98a9c434911dcb5c67","0x0000000000000000000000000000005f9d324c0abd22cec92d99dbec438e9491","0x0000000000000000000000000000000000240dfafe1b53dc27147cbab14ea893","0x000000000000000000000000000000044a61d3aac32c6931247cf334a19d9611","0x000000000000000000000000000000000003f0f8cf4207bfa85c23ec9f8d0c88","0x00000000000000000000000000000002168a470e39ba2ac266f6b474de12045f","0x000000000000000000000000000000000025791e7d3feab542345c00ec5a30df","0x000000000000000000000000000000dcafd76d4c3640969c80e017b951ef6397","0x00000000000000000000000000000000001d27f75a1256771e88e0c86fc42dbc","0x0000000000000000000000000000007347ae7d2d9d7fc2b8f0baa014ee1fed9f","0x000000000000000000000000000000000018bd927f42bf7caf9555f56f09000d","0x000000000000000000000000000000041f765f83cbe5904c8f453f70a4531d10","0x00000000000000000000000000000000001858aabeeb5331a221419f4fed1c19","0x000000000000000000000000000000d254a54caaedf8287b9af951b2f2611121","0x000000000000000000000000000000000005ab493623c9563cf2e55ba5f18200","0x00000000000000000000000000000014f24cddc1a02440dc63637df8032c8074","0x000000000000000000000000000000000011950c16cef98471b1d78b935195a4","0x000000000000000000000000000000b0340b459e6bd5cc8f031c8654a502897f","0x00000000000000000000000000000000000e1cf3968dac4545a76a2ae58e512c","0x0000000000000000000000000000002adf7218aa06ca0d2c2e600dcc39193a2d","0x00000000000000000000000000000000001302e7e4b0f14749bd885ca25588b6","0x00000000000000000000000000000092009ce4056e79ab815d8cdfd4491138ae","0x000000000000000000000000000000000018af11e853c6cf2f0f6274b0da8133","0x000000000000000000000000000000dd3dc6f49232141718527b3a0e4b26e21d","0x00000000000000000000000000000000001a877853348a8b695c4f9a9aa4ce68","0x000000000000000000000000000000aecfc56ba07155450b368140d6324023b5","0x000000000000000000000000000000000029c11052798c57ece614617d33fcc2","0x000000000000000000000000000000eb106ffc816d16fb84e84b0b61157b2603","0x000000000000000000000000000000000026c3cac16206899a21cb5126841446","0x000000000000000000000000000000a782ed54805fe845068b362b58e2fa34ec","0x00000000000000000000000000000000000cf046a1bfcc666b7f28b572676073","0x000000000000000000000000000000b931c8dda60bb4aca4cc817f5540f1209f","0x000000000000000000000000000000000024ad50c3936fafc3d190e6a4874223","0x000000000000000000000000000000cce90cfbaf5671c8c8652db28a3a9566f7","0x000000000000000000000000000000000003574db9d0f84380c9635660f86354","0x0000000000000000000000000000003eb3e1dc31846a90f721e7a08c6d6dc4f7","0x000000000000000000000000000000000028999a700cd1abae1a288eebb9a91c","0x000000000000000000000000000000c1be4d385b11387e14eb9817050d772f78","0x000000000000000000000000000000000003c56b5bad8b4484c66ac921f1f102","0x000000000000000000000000000000ace245cabf0f00dc7fd253dd8af0377a14","0x0000000000000000000000000000000000107f1731fcf34b364c813599fa1df7","0x035b937d404932b542b706eb810ef4a7dca4566d4dde1ad6a8717f46167ead7e","0x17608cef3dc7960f41cb1295706df663727d45ee598a61e05e989d111449fb65","0x054712a950ad67da3aa860e49e6891f99b586b7f37caff94eb013fdb374b61ee","0x04b755083086c769b7f593e0e48d68dc54be808203351380ca5566a48149d8bb","0x17d7670b0915235f626fdc1d7e1134d2be906ef138d7843384b3ebc23b1d630f","0x064cf544ab5f4e3dab47960502cccc83321fb275068dfbdd3a2fcbc6dddcaa65","0x083338262712e2b66769ea40d9f412b18caa1bc81a51ff5a50b6c41f8c4b3d23","0x0cdd38958cab97defde00f4a5961b6fd676e29d9f2c352f6bb2c68b91f83f8af","0x02c8bdd005c2f43a0a8cbb2744916ce5c322dfa5b23367a829c12699f4036d32","0x25bac73c7e7b659fbea3135b7a0decf9db8dc3045bd2837dae337c64cc722546","0x19eb361aa419d37bce3d2e8b2b7692a02a9559e83d7f3d8fe9169970fbbc2cba","0x2494bd5106d00e05c7ea60e632e9fe03773b7f2c5b662aa37ec512a01f4a0775","0x18c52c2f2c6e7be1d7847c15e452a3a9c64316103d12e4b5b9a82fac4e940ee9","0x0e0342810456ef78f498c1bfa085a5f3cbc06db1f32fabd0ea9ad27dccac1680","0x024c13d6ef56af33ed7164ea8e47ddecc8a487b000d8b1b45edcd3895a503ba2","0x26e0d127f626bd39b55bc5d0c131dbf03fe006dc5c3edc57dda1e629799a4317","0x1b1140061bc52b15c4f5e100729a81968ee79dc03deb966a18850335a8e44a8b","0x1bb76f945199e71d531a89288912087a02dd0e83020e65d671485bf2e5e86e1a","0x29269900859c6d86e404185b415bf3b279cd100f38cfdb0077e8d6a299c4fd35","0x22b5e94bae2f6f0cdb424a3b12c4bf82cec3fb228e012c1974ed457827bbe012","0x18d3543a93249778e7a57936170dae85ffc47c2567f2d0076a32c0bb86fcf10a","0x03721dc2670206cde42a175fd56bcce32cf6cb8801450a8e8e4b3d4e07785973","0x2806db136dd214d3ac1478460855cae6a4324ab45cab35320d104fee26c260e8","0x1c3749f1937082afbbae9375b9be708cf339e1983e57ef4447f36cfa560c685c","0x1067b8cfb90ef08bcb48aea56b2716334241787c2004a95682d68a0685566fd0","0x0f41aee4416398f1d48ffc302403273cddef34a41f98507c53682041d82e51ff","0x10d854c9f0bfbdff7ca91a68f4978e9a79e7b14243d92f465f17bdf88d9f64f8","0x00000000000000000000000000000000018938b11099e0cdc05ddab84a153a97","0x0000000000000000000000000000000001d7dda1471f0dc3b3a3d3438c197982","0x00000000000000000000000000000000022682917da43ab9a6e9cbcece1db86d","0x2453913e6b0f36eab883ac4b0e0604d56aaeb9c55e641135173e63c342f1a660","0x05216c1b58dc43a49d01aaba3113b0e86be450fc17d28016e648e7162a1b67fb","0x152b34845a0222a2b41354c0d395a250d8363dc18748647d85acd89d6934ec56","0x1dfc6e971ce82b7dcda1f7f282713c6e22a8c79258a61209bda69719806da544","0x2968dd8b3af8e3953f1fbbd72f4c49b8270597bb27d4037adc157ac6083bee60","0x1b9425b88a4c7d39b3d75afe66917a9aa1d2055724392bc01fb918d84ff1410e","0x04ab571f236d8e750904dc307dd274003d9130f1a7110e4c1521cfb408877c73","0x2ad84f26fdc5831545272d02b806bb0e6dae44e71f73552c4eb9ff06030748c7","0x020e632b99d325db774b8630fb50b9a4e74d35b7f27d9fc02c65087ee747e42c","0x09a8c5a3171268cb61c02515c01c109889200ed13f415ae54df2078bbb887f92","0x1143281a9451abbb4c34c3fa84e7678c2af2e7ea8c05160a6f7f06988fc91af8","0x000000000000000000000000000000cbda736ca5cf6bc75413c2cc9e28ab0a68","0x00000000000000000000000000000000001ee78c9cc56aa5991062ae2e338587","0x000000000000000000000000000000bc9bfcdebb486f4cb314e681d2cc5f8df6","0x00000000000000000000000000000000000ad538431d04771bca7f633cb659ff","0x000000000000000000000000000000d45b317afcefa466a59bba9e171f1af70c","0x0000000000000000000000000000000000133c50180ea17932e4881124e7a7c6","0x000000000000000000000000000000fc9ed37f543775849f3e84eaa06f77f992","0x00000000000000000000000000000000001372873c9c051d1baff99248b8f70e"] +public_inputs = ["0x0000000000000000000000000000000000000000000000000000000000000003"] +verification_key = ["0x2b337de1c8c14f22ec9b9e2f96afef3652627366f8170a0a948dad4ac1bd5e80","0x0000000000000000000000000000000000000000000000000000000000000008","0x0000000000000000000000000000000000000000000000000000000000000005","0x0000000000000000000000000000000000000000000000000000000000000008","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x00000000000000000000000000000092139c61bae1a44f0fc7689507414be688","0x00000000000000000000000000000000000160ce4e279582f91bde4f03f5e9a2","0x0000000000000000000000000000005dc2d37f658c3b2d60f24740eb13b65d79","0x000000000000000000000000000000000007e3e8a5d98a1177ec85bf88f163a5","0x000000000000000000000000000000dc3035fbd7ff16412a8fd7da587a935298","0x000000000000000000000000000000000023d08e2817ac16990004ed11d8fc66","0x000000000000000000000000000000356a5ad59c646c746a8d09f5d154e47c4f","0x00000000000000000000000000000000000708529196af3c8e16ffa580c26182","0x0000000000000000000000000000002ddfe70eb7a1280596e8e4a804f118a6dd","0x000000000000000000000000000000000013757e15a0905f298303784a161b21","0x000000000000000000000000000000a23a729df796935c7824e3a26be794829b","0x000000000000000000000000000000000005775b6c146c4a59856e869fe5a70e","0x000000000000000000000000000000eef0c9e088fd2d45aa40311082d1f2809b","0x00000000000000000000000000000000001d539ccbfc556d0ad59307a218de65","0x000000000000000000000000000000a2c848beceb6ab7806fd3b88037b8410fc","0x0000000000000000000000000000000000177004deeb1f9d401fd7b1af1a5ac8","0x0000000000000000000000000000002508eb63672a733f20de1a97644be4f540","0x00000000000000000000000000000000000d82d51f2f75d806285fd248c819b8","0x000000000000000000000000000000d002f9100cbba8a29f13b11513c53c59d0","0x000000000000000000000000000000000006cd3b0e3460533b9e5ea2cdc0fcbb","0x000000000000000000000000000000f45ea38a93b2f810c5633ddb54927c1c96","0x000000000000000000000000000000000021791de65f9a28ec7024b1a87ab4f3","0x000000000000000000000000000000926511a0439502c86885a8c6f0327aa7ad","0x000000000000000000000000000000000029fa14a969c5d81ed3abbbfb11220a","0x000000000000000000000000000000b84c3258e8206f560e5b5b18cbeafef87e","0x00000000000000000000000000000000002a910445cd8fc895e5d235cd8ea185","0x000000000000000000000000000000887e67f15e84bcb8507a5064a363f6043b","0x000000000000000000000000000000000014dc6643d801c3ef27c2066b6e2bb4","0x000000000000000000000000000000e38e900b42c314ba803088e8fbf125203f","0x000000000000000000000000000000000020690fd4869db418306046b38161dc","0x0000000000000000000000000000001e2fa856bf7951b8292b1e88185993629c","0x0000000000000000000000000000000000048a85e0bbac7c60ad3d78f601f63c","0x0000000000000000000000000000006f457719495073d3666d77a625aeab0c51","0x00000000000000000000000000000000002623ad892dc62b1fa7d0a650f0d470","0x000000000000000000000000000000dbfcc8a467e021c03b13f74a9f79c3a10c","0x0000000000000000000000000000000000295f6f10976c37bd9c6f96bb7187d5","0x000000000000000000000000000000c13ef9a937cc12420fb38d9ab8e848e85e","0x000000000000000000000000000000000003560a3b334e887532f605c9cb7628","0x0000000000000000000000000000009bcebf08a4599cdda0fb96312d4dc0c7a9","0x000000000000000000000000000000000015adc8bb1e01c835f48959d1237bd6","0x00000000000000000000000000000047762ab839e4ff63c77605a9f383da37c2","0x000000000000000000000000000000000016a8c3c53d89660cf271522cd301fb","0x000000000000000000000000000000f0c8539a0b5f94420a513f9c305b932bfe","0x00000000000000000000000000000000002957ba01d9de5638f808f88a692533","0x000000000000000000000000000000ab17c6189d67d3bf5dd2f3885de0151b6f","0x0000000000000000000000000000000000060d8aa43fdc434d1942263f364d95","0x0000000000000000000000000000005d292333b3adb497f00b4bc32d45229060","0x00000000000000000000000000000000001a1018a66221883639f2898a66f345","0x00000000000000000000000000000006555a806b1993291deba0dc44e2abf431","0x00000000000000000000000000000000000cacff7099a9d5e35a21f4a00b2dc3","0x000000000000000000000000000000f50c11ba95d349c36d143eefd12e494950","0x00000000000000000000000000000000001022e8c5f02d639bc9dd8bc4407f99","0x000000000000000000000000000000c76828795098eda73d50b4b585c60afc60","0x00000000000000000000000000000000002bf09c0ec7011e93888962f2406630","0x00000000000000000000000000000049e5c83a8978d832fb8e144548e3ca1adb","0x00000000000000000000000000000000000e0ec242c2e160a984f61ca5adf5f5","0x0000000000000000000000000000009c5d6e08a6605ab4513748ac0fa017dd1c","0x00000000000000000000000000000000001f54baa07558e5fb055bd9ba49c067","0x0000000000000000000000000000001e1ee7ee29bbb5e4b080c6091c1433ce62","0x000000000000000000000000000000000024aec62a9d9763499267dc98c33428","0x0000000000000000000000000000001a96755946ff16f0d6632365f0eb0ab4d4","0x000000000000000000000000000000000028cf3e22bcd53782ebc3e0490e27e5","0x00000000000000000000000000000043148d7d8c9ba43f2133fab4201435a364","0x0000000000000000000000000000000000234ce541f1f5117dd404cfaf01a229","0x000000000000000000000000000000a7fb95ffb461d9514a1070e2d2403982ef","0x00000000000000000000000000000000003016955028b6390f446c3fd0c5b424","0x00000000000000000000000000000008863c3b7cd7cddc20ba79ce915051c56e","0x000000000000000000000000000000000013ef666111b0be56a235983d397d2a","0x000000000000000000000000000000e3993f465fc9f56e93ac769e597b752c1c","0x0000000000000000000000000000000000217f7c4235161e9a3c16c45b6ca499","0x0000000000000000000000000000008ffa4cd96bc67b0b7df5678271e1114075","0x0000000000000000000000000000000000256467bfcb63d9fdcb5dde397757ad","0x00000000000000000000000000000054e5eb270bb64bde6e6ececadfd8c3236c","0x00000000000000000000000000000000000e52d1bd75812c33c6f3d79ee4b94c","0x000000000000000000000000000000484a2c641dce55bc2dd64ef0cd790a7fea","0x00000000000000000000000000000000000ff417d256be43e73c8b1aa85bdda3","0x0000000000000000000000000000000b72e7b7713ab5da44e0f864182e748a23","0x00000000000000000000000000000000001a221055f1625ad833a44705f5f74e","0x00000000000000000000000000000067a99a34e9b81a17ad001db02e29bcb82a","0x000000000000000000000000000000000018a6c02e398389827568fa960e86e2","0x000000000000000000000000000000bb29f26f9890d6cc6401f4921d5884edca","0x00000000000000000000000000000000000868357b28039385c5a5058b6d358e","0x00000000000000000000000000000036fb6e229dde8edf7ec858b12d7e8be485","0x00000000000000000000000000000000001060afe929554ca473103f5e68193c","0x00000000000000000000000000000015226e07e207744c0857074dcab883af4a","0x00000000000000000000000000000000000b1c02619282755533457230b19b4a","0x0000000000000000000000000000001f2a0277e4807e6e1cbabca21dde5eb5e1","0x00000000000000000000000000000000000d928deafed363659688ed4ccdef52","0x000000000000000000000000000000363f0c994e91cecad25835338edee2294f","0x00000000000000000000000000000000002eea648c8732596b1314fe2a4d2f05","0x000000000000000000000000000000b2671d2ae51d31c1210433c3972bb64578","0x00000000000000000000000000000000000ab49886c2b94bd0bd3f6ed1dbbe2c"] +proof_b = ["0x000000000000000000000000000000f05c69448ca29bdf52076f9b073bb30fed","0x000000000000000000000000000000000028c86bb3e27b4aaaaef126f7df5349","0x00000000000000000000000000000026ae031fc93594375dfc7f3bbe027f97d5","0x000000000000000000000000000000000000dd12c7290fe7f775796a233b8590","0x000000000000000000000000000000c1ee6631704de424d010c5c4ac8293ac49","0x00000000000000000000000000000000002f41818c9aa83f5c8d9bdd128015b9","0x000000000000000000000000000000b50a5801482f7e3a5de8ab3cce0f10b0d3","0x000000000000000000000000000000000022a0bc69c293dbf293b25bc9eef7f8","0x0000000000000000000000000000003b02abf1967ef394154dc15d763135e903","0x00000000000000000000000000000000000d8a2ee46acc6d1ed8d517b56d47c8","0x00000000000000000000000000000039bf0d1b3d8cf9de898f101c626e978d78","0x0000000000000000000000000000000000008faa7df2451a24d291a9b584f1a5","0x000000000000000000000000000000c1dae329ed7adf63a2d89a5f16fb98b6d8","0x00000000000000000000000000000000001ff0bc16fc0bd4aa2d6255690453c2","0x000000000000000000000000000000d12d7589f853a9b472613efa56689beaf1","0x00000000000000000000000000000000002d6fbc798f4403751df6aeee8bedd3","0x0000000000000000000000000000007c1fa069cb17194fecf88db9dd54a4ee36","0x0000000000000000000000000000000000268e026f9814822a42b2d59eec5d24","0x000000000000000000000000000000c3fb56beab774218cd63498fc050a5fd9b","0x00000000000000000000000000000000000071c014d7b5063f005a0bc2ee1af4","0x000000000000000000000000000000ae12b25371c6af42bbe0a85cddd2eaebc7","0x000000000000000000000000000000000026d270e1ffc9c7c344c694dfadda83","0x00000000000000000000000000000080280858c6be461716921caa3c26f3f6f3","0x000000000000000000000000000000000001dcdd3f39e27d0ce6aa5d14dff4c1","0x000000000000000000000000000000080e1d2c913c834ebcf7e0600c076c08fd","0x00000000000000000000000000000000002df3d142217694e65fb7c355d62764","0x000000000000000000000000000000e5e336f3f59d77e500f49771bfbeb12e83","0x000000000000000000000000000000000028fffe08bdc4c0690643d2e1a1275f","0x000000000000000000000000000000db5618b32afc13e18f21b39f3fbede9d11","0x00000000000000000000000000000000001d244818370d43fb7e8bc67e03787b","0x0000000000000000000000000000006bcc1fd3f9f78449ad1df1bc11bc379edd","0x000000000000000000000000000000000009ac9cbb285edbf5b3a973f3f5f1cb","0x000000000000000000000000000000fd885905b6c0fc95bb4dd0b11f6797d4b3","0x000000000000000000000000000000000021f07995cdd835145e19c38127c562","0x000000000000000000000000000000bbbf2b975c2c97ae4b45c4a52059e53ee3","0x000000000000000000000000000000000024158163788841cf4590bbc1e89a90","0x0000000000000000000000000000009aca93d2b1386ea412d4b36ea5bb9894a8","0x00000000000000000000000000000000002532d1d210e8ed4c2f5c00cbaaa475","0x000000000000000000000000000000634a88caa1d77cb6b5fe77cac31458fc31","0x00000000000000000000000000000000000bdf18bae92fce7cfddab5520cac6e","0x000000000000000000000000000000622e9626255170ccec77602c755aa193e1","0x000000000000000000000000000000000001d4edba370e04436a988bad05dada","0x000000000000000000000000000000b52934323a0aec8f803cdaafee2ab7bfb2","0x0000000000000000000000000000000000155312af5e0e25ca9fd61aef9e58ed","0x06270b517855f6f6a608e432883d1d1030a12a1e33022dc142b7728691421da2","0x2af7c794d7b720b25eb1df0afd8c8e3c15b6e518194c3caea7966a5f8210ff04","0x073fe573aeb27d81a5713be93e1365390dcbc3c8e7439ff1d36a84cc014f5642","0x11351b961147431e54535248b58b35cf5cddb9b13827899167617d7a96794d64","0x297c9421c9c3db286770787c35b86bc41583386491b4ae55e5fa81aefa21efc4","0x0f4eeca3ff4a3495f859898937688652d33f9b4dd3e003e12adf15278e0997c3","0x133e3d8b82721d40d919f2326810ba6f07eff3f7d20d86b2bde692a811522019","0x2c502f53c9698b73bb8c8f9b9cf2d705d16a64a7040348b4b39c637a2064316c","0x0cbc1971e1c566cde9d9125c91cdc88e817db182692f836c1a5170a6246eaf73","0x12c47793e7db706c637cd4b4d96d227f569850176b852b1fe8ad522ddb38ef0e","0x0cd7b300e9309a135285be1aeb02b152f97931a7357ab6d609a2cb1970aab877","0x2a7789dfe286c9d0a7592f1c9316e730cb14c9d843aefc4764d76e7f8571c96a","0x248ac54ce3dbf37796621882a4ac76046df5ab680da487fd85cce76b1ae392d3","0x149d1d07cebe320f77b03533e34912545cedeae62bd9778d37724728762b5710","0x00fe29daebdaed61309790e70e2dcefa3f3af4c6c965ce424b8dbcf09b8e4b49","0x2b75b3bace61b731d7f0c003a144b62b0a4fbe9f0d14ca89b0652b70210014b3","0x2588ef27cfb6e0d8c6f9a969b2da44fead30a02ed70a563fd15aa45bb671de1c","0x2b74d7674b55642697b4a1e226eddb0e4918b2d57aa5b99093dc46cadcdea000","0x244c626845d3a5040f08f01e9611f968ad675ca857789149b13a0cfa83a2e064","0x2cb8d02f90cae33fd7bcfb80af4aff067c4f5fc4b3f9228d5b8f768bc8f6c971","0x1372f3d1f04e0c39a50e823d5da03d70bebe19a1b8e28f8c2ff601cc0bfc0095","0x19af6601d2613426a50b7c35d60562a5f2f2634e6af56dac13459632e15570ee","0x13c2a16ed3b65dcd9414659be79af17995d344de34eaf962343b0f1e76c73a57","0x0dd5dcdbd50b8774831d4f01f930804d38b4266dfee085185530880a0c3903c0","0x07e91848d660b11b722638680ac60f20db9507fdc8d610ce762600f5a1aacd29","0x1f9c2a94d10c0a7fb60292cfc46fd3d2501181bea0ffe1f5f2501d474be3a785","0x14edb9c5bd389eae08a5ea2a7a1662894e1e878c142084d966a625bef68cf7c3","0x00000000000000000000000000000000cecd01810814d175f0a533f0067618c4","0x00000000000000000000000000000000f82935013ce5c82720c63e533af41db8","0x000000000000000000000000000000012185688171b6bed850e748b66f7222ac","0x2dd7f5ff2150155c2ac86ebe28d9ecbca2eea812b0021ab2bceae111cfea8325","0x04ea6c2daf2b9e827d2213c3d03953410dcf1ed67ba34a3c00e772be92606a8b","0x163f2bd18dcde52f99b9867c944780fd718d1612927053b139b280fc55013d1b","0x05e388fd160ccac30a8f7b18a4bd042f705e92b5937e8c0e9478e2ff623907c6","0x00ba3f6f527d6ed3ff17a63b1d5be3c42bdfae88fdf63311fc7b871157939309","0x16187d9daa8c2e5a1a9ab15be7ca6a8feebfb31bea76f9a3ca69381881c70561","0x0f64522e4904edb7377b14a7b9dad848829167324ef5c016346b3ad8251191ee","0x273bbe6000a4001dce369e5a36cc0b0ca3fd351665b688238aa8c556a6ca6b8e","0x022d2232efb2faa8307846c9a4c697aabad1b7f1336b35ad72fa8922975b49d9","0x0d82d478bff3955c4b0a34ef94427ca5f9da23147ad953c89f2e428277ec2825","0x18d886be90343010659c231583be61a138e28e37c24771e3cb61fbe2587d0671","0x000000000000000000000000000000196ba6a58dbeb7c34cb1d6287e23d434de","0x00000000000000000000000000000000001df8ae8a1589590f8863c1fefd8dfd","0x000000000000000000000000000000f30e11b2c5fbefa166cbb9f58c5f8e1a4c","0x000000000000000000000000000000000026420ade7666bc0ab1cf1fd9d0c534","0x0000000000000000000000000000000feb5b7d8260d25a1ee1ce76ff461673fc","0x00000000000000000000000000000000002bd2ac6223a80671b777bf5dca70a4","0x000000000000000000000000000000690f757006d2fa1ddb0114c9f268783537","0x000000000000000000000000000000000023ad36feadd91e50118f32e97a0204"] \ No newline at end of file diff --git a/test_programs/execution_success/double_verify_proof_recursive/src/main.nr b/test_programs/execution_success/double_verify_proof_recursive/src/main.nr new file mode 100644 index 00000000000..86b4971c3a6 --- /dev/null +++ b/test_programs/execution_success/double_verify_proof_recursive/src/main.nr @@ -0,0 +1,30 @@ +use dep::std; + +// This circuit aggregates two proofs from `assert_statement_recursive`. +#[recursive] +fn main( + verification_key: [Field; 114], + // This is the proof without public inputs attached. + // + // This means: the size of this does not change with the number of public inputs. + proof: [Field; 93], + public_inputs: pub [Field; 1], + // This is currently not public. It is fine given that the vk is a part of the circuit definition. + // I believe we want to eventually make it public too though. + key_hash: Field, + proof_b: [Field; 93] +) { + std::verify_proof( + verification_key.as_slice(), + proof.as_slice(), + public_inputs.as_slice(), + key_hash + ); + + std::verify_proof( + verification_key.as_slice(), + proof_b.as_slice(), + public_inputs.as_slice(), + key_hash + ); +} diff --git a/test_programs/execution_success/eddsa/src/main.nr b/test_programs/execution_success/eddsa/src/main.nr index 589c75a02de..cdf57d25c9a 100644 --- a/test_programs/execution_success/eddsa/src/main.nr +++ b/test_programs/execution_success/eddsa/src/main.nr @@ -1,14 +1,22 @@ use dep::std::compat; use dep::std::ec::consts::te::baby_jubjub; +use dep::std::ec::tecurve::affine::Point as TEPoint; use dep::std::hash; -use dep::std::eddsa::eddsa_poseidon_verify; +use dep::std::eddsa::{eddsa_to_pub, eddsa_poseidon_verify, eddsa_verify_with_hasher}; +use dep::std::hash::poseidon2::Poseidon2Hasher; +use dep::std::hash::pedersen::PedersenHasher; + fn main(msg: pub field, _priv_key_a: field, _priv_key_b: field) { // Skip this test for non-bn254 backends if compat::is_bn254() { let bjj = baby_jubjub(); let pub_key_a = bjj.curve.mul(_priv_key_a, bjj.curve.gen); - // let pub_key_b = bjj.curve.mul(_priv_key_b, bjj.curve.gen); + let pub_key_b = bjj.curve.mul(_priv_key_b, bjj.curve.gen); + let (pub_key_a_x, pub_key_a_y) = eddsa_to_pub(_priv_key_a); + let (pub_key_b_x, pub_key_b_y) = eddsa_to_pub(_priv_key_b); + assert(TEPoint::new(pub_key_a_x, pub_key_a_y) == pub_key_a); + assert(TEPoint::new(pub_key_b_x, pub_key_b_y) == pub_key_b); // Manually computed as fields can't use modulo. Importantantly the commitment is within // the subgroup order. Note that choice of hash is flexible for this step. // let r_a = hash::pedersen_commitment([_priv_key_a, msg])[0] % bjj.suborder; // modulus computed manually @@ -42,5 +50,11 @@ fn main(msg: pub field, _priv_key_a: field, _priv_key_b: field) { assert(!eddsa_poseidon_verify(pub_key_a.x, pub_key_a.y, s_b, r8_b.x, r8_b.y, msg)); // User A's signature over the message can't be used with another message assert(!eddsa_poseidon_verify(pub_key_a.x, pub_key_a.y, s_a, r8_a.x, r8_a.y, msg + 1)); + // Using a different hash should fail + let mut hasher = Poseidon2Hasher::default(); + assert(!eddsa_verify_with_hasher(pub_key_a.x, pub_key_a.y, s_a, r8_a.x, r8_a.y, msg, &mut hasher)); + // Using a different hash should fail + let mut hasher = PedersenHasher::default(); + assert(!eddsa_verify_with_hasher(pub_key_a.x, pub_key_a.y, s_a, r8_a.x, r8_a.y, msg, &mut hasher)); } } diff --git a/test_programs/execution_success/fold_basic/Nargo.toml b/test_programs/execution_success/fold_basic/Nargo.toml new file mode 100644 index 00000000000..575ba1f3ad1 --- /dev/null +++ b/test_programs/execution_success/fold_basic/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "fold_basic" +type = "bin" +authors = [""] +compiler_version = ">=0.25.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_failure/slice_remove_failure/Prover.toml b/test_programs/execution_success/fold_basic/Prover.toml similarity index 100% rename from test_programs/compile_failure/slice_remove_failure/Prover.toml rename to test_programs/execution_success/fold_basic/Prover.toml diff --git a/test_programs/execution_success/fold_basic/src/main.nr b/test_programs/execution_success/fold_basic/src/main.nr new file mode 100644 index 00000000000..6c17120660b --- /dev/null +++ b/test_programs/execution_success/fold_basic/src/main.nr @@ -0,0 +1,11 @@ +fn main(x: Field, y: pub Field) { + let z = foo(x, y); + let z2 = foo(x, y); + assert(z == z2); +} + +#[fold] +fn foo(x: Field, y: Field) -> Field { + assert(x != y); + x +} diff --git a/test_programs/execution_success/fold_basic_nested_call/Nargo.toml b/test_programs/execution_success/fold_basic_nested_call/Nargo.toml new file mode 100644 index 00000000000..1b3c32999ae --- /dev/null +++ b/test_programs/execution_success/fold_basic_nested_call/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "fold_basic_nested_call" +type = "bin" +authors = [""] +compiler_version = ">=0.25.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/execution_success/fold_basic_nested_call/Prover.toml b/test_programs/execution_success/fold_basic_nested_call/Prover.toml new file mode 100644 index 00000000000..f28f2f8cc48 --- /dev/null +++ b/test_programs/execution_success/fold_basic_nested_call/Prover.toml @@ -0,0 +1,2 @@ +x = "5" +y = "10" diff --git a/test_programs/execution_success/fold_basic_nested_call/src/main.nr b/test_programs/execution_success/fold_basic_nested_call/src/main.nr new file mode 100644 index 00000000000..6d02b734727 --- /dev/null +++ b/test_programs/execution_success/fold_basic_nested_call/src/main.nr @@ -0,0 +1,16 @@ +fn main(x: Field, y: pub Field) { + let z = func_with_nested_foo_call(x, y); + let z2 = func_with_nested_foo_call(x, y); + assert(z == z2); +} + +#[fold] +fn func_with_nested_foo_call(x: Field, y: Field) -> Field { + foo(x + 2, y) +} + +#[fold] +fn foo(x: Field, y: Field) -> Field { + assert(x != y); + x +} diff --git a/test_programs/execution_success/fold_call_witness_condition/Nargo.toml b/test_programs/execution_success/fold_call_witness_condition/Nargo.toml new file mode 100644 index 00000000000..cedaea348c5 --- /dev/null +++ b/test_programs/execution_success/fold_call_witness_condition/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "fold_call_witness_condition" +type = "bin" +authors = [""] +compiler_version = ">=0.26.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/execution_success/fold_call_witness_condition/Prover.toml b/test_programs/execution_success/fold_call_witness_condition/Prover.toml new file mode 100644 index 00000000000..8481ce25648 --- /dev/null +++ b/test_programs/execution_success/fold_call_witness_condition/Prover.toml @@ -0,0 +1,5 @@ +# TODO(https://github.com/noir-lang/noir/issues/4707): Change these inputs to fail the assertion in `fn return_value` +# and change `enable` to false. For now we need the inputs to pass as we do not handle predicates with ACIR calls +x = "5" +y = "10" +enable = true \ No newline at end of file diff --git a/test_programs/execution_success/fold_call_witness_condition/src/main.nr b/test_programs/execution_success/fold_call_witness_condition/src/main.nr new file mode 100644 index 00000000000..5dc75e4a99f --- /dev/null +++ b/test_programs/execution_success/fold_call_witness_condition/src/main.nr @@ -0,0 +1,16 @@ +global NUM_RESULTS = 2; +fn main(x: Field, y: pub Field, enable: bool) -> pub [Field; NUM_RESULTS] { + let mut result = [0; NUM_RESULTS]; + for i in 0..NUM_RESULTS { + if enable { + result[i] = return_value(x, y); + } + } + result +} + +#[fold] +fn return_value(x: Field, y: Field) -> Field { + assert(x != y); + x +} diff --git a/test_programs/execution_success/global_consts/src/main.nr b/test_programs/execution_success/global_consts/src/main.nr index 6259927b6f9..b3770a55b04 100644 --- a/test_programs/execution_success/global_consts/src/main.nr +++ b/test_programs/execution_success/global_consts/src/main.nr @@ -107,3 +107,20 @@ mod my_submodule { x } } + +struct Foo { + a: Field, +} + +struct Bar {} + +impl Bar { + fn get_a() -> Field { + 1 + } +} + +// Regression for #1440 +global foo = Foo { + a: Bar::get_a(), +}; diff --git a/test_programs/execution_success/hash_to_field/src/main.nr b/test_programs/execution_success/hash_to_field/src/main.nr index 7744e8c78f0..4710d39ca83 100644 --- a/test_programs/execution_success/hash_to_field/src/main.nr +++ b/test_programs/execution_success/hash_to_field/src/main.nr @@ -1,5 +1,5 @@ use dep::std; fn main(input: field) -> pub field { - std::hash::hash_to_field([input]) + std::hash::hash_to_field(&[input]) } diff --git a/test_programs/execution_success/hashmap/src/main.nr b/test_programs/execution_success/hashmap/src/main.nr index 597a5c0b7de..4d2cbd45993 100644 --- a/test_programs/execution_success/hashmap/src/main.nr +++ b/test_programs/execution_success/hashmap/src/main.nr @@ -37,6 +37,8 @@ fn main(input: [Entry; HASHMAP_LEN]) { test_retain(); test_iterators(); test_mut_iterators(); + + doc_tests(); } // Insert, get, remove. @@ -154,9 +156,9 @@ fn test_iterators() { hashmap.insert(5, 7); hashmap.insert(11, 13); - let keys: [K; 3] = cut(hashmap.keys()).map(|k: Option| k.unwrap_unchecked()).sort_via(K_CMP); - let values: [V; 3] = cut(hashmap.values()).map(|v: Option| v.unwrap_unchecked()).sort_via(V_CMP); - let entries: [(K, V); 3] = cut(hashmap.entries()).map(|e: Option<(K, V)>| e.unwrap_unchecked()).sort_via(KV_CMP); + let keys: [K; 3] = cut(hashmap.keys()).sort_via(K_CMP); + let values: [V; 3] = cut(hashmap.values()).sort_via(V_CMP); + let entries: [(K, V); 3] = cut(hashmap.entries()).sort_via(KV_CMP); assert(keys == [2, 5, 11], "Got incorrect iteration of keys."); assert(values == [3, 7, 13], "Got incorrect iteration of values."); @@ -177,8 +179,8 @@ fn test_mut_iterators() { let f = |v: V| -> V{ v * 5}; hashmap.iter_values_mut(f); - let keys: [K; 3] = cut(hashmap.keys()).map(|k: Option| k.unwrap_unchecked()).sort_via(K_CMP); - let values: [V; 3] = cut(hashmap.values()).map(|v: Option| v.unwrap_unchecked()).sort_via(V_CMP); + let keys: [K; 3] = cut(hashmap.keys()).sort_via(K_CMP); + let values: [V; 3] = cut(hashmap.values()).sort_via(V_CMP); assert(keys == [6, 15, 33], f"Got incorrect iteration of keys: {keys}"); assert(values == [15, 35, 65], "Got incorrect iteration of values."); @@ -186,7 +188,175 @@ fn test_mut_iterators() { let f = |k: K, v: V| -> (K, V){(k * 2, v * 2)}; hashmap.iter_mut(f); - let entries: [(K, V); 3] = cut(hashmap.entries()).map(|e: Option<(K, V)>| e.unwrap_unchecked()).sort_via(KV_CMP); + let entries: [(K, V); 3] = cut(hashmap.entries()).sort_via(KV_CMP); assert(entries == [(12, 30), (30, 70), (66, 130)], "Got incorrect iteration of entries."); } + +// docs:start:type_alias +type MyMap = HashMap>; +// docs:end:type_alias + +/// Tests examples from the stdlib hashmap documentation +fn doc_tests() { + // docs:start:default_example + let hashmap: HashMap> = HashMap::default(); + assert(hashmap.is_empty()); + // docs:end:default_example + + // docs:start:with_hasher_example + let my_hasher: BuildHasherDefault = Default::default(); + let hashmap: HashMap> = HashMap::with_hasher(my_hasher); + assert(hashmap.is_empty()); + // docs:end:with_hasher_example + + // docs:start:insert_example + let mut map: HashMap> = HashMap::default(); + map.insert(12, 42); + assert(map.len() == 1); + // docs:end:insert_example + + get_example(map); + + // docs:start:remove_example + map.remove(12); + assert(map.is_empty()); + + // If a key was not present in the map, remove does nothing + map.remove(12); + assert(map.is_empty()); + // docs:end:remove_example + + // docs:start:is_empty_example + assert(map.is_empty()); + + map.insert(1, 2); + assert(!map.is_empty()); + + map.remove(1); + assert(map.is_empty()); + // docs:end:is_empty_example + + // docs:start:len_example + // This is equivalent to checking map.is_empty() + assert(map.len() == 0); + + map.insert(1, 2); + map.insert(3, 4); + map.insert(5, 6); + assert(map.len() == 3); + + // 3 was already present as a key in the hash map, so the length is unchanged + map.insert(3, 7); + assert(map.len() == 3); + + map.remove(1); + assert(map.len() == 2); + // docs:end:len_example + + // docs:start:capacity_example + let empty_map: HashMap> = HashMap::default(); + assert(empty_map.len() == 0); + assert(empty_map.capacity() == 42); + // docs:end:capacity_example + + // docs:start:clear_example + assert(!map.is_empty()); + map.clear(); + assert(map.is_empty()); + // docs:end:clear_example + + // docs:start:contains_key_example + if map.contains_key(7) { + let value = map.get(7); + assert(value.is_some()); + } else { + println("No value for key 7!"); + } + // docs:end:contains_key_example + + entries_examples(map); + iter_examples(map); + + // docs:start:retain_example + map.retain(|k, v| (k != 0) & (v != 0)); + // docs:end:retain_example + + // docs:start:eq_example + let mut map1: HashMap> = HashMap::default(); + let mut map2: HashMap> = HashMap::default(); + + map1.insert(1, 2); + map1.insert(3, 4); + + map2.insert(3, 4); + map2.insert(1, 2); + + assert(map1 == map2); + // docs:end:eq_example +} + +// docs:start:get_example +fn get_example(map: HashMap>) { + let x = map.get(12); + + if x.is_some() { + assert(x.unwrap() == 42); + } +} +// docs:end:get_example + +fn entries_examples(map: HashMap>) { + // docs:start:entries_example + let entries = map.entries(); + + // The length of a hashmap may not be compile-time known, so we + // need to loop over its capacity instead + for i in 0..map.capacity() { + if i < entries.len() { + let (key, value) = entries.get(i); + println(f"{key} -> {value}"); + } + } + // docs:end:entries_example + + // docs:start:keys_example + let keys = map.keys(); + + for i in 0..keys.max_len() { + if i < keys.len() { + let key = keys.get_unchecked(i); + let value = map.get(key).unwrap_unchecked(); + println(f"{key} -> {value}"); + } + } + // docs:end:keys_example + + // docs:start:values_example + let values = map.values(); + + for i in 0..values.max_len() { + if i < values.len() { + let value = values.get_unchecked(i); + println(f"Found value {value}"); + } + } + // docs:end:values_example +} + +fn iter_examples(mut map: HashMap>) { + // docs:start:iter_mut_example + // Add 1 to each key in the map, and double the value associated with that key. + map.iter_mut(|k, v| (k + 1, v * 2)); + // docs:end:iter_mut_example + + // docs:start:iter_keys_mut_example + // Double each key, leaving the value associated with that key untouched + map.iter_keys_mut(|k| k * 2); + // docs:end:iter_keys_mut_example + + // docs:start:iter_values_mut_example + // Halve each value + map.iter_values_mut(|v| v / 2); + // docs:end:iter_values_mut_example +} diff --git a/test_programs/execution_success/hashmap/src/utils.nr b/test_programs/execution_success/hashmap/src/utils.nr index 45c9ca9bbf7..ee73245a902 100644 --- a/test_programs/execution_success/hashmap/src/utils.nr +++ b/test_programs/execution_success/hashmap/src/utils.nr @@ -1,10 +1,10 @@ -// Compile-time: cuts the M first elements from the [T; N] array. -pub(crate) fn cut(input: [T; N]) -> [T; M] { - assert(M as u64 < N as u64, "M should be less than N."); +// Compile-time: cuts the M first elements from the BoundedVec. +pub(crate) fn cut(input: BoundedVec) -> [T; M] { + assert(M < N, "M should be less than N."); - let mut new = [dep::std::unsafe::zeroed(); M]; + let mut new = BoundedVec::new(); for i in 0..M { - new[i] = input[i]; + new.push(input.get(i)); } - new + new.storage() } diff --git a/test_programs/execution_success/nested_array_in_slice/src/main.nr b/test_programs/execution_success/nested_array_in_slice/src/main.nr index e59123d0840..0594fa77a78 100644 --- a/test_programs/execution_success/nested_array_in_slice/src/main.nr +++ b/test_programs/execution_success/nested_array_in_slice/src/main.nr @@ -13,7 +13,7 @@ fn main(y: field) { let foo_two = Foo { a: 4, b: [5, 6, 21], bar: Bar { inner: [103, 104, 105] } }; let foo_three = Foo { a: 7, b: [8, 9, 22], bar: Bar { inner: [106, 107, 108] } }; let foo_four = Foo { a: 10, b: [11, 12, 23], bar: Bar { inner: [109, 110, 111] } }; - let mut x = [foo_one]; + let mut x = &[foo_one]; x = x.push_back(foo_two); x = x.push_back(foo_three); x = x.push_back(foo_four); diff --git a/test_programs/execution_success/poseidon_bn254_hash/src/main.nr b/test_programs/execution_success/poseidon_bn254_hash/src/main.nr index c7ae3d3d5c4..b4525af645e 100644 --- a/test_programs/execution_success/poseidon_bn254_hash/src/main.nr +++ b/test_programs/execution_success/poseidon_bn254_hash/src/main.nr @@ -9,7 +9,7 @@ fn main(x1: [field; 2], y1: pub field, x2: [field; 4], y2: pub field, x3: [field let hash2 = poseidon::bn254::hash_4(x2); assert(hash2 == y2); - let hash3 = poseidon2::Poseidon2::hash(x3, x3.len() as u32); + let hash3 = poseidon2::Poseidon2::hash(x3, x3.len()); assert(hash3 == y3); } // docs:end:poseidon diff --git a/test_programs/execution_success/prelude/src/main.nr b/test_programs/execution_success/prelude/src/main.nr index c9ae448c486..226341f1e7b 100644 --- a/test_programs/execution_success/prelude/src/main.nr +++ b/test_programs/execution_success/prelude/src/main.nr @@ -1,6 +1,6 @@ fn main() { - let _xs = Vec::new(); - let _option = Option::none(); + let _xs: Vec = Vec::new(); + let _option: Option = Option::none(); print("42\n"); println("42"); diff --git a/test_programs/execution_success/regression/src/main.nr b/test_programs/execution_success/regression/src/main.nr index c26c71209d3..33a2bb3cb26 100644 --- a/test_programs/execution_success/regression/src/main.nr +++ b/test_programs/execution_success/regression/src/main.nr @@ -1,4 +1,4 @@ -global NIBBLE_LENGTH: Field = 16; +global NIBBLE_LENGTH: u64 = 16; struct U4 { inner: u8, @@ -21,8 +21,8 @@ impl Eq for U4 { } fn compact_decode(input: [u8; N], length: field) -> ([U4; NIBBLE_LENGTH], field) { - assert(2 * input.len() as u64 <= NIBBLE_LENGTH as u64); - assert(length as u64 <= input.len() as u64); + assert(2 * input.len() <= NIBBLE_LENGTH); + assert(length as u64 <= input.len()); let mut nibble = [U4::zero(); NIBBLE_LENGTH]; diff --git a/test_programs/execution_success/regression_4202/src/main.nr b/test_programs/execution_success/regression_4202/src/main.nr index 37d2ee4578d..faa14f03912 100644 --- a/test_programs/execution_success/regression_4202/src/main.nr +++ b/test_programs/execution_success/regression_4202/src/main.nr @@ -1,5 +1,5 @@ fn main(input: [u32; 4]) { - let mut slice1: [u32] = [1, 2, 3, 4]; + let mut slice1: [u32] = &[1, 2, 3, 4]; if slice1[0] == 3 { slice1[1] = 4; } diff --git a/test_programs/execution_success/regression_4436/Nargo.toml b/test_programs/execution_success/regression_4436/Nargo.toml new file mode 100644 index 00000000000..0904d858596 --- /dev/null +++ b/test_programs/execution_success/regression_4436/Nargo.toml @@ -0,0 +1,5 @@ +[package] +name = "regression_4436" +type = "bin" +authors = [""] +compiler_version = ">=0.22.0" diff --git a/test_programs/execution_success/regression_4436/src/main.nr b/test_programs/execution_success/regression_4436/src/main.nr new file mode 100644 index 00000000000..834ea3250cc --- /dev/null +++ b/test_programs/execution_success/regression_4436/src/main.nr @@ -0,0 +1,31 @@ +trait LibTrait { + fn broadcast(); + fn get_constant() -> Field; +} + +global STRUCT_A_LEN: Field = 3; +global STRUCT_B_LEN: Field = 5; + +struct StructA; +struct StructB; + +impl LibTrait for StructA { + fn broadcast() { + Self::get_constant(); + } + + fn get_constant() -> Field { + 1 + } +} +impl LibTrait for StructB { + fn broadcast() { + Self::get_constant(); + } + + fn get_constant() -> Field { + 1 + } +} + +fn main() {} diff --git a/test_programs/execution_success/regression_4449/Nargo.toml b/test_programs/execution_success/regression_4449/Nargo.toml new file mode 100644 index 00000000000..925420a03a8 --- /dev/null +++ b/test_programs/execution_success/regression_4449/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "regression_4449" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/execution_success/regression_4449/Prover.toml b/test_programs/execution_success/regression_4449/Prover.toml new file mode 100644 index 00000000000..81af476bcc9 --- /dev/null +++ b/test_programs/execution_success/regression_4449/Prover.toml @@ -0,0 +1,3 @@ + +x = 0xbd +result = [204, 59, 83, 197, 18, 1, 128, 43, 247, 28, 104, 225, 106, 13, 20, 187, 42, 26, 67, 150, 48, 75, 238, 168, 121, 247, 142, 160, 71, 222, 97, 188] \ No newline at end of file diff --git a/test_programs/execution_success/regression_4449/src/main.nr b/test_programs/execution_success/regression_4449/src/main.nr new file mode 100644 index 00000000000..454a93f5d1a --- /dev/null +++ b/test_programs/execution_success/regression_4449/src/main.nr @@ -0,0 +1,14 @@ +// Regression test for issue #4449 +use dep::std; + +fn main(x: u8, result: [u8; 32]) { + let x = x % 31; + let mut digest = [0; 32]; + for i in 0..70 { + let y = x + i; + let a = [y, x, 32, 0, y + 1, y - 1, y - 2, 5]; + digest = std::sha256::digest(a); + } + + assert(digest == result); +} diff --git a/test_programs/execution_success/regression_capacity_tracker/Nargo.toml b/test_programs/execution_success/regression_capacity_tracker/Nargo.toml new file mode 100644 index 00000000000..d5a3839626f --- /dev/null +++ b/test_programs/execution_success/regression_capacity_tracker/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "regression_capacity_tracker" +type = "bin" +authors = [""] +compiler_version = ">=0.26.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/execution_success/regression_capacity_tracker/Prover.toml b/test_programs/execution_success/regression_capacity_tracker/Prover.toml new file mode 100644 index 00000000000..bbf35b23a0f --- /dev/null +++ b/test_programs/execution_success/regression_capacity_tracker/Prover.toml @@ -0,0 +1,3 @@ +expected = "10" +first = "10" +input = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] \ No newline at end of file diff --git a/test_programs/execution_success/regression_capacity_tracker/src/main.nr b/test_programs/execution_success/regression_capacity_tracker/src/main.nr new file mode 100644 index 00000000000..be645c811d2 --- /dev/null +++ b/test_programs/execution_success/regression_capacity_tracker/src/main.nr @@ -0,0 +1,19 @@ +// Reference https://github.com/noir-lang/noir/issues/4395#issuecomment-2018948631 +// for context. +// We were not accurately accounting for situations where the slice capacity tracker +// was expecting a capacity from slice intrinsic results. +fn main(expected: pub Field, first: Field, input: [Field; 20]) { + let mut hasher_slice = input.as_slice(); + hasher_slice = hasher_slice.push_front(first); + assert(hasher_slice[0] == expected); + // We need a conditional based upon witnesses + // to force a store of the slice. + // If this successfully compiles it means we have stored + // the results of the slice intrinsics used above. + if expected as u32 > 10 { + hasher_slice[expected - 10] = 100; + } else { + hasher_slice[expected] = 100; + } + assert(hasher_slice[0] == expected); +} diff --git a/test_programs/execution_success/regression_sha256_slice/Nargo.toml b/test_programs/execution_success/regression_sha256_slice/Nargo.toml new file mode 100644 index 00000000000..759c3b20ba8 --- /dev/null +++ b/test_programs/execution_success/regression_sha256_slice/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "regression_sha256_slice" +type = "bin" +authors = [""] +compiler_version = ">=0.26.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/execution_success/regression_sha256_slice/Prover.toml b/test_programs/execution_success/regression_sha256_slice/Prover.toml new file mode 100644 index 00000000000..8a027e9eca9 --- /dev/null +++ b/test_programs/execution_success/regression_sha256_slice/Prover.toml @@ -0,0 +1 @@ +x = ["5", "10"] diff --git a/test_programs/execution_success/regression_sha256_slice/src/main.nr b/test_programs/execution_success/regression_sha256_slice/src/main.nr new file mode 100644 index 00000000000..60b0911cf09 --- /dev/null +++ b/test_programs/execution_success/regression_sha256_slice/src/main.nr @@ -0,0 +1,12 @@ +use dep::std; + +fn main(x: [u8; 2]) { + let mut y = x.as_slice(); + let digest1 = std::hash::sha256_slice(y); + let mut v = y; + if x[0] != 0 { + v = y.push_back(x[0]); + } + let digest2 = std::hash::sha256_slice(v); + assert(digest1 != digest2); +} diff --git a/test_programs/execution_success/schnorr/src/main.nr b/test_programs/execution_success/schnorr/src/main.nr index fda3afd31c7..ff64268f1bf 100644 --- a/test_programs/execution_success/schnorr/src/main.nr +++ b/test_programs/execution_success/schnorr/src/main.nr @@ -17,7 +17,7 @@ fn main( // Is there ever a situation where someone would want // to ensure that a signature was invalid? // Check that passing a slice as the message is valid - let valid_signature = std::schnorr::verify_signature(pub_key_x, pub_key_y, signature, message_field_bytes); + let valid_signature = std::schnorr::verify_signature_slice(pub_key_x, pub_key_y, signature, message_field_bytes); assert(valid_signature); // Check that passing an array as the message is valid let valid_signature = std::schnorr::verify_signature(pub_key_x, pub_key_y, signature, message); diff --git a/test_programs/execution_success/slice_coercion/Nargo.toml b/test_programs/execution_success/slice_coercion/Nargo.toml new file mode 100644 index 00000000000..659677cc560 --- /dev/null +++ b/test_programs/execution_success/slice_coercion/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "slice_coercion" +type = "bin" +authors = [""] +compiler_version = ">=0.25.0" + +[dependencies] diff --git a/test_programs/execution_success/slice_coercion/Prover.toml b/test_programs/execution_success/slice_coercion/Prover.toml new file mode 100644 index 00000000000..09c44a855b0 --- /dev/null +++ b/test_programs/execution_success/slice_coercion/Prover.toml @@ -0,0 +1,2 @@ +first = 3 +expected = 3 diff --git a/test_programs/execution_success/slice_coercion/src/main.nr b/test_programs/execution_success/slice_coercion/src/main.nr new file mode 100644 index 00000000000..a3785e79afa --- /dev/null +++ b/test_programs/execution_success/slice_coercion/src/main.nr @@ -0,0 +1,19 @@ +struct Hasher { + fields: [Field], +} + +impl Hasher { + pub fn new() -> Self { + Self { fields: [] } + } + + pub fn add(&mut self, field: Field) { + self.fields = self.fields.push_back(field); + } +} + +fn main(expected: pub Field, first: Field) { + let mut hasher = Hasher::new(); + hasher.add(first); + assert(hasher.fields[0] == expected); +} diff --git a/test_programs/execution_success/slice_dynamic_index/src/main.nr b/test_programs/execution_success/slice_dynamic_index/src/main.nr index 8b8790280c8..771efd80ff6 100644 --- a/test_programs/execution_success/slice_dynamic_index/src/main.nr +++ b/test_programs/execution_success/slice_dynamic_index/src/main.nr @@ -4,7 +4,7 @@ fn main(x: field) { } fn regression_dynamic_slice_index(x: field, y: field) { - let mut slice = []; + let mut slice = &[]; for i in 0..5 { slice = slice.push_back(i as Field); } diff --git a/test_programs/execution_success/slices/src/main.nr b/test_programs/execution_success/slices/src/main.nr index 429b0ea563f..5708f231840 100644 --- a/test_programs/execution_success/slices/src/main.nr +++ b/test_programs/execution_success/slices/src/main.nr @@ -2,7 +2,7 @@ use dep::std::slice; use dep::std; fn main(x: field, y: pub field) { - let mut slice = [0; 2]; + let mut slice = &[0; 2]; assert(slice[0] == 0); assert(slice[0] != 1); slice[0] = x; @@ -13,7 +13,7 @@ fn main(x: field, y: pub field) { assert(slice_plus_10[2] != 8); assert(slice_plus_10.len() == 3); - let mut new_slice = []; + let mut new_slice = &[]; for i in 0..5 { new_slice = new_slice.push_back(i); } @@ -41,7 +41,7 @@ fn main(x: field, y: pub field) { assert(remove_slice[3] == 3); assert(remove_slice.len() == 4); - let append = [1, 2].append([3, 4, 5]); + let append = &[1, 2].append(&[3, 4, 5]); assert(append.len() == 5); assert(append[0] == 1); assert(append[4] == 5); @@ -50,10 +50,15 @@ fn main(x: field, y: pub field) { // The parameters to this function must come from witness values (inputs to main) regression_merge_slices(x, y); regression_2370(); + + regression_4418(x); + regression_slice_call_result(x, y); + regression_4506(); } + // Ensure that slices of struct/tuple values work. fn regression_2083() { - let y = [(1, 2)]; + let y = &[(1, 2)]; let y = y.push_back((3, 4)); // [(1, 2), (3, 4)] let y = y.push_back((5, 6)); // [(1, 2), (3, 4), (5, 6)] assert(y[2].1 == 6); @@ -82,6 +87,7 @@ fn regression_2083() { assert(x.0 == 5); assert(x.1 == 6); } + // The parameters to this function must come from witness values (inputs to main) fn regression_merge_slices(x: field, y: field) { merge_slices_if(x, y); @@ -142,15 +148,17 @@ fn merge_slices_else(x: field) { assert(slice[2] == 5); assert(slice.len() == 3); } + // Test returning a merged slice without a mutation fn merge_slices_return(x: field, y: field) -> [field] { - let slice = [0; 2]; + let slice = &[0; 2]; if x != y { if x != 20 { slice.push_back(y) } else { slice } } else { slice } } + // Test mutating a slice inside of an if statement fn merge_slices_mutate(x: field, y: field) -> [field] { let mut slice = [0; 2]; @@ -162,6 +170,7 @@ fn merge_slices_mutate(x: field, y: field) -> [field] { } slice } + // Test mutating a slice inside of a loop in an if statement fn merge_slices_mutate_in_loop(x: field, y: field) -> [field] { let mut slice = [0; 2]; @@ -294,6 +303,35 @@ fn merge_slices_remove_between_ifs(x: field, y: field) -> [field] { // Previously, we'd get a type error when trying to assign an array of a different size to // an existing array variable. Now, we infer the variable must be a slice. fn regression_2370() { - let mut slice = []; - slice = [1, 2, 3]; + let mut slice = &[]; + slice = &[1, 2, 3]; +} + +fn regression_4418(x: field) { + let mut crash = x.to_be_bytes(32); + + if x != 0 { + crash[0] = 10; + } +} + +fn regression_slice_call_result(x: field, y: field) { + let mut slice = merge_slices_return(x, y); + if x != 0 { + slice = slice.push_back(5); + slice = slice.push_back(10); + } else { + slice = slice.push_back(5); + } + assert(slice.len() == 5); + assert(slice[0] == 0); + assert(slice[1] == 0); + assert(slice[2] == 10); + assert(slice[3] == 5); + assert(slice[4] == 10); +} + +fn regression_4506() { + let slice: [Field] = &[1, 2, 3]; + assert(slice == slice); } diff --git a/test_programs/execution_success/witness_compression/Nargo.toml b/test_programs/execution_success/witness_compression/Nargo.toml new file mode 100644 index 00000000000..7d6ba0c1938 --- /dev/null +++ b/test_programs/execution_success/witness_compression/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "witness_compression" +type = "bin" +authors = [""] +compiler_version = ">=0.24.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_failure/custom_entry_not_found/Prover.toml b/test_programs/execution_success/witness_compression/Prover.toml similarity index 50% rename from test_programs/compile_failure/custom_entry_not_found/Prover.toml rename to test_programs/execution_success/witness_compression/Prover.toml index 4dd6b405159..8c12ebba6cf 100644 --- a/test_programs/compile_failure/custom_entry_not_found/Prover.toml +++ b/test_programs/execution_success/witness_compression/Prover.toml @@ -1 +1,2 @@ x = "1" +y = "2" diff --git a/test_programs/execution_success/witness_compression/src/main.nr b/test_programs/execution_success/witness_compression/src/main.nr new file mode 100644 index 00000000000..3027d35b13a --- /dev/null +++ b/test_programs/execution_success/witness_compression/src/main.nr @@ -0,0 +1,7 @@ +// This test should be used to regenerate the serialized witness used in the `acvm_js` integration tests. +// The `acvm_js` test file containing the serialized witness should be also called `witness_compression`. +// After recompiling Noir, you can manually print the witness byte array to be written to file after execution. +fn main(x: Field, y: pub Field) -> pub Field { + assert(x != y); + x + y +} diff --git a/test_programs/noir_test_failure/should_fail_suite_with_one_failure/Nargo.toml b/test_programs/noir_test_failure/should_fail_suite_with_one_failure/Nargo.toml new file mode 100644 index 00000000000..3d2cf2c6096 --- /dev/null +++ b/test_programs/noir_test_failure/should_fail_suite_with_one_failure/Nargo.toml @@ -0,0 +1,5 @@ +[package] +name = "should_fail_with_mismatch" +type = "bin" +authors = [""] +[dependencies] diff --git a/test_programs/compile_failure/div_by_zero_modulo/Prover.toml b/test_programs/noir_test_failure/should_fail_suite_with_one_failure/Prover.toml similarity index 100% rename from test_programs/compile_failure/div_by_zero_modulo/Prover.toml rename to test_programs/noir_test_failure/should_fail_suite_with_one_failure/Prover.toml diff --git a/test_programs/noir_test_failure/should_fail_suite_with_one_failure/src/main.nr b/test_programs/noir_test_failure/should_fail_suite_with_one_failure/src/main.nr new file mode 100644 index 00000000000..8ed9003164a --- /dev/null +++ b/test_programs/noir_test_failure/should_fail_suite_with_one_failure/src/main.nr @@ -0,0 +1,11 @@ +/// Test to make sure the entire test suite fails, even if some of the tests pass! + +#[test] +fn this_will_pass() { + assert(true); +} + +#[test] +fn this_will_fail() { + assert(false); +} diff --git a/test_programs/noir_test_success/bounded_vec/src/main.nr b/test_programs/noir_test_success/bounded_vec/src/main.nr index 0e2c89c9064..22ec291f9d6 100644 --- a/test_programs/noir_test_success/bounded_vec/src/main.nr +++ b/test_programs/noir_test_success/bounded_vec/src/main.nr @@ -1,3 +1,31 @@ +#[test] +fn test_vec_new_foo() { + foo(); +} + +#[test(should_fail)] +fn test_vec_new_bad() { + bad(); +} + +// docs:start:new_example +fn foo() -> BoundedVec { + // Ok! MaxLen is specified with a type annotation + let v1: BoundedVec = BoundedVec::new(); + let v2 = BoundedVec::new(); + + // Ok! MaxLen is known from the type of foo's return value + v2 +} + +fn bad() { + let mut v3 = BoundedVec::new(); + + // Not Ok! We don't know if v3's MaxLen is at least 1, and the compiler often infers 0 by default. + v3.push(5); +} +// docs:end:new_example + #[test] fn test_vec_push_pop() { let mut vec: BoundedVec = BoundedVec::new(); @@ -15,13 +43,123 @@ fn test_vec_push_pop() { assert(vec.get(1) == 4); } +#[test] +fn test_vec_get_unchecked() { + let mut vec: BoundedVec = BoundedVec::new(); + vec.extend_from_array([1, 2, 3, 4]); + let sum = sum_of_first_three(vec); + assert_eq(sum, 6); +} + +// docs:start:get_unchecked_example +fn sum_of_first_three(v: BoundedVec) -> u32 { + // Always ensure the length is larger than the largest + // index passed to get_unchecked + assert(v.len() > 2); + let first = v.get_unchecked(0); + let second = v.get_unchecked(1); + let third = v.get_unchecked(2); + first + second + third +} +// docs:end:get_unchecked_example + +#[test(should_fail_with = "push out of bounds")] +fn push_docs_example() { + // docs:start:bounded-vec-push-example + let mut v: BoundedVec = BoundedVec::new(); + + v.push(1); + v.push(2); + + // Panics with failed assertion "push out of bounds" + v.push(3); + // docs:end:bounded-vec-push-example +} + +#[test] +fn pop_docs_example() { + // docs:start:bounded-vec-pop-example + let mut v: BoundedVec = BoundedVec::new(); + v.push(1); + v.push(2); + + let two = v.pop(); + let one = v.pop(); + + assert(two == 2); + assert(one == 1); + // error: cannot pop from an empty vector + // let _ = v.pop(); + // docs:end:bounded-vec-pop-example +} + +#[test] +fn len_docs_example() { + // docs:start:bounded-vec-len-example + let mut v: BoundedVec = BoundedVec::new(); + assert(v.len() == 0); + + v.push(100); + assert(v.len() == 1); + + v.push(200); + v.push(300); + v.push(400); + assert(v.len() == 4); + + let _ = v.pop(); + let _ = v.pop(); + assert(v.len() == 2); + // docs:end:bounded-vec-len-example +} + +#[test] +fn max_len_docs_example() { + // docs:start:bounded-vec-max-len-example + let mut v: BoundedVec = BoundedVec::new(); + + assert(v.max_len() == 5); + v.push(10); + assert(v.max_len() == 5); + // docs:end:bounded-vec-max-len-example +} + +#[test] +fn storage_docs_example() { + // docs:start:bounded-vec-storage-example + let mut v: BoundedVec = BoundedVec::new(); + + assert(v.storage() == [0, 0, 0, 0, 0]); + + v.push(57); + assert(v.storage() == [57, 0, 0, 0, 0]); + // docs:end:bounded-vec-storage-example +} + #[test] fn test_vec_extend_from_array() { + // docs:start:bounded-vec-extend-from-array-example let mut vec: BoundedVec = BoundedVec::new(); vec.extend_from_array([2, 4]); + assert(vec.len == 2); assert(vec.get(0) == 2); assert(vec.get(1) == 4); + // docs:end:bounded-vec-extend-from-array-example +} + +#[test] +fn test_vec_extend_from_bounded_vec() { + // docs:start:bounded-vec-extend-from-bounded-vec-example + let mut v1: BoundedVec = BoundedVec::new(); + let mut v2: BoundedVec = BoundedVec::new(); + + v2.extend_from_array([1, 2, 3]); + v1.extend_from_bounded_vec(v2); + + assert(v1.storage() == [1, 2, 3, 0, 0]); + assert(v2.storage() == [1, 2, 3, 0, 0, 0, 0]); + // docs:end:bounded-vec-extend-from-bounded-vec-example } #[test(should_fail_with="extend_from_array out of bounds")] @@ -88,12 +226,13 @@ fn test_vec_extend_from_bounded_vec_twice_out_of_bound() { #[test] fn test_vec_any() { - let mut vec: BoundedVec = BoundedVec::new(); - vec.extend_from_array([2, 4, 6]); - assert(vec.any(|v| v == 2) == true); - assert(vec.any(|v| v == 4) == true); - assert(vec.any(|v| v == 6) == true); - assert(vec.any(|v| v == 3) == false); + // docs:start:bounded-vec-any-example + let mut v: BoundedVec = BoundedVec::new(); + v.extend_from_array([2, 4, 6]); + + let all_even = !v.any(|elem: u32| elem % 2 != 0); + assert(all_even); + // docs:end:bounded-vec-any-example } #[test] @@ -101,5 +240,6 @@ fn test_vec_any_not_default() { let default_value = 0; let mut vec: BoundedVec = BoundedVec::new(); vec.extend_from_array([2, 4]); - assert(vec.any(|v| v == default_value) == false); + assert(!vec.any(|v| v == default_value)); } + diff --git a/test_programs/noir_test_success/brillig_overflow_checks/Nargo.toml b/test_programs/noir_test_success/brillig_overflow_checks/Nargo.toml new file mode 100644 index 00000000000..b2d47d258ed --- /dev/null +++ b/test_programs/noir_test_success/brillig_overflow_checks/Nargo.toml @@ -0,0 +1,5 @@ +[package] +name = "brillig_overflow_checks" +type = "bin" +authors = [""] +[dependencies] diff --git a/test_programs/compile_failure/dup_trait_implementation_4/Prover.toml b/test_programs/noir_test_success/brillig_overflow_checks/Prover.toml similarity index 100% rename from test_programs/compile_failure/dup_trait_implementation_4/Prover.toml rename to test_programs/noir_test_success/brillig_overflow_checks/Prover.toml diff --git a/test_programs/noir_test_success/brillig_overflow_checks/src/main.nr b/test_programs/noir_test_success/brillig_overflow_checks/src/main.nr new file mode 100644 index 00000000000..5d73ef96d49 --- /dev/null +++ b/test_programs/noir_test_success/brillig_overflow_checks/src/main.nr @@ -0,0 +1,23 @@ +use dep::std::field::bn254::{TWO_POW_128, assert_gt}; + +#[test(should_fail_with = "attempt to add with overflow")] +unconstrained fn test_overflow_add() { + let a: u8 = 255; + let b: u8 = 1; + assert_eq(a + b, 0); +} + +#[test(should_fail_with = "attempt to subtract with overflow")] +unconstrained fn test_overflow_sub() { + let a: u8 = 0; + let b: u8 = 1; + assert_eq(a - b, 255); +} + +#[test(should_fail_with = "attempt to multiply with overflow")] +unconstrained fn test_overflow_mul() { + let a: u8 = 128; + let b: u8 = 2; + assert_eq(a * b, 0); +} + diff --git a/test_programs/test_libraries/exporting_lib/src/lib.nr b/test_programs/test_libraries/exporting_lib/src/lib.nr index af1fd7a32de..bfb1819132a 100644 --- a/test_programs/test_libraries/exporting_lib/src/lib.nr +++ b/test_programs/test_libraries/exporting_lib/src/lib.nr @@ -1,4 +1,3 @@ - struct MyStruct { inner: Field } diff --git a/tooling/acvm_cli/Cargo.toml b/tooling/acvm_cli/Cargo.toml new file mode 100644 index 00000000000..72424405d36 --- /dev/null +++ b/tooling/acvm_cli/Cargo.toml @@ -0,0 +1,38 @@ +[package] +name = "acvm_cli" +description = "The entrypoint for executing the ACVM" +# x-release-please-start-version +version = "0.40.0" +# x-release-please-end +authors.workspace = true +edition.workspace = true +license.workspace = true +rust-version.workspace = true +repository.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +# Rename binary from `acvm_cli` to `acvm` +[[bin]] +name = "acvm" +path = "src/main.rs" + +[dependencies] +thiserror.workspace = true +toml.workspace = true +color-eyre = "0.6.2" +clap.workspace = true +acvm.workspace = true +nargo.workspace = true +const_format.workspace = true +bn254_blackbox_solver.workspace = true +acir.workspace = true + +# Logs +tracing-subscriber.workspace = true +tracing-appender = "0.2.3" + +[dev-dependencies] +rand = "0.8.5" +proptest = "1.2.0" +paste = "1.0.14" diff --git a/tooling/acvm_cli/src/cli/execute_cmd.rs b/tooling/acvm_cli/src/cli/execute_cmd.rs new file mode 100644 index 00000000000..86e7277451f --- /dev/null +++ b/tooling/acvm_cli/src/cli/execute_cmd.rs @@ -0,0 +1,81 @@ +use std::io::{self, Write}; + +use acir::circuit::Program; +use acir::native_types::{WitnessMap, WitnessStack}; +use bn254_blackbox_solver::Bn254BlackBoxSolver; +use clap::Args; + +use crate::cli::fs::inputs::{read_bytecode_from_file, read_inputs_from_file}; +use crate::cli::fs::witness::save_witness_to_dir; +use crate::errors::CliError; +use nargo::ops::{execute_program, DefaultForeignCallExecutor}; + +use super::fs::witness::create_output_witness_string; + +/// Executes a circuit to calculate its return value +#[derive(Debug, Clone, Args)] +pub(crate) struct ExecuteCommand { + /// Write the execution witness to named file + #[clap(long, short)] + output_witness: Option, + + /// The name of the toml file which contains the input witness map + #[clap(long, short)] + input_witness: String, + + /// The name of the binary file containing circuit bytecode + #[clap(long, short)] + bytecode: String, + + /// The working directory + #[clap(long, short)] + working_directory: String, + + /// Set to print output witness to stdout + #[clap(long, short, action)] + print: bool, +} + +fn run_command(args: ExecuteCommand) -> Result { + let bytecode = read_bytecode_from_file(&args.working_directory, &args.bytecode)?; + let circuit_inputs = read_inputs_from_file(&args.working_directory, &args.input_witness)?; + let output_witness = execute_program_from_witness(circuit_inputs, &bytecode, None)?; + assert_eq!(output_witness.length(), 1, "ACVM CLI only supports a witness stack of size 1"); + let output_witness_string = create_output_witness_string( + &output_witness.peek().expect("Should have a witness stack item").witness, + )?; + if args.output_witness.is_some() { + save_witness_to_dir( + &output_witness_string, + &args.working_directory, + &args.output_witness.unwrap(), + )?; + } + Ok(output_witness_string) +} + +pub(crate) fn run(args: ExecuteCommand) -> Result { + let print = args.print; + let output_witness_string = run_command(args)?; + if print { + io::stdout().write_all(output_witness_string.as_bytes()).unwrap(); + } + Ok(output_witness_string) +} + +pub(crate) fn execute_program_from_witness( + inputs_map: WitnessMap, + bytecode: &[u8], + foreign_call_resolver_url: Option<&str>, +) -> Result { + let blackbox_solver = Bn254BlackBoxSolver::new(); + let program: Program = Program::deserialize_program(bytecode) + .map_err(|_| CliError::CircuitDeserializationError())?; + execute_program( + &program, + inputs_map, + &blackbox_solver, + &mut DefaultForeignCallExecutor::new(true, foreign_call_resolver_url), + ) + .map_err(CliError::CircuitExecutionError) +} diff --git a/tooling/acvm_cli/src/cli/fs/inputs.rs b/tooling/acvm_cli/src/cli/fs/inputs.rs new file mode 100644 index 00000000000..2a46cfba884 --- /dev/null +++ b/tooling/acvm_cli/src/cli/fs/inputs.rs @@ -0,0 +1,54 @@ +use acir::{ + native_types::{Witness, WitnessMap}, + FieldElement, +}; +use toml::Table; + +use crate::errors::{CliError, FilesystemError}; +use std::{fs::read, path::Path}; + +/// Returns the circuit's parameters parsed from a toml file at the given location +pub(crate) fn read_inputs_from_file>( + working_directory: P, + file_name: &String, +) -> Result { + let file_path = working_directory.as_ref().join(file_name); + if !file_path.exists() { + return Err(CliError::FilesystemError(FilesystemError::MissingTomlFile( + file_name.to_owned(), + file_path, + ))); + } + + let input_string = std::fs::read_to_string(file_path) + .map_err(|_| FilesystemError::InvalidTomlFile(file_name.clone()))?; + let input_map = input_string + .parse::() + .map_err(|_| FilesystemError::InvalidTomlFile(file_name.clone()))?; + let mut witnesses: WitnessMap = WitnessMap::new(); + for (key, value) in input_map.into_iter() { + let index = + Witness(key.trim().parse().map_err(|_| CliError::WitnessIndexError(key.clone()))?); + if !value.is_str() { + return Err(CliError::WitnessValueError(key.clone())); + } + let field = FieldElement::from_hex(value.as_str().unwrap()).unwrap(); + witnesses.insert(index, field); + } + + Ok(witnesses) +} + +/// Returns the circuit's bytecode read from the file at the given location +pub(crate) fn read_bytecode_from_file>( + working_directory: P, + file_name: &String, +) -> Result, FilesystemError> { + let file_path = working_directory.as_ref().join(file_name); + if !file_path.exists() { + return Err(FilesystemError::MissingBytecodeFile(file_name.to_owned(), file_path)); + } + let bytecode: Vec = + read(file_path).map_err(|_| FilesystemError::InvalidBytecodeFile(file_name.clone()))?; + Ok(bytecode) +} diff --git a/tooling/acvm_cli/src/cli/fs/mod.rs b/tooling/acvm_cli/src/cli/fs/mod.rs new file mode 100644 index 00000000000..f23ba06fd8b --- /dev/null +++ b/tooling/acvm_cli/src/cli/fs/mod.rs @@ -0,0 +1,2 @@ +pub(super) mod inputs; +pub(super) mod witness; diff --git a/tooling/acvm_cli/src/cli/fs/witness.rs b/tooling/acvm_cli/src/cli/fs/witness.rs new file mode 100644 index 00000000000..2daaa5a3a58 --- /dev/null +++ b/tooling/acvm_cli/src/cli/fs/witness.rs @@ -0,0 +1,36 @@ +use std::{ + collections::BTreeMap, + fs::File, + io::Write, + path::{Path, PathBuf}, +}; + +use acvm::acir::native_types::WitnessMap; + +use crate::errors::{CliError, FilesystemError}; + +/// Saves the provided output witnesses to a toml file created at the given location +pub(crate) fn save_witness_to_dir>( + output_witness: &String, + witness_dir: P, + file_name: &String, +) -> Result { + let witness_path = witness_dir.as_ref().join(file_name); + + let mut file = File::create(&witness_path) + .map_err(|_| FilesystemError::OutputWitnessCreationFailed(file_name.clone()))?; + write!(file, "{}", output_witness) + .map_err(|_| FilesystemError::OutputWitnessWriteFailed(file_name.clone()))?; + + Ok(witness_path) +} + +/// Creates a toml representation of the provided witness map +pub(crate) fn create_output_witness_string(witnesses: &WitnessMap) -> Result { + let mut witness_map: BTreeMap = BTreeMap::new(); + for (key, value) in witnesses.clone().into_iter() { + witness_map.insert(key.0.to_string(), format!("0x{}", value.to_hex())); + } + + toml::to_string(&witness_map).map_err(|_| CliError::OutputWitnessSerializationFailed()) +} diff --git a/tooling/acvm_cli/src/cli/mod.rs b/tooling/acvm_cli/src/cli/mod.rs new file mode 100644 index 00000000000..a610b08ab77 --- /dev/null +++ b/tooling/acvm_cli/src/cli/mod.rs @@ -0,0 +1,41 @@ +use clap::{Parser, Subcommand}; +use color_eyre::eyre; +use const_format::formatcp; + +mod execute_cmd; +mod fs; + +const ACVM_VERSION: &str = env!("CARGO_PKG_VERSION"); + +static VERSION_STRING: &str = formatcp!("version = {}\n", ACVM_VERSION,); + +#[derive(Parser, Debug)] +#[command(name="acvm", author, version=VERSION_STRING, about, long_about = None)] +struct ACVMCli { + #[command(subcommand)] + command: ACVMCommand, +} + +#[non_exhaustive] +#[derive(Subcommand, Clone, Debug)] +enum ACVMCommand { + Execute(execute_cmd::ExecuteCommand), +} + +#[cfg(not(feature = "codegen-docs"))] +pub(crate) fn start_cli() -> eyre::Result<()> { + let ACVMCli { command } = ACVMCli::parse(); + + match command { + ACVMCommand::Execute(args) => execute_cmd::run(args), + }?; + + Ok(()) +} + +#[cfg(feature = "codegen-docs")] +pub(crate) fn start_cli() -> eyre::Result<()> { + let markdown: String = clap_markdown::help_markdown::(); + println!("{markdown}"); + Ok(()) +} diff --git a/tooling/acvm_cli/src/errors.rs b/tooling/acvm_cli/src/errors.rs new file mode 100644 index 00000000000..923046410ea --- /dev/null +++ b/tooling/acvm_cli/src/errors.rs @@ -0,0 +1,52 @@ +use nargo::NargoError; +use std::path::PathBuf; +use thiserror::Error; + +#[derive(Debug, Error)] +pub(crate) enum FilesystemError { + #[error( + " Error: cannot find {0} in expected location {1:?}.\n Please generate this file at the expected location." + )] + MissingTomlFile(String, PathBuf), + #[error(" Error: failed to parse toml file {0}.")] + InvalidTomlFile(String), + #[error( + " Error: cannot find {0} in expected location {1:?}.\n Please generate this file at the expected location." + )] + MissingBytecodeFile(String, PathBuf), + + #[error(" Error: failed to read bytecode file {0}.")] + InvalidBytecodeFile(String), + + #[error(" Error: failed to create output witness file {0}.")] + OutputWitnessCreationFailed(String), + + #[error(" Error: failed to write output witness file {0}.")] + OutputWitnessWriteFailed(String), +} + +#[derive(Debug, Error)] +pub(crate) enum CliError { + /// Filesystem errors + #[error(transparent)] + FilesystemError(#[from] FilesystemError), + + /// Error related to circuit deserialization + #[error("Error: failed to deserialize circuit in ACVM CLI")] + CircuitDeserializationError(), + + /// Error related to circuit execution + #[error(transparent)] + CircuitExecutionError(#[from] NargoError), + + /// Input Witness Value Error + #[error("Error: failed to parse witness value {0}")] + WitnessValueError(String), + + /// Input Witness Index Error + #[error("Error: failed to parse witness index {0}")] + WitnessIndexError(String), + + #[error(" Error: failed to serialize output witness.")] + OutputWitnessSerializationFailed(), +} diff --git a/tooling/acvm_cli/src/main.rs b/tooling/acvm_cli/src/main.rs new file mode 100644 index 00000000000..33cadc73a7c --- /dev/null +++ b/tooling/acvm_cli/src/main.rs @@ -0,0 +1,36 @@ +#![forbid(unsafe_code)] +#![warn(unreachable_pub)] +#![warn(clippy::semicolon_if_nothing_returned)] +#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))] + +mod cli; +mod errors; + +use std::env; + +use tracing_appender::rolling; +use tracing_subscriber::{fmt::format::FmtSpan, EnvFilter}; + +fn main() { + // Setup tracing + if let Ok(log_dir) = env::var("ACVM_LOG_DIR") { + let debug_file = rolling::daily(log_dir, "acvm-log"); + tracing_subscriber::fmt() + .with_span_events(FmtSpan::ACTIVE) + .with_writer(debug_file) + .with_ansi(false) + .with_env_filter(EnvFilter::from_default_env()) + .init(); + } else { + tracing_subscriber::fmt() + .with_span_events(FmtSpan::ACTIVE) + .with_ansi(true) + .with_env_filter(EnvFilter::from_env("NOIR_LOG")) + .init(); + } + + if let Err(report) = cli::start_cli() { + eprintln!("{report}"); + std::process::exit(1); + } +} diff --git a/tooling/backend_interface/src/proof_system.rs b/tooling/backend_interface/src/proof_system.rs index 485381006df..3b47a7ced3a 100644 --- a/tooling/backend_interface/src/proof_system.rs +++ b/tooling/backend_interface/src/proof_system.rs @@ -3,8 +3,8 @@ use std::io::Write; use std::path::Path; use acvm::acir::{ - circuit::{Circuit, ExpressionWidth}, - native_types::WitnessMap, + circuit::{ExpressionWidth, Program}, + native_types::{WitnessMap, WitnessStack}, }; use acvm::FieldElement; use tempfile::tempdir; @@ -17,7 +17,7 @@ use crate::cli::{ use crate::{Backend, BackendError}; impl Backend { - pub fn get_exact_circuit_size(&self, circuit: &Circuit) -> Result { + pub fn get_exact_circuit_size(&self, program: &Program) -> Result { let binary_path = self.assert_binary_exists()?; self.assert_correct_version()?; @@ -26,8 +26,8 @@ impl Backend { // Create a temporary file for the circuit let circuit_path = temp_directory.join("circuit").with_extension("bytecode"); - let serialized_circuit = Circuit::serialize_circuit(circuit); - write_to_file(&serialized_circuit, &circuit_path); + let serialized_program = Program::serialize_program(program); + write_to_file(&serialized_program, &circuit_path); GatesCommand { crs_path: self.crs_directory(), bytecode_path: circuit_path } .run(binary_path) @@ -55,8 +55,8 @@ impl Backend { #[tracing::instrument(level = "trace", skip_all)] pub fn prove( &self, - circuit: &Circuit, - witness_values: WitnessMap, + program: &Program, + witness_stack: WitnessStack, ) -> Result, BackendError> { let binary_path = self.assert_binary_exists()?; self.assert_correct_version()?; @@ -66,15 +66,15 @@ impl Backend { // Create a temporary file for the witness let serialized_witnesses: Vec = - witness_values.try_into().expect("could not serialize witness map"); + witness_stack.try_into().expect("could not serialize witness map"); let witness_path = temp_directory.join("witness").with_extension("tr"); write_to_file(&serialized_witnesses, &witness_path); // Create a temporary file for the circuit // - let bytecode_path = temp_directory.join("circuit").with_extension("bytecode"); - let serialized_circuit = Circuit::serialize_circuit(circuit); - write_to_file(&serialized_circuit, &bytecode_path); + let bytecode_path = temp_directory.join("program").with_extension("bytecode"); + let serialized_program = Program::serialize_program(program); + write_to_file(&serialized_program, &bytecode_path); // Create proof and store it in the specified path let proof_with_public_inputs = @@ -82,7 +82,8 @@ impl Backend { .run(binary_path)?; let proof = bb_abstraction_leaks::remove_public_inputs( - circuit.public_inputs().0.len(), + // TODO(https://github.com/noir-lang/noir/issues/4428) + program.functions[0].public_inputs().0.len(), &proof_with_public_inputs, ); Ok(proof) @@ -93,7 +94,7 @@ impl Backend { &self, proof: &[u8], public_inputs: WitnessMap, - circuit: &Circuit, + program: &Program, ) -> Result { let binary_path = self.assert_binary_exists()?; self.assert_correct_version()?; @@ -108,9 +109,9 @@ impl Backend { write_to_file(&proof_with_public_inputs, &proof_path); // Create a temporary file for the circuit - let bytecode_path = temp_directory.join("circuit").with_extension("bytecode"); - let serialized_circuit = Circuit::serialize_circuit(circuit); - write_to_file(&serialized_circuit, &bytecode_path); + let bytecode_path = temp_directory.join("program").with_extension("bytecode"); + let serialized_program = Program::serialize_program(program); + write_to_file(&serialized_program, &bytecode_path); // Create the verification key and write it to the specified path let vk_path = temp_directory.join("vk"); @@ -128,7 +129,7 @@ impl Backend { pub fn get_intermediate_proof_artifacts( &self, - circuit: &Circuit, + program: &Program, proof: &[u8], public_inputs: WitnessMap, ) -> Result<(Vec, FieldElement, Vec), BackendError> { @@ -140,9 +141,9 @@ impl Backend { // Create a temporary file for the circuit // - let bytecode_path = temp_directory.join("circuit").with_extension("bytecode"); - let serialized_circuit = Circuit::serialize_circuit(circuit); - write_to_file(&serialized_circuit, &bytecode_path); + let bytecode_path = temp_directory.join("program").with_extension("bytecode"); + let serialized_program = Program::serialize_program(program); + write_to_file(&serialized_program, &bytecode_path); // Create the verification key and write it to the specified path let vk_path = temp_directory.join("vk"); diff --git a/tooling/backend_interface/src/smart_contract.rs b/tooling/backend_interface/src/smart_contract.rs index 5af75e48389..f6beeeb09d9 100644 --- a/tooling/backend_interface/src/smart_contract.rs +++ b/tooling/backend_interface/src/smart_contract.rs @@ -3,11 +3,11 @@ use crate::{ cli::{ContractCommand, WriteVkCommand}, Backend, BackendError, }; -use acvm::acir::circuit::Circuit; +use acvm::acir::circuit::Program; use tempfile::tempdir; impl Backend { - pub fn eth_contract(&self, circuit: &Circuit) -> Result { + pub fn eth_contract(&self, program: &Program) -> Result { let binary_path = self.assert_binary_exists()?; self.assert_correct_version()?; @@ -15,9 +15,9 @@ impl Backend { let temp_directory_path = temp_directory.path().to_path_buf(); // Create a temporary file for the circuit - let bytecode_path = temp_directory_path.join("circuit").with_extension("bytecode"); - let serialized_circuit = Circuit::serialize_circuit(circuit); - write_to_file(&serialized_circuit, &bytecode_path); + let bytecode_path = temp_directory_path.join("program").with_extension("bytecode"); + let serialized_program = Program::serialize_program(program); + write_to_file(&serialized_program, &bytecode_path); // Create the verification key and write it to the specified path let vk_path = temp_directory_path.join("vk"); @@ -38,7 +38,7 @@ mod tests { use std::collections::BTreeSet; use acvm::acir::{ - circuit::{Circuit, ExpressionWidth, Opcode, PublicInputs}, + circuit::{Circuit, ExpressionWidth, Opcode, Program, PublicInputs}, native_types::{Expression, Witness}, }; @@ -59,8 +59,9 @@ mod tests { assert_messages: Default::default(), recursive: false, }; + let program = Program { functions: vec![circuit] }; - let contract = get_mock_backend()?.eth_contract(&circuit)?; + let contract = get_mock_backend()?.eth_contract(&program)?; assert!(contract.contains("contract VerifierContract")); diff --git a/tooling/bb_abstraction_leaks/build.rs b/tooling/bb_abstraction_leaks/build.rs index f9effd5d991..52f7783851a 100644 --- a/tooling/bb_abstraction_leaks/build.rs +++ b/tooling/bb_abstraction_leaks/build.rs @@ -10,7 +10,7 @@ use const_format::formatcp; const USERNAME: &str = "AztecProtocol"; const REPO: &str = "aztec-packages"; -const VERSION: &str = "0.24.0"; +const VERSION: &str = "0.32.0"; const TAG: &str = formatcp!("aztec-packages-v{}", VERSION); const API_URL: &str = diff --git a/tooling/debugger/build.rs b/tooling/debugger/build.rs index 26a8bc64b0e..ebdf2036894 100644 --- a/tooling/debugger/build.rs +++ b/tooling/debugger/build.rs @@ -7,8 +7,7 @@ use std::{env, fs}; const GIT_COMMIT: &&str = &"GIT_COMMIT"; fn main() { - // Only use build_data if the environment variable isn't set - // The environment variable is always set when working via Nix + // Only use build_data if the environment variable isn't set. if std::env::var(GIT_COMMIT).is_err() { build_data::set_GIT_COMMIT(); build_data::set_GIT_DIRTY(); diff --git a/tooling/debugger/ignored-tests.txt b/tooling/debugger/ignored-tests.txt index c472e828739..4507aeb8545 100644 --- a/tooling/debugger/ignored-tests.txt +++ b/tooling/debugger/ignored-tests.txt @@ -1,21 +1,17 @@ array_dynamic_blackbox_input -array_sort -assign_ex +bigint bit_shifts_comptime -brillig_cow -brillig_nested_arrays brillig_references brillig_to_bytes_integration debug_logs double_verify_nested_proof double_verify_proof +double_verify_proof_recursive modulus -nested_array_dynamic -nested_array_in_slice -nested_arrays_from_brillig references scalar_mul signed_comparison -simple_2d_array to_bytes_integration -bigint +fold_basic +fold_basic_nested_call +fold_call_witness_condition diff --git a/tooling/debugger/src/context.rs b/tooling/debugger/src/context.rs index 515edf0bb06..1acd581b2be 100644 --- a/tooling/debugger/src/context.rs +++ b/tooling/debugger/src/context.rs @@ -2,17 +2,20 @@ use crate::foreign_calls::DebugForeignCallExecutor; use acvm::acir::circuit::{Circuit, Opcode, OpcodeLocation}; use acvm::acir::native_types::{Witness, WitnessMap}; use acvm::brillig_vm::brillig::ForeignCallResult; -use acvm::brillig_vm::brillig::Value; +use acvm::brillig_vm::MemoryValue; use acvm::pwg::{ ACVMStatus, BrilligSolver, BrilligSolverStatus, ForeignCallWaitInfo, StepResult, ACVM, }; use acvm::{BlackBoxFunctionSolver, FieldElement}; -use nargo::artifacts::debug::DebugArtifact; +use codespan_reporting::files::{Files, SimpleFile}; +use fm::FileId; +use nargo::artifacts::debug::{DebugArtifact, StackFrame}; use nargo::errors::{ExecutionError, Location}; use nargo::NargoError; -use noirc_printable_type::{PrintableType, PrintableValue}; +use noirc_driver::DebugFile; +use std::collections::BTreeMap; use std::collections::{hash_set::Iter, HashSet}; #[derive(Debug)] @@ -29,6 +32,7 @@ pub(super) struct DebugContext<'a, B: BlackBoxFunctionSolver> { foreign_call_executor: Box, debug_artifact: &'a DebugArtifact, breakpoints: HashSet, + source_to_opcodes: BTreeMap>, } impl<'a, B: BlackBoxFunctionSolver> DebugContext<'a, B> { @@ -39,12 +43,14 @@ impl<'a, B: BlackBoxFunctionSolver> DebugContext<'a, B> { initial_witness: WitnessMap, foreign_call_executor: Box, ) -> Self { + let source_to_opcodes = build_source_to_opcode_debug_mappings(debug_artifact); Self { acvm: ACVM::new(blackbox_solver, &circuit.opcodes, initial_witness), brillig_solver: None, foreign_call_executor, debug_artifact, breakpoints: HashSet::new(), + source_to_opcodes, } } @@ -100,10 +106,48 @@ impl<'a, B: BlackBoxFunctionSolver> DebugContext<'a, B> { self.debug_artifact .file_map .get(&location.file) - .map(|file| file.path.starts_with("__debug/")) + .map(is_debug_file_in_debug_crate) .unwrap_or(false) } + /// Find an opcode location matching a source code location + // We apply some heuristics here, and there are four possibilities for the + // return value of this function: + // 1. the source location is not found -> None + // 2. an exact unique location is found (very rare) -> Some(opcode_location) + // 3. an exact but not unique location is found, ie. a source location may + // be mapped to multiple opcodes, and those may be disjoint, for example for + // functions called multiple times throughout the program + // -> return the first opcode in program order that matches the source location + // 4. exact location is not found, so an opcode for a nearby source location + // is returned (this again could actually be more than one opcodes) + // -> return the opcode for the next source line that is mapped + pub(super) fn find_opcode_for_source_location( + &self, + file_id: &FileId, + line: i64, + ) -> Option { + let line = line as usize; + let line_to_opcodes = self.source_to_opcodes.get(file_id)?; + let found_index = match line_to_opcodes.binary_search_by(|x| x.0.cmp(&line)) { + Ok(index) => { + // move backwards to find the first opcode which matches the line + let mut index = index; + while index > 0 && line_to_opcodes[index - 1].0 == line { + index -= 1; + } + line_to_opcodes[index].1 + } + Err(index) => { + if index >= line_to_opcodes.len() { + return None; + } + line_to_opcodes[index].1 + } + }; + Some(found_index) + } + /// Returns the callstack in source code locations for the currently /// executing opcode. This can be `None` if the execution finished (and /// `get_current_opcode_location()` returns `None`) or if the opcode is not @@ -128,6 +172,9 @@ impl<'a, B: BlackBoxFunctionSolver> DebugContext<'a, B> { &self, opcode_location: &OpcodeLocation, ) -> Vec { + // TODO: this assumes we're debugging a program (ie. the DebugArtifact + // will contain a single DebugInfo), but this assumption doesn't hold + // for contracts self.debug_artifact.debug_symbols[0] .opcode_location(opcode_location) .map(|source_locations| { @@ -332,6 +379,9 @@ impl<'a, B: BlackBoxFunctionSolver> DebugContext<'a, B> { ACVMStatus::RequiresForeignCall(_) => { unreachable!("Unexpected pending foreign call resolution"); } + ACVMStatus::RequiresAcirCall(_) => { + todo!("Multiple ACIR calls are not supported"); + } } } @@ -457,20 +507,24 @@ impl<'a, B: BlackBoxFunctionSolver> DebugContext<'a, B> { acir_index < opcodes.len() && matches!(opcodes[acir_index], Opcode::Brillig(..)) } - pub(super) fn get_brillig_memory(&self) -> Option<&[Value]> { + pub(super) fn get_brillig_memory(&self) -> Option<&[MemoryValue]> { self.brillig_solver.as_ref().map(|solver| solver.get_memory()) } - pub(super) fn write_brillig_memory(&mut self, ptr: usize, value: FieldElement) { + pub(super) fn write_brillig_memory(&mut self, ptr: usize, value: FieldElement, bit_size: u32) { if let Some(solver) = self.brillig_solver.as_mut() { - solver.write_memory_at(ptr, value.into()); + solver.write_memory_at(ptr, MemoryValue::new(value, bit_size)); } } - pub(super) fn get_variables(&self) -> Vec<(&str, &PrintableValue, &PrintableType)> { + pub(super) fn get_variables(&self) -> Vec { return self.foreign_call_executor.get_variables(); } + pub(super) fn current_stack_frame(&self) -> Option { + return self.foreign_call_executor.current_stack_frame(); + } + fn breakpoint_reached(&self) -> bool { if let Some(location) = self.get_current_opcode_location() { self.breakpoints.contains(&location) @@ -526,10 +580,55 @@ impl<'a, B: BlackBoxFunctionSolver> DebugContext<'a, B> { } } +fn is_debug_file_in_debug_crate(debug_file: &DebugFile) -> bool { + debug_file.path.starts_with("__debug/") +} + +/// Builds a map from FileId to an ordered vector of tuples with line +/// numbers and opcode locations corresponding to those line numbers +fn build_source_to_opcode_debug_mappings( + debug_artifact: &DebugArtifact, +) -> BTreeMap> { + if debug_artifact.debug_symbols.is_empty() { + return BTreeMap::new(); + } + let locations = &debug_artifact.debug_symbols[0].locations; + let simple_files: BTreeMap<_, _> = debug_artifact + .file_map + .iter() + .filter(|(_, debug_file)| !is_debug_file_in_debug_crate(debug_file)) + .map(|(file_id, debug_file)| { + ( + file_id, + SimpleFile::new(debug_file.path.to_str().unwrap(), debug_file.source.as_str()), + ) + }) + .collect(); + + let mut result: BTreeMap> = BTreeMap::new(); + locations.iter().for_each(|(opcode_location, source_locations)| { + source_locations.iter().for_each(|source_location| { + let span = source_location.span; + let file_id = source_location.file; + let Some(file) = simple_files.get(&file_id) else { + return; + }; + let Ok(line_index) = file.line_index((), span.start() as usize) else { + return; + }; + let line_number = line_index + 1; + + result.entry(file_id).or_default().push((line_number, *opcode_location)); + }); + }); + result.iter_mut().for_each(|(_, file_locations)| file_locations.sort_by_key(|x| (x.0, x.1))); + + result +} + #[cfg(test)] mod tests { use super::*; - use crate::context::{DebugCommandResult, DebugContext}; use crate::foreign_calls::DefaultDebugForeignCallExecutor; use acvm::{ @@ -545,8 +644,6 @@ mod tests { BinaryFieldOp, HeapValueType, MemoryAddress, Opcode as BrilligOpcode, ValueOrArray, }, }; - use nargo::artifacts::debug::DebugArtifact; - use std::collections::BTreeMap; #[test] fn test_resolve_foreign_calls_stepping_into_brillig() { @@ -568,7 +665,7 @@ mod tests { }, BrilligOpcode::Const { destination: MemoryAddress::from(1), - value: Value::from(fe_0), + value: fe_0, bit_size: 32, }, BrilligOpcode::ForeignCall { @@ -576,7 +673,7 @@ mod tests { destinations: vec![], destination_value_types: vec![], inputs: vec![ValueOrArray::MemoryAddress(MemoryAddress::from(0))], - input_value_types: vec![HeapValueType::Simple], + input_value_types: vec![HeapValueType::field()], }, BrilligOpcode::Stop { return_data_offset: 0, return_data_size: 0 }, ], diff --git a/tooling/debugger/src/dap.rs b/tooling/debugger/src/dap.rs index 7e67a26b257..ea3204ebbbc 100644 --- a/tooling/debugger/src/dap.rs +++ b/tooling/debugger/src/dap.rs @@ -5,7 +5,6 @@ use std::str::FromStr; use acvm::acir::circuit::{Circuit, OpcodeLocation}; use acvm::acir::native_types::WitnessMap; use acvm::BlackBoxFunctionSolver; -use codespan_reporting::files::{Files, SimpleFile}; use crate::context::DebugCommandResult; use crate::context::DebugContext; @@ -30,15 +29,16 @@ use nargo::artifacts::debug::DebugArtifact; use fm::FileId; use noirc_driver::CompiledProgram; +type BreakpointId = i64; + pub struct DapSession<'a, R: Read, W: Write, B: BlackBoxFunctionSolver> { server: Server, context: DebugContext<'a, B>, debug_artifact: &'a DebugArtifact, running: bool, - source_to_opcodes: BTreeMap>, - next_breakpoint_id: i64, - instruction_breakpoints: Vec<(OpcodeLocation, i64)>, - source_breakpoints: BTreeMap>, + next_breakpoint_id: BreakpointId, + instruction_breakpoints: Vec<(OpcodeLocation, BreakpointId)>, + source_breakpoints: BTreeMap>, } enum ScopeReferences { @@ -57,8 +57,6 @@ impl From for ScopeReferences { } } -// BTreeMap - impl<'a, R: Read, W: Write, B: BlackBoxFunctionSolver> DapSession<'a, R, W, B> { pub fn new( server: Server, @@ -67,7 +65,6 @@ impl<'a, R: Read, W: Write, B: BlackBoxFunctionSolver> DapSession<'a, R, W, B> { debug_artifact: &'a DebugArtifact, initial_witness: WitnessMap, ) -> Self { - let source_to_opcodes = Self::build_source_to_opcode_debug_mappings(debug_artifact); let context = DebugContext::new( solver, circuit, @@ -79,7 +76,6 @@ impl<'a, R: Read, W: Write, B: BlackBoxFunctionSolver> DapSession<'a, R, W, B> { server, context, debug_artifact, - source_to_opcodes, running: false, next_breakpoint_id: 1, instruction_breakpoints: vec![], @@ -87,46 +83,6 @@ impl<'a, R: Read, W: Write, B: BlackBoxFunctionSolver> DapSession<'a, R, W, B> { } } - /// Builds a map from FileId to an ordered vector of tuples with line - /// numbers and opcode locations corresponding to those line numbers - fn build_source_to_opcode_debug_mappings( - debug_artifact: &'a DebugArtifact, - ) -> BTreeMap> { - if debug_artifact.debug_symbols.is_empty() { - return BTreeMap::new(); - } - let locations = &debug_artifact.debug_symbols[0].locations; - let simple_files: BTreeMap<_, _> = debug_artifact - .file_map - .iter() - .map(|(file_id, debug_file)| { - ( - file_id, - SimpleFile::new(debug_file.path.to_str().unwrap(), debug_file.source.as_str()), - ) - }) - .collect(); - - let mut result: BTreeMap> = BTreeMap::new(); - locations.iter().for_each(|(opcode_location, source_locations)| { - if source_locations.is_empty() { - return; - } - let source_location = source_locations[0]; - let span = source_location.span; - let file_id = source_location.file; - let Ok(line_index) = &simple_files[&file_id].line_index((), span.start() as usize) - else { - return; - }; - let line_number = line_index + 1; - - result.entry(file_id).or_default().push((line_number, *opcode_location)); - }); - result.iter_mut().for_each(|(_, file_locations)| file_locations.sort_by_key(|x| x.0)); - result - } - fn send_stopped_event(&mut self, reason: StoppedEventReason) -> Result<(), ServerError> { let description = format!("{:?}", &reason); self.server.send_event(Event::Stopped(StoppedEventBody { @@ -230,6 +186,8 @@ impl<'a, R: Read, W: Write, B: BlackBoxFunctionSolver> DapSession<'a, R, W, B> { } fn build_stack_trace(&self) -> Vec { + let stack_frames = self.context.get_variables(); + self.context .get_source_call_stack() .iter() @@ -239,9 +197,15 @@ impl<'a, R: Read, W: Write, B: BlackBoxFunctionSolver> DapSession<'a, R, W, B> { self.debug_artifact.location_line_number(*source_location).unwrap(); let column_number = self.debug_artifact.location_column_number(*source_location).unwrap(); + + let name = match stack_frames.get(index) { + Some(frame) => format!("{} {}", frame.function_name, index), + None => format!("frame #{index}"), + }; + StackFrame { id: index as i64, - name: format!("frame #{index}"), + name, source: Some(Source { path: self.debug_artifact.file_map[&source_location.file] .path @@ -422,7 +386,7 @@ impl<'a, R: Read, W: Write, B: BlackBoxFunctionSolver> DapSession<'a, R, W, B> { Ok(()) } - fn get_next_breakpoint_id(&mut self) -> i64 { + fn get_next_breakpoint_id(&mut self) -> BreakpointId { let id = self.next_breakpoint_id; self.next_breakpoint_id += 1; id @@ -493,36 +457,6 @@ impl<'a, R: Read, W: Write, B: BlackBoxFunctionSolver> DapSession<'a, R, W, B> { found.map(|iter| *iter.0) } - // TODO: there are four possibilities for the return value of this function: - // 1. the source location is not found -> None - // 2. an exact unique location is found -> Some(opcode_location) - // 3. an exact but not unique location is found (ie. a source location may - // be mapped to multiple opcodes, and those may be disjoint, for example for - // functions called multiple times throughout the program) - // 4. exact location is not found, so an opcode for a nearby source location - // is returned (this again could actually be more than one opcodes) - // Case 3 is not supported yet, and 4 is not correctly handled. - fn find_opcode_for_source_location( - &self, - file_id: &FileId, - line: i64, - ) -> Option { - let line = line as usize; - let Some(line_to_opcodes) = self.source_to_opcodes.get(file_id) else { - return None; - }; - let found_index = match line_to_opcodes.binary_search_by(|x| x.0.cmp(&line)) { - Ok(index) => line_to_opcodes[index].1, - Err(index) => { - if index >= line_to_opcodes.len() { - return None; - } - line_to_opcodes[index].1 - } - }; - Some(found_index) - } - fn map_source_breakpoints(&mut self, args: &SetBreakpointsArguments) -> Vec { let Some(ref source) = &args.source.path else { return vec![]; @@ -539,7 +473,8 @@ impl<'a, R: Read, W: Write, B: BlackBoxFunctionSolver> DapSession<'a, R, W, B> { .iter() .map(|breakpoint| { let line = breakpoint.line; - let Some(location) = self.find_opcode_for_source_location(&file_id, line) else { + let Some(location) = self.context.find_opcode_for_source_location(&file_id, line) + else { return Breakpoint { verified: false, message: Some(String::from( @@ -608,16 +543,20 @@ impl<'a, R: Read, W: Write, B: BlackBoxFunctionSolver> DapSession<'a, R, W, B> { } fn build_local_variables(&self) -> Vec { - let mut variables: Vec<_> = self - .context - .get_variables() + let Some(current_stack_frame) = self.context.current_stack_frame() else { + return vec![]; + }; + + let mut variables = current_stack_frame + .variables .iter() .map(|(name, value, _var_type)| Variable { name: String::from(*name), value: format!("{:?}", *value), ..Variable::default() }) - .collect(); + .collect::>(); + variables.sort_by(|a, b| a.name.partial_cmp(&b.name).unwrap()); variables } @@ -668,8 +607,13 @@ pub fn run_session( file_map: program.file_map, warnings: program.warnings, }; - let mut session = - DapSession::new(server, solver, &program.circuit, &debug_artifact, initial_witness); + let mut session = DapSession::new( + server, + solver, + &program.program.functions[0], + &debug_artifact, + initial_witness, + ); session.run_loop() } diff --git a/tooling/debugger/src/foreign_calls.rs b/tooling/debugger/src/foreign_calls.rs index 68c4d3947b0..f11ac22cd75 100644 --- a/tooling/debugger/src/foreign_calls.rs +++ b/tooling/debugger/src/foreign_calls.rs @@ -1,19 +1,22 @@ use acvm::{ - acir::brillig::{ForeignCallParam, ForeignCallResult, Value}, + acir::brillig::{ForeignCallParam, ForeignCallResult}, pwg::ForeignCallWaitInfo, + FieldElement, }; use nargo::{ - artifacts::debug::{DebugArtifact, DebugVars}, + artifacts::debug::{DebugArtifact, DebugVars, StackFrame}, ops::{DefaultForeignCallExecutor, ForeignCallExecutor, NargoForeignCallResult}, }; -use noirc_errors::debug_info::DebugVarId; -use noirc_printable_type::{ForeignCallError, PrintableType, PrintableValue}; +use noirc_errors::debug_info::{DebugFnId, DebugVarId}; +use noirc_printable_type::ForeignCallError; pub(crate) enum DebugForeignCall { VarAssign, VarDrop, MemberAssign(u32), DerefAssign, + FnEnter, + FnExit, } impl DebugForeignCall { @@ -28,13 +31,16 @@ impl DebugForeignCall { "__debug_var_assign" => Some(DebugForeignCall::VarAssign), "__debug_var_drop" => Some(DebugForeignCall::VarDrop), "__debug_deref_assign" => Some(DebugForeignCall::DerefAssign), + "__debug_fn_enter" => Some(DebugForeignCall::FnEnter), + "__debug_fn_exit" => Some(DebugForeignCall::FnExit), _ => None, } } } pub trait DebugForeignCallExecutor: ForeignCallExecutor { - fn get_variables(&self) -> Vec<(&str, &PrintableValue, &PrintableType)>; + fn get_variables(&self) -> Vec; + fn current_stack_frame(&self) -> Option; } pub struct DefaultDebugForeignCallExecutor { @@ -57,23 +63,33 @@ impl DefaultDebugForeignCallExecutor { } pub fn load_artifact(&mut self, artifact: &DebugArtifact) { - artifact.debug_symbols.iter().for_each(|info| { - self.debug_vars.insert_variables(&info.variables); - self.debug_vars.insert_types(&info.types); - }); + // TODO: handle loading from the correct DebugInfo when we support + // debugging contracts + let Some(info) = artifact.debug_symbols.first() else { + return; + }; + self.debug_vars.insert_debug_info(info); } } impl DebugForeignCallExecutor for DefaultDebugForeignCallExecutor { - fn get_variables(&self) -> Vec<(&str, &PrintableValue, &PrintableType)> { + fn get_variables(&self) -> Vec { self.debug_vars.get_variables() } + + fn current_stack_frame(&self) -> Option { + self.debug_vars.current_stack_frame() + } } -fn debug_var_id(value: &Value) -> DebugVarId { +fn debug_var_id(value: &FieldElement) -> DebugVarId { DebugVarId(value.to_u128() as u32) } +fn debug_fn_id(value: &FieldElement) -> DebugFnId { + DebugFnId(value.to_u128() as u32) +} + impl ForeignCallExecutor for DefaultDebugForeignCallExecutor { fn execute( &mut self, @@ -85,8 +101,8 @@ impl ForeignCallExecutor for DefaultDebugForeignCallExecutor { let fcp_var_id = &foreign_call.inputs[0]; if let ForeignCallParam::Single(var_id_value) = fcp_var_id { let var_id = debug_var_id(var_id_value); - let values: Vec = - foreign_call.inputs[1..].iter().flat_map(|x| x.values()).collect(); + let values: Vec = + foreign_call.inputs[1..].iter().flat_map(|x| x.fields()).collect(); self.debug_vars.assign_var(var_id, &values); } Ok(ForeignCallResult::default().into()) @@ -114,12 +130,12 @@ impl ForeignCallExecutor for DefaultDebugForeignCallExecutor { } }) .collect(); - let values: Vec = (0..n - 1 - arity) + let values: Vec = (0..n - 1 - arity) .flat_map(|i| { foreign_call .inputs .get(1 + i) - .map(|fci| fci.values()) + .map(|fci| fci.fields()) .unwrap_or_default() }) .collect(); @@ -132,10 +148,23 @@ impl ForeignCallExecutor for DefaultDebugForeignCallExecutor { let fcp_value = &foreign_call.inputs[1]; if let ForeignCallParam::Single(var_id_value) = fcp_var_id { let var_id = debug_var_id(var_id_value); - self.debug_vars.assign_deref(var_id, &fcp_value.values()); + self.debug_vars.assign_deref(var_id, &fcp_value.fields()); } Ok(ForeignCallResult::default().into()) } + Some(DebugForeignCall::FnEnter) => { + let fcp_fn_id = &foreign_call.inputs[0]; + let ForeignCallParam::Single(fn_id_value) = fcp_fn_id else { + panic!("unexpected foreign call parameter in fn enter: {fcp_fn_id:?}") + }; + let fn_id = debug_fn_id(fn_id_value); + self.debug_vars.push_fn(fn_id); + Ok(ForeignCallResult::default().into()) + } + Some(DebugForeignCall::FnExit) => { + self.debug_vars.pop_fn(); + Ok(ForeignCallResult::default().into()) + } None => self.executor.execute(foreign_call), } } diff --git a/tooling/debugger/src/repl.rs b/tooling/debugger/src/repl.rs index 8441dbde9be..1c077c6ee9b 100644 --- a/tooling/debugger/src/repl.rs +++ b/tooling/debugger/src/repl.rs @@ -319,12 +319,12 @@ impl<'a, B: BlackBoxFunctionSolver> ReplDebugger<'a, B> { return; }; - for (index, value) in memory.iter().enumerate() { - println!("{index} = {}", value.to_field()); + for (index, value) in memory.iter().enumerate().filter(|(_, value)| value.bit_size > 0) { + println!("{index} = {}", value); } } - pub fn write_brillig_memory(&mut self, index: usize, value: String) { + pub fn write_brillig_memory(&mut self, index: usize, value: String, bit_size: u32) { let Some(field_value) = FieldElement::try_from_str(&value) else { println!("Invalid value: {value}"); return; @@ -333,15 +333,17 @@ impl<'a, B: BlackBoxFunctionSolver> ReplDebugger<'a, B> { println!("Not executing a Brillig block"); return; } - self.context.write_brillig_memory(index, field_value); + self.context.write_brillig_memory(index, field_value, bit_size); } pub fn show_vars(&self) { - let vars = self.context.get_variables(); - for (var_name, value, var_type) in vars.iter() { - let printable_value = - PrintableValueDisplay::Plain((*value).clone(), (*var_type).clone()); - println!("{var_name}:{var_type:?} = {}", printable_value); + for frame in self.context.get_variables() { + println!("{}({})", frame.function_name, frame.function_params.join(", ")); + for (var_name, value, var_type) in frame.variables.iter() { + let printable_value = + PrintableValueDisplay::Plain((*value).clone(), (*var_type).clone()); + println!(" {var_name}:{var_type:?} = {}", printable_value); + } } } @@ -511,8 +513,8 @@ pub fn run( "memset", command! { "update a Brillig memory cell with the given value", - (index: usize, value: String) => |index, value| { - ref_context.borrow_mut().write_brillig_memory(index, value); + (index: usize, value: String, bit_size: u32) => |index, value, bit_size| { + ref_context.borrow_mut().write_brillig_memory(index, value, bit_size); Ok(CommandStatus::Done) } }, @@ -530,7 +532,7 @@ pub fn run( .add( "vars", command! { - "show variable values available at this point in execution", + "show variables for each function scope available at this point in execution", () => || { ref_context.borrow_mut().show_vars(); Ok(CommandStatus::Done) diff --git a/tooling/debugger/src/source_code_printer.rs b/tooling/debugger/src/source_code_printer.rs index b5ffdb12d01..e298eb8aadd 100644 --- a/tooling/debugger/src/source_code_printer.rs +++ b/tooling/debugger/src/source_code_printer.rs @@ -30,7 +30,7 @@ struct LocationPrintContext { // Given a DebugArtifact and an OpcodeLocation, prints all the source code // locations the OpcodeLocation maps to, with some surrounding context and // visual aids to highlight the location itself. -pub(crate) fn print_source_code_location(debug_artifact: &DebugArtifact, locations: &[Location]) { +pub(super) fn print_source_code_location(debug_artifact: &DebugArtifact, locations: &[Location]) { let locations = locations.iter(); for loc in locations { @@ -269,8 +269,12 @@ mod tests { let mut opcode_locations = BTreeMap::>::new(); opcode_locations.insert(OpcodeLocation::Acir(42), vec![loc]); - let debug_symbols = - vec![DebugInfo::new(opcode_locations, BTreeMap::default(), BTreeMap::default())]; + let debug_symbols = vec![DebugInfo::new( + opcode_locations, + BTreeMap::default(), + BTreeMap::default(), + BTreeMap::default(), + )]; let debug_artifact = DebugArtifact::new(debug_symbols, &fm); let location_rendered: Vec<_> = render_location(&debug_artifact, &loc).collect(); diff --git a/tooling/debugger/tests/debug.rs b/tooling/debugger/tests/debug.rs index 4cb678192b8..b104a2c84ac 100644 --- a/tooling/debugger/tests/debug.rs +++ b/tooling/debugger/tests/debug.rs @@ -12,7 +12,9 @@ mod tests { let nargo_bin = cargo_bin("nargo").into_os_string().into_string().expect("Cannot parse nargo path"); - let mut dbg_session = spawn_bash(Some(10000)).expect("Could not start bash session"); + let timeout_seconds = 20; + let mut dbg_session = + spawn_bash(Some(timeout_seconds * 1000)).expect("Could not start bash session"); // Set backend to `/dev/null` to force an error if nargo tries to speak to a backend. dbg_session @@ -49,5 +51,8 @@ mod tests { dbg_session .exp_regex(".*Circuit witness successfully solved.*") .expect("Expected circuit witness to be successfully solved."); + + // Exit the bash session. + dbg_session.send_line("exit").expect("Failed to quit bash session"); } } diff --git a/tooling/lsp/src/requests/profile_run.rs b/tooling/lsp/src/requests/profile_run.rs index 917c247410d..89719947689 100644 --- a/tooling/lsp/src/requests/profile_run.rs +++ b/tooling/lsp/src/requests/profile_run.rs @@ -5,7 +5,10 @@ use std::{ use acvm::acir::circuit::ExpressionWidth; use async_lsp::{ErrorCode, ResponseError}; -use nargo::{artifacts::debug::DebugArtifact, insert_all_files_for_workspace_into_file_manager}; +use nargo::{ + artifacts::debug::DebugArtifact, insert_all_files_for_workspace_into_file_manager, + ops::report_errors, +}; use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_driver::{ file_manager_with_stdlib, CompileOptions, DebugFile, NOIR_ARTIFACT_VERSION_STRING, @@ -60,11 +63,18 @@ fn on_profile_run_request_inner( Some(_package) => { let expression_width = ExpressionWidth::Bounded { width: 3 }; - let (compiled_programs, compiled_contracts) = nargo::ops::compile_workspace( + let compiled_workspace = nargo::ops::compile_workspace( &workspace_file_manager, &parsed_files, &workspace, &CompileOptions::default(), + ); + + let (compiled_programs, compiled_contracts) = report_errors( + compiled_workspace, + &workspace_file_manager, + CompileOptions::default().deny_warnings, + CompileOptions::default().silence_warnings, ) .map_err(|err| ResponseError::new(ErrorCode::REQUEST_FAILED, err))?; diff --git a/tooling/lsp/src/requests/test_run.rs b/tooling/lsp/src/requests/test_run.rs index 0b88d814265..1844a3d9bf0 100644 --- a/tooling/lsp/src/requests/test_run.rs +++ b/tooling/lsp/src/requests/test_run.rs @@ -84,7 +84,7 @@ fn on_test_run_request_inner( let test_result = run_test( &state.solver, &mut context, - test_function, + &test_function, false, None, &CompileOptions::default(), diff --git a/tooling/nargo/src/artifacts/contract.rs b/tooling/nargo/src/artifacts/contract.rs index d928b09fcb9..c0316a6d1a2 100644 --- a/tooling/nargo/src/artifacts/contract.rs +++ b/tooling/nargo/src/artifacts/contract.rs @@ -1,6 +1,6 @@ -use acvm::acir::circuit::Circuit; +use acvm::acir::circuit::Program; use noirc_abi::{Abi, ContractEvent}; -use noirc_driver::{CompiledContract, ContractFunction, ContractFunctionType}; +use noirc_driver::{CompiledContract, ContractFunction}; use serde::{Deserialize, Serialize}; use noirc_driver::DebugFile; @@ -43,17 +43,17 @@ impl From for ContractArtifact { pub struct ContractFunctionArtifact { pub name: String, - pub function_type: ContractFunctionType, + pub is_unconstrained: bool, - pub is_internal: bool, + pub custom_attributes: Vec, pub abi: Abi, #[serde( - serialize_with = "Circuit::serialize_circuit_base64", - deserialize_with = "Circuit::deserialize_circuit_base64" + serialize_with = "Program::serialize_program_base64", + deserialize_with = "Program::deserialize_program_base64" )] - pub bytecode: Circuit, + pub bytecode: Program, #[serde( serialize_with = "DebugInfo::serialize_compressed_base64_json", @@ -66,8 +66,8 @@ impl From for ContractFunctionArtifact { fn from(func: ContractFunction) -> Self { ContractFunctionArtifact { name: func.name, - function_type: func.function_type, - is_internal: func.is_internal, + is_unconstrained: func.is_unconstrained, + custom_attributes: func.custom_attributes, abi: func.abi, bytecode: func.bytecode, debug_symbols: func.debug, diff --git a/tooling/nargo/src/artifacts/debug.rs b/tooling/nargo/src/artifacts/debug.rs index a249ecb03ad..fbdf59805c9 100644 --- a/tooling/nargo/src/artifacts/debug.rs +++ b/tooling/nargo/src/artifacts/debug.rs @@ -8,7 +8,7 @@ use std::{ ops::Range, }; -pub use super::debug_vars::DebugVars; +pub use super::debug_vars::{DebugVars, StackFrame}; use fm::{FileId, FileManager, PathString}; /// A Debug Artifact stores, for a given program, the debug info for every function @@ -231,8 +231,12 @@ mod tests { let mut opcode_locations = BTreeMap::>::new(); opcode_locations.insert(OpcodeLocation::Acir(42), vec![loc]); - let debug_symbols = - vec![DebugInfo::new(opcode_locations, BTreeMap::default(), BTreeMap::default())]; + let debug_symbols = vec![DebugInfo::new( + opcode_locations, + BTreeMap::default(), + BTreeMap::default(), + BTreeMap::default(), + )]; let debug_artifact = DebugArtifact::new(debug_symbols, &fm); let location_in_line = debug_artifact.location_in_line(loc).expect("Expected a range"); diff --git a/tooling/nargo/src/artifacts/debug_vars.rs b/tooling/nargo/src/artifacts/debug_vars.rs index 20f2637f7d6..6a42a4c3311 100644 --- a/tooling/nargo/src/artifacts/debug_vars.rs +++ b/tooling/nargo/src/artifacts/debug_vars.rs @@ -1,54 +1,83 @@ -use acvm::brillig_vm::brillig::Value; +use acvm::FieldElement; use noirc_errors::debug_info::{ - DebugTypeId, DebugTypes, DebugVarId, DebugVariable, DebugVariables, + DebugFnId, DebugFunction, DebugInfo, DebugTypeId, DebugVarId, DebugVariable, }; use noirc_printable_type::{decode_value, PrintableType, PrintableValue}; -use std::collections::{HashMap, HashSet}; +use std::collections::HashMap; #[derive(Debug, Default, Clone)] pub struct DebugVars { variables: HashMap, + functions: HashMap, types: HashMap, - active: HashSet, - values: HashMap, + frames: Vec<(DebugFnId, HashMap)>, +} + +pub struct StackFrame<'a> { + pub function_name: &'a str, + pub function_params: Vec<&'a str>, + pub variables: Vec<(&'a str, &'a PrintableValue, &'a PrintableType)>, } impl DebugVars { - pub fn get_variables(&self) -> Vec<(&str, &PrintableValue, &PrintableType)> { - self.active - .iter() - .filter_map(|var_id| { - self.variables.get(var_id).and_then(|debug_var| { - let Some(value) = self.values.get(var_id) else { - return None; - }; - let Some(ptype) = self.types.get(&debug_var.debug_type_id) else { - return None; - }; - Some((debug_var.name.as_str(), value, ptype)) - }) - }) - .collect() + pub fn insert_debug_info(&mut self, info: &DebugInfo) { + self.variables.extend(info.variables.clone()); + self.types.extend(info.types.clone()); + self.functions.extend(info.functions.clone()); } - pub fn insert_variables(&mut self, vars: &DebugVariables) { - self.variables.extend(vars.clone()); + pub fn get_variables(&self) -> Vec { + self.frames.iter().map(|(fn_id, frame)| self.build_stack_frame(fn_id, frame)).collect() } - pub fn insert_types(&mut self, types: &DebugTypes) { - self.types.extend(types.clone()); + pub fn current_stack_frame(&self) -> Option { + self.frames.last().map(|(fn_id, frame)| self.build_stack_frame(fn_id, frame)) + } + + fn lookup_var(&self, var_id: DebugVarId) -> Option<(&str, &PrintableType)> { + self.variables.get(&var_id).and_then(|debug_var| { + let ptype = self.types.get(&debug_var.debug_type_id)?; + Some((debug_var.name.as_str(), ptype)) + }) + } + + fn build_stack_frame<'a>( + &'a self, + fn_id: &DebugFnId, + frame: &'a HashMap, + ) -> StackFrame { + let debug_fn = &self.functions.get(fn_id).expect("failed to find function metadata"); + + let params: Vec<&str> = + debug_fn.arg_names.iter().map(|arg_name| arg_name.as_str()).collect(); + let vars: Vec<(&str, &PrintableValue, &PrintableType)> = frame + .iter() + .filter_map(|(var_id, var_value)| { + self.lookup_var(*var_id).map(|(name, typ)| (name, var_value, typ)) + }) + .collect(); + + StackFrame { + function_name: debug_fn.name.as_str(), + function_params: params, + variables: vars, + } } - pub fn assign_var(&mut self, var_id: DebugVarId, values: &[Value]) { - self.active.insert(var_id); + pub fn assign_var(&mut self, var_id: DebugVarId, values: &[FieldElement]) { let type_id = &self.variables.get(&var_id).unwrap().debug_type_id; let ptype = self.types.get(type_id).unwrap(); - self.values.insert(var_id, decode_value(&mut values.iter().map(|v| v.to_field()), ptype)); + + self.frames + .last_mut() + .expect("unexpected empty stack frames") + .1 + .insert(var_id, decode_value(&mut values.iter().copied(), ptype)); } - pub fn assign_field(&mut self, var_id: DebugVarId, indexes: Vec, values: &[Value]) { - let mut cursor: &mut PrintableValue = self - .values + pub fn assign_field(&mut self, var_id: DebugVarId, indexes: Vec, values: &[FieldElement]) { + let current_frame = &mut self.frames.last_mut().expect("unexpected empty stack frames").1; + let mut cursor: &mut PrintableValue = current_frame .get_mut(&var_id) .unwrap_or_else(|| panic!("value unavailable for var_id {var_id:?}")); let cursor_type_id = &self @@ -62,16 +91,27 @@ impl DebugVars { .unwrap_or_else(|| panic!("type unavailable for type id {cursor_type_id:?}")); for index in indexes.iter() { (cursor, cursor_type) = match (cursor, cursor_type) { - (PrintableValue::Vec(array), PrintableType::Array { length, typ }) => { + ( + PrintableValue::Vec { array_elements, is_slice }, + PrintableType::Array { length, typ }, + ) => { + assert!(!*is_slice, "slice has array type"); if let Some(len) = length { if *index as u64 >= *len { panic!("unexpected field index past array length") } - if *len != array.len() as u64 { + if *len != array_elements.len() as u64 { panic!("type/array length mismatch") } } - (array.get_mut(*index as usize).unwrap(), &*Box::leak(typ.clone())) + (array_elements.get_mut(*index as usize).unwrap(), &*Box::leak(typ.clone())) + } + ( + PrintableValue::Vec { array_elements, is_slice }, + PrintableType::Slice { typ }, + ) => { + assert!(*is_slice, "array has slice type"); + (array_elements.get_mut(*index as usize).unwrap(), &*Box::leak(typ.clone())) } ( PrintableValue::Struct(field_map), @@ -83,29 +123,32 @@ impl DebugVars { let (key, typ) = fields.get(*index as usize).unwrap(); (field_map.get_mut(key).unwrap(), typ) } - (PrintableValue::Vec(array), PrintableType::Tuple { types }) => { + ( + PrintableValue::Vec { array_elements, is_slice }, + PrintableType::Tuple { types }, + ) => { + assert!(!*is_slice, "slice has tuple type"); if *index >= types.len() as u32 { panic!( "unexpected field index ({index}) past tuple length ({})", types.len() ); } - if types.len() != array.len() { + if types.len() != array_elements.len() { panic!("type/array length mismatch") } let typ = types.get(*index as usize).unwrap(); - (array.get_mut(*index as usize).unwrap(), typ) + (array_elements.get_mut(*index as usize).unwrap(), typ) } _ => { panic!("unexpected assign field of {cursor_type:?} type"); } }; } - *cursor = decode_value(&mut values.iter().map(|v| v.to_field()), cursor_type); - self.active.insert(var_id); + *cursor = decode_value(&mut values.iter().copied(), cursor_type); } - pub fn assign_deref(&mut self, _var_id: DebugVarId, _values: &[Value]) { + pub fn assign_deref(&mut self, _var_id: DebugVarId, _values: &[FieldElement]) { unimplemented![] } @@ -114,6 +157,14 @@ impl DebugVars { } pub fn drop_var(&mut self, var_id: DebugVarId) { - self.active.remove(&var_id); + self.frames.last_mut().expect("unexpected empty stack frames").1.remove(&var_id); + } + + pub fn push_fn(&mut self, fn_id: DebugFnId) { + self.frames.push((fn_id, HashMap::default())); + } + + pub fn pop_fn(&mut self) { + self.frames.pop(); } } diff --git a/tooling/nargo/src/artifacts/program.rs b/tooling/nargo/src/artifacts/program.rs index d8dc42ec214..9e660cbd359 100644 --- a/tooling/nargo/src/artifacts/program.rs +++ b/tooling/nargo/src/artifacts/program.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use acvm::acir::circuit::Circuit; +use acvm::acir::circuit::Program; use fm::FileId; use noirc_abi::Abi; use noirc_driver::CompiledProgram; @@ -21,10 +21,10 @@ pub struct ProgramArtifact { pub abi: Abi, #[serde( - serialize_with = "Circuit::serialize_circuit_base64", - deserialize_with = "Circuit::deserialize_circuit_base64" + serialize_with = "Program::serialize_program_base64", + deserialize_with = "Program::deserialize_program_base64" )] - pub bytecode: Circuit, + pub bytecode: Program, #[serde( serialize_with = "DebugInfo::serialize_compressed_base64_json", @@ -34,17 +34,20 @@ pub struct ProgramArtifact { /// Map of file Id to the source code so locations in debug info can be mapped to source code they point to. pub file_map: BTreeMap, + + pub names: Vec, } impl From for ProgramArtifact { - fn from(program: CompiledProgram) -> Self { + fn from(compiled_program: CompiledProgram) -> Self { ProgramArtifact { - hash: program.hash, - abi: program.abi, - noir_version: program.noir_version, - bytecode: program.circuit, - debug_symbols: program.debug, - file_map: program.file_map, + hash: compiled_program.hash, + abi: compiled_program.abi, + noir_version: compiled_program.noir_version, + bytecode: compiled_program.program, + debug_symbols: compiled_program.debug, + file_map: compiled_program.file_map, + names: compiled_program.names, } } } @@ -55,10 +58,11 @@ impl From for CompiledProgram { hash: program.hash, abi: program.abi, noir_version: program.noir_version, - circuit: program.bytecode, + program: program.bytecode, debug: program.debug_symbols, file_map: program.file_map, warnings: vec![], + names: program.names, } } } diff --git a/tooling/nargo/src/errors.rs b/tooling/nargo/src/errors.rs index c743768bee2..ff238d79a46 100644 --- a/tooling/nargo/src/errors.rs +++ b/tooling/nargo/src/errors.rs @@ -64,7 +64,9 @@ impl NargoError { ExecutionError::SolvingError(error) => match error { OpcodeResolutionError::IndexOutOfBounds { .. } | OpcodeResolutionError::OpcodeNotSolvable(_) - | OpcodeResolutionError::UnsatisfiedConstrain { .. } => None, + | OpcodeResolutionError::UnsatisfiedConstrain { .. } + | OpcodeResolutionError::AcirMainCallAttempted { .. } + | OpcodeResolutionError::AcirCallOutputsMismatch { .. } => None, OpcodeResolutionError::BrilligFunctionFailed { message, .. } => Some(message), OpcodeResolutionError::BlackBoxFunctionFailed(_, reason) => Some(reason), }, diff --git a/tooling/nargo/src/ops/compile.rs b/tooling/nargo/src/ops/compile.rs index bd1850649c4..d7c7cc2c123 100644 --- a/tooling/nargo/src/ops/compile.rs +++ b/tooling/nargo/src/ops/compile.rs @@ -21,7 +21,7 @@ pub fn compile_workspace( parsed_files: &ParsedFiles, workspace: &Workspace, compile_options: &CompileOptions, -) -> Result<(Vec, Vec), CompileError> { +) -> CompilationResult<(Vec, Vec)> { let (binary_packages, contract_packages): (Vec<_>, Vec<_>) = workspace .into_iter() .filter(|package| !package.is_library()) @@ -38,31 +38,20 @@ pub fn compile_workspace( .map(|package| compile_contract(file_manager, parsed_files, package, compile_options)) .collect(); - // Report any warnings/errors which were encountered during compilation. - let compiled_programs: Vec = program_results - .into_iter() - .map(|compilation_result| { - report_errors( - compilation_result, - file_manager, - compile_options.deny_warnings, - compile_options.silence_warnings, - ) - }) - .collect::>()?; - let compiled_contracts: Vec = contract_results - .into_iter() - .map(|compilation_result| { - report_errors( - compilation_result, - file_manager, - compile_options.deny_warnings, - compile_options.silence_warnings, - ) - }) - .collect::>()?; - - Ok((compiled_programs, compiled_contracts)) + // Collate any warnings/errors which were encountered during compilation. + let compiled_programs = collect_errors(program_results); + let compiled_contracts = collect_errors(contract_results); + + match (compiled_programs, compiled_contracts) { + (Ok((programs, program_warnings)), Ok((contracts, contract_warnings))) => { + let warnings = [program_warnings, contract_warnings].concat(); + Ok(((programs, contracts), warnings)) + } + (Err(program_errors), Err(contract_errors)) => { + Err([program_errors, contract_errors].concat()) + } + (Err(errors), _) | (_, Err(errors)) => Err(errors), + } } pub fn compile_program( @@ -107,7 +96,30 @@ pub fn compile_contract( noirc_driver::compile_contract(&mut context, crate_id, compile_options) } -pub(crate) fn report_errors( +/// Constructs a single `CompilationResult` for a collection of `CompilationResult`s, merging the set of warnings/errors. +pub fn collect_errors(results: Vec>) -> CompilationResult> { + let mut artifacts = Vec::new(); + let mut warnings = Vec::new(); + let mut errors = Vec::new(); + + for result in results { + match result { + Ok((new_artifact, new_warnings)) => { + artifacts.push(new_artifact); + warnings.extend(new_warnings); + } + Err(new_errors) => errors.extend(new_errors), + } + } + + if errors.is_empty() { + Ok((artifacts, warnings)) + } else { + Err(errors) + } +} + +pub fn report_errors( result: CompilationResult, file_manager: &FileManager, deny_warnings: bool, diff --git a/tooling/nargo/src/ops/execute.rs b/tooling/nargo/src/ops/execute.rs index 370393fea09..6d328d65119 100644 --- a/tooling/nargo/src/ops/execute.rs +++ b/tooling/nargo/src/ops/execute.rs @@ -1,5 +1,7 @@ +use acvm::acir::circuit::Program; +use acvm::acir::native_types::WitnessStack; use acvm::brillig_vm::brillig::ForeignCallResult; -use acvm::pwg::{ACVMStatus, ErrorLocation, OpcodeResolutionError, ACVM}; +use acvm::pwg::{ACVMStatus, ErrorLocation, OpcodeNotSolvable, OpcodeResolutionError, ACVM}; use acvm::BlackBoxFunctionSolver; use acvm::{acir::circuit::Circuit, acir::native_types::WitnessMap}; @@ -8,73 +10,145 @@ use crate::NargoError; use super::foreign_calls::{ForeignCallExecutor, NargoForeignCallResult}; -#[tracing::instrument(level = "trace", skip_all)] -pub fn execute_circuit( - circuit: &Circuit, - initial_witness: WitnessMap, - blackbox_solver: &B, - foreign_call_executor: &mut F, -) -> Result { - let mut acvm = ACVM::new(blackbox_solver, &circuit.opcodes, initial_witness); - - // This message should be resolved by a nargo foreign call only when we have an unsatisfied assertion. - let mut assert_message: Option = None; - loop { - let solver_status = acvm.solve(); - - match solver_status { - ACVMStatus::Solved => break, - ACVMStatus::InProgress => { - unreachable!("Execution should not stop while in `InProgress` state.") - } - ACVMStatus::Failure(error) => { - let call_stack = match &error { - OpcodeResolutionError::UnsatisfiedConstrain { - opcode_location: ErrorLocation::Resolved(opcode_location), - } => Some(vec![*opcode_location]), - OpcodeResolutionError::BrilligFunctionFailed { call_stack, .. } => { - Some(call_stack.clone()) - } - _ => None, - }; - - return Err(NargoError::ExecutionError(match call_stack { - Some(call_stack) => { - // First check whether we have a runtime assertion message that should be resolved on an ACVM failure - // If we do not have a runtime assertion message, we should check whether the circuit has any hardcoded - // messages associated with a specific `OpcodeLocation`. - // Otherwise return the provided opcode resolution error. - if let Some(assert_message) = assert_message { - ExecutionError::AssertionFailed(assert_message.to_owned(), call_stack) - } else if let Some(assert_message) = circuit.get_assert_message( - *call_stack.last().expect("Call stacks should not be empty"), - ) { - ExecutionError::AssertionFailed(assert_message.to_owned(), call_stack) - } else { - ExecutionError::SolvingError(error) +struct ProgramExecutor<'a, B: BlackBoxFunctionSolver, F: ForeignCallExecutor> { + functions: &'a [Circuit], + // This gets built as we run through the program looking at each function call + witness_stack: WitnessStack, + + blackbox_solver: &'a B, + + foreign_call_executor: &'a mut F, +} + +impl<'a, B: BlackBoxFunctionSolver, F: ForeignCallExecutor> ProgramExecutor<'a, B, F> { + fn new( + functions: &'a [Circuit], + blackbox_solver: &'a B, + foreign_call_executor: &'a mut F, + ) -> Self { + ProgramExecutor { + functions, + witness_stack: WitnessStack::default(), + blackbox_solver, + foreign_call_executor, + } + } + + fn finalize(self) -> WitnessStack { + self.witness_stack + } + + #[tracing::instrument(level = "trace", skip_all)] + fn execute_circuit( + &mut self, + circuit: &Circuit, + initial_witness: WitnessMap, + ) -> Result { + let mut acvm = ACVM::new(self.blackbox_solver, &circuit.opcodes, initial_witness); + + // This message should be resolved by a nargo foreign call only when we have an unsatisfied assertion. + let mut assert_message: Option = None; + loop { + let solver_status = acvm.solve(); + + match solver_status { + ACVMStatus::Solved => break, + ACVMStatus::InProgress => { + unreachable!("Execution should not stop while in `InProgress` state.") + } + ACVMStatus::Failure(error) => { + let call_stack = match &error { + OpcodeResolutionError::UnsatisfiedConstrain { + opcode_location: ErrorLocation::Resolved(opcode_location), + } => Some(vec![*opcode_location]), + OpcodeResolutionError::BrilligFunctionFailed { call_stack, .. } => { + Some(call_stack.clone()) } - } - None => ExecutionError::SolvingError(error), - })); - } - ACVMStatus::RequiresForeignCall(foreign_call) => { - let foreign_call_result = foreign_call_executor.execute(&foreign_call)?; - match foreign_call_result { - NargoForeignCallResult::BrilligOutput(foreign_call_result) => { - acvm.resolve_pending_foreign_call(foreign_call_result); - } - NargoForeignCallResult::ResolvedAssertMessage(message) => { - if assert_message.is_some() { - unreachable!("Resolving an assert message should happen only once as the VM should have failed"); + _ => None, + }; + + return Err(NargoError::ExecutionError(match call_stack { + Some(call_stack) => { + // First check whether we have a runtime assertion message that should be resolved on an ACVM failure + // If we do not have a runtime assertion message, we should check whether the circuit has any hardcoded + // messages associated with a specific `OpcodeLocation`. + // Otherwise return the provided opcode resolution error. + if let Some(assert_message) = assert_message { + ExecutionError::AssertionFailed( + assert_message.to_owned(), + call_stack, + ) + } else if let Some(assert_message) = circuit.get_assert_message( + *call_stack.last().expect("Call stacks should not be empty"), + ) { + ExecutionError::AssertionFailed( + assert_message.to_owned(), + call_stack, + ) + } else { + ExecutionError::SolvingError(error) + } + } + None => ExecutionError::SolvingError(error), + })); + } + ACVMStatus::RequiresForeignCall(foreign_call) => { + let foreign_call_result = self.foreign_call_executor.execute(&foreign_call)?; + match foreign_call_result { + NargoForeignCallResult::BrilligOutput(foreign_call_result) => { + acvm.resolve_pending_foreign_call(foreign_call_result); } - assert_message = Some(message); + NargoForeignCallResult::ResolvedAssertMessage(message) => { + if assert_message.is_some() { + unreachable!("Resolving an assert message should happen only once as the VM should have failed"); + } + assert_message = Some(message); - acvm.resolve_pending_foreign_call(ForeignCallResult::default()); + acvm.resolve_pending_foreign_call(ForeignCallResult::default()); + } } } + ACVMStatus::RequiresAcirCall(call_info) => { + let acir_to_call = &self.functions[call_info.id as usize]; + let initial_witness = call_info.initial_witness; + let call_solved_witness = + self.execute_circuit(acir_to_call, initial_witness)?; + let mut call_resolved_outputs = Vec::new(); + for return_witness_index in acir_to_call.return_values.indices() { + if let Some(return_value) = + call_solved_witness.get_index(return_witness_index) + { + call_resolved_outputs.push(*return_value); + } else { + return Err(ExecutionError::SolvingError( + OpcodeNotSolvable::MissingAssignment(return_witness_index).into(), + ) + .into()); + } + } + acvm.resolve_pending_acir_call(call_resolved_outputs); + self.witness_stack.push(call_info.id, call_solved_witness); + } } } + + Ok(acvm.finalize()) } +} + +#[tracing::instrument(level = "trace", skip_all)] +pub fn execute_program( + program: &Program, + initial_witness: WitnessMap, + blackbox_solver: &B, + foreign_call_executor: &mut F, +) -> Result { + let main = &program.functions[0]; + + let mut executor = + ProgramExecutor::new(&program.functions, blackbox_solver, foreign_call_executor); + let main_witness = executor.execute_circuit(main, initial_witness)?; + executor.witness_stack.push(0, main_witness); - Ok(acvm.finalize()) + Ok(executor.finalize()) } diff --git a/tooling/nargo/src/ops/foreign_calls.rs b/tooling/nargo/src/ops/foreign_calls.rs index f7f36c65c90..ea67f17af2a 100644 --- a/tooling/nargo/src/ops/foreign_calls.rs +++ b/tooling/nargo/src/ops/foreign_calls.rs @@ -1,6 +1,7 @@ use acvm::{ - acir::brillig::{ForeignCallParam, ForeignCallResult, Value}, + acir::brillig::{ForeignCallParam, ForeignCallResult}, pwg::ForeignCallWaitInfo, + FieldElement, }; use jsonrpc::{arg as build_json_rpc_arg, minreq_http::Builder, Client}; use noirc_printable_type::{decode_string_value, ForeignCallError, PrintableValueDisplay}; @@ -46,15 +47,15 @@ impl From for NargoForeignCallResult { } } -impl From for NargoForeignCallResult { - fn from(value: Value) -> Self { +impl From for NargoForeignCallResult { + fn from(value: FieldElement) -> Self { let foreign_call_result: ForeignCallResult = value.into(); foreign_call_result.into() } } -impl From> for NargoForeignCallResult { - fn from(values: Vec) -> Self { +impl From> for NargoForeignCallResult { + fn from(values: Vec) -> Self { let foreign_call_result: ForeignCallResult = values.into(); foreign_call_result.into() } @@ -178,7 +179,10 @@ impl DefaultForeignCallExecutor { ) -> Result<(usize, &[ForeignCallParam]), ForeignCallError> { let (id, params) = foreign_call_inputs.split_first().ok_or(ForeignCallError::MissingForeignCallInputs)?; - Ok((id.unwrap_value().to_usize(), params)) + let id = + usize::try_from(id.unwrap_field().try_to_u64().expect("value does not fit into u64")) + .expect("value does not fit into usize"); + Ok((id, params)) } fn find_mock_by_id(&mut self, id: usize) -> Option<&mut MockedCall> { @@ -186,12 +190,12 @@ impl DefaultForeignCallExecutor { } fn parse_string(param: &ForeignCallParam) -> String { - let fields: Vec<_> = param.values().into_iter().map(|value| value.to_field()).collect(); + let fields: Vec<_> = param.fields().to_vec(); decode_string_value(&fields) } fn execute_print(foreign_call_inputs: &[ForeignCallParam]) -> Result<(), ForeignCallError> { - let skip_newline = foreign_call_inputs[0].unwrap_value().is_zero(); + let skip_newline = foreign_call_inputs[0].unwrap_field().is_zero(); let foreign_call_inputs = foreign_call_inputs.split_first().ok_or(ForeignCallError::MissingForeignCallInputs)?.1; @@ -242,7 +246,7 @@ impl ForeignCallExecutor for DefaultForeignCallExecutor { self.mocked_responses.push(MockedCall::new(id, mock_oracle_name)); self.last_mock_id += 1; - Ok(Value::from(id).into()) + Ok(FieldElement::from(id).into()) } Some(ForeignCall::SetMockParams) => { let (id, params) = Self::extract_mock_id(&foreign_call.inputs)?; @@ -262,11 +266,8 @@ impl ForeignCallExecutor for DefaultForeignCallExecutor { } Some(ForeignCall::SetMockTimes) => { let (id, params) = Self::extract_mock_id(&foreign_call.inputs)?; - let times = params[0] - .unwrap_value() - .to_field() - .try_to_u64() - .expect("Invalid bit size of times"); + let times = + params[0].unwrap_field().try_to_u64().expect("Invalid bit size of times"); self.find_mock_by_id(id) .unwrap_or_else(|| panic!("Unknown mock id {}", id)) @@ -325,10 +326,8 @@ impl ForeignCallExecutor for DefaultForeignCallExecutor { #[cfg(test)] mod tests { use acvm::{ - acir::brillig::ForeignCallParam, - brillig_vm::brillig::{ForeignCallResult, Value}, - pwg::ForeignCallWaitInfo, - FieldElement, + acir::brillig::ForeignCallParam, brillig_vm::brillig::ForeignCallResult, + pwg::ForeignCallWaitInfo, FieldElement, }; use jsonrpc_core::Result as RpcResult; use jsonrpc_derive::rpc; @@ -356,11 +355,11 @@ mod tests { fn sum(&self, array: ForeignCallParam) -> RpcResult { let mut res: FieldElement = 0_usize.into(); - for value in array.values() { - res += value.to_field(); + for value in array.fields() { + res += value; } - Ok(Value::from(res).into()) + Ok(res.into()) } } @@ -406,7 +405,7 @@ mod tests { }; let result = executor.execute(&foreign_call); - assert_eq!(result.unwrap(), Value::from(3_usize).into()); + assert_eq!(result.unwrap(), FieldElement::from(3_usize).into()); server.close(); } diff --git a/tooling/nargo/src/ops/mod.rs b/tooling/nargo/src/ops/mod.rs index 23dd0db15b9..2f5e6ebb7d4 100644 --- a/tooling/nargo/src/ops/mod.rs +++ b/tooling/nargo/src/ops/mod.rs @@ -1,7 +1,8 @@ pub use self::compile::{ - compile_contract, compile_program, compile_program_with_debug_instrumenter, compile_workspace, + collect_errors, compile_contract, compile_program, compile_program_with_debug_instrumenter, + compile_workspace, report_errors, }; -pub use self::execute::execute_circuit; +pub use self::execute::execute_program; pub use self::foreign_calls::{ DefaultForeignCallExecutor, ForeignCall, ForeignCallExecutor, NargoForeignCallResult, }; diff --git a/tooling/nargo/src/ops/optimize.rs b/tooling/nargo/src/ops/optimize.rs index 2d0c4c43d25..cfaaf27ea98 100644 --- a/tooling/nargo/src/ops/optimize.rs +++ b/tooling/nargo/src/ops/optimize.rs @@ -1,17 +1,22 @@ use iter_extended::vecmap; use noirc_driver::{CompiledContract, CompiledProgram}; -pub fn optimize_program(mut program: CompiledProgram) -> CompiledProgram { - let (optimized_circuit, location_map) = acvm::compiler::optimize(program.circuit); - program.circuit = optimized_circuit; - program.debug.update_acir(location_map); - program +/// TODO(https://github.com/noir-lang/noir/issues/4428): Need to update how these passes are run to account for +/// multiple ACIR functions + +pub fn optimize_program(mut compiled_program: CompiledProgram) -> CompiledProgram { + let (optimized_circuit, location_map) = + acvm::compiler::optimize(std::mem::take(&mut compiled_program.program.functions[0])); + compiled_program.program.functions[0] = optimized_circuit; + compiled_program.debug.update_acir(location_map); + compiled_program } pub fn optimize_contract(contract: CompiledContract) -> CompiledContract { let functions = vecmap(contract.functions, |mut func| { - let (optimized_bytecode, location_map) = acvm::compiler::optimize(func.bytecode); - func.bytecode = optimized_bytecode; + let (optimized_bytecode, location_map) = + acvm::compiler::optimize(std::mem::take(&mut func.bytecode.functions[0])); + func.bytecode.functions[0] = optimized_bytecode; func.debug.update_acir(location_map); func }); diff --git a/tooling/nargo/src/ops/test.rs b/tooling/nargo/src/ops/test.rs index 92c09ec889e..45b1a88f99c 100644 --- a/tooling/nargo/src/ops/test.rs +++ b/tooling/nargo/src/ops/test.rs @@ -1,4 +1,7 @@ -use acvm::{acir::native_types::WitnessMap, BlackBoxFunctionSolver}; +use acvm::{ + acir::native_types::{WitnessMap, WitnessStack}, + BlackBoxFunctionSolver, +}; use noirc_driver::{compile_no_check, CompileError, CompileOptions}; use noirc_errors::{debug_info::DebugInfo, FileDiagnostic}; use noirc_evaluator::errors::RuntimeError; @@ -6,7 +9,7 @@ use noirc_frontend::hir::{def_map::TestFunction, Context}; use crate::{errors::try_to_diagnose_runtime_error, NargoError}; -use super::{execute_circuit, DefaultForeignCallExecutor}; +use super::{execute_program, DefaultForeignCallExecutor}; pub enum TestStatus { Pass, @@ -14,26 +17,36 @@ pub enum TestStatus { CompileError(FileDiagnostic), } +impl TestStatus { + pub fn failed(&self) -> bool { + !matches!(self, TestStatus::Pass) + } +} + pub fn run_test( blackbox_solver: &B, context: &mut Context, - test_function: TestFunction, + test_function: &TestFunction, show_output: bool, foreign_call_resolver_url: Option<&str>, config: &CompileOptions, ) -> TestStatus { - let program = compile_no_check(context, config, test_function.get_id(), None, false); - match program { - Ok(program) => { + let compiled_program = compile_no_check(context, config, test_function.get_id(), None, false); + match compiled_program { + Ok(compiled_program) => { // Run the backend to ensure the PWG evaluates functions like std::hash::pedersen, // otherwise constraints involving these expressions will not error. - let circuit_execution = execute_circuit( - &program.circuit, + let circuit_execution = execute_program( + &compiled_program.program, WitnessMap::new(), blackbox_solver, &mut DefaultForeignCallExecutor::new(show_output, foreign_call_resolver_url), ); - test_status_program_compile_pass(test_function, program.debug, circuit_execution) + test_status_program_compile_pass( + test_function, + compiled_program.debug, + circuit_execution, + ) } Err(err) => test_status_program_compile_fail(err, test_function), } @@ -45,7 +58,7 @@ pub fn run_test( /// that a constraint was never satisfiable. /// An example of this is the program `assert(false)` /// In that case, we check if the test function should fail, and if so, we return `TestStatus::Pass`. -fn test_status_program_compile_fail(err: CompileError, test_function: TestFunction) -> TestStatus { +fn test_status_program_compile_fail(err: CompileError, test_function: &TestFunction) -> TestStatus { // The test has failed compilation, but it should never fail. Report error. if !test_function.should_fail() { return TestStatus::CompileError(err.into()); @@ -70,9 +83,9 @@ fn test_status_program_compile_fail(err: CompileError, test_function: TestFuncti /// We now check whether execution passed/failed and whether it should have /// passed/failed to determine the test status. fn test_status_program_compile_pass( - test_function: TestFunction, + test_function: &TestFunction, debug: DebugInfo, - circuit_execution: Result, + circuit_execution: Result, ) -> TestStatus { let circuit_execution_err = match circuit_execution { // Circuit execution was successful; ie no errors or unsatisfied constraints @@ -109,7 +122,7 @@ fn test_status_program_compile_pass( } fn check_expected_failure_message( - test_function: TestFunction, + test_function: &TestFunction, failed_assertion: Option, error_diagnostic: Option, ) -> TestStatus { diff --git a/tooling/nargo/src/ops/transform.rs b/tooling/nargo/src/ops/transform.rs index 9267ed7e045..274286a46e4 100644 --- a/tooling/nargo/src/ops/transform.rs +++ b/tooling/nargo/src/ops/transform.rs @@ -2,16 +2,21 @@ use acvm::acir::circuit::ExpressionWidth; use iter_extended::vecmap; use noirc_driver::{CompiledContract, CompiledProgram}; +/// TODO(https://github.com/noir-lang/noir/issues/4428): Need to update how these passes are run to account for +/// multiple ACIR functions + pub fn transform_program( - mut program: CompiledProgram, + mut compiled_program: CompiledProgram, expression_width: ExpressionWidth, ) -> CompiledProgram { - let (optimized_circuit, location_map) = - acvm::compiler::compile(program.circuit, expression_width); + let (optimized_circuit, location_map) = acvm::compiler::compile( + std::mem::take(&mut compiled_program.program.functions[0]), + expression_width, + ); - program.circuit = optimized_circuit; - program.debug.update_acir(location_map); - program + compiled_program.program.functions[0] = optimized_circuit; + compiled_program.debug.update_acir(location_map); + compiled_program } pub fn transform_contract( @@ -19,9 +24,11 @@ pub fn transform_contract( expression_width: ExpressionWidth, ) -> CompiledContract { let functions = vecmap(contract.functions, |mut func| { - let (optimized_bytecode, location_map) = - acvm::compiler::compile(func.bytecode, expression_width); - func.bytecode = optimized_bytecode; + let (optimized_bytecode, location_map) = acvm::compiler::compile( + std::mem::take(&mut func.bytecode.functions[0]), + expression_width, + ); + func.bytecode.functions[0] = optimized_bytecode; func.debug.update_acir(location_map); func }); diff --git a/tooling/nargo_cli/Cargo.toml b/tooling/nargo_cli/Cargo.toml index 57edbf5ae04..1629ae86edb 100644 --- a/tooling/nargo_cli/Cargo.toml +++ b/tooling/nargo_cli/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "nargo_cli" description = "Noir's package manager" +default-run = "nargo" version.workspace = true authors.workspace = true edition.workspace = true @@ -50,6 +51,10 @@ tokio = { version = "1.0", features = ["io-std"] } dap.workspace = true clap-markdown = { git = "https://github.com/noir-lang/clap-markdown", rev = "450d759532c88f0dba70891ceecdbc9ff8f25d2b", optional = true } +notify = "6.1.1" +notify-debouncer-full = "0.3.1" +termion = "3.0.0" + # Backends backend-interface = { path = "../backend_interface" } @@ -86,4 +91,4 @@ name = "iai" harness = false [features] -codegen-docs = ["dep:clap-markdown"] \ No newline at end of file +codegen-docs = ["dep:clap-markdown"] diff --git a/tooling/nargo_cli/benches/criterion.rs b/tooling/nargo_cli/benches/criterion.rs index a7b094fd7aa..9f67bcffd6e 100644 --- a/tooling/nargo_cli/benches/criterion.rs +++ b/tooling/nargo_cli/benches/criterion.rs @@ -1,9 +1,10 @@ //! Select representative tests to bench with criterion use assert_cmd::prelude::{CommandCargoExt, OutputAssertExt}; use criterion::{criterion_group, criterion_main, Criterion}; + use paste::paste; use pprof::criterion::{Output, PProfProfiler}; -use std::process::Command; +use std::{process::Command, time::Duration}; include!("./utils.rs"); macro_rules! criterion_command { @@ -15,9 +16,11 @@ macro_rules! criterion_command { let mut cmd = Command::cargo_bin("nargo").unwrap(); cmd.arg("--program-dir").arg(&test_program_dir); cmd.arg($command_string); + cmd.arg("--force"); - c.bench_function(&format!("{}_{}", test_program_dir.file_name().unwrap().to_str().unwrap(), $command_string), |b| { - b.iter(|| cmd.assert()) + let benchmark_name = format!("{}_{}", test_program_dir.file_name().unwrap().to_str().unwrap(), $command_string); + c.bench_function(&benchmark_name, |b| { + b.iter(|| cmd.assert().success()) }); } } @@ -25,9 +28,16 @@ macro_rules! criterion_command { }; } criterion_command!(execution, "execute"); +criterion_command!(prove, "prove"); + +criterion_group! { + name = execution_benches; + config = Criterion::default().sample_size(20).measurement_time(Duration::from_secs(20)).with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); + targets = criterion_selected_tests_execution +} criterion_group! { - name = benches; - config = Criterion::default().sample_size(20).with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); - targets = criterion_selected_tests_execution + name = prove_benches; + config = Criterion::default().sample_size(10).measurement_time(Duration::from_secs(20)).with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); + targets = criterion_selected_tests_prove } -criterion_main!(benches); +criterion_main!(execution_benches, prove_benches); diff --git a/tooling/nargo_cli/benches/utils.rs b/tooling/nargo_cli/benches/utils.rs index 52a6b718c44..47968f7e898 100644 --- a/tooling/nargo_cli/benches/utils.rs +++ b/tooling/nargo_cli/benches/utils.rs @@ -4,11 +4,16 @@ use std::path::PathBuf; fn get_selected_tests() -> Vec { let manifest_dir = match std::env::var("CARGO_MANIFEST_DIR") { Ok(dir) => PathBuf::from(dir), - Err(_) => std::env::current_dir().unwrap().join("crates").join("nargo_cli"), + Err(_) => std::env::current_dir().unwrap(), }; - let test_dir = manifest_dir.join("tests").join("execution_success"); + let test_dir = manifest_dir + .parent() + .unwrap() + .parent() + .unwrap() + .join("test_programs") + .join("execution_success"); - let selected_tests = - vec!["8_integration", "sha256_blocks", "struct", "eddsa", "regression", "regression_2099"]; + let selected_tests = vec!["struct", "eddsa", "regression"]; selected_tests.into_iter().map(|t| test_dir.join(t)).collect() } diff --git a/tooling/nargo_cli/build.rs b/tooling/nargo_cli/build.rs index 1ca12b75dfb..bf97dfb3e96 100644 --- a/tooling/nargo_cli/build.rs +++ b/tooling/nargo_cli/build.rs @@ -16,8 +16,7 @@ const GIT_COMMIT: &&str = &"GIT_COMMIT"; fn main() { check_rustc_version(); - // Only use build_data if the environment variable isn't set - // The environment variable is always set when working via Nix + // Only use build_data if the environment variable isn't set. if std::env::var(GIT_COMMIT).is_err() { build_data::set_GIT_COMMIT(); build_data::set_GIT_DIRTY(); @@ -41,6 +40,7 @@ fn main() { println!("cargo:rerun-if-changed={}", test_dir.as_os_str().to_str().unwrap()); generate_execution_success_tests(&mut test_file, &test_dir); + generate_execution_failure_tests(&mut test_file, &test_dir); generate_noir_test_success_tests(&mut test_file, &test_dir); generate_noir_test_failure_tests(&mut test_file, &test_dir); generate_compile_success_empty_tests(&mut test_file, &test_dir); @@ -86,6 +86,44 @@ fn execution_success_{test_name}() {{ } } +fn generate_execution_failure_tests(test_file: &mut File, test_data_dir: &Path) { + let test_sub_dir = "execution_failure"; + let test_data_dir = test_data_dir.join(test_sub_dir); + + let test_case_dirs = + fs::read_dir(test_data_dir).unwrap().flatten().filter(|c| c.path().is_dir()); + + for test_dir in test_case_dirs { + let test_name = + test_dir.file_name().into_string().expect("Directory can't be converted to string"); + if test_name.contains('-') { + panic!( + "Invalid test directory: {test_name}. Cannot include `-`, please convert to `_`" + ); + }; + let test_dir = &test_dir.path(); + + write!( + test_file, + r#" +#[test] +fn execution_failure_{test_name}() {{ + let test_program_dir = PathBuf::from("{test_dir}"); + + let mut cmd = Command::cargo_bin("nargo").unwrap(); + cmd.env("NARGO_BACKEND_PATH", path_to_mock_backend()); + cmd.arg("--program-dir").arg(test_program_dir); + cmd.arg("execute").arg("--force"); + + cmd.assert().failure().stderr(predicate::str::contains("The application panicked (crashed).").not()); +}} + "#, + test_dir = test_dir.display(), + ) + .expect("Could not write templated test file."); + } +} + fn generate_noir_test_success_tests(test_file: &mut File, test_data_dir: &Path) { let test_sub_dir = "noir_test_success"; let test_data_dir = test_data_dir.join(test_sub_dir); @@ -203,10 +241,10 @@ fn compile_success_empty_{test_name}() {{ }} // `compile_success_empty` tests should be able to compile down to an empty circuit. - let json: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap_or_else(|_| {{ - panic!("JSON was not well-formatted {{:?}}",output.stdout) + let json: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap_or_else(|e| {{ + panic!("JSON was not well-formatted {{:?}}\n\n{{:?}}", e, std::str::from_utf8(&output.stdout)) }}); - let num_opcodes = &json["programs"][0]["acir_opcodes"]; + let num_opcodes = &json["programs"][0]["functions"][0]["acir_opcodes"]; assert_eq!(num_opcodes.as_u64().expect("number of opcodes should fit in a u64"), 0); }} "#, @@ -281,7 +319,7 @@ fn compile_failure_{test_name}() {{ let mut cmd = Command::cargo_bin("nargo").unwrap(); cmd.env("NARGO_BACKEND_PATH", path_to_mock_backend()); cmd.arg("--program-dir").arg(test_program_dir); - cmd.arg("execute").arg("--force"); + cmd.arg("compile").arg("--force"); cmd.assert().failure().stderr(predicate::str::contains("The application panicked (crashed).").not()); }} diff --git a/tooling/nargo_cli/src/cli/check_cmd.rs b/tooling/nargo_cli/src/cli/check_cmd.rs index 4da06d2536a..2b729e44b8a 100644 --- a/tooling/nargo_cli/src/cli/check_cmd.rs +++ b/tooling/nargo_cli/src/cli/check_cmd.rs @@ -5,8 +5,8 @@ use clap::Args; use fm::FileManager; use iter_extended::btree_map; use nargo::{ - errors::CompileError, insert_all_files_for_workspace_into_file_manager, package::Package, - parse_all, prepare_package, + errors::CompileError, insert_all_files_for_workspace_into_file_manager, ops::report_errors, + package::Package, parse_all, prepare_package, }; use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_abi::{AbiParameter, AbiType, MAIN_RETURN_NAME}; @@ -24,6 +24,7 @@ use super::NargoConfig; /// Checks the constraint system for errors #[derive(Debug, Clone, Args)] +#[clap(visible_alias = "c")] pub(crate) struct CheckCommand { /// The name of the package to check #[clap(long, conflicts_with = "workspace")] @@ -33,6 +34,10 @@ pub(crate) struct CheckCommand { #[clap(long, conflicts_with = "package")] workspace: bool, + /// Force overwrite of existing files + #[clap(long = "overwrite")] + allow_overwrite: bool, + #[clap(flatten)] compile_options: CompileOptions, } @@ -57,18 +62,29 @@ pub(crate) fn run( let parsed_files = parse_all(&workspace_file_manager); for package in &workspace { - check_package(&workspace_file_manager, &parsed_files, package, &args.compile_options)?; - println!("[{}] Constraint system successfully built!", package.name); + let any_file_written = check_package( + &workspace_file_manager, + &parsed_files, + package, + &args.compile_options, + args.allow_overwrite, + )?; + if any_file_written { + println!("[{}] Constraint system successfully built!", package.name); + } } Ok(()) } +/// Evaluates the necessity to create or update Prover.toml and Verifier.toml based on the allow_overwrite flag and files' existence. +/// Returns `true` if any file was generated or updated, `false` otherwise. fn check_package( file_manager: &FileManager, parsed_files: &ParsedFiles, package: &Package, compile_options: &CompileOptions, -) -> Result<(), CompileError> { + allow_overwrite: bool, +) -> Result { let (mut context, crate_id) = prepare_package(file_manager, parsed_files, package); check_crate_and_report_errors( &mut context, @@ -80,27 +96,39 @@ fn check_package( if package.is_library() || package.is_contract() { // Libraries do not have ABIs while contracts have many, so we cannot generate a `Prover.toml` file. - Ok(()) + Ok(false) } else { // XXX: We can have a --overwrite flag to determine if you want to overwrite the Prover/Verifier.toml files if let Some((parameters, return_type)) = compute_function_abi(&context, &crate_id) { let path_to_prover_input = package.prover_input_path(); let path_to_verifier_input = package.verifier_input_path(); - // If they are not available, then create them and populate them based on the ABI - if !path_to_prover_input.exists() { + // Before writing the file, check if it exists and whether overwrite is set + let should_write_prover = !path_to_prover_input.exists() || allow_overwrite; + let should_write_verifier = !path_to_verifier_input.exists() || allow_overwrite; + + if should_write_prover { let prover_toml = create_input_toml_template(parameters.clone(), None); write_to_file(prover_toml.as_bytes(), &path_to_prover_input); + } else { + eprintln!("Note: Prover.toml already exists. Use --overwrite to force overwrite."); } - if !path_to_verifier_input.exists() { + + if should_write_verifier { let public_inputs = parameters.into_iter().filter(|param| param.is_public()).collect(); let verifier_toml = create_input_toml_template(public_inputs, return_type); write_to_file(verifier_toml.as_bytes(), &path_to_verifier_input); + } else { + eprintln!( + "Note: Verifier.toml already exists. Use --overwrite to force overwrite." + ); } - Ok(()) + let any_file_written = should_write_prover || should_write_verifier; + + Ok(any_file_written) } else { Err(CompileError::MissingMainFunction(package.name.clone())) } @@ -152,12 +180,7 @@ pub(crate) fn check_crate_and_report_errors( silence_warnings: bool, ) -> Result<(), CompileError> { let result = check_crate(context, crate_id, deny_warnings, disable_macros); - super::compile_cmd::report_errors( - result, - &context.file_manager, - deny_warnings, - silence_warnings, - ) + report_errors(result, &context.file_manager, deny_warnings, silence_warnings) } #[cfg(test)] diff --git a/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs b/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs index 63d27e30836..259e209b65a 100644 --- a/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs +++ b/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs @@ -1,11 +1,10 @@ use super::fs::{create_named_dir, write_to_file}; use super::NargoConfig; use crate::backends::Backend; -use crate::cli::compile_cmd::report_errors; use crate::errors::CliError; use clap::Args; -use nargo::ops::compile_program; +use nargo::ops::{compile_program, report_errors}; use nargo::{insert_all_files_for_workspace_into_file_manager, parse_all}; use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_driver::{file_manager_with_stdlib, CompileOptions, NOIR_ARTIFACT_VERSION_STRING}; @@ -65,7 +64,13 @@ pub(crate) fn run( let program = nargo::ops::transform_program(program, expression_width); - let smart_contract_string = backend.eth_contract(&program.circuit)?; + // TODO(https://github.com/noir-lang/noir/issues/4428): + // We do not expect to have a smart contract verifier for a foldable program with multiple circuits. + // However, in the future we can expect to possibly have non-inlined ACIR functions during compilation + // that will be inlined at a later step such as by the ACVM compiler or by the backend. + // Add appropriate handling here once the compiler enables multiple ACIR functions. + assert_eq!(program.program.functions.len(), 1); + let smart_contract_string = backend.eth_contract(&program.program)?; let contract_dir = workspace.contracts_directory_path(package); create_named_dir(&contract_dir, "contract"); diff --git a/tooling/nargo_cli/src/cli/compile_cmd.rs b/tooling/nargo_cli/src/cli/compile_cmd.rs index 34fb05249b5..54e8535f094 100644 --- a/tooling/nargo_cli/src/cli/compile_cmd.rs +++ b/tooling/nargo_cli/src/cli/compile_cmd.rs @@ -1,9 +1,10 @@ +use std::io::Write; use std::path::Path; +use std::time::Duration; use fm::FileManager; use nargo::artifacts::program::ProgramArtifact; -use nargo::errors::CompileError; -use nargo::ops::{compile_contract, compile_program}; +use nargo::ops::{collect_errors, compile_contract, compile_program, report_errors}; use nargo::package::Package; use nargo::workspace::Workspace; use nargo::{insert_all_files_for_workspace_into_file_manager, parse_all}; @@ -16,6 +17,8 @@ use noirc_frontend::graph::CrateName; use clap::Args; use noirc_frontend::hir::ParsedFiles; +use notify::{EventKind, RecursiveMode, Watcher}; +use notify_debouncer_full::new_debouncer; use crate::backends::Backend; use crate::errors::CliError; @@ -32,17 +35,21 @@ pub(crate) struct CompileCommand { #[clap(long, conflicts_with = "workspace")] package: Option, - /// Compile all packages in the workspace + /// Compile all packages in the workspace. #[clap(long, conflicts_with = "package")] workspace: bool, #[clap(flatten)] compile_options: CompileOptions, + + /// Watch workspace and recompile on changes. + #[clap(long, hide = true)] + watch: bool, } pub(crate) fn run( backend: &Backend, - args: CompileCommand, + mut args: CompileCommand, config: NargoConfig, ) -> Result<(), CliError> { let toml_path = get_package_manifest(&config.program_dir)?; @@ -55,21 +62,82 @@ pub(crate) fn run( selection, Some(NOIR_ARTIFACT_VERSION_STRING.to_owned()), )?; - let circuit_dir = workspace.target_directory_path(); + if args.compile_options.expression_width.is_none() { + args.compile_options.expression_width = Some(backend.get_backend_info_or_default()); + }; + + if args.watch { + watch_workspace(&workspace, &args.compile_options) + .map_err(|err| CliError::Generic(err.to_string()))?; + } else { + compile_workspace_full(&workspace, &args.compile_options)?; + } + + Ok(()) +} + +fn watch_workspace(workspace: &Workspace, compile_options: &CompileOptions) -> notify::Result<()> { + let (tx, rx) = std::sync::mpsc::channel(); + + // No specific tickrate, max debounce time 1 seconds + let mut debouncer = new_debouncer(Duration::from_secs(1), None, tx)?; + + // Add a path to be watched. All files and directories at that path and + // below will be monitored for changes. + debouncer.watcher().watch(&workspace.root_dir, RecursiveMode::Recursive)?; + + let mut screen = std::io::stdout(); + write!(screen, "{}", termion::cursor::Save).unwrap(); + screen.flush().unwrap(); + let _ = compile_workspace_full(workspace, compile_options); + for res in rx { + let debounced_events = res.map_err(|mut err| err.remove(0))?; + + // We only want to trigger a rebuild if a noir source file has been modified. + let noir_files_modified = debounced_events.iter().any(|event| { + let mut event_paths = event.event.paths.iter(); + let event_affects_noir_file = + event_paths.any(|path| path.extension().map_or(false, |ext| ext == "nr")); + + let is_relevant_event_kind = matches!( + event.kind, + EventKind::Create(_) | EventKind::Modify(_) | EventKind::Remove(_) + ); + + is_relevant_event_kind && event_affects_noir_file + }); + + if noir_files_modified { + write!(screen, "{}{}", termion::cursor::Restore, termion::clear::AfterCursor).unwrap(); + screen.flush().unwrap(); + let _ = compile_workspace_full(workspace, compile_options); + } + } + + screen.flush().unwrap(); + + Ok(()) +} + +fn compile_workspace_full( + workspace: &Workspace, + compile_options: &CompileOptions, +) -> Result<(), CliError> { let mut workspace_file_manager = file_manager_with_stdlib(&workspace.root_dir); - insert_all_files_for_workspace_into_file_manager(&workspace, &mut workspace_file_manager); + insert_all_files_for_workspace_into_file_manager(workspace, &mut workspace_file_manager); let parsed_files = parse_all(&workspace_file_manager); - let expression_width = args - .compile_options - .expression_width - .unwrap_or_else(|| backend.get_backend_info_or_default()); - let (compiled_program, compiled_contracts) = compile_workspace( + let expression_width = + compile_options.expression_width.expect("expression width should have been set"); + let compiled_workspace = + compile_workspace(&workspace_file_manager, &parsed_files, workspace, compile_options); + + let (compiled_programs, compiled_contracts) = report_errors( + compiled_workspace, &workspace_file_manager, - &parsed_files, - &workspace, - &args.compile_options, + compile_options.deny_warnings, + compile_options.silence_warnings, )?; let (binary_packages, contract_packages): (Vec<_>, Vec<_>) = workspace @@ -79,11 +147,12 @@ pub(crate) fn run( .partition(|package| package.is_binary()); // Save build artifacts to disk. - let only_acir = args.compile_options.only_acir; - for (package, program) in binary_packages.into_iter().zip(compiled_program) { + let only_acir = compile_options.only_acir; + for (package, program) in binary_packages.into_iter().zip(compiled_programs) { let program = nargo::ops::transform_program(program, expression_width); save_program(program.clone(), &package, &workspace.target_directory_path(), only_acir); } + let circuit_dir = workspace.target_directory_path(); for (package, contract) in contract_packages.into_iter().zip(compiled_contracts) { let contract = nargo::ops::transform_contract(contract, expression_width); save_contract(contract, &package, &circuit_dir); @@ -97,7 +166,7 @@ pub(super) fn compile_workspace( parsed_files: &ParsedFiles, workspace: &Workspace, compile_options: &CompileOptions, -) -> Result<(Vec, Vec), CliError> { +) -> CompilationResult<(Vec, Vec)> { let (binary_packages, contract_packages): (Vec<_>, Vec<_>) = workspace .into_iter() .filter(|package| !package.is_library()) @@ -123,31 +192,20 @@ pub(super) fn compile_workspace( .map(|package| compile_contract(file_manager, parsed_files, package, compile_options)) .collect(); - // Report any warnings/errors which were encountered during compilation. - let compiled_programs: Vec = program_results - .into_iter() - .map(|compilation_result| { - report_errors( - compilation_result, - file_manager, - compile_options.deny_warnings, - compile_options.silence_warnings, - ) - }) - .collect::>()?; - let compiled_contracts: Vec = contract_results - .into_iter() - .map(|compilation_result| { - report_errors( - compilation_result, - file_manager, - compile_options.deny_warnings, - compile_options.silence_warnings, - ) - }) - .collect::>()?; - - Ok((compiled_programs, compiled_contracts)) + // Collate any warnings/errors which were encountered during compilation. + let compiled_programs = collect_errors(program_results); + let compiled_contracts = collect_errors(contract_results); + + match (compiled_programs, compiled_contracts) { + (Ok((programs, program_warnings)), Ok((contracts, contract_warnings))) => { + let warnings = [program_warnings, contract_warnings].concat(); + Ok(((programs, contracts), warnings)) + } + (Err(program_errors), Err(contract_errors)) => { + Err([program_errors, contract_errors].concat()) + } + (Err(errors), _) | (_, Err(errors)) => Err(errors), + } } pub(super) fn save_program( @@ -156,10 +214,10 @@ pub(super) fn save_program( circuit_dir: &Path, only_acir_opt: bool, ) { - let program_artifact = ProgramArtifact::from(program.clone()); if only_acir_opt { - only_acir(&program_artifact, circuit_dir); + only_acir(program.program, circuit_dir); } else { + let program_artifact = ProgramArtifact::from(program.clone()); save_program_to_file(&program_artifact, &package.name, circuit_dir); } } @@ -172,30 +230,3 @@ fn save_contract(contract: CompiledContract, package: &Package, circuit_dir: &Pa circuit_dir, ); } - -/// Helper function for reporting any errors in a `CompilationResult` -/// structure that is commonly used as a return result in this file. -pub(crate) fn report_errors( - result: CompilationResult, - file_manager: &FileManager, - deny_warnings: bool, - silence_warnings: bool, -) -> Result { - let (t, warnings) = result.map_err(|errors| { - noirc_errors::reporter::report_all( - file_manager.as_file_map(), - &errors, - deny_warnings, - silence_warnings, - ) - })?; - - noirc_errors::reporter::report_all( - file_manager.as_file_map(), - &warnings, - deny_warnings, - silence_warnings, - ); - - Ok(t) -} diff --git a/tooling/nargo_cli/src/cli/debug_cmd.rs b/tooling/nargo_cli/src/cli/debug_cmd.rs index 130a07b5c90..4f3e2886b2e 100644 --- a/tooling/nargo_cli/src/cli/debug_cmd.rs +++ b/tooling/nargo_cli/src/cli/debug_cmd.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use acvm::acir::native_types::WitnessMap; +use acvm::acir::native_types::{WitnessMap, WitnessStack}; use bn254_blackbox_solver::Bn254BlackBoxSolver; use clap::Args; @@ -8,7 +8,7 @@ use fm::FileManager; use nargo::artifacts::debug::DebugArtifact; use nargo::constants::PROVER_INPUT_FILE; use nargo::errors::CompileError; -use nargo::ops::{compile_program, compile_program_with_debug_instrumenter}; +use nargo::ops::{compile_program, compile_program_with_debug_instrumenter, report_errors}; use nargo::package::Package; use nargo::workspace::Workspace; use nargo::{insert_all_files_for_workspace_into_file_manager, parse_all}; @@ -22,7 +22,6 @@ use noirc_frontend::debug::DebugInstrumenter; use noirc_frontend::graph::CrateName; use noirc_frontend::hir::ParsedFiles; -use super::compile_cmd::report_errors; use super::fs::{inputs::read_inputs_from_file, witness::save_witness_to_dir}; use super::NargoConfig; use crate::backends::Backend; @@ -188,7 +187,11 @@ fn run_async( } if let Some(witness_name) = witness_name { - let witness_path = save_witness_to_dir(solved_witness, witness_name, target_dir)?; + let witness_path = save_witness_to_dir( + WitnessStack::from(solved_witness), + witness_name, + target_dir, + )?; println!("[{}] Witness saved to {}", package.name, witness_path.display()); } @@ -236,7 +239,7 @@ pub(crate) fn debug_program( noir_debugger::debug_circuit( &blackbox_solver, - &compiled_program.circuit, + &compiled_program.program.functions[0], debug_artifact, initial_witness, ) diff --git a/tooling/nargo_cli/src/cli/execute_cmd.rs b/tooling/nargo_cli/src/cli/execute_cmd.rs index a3fcebab94f..697f6d7c1ea 100644 --- a/tooling/nargo_cli/src/cli/execute_cmd.rs +++ b/tooling/nargo_cli/src/cli/execute_cmd.rs @@ -1,11 +1,11 @@ -use acvm::acir::native_types::WitnessMap; +use acvm::acir::native_types::WitnessStack; use bn254_blackbox_solver::Bn254BlackBoxSolver; use clap::Args; use nargo::artifacts::debug::DebugArtifact; use nargo::constants::PROVER_INPUT_FILE; use nargo::errors::try_to_diagnose_runtime_error; -use nargo::ops::{compile_program, DefaultForeignCallExecutor}; +use nargo::ops::{compile_program, report_errors, DefaultForeignCallExecutor}; use nargo::package::Package; use nargo::{insert_all_files_for_workspace_into_file_manager, parse_all}; use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection}; @@ -19,11 +19,11 @@ use noirc_frontend::graph::CrateName; use super::fs::{inputs::read_inputs_from_file, witness::save_witness_to_dir}; use super::NargoConfig; use crate::backends::Backend; -use crate::cli::compile_cmd::report_errors; use crate::errors::CliError; /// Executes a circuit to calculate its return value #[derive(Debug, Clone, Args)] +#[clap(visible_alias = "e")] pub(crate) struct ExecuteCommand { /// Write the execution witness to named file witness_name: Option, @@ -91,7 +91,7 @@ pub(crate) fn run( let compiled_program = nargo::ops::transform_program(compiled_program, expression_width); - let (return_value, solved_witness) = execute_program_and_decode( + let (return_value, witness_stack) = execute_program_and_decode( compiled_program, package, &args.prover_name, @@ -103,7 +103,7 @@ pub(crate) fn run( println!("[{}] Circuit output: {return_value:?}", package.name); } if let Some(witness_name) = &args.witness_name { - let witness_path = save_witness_to_dir(solved_witness, witness_name, target_dir)?; + let witness_path = save_witness_to_dir(witness_stack, witness_name, target_dir)?; println!("[{}] Witness saved to {}", package.name, witness_path.display()); } @@ -116,34 +116,37 @@ fn execute_program_and_decode( package: &Package, prover_name: &str, foreign_call_resolver_url: Option<&str>, -) -> Result<(Option, WitnessMap), CliError> { +) -> Result<(Option, WitnessStack), CliError> { // Parse the initial witness values from Prover.toml let (inputs_map, _) = read_inputs_from_file(&package.root_dir, prover_name, Format::Toml, &program.abi)?; - let solved_witness = execute_program(&program, &inputs_map, foreign_call_resolver_url)?; + let witness_stack = execute_program(&program, &inputs_map, foreign_call_resolver_url)?; let public_abi = program.abi.public_abi(); - let (_, return_value) = public_abi.decode(&solved_witness)?; + // Get the entry point witness for the ABI + let main_witness = + &witness_stack.peek().expect("Should have at least one witness on the stack").witness; + let (_, return_value) = public_abi.decode(main_witness)?; - Ok((return_value, solved_witness)) + Ok((return_value, witness_stack)) } pub(crate) fn execute_program( compiled_program: &CompiledProgram, inputs_map: &InputMap, foreign_call_resolver_url: Option<&str>, -) -> Result { +) -> Result { let blackbox_solver = Bn254BlackBoxSolver::new(); let initial_witness = compiled_program.abi.encode(inputs_map, None)?; - let solved_witness_err = nargo::ops::execute_circuit( - &compiled_program.circuit, + let solved_witness_stack_err = nargo::ops::execute_program( + &compiled_program.program, initial_witness, &blackbox_solver, &mut DefaultForeignCallExecutor::new(true, foreign_call_resolver_url), ); - match solved_witness_err { - Ok(solved_witness) => Ok(solved_witness), + match solved_witness_stack_err { + Ok(solved_witness_stack) => Ok(solved_witness_stack), Err(err) => { let debug_artifact = DebugArtifact { debug_symbols: vec![compiled_program.debug.clone()], diff --git a/tooling/nargo_cli/src/cli/export_cmd.rs b/tooling/nargo_cli/src/cli/export_cmd.rs index 96b24796a2b..044c2cb4ebb 100644 --- a/tooling/nargo_cli/src/cli/export_cmd.rs +++ b/tooling/nargo_cli/src/cli/export_cmd.rs @@ -1,4 +1,5 @@ use nargo::errors::CompileError; +use nargo::ops::report_errors; use noirc_errors::FileDiagnostic; use noirc_frontend::hir::ParsedFiles; use rayon::prelude::*; @@ -24,7 +25,6 @@ use crate::errors::CliError; use super::check_cmd::check_crate_and_report_errors; -use super::compile_cmd::report_errors; use super::fs::program::save_program_to_file; use super::NargoConfig; diff --git a/tooling/nargo_cli/src/cli/fmt_cmd.rs b/tooling/nargo_cli/src/cli/fmt_cmd.rs index 0bd25a3a0ce..2e0ca5632f1 100644 --- a/tooling/nargo_cli/src/cli/fmt_cmd.rs +++ b/tooling/nargo_cli/src/cli/fmt_cmd.rs @@ -1,7 +1,7 @@ use std::{fs::DirEntry, path::Path}; use clap::Args; -use nargo::insert_all_files_for_workspace_into_file_manager; +use nargo::{insert_all_files_for_workspace_into_file_manager, ops::report_errors}; use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_driver::{file_manager_with_stdlib, NOIR_ARTIFACT_VERSION_STRING}; use noirc_errors::CustomDiagnostic; @@ -53,7 +53,7 @@ pub(crate) fn run(args: FormatCommand, config: NargoConfig) -> Result<(), CliErr }) .collect(); - let _ = super::compile_cmd::report_errors::<()>( + let _ = report_errors::<()>( Err(errors), &workspace_file_manager, false, diff --git a/tooling/nargo_cli/src/cli/fs/program.rs b/tooling/nargo_cli/src/cli/fs/program.rs index 1fb57ae6685..77005e8d5af 100644 --- a/tooling/nargo_cli/src/cli/fs/program.rs +++ b/tooling/nargo_cli/src/cli/fs/program.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; -use acvm::acir::circuit::Circuit; +use acvm::acir::circuit::Program; use nargo::artifacts::{contract::ContractArtifact, program::ProgramArtifact}; use noirc_frontend::graph::CrateName; @@ -18,13 +18,10 @@ pub(crate) fn save_program_to_file>( } /// Writes the bytecode as acir.gz -pub(crate) fn only_acir>( - program_artifact: &ProgramArtifact, - circuit_dir: P, -) -> PathBuf { +pub(crate) fn only_acir>(program: Program, circuit_dir: P) -> PathBuf { create_named_dir(circuit_dir.as_ref(), "target"); let circuit_path = circuit_dir.as_ref().join("acir").with_extension("gz"); - let bytes = Circuit::serialize_circuit(&program_artifact.bytecode); + let bytes = Program::serialize_program(&program); write_to_file(&bytes, &circuit_path); circuit_path diff --git a/tooling/nargo_cli/src/cli/fs/witness.rs b/tooling/nargo_cli/src/cli/fs/witness.rs index 1a2cf88f4a1..613cdec28da 100644 --- a/tooling/nargo_cli/src/cli/fs/witness.rs +++ b/tooling/nargo_cli/src/cli/fs/witness.rs @@ -1,20 +1,20 @@ use std::path::{Path, PathBuf}; -use acvm::acir::native_types::WitnessMap; +use acvm::acir::native_types::WitnessStack; use nargo::constants::WITNESS_EXT; use super::{create_named_dir, write_to_file}; use crate::errors::FilesystemError; pub(crate) fn save_witness_to_dir>( - witnesses: WitnessMap, + witness_stack: WitnessStack, witness_name: &str, witness_dir: P, ) -> Result { create_named_dir(witness_dir.as_ref(), "witness"); let witness_path = witness_dir.as_ref().join(witness_name).with_extension(WITNESS_EXT); - let buf: Vec = witnesses.try_into()?; + let buf: Vec = witness_stack.try_into()?; write_to_file(buf.as_slice(), &witness_path); diff --git a/tooling/nargo_cli/src/cli/info_cmd.rs b/tooling/nargo_cli/src/cli/info_cmd.rs index ef0df0bf25b..72784013e17 100644 --- a/tooling/nargo_cli/src/cli/info_cmd.rs +++ b/tooling/nargo_cli/src/cli/info_cmd.rs @@ -1,12 +1,12 @@ use std::collections::HashMap; -use acvm::acir::circuit::ExpressionWidth; +use acvm::acir::circuit::{ExpressionWidth, Program}; use backend_interface::BackendError; use clap::Args; use iter_extended::vecmap; use nargo::{ artifacts::debug::DebugArtifact, insert_all_files_for_workspace_into_file_manager, - package::Package, parse_all, + ops::report_errors, package::Package, parse_all, }; use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_driver::{ @@ -24,12 +24,13 @@ use crate::errors::CliError; use super::{compile_cmd::compile_workspace, NargoConfig}; -/// Provides detailed information on a circuit +/// Provides detailed information on each of a program's function (represented by a single circuit) /// -/// Current information provided: +/// Current information provided per circuit: /// 1. The number of ACIR opcodes /// 2. Counts the final number gates in the circuit used by a backend #[derive(Debug, Clone, Args)] +#[clap(visible_alias = "i")] pub(crate) struct InfoCommand { /// The name of the package to detail #[clap(long, conflicts_with = "workspace")] @@ -73,11 +74,18 @@ pub(crate) fn run( .compile_options .expression_width .unwrap_or_else(|| backend.get_backend_info_or_default()); - let (compiled_programs, compiled_contracts) = compile_workspace( + let compiled_workspace = compile_workspace( &workspace_file_manager, &parsed_files, &workspace, &args.compile_options, + ); + + let (compiled_programs, compiled_contracts) = report_errors( + compiled_workspace, + &workspace_file_manager, + args.compile_options.deny_warnings, + args.compile_options.silence_warnings, )?; let compiled_programs = vecmap(compiled_programs, |program| { @@ -106,6 +114,7 @@ pub(crate) fn run( let binary_packages = workspace.into_iter().filter(|package| package.is_binary()).zip(compiled_programs); + let program_info = binary_packages .par_bridge() .map(|(package, program)| { @@ -126,10 +135,13 @@ pub(crate) fn run( } else { // Otherwise print human-readable table. if !info_report.programs.is_empty() { - let mut program_table = table!([Fm->"Package", Fm->"Expression Width", Fm->"ACIR Opcodes", Fm->"Backend Circuit Size"]); + let mut program_table = table!([Fm->"Package", Fm->"Function", Fm->"Expression Width", Fm->"ACIR Opcodes", Fm->"Backend Circuit Size"]); - for program in info_report.programs { - program_table.add_row(program.into()); + for program_info in info_report.programs { + let program_rows: Vec = program_info.into(); + for row in program_rows { + program_table.add_row(row); + } } program_table.printstd(); } @@ -215,18 +227,20 @@ struct ProgramInfo { name: String, #[serde(skip)] expression_width: ExpressionWidth, - acir_opcodes: usize, - circuit_size: u32, + functions: Vec, } -impl From for Row { +impl From for Vec { fn from(program_info: ProgramInfo) -> Self { - row![ - Fm->format!("{}", program_info.name), - format!("{:?}", program_info.expression_width), - Fc->format!("{}", program_info.acir_opcodes), - Fc->format!("{}", program_info.circuit_size), - ] + vecmap(program_info.functions, |function| { + row![ + Fm->format!("{}", program_info.name), + Fc->format!("{}", function.name), + format!("{:?}", program_info.expression_width), + Fc->format!("{}", function.acir_opcodes), + Fc->format!("{}", function.circuit_size), + ] + }) } } @@ -235,6 +249,7 @@ struct ContractInfo { name: String, #[serde(skip)] expression_width: ExpressionWidth, + // TODO(https://github.com/noir-lang/noir/issues/4720): Settle on how to display contract functions with non-inlined Acir calls functions: Vec, } @@ -265,12 +280,22 @@ fn count_opcodes_and_gates_in_program( package: &Package, expression_width: ExpressionWidth, ) -> Result { - Ok(ProgramInfo { - name: package.name.to_string(), - expression_width, - acir_opcodes: compiled_program.circuit.opcodes.len(), - circuit_size: backend.get_exact_circuit_size(&compiled_program.circuit)?, - }) + let functions = compiled_program + .program + .functions + .into_par_iter() + .enumerate() + .map(|(i, function)| -> Result<_, BackendError> { + Ok(FunctionInfo { + name: compiled_program.names[i].clone(), + acir_opcodes: function.opcodes.len(), + circuit_size: backend + .get_exact_circuit_size(&Program { functions: vec![function] })?, + }) + }) + .collect::>()?; + + Ok(ProgramInfo { name: package.name.to_string(), expression_width, functions }) } fn count_opcodes_and_gates_in_contract( @@ -284,7 +309,8 @@ fn count_opcodes_and_gates_in_contract( .map(|function| -> Result<_, BackendError> { Ok(FunctionInfo { name: function.name, - acir_opcodes: function.bytecode.opcodes.len(), + // TODO(https://github.com/noir-lang/noir/issues/4720) + acir_opcodes: function.bytecode.functions[0].opcodes.len(), circuit_size: backend.get_exact_circuit_size(&function.bytecode)?, }) }) diff --git a/tooling/nargo_cli/src/cli/noir_template_files/contract.nr b/tooling/nargo_cli/src/cli/noir_template_files/contract.nr index e126726393d..3cd3b5b3766 100644 --- a/tooling/nargo_cli/src/cli/noir_template_files/contract.nr +++ b/tooling/nargo_cli/src/cli/noir_template_files/contract.nr @@ -1,5 +1,5 @@ contract Main { - internal fn double(x: Field) -> pub Field { x * 2 } + fn double(x: Field) -> pub Field { x * 2 } fn triple(x: Field) -> pub Field { x * 3 } fn quadruple(x: Field) -> pub Field { double(double(x)) } } diff --git a/tooling/nargo_cli/src/cli/prove_cmd.rs b/tooling/nargo_cli/src/cli/prove_cmd.rs index cc39b0535bc..b9e4bca9e69 100644 --- a/tooling/nargo_cli/src/cli/prove_cmd.rs +++ b/tooling/nargo_cli/src/cli/prove_cmd.rs @@ -1,6 +1,6 @@ use clap::Args; use nargo::constants::{PROVER_INPUT_FILE, VERIFIER_INPUT_FILE}; -use nargo::ops::compile_program; +use nargo::ops::{compile_program, report_errors}; use nargo::package::Package; use nargo::workspace::Workspace; use nargo::{insert_all_files_for_workspace_into_file_manager, parse_all}; @@ -11,7 +11,6 @@ use noirc_driver::{ }; use noirc_frontend::graph::CrateName; -use super::compile_cmd::report_errors; use super::fs::{ inputs::{read_inputs_from_file, write_inputs_to_file}, proof::save_proof_to_dir, @@ -21,6 +20,7 @@ use crate::{backends::Backend, cli::execute_cmd::execute_program, errors::CliErr /// Create proof for this program. The proof is returned as a hex encoded string. #[derive(Debug, Clone, Args)] +#[clap(visible_alias = "p")] pub(crate) struct ProveCommand { /// The name of the toml file which contains the inputs for the prover #[clap(long, short, default_value = PROVER_INPUT_FILE)] @@ -122,12 +122,14 @@ pub(crate) fn prove_package( let (inputs_map, _) = read_inputs_from_file(&package.root_dir, prover_name, Format::Toml, &compiled_program.abi)?; - let solved_witness = - execute_program(&compiled_program, &inputs_map, foreign_call_resolver_url)?; + let witness_stack = execute_program(&compiled_program, &inputs_map, foreign_call_resolver_url)?; // Write public inputs into Verifier.toml let public_abi = compiled_program.abi.public_abi(); - let (public_inputs, return_value) = public_abi.decode(&solved_witness)?; + // Get the entry point witness for the ABI + let main_witness = + &witness_stack.peek().expect("Should have at least one witness on the stack").witness; + let (public_inputs, return_value) = public_abi.decode(main_witness)?; write_inputs_to_file( &public_inputs, @@ -138,11 +140,11 @@ pub(crate) fn prove_package( Format::Toml, )?; - let proof = backend.prove(&compiled_program.circuit, solved_witness)?; + let proof = backend.prove(&compiled_program.program, witness_stack)?; if check_proof { let public_inputs = public_abi.encode(&public_inputs, return_value)?; - let valid_proof = backend.verify(&proof, public_inputs, &compiled_program.circuit)?; + let valid_proof = backend.verify(&proof, public_inputs, &compiled_program.program)?; if !valid_proof { return Err(CliError::InvalidProof("".into())); diff --git a/tooling/nargo_cli/src/cli/test_cmd.rs b/tooling/nargo_cli/src/cli/test_cmd.rs index 503fd5afdd4..88a804d5cf4 100644 --- a/tooling/nargo_cli/src/cli/test_cmd.rs +++ b/tooling/nargo_cli/src/cli/test_cmd.rs @@ -5,17 +5,18 @@ use bn254_blackbox_solver::Bn254BlackBoxSolver; use clap::Args; use fm::FileManager; use nargo::{ - insert_all_files_for_workspace_into_file_manager, - ops::{run_test, TestStatus}, - package::Package, - parse_all, prepare_package, + insert_all_files_for_workspace_into_file_manager, ops::TestStatus, package::Package, parse_all, + prepare_package, }; use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection}; -use noirc_driver::{file_manager_with_stdlib, CompileOptions, NOIR_ARTIFACT_VERSION_STRING}; +use noirc_driver::{ + check_crate, file_manager_with_stdlib, CompileOptions, NOIR_ARTIFACT_VERSION_STRING, +}; use noirc_frontend::{ graph::CrateName, hir::{FunctionNameMatch, ParsedFiles}, }; +use rayon::prelude::{IntoParallelIterator, ParallelBridge, ParallelIterator}; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; use crate::{backends::Backend, cli::check_cmd::check_crate_and_report_errors, errors::CliError}; @@ -24,6 +25,7 @@ use super::NargoConfig; /// Run the tests for this program #[derive(Debug, Clone, Args)] +#[clap(visible_alias = "t")] pub(crate) struct TestCommand { /// If given, only tests with names containing this string will be run test_name: Option, @@ -82,15 +84,13 @@ pub(crate) fn run( None => FunctionNameMatch::Anything, }; - let blackbox_solver = Bn254BlackBoxSolver::new(); - let test_reports: Vec> = workspace .into_iter() + .par_bridge() .map(|package| { - run_tests( + run_tests::( &workspace_file_manager, &parsed_files, - &blackbox_solver, package, pattern, args.show_output, @@ -116,24 +116,95 @@ pub(crate) fn run( }; } - if test_report.iter().any(|(_, status)| !matches!(status, TestStatus::Fail { .. })) { - Ok(()) - } else { + if test_report.iter().any(|(_, status)| status.failed()) { Err(CliError::Generic(String::new())) + } else { + Ok(()) } } -#[allow(clippy::too_many_arguments)] -fn run_tests( +fn run_tests( file_manager: &FileManager, parsed_files: &ParsedFiles, - blackbox_solver: &S, package: &Package, fn_name: FunctionNameMatch, show_output: bool, foreign_call_resolver_url: Option<&str>, compile_options: &CompileOptions, ) -> Result, CliError> { + let test_functions = + get_tests_in_package(file_manager, parsed_files, package, fn_name, compile_options)?; + + let count_all = test_functions.len(); + + let plural = if count_all == 1 { "" } else { "s" }; + println!("[{}] Running {count_all} test function{plural}", package.name); + + let test_report: Vec<(String, TestStatus)> = test_functions + .into_par_iter() + .map(|test_name| { + let status = run_test::( + file_manager, + parsed_files, + package, + &test_name, + show_output, + foreign_call_resolver_url, + compile_options, + ); + + (test_name, status) + }) + .collect(); + + display_test_report(file_manager, package, compile_options, &test_report)?; + Ok(test_report) +} + +fn run_test( + file_manager: &FileManager, + parsed_files: &ParsedFiles, + package: &Package, + fn_name: &str, + show_output: bool, + foreign_call_resolver_url: Option<&str>, + compile_options: &CompileOptions, +) -> TestStatus { + // This is really hacky but we can't share `Context` or `S` across threads. + // We then need to construct a separate copy for each test. + + let (mut context, crate_id) = prepare_package(file_manager, parsed_files, package); + check_crate( + &mut context, + crate_id, + compile_options.deny_warnings, + compile_options.disable_macros, + ) + .expect("Any errors should have occurred when collecting test functions"); + + let test_functions = context + .get_all_test_functions_in_crate_matching(&crate_id, FunctionNameMatch::Exact(fn_name)); + let (_, test_function) = test_functions.first().expect("Test function should exist"); + + let blackbox_solver = S::default(); + + nargo::ops::run_test( + &blackbox_solver, + &mut context, + test_function, + show_output, + foreign_call_resolver_url, + compile_options, + ) +} + +fn get_tests_in_package( + file_manager: &FileManager, + parsed_files: &ParsedFiles, + package: &Package, + fn_name: FunctionNameMatch, + compile_options: &CompileOptions, +) -> Result, CliError> { let (mut context, crate_id) = prepare_package(file_manager, parsed_files, package); check_crate_and_report_errors( &mut context, @@ -143,30 +214,27 @@ fn run_tests( compile_options.silence_warnings, )?; - let test_functions = context.get_all_test_functions_in_crate_matching(&crate_id, fn_name); - let count_all = test_functions.len(); - - let plural = if count_all == 1 { "" } else { "s" }; - println!("[{}] Running {count_all} test function{plural}", package.name); + Ok(context + .get_all_test_functions_in_crate_matching(&crate_id, fn_name) + .into_iter() + .map(|(test_name, _)| test_name) + .collect()) +} +fn display_test_report( + file_manager: &FileManager, + package: &Package, + compile_options: &CompileOptions, + test_report: &[(String, TestStatus)], +) -> Result<(), CliError> { let writer = StandardStream::stderr(ColorChoice::Always); let mut writer = writer.lock(); - let mut test_report: Vec<(String, TestStatus)> = Vec::new(); - for (test_name, test_function) in test_functions { + for (test_name, test_status) in test_report { write!(writer, "[{}] Testing {test_name}... ", package.name) .expect("Failed to write to stderr"); writer.flush().expect("Failed to flush writer"); - let test_status = run_test( - blackbox_solver, - &mut context, - test_function, - show_output, - foreign_call_resolver_url, - compile_options, - ); - match &test_status { TestStatus::Pass { .. } => { writer @@ -181,7 +249,7 @@ fn run_tests( writeln!(writer, "FAIL\n{message}\n").expect("Failed to write to stderr"); if let Some(diag) = error_diagnostic { noirc_errors::reporter::report_all( - context.file_manager.as_file_map(), + file_manager.as_file_map(), &[diag.clone()], compile_options.deny_warnings, compile_options.silence_warnings, @@ -190,23 +258,21 @@ fn run_tests( } TestStatus::CompileError(err) => { noirc_errors::reporter::report_all( - context.file_manager.as_file_map(), + file_manager.as_file_map(), &[err.clone()], compile_options.deny_warnings, compile_options.silence_warnings, ); } } - - test_report.push((test_name, test_status)); - writer.reset().expect("Failed to reset writer"); } write!(writer, "[{}] ", package.name).expect("Failed to write to stderr"); - let count_failed = - test_report.iter().filter(|(_, status)| !matches!(status, TestStatus::Pass)).count(); + let count_all = test_report.len(); + let count_failed = test_report.iter().filter(|(_, status)| status.failed()).count(); + let plural = if count_all == 1 { "" } else { "s" }; if count_failed == 0 { writer.set_color(ColorSpec::new().set_fg(Some(Color::Green))).expect("Failed to set color"); write!(writer, "{count_all} test{plural} passed").expect("Failed to write to stderr"); @@ -231,5 +297,5 @@ fn run_tests( writer.reset().expect("Failed to reset writer"); } - Ok(test_report) + Ok(()) } diff --git a/tooling/nargo_cli/src/cli/verify_cmd.rs b/tooling/nargo_cli/src/cli/verify_cmd.rs index 66b88a22f2a..7202a179aae 100644 --- a/tooling/nargo_cli/src/cli/verify_cmd.rs +++ b/tooling/nargo_cli/src/cli/verify_cmd.rs @@ -1,11 +1,10 @@ -use super::compile_cmd::report_errors; use super::fs::{inputs::read_inputs_from_file, load_hex_data}; use super::NargoConfig; use crate::{backends::Backend, errors::CliError}; use clap::Args; use nargo::constants::{PROOF_EXT, VERIFIER_INPUT_FILE}; -use nargo::ops::compile_program; +use nargo::ops::{compile_program, report_errors}; use nargo::package::Package; use nargo::workspace::Workspace; use nargo::{insert_all_files_for_workspace_into_file_manager, parse_all}; @@ -18,6 +17,7 @@ use noirc_frontend::graph::CrateName; /// Given a proof and a program, verify whether the proof is valid #[derive(Debug, Clone, Args)] +#[clap(visible_alias = "v")] pub(crate) struct VerifyCommand { /// The name of the toml file which contains the inputs for the verifier #[clap(long, short, default_value = VERIFIER_INPUT_FILE)] @@ -102,7 +102,7 @@ fn verify_package( let proof = load_hex_data(&proof_path)?; - let valid_proof = backend.verify(&proof, public_inputs, &compiled_program.circuit)?; + let valid_proof = backend.verify(&proof, public_inputs, &compiled_program.program)?; if valid_proof { Ok(()) diff --git a/tooling/nargo_cli/src/errors.rs b/tooling/nargo_cli/src/errors.rs index c2996f53420..40fb7886405 100644 --- a/tooling/nargo_cli/src/errors.rs +++ b/tooling/nargo_cli/src/errors.rs @@ -1,4 +1,4 @@ -use acvm::acir::native_types::WitnessMapError; +use acvm::acir::native_types::WitnessStackError; use hex::FromHexError; use nargo::{errors::CompileError, NargoError}; use nargo_toml::ManifestError; @@ -22,9 +22,9 @@ pub(crate) enum FilesystemError { #[error(transparent)] InputParserError(#[from] InputParserError), - /// WitnessMap serialization error + /// WitnessStack serialization error #[error(transparent)] - WitnessMapSerialization(#[from] WitnessMapError), + WitnessStackSerialization(#[from] WitnessStackError), #[error("Error: could not deserialize build program: {0}")] ProgramSerializationError(String), diff --git a/tooling/nargo_cli/src/main.rs b/tooling/nargo_cli/src/main.rs index 3f797b0bf0c..6e2b7069bc4 100644 --- a/tooling/nargo_cli/src/main.rs +++ b/tooling/nargo_cli/src/main.rs @@ -25,14 +25,14 @@ fn main() { if let Ok(log_dir) = env::var("NARGO_LOG_DIR") { let debug_file = rolling::daily(log_dir, "nargo-log"); tracing_subscriber::fmt() - .with_span_events(FmtSpan::ACTIVE) + .with_span_events(FmtSpan::ENTER | FmtSpan::CLOSE) .with_writer(debug_file) .with_ansi(false) .with_env_filter(EnvFilter::from_default_env()) .init(); } else { tracing_subscriber::fmt() - .with_span_events(FmtSpan::ACTIVE) + .with_span_events(FmtSpan::ENTER | FmtSpan::CLOSE) .with_ansi(true) .with_env_filter(EnvFilter::from_env("NOIR_LOG")) .init(); diff --git a/tooling/nargo_cli/tests/stdlib-tests.rs b/tooling/nargo_cli/tests/stdlib-tests.rs new file mode 100644 index 00000000000..9d377cfaee9 --- /dev/null +++ b/tooling/nargo_cli/tests/stdlib-tests.rs @@ -0,0 +1,62 @@ +use std::{collections::BTreeMap, path::PathBuf}; + +use acvm::blackbox_solver::StubbedBlackBoxSolver; +use noirc_driver::{check_crate, file_manager_with_stdlib, CompileOptions}; +use noirc_frontend::hir::FunctionNameMatch; + +use nargo::{ + ops::{report_errors, run_test, TestStatus}, + package::{Package, PackageType}, + parse_all, prepare_package, +}; + +#[test] +fn stdlib_noir_tests() { + let mut file_manager = file_manager_with_stdlib(&PathBuf::from(".")); + file_manager.add_file_with_source_canonical_path(&PathBuf::from("main.nr"), "".to_owned()); + let parsed_files = parse_all(&file_manager); + + // We need a dummy package as we cannot compile the stdlib on its own. + let dummy_package = Package { + version: None, + compiler_required_version: None, + root_dir: PathBuf::from("."), + package_type: PackageType::Binary, + entry_path: PathBuf::from("main.nr"), + name: "dummy".parse().unwrap(), + dependencies: BTreeMap::new(), + }; + + let (mut context, dummy_crate_id) = + prepare_package(&file_manager, &parsed_files, &dummy_package); + + let result = check_crate(&mut context, dummy_crate_id, true, false); + report_errors(result, &context.file_manager, true, false) + .expect("Error encountered while compiling standard library"); + + // We can now search within the stdlib for any test functions to compile. + + let test_functions = context.get_all_test_functions_in_crate_matching( + context.stdlib_crate_id(), + FunctionNameMatch::Anything, + ); + + let test_report: Vec<(String, TestStatus)> = test_functions + .into_iter() + .map(|(test_name, test_function)| { + let status = run_test( + &StubbedBlackBoxSolver, + &mut context, + &test_function, + false, + None, + &CompileOptions::default(), + ); + + (test_name, status) + }) + .collect(); + + assert!(!test_report.is_empty(), "Could not find any tests within the stdlib"); + assert!(test_report.iter().all(|(_, status)| !status.failed())); +} diff --git a/tooling/nargo_fmt/build.rs b/tooling/nargo_fmt/build.rs index c356b403ae5..6f41768c1dc 100644 --- a/tooling/nargo_fmt/build.rs +++ b/tooling/nargo_fmt/build.rs @@ -58,10 +58,10 @@ fn format_{test_name}() {{ let expected_output = r#"{output_source}"#; - let (parsed_module, _errors) = noirc_frontend::parse_program(&input); + let (parsed_module, _errors) = noirc_frontend::parse_program(input); let config = nargo_fmt::Config::of("{config}").unwrap(); - let fmt_text = nargo_fmt::format(&input, parsed_module, &config); + let fmt_text = nargo_fmt::format(input, parsed_module, &config); if std::env::var("UPDATE_EXPECT").is_ok() {{ std::fs::write("{output_source_path}", fmt_text.clone()).unwrap(); diff --git a/tooling/nargo_fmt/src/rewrite/array.rs b/tooling/nargo_fmt/src/rewrite/array.rs index 77e5e756f19..db7dc4701b7 100644 --- a/tooling/nargo_fmt/src/rewrite/array.rs +++ b/tooling/nargo_fmt/src/rewrite/array.rs @@ -6,7 +6,12 @@ use crate::{ visitor::{expr::NewlineMode, FmtVisitor}, }; -pub(crate) fn rewrite(mut visitor: FmtVisitor, array: Vec, array_span: Span) -> String { +pub(crate) fn rewrite( + mut visitor: FmtVisitor, + array: Vec, + array_span: Span, + is_slice: bool, +) -> String { let pattern: &[_] = &[' ', '\t']; visitor.indent.block_indent(visitor.config); @@ -75,8 +80,9 @@ pub(crate) fn rewrite(mut visitor: FmtVisitor, array: Vec, array_spa } } + let open_bracket = if is_slice { "&[" } else { "[" }; crate::visitor::expr::wrap_exprs( - "[", + open_bracket, "]", items_str.trim().into(), nested_indent, diff --git a/tooling/nargo_fmt/src/rewrite/expr.rs b/tooling/nargo_fmt/src/rewrite/expr.rs index c3d42fd2b2e..10919a241a1 100644 --- a/tooling/nargo_fmt/src/rewrite/expr.rs +++ b/tooling/nargo_fmt/src/rewrite/expr.rs @@ -1,4 +1,7 @@ -use noirc_frontend::{token::Token, ArrayLiteral, Expression, ExpressionKind, Literal, UnaryOp}; +use noirc_frontend::{ + macros_api::Span, token::Token, ArrayLiteral, BlockExpression, Expression, ExpressionKind, + Literal, UnaryOp, +}; use crate::visitor::{ expr::{format_brackets, format_parens, NewlineMode}, @@ -20,11 +23,7 @@ pub(crate) fn rewrite( shape: Shape, ) -> String { match kind { - ExpressionKind::Block(block) => { - let mut visitor = visitor.fork(); - visitor.visit_block(block, span); - visitor.finish() - } + ExpressionKind::Block(block) => rewrite_block(visitor, block, span), ExpressionKind::Prefix(prefix) => { let op = match prefix.operator { UnaryOp::Minus => "-", @@ -126,7 +125,16 @@ pub(crate) fn rewrite( format!("[{repeated}; {length}]") } Literal::Array(ArrayLiteral::Standard(exprs)) => { - super::array(visitor.fork(), exprs, span) + super::array(visitor.fork(), exprs, span, false) + } + Literal::Slice(ArrayLiteral::Repeated { repeated_element, length }) => { + let repeated = rewrite_sub_expr(visitor, shape, *repeated_element); + let length = rewrite_sub_expr(visitor, shape, *length); + + format!("&[{repeated}; {length}]") + } + Literal::Slice(ArrayLiteral::Standard(exprs)) => { + super::array(visitor.fork(), exprs, span, true) } Literal::Unit => "()".to_string(), }, @@ -154,6 +162,13 @@ pub(crate) fn rewrite( visitor.format_if(*if_expr) } ExpressionKind::Lambda(_) | ExpressionKind::Variable(_) => visitor.slice(span).to_string(), + ExpressionKind::Quote(block) => format!("quote {}", rewrite_block(visitor, block, span)), ExpressionKind::Error => unreachable!(), } } + +fn rewrite_block(visitor: &FmtVisitor, block: BlockExpression, span: Span) -> String { + let mut visitor = visitor.fork(); + visitor.visit_block(block, span); + visitor.finish() +} diff --git a/tooling/nargo_fmt/src/rewrite/imports.rs b/tooling/nargo_fmt/src/rewrite/imports.rs index 2788f778140..55eb259bcdd 100644 --- a/tooling/nargo_fmt/src/rewrite/imports.rs +++ b/tooling/nargo_fmt/src/rewrite/imports.rs @@ -102,7 +102,14 @@ impl UseTree { let mut iter = self.path.iter().peekable(); while let Some(segment) = iter.next() { - let segment_str = segment.rewrite(visitor, shape); + let mut segment_str = segment.rewrite(visitor, shape); + if segment_str.contains('{') + && !segment_str.contains(',') + && !segment_str.contains("::") + { + let empty = ""; + segment_str = segment_str.replace(['{', '}'], empty); + } result.push_str(&segment_str); if iter.peek().is_some() { diff --git a/tooling/nargo_fmt/src/rewrite/typ.rs b/tooling/nargo_fmt/src/rewrite/typ.rs index f027589d24a..d132afcc850 100644 --- a/tooling/nargo_fmt/src/rewrite/typ.rs +++ b/tooling/nargo_fmt/src/rewrite/typ.rs @@ -9,12 +9,12 @@ pub(crate) fn rewrite(visitor: &FmtVisitor, _shape: Shape, typ: UnresolvedType) match typ.typ { UnresolvedTypeData::Array(length, element) => { let typ = rewrite(visitor, _shape, *element); - if let Some(length) = length { - let length = visitor.slice(length.span()); - format!("[{typ}; {length}]") - } else { - format!("[{typ}]") - } + let length = visitor.slice(length.span()); + format!("[{typ}; {length}]") + } + UnresolvedTypeData::Slice(element) => { + let typ = rewrite(visitor, _shape, *element); + format!("[{typ}]") } UnresolvedTypeData::Parenthesized(typ) => { let typ = rewrite(visitor, _shape, *typ); diff --git a/tooling/nargo_fmt/src/visitor/expr.rs b/tooling/nargo_fmt/src/visitor/expr.rs index 2cd0e881e84..f9836adda18 100644 --- a/tooling/nargo_fmt/src/visitor/expr.rs +++ b/tooling/nargo_fmt/src/visitor/expr.rs @@ -119,11 +119,11 @@ impl FmtVisitor<'_> { self.last_position = block_span.start() + 1; // `{` self.push_str("{"); - self.trim_spaces_after_opening_brace(&block.0); + self.trim_spaces_after_opening_brace(&block.statements); self.indent.block_indent(self.config); - self.visit_stmts(block.0); + self.visit_stmts(block.statements); let span = (self.last_position..block_span.end() - 1).into(); self.close_block(span); diff --git a/tooling/nargo_fmt/src/visitor/stmt.rs b/tooling/nargo_fmt/src/visitor/stmt.rs index 44c5dad6b5d..ee8cc990e0e 100644 --- a/tooling/nargo_fmt/src/visitor/stmt.rs +++ b/tooling/nargo_fmt/src/visitor/stmt.rs @@ -95,6 +95,8 @@ impl super::FmtVisitor<'_> { self.push_rewrite(self.slice(span).to_string(), span); } StatementKind::Error => unreachable!(), + StatementKind::Break => self.push_rewrite("break;".into(), span), + StatementKind::Continue => self.push_rewrite("continue;".into(), span), } self.last_position = span.end(); diff --git a/tooling/nargo_fmt/tests/expected/contract.nr b/tooling/nargo_fmt/tests/expected/contract.nr index 1e82daba4ca..3e73d5f3344 100644 --- a/tooling/nargo_fmt/tests/expected/contract.nr +++ b/tooling/nargo_fmt/tests/expected/contract.nr @@ -8,11 +8,10 @@ contract Benchmarking { use dep::value_note::{utils::{increment, decrement}, value_note::{VALUE_NOTE_LEN, ValueNote, ValueNoteMethods}}; use dep::aztec::{ - context::{Context}, - note::{utils as note_utils, note_getter_options::NoteGetterOptions, note_header::NoteHeader}, + context::Context, note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader}, log::emit_unencrypted_log, state_vars::{Map, PublicMutable, PrivateSet}, - types::type_serialization::field_serialization::{FieldSerializationMethods, field_SERIALIZED_LEN}, - types::address::{AztecAddress} + types::type_serialization::field_serialization::{FieldSerializationMethods, FIELD_SERIALIZED_LEN}, + types::address::AztecAddress }; struct Storage { diff --git a/tooling/nargo_fmt/tests/expected/import_braces.nr b/tooling/nargo_fmt/tests/expected/import_braces.nr new file mode 100644 index 00000000000..49c9d09001e --- /dev/null +++ b/tooling/nargo_fmt/tests/expected/import_braces.nr @@ -0,0 +1 @@ +use dep::std::hash::sha256; diff --git a/tooling/nargo_fmt/tests/input/contract.nr b/tooling/nargo_fmt/tests/input/contract.nr index a03b8774700..97a6ebd6b77 100644 --- a/tooling/nargo_fmt/tests/input/contract.nr +++ b/tooling/nargo_fmt/tests/input/contract.nr @@ -8,11 +8,10 @@ contract Benchmarking { use dep::value_note::{utils::{increment, decrement}, value_note::{VALUE_NOTE_LEN, ValueNote, ValueNoteMethods}}; use dep::aztec::{ - context::{Context}, - note::{utils as note_utils, note_getter_options::NoteGetterOptions, note_header::NoteHeader}, + context::Context, note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader}, log::emit_unencrypted_log, state_vars::{Map, PublicMutable, PrivateSet}, types::type_serialization::field_serialization::{FieldSerializationMethods, FIELD_SERIALIZED_LEN}, - types::address::{AztecAddress} + types::address::AztecAddress }; struct Storage { diff --git a/tooling/nargo_fmt/tests/input/import_braces.nr b/tooling/nargo_fmt/tests/input/import_braces.nr new file mode 100644 index 00000000000..88c7e9562a8 --- /dev/null +++ b/tooling/nargo_fmt/tests/input/import_braces.nr @@ -0,0 +1 @@ +use dep::std::hash::{sha256}; \ No newline at end of file diff --git a/tooling/noir_codegen/package.json b/tooling/noir_codegen/package.json index 6bb9d06f718..1eabc6a1398 100644 --- a/tooling/noir_codegen/package.json +++ b/tooling/noir_codegen/package.json @@ -3,7 +3,7 @@ "contributors": [ "The Noir Team " ], - "version": "0.24.0", + "version": "0.26.0", "packageManager": "yarn@3.5.1", "license": "(MIT OR Apache-2.0)", "type": "module", @@ -51,13 +51,13 @@ "@types/mocha": "^10.0.1", "@types/node": "^20.6.2", "@types/prettier": "^3", - "chai": "^4.3.8", - "eslint": "^8.56.0", - "eslint-plugin-prettier": "^5.0.0", + "chai": "^4.4.1", + "eslint": "^8.57.0", + "eslint-plugin-prettier": "^5.1.3", "mocha": "^10.2.0", - "prettier": "3.0.3", + "prettier": "3.2.5", "ts-node": "^10.9.1", "tsx": "^4.6.2", - "typescript": "^5.2.2" + "typescript": "^5.4.2" } } diff --git a/tooling/noir_js/package.json b/tooling/noir_js/package.json index 6f1899fae52..c8d4873e095 100644 --- a/tooling/noir_js/package.json +++ b/tooling/noir_js/package.json @@ -3,7 +3,7 @@ "contributors": [ "The Noir Team " ], - "version": "0.24.0", + "version": "0.26.0", "packageManager": "yarn@3.5.1", "license": "(MIT OR Apache-2.0)", "type": "module", @@ -53,14 +53,14 @@ "@types/mocha": "^10.0.1", "@types/node": "^20.6.2", "@types/prettier": "^3", - "chai": "^4.3.8", - "eslint": "^8.56.0", - "eslint-plugin-prettier": "^5.0.0", + "chai": "^4.4.1", + "eslint": "^8.57.0", + "eslint-plugin-prettier": "^5.1.3", "mocha": "^10.2.0", - "prettier": "3.0.3", + "prettier": "3.2.5", "ts-node": "^10.9.1", "tsc-multi": "^1.1.0", "tsx": "^4.6.2", - "typescript": "^5.2.2" + "typescript": "^5.4.2" } } diff --git a/tooling/noir_js_backend_barretenberg/package.json b/tooling/noir_js_backend_barretenberg/package.json index 28c3609fd14..251dd80c2f4 100644 --- a/tooling/noir_js_backend_barretenberg/package.json +++ b/tooling/noir_js_backend_barretenberg/package.json @@ -3,7 +3,7 @@ "contributors": [ "The Noir Team " ], - "version": "0.24.0", + "version": "0.26.0", "packageManager": "yarn@3.5.1", "license": "(MIT OR Apache-2.0)", "type": "module", @@ -42,19 +42,19 @@ "lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0" }, "dependencies": { - "@aztec/bb.js": "0.24.0", + "@aztec/bb.js": "0.32.0", "@noir-lang/types": "workspace:*", "fflate": "^0.8.0" }, "devDependencies": { "@types/node": "^20.6.2", "@types/prettier": "^3", - "chai": "^4.3.8", - "eslint": "^8.56.0", - "eslint-plugin-prettier": "^5.0.0", + "chai": "^4.4.1", + "eslint": "^8.57.0", + "eslint-plugin-prettier": "^5.1.3", "mocha": "^10.2.0", - "prettier": "3.0.3", + "prettier": "3.2.5", "ts-node": "^10.9.1", - "typescript": "5.1.5" + "typescript": "5.4.2" } } diff --git a/tooling/noir_js_backend_barretenberg/src/index.ts b/tooling/noir_js_backend_barretenberg/src/index.ts index d79b487c3cf..bfdf1005a93 100644 --- a/tooling/noir_js_backend_barretenberg/src/index.ts +++ b/tooling/noir_js_backend_barretenberg/src/index.ts @@ -33,9 +33,18 @@ export class BarretenbergBackend implements Backend { /** @ignore */ async instantiate(): Promise { if (!this.api) { + if (typeof navigator !== 'undefined' && navigator.hardwareConcurrency) { + this.options.threads = navigator.hardwareConcurrency; + } else { + try { + const os = await import('os'); + this.options.threads = os.cpus().length; + } catch (e) { + console.log('Could not detect environment. Falling back to one thread.', e); + } + } const { Barretenberg, RawBuffer, Crs } = await import('@aztec/bb.js'); - const api = await Barretenberg.new({ threads: this.options.threads }); - + const api = await Barretenberg.new(this.options); const [_exact, _total, subgroupSize] = await api.acirGetCircuitSizes(this.acirUncompressedBytecode); const crs = await Crs.new(subgroupSize + 1); await api.commonInitSlabAllocator(subgroupSize); diff --git a/tooling/noir_js_backend_barretenberg/src/types.ts b/tooling/noir_js_backend_barretenberg/src/types.ts index 041e36fdf91..fac23030aad 100644 --- a/tooling/noir_js_backend_barretenberg/src/types.ts +++ b/tooling/noir_js_backend_barretenberg/src/types.ts @@ -5,4 +5,5 @@ export type BackendOptions = { /** @description Number of threads */ threads: number; + memory?: { maximum: number }; }; diff --git a/tooling/noir_js_backend_barretenberg/tsconfig.cjs.json b/tooling/noir_js_backend_barretenberg/tsconfig.cjs.json index 15d273af62e..ac1e3784480 100644 --- a/tooling/noir_js_backend_barretenberg/tsconfig.cjs.json +++ b/tooling/noir_js_backend_barretenberg/tsconfig.cjs.json @@ -2,6 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "module": "CommonJS", + "moduleResolution": "Node", "outDir": "./lib/cjs" }, } diff --git a/tooling/noir_js_types/package.json b/tooling/noir_js_types/package.json index a3b5c85897a..eadb6f49665 100644 --- a/tooling/noir_js_types/package.json +++ b/tooling/noir_js_types/package.json @@ -4,7 +4,7 @@ "The Noir Team " ], "packageManager": "yarn@3.5.1", - "version": "0.24.0", + "version": "0.26.0", "license": "(MIT OR Apache-2.0)", "homepage": "https://noir-lang.org/", "repository": { @@ -40,9 +40,9 @@ }, "devDependencies": { "@types/prettier": "^3", - "eslint": "^8.56.0", - "eslint-plugin-prettier": "^5.0.0", - "prettier": "3.0.3", - "typescript": "^5.2.2" + "eslint": "^8.57.0", + "eslint-plugin-prettier": "^5.1.3", + "prettier": "3.2.5", + "typescript": "^5.4.2" } } diff --git a/tooling/noirc_abi/src/lib.rs b/tooling/noirc_abi/src/lib.rs index 26feab65d83..d0dcb373963 100644 --- a/tooling/noirc_abi/src/lib.rs +++ b/tooling/noirc_abi/src/lib.rs @@ -147,7 +147,9 @@ impl AbiType { Type::TypeVariable(binding, TypeVariableKind::IntegerOrField) | Type::TypeVariable(binding, TypeVariableKind::Integer) => match &*binding.borrow() { TypeBinding::Bound(typ) => Self::from_type(context, typ), - TypeBinding::Unbound(_) => Self::from_type(context, &Type::default_int_type()), + TypeBinding::Unbound(_) => { + Self::from_type(context, &Type::default_int_or_field_type()) + } }, Type::Bool => Self::Boolean, Type::String(size) => { @@ -178,8 +180,9 @@ impl AbiType { | Type::TypeVariable(_, _) | Type::NamedGeneric(..) | Type::Forall(..) - | Type::NotConstant - | Type::Function(_, _, _) => unreachable!("Type cannot be used in the abi"), + | Type::Code + | Type::Slice(_) + | Type::Function(_, _, _) => unreachable!("{typ} cannot be used in the abi"), Type::FmtString(_, _) => unreachable!("format strings cannot be used in the abi"), Type::MutableReference(_) => unreachable!("&mut cannot be used in the abi"), } diff --git a/tooling/noirc_abi_wasm/README.md b/tooling/noirc_abi_wasm/README.md index 77bc1f5fae2..2b0cf9b74d4 100644 --- a/tooling/noirc_abi_wasm/README.md +++ b/tooling/noirc_abi_wasm/README.md @@ -1,17 +1,3 @@ # Noir Lang ABI JavaScript Package This JavaScript package enables users to ABI encode inputs to a Noir program, i.e. generating an initial witness. - -## Building from source - -Outside of the [noir repo](https://github.com/noir-lang/noir), this package can be built using the command below: - -```bash -nix build -L github:noir-lang/noir/master#abi_wasm -``` - -If you are within the noir repo and would like to build local changes, you can use: - -```bash -nix build -L #abi_wasm -``` diff --git a/tooling/noirc_abi_wasm/build.rs b/tooling/noirc_abi_wasm/build.rs index 3b96be74ef3..7a6eb861de2 100644 --- a/tooling/noirc_abi_wasm/build.rs +++ b/tooling/noirc_abi_wasm/build.rs @@ -1,8 +1,7 @@ const GIT_COMMIT: &&str = &"GIT_COMMIT"; fn main() { - // Only use build_data if the environment variable isn't set - // The environment variable is always set when working via Nix + // Only use build_data if the environment variable isn't set. if std::env::var(GIT_COMMIT).is_err() { build_data::set_GIT_COMMIT(); build_data::set_GIT_DIRTY(); diff --git a/tooling/noirc_abi_wasm/build.sh b/tooling/noirc_abi_wasm/build.sh index 24af149bcea..fe0b4dcbfff 100755 --- a/tooling/noirc_abi_wasm/build.sh +++ b/tooling/noirc_abi_wasm/build.sh @@ -6,13 +6,6 @@ function require_command { exit 1 fi } -function check_installed { - if ! command -v "$1" >/dev/null 2>&1; then - echo "$1 is not installed. Please install it." >&2 - return 1 - fi - return 0 -} function run_or_fail { "$@" local status=$? @@ -25,23 +18,29 @@ function run_or_fail { require_command jq require_command cargo require_command wasm-bindgen -check_installed wasm-opt +require_command wasm-opt self_path=$(dirname "$(readlink -f "$0")") -export pname=$(cargo read-manifest | jq -r '.name') -export CARGO_TARGET_DIR=$self_path/target +pname=$(cargo read-manifest | jq -r '.name') -rm -rf $self_path/outputs >/dev/null 2>&1 -rm -rf $self_path/result >/dev/null 2>&1 +NODE_DIR=$self_path/nodejs +BROWSER_DIR=$self_path/web -if [ -n "$out" ]; then - echo "Will install package to $out (defined outside installPhase.sh script)" -else - export out="$self_path/outputs/out" - echo "Will install package to $out" +# Clear out the existing build artifacts as these aren't automatically removed by wasm-bindgen. +if [ -d ./pkg/ ]; then + rm -r $NODE_DIR + rm -r $BROWSER_DIR fi -run_or_fail $self_path/buildPhaseCargoCommand.sh -run_or_fail $self_path/installPhase.sh +TARGET=wasm32-unknown-unknown +WASM_BINARY=${self_path}/../../target/$TARGET/release/${pname}.wasm + +NODE_WASM=${NODE_DIR}/${pname}_bg.wasm +BROWSER_WASM=${BROWSER_DIR}/${pname}_bg.wasm -ln -s $out $self_path/result +# Build the new wasm package +run_or_fail cargo build --lib --release --target $TARGET --package ${pname} +run_or_fail wasm-bindgen $WASM_BINARY --out-dir $NODE_DIR --typescript --target nodejs +run_or_fail wasm-bindgen $WASM_BINARY --out-dir $BROWSER_DIR --typescript --target web +run_or_fail wasm-opt $NODE_WASM -o $NODE_WASM -O +run_or_fail wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O diff --git a/tooling/noirc_abi_wasm/buildPhaseCargoCommand.sh b/tooling/noirc_abi_wasm/buildPhaseCargoCommand.sh deleted file mode 100755 index 1188d00953e..00000000000 --- a/tooling/noirc_abi_wasm/buildPhaseCargoCommand.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash - -function run_or_fail { - "$@" - local status=$? - if [ $status -ne 0 ]; then - echo "Command '$*' failed with exit code $status" >&2 - exit $status - fi -} -function run_if_available { - if command -v "$1" >/dev/null 2>&1; then - "$@" - else - echo "$1 is not installed. Please install it to use this feature." >&2 - fi -} - -export self_path=$(dirname "$(readlink -f "$0")") - -# Clear out the existing build artifacts as these aren't automatically removed by wasm-pack. -if [ -d ./pkg/ ]; then - rm -rf $self_path/pkg/ -fi - -TARGET=wasm32-unknown-unknown -WASM_BINARY=$CARGO_TARGET_DIR/$TARGET/release/${pname}.wasm - -NODE_DIR=$self_path/nodejs/ -BROWSER_DIR=$self_path/web/ -NODE_WASM=${NODE_DIR}/${pname}_bg.wasm -BROWSER_WASM=${BROWSER_DIR}/${pname}_bg.wasm - -# Build the new wasm package -run_or_fail cargo build --lib --release --target $TARGET --package ${pname} -run_or_fail wasm-bindgen $WASM_BINARY --out-dir $NODE_DIR --typescript --target nodejs -run_or_fail wasm-bindgen $WASM_BINARY --out-dir $BROWSER_DIR --typescript --target web -run_if_available wasm-opt $NODE_WASM -o $NODE_WASM -O -run_if_available wasm-opt $BROWSER_WASM -o $BROWSER_WASM -O \ No newline at end of file diff --git a/tooling/noirc_abi_wasm/installPhase.sh b/tooling/noirc_abi_wasm/installPhase.sh deleted file mode 100755 index d9b94f2d171..00000000000 --- a/tooling/noirc_abi_wasm/installPhase.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -export self_path=$(dirname "$(readlink -f "$0")") - -export out_path=$out/noirc_abi_wasm - -mkdir -p $out_path -cp $self_path/README.md $out_path/ -cp $self_path/package.json $out_path/ -cp -r $self_path/nodejs $out_path/ -cp -r $self_path/web $out_path/ diff --git a/tooling/noirc_abi_wasm/package.json b/tooling/noirc_abi_wasm/package.json index 05fcc270402..14e528c3b15 100644 --- a/tooling/noirc_abi_wasm/package.json +++ b/tooling/noirc_abi_wasm/package.json @@ -3,7 +3,7 @@ "contributors": [ "The Noir Team " ], - "version": "0.24.0", + "version": "0.26.0", "license": "(MIT OR Apache-2.0)", "homepage": "https://noir-lang.org/", "repository": { @@ -33,9 +33,7 @@ "clean": "chmod u+w web nodejs || true && rm -rf ./nodejs ./web ./target ./result", "nightly:version": "jq --arg new_version \"-$(git rev-parse --short HEAD)$1\" '.version = .version + $new_version' package.json > package-tmp.json && mv package-tmp.json package.json", "publish": "echo 📡 publishing `$npm_package_name` && yarn npm publish", - "lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0", - "build:nix": "nix build -L .#noirc_abi_wasm", - "install:from:nix": "yarn clean && yarn build:nix && cp -rL ./result/noirc_abi_wasm/nodejs ./ && cp -rL ./result/noirc_abi_wasm/web ./" + "lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0" }, "dependencies": { "@noir-lang/types": "workspace:*" @@ -43,9 +41,9 @@ "devDependencies": { "@esm-bundle/chai": "^4.3.4-fix.0", "@web/dev-server-esbuild": "^0.3.6", - "@web/test-runner": "^0.15.3", + "@web/test-runner": "^0.18.1", "@web/test-runner-playwright": "^0.10.0", - "eslint": "^8.56.0", + "eslint": "^8.57.0", "mocha": "^10.2.0" } } diff --git a/wasm-bindgen-cli.nix b/wasm-bindgen-cli.nix deleted file mode 100644 index 7c3910f032e..00000000000 --- a/wasm-bindgen-cli.nix +++ /dev/null @@ -1,43 +0,0 @@ -{ lib -, rustPlatform -, fetchCrate -, nodejs -, pkg-config -, openssl -, stdenv -, curl -, darwin -, libiconv -, runCommand -}: - -rustPlatform.buildRustPackage rec { - pname = "wasm-bindgen-cli"; - version = "0.2.86"; - - src = fetchCrate { - inherit pname version; - sha256 = "sha256-56EOiLbdgAcoTrkyvB3t9TjtLaRvGxFUXx4haLwE2QY="; - }; - - cargoSha256 = "sha256-4CPBmz92PuPN6KeGDTdYPAf5+vTFk9EN5Cmx4QJy6yI="; - - nativeBuildInputs = [ pkg-config ]; - - buildInputs = [ openssl ] ++ lib.optionals stdenv.isDarwin [ - curl - # Need libiconv and apple Security on Darwin. See https://github.com/ipetkov/crane/issues/156 - libiconv - darwin.apple_sdk.frameworks.Security - ]; - - doCheck = false; - - meta = with lib; { - homepage = "https://rustwasm.github.io/docs/wasm-bindgen/"; - license = with licenses; [ asl20 /* or */ mit ]; - description = "Facilitating high-level interactions between wasm modules and JavaScript"; - maintainers = with maintainers; [ nitsky rizary ]; - mainProgram = "wasm-bindgen"; - }; -} diff --git a/yarn.lock b/yarn.lock index ace7959279f..a39ae9921da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -221,9 +221,9 @@ __metadata: languageName: node linkType: hard -"@aztec/bb.js@npm:0.24.0": - version: 0.24.0 - resolution: "@aztec/bb.js@npm:0.24.0" +"@aztec/bb.js@npm:0.32.0": + version: 0.32.0 + resolution: "@aztec/bb.js@npm:0.32.0" dependencies: comlink: ^4.4.1 commander: ^10.0.1 @@ -231,7 +231,7 @@ __metadata: tslib: ^2.4.0 bin: bb.js: dest/node/main.js - checksum: a086dabf30084cfa526e512148b9c02f0a0770dcc19b7dca4af9a3e98612b716acc7eaac6b52c0f12d985932e866d1cb9e534ded6ac9d747f3dd021afe25de27 + checksum: 0919957e141ae0a65cfab961dce122fa06de628a10b7cb661d31d8ed4793ce80980fcf315620ceffffa45581db941bad43c392f4b2aa9becaaf7d2faaba01ffc languageName: node linkType: hard @@ -3485,10 +3485,10 @@ __metadata: languageName: node linkType: hard -"@eslint/js@npm:8.56.0": - version: 8.56.0 - resolution: "@eslint/js@npm:8.56.0" - checksum: 5804130574ef810207bdf321c265437814e7a26f4e6fac9b496de3206afd52f533e09ec002a3be06cd9adcc9da63e727f1883938e663c4e4751c007d5b58e539 +"@eslint/js@npm:8.57.0": + version: 8.57.0 + resolution: "@eslint/js@npm:8.57.0" + checksum: 315dc65b0e9893e2bff139bddace7ea601ad77ed47b4550e73da8c9c2d2766c7a575c3cddf17ef85b8fd6a36ff34f91729d0dcca56e73ca887c10df91a41b0bb languageName: node linkType: hard @@ -3926,14 +3926,14 @@ __metadata: languageName: node linkType: hard -"@humanwhocodes/config-array@npm:^0.11.13": - version: 0.11.13 - resolution: "@humanwhocodes/config-array@npm:0.11.13" +"@humanwhocodes/config-array@npm:^0.11.14": + version: 0.11.14 + resolution: "@humanwhocodes/config-array@npm:0.11.14" dependencies: - "@humanwhocodes/object-schema": ^2.0.1 - debug: ^4.1.1 + "@humanwhocodes/object-schema": ^2.0.2 + debug: ^4.3.1 minimatch: ^3.0.5 - checksum: f8ea57b0d7ed7f2d64cd3944654976829d9da91c04d9c860e18804729a33f7681f78166ef4c761850b8c324d362f7d53f14c5c44907a6b38b32c703ff85e4805 + checksum: 861ccce9eaea5de19546653bccf75bf09fe878bc39c3aab00aeee2d2a0e654516adad38dd1098aab5e3af0145bbcbf3f309bdf4d964f8dab9dcd5834ae4c02f2 languageName: node linkType: hard @@ -3944,10 +3944,17 @@ __metadata: languageName: node linkType: hard -"@humanwhocodes/object-schema@npm:^2.0.1": - version: 2.0.1 - resolution: "@humanwhocodes/object-schema@npm:2.0.1" - checksum: 24929487b1ed48795d2f08346a0116cc5ee4634848bce64161fb947109352c562310fd159fc64dda0e8b853307f5794605191a9547f7341158559ca3c8262a45 +"@humanwhocodes/object-schema@npm:^2.0.2": + version: 2.0.2 + resolution: "@humanwhocodes/object-schema@npm:2.0.2" + checksum: 2fc11503361b5fb4f14714c700c02a3f4c7c93e9acd6b87a29f62c522d90470f364d6161b03d1cc618b979f2ae02aed1106fd29d302695d8927e2fc8165ba8ee + languageName: node + linkType: hard + +"@import-maps/resolve@npm:^1.0.1": + version: 1.0.1 + resolution: "@import-maps/resolve@npm:1.0.1" + checksum: 17ee033e26a0fd82294de87eae76d32b553a130fdbf0fb8c70d39f2087a3e8a4a5908970a99aa32bd175153efe9b7dfee6b7f99df36f41abed08c1911dbdb19c languageName: node linkType: hard @@ -4373,15 +4380,15 @@ __metadata: dependencies: "@esm-bundle/chai": ^4.3.4-fix.0 "@web/dev-server-esbuild": ^0.3.6 - "@web/test-runner": ^0.15.3 + "@web/test-runner": ^0.18.1 "@web/test-runner-playwright": ^0.10.0 - chai: ^4.3.7 - eslint: ^8.56.0 - eslint-plugin-prettier: ^5.0.0 + chai: ^4.4.1 + eslint: ^8.57.0 + eslint-plugin-prettier: ^5.1.3 mocha: ^10.2.0 - prettier: 3.0.3 + prettier: 3.2.5 ts-node: ^10.9.1 - typescript: ^5.0.4 + typescript: ^5.4.2 languageName: unknown linkType: soft @@ -4389,18 +4396,18 @@ __metadata: version: 0.0.0-use.local resolution: "@noir-lang/backend_barretenberg@workspace:tooling/noir_js_backend_barretenberg" dependencies: - "@aztec/bb.js": 0.24.0 + "@aztec/bb.js": 0.32.0 "@noir-lang/types": "workspace:*" "@types/node": ^20.6.2 "@types/prettier": ^3 - chai: ^4.3.8 - eslint: ^8.56.0 - eslint-plugin-prettier: ^5.0.0 + chai: ^4.4.1 + eslint: ^8.57.0 + eslint-plugin-prettier: ^5.1.3 fflate: ^0.8.0 mocha: ^10.2.0 - prettier: 3.0.3 + prettier: 3.2.5 ts-node: ^10.9.1 - typescript: 5.1.5 + typescript: 5.4.2 languageName: unknown linkType: soft @@ -4414,16 +4421,16 @@ __metadata: "@types/mocha": ^10.0.1 "@types/node": ^20.6.2 "@types/prettier": ^3 - chai: ^4.3.8 - eslint: ^8.56.0 - eslint-plugin-prettier: ^5.0.0 + chai: ^4.4.1 + eslint: ^8.57.0 + eslint-plugin-prettier: ^5.1.3 glob: ^10.3.10 mocha: ^10.2.0 - prettier: 3.0.3 + prettier: 3.2.5 ts-command-line-args: ^2.5.1 ts-node: ^10.9.1 tsx: ^4.6.2 - typescript: ^5.2.2 + typescript: ^5.4.2 bin: noir-codegen: lib/main.js languageName: unknown @@ -4440,15 +4447,15 @@ __metadata: "@types/mocha": ^10.0.1 "@types/node": ^20.6.2 "@types/prettier": ^3 - chai: ^4.3.8 - eslint: ^8.56.0 - eslint-plugin-prettier: ^5.0.0 + chai: ^4.4.1 + eslint: ^8.57.0 + eslint-plugin-prettier: ^5.1.3 mocha: ^10.2.0 - prettier: 3.0.3 + prettier: 3.2.5 ts-node: ^10.9.1 tsc-multi: ^1.1.0 tsx: ^4.6.2 - typescript: ^5.2.2 + typescript: ^5.4.2 languageName: unknown linkType: soft @@ -4470,28 +4477,28 @@ __metadata: "@types/sinon": ^17 "@wasm-tool/wasm-pack-plugin": ^1.7.0 "@web/dev-server-esbuild": ^0.3.6 - "@web/test-runner": ^0.18.0 + "@web/test-runner": ^0.18.1 "@web/test-runner-playwright": ^0.11.0 adm-zip: ^0.5.0 assert: ^2.1.0 browserify-fs: ^1.0.0 - chai: ^4.3.10 + chai: ^4.4.1 copy-webpack-plugin: ^12.0.2 - eslint: ^8.56.0 - eslint-plugin-prettier: ^5.0.0 + eslint: ^8.57.0 + eslint-plugin-prettier: ^5.1.3 html-webpack-plugin: ^5.6.0 memfs: ^4.6.0 mocha: ^10.2.0 mocha-each: ^2.0.1 pako: ^2.1.0 path-browserify: ^1.0.1 - prettier: 3.0.3 + prettier: 3.2.5 process: ^0.11.10 readable-stream: ^4.4.2 sinon: ^17.0.1 ts-loader: ^9.5.1 ts-node: ^10.9.1 - typescript: ~5.2.2 + typescript: ^5.4.2 unzipit: ^1.4.3 url: ^0.11.3 webpack: ^5.90.1 @@ -4507,9 +4514,9 @@ __metadata: "@esm-bundle/chai": ^4.3.4-fix.0 "@noir-lang/types": "workspace:*" "@web/dev-server-esbuild": ^0.3.6 - "@web/test-runner": ^0.15.3 + "@web/test-runner": ^0.18.1 "@web/test-runner-playwright": ^0.10.0 - eslint: ^8.56.0 + eslint: ^8.57.0 mocha: ^10.2.0 languageName: unknown linkType: soft @@ -4520,14 +4527,14 @@ __metadata: dependencies: "@typescript-eslint/eslint-plugin": ^6.7.3 "@typescript-eslint/parser": ^6.7.3 - chai: ^4.3.7 + chai: ^4.4.1 cspell: ^8.3.2 - eslint: ^8.56.0 - eslint-plugin-prettier: ^5.0.0 + eslint: ^8.57.0 + eslint-plugin-prettier: ^5.1.3 mocha: ^10.2.0 - prettier: 3.0.3 + prettier: 3.2.5 ts-node: ^10.9.1 - typescript: ^5.0.4 + typescript: ^5.4.2 languageName: unknown linkType: soft @@ -4536,10 +4543,10 @@ __metadata: resolution: "@noir-lang/types@workspace:tooling/noir_js_types" dependencies: "@types/prettier": ^3 - eslint: ^8.56.0 - eslint-plugin-prettier: ^5.0.0 - prettier: 3.0.3 - typescript: ^5.2.2 + eslint: ^8.57.0 + eslint-plugin-prettier: ^5.1.3 + prettier: 3.2.5 + typescript: ^5.4.2 languageName: unknown linkType: soft @@ -4869,17 +4876,10 @@ __metadata: languageName: node linkType: hard -"@pkgr/utils@npm:^2.4.2": - version: 2.4.2 - resolution: "@pkgr/utils@npm:2.4.2" - dependencies: - cross-spawn: ^7.0.3 - fast-glob: ^3.3.0 - is-glob: ^4.0.3 - open: ^9.1.0 - picocolors: ^1.0.0 - tslib: ^2.6.0 - checksum: 24e04c121269317d259614cd32beea3af38277151c4002df5883c4be920b8e3490bb897748e844f9d46bf68230f86dabd4e8f093773130e7e60529a769a132fc +"@pkgr/core@npm:^0.1.0": + version: 0.1.1 + resolution: "@pkgr/core@npm:0.1.1" + checksum: 6f25fd2e3008f259c77207ac9915b02f1628420403b2630c92a07ff963129238c9262afc9e84344c7a23b5cc1f3965e2cd17e3798219f5fd78a63d144d3cceba languageName: node linkType: hard @@ -4917,64 +4917,21 @@ __metadata: languageName: node linkType: hard -"@puppeteer/browsers@npm:0.5.0": - version: 0.5.0 - resolution: "@puppeteer/browsers@npm:0.5.0" - dependencies: - debug: 4.3.4 - extract-zip: 2.0.1 - https-proxy-agent: 5.0.1 - progress: 2.0.3 - proxy-from-env: 1.1.0 - tar-fs: 2.1.1 - unbzip2-stream: 1.4.3 - yargs: 17.7.1 - peerDependencies: - typescript: ">= 4.7.4" - peerDependenciesMeta: - typescript: - optional: true - bin: - browsers: lib/cjs/main-cli.js - checksum: d75fde03be4be106ca907834739251c2bb0b33a09fa23315c5dbe8b8b4cfed2f1b26af62e1dbe5fccc227e9bc87b51da0815461b982477eb01439bfdd6e7b01a - languageName: node - linkType: hard - -"@puppeteer/browsers@npm:1.4.6": - version: 1.4.6 - resolution: "@puppeteer/browsers@npm:1.4.6" +"@puppeteer/browsers@npm:2.1.0": + version: 2.1.0 + resolution: "@puppeteer/browsers@npm:2.1.0" dependencies: debug: 4.3.4 extract-zip: 2.0.1 progress: 2.0.3 - proxy-agent: 6.3.0 - tar-fs: 3.0.4 + proxy-agent: 6.4.0 + semver: 7.6.0 + tar-fs: 3.0.5 unbzip2-stream: 1.4.3 - yargs: 17.7.1 - peerDependencies: - typescript: ">= 4.7.4" - peerDependenciesMeta: - typescript: - optional: true + yargs: 17.7.2 bin: browsers: lib/cjs/main-cli.js - checksum: 29569dd8a8a41737bb0dd40cce6279cfc8764afc6242d2f9d8ae610bed7e466fc77eeb27b9b3ac53dd04927a1a0e26389f282f6ba057210979b36ab455009d64 - languageName: node - linkType: hard - -"@rollup/plugin-node-resolve@npm:^13.0.4": - version: 13.3.0 - resolution: "@rollup/plugin-node-resolve@npm:13.3.0" - dependencies: - "@rollup/pluginutils": ^3.1.0 - "@types/resolve": 1.17.1 - deepmerge: ^4.2.2 - is-builtin-module: ^3.1.0 - is-module: ^1.0.0 - resolve: ^1.19.0 - peerDependencies: - rollup: ^2.42.0 - checksum: ec5418e6b3c23a9e30683056b3010e9d325316dcfae93fbc673ae64dad8e56a2ce761c15c48f5e2dcfe0c822fdc4a4905ee6346e3dcf90603ba2260afef5a5e6 + checksum: 318740056fc716cf26179f053eb47e119bc01658f59382a19fb7d39e5b9232a7ad7d82e33445e0519683c13e22b328193fc9952c99d09cdc09f6539391d4749c languageName: node linkType: hard @@ -4997,19 +4954,6 @@ __metadata: languageName: node linkType: hard -"@rollup/pluginutils@npm:^3.1.0": - version: 3.1.0 - resolution: "@rollup/pluginutils@npm:3.1.0" - dependencies: - "@types/estree": 0.0.39 - estree-walker: ^1.0.1 - picomatch: ^2.2.2 - peerDependencies: - rollup: ^1.20.0||^2.0.0 - checksum: 8be16e27863c219edbb25a4e6ec2fe0e1e451d9e917b6a43cf2ae5bc025a6b8faaa40f82a6e53b66d0de37b58ff472c6c3d57a83037ae635041f8df959d6d9aa - languageName: node - linkType: hard - "@rollup/pluginutils@npm:^5.0.1": version: 5.1.0 resolution: "@rollup/pluginutils@npm:5.1.0" @@ -5778,13 +5722,6 @@ __metadata: languageName: node linkType: hard -"@types/estree@npm:0.0.39": - version: 0.0.39 - resolution: "@types/estree@npm:0.0.39" - checksum: 412fb5b9868f2c418126451821833414189b75cc6bf84361156feed733e3d92ec220b9d74a89e52722e03d5e241b2932732711b7497374a404fad49087adc248 - languageName: node - linkType: hard - "@types/express-serve-static-core@npm:*, @types/express-serve-static-core@npm:^4.17.33": version: 4.17.41 resolution: "@types/express-serve-static-core@npm:4.17.41" @@ -6020,13 +5957,6 @@ __metadata: languageName: node linkType: hard -"@types/mocha@npm:^8.2.0": - version: 8.2.3 - resolution: "@types/mocha@npm:8.2.3" - checksum: b43ed1b642a2ee62bf10792a07d5d21d66ab8b4d2cf5d822c8a7643e77b90009aecc000eefab5f6ddc9eb69004192f84119a6f97a8499e1a13ea082e7a5e71bf - languageName: node - linkType: hard - "@types/ms@npm:*": version: 0.7.34 resolution: "@types/ms@npm:0.7.34" @@ -6219,15 +6149,6 @@ __metadata: languageName: node linkType: hard -"@types/resolve@npm:1.17.1": - version: 1.17.1 - resolution: "@types/resolve@npm:1.17.1" - dependencies: - "@types/node": "*" - checksum: dc6a6df507656004e242dcb02c784479deca516d5f4b58a1707e708022b269ae147e1da0521f3e8ad0d63638869d87e0adc023f0bd5454aa6f72ac66c7525cf5 - languageName: node - linkType: hard - "@types/resolve@npm:1.20.2": version: 1.20.2 resolution: "@types/resolve@npm:1.20.2" @@ -6543,15 +6464,6 @@ __metadata: languageName: node linkType: hard -"@web/browser-logs@npm:^0.2.6": - version: 0.2.6 - resolution: "@web/browser-logs@npm:0.2.6" - dependencies: - errorstacks: ^2.2.0 - checksum: 82693e37a7e5a3c3df255e1e4feef6e6c2f2b7f5f883e1a9fd233d09a22c4f3e9e3dfd2ec809d7a02f0894156f26b89f1759bf4e9317640ee3630e9a3d9ec2a8 - languageName: node - linkType: hard - "@web/browser-logs@npm:^0.3.4": version: 0.3.4 resolution: "@web/browser-logs@npm:0.3.4" @@ -6570,15 +6482,6 @@ __metadata: languageName: node linkType: hard -"@web/config-loader@npm:^0.1.3": - version: 0.1.3 - resolution: "@web/config-loader@npm:0.1.3" - dependencies: - semver: ^7.3.4 - checksum: 278554bd00b757eaf296ba904a224c61d4698df1a5d6c04931c40bc6bb308e81e767055cbf283b763cc530aae6b200bb950aa19eb41aa8979a3a2b29e5f0ac7a - languageName: node - linkType: hard - "@web/config-loader@npm:^0.3.0": version: 0.3.1 resolution: "@web/config-loader@npm:0.3.1" @@ -6677,17 +6580,17 @@ __metadata: languageName: node linkType: hard -"@web/dev-server-rollup@npm:^0.4.1": - version: 0.4.1 - resolution: "@web/dev-server-rollup@npm:0.4.1" +"@web/dev-server-import-maps@npm:^0.2.0": + version: 0.2.0 + resolution: "@web/dev-server-import-maps@npm:0.2.0" dependencies: - "@rollup/plugin-node-resolve": ^13.0.4 - "@web/dev-server-core": ^0.4.1 - nanocolors: ^0.2.1 + "@import-maps/resolve": ^1.0.1 + "@types/parse5": ^6.0.1 + "@web/dev-server-core": ^0.7.0 + "@web/parse5-utils": ^2.1.0 parse5: ^6.0.1 - rollup: ^2.67.0 - whatwg-url: ^11.0.0 - checksum: a0c3566f67b5a5ead3822431302ddcaa9d043b18fdcf1190056a4e0539e5d5b545ebfecaf6021412eb4b5b6e074c2b1eff35c71e859195623c7c07e065f9df58 + picomatch: ^2.2.2 + checksum: 15dabfa385f023bab70758b80cc09443455830799793c1a404a7230d90ebf60e40984a10d8a6ceea2afb8f057e90a9f7356a76f867d5e5a2eeacbc397e41535a languageName: node linkType: hard @@ -6705,31 +6608,6 @@ __metadata: languageName: node linkType: hard -"@web/dev-server@npm:^0.1.38": - version: 0.1.38 - resolution: "@web/dev-server@npm:0.1.38" - dependencies: - "@babel/code-frame": ^7.12.11 - "@types/command-line-args": ^5.0.0 - "@web/config-loader": ^0.1.3 - "@web/dev-server-core": ^0.4.1 - "@web/dev-server-rollup": ^0.4.1 - camelcase: ^6.2.0 - command-line-args: ^5.1.1 - command-line-usage: ^7.0.1 - debounce: ^1.2.0 - deepmerge: ^4.2.2 - ip: ^1.1.5 - nanocolors: ^0.2.1 - open: ^8.0.2 - portfinder: ^1.0.32 - bin: - wds: dist/bin.js - web-dev-server: dist/bin.js - checksum: eeaf34f8744f58cfb9493155ad8548a87cae4e445a2fa894610b070f66cb303614d247bb609e378b9df342935ad980a259630317c444d19f9796abfcfb20bb13 - languageName: node - linkType: hard - "@web/dev-server@npm:^0.4.0": version: 0.4.1 resolution: "@web/dev-server@npm:0.4.1" @@ -6775,38 +6653,16 @@ __metadata: languageName: node linkType: hard -"@web/test-runner-chrome@npm:^0.12.1": - version: 0.12.1 - resolution: "@web/test-runner-chrome@npm:0.12.1" - dependencies: - "@web/test-runner-core": ^0.10.29 - "@web/test-runner-coverage-v8": ^0.5.0 - chrome-launcher: ^0.15.0 - puppeteer-core: ^19.8.1 - checksum: 08964e4c22c286231a6bdc003393316a7e0c7878560a9394d8bb9212c3c2e37799bc0aaf4732921213647c3dc89169146f65746d381feaa9c281c0373bf9da59 - languageName: node - linkType: hard - -"@web/test-runner-chrome@npm:^0.15.0": - version: 0.15.0 - resolution: "@web/test-runner-chrome@npm:0.15.0" +"@web/test-runner-chrome@npm:^0.16.0": + version: 0.16.0 + resolution: "@web/test-runner-chrome@npm:0.16.0" dependencies: "@web/test-runner-core": ^0.13.0 "@web/test-runner-coverage-v8": ^0.8.0 async-mutex: 0.4.0 chrome-launcher: ^0.15.0 - puppeteer-core: ^20.0.0 - checksum: 091aa83707aa1a6ade8074c37050f9a0fae2729f223b5e7d756f86ccdadcd85e738cc47d0a4ae8ac6ea930142cc20e341f5d3ad30a3a81d6666b353a7e8c2dd4 - languageName: node - linkType: hard - -"@web/test-runner-commands@npm:^0.6.6": - version: 0.6.6 - resolution: "@web/test-runner-commands@npm:0.6.6" - dependencies: - "@web/test-runner-core": ^0.10.29 - mkdirp: ^1.0.4 - checksum: b25533edd9ec59aeec28756a52ae4c6730388c336fa94e0c21eedf208012efd9aedf96c47ebad9a98cce9d87c4ee539b318a571e1e2bfb1bf8e5f1f6889c98e4 + puppeteer-core: ^22.0.0 + checksum: 99cfa93d12e8854fb2d104de1f8c5a73403e39fc56e5ed78e24f63e903299521750c7b475253dfb75293a2e604ed83d5cfdc1e593a72e9208a99a511bdb6169a languageName: node linkType: hard @@ -6820,40 +6676,6 @@ __metadata: languageName: node linkType: hard -"@web/test-runner-core@npm:^0.10.20, @web/test-runner-core@npm:^0.10.29": - version: 0.10.29 - resolution: "@web/test-runner-core@npm:0.10.29" - dependencies: - "@babel/code-frame": ^7.12.11 - "@types/babel__code-frame": ^7.0.2 - "@types/co-body": ^6.1.0 - "@types/convert-source-map": ^2.0.0 - "@types/debounce": ^1.2.0 - "@types/istanbul-lib-coverage": ^2.0.3 - "@types/istanbul-reports": ^3.0.0 - "@web/browser-logs": ^0.2.6 - "@web/dev-server-core": ^0.4.1 - chokidar: ^3.4.3 - cli-cursor: ^3.1.0 - co-body: ^6.1.0 - convert-source-map: ^2.0.0 - debounce: ^1.2.0 - dependency-graph: ^0.11.0 - globby: ^11.0.1 - ip: ^1.1.5 - istanbul-lib-coverage: ^3.0.0 - istanbul-lib-report: ^3.0.0 - istanbul-reports: ^3.0.2 - log-update: ^4.0.0 - nanocolors: ^0.2.1 - nanoid: ^3.1.25 - open: ^8.0.2 - picomatch: ^2.2.2 - source-map: ^0.7.3 - checksum: 635a510442bea3bce97596a2aed1c58a6154b4b83a44bf3e9c9497a751f42426cae5f67555916c4fd63064a4e91a5e26755e3090887ebac38ec0ab2691e1fe6c - languageName: node - linkType: hard - "@web/test-runner-core@npm:^0.12.0": version: 0.12.0 resolution: "@web/test-runner-core@npm:0.12.0" @@ -6922,18 +6744,6 @@ __metadata: languageName: node linkType: hard -"@web/test-runner-coverage-v8@npm:^0.5.0": - version: 0.5.0 - resolution: "@web/test-runner-coverage-v8@npm:0.5.0" - dependencies: - "@web/test-runner-core": ^0.10.20 - istanbul-lib-coverage: ^3.0.0 - picomatch: ^2.2.2 - v8-to-istanbul: ^9.0.1 - checksum: e69dc6379cff24f28bd21cc37a661945fbf7f3fd532da813e74f4042efe17fc191cdb7c09f1e1ea276167952b0116478ba0fe7af0966fa4867278c3a2cd772df - languageName: node - linkType: hard - "@web/test-runner-coverage-v8@npm:^0.7.3": version: 0.7.3 resolution: "@web/test-runner-coverage-v8@npm:0.7.3" @@ -6960,16 +6770,6 @@ __metadata: languageName: node linkType: hard -"@web/test-runner-mocha@npm:^0.7.5": - version: 0.7.5 - resolution: "@web/test-runner-mocha@npm:0.7.5" - dependencies: - "@types/mocha": ^8.2.0 - "@web/test-runner-core": ^0.10.20 - checksum: 12f87299945d230815bb783de2953ac4239306c1a67145ef5b78cfb0b361ae7f659e5d3e5150af2cedc6f2c55adf10652b761f016430a7ac2d7f77b91ecb9cd1 - languageName: node - linkType: hard - "@web/test-runner-mocha@npm:^0.9.0": version: 0.9.0 resolution: "@web/test-runner-mocha@npm:0.9.0" @@ -7001,41 +6801,14 @@ __metadata: languageName: node linkType: hard -"@web/test-runner@npm:^0.15.3": - version: 0.15.3 - resolution: "@web/test-runner@npm:0.15.3" - dependencies: - "@web/browser-logs": ^0.2.6 - "@web/config-loader": ^0.1.3 - "@web/dev-server": ^0.1.38 - "@web/test-runner-chrome": ^0.12.1 - "@web/test-runner-commands": ^0.6.6 - "@web/test-runner-core": ^0.10.29 - "@web/test-runner-mocha": ^0.7.5 - camelcase: ^6.2.0 - command-line-args: ^5.1.1 - command-line-usage: ^7.0.1 - convert-source-map: ^2.0.0 - diff: ^5.0.0 - globby: ^11.0.1 - nanocolors: ^0.2.1 - portfinder: ^1.0.32 - source-map: ^0.7.3 - bin: - web-test-runner: dist/bin.js - wtr: dist/bin.js - checksum: 75d00d4f15f9977ff4e8fca84e1c7f9d834073688df06d9e4b62bf43cad65a36b2ae21b9ebab5706e4d3b07fc639bb90758b1be1df036c8b80137ec3407a8f08 - languageName: node - linkType: hard - -"@web/test-runner@npm:^0.18.0": - version: 0.18.0 - resolution: "@web/test-runner@npm:0.18.0" +"@web/test-runner@npm:^0.18.1": + version: 0.18.1 + resolution: "@web/test-runner@npm:0.18.1" dependencies: "@web/browser-logs": ^0.4.0 "@web/config-loader": ^0.3.0 "@web/dev-server": ^0.4.0 - "@web/test-runner-chrome": ^0.15.0 + "@web/test-runner-chrome": ^0.16.0 "@web/test-runner-commands": ^0.9.0 "@web/test-runner-core": ^0.13.0 "@web/test-runner-mocha": ^0.9.0 @@ -7051,7 +6824,7 @@ __metadata: bin: web-test-runner: dist/bin.js wtr: dist/bin.js - checksum: d5e410f08cb954f9854a3d837f5f704b578376ee8b0452cff66aeca2eb3cb98e50556ca3b958bda567b42af2ef2cd0a7424eaea40f9b3e80362ae788fbd33118 + checksum: eb21fc5978da2ccbfd6ffac0f61b519036d68a9cdcf211c1dbafa9c6b6f92bb10a9267dec02f4d71dfc45e636166d98712ff9a347af951eabff99b0d7e5899b5 languageName: node linkType: hard @@ -7937,6 +7710,41 @@ __metadata: languageName: node linkType: hard +"bare-events@npm:^2.0.0, bare-events@npm:^2.2.0": + version: 2.2.1 + resolution: "bare-events@npm:2.2.1" + checksum: f4f830fe780b105fce189180761cf69ac60848212133ca7d29eb94f8888f813bf70f339e4e651b200aa8304fc9dc77ca7443756cc68b43294367b5867ad4536b + languageName: node + linkType: hard + +"bare-fs@npm:^2.1.1": + version: 2.2.2 + resolution: "bare-fs@npm:2.2.2" + dependencies: + bare-events: ^2.0.0 + bare-os: ^2.0.0 + bare-path: ^2.0.0 + streamx: ^2.13.0 + checksum: 5b6d26690ee4de93b559f6a1187b6ff553224fe4faea5ef9cbd235b13e033ef96a598dc28eb10aad17d1f35baed24e14e18436534041913f905a0c50ed27713a + languageName: node + linkType: hard + +"bare-os@npm:^2.0.0, bare-os@npm:^2.1.0": + version: 2.2.1 + resolution: "bare-os@npm:2.2.1" + checksum: 7d870d8955531809253dfbceeda5b68e8396ef640166f8ff6c4c5e344f18a6bc9253f6d5e7d9ae2841426b66e9b7b1a39b2a102e6b23e1ddff26ad8a8981af81 + languageName: node + linkType: hard + +"bare-path@npm:^2.0.0, bare-path@npm:^2.1.0": + version: 2.1.0 + resolution: "bare-path@npm:2.1.0" + dependencies: + bare-os: ^2.1.0 + checksum: 03f260e72bd0ae0df4cd712322a2d3c8c16701ffaa55cf2d517ae62b7f78c64b7ec5bba81ec579367f966472481f5160db282e6663bd0fc8cfb09ebe272d8bba + languageName: node + linkType: hard + "base-x@npm:^3.0.2": version: 3.0.9 resolution: "base-x@npm:3.0.9" @@ -7974,13 +7782,6 @@ __metadata: languageName: node linkType: hard -"big-integer@npm:^1.6.44": - version: 1.6.52 - resolution: "big-integer@npm:1.6.52" - checksum: 6e86885787a20fed96521958ae9086960e4e4b5e74d04f3ef7513d4d0ad631a9f3bde2730fc8aaa4b00419fc865f6ec573e5320234531ef37505da7da192c40b - languageName: node - linkType: hard - "big.js@npm:^5.2.2": version: 5.2.2 resolution: "big.js@npm:5.2.2" @@ -8002,17 +7803,6 @@ __metadata: languageName: node linkType: hard -"bl@npm:^4.0.3": - version: 4.1.0 - resolution: "bl@npm:4.1.0" - dependencies: - buffer: ^5.5.0 - inherits: ^2.0.4 - readable-stream: ^3.4.0 - checksum: 9e8521fa7e83aa9427c6f8ccdcba6e8167ef30cc9a22df26effcc5ab682ef91d2cbc23a239f945d099289e4bbcfae7a192e9c28c84c6202e710a0dfec3722662 - languageName: node - linkType: hard - "bl@npm:~0.8.1": version: 0.8.2 resolution: "bl@npm:0.8.2" @@ -8156,15 +7946,6 @@ __metadata: languageName: node linkType: hard -"bplist-parser@npm:^0.2.0": - version: 0.2.0 - resolution: "bplist-parser@npm:0.2.0" - dependencies: - big-integer: ^1.6.44 - checksum: d5339dd16afc51de6c88f88f58a45b72ed6a06aa31f5557d09877575f220b7c1d3fbe375da0b62e6a10d4b8ed80523567e351f24014f5bc886ad523758142cdd - languageName: node - linkType: hard - "brace-expansion@npm:^1.1.7": version: 1.1.11 resolution: "brace-expansion@npm:1.1.11" @@ -8299,7 +8080,7 @@ __metadata: languageName: node linkType: hard -"buffer@npm:^5.2.1, buffer@npm:^5.5.0": +"buffer@npm:^5.2.1": version: 5.7.1 resolution: "buffer@npm:5.7.1" dependencies: @@ -8326,15 +8107,6 @@ __metadata: languageName: node linkType: hard -"bundle-name@npm:^3.0.0": - version: 3.0.0 - resolution: "bundle-name@npm:3.0.0" - dependencies: - run-applescript: ^5.0.0 - checksum: edf2b1fbe6096ed32e7566947ace2ea937ee427391744d7510a2880c4b9a5b3543d3f6c551236a29e5c87d3195f8e2912516290e638c15bcbede7b37cc375615 - languageName: node - linkType: hard - "bundle-name@npm:^4.1.0": version: 4.1.0 resolution: "bundle-name@npm:4.1.0" @@ -8532,9 +8304,9 @@ __metadata: languageName: node linkType: hard -"chai@npm:^4.3.10, chai@npm:^4.3.7, chai@npm:^4.3.8": - version: 4.3.10 - resolution: "chai@npm:4.3.10" +"chai@npm:^4.4.1": + version: 4.4.1 + resolution: "chai@npm:4.4.1" dependencies: assertion-error: ^1.1.0 check-error: ^1.0.3 @@ -8543,7 +8315,7 @@ __metadata: loupe: ^2.3.6 pathval: ^1.1.1 type-detect: ^4.0.8 - checksum: 536668c60a0d985a0fbd94418028e388d243a925d7c5e858c7443e334753511614a3b6a124bac9ca077dfc4c37acc367d62f8c294960f440749536dc181dfc6d + checksum: 9ab84f36eb8e0b280c56c6c21ca4da5933132cd8a0c89c384f1497f77953640db0bc151edd47f81748240a9fab57b78f7d925edfeedc8e8fc98016d71f40c36e languageName: node linkType: hard @@ -8732,13 +8504,6 @@ __metadata: languageName: node linkType: hard -"chownr@npm:^1.1.1": - version: 1.1.4 - resolution: "chownr@npm:1.1.4" - checksum: 115648f8eb38bac5e41c3857f3e663f9c39ed6480d1349977c4d96c95a47266fcacc5a5aabf3cb6c481e22d72f41992827db47301851766c4fd77ac21a4f081d - languageName: node - linkType: hard - "chownr@npm:^2.0.0": version: 2.0.0 resolution: "chownr@npm:2.0.0" @@ -8767,25 +8532,15 @@ __metadata: languageName: node linkType: hard -"chromium-bidi@npm:0.4.16": - version: 0.4.16 - resolution: "chromium-bidi@npm:0.4.16" - dependencies: - mitt: 3.0.0 - peerDependencies: - devtools-protocol: "*" - checksum: 9cbb362fdf589dbdfd1618499c5bbdac45a3aa1291c1d2faa2f1ea3768738677985175d1bb1511dfe3e188bc78e6ea2acb453564ece7e09f535bbcd2253ce06a - languageName: node - linkType: hard - -"chromium-bidi@npm:0.4.7": - version: 0.4.7 - resolution: "chromium-bidi@npm:0.4.7" +"chromium-bidi@npm:0.5.12": + version: 0.5.12 + resolution: "chromium-bidi@npm:0.5.12" dependencies: - mitt: 3.0.0 + mitt: 3.0.1 + urlpattern-polyfill: 10.0.0 peerDependencies: devtools-protocol: "*" - checksum: eec7581e2eddd2c95014c6edc5aae0b036c79bbeadee05166436b16139b6932c902c5ce21d95ed919a592f58d3a47c5469dc5f3de2a300700b2748ab119ad65e + checksum: c14aedc9725a813d82ce66423750757383af6d7580b4f22f8756d31a340b8d6d77dd30a4de0e213f2f89e63faf54a333431acc07675791f1c176d2275e499525 languageName: node linkType: hard @@ -9522,15 +9277,6 @@ __metadata: languageName: node linkType: hard -"cross-fetch@npm:3.1.5": - version: 3.1.5 - resolution: "cross-fetch@npm:3.1.5" - dependencies: - node-fetch: 2.6.7 - checksum: f6b8c6ee3ef993ace6277fd789c71b6acf1b504fd5f5c7128df4ef2f125a429e29cd62dc8c127523f04a5f2fa4771ed80e3f3d9695617f441425045f505cf3bb - languageName: node - linkType: hard - "cross-fetch@npm:4.0.0": version: 4.0.0 resolution: "cross-fetch@npm:4.0.0" @@ -9926,7 +9672,7 @@ __metadata: languageName: node linkType: hard -"debug@npm:4, debug@npm:4.3.4, debug@npm:^4.0.0, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.2.0, debug@npm:^4.3.2, debug@npm:^4.3.3, debug@npm:^4.3.4": +"debug@npm:4, debug@npm:4.3.4, debug@npm:^4.0.0, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.2.0, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.3, debug@npm:^4.3.4": version: 4.3.4 resolution: "debug@npm:4.3.4" dependencies: @@ -10018,16 +9764,6 @@ __metadata: languageName: node linkType: hard -"default-browser-id@npm:^3.0.0": - version: 3.0.0 - resolution: "default-browser-id@npm:3.0.0" - dependencies: - bplist-parser: ^0.2.0 - untildify: ^4.0.0 - checksum: 279c7ad492542e5556336b6c254a4eaf31b2c63a5433265655ae6e47301197b6cfb15c595a6fdc6463b2ff8e1a1a1ed3cba56038a60e1527ba4ab1628c6b9941 - languageName: node - linkType: hard - "default-browser-id@npm:^5.0.0": version: 5.0.0 resolution: "default-browser-id@npm:5.0.0" @@ -10035,18 +9771,6 @@ __metadata: languageName: node linkType: hard -"default-browser@npm:^4.0.0": - version: 4.0.0 - resolution: "default-browser@npm:4.0.0" - dependencies: - bundle-name: ^3.0.0 - default-browser-id: ^3.0.0 - execa: ^7.1.1 - titleize: ^3.0.0 - checksum: 40c5af984799042b140300be5639c9742599bda76dc9eba5ac9ad5943c83dd36cebc4471eafcfddf8e0ec817166d5ba89d56f08e66a126c7c7908a179cead1a7 - languageName: node - linkType: hard - "default-browser@npm:^5.2.1": version: 5.2.1 resolution: "default-browser@npm:5.2.1" @@ -10252,17 +9976,10 @@ __metadata: languageName: node linkType: hard -"devtools-protocol@npm:0.0.1107588": - version: 0.0.1107588 - resolution: "devtools-protocol@npm:0.0.1107588" - checksum: 9064fd643f39ae0adabb8f425b746899ff24371d89a5047d38752653259e6afcb6bcb2d9759ff727eb5885cfc0f9ba8eb384850a2af00694135622e88080e3e5 - languageName: node - linkType: hard - -"devtools-protocol@npm:0.0.1147663": - version: 0.0.1147663 - resolution: "devtools-protocol@npm:0.0.1147663" - checksum: 0631f2b6c6cd7f56e7d62a85bfc291f7e167f0f2de90969ef61fb24e2bd546b2e9530043d2bc3fe6c4d7a9e00473004272d2c2832a10a05e4b75c03a22f549fc +"devtools-protocol@npm:0.0.1249869": + version: 0.0.1249869 + resolution: "devtools-protocol@npm:0.0.1249869" + checksum: 549dda02f6d778741930e5abdde3f8e5d39e16fdbe8af38597a974e9c239798dd464250bd7ab4360d77e3d059620e95be7cf05150142473bf9b661ed28a616ed languageName: node linkType: hard @@ -10330,9 +10047,9 @@ __metadata: axios: ^1.4.0 clsx: ^1.2.1 docusaurus-plugin-typedoc: 1.0.0-next.18 - eslint-plugin-prettier: ^5.0.0 + eslint-plugin-prettier: ^5.1.3 hast-util-is-element: ^1.1.0 - prettier: 3.0.3 + prettier: 3.2.5 prism-react-renderer: ^2.1.0 react: ^18.2.0 react-dom: ^18.2.0 @@ -10345,7 +10062,7 @@ __metadata: typedoc-plugin-frontmatter: ^0.0.2 typedoc-plugin-markdown: 4.0.0-next.25 typedoc-plugin-merge-modules: ^5.1.0 - typescript: ~5.2.2 + typescript: ^5.4.2 languageName: unknown linkType: soft @@ -10583,7 +10300,7 @@ __metadata: languageName: node linkType: hard -"end-of-stream@npm:^1.1.0, end-of-stream@npm:^1.4.1": +"end-of-stream@npm:^1.1.0": version: 1.4.4 resolution: "end-of-stream@npm:1.4.4" dependencies: @@ -10904,22 +10621,23 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-prettier@npm:^5.0.0": - version: 5.0.1 - resolution: "eslint-plugin-prettier@npm:5.0.1" +"eslint-plugin-prettier@npm:^5.1.3": + version: 5.1.3 + resolution: "eslint-plugin-prettier@npm:5.1.3" dependencies: prettier-linter-helpers: ^1.0.0 - synckit: ^0.8.5 + synckit: ^0.8.6 peerDependencies: "@types/eslint": ">=8.0.0" eslint: ">=8.0.0" + eslint-config-prettier: "*" prettier: ">=3.0.0" peerDependenciesMeta: "@types/eslint": optional: true eslint-config-prettier: optional: true - checksum: c2261033b97bafe99ccb7cc47c2fac6fa85b8bbc8b128042e52631f906b69e12afed2cdd9d7e3021cc892ee8dd4204a3574e1f32a0b718b4bb3b440944b6983b + checksum: eb2a7d46a1887e1b93788ee8f8eb81e0b6b2a6f5a66a62bc6f375b033fc4e7ca16448da99380be800042786e76cf5c0df9c87a51a2c9b960ed47acbd7c0b9381 languageName: node linkType: hard @@ -10950,15 +10668,15 @@ __metadata: languageName: node linkType: hard -"eslint@npm:^8.56.0": - version: 8.56.0 - resolution: "eslint@npm:8.56.0" +"eslint@npm:^8.57.0": + version: 8.57.0 + resolution: "eslint@npm:8.57.0" dependencies: "@eslint-community/eslint-utils": ^4.2.0 "@eslint-community/regexpp": ^4.6.1 "@eslint/eslintrc": ^2.1.4 - "@eslint/js": 8.56.0 - "@humanwhocodes/config-array": ^0.11.13 + "@eslint/js": 8.57.0 + "@humanwhocodes/config-array": ^0.11.14 "@humanwhocodes/module-importer": ^1.0.1 "@nodelib/fs.walk": ^1.2.8 "@ungap/structured-clone": ^1.2.0 @@ -10994,7 +10712,7 @@ __metadata: text-table: ^0.2.0 bin: eslint: bin/eslint.js - checksum: 883436d1e809b4a25d9eb03d42f584b84c408dbac28b0019f6ea07b5177940bf3cca86208f749a6a1e0039b63e085ee47aca1236c30721e91f0deef5cc5a5136 + checksum: 3a48d7ff85ab420a8447e9810d8087aea5b1df9ef68c9151732b478de698389ee656fd895635b5f2871c89ee5a2652b3f343d11e9db6f8486880374ebc74a2d9 languageName: node linkType: hard @@ -11110,13 +10828,6 @@ __metadata: languageName: node linkType: hard -"estree-walker@npm:^1.0.1": - version: 1.0.1 - resolution: "estree-walker@npm:1.0.1" - checksum: 7e70da539691f6db03a08e7ce94f394ce2eef4180e136d251af299d41f92fb2d28ebcd9a6e393e3728d7970aeb5358705ddf7209d52fbcb2dd4693f95dcf925f - languageName: node - linkType: hard - "estree-walker@npm:^2.0.2": version: 2.0.2 resolution: "estree-walker@npm:2.0.2" @@ -11336,23 +11047,6 @@ __metadata: languageName: node linkType: hard -"execa@npm:^7.1.1": - version: 7.2.0 - resolution: "execa@npm:7.2.0" - dependencies: - cross-spawn: ^7.0.3 - get-stream: ^6.0.1 - human-signals: ^4.3.0 - is-stream: ^3.0.0 - merge-stream: ^2.0.0 - npm-run-path: ^5.1.0 - onetime: ^6.0.0 - signal-exit: ^3.0.7 - strip-final-newline: ^3.0.0 - checksum: 14fd17ba0ca8c87b277584d93b1d9fc24f2a65e5152b31d5eb159a3b814854283eaae5f51efa9525e304447e2f757c691877f7adff8fde5746aae67eb1edd1cc - languageName: node - linkType: hard - "exponential-backoff@npm:^3.1.1": version: 3.1.1 resolution: "exponential-backoff@npm:3.1.1" @@ -11866,13 +11560,6 @@ __metadata: languageName: node linkType: hard -"fs-constants@npm:^1.0.0": - version: 1.0.0 - resolution: "fs-constants@npm:1.0.0" - checksum: 18f5b718371816155849475ac36c7d0b24d39a11d91348cfcb308b4494824413e03572c403c86d3a260e049465518c4f0d5bd00f0371cdfcad6d4f30a85b350d - languageName: node - linkType: hard - "fs-extra@npm:^0.30.0": version: 0.30.0 resolution: "fs-extra@npm:0.30.0" @@ -13109,6 +12796,16 @@ __metadata: languageName: node linkType: hard +"http-proxy-agent@npm:^7.0.1": + version: 7.0.2 + resolution: "http-proxy-agent@npm:7.0.2" + dependencies: + agent-base: ^7.1.0 + debug: ^4.3.4 + checksum: 670858c8f8f3146db5889e1fa117630910101db601fff7d5a8aa637da0abedf68c899f03d3451cac2f83bcc4c3d2dabf339b3aa00ff8080571cceb02c3ce02f3 + languageName: node + linkType: hard + "http-proxy-middleware@npm:^2.0.3": version: 2.0.6 resolution: "http-proxy-middleware@npm:2.0.6" @@ -13148,7 +12845,7 @@ __metadata: languageName: node linkType: hard -"https-proxy-agent@npm:5.0.1, https-proxy-agent@npm:^5.0.0": +"https-proxy-agent@npm:^5.0.0": version: 5.0.1 resolution: "https-proxy-agent@npm:5.0.1" dependencies: @@ -13158,7 +12855,7 @@ __metadata: languageName: node linkType: hard -"https-proxy-agent@npm:^7.0.0, https-proxy-agent@npm:^7.0.1, https-proxy-agent@npm:^7.0.2": +"https-proxy-agent@npm:^7.0.1, https-proxy-agent@npm:^7.0.2": version: 7.0.2 resolution: "https-proxy-agent@npm:7.0.2" dependencies: @@ -13168,6 +12865,16 @@ __metadata: languageName: node linkType: hard +"https-proxy-agent@npm:^7.0.3": + version: 7.0.4 + resolution: "https-proxy-agent@npm:7.0.4" + dependencies: + agent-base: ^7.0.2 + debug: 4 + checksum: daaab857a967a2519ddc724f91edbbd388d766ff141b9025b629f92b9408fc83cee8a27e11a907aede392938e9c398e240d643e178408a59e4073539cde8cfe9 + languageName: node + linkType: hard + "human-signals@npm:^2.1.0": version: 2.1.0 resolution: "human-signals@npm:2.1.0" @@ -13175,13 +12882,6 @@ __metadata: languageName: node linkType: hard -"human-signals@npm:^4.3.0": - version: 4.3.1 - resolution: "human-signals@npm:4.3.1" - checksum: 6f12958df3f21b6fdaf02d90896c271df00636a31e2bbea05bddf817a35c66b38a6fdac5863e2df85bd52f34958997f1f50350ff97249e1dff8452865d5235d1 - languageName: node - linkType: hard - "hyperdyperid@npm:^1.2.0": version: 1.2.0 resolution: "hyperdyperid@npm:1.2.0" @@ -13416,13 +13116,14 @@ __metadata: "@nomicfoundation/hardhat-chai-matchers": ^2.0.0 "@nomicfoundation/hardhat-ethers": ^3.0.0 "@web/dev-server-esbuild": ^0.3.6 - "@web/test-runner": ^0.15.3 + "@web/dev-server-import-maps": ^0.2.0 + "@web/test-runner": ^0.18.1 "@web/test-runner-playwright": ^0.10.0 - eslint: ^8.56.0 - eslint-plugin-prettier: ^5.0.0 + eslint: ^8.57.0 + eslint-plugin-prettier: ^5.1.3 ethers: ^6.7.1 hardhat: ^2.17.4 - prettier: 3.0.3 + prettier: 3.2.5 smol-toml: ^1.1.2 toml: ^3.0.0 tslog: ^4.9.2 @@ -13556,7 +13257,7 @@ __metadata: languageName: node linkType: hard -"is-builtin-module@npm:^3.1.0, is-builtin-module@npm:^3.2.1": +"is-builtin-module@npm:^3.2.1": version: 3.2.1 resolution: "is-builtin-module@npm:3.2.1" dependencies: @@ -13877,13 +13578,6 @@ __metadata: languageName: node linkType: hard -"is-stream@npm:^3.0.0": - version: 3.0.0 - resolution: "is-stream@npm:3.0.0" - checksum: 172093fe99119ffd07611ab6d1bcccfe8bc4aa80d864b15f43e63e54b7abc71e779acd69afdb854c4e2a67fdc16ae710e370eda40088d1cfc956a50ed82d8f16 - languageName: node - linkType: hard - "is-typed-array@npm:^1.1.3": version: 1.1.12 resolution: "is-typed-array@npm:1.1.12" @@ -16012,13 +15706,6 @@ __metadata: languageName: node linkType: hard -"mimic-fn@npm:^4.0.0": - version: 4.0.0 - resolution: "mimic-fn@npm:4.0.0" - checksum: 995dcece15ee29aa16e188de6633d43a3db4611bcf93620e7e62109ec41c79c0f34277165b8ce5e361205049766e371851264c21ac64ca35499acb5421c2ba56 - languageName: node - linkType: hard - "mimic-response@npm:^1.0.0, mimic-response@npm:^1.0.1": version: 1.0.1 resolution: "mimic-response@npm:1.0.1" @@ -16183,17 +15870,10 @@ __metadata: languageName: node linkType: hard -"mitt@npm:3.0.0": - version: 3.0.0 - resolution: "mitt@npm:3.0.0" - checksum: f7be5049d27d18b1dbe9408452d66376fa60ae4a79fe9319869d1b90ae8cbaedadc7e9dab30b32d781411256d468be5538996bb7368941c09009ef6bbfa6bfc7 - languageName: node - linkType: hard - -"mkdirp-classic@npm:^0.5.2": - version: 0.5.3 - resolution: "mkdirp-classic@npm:0.5.3" - checksum: 3f4e088208270bbcc148d53b73e9a5bd9eef05ad2cbf3b3d0ff8795278d50dd1d11a8ef1875ff5aea3fa888931f95bfcb2ad5b7c1061cfefd6284d199e6776ac +"mitt@npm:3.0.1": + version: 3.0.1 + resolution: "mitt@npm:3.0.1" + checksum: b55a489ac9c2949ab166b7f060601d3b6d893a852515ae9eca4e11df01c013876df777ea109317622b5c1c60e8aae252558e33c8c94e14124db38f64a39614b1 languageName: node linkType: hard @@ -16427,20 +16107,6 @@ __metadata: languageName: node linkType: hard -"node-fetch@npm:2.6.7": - version: 2.6.7 - resolution: "node-fetch@npm:2.6.7" - dependencies: - whatwg-url: ^5.0.0 - peerDependencies: - encoding: ^0.1.0 - peerDependenciesMeta: - encoding: - optional: true - checksum: 8d816ffd1ee22cab8301c7756ef04f3437f18dace86a1dae22cf81db8ef29c0bf6655f3215cb0cdb22b420b6fe141e64b26905e7f33f9377a7fa59135ea3e10b - languageName: node - linkType: hard - "node-fetch@npm:^2.6.12": version: 2.7.0 resolution: "node-fetch@npm:2.7.0" @@ -16555,15 +16221,6 @@ __metadata: languageName: node linkType: hard -"npm-run-path@npm:^5.1.0": - version: 5.1.0 - resolution: "npm-run-path@npm:5.1.0" - dependencies: - path-key: ^4.0.0 - checksum: dc184eb5ec239d6a2b990b43236845332ef12f4e0beaa9701de724aa797fe40b6bbd0157fb7639d24d3ab13f5d5cf22d223a19c6300846b8126f335f788bee66 - languageName: node - linkType: hard - "nprogress@npm:^0.2.0": version: 0.2.0 resolution: "nprogress@npm:0.2.0" @@ -16696,15 +16353,6 @@ __metadata: languageName: node linkType: hard -"onetime@npm:^6.0.0": - version: 6.0.0 - resolution: "onetime@npm:6.0.0" - dependencies: - mimic-fn: ^4.0.0 - checksum: 0846ce78e440841335d4e9182ef69d5762e9f38aa7499b19f42ea1c4cd40f0b4446094c455c713f9adac3f4ae86f613bb5e30c99e52652764d06a89f709b3788 - languageName: node - linkType: hard - "only@npm:~0.0.2": version: 0.0.2 resolution: "only@npm:0.0.2" @@ -16735,18 +16383,6 @@ __metadata: languageName: node linkType: hard -"open@npm:^9.1.0": - version: 9.1.0 - resolution: "open@npm:9.1.0" - dependencies: - default-browser: ^4.0.0 - define-lazy-prop: ^3.0.0 - is-inside-container: ^1.0.0 - is-wsl: ^2.2.0 - checksum: 3993c0f61d51fed8ac290e99c9c3cf45d3b6cfb3e2aa2b74cafd312c3486c22fd81df16ac8f3ab91dd8a4e3e729a16fc2480cfc406c4833416cf908acf1ae7c9 - languageName: node - linkType: hard - "opener@npm:^1.5.2": version: 1.5.2 resolution: "opener@npm:1.5.2" @@ -16932,7 +16568,7 @@ __metadata: languageName: node linkType: hard -"pac-proxy-agent@npm:^7.0.0": +"pac-proxy-agent@npm:^7.0.1": version: 7.0.1 resolution: "pac-proxy-agent@npm:7.0.1" dependencies: @@ -17159,13 +16795,6 @@ __metadata: languageName: node linkType: hard -"path-key@npm:^4.0.0": - version: 4.0.0 - resolution: "path-key@npm:4.0.0" - checksum: 8e6c314ae6d16b83e93032c61020129f6f4484590a777eed709c4a01b50e498822b00f76ceaf94bc64dbd90b327df56ceadce27da3d83393790f1219e07721d7 - languageName: node - linkType: hard - "path-parse@npm:^1.0.6, path-parse@npm:^1.0.7": version: 1.0.7 resolution: "path-parse@npm:1.0.7" @@ -17811,12 +17440,12 @@ __metadata: languageName: node linkType: hard -"prettier@npm:3.0.3": - version: 3.0.3 - resolution: "prettier@npm:3.0.3" +"prettier@npm:3.2.5": + version: 3.2.5 + resolution: "prettier@npm:3.2.5" bin: prettier: bin/prettier.cjs - checksum: e10b9af02b281f6c617362ebd2571b1d7fc9fb8a3bd17e371754428cda992e5e8d8b7a046e8f7d3e2da1dcd21aa001e2e3c797402ebb6111b5cd19609dd228e0 + checksum: 2ee4e1417572372afb7a13bb446b34f20f1bf1747db77cf6ccaf57a9be005f2f15c40f903d41a6b79eec3f57fff14d32a20fb6dee1f126da48908926fe43c311 languageName: node linkType: hard @@ -17948,23 +17577,23 @@ __metadata: languageName: node linkType: hard -"proxy-agent@npm:6.3.0": - version: 6.3.0 - resolution: "proxy-agent@npm:6.3.0" +"proxy-agent@npm:6.4.0": + version: 6.4.0 + resolution: "proxy-agent@npm:6.4.0" dependencies: agent-base: ^7.0.2 debug: ^4.3.4 - http-proxy-agent: ^7.0.0 - https-proxy-agent: ^7.0.0 + http-proxy-agent: ^7.0.1 + https-proxy-agent: ^7.0.3 lru-cache: ^7.14.1 - pac-proxy-agent: ^7.0.0 + pac-proxy-agent: ^7.0.1 proxy-from-env: ^1.1.0 - socks-proxy-agent: ^8.0.1 - checksum: e3fb0633d665e352ed4efe23ae5616b8301423dfa4ff1c5975d093da8a636181a97391f7a91c6a7ffae17c1a305df855e95507f73bcdafda8876198c64b88f5b + socks-proxy-agent: ^8.0.2 + checksum: 4d3794ad5e07486298902f0a7f250d0f869fa0e92d790767ca3f793a81374ce0ab6c605f8ab8e791c4d754da96656b48d1c24cb7094bfd310a15867e4a0841d7 languageName: node linkType: hard -"proxy-from-env@npm:1.1.0, proxy-from-env@npm:^1.1.0": +"proxy-from-env@npm:^1.1.0": version: 1.1.0 resolution: "proxy-from-env@npm:1.1.0" checksum: ed7fcc2ba0a33404958e34d95d18638249a68c430e30fcb6c478497d72739ba64ce9810a24f53a7d921d0c065e5b78e3822759800698167256b04659366ca4d4 @@ -18027,46 +17656,17 @@ __metadata: languageName: node linkType: hard -"puppeteer-core@npm:^19.8.1": - version: 19.11.1 - resolution: "puppeteer-core@npm:19.11.1" - dependencies: - "@puppeteer/browsers": 0.5.0 - chromium-bidi: 0.4.7 - cross-fetch: 3.1.5 - debug: 4.3.4 - devtools-protocol: 0.0.1107588 - extract-zip: 2.0.1 - https-proxy-agent: 5.0.1 - proxy-from-env: 1.1.0 - tar-fs: 2.1.1 - unbzip2-stream: 1.4.3 - ws: 8.13.0 - peerDependencies: - typescript: ">= 4.7.4" - peerDependenciesMeta: - typescript: - optional: true - checksum: 06126e478b8b653e83b98b51cec35dceef8ab576abd1369afd45360c5bac3711443e58ebe3b852d40801a118e4cb7ddf5d3154518b5a9294ee93f7a42d9f22d4 - languageName: node - linkType: hard - -"puppeteer-core@npm:^20.0.0": - version: 20.9.0 - resolution: "puppeteer-core@npm:20.9.0" +"puppeteer-core@npm:^22.0.0": + version: 22.4.1 + resolution: "puppeteer-core@npm:22.4.1" dependencies: - "@puppeteer/browsers": 1.4.6 - chromium-bidi: 0.4.16 + "@puppeteer/browsers": 2.1.0 + chromium-bidi: 0.5.12 cross-fetch: 4.0.0 debug: 4.3.4 - devtools-protocol: 0.0.1147663 - ws: 8.13.0 - peerDependencies: - typescript: ">= 4.7.4" - peerDependenciesMeta: - typescript: - optional: true - checksum: d298598445b0f2032c02d0ed7d1d18a8d2d2fcaf6fc31fc96e93e2669a7fc6fbee0338bd9b8c8f8822887f18a8fb680b77bb56e96fe1928baadb52292bbd93b4 + devtools-protocol: 0.0.1249869 + ws: 8.16.0 + checksum: 01c28c4f0f66a4ed6c7fee14871920fd25c60ae3507c1b8aed37968b240021f8d0cdd37cb863cebb88fde792ae9fea453e3b943931ae075c99f8e90303d2625f languageName: node linkType: hard @@ -18389,7 +17989,7 @@ __metadata: languageName: node linkType: hard -"readable-stream@npm:^3.0.6, readable-stream@npm:^3.1.1, readable-stream@npm:^3.4.0, readable-stream@npm:^3.6.0": +"readable-stream@npm:^3.0.6, readable-stream@npm:^3.4.0, readable-stream@npm:^3.6.0": version: 3.6.2 resolution: "readable-stream@npm:3.6.2" dependencies: @@ -18907,7 +18507,7 @@ __metadata: languageName: node linkType: hard -"resolve@npm:^1.1.6, resolve@npm:^1.14.2, resolve@npm:^1.19.0, resolve@npm:^1.20.0, resolve@npm:^1.22.1, resolve@npm:^1.3.2": +"resolve@npm:^1.1.6, resolve@npm:^1.14.2, resolve@npm:^1.20.0, resolve@npm:^1.22.1, resolve@npm:^1.3.2": version: 1.22.8 resolution: "resolve@npm:1.22.8" dependencies: @@ -18929,7 +18529,7 @@ __metadata: languageName: node linkType: hard -"resolve@patch:resolve@^1.1.6#~builtin, resolve@patch:resolve@^1.14.2#~builtin, resolve@patch:resolve@^1.19.0#~builtin, resolve@patch:resolve@^1.20.0#~builtin, resolve@patch:resolve@^1.22.1#~builtin, resolve@patch:resolve@^1.3.2#~builtin": +"resolve@patch:resolve@^1.1.6#~builtin, resolve@patch:resolve@^1.14.2#~builtin, resolve@patch:resolve@^1.20.0#~builtin, resolve@patch:resolve@^1.22.1#~builtin, resolve@patch:resolve@^1.3.2#~builtin": version: 1.22.8 resolution: "resolve@patch:resolve@npm%3A1.22.8#~builtin::version=1.22.8&hash=c3c19d" dependencies: @@ -19045,20 +18645,6 @@ __metadata: languageName: node linkType: hard -"rollup@npm:^2.67.0": - version: 2.79.1 - resolution: "rollup@npm:2.79.1" - dependencies: - fsevents: ~2.3.2 - dependenciesMeta: - fsevents: - optional: true - bin: - rollup: dist/bin/rollup - checksum: 6a2bf167b3587d4df709b37d149ad0300692cc5deb510f89ac7bdc77c8738c9546ae3de9322b0968e1ed2b0e984571f5f55aae28fa7de4cfcb1bc5402a4e2be6 - languageName: node - linkType: hard - "rollup@npm:^4.4.0": version: 4.9.4 resolution: "rollup@npm:4.9.4" @@ -19134,15 +18720,6 @@ __metadata: languageName: node linkType: hard -"run-applescript@npm:^5.0.0": - version: 5.0.0 - resolution: "run-applescript@npm:5.0.0" - dependencies: - execa: ^5.0.0 - checksum: d00c2dbfa5b2d774de7451194b8b125f40f65fc183de7d9dcae97f57f59433586d3c39b9001e111c38bfa24c3436c99df1bb4066a2a0c90d39a8c4cd6889af77 - languageName: node - linkType: hard - "run-applescript@npm:^7.0.0": version: 7.0.0 resolution: "run-applescript@npm:7.0.0" @@ -19330,6 +18907,17 @@ __metadata: languageName: node linkType: hard +"semver@npm:7.6.0": + version: 7.6.0 + resolution: "semver@npm:7.6.0" + dependencies: + lru-cache: ^6.0.0 + bin: + semver: bin/semver.js + checksum: 7427f05b70786c696640edc29fdd4bc33b2acf3bbe1740b955029044f80575fc664e1a512e4113c3af21e767154a94b4aa214bf6cd6e42a1f6dba5914e0b208c + languageName: node + linkType: hard + "semver@npm:^5.4.1, semver@npm:^5.5.0": version: 5.7.2 resolution: "semver@npm:5.7.2" @@ -19933,6 +19521,20 @@ __metadata: languageName: node linkType: hard +"streamx@npm:^2.13.0": + version: 2.16.1 + resolution: "streamx@npm:2.16.1" + dependencies: + bare-events: ^2.2.0 + fast-fifo: ^1.1.0 + queue-tick: ^1.0.1 + dependenciesMeta: + bare-events: + optional: true + checksum: 6bbb4c38c0ab6ddbe0857d55e72f71288f308f2a9f4413b7b07391cdf9f94232ffc2bbe40a1212d2e09634ecdbd5052b444c73cc8d67ae1c97e2b7e553dad559 + languageName: node + linkType: hard + "streamx@npm:^2.15.0": version: 2.15.6 resolution: "streamx@npm:2.15.6" @@ -20066,13 +19668,6 @@ __metadata: languageName: node linkType: hard -"strip-final-newline@npm:^3.0.0": - version: 3.0.0 - resolution: "strip-final-newline@npm:3.0.0" - checksum: 23ee263adfa2070cd0f23d1ac14e2ed2f000c9b44229aec9c799f1367ec001478469560abefd00c5c99ee6f0b31c137d53ec6029c53e9f32a93804e18c201050 - languageName: node - linkType: hard - "strip-hex-prefix@npm:1.0.0": version: 1.0.0 resolution: "strip-hex-prefix@npm:1.0.0" @@ -20200,13 +19795,13 @@ __metadata: languageName: node linkType: hard -"synckit@npm:^0.8.5": - version: 0.8.6 - resolution: "synckit@npm:0.8.6" +"synckit@npm:^0.8.6": + version: 0.8.8 + resolution: "synckit@npm:0.8.8" dependencies: - "@pkgr/utils": ^2.4.2 + "@pkgr/core": ^0.1.0 tslib: ^2.6.2 - checksum: 7c1f4991d0afd63c090c0537f1cf8619dd5777a40cf83bf46beadbf4eb0f9e400d92044e90a177a305df4bcb56efbaf1b689877f301f2672d865b6eecf1be75a + checksum: 9ed5d33abb785f5f24e2531efd53b2782ca77abf7912f734d170134552b99001915531be5a50297aa45c5701b5c9041e8762e6cd7a38e41e2461c1e7fccdedf8 languageName: node linkType: hard @@ -20253,39 +19848,20 @@ __metadata: languageName: node linkType: hard -"tar-fs@npm:2.1.1": - version: 2.1.1 - resolution: "tar-fs@npm:2.1.1" - dependencies: - chownr: ^1.1.1 - mkdirp-classic: ^0.5.2 - pump: ^3.0.0 - tar-stream: ^2.1.4 - checksum: f5b9a70059f5b2969e65f037b4e4da2daf0fa762d3d232ffd96e819e3f94665dbbbe62f76f084f1acb4dbdcce16c6e4dac08d12ffc6d24b8d76720f4d9cf032d - languageName: node - linkType: hard - -"tar-fs@npm:3.0.4": - version: 3.0.4 - resolution: "tar-fs@npm:3.0.4" +"tar-fs@npm:3.0.5": + version: 3.0.5 + resolution: "tar-fs@npm:3.0.5" dependencies: - mkdirp-classic: ^0.5.2 + bare-fs: ^2.1.1 + bare-path: ^2.1.0 pump: ^3.0.0 tar-stream: ^3.1.5 - checksum: dcf4054f9e92ca0efe61c2b3f612914fb259a47900aa908a63106513a6d006c899b426ada53eb88d9dbbf089b5724c8e90b96a2c4ca6171845fa14203d734e30 - languageName: node - linkType: hard - -"tar-stream@npm:^2.1.4": - version: 2.2.0 - resolution: "tar-stream@npm:2.2.0" - dependencies: - bl: ^4.0.3 - end-of-stream: ^1.4.1 - fs-constants: ^1.0.0 - inherits: ^2.0.3 - readable-stream: ^3.1.1 - checksum: 699831a8b97666ef50021c767f84924cfee21c142c2eb0e79c63254e140e6408d6d55a065a2992548e72b06de39237ef2b802b99e3ece93ca3904a37622a66f3 + dependenciesMeta: + bare-fs: + optional: true + bare-path: + optional: true + checksum: e31c7e3e525fec0afecdec1cac58071809e396187725f2eba442f08a4c5649c8cd6b7ce25982f9a91bb0f055628df47c08177dd2ea4f5dafd3c22f42f8da8f00 languageName: node linkType: hard @@ -20430,13 +20006,6 @@ __metadata: languageName: node linkType: hard -"titleize@npm:^3.0.0": - version: 3.0.0 - resolution: "titleize@npm:3.0.0" - checksum: 71fbbeabbfb36ccd840559f67f21e356e1d03da2915b32d2ae1a60ddcc13a124be2739f696d2feb884983441d159a18649e8d956648d591bdad35c430a6b6d28 - languageName: node - linkType: hard - "tmp@npm:0.0.33": version: 0.0.33 resolution: "tmp@npm:0.0.33" @@ -20839,63 +20408,23 @@ __metadata: languageName: node linkType: hard -"typescript@npm:5.1.5": - version: 5.1.5 - resolution: "typescript@npm:5.1.5" +"typescript@npm:5.4.2, typescript@npm:^5.4.2": + version: 5.4.2 + resolution: "typescript@npm:5.4.2" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 0eef8699e05ae767096924dbed633c340b4d36e953bb8ed87fb12e9dd9dcea5055ceac7182c614a556dbd346a8a82df799d330e1e286ae66e17c84e1710f6a6f + checksum: 96d80fde25a09bcb04d399082fb27a808a9e17c2111e43849d2aafbd642d835e4f4ef0de09b0ba795ec2a700be6c4c2c3f62bf4660c05404c948727b5bbfb32a languageName: node linkType: hard -"typescript@npm:^5.0.4, typescript@npm:^5.2.2": - version: 5.3.3 - resolution: "typescript@npm:5.3.3" +"typescript@patch:typescript@5.4.2#~builtin, typescript@patch:typescript@^5.4.2#~builtin": + version: 5.4.2 + resolution: "typescript@patch:typescript@npm%3A5.4.2#~builtin::version=5.4.2&hash=f3b441" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 2007ccb6e51bbbf6fde0a78099efe04dc1c3dfbdff04ca3b6a8bc717991862b39fd6126c0c3ebf2d2d98ac5e960bcaa873826bb2bb241f14277034148f41f6a2 - languageName: node - linkType: hard - -"typescript@npm:~5.2.2": - version: 5.2.2 - resolution: "typescript@npm:5.2.2" - bin: - tsc: bin/tsc - tsserver: bin/tsserver - checksum: 7912821dac4d962d315c36800fe387cdc0a6298dba7ec171b350b4a6e988b51d7b8f051317786db1094bd7431d526b648aba7da8236607febb26cf5b871d2d3c - languageName: node - linkType: hard - -"typescript@patch:typescript@5.1.5#~builtin": - version: 5.1.5 - resolution: "typescript@patch:typescript@npm%3A5.1.5#~builtin::version=5.1.5&hash=5da071" - bin: - tsc: bin/tsc - tsserver: bin/tsserver - checksum: 12ff5d14888805f24479e54bc8a3f83647107a6345f6c29dffcd429fb345be55f584a37e262cca58a0105203e41d4cb4e31b1b9096c9abeca0e2ace8eb00935e - languageName: node - linkType: hard - -"typescript@patch:typescript@^5.0.4#~builtin, typescript@patch:typescript@^5.2.2#~builtin": - version: 5.3.3 - resolution: "typescript@patch:typescript@npm%3A5.3.3#~builtin::version=5.3.3&hash=f3b441" - bin: - tsc: bin/tsc - tsserver: bin/tsserver - checksum: f61375590b3162599f0f0d5b8737877ac0a7bc52761dbb585d67e7b8753a3a4c42d9a554c4cc929f591ffcf3a2b0602f65ae3ce74714fd5652623a816862b610 - languageName: node - linkType: hard - -"typescript@patch:typescript@~5.2.2#~builtin": - version: 5.2.2 - resolution: "typescript@patch:typescript@npm%3A5.2.2#~builtin::version=5.2.2&hash=f3b441" - bin: - tsc: bin/tsc - tsserver: bin/tsserver - checksum: 0f4da2f15e6f1245e49db15801dbee52f2bbfb267e1c39225afdab5afee1a72839cd86000e65ee9d7e4dfaff12239d28beaf5ee431357fcced15fb08583d72ca + checksum: c1b669146bca5529873aae60870e243fa8140c85f57ca32c42f898f586d73ce4a6b4f6bb02ae312729e214d7f5859a0c70da3e527a116fdf5ad00c9fc733ecc6 languageName: node linkType: hard @@ -21261,13 +20790,6 @@ __metadata: languageName: node linkType: hard -"untildify@npm:^4.0.0": - version: 4.0.0 - resolution: "untildify@npm:4.0.0" - checksum: 39ced9c418a74f73f0a56e1ba4634b4d959422dff61f4c72a8e39f60b99380c1b45ed776fbaa0a4101b157e4310d873ad7d114e8534ca02609b4916bb4187fb9 - languageName: node - linkType: hard - "unzipit@npm:^1.4.3": version: 1.4.3 resolution: "unzipit@npm:1.4.3" @@ -21390,6 +20912,13 @@ __metadata: languageName: node linkType: hard +"urlpattern-polyfill@npm:10.0.0": + version: 10.0.0 + resolution: "urlpattern-polyfill@npm:10.0.0" + checksum: 61d890f151ea4ecf34a3dcab32c65ad1f3cda857c9d154af198260c6e5b2ad96d024593409baaa6d4428dd1ab206c14799bf37fe011117ac93a6a44913ac5aa4 + languageName: node + linkType: hard + "util-deprecate@npm:^1.0.1, util-deprecate@npm:^1.0.2, util-deprecate@npm:~1.0.1": version: 1.0.2 resolution: "util-deprecate@npm:1.0.2" @@ -22117,9 +21646,9 @@ __metadata: languageName: node linkType: hard -"ws@npm:8.13.0": - version: 8.13.0 - resolution: "ws@npm:8.13.0" +"ws@npm:8.16.0, ws@npm:^8.16.0": + version: 8.16.0 + resolution: "ws@npm:8.16.0" peerDependencies: bufferutil: ^4.0.1 utf-8-validate: ">=5.0.2" @@ -22128,7 +21657,7 @@ __metadata: optional: true utf-8-validate: optional: true - checksum: 53e991bbf928faf5dc6efac9b8eb9ab6497c69feeb94f963d648b7a3530a720b19ec2e0ec037344257e05a4f35bd9ad04d9de6f289615ffb133282031b18c61c + checksum: feb3eecd2bae82fa8a8beef800290ce437d8b8063bdc69712725f21aef77c49cb2ff45c6e5e7fce622248f9c7abaee506bae0a9064067ffd6935460c7357321b languageName: node linkType: hard @@ -22177,21 +21706,6 @@ __metadata: languageName: node linkType: hard -"ws@npm:^8.16.0": - version: 8.16.0 - resolution: "ws@npm:8.16.0" - peerDependencies: - bufferutil: ^4.0.1 - utf-8-validate: ">=5.0.2" - peerDependenciesMeta: - bufferutil: - optional: true - utf-8-validate: - optional: true - checksum: feb3eecd2bae82fa8a8beef800290ce437d8b8063bdc69712725f21aef77c49cb2ff45c6e5e7fce622248f9c7abaee506bae0a9064067ffd6935460c7357321b - languageName: node - linkType: hard - "xdg-basedir@npm:^4.0.0": version: 4.0.0 resolution: "xdg-basedir@npm:4.0.0" @@ -22340,22 +21854,7 @@ __metadata: languageName: node linkType: hard -"yargs@npm:17.7.1": - version: 17.7.1 - resolution: "yargs@npm:17.7.1" - dependencies: - cliui: ^8.0.1 - escalade: ^3.1.1 - get-caller-file: ^2.0.5 - require-directory: ^2.1.1 - string-width: ^4.2.3 - y18n: ^5.0.5 - yargs-parser: ^21.1.1 - checksum: 3d8a43c336a4942bc68080768664aca85c7bd406f018bad362fd255c41c8f4e650277f42fd65d543fce99e084124ddafee7bbfc1a5c6a8fda4cec78609dcf8d4 - languageName: node - linkType: hard - -"yargs@npm:^17.7.1": +"yargs@npm:17.7.2, yargs@npm:^17.7.1": version: 17.7.2 resolution: "yargs@npm:17.7.2" dependencies: