diff --git a/.circleci/config.yml b/.circleci/config.yml index 4583d493678..8c3765900aa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -231,7 +231,7 @@ jobs: command: cond_spot_run_build noir-packages 32 aztec_manifest_key: noir-packages - avm-transpiler: + avm-transpiler-x86_64: docker: - image: aztecprotocol/alpine-build-image resource_class: small @@ -243,7 +243,7 @@ jobs: command: cond_spot_run_build avm-transpiler 32 aztec_manifest_key: avm-transpiler - aztec-nargo: + avm-transpiler-arm64: docker: - image: aztecprotocol/alpine-build-image resource_class: small @@ -252,7 +252,31 @@ jobs: - *setup_env - run: name: "Build" - command: cond_spot_run_build aztec-nargo 32 + command: cond_spot_run_build avm-transpiler 32 arm64 + aztec_manifest_key: avm-transpiler + + avm-transpiler-ecr-manifest: + machine: + image: default + resource_class: medium + steps: + - *checkout + - *setup_env + - run: + name: "Create ECR manifest" + command: create_ecr_manifest avm-transpiler x86_64,arm64 + aztec_manifest_key: avm-transpiler + + aztec-nargo: + machine: + image: default + resource_class: small + steps: + - *checkout + - *setup_env + - run: + name: "Build image" + command: build aztec-nargo aztec_manifest_key: aztec-nargo l1-contracts: @@ -429,8 +453,9 @@ jobs: - run: name: "Update aztec-up" command: | - should_release || exit 0 - deploy_terraform "" aztec-up/terraform + if [ -n "$COMMIT_TAG" ]; then + deploy_terraform "" aztec-up/terraform + fi # Repeatable config for defining the workflow below. defaults: &defaults @@ -510,15 +535,24 @@ workflows: <<: *defaults # Transpiler - - avm-transpiler: + - avm-transpiler-x86_64: requires: - - noir-ecr-manifest + - noir-x86_64 + <<: *defaults + - avm-transpiler-arm64: + requires: + - noir-arm64 + <<: *defaults + - avm-transpiler-ecr-manifest: + requires: + - avm-transpiler-x86_64 + - avm-transpiler-arm64 <<: *defaults # aztec-nargo (nargo & transpiler) - aztec-nargo: requires: - - avm-transpiler + - avm-transpiler-ecr-manifest <<: *defaults # Barretenberg @@ -536,7 +570,7 @@ workflows: - noir-projects: requires: - - avm-transpiler + - avm-transpiler-ecr-manifest - noir-ecr-manifest <<: *defaults diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 671ce7a2acb..196a9efb59a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -418,7 +418,7 @@ jobs: run: earthly-ci --no-output ./noir+packages-test noir-projects: - needs: [setup, changes] + needs: [setup, changes, build] runs-on: ${{ github.event.pull_request.user.login || github.actor }}-x86 if: ${{ needs.changes.outputs.barretenberg == 'true' || needs.changes.outputs.noir == 'true' || needs.changes.outputs.noir-projects == 'true' }} steps: diff --git a/.github/workflows/devnet-deploys.yml b/.github/workflows/devnet-deploys.yml new file mode 100644 index 00000000000..a2b09291c1e --- /dev/null +++ b/.github/workflows/devnet-deploys.yml @@ -0,0 +1,69 @@ +name: Deploy to devnet +on: + push: + branches: [devnet] + +env: + DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} + GIT_COMMIT: ${{ github.sha }} + # TF Vars + TF_VAR_DOCKERHUB_ACCOUNT: aztecprotocol + TF_VAR_CHAIN_ID: 31337 + TF_VAR_BOOTNODE_1_PRIVATE_KEY: ${{ secrets.BOOTNODE_1_PRIVATE_KEY }} + TF_VAR_BOOTNODE_2_PRIVATE_KEY: ${{ secrets.BOOTNODE_2_PRIVATE_KEY }} + TF_VAR_SEQ_1_PUBLISHER_PRIVATE_KEY: ${{ secrets.SEQ_1_PUBLISHER_PRIVATE_KEY }} + TF_VAR_SEQ_2_PUBLISHER_PRIVATE_KEY: ${{ secrets.SEQ_2_PUBLISHER_PRIVATE_KEY }} + TF_VAR_DEPLOY_TAG: devnet + TF_VAR_API_KEY: ${{ secrets.FORK_API_KEY }} + +jobs: + setup: + uses: ./.github/workflows/setup-runner.yml + with: + username: master + runner_type: builder-x86 + secrets: inherit + + build: + runs-on: ${{ github.actor }}-x86 + steps: + - uses: actions/checkout@v4 + with: { ref: "${{ env.GIT_COMMIT }}" } + - uses: ./.github/ci-setup-action + with: + dockerhub_password: "${{ secrets.DOCKERHUB_PASSWORD }}" + concurrency_key: build-release-artifacts-${{ github.actor }} + - name: "Build & Push images" + timeout-minutes: 40 + # Run the build steps for each image with version and arch, push to dockerhub + run: | + earthly-ci --no-output --push ./yarn-project+export-aztec-arch --DIST_TAG=devnet + + terraform_deploy: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v4 + with: { ref: "${{ env.GIT_COMMIT }}" } + - uses: hashicorp/setup-terraform@v3 + with: + terraform_version: 1.7.5 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-2 + + - name: Deploy Bootstrap Nodes + working-directory: ./yarn-project/aztec/terraform/node + run: | + terraform init -input=false -backend-config="key=devnet/aztec-node" + terraform apply -input=false -auto-approve + + - name: Deploy Aztec Nodes + working-directory: ./yarn-project/aztec/terraform/node + run: | + terraform init -input=false -backend-config="key=devnet/aztec-node" + terraform apply -input=false -auto-approve diff --git a/.github/workflows/mirror-noir-subrepo.yml b/.github/workflows/mirror-noir-subrepo.yml index abcae31ac0a..9ca0d61d2ca 100644 --- a/.github/workflows/mirror-noir-subrepo.yml +++ b/.github/workflows/mirror-noir-subrepo.yml @@ -96,6 +96,12 @@ jobs: git config --file="$SUBREPO_PATH/.gitrepo" subrepo.commit "$BASE_NOIR_COMMIT" # make a new commit with our previous message git commit -am "$COMMIT_MESSAGE" + + # There's various changes which we need to make to account for CI differences so we run this script to apply them. + git checkout origin/master -- noir/scripts/sync-out-fixup.sh + noir/scripts/sync-out-fixup.sh + git commit -am "chore: apply sync fixes" + # Now push to it with subrepo with computed commit messages if ./scripts/git-subrepo/lib/git-subrepo push $SUBREPO_PATH --squash --branch=$STAGING_BRANCH; then # We don't push a commit to aztec anymore so that we can maintain the 'commit' as our last pull branch diff --git a/.github/workflows/pull-noir.yml b/.github/workflows/pull-noir.yml index fdd990816c2..b1ca0cc7bbf 100644 --- a/.github/workflows/pull-noir.yml +++ b/.github/workflows/pull-noir.yml @@ -101,8 +101,8 @@ jobs: git commit -am "[$LINES changes] $COMMIT_MESSAGE" # There's various changes which we need to make to account for CI differences so we run this script to apply them. - git checkout origin/master -- noir/scripts/sync-fixup.sh - noir/scripts/sync-fixup.sh + git checkout origin/master -- noir/scripts/sync-in-fixup.sh + noir/scripts/sync-in-fixup.sh git commit -am "chore: apply sync fixes" git push origin $STAGING_BRANCH --force diff --git a/.github/workflows/vm_full_tests.yml b/.github/workflows/vm_full_tests.yml new file mode 100644 index 00000000000..1e912a05438 --- /dev/null +++ b/.github/workflows/vm_full_tests.yml @@ -0,0 +1,60 @@ +name: AVM Full Tests + +on: + schedule: + - cron: "15 4 * * 1-5" # Monday to Friday at 4:15 AM UTC + workflow_dispatch: + inputs: + username: + description: "Username (optional)" + required: false + action: + description: "Default to 'start'" + required: false + default: "start" + +concurrency: + # force parallelism in master + group: avm-full-tests-${{ github.ref }} + cancel-in-progress: true + +env: + DOCKERHUB_PASSWORD: "${{ secrets.DOCKERHUB_PASSWORD }}" + RUN_ID: ${{ github.run_id }} + RUN_ATTEMPT: ${{ github.run_attempt }} + USERNAME: ${{ github.event.pull_request.user.login || github.actor }} + GITHUB_TOKEN: ${{ github.token }} + GH_SELF_HOSTED_RUNNER_TOKEN: ${{ secrets.GH_SELF_HOSTED_RUNNER_TOKEN }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + BUILD_INSTANCE_SSH_KEY: ${{ secrets.BUILD_INSTANCE_SSH_KEY }} + GIT_COMMIT: ${{ github.event.pull_request.head.sha || github.sha }} + # kludge until we move away from runners + WAIT_FOR_RUNNERS: false + +jobs: + setup: + uses: ./.github/workflows/setup-runner.yml + with: + username: ${{ github.event.pull_request.user.login || github.actor }} + runner_type: builder-x86 + secrets: inherit + + # barretenberg (prover) native and AVM (public VM) tests + # only ran on x86 for resource reasons (memory intensive) + avm-full-tests: + needs: [setup] + runs-on: ${{ github.event.pull_request.user.login || github.actor }}-x86 + steps: + - uses: actions/checkout@v4 + with: { ref: "${{ env.GIT_COMMIT }}" } + # Only allow one memory-hunger prover test to use this runner + - uses: ./.github/ci-setup-action + with: + # must be globally unique for build x runner + concurrency_key: avm-full-tests-x86 + - name: "AVM Full Tests" + working-directory: ./barretenberg/cpp/ + timeout-minutes: 90 + # limit our parallelism to half our cores + run: earthly-ci --no-output +vm-full-test --hardware_concurrency=64 diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 068a4b82775..a2daeb9352c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,7 +1,7 @@ { - ".": "0.42.0", + ".": "0.43.0", "yarn-project/cli": "0.35.1", - "yarn-project/aztec": "0.42.0", - "barretenberg": "0.42.0", - "barretenberg/ts": "0.42.0" + "yarn-project/aztec": "0.43.0", + "barretenberg": "0.43.0", + "barretenberg/ts": "0.43.0" } diff --git a/.vscode/settings.json b/.vscode/settings.json index a8ab844ebe1..86a0427f790 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -169,5 +169,4 @@ "**/noir/noir-repo/docs/versioned_docs/**": true }, "cmake.sourceDirectory": "${workspaceFolder}/barretenberg/cpp", - "noir.nargoPath": "./noir/noir-repo/target/release/nargo" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 550b06bcb7c..31100bab7b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,219 @@ # Changelog +## [0.43.0](https://github.com/AztecProtocol/aztec-packages/compare/aztec-packages-v0.42.0...aztec-packages-v0.43.0) (2024-06-18) + + +### ⚠ BREAKING CHANGES + +* remove `distinct` keyword (https://github.com/noir-lang/noir/pull/5219) +* remove `param_witnesses` and `return_witnesses` from ABI (https://github.com/noir-lang/noir/pull/5154) +* add session id to foreign call RPC requests (https://github.com/noir-lang/noir/pull/5205) +* make options.limit a compile-time constant ([#7027](https://github.com/AztecProtocol/aztec-packages/issues/7027)) +* restrict noir word size to u32 (https://github.com/noir-lang/noir/pull/5180) +* separate proving from `noir_js` (https://github.com/noir-lang/noir/pull/5072) + +### Features + +* `pxe.addNullifiedNote(...)` ([#6948](https://github.com/AztecProtocol/aztec-packages/issues/6948)) ([42a4b1c](https://github.com/AztecProtocol/aztec-packages/commit/42a4b1c6f000886b8b63e2fd6b0b218a29cb820c)) +* Add data dir to pxe container ([#6874](https://github.com/AztecProtocol/aztec-packages/issues/6874)) ([504fea2](https://github.com/AztecProtocol/aztec-packages/commit/504fea2e330ad66ec269ddff581b7448c008f9ca)) +* Add ENFORCE_FEES sequencer config ([#6949](https://github.com/AztecProtocol/aztec-packages/issues/6949)) ([46dcb98](https://github.com/AztecProtocol/aztec-packages/commit/46dcb985e98ca26ee2dd3d2ec98976f1d8f27ba7)) +* Add gate profiler for noir circuits ([#7004](https://github.com/AztecProtocol/aztec-packages/issues/7004)) ([a2f6876](https://github.com/AztecProtocol/aztec-packages/commit/a2f687687559d15fde52abce54838f6e144a0aa4)) +* Add node to devnet ([#6898](https://github.com/AztecProtocol/aztec-packages/issues/6898)) ([acc534c](https://github.com/AztecProtocol/aztec-packages/commit/acc534c339ad05d548f8f287e4bd6051201cb1f6)) +* Add session id to foreign call RPC requests (https://github.com/noir-lang/noir/pull/5205) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* Add standard form function to biggroup ([#6899](https://github.com/AztecProtocol/aztec-packages/issues/6899)) ([3e44be5](https://github.com/AztecProtocol/aztec-packages/commit/3e44be538e5c7f0e7269c1e5c0820f7bc6e83734)) +* Add utils::collapse ([#7016](https://github.com/AztecProtocol/aztec-packages/issues/7016)) ([2d19ad9](https://github.com/AztecProtocol/aztec-packages/commit/2d19ad9af6130aeaf6621f239c4119c3126dd7c6)) +* Affine_element read/write with proper handling of point at infinity ([#6963](https://github.com/AztecProtocol/aztec-packages/issues/6963)) ([c6cbe39](https://github.com/AztecProtocol/aztec-packages/commit/c6cbe39eed23dc845aef898e937e99de43f71675)) +* Auth registry ([#7035](https://github.com/AztecProtocol/aztec-packages/issues/7035)) ([cea0b3b](https://github.com/AztecProtocol/aztec-packages/commit/cea0b3b29c2f7c37eb07c226a06534f92518cea6)) +* Auto-gen p2p private key ([#6910](https://github.com/AztecProtocol/aztec-packages/issues/6910)) ([0fc9677](https://github.com/AztecProtocol/aztec-packages/commit/0fc9677b2db0b126e6b604b387735a29e295ff05)) +* Avm e2e nested call + alu fix + cast fix ([#6974](https://github.com/AztecProtocol/aztec-packages/issues/6974)) ([b150b61](https://github.com/AztecProtocol/aztec-packages/commit/b150b610153e380a93240914c95887f88b56fa94)) +* **avm-simulator:** Msm blackbox ([#7048](https://github.com/AztecProtocol/aztec-packages/issues/7048)) ([0ce27e0](https://github.com/AztecProtocol/aztec-packages/commit/0ce27e05c4c099167d0d98300f6d73ced22639ad)) +* **avm:** Add get_contract_instance ([#6871](https://github.com/AztecProtocol/aztec-packages/issues/6871)) ([b3a86bf](https://github.com/AztecProtocol/aztec-packages/commit/b3a86bf72343d1060ce58a11f139e05ba2a75754)) +* **avm:** Deserialise execution hints in bb main ([#6848](https://github.com/AztecProtocol/aztec-packages/issues/6848)) ([d3be85f](https://github.com/AztecProtocol/aztec-packages/commit/d3be85f57c34aa88e732ea115239f3bed1e7aa16)) +* **avm:** E2e proving of storage ([#6967](https://github.com/AztecProtocol/aztec-packages/issues/6967)) ([6a7be0c](https://github.com/AztecProtocol/aztec-packages/commit/6a7be0c434934175bb6da1f3525c025b3f743824)) +* **avm:** E2e send l1 msg ([#6880](https://github.com/AztecProtocol/aztec-packages/issues/6880)) ([deb972d](https://github.com/AztecProtocol/aztec-packages/commit/deb972d3f13a92d34a6f91074b072fb66d247f64)) +* **avm:** Gas remaining range check and handling of out of gas ([#6944](https://github.com/AztecProtocol/aztec-packages/issues/6944)) ([5647571](https://github.com/AztecProtocol/aztec-packages/commit/56475716e05973e6b493de427f32eee71c0f8f6a)), closes [#6902](https://github.com/AztecProtocol/aztec-packages/issues/6902) +* **avm:** Get contract instance now works e2e with avm proving ([#6911](https://github.com/AztecProtocol/aztec-packages/issues/6911)) ([662187d](https://github.com/AztecProtocol/aztec-packages/commit/662187d1d6960b734a71aaf365e7f20d471dc4c9)) +* **avm:** Indirect support for kernel output opcodes ([#6962](https://github.com/AztecProtocol/aztec-packages/issues/6962)) ([f330bff](https://github.com/AztecProtocol/aztec-packages/commit/f330bffa80b6da5f037cea3cf469ef1c7b6d9d03)) +* **avm:** Indirect support for kernel read opcodes ([#6940](https://github.com/AztecProtocol/aztec-packages/issues/6940)) ([ccc474d](https://github.com/AztecProtocol/aztec-packages/commit/ccc474d9d0cd10faf857bc1ec6571dc25306a531)) +* **avm:** L2gasleft and dagasleft opcodes ([#6884](https://github.com/AztecProtocol/aztec-packages/issues/6884)) ([fbab612](https://github.com/AztecProtocol/aztec-packages/commit/fbab612b17dfe0e95ead1a592b7bc9fe6ca5415d)) +* **avm:** Nullifier non exist ([#6877](https://github.com/AztecProtocol/aztec-packages/issues/6877)) ([05697f2](https://github.com/AztecProtocol/aztec-packages/commit/05697f289d3b97def74f45cd839a58a8a077c3fa)) +* **avm:** Plumb externalcall hints ([#6890](https://github.com/AztecProtocol/aztec-packages/issues/6890)) ([3a97f08](https://github.com/AztecProtocol/aztec-packages/commit/3a97f08c457472bd701200adfa45d61554fd3867)) +* **avm:** Plumb start side effect counter in circuit ([#7007](https://github.com/AztecProtocol/aztec-packages/issues/7007)) ([fa8f12f](https://github.com/AztecProtocol/aztec-packages/commit/fa8f12f93a8d94604a4382de444501fac310dbb8)) +* **avm:** Revert opcode ([#6909](https://github.com/AztecProtocol/aztec-packages/issues/6909)) ([620d3da](https://github.com/AztecProtocol/aztec-packages/commit/620d3dacc853c71e808ef58001eb4c8584fa59d9)) +* **avm:** Support preserving BB working dir for better debugging ([#6990](https://github.com/AztecProtocol/aztec-packages/issues/6990)) ([a9688f0](https://github.com/AztecProtocol/aztec-packages/commit/a9688f058252cb1c4714cfb06bd2cf30c6ac0268)) +* **avm:** Use hints in gas accounting (circuit) ([#6895](https://github.com/AztecProtocol/aztec-packages/issues/6895)) ([c3746f5](https://github.com/AztecProtocol/aztec-packages/commit/c3746f5d6ae38bc448d00834d91a7ddd7b901e64)) +* **bb:** Stack traces for check_circuit ([#6851](https://github.com/AztecProtocol/aztec-packages/issues/6851)) ([eb35e62](https://github.com/AztecProtocol/aztec-packages/commit/eb35e627445c72ee07fafb3652076349302e7fa1)) +* **cli:** Publicly deploy a pre-initialized account ([#6960](https://github.com/AztecProtocol/aztec-packages/issues/6960)) ([e671935](https://github.com/AztecProtocol/aztec-packages/commit/e67193585fe967106a013d266e00e94d20d31b32)) +* Constrain note encryption ([#6432](https://github.com/AztecProtocol/aztec-packages/issues/6432)) ([e59f4d3](https://github.com/AztecProtocol/aztec-packages/commit/e59f4d3cee4b27248d26111fc6fda2f0e55a7d54)) +* Contract storage reads serialize with side effect counter ([#6961](https://github.com/AztecProtocol/aztec-packages/issues/6961)) ([db49ed5](https://github.com/AztecProtocol/aztec-packages/commit/db49ed57d1d4165ce47e6af01b6fd67239121aa4)) +* **docs:** Add uniswap back in as a reference and fix links ([#7074](https://github.com/AztecProtocol/aztec-packages/issues/7074)) ([a4d1df6](https://github.com/AztecProtocol/aztec-packages/commit/a4d1df6d2900185a9c57af44e6f0c3ca80df7c9b)) +* **docs:** Nits ([#6187](https://github.com/AztecProtocol/aztec-packages/issues/6187)) ([d025496](https://github.com/AztecProtocol/aztec-packages/commit/d0254960b1712b717e156b428aa05721702ec4a8)) +* Ecadd op code ([#6906](https://github.com/AztecProtocol/aztec-packages/issues/6906)) ([03a9064](https://github.com/AztecProtocol/aztec-packages/commit/03a9064b308fbf5541f4f763e1ad1e05f60e1fff)) +* Estimate tx size ([#6928](https://github.com/AztecProtocol/aztec-packages/issues/6928)) ([1fa7d84](https://github.com/AztecProtocol/aztec-packages/commit/1fa7d84b6bf176d4585c333747ac4a61b8743e36)) +* Flows and tests for the tube component ([#6934](https://github.com/AztecProtocol/aztec-packages/issues/6934)) ([4b45438](https://github.com/AztecProtocol/aztec-packages/commit/4b454386a35f4b0cd4c6a9b8003c55e55e50b592)) +* Gas token self deploys ([#6956](https://github.com/AztecProtocol/aztec-packages/issues/6956)) ([ecd7614](https://github.com/AztecProtocol/aztec-packages/commit/ecd7614d0a52d277862aef97e81b68b8f66bc2c0)) +* Implement println in the comptime interpreter (https://github.com/noir-lang/noir/pull/5197) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* Increase max L2 to L1 msgs ([#6959](https://github.com/AztecProtocol/aztec-packages/issues/6959)) ([875fb2d](https://github.com/AztecProtocol/aztec-packages/commit/875fb2d507368b15c9672526c52b92039ef558d3)) +* Make options.limit a compile-time constant ([#7027](https://github.com/AztecProtocol/aztec-packages/issues/7027)) ([78cd640](https://github.com/AztecProtocol/aztec-packages/commit/78cd640dd2d5b281a921140b915a294eaa44f6f0)) +* Nuking last hardcoded note type ids ([#7069](https://github.com/AztecProtocol/aztec-packages/issues/7069)) ([a23fd0b](https://github.com/AztecProtocol/aztec-packages/commit/a23fd0ba1604a5308fd77ed45a5b1d20da13f405)), closes [#5833](https://github.com/AztecProtocol/aztec-packages/issues/5833) +* Place return value witnesses directly after function arguments (https://github.com/noir-lang/noir/pull/5142) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Poor man's CLI block explorer ([#6946](https://github.com/AztecProtocol/aztec-packages/issues/6946)) ([2b79df6](https://github.com/AztecProtocol/aztec-packages/commit/2b79df673e7a23886052990c85dc6ca530537e9f)) +* Poor man's fernet ([#6918](https://github.com/AztecProtocol/aztec-packages/issues/6918)) ([19c2a97](https://github.com/AztecProtocol/aztec-packages/commit/19c2a97784c917da212e76f3307d47e1beb8099f)) +* Private kernel output validator ([#6892](https://github.com/AztecProtocol/aztec-packages/issues/6892)) ([0435e9a](https://github.com/AztecProtocol/aztec-packages/commit/0435e9a76f158b72690f34025a2723a29a3c7816)) +* Processing outgoing ([#6766](https://github.com/AztecProtocol/aztec-packages/issues/6766)) ([4da66fd](https://github.com/AztecProtocol/aztec-packages/commit/4da66fdfb3d0686b5ed917e947869b9c2cef14a8)) +* Pxe can filter on emitted events ([#6947](https://github.com/AztecProtocol/aztec-packages/issues/6947)) ([ee45fda](https://github.com/AztecProtocol/aztec-packages/commit/ee45fdafd837e4070b627aaac630e2f985531c97)) +* Restrict noir word size to u32 (https://github.com/noir-lang/noir/pull/5180) ([bf38cc2](https://github.com/AztecProtocol/aztec-packages/commit/bf38cc29821d96d801f56e70342426e1b12692e1)) +* Separate proving from `noir_js` (https://github.com/noir-lang/noir/pull/5072) ([bf38cc2](https://github.com/AztecProtocol/aztec-packages/commit/bf38cc29821d96d801f56e70342426e1b12692e1)) +* Separate runtimes of SSA functions before inlining (https://github.com/noir-lang/noir/pull/5121) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* SMT Standard Circuit separation ([#6904](https://github.com/AztecProtocol/aztec-packages/issues/6904)) ([f970732](https://github.com/AztecProtocol/aztec-packages/commit/f9707321bdd107e3c7116cafd89fd570224e89ef)) +* SMT Verification Module Update ([#6849](https://github.com/AztecProtocol/aztec-packages/issues/6849)) ([6c98529](https://github.com/AztecProtocol/aztec-packages/commit/6c985299d796b8c711794395518c3b3a0f41e775)) +* SMT Verifier for Ultra Arithmetization ([#7067](https://github.com/AztecProtocol/aztec-packages/issues/7067)) ([6692ac8](https://github.com/AztecProtocol/aztec-packages/commit/6692ac831ab980d9623442236c21b499a7238966)) +* Splitting event log functionality ([#6921](https://github.com/AztecProtocol/aztec-packages/issues/6921)) ([8052bc6](https://github.com/AztecProtocol/aztec-packages/commit/8052bc64ee53e27f364438ecee057e2c9c1b3583)) +* Standard form for cycle_group ([#6915](https://github.com/AztecProtocol/aztec-packages/issues/6915)) ([e6cba16](https://github.com/AztecProtocol/aztec-packages/commit/e6cba16ef82428b115d527eabe237122e269aa32)) +* Standardize pedersen functions to return `EmbeddedCurvePoint` (https://github.com/noir-lang/noir/pull/5190) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* Storing outgoing + API for outgoing ([#7022](https://github.com/AztecProtocol/aztec-packages/issues/7022)) ([8281ec6](https://github.com/AztecProtocol/aztec-packages/commit/8281ec6dcd60a08a20da86fb9805dda8e9581764)) +* Support casting in globals (https://github.com/noir-lang/noir/pull/5164) ([bf38cc2](https://github.com/AztecProtocol/aztec-packages/commit/bf38cc29821d96d801f56e70342426e1b12692e1)) +* Support disabling aztec vm in non-wasm builds ([#6965](https://github.com/AztecProtocol/aztec-packages/issues/6965)) ([f7a46c0](https://github.com/AztecProtocol/aztec-packages/commit/f7a46c0d8de2e58b7e76576a76eb85f52b266966)) +* Sync from aztec-packages (https://github.com/noir-lang/noir/pull/5222) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* Track timeout status of proving jobs ([#6868](https://github.com/AztecProtocol/aztec-packages/issues/6868)) ([7306176](https://github.com/AztecProtocol/aztec-packages/commit/7306176c80d1d80c032c3eed38a2008d545fb025)) + + +### Bug Fixes + +* ALU pil relation TWO_LINE_OP_NO_OVERLAP ([#6968](https://github.com/AztecProtocol/aztec-packages/issues/6968)) ([4ba553b](https://github.com/AztecProtocol/aztec-packages/commit/4ba553ba3170838de3b6c4cf47b609b0198443d0)) +* AVM / aztec-up CircleCI issues ([#7045](https://github.com/AztecProtocol/aztec-packages/issues/7045)) ([3f5d380](https://github.com/AztecProtocol/aztec-packages/commit/3f5d380f72d5ae819b2718ef9fbdfaec6b9a0e4d)) +* **avm:** Bugfix related to pc increment in calldatacopy of avm circuit ([#6891](https://github.com/AztecProtocol/aztec-packages/issues/6891)) ([5fe59d2](https://github.com/AztecProtocol/aztec-packages/commit/5fe59d2ed96a5b966efc9e3619c87b4a23c502f4)) +* **avm:** Correctly generate public inputs in verifier ([#7018](https://github.com/AztecProtocol/aztec-packages/issues/7018)) ([4c4c17f](https://github.com/AztecProtocol/aztec-packages/commit/4c4c17f804b8735dc017bbae171117ca15df25cc)) +* Aztec-builder port issue ([#7068](https://github.com/AztecProtocol/aztec-packages/issues/7068)) ([729e69a](https://github.com/AztecProtocol/aztec-packages/commit/729e69ae2cd773ee176935b7d4644db95dd62668)) +* Biggroup batch mul handles collisions ([#6780](https://github.com/AztecProtocol/aztec-packages/issues/6780)) ([e61c40e](https://github.com/AztecProtocol/aztec-packages/commit/e61c40e9c3e71f50c2d6a6c8a1688b6a8ddd4ba8)) +* Bugfix for Keccak opcode related to reading bytes from input ([#6989](https://github.com/AztecProtocol/aztec-packages/issues/6989)) ([5713f4e](https://github.com/AztecProtocol/aztec-packages/commit/5713f4e25ef8bf09cb91632bd210cd46bb7a77c3)) +* Correct docker-compose vars ([#6945](https://github.com/AztecProtocol/aztec-packages/issues/6945)) ([d492ac8](https://github.com/AztecProtocol/aztec-packages/commit/d492ac80e346572a371df84a6cebc4409b634a8d)) +* Declare volume ([#6881](https://github.com/AztecProtocol/aztec-packages/issues/6881)) ([1e38115](https://github.com/AztecProtocol/aztec-packages/commit/1e381159bb1d407dec8a4926242ecd54ec38e787)) +* Dirty merge 6880 ([#6905](https://github.com/AztecProtocol/aztec-packages/issues/6905)) ([fc6ec3f](https://github.com/AztecProtocol/aztec-packages/commit/fc6ec3fc7371b2506e7409a7d24ce37f25803fac)) +* Do not fail if rollup contract does not support turns ([#6938](https://github.com/AztecProtocol/aztec-packages/issues/6938)) ([5e6fe68](https://github.com/AztecProtocol/aztec-packages/commit/5e6fe68e088483203655522e0242c7e3230297b5)) +* Docker compose env vars ([#6926](https://github.com/AztecProtocol/aztec-packages/issues/6926)) ([14e0c1d](https://github.com/AztecProtocol/aztec-packages/commit/14e0c1df512555900cd49fff2d9070b489984e2f)) +* **docs:** Fix avm instruction set table ([#7061](https://github.com/AztecProtocol/aztec-packages/issues/7061)) ([fcbd44b](https://github.com/AztecProtocol/aztec-packages/commit/fcbd44b43e8a5dd459b543aaa25158d7f1dcc050)) +* **docs:** Remove prefix in link to code snippet source ([#6878](https://github.com/AztecProtocol/aztec-packages/issues/6878)) ([0e8e772](https://github.com/AztecProtocol/aztec-packages/commit/0e8e772c05c81c0b5cf6a2d047a5587c6c2e1a9c)) +* **elaborator:** Invert unconstrained check (https://github.com/noir-lang/noir/pull/5176) ([bf38cc2](https://github.com/AztecProtocol/aztec-packages/commit/bf38cc29821d96d801f56e70342426e1b12692e1)) +* **elaborator:** Lazily elaborate globals (https://github.com/noir-lang/noir/pull/5191) ([bf38cc2](https://github.com/AztecProtocol/aztec-packages/commit/bf38cc29821d96d801f56e70342426e1b12692e1)) +* Ensure changes in aztec up directory are deployed ([#7031](https://github.com/AztecProtocol/aztec-packages/issues/7031)) ([e673fd4](https://github.com/AztecProtocol/aztec-packages/commit/e673fd4784147c365d9191a997049c53a7d6d67f)), closes [#6932](https://github.com/AztecProtocol/aztec-packages/issues/6932) +* Error for allocate instructions in acir-gen (https://github.com/noir-lang/noir/pull/5200) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* **experimental elaborator:** Clear generics after elaborating type aliases (https://github.com/noir-lang/noir/pull/5136) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* **experimental elaborator:** Fix `impl Trait` when `--use-elaborator` is selected (https://github.com/noir-lang/noir/pull/5138) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* **experimental elaborator:** Fix definition kind of globals and tuple patterns with `--use-elaborator` flag (https://github.com/noir-lang/noir/pull/5139) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* **experimental elaborator:** Fix frontend tests when `--use-elaborator` flag is specified (https://github.com/noir-lang/noir/pull/5145) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* **experimental elaborator:** Fix global values used in the elaborator (https://github.com/noir-lang/noir/pull/5135) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* **experimental elaborator:** Fix globals which use function calls (https://github.com/noir-lang/noir/pull/5172) ([bf38cc2](https://github.com/AztecProtocol/aztec-packages/commit/bf38cc29821d96d801f56e70342426e1b12692e1)) +* Expose node port ([#6917](https://github.com/AztecProtocol/aztec-packages/issues/6917)) ([131af88](https://github.com/AztecProtocol/aztec-packages/commit/131af8806a453b851403b0eb7cba855bc2c0cc43)) +* Fix avm unit test with proving by passing the public_inputs ([#7062](https://github.com/AztecProtocol/aztec-packages/issues/7062)) ([2d7c097](https://github.com/AztecProtocol/aztec-packages/commit/2d7c097d7a6606101354736d69bd0bbbe6f005bf)) +* Fix client ivc incorrect srs size issue and parallelise srs generation for grumpkin ([#6913](https://github.com/AztecProtocol/aztec-packages/issues/6913)) ([f015736](https://github.com/AztecProtocol/aztec-packages/commit/f01573641728d6cc62da36189a22fa813713fd82)) +* Fix for the flaky issue (I hope) ([#6923](https://github.com/AztecProtocol/aztec-packages/issues/6923)) ([39747b9](https://github.com/AztecProtocol/aztec-packages/commit/39747b933a13aa08f25c5074207f9d92489d5e3d)) +* Fix panic in `get_global_let_statement` (https://github.com/noir-lang/noir/pull/5177) ([bf38cc2](https://github.com/AztecProtocol/aztec-packages/commit/bf38cc29821d96d801f56e70342426e1b12692e1)) +* Fixing 0 naf ([#6950](https://github.com/AztecProtocol/aztec-packages/issues/6950)) ([d35ee2e](https://github.com/AztecProtocol/aztec-packages/commit/d35ee2ed87967a5161ef52d892856900a55de0b9)) +* **frontend:** Resolve object types from method calls a single time (https://github.com/noir-lang/noir/pull/5131) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Initialize side_effect_counter based on the initial value passed to builder ([#7017](https://github.com/AztecProtocol/aztec-packages/issues/7017)) ([46d166b](https://github.com/AztecProtocol/aztec-packages/commit/46d166b0f1d16d801e056d3195546970cddda1a8)) +* **p2p:** Remove p2p datastore persistence for now ([#6879](https://github.com/AztecProtocol/aztec-packages/issues/6879)) ([ce7f0e2](https://github.com/AztecProtocol/aztec-packages/commit/ce7f0e244621a599796e8d26fd37540b541ca0d3)) +* Pxe waits for node to go up ([#6933](https://github.com/AztecProtocol/aztec-packages/issues/6933)) ([06f03fd](https://github.com/AztecProtocol/aztec-packages/commit/06f03fdf73d9374b5d18d33cf1480f7748db016f)) +* Register account contract before recipient ([#6855](https://github.com/AztecProtocol/aztec-packages/issues/6855)) ([dfea1c7](https://github.com/AztecProtocol/aztec-packages/commit/dfea1c79f57564af3be83a0b3244374f74834571)) +* Revert "chore: add arm64 version of aztec-nargo image" ([#7039](https://github.com/AztecProtocol/aztec-packages/issues/7039)) ([25d12da](https://github.com/AztecProtocol/aztec-packages/commit/25d12da45c1c36e8c5b77a8c81baea3bb365d2c6)) +* SimulateTx does not prove ([#6930](https://github.com/AztecProtocol/aztec-packages/issues/6930)) ([d3d6b9e](https://github.com/AztecProtocol/aztec-packages/commit/d3d6b9ebfa81267b28ebf361fdba310071963492)) +* Stop squashing storage accesses in avm simulator - all need to be validated in kernel ([#7036](https://github.com/AztecProtocol/aztec-packages/issues/7036)) ([6ffc4b4](https://github.com/AztecProtocol/aztec-packages/commit/6ffc4b4455a0613c933de0ec7528774186f53bee)) +* Update docker-compopse env vars ([#6943](https://github.com/AztecProtocol/aztec-packages/issues/6943)) ([80d1121](https://github.com/AztecProtocol/aztec-packages/commit/80d1121f270363a3da1e4200f41283f822357f92)) +* Updating max update requests per tx ([#6783](https://github.com/AztecProtocol/aztec-packages/issues/6783)) ([55b1cf7](https://github.com/AztecProtocol/aztec-packages/commit/55b1cf7056ab3d630b2ed98d1d99c43b39feb587)) +* Use predicate for curve operations (https://github.com/noir-lang/noir/pull/5076) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Wrapping in signed division (https://github.com/noir-lang/noir/pull/5134) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) + + +### Miscellaneous + +* Add arm64 version of aztec-nargo image ([#7034](https://github.com/AztecProtocol/aztec-packages/issues/7034)) ([2a41e84](https://github.com/AztecProtocol/aztec-packages/commit/2a41e8415bac26b122c0da2672bf3077aae4eda2)) +* Add more lints related to oracle calls (https://github.com/noir-lang/noir/pull/5193) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* Add negative tests for cast and U128 multiplication related to TWO_LINE_OP_NO_OVERLAP ([#7041](https://github.com/AztecProtocol/aztec-packages/issues/7041)) ([7f14ca1](https://github.com/AztecProtocol/aztec-packages/commit/7f14ca122032a56eb322e34ee0290845e75a925a)), closes [#6969](https://github.com/AztecProtocol/aztec-packages/issues/6969) +* Add some property tests to ACVM crates (https://github.com/noir-lang/noir/pull/5215) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* Add transfer to undeployed account ([#7015](https://github.com/AztecProtocol/aztec-packages/issues/7015)) ([46324b9](https://github.com/AztecProtocol/aztec-packages/commit/46324b96343a9b603413843480211d05abdf4556)) +* Add transferFrom migration notes ([#7079](https://github.com/AztecProtocol/aztec-packages/issues/7079)) ([d4921a0](https://github.com/AztecProtocol/aztec-packages/commit/d4921a032a56eb0ba464b0e505f6ac11cb41502d)) +* Automate necessary changes to outward sync into noir-lang/noir ([#7049](https://github.com/AztecProtocol/aztec-packages/issues/7049)) ([449e41c](https://github.com/AztecProtocol/aztec-packages/commit/449e41c1ffbded4b64bf9cde7a97fd8670d7647c)) +* **avm:** Add a TS prover test suite for each avm context function ([#6957](https://github.com/AztecProtocol/aztec-packages/issues/6957)) ([f745696](https://github.com/AztecProtocol/aztec-packages/commit/f745696270a440ce45a33b1f72996e47dacdaf74)) +* **avm:** Add bytecode size metrics ([#7042](https://github.com/AztecProtocol/aztec-packages/issues/7042)) ([555d97a](https://github.com/AztecProtocol/aztec-packages/commit/555d97af65cfb1b8d30b32d5b9b9a23b9b446f9e)) +* **avm:** Add debugging info and trace dump ([#6979](https://github.com/AztecProtocol/aztec-packages/issues/6979)) ([e11f880](https://github.com/AztecProtocol/aztec-packages/commit/e11f88004e2c31cb2b2ae376095513e94584a4dc)) +* **avm:** Add tag checking and missing indirects ([#6936](https://github.com/AztecProtocol/aztec-packages/issues/6936)) ([48be80c](https://github.com/AztecProtocol/aztec-packages/commit/48be80c4f9cd21885b21cb9c8202e956d537e595)) +* **avm:** Add TS bb prover tests for hashing opcodes ([#6970](https://github.com/AztecProtocol/aztec-packages/issues/6970)) ([312718a](https://github.com/AztecProtocol/aztec-packages/commit/312718a6946651470c7c97e42414bfc654355d24)) +* **avm:** Enable tag checking and some proving tests ([#6966](https://github.com/AztecProtocol/aztec-packages/issues/6966)) ([b19daa4](https://github.com/AztecProtocol/aztec-packages/commit/b19daa44f034e50109e53363e691493534e7d3f1)) +* **avm:** Fix proving for kernel tests ([#7033](https://github.com/AztecProtocol/aztec-packages/issues/7033)) ([f5e1106](https://github.com/AztecProtocol/aztec-packages/commit/f5e1106bcaa9558ac0a953de06d4fafd09fb1fe8)) +* **avm:** Fix struct serialization and factory ([#6903](https://github.com/AztecProtocol/aztec-packages/issues/6903)) ([bee2646](https://github.com/AztecProtocol/aztec-packages/commit/bee2646d0274806e8fd1a74bd321620c8c8bd0d9)) +* **avm:** Gas alignments with simulator ([#6873](https://github.com/AztecProtocol/aztec-packages/issues/6873)) ([54339d4](https://github.com/AztecProtocol/aztec-packages/commit/54339d48861a91429e996177713f46952ffbd808)), closes [#6860](https://github.com/AztecProtocol/aztec-packages/issues/6860) +* **avm:** Modify unit test to have a calldatacopy over 4 elements ([#6893](https://github.com/AztecProtocol/aztec-packages/issues/6893)) ([9f5b113](https://github.com/AztecProtocol/aztec-packages/commit/9f5b11345dc5dd055442eaf7673227fe7cbaf262)) +* **avm:** Remove unused public context inputs ([#7028](https://github.com/AztecProtocol/aztec-packages/issues/7028)) ([f7a0921](https://github.com/AztecProtocol/aztec-packages/commit/f7a0921bb4bb26a3abba9c298a7f50e49248d711)) +* Avoid `bn254_blackbox_solver` polluting feature flags (https://github.com/noir-lang/noir/pull/5141) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* Avoid manual creation of contract artifact in wasm (https://github.com/noir-lang/noir/pull/5117) ([bf38cc2](https://github.com/AztecProtocol/aztec-packages/commit/bf38cc29821d96d801f56e70342426e1b12692e1)) +* Bb repo warning ([#7023](https://github.com/AztecProtocol/aztec-packages/issues/7023)) ([c3d7053](https://github.com/AztecProtocol/aztec-packages/commit/c3d70537c5558ba451a43e403bab067940aa48b6)) +* **bb:** Hide `debug()` logs under `--debug` flag ([#7008](https://github.com/AztecProtocol/aztec-packages/issues/7008)) ([a8c3c3f](https://github.com/AztecProtocol/aztec-packages/commit/a8c3c3fcf35b7c464006c481230afcb11b9952dc)) +* Break out helper methods for writing foreign call results (https://github.com/noir-lang/noir/pull/5181) ([bf38cc2](https://github.com/AztecProtocol/aztec-packages/commit/bf38cc29821d96d801f56e70342426e1b12692e1)) +* **ci:** Don't raise MSRV issue if workflow cancelled (https://github.com/noir-lang/noir/pull/5143) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Custom jest Field equality ([#7012](https://github.com/AztecProtocol/aztec-packages/issues/7012)) ([1a198b8](https://github.com/AztecProtocol/aztec-packages/commit/1a198b8d53397f89f9fe6299d9ec5cb42ce245b2)) +* Default to using bn254 in `noirc_frontend` (https://github.com/noir-lang/noir/pull/5144) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* **docs:** Fix incorrect docs github link in footer (https://github.com/noir-lang/noir/pull/5206) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* **docs:** Fixing the breadcrumb issue ([#6605](https://github.com/AztecProtocol/aztec-packages/issues/6605)) ([2624c26](https://github.com/AztecProtocol/aztec-packages/commit/2624c264fd266e090eec1b79654005b4dcd057de)) +* **docs:** Supplement Noir Debugger's dependency versions (https://github.com/noir-lang/noir/pull/5199) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* **docs:** Update docs homepage (https://github.com/noir-lang/noir/pull/5198) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* Enable skipped ordering tests since AVM properly updates side-effect counter for nested calls ([#7064](https://github.com/AztecProtocol/aztec-packages/issues/7064)) ([5ff5ffb](https://github.com/AztecProtocol/aztec-packages/commit/5ff5ffb83ae55c6f12af6e5271e399f4aeaa4737)), closes [#6471](https://github.com/AztecProtocol/aztec-packages/issues/6471) +* **experimental elaborator:** Handle `comptime` expressions in the elaborator (https://github.com/noir-lang/noir/pull/5169) ([bf38cc2](https://github.com/AztecProtocol/aztec-packages/commit/bf38cc29821d96d801f56e70342426e1b12692e1)) +* Fix issue [#6929](https://github.com/AztecProtocol/aztec-packages/issues/6929) (off-by-one error in `UltraCircuitBuilder::create_range_constraint`) ([#6931](https://github.com/AztecProtocol/aztec-packages/issues/6931)) ([16deef6](https://github.com/AztecProtocol/aztec-packages/commit/16deef6a83a9fe41e1f865e79e17c2f671604bb0)) +* Fix migration notes ([#7075](https://github.com/AztecProtocol/aztec-packages/issues/7075)) ([ac75f8c](https://github.com/AztecProtocol/aztec-packages/commit/ac75f8cf2019dd00f80c81259c30737a042a4b9b)) +* Granular public simulation benchmarks ([#6924](https://github.com/AztecProtocol/aztec-packages/issues/6924)) ([b70bc98](https://github.com/AztecProtocol/aztec-packages/commit/b70bc98c948c51053560e8948a43b65159a95b58)) +* Inline `FieldElement.is_negative` and document (https://github.com/noir-lang/noir/pull/5214) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* Lookups cleanup/documentation ([#7002](https://github.com/AztecProtocol/aztec-packages/issues/7002)) ([92b1349](https://github.com/AztecProtocol/aztec-packages/commit/92b1349ba671e87e948bf9248c5133accde9091f)) +* Loosen trait bounds on impls depending on `AcirField` (https://github.com/noir-lang/noir/pull/5115) ([bf38cc2](https://github.com/AztecProtocol/aztec-packages/commit/bf38cc29821d96d801f56e70342426e1b12692e1)) +* Make `nargo` crate and debug info generic (https://github.com/noir-lang/noir/pull/5184) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* Mark all oracles as unconstrained ([#7032](https://github.com/AztecProtocol/aztec-packages/issues/7032)) ([7a68be4](https://github.com/AztecProtocol/aztec-packages/commit/7a68be4bc31114853d8c25549029c74afd9a8f37)) +* Move acir docs to code declaration (https://github.com/noir-lang/noir/pull/5040) ([bf38cc2](https://github.com/AztecProtocol/aztec-packages/commit/bf38cc29821d96d801f56e70342426e1b12692e1)) +* Move gas bridge initialization into L1 contracts deployment ([#6912](https://github.com/AztecProtocol/aztec-packages/issues/6912)) ([26a1fc4](https://github.com/AztecProtocol/aztec-packages/commit/26a1fc4bcec04434b61651e2f527938a14f3ac3a)) +* Move implementation of bitwise operations into `blackbox_solver` (https://github.com/noir-lang/noir/pull/5209) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* Note emission ([#7003](https://github.com/AztecProtocol/aztec-packages/issues/7003)) ([10048da](https://github.com/AztecProtocol/aztec-packages/commit/10048da5ce7edfe850d03ee97505ed72552c1dca)) +* Note processor cleanup ([#6870](https://github.com/AztecProtocol/aztec-packages/issues/6870)) ([315c46e](https://github.com/AztecProtocol/aztec-packages/commit/315c46e3804718bcaf7337da887548755984ca67)) +* Opcodes l2gasleft and dagasleft return value with tag ff ([#6896](https://github.com/AztecProtocol/aztec-packages/issues/6896)) ([5890845](https://github.com/AztecProtocol/aztec-packages/commit/5890845e8f9b278b2a5c5c930eb28ec0aba74ebc)) +* Parallelise compilation of contracts and protocol circuits ([#7009](https://github.com/AztecProtocol/aztec-packages/issues/7009)) ([86a3314](https://github.com/AztecProtocol/aztec-packages/commit/86a33140f9a65e518003b3f4c60f97d132f85b89)) +* Remove `distinct` keyword (https://github.com/noir-lang/noir/pull/5219) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* Remove `param_witnesses` and `return_witnesses` from ABI (https://github.com/noir-lang/noir/pull/5154) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* Remove deprecated functions ([#7029](https://github.com/AztecProtocol/aztec-packages/issues/7029)) ([bc80e85](https://github.com/AztecProtocol/aztec-packages/commit/bc80e8575b5e60c3a45a7631e445c79774d20a49)) +* Remove hir to ast pass (https://github.com/noir-lang/noir/pull/5147) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Remove old public storage access ordering hack ([#7063](https://github.com/AztecProtocol/aztec-packages/issues/7063)) ([bf6b8b8](https://github.com/AztecProtocol/aztec-packages/commit/bf6b8b86d78ce6ee5e863dc0a43e78c36b6b35a8)) +* Remove stale comment (https://github.com/noir-lang/noir/pull/5179) ([12af650](https://github.com/AztecProtocol/aztec-packages/commit/12af650f0d27c37dca06bb329bf76a5574534d78)) +* Remove unused `new_variables` argument from `resolve_type_inner` (https://github.com/noir-lang/noir/pull/5148) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Rename p2p vars ([#6916](https://github.com/AztecProtocol/aztec-packages/issues/6916)) ([ae7d757](https://github.com/AztecProtocol/aztec-packages/commit/ae7d75764fc704daae67be882e0e9f09a0a9407c)) +* Replace relative paths to noir-protocol-circuits ([8f7b865](https://github.com/AztecProtocol/aztec-packages/commit/8f7b8656940354df38bb623bc6d8941ab98f3e5d)) +* Replace relative paths to noir-protocol-circuits ([91e1554](https://github.com/AztecProtocol/aztec-packages/commit/91e155472951908e455fff9279118f0b9be0900b)) +* Replace relative paths to noir-protocol-circuits ([f4fed13](https://github.com/AztecProtocol/aztec-packages/commit/f4fed131a9c3bb568a995846d09f793620c5a366)) +* Replace relative paths to noir-protocol-circuits ([7caa288](https://github.com/AztecProtocol/aztec-packages/commit/7caa28892086b9f97d417d0694e3cad228fd5788)) +* Replace relative paths to noir-protocol-circuits ([8a299e9](https://github.com/AztecProtocol/aztec-packages/commit/8a299e99783775d70ba8871f44057a03daaf4917)) +* Replace relative paths to noir-protocol-circuits ([acf1188](https://github.com/AztecProtocol/aztec-packages/commit/acf1188fb1fc5ea4d53d57a6c0a362ad55cd707e)) +* Replace relative paths to noir-protocol-circuits ([094b511](https://github.com/AztecProtocol/aztec-packages/commit/094b511e6a696e5c2a7687147ca21007801237de)) +* Replace relative paths to noir-protocol-circuits ([8e07176](https://github.com/AztecProtocol/aztec-packages/commit/8e0717654ec7f75fe2ea8577457359ec2a102b58)) +* Replace relative paths to noir-protocol-circuits ([52b6934](https://github.com/AztecProtocol/aztec-packages/commit/52b69341129a23e300292e3f5e207cb512b05aa6)) +* Replace relative paths to noir-protocol-circuits ([873dcea](https://github.com/AztecProtocol/aztec-packages/commit/873dcea15e4e802f99998e2ed113ebaa8bd834e6)) +* Replace sibling path read with leaf read ([#6834](https://github.com/AztecProtocol/aztec-packages/issues/6834)) ([a20d845](https://github.com/AztecProtocol/aztec-packages/commit/a20d845d35715816ddc889fb9a75fb9fba4fc356)) +* Run all test programs in brillig as well as ACIR (https://github.com/noir-lang/noir/pull/5128) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Schnorr signature verification in noir (https://github.com/noir-lang/noir/pull/5188) ([bf38cc2](https://github.com/AztecProtocol/aztec-packages/commit/bf38cc29821d96d801f56e70342426e1b12692e1)) +* Small fixes for the tube flows ([#7014](https://github.com/AztecProtocol/aztec-packages/issues/7014)) ([838ceed](https://github.com/AztecProtocol/aztec-packages/commit/838ceed3b6ccf1bb7d89552a147db92c3514f0c1)) +* Split log emission to encrypt and a log, remove address input ([#6987](https://github.com/AztecProtocol/aztec-packages/issues/6987)) ([ca0e084](https://github.com/AztecProtocol/aztec-packages/commit/ca0e0848563cfae72ebd7d4487a6e2812c2a405c)) +* Start moving lints into a separate linting directory (https://github.com/noir-lang/noir/pull/5165) ([bf38cc2](https://github.com/AztecProtocol/aztec-packages/commit/bf38cc29821d96d801f56e70342426e1b12692e1)) +* Terraform Updates ([#6887](https://github.com/AztecProtocol/aztec-packages/issues/6887)) ([33a3870](https://github.com/AztecProtocol/aztec-packages/commit/33a3870d06ae8bb5d08dbbd9f72a62e0811e5e7d)) +* Transfer and transferfrom to save constrains for simpler cases ([#7013](https://github.com/AztecProtocol/aztec-packages/issues/7013)) ([612b972](https://github.com/AztecProtocol/aztec-packages/commit/612b9724a419224c72cd823c889ece4ae8f00ab0)) +* TS avm proving test - add a pattern for assertion failure (timestamp example) ([#7005](https://github.com/AztecProtocol/aztec-packages/issues/7005)) ([cfef246](https://github.com/AztecProtocol/aztec-packages/commit/cfef24654492a1f3eef94db60937bd3a45f8ec3c)) +* Update comment on transient nullification ([#7001](https://github.com/AztecProtocol/aztec-packages/issues/7001)) ([6c4e61c](https://github.com/AztecProtocol/aztec-packages/commit/6c4e61c19613560af8aedba03531958f8471bb62)) +* Updated devnet terraform ([#6927](https://github.com/AztecProtocol/aztec-packages/issues/6927)) ([4692fb0](https://github.com/AztecProtocol/aztec-packages/commit/4692fb034f22bb62593d257777b7b545993c27ab)) +* Updated l1 contracts in compose file ([#6942](https://github.com/AztecProtocol/aztec-packages/issues/6942)) ([15371ce](https://github.com/AztecProtocol/aztec-packages/commit/15371ceafb62627cd0bcb5ba65c854f07e09cb49)) +* Updated sha for devnet image in compose file ([#6939](https://github.com/AztecProtocol/aztec-packages/issues/6939)) ([83dd231](https://github.com/AztecProtocol/aztec-packages/commit/83dd231d7c7bc561829296cb3f252fb9ab50528f)) + + +### Documentation + +* Add account tags ([#7011](https://github.com/AztecProtocol/aztec-packages/issues/7011)) ([8580467](https://github.com/AztecProtocol/aztec-packages/commit/8580467354fe32cda87c956ea40caa4d0f058a04)) +* **avm:** Comments in pil file related to range checks of addresses ([#6837](https://github.com/AztecProtocol/aztec-packages/issues/6837)) ([66f1c87](https://github.com/AztecProtocol/aztec-packages/commit/66f1c876578b05838698377f2ede12b52671e4ca)) +* Aztec macros ([#6935](https://github.com/AztecProtocol/aztec-packages/issues/6935)) ([57078d4](https://github.com/AztecProtocol/aztec-packages/commit/57078d4aea54c4beaf66f10db2f0052d4577e46a)) +* Clarify comment on collapse ([#7038](https://github.com/AztecProtocol/aztec-packages/issues/7038)) ([6237ddd](https://github.com/AztecProtocol/aztec-packages/commit/6237ddd9052fc98a26de07f11bd494843dcc07ee)) +* Update HOW_WE_WRITE_DOCS.md ([#6850](https://github.com/AztecProtocol/aztec-packages/issues/6850)) ([d4dfdaf](https://github.com/AztecProtocol/aztec-packages/commit/d4dfdaf9ab03eeafa3d54be178fc72c59ac51b95)) + ## [0.42.0](https://github.com/AztecProtocol/aztec-packages/compare/aztec-packages-v0.41.0...aztec-packages-v0.42.0) (2024-06-04) diff --git a/avm-transpiler/src/main.rs b/avm-transpiler/src/main.rs index 7a4c10f2cb5..1a858d59601 100644 --- a/avm-transpiler/src/main.rs +++ b/avm-transpiler/src/main.rs @@ -21,7 +21,7 @@ fn main() { let in_contract_artifact_path = &args[1]; let out_transpiled_artifact_path = &args[2]; - // Parse original (pre-transpile) contract + // Parse original (pre-transpile) contract. let contract_json = fs::read_to_string(Path::new(in_contract_artifact_path)).expect("Unable to read file"); let raw_json_obj: serde_json::Value = @@ -33,7 +33,7 @@ fn main() { return; } - // Backup the original file + // Backup the original file. std::fs::copy( Path::new(in_contract_artifact_path), Path::new(&(in_contract_artifact_path.clone() + ".bak")), diff --git a/avm-transpiler/src/opcodes.rs b/avm-transpiler/src/opcodes.rs index e4d642dd829..11cd956237d 100644 --- a/avm-transpiler/src/opcodes.rs +++ b/avm-transpiler/src/opcodes.rs @@ -73,6 +73,7 @@ pub enum AvmOpcode { SHA256, // temp - may be removed, but alot of contracts rely on it PEDERSEN, // temp - may be removed, but alot of contracts rely on it ECADD, + MSM, // Conversions TORADIXLE, } @@ -165,6 +166,7 @@ impl AvmOpcode { AvmOpcode::SHA256 => "SHA256 ", AvmOpcode::PEDERSEN => "PEDERSEN", AvmOpcode::ECADD => "ECADD", + AvmOpcode::MSM => "MSM", // Conversions AvmOpcode::TORADIXLE => "TORADIXLE", } diff --git a/avm-transpiler/src/transpile.rs b/avm-transpiler/src/transpile.rs index 67d0f8043a6..f1fdd201b8b 100644 --- a/avm-transpiler/src/transpile.rs +++ b/avm-transpiler/src/transpile.rs @@ -855,6 +855,30 @@ fn handle_black_box_function(avm_instrs: &mut Vec, operation: &B ], ..Default::default() }), + // Temporary while we dont have efficient noir implementations + BlackBoxOp::MultiScalarMul { points, scalars, outputs } => { + // The length of the scalars vector is 2x the length of the points vector due to limb + // decomposition + let points_offset = points.pointer.0; + let num_points = points.size.0; + let scalars_offset = scalars.pointer.0; + // Output array is fixed to 3 + assert_eq!(outputs.size, 3, "Output array size must be equal to 3"); + let outputs_offset = outputs.pointer.0; + avm_instrs.push(AvmInstruction { + opcode: AvmOpcode::MSM, + indirect: Some( + ZEROTH_OPERAND_INDIRECT | FIRST_OPERAND_INDIRECT | SECOND_OPERAND_INDIRECT, + ), + operands: vec![ + AvmOperand::U32 { value: points_offset as u32 }, + AvmOperand::U32 { value: scalars_offset as u32 }, + AvmOperand::U32 { value: outputs_offset as u32 }, + AvmOperand::U32 { value: num_points as u32 }, + ], + ..Default::default() + }); + } _ => panic!("Transpiler doesn't know how to process {:?}", operation), } } diff --git a/aztec-up/bin/aztec-builder b/aztec-up/bin/aztec-builder index cd4cafc81d2..c940ebf535e 100755 --- a/aztec-up/bin/aztec-builder +++ b/aztec-up/bin/aztec-builder @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -export SKIP_PORT_ASSIGNMENTS=1 +export SKIP_PORT_ASSIGNMENT=1 export ENV_VARS_TO_INJECT="PXE_URL PRIVATE_KEY DEBUG" export PXE_URL=${PXE_URL:-"http://host.docker.internal:8080"} export ETHEREUM_HOST=${ETHEREUM_HOST:-"http://host.docker.internal:8545"} diff --git a/barretenberg/.gitrepo b/barretenberg/.gitrepo index 9326d1f7624..d2508be6360 100644 --- a/barretenberg/.gitrepo +++ b/barretenberg/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/AztecProtocol/barretenberg branch = master - commit = 9cf627c8a0b5ca9b0ec3c41e379b6649dfe855bb - parent = f7a0921bb4bb26a3abba9c298a7f50e49248d711 + commit = 2d7b8b24571369e693e7e19470d7c85f0560368c + parent = 77761c670f2d516ab486de0f7bde036ff00ebd99 method = merge cmdver = 0.4.6 diff --git a/barretenberg/CHANGELOG.md b/barretenberg/CHANGELOG.md index 7360a1c32c9..38233698dbc 100644 --- a/barretenberg/CHANGELOG.md +++ b/barretenberg/CHANGELOG.md @@ -1,5 +1,90 @@ # Changelog +## [0.43.0](https://github.com/AztecProtocol/aztec-packages/compare/barretenberg-v0.42.0...barretenberg-v0.43.0) (2024-06-18) + + +### Features + +* Add gate profiler for noir circuits ([#7004](https://github.com/AztecProtocol/aztec-packages/issues/7004)) ([a2f6876](https://github.com/AztecProtocol/aztec-packages/commit/a2f687687559d15fde52abce54838f6e144a0aa4)) +* Add standard form function to biggroup ([#6899](https://github.com/AztecProtocol/aztec-packages/issues/6899)) ([3e44be5](https://github.com/AztecProtocol/aztec-packages/commit/3e44be538e5c7f0e7269c1e5c0820f7bc6e83734)) +* Affine_element read/write with proper handling of point at infinity ([#6963](https://github.com/AztecProtocol/aztec-packages/issues/6963)) ([c6cbe39](https://github.com/AztecProtocol/aztec-packages/commit/c6cbe39eed23dc845aef898e937e99de43f71675)) +* Avm e2e nested call + alu fix + cast fix ([#6974](https://github.com/AztecProtocol/aztec-packages/issues/6974)) ([b150b61](https://github.com/AztecProtocol/aztec-packages/commit/b150b610153e380a93240914c95887f88b56fa94)) +* **avm-simulator:** Msm blackbox ([#7048](https://github.com/AztecProtocol/aztec-packages/issues/7048)) ([0ce27e0](https://github.com/AztecProtocol/aztec-packages/commit/0ce27e05c4c099167d0d98300f6d73ced22639ad)) +* **avm:** Add get_contract_instance ([#6871](https://github.com/AztecProtocol/aztec-packages/issues/6871)) ([b3a86bf](https://github.com/AztecProtocol/aztec-packages/commit/b3a86bf72343d1060ce58a11f139e05ba2a75754)) +* **avm:** Deserialise execution hints in bb main ([#6848](https://github.com/AztecProtocol/aztec-packages/issues/6848)) ([d3be85f](https://github.com/AztecProtocol/aztec-packages/commit/d3be85f57c34aa88e732ea115239f3bed1e7aa16)) +* **avm:** E2e proving of storage ([#6967](https://github.com/AztecProtocol/aztec-packages/issues/6967)) ([6a7be0c](https://github.com/AztecProtocol/aztec-packages/commit/6a7be0c434934175bb6da1f3525c025b3f743824)) +* **avm:** E2e send l1 msg ([#6880](https://github.com/AztecProtocol/aztec-packages/issues/6880)) ([deb972d](https://github.com/AztecProtocol/aztec-packages/commit/deb972d3f13a92d34a6f91074b072fb66d247f64)) +* **avm:** Gas remaining range check and handling of out of gas ([#6944](https://github.com/AztecProtocol/aztec-packages/issues/6944)) ([5647571](https://github.com/AztecProtocol/aztec-packages/commit/56475716e05973e6b493de427f32eee71c0f8f6a)), closes [#6902](https://github.com/AztecProtocol/aztec-packages/issues/6902) +* **avm:** Get contract instance now works e2e with avm proving ([#6911](https://github.com/AztecProtocol/aztec-packages/issues/6911)) ([662187d](https://github.com/AztecProtocol/aztec-packages/commit/662187d1d6960b734a71aaf365e7f20d471dc4c9)) +* **avm:** Indirect support for kernel output opcodes ([#6962](https://github.com/AztecProtocol/aztec-packages/issues/6962)) ([f330bff](https://github.com/AztecProtocol/aztec-packages/commit/f330bffa80b6da5f037cea3cf469ef1c7b6d9d03)) +* **avm:** Indirect support for kernel read opcodes ([#6940](https://github.com/AztecProtocol/aztec-packages/issues/6940)) ([ccc474d](https://github.com/AztecProtocol/aztec-packages/commit/ccc474d9d0cd10faf857bc1ec6571dc25306a531)) +* **avm:** L2gasleft and dagasleft opcodes ([#6884](https://github.com/AztecProtocol/aztec-packages/issues/6884)) ([fbab612](https://github.com/AztecProtocol/aztec-packages/commit/fbab612b17dfe0e95ead1a592b7bc9fe6ca5415d)) +* **avm:** Nullifier non exist ([#6877](https://github.com/AztecProtocol/aztec-packages/issues/6877)) ([05697f2](https://github.com/AztecProtocol/aztec-packages/commit/05697f289d3b97def74f45cd839a58a8a077c3fa)) +* **avm:** Plumb externalcall hints ([#6890](https://github.com/AztecProtocol/aztec-packages/issues/6890)) ([3a97f08](https://github.com/AztecProtocol/aztec-packages/commit/3a97f08c457472bd701200adfa45d61554fd3867)) +* **avm:** Plumb start side effect counter in circuit ([#7007](https://github.com/AztecProtocol/aztec-packages/issues/7007)) ([fa8f12f](https://github.com/AztecProtocol/aztec-packages/commit/fa8f12f93a8d94604a4382de444501fac310dbb8)) +* **avm:** Revert opcode ([#6909](https://github.com/AztecProtocol/aztec-packages/issues/6909)) ([620d3da](https://github.com/AztecProtocol/aztec-packages/commit/620d3dacc853c71e808ef58001eb4c8584fa59d9)) +* **avm:** Use hints in gas accounting (circuit) ([#6895](https://github.com/AztecProtocol/aztec-packages/issues/6895)) ([c3746f5](https://github.com/AztecProtocol/aztec-packages/commit/c3746f5d6ae38bc448d00834d91a7ddd7b901e64)) +* **bb:** Stack traces for check_circuit ([#6851](https://github.com/AztecProtocol/aztec-packages/issues/6851)) ([eb35e62](https://github.com/AztecProtocol/aztec-packages/commit/eb35e627445c72ee07fafb3652076349302e7fa1)) +* Contract storage reads serialize with side effect counter ([#6961](https://github.com/AztecProtocol/aztec-packages/issues/6961)) ([db49ed5](https://github.com/AztecProtocol/aztec-packages/commit/db49ed57d1d4165ce47e6af01b6fd67239121aa4)) +* Ecadd op code ([#6906](https://github.com/AztecProtocol/aztec-packages/issues/6906)) ([03a9064](https://github.com/AztecProtocol/aztec-packages/commit/03a9064b308fbf5541f4f763e1ad1e05f60e1fff)) +* Flows and tests for the tube component ([#6934](https://github.com/AztecProtocol/aztec-packages/issues/6934)) ([4b45438](https://github.com/AztecProtocol/aztec-packages/commit/4b454386a35f4b0cd4c6a9b8003c55e55e50b592)) +* Place return value witnesses directly after function arguments (https://github.com/noir-lang/noir/pull/5142) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Separate runtimes of SSA functions before inlining (https://github.com/noir-lang/noir/pull/5121) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* SMT Standard Circuit separation ([#6904](https://github.com/AztecProtocol/aztec-packages/issues/6904)) ([f970732](https://github.com/AztecProtocol/aztec-packages/commit/f9707321bdd107e3c7116cafd89fd570224e89ef)) +* SMT Verification Module Update ([#6849](https://github.com/AztecProtocol/aztec-packages/issues/6849)) ([6c98529](https://github.com/AztecProtocol/aztec-packages/commit/6c985299d796b8c711794395518c3b3a0f41e775)) +* SMT Verifier for Ultra Arithmetization ([#7067](https://github.com/AztecProtocol/aztec-packages/issues/7067)) ([6692ac8](https://github.com/AztecProtocol/aztec-packages/commit/6692ac831ab980d9623442236c21b499a7238966)) +* Standard form for cycle_group ([#6915](https://github.com/AztecProtocol/aztec-packages/issues/6915)) ([e6cba16](https://github.com/AztecProtocol/aztec-packages/commit/e6cba16ef82428b115d527eabe237122e269aa32)) +* Support disabling aztec vm in non-wasm builds ([#6965](https://github.com/AztecProtocol/aztec-packages/issues/6965)) ([f7a46c0](https://github.com/AztecProtocol/aztec-packages/commit/f7a46c0d8de2e58b7e76576a76eb85f52b266966)) + + +### Bug Fixes + +* ALU pil relation TWO_LINE_OP_NO_OVERLAP ([#6968](https://github.com/AztecProtocol/aztec-packages/issues/6968)) ([4ba553b](https://github.com/AztecProtocol/aztec-packages/commit/4ba553ba3170838de3b6c4cf47b609b0198443d0)) +* **avm:** Bugfix related to pc increment in calldatacopy of avm circuit ([#6891](https://github.com/AztecProtocol/aztec-packages/issues/6891)) ([5fe59d2](https://github.com/AztecProtocol/aztec-packages/commit/5fe59d2ed96a5b966efc9e3619c87b4a23c502f4)) +* **avm:** Correctly generate public inputs in verifier ([#7018](https://github.com/AztecProtocol/aztec-packages/issues/7018)) ([4c4c17f](https://github.com/AztecProtocol/aztec-packages/commit/4c4c17f804b8735dc017bbae171117ca15df25cc)) +* Biggroup batch mul handles collisions ([#6780](https://github.com/AztecProtocol/aztec-packages/issues/6780)) ([e61c40e](https://github.com/AztecProtocol/aztec-packages/commit/e61c40e9c3e71f50c2d6a6c8a1688b6a8ddd4ba8)) +* Bugfix for Keccak opcode related to reading bytes from input ([#6989](https://github.com/AztecProtocol/aztec-packages/issues/6989)) ([5713f4e](https://github.com/AztecProtocol/aztec-packages/commit/5713f4e25ef8bf09cb91632bd210cd46bb7a77c3)) +* Dirty merge 6880 ([#6905](https://github.com/AztecProtocol/aztec-packages/issues/6905)) ([fc6ec3f](https://github.com/AztecProtocol/aztec-packages/commit/fc6ec3fc7371b2506e7409a7d24ce37f25803fac)) +* **experimental elaborator:** Clear generics after elaborating type aliases (https://github.com/noir-lang/noir/pull/5136) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* **experimental elaborator:** Fix `impl Trait` when `--use-elaborator` is selected (https://github.com/noir-lang/noir/pull/5138) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* **experimental elaborator:** Fix definition kind of globals and tuple patterns with `--use-elaborator` flag (https://github.com/noir-lang/noir/pull/5139) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* **experimental elaborator:** Fix frontend tests when `--use-elaborator` flag is specified (https://github.com/noir-lang/noir/pull/5145) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* **experimental elaborator:** Fix global values used in the elaborator (https://github.com/noir-lang/noir/pull/5135) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Fix avm unit test with proving by passing the public_inputs ([#7062](https://github.com/AztecProtocol/aztec-packages/issues/7062)) ([2d7c097](https://github.com/AztecProtocol/aztec-packages/commit/2d7c097d7a6606101354736d69bd0bbbe6f005bf)) +* Fix client ivc incorrect srs size issue and parallelise srs generation for grumpkin ([#6913](https://github.com/AztecProtocol/aztec-packages/issues/6913)) ([f015736](https://github.com/AztecProtocol/aztec-packages/commit/f01573641728d6cc62da36189a22fa813713fd82)) +* Fix for the flaky issue (I hope) ([#6923](https://github.com/AztecProtocol/aztec-packages/issues/6923)) ([39747b9](https://github.com/AztecProtocol/aztec-packages/commit/39747b933a13aa08f25c5074207f9d92489d5e3d)) +* Fixing 0 naf ([#6950](https://github.com/AztecProtocol/aztec-packages/issues/6950)) ([d35ee2e](https://github.com/AztecProtocol/aztec-packages/commit/d35ee2ed87967a5161ef52d892856900a55de0b9)) +* **frontend:** Resolve object types from method calls a single time (https://github.com/noir-lang/noir/pull/5131) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Initialize side_effect_counter based on the initial value passed to builder ([#7017](https://github.com/AztecProtocol/aztec-packages/issues/7017)) ([46d166b](https://github.com/AztecProtocol/aztec-packages/commit/46d166b0f1d16d801e056d3195546970cddda1a8)) +* Stop squashing storage accesses in avm simulator - all need to be validated in kernel ([#7036](https://github.com/AztecProtocol/aztec-packages/issues/7036)) ([6ffc4b4](https://github.com/AztecProtocol/aztec-packages/commit/6ffc4b4455a0613c933de0ec7528774186f53bee)) +* Use predicate for curve operations (https://github.com/noir-lang/noir/pull/5076) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Wrapping in signed division (https://github.com/noir-lang/noir/pull/5134) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) + + +### Miscellaneous + +* Add negative tests for cast and U128 multiplication related to TWO_LINE_OP_NO_OVERLAP ([#7041](https://github.com/AztecProtocol/aztec-packages/issues/7041)) ([7f14ca1](https://github.com/AztecProtocol/aztec-packages/commit/7f14ca122032a56eb322e34ee0290845e75a925a)), closes [#6969](https://github.com/AztecProtocol/aztec-packages/issues/6969) +* **avm:** Add debugging info and trace dump ([#6979](https://github.com/AztecProtocol/aztec-packages/issues/6979)) ([e11f880](https://github.com/AztecProtocol/aztec-packages/commit/e11f88004e2c31cb2b2ae376095513e94584a4dc)) +* **avm:** Fix proving for kernel tests ([#7033](https://github.com/AztecProtocol/aztec-packages/issues/7033)) ([f5e1106](https://github.com/AztecProtocol/aztec-packages/commit/f5e1106bcaa9558ac0a953de06d4fafd09fb1fe8)) +* **avm:** Gas alignments with simulator ([#6873](https://github.com/AztecProtocol/aztec-packages/issues/6873)) ([54339d4](https://github.com/AztecProtocol/aztec-packages/commit/54339d48861a91429e996177713f46952ffbd808)), closes [#6860](https://github.com/AztecProtocol/aztec-packages/issues/6860) +* **avm:** Modify unit test to have a calldatacopy over 4 elements ([#6893](https://github.com/AztecProtocol/aztec-packages/issues/6893)) ([9f5b113](https://github.com/AztecProtocol/aztec-packages/commit/9f5b11345dc5dd055442eaf7673227fe7cbaf262)) +* Bb repo warning ([#7023](https://github.com/AztecProtocol/aztec-packages/issues/7023)) ([c3d7053](https://github.com/AztecProtocol/aztec-packages/commit/c3d70537c5558ba451a43e403bab067940aa48b6)) +* **bb:** Hide `debug()` logs under `--debug` flag ([#7008](https://github.com/AztecProtocol/aztec-packages/issues/7008)) ([a8c3c3f](https://github.com/AztecProtocol/aztec-packages/commit/a8c3c3fcf35b7c464006c481230afcb11b9952dc)) +* **ci:** Don't raise MSRV issue if workflow cancelled (https://github.com/noir-lang/noir/pull/5143) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Default to using bn254 in `noirc_frontend` (https://github.com/noir-lang/noir/pull/5144) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Fix issue [#6929](https://github.com/AztecProtocol/aztec-packages/issues/6929) (off-by-one error in `UltraCircuitBuilder::create_range_constraint`) ([#6931](https://github.com/AztecProtocol/aztec-packages/issues/6931)) ([16deef6](https://github.com/AztecProtocol/aztec-packages/commit/16deef6a83a9fe41e1f865e79e17c2f671604bb0)) +* Lookups cleanup/documentation ([#7002](https://github.com/AztecProtocol/aztec-packages/issues/7002)) ([92b1349](https://github.com/AztecProtocol/aztec-packages/commit/92b1349ba671e87e948bf9248c5133accde9091f)) +* Opcodes l2gasleft and dagasleft return value with tag ff ([#6896](https://github.com/AztecProtocol/aztec-packages/issues/6896)) ([5890845](https://github.com/AztecProtocol/aztec-packages/commit/5890845e8f9b278b2a5c5c930eb28ec0aba74ebc)) +* Remove hir to ast pass (https://github.com/noir-lang/noir/pull/5147) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Remove unused `new_variables` argument from `resolve_type_inner` (https://github.com/noir-lang/noir/pull/5148) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Run all test programs in brillig as well as ACIR (https://github.com/noir-lang/noir/pull/5128) ([a44b8c8](https://github.com/AztecProtocol/aztec-packages/commit/a44b8c81458eb789e54624e020b6c93d0e9963cc)) +* Small fixes for the tube flows ([#7014](https://github.com/AztecProtocol/aztec-packages/issues/7014)) ([838ceed](https://github.com/AztecProtocol/aztec-packages/commit/838ceed3b6ccf1bb7d89552a147db92c3514f0c1)) + + +### Documentation + +* **avm:** Comments in pil file related to range checks of addresses ([#6837](https://github.com/AztecProtocol/aztec-packages/issues/6837)) ([66f1c87](https://github.com/AztecProtocol/aztec-packages/commit/66f1c876578b05838698377f2ede12b52671e4ca)) + ## [0.42.0](https://github.com/AztecProtocol/aztec-packages/compare/barretenberg-v0.41.0...barretenberg-v0.42.0) (2024-06-04) diff --git a/barretenberg/cpp/CMakeLists.txt b/barretenberg/cpp/CMakeLists.txt index f16b898bf6f..5c76eb77253 100644 --- a/barretenberg/cpp/CMakeLists.txt +++ b/barretenberg/cpp/CMakeLists.txt @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.24 FATAL_ERROR) project( Barretenberg DESCRIPTION "BN254 elliptic curve library, and PLONK SNARK prover" - VERSION 0.42.0 # x-release-please-version + VERSION 0.43.0 # x-release-please-version LANGUAGES CXX C ) # Insert version into `bb` config file diff --git a/barretenberg/cpp/Earthfile b/barretenberg/cpp/Earthfile index 831eb535d83..555b05e9b9b 100644 --- a/barretenberg/cpp/Earthfile +++ b/barretenberg/cpp/Earthfile @@ -247,6 +247,22 @@ test: END RUN cd build && GTEST_COLOR=1 ctest -j$(nproc) --output-on-failure +vm-full-test: + ARG hardware_concurrency="" + # prefetch + BUILD +test-binaries + BUILD +preset-release-assert-test + BUILD ./srs_db/+build # prefetch + FROM +source + COPY --dir +test-binaries/build build + FROM +preset-release-assert-test + COPY --dir ./srs_db/+build/. srs_db + # limit hardware concurrency, if provided + IF [ "$HARDWARE_CONCURRENCY" != "" ] + ENV HARDWARE_CONCURRENCY=$hardware_concurrency + END + RUN cd build && GTEST_COLOR=1 AVM_ENABLE_FULL_PROVING=1 ctest -j4 --test-dir src/barretenberg/vm --output-on-failure + build: BUILD +preset-wasm BUILD +preset-wasm-threads diff --git a/barretenberg/cpp/pil/avm/avm_alu.pil b/barretenberg/cpp/pil/avm/alu.pil similarity index 93% rename from barretenberg/cpp/pil/avm/avm_alu.pil rename to barretenberg/cpp/pil/avm/alu.pil index 4adb3e1b931..cae0003f39f 100644 --- a/barretenberg/cpp/pil/avm/avm_alu.pil +++ b/barretenberg/cpp/pil/avm/alu.pil @@ -1,6 +1,4 @@ -include "avm_main.pil"; - -namespace avm_alu(256); +namespace alu(256); // ========= Table ALU-TR ================================================= @@ -19,14 +17,14 @@ namespace avm_alu(256); pol commit op_eq; pol commit op_cast; pol commit op_cast_prev; // Predicate on whether op_cast is enabled at previous row - pol commit alu_sel; // Predicate to activate the copy of intermediate registers to ALU table. + pol commit sel_alu; // Predicate to activate the copy of intermediate registers to ALU table. pol commit op_lt; pol commit op_lte; - pol commit cmp_sel; // Predicate if LT or LTE is set - pol commit rng_chk_sel; // Predicate representing a range check row. + pol commit sel_cmp; // Predicate if LT or LTE is set + pol commit sel_rng_chk; // Predicate representing a range check row. pol commit op_shl; pol commit op_shr; - pol commit shift_sel; // Predicate if SHR or SHR is set + pol commit sel_shift_which; // Predicate if SHR or SHR is set // Instruction tag (1: u8, 2: u16, 3: u32, 4: u64, 5: u128, 6: field) copied from Main table pol commit in_tag; @@ -64,9 +62,9 @@ namespace avm_alu(256); pol commit cf; // Compute predicate telling whether there is a row entry in the ALU table. - alu_sel = op_add + op_sub + op_mul + op_not + op_eq + op_cast + op_lt + op_lte + op_shr + op_shl + op_div; - cmp_sel = op_lt + op_lte; - shift_sel = op_shl + op_shr; + sel_alu = op_add + op_sub + op_mul + op_not + op_eq + op_cast + op_lt + op_lte + op_shr + op_shl + op_div; + sel_cmp = op_lt + op_lte; + sel_shift_which = op_shl + op_shr; // ========= Type Constraints ============================================= // TODO: Range constraints @@ -86,7 +84,7 @@ namespace avm_alu(256); u128_tag * (1 - u128_tag) = 0; // Mutual exclusion of the flattened instruction tag. - alu_sel * (ff_tag + u8_tag + u16_tag + u32_tag + u64_tag + u128_tag - 1) = 0; + sel_alu * (ff_tag + u8_tag + u16_tag + u32_tag + u64_tag + u128_tag - 1) = 0; // Correct flattening of the instruction tag. in_tag = u8_tag + 2 * u16_tag + 3 * u32_tag + 4 * u64_tag + 5 * u128_tag + 6 * ff_tag; @@ -227,9 +225,9 @@ namespace avm_alu(256); // TODO decide if it is done here or in another trace // Do not allow ff_tag to be set if we are doing bitwise - pol BITWISE_SEL = op_not; // Add more bitwise operations + pol SEL_BITWISE = op_not; // Add more bitwise operations #[ALU_FF_NOT_XOR] - BITWISE_SEL * ff_tag = 0; + SEL_BITWISE * ff_tag = 0; // The value 2^k - 1 pol UINT_MAX = u8_tag * 2**8 + @@ -246,7 +244,7 @@ namespace avm_alu(256); // ========= EQUALITY Operation Constraints =============================== // TODO: Note this method differs from the approach taken for "equality to zero" checks - // in handling the error tags found in avm_main and avm_mem files. The predicted relation difference + // in handling the error tags found in main and mem files. The predicted relation difference // is minor and when we optimise we will harmonise the methods based on actual performance. // Equality of two elements is found by performing an "equality to zero" check. @@ -264,9 +262,9 @@ namespace avm_alu(256); // Need an additional helper that holds the inverse of the difference; pol commit op_eq_diff_inv; - // If EQ or CMP_SEL selector is set, ic needs to be boolean + // If EQ or sel_cmp selector is set, ic needs to be boolean #[ALU_RES_IS_BOOL] - (cmp_sel + op_eq) * (ic * (1 - ic)) = 0; + (sel_cmp + op_eq) * (ic * (1 - ic)) = 0; #[ALU_OP_EQ] op_eq * (DIFF * (ic * (1 - op_eq_diff_inv) + op_eq_diff_inv) - 1 + ic) = 0; @@ -296,13 +294,13 @@ namespace avm_alu(256); pol commit a_hi; // Check INPUT_IA is well formed from its lo and hi limbs #[INPUT_DECOMP_1] - INPUT_IA = (a_lo + 2 ** 128 * a_hi) * (cmp_sel + op_cast); + INPUT_IA = (a_lo + 2 ** 128 * a_hi) * (sel_cmp + op_cast); pol commit b_lo; pol commit b_hi; // Check INPUT_IB is well formed from its lo and hi limbs #[INPUT_DECOMP_2] - INPUT_IB = (b_lo + 2 ** 128 * b_hi) * cmp_sel; + INPUT_IB = (b_lo + 2 ** 128 * b_hi) * sel_cmp; pol commit p_sub_a_lo; // p_lo - a_lo pol commit p_sub_a_hi; // p_hi - a_hi @@ -317,9 +315,9 @@ namespace avm_alu(256); // First condition is if borrow = 0, second condition is if borrow = 1 // This underflow check is done by the 128-bit check that is performed on each of these lo and hi limbs. #[SUB_LO_1] - (p_sub_a_lo - (53438638232309528389504892708671455232 - a_lo + p_a_borrow * 2 ** 128)) * (cmp_sel + op_cast + op_div_std) = 0; + (p_sub_a_lo - (53438638232309528389504892708671455232 - a_lo + p_a_borrow * 2 ** 128)) * (sel_cmp + op_cast + op_div_std) = 0; #[SUB_HI_1] - (p_sub_a_hi - (64323764613183177041862057485226039389 - a_hi - p_a_borrow)) * (cmp_sel + op_cast + op_div_std) = 0; + (p_sub_a_hi - (64323764613183177041862057485226039389 - a_hi - p_a_borrow)) * (sel_cmp + op_cast + op_div_std) = 0; pol commit p_sub_b_lo; pol commit p_sub_b_hi; @@ -330,9 +328,9 @@ namespace avm_alu(256); // This is achieved by checking (p_lo > b_lo && p_hi >= bhi) || (p_lo <= b_lo && p_hi > b_hi) // First condition is if borrow = 0, second condition is if borrow = 1; #[SUB_LO_2] - (p_sub_b_lo - (53438638232309528389504892708671455232 - b_lo + p_b_borrow * 2 ** 128)) * cmp_sel = 0; + (p_sub_b_lo - (53438638232309528389504892708671455232 - b_lo + p_b_borrow * 2 ** 128)) * sel_cmp = 0; #[SUB_HI_2] - (p_sub_b_hi - (64323764613183177041862057485226039389 - b_hi - p_b_borrow)) * cmp_sel = 0; + (p_sub_b_hi - (64323764613183177041862057485226039389 - b_hi - p_b_borrow)) * sel_cmp = 0; // Calculate the combined relation: (a - b - 1) * q + (b -a ) * (1-q) // Check that (a > b) by checking (a_lo > b_lo && a_hi >= bhi) || (alo <= b_lo && a_hi > b_hi) @@ -410,9 +408,9 @@ namespace avm_alu(256); pol commit res_lo; pol commit res_hi; #[RES_LO] - (res_lo - (A_SUB_B_LO * IS_GT + B_SUB_A_LO * (1 - IS_GT))) * cmp_sel = 0; + (res_lo - (A_SUB_B_LO * IS_GT + B_SUB_A_LO * (1 - IS_GT))) * sel_cmp = 0; #[RES_HI] - (res_hi - (A_SUB_B_HI * IS_GT + B_SUB_A_HI * (1 - IS_GT))) * cmp_sel = 0; + (res_hi - (A_SUB_B_HI * IS_GT + B_SUB_A_HI * (1 - IS_GT))) * sel_cmp = 0; // ========= RANGE OPERATIONS =============================== @@ -426,25 +424,25 @@ namespace avm_alu(256); // if this row is a comparison operation, the next range_check_remaining value is set to 4 // it is not set to 5 since we do 1 as part of the comparison. #[CMP_CTR_REL_2] - (cmp_rng_ctr' - 4) * cmp_sel = 0; + (cmp_rng_ctr' - 4) * sel_cmp = 0; - rng_chk_sel * (1 - rng_chk_sel) = 0; - // If we have remaining range checks, we cannot have cmp_sel set. This prevents malicious truncating of the range + sel_rng_chk * (1 - sel_rng_chk) = 0; + // If we have remaining range checks, we cannot have sel_cmp set. This prevents malicious truncating of the range // checks by adding a new LT/LTE operation before all the range checks from the previous computation are complete. - rng_chk_sel * cmp_sel = 0; + sel_rng_chk * sel_cmp = 0; - // rng_chk_sel = 1 when cmp_rng_ctr != 0 and rng_chk_sel = 0 when cmp_rng_ctr = 0; + // sel_rng_chk = 1 when cmp_rng_ctr != 0 and sel_rng_chk = 0 when cmp_rng_ctr = 0; #[CTR_NON_ZERO_REL] - cmp_rng_ctr * ((1 - rng_chk_sel) * (1 - op_eq_diff_inv) + op_eq_diff_inv) - rng_chk_sel = 0; + cmp_rng_ctr * ((1 - sel_rng_chk) * (1 - op_eq_diff_inv) + op_eq_diff_inv) - sel_rng_chk = 0; // We perform a range check if we have some range checks remaining or we are performing a comparison op - pol RNG_CHK_OP = rng_chk_sel + cmp_sel + op_cast + op_cast_prev + shift_lt_bit_len + op_div; + pol RNG_CHK_OP = sel_rng_chk + sel_cmp + op_cast + op_cast_prev + shift_lt_bit_len + op_div; - pol commit rng_chk_lookup_selector; + pol commit sel_rng_chk_lookup; // TODO: Possible optimisation here if we swap the op_shl and op_shr with shift_lt_bit_len. // Shift_lt_bit_len is a more restrictive form therefore we can avoid performing redundant range checks when we know the result == 0. #[RNG_CHK_LOOKUP_SELECTOR] - rng_chk_lookup_selector' = cmp_sel' + rng_chk_sel' + op_add' + op_sub' + op_mul' + op_mul * u128_tag + op_cast' + op_cast_prev' + op_shl' + op_shr' + op_div'; + sel_rng_chk_lookup' = sel_cmp' + sel_rng_chk' + op_add' + op_sub' + op_mul' + op_mul * u128_tag + op_cast' + op_cast_prev' + op_shl' + op_shr' + op_div'; // Perform 128-bit range check on lo part #[LOWER_CMP_RNG_CHK] @@ -463,17 +461,17 @@ namespace avm_alu(256); // Briefly: given a > b and p > a and p > a - b - 1, it is sufficient confirm that p > b without a range check // To accomplish this we would likely change the order of the range_check so we can skip p_sub_b #[SHIFT_RELS_0] - (a_lo' - b_lo) * rng_chk_sel' = 0; - (a_hi' - b_hi) * rng_chk_sel' = 0; + (a_lo' - b_lo) * sel_rng_chk' = 0; + (a_hi' - b_hi) * sel_rng_chk' = 0; #[SHIFT_RELS_1] - (b_lo' - p_sub_a_lo) * rng_chk_sel' = 0; - (b_hi' - p_sub_a_hi) * rng_chk_sel' = 0; + (b_lo' - p_sub_a_lo) * sel_rng_chk' = 0; + (b_hi' - p_sub_a_hi) * sel_rng_chk' = 0; #[SHIFT_RELS_2] - (p_sub_a_lo' - p_sub_b_lo) * rng_chk_sel'= 0; - (p_sub_a_hi' - p_sub_b_hi) * rng_chk_sel'= 0; + (p_sub_a_lo' - p_sub_b_lo) * sel_rng_chk'= 0; + (p_sub_a_hi' - p_sub_b_hi) * sel_rng_chk'= 0; #[SHIFT_RELS_3] - (p_sub_b_lo' - res_lo) * rng_chk_sel'= 0; - (p_sub_b_hi' - res_hi) * rng_chk_sel'= 0; + (p_sub_b_lo' - res_lo) * sel_rng_chk'= 0; + (p_sub_b_hi' - res_hi) * sel_rng_chk'= 0; // ========= CAST Operation Constraints =============================== // We handle the input ia independently of its tag, i.e., we suppose it can take @@ -514,7 +512,7 @@ namespace avm_alu(256); // 128-bit multiplication and CAST need two rows in ALU trace. We need to ensure // that another ALU operation does not start in the second row. #[TWO_LINE_OP_NO_OVERLAP] - (op_mul * u128_tag + op_cast) * alu_sel' = 0; + (op_mul * u128_tag + op_cast) * sel_alu' = 0; // ========= SHIFT LEFT/RIGHT OPERATIONS =============================== // Given (1) an input b, within the range [0, 2**128-1], @@ -600,7 +598,7 @@ namespace avm_alu(256); // There is no chance of an underflow involving ib to result in a t_sub_b_bits < 2**8 ib is range checked to be < 2**8 // The range checking of t_sub_b_bits in the range [0, 2**8) is done by the lookup for 2**t_sub_s_bits #[SHIFT_LT_BIT_LEN] - t_sub_s_bits = shift_sel * (shift_lt_bit_len * (MAX_BITS - ib) + (1 - shift_lt_bit_len) * (ib - MAX_BITS)); + t_sub_s_bits = sel_shift_which * (shift_lt_bit_len * (MAX_BITS - ib) + (1 - shift_lt_bit_len) * (ib - MAX_BITS)); // ========= SHIFT RIGHT OPERATIONS =============================== // a_hi * 2**s + a_lo = a @@ -699,7 +697,7 @@ namespace avm_alu(256); (cmp_rng_ctr' - 2) * op_div_std = 0; // If we have more range checks left we cannot do more divisions operations that might truncate the steps - rng_chk_sel * op_div_std = 0; + sel_rng_chk * op_div_std = 0; // Check PRODUCT = ia - remainder #[DIVISION_RELATION] @@ -710,10 +708,10 @@ namespace avm_alu(256); // TODO: We need extra slice registers because we are performing an additional 64-bit range check in the same row, look into re-using old columns or refactoring // range checks to be more modular. // boolean to account for the division-specific 64-bit range checks. - pol commit div_rng_chk_selector; - div_rng_chk_selector * (1 - div_rng_chk_selector) = 0; - // div_rng_chk_selector && div_rng_chk_selector' = 1 if op_div_std = 1 - div_rng_chk_selector * div_rng_chk_selector' = op_div_std; + pol commit sel_div_rng_chk; + sel_div_rng_chk * (1 - sel_div_rng_chk) = 0; + // sel_div_rng_chk && sel_div_rng_chk' = 1 if op_div_std = 1 + sel_div_rng_chk * sel_div_rng_chk' = op_div_std; pol commit div_u16_r0; pol commit div_u16_r1; diff --git a/barretenberg/cpp/pil/avm/avm_binary.pil b/barretenberg/cpp/pil/avm/binary.pil similarity index 70% rename from barretenberg/cpp/pil/avm/avm_binary.pil rename to barretenberg/cpp/pil/avm/binary.pil index 5385efc982d..441f4c56bd1 100644 --- a/barretenberg/cpp/pil/avm/avm_binary.pil +++ b/barretenberg/cpp/pil/avm/binary.pil @@ -1,14 +1,14 @@ -include "avm_byte_lookup.pil"; -include "avm_main.pil"; +include "byte_lookup.pil"; +include "main.pil"; -namespace avm_binary(256); +namespace binary(256); pol commit clk; // Selector for Binary Operation - pol commit bin_sel; - bin_sel * (1 - bin_sel) = 0; + pol commit sel_bin; + sel_bin * (1 - sel_bin) = 0; // Byte recomposition column, the value in these columns are part of the equivalence // check to main wherever Start is set to 1. @@ -30,7 +30,7 @@ namespace avm_binary(256); (op_id' - op_id) * mem_tag_ctr = 0; // Little Endian bitwise decomposition of accumulators (which are processed top-down), - // constrained to be U8 given by the lookup to the avm_byte_lookup + // constrained to be U8 given by the lookup to the byte_lookup pol commit ia_bytes; pol commit ib_bytes; pol commit ic_bytes; @@ -46,31 +46,31 @@ namespace avm_binary(256); #[MEM_TAG_REL] (mem_tag_ctr' - mem_tag_ctr + 1) * mem_tag_ctr = 0; - // Bin_sel is a boolean that is set to 1 if mem_tag_ctr != 0. + // sel_bin is a boolean that is set to 1 if mem_tag_ctr != 0. // This is checked by two relation conditions and utilising mem_tag_ctr_inv pol commit mem_tag_ctr_inv; - // bin_sel is set to 1 when mem_tag_ctr != 0, and 0 otherwise. - // we constrain it such that bin_sel = mem_tag_ctr * mem_tag_ctr_inv unless mem_tag_ctr = 0 the bin_sel = 0 + // sel_bin is set to 1 when mem_tag_ctr != 0, and 0 otherwise. + // we constrain it such that sel_bin = mem_tag_ctr * mem_tag_ctr_inv unless mem_tag_ctr = 0 the sel_bin = 0 // In here we use the consolidated equality relation because it doesnt require us to enforce // this additional relation: mem_tag_ctr_inv = 1 when mem_tag_ctr = 0. (allows default zero value in trace) - #[BIN_SEL_CTR_REL] - mem_tag_ctr * ((1 - bin_sel) * (1 - mem_tag_ctr_inv) + mem_tag_ctr_inv) - bin_sel = 0; + #[SEL_BIN_CTR_REL] + mem_tag_ctr * ((1 - sel_bin) * (1 - mem_tag_ctr_inv) + mem_tag_ctr_inv) - sel_bin = 0; // Forces accumulator to start at zero when mem_tag_ctr == 0 - (1 - bin_sel) * acc_ia = 0; - (1 - bin_sel) * acc_ib = 0; - (1 - bin_sel) * acc_ic = 0; + (1 - sel_bin) * acc_ia = 0; + (1 - sel_bin) * acc_ib = 0; + (1 - sel_bin) * acc_ic = 0; #[LOOKUP_BYTE_LENGTHS] start {in_tag, mem_tag_ctr} in - avm_byte_lookup.bin_sel {avm_byte_lookup.table_in_tags, avm_byte_lookup.table_byte_lengths}; + byte_lookup.sel_bin {byte_lookup.table_in_tags, byte_lookup.table_byte_lengths}; #[LOOKUP_BYTE_OPERATIONS] - bin_sel {op_id, ia_bytes, ib_bytes, ic_bytes} + sel_bin {op_id, ia_bytes, ib_bytes, ic_bytes} in - avm_byte_lookup.bin_sel {avm_byte_lookup.table_op_id, avm_byte_lookup.table_input_a, avm_byte_lookup.table_input_b, avm_byte_lookup.table_output}; + byte_lookup.sel_bin {byte_lookup.table_op_id, byte_lookup.table_input_a, byte_lookup.table_input_b, byte_lookup.table_output}; #[ACC_REL_A] (acc_ia - ia_bytes - 256 * acc_ia') * mem_tag_ctr = 0; diff --git a/barretenberg/cpp/pil/avm/avm_byte_lookup.pil b/barretenberg/cpp/pil/avm/byte_lookup.pil similarity index 93% rename from barretenberg/cpp/pil/avm/avm_byte_lookup.pil rename to barretenberg/cpp/pil/avm/byte_lookup.pil index d06135389fd..a91272a86e6 100644 --- a/barretenberg/cpp/pil/avm/avm_byte_lookup.pil +++ b/barretenberg/cpp/pil/avm/byte_lookup.pil @@ -1,5 +1,5 @@ -namespace avm_byte_lookup(256); +namespace byte_lookup(256); // These columns are commited for now, but will be migrated to constant/fixed when // we support more *exotic* code generation options pol commit table_op_id; // identifies if operation is AND/OR/XOR @@ -8,7 +8,7 @@ namespace avm_byte_lookup(256); pol commit table_output; // output = a AND/OR/XOR b // Selector to indicate when to utilise the lookup table // TODO: Support for 1-sided lookups may make this redundant. - pol commit bin_sel; + pol commit sel_bin; // These two columns are a mapping between instruction tags and their byte lengths // {U8: 1, U16: 2, ... , U128: 16} diff --git a/barretenberg/cpp/pil/avm/constants.pil b/barretenberg/cpp/pil/avm/constants.pil index 35e385bfb45..6de0cfb9e77 100644 --- a/barretenberg/cpp/pil/avm/constants.pil +++ b/barretenberg/cpp/pil/avm/constants.pil @@ -36,7 +36,7 @@ namespace constants(256); pol MAX_NULLIFIER_READ_REQUESTS_PER_CALL = 32; pol MAX_NOTE_HASH_READ_REQUESTS_PER_CALL = 32; pol MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL = 32; - pol MAX_PUBLIC_DATA_READS_PER_CALL = 16; + pol MAX_PUBLIC_DATA_READS_PER_CALL = 32; // Emitting Data pol MAX_NEW_NOTE_HASHES_PER_CALL = 16; diff --git a/barretenberg/cpp/pil/avm/gadgets/avm_conversion.pil b/barretenberg/cpp/pil/avm/gadgets/conversion.pil similarity index 82% rename from barretenberg/cpp/pil/avm/gadgets/avm_conversion.pil rename to barretenberg/cpp/pil/avm/gadgets/conversion.pil index abd2e5c6121..115a0571075 100644 --- a/barretenberg/cpp/pil/avm/gadgets/avm_conversion.pil +++ b/barretenberg/cpp/pil/avm/gadgets/conversion.pil @@ -1,12 +1,10 @@ -include "../avm_main.pil"; - -namespace avm_conversion(256); +namespace conversion(256); pol commit clk; // Selector for Radix Operation - pol commit to_radix_le_sel; - to_radix_le_sel * (1 - to_radix_le_sel) = 0; + pol commit sel_to_radix_le; + sel_to_radix_le * (1 - sel_to_radix_le) = 0; // ===== DRAFT: Planned Constraints for To Radix LE // Similar to the binary trace; multi-row decomposition of the input using the number of limbs specified as the row count. diff --git a/barretenberg/cpp/pil/avm/gadgets/avm_keccakf1600.pil b/barretenberg/cpp/pil/avm/gadgets/keccakf1600.pil similarity index 61% rename from barretenberg/cpp/pil/avm/gadgets/avm_keccakf1600.pil rename to barretenberg/cpp/pil/avm/gadgets/keccakf1600.pil index acc9a54f277..72dd78005d7 100644 --- a/barretenberg/cpp/pil/avm/gadgets/avm_keccakf1600.pil +++ b/barretenberg/cpp/pil/avm/gadgets/keccakf1600.pil @@ -1,12 +1,10 @@ -include "../avm_main.pil"; - -namespace avm_keccakf1600(256); +namespace keccakf1600(256); pol commit clk; // Selector for Keccak Permutation Operation - pol commit keccakf1600_sel; - keccakf1600_sel * (1 - keccakf1600_sel) = 0; + pol commit sel_keccakf1600; + sel_keccakf1600 * (1 - sel_keccakf1600) = 0; // These will all be arrays, but we just store the first element for permutation to the main trace for now pol commit input; diff --git a/barretenberg/cpp/pil/avm/gadgets/avm_pedersen.pil b/barretenberg/cpp/pil/avm/gadgets/pedersen.pil similarity index 63% rename from barretenberg/cpp/pil/avm/gadgets/avm_pedersen.pil rename to barretenberg/cpp/pil/avm/gadgets/pedersen.pil index 335b6ea3f2c..cf881233ca4 100644 --- a/barretenberg/cpp/pil/avm/gadgets/avm_pedersen.pil +++ b/barretenberg/cpp/pil/avm/gadgets/pedersen.pil @@ -1,13 +1,10 @@ - -include "../avm_main.pil"; - -namespace avm_pedersen(256); +namespace pedersen(256); pol commit clk; // Selector for Pedersen Hash Operation - pol commit pedersen_sel; - pedersen_sel * (1 - pedersen_sel) = 0; + pol commit sel_pedersen; + sel_pedersen * (1 - sel_pedersen) = 0; // These will all be arrays, but we just store the first element for permutation to the main trace for now pol commit input; diff --git a/barretenberg/cpp/pil/avm/gadgets/avm_poseidon2.pil b/barretenberg/cpp/pil/avm/gadgets/poseidon2.pil similarity index 59% rename from barretenberg/cpp/pil/avm/gadgets/avm_poseidon2.pil rename to barretenberg/cpp/pil/avm/gadgets/poseidon2.pil index fd5a1d7c67c..b89685bc018 100644 --- a/barretenberg/cpp/pil/avm/gadgets/avm_poseidon2.pil +++ b/barretenberg/cpp/pil/avm/gadgets/poseidon2.pil @@ -1,12 +1,10 @@ -include "../avm_main.pil"; - -namespace avm_poseidon2(256); +namespace poseidon2(256); pol commit clk; // Selector for Radix Operation - pol commit poseidon_perm_sel; - poseidon_perm_sel * (1 - poseidon_perm_sel) = 0; + pol commit sel_poseidon_perm; + sel_poseidon_perm * (1 - sel_poseidon_perm) = 0; // These will all be arrays, but we just store the first element for permutation to the main trace for now pol commit input; diff --git a/barretenberg/cpp/pil/avm/gadgets/avm_sha256.pil b/barretenberg/cpp/pil/avm/gadgets/sha256.pil similarity index 60% rename from barretenberg/cpp/pil/avm/gadgets/avm_sha256.pil rename to barretenberg/cpp/pil/avm/gadgets/sha256.pil index f7ca8b8337a..2de296cbb24 100644 --- a/barretenberg/cpp/pil/avm/gadgets/avm_sha256.pil +++ b/barretenberg/cpp/pil/avm/gadgets/sha256.pil @@ -1,12 +1,10 @@ -include "../avm_main.pil"; - -namespace avm_sha256(256); +namespace sha256(256); pol commit clk; // Selector for Radix Operation - pol commit sha256_compression_sel; - sha256_compression_sel * (1 - sha256_compression_sel) = 0; + pol commit sel_sha256_compression; + sel_sha256_compression * (1 - sel_sha256_compression) = 0; // These will all be arrays, but we just store the first element for permutation to the main trace for now pol commit state; diff --git a/barretenberg/cpp/pil/avm/avm_gas.pil b/barretenberg/cpp/pil/avm/gas.pil similarity index 87% rename from barretenberg/cpp/pil/avm/avm_gas.pil rename to barretenberg/cpp/pil/avm/gas.pil index 0ee48d43ece..0a1ed20bdb2 100644 --- a/barretenberg/cpp/pil/avm/avm_gas.pil +++ b/barretenberg/cpp/pil/avm/gas.pil @@ -1,8 +1,7 @@ - -namespace avm_gas(256); +namespace gas(256); // TODO: WILL BE FIXED - we should be able to have this be a fixed column / the lookup tables are fixed so require no selectors // TODO: All the columns here will have to be constant (when supported by our powdr fork and proving system) - pol commit gas_cost_sel; + pol commit sel_gas_cost; // TODO(ISSUE_NUMBER): Constrain variable gas costs pol commit l2_gas_fixed_table; diff --git a/barretenberg/cpp/pil/avm/avm_kernel.pil b/barretenberg/cpp/pil/avm/kernel.pil similarity index 71% rename from barretenberg/cpp/pil/avm/avm_kernel.pil rename to barretenberg/cpp/pil/avm/kernel.pil index 1e09a36a3c3..f7d402826eb 100644 --- a/barretenberg/cpp/pil/avm/avm_kernel.pil +++ b/barretenberg/cpp/pil/avm/kernel.pil @@ -1,7 +1,7 @@ -include "avm_main.pil"; +include "main.pil"; include "constants.pil"; -namespace avm_kernel(256); +namespace kernel(256); pol public(/*idx=*/0) kernel_inputs; pol public(/*idx=*/1) kernel_value_out; @@ -32,14 +32,14 @@ namespace avm_kernel(256); pol START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET = 96; // START_NULLIFIER_EXISTS_OFFET + (MAX_NULLIFIER_READ_REQUESTS_PER_CALL + MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL) // Public storage requests - pol START_SSTORE_WRITE_OFFSET = 128; // START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL - pol START_SLOAD_WRITE_OFFSET = 144; // START_SSTORE_WRITE_OFFSET + MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL + pol START_SSTORE_WRITE_OFFSET = 112; // START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL + pol START_SLOAD_WRITE_OFFSET = 144; // START_SSTORE_WRITE_OFFSET + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL // Emit data - pol START_EMIT_NOTE_HASH_WRITE_OFFSET = 160; // START_SLOAD_WRITE_OFFSET + MAX_PUBLIC_DATA_READS_PER_CALL - pol START_EMIT_NULLIFIER_WRITE_OFFSET = 176; // START_EMIT_NOTE_HASH_WRITE_OFFSET + MAX_NEW_NOTE_HASHES_PER_CALL - pol START_EMIT_L2_TO_l1_MSG = 192; // START_EMIT_NULLIFIER_WRITE_OFFSET + MAX_NEW_NULLIFIERS_PER_CALL - pol START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET = 194; // START_EMIT_L2_TO_L1_MSG + MAX_NEW_L2_TO_L1_MSGS_PER_CALL + pol START_EMIT_NOTE_HASH_WRITE_OFFSET = 176; // START_SLOAD_WRITE_OFFSET + MAX_PUBLIC_DATA_READS_PER_CALL + pol START_EMIT_NULLIFIER_WRITE_OFFSET = 192; // START_EMIT_NOTE_HASH_WRITE_OFFSET + MAX_NEW_NOTE_HASHES_PER_CALL + pol START_EMIT_L2_TO_l1_MSG = 208; // START_EMIT_NULLIFIER_WRITE_OFFSET + MAX_NEW_NULLIFIERS_PER_CALL + pol START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET = 210; // START_EMIT_L2_TO_L1_MSG + MAX_NEW_L2_TO_L1_MSGS_PER_CALL // TODO(https://github.com/AztecProtocol/aztec-packages/issues/6465): Must constrain write_offset counters to be less than side effect MAX @@ -58,29 +58,29 @@ namespace avm_kernel(256); pol commit emit_l2_to_l1_msg_write_offset; - pol NOT_LAST = (1 - avm_main.last); + pol NOT_LAST = (1 - main.sel_last); // Constraints to increase the offsets when the opcodes are found #[NOTE_HASH_EXISTS_INC_CONSISTENCY_CHECK] - NOT_LAST * (note_hash_exist_write_offset' - (note_hash_exist_write_offset + avm_main.sel_op_note_hash_exists)) = 0; + NOT_LAST * (note_hash_exist_write_offset' - (note_hash_exist_write_offset + main.sel_op_note_hash_exists)) = 0; #[EMIT_NOTE_HASH_INC_CONSISTENCY_CHECK] - NOT_LAST * (emit_note_hash_write_offset' - (emit_note_hash_write_offset + avm_main.sel_op_emit_note_hash)) = 0; - // if avm_main.ib is set on op_nullifier_exists, then the nullifier_exists_write_offset will be incremented by 1, otherwise non_exists will be incremented + NOT_LAST * (emit_note_hash_write_offset' - (emit_note_hash_write_offset + main.sel_op_emit_note_hash)) = 0; + // if main.ib is set on op_nullifier_exists, then the nullifier_exists_write_offset will be incremented by 1, otherwise non_exists will be incremented #[NULLIFIER_EXISTS_INC_CONSISTENCY_CHECK] - NOT_LAST * (nullifier_exists_write_offset' - (nullifier_exists_write_offset + (avm_main.sel_op_nullifier_exists * avm_main.ib))) = 0; + NOT_LAST * (nullifier_exists_write_offset' - (nullifier_exists_write_offset + (main.sel_op_nullifier_exists * main.ib))) = 0; #[NULLIFIER_NON_EXISTS_INC_CONSISTENCY_CHECK] - NOT_LAST * (nullifier_non_exists_write_offset' - (nullifier_non_exists_write_offset + (avm_main.sel_op_nullifier_exists * (1 - avm_main.ib)))) = 0; + NOT_LAST * (nullifier_non_exists_write_offset' - (nullifier_non_exists_write_offset + (main.sel_op_nullifier_exists * (1 - main.ib)))) = 0; #[EMIT_NULLIFIER_INC_CONSISTENCY_CHECK] - NOT_LAST * (emit_nullifier_write_offset' - (emit_nullifier_write_offset + avm_main.sel_op_emit_nullifier)) = 0; + NOT_LAST * (emit_nullifier_write_offset' - (emit_nullifier_write_offset + main.sel_op_emit_nullifier)) = 0; #[L1_TO_L2_MSG_EXISTS_INC_CONSISTENCY_CHECK] - NOT_LAST * (l1_to_l2_msg_exists_write_offset' - (l1_to_l2_msg_exists_write_offset + avm_main.sel_op_l1_to_l2_msg_exists)) = 0; + NOT_LAST * (l1_to_l2_msg_exists_write_offset' - (l1_to_l2_msg_exists_write_offset + main.sel_op_l1_to_l2_msg_exists)) = 0; #[EMIT_UNENCRYPTED_LOG_INC_CONSISTENCY_CHECK] - NOT_LAST * (emit_unencrypted_log_write_offset' - (emit_unencrypted_log_write_offset + avm_main.sel_op_emit_unencrypted_log)) = 0; + NOT_LAST * (emit_unencrypted_log_write_offset' - (emit_unencrypted_log_write_offset + main.sel_op_emit_unencrypted_log)) = 0; #[EMIT_L2_TO_L1_MSG_INC_CONSISTENCY_CHECK] - NOT_LAST * (emit_l2_to_l1_msg_write_offset' - (emit_l2_to_l1_msg_write_offset + avm_main.sel_op_emit_l2_to_l1_msg)) = 0; + NOT_LAST * (emit_l2_to_l1_msg_write_offset' - (emit_l2_to_l1_msg_write_offset + main.sel_op_emit_l2_to_l1_msg)) = 0; #[SLOAD_INC_CONSISTENCY_CHECK] - NOT_LAST * (sload_write_offset' - (sload_write_offset + avm_main.sel_op_sload)) = 0; + NOT_LAST * (sload_write_offset' - (sload_write_offset + main.sel_op_sload)) = 0; #[SSTORE_INC_CONSISTENCY_CHECK] - NOT_LAST * (sstore_write_offset' - (sstore_write_offset + avm_main.sel_op_sstore)) = 0; + NOT_LAST * (sstore_write_offset' - (sstore_write_offset + main.sel_op_sstore)) = 0; diff --git a/barretenberg/cpp/pil/avm/avm_main.pil b/barretenberg/cpp/pil/avm/main.pil similarity index 57% rename from barretenberg/cpp/pil/avm/avm_main.pil rename to barretenberg/cpp/pil/avm/main.pil index 1952c1627e4..36b2b6e2b97 100644 --- a/barretenberg/cpp/pil/avm/avm_main.pil +++ b/barretenberg/cpp/pil/avm/main.pil @@ -1,25 +1,24 @@ - -include "avm_mem.pil"; -include "avm_alu.pil"; -include "avm_binary.pil"; +include "mem.pil"; +include "alu.pil"; +include "binary.pil"; include "constants.pil"; -include "avm_kernel.pil"; -include "avm_gas.pil"; -include "gadgets/avm_conversion.pil"; -include "gadgets/avm_sha256.pil"; -include "gadgets/avm_poseidon2.pil"; -include "gadgets/avm_keccakf1600.pil"; -include "gadgets/avm_pedersen.pil"; - -namespace avm_main(256); +include "kernel.pil"; +include "gas.pil"; +include "gadgets/conversion.pil"; +include "gadgets/sha256.pil"; +include "gadgets/poseidon2.pil"; +include "gadgets/keccakf1600.pil"; +include "gadgets/pedersen.pil"; + +namespace main(256); //===== CONSTANT POLYNOMIALS ================================================== pol constant clk(i) { i }; - pol constant first = [1] + [0]*; // Used mostly to toggle off the first row consisting - // only in first element of shifted polynomials. + pol constant sel_first = [1] + [0]*; // Used mostly to toggle off the first row consisting + // only in first element of shifted polynomials. //===== KERNEL INPUTS ========================================================= // Kernel lookup selector opcodes - pol commit q_kernel_lookup; + pol commit sel_q_kernel_lookup; // CALL CONTEXT pol commit sel_op_sender; @@ -43,7 +42,7 @@ namespace avm_main(256); pol commit sel_op_dagasleft; //===== KERNEL OUTPUTS ======================================================== - pol commit q_kernel_output_lookup; + pol commit sel_q_kernel_output_lookup; pol commit sel_op_note_hash_exists; pol commit sel_op_emit_note_hash; @@ -57,23 +56,24 @@ namespace avm_main(256); pol commit sel_op_sload; pol commit sel_op_sstore; + // TODO: Opcode value (byte) will be constrained by the bytecode validation circuit + pol commit opcode_val; + //===== GAS ACCOUNTING ======================================================== - // 1. The gas lookup table (in avm_gas.pil) is constant and maps the opcode value to L2/DA gas (fixed) cost. + // 1. The gas lookup table (in gas.pil) is constant and maps the opcode value to L2/DA gas (fixed) cost. // 2. Read gas_op from gas table based on the opcode value // 3. TODO(#6588): constrain gas start and gas end - // TODO: Opcode value (byte) will be constrained by the bytecode validation circuit - pol commit opcode_val; - // "gas_remaining" values correspond to the gas quantity which remains BEFORE the execution of the opcode // of the pertaining line. This means that the last value will be written on the row following the last // opcode execution. pol commit l2_gas_remaining; pol commit da_gas_remaining; + // These are the gas costs of the opcode execution. // TODO: allow lookups to evaluate expressions - pol commit l2_gas_op; - pol commit da_gas_op; + pol commit l2_gas_op_cost; + pol commit da_gas_op_cost; // Boolean indicating whether the current opcode gas consumption is higher than remaining gas pol commit l2_out_of_gas; @@ -91,41 +91,41 @@ namespace avm_main(256); // Constrain that the gas decrements correctly per instruction #[L2_GAS_REMAINING_DECREMENT] - gas_cost_active * (l2_gas_remaining' - l2_gas_remaining + l2_gas_op) = 0; + sel_gas_accounting_active * (l2_gas_remaining' - l2_gas_remaining + l2_gas_op_cost) = 0; #[DA_GAS_REMAINING_DECREMENT] - gas_cost_active * (da_gas_remaining' - da_gas_remaining + da_gas_op) = 0; + sel_gas_accounting_active * (da_gas_remaining' - da_gas_remaining + da_gas_op_cost) = 0; // Constrain that the remaining gas is unchanged otherwise (multi-line operations) #[L2_GAS_INACTIVE] - (1 - gas_cost_active) * l2_gas_op = 0; + (1 - sel_gas_accounting_active) * l2_gas_op_cost = 0; #[DA_GAS_INACTIVE] - (1 - gas_cost_active) * da_gas_op = 0; + (1 - sel_gas_accounting_active) * da_gas_op_cost = 0; // TODO: constrain that it stays the same if an opcode selector is not active -> TODO: will this break when the opcode takes multiple rows // So we also need to constrain that it is the first line of the opcodes execution // Prove that l2_out_of_gas == 0 <==> l2_gas_remaining' >= 0 // Same for da gas - // TODO: Ensure that remaining gas values are initialized as u32 and that gas l2_gas_op/da_gas_op are u32. - gas_cost_active * ((1 - 2 * l2_out_of_gas) * l2_gas_remaining' - 2**16 * abs_l2_rem_gas_hi - abs_l2_rem_gas_lo) = 0; - gas_cost_active * ((1 - 2 * da_out_of_gas) * da_gas_remaining' - 2**16 * abs_da_rem_gas_hi - abs_da_rem_gas_lo) = 0; + // TODO: Ensure that remaining gas values are initialized as u32 and that gas l2_gas_op_cost/da_gas_op_cost are u32. + sel_gas_accounting_active * ((1 - 2 * l2_out_of_gas) * l2_gas_remaining' - 2**16 * abs_l2_rem_gas_hi - abs_l2_rem_gas_lo) = 0; + sel_gas_accounting_active * ((1 - 2 * da_out_of_gas) * da_gas_remaining' - 2**16 * abs_da_rem_gas_hi - abs_da_rem_gas_lo) = 0; #[LOOKUP_OPCODE_GAS] - gas_cost_active {opcode_val, l2_gas_op, da_gas_op} + sel_gas_accounting_active {opcode_val, l2_gas_op_cost, da_gas_op_cost} in - avm_gas.gas_cost_sel {clk, avm_gas.l2_gas_fixed_table, avm_gas.da_gas_fixed_table}; + gas.sel_gas_cost {clk, gas.l2_gas_fixed_table, gas.da_gas_fixed_table}; #[RANGE_CHECK_L2_GAS_HI] - gas_cost_active {abs_l2_rem_gas_hi} in sel_rng_16 {clk}; + sel_gas_accounting_active {abs_l2_rem_gas_hi} in sel_rng_16 {clk}; #[RANGE_CHECK_L2_GAS_LO] - gas_cost_active {abs_l2_rem_gas_lo} in sel_rng_16 {clk}; + sel_gas_accounting_active {abs_l2_rem_gas_lo} in sel_rng_16 {clk}; #[RANGE_CHECK_DA_GAS_HI] - gas_cost_active {abs_da_rem_gas_hi} in sel_rng_16 {clk}; + sel_gas_accounting_active {abs_da_rem_gas_hi} in sel_rng_16 {clk}; #[RANGE_CHECK_DA_GAS_LO] - gas_cost_active {abs_da_rem_gas_lo} in sel_rng_16 {clk}; + sel_gas_accounting_active {abs_da_rem_gas_lo} in sel_rng_16 {clk}; //===== Gadget Selectors ====================================================== pol commit sel_op_radix_le; @@ -150,62 +150,47 @@ namespace avm_main(256); // Call Pointer (nested call) pol commit call_ptr; - pol commit sel_internal_call; - pol commit sel_internal_return; - pol commit sel_jump; - pol commit sel_jumpi; - pol commit sel_external_call; + pol commit sel_op_internal_call; + pol commit sel_op_internal_return; + pol commit sel_op_jump; + pol commit sel_op_jumpi; + pol commit sel_op_external_call; // Halt program execution - pol commit sel_halt; + pol commit sel_op_halt; // Memory Space Identifier pol commit space_id; //===== MEMORY OPCODES ========================================================== - pol commit sel_mov; - pol commit sel_cmov; + pol commit sel_op_mov; + pol commit sel_op_cmov; //===== TABLE SUBOP-TR ======================================================== // Boolean selectors for (sub-)operations. Only one operation is activated at // a time. - // ADD pol commit sel_op_add; - // SUB pol commit sel_op_sub; - // MUL pol commit sel_op_mul; - // DIV pol commit sel_op_div; - // FDIV pol commit sel_op_fdiv; - // NOT pol commit sel_op_not; - // EQ pol commit sel_op_eq; - // AND pol commit sel_op_and; - // OR pol commit sel_op_or; - // XOR pol commit sel_op_xor; - // CAST pol commit sel_op_cast; - // LT pol commit sel_op_lt; - // LTE pol commit sel_op_lte; - // SHL pol commit sel_op_shl; - // SHR pol commit sel_op_shr; // Helper selector to characterize an ALU chiplet selector - pol commit alu_sel; + pol commit sel_alu; // Helper selector to characterize a Binary chiplet selector - pol commit bin_sel; + pol commit sel_bin; // Instruction memory tags read/write (1: u8, 2: u16, 3: u32, 4: u64, 5: u128, 6: field) pol commit r_in_tag; @@ -214,13 +199,18 @@ namespace avm_main(256); // Errors pol commit op_err; // Boolean flag pertaining to an operation error - pol commit tag_err; // Boolean flag (foreign key to avm_mem.tag_err) + pol commit tag_err; // Boolean flag (foreign key to mem.tag_err) // A helper witness being the inverse of some value // to show a non-zero equality pol commit inv; pol commit id_zero; // Boolean telling whether id is zero (cmov opcode) + //===== MEMORY MODEL ======================================================== + // ind_addr_a -> (gets resolved to) + // mem_addr_a -> (gets loaded to) + // ia + // Intermediate register values pol commit ia; pol commit ib; @@ -228,40 +218,45 @@ namespace avm_main(256); pol commit id; // Memory operation selector per intermediate register - pol commit mem_op_a; - pol commit mem_op_b; - pol commit mem_op_c; - pol commit mem_op_d; + // They signal that a memory operation is performed on the register. + // This does NOT take into consideration indirections. + pol commit sel_mem_op_a; + pol commit sel_mem_op_b; + pol commit sel_mem_op_c; + pol commit sel_mem_op_d; // Read-write flag per intermediate register: Read = 0, Write = 1 + // This specifies whether the register is read or written to. pol commit rwa; pol commit rwb; pol commit rwc; pol commit rwd; // Indirect register values - pol commit ind_a; - pol commit ind_b; - pol commit ind_c; - pol commit ind_d; - - // Indirect memory operation selector per indirect register - pol commit ind_op_a; - pol commit ind_op_b; - pol commit ind_op_c; - pol commit ind_op_d; + // Cell ind_addr_x holds the indirect address to be resolved into mem_addr_ix. + pol commit ind_addr_a; + pol commit ind_addr_b; + pol commit ind_addr_c; + pol commit ind_addr_d; - // Memory index involved into a memory operation per pertaining intermediate register + // Memory address involved into a memory operation per pertaining intermediate register // We should range constrain it to 32 bits ultimately. For first version of the AVM, // we will assume that these columns are of the right type. - pol commit mem_idx_a; - pol commit mem_idx_b; - pol commit mem_idx_c; - pol commit mem_idx_d; + pol commit mem_addr_a; + pol commit mem_addr_b; + pol commit mem_addr_c; + pol commit mem_addr_d; + + // Indirect memory operation selector per indirect register + // This selects whether ind_addr_x is resolved to mem_addr_ix. + pol commit sel_resolve_ind_addr_a; + pol commit sel_resolve_ind_addr_b; + pol commit sel_resolve_ind_addr_c; + pol commit sel_resolve_ind_addr_d; // Track the last line of the execution trace. It does NOT correspond to the last row of the whole table // of size N. As this depends on the supplied bytecode, this polynomial cannot be constant. - pol commit last; + pol commit sel_last; // Relations on type constraints // TODO: Very likely, we can remove these constraints as the selectors should be derived during @@ -316,26 +311,26 @@ namespace avm_main(256); sel_op_shl * (1 - sel_op_shl) = 0; sel_op_shr * (1 - sel_op_shr) = 0; - sel_internal_call * (1 - sel_internal_call) = 0; - sel_internal_return * (1 - sel_internal_return) = 0; - sel_jump * (1 - sel_jump) = 0; - sel_jumpi * (1 - sel_jumpi) = 0; - sel_halt * (1 - sel_halt) = 0; - sel_external_call * (1 - sel_external_call) = 0; + sel_op_internal_call * (1 - sel_op_internal_call) = 0; + sel_op_internal_return * (1 - sel_op_internal_return) = 0; + sel_op_jump * (1 - sel_op_jump) = 0; + sel_op_jumpi * (1 - sel_op_jumpi) = 0; + sel_op_halt * (1 - sel_op_halt) = 0; + sel_op_external_call * (1 - sel_op_external_call) = 0; // Might be removed if derived from opcode based on a lookup of constants - sel_mov * ( 1 - sel_mov) = 0; - sel_cmov * ( 1 - sel_cmov) = 0; + sel_op_mov * ( 1 - sel_op_mov) = 0; + sel_op_cmov * ( 1 - sel_op_cmov) = 0; op_err * (1 - op_err) = 0; - tag_err * (1 - tag_err) = 0; // Potential optimization (boolean constraint derivation from equivalence check to avm_mem)? + tag_err * (1 - tag_err) = 0; // Potential optimization (boolean constraint derivation from equivalence check to mem)? id_zero * (1 - id_zero) = 0; // Might be removed if derived from opcode based on a lookup of constants - mem_op_a * (1 - mem_op_a) = 0; - mem_op_b * (1 - mem_op_b) = 0; - mem_op_c * (1 - mem_op_c) = 0; - mem_op_d * (1 - mem_op_d) = 0; + sel_mem_op_a * (1 - sel_mem_op_a) = 0; + sel_mem_op_b * (1 - sel_mem_op_b) = 0; + sel_mem_op_c * (1 - sel_mem_op_c) = 0; + sel_mem_op_d * (1 - sel_mem_op_d) = 0; rwa * (1 - rwa) = 0; rwb * (1 - rwb) = 0; @@ -343,21 +338,21 @@ namespace avm_main(256); rwd * (1 - rwd) = 0; // Might be removed if derived from opcode based on a lookup of constants - ind_op_a * (1 - ind_op_a) = 0; - ind_op_b * (1 - ind_op_b) = 0; - ind_op_c * (1 - ind_op_c) = 0; - ind_op_d * (1 - ind_op_d) = 0; + sel_resolve_ind_addr_a * (1 - sel_resolve_ind_addr_a) = 0; + sel_resolve_ind_addr_b * (1 - sel_resolve_ind_addr_b) = 0; + sel_resolve_ind_addr_c * (1 - sel_resolve_ind_addr_c) = 0; + sel_resolve_ind_addr_d * (1 - sel_resolve_ind_addr_d) = 0; // TODO - Potential constraints to be implemented: - // - mem_idx_a, mem_idx_b, mem_idx_c, mem_idx_d to u32 type: + // - mem_addr_a, mem_addr_b, mem_addr_c, mem_addr_d to u32 type: // - For direct memory accesses, this should be enforced by bytecode validation // and instruction decomposition. Namely, in this case, only 32-bit immediate // values should be written into these memory indices. // - For indirect memory accesses, the memory trace constraints ensure that // loaded values come from memory addresses with tag u32. This is enforced in the memory trace - // where each memory entry with flag ind_op_x (for x = a,b,c,d) constrains r_int_tag == 3 (u32). + // where each memory entry with flag sel_resolve_ind_addr_x (for x = a,b,c,d) constrains r_int_tag == 3 (u32). // - // - ind_a, ind_b, ind_c, ind_d to u32 type: Should be guaranteed by bytecode validation and + // - ind_addr_a, ind_addr_b, ind_addr_c, ind_addr_d to u32 type: Should be guaranteed by bytecode validation and // instruction decomposition as only immediate 32-bit values should be written into the indirect registers. // // - 0 <= r_in_tag, w_in_tag <= 6 // This should be constrained by the operation decomposition. @@ -419,38 +414,38 @@ namespace avm_main(256); ); // Ensure that only one kernel lookup is active when the kernel_in_offset is active #[KERNEL_INPUT_ACTIVE_CHECK] - KERNEL_INPUT_SELECTORS * (1 - q_kernel_lookup) = 0; + KERNEL_INPUT_SELECTORS * (1 - sel_q_kernel_lookup) = 0; pol KERNEL_OUTPUT_SELECTORS = ( sel_op_note_hash_exists + sel_op_emit_note_hash + sel_op_nullifier_exists + sel_op_emit_nullifier + sel_op_l1_to_l2_msg_exists + sel_op_emit_unencrypted_log + sel_op_emit_l2_to_l1_msg ); #[KERNEL_OUTPUT_ACTIVE_CHECK] - KERNEL_OUTPUT_SELECTORS * (1 - q_kernel_output_lookup) = 0; + KERNEL_OUTPUT_SELECTORS * (1 - sel_q_kernel_output_lookup) = 0; //===== CONTROL FLOW ======================================================= //===== JUMP =============================================================== #[PC_JUMP] - sel_jump * (pc' - ia) = 0; + sel_op_jump * (pc' - ia) = 0; #[PC_JUMPI] - sel_jumpi * ((1 - id_zero) * (pc' - ia) + id_zero * (pc' - pc - 1)) = 0; + sel_op_jumpi * ((1 - id_zero) * (pc' - ia) + id_zero * (pc' - pc - 1)) = 0; - // TODO: Consolidation with #[PC_JUMP] and sel_internal_call * (pc' - ia) = 0; sel_internal_return * (pc' - ia) = 0; + // TODO: Consolidation with #[PC_JUMP] and sel_op_internal_call * (pc' - ia) = 0; sel_op_internal_return * (pc' - ia) = 0; //===== INTERNAL_CALL ====================================================== // - The program counter in the next row should be equal to the value loaded from the ia register // - We then write the return location (pc + 1) into the call stack (in memory) #[RETURN_POINTER_INCREMENT] - sel_internal_call * (internal_return_ptr' - (internal_return_ptr + 1)) = 0; - sel_internal_call * (internal_return_ptr - mem_idx_b) = 0; - sel_internal_call * (pc' - ia) = 0; - sel_internal_call * ((pc + 1) - ib) = 0; + sel_op_internal_call * (internal_return_ptr' - (internal_return_ptr + 1)) = 0; + sel_op_internal_call * (internal_return_ptr - mem_addr_b) = 0; + sel_op_internal_call * (pc' - ia) = 0; + sel_op_internal_call * ((pc + 1) - ib) = 0; // TODO(md): Below relations may be removed through sub-op table lookup - sel_internal_call * (rwb - 1) = 0; - sel_internal_call * (mem_op_b - 1) = 0; + sel_op_internal_call * (rwb - 1) = 0; + sel_op_internal_call * (sel_mem_op_b - 1) = 0; //===== INTERNAL_RETURN =================================================== // - We load the memory pointer to be the internal_return_ptr @@ -458,44 +453,44 @@ namespace avm_main(256); // - decrement the internal_return_ptr #[RETURN_POINTER_DECREMENT] - sel_internal_return * (internal_return_ptr' - (internal_return_ptr - 1)) = 0; - sel_internal_return * ((internal_return_ptr - 1) - mem_idx_a) = 0; - sel_internal_return * (pc' - ia) = 0; + sel_op_internal_return * (internal_return_ptr' - (internal_return_ptr - 1)) = 0; + sel_op_internal_return * ((internal_return_ptr - 1) - mem_addr_a) = 0; + sel_op_internal_return * (pc' - ia) = 0; // TODO(md): Below relations may be removed through sub-op table lookup - sel_internal_return * rwa = 0; - sel_internal_return * (mem_op_a - 1) = 0; + sel_op_internal_return * rwa = 0; + sel_op_internal_return * (sel_mem_op_a - 1) = 0; //===== CONTROL_FLOW_CONSISTENCY ============================================ - pol INTERNAL_CALL_STACK_SELECTORS = (first + sel_internal_call + sel_internal_return + sel_halt); - pol ALL_CTRL_FLOW_SEL = sel_jump + sel_jumpi + sel_internal_call + sel_internal_return; + pol INTERNAL_CALL_STACK_SELECTORS = (sel_first + sel_op_internal_call + sel_op_internal_return + sel_op_halt); + pol SEL_ALL_CTRL_FLOW = sel_op_jump + sel_op_jumpi + sel_op_internal_call + sel_op_internal_return; - pol ALL_LEFTGAS_SEL = sel_op_dagasleft + sel_op_l2gasleft; - pol ALL_BINARY_SEL = sel_op_and + sel_op_or + sel_op_xor; - pol ALL_GADGET_SEL = sel_op_radix_le + sel_op_sha256 + sel_op_poseidon2 + sel_op_keccak + sel_op_pedersen; - pol ALL_MEMORY_SEL = sel_cmov + sel_mov; - pol OPCODE_SELECTORS = sel_op_fdiv + ALU_ALL_SEL + ALL_BINARY_SEL + ALL_MEMORY_SEL + ALL_GADGET_SEL - + KERNEL_INPUT_SELECTORS + KERNEL_OUTPUT_SELECTORS + ALL_LEFTGAS_SEL; + pol SEL_ALL_LEFTGAS = sel_op_dagasleft + sel_op_l2gasleft; + pol SEL_ALL_BINARY = sel_op_and + sel_op_or + sel_op_xor; + pol SEL_ALL_GADGET = sel_op_radix_le + sel_op_sha256 + sel_op_poseidon2 + sel_op_keccak + sel_op_pedersen; + pol SEL_ALL_MEMORY = sel_op_cmov + sel_op_mov; + pol OPCODE_SELECTORS = sel_op_fdiv + SEL_ALU_ALL + SEL_ALL_BINARY + SEL_ALL_MEMORY + SEL_ALL_GADGET + + KERNEL_INPUT_SELECTORS + KERNEL_OUTPUT_SELECTORS + SEL_ALL_LEFTGAS; - // TODO: gas_cost_active is activating gas accounting on a given row. All opcode with selectors + // TODO: sel_gas_accounting_active is activating gas accounting on a given row. All opcode with selectors // are activated through the relation below. The other opcodes which are implemented purely // through memory sub-operations such as CALLDATACOPY, RETURN, SET are activated by - // setting a newly introduced boolean mem_op_activate_gas which is set in witness generation. + // setting a newly introduced boolean sel_mem_op_activate_gas which is set in witness generation. // We should remove this shortcut and constrain this activation through bytecode decomposition. // Alternatively, we introduce a boolean selector for the three opcodes mentioned above. // Note: External call gas cost is not constrained - pol commit gas_cost_active; - pol commit mem_op_activate_gas; // TODO: remove this one + pol commit sel_gas_accounting_active; + pol commit sel_mem_op_activate_gas; // TODO: remove this one // TODO: remove sload and sstore from here // This temporarily disables gas tracking for sload and sstore because our gas // tracking doesn't work properly for instructions that span multiple rows - gas_cost_active - OPCODE_SELECTORS - ALL_CTRL_FLOW_SEL - sel_op_sload - sel_op_sstore - mem_op_activate_gas = 0; + sel_gas_accounting_active - OPCODE_SELECTORS - SEL_ALL_CTRL_FLOW - sel_op_sload - sel_op_sstore - sel_mem_op_activate_gas = 0; // Program counter must increment if not jumping or returning #[PC_INCREMENT] - (1 - first) * (1 - sel_halt) * OPCODE_SELECTORS * (pc' - (pc + 1)) = 0; + (1 - sel_first) * (1 - sel_op_halt) * OPCODE_SELECTORS * (pc' - (pc + 1)) = 0; - // first == 0 && sel_internal_call == 0 && sel_internal_return == 0 && sel_halt == 0 ==> internal_return_ptr == internal_return_ptr' + // sel_first == 0 && sel_op_internal_call == 0 && sel_op_internal_return == 0 && sel_op_halt == 0 ==> internal_return_ptr == internal_return_ptr' #[INTERNAL_RETURN_POINTER_CONSISTENCY] (1 - INTERNAL_CALL_STACK_SELECTORS) * (internal_return_ptr' - internal_return_ptr) = 0; @@ -503,7 +498,7 @@ namespace avm_main(256); //====== SPACE ID CONSTRAINTS =============================================== #[SPACE_ID_INTERNAL] - (sel_internal_call + sel_internal_return) * (space_id - constants.INTERNAL_CALL_SPACE_ID) = 0; + (sel_op_internal_call + sel_op_internal_return) * (space_id - constants.INTERNAL_CALL_SPACE_ID) = 0; #[SPACE_ID_STANDARD_OPCODES] OPCODE_SELECTORS * (call_ptr - space_id) = 0; @@ -511,49 +506,49 @@ namespace avm_main(256); //====== MEMORY OPCODES CONSTRAINTS ========================================= // TODO: consolidate with zero division error handling - // TODO: Ensure that operation decompostion will ensure mutual exclusivity of sel_cmov and sel_jumpi + // TODO: Ensure that operation decompostion will ensure mutual exclusivity of sel_op_cmov and sel_op_jumpi - // When sel_cmov or sel_jumpi == 1, we need id == 0 <==> id_zero == 0 + // When sel_op_cmov or sel_op_jumpi == 1, we need id == 0 <==> id_zero == 0 // This can be achieved with the 2 following relations. // inv is an extra witness to show that we can invert id, i.e., inv = id^(-1) // If id == 0, we have to set inv = 1 to satisfy the second relation, // because id_zero == 1 from the first relation. #[CMOV_CONDITION_RES_1] - (sel_cmov + sel_jumpi) * (id * inv - 1 + id_zero) = 0; + (sel_op_cmov + sel_op_jumpi) * (id * inv - 1 + id_zero) = 0; #[CMOV_CONDITION_RES_2] - (sel_cmov + sel_jumpi) * id_zero * (1 - inv) = 0; + (sel_op_cmov + sel_op_jumpi) * id_zero * (1 - inv) = 0; // Boolean selectors telling whether we move ia to ic or ib to ic. // Boolean constraints and mutual exclusivity are derived from their - // respective definitions based on sel_mov, sel_cmov, and id_zero. - pol commit sel_mov_a; - pol commit sel_mov_b; + // respective definitions based on sel_op_mov, sel_op_cmov, and id_zero. + pol commit sel_mov_ia_to_ic; + pol commit sel_mov_ib_to_ic; // For MOV, we copy ia to ic. // For CMOV, we copy ia to ic if id is NOT zero, otherwise we copy ib to ic. - sel_mov_a = sel_mov + sel_cmov * (1 - id_zero); - sel_mov_b = sel_cmov * id_zero; + sel_mov_ia_to_ic = sel_op_mov + sel_op_cmov * (1 - id_zero); + sel_mov_ib_to_ic = sel_op_cmov * id_zero; #[MOV_SAME_VALUE_A] - sel_mov_a * (ia - ic) = 0; // Ensure that the correct value is moved/copied. + sel_mov_ia_to_ic * (ia - ic) = 0; // Ensure that the correct value is moved/copied. #[MOV_SAME_VALUE_B] - sel_mov_b * (ib - ic) = 0; // Ensure that the correct value is moved/copied. + sel_mov_ib_to_ic * (ib - ic) = 0; // Ensure that the correct value is moved/copied. #[MOV_MAIN_SAME_TAG] - (sel_mov + sel_cmov) * (r_in_tag - w_in_tag) = 0; + (sel_op_mov + sel_op_cmov) * (r_in_tag - w_in_tag) = 0; //===== ALU CONSTRAINTS ===================================================== - pol ALU_R_TAG_SEL = sel_op_add + sel_op_sub + sel_op_mul + sel_op_div + sel_op_not + sel_op_eq + pol SEL_ALU_R_TAG = sel_op_add + sel_op_sub + sel_op_mul + sel_op_div + sel_op_not + sel_op_eq + sel_op_lt + sel_op_lte + sel_op_shr + sel_op_shl; - pol ALU_W_TAG_SEL = sel_op_cast; - pol ALU_ALL_SEL = ALU_R_TAG_SEL + ALU_W_TAG_SEL; + pol SEL_ALU_W_TAG = sel_op_cast; + pol SEL_ALU_ALL = SEL_ALU_R_TAG + SEL_ALU_W_TAG; // Predicate to activate the copy of intermediate registers to ALU table. If tag_err == 1, // the operation is not copied to the ALU table. - alu_sel = ALU_ALL_SEL * (1 - tag_err) * (1 - op_err); + sel_alu = SEL_ALU_ALL * (1 - tag_err) * (1 - op_err); // Dispatch the correct in_tag for alu - ALU_R_TAG_SEL * (alu_in_tag - r_in_tag) = 0; - ALU_W_TAG_SEL * (alu_in_tag - w_in_tag) = 0; + SEL_ALU_R_TAG * (alu_in_tag - r_in_tag) = 0; + SEL_ALU_W_TAG * (alu_in_tag - w_in_tag) = 0; //===== GASLEFT OPCODES ===================================================== #[L2GASLEFT] @@ -569,107 +564,107 @@ namespace avm_main(256); // CALL CONTEXT #[SENDER_KERNEL] - sel_op_sender * (avm_kernel.kernel_in_offset - constants.SENDER_SELECTOR) = 0; + sel_op_sender * (kernel.kernel_in_offset - constants.SENDER_SELECTOR) = 0; #[ADDRESS_KERNEL] - sel_op_address * (avm_kernel.kernel_in_offset - constants.ADDRESS_SELECTOR) = 0; + sel_op_address * (kernel.kernel_in_offset - constants.ADDRESS_SELECTOR) = 0; #[STORAGE_ADDRESS_KERNEL] - sel_op_storage_address * (avm_kernel.kernel_in_offset - constants.STORAGE_ADDRESS_SELECTOR) = 0; + sel_op_storage_address * (kernel.kernel_in_offset - constants.STORAGE_ADDRESS_SELECTOR) = 0; // FEES #[FEE_DA_GAS_KERNEL] - sel_op_fee_per_da_gas * (avm_kernel.kernel_in_offset - constants.FEE_PER_DA_GAS_SELECTOR) = 0; + sel_op_fee_per_da_gas * (kernel.kernel_in_offset - constants.FEE_PER_DA_GAS_SELECTOR) = 0; #[FEE_L2_GAS_KERNEL] - sel_op_fee_per_l2_gas * (avm_kernel.kernel_in_offset - constants.FEE_PER_L2_GAS_SELECTOR) = 0; + sel_op_fee_per_l2_gas * (kernel.kernel_in_offset - constants.FEE_PER_L2_GAS_SELECTOR) = 0; #[FEE_TRANSACTION_FEE_KERNEL] - sel_op_transaction_fee * (avm_kernel.kernel_in_offset - constants.TRANSACTION_FEE_SELECTOR) = 0; + sel_op_transaction_fee * (kernel.kernel_in_offset - constants.TRANSACTION_FEE_SELECTOR) = 0; // GLOBALS #[CHAIN_ID_KERNEL] - sel_op_chain_id * (avm_kernel.kernel_in_offset - constants.CHAIN_ID_SELECTOR) = 0; + sel_op_chain_id * (kernel.kernel_in_offset - constants.CHAIN_ID_SELECTOR) = 0; #[VERSION_KERNEL] - sel_op_version * (avm_kernel.kernel_in_offset - constants.VERSION_SELECTOR) = 0; + sel_op_version * (kernel.kernel_in_offset - constants.VERSION_SELECTOR) = 0; #[BLOCK_NUMBER_KERNEL] - sel_op_block_number * (avm_kernel.kernel_in_offset - constants.BLOCK_NUMBER_SELECTOR) = 0; + sel_op_block_number * (kernel.kernel_in_offset - constants.BLOCK_NUMBER_SELECTOR) = 0; #[COINBASE_KERNEL] - sel_op_coinbase * (avm_kernel.kernel_in_offset - constants.COINBASE_SELECTOR) = 0; + sel_op_coinbase * (kernel.kernel_in_offset - constants.COINBASE_SELECTOR) = 0; #[TIMESTAMP_KERNEL] - sel_op_timestamp * (avm_kernel.kernel_in_offset - constants.TIMESTAMP_SELECTOR) = 0; + sel_op_timestamp * (kernel.kernel_in_offset - constants.TIMESTAMP_SELECTOR) = 0; // OUTPUTS LOOKUPS // Constrain the value of kernel_out_offset to be the correct offset for the operation being performed #[NOTE_HASH_KERNEL_OUTPUT] - sel_op_note_hash_exists * (avm_kernel.kernel_out_offset - (avm_kernel.START_NOTE_HASH_EXISTS_WRITE_OFFSET + avm_kernel.note_hash_exist_write_offset)) = 0; - first * avm_kernel.note_hash_exist_write_offset = 0; + sel_op_note_hash_exists * (kernel.kernel_out_offset - (kernel.START_NOTE_HASH_EXISTS_WRITE_OFFSET + kernel.note_hash_exist_write_offset)) = 0; + sel_first * kernel.note_hash_exist_write_offset = 0; #[EMIT_NOTE_HASH_KERNEL_OUTPUT] - sel_op_emit_note_hash * (avm_kernel.kernel_out_offset - (avm_kernel.START_EMIT_NOTE_HASH_WRITE_OFFSET + avm_kernel.emit_note_hash_write_offset)) = 0; - first * avm_kernel.emit_note_hash_write_offset = 0; + sel_op_emit_note_hash * (kernel.kernel_out_offset - (kernel.START_EMIT_NOTE_HASH_WRITE_OFFSET + kernel.emit_note_hash_write_offset)) = 0; + sel_first * kernel.emit_note_hash_write_offset = 0; #[NULLIFIER_EXISTS_KERNEL_OUTPUT] - sel_op_nullifier_exists * (avm_kernel.kernel_out_offset - ((ib * (avm_kernel.START_NULLIFIER_EXISTS_OFFSET + avm_kernel.nullifier_exists_write_offset)) + ((1 - ib) * (avm_kernel.START_NULLIFIER_NON_EXISTS_OFFSET + avm_kernel.nullifier_non_exists_write_offset)))) = 0; - first * avm_kernel.nullifier_exists_write_offset = 0; - first * avm_kernel.nullifier_non_exists_write_offset = 0; + sel_op_nullifier_exists * (kernel.kernel_out_offset - ((ib * (kernel.START_NULLIFIER_EXISTS_OFFSET + kernel.nullifier_exists_write_offset)) + ((1 - ib) * (kernel.START_NULLIFIER_NON_EXISTS_OFFSET + kernel.nullifier_non_exists_write_offset)))) = 0; + sel_first * kernel.nullifier_exists_write_offset = 0; + sel_first * kernel.nullifier_non_exists_write_offset = 0; #[EMIT_NULLIFIER_KERNEL_OUTPUT] - sel_op_emit_nullifier * (avm_kernel.kernel_out_offset - (avm_kernel.START_EMIT_NULLIFIER_WRITE_OFFSET + avm_kernel.emit_nullifier_write_offset)) = 0; - first * avm_kernel.emit_nullifier_write_offset = 0; + sel_op_emit_nullifier * (kernel.kernel_out_offset - (kernel.START_EMIT_NULLIFIER_WRITE_OFFSET + kernel.emit_nullifier_write_offset)) = 0; + sel_first * kernel.emit_nullifier_write_offset = 0; #[L1_TO_L2_MSG_EXISTS_KERNEL_OUTPUT] - sel_op_l1_to_l2_msg_exists * (avm_kernel.kernel_out_offset - (avm_kernel.START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + avm_kernel.l1_to_l2_msg_exists_write_offset)) = 0; - first * avm_kernel.l1_to_l2_msg_exists_write_offset = 0; + sel_op_l1_to_l2_msg_exists * (kernel.kernel_out_offset - (kernel.START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + kernel.l1_to_l2_msg_exists_write_offset)) = 0; + sel_first * kernel.l1_to_l2_msg_exists_write_offset = 0; #[EMIT_UNENCRYPTED_LOG_KERNEL_OUTPUT] - sel_op_emit_unencrypted_log * (avm_kernel.kernel_out_offset - (avm_kernel.START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET + avm_kernel.emit_unencrypted_log_write_offset)) = 0; - first * avm_kernel.emit_unencrypted_log_write_offset = 0; + sel_op_emit_unencrypted_log * (kernel.kernel_out_offset - (kernel.START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET + kernel.emit_unencrypted_log_write_offset)) = 0; + sel_first * kernel.emit_unencrypted_log_write_offset = 0; // TODO: Add the equivalent for GETCONTRACTINSTANCE? #[EMIT_L2_TO_L1_MSGS_KERNEL_OUTPUT] - sel_op_emit_l2_to_l1_msg * (avm_kernel.kernel_out_offset - (avm_kernel.START_EMIT_L2_TO_l1_MSG + avm_kernel.emit_l2_to_l1_msg_write_offset)) = 0; - first * avm_kernel.emit_l2_to_l1_msg_write_offset = 0; + sel_op_emit_l2_to_l1_msg * (kernel.kernel_out_offset - (kernel.START_EMIT_L2_TO_l1_MSG + kernel.emit_l2_to_l1_msg_write_offset)) = 0; + sel_first * kernel.emit_l2_to_l1_msg_write_offset = 0; #[SLOAD_KERNEL_OUTPUT] - sel_op_sload * (avm_kernel.kernel_out_offset - (avm_kernel.START_SLOAD_WRITE_OFFSET + avm_kernel.sload_write_offset)) = 0; - first * avm_kernel.sload_write_offset = 0; + sel_op_sload * (kernel.kernel_out_offset - (kernel.START_SLOAD_WRITE_OFFSET + kernel.sload_write_offset)) = 0; + sel_first * kernel.sload_write_offset = 0; #[SSTORE_KERNEL_OUTPUT] - sel_op_sstore * (avm_kernel.kernel_out_offset - (avm_kernel.START_SSTORE_WRITE_OFFSET + avm_kernel.sstore_write_offset)) = 0; - first * avm_kernel.sstore_write_offset = 0; + sel_op_sstore * (kernel.kernel_out_offset - (kernel.START_SSTORE_WRITE_OFFSET + kernel.sstore_write_offset)) = 0; + sel_first * kernel.sstore_write_offset = 0; // When we encounter a state writing opcode // We increment the side effect counter by 1 - KERNEL_OUTPUT_SELECTORS * (avm_kernel.side_effect_counter' - (avm_kernel.side_effect_counter + 1)) = 0; + KERNEL_OUTPUT_SELECTORS * (kernel.side_effect_counter' - (kernel.side_effect_counter + 1)) = 0; #[KERNEL_OUTPUT_LOOKUP] - q_kernel_output_lookup {avm_kernel.kernel_out_offset, ia, avm_kernel.side_effect_counter, ib} in avm_kernel.q_public_input_kernel_out_add_to_table {clk, avm_kernel.kernel_value_out, avm_kernel.kernel_side_effect_out, avm_kernel.kernel_metadata_out}; + sel_q_kernel_output_lookup {kernel.kernel_out_offset, ia, kernel.side_effect_counter, ib} in kernel.q_public_input_kernel_out_add_to_table {clk, kernel.kernel_value_out, kernel.kernel_side_effect_out, kernel.kernel_metadata_out}; #[LOOKUP_INTO_KERNEL] - q_kernel_lookup { avm_main.ia, avm_kernel.kernel_in_offset } in avm_kernel.q_public_input_kernel_add_to_table { avm_kernel.kernel_inputs, clk }; + sel_q_kernel_lookup { main.ia, kernel.kernel_in_offset } in kernel.q_public_input_kernel_add_to_table { kernel.kernel_inputs, clk }; //====== Inter-table Constraints ============================================ #[INCL_MAIN_TAG_ERR] - avm_mem.tag_err {avm_mem.clk} in tag_err {clk}; + mem.tag_err {mem.clk} in tag_err {clk}; #[INCL_MEM_TAG_ERR] - tag_err {clk} in avm_mem.tag_err {avm_mem.clk}; + tag_err {clk} in mem.tag_err {mem.clk}; #[PERM_MAIN_ALU] - alu_sel {clk, ia, ib, ic, sel_op_add, sel_op_sub, + sel_alu {clk, ia, ib, ic, sel_op_add, sel_op_sub, sel_op_mul, sel_op_div, sel_op_eq, sel_op_not, sel_op_cast, sel_op_lt, sel_op_lte, sel_op_shr, sel_op_shl, alu_in_tag} is - avm_alu.alu_sel {avm_alu.clk, avm_alu.ia, avm_alu.ib, avm_alu.ic, avm_alu.op_add, avm_alu.op_sub, - avm_alu.op_mul, avm_alu.op_div, avm_alu.op_eq, avm_alu.op_not, avm_alu.op_cast, - avm_alu.op_lt, avm_alu.op_lte, avm_alu.op_shr, avm_alu.op_shl, avm_alu.in_tag}; + alu.sel_alu {alu.clk, alu.ia, alu.ib, alu.ic, alu.op_add, alu.op_sub, + alu.op_mul, alu.op_div, alu.op_eq, alu.op_not, alu.op_cast, + alu.op_lt, alu.op_lte, alu.op_shr, alu.op_shl, alu.in_tag}; // Based on the boolean selectors, we derive the binary op id to lookup in the table; // TODO: Check if having 4 columns (op_id + 3 boolean selectors) is more optimal that just using the op_id @@ -679,187 +674,182 @@ namespace avm_main(256); bin_op_id = sel_op_or + 2 * sel_op_xor; // sel_op_and excluded since op_id = 0 for op_and // Only 1 of the binary selectors should be set (i.e. Mutual Exclusivity) - // Bin_sel is not explicitly constrained to be boolean, however this is enforced through + // sel_Bin is not explicitly constrained to be boolean, however this is enforced through // the operation decomposition step during bytecode unpacking. #[BIN_SEL_2] - bin_sel = sel_op_and + sel_op_or + sel_op_xor; + sel_bin = sel_op_and + sel_op_or + sel_op_xor; #[PERM_MAIN_BIN] - bin_sel {clk, ia, ib, ic, bin_op_id, r_in_tag} + sel_bin {clk, ia, ib, ic, bin_op_id, r_in_tag} is - avm_binary.start {avm_binary.clk, avm_binary.acc_ia, avm_binary.acc_ib, avm_binary.acc_ic, avm_binary.op_id, avm_binary.in_tag}; + binary.start {binary.clk, binary.acc_ia, binary.acc_ib, binary.acc_ic, binary.op_id, binary.in_tag}; #[PERM_MAIN_CONV] sel_op_radix_le {clk, ia, ic, id} is - avm_conversion.to_radix_le_sel {avm_conversion.clk, avm_conversion.input, avm_conversion.radix, avm_conversion.num_limbs}; + conversion.sel_to_radix_le {conversion.clk, conversion.input, conversion.radix, conversion.num_limbs}; // This will be enabled when we migrate just to sha256Compression, as getting sha256 to work with it is tricky. // #[PERM_MAIN_SHA256] // sel_op_sha256 {clk, ia, ib, ic} // is - // avm_sha256.sha256_compression_sel {avm_sha256.clk, avm_sha256.state, avm_sha256.input, avm_sha256.output}; + // sha256.sel_sha256_compression {sha256.clk, sha256.state, sha256.input, sha256.output}; #[PERM_MAIN_POS2_PERM] sel_op_poseidon2 {clk, ia, ib} is - avm_poseidon2.poseidon_perm_sel {avm_poseidon2.clk, avm_poseidon2.input, avm_poseidon2.output}; + poseidon2.sel_poseidon_perm {poseidon2.clk, poseidon2.input, poseidon2.output}; // This will be enabled when we migrate just to keccakf1600, as getting keccak to work with it is tricky. // #[PERM_MAIN_KECCAK] // sel_op_keccak {clk, ia, ic} // is - // avm_keccakf1600.keccakf1600_sel {avm_keccakf1600.clk, avm_keccakf1600.input, avm_keccakf1600.output}; + // keccakf1600.sel_keccakf1600 {keccakf1600.clk, keccakf1600.input, keccakf1600.output}; #[PERM_MAIN_PEDERSEN] sel_op_pedersen {clk, ia} is - avm_pedersen.pedersen_sel {avm_pedersen.clk, avm_pedersen.input}; + pedersen.sel_pedersen {pedersen.clk, pedersen.input}; #[PERM_MAIN_MEM_A] - mem_op_a {clk, space_id, mem_idx_a, ia, rwa - , r_in_tag, w_in_tag, sel_mov_a, sel_cmov} + sel_mem_op_a {clk, space_id, mem_addr_a, ia, rwa, r_in_tag, w_in_tag, sel_mov_ia_to_ic, sel_op_cmov} is - avm_mem.op_a {avm_mem.clk, avm_mem.space_id, avm_mem.addr, avm_mem.val, avm_mem.rw - , avm_mem.r_in_tag, avm_mem.w_in_tag, avm_mem.sel_mov_a, avm_mem.sel_cmov}; + mem.sel_op_a {mem.clk, mem.space_id, mem.addr, mem.val, mem.rw + , mem.r_in_tag, mem.w_in_tag, mem.sel_mov_ia_to_ic, mem.sel_op_cmov}; #[PERM_MAIN_MEM_B] - mem_op_b {clk, space_id, mem_idx_b, ib, rwb - , r_in_tag, w_in_tag, sel_mov_b, sel_cmov} + sel_mem_op_b {clk, space_id, mem_addr_b, ib, rwb, r_in_tag, w_in_tag, sel_mov_ib_to_ic, sel_op_cmov} is - avm_mem.op_b {avm_mem.clk, avm_mem.space_id, avm_mem.addr, avm_mem.val, avm_mem.rw - , avm_mem.r_in_tag, avm_mem.w_in_tag, avm_mem.sel_mov_b, avm_mem.sel_cmov}; + mem.sel_op_b {mem.clk, mem.space_id, mem.addr, mem.val, mem.rw + , mem.r_in_tag, mem.w_in_tag, mem.sel_mov_ib_to_ic, mem.sel_op_cmov}; #[PERM_MAIN_MEM_C] - mem_op_c {clk, space_id, mem_idx_c, ic, rwc - , r_in_tag, w_in_tag} + sel_mem_op_c {clk, space_id, mem_addr_c, ic, rwc, r_in_tag, w_in_tag} is - avm_mem.op_c {avm_mem.clk, avm_mem.space_id, avm_mem.addr, avm_mem.val, avm_mem.rw - , avm_mem.r_in_tag, avm_mem.w_in_tag}; + mem.sel_op_c {mem.clk, mem.space_id, mem.addr, mem.val, mem.rw, mem.r_in_tag, mem.w_in_tag}; #[PERM_MAIN_MEM_D] - mem_op_d {clk, space_id, mem_idx_d, id, rwd - , r_in_tag, w_in_tag, sel_cmov} + sel_mem_op_d {clk, space_id, mem_addr_d, id, rwd, r_in_tag, w_in_tag, sel_op_cmov} is - avm_mem.op_d {avm_mem.clk, avm_mem.space_id, avm_mem.addr, avm_mem.val, avm_mem.rw - , avm_mem.r_in_tag, avm_mem.w_in_tag, avm_mem.sel_cmov}; + mem.sel_op_d {mem.clk, mem.space_id, mem.addr, mem.val, mem.rw + , mem.r_in_tag, mem.w_in_tag, mem.sel_op_cmov}; - #[PERM_MAIN_MEM_IND_A] - ind_op_a {clk, space_id, ind_a, mem_idx_a} + #[PERM_MAIN_MEM_IND_ADDR_A] + sel_resolve_ind_addr_a {clk, space_id, ind_addr_a, mem_addr_a} is - avm_mem.ind_op_a {avm_mem.clk, avm_mem.space_id, avm_mem.addr, avm_mem.val}; + mem.sel_resolve_ind_addr_a {mem.clk, mem.space_id, mem.addr, mem.val}; - #[PERM_MAIN_MEM_IND_B] - ind_op_b {clk, space_id, ind_b, mem_idx_b} + #[PERM_MAIN_MEM_IND_ADDR_B] + sel_resolve_ind_addr_b {clk, space_id, ind_addr_b, mem_addr_b} is - avm_mem.ind_op_b {avm_mem.clk, avm_mem.space_id, avm_mem.addr, avm_mem.val}; + mem.sel_resolve_ind_addr_b {mem.clk, mem.space_id, mem.addr, mem.val}; - #[PERM_MAIN_MEM_IND_C] - ind_op_c {clk, space_id, ind_c, mem_idx_c} + #[PERM_MAIN_MEM_IND_ADDR_C] + sel_resolve_ind_addr_c {clk, space_id, ind_addr_c, mem_addr_c} is - avm_mem.ind_op_c {avm_mem.clk, avm_mem.space_id, avm_mem.addr, avm_mem.val}; + mem.sel_resolve_ind_addr_c {mem.clk, mem.space_id, mem.addr, mem.val}; - #[PERM_MAIN_MEM_IND_D] - ind_op_d {clk, space_id, ind_d, mem_idx_d} + #[PERM_MAIN_MEM_IND_ADDR_D] + sel_resolve_ind_addr_d {clk, space_id, ind_addr_d, mem_addr_d} is - avm_mem.ind_op_d {avm_mem.clk, avm_mem.space_id, avm_mem.addr, avm_mem.val}; + mem.sel_resolve_ind_addr_d {mem.clk, mem.space_id, mem.addr, mem.val}; #[LOOKUP_MEM_RNG_CHK_LO] - avm_mem.rng_chk_sel {avm_mem.diff_lo} in sel_rng_16 {clk}; + mem.sel_rng_chk {mem.diff_lo} in sel_rng_16 {clk}; #[LOOKUP_MEM_RNG_CHK_MID] - avm_mem.rng_chk_sel {avm_mem.diff_mid} in sel_rng_16 {clk}; + mem.sel_rng_chk {mem.diff_mid} in sel_rng_16 {clk}; #[LOOKUP_MEM_RNG_CHK_HI] - avm_mem.rng_chk_sel {avm_mem.diff_hi} in sel_rng_8 {clk}; + mem.sel_rng_chk {mem.diff_hi} in sel_rng_8 {clk}; //====== Inter-table Shift Constraints (Lookups) ============================================ // Currently only used for shift operations but can be generalised for other uses. // Lookup for 2**(ib) #[LOOKUP_POW_2_0] - avm_alu.shift_sel {avm_alu.ib, avm_alu.two_pow_s} in sel_rng_8 {clk, table_pow_2}; + alu.sel_shift_which {alu.ib, alu.two_pow_s} in sel_rng_8 {clk, table_pow_2}; // Lookup for 2**(t-ib) #[LOOKUP_POW_2_1] - avm_alu.shift_sel {avm_alu.t_sub_s_bits , avm_alu.two_pow_t_sub_s} in sel_rng_8 {clk, table_pow_2}; + alu.sel_shift_which {alu.t_sub_s_bits , alu.two_pow_t_sub_s} in sel_rng_8 {clk, table_pow_2}; //====== Inter-table Constraints (Range Checks) ============================================ // TODO: Investigate optimising these range checks. Handling non-FF elements should require less range checks. // One can increase the granularity based on the operation and tag. In the most extreme case, // a specific selector per register might be introduced. #[LOOKUP_U8_0] - avm_alu.rng_chk_lookup_selector { avm_alu.u8_r0 } in sel_rng_8 { clk }; + alu.sel_rng_chk_lookup { alu.u8_r0 } in sel_rng_8 { clk }; #[LOOKUP_U8_1] - avm_alu.rng_chk_lookup_selector { avm_alu.u8_r1 } in sel_rng_8 { clk }; + alu.sel_rng_chk_lookup { alu.u8_r1 } in sel_rng_8 { clk }; #[LOOKUP_U16_0] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r0 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r0 } in sel_rng_16 { clk }; #[LOOKUP_U16_1] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r1 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r1 } in sel_rng_16 { clk }; #[LOOKUP_U16_2] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r2 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r2 } in sel_rng_16 { clk }; #[LOOKUP_U16_3] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r3 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r3 } in sel_rng_16 { clk }; #[LOOKUP_U16_4] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r4 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r4 } in sel_rng_16 { clk }; #[LOOKUP_U16_5] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r5 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r5 } in sel_rng_16 { clk }; #[LOOKUP_U16_6] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r6 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r6 } in sel_rng_16 { clk }; #[LOOKUP_U16_7] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r7 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r7 } in sel_rng_16 { clk }; #[LOOKUP_U16_8] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r8 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r8 } in sel_rng_16 { clk }; #[LOOKUP_U16_9] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r9 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r9 } in sel_rng_16 { clk }; #[LOOKUP_U16_10] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r10 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r10 } in sel_rng_16 { clk }; #[LOOKUP_U16_11] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r11 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r11 } in sel_rng_16 { clk }; #[LOOKUP_U16_12] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r12 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r12 } in sel_rng_16 { clk }; #[LOOKUP_U16_13] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r13 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r13 } in sel_rng_16 { clk }; #[LOOKUP_U16_14] - avm_alu.rng_chk_lookup_selector {avm_alu.u16_r14 } in sel_rng_16 { clk }; + alu.sel_rng_chk_lookup { alu.u16_r14 } in sel_rng_16 { clk }; // ==== Additional row range checks for division #[LOOKUP_DIV_U16_0] - avm_alu.div_rng_chk_selector {avm_alu.div_u16_r0} in sel_rng_16 { clk }; + alu.sel_div_rng_chk { alu.div_u16_r0 } in sel_rng_16 { clk }; #[LOOKUP_DIV_U16_1] - avm_alu.div_rng_chk_selector {avm_alu.div_u16_r1 } in sel_rng_16 { clk }; + alu.sel_div_rng_chk { alu.div_u16_r1 } in sel_rng_16 { clk }; #[LOOKUP_DIV_U16_2] - avm_alu.div_rng_chk_selector {avm_alu.div_u16_r2 } in sel_rng_16 { clk }; + alu.sel_div_rng_chk { alu.div_u16_r2 } in sel_rng_16 { clk }; #[LOOKUP_DIV_U16_3] - avm_alu.div_rng_chk_selector {avm_alu.div_u16_r3 } in sel_rng_16 { clk }; + alu.sel_div_rng_chk { alu.div_u16_r3 } in sel_rng_16 { clk }; #[LOOKUP_DIV_U16_4] - avm_alu.div_rng_chk_selector {avm_alu.div_u16_r4 } in sel_rng_16 { clk }; + alu.sel_div_rng_chk { alu.div_u16_r4 } in sel_rng_16 { clk }; #[LOOKUP_DIV_U16_5] - avm_alu.div_rng_chk_selector {avm_alu.div_u16_r5 } in sel_rng_16 { clk }; + alu.sel_div_rng_chk { alu.div_u16_r5 } in sel_rng_16 { clk }; #[LOOKUP_DIV_U16_6] - avm_alu.div_rng_chk_selector {avm_alu.div_u16_r6 } in sel_rng_16 { clk }; + alu.sel_div_rng_chk { alu.div_u16_r6 } in sel_rng_16 { clk }; #[LOOKUP_DIV_U16_7] - avm_alu.div_rng_chk_selector {avm_alu.div_u16_r7 } in sel_rng_16 { clk }; + alu.sel_div_rng_chk { alu.div_u16_r7 } in sel_rng_16 { clk }; diff --git a/barretenberg/cpp/pil/avm/avm_mem.pil b/barretenberg/cpp/pil/avm/mem.pil similarity index 70% rename from barretenberg/cpp/pil/avm/avm_mem.pil rename to barretenberg/cpp/pil/avm/mem.pil index 1b2b3164866..a5aa3080f03 100644 --- a/barretenberg/cpp/pil/avm/avm_mem.pil +++ b/barretenberg/cpp/pil/avm/mem.pil @@ -1,6 +1,6 @@ -include "avm_main.pil"; +include "main.pil"; -namespace avm_mem(256); +namespace mem(256); // ========= Table MEM-TR ================= pol commit clk; pol commit tsp; // Timestamp derived form clk and sub-operation types (SUB_CLK) @@ -12,31 +12,31 @@ namespace avm_mem(256); pol commit rw; // Enum: 0 (read), 1 (write) pol commit lastAccess; // Boolean (1 when this row is the last of a given address) pol commit last; // Boolean indicating the last row of the memory trace (not execution trace) - pol commit mem_sel; // Selector for every row pertaining to the memory trace - pol commit rng_chk_sel; // Selector for row on which range-checks apply. + pol commit sel_mem; // Selector for every row pertaining to the memory trace + pol commit sel_rng_chk; // Selector for row on which range-checks apply. - pol commit r_in_tag; // Instruction memory tag ("foreign key" pointing to avm_main.r_in_tag) - pol commit w_in_tag; // Instruction memory tag ("foreign key" pointing to avm_main.w_in_tag) + pol commit r_in_tag; // Instruction memory tag ("foreign key" pointing to main.r_in_tag) + pol commit w_in_tag; // Instruction memory tag ("foreign key" pointing to main.w_in_tag) pol commit skip_check_tag; // A boolean value which relaxes the consistency check in memory // trace between tag and r_in_tag. Required for CMOV opcode. - // Indicator of the intermediate register pertaining to the memory operation (foreign key to avm_main.mem_op_XXX) - pol commit op_a; - pol commit op_b; - pol commit op_c; - pol commit op_d; + // Indicator of the intermediate register pertaining to the memory operation (foreign key to main.sel_mem_op_XXX) + pol commit sel_op_a; + pol commit sel_op_b; + pol commit sel_op_c; + pol commit sel_op_d; - // Indicator of the indirect register pertaining to the memory operation (foreign key to avm_main.ind_op_XXX) - pol commit ind_op_a; - pol commit ind_op_b; - pol commit ind_op_c; - pol commit ind_op_d; + // Indicator of the indirect register pertaining to the memory operation (foreign key to main.sel_resolve_ind_addr_XXX) + pol commit sel_resolve_ind_addr_a; + pol commit sel_resolve_ind_addr_b; + pol commit sel_resolve_ind_addr_c; + pol commit sel_resolve_ind_addr_d; // Selectors related to MOV/CMOV opcodes (copied from main trace for loading operation on intermediated register ia/ib) // Boolean constraint is performed in main trace. - pol commit sel_mov_a; - pol commit sel_mov_b; - pol commit sel_cmov; + pol commit sel_mov_ia_to_ic; + pol commit sel_mov_ib_to_ic; + pol commit sel_op_cmov; // Error columns pol commit tag_err; // Boolean (1 if r_in_tag != tag is detected) @@ -53,38 +53,39 @@ namespace avm_mem(256); last * (1 - last) = 0; rw * (1 - rw) = 0; tag_err * (1 - tag_err) = 0; - op_a * (1 - op_a) = 0; - op_b * (1 - op_b) = 0; - op_c * (1 - op_c) = 0; - op_d * (1 - op_d) = 0; - ind_op_a * (1 - ind_op_a) = 0; - ind_op_b * (1 - ind_op_b) = 0; - ind_op_c * (1 - ind_op_c) = 0; - ind_op_d * (1 - ind_op_d) = 0; + sel_op_a * (1 - sel_op_a) = 0; + sel_op_b * (1 - sel_op_b) = 0; + sel_op_c * (1 - sel_op_c) = 0; + sel_op_d * (1 - sel_op_d) = 0; + sel_resolve_ind_addr_a * (1 - sel_resolve_ind_addr_a) = 0; + sel_resolve_ind_addr_b * (1 - sel_resolve_ind_addr_b) = 0; + sel_resolve_ind_addr_c * (1 - sel_resolve_ind_addr_c) = 0; + sel_resolve_ind_addr_d * (1 - sel_resolve_ind_addr_d) = 0; // TODO: 1) Ensure that addr is constrained to be 32 bits by the main trace and/or bytecode decomposition // 2) Ensure that tag, r_in_tag, w_in_tag are properly constrained by the main trace and/or bytecode decomposition - // Definition of mem_sel - mem_sel = op_a + op_b + op_c + op_d + ind_op_a + ind_op_b + ind_op_c + ind_op_d; + // Definition of sel_mem + sel_mem = sel_op_a + sel_op_b + sel_op_c + sel_op_d + + sel_resolve_ind_addr_a + sel_resolve_ind_addr_b + sel_resolve_ind_addr_c + sel_resolve_ind_addr_d; // Maximum one memory operation enabled per row - mem_sel * (mem_sel - 1) = 0; // TODO: might be infered by the main trace + sel_mem * (sel_mem - 1) = 0; // TODO: might be infered by the main trace // Enforce the memory entries to be contiguous, i.e., as soon as - // mem_sel is disabled all subsequent rows have mem_sel disabled. + // sel_mem is disabled all subsequent rows have sel_mem disabled. #[MEM_CONTIGUOUS] - (1 - avm_main.first) * mem_sel' * (1 - mem_sel) = 0; + (1 - main.sel_first) * sel_mem' * (1 - sel_mem) = 0; // Memory trace rows cannot start at first row #[MEM_FIRST_EMPTY] - avm_main.first * mem_sel = 0; + main.sel_first * sel_mem = 0; - // Definition of last, i.e., last row with mem_sel activated + // Definition of last, i.e., last row with sel_mem activated #[MEM_LAST] - (1 - last) * mem_sel * (1 - mem_sel') = 0; + (1 - last) * sel_mem * (1 - sel_mem') = 0; - // Definition of rng_chk_sel. It is a boolean as mem_sel and last are booleans. - rng_chk_sel = mem_sel * (1 - last); + // Definition of sel_rng_chk. It is a boolean as sel_mem and last are booleans. + sel_rng_chk = sel_mem * (1 - last); // sub_clk derivation // Current sub_clk range is [0,12) which is subdivided as follows: @@ -94,9 +95,9 @@ namespace avm_mem(256); // Each sub-range of 4 values correspond to registers ordered as a, b, c, d. pol NUM_SUB_CLK = 12; - pol IND_OP = ind_op_a + ind_op_b + ind_op_c + ind_op_d; - pol SUB_CLK = mem_sel * (ind_op_b + op_b + 2 * (ind_op_c + op_c) + 3 * (ind_op_d + op_d) + 4 * (1 - IND_OP + rw)); - // We need the mem_sel factor as the right factor is not zero when all columns are zero. + pol IND_OP = sel_resolve_ind_addr_a + sel_resolve_ind_addr_b + sel_resolve_ind_addr_c + sel_resolve_ind_addr_d; + pol SUB_CLK = sel_mem * (sel_resolve_ind_addr_b + sel_op_b + 2 * (sel_resolve_ind_addr_c + sel_op_c) + 3 * (sel_resolve_ind_addr_d + sel_op_d) + 4 * (1 - IND_OP + rw)); + // We need the sel_mem factor as the right factor is not zero when all columns are zero. #[TIMESTAMP] tsp = NUM_SUB_CLK * clk + SUB_CLK; @@ -105,13 +106,13 @@ namespace avm_mem(256); glob_addr = space_id * 2**32 + addr; #[LAST_ACCESS_FIRST_ROW] - avm_main.first * (1 - lastAccess) = 0; + main.sel_first * (1 - lastAccess) = 0; // Remark: lastAccess == 1 on first row and therefore any relation with the - // multiplicative term (1 - lastAccess) implicitly includes (1 - avm_main.first) + // multiplicative term (1 - lastAccess) implicitly includes (1 - main.sel_first) // Similarly, this includes (1 - last) as well. // lastAccess == 0 ==> glob_addr' == glob_addr - // Optimization: We removed the term (1 - avm_main.first) + // Optimization: We removed the term (1 - main.sel_first) #[MEM_LAST_ACCESS_DELIMITER] (1 - lastAccess) * (glob_addr' - glob_addr) = 0; @@ -120,8 +121,8 @@ namespace avm_mem(256); // This condition does not apply on the last row. // In addition, we need glob_addr' == glob_addr ==> tsp' > tsp - // For all rows pertaining to the memory trace (mem_sel == 1) except the last one, - // i.e., when rng_chk_sel == 1, we compute the difference: + // For all rows pertaining to the memory trace (sel_mem == 1) except the last one, + // i.e., when sel_rng_chk == 1, we compute the difference: // 1) glob_addr' - glob_addr if lastAccess == 1 // 2) tsp' - tsp if lastAccess == 0 (i.e., whenever glob_addr' == glob_addr) pol DIFF = lastAccess * (glob_addr' - glob_addr) + (1 - lastAccess) * (tsp' - tsp); @@ -131,19 +132,19 @@ namespace avm_mem(256); // Therefore, we ensure proper grouping of each global address and each memory access pertaining to a given // global address is sorted according the arrow of time. #[DIFF_RNG_CHK_DEC] - rng_chk_sel * (DIFF - diff_hi * 2**32 - diff_mid * 2**16 - diff_lo) = 0; + sel_rng_chk * (DIFF - diff_hi * 2**32 - diff_mid * 2**16 - diff_lo) = 0; // lastAccess == 0 && rw' == 0 ==> val == val' // This condition does not apply on the last row. // Note: in barretenberg, a shifted polynomial will be 0 on the last row (shift is not cyclic) // Note2: in barretenberg, if a poynomial is shifted, its non-shifted equivalent must be 0 on the first row - // Optimization: We removed the term (1 - avm_main.first) and (1 - last) + // Optimization: We removed the term (1 - main.sel_first) and (1 - last) #[MEM_READ_WRITE_VAL_CONSISTENCY] (1 - lastAccess) * (1 - rw') * (val' - val) = 0; // lastAccess == 0 && rw' == 0 ==> tag == tag' - // Optimization: We removed the term (1 - avm_main.first) and (1 - last) + // Optimization: We removed the term (1 - main.sel_first) and (1 - last) #[MEM_READ_WRITE_TAG_CONSISTENCY] (1 - lastAccess) * (1 - rw') * (tag' - tag) = 0; @@ -155,7 +156,7 @@ namespace avm_mem(256); // Skip check tag #[SKIP_CHECK_TAG] - skip_check_tag = sel_cmov * (op_d + op_a * (1-sel_mov_a) + op_b * (1-sel_mov_b)); + skip_check_tag = sel_op_cmov * (sel_op_d + sel_op_a * (1-sel_mov_ia_to_ic) + sel_op_b * (1-sel_mov_ib_to_ic)); // Memory tag consistency check for load operations, i.e., rw == 0. // We want to prove that r_in_tag == tag <==> tag_err == 0 @@ -191,16 +192,16 @@ namespace avm_mem(256); //====== Indirect Memory Constraints ===================================== // Enforce r_in_tag == 3, i.e., r_in_tag must be U32 - ind_op_a * (r_in_tag - 3) = 0; - ind_op_b * (r_in_tag - 3) = 0; - ind_op_c * (r_in_tag - 3) = 0; - ind_op_d * (r_in_tag - 3) = 0; + sel_resolve_ind_addr_a * (r_in_tag - 3) = 0; + sel_resolve_ind_addr_b * (r_in_tag - 3) = 0; + sel_resolve_ind_addr_c * (r_in_tag - 3) = 0; + sel_resolve_ind_addr_d * (r_in_tag - 3) = 0; // Indirect operation is always a load - ind_op_a * rw = 0; - ind_op_b * rw = 0; - ind_op_c * rw = 0; - ind_op_d * rw = 0; + sel_resolve_ind_addr_a * rw = 0; + sel_resolve_ind_addr_b * rw = 0; + sel_resolve_ind_addr_c * rw = 0; + sel_resolve_ind_addr_d * rw = 0; //====== MOV/CMOV Opcode Tag Constraint ===================================== // The following constraint ensures that the r_in_tag is set to tag for @@ -210,4 +211,4 @@ namespace avm_mem(256); // Constraint #[MOV_MAIN_SAME_TAG] copies r_in_tag to w_in_tag in the main // trace. Then, #[PERM_MAIN_MEM_C] copies w_in_tag for store operation from Ic. #[MOV_SAME_TAG] - (sel_mov_a + sel_mov_b) * tag_err = 0; // Equivalent to (sel_mov_a + sel_mov_b) * (r_in_tag - tag) = 0 \ No newline at end of file + (sel_mov_ia_to_ic + sel_mov_ib_to_ic) * tag_err = 0; // Equivalent to (sel_mov_ia_to_ic + sel_mov_ib_to_ic) * (r_in_tag - tag) = 0 \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 55a938fe44d..d62b3326310 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -446,15 +446,25 @@ void gateCount(const std::string& bytecodePath, bool honk_recursion) size_t i = 0; for (auto constraint_system : constraint_systems) { acir_proofs::AcirComposer acir_composer(0, verbose_logging); - acir_composer.create_circuit(constraint_system); + acir_composer.create_circuit(constraint_system, {}, true); auto circuit_size = acir_composer.get_total_circuit_size(); // Build individual circuit report + std::string gates_per_opcode_str; + for (size_t j = 0; j < constraint_system.gates_per_opcode.size(); j++) { + gates_per_opcode_str += std::to_string(constraint_system.gates_per_opcode[j]); + if (j != constraint_system.gates_per_opcode.size() - 1) { + gates_per_opcode_str += ","; + } + } + auto result_string = format("{\n \"acir_opcodes\": ", constraint_system.num_acir_opcodes, ",\n \"circuit_size\": ", circuit_size, - "\n }"); + ",\n \"gates_per_opcode\": [", + gates_per_opcode_str, + "]\n }"); // Attach a comma if we still circuit reports to generate if (i != (constraint_systems.size() - 1)) { diff --git a/barretenberg/cpp/src/barretenberg/circuit_checker/ultra_circuit_checker.cpp b/barretenberg/cpp/src/barretenberg/circuit_checker/ultra_circuit_checker.cpp index 55e7d3f44a1..1ad994064a0 100644 --- a/barretenberg/cpp/src/barretenberg/circuit_checker/ultra_circuit_checker.cpp +++ b/barretenberg/cpp/src/barretenberg/circuit_checker/ultra_circuit_checker.cpp @@ -25,7 +25,7 @@ template bool UltraCircuitChecker::check(const Builder& build LookupHashTable lookup_hash_table; for (const auto& table : builder.lookup_tables) { const FF table_index(table.table_index); - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table.size(); ++i) { lookup_hash_table.insert({ table.column_1[i], table.column_2[i], table.column_3[i], table_index }); } } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp index bee50d76742..bcfcce6776f 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -1,5 +1,6 @@ #include "acir_format.hpp" #include "barretenberg/common/log.hpp" +#include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/stdlib/primitives/field/field_conversion.hpp" #include "barretenberg/stdlib_circuit_builders/mega_circuit_builder.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" @@ -14,114 +15,215 @@ template class DSLBigInts; template void build_constraints(Builder& builder, - AcirFormat const& constraint_system, + AcirFormat& constraint_system, bool has_valid_witness_assignments, - bool honk_recursion) + bool honk_recursion, + bool collect_gates_per_opcode) { + if (collect_gates_per_opcode) { + constraint_system.gates_per_opcode.resize(constraint_system.num_acir_opcodes, 0); + } + size_t prev_gate_count = 0; + + auto compute_gate_diff = [&]() -> size_t { + if (!collect_gates_per_opcode) { + return 0; + } + size_t new_gate_count = builder.get_num_gates(); + size_t diff = new_gate_count - prev_gate_count; + prev_gate_count = new_gate_count; + return diff; + }; + + auto track_gate_diff = [&](std::vector& gates_per_opcode, size_t opcode_index) -> void { + if (collect_gates_per_opcode) { + gates_per_opcode[opcode_index] = compute_gate_diff(); + } + }; + // Add arithmetic gates - for (const auto& constraint : constraint_system.poly_triple_constraints) { + for (size_t i = 0; i < constraint_system.poly_triple_constraints.size(); ++i) { + const auto& constraint = constraint_system.poly_triple_constraints.at(i); builder.create_poly_gate(constraint); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.poly_triple_constraints.at(i)); } - for (const auto& constraint : constraint_system.quad_constraints) { + + for (size_t i = 0; i < constraint_system.quad_constraints.size(); ++i) { + const auto& constraint = constraint_system.quad_constraints.at(i); builder.create_big_mul_gate(constraint); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.quad_constraints.at(i)); } // Add logic constraint - for (const auto& constraint : constraint_system.logic_constraints) { + for (size_t i = 0; i < constraint_system.logic_constraints.size(); ++i) { + const auto& constraint = constraint_system.logic_constraints.at(i); create_logic_gate( builder, constraint.a, constraint.b, constraint.result, constraint.num_bits, constraint.is_xor_gate); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.logic_constraints.at(i)); } // Add range constraint - for (const auto& constraint : constraint_system.range_constraints) { + for (size_t i = 0; i < constraint_system.range_constraints.size(); ++i) { + const auto& constraint = constraint_system.range_constraints.at(i); builder.create_range_constraint(constraint.witness, constraint.num_bits, ""); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.range_constraints.at(i)); } // Add aes128 constraints - for (const auto& constraint : constraint_system.aes128_constraints) { + for (size_t i = 0; i < constraint_system.aes128_constraints.size(); ++i) { + const auto& constraint = constraint_system.aes128_constraints.at(i); create_aes128_constraints(builder, constraint); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.aes128_constraints.at(i)); } // Add sha256 constraints - for (const auto& constraint : constraint_system.sha256_constraints) { + for (size_t i = 0; i < constraint_system.sha256_constraints.size(); ++i) { + const auto& constraint = constraint_system.sha256_constraints.at(i); create_sha256_constraints(builder, constraint); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.sha256_constraints.at(i)); } - for (const auto& constraint : constraint_system.sha256_compression) { + + for (size_t i = 0; i < constraint_system.sha256_compression.size(); ++i) { + const auto& constraint = constraint_system.sha256_compression[i]; create_sha256_compression_constraints(builder, constraint); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.sha256_compression[i]); } // Add schnorr constraints - for (const auto& constraint : constraint_system.schnorr_constraints) { + for (size_t i = 0; i < constraint_system.schnorr_constraints.size(); ++i) { + const auto& constraint = constraint_system.schnorr_constraints.at(i); create_schnorr_verify_constraints(builder, constraint); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.schnorr_constraints.at(i)); } // Add ECDSA k1 constraints - for (const auto& constraint : constraint_system.ecdsa_k1_constraints) { + for (size_t i = 0; i < constraint_system.ecdsa_k1_constraints.size(); ++i) { + const auto& constraint = constraint_system.ecdsa_k1_constraints.at(i); create_ecdsa_k1_verify_constraints(builder, constraint, has_valid_witness_assignments); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.ecdsa_k1_constraints.at(i)); } // Add ECDSA r1 constraints - for (const auto& constraint : constraint_system.ecdsa_r1_constraints) { + for (size_t i = 0; i < constraint_system.ecdsa_r1_constraints.size(); ++i) { + const auto& constraint = constraint_system.ecdsa_r1_constraints.at(i); create_ecdsa_r1_verify_constraints(builder, constraint, has_valid_witness_assignments); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.ecdsa_r1_constraints.at(i)); } // Add blake2s constraints - for (const auto& constraint : constraint_system.blake2s_constraints) { + for (size_t i = 0; i < constraint_system.blake2s_constraints.size(); ++i) { + const auto& constraint = constraint_system.blake2s_constraints.at(i); create_blake2s_constraints(builder, constraint); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.blake2s_constraints.at(i)); } // Add blake3 constraints - for (const auto& constraint : constraint_system.blake3_constraints) { + for (size_t i = 0; i < constraint_system.blake3_constraints.size(); ++i) { + const auto& constraint = constraint_system.blake3_constraints.at(i); create_blake3_constraints(builder, constraint); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.blake3_constraints.at(i)); } // Add keccak constraints - for (const auto& constraint : constraint_system.keccak_constraints) { + for (size_t i = 0; i < constraint_system.keccak_constraints.size(); ++i) { + const auto& constraint = constraint_system.keccak_constraints.at(i); create_keccak_constraints(builder, constraint); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.keccak_constraints.at(i)); } - for (const auto& constraint : constraint_system.keccak_permutations) { + + for (size_t i = 0; i < constraint_system.keccak_permutations.size(); ++i) { + const auto& constraint = constraint_system.keccak_permutations[i]; create_keccak_permutations(builder, constraint); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.keccak_permutations[i]); } // Add pedersen constraints - for (const auto& constraint : constraint_system.pedersen_constraints) { + for (size_t i = 0; i < constraint_system.pedersen_constraints.size(); ++i) { + const auto& constraint = constraint_system.pedersen_constraints.at(i); create_pedersen_constraint(builder, constraint); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.pedersen_constraints.at(i)); } - for (const auto& constraint : constraint_system.pedersen_hash_constraints) { + for (size_t i = 0; i < constraint_system.pedersen_hash_constraints.size(); ++i) { + const auto& constraint = constraint_system.pedersen_hash_constraints.at(i); create_pedersen_hash_constraint(builder, constraint); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.pedersen_hash_constraints.at(i)); } - for (const auto& constraint : constraint_system.poseidon2_constraints) { + for (size_t i = 0; i < constraint_system.poseidon2_constraints.size(); ++i) { + const auto& constraint = constraint_system.poseidon2_constraints.at(i); create_poseidon2_permutations(builder, constraint); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.poseidon2_constraints.at(i)); } // Add multi scalar mul constraints - for (const auto& constraint : constraint_system.multi_scalar_mul_constraints) { + for (size_t i = 0; i < constraint_system.multi_scalar_mul_constraints.size(); ++i) { + const auto& constraint = constraint_system.multi_scalar_mul_constraints.at(i); create_multi_scalar_mul_constraint(builder, constraint); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.multi_scalar_mul_constraints.at(i)); } // Add ec add constraints - for (const auto& constraint : constraint_system.ec_add_constraints) { + for (size_t i = 0; i < constraint_system.ec_add_constraints.size(); ++i) { + const auto& constraint = constraint_system.ec_add_constraints.at(i); create_ec_add_constraint(builder, constraint, has_valid_witness_assignments); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.ec_add_constraints.at(i)); } // Add block constraints - for (const auto& constraint : constraint_system.block_constraints) { + for (size_t i = 0; i < constraint_system.block_constraints.size(); ++i) { + const auto& constraint = constraint_system.block_constraints.at(i); create_block_constraints(builder, constraint, has_valid_witness_assignments); + if (collect_gates_per_opcode) { + size_t avg_gates_per_opcode = + compute_gate_diff() / constraint_system.original_opcode_indices.block_constraints.at(i).size(); + for (size_t opcode_index : constraint_system.original_opcode_indices.block_constraints.at(i)) { + constraint_system.gates_per_opcode[opcode_index] = avg_gates_per_opcode; + } + } } // Add big_int constraints DSLBigInts dsl_bigints; dsl_bigints.set_builder(&builder); - for (const auto& constraint : constraint_system.bigint_from_le_bytes_constraints) { + for (size_t i = 0; i < constraint_system.bigint_from_le_bytes_constraints.size(); ++i) { + const auto& constraint = constraint_system.bigint_from_le_bytes_constraints.at(i); create_bigint_from_le_bytes_constraint(builder, constraint, dsl_bigints); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.bigint_from_le_bytes_constraints.at(i)); } - for (const auto& constraint : constraint_system.bigint_operations) { + + for (size_t i = 0; i < constraint_system.bigint_operations.size(); ++i) { + const auto& constraint = constraint_system.bigint_operations[i]; create_bigint_operations_constraint(constraint, dsl_bigints, has_valid_witness_assignments); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.bigint_operations[i]); } - for (const auto& constraint : constraint_system.bigint_to_le_bytes_constraints) { + + for (size_t i = 0; i < constraint_system.bigint_to_le_bytes_constraints.size(); ++i) { + const auto& constraint = constraint_system.bigint_to_le_bytes_constraints.at(i); create_bigint_to_le_bytes_constraint(builder, constraint, dsl_bigints); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.bigint_to_le_bytes_constraints.at(i)); } // RecursionConstraint @@ -152,7 +254,9 @@ void build_constraints(Builder& builder, auto proof_size_no_pub_inputs = recursion_proof_size_without_public_inputs(); // Add recursion constraints - for (auto constraint : constraint_system.recursion_constraints) { + for (size_t constraint_idx = 0; constraint_idx < constraint_system.recursion_constraints.size(); + ++constraint_idx) { + auto constraint = constraint_system.recursion_constraints[constraint_idx]; // A proof passed into the constraint should be stripped of its public inputs, except in the case where a // proof contains an aggregation object itself. We refer to this as the `nested_aggregation_object`. The // verifier circuit requires that the indices to a nested proof aggregation state are a circuit constant. @@ -187,12 +291,15 @@ void build_constraints(Builder& builder, constraint.proof.begin() + static_cast(RecursionConstraint::AGGREGATION_OBJECT_SIZE)); } + current_output_aggregation_object = create_recursion_constraints(builder, constraint, current_input_aggregation_object, nested_aggregation_object, has_valid_witness_assignments); current_input_aggregation_object = current_output_aggregation_object; + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.recursion_constraints[constraint_idx]); } // Now that the circuit has been completely built, we add the output aggregation as public @@ -232,11 +339,13 @@ void build_constraints(Builder& builder, }; // Add recursion constraints - for (auto constraint : constraint_system.honk_recursion_constraints) { - // A proof passed into the constraint should be stripped of its inner public inputs, but not the nested - // aggregation object itself. The verifier circuit requires that the indices to a nested proof aggregation - // state are a circuit constant. The user tells us they how they want these constants set by keeping the - // nested aggregation object attached to the proof as public inputs. + + for (size_t i = 0; i < constraint_system.honk_recursion_constraints.size(); ++i) { + auto constraint = constraint_system.honk_recursion_constraints.at(i); + // A proof passed into the constraint should be stripped of its inner public inputs, but not the + // nested aggregation object itself. The verifier circuit requires that the indices to a nested + // proof aggregation state are a circuit constant. The user tells us they how they want these + // constants set by keeping the nested aggregation object attached to the proof as public inputs. std::array nested_aggregation_object = {}; for (size_t i = 0; i < HonkRecursionConstraint::AGGREGATION_OBJECT_SIZE; ++i) { // Set the nested aggregation object indices to witness indices from the proof @@ -256,6 +365,8 @@ void build_constraints(Builder& builder, current_aggregation_object, nested_aggregation_object, has_valid_witness_assignments); + track_gate_diff(constraint_system.gates_per_opcode, + constraint_system.original_opcode_indices.honk_recursion_constraints.at(i)); } // Now that the circuit has been completely built, we add the output aggregation as public @@ -319,18 +430,20 @@ void build_constraints(Builder& builder, * @return Builder */ template <> -UltraCircuitBuilder create_circuit(const AcirFormat& constraint_system, +UltraCircuitBuilder create_circuit(AcirFormat& constraint_system, size_t size_hint, WitnessVector const& witness, bool honk_recursion, - [[maybe_unused]] std::shared_ptr) + [[maybe_unused]] std::shared_ptr, + bool collect_gates_per_opcode) { Builder builder{ size_hint, witness, constraint_system.public_inputs, constraint_system.varnum, constraint_system.recursive }; bool has_valid_witness_assignments = !witness.empty(); - build_constraints(builder, constraint_system, has_valid_witness_assignments, honk_recursion); + build_constraints( + builder, constraint_system, has_valid_witness_assignments, honk_recursion, collect_gates_per_opcode); return builder; }; @@ -345,22 +458,24 @@ UltraCircuitBuilder create_circuit(const AcirFormat& constraint_system, * @return Builder */ template <> -MegaCircuitBuilder create_circuit(const AcirFormat& constraint_system, +MegaCircuitBuilder create_circuit(AcirFormat& constraint_system, [[maybe_unused]] size_t size_hint, WitnessVector const& witness, bool honk_recursion, - std::shared_ptr op_queue) + std::shared_ptr op_queue, + bool collect_gates_per_opcode) { // Construct a builder using the witness and public input data from acir and with the goblin-owned op_queue auto builder = MegaCircuitBuilder{ op_queue, witness, constraint_system.public_inputs, constraint_system.varnum }; // Populate constraints in the builder via the data in constraint_system bool has_valid_witness_assignments = !witness.empty(); - acir_format::build_constraints(builder, constraint_system, has_valid_witness_assignments, honk_recursion); + acir_format::build_constraints( + builder, constraint_system, has_valid_witness_assignments, honk_recursion, collect_gates_per_opcode); return builder; }; -template void build_constraints(MegaCircuitBuilder&, AcirFormat const&, bool, bool); +template void build_constraints(MegaCircuitBuilder&, AcirFormat&, bool, bool, bool); } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp index 493cfe84061..80edf92270b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp @@ -24,6 +24,44 @@ namespace acir_format { +/** + * @brief Indices of the original opcode that originated each constraint in AcirFormat. + * @details Contains one array of indices per opcode type. The length of each array is equal to the number of + * constraints of that type. The relationship between the opcodes and constraints is assumed to be one to one, except + * for block constraints. + */ +struct AcirFormatOriginalOpcodeIndices { + std::vector logic_constraints; + std::vector range_constraints; + std::vector aes128_constraints; + std::vector sha256_constraints; + std::vector sha256_compression; + std::vector schnorr_constraints; + std::vector ecdsa_k1_constraints; + std::vector ecdsa_r1_constraints; + std::vector blake2s_constraints; + std::vector blake3_constraints; + std::vector keccak_constraints; + std::vector keccak_permutations; + std::vector pedersen_constraints; + std::vector pedersen_hash_constraints; + std::vector poseidon2_constraints; + std::vector multi_scalar_mul_constraints; + std::vector ec_add_constraints; + std::vector recursion_constraints; + std::vector honk_recursion_constraints; + std::vector bigint_from_le_bytes_constraints; + std::vector bigint_to_le_bytes_constraints; + std::vector bigint_operations; + std::vector poly_triple_constraints; + std::vector quad_constraints; + // Multiple opcode indices per block: + std::vector> block_constraints; + + friend bool operator==(AcirFormatOriginalOpcodeIndices const& lhs, + AcirFormatOriginalOpcodeIndices const& rhs) = default; +}; + struct AcirFormat { // The number of witnesses in the circuit uint32_t varnum; @@ -72,6 +110,13 @@ struct AcirFormat { quad_constraints; std::vector block_constraints; + // Number of gates added to the circuit per original opcode. + // Has length equal to num_acir_opcodes. + std::vector gates_per_opcode = {}; + + // Indices of the original opcode that originated each constraint in AcirFormat. + AcirFormatOriginalOpcodeIndices original_opcode_indices; + // For serialization, update with any new fields MSGPACK_FIELDS(varnum, public_inputs, @@ -142,18 +187,21 @@ struct AcirProgramStack { }; template -Builder create_circuit(const AcirFormat& constraint_system, +Builder create_circuit(AcirFormat& constraint_system, size_t size_hint = 0, WitnessVector const& witness = {}, bool honk_recursion = false, - std::shared_ptr op_queue = std::make_shared()); + std::shared_ptr op_queue = std::make_shared(), + bool collect_gates_per_opcode = false); template -void build_constraints(Builder& builder, - AcirFormat const& constraint_system, - bool has_valid_witness_assignments, - bool honk_recursion = false); // honk_recursion means we will honk to recursively verify this - // circuit. This distinction is needed to not add the default - // aggregation object when we're not using the honk RV. +void build_constraints( + Builder& builder, + AcirFormat& constraint_system, + bool has_valid_witness_assignments, + bool honk_recursion = false, + bool collect_gates_per_opcode = false); // honk_recursion means we will honk to recursively verify this + // circuit. This distinction is needed to not add the default + // aggregation object when we're not using the honk RV. } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp index 0d1ef31040f..6085671fb0a 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp @@ -1,13 +1,16 @@ #include +#include #include #include "acir_format.hpp" +#include "acir_format_mocks.hpp" #include "barretenberg/common/streams.hpp" #include "barretenberg/crypto/schnorr/schnorr.hpp" #include "barretenberg/plonk/composer/standard_composer.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/serialize/test_helper.hpp" +#include "barretenberg/stdlib_circuit_builders/op_queue/ecc_op_queue.hpp" #include "ecdsa_secp256k1.hpp" using namespace bb; @@ -64,8 +67,9 @@ TEST_F(AcirFormatTests, TestASingleConstraintNoPubInputs) .poly_triple_constraints = { constraint }, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; - + mock_opcode_indices(constraint_system); WitnessVector witness{ 0, 0, 1 }; auto builder = create_circuit(constraint_system, /*size_hint*/ 0, witness); @@ -154,35 +158,39 @@ TEST_F(AcirFormatTests, TestLogicGateFromNoirCircuit) // EXPR [ (1, _4, _6) (-1, _4) 0 ] // EXPR [ (-1, _6) 1 ] - AcirFormat constraint_system{ .varnum = 6, - .recursive = false, - .num_acir_opcodes = 7, - .public_inputs = { 1 }, - .logic_constraints = { logic_constraint }, - .range_constraints = { range_a, range_b }, - .aes128_constraints = {}, - .sha256_constraints = {}, - .sha256_compression = {}, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_permutations = {}, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .poseidon2_constraints = {}, - .multi_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .recursion_constraints = {}, - .honk_recursion_constraints = {}, - .bigint_from_le_bytes_constraints = {}, - .bigint_to_le_bytes_constraints = {}, - .bigint_operations = {}, - .poly_triple_constraints = { expr_a, expr_b, expr_c, expr_d }, - .quad_constraints = {}, - .block_constraints = {} }; + AcirFormat constraint_system{ + .varnum = 6, + .recursive = false, + .num_acir_opcodes = 7, + .public_inputs = { 1 }, + .logic_constraints = { logic_constraint }, + .range_constraints = { range_a, range_b }, + .aes128_constraints = {}, + .sha256_constraints = {}, + .sha256_compression = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .poseidon2_constraints = {}, + .multi_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .recursion_constraints = {}, + .honk_recursion_constraints = {}, + .bigint_from_le_bytes_constraints = {}, + .bigint_to_le_bytes_constraints = {}, + .bigint_operations = {}, + .poly_triple_constraints = { expr_a, expr_b, expr_c, expr_d }, + .quad_constraints = {}, + .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), + }; + mock_opcode_indices(constraint_system); uint256_t inverse_of_five = fr(5).invert(); WitnessVector witness{ @@ -202,11 +210,14 @@ TEST_F(AcirFormatTests, TestLogicGateFromNoirCircuit) TEST_F(AcirFormatTests, TestSchnorrVerifyPass) { std::vector range_constraints; + std::vector range_opcode_indices; + size_t current_opcode = 0; for (uint32_t i = 0; i < 10; i++) { range_constraints.push_back(RangeConstraint{ .witness = i, .num_bits = 15, }); + range_opcode_indices.push_back(current_opcode++); } std::array signature; @@ -216,6 +227,7 @@ TEST_F(AcirFormatTests, TestSchnorrVerifyPass) .witness = value, .num_bits = 15, }); + range_opcode_indices.push_back(current_opcode++); } SchnorrConstraint schnorr_constraint{ @@ -225,44 +237,48 @@ TEST_F(AcirFormatTests, TestSchnorrVerifyPass) .result = 76, .signature = signature, }; - AcirFormat constraint_system{ .varnum = 81, - .recursive = false, - .num_acir_opcodes = 75, - .public_inputs = {}, - .logic_constraints = {}, - .range_constraints = range_constraints, - .aes128_constraints = {}, - .sha256_constraints = {}, - .sha256_compression = {}, - .schnorr_constraints = { schnorr_constraint }, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_permutations = {}, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .poseidon2_constraints = {}, - .multi_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .recursion_constraints = {}, - .honk_recursion_constraints = {}, - .bigint_from_le_bytes_constraints = {}, - .bigint_to_le_bytes_constraints = {}, - .bigint_operations = {}, - .poly_triple_constraints = { poly_triple{ - .a = schnorr_constraint.result, - .b = schnorr_constraint.result, - .c = schnorr_constraint.result, - .q_m = 0, - .q_l = 0, - .q_r = 0, - .q_o = 1, - .q_c = fr::neg_one(), - } }, - .quad_constraints = {}, - .block_constraints = {} }; + AcirFormat constraint_system{ + .varnum = 81, + .recursive = false, + .num_acir_opcodes = 76, + .public_inputs = {}, + .logic_constraints = {}, + .range_constraints = range_constraints, + .aes128_constraints = {}, + .sha256_constraints = {}, + .sha256_compression = {}, + .schnorr_constraints = { schnorr_constraint }, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .poseidon2_constraints = {}, + .multi_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .recursion_constraints = {}, + .honk_recursion_constraints = {}, + .bigint_from_le_bytes_constraints = {}, + .bigint_to_le_bytes_constraints = {}, + .bigint_operations = {}, + .poly_triple_constraints = { poly_triple{ + .a = schnorr_constraint.result, + .b = schnorr_constraint.result, + .c = schnorr_constraint.result, + .q_m = 0, + .q_l = 0, + .q_r = 0, + .q_o = 1, + .q_c = fr::neg_one(), + } }, + .quad_constraints = {}, + .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), + }; + mock_opcode_indices(constraint_system); std::string message_string = "tenletters"; schnorr_key_pair account; @@ -299,11 +315,15 @@ TEST_F(AcirFormatTests, TestSchnorrVerifyPass) TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange) { std::vector range_constraints; + std::vector range_opcode_indices; + size_t current_opcode = 0; + for (uint32_t i = 0; i < 10; i++) { range_constraints.push_back(RangeConstraint{ .witness = i, .num_bits = 8, }); + range_opcode_indices.push_back(current_opcode++); } std::array signature; @@ -313,6 +333,7 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange) .witness = value, .num_bits = 8, }); + range_opcode_indices.push_back(current_opcode++); } SchnorrConstraint schnorr_constraint{ @@ -325,7 +346,7 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange) AcirFormat constraint_system{ .varnum = 81, .recursive = false, - .num_acir_opcodes = 75, + .num_acir_opcodes = 76, .public_inputs = {}, .logic_constraints = {}, .range_constraints = range_constraints, @@ -361,7 +382,9 @@ TEST_F(AcirFormatTests, TestSchnorrVerifySmallRange) } }, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); std::string message_string = "tenletters"; schnorr_key_pair account; @@ -469,7 +492,9 @@ TEST_F(AcirFormatTests, TestVarKeccak) .poly_triple_constraints = { dummy }, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); WitnessVector witness{ 4, 2, 6, 2 }; auto builder = create_circuit(constraint_system, /*size_hint*/ 0, witness); @@ -490,35 +515,39 @@ TEST_F(AcirFormatTests, TestKeccakPermutation) 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50 }, }; - AcirFormat constraint_system{ .varnum = 51, - .recursive = false, - .num_acir_opcodes = 1, - .public_inputs = {}, - .logic_constraints = {}, - .range_constraints = {}, - .aes128_constraints = {}, - .sha256_constraints = {}, - .sha256_compression = {}, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_permutations = { keccak_permutation }, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .poseidon2_constraints = {}, - .multi_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .recursion_constraints = {}, - .honk_recursion_constraints = {}, - .bigint_from_le_bytes_constraints = {}, - .bigint_to_le_bytes_constraints = {}, - .bigint_operations = {}, - .poly_triple_constraints = {}, - .quad_constraints = {}, - .block_constraints = {} }; + AcirFormat constraint_system{ + .varnum = 51, + .recursive = false, + .num_acir_opcodes = 1, + .public_inputs = {}, + .logic_constraints = {}, + .range_constraints = {}, + .aes128_constraints = {}, + .sha256_constraints = {}, + .sha256_compression = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_permutations = { keccak_permutation }, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .poseidon2_constraints = {}, + .multi_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .recursion_constraints = {}, + .honk_recursion_constraints = {}, + .bigint_from_le_bytes_constraints = {}, + .bigint_to_le_bytes_constraints = {}, + .bigint_operations = {}, + .poly_triple_constraints = {}, + .quad_constraints = {}, + .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), + }; + mock_opcode_indices(constraint_system); WitnessVector witness{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, @@ -534,3 +563,70 @@ TEST_F(AcirFormatTests, TestKeccakPermutation) EXPECT_EQ(verifier.verify_proof(proof), true); } + +TEST_F(AcirFormatTests, TestCollectsGateCounts) +{ + + // Witness 0 + witness 1 = witness 2 + poly_triple first_gate{ + .a = 0, + .b = 1, + .c = 2, + .q_m = 0, + .q_l = 1, + .q_r = 1, + .q_o = -1, + .q_c = 0, + }; + + // Witness 1 = 27 + poly_triple second_gate{ + .a = 1, + .b = 0, + .c = 0, + .q_m = 0, + .q_l = 1, + .q_r = 0, + .q_o = 0, + .q_c = -27, + }; + + AcirFormat constraint_system{ + .varnum = 4, + .recursive = false, + .num_acir_opcodes = 2, + .public_inputs = {}, + .logic_constraints = {}, + .range_constraints = {}, + .aes128_constraints = {}, + .sha256_constraints = {}, + .sha256_compression = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .poseidon2_constraints = {}, + .multi_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .recursion_constraints = {}, + .honk_recursion_constraints = {}, + .bigint_from_le_bytes_constraints = {}, + .bigint_to_le_bytes_constraints = {}, + .bigint_operations = {}, + .poly_triple_constraints = { first_gate, second_gate }, + .quad_constraints = {}, + .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), + }; + mock_opcode_indices(constraint_system); + WitnessVector witness{ 5, 27, 32 }; + auto builder = + create_circuit(constraint_system, /*size_hint*/ 0, witness, false, std::make_shared(), true); + + EXPECT_EQ(constraint_system.gates_per_opcode, std::vector({ 2, 1 })); +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format_mocks.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format_mocks.cpp new file mode 100644 index 00000000000..f53ff85d6e7 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format_mocks.cpp @@ -0,0 +1,118 @@ +#include "acir_format.hpp" + +acir_format::AcirFormatOriginalOpcodeIndices create_empty_original_opcode_indices() +{ + return acir_format::AcirFormatOriginalOpcodeIndices{ + .logic_constraints = {}, + .range_constraints = {}, + .aes128_constraints = {}, + .sha256_constraints = {}, + .sha256_compression = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .poseidon2_constraints = {}, + .multi_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .recursion_constraints = {}, + .honk_recursion_constraints = {}, + .bigint_from_le_bytes_constraints = {}, + .bigint_to_le_bytes_constraints = {}, + .bigint_operations = {}, + .poly_triple_constraints = {}, + .quad_constraints = {}, + .block_constraints = {}, + }; +} + +void mock_opcode_indices(acir_format::AcirFormat& constraint_system) +{ + size_t current_opcode = 0; + for (size_t i = 0; i < constraint_system.logic_constraints.size(); i++) { + constraint_system.original_opcode_indices.logic_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.range_constraints.size(); i++) { + constraint_system.original_opcode_indices.range_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.aes128_constraints.size(); i++) { + constraint_system.original_opcode_indices.aes128_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.sha256_constraints.size(); i++) { + constraint_system.original_opcode_indices.sha256_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.sha256_compression.size(); i++) { + constraint_system.original_opcode_indices.sha256_compression.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.schnorr_constraints.size(); i++) { + constraint_system.original_opcode_indices.schnorr_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.ecdsa_k1_constraints.size(); i++) { + constraint_system.original_opcode_indices.ecdsa_k1_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.ecdsa_r1_constraints.size(); i++) { + constraint_system.original_opcode_indices.ecdsa_r1_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.blake2s_constraints.size(); i++) { + constraint_system.original_opcode_indices.blake2s_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.blake3_constraints.size(); i++) { + constraint_system.original_opcode_indices.blake3_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.keccak_constraints.size(); i++) { + constraint_system.original_opcode_indices.keccak_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.keccak_permutations.size(); i++) { + constraint_system.original_opcode_indices.keccak_permutations.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.pedersen_constraints.size(); i++) { + constraint_system.original_opcode_indices.pedersen_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.pedersen_hash_constraints.size(); i++) { + constraint_system.original_opcode_indices.pedersen_hash_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.poseidon2_constraints.size(); i++) { + constraint_system.original_opcode_indices.poseidon2_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.multi_scalar_mul_constraints.size(); i++) { + constraint_system.original_opcode_indices.multi_scalar_mul_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.ec_add_constraints.size(); i++) { + constraint_system.original_opcode_indices.ec_add_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.recursion_constraints.size(); i++) { + constraint_system.original_opcode_indices.recursion_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.honk_recursion_constraints.size(); i++) { + constraint_system.original_opcode_indices.honk_recursion_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.bigint_from_le_bytes_constraints.size(); i++) { + constraint_system.original_opcode_indices.bigint_from_le_bytes_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.bigint_to_le_bytes_constraints.size(); i++) { + constraint_system.original_opcode_indices.bigint_to_le_bytes_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.bigint_operations.size(); i++) { + constraint_system.original_opcode_indices.bigint_operations.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.poly_triple_constraints.size(); i++) { + constraint_system.original_opcode_indices.poly_triple_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.quad_constraints.size(); i++) { + constraint_system.original_opcode_indices.quad_constraints.push_back(current_opcode++); + } + for (size_t i = 0; i < constraint_system.block_constraints.size(); i++) { + std::vector block_indices; + for (size_t j = 0; j < constraint_system.block_constraints[i].trace.size(); j++) { + block_indices.push_back(current_opcode++); + } + constraint_system.original_opcode_indices.block_constraints.push_back(block_indices); + } + + constraint_system.num_acir_opcodes = static_cast(current_opcode); +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format_mocks.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format_mocks.hpp new file mode 100644 index 00000000000..6a58c34aa0d --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format_mocks.hpp @@ -0,0 +1,5 @@ +#include "acir_format.hpp" + +acir_format::AcirFormatOriginalOpcodeIndices create_empty_original_opcode_indices(); + +void mock_opcode_indices(acir_format::AcirFormat& constraint_system); \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_integration.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_integration.test.cpp index bac815ed4ef..2842056f848 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_integration.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_integration.test.cpp @@ -36,7 +36,7 @@ class AcirIntegrationTest : public ::testing::Test { } acir_format::AcirProgramStack get_program_stack_data_from_test_file(const std::string& test_program_name, - bool honk_recursion) + bool honk_recursion = false) { std::string base_path = "../../acir_tests/acir_tests/" + test_program_name + "/target"; std::string bytecode_path = base_path + "/program.json"; @@ -45,7 +45,8 @@ class AcirIntegrationTest : public ::testing::Test { return acir_format::get_acir_program_stack(bytecode_path, witness_path, honk_recursion); } - acir_format::AcirProgram get_program_data_from_test_file(const std::string& test_program_name, bool honk_recursion) + acir_format::AcirProgram get_program_data_from_test_file(const std::string& test_program_name, + bool honk_recursion = false) { auto program_stack = get_program_stack_data_from_test_file(test_program_name, honk_recursion); ASSERT(program_stack.size() == 1); // Otherwise this method will not return full stack data @@ -428,6 +429,29 @@ INSTANTIATE_TEST_SUITE_P(AcirTests, AcirIntegrationFoldingTest, testing::Values("fold_basic", "fold_basic_nested_call")); +/** + *@brief A basic test of a circuit generated in noir that makes use of the databus + * + */ +TEST_F(AcirIntegrationTest, DISABLED_Databus) +{ + using Flavor = MegaFlavor; + using Builder = Flavor::CircuitBuilder; + + std::string test_name = "databus"; + info("Test: ", test_name); + acir_format::AcirProgram acir_program = get_program_data_from_test_file(test_name); + + // Construct a bberg circuit from the acir representation + Builder builder = acir_format::create_circuit(acir_program.constraints, 0, acir_program.witness); + + // This prints a summary of the types of gates in the circuit + builder.blocks.summarize(); + + // Construct and verify Honk proof + EXPECT_TRUE(prove_and_verify_honk(builder)); +} + /** * @brief Ensure that adding gates post-facto to a circuit generated from acir still results in a valid circuit * @details This is a pattern required by e.g. ClientIvc which appends recursive verifiers to acir-generated circuits diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp index e292766d78f..e949fa13305 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_to_constraint_buf.cpp @@ -1,5 +1,8 @@ #include "acir_to_constraint_buf.hpp" #include "barretenberg/common/container.hpp" +#include +#include +#include #ifndef __wasm__ #include "barretenberg/bb/get_bytecode.hpp" #endif @@ -164,7 +167,7 @@ mul_quad_ serialize_mul_quad_gate(Program::Expression const& arg) return quad; } -void handle_arithmetic(Program::Opcode::AssertZero const& arg, AcirFormat& af) +void handle_arithmetic(Program::Opcode::AssertZero const& arg, AcirFormat& af, size_t opcode_index) { if (arg.value.linear_combinations.size() <= 3) { poly_triple pt = serialize_arithmetic_gate(arg.value); @@ -174,15 +177,22 @@ void handle_arithmetic(Program::Opcode::AssertZero const& arg, AcirFormat& af) // gate instead. We could probably always use a width-4 gate in fact. if (pt == poly_triple{ 0, 0, 0, 0, 0, 0, 0, 0 }) { af.quad_constraints.push_back(serialize_mul_quad_gate(arg.value)); + af.original_opcode_indices.quad_constraints.push_back(opcode_index); + } else { af.poly_triple_constraints.push_back(pt); + af.original_opcode_indices.poly_triple_constraints.push_back(opcode_index); } } else { af.quad_constraints.push_back(serialize_mul_quad_gate(arg.value)); + af.original_opcode_indices.quad_constraints.push_back(opcode_index); } } -void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, AcirFormat& af, bool honk_recursion) +void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, + AcirFormat& af, + bool honk_recursion, + size_t opcode_index) { std::visit( [&](auto&& arg) { @@ -195,6 +205,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .num_bits = arg.lhs.num_bits, .is_xor_gate = false, }); + af.original_opcode_indices.logic_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.logic_constraints.push_back(LogicConstraint{ .a = arg.lhs.witness.value, @@ -203,11 +214,14 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .num_bits = arg.lhs.num_bits, .is_xor_gate = true, }); + af.original_opcode_indices.logic_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.range_constraints.push_back(RangeConstraint{ .witness = arg.input.witness.value, .num_bits = arg.input.num_bits, }); + af.original_opcode_indices.range_constraints.push_back(opcode_index); + } else if constexpr (std::is_same_v) { af.aes128_constraints.push_back(AES128Constraint{ .inputs = map(arg.inputs, @@ -233,6 +247,8 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci }), .outputs = map(arg.outputs, [](auto& e) { return e.value; }), }); + af.original_opcode_indices.aes128_constraints.push_back(opcode_index); + } else if constexpr (std::is_same_v) { af.sha256_constraints.push_back(Sha256Constraint{ .inputs = map(arg.inputs, @@ -244,6 +260,8 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci }), .result = map(arg.outputs, [](auto& e) { return e.value; }), }); + af.original_opcode_indices.sha256_constraints.push_back(opcode_index); + } else if constexpr (std::is_same_v) { af.sha256_compression.push_back(Sha256Compression{ .inputs = map(arg.inputs, @@ -262,6 +280,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci }), .result = map(arg.outputs, [](auto& e) { return e.value; }), }); + af.original_opcode_indices.sha256_compression.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.blake2s_constraints.push_back(Blake2sConstraint{ .inputs = map(arg.inputs, @@ -273,6 +292,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci }), .result = map(arg.outputs, [](auto& e) { return e.value; }), }); + af.original_opcode_indices.blake2s_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.blake3_constraints.push_back(Blake3Constraint{ .inputs = map(arg.inputs, @@ -284,6 +304,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci }), .result = map(arg.outputs, [](auto& e) { return e.value; }), }); + af.original_opcode_indices.blake3_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.schnorr_constraints.push_back(SchnorrConstraint{ .message = map(arg.message, [](auto& e) { return e.witness.value; }), @@ -292,6 +313,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .result = arg.output.value, .signature = map(arg.signature, [](auto& e) { return e.witness.value; }), }); + af.original_opcode_indices.schnorr_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.pedersen_constraints.push_back(PedersenConstraint{ .scalars = map(arg.inputs, [](auto& e) { return e.witness.value; }), @@ -299,12 +321,14 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .result_x = arg.outputs[0].value, .result_y = arg.outputs[1].value, }); + af.original_opcode_indices.pedersen_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.pedersen_hash_constraints.push_back(PedersenHashConstraint{ .scalars = map(arg.inputs, [](auto& e) { return e.witness.value; }), .hash_index = arg.domain_separator, .result = arg.output.value, }); + af.original_opcode_indices.pedersen_hash_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.ecdsa_k1_constraints.push_back(EcdsaSecp256k1Constraint{ .hashed_message = map(arg.hashed_message, [](auto& e) { return e.witness.value; }), @@ -313,6 +337,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .pub_y_indices = map(arg.public_key_y, [](auto& e) { return e.witness.value; }), .result = arg.output.value, }); + af.original_opcode_indices.ecdsa_k1_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.ecdsa_r1_constraints.push_back(EcdsaSecp256r1Constraint{ .hashed_message = map(arg.hashed_message, [](auto& e) { return e.witness.value; }), @@ -321,6 +346,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .result = arg.output.value, .signature = map(arg.signature, [](auto& e) { return e.witness.value; }), }); + af.original_opcode_indices.ecdsa_r1_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.multi_scalar_mul_constraints.push_back(MultiScalarMul{ .points = map(arg.points, [](auto& e) { return e.witness.value; }), @@ -329,6 +355,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .out_point_y = arg.outputs[1].value, .out_point_is_infinite = arg.outputs[2].value, }); + af.original_opcode_indices.multi_scalar_mul_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.ec_add_constraints.push_back(EcAdd{ .input1_x = arg.input1[0].witness.value, @@ -341,6 +368,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .result_y = arg.outputs[1].value, .result_infinite = arg.outputs[2].value, }); + af.original_opcode_indices.ec_add_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.keccak_constraints.push_back(KeccakConstraint{ .inputs = map(arg.inputs, @@ -353,11 +381,13 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .result = map(arg.outputs, [](auto& e) { return e.value; }), .var_message_size = arg.var_message_size.witness.value, }); + af.original_opcode_indices.keccak_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.keccak_permutations.push_back(Keccakf1600{ .state = map(arg.inputs, [](auto& e) { return e.witness.value; }), .result = map(arg.outputs, [](auto& e) { return e.value; }), }); + af.original_opcode_indices.keccak_permutations.push_back(opcode_index); } else if constexpr (std::is_same_v) { if (honk_recursion) { // if we're using the honk recursive verifier auto c = HonkRecursionConstraint{ @@ -366,6 +396,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .public_inputs = map(arg.public_inputs, [](auto& e) { return e.witness.value; }), }; af.honk_recursion_constraints.push_back(c); + af.original_opcode_indices.honk_recursion_constraints.push_back(opcode_index); } else { auto c = RecursionConstraint{ .key = map(arg.verification_key, [](auto& e) { return e.witness.value; }), @@ -374,6 +405,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .key_hash = arg.key_hash.witness.value, }; af.recursion_constraints.push_back(c); + af.original_opcode_indices.recursion_constraints.push_back(opcode_index); } } else if constexpr (std::is_same_v) { af.bigint_from_le_bytes_constraints.push_back(BigIntFromLeBytes{ @@ -381,11 +413,13 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .modulus = map(arg.modulus, [](auto& e) -> uint32_t { return e; }), .result = arg.output, }); + af.original_opcode_indices.bigint_from_le_bytes_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.bigint_to_le_bytes_constraints.push_back(BigIntToLeBytes{ .input = arg.input, .result = map(arg.outputs, [](auto& e) { return e.value; }), }); + af.original_opcode_indices.bigint_to_le_bytes_constraints.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.bigint_operations.push_back(BigIntOperation{ .lhs = arg.lhs, @@ -393,6 +427,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .result = arg.output, .opcode = BigIntOperationType::Add, }); + af.original_opcode_indices.bigint_operations.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.bigint_operations.push_back(BigIntOperation{ .lhs = arg.lhs, @@ -400,6 +435,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .result = arg.output, .opcode = BigIntOperationType::Sub, }); + af.original_opcode_indices.bigint_operations.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.bigint_operations.push_back(BigIntOperation{ .lhs = arg.lhs, @@ -407,6 +443,7 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .result = arg.output, .opcode = BigIntOperationType::Mul, }); + af.original_opcode_indices.bigint_operations.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.bigint_operations.push_back(BigIntOperation{ .lhs = arg.lhs, @@ -414,12 +451,14 @@ void handle_blackbox_func_call(Program::Opcode::BlackBoxFuncCall const& arg, Aci .result = arg.output, .opcode = BigIntOperationType::Div, }); + af.original_opcode_indices.bigint_operations.push_back(opcode_index); } else if constexpr (std::is_same_v) { af.poseidon2_constraints.push_back(Poseidon2Constraint{ .state = map(arg.inputs, [](auto& e) { return e.witness.value; }), .result = map(arg.outputs, [](auto& e) { return e.value; }), .len = arg.len, }); + af.original_opcode_indices.poseidon2_constraints.push_back(opcode_index); } }, arg.value.value); @@ -446,12 +485,10 @@ BlockConstraint handle_memory_init(Program::Opcode::MemoryInit const& mem_init) } // Databus is only supported for Goblin, non Goblin builders will treat call_data and return_data as normal array. - if (IsMegaBuilder) { - if (std::holds_alternative(mem_init.block_type.value)) { - block.type = BlockType::CallData; - } else if (std::holds_alternative(mem_init.block_type.value)) { - block.type = BlockType::ReturnData; - } + if (std::holds_alternative(mem_init.block_type.value)) { + block.type = BlockType::CallData; + } else if (std::holds_alternative(mem_init.block_type.value)) { + block.type = BlockType::ReturnData; } return block; @@ -490,32 +527,37 @@ AcirFormat circuit_serde_to_acir_format(Program::Circuit const& circuit, bool ho af.num_acir_opcodes = static_cast(circuit.opcodes.size()); af.public_inputs = join({ map(circuit.public_parameters.value, [](auto e) { return e.value; }), map(circuit.return_values.value, [](auto e) { return e.value; }) }); - std::map block_id_to_block_constraint; - for (auto gate : circuit.opcodes) { + // Map to a pair of: BlockConstraint, and list of opcodes associated with that BlockConstraint + std::unordered_map>> block_id_to_block_constraint; + for (size_t i = 0; i < circuit.opcodes.size(); ++i) { + auto gate = circuit.opcodes[i]; std::visit( [&](auto&& arg) { using T = std::decay_t; if constexpr (std::is_same_v) { - handle_arithmetic(arg, af); + handle_arithmetic(arg, af, i); } else if constexpr (std::is_same_v) { - handle_blackbox_func_call(arg, af, honk_recursion); + handle_blackbox_func_call(arg, af, honk_recursion, i); } else if constexpr (std::is_same_v) { auto block = handle_memory_init(arg); uint32_t block_id = arg.block_id.value; - block_id_to_block_constraint[block_id] = block; + block_id_to_block_constraint[block_id] = std::make_pair(block, std::vector()); } else if constexpr (std::is_same_v) { auto block = block_id_to_block_constraint.find(arg.block_id.value); if (block == block_id_to_block_constraint.end()) { throw_or_abort("unitialized MemoryOp"); } - handle_memory_op(arg, block->second); + handle_memory_op(arg, block->second.first); + block->second.second.push_back(i); } }, gate.value); } for (const auto& [block_id, block] : block_id_to_block_constraint) { - if (!block.trace.empty()) { - af.block_constraints.push_back(block); + // Note: the trace will always be empty for ReturnData since it cannot be explicitly read from in noir + if (!block.first.trace.empty() || block.first.type == BlockType::ReturnData) { + af.block_constraints.push_back(block.first); + af.original_opcode_indices.block_constraints.push_back(block.second); } } return af; @@ -523,9 +565,9 @@ AcirFormat circuit_serde_to_acir_format(Program::Circuit const& circuit, bool ho AcirFormat circuit_buf_to_acir_format(std::vector const& buf, bool honk_recursion) { - // TODO(https://github.com/AztecProtocol/barretenberg/issues/927): Move to using just `program_buf_to_acir_format` - // once Honk fully supports all ACIR test flows - // For now the backend still expects to work with a single ACIR function + // TODO(https://github.com/AztecProtocol/barretenberg/issues/927): Move to using just + // `program_buf_to_acir_format` once Honk fully supports all ACIR test flows For now the backend still expects + // to work with a single ACIR function auto circuit = Program::Program::bincodeDeserialize(buf).functions[0]; return circuit_serde_to_acir_format(circuit, honk_recursion); @@ -567,9 +609,9 @@ WitnessVector witness_map_to_witness_vector(WitnessStack::WitnessMap const& witn */ WitnessVector witness_buf_to_witness_data(std::vector const& buf) { - // TODO(https://github.com/AztecProtocol/barretenberg/issues/927): Move to using just `witness_buf_to_witness_stack` - // once Honk fully supports all ACIR test flows. - // For now the backend still expects to work with the stop of the `WitnessStack`. + // TODO(https://github.com/AztecProtocol/barretenberg/issues/927): Move to using just + // `witness_buf_to_witness_stack` once Honk fully supports all ACIR test flows. For now the backend still + // expects to work with the stop of the `WitnessStack`. auto witness_stack = WitnessStack::WitnessStack::bincodeDeserialize(buf); auto w = witness_stack.stack[witness_stack.stack.size() - 1].witness; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp index 69d40ffe965..4ce4f77b934 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/bigint_constraint.test.cpp @@ -1,5 +1,6 @@ #include "bigint_constraint.hpp" #include "acir_format.hpp" +#include "acir_format_mocks.hpp" #include "barretenberg/circuit_checker/circuit_checker.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" @@ -199,12 +200,14 @@ TEST_F(BigIntTests, TestBigIntConstraintMultiple) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; apply_constraints(constraint_system, contraints); apply_constraints(constraint_system, contraints2); apply_constraints(constraint_system, contraints3); apply_constraints(constraint_system, contraints4); apply_constraints(constraint_system, contraints5); + mock_opcode_indices(constraint_system); constraint_system.varnum = static_cast(witness.size() + 1); auto builder = create_circuit(constraint_system, /*size_hint*/ 0, witness); @@ -270,8 +273,9 @@ TEST_F(BigIntTests, TestBigIntConstraintSimple) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = {}, - + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); WitnessVector witness{ 0, 3, 6, 3, 0, @@ -326,6 +330,7 @@ TEST_F(BigIntTests, TestBigIntConstraintReuse) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; apply_constraints(constraint_system, contraints); apply_constraints(constraint_system, contraints2); @@ -336,6 +341,7 @@ TEST_F(BigIntTests, TestBigIntConstraintReuse) constraint_system.bigint_to_le_bytes_constraints.push_back(get<1>(contraints5)); constraint_system.bigint_operations.push_back(get<0>(contraints5)); constraint_system.varnum = static_cast(witness.size() + 1); + mock_opcode_indices(constraint_system); auto builder = create_circuit(constraint_system, /*size_hint*/ 0, witness); @@ -386,6 +392,7 @@ TEST_F(BigIntTests, TestBigIntConstraintReuse2) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; apply_constraints(constraint_system, contraints); apply_constraints(constraint_system, contraints2); @@ -396,6 +403,7 @@ TEST_F(BigIntTests, TestBigIntConstraintReuse2) constraint_system.bigint_to_le_bytes_constraints.push_back(get<1>(contraints5)); constraint_system.bigint_operations.push_back(get<0>(contraints5)); constraint_system.varnum = static_cast(witness.size() + 1); + mock_opcode_indices(constraint_system); auto builder = create_circuit(constraint_system, /*size_hint*/ 0, witness); @@ -467,8 +475,9 @@ TEST_F(BigIntTests, TestBigIntDIV) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = {}, - + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); WitnessVector witness{ 0, 6, 3, 2, 0, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.cpp index bb094b3392b..1ba27ff530d 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.cpp @@ -24,13 +24,17 @@ template stdlib::field_t poly_to_field_ct(const poly return x; } -template -void create_block_constraints(Builder& builder, const BlockConstraint& constraint, bool has_valid_witness_assignments) +/** + * @brief Create block constraints; Specialization for Ultra arithmetization + * @details Ultra does not support DataBus operations so calldata/returndata are treated as ROM ops + * + */ +template <> +void create_block_constraints(UltraCircuitBuilder& builder, + const BlockConstraint& constraint, + bool has_valid_witness_assignments) { - using field_ct = stdlib::field_t; - using rom_table_ct = stdlib::rom_table; - using ram_table_ct = stdlib::ram_table; - using databus_ct = stdlib::databus; + using field_ct = bb::stdlib::field_t; std::vector init; for (auto i : constraint.init) { @@ -39,86 +43,50 @@ void create_block_constraints(Builder& builder, const BlockConstraint& constrain } switch (constraint.type) { + // Note: CallData/ReturnData not supported by Ultra; interpreted as ROM ops instead + case BlockType::CallData: + case BlockType::ReturnData: case BlockType::ROM: { - rom_table_ct table(init); - for (auto& op : constraint.trace) { - ASSERT(op.access_type == 0); - field_ct value = poly_to_field_ct(op.value, builder); - field_ct index = poly_to_field_ct(op.index, builder); - // For a ROM table, constant read should be optimized out: - // The rom_table won't work with a constant read because the table may not be initialized - ASSERT(op.index.q_l != 0); - // We create a new witness w to avoid issues with non-valid witness assignements: - // if witness are not assigned, then w will be zero and table[w] will work - fr w_value = 0; - if (has_valid_witness_assignments) { - // If witness are assigned, we use the correct value for w - w_value = index.get_value(); - } - field_ct w = field_ct::from_witness(&builder, w_value); - value.assert_equal(table[w]); - w.assert_equal(index); - } + process_ROM_operations(builder, constraint, has_valid_witness_assignments, init); } break; case BlockType::RAM: { - ram_table_ct table(init); - for (auto& op : constraint.trace) { - field_ct value = poly_to_field_ct(op.value, builder); - field_ct index = poly_to_field_ct(op.index, builder); - - // We create a new witness w to avoid issues with non-valid witness assignements. - // If witness are not assigned, then index will be zero and table[index] won't hit bounds check. - fr index_value = has_valid_witness_assignments ? index.get_value() : 0; - // Create new witness and ensure equal to index. - field_ct::from_witness(&builder, index_value).assert_equal(index); - - if (op.access_type == 0) { - value.assert_equal(table.read(index)); - } else { - ASSERT(op.access_type == 1); - table.write(index, value); - } - } + process_RAM_operations(builder, constraint, has_valid_witness_assignments, init); + } break; + default: + ASSERT(false); + break; + } +} + +/** + * @brief Create block constraints; Specialization for Mega arithmetization + * + */ +template <> +void create_block_constraints(MegaCircuitBuilder& builder, + const BlockConstraint& constraint, + bool has_valid_witness_assignments) +{ + using field_ct = stdlib::field_t; + + std::vector init; + for (auto i : constraint.init) { + field_ct value = poly_to_field_ct(i, builder); + init.push_back(value); + } + + switch (constraint.type) { + case BlockType::ROM: { + process_ROM_operations(builder, constraint, has_valid_witness_assignments, init); + } break; + case BlockType::RAM: { + process_RAM_operations(builder, constraint, has_valid_witness_assignments, init); } break; case BlockType::CallData: { - if constexpr (IsMegaBuilder) { - databus_ct databus; - // Populate the calldata in the databus - databus.calldata.set_values(init); - for (const auto& op : constraint.trace) { - ASSERT(op.access_type == 0); - field_ct value = poly_to_field_ct(op.value, builder); - field_ct index = poly_to_field_ct(op.index, builder); - fr w_value = 0; - if (has_valid_witness_assignments) { - // If witness are assigned, we use the correct value for w - w_value = index.get_value(); - } - field_ct w = field_ct::from_witness(&builder, w_value); - value.assert_equal(databus.calldata[w]); - w.assert_equal(index); - } - } + process_call_data_operations(builder, constraint, has_valid_witness_assignments, init); } break; case BlockType::ReturnData: { - if constexpr (IsMegaBuilder) { - databus_ct databus; - // Populate the returndata in the databus - databus.return_data.set_values(init); - for (const auto& op : constraint.trace) { - ASSERT(op.access_type == 0); - field_ct value = poly_to_field_ct(op.value, builder); - field_ct index = poly_to_field_ct(op.index, builder); - fr w_value = 0; - if (has_valid_witness_assignments) { - // If witness are assigned, we use the correct value for w - w_value = index.get_value(); - } - field_ct w = field_ct::from_witness(&builder, w_value); - value.assert_equal(databus.return_data[w]); - w.assert_equal(index); - } - } + process_return_data_operations(constraint, init); } break; default: ASSERT(false); @@ -126,11 +94,109 @@ void create_block_constraints(Builder& builder, const BlockConstraint& constrain } } -template void create_block_constraints(UltraCircuitBuilder& builder, - const BlockConstraint& constraint, - bool has_valid_witness_assignments); -template void create_block_constraints(MegaCircuitBuilder& builder, - const BlockConstraint& constraint, - bool has_valid_witness_assignments); +template +void process_ROM_operations(Builder& builder, + const BlockConstraint& constraint, + bool has_valid_witness_assignments, + std::vector>& init) +{ + using field_ct = stdlib::field_t; + using rom_table_ct = stdlib::rom_table; + + rom_table_ct table(init); + for (auto& op : constraint.trace) { + ASSERT(op.access_type == 0); + field_ct value = poly_to_field_ct(op.value, builder); + field_ct index = poly_to_field_ct(op.index, builder); + // For a ROM table, constant read should be optimized out: + // The rom_table won't work with a constant read because the table may not be initialized + ASSERT(op.index.q_l != 0); + // We create a new witness w to avoid issues with non-valid witness assignements: + // if witness are not assigned, then w will be zero and table[w] will work + fr w_value = 0; + if (has_valid_witness_assignments) { + // If witness are assigned, we use the correct value for w + w_value = index.get_value(); + } + field_ct w = field_ct::from_witness(&builder, w_value); + value.assert_equal(table[w]); + w.assert_equal(index); + } +} + +template +void process_RAM_operations(Builder& builder, + const BlockConstraint& constraint, + bool has_valid_witness_assignments, + std::vector>& init) +{ + using field_ct = stdlib::field_t; + using ram_table_ct = stdlib::ram_table; + + ram_table_ct table(init); + for (auto& op : constraint.trace) { + field_ct value = poly_to_field_ct(op.value, builder); + field_ct index = poly_to_field_ct(op.index, builder); + + // We create a new witness w to avoid issues with non-valid witness assignements. + // If witness are not assigned, then index will be zero and table[index] won't hit bounds check. + fr index_value = has_valid_witness_assignments ? index.get_value() : 0; + // Create new witness and ensure equal to index. + field_ct::from_witness(&builder, index_value).assert_equal(index); + + if (op.access_type == 0) { + value.assert_equal(table.read(index)); + } else { + ASSERT(op.access_type == 1); + table.write(index, value); + } + } +} + +template +void process_call_data_operations(Builder& builder, + const BlockConstraint& constraint, + bool has_valid_witness_assignments, + std::vector>& init) +{ + using field_ct = stdlib::field_t; + using databus_ct = stdlib::databus; + + databus_ct databus; + // Populate the calldata in the databus + databus.calldata.set_values(init); + for (const auto& op : constraint.trace) { + ASSERT(op.access_type == 0); + field_ct value = poly_to_field_ct(op.value, builder); + field_ct index = poly_to_field_ct(op.index, builder); + fr w_value = 0; + if (has_valid_witness_assignments) { + // If witness are assigned, we use the correct value for w + w_value = index.get_value(); + } + field_ct w = field_ct::from_witness(&builder, w_value); + value.assert_equal(databus.calldata[w]); + w.assert_equal(index); + } +} + +template +void process_return_data_operations(const BlockConstraint& constraint, std::vector>& init) +{ + using databus_ct = stdlib::databus; + + databus_ct databus; + // Populate the returndata in the databus + databus.return_data.set_values(init); + // For each entry of the return data, explicitly assert equality with the initialization value. This implicitly + // creates the return data read gates that are required to connect witness values in the main wires to witness + // values in the databus return data column. + size_t c = 0; + for (const auto& value : init) { + value.assert_equal(databus.return_data[c]); + c++; + } + ASSERT(constraint.trace.size() == 0); +} } // namespace acir_format \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.hpp index 5f21ed8716a..8a0da27058b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.hpp @@ -29,6 +29,24 @@ void create_block_constraints(Builder& builder, const BlockConstraint& constraint, bool has_valid_witness_assignments = true); +template +void process_ROM_operations(Builder& builder, + const BlockConstraint& constraint, + bool has_valid_witness_assignments, + std::vector>& init); +template +void process_RAM_operations(Builder& builder, + const BlockConstraint& constraint, + bool has_valid_witness_assignments, + std::vector>& init); +template +void process_call_data_operations(Builder& builder, + const BlockConstraint& constraint, + bool has_valid_witness_assignments, + std::vector>& init); +template +void process_return_data_operations(const BlockConstraint& constraint, std::vector>& init); + template inline void read(B& buf, MemOp& mem_op) { using serialize::read; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp index 5da46acc95e..9affaf9f9f5 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp @@ -1,5 +1,6 @@ #include "block_constraint.hpp" #include "acir_format.hpp" +#include "acir_format_mocks.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" @@ -167,7 +168,9 @@ TEST_F(UltraPlonkRAM, TestBlockConstraint) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = { block }, + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); auto builder = create_circuit(constraint_system, /*size_hint*/ 0, witness_values); @@ -216,7 +219,9 @@ TEST_F(MegaHonk, Databus) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = { block }, + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); // Construct a bberg circuit from the acir representation auto circuit = acir_format::create_circuit(constraint_system, 0, witness_values); @@ -293,7 +298,7 @@ TEST_F(MegaHonk, DatabusReturn) AcirFormat constraint_system{ .varnum = static_cast(num_variables), .recursive = false, - .num_acir_opcodes = 1, + .num_acir_opcodes = 2, .public_inputs = {}, .logic_constraints = {}, .range_constraints = {}, @@ -320,7 +325,9 @@ TEST_F(MegaHonk, DatabusReturn) .poly_triple_constraints = { assert_equal }, .quad_constraints = {}, .block_constraints = { block }, + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); // Construct a bberg circuit from the acir representation auto circuit = acir_format::create_circuit(constraint_system, 0, witness_values); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.test.cpp index c006186494d..1dacfe85a0f 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.test.cpp @@ -1,5 +1,6 @@ #include "ec_operations.hpp" #include "acir_format.hpp" +#include "acir_format_mocks.hpp" #include "barretenberg/circuit_checker/circuit_checker.hpp" #include "barretenberg/plonk/composer/standard_composer.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" @@ -89,7 +90,9 @@ TEST_F(EcOperations, TestECOperations) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); auto builder = create_circuit(constraint_system, /*size_hint*/ 0, witness_values); @@ -175,7 +178,9 @@ TEST_F(EcOperations, TestECMultiScalarMul) .poly_triple_constraints = { assert_equal }, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); auto builder = create_circuit(constraint_system, /*size_hint*/ 0, witness_values); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp index 88140210210..6026f0cf31e 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp @@ -1,5 +1,6 @@ #include "ecdsa_secp256k1.hpp" #include "acir_format.hpp" +#include "acir_format_mocks.hpp" #include "barretenberg/crypto/ecdsa/ecdsa.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" @@ -121,7 +122,9 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintSucceed) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); auto builder = create_circuit(constraint_system, /*size_hint*/ 0, witness_values); @@ -173,7 +176,9 @@ TEST_F(ECDSASecp256k1, TestECDSACompilesForVerifier) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); auto builder = create_circuit(constraint_system); } @@ -220,7 +225,9 @@ TEST_F(ECDSASecp256k1, TestECDSAConstraintFail) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); auto builder = create_circuit(constraint_system, /*size_hint*/ 0, witness_values); EXPECT_EQ(builder.get_variable(ecdsa_k1_constraint.result), 0); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp index ac0d9a31938..68f0f416dbe 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256r1.test.cpp @@ -1,5 +1,6 @@ #include "ecdsa_secp256r1.hpp" #include "acir_format.hpp" +#include "acir_format_mocks.hpp" #include "barretenberg/crypto/ecdsa/ecdsa.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" @@ -155,7 +156,9 @@ TEST(ECDSASecp256r1, test_hardcoded) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); secp256r1::g1::affine_element pub_key = { pub_key_x, pub_key_y }; bool we_ballin = @@ -209,7 +212,9 @@ TEST(ECDSASecp256r1, TestECDSAConstraintSucceed) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); auto builder = create_circuit(constraint_system, /*size_hint*/ 0, witness_values); @@ -261,7 +266,10 @@ TEST(ECDSASecp256r1, TestECDSACompilesForVerifier) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); + auto builder = create_circuit(constraint_system); } @@ -308,7 +316,9 @@ TEST(ECDSASecp256r1, TestECDSAConstraintFail) .poly_triple_constraints = {}, .quad_constraints = {}, .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), }; + mock_opcode_indices(constraint_system); auto builder = create_circuit(constraint_system, /*size_hint*/ 0, witness_values); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.test.cpp index 3b653fecc18..61259910828 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.test.cpp @@ -1,5 +1,6 @@ #include "honk_recursion_constraint.hpp" #include "acir_format.hpp" +#include "acir_format_mocks.hpp" #include "barretenberg/sumcheck/instance/prover_instance.hpp" #include "barretenberg/ultra_honk/ultra_prover.hpp" #include "barretenberg/ultra_honk/ultra_verifier.hpp" @@ -86,35 +87,39 @@ class AcirHonkRecursionConstraint : public ::testing::Test { .q_c = 1, }; - AcirFormat constraint_system{ .varnum = 6, - .recursive = true, - .num_acir_opcodes = 7, - .public_inputs = { 1, 2 }, - .logic_constraints = { logic_constraint }, - .range_constraints = { range_a, range_b }, - .aes128_constraints = {}, - .sha256_constraints = {}, - .sha256_compression = {}, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_permutations = {}, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .poseidon2_constraints = {}, - .multi_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .recursion_constraints = {}, - .honk_recursion_constraints = {}, - .bigint_from_le_bytes_constraints = {}, - .bigint_to_le_bytes_constraints = {}, - .bigint_operations = {}, - .poly_triple_constraints = { expr_a, expr_b, expr_c, expr_d }, - .quad_constraints = {}, - .block_constraints = {} }; + AcirFormat constraint_system{ + .varnum = 6, + .recursive = true, + .num_acir_opcodes = 7, + .public_inputs = { 1, 2 }, + .logic_constraints = { logic_constraint }, + .range_constraints = { range_a, range_b }, + .aes128_constraints = {}, + .sha256_constraints = {}, + .sha256_compression = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .poseidon2_constraints = {}, + .multi_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .recursion_constraints = {}, + .honk_recursion_constraints = {}, + .bigint_from_le_bytes_constraints = {}, + .bigint_to_le_bytes_constraints = {}, + .bigint_operations = {}, + .poly_triple_constraints = { expr_a, expr_b, expr_c, expr_d }, + .quad_constraints = {}, + .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), + }; + mock_opcode_indices(constraint_system); uint256_t inverse_of_five = fr(5).invert(); WitnessVector witness{ @@ -244,36 +249,42 @@ class AcirHonkRecursionConstraint : public ::testing::Test { witness_offset = key_indices_start_idx + key_witnesses.size(); } - AcirFormat constraint_system{ .varnum = static_cast(witness.size()), - .recursive = false, - .num_acir_opcodes = static_cast(honk_recursion_constraints.size()), - .public_inputs = {}, - .logic_constraints = {}, - .range_constraints = {}, - .aes128_constraints = {}, - .sha256_constraints = {}, - .sha256_compression = {}, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_permutations = {}, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .poseidon2_constraints = {}, - .multi_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .recursion_constraints = {}, - .honk_recursion_constraints = honk_recursion_constraints, - .bigint_from_le_bytes_constraints = {}, - .bigint_to_le_bytes_constraints = {}, - .bigint_operations = {}, - .poly_triple_constraints = {}, - .quad_constraints = {}, - .block_constraints = {} }; - + std::vector honk_recursion_opcode_indices(honk_recursion_constraints.size()); + std::iota(honk_recursion_opcode_indices.begin(), honk_recursion_opcode_indices.end(), 0); + + AcirFormat constraint_system{ + .varnum = static_cast(witness.size()), + .recursive = false, + .num_acir_opcodes = static_cast(honk_recursion_constraints.size()), + .public_inputs = {}, + .logic_constraints = {}, + .range_constraints = {}, + .aes128_constraints = {}, + .sha256_constraints = {}, + .sha256_compression = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .poseidon2_constraints = {}, + .multi_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .recursion_constraints = {}, + .honk_recursion_constraints = honk_recursion_constraints, + .bigint_from_le_bytes_constraints = {}, + .bigint_to_le_bytes_constraints = {}, + .bigint_operations = {}, + .poly_triple_constraints = {}, + .quad_constraints = {}, + .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), + }; + mock_opcode_indices(constraint_system); auto outer_circuit = create_circuit(constraint_system, /*size_hint*/ 0, witness, /*honk recursion*/ true); return outer_circuit; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.test.cpp index dd01d0b9b3e..cc144fa6fd9 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/poseidon2_constraint.test.cpp @@ -1,5 +1,6 @@ #include "poseidon2_constraint.hpp" #include "acir_format.hpp" +#include "acir_format_mocks.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" @@ -33,35 +34,39 @@ TEST_F(Poseidon2Tests, TestPoseidon2Permutation) .len = 4, }; - AcirFormat constraint_system{ .varnum = 9, - .recursive = false, - .num_acir_opcodes = 1, - .public_inputs = {}, - .logic_constraints = {}, - .range_constraints = {}, - .aes128_constraints = {}, - .sha256_constraints = {}, - .sha256_compression = {}, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_permutations = {}, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .poseidon2_constraints = { poseidon2_constraint }, - .multi_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .recursion_constraints = {}, - .honk_recursion_constraints = {}, - .bigint_from_le_bytes_constraints = {}, - .bigint_to_le_bytes_constraints = {}, - .bigint_operations = {}, - .poly_triple_constraints = {}, - .quad_constraints = {}, - .block_constraints = {} }; + AcirFormat constraint_system{ + .varnum = 9, + .recursive = false, + .num_acir_opcodes = 1, + .public_inputs = {}, + .logic_constraints = {}, + .range_constraints = {}, + .aes128_constraints = {}, + .sha256_constraints = {}, + .sha256_compression = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .poseidon2_constraints = { poseidon2_constraint }, + .multi_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .recursion_constraints = {}, + .honk_recursion_constraints = {}, + .bigint_from_le_bytes_constraints = {}, + .bigint_to_le_bytes_constraints = {}, + .bigint_operations = {}, + .poly_triple_constraints = {}, + .quad_constraints = {}, + .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), + }; + mock_opcode_indices(constraint_system); WitnessVector witness{ 1, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp index 2715bc873a9..72ea7e939ac 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp @@ -1,5 +1,6 @@ #include "recursion_constraint.hpp" #include "acir_format.hpp" +#include "acir_format_mocks.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" @@ -84,35 +85,39 @@ Builder create_inner_circuit() .q_c = 1, }; - AcirFormat constraint_system{ .varnum = 6, - .recursive = true, - .num_acir_opcodes = 7, - .public_inputs = { 1, 2 }, - .logic_constraints = { logic_constraint }, - .range_constraints = { range_a, range_b }, - .aes128_constraints = {}, - .sha256_constraints = {}, - .sha256_compression = {}, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_permutations = {}, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .poseidon2_constraints = {}, - .multi_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .recursion_constraints = {}, - .honk_recursion_constraints = {}, - .bigint_from_le_bytes_constraints = {}, - .bigint_to_le_bytes_constraints = {}, - .bigint_operations = {}, - .poly_triple_constraints = { expr_a, expr_b, expr_c, expr_d }, - .quad_constraints = {}, - .block_constraints = {} }; + AcirFormat constraint_system{ + .varnum = 6, + .recursive = true, + .num_acir_opcodes = 7, + .public_inputs = { 1, 2 }, + .logic_constraints = { logic_constraint }, + .range_constraints = { range_a, range_b }, + .aes128_constraints = {}, + .sha256_constraints = {}, + .sha256_compression = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .poseidon2_constraints = {}, + .multi_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .recursion_constraints = {}, + .honk_recursion_constraints = {}, + .bigint_from_le_bytes_constraints = {}, + .bigint_to_le_bytes_constraints = {}, + .bigint_operations = {}, + .poly_triple_constraints = { expr_a, expr_b, expr_c, expr_d }, + .quad_constraints = {}, + .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), + }; + mock_opcode_indices(constraint_system); uint256_t inverse_of_five = fr(5).invert(); WitnessVector witness{ @@ -239,35 +244,42 @@ Builder create_outer_circuit(std::vector& inner_circuits) witness_offset = key_indices_start_idx + key_witnesses.size(); } - AcirFormat constraint_system{ .varnum = static_cast(witness.size()), - .recursive = false, - .num_acir_opcodes = static_cast(recursion_constraints.size()), - .public_inputs = {}, - .logic_constraints = {}, - .range_constraints = {}, - .aes128_constraints = {}, - .sha256_constraints = {}, - .sha256_compression = {}, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_permutations = {}, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .poseidon2_constraints = {}, - .multi_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .recursion_constraints = recursion_constraints, - .honk_recursion_constraints = {}, - .bigint_from_le_bytes_constraints = {}, - .bigint_to_le_bytes_constraints = {}, - .bigint_operations = {}, - .poly_triple_constraints = {}, - .quad_constraints = {}, - .block_constraints = {} }; + std::vector recursion_opcode_indices(recursion_constraints.size()); + std::iota(recursion_opcode_indices.begin(), recursion_opcode_indices.end(), 0); + + AcirFormat constraint_system{ + .varnum = static_cast(witness.size()), + .recursive = false, + .num_acir_opcodes = static_cast(recursion_constraints.size()), + .public_inputs = {}, + .logic_constraints = {}, + .range_constraints = {}, + .aes128_constraints = {}, + .sha256_constraints = {}, + .sha256_compression = {}, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .poseidon2_constraints = {}, + .multi_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .recursion_constraints = recursion_constraints, + .honk_recursion_constraints = {}, + .bigint_from_le_bytes_constraints = {}, + .bigint_to_le_bytes_constraints = {}, + .bigint_operations = {}, + .poly_triple_constraints = {}, + .quad_constraints = {}, + .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), + }; + mock_opcode_indices(constraint_system); auto outer_circuit = create_circuit(constraint_system, /*size_hint*/ 0, witness); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.test.cpp index 902ac2944e9..72936adc776 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.test.cpp @@ -1,5 +1,6 @@ #include "sha256_constraint.hpp" #include "acir_format.hpp" +#include "acir_format_mocks.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" @@ -34,35 +35,39 @@ TEST_F(Sha256Tests, TestSha256Compression) .result = { 25, 26, 27, 28, 29, 30, 31, 32 }, }; - AcirFormat constraint_system{ .varnum = 34, - .recursive = false, - .num_acir_opcodes = 1, - .public_inputs = {}, - .logic_constraints = {}, - .range_constraints = {}, - .aes128_constraints = {}, - .sha256_constraints = {}, - .sha256_compression = { sha256_compression }, - .schnorr_constraints = {}, - .ecdsa_k1_constraints = {}, - .ecdsa_r1_constraints = {}, - .blake2s_constraints = {}, - .blake3_constraints = {}, - .keccak_constraints = {}, - .keccak_permutations = {}, - .pedersen_constraints = {}, - .pedersen_hash_constraints = {}, - .poseidon2_constraints = {}, - .multi_scalar_mul_constraints = {}, - .ec_add_constraints = {}, - .recursion_constraints = {}, - .honk_recursion_constraints = {}, - .bigint_from_le_bytes_constraints = {}, - .bigint_to_le_bytes_constraints = {}, - .bigint_operations = {}, - .poly_triple_constraints = {}, - .quad_constraints = {}, - .block_constraints = {} }; + AcirFormat constraint_system{ + .varnum = 34, + .recursive = false, + .num_acir_opcodes = 1, + .public_inputs = {}, + .logic_constraints = {}, + .range_constraints = {}, + .aes128_constraints = {}, + .sha256_constraints = {}, + .sha256_compression = { sha256_compression }, + .schnorr_constraints = {}, + .ecdsa_k1_constraints = {}, + .ecdsa_r1_constraints = {}, + .blake2s_constraints = {}, + .blake3_constraints = {}, + .keccak_constraints = {}, + .keccak_permutations = {}, + .pedersen_constraints = {}, + .pedersen_hash_constraints = {}, + .poseidon2_constraints = {}, + .multi_scalar_mul_constraints = {}, + .ec_add_constraints = {}, + .recursion_constraints = {}, + .honk_recursion_constraints = {}, + .bigint_from_le_bytes_constraints = {}, + .bigint_to_le_bytes_constraints = {}, + .bigint_operations = {}, + .poly_triple_constraints = {}, + .quad_constraints = {}, + .block_constraints = {}, + .original_opcode_indices = create_empty_original_opcode_indices(), + }; + mock_opcode_indices(constraint_system); WitnessVector witness{ 0, 0, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp index b54244cf9bb..3775ac65f83 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp @@ -28,10 +28,13 @@ AcirComposer::AcirComposer(size_t size_hint, bool verbose) * @param witness */ template -void AcirComposer::create_circuit(acir_format::AcirFormat& constraint_system, WitnessVector const& witness) +void AcirComposer::create_circuit(acir_format::AcirFormat& constraint_system, + WitnessVector const& witness, + bool collect_gates_per_opcode) { vinfo("building circuit..."); - builder_ = acir_format::create_circuit(constraint_system, size_hint_, witness); + builder_ = acir_format::create_circuit( + constraint_system, size_hint_, witness, false, std::make_shared(), collect_gates_per_opcode); vinfo("gates: ", builder_.get_total_circuit_size()); vinfo("circuit is recursive friendly: ", builder_.is_recursive_circuit); } @@ -144,6 +147,7 @@ std::vector AcirComposer::serialize_verification_key_into_fields() } template void AcirComposer::create_circuit(acir_format::AcirFormat& constraint_system, - WitnessVector const& witness); + WitnessVector const& witness, + bool collect_gates_per_opcode); } // namespace acir_proofs diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp index e15c59fa60d..f53011ec374 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp @@ -17,7 +17,9 @@ class AcirComposer { AcirComposer(size_t size_hint = 0, bool verbose = true); template - void create_circuit(acir_format::AcirFormat& constraint_system, WitnessVector const& witness = {}); + void create_circuit(acir_format::AcirFormat& constraint_system, + WitnessVector const& witness = {}, + bool collect_gates_per_opcode = false); std::shared_ptr init_proving_key(); diff --git a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp index 06a901d7425..7745a853c58 100644 --- a/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.hpp @@ -26,7 +26,7 @@ void construct_lookup_table_polynomials(RefArray for (const auto& table : circuit.lookup_tables) { const fr table_index(table.table_index); - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table.size(); ++i) { table_polynomials[0][offset] = table.column_1[i]; table_polynomials[1][offset] = table.column_2[i]; table_polynomials[2][offset] = table.column_3[i]; @@ -67,7 +67,7 @@ std::array construct_sorted_list_polynomials(typ for (auto& table : circuit.lookup_tables) { const fr table_index(table.table_index); auto& lookup_gates = table.lookup_gates; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table.size(); ++i) { if (table.use_twin_keys) { lookup_gates.push_back({ { diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp index 4ff7f81cb51..4c47ac5086b 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp @@ -2,6 +2,7 @@ #include "barretenberg/polynomials/pow.hpp" #include "barretenberg/protogalaxy/protogalaxy_prover.hpp" #include "barretenberg/relations/relation_parameters.hpp" +#include "barretenberg/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp" #include "barretenberg/sumcheck/instance/instances.hpp" #include @@ -44,12 +45,6 @@ TEST(Protogalaxy, CombinerOn2Instances) auto prover_polynomials = get_sequential_prover_polynomials( /*log_circuit_size=*/1, idx * 128); restrict_to_standard_arithmetic_relation(prover_polynomials); - // This ensures that the combiner accumulator for second instance = 0 - // The value is computed by generating the python script values, computing the resulting accumulator and - // taking the value at index 1 - if (idx == NUM_INSTANCES - 1) { - prover_polynomials.q_c[0] -= 13644570; - } instance->proving_key.polynomials = std::move(prover_polynomials); instance->proving_key.circuit_size = 2; instance_data[idx] = instance; @@ -57,21 +52,204 @@ TEST(Protogalaxy, CombinerOn2Instances) ProverInstances instances{ instance_data }; instances.alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only + auto pow_polynomial = PowPolynomial(std::vector{ 2 }); + auto result = prover.compute_combiner(instances, pow_polynomial); + // The expected_result values are computed by running the python script combiner_example_gen.py + auto expected_result = Univariate(std::array{ 8600UL, + 12679448UL, + 73617560UL, + 220571672UL, + 491290520UL, + 923522840UL, + 1555017368UL, + 2423522840UL, + 3566787992UL, + 5022561560UL, + 6828592280UL, + 9022628888UL }); + EXPECT_EQ(result, expected_result); + } else { + std::vector> instance_data(NUM_INSTANCES); + ProtoGalaxyProver prover; + + for (size_t idx = 0; idx < NUM_INSTANCES; idx++) { + auto instance = std::make_shared(); + auto prover_polynomials = get_zero_prover_polynomials( + /*log_circuit_size=*/1); + restrict_to_standard_arithmetic_relation(prover_polynomials); + instance->proving_key.polynomials = std::move(prover_polynomials); + instance->proving_key.circuit_size = 2; + instance_data[idx] = instance; + } + + ProverInstances instances{ instance_data }; + instances.alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only + + const auto create_add_gate = [](auto& polys, const size_t idx, FF w_l, FF w_r) { + polys.w_l[idx] = w_l; + polys.w_r[idx] = w_r; + polys.w_o[idx] = w_l + w_r; + polys.q_l[idx] = 1; + polys.q_r[idx] = 1; + polys.q_o[idx] = -1; + }; + + const auto create_mul_gate = [](auto& polys, const size_t idx, FF w_l, FF w_r) { + polys.w_l[idx] = w_l; + polys.w_r[idx] = w_r; + polys.w_o[idx] = w_l * w_r; + polys.q_m[idx] = 1; + polys.q_o[idx] = -1; + }; + + create_add_gate(instances[0]->proving_key.polynomials, 0, 1, 2); + create_add_gate(instances[0]->proving_key.polynomials, 1, 0, 4); + create_add_gate(instances[1]->proving_key.polynomials, 0, 3, 4); + create_mul_gate(instances[1]->proving_key.polynomials, 1, 1, 4); + + restrict_to_standard_arithmetic_relation(instances[0]->proving_key.polynomials); + restrict_to_standard_arithmetic_relation(instances[1]->proving_key.polynomials); + + /* Instance 0 Instance 1 + w_l w_r w_o q_m q_l q_r q_o q_c w_l w_r w_o q_m q_l q_r q_o q_c + 1 2 3 0 1 1 -1 0 3 4 7 0 1 1 -1 0 + 0 4 4 0 1 1 -1 0 1 4 4 1 0 0 -1 0 */ + + /* Lagrange-combined values, row index 0 Lagrange-combined values, row index 1 + in 0 1 2 3 4 5 6 in 0 1 2 3 4 5 6 + w_l 1 3 5 7 9 11 13 w_l 0 1 2 3 4 5 6 + w_r 2 4 6 8 10 12 14 w_r 4 4 4 4 4 4 4 + w_o 3 7 11 15 19 23 27 w_o 4 4 4 4 4 4 0 + q_m 0 0 0 0 0 0 0 q_m 0 1 2 3 4 5 6 + q_l 1 1 1 1 1 1 1 q_l 1 0 -1 -2 -3 -4 -5 + q_r 1 1 1 1 1 1 1 q_r 1 0 -1 -2 -3 -4 -5 + q_o -1 -1 -1 -1 -1 -1 -1 q_o -1 -1 -1 -1 -1 -1 -1 + q_c 0 0 0 0 0 0 0 q_c 0 0 0 0 0 0 0 + + relation value: + 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ + auto pow_polynomial = PowPolynomial(std::vector{ 2 }); auto result = prover.compute_combiner(instances, pow_polynomial); auto optimised_result = prover.compute_combiner(instances, pow_polynomial); - auto expected_result = Univariate(std::array{ 87706, - 0, - 0x02ee2966, - 0x0b0bd2cc, - 0x00001a98fc32, - 0x000033d5a598, - 0x00005901cefe, - 0x00008c5d7864, - 0x0000d028a1ca, - 0x000126a34b30UL, - 0x0001920d7496UL, - 0x000214a71dfcUL }); + auto expected_result = + Univariate(std::array{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660 }); + + EXPECT_EQ(result, expected_result); + EXPECT_EQ(optimised_result, expected_result); + } + }; + run_test(true); + run_test(false); +}; + +// Check that the optimized combiner computation yields a result consistent with the unoptimized version +TEST(Protogalaxy, CombinerOptimizationConsistency) +{ + constexpr size_t NUM_INSTANCES = 2; + using ProverInstance = ProverInstance_; + using ProverInstances = ProverInstances_; + using ProtoGalaxyProver = ProtoGalaxyProver_; + using UltraArithmeticRelation = UltraArithmeticRelation; + + constexpr size_t UNIVARIATE_LENGTH = 12; + const auto restrict_to_standard_arithmetic_relation = [](auto& polys) { + std::fill(polys.q_arith.begin(), polys.q_arith.end(), 1); + std::fill(polys.q_delta_range.begin(), polys.q_delta_range.end(), 0); + std::fill(polys.q_elliptic.begin(), polys.q_elliptic.end(), 0); + std::fill(polys.q_aux.begin(), polys.q_aux.end(), 0); + std::fill(polys.q_lookup.begin(), polys.q_lookup.end(), 0); + std::fill(polys.q_4.begin(), polys.q_4.end(), 0); + std::fill(polys.w_4.begin(), polys.w_4.end(), 0); + std::fill(polys.w_4_shift.begin(), polys.w_4_shift.end(), 0); + }; + + auto run_test = [&](bool is_random_input) { + // Combiner test on prover polynomisls containing random values, restricted to only the standard arithmetic + // relation. + if (is_random_input) { + std::vector> instance_data(NUM_INSTANCES); + ASSERT(NUM_INSTANCES == 2); // Don't want to handle more here + ProtoGalaxyProver prover; + + for (size_t idx = 0; idx < NUM_INSTANCES; idx++) { + auto instance = std::make_shared(); + auto prover_polynomials = get_sequential_prover_polynomials( + /*log_circuit_size=*/1, idx * 128); + restrict_to_standard_arithmetic_relation(prover_polynomials); + instance->proving_key.polynomials = std::move(prover_polynomials); + instance->proving_key.circuit_size = 2; + instance_data[idx] = instance; + } + + ProverInstances instances{ instance_data }; + instances.alphas.fill( + bb::Univariate(FF(0))); // focus on the arithmetic relation only + auto pow_polynomial = PowPolynomial(std::vector{ 2 }); + pow_polynomial.compute_values(); + + // Relation parameters are all zeroes + RelationParameters relation_parameters; + // Temporary accumulator to compute the sumcheck on the second instance + typename Flavor::TupleOfArraysOfValues temporary_accumulator; + + // Accumulate arithmetic relation over 2 rows on the second instance + for (size_t i = 0; i < 2; i++) { + UltraArithmeticRelation::accumulate( + std::get<0>(temporary_accumulator), + instance_data[NUM_INSTANCES - 1]->proving_key.polynomials.get_row(i), + relation_parameters, + pow_polynomial[i]); + } + // Get the result of the 0th subrelation of the arithmetic relation + FF instance_offset = std::get<0>(temporary_accumulator)[0]; + // Subtract it from q_c[0] (it directly affect the target sum, making it zero and enabling the optimisation) + instance_data[1]->proving_key.polynomials.q_c[0] -= instance_offset; + std::vector + extended_polynomials; // These hold the extensions of prover polynomials + + // Manually extend all polynomials. Create new ProverPolynomials from extended values + for (size_t idx = NUM_INSTANCES; idx < UNIVARIATE_LENGTH; idx++) { + + auto instance = std::make_shared(); + auto prover_polynomials = get_zero_prover_polynomials(1); + for (auto [instance_0_polynomial, instance_1_polynomial, new_polynomial] : + zip_view(instance_data[0]->proving_key.polynomials.get_all(), + instance_data[1]->proving_key.polynomials.get_all(), + prover_polynomials.get_all())) { + for (size_t i = 0; i < /*circuit_size*/ 2; i++) { + new_polynomial[i] = + instance_0_polynomial[i] + ((instance_1_polynomial[i] - instance_0_polynomial[i]) * idx); + } + } + extended_polynomials.push_back(std::move(prover_polynomials)); + } + std::array precomputed_result{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + // Compute the sum for each index separately, treating each extended instance independently + for (size_t idx = 0; idx < UNIVARIATE_LENGTH; idx++) { + + typename Flavor::TupleOfArraysOfValues accumulator; + if (idx < NUM_INSTANCES) { + for (size_t i = 0; i < 2; i++) { + UltraArithmeticRelation::accumulate(std::get<0>(accumulator), + instance_data[idx]->proving_key.polynomials.get_row(i), + relation_parameters, + pow_polynomial[i]); + } + } else { + for (size_t i = 0; i < 2; i++) { + UltraArithmeticRelation::accumulate(std::get<0>(accumulator), + extended_polynomials[idx - NUM_INSTANCES].get_row(i), + relation_parameters, + pow_polynomial[i]); + } + } + precomputed_result[idx] = std::get<0>(accumulator)[0]; + } + auto expected_result = Univariate(precomputed_result); + auto result = prover.compute_combiner(instances, pow_polynomial); + auto optimised_result = prover.compute_combiner(instances, pow_polynomial); + EXPECT_EQ(result, expected_result); EXPECT_EQ(optimised_result, expected_result); } else { diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner_example_gen.py b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner_example_gen.py index 0ace782160a..bc0fb19128b 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner_example_gen.py +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner_example_gen.py @@ -6,71 +6,55 @@ EXTENDED_RELATION_LENGTH = 13 class Row: - def __init__(self, start): - - self.q_c = start + 2 * 0 - self.q_l = start + 2 * 1 - self.q_r = start + 2 * 2 - self.q_o = start + 2 * 3 - self.q_4 = start + 2 * 4 - self.q_m = start + 2 * 5 - self.q_arith = start + 2 * 6 - self.q_delta_range = start + 2 * 7 - self.q_elliptic = start + 2 * 8 - self.q_aux = start + 2 * 9 - self.q_lookup = start + 2 * 10 - self.sigma_1 = start + 2 * 11 - self.sigma_2 = start + 2 * 12 - self.sigma_3 = start + 2 * 13 - self.sigma_4 = start + 2 * 14 - self.id_1 = start + 2 * 15 - self.id_2 = start + 2 * 16 - self.id_3 = start + 2 * 17 - self.id_4 = start + 2 * 18 - self.table_1 = start + 2 * 19 - self.table_2 = start + 2 * 20 - self.table_3 = start + 2 * 21 - self.table_4 = start + 2 * 22 - self.lagrange_first = start + 2 * 23 - self.lagrange_last = start + 2 * 24 - self.w_l = start + 2 * 25 - self.w_r = start + 2 * 26 - self.w_o = start + 2 * 27 - self.w_4 = start + 2 * 28 - self.sorted_accum = start + 2 * 29 - self.z_perm = start + 2 * 30 - self.z_lookup = start + 2 * 31 - self.table_1_shift = start + 2 * 32 - self.table_2_shift = start + 2 * 33 - self.table_3_shift = start + 2 * 34 - self.table_4_shift = start + 2 * 35 - self.w_l_shift = start + 2 * 36 - self.w_r_shift = start + 2 * 37 - self.w_o_shift = start + 2 * 38 - self.w_4_shift = start + 2 * 39 - self.sorted_accum_shift = start + 2 * 40 - self.z_perm_shift = start + 2 * 41 - self.z_lookup_shift = start + 2 * 42 - - self.entities = [self.q_c, self.q_l, self.q_r, self.q_o, self.q_m, self.sigma_1, self.sigma_2, self.sigma_3, self.id_1, - self.id_2, self.id_3, self.lagrange_first, self.lagrange_last, self.w_l, self.w_r, self.w_o, self.z_perm, self.z_perm_shift] - - -class Instance: - def __init__(self, rows): - self.num_entities = len(rows[0].entities) - self.rows = rows - - -class Instances: - def __init__(self, instances): - self.num_entities = instances[0].num_entities - self.data = instances - - -def rel(w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c): - return q_m * w_l * w_r + q_l * w_l + q_r * w_r + q_o * w_o + q_c - + # Construct a set of 'all' polynomials with a very simple structure + def __init__(self, base_poly): + # Constuct polys by adding increasing factors of 2 to an input poly + self.q_m = base_poly + 2 * 0 + self.q_c = base_poly + 2 * 1 + self.q_l = base_poly + 2 * 2 + self.q_r = base_poly + 2 * 3 + self.q_o = base_poly + 2 * 4 + self.q_4 = base_poly + 2 * 5 + self.q_arith = base_poly + 2 * 6 + self.q_delta_range = base_poly + 2 * 7 + self.q_elliptic = base_poly + 2 * 8 + self.q_aux = base_poly + 2 * 9 + self.q_lookup = base_poly + 2 * 10 + self.sigma_1 = base_poly + 2 * 11 + self.sigma_2 = base_poly + 2 * 12 + self.sigma_3 = base_poly + 2 * 13 + self.sigma_4 = base_poly + 2 * 14 + self.id_1 = base_poly + 2 * 15 + self.id_2 = base_poly + 2 * 16 + self.id_3 = base_poly + 2 * 17 + self.id_4 = base_poly + 2 * 18 + self.table_1 = base_poly + 2 * 19 + self.table_2 = base_poly + 2 * 20 + self.table_3 = base_poly + 2 * 21 + self.table_4 = base_poly + 2 * 22 + self.lagrange_first = base_poly + 2 * 23 + self.lagrange_last = base_poly + 2 * 24 + self.w_l = base_poly + 2 * 25 + self.w_r = base_poly + 2 * 26 + self.w_o = base_poly + 2 * 27 + self.w_4 = base_poly + 2 * 28 + self.sorted_accum = base_poly + 2 * 29 + self.z_perm = base_poly + 2 * 30 + self.z_lookup = base_poly + 2 * 31 + self.table_1_shift = base_poly + 2 * 32 + self.table_2_shift = base_poly + 2 * 33 + self.table_3_shift = base_poly + 2 * 34 + self.table_4_shift = base_poly + 2 * 35 + self.w_l_shift = base_poly + 2 * 36 + self.w_r_shift = base_poly + 2 * 37 + self.w_o_shift = base_poly + 2 * 38 + self.w_4_shift = base_poly + 2 * 39 + self.sorted_accum_shift = base_poly + 2 * 40 + self.z_perm_shift = base_poly + 2 * 41 + self.z_lookup_shift = base_poly + 2 * 42 + + def arith_relation(self): + return self.q_m * self.w_l * self.w_r + self.q_l * self.w_l + self.q_r * self.w_r + self.q_o * self.w_o + self.q_c def extend_one_entity(input): result = input @@ -79,60 +63,54 @@ def extend_one_entity(input): result.append(delta + result[-1]) return result - -def get_extended_univariates(instances, row_idx): - rows = [instance.rows[row_idx] for instance in instances.data] - for entity_idx in range(instances.num_entities): - result = [row.entities[entity_idx] for row in rows] - result = np.array(extend_one_entity(result)) - return result - def compute_first_example(): - i0 = Instance([Row(0), Row(1)]) - i1 = Instance([Row(128), Row(129)]) - instances = Instances([i0, i1]) + # Construct baseline extensions for the two rows; extentions for all polys will be computed via the Row constructor + baseline_extension_0 = np.array(extend_one_entity([0, 128])) + baseline_extension_1 = baseline_extension_0 + 1 - row_0_extended = Row(get_extended_univariates(instances, 0)) - row_1_extended = Row(get_extended_univariates(instances, 1)) + # Construct extensions for all polys for the two rows in consideration + row_0_extended = Row(baseline_extension_0) + row_1_extended = Row(baseline_extension_1) accumulator = np.array([0 for _ in range(EXTENDED_RELATION_LENGTH)]) zeta_pow = 1 zeta = 2 for row in [row_0_extended, row_1_extended]: - relation_value = rel(row.w_l, row.w_r, row.w_o, row.q_m, - row.q_l, row.q_r, row.q_o, row.q_c) - accumulator += zeta_pow * relation_value + accumulator += zeta_pow * row.arith_relation() zeta_pow *= zeta return accumulator def compute_second_example(): - result = 0 - # 0 1 2 3 4 5 6 7 8 9 10 11 12 - w_l = np.array([ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) - w_r = np.array([ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26]) - w_o = np.array([ 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51]) - q_m = np.array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - q_l = np.array([ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) - q_r = np.array([ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) - q_o = np.array([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) - q_c = np.array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - # contribution is zero, but why not? - result += rel(w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c) - - w_l = np.array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) - w_r = np.array([ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) - w_o = np.array([ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) - q_m = np.array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) - q_l = np.array([ 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9,-10,-11]) - q_r = np.array([ 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9,-10,-11]) - q_o = np.array([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) - q_c = np.array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) - - result += rel(w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c) - result *= 2 - - return result + def arith_relation(w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c): + return q_m * w_l * w_r + q_l * w_l + q_r * w_r + q_o * w_o + q_c + + result = 0 + # 0 1 2 3 4 5 6 7 8 9 10 11 12 + w_l = np.array([ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) + w_r = np.array([ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26]) + w_o = np.array([ 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51]) + q_m = np.array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) + q_l = np.array([ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) + q_r = np.array([ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) + q_o = np.array([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) + q_c = np.array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) + # contribution is zero, but why not? + result += arith_relation(w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c) + + w_l = np.array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) + w_r = np.array([ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) + w_o = np.array([ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) + q_m = np.array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) + q_l = np.array([ 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9,-10,-11]) + q_r = np.array([ 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9,-10,-11]) + q_o = np.array([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) + q_c = np.array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) + + result += arith_relation(w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c) + result *= 2 + + return result if __name__ == "__main__": print(f"First example: \n {compute_first_example()}") diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index e8cf235f4aa..6c717c1d126 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -310,6 +310,34 @@ template class ProtoGalaxyTests : public testing::Test { } } + /** + * @brief Testing one valid round of folding followed by the decider. + * @brief For additional robustness we give one of the circuits more public inputs than the other + * + */ + static void test_full_protogalaxy_simple() + { + // Construct a first circuit with some public inputs + Builder builder1; + construct_circuit(builder1); + bb::MockCircuits::add_arithmetic_gates_with_public_inputs(builder1, /*num_gates=*/4); + + // Construct a second circuit with no public inputs + Builder builder2; + construct_circuit(builder2); + + // Construct the prover/verifier instances for each + TupleOfInstances instances; + construct_prover_and_verifier_instance(instances, builder1); + construct_prover_and_verifier_instance(instances, builder2); + + // Perform prover and verifier folding + auto [prover_accumulator, verifier_accumulator] = fold_and_verify(get<0>(instances), get<1>(instances)); + check_accumulator_target_sum_manual(prover_accumulator, true); + + decide_and_verify(prover_accumulator, verifier_accumulator, true); + } + /** * @brief Testing two valid rounds of folding followed by the decider. * @@ -489,6 +517,11 @@ TYPED_TEST(ProtoGalaxyTests, CombineAlpha) TestFixture::test_combine_alpha(); } +TYPED_TEST(ProtoGalaxyTests, FullProtogalaxySimple) +{ + TestFixture::test_full_protogalaxy_simple(); +} + TYPED_TEST(ProtoGalaxyTests, FullProtogalaxyTest) { TestFixture::test_full_protogalaxy(); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 02fbb08ff15..f38ff10b3e1 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -104,22 +104,6 @@ std::shared_ptr ProtoGalaxyProver_proving_key.public_inputs) { - el *= lagranges[0]; - size_t inst = 0; - for (size_t inst_idx = 1; inst_idx < ProverInstances::NUM; inst_idx++) { - auto& instance = instances[inst_idx]; - // TODO(https://github.com/AztecProtocol/barretenberg/issues/830) - if (instance->proving_key.num_public_inputs >= next_accumulator->proving_key.num_public_inputs) { - el += instance->proving_key.public_inputs[el_idx] * lagranges[inst]; - inst++; - }; - } - el_idx++; - } - // Evaluate the combined batching α_i univariate at challenge to obtain next α_i and send it to the // verifier, where i ∈ {0,...,NUM_SUBRELATIONS - 1} auto& folded_alphas = next_accumulator->alphas; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp index a16bacd6e3d..9ffce227620 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp @@ -115,19 +115,7 @@ std::shared_ptr ProtoGalaxyVerifier_verification_key->num_public_inputs = accumulator->verification_key->num_public_inputs; next_accumulator->public_inputs = std::vector(static_cast(next_accumulator->verification_key->num_public_inputs), 0); - size_t public_input_idx = 0; - for (auto& public_input : next_accumulator->public_inputs) { - size_t inst = 0; - for (auto& instance : instances) { - // TODO(https://github.com/AztecProtocol/barretenberg/issues/830) - if (instance->verification_key->num_public_inputs >= - next_accumulator->verification_key->num_public_inputs) { - public_input += instance->public_inputs[public_input_idx] * lagranges[inst]; - inst++; - } - } - public_input_idx++; - } + next_accumulator->is_accumulator = true; // Compute next folding parameters diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/alu.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/alu.hpp new file mode 100644 index 00000000000..eda58900a6e --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/alu.hpp @@ -0,0 +1,1187 @@ + +#pragma once +#include "../../relation_parameters.hpp" +#include "../../relation_types.hpp" +#include "./declare_views.hpp" + +namespace bb::Avm_vm { + +template struct AluRow { + FF alu_a_hi{}; + FF alu_a_hi_shift{}; + FF alu_a_lo{}; + FF alu_a_lo_shift{}; + FF alu_b_hi{}; + FF alu_b_hi_shift{}; + FF alu_b_lo{}; + FF alu_b_lo_shift{}; + FF alu_borrow{}; + FF alu_cf{}; + FF alu_cmp_rng_ctr{}; + FF alu_cmp_rng_ctr_shift{}; + FF alu_div_u16_r0{}; + FF alu_div_u16_r0_shift{}; + FF alu_div_u16_r1{}; + FF alu_div_u16_r1_shift{}; + FF alu_div_u16_r2{}; + FF alu_div_u16_r2_shift{}; + FF alu_div_u16_r3{}; + FF alu_div_u16_r3_shift{}; + FF alu_div_u16_r4{}; + FF alu_div_u16_r4_shift{}; + FF alu_div_u16_r5{}; + FF alu_div_u16_r5_shift{}; + FF alu_div_u16_r6{}; + FF alu_div_u16_r6_shift{}; + FF alu_div_u16_r7{}; + FF alu_div_u16_r7_shift{}; + FF alu_divisor_hi{}; + FF alu_divisor_lo{}; + FF alu_ff_tag{}; + FF alu_ia{}; + FF alu_ib{}; + FF alu_ic{}; + FF alu_in_tag{}; + FF alu_op_add{}; + FF alu_op_add_shift{}; + FF alu_op_cast{}; + FF alu_op_cast_prev{}; + FF alu_op_cast_prev_shift{}; + FF alu_op_cast_shift{}; + FF alu_op_div{}; + FF alu_op_div_a_lt_b{}; + FF alu_op_div_shift{}; + FF alu_op_div_std{}; + FF alu_op_eq{}; + FF alu_op_eq_diff_inv{}; + FF alu_op_lt{}; + FF alu_op_lte{}; + FF alu_op_mul{}; + FF alu_op_mul_shift{}; + FF alu_op_not{}; + FF alu_op_shl{}; + FF alu_op_shl_shift{}; + FF alu_op_shr{}; + FF alu_op_shr_shift{}; + FF alu_op_sub{}; + FF alu_op_sub_shift{}; + FF alu_p_a_borrow{}; + FF alu_p_b_borrow{}; + FF alu_p_sub_a_hi{}; + FF alu_p_sub_a_hi_shift{}; + FF alu_p_sub_a_lo{}; + FF alu_p_sub_a_lo_shift{}; + FF alu_p_sub_b_hi{}; + FF alu_p_sub_b_hi_shift{}; + FF alu_p_sub_b_lo{}; + FF alu_p_sub_b_lo_shift{}; + FF alu_partial_prod_hi{}; + FF alu_partial_prod_lo{}; + FF alu_quotient_hi{}; + FF alu_quotient_lo{}; + FF alu_remainder{}; + FF alu_res_hi{}; + FF alu_res_lo{}; + FF alu_sel_alu{}; + FF alu_sel_alu_shift{}; + FF alu_sel_cmp{}; + FF alu_sel_cmp_shift{}; + FF alu_sel_div_rng_chk{}; + FF alu_sel_div_rng_chk_shift{}; + FF alu_sel_rng_chk{}; + FF alu_sel_rng_chk_lookup_shift{}; + FF alu_sel_rng_chk_shift{}; + FF alu_sel_shift_which{}; + FF alu_shift_lt_bit_len{}; + FF alu_t_sub_s_bits{}; + FF alu_two_pow_s{}; + FF alu_two_pow_t_sub_s{}; + FF alu_u128_tag{}; + FF alu_u16_r0{}; + FF alu_u16_r0_shift{}; + FF alu_u16_r1{}; + FF alu_u16_r10{}; + FF alu_u16_r11{}; + FF alu_u16_r12{}; + FF alu_u16_r13{}; + FF alu_u16_r14{}; + FF alu_u16_r1_shift{}; + FF alu_u16_r2{}; + FF alu_u16_r2_shift{}; + FF alu_u16_r3{}; + FF alu_u16_r3_shift{}; + FF alu_u16_r4{}; + FF alu_u16_r4_shift{}; + FF alu_u16_r5{}; + FF alu_u16_r5_shift{}; + FF alu_u16_r6{}; + FF alu_u16_r6_shift{}; + FF alu_u16_r7{}; + FF alu_u16_r8{}; + FF alu_u16_r9{}; + FF alu_u16_tag{}; + FF alu_u32_tag{}; + FF alu_u64_tag{}; + FF alu_u8_r0{}; + FF alu_u8_r0_shift{}; + FF alu_u8_r1{}; + FF alu_u8_r1_shift{}; + FF alu_u8_tag{}; + + [[maybe_unused]] static std::vector names(); +}; + +inline std::string get_relation_label_alu(int index) +{ + switch (index) { + case 12: + return "ALU_ADD_SUB_1"; + + case 13: + return "ALU_ADD_SUB_2"; + + case 14: + return "ALU_MULTIPLICATION_FF"; + + case 15: + return "ALU_MUL_COMMON_1"; + + case 16: + return "ALU_MUL_COMMON_2"; + + case 19: + return "ALU_MULTIPLICATION_OUT_U128"; + + case 20: + return "ALU_FF_NOT_XOR"; + + case 21: + return "ALU_OP_NOT"; + + case 22: + return "ALU_RES_IS_BOOL"; + + case 23: + return "ALU_OP_EQ"; + + case 24: + return "INPUT_DECOMP_1"; + + case 25: + return "INPUT_DECOMP_2"; + + case 27: + return "SUB_LO_1"; + + case 28: + return "SUB_HI_1"; + + case 30: + return "SUB_LO_2"; + + case 31: + return "SUB_HI_2"; + + case 32: + return "RES_LO"; + + case 33: + return "RES_HI"; + + case 34: + return "CMP_CTR_REL_1"; + + case 35: + return "CMP_CTR_REL_2"; + + case 38: + return "CTR_NON_ZERO_REL"; + + case 39: + return "RNG_CHK_LOOKUP_SELECTOR"; + + case 40: + return "LOWER_CMP_RNG_CHK"; + + case 41: + return "UPPER_CMP_RNG_CHK"; + + case 42: + return "SHIFT_RELS_0"; + + case 44: + return "SHIFT_RELS_1"; + + case 46: + return "SHIFT_RELS_2"; + + case 48: + return "SHIFT_RELS_3"; + + case 50: + return "OP_CAST_PREV_LINE"; + + case 51: + return "ALU_OP_CAST"; + + case 52: + return "OP_CAST_RNG_CHECK_P_SUB_A_LOW"; + + case 53: + return "OP_CAST_RNG_CHECK_P_SUB_A_HIGH"; + + case 54: + return "TWO_LINE_OP_NO_OVERLAP"; + + case 55: + return "SHR_RANGE_0"; + + case 56: + return "SHR_RANGE_1"; + + case 57: + return "SHL_RANGE_0"; + + case 58: + return "SHL_RANGE_1"; + + case 60: + return "SHIFT_LT_BIT_LEN"; + + case 61: + return "SHR_INPUT_DECOMPOSITION"; + + case 62: + return "SHR_OUTPUT"; + + case 63: + return "SHL_INPUT_DECOMPOSITION"; + + case 64: + return "SHL_OUTPUT"; + + case 74: + return "ALU_PROD_DIV"; + + case 75: + return "REMAINDER_RANGE_CHK"; + + case 76: + return "CMP_CTR_REL_3"; + + case 78: + return "DIVISION_RELATION"; + } + return std::to_string(index); +} + +template class aluImpl { + public: + using FF = FF_; + + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 6, 6, 8, 3, 4, 4, 5, 4, 4, 3, 4, 3, + 3, 4, 3, 6, 5, 3, 3, 3, 3, 4, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 2, 5, 3, 3, 4, 4, 4, 4, + 4, 3, 5, 5, 4, 5, 5, 2, 3, 3, 3, 3, 3, 4, 4, 3, 5, 3, 3, 3, 5, 3, 3, 4, 4, 4, 4, 4, 4, + }; + + template + void static accumulate(ContainerOverSubrelations& evals, + const AllEntities& new_term, + [[maybe_unused]] const RelationParameters&, + [[maybe_unused]] const FF& scaling_factor) + { + + // Contribution 0 + { + Avm_DECLARE_VIEWS(0); + + auto tmp = (alu_sel_alu - + ((((((((((alu_op_add + alu_op_sub) + alu_op_mul) + alu_op_not) + alu_op_eq) + alu_op_cast) + + alu_op_lt) + + alu_op_lte) + + alu_op_shr) + + alu_op_shl) + + alu_op_div)); + tmp *= scaling_factor; + std::get<0>(evals) += tmp; + } + // Contribution 1 + { + Avm_DECLARE_VIEWS(1); + + auto tmp = (alu_sel_cmp - (alu_op_lt + alu_op_lte)); + tmp *= scaling_factor; + std::get<1>(evals) += tmp; + } + // Contribution 2 + { + Avm_DECLARE_VIEWS(2); + + auto tmp = (alu_sel_shift_which - (alu_op_shl + alu_op_shr)); + tmp *= scaling_factor; + std::get<2>(evals) += tmp; + } + // Contribution 3 + { + Avm_DECLARE_VIEWS(3); + + auto tmp = (alu_cf * (-alu_cf + FF(1))); + tmp *= scaling_factor; + std::get<3>(evals) += tmp; + } + // Contribution 4 + { + Avm_DECLARE_VIEWS(4); + + auto tmp = (alu_ff_tag * (-alu_ff_tag + FF(1))); + tmp *= scaling_factor; + std::get<4>(evals) += tmp; + } + // Contribution 5 + { + Avm_DECLARE_VIEWS(5); + + auto tmp = (alu_u8_tag * (-alu_u8_tag + FF(1))); + tmp *= scaling_factor; + std::get<5>(evals) += tmp; + } + // Contribution 6 + { + Avm_DECLARE_VIEWS(6); + + auto tmp = (alu_u16_tag * (-alu_u16_tag + FF(1))); + tmp *= scaling_factor; + std::get<6>(evals) += tmp; + } + // Contribution 7 + { + Avm_DECLARE_VIEWS(7); + + auto tmp = (alu_u32_tag * (-alu_u32_tag + FF(1))); + tmp *= scaling_factor; + std::get<7>(evals) += tmp; + } + // Contribution 8 + { + Avm_DECLARE_VIEWS(8); + + auto tmp = (alu_u64_tag * (-alu_u64_tag + FF(1))); + tmp *= scaling_factor; + std::get<8>(evals) += tmp; + } + // Contribution 9 + { + Avm_DECLARE_VIEWS(9); + + auto tmp = (alu_u128_tag * (-alu_u128_tag + FF(1))); + tmp *= scaling_factor; + std::get<9>(evals) += tmp; + } + // Contribution 10 + { + Avm_DECLARE_VIEWS(10); + + auto tmp = + (alu_sel_alu * + ((((((alu_ff_tag + alu_u8_tag) + alu_u16_tag) + alu_u32_tag) + alu_u64_tag) + alu_u128_tag) - FF(1))); + tmp *= scaling_factor; + std::get<10>(evals) += tmp; + } + // Contribution 11 + { + Avm_DECLARE_VIEWS(11); + + auto tmp = (alu_in_tag - + (((((alu_u8_tag + (alu_u16_tag * FF(2))) + (alu_u32_tag * FF(3))) + (alu_u64_tag * FF(4))) + + (alu_u128_tag * FF(5))) + + (alu_ff_tag * FF(6)))); + tmp *= scaling_factor; + std::get<11>(evals) += tmp; + } + // Contribution 12 + { + Avm_DECLARE_VIEWS(12); + + auto tmp = + (((alu_op_add + alu_op_sub) * ((((((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))) + + (alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + (alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + + (alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + + (alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))) - + alu_ia) + + (alu_ff_tag * alu_ic))) + + ((alu_op_add - alu_op_sub) * ((alu_cf * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL })) - alu_ib))); + tmp *= scaling_factor; + std::get<12>(evals) += tmp; + } + // Contribution 13 + { + Avm_DECLARE_VIEWS(13); + + auto tmp = (((alu_op_add + alu_op_sub) * + (((((((alu_u8_tag * alu_u8_r0) + (alu_u16_tag * (alu_u8_r0 + (alu_u8_r1 * FF(256))))) + + (alu_u32_tag * ((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))))) + + (alu_u64_tag * ((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))))) + + (alu_u128_tag * ((((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))) + + (alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + (alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + + (alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + + (alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))))) + + (alu_ff_tag * alu_ia)) - + alu_ic)) + + ((alu_ff_tag * (alu_op_add - alu_op_sub)) * alu_ib)); + tmp *= scaling_factor; + std::get<13>(evals) += tmp; + } + // Contribution 14 + { + Avm_DECLARE_VIEWS(14); + + auto tmp = ((alu_ff_tag * alu_op_mul) * ((alu_ia * alu_ib) - alu_ic)); + tmp *= scaling_factor; + std::get<14>(evals) += tmp; + } + // Contribution 15 + { + Avm_DECLARE_VIEWS(15); + + auto tmp = ((((-alu_ff_tag + FF(1)) - alu_u128_tag) * alu_op_mul) * + (((((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))) + + (alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + (alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + + (alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + + (alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))) - + (alu_ia * alu_ib))); + tmp *= scaling_factor; + std::get<15>(evals) += tmp; + } + // Contribution 16 + { + Avm_DECLARE_VIEWS(16); + + auto tmp = + (alu_op_mul * (((((alu_u8_tag * alu_u8_r0) + (alu_u16_tag * (alu_u8_r0 + (alu_u8_r1 * FF(256))))) + + (alu_u32_tag * ((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))))) + + (alu_u64_tag * ((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))))) - + (((-alu_ff_tag + FF(1)) - alu_u128_tag) * alu_ic))); + tmp *= scaling_factor; + std::get<16>(evals) += tmp; + } + // Contribution 17 + { + Avm_DECLARE_VIEWS(17); + + auto tmp = ((alu_u128_tag * alu_op_mul) * + ((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))) + + ((((alu_u16_r3 + (alu_u16_r4 * FF(65536))) + (alu_u16_r5 * FF(4294967296UL))) + + (alu_u16_r6 * FF(281474976710656UL))) * + FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) - + alu_ia)); + tmp *= scaling_factor; + std::get<17>(evals) += tmp; + } + // Contribution 18 + { + Avm_DECLARE_VIEWS(18); + + auto tmp = + ((alu_u128_tag * alu_op_mul) * + ((((((alu_u8_r0_shift + (alu_u8_r1_shift * FF(256))) + (alu_u16_r0_shift * FF(65536))) + + (alu_u16_r1_shift * FF(4294967296UL))) + + (alu_u16_r2_shift * FF(281474976710656UL))) + + ((((alu_u16_r3_shift + (alu_u16_r4_shift * FF(65536))) + (alu_u16_r5_shift * FF(4294967296UL))) + + (alu_u16_r6_shift * FF(281474976710656UL))) * + FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) - + alu_ib)); + tmp *= scaling_factor; + std::get<18>(evals) += tmp; + } + // Contribution 19 + { + Avm_DECLARE_VIEWS(19); + + auto tmp = + ((alu_u128_tag * alu_op_mul) * + ((((alu_ia * ((((alu_u8_r0_shift + (alu_u8_r1_shift * FF(256))) + (alu_u16_r0_shift * FF(65536))) + + (alu_u16_r1_shift * FF(4294967296UL))) + + (alu_u16_r2_shift * FF(281474976710656UL)))) + + ((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))) * + (((alu_u16_r3_shift + (alu_u16_r4_shift * FF(65536))) + (alu_u16_r5_shift * FF(4294967296UL))) + + (alu_u16_r6_shift * FF(281474976710656UL)))) * + FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) - + (((alu_cf * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL })) + + (((alu_u16_r7 + (alu_u16_r8 * FF(65536))) + (alu_u16_r9 * FF(4294967296UL))) + + (alu_u16_r10 * FF(281474976710656UL)))) * + FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - + alu_ic)); + tmp *= scaling_factor; + std::get<19>(evals) += tmp; + } + // Contribution 20 + { + Avm_DECLARE_VIEWS(20); + + auto tmp = (alu_op_not * alu_ff_tag); + tmp *= scaling_factor; + std::get<20>(evals) += tmp; + } + // Contribution 21 + { + Avm_DECLARE_VIEWS(21); + + auto tmp = (alu_op_not * + ((alu_ia + alu_ic) - + ((((((alu_u8_tag * FF(256)) + (alu_u16_tag * FF(65536))) + (alu_u32_tag * FF(4294967296UL))) + + (alu_u64_tag * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + (alu_u128_tag * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - + FF(1)))); + tmp *= scaling_factor; + std::get<21>(evals) += tmp; + } + // Contribution 22 + { + Avm_DECLARE_VIEWS(22); + + auto tmp = ((alu_sel_cmp + alu_op_eq) * (alu_ic * (-alu_ic + FF(1)))); + tmp *= scaling_factor; + std::get<22>(evals) += tmp; + } + // Contribution 23 + { + Avm_DECLARE_VIEWS(23); + + auto tmp = + (alu_op_eq * + ((((alu_ia - alu_ib) * ((alu_ic * (-alu_op_eq_diff_inv + FF(1))) + alu_op_eq_diff_inv)) - FF(1)) + + alu_ic)); + tmp *= scaling_factor; + std::get<23>(evals) += tmp; + } + // Contribution 24 + { + Avm_DECLARE_VIEWS(24); + + auto tmp = (((alu_op_lt * alu_ib) + ((alu_op_lte + alu_op_cast) * alu_ia)) - + ((alu_a_lo + (alu_a_hi * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) * (alu_sel_cmp + alu_op_cast))); + tmp *= scaling_factor; + std::get<24>(evals) += tmp; + } + // Contribution 25 + { + Avm_DECLARE_VIEWS(25); + + auto tmp = (((alu_op_lt * alu_ia) + (alu_op_lte * alu_ib)) - + ((alu_b_lo + (alu_b_hi * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) * alu_sel_cmp)); + tmp *= scaling_factor; + std::get<25>(evals) += tmp; + } + // Contribution 26 + { + Avm_DECLARE_VIEWS(26); + + auto tmp = (alu_p_a_borrow * (-alu_p_a_borrow + FF(1))); + tmp *= scaling_factor; + std::get<26>(evals) += tmp; + } + // Contribution 27 + { + Avm_DECLARE_VIEWS(27); + + auto tmp = ((alu_p_sub_a_lo - + ((-alu_a_lo + FF(uint256_t{ 4891460686036598784UL, 2896914383306846353UL, 0UL, 0UL })) + + (alu_p_a_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL })))) * + ((alu_sel_cmp + alu_op_cast) + alu_op_div_std)); + tmp *= scaling_factor; + std::get<27>(evals) += tmp; + } + // Contribution 28 + { + Avm_DECLARE_VIEWS(28); + + auto tmp = ((alu_p_sub_a_hi - + ((-alu_a_hi + FF(uint256_t{ 13281191951274694749UL, 3486998266802970665UL, 0UL, 0UL })) - + alu_p_a_borrow)) * + ((alu_sel_cmp + alu_op_cast) + alu_op_div_std)); + tmp *= scaling_factor; + std::get<28>(evals) += tmp; + } + // Contribution 29 + { + Avm_DECLARE_VIEWS(29); + + auto tmp = (alu_p_b_borrow * (-alu_p_b_borrow + FF(1))); + tmp *= scaling_factor; + std::get<29>(evals) += tmp; + } + // Contribution 30 + { + Avm_DECLARE_VIEWS(30); + + auto tmp = ((alu_p_sub_b_lo - + ((-alu_b_lo + FF(uint256_t{ 4891460686036598784UL, 2896914383306846353UL, 0UL, 0UL })) + + (alu_p_b_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL })))) * + alu_sel_cmp); + tmp *= scaling_factor; + std::get<30>(evals) += tmp; + } + // Contribution 31 + { + Avm_DECLARE_VIEWS(31); + + auto tmp = ((alu_p_sub_b_hi - + ((-alu_b_hi + FF(uint256_t{ 13281191951274694749UL, 3486998266802970665UL, 0UL, 0UL })) - + alu_p_b_borrow)) * + alu_sel_cmp); + tmp *= scaling_factor; + std::get<31>(evals) += tmp; + } + // Contribution 32 + { + Avm_DECLARE_VIEWS(32); + + auto tmp = ((alu_res_lo - + (((((alu_a_lo - alu_b_lo) - FF(1)) + (alu_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) * + ((alu_op_lt * alu_ic) + ((-alu_ic + FF(1)) * alu_op_lte))) + + (((alu_b_lo - alu_a_lo) + (alu_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) * + (-((alu_op_lt * alu_ic) + ((-alu_ic + FF(1)) * alu_op_lte)) + FF(1))))) * + alu_sel_cmp); + tmp *= scaling_factor; + std::get<32>(evals) += tmp; + } + // Contribution 33 + { + Avm_DECLARE_VIEWS(33); + + auto tmp = + ((alu_res_hi - + ((((alu_a_hi - alu_b_hi) - alu_borrow) * ((alu_op_lt * alu_ic) + ((-alu_ic + FF(1)) * alu_op_lte))) + + (((alu_b_hi - alu_a_hi) - alu_borrow) * + (-((alu_op_lt * alu_ic) + ((-alu_ic + FF(1)) * alu_op_lte)) + FF(1))))) * + alu_sel_cmp); + tmp *= scaling_factor; + std::get<33>(evals) += tmp; + } + // Contribution 34 + { + Avm_DECLARE_VIEWS(34); + + auto tmp = (((alu_cmp_rng_ctr_shift - alu_cmp_rng_ctr) + FF(1)) * alu_cmp_rng_ctr); + tmp *= scaling_factor; + std::get<34>(evals) += tmp; + } + // Contribution 35 + { + Avm_DECLARE_VIEWS(35); + + auto tmp = ((alu_cmp_rng_ctr_shift - FF(4)) * alu_sel_cmp); + tmp *= scaling_factor; + std::get<35>(evals) += tmp; + } + // Contribution 36 + { + Avm_DECLARE_VIEWS(36); + + auto tmp = (alu_sel_rng_chk * (-alu_sel_rng_chk + FF(1))); + tmp *= scaling_factor; + std::get<36>(evals) += tmp; + } + // Contribution 37 + { + Avm_DECLARE_VIEWS(37); + + auto tmp = (alu_sel_rng_chk * alu_sel_cmp); + tmp *= scaling_factor; + std::get<37>(evals) += tmp; + } + // Contribution 38 + { + Avm_DECLARE_VIEWS(38); + + auto tmp = ((alu_cmp_rng_ctr * + (((-alu_sel_rng_chk + FF(1)) * (-alu_op_eq_diff_inv + FF(1))) + alu_op_eq_diff_inv)) - + alu_sel_rng_chk); + tmp *= scaling_factor; + std::get<38>(evals) += tmp; + } + // Contribution 39 + { + Avm_DECLARE_VIEWS(39); + + auto tmp = (alu_sel_rng_chk_lookup_shift - + ((((((((((alu_sel_cmp_shift + alu_sel_rng_chk_shift) + alu_op_add_shift) + alu_op_sub_shift) + + alu_op_mul_shift) + + (alu_op_mul * alu_u128_tag)) + + alu_op_cast_shift) + + alu_op_cast_prev_shift) + + alu_op_shl_shift) + + alu_op_shr_shift) + + alu_op_div_shift)); + tmp *= scaling_factor; + std::get<39>(evals) += tmp; + } + // Contribution 40 + { + Avm_DECLARE_VIEWS(40); + + auto tmp = + (alu_a_lo - + (((((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))) + + (alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + (alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + + (alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + + (alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))) * + (((((alu_sel_rng_chk + alu_sel_cmp) + alu_op_cast) + alu_op_cast_prev) + alu_shift_lt_bit_len) + + alu_op_div))); + tmp *= scaling_factor; + std::get<40>(evals) += tmp; + } + // Contribution 41 + { + Avm_DECLARE_VIEWS(41); + + auto tmp = + (alu_a_hi - + ((((((((alu_u16_r7 + (alu_u16_r8 * FF(65536))) + (alu_u16_r9 * FF(4294967296UL))) + + (alu_u16_r10 * FF(281474976710656UL))) + + (alu_u16_r11 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + (alu_u16_r12 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + + (alu_u16_r13 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + + (alu_u16_r14 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))) * + (((((alu_sel_rng_chk + alu_sel_cmp) + alu_op_cast) + alu_op_cast_prev) + alu_shift_lt_bit_len) + + alu_op_div))); + tmp *= scaling_factor; + std::get<41>(evals) += tmp; + } + // Contribution 42 + { + Avm_DECLARE_VIEWS(42); + + auto tmp = ((alu_a_lo_shift - alu_b_lo) * alu_sel_rng_chk_shift); + tmp *= scaling_factor; + std::get<42>(evals) += tmp; + } + // Contribution 43 + { + Avm_DECLARE_VIEWS(43); + + auto tmp = ((alu_a_hi_shift - alu_b_hi) * alu_sel_rng_chk_shift); + tmp *= scaling_factor; + std::get<43>(evals) += tmp; + } + // Contribution 44 + { + Avm_DECLARE_VIEWS(44); + + auto tmp = ((alu_b_lo_shift - alu_p_sub_a_lo) * alu_sel_rng_chk_shift); + tmp *= scaling_factor; + std::get<44>(evals) += tmp; + } + // Contribution 45 + { + Avm_DECLARE_VIEWS(45); + + auto tmp = ((alu_b_hi_shift - alu_p_sub_a_hi) * alu_sel_rng_chk_shift); + tmp *= scaling_factor; + std::get<45>(evals) += tmp; + } + // Contribution 46 + { + Avm_DECLARE_VIEWS(46); + + auto tmp = ((alu_p_sub_a_lo_shift - alu_p_sub_b_lo) * alu_sel_rng_chk_shift); + tmp *= scaling_factor; + std::get<46>(evals) += tmp; + } + // Contribution 47 + { + Avm_DECLARE_VIEWS(47); + + auto tmp = ((alu_p_sub_a_hi_shift - alu_p_sub_b_hi) * alu_sel_rng_chk_shift); + tmp *= scaling_factor; + std::get<47>(evals) += tmp; + } + // Contribution 48 + { + Avm_DECLARE_VIEWS(48); + + auto tmp = ((alu_p_sub_b_lo_shift - alu_res_lo) * alu_sel_rng_chk_shift); + tmp *= scaling_factor; + std::get<48>(evals) += tmp; + } + // Contribution 49 + { + Avm_DECLARE_VIEWS(49); + + auto tmp = ((alu_p_sub_b_hi_shift - alu_res_hi) * alu_sel_rng_chk_shift); + tmp *= scaling_factor; + std::get<49>(evals) += tmp; + } + // Contribution 50 + { + Avm_DECLARE_VIEWS(50); + + auto tmp = (alu_op_cast_prev_shift - alu_op_cast); + tmp *= scaling_factor; + std::get<50>(evals) += tmp; + } + // Contribution 51 + { + Avm_DECLARE_VIEWS(51); + + auto tmp = (alu_op_cast * + (((((((alu_u8_tag * alu_u8_r0) + (alu_u16_tag * (alu_u8_r0 + (alu_u8_r1 * FF(256))))) + + (alu_u32_tag * ((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))))) + + (alu_u64_tag * ((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))))) + + (alu_u128_tag * ((((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))) + + (alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + (alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + + (alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + + (alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))))) + + (alu_ff_tag * alu_ia)) - + alu_ic)); + tmp *= scaling_factor; + std::get<51>(evals) += tmp; + } + // Contribution 52 + { + Avm_DECLARE_VIEWS(52); + + auto tmp = (alu_op_cast * (alu_a_lo_shift - alu_p_sub_a_lo)); + tmp *= scaling_factor; + std::get<52>(evals) += tmp; + } + // Contribution 53 + { + Avm_DECLARE_VIEWS(53); + + auto tmp = (alu_op_cast * (alu_a_hi_shift - alu_p_sub_a_hi)); + tmp *= scaling_factor; + std::get<53>(evals) += tmp; + } + // Contribution 54 + { + Avm_DECLARE_VIEWS(54); + + auto tmp = (((alu_op_mul * alu_u128_tag) + alu_op_cast) * alu_sel_alu_shift); + tmp *= scaling_factor; + std::get<54>(evals) += tmp; + } + // Contribution 55 + { + Avm_DECLARE_VIEWS(55); + + auto tmp = ((alu_shift_lt_bit_len * alu_op_shr) * (alu_a_lo - ((alu_two_pow_s - alu_b_lo) - FF(1)))); + tmp *= scaling_factor; + std::get<55>(evals) += tmp; + } + // Contribution 56 + { + Avm_DECLARE_VIEWS(56); + + auto tmp = ((alu_shift_lt_bit_len * alu_op_shr) * (alu_a_hi - ((alu_two_pow_t_sub_s - alu_b_hi) - FF(1)))); + tmp *= scaling_factor; + std::get<56>(evals) += tmp; + } + // Contribution 57 + { + Avm_DECLARE_VIEWS(57); + + auto tmp = ((alu_shift_lt_bit_len * alu_op_shl) * (alu_a_lo - ((alu_two_pow_t_sub_s - alu_b_lo) - FF(1)))); + tmp *= scaling_factor; + std::get<57>(evals) += tmp; + } + // Contribution 58 + { + Avm_DECLARE_VIEWS(58); + + auto tmp = ((alu_shift_lt_bit_len * alu_op_shl) * (alu_a_hi - ((alu_two_pow_s - alu_b_hi) - FF(1)))); + tmp *= scaling_factor; + std::get<58>(evals) += tmp; + } + // Contribution 59 + { + Avm_DECLARE_VIEWS(59); + + auto tmp = (alu_shift_lt_bit_len * (-alu_shift_lt_bit_len + FF(1))); + tmp *= scaling_factor; + std::get<59>(evals) += tmp; + } + // Contribution 60 + { + Avm_DECLARE_VIEWS(60); + + auto tmp = (alu_t_sub_s_bits - + (alu_sel_shift_which * + ((alu_shift_lt_bit_len * + ((((((alu_u8_tag * FF(8)) + (alu_u16_tag * FF(16))) + (alu_u32_tag * FF(32))) + + (alu_u64_tag * FF(64))) + + (alu_u128_tag * FF(128))) - + alu_ib)) + + ((-alu_shift_lt_bit_len + FF(1)) * + (alu_ib - (((((alu_u8_tag * FF(8)) + (alu_u16_tag * FF(16))) + (alu_u32_tag * FF(32))) + + (alu_u64_tag * FF(64))) + + (alu_u128_tag * FF(128)))))))); + tmp *= scaling_factor; + std::get<60>(evals) += tmp; + } + // Contribution 61 + { + Avm_DECLARE_VIEWS(61); + + auto tmp = ((alu_shift_lt_bit_len * alu_op_shr) * (((alu_b_hi * alu_two_pow_s) + alu_b_lo) - alu_ia)); + tmp *= scaling_factor; + std::get<61>(evals) += tmp; + } + // Contribution 62 + { + Avm_DECLARE_VIEWS(62); + + auto tmp = (alu_op_shr * (alu_ic - (alu_b_hi * alu_shift_lt_bit_len))); + tmp *= scaling_factor; + std::get<62>(evals) += tmp; + } + // Contribution 63 + { + Avm_DECLARE_VIEWS(63); + + auto tmp = ((alu_shift_lt_bit_len * alu_op_shl) * (((alu_b_hi * alu_two_pow_t_sub_s) + alu_b_lo) - alu_ia)); + tmp *= scaling_factor; + std::get<63>(evals) += tmp; + } + // Contribution 64 + { + Avm_DECLARE_VIEWS(64); + + auto tmp = (alu_op_shl * (alu_ic - ((alu_b_lo * alu_two_pow_s) * alu_shift_lt_bit_len))); + tmp *= scaling_factor; + std::get<64>(evals) += tmp; + } + // Contribution 65 + { + Avm_DECLARE_VIEWS(65); + + auto tmp = (alu_op_div - (alu_op_div_std + alu_op_div_a_lt_b)); + tmp *= scaling_factor; + std::get<65>(evals) += tmp; + } + // Contribution 66 + { + Avm_DECLARE_VIEWS(66); + + auto tmp = (alu_op_div_a_lt_b * (-alu_op_div_a_lt_b + FF(1))); + tmp *= scaling_factor; + std::get<66>(evals) += tmp; + } + // Contribution 67 + { + Avm_DECLARE_VIEWS(67); + + auto tmp = (alu_op_div_a_lt_b * (alu_a_lo - ((alu_ib - alu_ia) - FF(1)))); + tmp *= scaling_factor; + std::get<67>(evals) += tmp; + } + // Contribution 68 + { + Avm_DECLARE_VIEWS(68); + + auto tmp = (alu_op_div_a_lt_b * alu_ic); + tmp *= scaling_factor; + std::get<68>(evals) += tmp; + } + // Contribution 69 + { + Avm_DECLARE_VIEWS(69); + + auto tmp = (alu_op_div_a_lt_b * (alu_ia - alu_remainder)); + tmp *= scaling_factor; + std::get<69>(evals) += tmp; + } + // Contribution 70 + { + Avm_DECLARE_VIEWS(70); + + auto tmp = (alu_op_div_std * (-alu_op_div_std + FF(1))); + tmp *= scaling_factor; + std::get<70>(evals) += tmp; + } + // Contribution 71 + { + Avm_DECLARE_VIEWS(71); + + auto tmp = + (alu_op_div_std * ((alu_ib - alu_divisor_lo) - (alu_divisor_hi * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL })))); + tmp *= scaling_factor; + std::get<71>(evals) += tmp; + } + // Contribution 72 + { + Avm_DECLARE_VIEWS(72); + + auto tmp = (alu_op_div_std * + ((alu_ic - alu_quotient_lo) - (alu_quotient_hi * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL })))); + tmp *= scaling_factor; + std::get<72>(evals) += tmp; + } + // Contribution 73 + { + Avm_DECLARE_VIEWS(73); + + auto tmp = (((alu_divisor_hi * alu_quotient_lo) + (alu_divisor_lo * alu_quotient_hi)) - + (alu_partial_prod_lo + (alu_partial_prod_hi * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL })))); + tmp *= scaling_factor; + std::get<73>(evals) += tmp; + } + // Contribution 74 + { + Avm_DECLARE_VIEWS(74); + + auto tmp = + (alu_op_div_std * + ((((alu_divisor_lo * alu_quotient_lo) + (alu_partial_prod_lo * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + ((alu_partial_prod_hi + (alu_divisor_hi * alu_quotient_hi)) * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - + (alu_a_lo + (alu_a_hi * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))))); + tmp *= scaling_factor; + std::get<74>(evals) += tmp; + } + // Contribution 75 + { + Avm_DECLARE_VIEWS(75); + + auto tmp = (alu_op_div_std * (alu_b_hi - ((alu_ib - alu_remainder) - FF(1)))); + tmp *= scaling_factor; + std::get<75>(evals) += tmp; + } + // Contribution 76 + { + Avm_DECLARE_VIEWS(76); + + auto tmp = ((alu_cmp_rng_ctr_shift - FF(2)) * alu_op_div_std); + tmp *= scaling_factor; + std::get<76>(evals) += tmp; + } + // Contribution 77 + { + Avm_DECLARE_VIEWS(77); + + auto tmp = (alu_sel_rng_chk * alu_op_div_std); + tmp *= scaling_factor; + std::get<77>(evals) += tmp; + } + // Contribution 78 + { + Avm_DECLARE_VIEWS(78); + + auto tmp = + (alu_op_div_std * + ((((alu_divisor_lo * alu_quotient_lo) + (alu_partial_prod_lo * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + ((alu_partial_prod_hi + (alu_divisor_hi * alu_quotient_hi)) * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - + (alu_ia - alu_remainder))); + tmp *= scaling_factor; + std::get<78>(evals) += tmp; + } + // Contribution 79 + { + Avm_DECLARE_VIEWS(79); + + auto tmp = (alu_sel_div_rng_chk * (-alu_sel_div_rng_chk + FF(1))); + tmp *= scaling_factor; + std::get<79>(evals) += tmp; + } + // Contribution 80 + { + Avm_DECLARE_VIEWS(80); + + auto tmp = ((alu_sel_div_rng_chk * alu_sel_div_rng_chk_shift) - alu_op_div_std); + tmp *= scaling_factor; + std::get<80>(evals) += tmp; + } + // Contribution 81 + { + Avm_DECLARE_VIEWS(81); + + auto tmp = (alu_divisor_lo - (alu_op_div_std * (((alu_div_u16_r0 + (alu_div_u16_r1 * FF(65536))) + + (alu_div_u16_r2 * FF(4294967296UL))) + + (alu_div_u16_r3 * FF(281474976710656UL))))); + tmp *= scaling_factor; + std::get<81>(evals) += tmp; + } + // Contribution 82 + { + Avm_DECLARE_VIEWS(82); + + auto tmp = (alu_divisor_hi - (alu_op_div_std * (((alu_div_u16_r4 + (alu_div_u16_r5 * FF(65536))) + + (alu_div_u16_r6 * FF(4294967296UL))) + + (alu_div_u16_r7 * FF(281474976710656UL))))); + tmp *= scaling_factor; + std::get<82>(evals) += tmp; + } + // Contribution 83 + { + Avm_DECLARE_VIEWS(83); + + auto tmp = + (alu_quotient_lo - (alu_op_div_std * (((alu_div_u16_r0_shift + (alu_div_u16_r1_shift * FF(65536))) + + (alu_div_u16_r2_shift * FF(4294967296UL))) + + (alu_div_u16_r3_shift * FF(281474976710656UL))))); + tmp *= scaling_factor; + std::get<83>(evals) += tmp; + } + // Contribution 84 + { + Avm_DECLARE_VIEWS(84); + + auto tmp = + (alu_quotient_hi - (alu_op_div_std * (((alu_div_u16_r4_shift + (alu_div_u16_r5_shift * FF(65536))) + + (alu_div_u16_r6_shift * FF(4294967296UL))) + + (alu_div_u16_r7_shift * FF(281474976710656UL))))); + tmp *= scaling_factor; + std::get<84>(evals) += tmp; + } + // Contribution 85 + { + Avm_DECLARE_VIEWS(85); + + auto tmp = (alu_partial_prod_lo - (alu_op_div_std * ((((alu_u8_r0_shift + (alu_u8_r1_shift * FF(256))) + + (alu_u16_r0_shift * FF(65536))) + + (alu_u16_r1_shift * FF(4294967296UL))) + + (alu_u16_r2_shift * FF(281474976710656UL))))); + tmp *= scaling_factor; + std::get<85>(evals) += tmp; + } + // Contribution 86 + { + Avm_DECLARE_VIEWS(86); + + auto tmp = (alu_partial_prod_hi - (alu_op_div_std * (((alu_u16_r3_shift + (alu_u16_r4_shift * FF(65536))) + + (alu_u16_r5_shift * FF(4294967296UL))) + + (alu_u16_r6_shift * FF(281474976710656UL))))); + tmp *= scaling_factor; + std::get<86>(evals) += tmp; + } + } +}; + +template using alu = Relation>; + +} // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_alu.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_alu.hpp deleted file mode 100644 index 013013909c3..00000000000 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_alu.hpp +++ /dev/null @@ -1,1222 +0,0 @@ - -#pragma once -#include "../../relation_parameters.hpp" -#include "../../relation_types.hpp" -#include "./declare_views.hpp" - -namespace bb::Avm_vm { - -template struct Avm_aluRow { - FF avm_alu_a_hi{}; - FF avm_alu_a_hi_shift{}; - FF avm_alu_a_lo{}; - FF avm_alu_a_lo_shift{}; - FF avm_alu_alu_sel{}; - FF avm_alu_alu_sel_shift{}; - FF avm_alu_b_hi{}; - FF avm_alu_b_hi_shift{}; - FF avm_alu_b_lo{}; - FF avm_alu_b_lo_shift{}; - FF avm_alu_borrow{}; - FF avm_alu_cf{}; - FF avm_alu_cmp_rng_ctr{}; - FF avm_alu_cmp_rng_ctr_shift{}; - FF avm_alu_cmp_sel{}; - FF avm_alu_cmp_sel_shift{}; - FF avm_alu_div_rng_chk_selector{}; - FF avm_alu_div_rng_chk_selector_shift{}; - FF avm_alu_div_u16_r0{}; - FF avm_alu_div_u16_r0_shift{}; - FF avm_alu_div_u16_r1{}; - FF avm_alu_div_u16_r1_shift{}; - FF avm_alu_div_u16_r2{}; - FF avm_alu_div_u16_r2_shift{}; - FF avm_alu_div_u16_r3{}; - FF avm_alu_div_u16_r3_shift{}; - FF avm_alu_div_u16_r4{}; - FF avm_alu_div_u16_r4_shift{}; - FF avm_alu_div_u16_r5{}; - FF avm_alu_div_u16_r5_shift{}; - FF avm_alu_div_u16_r6{}; - FF avm_alu_div_u16_r6_shift{}; - FF avm_alu_div_u16_r7{}; - FF avm_alu_div_u16_r7_shift{}; - FF avm_alu_divisor_hi{}; - FF avm_alu_divisor_lo{}; - FF avm_alu_ff_tag{}; - FF avm_alu_ia{}; - FF avm_alu_ib{}; - FF avm_alu_ic{}; - FF avm_alu_in_tag{}; - FF avm_alu_op_add{}; - FF avm_alu_op_add_shift{}; - FF avm_alu_op_cast{}; - FF avm_alu_op_cast_prev{}; - FF avm_alu_op_cast_prev_shift{}; - FF avm_alu_op_cast_shift{}; - FF avm_alu_op_div{}; - FF avm_alu_op_div_a_lt_b{}; - FF avm_alu_op_div_shift{}; - FF avm_alu_op_div_std{}; - FF avm_alu_op_eq{}; - FF avm_alu_op_eq_diff_inv{}; - FF avm_alu_op_lt{}; - FF avm_alu_op_lte{}; - FF avm_alu_op_mul{}; - FF avm_alu_op_mul_shift{}; - FF avm_alu_op_not{}; - FF avm_alu_op_shl{}; - FF avm_alu_op_shl_shift{}; - FF avm_alu_op_shr{}; - FF avm_alu_op_shr_shift{}; - FF avm_alu_op_sub{}; - FF avm_alu_op_sub_shift{}; - FF avm_alu_p_a_borrow{}; - FF avm_alu_p_b_borrow{}; - FF avm_alu_p_sub_a_hi{}; - FF avm_alu_p_sub_a_hi_shift{}; - FF avm_alu_p_sub_a_lo{}; - FF avm_alu_p_sub_a_lo_shift{}; - FF avm_alu_p_sub_b_hi{}; - FF avm_alu_p_sub_b_hi_shift{}; - FF avm_alu_p_sub_b_lo{}; - FF avm_alu_p_sub_b_lo_shift{}; - FF avm_alu_partial_prod_hi{}; - FF avm_alu_partial_prod_lo{}; - FF avm_alu_quotient_hi{}; - FF avm_alu_quotient_lo{}; - FF avm_alu_remainder{}; - FF avm_alu_res_hi{}; - FF avm_alu_res_lo{}; - FF avm_alu_rng_chk_lookup_selector_shift{}; - FF avm_alu_rng_chk_sel{}; - FF avm_alu_rng_chk_sel_shift{}; - FF avm_alu_shift_lt_bit_len{}; - FF avm_alu_shift_sel{}; - FF avm_alu_t_sub_s_bits{}; - FF avm_alu_two_pow_s{}; - FF avm_alu_two_pow_t_sub_s{}; - FF avm_alu_u128_tag{}; - FF avm_alu_u16_r0{}; - FF avm_alu_u16_r0_shift{}; - FF avm_alu_u16_r1{}; - FF avm_alu_u16_r10{}; - FF avm_alu_u16_r11{}; - FF avm_alu_u16_r12{}; - FF avm_alu_u16_r13{}; - FF avm_alu_u16_r14{}; - FF avm_alu_u16_r1_shift{}; - FF avm_alu_u16_r2{}; - FF avm_alu_u16_r2_shift{}; - FF avm_alu_u16_r3{}; - FF avm_alu_u16_r3_shift{}; - FF avm_alu_u16_r4{}; - FF avm_alu_u16_r4_shift{}; - FF avm_alu_u16_r5{}; - FF avm_alu_u16_r5_shift{}; - FF avm_alu_u16_r6{}; - FF avm_alu_u16_r6_shift{}; - FF avm_alu_u16_r7{}; - FF avm_alu_u16_r8{}; - FF avm_alu_u16_r9{}; - FF avm_alu_u16_tag{}; - FF avm_alu_u32_tag{}; - FF avm_alu_u64_tag{}; - FF avm_alu_u8_r0{}; - FF avm_alu_u8_r0_shift{}; - FF avm_alu_u8_r1{}; - FF avm_alu_u8_r1_shift{}; - FF avm_alu_u8_tag{}; - - [[maybe_unused]] static std::vector names(); -}; - -inline std::string get_relation_label_avm_alu(int index) -{ - switch (index) { - case 12: - return "ALU_ADD_SUB_1"; - - case 13: - return "ALU_ADD_SUB_2"; - - case 14: - return "ALU_MULTIPLICATION_FF"; - - case 15: - return "ALU_MUL_COMMON_1"; - - case 16: - return "ALU_MUL_COMMON_2"; - - case 19: - return "ALU_MULTIPLICATION_OUT_U128"; - - case 20: - return "ALU_FF_NOT_XOR"; - - case 21: - return "ALU_OP_NOT"; - - case 22: - return "ALU_RES_IS_BOOL"; - - case 23: - return "ALU_OP_EQ"; - - case 24: - return "INPUT_DECOMP_1"; - - case 25: - return "INPUT_DECOMP_2"; - - case 27: - return "SUB_LO_1"; - - case 28: - return "SUB_HI_1"; - - case 30: - return "SUB_LO_2"; - - case 31: - return "SUB_HI_2"; - - case 32: - return "RES_LO"; - - case 33: - return "RES_HI"; - - case 34: - return "CMP_CTR_REL_1"; - - case 35: - return "CMP_CTR_REL_2"; - - case 38: - return "CTR_NON_ZERO_REL"; - - case 39: - return "RNG_CHK_LOOKUP_SELECTOR"; - - case 40: - return "LOWER_CMP_RNG_CHK"; - - case 41: - return "UPPER_CMP_RNG_CHK"; - - case 42: - return "SHIFT_RELS_0"; - - case 44: - return "SHIFT_RELS_1"; - - case 46: - return "SHIFT_RELS_2"; - - case 48: - return "SHIFT_RELS_3"; - - case 50: - return "OP_CAST_PREV_LINE"; - - case 51: - return "ALU_OP_CAST"; - - case 52: - return "OP_CAST_RNG_CHECK_P_SUB_A_LOW"; - - case 53: - return "OP_CAST_RNG_CHECK_P_SUB_A_HIGH"; - - case 54: - return "TWO_LINE_OP_NO_OVERLAP"; - - case 55: - return "SHR_RANGE_0"; - - case 56: - return "SHR_RANGE_1"; - - case 57: - return "SHL_RANGE_0"; - - case 58: - return "SHL_RANGE_1"; - - case 60: - return "SHIFT_LT_BIT_LEN"; - - case 61: - return "SHR_INPUT_DECOMPOSITION"; - - case 62: - return "SHR_OUTPUT"; - - case 63: - return "SHL_INPUT_DECOMPOSITION"; - - case 64: - return "SHL_OUTPUT"; - - case 74: - return "ALU_PROD_DIV"; - - case 75: - return "REMAINDER_RANGE_CHK"; - - case 76: - return "CMP_CTR_REL_3"; - - case 78: - return "DIVISION_RELATION"; - } - return std::to_string(index); -} - -template class avm_aluImpl { - public: - using FF = FF_; - - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 6, 6, 8, 3, 4, 4, 5, 4, 4, 3, 4, 3, - 3, 4, 3, 6, 5, 3, 3, 3, 3, 4, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 2, 5, 3, 3, 4, 4, 4, 4, - 4, 3, 5, 5, 4, 5, 5, 2, 3, 3, 3, 3, 3, 4, 4, 3, 5, 3, 3, 3, 5, 3, 3, 4, 4, 4, 4, 4, 4, - }; - - template - void static accumulate(ContainerOverSubrelations& evals, - const AllEntities& new_term, - [[maybe_unused]] const RelationParameters&, - [[maybe_unused]] const FF& scaling_factor) - { - - // Contribution 0 - { - Avm_DECLARE_VIEWS(0); - - auto tmp = - (avm_alu_alu_sel - - ((((((((((avm_alu_op_add + avm_alu_op_sub) + avm_alu_op_mul) + avm_alu_op_not) + avm_alu_op_eq) + - avm_alu_op_cast) + - avm_alu_op_lt) + - avm_alu_op_lte) + - avm_alu_op_shr) + - avm_alu_op_shl) + - avm_alu_op_div)); - tmp *= scaling_factor; - std::get<0>(evals) += tmp; - } - // Contribution 1 - { - Avm_DECLARE_VIEWS(1); - - auto tmp = (avm_alu_cmp_sel - (avm_alu_op_lt + avm_alu_op_lte)); - tmp *= scaling_factor; - std::get<1>(evals) += tmp; - } - // Contribution 2 - { - Avm_DECLARE_VIEWS(2); - - auto tmp = (avm_alu_shift_sel - (avm_alu_op_shl + avm_alu_op_shr)); - tmp *= scaling_factor; - std::get<2>(evals) += tmp; - } - // Contribution 3 - { - Avm_DECLARE_VIEWS(3); - - auto tmp = (avm_alu_cf * (-avm_alu_cf + FF(1))); - tmp *= scaling_factor; - std::get<3>(evals) += tmp; - } - // Contribution 4 - { - Avm_DECLARE_VIEWS(4); - - auto tmp = (avm_alu_ff_tag * (-avm_alu_ff_tag + FF(1))); - tmp *= scaling_factor; - std::get<4>(evals) += tmp; - } - // Contribution 5 - { - Avm_DECLARE_VIEWS(5); - - auto tmp = (avm_alu_u8_tag * (-avm_alu_u8_tag + FF(1))); - tmp *= scaling_factor; - std::get<5>(evals) += tmp; - } - // Contribution 6 - { - Avm_DECLARE_VIEWS(6); - - auto tmp = (avm_alu_u16_tag * (-avm_alu_u16_tag + FF(1))); - tmp *= scaling_factor; - std::get<6>(evals) += tmp; - } - // Contribution 7 - { - Avm_DECLARE_VIEWS(7); - - auto tmp = (avm_alu_u32_tag * (-avm_alu_u32_tag + FF(1))); - tmp *= scaling_factor; - std::get<7>(evals) += tmp; - } - // Contribution 8 - { - Avm_DECLARE_VIEWS(8); - - auto tmp = (avm_alu_u64_tag * (-avm_alu_u64_tag + FF(1))); - tmp *= scaling_factor; - std::get<8>(evals) += tmp; - } - // Contribution 9 - { - Avm_DECLARE_VIEWS(9); - - auto tmp = (avm_alu_u128_tag * (-avm_alu_u128_tag + FF(1))); - tmp *= scaling_factor; - std::get<9>(evals) += tmp; - } - // Contribution 10 - { - Avm_DECLARE_VIEWS(10); - - auto tmp = - (avm_alu_alu_sel * - ((((((avm_alu_ff_tag + avm_alu_u8_tag) + avm_alu_u16_tag) + avm_alu_u32_tag) + avm_alu_u64_tag) + - avm_alu_u128_tag) - - FF(1))); - tmp *= scaling_factor; - std::get<10>(evals) += tmp; - } - // Contribution 11 - { - Avm_DECLARE_VIEWS(11); - - auto tmp = (avm_alu_in_tag - (((((avm_alu_u8_tag + (avm_alu_u16_tag * FF(2))) + (avm_alu_u32_tag * FF(3))) + - (avm_alu_u64_tag * FF(4))) + - (avm_alu_u128_tag * FF(5))) + - (avm_alu_ff_tag * FF(6)))); - tmp *= scaling_factor; - std::get<11>(evals) += tmp; - } - // Contribution 12 - { - Avm_DECLARE_VIEWS(12); - - auto tmp = (((avm_alu_op_add + avm_alu_op_sub) * - ((((((((((avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))) + (avm_alu_u16_r0 * FF(65536))) + - (avm_alu_u16_r1 * FF(4294967296UL))) + - (avm_alu_u16_r2 * FF(281474976710656UL))) + - (avm_alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - (avm_alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + - (avm_alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + - (avm_alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))) - - avm_alu_ia) + - (avm_alu_ff_tag * avm_alu_ic))) + - ((avm_alu_op_add - avm_alu_op_sub) * - ((avm_alu_cf * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL })) - avm_alu_ib))); - tmp *= scaling_factor; - std::get<12>(evals) += tmp; - } - // Contribution 13 - { - Avm_DECLARE_VIEWS(13); - - auto tmp = (((avm_alu_op_add + avm_alu_op_sub) * - (((((((avm_alu_u8_tag * avm_alu_u8_r0) + - (avm_alu_u16_tag * (avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))))) + - (avm_alu_u32_tag * - ((avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))) + (avm_alu_u16_r0 * FF(65536))))) + - (avm_alu_u64_tag * - ((((avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))) + (avm_alu_u16_r0 * FF(65536))) + - (avm_alu_u16_r1 * FF(4294967296UL))) + - (avm_alu_u16_r2 * FF(281474976710656UL))))) + - (avm_alu_u128_tag * - ((((((((avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))) + (avm_alu_u16_r0 * FF(65536))) + - (avm_alu_u16_r1 * FF(4294967296UL))) + - (avm_alu_u16_r2 * FF(281474976710656UL))) + - (avm_alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - (avm_alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + - (avm_alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + - (avm_alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))))) + - (avm_alu_ff_tag * avm_alu_ia)) - - avm_alu_ic)) + - ((avm_alu_ff_tag * (avm_alu_op_add - avm_alu_op_sub)) * avm_alu_ib)); - tmp *= scaling_factor; - std::get<13>(evals) += tmp; - } - // Contribution 14 - { - Avm_DECLARE_VIEWS(14); - - auto tmp = ((avm_alu_ff_tag * avm_alu_op_mul) * ((avm_alu_ia * avm_alu_ib) - avm_alu_ic)); - tmp *= scaling_factor; - std::get<14>(evals) += tmp; - } - // Contribution 15 - { - Avm_DECLARE_VIEWS(15); - - auto tmp = ((((-avm_alu_ff_tag + FF(1)) - avm_alu_u128_tag) * avm_alu_op_mul) * - (((((((((avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))) + (avm_alu_u16_r0 * FF(65536))) + - (avm_alu_u16_r1 * FF(4294967296UL))) + - (avm_alu_u16_r2 * FF(281474976710656UL))) + - (avm_alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - (avm_alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + - (avm_alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + - (avm_alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))) - - (avm_alu_ia * avm_alu_ib))); - tmp *= scaling_factor; - std::get<15>(evals) += tmp; - } - // Contribution 16 - { - Avm_DECLARE_VIEWS(16); - - auto tmp = - (avm_alu_op_mul * - (((((avm_alu_u8_tag * avm_alu_u8_r0) + - (avm_alu_u16_tag * (avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))))) + - (avm_alu_u32_tag * ((avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))) + (avm_alu_u16_r0 * FF(65536))))) + - (avm_alu_u64_tag * ((((avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))) + (avm_alu_u16_r0 * FF(65536))) + - (avm_alu_u16_r1 * FF(4294967296UL))) + - (avm_alu_u16_r2 * FF(281474976710656UL))))) - - (((-avm_alu_ff_tag + FF(1)) - avm_alu_u128_tag) * avm_alu_ic))); - tmp *= scaling_factor; - std::get<16>(evals) += tmp; - } - // Contribution 17 - { - Avm_DECLARE_VIEWS(17); - - auto tmp = ((avm_alu_u128_tag * avm_alu_op_mul) * - ((((((avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))) + (avm_alu_u16_r0 * FF(65536))) + - (avm_alu_u16_r1 * FF(4294967296UL))) + - (avm_alu_u16_r2 * FF(281474976710656UL))) + - ((((avm_alu_u16_r3 + (avm_alu_u16_r4 * FF(65536))) + (avm_alu_u16_r5 * FF(4294967296UL))) + - (avm_alu_u16_r6 * FF(281474976710656UL))) * - FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) - - avm_alu_ia)); - tmp *= scaling_factor; - std::get<17>(evals) += tmp; - } - // Contribution 18 - { - Avm_DECLARE_VIEWS(18); - - auto tmp = - ((avm_alu_u128_tag * avm_alu_op_mul) * - ((((((avm_alu_u8_r0_shift + (avm_alu_u8_r1_shift * FF(256))) + (avm_alu_u16_r0_shift * FF(65536))) + - (avm_alu_u16_r1_shift * FF(4294967296UL))) + - (avm_alu_u16_r2_shift * FF(281474976710656UL))) + - ((((avm_alu_u16_r3_shift + (avm_alu_u16_r4_shift * FF(65536))) + - (avm_alu_u16_r5_shift * FF(4294967296UL))) + - (avm_alu_u16_r6_shift * FF(281474976710656UL))) * - FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) - - avm_alu_ib)); - tmp *= scaling_factor; - std::get<18>(evals) += tmp; - } - // Contribution 19 - { - Avm_DECLARE_VIEWS(19); - - auto tmp = - ((avm_alu_u128_tag * avm_alu_op_mul) * - ((((avm_alu_ia * - ((((avm_alu_u8_r0_shift + (avm_alu_u8_r1_shift * FF(256))) + (avm_alu_u16_r0_shift * FF(65536))) + - (avm_alu_u16_r1_shift * FF(4294967296UL))) + - (avm_alu_u16_r2_shift * FF(281474976710656UL)))) + - ((((((avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))) + (avm_alu_u16_r0 * FF(65536))) + - (avm_alu_u16_r1 * FF(4294967296UL))) + - (avm_alu_u16_r2 * FF(281474976710656UL))) * - (((avm_alu_u16_r3_shift + (avm_alu_u16_r4_shift * FF(65536))) + - (avm_alu_u16_r5_shift * FF(4294967296UL))) + - (avm_alu_u16_r6_shift * FF(281474976710656UL)))) * - FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) - - (((avm_alu_cf * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL })) + - (((avm_alu_u16_r7 + (avm_alu_u16_r8 * FF(65536))) + (avm_alu_u16_r9 * FF(4294967296UL))) + - (avm_alu_u16_r10 * FF(281474976710656UL)))) * - FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - - avm_alu_ic)); - tmp *= scaling_factor; - std::get<19>(evals) += tmp; - } - // Contribution 20 - { - Avm_DECLARE_VIEWS(20); - - auto tmp = (avm_alu_op_not * avm_alu_ff_tag); - tmp *= scaling_factor; - std::get<20>(evals) += tmp; - } - // Contribution 21 - { - Avm_DECLARE_VIEWS(21); - - auto tmp = (avm_alu_op_not * - ((avm_alu_ia + avm_alu_ic) - ((((((avm_alu_u8_tag * FF(256)) + (avm_alu_u16_tag * FF(65536))) + - (avm_alu_u32_tag * FF(4294967296UL))) + - (avm_alu_u64_tag * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - (avm_alu_u128_tag * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - - FF(1)))); - tmp *= scaling_factor; - std::get<21>(evals) += tmp; - } - // Contribution 22 - { - Avm_DECLARE_VIEWS(22); - - auto tmp = ((avm_alu_cmp_sel + avm_alu_op_eq) * (avm_alu_ic * (-avm_alu_ic + FF(1)))); - tmp *= scaling_factor; - std::get<22>(evals) += tmp; - } - // Contribution 23 - { - Avm_DECLARE_VIEWS(23); - - auto tmp = - (avm_alu_op_eq * ((((avm_alu_ia - avm_alu_ib) * - ((avm_alu_ic * (-avm_alu_op_eq_diff_inv + FF(1))) + avm_alu_op_eq_diff_inv)) - - FF(1)) + - avm_alu_ic)); - tmp *= scaling_factor; - std::get<23>(evals) += tmp; - } - // Contribution 24 - { - Avm_DECLARE_VIEWS(24); - - auto tmp = (((avm_alu_op_lt * avm_alu_ib) + ((avm_alu_op_lte + avm_alu_op_cast) * avm_alu_ia)) - - ((avm_alu_a_lo + (avm_alu_a_hi * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) * - (avm_alu_cmp_sel + avm_alu_op_cast))); - tmp *= scaling_factor; - std::get<24>(evals) += tmp; - } - // Contribution 25 - { - Avm_DECLARE_VIEWS(25); - - auto tmp = (((avm_alu_op_lt * avm_alu_ia) + (avm_alu_op_lte * avm_alu_ib)) - - ((avm_alu_b_lo + (avm_alu_b_hi * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) * avm_alu_cmp_sel)); - tmp *= scaling_factor; - std::get<25>(evals) += tmp; - } - // Contribution 26 - { - Avm_DECLARE_VIEWS(26); - - auto tmp = (avm_alu_p_a_borrow * (-avm_alu_p_a_borrow + FF(1))); - tmp *= scaling_factor; - std::get<26>(evals) += tmp; - } - // Contribution 27 - { - Avm_DECLARE_VIEWS(27); - - auto tmp = ((avm_alu_p_sub_a_lo - - ((-avm_alu_a_lo + FF(uint256_t{ 4891460686036598784UL, 2896914383306846353UL, 0UL, 0UL })) + - (avm_alu_p_a_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL })))) * - ((avm_alu_cmp_sel + avm_alu_op_cast) + avm_alu_op_div_std)); - tmp *= scaling_factor; - std::get<27>(evals) += tmp; - } - // Contribution 28 - { - Avm_DECLARE_VIEWS(28); - - auto tmp = ((avm_alu_p_sub_a_hi - - ((-avm_alu_a_hi + FF(uint256_t{ 13281191951274694749UL, 3486998266802970665UL, 0UL, 0UL })) - - avm_alu_p_a_borrow)) * - ((avm_alu_cmp_sel + avm_alu_op_cast) + avm_alu_op_div_std)); - tmp *= scaling_factor; - std::get<28>(evals) += tmp; - } - // Contribution 29 - { - Avm_DECLARE_VIEWS(29); - - auto tmp = (avm_alu_p_b_borrow * (-avm_alu_p_b_borrow + FF(1))); - tmp *= scaling_factor; - std::get<29>(evals) += tmp; - } - // Contribution 30 - { - Avm_DECLARE_VIEWS(30); - - auto tmp = ((avm_alu_p_sub_b_lo - - ((-avm_alu_b_lo + FF(uint256_t{ 4891460686036598784UL, 2896914383306846353UL, 0UL, 0UL })) + - (avm_alu_p_b_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL })))) * - avm_alu_cmp_sel); - tmp *= scaling_factor; - std::get<30>(evals) += tmp; - } - // Contribution 31 - { - Avm_DECLARE_VIEWS(31); - - auto tmp = ((avm_alu_p_sub_b_hi - - ((-avm_alu_b_hi + FF(uint256_t{ 13281191951274694749UL, 3486998266802970665UL, 0UL, 0UL })) - - avm_alu_p_b_borrow)) * - avm_alu_cmp_sel); - tmp *= scaling_factor; - std::get<31>(evals) += tmp; - } - // Contribution 32 - { - Avm_DECLARE_VIEWS(32); - - auto tmp = - ((avm_alu_res_lo - - (((((avm_alu_a_lo - avm_alu_b_lo) - FF(1)) + (avm_alu_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) * - ((avm_alu_op_lt * avm_alu_ic) + ((-avm_alu_ic + FF(1)) * avm_alu_op_lte))) + - (((avm_alu_b_lo - avm_alu_a_lo) + (avm_alu_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) * - (-((avm_alu_op_lt * avm_alu_ic) + ((-avm_alu_ic + FF(1)) * avm_alu_op_lte)) + FF(1))))) * - avm_alu_cmp_sel); - tmp *= scaling_factor; - std::get<32>(evals) += tmp; - } - // Contribution 33 - { - Avm_DECLARE_VIEWS(33); - - auto tmp = ((avm_alu_res_hi - - ((((avm_alu_a_hi - avm_alu_b_hi) - avm_alu_borrow) * - ((avm_alu_op_lt * avm_alu_ic) + ((-avm_alu_ic + FF(1)) * avm_alu_op_lte))) + - (((avm_alu_b_hi - avm_alu_a_hi) - avm_alu_borrow) * - (-((avm_alu_op_lt * avm_alu_ic) + ((-avm_alu_ic + FF(1)) * avm_alu_op_lte)) + FF(1))))) * - avm_alu_cmp_sel); - tmp *= scaling_factor; - std::get<33>(evals) += tmp; - } - // Contribution 34 - { - Avm_DECLARE_VIEWS(34); - - auto tmp = (((avm_alu_cmp_rng_ctr_shift - avm_alu_cmp_rng_ctr) + FF(1)) * avm_alu_cmp_rng_ctr); - tmp *= scaling_factor; - std::get<34>(evals) += tmp; - } - // Contribution 35 - { - Avm_DECLARE_VIEWS(35); - - auto tmp = ((avm_alu_cmp_rng_ctr_shift - FF(4)) * avm_alu_cmp_sel); - tmp *= scaling_factor; - std::get<35>(evals) += tmp; - } - // Contribution 36 - { - Avm_DECLARE_VIEWS(36); - - auto tmp = (avm_alu_rng_chk_sel * (-avm_alu_rng_chk_sel + FF(1))); - tmp *= scaling_factor; - std::get<36>(evals) += tmp; - } - // Contribution 37 - { - Avm_DECLARE_VIEWS(37); - - auto tmp = (avm_alu_rng_chk_sel * avm_alu_cmp_sel); - tmp *= scaling_factor; - std::get<37>(evals) += tmp; - } - // Contribution 38 - { - Avm_DECLARE_VIEWS(38); - - auto tmp = ((avm_alu_cmp_rng_ctr * (((-avm_alu_rng_chk_sel + FF(1)) * (-avm_alu_op_eq_diff_inv + FF(1))) + - avm_alu_op_eq_diff_inv)) - - avm_alu_rng_chk_sel); - tmp *= scaling_factor; - std::get<38>(evals) += tmp; - } - // Contribution 39 - { - Avm_DECLARE_VIEWS(39); - - auto tmp = (avm_alu_rng_chk_lookup_selector_shift - - ((((((((((avm_alu_cmp_sel_shift + avm_alu_rng_chk_sel_shift) + avm_alu_op_add_shift) + - avm_alu_op_sub_shift) + - avm_alu_op_mul_shift) + - (avm_alu_op_mul * avm_alu_u128_tag)) + - avm_alu_op_cast_shift) + - avm_alu_op_cast_prev_shift) + - avm_alu_op_shl_shift) + - avm_alu_op_shr_shift) + - avm_alu_op_div_shift)); - tmp *= scaling_factor; - std::get<39>(evals) += tmp; - } - // Contribution 40 - { - Avm_DECLARE_VIEWS(40); - - auto tmp = (avm_alu_a_lo - - (((((((((avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))) + (avm_alu_u16_r0 * FF(65536))) + - (avm_alu_u16_r1 * FF(4294967296UL))) + - (avm_alu_u16_r2 * FF(281474976710656UL))) + - (avm_alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - (avm_alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + - (avm_alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + - (avm_alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))) * - (((((avm_alu_rng_chk_sel + avm_alu_cmp_sel) + avm_alu_op_cast) + avm_alu_op_cast_prev) + - avm_alu_shift_lt_bit_len) + - avm_alu_op_div))); - tmp *= scaling_factor; - std::get<40>(evals) += tmp; - } - // Contribution 41 - { - Avm_DECLARE_VIEWS(41); - - auto tmp = (avm_alu_a_hi - - ((((((((avm_alu_u16_r7 + (avm_alu_u16_r8 * FF(65536))) + (avm_alu_u16_r9 * FF(4294967296UL))) + - (avm_alu_u16_r10 * FF(281474976710656UL))) + - (avm_alu_u16_r11 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - (avm_alu_u16_r12 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + - (avm_alu_u16_r13 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + - (avm_alu_u16_r14 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))) * - (((((avm_alu_rng_chk_sel + avm_alu_cmp_sel) + avm_alu_op_cast) + avm_alu_op_cast_prev) + - avm_alu_shift_lt_bit_len) + - avm_alu_op_div))); - tmp *= scaling_factor; - std::get<41>(evals) += tmp; - } - // Contribution 42 - { - Avm_DECLARE_VIEWS(42); - - auto tmp = ((avm_alu_a_lo_shift - avm_alu_b_lo) * avm_alu_rng_chk_sel_shift); - tmp *= scaling_factor; - std::get<42>(evals) += tmp; - } - // Contribution 43 - { - Avm_DECLARE_VIEWS(43); - - auto tmp = ((avm_alu_a_hi_shift - avm_alu_b_hi) * avm_alu_rng_chk_sel_shift); - tmp *= scaling_factor; - std::get<43>(evals) += tmp; - } - // Contribution 44 - { - Avm_DECLARE_VIEWS(44); - - auto tmp = ((avm_alu_b_lo_shift - avm_alu_p_sub_a_lo) * avm_alu_rng_chk_sel_shift); - tmp *= scaling_factor; - std::get<44>(evals) += tmp; - } - // Contribution 45 - { - Avm_DECLARE_VIEWS(45); - - auto tmp = ((avm_alu_b_hi_shift - avm_alu_p_sub_a_hi) * avm_alu_rng_chk_sel_shift); - tmp *= scaling_factor; - std::get<45>(evals) += tmp; - } - // Contribution 46 - { - Avm_DECLARE_VIEWS(46); - - auto tmp = ((avm_alu_p_sub_a_lo_shift - avm_alu_p_sub_b_lo) * avm_alu_rng_chk_sel_shift); - tmp *= scaling_factor; - std::get<46>(evals) += tmp; - } - // Contribution 47 - { - Avm_DECLARE_VIEWS(47); - - auto tmp = ((avm_alu_p_sub_a_hi_shift - avm_alu_p_sub_b_hi) * avm_alu_rng_chk_sel_shift); - tmp *= scaling_factor; - std::get<47>(evals) += tmp; - } - // Contribution 48 - { - Avm_DECLARE_VIEWS(48); - - auto tmp = ((avm_alu_p_sub_b_lo_shift - avm_alu_res_lo) * avm_alu_rng_chk_sel_shift); - tmp *= scaling_factor; - std::get<48>(evals) += tmp; - } - // Contribution 49 - { - Avm_DECLARE_VIEWS(49); - - auto tmp = ((avm_alu_p_sub_b_hi_shift - avm_alu_res_hi) * avm_alu_rng_chk_sel_shift); - tmp *= scaling_factor; - std::get<49>(evals) += tmp; - } - // Contribution 50 - { - Avm_DECLARE_VIEWS(50); - - auto tmp = (avm_alu_op_cast_prev_shift - avm_alu_op_cast); - tmp *= scaling_factor; - std::get<50>(evals) += tmp; - } - // Contribution 51 - { - Avm_DECLARE_VIEWS(51); - - auto tmp = - (avm_alu_op_cast * - (((((((avm_alu_u8_tag * avm_alu_u8_r0) + - (avm_alu_u16_tag * (avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))))) + - (avm_alu_u32_tag * - ((avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))) + (avm_alu_u16_r0 * FF(65536))))) + - (avm_alu_u64_tag * ((((avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))) + (avm_alu_u16_r0 * FF(65536))) + - (avm_alu_u16_r1 * FF(4294967296UL))) + - (avm_alu_u16_r2 * FF(281474976710656UL))))) + - (avm_alu_u128_tag * - ((((((((avm_alu_u8_r0 + (avm_alu_u8_r1 * FF(256))) + (avm_alu_u16_r0 * FF(65536))) + - (avm_alu_u16_r1 * FF(4294967296UL))) + - (avm_alu_u16_r2 * FF(281474976710656UL))) + - (avm_alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - (avm_alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + - (avm_alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + - (avm_alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))))) + - (avm_alu_ff_tag * avm_alu_ia)) - - avm_alu_ic)); - tmp *= scaling_factor; - std::get<51>(evals) += tmp; - } - // Contribution 52 - { - Avm_DECLARE_VIEWS(52); - - auto tmp = (avm_alu_op_cast * (avm_alu_a_lo_shift - avm_alu_p_sub_a_lo)); - tmp *= scaling_factor; - std::get<52>(evals) += tmp; - } - // Contribution 53 - { - Avm_DECLARE_VIEWS(53); - - auto tmp = (avm_alu_op_cast * (avm_alu_a_hi_shift - avm_alu_p_sub_a_hi)); - tmp *= scaling_factor; - std::get<53>(evals) += tmp; - } - // Contribution 54 - { - Avm_DECLARE_VIEWS(54); - - auto tmp = (((avm_alu_op_mul * avm_alu_u128_tag) + avm_alu_op_cast) * avm_alu_alu_sel_shift); - tmp *= scaling_factor; - std::get<54>(evals) += tmp; - } - // Contribution 55 - { - Avm_DECLARE_VIEWS(55); - - auto tmp = ((avm_alu_shift_lt_bit_len * avm_alu_op_shr) * - (avm_alu_a_lo - ((avm_alu_two_pow_s - avm_alu_b_lo) - FF(1)))); - tmp *= scaling_factor; - std::get<55>(evals) += tmp; - } - // Contribution 56 - { - Avm_DECLARE_VIEWS(56); - - auto tmp = ((avm_alu_shift_lt_bit_len * avm_alu_op_shr) * - (avm_alu_a_hi - ((avm_alu_two_pow_t_sub_s - avm_alu_b_hi) - FF(1)))); - tmp *= scaling_factor; - std::get<56>(evals) += tmp; - } - // Contribution 57 - { - Avm_DECLARE_VIEWS(57); - - auto tmp = ((avm_alu_shift_lt_bit_len * avm_alu_op_shl) * - (avm_alu_a_lo - ((avm_alu_two_pow_t_sub_s - avm_alu_b_lo) - FF(1)))); - tmp *= scaling_factor; - std::get<57>(evals) += tmp; - } - // Contribution 58 - { - Avm_DECLARE_VIEWS(58); - - auto tmp = ((avm_alu_shift_lt_bit_len * avm_alu_op_shl) * - (avm_alu_a_hi - ((avm_alu_two_pow_s - avm_alu_b_hi) - FF(1)))); - tmp *= scaling_factor; - std::get<58>(evals) += tmp; - } - // Contribution 59 - { - Avm_DECLARE_VIEWS(59); - - auto tmp = (avm_alu_shift_lt_bit_len * (-avm_alu_shift_lt_bit_len + FF(1))); - tmp *= scaling_factor; - std::get<59>(evals) += tmp; - } - // Contribution 60 - { - Avm_DECLARE_VIEWS(60); - - auto tmp = (avm_alu_t_sub_s_bits - - (avm_alu_shift_sel * - ((avm_alu_shift_lt_bit_len * - ((((((avm_alu_u8_tag * FF(8)) + (avm_alu_u16_tag * FF(16))) + (avm_alu_u32_tag * FF(32))) + - (avm_alu_u64_tag * FF(64))) + - (avm_alu_u128_tag * FF(128))) - - avm_alu_ib)) + - ((-avm_alu_shift_lt_bit_len + FF(1)) * - (avm_alu_ib - - (((((avm_alu_u8_tag * FF(8)) + (avm_alu_u16_tag * FF(16))) + (avm_alu_u32_tag * FF(32))) + - (avm_alu_u64_tag * FF(64))) + - (avm_alu_u128_tag * FF(128)))))))); - tmp *= scaling_factor; - std::get<60>(evals) += tmp; - } - // Contribution 61 - { - Avm_DECLARE_VIEWS(61); - - auto tmp = ((avm_alu_shift_lt_bit_len * avm_alu_op_shr) * - (((avm_alu_b_hi * avm_alu_two_pow_s) + avm_alu_b_lo) - avm_alu_ia)); - tmp *= scaling_factor; - std::get<61>(evals) += tmp; - } - // Contribution 62 - { - Avm_DECLARE_VIEWS(62); - - auto tmp = (avm_alu_op_shr * (avm_alu_ic - (avm_alu_b_hi * avm_alu_shift_lt_bit_len))); - tmp *= scaling_factor; - std::get<62>(evals) += tmp; - } - // Contribution 63 - { - Avm_DECLARE_VIEWS(63); - - auto tmp = ((avm_alu_shift_lt_bit_len * avm_alu_op_shl) * - (((avm_alu_b_hi * avm_alu_two_pow_t_sub_s) + avm_alu_b_lo) - avm_alu_ia)); - tmp *= scaling_factor; - std::get<63>(evals) += tmp; - } - // Contribution 64 - { - Avm_DECLARE_VIEWS(64); - - auto tmp = - (avm_alu_op_shl * (avm_alu_ic - ((avm_alu_b_lo * avm_alu_two_pow_s) * avm_alu_shift_lt_bit_len))); - tmp *= scaling_factor; - std::get<64>(evals) += tmp; - } - // Contribution 65 - { - Avm_DECLARE_VIEWS(65); - - auto tmp = (avm_alu_op_div - (avm_alu_op_div_std + avm_alu_op_div_a_lt_b)); - tmp *= scaling_factor; - std::get<65>(evals) += tmp; - } - // Contribution 66 - { - Avm_DECLARE_VIEWS(66); - - auto tmp = (avm_alu_op_div_a_lt_b * (-avm_alu_op_div_a_lt_b + FF(1))); - tmp *= scaling_factor; - std::get<66>(evals) += tmp; - } - // Contribution 67 - { - Avm_DECLARE_VIEWS(67); - - auto tmp = (avm_alu_op_div_a_lt_b * (avm_alu_a_lo - ((avm_alu_ib - avm_alu_ia) - FF(1)))); - tmp *= scaling_factor; - std::get<67>(evals) += tmp; - } - // Contribution 68 - { - Avm_DECLARE_VIEWS(68); - - auto tmp = (avm_alu_op_div_a_lt_b * avm_alu_ic); - tmp *= scaling_factor; - std::get<68>(evals) += tmp; - } - // Contribution 69 - { - Avm_DECLARE_VIEWS(69); - - auto tmp = (avm_alu_op_div_a_lt_b * (avm_alu_ia - avm_alu_remainder)); - tmp *= scaling_factor; - std::get<69>(evals) += tmp; - } - // Contribution 70 - { - Avm_DECLARE_VIEWS(70); - - auto tmp = (avm_alu_op_div_std * (-avm_alu_op_div_std + FF(1))); - tmp *= scaling_factor; - std::get<70>(evals) += tmp; - } - // Contribution 71 - { - Avm_DECLARE_VIEWS(71); - - auto tmp = (avm_alu_op_div_std * ((avm_alu_ib - avm_alu_divisor_lo) - - (avm_alu_divisor_hi * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL })))); - tmp *= scaling_factor; - std::get<71>(evals) += tmp; - } - // Contribution 72 - { - Avm_DECLARE_VIEWS(72); - - auto tmp = (avm_alu_op_div_std * ((avm_alu_ic - avm_alu_quotient_lo) - - (avm_alu_quotient_hi * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL })))); - tmp *= scaling_factor; - std::get<72>(evals) += tmp; - } - // Contribution 73 - { - Avm_DECLARE_VIEWS(73); - - auto tmp = (((avm_alu_divisor_hi * avm_alu_quotient_lo) + (avm_alu_divisor_lo * avm_alu_quotient_hi)) - - (avm_alu_partial_prod_lo + (avm_alu_partial_prod_hi * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL })))); - tmp *= scaling_factor; - std::get<73>(evals) += tmp; - } - // Contribution 74 - { - Avm_DECLARE_VIEWS(74); - - auto tmp = (avm_alu_op_div_std * ((((avm_alu_divisor_lo * avm_alu_quotient_lo) + - (avm_alu_partial_prod_lo * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - ((avm_alu_partial_prod_hi + (avm_alu_divisor_hi * avm_alu_quotient_hi)) * - FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - - (avm_alu_a_lo + (avm_alu_a_hi * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))))); - tmp *= scaling_factor; - std::get<74>(evals) += tmp; - } - // Contribution 75 - { - Avm_DECLARE_VIEWS(75); - - auto tmp = (avm_alu_op_div_std * (avm_alu_b_hi - ((avm_alu_ib - avm_alu_remainder) - FF(1)))); - tmp *= scaling_factor; - std::get<75>(evals) += tmp; - } - // Contribution 76 - { - Avm_DECLARE_VIEWS(76); - - auto tmp = ((avm_alu_cmp_rng_ctr_shift - FF(2)) * avm_alu_op_div_std); - tmp *= scaling_factor; - std::get<76>(evals) += tmp; - } - // Contribution 77 - { - Avm_DECLARE_VIEWS(77); - - auto tmp = (avm_alu_rng_chk_sel * avm_alu_op_div_std); - tmp *= scaling_factor; - std::get<77>(evals) += tmp; - } - // Contribution 78 - { - Avm_DECLARE_VIEWS(78); - - auto tmp = (avm_alu_op_div_std * ((((avm_alu_divisor_lo * avm_alu_quotient_lo) + - (avm_alu_partial_prod_lo * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - ((avm_alu_partial_prod_hi + (avm_alu_divisor_hi * avm_alu_quotient_hi)) * - FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - - (avm_alu_ia - avm_alu_remainder))); - tmp *= scaling_factor; - std::get<78>(evals) += tmp; - } - // Contribution 79 - { - Avm_DECLARE_VIEWS(79); - - auto tmp = (avm_alu_div_rng_chk_selector * (-avm_alu_div_rng_chk_selector + FF(1))); - tmp *= scaling_factor; - std::get<79>(evals) += tmp; - } - // Contribution 80 - { - Avm_DECLARE_VIEWS(80); - - auto tmp = ((avm_alu_div_rng_chk_selector * avm_alu_div_rng_chk_selector_shift) - avm_alu_op_div_std); - tmp *= scaling_factor; - std::get<80>(evals) += tmp; - } - // Contribution 81 - { - Avm_DECLARE_VIEWS(81); - - auto tmp = - (avm_alu_divisor_lo - (avm_alu_op_div_std * (((avm_alu_div_u16_r0 + (avm_alu_div_u16_r1 * FF(65536))) + - (avm_alu_div_u16_r2 * FF(4294967296UL))) + - (avm_alu_div_u16_r3 * FF(281474976710656UL))))); - tmp *= scaling_factor; - std::get<81>(evals) += tmp; - } - // Contribution 82 - { - Avm_DECLARE_VIEWS(82); - - auto tmp = - (avm_alu_divisor_hi - (avm_alu_op_div_std * (((avm_alu_div_u16_r4 + (avm_alu_div_u16_r5 * FF(65536))) + - (avm_alu_div_u16_r6 * FF(4294967296UL))) + - (avm_alu_div_u16_r7 * FF(281474976710656UL))))); - tmp *= scaling_factor; - std::get<82>(evals) += tmp; - } - // Contribution 83 - { - Avm_DECLARE_VIEWS(83); - - auto tmp = (avm_alu_quotient_lo - - (avm_alu_op_div_std * (((avm_alu_div_u16_r0_shift + (avm_alu_div_u16_r1_shift * FF(65536))) + - (avm_alu_div_u16_r2_shift * FF(4294967296UL))) + - (avm_alu_div_u16_r3_shift * FF(281474976710656UL))))); - tmp *= scaling_factor; - std::get<83>(evals) += tmp; - } - // Contribution 84 - { - Avm_DECLARE_VIEWS(84); - - auto tmp = (avm_alu_quotient_hi - - (avm_alu_op_div_std * (((avm_alu_div_u16_r4_shift + (avm_alu_div_u16_r5_shift * FF(65536))) + - (avm_alu_div_u16_r6_shift * FF(4294967296UL))) + - (avm_alu_div_u16_r7_shift * FF(281474976710656UL))))); - tmp *= scaling_factor; - std::get<84>(evals) += tmp; - } - // Contribution 85 - { - Avm_DECLARE_VIEWS(85); - - auto tmp = - (avm_alu_partial_prod_lo - - (avm_alu_op_div_std * - ((((avm_alu_u8_r0_shift + (avm_alu_u8_r1_shift * FF(256))) + (avm_alu_u16_r0_shift * FF(65536))) + - (avm_alu_u16_r1_shift * FF(4294967296UL))) + - (avm_alu_u16_r2_shift * FF(281474976710656UL))))); - tmp *= scaling_factor; - std::get<85>(evals) += tmp; - } - // Contribution 86 - { - Avm_DECLARE_VIEWS(86); - - auto tmp = (avm_alu_partial_prod_hi - - (avm_alu_op_div_std * (((avm_alu_u16_r3_shift + (avm_alu_u16_r4_shift * FF(65536))) + - (avm_alu_u16_r5_shift * FF(4294967296UL))) + - (avm_alu_u16_r6_shift * FF(281474976710656UL))))); - tmp *= scaling_factor; - std::get<86>(evals) += tmp; - } - } -}; - -template using avm_alu = Relation>; - -} // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_keccakf1600.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_keccakf1600.hpp deleted file mode 100644 index bdff14a827b..00000000000 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_keccakf1600.hpp +++ /dev/null @@ -1,49 +0,0 @@ - -#pragma once -#include "../../relation_parameters.hpp" -#include "../../relation_types.hpp" -#include "./declare_views.hpp" - -namespace bb::Avm_vm { - -template struct Avm_keccakf1600Row { - FF avm_keccakf1600_keccakf1600_sel{}; - - [[maybe_unused]] static std::vector names(); -}; - -inline std::string get_relation_label_avm_keccakf1600(int index) -{ - switch (index) {} - return std::to_string(index); -} - -template class avm_keccakf1600Impl { - public: - using FF = FF_; - - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 3, - }; - - template - void static accumulate(ContainerOverSubrelations& evals, - const AllEntities& new_term, - [[maybe_unused]] const RelationParameters&, - [[maybe_unused]] const FF& scaling_factor) - { - - // Contribution 0 - { - Avm_DECLARE_VIEWS(0); - - auto tmp = (avm_keccakf1600_keccakf1600_sel * (-avm_keccakf1600_keccakf1600_sel + FF(1))); - tmp *= scaling_factor; - std::get<0>(evals) += tmp; - } - } -}; - -template using avm_keccakf1600 = Relation>; - -} // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_kernel.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_kernel.hpp deleted file mode 100644 index 60e1051b1f9..00000000000 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_kernel.hpp +++ /dev/null @@ -1,200 +0,0 @@ - -#pragma once -#include "../../relation_parameters.hpp" -#include "../../relation_types.hpp" -#include "./declare_views.hpp" - -namespace bb::Avm_vm { - -template struct Avm_kernelRow { - FF avm_kernel_emit_l2_to_l1_msg_write_offset{}; - FF avm_kernel_emit_l2_to_l1_msg_write_offset_shift{}; - FF avm_kernel_emit_note_hash_write_offset{}; - FF avm_kernel_emit_note_hash_write_offset_shift{}; - FF avm_kernel_emit_nullifier_write_offset{}; - FF avm_kernel_emit_nullifier_write_offset_shift{}; - FF avm_kernel_emit_unencrypted_log_write_offset{}; - FF avm_kernel_emit_unencrypted_log_write_offset_shift{}; - FF avm_kernel_l1_to_l2_msg_exists_write_offset{}; - FF avm_kernel_l1_to_l2_msg_exists_write_offset_shift{}; - FF avm_kernel_note_hash_exist_write_offset{}; - FF avm_kernel_note_hash_exist_write_offset_shift{}; - FF avm_kernel_nullifier_exists_write_offset{}; - FF avm_kernel_nullifier_exists_write_offset_shift{}; - FF avm_kernel_nullifier_non_exists_write_offset{}; - FF avm_kernel_nullifier_non_exists_write_offset_shift{}; - FF avm_kernel_sload_write_offset{}; - FF avm_kernel_sload_write_offset_shift{}; - FF avm_kernel_sstore_write_offset{}; - FF avm_kernel_sstore_write_offset_shift{}; - FF avm_main_ib{}; - FF avm_main_last{}; - FF avm_main_sel_op_emit_l2_to_l1_msg{}; - FF avm_main_sel_op_emit_note_hash{}; - FF avm_main_sel_op_emit_nullifier{}; - FF avm_main_sel_op_emit_unencrypted_log{}; - FF avm_main_sel_op_l1_to_l2_msg_exists{}; - FF avm_main_sel_op_note_hash_exists{}; - FF avm_main_sel_op_nullifier_exists{}; - FF avm_main_sel_op_sload{}; - FF avm_main_sel_op_sstore{}; - - [[maybe_unused]] static std::vector names(); -}; - -inline std::string get_relation_label_avm_kernel(int index) -{ - switch (index) { - case 0: - return "NOTE_HASH_EXISTS_INC_CONSISTENCY_CHECK"; - - case 1: - return "EMIT_NOTE_HASH_INC_CONSISTENCY_CHECK"; - - case 2: - return "NULLIFIER_EXISTS_INC_CONSISTENCY_CHECK"; - - case 3: - return "NULLIFIER_NON_EXISTS_INC_CONSISTENCY_CHECK"; - - case 4: - return "EMIT_NULLIFIER_INC_CONSISTENCY_CHECK"; - - case 5: - return "L1_TO_L2_MSG_EXISTS_INC_CONSISTENCY_CHECK"; - - case 6: - return "EMIT_UNENCRYPTED_LOG_INC_CONSISTENCY_CHECK"; - - case 7: - return "EMIT_L2_TO_L1_MSG_INC_CONSISTENCY_CHECK"; - - case 8: - return "SLOAD_INC_CONSISTENCY_CHECK"; - - case 9: - return "SSTORE_INC_CONSISTENCY_CHECK"; - } - return std::to_string(index); -} - -template class avm_kernelImpl { - public: - using FF = FF_; - - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ - 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, - }; - - template - void static accumulate(ContainerOverSubrelations& evals, - const AllEntities& new_term, - [[maybe_unused]] const RelationParameters&, - [[maybe_unused]] const FF& scaling_factor) - { - - // Contribution 0 - { - Avm_DECLARE_VIEWS(0); - - auto tmp = ((-avm_main_last + FF(1)) * - (avm_kernel_note_hash_exist_write_offset_shift - - (avm_kernel_note_hash_exist_write_offset + avm_main_sel_op_note_hash_exists))); - tmp *= scaling_factor; - std::get<0>(evals) += tmp; - } - // Contribution 1 - { - Avm_DECLARE_VIEWS(1); - - auto tmp = ((-avm_main_last + FF(1)) * - (avm_kernel_emit_note_hash_write_offset_shift - - (avm_kernel_emit_note_hash_write_offset + avm_main_sel_op_emit_note_hash))); - tmp *= scaling_factor; - std::get<1>(evals) += tmp; - } - // Contribution 2 - { - Avm_DECLARE_VIEWS(2); - - auto tmp = - ((-avm_main_last + FF(1)) * - (avm_kernel_nullifier_exists_write_offset_shift - - (avm_kernel_nullifier_exists_write_offset + (avm_main_sel_op_nullifier_exists * avm_main_ib)))); - tmp *= scaling_factor; - std::get<2>(evals) += tmp; - } - // Contribution 3 - { - Avm_DECLARE_VIEWS(3); - - auto tmp = ((-avm_main_last + FF(1)) * (avm_kernel_nullifier_non_exists_write_offset_shift - - (avm_kernel_nullifier_non_exists_write_offset + - (avm_main_sel_op_nullifier_exists * (-avm_main_ib + FF(1)))))); - tmp *= scaling_factor; - std::get<3>(evals) += tmp; - } - // Contribution 4 - { - Avm_DECLARE_VIEWS(4); - - auto tmp = ((-avm_main_last + FF(1)) * - (avm_kernel_emit_nullifier_write_offset_shift - - (avm_kernel_emit_nullifier_write_offset + avm_main_sel_op_emit_nullifier))); - tmp *= scaling_factor; - std::get<4>(evals) += tmp; - } - // Contribution 5 - { - Avm_DECLARE_VIEWS(5); - - auto tmp = ((-avm_main_last + FF(1)) * - (avm_kernel_l1_to_l2_msg_exists_write_offset_shift - - (avm_kernel_l1_to_l2_msg_exists_write_offset + avm_main_sel_op_l1_to_l2_msg_exists))); - tmp *= scaling_factor; - std::get<5>(evals) += tmp; - } - // Contribution 6 - { - Avm_DECLARE_VIEWS(6); - - auto tmp = ((-avm_main_last + FF(1)) * - (avm_kernel_emit_unencrypted_log_write_offset_shift - - (avm_kernel_emit_unencrypted_log_write_offset + avm_main_sel_op_emit_unencrypted_log))); - tmp *= scaling_factor; - std::get<6>(evals) += tmp; - } - // Contribution 7 - { - Avm_DECLARE_VIEWS(7); - - auto tmp = ((-avm_main_last + FF(1)) * - (avm_kernel_emit_l2_to_l1_msg_write_offset_shift - - (avm_kernel_emit_l2_to_l1_msg_write_offset + avm_main_sel_op_emit_l2_to_l1_msg))); - tmp *= scaling_factor; - std::get<7>(evals) += tmp; - } - // Contribution 8 - { - Avm_DECLARE_VIEWS(8); - - auto tmp = ((-avm_main_last + FF(1)) * (avm_kernel_sload_write_offset_shift - - (avm_kernel_sload_write_offset + avm_main_sel_op_sload))); - tmp *= scaling_factor; - std::get<8>(evals) += tmp; - } - // Contribution 9 - { - Avm_DECLARE_VIEWS(9); - - auto tmp = ((-avm_main_last + FF(1)) * (avm_kernel_sstore_write_offset_shift - - (avm_kernel_sstore_write_offset + avm_main_sel_op_sstore))); - tmp *= scaling_factor; - std::get<9>(evals) += tmp; - } - } -}; - -template using avm_kernel = Relation>; - -} // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_binary.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/binary.hpp similarity index 56% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_binary.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/binary.hpp index c36833b090f..98260f37337 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_binary.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/binary.hpp @@ -6,27 +6,27 @@ namespace bb::Avm_vm { -template struct Avm_binaryRow { - FF avm_binary_acc_ia{}; - FF avm_binary_acc_ia_shift{}; - FF avm_binary_acc_ib{}; - FF avm_binary_acc_ib_shift{}; - FF avm_binary_acc_ic{}; - FF avm_binary_acc_ic_shift{}; - FF avm_binary_bin_sel{}; - FF avm_binary_ia_bytes{}; - FF avm_binary_ib_bytes{}; - FF avm_binary_ic_bytes{}; - FF avm_binary_mem_tag_ctr{}; - FF avm_binary_mem_tag_ctr_inv{}; - FF avm_binary_mem_tag_ctr_shift{}; - FF avm_binary_op_id{}; - FF avm_binary_op_id_shift{}; +template struct BinaryRow { + FF binary_acc_ia{}; + FF binary_acc_ia_shift{}; + FF binary_acc_ib{}; + FF binary_acc_ib_shift{}; + FF binary_acc_ic{}; + FF binary_acc_ic_shift{}; + FF binary_ia_bytes{}; + FF binary_ib_bytes{}; + FF binary_ic_bytes{}; + FF binary_mem_tag_ctr{}; + FF binary_mem_tag_ctr_inv{}; + FF binary_mem_tag_ctr_shift{}; + FF binary_op_id{}; + FF binary_op_id_shift{}; + FF binary_sel_bin{}; [[maybe_unused]] static std::vector names(); }; -inline std::string get_relation_label_avm_binary(int index) +inline std::string get_relation_label_binary(int index) { switch (index) { case 1: @@ -36,7 +36,7 @@ inline std::string get_relation_label_avm_binary(int index) return "MEM_TAG_REL"; case 3: - return "BIN_SEL_CTR_REL"; + return "SEL_BIN_CTR_REL"; case 7: return "ACC_REL_A"; @@ -50,7 +50,7 @@ inline std::string get_relation_label_avm_binary(int index) return std::to_string(index); } -template class avm_binaryImpl { +template class binaryImpl { public: using FF = FF_; @@ -69,7 +69,7 @@ template class avm_binaryImpl { { Avm_DECLARE_VIEWS(0); - auto tmp = (avm_binary_bin_sel * (-avm_binary_bin_sel + FF(1))); + auto tmp = (binary_sel_bin * (-binary_sel_bin + FF(1))); tmp *= scaling_factor; std::get<0>(evals) += tmp; } @@ -77,7 +77,7 @@ template class avm_binaryImpl { { Avm_DECLARE_VIEWS(1); - auto tmp = ((avm_binary_op_id_shift - avm_binary_op_id) * avm_binary_mem_tag_ctr); + auto tmp = ((binary_op_id_shift - binary_op_id) * binary_mem_tag_ctr); tmp *= scaling_factor; std::get<1>(evals) += tmp; } @@ -85,7 +85,7 @@ template class avm_binaryImpl { { Avm_DECLARE_VIEWS(2); - auto tmp = (((avm_binary_mem_tag_ctr_shift - avm_binary_mem_tag_ctr) + FF(1)) * avm_binary_mem_tag_ctr); + auto tmp = (((binary_mem_tag_ctr_shift - binary_mem_tag_ctr) + FF(1)) * binary_mem_tag_ctr); tmp *= scaling_factor; std::get<2>(evals) += tmp; } @@ -93,10 +93,9 @@ template class avm_binaryImpl { { Avm_DECLARE_VIEWS(3); - auto tmp = - ((avm_binary_mem_tag_ctr * (((-avm_binary_bin_sel + FF(1)) * (-avm_binary_mem_tag_ctr_inv + FF(1))) + - avm_binary_mem_tag_ctr_inv)) - - avm_binary_bin_sel); + auto tmp = ((binary_mem_tag_ctr * + (((-binary_sel_bin + FF(1)) * (-binary_mem_tag_ctr_inv + FF(1))) + binary_mem_tag_ctr_inv)) - + binary_sel_bin); tmp *= scaling_factor; std::get<3>(evals) += tmp; } @@ -104,7 +103,7 @@ template class avm_binaryImpl { { Avm_DECLARE_VIEWS(4); - auto tmp = ((-avm_binary_bin_sel + FF(1)) * avm_binary_acc_ia); + auto tmp = ((-binary_sel_bin + FF(1)) * binary_acc_ia); tmp *= scaling_factor; std::get<4>(evals) += tmp; } @@ -112,7 +111,7 @@ template class avm_binaryImpl { { Avm_DECLARE_VIEWS(5); - auto tmp = ((-avm_binary_bin_sel + FF(1)) * avm_binary_acc_ib); + auto tmp = ((-binary_sel_bin + FF(1)) * binary_acc_ib); tmp *= scaling_factor; std::get<5>(evals) += tmp; } @@ -120,7 +119,7 @@ template class avm_binaryImpl { { Avm_DECLARE_VIEWS(6); - auto tmp = ((-avm_binary_bin_sel + FF(1)) * avm_binary_acc_ic); + auto tmp = ((-binary_sel_bin + FF(1)) * binary_acc_ic); tmp *= scaling_factor; std::get<6>(evals) += tmp; } @@ -128,8 +127,7 @@ template class avm_binaryImpl { { Avm_DECLARE_VIEWS(7); - auto tmp = (((avm_binary_acc_ia - avm_binary_ia_bytes) - (avm_binary_acc_ia_shift * FF(256))) * - avm_binary_mem_tag_ctr); + auto tmp = (((binary_acc_ia - binary_ia_bytes) - (binary_acc_ia_shift * FF(256))) * binary_mem_tag_ctr); tmp *= scaling_factor; std::get<7>(evals) += tmp; } @@ -137,8 +135,7 @@ template class avm_binaryImpl { { Avm_DECLARE_VIEWS(8); - auto tmp = (((avm_binary_acc_ib - avm_binary_ib_bytes) - (avm_binary_acc_ib_shift * FF(256))) * - avm_binary_mem_tag_ctr); + auto tmp = (((binary_acc_ib - binary_ib_bytes) - (binary_acc_ib_shift * FF(256))) * binary_mem_tag_ctr); tmp *= scaling_factor; std::get<8>(evals) += tmp; } @@ -146,14 +143,13 @@ template class avm_binaryImpl { { Avm_DECLARE_VIEWS(9); - auto tmp = (((avm_binary_acc_ic - avm_binary_ic_bytes) - (avm_binary_acc_ic_shift * FF(256))) * - avm_binary_mem_tag_ctr); + auto tmp = (((binary_acc_ic - binary_ic_bytes) - (binary_acc_ic_shift * FF(256))) * binary_mem_tag_ctr); tmp *= scaling_factor; std::get<9>(evals) += tmp; } } }; -template using avm_binary = Relation>; +template using binary = Relation>; } // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_pedersen.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/conversion.hpp similarity index 71% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_pedersen.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/conversion.hpp index 76f784d5634..b83fb6bf7ac 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_pedersen.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/conversion.hpp @@ -6,19 +6,19 @@ namespace bb::Avm_vm { -template struct Avm_pedersenRow { - FF avm_pedersen_pedersen_sel{}; +template struct ConversionRow { + FF conversion_sel_to_radix_le{}; [[maybe_unused]] static std::vector names(); }; -inline std::string get_relation_label_avm_pedersen(int index) +inline std::string get_relation_label_conversion(int index) { switch (index) {} return std::to_string(index); } -template class avm_pedersenImpl { +template class conversionImpl { public: using FF = FF_; @@ -37,13 +37,13 @@ template class avm_pedersenImpl { { Avm_DECLARE_VIEWS(0); - auto tmp = (avm_pedersen_pedersen_sel * (-avm_pedersen_pedersen_sel + FF(1))); + auto tmp = (conversion_sel_to_radix_le * (-conversion_sel_to_radix_le + FF(1))); tmp *= scaling_factor; std::get<0>(evals) += tmp; } } }; -template using avm_pedersen = Relation>; +template using conversion = Relation>; } // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp index b40847cdff2..ef1db050b75 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp @@ -2,307 +2,302 @@ #define Avm_DECLARE_VIEWS(index) \ using Accumulator = typename std::tuple_element::type; \ using View = typename Accumulator::View; \ - [[maybe_unused]] auto avm_main_clk = View(new_term.avm_main_clk); \ - [[maybe_unused]] auto avm_main_first = View(new_term.avm_main_first); \ - [[maybe_unused]] auto avm_alu_a_hi = View(new_term.avm_alu_a_hi); \ - [[maybe_unused]] auto avm_alu_a_lo = View(new_term.avm_alu_a_lo); \ - [[maybe_unused]] auto avm_alu_alu_sel = View(new_term.avm_alu_alu_sel); \ - [[maybe_unused]] auto avm_alu_b_hi = View(new_term.avm_alu_b_hi); \ - [[maybe_unused]] auto avm_alu_b_lo = View(new_term.avm_alu_b_lo); \ - [[maybe_unused]] auto avm_alu_borrow = View(new_term.avm_alu_borrow); \ - [[maybe_unused]] auto avm_alu_cf = View(new_term.avm_alu_cf); \ - [[maybe_unused]] auto avm_alu_clk = View(new_term.avm_alu_clk); \ - [[maybe_unused]] auto avm_alu_cmp_rng_ctr = View(new_term.avm_alu_cmp_rng_ctr); \ - [[maybe_unused]] auto avm_alu_cmp_sel = View(new_term.avm_alu_cmp_sel); \ - [[maybe_unused]] auto avm_alu_div_rng_chk_selector = View(new_term.avm_alu_div_rng_chk_selector); \ - [[maybe_unused]] auto avm_alu_div_u16_r0 = View(new_term.avm_alu_div_u16_r0); \ - [[maybe_unused]] auto avm_alu_div_u16_r1 = View(new_term.avm_alu_div_u16_r1); \ - [[maybe_unused]] auto avm_alu_div_u16_r2 = View(new_term.avm_alu_div_u16_r2); \ - [[maybe_unused]] auto avm_alu_div_u16_r3 = View(new_term.avm_alu_div_u16_r3); \ - [[maybe_unused]] auto avm_alu_div_u16_r4 = View(new_term.avm_alu_div_u16_r4); \ - [[maybe_unused]] auto avm_alu_div_u16_r5 = View(new_term.avm_alu_div_u16_r5); \ - [[maybe_unused]] auto avm_alu_div_u16_r6 = View(new_term.avm_alu_div_u16_r6); \ - [[maybe_unused]] auto avm_alu_div_u16_r7 = View(new_term.avm_alu_div_u16_r7); \ - [[maybe_unused]] auto avm_alu_divisor_hi = View(new_term.avm_alu_divisor_hi); \ - [[maybe_unused]] auto avm_alu_divisor_lo = View(new_term.avm_alu_divisor_lo); \ - [[maybe_unused]] auto avm_alu_ff_tag = View(new_term.avm_alu_ff_tag); \ - [[maybe_unused]] auto avm_alu_ia = View(new_term.avm_alu_ia); \ - [[maybe_unused]] auto avm_alu_ib = View(new_term.avm_alu_ib); \ - [[maybe_unused]] auto avm_alu_ic = View(new_term.avm_alu_ic); \ - [[maybe_unused]] auto avm_alu_in_tag = View(new_term.avm_alu_in_tag); \ - [[maybe_unused]] auto avm_alu_op_add = View(new_term.avm_alu_op_add); \ - [[maybe_unused]] auto avm_alu_op_cast = View(new_term.avm_alu_op_cast); \ - [[maybe_unused]] auto avm_alu_op_cast_prev = View(new_term.avm_alu_op_cast_prev); \ - [[maybe_unused]] auto avm_alu_op_div = View(new_term.avm_alu_op_div); \ - [[maybe_unused]] auto avm_alu_op_div_a_lt_b = View(new_term.avm_alu_op_div_a_lt_b); \ - [[maybe_unused]] auto avm_alu_op_div_std = View(new_term.avm_alu_op_div_std); \ - [[maybe_unused]] auto avm_alu_op_eq = View(new_term.avm_alu_op_eq); \ - [[maybe_unused]] auto avm_alu_op_eq_diff_inv = View(new_term.avm_alu_op_eq_diff_inv); \ - [[maybe_unused]] auto avm_alu_op_lt = View(new_term.avm_alu_op_lt); \ - [[maybe_unused]] auto avm_alu_op_lte = View(new_term.avm_alu_op_lte); \ - [[maybe_unused]] auto avm_alu_op_mul = View(new_term.avm_alu_op_mul); \ - [[maybe_unused]] auto avm_alu_op_not = View(new_term.avm_alu_op_not); \ - [[maybe_unused]] auto avm_alu_op_shl = View(new_term.avm_alu_op_shl); \ - [[maybe_unused]] auto avm_alu_op_shr = View(new_term.avm_alu_op_shr); \ - [[maybe_unused]] auto avm_alu_op_sub = View(new_term.avm_alu_op_sub); \ - [[maybe_unused]] auto avm_alu_p_a_borrow = View(new_term.avm_alu_p_a_borrow); \ - [[maybe_unused]] auto avm_alu_p_b_borrow = View(new_term.avm_alu_p_b_borrow); \ - [[maybe_unused]] auto avm_alu_p_sub_a_hi = View(new_term.avm_alu_p_sub_a_hi); \ - [[maybe_unused]] auto avm_alu_p_sub_a_lo = View(new_term.avm_alu_p_sub_a_lo); \ - [[maybe_unused]] auto avm_alu_p_sub_b_hi = View(new_term.avm_alu_p_sub_b_hi); \ - [[maybe_unused]] auto avm_alu_p_sub_b_lo = View(new_term.avm_alu_p_sub_b_lo); \ - [[maybe_unused]] auto avm_alu_partial_prod_hi = View(new_term.avm_alu_partial_prod_hi); \ - [[maybe_unused]] auto avm_alu_partial_prod_lo = View(new_term.avm_alu_partial_prod_lo); \ - [[maybe_unused]] auto avm_alu_quotient_hi = View(new_term.avm_alu_quotient_hi); \ - [[maybe_unused]] auto avm_alu_quotient_lo = View(new_term.avm_alu_quotient_lo); \ - [[maybe_unused]] auto avm_alu_remainder = View(new_term.avm_alu_remainder); \ - [[maybe_unused]] auto avm_alu_res_hi = View(new_term.avm_alu_res_hi); \ - [[maybe_unused]] auto avm_alu_res_lo = View(new_term.avm_alu_res_lo); \ - [[maybe_unused]] auto avm_alu_rng_chk_lookup_selector = View(new_term.avm_alu_rng_chk_lookup_selector); \ - [[maybe_unused]] auto avm_alu_rng_chk_sel = View(new_term.avm_alu_rng_chk_sel); \ - [[maybe_unused]] auto avm_alu_shift_lt_bit_len = View(new_term.avm_alu_shift_lt_bit_len); \ - [[maybe_unused]] auto avm_alu_shift_sel = View(new_term.avm_alu_shift_sel); \ - [[maybe_unused]] auto avm_alu_t_sub_s_bits = View(new_term.avm_alu_t_sub_s_bits); \ - [[maybe_unused]] auto avm_alu_two_pow_s = View(new_term.avm_alu_two_pow_s); \ - [[maybe_unused]] auto avm_alu_two_pow_t_sub_s = View(new_term.avm_alu_two_pow_t_sub_s); \ - [[maybe_unused]] auto avm_alu_u128_tag = View(new_term.avm_alu_u128_tag); \ - [[maybe_unused]] auto avm_alu_u16_r0 = View(new_term.avm_alu_u16_r0); \ - [[maybe_unused]] auto avm_alu_u16_r1 = View(new_term.avm_alu_u16_r1); \ - [[maybe_unused]] auto avm_alu_u16_r10 = View(new_term.avm_alu_u16_r10); \ - [[maybe_unused]] auto avm_alu_u16_r11 = View(new_term.avm_alu_u16_r11); \ - [[maybe_unused]] auto avm_alu_u16_r12 = View(new_term.avm_alu_u16_r12); \ - [[maybe_unused]] auto avm_alu_u16_r13 = View(new_term.avm_alu_u16_r13); \ - [[maybe_unused]] auto avm_alu_u16_r14 = View(new_term.avm_alu_u16_r14); \ - [[maybe_unused]] auto avm_alu_u16_r2 = View(new_term.avm_alu_u16_r2); \ - [[maybe_unused]] auto avm_alu_u16_r3 = View(new_term.avm_alu_u16_r3); \ - [[maybe_unused]] auto avm_alu_u16_r4 = View(new_term.avm_alu_u16_r4); \ - [[maybe_unused]] auto avm_alu_u16_r5 = View(new_term.avm_alu_u16_r5); \ - [[maybe_unused]] auto avm_alu_u16_r6 = View(new_term.avm_alu_u16_r6); \ - [[maybe_unused]] auto avm_alu_u16_r7 = View(new_term.avm_alu_u16_r7); \ - [[maybe_unused]] auto avm_alu_u16_r8 = View(new_term.avm_alu_u16_r8); \ - [[maybe_unused]] auto avm_alu_u16_r9 = View(new_term.avm_alu_u16_r9); \ - [[maybe_unused]] auto avm_alu_u16_tag = View(new_term.avm_alu_u16_tag); \ - [[maybe_unused]] auto avm_alu_u32_tag = View(new_term.avm_alu_u32_tag); \ - [[maybe_unused]] auto avm_alu_u64_tag = View(new_term.avm_alu_u64_tag); \ - [[maybe_unused]] auto avm_alu_u8_r0 = View(new_term.avm_alu_u8_r0); \ - [[maybe_unused]] auto avm_alu_u8_r1 = View(new_term.avm_alu_u8_r1); \ - [[maybe_unused]] auto avm_alu_u8_tag = View(new_term.avm_alu_u8_tag); \ - [[maybe_unused]] auto avm_binary_acc_ia = View(new_term.avm_binary_acc_ia); \ - [[maybe_unused]] auto avm_binary_acc_ib = View(new_term.avm_binary_acc_ib); \ - [[maybe_unused]] auto avm_binary_acc_ic = View(new_term.avm_binary_acc_ic); \ - [[maybe_unused]] auto avm_binary_bin_sel = View(new_term.avm_binary_bin_sel); \ - [[maybe_unused]] auto avm_binary_clk = View(new_term.avm_binary_clk); \ - [[maybe_unused]] auto avm_binary_ia_bytes = View(new_term.avm_binary_ia_bytes); \ - [[maybe_unused]] auto avm_binary_ib_bytes = View(new_term.avm_binary_ib_bytes); \ - [[maybe_unused]] auto avm_binary_ic_bytes = View(new_term.avm_binary_ic_bytes); \ - [[maybe_unused]] auto avm_binary_in_tag = View(new_term.avm_binary_in_tag); \ - [[maybe_unused]] auto avm_binary_mem_tag_ctr = View(new_term.avm_binary_mem_tag_ctr); \ - [[maybe_unused]] auto avm_binary_mem_tag_ctr_inv = View(new_term.avm_binary_mem_tag_ctr_inv); \ - [[maybe_unused]] auto avm_binary_op_id = View(new_term.avm_binary_op_id); \ - [[maybe_unused]] auto avm_binary_start = View(new_term.avm_binary_start); \ - [[maybe_unused]] auto avm_byte_lookup_bin_sel = View(new_term.avm_byte_lookup_bin_sel); \ - [[maybe_unused]] auto avm_byte_lookup_table_byte_lengths = View(new_term.avm_byte_lookup_table_byte_lengths); \ - [[maybe_unused]] auto avm_byte_lookup_table_in_tags = View(new_term.avm_byte_lookup_table_in_tags); \ - [[maybe_unused]] auto avm_byte_lookup_table_input_a = View(new_term.avm_byte_lookup_table_input_a); \ - [[maybe_unused]] auto avm_byte_lookup_table_input_b = View(new_term.avm_byte_lookup_table_input_b); \ - [[maybe_unused]] auto avm_byte_lookup_table_op_id = View(new_term.avm_byte_lookup_table_op_id); \ - [[maybe_unused]] auto avm_byte_lookup_table_output = View(new_term.avm_byte_lookup_table_output); \ - [[maybe_unused]] auto avm_conversion_clk = View(new_term.avm_conversion_clk); \ - [[maybe_unused]] auto avm_conversion_input = View(new_term.avm_conversion_input); \ - [[maybe_unused]] auto avm_conversion_num_limbs = View(new_term.avm_conversion_num_limbs); \ - [[maybe_unused]] auto avm_conversion_radix = View(new_term.avm_conversion_radix); \ - [[maybe_unused]] auto avm_conversion_to_radix_le_sel = View(new_term.avm_conversion_to_radix_le_sel); \ - [[maybe_unused]] auto avm_gas_da_gas_fixed_table = View(new_term.avm_gas_da_gas_fixed_table); \ - [[maybe_unused]] auto avm_gas_gas_cost_sel = View(new_term.avm_gas_gas_cost_sel); \ - [[maybe_unused]] auto avm_gas_l2_gas_fixed_table = View(new_term.avm_gas_l2_gas_fixed_table); \ - [[maybe_unused]] auto avm_keccakf1600_clk = View(new_term.avm_keccakf1600_clk); \ - [[maybe_unused]] auto avm_keccakf1600_input = View(new_term.avm_keccakf1600_input); \ - [[maybe_unused]] auto avm_keccakf1600_keccakf1600_sel = View(new_term.avm_keccakf1600_keccakf1600_sel); \ - [[maybe_unused]] auto avm_keccakf1600_output = View(new_term.avm_keccakf1600_output); \ - [[maybe_unused]] auto avm_kernel_emit_l2_to_l1_msg_write_offset = \ - View(new_term.avm_kernel_emit_l2_to_l1_msg_write_offset); \ - [[maybe_unused]] auto avm_kernel_emit_note_hash_write_offset = \ - View(new_term.avm_kernel_emit_note_hash_write_offset); \ - [[maybe_unused]] auto avm_kernel_emit_nullifier_write_offset = \ - View(new_term.avm_kernel_emit_nullifier_write_offset); \ - [[maybe_unused]] auto avm_kernel_emit_unencrypted_log_write_offset = \ - View(new_term.avm_kernel_emit_unencrypted_log_write_offset); \ - [[maybe_unused]] auto avm_kernel_kernel_in_offset = View(new_term.avm_kernel_kernel_in_offset); \ - [[maybe_unused]] auto avm_kernel_kernel_inputs = View(new_term.avm_kernel_kernel_inputs); \ - [[maybe_unused]] auto avm_kernel_kernel_metadata_out = View(new_term.avm_kernel_kernel_metadata_out); \ - [[maybe_unused]] auto avm_kernel_kernel_out_offset = View(new_term.avm_kernel_kernel_out_offset); \ - [[maybe_unused]] auto avm_kernel_kernel_side_effect_out = View(new_term.avm_kernel_kernel_side_effect_out); \ - [[maybe_unused]] auto avm_kernel_kernel_value_out = View(new_term.avm_kernel_kernel_value_out); \ - [[maybe_unused]] auto avm_kernel_l1_to_l2_msg_exists_write_offset = \ - View(new_term.avm_kernel_l1_to_l2_msg_exists_write_offset); \ - [[maybe_unused]] auto avm_kernel_note_hash_exist_write_offset = \ - View(new_term.avm_kernel_note_hash_exist_write_offset); \ - [[maybe_unused]] auto avm_kernel_nullifier_exists_write_offset = \ - View(new_term.avm_kernel_nullifier_exists_write_offset); \ - [[maybe_unused]] auto avm_kernel_nullifier_non_exists_write_offset = \ - View(new_term.avm_kernel_nullifier_non_exists_write_offset); \ - [[maybe_unused]] auto avm_kernel_q_public_input_kernel_add_to_table = \ - View(new_term.avm_kernel_q_public_input_kernel_add_to_table); \ - [[maybe_unused]] auto avm_kernel_q_public_input_kernel_out_add_to_table = \ - View(new_term.avm_kernel_q_public_input_kernel_out_add_to_table); \ - [[maybe_unused]] auto avm_kernel_side_effect_counter = View(new_term.avm_kernel_side_effect_counter); \ - [[maybe_unused]] auto avm_kernel_sload_write_offset = View(new_term.avm_kernel_sload_write_offset); \ - [[maybe_unused]] auto avm_kernel_sstore_write_offset = View(new_term.avm_kernel_sstore_write_offset); \ - [[maybe_unused]] auto avm_main_abs_da_rem_gas_hi = View(new_term.avm_main_abs_da_rem_gas_hi); \ - [[maybe_unused]] auto avm_main_abs_da_rem_gas_lo = View(new_term.avm_main_abs_da_rem_gas_lo); \ - [[maybe_unused]] auto avm_main_abs_l2_rem_gas_hi = View(new_term.avm_main_abs_l2_rem_gas_hi); \ - [[maybe_unused]] auto avm_main_abs_l2_rem_gas_lo = View(new_term.avm_main_abs_l2_rem_gas_lo); \ - [[maybe_unused]] auto avm_main_alu_in_tag = View(new_term.avm_main_alu_in_tag); \ - [[maybe_unused]] auto avm_main_alu_sel = View(new_term.avm_main_alu_sel); \ - [[maybe_unused]] auto avm_main_bin_op_id = View(new_term.avm_main_bin_op_id); \ - [[maybe_unused]] auto avm_main_bin_sel = View(new_term.avm_main_bin_sel); \ - [[maybe_unused]] auto avm_main_call_ptr = View(new_term.avm_main_call_ptr); \ - [[maybe_unused]] auto avm_main_da_gas_op = View(new_term.avm_main_da_gas_op); \ - [[maybe_unused]] auto avm_main_da_gas_remaining = View(new_term.avm_main_da_gas_remaining); \ - [[maybe_unused]] auto avm_main_da_out_of_gas = View(new_term.avm_main_da_out_of_gas); \ - [[maybe_unused]] auto avm_main_gas_cost_active = View(new_term.avm_main_gas_cost_active); \ - [[maybe_unused]] auto avm_main_ia = View(new_term.avm_main_ia); \ - [[maybe_unused]] auto avm_main_ib = View(new_term.avm_main_ib); \ - [[maybe_unused]] auto avm_main_ic = View(new_term.avm_main_ic); \ - [[maybe_unused]] auto avm_main_id = View(new_term.avm_main_id); \ - [[maybe_unused]] auto avm_main_id_zero = View(new_term.avm_main_id_zero); \ - [[maybe_unused]] auto avm_main_ind_a = View(new_term.avm_main_ind_a); \ - [[maybe_unused]] auto avm_main_ind_b = View(new_term.avm_main_ind_b); \ - [[maybe_unused]] auto avm_main_ind_c = View(new_term.avm_main_ind_c); \ - [[maybe_unused]] auto avm_main_ind_d = View(new_term.avm_main_ind_d); \ - [[maybe_unused]] auto avm_main_ind_op_a = View(new_term.avm_main_ind_op_a); \ - [[maybe_unused]] auto avm_main_ind_op_b = View(new_term.avm_main_ind_op_b); \ - [[maybe_unused]] auto avm_main_ind_op_c = View(new_term.avm_main_ind_op_c); \ - [[maybe_unused]] auto avm_main_ind_op_d = View(new_term.avm_main_ind_op_d); \ - [[maybe_unused]] auto avm_main_internal_return_ptr = View(new_term.avm_main_internal_return_ptr); \ - [[maybe_unused]] auto avm_main_inv = View(new_term.avm_main_inv); \ - [[maybe_unused]] auto avm_main_l2_gas_op = View(new_term.avm_main_l2_gas_op); \ - [[maybe_unused]] auto avm_main_l2_gas_remaining = View(new_term.avm_main_l2_gas_remaining); \ - [[maybe_unused]] auto avm_main_l2_out_of_gas = View(new_term.avm_main_l2_out_of_gas); \ - [[maybe_unused]] auto avm_main_last = View(new_term.avm_main_last); \ - [[maybe_unused]] auto avm_main_mem_idx_a = View(new_term.avm_main_mem_idx_a); \ - [[maybe_unused]] auto avm_main_mem_idx_b = View(new_term.avm_main_mem_idx_b); \ - [[maybe_unused]] auto avm_main_mem_idx_c = View(new_term.avm_main_mem_idx_c); \ - [[maybe_unused]] auto avm_main_mem_idx_d = View(new_term.avm_main_mem_idx_d); \ - [[maybe_unused]] auto avm_main_mem_op_a = View(new_term.avm_main_mem_op_a); \ - [[maybe_unused]] auto avm_main_mem_op_activate_gas = View(new_term.avm_main_mem_op_activate_gas); \ - [[maybe_unused]] auto avm_main_mem_op_b = View(new_term.avm_main_mem_op_b); \ - [[maybe_unused]] auto avm_main_mem_op_c = View(new_term.avm_main_mem_op_c); \ - [[maybe_unused]] auto avm_main_mem_op_d = View(new_term.avm_main_mem_op_d); \ - [[maybe_unused]] auto avm_main_op_err = View(new_term.avm_main_op_err); \ - [[maybe_unused]] auto avm_main_opcode_val = View(new_term.avm_main_opcode_val); \ - [[maybe_unused]] auto avm_main_pc = View(new_term.avm_main_pc); \ - [[maybe_unused]] auto avm_main_q_kernel_lookup = View(new_term.avm_main_q_kernel_lookup); \ - [[maybe_unused]] auto avm_main_q_kernel_output_lookup = View(new_term.avm_main_q_kernel_output_lookup); \ - [[maybe_unused]] auto avm_main_r_in_tag = View(new_term.avm_main_r_in_tag); \ - [[maybe_unused]] auto avm_main_rwa = View(new_term.avm_main_rwa); \ - [[maybe_unused]] auto avm_main_rwb = View(new_term.avm_main_rwb); \ - [[maybe_unused]] auto avm_main_rwc = View(new_term.avm_main_rwc); \ - [[maybe_unused]] auto avm_main_rwd = View(new_term.avm_main_rwd); \ - [[maybe_unused]] auto avm_main_sel_cmov = View(new_term.avm_main_sel_cmov); \ - [[maybe_unused]] auto avm_main_sel_external_call = View(new_term.avm_main_sel_external_call); \ - [[maybe_unused]] auto avm_main_sel_halt = View(new_term.avm_main_sel_halt); \ - [[maybe_unused]] auto avm_main_sel_internal_call = View(new_term.avm_main_sel_internal_call); \ - [[maybe_unused]] auto avm_main_sel_internal_return = View(new_term.avm_main_sel_internal_return); \ - [[maybe_unused]] auto avm_main_sel_jump = View(new_term.avm_main_sel_jump); \ - [[maybe_unused]] auto avm_main_sel_jumpi = View(new_term.avm_main_sel_jumpi); \ - [[maybe_unused]] auto avm_main_sel_mov = View(new_term.avm_main_sel_mov); \ - [[maybe_unused]] auto avm_main_sel_mov_a = View(new_term.avm_main_sel_mov_a); \ - [[maybe_unused]] auto avm_main_sel_mov_b = View(new_term.avm_main_sel_mov_b); \ - [[maybe_unused]] auto avm_main_sel_op_add = View(new_term.avm_main_sel_op_add); \ - [[maybe_unused]] auto avm_main_sel_op_address = View(new_term.avm_main_sel_op_address); \ - [[maybe_unused]] auto avm_main_sel_op_and = View(new_term.avm_main_sel_op_and); \ - [[maybe_unused]] auto avm_main_sel_op_block_number = View(new_term.avm_main_sel_op_block_number); \ - [[maybe_unused]] auto avm_main_sel_op_cast = View(new_term.avm_main_sel_op_cast); \ - [[maybe_unused]] auto avm_main_sel_op_chain_id = View(new_term.avm_main_sel_op_chain_id); \ - [[maybe_unused]] auto avm_main_sel_op_coinbase = View(new_term.avm_main_sel_op_coinbase); \ - [[maybe_unused]] auto avm_main_sel_op_dagasleft = View(new_term.avm_main_sel_op_dagasleft); \ - [[maybe_unused]] auto avm_main_sel_op_div = View(new_term.avm_main_sel_op_div); \ - [[maybe_unused]] auto avm_main_sel_op_emit_l2_to_l1_msg = View(new_term.avm_main_sel_op_emit_l2_to_l1_msg); \ - [[maybe_unused]] auto avm_main_sel_op_emit_note_hash = View(new_term.avm_main_sel_op_emit_note_hash); \ - [[maybe_unused]] auto avm_main_sel_op_emit_nullifier = View(new_term.avm_main_sel_op_emit_nullifier); \ - [[maybe_unused]] auto avm_main_sel_op_emit_unencrypted_log = View(new_term.avm_main_sel_op_emit_unencrypted_log); \ - [[maybe_unused]] auto avm_main_sel_op_eq = View(new_term.avm_main_sel_op_eq); \ - [[maybe_unused]] auto avm_main_sel_op_fdiv = View(new_term.avm_main_sel_op_fdiv); \ - [[maybe_unused]] auto avm_main_sel_op_fee_per_da_gas = View(new_term.avm_main_sel_op_fee_per_da_gas); \ - [[maybe_unused]] auto avm_main_sel_op_fee_per_l2_gas = View(new_term.avm_main_sel_op_fee_per_l2_gas); \ - [[maybe_unused]] auto avm_main_sel_op_get_contract_instance = \ - View(new_term.avm_main_sel_op_get_contract_instance); \ - [[maybe_unused]] auto avm_main_sel_op_keccak = View(new_term.avm_main_sel_op_keccak); \ - [[maybe_unused]] auto avm_main_sel_op_l1_to_l2_msg_exists = View(new_term.avm_main_sel_op_l1_to_l2_msg_exists); \ - [[maybe_unused]] auto avm_main_sel_op_l2gasleft = View(new_term.avm_main_sel_op_l2gasleft); \ - [[maybe_unused]] auto avm_main_sel_op_lt = View(new_term.avm_main_sel_op_lt); \ - [[maybe_unused]] auto avm_main_sel_op_lte = View(new_term.avm_main_sel_op_lte); \ - [[maybe_unused]] auto avm_main_sel_op_mul = View(new_term.avm_main_sel_op_mul); \ - [[maybe_unused]] auto avm_main_sel_op_not = View(new_term.avm_main_sel_op_not); \ - [[maybe_unused]] auto avm_main_sel_op_note_hash_exists = View(new_term.avm_main_sel_op_note_hash_exists); \ - [[maybe_unused]] auto avm_main_sel_op_nullifier_exists = View(new_term.avm_main_sel_op_nullifier_exists); \ - [[maybe_unused]] auto avm_main_sel_op_or = View(new_term.avm_main_sel_op_or); \ - [[maybe_unused]] auto avm_main_sel_op_pedersen = View(new_term.avm_main_sel_op_pedersen); \ - [[maybe_unused]] auto avm_main_sel_op_poseidon2 = View(new_term.avm_main_sel_op_poseidon2); \ - [[maybe_unused]] auto avm_main_sel_op_radix_le = View(new_term.avm_main_sel_op_radix_le); \ - [[maybe_unused]] auto avm_main_sel_op_sender = View(new_term.avm_main_sel_op_sender); \ - [[maybe_unused]] auto avm_main_sel_op_sha256 = View(new_term.avm_main_sel_op_sha256); \ - [[maybe_unused]] auto avm_main_sel_op_shl = View(new_term.avm_main_sel_op_shl); \ - [[maybe_unused]] auto avm_main_sel_op_shr = View(new_term.avm_main_sel_op_shr); \ - [[maybe_unused]] auto avm_main_sel_op_sload = View(new_term.avm_main_sel_op_sload); \ - [[maybe_unused]] auto avm_main_sel_op_sstore = View(new_term.avm_main_sel_op_sstore); \ - [[maybe_unused]] auto avm_main_sel_op_storage_address = View(new_term.avm_main_sel_op_storage_address); \ - [[maybe_unused]] auto avm_main_sel_op_sub = View(new_term.avm_main_sel_op_sub); \ - [[maybe_unused]] auto avm_main_sel_op_timestamp = View(new_term.avm_main_sel_op_timestamp); \ - [[maybe_unused]] auto avm_main_sel_op_transaction_fee = View(new_term.avm_main_sel_op_transaction_fee); \ - [[maybe_unused]] auto avm_main_sel_op_version = View(new_term.avm_main_sel_op_version); \ - [[maybe_unused]] auto avm_main_sel_op_xor = View(new_term.avm_main_sel_op_xor); \ - [[maybe_unused]] auto avm_main_sel_rng_16 = View(new_term.avm_main_sel_rng_16); \ - [[maybe_unused]] auto avm_main_sel_rng_8 = View(new_term.avm_main_sel_rng_8); \ - [[maybe_unused]] auto avm_main_space_id = View(new_term.avm_main_space_id); \ - [[maybe_unused]] auto avm_main_table_pow_2 = View(new_term.avm_main_table_pow_2); \ - [[maybe_unused]] auto avm_main_tag_err = View(new_term.avm_main_tag_err); \ - [[maybe_unused]] auto avm_main_w_in_tag = View(new_term.avm_main_w_in_tag); \ - [[maybe_unused]] auto avm_mem_addr = View(new_term.avm_mem_addr); \ - [[maybe_unused]] auto avm_mem_clk = View(new_term.avm_mem_clk); \ - [[maybe_unused]] auto avm_mem_diff_hi = View(new_term.avm_mem_diff_hi); \ - [[maybe_unused]] auto avm_mem_diff_lo = View(new_term.avm_mem_diff_lo); \ - [[maybe_unused]] auto avm_mem_diff_mid = View(new_term.avm_mem_diff_mid); \ - [[maybe_unused]] auto avm_mem_glob_addr = View(new_term.avm_mem_glob_addr); \ - [[maybe_unused]] auto avm_mem_ind_op_a = View(new_term.avm_mem_ind_op_a); \ - [[maybe_unused]] auto avm_mem_ind_op_b = View(new_term.avm_mem_ind_op_b); \ - [[maybe_unused]] auto avm_mem_ind_op_c = View(new_term.avm_mem_ind_op_c); \ - [[maybe_unused]] auto avm_mem_ind_op_d = View(new_term.avm_mem_ind_op_d); \ - [[maybe_unused]] auto avm_mem_last = View(new_term.avm_mem_last); \ - [[maybe_unused]] auto avm_mem_lastAccess = View(new_term.avm_mem_lastAccess); \ - [[maybe_unused]] auto avm_mem_mem_sel = View(new_term.avm_mem_mem_sel); \ - [[maybe_unused]] auto avm_mem_one_min_inv = View(new_term.avm_mem_one_min_inv); \ - [[maybe_unused]] auto avm_mem_op_a = View(new_term.avm_mem_op_a); \ - [[maybe_unused]] auto avm_mem_op_b = View(new_term.avm_mem_op_b); \ - [[maybe_unused]] auto avm_mem_op_c = View(new_term.avm_mem_op_c); \ - [[maybe_unused]] auto avm_mem_op_d = View(new_term.avm_mem_op_d); \ - [[maybe_unused]] auto avm_mem_r_in_tag = View(new_term.avm_mem_r_in_tag); \ - [[maybe_unused]] auto avm_mem_rng_chk_sel = View(new_term.avm_mem_rng_chk_sel); \ - [[maybe_unused]] auto avm_mem_rw = View(new_term.avm_mem_rw); \ - [[maybe_unused]] auto avm_mem_sel_cmov = View(new_term.avm_mem_sel_cmov); \ - [[maybe_unused]] auto avm_mem_sel_mov_a = View(new_term.avm_mem_sel_mov_a); \ - [[maybe_unused]] auto avm_mem_sel_mov_b = View(new_term.avm_mem_sel_mov_b); \ - [[maybe_unused]] auto avm_mem_skip_check_tag = View(new_term.avm_mem_skip_check_tag); \ - [[maybe_unused]] auto avm_mem_space_id = View(new_term.avm_mem_space_id); \ - [[maybe_unused]] auto avm_mem_tag = View(new_term.avm_mem_tag); \ - [[maybe_unused]] auto avm_mem_tag_err = View(new_term.avm_mem_tag_err); \ - [[maybe_unused]] auto avm_mem_tsp = View(new_term.avm_mem_tsp); \ - [[maybe_unused]] auto avm_mem_val = View(new_term.avm_mem_val); \ - [[maybe_unused]] auto avm_mem_w_in_tag = View(new_term.avm_mem_w_in_tag); \ - [[maybe_unused]] auto avm_pedersen_clk = View(new_term.avm_pedersen_clk); \ - [[maybe_unused]] auto avm_pedersen_input = View(new_term.avm_pedersen_input); \ - [[maybe_unused]] auto avm_pedersen_output = View(new_term.avm_pedersen_output); \ - [[maybe_unused]] auto avm_pedersen_pedersen_sel = View(new_term.avm_pedersen_pedersen_sel); \ - [[maybe_unused]] auto avm_poseidon2_clk = View(new_term.avm_poseidon2_clk); \ - [[maybe_unused]] auto avm_poseidon2_input = View(new_term.avm_poseidon2_input); \ - [[maybe_unused]] auto avm_poseidon2_output = View(new_term.avm_poseidon2_output); \ - [[maybe_unused]] auto avm_poseidon2_poseidon_perm_sel = View(new_term.avm_poseidon2_poseidon_perm_sel); \ - [[maybe_unused]] auto avm_sha256_clk = View(new_term.avm_sha256_clk); \ - [[maybe_unused]] auto avm_sha256_input = View(new_term.avm_sha256_input); \ - [[maybe_unused]] auto avm_sha256_output = View(new_term.avm_sha256_output); \ - [[maybe_unused]] auto avm_sha256_sha256_compression_sel = View(new_term.avm_sha256_sha256_compression_sel); \ - [[maybe_unused]] auto avm_sha256_state = View(new_term.avm_sha256_state); \ + [[maybe_unused]] auto main_clk = View(new_term.main_clk); \ + [[maybe_unused]] auto main_sel_first = View(new_term.main_sel_first); \ + [[maybe_unused]] auto alu_a_hi = View(new_term.alu_a_hi); \ + [[maybe_unused]] auto alu_a_lo = View(new_term.alu_a_lo); \ + [[maybe_unused]] auto alu_b_hi = View(new_term.alu_b_hi); \ + [[maybe_unused]] auto alu_b_lo = View(new_term.alu_b_lo); \ + [[maybe_unused]] auto alu_borrow = View(new_term.alu_borrow); \ + [[maybe_unused]] auto alu_cf = View(new_term.alu_cf); \ + [[maybe_unused]] auto alu_clk = View(new_term.alu_clk); \ + [[maybe_unused]] auto alu_cmp_rng_ctr = View(new_term.alu_cmp_rng_ctr); \ + [[maybe_unused]] auto alu_div_u16_r0 = View(new_term.alu_div_u16_r0); \ + [[maybe_unused]] auto alu_div_u16_r1 = View(new_term.alu_div_u16_r1); \ + [[maybe_unused]] auto alu_div_u16_r2 = View(new_term.alu_div_u16_r2); \ + [[maybe_unused]] auto alu_div_u16_r3 = View(new_term.alu_div_u16_r3); \ + [[maybe_unused]] auto alu_div_u16_r4 = View(new_term.alu_div_u16_r4); \ + [[maybe_unused]] auto alu_div_u16_r5 = View(new_term.alu_div_u16_r5); \ + [[maybe_unused]] auto alu_div_u16_r6 = View(new_term.alu_div_u16_r6); \ + [[maybe_unused]] auto alu_div_u16_r7 = View(new_term.alu_div_u16_r7); \ + [[maybe_unused]] auto alu_divisor_hi = View(new_term.alu_divisor_hi); \ + [[maybe_unused]] auto alu_divisor_lo = View(new_term.alu_divisor_lo); \ + [[maybe_unused]] auto alu_ff_tag = View(new_term.alu_ff_tag); \ + [[maybe_unused]] auto alu_ia = View(new_term.alu_ia); \ + [[maybe_unused]] auto alu_ib = View(new_term.alu_ib); \ + [[maybe_unused]] auto alu_ic = View(new_term.alu_ic); \ + [[maybe_unused]] auto alu_in_tag = View(new_term.alu_in_tag); \ + [[maybe_unused]] auto alu_op_add = View(new_term.alu_op_add); \ + [[maybe_unused]] auto alu_op_cast = View(new_term.alu_op_cast); \ + [[maybe_unused]] auto alu_op_cast_prev = View(new_term.alu_op_cast_prev); \ + [[maybe_unused]] auto alu_op_div = View(new_term.alu_op_div); \ + [[maybe_unused]] auto alu_op_div_a_lt_b = View(new_term.alu_op_div_a_lt_b); \ + [[maybe_unused]] auto alu_op_div_std = View(new_term.alu_op_div_std); \ + [[maybe_unused]] auto alu_op_eq = View(new_term.alu_op_eq); \ + [[maybe_unused]] auto alu_op_eq_diff_inv = View(new_term.alu_op_eq_diff_inv); \ + [[maybe_unused]] auto alu_op_lt = View(new_term.alu_op_lt); \ + [[maybe_unused]] auto alu_op_lte = View(new_term.alu_op_lte); \ + [[maybe_unused]] auto alu_op_mul = View(new_term.alu_op_mul); \ + [[maybe_unused]] auto alu_op_not = View(new_term.alu_op_not); \ + [[maybe_unused]] auto alu_op_shl = View(new_term.alu_op_shl); \ + [[maybe_unused]] auto alu_op_shr = View(new_term.alu_op_shr); \ + [[maybe_unused]] auto alu_op_sub = View(new_term.alu_op_sub); \ + [[maybe_unused]] auto alu_p_a_borrow = View(new_term.alu_p_a_borrow); \ + [[maybe_unused]] auto alu_p_b_borrow = View(new_term.alu_p_b_borrow); \ + [[maybe_unused]] auto alu_p_sub_a_hi = View(new_term.alu_p_sub_a_hi); \ + [[maybe_unused]] auto alu_p_sub_a_lo = View(new_term.alu_p_sub_a_lo); \ + [[maybe_unused]] auto alu_p_sub_b_hi = View(new_term.alu_p_sub_b_hi); \ + [[maybe_unused]] auto alu_p_sub_b_lo = View(new_term.alu_p_sub_b_lo); \ + [[maybe_unused]] auto alu_partial_prod_hi = View(new_term.alu_partial_prod_hi); \ + [[maybe_unused]] auto alu_partial_prod_lo = View(new_term.alu_partial_prod_lo); \ + [[maybe_unused]] auto alu_quotient_hi = View(new_term.alu_quotient_hi); \ + [[maybe_unused]] auto alu_quotient_lo = View(new_term.alu_quotient_lo); \ + [[maybe_unused]] auto alu_remainder = View(new_term.alu_remainder); \ + [[maybe_unused]] auto alu_res_hi = View(new_term.alu_res_hi); \ + [[maybe_unused]] auto alu_res_lo = View(new_term.alu_res_lo); \ + [[maybe_unused]] auto alu_sel_alu = View(new_term.alu_sel_alu); \ + [[maybe_unused]] auto alu_sel_cmp = View(new_term.alu_sel_cmp); \ + [[maybe_unused]] auto alu_sel_div_rng_chk = View(new_term.alu_sel_div_rng_chk); \ + [[maybe_unused]] auto alu_sel_rng_chk = View(new_term.alu_sel_rng_chk); \ + [[maybe_unused]] auto alu_sel_rng_chk_lookup = View(new_term.alu_sel_rng_chk_lookup); \ + [[maybe_unused]] auto alu_sel_shift_which = View(new_term.alu_sel_shift_which); \ + [[maybe_unused]] auto alu_shift_lt_bit_len = View(new_term.alu_shift_lt_bit_len); \ + [[maybe_unused]] auto alu_t_sub_s_bits = View(new_term.alu_t_sub_s_bits); \ + [[maybe_unused]] auto alu_two_pow_s = View(new_term.alu_two_pow_s); \ + [[maybe_unused]] auto alu_two_pow_t_sub_s = View(new_term.alu_two_pow_t_sub_s); \ + [[maybe_unused]] auto alu_u128_tag = View(new_term.alu_u128_tag); \ + [[maybe_unused]] auto alu_u16_r0 = View(new_term.alu_u16_r0); \ + [[maybe_unused]] auto alu_u16_r1 = View(new_term.alu_u16_r1); \ + [[maybe_unused]] auto alu_u16_r10 = View(new_term.alu_u16_r10); \ + [[maybe_unused]] auto alu_u16_r11 = View(new_term.alu_u16_r11); \ + [[maybe_unused]] auto alu_u16_r12 = View(new_term.alu_u16_r12); \ + [[maybe_unused]] auto alu_u16_r13 = View(new_term.alu_u16_r13); \ + [[maybe_unused]] auto alu_u16_r14 = View(new_term.alu_u16_r14); \ + [[maybe_unused]] auto alu_u16_r2 = View(new_term.alu_u16_r2); \ + [[maybe_unused]] auto alu_u16_r3 = View(new_term.alu_u16_r3); \ + [[maybe_unused]] auto alu_u16_r4 = View(new_term.alu_u16_r4); \ + [[maybe_unused]] auto alu_u16_r5 = View(new_term.alu_u16_r5); \ + [[maybe_unused]] auto alu_u16_r6 = View(new_term.alu_u16_r6); \ + [[maybe_unused]] auto alu_u16_r7 = View(new_term.alu_u16_r7); \ + [[maybe_unused]] auto alu_u16_r8 = View(new_term.alu_u16_r8); \ + [[maybe_unused]] auto alu_u16_r9 = View(new_term.alu_u16_r9); \ + [[maybe_unused]] auto alu_u16_tag = View(new_term.alu_u16_tag); \ + [[maybe_unused]] auto alu_u32_tag = View(new_term.alu_u32_tag); \ + [[maybe_unused]] auto alu_u64_tag = View(new_term.alu_u64_tag); \ + [[maybe_unused]] auto alu_u8_r0 = View(new_term.alu_u8_r0); \ + [[maybe_unused]] auto alu_u8_r1 = View(new_term.alu_u8_r1); \ + [[maybe_unused]] auto alu_u8_tag = View(new_term.alu_u8_tag); \ + [[maybe_unused]] auto binary_acc_ia = View(new_term.binary_acc_ia); \ + [[maybe_unused]] auto binary_acc_ib = View(new_term.binary_acc_ib); \ + [[maybe_unused]] auto binary_acc_ic = View(new_term.binary_acc_ic); \ + [[maybe_unused]] auto binary_clk = View(new_term.binary_clk); \ + [[maybe_unused]] auto binary_ia_bytes = View(new_term.binary_ia_bytes); \ + [[maybe_unused]] auto binary_ib_bytes = View(new_term.binary_ib_bytes); \ + [[maybe_unused]] auto binary_ic_bytes = View(new_term.binary_ic_bytes); \ + [[maybe_unused]] auto binary_in_tag = View(new_term.binary_in_tag); \ + [[maybe_unused]] auto binary_mem_tag_ctr = View(new_term.binary_mem_tag_ctr); \ + [[maybe_unused]] auto binary_mem_tag_ctr_inv = View(new_term.binary_mem_tag_ctr_inv); \ + [[maybe_unused]] auto binary_op_id = View(new_term.binary_op_id); \ + [[maybe_unused]] auto binary_sel_bin = View(new_term.binary_sel_bin); \ + [[maybe_unused]] auto binary_start = View(new_term.binary_start); \ + [[maybe_unused]] auto byte_lookup_sel_bin = View(new_term.byte_lookup_sel_bin); \ + [[maybe_unused]] auto byte_lookup_table_byte_lengths = View(new_term.byte_lookup_table_byte_lengths); \ + [[maybe_unused]] auto byte_lookup_table_in_tags = View(new_term.byte_lookup_table_in_tags); \ + [[maybe_unused]] auto byte_lookup_table_input_a = View(new_term.byte_lookup_table_input_a); \ + [[maybe_unused]] auto byte_lookup_table_input_b = View(new_term.byte_lookup_table_input_b); \ + [[maybe_unused]] auto byte_lookup_table_op_id = View(new_term.byte_lookup_table_op_id); \ + [[maybe_unused]] auto byte_lookup_table_output = View(new_term.byte_lookup_table_output); \ + [[maybe_unused]] auto conversion_clk = View(new_term.conversion_clk); \ + [[maybe_unused]] auto conversion_input = View(new_term.conversion_input); \ + [[maybe_unused]] auto conversion_num_limbs = View(new_term.conversion_num_limbs); \ + [[maybe_unused]] auto conversion_radix = View(new_term.conversion_radix); \ + [[maybe_unused]] auto conversion_sel_to_radix_le = View(new_term.conversion_sel_to_radix_le); \ + [[maybe_unused]] auto gas_da_gas_fixed_table = View(new_term.gas_da_gas_fixed_table); \ + [[maybe_unused]] auto gas_l2_gas_fixed_table = View(new_term.gas_l2_gas_fixed_table); \ + [[maybe_unused]] auto gas_sel_gas_cost = View(new_term.gas_sel_gas_cost); \ + [[maybe_unused]] auto keccakf1600_clk = View(new_term.keccakf1600_clk); \ + [[maybe_unused]] auto keccakf1600_input = View(new_term.keccakf1600_input); \ + [[maybe_unused]] auto keccakf1600_output = View(new_term.keccakf1600_output); \ + [[maybe_unused]] auto keccakf1600_sel_keccakf1600 = View(new_term.keccakf1600_sel_keccakf1600); \ + [[maybe_unused]] auto kernel_emit_l2_to_l1_msg_write_offset = \ + View(new_term.kernel_emit_l2_to_l1_msg_write_offset); \ + [[maybe_unused]] auto kernel_emit_note_hash_write_offset = View(new_term.kernel_emit_note_hash_write_offset); \ + [[maybe_unused]] auto kernel_emit_nullifier_write_offset = View(new_term.kernel_emit_nullifier_write_offset); \ + [[maybe_unused]] auto kernel_emit_unencrypted_log_write_offset = \ + View(new_term.kernel_emit_unencrypted_log_write_offset); \ + [[maybe_unused]] auto kernel_kernel_in_offset = View(new_term.kernel_kernel_in_offset); \ + [[maybe_unused]] auto kernel_kernel_inputs = View(new_term.kernel_kernel_inputs); \ + [[maybe_unused]] auto kernel_kernel_metadata_out = View(new_term.kernel_kernel_metadata_out); \ + [[maybe_unused]] auto kernel_kernel_out_offset = View(new_term.kernel_kernel_out_offset); \ + [[maybe_unused]] auto kernel_kernel_side_effect_out = View(new_term.kernel_kernel_side_effect_out); \ + [[maybe_unused]] auto kernel_kernel_value_out = View(new_term.kernel_kernel_value_out); \ + [[maybe_unused]] auto kernel_l1_to_l2_msg_exists_write_offset = \ + View(new_term.kernel_l1_to_l2_msg_exists_write_offset); \ + [[maybe_unused]] auto kernel_note_hash_exist_write_offset = View(new_term.kernel_note_hash_exist_write_offset); \ + [[maybe_unused]] auto kernel_nullifier_exists_write_offset = View(new_term.kernel_nullifier_exists_write_offset); \ + [[maybe_unused]] auto kernel_nullifier_non_exists_write_offset = \ + View(new_term.kernel_nullifier_non_exists_write_offset); \ + [[maybe_unused]] auto kernel_q_public_input_kernel_add_to_table = \ + View(new_term.kernel_q_public_input_kernel_add_to_table); \ + [[maybe_unused]] auto kernel_q_public_input_kernel_out_add_to_table = \ + View(new_term.kernel_q_public_input_kernel_out_add_to_table); \ + [[maybe_unused]] auto kernel_side_effect_counter = View(new_term.kernel_side_effect_counter); \ + [[maybe_unused]] auto kernel_sload_write_offset = View(new_term.kernel_sload_write_offset); \ + [[maybe_unused]] auto kernel_sstore_write_offset = View(new_term.kernel_sstore_write_offset); \ + [[maybe_unused]] auto main_abs_da_rem_gas_hi = View(new_term.main_abs_da_rem_gas_hi); \ + [[maybe_unused]] auto main_abs_da_rem_gas_lo = View(new_term.main_abs_da_rem_gas_lo); \ + [[maybe_unused]] auto main_abs_l2_rem_gas_hi = View(new_term.main_abs_l2_rem_gas_hi); \ + [[maybe_unused]] auto main_abs_l2_rem_gas_lo = View(new_term.main_abs_l2_rem_gas_lo); \ + [[maybe_unused]] auto main_alu_in_tag = View(new_term.main_alu_in_tag); \ + [[maybe_unused]] auto main_bin_op_id = View(new_term.main_bin_op_id); \ + [[maybe_unused]] auto main_call_ptr = View(new_term.main_call_ptr); \ + [[maybe_unused]] auto main_da_gas_op_cost = View(new_term.main_da_gas_op_cost); \ + [[maybe_unused]] auto main_da_gas_remaining = View(new_term.main_da_gas_remaining); \ + [[maybe_unused]] auto main_da_out_of_gas = View(new_term.main_da_out_of_gas); \ + [[maybe_unused]] auto main_ia = View(new_term.main_ia); \ + [[maybe_unused]] auto main_ib = View(new_term.main_ib); \ + [[maybe_unused]] auto main_ic = View(new_term.main_ic); \ + [[maybe_unused]] auto main_id = View(new_term.main_id); \ + [[maybe_unused]] auto main_id_zero = View(new_term.main_id_zero); \ + [[maybe_unused]] auto main_ind_addr_a = View(new_term.main_ind_addr_a); \ + [[maybe_unused]] auto main_ind_addr_b = View(new_term.main_ind_addr_b); \ + [[maybe_unused]] auto main_ind_addr_c = View(new_term.main_ind_addr_c); \ + [[maybe_unused]] auto main_ind_addr_d = View(new_term.main_ind_addr_d); \ + [[maybe_unused]] auto main_internal_return_ptr = View(new_term.main_internal_return_ptr); \ + [[maybe_unused]] auto main_inv = View(new_term.main_inv); \ + [[maybe_unused]] auto main_l2_gas_op_cost = View(new_term.main_l2_gas_op_cost); \ + [[maybe_unused]] auto main_l2_gas_remaining = View(new_term.main_l2_gas_remaining); \ + [[maybe_unused]] auto main_l2_out_of_gas = View(new_term.main_l2_out_of_gas); \ + [[maybe_unused]] auto main_mem_addr_a = View(new_term.main_mem_addr_a); \ + [[maybe_unused]] auto main_mem_addr_b = View(new_term.main_mem_addr_b); \ + [[maybe_unused]] auto main_mem_addr_c = View(new_term.main_mem_addr_c); \ + [[maybe_unused]] auto main_mem_addr_d = View(new_term.main_mem_addr_d); \ + [[maybe_unused]] auto main_op_err = View(new_term.main_op_err); \ + [[maybe_unused]] auto main_opcode_val = View(new_term.main_opcode_val); \ + [[maybe_unused]] auto main_pc = View(new_term.main_pc); \ + [[maybe_unused]] auto main_r_in_tag = View(new_term.main_r_in_tag); \ + [[maybe_unused]] auto main_rwa = View(new_term.main_rwa); \ + [[maybe_unused]] auto main_rwb = View(new_term.main_rwb); \ + [[maybe_unused]] auto main_rwc = View(new_term.main_rwc); \ + [[maybe_unused]] auto main_rwd = View(new_term.main_rwd); \ + [[maybe_unused]] auto main_sel_alu = View(new_term.main_sel_alu); \ + [[maybe_unused]] auto main_sel_bin = View(new_term.main_sel_bin); \ + [[maybe_unused]] auto main_sel_gas_accounting_active = View(new_term.main_sel_gas_accounting_active); \ + [[maybe_unused]] auto main_sel_last = View(new_term.main_sel_last); \ + [[maybe_unused]] auto main_sel_mem_op_a = View(new_term.main_sel_mem_op_a); \ + [[maybe_unused]] auto main_sel_mem_op_activate_gas = View(new_term.main_sel_mem_op_activate_gas); \ + [[maybe_unused]] auto main_sel_mem_op_b = View(new_term.main_sel_mem_op_b); \ + [[maybe_unused]] auto main_sel_mem_op_c = View(new_term.main_sel_mem_op_c); \ + [[maybe_unused]] auto main_sel_mem_op_d = View(new_term.main_sel_mem_op_d); \ + [[maybe_unused]] auto main_sel_mov_ia_to_ic = View(new_term.main_sel_mov_ia_to_ic); \ + [[maybe_unused]] auto main_sel_mov_ib_to_ic = View(new_term.main_sel_mov_ib_to_ic); \ + [[maybe_unused]] auto main_sel_op_add = View(new_term.main_sel_op_add); \ + [[maybe_unused]] auto main_sel_op_address = View(new_term.main_sel_op_address); \ + [[maybe_unused]] auto main_sel_op_and = View(new_term.main_sel_op_and); \ + [[maybe_unused]] auto main_sel_op_block_number = View(new_term.main_sel_op_block_number); \ + [[maybe_unused]] auto main_sel_op_cast = View(new_term.main_sel_op_cast); \ + [[maybe_unused]] auto main_sel_op_chain_id = View(new_term.main_sel_op_chain_id); \ + [[maybe_unused]] auto main_sel_op_cmov = View(new_term.main_sel_op_cmov); \ + [[maybe_unused]] auto main_sel_op_coinbase = View(new_term.main_sel_op_coinbase); \ + [[maybe_unused]] auto main_sel_op_dagasleft = View(new_term.main_sel_op_dagasleft); \ + [[maybe_unused]] auto main_sel_op_div = View(new_term.main_sel_op_div); \ + [[maybe_unused]] auto main_sel_op_emit_l2_to_l1_msg = View(new_term.main_sel_op_emit_l2_to_l1_msg); \ + [[maybe_unused]] auto main_sel_op_emit_note_hash = View(new_term.main_sel_op_emit_note_hash); \ + [[maybe_unused]] auto main_sel_op_emit_nullifier = View(new_term.main_sel_op_emit_nullifier); \ + [[maybe_unused]] auto main_sel_op_emit_unencrypted_log = View(new_term.main_sel_op_emit_unencrypted_log); \ + [[maybe_unused]] auto main_sel_op_eq = View(new_term.main_sel_op_eq); \ + [[maybe_unused]] auto main_sel_op_external_call = View(new_term.main_sel_op_external_call); \ + [[maybe_unused]] auto main_sel_op_fdiv = View(new_term.main_sel_op_fdiv); \ + [[maybe_unused]] auto main_sel_op_fee_per_da_gas = View(new_term.main_sel_op_fee_per_da_gas); \ + [[maybe_unused]] auto main_sel_op_fee_per_l2_gas = View(new_term.main_sel_op_fee_per_l2_gas); \ + [[maybe_unused]] auto main_sel_op_get_contract_instance = View(new_term.main_sel_op_get_contract_instance); \ + [[maybe_unused]] auto main_sel_op_halt = View(new_term.main_sel_op_halt); \ + [[maybe_unused]] auto main_sel_op_internal_call = View(new_term.main_sel_op_internal_call); \ + [[maybe_unused]] auto main_sel_op_internal_return = View(new_term.main_sel_op_internal_return); \ + [[maybe_unused]] auto main_sel_op_jump = View(new_term.main_sel_op_jump); \ + [[maybe_unused]] auto main_sel_op_jumpi = View(new_term.main_sel_op_jumpi); \ + [[maybe_unused]] auto main_sel_op_keccak = View(new_term.main_sel_op_keccak); \ + [[maybe_unused]] auto main_sel_op_l1_to_l2_msg_exists = View(new_term.main_sel_op_l1_to_l2_msg_exists); \ + [[maybe_unused]] auto main_sel_op_l2gasleft = View(new_term.main_sel_op_l2gasleft); \ + [[maybe_unused]] auto main_sel_op_lt = View(new_term.main_sel_op_lt); \ + [[maybe_unused]] auto main_sel_op_lte = View(new_term.main_sel_op_lte); \ + [[maybe_unused]] auto main_sel_op_mov = View(new_term.main_sel_op_mov); \ + [[maybe_unused]] auto main_sel_op_mul = View(new_term.main_sel_op_mul); \ + [[maybe_unused]] auto main_sel_op_not = View(new_term.main_sel_op_not); \ + [[maybe_unused]] auto main_sel_op_note_hash_exists = View(new_term.main_sel_op_note_hash_exists); \ + [[maybe_unused]] auto main_sel_op_nullifier_exists = View(new_term.main_sel_op_nullifier_exists); \ + [[maybe_unused]] auto main_sel_op_or = View(new_term.main_sel_op_or); \ + [[maybe_unused]] auto main_sel_op_pedersen = View(new_term.main_sel_op_pedersen); \ + [[maybe_unused]] auto main_sel_op_poseidon2 = View(new_term.main_sel_op_poseidon2); \ + [[maybe_unused]] auto main_sel_op_radix_le = View(new_term.main_sel_op_radix_le); \ + [[maybe_unused]] auto main_sel_op_sender = View(new_term.main_sel_op_sender); \ + [[maybe_unused]] auto main_sel_op_sha256 = View(new_term.main_sel_op_sha256); \ + [[maybe_unused]] auto main_sel_op_shl = View(new_term.main_sel_op_shl); \ + [[maybe_unused]] auto main_sel_op_shr = View(new_term.main_sel_op_shr); \ + [[maybe_unused]] auto main_sel_op_sload = View(new_term.main_sel_op_sload); \ + [[maybe_unused]] auto main_sel_op_sstore = View(new_term.main_sel_op_sstore); \ + [[maybe_unused]] auto main_sel_op_storage_address = View(new_term.main_sel_op_storage_address); \ + [[maybe_unused]] auto main_sel_op_sub = View(new_term.main_sel_op_sub); \ + [[maybe_unused]] auto main_sel_op_timestamp = View(new_term.main_sel_op_timestamp); \ + [[maybe_unused]] auto main_sel_op_transaction_fee = View(new_term.main_sel_op_transaction_fee); \ + [[maybe_unused]] auto main_sel_op_version = View(new_term.main_sel_op_version); \ + [[maybe_unused]] auto main_sel_op_xor = View(new_term.main_sel_op_xor); \ + [[maybe_unused]] auto main_sel_q_kernel_lookup = View(new_term.main_sel_q_kernel_lookup); \ + [[maybe_unused]] auto main_sel_q_kernel_output_lookup = View(new_term.main_sel_q_kernel_output_lookup); \ + [[maybe_unused]] auto main_sel_resolve_ind_addr_a = View(new_term.main_sel_resolve_ind_addr_a); \ + [[maybe_unused]] auto main_sel_resolve_ind_addr_b = View(new_term.main_sel_resolve_ind_addr_b); \ + [[maybe_unused]] auto main_sel_resolve_ind_addr_c = View(new_term.main_sel_resolve_ind_addr_c); \ + [[maybe_unused]] auto main_sel_resolve_ind_addr_d = View(new_term.main_sel_resolve_ind_addr_d); \ + [[maybe_unused]] auto main_sel_rng_16 = View(new_term.main_sel_rng_16); \ + [[maybe_unused]] auto main_sel_rng_8 = View(new_term.main_sel_rng_8); \ + [[maybe_unused]] auto main_space_id = View(new_term.main_space_id); \ + [[maybe_unused]] auto main_table_pow_2 = View(new_term.main_table_pow_2); \ + [[maybe_unused]] auto main_tag_err = View(new_term.main_tag_err); \ + [[maybe_unused]] auto main_w_in_tag = View(new_term.main_w_in_tag); \ + [[maybe_unused]] auto mem_addr = View(new_term.mem_addr); \ + [[maybe_unused]] auto mem_clk = View(new_term.mem_clk); \ + [[maybe_unused]] auto mem_diff_hi = View(new_term.mem_diff_hi); \ + [[maybe_unused]] auto mem_diff_lo = View(new_term.mem_diff_lo); \ + [[maybe_unused]] auto mem_diff_mid = View(new_term.mem_diff_mid); \ + [[maybe_unused]] auto mem_glob_addr = View(new_term.mem_glob_addr); \ + [[maybe_unused]] auto mem_last = View(new_term.mem_last); \ + [[maybe_unused]] auto mem_lastAccess = View(new_term.mem_lastAccess); \ + [[maybe_unused]] auto mem_one_min_inv = View(new_term.mem_one_min_inv); \ + [[maybe_unused]] auto mem_r_in_tag = View(new_term.mem_r_in_tag); \ + [[maybe_unused]] auto mem_rw = View(new_term.mem_rw); \ + [[maybe_unused]] auto mem_sel_mem = View(new_term.mem_sel_mem); \ + [[maybe_unused]] auto mem_sel_mov_ia_to_ic = View(new_term.mem_sel_mov_ia_to_ic); \ + [[maybe_unused]] auto mem_sel_mov_ib_to_ic = View(new_term.mem_sel_mov_ib_to_ic); \ + [[maybe_unused]] auto mem_sel_op_a = View(new_term.mem_sel_op_a); \ + [[maybe_unused]] auto mem_sel_op_b = View(new_term.mem_sel_op_b); \ + [[maybe_unused]] auto mem_sel_op_c = View(new_term.mem_sel_op_c); \ + [[maybe_unused]] auto mem_sel_op_cmov = View(new_term.mem_sel_op_cmov); \ + [[maybe_unused]] auto mem_sel_op_d = View(new_term.mem_sel_op_d); \ + [[maybe_unused]] auto mem_sel_resolve_ind_addr_a = View(new_term.mem_sel_resolve_ind_addr_a); \ + [[maybe_unused]] auto mem_sel_resolve_ind_addr_b = View(new_term.mem_sel_resolve_ind_addr_b); \ + [[maybe_unused]] auto mem_sel_resolve_ind_addr_c = View(new_term.mem_sel_resolve_ind_addr_c); \ + [[maybe_unused]] auto mem_sel_resolve_ind_addr_d = View(new_term.mem_sel_resolve_ind_addr_d); \ + [[maybe_unused]] auto mem_sel_rng_chk = View(new_term.mem_sel_rng_chk); \ + [[maybe_unused]] auto mem_skip_check_tag = View(new_term.mem_skip_check_tag); \ + [[maybe_unused]] auto mem_space_id = View(new_term.mem_space_id); \ + [[maybe_unused]] auto mem_tag = View(new_term.mem_tag); \ + [[maybe_unused]] auto mem_tag_err = View(new_term.mem_tag_err); \ + [[maybe_unused]] auto mem_tsp = View(new_term.mem_tsp); \ + [[maybe_unused]] auto mem_val = View(new_term.mem_val); \ + [[maybe_unused]] auto mem_w_in_tag = View(new_term.mem_w_in_tag); \ + [[maybe_unused]] auto pedersen_clk = View(new_term.pedersen_clk); \ + [[maybe_unused]] auto pedersen_input = View(new_term.pedersen_input); \ + [[maybe_unused]] auto pedersen_output = View(new_term.pedersen_output); \ + [[maybe_unused]] auto pedersen_sel_pedersen = View(new_term.pedersen_sel_pedersen); \ + [[maybe_unused]] auto poseidon2_clk = View(new_term.poseidon2_clk); \ + [[maybe_unused]] auto poseidon2_input = View(new_term.poseidon2_input); \ + [[maybe_unused]] auto poseidon2_output = View(new_term.poseidon2_output); \ + [[maybe_unused]] auto poseidon2_sel_poseidon_perm = View(new_term.poseidon2_sel_poseidon_perm); \ + [[maybe_unused]] auto sha256_clk = View(new_term.sha256_clk); \ + [[maybe_unused]] auto sha256_input = View(new_term.sha256_input); \ + [[maybe_unused]] auto sha256_output = View(new_term.sha256_output); \ + [[maybe_unused]] auto sha256_sel_sha256_compression = View(new_term.sha256_sel_sha256_compression); \ + [[maybe_unused]] auto sha256_state = View(new_term.sha256_state); \ [[maybe_unused]] auto perm_main_alu = View(new_term.perm_main_alu); \ [[maybe_unused]] auto perm_main_bin = View(new_term.perm_main_bin); \ [[maybe_unused]] auto perm_main_conv = View(new_term.perm_main_conv); \ @@ -312,10 +307,10 @@ [[maybe_unused]] auto perm_main_mem_b = View(new_term.perm_main_mem_b); \ [[maybe_unused]] auto perm_main_mem_c = View(new_term.perm_main_mem_c); \ [[maybe_unused]] auto perm_main_mem_d = View(new_term.perm_main_mem_d); \ - [[maybe_unused]] auto perm_main_mem_ind_a = View(new_term.perm_main_mem_ind_a); \ - [[maybe_unused]] auto perm_main_mem_ind_b = View(new_term.perm_main_mem_ind_b); \ - [[maybe_unused]] auto perm_main_mem_ind_c = View(new_term.perm_main_mem_ind_c); \ - [[maybe_unused]] auto perm_main_mem_ind_d = View(new_term.perm_main_mem_ind_d); \ + [[maybe_unused]] auto perm_main_mem_ind_addr_a = View(new_term.perm_main_mem_ind_addr_a); \ + [[maybe_unused]] auto perm_main_mem_ind_addr_b = View(new_term.perm_main_mem_ind_addr_b); \ + [[maybe_unused]] auto perm_main_mem_ind_addr_c = View(new_term.perm_main_mem_ind_addr_c); \ + [[maybe_unused]] auto perm_main_mem_ind_addr_d = View(new_term.perm_main_mem_ind_addr_d); \ [[maybe_unused]] auto lookup_byte_lengths = View(new_term.lookup_byte_lengths); \ [[maybe_unused]] auto lookup_byte_operations = View(new_term.lookup_byte_operations); \ [[maybe_unused]] auto lookup_opcode_gas = View(new_term.lookup_opcode_gas); \ @@ -398,77 +393,76 @@ [[maybe_unused]] auto lookup_div_u16_5_counts = View(new_term.lookup_div_u16_5_counts); \ [[maybe_unused]] auto lookup_div_u16_6_counts = View(new_term.lookup_div_u16_6_counts); \ [[maybe_unused]] auto lookup_div_u16_7_counts = View(new_term.lookup_div_u16_7_counts); \ - [[maybe_unused]] auto avm_alu_a_hi_shift = View(new_term.avm_alu_a_hi_shift); \ - [[maybe_unused]] auto avm_alu_a_lo_shift = View(new_term.avm_alu_a_lo_shift); \ - [[maybe_unused]] auto avm_alu_alu_sel_shift = View(new_term.avm_alu_alu_sel_shift); \ - [[maybe_unused]] auto avm_alu_b_hi_shift = View(new_term.avm_alu_b_hi_shift); \ - [[maybe_unused]] auto avm_alu_b_lo_shift = View(new_term.avm_alu_b_lo_shift); \ - [[maybe_unused]] auto avm_alu_cmp_rng_ctr_shift = View(new_term.avm_alu_cmp_rng_ctr_shift); \ - [[maybe_unused]] auto avm_alu_cmp_sel_shift = View(new_term.avm_alu_cmp_sel_shift); \ - [[maybe_unused]] auto avm_alu_div_rng_chk_selector_shift = View(new_term.avm_alu_div_rng_chk_selector_shift); \ - [[maybe_unused]] auto avm_alu_div_u16_r0_shift = View(new_term.avm_alu_div_u16_r0_shift); \ - [[maybe_unused]] auto avm_alu_div_u16_r1_shift = View(new_term.avm_alu_div_u16_r1_shift); \ - [[maybe_unused]] auto avm_alu_div_u16_r2_shift = View(new_term.avm_alu_div_u16_r2_shift); \ - [[maybe_unused]] auto avm_alu_div_u16_r3_shift = View(new_term.avm_alu_div_u16_r3_shift); \ - [[maybe_unused]] auto avm_alu_div_u16_r4_shift = View(new_term.avm_alu_div_u16_r4_shift); \ - [[maybe_unused]] auto avm_alu_div_u16_r5_shift = View(new_term.avm_alu_div_u16_r5_shift); \ - [[maybe_unused]] auto avm_alu_div_u16_r6_shift = View(new_term.avm_alu_div_u16_r6_shift); \ - [[maybe_unused]] auto avm_alu_div_u16_r7_shift = View(new_term.avm_alu_div_u16_r7_shift); \ - [[maybe_unused]] auto avm_alu_op_add_shift = View(new_term.avm_alu_op_add_shift); \ - [[maybe_unused]] auto avm_alu_op_cast_prev_shift = View(new_term.avm_alu_op_cast_prev_shift); \ - [[maybe_unused]] auto avm_alu_op_cast_shift = View(new_term.avm_alu_op_cast_shift); \ - [[maybe_unused]] auto avm_alu_op_div_shift = View(new_term.avm_alu_op_div_shift); \ - [[maybe_unused]] auto avm_alu_op_mul_shift = View(new_term.avm_alu_op_mul_shift); \ - [[maybe_unused]] auto avm_alu_op_shl_shift = View(new_term.avm_alu_op_shl_shift); \ - [[maybe_unused]] auto avm_alu_op_shr_shift = View(new_term.avm_alu_op_shr_shift); \ - [[maybe_unused]] auto avm_alu_op_sub_shift = View(new_term.avm_alu_op_sub_shift); \ - [[maybe_unused]] auto avm_alu_p_sub_a_hi_shift = View(new_term.avm_alu_p_sub_a_hi_shift); \ - [[maybe_unused]] auto avm_alu_p_sub_a_lo_shift = View(new_term.avm_alu_p_sub_a_lo_shift); \ - [[maybe_unused]] auto avm_alu_p_sub_b_hi_shift = View(new_term.avm_alu_p_sub_b_hi_shift); \ - [[maybe_unused]] auto avm_alu_p_sub_b_lo_shift = View(new_term.avm_alu_p_sub_b_lo_shift); \ - [[maybe_unused]] auto avm_alu_rng_chk_lookup_selector_shift = \ - View(new_term.avm_alu_rng_chk_lookup_selector_shift); \ - [[maybe_unused]] auto avm_alu_rng_chk_sel_shift = View(new_term.avm_alu_rng_chk_sel_shift); \ - [[maybe_unused]] auto avm_alu_u16_r0_shift = View(new_term.avm_alu_u16_r0_shift); \ - [[maybe_unused]] auto avm_alu_u16_r1_shift = View(new_term.avm_alu_u16_r1_shift); \ - [[maybe_unused]] auto avm_alu_u16_r2_shift = View(new_term.avm_alu_u16_r2_shift); \ - [[maybe_unused]] auto avm_alu_u16_r3_shift = View(new_term.avm_alu_u16_r3_shift); \ - [[maybe_unused]] auto avm_alu_u16_r4_shift = View(new_term.avm_alu_u16_r4_shift); \ - [[maybe_unused]] auto avm_alu_u16_r5_shift = View(new_term.avm_alu_u16_r5_shift); \ - [[maybe_unused]] auto avm_alu_u16_r6_shift = View(new_term.avm_alu_u16_r6_shift); \ - [[maybe_unused]] auto avm_alu_u8_r0_shift = View(new_term.avm_alu_u8_r0_shift); \ - [[maybe_unused]] auto avm_alu_u8_r1_shift = View(new_term.avm_alu_u8_r1_shift); \ - [[maybe_unused]] auto avm_binary_acc_ia_shift = View(new_term.avm_binary_acc_ia_shift); \ - [[maybe_unused]] auto avm_binary_acc_ib_shift = View(new_term.avm_binary_acc_ib_shift); \ - [[maybe_unused]] auto avm_binary_acc_ic_shift = View(new_term.avm_binary_acc_ic_shift); \ - [[maybe_unused]] auto avm_binary_mem_tag_ctr_shift = View(new_term.avm_binary_mem_tag_ctr_shift); \ - [[maybe_unused]] auto avm_binary_op_id_shift = View(new_term.avm_binary_op_id_shift); \ - [[maybe_unused]] auto avm_kernel_emit_l2_to_l1_msg_write_offset_shift = \ - View(new_term.avm_kernel_emit_l2_to_l1_msg_write_offset_shift); \ - [[maybe_unused]] auto avm_kernel_emit_note_hash_write_offset_shift = \ - View(new_term.avm_kernel_emit_note_hash_write_offset_shift); \ - [[maybe_unused]] auto avm_kernel_emit_nullifier_write_offset_shift = \ - View(new_term.avm_kernel_emit_nullifier_write_offset_shift); \ - [[maybe_unused]] auto avm_kernel_emit_unencrypted_log_write_offset_shift = \ - View(new_term.avm_kernel_emit_unencrypted_log_write_offset_shift); \ - [[maybe_unused]] auto avm_kernel_l1_to_l2_msg_exists_write_offset_shift = \ - View(new_term.avm_kernel_l1_to_l2_msg_exists_write_offset_shift); \ - [[maybe_unused]] auto avm_kernel_note_hash_exist_write_offset_shift = \ - View(new_term.avm_kernel_note_hash_exist_write_offset_shift); \ - [[maybe_unused]] auto avm_kernel_nullifier_exists_write_offset_shift = \ - View(new_term.avm_kernel_nullifier_exists_write_offset_shift); \ - [[maybe_unused]] auto avm_kernel_nullifier_non_exists_write_offset_shift = \ - View(new_term.avm_kernel_nullifier_non_exists_write_offset_shift); \ - [[maybe_unused]] auto avm_kernel_side_effect_counter_shift = View(new_term.avm_kernel_side_effect_counter_shift); \ - [[maybe_unused]] auto avm_kernel_sload_write_offset_shift = View(new_term.avm_kernel_sload_write_offset_shift); \ - [[maybe_unused]] auto avm_kernel_sstore_write_offset_shift = View(new_term.avm_kernel_sstore_write_offset_shift); \ - [[maybe_unused]] auto avm_main_da_gas_remaining_shift = View(new_term.avm_main_da_gas_remaining_shift); \ - [[maybe_unused]] auto avm_main_internal_return_ptr_shift = View(new_term.avm_main_internal_return_ptr_shift); \ - [[maybe_unused]] auto avm_main_l2_gas_remaining_shift = View(new_term.avm_main_l2_gas_remaining_shift); \ - [[maybe_unused]] auto avm_main_pc_shift = View(new_term.avm_main_pc_shift); \ - [[maybe_unused]] auto avm_mem_glob_addr_shift = View(new_term.avm_mem_glob_addr_shift); \ - [[maybe_unused]] auto avm_mem_mem_sel_shift = View(new_term.avm_mem_mem_sel_shift); \ - [[maybe_unused]] auto avm_mem_rw_shift = View(new_term.avm_mem_rw_shift); \ - [[maybe_unused]] auto avm_mem_tag_shift = View(new_term.avm_mem_tag_shift); \ - [[maybe_unused]] auto avm_mem_tsp_shift = View(new_term.avm_mem_tsp_shift); \ - [[maybe_unused]] auto avm_mem_val_shift = View(new_term.avm_mem_val_shift); + [[maybe_unused]] auto alu_a_hi_shift = View(new_term.alu_a_hi_shift); \ + [[maybe_unused]] auto alu_a_lo_shift = View(new_term.alu_a_lo_shift); \ + [[maybe_unused]] auto alu_b_hi_shift = View(new_term.alu_b_hi_shift); \ + [[maybe_unused]] auto alu_b_lo_shift = View(new_term.alu_b_lo_shift); \ + [[maybe_unused]] auto alu_cmp_rng_ctr_shift = View(new_term.alu_cmp_rng_ctr_shift); \ + [[maybe_unused]] auto alu_div_u16_r0_shift = View(new_term.alu_div_u16_r0_shift); \ + [[maybe_unused]] auto alu_div_u16_r1_shift = View(new_term.alu_div_u16_r1_shift); \ + [[maybe_unused]] auto alu_div_u16_r2_shift = View(new_term.alu_div_u16_r2_shift); \ + [[maybe_unused]] auto alu_div_u16_r3_shift = View(new_term.alu_div_u16_r3_shift); \ + [[maybe_unused]] auto alu_div_u16_r4_shift = View(new_term.alu_div_u16_r4_shift); \ + [[maybe_unused]] auto alu_div_u16_r5_shift = View(new_term.alu_div_u16_r5_shift); \ + [[maybe_unused]] auto alu_div_u16_r6_shift = View(new_term.alu_div_u16_r6_shift); \ + [[maybe_unused]] auto alu_div_u16_r7_shift = View(new_term.alu_div_u16_r7_shift); \ + [[maybe_unused]] auto alu_op_add_shift = View(new_term.alu_op_add_shift); \ + [[maybe_unused]] auto alu_op_cast_prev_shift = View(new_term.alu_op_cast_prev_shift); \ + [[maybe_unused]] auto alu_op_cast_shift = View(new_term.alu_op_cast_shift); \ + [[maybe_unused]] auto alu_op_div_shift = View(new_term.alu_op_div_shift); \ + [[maybe_unused]] auto alu_op_mul_shift = View(new_term.alu_op_mul_shift); \ + [[maybe_unused]] auto alu_op_shl_shift = View(new_term.alu_op_shl_shift); \ + [[maybe_unused]] auto alu_op_shr_shift = View(new_term.alu_op_shr_shift); \ + [[maybe_unused]] auto alu_op_sub_shift = View(new_term.alu_op_sub_shift); \ + [[maybe_unused]] auto alu_p_sub_a_hi_shift = View(new_term.alu_p_sub_a_hi_shift); \ + [[maybe_unused]] auto alu_p_sub_a_lo_shift = View(new_term.alu_p_sub_a_lo_shift); \ + [[maybe_unused]] auto alu_p_sub_b_hi_shift = View(new_term.alu_p_sub_b_hi_shift); \ + [[maybe_unused]] auto alu_p_sub_b_lo_shift = View(new_term.alu_p_sub_b_lo_shift); \ + [[maybe_unused]] auto alu_sel_alu_shift = View(new_term.alu_sel_alu_shift); \ + [[maybe_unused]] auto alu_sel_cmp_shift = View(new_term.alu_sel_cmp_shift); \ + [[maybe_unused]] auto alu_sel_div_rng_chk_shift = View(new_term.alu_sel_div_rng_chk_shift); \ + [[maybe_unused]] auto alu_sel_rng_chk_lookup_shift = View(new_term.alu_sel_rng_chk_lookup_shift); \ + [[maybe_unused]] auto alu_sel_rng_chk_shift = View(new_term.alu_sel_rng_chk_shift); \ + [[maybe_unused]] auto alu_u16_r0_shift = View(new_term.alu_u16_r0_shift); \ + [[maybe_unused]] auto alu_u16_r1_shift = View(new_term.alu_u16_r1_shift); \ + [[maybe_unused]] auto alu_u16_r2_shift = View(new_term.alu_u16_r2_shift); \ + [[maybe_unused]] auto alu_u16_r3_shift = View(new_term.alu_u16_r3_shift); \ + [[maybe_unused]] auto alu_u16_r4_shift = View(new_term.alu_u16_r4_shift); \ + [[maybe_unused]] auto alu_u16_r5_shift = View(new_term.alu_u16_r5_shift); \ + [[maybe_unused]] auto alu_u16_r6_shift = View(new_term.alu_u16_r6_shift); \ + [[maybe_unused]] auto alu_u8_r0_shift = View(new_term.alu_u8_r0_shift); \ + [[maybe_unused]] auto alu_u8_r1_shift = View(new_term.alu_u8_r1_shift); \ + [[maybe_unused]] auto binary_acc_ia_shift = View(new_term.binary_acc_ia_shift); \ + [[maybe_unused]] auto binary_acc_ib_shift = View(new_term.binary_acc_ib_shift); \ + [[maybe_unused]] auto binary_acc_ic_shift = View(new_term.binary_acc_ic_shift); \ + [[maybe_unused]] auto binary_mem_tag_ctr_shift = View(new_term.binary_mem_tag_ctr_shift); \ + [[maybe_unused]] auto binary_op_id_shift = View(new_term.binary_op_id_shift); \ + [[maybe_unused]] auto kernel_emit_l2_to_l1_msg_write_offset_shift = \ + View(new_term.kernel_emit_l2_to_l1_msg_write_offset_shift); \ + [[maybe_unused]] auto kernel_emit_note_hash_write_offset_shift = \ + View(new_term.kernel_emit_note_hash_write_offset_shift); \ + [[maybe_unused]] auto kernel_emit_nullifier_write_offset_shift = \ + View(new_term.kernel_emit_nullifier_write_offset_shift); \ + [[maybe_unused]] auto kernel_emit_unencrypted_log_write_offset_shift = \ + View(new_term.kernel_emit_unencrypted_log_write_offset_shift); \ + [[maybe_unused]] auto kernel_l1_to_l2_msg_exists_write_offset_shift = \ + View(new_term.kernel_l1_to_l2_msg_exists_write_offset_shift); \ + [[maybe_unused]] auto kernel_note_hash_exist_write_offset_shift = \ + View(new_term.kernel_note_hash_exist_write_offset_shift); \ + [[maybe_unused]] auto kernel_nullifier_exists_write_offset_shift = \ + View(new_term.kernel_nullifier_exists_write_offset_shift); \ + [[maybe_unused]] auto kernel_nullifier_non_exists_write_offset_shift = \ + View(new_term.kernel_nullifier_non_exists_write_offset_shift); \ + [[maybe_unused]] auto kernel_side_effect_counter_shift = View(new_term.kernel_side_effect_counter_shift); \ + [[maybe_unused]] auto kernel_sload_write_offset_shift = View(new_term.kernel_sload_write_offset_shift); \ + [[maybe_unused]] auto kernel_sstore_write_offset_shift = View(new_term.kernel_sstore_write_offset_shift); \ + [[maybe_unused]] auto main_da_gas_remaining_shift = View(new_term.main_da_gas_remaining_shift); \ + [[maybe_unused]] auto main_internal_return_ptr_shift = View(new_term.main_internal_return_ptr_shift); \ + [[maybe_unused]] auto main_l2_gas_remaining_shift = View(new_term.main_l2_gas_remaining_shift); \ + [[maybe_unused]] auto main_pc_shift = View(new_term.main_pc_shift); \ + [[maybe_unused]] auto mem_glob_addr_shift = View(new_term.mem_glob_addr_shift); \ + [[maybe_unused]] auto mem_rw_shift = View(new_term.mem_rw_shift); \ + [[maybe_unused]] auto mem_sel_mem_shift = View(new_term.mem_sel_mem_shift); \ + [[maybe_unused]] auto mem_tag_shift = View(new_term.mem_tag_shift); \ + [[maybe_unused]] auto mem_tsp_shift = View(new_term.mem_tsp_shift); \ + [[maybe_unused]] auto mem_val_shift = View(new_term.mem_val_shift); diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/incl_main_tag_err.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/incl_main_tag_err.hpp index cfb4885c4b5..c9caae3a4fb 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/incl_main_tag_err.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/incl_main_tag_err.hpp @@ -87,7 +87,7 @@ class incl_main_tag_err_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_mem_tag_err == 1 || in.avm_main_tag_err == 1); + return (in.mem_tag_err == 1 || in.main_tag_err == 1); } /** @@ -104,8 +104,8 @@ class incl_main_tag_err_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_mem_tag_err); - const auto is_table_entry = View(in.avm_main_tag_err); + const auto is_operation = View(in.mem_tag_err); + const auto is_table_entry = View(in.main_tag_err); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class incl_main_tag_err_lookup_settings { return std::forward_as_tuple(in.incl_main_tag_err, in.incl_main_tag_err_counts, - in.avm_mem_tag_err, - in.avm_main_tag_err, - in.avm_mem_clk, - in.avm_main_clk); + in.mem_tag_err, + in.main_tag_err, + in.mem_clk, + in.main_clk); } /** @@ -153,10 +153,10 @@ class incl_main_tag_err_lookup_settings { return std::forward_as_tuple(in.incl_main_tag_err, in.incl_main_tag_err_counts, - in.avm_mem_tag_err, - in.avm_main_tag_err, - in.avm_mem_clk, - in.avm_main_clk); + in.mem_tag_err, + in.main_tag_err, + in.mem_clk, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/incl_mem_tag_err.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/incl_mem_tag_err.hpp index 4055ceb7951..abbdf261766 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/incl_mem_tag_err.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/incl_mem_tag_err.hpp @@ -87,7 +87,7 @@ class incl_mem_tag_err_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_tag_err == 1 || in.avm_mem_tag_err == 1); + return (in.main_tag_err == 1 || in.mem_tag_err == 1); } /** @@ -104,8 +104,8 @@ class incl_mem_tag_err_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_main_tag_err); - const auto is_table_entry = View(in.avm_mem_tag_err); + const auto is_operation = View(in.main_tag_err); + const auto is_table_entry = View(in.mem_tag_err); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -133,12 +133,8 @@ class incl_mem_tag_err_lookup_settings { template static inline auto get_const_entities(const AllEntities& in) { - return std::forward_as_tuple(in.incl_mem_tag_err, - in.incl_mem_tag_err_counts, - in.avm_main_tag_err, - in.avm_mem_tag_err, - in.avm_main_clk, - in.avm_mem_clk); + return std::forward_as_tuple( + in.incl_mem_tag_err, in.incl_mem_tag_err_counts, in.main_tag_err, in.mem_tag_err, in.main_clk, in.mem_clk); } /** @@ -151,12 +147,8 @@ class incl_mem_tag_err_lookup_settings { template static inline auto get_nonconst_entities(AllEntities& in) { - return std::forward_as_tuple(in.incl_mem_tag_err, - in.incl_mem_tag_err_counts, - in.avm_main_tag_err, - in.avm_mem_tag_err, - in.avm_main_clk, - in.avm_mem_clk); + return std::forward_as_tuple( + in.incl_mem_tag_err, in.incl_mem_tag_err_counts, in.main_tag_err, in.mem_tag_err, in.main_clk, in.mem_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_sha256.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/keccakf1600.hpp similarity index 71% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_sha256.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/keccakf1600.hpp index 5b18fa3fc57..56e0a9e6a5d 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_sha256.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/keccakf1600.hpp @@ -6,19 +6,19 @@ namespace bb::Avm_vm { -template struct Avm_sha256Row { - FF avm_sha256_sha256_compression_sel{}; +template struct Keccakf1600Row { + FF keccakf1600_sel_keccakf1600{}; [[maybe_unused]] static std::vector names(); }; -inline std::string get_relation_label_avm_sha256(int index) +inline std::string get_relation_label_keccakf1600(int index) { switch (index) {} return std::to_string(index); } -template class avm_sha256Impl { +template class keccakf1600Impl { public: using FF = FF_; @@ -37,13 +37,13 @@ template class avm_sha256Impl { { Avm_DECLARE_VIEWS(0); - auto tmp = (avm_sha256_sha256_compression_sel * (-avm_sha256_sha256_compression_sel + FF(1))); + auto tmp = (keccakf1600_sel_keccakf1600 * (-keccakf1600_sel_keccakf1600 + FF(1))); tmp *= scaling_factor; std::get<0>(evals) += tmp; } } }; -template using avm_sha256 = Relation>; +template using keccakf1600 = Relation>; } // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/kernel.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/kernel.hpp new file mode 100644 index 00000000000..a53770f6481 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/kernel.hpp @@ -0,0 +1,198 @@ + +#pragma once +#include "../../relation_parameters.hpp" +#include "../../relation_types.hpp" +#include "./declare_views.hpp" + +namespace bb::Avm_vm { + +template struct KernelRow { + FF kernel_emit_l2_to_l1_msg_write_offset{}; + FF kernel_emit_l2_to_l1_msg_write_offset_shift{}; + FF kernel_emit_note_hash_write_offset{}; + FF kernel_emit_note_hash_write_offset_shift{}; + FF kernel_emit_nullifier_write_offset{}; + FF kernel_emit_nullifier_write_offset_shift{}; + FF kernel_emit_unencrypted_log_write_offset{}; + FF kernel_emit_unencrypted_log_write_offset_shift{}; + FF kernel_l1_to_l2_msg_exists_write_offset{}; + FF kernel_l1_to_l2_msg_exists_write_offset_shift{}; + FF kernel_note_hash_exist_write_offset{}; + FF kernel_note_hash_exist_write_offset_shift{}; + FF kernel_nullifier_exists_write_offset{}; + FF kernel_nullifier_exists_write_offset_shift{}; + FF kernel_nullifier_non_exists_write_offset{}; + FF kernel_nullifier_non_exists_write_offset_shift{}; + FF kernel_sload_write_offset{}; + FF kernel_sload_write_offset_shift{}; + FF kernel_sstore_write_offset{}; + FF kernel_sstore_write_offset_shift{}; + FF main_ib{}; + FF main_sel_last{}; + FF main_sel_op_emit_l2_to_l1_msg{}; + FF main_sel_op_emit_note_hash{}; + FF main_sel_op_emit_nullifier{}; + FF main_sel_op_emit_unencrypted_log{}; + FF main_sel_op_l1_to_l2_msg_exists{}; + FF main_sel_op_note_hash_exists{}; + FF main_sel_op_nullifier_exists{}; + FF main_sel_op_sload{}; + FF main_sel_op_sstore{}; + + [[maybe_unused]] static std::vector names(); +}; + +inline std::string get_relation_label_kernel(int index) +{ + switch (index) { + case 0: + return "NOTE_HASH_EXISTS_INC_CONSISTENCY_CHECK"; + + case 1: + return "EMIT_NOTE_HASH_INC_CONSISTENCY_CHECK"; + + case 2: + return "NULLIFIER_EXISTS_INC_CONSISTENCY_CHECK"; + + case 3: + return "NULLIFIER_NON_EXISTS_INC_CONSISTENCY_CHECK"; + + case 4: + return "EMIT_NULLIFIER_INC_CONSISTENCY_CHECK"; + + case 5: + return "L1_TO_L2_MSG_EXISTS_INC_CONSISTENCY_CHECK"; + + case 6: + return "EMIT_UNENCRYPTED_LOG_INC_CONSISTENCY_CHECK"; + + case 7: + return "EMIT_L2_TO_L1_MSG_INC_CONSISTENCY_CHECK"; + + case 8: + return "SLOAD_INC_CONSISTENCY_CHECK"; + + case 9: + return "SSTORE_INC_CONSISTENCY_CHECK"; + } + return std::to_string(index); +} + +template class kernelImpl { + public: + using FF = FF_; + + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, + }; + + template + void static accumulate(ContainerOverSubrelations& evals, + const AllEntities& new_term, + [[maybe_unused]] const RelationParameters&, + [[maybe_unused]] const FF& scaling_factor) + { + + // Contribution 0 + { + Avm_DECLARE_VIEWS(0); + + auto tmp = + ((-main_sel_last + FF(1)) * (kernel_note_hash_exist_write_offset_shift - + (kernel_note_hash_exist_write_offset + main_sel_op_note_hash_exists))); + tmp *= scaling_factor; + std::get<0>(evals) += tmp; + } + // Contribution 1 + { + Avm_DECLARE_VIEWS(1); + + auto tmp = ((-main_sel_last + FF(1)) * (kernel_emit_note_hash_write_offset_shift - + (kernel_emit_note_hash_write_offset + main_sel_op_emit_note_hash))); + tmp *= scaling_factor; + std::get<1>(evals) += tmp; + } + // Contribution 2 + { + Avm_DECLARE_VIEWS(2); + + auto tmp = ((-main_sel_last + FF(1)) * + (kernel_nullifier_exists_write_offset_shift - + (kernel_nullifier_exists_write_offset + (main_sel_op_nullifier_exists * main_ib)))); + tmp *= scaling_factor; + std::get<2>(evals) += tmp; + } + // Contribution 3 + { + Avm_DECLARE_VIEWS(3); + + auto tmp = + ((-main_sel_last + FF(1)) * + (kernel_nullifier_non_exists_write_offset_shift - + (kernel_nullifier_non_exists_write_offset + (main_sel_op_nullifier_exists * (-main_ib + FF(1)))))); + tmp *= scaling_factor; + std::get<3>(evals) += tmp; + } + // Contribution 4 + { + Avm_DECLARE_VIEWS(4); + + auto tmp = ((-main_sel_last + FF(1)) * (kernel_emit_nullifier_write_offset_shift - + (kernel_emit_nullifier_write_offset + main_sel_op_emit_nullifier))); + tmp *= scaling_factor; + std::get<4>(evals) += tmp; + } + // Contribution 5 + { + Avm_DECLARE_VIEWS(5); + + auto tmp = ((-main_sel_last + FF(1)) * + (kernel_l1_to_l2_msg_exists_write_offset_shift - + (kernel_l1_to_l2_msg_exists_write_offset + main_sel_op_l1_to_l2_msg_exists))); + tmp *= scaling_factor; + std::get<5>(evals) += tmp; + } + // Contribution 6 + { + Avm_DECLARE_VIEWS(6); + + auto tmp = ((-main_sel_last + FF(1)) * + (kernel_emit_unencrypted_log_write_offset_shift - + (kernel_emit_unencrypted_log_write_offset + main_sel_op_emit_unencrypted_log))); + tmp *= scaling_factor; + std::get<6>(evals) += tmp; + } + // Contribution 7 + { + Avm_DECLARE_VIEWS(7); + + auto tmp = + ((-main_sel_last + FF(1)) * (kernel_emit_l2_to_l1_msg_write_offset_shift - + (kernel_emit_l2_to_l1_msg_write_offset + main_sel_op_emit_l2_to_l1_msg))); + tmp *= scaling_factor; + std::get<7>(evals) += tmp; + } + // Contribution 8 + { + Avm_DECLARE_VIEWS(8); + + auto tmp = ((-main_sel_last + FF(1)) * + (kernel_sload_write_offset_shift - (kernel_sload_write_offset + main_sel_op_sload))); + tmp *= scaling_factor; + std::get<8>(evals) += tmp; + } + // Contribution 9 + { + Avm_DECLARE_VIEWS(9); + + auto tmp = ((-main_sel_last + FF(1)) * + (kernel_sstore_write_offset_shift - (kernel_sstore_write_offset + main_sel_op_sstore))); + tmp *= scaling_factor; + std::get<9>(evals) += tmp; + } + } +}; + +template using kernel = Relation>; + +} // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/kernel_output_lookup.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/kernel_output_lookup.hpp index d7c6f2c1e8c..d2eda9e27dd 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/kernel_output_lookup.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/kernel_output_lookup.hpp @@ -87,7 +87,7 @@ class kernel_output_lookup_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_q_kernel_output_lookup == 1 || in.avm_kernel_q_public_input_kernel_out_add_to_table == 1); + return (in.main_sel_q_kernel_output_lookup == 1 || in.kernel_q_public_input_kernel_out_add_to_table == 1); } /** @@ -104,8 +104,8 @@ class kernel_output_lookup_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_main_q_kernel_output_lookup); - const auto is_table_entry = View(in.avm_kernel_q_public_input_kernel_out_add_to_table); + const auto is_operation = View(in.main_sel_q_kernel_output_lookup); + const auto is_table_entry = View(in.kernel_q_public_input_kernel_out_add_to_table); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,16 +135,16 @@ class kernel_output_lookup_lookup_settings { return std::forward_as_tuple(in.kernel_output_lookup, in.kernel_output_lookup_counts, - in.avm_main_q_kernel_output_lookup, - in.avm_kernel_q_public_input_kernel_out_add_to_table, - in.avm_kernel_kernel_out_offset, - in.avm_main_ia, - in.avm_kernel_side_effect_counter, - in.avm_main_ib, - in.avm_main_clk, - in.avm_kernel_kernel_value_out, - in.avm_kernel_kernel_side_effect_out, - in.avm_kernel_kernel_metadata_out); + in.main_sel_q_kernel_output_lookup, + in.kernel_q_public_input_kernel_out_add_to_table, + in.kernel_kernel_out_offset, + in.main_ia, + in.kernel_side_effect_counter, + in.main_ib, + in.main_clk, + in.kernel_kernel_value_out, + in.kernel_kernel_side_effect_out, + in.kernel_kernel_metadata_out); } /** @@ -159,16 +159,16 @@ class kernel_output_lookup_lookup_settings { return std::forward_as_tuple(in.kernel_output_lookup, in.kernel_output_lookup_counts, - in.avm_main_q_kernel_output_lookup, - in.avm_kernel_q_public_input_kernel_out_add_to_table, - in.avm_kernel_kernel_out_offset, - in.avm_main_ia, - in.avm_kernel_side_effect_counter, - in.avm_main_ib, - in.avm_main_clk, - in.avm_kernel_kernel_value_out, - in.avm_kernel_kernel_side_effect_out, - in.avm_kernel_kernel_metadata_out); + in.main_sel_q_kernel_output_lookup, + in.kernel_q_public_input_kernel_out_add_to_table, + in.kernel_kernel_out_offset, + in.main_ia, + in.kernel_side_effect_counter, + in.main_ib, + in.main_clk, + in.kernel_kernel_value_out, + in.kernel_kernel_side_effect_out, + in.kernel_kernel_metadata_out); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_byte_lengths.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_byte_lengths.hpp index 66268991c7c..bf8caeffe83 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_byte_lengths.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_byte_lengths.hpp @@ -87,7 +87,7 @@ class lookup_byte_lengths_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_binary_start == 1 || in.avm_byte_lookup_bin_sel == 1); + return (in.binary_start == 1 || in.byte_lookup_sel_bin == 1); } /** @@ -104,8 +104,8 @@ class lookup_byte_lengths_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_binary_start); - const auto is_table_entry = View(in.avm_byte_lookup_bin_sel); + const auto is_operation = View(in.binary_start); + const auto is_table_entry = View(in.byte_lookup_sel_bin); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,12 +135,12 @@ class lookup_byte_lengths_lookup_settings { return std::forward_as_tuple(in.lookup_byte_lengths, in.lookup_byte_lengths_counts, - in.avm_binary_start, - in.avm_byte_lookup_bin_sel, - in.avm_binary_in_tag, - in.avm_binary_mem_tag_ctr, - in.avm_byte_lookup_table_in_tags, - in.avm_byte_lookup_table_byte_lengths); + in.binary_start, + in.byte_lookup_sel_bin, + in.binary_in_tag, + in.binary_mem_tag_ctr, + in.byte_lookup_table_in_tags, + in.byte_lookup_table_byte_lengths); } /** @@ -155,12 +155,12 @@ class lookup_byte_lengths_lookup_settings { return std::forward_as_tuple(in.lookup_byte_lengths, in.lookup_byte_lengths_counts, - in.avm_binary_start, - in.avm_byte_lookup_bin_sel, - in.avm_binary_in_tag, - in.avm_binary_mem_tag_ctr, - in.avm_byte_lookup_table_in_tags, - in.avm_byte_lookup_table_byte_lengths); + in.binary_start, + in.byte_lookup_sel_bin, + in.binary_in_tag, + in.binary_mem_tag_ctr, + in.byte_lookup_table_in_tags, + in.byte_lookup_table_byte_lengths); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_byte_operations.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_byte_operations.hpp index baf2995fcb8..94b514151e5 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_byte_operations.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_byte_operations.hpp @@ -87,7 +87,7 @@ class lookup_byte_operations_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_binary_bin_sel == 1 || in.avm_byte_lookup_bin_sel == 1); + return (in.binary_sel_bin == 1 || in.byte_lookup_sel_bin == 1); } /** @@ -104,8 +104,8 @@ class lookup_byte_operations_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_binary_bin_sel); - const auto is_table_entry = View(in.avm_byte_lookup_bin_sel); + const auto is_operation = View(in.binary_sel_bin); + const auto is_table_entry = View(in.byte_lookup_sel_bin); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,16 +135,16 @@ class lookup_byte_operations_lookup_settings { return std::forward_as_tuple(in.lookup_byte_operations, in.lookup_byte_operations_counts, - in.avm_binary_bin_sel, - in.avm_byte_lookup_bin_sel, - in.avm_binary_op_id, - in.avm_binary_ia_bytes, - in.avm_binary_ib_bytes, - in.avm_binary_ic_bytes, - in.avm_byte_lookup_table_op_id, - in.avm_byte_lookup_table_input_a, - in.avm_byte_lookup_table_input_b, - in.avm_byte_lookup_table_output); + in.binary_sel_bin, + in.byte_lookup_sel_bin, + in.binary_op_id, + in.binary_ia_bytes, + in.binary_ib_bytes, + in.binary_ic_bytes, + in.byte_lookup_table_op_id, + in.byte_lookup_table_input_a, + in.byte_lookup_table_input_b, + in.byte_lookup_table_output); } /** @@ -159,16 +159,16 @@ class lookup_byte_operations_lookup_settings { return std::forward_as_tuple(in.lookup_byte_operations, in.lookup_byte_operations_counts, - in.avm_binary_bin_sel, - in.avm_byte_lookup_bin_sel, - in.avm_binary_op_id, - in.avm_binary_ia_bytes, - in.avm_binary_ib_bytes, - in.avm_binary_ic_bytes, - in.avm_byte_lookup_table_op_id, - in.avm_byte_lookup_table_input_a, - in.avm_byte_lookup_table_input_b, - in.avm_byte_lookup_table_output); + in.binary_sel_bin, + in.byte_lookup_sel_bin, + in.binary_op_id, + in.binary_ia_bytes, + in.binary_ib_bytes, + in.binary_ic_bytes, + in.byte_lookup_table_op_id, + in.byte_lookup_table_input_a, + in.byte_lookup_table_input_b, + in.byte_lookup_table_output); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_0.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_0.hpp index 67284e42972..405c7068df5 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_0.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_0.hpp @@ -87,7 +87,7 @@ class lookup_div_u16_0_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_div_rng_chk_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_div_rng_chk == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_div_u16_0_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_div_rng_chk_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_div_rng_chk); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_div_u16_0_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_0, in.lookup_div_u16_0_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r0, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r0, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_div_u16_0_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_0, in.lookup_div_u16_0_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r0, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r0, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_1.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_1.hpp index 38c6fd614f8..2a66fac3525 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_1.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_1.hpp @@ -87,7 +87,7 @@ class lookup_div_u16_1_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_div_rng_chk_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_div_rng_chk == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_div_u16_1_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_div_rng_chk_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_div_rng_chk); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_div_u16_1_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_1, in.lookup_div_u16_1_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r1, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r1, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_div_u16_1_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_1, in.lookup_div_u16_1_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r1, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r1, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_2.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_2.hpp index 36c347a5ba9..02d12a78597 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_2.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_2.hpp @@ -87,7 +87,7 @@ class lookup_div_u16_2_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_div_rng_chk_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_div_rng_chk == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_div_u16_2_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_div_rng_chk_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_div_rng_chk); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_div_u16_2_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_2, in.lookup_div_u16_2_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r2, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r2, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_div_u16_2_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_2, in.lookup_div_u16_2_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r2, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r2, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_3.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_3.hpp index e167bae69bb..438d59d1d4a 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_3.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_3.hpp @@ -87,7 +87,7 @@ class lookup_div_u16_3_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_div_rng_chk_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_div_rng_chk == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_div_u16_3_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_div_rng_chk_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_div_rng_chk); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_div_u16_3_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_3, in.lookup_div_u16_3_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r3, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r3, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_div_u16_3_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_3, in.lookup_div_u16_3_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r3, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r3, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_4.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_4.hpp index 6248bc098d6..7dd1c7cac4f 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_4.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_4.hpp @@ -87,7 +87,7 @@ class lookup_div_u16_4_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_div_rng_chk_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_div_rng_chk == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_div_u16_4_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_div_rng_chk_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_div_rng_chk); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_div_u16_4_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_4, in.lookup_div_u16_4_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r4, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r4, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_div_u16_4_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_4, in.lookup_div_u16_4_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r4, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r4, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_5.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_5.hpp index 052eafcaa3b..cf3b6d8c71f 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_5.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_5.hpp @@ -87,7 +87,7 @@ class lookup_div_u16_5_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_div_rng_chk_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_div_rng_chk == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_div_u16_5_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_div_rng_chk_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_div_rng_chk); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_div_u16_5_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_5, in.lookup_div_u16_5_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r5, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r5, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_div_u16_5_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_5, in.lookup_div_u16_5_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r5, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r5, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_6.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_6.hpp index c52d71bdb99..d78115f533c 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_6.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_6.hpp @@ -87,7 +87,7 @@ class lookup_div_u16_6_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_div_rng_chk_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_div_rng_chk == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_div_u16_6_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_div_rng_chk_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_div_rng_chk); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_div_u16_6_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_6, in.lookup_div_u16_6_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r6, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r6, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_div_u16_6_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_6, in.lookup_div_u16_6_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r6, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r6, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_7.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_7.hpp index dde1e6f54b4..3ddb1cc484d 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_7.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_div_u16_7.hpp @@ -87,7 +87,7 @@ class lookup_div_u16_7_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_div_rng_chk_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_div_rng_chk == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_div_u16_7_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_div_rng_chk_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_div_rng_chk); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_div_u16_7_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_7, in.lookup_div_u16_7_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r7, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r7, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_div_u16_7_lookup_settings { return std::forward_as_tuple(in.lookup_div_u16_7, in.lookup_div_u16_7_counts, - in.avm_alu_div_rng_chk_selector, - in.avm_main_sel_rng_16, - in.avm_alu_div_u16_r7, - in.avm_main_clk); + in.alu_sel_div_rng_chk, + in.main_sel_rng_16, + in.alu_div_u16_r7, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_into_kernel.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_into_kernel.hpp index 28bb6402999..0dc497d421a 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_into_kernel.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_into_kernel.hpp @@ -87,7 +87,7 @@ class lookup_into_kernel_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_q_kernel_lookup == 1 || in.avm_kernel_q_public_input_kernel_add_to_table == 1); + return (in.main_sel_q_kernel_lookup == 1 || in.kernel_q_public_input_kernel_add_to_table == 1); } /** @@ -104,8 +104,8 @@ class lookup_into_kernel_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_main_q_kernel_lookup); - const auto is_table_entry = View(in.avm_kernel_q_public_input_kernel_add_to_table); + const auto is_operation = View(in.main_sel_q_kernel_lookup); + const auto is_table_entry = View(in.kernel_q_public_input_kernel_add_to_table); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,12 +135,12 @@ class lookup_into_kernel_lookup_settings { return std::forward_as_tuple(in.lookup_into_kernel, in.lookup_into_kernel_counts, - in.avm_main_q_kernel_lookup, - in.avm_kernel_q_public_input_kernel_add_to_table, - in.avm_main_ia, - in.avm_kernel_kernel_in_offset, - in.avm_kernel_kernel_inputs, - in.avm_main_clk); + in.main_sel_q_kernel_lookup, + in.kernel_q_public_input_kernel_add_to_table, + in.main_ia, + in.kernel_kernel_in_offset, + in.kernel_kernel_inputs, + in.main_clk); } /** @@ -155,12 +155,12 @@ class lookup_into_kernel_lookup_settings { return std::forward_as_tuple(in.lookup_into_kernel, in.lookup_into_kernel_counts, - in.avm_main_q_kernel_lookup, - in.avm_kernel_q_public_input_kernel_add_to_table, - in.avm_main_ia, - in.avm_kernel_kernel_in_offset, - in.avm_kernel_kernel_inputs, - in.avm_main_clk); + in.main_sel_q_kernel_lookup, + in.kernel_q_public_input_kernel_add_to_table, + in.main_ia, + in.kernel_kernel_in_offset, + in.kernel_kernel_inputs, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_mem_rng_chk_hi.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_mem_rng_chk_hi.hpp index d982ee18fc0..7557705c592 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_mem_rng_chk_hi.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_mem_rng_chk_hi.hpp @@ -87,7 +87,7 @@ class lookup_mem_rng_chk_hi_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_mem_rng_chk_sel == 1 || in.avm_main_sel_rng_8 == 1); + return (in.mem_sel_rng_chk == 1 || in.main_sel_rng_8 == 1); } /** @@ -104,8 +104,8 @@ class lookup_mem_rng_chk_hi_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_mem_rng_chk_sel); - const auto is_table_entry = View(in.avm_main_sel_rng_8); + const auto is_operation = View(in.mem_sel_rng_chk); + const auto is_table_entry = View(in.main_sel_rng_8); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_mem_rng_chk_hi_lookup_settings { return std::forward_as_tuple(in.lookup_mem_rng_chk_hi, in.lookup_mem_rng_chk_hi_counts, - in.avm_mem_rng_chk_sel, - in.avm_main_sel_rng_8, - in.avm_mem_diff_hi, - in.avm_main_clk); + in.mem_sel_rng_chk, + in.main_sel_rng_8, + in.mem_diff_hi, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_mem_rng_chk_hi_lookup_settings { return std::forward_as_tuple(in.lookup_mem_rng_chk_hi, in.lookup_mem_rng_chk_hi_counts, - in.avm_mem_rng_chk_sel, - in.avm_main_sel_rng_8, - in.avm_mem_diff_hi, - in.avm_main_clk); + in.mem_sel_rng_chk, + in.main_sel_rng_8, + in.mem_diff_hi, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_mem_rng_chk_lo.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_mem_rng_chk_lo.hpp index d59ef829c2d..ebe9884b863 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_mem_rng_chk_lo.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_mem_rng_chk_lo.hpp @@ -87,7 +87,7 @@ class lookup_mem_rng_chk_lo_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_mem_rng_chk_sel == 1 || in.avm_main_sel_rng_16 == 1); + return (in.mem_sel_rng_chk == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_mem_rng_chk_lo_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_mem_rng_chk_sel); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.mem_sel_rng_chk); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_mem_rng_chk_lo_lookup_settings { return std::forward_as_tuple(in.lookup_mem_rng_chk_lo, in.lookup_mem_rng_chk_lo_counts, - in.avm_mem_rng_chk_sel, - in.avm_main_sel_rng_16, - in.avm_mem_diff_lo, - in.avm_main_clk); + in.mem_sel_rng_chk, + in.main_sel_rng_16, + in.mem_diff_lo, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_mem_rng_chk_lo_lookup_settings { return std::forward_as_tuple(in.lookup_mem_rng_chk_lo, in.lookup_mem_rng_chk_lo_counts, - in.avm_mem_rng_chk_sel, - in.avm_main_sel_rng_16, - in.avm_mem_diff_lo, - in.avm_main_clk); + in.mem_sel_rng_chk, + in.main_sel_rng_16, + in.mem_diff_lo, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_mem_rng_chk_mid.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_mem_rng_chk_mid.hpp index bece75f6f1a..45b8a5f03ff 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_mem_rng_chk_mid.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_mem_rng_chk_mid.hpp @@ -87,7 +87,7 @@ class lookup_mem_rng_chk_mid_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_mem_rng_chk_sel == 1 || in.avm_main_sel_rng_16 == 1); + return (in.mem_sel_rng_chk == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_mem_rng_chk_mid_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_mem_rng_chk_sel); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.mem_sel_rng_chk); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_mem_rng_chk_mid_lookup_settings { return std::forward_as_tuple(in.lookup_mem_rng_chk_mid, in.lookup_mem_rng_chk_mid_counts, - in.avm_mem_rng_chk_sel, - in.avm_main_sel_rng_16, - in.avm_mem_diff_mid, - in.avm_main_clk); + in.mem_sel_rng_chk, + in.main_sel_rng_16, + in.mem_diff_mid, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_mem_rng_chk_mid_lookup_settings { return std::forward_as_tuple(in.lookup_mem_rng_chk_mid, in.lookup_mem_rng_chk_mid_counts, - in.avm_mem_rng_chk_sel, - in.avm_main_sel_rng_16, - in.avm_mem_diff_mid, - in.avm_main_clk); + in.mem_sel_rng_chk, + in.main_sel_rng_16, + in.mem_diff_mid, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_opcode_gas.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_opcode_gas.hpp index fec6ee9753d..1a164fc171a 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_opcode_gas.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_opcode_gas.hpp @@ -87,7 +87,7 @@ class lookup_opcode_gas_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_gas_cost_active == 1 || in.avm_gas_gas_cost_sel == 1); + return (in.main_sel_gas_accounting_active == 1 || in.gas_sel_gas_cost == 1); } /** @@ -104,8 +104,8 @@ class lookup_opcode_gas_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_main_gas_cost_active); - const auto is_table_entry = View(in.avm_gas_gas_cost_sel); + const auto is_operation = View(in.main_sel_gas_accounting_active); + const auto is_table_entry = View(in.gas_sel_gas_cost); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,14 +135,14 @@ class lookup_opcode_gas_lookup_settings { return std::forward_as_tuple(in.lookup_opcode_gas, in.lookup_opcode_gas_counts, - in.avm_main_gas_cost_active, - in.avm_gas_gas_cost_sel, - in.avm_main_opcode_val, - in.avm_main_l2_gas_op, - in.avm_main_da_gas_op, - in.avm_main_clk, - in.avm_gas_l2_gas_fixed_table, - in.avm_gas_da_gas_fixed_table); + in.main_sel_gas_accounting_active, + in.gas_sel_gas_cost, + in.main_opcode_val, + in.main_l2_gas_op_cost, + in.main_da_gas_op_cost, + in.main_clk, + in.gas_l2_gas_fixed_table, + in.gas_da_gas_fixed_table); } /** @@ -157,14 +157,14 @@ class lookup_opcode_gas_lookup_settings { return std::forward_as_tuple(in.lookup_opcode_gas, in.lookup_opcode_gas_counts, - in.avm_main_gas_cost_active, - in.avm_gas_gas_cost_sel, - in.avm_main_opcode_val, - in.avm_main_l2_gas_op, - in.avm_main_da_gas_op, - in.avm_main_clk, - in.avm_gas_l2_gas_fixed_table, - in.avm_gas_da_gas_fixed_table); + in.main_sel_gas_accounting_active, + in.gas_sel_gas_cost, + in.main_opcode_val, + in.main_l2_gas_op_cost, + in.main_da_gas_op_cost, + in.main_clk, + in.gas_l2_gas_fixed_table, + in.gas_da_gas_fixed_table); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_pow_2_0.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_pow_2_0.hpp index a4629615a75..b042e72cf58 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_pow_2_0.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_pow_2_0.hpp @@ -87,7 +87,7 @@ class lookup_pow_2_0_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_shift_sel == 1 || in.avm_main_sel_rng_8 == 1); + return (in.alu_sel_shift_which == 1 || in.main_sel_rng_8 == 1); } /** @@ -104,8 +104,8 @@ class lookup_pow_2_0_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_shift_sel); - const auto is_table_entry = View(in.avm_main_sel_rng_8); + const auto is_operation = View(in.alu_sel_shift_which); + const auto is_table_entry = View(in.main_sel_rng_8); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,12 +135,12 @@ class lookup_pow_2_0_lookup_settings { return std::forward_as_tuple(in.lookup_pow_2_0, in.lookup_pow_2_0_counts, - in.avm_alu_shift_sel, - in.avm_main_sel_rng_8, - in.avm_alu_ib, - in.avm_alu_two_pow_s, - in.avm_main_clk, - in.avm_main_table_pow_2); + in.alu_sel_shift_which, + in.main_sel_rng_8, + in.alu_ib, + in.alu_two_pow_s, + in.main_clk, + in.main_table_pow_2); } /** @@ -155,12 +155,12 @@ class lookup_pow_2_0_lookup_settings { return std::forward_as_tuple(in.lookup_pow_2_0, in.lookup_pow_2_0_counts, - in.avm_alu_shift_sel, - in.avm_main_sel_rng_8, - in.avm_alu_ib, - in.avm_alu_two_pow_s, - in.avm_main_clk, - in.avm_main_table_pow_2); + in.alu_sel_shift_which, + in.main_sel_rng_8, + in.alu_ib, + in.alu_two_pow_s, + in.main_clk, + in.main_table_pow_2); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_pow_2_1.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_pow_2_1.hpp index e1e7284056e..0e3a413289c 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_pow_2_1.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_pow_2_1.hpp @@ -87,7 +87,7 @@ class lookup_pow_2_1_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_shift_sel == 1 || in.avm_main_sel_rng_8 == 1); + return (in.alu_sel_shift_which == 1 || in.main_sel_rng_8 == 1); } /** @@ -104,8 +104,8 @@ class lookup_pow_2_1_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_shift_sel); - const auto is_table_entry = View(in.avm_main_sel_rng_8); + const auto is_operation = View(in.alu_sel_shift_which); + const auto is_table_entry = View(in.main_sel_rng_8); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,12 +135,12 @@ class lookup_pow_2_1_lookup_settings { return std::forward_as_tuple(in.lookup_pow_2_1, in.lookup_pow_2_1_counts, - in.avm_alu_shift_sel, - in.avm_main_sel_rng_8, - in.avm_alu_t_sub_s_bits, - in.avm_alu_two_pow_t_sub_s, - in.avm_main_clk, - in.avm_main_table_pow_2); + in.alu_sel_shift_which, + in.main_sel_rng_8, + in.alu_t_sub_s_bits, + in.alu_two_pow_t_sub_s, + in.main_clk, + in.main_table_pow_2); } /** @@ -155,12 +155,12 @@ class lookup_pow_2_1_lookup_settings { return std::forward_as_tuple(in.lookup_pow_2_1, in.lookup_pow_2_1_counts, - in.avm_alu_shift_sel, - in.avm_main_sel_rng_8, - in.avm_alu_t_sub_s_bits, - in.avm_alu_two_pow_t_sub_s, - in.avm_main_clk, - in.avm_main_table_pow_2); + in.alu_sel_shift_which, + in.main_sel_rng_8, + in.alu_t_sub_s_bits, + in.alu_two_pow_t_sub_s, + in.main_clk, + in.main_table_pow_2); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_0.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_0.hpp index 67c79053609..9fd20ef02fe 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_0.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_0.hpp @@ -87,7 +87,7 @@ class lookup_u16_0_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_0_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_0_lookup_settings { return std::forward_as_tuple(in.lookup_u16_0, in.lookup_u16_0_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r0, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r0, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_0_lookup_settings { return std::forward_as_tuple(in.lookup_u16_0, in.lookup_u16_0_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r0, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r0, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_1.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_1.hpp index c5c39dd2f80..5ba1b374b8d 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_1.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_1.hpp @@ -87,7 +87,7 @@ class lookup_u16_1_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_1_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_1_lookup_settings { return std::forward_as_tuple(in.lookup_u16_1, in.lookup_u16_1_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r1, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r1, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_1_lookup_settings { return std::forward_as_tuple(in.lookup_u16_1, in.lookup_u16_1_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r1, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r1, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_10.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_10.hpp index 275dcb0f824..44de0ae6aa2 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_10.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_10.hpp @@ -87,7 +87,7 @@ class lookup_u16_10_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_10_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_10_lookup_settings { return std::forward_as_tuple(in.lookup_u16_10, in.lookup_u16_10_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r10, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r10, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_10_lookup_settings { return std::forward_as_tuple(in.lookup_u16_10, in.lookup_u16_10_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r10, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r10, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_11.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_11.hpp index b94a5f65d84..d415ae20406 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_11.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_11.hpp @@ -87,7 +87,7 @@ class lookup_u16_11_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_11_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_11_lookup_settings { return std::forward_as_tuple(in.lookup_u16_11, in.lookup_u16_11_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r11, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r11, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_11_lookup_settings { return std::forward_as_tuple(in.lookup_u16_11, in.lookup_u16_11_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r11, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r11, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_12.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_12.hpp index 4fc5cca4ebe..2fc33c33fed 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_12.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_12.hpp @@ -87,7 +87,7 @@ class lookup_u16_12_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_12_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_12_lookup_settings { return std::forward_as_tuple(in.lookup_u16_12, in.lookup_u16_12_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r12, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r12, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_12_lookup_settings { return std::forward_as_tuple(in.lookup_u16_12, in.lookup_u16_12_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r12, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r12, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_13.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_13.hpp index 908d478b8ad..1c9f92c36a8 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_13.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_13.hpp @@ -87,7 +87,7 @@ class lookup_u16_13_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_13_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_13_lookup_settings { return std::forward_as_tuple(in.lookup_u16_13, in.lookup_u16_13_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r13, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r13, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_13_lookup_settings { return std::forward_as_tuple(in.lookup_u16_13, in.lookup_u16_13_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r13, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r13, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_14.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_14.hpp index 735361f8e6c..3907fb353c0 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_14.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_14.hpp @@ -87,7 +87,7 @@ class lookup_u16_14_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_14_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_14_lookup_settings { return std::forward_as_tuple(in.lookup_u16_14, in.lookup_u16_14_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r14, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r14, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_14_lookup_settings { return std::forward_as_tuple(in.lookup_u16_14, in.lookup_u16_14_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r14, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r14, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_2.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_2.hpp index 8aa66dc7a70..7301b0fac92 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_2.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_2.hpp @@ -87,7 +87,7 @@ class lookup_u16_2_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_2_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_2_lookup_settings { return std::forward_as_tuple(in.lookup_u16_2, in.lookup_u16_2_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r2, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r2, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_2_lookup_settings { return std::forward_as_tuple(in.lookup_u16_2, in.lookup_u16_2_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r2, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r2, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_3.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_3.hpp index b1bda551024..86170a20a61 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_3.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_3.hpp @@ -87,7 +87,7 @@ class lookup_u16_3_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_3_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_3_lookup_settings { return std::forward_as_tuple(in.lookup_u16_3, in.lookup_u16_3_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r3, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r3, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_3_lookup_settings { return std::forward_as_tuple(in.lookup_u16_3, in.lookup_u16_3_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r3, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r3, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_4.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_4.hpp index 5984e1a6e59..877440f08f0 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_4.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_4.hpp @@ -87,7 +87,7 @@ class lookup_u16_4_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_4_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_4_lookup_settings { return std::forward_as_tuple(in.lookup_u16_4, in.lookup_u16_4_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r4, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r4, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_4_lookup_settings { return std::forward_as_tuple(in.lookup_u16_4, in.lookup_u16_4_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r4, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r4, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_5.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_5.hpp index d1bc6db3a29..07bac6f53b7 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_5.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_5.hpp @@ -87,7 +87,7 @@ class lookup_u16_5_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_5_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_5_lookup_settings { return std::forward_as_tuple(in.lookup_u16_5, in.lookup_u16_5_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r5, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r5, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_5_lookup_settings { return std::forward_as_tuple(in.lookup_u16_5, in.lookup_u16_5_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r5, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r5, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_6.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_6.hpp index 3838f21e967..a3db62cea1c 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_6.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_6.hpp @@ -87,7 +87,7 @@ class lookup_u16_6_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_6_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_6_lookup_settings { return std::forward_as_tuple(in.lookup_u16_6, in.lookup_u16_6_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r6, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r6, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_6_lookup_settings { return std::forward_as_tuple(in.lookup_u16_6, in.lookup_u16_6_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r6, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r6, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_7.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_7.hpp index 84b098172e9..5630605508c 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_7.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_7.hpp @@ -87,7 +87,7 @@ class lookup_u16_7_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_7_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_7_lookup_settings { return std::forward_as_tuple(in.lookup_u16_7, in.lookup_u16_7_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r7, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r7, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_7_lookup_settings { return std::forward_as_tuple(in.lookup_u16_7, in.lookup_u16_7_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r7, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r7, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_8.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_8.hpp index f75f9fa9c28..f5191fcd342 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_8.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_8.hpp @@ -87,7 +87,7 @@ class lookup_u16_8_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_8_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_8_lookup_settings { return std::forward_as_tuple(in.lookup_u16_8, in.lookup_u16_8_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r8, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r8, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_8_lookup_settings { return std::forward_as_tuple(in.lookup_u16_8, in.lookup_u16_8_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r8, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r8, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_9.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_9.hpp index 5e72a369ac4..d1337b15fd8 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_9.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u16_9.hpp @@ -87,7 +87,7 @@ class lookup_u16_9_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_16 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u16_9_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u16_9_lookup_settings { return std::forward_as_tuple(in.lookup_u16_9, in.lookup_u16_9_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r9, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r9, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u16_9_lookup_settings { return std::forward_as_tuple(in.lookup_u16_9, in.lookup_u16_9_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_16, - in.avm_alu_u16_r9, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_16, + in.alu_u16_r9, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u8_0.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u8_0.hpp index 37b5936f008..c3548716078 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u8_0.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u8_0.hpp @@ -87,7 +87,7 @@ class lookup_u8_0_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_8 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_8 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u8_0_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_8); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_8); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u8_0_lookup_settings { return std::forward_as_tuple(in.lookup_u8_0, in.lookup_u8_0_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_8, - in.avm_alu_u8_r0, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_8, + in.alu_u8_r0, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u8_0_lookup_settings { return std::forward_as_tuple(in.lookup_u8_0, in.lookup_u8_0_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_8, - in.avm_alu_u8_r0, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_8, + in.alu_u8_r0, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u8_1.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u8_1.hpp index 7941ecb1aee..41cf78b9945 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u8_1.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/lookup_u8_1.hpp @@ -87,7 +87,7 @@ class lookup_u8_1_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_alu_rng_chk_lookup_selector == 1 || in.avm_main_sel_rng_8 == 1); + return (in.alu_sel_rng_chk_lookup == 1 || in.main_sel_rng_8 == 1); } /** @@ -104,8 +104,8 @@ class lookup_u8_1_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_rng_chk_lookup_selector); - const auto is_table_entry = View(in.avm_main_sel_rng_8); + const auto is_operation = View(in.alu_sel_rng_chk_lookup); + const auto is_table_entry = View(in.main_sel_rng_8); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class lookup_u8_1_lookup_settings { return std::forward_as_tuple(in.lookup_u8_1, in.lookup_u8_1_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_8, - in.avm_alu_u8_r1, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_8, + in.alu_u8_r1, + in.main_clk); } /** @@ -153,10 +153,10 @@ class lookup_u8_1_lookup_settings { return std::forward_as_tuple(in.lookup_u8_1, in.lookup_u8_1_counts, - in.avm_alu_rng_chk_lookup_selector, - in.avm_main_sel_rng_8, - in.avm_alu_u8_r1, - in.avm_main_clk); + in.alu_sel_rng_chk_lookup, + in.main_sel_rng_8, + in.alu_u8_r1, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/main.hpp similarity index 50% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/main.hpp index f9f431b3bde..38835bdab22 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_main.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/main.hpp @@ -6,130 +6,130 @@ namespace bb::Avm_vm { -template struct Avm_mainRow { - FF avm_kernel_emit_l2_to_l1_msg_write_offset{}; - FF avm_kernel_emit_note_hash_write_offset{}; - FF avm_kernel_emit_nullifier_write_offset{}; - FF avm_kernel_emit_unencrypted_log_write_offset{}; - FF avm_kernel_kernel_in_offset{}; - FF avm_kernel_kernel_out_offset{}; - FF avm_kernel_l1_to_l2_msg_exists_write_offset{}; - FF avm_kernel_note_hash_exist_write_offset{}; - FF avm_kernel_nullifier_exists_write_offset{}; - FF avm_kernel_nullifier_non_exists_write_offset{}; - FF avm_kernel_side_effect_counter{}; - FF avm_kernel_side_effect_counter_shift{}; - FF avm_kernel_sload_write_offset{}; - FF avm_kernel_sstore_write_offset{}; - FF avm_main_abs_da_rem_gas_hi{}; - FF avm_main_abs_da_rem_gas_lo{}; - FF avm_main_abs_l2_rem_gas_hi{}; - FF avm_main_abs_l2_rem_gas_lo{}; - FF avm_main_alu_in_tag{}; - FF avm_main_alu_sel{}; - FF avm_main_bin_op_id{}; - FF avm_main_bin_sel{}; - FF avm_main_call_ptr{}; - FF avm_main_da_gas_op{}; - FF avm_main_da_gas_remaining{}; - FF avm_main_da_gas_remaining_shift{}; - FF avm_main_da_out_of_gas{}; - FF avm_main_first{}; - FF avm_main_gas_cost_active{}; - FF avm_main_ia{}; - FF avm_main_ib{}; - FF avm_main_ic{}; - FF avm_main_id{}; - FF avm_main_id_zero{}; - FF avm_main_ind_op_a{}; - FF avm_main_ind_op_b{}; - FF avm_main_ind_op_c{}; - FF avm_main_ind_op_d{}; - FF avm_main_internal_return_ptr{}; - FF avm_main_internal_return_ptr_shift{}; - FF avm_main_inv{}; - FF avm_main_l2_gas_op{}; - FF avm_main_l2_gas_remaining{}; - FF avm_main_l2_gas_remaining_shift{}; - FF avm_main_l2_out_of_gas{}; - FF avm_main_mem_idx_a{}; - FF avm_main_mem_idx_b{}; - FF avm_main_mem_op_a{}; - FF avm_main_mem_op_activate_gas{}; - FF avm_main_mem_op_b{}; - FF avm_main_mem_op_c{}; - FF avm_main_mem_op_d{}; - FF avm_main_op_err{}; - FF avm_main_pc{}; - FF avm_main_pc_shift{}; - FF avm_main_q_kernel_lookup{}; - FF avm_main_q_kernel_output_lookup{}; - FF avm_main_r_in_tag{}; - FF avm_main_rwa{}; - FF avm_main_rwb{}; - FF avm_main_rwc{}; - FF avm_main_rwd{}; - FF avm_main_sel_cmov{}; - FF avm_main_sel_external_call{}; - FF avm_main_sel_halt{}; - FF avm_main_sel_internal_call{}; - FF avm_main_sel_internal_return{}; - FF avm_main_sel_jump{}; - FF avm_main_sel_jumpi{}; - FF avm_main_sel_mov{}; - FF avm_main_sel_mov_a{}; - FF avm_main_sel_mov_b{}; - FF avm_main_sel_op_add{}; - FF avm_main_sel_op_address{}; - FF avm_main_sel_op_and{}; - FF avm_main_sel_op_block_number{}; - FF avm_main_sel_op_cast{}; - FF avm_main_sel_op_chain_id{}; - FF avm_main_sel_op_coinbase{}; - FF avm_main_sel_op_dagasleft{}; - FF avm_main_sel_op_div{}; - FF avm_main_sel_op_emit_l2_to_l1_msg{}; - FF avm_main_sel_op_emit_note_hash{}; - FF avm_main_sel_op_emit_nullifier{}; - FF avm_main_sel_op_emit_unencrypted_log{}; - FF avm_main_sel_op_eq{}; - FF avm_main_sel_op_fdiv{}; - FF avm_main_sel_op_fee_per_da_gas{}; - FF avm_main_sel_op_fee_per_l2_gas{}; - FF avm_main_sel_op_get_contract_instance{}; - FF avm_main_sel_op_keccak{}; - FF avm_main_sel_op_l1_to_l2_msg_exists{}; - FF avm_main_sel_op_l2gasleft{}; - FF avm_main_sel_op_lt{}; - FF avm_main_sel_op_lte{}; - FF avm_main_sel_op_mul{}; - FF avm_main_sel_op_not{}; - FF avm_main_sel_op_note_hash_exists{}; - FF avm_main_sel_op_nullifier_exists{}; - FF avm_main_sel_op_or{}; - FF avm_main_sel_op_pedersen{}; - FF avm_main_sel_op_poseidon2{}; - FF avm_main_sel_op_radix_le{}; - FF avm_main_sel_op_sender{}; - FF avm_main_sel_op_sha256{}; - FF avm_main_sel_op_shl{}; - FF avm_main_sel_op_shr{}; - FF avm_main_sel_op_sload{}; - FF avm_main_sel_op_sstore{}; - FF avm_main_sel_op_storage_address{}; - FF avm_main_sel_op_sub{}; - FF avm_main_sel_op_timestamp{}; - FF avm_main_sel_op_transaction_fee{}; - FF avm_main_sel_op_version{}; - FF avm_main_sel_op_xor{}; - FF avm_main_space_id{}; - FF avm_main_tag_err{}; - FF avm_main_w_in_tag{}; +template struct MainRow { + FF kernel_emit_l2_to_l1_msg_write_offset{}; + FF kernel_emit_note_hash_write_offset{}; + FF kernel_emit_nullifier_write_offset{}; + FF kernel_emit_unencrypted_log_write_offset{}; + FF kernel_kernel_in_offset{}; + FF kernel_kernel_out_offset{}; + FF kernel_l1_to_l2_msg_exists_write_offset{}; + FF kernel_note_hash_exist_write_offset{}; + FF kernel_nullifier_exists_write_offset{}; + FF kernel_nullifier_non_exists_write_offset{}; + FF kernel_side_effect_counter{}; + FF kernel_side_effect_counter_shift{}; + FF kernel_sload_write_offset{}; + FF kernel_sstore_write_offset{}; + FF main_abs_da_rem_gas_hi{}; + FF main_abs_da_rem_gas_lo{}; + FF main_abs_l2_rem_gas_hi{}; + FF main_abs_l2_rem_gas_lo{}; + FF main_alu_in_tag{}; + FF main_bin_op_id{}; + FF main_call_ptr{}; + FF main_da_gas_op_cost{}; + FF main_da_gas_remaining{}; + FF main_da_gas_remaining_shift{}; + FF main_da_out_of_gas{}; + FF main_ia{}; + FF main_ib{}; + FF main_ic{}; + FF main_id{}; + FF main_id_zero{}; + FF main_internal_return_ptr{}; + FF main_internal_return_ptr_shift{}; + FF main_inv{}; + FF main_l2_gas_op_cost{}; + FF main_l2_gas_remaining{}; + FF main_l2_gas_remaining_shift{}; + FF main_l2_out_of_gas{}; + FF main_mem_addr_a{}; + FF main_mem_addr_b{}; + FF main_op_err{}; + FF main_pc{}; + FF main_pc_shift{}; + FF main_r_in_tag{}; + FF main_rwa{}; + FF main_rwb{}; + FF main_rwc{}; + FF main_rwd{}; + FF main_sel_alu{}; + FF main_sel_bin{}; + FF main_sel_first{}; + FF main_sel_gas_accounting_active{}; + FF main_sel_mem_op_a{}; + FF main_sel_mem_op_activate_gas{}; + FF main_sel_mem_op_b{}; + FF main_sel_mem_op_c{}; + FF main_sel_mem_op_d{}; + FF main_sel_mov_ia_to_ic{}; + FF main_sel_mov_ib_to_ic{}; + FF main_sel_op_add{}; + FF main_sel_op_address{}; + FF main_sel_op_and{}; + FF main_sel_op_block_number{}; + FF main_sel_op_cast{}; + FF main_sel_op_chain_id{}; + FF main_sel_op_cmov{}; + FF main_sel_op_coinbase{}; + FF main_sel_op_dagasleft{}; + FF main_sel_op_div{}; + FF main_sel_op_emit_l2_to_l1_msg{}; + FF main_sel_op_emit_note_hash{}; + FF main_sel_op_emit_nullifier{}; + FF main_sel_op_emit_unencrypted_log{}; + FF main_sel_op_eq{}; + FF main_sel_op_external_call{}; + FF main_sel_op_fdiv{}; + FF main_sel_op_fee_per_da_gas{}; + FF main_sel_op_fee_per_l2_gas{}; + FF main_sel_op_get_contract_instance{}; + FF main_sel_op_halt{}; + FF main_sel_op_internal_call{}; + FF main_sel_op_internal_return{}; + FF main_sel_op_jump{}; + FF main_sel_op_jumpi{}; + FF main_sel_op_keccak{}; + FF main_sel_op_l1_to_l2_msg_exists{}; + FF main_sel_op_l2gasleft{}; + FF main_sel_op_lt{}; + FF main_sel_op_lte{}; + FF main_sel_op_mov{}; + FF main_sel_op_mul{}; + FF main_sel_op_not{}; + FF main_sel_op_note_hash_exists{}; + FF main_sel_op_nullifier_exists{}; + FF main_sel_op_or{}; + FF main_sel_op_pedersen{}; + FF main_sel_op_poseidon2{}; + FF main_sel_op_radix_le{}; + FF main_sel_op_sender{}; + FF main_sel_op_sha256{}; + FF main_sel_op_shl{}; + FF main_sel_op_shr{}; + FF main_sel_op_sload{}; + FF main_sel_op_sstore{}; + FF main_sel_op_storage_address{}; + FF main_sel_op_sub{}; + FF main_sel_op_timestamp{}; + FF main_sel_op_transaction_fee{}; + FF main_sel_op_version{}; + FF main_sel_op_xor{}; + FF main_sel_q_kernel_lookup{}; + FF main_sel_q_kernel_output_lookup{}; + FF main_sel_resolve_ind_addr_a{}; + FF main_sel_resolve_ind_addr_b{}; + FF main_sel_resolve_ind_addr_c{}; + FF main_sel_resolve_ind_addr_d{}; + FF main_space_id{}; + FF main_tag_err{}; + FF main_w_in_tag{}; [[maybe_unused]] static std::vector names(); }; -inline std::string get_relation_label_avm_main(int index) +inline std::string get_relation_label_main(int index) { switch (index) { case 2: @@ -285,7 +285,7 @@ inline std::string get_relation_label_avm_main(int index) return std::to_string(index); } -template class avm_mainImpl { +template class mainImpl { public: using FF = FF_; @@ -307,7 +307,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(0); - auto tmp = (avm_main_l2_out_of_gas * (-avm_main_l2_out_of_gas + FF(1))); + auto tmp = (main_l2_out_of_gas * (-main_l2_out_of_gas + FF(1))); tmp *= scaling_factor; std::get<0>(evals) += tmp; } @@ -315,7 +315,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(1); - auto tmp = (avm_main_da_out_of_gas * (-avm_main_da_out_of_gas + FF(1))); + auto tmp = (main_da_out_of_gas * (-main_da_out_of_gas + FF(1))); tmp *= scaling_factor; std::get<1>(evals) += tmp; } @@ -323,8 +323,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(2); - auto tmp = (avm_main_gas_cost_active * - ((avm_main_l2_gas_remaining_shift - avm_main_l2_gas_remaining) + avm_main_l2_gas_op)); + auto tmp = (main_sel_gas_accounting_active * + ((main_l2_gas_remaining_shift - main_l2_gas_remaining) + main_l2_gas_op_cost)); tmp *= scaling_factor; std::get<2>(evals) += tmp; } @@ -332,8 +332,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(3); - auto tmp = (avm_main_gas_cost_active * - ((avm_main_da_gas_remaining_shift - avm_main_da_gas_remaining) + avm_main_da_gas_op)); + auto tmp = (main_sel_gas_accounting_active * + ((main_da_gas_remaining_shift - main_da_gas_remaining) + main_da_gas_op_cost)); tmp *= scaling_factor; std::get<3>(evals) += tmp; } @@ -341,7 +341,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(4); - auto tmp = ((-avm_main_gas_cost_active + FF(1)) * avm_main_l2_gas_op); + auto tmp = ((-main_sel_gas_accounting_active + FF(1)) * main_l2_gas_op_cost); tmp *= scaling_factor; std::get<4>(evals) += tmp; } @@ -349,7 +349,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(5); - auto tmp = ((-avm_main_gas_cost_active + FF(1)) * avm_main_da_gas_op); + auto tmp = ((-main_sel_gas_accounting_active + FF(1)) * main_da_gas_op_cost); tmp *= scaling_factor; std::get<5>(evals) += tmp; } @@ -357,10 +357,10 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(6); - auto tmp = (avm_main_gas_cost_active * - ((((-(avm_main_l2_out_of_gas * FF(2)) + FF(1)) * avm_main_l2_gas_remaining_shift) - - (avm_main_abs_l2_rem_gas_hi * FF(65536))) - - avm_main_abs_l2_rem_gas_lo)); + auto tmp = (main_sel_gas_accounting_active * + ((((-(main_l2_out_of_gas * FF(2)) + FF(1)) * main_l2_gas_remaining_shift) - + (main_abs_l2_rem_gas_hi * FF(65536))) - + main_abs_l2_rem_gas_lo)); tmp *= scaling_factor; std::get<6>(evals) += tmp; } @@ -368,10 +368,10 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(7); - auto tmp = (avm_main_gas_cost_active * - ((((-(avm_main_da_out_of_gas * FF(2)) + FF(1)) * avm_main_da_gas_remaining_shift) - - (avm_main_abs_da_rem_gas_hi * FF(65536))) - - avm_main_abs_da_rem_gas_lo)); + auto tmp = (main_sel_gas_accounting_active * + ((((-(main_da_out_of_gas * FF(2)) + FF(1)) * main_da_gas_remaining_shift) - + (main_abs_da_rem_gas_hi * FF(65536))) - + main_abs_da_rem_gas_lo)); tmp *= scaling_factor; std::get<7>(evals) += tmp; } @@ -379,7 +379,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(8); - auto tmp = (avm_main_sel_op_sender * (-avm_main_sel_op_sender + FF(1))); + auto tmp = (main_sel_op_sender * (-main_sel_op_sender + FF(1))); tmp *= scaling_factor; std::get<8>(evals) += tmp; } @@ -387,7 +387,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(9); - auto tmp = (avm_main_sel_op_address * (-avm_main_sel_op_address + FF(1))); + auto tmp = (main_sel_op_address * (-main_sel_op_address + FF(1))); tmp *= scaling_factor; std::get<9>(evals) += tmp; } @@ -395,7 +395,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(10); - auto tmp = (avm_main_sel_op_storage_address * (-avm_main_sel_op_storage_address + FF(1))); + auto tmp = (main_sel_op_storage_address * (-main_sel_op_storage_address + FF(1))); tmp *= scaling_factor; std::get<10>(evals) += tmp; } @@ -403,7 +403,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(11); - auto tmp = (avm_main_sel_op_chain_id * (-avm_main_sel_op_chain_id + FF(1))); + auto tmp = (main_sel_op_chain_id * (-main_sel_op_chain_id + FF(1))); tmp *= scaling_factor; std::get<11>(evals) += tmp; } @@ -411,7 +411,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(12); - auto tmp = (avm_main_sel_op_version * (-avm_main_sel_op_version + FF(1))); + auto tmp = (main_sel_op_version * (-main_sel_op_version + FF(1))); tmp *= scaling_factor; std::get<12>(evals) += tmp; } @@ -419,7 +419,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(13); - auto tmp = (avm_main_sel_op_block_number * (-avm_main_sel_op_block_number + FF(1))); + auto tmp = (main_sel_op_block_number * (-main_sel_op_block_number + FF(1))); tmp *= scaling_factor; std::get<13>(evals) += tmp; } @@ -427,7 +427,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(14); - auto tmp = (avm_main_sel_op_coinbase * (-avm_main_sel_op_coinbase + FF(1))); + auto tmp = (main_sel_op_coinbase * (-main_sel_op_coinbase + FF(1))); tmp *= scaling_factor; std::get<14>(evals) += tmp; } @@ -435,7 +435,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(15); - auto tmp = (avm_main_sel_op_timestamp * (-avm_main_sel_op_timestamp + FF(1))); + auto tmp = (main_sel_op_timestamp * (-main_sel_op_timestamp + FF(1))); tmp *= scaling_factor; std::get<15>(evals) += tmp; } @@ -443,7 +443,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(16); - auto tmp = (avm_main_sel_op_fee_per_l2_gas * (-avm_main_sel_op_fee_per_l2_gas + FF(1))); + auto tmp = (main_sel_op_fee_per_l2_gas * (-main_sel_op_fee_per_l2_gas + FF(1))); tmp *= scaling_factor; std::get<16>(evals) += tmp; } @@ -451,7 +451,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(17); - auto tmp = (avm_main_sel_op_fee_per_da_gas * (-avm_main_sel_op_fee_per_da_gas + FF(1))); + auto tmp = (main_sel_op_fee_per_da_gas * (-main_sel_op_fee_per_da_gas + FF(1))); tmp *= scaling_factor; std::get<17>(evals) += tmp; } @@ -459,7 +459,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(18); - auto tmp = (avm_main_sel_op_transaction_fee * (-avm_main_sel_op_transaction_fee + FF(1))); + auto tmp = (main_sel_op_transaction_fee * (-main_sel_op_transaction_fee + FF(1))); tmp *= scaling_factor; std::get<18>(evals) += tmp; } @@ -467,7 +467,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(19); - auto tmp = (avm_main_sel_op_l2gasleft * (-avm_main_sel_op_l2gasleft + FF(1))); + auto tmp = (main_sel_op_l2gasleft * (-main_sel_op_l2gasleft + FF(1))); tmp *= scaling_factor; std::get<19>(evals) += tmp; } @@ -475,7 +475,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(20); - auto tmp = (avm_main_sel_op_dagasleft * (-avm_main_sel_op_dagasleft + FF(1))); + auto tmp = (main_sel_op_dagasleft * (-main_sel_op_dagasleft + FF(1))); tmp *= scaling_factor; std::get<20>(evals) += tmp; } @@ -483,7 +483,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(21); - auto tmp = (avm_main_sel_op_note_hash_exists * (-avm_main_sel_op_note_hash_exists + FF(1))); + auto tmp = (main_sel_op_note_hash_exists * (-main_sel_op_note_hash_exists + FF(1))); tmp *= scaling_factor; std::get<21>(evals) += tmp; } @@ -491,7 +491,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(22); - auto tmp = (avm_main_sel_op_emit_note_hash * (-avm_main_sel_op_emit_note_hash + FF(1))); + auto tmp = (main_sel_op_emit_note_hash * (-main_sel_op_emit_note_hash + FF(1))); tmp *= scaling_factor; std::get<22>(evals) += tmp; } @@ -499,7 +499,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(23); - auto tmp = (avm_main_sel_op_nullifier_exists * (-avm_main_sel_op_nullifier_exists + FF(1))); + auto tmp = (main_sel_op_nullifier_exists * (-main_sel_op_nullifier_exists + FF(1))); tmp *= scaling_factor; std::get<23>(evals) += tmp; } @@ -507,7 +507,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(24); - auto tmp = (avm_main_sel_op_emit_nullifier * (-avm_main_sel_op_emit_nullifier + FF(1))); + auto tmp = (main_sel_op_emit_nullifier * (-main_sel_op_emit_nullifier + FF(1))); tmp *= scaling_factor; std::get<24>(evals) += tmp; } @@ -515,7 +515,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(25); - auto tmp = (avm_main_sel_op_l1_to_l2_msg_exists * (-avm_main_sel_op_l1_to_l2_msg_exists + FF(1))); + auto tmp = (main_sel_op_l1_to_l2_msg_exists * (-main_sel_op_l1_to_l2_msg_exists + FF(1))); tmp *= scaling_factor; std::get<25>(evals) += tmp; } @@ -523,7 +523,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(26); - auto tmp = (avm_main_sel_op_emit_unencrypted_log * (-avm_main_sel_op_emit_unencrypted_log + FF(1))); + auto tmp = (main_sel_op_emit_unencrypted_log * (-main_sel_op_emit_unencrypted_log + FF(1))); tmp *= scaling_factor; std::get<26>(evals) += tmp; } @@ -531,7 +531,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(27); - auto tmp = (avm_main_sel_op_emit_l2_to_l1_msg * (-avm_main_sel_op_emit_l2_to_l1_msg + FF(1))); + auto tmp = (main_sel_op_emit_l2_to_l1_msg * (-main_sel_op_emit_l2_to_l1_msg + FF(1))); tmp *= scaling_factor; std::get<27>(evals) += tmp; } @@ -539,7 +539,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(28); - auto tmp = (avm_main_sel_op_get_contract_instance * (-avm_main_sel_op_get_contract_instance + FF(1))); + auto tmp = (main_sel_op_get_contract_instance * (-main_sel_op_get_contract_instance + FF(1))); tmp *= scaling_factor; std::get<28>(evals) += tmp; } @@ -547,7 +547,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(29); - auto tmp = (avm_main_sel_op_sload * (-avm_main_sel_op_sload + FF(1))); + auto tmp = (main_sel_op_sload * (-main_sel_op_sload + FF(1))); tmp *= scaling_factor; std::get<29>(evals) += tmp; } @@ -555,7 +555,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(30); - auto tmp = (avm_main_sel_op_sstore * (-avm_main_sel_op_sstore + FF(1))); + auto tmp = (main_sel_op_sstore * (-main_sel_op_sstore + FF(1))); tmp *= scaling_factor; std::get<30>(evals) += tmp; } @@ -563,7 +563,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(31); - auto tmp = (avm_main_sel_op_radix_le * (-avm_main_sel_op_radix_le + FF(1))); + auto tmp = (main_sel_op_radix_le * (-main_sel_op_radix_le + FF(1))); tmp *= scaling_factor; std::get<31>(evals) += tmp; } @@ -571,7 +571,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(32); - auto tmp = (avm_main_sel_op_sha256 * (-avm_main_sel_op_sha256 + FF(1))); + auto tmp = (main_sel_op_sha256 * (-main_sel_op_sha256 + FF(1))); tmp *= scaling_factor; std::get<32>(evals) += tmp; } @@ -579,7 +579,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(33); - auto tmp = (avm_main_sel_op_poseidon2 * (-avm_main_sel_op_poseidon2 + FF(1))); + auto tmp = (main_sel_op_poseidon2 * (-main_sel_op_poseidon2 + FF(1))); tmp *= scaling_factor; std::get<33>(evals) += tmp; } @@ -587,7 +587,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(34); - auto tmp = (avm_main_sel_op_keccak * (-avm_main_sel_op_keccak + FF(1))); + auto tmp = (main_sel_op_keccak * (-main_sel_op_keccak + FF(1))); tmp *= scaling_factor; std::get<34>(evals) += tmp; } @@ -595,7 +595,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(35); - auto tmp = (avm_main_sel_op_pedersen * (-avm_main_sel_op_pedersen + FF(1))); + auto tmp = (main_sel_op_pedersen * (-main_sel_op_pedersen + FF(1))); tmp *= scaling_factor; std::get<35>(evals) += tmp; } @@ -603,7 +603,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(36); - auto tmp = (avm_main_sel_op_add * (-avm_main_sel_op_add + FF(1))); + auto tmp = (main_sel_op_add * (-main_sel_op_add + FF(1))); tmp *= scaling_factor; std::get<36>(evals) += tmp; } @@ -611,7 +611,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(37); - auto tmp = (avm_main_sel_op_sub * (-avm_main_sel_op_sub + FF(1))); + auto tmp = (main_sel_op_sub * (-main_sel_op_sub + FF(1))); tmp *= scaling_factor; std::get<37>(evals) += tmp; } @@ -619,7 +619,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(38); - auto tmp = (avm_main_sel_op_mul * (-avm_main_sel_op_mul + FF(1))); + auto tmp = (main_sel_op_mul * (-main_sel_op_mul + FF(1))); tmp *= scaling_factor; std::get<38>(evals) += tmp; } @@ -627,7 +627,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(39); - auto tmp = (avm_main_sel_op_div * (-avm_main_sel_op_div + FF(1))); + auto tmp = (main_sel_op_div * (-main_sel_op_div + FF(1))); tmp *= scaling_factor; std::get<39>(evals) += tmp; } @@ -635,7 +635,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(40); - auto tmp = (avm_main_sel_op_fdiv * (-avm_main_sel_op_fdiv + FF(1))); + auto tmp = (main_sel_op_fdiv * (-main_sel_op_fdiv + FF(1))); tmp *= scaling_factor; std::get<40>(evals) += tmp; } @@ -643,7 +643,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(41); - auto tmp = (avm_main_sel_op_not * (-avm_main_sel_op_not + FF(1))); + auto tmp = (main_sel_op_not * (-main_sel_op_not + FF(1))); tmp *= scaling_factor; std::get<41>(evals) += tmp; } @@ -651,7 +651,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(42); - auto tmp = (avm_main_sel_op_eq * (-avm_main_sel_op_eq + FF(1))); + auto tmp = (main_sel_op_eq * (-main_sel_op_eq + FF(1))); tmp *= scaling_factor; std::get<42>(evals) += tmp; } @@ -659,7 +659,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(43); - auto tmp = (avm_main_sel_op_and * (-avm_main_sel_op_and + FF(1))); + auto tmp = (main_sel_op_and * (-main_sel_op_and + FF(1))); tmp *= scaling_factor; std::get<43>(evals) += tmp; } @@ -667,7 +667,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(44); - auto tmp = (avm_main_sel_op_or * (-avm_main_sel_op_or + FF(1))); + auto tmp = (main_sel_op_or * (-main_sel_op_or + FF(1))); tmp *= scaling_factor; std::get<44>(evals) += tmp; } @@ -675,7 +675,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(45); - auto tmp = (avm_main_sel_op_xor * (-avm_main_sel_op_xor + FF(1))); + auto tmp = (main_sel_op_xor * (-main_sel_op_xor + FF(1))); tmp *= scaling_factor; std::get<45>(evals) += tmp; } @@ -683,7 +683,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(46); - auto tmp = (avm_main_sel_op_cast * (-avm_main_sel_op_cast + FF(1))); + auto tmp = (main_sel_op_cast * (-main_sel_op_cast + FF(1))); tmp *= scaling_factor; std::get<46>(evals) += tmp; } @@ -691,7 +691,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(47); - auto tmp = (avm_main_sel_op_lt * (-avm_main_sel_op_lt + FF(1))); + auto tmp = (main_sel_op_lt * (-main_sel_op_lt + FF(1))); tmp *= scaling_factor; std::get<47>(evals) += tmp; } @@ -699,7 +699,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(48); - auto tmp = (avm_main_sel_op_lte * (-avm_main_sel_op_lte + FF(1))); + auto tmp = (main_sel_op_lte * (-main_sel_op_lte + FF(1))); tmp *= scaling_factor; std::get<48>(evals) += tmp; } @@ -707,7 +707,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(49); - auto tmp = (avm_main_sel_op_shl * (-avm_main_sel_op_shl + FF(1))); + auto tmp = (main_sel_op_shl * (-main_sel_op_shl + FF(1))); tmp *= scaling_factor; std::get<49>(evals) += tmp; } @@ -715,7 +715,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(50); - auto tmp = (avm_main_sel_op_shr * (-avm_main_sel_op_shr + FF(1))); + auto tmp = (main_sel_op_shr * (-main_sel_op_shr + FF(1))); tmp *= scaling_factor; std::get<50>(evals) += tmp; } @@ -723,7 +723,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(51); - auto tmp = (avm_main_sel_internal_call * (-avm_main_sel_internal_call + FF(1))); + auto tmp = (main_sel_op_internal_call * (-main_sel_op_internal_call + FF(1))); tmp *= scaling_factor; std::get<51>(evals) += tmp; } @@ -731,7 +731,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(52); - auto tmp = (avm_main_sel_internal_return * (-avm_main_sel_internal_return + FF(1))); + auto tmp = (main_sel_op_internal_return * (-main_sel_op_internal_return + FF(1))); tmp *= scaling_factor; std::get<52>(evals) += tmp; } @@ -739,7 +739,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(53); - auto tmp = (avm_main_sel_jump * (-avm_main_sel_jump + FF(1))); + auto tmp = (main_sel_op_jump * (-main_sel_op_jump + FF(1))); tmp *= scaling_factor; std::get<53>(evals) += tmp; } @@ -747,7 +747,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(54); - auto tmp = (avm_main_sel_jumpi * (-avm_main_sel_jumpi + FF(1))); + auto tmp = (main_sel_op_jumpi * (-main_sel_op_jumpi + FF(1))); tmp *= scaling_factor; std::get<54>(evals) += tmp; } @@ -755,7 +755,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(55); - auto tmp = (avm_main_sel_halt * (-avm_main_sel_halt + FF(1))); + auto tmp = (main_sel_op_halt * (-main_sel_op_halt + FF(1))); tmp *= scaling_factor; std::get<55>(evals) += tmp; } @@ -763,7 +763,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(56); - auto tmp = (avm_main_sel_external_call * (-avm_main_sel_external_call + FF(1))); + auto tmp = (main_sel_op_external_call * (-main_sel_op_external_call + FF(1))); tmp *= scaling_factor; std::get<56>(evals) += tmp; } @@ -771,7 +771,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(57); - auto tmp = (avm_main_sel_mov * (-avm_main_sel_mov + FF(1))); + auto tmp = (main_sel_op_mov * (-main_sel_op_mov + FF(1))); tmp *= scaling_factor; std::get<57>(evals) += tmp; } @@ -779,7 +779,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(58); - auto tmp = (avm_main_sel_cmov * (-avm_main_sel_cmov + FF(1))); + auto tmp = (main_sel_op_cmov * (-main_sel_op_cmov + FF(1))); tmp *= scaling_factor; std::get<58>(evals) += tmp; } @@ -787,7 +787,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(59); - auto tmp = (avm_main_op_err * (-avm_main_op_err + FF(1))); + auto tmp = (main_op_err * (-main_op_err + FF(1))); tmp *= scaling_factor; std::get<59>(evals) += tmp; } @@ -795,7 +795,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(60); - auto tmp = (avm_main_tag_err * (-avm_main_tag_err + FF(1))); + auto tmp = (main_tag_err * (-main_tag_err + FF(1))); tmp *= scaling_factor; std::get<60>(evals) += tmp; } @@ -803,7 +803,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(61); - auto tmp = (avm_main_id_zero * (-avm_main_id_zero + FF(1))); + auto tmp = (main_id_zero * (-main_id_zero + FF(1))); tmp *= scaling_factor; std::get<61>(evals) += tmp; } @@ -811,7 +811,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(62); - auto tmp = (avm_main_mem_op_a * (-avm_main_mem_op_a + FF(1))); + auto tmp = (main_sel_mem_op_a * (-main_sel_mem_op_a + FF(1))); tmp *= scaling_factor; std::get<62>(evals) += tmp; } @@ -819,7 +819,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(63); - auto tmp = (avm_main_mem_op_b * (-avm_main_mem_op_b + FF(1))); + auto tmp = (main_sel_mem_op_b * (-main_sel_mem_op_b + FF(1))); tmp *= scaling_factor; std::get<63>(evals) += tmp; } @@ -827,7 +827,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(64); - auto tmp = (avm_main_mem_op_c * (-avm_main_mem_op_c + FF(1))); + auto tmp = (main_sel_mem_op_c * (-main_sel_mem_op_c + FF(1))); tmp *= scaling_factor; std::get<64>(evals) += tmp; } @@ -835,7 +835,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(65); - auto tmp = (avm_main_mem_op_d * (-avm_main_mem_op_d + FF(1))); + auto tmp = (main_sel_mem_op_d * (-main_sel_mem_op_d + FF(1))); tmp *= scaling_factor; std::get<65>(evals) += tmp; } @@ -843,7 +843,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(66); - auto tmp = (avm_main_rwa * (-avm_main_rwa + FF(1))); + auto tmp = (main_rwa * (-main_rwa + FF(1))); tmp *= scaling_factor; std::get<66>(evals) += tmp; } @@ -851,7 +851,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(67); - auto tmp = (avm_main_rwb * (-avm_main_rwb + FF(1))); + auto tmp = (main_rwb * (-main_rwb + FF(1))); tmp *= scaling_factor; std::get<67>(evals) += tmp; } @@ -859,7 +859,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(68); - auto tmp = (avm_main_rwc * (-avm_main_rwc + FF(1))); + auto tmp = (main_rwc * (-main_rwc + FF(1))); tmp *= scaling_factor; std::get<68>(evals) += tmp; } @@ -867,7 +867,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(69); - auto tmp = (avm_main_rwd * (-avm_main_rwd + FF(1))); + auto tmp = (main_rwd * (-main_rwd + FF(1))); tmp *= scaling_factor; std::get<69>(evals) += tmp; } @@ -875,7 +875,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(70); - auto tmp = (avm_main_ind_op_a * (-avm_main_ind_op_a + FF(1))); + auto tmp = (main_sel_resolve_ind_addr_a * (-main_sel_resolve_ind_addr_a + FF(1))); tmp *= scaling_factor; std::get<70>(evals) += tmp; } @@ -883,7 +883,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(71); - auto tmp = (avm_main_ind_op_b * (-avm_main_ind_op_b + FF(1))); + auto tmp = (main_sel_resolve_ind_addr_b * (-main_sel_resolve_ind_addr_b + FF(1))); tmp *= scaling_factor; std::get<71>(evals) += tmp; } @@ -891,7 +891,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(72); - auto tmp = (avm_main_ind_op_c * (-avm_main_ind_op_c + FF(1))); + auto tmp = (main_sel_resolve_ind_addr_c * (-main_sel_resolve_ind_addr_c + FF(1))); tmp *= scaling_factor; std::get<72>(evals) += tmp; } @@ -899,7 +899,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(73); - auto tmp = (avm_main_ind_op_d * (-avm_main_ind_op_d + FF(1))); + auto tmp = (main_sel_resolve_ind_addr_d * (-main_sel_resolve_ind_addr_d + FF(1))); tmp *= scaling_factor; std::get<73>(evals) += tmp; } @@ -907,8 +907,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(74); - auto tmp = - (((avm_main_sel_op_eq + avm_main_sel_op_lte) + avm_main_sel_op_lt) * (avm_main_w_in_tag - FF(1))); + auto tmp = (((main_sel_op_eq + main_sel_op_lte) + main_sel_op_lt) * (main_w_in_tag - FF(1))); tmp *= scaling_factor; std::get<74>(evals) += tmp; } @@ -916,8 +915,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(75); - auto tmp = - ((avm_main_sel_op_fdiv * (-avm_main_op_err + FF(1))) * ((avm_main_ic * avm_main_ib) - avm_main_ia)); + auto tmp = ((main_sel_op_fdiv * (-main_op_err + FF(1))) * ((main_ic * main_ib) - main_ia)); tmp *= scaling_factor; std::get<75>(evals) += tmp; } @@ -925,8 +923,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(76); - auto tmp = ((avm_main_sel_op_fdiv + avm_main_sel_op_div) * - (((avm_main_ib * avm_main_inv) - FF(1)) + avm_main_op_err)); + auto tmp = ((main_sel_op_fdiv + main_sel_op_div) * (((main_ib * main_inv) - FF(1)) + main_op_err)); tmp *= scaling_factor; std::get<76>(evals) += tmp; } @@ -934,7 +931,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(77); - auto tmp = (((avm_main_sel_op_fdiv + avm_main_sel_op_div) * avm_main_op_err) * (-avm_main_inv + FF(1))); + auto tmp = (((main_sel_op_fdiv + main_sel_op_div) * main_op_err) * (-main_inv + FF(1))); tmp *= scaling_factor; std::get<77>(evals) += tmp; } @@ -942,7 +939,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(78); - auto tmp = (avm_main_sel_op_fdiv * (avm_main_r_in_tag - FF(6))); + auto tmp = (main_sel_op_fdiv * (main_r_in_tag - FF(6))); tmp *= scaling_factor; std::get<78>(evals) += tmp; } @@ -950,7 +947,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(79); - auto tmp = (avm_main_sel_op_fdiv * (avm_main_w_in_tag - FF(6))); + auto tmp = (main_sel_op_fdiv * (main_w_in_tag - FF(6))); tmp *= scaling_factor; std::get<79>(evals) += tmp; } @@ -958,7 +955,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(80); - auto tmp = (avm_main_op_err * ((avm_main_sel_op_fdiv + avm_main_sel_op_div) - FF(1))); + auto tmp = (main_op_err * ((main_sel_op_fdiv + main_sel_op_div) - FF(1))); tmp *= scaling_factor; std::get<80>(evals) += tmp; } @@ -966,16 +963,16 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(81); - auto tmp = (((((((((((avm_main_sel_op_sender + avm_main_sel_op_address) + avm_main_sel_op_storage_address) + - avm_main_sel_op_chain_id) + - avm_main_sel_op_version) + - avm_main_sel_op_block_number) + - avm_main_sel_op_coinbase) + - avm_main_sel_op_timestamp) + - avm_main_sel_op_fee_per_l2_gas) + - avm_main_sel_op_fee_per_da_gas) + - avm_main_sel_op_transaction_fee) * - (-avm_main_q_kernel_lookup + FF(1))); + auto tmp = (((((((((((main_sel_op_sender + main_sel_op_address) + main_sel_op_storage_address) + + main_sel_op_chain_id) + + main_sel_op_version) + + main_sel_op_block_number) + + main_sel_op_coinbase) + + main_sel_op_timestamp) + + main_sel_op_fee_per_l2_gas) + + main_sel_op_fee_per_da_gas) + + main_sel_op_transaction_fee) * + (-main_sel_q_kernel_lookup + FF(1))); tmp *= scaling_factor; std::get<81>(evals) += tmp; } @@ -983,13 +980,13 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(82); - auto tmp = (((((((avm_main_sel_op_note_hash_exists + avm_main_sel_op_emit_note_hash) + - avm_main_sel_op_nullifier_exists) + - avm_main_sel_op_emit_nullifier) + - avm_main_sel_op_l1_to_l2_msg_exists) + - avm_main_sel_op_emit_unencrypted_log) + - avm_main_sel_op_emit_l2_to_l1_msg) * - (-avm_main_q_kernel_output_lookup + FF(1))); + auto tmp = + (((((((main_sel_op_note_hash_exists + main_sel_op_emit_note_hash) + main_sel_op_nullifier_exists) + + main_sel_op_emit_nullifier) + + main_sel_op_l1_to_l2_msg_exists) + + main_sel_op_emit_unencrypted_log) + + main_sel_op_emit_l2_to_l1_msg) * + (-main_sel_q_kernel_output_lookup + FF(1))); tmp *= scaling_factor; std::get<82>(evals) += tmp; } @@ -997,7 +994,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(83); - auto tmp = (avm_main_sel_jump * (avm_main_pc_shift - avm_main_ia)); + auto tmp = (main_sel_op_jump * (main_pc_shift - main_ia)); tmp *= scaling_factor; std::get<83>(evals) += tmp; } @@ -1005,8 +1002,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(84); - auto tmp = (avm_main_sel_jumpi * (((-avm_main_id_zero + FF(1)) * (avm_main_pc_shift - avm_main_ia)) + - (avm_main_id_zero * ((avm_main_pc_shift - avm_main_pc) - FF(1))))); + auto tmp = (main_sel_op_jumpi * (((-main_id_zero + FF(1)) * (main_pc_shift - main_ia)) + + (main_id_zero * ((main_pc_shift - main_pc) - FF(1))))); tmp *= scaling_factor; std::get<84>(evals) += tmp; } @@ -1014,8 +1011,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(85); - auto tmp = (avm_main_sel_internal_call * - (avm_main_internal_return_ptr_shift - (avm_main_internal_return_ptr + FF(1)))); + auto tmp = + (main_sel_op_internal_call * (main_internal_return_ptr_shift - (main_internal_return_ptr + FF(1)))); tmp *= scaling_factor; std::get<85>(evals) += tmp; } @@ -1023,7 +1020,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(86); - auto tmp = (avm_main_sel_internal_call * (avm_main_internal_return_ptr - avm_main_mem_idx_b)); + auto tmp = (main_sel_op_internal_call * (main_internal_return_ptr - main_mem_addr_b)); tmp *= scaling_factor; std::get<86>(evals) += tmp; } @@ -1031,7 +1028,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(87); - auto tmp = (avm_main_sel_internal_call * (avm_main_pc_shift - avm_main_ia)); + auto tmp = (main_sel_op_internal_call * (main_pc_shift - main_ia)); tmp *= scaling_factor; std::get<87>(evals) += tmp; } @@ -1039,7 +1036,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(88); - auto tmp = (avm_main_sel_internal_call * ((avm_main_pc + FF(1)) - avm_main_ib)); + auto tmp = (main_sel_op_internal_call * ((main_pc + FF(1)) - main_ib)); tmp *= scaling_factor; std::get<88>(evals) += tmp; } @@ -1047,7 +1044,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(89); - auto tmp = (avm_main_sel_internal_call * (avm_main_rwb - FF(1))); + auto tmp = (main_sel_op_internal_call * (main_rwb - FF(1))); tmp *= scaling_factor; std::get<89>(evals) += tmp; } @@ -1055,7 +1052,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(90); - auto tmp = (avm_main_sel_internal_call * (avm_main_mem_op_b - FF(1))); + auto tmp = (main_sel_op_internal_call * (main_sel_mem_op_b - FF(1))); tmp *= scaling_factor; std::get<90>(evals) += tmp; } @@ -1063,8 +1060,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(91); - auto tmp = (avm_main_sel_internal_return * - (avm_main_internal_return_ptr_shift - (avm_main_internal_return_ptr - FF(1)))); + auto tmp = + (main_sel_op_internal_return * (main_internal_return_ptr_shift - (main_internal_return_ptr - FF(1)))); tmp *= scaling_factor; std::get<91>(evals) += tmp; } @@ -1072,7 +1069,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(92); - auto tmp = (avm_main_sel_internal_return * ((avm_main_internal_return_ptr - FF(1)) - avm_main_mem_idx_a)); + auto tmp = (main_sel_op_internal_return * ((main_internal_return_ptr - FF(1)) - main_mem_addr_a)); tmp *= scaling_factor; std::get<92>(evals) += tmp; } @@ -1080,7 +1077,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(93); - auto tmp = (avm_main_sel_internal_return * (avm_main_pc_shift - avm_main_ia)); + auto tmp = (main_sel_op_internal_return * (main_pc_shift - main_ia)); tmp *= scaling_factor; std::get<93>(evals) += tmp; } @@ -1088,7 +1085,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(94); - auto tmp = (avm_main_sel_internal_return * avm_main_rwa); + auto tmp = (main_sel_op_internal_return * main_rwa); tmp *= scaling_factor; std::get<94>(evals) += tmp; } @@ -1096,7 +1093,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(95); - auto tmp = (avm_main_sel_internal_return * (avm_main_mem_op_a - FF(1))); + auto tmp = (main_sel_op_internal_return * (main_sel_mem_op_a - FF(1))); tmp *= scaling_factor; std::get<95>(evals) += tmp; } @@ -1105,43 +1102,41 @@ template class avm_mainImpl { Avm_DECLARE_VIEWS(96); auto tmp = - (((((avm_main_gas_cost_active - - (((((((avm_main_sel_op_fdiv + - ((((((((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_mul) + - avm_main_sel_op_div) + - avm_main_sel_op_not) + - avm_main_sel_op_eq) + - avm_main_sel_op_lt) + - avm_main_sel_op_lte) + - avm_main_sel_op_shr) + - avm_main_sel_op_shl) + - avm_main_sel_op_cast)) + - ((avm_main_sel_op_and + avm_main_sel_op_or) + avm_main_sel_op_xor)) + - (avm_main_sel_cmov + avm_main_sel_mov)) + - ((((avm_main_sel_op_radix_le + avm_main_sel_op_sha256) + avm_main_sel_op_poseidon2) + - avm_main_sel_op_keccak) + - avm_main_sel_op_pedersen)) + - ((((((((((avm_main_sel_op_sender + avm_main_sel_op_address) + avm_main_sel_op_storage_address) + - avm_main_sel_op_chain_id) + - avm_main_sel_op_version) + - avm_main_sel_op_block_number) + - avm_main_sel_op_coinbase) + - avm_main_sel_op_timestamp) + - avm_main_sel_op_fee_per_l2_gas) + - avm_main_sel_op_fee_per_da_gas) + - avm_main_sel_op_transaction_fee)) + - ((((((avm_main_sel_op_note_hash_exists + avm_main_sel_op_emit_note_hash) + - avm_main_sel_op_nullifier_exists) + - avm_main_sel_op_emit_nullifier) + - avm_main_sel_op_l1_to_l2_msg_exists) + - avm_main_sel_op_emit_unencrypted_log) + - avm_main_sel_op_emit_l2_to_l1_msg)) + - (avm_main_sel_op_dagasleft + avm_main_sel_op_l2gasleft))) - - (((avm_main_sel_jump + avm_main_sel_jumpi) + avm_main_sel_internal_call) + - avm_main_sel_internal_return)) - - avm_main_sel_op_sload) - - avm_main_sel_op_sstore) - - avm_main_mem_op_activate_gas); + (((((main_sel_gas_accounting_active - + (((((((main_sel_op_fdiv + + ((((((((((main_sel_op_add + main_sel_op_sub) + main_sel_op_mul) + main_sel_op_div) + + main_sel_op_not) + + main_sel_op_eq) + + main_sel_op_lt) + + main_sel_op_lte) + + main_sel_op_shr) + + main_sel_op_shl) + + main_sel_op_cast)) + + ((main_sel_op_and + main_sel_op_or) + main_sel_op_xor)) + + (main_sel_op_cmov + main_sel_op_mov)) + + ((((main_sel_op_radix_le + main_sel_op_sha256) + main_sel_op_poseidon2) + main_sel_op_keccak) + + main_sel_op_pedersen)) + + ((((((((((main_sel_op_sender + main_sel_op_address) + main_sel_op_storage_address) + + main_sel_op_chain_id) + + main_sel_op_version) + + main_sel_op_block_number) + + main_sel_op_coinbase) + + main_sel_op_timestamp) + + main_sel_op_fee_per_l2_gas) + + main_sel_op_fee_per_da_gas) + + main_sel_op_transaction_fee)) + + ((((((main_sel_op_note_hash_exists + main_sel_op_emit_note_hash) + + main_sel_op_nullifier_exists) + + main_sel_op_emit_nullifier) + + main_sel_op_l1_to_l2_msg_exists) + + main_sel_op_emit_unencrypted_log) + + main_sel_op_emit_l2_to_l1_msg)) + + (main_sel_op_dagasleft + main_sel_op_l2gasleft))) - + (((main_sel_op_jump + main_sel_op_jumpi) + main_sel_op_internal_call) + + main_sel_op_internal_return)) - + main_sel_op_sload) - + main_sel_op_sstore) - + main_sel_mem_op_activate_gas); tmp *= scaling_factor; std::get<96>(evals) += tmp; } @@ -1150,39 +1145,36 @@ template class avm_mainImpl { Avm_DECLARE_VIEWS(97); auto tmp = - ((((-avm_main_first + FF(1)) * (-avm_main_sel_halt + FF(1))) * - (((((((avm_main_sel_op_fdiv + - ((((((((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_mul) + - avm_main_sel_op_div) + - avm_main_sel_op_not) + - avm_main_sel_op_eq) + - avm_main_sel_op_lt) + - avm_main_sel_op_lte) + - avm_main_sel_op_shr) + - avm_main_sel_op_shl) + - avm_main_sel_op_cast)) + - ((avm_main_sel_op_and + avm_main_sel_op_or) + avm_main_sel_op_xor)) + - (avm_main_sel_cmov + avm_main_sel_mov)) + - ((((avm_main_sel_op_radix_le + avm_main_sel_op_sha256) + avm_main_sel_op_poseidon2) + - avm_main_sel_op_keccak) + - avm_main_sel_op_pedersen)) + - ((((((((((avm_main_sel_op_sender + avm_main_sel_op_address) + avm_main_sel_op_storage_address) + - avm_main_sel_op_chain_id) + - avm_main_sel_op_version) + - avm_main_sel_op_block_number) + - avm_main_sel_op_coinbase) + - avm_main_sel_op_timestamp) + - avm_main_sel_op_fee_per_l2_gas) + - avm_main_sel_op_fee_per_da_gas) + - avm_main_sel_op_transaction_fee)) + - ((((((avm_main_sel_op_note_hash_exists + avm_main_sel_op_emit_note_hash) + - avm_main_sel_op_nullifier_exists) + - avm_main_sel_op_emit_nullifier) + - avm_main_sel_op_l1_to_l2_msg_exists) + - avm_main_sel_op_emit_unencrypted_log) + - avm_main_sel_op_emit_l2_to_l1_msg)) + - (avm_main_sel_op_dagasleft + avm_main_sel_op_l2gasleft))) * - (avm_main_pc_shift - (avm_main_pc + FF(1)))); + ((((-main_sel_first + FF(1)) * (-main_sel_op_halt + FF(1))) * + (((((((main_sel_op_fdiv + + ((((((((((main_sel_op_add + main_sel_op_sub) + main_sel_op_mul) + main_sel_op_div) + + main_sel_op_not) + + main_sel_op_eq) + + main_sel_op_lt) + + main_sel_op_lte) + + main_sel_op_shr) + + main_sel_op_shl) + + main_sel_op_cast)) + + ((main_sel_op_and + main_sel_op_or) + main_sel_op_xor)) + + (main_sel_op_cmov + main_sel_op_mov)) + + ((((main_sel_op_radix_le + main_sel_op_sha256) + main_sel_op_poseidon2) + main_sel_op_keccak) + + main_sel_op_pedersen)) + + ((((((((((main_sel_op_sender + main_sel_op_address) + main_sel_op_storage_address) + + main_sel_op_chain_id) + + main_sel_op_version) + + main_sel_op_block_number) + + main_sel_op_coinbase) + + main_sel_op_timestamp) + + main_sel_op_fee_per_l2_gas) + + main_sel_op_fee_per_da_gas) + + main_sel_op_transaction_fee)) + + ((((((main_sel_op_note_hash_exists + main_sel_op_emit_note_hash) + main_sel_op_nullifier_exists) + + main_sel_op_emit_nullifier) + + main_sel_op_l1_to_l2_msg_exists) + + main_sel_op_emit_unencrypted_log) + + main_sel_op_emit_l2_to_l1_msg)) + + (main_sel_op_dagasleft + main_sel_op_l2gasleft))) * + (main_pc_shift - (main_pc + FF(1)))); tmp *= scaling_factor; std::get<97>(evals) += tmp; } @@ -1190,10 +1182,10 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(98); - auto tmp = ((-(((avm_main_first + avm_main_sel_internal_call) + avm_main_sel_internal_return) + - avm_main_sel_halt) + - FF(1)) * - (avm_main_internal_return_ptr_shift - avm_main_internal_return_ptr)); + auto tmp = + ((-(((main_sel_first + main_sel_op_internal_call) + main_sel_op_internal_return) + main_sel_op_halt) + + FF(1)) * + (main_internal_return_ptr_shift - main_internal_return_ptr)); tmp *= scaling_factor; std::get<98>(evals) += tmp; } @@ -1201,7 +1193,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(99); - auto tmp = ((avm_main_sel_internal_call + avm_main_sel_internal_return) * (avm_main_space_id - FF(255))); + auto tmp = ((main_sel_op_internal_call + main_sel_op_internal_return) * (main_space_id - FF(255))); tmp *= scaling_factor; std::get<99>(evals) += tmp; } @@ -1210,38 +1202,35 @@ template class avm_mainImpl { Avm_DECLARE_VIEWS(100); auto tmp = - ((((((((avm_main_sel_op_fdiv + - ((((((((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_mul) + - avm_main_sel_op_div) + - avm_main_sel_op_not) + - avm_main_sel_op_eq) + - avm_main_sel_op_lt) + - avm_main_sel_op_lte) + - avm_main_sel_op_shr) + - avm_main_sel_op_shl) + - avm_main_sel_op_cast)) + - ((avm_main_sel_op_and + avm_main_sel_op_or) + avm_main_sel_op_xor)) + - (avm_main_sel_cmov + avm_main_sel_mov)) + - ((((avm_main_sel_op_radix_le + avm_main_sel_op_sha256) + avm_main_sel_op_poseidon2) + - avm_main_sel_op_keccak) + - avm_main_sel_op_pedersen)) + - ((((((((((avm_main_sel_op_sender + avm_main_sel_op_address) + avm_main_sel_op_storage_address) + - avm_main_sel_op_chain_id) + - avm_main_sel_op_version) + - avm_main_sel_op_block_number) + - avm_main_sel_op_coinbase) + - avm_main_sel_op_timestamp) + - avm_main_sel_op_fee_per_l2_gas) + - avm_main_sel_op_fee_per_da_gas) + - avm_main_sel_op_transaction_fee)) + - ((((((avm_main_sel_op_note_hash_exists + avm_main_sel_op_emit_note_hash) + - avm_main_sel_op_nullifier_exists) + - avm_main_sel_op_emit_nullifier) + - avm_main_sel_op_l1_to_l2_msg_exists) + - avm_main_sel_op_emit_unencrypted_log) + - avm_main_sel_op_emit_l2_to_l1_msg)) + - (avm_main_sel_op_dagasleft + avm_main_sel_op_l2gasleft)) * - (avm_main_call_ptr - avm_main_space_id)); + ((((((((main_sel_op_fdiv + + ((((((((((main_sel_op_add + main_sel_op_sub) + main_sel_op_mul) + main_sel_op_div) + + main_sel_op_not) + + main_sel_op_eq) + + main_sel_op_lt) + + main_sel_op_lte) + + main_sel_op_shr) + + main_sel_op_shl) + + main_sel_op_cast)) + + ((main_sel_op_and + main_sel_op_or) + main_sel_op_xor)) + + (main_sel_op_cmov + main_sel_op_mov)) + + ((((main_sel_op_radix_le + main_sel_op_sha256) + main_sel_op_poseidon2) + main_sel_op_keccak) + + main_sel_op_pedersen)) + + ((((((((((main_sel_op_sender + main_sel_op_address) + main_sel_op_storage_address) + + main_sel_op_chain_id) + + main_sel_op_version) + + main_sel_op_block_number) + + main_sel_op_coinbase) + + main_sel_op_timestamp) + + main_sel_op_fee_per_l2_gas) + + main_sel_op_fee_per_da_gas) + + main_sel_op_transaction_fee)) + + ((((((main_sel_op_note_hash_exists + main_sel_op_emit_note_hash) + main_sel_op_nullifier_exists) + + main_sel_op_emit_nullifier) + + main_sel_op_l1_to_l2_msg_exists) + + main_sel_op_emit_unencrypted_log) + + main_sel_op_emit_l2_to_l1_msg)) + + (main_sel_op_dagasleft + main_sel_op_l2gasleft)) * + (main_call_ptr - main_space_id)); tmp *= scaling_factor; std::get<100>(evals) += tmp; } @@ -1249,8 +1238,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(101); - auto tmp = ((avm_main_sel_cmov + avm_main_sel_jumpi) * - (((avm_main_id * avm_main_inv) - FF(1)) + avm_main_id_zero)); + auto tmp = ((main_sel_op_cmov + main_sel_op_jumpi) * (((main_id * main_inv) - FF(1)) + main_id_zero)); tmp *= scaling_factor; std::get<101>(evals) += tmp; } @@ -1258,7 +1246,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(102); - auto tmp = (((avm_main_sel_cmov + avm_main_sel_jumpi) * avm_main_id_zero) * (-avm_main_inv + FF(1))); + auto tmp = (((main_sel_op_cmov + main_sel_op_jumpi) * main_id_zero) * (-main_inv + FF(1))); tmp *= scaling_factor; std::get<102>(evals) += tmp; } @@ -1266,7 +1254,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(103); - auto tmp = (avm_main_sel_mov_a - (avm_main_sel_mov + (avm_main_sel_cmov * (-avm_main_id_zero + FF(1))))); + auto tmp = (main_sel_mov_ia_to_ic - (main_sel_op_mov + (main_sel_op_cmov * (-main_id_zero + FF(1))))); tmp *= scaling_factor; std::get<103>(evals) += tmp; } @@ -1274,7 +1262,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(104); - auto tmp = (avm_main_sel_mov_b - (avm_main_sel_cmov * avm_main_id_zero)); + auto tmp = (main_sel_mov_ib_to_ic - (main_sel_op_cmov * main_id_zero)); tmp *= scaling_factor; std::get<104>(evals) += tmp; } @@ -1282,7 +1270,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(105); - auto tmp = (avm_main_sel_mov_a * (avm_main_ia - avm_main_ic)); + auto tmp = (main_sel_mov_ia_to_ic * (main_ia - main_ic)); tmp *= scaling_factor; std::get<105>(evals) += tmp; } @@ -1290,7 +1278,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(106); - auto tmp = (avm_main_sel_mov_b * (avm_main_ib - avm_main_ic)); + auto tmp = (main_sel_mov_ib_to_ic * (main_ib - main_ic)); tmp *= scaling_factor; std::get<106>(evals) += tmp; } @@ -1298,7 +1286,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(107); - auto tmp = ((avm_main_sel_mov + avm_main_sel_cmov) * (avm_main_r_in_tag - avm_main_w_in_tag)); + auto tmp = ((main_sel_op_mov + main_sel_op_cmov) * (main_r_in_tag - main_w_in_tag)); tmp *= scaling_factor; std::get<107>(evals) += tmp; } @@ -1307,17 +1295,16 @@ template class avm_mainImpl { Avm_DECLARE_VIEWS(108); auto tmp = - (avm_main_alu_sel - - ((((((((((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_mul) + avm_main_sel_op_div) + - avm_main_sel_op_not) + - avm_main_sel_op_eq) + - avm_main_sel_op_lt) + - avm_main_sel_op_lte) + - avm_main_sel_op_shr) + - avm_main_sel_op_shl) + - avm_main_sel_op_cast) * - (-avm_main_tag_err + FF(1))) * - (-avm_main_op_err + FF(1)))); + (main_sel_alu - ((((((((((((main_sel_op_add + main_sel_op_sub) + main_sel_op_mul) + main_sel_op_div) + + main_sel_op_not) + + main_sel_op_eq) + + main_sel_op_lt) + + main_sel_op_lte) + + main_sel_op_shr) + + main_sel_op_shl) + + main_sel_op_cast) * + (-main_tag_err + FF(1))) * + (-main_op_err + FF(1)))); tmp *= scaling_factor; std::get<108>(evals) += tmp; } @@ -1326,14 +1313,13 @@ template class avm_mainImpl { Avm_DECLARE_VIEWS(109); auto tmp = - ((((((((((avm_main_sel_op_add + avm_main_sel_op_sub) + avm_main_sel_op_mul) + avm_main_sel_op_div) + - avm_main_sel_op_not) + - avm_main_sel_op_eq) + - avm_main_sel_op_lt) + - avm_main_sel_op_lte) + - avm_main_sel_op_shr) + - avm_main_sel_op_shl) * - (avm_main_alu_in_tag - avm_main_r_in_tag)); + ((((((((((main_sel_op_add + main_sel_op_sub) + main_sel_op_mul) + main_sel_op_div) + main_sel_op_not) + + main_sel_op_eq) + + main_sel_op_lt) + + main_sel_op_lte) + + main_sel_op_shr) + + main_sel_op_shl) * + (main_alu_in_tag - main_r_in_tag)); tmp *= scaling_factor; std::get<109>(evals) += tmp; } @@ -1341,7 +1327,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(110); - auto tmp = (avm_main_sel_op_cast * (avm_main_alu_in_tag - avm_main_w_in_tag)); + auto tmp = (main_sel_op_cast * (main_alu_in_tag - main_w_in_tag)); tmp *= scaling_factor; std::get<110>(evals) += tmp; } @@ -1349,7 +1335,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(111); - auto tmp = (avm_main_sel_op_l2gasleft * (avm_main_ia - avm_main_l2_gas_remaining_shift)); + auto tmp = (main_sel_op_l2gasleft * (main_ia - main_l2_gas_remaining_shift)); tmp *= scaling_factor; std::get<111>(evals) += tmp; } @@ -1357,7 +1343,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(112); - auto tmp = (avm_main_sel_op_dagasleft * (avm_main_ia - avm_main_da_gas_remaining_shift)); + auto tmp = (main_sel_op_dagasleft * (main_ia - main_da_gas_remaining_shift)); tmp *= scaling_factor; std::get<112>(evals) += tmp; } @@ -1365,7 +1351,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(113); - auto tmp = (avm_main_sel_op_sender * (avm_kernel_kernel_in_offset - FF(0))); + auto tmp = (main_sel_op_sender * (kernel_kernel_in_offset - FF(0))); tmp *= scaling_factor; std::get<113>(evals) += tmp; } @@ -1373,7 +1359,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(114); - auto tmp = (avm_main_sel_op_address * (avm_kernel_kernel_in_offset - FF(1))); + auto tmp = (main_sel_op_address * (kernel_kernel_in_offset - FF(1))); tmp *= scaling_factor; std::get<114>(evals) += tmp; } @@ -1381,7 +1367,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(115); - auto tmp = (avm_main_sel_op_storage_address * (avm_kernel_kernel_in_offset - FF(2))); + auto tmp = (main_sel_op_storage_address * (kernel_kernel_in_offset - FF(2))); tmp *= scaling_factor; std::get<115>(evals) += tmp; } @@ -1389,7 +1375,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(116); - auto tmp = (avm_main_sel_op_fee_per_da_gas * (avm_kernel_kernel_in_offset - FF(35))); + auto tmp = (main_sel_op_fee_per_da_gas * (kernel_kernel_in_offset - FF(35))); tmp *= scaling_factor; std::get<116>(evals) += tmp; } @@ -1397,7 +1383,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(117); - auto tmp = (avm_main_sel_op_fee_per_l2_gas * (avm_kernel_kernel_in_offset - FF(36))); + auto tmp = (main_sel_op_fee_per_l2_gas * (kernel_kernel_in_offset - FF(36))); tmp *= scaling_factor; std::get<117>(evals) += tmp; } @@ -1405,7 +1391,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(118); - auto tmp = (avm_main_sel_op_transaction_fee * (avm_kernel_kernel_in_offset - FF(40))); + auto tmp = (main_sel_op_transaction_fee * (kernel_kernel_in_offset - FF(40))); tmp *= scaling_factor; std::get<118>(evals) += tmp; } @@ -1413,7 +1399,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(119); - auto tmp = (avm_main_sel_op_chain_id * (avm_kernel_kernel_in_offset - FF(29))); + auto tmp = (main_sel_op_chain_id * (kernel_kernel_in_offset - FF(29))); tmp *= scaling_factor; std::get<119>(evals) += tmp; } @@ -1421,7 +1407,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(120); - auto tmp = (avm_main_sel_op_version * (avm_kernel_kernel_in_offset - FF(30))); + auto tmp = (main_sel_op_version * (kernel_kernel_in_offset - FF(30))); tmp *= scaling_factor; std::get<120>(evals) += tmp; } @@ -1429,7 +1415,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(121); - auto tmp = (avm_main_sel_op_block_number * (avm_kernel_kernel_in_offset - FF(31))); + auto tmp = (main_sel_op_block_number * (kernel_kernel_in_offset - FF(31))); tmp *= scaling_factor; std::get<121>(evals) += tmp; } @@ -1437,7 +1423,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(122); - auto tmp = (avm_main_sel_op_coinbase * (avm_kernel_kernel_in_offset - FF(33))); + auto tmp = (main_sel_op_coinbase * (kernel_kernel_in_offset - FF(33))); tmp *= scaling_factor; std::get<122>(evals) += tmp; } @@ -1445,7 +1431,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(123); - auto tmp = (avm_main_sel_op_timestamp * (avm_kernel_kernel_in_offset - FF(32))); + auto tmp = (main_sel_op_timestamp * (kernel_kernel_in_offset - FF(32))); tmp *= scaling_factor; std::get<123>(evals) += tmp; } @@ -1453,8 +1439,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(124); - auto tmp = (avm_main_sel_op_note_hash_exists * - (avm_kernel_kernel_out_offset - (avm_kernel_note_hash_exist_write_offset + FF(0)))); + auto tmp = (main_sel_op_note_hash_exists * + (kernel_kernel_out_offset - (kernel_note_hash_exist_write_offset + FF(0)))); tmp *= scaling_factor; std::get<124>(evals) += tmp; } @@ -1462,7 +1448,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(125); - auto tmp = (avm_main_first * avm_kernel_note_hash_exist_write_offset); + auto tmp = (main_sel_first * kernel_note_hash_exist_write_offset); tmp *= scaling_factor; std::get<125>(evals) += tmp; } @@ -1470,8 +1456,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(126); - auto tmp = (avm_main_sel_op_emit_note_hash * - (avm_kernel_kernel_out_offset - (avm_kernel_emit_note_hash_write_offset + FF(160)))); + auto tmp = (main_sel_op_emit_note_hash * + (kernel_kernel_out_offset - (kernel_emit_note_hash_write_offset + FF(176)))); tmp *= scaling_factor; std::get<126>(evals) += tmp; } @@ -1479,7 +1465,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(127); - auto tmp = (avm_main_first * avm_kernel_emit_note_hash_write_offset); + auto tmp = (main_sel_first * kernel_emit_note_hash_write_offset); tmp *= scaling_factor; std::get<127>(evals) += tmp; } @@ -1487,10 +1473,10 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(128); - auto tmp = (avm_main_sel_op_nullifier_exists * - (avm_kernel_kernel_out_offset - - ((avm_main_ib * (avm_kernel_nullifier_exists_write_offset + FF(32))) + - ((-avm_main_ib + FF(1)) * (avm_kernel_nullifier_non_exists_write_offset + FF(64)))))); + auto tmp = (main_sel_op_nullifier_exists * + (kernel_kernel_out_offset - + ((main_ib * (kernel_nullifier_exists_write_offset + FF(32))) + + ((-main_ib + FF(1)) * (kernel_nullifier_non_exists_write_offset + FF(64)))))); tmp *= scaling_factor; std::get<128>(evals) += tmp; } @@ -1498,7 +1484,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(129); - auto tmp = (avm_main_first * avm_kernel_nullifier_exists_write_offset); + auto tmp = (main_sel_first * kernel_nullifier_exists_write_offset); tmp *= scaling_factor; std::get<129>(evals) += tmp; } @@ -1506,7 +1492,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(130); - auto tmp = (avm_main_first * avm_kernel_nullifier_non_exists_write_offset); + auto tmp = (main_sel_first * kernel_nullifier_non_exists_write_offset); tmp *= scaling_factor; std::get<130>(evals) += tmp; } @@ -1514,8 +1500,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(131); - auto tmp = (avm_main_sel_op_emit_nullifier * - (avm_kernel_kernel_out_offset - (avm_kernel_emit_nullifier_write_offset + FF(176)))); + auto tmp = (main_sel_op_emit_nullifier * + (kernel_kernel_out_offset - (kernel_emit_nullifier_write_offset + FF(192)))); tmp *= scaling_factor; std::get<131>(evals) += tmp; } @@ -1523,7 +1509,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(132); - auto tmp = (avm_main_first * avm_kernel_emit_nullifier_write_offset); + auto tmp = (main_sel_first * kernel_emit_nullifier_write_offset); tmp *= scaling_factor; std::get<132>(evals) += tmp; } @@ -1531,8 +1517,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(133); - auto tmp = (avm_main_sel_op_l1_to_l2_msg_exists * - (avm_kernel_kernel_out_offset - (avm_kernel_l1_to_l2_msg_exists_write_offset + FF(96)))); + auto tmp = (main_sel_op_l1_to_l2_msg_exists * + (kernel_kernel_out_offset - (kernel_l1_to_l2_msg_exists_write_offset + FF(96)))); tmp *= scaling_factor; std::get<133>(evals) += tmp; } @@ -1540,7 +1526,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(134); - auto tmp = (avm_main_first * avm_kernel_l1_to_l2_msg_exists_write_offset); + auto tmp = (main_sel_first * kernel_l1_to_l2_msg_exists_write_offset); tmp *= scaling_factor; std::get<134>(evals) += tmp; } @@ -1548,8 +1534,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(135); - auto tmp = (avm_main_sel_op_emit_unencrypted_log * - (avm_kernel_kernel_out_offset - (avm_kernel_emit_unencrypted_log_write_offset + FF(194)))); + auto tmp = (main_sel_op_emit_unencrypted_log * + (kernel_kernel_out_offset - (kernel_emit_unencrypted_log_write_offset + FF(210)))); tmp *= scaling_factor; std::get<135>(evals) += tmp; } @@ -1557,7 +1543,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(136); - auto tmp = (avm_main_first * avm_kernel_emit_unencrypted_log_write_offset); + auto tmp = (main_sel_first * kernel_emit_unencrypted_log_write_offset); tmp *= scaling_factor; std::get<136>(evals) += tmp; } @@ -1565,8 +1551,8 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(137); - auto tmp = (avm_main_sel_op_emit_l2_to_l1_msg * - (avm_kernel_kernel_out_offset - (avm_kernel_emit_l2_to_l1_msg_write_offset + FF(192)))); + auto tmp = (main_sel_op_emit_l2_to_l1_msg * + (kernel_kernel_out_offset - (kernel_emit_l2_to_l1_msg_write_offset + FF(208)))); tmp *= scaling_factor; std::get<137>(evals) += tmp; } @@ -1574,7 +1560,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(138); - auto tmp = (avm_main_first * avm_kernel_emit_l2_to_l1_msg_write_offset); + auto tmp = (main_sel_first * kernel_emit_l2_to_l1_msg_write_offset); tmp *= scaling_factor; std::get<138>(evals) += tmp; } @@ -1582,8 +1568,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(139); - auto tmp = - (avm_main_sel_op_sload * (avm_kernel_kernel_out_offset - (avm_kernel_sload_write_offset + FF(144)))); + auto tmp = (main_sel_op_sload * (kernel_kernel_out_offset - (kernel_sload_write_offset + FF(144)))); tmp *= scaling_factor; std::get<139>(evals) += tmp; } @@ -1591,7 +1576,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(140); - auto tmp = (avm_main_first * avm_kernel_sload_write_offset); + auto tmp = (main_sel_first * kernel_sload_write_offset); tmp *= scaling_factor; std::get<140>(evals) += tmp; } @@ -1599,8 +1584,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(141); - auto tmp = - (avm_main_sel_op_sstore * (avm_kernel_kernel_out_offset - (avm_kernel_sstore_write_offset + FF(128)))); + auto tmp = (main_sel_op_sstore * (kernel_kernel_out_offset - (kernel_sstore_write_offset + FF(112)))); tmp *= scaling_factor; std::get<141>(evals) += tmp; } @@ -1608,7 +1592,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(142); - auto tmp = (avm_main_first * avm_kernel_sstore_write_offset); + auto tmp = (main_sel_first * kernel_sstore_write_offset); tmp *= scaling_factor; std::get<142>(evals) += tmp; } @@ -1616,13 +1600,13 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(143); - auto tmp = (((((((avm_main_sel_op_note_hash_exists + avm_main_sel_op_emit_note_hash) + - avm_main_sel_op_nullifier_exists) + - avm_main_sel_op_emit_nullifier) + - avm_main_sel_op_l1_to_l2_msg_exists) + - avm_main_sel_op_emit_unencrypted_log) + - avm_main_sel_op_emit_l2_to_l1_msg) * - (avm_kernel_side_effect_counter_shift - (avm_kernel_side_effect_counter + FF(1)))); + auto tmp = + (((((((main_sel_op_note_hash_exists + main_sel_op_emit_note_hash) + main_sel_op_nullifier_exists) + + main_sel_op_emit_nullifier) + + main_sel_op_l1_to_l2_msg_exists) + + main_sel_op_emit_unencrypted_log) + + main_sel_op_emit_l2_to_l1_msg) * + (kernel_side_effect_counter_shift - (kernel_side_effect_counter + FF(1)))); tmp *= scaling_factor; std::get<143>(evals) += tmp; } @@ -1630,7 +1614,7 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(144); - auto tmp = (avm_main_bin_op_id - (avm_main_sel_op_or + (avm_main_sel_op_xor * FF(2)))); + auto tmp = (main_bin_op_id - (main_sel_op_or + (main_sel_op_xor * FF(2)))); tmp *= scaling_factor; std::get<144>(evals) += tmp; } @@ -1638,13 +1622,13 @@ template class avm_mainImpl { { Avm_DECLARE_VIEWS(145); - auto tmp = (avm_main_bin_sel - ((avm_main_sel_op_and + avm_main_sel_op_or) + avm_main_sel_op_xor)); + auto tmp = (main_sel_bin - ((main_sel_op_and + main_sel_op_or) + main_sel_op_xor)); tmp *= scaling_factor; std::get<145>(evals) += tmp; } } }; -template using avm_main = Relation>; +template using main = Relation>; } // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/mem.hpp similarity index 59% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/mem.hpp index e6ef54aa6c4..8b1c6dcfe57 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_mem.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/mem.hpp @@ -6,50 +6,50 @@ namespace bb::Avm_vm { -template struct Avm_memRow { - FF avm_main_first{}; - FF avm_mem_addr{}; - FF avm_mem_clk{}; - FF avm_mem_diff_hi{}; - FF avm_mem_diff_lo{}; - FF avm_mem_diff_mid{}; - FF avm_mem_glob_addr{}; - FF avm_mem_glob_addr_shift{}; - FF avm_mem_ind_op_a{}; - FF avm_mem_ind_op_b{}; - FF avm_mem_ind_op_c{}; - FF avm_mem_ind_op_d{}; - FF avm_mem_last{}; - FF avm_mem_lastAccess{}; - FF avm_mem_mem_sel{}; - FF avm_mem_mem_sel_shift{}; - FF avm_mem_one_min_inv{}; - FF avm_mem_op_a{}; - FF avm_mem_op_b{}; - FF avm_mem_op_c{}; - FF avm_mem_op_d{}; - FF avm_mem_r_in_tag{}; - FF avm_mem_rng_chk_sel{}; - FF avm_mem_rw{}; - FF avm_mem_rw_shift{}; - FF avm_mem_sel_cmov{}; - FF avm_mem_sel_mov_a{}; - FF avm_mem_sel_mov_b{}; - FF avm_mem_skip_check_tag{}; - FF avm_mem_space_id{}; - FF avm_mem_tag{}; - FF avm_mem_tag_err{}; - FF avm_mem_tag_shift{}; - FF avm_mem_tsp{}; - FF avm_mem_tsp_shift{}; - FF avm_mem_val{}; - FF avm_mem_val_shift{}; - FF avm_mem_w_in_tag{}; +template struct MemRow { + FF main_sel_first{}; + FF mem_addr{}; + FF mem_clk{}; + FF mem_diff_hi{}; + FF mem_diff_lo{}; + FF mem_diff_mid{}; + FF mem_glob_addr{}; + FF mem_glob_addr_shift{}; + FF mem_last{}; + FF mem_lastAccess{}; + FF mem_one_min_inv{}; + FF mem_r_in_tag{}; + FF mem_rw{}; + FF mem_rw_shift{}; + FF mem_sel_mem{}; + FF mem_sel_mem_shift{}; + FF mem_sel_mov_ia_to_ic{}; + FF mem_sel_mov_ib_to_ic{}; + FF mem_sel_op_a{}; + FF mem_sel_op_b{}; + FF mem_sel_op_c{}; + FF mem_sel_op_cmov{}; + FF mem_sel_op_d{}; + FF mem_sel_resolve_ind_addr_a{}; + FF mem_sel_resolve_ind_addr_b{}; + FF mem_sel_resolve_ind_addr_c{}; + FF mem_sel_resolve_ind_addr_d{}; + FF mem_sel_rng_chk{}; + FF mem_skip_check_tag{}; + FF mem_space_id{}; + FF mem_tag{}; + FF mem_tag_err{}; + FF mem_tag_shift{}; + FF mem_tsp{}; + FF mem_tsp_shift{}; + FF mem_val{}; + FF mem_val_shift{}; + FF mem_w_in_tag{}; [[maybe_unused]] static std::vector names(); }; -inline std::string get_relation_label_avm_mem(int index) +inline std::string get_relation_label_mem(int index) { switch (index) { case 14: @@ -106,7 +106,7 @@ inline std::string get_relation_label_avm_mem(int index) return std::to_string(index); } -template class avm_memImpl { +template class memImpl { public: using FF = FF_; @@ -126,7 +126,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(0); - auto tmp = (avm_mem_lastAccess * (-avm_mem_lastAccess + FF(1))); + auto tmp = (mem_lastAccess * (-mem_lastAccess + FF(1))); tmp *= scaling_factor; std::get<0>(evals) += tmp; } @@ -134,7 +134,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(1); - auto tmp = (avm_mem_last * (-avm_mem_last + FF(1))); + auto tmp = (mem_last * (-mem_last + FF(1))); tmp *= scaling_factor; std::get<1>(evals) += tmp; } @@ -142,7 +142,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(2); - auto tmp = (avm_mem_rw * (-avm_mem_rw + FF(1))); + auto tmp = (mem_rw * (-mem_rw + FF(1))); tmp *= scaling_factor; std::get<2>(evals) += tmp; } @@ -150,7 +150,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(3); - auto tmp = (avm_mem_tag_err * (-avm_mem_tag_err + FF(1))); + auto tmp = (mem_tag_err * (-mem_tag_err + FF(1))); tmp *= scaling_factor; std::get<3>(evals) += tmp; } @@ -158,7 +158,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(4); - auto tmp = (avm_mem_op_a * (-avm_mem_op_a + FF(1))); + auto tmp = (mem_sel_op_a * (-mem_sel_op_a + FF(1))); tmp *= scaling_factor; std::get<4>(evals) += tmp; } @@ -166,7 +166,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(5); - auto tmp = (avm_mem_op_b * (-avm_mem_op_b + FF(1))); + auto tmp = (mem_sel_op_b * (-mem_sel_op_b + FF(1))); tmp *= scaling_factor; std::get<5>(evals) += tmp; } @@ -174,7 +174,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(6); - auto tmp = (avm_mem_op_c * (-avm_mem_op_c + FF(1))); + auto tmp = (mem_sel_op_c * (-mem_sel_op_c + FF(1))); tmp *= scaling_factor; std::get<6>(evals) += tmp; } @@ -182,7 +182,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(7); - auto tmp = (avm_mem_op_d * (-avm_mem_op_d + FF(1))); + auto tmp = (mem_sel_op_d * (-mem_sel_op_d + FF(1))); tmp *= scaling_factor; std::get<7>(evals) += tmp; } @@ -190,7 +190,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(8); - auto tmp = (avm_mem_ind_op_a * (-avm_mem_ind_op_a + FF(1))); + auto tmp = (mem_sel_resolve_ind_addr_a * (-mem_sel_resolve_ind_addr_a + FF(1))); tmp *= scaling_factor; std::get<8>(evals) += tmp; } @@ -198,7 +198,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(9); - auto tmp = (avm_mem_ind_op_b * (-avm_mem_ind_op_b + FF(1))); + auto tmp = (mem_sel_resolve_ind_addr_b * (-mem_sel_resolve_ind_addr_b + FF(1))); tmp *= scaling_factor; std::get<9>(evals) += tmp; } @@ -206,7 +206,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(10); - auto tmp = (avm_mem_ind_op_c * (-avm_mem_ind_op_c + FF(1))); + auto tmp = (mem_sel_resolve_ind_addr_c * (-mem_sel_resolve_ind_addr_c + FF(1))); tmp *= scaling_factor; std::get<10>(evals) += tmp; } @@ -214,7 +214,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(11); - auto tmp = (avm_mem_ind_op_d * (-avm_mem_ind_op_d + FF(1))); + auto tmp = (mem_sel_resolve_ind_addr_d * (-mem_sel_resolve_ind_addr_d + FF(1))); tmp *= scaling_factor; std::get<11>(evals) += tmp; } @@ -222,11 +222,12 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(12); - auto tmp = (avm_mem_mem_sel - - (((((((avm_mem_op_a + avm_mem_op_b) + avm_mem_op_c) + avm_mem_op_d) + avm_mem_ind_op_a) + - avm_mem_ind_op_b) + - avm_mem_ind_op_c) + - avm_mem_ind_op_d)); + auto tmp = + (mem_sel_mem - + (((((((mem_sel_op_a + mem_sel_op_b) + mem_sel_op_c) + mem_sel_op_d) + mem_sel_resolve_ind_addr_a) + + mem_sel_resolve_ind_addr_b) + + mem_sel_resolve_ind_addr_c) + + mem_sel_resolve_ind_addr_d)); tmp *= scaling_factor; std::get<12>(evals) += tmp; } @@ -234,7 +235,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(13); - auto tmp = (avm_mem_mem_sel * (avm_mem_mem_sel - FF(1))); + auto tmp = (mem_sel_mem * (mem_sel_mem - FF(1))); tmp *= scaling_factor; std::get<13>(evals) += tmp; } @@ -242,7 +243,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(14); - auto tmp = (((-avm_main_first + FF(1)) * avm_mem_mem_sel_shift) * (-avm_mem_mem_sel + FF(1))); + auto tmp = (((-main_sel_first + FF(1)) * mem_sel_mem_shift) * (-mem_sel_mem + FF(1))); tmp *= scaling_factor; std::get<14>(evals) += tmp; } @@ -250,7 +251,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(15); - auto tmp = (avm_main_first * avm_mem_mem_sel); + auto tmp = (main_sel_first * mem_sel_mem); tmp *= scaling_factor; std::get<15>(evals) += tmp; } @@ -258,7 +259,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(16); - auto tmp = (((-avm_mem_last + FF(1)) * avm_mem_mem_sel) * (-avm_mem_mem_sel_shift + FF(1))); + auto tmp = (((-mem_last + FF(1)) * mem_sel_mem) * (-mem_sel_mem_shift + FF(1))); tmp *= scaling_factor; std::get<16>(evals) += tmp; } @@ -266,7 +267,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(17); - auto tmp = (avm_mem_rng_chk_sel - (avm_mem_mem_sel * (-avm_mem_last + FF(1)))); + auto tmp = (mem_sel_rng_chk - (mem_sel_mem * (-mem_last + FF(1)))); tmp *= scaling_factor; std::get<17>(evals) += tmp; } @@ -275,13 +276,16 @@ template class avm_memImpl { Avm_DECLARE_VIEWS(18); auto tmp = - (avm_mem_tsp - - ((avm_mem_clk * FF(12)) + - (avm_mem_mem_sel * - ((((avm_mem_ind_op_b + avm_mem_op_b) + ((avm_mem_ind_op_c + avm_mem_op_c) * FF(2))) + - ((avm_mem_ind_op_d + avm_mem_op_d) * FF(3))) + - (((-(((avm_mem_ind_op_a + avm_mem_ind_op_b) + avm_mem_ind_op_c) + avm_mem_ind_op_d) + FF(1)) + - avm_mem_rw) * + (mem_tsp - + ((mem_clk * FF(12)) + + (mem_sel_mem * + ((((mem_sel_resolve_ind_addr_b + mem_sel_op_b) + + ((mem_sel_resolve_ind_addr_c + mem_sel_op_c) * FF(2))) + + ((mem_sel_resolve_ind_addr_d + mem_sel_op_d) * FF(3))) + + (((-(((mem_sel_resolve_ind_addr_a + mem_sel_resolve_ind_addr_b) + mem_sel_resolve_ind_addr_c) + + mem_sel_resolve_ind_addr_d) + + FF(1)) + + mem_rw) * FF(4)))))); tmp *= scaling_factor; std::get<18>(evals) += tmp; @@ -290,7 +294,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(19); - auto tmp = (avm_mem_glob_addr - ((avm_mem_space_id * FF(4294967296UL)) + avm_mem_addr)); + auto tmp = (mem_glob_addr - ((mem_space_id * FF(4294967296UL)) + mem_addr)); tmp *= scaling_factor; std::get<19>(evals) += tmp; } @@ -298,7 +302,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(20); - auto tmp = (avm_main_first * (-avm_mem_lastAccess + FF(1))); + auto tmp = (main_sel_first * (-mem_lastAccess + FF(1))); tmp *= scaling_factor; std::get<20>(evals) += tmp; } @@ -306,7 +310,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(21); - auto tmp = ((-avm_mem_lastAccess + FF(1)) * (avm_mem_glob_addr_shift - avm_mem_glob_addr)); + auto tmp = ((-mem_lastAccess + FF(1)) * (mem_glob_addr_shift - mem_glob_addr)); tmp *= scaling_factor; std::get<21>(evals) += tmp; } @@ -314,11 +318,11 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(22); - auto tmp = (avm_mem_rng_chk_sel * (((((avm_mem_lastAccess * (avm_mem_glob_addr_shift - avm_mem_glob_addr)) + - ((-avm_mem_lastAccess + FF(1)) * (avm_mem_tsp_shift - avm_mem_tsp))) - - (avm_mem_diff_hi * FF(4294967296UL))) - - (avm_mem_diff_mid * FF(65536))) - - avm_mem_diff_lo)); + auto tmp = (mem_sel_rng_chk * (((((mem_lastAccess * (mem_glob_addr_shift - mem_glob_addr)) + + ((-mem_lastAccess + FF(1)) * (mem_tsp_shift - mem_tsp))) - + (mem_diff_hi * FF(4294967296UL))) - + (mem_diff_mid * FF(65536))) - + mem_diff_lo)); tmp *= scaling_factor; std::get<22>(evals) += tmp; } @@ -326,8 +330,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(23); - auto tmp = - (((-avm_mem_lastAccess + FF(1)) * (-avm_mem_rw_shift + FF(1))) * (avm_mem_val_shift - avm_mem_val)); + auto tmp = (((-mem_lastAccess + FF(1)) * (-mem_rw_shift + FF(1))) * (mem_val_shift - mem_val)); tmp *= scaling_factor; std::get<23>(evals) += tmp; } @@ -335,8 +338,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(24); - auto tmp = - (((-avm_mem_lastAccess + FF(1)) * (-avm_mem_rw_shift + FF(1))) * (avm_mem_tag_shift - avm_mem_tag)); + auto tmp = (((-mem_lastAccess + FF(1)) * (-mem_rw_shift + FF(1))) * (mem_tag_shift - mem_tag)); tmp *= scaling_factor; std::get<24>(evals) += tmp; } @@ -344,7 +346,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(25); - auto tmp = ((avm_mem_lastAccess * (-avm_mem_rw_shift + FF(1))) * avm_mem_val_shift); + auto tmp = ((mem_lastAccess * (-mem_rw_shift + FF(1))) * mem_val_shift); tmp *= scaling_factor; std::get<25>(evals) += tmp; } @@ -352,9 +354,9 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(26); - auto tmp = (avm_mem_skip_check_tag - - (avm_mem_sel_cmov * ((avm_mem_op_d + (avm_mem_op_a * (-avm_mem_sel_mov_a + FF(1)))) + - (avm_mem_op_b * (-avm_mem_sel_mov_b + FF(1)))))); + auto tmp = (mem_skip_check_tag - + (mem_sel_op_cmov * ((mem_sel_op_d + (mem_sel_op_a * (-mem_sel_mov_ia_to_ic + FF(1)))) + + (mem_sel_op_b * (-mem_sel_mov_ib_to_ic + FF(1)))))); tmp *= scaling_factor; std::get<26>(evals) += tmp; } @@ -362,8 +364,8 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(27); - auto tmp = (((-avm_mem_skip_check_tag + FF(1)) * (-avm_mem_rw + FF(1))) * - (((avm_mem_r_in_tag - avm_mem_tag) * (-avm_mem_one_min_inv + FF(1))) - avm_mem_tag_err)); + auto tmp = (((-mem_skip_check_tag + FF(1)) * (-mem_rw + FF(1))) * + (((mem_r_in_tag - mem_tag) * (-mem_one_min_inv + FF(1))) - mem_tag_err)); tmp *= scaling_factor; std::get<27>(evals) += tmp; } @@ -371,7 +373,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(28); - auto tmp = ((-avm_mem_tag_err + FF(1)) * avm_mem_one_min_inv); + auto tmp = ((-mem_tag_err + FF(1)) * mem_one_min_inv); tmp *= scaling_factor; std::get<28>(evals) += tmp; } @@ -379,7 +381,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(29); - auto tmp = ((avm_mem_skip_check_tag + avm_mem_rw) * avm_mem_tag_err); + auto tmp = ((mem_skip_check_tag + mem_rw) * mem_tag_err); tmp *= scaling_factor; std::get<29>(evals) += tmp; } @@ -387,7 +389,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(30); - auto tmp = (avm_mem_rw * (avm_mem_w_in_tag - avm_mem_tag)); + auto tmp = (mem_rw * (mem_w_in_tag - mem_tag)); tmp *= scaling_factor; std::get<30>(evals) += tmp; } @@ -395,7 +397,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(31); - auto tmp = (avm_mem_rw * avm_mem_tag_err); + auto tmp = (mem_rw * mem_tag_err); tmp *= scaling_factor; std::get<31>(evals) += tmp; } @@ -403,7 +405,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(32); - auto tmp = (avm_mem_ind_op_a * (avm_mem_r_in_tag - FF(3))); + auto tmp = (mem_sel_resolve_ind_addr_a * (mem_r_in_tag - FF(3))); tmp *= scaling_factor; std::get<32>(evals) += tmp; } @@ -411,7 +413,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(33); - auto tmp = (avm_mem_ind_op_b * (avm_mem_r_in_tag - FF(3))); + auto tmp = (mem_sel_resolve_ind_addr_b * (mem_r_in_tag - FF(3))); tmp *= scaling_factor; std::get<33>(evals) += tmp; } @@ -419,7 +421,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(34); - auto tmp = (avm_mem_ind_op_c * (avm_mem_r_in_tag - FF(3))); + auto tmp = (mem_sel_resolve_ind_addr_c * (mem_r_in_tag - FF(3))); tmp *= scaling_factor; std::get<34>(evals) += tmp; } @@ -427,7 +429,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(35); - auto tmp = (avm_mem_ind_op_d * (avm_mem_r_in_tag - FF(3))); + auto tmp = (mem_sel_resolve_ind_addr_d * (mem_r_in_tag - FF(3))); tmp *= scaling_factor; std::get<35>(evals) += tmp; } @@ -435,7 +437,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(36); - auto tmp = (avm_mem_ind_op_a * avm_mem_rw); + auto tmp = (mem_sel_resolve_ind_addr_a * mem_rw); tmp *= scaling_factor; std::get<36>(evals) += tmp; } @@ -443,7 +445,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(37); - auto tmp = (avm_mem_ind_op_b * avm_mem_rw); + auto tmp = (mem_sel_resolve_ind_addr_b * mem_rw); tmp *= scaling_factor; std::get<37>(evals) += tmp; } @@ -451,7 +453,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(38); - auto tmp = (avm_mem_ind_op_c * avm_mem_rw); + auto tmp = (mem_sel_resolve_ind_addr_c * mem_rw); tmp *= scaling_factor; std::get<38>(evals) += tmp; } @@ -459,7 +461,7 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(39); - auto tmp = (avm_mem_ind_op_d * avm_mem_rw); + auto tmp = (mem_sel_resolve_ind_addr_d * mem_rw); tmp *= scaling_factor; std::get<39>(evals) += tmp; } @@ -467,13 +469,13 @@ template class avm_memImpl { { Avm_DECLARE_VIEWS(40); - auto tmp = ((avm_mem_sel_mov_a + avm_mem_sel_mov_b) * avm_mem_tag_err); + auto tmp = ((mem_sel_mov_ia_to_ic + mem_sel_mov_ib_to_ic) * mem_tag_err); tmp *= scaling_factor; std::get<40>(evals) += tmp; } } }; -template using avm_mem = Relation>; +template using mem = Relation>; } // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_poseidon2.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/pedersen.hpp similarity index 70% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_poseidon2.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/pedersen.hpp index 807e1d50341..d09722720e9 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_poseidon2.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/pedersen.hpp @@ -6,19 +6,19 @@ namespace bb::Avm_vm { -template struct Avm_poseidon2Row { - FF avm_poseidon2_poseidon_perm_sel{}; +template struct PedersenRow { + FF pedersen_sel_pedersen{}; [[maybe_unused]] static std::vector names(); }; -inline std::string get_relation_label_avm_poseidon2(int index) +inline std::string get_relation_label_pedersen(int index) { switch (index) {} return std::to_string(index); } -template class avm_poseidon2Impl { +template class pedersenImpl { public: using FF = FF_; @@ -37,13 +37,13 @@ template class avm_poseidon2Impl { { Avm_DECLARE_VIEWS(0); - auto tmp = (avm_poseidon2_poseidon_perm_sel * (-avm_poseidon2_poseidon_perm_sel + FF(1))); + auto tmp = (pedersen_sel_pedersen * (-pedersen_sel_pedersen + FF(1))); tmp *= scaling_factor; std::get<0>(evals) += tmp; } } }; -template using avm_poseidon2 = Relation>; +template using pedersen = Relation>; } // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_alu.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_alu.hpp index 83506a187ff..1b1a70a81c5 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_alu.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_alu.hpp @@ -23,7 +23,7 @@ class perm_main_alu_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_alu_sel == 1 || in.avm_alu_alu_sel == 1); + return (in.main_sel_alu == 1 || in.alu_sel_alu == 1); } /** @@ -47,41 +47,41 @@ class perm_main_alu_permutation_settings { { return std::forward_as_tuple(in.perm_main_alu, - in.avm_main_alu_sel, - in.avm_main_alu_sel, - in.avm_alu_alu_sel, - in.avm_main_clk, - in.avm_main_ia, - in.avm_main_ib, - in.avm_main_ic, - in.avm_main_sel_op_add, - in.avm_main_sel_op_sub, - in.avm_main_sel_op_mul, - in.avm_main_sel_op_div, - in.avm_main_sel_op_eq, - in.avm_main_sel_op_not, - in.avm_main_sel_op_cast, - in.avm_main_sel_op_lt, - in.avm_main_sel_op_lte, - in.avm_main_sel_op_shr, - in.avm_main_sel_op_shl, - in.avm_main_alu_in_tag, - in.avm_alu_clk, - in.avm_alu_ia, - in.avm_alu_ib, - in.avm_alu_ic, - in.avm_alu_op_add, - in.avm_alu_op_sub, - in.avm_alu_op_mul, - in.avm_alu_op_div, - in.avm_alu_op_eq, - in.avm_alu_op_not, - in.avm_alu_op_cast, - in.avm_alu_op_lt, - in.avm_alu_op_lte, - in.avm_alu_op_shr, - in.avm_alu_op_shl, - in.avm_alu_in_tag); + in.main_sel_alu, + in.main_sel_alu, + in.alu_sel_alu, + in.main_clk, + in.main_ia, + in.main_ib, + in.main_ic, + in.main_sel_op_add, + in.main_sel_op_sub, + in.main_sel_op_mul, + in.main_sel_op_div, + in.main_sel_op_eq, + in.main_sel_op_not, + in.main_sel_op_cast, + in.main_sel_op_lt, + in.main_sel_op_lte, + in.main_sel_op_shr, + in.main_sel_op_shl, + in.main_alu_in_tag, + in.alu_clk, + in.alu_ia, + in.alu_ib, + in.alu_ic, + in.alu_op_add, + in.alu_op_sub, + in.alu_op_mul, + in.alu_op_div, + in.alu_op_eq, + in.alu_op_not, + in.alu_op_cast, + in.alu_op_lt, + in.alu_op_lte, + in.alu_op_shr, + in.alu_op_shl, + in.alu_in_tag); } /** @@ -105,41 +105,41 @@ class perm_main_alu_permutation_settings { { return std::forward_as_tuple(in.perm_main_alu, - in.avm_main_alu_sel, - in.avm_main_alu_sel, - in.avm_alu_alu_sel, - in.avm_main_clk, - in.avm_main_ia, - in.avm_main_ib, - in.avm_main_ic, - in.avm_main_sel_op_add, - in.avm_main_sel_op_sub, - in.avm_main_sel_op_mul, - in.avm_main_sel_op_div, - in.avm_main_sel_op_eq, - in.avm_main_sel_op_not, - in.avm_main_sel_op_cast, - in.avm_main_sel_op_lt, - in.avm_main_sel_op_lte, - in.avm_main_sel_op_shr, - in.avm_main_sel_op_shl, - in.avm_main_alu_in_tag, - in.avm_alu_clk, - in.avm_alu_ia, - in.avm_alu_ib, - in.avm_alu_ic, - in.avm_alu_op_add, - in.avm_alu_op_sub, - in.avm_alu_op_mul, - in.avm_alu_op_div, - in.avm_alu_op_eq, - in.avm_alu_op_not, - in.avm_alu_op_cast, - in.avm_alu_op_lt, - in.avm_alu_op_lte, - in.avm_alu_op_shr, - in.avm_alu_op_shl, - in.avm_alu_in_tag); + in.main_sel_alu, + in.main_sel_alu, + in.alu_sel_alu, + in.main_clk, + in.main_ia, + in.main_ib, + in.main_ic, + in.main_sel_op_add, + in.main_sel_op_sub, + in.main_sel_op_mul, + in.main_sel_op_div, + in.main_sel_op_eq, + in.main_sel_op_not, + in.main_sel_op_cast, + in.main_sel_op_lt, + in.main_sel_op_lte, + in.main_sel_op_shr, + in.main_sel_op_shl, + in.main_alu_in_tag, + in.alu_clk, + in.alu_ia, + in.alu_ib, + in.alu_ic, + in.alu_op_add, + in.alu_op_sub, + in.alu_op_mul, + in.alu_op_div, + in.alu_op_eq, + in.alu_op_not, + in.alu_op_cast, + in.alu_op_lt, + in.alu_op_lte, + in.alu_op_shr, + in.alu_op_shl, + in.alu_in_tag); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_bin.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_bin.hpp index 0e3533051d1..ebcd77a04ab 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_bin.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_bin.hpp @@ -23,7 +23,7 @@ class perm_main_bin_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_bin_sel == 1 || in.avm_binary_start == 1); + return (in.main_sel_bin == 1 || in.binary_start == 1); } /** @@ -47,21 +47,21 @@ class perm_main_bin_permutation_settings { { return std::forward_as_tuple(in.perm_main_bin, - in.avm_main_bin_sel, - in.avm_main_bin_sel, - in.avm_binary_start, - in.avm_main_clk, - in.avm_main_ia, - in.avm_main_ib, - in.avm_main_ic, - in.avm_main_bin_op_id, - in.avm_main_r_in_tag, - in.avm_binary_clk, - in.avm_binary_acc_ia, - in.avm_binary_acc_ib, - in.avm_binary_acc_ic, - in.avm_binary_op_id, - in.avm_binary_in_tag); + in.main_sel_bin, + in.main_sel_bin, + in.binary_start, + in.main_clk, + in.main_ia, + in.main_ib, + in.main_ic, + in.main_bin_op_id, + in.main_r_in_tag, + in.binary_clk, + in.binary_acc_ia, + in.binary_acc_ib, + in.binary_acc_ic, + in.binary_op_id, + in.binary_in_tag); } /** @@ -85,21 +85,21 @@ class perm_main_bin_permutation_settings { { return std::forward_as_tuple(in.perm_main_bin, - in.avm_main_bin_sel, - in.avm_main_bin_sel, - in.avm_binary_start, - in.avm_main_clk, - in.avm_main_ia, - in.avm_main_ib, - in.avm_main_ic, - in.avm_main_bin_op_id, - in.avm_main_r_in_tag, - in.avm_binary_clk, - in.avm_binary_acc_ia, - in.avm_binary_acc_ib, - in.avm_binary_acc_ic, - in.avm_binary_op_id, - in.avm_binary_in_tag); + in.main_sel_bin, + in.main_sel_bin, + in.binary_start, + in.main_clk, + in.main_ia, + in.main_ib, + in.main_ic, + in.main_bin_op_id, + in.main_r_in_tag, + in.binary_clk, + in.binary_acc_ia, + in.binary_acc_ib, + in.binary_acc_ic, + in.binary_op_id, + in.binary_in_tag); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_conv.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_conv.hpp index 2d7ac39f44e..3890911bd5b 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_conv.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_conv.hpp @@ -23,7 +23,7 @@ class perm_main_conv_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_sel_op_radix_le == 1 || in.avm_conversion_to_radix_le_sel == 1); + return (in.main_sel_op_radix_le == 1 || in.conversion_sel_to_radix_le == 1); } /** @@ -47,17 +47,17 @@ class perm_main_conv_permutation_settings { { return std::forward_as_tuple(in.perm_main_conv, - in.avm_main_sel_op_radix_le, - in.avm_main_sel_op_radix_le, - in.avm_conversion_to_radix_le_sel, - in.avm_main_clk, - in.avm_main_ia, - in.avm_main_ic, - in.avm_main_id, - in.avm_conversion_clk, - in.avm_conversion_input, - in.avm_conversion_radix, - in.avm_conversion_num_limbs); + in.main_sel_op_radix_le, + in.main_sel_op_radix_le, + in.conversion_sel_to_radix_le, + in.main_clk, + in.main_ia, + in.main_ic, + in.main_id, + in.conversion_clk, + in.conversion_input, + in.conversion_radix, + in.conversion_num_limbs); } /** @@ -81,17 +81,17 @@ class perm_main_conv_permutation_settings { { return std::forward_as_tuple(in.perm_main_conv, - in.avm_main_sel_op_radix_le, - in.avm_main_sel_op_radix_le, - in.avm_conversion_to_radix_le_sel, - in.avm_main_clk, - in.avm_main_ia, - in.avm_main_ic, - in.avm_main_id, - in.avm_conversion_clk, - in.avm_conversion_input, - in.avm_conversion_radix, - in.avm_conversion_num_limbs); + in.main_sel_op_radix_le, + in.main_sel_op_radix_le, + in.conversion_sel_to_radix_le, + in.main_clk, + in.main_ia, + in.main_ic, + in.main_id, + in.conversion_clk, + in.conversion_input, + in.conversion_radix, + in.conversion_num_limbs); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_a.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_a.hpp index d7647bcc463..867dd008f0a 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_a.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_a.hpp @@ -23,7 +23,7 @@ class perm_main_mem_a_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_mem_op_a == 1 || in.avm_mem_op_a == 1); + return (in.main_sel_mem_op_a == 1 || in.mem_sel_op_a == 1); } /** @@ -47,27 +47,27 @@ class perm_main_mem_a_permutation_settings { { return std::forward_as_tuple(in.perm_main_mem_a, - in.avm_main_mem_op_a, - in.avm_main_mem_op_a, - in.avm_mem_op_a, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_mem_idx_a, - in.avm_main_ia, - in.avm_main_rwa, - in.avm_main_r_in_tag, - in.avm_main_w_in_tag, - in.avm_main_sel_mov_a, - in.avm_main_sel_cmov, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val, - in.avm_mem_rw, - in.avm_mem_r_in_tag, - in.avm_mem_w_in_tag, - in.avm_mem_sel_mov_a, - in.avm_mem_sel_cmov); + in.main_sel_mem_op_a, + in.main_sel_mem_op_a, + in.mem_sel_op_a, + in.main_clk, + in.main_space_id, + in.main_mem_addr_a, + in.main_ia, + in.main_rwa, + in.main_r_in_tag, + in.main_w_in_tag, + in.main_sel_mov_ia_to_ic, + in.main_sel_op_cmov, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val, + in.mem_rw, + in.mem_r_in_tag, + in.mem_w_in_tag, + in.mem_sel_mov_ia_to_ic, + in.mem_sel_op_cmov); } /** @@ -91,27 +91,27 @@ class perm_main_mem_a_permutation_settings { { return std::forward_as_tuple(in.perm_main_mem_a, - in.avm_main_mem_op_a, - in.avm_main_mem_op_a, - in.avm_mem_op_a, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_mem_idx_a, - in.avm_main_ia, - in.avm_main_rwa, - in.avm_main_r_in_tag, - in.avm_main_w_in_tag, - in.avm_main_sel_mov_a, - in.avm_main_sel_cmov, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val, - in.avm_mem_rw, - in.avm_mem_r_in_tag, - in.avm_mem_w_in_tag, - in.avm_mem_sel_mov_a, - in.avm_mem_sel_cmov); + in.main_sel_mem_op_a, + in.main_sel_mem_op_a, + in.mem_sel_op_a, + in.main_clk, + in.main_space_id, + in.main_mem_addr_a, + in.main_ia, + in.main_rwa, + in.main_r_in_tag, + in.main_w_in_tag, + in.main_sel_mov_ia_to_ic, + in.main_sel_op_cmov, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val, + in.mem_rw, + in.mem_r_in_tag, + in.mem_w_in_tag, + in.mem_sel_mov_ia_to_ic, + in.mem_sel_op_cmov); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_b.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_b.hpp index 7d873de8722..c724cbebb28 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_b.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_b.hpp @@ -23,7 +23,7 @@ class perm_main_mem_b_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_mem_op_b == 1 || in.avm_mem_op_b == 1); + return (in.main_sel_mem_op_b == 1 || in.mem_sel_op_b == 1); } /** @@ -47,27 +47,27 @@ class perm_main_mem_b_permutation_settings { { return std::forward_as_tuple(in.perm_main_mem_b, - in.avm_main_mem_op_b, - in.avm_main_mem_op_b, - in.avm_mem_op_b, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_mem_idx_b, - in.avm_main_ib, - in.avm_main_rwb, - in.avm_main_r_in_tag, - in.avm_main_w_in_tag, - in.avm_main_sel_mov_b, - in.avm_main_sel_cmov, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val, - in.avm_mem_rw, - in.avm_mem_r_in_tag, - in.avm_mem_w_in_tag, - in.avm_mem_sel_mov_b, - in.avm_mem_sel_cmov); + in.main_sel_mem_op_b, + in.main_sel_mem_op_b, + in.mem_sel_op_b, + in.main_clk, + in.main_space_id, + in.main_mem_addr_b, + in.main_ib, + in.main_rwb, + in.main_r_in_tag, + in.main_w_in_tag, + in.main_sel_mov_ib_to_ic, + in.main_sel_op_cmov, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val, + in.mem_rw, + in.mem_r_in_tag, + in.mem_w_in_tag, + in.mem_sel_mov_ib_to_ic, + in.mem_sel_op_cmov); } /** @@ -91,27 +91,27 @@ class perm_main_mem_b_permutation_settings { { return std::forward_as_tuple(in.perm_main_mem_b, - in.avm_main_mem_op_b, - in.avm_main_mem_op_b, - in.avm_mem_op_b, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_mem_idx_b, - in.avm_main_ib, - in.avm_main_rwb, - in.avm_main_r_in_tag, - in.avm_main_w_in_tag, - in.avm_main_sel_mov_b, - in.avm_main_sel_cmov, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val, - in.avm_mem_rw, - in.avm_mem_r_in_tag, - in.avm_mem_w_in_tag, - in.avm_mem_sel_mov_b, - in.avm_mem_sel_cmov); + in.main_sel_mem_op_b, + in.main_sel_mem_op_b, + in.mem_sel_op_b, + in.main_clk, + in.main_space_id, + in.main_mem_addr_b, + in.main_ib, + in.main_rwb, + in.main_r_in_tag, + in.main_w_in_tag, + in.main_sel_mov_ib_to_ic, + in.main_sel_op_cmov, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val, + in.mem_rw, + in.mem_r_in_tag, + in.mem_w_in_tag, + in.mem_sel_mov_ib_to_ic, + in.mem_sel_op_cmov); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_c.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_c.hpp index 64919b1ca3d..532d2fbdd9e 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_c.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_c.hpp @@ -23,7 +23,7 @@ class perm_main_mem_c_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_mem_op_c == 1 || in.avm_mem_op_c == 1); + return (in.main_sel_mem_op_c == 1 || in.mem_sel_op_c == 1); } /** @@ -47,23 +47,23 @@ class perm_main_mem_c_permutation_settings { { return std::forward_as_tuple(in.perm_main_mem_c, - in.avm_main_mem_op_c, - in.avm_main_mem_op_c, - in.avm_mem_op_c, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_mem_idx_c, - in.avm_main_ic, - in.avm_main_rwc, - in.avm_main_r_in_tag, - in.avm_main_w_in_tag, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val, - in.avm_mem_rw, - in.avm_mem_r_in_tag, - in.avm_mem_w_in_tag); + in.main_sel_mem_op_c, + in.main_sel_mem_op_c, + in.mem_sel_op_c, + in.main_clk, + in.main_space_id, + in.main_mem_addr_c, + in.main_ic, + in.main_rwc, + in.main_r_in_tag, + in.main_w_in_tag, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val, + in.mem_rw, + in.mem_r_in_tag, + in.mem_w_in_tag); } /** @@ -87,23 +87,23 @@ class perm_main_mem_c_permutation_settings { { return std::forward_as_tuple(in.perm_main_mem_c, - in.avm_main_mem_op_c, - in.avm_main_mem_op_c, - in.avm_mem_op_c, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_mem_idx_c, - in.avm_main_ic, - in.avm_main_rwc, - in.avm_main_r_in_tag, - in.avm_main_w_in_tag, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val, - in.avm_mem_rw, - in.avm_mem_r_in_tag, - in.avm_mem_w_in_tag); + in.main_sel_mem_op_c, + in.main_sel_mem_op_c, + in.mem_sel_op_c, + in.main_clk, + in.main_space_id, + in.main_mem_addr_c, + in.main_ic, + in.main_rwc, + in.main_r_in_tag, + in.main_w_in_tag, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val, + in.mem_rw, + in.mem_r_in_tag, + in.mem_w_in_tag); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_d.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_d.hpp index b6f64c60a27..3112f97cd87 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_d.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_d.hpp @@ -23,7 +23,7 @@ class perm_main_mem_d_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_mem_op_d == 1 || in.avm_mem_op_d == 1); + return (in.main_sel_mem_op_d == 1 || in.mem_sel_op_d == 1); } /** @@ -47,25 +47,25 @@ class perm_main_mem_d_permutation_settings { { return std::forward_as_tuple(in.perm_main_mem_d, - in.avm_main_mem_op_d, - in.avm_main_mem_op_d, - in.avm_mem_op_d, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_mem_idx_d, - in.avm_main_id, - in.avm_main_rwd, - in.avm_main_r_in_tag, - in.avm_main_w_in_tag, - in.avm_main_sel_cmov, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val, - in.avm_mem_rw, - in.avm_mem_r_in_tag, - in.avm_mem_w_in_tag, - in.avm_mem_sel_cmov); + in.main_sel_mem_op_d, + in.main_sel_mem_op_d, + in.mem_sel_op_d, + in.main_clk, + in.main_space_id, + in.main_mem_addr_d, + in.main_id, + in.main_rwd, + in.main_r_in_tag, + in.main_w_in_tag, + in.main_sel_op_cmov, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val, + in.mem_rw, + in.mem_r_in_tag, + in.mem_w_in_tag, + in.mem_sel_op_cmov); } /** @@ -89,25 +89,25 @@ class perm_main_mem_d_permutation_settings { { return std::forward_as_tuple(in.perm_main_mem_d, - in.avm_main_mem_op_d, - in.avm_main_mem_op_d, - in.avm_mem_op_d, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_mem_idx_d, - in.avm_main_id, - in.avm_main_rwd, - in.avm_main_r_in_tag, - in.avm_main_w_in_tag, - in.avm_main_sel_cmov, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val, - in.avm_mem_rw, - in.avm_mem_r_in_tag, - in.avm_mem_w_in_tag, - in.avm_mem_sel_cmov); + in.main_sel_mem_op_d, + in.main_sel_mem_op_d, + in.mem_sel_op_d, + in.main_clk, + in.main_space_id, + in.main_mem_addr_d, + in.main_id, + in.main_rwd, + in.main_r_in_tag, + in.main_w_in_tag, + in.main_sel_op_cmov, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val, + in.mem_rw, + in.mem_r_in_tag, + in.mem_w_in_tag, + in.mem_sel_op_cmov); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_cmp.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_addr_a.hpp similarity index 62% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_cmp.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_addr_a.hpp index 362f4321566..3d0de9cf392 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_cmp.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_addr_a.hpp @@ -9,7 +9,7 @@ namespace bb { -class perm_main_cmp_permutation_settings { +class perm_main_mem_ind_addr_a_permutation_settings { public: // This constant defines how many columns are bundled together to form each set. constexpr static size_t COLUMNS_PER_SET = 4; @@ -23,7 +23,7 @@ class perm_main_cmp_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_cmp_sel == 1 || in.avm_alu_cmp_sel == 1); + return (in.main_sel_resolve_ind_addr_a == 1 || in.mem_sel_resolve_ind_addr_a == 1); } /** @@ -46,18 +46,18 @@ class perm_main_cmp_permutation_settings { template static inline auto get_const_entities(const AllEntities& in) { - return std::forward_as_tuple(in.perm_main_cmp, - in.avm_main_cmp_sel, - in.avm_main_cmp_sel, - in.avm_alu_cmp_sel, - in.avm_main_clk, - in.avm_main_ia, - in.avm_main_ib, - in.avm_main_ic, - in.avm_alu_clk, - in.avm_alu_ia, - in.avm_alu_ib, - in.avm_alu_ic); + return std::forward_as_tuple(in.perm_main_mem_ind_addr_a, + in.main_sel_resolve_ind_addr_a, + in.main_sel_resolve_ind_addr_a, + in.mem_sel_resolve_ind_addr_a, + in.main_clk, + in.main_space_id, + in.main_ind_addr_a, + in.main_mem_addr_a, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val); } /** @@ -80,23 +80,25 @@ class perm_main_cmp_permutation_settings { template static inline auto get_nonconst_entities(AllEntities& in) { - return std::forward_as_tuple(in.perm_main_cmp, - in.avm_main_cmp_sel, - in.avm_main_cmp_sel, - in.avm_alu_cmp_sel, - in.avm_main_clk, - in.avm_main_ia, - in.avm_main_ib, - in.avm_main_ic, - in.avm_alu_clk, - in.avm_alu_ia, - in.avm_alu_ib, - in.avm_alu_ic); + return std::forward_as_tuple(in.perm_main_mem_ind_addr_a, + in.main_sel_resolve_ind_addr_a, + in.main_sel_resolve_ind_addr_a, + in.mem_sel_resolve_ind_addr_a, + in.main_clk, + in.main_space_id, + in.main_ind_addr_a, + in.main_mem_addr_a, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val); } }; template -using perm_main_cmp_relation = GenericPermutationRelation; -template using perm_main_cmp = GenericPermutation; +using perm_main_mem_ind_addr_a_relation = + GenericPermutationRelation; +template +using perm_main_mem_ind_addr_a = GenericPermutation; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_c.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_addr_b.hpp similarity index 62% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_c.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_addr_b.hpp index 98676a0d8b3..eec199f39f7 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_c.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_addr_b.hpp @@ -9,7 +9,7 @@ namespace bb { -class perm_main_mem_ind_c_permutation_settings { +class perm_main_mem_ind_addr_b_permutation_settings { public: // This constant defines how many columns are bundled together to form each set. constexpr static size_t COLUMNS_PER_SET = 4; @@ -23,7 +23,7 @@ class perm_main_mem_ind_c_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_ind_op_c == 1 || in.avm_mem_ind_op_c == 1); + return (in.main_sel_resolve_ind_addr_b == 1 || in.mem_sel_resolve_ind_addr_b == 1); } /** @@ -46,18 +46,18 @@ class perm_main_mem_ind_c_permutation_settings { template static inline auto get_const_entities(const AllEntities& in) { - return std::forward_as_tuple(in.perm_main_mem_ind_c, - in.avm_main_ind_op_c, - in.avm_main_ind_op_c, - in.avm_mem_ind_op_c, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_ind_c, - in.avm_main_mem_idx_c, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val); + return std::forward_as_tuple(in.perm_main_mem_ind_addr_b, + in.main_sel_resolve_ind_addr_b, + in.main_sel_resolve_ind_addr_b, + in.mem_sel_resolve_ind_addr_b, + in.main_clk, + in.main_space_id, + in.main_ind_addr_b, + in.main_mem_addr_b, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val); } /** @@ -80,23 +80,25 @@ class perm_main_mem_ind_c_permutation_settings { template static inline auto get_nonconst_entities(AllEntities& in) { - return std::forward_as_tuple(in.perm_main_mem_ind_c, - in.avm_main_ind_op_c, - in.avm_main_ind_op_c, - in.avm_mem_ind_op_c, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_ind_c, - in.avm_main_mem_idx_c, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val); + return std::forward_as_tuple(in.perm_main_mem_ind_addr_b, + in.main_sel_resolve_ind_addr_b, + in.main_sel_resolve_ind_addr_b, + in.mem_sel_resolve_ind_addr_b, + in.main_clk, + in.main_space_id, + in.main_ind_addr_b, + in.main_mem_addr_b, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val); } }; template -using perm_main_mem_ind_c_relation = GenericPermutationRelation; -template using perm_main_mem_ind_c = GenericPermutation; +using perm_main_mem_ind_addr_b_relation = + GenericPermutationRelation; +template +using perm_main_mem_ind_addr_b = GenericPermutation; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_a.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_addr_c.hpp similarity index 64% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_a.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_addr_c.hpp index fde1c682370..7367fc905f8 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_a.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_addr_c.hpp @@ -9,7 +9,7 @@ namespace bb { -class perm_main_mem_ind_a_permutation_settings { +class perm_main_mem_ind_addr_c_permutation_settings { public: // This constant defines how many columns are bundled together to form each set. constexpr static size_t COLUMNS_PER_SET = 4; @@ -23,7 +23,7 @@ class perm_main_mem_ind_a_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_ind_op_a == 1 || in.avm_mem_ind_op_a == 1); + return (in.main_sel_resolve_ind_addr_c == 1 || in.mem_sel_resolve_ind_addr_c == 1); } /** @@ -46,18 +46,18 @@ class perm_main_mem_ind_a_permutation_settings { template static inline auto get_const_entities(const AllEntities& in) { - return std::forward_as_tuple(in.perm_main_mem_ind_a, - in.avm_main_ind_op_a, - in.avm_main_ind_op_a, - in.avm_mem_ind_op_a, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_ind_a, - in.avm_main_mem_idx_a, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val); + return std::forward_as_tuple(in.perm_main_mem_ind_addr_c, + in.main_sel_resolve_ind_addr_c, + in.main_sel_resolve_ind_addr_c, + in.mem_sel_resolve_ind_addr_c, + in.main_clk, + in.main_space_id, + in.main_ind_addr_c, + in.main_mem_addr_c, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val); } /** @@ -80,23 +80,25 @@ class perm_main_mem_ind_a_permutation_settings { template static inline auto get_nonconst_entities(AllEntities& in) { - return std::forward_as_tuple(in.perm_main_mem_ind_a, - in.avm_main_ind_op_a, - in.avm_main_ind_op_a, - in.avm_mem_ind_op_a, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_ind_a, - in.avm_main_mem_idx_a, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val); + return std::forward_as_tuple(in.perm_main_mem_ind_addr_c, + in.main_sel_resolve_ind_addr_c, + in.main_sel_resolve_ind_addr_c, + in.mem_sel_resolve_ind_addr_c, + in.main_clk, + in.main_space_id, + in.main_ind_addr_c, + in.main_mem_addr_c, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val); } }; template -using perm_main_mem_ind_a_relation = GenericPermutationRelation; -template using perm_main_mem_ind_a = GenericPermutation; +using perm_main_mem_ind_addr_c_relation = + GenericPermutationRelation; +template +using perm_main_mem_ind_addr_c = GenericPermutation; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_b.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_addr_d.hpp similarity index 64% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_b.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_addr_d.hpp index 0fb572b5302..6515b55c4bd 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_b.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_addr_d.hpp @@ -9,7 +9,7 @@ namespace bb { -class perm_main_mem_ind_b_permutation_settings { +class perm_main_mem_ind_addr_d_permutation_settings { public: // This constant defines how many columns are bundled together to form each set. constexpr static size_t COLUMNS_PER_SET = 4; @@ -23,7 +23,7 @@ class perm_main_mem_ind_b_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_ind_op_b == 1 || in.avm_mem_ind_op_b == 1); + return (in.main_sel_resolve_ind_addr_d == 1 || in.mem_sel_resolve_ind_addr_d == 1); } /** @@ -46,18 +46,18 @@ class perm_main_mem_ind_b_permutation_settings { template static inline auto get_const_entities(const AllEntities& in) { - return std::forward_as_tuple(in.perm_main_mem_ind_b, - in.avm_main_ind_op_b, - in.avm_main_ind_op_b, - in.avm_mem_ind_op_b, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_ind_b, - in.avm_main_mem_idx_b, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val); + return std::forward_as_tuple(in.perm_main_mem_ind_addr_d, + in.main_sel_resolve_ind_addr_d, + in.main_sel_resolve_ind_addr_d, + in.mem_sel_resolve_ind_addr_d, + in.main_clk, + in.main_space_id, + in.main_ind_addr_d, + in.main_mem_addr_d, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val); } /** @@ -80,23 +80,25 @@ class perm_main_mem_ind_b_permutation_settings { template static inline auto get_nonconst_entities(AllEntities& in) { - return std::forward_as_tuple(in.perm_main_mem_ind_b, - in.avm_main_ind_op_b, - in.avm_main_ind_op_b, - in.avm_mem_ind_op_b, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_ind_b, - in.avm_main_mem_idx_b, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val); + return std::forward_as_tuple(in.perm_main_mem_ind_addr_d, + in.main_sel_resolve_ind_addr_d, + in.main_sel_resolve_ind_addr_d, + in.mem_sel_resolve_ind_addr_d, + in.main_clk, + in.main_space_id, + in.main_ind_addr_d, + in.main_mem_addr_d, + in.mem_clk, + in.mem_space_id, + in.mem_addr, + in.mem_val); } }; template -using perm_main_mem_ind_b_relation = GenericPermutationRelation; -template using perm_main_mem_ind_b = GenericPermutation; +using perm_main_mem_ind_addr_d_relation = + GenericPermutationRelation; +template +using perm_main_mem_ind_addr_d = GenericPermutation; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_d.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_d.hpp deleted file mode 100644 index c66b01e035a..00000000000 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_mem_ind_d.hpp +++ /dev/null @@ -1,102 +0,0 @@ - - -#pragma once - -#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" - -#include -#include - -namespace bb { - -class perm_main_mem_ind_d_permutation_settings { - public: - // This constant defines how many columns are bundled together to form each set. - constexpr static size_t COLUMNS_PER_SET = 4; - - /** - * @brief If this method returns true on a row of values, then the inverse polynomial at this index. Otherwise the - * value needs to be set to zero. - * - * @details If this is true then permutation takes place in this row - */ - - template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) - { - return (in.avm_main_ind_op_d == 1 || in.avm_mem_ind_op_d == 1); - } - - /** - * @brief Get all the entities for the permutation when we don't need to update them - * - * @details The entities are returned as a tuple of references in the following order: - * - The entity/polynomial used to store the product of the inverse values - * - The entity/polynomial that switches on the subrelation of the permutation relation that ensures correctness of - * the inverse polynomial - * - The entity/polynomial that enables adding a tuple-generated value from the first set to the logderivative sum - * subrelation - * - The entity/polynomial that enables adding a tuple-generated value from the second set to the logderivative sum - * subrelation - * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the first set (N.B. ORDER IS IMPORTANT!) - * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the second set (N.B. ORDER IS IMPORTANT!) - * - * @return All the entities needed for the permutation - */ - - template static inline auto get_const_entities(const AllEntities& in) - { - - return std::forward_as_tuple(in.perm_main_mem_ind_d, - in.avm_main_ind_op_d, - in.avm_main_ind_op_d, - in.avm_mem_ind_op_d, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_ind_d, - in.avm_main_mem_idx_d, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val); - } - - /** - * @brief Get all the entities for the permutation when need to update them - * - * @details The entities are returned as a tuple of references in the following order: - * - The entity/polynomial used to store the product of the inverse values - * - The entity/polynomial that switches on the subrelation of the permutation relation that ensures correctness of - * the inverse polynomial - * - The entity/polynomial that enables adding a tuple-generated value from the first set to the logderivative sum - * subrelation - * - The entity/polynomial that enables adding a tuple-generated value from the second set to the logderivative sum - * subrelation - * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the first set (N.B. ORDER IS IMPORTANT!) - * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the second set (N.B. ORDER IS IMPORTANT!) - * - * @return All the entities needed for the permutation - */ - - template static inline auto get_nonconst_entities(AllEntities& in) - { - - return std::forward_as_tuple(in.perm_main_mem_ind_d, - in.avm_main_ind_op_d, - in.avm_main_ind_op_d, - in.avm_mem_ind_op_d, - in.avm_main_clk, - in.avm_main_space_id, - in.avm_main_ind_d, - in.avm_main_mem_idx_d, - in.avm_mem_clk, - in.avm_mem_space_id, - in.avm_mem_addr, - in.avm_mem_val); - } -}; - -template -using perm_main_mem_ind_d_relation = GenericPermutationRelation; -template using perm_main_mem_ind_d = GenericPermutation; - -} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_pedersen.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_pedersen.hpp index 75d4809336f..f59fdd920fa 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_pedersen.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_pedersen.hpp @@ -23,7 +23,7 @@ class perm_main_pedersen_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_sel_op_pedersen == 1 || in.avm_pedersen_pedersen_sel == 1); + return (in.main_sel_op_pedersen == 1 || in.pedersen_sel_pedersen == 1); } /** @@ -47,13 +47,13 @@ class perm_main_pedersen_permutation_settings { { return std::forward_as_tuple(in.perm_main_pedersen, - in.avm_main_sel_op_pedersen, - in.avm_main_sel_op_pedersen, - in.avm_pedersen_pedersen_sel, - in.avm_main_clk, - in.avm_main_ia, - in.avm_pedersen_clk, - in.avm_pedersen_input); + in.main_sel_op_pedersen, + in.main_sel_op_pedersen, + in.pedersen_sel_pedersen, + in.main_clk, + in.main_ia, + in.pedersen_clk, + in.pedersen_input); } /** @@ -77,13 +77,13 @@ class perm_main_pedersen_permutation_settings { { return std::forward_as_tuple(in.perm_main_pedersen, - in.avm_main_sel_op_pedersen, - in.avm_main_sel_op_pedersen, - in.avm_pedersen_pedersen_sel, - in.avm_main_clk, - in.avm_main_ia, - in.avm_pedersen_clk, - in.avm_pedersen_input); + in.main_sel_op_pedersen, + in.main_sel_op_pedersen, + in.pedersen_sel_pedersen, + in.main_clk, + in.main_ia, + in.pedersen_clk, + in.pedersen_input); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_pos2_perm.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_pos2_perm.hpp index e75d3658eca..dab9abe744f 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_pos2_perm.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_pos2_perm.hpp @@ -23,7 +23,7 @@ class perm_main_pos2_perm_permutation_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_sel_op_poseidon2 == 1 || in.avm_poseidon2_poseidon_perm_sel == 1); + return (in.main_sel_op_poseidon2 == 1 || in.poseidon2_sel_poseidon_perm == 1); } /** @@ -47,15 +47,15 @@ class perm_main_pos2_perm_permutation_settings { { return std::forward_as_tuple(in.perm_main_pos2_perm, - in.avm_main_sel_op_poseidon2, - in.avm_main_sel_op_poseidon2, - in.avm_poseidon2_poseidon_perm_sel, - in.avm_main_clk, - in.avm_main_ia, - in.avm_main_ib, - in.avm_poseidon2_clk, - in.avm_poseidon2_input, - in.avm_poseidon2_output); + in.main_sel_op_poseidon2, + in.main_sel_op_poseidon2, + in.poseidon2_sel_poseidon_perm, + in.main_clk, + in.main_ia, + in.main_ib, + in.poseidon2_clk, + in.poseidon2_input, + in.poseidon2_output); } /** @@ -79,15 +79,15 @@ class perm_main_pos2_perm_permutation_settings { { return std::forward_as_tuple(in.perm_main_pos2_perm, - in.avm_main_sel_op_poseidon2, - in.avm_main_sel_op_poseidon2, - in.avm_poseidon2_poseidon_perm_sel, - in.avm_main_clk, - in.avm_main_ia, - in.avm_main_ib, - in.avm_poseidon2_clk, - in.avm_poseidon2_input, - in.avm_poseidon2_output); + in.main_sel_op_poseidon2, + in.main_sel_op_poseidon2, + in.poseidon2_sel_poseidon_perm, + in.main_clk, + in.main_ia, + in.main_ib, + in.poseidon2_clk, + in.poseidon2_input, + in.poseidon2_output); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_sha256.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_sha256.hpp deleted file mode 100644 index d7943e2d5a3..00000000000 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/perm_main_sha256.hpp +++ /dev/null @@ -1,102 +0,0 @@ - - -#pragma once - -#include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" - -#include -#include - -namespace bb { - -class perm_main_sha256_permutation_settings { - public: - // This constant defines how many columns are bundled together to form each set. - constexpr static size_t COLUMNS_PER_SET = 4; - - /** - * @brief If this method returns true on a row of values, then the inverse polynomial at this index. Otherwise the - * value needs to be set to zero. - * - * @details If this is true then permutation takes place in this row - */ - - template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) - { - return (in.avm_main_sel_op_sha256 == 1 || in.avm_sha256_sha256_compression_sel == 1); - } - - /** - * @brief Get all the entities for the permutation when we don't need to update them - * - * @details The entities are returned as a tuple of references in the following order: - * - The entity/polynomial used to store the product of the inverse values - * - The entity/polynomial that switches on the subrelation of the permutation relation that ensures correctness of - * the inverse polynomial - * - The entity/polynomial that enables adding a tuple-generated value from the first set to the logderivative sum - * subrelation - * - The entity/polynomial that enables adding a tuple-generated value from the second set to the logderivative sum - * subrelation - * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the first set (N.B. ORDER IS IMPORTANT!) - * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the second set (N.B. ORDER IS IMPORTANT!) - * - * @return All the entities needed for the permutation - */ - - template static inline auto get_const_entities(const AllEntities& in) - { - - return std::forward_as_tuple(in.perm_main_sha256, - in.avm_main_sel_op_sha256, - in.avm_main_sel_op_sha256, - in.avm_sha256_sha256_compression_sel, - in.avm_main_clk, - in.avm_main_ia, - in.avm_main_ib, - in.avm_main_ic, - in.avm_sha256_clk, - in.avm_sha256_state, - in.avm_sha256_input, - in.avm_sha256_output); - } - - /** - * @brief Get all the entities for the permutation when need to update them - * - * @details The entities are returned as a tuple of references in the following order: - * - The entity/polynomial used to store the product of the inverse values - * - The entity/polynomial that switches on the subrelation of the permutation relation that ensures correctness of - * the inverse polynomial - * - The entity/polynomial that enables adding a tuple-generated value from the first set to the logderivative sum - * subrelation - * - The entity/polynomial that enables adding a tuple-generated value from the second set to the logderivative sum - * subrelation - * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the first set (N.B. ORDER IS IMPORTANT!) - * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the second set (N.B. ORDER IS IMPORTANT!) - * - * @return All the entities needed for the permutation - */ - - template static inline auto get_nonconst_entities(AllEntities& in) - { - - return std::forward_as_tuple(in.perm_main_sha256, - in.avm_main_sel_op_sha256, - in.avm_main_sel_op_sha256, - in.avm_sha256_sha256_compression_sel, - in.avm_main_clk, - in.avm_main_ia, - in.avm_main_ib, - in.avm_main_ic, - in.avm_sha256_clk, - in.avm_sha256_state, - in.avm_sha256_input, - in.avm_sha256_output); - } -}; - -template -using perm_main_sha256_relation = GenericPermutationRelation; -template using perm_main_sha256 = GenericPermutation; - -} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_conversion.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/poseidon2.hpp similarity index 70% rename from barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_conversion.hpp rename to barretenberg/cpp/src/barretenberg/relations/generated/avm/poseidon2.hpp index b269078f03b..a758f8333b2 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/avm_conversion.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/poseidon2.hpp @@ -6,19 +6,19 @@ namespace bb::Avm_vm { -template struct Avm_conversionRow { - FF avm_conversion_to_radix_le_sel{}; +template struct Poseidon2Row { + FF poseidon2_sel_poseidon_perm{}; [[maybe_unused]] static std::vector names(); }; -inline std::string get_relation_label_avm_conversion(int index) +inline std::string get_relation_label_poseidon2(int index) { switch (index) {} return std::to_string(index); } -template class avm_conversionImpl { +template class poseidon2Impl { public: using FF = FF_; @@ -37,13 +37,13 @@ template class avm_conversionImpl { { Avm_DECLARE_VIEWS(0); - auto tmp = (avm_conversion_to_radix_le_sel * (-avm_conversion_to_radix_le_sel + FF(1))); + auto tmp = (poseidon2_sel_poseidon_perm * (-poseidon2_sel_poseidon_perm + FF(1))); tmp *= scaling_factor; std::get<0>(evals) += tmp; } } }; -template using avm_conversion = Relation>; +template using poseidon2 = Relation>; } // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/pow_2_lookups.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/pow_2_lookups.hpp deleted file mode 100644 index b66844e7d06..00000000000 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/pow_2_lookups.hpp +++ /dev/null @@ -1,170 +0,0 @@ - - -#pragma once - -#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp" - -#include -#include - -namespace bb { - -/** - * @brief This class contains an example of how to set LookupSettings classes used by the - * GenericLookupRelationImpl class to specify a scaled lookup - * - * @details To create your own lookup: - * 1) Create a copy of this class and rename it - * 2) Update all the values with the ones needed for your lookup - * 3) Update "DECLARE_LOOKUP_IMPLEMENTATIONS_FOR_ALL_SETTINGS" and "DEFINE_LOOKUP_IMPLEMENTATIONS_FOR_ALL_SETTINGS" to - * include the new settings - * 4) Add the relation with the chosen settings to Relations in the flavor (for example,"` - * using Relations = std::tuple>;)` - * - */ -class pow_2_lookups_lookup_settings { - public: - /** - * @brief The number of read terms (how many lookups we perform) in each row - * - */ - static constexpr size_t READ_TERMS = 1; - /** - * @brief The number of write terms (how many additions to the lookup table we make) in each row - * - */ - static constexpr size_t WRITE_TERMS = 1; - - /** - * @brief The type of READ_TERM used for each read index (basic and scaled) - * - */ - static constexpr size_t READ_TERM_TYPES[READ_TERMS] = { 0 }; - - /** - * @brief They type of WRITE_TERM used for each write index - * - */ - static constexpr size_t WRITE_TERM_TYPES[WRITE_TERMS] = { 0 }; - - /** - * @brief How many values represent a single lookup object. This value is used by the automatic read term - * implementation in the relation in case the lookup is a basic or scaled tuple and in the write term if it's a - * basic tuple - * - */ - static constexpr size_t LOOKUP_TUPLE_SIZE = 2; - - /** - * @brief The polynomial degree of the relation telling us if the inverse polynomial value needs to be computed - * - */ - static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4; - - /** - * @brief The degree of the read term if implemented arbitrarily. This value is not used by basic and scaled read - * terms, but will cause compilation error if not defined - * - */ - static constexpr size_t READ_TERM_DEGREE = 0; - - /** - * @brief The degree of the write term if implemented arbitrarily. This value is not used by the basic write - * term, but will cause compilation error if not defined - * - */ - - static constexpr size_t WRITE_TERM_DEGREE = 0; - - /** - * @brief If this method returns true on a row of values, then the inverse polynomial exists at this index. - * Otherwise the value needs to be set to zero. - * - * @details If this is true then the lookup takes place in this row - * - */ - - template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) - { - return (in.avm_alu_pow_2_sel == 1 || in.avm_main_sel_rng_8 == 1); - } - - /** - * @brief Subprocedure for computing the value deciding if the inverse polynomial value needs to be checked in this - * row - * - * @tparam Accumulator Type specified by the lookup relation - * @tparam AllEntities Values/Univariates of all entities row - * @param in Value/Univariate of all entities at row/edge - * @return Accumulator - */ - - template - static inline auto compute_inverse_exists(const AllEntities& in) - { - using View = typename Accumulator::View; - const auto is_operation = View(in.avm_alu_pow_2_sel); - const auto is_table_entry = View(in.avm_main_sel_rng_8); - return (is_operation + is_table_entry - is_operation * is_table_entry); - } - - /** - * @brief Get all the entities for the lookup when need to update them - * - * @details The generic structure of this tuple is described in ./generic_lookup_relation.hpp . The following is - description for the current case: - The entities are returned as a tuple of references in the following order (this is for ): - * - The entity/polynomial used to store the product of the inverse values - * - The entity/polynomial that specifies how many times the lookup table entry at this row has been looked up - * - READ_TERMS entities/polynomials that enable individual lookup operations - * - The entity/polynomial that enables adding an entry to the lookup table in this row - * - LOOKUP_TUPLE_SIZE entities/polynomials representing the basic tuple being looked up as the first read term - * - LOOKUP_TUPLE_SIZE entities/polynomials representing the previous accumulators in the second read term - (scaled tuple) - * - LOOKUP_TUPLE_SIZE entities/polynomials representing the shifts in the second read term (scaled tuple) - * - LOOKUP_TUPLE_SIZE entities/polynomials representing the current accumulators in the second read term - (scaled tuple) - * - LOOKUP_TUPLE_SIZE entities/polynomials representing basic tuples added to the table - * - * @return All the entities needed for the lookup - */ - - template static inline auto get_const_entities(const AllEntities& in) - { - - return std::forward_as_tuple(in.pow_2_lookups, - in.pow_2_lookups_counts, - in.avm_alu_pow_2_sel, - in.avm_main_sel_rng_8, - in.avm_alu_ib, - in.avm_alu_two_pow_b, - in.avm_main_clk, - in.avm_main_table_pow_2); - } - - /** - * @brief Get all the entities for the lookup when we only need to read them - * @details Same as in get_const_entities, but nonconst - * - * @return All the entities needed for the lookup - */ - - template static inline auto get_nonconst_entities(AllEntities& in) - { - - return std::forward_as_tuple(in.pow_2_lookups, - in.pow_2_lookups_counts, - in.avm_alu_pow_2_sel, - in.avm_main_sel_rng_8, - in.avm_alu_ib, - in.avm_alu_two_pow_b, - in.avm_main_clk, - in.avm_main_table_pow_2); - } -}; - -template using pow_2_lookups_relation = GenericLookupRelation; -template using pow_2_lookups = GenericLookup; - -} // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_da_gas_hi.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_da_gas_hi.hpp index 6b68d3b90cb..b3c732c4e59 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_da_gas_hi.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_da_gas_hi.hpp @@ -87,7 +87,7 @@ class range_check_da_gas_hi_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_gas_cost_active == 1 || in.avm_main_sel_rng_16 == 1); + return (in.main_sel_gas_accounting_active == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class range_check_da_gas_hi_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_main_gas_cost_active); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.main_sel_gas_accounting_active); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class range_check_da_gas_hi_lookup_settings { return std::forward_as_tuple(in.range_check_da_gas_hi, in.range_check_da_gas_hi_counts, - in.avm_main_gas_cost_active, - in.avm_main_sel_rng_16, - in.avm_main_abs_da_rem_gas_hi, - in.avm_main_clk); + in.main_sel_gas_accounting_active, + in.main_sel_rng_16, + in.main_abs_da_rem_gas_hi, + in.main_clk); } /** @@ -153,10 +153,10 @@ class range_check_da_gas_hi_lookup_settings { return std::forward_as_tuple(in.range_check_da_gas_hi, in.range_check_da_gas_hi_counts, - in.avm_main_gas_cost_active, - in.avm_main_sel_rng_16, - in.avm_main_abs_da_rem_gas_hi, - in.avm_main_clk); + in.main_sel_gas_accounting_active, + in.main_sel_rng_16, + in.main_abs_da_rem_gas_hi, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_da_gas_lo.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_da_gas_lo.hpp index 0ab6e798dac..0167a2e4ee3 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_da_gas_lo.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_da_gas_lo.hpp @@ -87,7 +87,7 @@ class range_check_da_gas_lo_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_gas_cost_active == 1 || in.avm_main_sel_rng_16 == 1); + return (in.main_sel_gas_accounting_active == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class range_check_da_gas_lo_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_main_gas_cost_active); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.main_sel_gas_accounting_active); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class range_check_da_gas_lo_lookup_settings { return std::forward_as_tuple(in.range_check_da_gas_lo, in.range_check_da_gas_lo_counts, - in.avm_main_gas_cost_active, - in.avm_main_sel_rng_16, - in.avm_main_abs_da_rem_gas_lo, - in.avm_main_clk); + in.main_sel_gas_accounting_active, + in.main_sel_rng_16, + in.main_abs_da_rem_gas_lo, + in.main_clk); } /** @@ -153,10 +153,10 @@ class range_check_da_gas_lo_lookup_settings { return std::forward_as_tuple(in.range_check_da_gas_lo, in.range_check_da_gas_lo_counts, - in.avm_main_gas_cost_active, - in.avm_main_sel_rng_16, - in.avm_main_abs_da_rem_gas_lo, - in.avm_main_clk); + in.main_sel_gas_accounting_active, + in.main_sel_rng_16, + in.main_abs_da_rem_gas_lo, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_l2_gas_hi.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_l2_gas_hi.hpp index 913f0cec89e..81a3f1e0b97 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_l2_gas_hi.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_l2_gas_hi.hpp @@ -87,7 +87,7 @@ class range_check_l2_gas_hi_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_gas_cost_active == 1 || in.avm_main_sel_rng_16 == 1); + return (in.main_sel_gas_accounting_active == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class range_check_l2_gas_hi_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_main_gas_cost_active); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.main_sel_gas_accounting_active); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class range_check_l2_gas_hi_lookup_settings { return std::forward_as_tuple(in.range_check_l2_gas_hi, in.range_check_l2_gas_hi_counts, - in.avm_main_gas_cost_active, - in.avm_main_sel_rng_16, - in.avm_main_abs_l2_rem_gas_hi, - in.avm_main_clk); + in.main_sel_gas_accounting_active, + in.main_sel_rng_16, + in.main_abs_l2_rem_gas_hi, + in.main_clk); } /** @@ -153,10 +153,10 @@ class range_check_l2_gas_hi_lookup_settings { return std::forward_as_tuple(in.range_check_l2_gas_hi, in.range_check_l2_gas_hi_counts, - in.avm_main_gas_cost_active, - in.avm_main_sel_rng_16, - in.avm_main_abs_l2_rem_gas_hi, - in.avm_main_clk); + in.main_sel_gas_accounting_active, + in.main_sel_rng_16, + in.main_abs_l2_rem_gas_hi, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_l2_gas_lo.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_l2_gas_lo.hpp index 0b5ffedb068..ca2165657a2 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_l2_gas_lo.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/range_check_l2_gas_lo.hpp @@ -87,7 +87,7 @@ class range_check_l2_gas_lo_lookup_settings { template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) { - return (in.avm_main_gas_cost_active == 1 || in.avm_main_sel_rng_16 == 1); + return (in.main_sel_gas_accounting_active == 1 || in.main_sel_rng_16 == 1); } /** @@ -104,8 +104,8 @@ class range_check_l2_gas_lo_lookup_settings { static inline auto compute_inverse_exists(const AllEntities& in) { using View = typename Accumulator::View; - const auto is_operation = View(in.avm_main_gas_cost_active); - const auto is_table_entry = View(in.avm_main_sel_rng_16); + const auto is_operation = View(in.main_sel_gas_accounting_active); + const auto is_table_entry = View(in.main_sel_rng_16); return (is_operation + is_table_entry - is_operation * is_table_entry); } @@ -135,10 +135,10 @@ class range_check_l2_gas_lo_lookup_settings { return std::forward_as_tuple(in.range_check_l2_gas_lo, in.range_check_l2_gas_lo_counts, - in.avm_main_gas_cost_active, - in.avm_main_sel_rng_16, - in.avm_main_abs_l2_rem_gas_lo, - in.avm_main_clk); + in.main_sel_gas_accounting_active, + in.main_sel_rng_16, + in.main_abs_l2_rem_gas_lo, + in.main_clk); } /** @@ -153,10 +153,10 @@ class range_check_l2_gas_lo_lookup_settings { return std::forward_as_tuple(in.range_check_l2_gas_lo, in.range_check_l2_gas_lo_counts, - in.avm_main_gas_cost_active, - in.avm_main_sel_rng_16, - in.avm_main_abs_l2_rem_gas_lo, - in.avm_main_clk); + in.main_sel_gas_accounting_active, + in.main_sel_rng_16, + in.main_abs_l2_rem_gas_lo, + in.main_clk); } }; diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/sha256.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/sha256.hpp new file mode 100644 index 00000000000..189cbb7c699 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/sha256.hpp @@ -0,0 +1,49 @@ + +#pragma once +#include "../../relation_parameters.hpp" +#include "../../relation_types.hpp" +#include "./declare_views.hpp" + +namespace bb::Avm_vm { + +template struct Sha256Row { + FF sha256_sel_sha256_compression{}; + + [[maybe_unused]] static std::vector names(); +}; + +inline std::string get_relation_label_sha256(int index) +{ + switch (index) {} + return std::to_string(index); +} + +template class sha256Impl { + public: + using FF = FF_; + + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, + }; + + template + void static accumulate(ContainerOverSubrelations& evals, + const AllEntities& new_term, + [[maybe_unused]] const RelationParameters&, + [[maybe_unused]] const FF& scaling_factor) + { + + // Contribution 0 + { + Avm_DECLARE_VIEWS(0); + + auto tmp = (sha256_sel_sha256_compression * (-sha256_sel_sha256_compression + FF(1))); + tmp *= scaling_factor; + std::get<0>(evals) += tmp; + } + } +}; + +template using sha256 = Relation>; + +} // namespace bb::Avm_vm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/smt_verification/CMakeLists.txt index 5428aeae1c7..265a64887e6 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/smt_verification/CMakeLists.txt @@ -26,7 +26,7 @@ add_dependencies(cvc5-lib cvc5) include_directories(${CVC5_INCLUDE}) set_target_properties(cvc5-lib PROPERTIES IMPORTED_LOCATION ${CVC5_LIB}) -barretenberg_module(smt_verification common stdlib_primitives stdlib_sha256 circuit_checker transcript plonk cvc5-lib) +barretenberg_module(smt_verification common stdlib_primitives stdlib_sha256 circuit_checker transcript plonk stdlib_pedersen_commitment cvc5-lib) # We have no easy way to add a dependency to an external target, we list the built targets explicit. Could be cleaner. add_dependencies(smt_verification cvc5) add_dependencies(smt_verification_objects cvc5) diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/README.md b/barretenberg/cpp/src/barretenberg/smt_verification/README.md index 9230c405690..aa12cccf666 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/README.md +++ b/barretenberg/cpp/src/barretenberg/smt_verification/README.md @@ -1,14 +1,14 @@ # Using cvc5 and smt_verification module -Just build with `smt-verification` preset +You have to install the following packages on your system: `sudo apt install python3-pip python3.11-venv` -Now you can import cvc5 using +Then just build with `smt-verification` preset. # How to use smt_circuit library ## 1. Setting variable names during circuit creation and exporting the circuit. -### There're five new methods inside (for now standard) circuit_builder +### There're four new methods inside Standard and Ultra CircuitBuilders - ```set_variable_name(u32 index, str name)``` - assignes a name to a variable. Specifically, binds a name with the first index of an equivalence class. @@ -18,9 +18,9 @@ Now you can import cvc5 using - ```export_circuit()``` - exports all variables, gates, and assigned names to an msgpack-compatible buffer namely `msgpack::sbuffer`. -To store it on the disk just do +To store it on the disk just do the following -```cpp +```c++ msgpack::sbuffer buffer = circuit.export_circuit(); std::fstream myfile; @@ -49,20 +49,26 @@ To store it on the disk just do uint64_t timeout; uint32_t debug; - bool ff_disjunctive_bit; + bool ff_elim_disjunctive_bit; std::string ff_solver; + + bool lookup_enabled; }; ``` - `produce_models` - should be initialized as `true` if you want to check the values obtained using the solver when the result of the check does not meet your expectations. **All the public variables will be constrained to be equal their real value**. - `timeout` - solver timeout in milliseconds - `debug` - 0, 1, 2 - defines verbosity level of cvc5 - - `ff_disjunctive_bit` - **Advanced**. Should be used to transform assertions like `(x == 0) | (x == 1)` to `x^2 - x = 0` + - `ff_elim_disjunctive_bit` - **Advanced**. Should be used to transform assertions like `(x == 0) | (x == 1)` to `x^2 - x = 0` when set to true - `ff_solver` - "gb" or "split-gb". **Advanced**. Change the solver approach to solving systems over finite fields. + - `lookup_enabled` - enables set theory inside the solver. Have to be true when we are dealing with lookup tables. - There's a `default_solver_config = { true, 0, 0, false, ""}` + There're two default configs in `smt_solver` namespace - More info on `SolverConfiguration` can be found [here](solver/solver.hpp) + - `default_solver_config = { true, 0, 0, false, "", false}` + - `ultra_solver_config = {true, 0, 0, false, "", true}` + + More info on `SolverConfiguration` can be found in [solver.hpp](solver/solver.hpp) Now we can initialize the solver @@ -77,8 +83,22 @@ To store it on the disk just do `Solver` instance has useful method `print_assertions` that will output all the assertions in kind of human readable format(not SMT2 lang). - There's also a function `smt_timer(Solver& s, bool mins)` in `barretenberg/smt_verification/util/smt_util.hpp` that will run the `check`, measure the time in minutes/seconds and send it to stdout. - + There's also a function `smt_timer(Solver& s)` in `barretenberg/smt_verification/util/smt_util.hpp` that will run the `check`, measure the time in minutes:seconds and send it to stdout. + + + All the tables are exoported directly from circuit, but if you want to create your own table, there're two methods for this: + + - `Solver::create_table(vector& table)` - creates a set of values. + - `Solver::create_lookup_table(vector>& table)` - creates a table with three columns. + + ```c++ + std::vector> table = { { FFConst("1", &s), FFConst("2", &s), FFConst("3", &s) }, + { FFConst("4", &s), FFConst("5", &s), FFConst("6", &s) } }; + cvc5::Term symbolic_table = s.create_lookup_table(table); + ``` + + There is more on `FFConst` in the following sections. + 3. Initialize the Circuit From now on we will use `smt_terms::STerm` and `smt_terms::Bool` types to operate inside the solver. @@ -86,7 +106,8 @@ To store it on the disk just do You can choose the behaviour of symbolic variables by providing the specific type to `STerm` or `Circuit` constructor: - `smt_terms::TermType::FFTerm` - symbolic variables that simulate finite field arithmetic. - - `smt_terms::TermType::FFITerm` - symbolic variables that simulate integer elements which behave like finite field ones. Useful, when you want to create range constraints. Bad when you try multiplication. + - `smt_terms::TermType::FFITerm` - symbolic variables that simulate integer elements which behave like finite field ones. Useful, when you want to create range constraints. Bad, when you try multiplication. + - `smt_terms::TermType::ITerm` - symbolic variables that simulate ordinary integer elements. Useful, when you want to create range constraints and operate with signed values that are not shrinked modulo smth. - `smt_terms::TermType::BVTerm` - symbolic variables that simulate $\pmod{2^n}$ arithmetic. Useful, when you test uint circuits. Supports range constraints and bitwise operations. Doesn't behave like finite field element. All these types use different solver engines. The most general one is `FFTerm`. @@ -95,15 +116,19 @@ To store it on the disk just do Now we can create symbolic circuit - ```smt_circuit::Circuit circuit(CircuitSchema c_info, Solver* s, TermType type, str tag="")``` + - ```smt_circuit::StandardCircuit circuit(CircuitSchema c_info, Solver* s, TermType type, str tag="", bool optimizations=true)``` + - ```smt_circuit::UltraCircuit circuit(CircuitSchema c_info, Solver* s, TermType type, str tag="", bool optimizations=true)``` It will generate all the symbolic values of the circuit wires, add all the gate constrains, create a map `term_name->STerm` and the inverse of it. Where `term_name` is the the name you provided earlier. - In case you want to create two similar circuits with the same `solver` and `schema`, then you should specify the tag(name) of a circuit. + In case you want to create two similar circuits with the same `solver` and `schema`, then you should specify the `tag`(name) of a circuit. + + **Advanced** If you don't want the circuit optimizations to be applied then you should set `optimizations` to `false`. Optimizations interchange the complex circuits like bitwise XOR with simple XOR operation. More on optimizations can be found [standard_circuit.cpp](circuit/standard_circuit.cpp) - Then you can get the previously named variables via `circuit[name]` or any other variable by `circuit[idx]`. - There is a method `Circuit::simulate_circuit_eval(vector w)`. It checks that the evaluation process is correct for this particular witness. + After the symbolic circuit is initialized, you can get the previously named variables via `circuit[name]` or any other variable by `circuit[idx]`. + + There is a method `Circuit::simulate_circuit_eval(vector w)`. It checks that the evaluation process is correct for this particular witness. (Only in Standard for now). 4. Terms creation @@ -122,13 +147,20 @@ To store it on the disk just do to create an addition/multiplication Term in one call - `FFITerm` also can be used to create range constraints. e.g. `x <= bb::fr(2).pow(10);` + `FFITerm` also can be used to create range constraints. e.g. `x <= bb::fr(2).pow(10) - 1;` `BVTerm` can be used to create bitwise constraints. e.g. `STerm y = x^z` or `STerm y = x.rotr(10)`. And range constraints too. You can create a constraint `==` or `!=` that will be included directly into solver. e.g. `x == y;` - **!Note: In this case it's not comparison operators** + **!Note: In this case these are not comparison operators** + + Also you can create set inclusion constraints. After creating a table(shown in section 2) there're two options: + + - `STerm::in(cvc5::Term table&)` - simple set inclusion. + - `static STerm::in_table(std::vector entry, cvc5::Term& table)` - lookup table inclusion. + + --- There is a Bool type: - `Bool Bool(STerm t)` or `Bool Bool(bool b, Solver* s)` @@ -140,35 +172,72 @@ To store it on the disk just do **!Note that constraint like `(Bool(STerm a) == Bool(STerm b)).assert_term()`, where a has `FFTerm` type and b has `FFITerm` type, won't work, since their types differ.** **!Note `Bool(a == b)` won't work since `a==b` will create an equality constraint as I mentioned earlier and the return type of this operation is `void`.** -5. Post model checking - After generating all the constrains you should call `bool res = solver.check()` and depending on your goal it could be `true` or `false`. - - In case you expected `false` but `true` was returned you can then check what went wrong. - You should generate an unordered map with `str->term` values and ask the solver to obtain `unoredered_map res = solver.model(unordered_map terms)`. - Or you can provide a vector of terms that you want to check and the return map will contain their symbolic names that are given during initialization. Specifically either it's the name that you set or `var_{i}`. - - Now you have the values of the specified terms, which resulted into `true` result. - **!Note that the return values are decimal strings/binary strings**, so if you want to use them later you should use `FFConst`, etc. +## 3. Post model checking +After generating all the constrains you should call `bool res = solver.check()` and depending on your goal it could be `true` or `false`. + +In case you expected `false` but `true` was returned you can then check what went wrong. +You should generate an unordered map with `str->term` values and ask the solver to obtain `unoredered_map res = solver.model(unordered_map terms)`. + Or you can provide a vector of terms that you want to check and the return map will contain their symbolic names that are given during initialization. Specifically either it's the name that you set or `var_{i}`. + +Now you have the values of the specified terms, which resulted into `true` result. +**!Note that the return values are decimal strings/binary strings**, so if you want to use them later you should use `FFConst` with base 10, etc. - Also, there is a header file "barretenberg/common/smt_model.hpp" with two functions: - - `default_model(verctor special_names, circuit1, circuit2, *solver, fname="witness.out")` - - `default_model_single(vector special_names, circuit, *solver, fname="witness.out)` +Also, there is a header file "barretenberg/smt_verification/utl/smt_util.hpp" that contains two useful functions: +- `default_model(verctor special_names, circuit1, circuit2, *solver, fname="witness.out")` +- `default_model_single(vector special_names, circuit, *solver, fname="witness.out)` - These functions will write witness variables in c-like array format into file named `fname`. - The vector of special names is the values that you want ot see in stdout. +These functions will write witness variables in c-like array format into file named `fname`. +The vector of `special_names` is the values that you want ot see in stdout. -6. Automated verification of a unique witness +## 4. Automated verification of a unique witness +There's a static member of `StandardCircuit` and `UltraCircuit` + +- `pair StandardCircuit::unique_wintes(CircuitSchema circuit_info, Solver*, TermType type, vector equal, bool optimizations)` +- `pair UltraCircuit::unique_wintes(CircuitSchema circuit_info, Solver*, TermType type, vector equal, bool optimizations)` + +They will create two separate circuits, constrain variables with names from `equal` to be equal acrosss the circuits, and set all the other variables to be not equal at the same time. + +Another one is + +- `pair StandardCircuit::unique_witness_ext(CircuitSchema circuit_info, Solver* s, TermType type, vector equal_variables, vector nequal_variables, vector at_least_one_equal_variable, vector at_least_one_nequal_variable)` that does the same but provides you with more flexible settings. +- Same in `UltraCircuit` - There's a function `pair unique_wintes(CircuitSchema circuit_info, Solver*, TermType type, vector equal)` - It will create two separate circuits, constrain variables with names from `equal` to be equal acrosss the circuits, and set all the other variables to be not equal at the same time. +The return circuits can be useful, if you want to define some additional constraints, that are not covered by the the above functions. +You can call `s.check`, `s.model`, `smt_timer` or `default_model` further. - Another one is `pair unique_witness_ext(CircuitSchema circuit_info, Solver* s, TermType type, vector equal_variables, vector nequal_variables, vector at_least_one_equal_variable, vector at_least_one_nequal_variable)` that does the same but provides you with more flexible settings. +## 5. smt_util.hpp +Besides already mentioned `smt_timer`, `default_model` and `default_model_single` there're two extra functions in `smt_util.hpp` - The return circuits can be useful, if you want to define some additional constraints, that are not covered by the the above functions. - You can call `s.check`, `s.model`, `smt_timer` or `default_model` further. +- `pair, vector> base4(uint32_t el)` - that will return base4 accumulators +- `void fix_range_lists(UltraCircuitBuilder& builder)` - Since we are not using the part of the witness, that contains range lists, they are set to 0 by the solver. We need to overwrite them to check the witness obtained by the solver. -## 3. Simple examples +```c++ + UltraCircuitBuilder builder; + uint_ct a = witness_ct(&builder, 0); + uint_ct b = witness_ct(&builder, 0); + builder.set_variable_name(a.get_witness_index(), "a"); + builder.set_variable_name(b.get_witness_index(), "b"); + uint_ct c = a + b; + builder.set_variable_name(c.get_witness_index(), "c"); + + // NOTE BEFORE FINALIZE + for (size_t i = 0; i < builder.get_num_variables(); i++) { + builder.variables[i] = add_unique_output[i]; + } + fix_range_lists(builder); + + info(builder.get_variable(a.get_witness_index())); + info("+"); + info(builder.get_variable(b.get_witness_index())); + info("="); + info(builder.get_variable(c.get_witness_index())); + info("------------------------"); + ASSERT_TRUE(CircuitChecker::check(builder)); +``` +Where `add_unique_output` is a witness obtained by the solver. + +## 6. Simple examples ### Function Equality ```cpp @@ -187,7 +256,7 @@ To store it on the disk just do smt_circuit::CircuitSchema circuit_info = smt_circuit::unpack_from_buffer(buf); smt_solver::Solver s(circuit_info.modulus); - smt_circuit::Circuit circuit(circuit_info, &s, smt_terms::TermType::FFTerm); + smt_circuit::StandardCircuit circuit(circuit_info, &s, smt_terms::TermType::FFTerm); smt_terms::STerm a1 = circuit["a"]; smt_terms::STerm b1 = circuit["b"]; smt_terms::STerm c1 = circuit["c"]; @@ -217,7 +286,7 @@ To store it on the disk just do smt_circuit::CircuitSchema circuit_info = smt_circuit::unpack_from_buffer(buf); smt_solver::Solver s(circuit_info.modulus); - smt_circuit::Circuit circuit(circuit_info, &s, smt_terms::TermType::FFTerm); + smt_circuit::StandardCircuit circuit(circuit_info, &s, smt_terms::TermType::FFTerm); smt_terms::STerm a1 = circuit["a"]; smt_terms::STerm b1 = circuit["b"]; @@ -263,8 +332,8 @@ To store it on the disk just do smt_circuit::CircuitSchema circuit_info = smt_circuit::unpack_from_buffer(buf); smt_solver::Solver s(circuit_info.modulus); - std::pair cirs = - smt_circuit::unique_witness_ext(circuit_info, &s, smt_terms::TermType::FFTerm, { "ev" }, { "z" }); + auto cirs = + smt_circuit::StandardCircuit::unique_witness_ext(circuit_info, &s, smt_terms::TermType::FFTerm, { "ev" }, { "z" }); bool res = s.check(); ASSERT_TRUE(res); @@ -277,7 +346,8 @@ To store it on the disk just do ### Custom model function ```cpp -void model_variables(Circuit& c, Solver* s, FFTerm& evaluation) +template +void model_variables(SymCircuit& c, Solver* s, FFTerm& evaluation) { std::unordered_map terms; terms.insert({ "point", c["point"] }); @@ -292,4 +362,10 @@ void model_variables(Circuit& c, Solver* s, FFTerm& evaluation } ``` -More examples can be found in [terms/ffterm.test.cpp](terms/ffterm.test.cpp), [circuit/circuit.test.cpp](circuit/circuit.test.cpp) and [smt_polynomials.test.cpp](smt_polynomials.test.cpp). \ No newline at end of file + +More examples can be found in + +- [terms/ffterm.test.cpp](terms/ffterm.test.cpp), [terms/ffiterm.test.cpp](terms/ffiterm.test.cpp), [terms/bvterm.test.cpp](terms/bvterm.test.cpp), [terms/iterm.test.cpp](terms/iterm.test.cpp) +- [circuit/standard_circuit.test.cpp](circuit/standard_circuit.test.cpp), [circuit/ultra_circuit](circuit/ultra_circuit.test.cpp) +- [smt_polynomials.test.cpp](smt_polynomials.test.cpp), [smt_examples.test.cpp](smt_examples.test.cpp) +- [bb_tests](bb_tests) diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/circuit/circuit_base.cpp b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/circuit_base.cpp index 6d53857d5fa..b4c6d1c872b 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/circuit/circuit_base.cpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/circuit_base.cpp @@ -6,6 +6,8 @@ CircuitBase::CircuitBase(std::unordered_map& variable_nam std::vector& variables, std::vector& public_inps, std::vector& real_variable_index, + std::vector& real_variable_tags, + std::unordered_map& range_tags, Solver* solver, TermType type, const std::string& tag, @@ -14,6 +16,8 @@ CircuitBase::CircuitBase(std::unordered_map& variable_nam , public_inps(public_inps) , variable_names(variable_names) , real_variable_index(real_variable_index) + , real_variable_tags(real_variable_tags) + , range_tags(range_tags) , optimizations(optimizations) , solver(solver) , type(type) diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/circuit/circuit_base.hpp b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/circuit_base.hpp index e37bfcd06d5..5d551406a4c 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/circuit/circuit_base.hpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/circuit_base.hpp @@ -33,6 +33,8 @@ class CircuitBase { std::unordered_map variable_names_inverse; // inverse map of the previous memeber std::unordered_map symbolic_vars; // all the symbolic variables from the circuit std::vector real_variable_index; // indexes for assert_equal'd wires + std::vector real_variable_tags; // tags of the variables in the circuit + std::unordered_map range_tags; // ranges associated with a certain tag std::unordered_map optimized; // keeps track of the variables that were excluded from symbolic // circuit during optimizations bool optimizations; // flags to turn on circuit optimizations @@ -51,6 +53,8 @@ class CircuitBase { std::vector& variables, std::vector& public_inps, std::vector& real_variable_index, + std::vector& real_variable_tags, + std::unordered_map& range_tags, Solver* solver, TermType type, const std::string& tag = "", diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/circuit/circuit_schema.hpp b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/circuit_schema.hpp index dbfb885ad3f..cc3b37e8e41 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/circuit/circuit_schema.hpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/circuit_schema.hpp @@ -31,8 +31,18 @@ struct CircuitSchema { std::vector>> wires; std::vector real_variable_index; std::vector>> lookup_tables; - MSGPACK_FIELDS( - modulus, public_inps, vars_of_interest, variables, selectors, wires, real_variable_index, lookup_tables); + std::vector real_variable_tags; + std::unordered_map range_tags; + MSGPACK_FIELDS(modulus, + public_inps, + vars_of_interest, + variables, + selectors, + wires, + real_variable_index, + lookup_tables, + real_variable_tags, + range_tags); }; CircuitSchema unpack_from_buffer(const msgpack::sbuffer& buf); diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/circuit/standard_circuit.cpp b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/standard_circuit.cpp index 709fe8414e0..1365618b02c 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/circuit/standard_circuit.cpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/standard_circuit.cpp @@ -15,6 +15,8 @@ StandardCircuit::StandardCircuit( circuit_info.variables, circuit_info.public_inps, circuit_info.real_variable_index, + circuit_info.real_variable_tags, + circuit_info.range_tags, solver, type, tag, @@ -438,7 +440,7 @@ size_t StandardCircuit::handle_range_constraint(size_t cursor) * It compares the chunk of selectors of the current circuit * with pure shift left from uint/logic.cpp * After a match is found, it updates the cursor to skip all the - * redundant constraints and adds a pure b = a.ror(n) + * redundant constraints and adds a pure b = a >> n * constraint to solver. * If there's no match, it will return -1 * @@ -547,7 +549,7 @@ size_t StandardCircuit::handle_shr_constraint(size_t cursor) * It compares the chunk of selectors of the current circuit * with pure shift left from uint/logic.cpp * After a match is found, it updates the cursor to skip all the - * redundant constraints and adds a pure b = a.ror(n) + * redundant constraints and adds a pure b = a << n * constraint to solver. * If there's no match, it will return -1 * @@ -812,7 +814,6 @@ std::pair StandardCircuit::unique_witness_ext( const std::vector& not_equal_at_the_same_time, bool optimizations) { - // TODO(alex): set optimizations to be true once they are confirmed StandardCircuit c1(circuit_info, s, type, "circuit1", optimizations); StandardCircuit c2(circuit_info, s, type, "circuit2", optimizations); @@ -865,7 +866,6 @@ std::pair StandardCircuit::unique_witness_ext( std::pair StandardCircuit::unique_witness( CircuitSchema& circuit_info, Solver* s, TermType type, const std::vector& equal, bool optimizations) { - // TODO(alex): set optimizations to be true once they are confirmed StandardCircuit c1(circuit_info, s, type, "circuit1", optimizations); StandardCircuit c2(circuit_info, s, type, "circuit2", optimizations); diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/circuit/standard_circuit.test.hpp b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/standard_circuit.test.cpp similarity index 100% rename from barretenberg/cpp/src/barretenberg/smt_verification/circuit/standard_circuit.test.hpp rename to barretenberg/cpp/src/barretenberg/smt_verification/circuit/standard_circuit.test.cpp diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/circuit/ultra_circuit.cpp b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/ultra_circuit.cpp new file mode 100644 index 00000000000..c469ead82fc --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/ultra_circuit.cpp @@ -0,0 +1,485 @@ +#include "ultra_circuit.hpp" +#include "barretenberg/common/log.hpp" + +namespace smt_circuit { + +/** + * @brief Construct a new UltraCircuit object + * + * @param circuit_info CircuitShema object + * @param solver pointer to the global solver + * @param tag tag of the circuit. Empty by default. + */ +UltraCircuit::UltraCircuit( + CircuitSchema& circuit_info, Solver* solver, TermType type, const std::string& tag, bool optimizations) + : CircuitBase(circuit_info.vars_of_interest, + circuit_info.variables, + circuit_info.public_inps, + circuit_info.real_variable_index, + circuit_info.real_variable_tags, + circuit_info.range_tags, + solver, + type, + tag, + optimizations) + , selectors(circuit_info.selectors) + , wires_idxs(circuit_info.wires) + , lookup_tables(circuit_info.lookup_tables) +{ + // Perform all relaxations for gates or + // add gate in its normal state to solver + + size_t arith_cursor = 0; + while (arith_cursor < this->selectors[1].size()) { + arith_cursor = this->handle_arithmetic_relation(arith_cursor, 1); + } + + size_t lookup_cursor = 0; + while (lookup_cursor < this->selectors[5].size()) { + lookup_cursor = this->handle_lookup_relation(lookup_cursor, 5); + } + + size_t elliptic_cursor = 0; + while (elliptic_cursor < this->selectors[3].size()) { + elliptic_cursor = this->handle_elliptic_relation(elliptic_cursor, 3); + } + + // size_t delta_range_cursor = 0; + // while(delta_range_cursor < this->selectors[2].size()){ + // delta_range_cursor = this->handle_delta_range_relation(delta_range_cursor, 2); + // } + handle_range_constraints(); + + // TODO(alex): aux +} + +/** + * @brief Adds all the arithmetic gate constraints to the solver. + * Relaxes constraint system for non-ff solver engines + * via removing subcircuits that were already proved being correct. + * + * @param cusor current selector + * @param idx arithmthetic selectors position in all selectors + * @return new cursor value + */ +size_t UltraCircuit::handle_arithmetic_relation(size_t cursor, size_t idx) +{ + bb::fr q_m = this->selectors[idx][cursor][0]; + bb::fr q_l = this->selectors[idx][cursor][1]; + bb::fr q_r = this->selectors[idx][cursor][2]; + bb::fr q_o = this->selectors[idx][cursor][3]; + bb::fr q_4 = this->selectors[idx][cursor][4]; + bb::fr q_c = this->selectors[idx][cursor][5]; + bb::fr q_arith = this->selectors[idx][cursor][6]; + + uint32_t w_l_idx = this->wires_idxs[idx][cursor][0]; + uint32_t w_r_idx = this->wires_idxs[idx][cursor][1]; + uint32_t w_o_idx = this->wires_idxs[idx][cursor][2]; + uint32_t w_4_idx = this->wires_idxs[idx][cursor][3]; + uint32_t w_l_shift_idx = this->wires_idxs[idx][cursor][4]; + uint32_t w_4_shift_idx = this->wires_idxs[idx][cursor][7]; + + STerm w_l = this->symbolic_vars[w_l_idx]; + STerm w_r = this->symbolic_vars[w_r_idx]; + STerm w_o = this->symbolic_vars[w_o_idx]; + STerm w_4 = this->symbolic_vars[w_4_idx]; + STerm w_4_shift = this->symbolic_vars[w_4_shift_idx]; + STerm w_l_shift = this->symbolic_vars[w_l_shift_idx]; + + std::vector boolean_gate = { 1, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0 }; + bool boolean_gate_flag = + (boolean_gate == selectors[1][cursor]) && (w_l_idx == w_r_idx) && (w_o_idx == 0) && (w_4_idx == 0); + if (boolean_gate_flag) { + (Bool(w_l) == Bool(STerm(0, this->solver, this->type)) | Bool(w_l) == Bool(STerm(1, this->solver, this->type))) + .assert_term(); + return cursor + 1; + } + + STerm res = this->symbolic_vars[0]; + static const bb::fr neg_half = bb::fr(-2).invert(); + + if (!q_arith.is_zero()) { + if (q_m != 0) { + res += ((q_arith - 3) * q_m * neg_half) * w_r * w_l; + } + if (q_l != 0) { + res += (q_l * w_l); + } + if (q_r != 0) { + res += (q_r * w_r); + } + if (q_o != 0) { + res += (q_o * w_o); + } + if (q_4 != 0) { + res += (q_4 * w_4); + } + if (q_c != 0) { + res += q_c; + } + if (q_arith != 1) { + res += (q_arith - 1) * w_4_shift; + } + // res *= q_arith; + res == bb::fr::zero(); + + optimized[w_l_idx] = false; + optimized[w_r_idx] = false; + optimized[w_o_idx] = false; + optimized[w_4_idx] = false; + } + + if (q_arith * (q_arith - 1) * (q_arith - 2) != 0) { + res = w_l + w_4 - w_l_shift + q_m; + res == bb::fr::zero(); + optimized[w_l_shift_idx] = false; + } + + return cursor + 1; +} + +/** + * @brief Adds all the lookup gate constraints to the solver. + * Relaxes constraint system for non-ff solver engines + * via removing subcircuits that were already proved being correct. + * + * @param cusor current selector + * @param idx lookup selectors position in all selectors + * @return new cursor value + */ +size_t UltraCircuit::handle_lookup_relation(size_t cursor, size_t idx) +{ + bb::fr q_m = this->selectors[idx][cursor][0]; + bb::fr q_r = this->selectors[idx][cursor][2]; + bb::fr q_o = this->selectors[idx][cursor][3]; + bb::fr q_c = this->selectors[idx][cursor][5]; + bb::fr q_lookup = this->selectors[idx][cursor][10]; + + if (q_lookup.is_zero()) { + return cursor + 1; + } + + uint32_t w_l_idx = this->wires_idxs[idx][cursor][0]; + uint32_t w_r_idx = this->wires_idxs[idx][cursor][1]; + uint32_t w_o_idx = this->wires_idxs[idx][cursor][2]; + uint32_t w_l_shift_idx = this->wires_idxs[idx][cursor][4]; + uint32_t w_r_shift_idx = this->wires_idxs[idx][cursor][5]; + uint32_t w_o_shift_idx = this->wires_idxs[idx][cursor][6]; + + optimized[w_l_idx] = false; + optimized[w_r_idx] = false; + optimized[w_o_idx] = false; + optimized[w_l_shift_idx] = false; + optimized[w_r_shift_idx] = false; + optimized[w_o_shift_idx] = false; + + auto table_idx = static_cast(q_o); + if (!this->cached_symbolic_tables.contains(table_idx)) { + std::vector> new_table; + for (auto table_entry : this->lookup_tables[table_idx]) { + std::vector tmp_entry = { + STerm(table_entry[0], this->solver, this->type), + STerm(table_entry[1], this->solver, this->type), + STerm(table_entry[2], this->solver, this->type), + }; + new_table.push_back(tmp_entry); + } + this->cached_symbolic_tables.insert({ table_idx, this->solver->create_lookup_table(new_table) }); + } + + // Sort of an optimization. + // However if we don't do this, solver will find a unique witness that corresponds to overflowed value. + if (this->type == TermType::BVTerm && q_r == -64 && q_m == -64 && q_c == -64) { + this->symbolic_vars[w_l_shift_idx] = this->symbolic_vars[w_l_idx] >> 6; + this->symbolic_vars[w_r_shift_idx] = this->symbolic_vars[w_r_idx] >> 6; + this->symbolic_vars[w_o_shift_idx] = this->symbolic_vars[w_o_idx] >> 6; + } + + STerm first_entry = this->symbolic_vars[w_l_idx] + q_r * this->symbolic_vars[w_l_shift_idx]; + STerm second_entry = this->symbolic_vars[w_r_idx] + q_m * this->symbolic_vars[w_r_shift_idx]; + STerm third_entry = this->symbolic_vars[w_o_idx] + q_c * this->symbolic_vars[w_o_shift_idx]; + + std::vector entries = { first_entry, second_entry, third_entry }; + STerm::in_table(entries, this->cached_symbolic_tables[table_idx]); + return cursor + 1; +} + +/** + * @brief Adds all the elliptic gate constraints to the solver. + * + * @param cusor current selector + * @param idx elliptic selectors position in all selectors + * @return new cursor value + */ +size_t UltraCircuit::handle_elliptic_relation(size_t cursor, size_t idx) +{ + bb::fr q_is_double = this->selectors[idx][cursor][0]; + bb::fr q_sign = this->selectors[idx][cursor][1]; + bb::fr q_elliptic = this->selectors[idx][cursor][8]; + if (q_elliptic.is_zero()) { + return cursor + 1; + } + + uint32_t w_r_idx = this->wires_idxs[idx][cursor][1]; + uint32_t w_o_idx = this->wires_idxs[idx][cursor][2]; + uint32_t w_l_shift_idx = this->wires_idxs[idx][cursor][4]; + uint32_t w_r_shift_idx = this->wires_idxs[idx][cursor][5]; + uint32_t w_o_shift_idx = this->wires_idxs[idx][cursor][6]; + uint32_t w_4_shift_idx = this->wires_idxs[idx][cursor][7]; + optimized[w_r_idx] = false; + optimized[w_o_idx] = false; + optimized[w_l_shift_idx] = false; + optimized[w_r_shift_idx] = false; + optimized[w_o_shift_idx] = false; + optimized[w_4_shift_idx] = false; + + STerm x_1 = this->symbolic_vars[w_r_idx]; + STerm y_1 = this->symbolic_vars[w_o_idx]; + STerm x_2 = this->symbolic_vars[w_l_shift_idx]; + STerm y_2 = this->symbolic_vars[w_4_shift_idx]; + STerm x_3 = this->symbolic_vars[w_r_shift_idx]; + STerm y_3 = this->symbolic_vars[w_o_shift_idx]; + + auto x_diff = (x_2 - x_1); + auto y2_sqr = (y_2 * y_2); + auto y1_sqr = (y_1 * y_1); + auto y1y2 = y_1 * y_2 * q_sign; + auto x_add_identity = (x_3 + x_2 + x_1) * x_diff * x_diff - y2_sqr - y1_sqr + y1y2 + y1y2; + + auto y1_plus_y3 = y_1 + y_3; + auto y_diff = y_2 * q_sign - y_1; + auto y_add_identity = y1_plus_y3 * x_diff + (x_3 - x_1) * y_diff; + + if (q_is_double.is_zero()) { + x_add_identity == 0; // scaling_factor = 1 + y_add_identity == 0; // scaling_factor = 1 + } + + bb::fr curve_b = this->selectors[3][cursor][11]; + auto x_pow_4 = (y1_sqr - curve_b) * x_1; + auto y1_sqr_mul_4 = y1_sqr + y1_sqr; + y1_sqr_mul_4 += y1_sqr_mul_4; + auto x1_pow_4_mul_9 = x_pow_4 * 9; + auto x_double_identity = (x_3 + x_1 + x_1) * y1_sqr_mul_4 - x1_pow_4_mul_9; + + auto x1_sqr_mul_3 = (x_1 + x_1 + x_1) * x_1; + auto y_double_identity = x1_sqr_mul_3 * (x_1 - x_3) - (y_1 + y_1) * (y_1 + y_3); + + if (!q_is_double.is_zero()) { + x_double_identity == 0; // scaling_factor = 1 + y_double_identity == 0; // scaling_factor = 1 + } + + return cursor + 1; +} + +/** + * @brief Adds all the delta_range gate constraints to the solver. + * + * @param cusor current selector + * @param idx delta_range selectors position in all selectors + * @return new cursor value + * @todo Useless? + */ +size_t UltraCircuit::handle_delta_range_relation(size_t cursor, size_t idx) +{ + bb::fr q_delta_range = this->selectors[idx][cursor][7]; + if (q_delta_range == 0) { + return cursor + 1; + } + + uint32_t w_l_idx = this->wires_idxs[idx][cursor][0]; + uint32_t w_r_idx = this->wires_idxs[idx][cursor][1]; + uint32_t w_o_idx = this->wires_idxs[idx][cursor][2]; + uint32_t w_4_idx = this->wires_idxs[idx][cursor][3]; + uint32_t w_l_shift_idx = this->wires_idxs[idx][cursor][4]; + + STerm w_1 = this->symbolic_vars[w_l_idx]; + STerm w_2 = this->symbolic_vars[w_r_idx]; + STerm w_3 = this->symbolic_vars[w_o_idx]; + STerm w_4 = this->symbolic_vars[w_4_idx]; + STerm w_1_shift = this->symbolic_vars[w_l_shift_idx]; + + STerm delta_1 = w_2 - w_1; + STerm delta_2 = w_3 - w_2; + STerm delta_3 = w_4 - w_3; + STerm delta_4 = w_1_shift - w_4; + + STerm tmp = (delta_1 - 1) * (delta_1 - 1) - 1; + tmp *= (delta_1 - 2) * (delta_1 - 2) - 1; + tmp == 0; + + tmp = (delta_2 - 1) * (delta_2 - 1) - 1; + tmp *= (delta_2 - 2) * (delta_2 - 2) - 1; + tmp == 0; + + tmp = (delta_3 - 1) * (delta_3 - 1) - 1; + tmp *= (delta_3 - 2) * (delta_3 - 2) - 1; + tmp == 0; + + tmp = (delta_4 - 1) * (delta_4 - 1) - 1; + tmp *= (delta_4 - 2) * (delta_4 - 2) - 1; + tmp == 0; + + return cursor + 1; +} + +/** + * @brief Adds all the range constraints to the solver. + * + * @param cusor current selector + * @param idx delta_range selectors position in all selectors + * @return new cursor value + */ +void UltraCircuit::handle_range_constraints() +{ + for (uint32_t i = 0; i < this->get_num_vars(); i++) { + if (i != this->real_variable_index[i] || optimized[i]) { + continue; + } + + uint32_t tag = this->real_variable_tags[this->real_variable_index[i]]; + if (tag != 0 && this->range_tags.contains(tag)) { + uint64_t range = this->range_tags[tag]; + if (this->type == TermType::FFTerm || !this->optimizations) { + if (!this->cached_range_tables.contains(range)) { + std::vector new_range_table; + for (size_t entry = 0; entry < range; entry++) { + new_range_table.push_back(STerm(entry, this->solver, this->type)); + } + this->cached_range_tables.insert({ range, this->solver->create_table(new_range_table) }); + } + + this->symbolic_vars[i].in(this->cached_range_tables[range]); + } else { + this->symbolic_vars[i] <= range; + } + optimized[i] = false; + } + } +} +/** + * @brief Similar functionality to old .check_circuit() method + * in standard circuit builder. + * + * @param witness + * @return true + * @return false + * + * @todo Do we actually need this here? + */ +bool UltraCircuit::simulate_circuit_eval(std::vector& witness) const +{ + if (witness.size() != this->get_num_vars()) { + throw std::invalid_argument("Witness size should be " + std::to_string(this->get_num_vars()) + + + std::to_string(witness.size())); + } + return true; +} + +/** + * @brief Check your circuit for witness uniqueness + * + * @details Creates two Circuit objects that represent the same + * circuit, however you can choose which variables should be (not) equal in both cases, + * and also the variables that should (not) be equal at the same time. + * + * @param circuit_info + * @param s pointer to the global solver + * @param equal The list of names of variables which should be equal in both circuits(each is equal) + * @param not_equal The list of names of variables which should not be equal in both circuits(each is not equal) + * @param equal_at_the_same_time The list of variables, where at least one pair has to be equal + * @param not_equal_at_the_same_time The list of variables, where at least one pair has to be distinct + * @return std::pair + */ +std::pair UltraCircuit::unique_witness_ext( + CircuitSchema& circuit_info, + Solver* s, + TermType type, + const std::vector& equal, + const std::vector& not_equal, + const std::vector& equal_at_the_same_time, + const std::vector& not_equal_at_the_same_time, + bool optimizations) +{ + UltraCircuit c1(circuit_info, s, type, "circuit1", optimizations); + UltraCircuit c2(circuit_info, s, type, "circuit2", optimizations); + + for (const auto& term : equal) { + c1[term] == c2[term]; + } + for (const auto& term : not_equal) { + c1[term] != c2[term]; + } + + std::vector eqs; + for (const auto& term : equal_at_the_same_time) { + Bool tmp = Bool(c1[term]) == Bool(c2[term]); + eqs.push_back(tmp); + } + + if (eqs.size() > 1) { + batch_or(eqs).assert_term(); + } else if (eqs.size() == 1) { + eqs[0].assert_term(); + } + + std::vector neqs; + for (const auto& term : not_equal_at_the_same_time) { + Bool tmp = Bool(c1[term]) != Bool(c2[term]); + neqs.push_back(tmp); + } + + if (neqs.size() > 1) { + batch_or(neqs).assert_term(); + } else if (neqs.size() == 1) { + neqs[0].assert_term(); + } + return { c1, c2 }; +} + +/** + * @brief Check your circuit for witness uniqueness + * + * @details Creates two Circuit objects that represent the same + * circuit, however you can choose which variables should be equal in both cases, + * other witness members will be marked as not equal at the same time + * or basically they will have to differ by at least one element. + * + * @param circuit_info + * @param s pointer to the global solver + * @param equal The list of names of variables which should be equal in both circuits(each is equal) + * @return std::pair + */ +std::pair UltraCircuit::unique_witness( + CircuitSchema& circuit_info, Solver* s, TermType type, const std::vector& equal, bool optimizations) +{ + UltraCircuit c1(circuit_info, s, type, "circuit1", optimizations); + UltraCircuit c2(circuit_info, s, type, "circuit2", optimizations); + + for (const auto& term : equal) { + c1[term] == c2[term]; + } + + std::vector neqs; + for (const auto& node : c1.symbolic_vars) { + uint32_t i = node.first; + if (std::find(equal.begin(), equal.end(), std::string(c1.variable_names[i])) != equal.end()) { + continue; + } + if (c1.optimized[i]) { + continue; + } + Bool tmp = Bool(c1[i]) != Bool(c2[i]); + neqs.push_back(tmp); + } + + if (neqs.size() > 1) { + batch_or(neqs).assert_term(); + } else if (neqs.size() == 1) { + neqs[0].assert_term(); + } + return { c1, c2 }; +} +}; // namespace smt_circuit \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/circuit/ultra_circuit.hpp b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/ultra_circuit.hpp new file mode 100644 index 00000000000..c6ec07a849e --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/ultra_circuit.hpp @@ -0,0 +1,67 @@ +#pragma once +#include "circuit_base.hpp" + +namespace smt_circuit { + +/** + * @brief Symbolic Circuit class for Standard Circuit Builder. + * + * @details Contains all the information about the circuit: gates, variables, + * symbolic variables, specified names and global solver. + */ +class UltraCircuit : public CircuitBase { + public: + // TODO(alex): check that there's no actual pub_inputs block + std::vector>> selectors; // all selectors from the circuit + // 1st entry are arithmetic selectors + // 2nd entry are delta_range selectors + // 3rd entry are elliptic selectors + // 4th entry are aux selectors + // 5th entry are lookup selectors + std::vector>> wires_idxs; // values of the gates' wires idxs + + std::vector>> lookup_tables; + std::unordered_map cached_symbolic_tables; + std::unordered_map cached_range_tables; + + explicit UltraCircuit(CircuitSchema& circuit_info, + Solver* solver, + TermType type = TermType::FFTerm, + const std::string& tag = "", + bool optimizations = true); + UltraCircuit(const UltraCircuit& other) = default; + UltraCircuit(UltraCircuit&& other) = default; + UltraCircuit& operator=(const UltraCircuit& other) = default; + UltraCircuit& operator=(UltraCircuit&& other) = default; + ~UltraCircuit() override = default; + + inline size_t get_num_gates() const + { + return selectors[0].size() + selectors[1].size() + selectors[2].size() + selectors[3].size() + + selectors[4].size() + selectors[5].size(); + }; + + bool simulate_circuit_eval(std::vector& witness) const override; + + size_t handle_arithmetic_relation(size_t cursor, size_t idx); + size_t handle_lookup_relation(size_t cursor, size_t idx); + size_t handle_elliptic_relation(size_t cursor, size_t idx); + size_t handle_delta_range_relation(size_t cursor, size_t idx); + void handle_range_constraints(); + + static std::pair unique_witness_ext( + CircuitSchema& circuit_info, + Solver* s, + TermType type, + const std::vector& equal = {}, + const std::vector& not_equal = {}, + const std::vector& equal_at_the_same_time = {}, + const std::vector& not_equal_at_the_same_time = {}, + bool optimizations = false); + static std::pair unique_witness(CircuitSchema& circuit_info, + Solver* s, + TermType type, + const std::vector& equal = {}, + bool optimizations = false); +}; +}; // namespace smt_circuit \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/circuit/ultra_circuit.test.cpp b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/ultra_circuit.test.cpp new file mode 100644 index 00000000000..bdff9b10774 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/smt_verification/circuit/ultra_circuit.test.cpp @@ -0,0 +1,242 @@ +#include +#include +#include + +#include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" + +#include "barretenberg/crypto/pedersen_commitment/pedersen.hpp" +#include "barretenberg/stdlib/primitives/field/field.hpp" +#include "barretenberg/stdlib/primitives/uint/uint.hpp" + +#include "barretenberg/smt_verification/circuit/ultra_circuit.hpp" +#include "barretenberg/smt_verification/util/smt_util.hpp" + +#include + +using namespace bb; +using namespace smt_circuit; + +namespace { +auto& engine = numeric::get_debug_randomness(); +} + +using field_t = stdlib::field_t; +using witness_t = stdlib::witness_t; +using pub_witness_t = stdlib::public_witness_t; +using uint_t = stdlib::uint32; + +TEST(ultra_circuit, assert_equal) +{ + auto builder = UltraCircuitBuilder(); + + field_t a(witness_t(&builder, fr::random_element())); + field_t b(witness_t(&builder, fr::random_element())); + builder.set_variable_name(a.witness_index, "a"); + builder.set_variable_name(b.witness_index, "b"); + field_t c = (a + a) / (b + b + b); + builder.set_variable_name(c.witness_index, "c"); + + field_t d(witness_t(&builder, a.get_value())); + field_t e(witness_t(&builder, b.get_value())); + field_t f(witness_t(&builder, c.get_value())); + builder.assert_equal(d.get_witness_index(), a.get_witness_index()); + builder.assert_equal(e.get_witness_index(), b.get_witness_index()); + + field_t g = d + d; + field_t h = e + e + e; + field_t i = g / h; + builder.assert_equal(i.get_witness_index(), c.get_witness_index()); + field_t j(witness_t(&builder, i.get_value())); + field_t k(witness_t(&builder, j.get_value())); + builder.assert_equal(i.get_witness_index(), j.get_witness_index()); + builder.assert_equal(i.get_witness_index(), k.get_witness_index()); + + auto buf = builder.export_circuit(); + CircuitSchema circuit_info = unpack_from_buffer(buf); + Solver s(circuit_info.modulus, ultra_solver_config); + UltraCircuit circuit(circuit_info, &s, TermType::FFTerm); + + ASSERT_EQ(circuit[k.get_witness_index()].term, circuit["c"].term); + ASSERT_EQ(circuit[d.get_witness_index()].term, circuit["a"].term); + ASSERT_EQ(circuit[e.get_witness_index()].term, circuit["b"].term); + + ASSERT_EQ(circuit[i.get_witness_index()].term, circuit[k.get_witness_index()].term); + ASSERT_EQ(circuit[i.get_witness_index()].term, circuit[j.get_witness_index()].term); +} + +TEST(ultra_circuit, arithmetic) +{ + UltraCircuitBuilder builder; + + field_t a(witness_t(&builder, fr::random_element())); + field_t b(witness_t(&builder, fr::random_element())); + field_t c = a * a * b / (a + b * 3) - b / a; + + builder.set_variable_name(a.get_witness_index(), "a"); + builder.set_variable_name(b.get_witness_index(), "b"); + builder.set_variable_name(c.get_witness_index(), "c"); + + auto circuit_info = unpack_from_buffer(builder.export_circuit()); + Solver s(circuit_info.modulus, ultra_solver_config); + UltraCircuit cir(circuit_info, &s); + ASSERT_EQ(cir.get_num_gates(), builder.get_num_gates()); + + cir["a"] == a.get_value(); + cir["b"] == b.get_value(); + + bool res = s.check(); + ASSERT_TRUE(res); + + std::string c_solver_val = s.getValue(cir["c"]).getFiniteFieldValue(); + std::string c_builder_val = STerm(c.get_value(), &s, TermType::FFTerm).term.getFiniteFieldValue(); + ASSERT_EQ(c_solver_val, c_builder_val); +} + +TEST(ultra_circuit, elliptic_add) +{ + UltraCircuitBuilder builder; + + bb::grumpkin::g1::affine_element p1 = bb::crypto::pedersen_commitment::commit_native({ bb::fr::one() }, 0); + bb::grumpkin::g1::affine_element p2 = bb::crypto::pedersen_commitment::commit_native({ bb::fr::one() }, 1); + bb::grumpkin::g1::affine_element p3 = bb::grumpkin::g1::element(p1) + bb::grumpkin::g1::element(p2); + + uint32_t x1 = builder.add_variable(p1.x); + uint32_t y1 = builder.add_variable(p1.y); + uint32_t x2 = builder.add_variable(p2.x); + uint32_t y2 = builder.add_variable(p2.y); + uint32_t x3 = builder.add_variable(p3.x); + uint32_t y3 = builder.add_variable(p3.y); + + builder.set_variable_name(x1, "x1"); + builder.set_variable_name(x2, "x2"); + builder.set_variable_name(x3, "x3"); + builder.set_variable_name(y1, "y1"); + builder.set_variable_name(y2, "y2"); + builder.set_variable_name(y3, "y3"); + + builder.create_ecc_add_gate({ x1, y1, x2, y2, x3, y3, 1 }); + + auto circuit_info = unpack_from_buffer(builder.export_circuit()); + Solver s(circuit_info.modulus, ultra_solver_config); + UltraCircuit cir(circuit_info, &s); + ASSERT_EQ(cir.get_num_gates(), builder.get_num_gates()); + + cir["x1"] == builder.get_variable(x1); + cir["x2"] == builder.get_variable(x2); + cir["y1"] == builder.get_variable(y1); + cir["y2"] == builder.get_variable(y2); + + bool res = s.check(); + ASSERT_TRUE(res); + + std::string x3_solver_val = s.getValue(cir["x3"]).getFiniteFieldValue(); + std::string y3_solver_val = s.getValue(cir["y3"]).getFiniteFieldValue(); + + std::string x3_builder_val = STerm(builder.get_variable(x3), &s, TermType::FFTerm).term.getFiniteFieldValue(); + std::string y3_builder_val = STerm(builder.get_variable(y3), &s, TermType::FFTerm).term.getFiniteFieldValue(); + + ASSERT_EQ(x3_solver_val, x3_builder_val); + ASSERT_EQ(y3_solver_val, y3_builder_val); + + ((Bool(cir["x3"]) != Bool(STerm(builder.get_variable(x3), &s, TermType::FFTerm))) | + (Bool(cir["y3"]) != Bool(STerm(builder.get_variable(y3), &s, TermType::FFTerm)))) + .assert_term(); + res = s.check(); + ASSERT_FALSE(res); +} + +TEST(ultra_circuit, elliptic_dbl) +{ + UltraCircuitBuilder builder; + + bb::grumpkin::g1::affine_element p1 = bb::crypto::pedersen_commitment::commit_native({ bb::fr::one() }, 0); + bb::grumpkin::g1::affine_element p3 = bb::grumpkin::g1::element(p1).dbl(); + + uint32_t x1 = builder.add_variable(p1.x); + uint32_t y1 = builder.add_variable(p1.y); + uint32_t x3 = builder.add_variable(p3.x); + uint32_t y3 = builder.add_variable(p3.y); + builder.set_variable_name(x1, "x1"); + builder.set_variable_name(x3, "x3"); + builder.set_variable_name(y1, "y1"); + builder.set_variable_name(y3, "y3"); + + builder.create_ecc_dbl_gate({ x1, y1, x3, y3 }); + + auto circuit_info = unpack_from_buffer(builder.export_circuit()); + Solver s(circuit_info.modulus, ultra_solver_config); + UltraCircuit cir(circuit_info, &s); + ASSERT_EQ(cir.get_num_gates(), builder.get_num_gates()); + + cir["x1"] == builder.get_variable(x1); + cir["y1"] == builder.get_variable(y1); + + bool res = s.check(); + ASSERT_TRUE(res); + + std::string x3_solver_val = s.getValue(cir["x3"]).getFiniteFieldValue(); + std::string y3_solver_val = s.getValue(cir["y3"]).getFiniteFieldValue(); + + std::string x3_builder_val = STerm(builder.get_variable(x3), &s, TermType::FFTerm).term.getFiniteFieldValue(); + std::string y3_builder_val = STerm(builder.get_variable(y3), &s, TermType::FFTerm).term.getFiniteFieldValue(); + + ASSERT_EQ(x3_solver_val, x3_builder_val); + ASSERT_EQ(y3_solver_val, y3_builder_val); + + ((Bool(cir["x3"]) != Bool(STerm(builder.get_variable(x3), &s, TermType::FFTerm))) | + (Bool(cir["y3"]) != Bool(STerm(builder.get_variable(y3), &s, TermType::FFTerm)))) + .assert_term(); + res = s.check(); + ASSERT_FALSE(res); +} + +TEST(ultra_circuit, ranges) +{ + UltraCircuitBuilder builder; + + uint_t a(witness_t(&builder, static_cast(bb::fr::random_element()))); + builder.set_variable_name(a.get_witness_index(), "a"); + builder.finalize_circuit(); + + auto circuit_info = unpack_from_buffer(builder.export_circuit()); + Solver s(circuit_info.modulus, ultra_solver_config); + UltraCircuit cir(circuit_info, &s, TermType::BVTerm); + ASSERT_EQ(cir.get_num_gates(), builder.get_num_gates()); + + cir["a"] == a.get_value(); + s.print_assertions(); + + bool res = s.check(); + ASSERT_TRUE(res); +} + +TEST(ultra_circuit, lookup_tables) +{ + UltraCircuitBuilder builder; + + uint_t a(witness_t(&builder, static_cast(bb::fr::random_element()))); + uint_t b(witness_t(&builder, static_cast(bb::fr::random_element()))); + uint_t c = a ^ b; + builder.set_variable_name(a.get_witness_index(), "a"); + builder.set_variable_name(b.get_witness_index(), "b"); + builder.set_variable_name(c.get_witness_index(), "c"); + builder.finalize_circuit(); + + auto circuit_info = unpack_from_buffer(builder.export_circuit()); + uint32_t modulus_base = 16; + uint32_t bvsize = 32; + Solver s(circuit_info.modulus, ultra_solver_config, modulus_base, bvsize); + UltraCircuit cir(circuit_info, &s, TermType::BVTerm); + ASSERT_EQ(cir.get_num_gates(), builder.get_num_gates()); + + cir["a"] == a.get_value(); + cir["b"] == b.get_value(); + s.print_assertions(); + + bool res = s.check(); + ASSERT_TRUE(res); + + std::string c_solver_val = s.getValue(cir["c"]).getBitVectorValue(); + std::string c_builder_val = STerm(c.get_value(), &s, TermType::BVTerm).term.getBitVectorValue(); + ASSERT_EQ(c_solver_val, c_builder_val); +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/smt_examples.test.cpp b/barretenberg/cpp/src/barretenberg/smt_verification/smt_examples.test.cpp index ccca774985b..89a10ab5363 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/smt_examples.test.cpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/smt_examples.test.cpp @@ -34,9 +34,9 @@ TEST(SMT_Example, multiplication_true) auto buf = builder.export_circuit(); - smt_circuit::CircuitSchema circuit_info = smt_circuit::unpack_from_buffer(buf); + smt_circuit::CircuitSchema circuit_info = smt_circuit_schema::unpack_from_buffer(buf); smt_solver::Solver s(circuit_info.modulus); - smt_circuit::Circuit circuit(circuit_info, &s, smt_terms::TermType::FFTerm); + smt_circuit::StandardCircuit circuit(circuit_info, &s, smt_terms::TermType::FFTerm); smt_terms::STerm a1 = circuit["a"]; smt_terms::STerm b1 = circuit["b"]; smt_terms::STerm c1 = circuit["c"]; @@ -65,9 +65,9 @@ TEST(SMT_Example, multiplication_true_kind) auto buf = builder.export_circuit(); - smt_circuit::CircuitSchema circuit_info = smt_circuit::unpack_from_buffer(buf); + smt_circuit::CircuitSchema circuit_info = smt_circuit_schema::unpack_from_buffer(buf); smt_solver::Solver s(circuit_info.modulus); - smt_circuit::Circuit circuit(circuit_info, &s, smt_terms::TermType::FFTerm); + smt_circuit::StandardCircuit circuit(circuit_info, &s, smt_terms::TermType::FFTerm); smt_terms::STerm a1 = circuit["a"]; smt_terms::STerm b1 = circuit["b"]; smt_terms::STerm c1 = circuit["c"]; @@ -96,9 +96,9 @@ TEST(SMT_Example, multiplication_false) auto buf = builder.export_circuit(); - smt_circuit::CircuitSchema circuit_info = smt_circuit::unpack_from_buffer(buf); + smt_circuit::CircuitSchema circuit_info = smt_circuit_schema::unpack_from_buffer(buf); smt_solver::Solver s(circuit_info.modulus); - smt_circuit::Circuit circuit(circuit_info, &s, smt_terms::TermType::FFTerm); + smt_circuit::StandardCircuit circuit(circuit_info, &s, smt_terms::TermType::FFTerm); smt_terms::STerm a1 = circuit["a"]; smt_terms::STerm b1 = circuit["b"]; @@ -141,11 +141,12 @@ TEST(SMT_Example, unique_witness_ext) auto buf = builder.export_circuit(); - smt_circuit::CircuitSchema circuit_info = smt_circuit::unpack_from_buffer(buf); + smt_circuit::CircuitSchema circuit_info = smt_circuit_schema::unpack_from_buffer(buf); smt_solver::Solver s(circuit_info.modulus); - std::pair cirs = - smt_circuit::unique_witness_ext(circuit_info, &s, smt_terms::TermType::FFTerm, { "ev" }, { "z" }); + std::pair cirs = + smt_circuit::StandardCircuit::unique_witness_ext( + circuit_info, &s, smt_terms::TermType::FFTerm, { "ev" }, { "z" }); bool res = s.check(); ASSERT_TRUE(res); @@ -173,11 +174,11 @@ TEST(SMT_Example, unique_witness) auto buf = builder.export_circuit(); - smt_circuit::CircuitSchema circuit_info = smt_circuit::unpack_from_buffer(buf); + smt_circuit::CircuitSchema circuit_info = smt_circuit_schema::unpack_from_buffer(buf); smt_solver::Solver s(circuit_info.modulus); - std::pair cirs = - smt_circuit::unique_witness(circuit_info, &s, smt_terms::TermType::FFTerm, { "ev" }); + std::pair cirs = + smt_circuit::StandardCircuit::unique_witness(circuit_info, &s, smt_terms::TermType::FFTerm, { "ev" }); bool res = s.check(); ASSERT_TRUE(res); @@ -185,4 +186,4 @@ TEST(SMT_Example, unique_witness) std::unordered_map terms = { { "z_c1", cirs.first["z"] }, { "z_c2", cirs.second["z"] } }; std::unordered_map vals = s.model(terms); ASSERT_NE(vals["z_c1"], vals["z_c2"]); -} +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/smt_polynomials.test.cpp b/barretenberg/cpp/src/barretenberg/smt_verification/smt_polynomials.test.cpp index f3d9582a13b..f8e74061d44 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/smt_polynomials.test.cpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/smt_polynomials.test.cpp @@ -8,7 +8,7 @@ #include "barretenberg/stdlib/primitives/field/field.hpp" #include "barretenberg/stdlib_circuit_builders/standard_circuit_builder.hpp" -#include "barretenberg/smt_verification/circuit/circuit.hpp" +#include "barretenberg/smt_verification/circuit/standard_circuit.hpp" #include "barretenberg/smt_verification/util/smt_util.hpp" using namespace bb; @@ -54,7 +54,7 @@ msgpack::sbuffer create_polynomial_evaluation_circuit(size_t n, bool pub_coeffs) return builder.export_circuit(); } -STerm direct_polynomial_evaluation(Circuit& c, size_t n) +STerm direct_polynomial_evaluation(StandardCircuit& c, size_t n) { STerm point = c["point"]; STerm result = c["result"]; @@ -65,7 +65,7 @@ STerm direct_polynomial_evaluation(Circuit& c, size_t n) return ev; } -void model_variables(Circuit& c, Solver* s, STerm& evaluation) +void model_variables(StandardCircuit& c, Solver* s, STerm& evaluation) { std::unordered_map terms; terms.insert({ "point", c["point"] }); @@ -86,11 +86,11 @@ TEST(polynomial_evaluation, public) CircuitSchema circuit_info = unpack_from_buffer(buf); Solver s(circuit_info.modulus); - Circuit circuit(circuit_info, &s, TermType::FFTerm); + StandardCircuit circuit(circuit_info, &s, TermType::FFTerm); STerm ev = direct_polynomial_evaluation(circuit, n); ev != circuit["result"]; - bool res = smt_timer(&s, false); + bool res = smt_timer(&s); ASSERT_FALSE(res); } @@ -101,11 +101,11 @@ TEST(polynomial_evaluation, private) CircuitSchema circuit_info = unpack_from_buffer(buf); Solver s(circuit_info.modulus); - Circuit circuit(circuit_info, &s, TermType::FFTerm); + StandardCircuit circuit(circuit_info, &s, TermType::FFTerm); STerm ev = direct_polynomial_evaluation(circuit, n); ev != circuit["result"]; - bool res = smt_timer(&s, false); + bool res = smt_timer(&s); ASSERT_FALSE(res); info("Gates: ", circuit.get_num_gates()); info("Result: ", s.getResult()); diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/solver/solver.cpp b/barretenberg/cpp/src/barretenberg/smt_verification/solver/solver.cpp index 093b237b750..acd855ad69d 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/solver/solver.cpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/solver/solver.cpp @@ -105,7 +105,7 @@ std::unordered_map Solver::model(std::vector bool_res = { "false", "true" }; return bool_res[static_cast(term.getBooleanValue())]; } + // handling tuples + if (term.getKind() == cvc5::Kind::APPLY_CONSTRUCTOR) { + std::string res = "("; + for (const auto& t : term) { + res += stringify_term(t) + ", "; + } + return res + ")"; + } + if (term.getKind() == cvc5::Kind::INTERNAL_KIND) { + return ""; + } + if (term.getKind() == cvc5::Kind::SET_INSERT) { + return "set_" + std::to_string(this->tables[term]); + } + if (term.getKind() == cvc5::Kind::SET_EMPTY) { + return "{}"; + } std::string res; std::string op; @@ -184,11 +201,9 @@ std::string stringify_term(const cvc5::Term& term, bool parenthesis) op = " & "; break; case cvc5::Kind::BITVECTOR_SHL: - back = true; op = " << "; break; case cvc5::Kind::BITVECTOR_LSHR: - back = true; op = " >> "; break; case cvc5::Kind::BITVECTOR_ROTATE_LEFT: @@ -209,8 +224,13 @@ std::string stringify_term(const cvc5::Term& term, bool parenthesis) op = " % "; parenthesis = true; break; + case cvc5::Kind::SET_MEMBER: + op = " in "; + parenthesis = true; + break; default: info("Invalid operand :", term.getKind()); + info(term); break; } @@ -239,33 +259,51 @@ std::string stringify_term(const cvc5::Term& term, bool parenthesis) * Output assertions in human readable format. * * */ -void Solver::print_assertions() const +void Solver::print_assertions() { for (const auto& t : this->solver.getAssertions()) { - info(stringify_term(t)); + info(this->stringify_term(t)); } } cvc5::Term Solver::create_lookup_table(std::vector>& table) { - if (!lookup_enabled) { - this->solver.setLogic("ALL"); - this->solver.setOption("finite-model-find", "true"); - this->solver.setOption("sets-ext", "true"); - lookup_enabled = true; - } - cvc5::Term tmp = table[0][0]; cvc5::Sort tuple_sort = this->term_manager.mkTupleSort({ tmp.getSort(), tmp.getSort(), tmp.getSort() }); cvc5::Sort relation = this->term_manager.mkSetSort(tuple_sort); cvc5::Term resulting_table = this->term_manager.mkEmptySet(relation); std::vector children; + children.reserve(table.size() + 1); for (auto& table_entry : table) { cvc5::Term entry = this->term_manager.mkTuple(table_entry); children.push_back(entry); } children.push_back(resulting_table); - return this->term_manager.mkTerm(cvc5::Kind::SET_INSERT, children); + cvc5::Term res = this->term_manager.mkTerm(cvc5::Kind::SET_INSERT, children); + size_t cursize = this->tables.size(); + info("Creating table for op: ", children.size(), ", № ", cursize); + this->tables.insert({ res, cursize }); + return res; +} + +cvc5::Term Solver::create_table(std::vector& table) +{ + cvc5::Term tmp = table[0]; + cvc5::Sort relation = this->term_manager.mkSetSort(tmp.getSort()); + cvc5::Term resulting_table = this->term_manager.mkEmptySet(relation); + + std::vector children; + children.reserve(table.size() + 1); + for (auto& table_entry : table) { + children.push_back(table_entry); + } + children.push_back(resulting_table); + cvc5::Term res = this->term_manager.mkTerm(cvc5::Kind::SET_INSERT, children); + size_t cursize = this->tables.size(); + info("Creating table for range: ", children.size(), ", № ", cursize); + + this->tables.insert({ res, cursize }); + return res; } }; // namespace smt_solver diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/solver/solver.hpp b/barretenberg/cpp/src/barretenberg/smt_verification/solver/solver.hpp index 0151c1bb857..e6720e95c99 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/solver/solver.hpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/solver/solver.hpp @@ -14,8 +14,10 @@ namespace smt_solver { * @param timeout tells solver to stop trying after `timeout` msecs. * @param debug set verbosity of cvc5: 0, 1, 2. * - * @param ff_disjunctive_bit tells solver to change all ((x = 0) | (x = 1)) to x*x = x. + * @param ff_elim_disjunctive_bit tells solver to change all ((x = 0) | (x = 1)) to x*x = x. * @param ff_solver tells solver which finite field solver to use: "gb", "split". + * + * @param lookup_enabled tells solver to enable sets when we deal with lookups */ struct SolverConfiguration { bool produce_models; @@ -24,9 +26,12 @@ struct SolverConfiguration { bool ff_elim_disjunctive_bit; std::string ff_solver; + + bool lookup_enabled; }; -const SolverConfiguration default_solver_config = { true, 0, 0, false, "" }; +const SolverConfiguration default_solver_config = { true, 0, 0, false, "", false }; +const SolverConfiguration ultra_solver_config = { true, 0, 0, false, "", true }; /** * @brief Class for the solver. @@ -46,6 +51,8 @@ class Solver { cvc5::Result cvc_result; bool checked = false; + std::unordered_map tables; + explicit Solver(const std::string& modulus, const SolverConfiguration& config = default_solver_config, uint32_t base = 16, @@ -88,6 +95,13 @@ class Solver { solver.setOption("ff-solver", config.ff_solver); } + if (lookup_enabled) { + this->solver.setLogic("ALL"); + this->solver.setOption("finite-model-find", "true"); + this->solver.setOption("sets-ext", "true"); + lookup_enabled = true; + } + solver.setOption("output", "incomplete"); } @@ -99,6 +113,7 @@ class Solver { bool lookup_enabled = false; cvc5::Term create_lookup_table(std::vector>& table); + cvc5::Term create_table(std::vector& table); void assertFormula(const cvc5::Term& term) const { this->solver.assertFormula(term); } @@ -117,11 +132,10 @@ class Solver { std::unordered_map model(std::unordered_map& terms) const; std::unordered_map model(std::vector& terms) const; - void print_assertions() const; + void print_assertions(); + std::string stringify_term(const cvc5::Term& term, bool parenthesis = false); ~Solver() = default; }; -std::string stringify_term(const cvc5::Term& term, bool parenthesis = false); - }; // namespace smt_solver diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/terms/bvterm.test.cpp b/barretenberg/cpp/src/barretenberg/smt_verification/terms/bvterm.test.cpp index ad76add64ad..05d942cdcad 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/terms/bvterm.test.cpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/terms/bvterm.test.cpp @@ -242,11 +242,12 @@ TEST(BVTerm, or) ASSERT_EQ(bvals, xvals); } -TEST(BVTerm, shr) +TEST(BVTerm, div) { StandardCircuitBuilder builder; uint_ct a = witness_ct(&builder, static_cast(fr::random_element())); - uint_ct b = a >> 5; + uint_ct b = witness_ct(&builder, static_cast(fr::random_element())); + uint_ct c = a / b; uint32_t modulus_base = 16; uint32_t bitvector_size = 32; @@ -256,23 +257,25 @@ TEST(BVTerm, shr) bitvector_size); STerm x = BVVar("x", &s); - STerm y = x >> 5; + STerm y = BVVar("y", &s); + STerm z = x / y; x == a.get_value(); + y == b.get_value(); ASSERT_TRUE(s.check()); - std::string xvals = s.getValue(y.term).getBitVectorValue(); - STerm bval = STerm(b.get_value(), &s, TermType::BVTerm); + std::string xvals = s.getValue(z.term).getBitVectorValue(); + STerm bval = STerm(c.get_value(), &s, TermType::BVTerm); std::string bvals = s.getValue(bval.term).getBitVectorValue(); ASSERT_EQ(bvals, xvals); } -TEST(BVTerm, shl) +TEST(BVTerm, shr) { StandardCircuitBuilder builder; uint_ct a = witness_ct(&builder, static_cast(fr::random_element())); - uint_ct b = a << 5; + uint_ct b = a >> 5; uint32_t modulus_base = 16; uint32_t bitvector_size = 32; @@ -282,7 +285,7 @@ TEST(BVTerm, shl) bitvector_size); STerm x = BVVar("x", &s); - STerm y = x << 5; + STerm y = x >> 5; x == a.get_value(); @@ -294,11 +297,11 @@ TEST(BVTerm, shl) ASSERT_EQ(bvals, xvals); } -// This test aims to check for the absence of unintended -// behavior. If an unsupported operator is called, an info message appears in stderr -// and the value is supposed to remain unchanged. -TEST(BVTerm, unsupported_operations) +TEST(BVTerm, shl) { + StandardCircuitBuilder builder; + uint_ct a = witness_ct(&builder, static_cast(fr::random_element())); + uint_ct b = a << 5; uint32_t modulus_base = 16; uint32_t bitvector_size = 32; @@ -308,8 +311,14 @@ TEST(BVTerm, unsupported_operations) bitvector_size); STerm x = BVVar("x", &s); - STerm y = BVVar("y", &s); + STerm y = x << 5; - STerm z = x / y; - ASSERT_EQ(z.term, x.term); + x == a.get_value(); + + ASSERT_TRUE(s.check()); + + std::string xvals = s.getValue(y.term).getBitVectorValue(); + STerm bval = STerm(b.get_value(), &s, TermType::BVTerm); + std::string bvals = s.getValue(bval.term).getBitVectorValue(); + ASSERT_EQ(bvals, xvals); } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/terms/iterm.test.cpp b/barretenberg/cpp/src/barretenberg/smt_verification/terms/iterm.test.cpp new file mode 100644 index 00000000000..d86081a24bc --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/smt_verification/terms/iterm.test.cpp @@ -0,0 +1,149 @@ +#include + +#include "barretenberg/stdlib/primitives/uint/uint.hpp" +#include "term.hpp" + +#include + +namespace { +auto& engine = bb::numeric::get_debug_randomness(); +} + +using namespace bb; +using witness_ct = stdlib::witness_t; + +using namespace smt_terms; + +TEST(ITerm, addition) +{ + StandardCircuitBuilder builder; + uint64_t a = static_cast(fr::random_element()) % (static_cast(1) << 31); + uint64_t b = static_cast(fr::random_element()) % (static_cast(1) << 31); + uint64_t c = a + b; + + Solver s("30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001", default_solver_config); + + STerm x = IVar("x", &s); + STerm y = IVar("y", &s); + STerm z = x + y; + + z == c; + x == a; + ASSERT_TRUE(s.check()); + + std::string yvals = s.getValue(y.term).getIntegerValue(); + + STerm bval = STerm(b, &s, TermType::ITerm); + std::string bvals = s.getValue(bval.term).getIntegerValue(); + ASSERT_EQ(bvals, yvals); +} + +TEST(ITerm, subtraction) +{ + StandardCircuitBuilder builder; + uint64_t c = static_cast(fr::random_element()) % (static_cast(1) << 31); + uint64_t b = static_cast(fr::random_element()) % (static_cast(1) << 31); + uint64_t a = c + b; + + Solver s("30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001", default_solver_config); + + STerm x = IVar("x", &s); + STerm y = IVar("y", &s); + STerm z = x - y; + + x == a; + z == c; + ASSERT_TRUE(s.check()); + + std::string yvals = s.getValue(y.term).getIntegerValue(); + + STerm bval = STerm(b, &s, TermType::ITerm); + std::string bvals = s.getValue(bval.term).getIntegerValue(); + ASSERT_EQ(bvals, yvals); +} + +TEST(ITerm, mul) +{ + StandardCircuitBuilder builder; + uint64_t a = static_cast(fr::random_element()) % (static_cast(1) << 31); + uint64_t b = static_cast(fr::random_element()) % (static_cast(1) << 31); + uint64_t c = a * b; + + Solver s("30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001", default_solver_config); + + STerm x = IVar("x", &s); + STerm y = IVar("y", &s); + STerm z = x * y; + + x == a; + y == b; + + ASSERT_TRUE(s.check()); + + std::string xvals = s.getValue(z.term).getIntegerValue(); + STerm bval = STerm(c, &s, TermType::ITerm); + std::string bvals = s.getValue(bval.term).getIntegerValue(); + ASSERT_EQ(bvals, xvals); +} + +TEST(ITerm, div) +{ + StandardCircuitBuilder builder; + uint64_t a = static_cast(fr::random_element()) % (static_cast(1) << 31); + uint64_t b = static_cast(fr::random_element()) % (static_cast(1) << 31) + 1; + uint64_t c = a / b; + + Solver s("30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001", default_solver_config); + + STerm x = IVar("x", &s); + STerm y = IVar("y", &s); + STerm z = x / y; + + x == a; + y == b; + + ASSERT_TRUE(s.check()); + + std::string xvals = s.getValue(z.term).getIntegerValue(); + STerm bval = STerm(c, &s, TermType::ITerm); + std::string bvals = s.getValue(bval.term).getIntegerValue(); + ASSERT_EQ(bvals, xvals); +} + +// This test aims to check for the absence of unintended +// behavior. If an unsupported operator is called, an info message appears in stderr +// and the value is supposed to remain unchanged. +TEST(ITerm, unsupported_operations) +{ + Solver s("30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001"); + + STerm x = IVar("x", &s); + STerm y = IVar("y", &s); + + STerm z = x ^ y; + ASSERT_EQ(z.term, x.term); + z = x & y; + ASSERT_EQ(z.term, x.term); + z = x | y; + ASSERT_EQ(z.term, x.term); + z = x >> 10; + ASSERT_EQ(z.term, x.term); + z = x << 10; + ASSERT_EQ(z.term, x.term); + z = x.rotr(10); + ASSERT_EQ(z.term, x.term); + z = x.rotl(10); + ASSERT_EQ(z.term, x.term); + + cvc5::Term before_term = x.term; + x ^= y; + ASSERT_EQ(x.term, before_term); + x &= y; + ASSERT_EQ(x.term, before_term); + x |= y; + ASSERT_EQ(x.term, before_term); + x >>= 10; + ASSERT_EQ(x.term, before_term); + x <<= 10; + ASSERT_EQ(x.term, before_term); +} \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/terms/term.cpp b/barretenberg/cpp/src/barretenberg/smt_verification/terms/term.cpp index 7ab111cb86c..1207ab29142 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/terms/term.cpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/terms/term.cpp @@ -54,6 +54,9 @@ STerm::STerm(const std::string& t, Solver* slv, bool isconst, uint32_t base, Ter slv->assertFormula(ge); slv->assertFormula(lt); break; + case TermType::ITerm: + this->term = slv->term_manager.mkConst(slv->term_manager.getIntegerSort(), t); + break; case TermType::BVTerm: this->term = slv->term_manager.mkConst(slv->bv_sort, t); break; @@ -68,7 +71,11 @@ STerm::STerm(const std::string& t, Solver* slv, bool isconst, uint32_t base, Ter // TODO(alex): CVC5 doesn't provide integer initialization from hex. Yet. strvalue = slv->term_manager.mkFiniteFieldElem(t, slv->ff_sort, base).getFiniteFieldValue(); this->term = slv->term_manager.mkInteger(strvalue); - this->mod(); + this->term = this->mod().term; + break; + case TermType::ITerm: + strvalue = slv->term_manager.mkFiniteFieldElem(t, slv->ff_sort, base).getFiniteFieldValue(); + this->term = slv->term_manager.mkInteger(strvalue); break; case TermType::BVTerm: // it's better to have (-p/2, p/2) representation due to overflows @@ -79,12 +86,15 @@ STerm::STerm(const std::string& t, Solver* slv, bool isconst, uint32_t base, Ter } } -void STerm::mod() +STerm STerm::mod() const { - if (this->type == TermType::FFITerm) { - cvc5::Term modulus = this->solver->term_manager.mkInteger(solver->modulus); - this->term = this->solver->term_manager.mkTerm(this->operations.at(OpType::MOD), { this->term, modulus }); + if (!this->operations.contains(OpType::MOD)) { + info("Taking a remainder is not compatible with ", this->type); + return *this; } + cvc5::Term modulus = this->solver->term_manager.mkInteger(solver->modulus); + cvc5::Term res_s = this->solver->term_manager.mkTerm(this->operations.at(OpType::MOD), { this->term, modulus }); + return { res_s, this->solver, this->type }; } STerm STerm::operator+(const STerm& other) const @@ -144,13 +154,18 @@ STerm STerm::operator/(const STerm& other) const info("Division is not compatible with ", this->type); return *this; } + if (this->type == TermType::FFTerm || this->type == TermType::FFITerm) { + other != bb::fr(0); + STerm res = Var("df8b586e3fa7a1224ec95a886e17a7da_div_" + static_cast(*this) + "_" + + static_cast(other), + this->solver, + this->type); + res* other == *this; + return res; + } other != bb::fr(0); - STerm res = Var("df8b586e3fa7a1224ec95a886e17a7da_div_" + static_cast(*this) + "_" + - static_cast(other), - this->solver, - this->type); - res* other == *this; - return res; + cvc5::Term res_s = this->solver->term_manager.mkTerm(this->operations.at(OpType::DIV), { this->term, other.term }); + return { res_s, this->solver, this->type }; } void STerm::operator/=(const STerm& other) @@ -159,13 +174,17 @@ void STerm::operator/=(const STerm& other) info("Division is not compatible with ", this->type); return; } + if (this->type == TermType::FFTerm || this->type == TermType::FFITerm) { + other != bb::fr(0); + STerm res = Var("df8b586e3fa7a1224ec95a886e17a7da_div_" + static_cast(*this) + "_" + + static_cast(other), + this->solver, + this->type); + res* other == *this; + this->term = res.term; + } other != bb::fr(0); - STerm res = Var("df8b586e3fa7a1224ec95a886e17a7da_div_" + static_cast(*this) + "_" + - static_cast(other), - this->solver, - this->type); - res* other == *this; - this->term = res.term; + this->term = this->solver->term_manager.mkTerm(this->operations.at(OpType::DIV), { this->term, other.term }); } /** @@ -174,15 +193,12 @@ void STerm::operator/=(const STerm& other) */ void STerm::operator==(const STerm& other) const { - STerm tmp1 = *this; - if (tmp1.term.getNumChildren() > 1) { - tmp1.mod(); - } - STerm tmp2 = other; - if (tmp2.term.getNumChildren() > 1) { - tmp2.mod(); - } - cvc5::Term eq = this->solver->term_manager.mkTerm(cvc5::Kind::EQUAL, { tmp1.term, tmp2.term }); + STerm left = *this; + STerm right = other; + left = this->type == TermType::FFITerm && left.term.getNumChildren() > 1 ? left.mod() : left; + right = this->type == TermType::FFITerm && right.term.getNumChildren() > 1 ? right.mod() : right; + + cvc5::Term eq = this->solver->term_manager.mkTerm(cvc5::Kind::EQUAL, { left.term, right.term }); this->solver->assertFormula(eq); } @@ -192,15 +208,12 @@ void STerm::operator==(const STerm& other) const */ void STerm::operator!=(const STerm& other) const { - STerm tmp1 = *this; - if (tmp1.term.getNumChildren() > 1) { - tmp1.mod(); - } - STerm tmp2 = other; - if (tmp2.term.getNumChildren() > 1) { - tmp2.mod(); - } - cvc5::Term eq = this->solver->term_manager.mkTerm(cvc5::Kind::EQUAL, { tmp1.term, tmp2.term }); + STerm left = *this; + STerm right = other; + left = this->type == TermType::FFITerm && left.term.getNumChildren() > 1 ? left.mod() : left; + right = this->type == TermType::FFITerm && right.term.getNumChildren() > 1 ? right.mod() : right; + + cvc5::Term eq = this->solver->term_manager.mkTerm(cvc5::Kind::EQUAL, { left.term, right.term }); eq = this->solver->term_manager.mkTerm(cvc5::Kind::NOT, { eq }); this->solver->assertFormula(eq); } @@ -371,6 +384,22 @@ STerm STerm::rotl(const uint32_t& n) const return { res, this->solver, this->type }; } +/** + * @brief Create an inclusion constraint + * + * @param entry entry to be checked + * @param table table that consists of elements, ranges mostly + */ +void STerm::in(const cvc5::Term& table) const +{ + STerm left = *this; + left = this->type == TermType::FFITerm && left.term.getNumChildren() > 1 ? left.mod() : left; + + Solver* slv = this->solver; + cvc5::Term inc = slv->term_manager.mkTerm(cvc5::Kind::SET_MEMBER, { left.term, table }); + slv->assertFormula(inc); +} + STerm operator+(const bb::fr& lhs, const STerm& rhs) { return rhs + lhs; @@ -428,6 +457,9 @@ std::ostream& operator<<(std::ostream& os, const TermType type) case TermType::BVTerm: os << "BVTerm"; break; + case TermType::ITerm: + os << "ITerm"; + break; }; return os; } @@ -455,6 +487,16 @@ STerm FFIConst(const std::string& val, Solver* slv, uint32_t base) return STerm::Const(val, slv, base, TermType::FFITerm); } +STerm IVar(const std::string& name, Solver* slv) +{ + return STerm::Var(name, slv, TermType::ITerm); +} + +STerm IConst(const std::string& val, Solver* slv, uint32_t base) +{ + return STerm::Const(val, slv, base, TermType::ITerm); +} + STerm BVVar(const std::string& name, Solver* slv) { return STerm::Var(name, slv, TermType::BVTerm); diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/terms/term.hpp b/barretenberg/cpp/src/barretenberg/smt_verification/terms/term.hpp index 60c1f3df300..35aff409795 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/terms/term.hpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/terms/term.hpp @@ -8,10 +8,11 @@ using namespace smt_solver; * @brief Allows to define three types of symbolic terms * STerm - Symbolic Variables acting like a Finte Field elements * FFITerm - Symbolic Variables acting like integers modulo prime + * ITerm - Symbolic Variables acting like integers * BVTerm - Symbolic Variables acting like bitvectors modulo prime * */ -enum class TermType { FFTerm, FFITerm, BVTerm }; +enum class TermType { FFTerm, FFITerm, BVTerm, ITerm }; std::ostream& operator<<(std::ostream& os, TermType type); enum class OpType : int32_t { ADD, SUB, MUL, DIV, NEG, XOR, AND, OR, GT, GE, LT, LE, MOD, RSH, LSH, ROTR, ROTL }; @@ -42,6 +43,17 @@ const std::unordered_map> typed { OpType::MOD, cvc5::Kind::INTS_MODULUS }, // Just a placeholder that marks it supports division { OpType::DIV, cvc5::Kind::MULT } } }, + { TermType::ITerm, + { { OpType::ADD, cvc5::Kind::ADD }, + { OpType::SUB, cvc5::Kind::SUB }, + { OpType::MUL, cvc5::Kind::MULT }, + { OpType::NEG, cvc5::Kind::NEG }, + { OpType::GT, cvc5::Kind::GT }, + { OpType::GE, cvc5::Kind::GEQ }, + { OpType::LT, cvc5::Kind::LT }, + { OpType::LE, cvc5::Kind::LEQ }, + { OpType::MOD, cvc5::Kind::INTS_MODULUS }, + { OpType::DIV, cvc5::Kind::INTS_DIVISION } } }, { TermType::BVTerm, { @@ -59,7 +71,9 @@ const std::unordered_map> typed { OpType::RSH, cvc5::Kind::BITVECTOR_LSHR }, { OpType::LSH, cvc5::Kind::BITVECTOR_SHL }, { OpType::ROTL, cvc5::Kind::BITVECTOR_ROTATE_LEFT }, - { OpType::ROTR, cvc5::Kind::BITVECTOR_ROTATE_RIGHT } } } + { OpType::ROTR, cvc5::Kind::BITVECTOR_ROTATE_RIGHT }, + { OpType::MOD, cvc5::Kind::BITVECTOR_UREM }, + { OpType::DIV, cvc5::Kind::BITVECTOR_UDIV } } } }; /** @@ -82,7 +96,6 @@ class STerm { , isBitVector(type == TermType::BVTerm) , type(type) , operations(typed_operations.at(type)){}; - void mod(); public: Solver* solver; @@ -122,6 +135,8 @@ class STerm { *this = Const(tmp, s, 16, type); } + STerm mod() const; + STerm& operator=(const STerm& right) = default; STerm& operator=(STerm&& right) = default; @@ -153,7 +168,9 @@ class STerm { STerm rotr(const uint32_t& n) const; STerm rotl(const uint32_t& n) const; - operator std::string() const { return smt_solver::stringify_term(term); }; + void in(const cvc5::Term& table) const; + + operator std::string() const { return this->solver->stringify_term(term); }; operator cvc5::Term() const { return term; }; ~STerm() = default; @@ -187,8 +204,16 @@ class STerm { */ static void in_table(std::vector& entry, cvc5::Term& table) { + STerm entry0 = entry[0]; + STerm entry1 = entry[1]; + STerm entry2 = entry[2]; + + entry0 = entry0.type == TermType::FFITerm && entry0.term.getNumChildren() > 1 ? entry0.mod() : entry0; + entry1 = entry1.type == TermType::FFITerm && entry1.term.getNumChildren() > 1 ? entry1.mod() : entry1; + entry2 = entry2.type == TermType::FFITerm && entry2.term.getNumChildren() > 1 ? entry2.mod() : entry2; + Solver* slv = entry[0].solver; - cvc5::Term sym_entry = slv->term_manager.mkTuple({ entry[0], entry[1], entry[2] }); + cvc5::Term sym_entry = slv->term_manager.mkTuple({ entry0, entry1, entry2 }); cvc5::Term inc = slv->term_manager.mkTerm(cvc5::Kind::SET_MEMBER, { sym_entry, table }); slv->assertFormula(inc); } @@ -234,6 +259,8 @@ STerm FFVar(const std::string& name, Solver* slv); STerm FFConst(const std::string& val, Solver* slv, uint32_t base = 16); STerm FFIVar(const std::string& name, Solver* slv); STerm FFIConst(const std::string& val, Solver* slv, uint32_t base = 16); +STerm IVar(const std::string& name, Solver* slv); +STerm IConst(const std::string& val, Solver* slv, uint32_t base = 16); STerm BVVar(const std::string& name, Solver* slv); STerm BVConst(const std::string& val, Solver* slv, uint32_t base = 16); diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/util/smt_util.cpp b/barretenberg/cpp/src/barretenberg/smt_verification/util/smt_util.cpp index d3a1c7a2bab..91a59608f5f 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/util/smt_util.cpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/util/smt_util.cpp @@ -42,13 +42,14 @@ void default_model(const std::vector& special, myfile << "{" << mmap1[vname1] << ", " << mmap2[vname2] << "}"; myfile << ", // " << vname1 << ", " << vname2 << std::endl; if (mmap1[vname1] != mmap2[vname2]) { - info("{", mmap1[vname1], ", ", mmap2[vname2], "}", ", // ", vname1, ", ", vname2); + info(RED, "{", mmap1[vname1], ", ", mmap2[vname2], "}", ", // ", vname1, ", ", vname2, RESET); } } else { myfile << "{" << mmap1[vname1] << ", " + mmap2[vname2] << "}"; myfile << ", // " << vname1 << " ," << vname2 << " -> " << c1.real_variable_index[i] << std::endl; if (mmap1[vname1] != mmap2[vname2]) { - info("{", + info(RED, + "{", mmap1[vname1], ", ", mmap2[vname2], @@ -58,7 +59,8 @@ void default_model(const std::vector& special, ", ", vname2, " -> ", - c1.real_variable_index[i]); + c1.real_variable_index[i], + RESET); } } } @@ -172,4 +174,24 @@ std::pair, std::vector> base4(uint32_t el) std::reverse(limbs.begin(), limbs.end()); std::reverse(accumulators.begin(), accumulators.end()); return { limbs, accumulators }; +} + +/** + * @brief Fix the triples from range_lists in the witness + * @details Since we are not using the part of the witness, that + * contains range lists, they are set to 0 by the solver. We need to + * overwrite them to check the witness obtained by the solver. + * + * @param builder + */ +void fix_range_lists(bb::UltraCircuitBuilder& builder) +{ + for (auto list : builder.range_lists) { + uint64_t num_multiples_of_three = (list.first / bb::UltraCircuitBuilder::DEFAULT_PLOOKUP_RANGE_STEP_SIZE); + for (uint64_t i = 0; i <= num_multiples_of_three; i++) { + builder.variables[list.second.variable_indices[i]] = + i * bb::UltraCircuitBuilder::DEFAULT_PLOOKUP_RANGE_STEP_SIZE; + } + builder.variables[list.second.variable_indices[num_multiples_of_three + 1]] = list.first; + } } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/smt_verification/util/smt_util.hpp b/barretenberg/cpp/src/barretenberg/smt_verification/util/smt_util.hpp index 559b8fff7ee..cf0521b88f0 100644 --- a/barretenberg/cpp/src/barretenberg/smt_verification/util/smt_util.hpp +++ b/barretenberg/cpp/src/barretenberg/smt_verification/util/smt_util.hpp @@ -3,6 +3,9 @@ #include "barretenberg/smt_verification/circuit/circuit_base.hpp" +#define RED "\033[31m" +#define RESET "\033[0m" + void default_model(const std::vector& special, smt_circuit::CircuitBase& c1, smt_circuit::CircuitBase& c2, @@ -12,4 +15,5 @@ void default_model_single(const std::vector& special, const std::string& fname = "witness.out"); bool smt_timer(smt_solver::Solver* s); -std::pair, std::vector> base4(uint32_t el); \ No newline at end of file +std::pair, std::vector> base4(uint32_t el); +void fix_range_lists(bb::UltraCircuitBuilder& builder); \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp index 5ac843e6b8d..ab653fadfb7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp @@ -126,7 +126,7 @@ field_t keccak::normalize_and_rotate(const field_ct& limb, fie // We need to provide a key/value object for this lookup in order for the Builder // to compute the plookup sorted list commitment const auto [input_quotient, input_slice] = input.divmod(divisor); - lookup.key_entries.push_back( + lookup.lookup_entries.push_back( { { static_cast(input_slice), 0 }, { normalized_slice, normalized_msb } }); // reduce the input and output by 11^{bit_slice} diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp index b605840a125..daedb38fd71 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.cpp @@ -177,21 +177,6 @@ std::shared_ptr ProtoGalaxyRecursiveVerifi // Compute ϕ fold_commitments(lagranges, instances, next_accumulator); - next_accumulator->public_inputs = - std::vector(static_cast(next_accumulator->verification_key->num_public_inputs), 0); - size_t public_input_idx = 0; - for (auto& public_input : next_accumulator->public_inputs) { - size_t inst = 0; - for (auto& instance : instances) { - if (instance->verification_key->num_public_inputs >= - next_accumulator->verification_key->num_public_inputs) { - public_input += instance->public_inputs[public_input_idx] * lagranges[inst]; - inst++; - }; - } - public_input_idx++; - } - size_t alpha_idx = 0; for (auto& alpha : next_accumulator->alphas) { alpha = FF(0); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.cpp index 94d8bf089fd..375211e12a0 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.cpp @@ -77,7 +77,7 @@ field_t plookup_read::read_from_2_to_1_table(const MultiTableI const field_t& key_a, const field_t& key_b) { - const auto lookup = get_lookup_accumulators(id, key_a, key_b, true); + const auto lookup = get_lookup_accumulators(id, key_a, key_b, /*is_2_to_1_lookup=*/true); return lookup[ColumnIdx::C3][0]; } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/circuit_builder_base.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/circuit_builder_base.hpp index ff516661c1d..c99ebcc0f39 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/circuit_builder_base.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/circuit_builder_base.hpp @@ -223,7 +223,26 @@ template class CircuitBuilderBase { void failure(std::string msg); }; -template struct CircuitSchema { +/** + * @brief Serialized state of a circuit + * + * @details Used to transfer the state of the circuit + * to Symbolic Circuit class. + * Symbolic circuit is then used to produce SMT statements + * that describe needed properties of the circuit. + * + * @param modulus Modulus of the field we are working with + * @param public_inps Public inputs to the current circuit + * @param vars_of_interest Map wires indices to their given names + * @param variables List of wires values in the current circuit + * @param selectors List of selectors in the current circuit + * @param wires List of wires indices for each selector + * @param real_variable_index Encoded copy constraints + * @param lookup_tables List of lookup tables + * @param real_variable_tag Variables' tags for range constraints + * @param range_lists Existing range lists + */ +template struct CircuitSchemaInternal { std::string modulus; std::vector public_inps; std::unordered_map vars_of_interest; @@ -232,8 +251,18 @@ template struct CircuitSchema { std::vector>> wires; std::vector real_variable_index; std::vector>> lookup_tables; - MSGPACK_FIELDS( - modulus, public_inps, vars_of_interest, variables, selectors, wires, real_variable_index, lookup_tables); + std::vector real_variable_tags; + std::unordered_map range_tags; + MSGPACK_FIELDS(modulus, + public_inps, + vars_of_interest, + variables, + selectors, + wires, + real_variable_index, + lookup_tables, + real_variable_tags, + range_tags); }; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/aes128.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/aes128.hpp index f3102bbfd18..4dd529fb978 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/aes128.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/aes128.hpp @@ -25,9 +25,9 @@ inline BasicTable generate_aes_sparse_table(BasicTableId id, const size_t table_ BasicTable table; table.id = id; table.table_index = table_index; - table.size = 256; + size_t table_size = 256; table.use_twin_keys = true; - for (uint64_t i = 0; i < table.size; ++i) { + for (uint64_t i = 0; i < table_size; ++i) { uint64_t left = i; const auto right = numeric::map_into_sparse_form((uint8_t)i); table.column_1.emplace_back(bb::fr(left)); @@ -74,7 +74,6 @@ inline BasicTable generate_aes_sparse_normalization_table(BasicTableId id, const } } } - table.size = table.column_1.size(); table.use_twin_keys = false; table.get_values_from_key = &get_aes_sparse_normalization_values_from_key; @@ -102,7 +101,7 @@ inline MultiTable get_aes_normalization_table(const MultiTableId id = AES_NORMAL table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(AES_BASE * AES_BASE * AES_BASE * AES_BASE); - table.lookup_ids.emplace_back(AES_SPARSE_NORMALIZE); + table.basic_table_ids.emplace_back(AES_SPARSE_NORMALIZE); table.get_table_values.emplace_back(&get_aes_sparse_normalization_values_from_key); } return table; @@ -117,7 +116,7 @@ inline MultiTable get_aes_input_table(const MultiTableId id = AES_INPUT) table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(256); - table.lookup_ids.emplace_back(AES_SPARSE_MAP); + table.basic_table_ids.emplace_back(AES_SPARSE_MAP); table.get_table_values.emplace_back(&sparse_tables::get_sparse_table_with_rotation_values); } return table; @@ -137,9 +136,9 @@ inline BasicTable generate_aes_sbox_table(BasicTableId id, const size_t table_in BasicTable table; table.id = id; table.table_index = table_index; - table.size = 256; + size_t table_size = 256; table.use_twin_keys = false; - for (uint64_t i = 0; i < table.size; ++i) { + for (uint64_t i = 0; i < table_size; ++i) { const auto first = numeric::map_into_sparse_form((uint8_t)i); uint8_t sbox_value = crypto::aes128_sbox[(uint8_t)i]; uint8_t swizzled = ((uint8_t)(sbox_value << 1) ^ (uint8_t)(((sbox_value >> 7) & 1) * 0x1b)); @@ -167,7 +166,7 @@ inline MultiTable get_aes_sbox_table(const MultiTableId id = AES_SBOX) table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(numeric::pow64(AES_BASE, 8)); - table.lookup_ids.emplace_back(AES_SBOX_MAP); + table.basic_table_ids.emplace_back(AES_SBOX_MAP); table.get_table_values.emplace_back(&get_aes_sbox_values_from_key); } return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/blake2s.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/blake2s.hpp index 10a56396e6b..204b830b945 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/blake2s.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/blake2s.hpp @@ -35,7 +35,6 @@ inline BasicTable generate_xor_rotate_table(BasicTableId id, const size_t table_ BasicTable table; table.id = id; table.table_index = table_index; - table.size = base * base; table.use_twin_keys = true; for (uint64_t i = 0; i < base; ++i) { @@ -95,12 +94,12 @@ inline MultiTable get_blake2s_xor_table(const MultiTableId id = BLAKE_XOR) table.id = id; for (size_t i = 0; i < num_entries - 1; ++i) { table.slice_sizes.emplace_back(base); - table.lookup_ids.emplace_back(BLAKE_XOR_ROTATE0); + table.basic_table_ids.emplace_back(BLAKE_XOR_ROTATE0); table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>); } table.slice_sizes.emplace_back(SIZE_OF_LAST_SLICE); - table.lookup_ids.emplace_back(BLAKE_XOR_ROTATE0_SLICE5_MOD4); + table.basic_table_ids.emplace_back(BLAKE_XOR_ROTATE0_SLICE5_MOD4); table.get_table_values.emplace_back(&get_xor_rotate_values_from_key); return table; @@ -128,8 +127,8 @@ inline MultiTable get_blake2s_xor_rotate_16_table(const MultiTableId id = BLAKE_ table.id = id; table.slice_sizes = { base, base, base, base, base, SIZE_OF_LAST_SLICE }; - table.lookup_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE4, - BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 }; + table.basic_table_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE4, + BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 }; table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>); table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>); @@ -163,8 +162,8 @@ inline MultiTable get_blake2s_xor_rotate_8_table(const MultiTableId id = BLAKE_X table.id = id; table.slice_sizes = { base, base, base, base, base, SIZE_OF_LAST_SLICE }; - table.lookup_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE2, BLAKE_XOR_ROTATE0, - BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 }; + table.basic_table_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE2, BLAKE_XOR_ROTATE0, + BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 }; table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>); table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 2>); @@ -198,8 +197,8 @@ inline MultiTable get_blake2s_xor_rotate_7_table(const MultiTableId id = BLAKE_X table.id = id; table.slice_sizes = { base, base, base, base, base, SIZE_OF_LAST_SLICE }; - table.lookup_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE1, BLAKE_XOR_ROTATE0, - BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 }; + table.basic_table_ids = { BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE1, BLAKE_XOR_ROTATE0, + BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0, BLAKE_XOR_ROTATE0_SLICE5_MOD4 }; table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>); table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 1>); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/dummy.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/dummy.hpp index f49409c9bbc..cc3b443ca09 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/dummy.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/dummy.hpp @@ -49,7 +49,6 @@ inline BasicTable generate_honk_dummy_table(const BasicTableId id, const size_t BasicTable table; table.id = id; table.table_index = table_index; - table.size = base * base; table.use_twin_keys = true; for (uint64_t i = 0; i < base; ++i) { for (uint64_t j = 0; j < base; ++j) { @@ -85,10 +84,10 @@ inline MultiTable get_honk_dummy_multitable() number_of_lookups); table.id = id; table.slice_sizes.emplace_back(number_of_elements_in_argument); - table.lookup_ids.emplace_back(HONK_DUMMY_BASIC1); + table.basic_table_ids.emplace_back(HONK_DUMMY_BASIC1); table.get_table_values.emplace_back(&get_value_from_key); table.slice_sizes.emplace_back(number_of_elements_in_argument); - table.lookup_ids.emplace_back(HONK_DUMMY_BASIC2); + table.basic_table_ids.emplace_back(HONK_DUMMY_BASIC2); table.get_table_values.emplace_back(&get_value_from_key); return table; } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.cpp index 0feae681d45..edd9cce6b13 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.cpp @@ -197,12 +197,11 @@ BasicTable table::generate_basic_fixed_base_table(BasicTableId id, size_t basic_ BasicTable table; table.id = id; table.table_index = basic_table_index; - table.size = table_size; table.use_twin_keys = false; const auto& basic_table = fixed_base_tables[multitable_index][table_index]; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table_size; ++i) { table.column_1.emplace_back(i); table.column_2.emplace_back(basic_table[i].x); table.column_3.emplace_back(basic_table[i].y); @@ -213,7 +212,7 @@ BasicTable table::generate_basic_fixed_base_table(BasicTableId id, size_t basic_ table.get_values_from_key = get_values_from_key_table[multitable_index][table_index]; ASSERT(table.get_values_from_key != nullptr); - table.column_1_step_size = table.size; + table.column_1_step_size = table_size; table.column_2_step_size = 0; table.column_3_step_size = 0; @@ -243,13 +242,13 @@ template MultiTable table::get_fixed_ MultiTable table(MAX_TABLE_SIZE, 0, 0, NUM_TABLES); table.id = id; table.get_table_values.resize(NUM_TABLES); - table.lookup_ids.resize(NUM_TABLES); + table.basic_table_ids.resize(NUM_TABLES); for (size_t i = 0; i < NUM_TABLES; ++i) { table.slice_sizes.emplace_back(MAX_TABLE_SIZE); table.get_table_values[i] = get_values_from_key_table[multitable_index][i]; static_assert(multitable_index < NUM_FIXED_BASE_MULTI_TABLES); size_t idx = i + static_cast(basic_table_ids[multitable_index]); - table.lookup_ids[i] = static_cast(idx); + table.basic_table_ids[i] = static_cast(idx); } return table; } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_chi.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_chi.hpp index 0e5b4a8a5c3..4345112a713 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_chi.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_chi.hpp @@ -169,11 +169,11 @@ class Chi { table.id = id; table.table_index = table_index; table.use_twin_keys = false; - table.size = numeric::pow64(static_cast(EFFECTIVE_BASE), TABLE_BITS); + auto table_size = numeric::pow64(static_cast(EFFECTIVE_BASE), TABLE_BITS); std::array counts{}; std::array column_values{ 0, 0, 0 }; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table_size; ++i) { table.column_1.emplace_back(column_values[0]); table.column_2.emplace_back(column_values[1]); table.column_3.emplace_back(column_values[2]); @@ -242,7 +242,7 @@ class Chi { table.id = id; for (size_t i = 0; i < num_tables_per_multitable; ++i) { table.slice_sizes.emplace_back(numeric::pow64(BASE, TABLE_BITS)); - table.lookup_ids.emplace_back(KECCAK_CHI); + table.basic_table_ids.emplace_back(KECCAK_CHI); table.get_table_values.emplace_back(&get_chi_renormalization_values); } return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_input.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_input.hpp index c3b6d20ae98..f03e00bcc47 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_input.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_input.hpp @@ -57,11 +57,11 @@ class KeccakInput { BasicTable table; table.id = id; table.table_index = table_index; - table.size = (1U << TABLE_BITS); + auto table_size = (1U << TABLE_BITS); table.use_twin_keys = false; constexpr size_t msb_shift = (64 % TABLE_BITS == 0) ? TABLE_BITS - 1 : (64 % TABLE_BITS) - 1; - for (uint64_t i = 0; i < table.size; ++i) { + for (uint64_t i = 0; i < table_size; ++i) { const uint64_t source = i; const auto target = numeric::map_into_sparse_form(source); table.column_1.emplace_back(bb::fr(source)); @@ -132,7 +132,7 @@ class KeccakInput { table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(1 << 8); - table.lookup_ids.emplace_back(KECCAK_INPUT); + table.basic_table_ids.emplace_back(KECCAK_INPUT); table.get_table_values.emplace_back(&get_keccak_input_values); } return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_output.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_output.hpp index 53f2fc9a53f..d5160f21a7c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_output.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_output.hpp @@ -91,12 +91,12 @@ class KeccakOutput { table.id = id; table.table_index = table_index; table.use_twin_keys = false; - table.size = numeric::pow64(static_cast(EFFECTIVE_BASE), TABLE_BITS); + auto table_size = numeric::pow64(static_cast(EFFECTIVE_BASE), TABLE_BITS); std::array counts{}; std::array column_values{ 0, 0 }; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table_size; ++i) { table.column_1.emplace_back(column_values[0]); table.column_2.emplace_back(column_values[1]); table.column_3.emplace_back(0); @@ -162,7 +162,7 @@ class KeccakOutput { table.id = id; for (size_t i = 0; i < num_tables_per_multitable; ++i) { table.slice_sizes.emplace_back(numeric::pow64(BASE, TABLE_BITS)); - table.lookup_ids.emplace_back(KECCAK_OUTPUT); + table.basic_table_ids.emplace_back(KECCAK_OUTPUT); table.get_table_values.emplace_back( &sparse_tables::get_sparse_normalization_values); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_rho.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_rho.hpp index c16085aca8a..5d548e70cbb 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_rho.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_rho.hpp @@ -170,12 +170,12 @@ template class Rho { table.id = id; table.table_index = table_index; table.use_twin_keys = false; - table.size = numeric::pow64(static_cast(EFFECTIVE_BASE), TABLE_BITS); + auto table_size = numeric::pow64(static_cast(EFFECTIVE_BASE), TABLE_BITS); std::array counts{}; std::array column_values{ 0, 0, 0 }; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table_size; ++i) { table.column_1.emplace_back(column_values[0]); table.column_2.emplace_back(column_values[1]); table.column_3.emplace_back(column_values[2]); @@ -264,7 +264,7 @@ template class Rho { table.slice_sizes.push_back(scaled_base); table.get_table_values.emplace_back(&get_rho_renormalization_values); - table.lookup_ids.push_back((BasicTableId)((size_t)KECCAK_RHO_1 + (bit_slice - 1))); + table.basic_table_ids.push_back((BasicTableId)((size_t)KECCAK_RHO_1 + (bit_slice - 1))); }); // generate table selector values for the 'left' slice @@ -284,7 +284,7 @@ template class Rho { table.slice_sizes.push_back(scaled_base); table.get_table_values.emplace_back(&get_rho_renormalization_values); - table.lookup_ids.push_back((BasicTableId)((size_t)KECCAK_RHO_1 + (bit_slice - 1))); + table.basic_table_ids.push_back((BasicTableId)((size_t)KECCAK_RHO_1 + (bit_slice - 1))); }); return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_theta.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_theta.hpp index 9f05cf94267..41c0cc8608f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_theta.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/keccak/keccak_theta.hpp @@ -171,12 +171,12 @@ class Theta { table.id = id; table.table_index = table_index; table.use_twin_keys = false; - table.size = numeric::pow64(static_cast(BASE), TABLE_BITS); + auto table_size = numeric::pow64(static_cast(BASE), TABLE_BITS); std::array counts{}; std::array column_values{ 0, 0 }; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table_size; ++i) { table.column_1.emplace_back(column_values[0]); table.column_2.emplace_back(column_values[1]); table.column_3.emplace_back(0); @@ -244,7 +244,7 @@ class Theta { table.id = id; for (size_t i = 0; i < num_tables_per_multitable; ++i) { table.slice_sizes.emplace_back(numeric::pow64(BASE, TABLE_BITS)); - table.lookup_ids.emplace_back(KECCAK_THETA); + table.basic_table_ids.emplace_back(KECCAK_THETA); table.get_table_values.emplace_back(&get_theta_renormalization_values); } return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/non_native_group_generator.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/non_native_group_generator.cpp index ed172573e24..2031e949779 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/non_native_group_generator.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/non_native_group_generator.cpp @@ -182,10 +182,10 @@ template BasicTable ecc_generator_table::generate_xlo_table(Ba BasicTable table; table.id = id; table.table_index = table_index; - table.size = 256; + size_t table_size = 256; table.use_twin_keys = false; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table_size; ++i) { table.column_1.emplace_back((i)); table.column_2.emplace_back(ecc_generator_table::generator_xlo_table[i].first); table.column_3.emplace_back(ecc_generator_table::generator_xlo_table[i].second); @@ -205,10 +205,10 @@ template BasicTable ecc_generator_table::generate_xhi_table(Ba BasicTable table; table.id = id; table.table_index = table_index; - table.size = 256; + size_t table_size = 256; table.use_twin_keys = false; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table_size; ++i) { table.column_1.emplace_back((i)); table.column_2.emplace_back(ecc_generator_table::generator_xhi_table[i].first); table.column_3.emplace_back(ecc_generator_table::generator_xhi_table[i].second); @@ -229,10 +229,10 @@ BasicTable ecc_generator_table::generate_xlo_endo_table(BasicTableId id, con BasicTable table; table.id = id; table.table_index = table_index; - table.size = 256; + size_t table_size = 256; table.use_twin_keys = false; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table_size; ++i) { table.column_1.emplace_back((i)); table.column_2.emplace_back(ecc_generator_table::generator_endo_xlo_table[i].first); table.column_3.emplace_back(ecc_generator_table::generator_endo_xlo_table[i].second); @@ -253,10 +253,10 @@ BasicTable ecc_generator_table::generate_xhi_endo_table(BasicTableId id, con BasicTable table; table.id = id; table.table_index = table_index; - table.size = 256; + size_t table_size = 256; table.use_twin_keys = false; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table_size; ++i) { table.column_1.emplace_back((i)); table.column_2.emplace_back(ecc_generator_table::generator_endo_xhi_table[i].first); table.column_3.emplace_back(ecc_generator_table::generator_endo_xhi_table[i].second); @@ -276,10 +276,10 @@ template BasicTable ecc_generator_table::generate_ylo_table(Ba BasicTable table; table.id = id; table.table_index = table_index; - table.size = 256; + size_t table_size = 256; table.use_twin_keys = false; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table_size; ++i) { table.column_1.emplace_back((i)); table.column_2.emplace_back(ecc_generator_table::generator_ylo_table[i].first); table.column_3.emplace_back(ecc_generator_table::generator_ylo_table[i].second); @@ -299,10 +299,10 @@ template BasicTable ecc_generator_table::generate_yhi_table(Ba BasicTable table; table.id = id; table.table_index = table_index; - table.size = 256; + size_t table_size = 256; table.use_twin_keys = false; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table_size; ++i) { table.column_1.emplace_back((i)); table.column_2.emplace_back(ecc_generator_table::generator_yhi_table[i].first); table.column_3.emplace_back(ecc_generator_table::generator_yhi_table[i].second); @@ -323,10 +323,10 @@ BasicTable ecc_generator_table::generate_xyprime_table(BasicTableId id, cons BasicTable table; table.id = id; table.table_index = table_index; - table.size = 256; + size_t table_size = 256; table.use_twin_keys = false; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table_size; ++i) { table.column_1.emplace_back((i)); table.column_2.emplace_back(ecc_generator_table::generator_xyprime_table[i].first); table.column_3.emplace_back(ecc_generator_table::generator_xyprime_table[i].second); @@ -347,10 +347,10 @@ BasicTable ecc_generator_table::generate_xyprime_endo_table(BasicTableId id, BasicTable table; table.id = id; table.table_index = table_index; - table.size = 256; + size_t table_size = 256; table.use_twin_keys = false; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table_size; ++i) { table.column_1.emplace_back((i)); table.column_2.emplace_back(ecc_generator_table::generator_endo_xyprime_table[i].first); table.column_3.emplace_back(ecc_generator_table::generator_endo_xyprime_table[i].second); @@ -374,7 +374,7 @@ MultiTable ecc_generator_table::get_xlo_table(const MultiTableId id, const B table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_xlo_values); } return table; @@ -389,7 +389,7 @@ MultiTable ecc_generator_table::get_xhi_table(const MultiTableId id, const B table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_xhi_values); } return table; @@ -404,7 +404,7 @@ MultiTable ecc_generator_table::get_xlo_endo_table(const MultiTableId id, co table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_xlo_endo_values); } return table; @@ -419,7 +419,7 @@ MultiTable ecc_generator_table::get_xhi_endo_table(const MultiTableId id, co table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_xhi_endo_values); } return table; @@ -434,7 +434,7 @@ MultiTable ecc_generator_table::get_ylo_table(const MultiTableId id, const B table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_ylo_values); } return table; @@ -449,7 +449,7 @@ MultiTable ecc_generator_table::get_yhi_table(const MultiTableId id, const B table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_yhi_values); } return table; @@ -464,7 +464,7 @@ MultiTable ecc_generator_table::get_xyprime_table(const MultiTableId id, con table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_xyprime_values); } return table; @@ -479,7 +479,7 @@ MultiTable ecc_generator_table::get_xyprime_endo_table(const MultiTableId id table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(512); - table.lookup_ids.emplace_back(basic_id); + table.basic_table_ids.emplace_back(basic_id); table.get_table_values.emplace_back(&get_xyprime_endo_values); } return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp index 73e3814cba5..b897fc8c309 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.cpp @@ -26,7 +26,7 @@ std::array MULTI_TABLES; bool initialised = false; #ifndef NO_MULTITHREADING -// The multitables initialisation procedure is not thread-sage, so we need to make sure only 1 thread gets to initialize +// The multitables initialisation procedure is not thread-safe, so we need to make sure only 1 thread gets to initialize // them. std::mutex multi_table_mutex; #endif @@ -123,7 +123,16 @@ void init_multi_tables() initialised = true; } } // namespace -const MultiTable& create_table(const MultiTableId id) +/** + * @brief Return the multitable with the provided ID; construct all MultiTables if not constructed already + * @details The multitables are relatively light objects (they do not themselves store raw table data) so the first time + * we use one of them we simply construct all of them (regardless of which of them will actually be used) and store in + * MULTI_TABLES array. + * + * @param id The index of a MultiTable in the MULTI_TABLES array + * @return const MultiTable& + */ +const MultiTable& get_multitable(const MultiTableId id) { if (!initialised) { init_multi_tables(); @@ -132,14 +141,31 @@ const MultiTable& create_table(const MultiTableId id) return MULTI_TABLES[id]; } +/** + * @brief Given a table ID and the key(s) for a key-value lookup, return the lookup accumulators + * @details In general the number of bits in key/value is greater than what can be efficiently supported in lookup + * tables. For this reason we actually perform lookups on the corresponding limbs. However, since we're interested in + * the full values and not the limbs, its convenient to structure the witnesses of lookup gates to store the former. + * This way we don't have to waste gates reaccumulating the limbs to compute the actual value of interest. The way to do + * this is to populate the wires with 'accumulator' values such that the first gate in the series contains the full + * accumulated values, and successive gates contain prior stages of the accumulator such that wire_i - r*wire_{i-1} = + * v_i, where r = num limb bits and v_i is a limb that explicitly appears in one of the lookup tables. See the detailed + * comment block below for more explanation. + * + * @param id + * @param key_a + * @param key_b + * @param is_2_to_1_lookup + * @return ReadData + */ ReadData get_lookup_accumulators(const MultiTableId id, const fr& key_a, const fr& key_b, const bool is_2_to_1_lookup) { // return multi-table, populating global array of all multi-tables if need be - const auto& multi_table = create_table(id); - const size_t num_lookups = multi_table.lookup_ids.size(); + const auto& multi_table = get_multitable(id); + const size_t num_lookups = multi_table.basic_table_ids.size(); ReadData lookup; const auto key_a_slices = numeric::slice_input_using_variable_bases(key_a, multi_table.slice_sizes); @@ -150,21 +176,21 @@ ReadData get_lookup_accumulators(const MultiTableId id, std::vector column_3_raw_values; for (size_t i = 0; i < num_lookups; ++i) { - // get i-th table query function and then submit query + // compute the value(s) corresponding to the key(s) using on the i-th basic table query function const auto values = multi_table.get_table_values[i]({ key_a_slices[i], key_b_slices[i] }); // store all query data in raw columns and key entry column_1_raw_values.emplace_back(key_a_slices[i]); column_2_raw_values.emplace_back(is_2_to_1_lookup ? key_b_slices[i] : values[0]); column_3_raw_values.emplace_back(is_2_to_1_lookup ? values[0] : values[1]); - // Question: why are we storing the key slices twice? - const BasicTable::KeyEntry key_entry{ { key_a_slices[i], key_b_slices[i] }, values }; - lookup.key_entries.emplace_back(key_entry); + // Store the lookup entries for use in constructing the sorted table/lookup polynomials later on + const BasicTable::LookupEntry lookup_entry{ { key_a_slices[i], key_b_slices[i] }, values }; + lookup.lookup_entries.emplace_back(lookup_entry); } - lookup[ColumnIdx::C1].resize(num_lookups); - lookup[ColumnIdx::C2].resize(num_lookups); - lookup[ColumnIdx::C3].resize(num_lookups); + lookup[C1].resize(num_lookups); + lookup[C2].resize(num_lookups); + lookup[C3].resize(num_lookups); /** * A multi-table consists of multiple basic tables (say L = 6). @@ -178,8 +204,9 @@ ReadData get_lookup_accumulators(const MultiTableId id, * s1 s2 s3 s4 s5 s6 * * Note that different basic tables can be of different sizes. Every lookup query generates L output slices (one for - * each basic table, here, s1, s2, ..., s6). In other words, every lookup query add L lookup gates to the program. - * Let the input slices/keys be (a1, b1), (a2, b2), ..., (a6, b6). The lookup gate structure is as follows: + * each basic table, here, s1, s2, ..., s6). In other words, every lookup query adds L lookup gates to the program. + * For example, to look up the XOR of 32-bit inputs, we actually perform 6 individual lookups on the 6-bit XOR basic + * table. Let the input slices/keys be (a1, b1), (a2, b2), ..., (a6, b6). The lookup gate structure is as follows: * * +---+-----------------------------------+----------------------------------+-----------------------------------+ * | s | key_a | key_b | output | @@ -193,34 +220,25 @@ ReadData get_lookup_accumulators(const MultiTableId id, * +---+-----------------------------------+----------------------------------+-----------------------------------+ * * Note that we compute the accumulating sums of the slices so as to avoid using additonal gates for the purpose of - * reconstructing inputs/outputs. Here, (p, q, r) are referred to as column coefficients/step sizes. - * In the next few lines, we compute these accumulating sums from raw column values (a1, ..., a6), (b1, ..., b6), - * (s1, ..., s6) and column coefficients (p, q, r). + * reconstructing the original inputs/outputs. I.e. the output value at the 0th index in the above table is the + * actual value we were interested in computing in the first place. Importantly, the structure of the remaining rows + * is such that row_i - r*row_{i+1} produces an entry {a_j, b_j, s_j} that exactly corresponds to an entry in a + * BasicTable. This is what gives rise to the wire_i - scalar*wire_i_shift structure in the lookup relation. Here, + * (p, q, r) are referred to as column coefficients/step sizes. In the next few lines, we compute these accumulating + * sums from raw column values (a1, ..., a6), (b1, ..., b6), (s1, ..., s6) and column coefficients (p, q, r). * * For more details: see * https://app.gitbook.com/o/-LgCgJ8TCO7eGlBr34fj/s/-MEwtqp3H6YhHUTQ_pVJ/plookup-gates-for-ultraplonk/lookup-table-structures * */ - lookup[ColumnIdx::C1][num_lookups - 1] = column_1_raw_values[num_lookups - 1]; - lookup[ColumnIdx::C2][num_lookups - 1] = column_2_raw_values[num_lookups - 1]; - lookup[ColumnIdx::C3][num_lookups - 1] = column_3_raw_values[num_lookups - 1]; + lookup[C1][num_lookups - 1] = column_1_raw_values[num_lookups - 1]; + lookup[C2][num_lookups - 1] = column_2_raw_values[num_lookups - 1]; + lookup[C3][num_lookups - 1] = column_3_raw_values[num_lookups - 1]; - for (size_t i = 1; i < num_lookups; ++i) { - const auto& previous_1 = lookup[ColumnIdx::C1][num_lookups - i]; - const auto& previous_2 = lookup[ColumnIdx::C2][num_lookups - i]; - const auto& previous_3 = lookup[ColumnIdx::C3][num_lookups - i]; - - auto& current_1 = lookup[ColumnIdx::C1][num_lookups - 1 - i]; - auto& current_2 = lookup[ColumnIdx::C2][num_lookups - 1 - i]; - auto& current_3 = lookup[ColumnIdx::C3][num_lookups - 1 - i]; - - const auto& raw_1 = column_1_raw_values[num_lookups - 1 - i]; - const auto& raw_2 = column_2_raw_values[num_lookups - 1 - i]; - const auto& raw_3 = column_3_raw_values[num_lookups - 1 - i]; - - current_1 = raw_1 + previous_1 * multi_table.column_1_step_sizes[num_lookups - i]; - current_2 = raw_2 + previous_2 * multi_table.column_2_step_sizes[num_lookups - i]; - current_3 = raw_3 + previous_3 * multi_table.column_3_step_sizes[num_lookups - i]; + for (size_t i = num_lookups - 1; i > 0; --i) { + lookup[C1][i - 1] = column_1_raw_values[i - 1] + lookup[C1][i] * multi_table.column_1_step_sizes[i]; + lookup[C2][i - 1] = column_2_raw_values[i - 1] + lookup[C2][i] * multi_table.column_2_step_sizes[i]; + lookup[C3][i - 1] = column_3_raw_values[i - 1] + lookup[C3][i] * multi_table.column_3_step_sizes[i]; } return lookup; } diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.hpp index 504a4ba97b8..5b598f10a1f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/plookup_tables.hpp @@ -4,7 +4,7 @@ namespace bb::plookup { -const MultiTable& create_table(MultiTableId id); +const MultiTable& get_multitable(MultiTableId id); ReadData get_lookup_accumulators(MultiTableId id, const bb::fr& key_a, diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/sha256.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/sha256.hpp index a63b94cd20d..d702c5c24c9 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/sha256.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/sha256.hpp @@ -116,7 +116,7 @@ inline MultiTable get_witness_extension_output_table(const MultiTableId id = SHA table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(numeric::pow64(16, 3)); - table.lookup_ids.emplace_back(SHA256_WITNESS_NORMALIZE); + table.basic_table_ids.emplace_back(SHA256_WITNESS_NORMALIZE); table.get_table_values.emplace_back( &sparse_tables::get_sparse_normalization_values<16, witness_extension_normalization_table>); } @@ -132,7 +132,7 @@ inline MultiTable get_choose_output_table(const MultiTableId id = SHA256_CH_OUTP table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(numeric::pow64(28, 2)); - table.lookup_ids.emplace_back(SHA256_CH_NORMALIZE); + table.basic_table_ids.emplace_back(SHA256_CH_NORMALIZE); table.get_table_values.emplace_back( &sparse_tables::get_sparse_normalization_values<28, choose_normalization_table>); } @@ -148,7 +148,7 @@ inline MultiTable get_majority_output_table(const MultiTableId id = SHA256_MAJ_O table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(numeric::pow64(16, 3)); - table.lookup_ids.emplace_back(SHA256_MAJ_NORMALIZE); + table.basic_table_ids.emplace_back(SHA256_MAJ_NORMALIZE); table.get_table_values.emplace_back( &sparse_tables::get_sparse_normalization_values<16, majority_normalization_table>); } @@ -223,10 +223,10 @@ inline MultiTable get_witness_extension_input_table(const MultiTableId id = SHA2 MultiTable table(column_1_coefficients, column_2_coefficients, column_3_coefficients); table.id = id; table.slice_sizes = { (1 << 3), (1 << 7), (1 << 8), (1 << 18) }; - table.lookup_ids = { SHA256_WITNESS_SLICE_3, - SHA256_WITNESS_SLICE_7_ROTATE_4, - SHA256_WITNESS_SLICE_8_ROTATE_7, - SHA256_WITNESS_SLICE_14_ROTATE_1 }; + table.basic_table_ids = { SHA256_WITNESS_SLICE_3, + SHA256_WITNESS_SLICE_7_ROTATE_4, + SHA256_WITNESS_SLICE_8_ROTATE_7, + SHA256_WITNESS_SLICE_14_ROTATE_1 }; table.get_table_values = { &sparse_tables::get_sparse_table_with_rotation_values<16, 0>, @@ -321,7 +321,7 @@ inline MultiTable get_choose_input_table(const MultiTableId id = SHA256_CH_INPUT MultiTable table(column_1_coefficients, column_2_coefficients, column_3_coefficients); table.id = id; table.slice_sizes = { (1 << 11), (1 << 11), (1 << 10) }; - table.lookup_ids = { SHA256_BASE28_ROTATE6, SHA256_BASE28, SHA256_BASE28_ROTATE3 }; + table.basic_table_ids = { SHA256_BASE28_ROTATE6, SHA256_BASE28, SHA256_BASE28_ROTATE3 }; table.get_table_values.push_back(&sparse_tables::get_sparse_table_with_rotation_values<28, 6>); table.get_table_values.push_back(&sparse_tables::get_sparse_table_with_rotation_values<28, 0>); @@ -380,7 +380,7 @@ inline MultiTable get_majority_input_table(const MultiTableId id = SHA256_MAJ_IN MultiTable table(column_1_coefficients, column_2_coefficients, column_3_coefficients); table.id = id; table.slice_sizes = { (1 << 11), (1 << 11), (1 << 10) }; - table.lookup_ids = { SHA256_BASE16_ROTATE2, SHA256_BASE16_ROTATE2, SHA256_BASE16 }; + table.basic_table_ids = { SHA256_BASE16_ROTATE2, SHA256_BASE16_ROTATE2, SHA256_BASE16 }; table.get_table_values = { &sparse_tables::get_sparse_table_with_rotation_values<16, 2>, &sparse_tables::get_sparse_table_with_rotation_values<16, 2>, diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/sparse.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/sparse.hpp index 35c858e30a3..2dfdd880ea2 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/sparse.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/sparse.hpp @@ -28,10 +28,10 @@ inline BasicTable generate_sparse_table_with_rotation(BasicTableId id, const siz BasicTable table; table.id = id; table.table_index = table_index; - table.size = (1U << bits_per_slice); + auto table_size = (1U << bits_per_slice); table.use_twin_keys = false; - for (uint64_t i = 0; i < table.size; ++i) { + for (uint64_t i = 0; i < table_size; ++i) { const uint64_t source = i; const auto target = numeric::map_into_sparse_form(source); table.column_1.emplace_back(bb::fr(source)); @@ -89,11 +89,11 @@ inline BasicTable generate_sparse_normalization_table(BasicTableId id, const siz table.id = id; table.table_index = table_index; table.use_twin_keys = false; - table.size = numeric::pow64(static_cast(base), num_bits); + auto table_size = numeric::pow64(static_cast(base), num_bits); numeric::sparse_int accumulator(0); numeric::sparse_int to_add(1); - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table_size; ++i) { const auto& limbs = accumulator.get_limbs(); uint64_t key = 0; for (size_t j = 0; j < num_bits; ++j) { @@ -109,7 +109,7 @@ inline BasicTable generate_sparse_normalization_table(BasicTableId id, const siz table.get_values_from_key = &get_sparse_normalization_values; - table.column_1_step_size = bb::fr(table.size); + table.column_1_step_size = bb::fr(table_size); table.column_2_step_size = bb::fr(((uint64_t)1 << num_bits)); table.column_3_step_size = bb::fr(0); return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp index 0dfcaa916d3..c41d4e94670 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp @@ -121,19 +121,33 @@ enum MultiTableId { NUM_MULTI_TABLES = KECCAK_NORMALIZE_AND_ROTATE + 25, }; +/** + * @brief Container for managing multiple BasicTables plus the data needed to combine basic table outputs (limbs) into + * accumulators. Does not store actual raw table data. + * @details As a simple example, consider using lookups to compute XOR on uint32_t inputs. To do this we decompose the + * inputs into 6 limbs and use a BasicTable for 6-bit XOR lookups. In this case the MultiTable simply manages 6 basic + * tables, all of which are the XOR BasicTable. (In many cases all of the BasicTables managed by a MultiTable are + * identical, however there are some cases where more than 1 type is required, e.g. if a certain limb has to be handled + * differently etc.). This class also stores the scalars needed to reconstruct full values from the components that are + * contained in the basic lookup tables. + * @note Note that a MultiTable does not actually *store* any table data. Rather it stores a set of basic table IDs, the + * methods used to compute the basic table entries, plus some metadata. + * + */ struct MultiTable { // Coefficients are accumulated products of corresponding step sizes until that point std::vector column_1_coefficients; std::vector column_2_coefficients; std::vector column_3_coefficients; MultiTableId id; - std::vector lookup_ids; + std::vector basic_table_ids; std::vector slice_sizes; std::vector column_1_step_sizes; std::vector column_2_step_sizes; std::vector column_3_step_sizes; typedef std::array table_out; typedef std::array table_in; + // Methods for computing the value from a key for each basic table std::vector get_table_values; private: @@ -255,19 +269,22 @@ struct MultiTable { // } /** - * @brief The structure contains the most basic table serving one function (for, example an xor table) + * @brief A basic table from which we can perform lookups (for example, an xor table) + * @details Also stores the lookup gate data for all lookups performed on this table * * @details You can find initialization example at * ../ultra_plonk_composer.cpp#UltraPlonkComposer::initialize_precomputed_table(..) * */ struct BasicTable { - struct KeyEntry { - bool operator==(const KeyEntry& other) const = default; + struct LookupEntry { + bool operator==(const LookupEntry& other) const = default; + // Storage for two key values and two result values to support different lookup formats, i.e. 1:1, 1:2, and 2:1 std::array key{ 0, 0 }; std::array value{ bb::fr(0), bb::fr(0) }; - bool operator<(const KeyEntry& other) const + // Comparison operator required for sorting; Used to construct sorted-concatenated table/lookup polynomial + bool operator<(const LookupEntry& other) const { return key[0] < other.key[0] || ((key[0] == other.key[0]) && key[1] < other.key[1]); } @@ -285,8 +302,6 @@ struct BasicTable { // Unique id of the table which is used to look it up, when we need its functionality. One of BasicTableId enum BasicTableId id; size_t table_index; - // The size of the table - size_t size; // This means that we are using two inputs to look up stuff, not translate a single entry into another one. bool use_twin_keys; @@ -294,13 +309,19 @@ struct BasicTable { bb::fr column_2_step_size = bb::fr(0); bb::fr column_3_step_size = bb::fr(0); std::vector column_1; - std::vector column_3; std::vector column_2; - std::vector lookup_gates; + std::vector column_3; + std::vector lookup_gates; // wire data for all lookup gates created for lookups on this table std::array (*get_values_from_key)(const std::array); bool operator==(const BasicTable& other) const = default; + + size_t size() const + { + ASSERT(column_1.size() == column_2.size() && column_2.size() == column_3.size()); + return column_1.size(); + } }; enum ColumnIdx { C1, C2, C3 }; @@ -324,9 +345,10 @@ template class ReadData { std::vector& operator[](ColumnIdx idx) { return columns[static_cast(idx)]; }; const std::vector& operator[](ColumnIdx idx) const { return columns[static_cast(idx)]; }; - std::vector key_entries; + std::vector lookup_entries; private: + // Container for the lookup accumulators; 0th index of each column contains full accumulated value std::array, 3> columns; }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/uint.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/uint.hpp index 1ccfecdd2a5..7ba5d03304a 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/uint.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/plookup_tables/uint.hpp @@ -19,7 +19,6 @@ inline BasicTable generate_xor_rotate_table(BasicTableId id, const size_t table_ BasicTable table; table.id = id; table.table_index = table_index; - table.size = base * base; table.use_twin_keys = true; for (uint64_t i = 0; i < base; ++i) { @@ -52,7 +51,6 @@ inline BasicTable generate_and_rotate_table(BasicTableId id, const size_t table_ BasicTable table; table.id = id; table.table_index = table_index; - table.size = base * base; table.use_twin_keys = true; for (uint64_t i = 0; i < base; ++i) { @@ -81,7 +79,7 @@ inline MultiTable get_uint32_xor_table(const MultiTableId id = UINT32_XOR) table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(base); - table.lookup_ids.emplace_back(UINT_XOR_ROTATE0); + table.basic_table_ids.emplace_back(UINT_XOR_ROTATE0); table.get_table_values.emplace_back(&get_xor_rotate_values_from_key<6, 0>); } return table; @@ -96,7 +94,7 @@ inline MultiTable get_uint32_and_table(const MultiTableId id = UINT32_AND) table.id = id; for (size_t i = 0; i < num_entries; ++i) { table.slice_sizes.emplace_back(base); - table.lookup_ids.emplace_back(UINT_AND_ROTATE0); + table.basic_table_ids.emplace_back(UINT_AND_ROTATE0); table.get_table_values.emplace_back(&get_and_rotate_values_from_key<6, 0>); } return table; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/standard_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/standard_circuit_builder.cpp index 94e10887fba..b2fada856cb 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/standard_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/standard_circuit_builder.cpp @@ -520,7 +520,7 @@ void StandardCircuitBuilder_::assert_equal_constant(uint32_t const a_idx, FF template msgpack::sbuffer StandardCircuitBuilder_::export_circuit() { using base = CircuitBuilderBase; - CircuitSchema cir; + CircuitSchemaInternal cir; uint64_t modulus[4] = { FF::Params::modulus_0, FF::Params::modulus_1, FF::Params::modulus_2, FF::Params::modulus_3 diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp index e96c234c5ab..4325a52985f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.cpp @@ -609,6 +609,14 @@ uint32_t UltraCircuitBuilder_::put_constant_variable(const FF& } } +/** + * @brief Get the basic table with provided ID from the set of tables for the present circuit; create it if it doesnt + * yet exist + * + * @tparam Arithmetization + * @param id + * @return plookup::BasicTable& + */ template plookup::BasicTable& UltraCircuitBuilder_::get_table(const plookup::BasicTableId id) { @@ -619,7 +627,7 @@ plookup::BasicTable& UltraCircuitBuilder_::get_table(const ploo } // Table doesn't exist! So try to create it. lookup_tables.emplace_back(plookup::create_basic_table(id, lookup_tables.size())); - return lookup_tables[lookup_tables.size() - 1]; + return lookup_tables.back(); } /** @@ -633,13 +641,14 @@ plookup::ReadData UltraCircuitBuilder_::create_gates_ const uint32_t key_a_index, std::optional key_b_index) { - const auto& multi_table = plookup::create_table(id); + const auto& multi_table = plookup::get_multitable(id); const size_t num_lookups = read_values[plookup::ColumnIdx::C1].size(); plookup::ReadData read_data; for (size_t i = 0; i < num_lookups; ++i) { - auto& table = get_table(multi_table.lookup_ids[i]); + // get basic lookup table; construct and add to builder.lookup_tables if not already present + auto& table = get_table(multi_table.basic_table_ids[i]); - table.lookup_gates.emplace_back(read_values.key_entries[i]); + table.lookup_gates.emplace_back(read_values.lookup_entries[i]); // used for constructing sorted polynomials const auto first_idx = (i == 0) ? key_a_index : this->add_variable(read_values[plookup::ColumnIdx::C1][i]); const auto second_idx = (i == 0 && (key_b_index.has_value())) @@ -2718,13 +2727,14 @@ template uint256_t UltraCircuitBuilder_ msgpack::sbuffer UltraCircuitBuilder_::export_circuit() { using base = CircuitBuilderBase; - CircuitSchema cir; + CircuitSchemaInternal cir; uint64_t modulus[4] = { FF::Params::modulus_0, FF::Params::modulus_1, FF::Params::modulus_2, FF::Params::modulus_3 @@ -2761,17 +2771,10 @@ template msgpack::sbuffer UltraCircuitBuilder_> block_selectors; std::vector> block_wires; for (size_t idx = 0; idx < block.size(); ++idx) { - std::vector tmp_sel = { block.q_m()[idx], - block.q_1()[idx], - block.q_2()[idx], - block.q_3()[idx], - block.q_4()[idx], - block.q_c()[idx], - block.q_arith()[idx], - block.q_lookup_type()[idx], - block.q_elliptic()[idx], - block.q_aux()[idx], - curve_b }; + std::vector tmp_sel = { block.q_m()[idx], block.q_1()[idx], block.q_2()[idx], + block.q_3()[idx], block.q_4()[idx], block.q_c()[idx], + block.q_arith()[idx], block.q_delta_range()[idx], block.q_elliptic()[idx], + block.q_aux()[idx], block.q_lookup_type()[idx], curve_b }; std::vector tmp_w = { this->real_variable_index[block.w_l()[idx]], @@ -2806,12 +2809,18 @@ template msgpack::sbuffer UltraCircuitBuilder_> tmp_table; - for (size_t i = 0; i < table.size; ++i) { + for (size_t i = 0; i < table.size(); ++i) { tmp_table.push_back({ table.column_1[i], table.column_2[i], table.column_3[i] }); } cir.lookup_tables.push_back(tmp_table); } + cir.real_variable_tags = this->real_variable_tags; + + for (const auto& list : range_lists) { + cir.range_tags[list.second.range_tag] = list.first; + } + msgpack::sbuffer buffer; msgpack::pack(buffer, cir); return buffer; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp index 10317b7a009..ce1a8b8aebf 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp @@ -281,8 +281,9 @@ class UltraCircuitBuilder_ : public CircuitBuilderBase constant_variable_indices; + // The set of lookup tables used by the circuit, plus the gate data for the lookups from each table std::vector lookup_tables; - std::vector lookup_multi_tables; + std::map range_lists; // DOCTODO: explain this. /** @@ -367,7 +368,6 @@ class UltraCircuitBuilder_ : public CircuitBuilderBase (*get_values_from_key)(const std::array)); plookup::BasicTable& get_table(const plookup::BasicTableId id); - plookup::MultiTable& create_table(const plookup::MultiTableId id); + plookup::MultiTable& get_multitable(const plookup::MultiTableId id); plookup::ReadData create_gates_from_plookup_accumulators( const plookup::MultiTableId& id, diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 5cd7326d445..909aa29d0d2 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -48,12 +48,15 @@ class UltraFlavor { using GrandProductRelations = std::tuple, bb::LookupRelation>; // define the tuple of Relations that comprise the Sumcheck relation - using Relations = std::tuple, - bb::UltraPermutationRelation, - bb::LookupRelation, - bb::DeltaRangeConstraintRelation, - bb::EllipticRelation, - bb::AuxiliaryRelation>; + // Note: made generic for use in MegaRecursive. + template + using Relations_ = std::tuple, + bb::UltraPermutationRelation, + bb::LookupRelation, + bb::DeltaRangeConstraintRelation, + bb::EllipticRelation, + bb::AuxiliaryRelation>; + using Relations = Relations_; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); static_assert(MAX_PARTIAL_RELATION_LENGTH == 6); @@ -88,7 +91,6 @@ class UltraFlavor { static constexpr bool is_decider = true; - private: /** * @brief A base class labelling precomputed entities and (ordered) subsets of interest. * @details Used to build the proving key and verification key. @@ -189,92 +191,33 @@ class UltraFlavor { * Symbolically we have: AllEntities = PrecomputedEntities + WitnessEntities + "ShiftedEntities". It could be * implemented as such, but we have this now. */ - template class AllEntities { + template + class AllEntities : public PrecomputedEntities, + public WitnessEntities, + public ShiftedEntities { public: - DEFINE_FLAVOR_MEMBERS(DataType, - q_c, // column 0 - q_l, // column 1 - q_r, // column 2 - q_o, // column 3 - q_4, // column 4 - q_m, // column 5 - q_arith, // column 6 - q_delta_range, // column 7 - q_elliptic, // column 8 - q_aux, // column 9 - q_lookup, // column 10 - sigma_1, // column 11 - sigma_2, // column 12 - sigma_3, // column 13 - sigma_4, // column 14 - id_1, // column 15 - id_2, // column 16 - id_3, // column 17 - id_4, // column 18 - table_1, // column 19 - table_2, // column 20 - table_3, // column 21 - table_4, // column 22 - lagrange_first, // column 23 - lagrange_last, // column 24 - w_l, // column 25 - w_r, // column 26 - w_o, // column 27 - w_4, // column 28 - sorted_accum, // column 29 - z_perm, // column 30 - z_lookup, // column 31 - table_1_shift, // column 32 - table_2_shift, // column 33 - table_3_shift, // column 34 - table_4_shift, // column 35 - w_l_shift, // column 36 - w_r_shift, // column 37 - w_o_shift, // column 38 - w_4_shift, // column 39 - sorted_accum_shift, // column 40 - z_perm_shift, // column 41 - z_lookup_shift) // column 42 + DEFINE_COMPOUND_GET_ALL(PrecomputedEntities, WitnessEntities, ShiftedEntities) - auto get_wires() { return RefArray{ w_l, w_r, w_o, w_4 }; }; - auto get_selectors() - { - return RefArray{ q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_delta_range, q_elliptic, q_aux, q_lookup }; - } - auto get_sigmas() { return RefArray{ sigma_1, sigma_2, sigma_3, sigma_4 }; }; - auto get_ids() { return RefArray{ id_1, id_2, id_3, id_4 }; }; - auto get_tables() { return RefArray{ table_1, table_2, table_3, table_4 }; }; + auto get_wires() { return RefArray{ this->w_l, this->w_r, this->w_o, this->w_4 }; }; + auto get_selectors() { return PrecomputedEntities::get_selectors(); } + auto get_sigmas() { return RefArray{ this->sigma_1, this->sigma_2, this->sigma_3, this->sigma_4 }; }; + auto get_ids() { return RefArray{ this->id_1, this->id_2, this->id_3, this->id_4 }; }; + auto get_tables() { return RefArray{ this->table_1, this->table_2, this->table_3, this->table_4 }; }; // Gemini-specific getters. auto get_unshifted() { - return RefArray{ q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_delta_range, - q_elliptic, q_aux, q_lookup, sigma_1, sigma_2, sigma_3, sigma_4, id_1, - id_2, id_3, id_4, table_1, table_2, table_3, table_4, lagrange_first, - lagrange_last, w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup - - }; + return concatenate(PrecomputedEntities::get_all(), WitnessEntities::get_all()); }; - auto get_precomputed() - { - return RefArray{ q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_delta_range, - q_elliptic, q_aux, q_lookup, sigma_1, sigma_2, sigma_3, sigma_4, id_1, - id_2, id_3, id_4, table_1, table_2, table_3, table_4, lagrange_first, - lagrange_last + auto get_precomputed() { return PrecomputedEntities::get_all(); } - }; - } - - auto get_witness() { return RefArray{ w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup }; }; + auto get_witness() { return WitnessEntities::get_all(); }; auto get_to_be_shifted() { - return RefArray{ table_1, table_2, table_3, table_4, w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup }; - }; - auto get_shifted() - { - return RefArray{ table_1_shift, table_2_shift, table_3_shift, table_4_shift, w_l_shift, w_r_shift, - w_o_shift, w_4_shift, sorted_accum_shift, z_perm_shift, z_lookup_shift }; + return RefArray{ this->table_1, this->table_2, this->table_3, this->table_4, this->w_l, this->w_r, + this->w_o, this->w_4, this->sorted_accum, this->z_perm, this->z_lookup }; }; + auto get_shifted() { return ShiftedEntities::get_all(); }; }; public: @@ -667,36 +610,37 @@ class UltraFlavor { * witness polynomials). * */ - class VerifierCommitments : public AllEntities { + template + class VerifierCommitments_ : public AllEntities { public: - VerifierCommitments(const std::shared_ptr& verification_key, - const std::optional& witness_commitments = std::nullopt) + VerifierCommitments_(const std::shared_ptr& verification_key, + const std::optional& witness_commitments = std::nullopt) { - q_m = verification_key->q_m; - q_c = verification_key->q_c; - q_l = verification_key->q_l; - q_r = verification_key->q_r; - q_o = verification_key->q_o; - q_4 = verification_key->q_4; - q_arith = verification_key->q_arith; - q_delta_range = verification_key->q_delta_range; - q_elliptic = verification_key->q_elliptic; - q_aux = verification_key->q_aux; - q_lookup = verification_key->q_lookup; - sigma_1 = verification_key->sigma_1; - sigma_2 = verification_key->sigma_2; - sigma_3 = verification_key->sigma_3; - sigma_4 = verification_key->sigma_4; - id_1 = verification_key->id_1; - id_2 = verification_key->id_2; - id_3 = verification_key->id_3; - id_4 = verification_key->id_4; - table_1 = verification_key->table_1; - table_2 = verification_key->table_2; - table_3 = verification_key->table_3; - table_4 = verification_key->table_4; - lagrange_first = verification_key->lagrange_first; - lagrange_last = verification_key->lagrange_last; + this->q_m = verification_key->q_m; + this->q_c = verification_key->q_c; + this->q_l = verification_key->q_l; + this->q_r = verification_key->q_r; + this->q_o = verification_key->q_o; + this->q_4 = verification_key->q_4; + this->q_arith = verification_key->q_arith; + this->q_delta_range = verification_key->q_delta_range; + this->q_elliptic = verification_key->q_elliptic; + this->q_aux = verification_key->q_aux; + this->q_lookup = verification_key->q_lookup; + this->sigma_1 = verification_key->sigma_1; + this->sigma_2 = verification_key->sigma_2; + this->sigma_3 = verification_key->sigma_3; + this->sigma_4 = verification_key->sigma_4; + this->id_1 = verification_key->id_1; + this->id_2 = verification_key->id_2; + this->id_3 = verification_key->id_3; + this->id_4 = verification_key->id_4; + this->table_1 = verification_key->table_1; + this->table_2 = verification_key->table_2; + this->table_3 = verification_key->table_3; + this->table_4 = verification_key->table_4; + this->lagrange_first = verification_key->lagrange_first; + this->lagrange_last = verification_key->lagrange_last; if (witness_commitments.has_value()) { auto commitments = witness_commitments.value(); @@ -710,6 +654,8 @@ class UltraFlavor { } } }; + // Specialize for Ultra (general case used in UltraRecursive). + using VerifierCommitments = VerifierCommitments_; /** * @brief Derived class that defines proof structure for Ultra proofs, as well as supporting functions. diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp index 2979b9ac0d0..a73509fe018 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp @@ -71,12 +71,7 @@ template class UltraRecursiveFlavor_ { static constexpr size_t NUM_WITNESS_ENTITIES = 7; // define the tuple of Relations that comprise the Sumcheck relation - using Relations = std::tuple, - bb::UltraPermutationRelation, - bb::LookupRelation, - bb::DeltaRangeConstraintRelation, - bb::EllipticRelation, - bb::AuxiliaryRelation>; + using Relations = UltraFlavor::Relations_; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); static_assert(MAX_PARTIAL_RELATION_LENGTH == 6); @@ -99,167 +94,6 @@ template class UltraRecursiveFlavor_ { // define the container for storing the univariate contribution from each relation in Sumcheck using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); - private: - template - /** - * @brief A base class labelling precomputed entities and (ordered) subsets of interest. - * @details Used to build the proving key and verification key. - */ - class PrecomputedEntities : public PrecomputedEntitiesBase { - public: - DEFINE_FLAVOR_MEMBERS(DataType, - q_m, // column 0 - q_c, // column 1 - q_l, // column 2 - q_r, // column 3 - q_o, // column 4 - q_4, // column 5 - q_arith, // column 6 - q_delta_range, // column 7 - q_elliptic, // column 8 - q_aux, // column 9 - q_lookup, // column 10 - sigma_1, // column 11 - sigma_2, // column 12 - sigma_3, // column 13 - sigma_4, // column 14 - id_1, // column 15 - id_2, // column 16 - id_3, // column 17 - id_4, // column 18 - table_1, // column 19 - table_2, // column 20 - table_3, // column 21 - table_4, // column 22 - lagrange_first, // column 23 - lagrange_last); // column 24 - - auto get_selectors() - { - return RefArray{ q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_delta_range, q_elliptic, q_aux, q_lookup }; - }; - auto get_sigma_polynomials() { return RefArray{ sigma_1, sigma_2, sigma_3, sigma_4 }; }; - auto get_id_polynomials() { return RefArray{ id_1, id_2, id_3, id_4 }; }; - - auto get_table_polynomials() { return RefArray{ table_1, table_2, table_3, table_4 }; }; - }; - - /** - * @brief Container for all witness polynomials used/constructed by the prover. - * @details Shifts are not included here since they do not occupy their own memory. - */ - template class WitnessEntities { - public: - DEFINE_FLAVOR_MEMBERS(DataType, - w_l, // column 0 - w_r, // column 1 - w_o, // column 2 - w_4, // column 3 - sorted_accum, // column 4 - z_perm, // column 5 - z_lookup // column 6 - - ); - - auto get_wires() { return RefArray{ w_l, w_r, w_o, w_4 }; }; - }; - - public: - /** - * @brief A container for the witness commitments. - */ - using WitnessCommitments = WitnessEntities; - - /** - * @brief A base class labelling all entities (for instance, all of the polynomials used by the prover during - * sumcheck) in this Honk variant along with particular subsets of interest - * @details Used to build containers for: the prover's polynomial during sumcheck; the sumcheck's folded - * polynomials; the univariates consturcted during during sumcheck; the evaluations produced by sumcheck. - * - * Symbolically we have: AllEntities = PrecomputedEntities + WitnessEntities + "ShiftedEntities". It could be - * implemented as such, but we have this now. - */ - template class AllEntities { - public: - DEFINE_FLAVOR_MEMBERS(DataType, - q_c, // column 0 - q_l, // column 1 - q_r, // column 2 - q_o, // column 3 - q_4, // column 4 - q_m, // column 5 - q_arith, // column 6 - q_delta_range, // column 7 - q_elliptic, // column 8 - q_aux, // column 9 - q_lookup, // column 10 - sigma_1, // column 11 - sigma_2, // column 12 - sigma_3, // column 13 - sigma_4, // column 14 - id_1, // column 15 - id_2, // column 16 - id_3, // column 17 - id_4, // column 18 - table_1, // column 19 - table_2, // column 20 - table_3, // column 21 - table_4, // column 22 - lagrange_first, // column 23 - lagrange_last, // column 24 - w_l, // column 25 - w_r, // column 26 - w_o, // column 27 - w_4, // column 28 - sorted_accum, // column 29 - z_perm, // column 30 - z_lookup, // column 31 - table_1_shift, // column 32 - table_2_shift, // column 33 - table_3_shift, // column 34 - table_4_shift, // column 35 - w_l_shift, // column 36 - w_r_shift, // column 37 - w_o_shift, // column 38 - w_4_shift, // column 39 - sorted_accum_shift, // column 40 - z_perm_shift, // column 41 - z_lookup_shift // column 42 - ); - - auto get_wires() { return RefArray{ w_l, w_r, w_o, w_4 }; }; - // Gemini-specific getters. - auto get_unshifted() - { - return RefArray{ q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_delta_range, - q_elliptic, q_aux, q_lookup, sigma_1, sigma_2, sigma_3, sigma_4, id_1, - id_2, id_3, id_4, table_1, table_2, table_3, table_4, lagrange_first, - lagrange_last, w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup - - }; - }; - auto get_precomputed() - { - return RefArray{ q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_delta_range, - q_elliptic, q_aux, q_lookup, sigma_1, sigma_2, sigma_3, sigma_4, id_1, - id_2, id_3, id_4, table_1, table_2, table_3, table_4, lagrange_first, - lagrange_last - - }; - } - - auto get_witness() { return RefArray{ w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup }; }; - auto get_to_be_shifted() - { - return RefArray{ table_1, table_2, table_3, table_4, w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup }; - }; - auto get_shifted() - { - return RefArray{ table_1_shift, table_2_shift, table_3_shift, table_4_shift, w_l_shift, w_r_shift, - w_o_shift, w_4_shift, sorted_accum_shift, z_perm_shift, z_lookup_shift }; - }; - }; - public: /** * @brief The verification key is responsible for storing the the commitments to the precomputed (non-witnessk) @@ -269,7 +103,8 @@ template class UltraRecursiveFlavor_ { * that, and split out separate PrecomputedPolynomials/Commitments data for clarity but also for portability of our * circuits. */ - class VerificationKey : public VerificationKey_, VerifierCommitmentKey> { + class VerificationKey + : public VerificationKey_, VerifierCommitmentKey> { public: VerificationKey(const size_t circuit_size, const size_t num_public_inputs) { @@ -357,60 +192,17 @@ template class UltraRecursiveFlavor_ { * @brief A field element for each entity of the flavor. These entities represent the prover polynomials * evaluated at one point. */ - class AllValues : public AllEntities { + class AllValues : public UltraFlavor::AllEntities { public: - using Base = AllEntities; + using Base = UltraFlavor::AllEntities; using Base::Base; - AllValues(std::array _data_in) { this->_data = _data_in; } }; - /** - * @brief A container for commitment labels. - * @note It's debatable whether this should inherit from AllEntities. since most entries are not strictly - * needed. It has, however, been useful during debugging to have these labels available. - * - */ - class CommitmentLabels : public AllEntities { - public: - CommitmentLabels() - { - this->w_l = "W_L"; - this->w_r = "W_R"; - this->w_o = "W_O"; - this->w_4 = "W_4"; - this->z_perm = "Z_PERM"; - this->z_lookup = "Z_LOOKUP"; - this->sorted_accum = "SORTED_ACCUM"; + using CommitmentLabels = UltraFlavor::CommitmentLabels; - this->q_c = "Q_C"; - this->q_l = "Q_L"; - this->q_r = "Q_R"; - this->q_o = "Q_O"; - this->q_4 = "Q_4"; - this->q_m = "Q_M"; - this->q_arith = "Q_ARITH"; - this->q_delta_range = "Q_SORT"; - this->q_elliptic = "Q_ELLIPTIC"; - this->q_aux = "Q_AUX"; - this->q_lookup = "Q_LOOKUP"; - this->sigma_1 = "SIGMA_1"; - this->sigma_2 = "SIGMA_2"; - this->sigma_3 = "SIGMA_3"; - this->sigma_4 = "SIGMA_4"; - this->id_1 = "ID_1"; - this->id_2 = "ID_2"; - this->id_3 = "ID_3"; - this->id_4 = "ID_4"; - this->table_1 = "TABLE_1"; - this->table_2 = "TABLE_2"; - this->table_3 = "TABLE_3"; - this->table_4 = "TABLE_4"; - this->lagrange_first = "LAGRANGE_FIRST"; - this->lagrange_last = "LAGRANGE_LAST"; - }; - }; + using WitnessCommitments = UltraFlavor::WitnessEntities; - class VerifierCommitments : public AllEntities { + class VerifierCommitments : public UltraFlavor::AllEntities { public: VerifierCommitments(const std::shared_ptr& verification_key, const std::optional& witness_commitments = std::nullopt) diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp index 60e5afd118b..039591d2ba4 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp @@ -49,7 +49,7 @@ template bool UltraVerifier_::verify_proof(const HonkP transcript = std::make_shared(proof); VerifierCommitments commitments{ key }; OinkVerifier oink_verifier{ key, transcript }; - auto [relation_parameters, witness_commitments, _, alphas] = oink_verifier.verify(); + auto [relation_parameters, witness_commitments, public_inputs, alphas] = oink_verifier.verify(); // Copy the witness_commitments over to the VerifierCommitments for (auto [wit_comm_1, wit_comm_2] : zip_view(commitments.get_witness(), witness_commitments.get_all())) { diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp index 36fcd78744d..5a81dc569c3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.cpp @@ -2,15 +2,6 @@ namespace bb::avm_trace { -/** - * @brief Constructor of Alu trace builder of AVM. Only serves to set the capacity of the - * underlying trace. - */ -AvmAluTraceBuilder::AvmAluTraceBuilder() -{ - alu_trace.reserve(AVM_TRACE_SIZE); -} - /** * @brief Resetting the internal state so that a new Alu trace can be rebuilt using the same object. * diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp index a5445e1861c..fdd751b0cf8 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_alu_trace.hpp @@ -81,7 +81,7 @@ class AvmAluTraceBuilder { std::array, 15> u16_range_chk_counters; std::array, 8> div_u64_range_chk_counters; - AvmAluTraceBuilder(); + AvmAluTraceBuilder() = default; void reset(); std::vector finalize(); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_binary_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_binary_trace.cpp index 15384be9804..c87b4924fd3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_binary_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_binary_trace.cpp @@ -10,11 +10,6 @@ namespace bb::avm_trace { -AvmBinaryTraceBuilder::AvmBinaryTraceBuilder() -{ - binary_trace.reserve(AVM_TRACE_SIZE); -} - std::vector AvmBinaryTraceBuilder::finalize() { return std::move(binary_trace); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_binary_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_binary_trace.hpp index 29a88f5f9d5..9aa6cab9220 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_binary_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_binary_trace.hpp @@ -31,7 +31,7 @@ class AvmBinaryTraceBuilder { std::unordered_map byte_operation_counter; std::unordered_map byte_length_counter; - AvmBinaryTraceBuilder(); + AvmBinaryTraceBuilder() = default; void reset(); // Finalize the trace std::vector finalize(); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp index 40dde3ae6e9..1ff41a277cd 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp @@ -15,9 +15,8 @@ namespace bb::avm_trace { using Flavor = bb::AvmFlavor; using FF = Flavor::FF; -} // namespace bb::avm_trace - -namespace bb::avm_trace { +// To toggle all relevant unit tests with proving, set the env variable "AVM_ENABLE_FULL_PROVING". +static const bool ENABLE_PROVING = std::getenv("AVM_ENABLE_FULL_PROVING") != nullptr; // There are 4 public input columns, 1 for context inputs, and 3 for emitting side effects using VmPublicInputs = std::tuple, // Input: Kernel context inputs diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp index 6b10ab40afc..891d2af5695 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_deserialization.cpp @@ -158,6 +158,8 @@ const std::unordered_map> OPCODE_WIRE_FORMAT = OperandType::UINT32, // rhs.y OperandType::UINT32, // rhs.is_infinite OperandType::UINT32 } }, // dst_offset + { OpCode::MSM, + { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, // Gadget - Conversion { OpCode::TORADIXLE, { OperandType::INDIRECT, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32, OperandType::UINT32 } }, diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp index a3447e24c6e..f3d2dac5f2d 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp @@ -677,6 +677,13 @@ std::vector Execution::gen_trace(std::vector const& instructio std::get(inst.operands.at(6)), std::get(inst.operands.at(7))); break; + case OpCode::MSM: + trace_builder.op_variable_msm(std::get(inst.operands.at(0)), + std::get(inst.operands.at(1)), + std::get(inst.operands.at(2)), + std::get(inst.operands.at(3)), + std::get(inst.operands.at(4))); + break; case OpCode::REVERT: trace_builder.op_revert(std::get(inst.operands.at(0)), std::get(inst.operands.at(1)), diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_gas_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_gas_trace.cpp index 305e0d0d15f..4c8bb0f9872 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_gas_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_gas_trace.cpp @@ -3,8 +3,6 @@ namespace bb::avm_trace { -AvmGasTraceBuilder::AvmGasTraceBuilder() = default; - void AvmGasTraceBuilder::reset() { gas_trace.clear(); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_gas_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_gas_trace.hpp index 9934164ad23..8085321586b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_gas_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_gas_trace.hpp @@ -109,6 +109,7 @@ static const inline std::unordered_map GAS_COST_TABLE = { // Sentinel // LAST_OPCODE_SENTINEL, }; + class AvmGasTraceBuilder { public: struct GasTraceEntry { @@ -124,8 +125,7 @@ class AvmGasTraceBuilder { // opcode -> count std::unordered_map gas_opcode_lookup_counter; - // Constructor receives copy of kernel_inputs from the main trace builder - AvmGasTraceBuilder(); + AvmGasTraceBuilder() = default; void reset(); std::vector finalize(); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.cpp index 13c74741223..8a508442aa5 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_helper.cpp @@ -14,99 +14,102 @@ namespace bb::avm_trace { * @param beg The index of the beginning of the slice. (included) * @param end The index of the end of the slice (not included). */ -void log_avm_trace(std::vector const& trace, size_t beg, size_t end, bool enable_selectors) +void log_avm_trace([[maybe_unused]] std::vector const& trace, + [[maybe_unused]] size_t beg, + [[maybe_unused]] size_t end, + [[maybe_unused]] bool enable_selectors) { - { - info("Built circuit with ", trace.size(), " rows"); - - for (size_t i = beg; i < end; i++) { - info("====================================================================================="); - info("== ROW ", i); - info("====================================================================================="); - - info("=======MEMORY TRACE=================================================================="); - info("m_addr: ", trace.at(i).avm_mem_addr); - info("m_clk: ", trace.at(i).avm_mem_clk); - info("m_tsp: ", trace.at(i).avm_mem_tsp); - info("m_sub_clk: ", uint32_t(trace.at(i).avm_mem_tsp) % AvmMemTraceBuilder::NUM_SUB_CLK); - info("m_val: ", trace.at(i).avm_mem_val); - info("m_rw: ", trace.at(i).avm_mem_rw); - info("m_tag: ", trace.at(i).avm_mem_tag); - info("r_in_tag: ", trace.at(i).avm_mem_r_in_tag); - info("w_in_tag: ", trace.at(i).avm_mem_w_in_tag); - info("m_tag_err: ", trace.at(i).avm_mem_tag_err); - info("m_one_min_inv: ", trace.at(i).avm_mem_one_min_inv); - - info("m_lastAccess: ", trace.at(i).avm_mem_lastAccess); - info("m_last: ", trace.at(i).avm_mem_last); - info("m_val_shift: ", trace.at(i).avm_mem_val_shift); - - info("=======CONTROL_FLOW==================================================================="); - info("pc: ", trace.at(i).avm_main_pc); - info("internal_call: ", trace.at(i).avm_main_sel_internal_call); - info("internal_return: ", trace.at(i).avm_main_sel_internal_return); - info("internal_return_ptr:", trace.at(i).avm_main_internal_return_ptr); - - info("=======ALU TRACE====================================================================="); - info("alu_clk ", trace.at(i).avm_alu_clk); - info("alu_ia ", trace.at(i).avm_alu_ia); - info("alu_ib ", trace.at(i).avm_alu_ib); - info("alu_ic ", trace.at(i).avm_alu_ic); - - info("=======MAIN TRACE===================================================================="); - info("clk: ", trace.at(i).avm_main_clk); - info("ia: ", trace.at(i).avm_main_ia); - info("ib: ", trace.at(i).avm_main_ib); - info("ic: ", trace.at(i).avm_main_ic); - info("r_in_tag ", trace.at(i).avm_main_r_in_tag); - info("w_in_tag ", trace.at(i).avm_main_w_in_tag); - info("tag_err ", trace.at(i).avm_main_tag_err); - info("first: ", trace.at(i).avm_main_first); - info("last: ", trace.at(i).avm_main_last); - - info("=======MEM_OP_A======================================================================"); - info("mem_op_a: ", trace.at(i).avm_main_mem_op_a); - info("mem_idx_a: ", trace.at(i).avm_main_mem_idx_a); - info("rwa: ", trace.at(i).avm_main_rwa); - - info("=======MEM_OP_B======================================================================"); - info("mem_op_b: ", trace.at(i).avm_main_mem_op_b); - info("mem_idx_b: ", trace.at(i).avm_main_mem_idx_b); - info("rwb: ", trace.at(i).avm_main_rwb); - - info("=======MEM_OP_C======================================================================"); - info("mem_op_c: ", trace.at(i).avm_main_mem_op_c); - info("mem_idx_c: ", trace.at(i).avm_main_mem_idx_c); - info("rwc: ", trace.at(i).avm_main_rwc); - info("diff_hi: ", trace.at(i).avm_mem_diff_hi); - info("diff_mid: ", trace.at(i).avm_mem_diff_mid); - info("diff_lo: ", trace.at(i).avm_mem_diff_lo); - - info("=======GAS ACCOUNTING================================================================"); - info("opcode active: ", trace.at(i).avm_main_gas_cost_active); - info("l2_gas_remaining: ", trace.at(i).avm_main_l2_gas_remaining); - info("da_gas_remaining: ", trace.at(i).avm_main_da_gas_remaining); - info("l2_gas_op: ", trace.at(i).avm_main_l2_gas_op); - info("da_gas_op: ", trace.at(i).avm_main_da_gas_op); - info("l2_out_of_gas: ", trace.at(i).avm_main_l2_out_of_gas); - info("da_out_of_gas: ", trace.at(i).avm_main_da_out_of_gas); - info("abs_l2_hi_rem_gas: ", trace.at(i).avm_main_abs_l2_rem_gas_hi); - info("abs_l2_lo_rem_gas: ", trace.at(i).avm_main_abs_l2_rem_gas_lo); - info("abs_da_hi_rem_gas: ", trace.at(i).avm_main_abs_da_rem_gas_hi); - info("abs_da_lo_rem_gas: ", trace.at(i).avm_main_abs_da_rem_gas_lo); - - if (enable_selectors) { - info("=======SELECTORS======================================================================"); - info("sel_op_add: ", trace.at(i).avm_main_sel_op_add); - info("sel_op_sub: ", trace.at(i).avm_main_sel_op_sub); - info("sel_op_mul: ", trace.at(i).avm_main_sel_op_mul); - info("sel_op_eq: ", trace.at(i).avm_main_sel_op_eq); - info("sel_op_not: ", trace.at(i).avm_main_sel_op_not); - info("sel_op_sel_alu: ", trace.at(i).avm_main_alu_sel); - } - info("\n"); + /* + info("Built circuit with ", trace.size(), " rows"); + + for (size_t i = beg; i < end; i++) { + info("====================================================================================="); + info("== ROW ", i); + info("====================================================================================="); + + info("=======MEMORY TRACE=================================================================="); + info("m_addr: ", trace.at(i).mem_addr); + info("m_clk: ", trace.at(i).mem_clk); + info("m_tsp: ", trace.at(i).mem_tsp); + info("m_sub_clk: ", uint32_t(trace.at(i).mem_tsp) % AvmMemTraceBuilder::NUM_SUB_CLK); + info("m_val: ", trace.at(i).mem_val); + info("m_rw: ", trace.at(i).mem_rw); + info("m_tag: ", trace.at(i).mem_tag); + info("r_in_tag: ", trace.at(i).mem_r_in_tag); + info("w_in_tag: ", trace.at(i).mem_w_in_tag); + info("m_tag_err: ", trace.at(i).mem_tag_err); + info("m_one_min_inv: ", trace.at(i).mem_one_min_inv); + + info("m_lastAccess: ", trace.at(i).mem_lastAccess); + info("m_last: ", trace.at(i).mem_last); + info("m_val_shift: ", trace.at(i).mem_val_shift); + + info("=======CONTROL_FLOW==================================================================="); + info("pc: ", trace.at(i).main_pc); + info("internal_call: ", trace.at(i).main_sel_op_internal_call); + info("internal_return: ", trace.at(i).main_sel_op_internal_return); + info("internal_return_ptr:", trace.at(i).main_internal_return_ptr); + + info("=======ALU TRACE====================================================================="); + info("alu_clk ", trace.at(i).alu_clk); + info("alu_ia ", trace.at(i).alu_ia); + info("alu_ib ", trace.at(i).alu_ib); + info("alu_ic ", trace.at(i).alu_ic); + + info("=======MAIN TRACE===================================================================="); + info("clk: ", trace.at(i).main_clk); + info("ia: ", trace.at(i).main_ia); + info("ib: ", trace.at(i).main_ib); + info("ic: ", trace.at(i).main_ic); + info("r_in_tag ", trace.at(i).main_r_in_tag); + info("w_in_tag ", trace.at(i).main_w_in_tag); + info("tag_err ", trace.at(i).main_tag_err); + info("first: ", trace.at(i).main_sel_first); + info("last: ", trace.at(i).main_sel_last); + + info("=======MEM_OP_A======================================================================"); + info("mem_op_a: ", trace.at(i).main_mem_op_a); + info("mem_idx_a: ", trace.at(i).main_mem_idx_a); + info("rwa: ", trace.at(i).main_rwa); + + info("=======MEM_OP_B======================================================================"); + info("mem_op_b: ", trace.at(i).main_mem_op_b); + info("mem_idx_b: ", trace.at(i).main_mem_idx_b); + info("rwb: ", trace.at(i).main_rwb); + + info("=======MEM_OP_C======================================================================"); + info("mem_op_c: ", trace.at(i).main_mem_op_c); + info("mem_idx_c: ", trace.at(i).main_mem_idx_c); + info("rwc: ", trace.at(i).main_rwc); + info("diff_hi: ", trace.at(i).mem_diff_hi); + info("diff_mid: ", trace.at(i).mem_diff_mid); + info("diff_lo: ", trace.at(i).mem_diff_lo); + + info("=======GAS ACCOUNTING================================================================"); + info("opcode active: ", trace.at(i).main_gas_cost_active); + info("l2_gas_remaining: ", trace.at(i).main_l2_gas_remaining); + info("da_gas_remaining: ", trace.at(i).main_da_gas_remaining); + info("l2_gas_op: ", trace.at(i).main_l2_gas_op); + info("da_gas_op: ", trace.at(i).main_da_gas_op); + info("l2_out_of_gas: ", trace.at(i).main_l2_out_of_gas); + info("da_out_of_gas: ", trace.at(i).main_da_out_of_gas); + info("abs_l2_hi_rem_gas: ", trace.at(i).main_abs_l2_rem_gas_hi); + info("abs_l2_lo_rem_gas: ", trace.at(i).main_abs_l2_rem_gas_lo); + info("abs_da_hi_rem_gas: ", trace.at(i).main_abs_da_rem_gas_hi); + info("abs_da_lo_rem_gas: ", trace.at(i).main_abs_da_rem_gas_lo); + + if (enable_selectors) { + info("=======SELECTORS======================================================================"); + info("sel_op_add: ", trace.at(i).main_sel_op_add); + info("sel_op_sub: ", trace.at(i).main_sel_op_sub); + info("sel_op_mul: ", trace.at(i).main_sel_op_mul); + info("sel_op_eq: ", trace.at(i).main_sel_op_eq); + info("sel_op_not: ", trace.at(i).main_sel_op_not); + info("sel_op_sel_alu: ", trace.at(i).main_alu_sel); } + info("\n"); } + */ } void dump_trace_as_csv(std::vector const& trace, std::filesystem::path const& filename) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_kernel_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_kernel_trace.hpp index 068d82517e3..a8c43f66046 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_kernel_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_kernel_trace.hpp @@ -114,9 +114,9 @@ class AvmKernelTraceBuilder { START_NULLIFIER_NON_EXISTS_OFFSET + MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL; static const uint32_t START_SSTORE_WRITE_OFFSET = - START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL; + START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL; static const uint32_t START_SLOAD_WRITE_OFFSET = - START_SSTORE_WRITE_OFFSET + MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL; + START_SSTORE_WRITE_OFFSET + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL; static const uint32_t START_EMIT_NOTE_HASH_WRITE_OFFSET = START_SLOAD_WRITE_OFFSET + MAX_PUBLIC_DATA_READS_PER_CALL; static const uint32_t START_EMIT_NULLIFIER_WRITE_OFFSET = diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp index d3c38f0665d..8ee4f02595f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.cpp @@ -228,7 +228,7 @@ AvmMemTraceBuilder::MemEntry AvmMemTraceBuilder::read_and_load_mov_opcode(uint8_ .m_tag = mem_entry.tag, .r_in_tag = mem_entry.tag, .w_in_tag = mem_entry.tag, - .m_sel_mov_a = true, + .m_sel_mov_ia_to_ic = true, }); return mem_entry; @@ -271,7 +271,7 @@ std::array AvmMemTraceBuilder::read_and_load_cm .m_tag = a_mem_entry.tag, .r_in_tag = r_w_in_tag, .w_in_tag = r_w_in_tag, - .m_sel_mov_a = !mov_b, + .m_sel_mov_ia_to_ic = !mov_b, .m_sel_cmov = true, }); @@ -284,7 +284,7 @@ std::array AvmMemTraceBuilder::read_and_load_cm .m_tag = b_mem_entry.tag, .r_in_tag = r_w_in_tag, .w_in_tag = r_w_in_tag, - .m_sel_mov_b = mov_b, + .m_sel_mov_ib_to_ic = mov_b, .m_sel_cmov = true, }); @@ -483,4 +483,35 @@ void AvmMemTraceBuilder::write_into_memory(uint8_t space_id, store_in_mem_trace(space_id, clk, interm_reg, addr, val, r_in_tag, w_in_tag); } +bool AvmMemTraceBuilder::MemoryTraceEntry::operator<(const AvmMemTraceBuilder::MemoryTraceEntry& other) const +{ + if (m_space_id < other.m_space_id) { + return true; + } + + if (m_space_id > other.m_space_id) { + return false; + } + + if (m_addr < other.m_addr) { + return true; + } + + if (m_addr > other.m_addr) { + return false; + } + + if (m_clk < other.m_clk) { + return true; + } + + if (m_clk > other.m_clk) { + return false; + } + + // No safeguard in case they are equal. The caller should ensure this property. + // Otherwise, relation will not be satisfied. + return m_sub_clk < other.m_sub_clk; +} + } // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.hpp index 4efaf4f58fc..bd8e4b121e9 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_mem_trace.hpp @@ -28,19 +28,19 @@ class AvmMemTraceBuilder { std::map m_tag_err_lookup_counts; struct MemoryTraceEntry { - uint8_t m_space_id{}; - uint32_t m_clk{}; - uint32_t m_sub_clk{}; - uint32_t m_addr{}; + uint8_t m_space_id = 0; + uint32_t m_clk = 0; + uint32_t m_sub_clk = 0; + uint32_t m_addr = 0; FF m_val{}; - AvmMemoryTag m_tag{}; - AvmMemoryTag r_in_tag{}; - AvmMemoryTag w_in_tag{}; + AvmMemoryTag m_tag; + AvmMemoryTag r_in_tag; + AvmMemoryTag w_in_tag; bool m_rw = false; bool m_tag_err = false; FF m_one_min_inv{}; - bool m_sel_mov_a = false; - bool m_sel_mov_b = false; + bool m_sel_mov_ia_to_ic = false; + bool m_sel_mov_ib_to_ic = false; bool m_sel_cmov = false; bool m_tag_err_count_relevant = false; @@ -48,36 +48,7 @@ class AvmMemTraceBuilder { * @brief A comparator on MemoryTraceEntry to be used by sorting algorithm. We sort first by * ascending address (m_addr), then by clock (m_clk) and finally sub-clock (m_sub_clk). */ - bool operator<(const MemoryTraceEntry& other) const - { - if (m_space_id < other.m_space_id) { - return true; - } - - if (m_space_id > other.m_space_id) { - return false; - } - - if (m_addr < other.m_addr) { - return true; - } - - if (m_addr > other.m_addr) { - return false; - } - - if (m_clk < other.m_clk) { - return true; - } - - if (m_clk > other.m_clk) { - return false; - } - - // No safeguard in case they are equal. The caller should ensure this property. - // Otherwise, relation will not be satisfied. - return m_sub_clk < other.m_sub_clk; - } + bool operator<(MemoryTraceEntry const& other) const; }; // Structure representing an entry for the memory used in the simulation (not the trace). diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.cpp index 8ffe817e23a..2439fd4e0a2 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.cpp @@ -144,6 +144,10 @@ std::string to_string(OpCode opcode) return "SHA256"; case OpCode::PEDERSEN: return "PEDERSEN"; + case OpCode::ECADD: + return "ECADD"; + case OpCode::MSM: + return "MSM"; case OpCode::TORADIXLE: return "TORADIXLE"; case OpCode::SHA256COMPRESSION: diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.hpp index 83de32e6568..e3ced1a03e7 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_opcode.hpp @@ -105,6 +105,7 @@ enum class OpCode : uint8_t { SHA256, PEDERSEN, ECADD, + MSM, // Conversions TORADIXLE, // Future Gadgets -- pending changes in noir diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp index 5c1ac86c7c3..c97c71eccb2 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp @@ -14,7 +14,9 @@ #include #include "barretenberg/common/throw_or_abort.hpp" +#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" +#include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/vm/avm_trace/avm_common.hpp" #include "barretenberg/vm/avm_trace/avm_helper.hpp" #include "barretenberg/vm/avm_trace/avm_opcode.hpp" @@ -150,31 +152,31 @@ void AvmTraceBuilder::op_add( gas_trace_builder.constrain_gas_lookup(clk, OpCode::ADD); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_alu_in_tag = FF(static_cast(in_tag)), - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a, - .avm_main_ib = b, - .avm_main_ic = c, - .avm_main_ind_a = res.indirect_flag_a ? FF(a_offset) : FF(0), - .avm_main_ind_b = res.indirect_flag_b ? FF(b_offset) : FF(0), - .avm_main_ind_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(res.indirect_flag_a)), - .avm_main_ind_op_b = FF(static_cast(res.indirect_flag_b)), - .avm_main_ind_op_c = FF(static_cast(res.indirect_flag_c)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(res.direct_a_offset), - .avm_main_mem_idx_b = FF(res.direct_b_offset), - .avm_main_mem_idx_c = FF(res.direct_c_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(in_tag)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_add = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(in_tag)), + .main_clk = clk, + .main_alu_in_tag = FF(static_cast(in_tag)), + .main_call_ptr = call_ptr, + .main_ia = a, + .main_ib = b, + .main_ic = c, + .main_ind_addr_a = res.indirect_flag_a ? FF(a_offset) : FF(0), + .main_ind_addr_b = res.indirect_flag_b ? FF(b_offset) : FF(0), + .main_ind_addr_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(res.direct_a_offset), + .main_mem_addr_b = FF(res.direct_b_offset), + .main_mem_addr_c = FF(res.direct_c_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(in_tag)), + .main_rwc = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_add = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(res.indirect_flag_a)), + .main_sel_resolve_ind_addr_b = FF(static_cast(res.indirect_flag_b)), + .main_sel_resolve_ind_addr_c = FF(static_cast(res.indirect_flag_c)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(in_tag)), }); } @@ -218,31 +220,31 @@ void AvmTraceBuilder::op_sub( gas_trace_builder.constrain_gas_lookup(clk, OpCode::SUB); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_alu_in_tag = FF(static_cast(in_tag)), - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a, - .avm_main_ib = b, - .avm_main_ic = c, - .avm_main_ind_a = res.indirect_flag_a ? FF(a_offset) : FF(0), - .avm_main_ind_b = res.indirect_flag_b ? FF(b_offset) : FF(0), - .avm_main_ind_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(res.indirect_flag_a)), - .avm_main_ind_op_b = FF(static_cast(res.indirect_flag_b)), - .avm_main_ind_op_c = FF(static_cast(res.indirect_flag_c)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(res.direct_a_offset), - .avm_main_mem_idx_b = FF(res.direct_b_offset), - .avm_main_mem_idx_c = FF(res.direct_c_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(in_tag)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_sub = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(in_tag)), + .main_clk = clk, + .main_alu_in_tag = FF(static_cast(in_tag)), + .main_call_ptr = call_ptr, + .main_ia = a, + .main_ib = b, + .main_ic = c, + .main_ind_addr_a = res.indirect_flag_a ? FF(a_offset) : FF(0), + .main_ind_addr_b = res.indirect_flag_b ? FF(b_offset) : FF(0), + .main_ind_addr_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(res.direct_a_offset), + .main_mem_addr_b = FF(res.direct_b_offset), + .main_mem_addr_c = FF(res.direct_c_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(in_tag)), + .main_rwc = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_sub = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(res.indirect_flag_a)), + .main_sel_resolve_ind_addr_b = FF(static_cast(res.indirect_flag_b)), + .main_sel_resolve_ind_addr_c = FF(static_cast(res.indirect_flag_c)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(in_tag)), }); } @@ -286,31 +288,31 @@ void AvmTraceBuilder::op_mul( gas_trace_builder.constrain_gas_lookup(clk, OpCode::MUL); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_alu_in_tag = FF(static_cast(in_tag)), - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a, - .avm_main_ib = b, - .avm_main_ic = c, - .avm_main_ind_a = res.indirect_flag_a ? FF(a_offset) : FF(0), - .avm_main_ind_b = res.indirect_flag_b ? FF(b_offset) : FF(0), - .avm_main_ind_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(res.indirect_flag_a)), - .avm_main_ind_op_b = FF(static_cast(res.indirect_flag_b)), - .avm_main_ind_op_c = FF(static_cast(res.indirect_flag_c)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(res.direct_a_offset), - .avm_main_mem_idx_b = FF(res.direct_b_offset), - .avm_main_mem_idx_c = FF(res.direct_c_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(in_tag)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_mul = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(in_tag)), + .main_clk = clk, + .main_alu_in_tag = FF(static_cast(in_tag)), + .main_call_ptr = call_ptr, + .main_ia = a, + .main_ib = b, + .main_ic = c, + .main_ind_addr_a = res.indirect_flag_a ? FF(a_offset) : FF(0), + .main_ind_addr_b = res.indirect_flag_b ? FF(b_offset) : FF(0), + .main_ind_addr_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(res.direct_a_offset), + .main_mem_addr_b = FF(res.direct_b_offset), + .main_mem_addr_c = FF(res.direct_c_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(in_tag)), + .main_rwc = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_mul = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(res.indirect_flag_a)), + .main_sel_resolve_ind_addr_b = FF(static_cast(res.indirect_flag_b)), + .main_sel_resolve_ind_addr_c = FF(static_cast(res.indirect_flag_c)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(in_tag)), }); } @@ -363,32 +365,32 @@ void AvmTraceBuilder::op_fdiv(uint8_t indirect, uint32_t a_offset, uint32_t b_of gas_trace_builder.constrain_gas_lookup(clk, OpCode::FDIV); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_call_ptr = call_ptr, - .avm_main_ia = tag_match ? a : FF(0), - .avm_main_ib = tag_match ? b : FF(0), - .avm_main_ic = tag_match ? c : FF(0), - .avm_main_ind_a = res.indirect_flag_a ? FF(a_offset) : FF(0), - .avm_main_ind_b = res.indirect_flag_b ? FF(b_offset) : FF(0), - .avm_main_ind_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(res.indirect_flag_a)), - .avm_main_ind_op_b = FF(static_cast(res.indirect_flag_b)), - .avm_main_ind_op_c = FF(static_cast(res.indirect_flag_c)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_inv = tag_match ? inv : FF(1), - .avm_main_mem_idx_a = FF(res.direct_a_offset), - .avm_main_mem_idx_b = FF(res.direct_b_offset), - .avm_main_mem_idx_c = FF(res.direct_c_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_op_err = tag_match ? error : FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_fdiv = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_clk = clk, + .main_call_ptr = call_ptr, + .main_ia = tag_match ? a : FF(0), + .main_ib = tag_match ? b : FF(0), + .main_ic = tag_match ? c : FF(0), + .main_ind_addr_a = res.indirect_flag_a ? FF(a_offset) : FF(0), + .main_ind_addr_b = res.indirect_flag_b ? FF(b_offset) : FF(0), + .main_ind_addr_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_inv = tag_match ? inv : FF(1), + .main_mem_addr_a = FF(res.direct_a_offset), + .main_mem_addr_b = FF(res.direct_b_offset), + .main_mem_addr_c = FF(res.direct_c_offset), + .main_op_err = tag_match ? error : FF(1), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_rwc = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_fdiv = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(res.indirect_flag_a)), + .main_sel_resolve_ind_addr_b = FF(static_cast(res.indirect_flag_b)), + .main_sel_resolve_ind_addr_c = FF(static_cast(res.indirect_flag_c)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), }); } @@ -443,26 +445,26 @@ void AvmTraceBuilder::op_not(uint8_t indirect, uint32_t a_offset, uint32_t dst_o gas_trace_builder.constrain_gas_lookup(clk, OpCode::NOT); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_alu_in_tag = FF(static_cast(in_tag)), - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a, - .avm_main_ic = c, - .avm_main_ind_a = indirect_a_flag ? FF(a_offset) : FF(0), - .avm_main_ind_c = indirect_c_flag ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect_a_flag)), - .avm_main_ind_op_c = FF(static_cast(indirect_c_flag)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(direct_a_offset), - .avm_main_mem_idx_c = FF(direct_dst_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(in_tag)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_not = FF(1), - .avm_main_tag_err = FF(static_cast(!read_a.tag_match)), - .avm_main_w_in_tag = FF(static_cast(in_tag)), + .main_clk = clk, + .main_alu_in_tag = FF(static_cast(in_tag)), + .main_call_ptr = call_ptr, + .main_ia = a, + .main_ic = c, + .main_ind_addr_a = indirect_a_flag ? FF(a_offset) : FF(0), + .main_ind_addr_c = indirect_c_flag ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_a_offset), + .main_mem_addr_c = FF(direct_dst_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(in_tag)), + .main_rwc = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_not = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_a_flag)), + .main_sel_resolve_ind_addr_c = FF(static_cast(indirect_c_flag)), + .main_tag_err = FF(static_cast(!read_a.tag_match)), + .main_w_in_tag = FF(static_cast(in_tag)), }); } @@ -506,31 +508,31 @@ void AvmTraceBuilder::op_eq( gas_trace_builder.constrain_gas_lookup(clk, OpCode::EQ); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_alu_in_tag = FF(static_cast(in_tag)), - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a, - .avm_main_ib = b, - .avm_main_ic = c, - .avm_main_ind_a = res.indirect_flag_a ? FF(a_offset) : FF(0), - .avm_main_ind_b = res.indirect_flag_b ? FF(b_offset) : FF(0), - .avm_main_ind_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(res.indirect_flag_a)), - .avm_main_ind_op_b = FF(static_cast(res.indirect_flag_b)), - .avm_main_ind_op_c = FF(static_cast(res.indirect_flag_c)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(res.direct_a_offset), - .avm_main_mem_idx_b = FF(res.direct_b_offset), - .avm_main_mem_idx_c = FF(res.direct_c_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(in_tag)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_eq = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), + .main_clk = clk, + .main_alu_in_tag = FF(static_cast(in_tag)), + .main_call_ptr = call_ptr, + .main_ia = a, + .main_ib = b, + .main_ic = c, + .main_ind_addr_a = res.indirect_flag_a ? FF(a_offset) : FF(0), + .main_ind_addr_b = res.indirect_flag_b ? FF(b_offset) : FF(0), + .main_ind_addr_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(res.direct_a_offset), + .main_mem_addr_b = FF(res.direct_b_offset), + .main_mem_addr_c = FF(res.direct_c_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(in_tag)), + .main_rwc = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_eq = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(res.indirect_flag_a)), + .main_sel_resolve_ind_addr_b = FF(static_cast(res.indirect_flag_b)), + .main_sel_resolve_ind_addr_c = FF(static_cast(res.indirect_flag_c)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), }); } @@ -561,32 +563,32 @@ void AvmTraceBuilder::op_and( gas_trace_builder.constrain_gas_lookup(clk, OpCode::AND); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_bin_op_id = FF(0), - .avm_main_bin_sel = FF(1), - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a, - .avm_main_ib = b, - .avm_main_ic = c, - .avm_main_ind_a = res.indirect_flag_a ? FF(a_offset) : FF(0), - .avm_main_ind_b = res.indirect_flag_b ? FF(b_offset) : FF(0), - .avm_main_ind_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(res.indirect_flag_a)), - .avm_main_ind_op_b = FF(static_cast(res.indirect_flag_b)), - .avm_main_ind_op_c = FF(static_cast(res.indirect_flag_c)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(res.direct_a_offset), - .avm_main_mem_idx_b = FF(res.direct_b_offset), - .avm_main_mem_idx_c = FF(res.direct_c_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(in_tag)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_and = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(in_tag)), + .main_clk = clk, + .main_bin_op_id = FF(0), + .main_call_ptr = call_ptr, + .main_ia = a, + .main_ib = b, + .main_ic = c, + .main_ind_addr_a = res.indirect_flag_a ? FF(a_offset) : FF(0), + .main_ind_addr_b = res.indirect_flag_b ? FF(b_offset) : FF(0), + .main_ind_addr_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(res.direct_a_offset), + .main_mem_addr_b = FF(res.direct_b_offset), + .main_mem_addr_c = FF(res.direct_c_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(in_tag)), + .main_rwc = FF(1), + .main_sel_bin = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_and = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(res.indirect_flag_a)), + .main_sel_resolve_ind_addr_b = FF(static_cast(res.indirect_flag_b)), + .main_sel_resolve_ind_addr_c = FF(static_cast(res.indirect_flag_c)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(in_tag)), }); } @@ -617,32 +619,32 @@ void AvmTraceBuilder::op_or( gas_trace_builder.constrain_gas_lookup(clk, OpCode::OR); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_bin_op_id = FF(1), - .avm_main_bin_sel = FF(1), - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a, - .avm_main_ib = b, - .avm_main_ic = c, - .avm_main_ind_a = res.indirect_flag_a ? FF(a_offset) : FF(0), - .avm_main_ind_b = res.indirect_flag_b ? FF(b_offset) : FF(0), - .avm_main_ind_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(res.indirect_flag_a)), - .avm_main_ind_op_b = FF(static_cast(res.indirect_flag_b)), - .avm_main_ind_op_c = FF(static_cast(res.indirect_flag_c)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(res.direct_a_offset), - .avm_main_mem_idx_b = FF(res.direct_b_offset), - .avm_main_mem_idx_c = FF(res.direct_c_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(in_tag)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_or = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(in_tag)), + .main_clk = clk, + .main_bin_op_id = FF(1), + .main_call_ptr = call_ptr, + .main_ia = a, + .main_ib = b, + .main_ic = c, + .main_ind_addr_a = res.indirect_flag_a ? FF(a_offset) : FF(0), + .main_ind_addr_b = res.indirect_flag_b ? FF(b_offset) : FF(0), + .main_ind_addr_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(res.direct_a_offset), + .main_mem_addr_b = FF(res.direct_b_offset), + .main_mem_addr_c = FF(res.direct_c_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(in_tag)), + .main_rwc = FF(1), + .main_sel_bin = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_or = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(res.indirect_flag_a)), + .main_sel_resolve_ind_addr_b = FF(static_cast(res.indirect_flag_b)), + .main_sel_resolve_ind_addr_c = FF(static_cast(res.indirect_flag_c)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(in_tag)), }); } @@ -673,32 +675,32 @@ void AvmTraceBuilder::op_xor( gas_trace_builder.constrain_gas_lookup(clk, OpCode::XOR); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_bin_op_id = FF(2), - .avm_main_bin_sel = FF(1), - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a, - .avm_main_ib = b, - .avm_main_ic = c, - .avm_main_ind_a = res.indirect_flag_a ? FF(a_offset) : FF(0), - .avm_main_ind_b = res.indirect_flag_b ? FF(b_offset) : FF(0), - .avm_main_ind_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(res.indirect_flag_a)), - .avm_main_ind_op_b = FF(static_cast(res.indirect_flag_b)), - .avm_main_ind_op_c = FF(static_cast(res.indirect_flag_c)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(res.direct_a_offset), - .avm_main_mem_idx_b = FF(res.direct_b_offset), - .avm_main_mem_idx_c = FF(res.direct_c_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(in_tag)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_xor = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(in_tag)), + .main_clk = clk, + .main_bin_op_id = FF(2), + .main_call_ptr = call_ptr, + .main_ia = a, + .main_ib = b, + .main_ic = c, + .main_ind_addr_a = res.indirect_flag_a ? FF(a_offset) : FF(0), + .main_ind_addr_b = res.indirect_flag_b ? FF(b_offset) : FF(0), + .main_ind_addr_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(res.direct_a_offset), + .main_mem_addr_b = FF(res.direct_b_offset), + .main_mem_addr_c = FF(res.direct_c_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(in_tag)), + .main_rwc = FF(1), + .main_sel_bin = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_xor = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(res.indirect_flag_a)), + .main_sel_resolve_ind_addr_b = FF(static_cast(res.indirect_flag_b)), + .main_sel_resolve_ind_addr_c = FF(static_cast(res.indirect_flag_c)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(in_tag)), }); } @@ -730,31 +732,31 @@ void AvmTraceBuilder::op_lt( gas_trace_builder.constrain_gas_lookup(clk, OpCode::LT); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_alu_in_tag = FF(static_cast(in_tag)), - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a, - .avm_main_ib = b, - .avm_main_ic = c, - .avm_main_ind_a = res.indirect_flag_a ? FF(a_offset) : FF(0), - .avm_main_ind_b = res.indirect_flag_b ? FF(b_offset) : FF(0), - .avm_main_ind_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(res.indirect_flag_a)), - .avm_main_ind_op_b = FF(static_cast(res.indirect_flag_b)), - .avm_main_ind_op_c = FF(static_cast(res.indirect_flag_c)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(res.direct_a_offset), - .avm_main_mem_idx_b = FF(res.direct_b_offset), - .avm_main_mem_idx_c = FF(res.direct_c_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(in_tag)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_lt = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), + .main_clk = clk, + .main_alu_in_tag = FF(static_cast(in_tag)), + .main_call_ptr = call_ptr, + .main_ia = a, + .main_ib = b, + .main_ic = c, + .main_ind_addr_a = res.indirect_flag_a ? FF(a_offset) : FF(0), + .main_ind_addr_b = res.indirect_flag_b ? FF(b_offset) : FF(0), + .main_ind_addr_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(res.direct_a_offset), + .main_mem_addr_b = FF(res.direct_b_offset), + .main_mem_addr_c = FF(res.direct_c_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(in_tag)), + .main_rwc = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_lt = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(res.indirect_flag_a)), + .main_sel_resolve_ind_addr_b = FF(static_cast(res.indirect_flag_b)), + .main_sel_resolve_ind_addr_c = FF(static_cast(res.indirect_flag_c)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), }); } @@ -786,31 +788,31 @@ void AvmTraceBuilder::op_lte( gas_trace_builder.constrain_gas_lookup(clk, OpCode::LTE); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_alu_in_tag = FF(static_cast(in_tag)), - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a, - .avm_main_ib = b, - .avm_main_ic = c, - .avm_main_ind_a = res.indirect_flag_a ? FF(a_offset) : FF(0), - .avm_main_ind_b = res.indirect_flag_b ? FF(b_offset) : FF(0), - .avm_main_ind_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(res.indirect_flag_a)), - .avm_main_ind_op_b = FF(static_cast(res.indirect_flag_b)), - .avm_main_ind_op_c = FF(static_cast(res.indirect_flag_c)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(res.direct_a_offset), - .avm_main_mem_idx_b = FF(res.direct_b_offset), - .avm_main_mem_idx_c = FF(res.direct_c_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(in_tag)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_lte = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), + .main_clk = clk, + .main_alu_in_tag = FF(static_cast(in_tag)), + .main_call_ptr = call_ptr, + .main_ia = a, + .main_ib = b, + .main_ic = c, + .main_ind_addr_a = res.indirect_flag_a ? FF(a_offset) : FF(0), + .main_ind_addr_b = res.indirect_flag_b ? FF(b_offset) : FF(0), + .main_ind_addr_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(res.direct_a_offset), + .main_mem_addr_b = FF(res.direct_b_offset), + .main_mem_addr_c = FF(res.direct_c_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(in_tag)), + .main_rwc = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_lte = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(res.indirect_flag_a)), + .main_sel_resolve_ind_addr_b = FF(static_cast(res.indirect_flag_b)), + .main_sel_resolve_ind_addr_c = FF(static_cast(res.indirect_flag_c)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), }); } @@ -842,31 +844,31 @@ void AvmTraceBuilder::op_shr( gas_trace_builder.constrain_gas_lookup(clk, OpCode::SHR); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_alu_in_tag = FF(static_cast(in_tag)), - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a, - .avm_main_ib = b, - .avm_main_ic = c, - .avm_main_ind_a = res.indirect_flag_a ? FF(a_offset) : FF(0), - .avm_main_ind_b = res.indirect_flag_b ? FF(b_offset) : FF(0), - .avm_main_ind_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(res.indirect_flag_a)), - .avm_main_ind_op_b = FF(static_cast(res.indirect_flag_b)), - .avm_main_ind_op_c = FF(static_cast(res.indirect_flag_c)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(res.direct_a_offset), - .avm_main_mem_idx_b = FF(res.direct_b_offset), - .avm_main_mem_idx_c = FF(res.direct_c_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(in_tag)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_shr = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(in_tag)), + .main_clk = clk, + .main_alu_in_tag = FF(static_cast(in_tag)), + .main_call_ptr = call_ptr, + .main_ia = a, + .main_ib = b, + .main_ic = c, + .main_ind_addr_a = res.indirect_flag_a ? FF(a_offset) : FF(0), + .main_ind_addr_b = res.indirect_flag_b ? FF(b_offset) : FF(0), + .main_ind_addr_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(res.direct_a_offset), + .main_mem_addr_b = FF(res.direct_b_offset), + .main_mem_addr_c = FF(res.direct_c_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(in_tag)), + .main_rwc = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_shr = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(res.indirect_flag_a)), + .main_sel_resolve_ind_addr_b = FF(static_cast(res.indirect_flag_b)), + .main_sel_resolve_ind_addr_c = FF(static_cast(res.indirect_flag_c)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(in_tag)), }); } @@ -897,31 +899,31 @@ void AvmTraceBuilder::op_shl( gas_trace_builder.constrain_gas_lookup(clk, OpCode::SHL); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_alu_in_tag = FF(static_cast(in_tag)), - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a, - .avm_main_ib = b, - .avm_main_ic = c, - .avm_main_ind_a = res.indirect_flag_a ? FF(a_offset) : FF(0), - .avm_main_ind_b = res.indirect_flag_b ? FF(b_offset) : FF(0), - .avm_main_ind_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(res.indirect_flag_a)), - .avm_main_ind_op_b = FF(static_cast(res.indirect_flag_b)), - .avm_main_ind_op_c = FF(static_cast(res.indirect_flag_c)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(res.direct_a_offset), - .avm_main_mem_idx_b = FF(res.direct_b_offset), - .avm_main_mem_idx_c = FF(res.direct_c_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(in_tag)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_shl = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(in_tag)), + .main_clk = clk, + .main_alu_in_tag = FF(static_cast(in_tag)), + .main_call_ptr = call_ptr, + .main_ia = a, + .main_ib = b, + .main_ic = c, + .main_ind_addr_a = res.indirect_flag_a ? FF(a_offset) : FF(0), + .main_ind_addr_b = res.indirect_flag_b ? FF(b_offset) : FF(0), + .main_ind_addr_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(res.direct_a_offset), + .main_mem_addr_b = FF(res.direct_b_offset), + .main_mem_addr_c = FF(res.direct_c_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(in_tag)), + .main_rwc = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_shl = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(res.indirect_flag_a)), + .main_sel_resolve_ind_addr_b = FF(static_cast(res.indirect_flag_b)), + .main_sel_resolve_ind_addr_c = FF(static_cast(res.indirect_flag_c)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(in_tag)), }); } @@ -961,19 +963,19 @@ void AvmTraceBuilder::op_set(uint8_t indirect, uint128_t val, uint32_t dst_offse gas_trace_builder.constrain_gas_lookup(clk, OpCode::SET); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_call_ptr = call_ptr, - .avm_main_ic = val_ff, - .avm_main_ind_c = indirect_dst_flag ? dst_offset : 0, - .avm_main_ind_op_c = static_cast(indirect_dst_flag), - .avm_main_internal_return_ptr = internal_return_ptr, - .avm_main_mem_idx_c = direct_dst_offset, - .avm_main_mem_op_activate_gas = 1, // TODO: remove in the long term - .avm_main_mem_op_c = 1, - .avm_main_pc = pc++, - .avm_main_rwc = 1, - .avm_main_tag_err = static_cast(!tag_match), - .avm_main_w_in_tag = static_cast(in_tag), + .main_clk = clk, + .main_call_ptr = call_ptr, + .main_ic = val_ff, + .main_ind_addr_c = indirect_dst_flag ? dst_offset : 0, + .main_internal_return_ptr = internal_return_ptr, + .main_mem_addr_c = direct_dst_offset, + .main_pc = pc++, + .main_rwc = 1, + .main_sel_mem_op_activate_gas = 1, // TODO: remove in the long term + .main_sel_mem_op_c = 1, + .main_sel_resolve_ind_addr_c = static_cast(indirect_dst_flag), + .main_tag_err = static_cast(!tag_match), + .main_w_in_tag = static_cast(in_tag), }); } @@ -1019,26 +1021,26 @@ void AvmTraceBuilder::op_mov(uint8_t indirect, uint32_t src_offset, uint32_t dst gas_trace_builder.constrain_gas_lookup(clk, OpCode::MOV); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_call_ptr = call_ptr, - .avm_main_ia = val, - .avm_main_ic = val, - .avm_main_ind_a = indirect_src_flag ? src_offset : 0, - .avm_main_ind_c = indirect_dst_flag ? dst_offset : 0, - .avm_main_ind_op_a = static_cast(indirect_src_flag), - .avm_main_ind_op_c = static_cast(indirect_dst_flag), - .avm_main_internal_return_ptr = internal_return_ptr, - .avm_main_mem_idx_a = direct_src_offset, - .avm_main_mem_idx_c = direct_dst_offset, - .avm_main_mem_op_a = 1, - .avm_main_mem_op_c = 1, - .avm_main_pc = pc++, - .avm_main_r_in_tag = static_cast(tag), - .avm_main_rwc = 1, - .avm_main_sel_mov = 1, - .avm_main_sel_mov_a = 1, - .avm_main_tag_err = static_cast(!tag_match), - .avm_main_w_in_tag = static_cast(tag), + .main_clk = clk, + .main_call_ptr = call_ptr, + .main_ia = val, + .main_ic = val, + .main_ind_addr_a = indirect_src_flag ? src_offset : 0, + .main_ind_addr_c = indirect_dst_flag ? dst_offset : 0, + .main_internal_return_ptr = internal_return_ptr, + .main_mem_addr_a = direct_src_offset, + .main_mem_addr_c = direct_dst_offset, + .main_pc = pc++, + .main_r_in_tag = static_cast(tag), + .main_rwc = 1, + .main_sel_mem_op_a = 1, + .main_sel_mem_op_c = 1, + .main_sel_mov_ia_to_ic = 1, + .main_sel_op_mov = 1, + .main_sel_resolve_ind_addr_a = static_cast(indirect_src_flag), + .main_sel_resolve_ind_addr_c = static_cast(indirect_dst_flag), + .main_tag_err = static_cast(!tag_match), + .main_w_in_tag = static_cast(tag), }); } @@ -1119,39 +1121,39 @@ void AvmTraceBuilder::op_cmov( gas_trace_builder.constrain_gas_lookup(clk, OpCode::CMOV); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a_mem_entry.val, - .avm_main_ib = b_mem_entry.val, - .avm_main_ic = val, - .avm_main_id = cond_mem_entry.val, - .avm_main_id_zero = static_cast(id_zero), - .avm_main_ind_a = indirect_a_flag ? a_offset : 0, - .avm_main_ind_b = indirect_b_flag ? b_offset : 0, - .avm_main_ind_c = indirect_dst_flag ? dst_offset : 0, - .avm_main_ind_d = indirect_cond_flag ? cond_offset : 0, - .avm_main_ind_op_a = static_cast(indirect_a_flag), - .avm_main_ind_op_b = static_cast(indirect_b_flag), - .avm_main_ind_op_c = static_cast(indirect_dst_flag), - .avm_main_ind_op_d = static_cast(indirect_cond_flag), - .avm_main_internal_return_ptr = internal_return_ptr, - .avm_main_inv = inv, - .avm_main_mem_idx_a = direct_a_offset, - .avm_main_mem_idx_b = direct_b_offset, - .avm_main_mem_idx_c = direct_dst_offset, - .avm_main_mem_idx_d = direct_cond_offset, - .avm_main_mem_op_a = 1, - .avm_main_mem_op_b = 1, - .avm_main_mem_op_c = 1, - .avm_main_mem_op_d = 1, - .avm_main_pc = pc++, - .avm_main_r_in_tag = static_cast(tag), - .avm_main_rwc = 1, - .avm_main_sel_cmov = 1, - .avm_main_sel_mov_a = static_cast(!id_zero), - .avm_main_sel_mov_b = static_cast(id_zero), - .avm_main_tag_err = static_cast(!tag_match), - .avm_main_w_in_tag = static_cast(tag), + .main_clk = clk, + .main_call_ptr = call_ptr, + .main_ia = a_mem_entry.val, + .main_ib = b_mem_entry.val, + .main_ic = val, + .main_id = cond_mem_entry.val, + .main_id_zero = static_cast(id_zero), + .main_ind_addr_a = indirect_a_flag ? a_offset : 0, + .main_ind_addr_b = indirect_b_flag ? b_offset : 0, + .main_ind_addr_c = indirect_dst_flag ? dst_offset : 0, + .main_ind_addr_d = indirect_cond_flag ? cond_offset : 0, + .main_internal_return_ptr = internal_return_ptr, + .main_inv = inv, + .main_mem_addr_a = direct_a_offset, + .main_mem_addr_b = direct_b_offset, + .main_mem_addr_c = direct_dst_offset, + .main_mem_addr_d = direct_cond_offset, + .main_pc = pc++, + .main_r_in_tag = static_cast(tag), + .main_rwc = 1, + .main_sel_mem_op_a = 1, + .main_sel_mem_op_b = 1, + .main_sel_mem_op_c = 1, + .main_sel_mem_op_d = 1, + .main_sel_mov_ia_to_ic = static_cast(!id_zero), + .main_sel_mov_ib_to_ic = static_cast(id_zero), + .main_sel_op_cmov = 1, + .main_sel_resolve_ind_addr_a = static_cast(indirect_a_flag), + .main_sel_resolve_ind_addr_b = static_cast(indirect_b_flag), + .main_sel_resolve_ind_addr_c = static_cast(indirect_dst_flag), + .main_sel_resolve_ind_addr_d = static_cast(indirect_cond_flag), + .main_tag_err = static_cast(!tag_match), + .main_w_in_tag = static_cast(tag), }); } @@ -1175,19 +1177,19 @@ Row AvmTraceBuilder::create_kernel_lookup_opcode( mem_trace_builder.write_into_memory(call_ptr, clk, IntermRegister::IA, direct_dst_offset, value, r_tag, w_tag); return Row{ - .avm_main_clk = clk, - .avm_kernel_kernel_in_offset = selector, - .avm_main_call_ptr = call_ptr, - .avm_main_ia = value, - .avm_main_ind_a = indirect ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect)), - .avm_main_internal_return_ptr = internal_return_ptr, - .avm_main_mem_idx_a = direct_dst_offset, - .avm_main_mem_op_a = 1, - .avm_main_pc = pc++, - .avm_main_q_kernel_lookup = 1, - .avm_main_rwa = 1, - .avm_main_w_in_tag = static_cast(w_tag), + .main_clk = clk, + .kernel_kernel_in_offset = selector, + .main_call_ptr = call_ptr, + .main_ia = value, + .main_ind_addr_a = indirect ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = internal_return_ptr, + .main_mem_addr_a = direct_dst_offset, + .main_pc = pc++, + .main_rwa = 1, + .main_sel_mem_op_a = 1, + .main_sel_q_kernel_lookup = 1, + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect)), + .main_w_in_tag = static_cast(w_tag), }; } @@ -1198,10 +1200,10 @@ void AvmTraceBuilder::op_storage_address(uint8_t indirect, uint32_t dst_offset) bool indirect_dst_flag = is_operand_indirect(indirect, 0); Row row = create_kernel_lookup_opcode( indirect_dst_flag, dst_offset, STORAGE_ADDRESS_SELECTOR, ia_value, AvmMemoryTag::FF); - row.avm_main_sel_op_storage_address = FF(1); + row.main_sel_op_storage_address = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.avm_main_clk), OpCode::STORAGEADDRESS); + gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::STORAGEADDRESS); main_trace.push_back(row); } @@ -1212,10 +1214,10 @@ void AvmTraceBuilder::op_sender(uint8_t indirect, uint32_t dst_offset) bool indirect_dst_flag = is_operand_indirect(indirect, 0); Row row = create_kernel_lookup_opcode(indirect_dst_flag, dst_offset, SENDER_SELECTOR, ia_value, AvmMemoryTag::FF); - row.avm_main_sel_op_sender = FF(1); + row.main_sel_op_sender = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.avm_main_clk), OpCode::SENDER); + gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::SENDER); main_trace.push_back(row); } @@ -1226,10 +1228,10 @@ void AvmTraceBuilder::op_address(uint8_t indirect, uint32_t dst_offset) bool indirect_dst_flag = is_operand_indirect(indirect, 0); Row row = create_kernel_lookup_opcode(indirect_dst_flag, dst_offset, ADDRESS_SELECTOR, ia_value, AvmMemoryTag::FF); - row.avm_main_sel_op_address = FF(1); + row.main_sel_op_address = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.avm_main_clk), OpCode::ADDRESS); + gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::ADDRESS); main_trace.push_back(row); } @@ -1241,10 +1243,10 @@ void AvmTraceBuilder::op_fee_per_da_gas(uint8_t indirect, uint32_t dst_offset) bool indirect_dst_flag = is_operand_indirect(indirect, 0); Row row = create_kernel_lookup_opcode(indirect_dst_flag, dst_offset, FEE_PER_DA_GAS_SELECTOR, ia_value, AvmMemoryTag::FF); - row.avm_main_sel_op_fee_per_da_gas = FF(1); + row.main_sel_op_fee_per_da_gas = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.avm_main_clk), OpCode::FEEPERDAGAS); + gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::FEEPERDAGAS); main_trace.push_back(row); } @@ -1256,10 +1258,10 @@ void AvmTraceBuilder::op_fee_per_l2_gas(uint8_t indirect, uint32_t dst_offset) bool indirect_dst_flag = is_operand_indirect(indirect, 0); Row row = create_kernel_lookup_opcode(indirect_dst_flag, dst_offset, FEE_PER_L2_GAS_SELECTOR, ia_value, AvmMemoryTag::FF); - row.avm_main_sel_op_fee_per_l2_gas = FF(1); + row.main_sel_op_fee_per_l2_gas = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.avm_main_clk), OpCode::FEEPERL2GAS); + gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::FEEPERL2GAS); main_trace.push_back(row); } @@ -1271,10 +1273,10 @@ void AvmTraceBuilder::op_transaction_fee(uint8_t indirect, uint32_t dst_offset) bool indirect_dst_flag = is_operand_indirect(indirect, 0); Row row = create_kernel_lookup_opcode( indirect_dst_flag, dst_offset, TRANSACTION_FEE_SELECTOR, ia_value, AvmMemoryTag::FF); - row.avm_main_sel_op_transaction_fee = FF(1); + row.main_sel_op_transaction_fee = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.avm_main_clk), OpCode::TRANSACTIONFEE); + gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::TRANSACTIONFEE); main_trace.push_back(row); } @@ -1285,10 +1287,10 @@ void AvmTraceBuilder::op_chain_id(uint8_t indirect, uint32_t dst_offset) bool indirect_dst_flag = is_operand_indirect(indirect, 0); Row row = create_kernel_lookup_opcode(indirect_dst_flag, dst_offset, CHAIN_ID_SELECTOR, ia_value, AvmMemoryTag::FF); - row.avm_main_sel_op_chain_id = FF(1); + row.main_sel_op_chain_id = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.avm_main_clk), OpCode::CHAINID); + gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::CHAINID); main_trace.push_back(row); } @@ -1299,10 +1301,10 @@ void AvmTraceBuilder::op_version(uint8_t indirect, uint32_t dst_offset) bool indirect_dst_flag = is_operand_indirect(indirect, 0); Row row = create_kernel_lookup_opcode(indirect_dst_flag, dst_offset, VERSION_SELECTOR, ia_value, AvmMemoryTag::FF); - row.avm_main_sel_op_version = FF(1); + row.main_sel_op_version = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.avm_main_clk), OpCode::VERSION); + gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::VERSION); main_trace.push_back(row); } @@ -1314,10 +1316,10 @@ void AvmTraceBuilder::op_block_number(uint8_t indirect, uint32_t dst_offset) bool indirect_dst_flag = is_operand_indirect(indirect, 0); Row row = create_kernel_lookup_opcode(indirect_dst_flag, dst_offset, BLOCK_NUMBER_SELECTOR, ia_value, AvmMemoryTag::FF); - row.avm_main_sel_op_block_number = FF(1); + row.main_sel_op_block_number = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.avm_main_clk), OpCode::BLOCKNUMBER); + gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::BLOCKNUMBER); main_trace.push_back(row); } @@ -1328,10 +1330,10 @@ void AvmTraceBuilder::op_coinbase(uint8_t indirect, uint32_t dst_offset) bool indirect_dst_flag = is_operand_indirect(indirect, 0); Row row = create_kernel_lookup_opcode(indirect_dst_flag, dst_offset, COINBASE_SELECTOR, ia_value, AvmMemoryTag::FF); - row.avm_main_sel_op_coinbase = FF(1); + row.main_sel_op_coinbase = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.avm_main_clk), OpCode::COINBASE); + gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::COINBASE); main_trace.push_back(row); } @@ -1343,10 +1345,10 @@ void AvmTraceBuilder::op_timestamp(uint8_t indirect, uint32_t dst_offset) bool indirect_dst_flag = is_operand_indirect(indirect, 0); Row row = create_kernel_lookup_opcode(indirect_dst_flag, dst_offset, TIMESTAMP_SELECTOR, ia_value, AvmMemoryTag::U64); - row.avm_main_sel_op_timestamp = FF(1); + row.main_sel_op_timestamp = FF(1); // Constrain gas cost - gas_trace_builder.constrain_gas_lookup(static_cast(row.avm_main_clk), OpCode::TIMESTAMP); + gas_trace_builder.constrain_gas_lookup(static_cast(row.main_clk), OpCode::TIMESTAMP); main_trace.push_back(row); } @@ -1369,17 +1371,17 @@ Row AvmTraceBuilder::create_kernel_output_opcode(uint8_t indirect, uint32_t clk, call_ptr, clk, IntermRegister::IA, direct_data_offset, AvmMemoryTag::FF, AvmMemoryTag::U0); return Row{ - .avm_main_clk = clk, - .avm_main_ia = read_a.val, - .avm_main_ind_a = indirect_data_flag ? FF(data_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect)), - .avm_main_internal_return_ptr = internal_return_ptr, - .avm_main_mem_idx_a = direct_data_offset, - .avm_main_mem_op_a = 1, - .avm_main_pc = pc++, - .avm_main_q_kernel_output_lookup = 1, - .avm_main_r_in_tag = static_cast(AvmMemoryTag::FF), - .avm_main_rwa = 0, + .main_clk = clk, + .main_ia = read_a.val, + .main_ind_addr_a = indirect_data_flag ? FF(data_offset) : FF(0), + .main_internal_return_ptr = internal_return_ptr, + .main_mem_addr_a = direct_data_offset, + .main_pc = pc++, + .main_r_in_tag = static_cast(AvmMemoryTag::FF), + .main_rwa = 0, + .main_sel_mem_op_a = 1, + .main_sel_q_kernel_output_lookup = 1, + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect)), }; } @@ -1419,23 +1421,23 @@ Row AvmTraceBuilder::create_kernel_output_opcode_with_metadata(uint8_t indirect, call_ptr, clk, IntermRegister::IB, direct_metadata_offset, metadata_r_tag, AvmMemoryTag::U0); return Row{ - .avm_main_clk = clk, - .avm_main_ia = read_a.val, - .avm_main_ib = read_b.val, - .avm_main_ind_a = indirect_a_flag ? data_offset : FF(0), - .avm_main_ind_b = indirect_b_flag ? metadata_offset : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect_a_flag)), - .avm_main_ind_op_b = FF(static_cast(indirect_b_flag)), - .avm_main_internal_return_ptr = internal_return_ptr, - .avm_main_mem_idx_a = direct_data_offset, - .avm_main_mem_idx_b = direct_metadata_offset, - .avm_main_mem_op_a = 1, - .avm_main_mem_op_b = 1, - .avm_main_pc = pc++, - .avm_main_q_kernel_output_lookup = 1, - .avm_main_r_in_tag = static_cast(data_r_tag), - .avm_main_rwa = 0, - .avm_main_rwb = 0, + .main_clk = clk, + .main_ia = read_a.val, + .main_ib = read_b.val, + .main_ind_addr_a = indirect_a_flag ? data_offset : FF(0), + .main_ind_addr_b = indirect_b_flag ? metadata_offset : FF(0), + .main_internal_return_ptr = internal_return_ptr, + .main_mem_addr_a = direct_data_offset, + .main_mem_addr_b = direct_metadata_offset, + .main_pc = pc++, + .main_r_in_tag = static_cast(data_r_tag), + .main_rwa = 0, + .main_rwb = 0, + .main_sel_mem_op_a = 1, + .main_sel_mem_op_b = 1, + .main_sel_q_kernel_output_lookup = 1, + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_a_flag)), + .main_sel_resolve_ind_addr_b = FF(static_cast(indirect_b_flag)), }; } @@ -1477,24 +1479,24 @@ Row AvmTraceBuilder::create_kernel_output_opcode_with_set_metadata_output_from_h call_ptr, clk, IntermRegister::IB, direct_metadata_offset, exists, AvmMemoryTag::FF, AvmMemoryTag::U8); return Row{ - .avm_main_clk = clk, - .avm_main_ia = read_a.val, - .avm_main_ib = exists, - .avm_main_ind_a = indirect_a_flag ? data_offset : FF(0), - .avm_main_ind_b = indirect_b_flag ? metadata_offset : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect_a_flag)), - .avm_main_ind_op_b = FF(static_cast(indirect_b_flag)), - .avm_main_internal_return_ptr = internal_return_ptr, - .avm_main_mem_idx_a = direct_data_offset, - .avm_main_mem_idx_b = direct_metadata_offset, - .avm_main_mem_op_a = 1, - .avm_main_mem_op_b = 1, - .avm_main_pc = pc++, - .avm_main_q_kernel_output_lookup = 1, - .avm_main_r_in_tag = static_cast(AvmMemoryTag::FF), - .avm_main_rwa = 0, - .avm_main_rwb = 1, - .avm_main_w_in_tag = static_cast(AvmMemoryTag::U8), + .main_clk = clk, + .main_ia = read_a.val, + .main_ib = exists, + .main_ind_addr_a = indirect_a_flag ? data_offset : FF(0), + .main_ind_addr_b = indirect_b_flag ? metadata_offset : FF(0), + .main_internal_return_ptr = internal_return_ptr, + .main_mem_addr_a = direct_data_offset, + .main_mem_addr_b = direct_metadata_offset, + .main_pc = pc++, + .main_r_in_tag = static_cast(AvmMemoryTag::FF), + .main_rwa = 0, + .main_rwb = 1, + .main_sel_mem_op_a = 1, + .main_sel_mem_op_b = 1, + .main_sel_q_kernel_output_lookup = 1, + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_a_flag)), + .main_sel_resolve_ind_addr_b = FF(static_cast(indirect_b_flag)), + .main_w_in_tag = static_cast(AvmMemoryTag::U8), }; } @@ -1531,24 +1533,24 @@ Row AvmTraceBuilder::create_kernel_output_opcode_with_set_value_from_hint(uint8_ call_ptr, clk, IntermRegister::IB, direct_metadata_offset, AvmMemoryTag::FF, AvmMemoryTag::FF); return Row{ - .avm_main_clk = clk, - .avm_main_ia = value, - .avm_main_ib = read_b.val, - .avm_main_ind_a = indirect_a_flag ? data_offset : FF(0), - .avm_main_ind_b = indirect_b_flag ? metadata_offset : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect_a_flag)), - .avm_main_ind_op_b = FF(static_cast(indirect_b_flag)), - .avm_main_internal_return_ptr = internal_return_ptr, - .avm_main_mem_idx_a = direct_data_offset, - .avm_main_mem_idx_b = direct_metadata_offset, - .avm_main_mem_op_a = 1, - .avm_main_mem_op_b = 1, - .avm_main_pc = pc, // No PC increment here since we do it in the specific ops - .avm_main_q_kernel_output_lookup = 1, - .avm_main_r_in_tag = static_cast(AvmMemoryTag::FF), - .avm_main_rwa = 1, - .avm_main_rwb = 0, - .avm_main_w_in_tag = static_cast(AvmMemoryTag::FF), + .main_clk = clk, + .main_ia = value, + .main_ib = read_b.val, + .main_ind_addr_a = indirect_a_flag ? data_offset : FF(0), + .main_ind_addr_b = indirect_b_flag ? metadata_offset : FF(0), + .main_internal_return_ptr = internal_return_ptr, + .main_mem_addr_a = direct_data_offset, + .main_mem_addr_b = direct_metadata_offset, + .main_pc = pc, // No PC increment here since we do it in the specific ops + .main_r_in_tag = static_cast(AvmMemoryTag::FF), + .main_rwa = 1, + .main_rwb = 0, + .main_sel_mem_op_a = 1, + .main_sel_mem_op_b = 1, + .main_sel_q_kernel_output_lookup = 1, + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_a_flag)), + .main_sel_resolve_ind_addr_b = FF(static_cast(indirect_b_flag)), + .main_w_in_tag = static_cast(AvmMemoryTag::FF), }; } @@ -1557,8 +1559,8 @@ void AvmTraceBuilder::op_emit_note_hash(uint8_t indirect, uint32_t note_hash_off auto const clk = static_cast(main_trace.size()) + 1; Row row = create_kernel_output_opcode(indirect, clk, note_hash_offset); - kernel_trace_builder.op_emit_note_hash(clk, side_effect_counter, row.avm_main_ia); - row.avm_main_sel_op_emit_note_hash = FF(1); + kernel_trace_builder.op_emit_note_hash(clk, side_effect_counter, row.main_ia); + row.main_sel_op_emit_note_hash = FF(1); // Constrain gas cost gas_trace_builder.constrain_gas_lookup(clk, OpCode::EMITNOTEHASH); @@ -1572,8 +1574,8 @@ void AvmTraceBuilder::op_emit_nullifier(uint8_t indirect, uint32_t nullifier_off auto const clk = static_cast(main_trace.size()) + 1; Row row = create_kernel_output_opcode(indirect, clk, nullifier_offset); - kernel_trace_builder.op_emit_nullifier(clk, side_effect_counter, row.avm_main_ia); - row.avm_main_sel_op_emit_nullifier = FF(1); + kernel_trace_builder.op_emit_nullifier(clk, side_effect_counter, row.main_ia); + row.main_sel_op_emit_nullifier = FF(1); // Constrain gas cost gas_trace_builder.constrain_gas_lookup(clk, OpCode::EMITNULLIFIER); @@ -1589,8 +1591,8 @@ void AvmTraceBuilder::op_emit_l2_to_l1_msg(uint8_t indirect, uint32_t recipient_ // Note: unorthadox order - as seen in L2ToL1Message struct in TS Row row = create_kernel_output_opcode_with_metadata( indirect, clk, msg_offset, AvmMemoryTag::FF, recipient_offset, AvmMemoryTag::FF); - kernel_trace_builder.op_emit_l2_to_l1_msg(clk, side_effect_counter, row.avm_main_ia, row.avm_main_ib); - row.avm_main_sel_op_emit_l2_to_l1_msg = FF(1); + kernel_trace_builder.op_emit_l2_to_l1_msg(clk, side_effect_counter, row.main_ia, row.main_ib); + row.main_sel_op_emit_l2_to_l1_msg = FF(1); // Constrain gas cost gas_trace_builder.constrain_gas_lookup(clk, OpCode::SENDL2TOL1MSG); @@ -1604,8 +1606,8 @@ void AvmTraceBuilder::op_emit_unencrypted_log(uint8_t indirect, uint32_t log_off auto const clk = static_cast(main_trace.size()) + 1; Row row = create_kernel_output_opcode(indirect, clk, log_offset); - kernel_trace_builder.op_emit_unencrypted_log(clk, side_effect_counter, row.avm_main_ia); - row.avm_main_sel_op_emit_unencrypted_log = FF(1); + kernel_trace_builder.op_emit_unencrypted_log(clk, side_effect_counter, row.main_ia); + row.main_sel_op_emit_unencrypted_log = FF(1); // Constrain gas cost gas_trace_builder.constrain_gas_lookup(clk, OpCode::EMITUNENCRYPTEDLOG); @@ -1621,8 +1623,8 @@ void AvmTraceBuilder::op_l1_to_l2_msg_exists(uint8_t indirect, uint32_t log_offs Row row = create_kernel_output_opcode_with_set_metadata_output_from_hint(indirect, clk, log_offset, dest_offset); kernel_trace_builder.op_l1_to_l2_msg_exists( - clk, side_effect_counter, row.avm_main_ia, /*safe*/ static_cast(row.avm_main_ib)); - row.avm_main_sel_op_l1_to_l2_msg_exists = FF(1); + clk, side_effect_counter, row.main_ia, /*safe*/ static_cast(row.main_ib)); + row.main_sel_op_l1_to_l2_msg_exists = FF(1); // Constrain gas cost gas_trace_builder.constrain_gas_lookup(clk, OpCode::L1TOL2MSGEXISTS); @@ -1637,8 +1639,8 @@ void AvmTraceBuilder::op_note_hash_exists(uint8_t indirect, uint32_t note_offset Row row = create_kernel_output_opcode_with_set_metadata_output_from_hint(indirect, clk, note_offset, dest_offset); kernel_trace_builder.op_note_hash_exists( - clk, side_effect_counter, row.avm_main_ia, /*safe*/ static_cast(row.avm_main_ib)); - row.avm_main_sel_op_note_hash_exists = FF(1); + clk, side_effect_counter, row.main_ia, /*safe*/ static_cast(row.main_ib)); + row.main_sel_op_note_hash_exists = FF(1); // Constrain gas cost gas_trace_builder.constrain_gas_lookup(clk, OpCode::NOTEHASHEXISTS); @@ -1654,8 +1656,8 @@ void AvmTraceBuilder::op_nullifier_exists(uint8_t indirect, uint32_t nullifier_o Row row = create_kernel_output_opcode_with_set_metadata_output_from_hint(indirect, clk, nullifier_offset, dest_offset); kernel_trace_builder.op_nullifier_exists( - clk, side_effect_counter, row.avm_main_ia, /*safe*/ static_cast(row.avm_main_ib)); - row.avm_main_sel_op_nullifier_exists = FF(1); + clk, side_effect_counter, row.main_ia, /*safe*/ static_cast(row.main_ib)); + row.main_sel_op_nullifier_exists = FF(1); // Constrain gas cost gas_trace_builder.constrain_gas_lookup(clk, OpCode::NULLIFIEREXISTS); @@ -1685,19 +1687,19 @@ void AvmTraceBuilder::op_sload(uint8_t indirect, uint32_t slot_offset, uint32_t call_ptr, clk, IntermRegister::IB, slot_offset, AvmMemoryTag::FF, AvmMemoryTag::FF); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = read_dest_value.val, - .avm_main_ib = read_slot.val, - .avm_main_ind_a = dest_offset_is_indirect ? dest_offset : 0, - .avm_main_ind_op_a = FF(static_cast(dest_offset_is_indirect)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(direct_dest_offset), - .avm_main_mem_idx_b = FF(slot_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_pc = pc, // No PC increment here since this is the same opcode as the rows created below - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_clk = clk, + .main_ia = read_dest_value.val, + .main_ib = read_slot.val, + .main_ind_addr_a = dest_offset_is_indirect ? dest_offset : 0, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_dest_offset), + .main_mem_addr_b = FF(slot_offset), + .main_pc = pc, // No PC increment here since this is the same opcode as the rows created below + .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(dest_offset_is_indirect)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), }); clk++; @@ -1708,22 +1710,22 @@ void AvmTraceBuilder::op_sload(uint8_t indirect, uint32_t slot_offset, uint32_t call_ptr, clk, IntermRegister::IA, direct_dest_offset + i, value, AvmMemoryTag::FF, AvmMemoryTag::FF); auto row = Row{ - .avm_main_clk = clk, - .avm_main_ia = value, - .avm_main_ib = read_slot.val + i, // slot increments each time - .avm_main_internal_return_ptr = internal_return_ptr, - .avm_main_mem_idx_a = direct_dest_offset + i, - .avm_main_mem_op_a = 1, - .avm_main_pc = pc, // No PC increment here since this is the same opcode for all loop iterations - .avm_main_q_kernel_output_lookup = 1, - .avm_main_r_in_tag = static_cast(AvmMemoryTag::FF), - .avm_main_rwa = 1, - .avm_main_sel_op_sload = FF(1), - .avm_main_w_in_tag = static_cast(AvmMemoryTag::FF), + .main_clk = clk, + .main_ia = value, + .main_ib = read_slot.val + i, // slot increments each time + .main_internal_return_ptr = internal_return_ptr, + .main_mem_addr_a = direct_dest_offset + i, + .main_pc = pc, // No PC increment here since this is the same opcode for all loop iterations + .main_r_in_tag = static_cast(AvmMemoryTag::FF), + .main_rwa = 1, + .main_sel_mem_op_a = 1, + .main_sel_op_sload = FF(1), + .main_sel_q_kernel_output_lookup = 1, + .main_w_in_tag = static_cast(AvmMemoryTag::FF), }; // Output storage read to kernel outputs (performs lookup) - kernel_trace_builder.op_sload(clk, side_effect_counter, row.avm_main_ib, row.avm_main_ia); + kernel_trace_builder.op_sload(clk, side_effect_counter, row.main_ib, row.main_ia); // Constrain gas cost gas_trace_builder.constrain_gas_lookup(clk, OpCode::SLOAD); @@ -1757,19 +1759,19 @@ void AvmTraceBuilder::op_sstore(uint8_t indirect, uint32_t src_offset, uint32_t call_ptr, clk, IntermRegister::IB, slot_offset, AvmMemoryTag::FF, AvmMemoryTag::FF); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = read_src_value.val, - .avm_main_ib = read_slot.val, - .avm_main_ind_a = src_offset_is_indirect ? src_offset : 0, - .avm_main_ind_op_a = FF(static_cast(src_offset_is_indirect)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(direct_src_offset), - .avm_main_mem_idx_b = FF(slot_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_pc = pc, // No PC increment here since this is the same opcode as the rows created below - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_clk = clk, + .main_ia = read_src_value.val, + .main_ib = read_slot.val, + .main_ind_addr_a = src_offset_is_indirect ? src_offset : 0, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_src_offset), + .main_mem_addr_b = FF(slot_offset), + .main_pc = pc, // No PC increment here since this is the same opcode as the rows created below + .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(src_offset_is_indirect)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), }); clk++; @@ -1778,18 +1780,18 @@ void AvmTraceBuilder::op_sstore(uint8_t indirect, uint32_t src_offset, uint32_t call_ptr, clk, IntermRegister::IA, direct_src_offset + i, AvmMemoryTag::FF, AvmMemoryTag::U0); Row row = Row{ - .avm_main_clk = clk, - .avm_main_ia = read_a.val, - .avm_main_ib = read_slot.val + i, // slot increments each time - .avm_main_internal_return_ptr = internal_return_ptr, - .avm_main_mem_idx_a = direct_src_offset + i, - .avm_main_mem_op_a = 1, - .avm_main_pc = pc, - .avm_main_q_kernel_output_lookup = 1, - .avm_main_r_in_tag = static_cast(AvmMemoryTag::FF), + .main_clk = clk, + .main_ia = read_a.val, + .main_ib = read_slot.val + i, // slot increments each time + .main_internal_return_ptr = internal_return_ptr, + .main_mem_addr_a = direct_src_offset + i, + .main_pc = pc, + .main_r_in_tag = static_cast(AvmMemoryTag::FF), + .main_sel_mem_op_a = 1, + .main_sel_q_kernel_output_lookup = 1, }; - row.avm_main_sel_op_sstore = FF(1); - kernel_trace_builder.op_sstore(clk, side_effect_counter, row.avm_main_ib, row.avm_main_ia); + row.main_sel_op_sstore = FF(1); + kernel_trace_builder.op_sstore(clk, side_effect_counter, row.main_ib, row.main_ia); // Constrain gas cost gas_trace_builder.constrain_gas_lookup(clk, OpCode::SSTORE); @@ -1850,26 +1852,26 @@ void AvmTraceBuilder::op_cast(uint8_t indirect, uint32_t a_offset, uint32_t dst_ gas_trace_builder.constrain_gas_lookup(clk, OpCode::CAST); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_alu_in_tag = FF(static_cast(dst_tag)), - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a, - .avm_main_ic = c, - .avm_main_ind_a = indirect_a_flag ? FF(a_offset) : FF(0), - .avm_main_ind_c = indirect_dst_flag ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect_a_flag)), - .avm_main_ind_op_c = FF(static_cast(indirect_dst_flag)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(direct_a_offset), - .avm_main_mem_idx_c = FF(direct_dst_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(memEntry.tag)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_cast = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(dst_tag)), + .main_clk = clk, + .main_alu_in_tag = FF(static_cast(dst_tag)), + .main_call_ptr = call_ptr, + .main_ia = a, + .main_ic = c, + .main_ind_addr_a = indirect_a_flag ? FF(a_offset) : FF(0), + .main_ind_addr_c = indirect_dst_flag ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_a_offset), + .main_mem_addr_c = FF(direct_dst_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(memEntry.tag)), + .main_rwc = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_cast = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_a_flag)), + .main_sel_resolve_ind_addr_c = FF(static_cast(indirect_dst_flag)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(dst_tag)), }); } /** @@ -1925,33 +1927,33 @@ void AvmTraceBuilder::op_div( gas_trace_builder.constrain_gas_lookup(clk, OpCode::DIV); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_alu_in_tag = FF(static_cast(in_tag)), - .avm_main_call_ptr = call_ptr, - .avm_main_ia = a, - .avm_main_ib = b, - .avm_main_ic = c, - .avm_main_ind_a = res.indirect_flag_a ? FF(a_offset) : FF(0), - .avm_main_ind_b = res.indirect_flag_b ? FF(b_offset) : FF(0), - .avm_main_ind_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(res.indirect_flag_a)), - .avm_main_ind_op_b = FF(static_cast(res.indirect_flag_b)), - .avm_main_ind_op_c = FF(static_cast(res.indirect_flag_c)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_inv = tag_match ? inv : FF(1), - .avm_main_mem_idx_a = FF(res.direct_a_offset), - .avm_main_mem_idx_b = FF(res.direct_b_offset), - .avm_main_mem_idx_c = FF(res.direct_c_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_op_err = tag_match ? error : FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(in_tag)), - .avm_main_rwc = FF(1), - .avm_main_sel_op_div = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(in_tag)), + .main_clk = clk, + .main_alu_in_tag = FF(static_cast(in_tag)), + .main_call_ptr = call_ptr, + .main_ia = a, + .main_ib = b, + .main_ic = c, + .main_ind_addr_a = res.indirect_flag_a ? FF(a_offset) : FF(0), + .main_ind_addr_b = res.indirect_flag_b ? FF(b_offset) : FF(0), + .main_ind_addr_c = res.indirect_flag_c ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_inv = tag_match ? inv : FF(1), + .main_mem_addr_a = FF(res.direct_a_offset), + .main_mem_addr_b = FF(res.direct_b_offset), + .main_mem_addr_c = FF(res.direct_c_offset), + .main_op_err = tag_match ? error : FF(1), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(in_tag)), + .main_rwc = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_div = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(res.indirect_flag_a)), + .main_sel_resolve_ind_addr_b = FF(static_cast(res.indirect_flag_b)), + .main_sel_resolve_ind_addr_c = FF(static_cast(res.indirect_flag_c)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(in_tag)), }); } @@ -1992,8 +1994,8 @@ void AvmTraceBuilder::calldata_copy( FF ic(0); uint32_t mem_op_b(0); uint32_t mem_op_c(0); - uint32_t mem_idx_b(0); - uint32_t mem_idx_c(0); + uint32_t mem_addr_b(0); + uint32_t mem_addr_c(0); uint32_t rwb(0); uint32_t rwc(0); auto clk = static_cast(main_trace.size()) + 1; @@ -2013,32 +2015,32 @@ void AvmTraceBuilder::calldata_copy( tag_match = ind_read.tag_match; } - uint32_t mem_idx_a = direct_dst_offset + pos; + uint32_t mem_addr_a = direct_dst_offset + pos; // Storing from Ia mem_trace_builder.write_into_memory( - call_ptr, clk, IntermRegister::IA, mem_idx_a, ia, AvmMemoryTag::U0, AvmMemoryTag::FF); + call_ptr, clk, IntermRegister::IA, mem_addr_a, ia, AvmMemoryTag::U0, AvmMemoryTag::FF); if (copy_size - pos > 1) { ib = call_data_mem.at(cd_offset + pos + 1); mem_op_b = 1; - mem_idx_b = direct_dst_offset + pos + 1; + mem_addr_b = direct_dst_offset + pos + 1; rwb = 1; // Storing from Ib mem_trace_builder.write_into_memory( - call_ptr, clk, IntermRegister::IB, mem_idx_b, ib, AvmMemoryTag::U0, AvmMemoryTag::FF); + call_ptr, clk, IntermRegister::IB, mem_addr_b, ib, AvmMemoryTag::U0, AvmMemoryTag::FF); } if (copy_size - pos > 2) { ic = call_data_mem.at(cd_offset + pos + 2); mem_op_c = 1; - mem_idx_c = direct_dst_offset + pos + 2; + mem_addr_c = direct_dst_offset + pos + 2; rwc = 1; // Storing from Ic mem_trace_builder.write_into_memory( - call_ptr, clk, IntermRegister::IC, mem_idx_c, ic, AvmMemoryTag::U0, AvmMemoryTag::FF); + call_ptr, clk, IntermRegister::IC, mem_addr_c, ic, AvmMemoryTag::U0, AvmMemoryTag::FF); } // Constrain gas cost on the first row @@ -2047,28 +2049,28 @@ void AvmTraceBuilder::calldata_copy( } main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_call_ptr = call_ptr, - .avm_main_ia = ia, - .avm_main_ib = ib, - .avm_main_ic = ic, - .avm_main_ind_a = indirect_flag ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect_flag)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(mem_idx_a), - .avm_main_mem_idx_b = FF(mem_idx_b), - .avm_main_mem_idx_c = FF(mem_idx_c), - .avm_main_mem_op_a = FF(mem_op_a), - .avm_main_mem_op_activate_gas = FF(static_cast( + .main_clk = clk, + .main_call_ptr = call_ptr, + .main_ia = ia, + .main_ib = ib, + .main_ic = ic, + .main_ind_addr_a = indirect_flag ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(mem_addr_a), + .main_mem_addr_b = FF(mem_addr_b), + .main_mem_addr_c = FF(mem_addr_c), + .main_pc = FF(pc), + .main_rwa = FF(rwa), + .main_rwb = FF(rwb), + .main_rwc = FF(rwc), + .main_sel_mem_op_a = FF(mem_op_a), + .main_sel_mem_op_activate_gas = FF(static_cast( pos == 0)), // TODO: remove in the long term. This activate gas only for the first row. - .avm_main_mem_op_b = FF(mem_op_b), - .avm_main_mem_op_c = FF(mem_op_c), - .avm_main_pc = FF(pc), - .avm_main_rwa = FF(rwa), - .avm_main_rwb = FF(rwb), - .avm_main_rwc = FF(rwc), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_sel_mem_op_b = FF(mem_op_b), + .main_sel_mem_op_c = FF(mem_op_c), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_flag)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), }); if (copy_size - pos > 2) { // Guard to prevent overflow if copy_size is close to uint32_t maximum value. @@ -2126,8 +2128,8 @@ std::vector AvmTraceBuilder::return_op(uint8_t indirect, uint32_t ret_offset FF ic(0); uint32_t mem_op_b(0); uint32_t mem_op_c(0); - uint32_t mem_idx_b(0); - uint32_t mem_idx_c(0); + uint32_t mem_addr_b(0); + uint32_t mem_addr_c(0); auto clk = static_cast(main_trace.size()) + 1; uint32_t mem_op_a(1); @@ -2142,11 +2144,11 @@ std::vector AvmTraceBuilder::return_op(uint8_t indirect, uint32_t ret_offset tag_match = ind_read.tag_match; } - uint32_t mem_idx_a = direct_ret_offset + pos; + uint32_t mem_addr_a = direct_ret_offset + pos; // Reading and loading to Ia auto read_a = mem_trace_builder.read_and_load_from_memory( - call_ptr, clk, IntermRegister::IA, mem_idx_a, AvmMemoryTag::FF, AvmMemoryTag::FF); + call_ptr, clk, IntermRegister::IA, mem_addr_a, AvmMemoryTag::FF, AvmMemoryTag::FF); tag_match = tag_match && read_a.tag_match; FF ia = read_a.val; @@ -2154,11 +2156,11 @@ std::vector AvmTraceBuilder::return_op(uint8_t indirect, uint32_t ret_offset if (ret_size - pos > 1) { mem_op_b = 1; - mem_idx_b = direct_ret_offset + pos + 1; + mem_addr_b = direct_ret_offset + pos + 1; // Reading and loading to Ib auto read_b = mem_trace_builder.read_and_load_from_memory( - call_ptr, clk, IntermRegister::IB, mem_idx_b, AvmMemoryTag::FF, AvmMemoryTag::FF); + call_ptr, clk, IntermRegister::IB, mem_addr_b, AvmMemoryTag::FF, AvmMemoryTag::FF); tag_match = tag_match && read_b.tag_match; ib = read_b.val; returnMem.push_back(ib); @@ -2166,11 +2168,11 @@ std::vector AvmTraceBuilder::return_op(uint8_t indirect, uint32_t ret_offset if (ret_size - pos > 2) { mem_op_c = 1; - mem_idx_c = direct_ret_offset + pos + 2; + mem_addr_c = direct_ret_offset + pos + 2; // Reading and loading to Ic auto read_c = mem_trace_builder.read_and_load_from_memory( - call_ptr, clk, IntermRegister::IC, mem_idx_c, AvmMemoryTag::FF, AvmMemoryTag::FF); + call_ptr, clk, IntermRegister::IC, mem_addr_c, AvmMemoryTag::FF, AvmMemoryTag::FF); tag_match = tag_match && read_c.tag_match; ic = read_c.val; returnMem.push_back(ic); @@ -2182,27 +2184,27 @@ std::vector AvmTraceBuilder::return_op(uint8_t indirect, uint32_t ret_offset } main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_call_ptr = call_ptr, - .avm_main_ia = ia, - .avm_main_ib = ib, - .avm_main_ic = ic, - .avm_main_ind_a = indirect_flag ? FF(ret_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect_flag)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(mem_idx_a), - .avm_main_mem_idx_b = FF(mem_idx_b), - .avm_main_mem_idx_c = FF(mem_idx_c), - .avm_main_mem_op_a = FF(mem_op_a), - .avm_main_mem_op_activate_gas = FF(static_cast( + .main_clk = clk, + .main_call_ptr = call_ptr, + .main_ia = ia, + .main_ib = ib, + .main_ic = ic, + .main_ind_addr_a = indirect_flag ? FF(ret_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(mem_addr_a), + .main_mem_addr_b = FF(mem_addr_b), + .main_mem_addr_c = FF(mem_addr_c), + .main_pc = FF(pc), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_sel_mem_op_a = FF(mem_op_a), + .main_sel_mem_op_activate_gas = FF(static_cast( pos == 0)), // TODO: remove in the long term. This activate gas only for the first row. - .avm_main_mem_op_b = FF(mem_op_b), - .avm_main_mem_op_c = FF(mem_op_c), - .avm_main_pc = FF(pc), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), - .avm_main_sel_halt = FF(1), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_sel_mem_op_b = FF(mem_op_b), + .main_sel_mem_op_c = FF(mem_op_c), + .main_sel_op_halt = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_flag)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), }); if (ret_size - pos > 2) { // Guard to prevent overflow if ret_size is close to uint32_t maximum value. @@ -2226,11 +2228,11 @@ void AvmTraceBuilder::halt() auto clk = main_trace.size() + 1; main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_call_ptr = call_ptr, - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_pc = FF(pc), - .avm_main_sel_halt = FF(1), + .main_clk = clk, + .main_call_ptr = call_ptr, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_pc = FF(pc), + .main_sel_op_halt = FF(1), }); pc = UINT32_MAX; // This ensures that no subsequent opcode will be executed. @@ -2275,22 +2277,22 @@ void AvmTraceBuilder::execute_gasleft(OpCode opcode, uint8_t indirect, uint32_t AvmMemoryTag::FF); // TODO: probably will be U32 in final version main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_call_ptr = call_ptr, - .avm_main_ia = gas_remaining, - .avm_main_ind_a = indirect_dst_flag ? FF(dst_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect_dst_flag)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(direct_dst_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U0)), - .avm_main_rwa = FF(1), - .avm_main_sel_op_dagasleft = (opcode == OpCode::DAGASLEFT) ? FF(1) : FF(0), - .avm_main_sel_op_l2gasleft = (opcode == OpCode::L2GASLEFT) ? FF(1) : FF(0), - .avm_main_tag_err = FF(static_cast(!tag_match)), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), // TODO: probably will be U32 in final version - // Should the circuit (pil) constrain U32? + .main_clk = clk, + .main_call_ptr = call_ptr, + .main_ia = gas_remaining, + .main_ind_addr_a = indirect_dst_flag ? FF(dst_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_dst_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U0)), + .main_rwa = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_op_dagasleft = (opcode == OpCode::DAGASLEFT) ? FF(1) : FF(0), + .main_sel_op_l2gasleft = (opcode == OpCode::L2GASLEFT) ? FF(1) : FF(0), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_dst_flag)), + .main_tag_err = FF(static_cast(!tag_match)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), // TODO: probably will be U32 in final version + // Should the circuit (pil) constrain U32? }); } @@ -2320,12 +2322,12 @@ void AvmTraceBuilder::jump(uint32_t jmp_dest) gas_trace_builder.constrain_gas_lookup(clk, OpCode::JUMP); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_call_ptr = call_ptr, - .avm_main_ia = FF(jmp_dest), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_pc = FF(pc), - .avm_main_sel_jump = FF(1), + .main_clk = clk, + .main_call_ptr = call_ptr, + .main_ia = FF(jmp_dest), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_pc = FF(pc), + .main_sel_op_jump = FF(1), }); // Adjust parameters for the next row @@ -2369,22 +2371,22 @@ void AvmTraceBuilder::jumpi(uint8_t indirect, uint32_t jmp_dest, uint32_t cond_o gas_trace_builder.constrain_gas_lookup(clk, OpCode::JUMPI); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_call_ptr = call_ptr, - .avm_main_ia = FF(next_pc), - .avm_main_id = read_d.val, - .avm_main_id_zero = static_cast(id_zero), - .avm_main_ind_d = indirect_cond_flag ? cond_offset : 0, - .avm_main_ind_op_d = static_cast(indirect_cond_flag), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_inv = inv, - .avm_main_mem_idx_d = direct_cond_offset, - .avm_main_mem_op_d = 1, - .avm_main_pc = FF(pc), - .avm_main_r_in_tag = static_cast(read_d.tag), - .avm_main_sel_jumpi = FF(1), - .avm_main_tag_err = static_cast(!tag_match), - .avm_main_w_in_tag = static_cast(read_d.tag), + .main_clk = clk, + .main_call_ptr = call_ptr, + .main_ia = FF(next_pc), + .main_id = read_d.val, + .main_id_zero = static_cast(id_zero), + .main_ind_addr_d = indirect_cond_flag ? cond_offset : 0, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_inv = inv, + .main_mem_addr_d = direct_cond_offset, + .main_pc = FF(pc), + .main_r_in_tag = static_cast(read_d.tag), + .main_sel_mem_op_d = 1, + .main_sel_op_jumpi = FF(1), + .main_sel_resolve_ind_addr_d = static_cast(indirect_cond_flag), + .main_tag_err = static_cast(!tag_match), + .main_w_in_tag = static_cast(read_d.tag), }); // Adjust parameters for the next row @@ -2421,17 +2423,17 @@ void AvmTraceBuilder::internal_call(uint32_t jmp_dest) gas_trace_builder.constrain_gas_lookup(clk, OpCode::INTERNALCALL); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_call_ptr = call_ptr, - .avm_main_ia = FF(jmp_dest), - .avm_main_ib = FF(pc + 1), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_b = FF(internal_return_ptr), - .avm_main_mem_op_b = FF(1), - .avm_main_pc = FF(pc), - .avm_main_rwb = FF(1), - .avm_main_sel_internal_call = FF(1), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_clk = clk, + .main_call_ptr = call_ptr, + .main_ia = FF(jmp_dest), + .main_ib = FF(pc + 1), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_b = FF(internal_return_ptr), + .main_pc = FF(pc), + .main_rwb = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_op_internal_call = FF(1), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U32)), }); // Adjust parameters for the next row @@ -2463,17 +2465,17 @@ void AvmTraceBuilder::internal_return() gas_trace_builder.constrain_gas_lookup(clk, OpCode::INTERNALRETURN); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_call_ptr = call_ptr, - .avm_main_ia = read_a.val, - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(internal_return_ptr - 1), - .avm_main_mem_op_a = FF(1), - .avm_main_pc = pc, - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), - .avm_main_rwa = FF(0), - .avm_main_sel_internal_return = FF(1), - .avm_main_tag_err = FF(static_cast(!read_a.tag_match)), + .main_clk = clk, + .main_call_ptr = call_ptr, + .main_ia = read_a.val, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(internal_return_ptr - 1), + .main_pc = pc, + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_rwa = FF(0), + .main_sel_mem_op_a = FF(1), + .main_sel_op_internal_return = FF(1), + .main_tag_err = FF(static_cast(!read_a.tag_match)), }); pc = uint32_t(read_a.val); @@ -2496,11 +2498,11 @@ void AvmTraceBuilder::write_slice_to_memory(uint8_t space_id, static_cast(slice.size()) / 4 + static_cast(slice.size() % 4 != 0); for (uint32_t i = 0; i < num_main_rows; i++) { Row main_row{ - .avm_main_clk = clk + i, - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_pc = FF(pc), - .avm_main_r_in_tag = FF(static_cast(r_tag)), - .avm_main_w_in_tag = FF(static_cast(w_tag)), + .main_clk = clk + i, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_pc = FF(pc), + .main_r_in_tag = FF(static_cast(r_tag)), + .main_w_in_tag = FF(static_cast(w_tag)), }; // Write 4 values to memory in each_row for (uint32_t j = 0; j < 4; j++) { @@ -2513,25 +2515,25 @@ void AvmTraceBuilder::write_slice_to_memory(uint8_t space_id, space_id, clk + i, register_order[j], dst_offset + offset, slice.at(offset), r_tag, w_tag); // This looks a bit gross, but it is fine for now. if (j == 0) { - main_row.avm_main_ia = slice.at(offset); - main_row.avm_main_mem_idx_a = FF(dst_offset + offset); - main_row.avm_main_mem_op_a = FF(1); - main_row.avm_main_rwa = FF(1); + main_row.main_ia = slice.at(offset); + main_row.main_mem_addr_a = FF(dst_offset + offset); + main_row.main_sel_mem_op_a = FF(1); + main_row.main_rwa = FF(1); } else if (j == 1) { - main_row.avm_main_ib = slice.at(offset); - main_row.avm_main_mem_idx_b = FF(dst_offset + offset); - main_row.avm_main_mem_op_b = FF(1); - main_row.avm_main_rwb = FF(1); + main_row.main_ib = slice.at(offset); + main_row.main_mem_addr_b = FF(dst_offset + offset); + main_row.main_sel_mem_op_b = FF(1); + main_row.main_rwb = FF(1); } else if (j == 2) { - main_row.avm_main_ic = slice.at(offset); - main_row.avm_main_mem_idx_c = FF(dst_offset + offset); - main_row.avm_main_mem_op_c = FF(1); - main_row.avm_main_rwc = FF(1); + main_row.main_ic = slice.at(offset); + main_row.main_mem_addr_c = FF(dst_offset + offset); + main_row.main_sel_mem_op_c = FF(1); + main_row.main_rwc = FF(1); } else { - main_row.avm_main_id = slice.at(offset); - main_row.avm_main_mem_idx_d = FF(dst_offset + offset); - main_row.avm_main_mem_op_d = FF(1); - main_row.avm_main_rwd = FF(1); + main_row.main_id = slice.at(offset); + main_row.main_mem_addr_d = FF(dst_offset + offset); + main_row.main_sel_mem_op_d = FF(1); + main_row.main_rwd = FF(1); } } main_trace.emplace_back(main_row); @@ -2564,11 +2566,11 @@ uint32_t AvmTraceBuilder::read_slice_to_memory(uint8_t space_id, uint32_t const num_main_rows = static_cast(slice_len) / 4 + static_cast(slice_len % 4 != 0); for (uint32_t i = 0; i < num_main_rows; i++) { Row main_row{ - .avm_main_clk = clk + i, - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_pc = FF(pc), - .avm_main_r_in_tag = FF(static_cast(r_tag)), - .avm_main_w_in_tag = FF(static_cast(w_tag)), + .main_clk = clk + i, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_pc = FF(pc), + .main_r_in_tag = FF(static_cast(r_tag)), + .main_w_in_tag = FF(static_cast(w_tag)), }; // Write 4 values to memory in each_row for (uint32_t j = 0; j < 4; j++) { @@ -2582,25 +2584,25 @@ uint32_t AvmTraceBuilder::read_slice_to_memory(uint8_t space_id, slice.emplace_back(MEM(mem_read.val)); // This looks a bit gross, but it is fine for now. if (j == 0) { - main_row.avm_main_ia = slice.at(offset); - main_row.avm_main_mem_idx_a = FF(src_offset + offset); - main_row.avm_main_mem_op_a = FF(1); - main_row.avm_main_tag_err = FF(static_cast(!mem_read.tag_match)); + main_row.main_ia = slice.at(offset); + main_row.main_mem_addr_a = FF(src_offset + offset); + main_row.main_sel_mem_op_a = FF(1); + main_row.main_tag_err = FF(static_cast(!mem_read.tag_match)); } else if (j == 1) { - main_row.avm_main_ib = slice.at(offset); - main_row.avm_main_mem_idx_b = FF(src_offset + offset); - main_row.avm_main_mem_op_b = FF(1); - main_row.avm_main_tag_err = FF(static_cast(!mem_read.tag_match)); + main_row.main_ib = slice.at(offset); + main_row.main_mem_addr_b = FF(src_offset + offset); + main_row.main_sel_mem_op_b = FF(1); + main_row.main_tag_err = FF(static_cast(!mem_read.tag_match)); } else if (j == 2) { - main_row.avm_main_ic = slice.at(offset); - main_row.avm_main_mem_idx_c = FF(src_offset + offset); - main_row.avm_main_mem_op_c = FF(1); - main_row.avm_main_tag_err = FF(static_cast(!mem_read.tag_match)); + main_row.main_ic = slice.at(offset); + main_row.main_mem_addr_c = FF(src_offset + offset); + main_row.main_sel_mem_op_c = FF(1); + main_row.main_tag_err = FF(static_cast(!mem_read.tag_match)); } else { - main_row.avm_main_id = slice.at(offset); - main_row.avm_main_mem_idx_d = FF(src_offset + offset); - main_row.avm_main_mem_op_d = FF(1); - main_row.avm_main_tag_err = FF(static_cast(!mem_read.tag_match)); + main_row.main_id = slice.at(offset); + main_row.main_mem_addr_d = FF(src_offset + offset); + main_row.main_sel_mem_op_d = FF(1); + main_row.main_tag_err = FF(static_cast(!mem_read.tag_match)); } } main_trace.emplace_back(main_row); @@ -2666,24 +2668,24 @@ void AvmTraceBuilder::op_call([[maybe_unused]] uint8_t indirect, // We read the input and output addresses in one row as they should contain FF elements main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = first_row_values[0], /* gas_offset */ - .avm_main_ib = first_row_values[1], /* addr_offset */ - .avm_main_ic = first_row_values[2], /* args_offset */ - .avm_main_ind_a = gas_offset, - .avm_main_ind_c = args_offset, - .avm_main_ind_op_a = FF(1), - .avm_main_ind_op_c = FF(1), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = read_ind_gas_offset.val, - .avm_main_mem_idx_b = addr_offset, - .avm_main_mem_idx_c = read_ind_args_offset.val, - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), - .avm_main_sel_external_call = FF(1), + .main_clk = clk, + .main_ia = first_row_values[0], /* gas_offset */ + .main_ib = first_row_values[1], /* addr_offset */ + .main_ic = first_row_values[2], /* args_offset */ + .main_ind_addr_a = gas_offset, + .main_ind_addr_c = args_offset, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = read_ind_gas_offset.val, + .main_mem_addr_b = addr_offset, + .main_mem_addr_c = read_ind_args_offset.val, + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_external_call = FF(1), + .main_sel_resolve_ind_addr_a = FF(1), + .main_sel_resolve_ind_addr_c = FF(1), }); clk++; // Read the rest on a separate line, remember that the 4th operand is indirect @@ -2693,27 +2695,27 @@ void AvmTraceBuilder::op_call([[maybe_unused]] uint8_t indirect, auto mem_read_ret = mem_trace_builder.read_and_load_from_memory( call_ptr, clk, IntermRegister::IA, uint32_t(read_ind_ret_offset.val), AvmMemoryTag::FF, AvmMemoryTag::U0); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = mem_read_ret.val, /* ret_offset */ - .avm_main_ind_a = ret_offset, - .avm_main_ind_op_a = FF(1), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = read_ind_ret_offset.val, - .avm_main_mem_op_a = FF(1), - .avm_main_pc = FF(pc), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_clk = clk, + .main_ia = mem_read_ret.val, /* ret_offset */ + .main_ind_addr_a = ret_offset, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = read_ind_ret_offset.val, + .main_pc = FF(pc), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_sel_mem_op_a = FF(1), + .main_sel_resolve_ind_addr_a = FF(1), }); clk++; auto mem_read_success = mem_trace_builder.read_and_load_from_memory( call_ptr, clk, IntermRegister::IA, success_offset, AvmMemoryTag::U32, AvmMemoryTag::U0); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = mem_read_success.val, /* success_offset */ - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(success_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_pc = FF(pc), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_clk = clk, + .main_ia = mem_read_success.val, /* success_offset */ + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(success_offset), + .main_pc = FF(pc), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_sel_mem_op_a = FF(1), }); clk++; write_slice_to_memory(call_ptr, @@ -2762,22 +2764,22 @@ void AvmTraceBuilder::op_get_contract_instance(uint8_t indirect, uint32_t addres gas_trace_builder.constrain_gas_lookup(clk, OpCode::GETCONTRACTINSTANCE); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = read_address.val, - .avm_main_ib = read_dst.val, - .avm_main_ind_a = indirect_address_flag ? address_offset : 0, - .avm_main_ind_b = indirect_dst_flag ? dst_offset : 0, - .avm_main_ind_op_a = FF(static_cast(indirect_address_flag)), - .avm_main_ind_op_b = FF(static_cast(indirect_dst_flag)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(direct_address_offset), - .avm_main_mem_idx_b = FF(direct_dst_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_activate_gas = FF(1), // TODO: remove in the long term - .avm_main_mem_op_b = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), - .avm_main_sel_op_get_contract_instance = FF(1), + .main_clk = clk, + .main_ia = read_address.val, + .main_ib = read_dst.val, + .main_ind_addr_a = indirect_address_flag ? address_offset : 0, + .main_ind_addr_b = indirect_dst_flag ? dst_offset : 0, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_address_offset), + .main_mem_addr_b = FF(direct_dst_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_activate_gas = FF(1), // TODO: remove in the long term + .main_sel_mem_op_b = FF(1), + .main_sel_op_get_contract_instance = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_address_flag)), + .main_sel_resolve_ind_addr_b = FF(static_cast(indirect_dst_flag)), }); clk++; // Read the contract instance @@ -2854,25 +2856,25 @@ void AvmTraceBuilder::op_to_radix_le( // This is the row that contains the selector to trigger the sel_op_radix_le // In this row, we read the input value and the destination address into register A and B respectively main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_call_ptr = call_ptr, - .avm_main_ia = input, - .avm_main_ib = dst_addr, - .avm_main_ic = radix, - .avm_main_id = num_limbs, - .avm_main_ind_a = indirect_src_flag ? src_offset : 0, - .avm_main_ind_b = indirect_dst_flag ? dst_offset : 0, - .avm_main_ind_op_a = FF(static_cast(indirect_src_flag)), - .avm_main_ind_op_b = FF(static_cast(indirect_dst_flag)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(direct_src_offset), - .avm_main_mem_idx_b = FF(direct_dst_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), - .avm_main_sel_op_radix_le = FF(1), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), + .main_clk = clk, + .main_call_ptr = call_ptr, + .main_ia = input, + .main_ib = dst_addr, + .main_ic = radix, + .main_id = num_limbs, + .main_ind_addr_a = indirect_src_flag ? src_offset : 0, + .main_ind_addr_b = indirect_dst_flag ? dst_offset : 0, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_src_offset), + .main_mem_addr_b = FF(direct_dst_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_op_radix_le = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_src_flag)), + .main_sel_resolve_ind_addr_b = FF(static_cast(indirect_dst_flag)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), }); // Increment the clock so we dont write at the same clock cycle // Instead we temporarily encode the writes into the subsequent rows of the main trace @@ -2930,27 +2932,27 @@ void AvmTraceBuilder::op_sha256_compression(uint8_t indirect, // Note: we could avoid output being zero if we loaded the input and state beforehand (with a new function that // did not lay down constraints), but this is a simplification main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = read_a.val, // First element of output (trivially 0) - .avm_main_ib = read_b.val, // First element of state - .avm_main_ic = read_c.val, // First element of input - .avm_main_ind_a = res.indirect_flag_a ? FF(h_init_offset) : FF(0), - .avm_main_ind_b = res.indirect_flag_b ? FF(input_offset) : FF(0), - .avm_main_ind_c = res.indirect_flag_a ? FF(output_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(res.indirect_flag_a)), - .avm_main_ind_op_b = FF(static_cast(res.indirect_flag_b)), - .avm_main_ind_op_c = FF(static_cast(res.indirect_flag_c)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(res.direct_a_offset), - .avm_main_mem_idx_b = FF(res.direct_b_offset), - .avm_main_mem_idx_c = FF(res.direct_c_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), - .avm_main_sel_op_sha256 = FF(1), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_clk = clk, + .main_ia = read_a.val, // First element of output (trivially 0) + .main_ib = read_b.val, // First element of state + .main_ic = read_c.val, // First element of input + .main_ind_addr_a = res.indirect_flag_a ? FF(h_init_offset) : FF(0), + .main_ind_addr_b = res.indirect_flag_b ? FF(input_offset) : FF(0), + .main_ind_addr_c = res.indirect_flag_a ? FF(output_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(res.direct_a_offset), + .main_mem_addr_b = FF(res.direct_b_offset), + .main_mem_addr_c = FF(res.direct_c_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_sha256 = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(res.indirect_flag_a)), + .main_sel_resolve_ind_addr_b = FF(static_cast(res.indirect_flag_b)), + .main_sel_resolve_ind_addr_c = FF(static_cast(res.indirect_flag_c)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U32)), }); // We store the current clk this main trace row occurred so that we can line up the sha256 gadget operation at // the same clk later. @@ -3051,35 +3053,35 @@ void AvmTraceBuilder::op_sha256(uint8_t indirect, // Store the clock time that we will use to line up the gadget later auto sha256_op_clk = clk; main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = input_read.val, // First element of input - .avm_main_ic = output_read.val, // First element of output - .avm_main_ind_a = indirect_src_flag ? FF(input_offset) : FF(0), - .avm_main_ind_c = indirect_dst_flag ? FF(output_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect_src_flag)), - .avm_main_ind_op_c = FF(static_cast(indirect_dst_flag)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(direct_src_offset), // input - .avm_main_mem_idx_c = FF(direct_dst_offset), // output - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U8)), - .avm_main_sel_op_sha256 = FF(1), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), + .main_clk = clk, + .main_ia = input_read.val, // First element of input + .main_ic = output_read.val, // First element of output + .main_ind_addr_a = indirect_src_flag ? FF(input_offset) : FF(0), + .main_ind_addr_c = indirect_dst_flag ? FF(output_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_src_offset), // input + .main_mem_addr_c = FF(direct_dst_offset), // output + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U8)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_sha256 = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_src_flag)), + .main_sel_resolve_ind_addr_c = FF(static_cast(indirect_dst_flag)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), }); clk++; auto input_length_read = mem_trace_builder.read_and_load_from_memory( call_ptr, clk, IntermRegister::IB, input_size_offset, AvmMemoryTag::U32, AvmMemoryTag::U32); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ib = input_length_read.val, // Message Length - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_b = FF(input_size_offset), // length - .avm_main_mem_op_b = FF(1), - .avm_main_pc = FF(pc), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_clk = clk, + .main_ib = input_length_read.val, // Message Length + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_b = FF(input_size_offset), // length + .main_pc = FF(pc), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_sel_mem_op_b = FF(1), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U32)), }); clk++; @@ -3094,11 +3096,11 @@ void AvmTraceBuilder::op_sha256(uint8_t indirect, static_cast(uint32_t(input_length_read.val) % 4 != 0); for (uint32_t i = 0; i < num_main_rows; i++) { Row main_row{ - .avm_main_clk = clk + i, - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_pc = FF(pc), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U8)), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), + .main_clk = clk + i, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_pc = FF(pc), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U8)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), }; // Write 4 values to memory in each_row for (uint32_t j = 0; j < 4; j++) { @@ -3112,25 +3114,25 @@ void AvmTraceBuilder::op_sha256(uint8_t indirect, input.emplace_back(uint8_t(mem_read.val)); // This looks a bit gross, but it is fine for now. if (j == 0) { - main_row.avm_main_ia = input.at(offset); - main_row.avm_main_mem_idx_a = FF(direct_src_offset + offset); - main_row.avm_main_mem_op_a = FF(1); - main_row.avm_main_tag_err = FF(static_cast(!mem_read.tag_match)); + main_row.main_ia = input.at(offset); + main_row.main_mem_addr_a = FF(direct_src_offset + offset); + main_row.main_sel_mem_op_a = FF(1); + main_row.main_tag_err = FF(static_cast(!mem_read.tag_match)); } else if (j == 1) { - main_row.avm_main_ib = input.at(offset); - main_row.avm_main_mem_idx_b = FF(direct_src_offset + offset); - main_row.avm_main_mem_op_b = FF(1); - main_row.avm_main_tag_err = FF(static_cast(!mem_read.tag_match)); + main_row.main_ib = input.at(offset); + main_row.main_mem_addr_b = FF(direct_src_offset + offset); + main_row.main_sel_mem_op_b = FF(1); + main_row.main_tag_err = FF(static_cast(!mem_read.tag_match)); } else if (j == 2) { - main_row.avm_main_ic = input.at(offset); - main_row.avm_main_mem_idx_c = FF(direct_src_offset + offset); - main_row.avm_main_mem_op_c = FF(1); - main_row.avm_main_tag_err = FF(static_cast(!mem_read.tag_match)); + main_row.main_ic = input.at(offset); + main_row.main_mem_addr_c = FF(direct_src_offset + offset); + main_row.main_sel_mem_op_c = FF(1); + main_row.main_tag_err = FF(static_cast(!mem_read.tag_match)); } else { - main_row.avm_main_id = input.at(offset); - main_row.avm_main_mem_idx_d = FF(direct_src_offset + offset); - main_row.avm_main_mem_op_d = FF(1); - main_row.avm_main_tag_err = FF(static_cast(!mem_read.tag_match)); + main_row.main_id = input.at(offset); + main_row.main_mem_addr_d = FF(direct_src_offset + offset); + main_row.main_sel_mem_op_d = FF(1); + main_row.main_tag_err = FF(static_cast(!mem_read.tag_match)); } } main_trace.emplace_back(main_row); @@ -3195,22 +3197,22 @@ void AvmTraceBuilder::op_poseidon2_permutation(uint8_t indirect, uint32_t input_ gas_trace_builder.constrain_gas_lookup(clk, OpCode::POSEIDON2); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = read_a.val, // First element of input - .avm_main_ib = read_b.val, // First element of output (trivially zero) - .avm_main_ind_a = indirect_src_flag ? FF(input_offset) : FF(0), - .avm_main_ind_b = indirect_dst_flag ? FF(output_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect_src_flag)), - .avm_main_ind_op_b = FF(static_cast(indirect_dst_flag)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(direct_src_offset), - .avm_main_mem_idx_b = FF(direct_dst_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), - .avm_main_sel_op_poseidon2 = FF(1), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_clk = clk, + .main_ia = read_a.val, // First element of input + .main_ib = read_b.val, // First element of output (trivially zero) + .main_ind_addr_a = indirect_src_flag ? FF(input_offset) : FF(0), + .main_ind_addr_b = indirect_dst_flag ? FF(output_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_src_offset), + .main_mem_addr_b = FF(direct_dst_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_op_poseidon2 = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_src_flag)), + .main_sel_resolve_ind_addr_b = FF(static_cast(indirect_dst_flag)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), }); // We store the current clk this main trace row occurred so that we can line up the poseidon2 gadget operation // at the same clk later. @@ -3285,22 +3287,22 @@ void AvmTraceBuilder::op_keccakf1600(uint8_t indirect, gas_trace_builder.constrain_gas_lookup(clk, OpCode::KECCAKF1600); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = input_read.val, // First element of input - .avm_main_ic = output_read.val, // First element of output - .avm_main_ind_a = indirect_src_flag ? FF(input_offset) : FF(0), - .avm_main_ind_c = indirect_dst_flag ? FF(output_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect_src_flag)), - .avm_main_ind_op_c = FF(static_cast(indirect_dst_flag)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(direct_src_offset), // input - .avm_main_mem_idx_c = FF(direct_dst_offset), // output - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U64)), - .avm_main_sel_op_keccak = FF(1), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::U64)), + .main_clk = clk, + .main_ia = input_read.val, // First element of input + .main_ic = output_read.val, // First element of output + .main_ind_addr_a = indirect_src_flag ? FF(input_offset) : FF(0), + .main_ind_addr_c = indirect_dst_flag ? FF(output_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_src_offset), // input + .main_mem_addr_c = FF(direct_dst_offset), // output + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U64)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_keccak = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_src_flag)), + .main_sel_resolve_ind_addr_c = FF(static_cast(indirect_dst_flag)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U64)), }); // We store the current clk this main trace row occurred so that we can line up the keccak gadget operation // at the same clk later. @@ -3310,14 +3312,14 @@ void AvmTraceBuilder::op_keccakf1600(uint8_t indirect, auto input_length_read = mem_trace_builder.read_and_load_from_memory( call_ptr, clk, IntermRegister::IB, input_size_offset, AvmMemoryTag::U32, AvmMemoryTag::U32); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ib = input_length_read.val, // Message Length - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_b = FF(input_size_offset), // length - .avm_main_mem_op_b = FF(1), - .avm_main_pc = FF(pc), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_clk = clk, + .main_ib = input_length_read.val, // Message Length + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_b = FF(input_size_offset), // length + .main_pc = FF(pc), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_sel_mem_op_b = FF(1), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U32)), }); clk++; // Array input is fixed to 1600 bits @@ -3393,35 +3395,35 @@ void AvmTraceBuilder::op_keccak(uint8_t indirect, // Store the clock time that we will use to line up the gadget later auto keccak_op_clk = clk; main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = input_read.val, // First element of input - .avm_main_ic = output_read.val, // First element of output - .avm_main_ind_a = indirect_src_flag ? FF(input_offset) : FF(0), - .avm_main_ind_c = indirect_dst_flag ? FF(output_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect_src_flag)), - .avm_main_ind_op_c = FF(static_cast(indirect_dst_flag)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(direct_src_offset), // input - .avm_main_mem_idx_c = FF(direct_dst_offset), // output - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U8)), - .avm_main_sel_op_keccak = FF(1), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), + .main_clk = clk, + .main_ia = input_read.val, // First element of input + .main_ic = output_read.val, // First element of output + .main_ind_addr_a = indirect_src_flag ? FF(input_offset) : FF(0), + .main_ind_addr_c = indirect_dst_flag ? FF(output_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_src_offset), // input + .main_mem_addr_c = FF(direct_dst_offset), // output + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U8)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_op_keccak = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_src_flag)), + .main_sel_resolve_ind_addr_c = FF(static_cast(indirect_dst_flag)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), }); clk++; auto input_length_read = mem_trace_builder.read_and_load_from_memory( call_ptr, clk, IntermRegister::IB, input_size_offset, AvmMemoryTag::U32, AvmMemoryTag::U32); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ib = input_length_read.val, // Message Length - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_b = FF(input_size_offset), // length - .avm_main_mem_op_b = FF(1), - .avm_main_pc = FF(pc), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_clk = clk, + .main_ib = input_length_read.val, // Message Length + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_b = FF(input_size_offset), // length + .main_pc = FF(pc), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_sel_mem_op_b = FF(1), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U32)), }); clk++; @@ -3478,17 +3480,17 @@ void AvmTraceBuilder::op_pedersen_hash(uint8_t indirect, uint32_t pedersen_clk = clk; // We read the input and output addresses in one row as they should contain FF elements main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = input_read.val, // First element of input - .avm_main_ind_a = indirect_src_flag ? FF(input_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect_src_flag)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(direct_src_offset), // input - .avm_main_mem_op_a = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), - .avm_main_sel_op_pedersen = FF(1), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_clk = clk, + .main_ia = input_read.val, // First element of input + .main_ind_addr_a = indirect_src_flag ? FF(input_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_src_offset), // input + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_sel_mem_op_a = FF(1), + .main_sel_op_pedersen = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_src_flag)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), }); clk++; // We read the input size and gen_ctx addresses in one row as they should contain U32 elements @@ -3497,17 +3499,17 @@ void AvmTraceBuilder::op_pedersen_hash(uint8_t indirect, auto gen_ctx_read = mem_trace_builder.read_and_load_from_memory( call_ptr, clk, IntermRegister::IB, gen_ctx_offset, AvmMemoryTag::U32, AvmMemoryTag::U32); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = input_size_read.val, - .avm_main_ib = gen_ctx_read.val, - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(input_size_offset), - .avm_main_mem_idx_b = FF(gen_ctx_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_pc = FF(pc), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_clk = clk, + .main_ia = input_size_read.val, + .main_ib = gen_ctx_read.val, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(input_size_offset), + .main_mem_addr_b = FF(gen_ctx_offset), + .main_pc = FF(pc), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U32)), }); clk++; @@ -3550,22 +3552,22 @@ void AvmTraceBuilder::op_ec_add(uint8_t indirect, // Save this clk time to line up with the gadget op. auto ecc_clk = clk; main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = lhs_x_read.val, - .avm_main_ib = lhs_y_read.val, - .avm_main_ic = rhs_x_read.val, - .avm_main_id = rhs_y_read.val, - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(lhs_x_offset), - .avm_main_mem_idx_b = FF(lhs_y_offset), - .avm_main_mem_idx_c = FF(rhs_x_offset), - .avm_main_mem_idx_d = FF(rhs_y_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_mem_op_c = FF(1), - .avm_main_mem_op_d = FF(1), - .avm_main_pc = FF(pc++), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_clk = clk, + .main_ia = lhs_x_read.val, + .main_ib = lhs_y_read.val, + .main_ic = rhs_x_read.val, + .main_id = rhs_y_read.val, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(lhs_x_offset), + .main_mem_addr_b = FF(lhs_y_offset), + .main_mem_addr_c = FF(rhs_x_offset), + .main_mem_addr_d = FF(rhs_y_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_mem_op_d = FF(1), }); clk++; // Load the infinite bools separately since they have a different memory tag @@ -3575,16 +3577,16 @@ void AvmTraceBuilder::op_ec_add(uint8_t indirect, call_ptr, clk, IntermRegister::IB, rhs_is_inf_offset, AvmMemoryTag::U8, AvmMemoryTag::U0); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = lhs_is_inf_read.val, - .avm_main_ib = rhs_is_inf_read.val, - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(lhs_is_inf_offset), - .avm_main_mem_idx_b = FF(rhs_is_inf_offset), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_pc = FF(pc), - .avm_main_r_in_tag = FF(static_cast(AvmMemoryTag::U8)), + .main_clk = clk, + .main_ia = lhs_is_inf_read.val, + .main_ib = rhs_is_inf_read.val, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(lhs_is_inf_offset), + .main_mem_addr_b = FF(rhs_is_inf_offset), + .main_pc = FF(pc), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U8)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), }); clk++; grumpkin::g1::affine_element lhs = uint8_t(lhs_is_inf_read.val) == 1 @@ -3608,20 +3610,20 @@ void AvmTraceBuilder::op_ec_add(uint8_t indirect, mem_trace_builder.write_into_memory( call_ptr, clk, IntermRegister::IB, direct_output_offset + 1, result.y, AvmMemoryTag::U0, AvmMemoryTag::FF); main_trace.push_back(Row{ - .avm_main_clk = clk, - .avm_main_ia = result.x, - .avm_main_ib = result.y, - .avm_main_ind_a = indirect_flag_output ? FF(output_offset) : FF(0), - .avm_main_ind_op_a = FF(static_cast(indirect_flag_output)), - .avm_main_internal_return_ptr = FF(internal_return_ptr), - .avm_main_mem_idx_a = FF(direct_output_offset), - .avm_main_mem_idx_b = FF(direct_output_offset + 1), - .avm_main_mem_op_a = FF(1), - .avm_main_mem_op_b = FF(1), - .avm_main_pc = FF(pc), - .avm_main_rwa = FF(1), - .avm_main_rwb = FF(1), - .avm_main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_clk = clk, + .main_ia = result.x, + .main_ib = result.y, + .main_ind_addr_a = indirect_flag_output ? FF(output_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_output_offset), + .main_mem_addr_b = FF(direct_output_offset + 1), + .main_pc = FF(pc), + .main_rwa = FF(1), + .main_rwb = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_flag_output)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), }); clk++; write_slice_to_memory(call_ptr, @@ -3632,6 +3634,255 @@ void AvmTraceBuilder::op_ec_add(uint8_t indirect, FF(internal_return_ptr), { result.is_point_at_infinity() }); } + +// This function is a bit overloaded with logic around reconstructing points and scalars that could probably be moved to +// the gadget at some stage (although this is another temporary gadget..) +void AvmTraceBuilder::op_variable_msm(uint8_t indirect, + uint32_t points_offset, + uint32_t scalars_offset, + uint32_t output_offset, + uint32_t point_length_offset) +{ + auto clk = static_cast(main_trace.size()) + 1; + // This will all get refactored as part of the indirection refactor + bool tag_match = true; + uint32_t direct_points_offset = points_offset; + uint32_t direct_scalars_offset = scalars_offset; + uint32_t direct_output_offset = output_offset; + // Resolve the indirects + bool indirect_points_flag = is_operand_indirect(indirect, 0); + bool indirect_scalars_flag = is_operand_indirect(indirect, 1); + bool indirect_output_flag = is_operand_indirect(indirect, 2); + + // Read in the points first + if (indirect_points_flag) { + auto read_ind_a = + mem_trace_builder.indirect_read_and_load_from_memory(call_ptr, clk, IndirectRegister::IND_A, points_offset); + direct_points_offset = uint32_t(read_ind_a.val); + tag_match = tag_match && read_ind_a.tag_match; + } + + auto read_points = mem_trace_builder.read_and_load_from_memory( + call_ptr, clk, IntermRegister::IA, direct_points_offset, AvmMemoryTag::FF, AvmMemoryTag::U0); + + // Read in the scalars + if (indirect_scalars_flag) { + auto read_ind_b = mem_trace_builder.indirect_read_and_load_from_memory( + call_ptr, clk, IndirectRegister::IND_B, scalars_offset); + direct_scalars_offset = uint32_t(read_ind_b.val); + tag_match = tag_match && read_ind_b.tag_match; + } + auto read_scalars = mem_trace_builder.read_and_load_from_memory( + call_ptr, clk, IntermRegister::IB, direct_scalars_offset, AvmMemoryTag::FF, AvmMemoryTag::U0); + + // In the refactor we will have the read_slice function handle indirects as well + main_trace.push_back(Row{ + .main_clk = clk, + .main_ia = read_points.val, + .main_ib = read_scalars.val, + .main_ind_addr_a = indirect_points_flag ? FF(points_offset) : FF(0), + .main_ind_addr_b = indirect_scalars_flag ? FF(scalars_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_points_offset), + .main_mem_addr_b = FF(direct_scalars_offset), + .main_pc = FF(pc++), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_points_flag)), + .main_sel_resolve_ind_addr_b = FF(static_cast(indirect_scalars_flag)), + .main_tag_err = FF(static_cast(!tag_match)), + }); + clk++; + + // Read the points length (different row since it has a different memory tag) + auto points_length_read = mem_trace_builder.read_and_load_from_memory( + call_ptr, clk, IntermRegister::IA, point_length_offset, AvmMemoryTag::U32, AvmMemoryTag::U0); + main_trace.push_back(Row{ + .main_clk = clk, + .main_ia = points_length_read.val, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(point_length_offset), + .main_pc = FF(pc), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U32)), + .main_sel_mem_op_a = FF(1), + .main_tag_err = FF(static_cast(!points_length_read.tag_match)), + }); + clk++; + + // Points are stored as [x1, y1, inf1, x2, y2, inf2, ...] with the types [FF, FF, U8, FF, FF, U8, ...] + uint32_t num_points = uint32_t(points_length_read.val) / 3; // 3 elements per point + // We need to split up the reads due to the memory tags, + std::vector points_coords_vec; + std::vector points_inf_vec; + std::vector scalars_vec; + // Read the coordinates first, +2 since we read 2 points per row + for (uint32_t i = 0; i < num_points; i += 2) { + // We can read up to 4 coordinates per row (x1,y1,x2,y2) + // Each pair of coordinates are separated by 3 memory addressess + auto point_x1_read = mem_trace_builder.read_and_load_from_memory( + call_ptr, clk, IntermRegister::IA, direct_points_offset + i * 3, AvmMemoryTag::FF, AvmMemoryTag::U0); + auto point_y1_read = mem_trace_builder.read_and_load_from_memory( + call_ptr, clk, IntermRegister::IB, direct_points_offset + i * 3 + 1, AvmMemoryTag::FF, AvmMemoryTag::U0); + auto point_x2_read = mem_trace_builder.read_and_load_from_memory( + call_ptr, clk, IntermRegister::IC, direct_points_offset + (i + 1) * 3, AvmMemoryTag::FF, AvmMemoryTag::U0); + auto point_y2_read = mem_trace_builder.read_and_load_from_memory(call_ptr, + clk, + IntermRegister::ID, + direct_points_offset + (i + 1) * 3 + 1, + AvmMemoryTag::FF, + AvmMemoryTag::U0); + bool tag_match = + point_x1_read.tag_match && point_y1_read.tag_match && point_x2_read.tag_match && point_y2_read.tag_match; + points_coords_vec.insert(points_coords_vec.end(), + { point_x1_read.val, point_y1_read.val, point_x2_read.val, point_y2_read.val }); + main_trace.push_back(Row{ + .main_clk = clk, + .main_ia = point_x1_read.val, + .main_ib = point_y1_read.val, + .main_ic = point_x2_read.val, + .main_id = point_y2_read.val, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_points_offset + i * 3), + .main_mem_addr_b = FF(direct_points_offset + i * 3 + 1), + .main_mem_addr_c = FF(direct_points_offset + (i + 1) * 3), + .main_mem_addr_d = FF(direct_points_offset + (i + 1) * 3 + 1), + .main_pc = FF(pc), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::FF)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_mem_op_d = FF(1), + .main_tag_err = FF(static_cast(!tag_match)), + }); + clk++; + } + // Read the Infinities flags, +4 since we read 4 points row + for (uint32_t i = 0; i < num_points; i += 4) { + // We can read up to 4 infinities per row + // Each infinity flag is separated by 3 memory addressess + uint32_t offset = direct_points_offset + i * 3 + 2; + auto point_inf1_read = mem_trace_builder.read_and_load_from_memory( + call_ptr, clk, IntermRegister::IA, offset, AvmMemoryTag::U8, AvmMemoryTag::U0); + offset += 3; + + auto point_inf2_read = mem_trace_builder.read_and_load_from_memory( + call_ptr, clk, IntermRegister::IB, offset, AvmMemoryTag::U8, AvmMemoryTag::U0); + offset += 3; + + auto point_inf3_read = mem_trace_builder.read_and_load_from_memory( + call_ptr, clk, IntermRegister::IC, offset, AvmMemoryTag::U8, AvmMemoryTag::U0); + offset += 3; + + auto point_inf4_read = mem_trace_builder.read_and_load_from_memory( + call_ptr, clk, IntermRegister::ID, offset, AvmMemoryTag::U8, AvmMemoryTag::U0); + + points_inf_vec.insert(points_inf_vec.end(), + { point_inf1_read.val, point_inf2_read.val, point_inf3_read.val, point_inf4_read.val }); + bool tag_match = point_inf1_read.tag_match && point_inf2_read.tag_match && point_inf3_read.tag_match && + point_inf4_read.tag_match; + main_trace.push_back(Row{ + .main_clk = clk, + .main_ia = point_inf1_read.val, + .main_ib = point_inf2_read.val, + .main_ic = point_inf3_read.val, + .main_id = point_inf4_read.val, + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_points_offset + i * 3 + 2), + .main_mem_addr_b = FF(direct_points_offset + (i + 1) * 3 + 2), + .main_mem_addr_c = FF(direct_points_offset + (i + 2) * 3 + 2), + .main_mem_addr_d = FF(direct_points_offset + (i + 3) * 3 + 2), + .main_pc = FF(pc), + .main_r_in_tag = FF(static_cast(AvmMemoryTag::U8)), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_mem_op_c = FF(1), + .main_sel_mem_op_d = FF(1), + .main_tag_err = FF(static_cast(!tag_match)), + }); + clk++; + } + // Scalar read length is num_points* 2 since scalars are stored as lo and hi limbs + uint32_t scalar_read_length = num_points * 2; + auto num_scalar_rows = read_slice_to_memory(call_ptr, + clk, + direct_scalars_offset, + AvmMemoryTag::FF, + AvmMemoryTag::U0, + FF(internal_return_ptr), + scalar_read_length, + scalars_vec); + clk += num_scalar_rows; + // Reconstruct Grumpkin points + std::vector points; + for (size_t i = 0; i < num_points; i++) { + grumpkin::g1::Fq x = points_coords_vec[i * 2]; + grumpkin::g1::Fq y = points_coords_vec[i * 2 + 1]; + bool is_inf = points_inf_vec[i] == 1; + if (is_inf) { + points.emplace_back(grumpkin::g1::affine_element::infinity()); + } else { + points.emplace_back(x, y); + } + } + // Reconstruct Grumpkin scalars + // Scalars are stored as [lo1, hi1, lo2, hi2, ...] with the types [FF, FF, FF, FF, ...] + std::vector scalars; + for (size_t i = 0; i < num_points; i++) { + FF lo = scalars_vec[i * 2]; + FF hi = scalars_vec[i * 2 + 1]; + // hi is shifted 128 bits + uint256_t scalar = (uint256_t(hi) << 128) + uint256_t(lo); + scalars.emplace_back(scalar); + } + // Perform the variable MSM - could just put the logic in here since there are no constraints. + auto result = ecc_trace_builder.variable_msm(points, scalars, clk); + // Write the result back to memory [x, y, inf] with tags [FF, FF, U8] + if (indirect_output_flag) { + auto read_ind_a = + mem_trace_builder.indirect_read_and_load_from_memory(call_ptr, clk, IndirectRegister::IND_A, output_offset); + direct_output_offset = uint32_t(read_ind_a.val); + } + mem_trace_builder.write_into_memory( + call_ptr, clk, IntermRegister::IA, direct_output_offset, result.x, AvmMemoryTag::U0, AvmMemoryTag::FF); + mem_trace_builder.write_into_memory( + call_ptr, clk, IntermRegister::IB, direct_output_offset + 1, result.y, AvmMemoryTag::U0, AvmMemoryTag::FF); + main_trace.push_back(Row{ + .main_clk = clk, + .main_ia = result.x, + .main_ib = result.y, + .main_ind_addr_a = indirect_output_flag ? FF(output_offset) : FF(0), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_output_offset), + .main_mem_addr_b = FF(direct_output_offset + 1), + .main_pc = FF(pc), + .main_rwa = FF(1), + .main_rwb = FF(1), + .main_sel_mem_op_a = FF(1), + .main_sel_mem_op_b = FF(1), + .main_sel_resolve_ind_addr_a = FF(static_cast(indirect_output_flag)), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::FF)), + }); + clk++; + // Write the infinity + mem_trace_builder.write_into_memory(call_ptr, + clk, + IntermRegister::IA, + direct_output_offset + 2, + result.is_point_at_infinity(), + AvmMemoryTag::U0, + AvmMemoryTag::U8); + main_trace.push_back(Row{ + .main_clk = clk, + .main_ia = static_cast(result.is_point_at_infinity()), + .main_internal_return_ptr = FF(internal_return_ptr), + .main_mem_addr_a = FF(direct_output_offset + 2), + .main_pc = FF(pc), + .main_rwa = FF(1), + .main_sel_mem_op_a = FF(1), + .main_w_in_tag = FF(static_cast(AvmMemoryTag::U8)), + }); +} // Finalise Lookup Counts // // For log derivative lookups, we require a column that contains the number of times each lookup is consumed @@ -3668,21 +3919,21 @@ uint32_t finalize_bin_trace_lookup_for_testing(std::vector& main_trace, Avm } if (clk > (main_trace.size() - 1)) { main_trace.push_back(Row{ - .avm_main_clk = FF(clk), - .avm_byte_lookup_bin_sel = FF(1), - .avm_byte_lookup_table_input_a = a, - .avm_byte_lookup_table_input_b = b, - .avm_byte_lookup_table_op_id = op_id, - .avm_byte_lookup_table_output = bit_op, + .main_clk = FF(clk), + .byte_lookup_sel_bin = FF(1), + .byte_lookup_table_input_a = a, + .byte_lookup_table_input_b = b, + .byte_lookup_table_op_id = op_id, + .byte_lookup_table_output = bit_op, .lookup_byte_operations_counts = count, }); } else { main_trace.at(clk).lookup_byte_operations_counts = count; - main_trace.at(clk).avm_byte_lookup_bin_sel = FF(1); - main_trace.at(clk).avm_byte_lookup_table_op_id = op_id; - main_trace.at(clk).avm_byte_lookup_table_input_a = a; - main_trace.at(clk).avm_byte_lookup_table_input_b = b; - main_trace.at(clk).avm_byte_lookup_table_output = bit_op; + main_trace.at(clk).byte_lookup_sel_bin = FF(1); + main_trace.at(clk).byte_lookup_table_op_id = op_id; + main_trace.at(clk).byte_lookup_table_input_a = a; + main_trace.at(clk).byte_lookup_table_input_b = b; + main_trace.at(clk).byte_lookup_table_output = bit_op; } // Add the counter value stored throughout the execution } @@ -3758,7 +4009,7 @@ uint32_t finalize_rng_chks_for_testing( auto old_size = main_trace.size(); for (auto const& clk : custom_clk) { if (clk >= old_size) { - main_trace.push_back(Row{ .avm_main_clk = FF(clk) }); + main_trace.push_back(Row{ .main_clk = FF(clk) }); } } @@ -3819,16 +4070,16 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c main_trace_size = *trace_size; main_trace.resize(*trace_size, {}); - main_trace.at(*trace_size - 1).avm_main_last = FF(1); + main_trace.at(*trace_size - 1).main_sel_last = FF(1); // Memory trace inclusion // We compute in the main loop the timestamp and global address for next row. // Perform initialization for index 0 outside of the loop provided that mem trace exists. if (mem_trace_size > 0) { - main_trace.at(0).avm_mem_tsp = + main_trace.at(0).mem_tsp = FF(AvmMemTraceBuilder::NUM_SUB_CLK * mem_trace.at(0).m_clk + mem_trace.at(0).m_sub_clk); - main_trace.at(0).avm_mem_glob_addr = + main_trace.at(0).mem_glob_addr = FF(mem_trace.at(0).m_addr + (static_cast(mem_trace.at(0).m_space_id) << 32)); } @@ -3836,92 +4087,92 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c auto const& src = mem_trace.at(i); auto& dest = main_trace.at(i); - dest.avm_mem_mem_sel = FF(1); - dest.avm_mem_clk = FF(src.m_clk); - dest.avm_mem_addr = FF(src.m_addr); - dest.avm_mem_space_id = FF(src.m_space_id); - dest.avm_mem_val = src.m_val; - dest.avm_mem_rw = FF(static_cast(src.m_rw)); - dest.avm_mem_r_in_tag = FF(static_cast(src.r_in_tag)); - dest.avm_mem_w_in_tag = FF(static_cast(src.w_in_tag)); - dest.avm_mem_tag = FF(static_cast(src.m_tag)); - dest.avm_mem_tag_err = FF(static_cast(src.m_tag_err)); - dest.avm_mem_one_min_inv = src.m_one_min_inv; - dest.avm_mem_sel_mov_a = FF(static_cast(src.m_sel_mov_a)); - dest.avm_mem_sel_mov_b = FF(static_cast(src.m_sel_mov_b)); - dest.avm_mem_sel_cmov = FF(static_cast(src.m_sel_cmov)); + dest.mem_sel_mem = FF(1); + dest.mem_clk = FF(src.m_clk); + dest.mem_addr = FF(src.m_addr); + dest.mem_space_id = FF(src.m_space_id); + dest.mem_val = src.m_val; + dest.mem_rw = FF(static_cast(src.m_rw)); + dest.mem_r_in_tag = FF(static_cast(src.r_in_tag)); + dest.mem_w_in_tag = FF(static_cast(src.w_in_tag)); + dest.mem_tag = FF(static_cast(src.m_tag)); + dest.mem_tag_err = FF(static_cast(src.m_tag_err)); + dest.mem_one_min_inv = src.m_one_min_inv; + dest.mem_sel_mov_ia_to_ic = FF(static_cast(src.m_sel_mov_ia_to_ic)); + dest.mem_sel_mov_ib_to_ic = FF(static_cast(src.m_sel_mov_ib_to_ic)); + dest.mem_sel_op_cmov = FF(static_cast(src.m_sel_cmov)); dest.incl_mem_tag_err_counts = FF(static_cast(src.m_tag_err_count_relevant)); switch (src.m_sub_clk) { case AvmMemTraceBuilder::SUB_CLK_LOAD_A: case AvmMemTraceBuilder::SUB_CLK_STORE_A: - dest.avm_mem_op_a = 1; + dest.mem_sel_op_a = 1; break; case AvmMemTraceBuilder::SUB_CLK_LOAD_B: case AvmMemTraceBuilder::SUB_CLK_STORE_B: - dest.avm_mem_op_b = 1; + dest.mem_sel_op_b = 1; break; case AvmMemTraceBuilder::SUB_CLK_LOAD_C: case AvmMemTraceBuilder::SUB_CLK_STORE_C: - dest.avm_mem_op_c = 1; + dest.mem_sel_op_c = 1; break; case AvmMemTraceBuilder::SUB_CLK_LOAD_D: case AvmMemTraceBuilder::SUB_CLK_STORE_D: - dest.avm_mem_op_d = 1; + dest.mem_sel_op_d = 1; break; case AvmMemTraceBuilder::SUB_CLK_IND_LOAD_A: - dest.avm_mem_ind_op_a = 1; + dest.mem_sel_resolve_ind_addr_a = 1; break; case AvmMemTraceBuilder::SUB_CLK_IND_LOAD_B: - dest.avm_mem_ind_op_b = 1; + dest.mem_sel_resolve_ind_addr_b = 1; break; case AvmMemTraceBuilder::SUB_CLK_IND_LOAD_C: - dest.avm_mem_ind_op_c = 1; + dest.mem_sel_resolve_ind_addr_c = 1; break; case AvmMemTraceBuilder::SUB_CLK_IND_LOAD_D: - dest.avm_mem_ind_op_d = 1; + dest.mem_sel_resolve_ind_addr_d = 1; break; default: break; } if (src.m_sel_cmov) { - dest.avm_mem_skip_check_tag = dest.avm_mem_op_d + dest.avm_mem_op_a * (-dest.avm_mem_sel_mov_a + 1) + - dest.avm_mem_op_b * (-dest.avm_mem_sel_mov_b + 1); + dest.mem_skip_check_tag = dest.mem_sel_op_d + dest.mem_sel_op_a * (-dest.mem_sel_mov_ia_to_ic + 1) + + dest.mem_sel_op_b * (-dest.mem_sel_mov_ib_to_ic + 1); } if (i + 1 < mem_trace_size) { auto const& next = mem_trace.at(i + 1); auto& dest_next = main_trace.at(i + 1); - dest_next.avm_mem_tsp = FF(AvmMemTraceBuilder::NUM_SUB_CLK * next.m_clk + next.m_sub_clk); - dest_next.avm_mem_glob_addr = FF(next.m_addr + (static_cast(next.m_space_id) << 32)); + dest_next.mem_tsp = FF(AvmMemTraceBuilder::NUM_SUB_CLK * next.m_clk + next.m_sub_clk); + dest_next.mem_glob_addr = FF(next.m_addr + (static_cast(next.m_space_id) << 32)); FF diff{}; - if (dest_next.avm_mem_glob_addr == dest.avm_mem_glob_addr) { - diff = dest_next.avm_mem_tsp - dest.avm_mem_tsp; + if (dest_next.mem_glob_addr == dest.mem_glob_addr) { + diff = dest_next.mem_tsp - dest.mem_tsp; } else { - diff = dest_next.avm_mem_glob_addr - dest.avm_mem_glob_addr; - dest.avm_mem_lastAccess = FF(1); + diff = dest_next.mem_glob_addr - dest.mem_glob_addr; + dest.mem_lastAccess = FF(1); } - dest.avm_mem_rng_chk_sel = FF(1); + dest.mem_sel_rng_chk = FF(1); // Decomposition of diff auto const diff_64 = uint64_t(diff); auto const diff_hi = static_cast(diff_64 >> 32); auto const diff_mid = static_cast((diff_64 & UINT32_MAX) >> 16); auto const diff_lo = static_cast(diff_64 & UINT16_MAX); - dest.avm_mem_diff_hi = FF(diff_hi); - dest.avm_mem_diff_mid = FF(diff_mid); - dest.avm_mem_diff_lo = FF(diff_lo); + dest.mem_diff_hi = FF(diff_hi); + dest.mem_diff_mid = FF(diff_mid); + dest.mem_diff_lo = FF(diff_lo); // Add the range checks counts mem_rng_check_hi_counts[diff_hi]++; mem_rng_check_mid_counts[diff_mid]++; mem_rng_check_lo_counts[diff_lo]++; } else { - dest.avm_mem_lastAccess = FF(1); - dest.avm_mem_last = FF(1); + dest.mem_lastAccess = FF(1); + dest.mem_last = FF(1); } } @@ -3930,146 +4181,145 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c auto const& src = alu_trace.at(i); auto& dest = main_trace.at(i); - dest.avm_alu_clk = FF(static_cast(src.alu_clk)); - - dest.avm_alu_op_add = FF(static_cast(src.alu_op_add)); - dest.avm_alu_op_sub = FF(static_cast(src.alu_op_sub)); - dest.avm_alu_op_mul = FF(static_cast(src.alu_op_mul)); - dest.avm_alu_op_not = FF(static_cast(src.alu_op_not)); - dest.avm_alu_op_eq = FF(static_cast(src.alu_op_eq)); - dest.avm_alu_op_lt = FF(static_cast(src.alu_op_lt)); - dest.avm_alu_op_lte = FF(static_cast(src.alu_op_lte)); - dest.avm_alu_op_cast = FF(static_cast(src.alu_op_cast)); - dest.avm_alu_op_cast_prev = FF(static_cast(src.alu_op_cast_prev)); - dest.avm_alu_cmp_sel = FF(static_cast(src.alu_op_lt) + static_cast(src.alu_op_lte)); - dest.avm_alu_rng_chk_sel = FF(static_cast(src.rng_chk_sel)); - dest.avm_alu_op_shr = FF(static_cast(src.alu_op_shr)); - dest.avm_alu_op_shl = FF(static_cast(src.alu_op_shl)); - dest.avm_alu_op_div = FF(static_cast(src.alu_op_div)); - - dest.avm_alu_ff_tag = FF(static_cast(src.alu_ff_tag)); - dest.avm_alu_u8_tag = FF(static_cast(src.alu_u8_tag)); - dest.avm_alu_u16_tag = FF(static_cast(src.alu_u16_tag)); - dest.avm_alu_u32_tag = FF(static_cast(src.alu_u32_tag)); - dest.avm_alu_u64_tag = FF(static_cast(src.alu_u64_tag)); - dest.avm_alu_u128_tag = FF(static_cast(src.alu_u128_tag)); - - dest.avm_alu_in_tag = dest.avm_alu_u8_tag + FF(2) * dest.avm_alu_u16_tag + FF(3) * dest.avm_alu_u32_tag + - FF(4) * dest.avm_alu_u64_tag + FF(5) * dest.avm_alu_u128_tag + - FF(6) * dest.avm_alu_ff_tag; - - dest.avm_alu_ia = src.alu_ia; - dest.avm_alu_ib = src.alu_ib; - dest.avm_alu_ic = src.alu_ic; - - dest.avm_alu_cf = FF(static_cast(src.alu_cf)); - - dest.avm_alu_u8_r0 = FF(src.alu_u8_r0); - dest.avm_alu_u8_r1 = FF(src.alu_u8_r1); - - dest.avm_alu_u16_r0 = FF(src.alu_u16_reg.at(0)); - dest.avm_alu_u16_r1 = FF(src.alu_u16_reg.at(1)); - dest.avm_alu_u16_r2 = FF(src.alu_u16_reg.at(2)); - dest.avm_alu_u16_r3 = FF(src.alu_u16_reg.at(3)); - dest.avm_alu_u16_r4 = FF(src.alu_u16_reg.at(4)); - dest.avm_alu_u16_r5 = FF(src.alu_u16_reg.at(5)); - dest.avm_alu_u16_r6 = FF(src.alu_u16_reg.at(6)); - dest.avm_alu_u16_r7 = FF(src.alu_u16_reg.at(7)); - dest.avm_alu_u16_r8 = FF(src.alu_u16_reg.at(8)); - dest.avm_alu_u16_r9 = FF(src.alu_u16_reg.at(9)); - dest.avm_alu_u16_r10 = FF(src.alu_u16_reg.at(10)); - dest.avm_alu_u16_r11 = FF(src.alu_u16_reg.at(11)); - dest.avm_alu_u16_r12 = FF(src.alu_u16_reg.at(12)); - dest.avm_alu_u16_r13 = FF(src.alu_u16_reg.at(13)); - dest.avm_alu_u16_r14 = FF(src.alu_u16_reg.at(14)); - - dest.avm_alu_div_rng_chk_selector = FF(static_cast(src.div_u64_range_chk_sel)); - dest.avm_alu_div_u16_r0 = FF(src.div_u64_range_chk.at(0)); - dest.avm_alu_div_u16_r1 = FF(src.div_u64_range_chk.at(1)); - dest.avm_alu_div_u16_r2 = FF(src.div_u64_range_chk.at(2)); - dest.avm_alu_div_u16_r3 = FF(src.div_u64_range_chk.at(3)); - dest.avm_alu_div_u16_r4 = FF(src.div_u64_range_chk.at(4)); - dest.avm_alu_div_u16_r5 = FF(src.div_u64_range_chk.at(5)); - dest.avm_alu_div_u16_r6 = FF(src.div_u64_range_chk.at(6)); - dest.avm_alu_div_u16_r7 = FF(src.div_u64_range_chk.at(7)); - dest.avm_alu_op_eq_diff_inv = FF(src.alu_op_eq_diff_inv); + dest.alu_clk = FF(static_cast(src.alu_clk)); + + dest.alu_op_add = FF(static_cast(src.alu_op_add)); + dest.alu_op_sub = FF(static_cast(src.alu_op_sub)); + dest.alu_op_mul = FF(static_cast(src.alu_op_mul)); + dest.alu_op_not = FF(static_cast(src.alu_op_not)); + dest.alu_op_eq = FF(static_cast(src.alu_op_eq)); + dest.alu_op_lt = FF(static_cast(src.alu_op_lt)); + dest.alu_op_lte = FF(static_cast(src.alu_op_lte)); + dest.alu_op_cast = FF(static_cast(src.alu_op_cast)); + dest.alu_op_cast_prev = FF(static_cast(src.alu_op_cast_prev)); + dest.alu_sel_cmp = FF(static_cast(src.alu_op_lt) + static_cast(src.alu_op_lte)); + dest.alu_sel_rng_chk = FF(static_cast(src.rng_chk_sel)); + dest.alu_op_shr = FF(static_cast(src.alu_op_shr)); + dest.alu_op_shl = FF(static_cast(src.alu_op_shl)); + dest.alu_op_div = FF(static_cast(src.alu_op_div)); + + dest.alu_ff_tag = FF(static_cast(src.alu_ff_tag)); + dest.alu_u8_tag = FF(static_cast(src.alu_u8_tag)); + dest.alu_u16_tag = FF(static_cast(src.alu_u16_tag)); + dest.alu_u32_tag = FF(static_cast(src.alu_u32_tag)); + dest.alu_u64_tag = FF(static_cast(src.alu_u64_tag)); + dest.alu_u128_tag = FF(static_cast(src.alu_u128_tag)); + + dest.alu_in_tag = dest.alu_u8_tag + FF(2) * dest.alu_u16_tag + FF(3) * dest.alu_u32_tag + + FF(4) * dest.alu_u64_tag + FF(5) * dest.alu_u128_tag + FF(6) * dest.alu_ff_tag; + + dest.alu_ia = src.alu_ia; + dest.alu_ib = src.alu_ib; + dest.alu_ic = src.alu_ic; + + dest.alu_cf = FF(static_cast(src.alu_cf)); + + dest.alu_u8_r0 = FF(src.alu_u8_r0); + dest.alu_u8_r1 = FF(src.alu_u8_r1); + + dest.alu_u16_r0 = FF(src.alu_u16_reg.at(0)); + dest.alu_u16_r1 = FF(src.alu_u16_reg.at(1)); + dest.alu_u16_r2 = FF(src.alu_u16_reg.at(2)); + dest.alu_u16_r3 = FF(src.alu_u16_reg.at(3)); + dest.alu_u16_r4 = FF(src.alu_u16_reg.at(4)); + dest.alu_u16_r5 = FF(src.alu_u16_reg.at(5)); + dest.alu_u16_r6 = FF(src.alu_u16_reg.at(6)); + dest.alu_u16_r7 = FF(src.alu_u16_reg.at(7)); + dest.alu_u16_r8 = FF(src.alu_u16_reg.at(8)); + dest.alu_u16_r9 = FF(src.alu_u16_reg.at(9)); + dest.alu_u16_r10 = FF(src.alu_u16_reg.at(10)); + dest.alu_u16_r11 = FF(src.alu_u16_reg.at(11)); + dest.alu_u16_r12 = FF(src.alu_u16_reg.at(12)); + dest.alu_u16_r13 = FF(src.alu_u16_reg.at(13)); + dest.alu_u16_r14 = FF(src.alu_u16_reg.at(14)); + + dest.alu_sel_div_rng_chk = FF(static_cast(src.div_u64_range_chk_sel)); + dest.alu_div_u16_r0 = FF(src.div_u64_range_chk.at(0)); + dest.alu_div_u16_r1 = FF(src.div_u64_range_chk.at(1)); + dest.alu_div_u16_r2 = FF(src.div_u64_range_chk.at(2)); + dest.alu_div_u16_r3 = FF(src.div_u64_range_chk.at(3)); + dest.alu_div_u16_r4 = FF(src.div_u64_range_chk.at(4)); + dest.alu_div_u16_r5 = FF(src.div_u64_range_chk.at(5)); + dest.alu_div_u16_r6 = FF(src.div_u64_range_chk.at(6)); + dest.alu_div_u16_r7 = FF(src.div_u64_range_chk.at(7)); + dest.alu_op_eq_diff_inv = FF(src.alu_op_eq_diff_inv); // Not all rows in ALU are enabled with a selector. For instance, // multiplication over u128 and cast is taking two lines. if (AvmAluTraceBuilder::is_alu_row_enabled(src)) { - dest.avm_alu_alu_sel = FF(1); + dest.alu_sel_alu = FF(1); } - if (dest.avm_alu_cmp_sel == FF(1) || dest.avm_alu_rng_chk_sel == FF(1)) { - dest.avm_alu_a_lo = FF(src.hi_lo_limbs.at(0)); - dest.avm_alu_a_hi = FF(src.hi_lo_limbs.at(1)); - dest.avm_alu_b_lo = FF(src.hi_lo_limbs.at(2)); - dest.avm_alu_b_hi = FF(src.hi_lo_limbs.at(3)); - dest.avm_alu_p_sub_a_lo = FF(src.hi_lo_limbs.at(4)); - dest.avm_alu_p_sub_a_hi = FF(src.hi_lo_limbs.at(5)); - dest.avm_alu_p_sub_b_lo = FF(src.hi_lo_limbs.at(6)); - dest.avm_alu_p_sub_b_hi = FF(src.hi_lo_limbs.at(7)); - dest.avm_alu_res_lo = FF(src.hi_lo_limbs.at(8)); - dest.avm_alu_res_hi = FF(src.hi_lo_limbs.at(9)); - dest.avm_alu_p_a_borrow = FF(static_cast(src.p_a_borrow)); - dest.avm_alu_p_b_borrow = FF(static_cast(src.p_b_borrow)); - dest.avm_alu_borrow = FF(static_cast(src.borrow)); - dest.avm_alu_cmp_rng_ctr = FF(static_cast(src.cmp_rng_ctr)); - dest.avm_alu_rng_chk_lookup_selector = FF(1); + if (dest.alu_sel_cmp == FF(1) || dest.alu_sel_rng_chk == FF(1)) { + dest.alu_a_lo = FF(src.hi_lo_limbs.at(0)); + dest.alu_a_hi = FF(src.hi_lo_limbs.at(1)); + dest.alu_b_lo = FF(src.hi_lo_limbs.at(2)); + dest.alu_b_hi = FF(src.hi_lo_limbs.at(3)); + dest.alu_p_sub_a_lo = FF(src.hi_lo_limbs.at(4)); + dest.alu_p_sub_a_hi = FF(src.hi_lo_limbs.at(5)); + dest.alu_p_sub_b_lo = FF(src.hi_lo_limbs.at(6)); + dest.alu_p_sub_b_hi = FF(src.hi_lo_limbs.at(7)); + dest.alu_res_lo = FF(src.hi_lo_limbs.at(8)); + dest.alu_res_hi = FF(src.hi_lo_limbs.at(9)); + dest.alu_p_a_borrow = FF(static_cast(src.p_a_borrow)); + dest.alu_p_b_borrow = FF(static_cast(src.p_b_borrow)); + dest.alu_borrow = FF(static_cast(src.borrow)); + dest.alu_cmp_rng_ctr = FF(static_cast(src.cmp_rng_ctr)); + dest.alu_sel_rng_chk_lookup = FF(1); } - if (dest.avm_alu_op_div == FF(1)) { - dest.avm_alu_op_div_std = uint256_t(src.alu_ia) >= uint256_t(src.alu_ib); - dest.avm_alu_op_div_a_lt_b = uint256_t(src.alu_ia) < uint256_t(src.alu_ib); - dest.avm_alu_rng_chk_lookup_selector = FF(1); - dest.avm_alu_a_lo = FF(src.hi_lo_limbs.at(0)); - dest.avm_alu_a_hi = FF(src.hi_lo_limbs.at(1)); - dest.avm_alu_b_lo = FF(src.hi_lo_limbs.at(2)); - dest.avm_alu_b_hi = FF(src.hi_lo_limbs.at(3)); - dest.avm_alu_p_sub_a_lo = FF(src.hi_lo_limbs.at(4)); - dest.avm_alu_p_sub_a_hi = FF(src.hi_lo_limbs.at(5)); - dest.avm_alu_remainder = src.remainder; - dest.avm_alu_divisor_lo = src.divisor_lo; - dest.avm_alu_divisor_hi = src.divisor_hi; - dest.avm_alu_quotient_lo = src.quotient_lo; - dest.avm_alu_quotient_hi = src.quotient_hi; - dest.avm_alu_partial_prod_lo = src.partial_prod_lo; - dest.avm_alu_partial_prod_hi = src.partial_prod_hi; + if (dest.alu_op_div == FF(1)) { + dest.alu_op_div_std = uint256_t(src.alu_ia) >= uint256_t(src.alu_ib); + dest.alu_op_div_a_lt_b = uint256_t(src.alu_ia) < uint256_t(src.alu_ib); + dest.alu_sel_rng_chk_lookup = FF(1); + dest.alu_a_lo = FF(src.hi_lo_limbs.at(0)); + dest.alu_a_hi = FF(src.hi_lo_limbs.at(1)); + dest.alu_b_lo = FF(src.hi_lo_limbs.at(2)); + dest.alu_b_hi = FF(src.hi_lo_limbs.at(3)); + dest.alu_p_sub_a_lo = FF(src.hi_lo_limbs.at(4)); + dest.alu_p_sub_a_hi = FF(src.hi_lo_limbs.at(5)); + dest.alu_remainder = src.remainder; + dest.alu_divisor_lo = src.divisor_lo; + dest.alu_divisor_hi = src.divisor_hi; + dest.alu_quotient_lo = src.quotient_lo; + dest.alu_quotient_hi = src.quotient_hi; + dest.alu_partial_prod_lo = src.partial_prod_lo; + dest.alu_partial_prod_hi = src.partial_prod_hi; } - if (dest.avm_alu_op_add == FF(1) || dest.avm_alu_op_sub == FF(1) || dest.avm_alu_op_mul == FF(1)) { - dest.avm_alu_rng_chk_lookup_selector = FF(1); + if (dest.alu_op_add == FF(1) || dest.alu_op_sub == FF(1) || dest.alu_op_mul == FF(1)) { + dest.alu_sel_rng_chk_lookup = FF(1); } - if (dest.avm_alu_op_cast == FF(1)) { - dest.avm_alu_a_lo = FF(src.hi_lo_limbs.at(0)); - dest.avm_alu_a_hi = FF(src.hi_lo_limbs.at(1)); - dest.avm_alu_p_sub_a_lo = FF(src.hi_lo_limbs.at(2)); - dest.avm_alu_p_sub_a_hi = FF(src.hi_lo_limbs.at(3)); - dest.avm_alu_p_a_borrow = FF(static_cast(src.p_a_borrow)); - dest.avm_alu_rng_chk_lookup_selector = FF(1); + if (dest.alu_op_cast == FF(1)) { + dest.alu_a_lo = FF(src.hi_lo_limbs.at(0)); + dest.alu_a_hi = FF(src.hi_lo_limbs.at(1)); + dest.alu_p_sub_a_lo = FF(src.hi_lo_limbs.at(2)); + dest.alu_p_sub_a_hi = FF(src.hi_lo_limbs.at(3)); + dest.alu_p_a_borrow = FF(static_cast(src.p_a_borrow)); + dest.alu_sel_rng_chk_lookup = FF(1); } - if (dest.avm_alu_op_cast_prev == FF(1)) { - dest.avm_alu_a_lo = FF(src.hi_lo_limbs.at(0)); - dest.avm_alu_a_hi = FF(src.hi_lo_limbs.at(1)); - dest.avm_alu_rng_chk_lookup_selector = FF(1); + if (dest.alu_op_cast_prev == FF(1)) { + dest.alu_a_lo = FF(src.hi_lo_limbs.at(0)); + dest.alu_a_hi = FF(src.hi_lo_limbs.at(1)); + dest.alu_sel_rng_chk_lookup = FF(1); } // Multiplication over u128 expands over two rows. - if (dest.avm_alu_op_mul == FF(1) && dest.avm_alu_u128_tag) { - main_trace.at(i + 1).avm_alu_rng_chk_lookup_selector = FF(1); + if (dest.alu_op_mul == FF(1) && dest.alu_u128_tag) { + main_trace.at(i + 1).alu_sel_rng_chk_lookup = FF(1); } if (src.alu_op_shr || src.alu_op_shl) { - dest.avm_alu_a_lo = FF(src.hi_lo_limbs[0]); - dest.avm_alu_a_hi = FF(src.hi_lo_limbs[1]); - dest.avm_alu_b_lo = FF(src.hi_lo_limbs[2]); - dest.avm_alu_b_hi = FF(src.hi_lo_limbs[3]); - dest.avm_alu_shift_sel = FF(1); - dest.avm_alu_shift_lt_bit_len = FF(static_cast(src.shift_lt_bit_len)); - dest.avm_alu_t_sub_s_bits = FF(src.mem_tag_sub_shift); - dest.avm_alu_two_pow_s = FF(uint256_t(1) << dest.avm_alu_ib); - dest.avm_alu_two_pow_t_sub_s = FF(uint256_t(1) << uint256_t(dest.avm_alu_t_sub_s_bits)); - dest.avm_alu_rng_chk_lookup_selector = FF(1); + dest.alu_a_lo = FF(src.hi_lo_limbs[0]); + dest.alu_a_hi = FF(src.hi_lo_limbs[1]); + dest.alu_b_lo = FF(src.hi_lo_limbs[2]); + dest.alu_b_hi = FF(src.hi_lo_limbs[3]); + dest.alu_sel_shift_which = FF(1); + dest.alu_shift_lt_bit_len = FF(static_cast(src.shift_lt_bit_len)); + dest.alu_t_sub_s_bits = FF(src.mem_tag_sub_shift); + dest.alu_two_pow_s = FF(uint256_t(1) << dest.alu_ib); + dest.alu_two_pow_t_sub_s = FF(uint256_t(1) << uint256_t(dest.alu_t_sub_s_bits)); + dest.alu_sel_rng_chk_lookup = FF(1); } } @@ -4077,73 +4327,73 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c for (size_t i = 0; i < conv_trace_size; i++) { auto const& src = conv_trace.at(i); auto& dest = main_trace.at(i); - dest.avm_conversion_to_radix_le_sel = FF(static_cast(src.to_radix_le_sel)); - dest.avm_conversion_clk = FF(src.conversion_clk); - dest.avm_conversion_input = src.input; - dest.avm_conversion_radix = FF(src.radix); - dest.avm_conversion_num_limbs = FF(src.num_limbs); + dest.conversion_sel_to_radix_le = FF(static_cast(src.to_radix_le_sel)); + dest.conversion_clk = FF(src.conversion_clk); + dest.conversion_input = src.input; + dest.conversion_radix = FF(src.radix); + dest.conversion_num_limbs = FF(src.num_limbs); } // Add SHA256 Gadget table for (size_t i = 0; i < sha256_trace_size; i++) { auto const& src = sha256_trace.at(i); auto& dest = main_trace.at(i); - dest.avm_sha256_clk = FF(src.clk); - dest.avm_sha256_input = src.input[0]; + dest.sha256_clk = FF(src.clk); + dest.sha256_input = src.input[0]; // TODO: This will need to be enabled later - // dest.avm_sha256_output = src.output[0]; - dest.avm_sha256_sha256_compression_sel = FF(1); - dest.avm_sha256_state = src.state[0]; + // dest.sha256_output = src.output[0]; + dest.sha256_sel_sha256_compression = FF(1); + dest.sha256_state = src.state[0]; } // Add Poseidon2 Gadget table for (size_t i = 0; i < poseidon2_trace_size; i++) { auto const& src = poseidon2_trace.at(i); auto& dest = main_trace.at(i); - dest.avm_poseidon2_clk = FF(src.clk); - dest.avm_poseidon2_input = src.input[0]; + dest.poseidon2_clk = FF(src.clk); + dest.poseidon2_input = src.input[0]; // TODO: This will need to be enabled later - // dest.avm_poseidon2_output = src.output[0]; - dest.avm_poseidon2_poseidon_perm_sel = FF(1); + // dest.poseidon2_output = src.output[0]; + dest.poseidon2_sel_poseidon_perm = FF(1); } // Add KeccakF1600 Gadget table for (size_t i = 0; i < keccak_trace_size; i++) { auto const& src = keccak_trace.at(i); auto& dest = main_trace.at(i); - dest.avm_keccakf1600_clk = FF(src.clk); - dest.avm_keccakf1600_input = FF(src.input[0]); + dest.keccakf1600_clk = FF(src.clk); + dest.keccakf1600_input = FF(src.input[0]); // TODO: This will need to be enabled later - // dest.avm_keccakf1600_output = src.output[0]; - dest.avm_keccakf1600_keccakf1600_sel = FF(1); + // dest.keccakf1600_output = src.output[0]; + dest.keccakf1600_sel_keccakf1600 = FF(1); } // Add Pedersen Gadget table for (size_t i = 0; i < pedersen_trace_size; i++) { auto const& src = pedersen_trace.at(i); auto& dest = main_trace.at(i); - dest.avm_pedersen_clk = FF(src.clk); - dest.avm_pedersen_input = FF(src.input[0]); - dest.avm_pedersen_pedersen_sel = FF(1); + dest.pedersen_clk = FF(src.clk); + dest.pedersen_input = FF(src.input[0]); + dest.pedersen_sel_pedersen = FF(1); } // Add Binary Trace table for (size_t i = 0; i < bin_trace_size; i++) { auto const& src = bin_trace.at(i); auto& dest = main_trace.at(i); - dest.avm_binary_clk = src.binary_clk; - dest.avm_binary_bin_sel = static_cast(src.bin_sel); - dest.avm_binary_acc_ia = src.acc_ia; - dest.avm_binary_acc_ib = src.acc_ib; - dest.avm_binary_acc_ic = src.acc_ic; - dest.avm_binary_in_tag = src.in_tag; - dest.avm_binary_op_id = src.op_id; - dest.avm_binary_ia_bytes = src.bin_ia_bytes; - dest.avm_binary_ib_bytes = src.bin_ib_bytes; - dest.avm_binary_ic_bytes = src.bin_ic_bytes; - dest.avm_binary_start = FF(static_cast(src.start)); - dest.avm_binary_mem_tag_ctr = src.mem_tag_ctr; - dest.avm_binary_mem_tag_ctr_inv = src.mem_tag_ctr_inv; + dest.binary_clk = src.binary_clk; + dest.binary_sel_bin = static_cast(src.bin_sel); + dest.binary_acc_ia = src.acc_ia; + dest.binary_acc_ib = src.acc_ib; + dest.binary_acc_ic = src.acc_ic; + dest.binary_in_tag = src.in_tag; + dest.binary_op_id = src.op_id; + dest.binary_ia_bytes = src.bin_ia_bytes; + dest.binary_ib_bytes = src.bin_ib_bytes; + dest.binary_ic_bytes = src.bin_ic_bytes; + dest.binary_start = FF(static_cast(src.start)); + dest.binary_mem_tag_ctr = src.mem_tag_ctr; + dest.binary_mem_tag_ctr_inv = src.mem_tag_ctr_inv; } // Only generate precomputed byte tables if we are actually going to use them in this main trace. @@ -4161,19 +4411,19 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c // Derive a unique row index given op_id, a, and b. auto main_trace_index = (op_id << 16) + (input_a << 8) + b; - main_trace.at(main_trace_index).avm_byte_lookup_bin_sel = FF(1); - main_trace.at(main_trace_index).avm_byte_lookup_table_op_id = op_id; - main_trace.at(main_trace_index).avm_byte_lookup_table_input_a = a; - main_trace.at(main_trace_index).avm_byte_lookup_table_input_b = b; + main_trace.at(main_trace_index).byte_lookup_sel_bin = FF(1); + main_trace.at(main_trace_index).byte_lookup_table_op_id = op_id; + main_trace.at(main_trace_index).byte_lookup_table_input_a = a; + main_trace.at(main_trace_index).byte_lookup_table_input_b = b; // Add the counter value stored throughout the execution main_trace.at(main_trace_index).lookup_byte_operations_counts = bin_trace_builder.byte_operation_counter[main_trace_index]; if (op_id == 0) { - main_trace.at(main_trace_index).avm_byte_lookup_table_output = a & b; + main_trace.at(main_trace_index).byte_lookup_table_output = a & b; } else if (op_id == 1) { - main_trace.at(main_trace_index).avm_byte_lookup_table_output = a | b; + main_trace.at(main_trace_index).byte_lookup_table_output = a | b; } else { - main_trace.at(main_trace_index).avm_byte_lookup_table_output = a ^ b; + main_trace.at(main_trace_index).byte_lookup_table_output = a ^ b; } } } @@ -4184,9 +4434,9 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c for (uint8_t avm_in_tag = 0; avm_in_tag < 5; avm_in_tag++) { // The +1 here is because the instruction tags we care about (i.e excl U0 and FF) has the range // [1,5] - main_trace.at(avm_in_tag).avm_byte_lookup_bin_sel = FF(1); - main_trace.at(avm_in_tag).avm_byte_lookup_table_in_tags = avm_in_tag + 1; - main_trace.at(avm_in_tag).avm_byte_lookup_table_byte_lengths = static_cast(pow(2, avm_in_tag)); + main_trace.at(avm_in_tag).byte_lookup_sel_bin = FF(1); + main_trace.at(avm_in_tag).byte_lookup_table_in_tags = avm_in_tag + 1; + main_trace.at(avm_in_tag).byte_lookup_table_byte_lengths = static_cast(pow(2, avm_in_tag)); main_trace.at(avm_in_tag).lookup_byte_lengths_counts = bin_trace_builder.byte_length_counter[avm_in_tag + 1]; } @@ -4201,12 +4451,12 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c // Add the gas accounting for each row // We can assume that the gas trace will never be larger than the main trace - // We infer that a row is active for gas (.avm_main_gas_cost_active = 1) based on the presence + // We infer that a row is active for gas (.main_gas_cost_active = 1) based on the presence // of a gas entry row. // Set the initial gas auto& first_opcode_row = main_trace.at(0); - first_opcode_row.avm_main_l2_gas_remaining = gas_trace_builder.initial_l2_gas; - first_opcode_row.avm_main_da_gas_remaining = gas_trace_builder.initial_da_gas; + first_opcode_row.main_l2_gas_remaining = gas_trace_builder.initial_l2_gas; + first_opcode_row.main_da_gas_remaining = gas_trace_builder.initial_da_gas; uint32_t current_clk = 1; uint32_t current_l2_gas_remaining = gas_trace_builder.initial_l2_gas; uint32_t current_da_gas_remaining = gas_trace_builder.initial_da_gas; @@ -4226,8 +4476,8 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c // Remaining gas values remain unchanged. while (gas_entry.clk > current_clk) { auto& next = main_trace.at(current_clk); - next.avm_main_l2_gas_remaining = current_l2_gas_remaining; - next.avm_main_da_gas_remaining = current_da_gas_remaining; + next.main_l2_gas_remaining = current_l2_gas_remaining; + next.main_da_gas_remaining = current_da_gas_remaining; current_clk++; } @@ -4235,9 +4485,9 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c auto& next = main_trace.at(gas_entry.clk); // Write each of the relevant gas accounting values - dest.avm_main_opcode_val = static_cast(gas_entry.opcode); - dest.avm_main_l2_gas_op = gas_entry.l2_gas_cost; - dest.avm_main_da_gas_op = gas_entry.da_gas_cost; + dest.main_opcode_val = static_cast(gas_entry.opcode); + dest.main_l2_gas_op_cost = gas_entry.l2_gas_cost; + dest.main_da_gas_op_cost = gas_entry.da_gas_cost; // If gas remaining is increasing, it means we underflowed in uint32_t bool l2_out_of_gas = current_l2_gas_remaining < gas_entry.remaining_l2_gas; @@ -4246,30 +4496,30 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c uint32_t abs_l2_gas_remaining = l2_out_of_gas ? -gas_entry.remaining_l2_gas : gas_entry.remaining_l2_gas; uint32_t abs_da_gas_remaining = da_out_of_gas ? -gas_entry.remaining_da_gas : gas_entry.remaining_da_gas; - dest.avm_main_abs_l2_rem_gas_hi = abs_l2_gas_remaining >> 16; - dest.avm_main_abs_da_rem_gas_hi = abs_da_gas_remaining >> 16; - dest.avm_main_abs_l2_rem_gas_lo = static_cast(abs_l2_gas_remaining); - dest.avm_main_abs_da_rem_gas_lo = static_cast(abs_da_gas_remaining); + dest.main_abs_l2_rem_gas_hi = abs_l2_gas_remaining >> 16; + dest.main_abs_da_rem_gas_hi = abs_da_gas_remaining >> 16; + dest.main_abs_l2_rem_gas_lo = static_cast(abs_l2_gas_remaining); + dest.main_abs_da_rem_gas_lo = static_cast(abs_da_gas_remaining); // TODO: gas is not constrained for external call at this time if (gas_entry.opcode != OpCode::CALL) { - dest.avm_main_gas_cost_active = FF(1); + dest.main_sel_gas_accounting_active = FF(1); // lookups counting - rem_gas_rng_check_counts[L2_HI_GAS_COUNTS_IDX][static_cast(dest.avm_main_abs_l2_rem_gas_hi)]++; - rem_gas_rng_check_counts[L2_LO_GAS_COUNTS_IDX][static_cast(dest.avm_main_abs_l2_rem_gas_lo)]++; - rem_gas_rng_check_counts[DA_HI_GAS_COUNTS_IDX][static_cast(dest.avm_main_abs_da_rem_gas_hi)]++; - rem_gas_rng_check_counts[DA_LO_GAS_COUNTS_IDX][static_cast(dest.avm_main_abs_da_rem_gas_lo)]++; + rem_gas_rng_check_counts[L2_HI_GAS_COUNTS_IDX][static_cast(dest.main_abs_l2_rem_gas_hi)]++; + rem_gas_rng_check_counts[L2_LO_GAS_COUNTS_IDX][static_cast(dest.main_abs_l2_rem_gas_lo)]++; + rem_gas_rng_check_counts[DA_HI_GAS_COUNTS_IDX][static_cast(dest.main_abs_da_rem_gas_hi)]++; + rem_gas_rng_check_counts[DA_LO_GAS_COUNTS_IDX][static_cast(dest.main_abs_da_rem_gas_lo)]++; } - dest.avm_main_l2_out_of_gas = static_cast(l2_out_of_gas); - dest.avm_main_da_out_of_gas = static_cast(da_out_of_gas); + dest.main_l2_out_of_gas = static_cast(l2_out_of_gas); + dest.main_da_out_of_gas = static_cast(da_out_of_gas); current_l2_gas_remaining = gas_entry.remaining_l2_gas; current_da_gas_remaining = gas_entry.remaining_da_gas; - next.avm_main_l2_gas_remaining = + next.main_l2_gas_remaining = l2_out_of_gas ? FF::modulus - uint256_t(abs_l2_gas_remaining) : current_l2_gas_remaining; - next.avm_main_da_gas_remaining = + next.main_da_gas_remaining = da_out_of_gas ? FF::modulus - uint256_t(abs_da_gas_remaining) : current_da_gas_remaining; current_clk++; @@ -4278,14 +4528,14 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c // Pad the rest of the trace with the same gas remaining for (size_t i = current_clk; i < main_trace_size; i++) { auto& dest = main_trace.at(i); - dest.avm_main_l2_gas_remaining = current_l2_gas_remaining; - dest.avm_main_da_gas_remaining = current_da_gas_remaining; + dest.main_l2_gas_remaining = current_l2_gas_remaining; + dest.main_da_gas_remaining = current_da_gas_remaining; } /////////// END OF GAS ACCOUNTING ////////////////////////// // Adding extra row for the shifted values at the top of the execution trace. - Row first_row = Row{ .avm_main_first = FF(1), .avm_mem_lastAccess = FF(1) }; + Row first_row = Row{ .main_sel_first = FF(1), .mem_lastAccess = FF(1) }; main_trace.insert(main_trace.begin(), first_row); auto const old_trace_size = main_trace.size(); @@ -4300,22 +4550,22 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c for (size_t i = 0; i < new_trace_size; i++) { auto& r = main_trace.at(i); - if ((r.avm_main_sel_op_add == FF(1) || r.avm_main_sel_op_sub == FF(1) || r.avm_main_sel_op_mul == FF(1) || - r.avm_main_sel_op_eq == FF(1) || r.avm_main_sel_op_not == FF(1) || r.avm_main_sel_op_lt == FF(1) || - r.avm_main_sel_op_lte == FF(1) || r.avm_main_sel_op_cast == FF(1) || r.avm_main_sel_op_shr == FF(1) || - r.avm_main_sel_op_shl == FF(1) || r.avm_main_sel_op_div == FF(1)) && - r.avm_main_tag_err == FF(0) && r.avm_main_op_err == FF(0)) { - r.avm_main_alu_sel = FF(1); + if ((r.main_sel_op_add == FF(1) || r.main_sel_op_sub == FF(1) || r.main_sel_op_mul == FF(1) || + r.main_sel_op_eq == FF(1) || r.main_sel_op_not == FF(1) || r.main_sel_op_lt == FF(1) || + r.main_sel_op_lte == FF(1) || r.main_sel_op_cast == FF(1) || r.main_sel_op_shr == FF(1) || + r.main_sel_op_shl == FF(1) || r.main_sel_op_div == FF(1)) && + r.main_tag_err == FF(0) && r.main_op_err == FF(0)) { + r.main_sel_alu = FF(1); } - if (r.avm_main_sel_internal_call == FF(1) || r.avm_main_sel_internal_return == FF(1)) { - r.avm_main_space_id = INTERNAL_CALL_SPACE_ID; + if (r.main_sel_op_internal_call == FF(1) || r.main_sel_op_internal_return == FF(1)) { + r.main_space_id = INTERNAL_CALL_SPACE_ID; } else { - r.avm_main_space_id = r.avm_main_call_ptr; + r.main_space_id = r.main_call_ptr; }; - r.avm_main_clk = i >= old_trace_size ? r.avm_main_clk : FF(i); - auto counter = i >= old_trace_size ? static_cast(r.avm_main_clk) : static_cast(i); + r.main_clk = i >= old_trace_size ? r.main_clk : FF(i); + auto counter = i >= old_trace_size ? static_cast(r.main_clk) : static_cast(i); r.incl_main_tag_err_counts = mem_trace_builder.m_tag_err_lookup_counts[static_cast(counter)]; if (counter <= UINT8_MAX) { @@ -4324,8 +4574,8 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c r.lookup_pow_2_0_counts = alu_trace_builder.u8_pow_2_counters[0][static_cast(counter)]; r.lookup_pow_2_1_counts = alu_trace_builder.u8_pow_2_counters[1][static_cast(counter)]; r.lookup_mem_rng_chk_hi_counts = mem_rng_check_hi_counts[static_cast(counter)]; - r.avm_main_sel_rng_8 = FF(1); - r.avm_main_table_pow_2 = uint256_t(1) << uint256_t(counter); + r.main_sel_rng_8 = FF(1); + r.main_table_pow_2 = uint256_t(1) << uint256_t(counter); } if (counter <= UINT16_MAX) { @@ -4369,7 +4619,7 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c r.range_check_da_gas_lo_counts = rem_gas_rng_check_counts[DA_LO_GAS_COUNTS_IDX][static_cast(counter)]; - r.avm_main_sel_rng_16 = FF(1); + r.main_sel_rng_16 = FF(1); } } @@ -4387,7 +4637,7 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c // Index 1 corresponds here to the first active row of the main execution trace, as // we already prepended the extra row for shifted columns. Therefore, initialization // of side_effect_counter occurs occurs on this row. - main_trace.at(1).avm_kernel_side_effect_counter = initial_side_effect_counter; + main_trace.at(1).kernel_side_effect_counter = initial_side_effect_counter; // External loop iterates over the kernel entries which are sorted by increasing clk. // Internal loop iterates to fill the gap in main trace between each kernel entries. @@ -4402,66 +4652,65 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c auto const& prev = main_trace.at(j); auto& dest = main_trace.at(j + 1); - dest.avm_kernel_note_hash_exist_write_offset = prev.avm_kernel_note_hash_exist_write_offset; - dest.avm_kernel_emit_note_hash_write_offset = prev.avm_kernel_emit_note_hash_write_offset; - dest.avm_kernel_nullifier_exists_write_offset = prev.avm_kernel_nullifier_exists_write_offset; - dest.avm_kernel_nullifier_non_exists_write_offset = prev.avm_kernel_nullifier_non_exists_write_offset; - dest.avm_kernel_emit_nullifier_write_offset = prev.avm_kernel_emit_nullifier_write_offset; - dest.avm_kernel_emit_l2_to_l1_msg_write_offset = prev.avm_kernel_emit_l2_to_l1_msg_write_offset; - dest.avm_kernel_emit_unencrypted_log_write_offset = prev.avm_kernel_emit_unencrypted_log_write_offset; - dest.avm_kernel_l1_to_l2_msg_exists_write_offset = prev.avm_kernel_l1_to_l2_msg_exists_write_offset; - dest.avm_kernel_sload_write_offset = prev.avm_kernel_sload_write_offset; - dest.avm_kernel_sstore_write_offset = prev.avm_kernel_sstore_write_offset; - dest.avm_kernel_side_effect_counter = prev.avm_kernel_side_effect_counter; + dest.kernel_note_hash_exist_write_offset = prev.kernel_note_hash_exist_write_offset; + dest.kernel_emit_note_hash_write_offset = prev.kernel_emit_note_hash_write_offset; + dest.kernel_nullifier_exists_write_offset = prev.kernel_nullifier_exists_write_offset; + dest.kernel_nullifier_non_exists_write_offset = prev.kernel_nullifier_non_exists_write_offset; + dest.kernel_emit_nullifier_write_offset = prev.kernel_emit_nullifier_write_offset; + dest.kernel_emit_l2_to_l1_msg_write_offset = prev.kernel_emit_l2_to_l1_msg_write_offset; + dest.kernel_emit_unencrypted_log_write_offset = prev.kernel_emit_unencrypted_log_write_offset; + dest.kernel_l1_to_l2_msg_exists_write_offset = prev.kernel_l1_to_l2_msg_exists_write_offset; + dest.kernel_sload_write_offset = prev.kernel_sload_write_offset; + dest.kernel_sstore_write_offset = prev.kernel_sstore_write_offset; + dest.kernel_side_effect_counter = prev.kernel_side_effect_counter; } Row& curr = main_trace.at(clk); // Read in values from kernel trace // Lookup values - curr.avm_kernel_kernel_in_offset = src.kernel_in_offset; - curr.avm_kernel_kernel_out_offset = src.kernel_out_offset; - curr.avm_main_q_kernel_lookup = static_cast(src.q_kernel_lookup); - curr.avm_main_q_kernel_output_lookup = static_cast(src.q_kernel_output_lookup); + curr.kernel_kernel_in_offset = src.kernel_in_offset; + curr.kernel_kernel_out_offset = src.kernel_out_offset; + curr.main_sel_q_kernel_lookup = static_cast(src.q_kernel_lookup); + curr.main_sel_q_kernel_output_lookup = static_cast(src.q_kernel_output_lookup); // Operation selectors - curr.avm_main_sel_op_note_hash_exists = static_cast(src.op_note_hash_exists); - curr.avm_main_sel_op_emit_note_hash = static_cast(src.op_emit_note_hash); - curr.avm_main_sel_op_nullifier_exists = static_cast(src.op_nullifier_exists); - curr.avm_main_sel_op_emit_nullifier = static_cast(src.op_emit_nullifier); - curr.avm_main_sel_op_l1_to_l2_msg_exists = static_cast(src.op_l1_to_l2_msg_exists); - curr.avm_main_sel_op_emit_unencrypted_log = static_cast(src.op_emit_unencrypted_log); - curr.avm_main_sel_op_emit_l2_to_l1_msg = static_cast(src.op_emit_l2_to_l1_msg); - curr.avm_main_sel_op_sload = static_cast(src.op_sload); - curr.avm_main_sel_op_sstore = static_cast(src.op_sstore); + curr.main_sel_op_note_hash_exists = static_cast(src.op_note_hash_exists); + curr.main_sel_op_emit_note_hash = static_cast(src.op_emit_note_hash); + curr.main_sel_op_nullifier_exists = static_cast(src.op_nullifier_exists); + curr.main_sel_op_emit_nullifier = static_cast(src.op_emit_nullifier); + curr.main_sel_op_l1_to_l2_msg_exists = static_cast(src.op_l1_to_l2_msg_exists); + curr.main_sel_op_emit_unencrypted_log = static_cast(src.op_emit_unencrypted_log); + curr.main_sel_op_emit_l2_to_l1_msg = static_cast(src.op_emit_l2_to_l1_msg); + curr.main_sel_op_sload = static_cast(src.op_sload); + curr.main_sel_op_sstore = static_cast(src.op_sstore); if (clk < old_trace_size) { Row& next = main_trace.at(clk + 1); // Increment the write offset counter for the following row - next.avm_kernel_note_hash_exist_write_offset = - curr.avm_kernel_note_hash_exist_write_offset + static_cast(src.op_note_hash_exists); - next.avm_kernel_emit_note_hash_write_offset = - curr.avm_kernel_emit_note_hash_write_offset + static_cast(src.op_emit_note_hash); - next.avm_kernel_emit_nullifier_write_offset = - curr.avm_kernel_emit_nullifier_write_offset + static_cast(src.op_emit_nullifier); - next.avm_kernel_nullifier_exists_write_offset = - curr.avm_kernel_nullifier_exists_write_offset + - (static_cast(src.op_nullifier_exists) * curr.avm_main_ib); - next.avm_kernel_nullifier_non_exists_write_offset = - curr.avm_kernel_nullifier_non_exists_write_offset + - (static_cast(src.op_nullifier_exists) * (FF(1) - curr.avm_main_ib)); - next.avm_kernel_l1_to_l2_msg_exists_write_offset = - curr.avm_kernel_l1_to_l2_msg_exists_write_offset + static_cast(src.op_l1_to_l2_msg_exists); - next.avm_kernel_emit_l2_to_l1_msg_write_offset = - curr.avm_kernel_emit_l2_to_l1_msg_write_offset + static_cast(src.op_emit_l2_to_l1_msg); - next.avm_kernel_emit_unencrypted_log_write_offset = - curr.avm_kernel_emit_unencrypted_log_write_offset + static_cast(src.op_emit_unencrypted_log); - next.avm_kernel_sload_write_offset = curr.avm_kernel_sload_write_offset + static_cast(src.op_sload); - next.avm_kernel_sstore_write_offset = curr.avm_kernel_sstore_write_offset + static_cast(src.op_sstore); + next.kernel_note_hash_exist_write_offset = + curr.kernel_note_hash_exist_write_offset + static_cast(src.op_note_hash_exists); + next.kernel_emit_note_hash_write_offset = + curr.kernel_emit_note_hash_write_offset + static_cast(src.op_emit_note_hash); + next.kernel_emit_nullifier_write_offset = + curr.kernel_emit_nullifier_write_offset + static_cast(src.op_emit_nullifier); + next.kernel_nullifier_exists_write_offset = + curr.kernel_nullifier_exists_write_offset + (static_cast(src.op_nullifier_exists) * curr.main_ib); + next.kernel_nullifier_non_exists_write_offset = + curr.kernel_nullifier_non_exists_write_offset + + (static_cast(src.op_nullifier_exists) * (FF(1) - curr.main_ib)); + next.kernel_l1_to_l2_msg_exists_write_offset = + curr.kernel_l1_to_l2_msg_exists_write_offset + static_cast(src.op_l1_to_l2_msg_exists); + next.kernel_emit_l2_to_l1_msg_write_offset = + curr.kernel_emit_l2_to_l1_msg_write_offset + static_cast(src.op_emit_l2_to_l1_msg); + next.kernel_emit_unencrypted_log_write_offset = + curr.kernel_emit_unencrypted_log_write_offset + static_cast(src.op_emit_unencrypted_log); + next.kernel_sload_write_offset = curr.kernel_sload_write_offset + static_cast(src.op_sload); + next.kernel_sstore_write_offset = curr.kernel_sstore_write_offset + static_cast(src.op_sstore); // The side effect counter will increment regardless of the offset value - next.avm_kernel_side_effect_counter = curr.avm_kernel_side_effect_counter + 1; + next.kernel_side_effect_counter = curr.kernel_side_effect_counter + 1; } kernel_padding_main_trace_bottom = clk + 1; @@ -4475,29 +4724,29 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c // Setting all of the counters to 0 after the IS_LAST check so we can satisfy the constraints until the end if (i == old_trace_size) { - dest.avm_kernel_note_hash_exist_write_offset = 0; - dest.avm_kernel_emit_note_hash_write_offset = 0; - dest.avm_kernel_nullifier_exists_write_offset = 0; - dest.avm_kernel_nullifier_non_exists_write_offset = 0; - dest.avm_kernel_emit_nullifier_write_offset = 0; - dest.avm_kernel_l1_to_l2_msg_exists_write_offset = 0; - dest.avm_kernel_emit_unencrypted_log_write_offset = 0; - dest.avm_kernel_emit_l2_to_l1_msg_write_offset = 0; - dest.avm_kernel_sload_write_offset = 0; - dest.avm_kernel_sstore_write_offset = 0; - dest.avm_kernel_side_effect_counter = 0; + dest.kernel_note_hash_exist_write_offset = 0; + dest.kernel_emit_note_hash_write_offset = 0; + dest.kernel_nullifier_exists_write_offset = 0; + dest.kernel_nullifier_non_exists_write_offset = 0; + dest.kernel_emit_nullifier_write_offset = 0; + dest.kernel_l1_to_l2_msg_exists_write_offset = 0; + dest.kernel_emit_unencrypted_log_write_offset = 0; + dest.kernel_emit_l2_to_l1_msg_write_offset = 0; + dest.kernel_sload_write_offset = 0; + dest.kernel_sstore_write_offset = 0; + dest.kernel_side_effect_counter = 0; } else { - dest.avm_kernel_note_hash_exist_write_offset = prev.avm_kernel_note_hash_exist_write_offset; - dest.avm_kernel_emit_note_hash_write_offset = prev.avm_kernel_emit_note_hash_write_offset; - dest.avm_kernel_nullifier_exists_write_offset = prev.avm_kernel_nullifier_exists_write_offset; - dest.avm_kernel_nullifier_non_exists_write_offset = prev.avm_kernel_nullifier_non_exists_write_offset; - dest.avm_kernel_emit_nullifier_write_offset = prev.avm_kernel_emit_nullifier_write_offset; - dest.avm_kernel_l1_to_l2_msg_exists_write_offset = prev.avm_kernel_l1_to_l2_msg_exists_write_offset; - dest.avm_kernel_emit_unencrypted_log_write_offset = prev.avm_kernel_emit_unencrypted_log_write_offset; - dest.avm_kernel_emit_l2_to_l1_msg_write_offset = prev.avm_kernel_emit_l2_to_l1_msg_write_offset; - dest.avm_kernel_sload_write_offset = prev.avm_kernel_sload_write_offset; - dest.avm_kernel_sstore_write_offset = prev.avm_kernel_sstore_write_offset; - dest.avm_kernel_side_effect_counter = prev.avm_kernel_side_effect_counter; + dest.kernel_note_hash_exist_write_offset = prev.kernel_note_hash_exist_write_offset; + dest.kernel_emit_note_hash_write_offset = prev.kernel_emit_note_hash_write_offset; + dest.kernel_nullifier_exists_write_offset = prev.kernel_nullifier_exists_write_offset; + dest.kernel_nullifier_non_exists_write_offset = prev.kernel_nullifier_non_exists_write_offset; + dest.kernel_emit_nullifier_write_offset = prev.kernel_emit_nullifier_write_offset; + dest.kernel_l1_to_l2_msg_exists_write_offset = prev.kernel_l1_to_l2_msg_exists_write_offset; + dest.kernel_emit_unencrypted_log_write_offset = prev.kernel_emit_unencrypted_log_write_offset; + dest.kernel_emit_l2_to_l1_msg_write_offset = prev.kernel_emit_l2_to_l1_msg_write_offset; + dest.kernel_sload_write_offset = prev.kernel_sload_write_offset; + dest.kernel_sstore_write_offset = prev.kernel_sstore_write_offset; + dest.kernel_side_effect_counter = prev.kernel_side_effect_counter; } } @@ -4510,13 +4759,13 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c if (value != kernel_trace_builder.kernel_input_selector_counter.end()) { auto& dest = main_trace.at(i); dest.lookup_into_kernel_counts = FF(value->second); - dest.avm_kernel_q_public_input_kernel_add_to_table = FF(1); + dest.kernel_q_public_input_kernel_add_to_table = FF(1); } } // Copy the kernel input public inputs for (size_t i = 0; i < KERNEL_INPUTS_LENGTH; i++) { - main_trace.at(i).avm_kernel_kernel_inputs = std::get(kernel_trace_builder.public_inputs).at(i); + main_trace.at(i).kernel_kernel_inputs = std::get(kernel_trace_builder.public_inputs).at(i); } // Write lookup counts for outputs @@ -4525,19 +4774,19 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c if (value != kernel_trace_builder.kernel_output_selector_counter.end()) { auto& dest = main_trace.at(i); dest.kernel_output_lookup_counts = FF(value->second); - dest.avm_kernel_q_public_input_kernel_out_add_to_table = FF(1); + dest.kernel_q_public_input_kernel_out_add_to_table = FF(1); } } // Copy the kernel outputs counts into the main trace for (size_t i = 0; i < KERNEL_OUTPUTS_LENGTH; i++) { - main_trace.at(i).avm_kernel_kernel_value_out = + main_trace.at(i).kernel_kernel_value_out = std::get(kernel_trace_builder.public_inputs).at(i); - main_trace.at(i).avm_kernel_kernel_side_effect_out = + main_trace.at(i).kernel_kernel_side_effect_out = std::get(kernel_trace_builder.public_inputs).at(i); - main_trace.at(i).avm_kernel_kernel_metadata_out = + main_trace.at(i).kernel_kernel_metadata_out = std::get(kernel_trace_builder.public_inputs).at(i); } @@ -4551,9 +4800,9 @@ std::vector AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c for (auto const& [opcode, gas_entry] : GAS_COST_TABLE) { auto& dest = main_trace.at(static_cast(opcode)); - dest.avm_gas_gas_cost_sel = FF(1); - dest.avm_gas_l2_gas_fixed_table = gas_entry.l2_fixed_gas_cost; - dest.avm_gas_da_gas_fixed_table = gas_entry.da_fixed_gas_cost; + dest.gas_sel_gas_cost = FF(1); + dest.gas_l2_gas_fixed_table = gas_entry.l2_fixed_gas_cost; + dest.gas_da_gas_fixed_table = gas_entry.da_fixed_gas_cost; } // Finalise gas left lookup counts diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp index aa2ff3c9900..b0d86f4c5da 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp @@ -33,7 +33,7 @@ class AvmTraceBuilder { ExecutionHints execution_hints = {}, uint32_t side_effect_counter = 0); - std::vector finalize(uint32_t min_trace_size = 0, bool range_check_required = false); + std::vector finalize(uint32_t min_trace_size = 0, bool range_check_required = ENABLE_PROVING); void reset(); uint32_t getPc() const { return pc; } @@ -204,6 +204,11 @@ class AvmTraceBuilder { uint32_t rhs_y_offset, uint32_t rhs_is_inf_offset, uint32_t output_offset); + void op_variable_msm(uint8_t indirect, + uint32_t points_offset, + uint32_t scalars_offset, + uint32_t output_offset, + uint32_t point_length_offset); private: // Used for the standard indirect address resolution of three operands opcode. diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp index b8206d9dedc..2f6cc507365 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp @@ -6,7 +6,7 @@ #define MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL 16 #define MAX_NEW_L2_TO_L1_MSGS_PER_CALL 2 #define MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL 32 -#define MAX_PUBLIC_DATA_READS_PER_CALL 16 +#define MAX_PUBLIC_DATA_READS_PER_CALL 32 #define MAX_NOTE_HASH_READ_REQUESTS_PER_CALL 32 #define MAX_NULLIFIER_READ_REQUESTS_PER_CALL 32 #define MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL 32 @@ -30,5 +30,5 @@ #define STATE_REFERENCE_LENGTH 8 #define TOTAL_FEES_LENGTH 1 #define HEADER_LENGTH 23 -#define PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH 530 +#define PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH 578 #define PUBLIC_CONTEXT_INPUTS_LENGTH 41 diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_conversion_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_conversion_trace.cpp index cb189e1750b..fe65a655a2a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_conversion_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_conversion_trace.cpp @@ -1,13 +1,7 @@ - #include "barretenberg/vm/avm_trace/gadgets/avm_conversion_trace.hpp" namespace bb::avm_trace { -AvmConversionTraceBuilder::AvmConversionTraceBuilder() -{ - conversion_trace.reserve(AVM_TRACE_SIZE); -} - std::vector AvmConversionTraceBuilder::finalize() { return std::move(conversion_trace); @@ -40,7 +34,7 @@ std::vector AvmConversionTraceBuilder::op_to_radix_le(FF const& a, auto a_uint256 = uint256_t(a); auto radix_uint256 = uint256_t(radix); - std::vector bytes{}; + std::vector bytes; for (uint32_t i = 0; i < num_limbs; i++) { bytes.emplace_back(static_cast(a_uint256 % radix_uint256)); a_uint256 /= radix_uint256; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_conversion_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_conversion_trace.hpp index 1cdce6502d7..e45d069ec2a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_conversion_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_conversion_trace.hpp @@ -20,7 +20,7 @@ class AvmConversionTraceBuilder { std::vector limbs; }; - AvmConversionTraceBuilder(); + AvmConversionTraceBuilder() = default; void reset(); // Finalize the trace std::vector finalize(); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_ecc.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_ecc.cpp index fd3fc8955d1..88cfccd42af 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_ecc.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_ecc.cpp @@ -2,12 +2,8 @@ #include "barretenberg/vm/avm_trace/avm_common.hpp" namespace bb::avm_trace { -using element = grumpkin::g1::affine_element; -AvmEccTraceBuilder::AvmEccTraceBuilder() -{ - ecc_trace.reserve(AVM_TRACE_SIZE); -} +using element = grumpkin::g1::affine_element; std::vector AvmEccTraceBuilder::finalize() { @@ -30,4 +26,21 @@ element AvmEccTraceBuilder::embedded_curve_add(element lhs, element rhs, uint32_ return result; } +element AvmEccTraceBuilder::variable_msm(const std::vector& points, + const std::vector& scalars, + uint32_t clk) +{ + // Replace this with pippenger if/when we have the time + auto result = grumpkin::g1::affine_point_at_infinity; + for (size_t i = 0; i < points.size(); ++i) { + result = result + points[i] * scalars[i]; + } + + std::tuple result_tuple = { result.x, result.y, result.is_point_at_infinity() }; + + ecc_trace.push_back({ .clk = clk, .result = result_tuple }); + + return result; +} + } // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_ecc.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_ecc.hpp index 6450a33db39..e3b4599dbc2 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_ecc.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_ecc.hpp @@ -5,22 +5,26 @@ #include "barretenberg/vm/avm_trace/avm_common.hpp" namespace bb::avm_trace { + class AvmEccTraceBuilder { public: struct EccTraceEntry { uint32_t clk = 0; - std::tuple p1; // x, y, is_infinity - std::tuple p2; - std::tuple result; + std::tuple p1 = { FF(0), FF(0), true }; // x, y, is_infinity + std::tuple p2 = { FF(0), FF(0), true }; + std::tuple result = { FF(0), FF(0), true }; }; - AvmEccTraceBuilder(); + AvmEccTraceBuilder() = default; void reset(); // Finalize the trace std::vector finalize(); grumpkin::g1::affine_element embedded_curve_add(grumpkin::g1::affine_element lhs, grumpkin::g1::affine_element rhs, uint32_t clk); + grumpkin::g1::affine_element variable_msm(const std::vector& points, + const std::vector& scalars, + uint32_t clk); private: std::vector ecc_trace; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_keccak.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_keccak.cpp index 6a6230b417a..c3048ca0c93 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_keccak.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_keccak.cpp @@ -7,11 +7,6 @@ namespace bb::avm_trace { -AvmKeccakTraceBuilder::AvmKeccakTraceBuilder() -{ - keccak_trace.reserve(AVM_TRACE_SIZE); -} - std::vector AvmKeccakTraceBuilder::finalize() { return std::move(keccak_trace); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_keccak.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_keccak.hpp index 341c728c9aa..fb21c3495de 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_keccak.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_keccak.hpp @@ -18,7 +18,7 @@ class AvmKeccakTraceBuilder { uint32_t output_size = 0; }; - AvmKeccakTraceBuilder(); + AvmKeccakTraceBuilder() = default; void reset(); // Finalize the trace std::vector finalize(); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_pedersen.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_pedersen.cpp index 81c0200db7b..d4321b9f8cc 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_pedersen.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_pedersen.cpp @@ -4,11 +4,6 @@ namespace bb::avm_trace { -AvmPedersenTraceBuilder::AvmPedersenTraceBuilder() -{ - pedersen_trace.reserve(AVM_TRACE_SIZE); -} - std::vector AvmPedersenTraceBuilder::finalize() { return std::move(pedersen_trace); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_pedersen.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_pedersen.hpp index 609e47f47ec..4ca459127e5 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_pedersen.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_pedersen.hpp @@ -15,7 +15,7 @@ class AvmPedersenTraceBuilder { FF output; }; - AvmPedersenTraceBuilder(); + AvmPedersenTraceBuilder() = default; void reset(); // Finalize the trace std::vector finalize(); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_poseidon2.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_poseidon2.cpp index 430fcec84cb..e61ce5810c4 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_poseidon2.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_poseidon2.cpp @@ -4,11 +4,6 @@ namespace bb::avm_trace { -AvmPoseidon2TraceBuilder::AvmPoseidon2TraceBuilder() -{ - poseidon2_trace.reserve(AVM_TRACE_SIZE); -} - std::vector AvmPoseidon2TraceBuilder::finalize() { return std::move(poseidon2_trace); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_poseidon2.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_poseidon2.hpp index 19248058ca4..1db074b658a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_poseidon2.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_poseidon2.hpp @@ -7,6 +7,7 @@ #include namespace bb::avm_trace { + class AvmPoseidon2TraceBuilder { public: struct Poseidon2TraceEntry { @@ -15,7 +16,7 @@ class AvmPoseidon2TraceBuilder { std::array output; }; - AvmPoseidon2TraceBuilder(); + AvmPoseidon2TraceBuilder() = default; void reset(); // Finalize the trace std::vector finalize(); @@ -25,4 +26,5 @@ class AvmPoseidon2TraceBuilder { private: std::vector poseidon2_trace; }; + } // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_sha256.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_sha256.cpp index a877aea1019..f431c271866 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_sha256.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_sha256.cpp @@ -11,11 +11,6 @@ namespace bb::avm_trace { -AvmSha256TraceBuilder::AvmSha256TraceBuilder() -{ - sha256_trace.reserve(AVM_TRACE_SIZE); -} - std::vector AvmSha256TraceBuilder::finalize() { return std::move(sha256_trace); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_sha256.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_sha256.hpp index 26bd9173503..672ad98c770 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_sha256.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/gadgets/avm_sha256.hpp @@ -7,6 +7,7 @@ #include namespace bb::avm_trace { + class AvmSha256TraceBuilder { public: struct Sha256TraceEntry { @@ -16,7 +17,7 @@ class AvmSha256TraceBuilder { std::array output{}; }; - AvmSha256TraceBuilder(); + AvmSha256TraceBuilder() = default; void reset(); // Finalize the trace std::vector finalize(); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.cpp index b675830a2e8..a0db02764b3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.cpp @@ -18,296 +18,296 @@ template std::string field_to_string(const FF& ff) template std::vector AvmFullRow::names() { - return { "avm_main_clk", - "avm_main_first", - "avm_alu_a_hi", - "avm_alu_a_lo", - "avm_alu_alu_sel", - "avm_alu_b_hi", - "avm_alu_b_lo", - "avm_alu_borrow", - "avm_alu_cf", - "avm_alu_clk", - "avm_alu_cmp_rng_ctr", - "avm_alu_cmp_sel", - "avm_alu_div_rng_chk_selector", - "avm_alu_div_u16_r0", - "avm_alu_div_u16_r1", - "avm_alu_div_u16_r2", - "avm_alu_div_u16_r3", - "avm_alu_div_u16_r4", - "avm_alu_div_u16_r5", - "avm_alu_div_u16_r6", - "avm_alu_div_u16_r7", - "avm_alu_divisor_hi", - "avm_alu_divisor_lo", - "avm_alu_ff_tag", - "avm_alu_ia", - "avm_alu_ib", - "avm_alu_ic", - "avm_alu_in_tag", - "avm_alu_op_add", - "avm_alu_op_cast", - "avm_alu_op_cast_prev", - "avm_alu_op_div", - "avm_alu_op_div_a_lt_b", - "avm_alu_op_div_std", - "avm_alu_op_eq", - "avm_alu_op_eq_diff_inv", - "avm_alu_op_lt", - "avm_alu_op_lte", - "avm_alu_op_mul", - "avm_alu_op_not", - "avm_alu_op_shl", - "avm_alu_op_shr", - "avm_alu_op_sub", - "avm_alu_p_a_borrow", - "avm_alu_p_b_borrow", - "avm_alu_p_sub_a_hi", - "avm_alu_p_sub_a_lo", - "avm_alu_p_sub_b_hi", - "avm_alu_p_sub_b_lo", - "avm_alu_partial_prod_hi", - "avm_alu_partial_prod_lo", - "avm_alu_quotient_hi", - "avm_alu_quotient_lo", - "avm_alu_remainder", - "avm_alu_res_hi", - "avm_alu_res_lo", - "avm_alu_rng_chk_lookup_selector", - "avm_alu_rng_chk_sel", - "avm_alu_shift_lt_bit_len", - "avm_alu_shift_sel", - "avm_alu_t_sub_s_bits", - "avm_alu_two_pow_s", - "avm_alu_two_pow_t_sub_s", - "avm_alu_u128_tag", - "avm_alu_u16_r0", - "avm_alu_u16_r1", - "avm_alu_u16_r10", - "avm_alu_u16_r11", - "avm_alu_u16_r12", - "avm_alu_u16_r13", - "avm_alu_u16_r14", - "avm_alu_u16_r2", - "avm_alu_u16_r3", - "avm_alu_u16_r4", - "avm_alu_u16_r5", - "avm_alu_u16_r6", - "avm_alu_u16_r7", - "avm_alu_u16_r8", - "avm_alu_u16_r9", - "avm_alu_u16_tag", - "avm_alu_u32_tag", - "avm_alu_u64_tag", - "avm_alu_u8_r0", - "avm_alu_u8_r1", - "avm_alu_u8_tag", - "avm_binary_acc_ia", - "avm_binary_acc_ib", - "avm_binary_acc_ic", - "avm_binary_bin_sel", - "avm_binary_clk", - "avm_binary_ia_bytes", - "avm_binary_ib_bytes", - "avm_binary_ic_bytes", - "avm_binary_in_tag", - "avm_binary_mem_tag_ctr", - "avm_binary_mem_tag_ctr_inv", - "avm_binary_op_id", - "avm_binary_start", - "avm_byte_lookup_bin_sel", - "avm_byte_lookup_table_byte_lengths", - "avm_byte_lookup_table_in_tags", - "avm_byte_lookup_table_input_a", - "avm_byte_lookup_table_input_b", - "avm_byte_lookup_table_op_id", - "avm_byte_lookup_table_output", - "avm_conversion_clk", - "avm_conversion_input", - "avm_conversion_num_limbs", - "avm_conversion_radix", - "avm_conversion_to_radix_le_sel", - "avm_gas_da_gas_fixed_table", - "avm_gas_gas_cost_sel", - "avm_gas_l2_gas_fixed_table", - "avm_keccakf1600_clk", - "avm_keccakf1600_input", - "avm_keccakf1600_keccakf1600_sel", - "avm_keccakf1600_output", - "avm_kernel_emit_l2_to_l1_msg_write_offset", - "avm_kernel_emit_note_hash_write_offset", - "avm_kernel_emit_nullifier_write_offset", - "avm_kernel_emit_unencrypted_log_write_offset", - "avm_kernel_kernel_in_offset", - "avm_kernel_kernel_inputs", - "avm_kernel_kernel_metadata_out", - "avm_kernel_kernel_out_offset", - "avm_kernel_kernel_side_effect_out", - "avm_kernel_kernel_value_out", - "avm_kernel_l1_to_l2_msg_exists_write_offset", - "avm_kernel_note_hash_exist_write_offset", - "avm_kernel_nullifier_exists_write_offset", - "avm_kernel_nullifier_non_exists_write_offset", - "avm_kernel_q_public_input_kernel_add_to_table", - "avm_kernel_q_public_input_kernel_out_add_to_table", - "avm_kernel_side_effect_counter", - "avm_kernel_sload_write_offset", - "avm_kernel_sstore_write_offset", - "avm_main_abs_da_rem_gas_hi", - "avm_main_abs_da_rem_gas_lo", - "avm_main_abs_l2_rem_gas_hi", - "avm_main_abs_l2_rem_gas_lo", - "avm_main_alu_in_tag", - "avm_main_alu_sel", - "avm_main_bin_op_id", - "avm_main_bin_sel", - "avm_main_call_ptr", - "avm_main_da_gas_op", - "avm_main_da_gas_remaining", - "avm_main_da_out_of_gas", - "avm_main_gas_cost_active", - "avm_main_ia", - "avm_main_ib", - "avm_main_ic", - "avm_main_id", - "avm_main_id_zero", - "avm_main_ind_a", - "avm_main_ind_b", - "avm_main_ind_c", - "avm_main_ind_d", - "avm_main_ind_op_a", - "avm_main_ind_op_b", - "avm_main_ind_op_c", - "avm_main_ind_op_d", - "avm_main_internal_return_ptr", - "avm_main_inv", - "avm_main_l2_gas_op", - "avm_main_l2_gas_remaining", - "avm_main_l2_out_of_gas", - "avm_main_last", - "avm_main_mem_idx_a", - "avm_main_mem_idx_b", - "avm_main_mem_idx_c", - "avm_main_mem_idx_d", - "avm_main_mem_op_a", - "avm_main_mem_op_activate_gas", - "avm_main_mem_op_b", - "avm_main_mem_op_c", - "avm_main_mem_op_d", - "avm_main_op_err", - "avm_main_opcode_val", - "avm_main_pc", - "avm_main_q_kernel_lookup", - "avm_main_q_kernel_output_lookup", - "avm_main_r_in_tag", - "avm_main_rwa", - "avm_main_rwb", - "avm_main_rwc", - "avm_main_rwd", - "avm_main_sel_cmov", - "avm_main_sel_external_call", - "avm_main_sel_halt", - "avm_main_sel_internal_call", - "avm_main_sel_internal_return", - "avm_main_sel_jump", - "avm_main_sel_jumpi", - "avm_main_sel_mov", - "avm_main_sel_mov_a", - "avm_main_sel_mov_b", - "avm_main_sel_op_add", - "avm_main_sel_op_address", - "avm_main_sel_op_and", - "avm_main_sel_op_block_number", - "avm_main_sel_op_cast", - "avm_main_sel_op_chain_id", - "avm_main_sel_op_coinbase", - "avm_main_sel_op_dagasleft", - "avm_main_sel_op_div", - "avm_main_sel_op_emit_l2_to_l1_msg", - "avm_main_sel_op_emit_note_hash", - "avm_main_sel_op_emit_nullifier", - "avm_main_sel_op_emit_unencrypted_log", - "avm_main_sel_op_eq", - "avm_main_sel_op_fdiv", - "avm_main_sel_op_fee_per_da_gas", - "avm_main_sel_op_fee_per_l2_gas", - "avm_main_sel_op_get_contract_instance", - "avm_main_sel_op_keccak", - "avm_main_sel_op_l1_to_l2_msg_exists", - "avm_main_sel_op_l2gasleft", - "avm_main_sel_op_lt", - "avm_main_sel_op_lte", - "avm_main_sel_op_mul", - "avm_main_sel_op_not", - "avm_main_sel_op_note_hash_exists", - "avm_main_sel_op_nullifier_exists", - "avm_main_sel_op_or", - "avm_main_sel_op_pedersen", - "avm_main_sel_op_poseidon2", - "avm_main_sel_op_radix_le", - "avm_main_sel_op_sender", - "avm_main_sel_op_sha256", - "avm_main_sel_op_shl", - "avm_main_sel_op_shr", - "avm_main_sel_op_sload", - "avm_main_sel_op_sstore", - "avm_main_sel_op_storage_address", - "avm_main_sel_op_sub", - "avm_main_sel_op_timestamp", - "avm_main_sel_op_transaction_fee", - "avm_main_sel_op_version", - "avm_main_sel_op_xor", - "avm_main_sel_rng_16", - "avm_main_sel_rng_8", - "avm_main_space_id", - "avm_main_table_pow_2", - "avm_main_tag_err", - "avm_main_w_in_tag", - "avm_mem_addr", - "avm_mem_clk", - "avm_mem_diff_hi", - "avm_mem_diff_lo", - "avm_mem_diff_mid", - "avm_mem_glob_addr", - "avm_mem_ind_op_a", - "avm_mem_ind_op_b", - "avm_mem_ind_op_c", - "avm_mem_ind_op_d", - "avm_mem_last", - "avm_mem_lastAccess", - "avm_mem_mem_sel", - "avm_mem_one_min_inv", - "avm_mem_op_a", - "avm_mem_op_b", - "avm_mem_op_c", - "avm_mem_op_d", - "avm_mem_r_in_tag", - "avm_mem_rng_chk_sel", - "avm_mem_rw", - "avm_mem_sel_cmov", - "avm_mem_sel_mov_a", - "avm_mem_sel_mov_b", - "avm_mem_skip_check_tag", - "avm_mem_space_id", - "avm_mem_tag", - "avm_mem_tag_err", - "avm_mem_tsp", - "avm_mem_val", - "avm_mem_w_in_tag", - "avm_pedersen_clk", - "avm_pedersen_input", - "avm_pedersen_output", - "avm_pedersen_pedersen_sel", - "avm_poseidon2_clk", - "avm_poseidon2_input", - "avm_poseidon2_output", - "avm_poseidon2_poseidon_perm_sel", - "avm_sha256_clk", - "avm_sha256_input", - "avm_sha256_output", - "avm_sha256_sha256_compression_sel", - "avm_sha256_state", + return { "main_clk", + "main_sel_first", + "alu_a_hi", + "alu_a_lo", + "alu_b_hi", + "alu_b_lo", + "alu_borrow", + "alu_cf", + "alu_clk", + "alu_cmp_rng_ctr", + "alu_div_u16_r0", + "alu_div_u16_r1", + "alu_div_u16_r2", + "alu_div_u16_r3", + "alu_div_u16_r4", + "alu_div_u16_r5", + "alu_div_u16_r6", + "alu_div_u16_r7", + "alu_divisor_hi", + "alu_divisor_lo", + "alu_ff_tag", + "alu_ia", + "alu_ib", + "alu_ic", + "alu_in_tag", + "alu_op_add", + "alu_op_cast", + "alu_op_cast_prev", + "alu_op_div", + "alu_op_div_a_lt_b", + "alu_op_div_std", + "alu_op_eq", + "alu_op_eq_diff_inv", + "alu_op_lt", + "alu_op_lte", + "alu_op_mul", + "alu_op_not", + "alu_op_shl", + "alu_op_shr", + "alu_op_sub", + "alu_p_a_borrow", + "alu_p_b_borrow", + "alu_p_sub_a_hi", + "alu_p_sub_a_lo", + "alu_p_sub_b_hi", + "alu_p_sub_b_lo", + "alu_partial_prod_hi", + "alu_partial_prod_lo", + "alu_quotient_hi", + "alu_quotient_lo", + "alu_remainder", + "alu_res_hi", + "alu_res_lo", + "alu_sel_alu", + "alu_sel_cmp", + "alu_sel_div_rng_chk", + "alu_sel_rng_chk", + "alu_sel_rng_chk_lookup", + "alu_sel_shift_which", + "alu_shift_lt_bit_len", + "alu_t_sub_s_bits", + "alu_two_pow_s", + "alu_two_pow_t_sub_s", + "alu_u128_tag", + "alu_u16_r0", + "alu_u16_r1", + "alu_u16_r10", + "alu_u16_r11", + "alu_u16_r12", + "alu_u16_r13", + "alu_u16_r14", + "alu_u16_r2", + "alu_u16_r3", + "alu_u16_r4", + "alu_u16_r5", + "alu_u16_r6", + "alu_u16_r7", + "alu_u16_r8", + "alu_u16_r9", + "alu_u16_tag", + "alu_u32_tag", + "alu_u64_tag", + "alu_u8_r0", + "alu_u8_r1", + "alu_u8_tag", + "binary_acc_ia", + "binary_acc_ib", + "binary_acc_ic", + "binary_clk", + "binary_ia_bytes", + "binary_ib_bytes", + "binary_ic_bytes", + "binary_in_tag", + "binary_mem_tag_ctr", + "binary_mem_tag_ctr_inv", + "binary_op_id", + "binary_sel_bin", + "binary_start", + "byte_lookup_sel_bin", + "byte_lookup_table_byte_lengths", + "byte_lookup_table_in_tags", + "byte_lookup_table_input_a", + "byte_lookup_table_input_b", + "byte_lookup_table_op_id", + "byte_lookup_table_output", + "conversion_clk", + "conversion_input", + "conversion_num_limbs", + "conversion_radix", + "conversion_sel_to_radix_le", + "gas_da_gas_fixed_table", + "gas_l2_gas_fixed_table", + "gas_sel_gas_cost", + "keccakf1600_clk", + "keccakf1600_input", + "keccakf1600_output", + "keccakf1600_sel_keccakf1600", + "kernel_emit_l2_to_l1_msg_write_offset", + "kernel_emit_note_hash_write_offset", + "kernel_emit_nullifier_write_offset", + "kernel_emit_unencrypted_log_write_offset", + "kernel_kernel_in_offset", + "kernel_kernel_inputs", + "kernel_kernel_metadata_out", + "kernel_kernel_out_offset", + "kernel_kernel_side_effect_out", + "kernel_kernel_value_out", + "kernel_l1_to_l2_msg_exists_write_offset", + "kernel_note_hash_exist_write_offset", + "kernel_nullifier_exists_write_offset", + "kernel_nullifier_non_exists_write_offset", + "kernel_q_public_input_kernel_add_to_table", + "kernel_q_public_input_kernel_out_add_to_table", + "kernel_side_effect_counter", + "kernel_sload_write_offset", + "kernel_sstore_write_offset", + "main_abs_da_rem_gas_hi", + "main_abs_da_rem_gas_lo", + "main_abs_l2_rem_gas_hi", + "main_abs_l2_rem_gas_lo", + "main_alu_in_tag", + "main_bin_op_id", + "main_call_ptr", + "main_da_gas_op_cost", + "main_da_gas_remaining", + "main_da_out_of_gas", + "main_ia", + "main_ib", + "main_ic", + "main_id", + "main_id_zero", + "main_ind_addr_a", + "main_ind_addr_b", + "main_ind_addr_c", + "main_ind_addr_d", + "main_internal_return_ptr", + "main_inv", + "main_l2_gas_op_cost", + "main_l2_gas_remaining", + "main_l2_out_of_gas", + "main_mem_addr_a", + "main_mem_addr_b", + "main_mem_addr_c", + "main_mem_addr_d", + "main_op_err", + "main_opcode_val", + "main_pc", + "main_r_in_tag", + "main_rwa", + "main_rwb", + "main_rwc", + "main_rwd", + "main_sel_alu", + "main_sel_bin", + "main_sel_gas_accounting_active", + "main_sel_last", + "main_sel_mem_op_a", + "main_sel_mem_op_activate_gas", + "main_sel_mem_op_b", + "main_sel_mem_op_c", + "main_sel_mem_op_d", + "main_sel_mov_ia_to_ic", + "main_sel_mov_ib_to_ic", + "main_sel_op_add", + "main_sel_op_address", + "main_sel_op_and", + "main_sel_op_block_number", + "main_sel_op_cast", + "main_sel_op_chain_id", + "main_sel_op_cmov", + "main_sel_op_coinbase", + "main_sel_op_dagasleft", + "main_sel_op_div", + "main_sel_op_emit_l2_to_l1_msg", + "main_sel_op_emit_note_hash", + "main_sel_op_emit_nullifier", + "main_sel_op_emit_unencrypted_log", + "main_sel_op_eq", + "main_sel_op_external_call", + "main_sel_op_fdiv", + "main_sel_op_fee_per_da_gas", + "main_sel_op_fee_per_l2_gas", + "main_sel_op_get_contract_instance", + "main_sel_op_halt", + "main_sel_op_internal_call", + "main_sel_op_internal_return", + "main_sel_op_jump", + "main_sel_op_jumpi", + "main_sel_op_keccak", + "main_sel_op_l1_to_l2_msg_exists", + "main_sel_op_l2gasleft", + "main_sel_op_lt", + "main_sel_op_lte", + "main_sel_op_mov", + "main_sel_op_mul", + "main_sel_op_not", + "main_sel_op_note_hash_exists", + "main_sel_op_nullifier_exists", + "main_sel_op_or", + "main_sel_op_pedersen", + "main_sel_op_poseidon2", + "main_sel_op_radix_le", + "main_sel_op_sender", + "main_sel_op_sha256", + "main_sel_op_shl", + "main_sel_op_shr", + "main_sel_op_sload", + "main_sel_op_sstore", + "main_sel_op_storage_address", + "main_sel_op_sub", + "main_sel_op_timestamp", + "main_sel_op_transaction_fee", + "main_sel_op_version", + "main_sel_op_xor", + "main_sel_q_kernel_lookup", + "main_sel_q_kernel_output_lookup", + "main_sel_resolve_ind_addr_a", + "main_sel_resolve_ind_addr_b", + "main_sel_resolve_ind_addr_c", + "main_sel_resolve_ind_addr_d", + "main_sel_rng_16", + "main_sel_rng_8", + "main_space_id", + "main_table_pow_2", + "main_tag_err", + "main_w_in_tag", + "mem_addr", + "mem_clk", + "mem_diff_hi", + "mem_diff_lo", + "mem_diff_mid", + "mem_glob_addr", + "mem_last", + "mem_lastAccess", + "mem_one_min_inv", + "mem_r_in_tag", + "mem_rw", + "mem_sel_mem", + "mem_sel_mov_ia_to_ic", + "mem_sel_mov_ib_to_ic", + "mem_sel_op_a", + "mem_sel_op_b", + "mem_sel_op_c", + "mem_sel_op_cmov", + "mem_sel_op_d", + "mem_sel_resolve_ind_addr_a", + "mem_sel_resolve_ind_addr_b", + "mem_sel_resolve_ind_addr_c", + "mem_sel_resolve_ind_addr_d", + "mem_sel_rng_chk", + "mem_skip_check_tag", + "mem_space_id", + "mem_tag", + "mem_tag_err", + "mem_tsp", + "mem_val", + "mem_w_in_tag", + "pedersen_clk", + "pedersen_input", + "pedersen_output", + "pedersen_sel_pedersen", + "poseidon2_clk", + "poseidon2_input", + "poseidon2_output", + "poseidon2_sel_poseidon_perm", + "sha256_clk", + "sha256_input", + "sha256_output", + "sha256_sel_sha256_compression", + "sha256_state", "perm_main_alu", "perm_main_bin", "perm_main_conv", @@ -317,10 +317,10 @@ template std::vector AvmFullRow::names() "perm_main_mem_b", "perm_main_mem_c", "perm_main_mem_d", - "perm_main_mem_ind_a", - "perm_main_mem_ind_b", - "perm_main_mem_ind_c", - "perm_main_mem_ind_d", + "perm_main_mem_ind_addr_a", + "perm_main_mem_ind_addr_b", + "perm_main_mem_ind_addr_c", + "perm_main_mem_ind_addr_d", "lookup_byte_lengths", "lookup_byte_operations", "lookup_opcode_gas", @@ -409,178 +409,171 @@ template std::vector AvmFullRow::names() template std::ostream& operator<<(std::ostream& os, AvmFullRow const& row) { return os - << field_to_string(row.avm_main_clk) << "," << field_to_string(row.avm_main_first) << "," - << field_to_string(row.avm_alu_a_hi) << "," << field_to_string(row.avm_alu_a_lo) << "," - << field_to_string(row.avm_alu_alu_sel) << "," << field_to_string(row.avm_alu_b_hi) << "," - << field_to_string(row.avm_alu_b_lo) << "," << field_to_string(row.avm_alu_borrow) << "," - << field_to_string(row.avm_alu_cf) << "," << field_to_string(row.avm_alu_clk) << "," - << field_to_string(row.avm_alu_cmp_rng_ctr) << "," << field_to_string(row.avm_alu_cmp_sel) << "," - << field_to_string(row.avm_alu_div_rng_chk_selector) << "," << field_to_string(row.avm_alu_div_u16_r0) << "," - << field_to_string(row.avm_alu_div_u16_r1) << "," << field_to_string(row.avm_alu_div_u16_r2) << "," - << field_to_string(row.avm_alu_div_u16_r3) << "," << field_to_string(row.avm_alu_div_u16_r4) << "," - << field_to_string(row.avm_alu_div_u16_r5) << "," << field_to_string(row.avm_alu_div_u16_r6) << "," - << field_to_string(row.avm_alu_div_u16_r7) << "," << field_to_string(row.avm_alu_divisor_hi) << "," - << field_to_string(row.avm_alu_divisor_lo) << "," << field_to_string(row.avm_alu_ff_tag) << "," - << field_to_string(row.avm_alu_ia) << "," << field_to_string(row.avm_alu_ib) << "," - << field_to_string(row.avm_alu_ic) << "," << field_to_string(row.avm_alu_in_tag) << "," - << field_to_string(row.avm_alu_op_add) << "," << field_to_string(row.avm_alu_op_cast) << "," - << field_to_string(row.avm_alu_op_cast_prev) << "," << field_to_string(row.avm_alu_op_div) << "," - << field_to_string(row.avm_alu_op_div_a_lt_b) << "," << field_to_string(row.avm_alu_op_div_std) << "," - << field_to_string(row.avm_alu_op_eq) << "," << field_to_string(row.avm_alu_op_eq_diff_inv) << "," - << field_to_string(row.avm_alu_op_lt) << "," << field_to_string(row.avm_alu_op_lte) << "," - << field_to_string(row.avm_alu_op_mul) << "," << field_to_string(row.avm_alu_op_not) << "," - << field_to_string(row.avm_alu_op_shl) << "," << field_to_string(row.avm_alu_op_shr) << "," - << field_to_string(row.avm_alu_op_sub) << "," << field_to_string(row.avm_alu_p_a_borrow) << "," - << field_to_string(row.avm_alu_p_b_borrow) << "," << field_to_string(row.avm_alu_p_sub_a_hi) << "," - << field_to_string(row.avm_alu_p_sub_a_lo) << "," << field_to_string(row.avm_alu_p_sub_b_hi) << "," - << field_to_string(row.avm_alu_p_sub_b_lo) << "," << field_to_string(row.avm_alu_partial_prod_hi) << "," - << field_to_string(row.avm_alu_partial_prod_lo) << "," << field_to_string(row.avm_alu_quotient_hi) << "," - << field_to_string(row.avm_alu_quotient_lo) << "," << field_to_string(row.avm_alu_remainder) << "," - << field_to_string(row.avm_alu_res_hi) << "," << field_to_string(row.avm_alu_res_lo) << "," - << field_to_string(row.avm_alu_rng_chk_lookup_selector) << "," << field_to_string(row.avm_alu_rng_chk_sel) - << "," << field_to_string(row.avm_alu_shift_lt_bit_len) << "," << field_to_string(row.avm_alu_shift_sel) - << "," << field_to_string(row.avm_alu_t_sub_s_bits) << "," << field_to_string(row.avm_alu_two_pow_s) << "," - << field_to_string(row.avm_alu_two_pow_t_sub_s) << "," << field_to_string(row.avm_alu_u128_tag) << "," - << field_to_string(row.avm_alu_u16_r0) << "," << field_to_string(row.avm_alu_u16_r1) << "," - << field_to_string(row.avm_alu_u16_r10) << "," << field_to_string(row.avm_alu_u16_r11) << "," - << field_to_string(row.avm_alu_u16_r12) << "," << field_to_string(row.avm_alu_u16_r13) << "," - << field_to_string(row.avm_alu_u16_r14) << "," << field_to_string(row.avm_alu_u16_r2) << "," - << field_to_string(row.avm_alu_u16_r3) << "," << field_to_string(row.avm_alu_u16_r4) << "," - << field_to_string(row.avm_alu_u16_r5) << "," << field_to_string(row.avm_alu_u16_r6) << "," - << field_to_string(row.avm_alu_u16_r7) << "," << field_to_string(row.avm_alu_u16_r8) << "," - << field_to_string(row.avm_alu_u16_r9) << "," << field_to_string(row.avm_alu_u16_tag) << "," - << field_to_string(row.avm_alu_u32_tag) << "," << field_to_string(row.avm_alu_u64_tag) << "," - << field_to_string(row.avm_alu_u8_r0) << "," << field_to_string(row.avm_alu_u8_r1) << "," - << field_to_string(row.avm_alu_u8_tag) << "," << field_to_string(row.avm_binary_acc_ia) << "," - << field_to_string(row.avm_binary_acc_ib) << "," << field_to_string(row.avm_binary_acc_ic) << "," - << field_to_string(row.avm_binary_bin_sel) << "," << field_to_string(row.avm_binary_clk) << "," - << field_to_string(row.avm_binary_ia_bytes) << "," << field_to_string(row.avm_binary_ib_bytes) << "," - << field_to_string(row.avm_binary_ic_bytes) << "," << field_to_string(row.avm_binary_in_tag) << "," - << field_to_string(row.avm_binary_mem_tag_ctr) << "," << field_to_string(row.avm_binary_mem_tag_ctr_inv) - << "," << field_to_string(row.avm_binary_op_id) << "," << field_to_string(row.avm_binary_start) << "," - << field_to_string(row.avm_byte_lookup_bin_sel) << "," - << field_to_string(row.avm_byte_lookup_table_byte_lengths) << "," - << field_to_string(row.avm_byte_lookup_table_in_tags) << "," - << field_to_string(row.avm_byte_lookup_table_input_a) << "," - << field_to_string(row.avm_byte_lookup_table_input_b) << "," - << field_to_string(row.avm_byte_lookup_table_op_id) << "," - << field_to_string(row.avm_byte_lookup_table_output) << "," << field_to_string(row.avm_conversion_clk) << "," - << field_to_string(row.avm_conversion_input) << "," << field_to_string(row.avm_conversion_num_limbs) << "," - << field_to_string(row.avm_conversion_radix) << "," << field_to_string(row.avm_conversion_to_radix_le_sel) - << "," << field_to_string(row.avm_gas_da_gas_fixed_table) << "," << field_to_string(row.avm_gas_gas_cost_sel) - << "," << field_to_string(row.avm_gas_l2_gas_fixed_table) << "," << field_to_string(row.avm_keccakf1600_clk) - << "," << field_to_string(row.avm_keccakf1600_input) << "," - << field_to_string(row.avm_keccakf1600_keccakf1600_sel) << "," << field_to_string(row.avm_keccakf1600_output) - << "," << field_to_string(row.avm_kernel_emit_l2_to_l1_msg_write_offset) << "," - << field_to_string(row.avm_kernel_emit_note_hash_write_offset) << "," - << field_to_string(row.avm_kernel_emit_nullifier_write_offset) << "," - << field_to_string(row.avm_kernel_emit_unencrypted_log_write_offset) << "," - << field_to_string(row.avm_kernel_kernel_in_offset) << "," << field_to_string(row.avm_kernel_kernel_inputs) - << "," << field_to_string(row.avm_kernel_kernel_metadata_out) << "," - << field_to_string(row.avm_kernel_kernel_out_offset) << "," - << field_to_string(row.avm_kernel_kernel_side_effect_out) << "," - << field_to_string(row.avm_kernel_kernel_value_out) << "," - << field_to_string(row.avm_kernel_l1_to_l2_msg_exists_write_offset) << "," - << field_to_string(row.avm_kernel_note_hash_exist_write_offset) << "," - << field_to_string(row.avm_kernel_nullifier_exists_write_offset) << "," - << field_to_string(row.avm_kernel_nullifier_non_exists_write_offset) << "," - << field_to_string(row.avm_kernel_q_public_input_kernel_add_to_table) << "," - << field_to_string(row.avm_kernel_q_public_input_kernel_out_add_to_table) << "," - << field_to_string(row.avm_kernel_side_effect_counter) << "," - << field_to_string(row.avm_kernel_sload_write_offset) << "," - << field_to_string(row.avm_kernel_sstore_write_offset) << "," - << field_to_string(row.avm_main_abs_da_rem_gas_hi) << "," << field_to_string(row.avm_main_abs_da_rem_gas_lo) - << "," << field_to_string(row.avm_main_abs_l2_rem_gas_hi) << "," - << field_to_string(row.avm_main_abs_l2_rem_gas_lo) << "," << field_to_string(row.avm_main_alu_in_tag) << "," - << field_to_string(row.avm_main_alu_sel) << "," << field_to_string(row.avm_main_bin_op_id) << "," - << field_to_string(row.avm_main_bin_sel) << "," << field_to_string(row.avm_main_call_ptr) << "," - << field_to_string(row.avm_main_da_gas_op) << "," << field_to_string(row.avm_main_da_gas_remaining) << "," - << field_to_string(row.avm_main_da_out_of_gas) << "," << field_to_string(row.avm_main_gas_cost_active) << "," - << field_to_string(row.avm_main_ia) << "," << field_to_string(row.avm_main_ib) << "," - << field_to_string(row.avm_main_ic) << "," << field_to_string(row.avm_main_id) << "," - << field_to_string(row.avm_main_id_zero) << "," << field_to_string(row.avm_main_ind_a) << "," - << field_to_string(row.avm_main_ind_b) << "," << field_to_string(row.avm_main_ind_c) << "," - << field_to_string(row.avm_main_ind_d) << "," << field_to_string(row.avm_main_ind_op_a) << "," - << field_to_string(row.avm_main_ind_op_b) << "," << field_to_string(row.avm_main_ind_op_c) << "," - << field_to_string(row.avm_main_ind_op_d) << "," << field_to_string(row.avm_main_internal_return_ptr) << "," - << field_to_string(row.avm_main_inv) << "," << field_to_string(row.avm_main_l2_gas_op) << "," - << field_to_string(row.avm_main_l2_gas_remaining) << "," << field_to_string(row.avm_main_l2_out_of_gas) - << "," << field_to_string(row.avm_main_last) << "," << field_to_string(row.avm_main_mem_idx_a) << "," - << field_to_string(row.avm_main_mem_idx_b) << "," << field_to_string(row.avm_main_mem_idx_c) << "," - << field_to_string(row.avm_main_mem_idx_d) << "," << field_to_string(row.avm_main_mem_op_a) << "," - << field_to_string(row.avm_main_mem_op_activate_gas) << "," << field_to_string(row.avm_main_mem_op_b) << "," - << field_to_string(row.avm_main_mem_op_c) << "," << field_to_string(row.avm_main_mem_op_d) << "," - << field_to_string(row.avm_main_op_err) << "," << field_to_string(row.avm_main_opcode_val) << "," - << field_to_string(row.avm_main_pc) << "," << field_to_string(row.avm_main_q_kernel_lookup) << "," - << field_to_string(row.avm_main_q_kernel_output_lookup) << "," << field_to_string(row.avm_main_r_in_tag) - << "," << field_to_string(row.avm_main_rwa) << "," << field_to_string(row.avm_main_rwb) << "," - << field_to_string(row.avm_main_rwc) << "," << field_to_string(row.avm_main_rwd) << "," - << field_to_string(row.avm_main_sel_cmov) << "," << field_to_string(row.avm_main_sel_external_call) << "," - << field_to_string(row.avm_main_sel_halt) << "," << field_to_string(row.avm_main_sel_internal_call) << "," - << field_to_string(row.avm_main_sel_internal_return) << "," << field_to_string(row.avm_main_sel_jump) << "," - << field_to_string(row.avm_main_sel_jumpi) << "," << field_to_string(row.avm_main_sel_mov) << "," - << field_to_string(row.avm_main_sel_mov_a) << "," << field_to_string(row.avm_main_sel_mov_b) << "," - << field_to_string(row.avm_main_sel_op_add) << "," << field_to_string(row.avm_main_sel_op_address) << "," - << field_to_string(row.avm_main_sel_op_and) << "," << field_to_string(row.avm_main_sel_op_block_number) - << "," << field_to_string(row.avm_main_sel_op_cast) << "," << field_to_string(row.avm_main_sel_op_chain_id) - << "," << field_to_string(row.avm_main_sel_op_coinbase) << "," - << field_to_string(row.avm_main_sel_op_dagasleft) << "," << field_to_string(row.avm_main_sel_op_div) << "," - << field_to_string(row.avm_main_sel_op_emit_l2_to_l1_msg) << "," - << field_to_string(row.avm_main_sel_op_emit_note_hash) << "," - << field_to_string(row.avm_main_sel_op_emit_nullifier) << "," - << field_to_string(row.avm_main_sel_op_emit_unencrypted_log) << "," - << field_to_string(row.avm_main_sel_op_eq) << "," << field_to_string(row.avm_main_sel_op_fdiv) << "," - << field_to_string(row.avm_main_sel_op_fee_per_da_gas) << "," - << field_to_string(row.avm_main_sel_op_fee_per_l2_gas) << "," - << field_to_string(row.avm_main_sel_op_get_contract_instance) << "," - << field_to_string(row.avm_main_sel_op_keccak) << "," - << field_to_string(row.avm_main_sel_op_l1_to_l2_msg_exists) << "," - << field_to_string(row.avm_main_sel_op_l2gasleft) << "," << field_to_string(row.avm_main_sel_op_lt) << "," - << field_to_string(row.avm_main_sel_op_lte) << "," << field_to_string(row.avm_main_sel_op_mul) << "," - << field_to_string(row.avm_main_sel_op_not) << "," << field_to_string(row.avm_main_sel_op_note_hash_exists) - << "," << field_to_string(row.avm_main_sel_op_nullifier_exists) << "," - << field_to_string(row.avm_main_sel_op_or) << "," << field_to_string(row.avm_main_sel_op_pedersen) << "," - << field_to_string(row.avm_main_sel_op_poseidon2) << "," << field_to_string(row.avm_main_sel_op_radix_le) - << "," << field_to_string(row.avm_main_sel_op_sender) << "," << field_to_string(row.avm_main_sel_op_sha256) - << "," << field_to_string(row.avm_main_sel_op_shl) << "," << field_to_string(row.avm_main_sel_op_shr) << "," - << field_to_string(row.avm_main_sel_op_sload) << "," << field_to_string(row.avm_main_sel_op_sstore) << "," - << field_to_string(row.avm_main_sel_op_storage_address) << "," << field_to_string(row.avm_main_sel_op_sub) - << "," << field_to_string(row.avm_main_sel_op_timestamp) << "," - << field_to_string(row.avm_main_sel_op_transaction_fee) << "," - << field_to_string(row.avm_main_sel_op_version) << "," << field_to_string(row.avm_main_sel_op_xor) << "," - << field_to_string(row.avm_main_sel_rng_16) << "," << field_to_string(row.avm_main_sel_rng_8) << "," - << field_to_string(row.avm_main_space_id) << "," << field_to_string(row.avm_main_table_pow_2) << "," - << field_to_string(row.avm_main_tag_err) << "," << field_to_string(row.avm_main_w_in_tag) << "," - << field_to_string(row.avm_mem_addr) << "," << field_to_string(row.avm_mem_clk) << "," - << field_to_string(row.avm_mem_diff_hi) << "," << field_to_string(row.avm_mem_diff_lo) << "," - << field_to_string(row.avm_mem_diff_mid) << "," << field_to_string(row.avm_mem_glob_addr) << "," - << field_to_string(row.avm_mem_ind_op_a) << "," << field_to_string(row.avm_mem_ind_op_b) << "," - << field_to_string(row.avm_mem_ind_op_c) << "," << field_to_string(row.avm_mem_ind_op_d) << "," - << field_to_string(row.avm_mem_last) << "," << field_to_string(row.avm_mem_lastAccess) << "," - << field_to_string(row.avm_mem_mem_sel) << "," << field_to_string(row.avm_mem_one_min_inv) << "," - << field_to_string(row.avm_mem_op_a) << "," << field_to_string(row.avm_mem_op_b) << "," - << field_to_string(row.avm_mem_op_c) << "," << field_to_string(row.avm_mem_op_d) << "," - << field_to_string(row.avm_mem_r_in_tag) << "," << field_to_string(row.avm_mem_rng_chk_sel) << "," - << field_to_string(row.avm_mem_rw) << "," << field_to_string(row.avm_mem_sel_cmov) << "," - << field_to_string(row.avm_mem_sel_mov_a) << "," << field_to_string(row.avm_mem_sel_mov_b) << "," - << field_to_string(row.avm_mem_skip_check_tag) << "," << field_to_string(row.avm_mem_space_id) << "," - << field_to_string(row.avm_mem_tag) << "," << field_to_string(row.avm_mem_tag_err) << "," - << field_to_string(row.avm_mem_tsp) << "," << field_to_string(row.avm_mem_val) << "," - << field_to_string(row.avm_mem_w_in_tag) << "," << field_to_string(row.avm_pedersen_clk) << "," - << field_to_string(row.avm_pedersen_input) << "," << field_to_string(row.avm_pedersen_output) << "," - << field_to_string(row.avm_pedersen_pedersen_sel) << "," << field_to_string(row.avm_poseidon2_clk) << "," - << field_to_string(row.avm_poseidon2_input) << "," << field_to_string(row.avm_poseidon2_output) << "," - << field_to_string(row.avm_poseidon2_poseidon_perm_sel) << "," << field_to_string(row.avm_sha256_clk) << "," - << field_to_string(row.avm_sha256_input) << "," << field_to_string(row.avm_sha256_output) << "," - << field_to_string(row.avm_sha256_sha256_compression_sel) << "," << field_to_string(row.avm_sha256_state) - << "," << field_to_string(row.perm_main_alu) << "," << field_to_string(row.perm_main_bin) << "," + << field_to_string(row.main_clk) << "," << field_to_string(row.main_sel_first) << "," + << field_to_string(row.alu_a_hi) << "," << field_to_string(row.alu_a_lo) << "," + << field_to_string(row.alu_b_hi) << "," << field_to_string(row.alu_b_lo) << "," + << field_to_string(row.alu_borrow) << "," << field_to_string(row.alu_cf) << "," + << field_to_string(row.alu_clk) << "," << field_to_string(row.alu_cmp_rng_ctr) << "," + << field_to_string(row.alu_div_u16_r0) << "," << field_to_string(row.alu_div_u16_r1) << "," + << field_to_string(row.alu_div_u16_r2) << "," << field_to_string(row.alu_div_u16_r3) << "," + << field_to_string(row.alu_div_u16_r4) << "," << field_to_string(row.alu_div_u16_r5) << "," + << field_to_string(row.alu_div_u16_r6) << "," << field_to_string(row.alu_div_u16_r7) << "," + << field_to_string(row.alu_divisor_hi) << "," << field_to_string(row.alu_divisor_lo) << "," + << field_to_string(row.alu_ff_tag) << "," << field_to_string(row.alu_ia) << "," + << field_to_string(row.alu_ib) << "," << field_to_string(row.alu_ic) << "," + << field_to_string(row.alu_in_tag) << "," << field_to_string(row.alu_op_add) << "," + << field_to_string(row.alu_op_cast) << "," << field_to_string(row.alu_op_cast_prev) << "," + << field_to_string(row.alu_op_div) << "," << field_to_string(row.alu_op_div_a_lt_b) << "," + << field_to_string(row.alu_op_div_std) << "," << field_to_string(row.alu_op_eq) << "," + << field_to_string(row.alu_op_eq_diff_inv) << "," << field_to_string(row.alu_op_lt) << "," + << field_to_string(row.alu_op_lte) << "," << field_to_string(row.alu_op_mul) << "," + << field_to_string(row.alu_op_not) << "," << field_to_string(row.alu_op_shl) << "," + << field_to_string(row.alu_op_shr) << "," << field_to_string(row.alu_op_sub) << "," + << field_to_string(row.alu_p_a_borrow) << "," << field_to_string(row.alu_p_b_borrow) << "," + << field_to_string(row.alu_p_sub_a_hi) << "," << field_to_string(row.alu_p_sub_a_lo) << "," + << field_to_string(row.alu_p_sub_b_hi) << "," << field_to_string(row.alu_p_sub_b_lo) << "," + << field_to_string(row.alu_partial_prod_hi) << "," << field_to_string(row.alu_partial_prod_lo) << "," + << field_to_string(row.alu_quotient_hi) << "," << field_to_string(row.alu_quotient_lo) << "," + << field_to_string(row.alu_remainder) << "," << field_to_string(row.alu_res_hi) << "," + << field_to_string(row.alu_res_lo) << "," << field_to_string(row.alu_sel_alu) << "," + << field_to_string(row.alu_sel_cmp) << "," << field_to_string(row.alu_sel_div_rng_chk) << "," + << field_to_string(row.alu_sel_rng_chk) << "," << field_to_string(row.alu_sel_rng_chk_lookup) << "," + << field_to_string(row.alu_sel_shift_which) << "," << field_to_string(row.alu_shift_lt_bit_len) << "," + << field_to_string(row.alu_t_sub_s_bits) << "," << field_to_string(row.alu_two_pow_s) << "," + << field_to_string(row.alu_two_pow_t_sub_s) << "," << field_to_string(row.alu_u128_tag) << "," + << field_to_string(row.alu_u16_r0) << "," << field_to_string(row.alu_u16_r1) << "," + << field_to_string(row.alu_u16_r10) << "," << field_to_string(row.alu_u16_r11) << "," + << field_to_string(row.alu_u16_r12) << "," << field_to_string(row.alu_u16_r13) << "," + << field_to_string(row.alu_u16_r14) << "," << field_to_string(row.alu_u16_r2) << "," + << field_to_string(row.alu_u16_r3) << "," << field_to_string(row.alu_u16_r4) << "," + << field_to_string(row.alu_u16_r5) << "," << field_to_string(row.alu_u16_r6) << "," + << field_to_string(row.alu_u16_r7) << "," << field_to_string(row.alu_u16_r8) << "," + << field_to_string(row.alu_u16_r9) << "," << field_to_string(row.alu_u16_tag) << "," + << field_to_string(row.alu_u32_tag) << "," << field_to_string(row.alu_u64_tag) << "," + << field_to_string(row.alu_u8_r0) << "," << field_to_string(row.alu_u8_r1) << "," + << field_to_string(row.alu_u8_tag) << "," << field_to_string(row.binary_acc_ia) << "," + << field_to_string(row.binary_acc_ib) << "," << field_to_string(row.binary_acc_ic) << "," + << field_to_string(row.binary_clk) << "," << field_to_string(row.binary_ia_bytes) << "," + << field_to_string(row.binary_ib_bytes) << "," << field_to_string(row.binary_ic_bytes) << "," + << field_to_string(row.binary_in_tag) << "," << field_to_string(row.binary_mem_tag_ctr) << "," + << field_to_string(row.binary_mem_tag_ctr_inv) << "," << field_to_string(row.binary_op_id) << "," + << field_to_string(row.binary_sel_bin) << "," << field_to_string(row.binary_start) << "," + << field_to_string(row.byte_lookup_sel_bin) << "," << field_to_string(row.byte_lookup_table_byte_lengths) + << "," << field_to_string(row.byte_lookup_table_in_tags) << "," + << field_to_string(row.byte_lookup_table_input_a) << "," << field_to_string(row.byte_lookup_table_input_b) + << "," << field_to_string(row.byte_lookup_table_op_id) << "," + << field_to_string(row.byte_lookup_table_output) << "," << field_to_string(row.conversion_clk) << "," + << field_to_string(row.conversion_input) << "," << field_to_string(row.conversion_num_limbs) << "," + << field_to_string(row.conversion_radix) << "," << field_to_string(row.conversion_sel_to_radix_le) << "," + << field_to_string(row.gas_da_gas_fixed_table) << "," << field_to_string(row.gas_l2_gas_fixed_table) << "," + << field_to_string(row.gas_sel_gas_cost) << "," << field_to_string(row.keccakf1600_clk) << "," + << field_to_string(row.keccakf1600_input) << "," << field_to_string(row.keccakf1600_output) << "," + << field_to_string(row.keccakf1600_sel_keccakf1600) << "," + << field_to_string(row.kernel_emit_l2_to_l1_msg_write_offset) << "," + << field_to_string(row.kernel_emit_note_hash_write_offset) << "," + << field_to_string(row.kernel_emit_nullifier_write_offset) << "," + << field_to_string(row.kernel_emit_unencrypted_log_write_offset) << "," + << field_to_string(row.kernel_kernel_in_offset) << "," << field_to_string(row.kernel_kernel_inputs) << "," + << field_to_string(row.kernel_kernel_metadata_out) << "," << field_to_string(row.kernel_kernel_out_offset) + << "," << field_to_string(row.kernel_kernel_side_effect_out) << "," + << field_to_string(row.kernel_kernel_value_out) << "," + << field_to_string(row.kernel_l1_to_l2_msg_exists_write_offset) << "," + << field_to_string(row.kernel_note_hash_exist_write_offset) << "," + << field_to_string(row.kernel_nullifier_exists_write_offset) << "," + << field_to_string(row.kernel_nullifier_non_exists_write_offset) << "," + << field_to_string(row.kernel_q_public_input_kernel_add_to_table) << "," + << field_to_string(row.kernel_q_public_input_kernel_out_add_to_table) << "," + << field_to_string(row.kernel_side_effect_counter) << "," << field_to_string(row.kernel_sload_write_offset) + << "," << field_to_string(row.kernel_sstore_write_offset) << "," + << field_to_string(row.main_abs_da_rem_gas_hi) << "," << field_to_string(row.main_abs_da_rem_gas_lo) << "," + << field_to_string(row.main_abs_l2_rem_gas_hi) << "," << field_to_string(row.main_abs_l2_rem_gas_lo) << "," + << field_to_string(row.main_alu_in_tag) << "," << field_to_string(row.main_bin_op_id) << "," + << field_to_string(row.main_call_ptr) << "," << field_to_string(row.main_da_gas_op_cost) << "," + << field_to_string(row.main_da_gas_remaining) << "," << field_to_string(row.main_da_out_of_gas) << "," + << field_to_string(row.main_ia) << "," << field_to_string(row.main_ib) << "," << field_to_string(row.main_ic) + << "," << field_to_string(row.main_id) << "," << field_to_string(row.main_id_zero) << "," + << field_to_string(row.main_ind_addr_a) << "," << field_to_string(row.main_ind_addr_b) << "," + << field_to_string(row.main_ind_addr_c) << "," << field_to_string(row.main_ind_addr_d) << "," + << field_to_string(row.main_internal_return_ptr) << "," << field_to_string(row.main_inv) << "," + << field_to_string(row.main_l2_gas_op_cost) << "," << field_to_string(row.main_l2_gas_remaining) << "," + << field_to_string(row.main_l2_out_of_gas) << "," << field_to_string(row.main_mem_addr_a) << "," + << field_to_string(row.main_mem_addr_b) << "," << field_to_string(row.main_mem_addr_c) << "," + << field_to_string(row.main_mem_addr_d) << "," << field_to_string(row.main_op_err) << "," + << field_to_string(row.main_opcode_val) << "," << field_to_string(row.main_pc) << "," + << field_to_string(row.main_r_in_tag) << "," << field_to_string(row.main_rwa) << "," + << field_to_string(row.main_rwb) << "," << field_to_string(row.main_rwc) << "," + << field_to_string(row.main_rwd) << "," << field_to_string(row.main_sel_alu) << "," + << field_to_string(row.main_sel_bin) << "," << field_to_string(row.main_sel_gas_accounting_active) << "," + << field_to_string(row.main_sel_last) << "," << field_to_string(row.main_sel_mem_op_a) << "," + << field_to_string(row.main_sel_mem_op_activate_gas) << "," << field_to_string(row.main_sel_mem_op_b) << "," + << field_to_string(row.main_sel_mem_op_c) << "," << field_to_string(row.main_sel_mem_op_d) << "," + << field_to_string(row.main_sel_mov_ia_to_ic) << "," << field_to_string(row.main_sel_mov_ib_to_ic) << "," + << field_to_string(row.main_sel_op_add) << "," << field_to_string(row.main_sel_op_address) << "," + << field_to_string(row.main_sel_op_and) << "," << field_to_string(row.main_sel_op_block_number) << "," + << field_to_string(row.main_sel_op_cast) << "," << field_to_string(row.main_sel_op_chain_id) << "," + << field_to_string(row.main_sel_op_cmov) << "," << field_to_string(row.main_sel_op_coinbase) << "," + << field_to_string(row.main_sel_op_dagasleft) << "," << field_to_string(row.main_sel_op_div) << "," + << field_to_string(row.main_sel_op_emit_l2_to_l1_msg) << "," + << field_to_string(row.main_sel_op_emit_note_hash) << "," << field_to_string(row.main_sel_op_emit_nullifier) + << "," << field_to_string(row.main_sel_op_emit_unencrypted_log) << "," << field_to_string(row.main_sel_op_eq) + << "," << field_to_string(row.main_sel_op_external_call) << "," << field_to_string(row.main_sel_op_fdiv) + << "," << field_to_string(row.main_sel_op_fee_per_da_gas) << "," + << field_to_string(row.main_sel_op_fee_per_l2_gas) << "," + << field_to_string(row.main_sel_op_get_contract_instance) << "," << field_to_string(row.main_sel_op_halt) + << "," << field_to_string(row.main_sel_op_internal_call) << "," + << field_to_string(row.main_sel_op_internal_return) << "," << field_to_string(row.main_sel_op_jump) << "," + << field_to_string(row.main_sel_op_jumpi) << "," << field_to_string(row.main_sel_op_keccak) << "," + << field_to_string(row.main_sel_op_l1_to_l2_msg_exists) << "," << field_to_string(row.main_sel_op_l2gasleft) + << "," << field_to_string(row.main_sel_op_lt) << "," << field_to_string(row.main_sel_op_lte) << "," + << field_to_string(row.main_sel_op_mov) << "," << field_to_string(row.main_sel_op_mul) << "," + << field_to_string(row.main_sel_op_not) << "," << field_to_string(row.main_sel_op_note_hash_exists) << "," + << field_to_string(row.main_sel_op_nullifier_exists) << "," << field_to_string(row.main_sel_op_or) << "," + << field_to_string(row.main_sel_op_pedersen) << "," << field_to_string(row.main_sel_op_poseidon2) << "," + << field_to_string(row.main_sel_op_radix_le) << "," << field_to_string(row.main_sel_op_sender) << "," + << field_to_string(row.main_sel_op_sha256) << "," << field_to_string(row.main_sel_op_shl) << "," + << field_to_string(row.main_sel_op_shr) << "," << field_to_string(row.main_sel_op_sload) << "," + << field_to_string(row.main_sel_op_sstore) << "," << field_to_string(row.main_sel_op_storage_address) << "," + << field_to_string(row.main_sel_op_sub) << "," << field_to_string(row.main_sel_op_timestamp) << "," + << field_to_string(row.main_sel_op_transaction_fee) << "," << field_to_string(row.main_sel_op_version) << "," + << field_to_string(row.main_sel_op_xor) << "," << field_to_string(row.main_sel_q_kernel_lookup) << "," + << field_to_string(row.main_sel_q_kernel_output_lookup) << "," + << field_to_string(row.main_sel_resolve_ind_addr_a) << "," + << field_to_string(row.main_sel_resolve_ind_addr_b) << "," + << field_to_string(row.main_sel_resolve_ind_addr_c) << "," + << field_to_string(row.main_sel_resolve_ind_addr_d) << "," << field_to_string(row.main_sel_rng_16) << "," + << field_to_string(row.main_sel_rng_8) << "," << field_to_string(row.main_space_id) << "," + << field_to_string(row.main_table_pow_2) << "," << field_to_string(row.main_tag_err) << "," + << field_to_string(row.main_w_in_tag) << "," << field_to_string(row.mem_addr) << "," + << field_to_string(row.mem_clk) << "," << field_to_string(row.mem_diff_hi) << "," + << field_to_string(row.mem_diff_lo) << "," << field_to_string(row.mem_diff_mid) << "," + << field_to_string(row.mem_glob_addr) << "," << field_to_string(row.mem_last) << "," + << field_to_string(row.mem_lastAccess) << "," << field_to_string(row.mem_one_min_inv) << "," + << field_to_string(row.mem_r_in_tag) << "," << field_to_string(row.mem_rw) << "," + << field_to_string(row.mem_sel_mem) << "," << field_to_string(row.mem_sel_mov_ia_to_ic) << "," + << field_to_string(row.mem_sel_mov_ib_to_ic) << "," << field_to_string(row.mem_sel_op_a) << "," + << field_to_string(row.mem_sel_op_b) << "," << field_to_string(row.mem_sel_op_c) << "," + << field_to_string(row.mem_sel_op_cmov) << "," << field_to_string(row.mem_sel_op_d) << "," + << field_to_string(row.mem_sel_resolve_ind_addr_a) << "," << field_to_string(row.mem_sel_resolve_ind_addr_b) + << "," << field_to_string(row.mem_sel_resolve_ind_addr_c) << "," + << field_to_string(row.mem_sel_resolve_ind_addr_d) << "," << field_to_string(row.mem_sel_rng_chk) << "," + << field_to_string(row.mem_skip_check_tag) << "," << field_to_string(row.mem_space_id) << "," + << field_to_string(row.mem_tag) << "," << field_to_string(row.mem_tag_err) << "," + << field_to_string(row.mem_tsp) << "," << field_to_string(row.mem_val) << "," + << field_to_string(row.mem_w_in_tag) << "," << field_to_string(row.pedersen_clk) << "," + << field_to_string(row.pedersen_input) << "," << field_to_string(row.pedersen_output) << "," + << field_to_string(row.pedersen_sel_pedersen) << "," << field_to_string(row.poseidon2_clk) << "," + << field_to_string(row.poseidon2_input) << "," << field_to_string(row.poseidon2_output) << "," + << field_to_string(row.poseidon2_sel_poseidon_perm) << "," << field_to_string(row.sha256_clk) << "," + << field_to_string(row.sha256_input) << "," << field_to_string(row.sha256_output) << "," + << field_to_string(row.sha256_sel_sha256_compression) << "," << field_to_string(row.sha256_state) << "," + << field_to_string(row.perm_main_alu) << "," << field_to_string(row.perm_main_bin) << "," << field_to_string(row.perm_main_conv) << "," << field_to_string(row.perm_main_pos2_perm) << "," << field_to_string(row.perm_main_pedersen) << "," << field_to_string(row.perm_main_mem_a) << "," << field_to_string(row.perm_main_mem_b) << "," << field_to_string(row.perm_main_mem_c) << "," - << field_to_string(row.perm_main_mem_d) << "," << field_to_string(row.perm_main_mem_ind_a) << "," - << field_to_string(row.perm_main_mem_ind_b) << "," << field_to_string(row.perm_main_mem_ind_c) << "," - << field_to_string(row.perm_main_mem_ind_d) << "," << field_to_string(row.lookup_byte_lengths) << "," - << field_to_string(row.lookup_byte_operations) << "," << field_to_string(row.lookup_opcode_gas) << "," + << field_to_string(row.perm_main_mem_d) << "," << field_to_string(row.perm_main_mem_ind_addr_a) << "," + << field_to_string(row.perm_main_mem_ind_addr_b) << "," << field_to_string(row.perm_main_mem_ind_addr_c) + << "," << field_to_string(row.perm_main_mem_ind_addr_d) << "," << field_to_string(row.lookup_byte_lengths) + << "," << field_to_string(row.lookup_byte_operations) << "," << field_to_string(row.lookup_opcode_gas) << "," << field_to_string(row.range_check_l2_gas_hi) << "," << field_to_string(row.range_check_l2_gas_lo) << "," << field_to_string(row.range_check_da_gas_hi) << "," << field_to_string(row.range_check_da_gas_lo) << "," << field_to_string(row.kernel_output_lookup) << "," << field_to_string(row.lookup_into_kernel) << "," diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp index a3a8b784711..83e3cd74b16 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp @@ -16,18 +16,13 @@ #include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" #include "barretenberg/stdlib_circuit_builders/circuit_builder_base.hpp" -#include "barretenberg/relations/generated/avm/avm_alu.hpp" -#include "barretenberg/relations/generated/avm/avm_binary.hpp" -#include "barretenberg/relations/generated/avm/avm_conversion.hpp" -#include "barretenberg/relations/generated/avm/avm_keccakf1600.hpp" -#include "barretenberg/relations/generated/avm/avm_kernel.hpp" -#include "barretenberg/relations/generated/avm/avm_main.hpp" -#include "barretenberg/relations/generated/avm/avm_mem.hpp" -#include "barretenberg/relations/generated/avm/avm_pedersen.hpp" -#include "barretenberg/relations/generated/avm/avm_poseidon2.hpp" -#include "barretenberg/relations/generated/avm/avm_sha256.hpp" +#include "barretenberg/relations/generated/avm/alu.hpp" +#include "barretenberg/relations/generated/avm/binary.hpp" +#include "barretenberg/relations/generated/avm/conversion.hpp" #include "barretenberg/relations/generated/avm/incl_main_tag_err.hpp" #include "barretenberg/relations/generated/avm/incl_mem_tag_err.hpp" +#include "barretenberg/relations/generated/avm/keccakf1600.hpp" +#include "barretenberg/relations/generated/avm/kernel.hpp" #include "barretenberg/relations/generated/avm/kernel_output_lookup.hpp" #include "barretenberg/relations/generated/avm/lookup_byte_lengths.hpp" #include "barretenberg/relations/generated/avm/lookup_byte_operations.hpp" @@ -63,6 +58,9 @@ #include "barretenberg/relations/generated/avm/lookup_u16_9.hpp" #include "barretenberg/relations/generated/avm/lookup_u8_0.hpp" #include "barretenberg/relations/generated/avm/lookup_u8_1.hpp" +#include "barretenberg/relations/generated/avm/main.hpp" +#include "barretenberg/relations/generated/avm/mem.hpp" +#include "barretenberg/relations/generated/avm/pedersen.hpp" #include "barretenberg/relations/generated/avm/perm_main_alu.hpp" #include "barretenberg/relations/generated/avm/perm_main_bin.hpp" #include "barretenberg/relations/generated/avm/perm_main_conv.hpp" @@ -70,311 +68,313 @@ #include "barretenberg/relations/generated/avm/perm_main_mem_b.hpp" #include "barretenberg/relations/generated/avm/perm_main_mem_c.hpp" #include "barretenberg/relations/generated/avm/perm_main_mem_d.hpp" -#include "barretenberg/relations/generated/avm/perm_main_mem_ind_a.hpp" -#include "barretenberg/relations/generated/avm/perm_main_mem_ind_b.hpp" -#include "barretenberg/relations/generated/avm/perm_main_mem_ind_c.hpp" -#include "barretenberg/relations/generated/avm/perm_main_mem_ind_d.hpp" +#include "barretenberg/relations/generated/avm/perm_main_mem_ind_addr_a.hpp" +#include "barretenberg/relations/generated/avm/perm_main_mem_ind_addr_b.hpp" +#include "barretenberg/relations/generated/avm/perm_main_mem_ind_addr_c.hpp" +#include "barretenberg/relations/generated/avm/perm_main_mem_ind_addr_d.hpp" #include "barretenberg/relations/generated/avm/perm_main_pedersen.hpp" #include "barretenberg/relations/generated/avm/perm_main_pos2_perm.hpp" +#include "barretenberg/relations/generated/avm/poseidon2.hpp" #include "barretenberg/relations/generated/avm/range_check_da_gas_hi.hpp" #include "barretenberg/relations/generated/avm/range_check_da_gas_lo.hpp" #include "barretenberg/relations/generated/avm/range_check_l2_gas_hi.hpp" #include "barretenberg/relations/generated/avm/range_check_l2_gas_lo.hpp" +#include "barretenberg/relations/generated/avm/sha256.hpp" #include "barretenberg/vm/generated/avm_flavor.hpp" namespace bb { template struct AvmFullRow { - FF avm_main_clk{}; - FF avm_main_first{}; - FF avm_alu_a_hi{}; - FF avm_alu_a_lo{}; - FF avm_alu_alu_sel{}; - FF avm_alu_b_hi{}; - FF avm_alu_b_lo{}; - FF avm_alu_borrow{}; - FF avm_alu_cf{}; - FF avm_alu_clk{}; - FF avm_alu_cmp_rng_ctr{}; - FF avm_alu_cmp_sel{}; - FF avm_alu_div_rng_chk_selector{}; - FF avm_alu_div_u16_r0{}; - FF avm_alu_div_u16_r1{}; - FF avm_alu_div_u16_r2{}; - FF avm_alu_div_u16_r3{}; - FF avm_alu_div_u16_r4{}; - FF avm_alu_div_u16_r5{}; - FF avm_alu_div_u16_r6{}; - FF avm_alu_div_u16_r7{}; - FF avm_alu_divisor_hi{}; - FF avm_alu_divisor_lo{}; - FF avm_alu_ff_tag{}; - FF avm_alu_ia{}; - FF avm_alu_ib{}; - FF avm_alu_ic{}; - FF avm_alu_in_tag{}; - FF avm_alu_op_add{}; - FF avm_alu_op_cast{}; - FF avm_alu_op_cast_prev{}; - FF avm_alu_op_div{}; - FF avm_alu_op_div_a_lt_b{}; - FF avm_alu_op_div_std{}; - FF avm_alu_op_eq{}; - FF avm_alu_op_eq_diff_inv{}; - FF avm_alu_op_lt{}; - FF avm_alu_op_lte{}; - FF avm_alu_op_mul{}; - FF avm_alu_op_not{}; - FF avm_alu_op_shl{}; - FF avm_alu_op_shr{}; - FF avm_alu_op_sub{}; - FF avm_alu_p_a_borrow{}; - FF avm_alu_p_b_borrow{}; - FF avm_alu_p_sub_a_hi{}; - FF avm_alu_p_sub_a_lo{}; - FF avm_alu_p_sub_b_hi{}; - FF avm_alu_p_sub_b_lo{}; - FF avm_alu_partial_prod_hi{}; - FF avm_alu_partial_prod_lo{}; - FF avm_alu_quotient_hi{}; - FF avm_alu_quotient_lo{}; - FF avm_alu_remainder{}; - FF avm_alu_res_hi{}; - FF avm_alu_res_lo{}; - FF avm_alu_rng_chk_lookup_selector{}; - FF avm_alu_rng_chk_sel{}; - FF avm_alu_shift_lt_bit_len{}; - FF avm_alu_shift_sel{}; - FF avm_alu_t_sub_s_bits{}; - FF avm_alu_two_pow_s{}; - FF avm_alu_two_pow_t_sub_s{}; - FF avm_alu_u128_tag{}; - FF avm_alu_u16_r0{}; - FF avm_alu_u16_r1{}; - FF avm_alu_u16_r10{}; - FF avm_alu_u16_r11{}; - FF avm_alu_u16_r12{}; - FF avm_alu_u16_r13{}; - FF avm_alu_u16_r14{}; - FF avm_alu_u16_r2{}; - FF avm_alu_u16_r3{}; - FF avm_alu_u16_r4{}; - FF avm_alu_u16_r5{}; - FF avm_alu_u16_r6{}; - FF avm_alu_u16_r7{}; - FF avm_alu_u16_r8{}; - FF avm_alu_u16_r9{}; - FF avm_alu_u16_tag{}; - FF avm_alu_u32_tag{}; - FF avm_alu_u64_tag{}; - FF avm_alu_u8_r0{}; - FF avm_alu_u8_r1{}; - FF avm_alu_u8_tag{}; - FF avm_binary_acc_ia{}; - FF avm_binary_acc_ib{}; - FF avm_binary_acc_ic{}; - FF avm_binary_bin_sel{}; - FF avm_binary_clk{}; - FF avm_binary_ia_bytes{}; - FF avm_binary_ib_bytes{}; - FF avm_binary_ic_bytes{}; - FF avm_binary_in_tag{}; - FF avm_binary_mem_tag_ctr{}; - FF avm_binary_mem_tag_ctr_inv{}; - FF avm_binary_op_id{}; - FF avm_binary_start{}; - FF avm_byte_lookup_bin_sel{}; - FF avm_byte_lookup_table_byte_lengths{}; - FF avm_byte_lookup_table_in_tags{}; - FF avm_byte_lookup_table_input_a{}; - FF avm_byte_lookup_table_input_b{}; - FF avm_byte_lookup_table_op_id{}; - FF avm_byte_lookup_table_output{}; - FF avm_conversion_clk{}; - FF avm_conversion_input{}; - FF avm_conversion_num_limbs{}; - FF avm_conversion_radix{}; - FF avm_conversion_to_radix_le_sel{}; - FF avm_gas_da_gas_fixed_table{}; - FF avm_gas_gas_cost_sel{}; - FF avm_gas_l2_gas_fixed_table{}; - FF avm_keccakf1600_clk{}; - FF avm_keccakf1600_input{}; - FF avm_keccakf1600_keccakf1600_sel{}; - FF avm_keccakf1600_output{}; - FF avm_kernel_emit_l2_to_l1_msg_write_offset{}; - FF avm_kernel_emit_note_hash_write_offset{}; - FF avm_kernel_emit_nullifier_write_offset{}; - FF avm_kernel_emit_unencrypted_log_write_offset{}; - FF avm_kernel_kernel_in_offset{}; - FF avm_kernel_kernel_inputs{}; - FF avm_kernel_kernel_metadata_out{}; - FF avm_kernel_kernel_out_offset{}; - FF avm_kernel_kernel_side_effect_out{}; - FF avm_kernel_kernel_value_out{}; - FF avm_kernel_l1_to_l2_msg_exists_write_offset{}; - FF avm_kernel_note_hash_exist_write_offset{}; - FF avm_kernel_nullifier_exists_write_offset{}; - FF avm_kernel_nullifier_non_exists_write_offset{}; - FF avm_kernel_q_public_input_kernel_add_to_table{}; - FF avm_kernel_q_public_input_kernel_out_add_to_table{}; - FF avm_kernel_side_effect_counter{}; - FF avm_kernel_sload_write_offset{}; - FF avm_kernel_sstore_write_offset{}; - FF avm_main_abs_da_rem_gas_hi{}; - FF avm_main_abs_da_rem_gas_lo{}; - FF avm_main_abs_l2_rem_gas_hi{}; - FF avm_main_abs_l2_rem_gas_lo{}; - FF avm_main_alu_in_tag{}; - FF avm_main_alu_sel{}; - FF avm_main_bin_op_id{}; - FF avm_main_bin_sel{}; - FF avm_main_call_ptr{}; - FF avm_main_da_gas_op{}; - FF avm_main_da_gas_remaining{}; - FF avm_main_da_out_of_gas{}; - FF avm_main_gas_cost_active{}; - FF avm_main_ia{}; - FF avm_main_ib{}; - FF avm_main_ic{}; - FF avm_main_id{}; - FF avm_main_id_zero{}; - FF avm_main_ind_a{}; - FF avm_main_ind_b{}; - FF avm_main_ind_c{}; - FF avm_main_ind_d{}; - FF avm_main_ind_op_a{}; - FF avm_main_ind_op_b{}; - FF avm_main_ind_op_c{}; - FF avm_main_ind_op_d{}; - FF avm_main_internal_return_ptr{}; - FF avm_main_inv{}; - FF avm_main_l2_gas_op{}; - FF avm_main_l2_gas_remaining{}; - FF avm_main_l2_out_of_gas{}; - FF avm_main_last{}; - FF avm_main_mem_idx_a{}; - FF avm_main_mem_idx_b{}; - FF avm_main_mem_idx_c{}; - FF avm_main_mem_idx_d{}; - FF avm_main_mem_op_a{}; - FF avm_main_mem_op_activate_gas{}; - FF avm_main_mem_op_b{}; - FF avm_main_mem_op_c{}; - FF avm_main_mem_op_d{}; - FF avm_main_op_err{}; - FF avm_main_opcode_val{}; - FF avm_main_pc{}; - FF avm_main_q_kernel_lookup{}; - FF avm_main_q_kernel_output_lookup{}; - FF avm_main_r_in_tag{}; - FF avm_main_rwa{}; - FF avm_main_rwb{}; - FF avm_main_rwc{}; - FF avm_main_rwd{}; - FF avm_main_sel_cmov{}; - FF avm_main_sel_external_call{}; - FF avm_main_sel_halt{}; - FF avm_main_sel_internal_call{}; - FF avm_main_sel_internal_return{}; - FF avm_main_sel_jump{}; - FF avm_main_sel_jumpi{}; - FF avm_main_sel_mov{}; - FF avm_main_sel_mov_a{}; - FF avm_main_sel_mov_b{}; - FF avm_main_sel_op_add{}; - FF avm_main_sel_op_address{}; - FF avm_main_sel_op_and{}; - FF avm_main_sel_op_block_number{}; - FF avm_main_sel_op_cast{}; - FF avm_main_sel_op_chain_id{}; - FF avm_main_sel_op_coinbase{}; - FF avm_main_sel_op_dagasleft{}; - FF avm_main_sel_op_div{}; - FF avm_main_sel_op_emit_l2_to_l1_msg{}; - FF avm_main_sel_op_emit_note_hash{}; - FF avm_main_sel_op_emit_nullifier{}; - FF avm_main_sel_op_emit_unencrypted_log{}; - FF avm_main_sel_op_eq{}; - FF avm_main_sel_op_fdiv{}; - FF avm_main_sel_op_fee_per_da_gas{}; - FF avm_main_sel_op_fee_per_l2_gas{}; - FF avm_main_sel_op_get_contract_instance{}; - FF avm_main_sel_op_keccak{}; - FF avm_main_sel_op_l1_to_l2_msg_exists{}; - FF avm_main_sel_op_l2gasleft{}; - FF avm_main_sel_op_lt{}; - FF avm_main_sel_op_lte{}; - FF avm_main_sel_op_mul{}; - FF avm_main_sel_op_not{}; - FF avm_main_sel_op_note_hash_exists{}; - FF avm_main_sel_op_nullifier_exists{}; - FF avm_main_sel_op_or{}; - FF avm_main_sel_op_pedersen{}; - FF avm_main_sel_op_poseidon2{}; - FF avm_main_sel_op_radix_le{}; - FF avm_main_sel_op_sender{}; - FF avm_main_sel_op_sha256{}; - FF avm_main_sel_op_shl{}; - FF avm_main_sel_op_shr{}; - FF avm_main_sel_op_sload{}; - FF avm_main_sel_op_sstore{}; - FF avm_main_sel_op_storage_address{}; - FF avm_main_sel_op_sub{}; - FF avm_main_sel_op_timestamp{}; - FF avm_main_sel_op_transaction_fee{}; - FF avm_main_sel_op_version{}; - FF avm_main_sel_op_xor{}; - FF avm_main_sel_rng_16{}; - FF avm_main_sel_rng_8{}; - FF avm_main_space_id{}; - FF avm_main_table_pow_2{}; - FF avm_main_tag_err{}; - FF avm_main_w_in_tag{}; - FF avm_mem_addr{}; - FF avm_mem_clk{}; - FF avm_mem_diff_hi{}; - FF avm_mem_diff_lo{}; - FF avm_mem_diff_mid{}; - FF avm_mem_glob_addr{}; - FF avm_mem_ind_op_a{}; - FF avm_mem_ind_op_b{}; - FF avm_mem_ind_op_c{}; - FF avm_mem_ind_op_d{}; - FF avm_mem_last{}; - FF avm_mem_lastAccess{}; - FF avm_mem_mem_sel{}; - FF avm_mem_one_min_inv{}; - FF avm_mem_op_a{}; - FF avm_mem_op_b{}; - FF avm_mem_op_c{}; - FF avm_mem_op_d{}; - FF avm_mem_r_in_tag{}; - FF avm_mem_rng_chk_sel{}; - FF avm_mem_rw{}; - FF avm_mem_sel_cmov{}; - FF avm_mem_sel_mov_a{}; - FF avm_mem_sel_mov_b{}; - FF avm_mem_skip_check_tag{}; - FF avm_mem_space_id{}; - FF avm_mem_tag{}; - FF avm_mem_tag_err{}; - FF avm_mem_tsp{}; - FF avm_mem_val{}; - FF avm_mem_w_in_tag{}; - FF avm_pedersen_clk{}; - FF avm_pedersen_input{}; - FF avm_pedersen_output{}; - FF avm_pedersen_pedersen_sel{}; - FF avm_poseidon2_clk{}; - FF avm_poseidon2_input{}; - FF avm_poseidon2_output{}; - FF avm_poseidon2_poseidon_perm_sel{}; - FF avm_sha256_clk{}; - FF avm_sha256_input{}; - FF avm_sha256_output{}; - FF avm_sha256_sha256_compression_sel{}; - FF avm_sha256_state{}; + FF main_clk{}; + FF main_sel_first{}; + FF alu_a_hi{}; + FF alu_a_lo{}; + FF alu_b_hi{}; + FF alu_b_lo{}; + FF alu_borrow{}; + FF alu_cf{}; + FF alu_clk{}; + FF alu_cmp_rng_ctr{}; + FF alu_div_u16_r0{}; + FF alu_div_u16_r1{}; + FF alu_div_u16_r2{}; + FF alu_div_u16_r3{}; + FF alu_div_u16_r4{}; + FF alu_div_u16_r5{}; + FF alu_div_u16_r6{}; + FF alu_div_u16_r7{}; + FF alu_divisor_hi{}; + FF alu_divisor_lo{}; + FF alu_ff_tag{}; + FF alu_ia{}; + FF alu_ib{}; + FF alu_ic{}; + FF alu_in_tag{}; + FF alu_op_add{}; + FF alu_op_cast{}; + FF alu_op_cast_prev{}; + FF alu_op_div{}; + FF alu_op_div_a_lt_b{}; + FF alu_op_div_std{}; + FF alu_op_eq{}; + FF alu_op_eq_diff_inv{}; + FF alu_op_lt{}; + FF alu_op_lte{}; + FF alu_op_mul{}; + FF alu_op_not{}; + FF alu_op_shl{}; + FF alu_op_shr{}; + FF alu_op_sub{}; + FF alu_p_a_borrow{}; + FF alu_p_b_borrow{}; + FF alu_p_sub_a_hi{}; + FF alu_p_sub_a_lo{}; + FF alu_p_sub_b_hi{}; + FF alu_p_sub_b_lo{}; + FF alu_partial_prod_hi{}; + FF alu_partial_prod_lo{}; + FF alu_quotient_hi{}; + FF alu_quotient_lo{}; + FF alu_remainder{}; + FF alu_res_hi{}; + FF alu_res_lo{}; + FF alu_sel_alu{}; + FF alu_sel_cmp{}; + FF alu_sel_div_rng_chk{}; + FF alu_sel_rng_chk{}; + FF alu_sel_rng_chk_lookup{}; + FF alu_sel_shift_which{}; + FF alu_shift_lt_bit_len{}; + FF alu_t_sub_s_bits{}; + FF alu_two_pow_s{}; + FF alu_two_pow_t_sub_s{}; + FF alu_u128_tag{}; + FF alu_u16_r0{}; + FF alu_u16_r1{}; + FF alu_u16_r10{}; + FF alu_u16_r11{}; + FF alu_u16_r12{}; + FF alu_u16_r13{}; + FF alu_u16_r14{}; + FF alu_u16_r2{}; + FF alu_u16_r3{}; + FF alu_u16_r4{}; + FF alu_u16_r5{}; + FF alu_u16_r6{}; + FF alu_u16_r7{}; + FF alu_u16_r8{}; + FF alu_u16_r9{}; + FF alu_u16_tag{}; + FF alu_u32_tag{}; + FF alu_u64_tag{}; + FF alu_u8_r0{}; + FF alu_u8_r1{}; + FF alu_u8_tag{}; + FF binary_acc_ia{}; + FF binary_acc_ib{}; + FF binary_acc_ic{}; + FF binary_clk{}; + FF binary_ia_bytes{}; + FF binary_ib_bytes{}; + FF binary_ic_bytes{}; + FF binary_in_tag{}; + FF binary_mem_tag_ctr{}; + FF binary_mem_tag_ctr_inv{}; + FF binary_op_id{}; + FF binary_sel_bin{}; + FF binary_start{}; + FF byte_lookup_sel_bin{}; + FF byte_lookup_table_byte_lengths{}; + FF byte_lookup_table_in_tags{}; + FF byte_lookup_table_input_a{}; + FF byte_lookup_table_input_b{}; + FF byte_lookup_table_op_id{}; + FF byte_lookup_table_output{}; + FF conversion_clk{}; + FF conversion_input{}; + FF conversion_num_limbs{}; + FF conversion_radix{}; + FF conversion_sel_to_radix_le{}; + FF gas_da_gas_fixed_table{}; + FF gas_l2_gas_fixed_table{}; + FF gas_sel_gas_cost{}; + FF keccakf1600_clk{}; + FF keccakf1600_input{}; + FF keccakf1600_output{}; + FF keccakf1600_sel_keccakf1600{}; + FF kernel_emit_l2_to_l1_msg_write_offset{}; + FF kernel_emit_note_hash_write_offset{}; + FF kernel_emit_nullifier_write_offset{}; + FF kernel_emit_unencrypted_log_write_offset{}; + FF kernel_kernel_in_offset{}; + FF kernel_kernel_inputs{}; + FF kernel_kernel_metadata_out{}; + FF kernel_kernel_out_offset{}; + FF kernel_kernel_side_effect_out{}; + FF kernel_kernel_value_out{}; + FF kernel_l1_to_l2_msg_exists_write_offset{}; + FF kernel_note_hash_exist_write_offset{}; + FF kernel_nullifier_exists_write_offset{}; + FF kernel_nullifier_non_exists_write_offset{}; + FF kernel_q_public_input_kernel_add_to_table{}; + FF kernel_q_public_input_kernel_out_add_to_table{}; + FF kernel_side_effect_counter{}; + FF kernel_sload_write_offset{}; + FF kernel_sstore_write_offset{}; + FF main_abs_da_rem_gas_hi{}; + FF main_abs_da_rem_gas_lo{}; + FF main_abs_l2_rem_gas_hi{}; + FF main_abs_l2_rem_gas_lo{}; + FF main_alu_in_tag{}; + FF main_bin_op_id{}; + FF main_call_ptr{}; + FF main_da_gas_op_cost{}; + FF main_da_gas_remaining{}; + FF main_da_out_of_gas{}; + FF main_ia{}; + FF main_ib{}; + FF main_ic{}; + FF main_id{}; + FF main_id_zero{}; + FF main_ind_addr_a{}; + FF main_ind_addr_b{}; + FF main_ind_addr_c{}; + FF main_ind_addr_d{}; + FF main_internal_return_ptr{}; + FF main_inv{}; + FF main_l2_gas_op_cost{}; + FF main_l2_gas_remaining{}; + FF main_l2_out_of_gas{}; + FF main_mem_addr_a{}; + FF main_mem_addr_b{}; + FF main_mem_addr_c{}; + FF main_mem_addr_d{}; + FF main_op_err{}; + FF main_opcode_val{}; + FF main_pc{}; + FF main_r_in_tag{}; + FF main_rwa{}; + FF main_rwb{}; + FF main_rwc{}; + FF main_rwd{}; + FF main_sel_alu{}; + FF main_sel_bin{}; + FF main_sel_gas_accounting_active{}; + FF main_sel_last{}; + FF main_sel_mem_op_a{}; + FF main_sel_mem_op_activate_gas{}; + FF main_sel_mem_op_b{}; + FF main_sel_mem_op_c{}; + FF main_sel_mem_op_d{}; + FF main_sel_mov_ia_to_ic{}; + FF main_sel_mov_ib_to_ic{}; + FF main_sel_op_add{}; + FF main_sel_op_address{}; + FF main_sel_op_and{}; + FF main_sel_op_block_number{}; + FF main_sel_op_cast{}; + FF main_sel_op_chain_id{}; + FF main_sel_op_cmov{}; + FF main_sel_op_coinbase{}; + FF main_sel_op_dagasleft{}; + FF main_sel_op_div{}; + FF main_sel_op_emit_l2_to_l1_msg{}; + FF main_sel_op_emit_note_hash{}; + FF main_sel_op_emit_nullifier{}; + FF main_sel_op_emit_unencrypted_log{}; + FF main_sel_op_eq{}; + FF main_sel_op_external_call{}; + FF main_sel_op_fdiv{}; + FF main_sel_op_fee_per_da_gas{}; + FF main_sel_op_fee_per_l2_gas{}; + FF main_sel_op_get_contract_instance{}; + FF main_sel_op_halt{}; + FF main_sel_op_internal_call{}; + FF main_sel_op_internal_return{}; + FF main_sel_op_jump{}; + FF main_sel_op_jumpi{}; + FF main_sel_op_keccak{}; + FF main_sel_op_l1_to_l2_msg_exists{}; + FF main_sel_op_l2gasleft{}; + FF main_sel_op_lt{}; + FF main_sel_op_lte{}; + FF main_sel_op_mov{}; + FF main_sel_op_mul{}; + FF main_sel_op_not{}; + FF main_sel_op_note_hash_exists{}; + FF main_sel_op_nullifier_exists{}; + FF main_sel_op_or{}; + FF main_sel_op_pedersen{}; + FF main_sel_op_poseidon2{}; + FF main_sel_op_radix_le{}; + FF main_sel_op_sender{}; + FF main_sel_op_sha256{}; + FF main_sel_op_shl{}; + FF main_sel_op_shr{}; + FF main_sel_op_sload{}; + FF main_sel_op_sstore{}; + FF main_sel_op_storage_address{}; + FF main_sel_op_sub{}; + FF main_sel_op_timestamp{}; + FF main_sel_op_transaction_fee{}; + FF main_sel_op_version{}; + FF main_sel_op_xor{}; + FF main_sel_q_kernel_lookup{}; + FF main_sel_q_kernel_output_lookup{}; + FF main_sel_resolve_ind_addr_a{}; + FF main_sel_resolve_ind_addr_b{}; + FF main_sel_resolve_ind_addr_c{}; + FF main_sel_resolve_ind_addr_d{}; + FF main_sel_rng_16{}; + FF main_sel_rng_8{}; + FF main_space_id{}; + FF main_table_pow_2{}; + FF main_tag_err{}; + FF main_w_in_tag{}; + FF mem_addr{}; + FF mem_clk{}; + FF mem_diff_hi{}; + FF mem_diff_lo{}; + FF mem_diff_mid{}; + FF mem_glob_addr{}; + FF mem_last{}; + FF mem_lastAccess{}; + FF mem_one_min_inv{}; + FF mem_r_in_tag{}; + FF mem_rw{}; + FF mem_sel_mem{}; + FF mem_sel_mov_ia_to_ic{}; + FF mem_sel_mov_ib_to_ic{}; + FF mem_sel_op_a{}; + FF mem_sel_op_b{}; + FF mem_sel_op_c{}; + FF mem_sel_op_cmov{}; + FF mem_sel_op_d{}; + FF mem_sel_resolve_ind_addr_a{}; + FF mem_sel_resolve_ind_addr_b{}; + FF mem_sel_resolve_ind_addr_c{}; + FF mem_sel_resolve_ind_addr_d{}; + FF mem_sel_rng_chk{}; + FF mem_skip_check_tag{}; + FF mem_space_id{}; + FF mem_tag{}; + FF mem_tag_err{}; + FF mem_tsp{}; + FF mem_val{}; + FF mem_w_in_tag{}; + FF pedersen_clk{}; + FF pedersen_input{}; + FF pedersen_output{}; + FF pedersen_sel_pedersen{}; + FF poseidon2_clk{}; + FF poseidon2_input{}; + FF poseidon2_output{}; + FF poseidon2_sel_poseidon_perm{}; + FF sha256_clk{}; + FF sha256_input{}; + FF sha256_output{}; + FF sha256_sel_sha256_compression{}; + FF sha256_state{}; FF perm_main_alu{}; FF perm_main_bin{}; FF perm_main_conv{}; @@ -384,10 +384,10 @@ template struct AvmFullRow { FF perm_main_mem_b{}; FF perm_main_mem_c{}; FF perm_main_mem_d{}; - FF perm_main_mem_ind_a{}; - FF perm_main_mem_ind_b{}; - FF perm_main_mem_ind_c{}; - FF perm_main_mem_ind_d{}; + FF perm_main_mem_ind_addr_a{}; + FF perm_main_mem_ind_addr_b{}; + FF perm_main_mem_ind_addr_c{}; + FF perm_main_mem_ind_addr_d{}; FF lookup_byte_lengths{}; FF lookup_byte_operations{}; FF lookup_opcode_gas{}; @@ -470,71 +470,71 @@ template struct AvmFullRow { FF lookup_div_u16_5_counts{}; FF lookup_div_u16_6_counts{}; FF lookup_div_u16_7_counts{}; - FF avm_alu_a_hi_shift{}; - FF avm_alu_a_lo_shift{}; - FF avm_alu_alu_sel_shift{}; - FF avm_alu_b_hi_shift{}; - FF avm_alu_b_lo_shift{}; - FF avm_alu_cmp_rng_ctr_shift{}; - FF avm_alu_cmp_sel_shift{}; - FF avm_alu_div_rng_chk_selector_shift{}; - FF avm_alu_div_u16_r0_shift{}; - FF avm_alu_div_u16_r1_shift{}; - FF avm_alu_div_u16_r2_shift{}; - FF avm_alu_div_u16_r3_shift{}; - FF avm_alu_div_u16_r4_shift{}; - FF avm_alu_div_u16_r5_shift{}; - FF avm_alu_div_u16_r6_shift{}; - FF avm_alu_div_u16_r7_shift{}; - FF avm_alu_op_add_shift{}; - FF avm_alu_op_cast_prev_shift{}; - FF avm_alu_op_cast_shift{}; - FF avm_alu_op_div_shift{}; - FF avm_alu_op_mul_shift{}; - FF avm_alu_op_shl_shift{}; - FF avm_alu_op_shr_shift{}; - FF avm_alu_op_sub_shift{}; - FF avm_alu_p_sub_a_hi_shift{}; - FF avm_alu_p_sub_a_lo_shift{}; - FF avm_alu_p_sub_b_hi_shift{}; - FF avm_alu_p_sub_b_lo_shift{}; - FF avm_alu_rng_chk_lookup_selector_shift{}; - FF avm_alu_rng_chk_sel_shift{}; - FF avm_alu_u16_r0_shift{}; - FF avm_alu_u16_r1_shift{}; - FF avm_alu_u16_r2_shift{}; - FF avm_alu_u16_r3_shift{}; - FF avm_alu_u16_r4_shift{}; - FF avm_alu_u16_r5_shift{}; - FF avm_alu_u16_r6_shift{}; - FF avm_alu_u8_r0_shift{}; - FF avm_alu_u8_r1_shift{}; - FF avm_binary_acc_ia_shift{}; - FF avm_binary_acc_ib_shift{}; - FF avm_binary_acc_ic_shift{}; - FF avm_binary_mem_tag_ctr_shift{}; - FF avm_binary_op_id_shift{}; - FF avm_kernel_emit_l2_to_l1_msg_write_offset_shift{}; - FF avm_kernel_emit_note_hash_write_offset_shift{}; - FF avm_kernel_emit_nullifier_write_offset_shift{}; - FF avm_kernel_emit_unencrypted_log_write_offset_shift{}; - FF avm_kernel_l1_to_l2_msg_exists_write_offset_shift{}; - FF avm_kernel_note_hash_exist_write_offset_shift{}; - FF avm_kernel_nullifier_exists_write_offset_shift{}; - FF avm_kernel_nullifier_non_exists_write_offset_shift{}; - FF avm_kernel_side_effect_counter_shift{}; - FF avm_kernel_sload_write_offset_shift{}; - FF avm_kernel_sstore_write_offset_shift{}; - FF avm_main_da_gas_remaining_shift{}; - FF avm_main_internal_return_ptr_shift{}; - FF avm_main_l2_gas_remaining_shift{}; - FF avm_main_pc_shift{}; - FF avm_mem_glob_addr_shift{}; - FF avm_mem_mem_sel_shift{}; - FF avm_mem_rw_shift{}; - FF avm_mem_tag_shift{}; - FF avm_mem_tsp_shift{}; - FF avm_mem_val_shift{}; + FF alu_a_hi_shift{}; + FF alu_a_lo_shift{}; + FF alu_b_hi_shift{}; + FF alu_b_lo_shift{}; + FF alu_cmp_rng_ctr_shift{}; + FF alu_div_u16_r0_shift{}; + FF alu_div_u16_r1_shift{}; + FF alu_div_u16_r2_shift{}; + FF alu_div_u16_r3_shift{}; + FF alu_div_u16_r4_shift{}; + FF alu_div_u16_r5_shift{}; + FF alu_div_u16_r6_shift{}; + FF alu_div_u16_r7_shift{}; + FF alu_op_add_shift{}; + FF alu_op_cast_prev_shift{}; + FF alu_op_cast_shift{}; + FF alu_op_div_shift{}; + FF alu_op_mul_shift{}; + FF alu_op_shl_shift{}; + FF alu_op_shr_shift{}; + FF alu_op_sub_shift{}; + FF alu_p_sub_a_hi_shift{}; + FF alu_p_sub_a_lo_shift{}; + FF alu_p_sub_b_hi_shift{}; + FF alu_p_sub_b_lo_shift{}; + FF alu_sel_alu_shift{}; + FF alu_sel_cmp_shift{}; + FF alu_sel_div_rng_chk_shift{}; + FF alu_sel_rng_chk_lookup_shift{}; + FF alu_sel_rng_chk_shift{}; + FF alu_u16_r0_shift{}; + FF alu_u16_r1_shift{}; + FF alu_u16_r2_shift{}; + FF alu_u16_r3_shift{}; + FF alu_u16_r4_shift{}; + FF alu_u16_r5_shift{}; + FF alu_u16_r6_shift{}; + FF alu_u8_r0_shift{}; + FF alu_u8_r1_shift{}; + FF binary_acc_ia_shift{}; + FF binary_acc_ib_shift{}; + FF binary_acc_ic_shift{}; + FF binary_mem_tag_ctr_shift{}; + FF binary_op_id_shift{}; + FF kernel_emit_l2_to_l1_msg_write_offset_shift{}; + FF kernel_emit_note_hash_write_offset_shift{}; + FF kernel_emit_nullifier_write_offset_shift{}; + FF kernel_emit_unencrypted_log_write_offset_shift{}; + FF kernel_l1_to_l2_msg_exists_write_offset_shift{}; + FF kernel_note_hash_exist_write_offset_shift{}; + FF kernel_nullifier_exists_write_offset_shift{}; + FF kernel_nullifier_non_exists_write_offset_shift{}; + FF kernel_side_effect_counter_shift{}; + FF kernel_sload_write_offset_shift{}; + FF kernel_sstore_write_offset_shift{}; + FF main_da_gas_remaining_shift{}; + FF main_internal_return_ptr_shift{}; + FF main_l2_gas_remaining_shift{}; + FF main_pc_shift{}; + FF mem_glob_addr_shift{}; + FF mem_rw_shift{}; + FF mem_sel_mem_shift{}; + FF mem_tag_shift{}; + FF mem_tsp_shift{}; + FF mem_val_shift{}; [[maybe_unused]] static std::vector names(); }; @@ -568,300 +568,297 @@ class AvmCircuitBuilder { } for (size_t i = 0; i < rows.size(); i++) { - polys.avm_main_clk[i] = rows[i].avm_main_clk; - polys.avm_main_first[i] = rows[i].avm_main_first; - polys.avm_alu_a_hi[i] = rows[i].avm_alu_a_hi; - polys.avm_alu_a_lo[i] = rows[i].avm_alu_a_lo; - polys.avm_alu_alu_sel[i] = rows[i].avm_alu_alu_sel; - polys.avm_alu_b_hi[i] = rows[i].avm_alu_b_hi; - polys.avm_alu_b_lo[i] = rows[i].avm_alu_b_lo; - polys.avm_alu_borrow[i] = rows[i].avm_alu_borrow; - polys.avm_alu_cf[i] = rows[i].avm_alu_cf; - polys.avm_alu_clk[i] = rows[i].avm_alu_clk; - polys.avm_alu_cmp_rng_ctr[i] = rows[i].avm_alu_cmp_rng_ctr; - polys.avm_alu_cmp_sel[i] = rows[i].avm_alu_cmp_sel; - polys.avm_alu_div_rng_chk_selector[i] = rows[i].avm_alu_div_rng_chk_selector; - polys.avm_alu_div_u16_r0[i] = rows[i].avm_alu_div_u16_r0; - polys.avm_alu_div_u16_r1[i] = rows[i].avm_alu_div_u16_r1; - polys.avm_alu_div_u16_r2[i] = rows[i].avm_alu_div_u16_r2; - polys.avm_alu_div_u16_r3[i] = rows[i].avm_alu_div_u16_r3; - polys.avm_alu_div_u16_r4[i] = rows[i].avm_alu_div_u16_r4; - polys.avm_alu_div_u16_r5[i] = rows[i].avm_alu_div_u16_r5; - polys.avm_alu_div_u16_r6[i] = rows[i].avm_alu_div_u16_r6; - polys.avm_alu_div_u16_r7[i] = rows[i].avm_alu_div_u16_r7; - polys.avm_alu_divisor_hi[i] = rows[i].avm_alu_divisor_hi; - polys.avm_alu_divisor_lo[i] = rows[i].avm_alu_divisor_lo; - polys.avm_alu_ff_tag[i] = rows[i].avm_alu_ff_tag; - polys.avm_alu_ia[i] = rows[i].avm_alu_ia; - polys.avm_alu_ib[i] = rows[i].avm_alu_ib; - polys.avm_alu_ic[i] = rows[i].avm_alu_ic; - polys.avm_alu_in_tag[i] = rows[i].avm_alu_in_tag; - polys.avm_alu_op_add[i] = rows[i].avm_alu_op_add; - polys.avm_alu_op_cast[i] = rows[i].avm_alu_op_cast; - polys.avm_alu_op_cast_prev[i] = rows[i].avm_alu_op_cast_prev; - polys.avm_alu_op_div[i] = rows[i].avm_alu_op_div; - polys.avm_alu_op_div_a_lt_b[i] = rows[i].avm_alu_op_div_a_lt_b; - polys.avm_alu_op_div_std[i] = rows[i].avm_alu_op_div_std; - polys.avm_alu_op_eq[i] = rows[i].avm_alu_op_eq; - polys.avm_alu_op_eq_diff_inv[i] = rows[i].avm_alu_op_eq_diff_inv; - polys.avm_alu_op_lt[i] = rows[i].avm_alu_op_lt; - polys.avm_alu_op_lte[i] = rows[i].avm_alu_op_lte; - polys.avm_alu_op_mul[i] = rows[i].avm_alu_op_mul; - polys.avm_alu_op_not[i] = rows[i].avm_alu_op_not; - polys.avm_alu_op_shl[i] = rows[i].avm_alu_op_shl; - polys.avm_alu_op_shr[i] = rows[i].avm_alu_op_shr; - polys.avm_alu_op_sub[i] = rows[i].avm_alu_op_sub; - polys.avm_alu_p_a_borrow[i] = rows[i].avm_alu_p_a_borrow; - polys.avm_alu_p_b_borrow[i] = rows[i].avm_alu_p_b_borrow; - polys.avm_alu_p_sub_a_hi[i] = rows[i].avm_alu_p_sub_a_hi; - polys.avm_alu_p_sub_a_lo[i] = rows[i].avm_alu_p_sub_a_lo; - polys.avm_alu_p_sub_b_hi[i] = rows[i].avm_alu_p_sub_b_hi; - polys.avm_alu_p_sub_b_lo[i] = rows[i].avm_alu_p_sub_b_lo; - polys.avm_alu_partial_prod_hi[i] = rows[i].avm_alu_partial_prod_hi; - polys.avm_alu_partial_prod_lo[i] = rows[i].avm_alu_partial_prod_lo; - polys.avm_alu_quotient_hi[i] = rows[i].avm_alu_quotient_hi; - polys.avm_alu_quotient_lo[i] = rows[i].avm_alu_quotient_lo; - polys.avm_alu_remainder[i] = rows[i].avm_alu_remainder; - polys.avm_alu_res_hi[i] = rows[i].avm_alu_res_hi; - polys.avm_alu_res_lo[i] = rows[i].avm_alu_res_lo; - polys.avm_alu_rng_chk_lookup_selector[i] = rows[i].avm_alu_rng_chk_lookup_selector; - polys.avm_alu_rng_chk_sel[i] = rows[i].avm_alu_rng_chk_sel; - polys.avm_alu_shift_lt_bit_len[i] = rows[i].avm_alu_shift_lt_bit_len; - polys.avm_alu_shift_sel[i] = rows[i].avm_alu_shift_sel; - polys.avm_alu_t_sub_s_bits[i] = rows[i].avm_alu_t_sub_s_bits; - polys.avm_alu_two_pow_s[i] = rows[i].avm_alu_two_pow_s; - polys.avm_alu_two_pow_t_sub_s[i] = rows[i].avm_alu_two_pow_t_sub_s; - polys.avm_alu_u128_tag[i] = rows[i].avm_alu_u128_tag; - polys.avm_alu_u16_r0[i] = rows[i].avm_alu_u16_r0; - polys.avm_alu_u16_r1[i] = rows[i].avm_alu_u16_r1; - polys.avm_alu_u16_r10[i] = rows[i].avm_alu_u16_r10; - polys.avm_alu_u16_r11[i] = rows[i].avm_alu_u16_r11; - polys.avm_alu_u16_r12[i] = rows[i].avm_alu_u16_r12; - polys.avm_alu_u16_r13[i] = rows[i].avm_alu_u16_r13; - polys.avm_alu_u16_r14[i] = rows[i].avm_alu_u16_r14; - polys.avm_alu_u16_r2[i] = rows[i].avm_alu_u16_r2; - polys.avm_alu_u16_r3[i] = rows[i].avm_alu_u16_r3; - polys.avm_alu_u16_r4[i] = rows[i].avm_alu_u16_r4; - polys.avm_alu_u16_r5[i] = rows[i].avm_alu_u16_r5; - polys.avm_alu_u16_r6[i] = rows[i].avm_alu_u16_r6; - polys.avm_alu_u16_r7[i] = rows[i].avm_alu_u16_r7; - polys.avm_alu_u16_r8[i] = rows[i].avm_alu_u16_r8; - polys.avm_alu_u16_r9[i] = rows[i].avm_alu_u16_r9; - polys.avm_alu_u16_tag[i] = rows[i].avm_alu_u16_tag; - polys.avm_alu_u32_tag[i] = rows[i].avm_alu_u32_tag; - polys.avm_alu_u64_tag[i] = rows[i].avm_alu_u64_tag; - polys.avm_alu_u8_r0[i] = rows[i].avm_alu_u8_r0; - polys.avm_alu_u8_r1[i] = rows[i].avm_alu_u8_r1; - polys.avm_alu_u8_tag[i] = rows[i].avm_alu_u8_tag; - polys.avm_binary_acc_ia[i] = rows[i].avm_binary_acc_ia; - polys.avm_binary_acc_ib[i] = rows[i].avm_binary_acc_ib; - polys.avm_binary_acc_ic[i] = rows[i].avm_binary_acc_ic; - polys.avm_binary_bin_sel[i] = rows[i].avm_binary_bin_sel; - polys.avm_binary_clk[i] = rows[i].avm_binary_clk; - polys.avm_binary_ia_bytes[i] = rows[i].avm_binary_ia_bytes; - polys.avm_binary_ib_bytes[i] = rows[i].avm_binary_ib_bytes; - polys.avm_binary_ic_bytes[i] = rows[i].avm_binary_ic_bytes; - polys.avm_binary_in_tag[i] = rows[i].avm_binary_in_tag; - polys.avm_binary_mem_tag_ctr[i] = rows[i].avm_binary_mem_tag_ctr; - polys.avm_binary_mem_tag_ctr_inv[i] = rows[i].avm_binary_mem_tag_ctr_inv; - polys.avm_binary_op_id[i] = rows[i].avm_binary_op_id; - polys.avm_binary_start[i] = rows[i].avm_binary_start; - polys.avm_byte_lookup_bin_sel[i] = rows[i].avm_byte_lookup_bin_sel; - polys.avm_byte_lookup_table_byte_lengths[i] = rows[i].avm_byte_lookup_table_byte_lengths; - polys.avm_byte_lookup_table_in_tags[i] = rows[i].avm_byte_lookup_table_in_tags; - polys.avm_byte_lookup_table_input_a[i] = rows[i].avm_byte_lookup_table_input_a; - polys.avm_byte_lookup_table_input_b[i] = rows[i].avm_byte_lookup_table_input_b; - polys.avm_byte_lookup_table_op_id[i] = rows[i].avm_byte_lookup_table_op_id; - polys.avm_byte_lookup_table_output[i] = rows[i].avm_byte_lookup_table_output; - polys.avm_conversion_clk[i] = rows[i].avm_conversion_clk; - polys.avm_conversion_input[i] = rows[i].avm_conversion_input; - polys.avm_conversion_num_limbs[i] = rows[i].avm_conversion_num_limbs; - polys.avm_conversion_radix[i] = rows[i].avm_conversion_radix; - polys.avm_conversion_to_radix_le_sel[i] = rows[i].avm_conversion_to_radix_le_sel; - polys.avm_gas_da_gas_fixed_table[i] = rows[i].avm_gas_da_gas_fixed_table; - polys.avm_gas_gas_cost_sel[i] = rows[i].avm_gas_gas_cost_sel; - polys.avm_gas_l2_gas_fixed_table[i] = rows[i].avm_gas_l2_gas_fixed_table; - polys.avm_keccakf1600_clk[i] = rows[i].avm_keccakf1600_clk; - polys.avm_keccakf1600_input[i] = rows[i].avm_keccakf1600_input; - polys.avm_keccakf1600_keccakf1600_sel[i] = rows[i].avm_keccakf1600_keccakf1600_sel; - polys.avm_keccakf1600_output[i] = rows[i].avm_keccakf1600_output; - polys.avm_kernel_emit_l2_to_l1_msg_write_offset[i] = rows[i].avm_kernel_emit_l2_to_l1_msg_write_offset; - polys.avm_kernel_emit_note_hash_write_offset[i] = rows[i].avm_kernel_emit_note_hash_write_offset; - polys.avm_kernel_emit_nullifier_write_offset[i] = rows[i].avm_kernel_emit_nullifier_write_offset; - polys.avm_kernel_emit_unencrypted_log_write_offset[i] = - rows[i].avm_kernel_emit_unencrypted_log_write_offset; - polys.avm_kernel_kernel_in_offset[i] = rows[i].avm_kernel_kernel_in_offset; - polys.avm_kernel_kernel_inputs[i] = rows[i].avm_kernel_kernel_inputs; - polys.avm_kernel_kernel_metadata_out[i] = rows[i].avm_kernel_kernel_metadata_out; - polys.avm_kernel_kernel_out_offset[i] = rows[i].avm_kernel_kernel_out_offset; - polys.avm_kernel_kernel_side_effect_out[i] = rows[i].avm_kernel_kernel_side_effect_out; - polys.avm_kernel_kernel_value_out[i] = rows[i].avm_kernel_kernel_value_out; - polys.avm_kernel_l1_to_l2_msg_exists_write_offset[i] = rows[i].avm_kernel_l1_to_l2_msg_exists_write_offset; - polys.avm_kernel_note_hash_exist_write_offset[i] = rows[i].avm_kernel_note_hash_exist_write_offset; - polys.avm_kernel_nullifier_exists_write_offset[i] = rows[i].avm_kernel_nullifier_exists_write_offset; - polys.avm_kernel_nullifier_non_exists_write_offset[i] = - rows[i].avm_kernel_nullifier_non_exists_write_offset; - polys.avm_kernel_q_public_input_kernel_add_to_table[i] = - rows[i].avm_kernel_q_public_input_kernel_add_to_table; - polys.avm_kernel_q_public_input_kernel_out_add_to_table[i] = - rows[i].avm_kernel_q_public_input_kernel_out_add_to_table; - polys.avm_kernel_side_effect_counter[i] = rows[i].avm_kernel_side_effect_counter; - polys.avm_kernel_sload_write_offset[i] = rows[i].avm_kernel_sload_write_offset; - polys.avm_kernel_sstore_write_offset[i] = rows[i].avm_kernel_sstore_write_offset; - polys.avm_main_abs_da_rem_gas_hi[i] = rows[i].avm_main_abs_da_rem_gas_hi; - polys.avm_main_abs_da_rem_gas_lo[i] = rows[i].avm_main_abs_da_rem_gas_lo; - polys.avm_main_abs_l2_rem_gas_hi[i] = rows[i].avm_main_abs_l2_rem_gas_hi; - polys.avm_main_abs_l2_rem_gas_lo[i] = rows[i].avm_main_abs_l2_rem_gas_lo; - polys.avm_main_alu_in_tag[i] = rows[i].avm_main_alu_in_tag; - polys.avm_main_alu_sel[i] = rows[i].avm_main_alu_sel; - polys.avm_main_bin_op_id[i] = rows[i].avm_main_bin_op_id; - polys.avm_main_bin_sel[i] = rows[i].avm_main_bin_sel; - polys.avm_main_call_ptr[i] = rows[i].avm_main_call_ptr; - polys.avm_main_da_gas_op[i] = rows[i].avm_main_da_gas_op; - polys.avm_main_da_gas_remaining[i] = rows[i].avm_main_da_gas_remaining; - polys.avm_main_da_out_of_gas[i] = rows[i].avm_main_da_out_of_gas; - polys.avm_main_gas_cost_active[i] = rows[i].avm_main_gas_cost_active; - polys.avm_main_ia[i] = rows[i].avm_main_ia; - polys.avm_main_ib[i] = rows[i].avm_main_ib; - polys.avm_main_ic[i] = rows[i].avm_main_ic; - polys.avm_main_id[i] = rows[i].avm_main_id; - polys.avm_main_id_zero[i] = rows[i].avm_main_id_zero; - polys.avm_main_ind_a[i] = rows[i].avm_main_ind_a; - polys.avm_main_ind_b[i] = rows[i].avm_main_ind_b; - polys.avm_main_ind_c[i] = rows[i].avm_main_ind_c; - polys.avm_main_ind_d[i] = rows[i].avm_main_ind_d; - polys.avm_main_ind_op_a[i] = rows[i].avm_main_ind_op_a; - polys.avm_main_ind_op_b[i] = rows[i].avm_main_ind_op_b; - polys.avm_main_ind_op_c[i] = rows[i].avm_main_ind_op_c; - polys.avm_main_ind_op_d[i] = rows[i].avm_main_ind_op_d; - polys.avm_main_internal_return_ptr[i] = rows[i].avm_main_internal_return_ptr; - polys.avm_main_inv[i] = rows[i].avm_main_inv; - polys.avm_main_l2_gas_op[i] = rows[i].avm_main_l2_gas_op; - polys.avm_main_l2_gas_remaining[i] = rows[i].avm_main_l2_gas_remaining; - polys.avm_main_l2_out_of_gas[i] = rows[i].avm_main_l2_out_of_gas; - polys.avm_main_last[i] = rows[i].avm_main_last; - polys.avm_main_mem_idx_a[i] = rows[i].avm_main_mem_idx_a; - polys.avm_main_mem_idx_b[i] = rows[i].avm_main_mem_idx_b; - polys.avm_main_mem_idx_c[i] = rows[i].avm_main_mem_idx_c; - polys.avm_main_mem_idx_d[i] = rows[i].avm_main_mem_idx_d; - polys.avm_main_mem_op_a[i] = rows[i].avm_main_mem_op_a; - polys.avm_main_mem_op_activate_gas[i] = rows[i].avm_main_mem_op_activate_gas; - polys.avm_main_mem_op_b[i] = rows[i].avm_main_mem_op_b; - polys.avm_main_mem_op_c[i] = rows[i].avm_main_mem_op_c; - polys.avm_main_mem_op_d[i] = rows[i].avm_main_mem_op_d; - polys.avm_main_op_err[i] = rows[i].avm_main_op_err; - polys.avm_main_opcode_val[i] = rows[i].avm_main_opcode_val; - polys.avm_main_pc[i] = rows[i].avm_main_pc; - polys.avm_main_q_kernel_lookup[i] = rows[i].avm_main_q_kernel_lookup; - polys.avm_main_q_kernel_output_lookup[i] = rows[i].avm_main_q_kernel_output_lookup; - polys.avm_main_r_in_tag[i] = rows[i].avm_main_r_in_tag; - polys.avm_main_rwa[i] = rows[i].avm_main_rwa; - polys.avm_main_rwb[i] = rows[i].avm_main_rwb; - polys.avm_main_rwc[i] = rows[i].avm_main_rwc; - polys.avm_main_rwd[i] = rows[i].avm_main_rwd; - polys.avm_main_sel_cmov[i] = rows[i].avm_main_sel_cmov; - polys.avm_main_sel_external_call[i] = rows[i].avm_main_sel_external_call; - polys.avm_main_sel_halt[i] = rows[i].avm_main_sel_halt; - polys.avm_main_sel_internal_call[i] = rows[i].avm_main_sel_internal_call; - polys.avm_main_sel_internal_return[i] = rows[i].avm_main_sel_internal_return; - polys.avm_main_sel_jump[i] = rows[i].avm_main_sel_jump; - polys.avm_main_sel_jumpi[i] = rows[i].avm_main_sel_jumpi; - polys.avm_main_sel_mov[i] = rows[i].avm_main_sel_mov; - polys.avm_main_sel_mov_a[i] = rows[i].avm_main_sel_mov_a; - polys.avm_main_sel_mov_b[i] = rows[i].avm_main_sel_mov_b; - polys.avm_main_sel_op_add[i] = rows[i].avm_main_sel_op_add; - polys.avm_main_sel_op_address[i] = rows[i].avm_main_sel_op_address; - polys.avm_main_sel_op_and[i] = rows[i].avm_main_sel_op_and; - polys.avm_main_sel_op_block_number[i] = rows[i].avm_main_sel_op_block_number; - polys.avm_main_sel_op_cast[i] = rows[i].avm_main_sel_op_cast; - polys.avm_main_sel_op_chain_id[i] = rows[i].avm_main_sel_op_chain_id; - polys.avm_main_sel_op_coinbase[i] = rows[i].avm_main_sel_op_coinbase; - polys.avm_main_sel_op_dagasleft[i] = rows[i].avm_main_sel_op_dagasleft; - polys.avm_main_sel_op_div[i] = rows[i].avm_main_sel_op_div; - polys.avm_main_sel_op_emit_l2_to_l1_msg[i] = rows[i].avm_main_sel_op_emit_l2_to_l1_msg; - polys.avm_main_sel_op_emit_note_hash[i] = rows[i].avm_main_sel_op_emit_note_hash; - polys.avm_main_sel_op_emit_nullifier[i] = rows[i].avm_main_sel_op_emit_nullifier; - polys.avm_main_sel_op_emit_unencrypted_log[i] = rows[i].avm_main_sel_op_emit_unencrypted_log; - polys.avm_main_sel_op_eq[i] = rows[i].avm_main_sel_op_eq; - polys.avm_main_sel_op_fdiv[i] = rows[i].avm_main_sel_op_fdiv; - polys.avm_main_sel_op_fee_per_da_gas[i] = rows[i].avm_main_sel_op_fee_per_da_gas; - polys.avm_main_sel_op_fee_per_l2_gas[i] = rows[i].avm_main_sel_op_fee_per_l2_gas; - polys.avm_main_sel_op_get_contract_instance[i] = rows[i].avm_main_sel_op_get_contract_instance; - polys.avm_main_sel_op_keccak[i] = rows[i].avm_main_sel_op_keccak; - polys.avm_main_sel_op_l1_to_l2_msg_exists[i] = rows[i].avm_main_sel_op_l1_to_l2_msg_exists; - polys.avm_main_sel_op_l2gasleft[i] = rows[i].avm_main_sel_op_l2gasleft; - polys.avm_main_sel_op_lt[i] = rows[i].avm_main_sel_op_lt; - polys.avm_main_sel_op_lte[i] = rows[i].avm_main_sel_op_lte; - polys.avm_main_sel_op_mul[i] = rows[i].avm_main_sel_op_mul; - polys.avm_main_sel_op_not[i] = rows[i].avm_main_sel_op_not; - polys.avm_main_sel_op_note_hash_exists[i] = rows[i].avm_main_sel_op_note_hash_exists; - polys.avm_main_sel_op_nullifier_exists[i] = rows[i].avm_main_sel_op_nullifier_exists; - polys.avm_main_sel_op_or[i] = rows[i].avm_main_sel_op_or; - polys.avm_main_sel_op_pedersen[i] = rows[i].avm_main_sel_op_pedersen; - polys.avm_main_sel_op_poseidon2[i] = rows[i].avm_main_sel_op_poseidon2; - polys.avm_main_sel_op_radix_le[i] = rows[i].avm_main_sel_op_radix_le; - polys.avm_main_sel_op_sender[i] = rows[i].avm_main_sel_op_sender; - polys.avm_main_sel_op_sha256[i] = rows[i].avm_main_sel_op_sha256; - polys.avm_main_sel_op_shl[i] = rows[i].avm_main_sel_op_shl; - polys.avm_main_sel_op_shr[i] = rows[i].avm_main_sel_op_shr; - polys.avm_main_sel_op_sload[i] = rows[i].avm_main_sel_op_sload; - polys.avm_main_sel_op_sstore[i] = rows[i].avm_main_sel_op_sstore; - polys.avm_main_sel_op_storage_address[i] = rows[i].avm_main_sel_op_storage_address; - polys.avm_main_sel_op_sub[i] = rows[i].avm_main_sel_op_sub; - polys.avm_main_sel_op_timestamp[i] = rows[i].avm_main_sel_op_timestamp; - polys.avm_main_sel_op_transaction_fee[i] = rows[i].avm_main_sel_op_transaction_fee; - polys.avm_main_sel_op_version[i] = rows[i].avm_main_sel_op_version; - polys.avm_main_sel_op_xor[i] = rows[i].avm_main_sel_op_xor; - polys.avm_main_sel_rng_16[i] = rows[i].avm_main_sel_rng_16; - polys.avm_main_sel_rng_8[i] = rows[i].avm_main_sel_rng_8; - polys.avm_main_space_id[i] = rows[i].avm_main_space_id; - polys.avm_main_table_pow_2[i] = rows[i].avm_main_table_pow_2; - polys.avm_main_tag_err[i] = rows[i].avm_main_tag_err; - polys.avm_main_w_in_tag[i] = rows[i].avm_main_w_in_tag; - polys.avm_mem_addr[i] = rows[i].avm_mem_addr; - polys.avm_mem_clk[i] = rows[i].avm_mem_clk; - polys.avm_mem_diff_hi[i] = rows[i].avm_mem_diff_hi; - polys.avm_mem_diff_lo[i] = rows[i].avm_mem_diff_lo; - polys.avm_mem_diff_mid[i] = rows[i].avm_mem_diff_mid; - polys.avm_mem_glob_addr[i] = rows[i].avm_mem_glob_addr; - polys.avm_mem_ind_op_a[i] = rows[i].avm_mem_ind_op_a; - polys.avm_mem_ind_op_b[i] = rows[i].avm_mem_ind_op_b; - polys.avm_mem_ind_op_c[i] = rows[i].avm_mem_ind_op_c; - polys.avm_mem_ind_op_d[i] = rows[i].avm_mem_ind_op_d; - polys.avm_mem_last[i] = rows[i].avm_mem_last; - polys.avm_mem_lastAccess[i] = rows[i].avm_mem_lastAccess; - polys.avm_mem_mem_sel[i] = rows[i].avm_mem_mem_sel; - polys.avm_mem_one_min_inv[i] = rows[i].avm_mem_one_min_inv; - polys.avm_mem_op_a[i] = rows[i].avm_mem_op_a; - polys.avm_mem_op_b[i] = rows[i].avm_mem_op_b; - polys.avm_mem_op_c[i] = rows[i].avm_mem_op_c; - polys.avm_mem_op_d[i] = rows[i].avm_mem_op_d; - polys.avm_mem_r_in_tag[i] = rows[i].avm_mem_r_in_tag; - polys.avm_mem_rng_chk_sel[i] = rows[i].avm_mem_rng_chk_sel; - polys.avm_mem_rw[i] = rows[i].avm_mem_rw; - polys.avm_mem_sel_cmov[i] = rows[i].avm_mem_sel_cmov; - polys.avm_mem_sel_mov_a[i] = rows[i].avm_mem_sel_mov_a; - polys.avm_mem_sel_mov_b[i] = rows[i].avm_mem_sel_mov_b; - polys.avm_mem_skip_check_tag[i] = rows[i].avm_mem_skip_check_tag; - polys.avm_mem_space_id[i] = rows[i].avm_mem_space_id; - polys.avm_mem_tag[i] = rows[i].avm_mem_tag; - polys.avm_mem_tag_err[i] = rows[i].avm_mem_tag_err; - polys.avm_mem_tsp[i] = rows[i].avm_mem_tsp; - polys.avm_mem_val[i] = rows[i].avm_mem_val; - polys.avm_mem_w_in_tag[i] = rows[i].avm_mem_w_in_tag; - polys.avm_pedersen_clk[i] = rows[i].avm_pedersen_clk; - polys.avm_pedersen_input[i] = rows[i].avm_pedersen_input; - polys.avm_pedersen_output[i] = rows[i].avm_pedersen_output; - polys.avm_pedersen_pedersen_sel[i] = rows[i].avm_pedersen_pedersen_sel; - polys.avm_poseidon2_clk[i] = rows[i].avm_poseidon2_clk; - polys.avm_poseidon2_input[i] = rows[i].avm_poseidon2_input; - polys.avm_poseidon2_output[i] = rows[i].avm_poseidon2_output; - polys.avm_poseidon2_poseidon_perm_sel[i] = rows[i].avm_poseidon2_poseidon_perm_sel; - polys.avm_sha256_clk[i] = rows[i].avm_sha256_clk; - polys.avm_sha256_input[i] = rows[i].avm_sha256_input; - polys.avm_sha256_output[i] = rows[i].avm_sha256_output; - polys.avm_sha256_sha256_compression_sel[i] = rows[i].avm_sha256_sha256_compression_sel; - polys.avm_sha256_state[i] = rows[i].avm_sha256_state; + polys.main_clk[i] = rows[i].main_clk; + polys.main_sel_first[i] = rows[i].main_sel_first; + polys.alu_a_hi[i] = rows[i].alu_a_hi; + polys.alu_a_lo[i] = rows[i].alu_a_lo; + polys.alu_b_hi[i] = rows[i].alu_b_hi; + polys.alu_b_lo[i] = rows[i].alu_b_lo; + polys.alu_borrow[i] = rows[i].alu_borrow; + polys.alu_cf[i] = rows[i].alu_cf; + polys.alu_clk[i] = rows[i].alu_clk; + polys.alu_cmp_rng_ctr[i] = rows[i].alu_cmp_rng_ctr; + polys.alu_div_u16_r0[i] = rows[i].alu_div_u16_r0; + polys.alu_div_u16_r1[i] = rows[i].alu_div_u16_r1; + polys.alu_div_u16_r2[i] = rows[i].alu_div_u16_r2; + polys.alu_div_u16_r3[i] = rows[i].alu_div_u16_r3; + polys.alu_div_u16_r4[i] = rows[i].alu_div_u16_r4; + polys.alu_div_u16_r5[i] = rows[i].alu_div_u16_r5; + polys.alu_div_u16_r6[i] = rows[i].alu_div_u16_r6; + polys.alu_div_u16_r7[i] = rows[i].alu_div_u16_r7; + polys.alu_divisor_hi[i] = rows[i].alu_divisor_hi; + polys.alu_divisor_lo[i] = rows[i].alu_divisor_lo; + polys.alu_ff_tag[i] = rows[i].alu_ff_tag; + polys.alu_ia[i] = rows[i].alu_ia; + polys.alu_ib[i] = rows[i].alu_ib; + polys.alu_ic[i] = rows[i].alu_ic; + polys.alu_in_tag[i] = rows[i].alu_in_tag; + polys.alu_op_add[i] = rows[i].alu_op_add; + polys.alu_op_cast[i] = rows[i].alu_op_cast; + polys.alu_op_cast_prev[i] = rows[i].alu_op_cast_prev; + polys.alu_op_div[i] = rows[i].alu_op_div; + polys.alu_op_div_a_lt_b[i] = rows[i].alu_op_div_a_lt_b; + polys.alu_op_div_std[i] = rows[i].alu_op_div_std; + polys.alu_op_eq[i] = rows[i].alu_op_eq; + polys.alu_op_eq_diff_inv[i] = rows[i].alu_op_eq_diff_inv; + polys.alu_op_lt[i] = rows[i].alu_op_lt; + polys.alu_op_lte[i] = rows[i].alu_op_lte; + polys.alu_op_mul[i] = rows[i].alu_op_mul; + polys.alu_op_not[i] = rows[i].alu_op_not; + polys.alu_op_shl[i] = rows[i].alu_op_shl; + polys.alu_op_shr[i] = rows[i].alu_op_shr; + polys.alu_op_sub[i] = rows[i].alu_op_sub; + polys.alu_p_a_borrow[i] = rows[i].alu_p_a_borrow; + polys.alu_p_b_borrow[i] = rows[i].alu_p_b_borrow; + polys.alu_p_sub_a_hi[i] = rows[i].alu_p_sub_a_hi; + polys.alu_p_sub_a_lo[i] = rows[i].alu_p_sub_a_lo; + polys.alu_p_sub_b_hi[i] = rows[i].alu_p_sub_b_hi; + polys.alu_p_sub_b_lo[i] = rows[i].alu_p_sub_b_lo; + polys.alu_partial_prod_hi[i] = rows[i].alu_partial_prod_hi; + polys.alu_partial_prod_lo[i] = rows[i].alu_partial_prod_lo; + polys.alu_quotient_hi[i] = rows[i].alu_quotient_hi; + polys.alu_quotient_lo[i] = rows[i].alu_quotient_lo; + polys.alu_remainder[i] = rows[i].alu_remainder; + polys.alu_res_hi[i] = rows[i].alu_res_hi; + polys.alu_res_lo[i] = rows[i].alu_res_lo; + polys.alu_sel_alu[i] = rows[i].alu_sel_alu; + polys.alu_sel_cmp[i] = rows[i].alu_sel_cmp; + polys.alu_sel_div_rng_chk[i] = rows[i].alu_sel_div_rng_chk; + polys.alu_sel_rng_chk[i] = rows[i].alu_sel_rng_chk; + polys.alu_sel_rng_chk_lookup[i] = rows[i].alu_sel_rng_chk_lookup; + polys.alu_sel_shift_which[i] = rows[i].alu_sel_shift_which; + polys.alu_shift_lt_bit_len[i] = rows[i].alu_shift_lt_bit_len; + polys.alu_t_sub_s_bits[i] = rows[i].alu_t_sub_s_bits; + polys.alu_two_pow_s[i] = rows[i].alu_two_pow_s; + polys.alu_two_pow_t_sub_s[i] = rows[i].alu_two_pow_t_sub_s; + polys.alu_u128_tag[i] = rows[i].alu_u128_tag; + polys.alu_u16_r0[i] = rows[i].alu_u16_r0; + polys.alu_u16_r1[i] = rows[i].alu_u16_r1; + polys.alu_u16_r10[i] = rows[i].alu_u16_r10; + polys.alu_u16_r11[i] = rows[i].alu_u16_r11; + polys.alu_u16_r12[i] = rows[i].alu_u16_r12; + polys.alu_u16_r13[i] = rows[i].alu_u16_r13; + polys.alu_u16_r14[i] = rows[i].alu_u16_r14; + polys.alu_u16_r2[i] = rows[i].alu_u16_r2; + polys.alu_u16_r3[i] = rows[i].alu_u16_r3; + polys.alu_u16_r4[i] = rows[i].alu_u16_r4; + polys.alu_u16_r5[i] = rows[i].alu_u16_r5; + polys.alu_u16_r6[i] = rows[i].alu_u16_r6; + polys.alu_u16_r7[i] = rows[i].alu_u16_r7; + polys.alu_u16_r8[i] = rows[i].alu_u16_r8; + polys.alu_u16_r9[i] = rows[i].alu_u16_r9; + polys.alu_u16_tag[i] = rows[i].alu_u16_tag; + polys.alu_u32_tag[i] = rows[i].alu_u32_tag; + polys.alu_u64_tag[i] = rows[i].alu_u64_tag; + polys.alu_u8_r0[i] = rows[i].alu_u8_r0; + polys.alu_u8_r1[i] = rows[i].alu_u8_r1; + polys.alu_u8_tag[i] = rows[i].alu_u8_tag; + polys.binary_acc_ia[i] = rows[i].binary_acc_ia; + polys.binary_acc_ib[i] = rows[i].binary_acc_ib; + polys.binary_acc_ic[i] = rows[i].binary_acc_ic; + polys.binary_clk[i] = rows[i].binary_clk; + polys.binary_ia_bytes[i] = rows[i].binary_ia_bytes; + polys.binary_ib_bytes[i] = rows[i].binary_ib_bytes; + polys.binary_ic_bytes[i] = rows[i].binary_ic_bytes; + polys.binary_in_tag[i] = rows[i].binary_in_tag; + polys.binary_mem_tag_ctr[i] = rows[i].binary_mem_tag_ctr; + polys.binary_mem_tag_ctr_inv[i] = rows[i].binary_mem_tag_ctr_inv; + polys.binary_op_id[i] = rows[i].binary_op_id; + polys.binary_sel_bin[i] = rows[i].binary_sel_bin; + polys.binary_start[i] = rows[i].binary_start; + polys.byte_lookup_sel_bin[i] = rows[i].byte_lookup_sel_bin; + polys.byte_lookup_table_byte_lengths[i] = rows[i].byte_lookup_table_byte_lengths; + polys.byte_lookup_table_in_tags[i] = rows[i].byte_lookup_table_in_tags; + polys.byte_lookup_table_input_a[i] = rows[i].byte_lookup_table_input_a; + polys.byte_lookup_table_input_b[i] = rows[i].byte_lookup_table_input_b; + polys.byte_lookup_table_op_id[i] = rows[i].byte_lookup_table_op_id; + polys.byte_lookup_table_output[i] = rows[i].byte_lookup_table_output; + polys.conversion_clk[i] = rows[i].conversion_clk; + polys.conversion_input[i] = rows[i].conversion_input; + polys.conversion_num_limbs[i] = rows[i].conversion_num_limbs; + polys.conversion_radix[i] = rows[i].conversion_radix; + polys.conversion_sel_to_radix_le[i] = rows[i].conversion_sel_to_radix_le; + polys.gas_da_gas_fixed_table[i] = rows[i].gas_da_gas_fixed_table; + polys.gas_l2_gas_fixed_table[i] = rows[i].gas_l2_gas_fixed_table; + polys.gas_sel_gas_cost[i] = rows[i].gas_sel_gas_cost; + polys.keccakf1600_clk[i] = rows[i].keccakf1600_clk; + polys.keccakf1600_input[i] = rows[i].keccakf1600_input; + polys.keccakf1600_output[i] = rows[i].keccakf1600_output; + polys.keccakf1600_sel_keccakf1600[i] = rows[i].keccakf1600_sel_keccakf1600; + polys.kernel_emit_l2_to_l1_msg_write_offset[i] = rows[i].kernel_emit_l2_to_l1_msg_write_offset; + polys.kernel_emit_note_hash_write_offset[i] = rows[i].kernel_emit_note_hash_write_offset; + polys.kernel_emit_nullifier_write_offset[i] = rows[i].kernel_emit_nullifier_write_offset; + polys.kernel_emit_unencrypted_log_write_offset[i] = rows[i].kernel_emit_unencrypted_log_write_offset; + polys.kernel_kernel_in_offset[i] = rows[i].kernel_kernel_in_offset; + polys.kernel_kernel_inputs[i] = rows[i].kernel_kernel_inputs; + polys.kernel_kernel_metadata_out[i] = rows[i].kernel_kernel_metadata_out; + polys.kernel_kernel_out_offset[i] = rows[i].kernel_kernel_out_offset; + polys.kernel_kernel_side_effect_out[i] = rows[i].kernel_kernel_side_effect_out; + polys.kernel_kernel_value_out[i] = rows[i].kernel_kernel_value_out; + polys.kernel_l1_to_l2_msg_exists_write_offset[i] = rows[i].kernel_l1_to_l2_msg_exists_write_offset; + polys.kernel_note_hash_exist_write_offset[i] = rows[i].kernel_note_hash_exist_write_offset; + polys.kernel_nullifier_exists_write_offset[i] = rows[i].kernel_nullifier_exists_write_offset; + polys.kernel_nullifier_non_exists_write_offset[i] = rows[i].kernel_nullifier_non_exists_write_offset; + polys.kernel_q_public_input_kernel_add_to_table[i] = rows[i].kernel_q_public_input_kernel_add_to_table; + polys.kernel_q_public_input_kernel_out_add_to_table[i] = + rows[i].kernel_q_public_input_kernel_out_add_to_table; + polys.kernel_side_effect_counter[i] = rows[i].kernel_side_effect_counter; + polys.kernel_sload_write_offset[i] = rows[i].kernel_sload_write_offset; + polys.kernel_sstore_write_offset[i] = rows[i].kernel_sstore_write_offset; + polys.main_abs_da_rem_gas_hi[i] = rows[i].main_abs_da_rem_gas_hi; + polys.main_abs_da_rem_gas_lo[i] = rows[i].main_abs_da_rem_gas_lo; + polys.main_abs_l2_rem_gas_hi[i] = rows[i].main_abs_l2_rem_gas_hi; + polys.main_abs_l2_rem_gas_lo[i] = rows[i].main_abs_l2_rem_gas_lo; + polys.main_alu_in_tag[i] = rows[i].main_alu_in_tag; + polys.main_bin_op_id[i] = rows[i].main_bin_op_id; + polys.main_call_ptr[i] = rows[i].main_call_ptr; + polys.main_da_gas_op_cost[i] = rows[i].main_da_gas_op_cost; + polys.main_da_gas_remaining[i] = rows[i].main_da_gas_remaining; + polys.main_da_out_of_gas[i] = rows[i].main_da_out_of_gas; + polys.main_ia[i] = rows[i].main_ia; + polys.main_ib[i] = rows[i].main_ib; + polys.main_ic[i] = rows[i].main_ic; + polys.main_id[i] = rows[i].main_id; + polys.main_id_zero[i] = rows[i].main_id_zero; + polys.main_ind_addr_a[i] = rows[i].main_ind_addr_a; + polys.main_ind_addr_b[i] = rows[i].main_ind_addr_b; + polys.main_ind_addr_c[i] = rows[i].main_ind_addr_c; + polys.main_ind_addr_d[i] = rows[i].main_ind_addr_d; + polys.main_internal_return_ptr[i] = rows[i].main_internal_return_ptr; + polys.main_inv[i] = rows[i].main_inv; + polys.main_l2_gas_op_cost[i] = rows[i].main_l2_gas_op_cost; + polys.main_l2_gas_remaining[i] = rows[i].main_l2_gas_remaining; + polys.main_l2_out_of_gas[i] = rows[i].main_l2_out_of_gas; + polys.main_mem_addr_a[i] = rows[i].main_mem_addr_a; + polys.main_mem_addr_b[i] = rows[i].main_mem_addr_b; + polys.main_mem_addr_c[i] = rows[i].main_mem_addr_c; + polys.main_mem_addr_d[i] = rows[i].main_mem_addr_d; + polys.main_op_err[i] = rows[i].main_op_err; + polys.main_opcode_val[i] = rows[i].main_opcode_val; + polys.main_pc[i] = rows[i].main_pc; + polys.main_r_in_tag[i] = rows[i].main_r_in_tag; + polys.main_rwa[i] = rows[i].main_rwa; + polys.main_rwb[i] = rows[i].main_rwb; + polys.main_rwc[i] = rows[i].main_rwc; + polys.main_rwd[i] = rows[i].main_rwd; + polys.main_sel_alu[i] = rows[i].main_sel_alu; + polys.main_sel_bin[i] = rows[i].main_sel_bin; + polys.main_sel_gas_accounting_active[i] = rows[i].main_sel_gas_accounting_active; + polys.main_sel_last[i] = rows[i].main_sel_last; + polys.main_sel_mem_op_a[i] = rows[i].main_sel_mem_op_a; + polys.main_sel_mem_op_activate_gas[i] = rows[i].main_sel_mem_op_activate_gas; + polys.main_sel_mem_op_b[i] = rows[i].main_sel_mem_op_b; + polys.main_sel_mem_op_c[i] = rows[i].main_sel_mem_op_c; + polys.main_sel_mem_op_d[i] = rows[i].main_sel_mem_op_d; + polys.main_sel_mov_ia_to_ic[i] = rows[i].main_sel_mov_ia_to_ic; + polys.main_sel_mov_ib_to_ic[i] = rows[i].main_sel_mov_ib_to_ic; + polys.main_sel_op_add[i] = rows[i].main_sel_op_add; + polys.main_sel_op_address[i] = rows[i].main_sel_op_address; + polys.main_sel_op_and[i] = rows[i].main_sel_op_and; + polys.main_sel_op_block_number[i] = rows[i].main_sel_op_block_number; + polys.main_sel_op_cast[i] = rows[i].main_sel_op_cast; + polys.main_sel_op_chain_id[i] = rows[i].main_sel_op_chain_id; + polys.main_sel_op_cmov[i] = rows[i].main_sel_op_cmov; + polys.main_sel_op_coinbase[i] = rows[i].main_sel_op_coinbase; + polys.main_sel_op_dagasleft[i] = rows[i].main_sel_op_dagasleft; + polys.main_sel_op_div[i] = rows[i].main_sel_op_div; + polys.main_sel_op_emit_l2_to_l1_msg[i] = rows[i].main_sel_op_emit_l2_to_l1_msg; + polys.main_sel_op_emit_note_hash[i] = rows[i].main_sel_op_emit_note_hash; + polys.main_sel_op_emit_nullifier[i] = rows[i].main_sel_op_emit_nullifier; + polys.main_sel_op_emit_unencrypted_log[i] = rows[i].main_sel_op_emit_unencrypted_log; + polys.main_sel_op_eq[i] = rows[i].main_sel_op_eq; + polys.main_sel_op_external_call[i] = rows[i].main_sel_op_external_call; + polys.main_sel_op_fdiv[i] = rows[i].main_sel_op_fdiv; + polys.main_sel_op_fee_per_da_gas[i] = rows[i].main_sel_op_fee_per_da_gas; + polys.main_sel_op_fee_per_l2_gas[i] = rows[i].main_sel_op_fee_per_l2_gas; + polys.main_sel_op_get_contract_instance[i] = rows[i].main_sel_op_get_contract_instance; + polys.main_sel_op_halt[i] = rows[i].main_sel_op_halt; + polys.main_sel_op_internal_call[i] = rows[i].main_sel_op_internal_call; + polys.main_sel_op_internal_return[i] = rows[i].main_sel_op_internal_return; + polys.main_sel_op_jump[i] = rows[i].main_sel_op_jump; + polys.main_sel_op_jumpi[i] = rows[i].main_sel_op_jumpi; + polys.main_sel_op_keccak[i] = rows[i].main_sel_op_keccak; + polys.main_sel_op_l1_to_l2_msg_exists[i] = rows[i].main_sel_op_l1_to_l2_msg_exists; + polys.main_sel_op_l2gasleft[i] = rows[i].main_sel_op_l2gasleft; + polys.main_sel_op_lt[i] = rows[i].main_sel_op_lt; + polys.main_sel_op_lte[i] = rows[i].main_sel_op_lte; + polys.main_sel_op_mov[i] = rows[i].main_sel_op_mov; + polys.main_sel_op_mul[i] = rows[i].main_sel_op_mul; + polys.main_sel_op_not[i] = rows[i].main_sel_op_not; + polys.main_sel_op_note_hash_exists[i] = rows[i].main_sel_op_note_hash_exists; + polys.main_sel_op_nullifier_exists[i] = rows[i].main_sel_op_nullifier_exists; + polys.main_sel_op_or[i] = rows[i].main_sel_op_or; + polys.main_sel_op_pedersen[i] = rows[i].main_sel_op_pedersen; + polys.main_sel_op_poseidon2[i] = rows[i].main_sel_op_poseidon2; + polys.main_sel_op_radix_le[i] = rows[i].main_sel_op_radix_le; + polys.main_sel_op_sender[i] = rows[i].main_sel_op_sender; + polys.main_sel_op_sha256[i] = rows[i].main_sel_op_sha256; + polys.main_sel_op_shl[i] = rows[i].main_sel_op_shl; + polys.main_sel_op_shr[i] = rows[i].main_sel_op_shr; + polys.main_sel_op_sload[i] = rows[i].main_sel_op_sload; + polys.main_sel_op_sstore[i] = rows[i].main_sel_op_sstore; + polys.main_sel_op_storage_address[i] = rows[i].main_sel_op_storage_address; + polys.main_sel_op_sub[i] = rows[i].main_sel_op_sub; + polys.main_sel_op_timestamp[i] = rows[i].main_sel_op_timestamp; + polys.main_sel_op_transaction_fee[i] = rows[i].main_sel_op_transaction_fee; + polys.main_sel_op_version[i] = rows[i].main_sel_op_version; + polys.main_sel_op_xor[i] = rows[i].main_sel_op_xor; + polys.main_sel_q_kernel_lookup[i] = rows[i].main_sel_q_kernel_lookup; + polys.main_sel_q_kernel_output_lookup[i] = rows[i].main_sel_q_kernel_output_lookup; + polys.main_sel_resolve_ind_addr_a[i] = rows[i].main_sel_resolve_ind_addr_a; + polys.main_sel_resolve_ind_addr_b[i] = rows[i].main_sel_resolve_ind_addr_b; + polys.main_sel_resolve_ind_addr_c[i] = rows[i].main_sel_resolve_ind_addr_c; + polys.main_sel_resolve_ind_addr_d[i] = rows[i].main_sel_resolve_ind_addr_d; + polys.main_sel_rng_16[i] = rows[i].main_sel_rng_16; + polys.main_sel_rng_8[i] = rows[i].main_sel_rng_8; + polys.main_space_id[i] = rows[i].main_space_id; + polys.main_table_pow_2[i] = rows[i].main_table_pow_2; + polys.main_tag_err[i] = rows[i].main_tag_err; + polys.main_w_in_tag[i] = rows[i].main_w_in_tag; + polys.mem_addr[i] = rows[i].mem_addr; + polys.mem_clk[i] = rows[i].mem_clk; + polys.mem_diff_hi[i] = rows[i].mem_diff_hi; + polys.mem_diff_lo[i] = rows[i].mem_diff_lo; + polys.mem_diff_mid[i] = rows[i].mem_diff_mid; + polys.mem_glob_addr[i] = rows[i].mem_glob_addr; + polys.mem_last[i] = rows[i].mem_last; + polys.mem_lastAccess[i] = rows[i].mem_lastAccess; + polys.mem_one_min_inv[i] = rows[i].mem_one_min_inv; + polys.mem_r_in_tag[i] = rows[i].mem_r_in_tag; + polys.mem_rw[i] = rows[i].mem_rw; + polys.mem_sel_mem[i] = rows[i].mem_sel_mem; + polys.mem_sel_mov_ia_to_ic[i] = rows[i].mem_sel_mov_ia_to_ic; + polys.mem_sel_mov_ib_to_ic[i] = rows[i].mem_sel_mov_ib_to_ic; + polys.mem_sel_op_a[i] = rows[i].mem_sel_op_a; + polys.mem_sel_op_b[i] = rows[i].mem_sel_op_b; + polys.mem_sel_op_c[i] = rows[i].mem_sel_op_c; + polys.mem_sel_op_cmov[i] = rows[i].mem_sel_op_cmov; + polys.mem_sel_op_d[i] = rows[i].mem_sel_op_d; + polys.mem_sel_resolve_ind_addr_a[i] = rows[i].mem_sel_resolve_ind_addr_a; + polys.mem_sel_resolve_ind_addr_b[i] = rows[i].mem_sel_resolve_ind_addr_b; + polys.mem_sel_resolve_ind_addr_c[i] = rows[i].mem_sel_resolve_ind_addr_c; + polys.mem_sel_resolve_ind_addr_d[i] = rows[i].mem_sel_resolve_ind_addr_d; + polys.mem_sel_rng_chk[i] = rows[i].mem_sel_rng_chk; + polys.mem_skip_check_tag[i] = rows[i].mem_skip_check_tag; + polys.mem_space_id[i] = rows[i].mem_space_id; + polys.mem_tag[i] = rows[i].mem_tag; + polys.mem_tag_err[i] = rows[i].mem_tag_err; + polys.mem_tsp[i] = rows[i].mem_tsp; + polys.mem_val[i] = rows[i].mem_val; + polys.mem_w_in_tag[i] = rows[i].mem_w_in_tag; + polys.pedersen_clk[i] = rows[i].pedersen_clk; + polys.pedersen_input[i] = rows[i].pedersen_input; + polys.pedersen_output[i] = rows[i].pedersen_output; + polys.pedersen_sel_pedersen[i] = rows[i].pedersen_sel_pedersen; + polys.poseidon2_clk[i] = rows[i].poseidon2_clk; + polys.poseidon2_input[i] = rows[i].poseidon2_input; + polys.poseidon2_output[i] = rows[i].poseidon2_output; + polys.poseidon2_sel_poseidon_perm[i] = rows[i].poseidon2_sel_poseidon_perm; + polys.sha256_clk[i] = rows[i].sha256_clk; + polys.sha256_input[i] = rows[i].sha256_input; + polys.sha256_output[i] = rows[i].sha256_output; + polys.sha256_sel_sha256_compression[i] = rows[i].sha256_sel_sha256_compression; + polys.sha256_state[i] = rows[i].sha256_state; polys.lookup_byte_lengths_counts[i] = rows[i].lookup_byte_lengths_counts; polys.lookup_byte_operations_counts[i] = rows[i].lookup_byte_operations_counts; polys.lookup_opcode_gas_counts[i] = rows[i].lookup_opcode_gas_counts; @@ -905,79 +902,77 @@ class AvmCircuitBuilder { polys.lookup_div_u16_7_counts[i] = rows[i].lookup_div_u16_7_counts; } - polys.avm_alu_a_hi_shift = Polynomial(polys.avm_alu_a_hi.shifted()); - polys.avm_alu_a_lo_shift = Polynomial(polys.avm_alu_a_lo.shifted()); - polys.avm_alu_alu_sel_shift = Polynomial(polys.avm_alu_alu_sel.shifted()); - polys.avm_alu_b_hi_shift = Polynomial(polys.avm_alu_b_hi.shifted()); - polys.avm_alu_b_lo_shift = Polynomial(polys.avm_alu_b_lo.shifted()); - polys.avm_alu_cmp_rng_ctr_shift = Polynomial(polys.avm_alu_cmp_rng_ctr.shifted()); - polys.avm_alu_cmp_sel_shift = Polynomial(polys.avm_alu_cmp_sel.shifted()); - polys.avm_alu_div_rng_chk_selector_shift = Polynomial(polys.avm_alu_div_rng_chk_selector.shifted()); - polys.avm_alu_div_u16_r0_shift = Polynomial(polys.avm_alu_div_u16_r0.shifted()); - polys.avm_alu_div_u16_r1_shift = Polynomial(polys.avm_alu_div_u16_r1.shifted()); - polys.avm_alu_div_u16_r2_shift = Polynomial(polys.avm_alu_div_u16_r2.shifted()); - polys.avm_alu_div_u16_r3_shift = Polynomial(polys.avm_alu_div_u16_r3.shifted()); - polys.avm_alu_div_u16_r4_shift = Polynomial(polys.avm_alu_div_u16_r4.shifted()); - polys.avm_alu_div_u16_r5_shift = Polynomial(polys.avm_alu_div_u16_r5.shifted()); - polys.avm_alu_div_u16_r6_shift = Polynomial(polys.avm_alu_div_u16_r6.shifted()); - polys.avm_alu_div_u16_r7_shift = Polynomial(polys.avm_alu_div_u16_r7.shifted()); - polys.avm_alu_op_add_shift = Polynomial(polys.avm_alu_op_add.shifted()); - polys.avm_alu_op_cast_prev_shift = Polynomial(polys.avm_alu_op_cast_prev.shifted()); - polys.avm_alu_op_cast_shift = Polynomial(polys.avm_alu_op_cast.shifted()); - polys.avm_alu_op_div_shift = Polynomial(polys.avm_alu_op_div.shifted()); - polys.avm_alu_op_mul_shift = Polynomial(polys.avm_alu_op_mul.shifted()); - polys.avm_alu_op_shl_shift = Polynomial(polys.avm_alu_op_shl.shifted()); - polys.avm_alu_op_shr_shift = Polynomial(polys.avm_alu_op_shr.shifted()); - polys.avm_alu_op_sub_shift = Polynomial(polys.avm_alu_op_sub.shifted()); - polys.avm_alu_p_sub_a_hi_shift = Polynomial(polys.avm_alu_p_sub_a_hi.shifted()); - polys.avm_alu_p_sub_a_lo_shift = Polynomial(polys.avm_alu_p_sub_a_lo.shifted()); - polys.avm_alu_p_sub_b_hi_shift = Polynomial(polys.avm_alu_p_sub_b_hi.shifted()); - polys.avm_alu_p_sub_b_lo_shift = Polynomial(polys.avm_alu_p_sub_b_lo.shifted()); - polys.avm_alu_rng_chk_lookup_selector_shift = Polynomial(polys.avm_alu_rng_chk_lookup_selector.shifted()); - polys.avm_alu_rng_chk_sel_shift = Polynomial(polys.avm_alu_rng_chk_sel.shifted()); - polys.avm_alu_u16_r0_shift = Polynomial(polys.avm_alu_u16_r0.shifted()); - polys.avm_alu_u16_r1_shift = Polynomial(polys.avm_alu_u16_r1.shifted()); - polys.avm_alu_u16_r2_shift = Polynomial(polys.avm_alu_u16_r2.shifted()); - polys.avm_alu_u16_r3_shift = Polynomial(polys.avm_alu_u16_r3.shifted()); - polys.avm_alu_u16_r4_shift = Polynomial(polys.avm_alu_u16_r4.shifted()); - polys.avm_alu_u16_r5_shift = Polynomial(polys.avm_alu_u16_r5.shifted()); - polys.avm_alu_u16_r6_shift = Polynomial(polys.avm_alu_u16_r6.shifted()); - polys.avm_alu_u8_r0_shift = Polynomial(polys.avm_alu_u8_r0.shifted()); - polys.avm_alu_u8_r1_shift = Polynomial(polys.avm_alu_u8_r1.shifted()); - polys.avm_binary_acc_ia_shift = Polynomial(polys.avm_binary_acc_ia.shifted()); - polys.avm_binary_acc_ib_shift = Polynomial(polys.avm_binary_acc_ib.shifted()); - polys.avm_binary_acc_ic_shift = Polynomial(polys.avm_binary_acc_ic.shifted()); - polys.avm_binary_mem_tag_ctr_shift = Polynomial(polys.avm_binary_mem_tag_ctr.shifted()); - polys.avm_binary_op_id_shift = Polynomial(polys.avm_binary_op_id.shifted()); - polys.avm_kernel_emit_l2_to_l1_msg_write_offset_shift = - Polynomial(polys.avm_kernel_emit_l2_to_l1_msg_write_offset.shifted()); - polys.avm_kernel_emit_note_hash_write_offset_shift = - Polynomial(polys.avm_kernel_emit_note_hash_write_offset.shifted()); - polys.avm_kernel_emit_nullifier_write_offset_shift = - Polynomial(polys.avm_kernel_emit_nullifier_write_offset.shifted()); - polys.avm_kernel_emit_unencrypted_log_write_offset_shift = - Polynomial(polys.avm_kernel_emit_unencrypted_log_write_offset.shifted()); - polys.avm_kernel_l1_to_l2_msg_exists_write_offset_shift = - Polynomial(polys.avm_kernel_l1_to_l2_msg_exists_write_offset.shifted()); - polys.avm_kernel_note_hash_exist_write_offset_shift = - Polynomial(polys.avm_kernel_note_hash_exist_write_offset.shifted()); - polys.avm_kernel_nullifier_exists_write_offset_shift = - Polynomial(polys.avm_kernel_nullifier_exists_write_offset.shifted()); - polys.avm_kernel_nullifier_non_exists_write_offset_shift = - Polynomial(polys.avm_kernel_nullifier_non_exists_write_offset.shifted()); - polys.avm_kernel_side_effect_counter_shift = Polynomial(polys.avm_kernel_side_effect_counter.shifted()); - polys.avm_kernel_sload_write_offset_shift = Polynomial(polys.avm_kernel_sload_write_offset.shifted()); - polys.avm_kernel_sstore_write_offset_shift = Polynomial(polys.avm_kernel_sstore_write_offset.shifted()); - polys.avm_main_da_gas_remaining_shift = Polynomial(polys.avm_main_da_gas_remaining.shifted()); - polys.avm_main_internal_return_ptr_shift = Polynomial(polys.avm_main_internal_return_ptr.shifted()); - polys.avm_main_l2_gas_remaining_shift = Polynomial(polys.avm_main_l2_gas_remaining.shifted()); - polys.avm_main_pc_shift = Polynomial(polys.avm_main_pc.shifted()); - polys.avm_mem_glob_addr_shift = Polynomial(polys.avm_mem_glob_addr.shifted()); - polys.avm_mem_mem_sel_shift = Polynomial(polys.avm_mem_mem_sel.shifted()); - polys.avm_mem_rw_shift = Polynomial(polys.avm_mem_rw.shifted()); - polys.avm_mem_tag_shift = Polynomial(polys.avm_mem_tag.shifted()); - polys.avm_mem_tsp_shift = Polynomial(polys.avm_mem_tsp.shifted()); - polys.avm_mem_val_shift = Polynomial(polys.avm_mem_val.shifted()); + polys.alu_a_hi_shift = Polynomial(polys.alu_a_hi.shifted()); + polys.alu_a_lo_shift = Polynomial(polys.alu_a_lo.shifted()); + polys.alu_b_hi_shift = Polynomial(polys.alu_b_hi.shifted()); + polys.alu_b_lo_shift = Polynomial(polys.alu_b_lo.shifted()); + polys.alu_cmp_rng_ctr_shift = Polynomial(polys.alu_cmp_rng_ctr.shifted()); + polys.alu_div_u16_r0_shift = Polynomial(polys.alu_div_u16_r0.shifted()); + polys.alu_div_u16_r1_shift = Polynomial(polys.alu_div_u16_r1.shifted()); + polys.alu_div_u16_r2_shift = Polynomial(polys.alu_div_u16_r2.shifted()); + polys.alu_div_u16_r3_shift = Polynomial(polys.alu_div_u16_r3.shifted()); + polys.alu_div_u16_r4_shift = Polynomial(polys.alu_div_u16_r4.shifted()); + polys.alu_div_u16_r5_shift = Polynomial(polys.alu_div_u16_r5.shifted()); + polys.alu_div_u16_r6_shift = Polynomial(polys.alu_div_u16_r6.shifted()); + polys.alu_div_u16_r7_shift = Polynomial(polys.alu_div_u16_r7.shifted()); + polys.alu_op_add_shift = Polynomial(polys.alu_op_add.shifted()); + polys.alu_op_cast_prev_shift = Polynomial(polys.alu_op_cast_prev.shifted()); + polys.alu_op_cast_shift = Polynomial(polys.alu_op_cast.shifted()); + polys.alu_op_div_shift = Polynomial(polys.alu_op_div.shifted()); + polys.alu_op_mul_shift = Polynomial(polys.alu_op_mul.shifted()); + polys.alu_op_shl_shift = Polynomial(polys.alu_op_shl.shifted()); + polys.alu_op_shr_shift = Polynomial(polys.alu_op_shr.shifted()); + polys.alu_op_sub_shift = Polynomial(polys.alu_op_sub.shifted()); + polys.alu_p_sub_a_hi_shift = Polynomial(polys.alu_p_sub_a_hi.shifted()); + polys.alu_p_sub_a_lo_shift = Polynomial(polys.alu_p_sub_a_lo.shifted()); + polys.alu_p_sub_b_hi_shift = Polynomial(polys.alu_p_sub_b_hi.shifted()); + polys.alu_p_sub_b_lo_shift = Polynomial(polys.alu_p_sub_b_lo.shifted()); + polys.alu_sel_alu_shift = Polynomial(polys.alu_sel_alu.shifted()); + polys.alu_sel_cmp_shift = Polynomial(polys.alu_sel_cmp.shifted()); + polys.alu_sel_div_rng_chk_shift = Polynomial(polys.alu_sel_div_rng_chk.shifted()); + polys.alu_sel_rng_chk_lookup_shift = Polynomial(polys.alu_sel_rng_chk_lookup.shifted()); + polys.alu_sel_rng_chk_shift = Polynomial(polys.alu_sel_rng_chk.shifted()); + polys.alu_u16_r0_shift = Polynomial(polys.alu_u16_r0.shifted()); + polys.alu_u16_r1_shift = Polynomial(polys.alu_u16_r1.shifted()); + polys.alu_u16_r2_shift = Polynomial(polys.alu_u16_r2.shifted()); + polys.alu_u16_r3_shift = Polynomial(polys.alu_u16_r3.shifted()); + polys.alu_u16_r4_shift = Polynomial(polys.alu_u16_r4.shifted()); + polys.alu_u16_r5_shift = Polynomial(polys.alu_u16_r5.shifted()); + polys.alu_u16_r6_shift = Polynomial(polys.alu_u16_r6.shifted()); + polys.alu_u8_r0_shift = Polynomial(polys.alu_u8_r0.shifted()); + polys.alu_u8_r1_shift = Polynomial(polys.alu_u8_r1.shifted()); + polys.binary_acc_ia_shift = Polynomial(polys.binary_acc_ia.shifted()); + polys.binary_acc_ib_shift = Polynomial(polys.binary_acc_ib.shifted()); + polys.binary_acc_ic_shift = Polynomial(polys.binary_acc_ic.shifted()); + polys.binary_mem_tag_ctr_shift = Polynomial(polys.binary_mem_tag_ctr.shifted()); + polys.binary_op_id_shift = Polynomial(polys.binary_op_id.shifted()); + polys.kernel_emit_l2_to_l1_msg_write_offset_shift = + Polynomial(polys.kernel_emit_l2_to_l1_msg_write_offset.shifted()); + polys.kernel_emit_note_hash_write_offset_shift = Polynomial(polys.kernel_emit_note_hash_write_offset.shifted()); + polys.kernel_emit_nullifier_write_offset_shift = Polynomial(polys.kernel_emit_nullifier_write_offset.shifted()); + polys.kernel_emit_unencrypted_log_write_offset_shift = + Polynomial(polys.kernel_emit_unencrypted_log_write_offset.shifted()); + polys.kernel_l1_to_l2_msg_exists_write_offset_shift = + Polynomial(polys.kernel_l1_to_l2_msg_exists_write_offset.shifted()); + polys.kernel_note_hash_exist_write_offset_shift = + Polynomial(polys.kernel_note_hash_exist_write_offset.shifted()); + polys.kernel_nullifier_exists_write_offset_shift = + Polynomial(polys.kernel_nullifier_exists_write_offset.shifted()); + polys.kernel_nullifier_non_exists_write_offset_shift = + Polynomial(polys.kernel_nullifier_non_exists_write_offset.shifted()); + polys.kernel_side_effect_counter_shift = Polynomial(polys.kernel_side_effect_counter.shifted()); + polys.kernel_sload_write_offset_shift = Polynomial(polys.kernel_sload_write_offset.shifted()); + polys.kernel_sstore_write_offset_shift = Polynomial(polys.kernel_sstore_write_offset.shifted()); + polys.main_da_gas_remaining_shift = Polynomial(polys.main_da_gas_remaining.shifted()); + polys.main_internal_return_ptr_shift = Polynomial(polys.main_internal_return_ptr.shifted()); + polys.main_l2_gas_remaining_shift = Polynomial(polys.main_l2_gas_remaining.shifted()); + polys.main_pc_shift = Polynomial(polys.main_pc.shifted()); + polys.mem_glob_addr_shift = Polynomial(polys.mem_glob_addr.shifted()); + polys.mem_rw_shift = Polynomial(polys.mem_rw.shifted()); + polys.mem_sel_mem_shift = Polynomial(polys.mem_sel_mem.shifted()); + polys.mem_tag_shift = Polynomial(polys.mem_tag.shifted()); + polys.mem_tsp_shift = Polynomial(polys.mem_tsp.shifted()); + polys.mem_val_shift = Polynomial(polys.mem_val.shifted()); return polys; } @@ -1049,54 +1044,51 @@ class AvmCircuitBuilder { return true; }; - auto avm_alu = [=]() { - return evaluate_relation.template operator()>("avm_alu", - Avm_vm::get_relation_label_avm_alu); + auto alu = [=]() { + return evaluate_relation.template operator()>("alu", Avm_vm::get_relation_label_alu); }; - auto avm_binary = [=]() { - return evaluate_relation.template operator()>("avm_binary", - Avm_vm::get_relation_label_avm_binary); + auto binary = [=]() { + return evaluate_relation.template operator()>("binary", + Avm_vm::get_relation_label_binary); }; - auto avm_conversion = [=]() { - return evaluate_relation.template operator()>( - "avm_conversion", Avm_vm::get_relation_label_avm_conversion); + auto conversion = [=]() { + return evaluate_relation.template operator()>("conversion", + Avm_vm::get_relation_label_conversion); }; - auto avm_keccakf1600 = [=]() { - return evaluate_relation.template operator()>( - "avm_keccakf1600", Avm_vm::get_relation_label_avm_keccakf1600); + auto keccakf1600 = [=]() { + return evaluate_relation.template operator()>( + "keccakf1600", Avm_vm::get_relation_label_keccakf1600); }; - auto avm_kernel = [=]() { - return evaluate_relation.template operator()>("avm_kernel", - Avm_vm::get_relation_label_avm_kernel); + auto kernel = [=]() { + return evaluate_relation.template operator()>("kernel", + Avm_vm::get_relation_label_kernel); }; - auto avm_main = [=]() { - return evaluate_relation.template operator()>("avm_main", - Avm_vm::get_relation_label_avm_main); + auto main = [=]() { + return evaluate_relation.template operator()>("main", Avm_vm::get_relation_label_main); }; - auto avm_mem = [=]() { - return evaluate_relation.template operator()>("avm_mem", - Avm_vm::get_relation_label_avm_mem); + auto mem = [=]() { + return evaluate_relation.template operator()>("mem", Avm_vm::get_relation_label_mem); }; - auto avm_pedersen = [=]() { - return evaluate_relation.template operator()>( - "avm_pedersen", Avm_vm::get_relation_label_avm_pedersen); + auto pedersen = [=]() { + return evaluate_relation.template operator()>("pedersen", + Avm_vm::get_relation_label_pedersen); }; - auto avm_poseidon2 = [=]() { - return evaluate_relation.template operator()>( - "avm_poseidon2", Avm_vm::get_relation_label_avm_poseidon2); + auto poseidon2 = [=]() { + return evaluate_relation.template operator()>("poseidon2", + Avm_vm::get_relation_label_poseidon2); }; - auto avm_sha256 = [=]() { - return evaluate_relation.template operator()>("avm_sha256", - Avm_vm::get_relation_label_avm_sha256); + auto sha256 = [=]() { + return evaluate_relation.template operator()>("sha256", + Avm_vm::get_relation_label_sha256); }; auto perm_main_alu = [=]() { @@ -1135,20 +1127,24 @@ class AvmCircuitBuilder { return evaluate_logderivative.template operator()>("PERM_MAIN_MEM_D"); }; - auto perm_main_mem_ind_a = [=]() { - return evaluate_logderivative.template operator()>("PERM_MAIN_MEM_IND_A"); + auto perm_main_mem_ind_addr_a = [=]() { + return evaluate_logderivative.template operator()>( + "PERM_MAIN_MEM_IND_ADDR_A"); }; - auto perm_main_mem_ind_b = [=]() { - return evaluate_logderivative.template operator()>("PERM_MAIN_MEM_IND_B"); + auto perm_main_mem_ind_addr_b = [=]() { + return evaluate_logderivative.template operator()>( + "PERM_MAIN_MEM_IND_ADDR_B"); }; - auto perm_main_mem_ind_c = [=]() { - return evaluate_logderivative.template operator()>("PERM_MAIN_MEM_IND_C"); + auto perm_main_mem_ind_addr_c = [=]() { + return evaluate_logderivative.template operator()>( + "PERM_MAIN_MEM_IND_ADDR_C"); }; - auto perm_main_mem_ind_d = [=]() { - return evaluate_logderivative.template operator()>("PERM_MAIN_MEM_IND_D"); + auto perm_main_mem_ind_addr_d = [=]() { + return evaluate_logderivative.template operator()>( + "PERM_MAIN_MEM_IND_ADDR_D"); }; auto lookup_byte_lengths = [=]() { @@ -1329,25 +1325,25 @@ class AvmCircuitBuilder { // Evaluate check circuit closures as futures std::vector> relation_futures; - relation_futures.emplace_back(std::async(std::launch::async, avm_alu)); + relation_futures.emplace_back(std::async(std::launch::async, alu)); - relation_futures.emplace_back(std::async(std::launch::async, avm_binary)); + relation_futures.emplace_back(std::async(std::launch::async, binary)); - relation_futures.emplace_back(std::async(std::launch::async, avm_conversion)); + relation_futures.emplace_back(std::async(std::launch::async, conversion)); - relation_futures.emplace_back(std::async(std::launch::async, avm_keccakf1600)); + relation_futures.emplace_back(std::async(std::launch::async, keccakf1600)); - relation_futures.emplace_back(std::async(std::launch::async, avm_kernel)); + relation_futures.emplace_back(std::async(std::launch::async, kernel)); - relation_futures.emplace_back(std::async(std::launch::async, avm_main)); + relation_futures.emplace_back(std::async(std::launch::async, main)); - relation_futures.emplace_back(std::async(std::launch::async, avm_mem)); + relation_futures.emplace_back(std::async(std::launch::async, mem)); - relation_futures.emplace_back(std::async(std::launch::async, avm_pedersen)); + relation_futures.emplace_back(std::async(std::launch::async, pedersen)); - relation_futures.emplace_back(std::async(std::launch::async, avm_poseidon2)); + relation_futures.emplace_back(std::async(std::launch::async, poseidon2)); - relation_futures.emplace_back(std::async(std::launch::async, avm_sha256)); + relation_futures.emplace_back(std::async(std::launch::async, sha256)); relation_futures.emplace_back(std::async(std::launch::async, perm_main_alu)); @@ -1367,13 +1363,13 @@ class AvmCircuitBuilder { relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_d)); - relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_ind_a)); + relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_ind_addr_a)); - relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_ind_b)); + relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_ind_addr_b)); - relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_ind_c)); + relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_ind_addr_c)); - relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_ind_d)); + relation_futures.emplace_back(std::async(std::launch::async, perm_main_mem_ind_addr_d)); relation_futures.emplace_back(std::async(std::launch::async, lookup_byte_lengths)); @@ -1466,25 +1462,25 @@ class AvmCircuitBuilder { } #else - avm_alu(); + alu(); - avm_binary(); + binary(); - avm_conversion(); + conversion(); - avm_keccakf1600(); + keccakf1600(); - avm_kernel(); + kernel(); - avm_main(); + main(); - avm_mem(); + mem(); - avm_pedersen(); + pedersen(); - avm_poseidon2(); + poseidon2(); - avm_sha256(); + sha256(); perm_main_alu(); @@ -1504,13 +1500,13 @@ class AvmCircuitBuilder { perm_main_mem_d(); - perm_main_mem_ind_a(); + perm_main_mem_ind_addr_a(); - perm_main_mem_ind_b(); + perm_main_mem_ind_addr_b(); - perm_main_mem_ind_c(); + perm_main_mem_ind_addr_c(); - perm_main_mem_ind_d(); + perm_main_mem_ind_addr_d(); lookup_byte_lengths(); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp index 5d520d28dc3..41cae773d42 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp @@ -13,18 +13,13 @@ #include "barretenberg/flavor/flavor_macros.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" #include "barretenberg/polynomials/polynomial.hpp" -#include "barretenberg/relations/generated/avm/avm_alu.hpp" -#include "barretenberg/relations/generated/avm/avm_binary.hpp" -#include "barretenberg/relations/generated/avm/avm_conversion.hpp" -#include "barretenberg/relations/generated/avm/avm_keccakf1600.hpp" -#include "barretenberg/relations/generated/avm/avm_kernel.hpp" -#include "barretenberg/relations/generated/avm/avm_main.hpp" -#include "barretenberg/relations/generated/avm/avm_mem.hpp" -#include "barretenberg/relations/generated/avm/avm_pedersen.hpp" -#include "barretenberg/relations/generated/avm/avm_poseidon2.hpp" -#include "barretenberg/relations/generated/avm/avm_sha256.hpp" +#include "barretenberg/relations/generated/avm/alu.hpp" +#include "barretenberg/relations/generated/avm/binary.hpp" +#include "barretenberg/relations/generated/avm/conversion.hpp" #include "barretenberg/relations/generated/avm/incl_main_tag_err.hpp" #include "barretenberg/relations/generated/avm/incl_mem_tag_err.hpp" +#include "barretenberg/relations/generated/avm/keccakf1600.hpp" +#include "barretenberg/relations/generated/avm/kernel.hpp" #include "barretenberg/relations/generated/avm/kernel_output_lookup.hpp" #include "barretenberg/relations/generated/avm/lookup_byte_lengths.hpp" #include "barretenberg/relations/generated/avm/lookup_byte_operations.hpp" @@ -60,6 +55,9 @@ #include "barretenberg/relations/generated/avm/lookup_u16_9.hpp" #include "barretenberg/relations/generated/avm/lookup_u8_0.hpp" #include "barretenberg/relations/generated/avm/lookup_u8_1.hpp" +#include "barretenberg/relations/generated/avm/main.hpp" +#include "barretenberg/relations/generated/avm/mem.hpp" +#include "barretenberg/relations/generated/avm/pedersen.hpp" #include "barretenberg/relations/generated/avm/perm_main_alu.hpp" #include "barretenberg/relations/generated/avm/perm_main_bin.hpp" #include "barretenberg/relations/generated/avm/perm_main_conv.hpp" @@ -67,16 +65,18 @@ #include "barretenberg/relations/generated/avm/perm_main_mem_b.hpp" #include "barretenberg/relations/generated/avm/perm_main_mem_c.hpp" #include "barretenberg/relations/generated/avm/perm_main_mem_d.hpp" -#include "barretenberg/relations/generated/avm/perm_main_mem_ind_a.hpp" -#include "barretenberg/relations/generated/avm/perm_main_mem_ind_b.hpp" -#include "barretenberg/relations/generated/avm/perm_main_mem_ind_c.hpp" -#include "barretenberg/relations/generated/avm/perm_main_mem_ind_d.hpp" +#include "barretenberg/relations/generated/avm/perm_main_mem_ind_addr_a.hpp" +#include "barretenberg/relations/generated/avm/perm_main_mem_ind_addr_b.hpp" +#include "barretenberg/relations/generated/avm/perm_main_mem_ind_addr_c.hpp" +#include "barretenberg/relations/generated/avm/perm_main_mem_ind_addr_d.hpp" #include "barretenberg/relations/generated/avm/perm_main_pedersen.hpp" #include "barretenberg/relations/generated/avm/perm_main_pos2_perm.hpp" +#include "barretenberg/relations/generated/avm/poseidon2.hpp" #include "barretenberg/relations/generated/avm/range_check_da_gas_hi.hpp" #include "barretenberg/relations/generated/avm/range_check_da_gas_lo.hpp" #include "barretenberg/relations/generated/avm/range_check_l2_gas_hi.hpp" #include "barretenberg/relations/generated/avm/range_check_l2_gas_lo.hpp" +#include "barretenberg/relations/generated/avm/sha256.hpp" #include "barretenberg/transcript/transcript.hpp" namespace bb { @@ -113,10 +113,10 @@ class AvmFlavor { perm_main_mem_b_relation, perm_main_mem_c_relation, perm_main_mem_d_relation, - perm_main_mem_ind_a_relation, - perm_main_mem_ind_b_relation, - perm_main_mem_ind_c_relation, - perm_main_mem_ind_d_relation, + perm_main_mem_ind_addr_a_relation, + perm_main_mem_ind_addr_b_relation, + perm_main_mem_ind_addr_c_relation, + perm_main_mem_ind_addr_d_relation, lookup_byte_lengths_relation, lookup_byte_operations_relation, lookup_opcode_gas_relation, @@ -159,16 +159,16 @@ class AvmFlavor { lookup_div_u16_6_relation, lookup_div_u16_7_relation>; - using Relations = std::tuple, - Avm_vm::avm_binary, - Avm_vm::avm_conversion, - Avm_vm::avm_keccakf1600, - Avm_vm::avm_kernel, - Avm_vm::avm_main, - Avm_vm::avm_mem, - Avm_vm::avm_pedersen, - Avm_vm::avm_poseidon2, - Avm_vm::avm_sha256, + using Relations = std::tuple, + Avm_vm::binary, + Avm_vm::conversion, + Avm_vm::keccakf1600, + Avm_vm::kernel, + Avm_vm::main, + Avm_vm::mem, + Avm_vm::pedersen, + Avm_vm::poseidon2, + Avm_vm::sha256, perm_main_alu_relation, perm_main_bin_relation, perm_main_conv_relation, @@ -178,10 +178,10 @@ class AvmFlavor { perm_main_mem_b_relation, perm_main_mem_c_relation, perm_main_mem_d_relation, - perm_main_mem_ind_a_relation, - perm_main_mem_ind_b_relation, - perm_main_mem_ind_c_relation, - perm_main_mem_ind_d_relation, + perm_main_mem_ind_addr_a_relation, + perm_main_mem_ind_addr_b_relation, + perm_main_mem_ind_addr_c_relation, + perm_main_mem_ind_addr_d_relation, lookup_byte_lengths_relation, lookup_byte_operations_relation, lookup_opcode_gas_relation, @@ -245,9 +245,9 @@ class AvmFlavor { public: using DataType = DataType_; - DEFINE_FLAVOR_MEMBERS(DataType, avm_main_clk, avm_main_first) + DEFINE_FLAVOR_MEMBERS(DataType, main_clk, main_sel_first) - RefVector get_selectors() { return { avm_main_clk, avm_main_first }; }; + RefVector get_selectors() { return { main_clk, main_sel_first }; }; RefVector get_sigma_polynomials() { return {}; }; RefVector get_id_polynomials() { return {}; }; RefVector get_table_polynomials() { return {}; }; @@ -256,294 +256,294 @@ class AvmFlavor { template class WitnessEntities { public: DEFINE_FLAVOR_MEMBERS(DataType, - avm_alu_a_hi, - avm_alu_a_lo, - avm_alu_alu_sel, - avm_alu_b_hi, - avm_alu_b_lo, - avm_alu_borrow, - avm_alu_cf, - avm_alu_clk, - avm_alu_cmp_rng_ctr, - avm_alu_cmp_sel, - avm_alu_div_rng_chk_selector, - avm_alu_div_u16_r0, - avm_alu_div_u16_r1, - avm_alu_div_u16_r2, - avm_alu_div_u16_r3, - avm_alu_div_u16_r4, - avm_alu_div_u16_r5, - avm_alu_div_u16_r6, - avm_alu_div_u16_r7, - avm_alu_divisor_hi, - avm_alu_divisor_lo, - avm_alu_ff_tag, - avm_alu_ia, - avm_alu_ib, - avm_alu_ic, - avm_alu_in_tag, - avm_alu_op_add, - avm_alu_op_cast, - avm_alu_op_cast_prev, - avm_alu_op_div, - avm_alu_op_div_a_lt_b, - avm_alu_op_div_std, - avm_alu_op_eq, - avm_alu_op_eq_diff_inv, - avm_alu_op_lt, - avm_alu_op_lte, - avm_alu_op_mul, - avm_alu_op_not, - avm_alu_op_shl, - avm_alu_op_shr, - avm_alu_op_sub, - avm_alu_p_a_borrow, - avm_alu_p_b_borrow, - avm_alu_p_sub_a_hi, - avm_alu_p_sub_a_lo, - avm_alu_p_sub_b_hi, - avm_alu_p_sub_b_lo, - avm_alu_partial_prod_hi, - avm_alu_partial_prod_lo, - avm_alu_quotient_hi, - avm_alu_quotient_lo, - avm_alu_remainder, - avm_alu_res_hi, - avm_alu_res_lo, - avm_alu_rng_chk_lookup_selector, - avm_alu_rng_chk_sel, - avm_alu_shift_lt_bit_len, - avm_alu_shift_sel, - avm_alu_t_sub_s_bits, - avm_alu_two_pow_s, - avm_alu_two_pow_t_sub_s, - avm_alu_u128_tag, - avm_alu_u16_r0, - avm_alu_u16_r1, - avm_alu_u16_r10, - avm_alu_u16_r11, - avm_alu_u16_r12, - avm_alu_u16_r13, - avm_alu_u16_r14, - avm_alu_u16_r2, - avm_alu_u16_r3, - avm_alu_u16_r4, - avm_alu_u16_r5, - avm_alu_u16_r6, - avm_alu_u16_r7, - avm_alu_u16_r8, - avm_alu_u16_r9, - avm_alu_u16_tag, - avm_alu_u32_tag, - avm_alu_u64_tag, - avm_alu_u8_r0, - avm_alu_u8_r1, - avm_alu_u8_tag, - avm_binary_acc_ia, - avm_binary_acc_ib, - avm_binary_acc_ic, - avm_binary_bin_sel, - avm_binary_clk, - avm_binary_ia_bytes, - avm_binary_ib_bytes, - avm_binary_ic_bytes, - avm_binary_in_tag, - avm_binary_mem_tag_ctr, - avm_binary_mem_tag_ctr_inv, - avm_binary_op_id, - avm_binary_start, - avm_byte_lookup_bin_sel, - avm_byte_lookup_table_byte_lengths, - avm_byte_lookup_table_in_tags, - avm_byte_lookup_table_input_a, - avm_byte_lookup_table_input_b, - avm_byte_lookup_table_op_id, - avm_byte_lookup_table_output, - avm_conversion_clk, - avm_conversion_input, - avm_conversion_num_limbs, - avm_conversion_radix, - avm_conversion_to_radix_le_sel, - avm_gas_da_gas_fixed_table, - avm_gas_gas_cost_sel, - avm_gas_l2_gas_fixed_table, - avm_keccakf1600_clk, - avm_keccakf1600_input, - avm_keccakf1600_keccakf1600_sel, - avm_keccakf1600_output, - avm_kernel_emit_l2_to_l1_msg_write_offset, - avm_kernel_emit_note_hash_write_offset, - avm_kernel_emit_nullifier_write_offset, - avm_kernel_emit_unencrypted_log_write_offset, - avm_kernel_kernel_in_offset, - avm_kernel_kernel_inputs, - avm_kernel_kernel_metadata_out, - avm_kernel_kernel_out_offset, - avm_kernel_kernel_side_effect_out, - avm_kernel_kernel_value_out, - avm_kernel_l1_to_l2_msg_exists_write_offset, - avm_kernel_note_hash_exist_write_offset, - avm_kernel_nullifier_exists_write_offset, - avm_kernel_nullifier_non_exists_write_offset, - avm_kernel_q_public_input_kernel_add_to_table, - avm_kernel_q_public_input_kernel_out_add_to_table, - avm_kernel_side_effect_counter, - avm_kernel_sload_write_offset, - avm_kernel_sstore_write_offset, - avm_main_abs_da_rem_gas_hi, - avm_main_abs_da_rem_gas_lo, - avm_main_abs_l2_rem_gas_hi, - avm_main_abs_l2_rem_gas_lo, - avm_main_alu_in_tag, - avm_main_alu_sel, - avm_main_bin_op_id, - avm_main_bin_sel, - avm_main_call_ptr, - avm_main_da_gas_op, - avm_main_da_gas_remaining, - avm_main_da_out_of_gas, - avm_main_gas_cost_active, - avm_main_ia, - avm_main_ib, - avm_main_ic, - avm_main_id, - avm_main_id_zero, - avm_main_ind_a, - avm_main_ind_b, - avm_main_ind_c, - avm_main_ind_d, - avm_main_ind_op_a, - avm_main_ind_op_b, - avm_main_ind_op_c, - avm_main_ind_op_d, - avm_main_internal_return_ptr, - avm_main_inv, - avm_main_l2_gas_op, - avm_main_l2_gas_remaining, - avm_main_l2_out_of_gas, - avm_main_last, - avm_main_mem_idx_a, - avm_main_mem_idx_b, - avm_main_mem_idx_c, - avm_main_mem_idx_d, - avm_main_mem_op_a, - avm_main_mem_op_activate_gas, - avm_main_mem_op_b, - avm_main_mem_op_c, - avm_main_mem_op_d, - avm_main_op_err, - avm_main_opcode_val, - avm_main_pc, - avm_main_q_kernel_lookup, - avm_main_q_kernel_output_lookup, - avm_main_r_in_tag, - avm_main_rwa, - avm_main_rwb, - avm_main_rwc, - avm_main_rwd, - avm_main_sel_cmov, - avm_main_sel_external_call, - avm_main_sel_halt, - avm_main_sel_internal_call, - avm_main_sel_internal_return, - avm_main_sel_jump, - avm_main_sel_jumpi, - avm_main_sel_mov, - avm_main_sel_mov_a, - avm_main_sel_mov_b, - avm_main_sel_op_add, - avm_main_sel_op_address, - avm_main_sel_op_and, - avm_main_sel_op_block_number, - avm_main_sel_op_cast, - avm_main_sel_op_chain_id, - avm_main_sel_op_coinbase, - avm_main_sel_op_dagasleft, - avm_main_sel_op_div, - avm_main_sel_op_emit_l2_to_l1_msg, - avm_main_sel_op_emit_note_hash, - avm_main_sel_op_emit_nullifier, - avm_main_sel_op_emit_unencrypted_log, - avm_main_sel_op_eq, - avm_main_sel_op_fdiv, - avm_main_sel_op_fee_per_da_gas, - avm_main_sel_op_fee_per_l2_gas, - avm_main_sel_op_get_contract_instance, - avm_main_sel_op_keccak, - avm_main_sel_op_l1_to_l2_msg_exists, - avm_main_sel_op_l2gasleft, - avm_main_sel_op_lt, - avm_main_sel_op_lte, - avm_main_sel_op_mul, - avm_main_sel_op_not, - avm_main_sel_op_note_hash_exists, - avm_main_sel_op_nullifier_exists, - avm_main_sel_op_or, - avm_main_sel_op_pedersen, - avm_main_sel_op_poseidon2, - avm_main_sel_op_radix_le, - avm_main_sel_op_sender, - avm_main_sel_op_sha256, - avm_main_sel_op_shl, - avm_main_sel_op_shr, - avm_main_sel_op_sload, - avm_main_sel_op_sstore, - avm_main_sel_op_storage_address, - avm_main_sel_op_sub, - avm_main_sel_op_timestamp, - avm_main_sel_op_transaction_fee, - avm_main_sel_op_version, - avm_main_sel_op_xor, - avm_main_sel_rng_16, - avm_main_sel_rng_8, - avm_main_space_id, - avm_main_table_pow_2, - avm_main_tag_err, - avm_main_w_in_tag, - avm_mem_addr, - avm_mem_clk, - avm_mem_diff_hi, - avm_mem_diff_lo, - avm_mem_diff_mid, - avm_mem_glob_addr, - avm_mem_ind_op_a, - avm_mem_ind_op_b, - avm_mem_ind_op_c, - avm_mem_ind_op_d, - avm_mem_last, - avm_mem_lastAccess, - avm_mem_mem_sel, - avm_mem_one_min_inv, - avm_mem_op_a, - avm_mem_op_b, - avm_mem_op_c, - avm_mem_op_d, - avm_mem_r_in_tag, - avm_mem_rng_chk_sel, - avm_mem_rw, - avm_mem_sel_cmov, - avm_mem_sel_mov_a, - avm_mem_sel_mov_b, - avm_mem_skip_check_tag, - avm_mem_space_id, - avm_mem_tag, - avm_mem_tag_err, - avm_mem_tsp, - avm_mem_val, - avm_mem_w_in_tag, - avm_pedersen_clk, - avm_pedersen_input, - avm_pedersen_output, - avm_pedersen_pedersen_sel, - avm_poseidon2_clk, - avm_poseidon2_input, - avm_poseidon2_output, - avm_poseidon2_poseidon_perm_sel, - avm_sha256_clk, - avm_sha256_input, - avm_sha256_output, - avm_sha256_sha256_compression_sel, - avm_sha256_state, + alu_a_hi, + alu_a_lo, + alu_b_hi, + alu_b_lo, + alu_borrow, + alu_cf, + alu_clk, + alu_cmp_rng_ctr, + alu_div_u16_r0, + alu_div_u16_r1, + alu_div_u16_r2, + alu_div_u16_r3, + alu_div_u16_r4, + alu_div_u16_r5, + alu_div_u16_r6, + alu_div_u16_r7, + alu_divisor_hi, + alu_divisor_lo, + alu_ff_tag, + alu_ia, + alu_ib, + alu_ic, + alu_in_tag, + alu_op_add, + alu_op_cast, + alu_op_cast_prev, + alu_op_div, + alu_op_div_a_lt_b, + alu_op_div_std, + alu_op_eq, + alu_op_eq_diff_inv, + alu_op_lt, + alu_op_lte, + alu_op_mul, + alu_op_not, + alu_op_shl, + alu_op_shr, + alu_op_sub, + alu_p_a_borrow, + alu_p_b_borrow, + alu_p_sub_a_hi, + alu_p_sub_a_lo, + alu_p_sub_b_hi, + alu_p_sub_b_lo, + alu_partial_prod_hi, + alu_partial_prod_lo, + alu_quotient_hi, + alu_quotient_lo, + alu_remainder, + alu_res_hi, + alu_res_lo, + alu_sel_alu, + alu_sel_cmp, + alu_sel_div_rng_chk, + alu_sel_rng_chk, + alu_sel_rng_chk_lookup, + alu_sel_shift_which, + alu_shift_lt_bit_len, + alu_t_sub_s_bits, + alu_two_pow_s, + alu_two_pow_t_sub_s, + alu_u128_tag, + alu_u16_r0, + alu_u16_r1, + alu_u16_r10, + alu_u16_r11, + alu_u16_r12, + alu_u16_r13, + alu_u16_r14, + alu_u16_r2, + alu_u16_r3, + alu_u16_r4, + alu_u16_r5, + alu_u16_r6, + alu_u16_r7, + alu_u16_r8, + alu_u16_r9, + alu_u16_tag, + alu_u32_tag, + alu_u64_tag, + alu_u8_r0, + alu_u8_r1, + alu_u8_tag, + binary_acc_ia, + binary_acc_ib, + binary_acc_ic, + binary_clk, + binary_ia_bytes, + binary_ib_bytes, + binary_ic_bytes, + binary_in_tag, + binary_mem_tag_ctr, + binary_mem_tag_ctr_inv, + binary_op_id, + binary_sel_bin, + binary_start, + byte_lookup_sel_bin, + byte_lookup_table_byte_lengths, + byte_lookup_table_in_tags, + byte_lookup_table_input_a, + byte_lookup_table_input_b, + byte_lookup_table_op_id, + byte_lookup_table_output, + conversion_clk, + conversion_input, + conversion_num_limbs, + conversion_radix, + conversion_sel_to_radix_le, + gas_da_gas_fixed_table, + gas_l2_gas_fixed_table, + gas_sel_gas_cost, + keccakf1600_clk, + keccakf1600_input, + keccakf1600_output, + keccakf1600_sel_keccakf1600, + kernel_emit_l2_to_l1_msg_write_offset, + kernel_emit_note_hash_write_offset, + kernel_emit_nullifier_write_offset, + kernel_emit_unencrypted_log_write_offset, + kernel_kernel_in_offset, + kernel_kernel_inputs, + kernel_kernel_metadata_out, + kernel_kernel_out_offset, + kernel_kernel_side_effect_out, + kernel_kernel_value_out, + kernel_l1_to_l2_msg_exists_write_offset, + kernel_note_hash_exist_write_offset, + kernel_nullifier_exists_write_offset, + kernel_nullifier_non_exists_write_offset, + kernel_q_public_input_kernel_add_to_table, + kernel_q_public_input_kernel_out_add_to_table, + kernel_side_effect_counter, + kernel_sload_write_offset, + kernel_sstore_write_offset, + main_abs_da_rem_gas_hi, + main_abs_da_rem_gas_lo, + main_abs_l2_rem_gas_hi, + main_abs_l2_rem_gas_lo, + main_alu_in_tag, + main_bin_op_id, + main_call_ptr, + main_da_gas_op_cost, + main_da_gas_remaining, + main_da_out_of_gas, + main_ia, + main_ib, + main_ic, + main_id, + main_id_zero, + main_ind_addr_a, + main_ind_addr_b, + main_ind_addr_c, + main_ind_addr_d, + main_internal_return_ptr, + main_inv, + main_l2_gas_op_cost, + main_l2_gas_remaining, + main_l2_out_of_gas, + main_mem_addr_a, + main_mem_addr_b, + main_mem_addr_c, + main_mem_addr_d, + main_op_err, + main_opcode_val, + main_pc, + main_r_in_tag, + main_rwa, + main_rwb, + main_rwc, + main_rwd, + main_sel_alu, + main_sel_bin, + main_sel_gas_accounting_active, + main_sel_last, + main_sel_mem_op_a, + main_sel_mem_op_activate_gas, + main_sel_mem_op_b, + main_sel_mem_op_c, + main_sel_mem_op_d, + main_sel_mov_ia_to_ic, + main_sel_mov_ib_to_ic, + main_sel_op_add, + main_sel_op_address, + main_sel_op_and, + main_sel_op_block_number, + main_sel_op_cast, + main_sel_op_chain_id, + main_sel_op_cmov, + main_sel_op_coinbase, + main_sel_op_dagasleft, + main_sel_op_div, + main_sel_op_emit_l2_to_l1_msg, + main_sel_op_emit_note_hash, + main_sel_op_emit_nullifier, + main_sel_op_emit_unencrypted_log, + main_sel_op_eq, + main_sel_op_external_call, + main_sel_op_fdiv, + main_sel_op_fee_per_da_gas, + main_sel_op_fee_per_l2_gas, + main_sel_op_get_contract_instance, + main_sel_op_halt, + main_sel_op_internal_call, + main_sel_op_internal_return, + main_sel_op_jump, + main_sel_op_jumpi, + main_sel_op_keccak, + main_sel_op_l1_to_l2_msg_exists, + main_sel_op_l2gasleft, + main_sel_op_lt, + main_sel_op_lte, + main_sel_op_mov, + main_sel_op_mul, + main_sel_op_not, + main_sel_op_note_hash_exists, + main_sel_op_nullifier_exists, + main_sel_op_or, + main_sel_op_pedersen, + main_sel_op_poseidon2, + main_sel_op_radix_le, + main_sel_op_sender, + main_sel_op_sha256, + main_sel_op_shl, + main_sel_op_shr, + main_sel_op_sload, + main_sel_op_sstore, + main_sel_op_storage_address, + main_sel_op_sub, + main_sel_op_timestamp, + main_sel_op_transaction_fee, + main_sel_op_version, + main_sel_op_xor, + main_sel_q_kernel_lookup, + main_sel_q_kernel_output_lookup, + main_sel_resolve_ind_addr_a, + main_sel_resolve_ind_addr_b, + main_sel_resolve_ind_addr_c, + main_sel_resolve_ind_addr_d, + main_sel_rng_16, + main_sel_rng_8, + main_space_id, + main_table_pow_2, + main_tag_err, + main_w_in_tag, + mem_addr, + mem_clk, + mem_diff_hi, + mem_diff_lo, + mem_diff_mid, + mem_glob_addr, + mem_last, + mem_lastAccess, + mem_one_min_inv, + mem_r_in_tag, + mem_rw, + mem_sel_mem, + mem_sel_mov_ia_to_ic, + mem_sel_mov_ib_to_ic, + mem_sel_op_a, + mem_sel_op_b, + mem_sel_op_c, + mem_sel_op_cmov, + mem_sel_op_d, + mem_sel_resolve_ind_addr_a, + mem_sel_resolve_ind_addr_b, + mem_sel_resolve_ind_addr_c, + mem_sel_resolve_ind_addr_d, + mem_sel_rng_chk, + mem_skip_check_tag, + mem_space_id, + mem_tag, + mem_tag_err, + mem_tsp, + mem_val, + mem_w_in_tag, + pedersen_clk, + pedersen_input, + pedersen_output, + pedersen_sel_pedersen, + poseidon2_clk, + poseidon2_input, + poseidon2_output, + poseidon2_sel_poseidon_perm, + sha256_clk, + sha256_input, + sha256_output, + sha256_sel_sha256_compression, + sha256_state, perm_main_alu, perm_main_bin, perm_main_conv, @@ -553,10 +553,10 @@ class AvmFlavor { perm_main_mem_b, perm_main_mem_c, perm_main_mem_d, - perm_main_mem_ind_a, - perm_main_mem_ind_b, - perm_main_mem_ind_c, - perm_main_mem_ind_d, + perm_main_mem_ind_addr_a, + perm_main_mem_ind_addr_b, + perm_main_mem_ind_addr_c, + perm_main_mem_ind_addr_d, lookup_byte_lengths, lookup_byte_operations, lookup_opcode_gas, @@ -642,294 +642,294 @@ class AvmFlavor { RefVector get_wires() { - return { avm_alu_a_hi, - avm_alu_a_lo, - avm_alu_alu_sel, - avm_alu_b_hi, - avm_alu_b_lo, - avm_alu_borrow, - avm_alu_cf, - avm_alu_clk, - avm_alu_cmp_rng_ctr, - avm_alu_cmp_sel, - avm_alu_div_rng_chk_selector, - avm_alu_div_u16_r0, - avm_alu_div_u16_r1, - avm_alu_div_u16_r2, - avm_alu_div_u16_r3, - avm_alu_div_u16_r4, - avm_alu_div_u16_r5, - avm_alu_div_u16_r6, - avm_alu_div_u16_r7, - avm_alu_divisor_hi, - avm_alu_divisor_lo, - avm_alu_ff_tag, - avm_alu_ia, - avm_alu_ib, - avm_alu_ic, - avm_alu_in_tag, - avm_alu_op_add, - avm_alu_op_cast, - avm_alu_op_cast_prev, - avm_alu_op_div, - avm_alu_op_div_a_lt_b, - avm_alu_op_div_std, - avm_alu_op_eq, - avm_alu_op_eq_diff_inv, - avm_alu_op_lt, - avm_alu_op_lte, - avm_alu_op_mul, - avm_alu_op_not, - avm_alu_op_shl, - avm_alu_op_shr, - avm_alu_op_sub, - avm_alu_p_a_borrow, - avm_alu_p_b_borrow, - avm_alu_p_sub_a_hi, - avm_alu_p_sub_a_lo, - avm_alu_p_sub_b_hi, - avm_alu_p_sub_b_lo, - avm_alu_partial_prod_hi, - avm_alu_partial_prod_lo, - avm_alu_quotient_hi, - avm_alu_quotient_lo, - avm_alu_remainder, - avm_alu_res_hi, - avm_alu_res_lo, - avm_alu_rng_chk_lookup_selector, - avm_alu_rng_chk_sel, - avm_alu_shift_lt_bit_len, - avm_alu_shift_sel, - avm_alu_t_sub_s_bits, - avm_alu_two_pow_s, - avm_alu_two_pow_t_sub_s, - avm_alu_u128_tag, - avm_alu_u16_r0, - avm_alu_u16_r1, - avm_alu_u16_r10, - avm_alu_u16_r11, - avm_alu_u16_r12, - avm_alu_u16_r13, - avm_alu_u16_r14, - avm_alu_u16_r2, - avm_alu_u16_r3, - avm_alu_u16_r4, - avm_alu_u16_r5, - avm_alu_u16_r6, - avm_alu_u16_r7, - avm_alu_u16_r8, - avm_alu_u16_r9, - avm_alu_u16_tag, - avm_alu_u32_tag, - avm_alu_u64_tag, - avm_alu_u8_r0, - avm_alu_u8_r1, - avm_alu_u8_tag, - avm_binary_acc_ia, - avm_binary_acc_ib, - avm_binary_acc_ic, - avm_binary_bin_sel, - avm_binary_clk, - avm_binary_ia_bytes, - avm_binary_ib_bytes, - avm_binary_ic_bytes, - avm_binary_in_tag, - avm_binary_mem_tag_ctr, - avm_binary_mem_tag_ctr_inv, - avm_binary_op_id, - avm_binary_start, - avm_byte_lookup_bin_sel, - avm_byte_lookup_table_byte_lengths, - avm_byte_lookup_table_in_tags, - avm_byte_lookup_table_input_a, - avm_byte_lookup_table_input_b, - avm_byte_lookup_table_op_id, - avm_byte_lookup_table_output, - avm_conversion_clk, - avm_conversion_input, - avm_conversion_num_limbs, - avm_conversion_radix, - avm_conversion_to_radix_le_sel, - avm_gas_da_gas_fixed_table, - avm_gas_gas_cost_sel, - avm_gas_l2_gas_fixed_table, - avm_keccakf1600_clk, - avm_keccakf1600_input, - avm_keccakf1600_keccakf1600_sel, - avm_keccakf1600_output, - avm_kernel_emit_l2_to_l1_msg_write_offset, - avm_kernel_emit_note_hash_write_offset, - avm_kernel_emit_nullifier_write_offset, - avm_kernel_emit_unencrypted_log_write_offset, - avm_kernel_kernel_in_offset, - avm_kernel_kernel_inputs, - avm_kernel_kernel_metadata_out, - avm_kernel_kernel_out_offset, - avm_kernel_kernel_side_effect_out, - avm_kernel_kernel_value_out, - avm_kernel_l1_to_l2_msg_exists_write_offset, - avm_kernel_note_hash_exist_write_offset, - avm_kernel_nullifier_exists_write_offset, - avm_kernel_nullifier_non_exists_write_offset, - avm_kernel_q_public_input_kernel_add_to_table, - avm_kernel_q_public_input_kernel_out_add_to_table, - avm_kernel_side_effect_counter, - avm_kernel_sload_write_offset, - avm_kernel_sstore_write_offset, - avm_main_abs_da_rem_gas_hi, - avm_main_abs_da_rem_gas_lo, - avm_main_abs_l2_rem_gas_hi, - avm_main_abs_l2_rem_gas_lo, - avm_main_alu_in_tag, - avm_main_alu_sel, - avm_main_bin_op_id, - avm_main_bin_sel, - avm_main_call_ptr, - avm_main_da_gas_op, - avm_main_da_gas_remaining, - avm_main_da_out_of_gas, - avm_main_gas_cost_active, - avm_main_ia, - avm_main_ib, - avm_main_ic, - avm_main_id, - avm_main_id_zero, - avm_main_ind_a, - avm_main_ind_b, - avm_main_ind_c, - avm_main_ind_d, - avm_main_ind_op_a, - avm_main_ind_op_b, - avm_main_ind_op_c, - avm_main_ind_op_d, - avm_main_internal_return_ptr, - avm_main_inv, - avm_main_l2_gas_op, - avm_main_l2_gas_remaining, - avm_main_l2_out_of_gas, - avm_main_last, - avm_main_mem_idx_a, - avm_main_mem_idx_b, - avm_main_mem_idx_c, - avm_main_mem_idx_d, - avm_main_mem_op_a, - avm_main_mem_op_activate_gas, - avm_main_mem_op_b, - avm_main_mem_op_c, - avm_main_mem_op_d, - avm_main_op_err, - avm_main_opcode_val, - avm_main_pc, - avm_main_q_kernel_lookup, - avm_main_q_kernel_output_lookup, - avm_main_r_in_tag, - avm_main_rwa, - avm_main_rwb, - avm_main_rwc, - avm_main_rwd, - avm_main_sel_cmov, - avm_main_sel_external_call, - avm_main_sel_halt, - avm_main_sel_internal_call, - avm_main_sel_internal_return, - avm_main_sel_jump, - avm_main_sel_jumpi, - avm_main_sel_mov, - avm_main_sel_mov_a, - avm_main_sel_mov_b, - avm_main_sel_op_add, - avm_main_sel_op_address, - avm_main_sel_op_and, - avm_main_sel_op_block_number, - avm_main_sel_op_cast, - avm_main_sel_op_chain_id, - avm_main_sel_op_coinbase, - avm_main_sel_op_dagasleft, - avm_main_sel_op_div, - avm_main_sel_op_emit_l2_to_l1_msg, - avm_main_sel_op_emit_note_hash, - avm_main_sel_op_emit_nullifier, - avm_main_sel_op_emit_unencrypted_log, - avm_main_sel_op_eq, - avm_main_sel_op_fdiv, - avm_main_sel_op_fee_per_da_gas, - avm_main_sel_op_fee_per_l2_gas, - avm_main_sel_op_get_contract_instance, - avm_main_sel_op_keccak, - avm_main_sel_op_l1_to_l2_msg_exists, - avm_main_sel_op_l2gasleft, - avm_main_sel_op_lt, - avm_main_sel_op_lte, - avm_main_sel_op_mul, - avm_main_sel_op_not, - avm_main_sel_op_note_hash_exists, - avm_main_sel_op_nullifier_exists, - avm_main_sel_op_or, - avm_main_sel_op_pedersen, - avm_main_sel_op_poseidon2, - avm_main_sel_op_radix_le, - avm_main_sel_op_sender, - avm_main_sel_op_sha256, - avm_main_sel_op_shl, - avm_main_sel_op_shr, - avm_main_sel_op_sload, - avm_main_sel_op_sstore, - avm_main_sel_op_storage_address, - avm_main_sel_op_sub, - avm_main_sel_op_timestamp, - avm_main_sel_op_transaction_fee, - avm_main_sel_op_version, - avm_main_sel_op_xor, - avm_main_sel_rng_16, - avm_main_sel_rng_8, - avm_main_space_id, - avm_main_table_pow_2, - avm_main_tag_err, - avm_main_w_in_tag, - avm_mem_addr, - avm_mem_clk, - avm_mem_diff_hi, - avm_mem_diff_lo, - avm_mem_diff_mid, - avm_mem_glob_addr, - avm_mem_ind_op_a, - avm_mem_ind_op_b, - avm_mem_ind_op_c, - avm_mem_ind_op_d, - avm_mem_last, - avm_mem_lastAccess, - avm_mem_mem_sel, - avm_mem_one_min_inv, - avm_mem_op_a, - avm_mem_op_b, - avm_mem_op_c, - avm_mem_op_d, - avm_mem_r_in_tag, - avm_mem_rng_chk_sel, - avm_mem_rw, - avm_mem_sel_cmov, - avm_mem_sel_mov_a, - avm_mem_sel_mov_b, - avm_mem_skip_check_tag, - avm_mem_space_id, - avm_mem_tag, - avm_mem_tag_err, - avm_mem_tsp, - avm_mem_val, - avm_mem_w_in_tag, - avm_pedersen_clk, - avm_pedersen_input, - avm_pedersen_output, - avm_pedersen_pedersen_sel, - avm_poseidon2_clk, - avm_poseidon2_input, - avm_poseidon2_output, - avm_poseidon2_poseidon_perm_sel, - avm_sha256_clk, - avm_sha256_input, - avm_sha256_output, - avm_sha256_sha256_compression_sel, - avm_sha256_state, + return { alu_a_hi, + alu_a_lo, + alu_b_hi, + alu_b_lo, + alu_borrow, + alu_cf, + alu_clk, + alu_cmp_rng_ctr, + alu_div_u16_r0, + alu_div_u16_r1, + alu_div_u16_r2, + alu_div_u16_r3, + alu_div_u16_r4, + alu_div_u16_r5, + alu_div_u16_r6, + alu_div_u16_r7, + alu_divisor_hi, + alu_divisor_lo, + alu_ff_tag, + alu_ia, + alu_ib, + alu_ic, + alu_in_tag, + alu_op_add, + alu_op_cast, + alu_op_cast_prev, + alu_op_div, + alu_op_div_a_lt_b, + alu_op_div_std, + alu_op_eq, + alu_op_eq_diff_inv, + alu_op_lt, + alu_op_lte, + alu_op_mul, + alu_op_not, + alu_op_shl, + alu_op_shr, + alu_op_sub, + alu_p_a_borrow, + alu_p_b_borrow, + alu_p_sub_a_hi, + alu_p_sub_a_lo, + alu_p_sub_b_hi, + alu_p_sub_b_lo, + alu_partial_prod_hi, + alu_partial_prod_lo, + alu_quotient_hi, + alu_quotient_lo, + alu_remainder, + alu_res_hi, + alu_res_lo, + alu_sel_alu, + alu_sel_cmp, + alu_sel_div_rng_chk, + alu_sel_rng_chk, + alu_sel_rng_chk_lookup, + alu_sel_shift_which, + alu_shift_lt_bit_len, + alu_t_sub_s_bits, + alu_two_pow_s, + alu_two_pow_t_sub_s, + alu_u128_tag, + alu_u16_r0, + alu_u16_r1, + alu_u16_r10, + alu_u16_r11, + alu_u16_r12, + alu_u16_r13, + alu_u16_r14, + alu_u16_r2, + alu_u16_r3, + alu_u16_r4, + alu_u16_r5, + alu_u16_r6, + alu_u16_r7, + alu_u16_r8, + alu_u16_r9, + alu_u16_tag, + alu_u32_tag, + alu_u64_tag, + alu_u8_r0, + alu_u8_r1, + alu_u8_tag, + binary_acc_ia, + binary_acc_ib, + binary_acc_ic, + binary_clk, + binary_ia_bytes, + binary_ib_bytes, + binary_ic_bytes, + binary_in_tag, + binary_mem_tag_ctr, + binary_mem_tag_ctr_inv, + binary_op_id, + binary_sel_bin, + binary_start, + byte_lookup_sel_bin, + byte_lookup_table_byte_lengths, + byte_lookup_table_in_tags, + byte_lookup_table_input_a, + byte_lookup_table_input_b, + byte_lookup_table_op_id, + byte_lookup_table_output, + conversion_clk, + conversion_input, + conversion_num_limbs, + conversion_radix, + conversion_sel_to_radix_le, + gas_da_gas_fixed_table, + gas_l2_gas_fixed_table, + gas_sel_gas_cost, + keccakf1600_clk, + keccakf1600_input, + keccakf1600_output, + keccakf1600_sel_keccakf1600, + kernel_emit_l2_to_l1_msg_write_offset, + kernel_emit_note_hash_write_offset, + kernel_emit_nullifier_write_offset, + kernel_emit_unencrypted_log_write_offset, + kernel_kernel_in_offset, + kernel_kernel_inputs, + kernel_kernel_metadata_out, + kernel_kernel_out_offset, + kernel_kernel_side_effect_out, + kernel_kernel_value_out, + kernel_l1_to_l2_msg_exists_write_offset, + kernel_note_hash_exist_write_offset, + kernel_nullifier_exists_write_offset, + kernel_nullifier_non_exists_write_offset, + kernel_q_public_input_kernel_add_to_table, + kernel_q_public_input_kernel_out_add_to_table, + kernel_side_effect_counter, + kernel_sload_write_offset, + kernel_sstore_write_offset, + main_abs_da_rem_gas_hi, + main_abs_da_rem_gas_lo, + main_abs_l2_rem_gas_hi, + main_abs_l2_rem_gas_lo, + main_alu_in_tag, + main_bin_op_id, + main_call_ptr, + main_da_gas_op_cost, + main_da_gas_remaining, + main_da_out_of_gas, + main_ia, + main_ib, + main_ic, + main_id, + main_id_zero, + main_ind_addr_a, + main_ind_addr_b, + main_ind_addr_c, + main_ind_addr_d, + main_internal_return_ptr, + main_inv, + main_l2_gas_op_cost, + main_l2_gas_remaining, + main_l2_out_of_gas, + main_mem_addr_a, + main_mem_addr_b, + main_mem_addr_c, + main_mem_addr_d, + main_op_err, + main_opcode_val, + main_pc, + main_r_in_tag, + main_rwa, + main_rwb, + main_rwc, + main_rwd, + main_sel_alu, + main_sel_bin, + main_sel_gas_accounting_active, + main_sel_last, + main_sel_mem_op_a, + main_sel_mem_op_activate_gas, + main_sel_mem_op_b, + main_sel_mem_op_c, + main_sel_mem_op_d, + main_sel_mov_ia_to_ic, + main_sel_mov_ib_to_ic, + main_sel_op_add, + main_sel_op_address, + main_sel_op_and, + main_sel_op_block_number, + main_sel_op_cast, + main_sel_op_chain_id, + main_sel_op_cmov, + main_sel_op_coinbase, + main_sel_op_dagasleft, + main_sel_op_div, + main_sel_op_emit_l2_to_l1_msg, + main_sel_op_emit_note_hash, + main_sel_op_emit_nullifier, + main_sel_op_emit_unencrypted_log, + main_sel_op_eq, + main_sel_op_external_call, + main_sel_op_fdiv, + main_sel_op_fee_per_da_gas, + main_sel_op_fee_per_l2_gas, + main_sel_op_get_contract_instance, + main_sel_op_halt, + main_sel_op_internal_call, + main_sel_op_internal_return, + main_sel_op_jump, + main_sel_op_jumpi, + main_sel_op_keccak, + main_sel_op_l1_to_l2_msg_exists, + main_sel_op_l2gasleft, + main_sel_op_lt, + main_sel_op_lte, + main_sel_op_mov, + main_sel_op_mul, + main_sel_op_not, + main_sel_op_note_hash_exists, + main_sel_op_nullifier_exists, + main_sel_op_or, + main_sel_op_pedersen, + main_sel_op_poseidon2, + main_sel_op_radix_le, + main_sel_op_sender, + main_sel_op_sha256, + main_sel_op_shl, + main_sel_op_shr, + main_sel_op_sload, + main_sel_op_sstore, + main_sel_op_storage_address, + main_sel_op_sub, + main_sel_op_timestamp, + main_sel_op_transaction_fee, + main_sel_op_version, + main_sel_op_xor, + main_sel_q_kernel_lookup, + main_sel_q_kernel_output_lookup, + main_sel_resolve_ind_addr_a, + main_sel_resolve_ind_addr_b, + main_sel_resolve_ind_addr_c, + main_sel_resolve_ind_addr_d, + main_sel_rng_16, + main_sel_rng_8, + main_space_id, + main_table_pow_2, + main_tag_err, + main_w_in_tag, + mem_addr, + mem_clk, + mem_diff_hi, + mem_diff_lo, + mem_diff_mid, + mem_glob_addr, + mem_last, + mem_lastAccess, + mem_one_min_inv, + mem_r_in_tag, + mem_rw, + mem_sel_mem, + mem_sel_mov_ia_to_ic, + mem_sel_mov_ib_to_ic, + mem_sel_op_a, + mem_sel_op_b, + mem_sel_op_c, + mem_sel_op_cmov, + mem_sel_op_d, + mem_sel_resolve_ind_addr_a, + mem_sel_resolve_ind_addr_b, + mem_sel_resolve_ind_addr_c, + mem_sel_resolve_ind_addr_d, + mem_sel_rng_chk, + mem_skip_check_tag, + mem_space_id, + mem_tag, + mem_tag_err, + mem_tsp, + mem_val, + mem_w_in_tag, + pedersen_clk, + pedersen_input, + pedersen_output, + pedersen_sel_pedersen, + poseidon2_clk, + poseidon2_input, + poseidon2_output, + poseidon2_sel_poseidon_perm, + sha256_clk, + sha256_input, + sha256_output, + sha256_sel_sha256_compression, + sha256_state, perm_main_alu, perm_main_bin, perm_main_conv, @@ -939,10 +939,10 @@ class AvmFlavor { perm_main_mem_b, perm_main_mem_c, perm_main_mem_d, - perm_main_mem_ind_a, - perm_main_mem_ind_b, - perm_main_mem_ind_c, - perm_main_mem_ind_d, + perm_main_mem_ind_addr_a, + perm_main_mem_ind_addr_b, + perm_main_mem_ind_addr_c, + perm_main_mem_ind_addr_d, lookup_byte_lengths, lookup_byte_operations, lookup_opcode_gas, @@ -1031,296 +1031,296 @@ class AvmFlavor { template class AllEntities { public: DEFINE_FLAVOR_MEMBERS(DataType, - avm_main_clk, - avm_main_first, - avm_alu_a_hi, - avm_alu_a_lo, - avm_alu_alu_sel, - avm_alu_b_hi, - avm_alu_b_lo, - avm_alu_borrow, - avm_alu_cf, - avm_alu_clk, - avm_alu_cmp_rng_ctr, - avm_alu_cmp_sel, - avm_alu_div_rng_chk_selector, - avm_alu_div_u16_r0, - avm_alu_div_u16_r1, - avm_alu_div_u16_r2, - avm_alu_div_u16_r3, - avm_alu_div_u16_r4, - avm_alu_div_u16_r5, - avm_alu_div_u16_r6, - avm_alu_div_u16_r7, - avm_alu_divisor_hi, - avm_alu_divisor_lo, - avm_alu_ff_tag, - avm_alu_ia, - avm_alu_ib, - avm_alu_ic, - avm_alu_in_tag, - avm_alu_op_add, - avm_alu_op_cast, - avm_alu_op_cast_prev, - avm_alu_op_div, - avm_alu_op_div_a_lt_b, - avm_alu_op_div_std, - avm_alu_op_eq, - avm_alu_op_eq_diff_inv, - avm_alu_op_lt, - avm_alu_op_lte, - avm_alu_op_mul, - avm_alu_op_not, - avm_alu_op_shl, - avm_alu_op_shr, - avm_alu_op_sub, - avm_alu_p_a_borrow, - avm_alu_p_b_borrow, - avm_alu_p_sub_a_hi, - avm_alu_p_sub_a_lo, - avm_alu_p_sub_b_hi, - avm_alu_p_sub_b_lo, - avm_alu_partial_prod_hi, - avm_alu_partial_prod_lo, - avm_alu_quotient_hi, - avm_alu_quotient_lo, - avm_alu_remainder, - avm_alu_res_hi, - avm_alu_res_lo, - avm_alu_rng_chk_lookup_selector, - avm_alu_rng_chk_sel, - avm_alu_shift_lt_bit_len, - avm_alu_shift_sel, - avm_alu_t_sub_s_bits, - avm_alu_two_pow_s, - avm_alu_two_pow_t_sub_s, - avm_alu_u128_tag, - avm_alu_u16_r0, - avm_alu_u16_r1, - avm_alu_u16_r10, - avm_alu_u16_r11, - avm_alu_u16_r12, - avm_alu_u16_r13, - avm_alu_u16_r14, - avm_alu_u16_r2, - avm_alu_u16_r3, - avm_alu_u16_r4, - avm_alu_u16_r5, - avm_alu_u16_r6, - avm_alu_u16_r7, - avm_alu_u16_r8, - avm_alu_u16_r9, - avm_alu_u16_tag, - avm_alu_u32_tag, - avm_alu_u64_tag, - avm_alu_u8_r0, - avm_alu_u8_r1, - avm_alu_u8_tag, - avm_binary_acc_ia, - avm_binary_acc_ib, - avm_binary_acc_ic, - avm_binary_bin_sel, - avm_binary_clk, - avm_binary_ia_bytes, - avm_binary_ib_bytes, - avm_binary_ic_bytes, - avm_binary_in_tag, - avm_binary_mem_tag_ctr, - avm_binary_mem_tag_ctr_inv, - avm_binary_op_id, - avm_binary_start, - avm_byte_lookup_bin_sel, - avm_byte_lookup_table_byte_lengths, - avm_byte_lookup_table_in_tags, - avm_byte_lookup_table_input_a, - avm_byte_lookup_table_input_b, - avm_byte_lookup_table_op_id, - avm_byte_lookup_table_output, - avm_conversion_clk, - avm_conversion_input, - avm_conversion_num_limbs, - avm_conversion_radix, - avm_conversion_to_radix_le_sel, - avm_gas_da_gas_fixed_table, - avm_gas_gas_cost_sel, - avm_gas_l2_gas_fixed_table, - avm_keccakf1600_clk, - avm_keccakf1600_input, - avm_keccakf1600_keccakf1600_sel, - avm_keccakf1600_output, - avm_kernel_emit_l2_to_l1_msg_write_offset, - avm_kernel_emit_note_hash_write_offset, - avm_kernel_emit_nullifier_write_offset, - avm_kernel_emit_unencrypted_log_write_offset, - avm_kernel_kernel_in_offset, - avm_kernel_kernel_inputs, - avm_kernel_kernel_metadata_out, - avm_kernel_kernel_out_offset, - avm_kernel_kernel_side_effect_out, - avm_kernel_kernel_value_out, - avm_kernel_l1_to_l2_msg_exists_write_offset, - avm_kernel_note_hash_exist_write_offset, - avm_kernel_nullifier_exists_write_offset, - avm_kernel_nullifier_non_exists_write_offset, - avm_kernel_q_public_input_kernel_add_to_table, - avm_kernel_q_public_input_kernel_out_add_to_table, - avm_kernel_side_effect_counter, - avm_kernel_sload_write_offset, - avm_kernel_sstore_write_offset, - avm_main_abs_da_rem_gas_hi, - avm_main_abs_da_rem_gas_lo, - avm_main_abs_l2_rem_gas_hi, - avm_main_abs_l2_rem_gas_lo, - avm_main_alu_in_tag, - avm_main_alu_sel, - avm_main_bin_op_id, - avm_main_bin_sel, - avm_main_call_ptr, - avm_main_da_gas_op, - avm_main_da_gas_remaining, - avm_main_da_out_of_gas, - avm_main_gas_cost_active, - avm_main_ia, - avm_main_ib, - avm_main_ic, - avm_main_id, - avm_main_id_zero, - avm_main_ind_a, - avm_main_ind_b, - avm_main_ind_c, - avm_main_ind_d, - avm_main_ind_op_a, - avm_main_ind_op_b, - avm_main_ind_op_c, - avm_main_ind_op_d, - avm_main_internal_return_ptr, - avm_main_inv, - avm_main_l2_gas_op, - avm_main_l2_gas_remaining, - avm_main_l2_out_of_gas, - avm_main_last, - avm_main_mem_idx_a, - avm_main_mem_idx_b, - avm_main_mem_idx_c, - avm_main_mem_idx_d, - avm_main_mem_op_a, - avm_main_mem_op_activate_gas, - avm_main_mem_op_b, - avm_main_mem_op_c, - avm_main_mem_op_d, - avm_main_op_err, - avm_main_opcode_val, - avm_main_pc, - avm_main_q_kernel_lookup, - avm_main_q_kernel_output_lookup, - avm_main_r_in_tag, - avm_main_rwa, - avm_main_rwb, - avm_main_rwc, - avm_main_rwd, - avm_main_sel_cmov, - avm_main_sel_external_call, - avm_main_sel_halt, - avm_main_sel_internal_call, - avm_main_sel_internal_return, - avm_main_sel_jump, - avm_main_sel_jumpi, - avm_main_sel_mov, - avm_main_sel_mov_a, - avm_main_sel_mov_b, - avm_main_sel_op_add, - avm_main_sel_op_address, - avm_main_sel_op_and, - avm_main_sel_op_block_number, - avm_main_sel_op_cast, - avm_main_sel_op_chain_id, - avm_main_sel_op_coinbase, - avm_main_sel_op_dagasleft, - avm_main_sel_op_div, - avm_main_sel_op_emit_l2_to_l1_msg, - avm_main_sel_op_emit_note_hash, - avm_main_sel_op_emit_nullifier, - avm_main_sel_op_emit_unencrypted_log, - avm_main_sel_op_eq, - avm_main_sel_op_fdiv, - avm_main_sel_op_fee_per_da_gas, - avm_main_sel_op_fee_per_l2_gas, - avm_main_sel_op_get_contract_instance, - avm_main_sel_op_keccak, - avm_main_sel_op_l1_to_l2_msg_exists, - avm_main_sel_op_l2gasleft, - avm_main_sel_op_lt, - avm_main_sel_op_lte, - avm_main_sel_op_mul, - avm_main_sel_op_not, - avm_main_sel_op_note_hash_exists, - avm_main_sel_op_nullifier_exists, - avm_main_sel_op_or, - avm_main_sel_op_pedersen, - avm_main_sel_op_poseidon2, - avm_main_sel_op_radix_le, - avm_main_sel_op_sender, - avm_main_sel_op_sha256, - avm_main_sel_op_shl, - avm_main_sel_op_shr, - avm_main_sel_op_sload, - avm_main_sel_op_sstore, - avm_main_sel_op_storage_address, - avm_main_sel_op_sub, - avm_main_sel_op_timestamp, - avm_main_sel_op_transaction_fee, - avm_main_sel_op_version, - avm_main_sel_op_xor, - avm_main_sel_rng_16, - avm_main_sel_rng_8, - avm_main_space_id, - avm_main_table_pow_2, - avm_main_tag_err, - avm_main_w_in_tag, - avm_mem_addr, - avm_mem_clk, - avm_mem_diff_hi, - avm_mem_diff_lo, - avm_mem_diff_mid, - avm_mem_glob_addr, - avm_mem_ind_op_a, - avm_mem_ind_op_b, - avm_mem_ind_op_c, - avm_mem_ind_op_d, - avm_mem_last, - avm_mem_lastAccess, - avm_mem_mem_sel, - avm_mem_one_min_inv, - avm_mem_op_a, - avm_mem_op_b, - avm_mem_op_c, - avm_mem_op_d, - avm_mem_r_in_tag, - avm_mem_rng_chk_sel, - avm_mem_rw, - avm_mem_sel_cmov, - avm_mem_sel_mov_a, - avm_mem_sel_mov_b, - avm_mem_skip_check_tag, - avm_mem_space_id, - avm_mem_tag, - avm_mem_tag_err, - avm_mem_tsp, - avm_mem_val, - avm_mem_w_in_tag, - avm_pedersen_clk, - avm_pedersen_input, - avm_pedersen_output, - avm_pedersen_pedersen_sel, - avm_poseidon2_clk, - avm_poseidon2_input, - avm_poseidon2_output, - avm_poseidon2_poseidon_perm_sel, - avm_sha256_clk, - avm_sha256_input, - avm_sha256_output, - avm_sha256_sha256_compression_sel, - avm_sha256_state, + main_clk, + main_sel_first, + alu_a_hi, + alu_a_lo, + alu_b_hi, + alu_b_lo, + alu_borrow, + alu_cf, + alu_clk, + alu_cmp_rng_ctr, + alu_div_u16_r0, + alu_div_u16_r1, + alu_div_u16_r2, + alu_div_u16_r3, + alu_div_u16_r4, + alu_div_u16_r5, + alu_div_u16_r6, + alu_div_u16_r7, + alu_divisor_hi, + alu_divisor_lo, + alu_ff_tag, + alu_ia, + alu_ib, + alu_ic, + alu_in_tag, + alu_op_add, + alu_op_cast, + alu_op_cast_prev, + alu_op_div, + alu_op_div_a_lt_b, + alu_op_div_std, + alu_op_eq, + alu_op_eq_diff_inv, + alu_op_lt, + alu_op_lte, + alu_op_mul, + alu_op_not, + alu_op_shl, + alu_op_shr, + alu_op_sub, + alu_p_a_borrow, + alu_p_b_borrow, + alu_p_sub_a_hi, + alu_p_sub_a_lo, + alu_p_sub_b_hi, + alu_p_sub_b_lo, + alu_partial_prod_hi, + alu_partial_prod_lo, + alu_quotient_hi, + alu_quotient_lo, + alu_remainder, + alu_res_hi, + alu_res_lo, + alu_sel_alu, + alu_sel_cmp, + alu_sel_div_rng_chk, + alu_sel_rng_chk, + alu_sel_rng_chk_lookup, + alu_sel_shift_which, + alu_shift_lt_bit_len, + alu_t_sub_s_bits, + alu_two_pow_s, + alu_two_pow_t_sub_s, + alu_u128_tag, + alu_u16_r0, + alu_u16_r1, + alu_u16_r10, + alu_u16_r11, + alu_u16_r12, + alu_u16_r13, + alu_u16_r14, + alu_u16_r2, + alu_u16_r3, + alu_u16_r4, + alu_u16_r5, + alu_u16_r6, + alu_u16_r7, + alu_u16_r8, + alu_u16_r9, + alu_u16_tag, + alu_u32_tag, + alu_u64_tag, + alu_u8_r0, + alu_u8_r1, + alu_u8_tag, + binary_acc_ia, + binary_acc_ib, + binary_acc_ic, + binary_clk, + binary_ia_bytes, + binary_ib_bytes, + binary_ic_bytes, + binary_in_tag, + binary_mem_tag_ctr, + binary_mem_tag_ctr_inv, + binary_op_id, + binary_sel_bin, + binary_start, + byte_lookup_sel_bin, + byte_lookup_table_byte_lengths, + byte_lookup_table_in_tags, + byte_lookup_table_input_a, + byte_lookup_table_input_b, + byte_lookup_table_op_id, + byte_lookup_table_output, + conversion_clk, + conversion_input, + conversion_num_limbs, + conversion_radix, + conversion_sel_to_radix_le, + gas_da_gas_fixed_table, + gas_l2_gas_fixed_table, + gas_sel_gas_cost, + keccakf1600_clk, + keccakf1600_input, + keccakf1600_output, + keccakf1600_sel_keccakf1600, + kernel_emit_l2_to_l1_msg_write_offset, + kernel_emit_note_hash_write_offset, + kernel_emit_nullifier_write_offset, + kernel_emit_unencrypted_log_write_offset, + kernel_kernel_in_offset, + kernel_kernel_inputs, + kernel_kernel_metadata_out, + kernel_kernel_out_offset, + kernel_kernel_side_effect_out, + kernel_kernel_value_out, + kernel_l1_to_l2_msg_exists_write_offset, + kernel_note_hash_exist_write_offset, + kernel_nullifier_exists_write_offset, + kernel_nullifier_non_exists_write_offset, + kernel_q_public_input_kernel_add_to_table, + kernel_q_public_input_kernel_out_add_to_table, + kernel_side_effect_counter, + kernel_sload_write_offset, + kernel_sstore_write_offset, + main_abs_da_rem_gas_hi, + main_abs_da_rem_gas_lo, + main_abs_l2_rem_gas_hi, + main_abs_l2_rem_gas_lo, + main_alu_in_tag, + main_bin_op_id, + main_call_ptr, + main_da_gas_op_cost, + main_da_gas_remaining, + main_da_out_of_gas, + main_ia, + main_ib, + main_ic, + main_id, + main_id_zero, + main_ind_addr_a, + main_ind_addr_b, + main_ind_addr_c, + main_ind_addr_d, + main_internal_return_ptr, + main_inv, + main_l2_gas_op_cost, + main_l2_gas_remaining, + main_l2_out_of_gas, + main_mem_addr_a, + main_mem_addr_b, + main_mem_addr_c, + main_mem_addr_d, + main_op_err, + main_opcode_val, + main_pc, + main_r_in_tag, + main_rwa, + main_rwb, + main_rwc, + main_rwd, + main_sel_alu, + main_sel_bin, + main_sel_gas_accounting_active, + main_sel_last, + main_sel_mem_op_a, + main_sel_mem_op_activate_gas, + main_sel_mem_op_b, + main_sel_mem_op_c, + main_sel_mem_op_d, + main_sel_mov_ia_to_ic, + main_sel_mov_ib_to_ic, + main_sel_op_add, + main_sel_op_address, + main_sel_op_and, + main_sel_op_block_number, + main_sel_op_cast, + main_sel_op_chain_id, + main_sel_op_cmov, + main_sel_op_coinbase, + main_sel_op_dagasleft, + main_sel_op_div, + main_sel_op_emit_l2_to_l1_msg, + main_sel_op_emit_note_hash, + main_sel_op_emit_nullifier, + main_sel_op_emit_unencrypted_log, + main_sel_op_eq, + main_sel_op_external_call, + main_sel_op_fdiv, + main_sel_op_fee_per_da_gas, + main_sel_op_fee_per_l2_gas, + main_sel_op_get_contract_instance, + main_sel_op_halt, + main_sel_op_internal_call, + main_sel_op_internal_return, + main_sel_op_jump, + main_sel_op_jumpi, + main_sel_op_keccak, + main_sel_op_l1_to_l2_msg_exists, + main_sel_op_l2gasleft, + main_sel_op_lt, + main_sel_op_lte, + main_sel_op_mov, + main_sel_op_mul, + main_sel_op_not, + main_sel_op_note_hash_exists, + main_sel_op_nullifier_exists, + main_sel_op_or, + main_sel_op_pedersen, + main_sel_op_poseidon2, + main_sel_op_radix_le, + main_sel_op_sender, + main_sel_op_sha256, + main_sel_op_shl, + main_sel_op_shr, + main_sel_op_sload, + main_sel_op_sstore, + main_sel_op_storage_address, + main_sel_op_sub, + main_sel_op_timestamp, + main_sel_op_transaction_fee, + main_sel_op_version, + main_sel_op_xor, + main_sel_q_kernel_lookup, + main_sel_q_kernel_output_lookup, + main_sel_resolve_ind_addr_a, + main_sel_resolve_ind_addr_b, + main_sel_resolve_ind_addr_c, + main_sel_resolve_ind_addr_d, + main_sel_rng_16, + main_sel_rng_8, + main_space_id, + main_table_pow_2, + main_tag_err, + main_w_in_tag, + mem_addr, + mem_clk, + mem_diff_hi, + mem_diff_lo, + mem_diff_mid, + mem_glob_addr, + mem_last, + mem_lastAccess, + mem_one_min_inv, + mem_r_in_tag, + mem_rw, + mem_sel_mem, + mem_sel_mov_ia_to_ic, + mem_sel_mov_ib_to_ic, + mem_sel_op_a, + mem_sel_op_b, + mem_sel_op_c, + mem_sel_op_cmov, + mem_sel_op_d, + mem_sel_resolve_ind_addr_a, + mem_sel_resolve_ind_addr_b, + mem_sel_resolve_ind_addr_c, + mem_sel_resolve_ind_addr_d, + mem_sel_rng_chk, + mem_skip_check_tag, + mem_space_id, + mem_tag, + mem_tag_err, + mem_tsp, + mem_val, + mem_w_in_tag, + pedersen_clk, + pedersen_input, + pedersen_output, + pedersen_sel_pedersen, + poseidon2_clk, + poseidon2_input, + poseidon2_output, + poseidon2_sel_poseidon_perm, + sha256_clk, + sha256_input, + sha256_output, + sha256_sel_sha256_compression, + sha256_state, perm_main_alu, perm_main_bin, perm_main_conv, @@ -1330,10 +1330,10 @@ class AvmFlavor { perm_main_mem_b, perm_main_mem_c, perm_main_mem_d, - perm_main_mem_ind_a, - perm_main_mem_ind_b, - perm_main_mem_ind_c, - perm_main_mem_ind_d, + perm_main_mem_ind_addr_a, + perm_main_mem_ind_addr_b, + perm_main_mem_ind_addr_c, + perm_main_mem_ind_addr_d, lookup_byte_lengths, lookup_byte_operations, lookup_opcode_gas, @@ -1416,364 +1416,364 @@ class AvmFlavor { lookup_div_u16_5_counts, lookup_div_u16_6_counts, lookup_div_u16_7_counts, - avm_alu_a_hi_shift, - avm_alu_a_lo_shift, - avm_alu_alu_sel_shift, - avm_alu_b_hi_shift, - avm_alu_b_lo_shift, - avm_alu_cmp_rng_ctr_shift, - avm_alu_cmp_sel_shift, - avm_alu_div_rng_chk_selector_shift, - avm_alu_div_u16_r0_shift, - avm_alu_div_u16_r1_shift, - avm_alu_div_u16_r2_shift, - avm_alu_div_u16_r3_shift, - avm_alu_div_u16_r4_shift, - avm_alu_div_u16_r5_shift, - avm_alu_div_u16_r6_shift, - avm_alu_div_u16_r7_shift, - avm_alu_op_add_shift, - avm_alu_op_cast_prev_shift, - avm_alu_op_cast_shift, - avm_alu_op_div_shift, - avm_alu_op_mul_shift, - avm_alu_op_shl_shift, - avm_alu_op_shr_shift, - avm_alu_op_sub_shift, - avm_alu_p_sub_a_hi_shift, - avm_alu_p_sub_a_lo_shift, - avm_alu_p_sub_b_hi_shift, - avm_alu_p_sub_b_lo_shift, - avm_alu_rng_chk_lookup_selector_shift, - avm_alu_rng_chk_sel_shift, - avm_alu_u16_r0_shift, - avm_alu_u16_r1_shift, - avm_alu_u16_r2_shift, - avm_alu_u16_r3_shift, - avm_alu_u16_r4_shift, - avm_alu_u16_r5_shift, - avm_alu_u16_r6_shift, - avm_alu_u8_r0_shift, - avm_alu_u8_r1_shift, - avm_binary_acc_ia_shift, - avm_binary_acc_ib_shift, - avm_binary_acc_ic_shift, - avm_binary_mem_tag_ctr_shift, - avm_binary_op_id_shift, - avm_kernel_emit_l2_to_l1_msg_write_offset_shift, - avm_kernel_emit_note_hash_write_offset_shift, - avm_kernel_emit_nullifier_write_offset_shift, - avm_kernel_emit_unencrypted_log_write_offset_shift, - avm_kernel_l1_to_l2_msg_exists_write_offset_shift, - avm_kernel_note_hash_exist_write_offset_shift, - avm_kernel_nullifier_exists_write_offset_shift, - avm_kernel_nullifier_non_exists_write_offset_shift, - avm_kernel_side_effect_counter_shift, - avm_kernel_sload_write_offset_shift, - avm_kernel_sstore_write_offset_shift, - avm_main_da_gas_remaining_shift, - avm_main_internal_return_ptr_shift, - avm_main_l2_gas_remaining_shift, - avm_main_pc_shift, - avm_mem_glob_addr_shift, - avm_mem_mem_sel_shift, - avm_mem_rw_shift, - avm_mem_tag_shift, - avm_mem_tsp_shift, - avm_mem_val_shift) + alu_a_hi_shift, + alu_a_lo_shift, + alu_b_hi_shift, + alu_b_lo_shift, + alu_cmp_rng_ctr_shift, + alu_div_u16_r0_shift, + alu_div_u16_r1_shift, + alu_div_u16_r2_shift, + alu_div_u16_r3_shift, + alu_div_u16_r4_shift, + alu_div_u16_r5_shift, + alu_div_u16_r6_shift, + alu_div_u16_r7_shift, + alu_op_add_shift, + alu_op_cast_prev_shift, + alu_op_cast_shift, + alu_op_div_shift, + alu_op_mul_shift, + alu_op_shl_shift, + alu_op_shr_shift, + alu_op_sub_shift, + alu_p_sub_a_hi_shift, + alu_p_sub_a_lo_shift, + alu_p_sub_b_hi_shift, + alu_p_sub_b_lo_shift, + alu_sel_alu_shift, + alu_sel_cmp_shift, + alu_sel_div_rng_chk_shift, + alu_sel_rng_chk_lookup_shift, + alu_sel_rng_chk_shift, + alu_u16_r0_shift, + alu_u16_r1_shift, + alu_u16_r2_shift, + alu_u16_r3_shift, + alu_u16_r4_shift, + alu_u16_r5_shift, + alu_u16_r6_shift, + alu_u8_r0_shift, + alu_u8_r1_shift, + binary_acc_ia_shift, + binary_acc_ib_shift, + binary_acc_ic_shift, + binary_mem_tag_ctr_shift, + binary_op_id_shift, + kernel_emit_l2_to_l1_msg_write_offset_shift, + kernel_emit_note_hash_write_offset_shift, + kernel_emit_nullifier_write_offset_shift, + kernel_emit_unencrypted_log_write_offset_shift, + kernel_l1_to_l2_msg_exists_write_offset_shift, + kernel_note_hash_exist_write_offset_shift, + kernel_nullifier_exists_write_offset_shift, + kernel_nullifier_non_exists_write_offset_shift, + kernel_side_effect_counter_shift, + kernel_sload_write_offset_shift, + kernel_sstore_write_offset_shift, + main_da_gas_remaining_shift, + main_internal_return_ptr_shift, + main_l2_gas_remaining_shift, + main_pc_shift, + mem_glob_addr_shift, + mem_rw_shift, + mem_sel_mem_shift, + mem_tag_shift, + mem_tsp_shift, + mem_val_shift) RefVector get_wires() { - return { avm_main_clk, - avm_main_first, - avm_alu_a_hi, - avm_alu_a_lo, - avm_alu_alu_sel, - avm_alu_b_hi, - avm_alu_b_lo, - avm_alu_borrow, - avm_alu_cf, - avm_alu_clk, - avm_alu_cmp_rng_ctr, - avm_alu_cmp_sel, - avm_alu_div_rng_chk_selector, - avm_alu_div_u16_r0, - avm_alu_div_u16_r1, - avm_alu_div_u16_r2, - avm_alu_div_u16_r3, - avm_alu_div_u16_r4, - avm_alu_div_u16_r5, - avm_alu_div_u16_r6, - avm_alu_div_u16_r7, - avm_alu_divisor_hi, - avm_alu_divisor_lo, - avm_alu_ff_tag, - avm_alu_ia, - avm_alu_ib, - avm_alu_ic, - avm_alu_in_tag, - avm_alu_op_add, - avm_alu_op_cast, - avm_alu_op_cast_prev, - avm_alu_op_div, - avm_alu_op_div_a_lt_b, - avm_alu_op_div_std, - avm_alu_op_eq, - avm_alu_op_eq_diff_inv, - avm_alu_op_lt, - avm_alu_op_lte, - avm_alu_op_mul, - avm_alu_op_not, - avm_alu_op_shl, - avm_alu_op_shr, - avm_alu_op_sub, - avm_alu_p_a_borrow, - avm_alu_p_b_borrow, - avm_alu_p_sub_a_hi, - avm_alu_p_sub_a_lo, - avm_alu_p_sub_b_hi, - avm_alu_p_sub_b_lo, - avm_alu_partial_prod_hi, - avm_alu_partial_prod_lo, - avm_alu_quotient_hi, - avm_alu_quotient_lo, - avm_alu_remainder, - avm_alu_res_hi, - avm_alu_res_lo, - avm_alu_rng_chk_lookup_selector, - avm_alu_rng_chk_sel, - avm_alu_shift_lt_bit_len, - avm_alu_shift_sel, - avm_alu_t_sub_s_bits, - avm_alu_two_pow_s, - avm_alu_two_pow_t_sub_s, - avm_alu_u128_tag, - avm_alu_u16_r0, - avm_alu_u16_r1, - avm_alu_u16_r10, - avm_alu_u16_r11, - avm_alu_u16_r12, - avm_alu_u16_r13, - avm_alu_u16_r14, - avm_alu_u16_r2, - avm_alu_u16_r3, - avm_alu_u16_r4, - avm_alu_u16_r5, - avm_alu_u16_r6, - avm_alu_u16_r7, - avm_alu_u16_r8, - avm_alu_u16_r9, - avm_alu_u16_tag, - avm_alu_u32_tag, - avm_alu_u64_tag, - avm_alu_u8_r0, - avm_alu_u8_r1, - avm_alu_u8_tag, - avm_binary_acc_ia, - avm_binary_acc_ib, - avm_binary_acc_ic, - avm_binary_bin_sel, - avm_binary_clk, - avm_binary_ia_bytes, - avm_binary_ib_bytes, - avm_binary_ic_bytes, - avm_binary_in_tag, - avm_binary_mem_tag_ctr, - avm_binary_mem_tag_ctr_inv, - avm_binary_op_id, - avm_binary_start, - avm_byte_lookup_bin_sel, - avm_byte_lookup_table_byte_lengths, - avm_byte_lookup_table_in_tags, - avm_byte_lookup_table_input_a, - avm_byte_lookup_table_input_b, - avm_byte_lookup_table_op_id, - avm_byte_lookup_table_output, - avm_conversion_clk, - avm_conversion_input, - avm_conversion_num_limbs, - avm_conversion_radix, - avm_conversion_to_radix_le_sel, - avm_gas_da_gas_fixed_table, - avm_gas_gas_cost_sel, - avm_gas_l2_gas_fixed_table, - avm_keccakf1600_clk, - avm_keccakf1600_input, - avm_keccakf1600_keccakf1600_sel, - avm_keccakf1600_output, - avm_kernel_emit_l2_to_l1_msg_write_offset, - avm_kernel_emit_note_hash_write_offset, - avm_kernel_emit_nullifier_write_offset, - avm_kernel_emit_unencrypted_log_write_offset, - avm_kernel_kernel_in_offset, - avm_kernel_kernel_inputs, - avm_kernel_kernel_metadata_out, - avm_kernel_kernel_out_offset, - avm_kernel_kernel_side_effect_out, - avm_kernel_kernel_value_out, - avm_kernel_l1_to_l2_msg_exists_write_offset, - avm_kernel_note_hash_exist_write_offset, - avm_kernel_nullifier_exists_write_offset, - avm_kernel_nullifier_non_exists_write_offset, - avm_kernel_q_public_input_kernel_add_to_table, - avm_kernel_q_public_input_kernel_out_add_to_table, - avm_kernel_side_effect_counter, - avm_kernel_sload_write_offset, - avm_kernel_sstore_write_offset, - avm_main_abs_da_rem_gas_hi, - avm_main_abs_da_rem_gas_lo, - avm_main_abs_l2_rem_gas_hi, - avm_main_abs_l2_rem_gas_lo, - avm_main_alu_in_tag, - avm_main_alu_sel, - avm_main_bin_op_id, - avm_main_bin_sel, - avm_main_call_ptr, - avm_main_da_gas_op, - avm_main_da_gas_remaining, - avm_main_da_out_of_gas, - avm_main_gas_cost_active, - avm_main_ia, - avm_main_ib, - avm_main_ic, - avm_main_id, - avm_main_id_zero, - avm_main_ind_a, - avm_main_ind_b, - avm_main_ind_c, - avm_main_ind_d, - avm_main_ind_op_a, - avm_main_ind_op_b, - avm_main_ind_op_c, - avm_main_ind_op_d, - avm_main_internal_return_ptr, - avm_main_inv, - avm_main_l2_gas_op, - avm_main_l2_gas_remaining, - avm_main_l2_out_of_gas, - avm_main_last, - avm_main_mem_idx_a, - avm_main_mem_idx_b, - avm_main_mem_idx_c, - avm_main_mem_idx_d, - avm_main_mem_op_a, - avm_main_mem_op_activate_gas, - avm_main_mem_op_b, - avm_main_mem_op_c, - avm_main_mem_op_d, - avm_main_op_err, - avm_main_opcode_val, - avm_main_pc, - avm_main_q_kernel_lookup, - avm_main_q_kernel_output_lookup, - avm_main_r_in_tag, - avm_main_rwa, - avm_main_rwb, - avm_main_rwc, - avm_main_rwd, - avm_main_sel_cmov, - avm_main_sel_external_call, - avm_main_sel_halt, - avm_main_sel_internal_call, - avm_main_sel_internal_return, - avm_main_sel_jump, - avm_main_sel_jumpi, - avm_main_sel_mov, - avm_main_sel_mov_a, - avm_main_sel_mov_b, - avm_main_sel_op_add, - avm_main_sel_op_address, - avm_main_sel_op_and, - avm_main_sel_op_block_number, - avm_main_sel_op_cast, - avm_main_sel_op_chain_id, - avm_main_sel_op_coinbase, - avm_main_sel_op_dagasleft, - avm_main_sel_op_div, - avm_main_sel_op_emit_l2_to_l1_msg, - avm_main_sel_op_emit_note_hash, - avm_main_sel_op_emit_nullifier, - avm_main_sel_op_emit_unencrypted_log, - avm_main_sel_op_eq, - avm_main_sel_op_fdiv, - avm_main_sel_op_fee_per_da_gas, - avm_main_sel_op_fee_per_l2_gas, - avm_main_sel_op_get_contract_instance, - avm_main_sel_op_keccak, - avm_main_sel_op_l1_to_l2_msg_exists, - avm_main_sel_op_l2gasleft, - avm_main_sel_op_lt, - avm_main_sel_op_lte, - avm_main_sel_op_mul, - avm_main_sel_op_not, - avm_main_sel_op_note_hash_exists, - avm_main_sel_op_nullifier_exists, - avm_main_sel_op_or, - avm_main_sel_op_pedersen, - avm_main_sel_op_poseidon2, - avm_main_sel_op_radix_le, - avm_main_sel_op_sender, - avm_main_sel_op_sha256, - avm_main_sel_op_shl, - avm_main_sel_op_shr, - avm_main_sel_op_sload, - avm_main_sel_op_sstore, - avm_main_sel_op_storage_address, - avm_main_sel_op_sub, - avm_main_sel_op_timestamp, - avm_main_sel_op_transaction_fee, - avm_main_sel_op_version, - avm_main_sel_op_xor, - avm_main_sel_rng_16, - avm_main_sel_rng_8, - avm_main_space_id, - avm_main_table_pow_2, - avm_main_tag_err, - avm_main_w_in_tag, - avm_mem_addr, - avm_mem_clk, - avm_mem_diff_hi, - avm_mem_diff_lo, - avm_mem_diff_mid, - avm_mem_glob_addr, - avm_mem_ind_op_a, - avm_mem_ind_op_b, - avm_mem_ind_op_c, - avm_mem_ind_op_d, - avm_mem_last, - avm_mem_lastAccess, - avm_mem_mem_sel, - avm_mem_one_min_inv, - avm_mem_op_a, - avm_mem_op_b, - avm_mem_op_c, - avm_mem_op_d, - avm_mem_r_in_tag, - avm_mem_rng_chk_sel, - avm_mem_rw, - avm_mem_sel_cmov, - avm_mem_sel_mov_a, - avm_mem_sel_mov_b, - avm_mem_skip_check_tag, - avm_mem_space_id, - avm_mem_tag, - avm_mem_tag_err, - avm_mem_tsp, - avm_mem_val, - avm_mem_w_in_tag, - avm_pedersen_clk, - avm_pedersen_input, - avm_pedersen_output, - avm_pedersen_pedersen_sel, - avm_poseidon2_clk, - avm_poseidon2_input, - avm_poseidon2_output, - avm_poseidon2_poseidon_perm_sel, - avm_sha256_clk, - avm_sha256_input, - avm_sha256_output, - avm_sha256_sha256_compression_sel, - avm_sha256_state, + return { main_clk, + main_sel_first, + alu_a_hi, + alu_a_lo, + alu_b_hi, + alu_b_lo, + alu_borrow, + alu_cf, + alu_clk, + alu_cmp_rng_ctr, + alu_div_u16_r0, + alu_div_u16_r1, + alu_div_u16_r2, + alu_div_u16_r3, + alu_div_u16_r4, + alu_div_u16_r5, + alu_div_u16_r6, + alu_div_u16_r7, + alu_divisor_hi, + alu_divisor_lo, + alu_ff_tag, + alu_ia, + alu_ib, + alu_ic, + alu_in_tag, + alu_op_add, + alu_op_cast, + alu_op_cast_prev, + alu_op_div, + alu_op_div_a_lt_b, + alu_op_div_std, + alu_op_eq, + alu_op_eq_diff_inv, + alu_op_lt, + alu_op_lte, + alu_op_mul, + alu_op_not, + alu_op_shl, + alu_op_shr, + alu_op_sub, + alu_p_a_borrow, + alu_p_b_borrow, + alu_p_sub_a_hi, + alu_p_sub_a_lo, + alu_p_sub_b_hi, + alu_p_sub_b_lo, + alu_partial_prod_hi, + alu_partial_prod_lo, + alu_quotient_hi, + alu_quotient_lo, + alu_remainder, + alu_res_hi, + alu_res_lo, + alu_sel_alu, + alu_sel_cmp, + alu_sel_div_rng_chk, + alu_sel_rng_chk, + alu_sel_rng_chk_lookup, + alu_sel_shift_which, + alu_shift_lt_bit_len, + alu_t_sub_s_bits, + alu_two_pow_s, + alu_two_pow_t_sub_s, + alu_u128_tag, + alu_u16_r0, + alu_u16_r1, + alu_u16_r10, + alu_u16_r11, + alu_u16_r12, + alu_u16_r13, + alu_u16_r14, + alu_u16_r2, + alu_u16_r3, + alu_u16_r4, + alu_u16_r5, + alu_u16_r6, + alu_u16_r7, + alu_u16_r8, + alu_u16_r9, + alu_u16_tag, + alu_u32_tag, + alu_u64_tag, + alu_u8_r0, + alu_u8_r1, + alu_u8_tag, + binary_acc_ia, + binary_acc_ib, + binary_acc_ic, + binary_clk, + binary_ia_bytes, + binary_ib_bytes, + binary_ic_bytes, + binary_in_tag, + binary_mem_tag_ctr, + binary_mem_tag_ctr_inv, + binary_op_id, + binary_sel_bin, + binary_start, + byte_lookup_sel_bin, + byte_lookup_table_byte_lengths, + byte_lookup_table_in_tags, + byte_lookup_table_input_a, + byte_lookup_table_input_b, + byte_lookup_table_op_id, + byte_lookup_table_output, + conversion_clk, + conversion_input, + conversion_num_limbs, + conversion_radix, + conversion_sel_to_radix_le, + gas_da_gas_fixed_table, + gas_l2_gas_fixed_table, + gas_sel_gas_cost, + keccakf1600_clk, + keccakf1600_input, + keccakf1600_output, + keccakf1600_sel_keccakf1600, + kernel_emit_l2_to_l1_msg_write_offset, + kernel_emit_note_hash_write_offset, + kernel_emit_nullifier_write_offset, + kernel_emit_unencrypted_log_write_offset, + kernel_kernel_in_offset, + kernel_kernel_inputs, + kernel_kernel_metadata_out, + kernel_kernel_out_offset, + kernel_kernel_side_effect_out, + kernel_kernel_value_out, + kernel_l1_to_l2_msg_exists_write_offset, + kernel_note_hash_exist_write_offset, + kernel_nullifier_exists_write_offset, + kernel_nullifier_non_exists_write_offset, + kernel_q_public_input_kernel_add_to_table, + kernel_q_public_input_kernel_out_add_to_table, + kernel_side_effect_counter, + kernel_sload_write_offset, + kernel_sstore_write_offset, + main_abs_da_rem_gas_hi, + main_abs_da_rem_gas_lo, + main_abs_l2_rem_gas_hi, + main_abs_l2_rem_gas_lo, + main_alu_in_tag, + main_bin_op_id, + main_call_ptr, + main_da_gas_op_cost, + main_da_gas_remaining, + main_da_out_of_gas, + main_ia, + main_ib, + main_ic, + main_id, + main_id_zero, + main_ind_addr_a, + main_ind_addr_b, + main_ind_addr_c, + main_ind_addr_d, + main_internal_return_ptr, + main_inv, + main_l2_gas_op_cost, + main_l2_gas_remaining, + main_l2_out_of_gas, + main_mem_addr_a, + main_mem_addr_b, + main_mem_addr_c, + main_mem_addr_d, + main_op_err, + main_opcode_val, + main_pc, + main_r_in_tag, + main_rwa, + main_rwb, + main_rwc, + main_rwd, + main_sel_alu, + main_sel_bin, + main_sel_gas_accounting_active, + main_sel_last, + main_sel_mem_op_a, + main_sel_mem_op_activate_gas, + main_sel_mem_op_b, + main_sel_mem_op_c, + main_sel_mem_op_d, + main_sel_mov_ia_to_ic, + main_sel_mov_ib_to_ic, + main_sel_op_add, + main_sel_op_address, + main_sel_op_and, + main_sel_op_block_number, + main_sel_op_cast, + main_sel_op_chain_id, + main_sel_op_cmov, + main_sel_op_coinbase, + main_sel_op_dagasleft, + main_sel_op_div, + main_sel_op_emit_l2_to_l1_msg, + main_sel_op_emit_note_hash, + main_sel_op_emit_nullifier, + main_sel_op_emit_unencrypted_log, + main_sel_op_eq, + main_sel_op_external_call, + main_sel_op_fdiv, + main_sel_op_fee_per_da_gas, + main_sel_op_fee_per_l2_gas, + main_sel_op_get_contract_instance, + main_sel_op_halt, + main_sel_op_internal_call, + main_sel_op_internal_return, + main_sel_op_jump, + main_sel_op_jumpi, + main_sel_op_keccak, + main_sel_op_l1_to_l2_msg_exists, + main_sel_op_l2gasleft, + main_sel_op_lt, + main_sel_op_lte, + main_sel_op_mov, + main_sel_op_mul, + main_sel_op_not, + main_sel_op_note_hash_exists, + main_sel_op_nullifier_exists, + main_sel_op_or, + main_sel_op_pedersen, + main_sel_op_poseidon2, + main_sel_op_radix_le, + main_sel_op_sender, + main_sel_op_sha256, + main_sel_op_shl, + main_sel_op_shr, + main_sel_op_sload, + main_sel_op_sstore, + main_sel_op_storage_address, + main_sel_op_sub, + main_sel_op_timestamp, + main_sel_op_transaction_fee, + main_sel_op_version, + main_sel_op_xor, + main_sel_q_kernel_lookup, + main_sel_q_kernel_output_lookup, + main_sel_resolve_ind_addr_a, + main_sel_resolve_ind_addr_b, + main_sel_resolve_ind_addr_c, + main_sel_resolve_ind_addr_d, + main_sel_rng_16, + main_sel_rng_8, + main_space_id, + main_table_pow_2, + main_tag_err, + main_w_in_tag, + mem_addr, + mem_clk, + mem_diff_hi, + mem_diff_lo, + mem_diff_mid, + mem_glob_addr, + mem_last, + mem_lastAccess, + mem_one_min_inv, + mem_r_in_tag, + mem_rw, + mem_sel_mem, + mem_sel_mov_ia_to_ic, + mem_sel_mov_ib_to_ic, + mem_sel_op_a, + mem_sel_op_b, + mem_sel_op_c, + mem_sel_op_cmov, + mem_sel_op_d, + mem_sel_resolve_ind_addr_a, + mem_sel_resolve_ind_addr_b, + mem_sel_resolve_ind_addr_c, + mem_sel_resolve_ind_addr_d, + mem_sel_rng_chk, + mem_skip_check_tag, + mem_space_id, + mem_tag, + mem_tag_err, + mem_tsp, + mem_val, + mem_w_in_tag, + pedersen_clk, + pedersen_input, + pedersen_output, + pedersen_sel_pedersen, + poseidon2_clk, + poseidon2_input, + poseidon2_output, + poseidon2_sel_poseidon_perm, + sha256_clk, + sha256_input, + sha256_output, + sha256_sel_sha256_compression, + sha256_state, perm_main_alu, perm_main_bin, perm_main_conv, @@ -1783,10 +1783,10 @@ class AvmFlavor { perm_main_mem_b, perm_main_mem_c, perm_main_mem_d, - perm_main_mem_ind_a, - perm_main_mem_ind_b, - perm_main_mem_ind_c, - perm_main_mem_ind_d, + perm_main_mem_ind_addr_a, + perm_main_mem_ind_addr_b, + perm_main_mem_ind_addr_c, + perm_main_mem_ind_addr_d, lookup_byte_lengths, lookup_byte_operations, lookup_opcode_gas, @@ -1869,364 +1869,364 @@ class AvmFlavor { lookup_div_u16_5_counts, lookup_div_u16_6_counts, lookup_div_u16_7_counts, - avm_alu_a_hi_shift, - avm_alu_a_lo_shift, - avm_alu_alu_sel_shift, - avm_alu_b_hi_shift, - avm_alu_b_lo_shift, - avm_alu_cmp_rng_ctr_shift, - avm_alu_cmp_sel_shift, - avm_alu_div_rng_chk_selector_shift, - avm_alu_div_u16_r0_shift, - avm_alu_div_u16_r1_shift, - avm_alu_div_u16_r2_shift, - avm_alu_div_u16_r3_shift, - avm_alu_div_u16_r4_shift, - avm_alu_div_u16_r5_shift, - avm_alu_div_u16_r6_shift, - avm_alu_div_u16_r7_shift, - avm_alu_op_add_shift, - avm_alu_op_cast_prev_shift, - avm_alu_op_cast_shift, - avm_alu_op_div_shift, - avm_alu_op_mul_shift, - avm_alu_op_shl_shift, - avm_alu_op_shr_shift, - avm_alu_op_sub_shift, - avm_alu_p_sub_a_hi_shift, - avm_alu_p_sub_a_lo_shift, - avm_alu_p_sub_b_hi_shift, - avm_alu_p_sub_b_lo_shift, - avm_alu_rng_chk_lookup_selector_shift, - avm_alu_rng_chk_sel_shift, - avm_alu_u16_r0_shift, - avm_alu_u16_r1_shift, - avm_alu_u16_r2_shift, - avm_alu_u16_r3_shift, - avm_alu_u16_r4_shift, - avm_alu_u16_r5_shift, - avm_alu_u16_r6_shift, - avm_alu_u8_r0_shift, - avm_alu_u8_r1_shift, - avm_binary_acc_ia_shift, - avm_binary_acc_ib_shift, - avm_binary_acc_ic_shift, - avm_binary_mem_tag_ctr_shift, - avm_binary_op_id_shift, - avm_kernel_emit_l2_to_l1_msg_write_offset_shift, - avm_kernel_emit_note_hash_write_offset_shift, - avm_kernel_emit_nullifier_write_offset_shift, - avm_kernel_emit_unencrypted_log_write_offset_shift, - avm_kernel_l1_to_l2_msg_exists_write_offset_shift, - avm_kernel_note_hash_exist_write_offset_shift, - avm_kernel_nullifier_exists_write_offset_shift, - avm_kernel_nullifier_non_exists_write_offset_shift, - avm_kernel_side_effect_counter_shift, - avm_kernel_sload_write_offset_shift, - avm_kernel_sstore_write_offset_shift, - avm_main_da_gas_remaining_shift, - avm_main_internal_return_ptr_shift, - avm_main_l2_gas_remaining_shift, - avm_main_pc_shift, - avm_mem_glob_addr_shift, - avm_mem_mem_sel_shift, - avm_mem_rw_shift, - avm_mem_tag_shift, - avm_mem_tsp_shift, - avm_mem_val_shift }; + alu_a_hi_shift, + alu_a_lo_shift, + alu_b_hi_shift, + alu_b_lo_shift, + alu_cmp_rng_ctr_shift, + alu_div_u16_r0_shift, + alu_div_u16_r1_shift, + alu_div_u16_r2_shift, + alu_div_u16_r3_shift, + alu_div_u16_r4_shift, + alu_div_u16_r5_shift, + alu_div_u16_r6_shift, + alu_div_u16_r7_shift, + alu_op_add_shift, + alu_op_cast_prev_shift, + alu_op_cast_shift, + alu_op_div_shift, + alu_op_mul_shift, + alu_op_shl_shift, + alu_op_shr_shift, + alu_op_sub_shift, + alu_p_sub_a_hi_shift, + alu_p_sub_a_lo_shift, + alu_p_sub_b_hi_shift, + alu_p_sub_b_lo_shift, + alu_sel_alu_shift, + alu_sel_cmp_shift, + alu_sel_div_rng_chk_shift, + alu_sel_rng_chk_lookup_shift, + alu_sel_rng_chk_shift, + alu_u16_r0_shift, + alu_u16_r1_shift, + alu_u16_r2_shift, + alu_u16_r3_shift, + alu_u16_r4_shift, + alu_u16_r5_shift, + alu_u16_r6_shift, + alu_u8_r0_shift, + alu_u8_r1_shift, + binary_acc_ia_shift, + binary_acc_ib_shift, + binary_acc_ic_shift, + binary_mem_tag_ctr_shift, + binary_op_id_shift, + kernel_emit_l2_to_l1_msg_write_offset_shift, + kernel_emit_note_hash_write_offset_shift, + kernel_emit_nullifier_write_offset_shift, + kernel_emit_unencrypted_log_write_offset_shift, + kernel_l1_to_l2_msg_exists_write_offset_shift, + kernel_note_hash_exist_write_offset_shift, + kernel_nullifier_exists_write_offset_shift, + kernel_nullifier_non_exists_write_offset_shift, + kernel_side_effect_counter_shift, + kernel_sload_write_offset_shift, + kernel_sstore_write_offset_shift, + main_da_gas_remaining_shift, + main_internal_return_ptr_shift, + main_l2_gas_remaining_shift, + main_pc_shift, + mem_glob_addr_shift, + mem_rw_shift, + mem_sel_mem_shift, + mem_tag_shift, + mem_tsp_shift, + mem_val_shift }; }; RefVector get_unshifted() { - return { avm_main_clk, - avm_main_first, - avm_alu_a_hi, - avm_alu_a_lo, - avm_alu_alu_sel, - avm_alu_b_hi, - avm_alu_b_lo, - avm_alu_borrow, - avm_alu_cf, - avm_alu_clk, - avm_alu_cmp_rng_ctr, - avm_alu_cmp_sel, - avm_alu_div_rng_chk_selector, - avm_alu_div_u16_r0, - avm_alu_div_u16_r1, - avm_alu_div_u16_r2, - avm_alu_div_u16_r3, - avm_alu_div_u16_r4, - avm_alu_div_u16_r5, - avm_alu_div_u16_r6, - avm_alu_div_u16_r7, - avm_alu_divisor_hi, - avm_alu_divisor_lo, - avm_alu_ff_tag, - avm_alu_ia, - avm_alu_ib, - avm_alu_ic, - avm_alu_in_tag, - avm_alu_op_add, - avm_alu_op_cast, - avm_alu_op_cast_prev, - avm_alu_op_div, - avm_alu_op_div_a_lt_b, - avm_alu_op_div_std, - avm_alu_op_eq, - avm_alu_op_eq_diff_inv, - avm_alu_op_lt, - avm_alu_op_lte, - avm_alu_op_mul, - avm_alu_op_not, - avm_alu_op_shl, - avm_alu_op_shr, - avm_alu_op_sub, - avm_alu_p_a_borrow, - avm_alu_p_b_borrow, - avm_alu_p_sub_a_hi, - avm_alu_p_sub_a_lo, - avm_alu_p_sub_b_hi, - avm_alu_p_sub_b_lo, - avm_alu_partial_prod_hi, - avm_alu_partial_prod_lo, - avm_alu_quotient_hi, - avm_alu_quotient_lo, - avm_alu_remainder, - avm_alu_res_hi, - avm_alu_res_lo, - avm_alu_rng_chk_lookup_selector, - avm_alu_rng_chk_sel, - avm_alu_shift_lt_bit_len, - avm_alu_shift_sel, - avm_alu_t_sub_s_bits, - avm_alu_two_pow_s, - avm_alu_two_pow_t_sub_s, - avm_alu_u128_tag, - avm_alu_u16_r0, - avm_alu_u16_r1, - avm_alu_u16_r10, - avm_alu_u16_r11, - avm_alu_u16_r12, - avm_alu_u16_r13, - avm_alu_u16_r14, - avm_alu_u16_r2, - avm_alu_u16_r3, - avm_alu_u16_r4, - avm_alu_u16_r5, - avm_alu_u16_r6, - avm_alu_u16_r7, - avm_alu_u16_r8, - avm_alu_u16_r9, - avm_alu_u16_tag, - avm_alu_u32_tag, - avm_alu_u64_tag, - avm_alu_u8_r0, - avm_alu_u8_r1, - avm_alu_u8_tag, - avm_binary_acc_ia, - avm_binary_acc_ib, - avm_binary_acc_ic, - avm_binary_bin_sel, - avm_binary_clk, - avm_binary_ia_bytes, - avm_binary_ib_bytes, - avm_binary_ic_bytes, - avm_binary_in_tag, - avm_binary_mem_tag_ctr, - avm_binary_mem_tag_ctr_inv, - avm_binary_op_id, - avm_binary_start, - avm_byte_lookup_bin_sel, - avm_byte_lookup_table_byte_lengths, - avm_byte_lookup_table_in_tags, - avm_byte_lookup_table_input_a, - avm_byte_lookup_table_input_b, - avm_byte_lookup_table_op_id, - avm_byte_lookup_table_output, - avm_conversion_clk, - avm_conversion_input, - avm_conversion_num_limbs, - avm_conversion_radix, - avm_conversion_to_radix_le_sel, - avm_gas_da_gas_fixed_table, - avm_gas_gas_cost_sel, - avm_gas_l2_gas_fixed_table, - avm_keccakf1600_clk, - avm_keccakf1600_input, - avm_keccakf1600_keccakf1600_sel, - avm_keccakf1600_output, - avm_kernel_emit_l2_to_l1_msg_write_offset, - avm_kernel_emit_note_hash_write_offset, - avm_kernel_emit_nullifier_write_offset, - avm_kernel_emit_unencrypted_log_write_offset, - avm_kernel_kernel_in_offset, - avm_kernel_kernel_inputs, - avm_kernel_kernel_metadata_out, - avm_kernel_kernel_out_offset, - avm_kernel_kernel_side_effect_out, - avm_kernel_kernel_value_out, - avm_kernel_l1_to_l2_msg_exists_write_offset, - avm_kernel_note_hash_exist_write_offset, - avm_kernel_nullifier_exists_write_offset, - avm_kernel_nullifier_non_exists_write_offset, - avm_kernel_q_public_input_kernel_add_to_table, - avm_kernel_q_public_input_kernel_out_add_to_table, - avm_kernel_side_effect_counter, - avm_kernel_sload_write_offset, - avm_kernel_sstore_write_offset, - avm_main_abs_da_rem_gas_hi, - avm_main_abs_da_rem_gas_lo, - avm_main_abs_l2_rem_gas_hi, - avm_main_abs_l2_rem_gas_lo, - avm_main_alu_in_tag, - avm_main_alu_sel, - avm_main_bin_op_id, - avm_main_bin_sel, - avm_main_call_ptr, - avm_main_da_gas_op, - avm_main_da_gas_remaining, - avm_main_da_out_of_gas, - avm_main_gas_cost_active, - avm_main_ia, - avm_main_ib, - avm_main_ic, - avm_main_id, - avm_main_id_zero, - avm_main_ind_a, - avm_main_ind_b, - avm_main_ind_c, - avm_main_ind_d, - avm_main_ind_op_a, - avm_main_ind_op_b, - avm_main_ind_op_c, - avm_main_ind_op_d, - avm_main_internal_return_ptr, - avm_main_inv, - avm_main_l2_gas_op, - avm_main_l2_gas_remaining, - avm_main_l2_out_of_gas, - avm_main_last, - avm_main_mem_idx_a, - avm_main_mem_idx_b, - avm_main_mem_idx_c, - avm_main_mem_idx_d, - avm_main_mem_op_a, - avm_main_mem_op_activate_gas, - avm_main_mem_op_b, - avm_main_mem_op_c, - avm_main_mem_op_d, - avm_main_op_err, - avm_main_opcode_val, - avm_main_pc, - avm_main_q_kernel_lookup, - avm_main_q_kernel_output_lookup, - avm_main_r_in_tag, - avm_main_rwa, - avm_main_rwb, - avm_main_rwc, - avm_main_rwd, - avm_main_sel_cmov, - avm_main_sel_external_call, - avm_main_sel_halt, - avm_main_sel_internal_call, - avm_main_sel_internal_return, - avm_main_sel_jump, - avm_main_sel_jumpi, - avm_main_sel_mov, - avm_main_sel_mov_a, - avm_main_sel_mov_b, - avm_main_sel_op_add, - avm_main_sel_op_address, - avm_main_sel_op_and, - avm_main_sel_op_block_number, - avm_main_sel_op_cast, - avm_main_sel_op_chain_id, - avm_main_sel_op_coinbase, - avm_main_sel_op_dagasleft, - avm_main_sel_op_div, - avm_main_sel_op_emit_l2_to_l1_msg, - avm_main_sel_op_emit_note_hash, - avm_main_sel_op_emit_nullifier, - avm_main_sel_op_emit_unencrypted_log, - avm_main_sel_op_eq, - avm_main_sel_op_fdiv, - avm_main_sel_op_fee_per_da_gas, - avm_main_sel_op_fee_per_l2_gas, - avm_main_sel_op_get_contract_instance, - avm_main_sel_op_keccak, - avm_main_sel_op_l1_to_l2_msg_exists, - avm_main_sel_op_l2gasleft, - avm_main_sel_op_lt, - avm_main_sel_op_lte, - avm_main_sel_op_mul, - avm_main_sel_op_not, - avm_main_sel_op_note_hash_exists, - avm_main_sel_op_nullifier_exists, - avm_main_sel_op_or, - avm_main_sel_op_pedersen, - avm_main_sel_op_poseidon2, - avm_main_sel_op_radix_le, - avm_main_sel_op_sender, - avm_main_sel_op_sha256, - avm_main_sel_op_shl, - avm_main_sel_op_shr, - avm_main_sel_op_sload, - avm_main_sel_op_sstore, - avm_main_sel_op_storage_address, - avm_main_sel_op_sub, - avm_main_sel_op_timestamp, - avm_main_sel_op_transaction_fee, - avm_main_sel_op_version, - avm_main_sel_op_xor, - avm_main_sel_rng_16, - avm_main_sel_rng_8, - avm_main_space_id, - avm_main_table_pow_2, - avm_main_tag_err, - avm_main_w_in_tag, - avm_mem_addr, - avm_mem_clk, - avm_mem_diff_hi, - avm_mem_diff_lo, - avm_mem_diff_mid, - avm_mem_glob_addr, - avm_mem_ind_op_a, - avm_mem_ind_op_b, - avm_mem_ind_op_c, - avm_mem_ind_op_d, - avm_mem_last, - avm_mem_lastAccess, - avm_mem_mem_sel, - avm_mem_one_min_inv, - avm_mem_op_a, - avm_mem_op_b, - avm_mem_op_c, - avm_mem_op_d, - avm_mem_r_in_tag, - avm_mem_rng_chk_sel, - avm_mem_rw, - avm_mem_sel_cmov, - avm_mem_sel_mov_a, - avm_mem_sel_mov_b, - avm_mem_skip_check_tag, - avm_mem_space_id, - avm_mem_tag, - avm_mem_tag_err, - avm_mem_tsp, - avm_mem_val, - avm_mem_w_in_tag, - avm_pedersen_clk, - avm_pedersen_input, - avm_pedersen_output, - avm_pedersen_pedersen_sel, - avm_poseidon2_clk, - avm_poseidon2_input, - avm_poseidon2_output, - avm_poseidon2_poseidon_perm_sel, - avm_sha256_clk, - avm_sha256_input, - avm_sha256_output, - avm_sha256_sha256_compression_sel, - avm_sha256_state, + return { main_clk, + main_sel_first, + alu_a_hi, + alu_a_lo, + alu_b_hi, + alu_b_lo, + alu_borrow, + alu_cf, + alu_clk, + alu_cmp_rng_ctr, + alu_div_u16_r0, + alu_div_u16_r1, + alu_div_u16_r2, + alu_div_u16_r3, + alu_div_u16_r4, + alu_div_u16_r5, + alu_div_u16_r6, + alu_div_u16_r7, + alu_divisor_hi, + alu_divisor_lo, + alu_ff_tag, + alu_ia, + alu_ib, + alu_ic, + alu_in_tag, + alu_op_add, + alu_op_cast, + alu_op_cast_prev, + alu_op_div, + alu_op_div_a_lt_b, + alu_op_div_std, + alu_op_eq, + alu_op_eq_diff_inv, + alu_op_lt, + alu_op_lte, + alu_op_mul, + alu_op_not, + alu_op_shl, + alu_op_shr, + alu_op_sub, + alu_p_a_borrow, + alu_p_b_borrow, + alu_p_sub_a_hi, + alu_p_sub_a_lo, + alu_p_sub_b_hi, + alu_p_sub_b_lo, + alu_partial_prod_hi, + alu_partial_prod_lo, + alu_quotient_hi, + alu_quotient_lo, + alu_remainder, + alu_res_hi, + alu_res_lo, + alu_sel_alu, + alu_sel_cmp, + alu_sel_div_rng_chk, + alu_sel_rng_chk, + alu_sel_rng_chk_lookup, + alu_sel_shift_which, + alu_shift_lt_bit_len, + alu_t_sub_s_bits, + alu_two_pow_s, + alu_two_pow_t_sub_s, + alu_u128_tag, + alu_u16_r0, + alu_u16_r1, + alu_u16_r10, + alu_u16_r11, + alu_u16_r12, + alu_u16_r13, + alu_u16_r14, + alu_u16_r2, + alu_u16_r3, + alu_u16_r4, + alu_u16_r5, + alu_u16_r6, + alu_u16_r7, + alu_u16_r8, + alu_u16_r9, + alu_u16_tag, + alu_u32_tag, + alu_u64_tag, + alu_u8_r0, + alu_u8_r1, + alu_u8_tag, + binary_acc_ia, + binary_acc_ib, + binary_acc_ic, + binary_clk, + binary_ia_bytes, + binary_ib_bytes, + binary_ic_bytes, + binary_in_tag, + binary_mem_tag_ctr, + binary_mem_tag_ctr_inv, + binary_op_id, + binary_sel_bin, + binary_start, + byte_lookup_sel_bin, + byte_lookup_table_byte_lengths, + byte_lookup_table_in_tags, + byte_lookup_table_input_a, + byte_lookup_table_input_b, + byte_lookup_table_op_id, + byte_lookup_table_output, + conversion_clk, + conversion_input, + conversion_num_limbs, + conversion_radix, + conversion_sel_to_radix_le, + gas_da_gas_fixed_table, + gas_l2_gas_fixed_table, + gas_sel_gas_cost, + keccakf1600_clk, + keccakf1600_input, + keccakf1600_output, + keccakf1600_sel_keccakf1600, + kernel_emit_l2_to_l1_msg_write_offset, + kernel_emit_note_hash_write_offset, + kernel_emit_nullifier_write_offset, + kernel_emit_unencrypted_log_write_offset, + kernel_kernel_in_offset, + kernel_kernel_inputs, + kernel_kernel_metadata_out, + kernel_kernel_out_offset, + kernel_kernel_side_effect_out, + kernel_kernel_value_out, + kernel_l1_to_l2_msg_exists_write_offset, + kernel_note_hash_exist_write_offset, + kernel_nullifier_exists_write_offset, + kernel_nullifier_non_exists_write_offset, + kernel_q_public_input_kernel_add_to_table, + kernel_q_public_input_kernel_out_add_to_table, + kernel_side_effect_counter, + kernel_sload_write_offset, + kernel_sstore_write_offset, + main_abs_da_rem_gas_hi, + main_abs_da_rem_gas_lo, + main_abs_l2_rem_gas_hi, + main_abs_l2_rem_gas_lo, + main_alu_in_tag, + main_bin_op_id, + main_call_ptr, + main_da_gas_op_cost, + main_da_gas_remaining, + main_da_out_of_gas, + main_ia, + main_ib, + main_ic, + main_id, + main_id_zero, + main_ind_addr_a, + main_ind_addr_b, + main_ind_addr_c, + main_ind_addr_d, + main_internal_return_ptr, + main_inv, + main_l2_gas_op_cost, + main_l2_gas_remaining, + main_l2_out_of_gas, + main_mem_addr_a, + main_mem_addr_b, + main_mem_addr_c, + main_mem_addr_d, + main_op_err, + main_opcode_val, + main_pc, + main_r_in_tag, + main_rwa, + main_rwb, + main_rwc, + main_rwd, + main_sel_alu, + main_sel_bin, + main_sel_gas_accounting_active, + main_sel_last, + main_sel_mem_op_a, + main_sel_mem_op_activate_gas, + main_sel_mem_op_b, + main_sel_mem_op_c, + main_sel_mem_op_d, + main_sel_mov_ia_to_ic, + main_sel_mov_ib_to_ic, + main_sel_op_add, + main_sel_op_address, + main_sel_op_and, + main_sel_op_block_number, + main_sel_op_cast, + main_sel_op_chain_id, + main_sel_op_cmov, + main_sel_op_coinbase, + main_sel_op_dagasleft, + main_sel_op_div, + main_sel_op_emit_l2_to_l1_msg, + main_sel_op_emit_note_hash, + main_sel_op_emit_nullifier, + main_sel_op_emit_unencrypted_log, + main_sel_op_eq, + main_sel_op_external_call, + main_sel_op_fdiv, + main_sel_op_fee_per_da_gas, + main_sel_op_fee_per_l2_gas, + main_sel_op_get_contract_instance, + main_sel_op_halt, + main_sel_op_internal_call, + main_sel_op_internal_return, + main_sel_op_jump, + main_sel_op_jumpi, + main_sel_op_keccak, + main_sel_op_l1_to_l2_msg_exists, + main_sel_op_l2gasleft, + main_sel_op_lt, + main_sel_op_lte, + main_sel_op_mov, + main_sel_op_mul, + main_sel_op_not, + main_sel_op_note_hash_exists, + main_sel_op_nullifier_exists, + main_sel_op_or, + main_sel_op_pedersen, + main_sel_op_poseidon2, + main_sel_op_radix_le, + main_sel_op_sender, + main_sel_op_sha256, + main_sel_op_shl, + main_sel_op_shr, + main_sel_op_sload, + main_sel_op_sstore, + main_sel_op_storage_address, + main_sel_op_sub, + main_sel_op_timestamp, + main_sel_op_transaction_fee, + main_sel_op_version, + main_sel_op_xor, + main_sel_q_kernel_lookup, + main_sel_q_kernel_output_lookup, + main_sel_resolve_ind_addr_a, + main_sel_resolve_ind_addr_b, + main_sel_resolve_ind_addr_c, + main_sel_resolve_ind_addr_d, + main_sel_rng_16, + main_sel_rng_8, + main_space_id, + main_table_pow_2, + main_tag_err, + main_w_in_tag, + mem_addr, + mem_clk, + mem_diff_hi, + mem_diff_lo, + mem_diff_mid, + mem_glob_addr, + mem_last, + mem_lastAccess, + mem_one_min_inv, + mem_r_in_tag, + mem_rw, + mem_sel_mem, + mem_sel_mov_ia_to_ic, + mem_sel_mov_ib_to_ic, + mem_sel_op_a, + mem_sel_op_b, + mem_sel_op_c, + mem_sel_op_cmov, + mem_sel_op_d, + mem_sel_resolve_ind_addr_a, + mem_sel_resolve_ind_addr_b, + mem_sel_resolve_ind_addr_c, + mem_sel_resolve_ind_addr_d, + mem_sel_rng_chk, + mem_skip_check_tag, + mem_space_id, + mem_tag, + mem_tag_err, + mem_tsp, + mem_val, + mem_w_in_tag, + pedersen_clk, + pedersen_input, + pedersen_output, + pedersen_sel_pedersen, + poseidon2_clk, + poseidon2_input, + poseidon2_output, + poseidon2_sel_poseidon_perm, + sha256_clk, + sha256_input, + sha256_output, + sha256_sel_sha256_compression, + sha256_state, perm_main_alu, perm_main_bin, perm_main_conv, @@ -2236,10 +2236,10 @@ class AvmFlavor { perm_main_mem_b, perm_main_mem_c, perm_main_mem_d, - perm_main_mem_ind_a, - perm_main_mem_ind_b, - perm_main_mem_ind_c, - perm_main_mem_ind_d, + perm_main_mem_ind_addr_a, + perm_main_mem_ind_addr_b, + perm_main_mem_ind_addr_c, + perm_main_mem_ind_addr_d, lookup_byte_lengths, lookup_byte_operations, lookup_opcode_gas, @@ -2325,139 +2325,139 @@ class AvmFlavor { }; RefVector get_to_be_shifted() { - return { avm_alu_a_hi, - avm_alu_a_lo, - avm_alu_alu_sel, - avm_alu_b_hi, - avm_alu_b_lo, - avm_alu_cmp_rng_ctr, - avm_alu_cmp_sel, - avm_alu_div_rng_chk_selector, - avm_alu_div_u16_r0, - avm_alu_div_u16_r1, - avm_alu_div_u16_r2, - avm_alu_div_u16_r3, - avm_alu_div_u16_r4, - avm_alu_div_u16_r5, - avm_alu_div_u16_r6, - avm_alu_div_u16_r7, - avm_alu_op_add, - avm_alu_op_cast_prev, - avm_alu_op_cast, - avm_alu_op_div, - avm_alu_op_mul, - avm_alu_op_shl, - avm_alu_op_shr, - avm_alu_op_sub, - avm_alu_p_sub_a_hi, - avm_alu_p_sub_a_lo, - avm_alu_p_sub_b_hi, - avm_alu_p_sub_b_lo, - avm_alu_rng_chk_lookup_selector, - avm_alu_rng_chk_sel, - avm_alu_u16_r0, - avm_alu_u16_r1, - avm_alu_u16_r2, - avm_alu_u16_r3, - avm_alu_u16_r4, - avm_alu_u16_r5, - avm_alu_u16_r6, - avm_alu_u8_r0, - avm_alu_u8_r1, - avm_binary_acc_ia, - avm_binary_acc_ib, - avm_binary_acc_ic, - avm_binary_mem_tag_ctr, - avm_binary_op_id, - avm_kernel_emit_l2_to_l1_msg_write_offset, - avm_kernel_emit_note_hash_write_offset, - avm_kernel_emit_nullifier_write_offset, - avm_kernel_emit_unencrypted_log_write_offset, - avm_kernel_l1_to_l2_msg_exists_write_offset, - avm_kernel_note_hash_exist_write_offset, - avm_kernel_nullifier_exists_write_offset, - avm_kernel_nullifier_non_exists_write_offset, - avm_kernel_side_effect_counter, - avm_kernel_sload_write_offset, - avm_kernel_sstore_write_offset, - avm_main_da_gas_remaining, - avm_main_internal_return_ptr, - avm_main_l2_gas_remaining, - avm_main_pc, - avm_mem_glob_addr, - avm_mem_mem_sel, - avm_mem_rw, - avm_mem_tag, - avm_mem_tsp, - avm_mem_val }; + return { alu_a_hi, + alu_a_lo, + alu_b_hi, + alu_b_lo, + alu_cmp_rng_ctr, + alu_div_u16_r0, + alu_div_u16_r1, + alu_div_u16_r2, + alu_div_u16_r3, + alu_div_u16_r4, + alu_div_u16_r5, + alu_div_u16_r6, + alu_div_u16_r7, + alu_op_add, + alu_op_cast_prev, + alu_op_cast, + alu_op_div, + alu_op_mul, + alu_op_shl, + alu_op_shr, + alu_op_sub, + alu_p_sub_a_hi, + alu_p_sub_a_lo, + alu_p_sub_b_hi, + alu_p_sub_b_lo, + alu_sel_alu, + alu_sel_cmp, + alu_sel_div_rng_chk, + alu_sel_rng_chk_lookup, + alu_sel_rng_chk, + alu_u16_r0, + alu_u16_r1, + alu_u16_r2, + alu_u16_r3, + alu_u16_r4, + alu_u16_r5, + alu_u16_r6, + alu_u8_r0, + alu_u8_r1, + binary_acc_ia, + binary_acc_ib, + binary_acc_ic, + binary_mem_tag_ctr, + binary_op_id, + kernel_emit_l2_to_l1_msg_write_offset, + kernel_emit_note_hash_write_offset, + kernel_emit_nullifier_write_offset, + kernel_emit_unencrypted_log_write_offset, + kernel_l1_to_l2_msg_exists_write_offset, + kernel_note_hash_exist_write_offset, + kernel_nullifier_exists_write_offset, + kernel_nullifier_non_exists_write_offset, + kernel_side_effect_counter, + kernel_sload_write_offset, + kernel_sstore_write_offset, + main_da_gas_remaining, + main_internal_return_ptr, + main_l2_gas_remaining, + main_pc, + mem_glob_addr, + mem_rw, + mem_sel_mem, + mem_tag, + mem_tsp, + mem_val }; }; RefVector get_shifted() { - return { avm_alu_a_hi_shift, - avm_alu_a_lo_shift, - avm_alu_alu_sel_shift, - avm_alu_b_hi_shift, - avm_alu_b_lo_shift, - avm_alu_cmp_rng_ctr_shift, - avm_alu_cmp_sel_shift, - avm_alu_div_rng_chk_selector_shift, - avm_alu_div_u16_r0_shift, - avm_alu_div_u16_r1_shift, - avm_alu_div_u16_r2_shift, - avm_alu_div_u16_r3_shift, - avm_alu_div_u16_r4_shift, - avm_alu_div_u16_r5_shift, - avm_alu_div_u16_r6_shift, - avm_alu_div_u16_r7_shift, - avm_alu_op_add_shift, - avm_alu_op_cast_prev_shift, - avm_alu_op_cast_shift, - avm_alu_op_div_shift, - avm_alu_op_mul_shift, - avm_alu_op_shl_shift, - avm_alu_op_shr_shift, - avm_alu_op_sub_shift, - avm_alu_p_sub_a_hi_shift, - avm_alu_p_sub_a_lo_shift, - avm_alu_p_sub_b_hi_shift, - avm_alu_p_sub_b_lo_shift, - avm_alu_rng_chk_lookup_selector_shift, - avm_alu_rng_chk_sel_shift, - avm_alu_u16_r0_shift, - avm_alu_u16_r1_shift, - avm_alu_u16_r2_shift, - avm_alu_u16_r3_shift, - avm_alu_u16_r4_shift, - avm_alu_u16_r5_shift, - avm_alu_u16_r6_shift, - avm_alu_u8_r0_shift, - avm_alu_u8_r1_shift, - avm_binary_acc_ia_shift, - avm_binary_acc_ib_shift, - avm_binary_acc_ic_shift, - avm_binary_mem_tag_ctr_shift, - avm_binary_op_id_shift, - avm_kernel_emit_l2_to_l1_msg_write_offset_shift, - avm_kernel_emit_note_hash_write_offset_shift, - avm_kernel_emit_nullifier_write_offset_shift, - avm_kernel_emit_unencrypted_log_write_offset_shift, - avm_kernel_l1_to_l2_msg_exists_write_offset_shift, - avm_kernel_note_hash_exist_write_offset_shift, - avm_kernel_nullifier_exists_write_offset_shift, - avm_kernel_nullifier_non_exists_write_offset_shift, - avm_kernel_side_effect_counter_shift, - avm_kernel_sload_write_offset_shift, - avm_kernel_sstore_write_offset_shift, - avm_main_da_gas_remaining_shift, - avm_main_internal_return_ptr_shift, - avm_main_l2_gas_remaining_shift, - avm_main_pc_shift, - avm_mem_glob_addr_shift, - avm_mem_mem_sel_shift, - avm_mem_rw_shift, - avm_mem_tag_shift, - avm_mem_tsp_shift, - avm_mem_val_shift }; + return { alu_a_hi_shift, + alu_a_lo_shift, + alu_b_hi_shift, + alu_b_lo_shift, + alu_cmp_rng_ctr_shift, + alu_div_u16_r0_shift, + alu_div_u16_r1_shift, + alu_div_u16_r2_shift, + alu_div_u16_r3_shift, + alu_div_u16_r4_shift, + alu_div_u16_r5_shift, + alu_div_u16_r6_shift, + alu_div_u16_r7_shift, + alu_op_add_shift, + alu_op_cast_prev_shift, + alu_op_cast_shift, + alu_op_div_shift, + alu_op_mul_shift, + alu_op_shl_shift, + alu_op_shr_shift, + alu_op_sub_shift, + alu_p_sub_a_hi_shift, + alu_p_sub_a_lo_shift, + alu_p_sub_b_hi_shift, + alu_p_sub_b_lo_shift, + alu_sel_alu_shift, + alu_sel_cmp_shift, + alu_sel_div_rng_chk_shift, + alu_sel_rng_chk_lookup_shift, + alu_sel_rng_chk_shift, + alu_u16_r0_shift, + alu_u16_r1_shift, + alu_u16_r2_shift, + alu_u16_r3_shift, + alu_u16_r4_shift, + alu_u16_r5_shift, + alu_u16_r6_shift, + alu_u8_r0_shift, + alu_u8_r1_shift, + binary_acc_ia_shift, + binary_acc_ib_shift, + binary_acc_ic_shift, + binary_mem_tag_ctr_shift, + binary_op_id_shift, + kernel_emit_l2_to_l1_msg_write_offset_shift, + kernel_emit_note_hash_write_offset_shift, + kernel_emit_nullifier_write_offset_shift, + kernel_emit_unencrypted_log_write_offset_shift, + kernel_l1_to_l2_msg_exists_write_offset_shift, + kernel_note_hash_exist_write_offset_shift, + kernel_nullifier_exists_write_offset_shift, + kernel_nullifier_non_exists_write_offset_shift, + kernel_side_effect_counter_shift, + kernel_sload_write_offset_shift, + kernel_sstore_write_offset_shift, + main_da_gas_remaining_shift, + main_internal_return_ptr_shift, + main_l2_gas_remaining_shift, + main_pc_shift, + mem_glob_addr_shift, + mem_rw_shift, + mem_sel_mem_shift, + mem_tag_shift, + mem_tsp_shift, + mem_val_shift }; }; }; @@ -2471,71 +2471,71 @@ class AvmFlavor { RefVector get_to_be_shifted() { - return { avm_alu_a_hi, - avm_alu_a_lo, - avm_alu_alu_sel, - avm_alu_b_hi, - avm_alu_b_lo, - avm_alu_cmp_rng_ctr, - avm_alu_cmp_sel, - avm_alu_div_rng_chk_selector, - avm_alu_div_u16_r0, - avm_alu_div_u16_r1, - avm_alu_div_u16_r2, - avm_alu_div_u16_r3, - avm_alu_div_u16_r4, - avm_alu_div_u16_r5, - avm_alu_div_u16_r6, - avm_alu_div_u16_r7, - avm_alu_op_add, - avm_alu_op_cast_prev, - avm_alu_op_cast, - avm_alu_op_div, - avm_alu_op_mul, - avm_alu_op_shl, - avm_alu_op_shr, - avm_alu_op_sub, - avm_alu_p_sub_a_hi, - avm_alu_p_sub_a_lo, - avm_alu_p_sub_b_hi, - avm_alu_p_sub_b_lo, - avm_alu_rng_chk_lookup_selector, - avm_alu_rng_chk_sel, - avm_alu_u16_r0, - avm_alu_u16_r1, - avm_alu_u16_r2, - avm_alu_u16_r3, - avm_alu_u16_r4, - avm_alu_u16_r5, - avm_alu_u16_r6, - avm_alu_u8_r0, - avm_alu_u8_r1, - avm_binary_acc_ia, - avm_binary_acc_ib, - avm_binary_acc_ic, - avm_binary_mem_tag_ctr, - avm_binary_op_id, - avm_kernel_emit_l2_to_l1_msg_write_offset, - avm_kernel_emit_note_hash_write_offset, - avm_kernel_emit_nullifier_write_offset, - avm_kernel_emit_unencrypted_log_write_offset, - avm_kernel_l1_to_l2_msg_exists_write_offset, - avm_kernel_note_hash_exist_write_offset, - avm_kernel_nullifier_exists_write_offset, - avm_kernel_nullifier_non_exists_write_offset, - avm_kernel_side_effect_counter, - avm_kernel_sload_write_offset, - avm_kernel_sstore_write_offset, - avm_main_da_gas_remaining, - avm_main_internal_return_ptr, - avm_main_l2_gas_remaining, - avm_main_pc, - avm_mem_glob_addr, - avm_mem_mem_sel, - avm_mem_rw, - avm_mem_tag, - avm_mem_tsp, - avm_mem_val }; + return { alu_a_hi, + alu_a_lo, + alu_b_hi, + alu_b_lo, + alu_cmp_rng_ctr, + alu_div_u16_r0, + alu_div_u16_r1, + alu_div_u16_r2, + alu_div_u16_r3, + alu_div_u16_r4, + alu_div_u16_r5, + alu_div_u16_r6, + alu_div_u16_r7, + alu_op_add, + alu_op_cast_prev, + alu_op_cast, + alu_op_div, + alu_op_mul, + alu_op_shl, + alu_op_shr, + alu_op_sub, + alu_p_sub_a_hi, + alu_p_sub_a_lo, + alu_p_sub_b_hi, + alu_p_sub_b_lo, + alu_sel_alu, + alu_sel_cmp, + alu_sel_div_rng_chk, + alu_sel_rng_chk_lookup, + alu_sel_rng_chk, + alu_u16_r0, + alu_u16_r1, + alu_u16_r2, + alu_u16_r3, + alu_u16_r4, + alu_u16_r5, + alu_u16_r6, + alu_u8_r0, + alu_u8_r1, + binary_acc_ia, + binary_acc_ib, + binary_acc_ic, + binary_mem_tag_ctr, + binary_op_id, + kernel_emit_l2_to_l1_msg_write_offset, + kernel_emit_note_hash_write_offset, + kernel_emit_nullifier_write_offset, + kernel_emit_unencrypted_log_write_offset, + kernel_l1_to_l2_msg_exists_write_offset, + kernel_note_hash_exist_write_offset, + kernel_nullifier_exists_write_offset, + kernel_nullifier_non_exists_write_offset, + kernel_side_effect_counter, + kernel_sload_write_offset, + kernel_sstore_write_offset, + main_da_gas_remaining, + main_internal_return_ptr, + main_l2_gas_remaining, + main_pc, + mem_glob_addr, + mem_rw, + mem_sel_mem, + mem_tag, + mem_tsp, + mem_val }; }; void compute_logderivative_inverses(const RelationParameters& relation_parameters) @@ -2560,13 +2560,13 @@ class AvmFlavor { prover_polynomials, relation_parameters, this->circuit_size); bb::compute_logderivative_inverse>( prover_polynomials, relation_parameters, this->circuit_size); - bb::compute_logderivative_inverse>( + bb::compute_logderivative_inverse>( prover_polynomials, relation_parameters, this->circuit_size); - bb::compute_logderivative_inverse>( + bb::compute_logderivative_inverse>( prover_polynomials, relation_parameters, this->circuit_size); - bb::compute_logderivative_inverse>( + bb::compute_logderivative_inverse>( prover_polynomials, relation_parameters, this->circuit_size); - bb::compute_logderivative_inverse>( + bb::compute_logderivative_inverse>( prover_polynomials, relation_parameters, this->circuit_size); bb::compute_logderivative_inverse>( prover_polynomials, relation_parameters, this->circuit_size); @@ -2686,7 +2686,7 @@ class AvmFlavor { } } - [[nodiscard]] size_t get_polynomial_size() const { return avm_alu_a_hi.size(); } + [[nodiscard]] size_t get_polynomial_size() const { return alu_a_hi.size(); } /** * @brief Returns the evaluations of all prover polynomials at one point on the boolean hypercube, which * represents one row in the execution trace. @@ -2746,297 +2746,296 @@ class AvmFlavor { CommitmentLabels() : AllEntities() { - Base::avm_main_clk = "AVM_MAIN_CLK"; - Base::avm_main_first = "AVM_MAIN_FIRST"; - Base::avm_alu_a_hi = "AVM_ALU_A_HI"; - Base::avm_alu_a_lo = "AVM_ALU_A_LO"; - Base::avm_alu_alu_sel = "AVM_ALU_ALU_SEL"; - Base::avm_alu_b_hi = "AVM_ALU_B_HI"; - Base::avm_alu_b_lo = "AVM_ALU_B_LO"; - Base::avm_alu_borrow = "AVM_ALU_BORROW"; - Base::avm_alu_cf = "AVM_ALU_CF"; - Base::avm_alu_clk = "AVM_ALU_CLK"; - Base::avm_alu_cmp_rng_ctr = "AVM_ALU_CMP_RNG_CTR"; - Base::avm_alu_cmp_sel = "AVM_ALU_CMP_SEL"; - Base::avm_alu_div_rng_chk_selector = "AVM_ALU_DIV_RNG_CHK_SELECTOR"; - Base::avm_alu_div_u16_r0 = "AVM_ALU_DIV_U16_R0"; - Base::avm_alu_div_u16_r1 = "AVM_ALU_DIV_U16_R1"; - Base::avm_alu_div_u16_r2 = "AVM_ALU_DIV_U16_R2"; - Base::avm_alu_div_u16_r3 = "AVM_ALU_DIV_U16_R3"; - Base::avm_alu_div_u16_r4 = "AVM_ALU_DIV_U16_R4"; - Base::avm_alu_div_u16_r5 = "AVM_ALU_DIV_U16_R5"; - Base::avm_alu_div_u16_r6 = "AVM_ALU_DIV_U16_R6"; - Base::avm_alu_div_u16_r7 = "AVM_ALU_DIV_U16_R7"; - Base::avm_alu_divisor_hi = "AVM_ALU_DIVISOR_HI"; - Base::avm_alu_divisor_lo = "AVM_ALU_DIVISOR_LO"; - Base::avm_alu_ff_tag = "AVM_ALU_FF_TAG"; - Base::avm_alu_ia = "AVM_ALU_IA"; - Base::avm_alu_ib = "AVM_ALU_IB"; - Base::avm_alu_ic = "AVM_ALU_IC"; - Base::avm_alu_in_tag = "AVM_ALU_IN_TAG"; - Base::avm_alu_op_add = "AVM_ALU_OP_ADD"; - Base::avm_alu_op_cast = "AVM_ALU_OP_CAST"; - Base::avm_alu_op_cast_prev = "AVM_ALU_OP_CAST_PREV"; - Base::avm_alu_op_div = "AVM_ALU_OP_DIV"; - Base::avm_alu_op_div_a_lt_b = "AVM_ALU_OP_DIV_A_LT_B"; - Base::avm_alu_op_div_std = "AVM_ALU_OP_DIV_STD"; - Base::avm_alu_op_eq = "AVM_ALU_OP_EQ"; - Base::avm_alu_op_eq_diff_inv = "AVM_ALU_OP_EQ_DIFF_INV"; - Base::avm_alu_op_lt = "AVM_ALU_OP_LT"; - Base::avm_alu_op_lte = "AVM_ALU_OP_LTE"; - Base::avm_alu_op_mul = "AVM_ALU_OP_MUL"; - Base::avm_alu_op_not = "AVM_ALU_OP_NOT"; - Base::avm_alu_op_shl = "AVM_ALU_OP_SHL"; - Base::avm_alu_op_shr = "AVM_ALU_OP_SHR"; - Base::avm_alu_op_sub = "AVM_ALU_OP_SUB"; - Base::avm_alu_p_a_borrow = "AVM_ALU_P_A_BORROW"; - Base::avm_alu_p_b_borrow = "AVM_ALU_P_B_BORROW"; - Base::avm_alu_p_sub_a_hi = "AVM_ALU_P_SUB_A_HI"; - Base::avm_alu_p_sub_a_lo = "AVM_ALU_P_SUB_A_LO"; - Base::avm_alu_p_sub_b_hi = "AVM_ALU_P_SUB_B_HI"; - Base::avm_alu_p_sub_b_lo = "AVM_ALU_P_SUB_B_LO"; - Base::avm_alu_partial_prod_hi = "AVM_ALU_PARTIAL_PROD_HI"; - Base::avm_alu_partial_prod_lo = "AVM_ALU_PARTIAL_PROD_LO"; - Base::avm_alu_quotient_hi = "AVM_ALU_QUOTIENT_HI"; - Base::avm_alu_quotient_lo = "AVM_ALU_QUOTIENT_LO"; - Base::avm_alu_remainder = "AVM_ALU_REMAINDER"; - Base::avm_alu_res_hi = "AVM_ALU_RES_HI"; - Base::avm_alu_res_lo = "AVM_ALU_RES_LO"; - Base::avm_alu_rng_chk_lookup_selector = "AVM_ALU_RNG_CHK_LOOKUP_SELECTOR"; - Base::avm_alu_rng_chk_sel = "AVM_ALU_RNG_CHK_SEL"; - Base::avm_alu_shift_lt_bit_len = "AVM_ALU_SHIFT_LT_BIT_LEN"; - Base::avm_alu_shift_sel = "AVM_ALU_SHIFT_SEL"; - Base::avm_alu_t_sub_s_bits = "AVM_ALU_T_SUB_S_BITS"; - Base::avm_alu_two_pow_s = "AVM_ALU_TWO_POW_S"; - Base::avm_alu_two_pow_t_sub_s = "AVM_ALU_TWO_POW_T_SUB_S"; - Base::avm_alu_u128_tag = "AVM_ALU_U128_TAG"; - Base::avm_alu_u16_r0 = "AVM_ALU_U16_R0"; - Base::avm_alu_u16_r1 = "AVM_ALU_U16_R1"; - Base::avm_alu_u16_r10 = "AVM_ALU_U16_R10"; - Base::avm_alu_u16_r11 = "AVM_ALU_U16_R11"; - Base::avm_alu_u16_r12 = "AVM_ALU_U16_R12"; - Base::avm_alu_u16_r13 = "AVM_ALU_U16_R13"; - Base::avm_alu_u16_r14 = "AVM_ALU_U16_R14"; - Base::avm_alu_u16_r2 = "AVM_ALU_U16_R2"; - Base::avm_alu_u16_r3 = "AVM_ALU_U16_R3"; - Base::avm_alu_u16_r4 = "AVM_ALU_U16_R4"; - Base::avm_alu_u16_r5 = "AVM_ALU_U16_R5"; - Base::avm_alu_u16_r6 = "AVM_ALU_U16_R6"; - Base::avm_alu_u16_r7 = "AVM_ALU_U16_R7"; - Base::avm_alu_u16_r8 = "AVM_ALU_U16_R8"; - Base::avm_alu_u16_r9 = "AVM_ALU_U16_R9"; - Base::avm_alu_u16_tag = "AVM_ALU_U16_TAG"; - Base::avm_alu_u32_tag = "AVM_ALU_U32_TAG"; - Base::avm_alu_u64_tag = "AVM_ALU_U64_TAG"; - Base::avm_alu_u8_r0 = "AVM_ALU_U8_R0"; - Base::avm_alu_u8_r1 = "AVM_ALU_U8_R1"; - Base::avm_alu_u8_tag = "AVM_ALU_U8_TAG"; - Base::avm_binary_acc_ia = "AVM_BINARY_ACC_IA"; - Base::avm_binary_acc_ib = "AVM_BINARY_ACC_IB"; - Base::avm_binary_acc_ic = "AVM_BINARY_ACC_IC"; - Base::avm_binary_bin_sel = "AVM_BINARY_BIN_SEL"; - Base::avm_binary_clk = "AVM_BINARY_CLK"; - Base::avm_binary_ia_bytes = "AVM_BINARY_IA_BYTES"; - Base::avm_binary_ib_bytes = "AVM_BINARY_IB_BYTES"; - Base::avm_binary_ic_bytes = "AVM_BINARY_IC_BYTES"; - Base::avm_binary_in_tag = "AVM_BINARY_IN_TAG"; - Base::avm_binary_mem_tag_ctr = "AVM_BINARY_MEM_TAG_CTR"; - Base::avm_binary_mem_tag_ctr_inv = "AVM_BINARY_MEM_TAG_CTR_INV"; - Base::avm_binary_op_id = "AVM_BINARY_OP_ID"; - Base::avm_binary_start = "AVM_BINARY_START"; - Base::avm_byte_lookup_bin_sel = "AVM_BYTE_LOOKUP_BIN_SEL"; - Base::avm_byte_lookup_table_byte_lengths = "AVM_BYTE_LOOKUP_TABLE_BYTE_LENGTHS"; - Base::avm_byte_lookup_table_in_tags = "AVM_BYTE_LOOKUP_TABLE_IN_TAGS"; - Base::avm_byte_lookup_table_input_a = "AVM_BYTE_LOOKUP_TABLE_INPUT_A"; - Base::avm_byte_lookup_table_input_b = "AVM_BYTE_LOOKUP_TABLE_INPUT_B"; - Base::avm_byte_lookup_table_op_id = "AVM_BYTE_LOOKUP_TABLE_OP_ID"; - Base::avm_byte_lookup_table_output = "AVM_BYTE_LOOKUP_TABLE_OUTPUT"; - Base::avm_conversion_clk = "AVM_CONVERSION_CLK"; - Base::avm_conversion_input = "AVM_CONVERSION_INPUT"; - Base::avm_conversion_num_limbs = "AVM_CONVERSION_NUM_LIMBS"; - Base::avm_conversion_radix = "AVM_CONVERSION_RADIX"; - Base::avm_conversion_to_radix_le_sel = "AVM_CONVERSION_TO_RADIX_LE_SEL"; - Base::avm_gas_da_gas_fixed_table = "AVM_GAS_DA_GAS_FIXED_TABLE"; - Base::avm_gas_gas_cost_sel = "AVM_GAS_GAS_COST_SEL"; - Base::avm_gas_l2_gas_fixed_table = "AVM_GAS_L2_GAS_FIXED_TABLE"; - Base::avm_keccakf1600_clk = "AVM_KECCAKF1600_CLK"; - Base::avm_keccakf1600_input = "AVM_KECCAKF1600_INPUT"; - Base::avm_keccakf1600_keccakf1600_sel = "AVM_KECCAKF1600_KECCAKF1600_SEL"; - Base::avm_keccakf1600_output = "AVM_KECCAKF1600_OUTPUT"; - Base::avm_kernel_emit_l2_to_l1_msg_write_offset = "AVM_KERNEL_EMIT_L2_TO_L1_MSG_WRITE_OFFSET"; - Base::avm_kernel_emit_note_hash_write_offset = "AVM_KERNEL_EMIT_NOTE_HASH_WRITE_OFFSET"; - Base::avm_kernel_emit_nullifier_write_offset = "AVM_KERNEL_EMIT_NULLIFIER_WRITE_OFFSET"; - Base::avm_kernel_emit_unencrypted_log_write_offset = "AVM_KERNEL_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET"; - Base::avm_kernel_kernel_in_offset = "AVM_KERNEL_KERNEL_IN_OFFSET"; - Base::avm_kernel_kernel_inputs = "AVM_KERNEL_KERNEL_INPUTS"; - Base::avm_kernel_kernel_metadata_out = "AVM_KERNEL_KERNEL_METADATA_OUT"; - Base::avm_kernel_kernel_out_offset = "AVM_KERNEL_KERNEL_OUT_OFFSET"; - Base::avm_kernel_kernel_side_effect_out = "AVM_KERNEL_KERNEL_SIDE_EFFECT_OUT"; - Base::avm_kernel_kernel_value_out = "AVM_KERNEL_KERNEL_VALUE_OUT"; - Base::avm_kernel_l1_to_l2_msg_exists_write_offset = "AVM_KERNEL_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET"; - Base::avm_kernel_note_hash_exist_write_offset = "AVM_KERNEL_NOTE_HASH_EXIST_WRITE_OFFSET"; - Base::avm_kernel_nullifier_exists_write_offset = "AVM_KERNEL_NULLIFIER_EXISTS_WRITE_OFFSET"; - Base::avm_kernel_nullifier_non_exists_write_offset = "AVM_KERNEL_NULLIFIER_NON_EXISTS_WRITE_OFFSET"; - Base::avm_kernel_q_public_input_kernel_add_to_table = "AVM_KERNEL_Q_PUBLIC_INPUT_KERNEL_ADD_TO_TABLE"; - Base::avm_kernel_q_public_input_kernel_out_add_to_table = - "AVM_KERNEL_Q_PUBLIC_INPUT_KERNEL_OUT_ADD_TO_TABLE"; - Base::avm_kernel_side_effect_counter = "AVM_KERNEL_SIDE_EFFECT_COUNTER"; - Base::avm_kernel_sload_write_offset = "AVM_KERNEL_SLOAD_WRITE_OFFSET"; - Base::avm_kernel_sstore_write_offset = "AVM_KERNEL_SSTORE_WRITE_OFFSET"; - Base::avm_main_abs_da_rem_gas_hi = "AVM_MAIN_ABS_DA_REM_GAS_HI"; - Base::avm_main_abs_da_rem_gas_lo = "AVM_MAIN_ABS_DA_REM_GAS_LO"; - Base::avm_main_abs_l2_rem_gas_hi = "AVM_MAIN_ABS_L2_REM_GAS_HI"; - Base::avm_main_abs_l2_rem_gas_lo = "AVM_MAIN_ABS_L2_REM_GAS_LO"; - Base::avm_main_alu_in_tag = "AVM_MAIN_ALU_IN_TAG"; - Base::avm_main_alu_sel = "AVM_MAIN_ALU_SEL"; - Base::avm_main_bin_op_id = "AVM_MAIN_BIN_OP_ID"; - Base::avm_main_bin_sel = "AVM_MAIN_BIN_SEL"; - Base::avm_main_call_ptr = "AVM_MAIN_CALL_PTR"; - Base::avm_main_da_gas_op = "AVM_MAIN_DA_GAS_OP"; - Base::avm_main_da_gas_remaining = "AVM_MAIN_DA_GAS_REMAINING"; - Base::avm_main_da_out_of_gas = "AVM_MAIN_DA_OUT_OF_GAS"; - Base::avm_main_gas_cost_active = "AVM_MAIN_GAS_COST_ACTIVE"; - Base::avm_main_ia = "AVM_MAIN_IA"; - Base::avm_main_ib = "AVM_MAIN_IB"; - Base::avm_main_ic = "AVM_MAIN_IC"; - Base::avm_main_id = "AVM_MAIN_ID"; - Base::avm_main_id_zero = "AVM_MAIN_ID_ZERO"; - Base::avm_main_ind_a = "AVM_MAIN_IND_A"; - Base::avm_main_ind_b = "AVM_MAIN_IND_B"; - Base::avm_main_ind_c = "AVM_MAIN_IND_C"; - Base::avm_main_ind_d = "AVM_MAIN_IND_D"; - Base::avm_main_ind_op_a = "AVM_MAIN_IND_OP_A"; - Base::avm_main_ind_op_b = "AVM_MAIN_IND_OP_B"; - Base::avm_main_ind_op_c = "AVM_MAIN_IND_OP_C"; - Base::avm_main_ind_op_d = "AVM_MAIN_IND_OP_D"; - Base::avm_main_internal_return_ptr = "AVM_MAIN_INTERNAL_RETURN_PTR"; - Base::avm_main_inv = "AVM_MAIN_INV"; - Base::avm_main_l2_gas_op = "AVM_MAIN_L2_GAS_OP"; - Base::avm_main_l2_gas_remaining = "AVM_MAIN_L2_GAS_REMAINING"; - Base::avm_main_l2_out_of_gas = "AVM_MAIN_L2_OUT_OF_GAS"; - Base::avm_main_last = "AVM_MAIN_LAST"; - Base::avm_main_mem_idx_a = "AVM_MAIN_MEM_IDX_A"; - Base::avm_main_mem_idx_b = "AVM_MAIN_MEM_IDX_B"; - Base::avm_main_mem_idx_c = "AVM_MAIN_MEM_IDX_C"; - Base::avm_main_mem_idx_d = "AVM_MAIN_MEM_IDX_D"; - Base::avm_main_mem_op_a = "AVM_MAIN_MEM_OP_A"; - Base::avm_main_mem_op_activate_gas = "AVM_MAIN_MEM_OP_ACTIVATE_GAS"; - Base::avm_main_mem_op_b = "AVM_MAIN_MEM_OP_B"; - Base::avm_main_mem_op_c = "AVM_MAIN_MEM_OP_C"; - Base::avm_main_mem_op_d = "AVM_MAIN_MEM_OP_D"; - Base::avm_main_op_err = "AVM_MAIN_OP_ERR"; - Base::avm_main_opcode_val = "AVM_MAIN_OPCODE_VAL"; - Base::avm_main_pc = "AVM_MAIN_PC"; - Base::avm_main_q_kernel_lookup = "AVM_MAIN_Q_KERNEL_LOOKUP"; - Base::avm_main_q_kernel_output_lookup = "AVM_MAIN_Q_KERNEL_OUTPUT_LOOKUP"; - Base::avm_main_r_in_tag = "AVM_MAIN_R_IN_TAG"; - Base::avm_main_rwa = "AVM_MAIN_RWA"; - Base::avm_main_rwb = "AVM_MAIN_RWB"; - Base::avm_main_rwc = "AVM_MAIN_RWC"; - Base::avm_main_rwd = "AVM_MAIN_RWD"; - Base::avm_main_sel_cmov = "AVM_MAIN_SEL_CMOV"; - Base::avm_main_sel_external_call = "AVM_MAIN_SEL_EXTERNAL_CALL"; - Base::avm_main_sel_halt = "AVM_MAIN_SEL_HALT"; - Base::avm_main_sel_internal_call = "AVM_MAIN_SEL_INTERNAL_CALL"; - Base::avm_main_sel_internal_return = "AVM_MAIN_SEL_INTERNAL_RETURN"; - Base::avm_main_sel_jump = "AVM_MAIN_SEL_JUMP"; - Base::avm_main_sel_jumpi = "AVM_MAIN_SEL_JUMPI"; - Base::avm_main_sel_mov = "AVM_MAIN_SEL_MOV"; - Base::avm_main_sel_mov_a = "AVM_MAIN_SEL_MOV_A"; - Base::avm_main_sel_mov_b = "AVM_MAIN_SEL_MOV_B"; - Base::avm_main_sel_op_add = "AVM_MAIN_SEL_OP_ADD"; - Base::avm_main_sel_op_address = "AVM_MAIN_SEL_OP_ADDRESS"; - Base::avm_main_sel_op_and = "AVM_MAIN_SEL_OP_AND"; - Base::avm_main_sel_op_block_number = "AVM_MAIN_SEL_OP_BLOCK_NUMBER"; - Base::avm_main_sel_op_cast = "AVM_MAIN_SEL_OP_CAST"; - Base::avm_main_sel_op_chain_id = "AVM_MAIN_SEL_OP_CHAIN_ID"; - Base::avm_main_sel_op_coinbase = "AVM_MAIN_SEL_OP_COINBASE"; - Base::avm_main_sel_op_dagasleft = "AVM_MAIN_SEL_OP_DAGASLEFT"; - Base::avm_main_sel_op_div = "AVM_MAIN_SEL_OP_DIV"; - Base::avm_main_sel_op_emit_l2_to_l1_msg = "AVM_MAIN_SEL_OP_EMIT_L2_TO_L1_MSG"; - Base::avm_main_sel_op_emit_note_hash = "AVM_MAIN_SEL_OP_EMIT_NOTE_HASH"; - Base::avm_main_sel_op_emit_nullifier = "AVM_MAIN_SEL_OP_EMIT_NULLIFIER"; - Base::avm_main_sel_op_emit_unencrypted_log = "AVM_MAIN_SEL_OP_EMIT_UNENCRYPTED_LOG"; - Base::avm_main_sel_op_eq = "AVM_MAIN_SEL_OP_EQ"; - Base::avm_main_sel_op_fdiv = "AVM_MAIN_SEL_OP_FDIV"; - Base::avm_main_sel_op_fee_per_da_gas = "AVM_MAIN_SEL_OP_FEE_PER_DA_GAS"; - Base::avm_main_sel_op_fee_per_l2_gas = "AVM_MAIN_SEL_OP_FEE_PER_L2_GAS"; - Base::avm_main_sel_op_get_contract_instance = "AVM_MAIN_SEL_OP_GET_CONTRACT_INSTANCE"; - Base::avm_main_sel_op_keccak = "AVM_MAIN_SEL_OP_KECCAK"; - Base::avm_main_sel_op_l1_to_l2_msg_exists = "AVM_MAIN_SEL_OP_L1_TO_L2_MSG_EXISTS"; - Base::avm_main_sel_op_l2gasleft = "AVM_MAIN_SEL_OP_L2GASLEFT"; - Base::avm_main_sel_op_lt = "AVM_MAIN_SEL_OP_LT"; - Base::avm_main_sel_op_lte = "AVM_MAIN_SEL_OP_LTE"; - Base::avm_main_sel_op_mul = "AVM_MAIN_SEL_OP_MUL"; - Base::avm_main_sel_op_not = "AVM_MAIN_SEL_OP_NOT"; - Base::avm_main_sel_op_note_hash_exists = "AVM_MAIN_SEL_OP_NOTE_HASH_EXISTS"; - Base::avm_main_sel_op_nullifier_exists = "AVM_MAIN_SEL_OP_NULLIFIER_EXISTS"; - Base::avm_main_sel_op_or = "AVM_MAIN_SEL_OP_OR"; - Base::avm_main_sel_op_pedersen = "AVM_MAIN_SEL_OP_PEDERSEN"; - Base::avm_main_sel_op_poseidon2 = "AVM_MAIN_SEL_OP_POSEIDON2"; - Base::avm_main_sel_op_radix_le = "AVM_MAIN_SEL_OP_RADIX_LE"; - Base::avm_main_sel_op_sender = "AVM_MAIN_SEL_OP_SENDER"; - Base::avm_main_sel_op_sha256 = "AVM_MAIN_SEL_OP_SHA256"; - Base::avm_main_sel_op_shl = "AVM_MAIN_SEL_OP_SHL"; - Base::avm_main_sel_op_shr = "AVM_MAIN_SEL_OP_SHR"; - Base::avm_main_sel_op_sload = "AVM_MAIN_SEL_OP_SLOAD"; - Base::avm_main_sel_op_sstore = "AVM_MAIN_SEL_OP_SSTORE"; - Base::avm_main_sel_op_storage_address = "AVM_MAIN_SEL_OP_STORAGE_ADDRESS"; - Base::avm_main_sel_op_sub = "AVM_MAIN_SEL_OP_SUB"; - Base::avm_main_sel_op_timestamp = "AVM_MAIN_SEL_OP_TIMESTAMP"; - Base::avm_main_sel_op_transaction_fee = "AVM_MAIN_SEL_OP_TRANSACTION_FEE"; - Base::avm_main_sel_op_version = "AVM_MAIN_SEL_OP_VERSION"; - Base::avm_main_sel_op_xor = "AVM_MAIN_SEL_OP_XOR"; - Base::avm_main_sel_rng_16 = "AVM_MAIN_SEL_RNG_16"; - Base::avm_main_sel_rng_8 = "AVM_MAIN_SEL_RNG_8"; - Base::avm_main_space_id = "AVM_MAIN_SPACE_ID"; - Base::avm_main_table_pow_2 = "AVM_MAIN_TABLE_POW_2"; - Base::avm_main_tag_err = "AVM_MAIN_TAG_ERR"; - Base::avm_main_w_in_tag = "AVM_MAIN_W_IN_TAG"; - Base::avm_mem_addr = "AVM_MEM_ADDR"; - Base::avm_mem_clk = "AVM_MEM_CLK"; - Base::avm_mem_diff_hi = "AVM_MEM_DIFF_HI"; - Base::avm_mem_diff_lo = "AVM_MEM_DIFF_LO"; - Base::avm_mem_diff_mid = "AVM_MEM_DIFF_MID"; - Base::avm_mem_glob_addr = "AVM_MEM_GLOB_ADDR"; - Base::avm_mem_ind_op_a = "AVM_MEM_IND_OP_A"; - Base::avm_mem_ind_op_b = "AVM_MEM_IND_OP_B"; - Base::avm_mem_ind_op_c = "AVM_MEM_IND_OP_C"; - Base::avm_mem_ind_op_d = "AVM_MEM_IND_OP_D"; - Base::avm_mem_last = "AVM_MEM_LAST"; - Base::avm_mem_lastAccess = "AVM_MEM_LASTACCESS"; - Base::avm_mem_mem_sel = "AVM_MEM_MEM_SEL"; - Base::avm_mem_one_min_inv = "AVM_MEM_ONE_MIN_INV"; - Base::avm_mem_op_a = "AVM_MEM_OP_A"; - Base::avm_mem_op_b = "AVM_MEM_OP_B"; - Base::avm_mem_op_c = "AVM_MEM_OP_C"; - Base::avm_mem_op_d = "AVM_MEM_OP_D"; - Base::avm_mem_r_in_tag = "AVM_MEM_R_IN_TAG"; - Base::avm_mem_rng_chk_sel = "AVM_MEM_RNG_CHK_SEL"; - Base::avm_mem_rw = "AVM_MEM_RW"; - Base::avm_mem_sel_cmov = "AVM_MEM_SEL_CMOV"; - Base::avm_mem_sel_mov_a = "AVM_MEM_SEL_MOV_A"; - Base::avm_mem_sel_mov_b = "AVM_MEM_SEL_MOV_B"; - Base::avm_mem_skip_check_tag = "AVM_MEM_SKIP_CHECK_TAG"; - Base::avm_mem_space_id = "AVM_MEM_SPACE_ID"; - Base::avm_mem_tag = "AVM_MEM_TAG"; - Base::avm_mem_tag_err = "AVM_MEM_TAG_ERR"; - Base::avm_mem_tsp = "AVM_MEM_TSP"; - Base::avm_mem_val = "AVM_MEM_VAL"; - Base::avm_mem_w_in_tag = "AVM_MEM_W_IN_TAG"; - Base::avm_pedersen_clk = "AVM_PEDERSEN_CLK"; - Base::avm_pedersen_input = "AVM_PEDERSEN_INPUT"; - Base::avm_pedersen_output = "AVM_PEDERSEN_OUTPUT"; - Base::avm_pedersen_pedersen_sel = "AVM_PEDERSEN_PEDERSEN_SEL"; - Base::avm_poseidon2_clk = "AVM_POSEIDON2_CLK"; - Base::avm_poseidon2_input = "AVM_POSEIDON2_INPUT"; - Base::avm_poseidon2_output = "AVM_POSEIDON2_OUTPUT"; - Base::avm_poseidon2_poseidon_perm_sel = "AVM_POSEIDON2_POSEIDON_PERM_SEL"; - Base::avm_sha256_clk = "AVM_SHA256_CLK"; - Base::avm_sha256_input = "AVM_SHA256_INPUT"; - Base::avm_sha256_output = "AVM_SHA256_OUTPUT"; - Base::avm_sha256_sha256_compression_sel = "AVM_SHA256_SHA256_COMPRESSION_SEL"; - Base::avm_sha256_state = "AVM_SHA256_STATE"; + Base::main_clk = "MAIN_CLK"; + Base::main_sel_first = "MAIN_SEL_FIRST"; + Base::alu_a_hi = "ALU_A_HI"; + Base::alu_a_lo = "ALU_A_LO"; + Base::alu_b_hi = "ALU_B_HI"; + Base::alu_b_lo = "ALU_B_LO"; + Base::alu_borrow = "ALU_BORROW"; + Base::alu_cf = "ALU_CF"; + Base::alu_clk = "ALU_CLK"; + Base::alu_cmp_rng_ctr = "ALU_CMP_RNG_CTR"; + Base::alu_div_u16_r0 = "ALU_DIV_U16_R0"; + Base::alu_div_u16_r1 = "ALU_DIV_U16_R1"; + Base::alu_div_u16_r2 = "ALU_DIV_U16_R2"; + Base::alu_div_u16_r3 = "ALU_DIV_U16_R3"; + Base::alu_div_u16_r4 = "ALU_DIV_U16_R4"; + Base::alu_div_u16_r5 = "ALU_DIV_U16_R5"; + Base::alu_div_u16_r6 = "ALU_DIV_U16_R6"; + Base::alu_div_u16_r7 = "ALU_DIV_U16_R7"; + Base::alu_divisor_hi = "ALU_DIVISOR_HI"; + Base::alu_divisor_lo = "ALU_DIVISOR_LO"; + Base::alu_ff_tag = "ALU_FF_TAG"; + Base::alu_ia = "ALU_IA"; + Base::alu_ib = "ALU_IB"; + Base::alu_ic = "ALU_IC"; + Base::alu_in_tag = "ALU_IN_TAG"; + Base::alu_op_add = "ALU_OP_ADD"; + Base::alu_op_cast = "ALU_OP_CAST"; + Base::alu_op_cast_prev = "ALU_OP_CAST_PREV"; + Base::alu_op_div = "ALU_OP_DIV"; + Base::alu_op_div_a_lt_b = "ALU_OP_DIV_A_LT_B"; + Base::alu_op_div_std = "ALU_OP_DIV_STD"; + Base::alu_op_eq = "ALU_OP_EQ"; + Base::alu_op_eq_diff_inv = "ALU_OP_EQ_DIFF_INV"; + Base::alu_op_lt = "ALU_OP_LT"; + Base::alu_op_lte = "ALU_OP_LTE"; + Base::alu_op_mul = "ALU_OP_MUL"; + Base::alu_op_not = "ALU_OP_NOT"; + Base::alu_op_shl = "ALU_OP_SHL"; + Base::alu_op_shr = "ALU_OP_SHR"; + Base::alu_op_sub = "ALU_OP_SUB"; + Base::alu_p_a_borrow = "ALU_P_A_BORROW"; + Base::alu_p_b_borrow = "ALU_P_B_BORROW"; + Base::alu_p_sub_a_hi = "ALU_P_SUB_A_HI"; + Base::alu_p_sub_a_lo = "ALU_P_SUB_A_LO"; + Base::alu_p_sub_b_hi = "ALU_P_SUB_B_HI"; + Base::alu_p_sub_b_lo = "ALU_P_SUB_B_LO"; + Base::alu_partial_prod_hi = "ALU_PARTIAL_PROD_HI"; + Base::alu_partial_prod_lo = "ALU_PARTIAL_PROD_LO"; + Base::alu_quotient_hi = "ALU_QUOTIENT_HI"; + Base::alu_quotient_lo = "ALU_QUOTIENT_LO"; + Base::alu_remainder = "ALU_REMAINDER"; + Base::alu_res_hi = "ALU_RES_HI"; + Base::alu_res_lo = "ALU_RES_LO"; + Base::alu_sel_alu = "ALU_SEL_ALU"; + Base::alu_sel_cmp = "ALU_SEL_CMP"; + Base::alu_sel_div_rng_chk = "ALU_SEL_DIV_RNG_CHK"; + Base::alu_sel_rng_chk = "ALU_SEL_RNG_CHK"; + Base::alu_sel_rng_chk_lookup = "ALU_SEL_RNG_CHK_LOOKUP"; + Base::alu_sel_shift_which = "ALU_SEL_SHIFT_WHICH"; + Base::alu_shift_lt_bit_len = "ALU_SHIFT_LT_BIT_LEN"; + Base::alu_t_sub_s_bits = "ALU_T_SUB_S_BITS"; + Base::alu_two_pow_s = "ALU_TWO_POW_S"; + Base::alu_two_pow_t_sub_s = "ALU_TWO_POW_T_SUB_S"; + Base::alu_u128_tag = "ALU_U128_TAG"; + Base::alu_u16_r0 = "ALU_U16_R0"; + Base::alu_u16_r1 = "ALU_U16_R1"; + Base::alu_u16_r10 = "ALU_U16_R10"; + Base::alu_u16_r11 = "ALU_U16_R11"; + Base::alu_u16_r12 = "ALU_U16_R12"; + Base::alu_u16_r13 = "ALU_U16_R13"; + Base::alu_u16_r14 = "ALU_U16_R14"; + Base::alu_u16_r2 = "ALU_U16_R2"; + Base::alu_u16_r3 = "ALU_U16_R3"; + Base::alu_u16_r4 = "ALU_U16_R4"; + Base::alu_u16_r5 = "ALU_U16_R5"; + Base::alu_u16_r6 = "ALU_U16_R6"; + Base::alu_u16_r7 = "ALU_U16_R7"; + Base::alu_u16_r8 = "ALU_U16_R8"; + Base::alu_u16_r9 = "ALU_U16_R9"; + Base::alu_u16_tag = "ALU_U16_TAG"; + Base::alu_u32_tag = "ALU_U32_TAG"; + Base::alu_u64_tag = "ALU_U64_TAG"; + Base::alu_u8_r0 = "ALU_U8_R0"; + Base::alu_u8_r1 = "ALU_U8_R1"; + Base::alu_u8_tag = "ALU_U8_TAG"; + Base::binary_acc_ia = "BINARY_ACC_IA"; + Base::binary_acc_ib = "BINARY_ACC_IB"; + Base::binary_acc_ic = "BINARY_ACC_IC"; + Base::binary_clk = "BINARY_CLK"; + Base::binary_ia_bytes = "BINARY_IA_BYTES"; + Base::binary_ib_bytes = "BINARY_IB_BYTES"; + Base::binary_ic_bytes = "BINARY_IC_BYTES"; + Base::binary_in_tag = "BINARY_IN_TAG"; + Base::binary_mem_tag_ctr = "BINARY_MEM_TAG_CTR"; + Base::binary_mem_tag_ctr_inv = "BINARY_MEM_TAG_CTR_INV"; + Base::binary_op_id = "BINARY_OP_ID"; + Base::binary_sel_bin = "BINARY_SEL_BIN"; + Base::binary_start = "BINARY_START"; + Base::byte_lookup_sel_bin = "BYTE_LOOKUP_SEL_BIN"; + Base::byte_lookup_table_byte_lengths = "BYTE_LOOKUP_TABLE_BYTE_LENGTHS"; + Base::byte_lookup_table_in_tags = "BYTE_LOOKUP_TABLE_IN_TAGS"; + Base::byte_lookup_table_input_a = "BYTE_LOOKUP_TABLE_INPUT_A"; + Base::byte_lookup_table_input_b = "BYTE_LOOKUP_TABLE_INPUT_B"; + Base::byte_lookup_table_op_id = "BYTE_LOOKUP_TABLE_OP_ID"; + Base::byte_lookup_table_output = "BYTE_LOOKUP_TABLE_OUTPUT"; + Base::conversion_clk = "CONVERSION_CLK"; + Base::conversion_input = "CONVERSION_INPUT"; + Base::conversion_num_limbs = "CONVERSION_NUM_LIMBS"; + Base::conversion_radix = "CONVERSION_RADIX"; + Base::conversion_sel_to_radix_le = "CONVERSION_SEL_TO_RADIX_LE"; + Base::gas_da_gas_fixed_table = "GAS_DA_GAS_FIXED_TABLE"; + Base::gas_l2_gas_fixed_table = "GAS_L2_GAS_FIXED_TABLE"; + Base::gas_sel_gas_cost = "GAS_SEL_GAS_COST"; + Base::keccakf1600_clk = "KECCAKF1600_CLK"; + Base::keccakf1600_input = "KECCAKF1600_INPUT"; + Base::keccakf1600_output = "KECCAKF1600_OUTPUT"; + Base::keccakf1600_sel_keccakf1600 = "KECCAKF1600_SEL_KECCAKF1600"; + Base::kernel_emit_l2_to_l1_msg_write_offset = "KERNEL_EMIT_L2_TO_L1_MSG_WRITE_OFFSET"; + Base::kernel_emit_note_hash_write_offset = "KERNEL_EMIT_NOTE_HASH_WRITE_OFFSET"; + Base::kernel_emit_nullifier_write_offset = "KERNEL_EMIT_NULLIFIER_WRITE_OFFSET"; + Base::kernel_emit_unencrypted_log_write_offset = "KERNEL_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET"; + Base::kernel_kernel_in_offset = "KERNEL_KERNEL_IN_OFFSET"; + Base::kernel_kernel_inputs = "KERNEL_KERNEL_INPUTS"; + Base::kernel_kernel_metadata_out = "KERNEL_KERNEL_METADATA_OUT"; + Base::kernel_kernel_out_offset = "KERNEL_KERNEL_OUT_OFFSET"; + Base::kernel_kernel_side_effect_out = "KERNEL_KERNEL_SIDE_EFFECT_OUT"; + Base::kernel_kernel_value_out = "KERNEL_KERNEL_VALUE_OUT"; + Base::kernel_l1_to_l2_msg_exists_write_offset = "KERNEL_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET"; + Base::kernel_note_hash_exist_write_offset = "KERNEL_NOTE_HASH_EXIST_WRITE_OFFSET"; + Base::kernel_nullifier_exists_write_offset = "KERNEL_NULLIFIER_EXISTS_WRITE_OFFSET"; + Base::kernel_nullifier_non_exists_write_offset = "KERNEL_NULLIFIER_NON_EXISTS_WRITE_OFFSET"; + Base::kernel_q_public_input_kernel_add_to_table = "KERNEL_Q_PUBLIC_INPUT_KERNEL_ADD_TO_TABLE"; + Base::kernel_q_public_input_kernel_out_add_to_table = "KERNEL_Q_PUBLIC_INPUT_KERNEL_OUT_ADD_TO_TABLE"; + Base::kernel_side_effect_counter = "KERNEL_SIDE_EFFECT_COUNTER"; + Base::kernel_sload_write_offset = "KERNEL_SLOAD_WRITE_OFFSET"; + Base::kernel_sstore_write_offset = "KERNEL_SSTORE_WRITE_OFFSET"; + Base::main_abs_da_rem_gas_hi = "MAIN_ABS_DA_REM_GAS_HI"; + Base::main_abs_da_rem_gas_lo = "MAIN_ABS_DA_REM_GAS_LO"; + Base::main_abs_l2_rem_gas_hi = "MAIN_ABS_L2_REM_GAS_HI"; + Base::main_abs_l2_rem_gas_lo = "MAIN_ABS_L2_REM_GAS_LO"; + Base::main_alu_in_tag = "MAIN_ALU_IN_TAG"; + Base::main_bin_op_id = "MAIN_BIN_OP_ID"; + Base::main_call_ptr = "MAIN_CALL_PTR"; + Base::main_da_gas_op_cost = "MAIN_DA_GAS_OP_COST"; + Base::main_da_gas_remaining = "MAIN_DA_GAS_REMAINING"; + Base::main_da_out_of_gas = "MAIN_DA_OUT_OF_GAS"; + Base::main_ia = "MAIN_IA"; + Base::main_ib = "MAIN_IB"; + Base::main_ic = "MAIN_IC"; + Base::main_id = "MAIN_ID"; + Base::main_id_zero = "MAIN_ID_ZERO"; + Base::main_ind_addr_a = "MAIN_IND_ADDR_A"; + Base::main_ind_addr_b = "MAIN_IND_ADDR_B"; + Base::main_ind_addr_c = "MAIN_IND_ADDR_C"; + Base::main_ind_addr_d = "MAIN_IND_ADDR_D"; + Base::main_internal_return_ptr = "MAIN_INTERNAL_RETURN_PTR"; + Base::main_inv = "MAIN_INV"; + Base::main_l2_gas_op_cost = "MAIN_L2_GAS_OP_COST"; + Base::main_l2_gas_remaining = "MAIN_L2_GAS_REMAINING"; + Base::main_l2_out_of_gas = "MAIN_L2_OUT_OF_GAS"; + Base::main_mem_addr_a = "MAIN_MEM_ADDR_A"; + Base::main_mem_addr_b = "MAIN_MEM_ADDR_B"; + Base::main_mem_addr_c = "MAIN_MEM_ADDR_C"; + Base::main_mem_addr_d = "MAIN_MEM_ADDR_D"; + Base::main_op_err = "MAIN_OP_ERR"; + Base::main_opcode_val = "MAIN_OPCODE_VAL"; + Base::main_pc = "MAIN_PC"; + Base::main_r_in_tag = "MAIN_R_IN_TAG"; + Base::main_rwa = "MAIN_RWA"; + Base::main_rwb = "MAIN_RWB"; + Base::main_rwc = "MAIN_RWC"; + Base::main_rwd = "MAIN_RWD"; + Base::main_sel_alu = "MAIN_SEL_ALU"; + Base::main_sel_bin = "MAIN_SEL_BIN"; + Base::main_sel_gas_accounting_active = "MAIN_SEL_GAS_ACCOUNTING_ACTIVE"; + Base::main_sel_last = "MAIN_SEL_LAST"; + Base::main_sel_mem_op_a = "MAIN_SEL_MEM_OP_A"; + Base::main_sel_mem_op_activate_gas = "MAIN_SEL_MEM_OP_ACTIVATE_GAS"; + Base::main_sel_mem_op_b = "MAIN_SEL_MEM_OP_B"; + Base::main_sel_mem_op_c = "MAIN_SEL_MEM_OP_C"; + Base::main_sel_mem_op_d = "MAIN_SEL_MEM_OP_D"; + Base::main_sel_mov_ia_to_ic = "MAIN_SEL_MOV_IA_TO_IC"; + Base::main_sel_mov_ib_to_ic = "MAIN_SEL_MOV_IB_TO_IC"; + Base::main_sel_op_add = "MAIN_SEL_OP_ADD"; + Base::main_sel_op_address = "MAIN_SEL_OP_ADDRESS"; + Base::main_sel_op_and = "MAIN_SEL_OP_AND"; + Base::main_sel_op_block_number = "MAIN_SEL_OP_BLOCK_NUMBER"; + Base::main_sel_op_cast = "MAIN_SEL_OP_CAST"; + Base::main_sel_op_chain_id = "MAIN_SEL_OP_CHAIN_ID"; + Base::main_sel_op_cmov = "MAIN_SEL_OP_CMOV"; + Base::main_sel_op_coinbase = "MAIN_SEL_OP_COINBASE"; + Base::main_sel_op_dagasleft = "MAIN_SEL_OP_DAGASLEFT"; + Base::main_sel_op_div = "MAIN_SEL_OP_DIV"; + Base::main_sel_op_emit_l2_to_l1_msg = "MAIN_SEL_OP_EMIT_L2_TO_L1_MSG"; + Base::main_sel_op_emit_note_hash = "MAIN_SEL_OP_EMIT_NOTE_HASH"; + Base::main_sel_op_emit_nullifier = "MAIN_SEL_OP_EMIT_NULLIFIER"; + Base::main_sel_op_emit_unencrypted_log = "MAIN_SEL_OP_EMIT_UNENCRYPTED_LOG"; + Base::main_sel_op_eq = "MAIN_SEL_OP_EQ"; + Base::main_sel_op_external_call = "MAIN_SEL_OP_EXTERNAL_CALL"; + Base::main_sel_op_fdiv = "MAIN_SEL_OP_FDIV"; + Base::main_sel_op_fee_per_da_gas = "MAIN_SEL_OP_FEE_PER_DA_GAS"; + Base::main_sel_op_fee_per_l2_gas = "MAIN_SEL_OP_FEE_PER_L2_GAS"; + Base::main_sel_op_get_contract_instance = "MAIN_SEL_OP_GET_CONTRACT_INSTANCE"; + Base::main_sel_op_halt = "MAIN_SEL_OP_HALT"; + Base::main_sel_op_internal_call = "MAIN_SEL_OP_INTERNAL_CALL"; + Base::main_sel_op_internal_return = "MAIN_SEL_OP_INTERNAL_RETURN"; + Base::main_sel_op_jump = "MAIN_SEL_OP_JUMP"; + Base::main_sel_op_jumpi = "MAIN_SEL_OP_JUMPI"; + Base::main_sel_op_keccak = "MAIN_SEL_OP_KECCAK"; + Base::main_sel_op_l1_to_l2_msg_exists = "MAIN_SEL_OP_L1_TO_L2_MSG_EXISTS"; + Base::main_sel_op_l2gasleft = "MAIN_SEL_OP_L2GASLEFT"; + Base::main_sel_op_lt = "MAIN_SEL_OP_LT"; + Base::main_sel_op_lte = "MAIN_SEL_OP_LTE"; + Base::main_sel_op_mov = "MAIN_SEL_OP_MOV"; + Base::main_sel_op_mul = "MAIN_SEL_OP_MUL"; + Base::main_sel_op_not = "MAIN_SEL_OP_NOT"; + Base::main_sel_op_note_hash_exists = "MAIN_SEL_OP_NOTE_HASH_EXISTS"; + Base::main_sel_op_nullifier_exists = "MAIN_SEL_OP_NULLIFIER_EXISTS"; + Base::main_sel_op_or = "MAIN_SEL_OP_OR"; + Base::main_sel_op_pedersen = "MAIN_SEL_OP_PEDERSEN"; + Base::main_sel_op_poseidon2 = "MAIN_SEL_OP_POSEIDON2"; + Base::main_sel_op_radix_le = "MAIN_SEL_OP_RADIX_LE"; + Base::main_sel_op_sender = "MAIN_SEL_OP_SENDER"; + Base::main_sel_op_sha256 = "MAIN_SEL_OP_SHA256"; + Base::main_sel_op_shl = "MAIN_SEL_OP_SHL"; + Base::main_sel_op_shr = "MAIN_SEL_OP_SHR"; + Base::main_sel_op_sload = "MAIN_SEL_OP_SLOAD"; + Base::main_sel_op_sstore = "MAIN_SEL_OP_SSTORE"; + Base::main_sel_op_storage_address = "MAIN_SEL_OP_STORAGE_ADDRESS"; + Base::main_sel_op_sub = "MAIN_SEL_OP_SUB"; + Base::main_sel_op_timestamp = "MAIN_SEL_OP_TIMESTAMP"; + Base::main_sel_op_transaction_fee = "MAIN_SEL_OP_TRANSACTION_FEE"; + Base::main_sel_op_version = "MAIN_SEL_OP_VERSION"; + Base::main_sel_op_xor = "MAIN_SEL_OP_XOR"; + Base::main_sel_q_kernel_lookup = "MAIN_SEL_Q_KERNEL_LOOKUP"; + Base::main_sel_q_kernel_output_lookup = "MAIN_SEL_Q_KERNEL_OUTPUT_LOOKUP"; + Base::main_sel_resolve_ind_addr_a = "MAIN_SEL_RESOLVE_IND_ADDR_A"; + Base::main_sel_resolve_ind_addr_b = "MAIN_SEL_RESOLVE_IND_ADDR_B"; + Base::main_sel_resolve_ind_addr_c = "MAIN_SEL_RESOLVE_IND_ADDR_C"; + Base::main_sel_resolve_ind_addr_d = "MAIN_SEL_RESOLVE_IND_ADDR_D"; + Base::main_sel_rng_16 = "MAIN_SEL_RNG_16"; + Base::main_sel_rng_8 = "MAIN_SEL_RNG_8"; + Base::main_space_id = "MAIN_SPACE_ID"; + Base::main_table_pow_2 = "MAIN_TABLE_POW_2"; + Base::main_tag_err = "MAIN_TAG_ERR"; + Base::main_w_in_tag = "MAIN_W_IN_TAG"; + Base::mem_addr = "MEM_ADDR"; + Base::mem_clk = "MEM_CLK"; + Base::mem_diff_hi = "MEM_DIFF_HI"; + Base::mem_diff_lo = "MEM_DIFF_LO"; + Base::mem_diff_mid = "MEM_DIFF_MID"; + Base::mem_glob_addr = "MEM_GLOB_ADDR"; + Base::mem_last = "MEM_LAST"; + Base::mem_lastAccess = "MEM_LASTACCESS"; + Base::mem_one_min_inv = "MEM_ONE_MIN_INV"; + Base::mem_r_in_tag = "MEM_R_IN_TAG"; + Base::mem_rw = "MEM_RW"; + Base::mem_sel_mem = "MEM_SEL_MEM"; + Base::mem_sel_mov_ia_to_ic = "MEM_SEL_MOV_IA_TO_IC"; + Base::mem_sel_mov_ib_to_ic = "MEM_SEL_MOV_IB_TO_IC"; + Base::mem_sel_op_a = "MEM_SEL_OP_A"; + Base::mem_sel_op_b = "MEM_SEL_OP_B"; + Base::mem_sel_op_c = "MEM_SEL_OP_C"; + Base::mem_sel_op_cmov = "MEM_SEL_OP_CMOV"; + Base::mem_sel_op_d = "MEM_SEL_OP_D"; + Base::mem_sel_resolve_ind_addr_a = "MEM_SEL_RESOLVE_IND_ADDR_A"; + Base::mem_sel_resolve_ind_addr_b = "MEM_SEL_RESOLVE_IND_ADDR_B"; + Base::mem_sel_resolve_ind_addr_c = "MEM_SEL_RESOLVE_IND_ADDR_C"; + Base::mem_sel_resolve_ind_addr_d = "MEM_SEL_RESOLVE_IND_ADDR_D"; + Base::mem_sel_rng_chk = "MEM_SEL_RNG_CHK"; + Base::mem_skip_check_tag = "MEM_SKIP_CHECK_TAG"; + Base::mem_space_id = "MEM_SPACE_ID"; + Base::mem_tag = "MEM_TAG"; + Base::mem_tag_err = "MEM_TAG_ERR"; + Base::mem_tsp = "MEM_TSP"; + Base::mem_val = "MEM_VAL"; + Base::mem_w_in_tag = "MEM_W_IN_TAG"; + Base::pedersen_clk = "PEDERSEN_CLK"; + Base::pedersen_input = "PEDERSEN_INPUT"; + Base::pedersen_output = "PEDERSEN_OUTPUT"; + Base::pedersen_sel_pedersen = "PEDERSEN_SEL_PEDERSEN"; + Base::poseidon2_clk = "POSEIDON2_CLK"; + Base::poseidon2_input = "POSEIDON2_INPUT"; + Base::poseidon2_output = "POSEIDON2_OUTPUT"; + Base::poseidon2_sel_poseidon_perm = "POSEIDON2_SEL_POSEIDON_PERM"; + Base::sha256_clk = "SHA256_CLK"; + Base::sha256_input = "SHA256_INPUT"; + Base::sha256_output = "SHA256_OUTPUT"; + Base::sha256_sel_sha256_compression = "SHA256_SEL_SHA256_COMPRESSION"; + Base::sha256_state = "SHA256_STATE"; Base::perm_main_alu = "PERM_MAIN_ALU"; Base::perm_main_bin = "PERM_MAIN_BIN"; Base::perm_main_conv = "PERM_MAIN_CONV"; @@ -3046,10 +3045,10 @@ class AvmFlavor { Base::perm_main_mem_b = "PERM_MAIN_MEM_B"; Base::perm_main_mem_c = "PERM_MAIN_MEM_C"; Base::perm_main_mem_d = "PERM_MAIN_MEM_D"; - Base::perm_main_mem_ind_a = "PERM_MAIN_MEM_IND_A"; - Base::perm_main_mem_ind_b = "PERM_MAIN_MEM_IND_B"; - Base::perm_main_mem_ind_c = "PERM_MAIN_MEM_IND_C"; - Base::perm_main_mem_ind_d = "PERM_MAIN_MEM_IND_D"; + Base::perm_main_mem_ind_addr_a = "PERM_MAIN_MEM_IND_ADDR_A"; + Base::perm_main_mem_ind_addr_b = "PERM_MAIN_MEM_IND_ADDR_B"; + Base::perm_main_mem_ind_addr_c = "PERM_MAIN_MEM_IND_ADDR_C"; + Base::perm_main_mem_ind_addr_d = "PERM_MAIN_MEM_IND_ADDR_D"; Base::lookup_byte_lengths = "LOOKUP_BYTE_LENGTHS"; Base::lookup_byte_operations = "LOOKUP_BYTE_OPERATIONS"; Base::lookup_opcode_gas = "LOOKUP_OPCODE_GAS"; @@ -3142,8 +3141,8 @@ class AvmFlavor { public: VerifierCommitments(const std::shared_ptr& verification_key) { - avm_main_clk = verification_key->avm_main_clk; - avm_main_first = verification_key->avm_main_first; + main_clk = verification_key->main_clk; + main_sel_first = verification_key->main_sel_first; } }; @@ -3151,294 +3150,294 @@ class AvmFlavor { public: uint32_t circuit_size; - Commitment avm_alu_a_hi; - Commitment avm_alu_a_lo; - Commitment avm_alu_alu_sel; - Commitment avm_alu_b_hi; - Commitment avm_alu_b_lo; - Commitment avm_alu_borrow; - Commitment avm_alu_cf; - Commitment avm_alu_clk; - Commitment avm_alu_cmp_rng_ctr; - Commitment avm_alu_cmp_sel; - Commitment avm_alu_div_rng_chk_selector; - Commitment avm_alu_div_u16_r0; - Commitment avm_alu_div_u16_r1; - Commitment avm_alu_div_u16_r2; - Commitment avm_alu_div_u16_r3; - Commitment avm_alu_div_u16_r4; - Commitment avm_alu_div_u16_r5; - Commitment avm_alu_div_u16_r6; - Commitment avm_alu_div_u16_r7; - Commitment avm_alu_divisor_hi; - Commitment avm_alu_divisor_lo; - Commitment avm_alu_ff_tag; - Commitment avm_alu_ia; - Commitment avm_alu_ib; - Commitment avm_alu_ic; - Commitment avm_alu_in_tag; - Commitment avm_alu_op_add; - Commitment avm_alu_op_cast; - Commitment avm_alu_op_cast_prev; - Commitment avm_alu_op_div; - Commitment avm_alu_op_div_a_lt_b; - Commitment avm_alu_op_div_std; - Commitment avm_alu_op_eq; - Commitment avm_alu_op_eq_diff_inv; - Commitment avm_alu_op_lt; - Commitment avm_alu_op_lte; - Commitment avm_alu_op_mul; - Commitment avm_alu_op_not; - Commitment avm_alu_op_shl; - Commitment avm_alu_op_shr; - Commitment avm_alu_op_sub; - Commitment avm_alu_p_a_borrow; - Commitment avm_alu_p_b_borrow; - Commitment avm_alu_p_sub_a_hi; - Commitment avm_alu_p_sub_a_lo; - Commitment avm_alu_p_sub_b_hi; - Commitment avm_alu_p_sub_b_lo; - Commitment avm_alu_partial_prod_hi; - Commitment avm_alu_partial_prod_lo; - Commitment avm_alu_quotient_hi; - Commitment avm_alu_quotient_lo; - Commitment avm_alu_remainder; - Commitment avm_alu_res_hi; - Commitment avm_alu_res_lo; - Commitment avm_alu_rng_chk_lookup_selector; - Commitment avm_alu_rng_chk_sel; - Commitment avm_alu_shift_lt_bit_len; - Commitment avm_alu_shift_sel; - Commitment avm_alu_t_sub_s_bits; - Commitment avm_alu_two_pow_s; - Commitment avm_alu_two_pow_t_sub_s; - Commitment avm_alu_u128_tag; - Commitment avm_alu_u16_r0; - Commitment avm_alu_u16_r1; - Commitment avm_alu_u16_r10; - Commitment avm_alu_u16_r11; - Commitment avm_alu_u16_r12; - Commitment avm_alu_u16_r13; - Commitment avm_alu_u16_r14; - Commitment avm_alu_u16_r2; - Commitment avm_alu_u16_r3; - Commitment avm_alu_u16_r4; - Commitment avm_alu_u16_r5; - Commitment avm_alu_u16_r6; - Commitment avm_alu_u16_r7; - Commitment avm_alu_u16_r8; - Commitment avm_alu_u16_r9; - Commitment avm_alu_u16_tag; - Commitment avm_alu_u32_tag; - Commitment avm_alu_u64_tag; - Commitment avm_alu_u8_r0; - Commitment avm_alu_u8_r1; - Commitment avm_alu_u8_tag; - Commitment avm_binary_acc_ia; - Commitment avm_binary_acc_ib; - Commitment avm_binary_acc_ic; - Commitment avm_binary_bin_sel; - Commitment avm_binary_clk; - Commitment avm_binary_ia_bytes; - Commitment avm_binary_ib_bytes; - Commitment avm_binary_ic_bytes; - Commitment avm_binary_in_tag; - Commitment avm_binary_mem_tag_ctr; - Commitment avm_binary_mem_tag_ctr_inv; - Commitment avm_binary_op_id; - Commitment avm_binary_start; - Commitment avm_byte_lookup_bin_sel; - Commitment avm_byte_lookup_table_byte_lengths; - Commitment avm_byte_lookup_table_in_tags; - Commitment avm_byte_lookup_table_input_a; - Commitment avm_byte_lookup_table_input_b; - Commitment avm_byte_lookup_table_op_id; - Commitment avm_byte_lookup_table_output; - Commitment avm_conversion_clk; - Commitment avm_conversion_input; - Commitment avm_conversion_num_limbs; - Commitment avm_conversion_radix; - Commitment avm_conversion_to_radix_le_sel; - Commitment avm_gas_da_gas_fixed_table; - Commitment avm_gas_gas_cost_sel; - Commitment avm_gas_l2_gas_fixed_table; - Commitment avm_keccakf1600_clk; - Commitment avm_keccakf1600_input; - Commitment avm_keccakf1600_keccakf1600_sel; - Commitment avm_keccakf1600_output; - Commitment avm_kernel_emit_l2_to_l1_msg_write_offset; - Commitment avm_kernel_emit_note_hash_write_offset; - Commitment avm_kernel_emit_nullifier_write_offset; - Commitment avm_kernel_emit_unencrypted_log_write_offset; - Commitment avm_kernel_kernel_in_offset; - Commitment avm_kernel_kernel_inputs; - Commitment avm_kernel_kernel_metadata_out; - Commitment avm_kernel_kernel_out_offset; - Commitment avm_kernel_kernel_side_effect_out; - Commitment avm_kernel_kernel_value_out; - Commitment avm_kernel_l1_to_l2_msg_exists_write_offset; - Commitment avm_kernel_note_hash_exist_write_offset; - Commitment avm_kernel_nullifier_exists_write_offset; - Commitment avm_kernel_nullifier_non_exists_write_offset; - Commitment avm_kernel_q_public_input_kernel_add_to_table; - Commitment avm_kernel_q_public_input_kernel_out_add_to_table; - Commitment avm_kernel_side_effect_counter; - Commitment avm_kernel_sload_write_offset; - Commitment avm_kernel_sstore_write_offset; - Commitment avm_main_abs_da_rem_gas_hi; - Commitment avm_main_abs_da_rem_gas_lo; - Commitment avm_main_abs_l2_rem_gas_hi; - Commitment avm_main_abs_l2_rem_gas_lo; - Commitment avm_main_alu_in_tag; - Commitment avm_main_alu_sel; - Commitment avm_main_bin_op_id; - Commitment avm_main_bin_sel; - Commitment avm_main_call_ptr; - Commitment avm_main_da_gas_op; - Commitment avm_main_da_gas_remaining; - Commitment avm_main_da_out_of_gas; - Commitment avm_main_gas_cost_active; - Commitment avm_main_ia; - Commitment avm_main_ib; - Commitment avm_main_ic; - Commitment avm_main_id; - Commitment avm_main_id_zero; - Commitment avm_main_ind_a; - Commitment avm_main_ind_b; - Commitment avm_main_ind_c; - Commitment avm_main_ind_d; - Commitment avm_main_ind_op_a; - Commitment avm_main_ind_op_b; - Commitment avm_main_ind_op_c; - Commitment avm_main_ind_op_d; - Commitment avm_main_internal_return_ptr; - Commitment avm_main_inv; - Commitment avm_main_l2_gas_op; - Commitment avm_main_l2_gas_remaining; - Commitment avm_main_l2_out_of_gas; - Commitment avm_main_last; - Commitment avm_main_mem_idx_a; - Commitment avm_main_mem_idx_b; - Commitment avm_main_mem_idx_c; - Commitment avm_main_mem_idx_d; - Commitment avm_main_mem_op_a; - Commitment avm_main_mem_op_activate_gas; - Commitment avm_main_mem_op_b; - Commitment avm_main_mem_op_c; - Commitment avm_main_mem_op_d; - Commitment avm_main_op_err; - Commitment avm_main_opcode_val; - Commitment avm_main_pc; - Commitment avm_main_q_kernel_lookup; - Commitment avm_main_q_kernel_output_lookup; - Commitment avm_main_r_in_tag; - Commitment avm_main_rwa; - Commitment avm_main_rwb; - Commitment avm_main_rwc; - Commitment avm_main_rwd; - Commitment avm_main_sel_cmov; - Commitment avm_main_sel_external_call; - Commitment avm_main_sel_halt; - Commitment avm_main_sel_internal_call; - Commitment avm_main_sel_internal_return; - Commitment avm_main_sel_jump; - Commitment avm_main_sel_jumpi; - Commitment avm_main_sel_mov; - Commitment avm_main_sel_mov_a; - Commitment avm_main_sel_mov_b; - Commitment avm_main_sel_op_add; - Commitment avm_main_sel_op_address; - Commitment avm_main_sel_op_and; - Commitment avm_main_sel_op_block_number; - Commitment avm_main_sel_op_cast; - Commitment avm_main_sel_op_chain_id; - Commitment avm_main_sel_op_coinbase; - Commitment avm_main_sel_op_dagasleft; - Commitment avm_main_sel_op_div; - Commitment avm_main_sel_op_emit_l2_to_l1_msg; - Commitment avm_main_sel_op_emit_note_hash; - Commitment avm_main_sel_op_emit_nullifier; - Commitment avm_main_sel_op_emit_unencrypted_log; - Commitment avm_main_sel_op_eq; - Commitment avm_main_sel_op_fdiv; - Commitment avm_main_sel_op_fee_per_da_gas; - Commitment avm_main_sel_op_fee_per_l2_gas; - Commitment avm_main_sel_op_get_contract_instance; - Commitment avm_main_sel_op_keccak; - Commitment avm_main_sel_op_l1_to_l2_msg_exists; - Commitment avm_main_sel_op_l2gasleft; - Commitment avm_main_sel_op_lt; - Commitment avm_main_sel_op_lte; - Commitment avm_main_sel_op_mul; - Commitment avm_main_sel_op_not; - Commitment avm_main_sel_op_note_hash_exists; - Commitment avm_main_sel_op_nullifier_exists; - Commitment avm_main_sel_op_or; - Commitment avm_main_sel_op_pedersen; - Commitment avm_main_sel_op_poseidon2; - Commitment avm_main_sel_op_radix_le; - Commitment avm_main_sel_op_sender; - Commitment avm_main_sel_op_sha256; - Commitment avm_main_sel_op_shl; - Commitment avm_main_sel_op_shr; - Commitment avm_main_sel_op_sload; - Commitment avm_main_sel_op_sstore; - Commitment avm_main_sel_op_storage_address; - Commitment avm_main_sel_op_sub; - Commitment avm_main_sel_op_timestamp; - Commitment avm_main_sel_op_transaction_fee; - Commitment avm_main_sel_op_version; - Commitment avm_main_sel_op_xor; - Commitment avm_main_sel_rng_16; - Commitment avm_main_sel_rng_8; - Commitment avm_main_space_id; - Commitment avm_main_table_pow_2; - Commitment avm_main_tag_err; - Commitment avm_main_w_in_tag; - Commitment avm_mem_addr; - Commitment avm_mem_clk; - Commitment avm_mem_diff_hi; - Commitment avm_mem_diff_lo; - Commitment avm_mem_diff_mid; - Commitment avm_mem_glob_addr; - Commitment avm_mem_ind_op_a; - Commitment avm_mem_ind_op_b; - Commitment avm_mem_ind_op_c; - Commitment avm_mem_ind_op_d; - Commitment avm_mem_last; - Commitment avm_mem_lastAccess; - Commitment avm_mem_mem_sel; - Commitment avm_mem_one_min_inv; - Commitment avm_mem_op_a; - Commitment avm_mem_op_b; - Commitment avm_mem_op_c; - Commitment avm_mem_op_d; - Commitment avm_mem_r_in_tag; - Commitment avm_mem_rng_chk_sel; - Commitment avm_mem_rw; - Commitment avm_mem_sel_cmov; - Commitment avm_mem_sel_mov_a; - Commitment avm_mem_sel_mov_b; - Commitment avm_mem_skip_check_tag; - Commitment avm_mem_space_id; - Commitment avm_mem_tag; - Commitment avm_mem_tag_err; - Commitment avm_mem_tsp; - Commitment avm_mem_val; - Commitment avm_mem_w_in_tag; - Commitment avm_pedersen_clk; - Commitment avm_pedersen_input; - Commitment avm_pedersen_output; - Commitment avm_pedersen_pedersen_sel; - Commitment avm_poseidon2_clk; - Commitment avm_poseidon2_input; - Commitment avm_poseidon2_output; - Commitment avm_poseidon2_poseidon_perm_sel; - Commitment avm_sha256_clk; - Commitment avm_sha256_input; - Commitment avm_sha256_output; - Commitment avm_sha256_sha256_compression_sel; - Commitment avm_sha256_state; + Commitment alu_a_hi; + Commitment alu_a_lo; + Commitment alu_b_hi; + Commitment alu_b_lo; + Commitment alu_borrow; + Commitment alu_cf; + Commitment alu_clk; + Commitment alu_cmp_rng_ctr; + Commitment alu_div_u16_r0; + Commitment alu_div_u16_r1; + Commitment alu_div_u16_r2; + Commitment alu_div_u16_r3; + Commitment alu_div_u16_r4; + Commitment alu_div_u16_r5; + Commitment alu_div_u16_r6; + Commitment alu_div_u16_r7; + Commitment alu_divisor_hi; + Commitment alu_divisor_lo; + Commitment alu_ff_tag; + Commitment alu_ia; + Commitment alu_ib; + Commitment alu_ic; + Commitment alu_in_tag; + Commitment alu_op_add; + Commitment alu_op_cast; + Commitment alu_op_cast_prev; + Commitment alu_op_div; + Commitment alu_op_div_a_lt_b; + Commitment alu_op_div_std; + Commitment alu_op_eq; + Commitment alu_op_eq_diff_inv; + Commitment alu_op_lt; + Commitment alu_op_lte; + Commitment alu_op_mul; + Commitment alu_op_not; + Commitment alu_op_shl; + Commitment alu_op_shr; + Commitment alu_op_sub; + Commitment alu_p_a_borrow; + Commitment alu_p_b_borrow; + Commitment alu_p_sub_a_hi; + Commitment alu_p_sub_a_lo; + Commitment alu_p_sub_b_hi; + Commitment alu_p_sub_b_lo; + Commitment alu_partial_prod_hi; + Commitment alu_partial_prod_lo; + Commitment alu_quotient_hi; + Commitment alu_quotient_lo; + Commitment alu_remainder; + Commitment alu_res_hi; + Commitment alu_res_lo; + Commitment alu_sel_alu; + Commitment alu_sel_cmp; + Commitment alu_sel_div_rng_chk; + Commitment alu_sel_rng_chk; + Commitment alu_sel_rng_chk_lookup; + Commitment alu_sel_shift_which; + Commitment alu_shift_lt_bit_len; + Commitment alu_t_sub_s_bits; + Commitment alu_two_pow_s; + Commitment alu_two_pow_t_sub_s; + Commitment alu_u128_tag; + Commitment alu_u16_r0; + Commitment alu_u16_r1; + Commitment alu_u16_r10; + Commitment alu_u16_r11; + Commitment alu_u16_r12; + Commitment alu_u16_r13; + Commitment alu_u16_r14; + Commitment alu_u16_r2; + Commitment alu_u16_r3; + Commitment alu_u16_r4; + Commitment alu_u16_r5; + Commitment alu_u16_r6; + Commitment alu_u16_r7; + Commitment alu_u16_r8; + Commitment alu_u16_r9; + Commitment alu_u16_tag; + Commitment alu_u32_tag; + Commitment alu_u64_tag; + Commitment alu_u8_r0; + Commitment alu_u8_r1; + Commitment alu_u8_tag; + Commitment binary_acc_ia; + Commitment binary_acc_ib; + Commitment binary_acc_ic; + Commitment binary_clk; + Commitment binary_ia_bytes; + Commitment binary_ib_bytes; + Commitment binary_ic_bytes; + Commitment binary_in_tag; + Commitment binary_mem_tag_ctr; + Commitment binary_mem_tag_ctr_inv; + Commitment binary_op_id; + Commitment binary_sel_bin; + Commitment binary_start; + Commitment byte_lookup_sel_bin; + Commitment byte_lookup_table_byte_lengths; + Commitment byte_lookup_table_in_tags; + Commitment byte_lookup_table_input_a; + Commitment byte_lookup_table_input_b; + Commitment byte_lookup_table_op_id; + Commitment byte_lookup_table_output; + Commitment conversion_clk; + Commitment conversion_input; + Commitment conversion_num_limbs; + Commitment conversion_radix; + Commitment conversion_sel_to_radix_le; + Commitment gas_da_gas_fixed_table; + Commitment gas_l2_gas_fixed_table; + Commitment gas_sel_gas_cost; + Commitment keccakf1600_clk; + Commitment keccakf1600_input; + Commitment keccakf1600_output; + Commitment keccakf1600_sel_keccakf1600; + Commitment kernel_emit_l2_to_l1_msg_write_offset; + Commitment kernel_emit_note_hash_write_offset; + Commitment kernel_emit_nullifier_write_offset; + Commitment kernel_emit_unencrypted_log_write_offset; + Commitment kernel_kernel_in_offset; + Commitment kernel_kernel_inputs; + Commitment kernel_kernel_metadata_out; + Commitment kernel_kernel_out_offset; + Commitment kernel_kernel_side_effect_out; + Commitment kernel_kernel_value_out; + Commitment kernel_l1_to_l2_msg_exists_write_offset; + Commitment kernel_note_hash_exist_write_offset; + Commitment kernel_nullifier_exists_write_offset; + Commitment kernel_nullifier_non_exists_write_offset; + Commitment kernel_q_public_input_kernel_add_to_table; + Commitment kernel_q_public_input_kernel_out_add_to_table; + Commitment kernel_side_effect_counter; + Commitment kernel_sload_write_offset; + Commitment kernel_sstore_write_offset; + Commitment main_abs_da_rem_gas_hi; + Commitment main_abs_da_rem_gas_lo; + Commitment main_abs_l2_rem_gas_hi; + Commitment main_abs_l2_rem_gas_lo; + Commitment main_alu_in_tag; + Commitment main_bin_op_id; + Commitment main_call_ptr; + Commitment main_da_gas_op_cost; + Commitment main_da_gas_remaining; + Commitment main_da_out_of_gas; + Commitment main_ia; + Commitment main_ib; + Commitment main_ic; + Commitment main_id; + Commitment main_id_zero; + Commitment main_ind_addr_a; + Commitment main_ind_addr_b; + Commitment main_ind_addr_c; + Commitment main_ind_addr_d; + Commitment main_internal_return_ptr; + Commitment main_inv; + Commitment main_l2_gas_op_cost; + Commitment main_l2_gas_remaining; + Commitment main_l2_out_of_gas; + Commitment main_mem_addr_a; + Commitment main_mem_addr_b; + Commitment main_mem_addr_c; + Commitment main_mem_addr_d; + Commitment main_op_err; + Commitment main_opcode_val; + Commitment main_pc; + Commitment main_r_in_tag; + Commitment main_rwa; + Commitment main_rwb; + Commitment main_rwc; + Commitment main_rwd; + Commitment main_sel_alu; + Commitment main_sel_bin; + Commitment main_sel_gas_accounting_active; + Commitment main_sel_last; + Commitment main_sel_mem_op_a; + Commitment main_sel_mem_op_activate_gas; + Commitment main_sel_mem_op_b; + Commitment main_sel_mem_op_c; + Commitment main_sel_mem_op_d; + Commitment main_sel_mov_ia_to_ic; + Commitment main_sel_mov_ib_to_ic; + Commitment main_sel_op_add; + Commitment main_sel_op_address; + Commitment main_sel_op_and; + Commitment main_sel_op_block_number; + Commitment main_sel_op_cast; + Commitment main_sel_op_chain_id; + Commitment main_sel_op_cmov; + Commitment main_sel_op_coinbase; + Commitment main_sel_op_dagasleft; + Commitment main_sel_op_div; + Commitment main_sel_op_emit_l2_to_l1_msg; + Commitment main_sel_op_emit_note_hash; + Commitment main_sel_op_emit_nullifier; + Commitment main_sel_op_emit_unencrypted_log; + Commitment main_sel_op_eq; + Commitment main_sel_op_external_call; + Commitment main_sel_op_fdiv; + Commitment main_sel_op_fee_per_da_gas; + Commitment main_sel_op_fee_per_l2_gas; + Commitment main_sel_op_get_contract_instance; + Commitment main_sel_op_halt; + Commitment main_sel_op_internal_call; + Commitment main_sel_op_internal_return; + Commitment main_sel_op_jump; + Commitment main_sel_op_jumpi; + Commitment main_sel_op_keccak; + Commitment main_sel_op_l1_to_l2_msg_exists; + Commitment main_sel_op_l2gasleft; + Commitment main_sel_op_lt; + Commitment main_sel_op_lte; + Commitment main_sel_op_mov; + Commitment main_sel_op_mul; + Commitment main_sel_op_not; + Commitment main_sel_op_note_hash_exists; + Commitment main_sel_op_nullifier_exists; + Commitment main_sel_op_or; + Commitment main_sel_op_pedersen; + Commitment main_sel_op_poseidon2; + Commitment main_sel_op_radix_le; + Commitment main_sel_op_sender; + Commitment main_sel_op_sha256; + Commitment main_sel_op_shl; + Commitment main_sel_op_shr; + Commitment main_sel_op_sload; + Commitment main_sel_op_sstore; + Commitment main_sel_op_storage_address; + Commitment main_sel_op_sub; + Commitment main_sel_op_timestamp; + Commitment main_sel_op_transaction_fee; + Commitment main_sel_op_version; + Commitment main_sel_op_xor; + Commitment main_sel_q_kernel_lookup; + Commitment main_sel_q_kernel_output_lookup; + Commitment main_sel_resolve_ind_addr_a; + Commitment main_sel_resolve_ind_addr_b; + Commitment main_sel_resolve_ind_addr_c; + Commitment main_sel_resolve_ind_addr_d; + Commitment main_sel_rng_16; + Commitment main_sel_rng_8; + Commitment main_space_id; + Commitment main_table_pow_2; + Commitment main_tag_err; + Commitment main_w_in_tag; + Commitment mem_addr; + Commitment mem_clk; + Commitment mem_diff_hi; + Commitment mem_diff_lo; + Commitment mem_diff_mid; + Commitment mem_glob_addr; + Commitment mem_last; + Commitment mem_lastAccess; + Commitment mem_one_min_inv; + Commitment mem_r_in_tag; + Commitment mem_rw; + Commitment mem_sel_mem; + Commitment mem_sel_mov_ia_to_ic; + Commitment mem_sel_mov_ib_to_ic; + Commitment mem_sel_op_a; + Commitment mem_sel_op_b; + Commitment mem_sel_op_c; + Commitment mem_sel_op_cmov; + Commitment mem_sel_op_d; + Commitment mem_sel_resolve_ind_addr_a; + Commitment mem_sel_resolve_ind_addr_b; + Commitment mem_sel_resolve_ind_addr_c; + Commitment mem_sel_resolve_ind_addr_d; + Commitment mem_sel_rng_chk; + Commitment mem_skip_check_tag; + Commitment mem_space_id; + Commitment mem_tag; + Commitment mem_tag_err; + Commitment mem_tsp; + Commitment mem_val; + Commitment mem_w_in_tag; + Commitment pedersen_clk; + Commitment pedersen_input; + Commitment pedersen_output; + Commitment pedersen_sel_pedersen; + Commitment poseidon2_clk; + Commitment poseidon2_input; + Commitment poseidon2_output; + Commitment poseidon2_sel_poseidon_perm; + Commitment sha256_clk; + Commitment sha256_input; + Commitment sha256_output; + Commitment sha256_sel_sha256_compression; + Commitment sha256_state; Commitment perm_main_alu; Commitment perm_main_bin; Commitment perm_main_conv; @@ -3448,10 +3447,10 @@ class AvmFlavor { Commitment perm_main_mem_b; Commitment perm_main_mem_c; Commitment perm_main_mem_d; - Commitment perm_main_mem_ind_a; - Commitment perm_main_mem_ind_b; - Commitment perm_main_mem_ind_c; - Commitment perm_main_mem_ind_d; + Commitment perm_main_mem_ind_addr_a; + Commitment perm_main_mem_ind_addr_b; + Commitment perm_main_mem_ind_addr_c; + Commitment perm_main_mem_ind_addr_d; Commitment lookup_byte_lengths; Commitment lookup_byte_operations; Commitment lookup_opcode_gas; @@ -3553,313 +3552,306 @@ class AvmFlavor { circuit_size = deserialize_from_buffer(proof_data, num_frs_read); size_t log_n = numeric::get_msb(circuit_size); - avm_alu_a_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_a_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_alu_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_b_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_b_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_borrow = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_cf = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_cmp_rng_ctr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_cmp_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_div_rng_chk_selector = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_div_u16_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_div_u16_r1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_div_u16_r2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_div_u16_r3 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_div_u16_r4 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_div_u16_r5 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_div_u16_r6 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_div_u16_r7 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_divisor_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_divisor_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_ff_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_ia = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_ib = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_add = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_cast = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_cast_prev = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_div = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_div_a_lt_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_div_std = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_eq = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_eq_diff_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_lt = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_lte = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_mul = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_not = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_shl = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_shr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_op_sub = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_p_a_borrow = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_p_b_borrow = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_p_sub_a_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_p_sub_a_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_p_sub_b_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_p_sub_b_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_partial_prod_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_partial_prod_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_quotient_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_quotient_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_remainder = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_res_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_res_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_rng_chk_lookup_selector = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_rng_chk_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_shift_lt_bit_len = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_shift_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_t_sub_s_bits = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_two_pow_s = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_two_pow_t_sub_s = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u128_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r10 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r11 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r12 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r13 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r14 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r3 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r4 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r5 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r6 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r7 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r8 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_r9 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u16_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u32_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u64_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u8_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u8_r1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_alu_u8_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_binary_acc_ia = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_binary_acc_ib = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_binary_acc_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_binary_bin_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_binary_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_binary_ia_bytes = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_binary_ib_bytes = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_binary_ic_bytes = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_binary_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_binary_mem_tag_ctr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_binary_mem_tag_ctr_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_binary_op_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_binary_start = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_byte_lookup_bin_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_byte_lookup_table_byte_lengths = + alu_a_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_a_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_b_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_b_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_borrow = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_cf = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_cmp_rng_ctr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_div_u16_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_div_u16_r1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_div_u16_r2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_div_u16_r3 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_div_u16_r4 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_div_u16_r5 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_div_u16_r6 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_div_u16_r7 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_divisor_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_divisor_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_ff_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_ia = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_ib = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_add = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_cast = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_cast_prev = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_div = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_div_a_lt_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_div_std = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_eq = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_eq_diff_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_lt = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_lte = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_mul = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_not = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_shl = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_shr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_op_sub = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_p_a_borrow = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_p_b_borrow = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_p_sub_a_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_p_sub_a_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_p_sub_b_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_p_sub_b_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_partial_prod_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_partial_prod_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_quotient_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_quotient_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_remainder = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_res_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_res_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_sel_alu = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_sel_cmp = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_sel_div_rng_chk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_sel_rng_chk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_sel_rng_chk_lookup = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_sel_shift_which = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_shift_lt_bit_len = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_t_sub_s_bits = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_two_pow_s = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_two_pow_t_sub_s = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u128_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r10 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r11 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r12 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r13 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r14 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r3 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r4 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r5 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r6 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r7 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r8 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_r9 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u16_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u32_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u64_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u8_r0 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u8_r1 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + alu_u8_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + binary_acc_ia = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + binary_acc_ib = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + binary_acc_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + binary_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + binary_ia_bytes = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + binary_ib_bytes = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + binary_ic_bytes = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + binary_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + binary_mem_tag_ctr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + binary_mem_tag_ctr_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + binary_op_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + binary_sel_bin = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + binary_start = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + byte_lookup_sel_bin = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + byte_lookup_table_byte_lengths = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + byte_lookup_table_in_tags = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + byte_lookup_table_input_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + byte_lookup_table_input_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + byte_lookup_table_op_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + byte_lookup_table_output = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + conversion_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + conversion_input = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + conversion_num_limbs = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + conversion_radix = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + conversion_sel_to_radix_le = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + gas_da_gas_fixed_table = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + gas_l2_gas_fixed_table = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + gas_sel_gas_cost = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + keccakf1600_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + keccakf1600_input = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + keccakf1600_output = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + keccakf1600_sel_keccakf1600 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + kernel_emit_l2_to_l1_msg_write_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_byte_lookup_table_in_tags = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_byte_lookup_table_input_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_byte_lookup_table_input_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_byte_lookup_table_op_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_byte_lookup_table_output = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_conversion_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_conversion_input = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_conversion_num_limbs = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_conversion_radix = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_conversion_to_radix_le_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_gas_da_gas_fixed_table = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_gas_gas_cost_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_gas_l2_gas_fixed_table = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_keccakf1600_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_keccakf1600_input = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_keccakf1600_keccakf1600_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_keccakf1600_output = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_emit_l2_to_l1_msg_write_offset = + kernel_emit_note_hash_write_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_emit_note_hash_write_offset = + kernel_emit_nullifier_write_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_emit_nullifier_write_offset = + kernel_emit_unencrypted_log_write_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_emit_unencrypted_log_write_offset = + kernel_kernel_in_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + kernel_kernel_inputs = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + kernel_kernel_metadata_out = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + kernel_kernel_out_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + kernel_kernel_side_effect_out = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + kernel_kernel_value_out = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + kernel_l1_to_l2_msg_exists_write_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_kernel_in_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_kernel_inputs = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_kernel_metadata_out = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_kernel_out_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_kernel_side_effect_out = + kernel_note_hash_exist_write_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_kernel_value_out = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_l1_to_l2_msg_exists_write_offset = + kernel_nullifier_exists_write_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_note_hash_exist_write_offset = + kernel_nullifier_non_exists_write_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_nullifier_exists_write_offset = + kernel_q_public_input_kernel_add_to_table = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_nullifier_non_exists_write_offset = + kernel_q_public_input_kernel_out_add_to_table = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_q_public_input_kernel_add_to_table = + kernel_side_effect_counter = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + kernel_sload_write_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + kernel_sstore_write_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_abs_da_rem_gas_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_abs_da_rem_gas_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_abs_l2_rem_gas_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_abs_l2_rem_gas_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_alu_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_bin_op_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_call_ptr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_da_gas_op_cost = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_da_gas_remaining = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_da_out_of_gas = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_ia = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_ib = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_id_zero = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_ind_addr_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_ind_addr_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_ind_addr_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_ind_addr_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_internal_return_ptr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_l2_gas_op_cost = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_l2_gas_remaining = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_l2_out_of_gas = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_mem_addr_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_mem_addr_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_mem_addr_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_mem_addr_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_op_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_opcode_val = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_pc = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_r_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_rwa = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_rwb = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_rwc = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_rwd = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_alu = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_bin = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_gas_accounting_active = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_last = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_mem_op_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_mem_op_activate_gas = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_mem_op_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_mem_op_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_mem_op_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_mov_ia_to_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_mov_ib_to_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_add = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_address = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_and = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_block_number = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_cast = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_chain_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_cmov = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_coinbase = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_dagasleft = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_div = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_emit_l2_to_l1_msg = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_emit_note_hash = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_emit_nullifier = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_emit_unencrypted_log = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_q_public_input_kernel_out_add_to_table = + main_sel_op_eq = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_external_call = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_fdiv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_fee_per_da_gas = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_fee_per_l2_gas = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_get_contract_instance = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_side_effect_counter = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_sload_write_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_kernel_sstore_write_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_abs_da_rem_gas_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_abs_da_rem_gas_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_abs_l2_rem_gas_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_abs_l2_rem_gas_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_alu_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_alu_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_bin_op_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_bin_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_call_ptr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_da_gas_op = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_da_gas_remaining = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_da_out_of_gas = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_gas_cost_active = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_ia = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_ib = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_id_zero = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_ind_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_ind_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_ind_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_ind_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_ind_op_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_ind_op_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_ind_op_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_ind_op_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_internal_return_ptr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_l2_gas_op = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_l2_gas_remaining = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_l2_out_of_gas = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_last = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_mem_idx_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_mem_idx_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_mem_idx_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_mem_idx_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_mem_op_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_mem_op_activate_gas = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_mem_op_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_mem_op_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_mem_op_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_op_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_opcode_val = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_pc = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_q_kernel_lookup = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_q_kernel_output_lookup = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_r_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_rwa = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_rwb = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_rwc = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_rwd = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_cmov = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_external_call = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_halt = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_internal_call = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_internal_return = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_jump = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_jumpi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_mov = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_mov_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_mov_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_add = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_address = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_and = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_block_number = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_cast = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_chain_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_coinbase = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_dagasleft = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_div = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_emit_l2_to_l1_msg = - deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_emit_note_hash = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_emit_nullifier = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_emit_unencrypted_log = - deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_eq = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_fdiv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_fee_per_da_gas = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_fee_per_l2_gas = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_get_contract_instance = - deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_keccak = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_l1_to_l2_msg_exists = - deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_l2gasleft = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_lt = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_lte = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_mul = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_not = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_note_hash_exists = - deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_nullifier_exists = - deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_or = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_pedersen = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_poseidon2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_radix_le = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_sender = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_sha256 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_shl = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_shr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_sload = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_sstore = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_storage_address = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_sub = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_timestamp = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_transaction_fee = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_version = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_op_xor = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_rng_16 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_sel_rng_8 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_space_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_table_pow_2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_main_w_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_addr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_diff_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_diff_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_diff_mid = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_glob_addr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_ind_op_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_ind_op_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_ind_op_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_ind_op_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_last = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_lastAccess = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_mem_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_one_min_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_op_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_op_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_op_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_op_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_r_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_rng_chk_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_rw = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_sel_cmov = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_sel_mov_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_sel_mov_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_skip_check_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_space_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_tsp = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_val = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_mem_w_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_pedersen_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_pedersen_input = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_pedersen_output = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_pedersen_pedersen_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_poseidon2_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_poseidon2_input = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_poseidon2_output = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_poseidon2_poseidon_perm_sel = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_sha256_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_sha256_input = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_sha256_output = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_sha256_sha256_compression_sel = - deserialize_from_buffer(Transcript::proof_data, num_frs_read); - avm_sha256_state = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_halt = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_internal_call = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_internal_return = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_jump = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_jumpi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_keccak = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_l1_to_l2_msg_exists = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_l2gasleft = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_lt = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_lte = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_mov = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_mul = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_not = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_note_hash_exists = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_nullifier_exists = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_or = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_pedersen = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_poseidon2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_radix_le = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_sender = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_sha256 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_shl = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_shr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_sload = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_sstore = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_storage_address = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_sub = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_timestamp = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_transaction_fee = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_version = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_op_xor = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_q_kernel_lookup = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_q_kernel_output_lookup = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_resolve_ind_addr_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_resolve_ind_addr_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_resolve_ind_addr_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_resolve_ind_addr_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_rng_16 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_sel_rng_8 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_space_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_table_pow_2 = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + main_w_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_addr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_diff_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_diff_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_diff_mid = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_glob_addr = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_last = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_lastAccess = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_one_min_inv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_r_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_rw = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_sel_mem = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_sel_mov_ia_to_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_sel_mov_ib_to_ic = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_sel_op_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_sel_op_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_sel_op_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_sel_op_cmov = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_sel_op_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_sel_resolve_ind_addr_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_sel_resolve_ind_addr_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_sel_resolve_ind_addr_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_sel_resolve_ind_addr_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_sel_rng_chk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_skip_check_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_space_id = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_tag_err = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_tsp = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_val = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + mem_w_in_tag = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + pedersen_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + pedersen_input = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + pedersen_output = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + pedersen_sel_pedersen = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + poseidon2_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + poseidon2_input = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + poseidon2_output = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + poseidon2_sel_poseidon_perm = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + sha256_clk = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + sha256_input = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + sha256_output = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + sha256_sel_sha256_compression = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + sha256_state = deserialize_from_buffer(Transcript::proof_data, num_frs_read); perm_main_alu = deserialize_from_buffer(Transcript::proof_data, num_frs_read); perm_main_bin = deserialize_from_buffer(Transcript::proof_data, num_frs_read); perm_main_conv = deserialize_from_buffer(Transcript::proof_data, num_frs_read); @@ -3869,10 +3861,10 @@ class AvmFlavor { perm_main_mem_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); perm_main_mem_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); perm_main_mem_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - perm_main_mem_ind_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - perm_main_mem_ind_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - perm_main_mem_ind_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - perm_main_mem_ind_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + perm_main_mem_ind_addr_a = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + perm_main_mem_ind_addr_b = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + perm_main_mem_ind_addr_c = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + perm_main_mem_ind_addr_d = deserialize_from_buffer(Transcript::proof_data, num_frs_read); lookup_byte_lengths = deserialize_from_buffer(Transcript::proof_data, num_frs_read); lookup_byte_operations = deserialize_from_buffer(Transcript::proof_data, num_frs_read); lookup_opcode_gas = deserialize_from_buffer(Transcript::proof_data, num_frs_read); @@ -3978,294 +3970,294 @@ class AvmFlavor { serialize_to_buffer(circuit_size, Transcript::proof_data); - serialize_to_buffer(avm_alu_a_hi, Transcript::proof_data); - serialize_to_buffer(avm_alu_a_lo, Transcript::proof_data); - serialize_to_buffer(avm_alu_alu_sel, Transcript::proof_data); - serialize_to_buffer(avm_alu_b_hi, Transcript::proof_data); - serialize_to_buffer(avm_alu_b_lo, Transcript::proof_data); - serialize_to_buffer(avm_alu_borrow, Transcript::proof_data); - serialize_to_buffer(avm_alu_cf, Transcript::proof_data); - serialize_to_buffer(avm_alu_clk, Transcript::proof_data); - serialize_to_buffer(avm_alu_cmp_rng_ctr, Transcript::proof_data); - serialize_to_buffer(avm_alu_cmp_sel, Transcript::proof_data); - serialize_to_buffer(avm_alu_div_rng_chk_selector, Transcript::proof_data); - serialize_to_buffer(avm_alu_div_u16_r0, Transcript::proof_data); - serialize_to_buffer(avm_alu_div_u16_r1, Transcript::proof_data); - serialize_to_buffer(avm_alu_div_u16_r2, Transcript::proof_data); - serialize_to_buffer(avm_alu_div_u16_r3, Transcript::proof_data); - serialize_to_buffer(avm_alu_div_u16_r4, Transcript::proof_data); - serialize_to_buffer(avm_alu_div_u16_r5, Transcript::proof_data); - serialize_to_buffer(avm_alu_div_u16_r6, Transcript::proof_data); - serialize_to_buffer(avm_alu_div_u16_r7, Transcript::proof_data); - serialize_to_buffer(avm_alu_divisor_hi, Transcript::proof_data); - serialize_to_buffer(avm_alu_divisor_lo, Transcript::proof_data); - serialize_to_buffer(avm_alu_ff_tag, Transcript::proof_data); - serialize_to_buffer(avm_alu_ia, Transcript::proof_data); - serialize_to_buffer(avm_alu_ib, Transcript::proof_data); - serialize_to_buffer(avm_alu_ic, Transcript::proof_data); - serialize_to_buffer(avm_alu_in_tag, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_add, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_cast, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_cast_prev, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_div, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_div_a_lt_b, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_div_std, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_eq, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_eq_diff_inv, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_lt, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_lte, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_mul, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_not, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_shl, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_shr, Transcript::proof_data); - serialize_to_buffer(avm_alu_op_sub, Transcript::proof_data); - serialize_to_buffer(avm_alu_p_a_borrow, Transcript::proof_data); - serialize_to_buffer(avm_alu_p_b_borrow, Transcript::proof_data); - serialize_to_buffer(avm_alu_p_sub_a_hi, Transcript::proof_data); - serialize_to_buffer(avm_alu_p_sub_a_lo, Transcript::proof_data); - serialize_to_buffer(avm_alu_p_sub_b_hi, Transcript::proof_data); - serialize_to_buffer(avm_alu_p_sub_b_lo, Transcript::proof_data); - serialize_to_buffer(avm_alu_partial_prod_hi, Transcript::proof_data); - serialize_to_buffer(avm_alu_partial_prod_lo, Transcript::proof_data); - serialize_to_buffer(avm_alu_quotient_hi, Transcript::proof_data); - serialize_to_buffer(avm_alu_quotient_lo, Transcript::proof_data); - serialize_to_buffer(avm_alu_remainder, Transcript::proof_data); - serialize_to_buffer(avm_alu_res_hi, Transcript::proof_data); - serialize_to_buffer(avm_alu_res_lo, Transcript::proof_data); - serialize_to_buffer(avm_alu_rng_chk_lookup_selector, Transcript::proof_data); - serialize_to_buffer(avm_alu_rng_chk_sel, Transcript::proof_data); - serialize_to_buffer(avm_alu_shift_lt_bit_len, Transcript::proof_data); - serialize_to_buffer(avm_alu_shift_sel, Transcript::proof_data); - serialize_to_buffer(avm_alu_t_sub_s_bits, Transcript::proof_data); - serialize_to_buffer(avm_alu_two_pow_s, Transcript::proof_data); - serialize_to_buffer(avm_alu_two_pow_t_sub_s, Transcript::proof_data); - serialize_to_buffer(avm_alu_u128_tag, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r0, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r1, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r10, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r11, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r12, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r13, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r14, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r2, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r3, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r4, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r5, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r6, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r7, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r8, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_r9, Transcript::proof_data); - serialize_to_buffer(avm_alu_u16_tag, Transcript::proof_data); - serialize_to_buffer(avm_alu_u32_tag, Transcript::proof_data); - serialize_to_buffer(avm_alu_u64_tag, Transcript::proof_data); - serialize_to_buffer(avm_alu_u8_r0, Transcript::proof_data); - serialize_to_buffer(avm_alu_u8_r1, Transcript::proof_data); - serialize_to_buffer(avm_alu_u8_tag, Transcript::proof_data); - serialize_to_buffer(avm_binary_acc_ia, Transcript::proof_data); - serialize_to_buffer(avm_binary_acc_ib, Transcript::proof_data); - serialize_to_buffer(avm_binary_acc_ic, Transcript::proof_data); - serialize_to_buffer(avm_binary_bin_sel, Transcript::proof_data); - serialize_to_buffer(avm_binary_clk, Transcript::proof_data); - serialize_to_buffer(avm_binary_ia_bytes, Transcript::proof_data); - serialize_to_buffer(avm_binary_ib_bytes, Transcript::proof_data); - serialize_to_buffer(avm_binary_ic_bytes, Transcript::proof_data); - serialize_to_buffer(avm_binary_in_tag, Transcript::proof_data); - serialize_to_buffer(avm_binary_mem_tag_ctr, Transcript::proof_data); - serialize_to_buffer(avm_binary_mem_tag_ctr_inv, Transcript::proof_data); - serialize_to_buffer(avm_binary_op_id, Transcript::proof_data); - serialize_to_buffer(avm_binary_start, Transcript::proof_data); - serialize_to_buffer(avm_byte_lookup_bin_sel, Transcript::proof_data); - serialize_to_buffer(avm_byte_lookup_table_byte_lengths, Transcript::proof_data); - serialize_to_buffer(avm_byte_lookup_table_in_tags, Transcript::proof_data); - serialize_to_buffer(avm_byte_lookup_table_input_a, Transcript::proof_data); - serialize_to_buffer(avm_byte_lookup_table_input_b, Transcript::proof_data); - serialize_to_buffer(avm_byte_lookup_table_op_id, Transcript::proof_data); - serialize_to_buffer(avm_byte_lookup_table_output, Transcript::proof_data); - serialize_to_buffer(avm_conversion_clk, Transcript::proof_data); - serialize_to_buffer(avm_conversion_input, Transcript::proof_data); - serialize_to_buffer(avm_conversion_num_limbs, Transcript::proof_data); - serialize_to_buffer(avm_conversion_radix, Transcript::proof_data); - serialize_to_buffer(avm_conversion_to_radix_le_sel, Transcript::proof_data); - serialize_to_buffer(avm_gas_da_gas_fixed_table, Transcript::proof_data); - serialize_to_buffer(avm_gas_gas_cost_sel, Transcript::proof_data); - serialize_to_buffer(avm_gas_l2_gas_fixed_table, Transcript::proof_data); - serialize_to_buffer(avm_keccakf1600_clk, Transcript::proof_data); - serialize_to_buffer(avm_keccakf1600_input, Transcript::proof_data); - serialize_to_buffer(avm_keccakf1600_keccakf1600_sel, Transcript::proof_data); - serialize_to_buffer(avm_keccakf1600_output, Transcript::proof_data); - serialize_to_buffer(avm_kernel_emit_l2_to_l1_msg_write_offset, Transcript::proof_data); - serialize_to_buffer(avm_kernel_emit_note_hash_write_offset, Transcript::proof_data); - serialize_to_buffer(avm_kernel_emit_nullifier_write_offset, Transcript::proof_data); - serialize_to_buffer(avm_kernel_emit_unencrypted_log_write_offset, Transcript::proof_data); - serialize_to_buffer(avm_kernel_kernel_in_offset, Transcript::proof_data); - serialize_to_buffer(avm_kernel_kernel_inputs, Transcript::proof_data); - serialize_to_buffer(avm_kernel_kernel_metadata_out, Transcript::proof_data); - serialize_to_buffer(avm_kernel_kernel_out_offset, Transcript::proof_data); - serialize_to_buffer(avm_kernel_kernel_side_effect_out, Transcript::proof_data); - serialize_to_buffer(avm_kernel_kernel_value_out, Transcript::proof_data); - serialize_to_buffer(avm_kernel_l1_to_l2_msg_exists_write_offset, Transcript::proof_data); - serialize_to_buffer(avm_kernel_note_hash_exist_write_offset, Transcript::proof_data); - serialize_to_buffer(avm_kernel_nullifier_exists_write_offset, Transcript::proof_data); - serialize_to_buffer(avm_kernel_nullifier_non_exists_write_offset, Transcript::proof_data); - serialize_to_buffer(avm_kernel_q_public_input_kernel_add_to_table, Transcript::proof_data); - serialize_to_buffer(avm_kernel_q_public_input_kernel_out_add_to_table, Transcript::proof_data); - serialize_to_buffer(avm_kernel_side_effect_counter, Transcript::proof_data); - serialize_to_buffer(avm_kernel_sload_write_offset, Transcript::proof_data); - serialize_to_buffer(avm_kernel_sstore_write_offset, Transcript::proof_data); - serialize_to_buffer(avm_main_abs_da_rem_gas_hi, Transcript::proof_data); - serialize_to_buffer(avm_main_abs_da_rem_gas_lo, Transcript::proof_data); - serialize_to_buffer(avm_main_abs_l2_rem_gas_hi, Transcript::proof_data); - serialize_to_buffer(avm_main_abs_l2_rem_gas_lo, Transcript::proof_data); - serialize_to_buffer(avm_main_alu_in_tag, Transcript::proof_data); - serialize_to_buffer(avm_main_alu_sel, Transcript::proof_data); - serialize_to_buffer(avm_main_bin_op_id, Transcript::proof_data); - serialize_to_buffer(avm_main_bin_sel, Transcript::proof_data); - serialize_to_buffer(avm_main_call_ptr, Transcript::proof_data); - serialize_to_buffer(avm_main_da_gas_op, Transcript::proof_data); - serialize_to_buffer(avm_main_da_gas_remaining, Transcript::proof_data); - serialize_to_buffer(avm_main_da_out_of_gas, Transcript::proof_data); - serialize_to_buffer(avm_main_gas_cost_active, Transcript::proof_data); - serialize_to_buffer(avm_main_ia, Transcript::proof_data); - serialize_to_buffer(avm_main_ib, Transcript::proof_data); - serialize_to_buffer(avm_main_ic, Transcript::proof_data); - serialize_to_buffer(avm_main_id, Transcript::proof_data); - serialize_to_buffer(avm_main_id_zero, Transcript::proof_data); - serialize_to_buffer(avm_main_ind_a, Transcript::proof_data); - serialize_to_buffer(avm_main_ind_b, Transcript::proof_data); - serialize_to_buffer(avm_main_ind_c, Transcript::proof_data); - serialize_to_buffer(avm_main_ind_d, Transcript::proof_data); - serialize_to_buffer(avm_main_ind_op_a, Transcript::proof_data); - serialize_to_buffer(avm_main_ind_op_b, Transcript::proof_data); - serialize_to_buffer(avm_main_ind_op_c, Transcript::proof_data); - serialize_to_buffer(avm_main_ind_op_d, Transcript::proof_data); - serialize_to_buffer(avm_main_internal_return_ptr, Transcript::proof_data); - serialize_to_buffer(avm_main_inv, Transcript::proof_data); - serialize_to_buffer(avm_main_l2_gas_op, Transcript::proof_data); - serialize_to_buffer(avm_main_l2_gas_remaining, Transcript::proof_data); - serialize_to_buffer(avm_main_l2_out_of_gas, Transcript::proof_data); - serialize_to_buffer(avm_main_last, Transcript::proof_data); - serialize_to_buffer(avm_main_mem_idx_a, Transcript::proof_data); - serialize_to_buffer(avm_main_mem_idx_b, Transcript::proof_data); - serialize_to_buffer(avm_main_mem_idx_c, Transcript::proof_data); - serialize_to_buffer(avm_main_mem_idx_d, Transcript::proof_data); - serialize_to_buffer(avm_main_mem_op_a, Transcript::proof_data); - serialize_to_buffer(avm_main_mem_op_activate_gas, Transcript::proof_data); - serialize_to_buffer(avm_main_mem_op_b, Transcript::proof_data); - serialize_to_buffer(avm_main_mem_op_c, Transcript::proof_data); - serialize_to_buffer(avm_main_mem_op_d, Transcript::proof_data); - serialize_to_buffer(avm_main_op_err, Transcript::proof_data); - serialize_to_buffer(avm_main_opcode_val, Transcript::proof_data); - serialize_to_buffer(avm_main_pc, Transcript::proof_data); - serialize_to_buffer(avm_main_q_kernel_lookup, Transcript::proof_data); - serialize_to_buffer(avm_main_q_kernel_output_lookup, Transcript::proof_data); - serialize_to_buffer(avm_main_r_in_tag, Transcript::proof_data); - serialize_to_buffer(avm_main_rwa, Transcript::proof_data); - serialize_to_buffer(avm_main_rwb, Transcript::proof_data); - serialize_to_buffer(avm_main_rwc, Transcript::proof_data); - serialize_to_buffer(avm_main_rwd, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_cmov, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_external_call, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_halt, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_internal_call, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_internal_return, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_jump, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_jumpi, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_mov, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_mov_a, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_mov_b, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_add, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_address, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_and, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_block_number, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_cast, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_chain_id, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_coinbase, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_dagasleft, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_div, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_emit_l2_to_l1_msg, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_emit_note_hash, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_emit_nullifier, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_emit_unencrypted_log, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_eq, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_fdiv, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_fee_per_da_gas, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_fee_per_l2_gas, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_get_contract_instance, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_keccak, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_l1_to_l2_msg_exists, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_l2gasleft, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_lt, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_lte, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_mul, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_not, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_note_hash_exists, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_nullifier_exists, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_or, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_pedersen, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_poseidon2, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_radix_le, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_sender, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_sha256, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_shl, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_shr, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_sload, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_sstore, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_storage_address, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_sub, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_timestamp, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_transaction_fee, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_version, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_op_xor, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_rng_16, Transcript::proof_data); - serialize_to_buffer(avm_main_sel_rng_8, Transcript::proof_data); - serialize_to_buffer(avm_main_space_id, Transcript::proof_data); - serialize_to_buffer(avm_main_table_pow_2, Transcript::proof_data); - serialize_to_buffer(avm_main_tag_err, Transcript::proof_data); - serialize_to_buffer(avm_main_w_in_tag, Transcript::proof_data); - serialize_to_buffer(avm_mem_addr, Transcript::proof_data); - serialize_to_buffer(avm_mem_clk, Transcript::proof_data); - serialize_to_buffer(avm_mem_diff_hi, Transcript::proof_data); - serialize_to_buffer(avm_mem_diff_lo, Transcript::proof_data); - serialize_to_buffer(avm_mem_diff_mid, Transcript::proof_data); - serialize_to_buffer(avm_mem_glob_addr, Transcript::proof_data); - serialize_to_buffer(avm_mem_ind_op_a, Transcript::proof_data); - serialize_to_buffer(avm_mem_ind_op_b, Transcript::proof_data); - serialize_to_buffer(avm_mem_ind_op_c, Transcript::proof_data); - serialize_to_buffer(avm_mem_ind_op_d, Transcript::proof_data); - serialize_to_buffer(avm_mem_last, Transcript::proof_data); - serialize_to_buffer(avm_mem_lastAccess, Transcript::proof_data); - serialize_to_buffer(avm_mem_mem_sel, Transcript::proof_data); - serialize_to_buffer(avm_mem_one_min_inv, Transcript::proof_data); - serialize_to_buffer(avm_mem_op_a, Transcript::proof_data); - serialize_to_buffer(avm_mem_op_b, Transcript::proof_data); - serialize_to_buffer(avm_mem_op_c, Transcript::proof_data); - serialize_to_buffer(avm_mem_op_d, Transcript::proof_data); - serialize_to_buffer(avm_mem_r_in_tag, Transcript::proof_data); - serialize_to_buffer(avm_mem_rng_chk_sel, Transcript::proof_data); - serialize_to_buffer(avm_mem_rw, Transcript::proof_data); - serialize_to_buffer(avm_mem_sel_cmov, Transcript::proof_data); - serialize_to_buffer(avm_mem_sel_mov_a, Transcript::proof_data); - serialize_to_buffer(avm_mem_sel_mov_b, Transcript::proof_data); - serialize_to_buffer(avm_mem_skip_check_tag, Transcript::proof_data); - serialize_to_buffer(avm_mem_space_id, Transcript::proof_data); - serialize_to_buffer(avm_mem_tag, Transcript::proof_data); - serialize_to_buffer(avm_mem_tag_err, Transcript::proof_data); - serialize_to_buffer(avm_mem_tsp, Transcript::proof_data); - serialize_to_buffer(avm_mem_val, Transcript::proof_data); - serialize_to_buffer(avm_mem_w_in_tag, Transcript::proof_data); - serialize_to_buffer(avm_pedersen_clk, Transcript::proof_data); - serialize_to_buffer(avm_pedersen_input, Transcript::proof_data); - serialize_to_buffer(avm_pedersen_output, Transcript::proof_data); - serialize_to_buffer(avm_pedersen_pedersen_sel, Transcript::proof_data); - serialize_to_buffer(avm_poseidon2_clk, Transcript::proof_data); - serialize_to_buffer(avm_poseidon2_input, Transcript::proof_data); - serialize_to_buffer(avm_poseidon2_output, Transcript::proof_data); - serialize_to_buffer(avm_poseidon2_poseidon_perm_sel, Transcript::proof_data); - serialize_to_buffer(avm_sha256_clk, Transcript::proof_data); - serialize_to_buffer(avm_sha256_input, Transcript::proof_data); - serialize_to_buffer(avm_sha256_output, Transcript::proof_data); - serialize_to_buffer(avm_sha256_sha256_compression_sel, Transcript::proof_data); - serialize_to_buffer(avm_sha256_state, Transcript::proof_data); + serialize_to_buffer(alu_a_hi, Transcript::proof_data); + serialize_to_buffer(alu_a_lo, Transcript::proof_data); + serialize_to_buffer(alu_b_hi, Transcript::proof_data); + serialize_to_buffer(alu_b_lo, Transcript::proof_data); + serialize_to_buffer(alu_borrow, Transcript::proof_data); + serialize_to_buffer(alu_cf, Transcript::proof_data); + serialize_to_buffer(alu_clk, Transcript::proof_data); + serialize_to_buffer(alu_cmp_rng_ctr, Transcript::proof_data); + serialize_to_buffer(alu_div_u16_r0, Transcript::proof_data); + serialize_to_buffer(alu_div_u16_r1, Transcript::proof_data); + serialize_to_buffer(alu_div_u16_r2, Transcript::proof_data); + serialize_to_buffer(alu_div_u16_r3, Transcript::proof_data); + serialize_to_buffer(alu_div_u16_r4, Transcript::proof_data); + serialize_to_buffer(alu_div_u16_r5, Transcript::proof_data); + serialize_to_buffer(alu_div_u16_r6, Transcript::proof_data); + serialize_to_buffer(alu_div_u16_r7, Transcript::proof_data); + serialize_to_buffer(alu_divisor_hi, Transcript::proof_data); + serialize_to_buffer(alu_divisor_lo, Transcript::proof_data); + serialize_to_buffer(alu_ff_tag, Transcript::proof_data); + serialize_to_buffer(alu_ia, Transcript::proof_data); + serialize_to_buffer(alu_ib, Transcript::proof_data); + serialize_to_buffer(alu_ic, Transcript::proof_data); + serialize_to_buffer(alu_in_tag, Transcript::proof_data); + serialize_to_buffer(alu_op_add, Transcript::proof_data); + serialize_to_buffer(alu_op_cast, Transcript::proof_data); + serialize_to_buffer(alu_op_cast_prev, Transcript::proof_data); + serialize_to_buffer(alu_op_div, Transcript::proof_data); + serialize_to_buffer(alu_op_div_a_lt_b, Transcript::proof_data); + serialize_to_buffer(alu_op_div_std, Transcript::proof_data); + serialize_to_buffer(alu_op_eq, Transcript::proof_data); + serialize_to_buffer(alu_op_eq_diff_inv, Transcript::proof_data); + serialize_to_buffer(alu_op_lt, Transcript::proof_data); + serialize_to_buffer(alu_op_lte, Transcript::proof_data); + serialize_to_buffer(alu_op_mul, Transcript::proof_data); + serialize_to_buffer(alu_op_not, Transcript::proof_data); + serialize_to_buffer(alu_op_shl, Transcript::proof_data); + serialize_to_buffer(alu_op_shr, Transcript::proof_data); + serialize_to_buffer(alu_op_sub, Transcript::proof_data); + serialize_to_buffer(alu_p_a_borrow, Transcript::proof_data); + serialize_to_buffer(alu_p_b_borrow, Transcript::proof_data); + serialize_to_buffer(alu_p_sub_a_hi, Transcript::proof_data); + serialize_to_buffer(alu_p_sub_a_lo, Transcript::proof_data); + serialize_to_buffer(alu_p_sub_b_hi, Transcript::proof_data); + serialize_to_buffer(alu_p_sub_b_lo, Transcript::proof_data); + serialize_to_buffer(alu_partial_prod_hi, Transcript::proof_data); + serialize_to_buffer(alu_partial_prod_lo, Transcript::proof_data); + serialize_to_buffer(alu_quotient_hi, Transcript::proof_data); + serialize_to_buffer(alu_quotient_lo, Transcript::proof_data); + serialize_to_buffer(alu_remainder, Transcript::proof_data); + serialize_to_buffer(alu_res_hi, Transcript::proof_data); + serialize_to_buffer(alu_res_lo, Transcript::proof_data); + serialize_to_buffer(alu_sel_alu, Transcript::proof_data); + serialize_to_buffer(alu_sel_cmp, Transcript::proof_data); + serialize_to_buffer(alu_sel_div_rng_chk, Transcript::proof_data); + serialize_to_buffer(alu_sel_rng_chk, Transcript::proof_data); + serialize_to_buffer(alu_sel_rng_chk_lookup, Transcript::proof_data); + serialize_to_buffer(alu_sel_shift_which, Transcript::proof_data); + serialize_to_buffer(alu_shift_lt_bit_len, Transcript::proof_data); + serialize_to_buffer(alu_t_sub_s_bits, Transcript::proof_data); + serialize_to_buffer(alu_two_pow_s, Transcript::proof_data); + serialize_to_buffer(alu_two_pow_t_sub_s, Transcript::proof_data); + serialize_to_buffer(alu_u128_tag, Transcript::proof_data); + serialize_to_buffer(alu_u16_r0, Transcript::proof_data); + serialize_to_buffer(alu_u16_r1, Transcript::proof_data); + serialize_to_buffer(alu_u16_r10, Transcript::proof_data); + serialize_to_buffer(alu_u16_r11, Transcript::proof_data); + serialize_to_buffer(alu_u16_r12, Transcript::proof_data); + serialize_to_buffer(alu_u16_r13, Transcript::proof_data); + serialize_to_buffer(alu_u16_r14, Transcript::proof_data); + serialize_to_buffer(alu_u16_r2, Transcript::proof_data); + serialize_to_buffer(alu_u16_r3, Transcript::proof_data); + serialize_to_buffer(alu_u16_r4, Transcript::proof_data); + serialize_to_buffer(alu_u16_r5, Transcript::proof_data); + serialize_to_buffer(alu_u16_r6, Transcript::proof_data); + serialize_to_buffer(alu_u16_r7, Transcript::proof_data); + serialize_to_buffer(alu_u16_r8, Transcript::proof_data); + serialize_to_buffer(alu_u16_r9, Transcript::proof_data); + serialize_to_buffer(alu_u16_tag, Transcript::proof_data); + serialize_to_buffer(alu_u32_tag, Transcript::proof_data); + serialize_to_buffer(alu_u64_tag, Transcript::proof_data); + serialize_to_buffer(alu_u8_r0, Transcript::proof_data); + serialize_to_buffer(alu_u8_r1, Transcript::proof_data); + serialize_to_buffer(alu_u8_tag, Transcript::proof_data); + serialize_to_buffer(binary_acc_ia, Transcript::proof_data); + serialize_to_buffer(binary_acc_ib, Transcript::proof_data); + serialize_to_buffer(binary_acc_ic, Transcript::proof_data); + serialize_to_buffer(binary_clk, Transcript::proof_data); + serialize_to_buffer(binary_ia_bytes, Transcript::proof_data); + serialize_to_buffer(binary_ib_bytes, Transcript::proof_data); + serialize_to_buffer(binary_ic_bytes, Transcript::proof_data); + serialize_to_buffer(binary_in_tag, Transcript::proof_data); + serialize_to_buffer(binary_mem_tag_ctr, Transcript::proof_data); + serialize_to_buffer(binary_mem_tag_ctr_inv, Transcript::proof_data); + serialize_to_buffer(binary_op_id, Transcript::proof_data); + serialize_to_buffer(binary_sel_bin, Transcript::proof_data); + serialize_to_buffer(binary_start, Transcript::proof_data); + serialize_to_buffer(byte_lookup_sel_bin, Transcript::proof_data); + serialize_to_buffer(byte_lookup_table_byte_lengths, Transcript::proof_data); + serialize_to_buffer(byte_lookup_table_in_tags, Transcript::proof_data); + serialize_to_buffer(byte_lookup_table_input_a, Transcript::proof_data); + serialize_to_buffer(byte_lookup_table_input_b, Transcript::proof_data); + serialize_to_buffer(byte_lookup_table_op_id, Transcript::proof_data); + serialize_to_buffer(byte_lookup_table_output, Transcript::proof_data); + serialize_to_buffer(conversion_clk, Transcript::proof_data); + serialize_to_buffer(conversion_input, Transcript::proof_data); + serialize_to_buffer(conversion_num_limbs, Transcript::proof_data); + serialize_to_buffer(conversion_radix, Transcript::proof_data); + serialize_to_buffer(conversion_sel_to_radix_le, Transcript::proof_data); + serialize_to_buffer(gas_da_gas_fixed_table, Transcript::proof_data); + serialize_to_buffer(gas_l2_gas_fixed_table, Transcript::proof_data); + serialize_to_buffer(gas_sel_gas_cost, Transcript::proof_data); + serialize_to_buffer(keccakf1600_clk, Transcript::proof_data); + serialize_to_buffer(keccakf1600_input, Transcript::proof_data); + serialize_to_buffer(keccakf1600_output, Transcript::proof_data); + serialize_to_buffer(keccakf1600_sel_keccakf1600, Transcript::proof_data); + serialize_to_buffer(kernel_emit_l2_to_l1_msg_write_offset, Transcript::proof_data); + serialize_to_buffer(kernel_emit_note_hash_write_offset, Transcript::proof_data); + serialize_to_buffer(kernel_emit_nullifier_write_offset, Transcript::proof_data); + serialize_to_buffer(kernel_emit_unencrypted_log_write_offset, Transcript::proof_data); + serialize_to_buffer(kernel_kernel_in_offset, Transcript::proof_data); + serialize_to_buffer(kernel_kernel_inputs, Transcript::proof_data); + serialize_to_buffer(kernel_kernel_metadata_out, Transcript::proof_data); + serialize_to_buffer(kernel_kernel_out_offset, Transcript::proof_data); + serialize_to_buffer(kernel_kernel_side_effect_out, Transcript::proof_data); + serialize_to_buffer(kernel_kernel_value_out, Transcript::proof_data); + serialize_to_buffer(kernel_l1_to_l2_msg_exists_write_offset, Transcript::proof_data); + serialize_to_buffer(kernel_note_hash_exist_write_offset, Transcript::proof_data); + serialize_to_buffer(kernel_nullifier_exists_write_offset, Transcript::proof_data); + serialize_to_buffer(kernel_nullifier_non_exists_write_offset, Transcript::proof_data); + serialize_to_buffer(kernel_q_public_input_kernel_add_to_table, Transcript::proof_data); + serialize_to_buffer(kernel_q_public_input_kernel_out_add_to_table, Transcript::proof_data); + serialize_to_buffer(kernel_side_effect_counter, Transcript::proof_data); + serialize_to_buffer(kernel_sload_write_offset, Transcript::proof_data); + serialize_to_buffer(kernel_sstore_write_offset, Transcript::proof_data); + serialize_to_buffer(main_abs_da_rem_gas_hi, Transcript::proof_data); + serialize_to_buffer(main_abs_da_rem_gas_lo, Transcript::proof_data); + serialize_to_buffer(main_abs_l2_rem_gas_hi, Transcript::proof_data); + serialize_to_buffer(main_abs_l2_rem_gas_lo, Transcript::proof_data); + serialize_to_buffer(main_alu_in_tag, Transcript::proof_data); + serialize_to_buffer(main_bin_op_id, Transcript::proof_data); + serialize_to_buffer(main_call_ptr, Transcript::proof_data); + serialize_to_buffer(main_da_gas_op_cost, Transcript::proof_data); + serialize_to_buffer(main_da_gas_remaining, Transcript::proof_data); + serialize_to_buffer(main_da_out_of_gas, Transcript::proof_data); + serialize_to_buffer(main_ia, Transcript::proof_data); + serialize_to_buffer(main_ib, Transcript::proof_data); + serialize_to_buffer(main_ic, Transcript::proof_data); + serialize_to_buffer(main_id, Transcript::proof_data); + serialize_to_buffer(main_id_zero, Transcript::proof_data); + serialize_to_buffer(main_ind_addr_a, Transcript::proof_data); + serialize_to_buffer(main_ind_addr_b, Transcript::proof_data); + serialize_to_buffer(main_ind_addr_c, Transcript::proof_data); + serialize_to_buffer(main_ind_addr_d, Transcript::proof_data); + serialize_to_buffer(main_internal_return_ptr, Transcript::proof_data); + serialize_to_buffer(main_inv, Transcript::proof_data); + serialize_to_buffer(main_l2_gas_op_cost, Transcript::proof_data); + serialize_to_buffer(main_l2_gas_remaining, Transcript::proof_data); + serialize_to_buffer(main_l2_out_of_gas, Transcript::proof_data); + serialize_to_buffer(main_mem_addr_a, Transcript::proof_data); + serialize_to_buffer(main_mem_addr_b, Transcript::proof_data); + serialize_to_buffer(main_mem_addr_c, Transcript::proof_data); + serialize_to_buffer(main_mem_addr_d, Transcript::proof_data); + serialize_to_buffer(main_op_err, Transcript::proof_data); + serialize_to_buffer(main_opcode_val, Transcript::proof_data); + serialize_to_buffer(main_pc, Transcript::proof_data); + serialize_to_buffer(main_r_in_tag, Transcript::proof_data); + serialize_to_buffer(main_rwa, Transcript::proof_data); + serialize_to_buffer(main_rwb, Transcript::proof_data); + serialize_to_buffer(main_rwc, Transcript::proof_data); + serialize_to_buffer(main_rwd, Transcript::proof_data); + serialize_to_buffer(main_sel_alu, Transcript::proof_data); + serialize_to_buffer(main_sel_bin, Transcript::proof_data); + serialize_to_buffer(main_sel_gas_accounting_active, Transcript::proof_data); + serialize_to_buffer(main_sel_last, Transcript::proof_data); + serialize_to_buffer(main_sel_mem_op_a, Transcript::proof_data); + serialize_to_buffer(main_sel_mem_op_activate_gas, Transcript::proof_data); + serialize_to_buffer(main_sel_mem_op_b, Transcript::proof_data); + serialize_to_buffer(main_sel_mem_op_c, Transcript::proof_data); + serialize_to_buffer(main_sel_mem_op_d, Transcript::proof_data); + serialize_to_buffer(main_sel_mov_ia_to_ic, Transcript::proof_data); + serialize_to_buffer(main_sel_mov_ib_to_ic, Transcript::proof_data); + serialize_to_buffer(main_sel_op_add, Transcript::proof_data); + serialize_to_buffer(main_sel_op_address, Transcript::proof_data); + serialize_to_buffer(main_sel_op_and, Transcript::proof_data); + serialize_to_buffer(main_sel_op_block_number, Transcript::proof_data); + serialize_to_buffer(main_sel_op_cast, Transcript::proof_data); + serialize_to_buffer(main_sel_op_chain_id, Transcript::proof_data); + serialize_to_buffer(main_sel_op_cmov, Transcript::proof_data); + serialize_to_buffer(main_sel_op_coinbase, Transcript::proof_data); + serialize_to_buffer(main_sel_op_dagasleft, Transcript::proof_data); + serialize_to_buffer(main_sel_op_div, Transcript::proof_data); + serialize_to_buffer(main_sel_op_emit_l2_to_l1_msg, Transcript::proof_data); + serialize_to_buffer(main_sel_op_emit_note_hash, Transcript::proof_data); + serialize_to_buffer(main_sel_op_emit_nullifier, Transcript::proof_data); + serialize_to_buffer(main_sel_op_emit_unencrypted_log, Transcript::proof_data); + serialize_to_buffer(main_sel_op_eq, Transcript::proof_data); + serialize_to_buffer(main_sel_op_external_call, Transcript::proof_data); + serialize_to_buffer(main_sel_op_fdiv, Transcript::proof_data); + serialize_to_buffer(main_sel_op_fee_per_da_gas, Transcript::proof_data); + serialize_to_buffer(main_sel_op_fee_per_l2_gas, Transcript::proof_data); + serialize_to_buffer(main_sel_op_get_contract_instance, Transcript::proof_data); + serialize_to_buffer(main_sel_op_halt, Transcript::proof_data); + serialize_to_buffer(main_sel_op_internal_call, Transcript::proof_data); + serialize_to_buffer(main_sel_op_internal_return, Transcript::proof_data); + serialize_to_buffer(main_sel_op_jump, Transcript::proof_data); + serialize_to_buffer(main_sel_op_jumpi, Transcript::proof_data); + serialize_to_buffer(main_sel_op_keccak, Transcript::proof_data); + serialize_to_buffer(main_sel_op_l1_to_l2_msg_exists, Transcript::proof_data); + serialize_to_buffer(main_sel_op_l2gasleft, Transcript::proof_data); + serialize_to_buffer(main_sel_op_lt, Transcript::proof_data); + serialize_to_buffer(main_sel_op_lte, Transcript::proof_data); + serialize_to_buffer(main_sel_op_mov, Transcript::proof_data); + serialize_to_buffer(main_sel_op_mul, Transcript::proof_data); + serialize_to_buffer(main_sel_op_not, Transcript::proof_data); + serialize_to_buffer(main_sel_op_note_hash_exists, Transcript::proof_data); + serialize_to_buffer(main_sel_op_nullifier_exists, Transcript::proof_data); + serialize_to_buffer(main_sel_op_or, Transcript::proof_data); + serialize_to_buffer(main_sel_op_pedersen, Transcript::proof_data); + serialize_to_buffer(main_sel_op_poseidon2, Transcript::proof_data); + serialize_to_buffer(main_sel_op_radix_le, Transcript::proof_data); + serialize_to_buffer(main_sel_op_sender, Transcript::proof_data); + serialize_to_buffer(main_sel_op_sha256, Transcript::proof_data); + serialize_to_buffer(main_sel_op_shl, Transcript::proof_data); + serialize_to_buffer(main_sel_op_shr, Transcript::proof_data); + serialize_to_buffer(main_sel_op_sload, Transcript::proof_data); + serialize_to_buffer(main_sel_op_sstore, Transcript::proof_data); + serialize_to_buffer(main_sel_op_storage_address, Transcript::proof_data); + serialize_to_buffer(main_sel_op_sub, Transcript::proof_data); + serialize_to_buffer(main_sel_op_timestamp, Transcript::proof_data); + serialize_to_buffer(main_sel_op_transaction_fee, Transcript::proof_data); + serialize_to_buffer(main_sel_op_version, Transcript::proof_data); + serialize_to_buffer(main_sel_op_xor, Transcript::proof_data); + serialize_to_buffer(main_sel_q_kernel_lookup, Transcript::proof_data); + serialize_to_buffer(main_sel_q_kernel_output_lookup, Transcript::proof_data); + serialize_to_buffer(main_sel_resolve_ind_addr_a, Transcript::proof_data); + serialize_to_buffer(main_sel_resolve_ind_addr_b, Transcript::proof_data); + serialize_to_buffer(main_sel_resolve_ind_addr_c, Transcript::proof_data); + serialize_to_buffer(main_sel_resolve_ind_addr_d, Transcript::proof_data); + serialize_to_buffer(main_sel_rng_16, Transcript::proof_data); + serialize_to_buffer(main_sel_rng_8, Transcript::proof_data); + serialize_to_buffer(main_space_id, Transcript::proof_data); + serialize_to_buffer(main_table_pow_2, Transcript::proof_data); + serialize_to_buffer(main_tag_err, Transcript::proof_data); + serialize_to_buffer(main_w_in_tag, Transcript::proof_data); + serialize_to_buffer(mem_addr, Transcript::proof_data); + serialize_to_buffer(mem_clk, Transcript::proof_data); + serialize_to_buffer(mem_diff_hi, Transcript::proof_data); + serialize_to_buffer(mem_diff_lo, Transcript::proof_data); + serialize_to_buffer(mem_diff_mid, Transcript::proof_data); + serialize_to_buffer(mem_glob_addr, Transcript::proof_data); + serialize_to_buffer(mem_last, Transcript::proof_data); + serialize_to_buffer(mem_lastAccess, Transcript::proof_data); + serialize_to_buffer(mem_one_min_inv, Transcript::proof_data); + serialize_to_buffer(mem_r_in_tag, Transcript::proof_data); + serialize_to_buffer(mem_rw, Transcript::proof_data); + serialize_to_buffer(mem_sel_mem, Transcript::proof_data); + serialize_to_buffer(mem_sel_mov_ia_to_ic, Transcript::proof_data); + serialize_to_buffer(mem_sel_mov_ib_to_ic, Transcript::proof_data); + serialize_to_buffer(mem_sel_op_a, Transcript::proof_data); + serialize_to_buffer(mem_sel_op_b, Transcript::proof_data); + serialize_to_buffer(mem_sel_op_c, Transcript::proof_data); + serialize_to_buffer(mem_sel_op_cmov, Transcript::proof_data); + serialize_to_buffer(mem_sel_op_d, Transcript::proof_data); + serialize_to_buffer(mem_sel_resolve_ind_addr_a, Transcript::proof_data); + serialize_to_buffer(mem_sel_resolve_ind_addr_b, Transcript::proof_data); + serialize_to_buffer(mem_sel_resolve_ind_addr_c, Transcript::proof_data); + serialize_to_buffer(mem_sel_resolve_ind_addr_d, Transcript::proof_data); + serialize_to_buffer(mem_sel_rng_chk, Transcript::proof_data); + serialize_to_buffer(mem_skip_check_tag, Transcript::proof_data); + serialize_to_buffer(mem_space_id, Transcript::proof_data); + serialize_to_buffer(mem_tag, Transcript::proof_data); + serialize_to_buffer(mem_tag_err, Transcript::proof_data); + serialize_to_buffer(mem_tsp, Transcript::proof_data); + serialize_to_buffer(mem_val, Transcript::proof_data); + serialize_to_buffer(mem_w_in_tag, Transcript::proof_data); + serialize_to_buffer(pedersen_clk, Transcript::proof_data); + serialize_to_buffer(pedersen_input, Transcript::proof_data); + serialize_to_buffer(pedersen_output, Transcript::proof_data); + serialize_to_buffer(pedersen_sel_pedersen, Transcript::proof_data); + serialize_to_buffer(poseidon2_clk, Transcript::proof_data); + serialize_to_buffer(poseidon2_input, Transcript::proof_data); + serialize_to_buffer(poseidon2_output, Transcript::proof_data); + serialize_to_buffer(poseidon2_sel_poseidon_perm, Transcript::proof_data); + serialize_to_buffer(sha256_clk, Transcript::proof_data); + serialize_to_buffer(sha256_input, Transcript::proof_data); + serialize_to_buffer(sha256_output, Transcript::proof_data); + serialize_to_buffer(sha256_sel_sha256_compression, Transcript::proof_data); + serialize_to_buffer(sha256_state, Transcript::proof_data); serialize_to_buffer(perm_main_alu, Transcript::proof_data); serialize_to_buffer(perm_main_bin, Transcript::proof_data); serialize_to_buffer(perm_main_conv, Transcript::proof_data); @@ -4275,10 +4267,10 @@ class AvmFlavor { serialize_to_buffer(perm_main_mem_b, Transcript::proof_data); serialize_to_buffer(perm_main_mem_c, Transcript::proof_data); serialize_to_buffer(perm_main_mem_d, Transcript::proof_data); - serialize_to_buffer(perm_main_mem_ind_a, Transcript::proof_data); - serialize_to_buffer(perm_main_mem_ind_b, Transcript::proof_data); - serialize_to_buffer(perm_main_mem_ind_c, Transcript::proof_data); - serialize_to_buffer(perm_main_mem_ind_d, Transcript::proof_data); + serialize_to_buffer(perm_main_mem_ind_addr_a, Transcript::proof_data); + serialize_to_buffer(perm_main_mem_ind_addr_b, Transcript::proof_data); + serialize_to_buffer(perm_main_mem_ind_addr_c, Transcript::proof_data); + serialize_to_buffer(perm_main_mem_ind_addr_d, Transcript::proof_data); serialize_to_buffer(lookup_byte_lengths, Transcript::proof_data); serialize_to_buffer(lookup_byte_operations, Transcript::proof_data); serialize_to_buffer(lookup_opcode_gas, Transcript::proof_data); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp index 57ee78efa8c..2bdb385ef3f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp @@ -59,313 +59,306 @@ void AvmProver::execute_wire_commitments_round() // Commit to all polynomials (apart from logderivative inverse polynomials, which are committed to in the later // logderivative phase) - witness_commitments.avm_alu_a_hi = commitment_key->commit(key->avm_alu_a_hi); - witness_commitments.avm_alu_a_lo = commitment_key->commit(key->avm_alu_a_lo); - witness_commitments.avm_alu_alu_sel = commitment_key->commit(key->avm_alu_alu_sel); - witness_commitments.avm_alu_b_hi = commitment_key->commit(key->avm_alu_b_hi); - witness_commitments.avm_alu_b_lo = commitment_key->commit(key->avm_alu_b_lo); - witness_commitments.avm_alu_borrow = commitment_key->commit(key->avm_alu_borrow); - witness_commitments.avm_alu_cf = commitment_key->commit(key->avm_alu_cf); - witness_commitments.avm_alu_clk = commitment_key->commit(key->avm_alu_clk); - witness_commitments.avm_alu_cmp_rng_ctr = commitment_key->commit(key->avm_alu_cmp_rng_ctr); - witness_commitments.avm_alu_cmp_sel = commitment_key->commit(key->avm_alu_cmp_sel); - witness_commitments.avm_alu_div_rng_chk_selector = commitment_key->commit(key->avm_alu_div_rng_chk_selector); - witness_commitments.avm_alu_div_u16_r0 = commitment_key->commit(key->avm_alu_div_u16_r0); - witness_commitments.avm_alu_div_u16_r1 = commitment_key->commit(key->avm_alu_div_u16_r1); - witness_commitments.avm_alu_div_u16_r2 = commitment_key->commit(key->avm_alu_div_u16_r2); - witness_commitments.avm_alu_div_u16_r3 = commitment_key->commit(key->avm_alu_div_u16_r3); - witness_commitments.avm_alu_div_u16_r4 = commitment_key->commit(key->avm_alu_div_u16_r4); - witness_commitments.avm_alu_div_u16_r5 = commitment_key->commit(key->avm_alu_div_u16_r5); - witness_commitments.avm_alu_div_u16_r6 = commitment_key->commit(key->avm_alu_div_u16_r6); - witness_commitments.avm_alu_div_u16_r7 = commitment_key->commit(key->avm_alu_div_u16_r7); - witness_commitments.avm_alu_divisor_hi = commitment_key->commit(key->avm_alu_divisor_hi); - witness_commitments.avm_alu_divisor_lo = commitment_key->commit(key->avm_alu_divisor_lo); - witness_commitments.avm_alu_ff_tag = commitment_key->commit(key->avm_alu_ff_tag); - witness_commitments.avm_alu_ia = commitment_key->commit(key->avm_alu_ia); - witness_commitments.avm_alu_ib = commitment_key->commit(key->avm_alu_ib); - witness_commitments.avm_alu_ic = commitment_key->commit(key->avm_alu_ic); - witness_commitments.avm_alu_in_tag = commitment_key->commit(key->avm_alu_in_tag); - witness_commitments.avm_alu_op_add = commitment_key->commit(key->avm_alu_op_add); - witness_commitments.avm_alu_op_cast = commitment_key->commit(key->avm_alu_op_cast); - witness_commitments.avm_alu_op_cast_prev = commitment_key->commit(key->avm_alu_op_cast_prev); - witness_commitments.avm_alu_op_div = commitment_key->commit(key->avm_alu_op_div); - witness_commitments.avm_alu_op_div_a_lt_b = commitment_key->commit(key->avm_alu_op_div_a_lt_b); - witness_commitments.avm_alu_op_div_std = commitment_key->commit(key->avm_alu_op_div_std); - witness_commitments.avm_alu_op_eq = commitment_key->commit(key->avm_alu_op_eq); - witness_commitments.avm_alu_op_eq_diff_inv = commitment_key->commit(key->avm_alu_op_eq_diff_inv); - witness_commitments.avm_alu_op_lt = commitment_key->commit(key->avm_alu_op_lt); - witness_commitments.avm_alu_op_lte = commitment_key->commit(key->avm_alu_op_lte); - witness_commitments.avm_alu_op_mul = commitment_key->commit(key->avm_alu_op_mul); - witness_commitments.avm_alu_op_not = commitment_key->commit(key->avm_alu_op_not); - witness_commitments.avm_alu_op_shl = commitment_key->commit(key->avm_alu_op_shl); - witness_commitments.avm_alu_op_shr = commitment_key->commit(key->avm_alu_op_shr); - witness_commitments.avm_alu_op_sub = commitment_key->commit(key->avm_alu_op_sub); - witness_commitments.avm_alu_p_a_borrow = commitment_key->commit(key->avm_alu_p_a_borrow); - witness_commitments.avm_alu_p_b_borrow = commitment_key->commit(key->avm_alu_p_b_borrow); - witness_commitments.avm_alu_p_sub_a_hi = commitment_key->commit(key->avm_alu_p_sub_a_hi); - witness_commitments.avm_alu_p_sub_a_lo = commitment_key->commit(key->avm_alu_p_sub_a_lo); - witness_commitments.avm_alu_p_sub_b_hi = commitment_key->commit(key->avm_alu_p_sub_b_hi); - witness_commitments.avm_alu_p_sub_b_lo = commitment_key->commit(key->avm_alu_p_sub_b_lo); - witness_commitments.avm_alu_partial_prod_hi = commitment_key->commit(key->avm_alu_partial_prod_hi); - witness_commitments.avm_alu_partial_prod_lo = commitment_key->commit(key->avm_alu_partial_prod_lo); - witness_commitments.avm_alu_quotient_hi = commitment_key->commit(key->avm_alu_quotient_hi); - witness_commitments.avm_alu_quotient_lo = commitment_key->commit(key->avm_alu_quotient_lo); - witness_commitments.avm_alu_remainder = commitment_key->commit(key->avm_alu_remainder); - witness_commitments.avm_alu_res_hi = commitment_key->commit(key->avm_alu_res_hi); - witness_commitments.avm_alu_res_lo = commitment_key->commit(key->avm_alu_res_lo); - witness_commitments.avm_alu_rng_chk_lookup_selector = commitment_key->commit(key->avm_alu_rng_chk_lookup_selector); - witness_commitments.avm_alu_rng_chk_sel = commitment_key->commit(key->avm_alu_rng_chk_sel); - witness_commitments.avm_alu_shift_lt_bit_len = commitment_key->commit(key->avm_alu_shift_lt_bit_len); - witness_commitments.avm_alu_shift_sel = commitment_key->commit(key->avm_alu_shift_sel); - witness_commitments.avm_alu_t_sub_s_bits = commitment_key->commit(key->avm_alu_t_sub_s_bits); - witness_commitments.avm_alu_two_pow_s = commitment_key->commit(key->avm_alu_two_pow_s); - witness_commitments.avm_alu_two_pow_t_sub_s = commitment_key->commit(key->avm_alu_two_pow_t_sub_s); - witness_commitments.avm_alu_u128_tag = commitment_key->commit(key->avm_alu_u128_tag); - witness_commitments.avm_alu_u16_r0 = commitment_key->commit(key->avm_alu_u16_r0); - witness_commitments.avm_alu_u16_r1 = commitment_key->commit(key->avm_alu_u16_r1); - witness_commitments.avm_alu_u16_r10 = commitment_key->commit(key->avm_alu_u16_r10); - witness_commitments.avm_alu_u16_r11 = commitment_key->commit(key->avm_alu_u16_r11); - witness_commitments.avm_alu_u16_r12 = commitment_key->commit(key->avm_alu_u16_r12); - witness_commitments.avm_alu_u16_r13 = commitment_key->commit(key->avm_alu_u16_r13); - witness_commitments.avm_alu_u16_r14 = commitment_key->commit(key->avm_alu_u16_r14); - witness_commitments.avm_alu_u16_r2 = commitment_key->commit(key->avm_alu_u16_r2); - witness_commitments.avm_alu_u16_r3 = commitment_key->commit(key->avm_alu_u16_r3); - witness_commitments.avm_alu_u16_r4 = commitment_key->commit(key->avm_alu_u16_r4); - witness_commitments.avm_alu_u16_r5 = commitment_key->commit(key->avm_alu_u16_r5); - witness_commitments.avm_alu_u16_r6 = commitment_key->commit(key->avm_alu_u16_r6); - witness_commitments.avm_alu_u16_r7 = commitment_key->commit(key->avm_alu_u16_r7); - witness_commitments.avm_alu_u16_r8 = commitment_key->commit(key->avm_alu_u16_r8); - witness_commitments.avm_alu_u16_r9 = commitment_key->commit(key->avm_alu_u16_r9); - witness_commitments.avm_alu_u16_tag = commitment_key->commit(key->avm_alu_u16_tag); - witness_commitments.avm_alu_u32_tag = commitment_key->commit(key->avm_alu_u32_tag); - witness_commitments.avm_alu_u64_tag = commitment_key->commit(key->avm_alu_u64_tag); - witness_commitments.avm_alu_u8_r0 = commitment_key->commit(key->avm_alu_u8_r0); - witness_commitments.avm_alu_u8_r1 = commitment_key->commit(key->avm_alu_u8_r1); - witness_commitments.avm_alu_u8_tag = commitment_key->commit(key->avm_alu_u8_tag); - witness_commitments.avm_binary_acc_ia = commitment_key->commit(key->avm_binary_acc_ia); - witness_commitments.avm_binary_acc_ib = commitment_key->commit(key->avm_binary_acc_ib); - witness_commitments.avm_binary_acc_ic = commitment_key->commit(key->avm_binary_acc_ic); - witness_commitments.avm_binary_bin_sel = commitment_key->commit(key->avm_binary_bin_sel); - witness_commitments.avm_binary_clk = commitment_key->commit(key->avm_binary_clk); - witness_commitments.avm_binary_ia_bytes = commitment_key->commit(key->avm_binary_ia_bytes); - witness_commitments.avm_binary_ib_bytes = commitment_key->commit(key->avm_binary_ib_bytes); - witness_commitments.avm_binary_ic_bytes = commitment_key->commit(key->avm_binary_ic_bytes); - witness_commitments.avm_binary_in_tag = commitment_key->commit(key->avm_binary_in_tag); - witness_commitments.avm_binary_mem_tag_ctr = commitment_key->commit(key->avm_binary_mem_tag_ctr); - witness_commitments.avm_binary_mem_tag_ctr_inv = commitment_key->commit(key->avm_binary_mem_tag_ctr_inv); - witness_commitments.avm_binary_op_id = commitment_key->commit(key->avm_binary_op_id); - witness_commitments.avm_binary_start = commitment_key->commit(key->avm_binary_start); - witness_commitments.avm_byte_lookup_bin_sel = commitment_key->commit(key->avm_byte_lookup_bin_sel); - witness_commitments.avm_byte_lookup_table_byte_lengths = - commitment_key->commit(key->avm_byte_lookup_table_byte_lengths); - witness_commitments.avm_byte_lookup_table_in_tags = commitment_key->commit(key->avm_byte_lookup_table_in_tags); - witness_commitments.avm_byte_lookup_table_input_a = commitment_key->commit(key->avm_byte_lookup_table_input_a); - witness_commitments.avm_byte_lookup_table_input_b = commitment_key->commit(key->avm_byte_lookup_table_input_b); - witness_commitments.avm_byte_lookup_table_op_id = commitment_key->commit(key->avm_byte_lookup_table_op_id); - witness_commitments.avm_byte_lookup_table_output = commitment_key->commit(key->avm_byte_lookup_table_output); - witness_commitments.avm_conversion_clk = commitment_key->commit(key->avm_conversion_clk); - witness_commitments.avm_conversion_input = commitment_key->commit(key->avm_conversion_input); - witness_commitments.avm_conversion_num_limbs = commitment_key->commit(key->avm_conversion_num_limbs); - witness_commitments.avm_conversion_radix = commitment_key->commit(key->avm_conversion_radix); - witness_commitments.avm_conversion_to_radix_le_sel = commitment_key->commit(key->avm_conversion_to_radix_le_sel); - witness_commitments.avm_gas_da_gas_fixed_table = commitment_key->commit(key->avm_gas_da_gas_fixed_table); - witness_commitments.avm_gas_gas_cost_sel = commitment_key->commit(key->avm_gas_gas_cost_sel); - witness_commitments.avm_gas_l2_gas_fixed_table = commitment_key->commit(key->avm_gas_l2_gas_fixed_table); - witness_commitments.avm_keccakf1600_clk = commitment_key->commit(key->avm_keccakf1600_clk); - witness_commitments.avm_keccakf1600_input = commitment_key->commit(key->avm_keccakf1600_input); - witness_commitments.avm_keccakf1600_keccakf1600_sel = commitment_key->commit(key->avm_keccakf1600_keccakf1600_sel); - witness_commitments.avm_keccakf1600_output = commitment_key->commit(key->avm_keccakf1600_output); - witness_commitments.avm_kernel_emit_l2_to_l1_msg_write_offset = - commitment_key->commit(key->avm_kernel_emit_l2_to_l1_msg_write_offset); - witness_commitments.avm_kernel_emit_note_hash_write_offset = - commitment_key->commit(key->avm_kernel_emit_note_hash_write_offset); - witness_commitments.avm_kernel_emit_nullifier_write_offset = - commitment_key->commit(key->avm_kernel_emit_nullifier_write_offset); - witness_commitments.avm_kernel_emit_unencrypted_log_write_offset = - commitment_key->commit(key->avm_kernel_emit_unencrypted_log_write_offset); - witness_commitments.avm_kernel_kernel_in_offset = commitment_key->commit(key->avm_kernel_kernel_in_offset); - witness_commitments.avm_kernel_kernel_inputs = commitment_key->commit(key->avm_kernel_kernel_inputs); - witness_commitments.avm_kernel_kernel_metadata_out = commitment_key->commit(key->avm_kernel_kernel_metadata_out); - witness_commitments.avm_kernel_kernel_out_offset = commitment_key->commit(key->avm_kernel_kernel_out_offset); - witness_commitments.avm_kernel_kernel_side_effect_out = - commitment_key->commit(key->avm_kernel_kernel_side_effect_out); - witness_commitments.avm_kernel_kernel_value_out = commitment_key->commit(key->avm_kernel_kernel_value_out); - witness_commitments.avm_kernel_l1_to_l2_msg_exists_write_offset = - commitment_key->commit(key->avm_kernel_l1_to_l2_msg_exists_write_offset); - witness_commitments.avm_kernel_note_hash_exist_write_offset = - commitment_key->commit(key->avm_kernel_note_hash_exist_write_offset); - witness_commitments.avm_kernel_nullifier_exists_write_offset = - commitment_key->commit(key->avm_kernel_nullifier_exists_write_offset); - witness_commitments.avm_kernel_nullifier_non_exists_write_offset = - commitment_key->commit(key->avm_kernel_nullifier_non_exists_write_offset); - witness_commitments.avm_kernel_q_public_input_kernel_add_to_table = - commitment_key->commit(key->avm_kernel_q_public_input_kernel_add_to_table); - witness_commitments.avm_kernel_q_public_input_kernel_out_add_to_table = - commitment_key->commit(key->avm_kernel_q_public_input_kernel_out_add_to_table); - witness_commitments.avm_kernel_side_effect_counter = commitment_key->commit(key->avm_kernel_side_effect_counter); - witness_commitments.avm_kernel_sload_write_offset = commitment_key->commit(key->avm_kernel_sload_write_offset); - witness_commitments.avm_kernel_sstore_write_offset = commitment_key->commit(key->avm_kernel_sstore_write_offset); - witness_commitments.avm_main_abs_da_rem_gas_hi = commitment_key->commit(key->avm_main_abs_da_rem_gas_hi); - witness_commitments.avm_main_abs_da_rem_gas_lo = commitment_key->commit(key->avm_main_abs_da_rem_gas_lo); - witness_commitments.avm_main_abs_l2_rem_gas_hi = commitment_key->commit(key->avm_main_abs_l2_rem_gas_hi); - witness_commitments.avm_main_abs_l2_rem_gas_lo = commitment_key->commit(key->avm_main_abs_l2_rem_gas_lo); - witness_commitments.avm_main_alu_in_tag = commitment_key->commit(key->avm_main_alu_in_tag); - witness_commitments.avm_main_alu_sel = commitment_key->commit(key->avm_main_alu_sel); - witness_commitments.avm_main_bin_op_id = commitment_key->commit(key->avm_main_bin_op_id); - witness_commitments.avm_main_bin_sel = commitment_key->commit(key->avm_main_bin_sel); - witness_commitments.avm_main_call_ptr = commitment_key->commit(key->avm_main_call_ptr); - witness_commitments.avm_main_da_gas_op = commitment_key->commit(key->avm_main_da_gas_op); - witness_commitments.avm_main_da_gas_remaining = commitment_key->commit(key->avm_main_da_gas_remaining); - witness_commitments.avm_main_da_out_of_gas = commitment_key->commit(key->avm_main_da_out_of_gas); - witness_commitments.avm_main_gas_cost_active = commitment_key->commit(key->avm_main_gas_cost_active); - witness_commitments.avm_main_ia = commitment_key->commit(key->avm_main_ia); - witness_commitments.avm_main_ib = commitment_key->commit(key->avm_main_ib); - witness_commitments.avm_main_ic = commitment_key->commit(key->avm_main_ic); - witness_commitments.avm_main_id = commitment_key->commit(key->avm_main_id); - witness_commitments.avm_main_id_zero = commitment_key->commit(key->avm_main_id_zero); - witness_commitments.avm_main_ind_a = commitment_key->commit(key->avm_main_ind_a); - witness_commitments.avm_main_ind_b = commitment_key->commit(key->avm_main_ind_b); - witness_commitments.avm_main_ind_c = commitment_key->commit(key->avm_main_ind_c); - witness_commitments.avm_main_ind_d = commitment_key->commit(key->avm_main_ind_d); - witness_commitments.avm_main_ind_op_a = commitment_key->commit(key->avm_main_ind_op_a); - witness_commitments.avm_main_ind_op_b = commitment_key->commit(key->avm_main_ind_op_b); - witness_commitments.avm_main_ind_op_c = commitment_key->commit(key->avm_main_ind_op_c); - witness_commitments.avm_main_ind_op_d = commitment_key->commit(key->avm_main_ind_op_d); - witness_commitments.avm_main_internal_return_ptr = commitment_key->commit(key->avm_main_internal_return_ptr); - witness_commitments.avm_main_inv = commitment_key->commit(key->avm_main_inv); - witness_commitments.avm_main_l2_gas_op = commitment_key->commit(key->avm_main_l2_gas_op); - witness_commitments.avm_main_l2_gas_remaining = commitment_key->commit(key->avm_main_l2_gas_remaining); - witness_commitments.avm_main_l2_out_of_gas = commitment_key->commit(key->avm_main_l2_out_of_gas); - witness_commitments.avm_main_last = commitment_key->commit(key->avm_main_last); - witness_commitments.avm_main_mem_idx_a = commitment_key->commit(key->avm_main_mem_idx_a); - witness_commitments.avm_main_mem_idx_b = commitment_key->commit(key->avm_main_mem_idx_b); - witness_commitments.avm_main_mem_idx_c = commitment_key->commit(key->avm_main_mem_idx_c); - witness_commitments.avm_main_mem_idx_d = commitment_key->commit(key->avm_main_mem_idx_d); - witness_commitments.avm_main_mem_op_a = commitment_key->commit(key->avm_main_mem_op_a); - witness_commitments.avm_main_mem_op_activate_gas = commitment_key->commit(key->avm_main_mem_op_activate_gas); - witness_commitments.avm_main_mem_op_b = commitment_key->commit(key->avm_main_mem_op_b); - witness_commitments.avm_main_mem_op_c = commitment_key->commit(key->avm_main_mem_op_c); - witness_commitments.avm_main_mem_op_d = commitment_key->commit(key->avm_main_mem_op_d); - witness_commitments.avm_main_op_err = commitment_key->commit(key->avm_main_op_err); - witness_commitments.avm_main_opcode_val = commitment_key->commit(key->avm_main_opcode_val); - witness_commitments.avm_main_pc = commitment_key->commit(key->avm_main_pc); - witness_commitments.avm_main_q_kernel_lookup = commitment_key->commit(key->avm_main_q_kernel_lookup); - witness_commitments.avm_main_q_kernel_output_lookup = commitment_key->commit(key->avm_main_q_kernel_output_lookup); - witness_commitments.avm_main_r_in_tag = commitment_key->commit(key->avm_main_r_in_tag); - witness_commitments.avm_main_rwa = commitment_key->commit(key->avm_main_rwa); - witness_commitments.avm_main_rwb = commitment_key->commit(key->avm_main_rwb); - witness_commitments.avm_main_rwc = commitment_key->commit(key->avm_main_rwc); - witness_commitments.avm_main_rwd = commitment_key->commit(key->avm_main_rwd); - witness_commitments.avm_main_sel_cmov = commitment_key->commit(key->avm_main_sel_cmov); - witness_commitments.avm_main_sel_external_call = commitment_key->commit(key->avm_main_sel_external_call); - witness_commitments.avm_main_sel_halt = commitment_key->commit(key->avm_main_sel_halt); - witness_commitments.avm_main_sel_internal_call = commitment_key->commit(key->avm_main_sel_internal_call); - witness_commitments.avm_main_sel_internal_return = commitment_key->commit(key->avm_main_sel_internal_return); - witness_commitments.avm_main_sel_jump = commitment_key->commit(key->avm_main_sel_jump); - witness_commitments.avm_main_sel_jumpi = commitment_key->commit(key->avm_main_sel_jumpi); - witness_commitments.avm_main_sel_mov = commitment_key->commit(key->avm_main_sel_mov); - witness_commitments.avm_main_sel_mov_a = commitment_key->commit(key->avm_main_sel_mov_a); - witness_commitments.avm_main_sel_mov_b = commitment_key->commit(key->avm_main_sel_mov_b); - witness_commitments.avm_main_sel_op_add = commitment_key->commit(key->avm_main_sel_op_add); - witness_commitments.avm_main_sel_op_address = commitment_key->commit(key->avm_main_sel_op_address); - witness_commitments.avm_main_sel_op_and = commitment_key->commit(key->avm_main_sel_op_and); - witness_commitments.avm_main_sel_op_block_number = commitment_key->commit(key->avm_main_sel_op_block_number); - witness_commitments.avm_main_sel_op_cast = commitment_key->commit(key->avm_main_sel_op_cast); - witness_commitments.avm_main_sel_op_chain_id = commitment_key->commit(key->avm_main_sel_op_chain_id); - witness_commitments.avm_main_sel_op_coinbase = commitment_key->commit(key->avm_main_sel_op_coinbase); - witness_commitments.avm_main_sel_op_dagasleft = commitment_key->commit(key->avm_main_sel_op_dagasleft); - witness_commitments.avm_main_sel_op_div = commitment_key->commit(key->avm_main_sel_op_div); - witness_commitments.avm_main_sel_op_emit_l2_to_l1_msg = - commitment_key->commit(key->avm_main_sel_op_emit_l2_to_l1_msg); - witness_commitments.avm_main_sel_op_emit_note_hash = commitment_key->commit(key->avm_main_sel_op_emit_note_hash); - witness_commitments.avm_main_sel_op_emit_nullifier = commitment_key->commit(key->avm_main_sel_op_emit_nullifier); - witness_commitments.avm_main_sel_op_emit_unencrypted_log = - commitment_key->commit(key->avm_main_sel_op_emit_unencrypted_log); - witness_commitments.avm_main_sel_op_eq = commitment_key->commit(key->avm_main_sel_op_eq); - witness_commitments.avm_main_sel_op_fdiv = commitment_key->commit(key->avm_main_sel_op_fdiv); - witness_commitments.avm_main_sel_op_fee_per_da_gas = commitment_key->commit(key->avm_main_sel_op_fee_per_da_gas); - witness_commitments.avm_main_sel_op_fee_per_l2_gas = commitment_key->commit(key->avm_main_sel_op_fee_per_l2_gas); - witness_commitments.avm_main_sel_op_get_contract_instance = - commitment_key->commit(key->avm_main_sel_op_get_contract_instance); - witness_commitments.avm_main_sel_op_keccak = commitment_key->commit(key->avm_main_sel_op_keccak); - witness_commitments.avm_main_sel_op_l1_to_l2_msg_exists = - commitment_key->commit(key->avm_main_sel_op_l1_to_l2_msg_exists); - witness_commitments.avm_main_sel_op_l2gasleft = commitment_key->commit(key->avm_main_sel_op_l2gasleft); - witness_commitments.avm_main_sel_op_lt = commitment_key->commit(key->avm_main_sel_op_lt); - witness_commitments.avm_main_sel_op_lte = commitment_key->commit(key->avm_main_sel_op_lte); - witness_commitments.avm_main_sel_op_mul = commitment_key->commit(key->avm_main_sel_op_mul); - witness_commitments.avm_main_sel_op_not = commitment_key->commit(key->avm_main_sel_op_not); - witness_commitments.avm_main_sel_op_note_hash_exists = - commitment_key->commit(key->avm_main_sel_op_note_hash_exists); - witness_commitments.avm_main_sel_op_nullifier_exists = - commitment_key->commit(key->avm_main_sel_op_nullifier_exists); - witness_commitments.avm_main_sel_op_or = commitment_key->commit(key->avm_main_sel_op_or); - witness_commitments.avm_main_sel_op_pedersen = commitment_key->commit(key->avm_main_sel_op_pedersen); - witness_commitments.avm_main_sel_op_poseidon2 = commitment_key->commit(key->avm_main_sel_op_poseidon2); - witness_commitments.avm_main_sel_op_radix_le = commitment_key->commit(key->avm_main_sel_op_radix_le); - witness_commitments.avm_main_sel_op_sender = commitment_key->commit(key->avm_main_sel_op_sender); - witness_commitments.avm_main_sel_op_sha256 = commitment_key->commit(key->avm_main_sel_op_sha256); - witness_commitments.avm_main_sel_op_shl = commitment_key->commit(key->avm_main_sel_op_shl); - witness_commitments.avm_main_sel_op_shr = commitment_key->commit(key->avm_main_sel_op_shr); - witness_commitments.avm_main_sel_op_sload = commitment_key->commit(key->avm_main_sel_op_sload); - witness_commitments.avm_main_sel_op_sstore = commitment_key->commit(key->avm_main_sel_op_sstore); - witness_commitments.avm_main_sel_op_storage_address = commitment_key->commit(key->avm_main_sel_op_storage_address); - witness_commitments.avm_main_sel_op_sub = commitment_key->commit(key->avm_main_sel_op_sub); - witness_commitments.avm_main_sel_op_timestamp = commitment_key->commit(key->avm_main_sel_op_timestamp); - witness_commitments.avm_main_sel_op_transaction_fee = commitment_key->commit(key->avm_main_sel_op_transaction_fee); - witness_commitments.avm_main_sel_op_version = commitment_key->commit(key->avm_main_sel_op_version); - witness_commitments.avm_main_sel_op_xor = commitment_key->commit(key->avm_main_sel_op_xor); - witness_commitments.avm_main_sel_rng_16 = commitment_key->commit(key->avm_main_sel_rng_16); - witness_commitments.avm_main_sel_rng_8 = commitment_key->commit(key->avm_main_sel_rng_8); - witness_commitments.avm_main_space_id = commitment_key->commit(key->avm_main_space_id); - witness_commitments.avm_main_table_pow_2 = commitment_key->commit(key->avm_main_table_pow_2); - witness_commitments.avm_main_tag_err = commitment_key->commit(key->avm_main_tag_err); - witness_commitments.avm_main_w_in_tag = commitment_key->commit(key->avm_main_w_in_tag); - witness_commitments.avm_mem_addr = commitment_key->commit(key->avm_mem_addr); - witness_commitments.avm_mem_clk = commitment_key->commit(key->avm_mem_clk); - witness_commitments.avm_mem_diff_hi = commitment_key->commit(key->avm_mem_diff_hi); - witness_commitments.avm_mem_diff_lo = commitment_key->commit(key->avm_mem_diff_lo); - witness_commitments.avm_mem_diff_mid = commitment_key->commit(key->avm_mem_diff_mid); - witness_commitments.avm_mem_glob_addr = commitment_key->commit(key->avm_mem_glob_addr); - witness_commitments.avm_mem_ind_op_a = commitment_key->commit(key->avm_mem_ind_op_a); - witness_commitments.avm_mem_ind_op_b = commitment_key->commit(key->avm_mem_ind_op_b); - witness_commitments.avm_mem_ind_op_c = commitment_key->commit(key->avm_mem_ind_op_c); - witness_commitments.avm_mem_ind_op_d = commitment_key->commit(key->avm_mem_ind_op_d); - witness_commitments.avm_mem_last = commitment_key->commit(key->avm_mem_last); - witness_commitments.avm_mem_lastAccess = commitment_key->commit(key->avm_mem_lastAccess); - witness_commitments.avm_mem_mem_sel = commitment_key->commit(key->avm_mem_mem_sel); - witness_commitments.avm_mem_one_min_inv = commitment_key->commit(key->avm_mem_one_min_inv); - witness_commitments.avm_mem_op_a = commitment_key->commit(key->avm_mem_op_a); - witness_commitments.avm_mem_op_b = commitment_key->commit(key->avm_mem_op_b); - witness_commitments.avm_mem_op_c = commitment_key->commit(key->avm_mem_op_c); - witness_commitments.avm_mem_op_d = commitment_key->commit(key->avm_mem_op_d); - witness_commitments.avm_mem_r_in_tag = commitment_key->commit(key->avm_mem_r_in_tag); - witness_commitments.avm_mem_rng_chk_sel = commitment_key->commit(key->avm_mem_rng_chk_sel); - witness_commitments.avm_mem_rw = commitment_key->commit(key->avm_mem_rw); - witness_commitments.avm_mem_sel_cmov = commitment_key->commit(key->avm_mem_sel_cmov); - witness_commitments.avm_mem_sel_mov_a = commitment_key->commit(key->avm_mem_sel_mov_a); - witness_commitments.avm_mem_sel_mov_b = commitment_key->commit(key->avm_mem_sel_mov_b); - witness_commitments.avm_mem_skip_check_tag = commitment_key->commit(key->avm_mem_skip_check_tag); - witness_commitments.avm_mem_space_id = commitment_key->commit(key->avm_mem_space_id); - witness_commitments.avm_mem_tag = commitment_key->commit(key->avm_mem_tag); - witness_commitments.avm_mem_tag_err = commitment_key->commit(key->avm_mem_tag_err); - witness_commitments.avm_mem_tsp = commitment_key->commit(key->avm_mem_tsp); - witness_commitments.avm_mem_val = commitment_key->commit(key->avm_mem_val); - witness_commitments.avm_mem_w_in_tag = commitment_key->commit(key->avm_mem_w_in_tag); - witness_commitments.avm_pedersen_clk = commitment_key->commit(key->avm_pedersen_clk); - witness_commitments.avm_pedersen_input = commitment_key->commit(key->avm_pedersen_input); - witness_commitments.avm_pedersen_output = commitment_key->commit(key->avm_pedersen_output); - witness_commitments.avm_pedersen_pedersen_sel = commitment_key->commit(key->avm_pedersen_pedersen_sel); - witness_commitments.avm_poseidon2_clk = commitment_key->commit(key->avm_poseidon2_clk); - witness_commitments.avm_poseidon2_input = commitment_key->commit(key->avm_poseidon2_input); - witness_commitments.avm_poseidon2_output = commitment_key->commit(key->avm_poseidon2_output); - witness_commitments.avm_poseidon2_poseidon_perm_sel = commitment_key->commit(key->avm_poseidon2_poseidon_perm_sel); - witness_commitments.avm_sha256_clk = commitment_key->commit(key->avm_sha256_clk); - witness_commitments.avm_sha256_input = commitment_key->commit(key->avm_sha256_input); - witness_commitments.avm_sha256_output = commitment_key->commit(key->avm_sha256_output); - witness_commitments.avm_sha256_sha256_compression_sel = - commitment_key->commit(key->avm_sha256_sha256_compression_sel); - witness_commitments.avm_sha256_state = commitment_key->commit(key->avm_sha256_state); + witness_commitments.alu_a_hi = commitment_key->commit(key->alu_a_hi); + witness_commitments.alu_a_lo = commitment_key->commit(key->alu_a_lo); + witness_commitments.alu_b_hi = commitment_key->commit(key->alu_b_hi); + witness_commitments.alu_b_lo = commitment_key->commit(key->alu_b_lo); + witness_commitments.alu_borrow = commitment_key->commit(key->alu_borrow); + witness_commitments.alu_cf = commitment_key->commit(key->alu_cf); + witness_commitments.alu_clk = commitment_key->commit(key->alu_clk); + witness_commitments.alu_cmp_rng_ctr = commitment_key->commit(key->alu_cmp_rng_ctr); + witness_commitments.alu_div_u16_r0 = commitment_key->commit(key->alu_div_u16_r0); + witness_commitments.alu_div_u16_r1 = commitment_key->commit(key->alu_div_u16_r1); + witness_commitments.alu_div_u16_r2 = commitment_key->commit(key->alu_div_u16_r2); + witness_commitments.alu_div_u16_r3 = commitment_key->commit(key->alu_div_u16_r3); + witness_commitments.alu_div_u16_r4 = commitment_key->commit(key->alu_div_u16_r4); + witness_commitments.alu_div_u16_r5 = commitment_key->commit(key->alu_div_u16_r5); + witness_commitments.alu_div_u16_r6 = commitment_key->commit(key->alu_div_u16_r6); + witness_commitments.alu_div_u16_r7 = commitment_key->commit(key->alu_div_u16_r7); + witness_commitments.alu_divisor_hi = commitment_key->commit(key->alu_divisor_hi); + witness_commitments.alu_divisor_lo = commitment_key->commit(key->alu_divisor_lo); + witness_commitments.alu_ff_tag = commitment_key->commit(key->alu_ff_tag); + witness_commitments.alu_ia = commitment_key->commit(key->alu_ia); + witness_commitments.alu_ib = commitment_key->commit(key->alu_ib); + witness_commitments.alu_ic = commitment_key->commit(key->alu_ic); + witness_commitments.alu_in_tag = commitment_key->commit(key->alu_in_tag); + witness_commitments.alu_op_add = commitment_key->commit(key->alu_op_add); + witness_commitments.alu_op_cast = commitment_key->commit(key->alu_op_cast); + witness_commitments.alu_op_cast_prev = commitment_key->commit(key->alu_op_cast_prev); + witness_commitments.alu_op_div = commitment_key->commit(key->alu_op_div); + witness_commitments.alu_op_div_a_lt_b = commitment_key->commit(key->alu_op_div_a_lt_b); + witness_commitments.alu_op_div_std = commitment_key->commit(key->alu_op_div_std); + witness_commitments.alu_op_eq = commitment_key->commit(key->alu_op_eq); + witness_commitments.alu_op_eq_diff_inv = commitment_key->commit(key->alu_op_eq_diff_inv); + witness_commitments.alu_op_lt = commitment_key->commit(key->alu_op_lt); + witness_commitments.alu_op_lte = commitment_key->commit(key->alu_op_lte); + witness_commitments.alu_op_mul = commitment_key->commit(key->alu_op_mul); + witness_commitments.alu_op_not = commitment_key->commit(key->alu_op_not); + witness_commitments.alu_op_shl = commitment_key->commit(key->alu_op_shl); + witness_commitments.alu_op_shr = commitment_key->commit(key->alu_op_shr); + witness_commitments.alu_op_sub = commitment_key->commit(key->alu_op_sub); + witness_commitments.alu_p_a_borrow = commitment_key->commit(key->alu_p_a_borrow); + witness_commitments.alu_p_b_borrow = commitment_key->commit(key->alu_p_b_borrow); + witness_commitments.alu_p_sub_a_hi = commitment_key->commit(key->alu_p_sub_a_hi); + witness_commitments.alu_p_sub_a_lo = commitment_key->commit(key->alu_p_sub_a_lo); + witness_commitments.alu_p_sub_b_hi = commitment_key->commit(key->alu_p_sub_b_hi); + witness_commitments.alu_p_sub_b_lo = commitment_key->commit(key->alu_p_sub_b_lo); + witness_commitments.alu_partial_prod_hi = commitment_key->commit(key->alu_partial_prod_hi); + witness_commitments.alu_partial_prod_lo = commitment_key->commit(key->alu_partial_prod_lo); + witness_commitments.alu_quotient_hi = commitment_key->commit(key->alu_quotient_hi); + witness_commitments.alu_quotient_lo = commitment_key->commit(key->alu_quotient_lo); + witness_commitments.alu_remainder = commitment_key->commit(key->alu_remainder); + witness_commitments.alu_res_hi = commitment_key->commit(key->alu_res_hi); + witness_commitments.alu_res_lo = commitment_key->commit(key->alu_res_lo); + witness_commitments.alu_sel_alu = commitment_key->commit(key->alu_sel_alu); + witness_commitments.alu_sel_cmp = commitment_key->commit(key->alu_sel_cmp); + witness_commitments.alu_sel_div_rng_chk = commitment_key->commit(key->alu_sel_div_rng_chk); + witness_commitments.alu_sel_rng_chk = commitment_key->commit(key->alu_sel_rng_chk); + witness_commitments.alu_sel_rng_chk_lookup = commitment_key->commit(key->alu_sel_rng_chk_lookup); + witness_commitments.alu_sel_shift_which = commitment_key->commit(key->alu_sel_shift_which); + witness_commitments.alu_shift_lt_bit_len = commitment_key->commit(key->alu_shift_lt_bit_len); + witness_commitments.alu_t_sub_s_bits = commitment_key->commit(key->alu_t_sub_s_bits); + witness_commitments.alu_two_pow_s = commitment_key->commit(key->alu_two_pow_s); + witness_commitments.alu_two_pow_t_sub_s = commitment_key->commit(key->alu_two_pow_t_sub_s); + witness_commitments.alu_u128_tag = commitment_key->commit(key->alu_u128_tag); + witness_commitments.alu_u16_r0 = commitment_key->commit(key->alu_u16_r0); + witness_commitments.alu_u16_r1 = commitment_key->commit(key->alu_u16_r1); + witness_commitments.alu_u16_r10 = commitment_key->commit(key->alu_u16_r10); + witness_commitments.alu_u16_r11 = commitment_key->commit(key->alu_u16_r11); + witness_commitments.alu_u16_r12 = commitment_key->commit(key->alu_u16_r12); + witness_commitments.alu_u16_r13 = commitment_key->commit(key->alu_u16_r13); + witness_commitments.alu_u16_r14 = commitment_key->commit(key->alu_u16_r14); + witness_commitments.alu_u16_r2 = commitment_key->commit(key->alu_u16_r2); + witness_commitments.alu_u16_r3 = commitment_key->commit(key->alu_u16_r3); + witness_commitments.alu_u16_r4 = commitment_key->commit(key->alu_u16_r4); + witness_commitments.alu_u16_r5 = commitment_key->commit(key->alu_u16_r5); + witness_commitments.alu_u16_r6 = commitment_key->commit(key->alu_u16_r6); + witness_commitments.alu_u16_r7 = commitment_key->commit(key->alu_u16_r7); + witness_commitments.alu_u16_r8 = commitment_key->commit(key->alu_u16_r8); + witness_commitments.alu_u16_r9 = commitment_key->commit(key->alu_u16_r9); + witness_commitments.alu_u16_tag = commitment_key->commit(key->alu_u16_tag); + witness_commitments.alu_u32_tag = commitment_key->commit(key->alu_u32_tag); + witness_commitments.alu_u64_tag = commitment_key->commit(key->alu_u64_tag); + witness_commitments.alu_u8_r0 = commitment_key->commit(key->alu_u8_r0); + witness_commitments.alu_u8_r1 = commitment_key->commit(key->alu_u8_r1); + witness_commitments.alu_u8_tag = commitment_key->commit(key->alu_u8_tag); + witness_commitments.binary_acc_ia = commitment_key->commit(key->binary_acc_ia); + witness_commitments.binary_acc_ib = commitment_key->commit(key->binary_acc_ib); + witness_commitments.binary_acc_ic = commitment_key->commit(key->binary_acc_ic); + witness_commitments.binary_clk = commitment_key->commit(key->binary_clk); + witness_commitments.binary_ia_bytes = commitment_key->commit(key->binary_ia_bytes); + witness_commitments.binary_ib_bytes = commitment_key->commit(key->binary_ib_bytes); + witness_commitments.binary_ic_bytes = commitment_key->commit(key->binary_ic_bytes); + witness_commitments.binary_in_tag = commitment_key->commit(key->binary_in_tag); + witness_commitments.binary_mem_tag_ctr = commitment_key->commit(key->binary_mem_tag_ctr); + witness_commitments.binary_mem_tag_ctr_inv = commitment_key->commit(key->binary_mem_tag_ctr_inv); + witness_commitments.binary_op_id = commitment_key->commit(key->binary_op_id); + witness_commitments.binary_sel_bin = commitment_key->commit(key->binary_sel_bin); + witness_commitments.binary_start = commitment_key->commit(key->binary_start); + witness_commitments.byte_lookup_sel_bin = commitment_key->commit(key->byte_lookup_sel_bin); + witness_commitments.byte_lookup_table_byte_lengths = commitment_key->commit(key->byte_lookup_table_byte_lengths); + witness_commitments.byte_lookup_table_in_tags = commitment_key->commit(key->byte_lookup_table_in_tags); + witness_commitments.byte_lookup_table_input_a = commitment_key->commit(key->byte_lookup_table_input_a); + witness_commitments.byte_lookup_table_input_b = commitment_key->commit(key->byte_lookup_table_input_b); + witness_commitments.byte_lookup_table_op_id = commitment_key->commit(key->byte_lookup_table_op_id); + witness_commitments.byte_lookup_table_output = commitment_key->commit(key->byte_lookup_table_output); + witness_commitments.conversion_clk = commitment_key->commit(key->conversion_clk); + witness_commitments.conversion_input = commitment_key->commit(key->conversion_input); + witness_commitments.conversion_num_limbs = commitment_key->commit(key->conversion_num_limbs); + witness_commitments.conversion_radix = commitment_key->commit(key->conversion_radix); + witness_commitments.conversion_sel_to_radix_le = commitment_key->commit(key->conversion_sel_to_radix_le); + witness_commitments.gas_da_gas_fixed_table = commitment_key->commit(key->gas_da_gas_fixed_table); + witness_commitments.gas_l2_gas_fixed_table = commitment_key->commit(key->gas_l2_gas_fixed_table); + witness_commitments.gas_sel_gas_cost = commitment_key->commit(key->gas_sel_gas_cost); + witness_commitments.keccakf1600_clk = commitment_key->commit(key->keccakf1600_clk); + witness_commitments.keccakf1600_input = commitment_key->commit(key->keccakf1600_input); + witness_commitments.keccakf1600_output = commitment_key->commit(key->keccakf1600_output); + witness_commitments.keccakf1600_sel_keccakf1600 = commitment_key->commit(key->keccakf1600_sel_keccakf1600); + witness_commitments.kernel_emit_l2_to_l1_msg_write_offset = + commitment_key->commit(key->kernel_emit_l2_to_l1_msg_write_offset); + witness_commitments.kernel_emit_note_hash_write_offset = + commitment_key->commit(key->kernel_emit_note_hash_write_offset); + witness_commitments.kernel_emit_nullifier_write_offset = + commitment_key->commit(key->kernel_emit_nullifier_write_offset); + witness_commitments.kernel_emit_unencrypted_log_write_offset = + commitment_key->commit(key->kernel_emit_unencrypted_log_write_offset); + witness_commitments.kernel_kernel_in_offset = commitment_key->commit(key->kernel_kernel_in_offset); + witness_commitments.kernel_kernel_inputs = commitment_key->commit(key->kernel_kernel_inputs); + witness_commitments.kernel_kernel_metadata_out = commitment_key->commit(key->kernel_kernel_metadata_out); + witness_commitments.kernel_kernel_out_offset = commitment_key->commit(key->kernel_kernel_out_offset); + witness_commitments.kernel_kernel_side_effect_out = commitment_key->commit(key->kernel_kernel_side_effect_out); + witness_commitments.kernel_kernel_value_out = commitment_key->commit(key->kernel_kernel_value_out); + witness_commitments.kernel_l1_to_l2_msg_exists_write_offset = + commitment_key->commit(key->kernel_l1_to_l2_msg_exists_write_offset); + witness_commitments.kernel_note_hash_exist_write_offset = + commitment_key->commit(key->kernel_note_hash_exist_write_offset); + witness_commitments.kernel_nullifier_exists_write_offset = + commitment_key->commit(key->kernel_nullifier_exists_write_offset); + witness_commitments.kernel_nullifier_non_exists_write_offset = + commitment_key->commit(key->kernel_nullifier_non_exists_write_offset); + witness_commitments.kernel_q_public_input_kernel_add_to_table = + commitment_key->commit(key->kernel_q_public_input_kernel_add_to_table); + witness_commitments.kernel_q_public_input_kernel_out_add_to_table = + commitment_key->commit(key->kernel_q_public_input_kernel_out_add_to_table); + witness_commitments.kernel_side_effect_counter = commitment_key->commit(key->kernel_side_effect_counter); + witness_commitments.kernel_sload_write_offset = commitment_key->commit(key->kernel_sload_write_offset); + witness_commitments.kernel_sstore_write_offset = commitment_key->commit(key->kernel_sstore_write_offset); + witness_commitments.main_abs_da_rem_gas_hi = commitment_key->commit(key->main_abs_da_rem_gas_hi); + witness_commitments.main_abs_da_rem_gas_lo = commitment_key->commit(key->main_abs_da_rem_gas_lo); + witness_commitments.main_abs_l2_rem_gas_hi = commitment_key->commit(key->main_abs_l2_rem_gas_hi); + witness_commitments.main_abs_l2_rem_gas_lo = commitment_key->commit(key->main_abs_l2_rem_gas_lo); + witness_commitments.main_alu_in_tag = commitment_key->commit(key->main_alu_in_tag); + witness_commitments.main_bin_op_id = commitment_key->commit(key->main_bin_op_id); + witness_commitments.main_call_ptr = commitment_key->commit(key->main_call_ptr); + witness_commitments.main_da_gas_op_cost = commitment_key->commit(key->main_da_gas_op_cost); + witness_commitments.main_da_gas_remaining = commitment_key->commit(key->main_da_gas_remaining); + witness_commitments.main_da_out_of_gas = commitment_key->commit(key->main_da_out_of_gas); + witness_commitments.main_ia = commitment_key->commit(key->main_ia); + witness_commitments.main_ib = commitment_key->commit(key->main_ib); + witness_commitments.main_ic = commitment_key->commit(key->main_ic); + witness_commitments.main_id = commitment_key->commit(key->main_id); + witness_commitments.main_id_zero = commitment_key->commit(key->main_id_zero); + witness_commitments.main_ind_addr_a = commitment_key->commit(key->main_ind_addr_a); + witness_commitments.main_ind_addr_b = commitment_key->commit(key->main_ind_addr_b); + witness_commitments.main_ind_addr_c = commitment_key->commit(key->main_ind_addr_c); + witness_commitments.main_ind_addr_d = commitment_key->commit(key->main_ind_addr_d); + witness_commitments.main_internal_return_ptr = commitment_key->commit(key->main_internal_return_ptr); + witness_commitments.main_inv = commitment_key->commit(key->main_inv); + witness_commitments.main_l2_gas_op_cost = commitment_key->commit(key->main_l2_gas_op_cost); + witness_commitments.main_l2_gas_remaining = commitment_key->commit(key->main_l2_gas_remaining); + witness_commitments.main_l2_out_of_gas = commitment_key->commit(key->main_l2_out_of_gas); + witness_commitments.main_mem_addr_a = commitment_key->commit(key->main_mem_addr_a); + witness_commitments.main_mem_addr_b = commitment_key->commit(key->main_mem_addr_b); + witness_commitments.main_mem_addr_c = commitment_key->commit(key->main_mem_addr_c); + witness_commitments.main_mem_addr_d = commitment_key->commit(key->main_mem_addr_d); + witness_commitments.main_op_err = commitment_key->commit(key->main_op_err); + witness_commitments.main_opcode_val = commitment_key->commit(key->main_opcode_val); + witness_commitments.main_pc = commitment_key->commit(key->main_pc); + witness_commitments.main_r_in_tag = commitment_key->commit(key->main_r_in_tag); + witness_commitments.main_rwa = commitment_key->commit(key->main_rwa); + witness_commitments.main_rwb = commitment_key->commit(key->main_rwb); + witness_commitments.main_rwc = commitment_key->commit(key->main_rwc); + witness_commitments.main_rwd = commitment_key->commit(key->main_rwd); + witness_commitments.main_sel_alu = commitment_key->commit(key->main_sel_alu); + witness_commitments.main_sel_bin = commitment_key->commit(key->main_sel_bin); + witness_commitments.main_sel_gas_accounting_active = commitment_key->commit(key->main_sel_gas_accounting_active); + witness_commitments.main_sel_last = commitment_key->commit(key->main_sel_last); + witness_commitments.main_sel_mem_op_a = commitment_key->commit(key->main_sel_mem_op_a); + witness_commitments.main_sel_mem_op_activate_gas = commitment_key->commit(key->main_sel_mem_op_activate_gas); + witness_commitments.main_sel_mem_op_b = commitment_key->commit(key->main_sel_mem_op_b); + witness_commitments.main_sel_mem_op_c = commitment_key->commit(key->main_sel_mem_op_c); + witness_commitments.main_sel_mem_op_d = commitment_key->commit(key->main_sel_mem_op_d); + witness_commitments.main_sel_mov_ia_to_ic = commitment_key->commit(key->main_sel_mov_ia_to_ic); + witness_commitments.main_sel_mov_ib_to_ic = commitment_key->commit(key->main_sel_mov_ib_to_ic); + witness_commitments.main_sel_op_add = commitment_key->commit(key->main_sel_op_add); + witness_commitments.main_sel_op_address = commitment_key->commit(key->main_sel_op_address); + witness_commitments.main_sel_op_and = commitment_key->commit(key->main_sel_op_and); + witness_commitments.main_sel_op_block_number = commitment_key->commit(key->main_sel_op_block_number); + witness_commitments.main_sel_op_cast = commitment_key->commit(key->main_sel_op_cast); + witness_commitments.main_sel_op_chain_id = commitment_key->commit(key->main_sel_op_chain_id); + witness_commitments.main_sel_op_cmov = commitment_key->commit(key->main_sel_op_cmov); + witness_commitments.main_sel_op_coinbase = commitment_key->commit(key->main_sel_op_coinbase); + witness_commitments.main_sel_op_dagasleft = commitment_key->commit(key->main_sel_op_dagasleft); + witness_commitments.main_sel_op_div = commitment_key->commit(key->main_sel_op_div); + witness_commitments.main_sel_op_emit_l2_to_l1_msg = commitment_key->commit(key->main_sel_op_emit_l2_to_l1_msg); + witness_commitments.main_sel_op_emit_note_hash = commitment_key->commit(key->main_sel_op_emit_note_hash); + witness_commitments.main_sel_op_emit_nullifier = commitment_key->commit(key->main_sel_op_emit_nullifier); + witness_commitments.main_sel_op_emit_unencrypted_log = + commitment_key->commit(key->main_sel_op_emit_unencrypted_log); + witness_commitments.main_sel_op_eq = commitment_key->commit(key->main_sel_op_eq); + witness_commitments.main_sel_op_external_call = commitment_key->commit(key->main_sel_op_external_call); + witness_commitments.main_sel_op_fdiv = commitment_key->commit(key->main_sel_op_fdiv); + witness_commitments.main_sel_op_fee_per_da_gas = commitment_key->commit(key->main_sel_op_fee_per_da_gas); + witness_commitments.main_sel_op_fee_per_l2_gas = commitment_key->commit(key->main_sel_op_fee_per_l2_gas); + witness_commitments.main_sel_op_get_contract_instance = + commitment_key->commit(key->main_sel_op_get_contract_instance); + witness_commitments.main_sel_op_halt = commitment_key->commit(key->main_sel_op_halt); + witness_commitments.main_sel_op_internal_call = commitment_key->commit(key->main_sel_op_internal_call); + witness_commitments.main_sel_op_internal_return = commitment_key->commit(key->main_sel_op_internal_return); + witness_commitments.main_sel_op_jump = commitment_key->commit(key->main_sel_op_jump); + witness_commitments.main_sel_op_jumpi = commitment_key->commit(key->main_sel_op_jumpi); + witness_commitments.main_sel_op_keccak = commitment_key->commit(key->main_sel_op_keccak); + witness_commitments.main_sel_op_l1_to_l2_msg_exists = commitment_key->commit(key->main_sel_op_l1_to_l2_msg_exists); + witness_commitments.main_sel_op_l2gasleft = commitment_key->commit(key->main_sel_op_l2gasleft); + witness_commitments.main_sel_op_lt = commitment_key->commit(key->main_sel_op_lt); + witness_commitments.main_sel_op_lte = commitment_key->commit(key->main_sel_op_lte); + witness_commitments.main_sel_op_mov = commitment_key->commit(key->main_sel_op_mov); + witness_commitments.main_sel_op_mul = commitment_key->commit(key->main_sel_op_mul); + witness_commitments.main_sel_op_not = commitment_key->commit(key->main_sel_op_not); + witness_commitments.main_sel_op_note_hash_exists = commitment_key->commit(key->main_sel_op_note_hash_exists); + witness_commitments.main_sel_op_nullifier_exists = commitment_key->commit(key->main_sel_op_nullifier_exists); + witness_commitments.main_sel_op_or = commitment_key->commit(key->main_sel_op_or); + witness_commitments.main_sel_op_pedersen = commitment_key->commit(key->main_sel_op_pedersen); + witness_commitments.main_sel_op_poseidon2 = commitment_key->commit(key->main_sel_op_poseidon2); + witness_commitments.main_sel_op_radix_le = commitment_key->commit(key->main_sel_op_radix_le); + witness_commitments.main_sel_op_sender = commitment_key->commit(key->main_sel_op_sender); + witness_commitments.main_sel_op_sha256 = commitment_key->commit(key->main_sel_op_sha256); + witness_commitments.main_sel_op_shl = commitment_key->commit(key->main_sel_op_shl); + witness_commitments.main_sel_op_shr = commitment_key->commit(key->main_sel_op_shr); + witness_commitments.main_sel_op_sload = commitment_key->commit(key->main_sel_op_sload); + witness_commitments.main_sel_op_sstore = commitment_key->commit(key->main_sel_op_sstore); + witness_commitments.main_sel_op_storage_address = commitment_key->commit(key->main_sel_op_storage_address); + witness_commitments.main_sel_op_sub = commitment_key->commit(key->main_sel_op_sub); + witness_commitments.main_sel_op_timestamp = commitment_key->commit(key->main_sel_op_timestamp); + witness_commitments.main_sel_op_transaction_fee = commitment_key->commit(key->main_sel_op_transaction_fee); + witness_commitments.main_sel_op_version = commitment_key->commit(key->main_sel_op_version); + witness_commitments.main_sel_op_xor = commitment_key->commit(key->main_sel_op_xor); + witness_commitments.main_sel_q_kernel_lookup = commitment_key->commit(key->main_sel_q_kernel_lookup); + witness_commitments.main_sel_q_kernel_output_lookup = commitment_key->commit(key->main_sel_q_kernel_output_lookup); + witness_commitments.main_sel_resolve_ind_addr_a = commitment_key->commit(key->main_sel_resolve_ind_addr_a); + witness_commitments.main_sel_resolve_ind_addr_b = commitment_key->commit(key->main_sel_resolve_ind_addr_b); + witness_commitments.main_sel_resolve_ind_addr_c = commitment_key->commit(key->main_sel_resolve_ind_addr_c); + witness_commitments.main_sel_resolve_ind_addr_d = commitment_key->commit(key->main_sel_resolve_ind_addr_d); + witness_commitments.main_sel_rng_16 = commitment_key->commit(key->main_sel_rng_16); + witness_commitments.main_sel_rng_8 = commitment_key->commit(key->main_sel_rng_8); + witness_commitments.main_space_id = commitment_key->commit(key->main_space_id); + witness_commitments.main_table_pow_2 = commitment_key->commit(key->main_table_pow_2); + witness_commitments.main_tag_err = commitment_key->commit(key->main_tag_err); + witness_commitments.main_w_in_tag = commitment_key->commit(key->main_w_in_tag); + witness_commitments.mem_addr = commitment_key->commit(key->mem_addr); + witness_commitments.mem_clk = commitment_key->commit(key->mem_clk); + witness_commitments.mem_diff_hi = commitment_key->commit(key->mem_diff_hi); + witness_commitments.mem_diff_lo = commitment_key->commit(key->mem_diff_lo); + witness_commitments.mem_diff_mid = commitment_key->commit(key->mem_diff_mid); + witness_commitments.mem_glob_addr = commitment_key->commit(key->mem_glob_addr); + witness_commitments.mem_last = commitment_key->commit(key->mem_last); + witness_commitments.mem_lastAccess = commitment_key->commit(key->mem_lastAccess); + witness_commitments.mem_one_min_inv = commitment_key->commit(key->mem_one_min_inv); + witness_commitments.mem_r_in_tag = commitment_key->commit(key->mem_r_in_tag); + witness_commitments.mem_rw = commitment_key->commit(key->mem_rw); + witness_commitments.mem_sel_mem = commitment_key->commit(key->mem_sel_mem); + witness_commitments.mem_sel_mov_ia_to_ic = commitment_key->commit(key->mem_sel_mov_ia_to_ic); + witness_commitments.mem_sel_mov_ib_to_ic = commitment_key->commit(key->mem_sel_mov_ib_to_ic); + witness_commitments.mem_sel_op_a = commitment_key->commit(key->mem_sel_op_a); + witness_commitments.mem_sel_op_b = commitment_key->commit(key->mem_sel_op_b); + witness_commitments.mem_sel_op_c = commitment_key->commit(key->mem_sel_op_c); + witness_commitments.mem_sel_op_cmov = commitment_key->commit(key->mem_sel_op_cmov); + witness_commitments.mem_sel_op_d = commitment_key->commit(key->mem_sel_op_d); + witness_commitments.mem_sel_resolve_ind_addr_a = commitment_key->commit(key->mem_sel_resolve_ind_addr_a); + witness_commitments.mem_sel_resolve_ind_addr_b = commitment_key->commit(key->mem_sel_resolve_ind_addr_b); + witness_commitments.mem_sel_resolve_ind_addr_c = commitment_key->commit(key->mem_sel_resolve_ind_addr_c); + witness_commitments.mem_sel_resolve_ind_addr_d = commitment_key->commit(key->mem_sel_resolve_ind_addr_d); + witness_commitments.mem_sel_rng_chk = commitment_key->commit(key->mem_sel_rng_chk); + witness_commitments.mem_skip_check_tag = commitment_key->commit(key->mem_skip_check_tag); + witness_commitments.mem_space_id = commitment_key->commit(key->mem_space_id); + witness_commitments.mem_tag = commitment_key->commit(key->mem_tag); + witness_commitments.mem_tag_err = commitment_key->commit(key->mem_tag_err); + witness_commitments.mem_tsp = commitment_key->commit(key->mem_tsp); + witness_commitments.mem_val = commitment_key->commit(key->mem_val); + witness_commitments.mem_w_in_tag = commitment_key->commit(key->mem_w_in_tag); + witness_commitments.pedersen_clk = commitment_key->commit(key->pedersen_clk); + witness_commitments.pedersen_input = commitment_key->commit(key->pedersen_input); + witness_commitments.pedersen_output = commitment_key->commit(key->pedersen_output); + witness_commitments.pedersen_sel_pedersen = commitment_key->commit(key->pedersen_sel_pedersen); + witness_commitments.poseidon2_clk = commitment_key->commit(key->poseidon2_clk); + witness_commitments.poseidon2_input = commitment_key->commit(key->poseidon2_input); + witness_commitments.poseidon2_output = commitment_key->commit(key->poseidon2_output); + witness_commitments.poseidon2_sel_poseidon_perm = commitment_key->commit(key->poseidon2_sel_poseidon_perm); + witness_commitments.sha256_clk = commitment_key->commit(key->sha256_clk); + witness_commitments.sha256_input = commitment_key->commit(key->sha256_input); + witness_commitments.sha256_output = commitment_key->commit(key->sha256_output); + witness_commitments.sha256_sel_sha256_compression = commitment_key->commit(key->sha256_sel_sha256_compression); + witness_commitments.sha256_state = commitment_key->commit(key->sha256_state); witness_commitments.lookup_byte_lengths_counts = commitment_key->commit(key->lookup_byte_lengths_counts); witness_commitments.lookup_byte_operations_counts = commitment_key->commit(key->lookup_byte_operations_counts); witness_commitments.lookup_opcode_gas_counts = commitment_key->commit(key->lookup_opcode_gas_counts); @@ -409,372 +402,351 @@ void AvmProver::execute_wire_commitments_round() witness_commitments.lookup_div_u16_7_counts = commitment_key->commit(key->lookup_div_u16_7_counts); // Send all commitments to the verifier - transcript->send_to_verifier(commitment_labels.avm_alu_a_hi, witness_commitments.avm_alu_a_hi); - transcript->send_to_verifier(commitment_labels.avm_alu_a_lo, witness_commitments.avm_alu_a_lo); - transcript->send_to_verifier(commitment_labels.avm_alu_alu_sel, witness_commitments.avm_alu_alu_sel); - transcript->send_to_verifier(commitment_labels.avm_alu_b_hi, witness_commitments.avm_alu_b_hi); - transcript->send_to_verifier(commitment_labels.avm_alu_b_lo, witness_commitments.avm_alu_b_lo); - transcript->send_to_verifier(commitment_labels.avm_alu_borrow, witness_commitments.avm_alu_borrow); - transcript->send_to_verifier(commitment_labels.avm_alu_cf, witness_commitments.avm_alu_cf); - transcript->send_to_verifier(commitment_labels.avm_alu_clk, witness_commitments.avm_alu_clk); - transcript->send_to_verifier(commitment_labels.avm_alu_cmp_rng_ctr, witness_commitments.avm_alu_cmp_rng_ctr); - transcript->send_to_verifier(commitment_labels.avm_alu_cmp_sel, witness_commitments.avm_alu_cmp_sel); - transcript->send_to_verifier(commitment_labels.avm_alu_div_rng_chk_selector, - witness_commitments.avm_alu_div_rng_chk_selector); - transcript->send_to_verifier(commitment_labels.avm_alu_div_u16_r0, witness_commitments.avm_alu_div_u16_r0); - transcript->send_to_verifier(commitment_labels.avm_alu_div_u16_r1, witness_commitments.avm_alu_div_u16_r1); - transcript->send_to_verifier(commitment_labels.avm_alu_div_u16_r2, witness_commitments.avm_alu_div_u16_r2); - transcript->send_to_verifier(commitment_labels.avm_alu_div_u16_r3, witness_commitments.avm_alu_div_u16_r3); - transcript->send_to_verifier(commitment_labels.avm_alu_div_u16_r4, witness_commitments.avm_alu_div_u16_r4); - transcript->send_to_verifier(commitment_labels.avm_alu_div_u16_r5, witness_commitments.avm_alu_div_u16_r5); - transcript->send_to_verifier(commitment_labels.avm_alu_div_u16_r6, witness_commitments.avm_alu_div_u16_r6); - transcript->send_to_verifier(commitment_labels.avm_alu_div_u16_r7, witness_commitments.avm_alu_div_u16_r7); - transcript->send_to_verifier(commitment_labels.avm_alu_divisor_hi, witness_commitments.avm_alu_divisor_hi); - transcript->send_to_verifier(commitment_labels.avm_alu_divisor_lo, witness_commitments.avm_alu_divisor_lo); - transcript->send_to_verifier(commitment_labels.avm_alu_ff_tag, witness_commitments.avm_alu_ff_tag); - transcript->send_to_verifier(commitment_labels.avm_alu_ia, witness_commitments.avm_alu_ia); - transcript->send_to_verifier(commitment_labels.avm_alu_ib, witness_commitments.avm_alu_ib); - transcript->send_to_verifier(commitment_labels.avm_alu_ic, witness_commitments.avm_alu_ic); - transcript->send_to_verifier(commitment_labels.avm_alu_in_tag, witness_commitments.avm_alu_in_tag); - transcript->send_to_verifier(commitment_labels.avm_alu_op_add, witness_commitments.avm_alu_op_add); - transcript->send_to_verifier(commitment_labels.avm_alu_op_cast, witness_commitments.avm_alu_op_cast); - transcript->send_to_verifier(commitment_labels.avm_alu_op_cast_prev, witness_commitments.avm_alu_op_cast_prev); - transcript->send_to_verifier(commitment_labels.avm_alu_op_div, witness_commitments.avm_alu_op_div); - transcript->send_to_verifier(commitment_labels.avm_alu_op_div_a_lt_b, witness_commitments.avm_alu_op_div_a_lt_b); - transcript->send_to_verifier(commitment_labels.avm_alu_op_div_std, witness_commitments.avm_alu_op_div_std); - transcript->send_to_verifier(commitment_labels.avm_alu_op_eq, witness_commitments.avm_alu_op_eq); - transcript->send_to_verifier(commitment_labels.avm_alu_op_eq_diff_inv, witness_commitments.avm_alu_op_eq_diff_inv); - transcript->send_to_verifier(commitment_labels.avm_alu_op_lt, witness_commitments.avm_alu_op_lt); - transcript->send_to_verifier(commitment_labels.avm_alu_op_lte, witness_commitments.avm_alu_op_lte); - transcript->send_to_verifier(commitment_labels.avm_alu_op_mul, witness_commitments.avm_alu_op_mul); - transcript->send_to_verifier(commitment_labels.avm_alu_op_not, witness_commitments.avm_alu_op_not); - transcript->send_to_verifier(commitment_labels.avm_alu_op_shl, witness_commitments.avm_alu_op_shl); - transcript->send_to_verifier(commitment_labels.avm_alu_op_shr, witness_commitments.avm_alu_op_shr); - transcript->send_to_verifier(commitment_labels.avm_alu_op_sub, witness_commitments.avm_alu_op_sub); - transcript->send_to_verifier(commitment_labels.avm_alu_p_a_borrow, witness_commitments.avm_alu_p_a_borrow); - transcript->send_to_verifier(commitment_labels.avm_alu_p_b_borrow, witness_commitments.avm_alu_p_b_borrow); - transcript->send_to_verifier(commitment_labels.avm_alu_p_sub_a_hi, witness_commitments.avm_alu_p_sub_a_hi); - transcript->send_to_verifier(commitment_labels.avm_alu_p_sub_a_lo, witness_commitments.avm_alu_p_sub_a_lo); - transcript->send_to_verifier(commitment_labels.avm_alu_p_sub_b_hi, witness_commitments.avm_alu_p_sub_b_hi); - transcript->send_to_verifier(commitment_labels.avm_alu_p_sub_b_lo, witness_commitments.avm_alu_p_sub_b_lo); - transcript->send_to_verifier(commitment_labels.avm_alu_partial_prod_hi, - witness_commitments.avm_alu_partial_prod_hi); - transcript->send_to_verifier(commitment_labels.avm_alu_partial_prod_lo, - witness_commitments.avm_alu_partial_prod_lo); - transcript->send_to_verifier(commitment_labels.avm_alu_quotient_hi, witness_commitments.avm_alu_quotient_hi); - transcript->send_to_verifier(commitment_labels.avm_alu_quotient_lo, witness_commitments.avm_alu_quotient_lo); - transcript->send_to_verifier(commitment_labels.avm_alu_remainder, witness_commitments.avm_alu_remainder); - transcript->send_to_verifier(commitment_labels.avm_alu_res_hi, witness_commitments.avm_alu_res_hi); - transcript->send_to_verifier(commitment_labels.avm_alu_res_lo, witness_commitments.avm_alu_res_lo); - transcript->send_to_verifier(commitment_labels.avm_alu_rng_chk_lookup_selector, - witness_commitments.avm_alu_rng_chk_lookup_selector); - transcript->send_to_verifier(commitment_labels.avm_alu_rng_chk_sel, witness_commitments.avm_alu_rng_chk_sel); - transcript->send_to_verifier(commitment_labels.avm_alu_shift_lt_bit_len, - witness_commitments.avm_alu_shift_lt_bit_len); - transcript->send_to_verifier(commitment_labels.avm_alu_shift_sel, witness_commitments.avm_alu_shift_sel); - transcript->send_to_verifier(commitment_labels.avm_alu_t_sub_s_bits, witness_commitments.avm_alu_t_sub_s_bits); - transcript->send_to_verifier(commitment_labels.avm_alu_two_pow_s, witness_commitments.avm_alu_two_pow_s); - transcript->send_to_verifier(commitment_labels.avm_alu_two_pow_t_sub_s, - witness_commitments.avm_alu_two_pow_t_sub_s); - transcript->send_to_verifier(commitment_labels.avm_alu_u128_tag, witness_commitments.avm_alu_u128_tag); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r0, witness_commitments.avm_alu_u16_r0); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r1, witness_commitments.avm_alu_u16_r1); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r10, witness_commitments.avm_alu_u16_r10); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r11, witness_commitments.avm_alu_u16_r11); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r12, witness_commitments.avm_alu_u16_r12); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r13, witness_commitments.avm_alu_u16_r13); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r14, witness_commitments.avm_alu_u16_r14); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r2, witness_commitments.avm_alu_u16_r2); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r3, witness_commitments.avm_alu_u16_r3); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r4, witness_commitments.avm_alu_u16_r4); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r5, witness_commitments.avm_alu_u16_r5); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r6, witness_commitments.avm_alu_u16_r6); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r7, witness_commitments.avm_alu_u16_r7); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r8, witness_commitments.avm_alu_u16_r8); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_r9, witness_commitments.avm_alu_u16_r9); - transcript->send_to_verifier(commitment_labels.avm_alu_u16_tag, witness_commitments.avm_alu_u16_tag); - transcript->send_to_verifier(commitment_labels.avm_alu_u32_tag, witness_commitments.avm_alu_u32_tag); - transcript->send_to_verifier(commitment_labels.avm_alu_u64_tag, witness_commitments.avm_alu_u64_tag); - transcript->send_to_verifier(commitment_labels.avm_alu_u8_r0, witness_commitments.avm_alu_u8_r0); - transcript->send_to_verifier(commitment_labels.avm_alu_u8_r1, witness_commitments.avm_alu_u8_r1); - transcript->send_to_verifier(commitment_labels.avm_alu_u8_tag, witness_commitments.avm_alu_u8_tag); - transcript->send_to_verifier(commitment_labels.avm_binary_acc_ia, witness_commitments.avm_binary_acc_ia); - transcript->send_to_verifier(commitment_labels.avm_binary_acc_ib, witness_commitments.avm_binary_acc_ib); - transcript->send_to_verifier(commitment_labels.avm_binary_acc_ic, witness_commitments.avm_binary_acc_ic); - transcript->send_to_verifier(commitment_labels.avm_binary_bin_sel, witness_commitments.avm_binary_bin_sel); - transcript->send_to_verifier(commitment_labels.avm_binary_clk, witness_commitments.avm_binary_clk); - transcript->send_to_verifier(commitment_labels.avm_binary_ia_bytes, witness_commitments.avm_binary_ia_bytes); - transcript->send_to_verifier(commitment_labels.avm_binary_ib_bytes, witness_commitments.avm_binary_ib_bytes); - transcript->send_to_verifier(commitment_labels.avm_binary_ic_bytes, witness_commitments.avm_binary_ic_bytes); - transcript->send_to_verifier(commitment_labels.avm_binary_in_tag, witness_commitments.avm_binary_in_tag); - transcript->send_to_verifier(commitment_labels.avm_binary_mem_tag_ctr, witness_commitments.avm_binary_mem_tag_ctr); - transcript->send_to_verifier(commitment_labels.avm_binary_mem_tag_ctr_inv, - witness_commitments.avm_binary_mem_tag_ctr_inv); - transcript->send_to_verifier(commitment_labels.avm_binary_op_id, witness_commitments.avm_binary_op_id); - transcript->send_to_verifier(commitment_labels.avm_binary_start, witness_commitments.avm_binary_start); - transcript->send_to_verifier(commitment_labels.avm_byte_lookup_bin_sel, - witness_commitments.avm_byte_lookup_bin_sel); - transcript->send_to_verifier(commitment_labels.avm_byte_lookup_table_byte_lengths, - witness_commitments.avm_byte_lookup_table_byte_lengths); - transcript->send_to_verifier(commitment_labels.avm_byte_lookup_table_in_tags, - witness_commitments.avm_byte_lookup_table_in_tags); - transcript->send_to_verifier(commitment_labels.avm_byte_lookup_table_input_a, - witness_commitments.avm_byte_lookup_table_input_a); - transcript->send_to_verifier(commitment_labels.avm_byte_lookup_table_input_b, - witness_commitments.avm_byte_lookup_table_input_b); - transcript->send_to_verifier(commitment_labels.avm_byte_lookup_table_op_id, - witness_commitments.avm_byte_lookup_table_op_id); - transcript->send_to_verifier(commitment_labels.avm_byte_lookup_table_output, - witness_commitments.avm_byte_lookup_table_output); - transcript->send_to_verifier(commitment_labels.avm_conversion_clk, witness_commitments.avm_conversion_clk); - transcript->send_to_verifier(commitment_labels.avm_conversion_input, witness_commitments.avm_conversion_input); - transcript->send_to_verifier(commitment_labels.avm_conversion_num_limbs, - witness_commitments.avm_conversion_num_limbs); - transcript->send_to_verifier(commitment_labels.avm_conversion_radix, witness_commitments.avm_conversion_radix); - transcript->send_to_verifier(commitment_labels.avm_conversion_to_radix_le_sel, - witness_commitments.avm_conversion_to_radix_le_sel); - transcript->send_to_verifier(commitment_labels.avm_gas_da_gas_fixed_table, - witness_commitments.avm_gas_da_gas_fixed_table); - transcript->send_to_verifier(commitment_labels.avm_gas_gas_cost_sel, witness_commitments.avm_gas_gas_cost_sel); - transcript->send_to_verifier(commitment_labels.avm_gas_l2_gas_fixed_table, - witness_commitments.avm_gas_l2_gas_fixed_table); - transcript->send_to_verifier(commitment_labels.avm_keccakf1600_clk, witness_commitments.avm_keccakf1600_clk); - transcript->send_to_verifier(commitment_labels.avm_keccakf1600_input, witness_commitments.avm_keccakf1600_input); - transcript->send_to_verifier(commitment_labels.avm_keccakf1600_keccakf1600_sel, - witness_commitments.avm_keccakf1600_keccakf1600_sel); - transcript->send_to_verifier(commitment_labels.avm_keccakf1600_output, witness_commitments.avm_keccakf1600_output); - transcript->send_to_verifier(commitment_labels.avm_kernel_emit_l2_to_l1_msg_write_offset, - witness_commitments.avm_kernel_emit_l2_to_l1_msg_write_offset); - transcript->send_to_verifier(commitment_labels.avm_kernel_emit_note_hash_write_offset, - witness_commitments.avm_kernel_emit_note_hash_write_offset); - transcript->send_to_verifier(commitment_labels.avm_kernel_emit_nullifier_write_offset, - witness_commitments.avm_kernel_emit_nullifier_write_offset); - transcript->send_to_verifier(commitment_labels.avm_kernel_emit_unencrypted_log_write_offset, - witness_commitments.avm_kernel_emit_unencrypted_log_write_offset); - transcript->send_to_verifier(commitment_labels.avm_kernel_kernel_in_offset, - witness_commitments.avm_kernel_kernel_in_offset); - transcript->send_to_verifier(commitment_labels.avm_kernel_kernel_inputs, - witness_commitments.avm_kernel_kernel_inputs); - transcript->send_to_verifier(commitment_labels.avm_kernel_kernel_metadata_out, - witness_commitments.avm_kernel_kernel_metadata_out); - transcript->send_to_verifier(commitment_labels.avm_kernel_kernel_out_offset, - witness_commitments.avm_kernel_kernel_out_offset); - transcript->send_to_verifier(commitment_labels.avm_kernel_kernel_side_effect_out, - witness_commitments.avm_kernel_kernel_side_effect_out); - transcript->send_to_verifier(commitment_labels.avm_kernel_kernel_value_out, - witness_commitments.avm_kernel_kernel_value_out); - transcript->send_to_verifier(commitment_labels.avm_kernel_l1_to_l2_msg_exists_write_offset, - witness_commitments.avm_kernel_l1_to_l2_msg_exists_write_offset); - transcript->send_to_verifier(commitment_labels.avm_kernel_note_hash_exist_write_offset, - witness_commitments.avm_kernel_note_hash_exist_write_offset); - transcript->send_to_verifier(commitment_labels.avm_kernel_nullifier_exists_write_offset, - witness_commitments.avm_kernel_nullifier_exists_write_offset); - transcript->send_to_verifier(commitment_labels.avm_kernel_nullifier_non_exists_write_offset, - witness_commitments.avm_kernel_nullifier_non_exists_write_offset); - transcript->send_to_verifier(commitment_labels.avm_kernel_q_public_input_kernel_add_to_table, - witness_commitments.avm_kernel_q_public_input_kernel_add_to_table); - transcript->send_to_verifier(commitment_labels.avm_kernel_q_public_input_kernel_out_add_to_table, - witness_commitments.avm_kernel_q_public_input_kernel_out_add_to_table); - transcript->send_to_verifier(commitment_labels.avm_kernel_side_effect_counter, - witness_commitments.avm_kernel_side_effect_counter); - transcript->send_to_verifier(commitment_labels.avm_kernel_sload_write_offset, - witness_commitments.avm_kernel_sload_write_offset); - transcript->send_to_verifier(commitment_labels.avm_kernel_sstore_write_offset, - witness_commitments.avm_kernel_sstore_write_offset); - transcript->send_to_verifier(commitment_labels.avm_main_abs_da_rem_gas_hi, - witness_commitments.avm_main_abs_da_rem_gas_hi); - transcript->send_to_verifier(commitment_labels.avm_main_abs_da_rem_gas_lo, - witness_commitments.avm_main_abs_da_rem_gas_lo); - transcript->send_to_verifier(commitment_labels.avm_main_abs_l2_rem_gas_hi, - witness_commitments.avm_main_abs_l2_rem_gas_hi); - transcript->send_to_verifier(commitment_labels.avm_main_abs_l2_rem_gas_lo, - witness_commitments.avm_main_abs_l2_rem_gas_lo); - transcript->send_to_verifier(commitment_labels.avm_main_alu_in_tag, witness_commitments.avm_main_alu_in_tag); - transcript->send_to_verifier(commitment_labels.avm_main_alu_sel, witness_commitments.avm_main_alu_sel); - transcript->send_to_verifier(commitment_labels.avm_main_bin_op_id, witness_commitments.avm_main_bin_op_id); - transcript->send_to_verifier(commitment_labels.avm_main_bin_sel, witness_commitments.avm_main_bin_sel); - transcript->send_to_verifier(commitment_labels.avm_main_call_ptr, witness_commitments.avm_main_call_ptr); - transcript->send_to_verifier(commitment_labels.avm_main_da_gas_op, witness_commitments.avm_main_da_gas_op); - transcript->send_to_verifier(commitment_labels.avm_main_da_gas_remaining, - witness_commitments.avm_main_da_gas_remaining); - transcript->send_to_verifier(commitment_labels.avm_main_da_out_of_gas, witness_commitments.avm_main_da_out_of_gas); - transcript->send_to_verifier(commitment_labels.avm_main_gas_cost_active, - witness_commitments.avm_main_gas_cost_active); - transcript->send_to_verifier(commitment_labels.avm_main_ia, witness_commitments.avm_main_ia); - transcript->send_to_verifier(commitment_labels.avm_main_ib, witness_commitments.avm_main_ib); - transcript->send_to_verifier(commitment_labels.avm_main_ic, witness_commitments.avm_main_ic); - transcript->send_to_verifier(commitment_labels.avm_main_id, witness_commitments.avm_main_id); - transcript->send_to_verifier(commitment_labels.avm_main_id_zero, witness_commitments.avm_main_id_zero); - transcript->send_to_verifier(commitment_labels.avm_main_ind_a, witness_commitments.avm_main_ind_a); - transcript->send_to_verifier(commitment_labels.avm_main_ind_b, witness_commitments.avm_main_ind_b); - transcript->send_to_verifier(commitment_labels.avm_main_ind_c, witness_commitments.avm_main_ind_c); - transcript->send_to_verifier(commitment_labels.avm_main_ind_d, witness_commitments.avm_main_ind_d); - transcript->send_to_verifier(commitment_labels.avm_main_ind_op_a, witness_commitments.avm_main_ind_op_a); - transcript->send_to_verifier(commitment_labels.avm_main_ind_op_b, witness_commitments.avm_main_ind_op_b); - transcript->send_to_verifier(commitment_labels.avm_main_ind_op_c, witness_commitments.avm_main_ind_op_c); - transcript->send_to_verifier(commitment_labels.avm_main_ind_op_d, witness_commitments.avm_main_ind_op_d); - transcript->send_to_verifier(commitment_labels.avm_main_internal_return_ptr, - witness_commitments.avm_main_internal_return_ptr); - transcript->send_to_verifier(commitment_labels.avm_main_inv, witness_commitments.avm_main_inv); - transcript->send_to_verifier(commitment_labels.avm_main_l2_gas_op, witness_commitments.avm_main_l2_gas_op); - transcript->send_to_verifier(commitment_labels.avm_main_l2_gas_remaining, - witness_commitments.avm_main_l2_gas_remaining); - transcript->send_to_verifier(commitment_labels.avm_main_l2_out_of_gas, witness_commitments.avm_main_l2_out_of_gas); - transcript->send_to_verifier(commitment_labels.avm_main_last, witness_commitments.avm_main_last); - transcript->send_to_verifier(commitment_labels.avm_main_mem_idx_a, witness_commitments.avm_main_mem_idx_a); - transcript->send_to_verifier(commitment_labels.avm_main_mem_idx_b, witness_commitments.avm_main_mem_idx_b); - transcript->send_to_verifier(commitment_labels.avm_main_mem_idx_c, witness_commitments.avm_main_mem_idx_c); - transcript->send_to_verifier(commitment_labels.avm_main_mem_idx_d, witness_commitments.avm_main_mem_idx_d); - transcript->send_to_verifier(commitment_labels.avm_main_mem_op_a, witness_commitments.avm_main_mem_op_a); - transcript->send_to_verifier(commitment_labels.avm_main_mem_op_activate_gas, - witness_commitments.avm_main_mem_op_activate_gas); - transcript->send_to_verifier(commitment_labels.avm_main_mem_op_b, witness_commitments.avm_main_mem_op_b); - transcript->send_to_verifier(commitment_labels.avm_main_mem_op_c, witness_commitments.avm_main_mem_op_c); - transcript->send_to_verifier(commitment_labels.avm_main_mem_op_d, witness_commitments.avm_main_mem_op_d); - transcript->send_to_verifier(commitment_labels.avm_main_op_err, witness_commitments.avm_main_op_err); - transcript->send_to_verifier(commitment_labels.avm_main_opcode_val, witness_commitments.avm_main_opcode_val); - transcript->send_to_verifier(commitment_labels.avm_main_pc, witness_commitments.avm_main_pc); - transcript->send_to_verifier(commitment_labels.avm_main_q_kernel_lookup, - witness_commitments.avm_main_q_kernel_lookup); - transcript->send_to_verifier(commitment_labels.avm_main_q_kernel_output_lookup, - witness_commitments.avm_main_q_kernel_output_lookup); - transcript->send_to_verifier(commitment_labels.avm_main_r_in_tag, witness_commitments.avm_main_r_in_tag); - transcript->send_to_verifier(commitment_labels.avm_main_rwa, witness_commitments.avm_main_rwa); - transcript->send_to_verifier(commitment_labels.avm_main_rwb, witness_commitments.avm_main_rwb); - transcript->send_to_verifier(commitment_labels.avm_main_rwc, witness_commitments.avm_main_rwc); - transcript->send_to_verifier(commitment_labels.avm_main_rwd, witness_commitments.avm_main_rwd); - transcript->send_to_verifier(commitment_labels.avm_main_sel_cmov, witness_commitments.avm_main_sel_cmov); - transcript->send_to_verifier(commitment_labels.avm_main_sel_external_call, - witness_commitments.avm_main_sel_external_call); - transcript->send_to_verifier(commitment_labels.avm_main_sel_halt, witness_commitments.avm_main_sel_halt); - transcript->send_to_verifier(commitment_labels.avm_main_sel_internal_call, - witness_commitments.avm_main_sel_internal_call); - transcript->send_to_verifier(commitment_labels.avm_main_sel_internal_return, - witness_commitments.avm_main_sel_internal_return); - transcript->send_to_verifier(commitment_labels.avm_main_sel_jump, witness_commitments.avm_main_sel_jump); - transcript->send_to_verifier(commitment_labels.avm_main_sel_jumpi, witness_commitments.avm_main_sel_jumpi); - transcript->send_to_verifier(commitment_labels.avm_main_sel_mov, witness_commitments.avm_main_sel_mov); - transcript->send_to_verifier(commitment_labels.avm_main_sel_mov_a, witness_commitments.avm_main_sel_mov_a); - transcript->send_to_verifier(commitment_labels.avm_main_sel_mov_b, witness_commitments.avm_main_sel_mov_b); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_add, witness_commitments.avm_main_sel_op_add); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_address, - witness_commitments.avm_main_sel_op_address); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_and, witness_commitments.avm_main_sel_op_and); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_block_number, - witness_commitments.avm_main_sel_op_block_number); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_cast, witness_commitments.avm_main_sel_op_cast); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_chain_id, - witness_commitments.avm_main_sel_op_chain_id); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_coinbase, - witness_commitments.avm_main_sel_op_coinbase); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_dagasleft, - witness_commitments.avm_main_sel_op_dagasleft); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_div, witness_commitments.avm_main_sel_op_div); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_emit_l2_to_l1_msg, - witness_commitments.avm_main_sel_op_emit_l2_to_l1_msg); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_emit_note_hash, - witness_commitments.avm_main_sel_op_emit_note_hash); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_emit_nullifier, - witness_commitments.avm_main_sel_op_emit_nullifier); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_emit_unencrypted_log, - witness_commitments.avm_main_sel_op_emit_unencrypted_log); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_eq, witness_commitments.avm_main_sel_op_eq); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_fdiv, witness_commitments.avm_main_sel_op_fdiv); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_fee_per_da_gas, - witness_commitments.avm_main_sel_op_fee_per_da_gas); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_fee_per_l2_gas, - witness_commitments.avm_main_sel_op_fee_per_l2_gas); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_get_contract_instance, - witness_commitments.avm_main_sel_op_get_contract_instance); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_keccak, witness_commitments.avm_main_sel_op_keccak); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_l1_to_l2_msg_exists, - witness_commitments.avm_main_sel_op_l1_to_l2_msg_exists); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_l2gasleft, - witness_commitments.avm_main_sel_op_l2gasleft); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_lt, witness_commitments.avm_main_sel_op_lt); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_lte, witness_commitments.avm_main_sel_op_lte); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_mul, witness_commitments.avm_main_sel_op_mul); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_not, witness_commitments.avm_main_sel_op_not); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_note_hash_exists, - witness_commitments.avm_main_sel_op_note_hash_exists); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_nullifier_exists, - witness_commitments.avm_main_sel_op_nullifier_exists); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_or, witness_commitments.avm_main_sel_op_or); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_pedersen, - witness_commitments.avm_main_sel_op_pedersen); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_poseidon2, - witness_commitments.avm_main_sel_op_poseidon2); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_radix_le, - witness_commitments.avm_main_sel_op_radix_le); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_sender, witness_commitments.avm_main_sel_op_sender); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_sha256, witness_commitments.avm_main_sel_op_sha256); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_shl, witness_commitments.avm_main_sel_op_shl); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_shr, witness_commitments.avm_main_sel_op_shr); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_sload, witness_commitments.avm_main_sel_op_sload); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_sstore, witness_commitments.avm_main_sel_op_sstore); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_storage_address, - witness_commitments.avm_main_sel_op_storage_address); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_sub, witness_commitments.avm_main_sel_op_sub); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_timestamp, - witness_commitments.avm_main_sel_op_timestamp); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_transaction_fee, - witness_commitments.avm_main_sel_op_transaction_fee); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_version, - witness_commitments.avm_main_sel_op_version); - transcript->send_to_verifier(commitment_labels.avm_main_sel_op_xor, witness_commitments.avm_main_sel_op_xor); - transcript->send_to_verifier(commitment_labels.avm_main_sel_rng_16, witness_commitments.avm_main_sel_rng_16); - transcript->send_to_verifier(commitment_labels.avm_main_sel_rng_8, witness_commitments.avm_main_sel_rng_8); - transcript->send_to_verifier(commitment_labels.avm_main_space_id, witness_commitments.avm_main_space_id); - transcript->send_to_verifier(commitment_labels.avm_main_table_pow_2, witness_commitments.avm_main_table_pow_2); - transcript->send_to_verifier(commitment_labels.avm_main_tag_err, witness_commitments.avm_main_tag_err); - transcript->send_to_verifier(commitment_labels.avm_main_w_in_tag, witness_commitments.avm_main_w_in_tag); - transcript->send_to_verifier(commitment_labels.avm_mem_addr, witness_commitments.avm_mem_addr); - transcript->send_to_verifier(commitment_labels.avm_mem_clk, witness_commitments.avm_mem_clk); - transcript->send_to_verifier(commitment_labels.avm_mem_diff_hi, witness_commitments.avm_mem_diff_hi); - transcript->send_to_verifier(commitment_labels.avm_mem_diff_lo, witness_commitments.avm_mem_diff_lo); - transcript->send_to_verifier(commitment_labels.avm_mem_diff_mid, witness_commitments.avm_mem_diff_mid); - transcript->send_to_verifier(commitment_labels.avm_mem_glob_addr, witness_commitments.avm_mem_glob_addr); - transcript->send_to_verifier(commitment_labels.avm_mem_ind_op_a, witness_commitments.avm_mem_ind_op_a); - transcript->send_to_verifier(commitment_labels.avm_mem_ind_op_b, witness_commitments.avm_mem_ind_op_b); - transcript->send_to_verifier(commitment_labels.avm_mem_ind_op_c, witness_commitments.avm_mem_ind_op_c); - transcript->send_to_verifier(commitment_labels.avm_mem_ind_op_d, witness_commitments.avm_mem_ind_op_d); - transcript->send_to_verifier(commitment_labels.avm_mem_last, witness_commitments.avm_mem_last); - transcript->send_to_verifier(commitment_labels.avm_mem_lastAccess, witness_commitments.avm_mem_lastAccess); - transcript->send_to_verifier(commitment_labels.avm_mem_mem_sel, witness_commitments.avm_mem_mem_sel); - transcript->send_to_verifier(commitment_labels.avm_mem_one_min_inv, witness_commitments.avm_mem_one_min_inv); - transcript->send_to_verifier(commitment_labels.avm_mem_op_a, witness_commitments.avm_mem_op_a); - transcript->send_to_verifier(commitment_labels.avm_mem_op_b, witness_commitments.avm_mem_op_b); - transcript->send_to_verifier(commitment_labels.avm_mem_op_c, witness_commitments.avm_mem_op_c); - transcript->send_to_verifier(commitment_labels.avm_mem_op_d, witness_commitments.avm_mem_op_d); - transcript->send_to_verifier(commitment_labels.avm_mem_r_in_tag, witness_commitments.avm_mem_r_in_tag); - transcript->send_to_verifier(commitment_labels.avm_mem_rng_chk_sel, witness_commitments.avm_mem_rng_chk_sel); - transcript->send_to_verifier(commitment_labels.avm_mem_rw, witness_commitments.avm_mem_rw); - transcript->send_to_verifier(commitment_labels.avm_mem_sel_cmov, witness_commitments.avm_mem_sel_cmov); - transcript->send_to_verifier(commitment_labels.avm_mem_sel_mov_a, witness_commitments.avm_mem_sel_mov_a); - transcript->send_to_verifier(commitment_labels.avm_mem_sel_mov_b, witness_commitments.avm_mem_sel_mov_b); - transcript->send_to_verifier(commitment_labels.avm_mem_skip_check_tag, witness_commitments.avm_mem_skip_check_tag); - transcript->send_to_verifier(commitment_labels.avm_mem_space_id, witness_commitments.avm_mem_space_id); - transcript->send_to_verifier(commitment_labels.avm_mem_tag, witness_commitments.avm_mem_tag); - transcript->send_to_verifier(commitment_labels.avm_mem_tag_err, witness_commitments.avm_mem_tag_err); - transcript->send_to_verifier(commitment_labels.avm_mem_tsp, witness_commitments.avm_mem_tsp); - transcript->send_to_verifier(commitment_labels.avm_mem_val, witness_commitments.avm_mem_val); - transcript->send_to_verifier(commitment_labels.avm_mem_w_in_tag, witness_commitments.avm_mem_w_in_tag); - transcript->send_to_verifier(commitment_labels.avm_pedersen_clk, witness_commitments.avm_pedersen_clk); - transcript->send_to_verifier(commitment_labels.avm_pedersen_input, witness_commitments.avm_pedersen_input); - transcript->send_to_verifier(commitment_labels.avm_pedersen_output, witness_commitments.avm_pedersen_output); - transcript->send_to_verifier(commitment_labels.avm_pedersen_pedersen_sel, - witness_commitments.avm_pedersen_pedersen_sel); - transcript->send_to_verifier(commitment_labels.avm_poseidon2_clk, witness_commitments.avm_poseidon2_clk); - transcript->send_to_verifier(commitment_labels.avm_poseidon2_input, witness_commitments.avm_poseidon2_input); - transcript->send_to_verifier(commitment_labels.avm_poseidon2_output, witness_commitments.avm_poseidon2_output); - transcript->send_to_verifier(commitment_labels.avm_poseidon2_poseidon_perm_sel, - witness_commitments.avm_poseidon2_poseidon_perm_sel); - transcript->send_to_verifier(commitment_labels.avm_sha256_clk, witness_commitments.avm_sha256_clk); - transcript->send_to_verifier(commitment_labels.avm_sha256_input, witness_commitments.avm_sha256_input); - transcript->send_to_verifier(commitment_labels.avm_sha256_output, witness_commitments.avm_sha256_output); - transcript->send_to_verifier(commitment_labels.avm_sha256_sha256_compression_sel, - witness_commitments.avm_sha256_sha256_compression_sel); - transcript->send_to_verifier(commitment_labels.avm_sha256_state, witness_commitments.avm_sha256_state); + transcript->send_to_verifier(commitment_labels.alu_a_hi, witness_commitments.alu_a_hi); + transcript->send_to_verifier(commitment_labels.alu_a_lo, witness_commitments.alu_a_lo); + transcript->send_to_verifier(commitment_labels.alu_b_hi, witness_commitments.alu_b_hi); + transcript->send_to_verifier(commitment_labels.alu_b_lo, witness_commitments.alu_b_lo); + transcript->send_to_verifier(commitment_labels.alu_borrow, witness_commitments.alu_borrow); + transcript->send_to_verifier(commitment_labels.alu_cf, witness_commitments.alu_cf); + transcript->send_to_verifier(commitment_labels.alu_clk, witness_commitments.alu_clk); + transcript->send_to_verifier(commitment_labels.alu_cmp_rng_ctr, witness_commitments.alu_cmp_rng_ctr); + transcript->send_to_verifier(commitment_labels.alu_div_u16_r0, witness_commitments.alu_div_u16_r0); + transcript->send_to_verifier(commitment_labels.alu_div_u16_r1, witness_commitments.alu_div_u16_r1); + transcript->send_to_verifier(commitment_labels.alu_div_u16_r2, witness_commitments.alu_div_u16_r2); + transcript->send_to_verifier(commitment_labels.alu_div_u16_r3, witness_commitments.alu_div_u16_r3); + transcript->send_to_verifier(commitment_labels.alu_div_u16_r4, witness_commitments.alu_div_u16_r4); + transcript->send_to_verifier(commitment_labels.alu_div_u16_r5, witness_commitments.alu_div_u16_r5); + transcript->send_to_verifier(commitment_labels.alu_div_u16_r6, witness_commitments.alu_div_u16_r6); + transcript->send_to_verifier(commitment_labels.alu_div_u16_r7, witness_commitments.alu_div_u16_r7); + transcript->send_to_verifier(commitment_labels.alu_divisor_hi, witness_commitments.alu_divisor_hi); + transcript->send_to_verifier(commitment_labels.alu_divisor_lo, witness_commitments.alu_divisor_lo); + transcript->send_to_verifier(commitment_labels.alu_ff_tag, witness_commitments.alu_ff_tag); + transcript->send_to_verifier(commitment_labels.alu_ia, witness_commitments.alu_ia); + transcript->send_to_verifier(commitment_labels.alu_ib, witness_commitments.alu_ib); + transcript->send_to_verifier(commitment_labels.alu_ic, witness_commitments.alu_ic); + transcript->send_to_verifier(commitment_labels.alu_in_tag, witness_commitments.alu_in_tag); + transcript->send_to_verifier(commitment_labels.alu_op_add, witness_commitments.alu_op_add); + transcript->send_to_verifier(commitment_labels.alu_op_cast, witness_commitments.alu_op_cast); + transcript->send_to_verifier(commitment_labels.alu_op_cast_prev, witness_commitments.alu_op_cast_prev); + transcript->send_to_verifier(commitment_labels.alu_op_div, witness_commitments.alu_op_div); + transcript->send_to_verifier(commitment_labels.alu_op_div_a_lt_b, witness_commitments.alu_op_div_a_lt_b); + transcript->send_to_verifier(commitment_labels.alu_op_div_std, witness_commitments.alu_op_div_std); + transcript->send_to_verifier(commitment_labels.alu_op_eq, witness_commitments.alu_op_eq); + transcript->send_to_verifier(commitment_labels.alu_op_eq_diff_inv, witness_commitments.alu_op_eq_diff_inv); + transcript->send_to_verifier(commitment_labels.alu_op_lt, witness_commitments.alu_op_lt); + transcript->send_to_verifier(commitment_labels.alu_op_lte, witness_commitments.alu_op_lte); + transcript->send_to_verifier(commitment_labels.alu_op_mul, witness_commitments.alu_op_mul); + transcript->send_to_verifier(commitment_labels.alu_op_not, witness_commitments.alu_op_not); + transcript->send_to_verifier(commitment_labels.alu_op_shl, witness_commitments.alu_op_shl); + transcript->send_to_verifier(commitment_labels.alu_op_shr, witness_commitments.alu_op_shr); + transcript->send_to_verifier(commitment_labels.alu_op_sub, witness_commitments.alu_op_sub); + transcript->send_to_verifier(commitment_labels.alu_p_a_borrow, witness_commitments.alu_p_a_borrow); + transcript->send_to_verifier(commitment_labels.alu_p_b_borrow, witness_commitments.alu_p_b_borrow); + transcript->send_to_verifier(commitment_labels.alu_p_sub_a_hi, witness_commitments.alu_p_sub_a_hi); + transcript->send_to_verifier(commitment_labels.alu_p_sub_a_lo, witness_commitments.alu_p_sub_a_lo); + transcript->send_to_verifier(commitment_labels.alu_p_sub_b_hi, witness_commitments.alu_p_sub_b_hi); + transcript->send_to_verifier(commitment_labels.alu_p_sub_b_lo, witness_commitments.alu_p_sub_b_lo); + transcript->send_to_verifier(commitment_labels.alu_partial_prod_hi, witness_commitments.alu_partial_prod_hi); + transcript->send_to_verifier(commitment_labels.alu_partial_prod_lo, witness_commitments.alu_partial_prod_lo); + transcript->send_to_verifier(commitment_labels.alu_quotient_hi, witness_commitments.alu_quotient_hi); + transcript->send_to_verifier(commitment_labels.alu_quotient_lo, witness_commitments.alu_quotient_lo); + transcript->send_to_verifier(commitment_labels.alu_remainder, witness_commitments.alu_remainder); + transcript->send_to_verifier(commitment_labels.alu_res_hi, witness_commitments.alu_res_hi); + transcript->send_to_verifier(commitment_labels.alu_res_lo, witness_commitments.alu_res_lo); + transcript->send_to_verifier(commitment_labels.alu_sel_alu, witness_commitments.alu_sel_alu); + transcript->send_to_verifier(commitment_labels.alu_sel_cmp, witness_commitments.alu_sel_cmp); + transcript->send_to_verifier(commitment_labels.alu_sel_div_rng_chk, witness_commitments.alu_sel_div_rng_chk); + transcript->send_to_verifier(commitment_labels.alu_sel_rng_chk, witness_commitments.alu_sel_rng_chk); + transcript->send_to_verifier(commitment_labels.alu_sel_rng_chk_lookup, witness_commitments.alu_sel_rng_chk_lookup); + transcript->send_to_verifier(commitment_labels.alu_sel_shift_which, witness_commitments.alu_sel_shift_which); + transcript->send_to_verifier(commitment_labels.alu_shift_lt_bit_len, witness_commitments.alu_shift_lt_bit_len); + transcript->send_to_verifier(commitment_labels.alu_t_sub_s_bits, witness_commitments.alu_t_sub_s_bits); + transcript->send_to_verifier(commitment_labels.alu_two_pow_s, witness_commitments.alu_two_pow_s); + transcript->send_to_verifier(commitment_labels.alu_two_pow_t_sub_s, witness_commitments.alu_two_pow_t_sub_s); + transcript->send_to_verifier(commitment_labels.alu_u128_tag, witness_commitments.alu_u128_tag); + transcript->send_to_verifier(commitment_labels.alu_u16_r0, witness_commitments.alu_u16_r0); + transcript->send_to_verifier(commitment_labels.alu_u16_r1, witness_commitments.alu_u16_r1); + transcript->send_to_verifier(commitment_labels.alu_u16_r10, witness_commitments.alu_u16_r10); + transcript->send_to_verifier(commitment_labels.alu_u16_r11, witness_commitments.alu_u16_r11); + transcript->send_to_verifier(commitment_labels.alu_u16_r12, witness_commitments.alu_u16_r12); + transcript->send_to_verifier(commitment_labels.alu_u16_r13, witness_commitments.alu_u16_r13); + transcript->send_to_verifier(commitment_labels.alu_u16_r14, witness_commitments.alu_u16_r14); + transcript->send_to_verifier(commitment_labels.alu_u16_r2, witness_commitments.alu_u16_r2); + transcript->send_to_verifier(commitment_labels.alu_u16_r3, witness_commitments.alu_u16_r3); + transcript->send_to_verifier(commitment_labels.alu_u16_r4, witness_commitments.alu_u16_r4); + transcript->send_to_verifier(commitment_labels.alu_u16_r5, witness_commitments.alu_u16_r5); + transcript->send_to_verifier(commitment_labels.alu_u16_r6, witness_commitments.alu_u16_r6); + transcript->send_to_verifier(commitment_labels.alu_u16_r7, witness_commitments.alu_u16_r7); + transcript->send_to_verifier(commitment_labels.alu_u16_r8, witness_commitments.alu_u16_r8); + transcript->send_to_verifier(commitment_labels.alu_u16_r9, witness_commitments.alu_u16_r9); + transcript->send_to_verifier(commitment_labels.alu_u16_tag, witness_commitments.alu_u16_tag); + transcript->send_to_verifier(commitment_labels.alu_u32_tag, witness_commitments.alu_u32_tag); + transcript->send_to_verifier(commitment_labels.alu_u64_tag, witness_commitments.alu_u64_tag); + transcript->send_to_verifier(commitment_labels.alu_u8_r0, witness_commitments.alu_u8_r0); + transcript->send_to_verifier(commitment_labels.alu_u8_r1, witness_commitments.alu_u8_r1); + transcript->send_to_verifier(commitment_labels.alu_u8_tag, witness_commitments.alu_u8_tag); + transcript->send_to_verifier(commitment_labels.binary_acc_ia, witness_commitments.binary_acc_ia); + transcript->send_to_verifier(commitment_labels.binary_acc_ib, witness_commitments.binary_acc_ib); + transcript->send_to_verifier(commitment_labels.binary_acc_ic, witness_commitments.binary_acc_ic); + transcript->send_to_verifier(commitment_labels.binary_clk, witness_commitments.binary_clk); + transcript->send_to_verifier(commitment_labels.binary_ia_bytes, witness_commitments.binary_ia_bytes); + transcript->send_to_verifier(commitment_labels.binary_ib_bytes, witness_commitments.binary_ib_bytes); + transcript->send_to_verifier(commitment_labels.binary_ic_bytes, witness_commitments.binary_ic_bytes); + transcript->send_to_verifier(commitment_labels.binary_in_tag, witness_commitments.binary_in_tag); + transcript->send_to_verifier(commitment_labels.binary_mem_tag_ctr, witness_commitments.binary_mem_tag_ctr); + transcript->send_to_verifier(commitment_labels.binary_mem_tag_ctr_inv, witness_commitments.binary_mem_tag_ctr_inv); + transcript->send_to_verifier(commitment_labels.binary_op_id, witness_commitments.binary_op_id); + transcript->send_to_verifier(commitment_labels.binary_sel_bin, witness_commitments.binary_sel_bin); + transcript->send_to_verifier(commitment_labels.binary_start, witness_commitments.binary_start); + transcript->send_to_verifier(commitment_labels.byte_lookup_sel_bin, witness_commitments.byte_lookup_sel_bin); + transcript->send_to_verifier(commitment_labels.byte_lookup_table_byte_lengths, + witness_commitments.byte_lookup_table_byte_lengths); + transcript->send_to_verifier(commitment_labels.byte_lookup_table_in_tags, + witness_commitments.byte_lookup_table_in_tags); + transcript->send_to_verifier(commitment_labels.byte_lookup_table_input_a, + witness_commitments.byte_lookup_table_input_a); + transcript->send_to_verifier(commitment_labels.byte_lookup_table_input_b, + witness_commitments.byte_lookup_table_input_b); + transcript->send_to_verifier(commitment_labels.byte_lookup_table_op_id, + witness_commitments.byte_lookup_table_op_id); + transcript->send_to_verifier(commitment_labels.byte_lookup_table_output, + witness_commitments.byte_lookup_table_output); + transcript->send_to_verifier(commitment_labels.conversion_clk, witness_commitments.conversion_clk); + transcript->send_to_verifier(commitment_labels.conversion_input, witness_commitments.conversion_input); + transcript->send_to_verifier(commitment_labels.conversion_num_limbs, witness_commitments.conversion_num_limbs); + transcript->send_to_verifier(commitment_labels.conversion_radix, witness_commitments.conversion_radix); + transcript->send_to_verifier(commitment_labels.conversion_sel_to_radix_le, + witness_commitments.conversion_sel_to_radix_le); + transcript->send_to_verifier(commitment_labels.gas_da_gas_fixed_table, witness_commitments.gas_da_gas_fixed_table); + transcript->send_to_verifier(commitment_labels.gas_l2_gas_fixed_table, witness_commitments.gas_l2_gas_fixed_table); + transcript->send_to_verifier(commitment_labels.gas_sel_gas_cost, witness_commitments.gas_sel_gas_cost); + transcript->send_to_verifier(commitment_labels.keccakf1600_clk, witness_commitments.keccakf1600_clk); + transcript->send_to_verifier(commitment_labels.keccakf1600_input, witness_commitments.keccakf1600_input); + transcript->send_to_verifier(commitment_labels.keccakf1600_output, witness_commitments.keccakf1600_output); + transcript->send_to_verifier(commitment_labels.keccakf1600_sel_keccakf1600, + witness_commitments.keccakf1600_sel_keccakf1600); + transcript->send_to_verifier(commitment_labels.kernel_emit_l2_to_l1_msg_write_offset, + witness_commitments.kernel_emit_l2_to_l1_msg_write_offset); + transcript->send_to_verifier(commitment_labels.kernel_emit_note_hash_write_offset, + witness_commitments.kernel_emit_note_hash_write_offset); + transcript->send_to_verifier(commitment_labels.kernel_emit_nullifier_write_offset, + witness_commitments.kernel_emit_nullifier_write_offset); + transcript->send_to_verifier(commitment_labels.kernel_emit_unencrypted_log_write_offset, + witness_commitments.kernel_emit_unencrypted_log_write_offset); + transcript->send_to_verifier(commitment_labels.kernel_kernel_in_offset, + witness_commitments.kernel_kernel_in_offset); + transcript->send_to_verifier(commitment_labels.kernel_kernel_inputs, witness_commitments.kernel_kernel_inputs); + transcript->send_to_verifier(commitment_labels.kernel_kernel_metadata_out, + witness_commitments.kernel_kernel_metadata_out); + transcript->send_to_verifier(commitment_labels.kernel_kernel_out_offset, + witness_commitments.kernel_kernel_out_offset); + transcript->send_to_verifier(commitment_labels.kernel_kernel_side_effect_out, + witness_commitments.kernel_kernel_side_effect_out); + transcript->send_to_verifier(commitment_labels.kernel_kernel_value_out, + witness_commitments.kernel_kernel_value_out); + transcript->send_to_verifier(commitment_labels.kernel_l1_to_l2_msg_exists_write_offset, + witness_commitments.kernel_l1_to_l2_msg_exists_write_offset); + transcript->send_to_verifier(commitment_labels.kernel_note_hash_exist_write_offset, + witness_commitments.kernel_note_hash_exist_write_offset); + transcript->send_to_verifier(commitment_labels.kernel_nullifier_exists_write_offset, + witness_commitments.kernel_nullifier_exists_write_offset); + transcript->send_to_verifier(commitment_labels.kernel_nullifier_non_exists_write_offset, + witness_commitments.kernel_nullifier_non_exists_write_offset); + transcript->send_to_verifier(commitment_labels.kernel_q_public_input_kernel_add_to_table, + witness_commitments.kernel_q_public_input_kernel_add_to_table); + transcript->send_to_verifier(commitment_labels.kernel_q_public_input_kernel_out_add_to_table, + witness_commitments.kernel_q_public_input_kernel_out_add_to_table); + transcript->send_to_verifier(commitment_labels.kernel_side_effect_counter, + witness_commitments.kernel_side_effect_counter); + transcript->send_to_verifier(commitment_labels.kernel_sload_write_offset, + witness_commitments.kernel_sload_write_offset); + transcript->send_to_verifier(commitment_labels.kernel_sstore_write_offset, + witness_commitments.kernel_sstore_write_offset); + transcript->send_to_verifier(commitment_labels.main_abs_da_rem_gas_hi, witness_commitments.main_abs_da_rem_gas_hi); + transcript->send_to_verifier(commitment_labels.main_abs_da_rem_gas_lo, witness_commitments.main_abs_da_rem_gas_lo); + transcript->send_to_verifier(commitment_labels.main_abs_l2_rem_gas_hi, witness_commitments.main_abs_l2_rem_gas_hi); + transcript->send_to_verifier(commitment_labels.main_abs_l2_rem_gas_lo, witness_commitments.main_abs_l2_rem_gas_lo); + transcript->send_to_verifier(commitment_labels.main_alu_in_tag, witness_commitments.main_alu_in_tag); + transcript->send_to_verifier(commitment_labels.main_bin_op_id, witness_commitments.main_bin_op_id); + transcript->send_to_verifier(commitment_labels.main_call_ptr, witness_commitments.main_call_ptr); + transcript->send_to_verifier(commitment_labels.main_da_gas_op_cost, witness_commitments.main_da_gas_op_cost); + transcript->send_to_verifier(commitment_labels.main_da_gas_remaining, witness_commitments.main_da_gas_remaining); + transcript->send_to_verifier(commitment_labels.main_da_out_of_gas, witness_commitments.main_da_out_of_gas); + transcript->send_to_verifier(commitment_labels.main_ia, witness_commitments.main_ia); + transcript->send_to_verifier(commitment_labels.main_ib, witness_commitments.main_ib); + transcript->send_to_verifier(commitment_labels.main_ic, witness_commitments.main_ic); + transcript->send_to_verifier(commitment_labels.main_id, witness_commitments.main_id); + transcript->send_to_verifier(commitment_labels.main_id_zero, witness_commitments.main_id_zero); + transcript->send_to_verifier(commitment_labels.main_ind_addr_a, witness_commitments.main_ind_addr_a); + transcript->send_to_verifier(commitment_labels.main_ind_addr_b, witness_commitments.main_ind_addr_b); + transcript->send_to_verifier(commitment_labels.main_ind_addr_c, witness_commitments.main_ind_addr_c); + transcript->send_to_verifier(commitment_labels.main_ind_addr_d, witness_commitments.main_ind_addr_d); + transcript->send_to_verifier(commitment_labels.main_internal_return_ptr, + witness_commitments.main_internal_return_ptr); + transcript->send_to_verifier(commitment_labels.main_inv, witness_commitments.main_inv); + transcript->send_to_verifier(commitment_labels.main_l2_gas_op_cost, witness_commitments.main_l2_gas_op_cost); + transcript->send_to_verifier(commitment_labels.main_l2_gas_remaining, witness_commitments.main_l2_gas_remaining); + transcript->send_to_verifier(commitment_labels.main_l2_out_of_gas, witness_commitments.main_l2_out_of_gas); + transcript->send_to_verifier(commitment_labels.main_mem_addr_a, witness_commitments.main_mem_addr_a); + transcript->send_to_verifier(commitment_labels.main_mem_addr_b, witness_commitments.main_mem_addr_b); + transcript->send_to_verifier(commitment_labels.main_mem_addr_c, witness_commitments.main_mem_addr_c); + transcript->send_to_verifier(commitment_labels.main_mem_addr_d, witness_commitments.main_mem_addr_d); + transcript->send_to_verifier(commitment_labels.main_op_err, witness_commitments.main_op_err); + transcript->send_to_verifier(commitment_labels.main_opcode_val, witness_commitments.main_opcode_val); + transcript->send_to_verifier(commitment_labels.main_pc, witness_commitments.main_pc); + transcript->send_to_verifier(commitment_labels.main_r_in_tag, witness_commitments.main_r_in_tag); + transcript->send_to_verifier(commitment_labels.main_rwa, witness_commitments.main_rwa); + transcript->send_to_verifier(commitment_labels.main_rwb, witness_commitments.main_rwb); + transcript->send_to_verifier(commitment_labels.main_rwc, witness_commitments.main_rwc); + transcript->send_to_verifier(commitment_labels.main_rwd, witness_commitments.main_rwd); + transcript->send_to_verifier(commitment_labels.main_sel_alu, witness_commitments.main_sel_alu); + transcript->send_to_verifier(commitment_labels.main_sel_bin, witness_commitments.main_sel_bin); + transcript->send_to_verifier(commitment_labels.main_sel_gas_accounting_active, + witness_commitments.main_sel_gas_accounting_active); + transcript->send_to_verifier(commitment_labels.main_sel_last, witness_commitments.main_sel_last); + transcript->send_to_verifier(commitment_labels.main_sel_mem_op_a, witness_commitments.main_sel_mem_op_a); + transcript->send_to_verifier(commitment_labels.main_sel_mem_op_activate_gas, + witness_commitments.main_sel_mem_op_activate_gas); + transcript->send_to_verifier(commitment_labels.main_sel_mem_op_b, witness_commitments.main_sel_mem_op_b); + transcript->send_to_verifier(commitment_labels.main_sel_mem_op_c, witness_commitments.main_sel_mem_op_c); + transcript->send_to_verifier(commitment_labels.main_sel_mem_op_d, witness_commitments.main_sel_mem_op_d); + transcript->send_to_verifier(commitment_labels.main_sel_mov_ia_to_ic, witness_commitments.main_sel_mov_ia_to_ic); + transcript->send_to_verifier(commitment_labels.main_sel_mov_ib_to_ic, witness_commitments.main_sel_mov_ib_to_ic); + transcript->send_to_verifier(commitment_labels.main_sel_op_add, witness_commitments.main_sel_op_add); + transcript->send_to_verifier(commitment_labels.main_sel_op_address, witness_commitments.main_sel_op_address); + transcript->send_to_verifier(commitment_labels.main_sel_op_and, witness_commitments.main_sel_op_and); + transcript->send_to_verifier(commitment_labels.main_sel_op_block_number, + witness_commitments.main_sel_op_block_number); + transcript->send_to_verifier(commitment_labels.main_sel_op_cast, witness_commitments.main_sel_op_cast); + transcript->send_to_verifier(commitment_labels.main_sel_op_chain_id, witness_commitments.main_sel_op_chain_id); + transcript->send_to_verifier(commitment_labels.main_sel_op_cmov, witness_commitments.main_sel_op_cmov); + transcript->send_to_verifier(commitment_labels.main_sel_op_coinbase, witness_commitments.main_sel_op_coinbase); + transcript->send_to_verifier(commitment_labels.main_sel_op_dagasleft, witness_commitments.main_sel_op_dagasleft); + transcript->send_to_verifier(commitment_labels.main_sel_op_div, witness_commitments.main_sel_op_div); + transcript->send_to_verifier(commitment_labels.main_sel_op_emit_l2_to_l1_msg, + witness_commitments.main_sel_op_emit_l2_to_l1_msg); + transcript->send_to_verifier(commitment_labels.main_sel_op_emit_note_hash, + witness_commitments.main_sel_op_emit_note_hash); + transcript->send_to_verifier(commitment_labels.main_sel_op_emit_nullifier, + witness_commitments.main_sel_op_emit_nullifier); + transcript->send_to_verifier(commitment_labels.main_sel_op_emit_unencrypted_log, + witness_commitments.main_sel_op_emit_unencrypted_log); + transcript->send_to_verifier(commitment_labels.main_sel_op_eq, witness_commitments.main_sel_op_eq); + transcript->send_to_verifier(commitment_labels.main_sel_op_external_call, + witness_commitments.main_sel_op_external_call); + transcript->send_to_verifier(commitment_labels.main_sel_op_fdiv, witness_commitments.main_sel_op_fdiv); + transcript->send_to_verifier(commitment_labels.main_sel_op_fee_per_da_gas, + witness_commitments.main_sel_op_fee_per_da_gas); + transcript->send_to_verifier(commitment_labels.main_sel_op_fee_per_l2_gas, + witness_commitments.main_sel_op_fee_per_l2_gas); + transcript->send_to_verifier(commitment_labels.main_sel_op_get_contract_instance, + witness_commitments.main_sel_op_get_contract_instance); + transcript->send_to_verifier(commitment_labels.main_sel_op_halt, witness_commitments.main_sel_op_halt); + transcript->send_to_verifier(commitment_labels.main_sel_op_internal_call, + witness_commitments.main_sel_op_internal_call); + transcript->send_to_verifier(commitment_labels.main_sel_op_internal_return, + witness_commitments.main_sel_op_internal_return); + transcript->send_to_verifier(commitment_labels.main_sel_op_jump, witness_commitments.main_sel_op_jump); + transcript->send_to_verifier(commitment_labels.main_sel_op_jumpi, witness_commitments.main_sel_op_jumpi); + transcript->send_to_verifier(commitment_labels.main_sel_op_keccak, witness_commitments.main_sel_op_keccak); + transcript->send_to_verifier(commitment_labels.main_sel_op_l1_to_l2_msg_exists, + witness_commitments.main_sel_op_l1_to_l2_msg_exists); + transcript->send_to_verifier(commitment_labels.main_sel_op_l2gasleft, witness_commitments.main_sel_op_l2gasleft); + transcript->send_to_verifier(commitment_labels.main_sel_op_lt, witness_commitments.main_sel_op_lt); + transcript->send_to_verifier(commitment_labels.main_sel_op_lte, witness_commitments.main_sel_op_lte); + transcript->send_to_verifier(commitment_labels.main_sel_op_mov, witness_commitments.main_sel_op_mov); + transcript->send_to_verifier(commitment_labels.main_sel_op_mul, witness_commitments.main_sel_op_mul); + transcript->send_to_verifier(commitment_labels.main_sel_op_not, witness_commitments.main_sel_op_not); + transcript->send_to_verifier(commitment_labels.main_sel_op_note_hash_exists, + witness_commitments.main_sel_op_note_hash_exists); + transcript->send_to_verifier(commitment_labels.main_sel_op_nullifier_exists, + witness_commitments.main_sel_op_nullifier_exists); + transcript->send_to_verifier(commitment_labels.main_sel_op_or, witness_commitments.main_sel_op_or); + transcript->send_to_verifier(commitment_labels.main_sel_op_pedersen, witness_commitments.main_sel_op_pedersen); + transcript->send_to_verifier(commitment_labels.main_sel_op_poseidon2, witness_commitments.main_sel_op_poseidon2); + transcript->send_to_verifier(commitment_labels.main_sel_op_radix_le, witness_commitments.main_sel_op_radix_le); + transcript->send_to_verifier(commitment_labels.main_sel_op_sender, witness_commitments.main_sel_op_sender); + transcript->send_to_verifier(commitment_labels.main_sel_op_sha256, witness_commitments.main_sel_op_sha256); + transcript->send_to_verifier(commitment_labels.main_sel_op_shl, witness_commitments.main_sel_op_shl); + transcript->send_to_verifier(commitment_labels.main_sel_op_shr, witness_commitments.main_sel_op_shr); + transcript->send_to_verifier(commitment_labels.main_sel_op_sload, witness_commitments.main_sel_op_sload); + transcript->send_to_verifier(commitment_labels.main_sel_op_sstore, witness_commitments.main_sel_op_sstore); + transcript->send_to_verifier(commitment_labels.main_sel_op_storage_address, + witness_commitments.main_sel_op_storage_address); + transcript->send_to_verifier(commitment_labels.main_sel_op_sub, witness_commitments.main_sel_op_sub); + transcript->send_to_verifier(commitment_labels.main_sel_op_timestamp, witness_commitments.main_sel_op_timestamp); + transcript->send_to_verifier(commitment_labels.main_sel_op_transaction_fee, + witness_commitments.main_sel_op_transaction_fee); + transcript->send_to_verifier(commitment_labels.main_sel_op_version, witness_commitments.main_sel_op_version); + transcript->send_to_verifier(commitment_labels.main_sel_op_xor, witness_commitments.main_sel_op_xor); + transcript->send_to_verifier(commitment_labels.main_sel_q_kernel_lookup, + witness_commitments.main_sel_q_kernel_lookup); + transcript->send_to_verifier(commitment_labels.main_sel_q_kernel_output_lookup, + witness_commitments.main_sel_q_kernel_output_lookup); + transcript->send_to_verifier(commitment_labels.main_sel_resolve_ind_addr_a, + witness_commitments.main_sel_resolve_ind_addr_a); + transcript->send_to_verifier(commitment_labels.main_sel_resolve_ind_addr_b, + witness_commitments.main_sel_resolve_ind_addr_b); + transcript->send_to_verifier(commitment_labels.main_sel_resolve_ind_addr_c, + witness_commitments.main_sel_resolve_ind_addr_c); + transcript->send_to_verifier(commitment_labels.main_sel_resolve_ind_addr_d, + witness_commitments.main_sel_resolve_ind_addr_d); + transcript->send_to_verifier(commitment_labels.main_sel_rng_16, witness_commitments.main_sel_rng_16); + transcript->send_to_verifier(commitment_labels.main_sel_rng_8, witness_commitments.main_sel_rng_8); + transcript->send_to_verifier(commitment_labels.main_space_id, witness_commitments.main_space_id); + transcript->send_to_verifier(commitment_labels.main_table_pow_2, witness_commitments.main_table_pow_2); + transcript->send_to_verifier(commitment_labels.main_tag_err, witness_commitments.main_tag_err); + transcript->send_to_verifier(commitment_labels.main_w_in_tag, witness_commitments.main_w_in_tag); + transcript->send_to_verifier(commitment_labels.mem_addr, witness_commitments.mem_addr); + transcript->send_to_verifier(commitment_labels.mem_clk, witness_commitments.mem_clk); + transcript->send_to_verifier(commitment_labels.mem_diff_hi, witness_commitments.mem_diff_hi); + transcript->send_to_verifier(commitment_labels.mem_diff_lo, witness_commitments.mem_diff_lo); + transcript->send_to_verifier(commitment_labels.mem_diff_mid, witness_commitments.mem_diff_mid); + transcript->send_to_verifier(commitment_labels.mem_glob_addr, witness_commitments.mem_glob_addr); + transcript->send_to_verifier(commitment_labels.mem_last, witness_commitments.mem_last); + transcript->send_to_verifier(commitment_labels.mem_lastAccess, witness_commitments.mem_lastAccess); + transcript->send_to_verifier(commitment_labels.mem_one_min_inv, witness_commitments.mem_one_min_inv); + transcript->send_to_verifier(commitment_labels.mem_r_in_tag, witness_commitments.mem_r_in_tag); + transcript->send_to_verifier(commitment_labels.mem_rw, witness_commitments.mem_rw); + transcript->send_to_verifier(commitment_labels.mem_sel_mem, witness_commitments.mem_sel_mem); + transcript->send_to_verifier(commitment_labels.mem_sel_mov_ia_to_ic, witness_commitments.mem_sel_mov_ia_to_ic); + transcript->send_to_verifier(commitment_labels.mem_sel_mov_ib_to_ic, witness_commitments.mem_sel_mov_ib_to_ic); + transcript->send_to_verifier(commitment_labels.mem_sel_op_a, witness_commitments.mem_sel_op_a); + transcript->send_to_verifier(commitment_labels.mem_sel_op_b, witness_commitments.mem_sel_op_b); + transcript->send_to_verifier(commitment_labels.mem_sel_op_c, witness_commitments.mem_sel_op_c); + transcript->send_to_verifier(commitment_labels.mem_sel_op_cmov, witness_commitments.mem_sel_op_cmov); + transcript->send_to_verifier(commitment_labels.mem_sel_op_d, witness_commitments.mem_sel_op_d); + transcript->send_to_verifier(commitment_labels.mem_sel_resolve_ind_addr_a, + witness_commitments.mem_sel_resolve_ind_addr_a); + transcript->send_to_verifier(commitment_labels.mem_sel_resolve_ind_addr_b, + witness_commitments.mem_sel_resolve_ind_addr_b); + transcript->send_to_verifier(commitment_labels.mem_sel_resolve_ind_addr_c, + witness_commitments.mem_sel_resolve_ind_addr_c); + transcript->send_to_verifier(commitment_labels.mem_sel_resolve_ind_addr_d, + witness_commitments.mem_sel_resolve_ind_addr_d); + transcript->send_to_verifier(commitment_labels.mem_sel_rng_chk, witness_commitments.mem_sel_rng_chk); + transcript->send_to_verifier(commitment_labels.mem_skip_check_tag, witness_commitments.mem_skip_check_tag); + transcript->send_to_verifier(commitment_labels.mem_space_id, witness_commitments.mem_space_id); + transcript->send_to_verifier(commitment_labels.mem_tag, witness_commitments.mem_tag); + transcript->send_to_verifier(commitment_labels.mem_tag_err, witness_commitments.mem_tag_err); + transcript->send_to_verifier(commitment_labels.mem_tsp, witness_commitments.mem_tsp); + transcript->send_to_verifier(commitment_labels.mem_val, witness_commitments.mem_val); + transcript->send_to_verifier(commitment_labels.mem_w_in_tag, witness_commitments.mem_w_in_tag); + transcript->send_to_verifier(commitment_labels.pedersen_clk, witness_commitments.pedersen_clk); + transcript->send_to_verifier(commitment_labels.pedersen_input, witness_commitments.pedersen_input); + transcript->send_to_verifier(commitment_labels.pedersen_output, witness_commitments.pedersen_output); + transcript->send_to_verifier(commitment_labels.pedersen_sel_pedersen, witness_commitments.pedersen_sel_pedersen); + transcript->send_to_verifier(commitment_labels.poseidon2_clk, witness_commitments.poseidon2_clk); + transcript->send_to_verifier(commitment_labels.poseidon2_input, witness_commitments.poseidon2_input); + transcript->send_to_verifier(commitment_labels.poseidon2_output, witness_commitments.poseidon2_output); + transcript->send_to_verifier(commitment_labels.poseidon2_sel_poseidon_perm, + witness_commitments.poseidon2_sel_poseidon_perm); + transcript->send_to_verifier(commitment_labels.sha256_clk, witness_commitments.sha256_clk); + transcript->send_to_verifier(commitment_labels.sha256_input, witness_commitments.sha256_input); + transcript->send_to_verifier(commitment_labels.sha256_output, witness_commitments.sha256_output); + transcript->send_to_verifier(commitment_labels.sha256_sel_sha256_compression, + witness_commitments.sha256_sel_sha256_compression); + transcript->send_to_verifier(commitment_labels.sha256_state, witness_commitments.sha256_state); transcript->send_to_verifier(commitment_labels.lookup_byte_lengths_counts, witness_commitments.lookup_byte_lengths_counts); transcript->send_to_verifier(commitment_labels.lookup_byte_operations_counts, @@ -859,10 +831,10 @@ void AvmProver::execute_log_derivative_inverse_round() witness_commitments.perm_main_mem_b = commitment_key->commit(key->perm_main_mem_b); witness_commitments.perm_main_mem_c = commitment_key->commit(key->perm_main_mem_c); witness_commitments.perm_main_mem_d = commitment_key->commit(key->perm_main_mem_d); - witness_commitments.perm_main_mem_ind_a = commitment_key->commit(key->perm_main_mem_ind_a); - witness_commitments.perm_main_mem_ind_b = commitment_key->commit(key->perm_main_mem_ind_b); - witness_commitments.perm_main_mem_ind_c = commitment_key->commit(key->perm_main_mem_ind_c); - witness_commitments.perm_main_mem_ind_d = commitment_key->commit(key->perm_main_mem_ind_d); + witness_commitments.perm_main_mem_ind_addr_a = commitment_key->commit(key->perm_main_mem_ind_addr_a); + witness_commitments.perm_main_mem_ind_addr_b = commitment_key->commit(key->perm_main_mem_ind_addr_b); + witness_commitments.perm_main_mem_ind_addr_c = commitment_key->commit(key->perm_main_mem_ind_addr_c); + witness_commitments.perm_main_mem_ind_addr_d = commitment_key->commit(key->perm_main_mem_ind_addr_d); witness_commitments.lookup_byte_lengths = commitment_key->commit(key->lookup_byte_lengths); witness_commitments.lookup_byte_operations = commitment_key->commit(key->lookup_byte_operations); witness_commitments.lookup_opcode_gas = commitment_key->commit(key->lookup_opcode_gas); @@ -915,10 +887,14 @@ void AvmProver::execute_log_derivative_inverse_round() transcript->send_to_verifier(commitment_labels.perm_main_mem_b, witness_commitments.perm_main_mem_b); transcript->send_to_verifier(commitment_labels.perm_main_mem_c, witness_commitments.perm_main_mem_c); transcript->send_to_verifier(commitment_labels.perm_main_mem_d, witness_commitments.perm_main_mem_d); - transcript->send_to_verifier(commitment_labels.perm_main_mem_ind_a, witness_commitments.perm_main_mem_ind_a); - transcript->send_to_verifier(commitment_labels.perm_main_mem_ind_b, witness_commitments.perm_main_mem_ind_b); - transcript->send_to_verifier(commitment_labels.perm_main_mem_ind_c, witness_commitments.perm_main_mem_ind_c); - transcript->send_to_verifier(commitment_labels.perm_main_mem_ind_d, witness_commitments.perm_main_mem_ind_d); + transcript->send_to_verifier(commitment_labels.perm_main_mem_ind_addr_a, + witness_commitments.perm_main_mem_ind_addr_a); + transcript->send_to_verifier(commitment_labels.perm_main_mem_ind_addr_b, + witness_commitments.perm_main_mem_ind_addr_b); + transcript->send_to_verifier(commitment_labels.perm_main_mem_ind_addr_c, + witness_commitments.perm_main_mem_ind_addr_c); + transcript->send_to_verifier(commitment_labels.perm_main_mem_ind_addr_d, + witness_commitments.perm_main_mem_ind_addr_d); transcript->send_to_verifier(commitment_labels.lookup_byte_lengths, witness_commitments.lookup_byte_lengths); transcript->send_to_verifier(commitment_labels.lookup_byte_operations, witness_commitments.lookup_byte_operations); transcript->send_to_verifier(commitment_labels.lookup_opcode_gas, witness_commitments.lookup_opcode_gas); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp index 70dcfeda257..32cb192f93a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp @@ -70,518 +70,452 @@ bool AvmVerifier::verify_proof(const HonkProof& proof, const std::vectortemplate receive_from_prover(commitment_labels.avm_alu_a_hi); - commitments.avm_alu_a_lo = transcript->template receive_from_prover(commitment_labels.avm_alu_a_lo); - commitments.avm_alu_alu_sel = - transcript->template receive_from_prover(commitment_labels.avm_alu_alu_sel); - commitments.avm_alu_b_hi = transcript->template receive_from_prover(commitment_labels.avm_alu_b_hi); - commitments.avm_alu_b_lo = transcript->template receive_from_prover(commitment_labels.avm_alu_b_lo); - commitments.avm_alu_borrow = transcript->template receive_from_prover(commitment_labels.avm_alu_borrow); - commitments.avm_alu_cf = transcript->template receive_from_prover(commitment_labels.avm_alu_cf); - commitments.avm_alu_clk = transcript->template receive_from_prover(commitment_labels.avm_alu_clk); - commitments.avm_alu_cmp_rng_ctr = - transcript->template receive_from_prover(commitment_labels.avm_alu_cmp_rng_ctr); - commitments.avm_alu_cmp_sel = - transcript->template receive_from_prover(commitment_labels.avm_alu_cmp_sel); - commitments.avm_alu_div_rng_chk_selector = - transcript->template receive_from_prover(commitment_labels.avm_alu_div_rng_chk_selector); - commitments.avm_alu_div_u16_r0 = - transcript->template receive_from_prover(commitment_labels.avm_alu_div_u16_r0); - commitments.avm_alu_div_u16_r1 = - transcript->template receive_from_prover(commitment_labels.avm_alu_div_u16_r1); - commitments.avm_alu_div_u16_r2 = - transcript->template receive_from_prover(commitment_labels.avm_alu_div_u16_r2); - commitments.avm_alu_div_u16_r3 = - transcript->template receive_from_prover(commitment_labels.avm_alu_div_u16_r3); - commitments.avm_alu_div_u16_r4 = - transcript->template receive_from_prover(commitment_labels.avm_alu_div_u16_r4); - commitments.avm_alu_div_u16_r5 = - transcript->template receive_from_prover(commitment_labels.avm_alu_div_u16_r5); - commitments.avm_alu_div_u16_r6 = - transcript->template receive_from_prover(commitment_labels.avm_alu_div_u16_r6); - commitments.avm_alu_div_u16_r7 = - transcript->template receive_from_prover(commitment_labels.avm_alu_div_u16_r7); - commitments.avm_alu_divisor_hi = - transcript->template receive_from_prover(commitment_labels.avm_alu_divisor_hi); - commitments.avm_alu_divisor_lo = - transcript->template receive_from_prover(commitment_labels.avm_alu_divisor_lo); - commitments.avm_alu_ff_tag = transcript->template receive_from_prover(commitment_labels.avm_alu_ff_tag); - commitments.avm_alu_ia = transcript->template receive_from_prover(commitment_labels.avm_alu_ia); - commitments.avm_alu_ib = transcript->template receive_from_prover(commitment_labels.avm_alu_ib); - commitments.avm_alu_ic = transcript->template receive_from_prover(commitment_labels.avm_alu_ic); - commitments.avm_alu_in_tag = transcript->template receive_from_prover(commitment_labels.avm_alu_in_tag); - commitments.avm_alu_op_add = transcript->template receive_from_prover(commitment_labels.avm_alu_op_add); - commitments.avm_alu_op_cast = - transcript->template receive_from_prover(commitment_labels.avm_alu_op_cast); - commitments.avm_alu_op_cast_prev = - transcript->template receive_from_prover(commitment_labels.avm_alu_op_cast_prev); - commitments.avm_alu_op_div = transcript->template receive_from_prover(commitment_labels.avm_alu_op_div); - commitments.avm_alu_op_div_a_lt_b = - transcript->template receive_from_prover(commitment_labels.avm_alu_op_div_a_lt_b); - commitments.avm_alu_op_div_std = - transcript->template receive_from_prover(commitment_labels.avm_alu_op_div_std); - commitments.avm_alu_op_eq = transcript->template receive_from_prover(commitment_labels.avm_alu_op_eq); - commitments.avm_alu_op_eq_diff_inv = - transcript->template receive_from_prover(commitment_labels.avm_alu_op_eq_diff_inv); - commitments.avm_alu_op_lt = transcript->template receive_from_prover(commitment_labels.avm_alu_op_lt); - commitments.avm_alu_op_lte = transcript->template receive_from_prover(commitment_labels.avm_alu_op_lte); - commitments.avm_alu_op_mul = transcript->template receive_from_prover(commitment_labels.avm_alu_op_mul); - commitments.avm_alu_op_not = transcript->template receive_from_prover(commitment_labels.avm_alu_op_not); - commitments.avm_alu_op_shl = transcript->template receive_from_prover(commitment_labels.avm_alu_op_shl); - commitments.avm_alu_op_shr = transcript->template receive_from_prover(commitment_labels.avm_alu_op_shr); - commitments.avm_alu_op_sub = transcript->template receive_from_prover(commitment_labels.avm_alu_op_sub); - commitments.avm_alu_p_a_borrow = - transcript->template receive_from_prover(commitment_labels.avm_alu_p_a_borrow); - commitments.avm_alu_p_b_borrow = - transcript->template receive_from_prover(commitment_labels.avm_alu_p_b_borrow); - commitments.avm_alu_p_sub_a_hi = - transcript->template receive_from_prover(commitment_labels.avm_alu_p_sub_a_hi); - commitments.avm_alu_p_sub_a_lo = - transcript->template receive_from_prover(commitment_labels.avm_alu_p_sub_a_lo); - commitments.avm_alu_p_sub_b_hi = - transcript->template receive_from_prover(commitment_labels.avm_alu_p_sub_b_hi); - commitments.avm_alu_p_sub_b_lo = - transcript->template receive_from_prover(commitment_labels.avm_alu_p_sub_b_lo); - commitments.avm_alu_partial_prod_hi = - transcript->template receive_from_prover(commitment_labels.avm_alu_partial_prod_hi); - commitments.avm_alu_partial_prod_lo = - transcript->template receive_from_prover(commitment_labels.avm_alu_partial_prod_lo); - commitments.avm_alu_quotient_hi = - transcript->template receive_from_prover(commitment_labels.avm_alu_quotient_hi); - commitments.avm_alu_quotient_lo = - transcript->template receive_from_prover(commitment_labels.avm_alu_quotient_lo); - commitments.avm_alu_remainder = - transcript->template receive_from_prover(commitment_labels.avm_alu_remainder); - commitments.avm_alu_res_hi = transcript->template receive_from_prover(commitment_labels.avm_alu_res_hi); - commitments.avm_alu_res_lo = transcript->template receive_from_prover(commitment_labels.avm_alu_res_lo); - commitments.avm_alu_rng_chk_lookup_selector = - transcript->template receive_from_prover(commitment_labels.avm_alu_rng_chk_lookup_selector); - commitments.avm_alu_rng_chk_sel = - transcript->template receive_from_prover(commitment_labels.avm_alu_rng_chk_sel); - commitments.avm_alu_shift_lt_bit_len = - transcript->template receive_from_prover(commitment_labels.avm_alu_shift_lt_bit_len); - commitments.avm_alu_shift_sel = - transcript->template receive_from_prover(commitment_labels.avm_alu_shift_sel); - commitments.avm_alu_t_sub_s_bits = - transcript->template receive_from_prover(commitment_labels.avm_alu_t_sub_s_bits); - commitments.avm_alu_two_pow_s = - transcript->template receive_from_prover(commitment_labels.avm_alu_two_pow_s); - commitments.avm_alu_two_pow_t_sub_s = - transcript->template receive_from_prover(commitment_labels.avm_alu_two_pow_t_sub_s); - commitments.avm_alu_u128_tag = - transcript->template receive_from_prover(commitment_labels.avm_alu_u128_tag); - commitments.avm_alu_u16_r0 = transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r0); - commitments.avm_alu_u16_r1 = transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r1); - commitments.avm_alu_u16_r10 = - transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r10); - commitments.avm_alu_u16_r11 = - transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r11); - commitments.avm_alu_u16_r12 = - transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r12); - commitments.avm_alu_u16_r13 = - transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r13); - commitments.avm_alu_u16_r14 = - transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r14); - commitments.avm_alu_u16_r2 = transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r2); - commitments.avm_alu_u16_r3 = transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r3); - commitments.avm_alu_u16_r4 = transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r4); - commitments.avm_alu_u16_r5 = transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r5); - commitments.avm_alu_u16_r6 = transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r6); - commitments.avm_alu_u16_r7 = transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r7); - commitments.avm_alu_u16_r8 = transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r8); - commitments.avm_alu_u16_r9 = transcript->template receive_from_prover(commitment_labels.avm_alu_u16_r9); - commitments.avm_alu_u16_tag = - transcript->template receive_from_prover(commitment_labels.avm_alu_u16_tag); - commitments.avm_alu_u32_tag = - transcript->template receive_from_prover(commitment_labels.avm_alu_u32_tag); - commitments.avm_alu_u64_tag = - transcript->template receive_from_prover(commitment_labels.avm_alu_u64_tag); - commitments.avm_alu_u8_r0 = transcript->template receive_from_prover(commitment_labels.avm_alu_u8_r0); - commitments.avm_alu_u8_r1 = transcript->template receive_from_prover(commitment_labels.avm_alu_u8_r1); - commitments.avm_alu_u8_tag = transcript->template receive_from_prover(commitment_labels.avm_alu_u8_tag); - commitments.avm_binary_acc_ia = - transcript->template receive_from_prover(commitment_labels.avm_binary_acc_ia); - commitments.avm_binary_acc_ib = - transcript->template receive_from_prover(commitment_labels.avm_binary_acc_ib); - commitments.avm_binary_acc_ic = - transcript->template receive_from_prover(commitment_labels.avm_binary_acc_ic); - commitments.avm_binary_bin_sel = - transcript->template receive_from_prover(commitment_labels.avm_binary_bin_sel); - commitments.avm_binary_clk = transcript->template receive_from_prover(commitment_labels.avm_binary_clk); - commitments.avm_binary_ia_bytes = - transcript->template receive_from_prover(commitment_labels.avm_binary_ia_bytes); - commitments.avm_binary_ib_bytes = - transcript->template receive_from_prover(commitment_labels.avm_binary_ib_bytes); - commitments.avm_binary_ic_bytes = - transcript->template receive_from_prover(commitment_labels.avm_binary_ic_bytes); - commitments.avm_binary_in_tag = - transcript->template receive_from_prover(commitment_labels.avm_binary_in_tag); - commitments.avm_binary_mem_tag_ctr = - transcript->template receive_from_prover(commitment_labels.avm_binary_mem_tag_ctr); - commitments.avm_binary_mem_tag_ctr_inv = - transcript->template receive_from_prover(commitment_labels.avm_binary_mem_tag_ctr_inv); - commitments.avm_binary_op_id = - transcript->template receive_from_prover(commitment_labels.avm_binary_op_id); - commitments.avm_binary_start = - transcript->template receive_from_prover(commitment_labels.avm_binary_start); - commitments.avm_byte_lookup_bin_sel = - transcript->template receive_from_prover(commitment_labels.avm_byte_lookup_bin_sel); - commitments.avm_byte_lookup_table_byte_lengths = - transcript->template receive_from_prover(commitment_labels.avm_byte_lookup_table_byte_lengths); - commitments.avm_byte_lookup_table_in_tags = - transcript->template receive_from_prover(commitment_labels.avm_byte_lookup_table_in_tags); - commitments.avm_byte_lookup_table_input_a = - transcript->template receive_from_prover(commitment_labels.avm_byte_lookup_table_input_a); - commitments.avm_byte_lookup_table_input_b = - transcript->template receive_from_prover(commitment_labels.avm_byte_lookup_table_input_b); - commitments.avm_byte_lookup_table_op_id = - transcript->template receive_from_prover(commitment_labels.avm_byte_lookup_table_op_id); - commitments.avm_byte_lookup_table_output = - transcript->template receive_from_prover(commitment_labels.avm_byte_lookup_table_output); - commitments.avm_conversion_clk = - transcript->template receive_from_prover(commitment_labels.avm_conversion_clk); - commitments.avm_conversion_input = - transcript->template receive_from_prover(commitment_labels.avm_conversion_input); - commitments.avm_conversion_num_limbs = - transcript->template receive_from_prover(commitment_labels.avm_conversion_num_limbs); - commitments.avm_conversion_radix = - transcript->template receive_from_prover(commitment_labels.avm_conversion_radix); - commitments.avm_conversion_to_radix_le_sel = - transcript->template receive_from_prover(commitment_labels.avm_conversion_to_radix_le_sel); - commitments.avm_gas_da_gas_fixed_table = - transcript->template receive_from_prover(commitment_labels.avm_gas_da_gas_fixed_table); - commitments.avm_gas_gas_cost_sel = - transcript->template receive_from_prover(commitment_labels.avm_gas_gas_cost_sel); - commitments.avm_gas_l2_gas_fixed_table = - transcript->template receive_from_prover(commitment_labels.avm_gas_l2_gas_fixed_table); - commitments.avm_keccakf1600_clk = - transcript->template receive_from_prover(commitment_labels.avm_keccakf1600_clk); - commitments.avm_keccakf1600_input = - transcript->template receive_from_prover(commitment_labels.avm_keccakf1600_input); - commitments.avm_keccakf1600_keccakf1600_sel = - transcript->template receive_from_prover(commitment_labels.avm_keccakf1600_keccakf1600_sel); - commitments.avm_keccakf1600_output = - transcript->template receive_from_prover(commitment_labels.avm_keccakf1600_output); - commitments.avm_kernel_emit_l2_to_l1_msg_write_offset = transcript->template receive_from_prover( - commitment_labels.avm_kernel_emit_l2_to_l1_msg_write_offset); - commitments.avm_kernel_emit_note_hash_write_offset = - transcript->template receive_from_prover(commitment_labels.avm_kernel_emit_note_hash_write_offset); - commitments.avm_kernel_emit_nullifier_write_offset = - transcript->template receive_from_prover(commitment_labels.avm_kernel_emit_nullifier_write_offset); - commitments.avm_kernel_emit_unencrypted_log_write_offset = transcript->template receive_from_prover( - commitment_labels.avm_kernel_emit_unencrypted_log_write_offset); - commitments.avm_kernel_kernel_in_offset = - transcript->template receive_from_prover(commitment_labels.avm_kernel_kernel_in_offset); - commitments.avm_kernel_kernel_inputs = - transcript->template receive_from_prover(commitment_labels.avm_kernel_kernel_inputs); - commitments.avm_kernel_kernel_metadata_out = - transcript->template receive_from_prover(commitment_labels.avm_kernel_kernel_metadata_out); - commitments.avm_kernel_kernel_out_offset = - transcript->template receive_from_prover(commitment_labels.avm_kernel_kernel_out_offset); - commitments.avm_kernel_kernel_side_effect_out = - transcript->template receive_from_prover(commitment_labels.avm_kernel_kernel_side_effect_out); - commitments.avm_kernel_kernel_value_out = - transcript->template receive_from_prover(commitment_labels.avm_kernel_kernel_value_out); - commitments.avm_kernel_l1_to_l2_msg_exists_write_offset = transcript->template receive_from_prover( - commitment_labels.avm_kernel_l1_to_l2_msg_exists_write_offset); - commitments.avm_kernel_note_hash_exist_write_offset = - transcript->template receive_from_prover(commitment_labels.avm_kernel_note_hash_exist_write_offset); - commitments.avm_kernel_nullifier_exists_write_offset = transcript->template receive_from_prover( - commitment_labels.avm_kernel_nullifier_exists_write_offset); - commitments.avm_kernel_nullifier_non_exists_write_offset = transcript->template receive_from_prover( - commitment_labels.avm_kernel_nullifier_non_exists_write_offset); - commitments.avm_kernel_q_public_input_kernel_add_to_table = transcript->template receive_from_prover( - commitment_labels.avm_kernel_q_public_input_kernel_add_to_table); - commitments.avm_kernel_q_public_input_kernel_out_add_to_table = - transcript->template receive_from_prover( - commitment_labels.avm_kernel_q_public_input_kernel_out_add_to_table); - commitments.avm_kernel_side_effect_counter = - transcript->template receive_from_prover(commitment_labels.avm_kernel_side_effect_counter); - commitments.avm_kernel_sload_write_offset = - transcript->template receive_from_prover(commitment_labels.avm_kernel_sload_write_offset); - commitments.avm_kernel_sstore_write_offset = - transcript->template receive_from_prover(commitment_labels.avm_kernel_sstore_write_offset); - commitments.avm_main_abs_da_rem_gas_hi = - transcript->template receive_from_prover(commitment_labels.avm_main_abs_da_rem_gas_hi); - commitments.avm_main_abs_da_rem_gas_lo = - transcript->template receive_from_prover(commitment_labels.avm_main_abs_da_rem_gas_lo); - commitments.avm_main_abs_l2_rem_gas_hi = - transcript->template receive_from_prover(commitment_labels.avm_main_abs_l2_rem_gas_hi); - commitments.avm_main_abs_l2_rem_gas_lo = - transcript->template receive_from_prover(commitment_labels.avm_main_abs_l2_rem_gas_lo); - commitments.avm_main_alu_in_tag = - transcript->template receive_from_prover(commitment_labels.avm_main_alu_in_tag); - commitments.avm_main_alu_sel = - transcript->template receive_from_prover(commitment_labels.avm_main_alu_sel); - commitments.avm_main_bin_op_id = - transcript->template receive_from_prover(commitment_labels.avm_main_bin_op_id); - commitments.avm_main_bin_sel = - transcript->template receive_from_prover(commitment_labels.avm_main_bin_sel); - commitments.avm_main_call_ptr = - transcript->template receive_from_prover(commitment_labels.avm_main_call_ptr); - commitments.avm_main_da_gas_op = - transcript->template receive_from_prover(commitment_labels.avm_main_da_gas_op); - commitments.avm_main_da_gas_remaining = - transcript->template receive_from_prover(commitment_labels.avm_main_da_gas_remaining); - commitments.avm_main_da_out_of_gas = - transcript->template receive_from_prover(commitment_labels.avm_main_da_out_of_gas); - commitments.avm_main_gas_cost_active = - transcript->template receive_from_prover(commitment_labels.avm_main_gas_cost_active); - commitments.avm_main_ia = transcript->template receive_from_prover(commitment_labels.avm_main_ia); - commitments.avm_main_ib = transcript->template receive_from_prover(commitment_labels.avm_main_ib); - commitments.avm_main_ic = transcript->template receive_from_prover(commitment_labels.avm_main_ic); - commitments.avm_main_id = transcript->template receive_from_prover(commitment_labels.avm_main_id); - commitments.avm_main_id_zero = - transcript->template receive_from_prover(commitment_labels.avm_main_id_zero); - commitments.avm_main_ind_a = transcript->template receive_from_prover(commitment_labels.avm_main_ind_a); - commitments.avm_main_ind_b = transcript->template receive_from_prover(commitment_labels.avm_main_ind_b); - commitments.avm_main_ind_c = transcript->template receive_from_prover(commitment_labels.avm_main_ind_c); - commitments.avm_main_ind_d = transcript->template receive_from_prover(commitment_labels.avm_main_ind_d); - commitments.avm_main_ind_op_a = - transcript->template receive_from_prover(commitment_labels.avm_main_ind_op_a); - commitments.avm_main_ind_op_b = - transcript->template receive_from_prover(commitment_labels.avm_main_ind_op_b); - commitments.avm_main_ind_op_c = - transcript->template receive_from_prover(commitment_labels.avm_main_ind_op_c); - commitments.avm_main_ind_op_d = - transcript->template receive_from_prover(commitment_labels.avm_main_ind_op_d); - commitments.avm_main_internal_return_ptr = - transcript->template receive_from_prover(commitment_labels.avm_main_internal_return_ptr); - commitments.avm_main_inv = transcript->template receive_from_prover(commitment_labels.avm_main_inv); - commitments.avm_main_l2_gas_op = - transcript->template receive_from_prover(commitment_labels.avm_main_l2_gas_op); - commitments.avm_main_l2_gas_remaining = - transcript->template receive_from_prover(commitment_labels.avm_main_l2_gas_remaining); - commitments.avm_main_l2_out_of_gas = - transcript->template receive_from_prover(commitment_labels.avm_main_l2_out_of_gas); - commitments.avm_main_last = transcript->template receive_from_prover(commitment_labels.avm_main_last); - commitments.avm_main_mem_idx_a = - transcript->template receive_from_prover(commitment_labels.avm_main_mem_idx_a); - commitments.avm_main_mem_idx_b = - transcript->template receive_from_prover(commitment_labels.avm_main_mem_idx_b); - commitments.avm_main_mem_idx_c = - transcript->template receive_from_prover(commitment_labels.avm_main_mem_idx_c); - commitments.avm_main_mem_idx_d = - transcript->template receive_from_prover(commitment_labels.avm_main_mem_idx_d); - commitments.avm_main_mem_op_a = - transcript->template receive_from_prover(commitment_labels.avm_main_mem_op_a); - commitments.avm_main_mem_op_activate_gas = - transcript->template receive_from_prover(commitment_labels.avm_main_mem_op_activate_gas); - commitments.avm_main_mem_op_b = - transcript->template receive_from_prover(commitment_labels.avm_main_mem_op_b); - commitments.avm_main_mem_op_c = - transcript->template receive_from_prover(commitment_labels.avm_main_mem_op_c); - commitments.avm_main_mem_op_d = - transcript->template receive_from_prover(commitment_labels.avm_main_mem_op_d); - commitments.avm_main_op_err = - transcript->template receive_from_prover(commitment_labels.avm_main_op_err); - commitments.avm_main_opcode_val = - transcript->template receive_from_prover(commitment_labels.avm_main_opcode_val); - commitments.avm_main_pc = transcript->template receive_from_prover(commitment_labels.avm_main_pc); - commitments.avm_main_q_kernel_lookup = - transcript->template receive_from_prover(commitment_labels.avm_main_q_kernel_lookup); - commitments.avm_main_q_kernel_output_lookup = - transcript->template receive_from_prover(commitment_labels.avm_main_q_kernel_output_lookup); - commitments.avm_main_r_in_tag = - transcript->template receive_from_prover(commitment_labels.avm_main_r_in_tag); - commitments.avm_main_rwa = transcript->template receive_from_prover(commitment_labels.avm_main_rwa); - commitments.avm_main_rwb = transcript->template receive_from_prover(commitment_labels.avm_main_rwb); - commitments.avm_main_rwc = transcript->template receive_from_prover(commitment_labels.avm_main_rwc); - commitments.avm_main_rwd = transcript->template receive_from_prover(commitment_labels.avm_main_rwd); - commitments.avm_main_sel_cmov = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_cmov); - commitments.avm_main_sel_external_call = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_external_call); - commitments.avm_main_sel_halt = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_halt); - commitments.avm_main_sel_internal_call = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_internal_call); - commitments.avm_main_sel_internal_return = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_internal_return); - commitments.avm_main_sel_jump = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_jump); - commitments.avm_main_sel_jumpi = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_jumpi); - commitments.avm_main_sel_mov = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_mov); - commitments.avm_main_sel_mov_a = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_mov_a); - commitments.avm_main_sel_mov_b = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_mov_b); - commitments.avm_main_sel_op_add = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_add); - commitments.avm_main_sel_op_address = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_address); - commitments.avm_main_sel_op_and = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_and); - commitments.avm_main_sel_op_block_number = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_block_number); - commitments.avm_main_sel_op_cast = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_cast); - commitments.avm_main_sel_op_chain_id = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_chain_id); - commitments.avm_main_sel_op_coinbase = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_coinbase); - commitments.avm_main_sel_op_dagasleft = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_dagasleft); - commitments.avm_main_sel_op_div = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_div); - commitments.avm_main_sel_op_emit_l2_to_l1_msg = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_emit_l2_to_l1_msg); - commitments.avm_main_sel_op_emit_note_hash = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_emit_note_hash); - commitments.avm_main_sel_op_emit_nullifier = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_emit_nullifier); - commitments.avm_main_sel_op_emit_unencrypted_log = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_emit_unencrypted_log); - commitments.avm_main_sel_op_eq = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_eq); - commitments.avm_main_sel_op_fdiv = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_fdiv); - commitments.avm_main_sel_op_fee_per_da_gas = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_fee_per_da_gas); - commitments.avm_main_sel_op_fee_per_l2_gas = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_fee_per_l2_gas); - commitments.avm_main_sel_op_get_contract_instance = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_get_contract_instance); - commitments.avm_main_sel_op_keccak = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_keccak); - commitments.avm_main_sel_op_l1_to_l2_msg_exists = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_l1_to_l2_msg_exists); - commitments.avm_main_sel_op_l2gasleft = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_l2gasleft); - commitments.avm_main_sel_op_lt = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_lt); - commitments.avm_main_sel_op_lte = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_lte); - commitments.avm_main_sel_op_mul = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_mul); - commitments.avm_main_sel_op_not = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_not); - commitments.avm_main_sel_op_note_hash_exists = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_note_hash_exists); - commitments.avm_main_sel_op_nullifier_exists = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_nullifier_exists); - commitments.avm_main_sel_op_or = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_or); - commitments.avm_main_sel_op_pedersen = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_pedersen); - commitments.avm_main_sel_op_poseidon2 = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_poseidon2); - commitments.avm_main_sel_op_radix_le = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_radix_le); - commitments.avm_main_sel_op_sender = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_sender); - commitments.avm_main_sel_op_sha256 = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_sha256); - commitments.avm_main_sel_op_shl = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_shl); - commitments.avm_main_sel_op_shr = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_shr); - commitments.avm_main_sel_op_sload = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_sload); - commitments.avm_main_sel_op_sstore = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_sstore); - commitments.avm_main_sel_op_storage_address = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_storage_address); - commitments.avm_main_sel_op_sub = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_sub); - commitments.avm_main_sel_op_timestamp = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_timestamp); - commitments.avm_main_sel_op_transaction_fee = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_transaction_fee); - commitments.avm_main_sel_op_version = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_version); - commitments.avm_main_sel_op_xor = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_op_xor); - commitments.avm_main_sel_rng_16 = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_rng_16); - commitments.avm_main_sel_rng_8 = - transcript->template receive_from_prover(commitment_labels.avm_main_sel_rng_8); - commitments.avm_main_space_id = - transcript->template receive_from_prover(commitment_labels.avm_main_space_id); - commitments.avm_main_table_pow_2 = - transcript->template receive_from_prover(commitment_labels.avm_main_table_pow_2); - commitments.avm_main_tag_err = - transcript->template receive_from_prover(commitment_labels.avm_main_tag_err); - commitments.avm_main_w_in_tag = - transcript->template receive_from_prover(commitment_labels.avm_main_w_in_tag); - commitments.avm_mem_addr = transcript->template receive_from_prover(commitment_labels.avm_mem_addr); - commitments.avm_mem_clk = transcript->template receive_from_prover(commitment_labels.avm_mem_clk); - commitments.avm_mem_diff_hi = - transcript->template receive_from_prover(commitment_labels.avm_mem_diff_hi); - commitments.avm_mem_diff_lo = - transcript->template receive_from_prover(commitment_labels.avm_mem_diff_lo); - commitments.avm_mem_diff_mid = - transcript->template receive_from_prover(commitment_labels.avm_mem_diff_mid); - commitments.avm_mem_glob_addr = - transcript->template receive_from_prover(commitment_labels.avm_mem_glob_addr); - commitments.avm_mem_ind_op_a = - transcript->template receive_from_prover(commitment_labels.avm_mem_ind_op_a); - commitments.avm_mem_ind_op_b = - transcript->template receive_from_prover(commitment_labels.avm_mem_ind_op_b); - commitments.avm_mem_ind_op_c = - transcript->template receive_from_prover(commitment_labels.avm_mem_ind_op_c); - commitments.avm_mem_ind_op_d = - transcript->template receive_from_prover(commitment_labels.avm_mem_ind_op_d); - commitments.avm_mem_last = transcript->template receive_from_prover(commitment_labels.avm_mem_last); - commitments.avm_mem_lastAccess = - transcript->template receive_from_prover(commitment_labels.avm_mem_lastAccess); - commitments.avm_mem_mem_sel = - transcript->template receive_from_prover(commitment_labels.avm_mem_mem_sel); - commitments.avm_mem_one_min_inv = - transcript->template receive_from_prover(commitment_labels.avm_mem_one_min_inv); - commitments.avm_mem_op_a = transcript->template receive_from_prover(commitment_labels.avm_mem_op_a); - commitments.avm_mem_op_b = transcript->template receive_from_prover(commitment_labels.avm_mem_op_b); - commitments.avm_mem_op_c = transcript->template receive_from_prover(commitment_labels.avm_mem_op_c); - commitments.avm_mem_op_d = transcript->template receive_from_prover(commitment_labels.avm_mem_op_d); - commitments.avm_mem_r_in_tag = - transcript->template receive_from_prover(commitment_labels.avm_mem_r_in_tag); - commitments.avm_mem_rng_chk_sel = - transcript->template receive_from_prover(commitment_labels.avm_mem_rng_chk_sel); - commitments.avm_mem_rw = transcript->template receive_from_prover(commitment_labels.avm_mem_rw); - commitments.avm_mem_sel_cmov = - transcript->template receive_from_prover(commitment_labels.avm_mem_sel_cmov); - commitments.avm_mem_sel_mov_a = - transcript->template receive_from_prover(commitment_labels.avm_mem_sel_mov_a); - commitments.avm_mem_sel_mov_b = - transcript->template receive_from_prover(commitment_labels.avm_mem_sel_mov_b); - commitments.avm_mem_skip_check_tag = - transcript->template receive_from_prover(commitment_labels.avm_mem_skip_check_tag); - commitments.avm_mem_space_id = - transcript->template receive_from_prover(commitment_labels.avm_mem_space_id); - commitments.avm_mem_tag = transcript->template receive_from_prover(commitment_labels.avm_mem_tag); - commitments.avm_mem_tag_err = - transcript->template receive_from_prover(commitment_labels.avm_mem_tag_err); - commitments.avm_mem_tsp = transcript->template receive_from_prover(commitment_labels.avm_mem_tsp); - commitments.avm_mem_val = transcript->template receive_from_prover(commitment_labels.avm_mem_val); - commitments.avm_mem_w_in_tag = - transcript->template receive_from_prover(commitment_labels.avm_mem_w_in_tag); - commitments.avm_pedersen_clk = - transcript->template receive_from_prover(commitment_labels.avm_pedersen_clk); - commitments.avm_pedersen_input = - transcript->template receive_from_prover(commitment_labels.avm_pedersen_input); - commitments.avm_pedersen_output = - transcript->template receive_from_prover(commitment_labels.avm_pedersen_output); - commitments.avm_pedersen_pedersen_sel = - transcript->template receive_from_prover(commitment_labels.avm_pedersen_pedersen_sel); - commitments.avm_poseidon2_clk = - transcript->template receive_from_prover(commitment_labels.avm_poseidon2_clk); - commitments.avm_poseidon2_input = - transcript->template receive_from_prover(commitment_labels.avm_poseidon2_input); - commitments.avm_poseidon2_output = - transcript->template receive_from_prover(commitment_labels.avm_poseidon2_output); - commitments.avm_poseidon2_poseidon_perm_sel = - transcript->template receive_from_prover(commitment_labels.avm_poseidon2_poseidon_perm_sel); - commitments.avm_sha256_clk = transcript->template receive_from_prover(commitment_labels.avm_sha256_clk); - commitments.avm_sha256_input = - transcript->template receive_from_prover(commitment_labels.avm_sha256_input); - commitments.avm_sha256_output = - transcript->template receive_from_prover(commitment_labels.avm_sha256_output); - commitments.avm_sha256_sha256_compression_sel = - transcript->template receive_from_prover(commitment_labels.avm_sha256_sha256_compression_sel); - commitments.avm_sha256_state = - transcript->template receive_from_prover(commitment_labels.avm_sha256_state); + commitments.alu_a_hi = transcript->template receive_from_prover(commitment_labels.alu_a_hi); + commitments.alu_a_lo = transcript->template receive_from_prover(commitment_labels.alu_a_lo); + commitments.alu_b_hi = transcript->template receive_from_prover(commitment_labels.alu_b_hi); + commitments.alu_b_lo = transcript->template receive_from_prover(commitment_labels.alu_b_lo); + commitments.alu_borrow = transcript->template receive_from_prover(commitment_labels.alu_borrow); + commitments.alu_cf = transcript->template receive_from_prover(commitment_labels.alu_cf); + commitments.alu_clk = transcript->template receive_from_prover(commitment_labels.alu_clk); + commitments.alu_cmp_rng_ctr = + transcript->template receive_from_prover(commitment_labels.alu_cmp_rng_ctr); + commitments.alu_div_u16_r0 = transcript->template receive_from_prover(commitment_labels.alu_div_u16_r0); + commitments.alu_div_u16_r1 = transcript->template receive_from_prover(commitment_labels.alu_div_u16_r1); + commitments.alu_div_u16_r2 = transcript->template receive_from_prover(commitment_labels.alu_div_u16_r2); + commitments.alu_div_u16_r3 = transcript->template receive_from_prover(commitment_labels.alu_div_u16_r3); + commitments.alu_div_u16_r4 = transcript->template receive_from_prover(commitment_labels.alu_div_u16_r4); + commitments.alu_div_u16_r5 = transcript->template receive_from_prover(commitment_labels.alu_div_u16_r5); + commitments.alu_div_u16_r6 = transcript->template receive_from_prover(commitment_labels.alu_div_u16_r6); + commitments.alu_div_u16_r7 = transcript->template receive_from_prover(commitment_labels.alu_div_u16_r7); + commitments.alu_divisor_hi = transcript->template receive_from_prover(commitment_labels.alu_divisor_hi); + commitments.alu_divisor_lo = transcript->template receive_from_prover(commitment_labels.alu_divisor_lo); + commitments.alu_ff_tag = transcript->template receive_from_prover(commitment_labels.alu_ff_tag); + commitments.alu_ia = transcript->template receive_from_prover(commitment_labels.alu_ia); + commitments.alu_ib = transcript->template receive_from_prover(commitment_labels.alu_ib); + commitments.alu_ic = transcript->template receive_from_prover(commitment_labels.alu_ic); + commitments.alu_in_tag = transcript->template receive_from_prover(commitment_labels.alu_in_tag); + commitments.alu_op_add = transcript->template receive_from_prover(commitment_labels.alu_op_add); + commitments.alu_op_cast = transcript->template receive_from_prover(commitment_labels.alu_op_cast); + commitments.alu_op_cast_prev = + transcript->template receive_from_prover(commitment_labels.alu_op_cast_prev); + commitments.alu_op_div = transcript->template receive_from_prover(commitment_labels.alu_op_div); + commitments.alu_op_div_a_lt_b = + transcript->template receive_from_prover(commitment_labels.alu_op_div_a_lt_b); + commitments.alu_op_div_std = transcript->template receive_from_prover(commitment_labels.alu_op_div_std); + commitments.alu_op_eq = transcript->template receive_from_prover(commitment_labels.alu_op_eq); + commitments.alu_op_eq_diff_inv = + transcript->template receive_from_prover(commitment_labels.alu_op_eq_diff_inv); + commitments.alu_op_lt = transcript->template receive_from_prover(commitment_labels.alu_op_lt); + commitments.alu_op_lte = transcript->template receive_from_prover(commitment_labels.alu_op_lte); + commitments.alu_op_mul = transcript->template receive_from_prover(commitment_labels.alu_op_mul); + commitments.alu_op_not = transcript->template receive_from_prover(commitment_labels.alu_op_not); + commitments.alu_op_shl = transcript->template receive_from_prover(commitment_labels.alu_op_shl); + commitments.alu_op_shr = transcript->template receive_from_prover(commitment_labels.alu_op_shr); + commitments.alu_op_sub = transcript->template receive_from_prover(commitment_labels.alu_op_sub); + commitments.alu_p_a_borrow = transcript->template receive_from_prover(commitment_labels.alu_p_a_borrow); + commitments.alu_p_b_borrow = transcript->template receive_from_prover(commitment_labels.alu_p_b_borrow); + commitments.alu_p_sub_a_hi = transcript->template receive_from_prover(commitment_labels.alu_p_sub_a_hi); + commitments.alu_p_sub_a_lo = transcript->template receive_from_prover(commitment_labels.alu_p_sub_a_lo); + commitments.alu_p_sub_b_hi = transcript->template receive_from_prover(commitment_labels.alu_p_sub_b_hi); + commitments.alu_p_sub_b_lo = transcript->template receive_from_prover(commitment_labels.alu_p_sub_b_lo); + commitments.alu_partial_prod_hi = + transcript->template receive_from_prover(commitment_labels.alu_partial_prod_hi); + commitments.alu_partial_prod_lo = + transcript->template receive_from_prover(commitment_labels.alu_partial_prod_lo); + commitments.alu_quotient_hi = + transcript->template receive_from_prover(commitment_labels.alu_quotient_hi); + commitments.alu_quotient_lo = + transcript->template receive_from_prover(commitment_labels.alu_quotient_lo); + commitments.alu_remainder = transcript->template receive_from_prover(commitment_labels.alu_remainder); + commitments.alu_res_hi = transcript->template receive_from_prover(commitment_labels.alu_res_hi); + commitments.alu_res_lo = transcript->template receive_from_prover(commitment_labels.alu_res_lo); + commitments.alu_sel_alu = transcript->template receive_from_prover(commitment_labels.alu_sel_alu); + commitments.alu_sel_cmp = transcript->template receive_from_prover(commitment_labels.alu_sel_cmp); + commitments.alu_sel_div_rng_chk = + transcript->template receive_from_prover(commitment_labels.alu_sel_div_rng_chk); + commitments.alu_sel_rng_chk = + transcript->template receive_from_prover(commitment_labels.alu_sel_rng_chk); + commitments.alu_sel_rng_chk_lookup = + transcript->template receive_from_prover(commitment_labels.alu_sel_rng_chk_lookup); + commitments.alu_sel_shift_which = + transcript->template receive_from_prover(commitment_labels.alu_sel_shift_which); + commitments.alu_shift_lt_bit_len = + transcript->template receive_from_prover(commitment_labels.alu_shift_lt_bit_len); + commitments.alu_t_sub_s_bits = + transcript->template receive_from_prover(commitment_labels.alu_t_sub_s_bits); + commitments.alu_two_pow_s = transcript->template receive_from_prover(commitment_labels.alu_two_pow_s); + commitments.alu_two_pow_t_sub_s = + transcript->template receive_from_prover(commitment_labels.alu_two_pow_t_sub_s); + commitments.alu_u128_tag = transcript->template receive_from_prover(commitment_labels.alu_u128_tag); + commitments.alu_u16_r0 = transcript->template receive_from_prover(commitment_labels.alu_u16_r0); + commitments.alu_u16_r1 = transcript->template receive_from_prover(commitment_labels.alu_u16_r1); + commitments.alu_u16_r10 = transcript->template receive_from_prover(commitment_labels.alu_u16_r10); + commitments.alu_u16_r11 = transcript->template receive_from_prover(commitment_labels.alu_u16_r11); + commitments.alu_u16_r12 = transcript->template receive_from_prover(commitment_labels.alu_u16_r12); + commitments.alu_u16_r13 = transcript->template receive_from_prover(commitment_labels.alu_u16_r13); + commitments.alu_u16_r14 = transcript->template receive_from_prover(commitment_labels.alu_u16_r14); + commitments.alu_u16_r2 = transcript->template receive_from_prover(commitment_labels.alu_u16_r2); + commitments.alu_u16_r3 = transcript->template receive_from_prover(commitment_labels.alu_u16_r3); + commitments.alu_u16_r4 = transcript->template receive_from_prover(commitment_labels.alu_u16_r4); + commitments.alu_u16_r5 = transcript->template receive_from_prover(commitment_labels.alu_u16_r5); + commitments.alu_u16_r6 = transcript->template receive_from_prover(commitment_labels.alu_u16_r6); + commitments.alu_u16_r7 = transcript->template receive_from_prover(commitment_labels.alu_u16_r7); + commitments.alu_u16_r8 = transcript->template receive_from_prover(commitment_labels.alu_u16_r8); + commitments.alu_u16_r9 = transcript->template receive_from_prover(commitment_labels.alu_u16_r9); + commitments.alu_u16_tag = transcript->template receive_from_prover(commitment_labels.alu_u16_tag); + commitments.alu_u32_tag = transcript->template receive_from_prover(commitment_labels.alu_u32_tag); + commitments.alu_u64_tag = transcript->template receive_from_prover(commitment_labels.alu_u64_tag); + commitments.alu_u8_r0 = transcript->template receive_from_prover(commitment_labels.alu_u8_r0); + commitments.alu_u8_r1 = transcript->template receive_from_prover(commitment_labels.alu_u8_r1); + commitments.alu_u8_tag = transcript->template receive_from_prover(commitment_labels.alu_u8_tag); + commitments.binary_acc_ia = transcript->template receive_from_prover(commitment_labels.binary_acc_ia); + commitments.binary_acc_ib = transcript->template receive_from_prover(commitment_labels.binary_acc_ib); + commitments.binary_acc_ic = transcript->template receive_from_prover(commitment_labels.binary_acc_ic); + commitments.binary_clk = transcript->template receive_from_prover(commitment_labels.binary_clk); + commitments.binary_ia_bytes = + transcript->template receive_from_prover(commitment_labels.binary_ia_bytes); + commitments.binary_ib_bytes = + transcript->template receive_from_prover(commitment_labels.binary_ib_bytes); + commitments.binary_ic_bytes = + transcript->template receive_from_prover(commitment_labels.binary_ic_bytes); + commitments.binary_in_tag = transcript->template receive_from_prover(commitment_labels.binary_in_tag); + commitments.binary_mem_tag_ctr = + transcript->template receive_from_prover(commitment_labels.binary_mem_tag_ctr); + commitments.binary_mem_tag_ctr_inv = + transcript->template receive_from_prover(commitment_labels.binary_mem_tag_ctr_inv); + commitments.binary_op_id = transcript->template receive_from_prover(commitment_labels.binary_op_id); + commitments.binary_sel_bin = transcript->template receive_from_prover(commitment_labels.binary_sel_bin); + commitments.binary_start = transcript->template receive_from_prover(commitment_labels.binary_start); + commitments.byte_lookup_sel_bin = + transcript->template receive_from_prover(commitment_labels.byte_lookup_sel_bin); + commitments.byte_lookup_table_byte_lengths = + transcript->template receive_from_prover(commitment_labels.byte_lookup_table_byte_lengths); + commitments.byte_lookup_table_in_tags = + transcript->template receive_from_prover(commitment_labels.byte_lookup_table_in_tags); + commitments.byte_lookup_table_input_a = + transcript->template receive_from_prover(commitment_labels.byte_lookup_table_input_a); + commitments.byte_lookup_table_input_b = + transcript->template receive_from_prover(commitment_labels.byte_lookup_table_input_b); + commitments.byte_lookup_table_op_id = + transcript->template receive_from_prover(commitment_labels.byte_lookup_table_op_id); + commitments.byte_lookup_table_output = + transcript->template receive_from_prover(commitment_labels.byte_lookup_table_output); + commitments.conversion_clk = transcript->template receive_from_prover(commitment_labels.conversion_clk); + commitments.conversion_input = + transcript->template receive_from_prover(commitment_labels.conversion_input); + commitments.conversion_num_limbs = + transcript->template receive_from_prover(commitment_labels.conversion_num_limbs); + commitments.conversion_radix = + transcript->template receive_from_prover(commitment_labels.conversion_radix); + commitments.conversion_sel_to_radix_le = + transcript->template receive_from_prover(commitment_labels.conversion_sel_to_radix_le); + commitments.gas_da_gas_fixed_table = + transcript->template receive_from_prover(commitment_labels.gas_da_gas_fixed_table); + commitments.gas_l2_gas_fixed_table = + transcript->template receive_from_prover(commitment_labels.gas_l2_gas_fixed_table); + commitments.gas_sel_gas_cost = + transcript->template receive_from_prover(commitment_labels.gas_sel_gas_cost); + commitments.keccakf1600_clk = + transcript->template receive_from_prover(commitment_labels.keccakf1600_clk); + commitments.keccakf1600_input = + transcript->template receive_from_prover(commitment_labels.keccakf1600_input); + commitments.keccakf1600_output = + transcript->template receive_from_prover(commitment_labels.keccakf1600_output); + commitments.keccakf1600_sel_keccakf1600 = + transcript->template receive_from_prover(commitment_labels.keccakf1600_sel_keccakf1600); + commitments.kernel_emit_l2_to_l1_msg_write_offset = + transcript->template receive_from_prover(commitment_labels.kernel_emit_l2_to_l1_msg_write_offset); + commitments.kernel_emit_note_hash_write_offset = + transcript->template receive_from_prover(commitment_labels.kernel_emit_note_hash_write_offset); + commitments.kernel_emit_nullifier_write_offset = + transcript->template receive_from_prover(commitment_labels.kernel_emit_nullifier_write_offset); + commitments.kernel_emit_unencrypted_log_write_offset = transcript->template receive_from_prover( + commitment_labels.kernel_emit_unencrypted_log_write_offset); + commitments.kernel_kernel_in_offset = + transcript->template receive_from_prover(commitment_labels.kernel_kernel_in_offset); + commitments.kernel_kernel_inputs = + transcript->template receive_from_prover(commitment_labels.kernel_kernel_inputs); + commitments.kernel_kernel_metadata_out = + transcript->template receive_from_prover(commitment_labels.kernel_kernel_metadata_out); + commitments.kernel_kernel_out_offset = + transcript->template receive_from_prover(commitment_labels.kernel_kernel_out_offset); + commitments.kernel_kernel_side_effect_out = + transcript->template receive_from_prover(commitment_labels.kernel_kernel_side_effect_out); + commitments.kernel_kernel_value_out = + transcript->template receive_from_prover(commitment_labels.kernel_kernel_value_out); + commitments.kernel_l1_to_l2_msg_exists_write_offset = + transcript->template receive_from_prover(commitment_labels.kernel_l1_to_l2_msg_exists_write_offset); + commitments.kernel_note_hash_exist_write_offset = + transcript->template receive_from_prover(commitment_labels.kernel_note_hash_exist_write_offset); + commitments.kernel_nullifier_exists_write_offset = + transcript->template receive_from_prover(commitment_labels.kernel_nullifier_exists_write_offset); + commitments.kernel_nullifier_non_exists_write_offset = transcript->template receive_from_prover( + commitment_labels.kernel_nullifier_non_exists_write_offset); + commitments.kernel_q_public_input_kernel_add_to_table = transcript->template receive_from_prover( + commitment_labels.kernel_q_public_input_kernel_add_to_table); + commitments.kernel_q_public_input_kernel_out_add_to_table = transcript->template receive_from_prover( + commitment_labels.kernel_q_public_input_kernel_out_add_to_table); + commitments.kernel_side_effect_counter = + transcript->template receive_from_prover(commitment_labels.kernel_side_effect_counter); + commitments.kernel_sload_write_offset = + transcript->template receive_from_prover(commitment_labels.kernel_sload_write_offset); + commitments.kernel_sstore_write_offset = + transcript->template receive_from_prover(commitment_labels.kernel_sstore_write_offset); + commitments.main_abs_da_rem_gas_hi = + transcript->template receive_from_prover(commitment_labels.main_abs_da_rem_gas_hi); + commitments.main_abs_da_rem_gas_lo = + transcript->template receive_from_prover(commitment_labels.main_abs_da_rem_gas_lo); + commitments.main_abs_l2_rem_gas_hi = + transcript->template receive_from_prover(commitment_labels.main_abs_l2_rem_gas_hi); + commitments.main_abs_l2_rem_gas_lo = + transcript->template receive_from_prover(commitment_labels.main_abs_l2_rem_gas_lo); + commitments.main_alu_in_tag = + transcript->template receive_from_prover(commitment_labels.main_alu_in_tag); + commitments.main_bin_op_id = transcript->template receive_from_prover(commitment_labels.main_bin_op_id); + commitments.main_call_ptr = transcript->template receive_from_prover(commitment_labels.main_call_ptr); + commitments.main_da_gas_op_cost = + transcript->template receive_from_prover(commitment_labels.main_da_gas_op_cost); + commitments.main_da_gas_remaining = + transcript->template receive_from_prover(commitment_labels.main_da_gas_remaining); + commitments.main_da_out_of_gas = + transcript->template receive_from_prover(commitment_labels.main_da_out_of_gas); + commitments.main_ia = transcript->template receive_from_prover(commitment_labels.main_ia); + commitments.main_ib = transcript->template receive_from_prover(commitment_labels.main_ib); + commitments.main_ic = transcript->template receive_from_prover(commitment_labels.main_ic); + commitments.main_id = transcript->template receive_from_prover(commitment_labels.main_id); + commitments.main_id_zero = transcript->template receive_from_prover(commitment_labels.main_id_zero); + commitments.main_ind_addr_a = + transcript->template receive_from_prover(commitment_labels.main_ind_addr_a); + commitments.main_ind_addr_b = + transcript->template receive_from_prover(commitment_labels.main_ind_addr_b); + commitments.main_ind_addr_c = + transcript->template receive_from_prover(commitment_labels.main_ind_addr_c); + commitments.main_ind_addr_d = + transcript->template receive_from_prover(commitment_labels.main_ind_addr_d); + commitments.main_internal_return_ptr = + transcript->template receive_from_prover(commitment_labels.main_internal_return_ptr); + commitments.main_inv = transcript->template receive_from_prover(commitment_labels.main_inv); + commitments.main_l2_gas_op_cost = + transcript->template receive_from_prover(commitment_labels.main_l2_gas_op_cost); + commitments.main_l2_gas_remaining = + transcript->template receive_from_prover(commitment_labels.main_l2_gas_remaining); + commitments.main_l2_out_of_gas = + transcript->template receive_from_prover(commitment_labels.main_l2_out_of_gas); + commitments.main_mem_addr_a = + transcript->template receive_from_prover(commitment_labels.main_mem_addr_a); + commitments.main_mem_addr_b = + transcript->template receive_from_prover(commitment_labels.main_mem_addr_b); + commitments.main_mem_addr_c = + transcript->template receive_from_prover(commitment_labels.main_mem_addr_c); + commitments.main_mem_addr_d = + transcript->template receive_from_prover(commitment_labels.main_mem_addr_d); + commitments.main_op_err = transcript->template receive_from_prover(commitment_labels.main_op_err); + commitments.main_opcode_val = + transcript->template receive_from_prover(commitment_labels.main_opcode_val); + commitments.main_pc = transcript->template receive_from_prover(commitment_labels.main_pc); + commitments.main_r_in_tag = transcript->template receive_from_prover(commitment_labels.main_r_in_tag); + commitments.main_rwa = transcript->template receive_from_prover(commitment_labels.main_rwa); + commitments.main_rwb = transcript->template receive_from_prover(commitment_labels.main_rwb); + commitments.main_rwc = transcript->template receive_from_prover(commitment_labels.main_rwc); + commitments.main_rwd = transcript->template receive_from_prover(commitment_labels.main_rwd); + commitments.main_sel_alu = transcript->template receive_from_prover(commitment_labels.main_sel_alu); + commitments.main_sel_bin = transcript->template receive_from_prover(commitment_labels.main_sel_bin); + commitments.main_sel_gas_accounting_active = + transcript->template receive_from_prover(commitment_labels.main_sel_gas_accounting_active); + commitments.main_sel_last = transcript->template receive_from_prover(commitment_labels.main_sel_last); + commitments.main_sel_mem_op_a = + transcript->template receive_from_prover(commitment_labels.main_sel_mem_op_a); + commitments.main_sel_mem_op_activate_gas = + transcript->template receive_from_prover(commitment_labels.main_sel_mem_op_activate_gas); + commitments.main_sel_mem_op_b = + transcript->template receive_from_prover(commitment_labels.main_sel_mem_op_b); + commitments.main_sel_mem_op_c = + transcript->template receive_from_prover(commitment_labels.main_sel_mem_op_c); + commitments.main_sel_mem_op_d = + transcript->template receive_from_prover(commitment_labels.main_sel_mem_op_d); + commitments.main_sel_mov_ia_to_ic = + transcript->template receive_from_prover(commitment_labels.main_sel_mov_ia_to_ic); + commitments.main_sel_mov_ib_to_ic = + transcript->template receive_from_prover(commitment_labels.main_sel_mov_ib_to_ic); + commitments.main_sel_op_add = + transcript->template receive_from_prover(commitment_labels.main_sel_op_add); + commitments.main_sel_op_address = + transcript->template receive_from_prover(commitment_labels.main_sel_op_address); + commitments.main_sel_op_and = + transcript->template receive_from_prover(commitment_labels.main_sel_op_and); + commitments.main_sel_op_block_number = + transcript->template receive_from_prover(commitment_labels.main_sel_op_block_number); + commitments.main_sel_op_cast = + transcript->template receive_from_prover(commitment_labels.main_sel_op_cast); + commitments.main_sel_op_chain_id = + transcript->template receive_from_prover(commitment_labels.main_sel_op_chain_id); + commitments.main_sel_op_cmov = + transcript->template receive_from_prover(commitment_labels.main_sel_op_cmov); + commitments.main_sel_op_coinbase = + transcript->template receive_from_prover(commitment_labels.main_sel_op_coinbase); + commitments.main_sel_op_dagasleft = + transcript->template receive_from_prover(commitment_labels.main_sel_op_dagasleft); + commitments.main_sel_op_div = + transcript->template receive_from_prover(commitment_labels.main_sel_op_div); + commitments.main_sel_op_emit_l2_to_l1_msg = + transcript->template receive_from_prover(commitment_labels.main_sel_op_emit_l2_to_l1_msg); + commitments.main_sel_op_emit_note_hash = + transcript->template receive_from_prover(commitment_labels.main_sel_op_emit_note_hash); + commitments.main_sel_op_emit_nullifier = + transcript->template receive_from_prover(commitment_labels.main_sel_op_emit_nullifier); + commitments.main_sel_op_emit_unencrypted_log = + transcript->template receive_from_prover(commitment_labels.main_sel_op_emit_unencrypted_log); + commitments.main_sel_op_eq = transcript->template receive_from_prover(commitment_labels.main_sel_op_eq); + commitments.main_sel_op_external_call = + transcript->template receive_from_prover(commitment_labels.main_sel_op_external_call); + commitments.main_sel_op_fdiv = + transcript->template receive_from_prover(commitment_labels.main_sel_op_fdiv); + commitments.main_sel_op_fee_per_da_gas = + transcript->template receive_from_prover(commitment_labels.main_sel_op_fee_per_da_gas); + commitments.main_sel_op_fee_per_l2_gas = + transcript->template receive_from_prover(commitment_labels.main_sel_op_fee_per_l2_gas); + commitments.main_sel_op_get_contract_instance = + transcript->template receive_from_prover(commitment_labels.main_sel_op_get_contract_instance); + commitments.main_sel_op_halt = + transcript->template receive_from_prover(commitment_labels.main_sel_op_halt); + commitments.main_sel_op_internal_call = + transcript->template receive_from_prover(commitment_labels.main_sel_op_internal_call); + commitments.main_sel_op_internal_return = + transcript->template receive_from_prover(commitment_labels.main_sel_op_internal_return); + commitments.main_sel_op_jump = + transcript->template receive_from_prover(commitment_labels.main_sel_op_jump); + commitments.main_sel_op_jumpi = + transcript->template receive_from_prover(commitment_labels.main_sel_op_jumpi); + commitments.main_sel_op_keccak = + transcript->template receive_from_prover(commitment_labels.main_sel_op_keccak); + commitments.main_sel_op_l1_to_l2_msg_exists = + transcript->template receive_from_prover(commitment_labels.main_sel_op_l1_to_l2_msg_exists); + commitments.main_sel_op_l2gasleft = + transcript->template receive_from_prover(commitment_labels.main_sel_op_l2gasleft); + commitments.main_sel_op_lt = transcript->template receive_from_prover(commitment_labels.main_sel_op_lt); + commitments.main_sel_op_lte = + transcript->template receive_from_prover(commitment_labels.main_sel_op_lte); + commitments.main_sel_op_mov = + transcript->template receive_from_prover(commitment_labels.main_sel_op_mov); + commitments.main_sel_op_mul = + transcript->template receive_from_prover(commitment_labels.main_sel_op_mul); + commitments.main_sel_op_not = + transcript->template receive_from_prover(commitment_labels.main_sel_op_not); + commitments.main_sel_op_note_hash_exists = + transcript->template receive_from_prover(commitment_labels.main_sel_op_note_hash_exists); + commitments.main_sel_op_nullifier_exists = + transcript->template receive_from_prover(commitment_labels.main_sel_op_nullifier_exists); + commitments.main_sel_op_or = transcript->template receive_from_prover(commitment_labels.main_sel_op_or); + commitments.main_sel_op_pedersen = + transcript->template receive_from_prover(commitment_labels.main_sel_op_pedersen); + commitments.main_sel_op_poseidon2 = + transcript->template receive_from_prover(commitment_labels.main_sel_op_poseidon2); + commitments.main_sel_op_radix_le = + transcript->template receive_from_prover(commitment_labels.main_sel_op_radix_le); + commitments.main_sel_op_sender = + transcript->template receive_from_prover(commitment_labels.main_sel_op_sender); + commitments.main_sel_op_sha256 = + transcript->template receive_from_prover(commitment_labels.main_sel_op_sha256); + commitments.main_sel_op_shl = + transcript->template receive_from_prover(commitment_labels.main_sel_op_shl); + commitments.main_sel_op_shr = + transcript->template receive_from_prover(commitment_labels.main_sel_op_shr); + commitments.main_sel_op_sload = + transcript->template receive_from_prover(commitment_labels.main_sel_op_sload); + commitments.main_sel_op_sstore = + transcript->template receive_from_prover(commitment_labels.main_sel_op_sstore); + commitments.main_sel_op_storage_address = + transcript->template receive_from_prover(commitment_labels.main_sel_op_storage_address); + commitments.main_sel_op_sub = + transcript->template receive_from_prover(commitment_labels.main_sel_op_sub); + commitments.main_sel_op_timestamp = + transcript->template receive_from_prover(commitment_labels.main_sel_op_timestamp); + commitments.main_sel_op_transaction_fee = + transcript->template receive_from_prover(commitment_labels.main_sel_op_transaction_fee); + commitments.main_sel_op_version = + transcript->template receive_from_prover(commitment_labels.main_sel_op_version); + commitments.main_sel_op_xor = + transcript->template receive_from_prover(commitment_labels.main_sel_op_xor); + commitments.main_sel_q_kernel_lookup = + transcript->template receive_from_prover(commitment_labels.main_sel_q_kernel_lookup); + commitments.main_sel_q_kernel_output_lookup = + transcript->template receive_from_prover(commitment_labels.main_sel_q_kernel_output_lookup); + commitments.main_sel_resolve_ind_addr_a = + transcript->template receive_from_prover(commitment_labels.main_sel_resolve_ind_addr_a); + commitments.main_sel_resolve_ind_addr_b = + transcript->template receive_from_prover(commitment_labels.main_sel_resolve_ind_addr_b); + commitments.main_sel_resolve_ind_addr_c = + transcript->template receive_from_prover(commitment_labels.main_sel_resolve_ind_addr_c); + commitments.main_sel_resolve_ind_addr_d = + transcript->template receive_from_prover(commitment_labels.main_sel_resolve_ind_addr_d); + commitments.main_sel_rng_16 = + transcript->template receive_from_prover(commitment_labels.main_sel_rng_16); + commitments.main_sel_rng_8 = transcript->template receive_from_prover(commitment_labels.main_sel_rng_8); + commitments.main_space_id = transcript->template receive_from_prover(commitment_labels.main_space_id); + commitments.main_table_pow_2 = + transcript->template receive_from_prover(commitment_labels.main_table_pow_2); + commitments.main_tag_err = transcript->template receive_from_prover(commitment_labels.main_tag_err); + commitments.main_w_in_tag = transcript->template receive_from_prover(commitment_labels.main_w_in_tag); + commitments.mem_addr = transcript->template receive_from_prover(commitment_labels.mem_addr); + commitments.mem_clk = transcript->template receive_from_prover(commitment_labels.mem_clk); + commitments.mem_diff_hi = transcript->template receive_from_prover(commitment_labels.mem_diff_hi); + commitments.mem_diff_lo = transcript->template receive_from_prover(commitment_labels.mem_diff_lo); + commitments.mem_diff_mid = transcript->template receive_from_prover(commitment_labels.mem_diff_mid); + commitments.mem_glob_addr = transcript->template receive_from_prover(commitment_labels.mem_glob_addr); + commitments.mem_last = transcript->template receive_from_prover(commitment_labels.mem_last); + commitments.mem_lastAccess = transcript->template receive_from_prover(commitment_labels.mem_lastAccess); + commitments.mem_one_min_inv = + transcript->template receive_from_prover(commitment_labels.mem_one_min_inv); + commitments.mem_r_in_tag = transcript->template receive_from_prover(commitment_labels.mem_r_in_tag); + commitments.mem_rw = transcript->template receive_from_prover(commitment_labels.mem_rw); + commitments.mem_sel_mem = transcript->template receive_from_prover(commitment_labels.mem_sel_mem); + commitments.mem_sel_mov_ia_to_ic = + transcript->template receive_from_prover(commitment_labels.mem_sel_mov_ia_to_ic); + commitments.mem_sel_mov_ib_to_ic = + transcript->template receive_from_prover(commitment_labels.mem_sel_mov_ib_to_ic); + commitments.mem_sel_op_a = transcript->template receive_from_prover(commitment_labels.mem_sel_op_a); + commitments.mem_sel_op_b = transcript->template receive_from_prover(commitment_labels.mem_sel_op_b); + commitments.mem_sel_op_c = transcript->template receive_from_prover(commitment_labels.mem_sel_op_c); + commitments.mem_sel_op_cmov = + transcript->template receive_from_prover(commitment_labels.mem_sel_op_cmov); + commitments.mem_sel_op_d = transcript->template receive_from_prover(commitment_labels.mem_sel_op_d); + commitments.mem_sel_resolve_ind_addr_a = + transcript->template receive_from_prover(commitment_labels.mem_sel_resolve_ind_addr_a); + commitments.mem_sel_resolve_ind_addr_b = + transcript->template receive_from_prover(commitment_labels.mem_sel_resolve_ind_addr_b); + commitments.mem_sel_resolve_ind_addr_c = + transcript->template receive_from_prover(commitment_labels.mem_sel_resolve_ind_addr_c); + commitments.mem_sel_resolve_ind_addr_d = + transcript->template receive_from_prover(commitment_labels.mem_sel_resolve_ind_addr_d); + commitments.mem_sel_rng_chk = + transcript->template receive_from_prover(commitment_labels.mem_sel_rng_chk); + commitments.mem_skip_check_tag = + transcript->template receive_from_prover(commitment_labels.mem_skip_check_tag); + commitments.mem_space_id = transcript->template receive_from_prover(commitment_labels.mem_space_id); + commitments.mem_tag = transcript->template receive_from_prover(commitment_labels.mem_tag); + commitments.mem_tag_err = transcript->template receive_from_prover(commitment_labels.mem_tag_err); + commitments.mem_tsp = transcript->template receive_from_prover(commitment_labels.mem_tsp); + commitments.mem_val = transcript->template receive_from_prover(commitment_labels.mem_val); + commitments.mem_w_in_tag = transcript->template receive_from_prover(commitment_labels.mem_w_in_tag); + commitments.pedersen_clk = transcript->template receive_from_prover(commitment_labels.pedersen_clk); + commitments.pedersen_input = transcript->template receive_from_prover(commitment_labels.pedersen_input); + commitments.pedersen_output = + transcript->template receive_from_prover(commitment_labels.pedersen_output); + commitments.pedersen_sel_pedersen = + transcript->template receive_from_prover(commitment_labels.pedersen_sel_pedersen); + commitments.poseidon2_clk = transcript->template receive_from_prover(commitment_labels.poseidon2_clk); + commitments.poseidon2_input = + transcript->template receive_from_prover(commitment_labels.poseidon2_input); + commitments.poseidon2_output = + transcript->template receive_from_prover(commitment_labels.poseidon2_output); + commitments.poseidon2_sel_poseidon_perm = + transcript->template receive_from_prover(commitment_labels.poseidon2_sel_poseidon_perm); + commitments.sha256_clk = transcript->template receive_from_prover(commitment_labels.sha256_clk); + commitments.sha256_input = transcript->template receive_from_prover(commitment_labels.sha256_input); + commitments.sha256_output = transcript->template receive_from_prover(commitment_labels.sha256_output); + commitments.sha256_sel_sha256_compression = + transcript->template receive_from_prover(commitment_labels.sha256_sel_sha256_compression); + commitments.sha256_state = transcript->template receive_from_prover(commitment_labels.sha256_state); commitments.lookup_byte_lengths_counts = transcript->template receive_from_prover(commitment_labels.lookup_byte_lengths_counts); commitments.lookup_byte_operations_counts = @@ -685,14 +619,14 @@ bool AvmVerifier::verify_proof(const HonkProof& proof, const std::vectortemplate receive_from_prover(commitment_labels.perm_main_mem_c); commitments.perm_main_mem_d = transcript->template receive_from_prover(commitment_labels.perm_main_mem_d); - commitments.perm_main_mem_ind_a = - transcript->template receive_from_prover(commitment_labels.perm_main_mem_ind_a); - commitments.perm_main_mem_ind_b = - transcript->template receive_from_prover(commitment_labels.perm_main_mem_ind_b); - commitments.perm_main_mem_ind_c = - transcript->template receive_from_prover(commitment_labels.perm_main_mem_ind_c); - commitments.perm_main_mem_ind_d = - transcript->template receive_from_prover(commitment_labels.perm_main_mem_ind_d); + commitments.perm_main_mem_ind_addr_a = + transcript->template receive_from_prover(commitment_labels.perm_main_mem_ind_addr_a); + commitments.perm_main_mem_ind_addr_b = + transcript->template receive_from_prover(commitment_labels.perm_main_mem_ind_addr_b); + commitments.perm_main_mem_ind_addr_c = + transcript->template receive_from_prover(commitment_labels.perm_main_mem_ind_addr_c); + commitments.perm_main_mem_ind_addr_d = + transcript->template receive_from_prover(commitment_labels.perm_main_mem_ind_addr_d); commitments.lookup_byte_lengths = transcript->template receive_from_prover(commitment_labels.lookup_byte_lengths); commitments.lookup_byte_operations = @@ -778,27 +712,27 @@ bool AvmVerifier::verify_proof(const HonkProof& proof, const std::vector namespace tests_avm { + using namespace bb; using namespace bb::avm_trace; @@ -24,32 +25,32 @@ void common_validate_arithmetic_op(Row const& main_row, avm_trace::AvmMemoryTag const tag) { // Check that the correct result is stored at the expected memory location. - EXPECT_EQ(main_row.avm_main_ic, c); - EXPECT_EQ(main_row.avm_main_mem_idx_c, addr_c); - EXPECT_EQ(main_row.avm_main_mem_op_c, FF(1)); - EXPECT_EQ(main_row.avm_main_rwc, FF(1)); + EXPECT_EQ(main_row.main_ic, c); + EXPECT_EQ(main_row.main_mem_addr_c, addr_c); + EXPECT_EQ(main_row.main_sel_mem_op_c, FF(1)); + EXPECT_EQ(main_row.main_rwc, FF(1)); // Check that ia and ib registers are correctly set with memory load operations. - EXPECT_EQ(main_row.avm_main_ia, a); - EXPECT_EQ(main_row.avm_main_mem_idx_a, addr_a); - EXPECT_EQ(main_row.avm_main_mem_op_a, FF(1)); - EXPECT_EQ(main_row.avm_main_rwa, FF(0)); - EXPECT_EQ(main_row.avm_main_ib, b); - EXPECT_EQ(main_row.avm_main_mem_idx_b, addr_b); - EXPECT_EQ(main_row.avm_main_mem_op_b, FF(1)); - EXPECT_EQ(main_row.avm_main_rwb, FF(0)); + EXPECT_EQ(main_row.main_ia, a); + EXPECT_EQ(main_row.main_mem_addr_a, addr_a); + EXPECT_EQ(main_row.main_sel_mem_op_a, FF(1)); + EXPECT_EQ(main_row.main_rwa, FF(0)); + EXPECT_EQ(main_row.main_ib, b); + EXPECT_EQ(main_row.main_mem_addr_b, addr_b); + EXPECT_EQ(main_row.main_sel_mem_op_b, FF(1)); + EXPECT_EQ(main_row.main_rwb, FF(0)); // Check the read instruction tag - EXPECT_EQ(main_row.avm_main_r_in_tag, FF(static_cast(tag))); + EXPECT_EQ(main_row.main_r_in_tag, FF(static_cast(tag))); // Check that intermediate registers are correctly copied in Alu trace - EXPECT_EQ(alu_row.avm_alu_ia, a); - EXPECT_EQ(alu_row.avm_alu_ib, b); - EXPECT_EQ(alu_row.avm_alu_ic, c); + EXPECT_EQ(alu_row.alu_ia, a); + EXPECT_EQ(alu_row.alu_ib, b); + EXPECT_EQ(alu_row.alu_ic, c); // Check that no error is raised - EXPECT_EQ(main_row.avm_main_tag_err, FF(0)); - EXPECT_EQ(main_row.avm_main_op_err, FF(0)); + EXPECT_EQ(main_row.main_tag_err, FF(0)); + EXPECT_EQ(main_row.main_op_err, FF(0)); } Row common_validate_add(std::vector const& trace, @@ -62,22 +63,22 @@ Row common_validate_add(std::vector const& trace, avm_trace::AvmMemoryTag const tag) { // Find the first row enabling the addition selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_add == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_add == FF(1); }); // Find the corresponding Alu trace row - auto clk = row->avm_main_clk; - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_clk == clk; }); + auto clk = row->main_clk; + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.alu_clk == clk; }); // Check that both rows were found EXPECT_TRUE(row != trace.end()); EXPECT_TRUE(alu_row != trace.end()); common_validate_arithmetic_op(*row, *alu_row, a, b, c, addr_a, addr_b, addr_c, tag); - EXPECT_EQ(row->avm_main_w_in_tag, FF(static_cast(tag))); + EXPECT_EQ(row->main_w_in_tag, FF(static_cast(tag))); // Check that addition selector is set. - EXPECT_EQ(row->avm_main_sel_op_add, FF(1)); - EXPECT_EQ(alu_row->avm_alu_op_add, FF(1)); + EXPECT_EQ(row->main_sel_op_add, FF(1)); + EXPECT_EQ(alu_row->alu_op_add, FF(1)); return *alu_row; } @@ -92,22 +93,22 @@ Row common_validate_sub(std::vector const& trace, avm_trace::AvmMemoryTag const tag) { // Find the first row enabling the subtraction selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sub == FF(1); }); // Find the corresponding Alu trace row - auto clk = row->avm_main_clk; - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_clk == clk; }); + auto clk = row->main_clk; + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.alu_clk == clk; }); // Check that both rows were found EXPECT_TRUE(row != trace.end()); EXPECT_TRUE(alu_row != trace.end()); common_validate_arithmetic_op(*row, *alu_row, a, b, c, addr_a, addr_b, addr_c, tag); - EXPECT_EQ(row->avm_main_w_in_tag, FF(static_cast(tag))); + EXPECT_EQ(row->main_w_in_tag, FF(static_cast(tag))); // Check that subtraction selector is set. - EXPECT_EQ(row->avm_main_sel_op_sub, FF(1)); - EXPECT_EQ(alu_row->avm_alu_op_sub, FF(1)); + EXPECT_EQ(row->main_sel_op_sub, FF(1)); + EXPECT_EQ(alu_row->alu_op_sub, FF(1)); return *alu_row; } @@ -122,22 +123,22 @@ size_t common_validate_mul(std::vector const& trace, avm_trace::AvmMemoryTag const tag) { // Find the first row enabling the multiplication selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_mul == FF(1); }); // Find the corresponding Alu trace row - auto clk = row->avm_main_clk; - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_clk == clk; }); + auto clk = row->main_clk; + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.alu_clk == clk; }); // Check that both rows were found EXPECT_TRUE(row != trace.end()); EXPECT_TRUE(alu_row != trace.end()); common_validate_arithmetic_op(*row, *alu_row, a, b, c, addr_a, addr_b, addr_c, tag); - EXPECT_EQ(row->avm_main_w_in_tag, FF(static_cast(tag))); + EXPECT_EQ(row->main_w_in_tag, FF(static_cast(tag))); // Check that multiplication selector is set. - EXPECT_EQ(row->avm_main_sel_op_mul, FF(1)); - EXPECT_EQ(alu_row->avm_alu_op_mul, FF(1)); + EXPECT_EQ(row->main_sel_op_mul, FF(1)); + EXPECT_EQ(alu_row->alu_op_mul, FF(1)); return static_cast(alu_row - trace.begin()); } @@ -152,22 +153,22 @@ size_t common_validate_eq(std::vector const& trace, avm_trace::AvmMemoryTag const tag) { // Find the first row enabling the equality selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_eq == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_eq == FF(1); }); // Find the corresponding Alu trace row - auto clk = row->avm_main_clk; - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_clk == clk; }); + auto clk = row->main_clk; + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.alu_clk == clk; }); // Check that both rows were found EXPECT_TRUE(row != trace.end()); EXPECT_TRUE(alu_row != trace.end()); common_validate_arithmetic_op(*row, *alu_row, a, b, c, addr_a, addr_b, addr_c, tag); - EXPECT_EQ(row->avm_main_w_in_tag, FF(static_cast(AvmMemoryTag::U8))); + EXPECT_EQ(row->main_w_in_tag, FF(static_cast(AvmMemoryTag::U8))); // Check that equality selector is set. - EXPECT_EQ(row->avm_main_sel_op_eq, FF(1)); - EXPECT_EQ(alu_row->avm_alu_op_eq, FF(1)); + EXPECT_EQ(row->main_sel_op_eq, FF(1)); + EXPECT_EQ(alu_row->alu_op_eq, FF(1)); return static_cast(alu_row - trace.begin()); } @@ -182,21 +183,21 @@ size_t common_validate_div(std::vector const& trace, avm_trace::AvmMemoryTag const tag) { // Find the first row enabling the division selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_div == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_div == FF(1); }); // Find the corresponding Alu trace row - auto clk = row->avm_main_clk; - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_clk == clk; }); + auto clk = row->main_clk; + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.alu_clk == clk; }); // Check that both rows were found EXPECT_TRUE(row != trace.end()); EXPECT_TRUE(alu_row != trace.end()); common_validate_arithmetic_op(*row, *alu_row, a, b, c, addr_a, addr_b, addr_c, tag); - EXPECT_EQ(row->avm_main_w_in_tag, FF(static_cast(tag))); + EXPECT_EQ(row->main_w_in_tag, FF(static_cast(tag))); // Check that division selector is set. - EXPECT_EQ(alu_row->avm_alu_op_div, FF(1)); + EXPECT_EQ(alu_row->alu_op_div, FF(1)); return static_cast(alu_row - trace.begin()); } @@ -245,7 +246,7 @@ class AvmArithmeticTests : public ::testing::Test { trace_builder.halt(); auto trace = trace_builder.finalize(); - auto select_row = [](Row r) { return r.avm_main_sel_op_add == FF(1); }; + auto select_row = [](Row r) { return r.main_sel_op_add == FF(1); }; mutate_ic_in_trace(trace, select_row, c_mutated, true); return trace; @@ -262,7 +263,7 @@ class AvmArithmeticTests : public ::testing::Test { trace_builder.halt(); auto trace = trace_builder.finalize(); - auto select_row = [](Row r) { return r.avm_main_sel_op_sub == FF(1); }; + auto select_row = [](Row r) { return r.main_sel_op_sub == FF(1); }; mutate_ic_in_trace(trace, select_row, c_mutated, true); return trace; @@ -279,7 +280,7 @@ class AvmArithmeticTests : public ::testing::Test { trace_builder.halt(); auto trace = trace_builder.finalize(); - auto select_row = [](Row r) { return r.avm_main_sel_op_mul == FF(1); }; + auto select_row = [](Row r) { return r.main_sel_op_mul == FF(1); }; mutate_ic_in_trace(trace, select_row, c_mutated, true); return trace; @@ -299,16 +300,16 @@ class AvmArithmeticTests : public ::testing::Test { trace_builder.halt(); auto trace = trace_builder.finalize(); - auto select_row = [](Row r) { return r.avm_main_sel_op_eq == FF(1); }; + auto select_row = [](Row r) { return r.main_sel_op_eq == FF(1); }; mutate_ic_in_trace(trace, select_row, c_mutated, true); auto main_trace_row = std::ranges::find_if(trace.begin(), trace.end(), select_row); - auto main_clk = main_trace_row->avm_main_clk; + auto main_clk = main_trace_row->main_clk; auto alu_row = - std::ranges::find_if(trace.begin(), trace.end(), [main_clk](Row r) { return r.avm_alu_clk == main_clk; }); + std::ranges::find_if(trace.begin(), trace.end(), [main_clk](Row r) { return r.alu_clk == main_clk; }); - main_trace_row->avm_alu_op_eq_diff_inv = mutated_inv_diff; - alu_row->avm_alu_op_eq_diff_inv = mutated_inv_diff; + main_trace_row->alu_op_eq_diff_inv = mutated_inv_diff; + alu_row->alu_op_eq_diff_inv = mutated_inv_diff; return trace; } @@ -381,9 +382,9 @@ TEST_F(AvmArithmeticTestsFF, addition) auto alu_row = common_validate_add(trace, FF(37), FF(4), FF(41), FF(0), FF(1), FF(4), AvmMemoryTag::FF); - EXPECT_EQ(alu_row.avm_alu_ff_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0)); + EXPECT_EQ(alu_row.alu_ff_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0)); validate_trace(std::move(trace), public_inputs, true); } @@ -400,11 +401,11 @@ TEST_F(AvmArithmeticTestsFF, subtraction) auto alu_row = common_validate_sub(trace, FF(17), FF(8), FF(9), FF(2), FF(0), FF(1), AvmMemoryTag::FF); - EXPECT_EQ(alu_row.avm_alu_ff_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0)); + EXPECT_EQ(alu_row.alu_ff_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic multiplication over finite field type. @@ -420,11 +421,11 @@ TEST_F(AvmArithmeticTestsFF, multiplication) auto alu_row_index = common_validate_mul(trace, FF(20), FF(5), FF(100), FF(2), FF(0), FF(1), AvmMemoryTag::FF); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_ff_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0)); + EXPECT_EQ(alu_row.alu_ff_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on multiplication by zero over finite field type. @@ -440,11 +441,11 @@ TEST_F(AvmArithmeticTestsFF, multiplicationByZero) auto alu_row_index = common_validate_mul(trace, FF(127), FF(0), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::FF); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_ff_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0)); + EXPECT_EQ(alu_row.alu_ff_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic division over finite field type. @@ -458,16 +459,16 @@ TEST_F(AvmArithmeticTestsFF, fDivision) auto trace = trace_builder.finalize(); // Find the first row enabling the fdiv selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fdiv == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fdiv == FF(1); }); // Check that the correct result is stored at the expected memory location. EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avm_main_ic, FF(21)); - EXPECT_EQ(row->avm_main_mem_idx_c, FF(2)); - EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); - EXPECT_EQ(row->avm_main_rwc, FF(1)); + EXPECT_EQ(row->main_ic, FF(21)); + EXPECT_EQ(row->main_mem_addr_c, FF(2)); + EXPECT_EQ(row->main_sel_mem_op_c, FF(1)); + EXPECT_EQ(row->main_rwc, FF(1)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on division with zero numerator over finite field type. @@ -481,16 +482,16 @@ TEST_F(AvmArithmeticTestsFF, fDivisionNumeratorZero) auto trace = trace_builder.finalize(); // Find the first row enabling the fdiv selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fdiv == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fdiv == FF(1); }); // Check that the correct result is stored at the expected memory location. EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avm_main_ic, FF(0)); - EXPECT_EQ(row->avm_main_mem_idx_c, FF(0)); - EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); - EXPECT_EQ(row->avm_main_rwc, FF(1)); + EXPECT_EQ(row->main_ic, FF(0)); + EXPECT_EQ(row->main_mem_addr_c, FF(0)); + EXPECT_EQ(row->main_sel_mem_op_c, FF(1)); + EXPECT_EQ(row->main_rwc, FF(1)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on division by zero over finite field type. @@ -505,17 +506,17 @@ TEST_F(AvmArithmeticTestsFF, fDivisionByZeroError) auto trace = trace_builder.finalize(); // Find the first row enabling the fdiv selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fdiv == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fdiv == FF(1); }); // Check that the correct result is stored at the expected memory location. EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avm_main_ic, FF(0)); - EXPECT_EQ(row->avm_main_mem_idx_c, FF(2)); - EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); - EXPECT_EQ(row->avm_main_rwc, FF(1)); - EXPECT_EQ(row->avm_main_op_err, FF(1)); + EXPECT_EQ(row->main_ic, FF(0)); + EXPECT_EQ(row->main_mem_addr_c, FF(2)); + EXPECT_EQ(row->main_sel_mem_op_c, FF(1)); + EXPECT_EQ(row->main_rwc, FF(1)); + EXPECT_EQ(row->main_op_err, FF(1)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on division of zero by zero over finite field type. @@ -528,17 +529,17 @@ TEST_F(AvmArithmeticTestsFF, fDivisionZeroByZeroError) auto trace = trace_builder.finalize(); // Find the first row enabling the fdiv selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fdiv == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fdiv == FF(1); }); // Check that the correct result is stored at the expected memory location. EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avm_main_ic, FF(0)); - EXPECT_EQ(row->avm_main_mem_idx_c, FF(2)); - EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); - EXPECT_EQ(row->avm_main_rwc, FF(1)); - EXPECT_EQ(row->avm_main_op_err, FF(1)); + EXPECT_EQ(row->main_ic, FF(0)); + EXPECT_EQ(row->main_mem_addr_c, FF(2)); + EXPECT_EQ(row->main_sel_mem_op_c, FF(1)); + EXPECT_EQ(row->main_rwc, FF(1)); + EXPECT_EQ(row->main_op_err, FF(1)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Testing an execution of the different arithmetic opcodes over finite field @@ -578,9 +579,9 @@ TEST_F(AvmArithmeticTestsFF, equality) auto alu_row_index = common_validate_eq(trace, elem, elem, FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::FF); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_ff_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_op_eq_diff_inv, FF(0)); // Expect 0 as inv of (q-1) - (q-1) - validate_trace(std::move(trace)); + EXPECT_EQ(alu_row.alu_ff_tag, FF(1)); + EXPECT_EQ(alu_row.alu_op_eq_diff_inv, FF(0)); // Expect 0 as inv of (q-1) - (q-1) + validate_trace(std::move(trace), public_inputs); } // Test correct non-equality of FF elements @@ -595,9 +596,9 @@ TEST_F(AvmArithmeticTestsFF, nonEquality) auto alu_row_index = common_validate_eq(trace, elem, FF(0), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::FF); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_ff_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_op_eq_diff_inv, FF(-1).invert()); - validate_trace(std::move(trace)); + EXPECT_EQ(alu_row.alu_ff_tag, FF(1)); + EXPECT_EQ(alu_row.alu_op_eq_diff_inv, FF(-1).invert()); + validate_trace(std::move(trace), public_inputs); } TEST_P(AvmArithmeticTestsDiv, division) @@ -613,7 +614,7 @@ TEST_P(AvmArithmeticTestsDiv, division) common_validate_div(trace, a, b, output, 0, 1, 2, mem_tag); // auto alu_row = trace.at(alu_row_index); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } INSTANTIATE_TEST_SUITE_P(AvmArithmeticTestsDiv, AvmArithmeticTestsDiv, @@ -630,17 +631,17 @@ TEST_F(AvmArithmeticTests, DivisionByZeroError) auto trace = trace_builder.finalize(); // Find the first row enabling the div selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_div == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_div == FF(1); }); // Check that the correct result is stored at the expected memory location. EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avm_main_ic, FF(0)); - EXPECT_EQ(row->avm_main_mem_idx_c, FF(2)); - EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); - EXPECT_EQ(row->avm_main_rwc, FF(1)); - EXPECT_EQ(row->avm_main_op_err, FF(1)); + EXPECT_EQ(row->main_ic, FF(0)); + EXPECT_EQ(row->main_mem_addr_c, FF(2)); + EXPECT_EQ(row->main_sel_mem_op_c, FF(1)); + EXPECT_EQ(row->main_rwc, FF(1)); + EXPECT_EQ(row->main_op_err, FF(1)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } /****************************************************************************** @@ -661,11 +662,11 @@ TEST_F(AvmArithmeticTestsU8, addition) auto alu_row = common_validate_add(trace, FF(62), FF(29), FF(91), FF(0), FF(1), FF(2), AvmMemoryTag::U8); - EXPECT_EQ(alu_row.avm_alu_u8_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(91)); + EXPECT_EQ(alu_row.alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(91)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic addition over u8 type with carry. @@ -682,12 +683,12 @@ TEST_F(AvmArithmeticTestsU8, additionCarry) auto alu_row = common_validate_add(trace, FF(159), FF(100), FF(3), FF(0), FF(1), FF(2), AvmMemoryTag::U8); - EXPECT_EQ(alu_row.avm_alu_u8_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(3)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(1)); + EXPECT_EQ(alu_row.alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(3)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(1)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic subtraction over u8 type. @@ -704,11 +705,11 @@ TEST_F(AvmArithmeticTestsU8, subtraction) auto alu_row = common_validate_sub(trace, FF(162), FF(29), FF(133), FF(0), FF(1), FF(2), AvmMemoryTag::U8); - EXPECT_EQ(alu_row.avm_alu_u8_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(133)); + EXPECT_EQ(alu_row.alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(133)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on subtraction over u8 type with carry. @@ -726,19 +727,19 @@ TEST_F(AvmArithmeticTestsU8, subtractionCarry) auto alu_row = common_validate_sub(trace, FF(5), FF(29), FF(232), FF(0), FF(1), FF(2), AvmMemoryTag::U8); - EXPECT_EQ(alu_row.avm_alu_u8_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(1)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(232)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(UINT8_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r3, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r4, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r5, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r6, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(1)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(232)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(UINT8_MAX)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r2, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r3, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r4, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r5, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r6, FF(UINT16_MAX)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic multiplication over u8 type. @@ -755,13 +756,13 @@ TEST_F(AvmArithmeticTestsU8, multiplication) auto alu_row_index = common_validate_mul(trace, FF(13), FF(15), FF(195), FF(0), FF(1), FF(2), AvmMemoryTag::U8); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.alu_u8_tag, FF(1)); // Decomposition of integer multiplication in 8-bit registers - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(195)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(195)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on multiplication over u8 type with overflow. @@ -778,14 +779,14 @@ TEST_F(AvmArithmeticTestsU8, multiplicationOverflow) auto alu_row_index = common_validate_mul(trace, FF(200), FF(170), FF(208), FF(0), FF(1), FF(2), AvmMemoryTag::U8); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.alu_u8_tag, FF(1)); // Decomposition of integer multiplication in 8-bit registers // 34'000 = 208 + 132 * 256 - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(208)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(132)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(208)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(132)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test of equality on u8 elements @@ -796,9 +797,9 @@ TEST_F(AvmArithmeticTestsU8, equality) auto alu_row_index = common_validate_eq(trace, FF(128), FF(128), FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::U8); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u8_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_op_eq_diff_inv, FF(0)); - validate_trace(std::move(trace)); + EXPECT_EQ(alu_row.alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.alu_op_eq_diff_inv, FF(0)); + validate_trace(std::move(trace), public_inputs); } // Test correct non-equality of U8 elements @@ -809,9 +810,9 @@ TEST_F(AvmArithmeticTestsU8, nonEquality) auto alu_row_index = common_validate_eq(trace, 84, 200, FF(0), FF(12), FF(15), FF(28), AvmMemoryTag::U8); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u8_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_op_eq_diff_inv, FF(-116).invert()); - validate_trace(std::move(trace)); + EXPECT_EQ(alu_row.alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row.alu_op_eq_diff_inv, FF(-116).invert()); + validate_trace(std::move(trace), public_inputs); } /****************************************************************************** @@ -832,12 +833,12 @@ TEST_F(AvmArithmeticTestsU16, addition) auto alu_row = common_validate_add(trace, FF(33005), FF(1775), FF(34780), FF(546), FF(119), FF(5), AvmMemoryTag::U16); - EXPECT_EQ(alu_row.avm_alu_u16_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0xDC)); // 34780 = 0x87DC - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0x87)); + EXPECT_EQ(alu_row.alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0xDC)); // 34780 = 0x87DC + EXPECT_EQ(alu_row.alu_u8_r1, FF(0x87)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic addition over u16 type with carry. @@ -854,12 +855,12 @@ TEST_F(AvmArithmeticTestsU16, additionCarry) auto alu_row = common_validate_add(trace, FF(1000), FF(UINT16_MAX - 982), FF(17), FF(1), FF(0), FF(0), AvmMemoryTag::U16); - EXPECT_EQ(alu_row.avm_alu_u16_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(17)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0)); + EXPECT_EQ(alu_row.alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(17)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic subtraction over u16 type. @@ -876,13 +877,13 @@ TEST_F(AvmArithmeticTestsU16, subtraction) auto alu_row = common_validate_sub(trace, FF(33005), FF(1775), FF(31230), FF(546), FF(119), FF(5), AvmMemoryTag::U16); - EXPECT_EQ(alu_row.avm_alu_u16_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0xFE)); // 31230 in Hex: 79FE - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0x79)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(0)); + EXPECT_EQ(alu_row.alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0xFE)); // 31230 in Hex: 79FE + EXPECT_EQ(alu_row.alu_u8_r1, FF(0x79)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(0)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic subtraction over u16 type with carry. @@ -900,19 +901,19 @@ TEST_F(AvmArithmeticTestsU16, subtractionCarry) auto alu_row = common_validate_sub(trace, FF(1000), FF(UINT16_MAX - 982), FF(1983), FF(1), FF(0), FF(0), AvmMemoryTag::U16); - EXPECT_EQ(alu_row.avm_alu_u16_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(1)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0xBF)); // 1983 = 0x7BF - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(7)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r3, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r4, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r5, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r6, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(1)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0xBF)); // 1983 = 0x7BF + EXPECT_EQ(alu_row.alu_u8_r1, FF(7)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r2, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r3, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r4, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r5, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r6, FF(UINT16_MAX)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic multiplication over u16 type. @@ -930,14 +931,14 @@ TEST_F(AvmArithmeticTestsU16, multiplication) common_validate_mul(trace, FF(200), FF(245), FF(49000), FF(0), FF(1), FF(2), AvmMemoryTag::U16); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.alu_u16_tag, FF(1)); // Decomposition of integer multiplication in 8-bit and 16-bit registers - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0x68)); // 49000 = 0xBF68 - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0xBF)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0x68)); // 49000 = 0xBF68 + EXPECT_EQ(alu_row.alu_u8_r1, FF(0xBF)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(0)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on multiplication over u16 type with overflow. @@ -954,16 +955,16 @@ TEST_F(AvmArithmeticTestsU16, multiplicationOverflow) auto alu_row_index = common_validate_mul(trace, FF(512), FF(1024), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::U16); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.alu_u16_tag, FF(1)); // Decomposition of integer multiplication in 8-bit and 16-bit registers // 512 * 1024 = 0 + 8 * 2^16 - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(8)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(8)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(0)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test of equality on U16 elements @@ -974,9 +975,9 @@ TEST_F(AvmArithmeticTestsU16, equality) auto alu_row_index = common_validate_eq(trace, FF(35823), FF(35823), FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::U16); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u16_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_op_eq_diff_inv, FF(0)); - validate_trace(std::move(trace)); + EXPECT_EQ(alu_row.alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.alu_op_eq_diff_inv, FF(0)); + validate_trace(std::move(trace), public_inputs); } // Test correct non-equality of U16 elements @@ -987,9 +988,9 @@ TEST_F(AvmArithmeticTestsU16, nonEquality) auto alu_row_index = common_validate_eq(trace, 35'823, 50'123, FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::U16); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u16_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_op_eq_diff_inv, FF(-14'300).invert()); - validate_trace(std::move(trace)); + EXPECT_EQ(alu_row.alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row.alu_op_eq_diff_inv, FF(-14'300).invert()); + validate_trace(std::move(trace), public_inputs); } /****************************************************************************** @@ -1010,13 +1011,13 @@ TEST_F(AvmArithmeticTestsU32, addition) auto alu_row = common_validate_add( trace, FF(1000000000), FF(1234567891), FF(2234567891LLU), FF(8), FF(9), FF(0), AvmMemoryTag::U32); - EXPECT_EQ(alu_row.avm_alu_u32_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(2234567891LLU & UINT8_MAX)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF((2234567891LLU >> 8) & UINT8_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(2234567891LLU >> 16)); + EXPECT_EQ(alu_row.alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(2234567891LLU & UINT8_MAX)); + EXPECT_EQ(alu_row.alu_u8_r1, FF((2234567891LLU >> 8) & UINT8_MAX)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(2234567891LLU >> 16)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic addition over u32 type with carry. @@ -1033,12 +1034,12 @@ TEST_F(AvmArithmeticTestsU32, additionCarry) auto alu_row = common_validate_add(trace, FF(UINT32_MAX - 1293), FF(2293), FF(999), FF(8), FF(9), FF(0), AvmMemoryTag::U32); - EXPECT_EQ(alu_row.avm_alu_u32_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(231)); // 999 = 3 * 256 + 231 - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(3)); + EXPECT_EQ(alu_row.alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(231)); // 999 = 3 * 256 + 231 + EXPECT_EQ(alu_row.alu_u8_r1, FF(3)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic subtraction over u32 type. @@ -1055,16 +1056,16 @@ TEST_F(AvmArithmeticTestsU32, subtraction) auto alu_row = common_validate_sub( trace, FF(1345678991), FF(1234567891), FF(111111100), FF(8), FF(9), FF(0), AvmMemoryTag::U32); - EXPECT_EQ(alu_row.avm_alu_u32_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); // 111111100 = 0x69F6BBC - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0xBC)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0x6B)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(0x69F)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0xBC)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0x6B)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(0x69F)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(0)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic subtraction over u32 type with carry. @@ -1082,21 +1083,21 @@ TEST_F(AvmArithmeticTestsU32, subtractionCarry) auto alu_row = common_validate_sub( trace, FF(3210987654LLU), FF(UINT32_MAX - 99), FF(3210987754LLU), FF(9), FF(8), FF(0), AvmMemoryTag::U32); - EXPECT_EQ(alu_row.avm_alu_u32_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(1)); + EXPECT_EQ(alu_row.alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(1)); // 3210987754 = 0xBF63C8EA - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0xEA)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0xC8)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(0xBF63)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r3, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r4, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r5, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r6, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0xEA)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0xC8)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(0xBF63)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r2, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r3, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r4, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r5, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r6, FF(UINT16_MAX)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic multiplication over u32 type. @@ -1114,18 +1115,18 @@ TEST_F(AvmArithmeticTestsU32, multiplication) common_validate_mul(trace, FF(11111), FF(11111), FF(123454321), FF(0), FF(1), FF(2), AvmMemoryTag::U32); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.alu_u32_tag, FF(1)); // Decomposition of integer multiplication in 8-bit and 16-bit registers // 123454321 = 0x75BC371 - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0x71)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0xC3)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(0x75B)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r3, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0x71)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0xC3)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(0x75B)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r2, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r3, FF(0)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on multiplication over u32 type with overflow. @@ -1143,18 +1144,18 @@ TEST_F(AvmArithmeticTestsU32, multiplicationOverflow) common_validate_mul(trace, FF(11 << 25), FF(13 << 22), FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::U32); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.alu_u32_tag, FF(1)); // Decomposition of integer multiplication in 8-bit and 16-bit registers // 143 * 2^47 = 0 + 0 * 2^16 + 2^15 * 2^32 + 71 * 2^48 - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(32768)); // 2^15 - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(71)); - EXPECT_EQ(alu_row.avm_alu_u16_r3, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(32768)); // 2^15 + EXPECT_EQ(alu_row.alu_u16_r2, FF(71)); + EXPECT_EQ(alu_row.alu_u16_r3, FF(0)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test of equality on U32 elements @@ -1166,9 +1167,9 @@ TEST_F(AvmArithmeticTestsU32, equality) common_validate_eq(trace, 0xb435e9c1, 0xb435e9c1, FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::U32); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u32_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_op_eq_diff_inv, FF(0)); - validate_trace(std::move(trace)); + EXPECT_EQ(alu_row.alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.alu_op_eq_diff_inv, FF(0)); + validate_trace(std::move(trace), public_inputs); } // Test correct non-equality of U32 elements @@ -1180,9 +1181,9 @@ TEST_F(AvmArithmeticTestsU32, nonEquality) common_validate_eq(trace, 0xb435e9c1, 0xb435e9c0, FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::U32); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u32_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_op_eq_diff_inv, FF(1).invert()); - validate_trace(std::move(trace)); + EXPECT_EQ(alu_row.alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row.alu_op_eq_diff_inv, FF(1).invert()); + validate_trace(std::move(trace), public_inputs); } /****************************************************************************** @@ -1206,17 +1207,17 @@ TEST_F(AvmArithmeticTestsU64, addition) auto alu_row = common_validate_add(trace, FF(a), FF(b), FF(c), FF(8), FF(9), FF(9), AvmMemoryTag::U64); - EXPECT_EQ(alu_row.avm_alu_u64_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); // c in HEX: 2436849FE16F1D - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0x1D)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0x6F)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(0x9FE1)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(0x3684)); - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(0x24)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0x1D)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0x6F)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(0x9FE1)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(0x3684)); + EXPECT_EQ(alu_row.alu_u16_r2, FF(0x24)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic addition over u64 type with carry. @@ -1236,15 +1237,15 @@ TEST_F(AvmArithmeticTestsU64, additionCarry) auto alu_row = common_validate_add(trace, FF(a), FF(b), FF(c), FF(0), FF(1), FF(0), AvmMemoryTag::U64); - EXPECT_EQ(alu_row.avm_alu_u64_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(UINT8_MAX - 201)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(UINT8_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(UINT8_MAX - 201)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(UINT8_MAX)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r2, FF(UINT16_MAX)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic subtraction over u64 type. @@ -1264,18 +1265,18 @@ TEST_F(AvmArithmeticTestsU64, subtraction) auto alu_row = common_validate_sub(trace, FF(a), FF(b), FF(c), FF(8), FF(9), FF(9), AvmMemoryTag::U64); - EXPECT_EQ(alu_row.avm_alu_u64_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); // 10000000000000000 = 0x2386F26FC10000 - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(0X6FC1)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(0X86F2)); - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(0X23)); - EXPECT_EQ(alu_row.avm_alu_u16_r3, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(0X6FC1)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(0X86F2)); + EXPECT_EQ(alu_row.alu_u16_r2, FF(0X23)); + EXPECT_EQ(alu_row.alu_u16_r3, FF(0)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic subtraction over u64 type with carry. @@ -1296,19 +1297,19 @@ TEST_F(AvmArithmeticTestsU64, subtractionCarry) auto alu_row = common_validate_sub(trace, FF(a), FF(b), FF(c), FF(0), FF(1), FF(0), AvmMemoryTag::U64); - EXPECT_EQ(alu_row.avm_alu_u64_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(1)); + EXPECT_EQ(alu_row.alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(1)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(UINT8_MAX - 74)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(UINT8_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r3, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r4, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r5, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r6, FF(UINT16_MAX)); - validate_trace(std::move(trace)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(UINT8_MAX - 74)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(UINT8_MAX)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r2, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r3, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r4, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r5, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r6, FF(UINT16_MAX)); + validate_trace(std::move(trace), public_inputs); } // Test on basic multiplication over u64 type. @@ -1326,18 +1327,18 @@ TEST_F(AvmArithmeticTestsU64, multiplication) trace, FF(999888777), FF(555444333), FF(555382554814950741LLU), FF(0), FF(1), FF(2), AvmMemoryTag::U64); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.alu_u64_tag, FF(1)); // Decomposition of integer multiplication in 8-bit and 16-bit registers // 555,382,554,814,950,741 = 0x 7B5 1D7D B631 AD55 - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0x55)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0xAD)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(0xB631)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(0x1D7D)); - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(0x7B5)); - EXPECT_EQ(alu_row.avm_alu_u16_r3, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0x55)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0xAD)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(0xB631)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(0x1D7D)); + EXPECT_EQ(alu_row.alu_u16_r2, FF(0x7B5)); + EXPECT_EQ(alu_row.alu_u16_r3, FF(0)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on multiplication over u64 type with overflow. @@ -1358,21 +1359,21 @@ TEST_F(AvmArithmeticTestsU64, multiplicationOverflow) auto alu_row_index = common_validate_mul(trace, FF(a), FF(b), FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::U64); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.alu_u64_tag, FF(1)); // Decomposition of integer multiplication in 8-bit and 16-bit registers // 2^128 - 2^65 + 1 - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(1)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r3, FF(UINT16_MAX - 1)); - EXPECT_EQ(alu_row.avm_alu_u16_r4, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r5, FF(UINT16_MAX)); - EXPECT_EQ(alu_row.avm_alu_u16_r6, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(1)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r2, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r3, FF(UINT16_MAX - 1)); + EXPECT_EQ(alu_row.alu_u16_r4, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r5, FF(UINT16_MAX)); + EXPECT_EQ(alu_row.alu_u16_r6, FF(UINT16_MAX)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } TEST_F(AvmArithmeticTestsU64, equality) @@ -1383,9 +1384,9 @@ TEST_F(AvmArithmeticTestsU64, equality) trace, 0xffffffffffffffe0LLU, 0xffffffffffffffe0LLU, FF(1), FF(0), FF(1), FF(2), AvmMemoryTag::U64); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u64_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_op_eq_diff_inv, FF(0)); - validate_trace(std::move(trace)); + EXPECT_EQ(alu_row.alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.alu_op_eq_diff_inv, FF(0)); + validate_trace(std::move(trace), public_inputs); } // Test correct non-equality of U64 elements @@ -1397,9 +1398,9 @@ TEST_F(AvmArithmeticTestsU64, nonEquality) trace, 0xffffffffffffffe0LLU, 0xffffffffffaeffe0LLU, FF(0), FF(0), FF(1), FF(2), AvmMemoryTag::U64); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u64_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_op_eq_diff_inv, FF(0x510000).invert()); - validate_trace(std::move(trace)); + EXPECT_EQ(alu_row.alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row.alu_op_eq_diff_inv, FF(0x510000).invert()); + validate_trace(std::move(trace), public_inputs); } /****************************************************************************** @@ -1430,19 +1431,19 @@ TEST_F(AvmArithmeticTestsU128, addition) FF(9), AvmMemoryTag::U128); - EXPECT_EQ(alu_row.avm_alu_u128_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0xEE)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0xEE)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(0xFFFF)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(0xAAAA)); - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(0xDDDD)); - EXPECT_EQ(alu_row.avm_alu_u16_r3, FF(0x5555)); - EXPECT_EQ(alu_row.avm_alu_u16_r4, FF(0x6666)); - EXPECT_EQ(alu_row.avm_alu_u16_r5, FF(0x4444)); - EXPECT_EQ(alu_row.avm_alu_u16_r6, FF(0x8888)); + EXPECT_EQ(alu_row.alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0xEE)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0xEE)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(0xFFFF)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(0xAAAA)); + EXPECT_EQ(alu_row.alu_u16_r2, FF(0xDDDD)); + EXPECT_EQ(alu_row.alu_u16_r3, FF(0x5555)); + EXPECT_EQ(alu_row.alu_u16_r4, FF(0x6666)); + EXPECT_EQ(alu_row.alu_u16_r5, FF(0x4444)); + EXPECT_EQ(alu_row.alu_u16_r6, FF(0x8888)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic addition over u128 type with carry. @@ -1470,19 +1471,19 @@ TEST_F(AvmArithmeticTestsU128, additionCarry) FF(9), AvmMemoryTag::U128); - EXPECT_EQ(alu_row.avm_alu_u128_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(1)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0x9B)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0xDD)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(0xF97E)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(0xFFFF)); - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(0xFFFF)); - EXPECT_EQ(alu_row.avm_alu_u16_r3, FF(0xFFFF)); - EXPECT_EQ(alu_row.avm_alu_u16_r4, FF(0xFFFF)); - EXPECT_EQ(alu_row.avm_alu_u16_r5, FF(0xFFFF)); - EXPECT_EQ(alu_row.avm_alu_u16_r6, FF(0xFFFF)); + EXPECT_EQ(alu_row.alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(1)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0x9B)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0xDD)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(0xF97E)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(0xFFFF)); + EXPECT_EQ(alu_row.alu_u16_r2, FF(0xFFFF)); + EXPECT_EQ(alu_row.alu_u16_r3, FF(0xFFFF)); + EXPECT_EQ(alu_row.alu_u16_r4, FF(0xFFFF)); + EXPECT_EQ(alu_row.alu_u16_r5, FF(0xFFFF)); + EXPECT_EQ(alu_row.alu_u16_r6, FF(0xFFFF)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic subtraction over u128 type. @@ -1509,22 +1510,22 @@ TEST_F(AvmArithmeticTestsU128, subtraction) FF(9), AvmMemoryTag::U128); - EXPECT_EQ(alu_row.avm_alu_u128_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); // 36771555 = 23116E3 - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0xE3)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0x16)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(0x231)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r3, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r4, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r5, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r6, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r7, FF(0)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0xE3)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0x16)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(0x231)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r2, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r3, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r4, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r5, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r6, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r7, FF(0)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic subtraction over u128 type with carry. @@ -1551,20 +1552,20 @@ TEST_F(AvmArithmeticTestsU128, subtractionCarry) FF(9), AvmMemoryTag::U128); - EXPECT_EQ(alu_row.avm_alu_u128_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_cf, FF(0)); + EXPECT_EQ(alu_row.alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row.alu_cf, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u8_r0, FF(0x88)); - EXPECT_EQ(alu_row.avm_alu_u8_r1, FF(0x88)); - EXPECT_EQ(alu_row.avm_alu_u16_r0, FF(0x5555)); - EXPECT_EQ(alu_row.avm_alu_u16_r1, FF(0x8888)); - EXPECT_EQ(alu_row.avm_alu_u16_r2, FF(0x3333)); - EXPECT_EQ(alu_row.avm_alu_u16_r3, FF(0x3333)); - EXPECT_EQ(alu_row.avm_alu_u16_r4, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r5, FF(0)); - EXPECT_EQ(alu_row.avm_alu_u16_r6, FF(0x2222)); + EXPECT_EQ(alu_row.alu_u8_r0, FF(0x88)); + EXPECT_EQ(alu_row.alu_u8_r1, FF(0x88)); + EXPECT_EQ(alu_row.alu_u16_r0, FF(0x5555)); + EXPECT_EQ(alu_row.alu_u16_r1, FF(0x8888)); + EXPECT_EQ(alu_row.alu_u16_r2, FF(0x3333)); + EXPECT_EQ(alu_row.alu_u16_r3, FF(0x3333)); + EXPECT_EQ(alu_row.alu_u16_r4, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r5, FF(0)); + EXPECT_EQ(alu_row.alu_u16_r6, FF(0x2222)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Test on basic multiplication over u128 type. @@ -1584,23 +1585,23 @@ TEST_F(AvmArithmeticTestsU128, multiplication) trace, FF(0x38D64BF685FFBLLU), FF(555444333222111LLU), c, FF(0), FF(1), FF(2), AvmMemoryTag::U128); auto alu_row_first = trace.at(alu_row_index); - EXPECT_EQ(alu_row_first.avm_alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row_first.alu_u128_tag, FF(1)); // Decomposition of the first operand in 16-bit registers - EXPECT_EQ(alu_row_first.avm_alu_u8_r0, FF(0xFB)); - EXPECT_EQ(alu_row_first.avm_alu_u8_r1, FF(0x5F)); - EXPECT_EQ(alu_row_first.avm_alu_u16_r0, FF(0xBF68)); - EXPECT_EQ(alu_row_first.avm_alu_u16_r1, FF(0x8D64)); - EXPECT_EQ(alu_row_first.avm_alu_u16_r2, FF(0x3)); + EXPECT_EQ(alu_row_first.alu_u8_r0, FF(0xFB)); + EXPECT_EQ(alu_row_first.alu_u8_r1, FF(0x5F)); + EXPECT_EQ(alu_row_first.alu_u16_r0, FF(0xBF68)); + EXPECT_EQ(alu_row_first.alu_u16_r1, FF(0x8D64)); + EXPECT_EQ(alu_row_first.alu_u16_r2, FF(0x3)); // Decomposition of the second operand in 16-bit registers auto alu_row_second = trace.at(alu_row_index + 1); - EXPECT_EQ(alu_row_second.avm_alu_u8_r0, FF(0xDF)); - EXPECT_EQ(alu_row_second.avm_alu_u8_r1, FF(0x98)); - EXPECT_EQ(alu_row_second.avm_alu_u16_r0, FF(0x762C)); - EXPECT_EQ(alu_row_second.avm_alu_u16_r1, FF(0xF92C)); - EXPECT_EQ(alu_row_second.avm_alu_u16_r2, FF(0x1)); - validate_trace(std::move(trace)); + EXPECT_EQ(alu_row_second.alu_u8_r0, FF(0xDF)); + EXPECT_EQ(alu_row_second.alu_u8_r1, FF(0x98)); + EXPECT_EQ(alu_row_second.alu_u16_r0, FF(0x762C)); + EXPECT_EQ(alu_row_second.alu_u16_r1, FF(0xF92C)); + EXPECT_EQ(alu_row_second.alu_u16_r2, FF(0x1)); + validate_trace(std::move(trace), public_inputs); } // Test on multiplication over u128 type with overflow. @@ -1629,30 +1630,30 @@ TEST_F(AvmArithmeticTestsU128, multiplicationOverflow) AvmMemoryTag::U128); auto alu_row_first = trace.at(alu_row_index); - EXPECT_EQ(alu_row_first.avm_alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row_first.alu_u128_tag, FF(1)); // Decomposition of the first operand in 16-bit registers - EXPECT_EQ(alu_row_first.avm_alu_u8_r0, FF(0xFE)); - EXPECT_EQ(alu_row_first.avm_alu_u8_r1, FF(0xFF)); - EXPECT_EQ(alu_row_first.avm_alu_u16_r0, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_first.avm_alu_u16_r1, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_first.avm_alu_u16_r2, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_first.avm_alu_u16_r3, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_first.avm_alu_u16_r4, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_first.avm_alu_u16_r5, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_first.avm_alu_u16_r6, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.alu_u8_r0, FF(0xFE)); + EXPECT_EQ(alu_row_first.alu_u8_r1, FF(0xFF)); + EXPECT_EQ(alu_row_first.alu_u16_r0, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.alu_u16_r1, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.alu_u16_r2, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.alu_u16_r3, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.alu_u16_r4, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.alu_u16_r5, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.alu_u16_r6, FF(UINT16_MAX)); // Decomposition of the second operand in 16-bit registers auto alu_row_second = trace.at(alu_row_index + 1); - EXPECT_EQ(alu_row_second.avm_alu_u8_r0, FF(0xFC)); - EXPECT_EQ(alu_row_second.avm_alu_u8_r1, FF(0xFF)); - EXPECT_EQ(alu_row_second.avm_alu_u16_r0, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_second.avm_alu_u16_r1, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_second.avm_alu_u16_r2, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_second.avm_alu_u16_r3, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_second.avm_alu_u16_r4, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_second.avm_alu_u16_r5, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_second.avm_alu_u16_r6, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_second.alu_u8_r0, FF(0xFC)); + EXPECT_EQ(alu_row_second.alu_u8_r1, FF(0xFF)); + EXPECT_EQ(alu_row_second.alu_u16_r0, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_second.alu_u16_r1, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_second.alu_u16_r2, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_second.alu_u16_r3, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_second.alu_u16_r4, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_second.alu_u16_r5, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_second.alu_u16_r6, FF(UINT16_MAX)); // Other registers involved in the relevant relations // PIL relation (avm_alu.pil): a * b_l + a_l * b_h * 2^64 = (CF * 2^64 + R_64) * 2^128 + c @@ -1661,14 +1662,14 @@ TEST_F(AvmArithmeticTestsU128, multiplicationOverflow) // Therefore, CF = 1 and R_64 = 2^64 - 7 // R_64 is decomposed over the 4 following 16-bit registers - EXPECT_EQ(alu_row_first.avm_alu_u16_r7, FF(UINT16_MAX - 6)); - EXPECT_EQ(alu_row_first.avm_alu_u16_r8, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_first.avm_alu_u16_r9, FF(UINT16_MAX)); - EXPECT_EQ(alu_row_first.avm_alu_u16_r10, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.alu_u16_r7, FF(UINT16_MAX - 6)); + EXPECT_EQ(alu_row_first.alu_u16_r8, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.alu_u16_r9, FF(UINT16_MAX)); + EXPECT_EQ(alu_row_first.alu_u16_r10, FF(UINT16_MAX)); // CF - EXPECT_EQ(alu_row_first.avm_alu_cf, FF(1)); + EXPECT_EQ(alu_row_first.alu_cf, FF(1)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } TEST_F(AvmArithmeticTestsU128, equality) @@ -1686,9 +1687,9 @@ TEST_F(AvmArithmeticTestsU128, equality) AvmMemoryTag::U128); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u128_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_op_eq_diff_inv, FF(0)); - validate_trace(std::move(trace)); + EXPECT_EQ(alu_row.alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row.alu_op_eq_diff_inv, FF(0)); + validate_trace(std::move(trace), public_inputs); } // Test correct non-equality of U128 elements @@ -1708,9 +1709,9 @@ TEST_F(AvmArithmeticTestsU128, nonEquality) AvmMemoryTag::U128); auto alu_row = trace.at(alu_row_index); - EXPECT_EQ(alu_row.avm_alu_u128_tag, FF(1)); - EXPECT_EQ(alu_row.avm_alu_op_eq_diff_inv, FF(0xdeadbeefLLU << 32).invert()); - validate_trace(std::move(trace)); + EXPECT_EQ(alu_row.alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row.alu_op_eq_diff_inv, FF(0xdeadbeefLLU << 32).invert()); + validate_trace(std::move(trace), public_inputs); } /****************************************************************************** @@ -1769,7 +1770,7 @@ TEST_F(AvmArithmeticNegativeTestsFF, fDivision) trace_builder.halt(); auto trace = trace_builder.finalize(); - auto select_row = [](Row r) { return r.avm_main_sel_op_fdiv == FF(1); }; + auto select_row = [](Row r) { return r.main_sel_op_fdiv == FF(1); }; mutate_ic_in_trace(trace, std::move(select_row), FF(0)); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "SUBOP_FDIV"); @@ -1787,18 +1788,18 @@ TEST_F(AvmArithmeticNegativeTestsFF, fDivisionNoZeroButError) auto trace = trace_builder.finalize(); // Find the first row enabling the fdiv selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fdiv == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fdiv == FF(1); }); size_t const index = static_cast(row - trace.begin()); // Activate the operator error - trace[index].avm_main_op_err = FF(1); + trace[index].main_op_err = FF(1); auto trace2 = trace; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "SUBOP_FDIV_ZERO_ERR1"); // Even more malicious, one makes the first relation passes by setting the inverse to zero. - trace2[index].avm_main_inv = FF(0); + trace2[index].main_inv = FF(0); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace2)), "SUBOP_FDIV_ZERO_ERR2"); } @@ -1813,10 +1814,10 @@ TEST_F(AvmArithmeticNegativeTestsFF, fDivisionByZeroNoError) auto trace = trace_builder.finalize(); // Find the first row enabling the fdiv selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fdiv == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fdiv == FF(1); }); // Remove the operator error flag - row->avm_main_op_err = FF(0); + row->main_op_err = FF(0); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "SUBOP_FDIV"); } @@ -1830,10 +1831,10 @@ TEST_F(AvmArithmeticNegativeTestsFF, fDivisionZeroByZeroNoError) auto trace = trace_builder.finalize(); // Find the first row enabling the fdiv selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fdiv == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fdiv == FF(1); }); // Remove the operator error flag - row->avm_main_op_err = FF(0); + row->main_op_err = FF(0); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "SUBOP_FDIV_ZERO_ERR1"); } @@ -1848,10 +1849,10 @@ TEST_F(AvmArithmeticNegativeTestsFF, fDivisionWrongRInTag) auto trace = trace_builder.finalize(); // Find the first row enabling the fdiv selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fdiv == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fdiv == FF(1); }); // Change read instruction tag - row->avm_main_r_in_tag = FF(3); + row->main_r_in_tag = FF(3); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "SUBOP_FDIV_R_IN_TAG_FF"); } @@ -1866,10 +1867,10 @@ TEST_F(AvmArithmeticNegativeTestsFF, fDivisionWrongWInTag) auto trace = trace_builder.finalize(); // Find the first row enabling the fdiv selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fdiv == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fdiv == FF(1); }); // Change write instruction tag - row->avm_main_w_in_tag = FF(3); + row->main_w_in_tag = FF(3); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "SUBOP_FDIV_W_IN_TAG_FF"); } @@ -1887,10 +1888,10 @@ TEST_F(AvmArithmeticNegativeTestsFF, operationWithErrorFlag) auto trace = trace_builder.finalize(); // Find the first row enabling the addition selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_add == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_add == FF(1); }); // Activate the operator error - row->avm_main_op_err = FF(1); + row->main_op_err = FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "SUBOP_ERROR_RELEVANT_OP"); @@ -1904,10 +1905,10 @@ TEST_F(AvmArithmeticNegativeTestsFF, operationWithErrorFlag) trace = trace_builder.finalize(); // Find the first row enabling the subtraction selector - row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == FF(1); }); + row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sub == FF(1); }); // Activate the operator error - row->avm_main_op_err = FF(1); + row->main_op_err = FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "SUBOP_ERROR_RELEVANT_OP"); @@ -1921,10 +1922,10 @@ TEST_F(AvmArithmeticNegativeTestsFF, operationWithErrorFlag) trace = trace_builder.finalize(); // Find the first row enabling the multiplication selector - row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == FF(1); }); + row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_mul == FF(1); }); // Activate the operator error - row->avm_main_op_err = FF(1); + row->main_op_err = FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "SUBOP_ERROR_RELEVANT_OP"); } @@ -1962,10 +1963,10 @@ TEST_F(AvmArithmeticNegativeTestsFF, eqOutputWrongTag) auto trace = trace_builder.finalize(); // Find the first row enabling the eq selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_eq == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_eq == FF(1); }); ASSERT_TRUE(row != trace.end()); - row->avm_main_w_in_tag = FF(4); + row->main_w_in_tag = FF(4); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "OUTPUT_U8"); } @@ -2030,10 +2031,10 @@ TEST_F(AvmArithmeticNegativeTestsU8, eqOutputWrongTag) auto trace = gen_trace_eq(2, 3, 23, 24, 25, AvmMemoryTag::U8); // Find the first row enabling the eq selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_eq == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_eq == FF(1); }); ASSERT_TRUE(row != trace.end()); - row->avm_main_w_in_tag = FF(3); + row->main_w_in_tag = FF(3); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "OUTPUT_U8"); } @@ -2097,10 +2098,10 @@ TEST_F(AvmArithmeticNegativeTestsU16, eqOutputWrongTag) auto trace = gen_trace_eq(1515, 1515, 23, 24, 25, AvmMemoryTag::U16); // Find the first row enabling the eq selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_eq == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_eq == FF(1); }); ASSERT_TRUE(row != trace.end()); - row->avm_main_w_in_tag = FF(5); + row->main_w_in_tag = FF(5); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "OUTPUT_U8"); } @@ -2164,10 +2165,10 @@ TEST_F(AvmArithmeticNegativeTestsU32, eqOutputWrongTag) auto trace = gen_trace_eq(15, 15, 23, 24, 25, AvmMemoryTag::U32); // Find the first row enabling the eq selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_eq == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_eq == FF(1); }); ASSERT_TRUE(row != trace.end()); - row->avm_main_w_in_tag = FF(6); + row->main_w_in_tag = FF(6); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "OUTPUT_U8"); } @@ -2238,10 +2239,10 @@ TEST_F(AvmArithmeticNegativeTestsU64, eqOutputWrongTag) auto trace = gen_trace_eq(198732, 15, 23, 24, 25, AvmMemoryTag::U64); // Find the first row enabling the eq selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_eq == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_eq == FF(1); }); ASSERT_TRUE(row != trace.end()); - row->avm_main_w_in_tag = FF(2); + row->main_w_in_tag = FF(2); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "OUTPUT_U8"); } @@ -2314,24 +2315,24 @@ TEST_F(AvmArithmeticNegativeTestsU128, multiplicationSecondRowNoOp) auto alu_row_index = common_validate_mul(trace, FF(3), FF(4), FF(12), FF(0), FF(1), FF(2), AvmMemoryTag::U128); // We have to enable alu_sel otherwise another relation will fail. - trace.at(alu_row_index + 1).avm_alu_alu_sel = 1; + trace.at(alu_row_index + 1).alu_sel_alu = 1; // Add an LTE selector in the next row (second part of U128 multiplication) auto trace_lte = trace; - trace_lte.at(alu_row_index + 1).avm_alu_op_lte = 1; + trace_lte.at(alu_row_index + 1).alu_op_lte = 1; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace_lte)), "TWO_LINE_OP_NO_OVERLAP"); // Try with SUB selector. auto trace_sub = trace; - trace_sub.at(alu_row_index + 1).avm_alu_op_sub = 1; + trace_sub.at(alu_row_index + 1).alu_op_sub = 1; // Adjust to not violate #[RNG_CHK_LOOKUP_SELECTOR] - trace_sub.at(alu_row_index + 1).avm_alu_rng_chk_lookup_selector = 2; + trace_sub.at(alu_row_index + 1).alu_sel_rng_chk_lookup = 2; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace_sub)), "TWO_LINE_OP_NO_OVERLAP"); // Try with another MUL selector. - trace.at(alu_row_index + 1).avm_alu_op_mul = 1; + trace.at(alu_row_index + 1).alu_op_mul = 1; // Adjust to not violate #[RNG_CHK_LOOKUP_SELECTOR] - trace.at(alu_row_index + 1).avm_alu_rng_chk_lookup_selector = 2; + trace.at(alu_row_index + 1).alu_sel_rng_chk_lookup = 2; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "TWO_LINE_OP_NO_OVERLAP"); } @@ -2372,10 +2373,10 @@ TEST_F(AvmArithmeticNegativeTestsU128, eqOutputWrongTag) auto trace = gen_trace_eq(1587, 1587, 23, 24, 25, AvmMemoryTag::U128); // Find the first row enabling the eq selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_eq == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_eq == FF(1); }); ASSERT_TRUE(row != trace.end()); - row->avm_main_w_in_tag = FF(4); + row->main_w_in_tag = FF(4); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "OUTPUT_U8"); } diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp index e84359e8e19..ff1c4168616 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_bitwise.test.cpp @@ -12,6 +12,7 @@ #include namespace tests_avm { + using namespace bb; using namespace bb::avm_trace; @@ -26,40 +27,40 @@ void common_validate_op_not(std::vector const& trace, { // Find the first row enabling the not selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_not == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_not == FF(1); }); // Use the row in the main trace to find the same operation in the alu trace. - FF clk = row->avm_main_clk; - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_clk == clk; }); + FF clk = row->main_clk; + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.alu_clk == clk; }); // Check that both rows were found EXPECT_TRUE(row != trace.end()); EXPECT_TRUE(alu_row != trace.end()); // Check that the correct result is stored at the expected memory location. - EXPECT_EQ(row->avm_main_ic, c); - EXPECT_EQ(row->avm_main_mem_idx_c, addr_c); - EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); - EXPECT_EQ(row->avm_main_rwc, FF(1)); + EXPECT_EQ(row->main_ic, c); + EXPECT_EQ(row->main_mem_addr_c, addr_c); + EXPECT_EQ(row->main_sel_mem_op_c, FF(1)); + EXPECT_EQ(row->main_rwc, FF(1)); // Check that ia register is correctly set with memory load operations. - EXPECT_EQ(row->avm_main_ia, a); - EXPECT_EQ(row->avm_main_mem_idx_a, addr_a); - EXPECT_EQ(row->avm_main_mem_op_a, FF(1)); - EXPECT_EQ(row->avm_main_rwa, FF(0)); + EXPECT_EQ(row->main_ia, a); + EXPECT_EQ(row->main_mem_addr_a, addr_a); + EXPECT_EQ(row->main_sel_mem_op_a, FF(1)); + EXPECT_EQ(row->main_rwa, FF(0)); // Check the instruction tags - EXPECT_EQ(row->avm_main_r_in_tag, FF(static_cast(tag))); - EXPECT_EQ(row->avm_main_w_in_tag, FF(static_cast(tag))); + EXPECT_EQ(row->main_r_in_tag, FF(static_cast(tag))); + EXPECT_EQ(row->main_w_in_tag, FF(static_cast(tag))); // Check that intermediate registers are correctly copied in Alu trace - EXPECT_EQ(alu_row->avm_alu_ia, a); - EXPECT_EQ(alu_row->avm_alu_ib, FF(0)); - EXPECT_EQ(alu_row->avm_alu_ic, c); + EXPECT_EQ(alu_row->alu_ia, a); + EXPECT_EQ(alu_row->alu_ib, FF(0)); + EXPECT_EQ(alu_row->alu_ic, c); // Check that not selector is set. - EXPECT_EQ(row->avm_main_sel_op_not, FF(1)); - EXPECT_EQ(alu_row->avm_alu_op_not, FF(1)); + EXPECT_EQ(row->main_sel_op_not, FF(1)); + EXPECT_EQ(alu_row->alu_op_not, FF(1)); switch (tag) { // Handle the different mem_tags here since this is part of a // parameterised test @@ -67,19 +68,19 @@ void common_validate_op_not(std::vector const& trace, FAIL() << "Unintialized Mem Tags Disallowed"; break; case AvmMemoryTag::U8: - EXPECT_EQ(alu_row->avm_alu_u8_tag, FF(1)); + EXPECT_EQ(alu_row->alu_u8_tag, FF(1)); break; case AvmMemoryTag::U16: - EXPECT_EQ(alu_row->avm_alu_u16_tag, FF(1)); + EXPECT_EQ(alu_row->alu_u16_tag, FF(1)); break; case AvmMemoryTag::U32: - EXPECT_EQ(alu_row->avm_alu_u32_tag, FF(1)); + EXPECT_EQ(alu_row->alu_u32_tag, FF(1)); break; case AvmMemoryTag::U64: - EXPECT_EQ(alu_row->avm_alu_u64_tag, FF(1)); + EXPECT_EQ(alu_row->alu_u64_tag, FF(1)); break; case AvmMemoryTag::U128: - EXPECT_EQ(alu_row->avm_alu_u128_tag, FF(1)); + EXPECT_EQ(alu_row->alu_u128_tag, FF(1)); break; case AvmMemoryTag::FF: FAIL() << "FF Mem Tags Disallowed for bitwise"; @@ -97,40 +98,39 @@ void common_validate_shift_op(std::vector const& trace, avm_trace::AvmMemoryTag const tag, bool shr) { - auto row = - shr ? std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_shr == FF(1); }) - : std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_shl == FF(1); }); + auto row = shr ? std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_shr == FF(1); }) + : std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_shl == FF(1); }); ASSERT_TRUE(row != trace.end()); - FF clk = row->avm_main_clk; - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_clk == clk; }); + FF clk = row->main_clk; + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.alu_clk == clk; }); ASSERT_TRUE(alu_row != trace.end()); // Check that the correct result is stored at the expected memory location. - EXPECT_EQ(row->avm_main_ic, c); - EXPECT_EQ(row->avm_main_mem_idx_c, addr_c); - EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); - EXPECT_EQ(row->avm_main_rwc, FF(1)); + EXPECT_EQ(row->main_ic, c); + EXPECT_EQ(row->main_mem_addr_c, addr_c); + EXPECT_EQ(row->main_sel_mem_op_c, FF(1)); + EXPECT_EQ(row->main_rwc, FF(1)); // Check that ia register is correctly set with memory load operations. - EXPECT_EQ(row->avm_main_ia, a); - EXPECT_EQ(row->avm_main_mem_idx_a, addr_a); - EXPECT_EQ(row->avm_main_mem_op_a, FF(1)); - EXPECT_EQ(row->avm_main_rwa, FF(0)); + EXPECT_EQ(row->main_ia, a); + EXPECT_EQ(row->main_mem_addr_a, addr_a); + EXPECT_EQ(row->main_sel_mem_op_a, FF(1)); + EXPECT_EQ(row->main_rwa, FF(0)); // Check that ib register is correctly set with memory load operations. - EXPECT_EQ(row->avm_main_ib, b); - EXPECT_EQ(row->avm_main_mem_idx_b, addr_b); - EXPECT_EQ(row->avm_main_mem_op_b, FF(1)); - EXPECT_EQ(row->avm_main_rwb, FF(0)); + EXPECT_EQ(row->main_ib, b); + EXPECT_EQ(row->main_mem_addr_b, addr_b); + EXPECT_EQ(row->main_sel_mem_op_b, FF(1)); + EXPECT_EQ(row->main_rwb, FF(0)); // Check the instruction tags - EXPECT_EQ(row->avm_main_r_in_tag, FF(static_cast(tag))); - EXPECT_EQ(row->avm_main_w_in_tag, FF(static_cast(tag))); + EXPECT_EQ(row->main_r_in_tag, FF(static_cast(tag))); + EXPECT_EQ(row->main_w_in_tag, FF(static_cast(tag))); // Check that start row is the same as what is copied into the main trace - EXPECT_EQ(alu_row->avm_alu_ia, a); - EXPECT_EQ(alu_row->avm_alu_ib, b); - EXPECT_EQ(alu_row->avm_alu_ic, c); + EXPECT_EQ(alu_row->alu_ia, a); + EXPECT_EQ(alu_row->alu_ib, b); + EXPECT_EQ(alu_row->alu_ic, c); } void common_validate_bit_op(std::vector const& trace, @@ -144,52 +144,52 @@ void common_validate_bit_op(std::vector const& trace, avm_trace::AvmMemoryTag const tag) { - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_xor == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_xor == FF(1); }); if (op_id == 0) { - row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_and == FF(1); }); + row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_and == FF(1); }); } else if (op_id == 1) { - row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_or == FF(1); }); + row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_or == FF(1); }); } // Use the row in the main trace to find the same operation in the alu trace. - FF clk = row->avm_main_clk; + FF clk = row->main_clk; auto bin_row_start = std::ranges::find_if( - trace.begin(), trace.end(), [clk](Row r) { return r.avm_binary_clk == clk && r.avm_binary_start == FF(1); }); + trace.begin(), trace.end(), [clk](Row r) { return r.binary_clk == clk && r.binary_start == FF(1); }); // Check that both rows were found ASSERT_TRUE(bin_row_start != trace.end()); ASSERT_TRUE(row != trace.end()); // Check that the correct result is stored at the expected memory location. - EXPECT_EQ(row->avm_main_ic, c); - EXPECT_EQ(row->avm_main_mem_idx_c, addr_c); - EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); - EXPECT_EQ(row->avm_main_rwc, FF(1)); + EXPECT_EQ(row->main_ic, c); + EXPECT_EQ(row->main_mem_addr_c, addr_c); + EXPECT_EQ(row->main_sel_mem_op_c, FF(1)); + EXPECT_EQ(row->main_rwc, FF(1)); // Check that ia register is correctly set with memory load operations. - EXPECT_EQ(row->avm_main_ia, a); - EXPECT_EQ(row->avm_main_mem_idx_a, addr_a); - EXPECT_EQ(row->avm_main_mem_op_a, FF(1)); - EXPECT_EQ(row->avm_main_rwa, FF(0)); + EXPECT_EQ(row->main_ia, a); + EXPECT_EQ(row->main_mem_addr_a, addr_a); + EXPECT_EQ(row->main_sel_mem_op_a, FF(1)); + EXPECT_EQ(row->main_rwa, FF(0)); // Check that ia register is correctly set with memory load operations. - EXPECT_EQ(row->avm_main_ib, b); - EXPECT_EQ(row->avm_main_mem_idx_b, addr_b); - EXPECT_EQ(row->avm_main_mem_op_b, FF(1)); - EXPECT_EQ(row->avm_main_rwb, FF(0)); + EXPECT_EQ(row->main_ib, b); + EXPECT_EQ(row->main_mem_addr_b, addr_b); + EXPECT_EQ(row->main_sel_mem_op_b, FF(1)); + EXPECT_EQ(row->main_rwb, FF(0)); // Check the instruction tags - EXPECT_EQ(row->avm_main_r_in_tag, FF(static_cast(tag))); - EXPECT_EQ(row->avm_main_w_in_tag, FF(static_cast(tag))); + EXPECT_EQ(row->main_r_in_tag, FF(static_cast(tag))); + EXPECT_EQ(row->main_w_in_tag, FF(static_cast(tag))); // Check that start row is the same as what is copied into the main trace - EXPECT_EQ(bin_row_start->avm_binary_acc_ia, a); - EXPECT_EQ(bin_row_start->avm_binary_acc_ib, b); - EXPECT_EQ(bin_row_start->avm_binary_acc_ic, c); + EXPECT_EQ(bin_row_start->binary_acc_ia, a); + EXPECT_EQ(bin_row_start->binary_acc_ib, b); + EXPECT_EQ(bin_row_start->binary_acc_ic, c); - EXPECT_EQ(bin_row_start->avm_binary_op_id, op_id); - EXPECT_EQ(bin_row_start->avm_binary_bin_sel, FF(1)); - EXPECT_EQ(bin_row_start->avm_binary_in_tag, static_cast(tag)); + EXPECT_EQ(bin_row_start->binary_op_id, op_id); + EXPECT_EQ(bin_row_start->binary_sel_bin, FF(1)); + EXPECT_EQ(bin_row_start->binary_in_tag, static_cast(tag)); } // These are the potential failures we handle for the negative tests involving the binary trace. @@ -216,48 +216,48 @@ std::tuple, std::string> gen_mutated_trace_shift(std::vectoravm_main_clk; + auto main_clk = main_trace_row->main_clk; // The corresponding row in the alu trace as well as the row where start = 1 auto alu_row = - std::ranges::find_if(trace.begin(), trace.end(), [main_clk](Row r) { return r.avm_alu_clk == main_clk; }); + std::ranges::find_if(trace.begin(), trace.end(), [main_clk](Row r) { return r.alu_clk == main_clk; }); std::string failure; switch (fail_mode) { case IncorrectShiftPastBitLength: - alu_row->avm_alu_shift_lt_bit_len = FF(0); + alu_row->alu_shift_lt_bit_len = FF(0); update_slice_registers(*alu_row, uint256_t{ 0 }); - alu_row->avm_alu_a_lo = FF(0); - alu_row->avm_alu_a_hi = FF(0); + alu_row->alu_a_lo = FF(0); + alu_row->alu_a_hi = FF(0); failure = "SHIFT_LT_BIT_LEN"; return std::make_tuple(trace, failure); case IncorrectInputDecomposition: { // Subtrace one from b_lo and update b_lo - uint256_t b_lo = alu_row->avm_alu_b_lo - 1; - uint256_t b_hi = alu_row->avm_alu_b_hi; - alu_row->avm_alu_b_lo = b_lo; + uint256_t b_lo = alu_row->alu_b_lo - 1; + uint256_t b_hi = alu_row->alu_b_hi; + alu_row->alu_b_lo = b_lo; // Update the range checks involving b_lo and b_hi so we dont throw an error about the range checks if (shr) { - uint256_t a_lo = (uint256_t(1) << alu_row->avm_alu_ib) - b_lo - 1; - uint256_t a_hi = (uint256_t(1) << (32 - uint8_t(alu_row->avm_alu_ib))) - b_hi - 1; - alu_row->avm_alu_a_lo = a_lo & ((uint256_t(1) << 128) - 1); - alu_row->avm_alu_a_hi = a_hi; + uint256_t a_lo = (uint256_t(1) << alu_row->alu_ib) - b_lo - 1; + uint256_t a_hi = (uint256_t(1) << (32 - uint8_t(alu_row->alu_ib))) - b_hi - 1; + alu_row->alu_a_lo = a_lo & ((uint256_t(1) << 128) - 1); + alu_row->alu_a_hi = a_hi; // Update slice registers update_slice_registers(*alu_row, a_lo + (a_hi << 128)); failure = "SHR_INPUT_DECOMPOSITION"; return std::make_tuple(trace, failure); } - uint256_t a_lo = (uint256_t(1) << (32 - uint8_t(alu_row->avm_alu_ib))) - b_lo - 1; - uint256_t a_hi = (uint256_t(1) << alu_row->avm_alu_ib) - b_hi - 1; - alu_row->avm_alu_a_lo = a_lo & ((uint256_t(1) << 128) - 1); - alu_row->avm_alu_a_hi = a_hi; + uint256_t a_lo = (uint256_t(1) << (32 - uint8_t(alu_row->alu_ib))) - b_lo - 1; + uint256_t a_hi = (uint256_t(1) << alu_row->alu_ib) - b_hi - 1; + alu_row->alu_a_lo = a_lo & ((uint256_t(1) << 128) - 1); + alu_row->alu_a_hi = a_hi; // Update slice registers update_slice_registers(*alu_row, a_lo + (a_hi << 128)); failure = "SHL_INPUT_DECOMPOSITION"; return std::make_tuple(trace, failure); } case ShiftOutputIncorrect: - alu_row->avm_alu_ic = c_mutated; + alu_row->alu_ic = c_mutated; failure = shr ? "SHR_OUTPUT" : "SHL_OUTPUT"; return std::make_tuple(trace, failure); } @@ -269,36 +269,36 @@ std::vector gen_mutated_trace_bit(std::vector trace, BIT_FAILURES fail_mode) { auto main_trace_row = std::ranges::find_if(trace.begin(), trace.end(), select_row); - auto main_clk = main_trace_row->avm_main_clk; + auto main_clk = main_trace_row->main_clk; // The corresponding row in the binary trace as well as the row where start = 1 auto binary_row = - std::ranges::find_if(trace.begin(), trace.end(), [main_clk](Row r) { return r.avm_binary_clk == main_clk; }); + std::ranges::find_if(trace.begin(), trace.end(), [main_clk](Row r) { return r.binary_clk == main_clk; }); // The corresponding row in the binary trace where the computation ends. auto last_row = std::ranges::find_if(trace.begin(), trace.end(), [main_clk](Row r) { - return r.avm_binary_clk == main_clk && r.avm_binary_mem_tag_ctr == FF(0); + return r.binary_clk == main_clk && r.binary_mem_tag_ctr == FF(0); }); switch (fail_mode) { case BitDecomposition: { // Incrementing the bytes should indicate an incorrect decomposition // The lookups are checked later so this will throw an error about decomposition - binary_row->avm_binary_ic_bytes++; + binary_row->binary_ic_bytes++; break; } case MemTagCtr: { // Increment instead of decrementing - binary_row->avm_binary_mem_tag_ctr++; + binary_row->binary_mem_tag_ctr++; break; } case IncorrectAcc: { // The lookups are checked later so this will throw an error about accumulation - binary_row->avm_binary_acc_ic++; + binary_row->binary_acc_ic++; break; } case InconsistentOpId: { // We don't update the first index as that is checked by the permutation check. // So we update the next op_id to be incorrect. auto first_index = static_cast(std::distance(trace.begin(), binary_row)); - trace.at(first_index + 1).avm_binary_op_id++; + trace.at(first_index + 1).binary_op_id++; break; } case ByteLookupError: { @@ -307,8 +307,8 @@ std::vector gen_mutated_trace_bit(std::vector trace, // We intentionally select the mutated value to be 0-bytes everywhere else so we dont need to // update anything there or in the corresponding accumulators. mutate_ic_in_trace(trace, std::move(select_row), c_mutated, false); - binary_row->avm_binary_acc_ic = c_mutated; - binary_row->avm_binary_ic_bytes = static_cast(uint128_t{ c_mutated }); + binary_row->binary_acc_ic = c_mutated; + binary_row->binary_ic_bytes = static_cast(uint128_t{ c_mutated }); break; } case ByteLengthError: { @@ -318,26 +318,26 @@ std::vector gen_mutated_trace_bit(std::vector trace, auto last_index = static_cast(std::distance(trace.begin(), last_row)); auto first_index = static_cast(std::distance(trace.begin(), binary_row)); for (size_t i = first_index; i <= last_index; i++) { - FF ctr = trace.at(i).avm_binary_mem_tag_ctr; + FF ctr = trace.at(i).binary_mem_tag_ctr; if (ctr == FF::one()) { // If the tag is currently 1, it will be set to 0 which means we need to set bin_sel to 0. - trace.at(i).avm_binary_bin_sel = FF(0); - trace.at(i).avm_binary_mem_tag_ctr = FF(0); - trace.at(i).avm_binary_mem_tag_ctr_inv = FF(0); + trace.at(i).binary_sel_bin = FF(0); + trace.at(i).binary_mem_tag_ctr = FF(0); + trace.at(i).binary_mem_tag_ctr_inv = FF(0); } else if (ctr == FF::zero()) { // Leave as zero instead of underflowing - trace.at(i).avm_binary_mem_tag_ctr = FF(0); + trace.at(i).binary_mem_tag_ctr = FF(0); } else { // Replace the values with the next row's values - trace.at(i).avm_binary_mem_tag_ctr = trace.at(i + 1).avm_binary_mem_tag_ctr; - trace.at(i).avm_binary_mem_tag_ctr_inv = trace.at(i + 1).avm_binary_mem_tag_ctr_inv; - trace.at(i).avm_binary_bin_sel = trace.at(i + 1).avm_binary_bin_sel; + trace.at(i).binary_mem_tag_ctr = trace.at(i + 1).binary_mem_tag_ctr; + trace.at(i).binary_mem_tag_ctr_inv = trace.at(i + 1).binary_mem_tag_ctr_inv; + trace.at(i).binary_sel_bin = trace.at(i + 1).binary_sel_bin; } } break; } case IncorrectBinSelector: - binary_row->avm_binary_bin_sel = FF(0); + binary_row->binary_sel_bin = FF(0); break; } return trace; @@ -368,7 +368,7 @@ class AvmBitwiseTests : public ::testing::Test { trace_builder.halt(); auto trace = trace_builder.finalize(); - auto select_row = [](Row r) { return r.avm_main_sel_op_not == FF(1); }; + auto select_row = [](Row r) { return r.main_sel_op_not == FF(1); }; mutate_ic_in_trace(trace, select_row, c_mutated, true); return trace; @@ -479,7 +479,7 @@ TEST_P(AvmBitwiseTestsNot, ParamTest) FF ff_a = FF(uint256_t::from_uint128(a)); FF ff_output = FF(uint256_t::from_uint128(output)); common_validate_op_not(trace, ff_a, ff_output, FF(0), FF(1), mem_tag); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } INSTANTIATE_TEST_SUITE_P(AvmBitwiseTests, @@ -514,7 +514,7 @@ TEST_P(AvmBitwiseTestsOr, AllOrTest) auto trace = trace_builder.finalize(); common_validate_bit_op(trace, 1, a, b, output, FF(0), FF(1), FF(2), mem_tag); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } INSTANTIATE_TEST_SUITE_P(AvmBitwiseTests, AvmBitwiseTestsOr, @@ -531,7 +531,7 @@ TEST_P(AvmBitwiseTestsXor, AllXorTest) auto trace = trace_builder.finalize(); common_validate_bit_op(trace, 2, a, b, output, FF(0), FF(1), FF(2), mem_tag); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } INSTANTIATE_TEST_SUITE_P(AvmBitwiseTests, @@ -548,7 +548,7 @@ TEST_P(AvmBitwiseTestsShr, AllShrTest) trace_builder.return_op(0, 2, 1); auto trace = trace_builder.finalize(); common_validate_shift_op(trace, a, b, output, FF(0), FF(1), FF(2), mem_tag, true); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } INSTANTIATE_TEST_SUITE_P(AvmBitwiseTests, @@ -566,7 +566,7 @@ TEST_P(AvmBitwiseTestsShl, AllShlTest) auto trace = trace_builder.finalize(); common_validate_shift_op(trace, a, b, output, FF(0), FF(1), FF(2), mem_tag, false); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } INSTANTIATE_TEST_SUITE_P(AvmBitwiseTests, @@ -605,7 +605,7 @@ std::vector> bit_failures = { { "LOOKUP_BYTE_LENGTHS", BIT_FAILURES::ByteLengthError }, { "LOOKUP_BYTE_OPERATIONS", BIT_FAILURES::ByteLookupError }, { "OP_ID_REL", BIT_FAILURES::InconsistentOpId }, - { "BIN_SEL_CTR_REL", BIT_FAILURES::IncorrectBinSelector }, + { "SEL_BIN_CTR_REL", BIT_FAILURES::IncorrectBinSelector }, }; std::vector shift_failures = { SHIFT_FAILURES::IncorrectShiftPastBitLength, SHIFT_FAILURES::IncorrectInputDecomposition, @@ -632,7 +632,7 @@ TEST_P(AvmBitwiseNegativeTestsAnd, AllNegativeTests) trace_builder.op_and(0, 0, 1, 2, mem_tag); trace_builder.halt(); auto trace = trace_builder.finalize(); - std::function&& select_row = [](Row r) { return r.avm_main_sel_op_and == FF(1); }; + std::function&& select_row = [](Row r) { return r.main_sel_op_and == FF(1); }; trace = gen_mutated_trace_bit(trace, std::move(select_row), output, failure_mode); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), failure_string); } @@ -651,7 +651,7 @@ TEST_P(AvmBitwiseNegativeTestsOr, AllNegativeTests) trace_builder.op_or(0, 0, 1, 2, mem_tag); trace_builder.halt(); auto trace = trace_builder.finalize(); - std::function&& select_row = [](Row r) { return r.avm_main_sel_op_or == FF(1); }; + std::function&& select_row = [](Row r) { return r.main_sel_op_or == FF(1); }; trace = gen_mutated_trace_bit(trace, std::move(select_row), output, failure_mode); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), failure_string); } @@ -669,7 +669,7 @@ TEST_P(AvmBitwiseNegativeTestsXor, AllNegativeTests) trace_builder.op_xor(0, 0, 1, 2, mem_tag); trace_builder.halt(); auto trace = trace_builder.finalize(); - std::function&& select_row = [](Row r) { return r.avm_main_sel_op_xor == FF(1); }; + std::function&& select_row = [](Row r) { return r.main_sel_op_xor == FF(1); }; trace = gen_mutated_trace_bit(trace, std::move(select_row), output, failure_mode); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), failure_string) } @@ -687,7 +687,7 @@ TEST_P(AvmBitwiseNegativeTestsShr, AllNegativeTests) trace_builder.op_shr(0, 0, 1, 2, mem_tag); trace_builder.halt(); auto trace = trace_builder.finalize(); - std::function&& select_row = [](Row r) { return r.avm_main_sel_op_shr == FF(1); }; + std::function&& select_row = [](Row r) { return r.main_sel_op_shr == FF(1); }; auto [mutated_trace, str] = gen_mutated_trace_shift(std::move(trace), std::move(select_row), output, failure, true); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(mutated_trace)), str); @@ -706,7 +706,7 @@ TEST_P(AvmBitwiseNegativeTestsShl, AllNegativeTests) trace_builder.op_shl(0, 0, 1, 2, mem_tag); trace_builder.halt(); auto trace = trace_builder.finalize(); - std::function&& select_row = [](Row r) { return r.avm_main_sel_op_shl == FF(1); }; + std::function&& select_row = [](Row r) { return r.main_sel_op_shl == FF(1); }; auto [mutated_trace, str] = gen_mutated_trace_shift(std::move(trace), std::move(select_row), output, failure, false); @@ -730,14 +730,14 @@ TEST_F(AvmBitwiseNegativeTestsFF, UndefinedOverFF) // TODO(ilyas): When the SET opcodes applies relational constraints, this will fail // we will need to look at a new way of doing this test. for (size_t i = 1; i < 4; i++) { - trace.at(i).avm_mem_tag = FF(6); - trace.at(i).avm_mem_r_in_tag = FF(6); - trace.at(i).avm_mem_w_in_tag = FF(6); - trace.at(i).avm_alu_ff_tag = FF::one(); - trace.at(i).avm_alu_u8_tag = FF::zero(); - trace.at(i).avm_main_r_in_tag = FF(6); - trace.at(i).avm_main_w_in_tag = FF(6); - trace.at(i).avm_alu_in_tag = FF(6); + trace.at(i).mem_tag = FF(6); + trace.at(i).mem_r_in_tag = FF(6); + trace.at(i).mem_w_in_tag = FF(6); + trace.at(i).alu_ff_tag = FF::one(); + trace.at(i).alu_u8_tag = FF::zero(); + trace.at(i).main_r_in_tag = FF(6); + trace.at(i).main_w_in_tag = FF(6); + trace.at(i).alu_in_tag = FF(6); } EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "ALU_FF_NOT_XOR"); diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_cast.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_cast.test.cpp index 2c9acd96642..040a1937688 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_cast.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_cast.test.cpp @@ -4,7 +4,10 @@ #include #include +#define ALU_ROW_FIELD_EQ(field_name, expression) Field(#field_name, &Row::alu_##field_name, expression) + namespace tests_avm { + using namespace bb; using namespace bb::avm_trace; using namespace testing; @@ -14,9 +17,9 @@ class AvmCastTests : public ::testing::Test { VmPublicInputs public_inputs{}; AvmTraceBuilder trace_builder; std::vector trace; - size_t main_idx; - size_t alu_idx; - size_t mem_idx_c; + size_t main_addr; + size_t alu_addr; + size_t mem_addr_c; // TODO(640): The Standard Honk on Grumpkin test suite fails unless the SRS is initialised for every test. void SetUp() override @@ -41,23 +44,22 @@ class AvmCastTests : public ::testing::Test { void gen_indices() { - auto row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_cast == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_cast == FF(1); }); ASSERT_TRUE(row != trace.end()); - main_idx = static_cast(row - trace.begin()); + main_addr = static_cast(row - trace.begin()); // Find the corresponding Alu trace row - auto clk = row->avm_main_clk; - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_clk == clk; }); + auto clk = row->main_clk; + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.alu_clk == clk; }); ASSERT_TRUE(alu_row != trace.end()); - alu_idx = static_cast(alu_row - trace.begin()); + alu_addr = static_cast(alu_row - trace.begin()); // Mem entry output ic write operation auto mem_row_c = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_STORE_C; + return r.mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_STORE_C; }); ASSERT_TRUE(mem_row_c != trace.end()); - mem_idx_c = static_cast(mem_row_c - trace.begin()); + mem_addr_c = static_cast(mem_row_c - trace.begin()); } void validate_cast_trace(FF const& a, @@ -70,55 +72,53 @@ class AvmCastTests : public ::testing::Test { ) { - auto const& row = trace.at(main_idx); + auto const& row = trace.at(main_addr); EXPECT_THAT(row, - AllOf(Field("sel_op_cast", &Row::avm_main_sel_op_cast, 1), - Field("ia", &Row::avm_main_ia, a), - Field("ib", &Row::avm_main_ib, 0), - Field("ic", &Row::avm_main_ic, cast_val), - Field("r_in_tag", &Row::avm_main_r_in_tag, static_cast(src_tag)), - Field("w_in_tag", &Row::avm_main_w_in_tag, static_cast(dst_tag)), - Field("alu_in_tag", &Row::avm_main_alu_in_tag, static_cast(dst_tag)), - Field("op_a", &Row::avm_main_mem_op_a, 1), - Field("op_c", &Row::avm_main_mem_op_c, 1), - Field("rwa", &Row::avm_main_rwa, 0), - Field("rwc", &Row::avm_main_rwc, 1), - Field("mem_idx_a", &Row::avm_main_mem_idx_a, src_address), - Field("mem_idx_c", &Row::avm_main_mem_idx_c, dst_address), - Field("tag_err", &Row::avm_main_tag_err, 0), - Field("alu_sel", &Row::avm_main_alu_sel, 1), - Field("sel_rng_8", &Row::avm_main_sel_rng_8, 1), - Field("sel_rng_16", &Row::avm_main_sel_rng_16, 1))); - - auto const& alu_row = trace.at(alu_idx); + AllOf(MAIN_ROW_FIELD_EQ(sel_op_cast, 1), + MAIN_ROW_FIELD_EQ(ia, a), + MAIN_ROW_FIELD_EQ(ib, 0), + MAIN_ROW_FIELD_EQ(ic, cast_val), + MAIN_ROW_FIELD_EQ(r_in_tag, static_cast(src_tag)), + MAIN_ROW_FIELD_EQ(w_in_tag, static_cast(dst_tag)), + MAIN_ROW_FIELD_EQ(alu_in_tag, static_cast(dst_tag)), + MAIN_ROW_FIELD_EQ(sel_mem_op_a, 1), + MAIN_ROW_FIELD_EQ(sel_mem_op_c, 1), + MAIN_ROW_FIELD_EQ(rwa, 0), + MAIN_ROW_FIELD_EQ(rwc, 1), + MAIN_ROW_FIELD_EQ(mem_addr_a, src_address), + MAIN_ROW_FIELD_EQ(mem_addr_c, dst_address), + MAIN_ROW_FIELD_EQ(tag_err, 0), + MAIN_ROW_FIELD_EQ(sel_alu, 1), + MAIN_ROW_FIELD_EQ(sel_rng_8, 1), + MAIN_ROW_FIELD_EQ(sel_rng_16, 1))); + + auto const& alu_row = trace.at(alu_addr); EXPECT_THAT(alu_row, - AllOf(Field("op_cast", &Row::avm_alu_op_cast, 1), - Field("alu_ia", &Row::avm_alu_ia, a), - Field("alu_ib", &Row::avm_alu_ib, 0), - Field("alu_ic", &Row::avm_alu_ic, cast_val), - Field("u8_tag", &Row::avm_alu_u8_tag, dst_tag == AvmMemoryTag::U8), - Field("u16_tag", &Row::avm_alu_u16_tag, dst_tag == AvmMemoryTag::U16), - Field("u32_tag", &Row::avm_alu_u32_tag, dst_tag == AvmMemoryTag::U32), - Field("u64_tag", &Row::avm_alu_u64_tag, dst_tag == AvmMemoryTag::U64), - Field("u128_tag", &Row::avm_alu_u128_tag, dst_tag == AvmMemoryTag::U128), - Field("ff_tag", &Row::avm_alu_ff_tag, dst_tag == AvmMemoryTag::FF), - Field("in_tag", &Row::avm_alu_in_tag, static_cast(dst_tag)), - Field("op_cast_prev", &Row::avm_alu_op_cast_prev, 0), - Field("lookup_selector", &Row::avm_alu_rng_chk_lookup_selector, 1), - Field("alu_sel", &Row::avm_alu_alu_sel, 1))); + AllOf(ALU_ROW_FIELD_EQ(op_cast, 1), + ALU_ROW_FIELD_EQ(ia, a), + ALU_ROW_FIELD_EQ(ib, 0), + ALU_ROW_FIELD_EQ(ic, cast_val), + ALU_ROW_FIELD_EQ(u8_tag, dst_tag == AvmMemoryTag::U8), + ALU_ROW_FIELD_EQ(u16_tag, dst_tag == AvmMemoryTag::U16), + ALU_ROW_FIELD_EQ(u32_tag, dst_tag == AvmMemoryTag::U32), + ALU_ROW_FIELD_EQ(u64_tag, dst_tag == AvmMemoryTag::U64), + ALU_ROW_FIELD_EQ(u128_tag, dst_tag == AvmMemoryTag::U128), + ALU_ROW_FIELD_EQ(ff_tag, dst_tag == AvmMemoryTag::FF), + ALU_ROW_FIELD_EQ(in_tag, static_cast(dst_tag)), + ALU_ROW_FIELD_EQ(op_cast_prev, 0), + ALU_ROW_FIELD_EQ(sel_rng_chk_lookup, 1), + ALU_ROW_FIELD_EQ(sel_alu, 1))); // Check that there is a second ALU row - auto alu_row_next = trace.at(alu_idx + 1); - EXPECT_THAT( - alu_row_next, - AllOf(Field("op_cast", &Row::avm_alu_op_cast, 0), Field("op_cast_prev", &Row::avm_alu_op_cast_prev, 1))); + auto alu_row_next = trace.at(alu_addr + 1); + EXPECT_THAT(alu_row_next, AllOf(ALU_ROW_FIELD_EQ(op_cast, 0), ALU_ROW_FIELD_EQ(op_cast_prev, 1))); // We still want the ability to enable proving through the environment variable and therefore we do not pass // the boolean variable force_proof to validate_trace second argument. if (force_proof) { validate_trace(std::move(trace), public_inputs, true); } else { - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } } }; @@ -229,38 +229,38 @@ TEST_F(AvmCastTests, indirectAddrWrongResolutionU64ToU8) trace_builder.return_op(0, 0, 0); trace = trace_builder.finalize(); - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_cast == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_cast == FF(1); }); ASSERT_TRUE(row != trace.end()); EXPECT_THAT(*row, - AllOf(Field("sel_op_cast", &Row::avm_main_sel_op_cast, 1), - Field("r_in_tag", &Row::avm_main_r_in_tag, static_cast(AvmMemoryTag::U64)), - Field("w_in_tag", &Row::avm_main_w_in_tag, static_cast(AvmMemoryTag::U8)), - Field("alu_in_tag", &Row::avm_main_alu_in_tag, static_cast(AvmMemoryTag::U8)), - Field("op_a", &Row::avm_main_mem_op_a, 1), - Field("op_c", &Row::avm_main_mem_op_c, 1), - Field("ind_op_a", &Row::avm_main_ind_op_a, 1), - Field("ind_op_c", &Row::avm_main_ind_op_c, 1), - Field("ind_a", &Row::avm_main_ind_a, 5), - Field("ind_c", &Row::avm_main_ind_c, 6), - Field("rwa", &Row::avm_main_rwa, 0), - Field("rwc", &Row::avm_main_rwc, 1), - Field("alu_sel", &Row::avm_main_alu_sel, 0), // ALU trace not activated - Field("tag_err", &Row::avm_main_tag_err, 1))); // Error activated - - validate_trace(std::move(trace)); + AllOf(MAIN_ROW_FIELD_EQ(sel_op_cast, 1), + MAIN_ROW_FIELD_EQ(r_in_tag, static_cast(AvmMemoryTag::U64)), + MAIN_ROW_FIELD_EQ(w_in_tag, static_cast(AvmMemoryTag::U8)), + MAIN_ROW_FIELD_EQ(alu_in_tag, static_cast(AvmMemoryTag::U8)), + MAIN_ROW_FIELD_EQ(sel_mem_op_a, 1), + MAIN_ROW_FIELD_EQ(sel_mem_op_c, 1), + MAIN_ROW_FIELD_EQ(sel_resolve_ind_addr_a, 1), + MAIN_ROW_FIELD_EQ(sel_resolve_ind_addr_c, 1), + MAIN_ROW_FIELD_EQ(ind_addr_a, 5), + MAIN_ROW_FIELD_EQ(ind_addr_c, 6), + MAIN_ROW_FIELD_EQ(rwa, 0), + MAIN_ROW_FIELD_EQ(rwc, 1), + MAIN_ROW_FIELD_EQ(sel_alu, 0), // ALU trace not activated + MAIN_ROW_FIELD_EQ(tag_err, 1))); // Error activated + + validate_trace(std::move(trace), public_inputs); } TEST_F(AvmCastNegativeTests, nonTruncatedOutputMainIc) { gen_trace(300, 0, 1, AvmMemoryTag::U16, AvmMemoryTag::U8); - ASSERT_EQ(trace.at(main_idx).avm_main_ic, 44); + ASSERT_EQ(trace.at(main_addr).main_ic, 44); // Replace the output in main trace with the non-truncated value - trace.at(main_idx).avm_main_ic = 300; + trace.at(main_addr).main_ic = 300; // Adapt the memory trace entry - trace.at(mem_idx_c).avm_mem_val = 300; + trace.at(mem_addr_c).mem_val = 300; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_ALU"); } @@ -268,13 +268,13 @@ TEST_F(AvmCastNegativeTests, nonTruncatedOutputMainIc) TEST_F(AvmCastNegativeTests, wrongOutputMainIc) { gen_trace(151515, 0, 1, AvmMemoryTag::U32, AvmMemoryTag::FF); - ASSERT_EQ(trace.at(main_idx).avm_main_ic, 151515); + ASSERT_EQ(trace.at(main_addr).main_ic, 151515); // Replace the output in main trace with a wrong value - trace.at(main_idx).avm_main_ic = 151516; + trace.at(main_addr).main_ic = 151516; // Adapt the memory trace entry - trace.at(mem_idx_c).avm_mem_val = 151516; + trace.at(mem_addr_c).mem_val = 151516; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_ALU"); } @@ -282,12 +282,12 @@ TEST_F(AvmCastNegativeTests, wrongOutputMainIc) TEST_F(AvmCastNegativeTests, wrongOutputAluIc) { gen_trace(6582736, 0, 1, AvmMemoryTag::U128, AvmMemoryTag::U16); - ASSERT_EQ(trace.at(alu_idx).avm_alu_ic, 29136); + ASSERT_EQ(trace.at(alu_addr).alu_ic, 29136); // Replace output in ALU, MAIN, and MEM trace - trace.at(alu_idx).avm_alu_ic = 33; - trace.at(main_idx).avm_main_ic = 33; - trace.at(mem_idx_c).avm_mem_val = 33; + trace.at(alu_addr).alu_ic = 33; + trace.at(main_addr).main_ic = 33; + trace.at(mem_addr_c).mem_val = 33; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "ALU_OP_CAST"); } @@ -300,7 +300,7 @@ TEST_F(AvmCastNegativeTests, wrongLimbDecompositionInput) trace = trace_builder.finalize(); gen_indices(); - trace.at(alu_idx).avm_alu_a_lo -= 23; + trace.at(alu_addr).alu_a_lo -= 23; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "INPUT_DECOMP_1"); } @@ -308,9 +308,9 @@ TEST_F(AvmCastNegativeTests, wrongLimbDecompositionInput) TEST_F(AvmCastNegativeTests, wrongPSubALo) { gen_trace(12345, 0, 1, AvmMemoryTag::U32, AvmMemoryTag::U16); - ASSERT_EQ(trace.at(alu_idx).avm_alu_ic, 12345); + ASSERT_EQ(trace.at(alu_addr).alu_ic, 12345); - trace.at(alu_idx).avm_alu_p_sub_a_lo += 3; + trace.at(alu_addr).alu_p_sub_a_lo += 3; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "SUB_LO_1"); } @@ -323,7 +323,7 @@ TEST_F(AvmCastNegativeTests, wrongPSubAHi) trace = trace_builder.finalize(); gen_indices(); - trace.at(alu_idx).avm_alu_p_sub_a_hi += 3; + trace.at(alu_addr).alu_p_sub_a_hi += 3; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "SUB_HI_1"); } @@ -332,7 +332,7 @@ TEST_F(AvmCastNegativeTests, disableRangecheck) { gen_trace(123, 23, 43, AvmMemoryTag::U8, AvmMemoryTag::U8); - trace.at(alu_idx).avm_alu_rng_chk_lookup_selector = 0; + trace.at(alu_addr).alu_sel_rng_chk_lookup = 0; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "RNG_CHK_LOOKUP_SELECTOR"); } @@ -340,16 +340,16 @@ TEST_F(AvmCastNegativeTests, disableRangecheckSub) { gen_trace(123, 23, 43, AvmMemoryTag::U8, AvmMemoryTag::U8); - trace.at(alu_idx + 1).avm_alu_rng_chk_lookup_selector = 0; + trace.at(alu_addr + 1).alu_sel_rng_chk_lookup = 0; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "RNG_CHK_LOOKUP_SELECTOR"); } TEST_F(AvmCastNegativeTests, wrongRangeCheckDecompositionLo) { gen_trace(987344323, 23, 43, AvmMemoryTag::FF, AvmMemoryTag::U128); - ASSERT_EQ(trace.at(alu_idx).avm_alu_ic, 987344323); + ASSERT_EQ(trace.at(alu_addr).alu_ic, 987344323); - trace.at(alu_idx).avm_alu_u16_r0 = 5555; + trace.at(alu_addr).alu_u16_r0 = 5555; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "LOWER_CMP_RNG_CHK"); } @@ -361,17 +361,17 @@ TEST_F(AvmCastNegativeTests, wrongRangeCheckDecompositionHi) trace = trace_builder.finalize(); gen_indices(); - trace.at(alu_idx).avm_alu_u16_r9 = 5555; + trace.at(alu_addr).alu_u16_r9 = 5555; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "UPPER_CMP_RNG_CHK"); } TEST_F(AvmCastNegativeTests, outOfRangeU8Registers) { gen_trace(987344323, 23, 43, AvmMemoryTag::FF, AvmMemoryTag::U128); - ASSERT_EQ(trace.at(alu_idx).avm_alu_ic, 987344323); + ASSERT_EQ(trace.at(alu_addr).alu_ic, 987344323); - trace.at(alu_idx).avm_alu_u8_r0 += 256; - trace.at(alu_idx).avm_alu_u8_r1 -= 1; // Adjust so that the decomposition is correct. + trace.at(alu_addr).alu_u8_r0 += 256; + trace.at(alu_addr).alu_u8_r1 -= 1; // Adjust so that the decomposition is correct. EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "Lookup LOOKUP_U8_0"); } @@ -379,10 +379,10 @@ TEST_F(AvmCastNegativeTests, outOfRangeU8Registers) TEST_F(AvmCastNegativeTests, outOfRangeU16Registers) { gen_trace(987344323, 23, 43, AvmMemoryTag::FF, AvmMemoryTag::U128); - ASSERT_EQ(trace.at(alu_idx).avm_alu_ic, 987344323); + ASSERT_EQ(trace.at(alu_addr).alu_ic, 987344323); - trace.at(alu_idx).avm_alu_u16_r0 += 65536; - trace.at(alu_idx).avm_alu_u16_r1 -= 1; // Adjust so that the decomposition is correct. + trace.at(alu_addr).alu_u16_r0 += 65536; + trace.at(alu_addr).alu_u16_r1 -= 1; // Adjust so that the decomposition is correct. EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "Lookup LOOKUP_U16_0"); } @@ -390,10 +390,10 @@ TEST_F(AvmCastNegativeTests, outOfRangeU16Registers) TEST_F(AvmCastNegativeTests, wrongCopySubLoForRangeCheck) { gen_trace(987344323, 23, 43, AvmMemoryTag::U64, AvmMemoryTag::U128); - ASSERT_EQ(trace.at(alu_idx).avm_alu_ic, 987344323); + ASSERT_EQ(trace.at(alu_addr).alu_ic, 987344323); - ASSERT_EQ(trace.at(alu_idx + 1).avm_alu_a_lo, trace.at(alu_idx).avm_alu_p_sub_a_lo); - trace.at(alu_idx + 1).avm_alu_a_lo -= 1; + ASSERT_EQ(trace.at(alu_addr + 1).alu_a_lo, trace.at(alu_addr).alu_p_sub_a_lo); + trace.at(alu_addr + 1).alu_a_lo -= 1; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "OP_CAST_RNG_CHECK_P_SUB_A_LOW"); } @@ -405,33 +405,33 @@ TEST_F(AvmCastNegativeTests, wrongCopySubHiForRangeCheck) trace = trace_builder.finalize(); gen_indices(); - ASSERT_EQ(trace.at(alu_idx + 1).avm_alu_a_hi, trace.at(alu_idx).avm_alu_p_sub_a_hi); - trace.at(alu_idx + 1).avm_alu_a_hi += 2; + ASSERT_EQ(trace.at(alu_addr + 1).alu_a_hi, trace.at(alu_addr).alu_p_sub_a_hi); + trace.at(alu_addr + 1).alu_a_hi += 2; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "OP_CAST_RNG_CHECK_P_SUB_A_HIGH"); } TEST_F(AvmCastNegativeTests, secondRowNoOp) { gen_trace(6583, 0, 1, AvmMemoryTag::U64, AvmMemoryTag::U8); - ASSERT_EQ(trace.at(alu_idx).avm_alu_ic, 183); + ASSERT_EQ(trace.at(alu_addr).alu_ic, 183); // We have to enable alu_sel otherwise another relation will fail. - trace.at(alu_idx + 1).avm_alu_alu_sel = 1; + trace.at(alu_addr + 1).alu_sel_alu = 1; // Add an LT selector in the next row (second part of the cast operation) auto trace_lt = trace; - trace_lt.at(alu_idx + 1).avm_alu_op_lt = 1; + trace_lt.at(alu_addr + 1).alu_op_lt = 1; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace_lt)), "TWO_LINE_OP_NO_OVERLAP"); // Try with EQ selector auto trace_eq = trace; - trace_eq.at(alu_idx + 1).avm_alu_op_eq = 1; + trace_eq.at(alu_addr + 1).alu_op_eq = 1; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace_eq)), "TWO_LINE_OP_NO_OVERLAP"); // Try with a second cast selector - trace.at(alu_idx + 1).avm_alu_op_cast = 1; + trace.at(alu_addr + 1).alu_op_cast = 1; // Adjust to not violate #[RNG_CHK_LOOKUP_SELECTOR] - trace.at(alu_idx + 1).avm_alu_rng_chk_lookup_selector = 2; + trace.at(alu_addr + 1).alu_sel_rng_chk_lookup = 2; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "TWO_LINE_OP_NO_OVERLAP"); } diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_comparison.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_comparison.test.cpp index fce886c26f0..38b028306f7 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_comparison.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_comparison.test.cpp @@ -14,6 +14,7 @@ #include namespace tests_avm { + using namespace bb; using namespace bb::avm_trace; namespace { @@ -31,31 +32,31 @@ void common_validate_cmp(Row const& row, // Use the row in the main trace to find the same operation in the alu trace. // Check that the correct result is stored at the expected memory location. - EXPECT_EQ(row.avm_main_ic, c); - EXPECT_EQ(row.avm_main_mem_idx_c, addr_c); - EXPECT_EQ(row.avm_main_mem_op_c, FF(1)); - EXPECT_EQ(row.avm_main_rwc, FF(1)); + EXPECT_EQ(row.main_ic, c); + EXPECT_EQ(row.main_mem_addr_c, addr_c); + EXPECT_EQ(row.main_sel_mem_op_c, FF(1)); + EXPECT_EQ(row.main_rwc, FF(1)); // Check that ia register is correctly set with memory load operations. - EXPECT_EQ(row.avm_main_ia, a); - EXPECT_EQ(row.avm_main_mem_idx_a, addr_a); - EXPECT_EQ(row.avm_main_mem_op_a, FF(1)); - EXPECT_EQ(row.avm_main_rwa, FF(0)); + EXPECT_EQ(row.main_ia, a); + EXPECT_EQ(row.main_mem_addr_a, addr_a); + EXPECT_EQ(row.main_sel_mem_op_a, FF(1)); + EXPECT_EQ(row.main_rwa, FF(0)); // Check that ib register is correctly set with memory load operations. - EXPECT_EQ(row.avm_main_ib, b); - EXPECT_EQ(row.avm_main_mem_idx_b, addr_b); - EXPECT_EQ(row.avm_main_mem_op_b, FF(1)); - EXPECT_EQ(row.avm_main_rwb, FF(0)); + EXPECT_EQ(row.main_ib, b); + EXPECT_EQ(row.main_mem_addr_b, addr_b); + EXPECT_EQ(row.main_sel_mem_op_b, FF(1)); + EXPECT_EQ(row.main_rwb, FF(0)); // Check the instruction tags - EXPECT_EQ(row.avm_main_r_in_tag, FF(static_cast(tag))); - EXPECT_EQ(row.avm_main_w_in_tag, FF(static_cast(AvmMemoryTag::U8))); + EXPECT_EQ(row.main_r_in_tag, FF(static_cast(tag))); + EXPECT_EQ(row.main_w_in_tag, FF(static_cast(AvmMemoryTag::U8))); // Check that intermediate registers are correctly copied in Alu trace - EXPECT_EQ(alu_row.avm_alu_ia, a); - EXPECT_EQ(alu_row.avm_alu_ib, b); - EXPECT_EQ(alu_row.avm_alu_ic, c); + EXPECT_EQ(alu_row.alu_ia, a); + EXPECT_EQ(alu_row.alu_ib, b); + EXPECT_EQ(alu_row.alu_ic, c); } } // namespace std::vector positive_op_lt_test_values = { { { FF(1), FF(1), FF(0) }, @@ -119,18 +120,18 @@ TEST_P(AvmCmpTestsLT, ParamTest) auto trace = trace_builder.finalize(); // Get the row in the avm with the LT selector set - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_lt == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_lt == FF(1); }); // Use the row in the main trace to find the same operation in the alu trace. - FF clk = row->avm_main_clk; + FF clk = row->main_clk; auto alu_row = std::ranges::find_if( - trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_clk == clk && r.avm_alu_op_lt == FF(1); }); + trace.begin(), trace.end(), [clk](Row r) { return r.alu_clk == clk && r.alu_op_lt == FF(1); }); // Check that both rows were found ASSERT_TRUE(row != trace.end()); ASSERT_TRUE(alu_row != trace.end()); common_validate_cmp(*row, *alu_row, a, b, c, FF(0), FF(1), FF(2), mem_tag); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } INSTANTIATE_TEST_SUITE_P(AvmCmpTests, AvmCmpTestsLT, @@ -149,17 +150,17 @@ TEST_P(AvmCmpTestsLTE, ParamTest) trace_builder.op_lte(0, 0, 1, 2, mem_tag); trace_builder.return_op(0, 0, 0); auto trace = trace_builder.finalize(); - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_lte == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_lte == FF(1); }); // Use the row in the main trace to find the same operation in the alu trace. - FF clk = row->avm_main_clk; - auto alu_row = std::ranges::find_if( - trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_clk == clk && r.avm_alu_op_lte; }); + FF clk = row->main_clk; + auto alu_row = + std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.alu_clk == clk && r.alu_op_lte; }); // Check that both rows were found ASSERT_TRUE(row != trace.end()); ASSERT_TRUE(alu_row != trace.end()); common_validate_cmp(*row, *alu_row, a, b, c, FF(0), FF(1), FF(2), mem_tag); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } INSTANTIATE_TEST_SUITE_P(AvmCmpTests, AvmCmpTestsLTE, @@ -200,36 +201,36 @@ std::vector gen_mutated_trace_cmp( std::vector trace, std::function select_row, FF c_mutated, CMP_FAILURES fail_mode, bool is_lte) { auto main_trace_row = std::ranges::find_if(trace.begin(), trace.end(), select_row); - auto main_clk = main_trace_row->avm_main_clk; + auto main_clk = main_trace_row->main_clk; // The corresponding row in the alu trace as well as the row where start = 1 auto alu_row = - std::ranges::find_if(trace.begin(), trace.end(), [main_clk](Row r) { return r.avm_alu_clk == main_clk; }); + std::ranges::find_if(trace.begin(), trace.end(), [main_clk](Row r) { return r.alu_clk == main_clk; }); // The corresponding row in the alu trace where the computation ends. auto range_check_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_alu_cmp_rng_ctr > FF(0); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.alu_cmp_rng_ctr > FF(0); }); switch (fail_mode) { case IncorrectInputDecomposition: - alu_row->avm_alu_a_lo = alu_row->avm_alu_a_lo + FF(1); + alu_row->alu_a_lo = alu_row->alu_a_lo + FF(1); break; case SubLoCheckFailed: - alu_row->avm_alu_p_a_borrow = FF::one() - alu_row->avm_alu_p_a_borrow; + alu_row->alu_p_a_borrow = FF::one() - alu_row->alu_p_a_borrow; break; case ResLoCheckFailed: - alu_row->avm_alu_res_lo = alu_row->avm_alu_res_lo - FF(1); + alu_row->alu_res_lo = alu_row->alu_res_lo - FF(1); break; case ResHiCheckFailed: - alu_row->avm_alu_res_hi = FF(1); + alu_row->alu_res_hi = FF(1); break; case CounterRelationFailed: - range_check_row->avm_alu_cmp_rng_ctr = FF(0); + range_check_row->alu_cmp_rng_ctr = FF(0); break; case CounterNonZeroCheckFailed: - range_check_row->avm_alu_rng_chk_sel = FF(0); - range_check_row->avm_alu_rng_chk_lookup_selector = FF(0); + range_check_row->alu_sel_rng_chk = FF(0); + range_check_row->alu_sel_rng_chk_lookup = FF(0); break; case ShiftRelationFailed: - range_check_row->avm_alu_a_lo = range_check_row->avm_alu_res_lo; - range_check_row->avm_alu_a_hi = range_check_row->avm_alu_res_hi; + range_check_row->alu_a_lo = range_check_row->alu_res_lo; + range_check_row->alu_a_hi = range_check_row->alu_res_hi; break; case RangeCheckFailed: // Canonicalisation check failure // TODO: We can probably refactor this to another function later as it is a bit verbose @@ -241,62 +242,61 @@ std::vector gen_mutated_trace_cmp( mutate_ic_in_trace(trace, std::move(select_row), c_mutated, true); // Now we have to also update the value of res_lo = (A_SUB_B_LO * IS_GT + B_SUB_A_LO * (1 - IS_GT)) - alu_row->avm_alu_borrow = FF(0); - FF mutated_res_lo = - alu_row->avm_alu_b_lo - alu_row->avm_alu_a_lo + alu_row->avm_alu_borrow * (uint256_t(1) << 128); - FF mutated_res_hi = alu_row->avm_alu_b_hi - alu_row->avm_alu_a_hi - alu_row->avm_alu_borrow; + alu_row->alu_borrow = FF(0); + FF mutated_res_lo = alu_row->alu_b_lo - alu_row->alu_a_lo + alu_row->alu_borrow * (uint256_t(1) << 128); + FF mutated_res_hi = alu_row->alu_b_hi - alu_row->alu_a_hi - alu_row->alu_borrow; if (is_lte) { - mutated_res_lo = alu_row->avm_alu_a_lo - alu_row->avm_alu_b_lo - FF::one() + - alu_row->avm_alu_borrow * (uint256_t(1) << 128); - mutated_res_hi = alu_row->avm_alu_a_hi - alu_row->avm_alu_b_hi - alu_row->avm_alu_borrow; + mutated_res_lo = + alu_row->alu_a_lo - alu_row->alu_b_lo - FF::one() + alu_row->alu_borrow * (uint256_t(1) << 128); + mutated_res_hi = alu_row->alu_a_hi - alu_row->alu_b_hi - alu_row->alu_borrow; } - alu_row->avm_alu_res_lo = mutated_res_lo; - alu_row->avm_alu_res_hi = mutated_res_hi; + alu_row->alu_res_lo = mutated_res_lo; + alu_row->alu_res_hi = mutated_res_hi; // For each subsequent row that involve the range check, we need to update the shifted values auto next_row = alu_row + 1; - next_row->avm_alu_p_sub_b_lo = mutated_res_lo; - next_row->avm_alu_p_sub_b_hi = mutated_res_hi; + next_row->alu_p_sub_b_lo = mutated_res_lo; + next_row->alu_p_sub_b_hi = mutated_res_hi; next_row = alu_row + 2; - next_row->avm_alu_p_sub_a_lo = mutated_res_lo; - next_row->avm_alu_p_sub_a_hi = mutated_res_hi; + next_row->alu_p_sub_a_lo = mutated_res_lo; + next_row->alu_p_sub_a_hi = mutated_res_hi; next_row = alu_row + 3; - next_row->avm_alu_b_lo = mutated_res_lo; - next_row->avm_alu_b_hi = mutated_res_hi; + next_row->alu_b_lo = mutated_res_lo; + next_row->alu_b_hi = mutated_res_hi; // The final row contains the mutated res_x values at the a_x slots that will be range check. auto final_row = alu_row + 4; // To prevent a trivial range check failure, we need to clear the lookup counters for the // current value of res_lo stored in a_lo - clear_range_check_counters(trace, final_row->avm_alu_a_lo); - final_row->avm_alu_a_lo = mutated_res_lo; - final_row->avm_alu_a_hi = mutated_res_hi; + clear_range_check_counters(trace, final_row->alu_a_lo); + final_row->alu_a_lo = mutated_res_lo; + final_row->alu_a_hi = mutated_res_hi; uint256_t mutated_res_lo_u256 = mutated_res_lo; // We update range check lookup counters and the registers here // Assign the new u8 value that goes into the first slice register. - final_row->avm_alu_u8_r0 = static_cast(mutated_res_lo_u256); + final_row->alu_u8_r0 = static_cast(mutated_res_lo_u256); // Find the main row where the new u8 value in the first register WILL be looked up auto new_lookup_row = std::ranges::find_if(trace.begin(), trace.end(), [final_row](Row r) { - return r.avm_main_clk == final_row->avm_alu_u8_r0 && r.avm_main_sel_rng_8 == FF(1); + return r.main_clk == final_row->alu_u8_r0 && r.main_sel_rng_8 == FF(1); }); // Increment the counter new_lookup_row->lookup_u8_0_counts = new_lookup_row->lookup_u8_0_counts + 1; mutated_res_lo_u256 >>= 8; // Assign the new u8 value that goes into the second slice register. - final_row->avm_alu_u8_r1 = static_cast(mutated_res_lo_u256); + final_row->alu_u8_r1 = static_cast(mutated_res_lo_u256); new_lookup_row = std::ranges::find_if(trace.begin(), trace.end(), [final_row](Row r) { - return r.avm_main_clk == final_row->avm_alu_u8_r1 && r.avm_main_sel_rng_8 == FF(1); + return r.main_clk == final_row->alu_u8_r1 && r.main_sel_rng_8 == FF(1); }); new_lookup_row->lookup_u8_1_counts = new_lookup_row->lookup_u8_1_counts + 1; mutated_res_lo_u256 >>= 8; // Set the remaining bits (that are > 16) to the first u16 register to trigger the overflow - final_row->avm_alu_u16_r0 = mutated_res_lo_u256; + final_row->alu_u16_r0 = mutated_res_lo_u256; break; } @@ -316,7 +316,7 @@ TEST_P(AvmCmpNegativeTestsLT, ParamTest) trace_builder.op_lt(0, 0, 1, 2, AvmMemoryTag::FF); trace_builder.return_op(0, 0, 0); auto trace = trace_builder.finalize(); - std::function select_row = [](Row r) { return r.avm_main_sel_op_lt == FF(1); }; + std::function select_row = [](Row r) { return r.main_sel_op_lt == FF(1); }; trace = gen_mutated_trace_cmp(trace, select_row, output, failure_mode, false); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), failure_string); } @@ -334,7 +334,7 @@ TEST_P(AvmCmpNegativeTestsLTE, ParamTest) trace_builder.op_lte(0, 0, 1, 2, AvmMemoryTag::FF); trace_builder.return_op(0, 0, 0); auto trace = trace_builder.finalize(); - std::function select_row = [](Row r) { return r.avm_main_sel_op_lte == FF(1); }; + std::function select_row = [](Row r) { return r.main_sel_op_lte == FF(1); }; trace = gen_mutated_trace_cmp(trace, select_row, output, failure_mode, true); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), failure_string); } diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp index e95d198e280..eb2b13781d1 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_control_flow.test.cpp @@ -1,6 +1,7 @@ #include "avm_common.test.hpp" namespace tests_avm { + using namespace bb; using namespace bb::avm_trace; @@ -8,29 +9,29 @@ namespace { void validate_internal_call(Row const& row, uint32_t current_pc, uint32_t target_pc, uint32_t stack_ptr) { - EXPECT_EQ(row.avm_main_sel_internal_call, FF(1)); - EXPECT_EQ(row.avm_main_pc, FF(current_pc)); - EXPECT_EQ(row.avm_main_ia, FF(target_pc)); - EXPECT_EQ(row.avm_main_internal_return_ptr, FF(stack_ptr)); - EXPECT_EQ(row.avm_main_mem_op_b, FF(1)); - EXPECT_EQ(row.avm_main_rwb, FF(1)); - EXPECT_EQ(row.avm_main_ib, FF(current_pc + 1)); - EXPECT_EQ(row.avm_main_mem_idx_b, FF(stack_ptr)); - EXPECT_EQ(row.avm_main_w_in_tag, FF(static_cast(AvmMemoryTag::U32))); - EXPECT_EQ(row.avm_main_space_id, FF(INTERNAL_CALL_SPACE_ID)); + EXPECT_EQ(row.main_sel_op_internal_call, FF(1)); + EXPECT_EQ(row.main_pc, FF(current_pc)); + EXPECT_EQ(row.main_ia, FF(target_pc)); + EXPECT_EQ(row.main_internal_return_ptr, FF(stack_ptr)); + EXPECT_EQ(row.main_sel_mem_op_b, FF(1)); + EXPECT_EQ(row.main_rwb, FF(1)); + EXPECT_EQ(row.main_ib, FF(current_pc + 1)); + EXPECT_EQ(row.main_mem_addr_b, FF(stack_ptr)); + EXPECT_EQ(row.main_w_in_tag, FF(static_cast(AvmMemoryTag::U32))); + EXPECT_EQ(row.main_space_id, FF(INTERNAL_CALL_SPACE_ID)); }; void validate_internal_return(Row const& row, uint32_t current_pc, uint32_t return_pc, uint32_t stack_ptr) { - EXPECT_EQ(row.avm_main_sel_internal_return, FF(1)); - EXPECT_EQ(row.avm_main_pc, FF(current_pc)); - EXPECT_EQ(row.avm_main_ia, FF(return_pc)); - EXPECT_EQ(row.avm_main_internal_return_ptr, FF(stack_ptr)); - EXPECT_EQ(row.avm_main_mem_op_a, FF(1)); - EXPECT_EQ(row.avm_main_rwa, FF(0)); - EXPECT_EQ(row.avm_main_mem_idx_a, FF(stack_ptr - 1)); - EXPECT_EQ(row.avm_main_r_in_tag, FF(static_cast(AvmMemoryTag::U32))); - EXPECT_EQ(row.avm_main_space_id, FF(INTERNAL_CALL_SPACE_ID)); + EXPECT_EQ(row.main_sel_op_internal_return, FF(1)); + EXPECT_EQ(row.main_pc, FF(current_pc)); + EXPECT_EQ(row.main_ia, FF(return_pc)); + EXPECT_EQ(row.main_internal_return_ptr, FF(stack_ptr)); + EXPECT_EQ(row.main_sel_mem_op_a, FF(1)); + EXPECT_EQ(row.main_rwa, FF(0)); + EXPECT_EQ(row.main_mem_addr_a, FF(stack_ptr - 1)); + EXPECT_EQ(row.main_r_in_tag, FF(static_cast(AvmMemoryTag::U32))); + EXPECT_EQ(row.main_space_id, FF(INTERNAL_CALL_SPACE_ID)); }; } // namespace @@ -75,7 +76,7 @@ TEST_F(AvmControlFlowTests, simpleCall) // Check call { auto call_row_iter = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_internal_call == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_internal_call == FF(1); }); EXPECT_TRUE(call_row_iter != trace.end()); auto& call_row = trace.at(static_cast(call_row_iter - trace.begin())); validate_internal_call(call_row, 0, CALL_PC, 0); @@ -84,12 +85,12 @@ TEST_F(AvmControlFlowTests, simpleCall) // Check halt { auto halt_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_halt == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_halt == FF(1); }); // Check that the correct result is stored at the expected memory location. EXPECT_TRUE(halt_row != trace.end()); - EXPECT_EQ(halt_row->avm_main_pc, FF(CALL_PC)); - EXPECT_EQ(halt_row->avm_main_internal_return_ptr, FF(1)); + EXPECT_EQ(halt_row->main_pc, FF(CALL_PC)); + EXPECT_EQ(halt_row->main_internal_return_ptr, FF(1)); } validate_trace(std::move(trace), public_inputs, true); } @@ -110,21 +111,21 @@ TEST_F(AvmControlFlowTests, simpleJump) // Check jump { auto call_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_jump == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_jump == FF(1); }); EXPECT_TRUE(call_row != trace.end()); - EXPECT_EQ(call_row->avm_main_pc, FF(0)); - EXPECT_EQ(call_row->avm_main_ia, FF(JUMP_PC)); + EXPECT_EQ(call_row->main_pc, FF(0)); + EXPECT_EQ(call_row->main_ia, FF(JUMP_PC)); } // Check halt { auto halt_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_halt == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_halt == FF(1); }); EXPECT_TRUE(halt_row != trace.end()); - EXPECT_EQ(halt_row->avm_main_pc, FF(JUMP_PC)); + EXPECT_EQ(halt_row->main_pc, FF(JUMP_PC)); } - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } TEST_F(AvmControlFlowTests, simpleCallAndReturn) @@ -145,7 +146,7 @@ TEST_F(AvmControlFlowTests, simpleCallAndReturn) // Check call { auto call_row_iter = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_internal_call == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_internal_call == FF(1); }); EXPECT_TRUE(call_row_iter != trace.end()); auto& call_row = trace.at(static_cast(call_row_iter - trace.begin())); validate_internal_call(call_row, 0, CALL_PC, 0); @@ -154,7 +155,7 @@ TEST_F(AvmControlFlowTests, simpleCallAndReturn) // Check return { auto return_row_iter = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_internal_return == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_internal_return == FF(1); }); // Check that the correct result is stored at the expected memory location. EXPECT_TRUE(return_row_iter != trace.end()); @@ -165,13 +166,13 @@ TEST_F(AvmControlFlowTests, simpleCallAndReturn) // Check halt { auto halt_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_halt == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_halt == FF(1); }); EXPECT_TRUE(halt_row != trace.end()); - EXPECT_EQ(halt_row->avm_main_pc, FF(RETURN_PC)); + EXPECT_EQ(halt_row->main_pc, FF(RETURN_PC)); } - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } TEST_F(AvmControlFlowTests, multipleCallsAndReturns) @@ -211,7 +212,7 @@ TEST_F(AvmControlFlowTests, multipleCallsAndReturns) // Check call 1 { auto call_1 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avm_main_sel_internal_call == FF(1) && r.avm_main_ib == FF(1); + return r.main_sel_op_internal_call == FF(1) && r.main_ib == FF(1); }); EXPECT_TRUE(call_1 != trace.end()); auto& call_1_row = trace.at(static_cast(call_1 - trace.begin())); @@ -221,7 +222,7 @@ TEST_F(AvmControlFlowTests, multipleCallsAndReturns) // Call 2 { auto call_2 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avm_main_sel_internal_call == FF(1) && r.avm_main_pc == FF(CALL_PC_1); + return r.main_sel_op_internal_call == FF(1) && r.main_pc == FF(CALL_PC_1); }); EXPECT_TRUE(call_2 != trace.end()); auto& call_2_row = trace.at(static_cast(call_2 - trace.begin())); @@ -231,7 +232,7 @@ TEST_F(AvmControlFlowTests, multipleCallsAndReturns) // Call 3 { auto call_3 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avm_main_sel_internal_call == FF(1) && r.avm_main_pc == FF(CALL_PC_2); + return r.main_sel_op_internal_call == FF(1) && r.main_pc == FF(CALL_PC_2); }); EXPECT_TRUE(call_3 != trace.end()); auto& call_3_row = trace.at(static_cast(call_3 - trace.begin())); @@ -241,7 +242,7 @@ TEST_F(AvmControlFlowTests, multipleCallsAndReturns) // Return 1 { auto return_1 = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_internal_return == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_internal_return == FF(1); }); EXPECT_TRUE(return_1 != trace.end()); auto& return_1_row = trace.at(static_cast(return_1 - trace.begin())); validate_internal_return(return_1_row, CALL_PC_3, CALL_PC_2 + 1, 3); @@ -250,7 +251,7 @@ TEST_F(AvmControlFlowTests, multipleCallsAndReturns) // Call 4 { auto call_4 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avm_main_sel_internal_call == FF(1) && r.avm_main_pc == FF(CALL_PC_2 + 1); + return r.main_sel_op_internal_call == FF(1) && r.main_pc == FF(CALL_PC_2 + 1); }); EXPECT_TRUE(call_4 != trace.end()); auto& call_4_row = trace.at(static_cast(call_4 - trace.begin())); @@ -260,7 +261,7 @@ TEST_F(AvmControlFlowTests, multipleCallsAndReturns) // Return 2 { auto return_2 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avm_main_sel_internal_return == FF(1) && r.avm_main_pc == FF(CALL_PC_4); + return r.main_sel_op_internal_return == FF(1) && r.main_pc == FF(CALL_PC_4); }); EXPECT_TRUE(return_2 != trace.end()); auto& return_2_row = trace.at(static_cast(return_2 - trace.begin())); @@ -270,17 +271,17 @@ TEST_F(AvmControlFlowTests, multipleCallsAndReturns) // Jump 1 { auto jump_1 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avm_main_sel_jump == FF(1) && r.avm_main_pc == FF(CALL_PC_2 + 2); + return r.main_sel_op_jump == FF(1) && r.main_pc == FF(CALL_PC_2 + 2); }); EXPECT_TRUE(jump_1 != trace.end()); - EXPECT_EQ(jump_1->avm_main_ia, FF(JUMP_PC_1)); - EXPECT_EQ(jump_1->avm_main_internal_return_ptr, FF(2)); + EXPECT_EQ(jump_1->main_ia, FF(JUMP_PC_1)); + EXPECT_EQ(jump_1->main_internal_return_ptr, FF(2)); } // Return 3 { auto return_3 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avm_main_sel_internal_return == FF(1) && r.avm_main_pc == FF(JUMP_PC_1); + return r.main_sel_op_internal_return == FF(1) && r.main_pc == FF(JUMP_PC_1); }); EXPECT_TRUE(return_3 != trace.end()); auto& return_3_row = trace.at(static_cast(return_3 - trace.begin())); @@ -290,7 +291,7 @@ TEST_F(AvmControlFlowTests, multipleCallsAndReturns) // Return 4 { auto return_4 = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { - return r.avm_main_sel_internal_return == FF(1) && r.avm_main_pc == FF(CALL_PC_1 + 1); + return r.main_sel_op_internal_return == FF(1) && r.main_pc == FF(CALL_PC_1 + 1); }); EXPECT_TRUE(return_4 != trace.end()); auto& return_4_row = trace.at(static_cast(return_4 - trace.begin())); @@ -298,12 +299,12 @@ TEST_F(AvmControlFlowTests, multipleCallsAndReturns) } // Halt row - auto halt_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_halt == FF(1); }); + auto halt_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_halt == FF(1); }); EXPECT_TRUE(halt_row != trace.end()); - EXPECT_EQ(halt_row->avm_main_pc, FF(1)); + EXPECT_EQ(halt_row->main_pc, FF(1)); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } + } // namespace tests_avm \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp index aa0e7be7005..696d0641ba3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_execution.test.cpp @@ -11,9 +11,6 @@ #include #include -// TODO: remove -#include "barretenberg/vm/avm_trace/avm_helper.cpp" - namespace tests_avm { using namespace bb; using namespace bb::avm_trace; @@ -23,7 +20,8 @@ using bb::utils::hex_to_bytes; class AvmExecutionTests : public ::testing::Test { public: - std::vector public_inputs_vec{}; + std::vector public_inputs_vec; + VmPublicInputs public_inputs; AvmExecutionTests() : public_inputs_vec(PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH){}; @@ -35,6 +33,7 @@ class AvmExecutionTests : public ::testing::Test { srs::init_crs_factory("../srs_db/ignition"); public_inputs_vec.at(DA_START_GAS_LEFT_PCPI_OFFSET) = DEFAULT_INITIAL_DA_GAS; public_inputs_vec.at(L2_START_GAS_LEFT_PCPI_OFFSET) = DEFAULT_INITIAL_L2_GAS; + public_inputs = Execution::convert_public_inputs(public_inputs_vec); }; /** @@ -48,6 +47,13 @@ class AvmExecutionTests : public ::testing::Test { std::vector calldata{}; return Execution::gen_trace(instructions, calldata, public_inputs_vec); } + + void feed_output(uint32_t output_offset, FF const& value, FF const& side_effect_counter, FF const& metadata) + { + std::get(public_inputs)[output_offset] = value; + std::get(public_inputs)[output_offset] = side_effect_counter; + std::get(public_inputs)[output_offset] = metadata; + }; }; // Basic positive test with an ADD and RETURN opcode. @@ -88,7 +94,7 @@ TEST_F(AvmExecutionTests, basicAddReturn) ElementsAre(VariantWith(0), VariantWith(0), VariantWith(0))))); auto trace = gen_trace_from_instr(instructions); - validate_trace(std::move(trace), Execution::convert_public_inputs(public_inputs_vec), true); + validate_trace(std::move(trace), public_inputs, true); } // Positive test for SET and SUB opcodes @@ -151,9 +157,9 @@ TEST_F(AvmExecutionTests, setAndSubOpcodes) auto trace = gen_trace_from_instr(instructions); // Find the first row enabling the subtraction selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == 1; }); - EXPECT_EQ(row->avm_main_ic, 10000); // 47123 - 37123 = 10000 - validate_trace(std::move(trace), Execution::convert_public_inputs(public_inputs_vec), true); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sub == 1; }); + EXPECT_EQ(row->main_ic, 10000); // 47123 - 37123 = 10000 + validate_trace(std::move(trace), public_inputs, true); } // Positive test for multiple MUL opcodes @@ -230,10 +236,10 @@ TEST_F(AvmExecutionTests, powerWithMulOpcodes) // Find the first row enabling the multiplication selector and pc = 13 auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == 1 && r.avm_main_pc == 13; }); - EXPECT_EQ(row->avm_main_ic, 244140625); // 5^12 = 244140625 + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_mul == 1 && r.main_pc == 13; }); + EXPECT_EQ(row->main_ic, 244140625); // 5^12 = 244140625 - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Positive test about a single internal_call and internal_return @@ -293,14 +299,14 @@ TEST_F(AvmExecutionTests, simpleInternalCall) std::vector pc_sequence{ 0, 1, 4, 5, 2, 3 }; for (size_t i = 0; i < 6; i++) { - EXPECT_EQ(trace.at(i + 1).avm_main_pc, pc_sequence.at(i)); + EXPECT_EQ(trace.at(i + 1).main_pc, pc_sequence.at(i)); } // Find the first row enabling the addition selector. - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_add == 1; }); - EXPECT_EQ(row->avm_main_ic, 345567789); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_add == 1; }); + EXPECT_EQ(row->main_ic, 345567789); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Positive test with some nested internall calls @@ -372,15 +378,15 @@ TEST_F(AvmExecutionTests, nestedInternalCalls) std::vector pc_sequence{ 0, 1, 2, 8, 6, 7, 9, 10, 4, 5, 11, 3 }; for (size_t i = 0; i < 6; i++) { - EXPECT_EQ(trace.at(i + 1).avm_main_pc, pc_sequence.at(i)); + EXPECT_EQ(trace.at(i + 1).main_pc, pc_sequence.at(i)); } // Find the first row enabling the multiplication selector. - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == 1; }); - EXPECT_EQ(row->avm_main_ic, 187); - EXPECT_EQ(row->avm_main_pc, 4); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_mul == 1; }); + EXPECT_EQ(row->main_ic, 187); + EXPECT_EQ(row->main_pc, 4); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Positive test with JUMP and CALLDATACOPY @@ -443,19 +449,19 @@ TEST_F(AvmExecutionTests, jumpAndCalldatacopy) std::vector pc_sequence{ 0, 1, 3, 4 }; for (size_t i = 0; i < 4; i++) { - EXPECT_EQ(trace.at(i + 1).avm_main_pc, pc_sequence.at(i)); + EXPECT_EQ(trace.at(i + 1).main_pc, pc_sequence.at(i)); } // Find the first row enabling the fdiv selector. - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fdiv == 1; }); - EXPECT_EQ(row->avm_main_ic, 12); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fdiv == 1; }); + EXPECT_EQ(row->main_ic, 12); // Find the first row enabling the subtraction selector. - row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == 1; }); + row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sub == 1; }); // It must have failed as subtraction was "jumped over". EXPECT_EQ(row, trace.end()); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Positive test for JUMPI. @@ -525,33 +531,32 @@ TEST_F(AvmExecutionTests, jumpiAndCalldatacopy) std::vector pc_sequence_no_jump{ 0, 1, 2, 3, 4, 5 }; for (size_t i = 0; i < 5; i++) { - EXPECT_EQ(trace_jump.at(i + 1).avm_main_pc, pc_sequence_jump.at(i)); + EXPECT_EQ(trace_jump.at(i + 1).main_pc, pc_sequence_jump.at(i)); } for (size_t i = 0; i < 6; i++) { - EXPECT_EQ(trace_no_jump.at(i + 1).avm_main_pc, pc_sequence_no_jump.at(i)); + EXPECT_EQ(trace_no_jump.at(i + 1).main_pc, pc_sequence_no_jump.at(i)); } // JUMP CASE // Find the first row enabling the MUL opcode - auto row = - std::ranges::find_if(trace_jump.begin(), trace_jump.end(), [](Row r) { return r.avm_main_sel_op_mul == 1; }); - EXPECT_EQ(row->avm_main_ic, 400); // 400 = 20 * 20 + auto row = std::ranges::find_if(trace_jump.begin(), trace_jump.end(), [](Row r) { return r.main_sel_op_mul == 1; }); + EXPECT_EQ(row->main_ic, 400); // 400 = 20 * 20 // Find the first row enabling the addition selector. - row = std::ranges::find_if(trace_jump.begin(), trace_jump.end(), [](Row r) { return r.avm_main_sel_op_add == 1; }); + row = std::ranges::find_if(trace_jump.begin(), trace_jump.end(), [](Row r) { return r.main_sel_op_add == 1; }); // It must have failed as addition was "jumped over". EXPECT_EQ(row, trace_jump.end()); // NO JUMP CASE // Find the first row enabling the MUL opcode - row = std::ranges::find_if( - trace_no_jump.begin(), trace_no_jump.end(), [](Row r) { return r.avm_main_sel_op_mul == 1; }); - EXPECT_EQ(row->avm_main_ic, 1600); // 800 = (20 + 20) * (20 + 20) + row = + std::ranges::find_if(trace_no_jump.begin(), trace_no_jump.end(), [](Row r) { return r.main_sel_op_mul == 1; }); + EXPECT_EQ(row->main_ic, 1600); // 800 = (20 + 20) * (20 + 20) // traces validation - validate_trace(std::move(trace_jump)); - validate_trace(std::move(trace_no_jump)); + validate_trace(std::move(trace_jump), public_inputs); + validate_trace(std::move(trace_no_jump), public_inputs); } // Positive test with MOV. @@ -595,11 +600,11 @@ TEST_F(AvmExecutionTests, movOpcode) auto trace = gen_trace_from_instr(instructions); // Find the first row enabling the MOV selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_mov == 1; }); - EXPECT_EQ(row->avm_main_ia, 19); - EXPECT_EQ(row->avm_main_ic, 19); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_mov == 1; }); + EXPECT_EQ(row->main_ia, 19); + EXPECT_EQ(row->main_ic, 19); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Positive test with CMOV. @@ -649,13 +654,13 @@ TEST_F(AvmExecutionTests, cmovOpcode) auto trace = gen_trace_from_instr(instructions); // Find the first row enabling the CMOV selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_cmov == 1; }); - EXPECT_EQ(row->avm_main_ia, 3); - EXPECT_EQ(row->avm_main_ib, 4); - EXPECT_EQ(row->avm_main_ic, 3); - EXPECT_EQ(row->avm_main_id, 5); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_cmov == 1; }); + EXPECT_EQ(row->main_ia, 3); + EXPECT_EQ(row->main_ib, 4); + EXPECT_EQ(row->main_ic, 3); + EXPECT_EQ(row->main_id, 5); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Positive test with indirect MOV. @@ -699,11 +704,11 @@ TEST_F(AvmExecutionTests, indMovOpcode) auto trace = gen_trace_from_instr(instructions); // Find the first row enabling the MOV selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_mov == 1; }); - EXPECT_EQ(row->avm_main_ia, 255); - EXPECT_EQ(row->avm_main_ic, 255); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_mov == 1; }); + EXPECT_EQ(row->main_ia, 255); + EXPECT_EQ(row->main_ic, 255); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Positive test for SET and CAST opcodes @@ -741,10 +746,10 @@ TEST_F(AvmExecutionTests, setAndCastOpcodes) auto trace = gen_trace_from_instr(instructions); // Find the first row enabling the cast selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_cast == 1; }); - EXPECT_EQ(row->avm_main_ic, 19); // 0XB813 --> 0X13 = 19 + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_cast == 1; }); + EXPECT_EQ(row->main_ic, 19); // 0XB813 --> 0X13 = 19 - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Positive test with TO_RADIX_LE. @@ -797,15 +802,15 @@ TEST_F(AvmExecutionTests, toRadixLeOpcode) Execution::gen_trace(instructions, returndata, std::vector{ FF::modulus - FF(1) }, public_inputs_vec); // Find the first row enabling the TORADIXLE selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_radix_le == 1; }); - EXPECT_EQ(row->avm_main_ind_a, 17); - EXPECT_EQ(row->avm_main_ind_b, 21); - EXPECT_EQ(row->avm_main_mem_idx_a, 1); // Indirect(17) -> 1 - EXPECT_EQ(row->avm_main_mem_idx_b, 5); // Indirect(21) -> 5 - EXPECT_EQ(row->avm_main_ia, FF(FF::modulus - FF(1))); // Indirect(17) -> Direct(1) -> FF::modulus - FF(1) - EXPECT_EQ(row->avm_main_ib, 0); // Indirect(21) -> 5 -> Unintialized memory - EXPECT_EQ(row->avm_main_ic, 2); - EXPECT_EQ(row->avm_main_id, 256); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_radix_le == 1; }); + EXPECT_EQ(row->main_ind_addr_a, 17); + EXPECT_EQ(row->main_ind_addr_b, 21); + EXPECT_EQ(row->main_mem_addr_a, 1); // Indirect(17) -> 1 + EXPECT_EQ(row->main_mem_addr_b, 5); // Indirect(21) -> 5 + EXPECT_EQ(row->main_ia, FF(FF::modulus - FF(1))); // Indirect(17) -> Direct(1) -> FF::modulus - FF(1) + EXPECT_EQ(row->main_ib, 0); // Indirect(21) -> 5 -> Unintialized memory + EXPECT_EQ(row->main_ic, 2); + EXPECT_EQ(row->main_id, 256); // Expected output is bitwise decomposition of MODULUS - 1..could hardcode the result but it's a bit long std::vector expected_output; @@ -816,7 +821,7 @@ TEST_F(AvmExecutionTests, toRadixLeOpcode) } EXPECT_EQ(returndata, expected_output); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // // Positive test with SHA256COMPRESSION. @@ -896,20 +901,20 @@ TEST_F(AvmExecutionTests, sha256CompressionOpcode) auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec); // Find the first row enabling the Sha256Compression selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sha256 == 1; }); - EXPECT_EQ(row->avm_main_ind_a, 34); - EXPECT_EQ(row->avm_main_ind_b, 35); - EXPECT_EQ(row->avm_main_ind_c, 36); - EXPECT_EQ(row->avm_main_mem_idx_a, 1); // Indirect(34) -> 9 - EXPECT_EQ(row->avm_main_mem_idx_b, 9); // Indirect(35) -> 9 - EXPECT_EQ(row->avm_main_mem_idx_c, 256); // Indirect(36) -> 256 - EXPECT_EQ(row->avm_main_ia, 1); // Trivially contains 0. (See avm_trace for explanation why) - EXPECT_EQ(row->avm_main_ib, 1); // Contains first element of the state - EXPECT_EQ(row->avm_main_ic, 0); // Contains first element of the input + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sha256 == 1; }); + EXPECT_EQ(row->main_ind_addr_a, 34); + EXPECT_EQ(row->main_ind_addr_b, 35); + EXPECT_EQ(row->main_ind_addr_c, 36); + EXPECT_EQ(row->main_mem_addr_a, 1); // Indirect(34) -> 9 + EXPECT_EQ(row->main_mem_addr_b, 9); // Indirect(35) -> 9 + EXPECT_EQ(row->main_mem_addr_c, 256); // Indirect(36) -> 256 + EXPECT_EQ(row->main_ia, 1); // Trivially contains 0. (See avm_trace for explanation why) + EXPECT_EQ(row->main_ib, 1); // Contains first element of the state + EXPECT_EQ(row->main_ic, 0); // Contains first element of the input EXPECT_EQ(returndata, expected_output); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Positive test with SHA256 @@ -987,22 +992,22 @@ TEST_F(AvmExecutionTests, sha256Opcode) auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec); // Find the first row enabling the sha256 selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sha256 == 1; }); - EXPECT_EQ(row->avm_main_ind_a, 36); // Register A is indirect - EXPECT_EQ(row->avm_main_ind_c, 35); // Register C is indirect - EXPECT_EQ(row->avm_main_mem_idx_a, 1); // Indirect(36) -> 1 - EXPECT_EQ(row->avm_main_mem_idx_c, 256); // Indirect(35) -> 256 - EXPECT_EQ(row->avm_main_ia, 97); - EXPECT_EQ(row->avm_main_ic, 0); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sha256 == 1; }); + EXPECT_EQ(row->main_ind_addr_a, 36); // Register A is indirect + EXPECT_EQ(row->main_ind_addr_c, 35); // Register C is indirect + EXPECT_EQ(row->main_mem_addr_a, 1); // Indirect(36) -> 1 + EXPECT_EQ(row->main_mem_addr_c, 256); // Indirect(35) -> 256 + EXPECT_EQ(row->main_ia, 97); + EXPECT_EQ(row->main_ic, 0); // Register b checks are done in the next row due to the difference in the memory tag std::advance(row, 1); - EXPECT_EQ(row->avm_main_ind_b, 0); // Register B is not - EXPECT_EQ(row->avm_main_mem_idx_b, 37); // Load(37) -> input length - EXPECT_EQ(row->avm_main_ib, 3); // Input length + EXPECT_EQ(row->main_ind_addr_b, 0); // Register B is not + EXPECT_EQ(row->main_mem_addr_b, 37); // Load(37) -> input length + EXPECT_EQ(row->main_ib, 3); // Input length EXPECT_EQ(returndata, expected_output); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Positive test with POSEIDON2_PERM. @@ -1063,17 +1068,17 @@ TEST_F(AvmExecutionTests, poseidon2PermutationOpCode) auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec); // Find the first row enabling the poseidon2 selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_poseidon2 == 1; }); - EXPECT_EQ(row->avm_main_ind_a, 36); - EXPECT_EQ(row->avm_main_ind_b, 35); - EXPECT_EQ(row->avm_main_mem_idx_a, 1); // Indirect(36) -> 1 - EXPECT_EQ(row->avm_main_mem_idx_b, 9); // Indirect(34) -> 9 - EXPECT_EQ(row->avm_main_ia, FF(std::string("9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789"))); - EXPECT_EQ(row->avm_main_ib, 0); // Contains first element of the output (trivially 0) + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_poseidon2 == 1; }); + EXPECT_EQ(row->main_ind_addr_a, 36); + EXPECT_EQ(row->main_ind_addr_b, 35); + EXPECT_EQ(row->main_mem_addr_a, 1); // Indirect(36) -> 1 + EXPECT_EQ(row->main_mem_addr_b, 9); // Indirect(34) -> 9 + EXPECT_EQ(row->main_ia, FF(std::string("9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789"))); + EXPECT_EQ(row->main_ib, 0); // Contains first element of the output (trivially 0) EXPECT_EQ(returndata, expected_output); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Positive test with Keccakf1600. @@ -1158,21 +1163,21 @@ TEST_F(AvmExecutionTests, keccakf1600OpCode) auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec); // Find the first row enabling the keccak selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_keccak == 1; }); - EXPECT_EQ(row->avm_main_ind_a, 36); // Register A is indirect - EXPECT_EQ(row->avm_main_ind_c, 35); // Register C is indirect - EXPECT_EQ(row->avm_main_mem_idx_a, 1); // Indirect(36) -> 1 - EXPECT_EQ(row->avm_main_mem_idx_c, 256); // Indirect(35) -> 256 - EXPECT_EQ(row->avm_main_ia, (0xF1258F7940E1DDE7LLU)); - EXPECT_EQ(row->avm_main_ic, 0); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_keccak == 1; }); + EXPECT_EQ(row->main_ind_addr_a, 36); // Register A is indirect + EXPECT_EQ(row->main_ind_addr_c, 35); // Register C is indirect + EXPECT_EQ(row->main_mem_addr_a, 1); // Indirect(36) -> 1 + EXPECT_EQ(row->main_mem_addr_c, 256); // Indirect(35) -> 256 + EXPECT_EQ(row->main_ia, (0xF1258F7940E1DDE7LLU)); + EXPECT_EQ(row->main_ic, 0); std::advance(row, 1); - EXPECT_EQ(row->avm_main_ind_b, 0); // Register B is not - EXPECT_EQ(row->avm_main_mem_idx_b, 37); // Load(37) -> input length - EXPECT_EQ(row->avm_main_ib, 25); // Input length + EXPECT_EQ(row->main_ind_addr_b, 0); // Register B is not + EXPECT_EQ(row->main_mem_addr_b, 37); // Load(37) -> input length + EXPECT_EQ(row->main_ib, 25); // Input length EXPECT_EQ(returndata, expected_output); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Positive test with Keccak. @@ -1240,22 +1245,22 @@ TEST_F(AvmExecutionTests, keccakOpCode) auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec); // Find the first row enabling the keccak selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_keccak == 1; }); - EXPECT_EQ(row->avm_main_ind_a, 36); // Register A is indirect - EXPECT_EQ(row->avm_main_ind_c, 35); // Register C is indirect - EXPECT_EQ(row->avm_main_mem_idx_a, 1); // Indirect(36) -> 1 - EXPECT_EQ(row->avm_main_mem_idx_c, 256); // Indirect(35) -> 256 - EXPECT_EQ(row->avm_main_ia, 189); - EXPECT_EQ(row->avm_main_ic, 0); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_keccak == 1; }); + EXPECT_EQ(row->main_ind_addr_a, 36); // Register A is indirect + EXPECT_EQ(row->main_ind_addr_c, 35); // Register C is indirect + EXPECT_EQ(row->main_mem_addr_a, 1); // Indirect(36) -> 1 + EXPECT_EQ(row->main_mem_addr_c, 256); // Indirect(35) -> 256 + EXPECT_EQ(row->main_ia, 189); + EXPECT_EQ(row->main_ic, 0); // Register b checks are done in the next row due to the difference in the memory tag std::advance(row, 1); - EXPECT_EQ(row->avm_main_ind_b, 0); // Register B is not - EXPECT_EQ(row->avm_main_mem_idx_b, 37); // Load(37) -> input length - EXPECT_EQ(row->avm_main_ib, 1); // Input length + EXPECT_EQ(row->main_ind_addr_b, 0); // Register B is not + EXPECT_EQ(row->main_mem_addr_b, 37); // Load(37) -> input length + EXPECT_EQ(row->main_ib, 1); // Input length EXPECT_EQ(returndata, expected_output); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Positive test with Pedersen. @@ -1318,18 +1323,18 @@ TEST_F(AvmExecutionTests, pedersenHashOpCode) auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec); // Find the first row enabling the pedersen selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_pedersen == 1; }); - EXPECT_EQ(row->avm_main_ind_a, 4); // Register A is indirect - EXPECT_EQ(row->avm_main_mem_idx_a, 0); // Indirect(4) -> 1 - EXPECT_EQ(row->avm_main_ia, 1); // The first input + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_pedersen == 1; }); + EXPECT_EQ(row->main_ind_addr_a, 4); // Register A is indirect + EXPECT_EQ(row->main_mem_addr_a, 0); // Indirect(4) -> 1 + EXPECT_EQ(row->main_ia, 1); // The first input // The second row loads the U32 values std::advance(row, 1); - EXPECT_EQ(row->avm_main_ia, 2); // Input length is 2 - EXPECT_EQ(row->avm_main_ib, 5); // Hash offset is 5 + EXPECT_EQ(row->main_ia, 2); // Input length is 2 + EXPECT_EQ(row->main_ib, 5); // Hash offset is 5 EXPECT_EQ(returndata[0], expected_output); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // // Positive test with EmbeddedCurveAdd @@ -1391,7 +1396,84 @@ TEST_F(AvmExecutionTests, embeddedCurveAddOpCode) EXPECT_EQ(returndata, expected_output); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); +} + +// Positive test with MSM +TEST_F(AvmExecutionTests, msmOpCode) +{ + grumpkin::g1::affine_element a = grumpkin::g1::affine_element::random_element(); + FF a_is_inf = a.is_point_at_infinity(); + grumpkin::g1::affine_element b = grumpkin::g1::affine_element::random_element(); + FF b_is_inf = b.is_point_at_infinity(); + + grumpkin::g1::Fr scalar_a = grumpkin::g1::Fr::random_element(); + FF scalar_a_lo = uint256_t::from_uint128(uint128_t(scalar_a)); + FF scalar_a_hi = uint256_t(scalar_a) >> 128; + grumpkin::g1::Fr scalar_b = grumpkin::g1::Fr::random_element(); + FF scalar_b_lo = uint256_t::from_uint128(uint128_t(scalar_b)); + FF scalar_b_hi = uint256_t(scalar_b) >> 128; + auto expected_result = a * scalar_a + b * scalar_b; + std::vector expected_output = { expected_result.x, expected_result.y, expected_result.is_point_at_infinity() }; + // Send all the input as Fields and cast them to U8 later + std::vector calldata = { FF(a.x), FF(a.y), a_is_inf, FF(b.x), FF(b.y), + b_is_inf, scalar_a_lo, scalar_a_hi, scalar_b_lo, scalar_b_hi }; + std::string bytecode_hex = to_hex(OpCode::CALLDATACOPY) + // Calldatacopy...should fix the limit on calldatacopy + "00" // Indirect flag + "00000000" // cd_offset 0 + "0000000a" // copy_size (10 elements) + "00000000" // dst_offset 0 + + to_hex(OpCode::CAST) + // opcode CAST inf to U8 + "00" // Indirect flag + "01" // U8 tag field + "00000002" // a_is_inf + "00000002" // + + to_hex(OpCode::CAST) + // opcode CAST inf to U8 + "00" // Indirect flag + "01" // U8 tag field + "00000005" // b_is_inf + "00000005" // + + to_hex(OpCode::SET) + // opcode SET for length + "00" // Indirect flag + "03" // U32 + "00000006" // Length of point elements (6) + "0000000b" // dst offset (11) + + to_hex(OpCode::SET) + // SET Indirects + "00" // Indirect flag + "03" // U32 + "00000000" // points offset + "0000000d" // dst offset + + + to_hex(OpCode::SET) + // SET Indirects + "00" // Indirect flag + "03" // U32 + "00000006" // scalars offset + "0000000e" + // dst offset + to_hex(OpCode::SET) + // SET Indirects + "00" // Indirect flag + "03" // U32 + "0000000c" // output offset + "0000000f" + // dst offset + to_hex(OpCode::MSM) + // opcode MSM + "07" // Indirect flag (first 3 indirect) + "0000000d" // points offset + "0000000e" // scalars offset + "0000000f" // output offset + "0000000b" // length offset + + to_hex(OpCode::RETURN) + // opcode RETURN + "00" // Indirect flag + "0000000c" // ret offset 12 (this overwrites) + "00000003"; // ret size 3 + + auto bytecode = hex_to_bytes(bytecode_hex); + auto instructions = Deserialization::parse(bytecode); + + // Assign a vector that we will mutate internally in gen_trace to store the return values; + std::vector returndata; + auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec); + + EXPECT_EQ(returndata, expected_output); + + validate_trace(std::move(trace), public_inputs); } // Positive test for Kernel Input opcodes @@ -1544,62 +1626,61 @@ TEST_F(AvmExecutionTests, kernelInputOpcodes) // Validate that the opcode read the correct value into ia // Check sender - auto sender_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sender == 1; }); - EXPECT_EQ(sender_row->avm_main_ia, sender); + auto sender_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sender == 1; }); + EXPECT_EQ(sender_row->main_ia, sender); // Check address auto address_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_address == 1; }); - EXPECT_EQ(address_row->avm_main_ia, address); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_address == 1; }); + EXPECT_EQ(address_row->main_ia, address); // Check storage address auto storage_addr_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_storage_address == 1; }); - EXPECT_EQ(storage_addr_row->avm_main_ia, storage_address); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_storage_address == 1; }); + EXPECT_EQ(storage_addr_row->main_ia, storage_address); // Check chain id auto chainid_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_chain_id == 1; }); - EXPECT_EQ(chainid_row->avm_main_ia, chainid); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_chain_id == 1; }); + EXPECT_EQ(chainid_row->main_ia, chainid); // Check version auto version_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_version == 1; }); - EXPECT_EQ(version_row->avm_main_ia, version); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_version == 1; }); + EXPECT_EQ(version_row->main_ia, version); // Check blocknumber auto blocknumber_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_block_number == 1; }); - EXPECT_EQ(blocknumber_row->avm_main_ia, blocknumber); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_block_number == 1; }); + EXPECT_EQ(blocknumber_row->main_ia, blocknumber); // Check timestamp auto timestamp_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_timestamp == 1; }); - EXPECT_EQ(timestamp_row->avm_main_ia, timestamp); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_timestamp == 1; }); + EXPECT_EQ(timestamp_row->main_ia, timestamp); // Check feeperdagas auto feeperdagas_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fee_per_da_gas == 1; }); - EXPECT_EQ(feeperdagas_row->avm_main_ia, feeperdagas); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fee_per_da_gas == 1; }); + EXPECT_EQ(feeperdagas_row->main_ia, feeperdagas); // Check feeperl2gas auto feeperl2gas_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fee_per_l2_gas == 1; }); - EXPECT_EQ(feeperl2gas_row->avm_main_ia, feeperl2gas); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fee_per_l2_gas == 1; }); + EXPECT_EQ(feeperl2gas_row->main_ia, feeperl2gas); // Check transactionfee auto transactionfee_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_transaction_fee == 1; }); - EXPECT_EQ(transactionfee_row->avm_main_ia, transactionfee); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_transaction_fee == 1; }); + EXPECT_EQ(transactionfee_row->main_ia, transactionfee); // // Check coinbase // Not in simulator // auto coinbase_row = - // std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_coinbase == 1; }); - // EXPECT_EQ(coinbase_row->avm_main_ia, coinbase); + // std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_coinbase == 1; }); + // EXPECT_EQ(coinbase_row->main_ia, coinbase); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), Execution::convert_public_inputs(public_inputs_vec)); } // Positive test for L2GASLEFT opcode @@ -1631,15 +1712,15 @@ TEST_F(AvmExecutionTests, l2GasLeft) auto trace = gen_trace_from_instr(instructions); // Find the first row enabling the L2GASLEFT selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_l2gasleft == 1; }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_l2gasleft == 1; }); uint32_t expected_rem_gas = DEFAULT_INITIAL_L2_GAS - GAS_COST_TABLE.at(OpCode::SET).l2_fixed_gas_cost - GAS_COST_TABLE.at(OpCode::L2GASLEFT).l2_fixed_gas_cost; - EXPECT_EQ(row->avm_main_ia, expected_rem_gas); - EXPECT_EQ(row->avm_main_mem_idx_a, 257); // Resolved direct address: 257 + EXPECT_EQ(row->main_ia, expected_rem_gas); + EXPECT_EQ(row->main_mem_addr_a, 257); // Resolved direct address: 257 - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Positive test for DAGASLEFT opcode @@ -1672,15 +1753,15 @@ TEST_F(AvmExecutionTests, daGasLeft) auto trace = gen_trace_from_instr(instructions); // Find the first row enabling the DAGASLEFT selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_dagasleft == 1; }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_dagasleft == 1; }); uint32_t expected_rem_gas = DEFAULT_INITIAL_DA_GAS - GAS_COST_TABLE.at(OpCode::ADD).da_fixed_gas_cost - GAS_COST_TABLE.at(OpCode::DAGASLEFT).da_fixed_gas_cost; - EXPECT_EQ(row->avm_main_ia, expected_rem_gas); - EXPECT_EQ(row->avm_main_mem_idx_a, 39); + EXPECT_EQ(row->main_ia, expected_rem_gas); + EXPECT_EQ(row->main_mem_addr_a, 39); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Should throw whenever the wrong number of public inputs are provided @@ -1718,13 +1799,13 @@ TEST_F(AvmExecutionTests, kernelOutputEmitOpcodes) + to_hex(OpCode::EMITNOTEHASH) + // opcode EMITNOTEHASH "00" // Indirect flag "00000001" // src offset 1 - + to_hex(OpCode::EMITNULLIFIER) + // opcode EMITNOTEHASH + + to_hex(OpCode::EMITNULLIFIER) + // opcode EMITNULLIFIER "00" // Indirect flag "00000001" // src offset 1 - + to_hex(OpCode::EMITUNENCRYPTEDLOG) + // opcode EMITNOTEHASH + + to_hex(OpCode::EMITUNENCRYPTEDLOG) + // opcode EMITUNENCRYPTEDLOG "00" // Indirect flag "00000001" // src offset 1 - + to_hex(OpCode::SENDL2TOL1MSG) + // opcode EMITNOTEHASH + + to_hex(OpCode::SENDL2TOL1MSG) + // opcode SENDL2TOL1MSG "00" // Indirect flag "00000001" // src offset 1 "00000001" // src offset 1 @@ -1745,56 +1826,60 @@ TEST_F(AvmExecutionTests, kernelOutputEmitOpcodes) // CHECK EMIT NOTE HASH // Check output data + side effect counters have been set correctly auto emit_note_hash_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_emit_note_hash == 1; }); - EXPECT_EQ(emit_note_hash_row->avm_main_ia, 1); - EXPECT_EQ(emit_note_hash_row->avm_kernel_side_effect_counter, 0); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_emit_note_hash == 1; }); + EXPECT_EQ(emit_note_hash_row->main_ia, 1); + EXPECT_EQ(emit_note_hash_row->kernel_side_effect_counter, 0); // Get the row of the first note hash out uint32_t emit_note_hash_out_offset = AvmKernelTraceBuilder::START_EMIT_NOTE_HASH_WRITE_OFFSET; auto emit_note_hash_kernel_out_row = std::ranges::find_if( - trace.begin(), trace.end(), [&](Row r) { return r.avm_main_clk == emit_note_hash_out_offset; }); - EXPECT_EQ(emit_note_hash_kernel_out_row->avm_kernel_kernel_value_out, 1); - EXPECT_EQ(emit_note_hash_kernel_out_row->avm_kernel_kernel_side_effect_out, 0); + trace.begin(), trace.end(), [&](Row r) { return r.main_clk == emit_note_hash_out_offset; }); + EXPECT_EQ(emit_note_hash_kernel_out_row->kernel_kernel_value_out, 1); + EXPECT_EQ(emit_note_hash_kernel_out_row->kernel_kernel_side_effect_out, 0); + feed_output(emit_note_hash_out_offset, 1, 0, 0); // CHECK EMIT NULLIFIER auto emit_nullifier_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_emit_nullifier == 1; }); - EXPECT_EQ(emit_nullifier_row->avm_main_ia, 1); - EXPECT_EQ(emit_nullifier_row->avm_kernel_side_effect_counter, 1); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_emit_nullifier == 1; }); + EXPECT_EQ(emit_nullifier_row->main_ia, 1); + EXPECT_EQ(emit_nullifier_row->kernel_side_effect_counter, 1); uint32_t emit_nullifier_out_offset = AvmKernelTraceBuilder::START_EMIT_NULLIFIER_WRITE_OFFSET; auto emit_nullifier_kernel_out_row = std::ranges::find_if( - trace.begin(), trace.end(), [&](Row r) { return r.avm_main_clk == emit_nullifier_out_offset; }); - EXPECT_EQ(emit_nullifier_kernel_out_row->avm_kernel_kernel_value_out, 1); - EXPECT_EQ(emit_nullifier_kernel_out_row->avm_kernel_kernel_side_effect_out, 1); + trace.begin(), trace.end(), [&](Row r) { return r.main_clk == emit_nullifier_out_offset; }); + EXPECT_EQ(emit_nullifier_kernel_out_row->kernel_kernel_value_out, 1); + EXPECT_EQ(emit_nullifier_kernel_out_row->kernel_kernel_side_effect_out, 1); + feed_output(emit_nullifier_out_offset, 1, 1, 0); // CHECK EMIT UNENCRYPTED LOG - auto emit_log_row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_emit_unencrypted_log == 1; }); - EXPECT_EQ(emit_log_row->avm_main_ia, 1); - EXPECT_EQ(emit_log_row->avm_kernel_side_effect_counter, 2); + auto emit_log_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_emit_unencrypted_log == 1; }); + EXPECT_EQ(emit_log_row->main_ia, 1); + EXPECT_EQ(emit_log_row->kernel_side_effect_counter, 2); uint32_t emit_log_out_offset = AvmKernelTraceBuilder::START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET; auto emit_log_kernel_out_row = - std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.avm_main_clk == emit_log_out_offset; }); - EXPECT_EQ(emit_log_kernel_out_row->avm_kernel_kernel_value_out, 1); - EXPECT_EQ(emit_log_kernel_out_row->avm_kernel_kernel_side_effect_out, 2); + std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == emit_log_out_offset; }); + EXPECT_EQ(emit_log_kernel_out_row->kernel_kernel_value_out, 1); + EXPECT_EQ(emit_log_kernel_out_row->kernel_kernel_side_effect_out, 2); + feed_output(emit_log_out_offset, 1, 2, 0); // CHECK SEND L2 TO L1 MSG - auto send_row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_emit_l2_to_l1_msg == 1; }); - EXPECT_EQ(send_row->avm_main_ia, 1); - EXPECT_EQ(send_row->avm_main_ib, 1); - EXPECT_EQ(send_row->avm_kernel_side_effect_counter, 3); + auto send_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_emit_l2_to_l1_msg == 1; }); + EXPECT_EQ(send_row->main_ia, 1); + EXPECT_EQ(send_row->main_ib, 1); + EXPECT_EQ(send_row->kernel_side_effect_counter, 3); auto msg_out_row = std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { - return r.avm_main_clk == AvmKernelTraceBuilder::START_L2_TO_L1_MSG_WRITE_OFFSET; + return r.main_clk == AvmKernelTraceBuilder::START_L2_TO_L1_MSG_WRITE_OFFSET; }); - EXPECT_EQ(msg_out_row->avm_kernel_kernel_value_out, 1); - EXPECT_EQ(msg_out_row->avm_kernel_kernel_side_effect_out, 3); - EXPECT_EQ(msg_out_row->avm_kernel_kernel_metadata_out, 1); + EXPECT_EQ(msg_out_row->kernel_kernel_value_out, 1); + EXPECT_EQ(msg_out_row->kernel_kernel_side_effect_out, 3); + EXPECT_EQ(msg_out_row->kernel_kernel_metadata_out, 1); + feed_output(AvmKernelTraceBuilder::START_L2_TO_L1_MSG_WRITE_OFFSET, 1, 3, 1); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // SLOAD @@ -1838,21 +1923,20 @@ TEST_F(AvmExecutionTests, kernelOutputStorageLoadOpcodeSimple) // CHECK SLOAD // Check output data + side effect counters have been set correctly - auto sload_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sload == 1; }); - EXPECT_EQ(sload_row->avm_main_ia, 42); // Read value - EXPECT_EQ(sload_row->avm_main_ib, 9); // Storage slot - EXPECT_EQ(sload_row->avm_kernel_side_effect_counter, 0); + auto sload_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sload == 1; }); + EXPECT_EQ(sload_row->main_ia, 42); // Read value + EXPECT_EQ(sload_row->main_ib, 9); // Storage slot + EXPECT_EQ(sload_row->kernel_side_effect_counter, 0); // Get the row of the first read storage read out uint32_t sload_out_offset = AvmKernelTraceBuilder::START_SLOAD_WRITE_OFFSET; auto sload_kernel_out_row = - std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.avm_main_clk == sload_out_offset; }); - EXPECT_EQ(sload_kernel_out_row->avm_kernel_kernel_value_out, 42); // value - EXPECT_EQ(sload_kernel_out_row->avm_kernel_kernel_side_effect_out, 0); - EXPECT_EQ(sload_kernel_out_row->avm_kernel_kernel_metadata_out, 9); // slot - - validate_trace(std::move(trace)); + std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == sload_out_offset; }); + EXPECT_EQ(sload_kernel_out_row->kernel_kernel_value_out, 42); // value + EXPECT_EQ(sload_kernel_out_row->kernel_kernel_side_effect_out, 0); + EXPECT_EQ(sload_kernel_out_row->kernel_kernel_metadata_out, 9); // slot + feed_output(sload_out_offset, 42, 0, 9); + validate_trace(std::move(trace), public_inputs); } // SLOAD @@ -1896,29 +1980,31 @@ TEST_F(AvmExecutionTests, kernelOutputStorageLoadOpcodeComplex) // CHECK SLOAD // Check output data + side effect counters have been set correctly - auto sload_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sload == 1; }); - EXPECT_EQ(sload_row->avm_main_ia, 42); // Read value - EXPECT_EQ(sload_row->avm_main_ib, 9); // Storage slot - EXPECT_EQ(sload_row->avm_kernel_side_effect_counter, 0); + auto sload_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sload == 1; }); + EXPECT_EQ(sload_row->main_ia, 42); // Read value + EXPECT_EQ(sload_row->main_ib, 9); // Storage slot + EXPECT_EQ(sload_row->kernel_side_effect_counter, 0); sload_row++; - EXPECT_EQ(sload_row->avm_main_ia, 123); // Read value - EXPECT_EQ(sload_row->avm_main_ib, 10); // Storage slot - EXPECT_EQ(sload_row->avm_kernel_side_effect_counter, 1); + EXPECT_EQ(sload_row->main_ia, 123); // Read value + EXPECT_EQ(sload_row->main_ib, 10); // Storage slot + EXPECT_EQ(sload_row->kernel_side_effect_counter, 1); // Get the row of the first read storage read out uint32_t sload_out_offset = AvmKernelTraceBuilder::START_SLOAD_WRITE_OFFSET; auto sload_kernel_out_row = - std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.avm_main_clk == sload_out_offset; }); - EXPECT_EQ(sload_kernel_out_row->avm_kernel_kernel_value_out, 42); // value - EXPECT_EQ(sload_kernel_out_row->avm_kernel_kernel_side_effect_out, 0); - EXPECT_EQ(sload_kernel_out_row->avm_kernel_kernel_metadata_out, 9); // slot + std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == sload_out_offset; }); + EXPECT_EQ(sload_kernel_out_row->kernel_kernel_value_out, 42); // value + EXPECT_EQ(sload_kernel_out_row->kernel_kernel_side_effect_out, 0); + EXPECT_EQ(sload_kernel_out_row->kernel_kernel_metadata_out, 9); // slot sload_kernel_out_row++; - EXPECT_EQ(sload_kernel_out_row->avm_kernel_kernel_value_out, 123); // value - EXPECT_EQ(sload_kernel_out_row->avm_kernel_kernel_side_effect_out, 1); - EXPECT_EQ(sload_kernel_out_row->avm_kernel_kernel_metadata_out, 10); // slot + EXPECT_EQ(sload_kernel_out_row->kernel_kernel_value_out, 123); // value + EXPECT_EQ(sload_kernel_out_row->kernel_kernel_side_effect_out, 1); + EXPECT_EQ(sload_kernel_out_row->kernel_kernel_metadata_out, 10); // slot + + feed_output(sload_out_offset, 42, 0, 9); + feed_output(sload_out_offset + 1, 123, 1, 10); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // SSTORE @@ -1950,21 +2036,25 @@ TEST_F(AvmExecutionTests, kernelOutputStorageStoreOpcodeSimple) auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec); // CHECK SSTORE - auto sstore_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sstore == 1; }); - EXPECT_EQ(sstore_row->avm_main_ia, 42); // Read value - EXPECT_EQ(sstore_row->avm_main_ib, 9); // Storage slot - EXPECT_EQ(sstore_row->avm_kernel_side_effect_counter, 0); + auto sstore_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sstore == 1; }); + EXPECT_EQ(sstore_row->main_ia, 42); // Read value + EXPECT_EQ(sstore_row->main_ib, 9); // Storage slot + EXPECT_EQ(sstore_row->kernel_side_effect_counter, 0); // Get the row of the first storage write out uint32_t sstore_out_offset = AvmKernelTraceBuilder::START_SSTORE_WRITE_OFFSET; auto sstore_kernel_out_row = - std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.avm_main_clk == sstore_out_offset; }); - EXPECT_EQ(sstore_kernel_out_row->avm_kernel_kernel_value_out, 42); // value - EXPECT_EQ(sstore_kernel_out_row->avm_kernel_kernel_side_effect_out, 0); - EXPECT_EQ(sstore_kernel_out_row->avm_kernel_kernel_metadata_out, 9); // slot + std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == sstore_out_offset; }); - validate_trace(std::move(trace)); + auto value_out = sstore_kernel_out_row->kernel_kernel_value_out; + auto side_effect_out = sstore_kernel_out_row->kernel_kernel_side_effect_out; + auto metadata_out = sstore_kernel_out_row->kernel_kernel_metadata_out; + EXPECT_EQ(value_out, 42); // value + EXPECT_EQ(side_effect_out, 0); + EXPECT_EQ(metadata_out, 9); // slot + + feed_output(sstore_out_offset, value_out, side_effect_out, metadata_out); + validate_trace(std::move(trace), public_inputs); } // SSTORE @@ -2001,30 +2091,32 @@ TEST_F(AvmExecutionTests, kernelOutputStorageStoreOpcodeComplex) auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec); // CHECK SSTORE - auto sstore_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sstore == 1; }); - EXPECT_EQ(sstore_row->avm_main_ia, 42); // Read value - EXPECT_EQ(sstore_row->avm_main_ib, 9); // Storage slot - EXPECT_EQ(sstore_row->avm_kernel_side_effect_counter, 0); + auto sstore_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sstore == 1; }); + EXPECT_EQ(sstore_row->main_ia, 42); // Read value + EXPECT_EQ(sstore_row->main_ib, 9); // Storage slot + EXPECT_EQ(sstore_row->kernel_side_effect_counter, 0); sstore_row++; - EXPECT_EQ(sstore_row->avm_main_ia, 123); // Read value - EXPECT_EQ(sstore_row->avm_main_ib, 10); // Storage slot - EXPECT_EQ(sstore_row->avm_kernel_side_effect_counter, 1); + EXPECT_EQ(sstore_row->main_ia, 123); // Read value + EXPECT_EQ(sstore_row->main_ib, 10); // Storage slot + EXPECT_EQ(sstore_row->kernel_side_effect_counter, 1); // Get the row of the first storage write out uint32_t sstore_out_offset = AvmKernelTraceBuilder::START_SSTORE_WRITE_OFFSET; auto sstore_kernel_out_row = - std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.avm_main_clk == sstore_out_offset; }); - EXPECT_EQ(sstore_kernel_out_row->avm_kernel_kernel_value_out, 42); // value - EXPECT_EQ(sstore_kernel_out_row->avm_kernel_kernel_side_effect_out, 0); - EXPECT_EQ(sstore_kernel_out_row->avm_kernel_kernel_metadata_out, 9); // slot + std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == sstore_out_offset; }); + EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_value_out, 42); // value + EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_side_effect_out, 0); + EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_metadata_out, 9); // slot sstore_kernel_out_row++; - EXPECT_EQ(sstore_kernel_out_row->avm_kernel_kernel_value_out, 123); // value - EXPECT_EQ(sstore_kernel_out_row->avm_kernel_kernel_side_effect_out, 1); - EXPECT_EQ(sstore_kernel_out_row->avm_kernel_kernel_metadata_out, 10); // slot + EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_value_out, 123); // value + EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_side_effect_out, 1); + EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_metadata_out, 10); // slot + + feed_output(sstore_out_offset, 42, 0, 9); + feed_output(sstore_out_offset + 1, 123, 1, 10); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // SLOAD and SSTORE @@ -2073,36 +2165,36 @@ TEST_F(AvmExecutionTests, kernelOutputStorageOpcodes) // CHECK SLOAD // Check output data + side effect counters have been set correctly - auto sload_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sload == 1; }); - EXPECT_EQ(sload_row->avm_main_ia, 42); // Read value - EXPECT_EQ(sload_row->avm_main_ib, 9); // Storage slot - EXPECT_EQ(sload_row->avm_kernel_side_effect_counter, 0); + auto sload_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sload == 1; }); + EXPECT_EQ(sload_row->main_ia, 42); // Read value + EXPECT_EQ(sload_row->main_ib, 9); // Storage slot + EXPECT_EQ(sload_row->kernel_side_effect_counter, 0); // Get the row of the first storage read out uint32_t sload_out_offset = AvmKernelTraceBuilder::START_SLOAD_WRITE_OFFSET; auto sload_kernel_out_row = - std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.avm_main_clk == sload_out_offset; }); - EXPECT_EQ(sload_kernel_out_row->avm_kernel_kernel_value_out, 42); // value - EXPECT_EQ(sload_kernel_out_row->avm_kernel_kernel_side_effect_out, 0); - EXPECT_EQ(sload_kernel_out_row->avm_kernel_kernel_metadata_out, 9); // slot + std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == sload_out_offset; }); + EXPECT_EQ(sload_kernel_out_row->kernel_kernel_value_out, 42); // value + EXPECT_EQ(sload_kernel_out_row->kernel_kernel_side_effect_out, 0); + EXPECT_EQ(sload_kernel_out_row->kernel_kernel_metadata_out, 9); // slot + feed_output(sload_out_offset, 42, 0, 9); // CHECK SSTORE - auto sstore_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sstore == 1; }); - EXPECT_EQ(sstore_row->avm_main_ia, 42); // Read value - EXPECT_EQ(sstore_row->avm_main_ib, 9); // Storage slot - EXPECT_EQ(sstore_row->avm_kernel_side_effect_counter, 1); + auto sstore_row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sstore == 1; }); + EXPECT_EQ(sstore_row->main_ia, 42); // Read value + EXPECT_EQ(sstore_row->main_ib, 9); // Storage slot + EXPECT_EQ(sstore_row->kernel_side_effect_counter, 1); // Get the row of the first storage write out uint32_t sstore_out_offset = AvmKernelTraceBuilder::START_SSTORE_WRITE_OFFSET; auto sstore_kernel_out_row = - std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.avm_main_clk == sstore_out_offset; }); - EXPECT_EQ(sstore_kernel_out_row->avm_kernel_kernel_value_out, 42); // value - EXPECT_EQ(sstore_kernel_out_row->avm_kernel_kernel_side_effect_out, 1); - EXPECT_EQ(sstore_kernel_out_row->avm_kernel_kernel_metadata_out, 9); // slot + std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == sstore_out_offset; }); + EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_value_out, 42); // value + EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_side_effect_out, 1); + EXPECT_EQ(sstore_kernel_out_row->kernel_kernel_metadata_out, 9); // slot + feed_output(sstore_out_offset, 42, 1, 9); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } TEST_F(AvmExecutionTests, kernelOutputHashExistsOpcodes) @@ -2154,47 +2246,50 @@ TEST_F(AvmExecutionTests, kernelOutputHashExistsOpcodes) // CHECK NOTEHASHEXISTS auto note_hash_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_note_hash_exists == 1; }); - EXPECT_EQ(note_hash_row->avm_main_ia, 1); // Read value - EXPECT_EQ(note_hash_row->avm_main_ib, 1); // Storage slot - EXPECT_EQ(note_hash_row->avm_kernel_side_effect_counter, 0); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_note_hash_exists == 1; }); + EXPECT_EQ(note_hash_row->main_ia, 1); // Read value + EXPECT_EQ(note_hash_row->main_ib, 1); // Storage slot + EXPECT_EQ(note_hash_row->kernel_side_effect_counter, 0); auto note_hash_out_row = std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { - return r.avm_main_clk == AvmKernelTraceBuilder::START_NOTE_HASH_EXISTS_WRITE_OFFSET; + return r.main_clk == AvmKernelTraceBuilder::START_NOTE_HASH_EXISTS_WRITE_OFFSET; }); - EXPECT_EQ(note_hash_out_row->avm_kernel_kernel_value_out, 1); // value - EXPECT_EQ(note_hash_out_row->avm_kernel_kernel_side_effect_out, 0); - EXPECT_EQ(note_hash_out_row->avm_kernel_kernel_metadata_out, 1); // exists + EXPECT_EQ(note_hash_out_row->kernel_kernel_value_out, 1); // value + EXPECT_EQ(note_hash_out_row->kernel_kernel_side_effect_out, 0); + EXPECT_EQ(note_hash_out_row->kernel_kernel_metadata_out, 1); // exists + feed_output(AvmKernelTraceBuilder::START_NOTE_HASH_EXISTS_WRITE_OFFSET, 1, 0, 1); // CHECK NULLIFIEREXISTS auto nullifier_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_nullifier_exists == 1; }); - EXPECT_EQ(nullifier_row->avm_main_ia, 1); // Read value - EXPECT_EQ(nullifier_row->avm_main_ib, 1); // Storage slot - EXPECT_EQ(nullifier_row->avm_kernel_side_effect_counter, 1); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_nullifier_exists == 1; }); + EXPECT_EQ(nullifier_row->main_ia, 1); // Read value + EXPECT_EQ(nullifier_row->main_ib, 1); // Storage slot + EXPECT_EQ(nullifier_row->kernel_side_effect_counter, 1); auto nullifier_out_row = std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { - return r.avm_main_clk == AvmKernelTraceBuilder::START_NULLIFIER_EXISTS_OFFSET; + return r.main_clk == AvmKernelTraceBuilder::START_NULLIFIER_EXISTS_OFFSET; }); - EXPECT_EQ(nullifier_out_row->avm_kernel_kernel_value_out, 1); // value - EXPECT_EQ(nullifier_out_row->avm_kernel_kernel_side_effect_out, 1); - EXPECT_EQ(nullifier_out_row->avm_kernel_kernel_metadata_out, 1); // exists + EXPECT_EQ(nullifier_out_row->kernel_kernel_value_out, 1); // value + EXPECT_EQ(nullifier_out_row->kernel_kernel_side_effect_out, 1); + EXPECT_EQ(nullifier_out_row->kernel_kernel_metadata_out, 1); // exists + feed_output(AvmKernelTraceBuilder::START_NULLIFIER_EXISTS_OFFSET, 1, 1, 1); // CHECK L1TOL2MSGEXISTS - auto l1_to_l2_row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_l1_to_l2_msg_exists == 1; }); - EXPECT_EQ(l1_to_l2_row->avm_main_ia, 1); // Read value - EXPECT_EQ(l1_to_l2_row->avm_main_ib, 1); // Storage slot - EXPECT_EQ(l1_to_l2_row->avm_kernel_side_effect_counter, 2); + auto l1_to_l2_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_l1_to_l2_msg_exists == 1; }); + EXPECT_EQ(l1_to_l2_row->main_ia, 1); // Read value + EXPECT_EQ(l1_to_l2_row->main_ib, 1); // Storage slot + EXPECT_EQ(l1_to_l2_row->kernel_side_effect_counter, 2); auto msg_out_row = std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { - return r.avm_main_clk == AvmKernelTraceBuilder::START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET; + return r.main_clk == AvmKernelTraceBuilder::START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET; }); - EXPECT_EQ(msg_out_row->avm_kernel_kernel_value_out, 1); // value - EXPECT_EQ(msg_out_row->avm_kernel_kernel_side_effect_out, 2); - EXPECT_EQ(msg_out_row->avm_kernel_kernel_metadata_out, 1); // exists + EXPECT_EQ(msg_out_row->kernel_kernel_value_out, 1); // value + EXPECT_EQ(msg_out_row->kernel_kernel_side_effect_out, 2); + EXPECT_EQ(msg_out_row->kernel_kernel_metadata_out, 1); // exists + feed_output(AvmKernelTraceBuilder::START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET, 1, 2, 1); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // TEST_F(AvmExecutionTests, opCallOpcodes) @@ -2233,7 +2328,8 @@ TEST_F(AvmExecutionTests, kernelOutputHashExistsOpcodes) // "03" // U32 // "00000002" // val i // "00000007"; -// std::string bytecode_hex = bytecode_preamble // SET gas, addr, args size, ret offset, success, function selector +// std::string bytecode_hex = bytecode_preamble // SET gas, addr, args size, ret offset, success, function +// selector // + to_hex(OpCode::CALL) + // opcode CALL // "15" // Indirect flag // "00000000" // gas offset @@ -2262,7 +2358,7 @@ TEST_F(AvmExecutionTests, kernelOutputHashExistsOpcodes) // auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec, execution_hints); // EXPECT_EQ(returndata, std::vector({ 9, 8, 1 })); // The 1 represents the success -// validate_trace(std::move(trace)); +// validate_trace(std::move(trace), public_inputs); // } TEST_F(AvmExecutionTests, opGetContractInstanceOpcodes) @@ -2301,7 +2397,7 @@ TEST_F(AvmExecutionTests, opGetContractInstanceOpcodes) auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec, execution_hints); EXPECT_EQ(returndata, std::vector({ 1, 2, 3, 4, 5, 6 })); // The first one represents true - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Negative test detecting an invalid opcode byte. TEST_F(AvmExecutionTests, invalidOpcode) diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_gas.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_gas.test.cpp index 42d1f37ee00..75ebab12270 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_gas.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_gas.test.cpp @@ -47,7 +47,7 @@ void test_gas(StartGas startGas, OpcodesFunc apply_opcodes, CheckFunc check_trac check_trace(trace); - log_avm_trace(trace, 0, 10); + // log_avm_trace(trace, 0, 10); validate_trace(std::move(trace), public_inputs); } @@ -67,7 +67,7 @@ TEST_F(AvmGasPositiveTests, gasAdd) auto checks = [=](const std::vector& trace) { auto sender_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_add == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_add == FF(1); }); EXPECT_TRUE(sender_row != trace.end()); }; diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_indirect_mem.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_indirect_mem.test.cpp index 35d2a523b7d..d75c53f49eb 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_indirect_mem.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_indirect_mem.test.cpp @@ -50,28 +50,28 @@ TEST_F(AvmIndirectMemTests, allIndirectAdd) auto trace = trace_builder.finalize(); // Find the first row enabling the addition selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_add == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_add == FF(1); }); EXPECT_TRUE(row != trace.end()); // Check all addresses and values - EXPECT_EQ(row->avm_main_ia, FF(100)); - EXPECT_EQ(row->avm_main_ib, FF(101)); - EXPECT_EQ(row->avm_main_ic, FF(201)); - EXPECT_EQ(row->avm_main_ind_a, FF(0)); - EXPECT_EQ(row->avm_main_ind_b, FF(1)); - EXPECT_EQ(row->avm_main_ind_c, FF(2)); - EXPECT_EQ(row->avm_main_mem_idx_a, FF(10)); - EXPECT_EQ(row->avm_main_mem_idx_b, FF(11)); - EXPECT_EQ(row->avm_main_mem_idx_c, FF(12)); + EXPECT_EQ(row->main_ia, FF(100)); + EXPECT_EQ(row->main_ib, FF(101)); + EXPECT_EQ(row->main_ic, FF(201)); + EXPECT_EQ(row->main_ind_addr_a, FF(0)); + EXPECT_EQ(row->main_ind_addr_b, FF(1)); + EXPECT_EQ(row->main_ind_addr_c, FF(2)); + EXPECT_EQ(row->main_mem_addr_a, FF(10)); + EXPECT_EQ(row->main_mem_addr_b, FF(11)); + EXPECT_EQ(row->main_mem_addr_c, FF(12)); // Check memory operation tags - EXPECT_EQ(row->avm_main_ind_op_a, FF(1)); - EXPECT_EQ(row->avm_main_ind_op_b, FF(1)); - EXPECT_EQ(row->avm_main_ind_op_c, FF(1)); - EXPECT_EQ(row->avm_main_mem_op_a, FF(1)); - EXPECT_EQ(row->avm_main_mem_op_b, FF(1)); - EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); + EXPECT_EQ(row->main_sel_resolve_ind_addr_a, FF(1)); + EXPECT_EQ(row->main_sel_resolve_ind_addr_b, FF(1)); + EXPECT_EQ(row->main_sel_resolve_ind_addr_c, FF(1)); + EXPECT_EQ(row->main_sel_mem_op_a, FF(1)); + EXPECT_EQ(row->main_sel_mem_op_b, FF(1)); + EXPECT_EQ(row->main_sel_mem_op_c, FF(1)); validate_trace(std::move(trace), public_inputs, true); } @@ -96,30 +96,30 @@ TEST_F(AvmIndirectMemTests, indirectOutputSub) auto trace = trace_builder.finalize(); // Find the first row enabling the subtraction selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sub == FF(1); }); EXPECT_TRUE(row != trace.end()); // Check all addresses and values - EXPECT_EQ(row->avm_main_ia, FF(600)); - EXPECT_EQ(row->avm_main_ib, FF(500)); - EXPECT_EQ(row->avm_main_ic, FF(100)); - EXPECT_EQ(row->avm_main_ind_a, FF(0)); - EXPECT_EQ(row->avm_main_ind_b, FF(0)); - EXPECT_EQ(row->avm_main_ind_c, FF(5)); - EXPECT_EQ(row->avm_main_mem_idx_a, FF(50)); - EXPECT_EQ(row->avm_main_mem_idx_b, FF(51)); - EXPECT_EQ(row->avm_main_mem_idx_c, FF(52)); + EXPECT_EQ(row->main_ia, FF(600)); + EXPECT_EQ(row->main_ib, FF(500)); + EXPECT_EQ(row->main_ic, FF(100)); + EXPECT_EQ(row->main_ind_addr_a, FF(0)); + EXPECT_EQ(row->main_ind_addr_b, FF(0)); + EXPECT_EQ(row->main_ind_addr_c, FF(5)); + EXPECT_EQ(row->main_mem_addr_a, FF(50)); + EXPECT_EQ(row->main_mem_addr_b, FF(51)); + EXPECT_EQ(row->main_mem_addr_c, FF(52)); // Check memory operation tags - EXPECT_EQ(row->avm_main_ind_op_a, FF(0)); - EXPECT_EQ(row->avm_main_ind_op_b, FF(0)); - EXPECT_EQ(row->avm_main_ind_op_c, FF(1)); - EXPECT_EQ(row->avm_main_mem_op_a, FF(1)); - EXPECT_EQ(row->avm_main_mem_op_b, FF(1)); - EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); - - validate_trace(std::move(trace)); + EXPECT_EQ(row->main_sel_resolve_ind_addr_a, FF(0)); + EXPECT_EQ(row->main_sel_resolve_ind_addr_b, FF(0)); + EXPECT_EQ(row->main_sel_resolve_ind_addr_c, FF(1)); + EXPECT_EQ(row->main_sel_mem_op_a, FF(1)); + EXPECT_EQ(row->main_sel_mem_op_b, FF(1)); + EXPECT_EQ(row->main_sel_mem_op_c, FF(1)); + + validate_trace(std::move(trace), public_inputs); } // Testing a multiplication operation with indirect input operand a, @@ -142,30 +142,30 @@ TEST_F(AvmIndirectMemTests, indirectInputAMul) auto trace = trace_builder.finalize(); // Find the first row enabling the multiplication selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_mul == FF(1); }); EXPECT_TRUE(row != trace.end()); // Check all addresses and values - EXPECT_EQ(row->avm_main_ia, FF(4)); - EXPECT_EQ(row->avm_main_ib, FF(7)); - EXPECT_EQ(row->avm_main_ic, FF(28)); - EXPECT_EQ(row->avm_main_ind_a, FF(1000)); - EXPECT_EQ(row->avm_main_ind_b, FF(0)); - EXPECT_EQ(row->avm_main_ind_c, FF(0)); - EXPECT_EQ(row->avm_main_mem_idx_a, FF(100)); - EXPECT_EQ(row->avm_main_mem_idx_b, FF(101)); - EXPECT_EQ(row->avm_main_mem_idx_c, FF(102)); + EXPECT_EQ(row->main_ia, FF(4)); + EXPECT_EQ(row->main_ib, FF(7)); + EXPECT_EQ(row->main_ic, FF(28)); + EXPECT_EQ(row->main_ind_addr_a, FF(1000)); + EXPECT_EQ(row->main_ind_addr_b, FF(0)); + EXPECT_EQ(row->main_ind_addr_c, FF(0)); + EXPECT_EQ(row->main_mem_addr_a, FF(100)); + EXPECT_EQ(row->main_mem_addr_b, FF(101)); + EXPECT_EQ(row->main_mem_addr_c, FF(102)); // Check memory operation tags - EXPECT_EQ(row->avm_main_ind_op_a, FF(1)); - EXPECT_EQ(row->avm_main_ind_op_b, FF(0)); - EXPECT_EQ(row->avm_main_ind_op_c, FF(0)); - EXPECT_EQ(row->avm_main_mem_op_a, FF(1)); - EXPECT_EQ(row->avm_main_mem_op_b, FF(1)); - EXPECT_EQ(row->avm_main_mem_op_c, FF(1)); - - validate_trace(std::move(trace)); + EXPECT_EQ(row->main_sel_resolve_ind_addr_a, FF(1)); + EXPECT_EQ(row->main_sel_resolve_ind_addr_b, FF(0)); + EXPECT_EQ(row->main_sel_resolve_ind_addr_c, FF(0)); + EXPECT_EQ(row->main_sel_mem_op_a, FF(1)); + EXPECT_EQ(row->main_sel_mem_op_b, FF(1)); + EXPECT_EQ(row->main_sel_mem_op_c, FF(1)); + + validate_trace(std::move(trace), public_inputs); } } // namespace tests_avm diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_inter_table.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_inter_table.test.cpp index f09d2612094..9a4855892e5 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_inter_table.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_inter_table.test.cpp @@ -49,9 +49,9 @@ class AvmInterTableTests : public ::testing::Test { class AvmPermMainAluNegativeTests : public AvmInterTableTests { protected: std::vector trace; - size_t main_idx; - size_t mem_idx; - size_t alu_idx; + size_t main_addr; + size_t mem_addr; + size_t alu_addr; void SetUp() override { @@ -67,26 +67,25 @@ class AvmPermMainAluNegativeTests : public AvmInterTableTests { trace = trace_builder.finalize(); // Find the row with multiplication operation and retrieve clk. - auto row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_mul == FF(1); }); ASSERT_TRUE(row != trace.end()); - ASSERT_EQ(row->avm_main_ic, 1007); // Sanity check - auto clk = row->avm_main_clk; + ASSERT_EQ(row->main_ic, 1007); // Sanity check + auto clk = row->main_clk; // Find the corresponding Alu trace row - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_clk == clk; }); + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.alu_clk == clk; }); ASSERT_TRUE(alu_row != trace.end()); // Find memory trace entry related to storing output (intermediate register Ic) in memory. auto mem_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_clk == clk && r.avm_mem_op_c == FF(1) && r.avm_mem_rw == FF(1); + return r.mem_clk == clk && r.mem_sel_op_c == FF(1) && r.mem_rw == FF(1); }); ASSERT_TRUE(mem_row != trace.end()); - main_idx = static_cast(row - trace.begin()); - alu_idx = static_cast(alu_row - trace.begin()); - mem_idx = static_cast(mem_row - trace.begin()); + main_addr = static_cast(row - trace.begin()); + alu_addr = static_cast(alu_row - trace.begin()); + mem_addr = static_cast(mem_row - trace.begin()); } }; @@ -94,8 +93,8 @@ TEST_F(AvmPermMainAluNegativeTests, wrongAluOutputCopyInMain) { // Mutate the multiplication output. Note that the output alu counterpart is still valid // and pass the multiplication relation. - trace.at(main_idx).avm_main_ic = 1008; - trace.at(mem_idx).avm_mem_val = 1008; + trace.at(main_addr).main_ic = 1008; + trace.at(mem_addr).mem_val = 1008; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_ALU"); } @@ -103,10 +102,10 @@ TEST_F(AvmPermMainAluNegativeTests, wrongAluOutputCopyInMain) TEST_F(AvmPermMainAluNegativeTests, wrongCopyToAluIaInput) { // Mutate the input of alu_ia and adapt the output ic accordingly. - trace.at(alu_idx).avm_alu_ia = 20; - trace.at(alu_idx).avm_alu_ic = 1060; // 20 * 53; required to pass the alu mul relation - trace.at(alu_idx).avm_alu_u8_r0 = 36; // 1060 % 256 = 36 - trace.at(alu_idx).avm_alu_u8_r1 = 4; // 4 * 256 = 1024 + trace.at(alu_addr).alu_ia = 20; + trace.at(alu_addr).alu_ic = 1060; // 20 * 53; required to pass the alu mul relation + trace.at(alu_addr).alu_u8_r0 = 36; // 1060 % 256 = 36 + trace.at(alu_addr).alu_u8_r1 = 4; // 4 * 256 = 1024 EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_ALU"); } @@ -114,30 +113,30 @@ TEST_F(AvmPermMainAluNegativeTests, wrongCopyToAluIaInput) TEST_F(AvmPermMainAluNegativeTests, wrongCopyToAluIbInput) { // Mutate the input of alu_ia and adapt the output ic accordingly. - trace.at(alu_idx).avm_alu_ib = 10; - trace.at(alu_idx).avm_alu_ic = 190; // 19 * 10; required to pass the alu mul relation - trace.at(alu_idx).avm_alu_u8_r0 = 190; - trace.at(alu_idx).avm_alu_u8_r1 = 0; + trace.at(alu_addr).alu_ib = 10; + trace.at(alu_addr).alu_ic = 190; // 19 * 10; required to pass the alu mul relation + trace.at(alu_addr).alu_u8_r0 = 190; + trace.at(alu_addr).alu_u8_r1 = 0; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_ALU"); } TEST_F(AvmPermMainAluNegativeTests, wrongCopyToAluOpSelector) { - trace.at(alu_idx).avm_alu_op_mul = 0; - trace.at(alu_idx).avm_alu_op_add = 1; - trace.at(alu_idx).avm_alu_ic = 72; // 19 + 53 - trace.at(alu_idx).avm_alu_u8_r0 = 72; - trace.at(alu_idx).avm_alu_u8_r1 = 0; + trace.at(alu_addr).alu_op_mul = 0; + trace.at(alu_addr).alu_op_add = 1; + trace.at(alu_addr).alu_ic = 72; // 19 + 53 + trace.at(alu_addr).alu_u8_r0 = 72; + trace.at(alu_addr).alu_u8_r1 = 0; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_ALU"); } TEST_F(AvmPermMainAluNegativeTests, removeAluSelector) { - trace.at(alu_idx).avm_alu_alu_sel = 0; - trace.at(alu_idx).avm_alu_op_mul = 0; - trace.at(alu_idx).avm_alu_rng_chk_lookup_selector = 0; + trace.at(alu_addr).alu_sel_alu = 0; + trace.at(alu_addr).alu_op_mul = 0; + trace.at(alu_addr).alu_sel_rng_chk_lookup = 0; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_ALU"); } @@ -148,9 +147,9 @@ TEST_F(AvmPermMainAluNegativeTests, removeAluSelector) class AvmRangeCheckNegativeTests : public AvmInterTableTests { protected: std::vector trace; - size_t main_idx; - size_t mem_idx; - size_t alu_idx; + size_t main_addr; + size_t mem_addr; + size_t alu_addr; void genTraceAdd( uint128_t const& a, uint128_t const& b, uint128_t const& c, AvmMemoryTag tag, uint32_t min_trace_size = 0) @@ -162,28 +161,27 @@ class AvmRangeCheckNegativeTests : public AvmInterTableTests { trace = trace_builder.finalize(min_trace_size); // Find the row with addition operation and retrieve clk. - auto row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_add == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_add == FF(1); }); ASSERT_TRUE(row != trace.end()); - ASSERT_EQ(row->avm_main_ia, FF(uint256_t::from_uint128(a))); - ASSERT_EQ(row->avm_main_ib, FF(uint256_t::from_uint128(b))); - ASSERT_EQ(row->avm_main_ic, FF(uint256_t::from_uint128(c))); - auto clk = row->avm_main_clk; + ASSERT_EQ(row->main_ia, FF(uint256_t::from_uint128(a))); + ASSERT_EQ(row->main_ib, FF(uint256_t::from_uint128(b))); + ASSERT_EQ(row->main_ic, FF(uint256_t::from_uint128(c))); + auto clk = row->main_clk; // Find the corresponding Alu trace row - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_clk == clk; }); + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.alu_clk == clk; }); ASSERT_TRUE(alu_row != trace.end()); // Find memory trace entry related to storing output (intermediate register Ic) in memory. auto mem_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_clk == clk && r.avm_mem_op_c == FF(1) && r.avm_mem_rw == FF(1); + return r.mem_clk == clk && r.mem_sel_op_c == FF(1) && r.mem_rw == FF(1); }); ASSERT_TRUE(mem_row != trace.end()); - main_idx = static_cast(row - trace.begin()); - alu_idx = static_cast(alu_row - trace.begin()); - mem_idx = static_cast(mem_row - trace.begin()); + main_addr = static_cast(row - trace.begin()); + alu_addr = static_cast(alu_row - trace.begin()); + mem_addr = static_cast(mem_row - trace.begin()); }; }; @@ -198,19 +196,19 @@ TEST_F(AvmRangeCheckNegativeTests, additionU8Reg0) // All constraints except range checks on u8_r0, u8_r1 are satisfied. FF const fake_c = FF(15).add(-FF(2).pow(254)); - auto& row = trace.at(main_idx); - auto& mem_row = trace.at(mem_idx); - auto& alu_row = trace.at(alu_idx); + auto& row = trace.at(main_addr); + auto& mem_row = trace.at(mem_addr); + auto& alu_row = trace.at(alu_addr); - row.avm_main_ic = fake_c; - mem_row.avm_mem_val = fake_c; - alu_row.avm_alu_ic = fake_c; + row.main_ic = fake_c; + mem_row.mem_val = fake_c; + alu_row.alu_ic = fake_c; - ASSERT_EQ(alu_row.avm_alu_u8_r0, 15); - ASSERT_EQ(alu_row.avm_alu_u8_r1, 0); + ASSERT_EQ(alu_row.alu_u8_r0, 15); + ASSERT_EQ(alu_row.alu_u8_r1, 0); - alu_row.avm_alu_u8_r0 = fake_c; - alu_row.avm_alu_u8_r1 = FF(2).pow(246); + alu_row.alu_u8_r0 = fake_c; + alu_row.alu_u8_r1 = FF(2).pow(246); // We first try to validate without any range check counters adjustment. auto trace_same_cnt = trace; @@ -228,9 +226,9 @@ TEST_F(AvmRangeCheckNegativeTests, additionU8Reg0) TEST_F(AvmRangeCheckNegativeTests, additionU8Reg1) { genTraceAdd(19, 20, 39, AvmMemoryTag::U8); - auto& row = trace.at(main_idx); - auto& mem_row = trace.at(mem_idx); - auto& alu_row = trace.at(alu_idx); + auto& row = trace.at(main_addr); + auto& mem_row = trace.at(mem_addr); + auto& alu_row = trace.at(alu_addr); // a + b = u8_r0 + 2^8 * u8_r1 (mod p) // We recall that p-1 is a multiple of a large power of two. @@ -240,15 +238,15 @@ TEST_F(AvmRangeCheckNegativeTests, additionU8Reg1) uint256_t const r1 = (uint256_t(FF::modulus) - 1) / 256; FF const fake_c = FF(40); - row.avm_main_ic = fake_c; - mem_row.avm_mem_val = fake_c; - alu_row.avm_alu_ic = fake_c; + row.main_ic = fake_c; + mem_row.mem_val = fake_c; + alu_row.alu_ic = fake_c; - ASSERT_EQ(alu_row.avm_alu_u8_r0, 39); - ASSERT_EQ(alu_row.avm_alu_u8_r1, 0); + ASSERT_EQ(alu_row.alu_u8_r0, 39); + ASSERT_EQ(alu_row.alu_u8_r1, 0); - alu_row.avm_alu_u8_r0 = fake_c; - alu_row.avm_alu_u8_r1 = FF(r1); + alu_row.alu_u8_r0 = fake_c; + alu_row.alu_u8_r1 = FF(r1); // We adjust counter to pass range check lookup for u8_r0 trace.at(39).lookup_u8_0_counts -= FF(1); @@ -266,9 +264,9 @@ TEST_F(AvmRangeCheckNegativeTests, additionU8Reg1) TEST_F(AvmRangeCheckNegativeTests, additionU16Reg0) { genTraceAdd(1200, 2000, 3200, AvmMemoryTag::U16, 130); - auto& row = trace.at(main_idx); - auto& mem_row = trace.at(mem_idx); - auto& alu_row = trace.at(alu_idx); + auto& row = trace.at(main_addr); + auto& mem_row = trace.at(mem_addr); + auto& alu_row = trace.at(alu_addr); // a + b = u8_r0 + 2^8 * u8_r1 + 2^16 * u16_r0 (mod p) // We recall that p-1 is a multiple of a large power of two. @@ -278,17 +276,17 @@ TEST_F(AvmRangeCheckNegativeTests, additionU16Reg0) uint256_t const u16_r0 = (uint256_t(FF::modulus) - 1) / 65536; FF const fake_c = FF(3201); - row.avm_main_ic = fake_c; - mem_row.avm_mem_val = fake_c; - alu_row.avm_alu_ic = fake_c; + row.main_ic = fake_c; + mem_row.mem_val = fake_c; + alu_row.alu_ic = fake_c; - ASSERT_EQ(alu_row.avm_alu_u8_r0, FF(128)); // 3200 % 256 = 128 - ASSERT_EQ(alu_row.avm_alu_u8_r1, FF(12)); // 3200/256 = 12 - ASSERT_EQ(alu_row.avm_alu_u16_r0, 0); + ASSERT_EQ(alu_row.alu_u8_r0, FF(128)); // 3200 % 256 = 128 + ASSERT_EQ(alu_row.alu_u8_r1, FF(12)); // 3200/256 = 12 + ASSERT_EQ(alu_row.alu_u16_r0, 0); - alu_row.avm_alu_u8_r0 = FF(129); // 3201 % 256 = 129 - // alu_row.avm_alu_u8_r1 = FF(r1); // Does not change 3201/256 = 12 - alu_row.avm_alu_u16_r0 = FF(u16_r0); + alu_row.alu_u8_r0 = FF(129); // 3201 % 256 = 129 + // alu_row.alu_u8_r1 = FF(r1); // Does not change 3201/256 = 12 + alu_row.alu_u16_r0 = FF(u16_r0); // We adjust counter to pass range check lookup for u8_r0 trace.at(128).lookup_u8_0_counts -= FF(1); @@ -313,8 +311,8 @@ TEST_F(AvmRangeCheckNegativeTests, additionU16Reg7) genTraceAdd(4500, 45, 4545, AvmMemoryTag::U16); auto trace_original = trace; - auto& alu_row = trace.at(alu_idx); - alu_row.avm_alu_u16_r7 = FF(235655); + auto& alu_row = trace.at(alu_addr); + alu_row.alu_u16_r7 = FF(235655); auto trace_same_cnt = trace; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace_same_cnt)), "LOOKUP_U16_7"); @@ -330,7 +328,7 @@ TEST_F(AvmRangeCheckNegativeTests, additionU16Reg7) TEST_F(AvmRangeCheckNegativeTests, additionU16Reg8) { genTraceAdd(4500, 45, 4545, AvmMemoryTag::U16); - trace.at(alu_idx).avm_alu_u16_r8 = FF(235655); + trace.at(alu_addr).alu_u16_r8 = FF(235655); trace.at(1).lookup_u16_8_counts -= FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "LOOKUP_U16_8"); } @@ -339,7 +337,7 @@ TEST_F(AvmRangeCheckNegativeTests, additionU16Reg8) TEST_F(AvmRangeCheckNegativeTests, additionU16Reg9) { genTraceAdd(4500, 45, 4545, AvmMemoryTag::U16); - trace.at(alu_idx).avm_alu_u16_r9 = FF(235655); + trace.at(alu_addr).alu_u16_r9 = FF(235655); trace.at(1).lookup_u16_9_counts -= FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "LOOKUP_U16_9"); } @@ -348,7 +346,7 @@ TEST_F(AvmRangeCheckNegativeTests, additionU16Reg9) TEST_F(AvmRangeCheckNegativeTests, additionU16Reg10) { genTraceAdd(4500, 45, 4545, AvmMemoryTag::U16); - trace.at(alu_idx).avm_alu_u16_r10 = FF(235655); + trace.at(alu_addr).alu_u16_r10 = FF(235655); trace.at(1).lookup_u16_10_counts -= FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "LOOKUP_U16_10"); } @@ -357,7 +355,7 @@ TEST_F(AvmRangeCheckNegativeTests, additionU16Reg10) TEST_F(AvmRangeCheckNegativeTests, additionU16Reg11) { genTraceAdd(4500, 45, 4545, AvmMemoryTag::U16); - trace.at(alu_idx).avm_alu_u16_r11 = FF(235655); + trace.at(alu_addr).alu_u16_r11 = FF(235655); trace.at(1).lookup_u16_11_counts -= FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "LOOKUP_U16_11"); } @@ -366,7 +364,7 @@ TEST_F(AvmRangeCheckNegativeTests, additionU16Reg11) TEST_F(AvmRangeCheckNegativeTests, additionU16Reg12) { genTraceAdd(4500, 45, 4545, AvmMemoryTag::U16); - trace.at(alu_idx).avm_alu_u16_r12 = FF(235655); + trace.at(alu_addr).alu_u16_r12 = FF(235655); trace.at(1).lookup_u16_12_counts -= FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "LOOKUP_U16_12"); } @@ -375,7 +373,7 @@ TEST_F(AvmRangeCheckNegativeTests, additionU16Reg12) TEST_F(AvmRangeCheckNegativeTests, additionU16Reg13) { genTraceAdd(4500, 45, 4545, AvmMemoryTag::U16); - trace.at(alu_idx).avm_alu_u16_r13 = FF(235655); + trace.at(alu_addr).alu_u16_r13 = FF(235655); trace.at(1).lookup_u16_13_counts -= FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "LOOKUP_U16_13"); } @@ -384,7 +382,7 @@ TEST_F(AvmRangeCheckNegativeTests, additionU16Reg13) TEST_F(AvmRangeCheckNegativeTests, additionU16Reg14) { genTraceAdd(4500, 45, 4545, AvmMemoryTag::U16); - trace.at(alu_idx).avm_alu_u16_r14 = FF(235655); + trace.at(alu_addr).alu_u16_r14 = FF(235655); trace.at(1).lookup_u16_14_counts -= FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "LOOKUP_U16_14"); } @@ -395,11 +393,11 @@ TEST_F(AvmRangeCheckNegativeTests, additionU16Reg14) class AvmPermMainMemNegativeTests : public AvmInterTableTests { protected: std::vector trace; - size_t main_idx; - size_t mem_idx_a; - size_t mem_idx_b; - size_t mem_idx_c; - size_t alu_idx; + size_t main_addr; + size_t mem_addr_a; + size_t mem_addr_b; + size_t mem_addr_c; + size_t alu_addr; // Helper function to generate a trace with a subtraction // for c = a - b at arbitray chosen addresses 52 (a), 11 (b), 55 (c). @@ -413,39 +411,38 @@ class AvmPermMainMemNegativeTests : public AvmInterTableTests { trace = trace_builder.finalize(); // Find the row with subtraction operation and retrieve clk. - auto row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sub == FF(1); }); ASSERT_TRUE(row != trace.end()); - auto clk = row->avm_main_clk; + auto clk = row->main_clk; // Find the corresponding Alu trace row - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_clk == clk; }); + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.alu_clk == clk; }); ASSERT_TRUE(alu_row != trace.end()); // Find memory trace entry related to storing output (intermediate register Ic) in memory. auto mem_row_c = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_clk == clk && r.avm_mem_op_c == FF(1) && r.avm_mem_rw == FF(1); + return r.mem_clk == clk && r.mem_sel_op_c == FF(1) && r.mem_rw == FF(1); }); ASSERT_TRUE(mem_row_c != trace.end()); // Find memory trace entry related to loading first input (intermediate register Ia) in memory. auto mem_row_a = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_clk == clk && r.avm_mem_op_a == FF(1) && r.avm_mem_rw == FF(0); + return r.mem_clk == clk && r.mem_sel_op_a == FF(1) && r.mem_rw == FF(0); }); ASSERT_TRUE(mem_row_a != trace.end()); // Find memory trace entry related to loading second input (intermediate register Ib) in memory. auto mem_row_b = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_clk == clk && r.avm_mem_op_b == FF(1) && r.avm_mem_rw == FF(0); + return r.mem_clk == clk && r.mem_sel_op_b == FF(1) && r.mem_rw == FF(0); }); ASSERT_TRUE(mem_row_b != trace.end()); - main_idx = static_cast(row - trace.begin()); - alu_idx = static_cast(alu_row - trace.begin()); - mem_idx_a = static_cast(mem_row_a - trace.begin()); - mem_idx_b = static_cast(mem_row_b - trace.begin()); - mem_idx_c = static_cast(mem_row_c - trace.begin()); + main_addr = static_cast(row - trace.begin()); + alu_addr = static_cast(alu_row - trace.begin()); + mem_addr_a = static_cast(mem_row_a - trace.begin()); + mem_addr_b = static_cast(mem_row_b - trace.begin()); + mem_addr_c = static_cast(mem_row_c - trace.begin()); } }; // Error tag propagation from memory trace back to the main trace. @@ -459,40 +456,40 @@ TEST_F(AvmPermMainMemNegativeTests, tagErrNotCopiedInMain) auto trace = trace_builder.finalize(); // Find the row with equality operation and mutate the error tag. - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_eq == 1; }); - ASSERT_EQ(row->avm_main_tag_err, FF(1)); // Sanity check that the error tag is set. - row->avm_main_tag_err = 0; - row->avm_main_alu_sel = 1; // We have to activate ALU trace if no error tag is present. - auto const clk = row->avm_main_clk; + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_eq == 1; }); + ASSERT_EQ(row->main_tag_err, FF(1)); // Sanity check that the error tag is set. + row->main_tag_err = 0; + row->main_sel_alu = 1; // We have to activate ALU trace if no error tag is present. + auto const clk = row->main_clk; // Create a valid ALU entry for this equality operation. auto& alu_row = trace.at(1); - alu_row.avm_alu_clk = clk; - alu_row.avm_alu_alu_sel = 1; - alu_row.avm_alu_ia = 32; - alu_row.avm_alu_ib = 32; - alu_row.avm_alu_ic = 1; - alu_row.avm_alu_op_eq = 1; - alu_row.avm_alu_in_tag = static_cast(AvmMemoryTag::U128); - alu_row.avm_alu_u128_tag = 1; + alu_row.alu_clk = clk; + alu_row.alu_sel_alu = 1; + alu_row.alu_ia = 32; + alu_row.alu_ib = 32; + alu_row.alu_ic = 1; + alu_row.alu_op_eq = 1; + alu_row.alu_in_tag = static_cast(AvmMemoryTag::U128); + alu_row.alu_u128_tag = 1; // Adjust the output of the computation as it would have been performed without tag check. - row->avm_main_ic = 1; + row->main_ic = 1; // Find the memory row pertaining to write operation from Ic. auto mem_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_STORE_C; + return r.mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_STORE_C; }); // Adjust the output in the memory trace. - mem_row->avm_mem_val = 1; + mem_row->mem_val = 1; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "INCL_MAIN_TAG_ERR"); } TEST_F(AvmPermMainMemNegativeTests, wrongValueIaInMem) { executeSub(21, 3); - trace.at(mem_idx_a).avm_mem_val = 26; // Correct value: 21 - trace.at(mem_idx_a - 1).avm_mem_val = 26; // We need to adjust the write operation beforehand (set opcode). + trace.at(mem_addr_a).mem_val = 26; // Correct value: 21 + trace.at(mem_addr_a - 1).mem_val = 26; // We need to adjust the write operation beforehand (set opcode). EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_A"); } @@ -500,8 +497,8 @@ TEST_F(AvmPermMainMemNegativeTests, wrongValueIaInMem) TEST_F(AvmPermMainMemNegativeTests, wrongValueIbInMem) { executeSub(21, 3); - trace.at(mem_idx_b).avm_mem_val = 7; // Correct value: 3 - trace.at(mem_idx_b - 1).avm_mem_val = 7; // We need to adjust the write operation beforehand (set opcode). + trace.at(mem_addr_b).mem_val = 7; // Correct value: 3 + trace.at(mem_addr_b - 1).mem_val = 7; // We need to adjust the write operation beforehand (set opcode). EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_B"); } @@ -509,7 +506,7 @@ TEST_F(AvmPermMainMemNegativeTests, wrongValueIbInMem) TEST_F(AvmPermMainMemNegativeTests, wrongValueIcInMem) { executeSub(21, 3); - trace.at(mem_idx_c).avm_mem_val = 17; // Correct value: 18 = 21 - 3 + trace.at(mem_addr_c).mem_val = 17; // Correct value: 18 = 21 - 3 EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_C"); } @@ -517,7 +514,7 @@ TEST_F(AvmPermMainMemNegativeTests, wrongValueIcInMem) TEST_F(AvmPermMainMemNegativeTests, wrongAddressIaInMain) { executeSub(21, 3); - trace.at(main_idx).avm_main_mem_idx_a = 28; // Correct address: 52 + trace.at(main_addr).main_mem_addr_a = 28; // Correct address: 52 EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_A"); } @@ -525,7 +522,7 @@ TEST_F(AvmPermMainMemNegativeTests, wrongAddressIaInMain) TEST_F(AvmPermMainMemNegativeTests, wrongAddressIbInMain) { executeSub(21, 3); - trace.at(main_idx).avm_main_mem_idx_b = 2; // Correct address: 11 + trace.at(main_addr).main_mem_addr_b = 2; // Correct address: 11 EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_B"); } @@ -533,7 +530,7 @@ TEST_F(AvmPermMainMemNegativeTests, wrongAddressIbInMain) TEST_F(AvmPermMainMemNegativeTests, wrongAddressIcInMain) { executeSub(21, 3); - trace.at(main_idx).avm_main_mem_idx_c = 75; // Correct address: 55 + trace.at(main_addr).main_mem_addr_c = 75; // Correct address: 55 EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_C"); } @@ -542,13 +539,13 @@ TEST_F(AvmPermMainMemNegativeTests, wrongInTagIaInMem) { executeSub(21, 3); auto wrong_in_tag = static_cast(AvmMemoryTag::U32); - trace.at(mem_idx_a).avm_mem_r_in_tag = wrong_in_tag; // Correct value: AvmMemoryTag::U8 - trace.at(mem_idx_a).avm_mem_tag = wrong_in_tag; + trace.at(mem_addr_a).mem_r_in_tag = wrong_in_tag; // Correct value: AvmMemoryTag::U8 + trace.at(mem_addr_a).mem_tag = wrong_in_tag; // We need to adjust the write operation beforehand (set opcode). - trace.at(mem_idx_a - 1).avm_mem_r_in_tag = wrong_in_tag; - trace.at(mem_idx_a - 1).avm_mem_w_in_tag = wrong_in_tag; - trace.at(mem_idx_a - 1).avm_mem_tag = wrong_in_tag; + trace.at(mem_addr_a - 1).mem_r_in_tag = wrong_in_tag; + trace.at(mem_addr_a - 1).mem_w_in_tag = wrong_in_tag; + trace.at(mem_addr_a - 1).mem_tag = wrong_in_tag; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_A"); } @@ -557,13 +554,13 @@ TEST_F(AvmPermMainMemNegativeTests, wrongInTagIbInMem) { executeSub(21, 3); auto wrong_in_tag = static_cast(AvmMemoryTag::U16); - trace.at(mem_idx_b).avm_mem_r_in_tag = wrong_in_tag; // Correct value: AvmMemoryTag::U8 - trace.at(mem_idx_b).avm_mem_tag = wrong_in_tag; + trace.at(mem_addr_b).mem_r_in_tag = wrong_in_tag; // Correct value: AvmMemoryTag::U8 + trace.at(mem_addr_b).mem_tag = wrong_in_tag; // We need to adjust the write operation beforehand (set opcode). - trace.at(mem_idx_b - 1).avm_mem_r_in_tag = wrong_in_tag; - trace.at(mem_idx_b - 1).avm_mem_w_in_tag = wrong_in_tag; - trace.at(mem_idx_b - 1).avm_mem_tag = wrong_in_tag; + trace.at(mem_addr_b - 1).mem_r_in_tag = wrong_in_tag; + trace.at(mem_addr_b - 1).mem_w_in_tag = wrong_in_tag; + trace.at(mem_addr_b - 1).mem_tag = wrong_in_tag; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_B"); } @@ -572,8 +569,8 @@ TEST_F(AvmPermMainMemNegativeTests, wrongInTagIcInMem) { executeSub(21, 3); auto wrong_in_tag = static_cast(AvmMemoryTag::U128); - trace.at(mem_idx_c).avm_mem_w_in_tag = wrong_in_tag; // Correct value: AvmMemoryTag::U8 - trace.at(mem_idx_c).avm_mem_tag = wrong_in_tag; + trace.at(mem_addr_c).mem_w_in_tag = wrong_in_tag; // Correct value: AvmMemoryTag::U8 + trace.at(mem_addr_c).mem_tag = wrong_in_tag; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_C"); } @@ -581,15 +578,15 @@ TEST_F(AvmPermMainMemNegativeTests, wrongInTagIcInMem) TEST_F(AvmPermMainMemNegativeTests, wrongRwIaInMem) { executeSub(21, 3); - trace.at(mem_idx_a).avm_mem_rw = 1; // Write instead of read. + trace.at(mem_addr_a).mem_rw = 1; // Write instead of read. // Adjust timestamp value - trace.at(mem_idx_a).avm_mem_tsp += FF(AvmMemTraceBuilder::SUB_CLK_STORE_A - AvmMemTraceBuilder::SUB_CLK_LOAD_A); + trace.at(mem_addr_a).mem_tsp += FF(AvmMemTraceBuilder::SUB_CLK_STORE_A - AvmMemTraceBuilder::SUB_CLK_LOAD_A); // Adjust diff value of previous row as well - FF diff = trace.at(mem_idx_a - 1).avm_mem_diff_lo + trace.at(mem_idx_a - 1).avm_mem_diff_mid * FF(1 << 16) + + FF diff = trace.at(mem_addr_a - 1).mem_diff_lo + trace.at(mem_addr_a - 1).mem_diff_mid * FF(1 << 16) + FF(AvmMemTraceBuilder::SUB_CLK_STORE_A - AvmMemTraceBuilder::SUB_CLK_LOAD_A); - trace.at(mem_idx_a - 1).avm_mem_diff_mid = FF(uint32_t(diff) >> 16); - trace.at(mem_idx_a - 1).avm_mem_diff_lo = FF(uint32_t(diff) & UINT16_MAX); + trace.at(mem_addr_a - 1).mem_diff_mid = FF(uint32_t(diff) >> 16); + trace.at(mem_addr_a - 1).mem_diff_lo = FF(uint32_t(diff) & UINT16_MAX); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_A"); } @@ -597,15 +594,15 @@ TEST_F(AvmPermMainMemNegativeTests, wrongRwIaInMem) TEST_F(AvmPermMainMemNegativeTests, wrongRwIbInMem) { executeSub(21, 3); - trace.at(mem_idx_b).avm_mem_rw = 1; // Write instead of read. + trace.at(mem_addr_b).mem_rw = 1; // Write instead of read. // Adjust timestamp value - trace.at(mem_idx_b).avm_mem_tsp += FF(AvmMemTraceBuilder::SUB_CLK_STORE_B - AvmMemTraceBuilder::SUB_CLK_LOAD_B); + trace.at(mem_addr_b).mem_tsp += FF(AvmMemTraceBuilder::SUB_CLK_STORE_B - AvmMemTraceBuilder::SUB_CLK_LOAD_B); // Adjust diff value of previous row as well - FF diff = trace.at(mem_idx_b - 1).avm_mem_diff_lo + trace.at(mem_idx_b - 1).avm_mem_diff_mid * FF(1 << 16) + + FF diff = trace.at(mem_addr_b - 1).mem_diff_lo + trace.at(mem_addr_b - 1).mem_diff_mid * FF(1 << 16) + FF(AvmMemTraceBuilder::SUB_CLK_STORE_B - AvmMemTraceBuilder::SUB_CLK_LOAD_B); - trace.at(mem_idx_b - 1).avm_mem_diff_mid = FF(uint32_t(diff) >> 16); - trace.at(mem_idx_b - 1).avm_mem_diff_lo = FF(uint32_t(diff) & UINT16_MAX); + trace.at(mem_addr_b - 1).mem_diff_mid = FF(uint32_t(diff) >> 16); + trace.at(mem_addr_b - 1).mem_diff_lo = FF(uint32_t(diff) & UINT16_MAX); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_B"); } @@ -616,10 +613,10 @@ TEST_F(AvmPermMainMemNegativeTests, wrongRwIcInMem) // a write for a read of Ic below leads to a violation that the memory // is initialized with zero values. executeSub(11, 11); - trace.at(mem_idx_c).avm_mem_rw = 0; // Read instead of write. + trace.at(mem_addr_c).mem_rw = 0; // Read instead of write. // Adjust timestamp value. - trace.at(mem_idx_c).avm_mem_tsp -= FF(AvmMemTraceBuilder::SUB_CLK_STORE_C - AvmMemTraceBuilder::SUB_CLK_LOAD_C); + trace.at(mem_addr_c).mem_tsp -= FF(AvmMemTraceBuilder::SUB_CLK_STORE_C - AvmMemTraceBuilder::SUB_CLK_LOAD_C); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_C"); } @@ -627,13 +624,13 @@ TEST_F(AvmPermMainMemNegativeTests, wrongRwIcInMem) TEST_F(AvmPermMainMemNegativeTests, wrongClkIaInMem) { executeSub(87, 23); - trace.at(mem_idx_a).avm_mem_clk += 3; - trace.at(mem_idx_a).avm_mem_tsp += AvmMemTraceBuilder::NUM_SUB_CLK * 3; + trace.at(mem_addr_a).mem_clk += 3; + trace.at(mem_addr_a).mem_tsp += AvmMemTraceBuilder::NUM_SUB_CLK * 3; // Adjust diff value of previous row as well - FF diff = trace.at(mem_idx_a - 1).avm_mem_diff_lo + trace.at(mem_idx_a - 1).avm_mem_diff_mid * FF(1 << 16) + + FF diff = trace.at(mem_addr_a - 1).mem_diff_lo + trace.at(mem_addr_a - 1).mem_diff_mid * FF(1 << 16) + FF(AvmMemTraceBuilder::NUM_SUB_CLK * 3); - trace.at(mem_idx_a - 1).avm_mem_diff_mid = FF(uint32_t(diff) >> 16); - trace.at(mem_idx_a - 1).avm_mem_diff_lo = FF(uint32_t(diff) & UINT16_MAX); + trace.at(mem_addr_a - 1).mem_diff_mid = FF(uint32_t(diff) >> 16); + trace.at(mem_addr_a - 1).mem_diff_lo = FF(uint32_t(diff) & UINT16_MAX); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_A"); } @@ -641,12 +638,12 @@ TEST_F(AvmPermMainMemNegativeTests, wrongClkIaInMem) TEST_F(AvmPermMainMemNegativeTests, wrongClkIbInMem) { executeSub(87, 23); - trace.at(mem_idx_b).avm_mem_clk += 5; - trace.at(mem_idx_b).avm_mem_tsp += AvmMemTraceBuilder::NUM_SUB_CLK * 5; - FF diff = trace.at(mem_idx_b - 1).avm_mem_diff_lo + trace.at(mem_idx_b - 1).avm_mem_diff_mid * FF(1 << 16) + + trace.at(mem_addr_b).mem_clk += 5; + trace.at(mem_addr_b).mem_tsp += AvmMemTraceBuilder::NUM_SUB_CLK * 5; + FF diff = trace.at(mem_addr_b - 1).mem_diff_lo + trace.at(mem_addr_b - 1).mem_diff_mid * FF(1 << 16) + FF(AvmMemTraceBuilder::NUM_SUB_CLK * 5); - trace.at(mem_idx_b - 1).avm_mem_diff_mid = FF(uint32_t(diff) >> 16); - trace.at(mem_idx_b - 1).avm_mem_diff_lo = FF(uint32_t(diff) & UINT16_MAX); + trace.at(mem_addr_b - 1).mem_diff_mid = FF(uint32_t(diff) >> 16); + trace.at(mem_addr_b - 1).mem_diff_lo = FF(uint32_t(diff) & UINT16_MAX); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_B"); } @@ -654,8 +651,8 @@ TEST_F(AvmPermMainMemNegativeTests, wrongClkIbInMem) TEST_F(AvmPermMainMemNegativeTests, wrongClkIcInMem) { executeSub(87, 23); - trace.at(mem_idx_c).avm_mem_clk += 7; - trace.at(mem_idx_c).avm_mem_tsp += AvmMemTraceBuilder::NUM_SUB_CLK * 7; + trace.at(mem_addr_c).mem_clk += 7; + trace.at(mem_addr_c).mem_tsp += AvmMemTraceBuilder::NUM_SUB_CLK * 7; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_C"); } diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_kernel.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_kernel.test.cpp index dba9a4eda4f..a985bb45a63 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_kernel.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_kernel.test.cpp @@ -79,103 +79,103 @@ void test_kernel_lookup(bool indirect, /* * Helper function to assert row values for a kernel lookup opcode */ -void expect_row(auto row, FF selector, FF ia, FF ind_a, FF mem_idx_a, AvmMemoryTag w_in_tag) +void expect_row(auto row, FF selector, FF ia, FF ind_a, FF mem_addr_a, AvmMemoryTag w_in_tag) { // Checks dependent on the opcode - EXPECT_EQ(row->avm_kernel_kernel_in_offset, selector); - EXPECT_EQ(row->avm_main_ia, ia); - EXPECT_EQ(row->avm_main_mem_idx_a, mem_idx_a); + EXPECT_EQ(row->kernel_kernel_in_offset, selector); + EXPECT_EQ(row->main_ia, ia); + EXPECT_EQ(row->main_mem_addr_a, mem_addr_a); // Checks that are fixed for kernel inputs - EXPECT_EQ(row->avm_main_rwa, FF(1)); - EXPECT_EQ(row->avm_main_ind_a, ind_a); - EXPECT_EQ(row->avm_main_ind_op_a, FF(ind_a != 0)); - EXPECT_EQ(row->avm_main_mem_op_a, FF(1)); - EXPECT_EQ(row->avm_main_w_in_tag, static_cast(w_in_tag)); - EXPECT_EQ(row->avm_main_q_kernel_lookup, FF(1)); + EXPECT_EQ(row->main_rwa, FF(1)); + EXPECT_EQ(row->main_ind_addr_a, ind_a); + EXPECT_EQ(row->main_sel_resolve_ind_addr_a, FF(ind_a != 0)); + EXPECT_EQ(row->main_sel_mem_op_a, FF(1)); + EXPECT_EQ(row->main_w_in_tag, static_cast(w_in_tag)); + EXPECT_EQ(row->main_sel_q_kernel_lookup, FF(1)); } void expect_output_table_row(auto row, FF selector, FF ia, - FF mem_idx_a, + FF mem_addr_a, FF ind_a, AvmMemoryTag r_in_tag, uint32_t side_effect_counter, uint32_t rwa = 0) { // Checks dependent on the opcode - EXPECT_EQ(row->avm_kernel_kernel_out_offset, selector); - EXPECT_EQ(row->avm_main_ia, ia); - EXPECT_EQ(row->avm_main_mem_idx_a, mem_idx_a); + EXPECT_EQ(row->kernel_kernel_out_offset, selector); + EXPECT_EQ(row->main_ia, ia); + EXPECT_EQ(row->main_mem_addr_a, mem_addr_a); // Checks that are fixed for kernel inputs - EXPECT_EQ(row->avm_main_rwa, FF(rwa)); - EXPECT_EQ(row->avm_main_ind_a, ind_a); - EXPECT_EQ(row->avm_main_ind_op_a, FF(ind_a != 0)); - EXPECT_EQ(row->avm_main_mem_op_a, FF(1)); - EXPECT_EQ(row->avm_main_r_in_tag, static_cast(r_in_tag)); - EXPECT_EQ(row->avm_main_q_kernel_output_lookup, FF(1)); - - EXPECT_EQ(row->avm_kernel_side_effect_counter, FF(side_effect_counter)); + EXPECT_EQ(row->main_rwa, FF(rwa)); + EXPECT_EQ(row->main_ind_addr_a, ind_a); + EXPECT_EQ(row->main_sel_resolve_ind_addr_a, FF(ind_a != 0)); + EXPECT_EQ(row->main_sel_mem_op_a, FF(1)); + EXPECT_EQ(row->main_r_in_tag, static_cast(r_in_tag)); + EXPECT_EQ(row->main_sel_q_kernel_output_lookup, FF(1)); + + EXPECT_EQ(row->kernel_side_effect_counter, FF(side_effect_counter)); } void expect_output_table_row_with_metadata(auto row, FF selector, FF ia, - FF mem_idx_a, + FF mem_addr_a, FF ind_a, FF ib, - FF mem_idx_b, + FF mem_addr_b, FF ind_b, AvmMemoryTag r_in_tag, uint32_t side_effect_counter, uint32_t rwa = 0, bool no_b = false) { - expect_output_table_row(row, selector, ia, mem_idx_a, ind_a, r_in_tag, side_effect_counter, rwa); + expect_output_table_row(row, selector, ia, mem_addr_a, ind_a, r_in_tag, side_effect_counter, rwa); - EXPECT_EQ(row->avm_main_ib, ib); - EXPECT_EQ(row->avm_main_mem_idx_b, mem_idx_b); + EXPECT_EQ(row->main_ib, ib); + EXPECT_EQ(row->main_mem_addr_b, mem_addr_b); // Checks that are fixed for kernel inputs - EXPECT_EQ(row->avm_main_rwb, FF(0)); + EXPECT_EQ(row->main_rwb, FF(0)); if (!no_b) { - EXPECT_EQ(row->avm_main_ind_b, ind_b); - EXPECT_EQ(row->avm_main_ind_op_b, FF(ind_b != 0)); - EXPECT_EQ(row->avm_main_mem_op_b, FF(1)); + EXPECT_EQ(row->main_ind_addr_b, ind_b); + EXPECT_EQ(row->main_sel_resolve_ind_addr_b, FF(ind_b != 0)); + EXPECT_EQ(row->main_sel_mem_op_b, FF(1)); } } void expect_output_table_row_with_exists_metadata(auto row, FF selector, FF ia, - FF mem_idx_a, + FF mem_addr_a, FF ind_a, FF ib, - FF mem_idx_b, + FF mem_addr_b, FF ind_b, AvmMemoryTag w_in_tag, uint32_t side_effect_counter) { - expect_output_table_row(row, selector, ia, mem_idx_a, ind_a, w_in_tag, side_effect_counter); + expect_output_table_row(row, selector, ia, mem_addr_a, ind_a, w_in_tag, side_effect_counter); - EXPECT_EQ(row->avm_main_ib, ib); - EXPECT_EQ(row->avm_main_mem_idx_b, mem_idx_b); + EXPECT_EQ(row->main_ib, ib); + EXPECT_EQ(row->main_mem_addr_b, mem_addr_b); // Checks that are fixed for kernel inputs - EXPECT_EQ(row->avm_main_rwb, FF(1)); - EXPECT_EQ(row->avm_main_ind_b, ind_b); - EXPECT_EQ(row->avm_main_ind_op_b, FF(ind_b != 0)); - EXPECT_EQ(row->avm_main_mem_op_b, FF(1)); + EXPECT_EQ(row->main_rwb, FF(1)); + EXPECT_EQ(row->main_ind_addr_b, ind_b); + EXPECT_EQ(row->main_sel_resolve_ind_addr_b, FF(ind_b != 0)); + EXPECT_EQ(row->main_sel_mem_op_b, FF(1)); } void check_kernel_outputs(const Row& row, FF value, FF side_effect_counter, FF metadata) { - EXPECT_EQ(row.avm_kernel_kernel_value_out, value); - EXPECT_EQ(row.avm_kernel_kernel_side_effect_out, side_effect_counter); - EXPECT_EQ(row.avm_kernel_kernel_metadata_out, metadata); + EXPECT_EQ(row.kernel_kernel_value_out, value); + EXPECT_EQ(row.kernel_kernel_side_effect_out, side_effect_counter); + EXPECT_EQ(row.kernel_kernel_metadata_out, metadata); } TEST_F(AvmKernelPositiveTests, kernelSender) @@ -198,7 +198,7 @@ TEST_F(AvmKernelPositiveTests, kernelSender) auto checks = [=](bool indirect, const std::vector& trace) { auto row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sender == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sender == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_row(row, @@ -206,7 +206,7 @@ TEST_F(AvmKernelPositiveTests, kernelSender) /*ia=*/SENDER_SELECTOR + 1, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect ? indirect_dst_offset : 0, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -232,7 +232,7 @@ TEST_F(AvmKernelPositiveTests, kernelAddress) auto checks = [=](bool indirect, const std::vector& trace) { auto address_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_address == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_address == FF(1); }); EXPECT_TRUE(address_row != trace.end()); expect_row(address_row, @@ -240,7 +240,7 @@ TEST_F(AvmKernelPositiveTests, kernelAddress) /*ia=*/ADDRESS_SELECTOR + 1, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect ? indirect_dst_offset : 0, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; test_kernel_lookup(false, direct_apply_opcodes, checks); @@ -265,7 +265,7 @@ TEST_F(AvmKernelPositiveTests, kernelStorageAddress) auto checks = [=](bool indirect, const std::vector& trace) { auto storage_address_row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_storage_address == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_storage_address == FF(1); }); EXPECT_TRUE(storage_address_row != trace.end()); expect_row(storage_address_row, @@ -273,7 +273,7 @@ TEST_F(AvmKernelPositiveTests, kernelStorageAddress) /*ia=*/STORAGE_ADDRESS_SELECTOR + 1, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect ? indirect_dst_offset : 0, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -299,7 +299,7 @@ TEST_F(AvmKernelPositiveTests, kernelFeePerDa) auto checks = [=](bool indirect, const std::vector& trace) { auto fee_row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fee_per_da_gas == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fee_per_da_gas == FF(1); }); EXPECT_TRUE(fee_row != trace.end()); expect_row(fee_row, @@ -307,7 +307,7 @@ TEST_F(AvmKernelPositiveTests, kernelFeePerDa) /*ia=*/FEE_PER_DA_GAS_SELECTOR + 1, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect ? indirect_dst_offset : 0, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -333,7 +333,7 @@ TEST_F(AvmKernelPositiveTests, kernelFeePerL2) auto checks = [=](bool indirect, const std::vector& trace) { auto fee_row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fee_per_l2_gas == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fee_per_l2_gas == FF(1); }); EXPECT_TRUE(fee_row != trace.end()); expect_row(fee_row, @@ -341,7 +341,7 @@ TEST_F(AvmKernelPositiveTests, kernelFeePerL2) /*ia=*/FEE_PER_L2_GAS_SELECTOR + 1, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect ? indirect_dst_offset : 0, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -367,7 +367,7 @@ TEST_F(AvmKernelPositiveTests, kernelTransactionFee) auto checks = [=](bool indirect, const std::vector& trace) { auto fee_row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_transaction_fee == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_transaction_fee == FF(1); }); EXPECT_TRUE(fee_row != trace.end()); expect_row(fee_row, @@ -375,7 +375,7 @@ TEST_F(AvmKernelPositiveTests, kernelTransactionFee) /*ia=*/TRANSACTION_FEE_SELECTOR + 1, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect ? indirect_dst_offset : 0, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -401,7 +401,7 @@ TEST_F(AvmKernelPositiveTests, kernelChainId) auto checks = [=](bool indirect, const std::vector& trace) { auto fee_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_chain_id == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_chain_id == FF(1); }); EXPECT_TRUE(fee_row != trace.end()); expect_row(fee_row, @@ -409,7 +409,7 @@ TEST_F(AvmKernelPositiveTests, kernelChainId) /*ia=*/CHAIN_ID_SELECTOR + 1, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect ? indirect_dst_offset : 0, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -435,7 +435,7 @@ TEST_F(AvmKernelPositiveTests, kernelVersion) auto checks = [=](bool indirect, const std::vector& trace) { auto fee_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_version == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_version == FF(1); }); EXPECT_TRUE(fee_row != trace.end()); expect_row(fee_row, @@ -443,7 +443,7 @@ TEST_F(AvmKernelPositiveTests, kernelVersion) /*ia=*/VERSION_SELECTOR + 1, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect ? indirect_dst_offset : 0, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -468,8 +468,8 @@ TEST_F(AvmKernelPositiveTests, kernelBlockNumber) }; auto checks = [=](bool indirect, const std::vector& trace) { - auto fee_row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_block_number == FF(1); }); + auto fee_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_block_number == FF(1); }); EXPECT_TRUE(fee_row != trace.end()); expect_row(fee_row, @@ -477,7 +477,7 @@ TEST_F(AvmKernelPositiveTests, kernelBlockNumber) /*ia=*/BLOCK_NUMBER_SELECTOR + 1, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect ? indirect_dst_offset : 0, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -503,7 +503,7 @@ TEST_F(AvmKernelPositiveTests, kernelCoinbase) auto checks = [=](bool indirect, const std::vector& trace) { auto fee_row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_coinbase == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_coinbase == FF(1); }); EXPECT_TRUE(fee_row != trace.end()); expect_row(fee_row, @@ -511,7 +511,7 @@ TEST_F(AvmKernelPositiveTests, kernelCoinbase) /*ia=*/COINBASE_SELECTOR + 1, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect ? indirect_dst_offset : 0, - /*mem_idx_a*/ dst_offset, + /*mem_addr_a*/ dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -536,8 +536,8 @@ TEST_F(AvmKernelPositiveTests, kernelTimestamp) }; auto checks = [=](bool indirect, const std::vector& trace) { - auto fee_row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_timestamp == FF(1); }); + auto fee_row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_timestamp == FF(1); }); EXPECT_TRUE(fee_row != trace.end()); expect_row(fee_row, @@ -545,7 +545,7 @@ TEST_F(AvmKernelPositiveTests, kernelTimestamp) /*ia=*/TIMESTAMP_SELECTOR + 1, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect ? indirect_dst_offset : 0, - /*mem_idx_a*/ dst_offset, + /*mem_addr_a*/ dst_offset, /*w_in_tag=*/AvmMemoryTag::U64); }; @@ -578,7 +578,7 @@ void negative_test_incorrect_ia_kernel_lookup(OpcodesFunc apply_opcodes, // Change the first row, as that will be where each of the opcodes are in the test auto& ta = trace.at(1); - ta.avm_main_ia = incorrect_ia; + ta.main_ia = incorrect_ia; check_trace(/*indirect*/ false, trace); @@ -596,7 +596,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaSender) }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sender == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sender == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_row( @@ -604,7 +604,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaSender) /*kernel_in_offset=*/SENDER_SELECTOR, /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -622,7 +622,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaAddress) }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_address == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_address == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_row( @@ -630,7 +630,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaAddress) /*kernel_in_offset=*/ADDRESS_SELECTOR, /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -648,7 +648,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaStorageAddress) }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_storage_address == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_storage_address == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_row( @@ -656,7 +656,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaStorageAddress) /*kernel_in_offset=*/STORAGE_ADDRESS_SELECTOR, /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -674,7 +674,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaDaGas) }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fee_per_da_gas == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fee_per_da_gas == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_row( @@ -682,7 +682,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaDaGas) /*kernel_in_offset=*/FEE_PER_DA_GAS_SELECTOR, /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -700,7 +700,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIal2Gas) }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fee_per_l2_gas == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fee_per_l2_gas == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_row( @@ -708,7 +708,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIal2Gas) /*kernel_in_offset=*/FEE_PER_L2_GAS_SELECTOR, /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -726,7 +726,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaTransactionFee) }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_transaction_fee == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_transaction_fee == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_row( @@ -734,7 +734,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaTransactionFee) /*kernel_in_offset=*/TRANSACTION_FEE_SELECTOR, /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -752,7 +752,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaChainId) }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_chain_id == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_chain_id == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_row( @@ -760,7 +760,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaChainId) /*kernel_in_offset=*/CHAIN_ID_SELECTOR, /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -778,7 +778,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaVersion) }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_version == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_version == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_row( @@ -786,7 +786,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaVersion) /*kernel_in_offset=*/VERSION_SELECTOR, /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -803,8 +803,8 @@ TEST_F(AvmKernelNegativeTests, incorrectIaBlockNumber) trace_builder.op_block_number(/*indirect*/ false, dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { - auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_block_number == FF(1); }); + auto row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_block_number == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_row( @@ -812,7 +812,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaBlockNumber) /*kernel_in_offset=*/BLOCK_NUMBER_SELECTOR, /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -829,8 +829,8 @@ TEST_F(AvmKernelNegativeTests, incorrectIaTimestamp) trace_builder.op_timestamp(/*indirect*/ false, dst_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { - auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_timestamp == FF(1); }); + auto row = + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_timestamp == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_row( @@ -838,7 +838,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaTimestamp) /*kernel_in_offset=*/TIMESTAMP_SELECTOR, /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect, - /*mem_idx_a*/ dst_offset, + /*mem_addr_a*/ dst_offset, /*w_in_tag=*/AvmMemoryTag::U64); }; @@ -856,7 +856,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaCoinbase) }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_coinbase == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_coinbase == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_row( @@ -864,7 +864,7 @@ TEST_F(AvmKernelNegativeTests, incorrectIaCoinbase) /*kernel_in_offset=*/COINBASE_SELECTOR, /*ia=*/incorrect_ia, // Note the value generated above for public inputs is the same as the index read + 1 /*ind_a*/ indirect, - /*mem_idx_a=*/dst_offset, + /*mem_addr_a=*/dst_offset, /*w_in_tag=*/AvmMemoryTag::FF); }; @@ -896,14 +896,14 @@ TEST_F(AvmKernelOutputPositiveTests, kernelEmitNoteHash) auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_emit_note_hash == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_emit_note_hash == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_output_table_row( row, /*kernel_in_offset=*/output_offset, /*ia=*/value, // Note the value generated above for public inputs is the same as the index read + 1 - /*mem_idx_a=*/direct_offset, + /*mem_addr_a=*/direct_offset, /*ind_a*/ indirect ? indirect_offset : 0, /*w_in_tag=*/AvmMemoryTag::FF, /*side_effect_counter=*/0); @@ -938,14 +938,14 @@ TEST_F(AvmKernelOutputPositiveTests, kernelEmitNullifier) auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_emit_nullifier == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_emit_nullifier == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_output_table_row( row, /*kernel_in_offset=*/output_offset, /*ia=*/value, // Note the value generated above for public inputs is the same as the index read + 1 - /*mem_idx_a=*/direct_offset, + /*mem_addr_a=*/direct_offset, /*ind_a*/ indirect ? indirect_offset : 0, /*w_in_tag=*/AvmMemoryTag::FF, /*side_effect_counter=*/0); @@ -988,17 +988,17 @@ TEST_F(AvmKernelOutputPositiveTests, kernelEmitL2ToL1Msg) auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_emit_l2_to_l1_msg == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_emit_l2_to_l1_msg == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_output_table_row_with_metadata( row, /*kernel_in_offset=*/output_offset, /*ia=*/value, // Note the value generated above for public inputs is the same as the index read + 1 - /*mem_idx_a=*/msg_offset, + /*mem_addr_a=*/msg_offset, /*ind_a*/ indirect ? indirect_msg_offset : 0, /*ib=*/recipient, - /*mem_idx_b=*/recipient_offset, + /*mem_addr_b=*/recipient_offset, /*ind_a*/ indirect ? indirect_recipient_offset : 0, /*w_in_tag=*/AvmMemoryTag::FF, /*side_effect_counter=*/0); @@ -1033,14 +1033,14 @@ TEST_F(AvmKernelOutputPositiveTests, kernelEmitUnencryptedLog) auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_emit_unencrypted_log == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_emit_unencrypted_log == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_output_table_row( row, /*kernel_in_offset=*/output_offset, /*ia=*/value, // Note the value generated above for public inputs is the same as the index read + 1 - /*mem_idx_a=*/direct_offset, + /*mem_addr_a=*/direct_offset, /*ind_a*/ indirect ? indirect_offset : 0, /*w_in_tag=*/AvmMemoryTag::FF, /*side_effect_counter=*/0); @@ -1071,8 +1071,7 @@ TEST_F(AvmKernelOutputPositiveTests, kernelSload) trace_builder.op_sload(indirect, slot_offset, size, dest_offset); }; auto checks = [=]([[maybe_unused]] bool indirect, const std::vector& trace) { - auto row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sload == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sload == FF(1); }); ASSERT_TRUE(row != trace.end()); // TODO: temporarily hardcoded to direct, resolved by dbanks12 / ilyas pr - use your changes @@ -1080,10 +1079,10 @@ TEST_F(AvmKernelOutputPositiveTests, kernelSload) row, /*kernel_in_offset=*/output_offset, /*ia=*/value, // Note the value generated above for public inputs is the same as the index read + 1 - /*mem_idx_a=*/dest_offset, + /*mem_addr_a=*/dest_offset, /*ind_a=*/false, /*ib=*/slot, - /*mem_idx_b=*/0, + /*mem_addr_b=*/0, /*ind_b=*/false, /*r_in_tag=*/AvmMemoryTag::FF, /*side_effect_counter=*/0, @@ -1114,7 +1113,7 @@ TEST_F(AvmKernelOutputPositiveTests, kernelSstore) }; auto checks = [=]([[maybe_unused]] bool indirect, const std::vector& trace) { auto row = - std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sstore == FF(1); }); + std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sstore == FF(1); }); EXPECT_TRUE(row != trace.end()); // TODO: temporarily hardcoded to direct, resolved by dbanks12 / ilyas pr - use your changes @@ -1122,10 +1121,10 @@ TEST_F(AvmKernelOutputPositiveTests, kernelSstore) row, /*kernel_in_offset=*/output_offset, /*ia=*/value, // Note the value generated above for public inputs is the same as the index read + 1 - /*mem_idx_a=*/value_offset, + /*mem_addr_a=*/value_offset, /*ind_a*/ false, /*ib=*/slot, - /*mem_idx_b=*/0, + /*mem_addr_b=*/0, /*ind_b*/ false, /*w_in_tag=*/AvmMemoryTag::FF, /*side_effect_counter=*/0, @@ -1164,17 +1163,17 @@ TEST_F(AvmKernelOutputPositiveTests, kernelNoteHashExists) }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_note_hash_exists == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_note_hash_exists == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_output_table_row_with_exists_metadata( row, /*kernel_in_offset=*/output_offset, /*ia=*/value, // Note the value generated above for public inputs is the same as the index read + 1 - /*mem_idx_a=*/value_offset, + /*mem_addr_a=*/value_offset, /*ind_a*/ indirect ? FF(indirect_value_offset) : FF(0), /*ib=*/exists, - /*mem_idx_b=*/metadata_offset, + /*mem_addr_b=*/metadata_offset, /*ind_b*/ indirect ? FF(indirect_metadata_offset) : FF(0), /*w_in_tag=*/AvmMemoryTag::FF, /*side_effect_counter=*/0); @@ -1204,17 +1203,17 @@ TEST_F(AvmKernelOutputPositiveTests, kernelNullifierExists) }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_nullifier_exists == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_nullifier_exists == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_output_table_row_with_exists_metadata( row, /*kernel_in_offset=*/output_offset, /*ia=*/value, // Note the value generated above for public inputs is the same as the index read + 1 - /*mem_idx_a=*/value_offset, + /*mem_addr_a=*/value_offset, /*ind_a*/ indirect, /*ib=*/exists, - /*mem_idx_b=*/metadata_offset, + /*mem_addr_b=*/metadata_offset, /*ind_b*/ indirect, /*w_in_tag=*/AvmMemoryTag::FF, /*side_effect_counter=*/0); @@ -1243,17 +1242,17 @@ TEST_F(AvmKernelOutputPositiveTests, kernelNullifierNonExists) }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_nullifier_exists == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_nullifier_exists == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_output_table_row_with_exists_metadata( row, /*kernel_in_offset=*/output_offset, /*ia=*/value, // Note the value generated above for public inputs is the same as the index read + 1 - /*mem_idx_a=*/value_offset, + /*mem_addr_a=*/value_offset, /*ind_a*/ indirect, /*ib=*/exists, - /*mem_idx_b=*/metadata_offset, + /*mem_addr_b=*/metadata_offset, /*ind_b*/ indirect, /*w_in_tag=*/AvmMemoryTag::FF, /*side_effect_counter=*/0); @@ -1283,17 +1282,17 @@ TEST_F(AvmKernelOutputPositiveTests, kernelL1ToL2MsgExists) }; auto checks = [=]([[maybe_unused]] bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( - trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_l1_to_l2_msg_exists == FF(1); }); + trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_l1_to_l2_msg_exists == FF(1); }); EXPECT_TRUE(row != trace.end()); expect_output_table_row_with_exists_metadata( row, /*kernel_in_offset=*/output_offset, /*ia=*/value, // Note the value generated above for public inputs is the same as the index read + 1 - /*mem_idx_a=*/value_offset, + /*mem_addr_a=*/value_offset, /*ind_a*/ indirect, /*ib=*/exists, - /*mem_idx_b=*/metadata_offset, + /*mem_addr_b=*/metadata_offset, /*ind_b*/ indirect, /*w_in_tag=*/AvmMemoryTag::FF, /*side_effect_counter=*/0); diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_mem_opcodes.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_mem_opcodes.test.cpp index ff144974512..3f0538411a2 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_mem_opcodes.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_mem_opcodes.test.cpp @@ -7,7 +7,10 @@ #include #include +#define MEM_ROW_FIELD_EQ(field_name, expression) Field(#field_name, &Row::mem_##field_name, expression) + namespace tests_avm { + using namespace bb; using namespace bb::avm_trace; using namespace testing; @@ -19,15 +22,15 @@ class AvmMemOpcodeTests : public ::testing::Test { protected: std::vector trace; - size_t main_idx; - size_t mem_a_idx; - size_t mem_b_idx; - size_t mem_c_idx; - size_t mem_d_idx; - size_t mem_ind_a_idx; - size_t mem_ind_b_idx; - size_t mem_ind_c_idx; - size_t mem_ind_d_idx; + size_t main_addr; + size_t mem_a_addr; + size_t mem_b_addr; + size_t mem_c_addr; + size_t mem_d_addr; + size_t mem_ind_a_addr; + size_t mem_ind_b_addr; + size_t mem_ind_c_addr; + size_t mem_ind_d_addr; // TODO(640): The Standard Honk on Grumpkin test suite fails unless the SRS is initialised for every test. void SetUp() override @@ -76,7 +79,7 @@ class AvmMemOpcodeTests : public ::testing::Test { static std::function gen_matcher(FF clk, uint32_t sub_clk) { - return [clk, sub_clk](Row r) { return r.avm_mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + sub_clk; }; + return [clk, sub_clk](Row r) { return r.mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + sub_clk; }; }; void compute_index_a(FF clk, bool indirect) @@ -85,14 +88,14 @@ class AvmMemOpcodeTests : public ::testing::Test { auto row = std::ranges::find_if(trace.begin(), trace.end(), gen_matcher(clk, AvmMemTraceBuilder::SUB_CLK_LOAD_A)); ASSERT_TRUE(row != trace.end()); - mem_a_idx = static_cast(row - trace.begin()); + mem_a_addr = static_cast(row - trace.begin()); // Find the memory trace position of the indirect load for register ia. if (indirect) { row = std::ranges::find_if( trace.begin(), trace.end(), gen_matcher(clk, AvmMemTraceBuilder::SUB_CLK_IND_LOAD_A)); ASSERT_TRUE(row != trace.end()); - mem_ind_a_idx = static_cast(row - trace.begin()); + mem_ind_a_addr = static_cast(row - trace.begin()); } } @@ -102,25 +105,25 @@ class AvmMemOpcodeTests : public ::testing::Test { auto row = std::ranges::find_if(trace.begin(), trace.end(), gen_matcher(clk, AvmMemTraceBuilder::SUB_CLK_STORE_C)); ASSERT_TRUE(row != trace.end()); - mem_c_idx = static_cast(row - trace.begin()); + mem_c_addr = static_cast(row - trace.begin()); // Find the memory trace position of the indirect load for register ic. if (indirect) { row = std::ranges::find_if( trace.begin(), trace.end(), gen_matcher(clk, AvmMemTraceBuilder::SUB_CLK_IND_LOAD_C)); ASSERT_TRUE(row != trace.end()); - mem_ind_c_idx = static_cast(row - trace.begin()); + mem_ind_c_addr = static_cast(row - trace.begin()); } } void compute_mov_indices(bool indirect) { // Find the first row enabling the MOV selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_mov == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_mov == FF(1); }); ASSERT_TRUE(row != trace.end()); - main_idx = static_cast(row - trace.begin()); + main_addr = static_cast(row - trace.begin()); - auto clk = row->avm_main_clk; + auto clk = row->main_clk; compute_index_a(clk, indirect); compute_index_c(clk, indirect); @@ -129,38 +132,38 @@ class AvmMemOpcodeTests : public ::testing::Test { void compute_cmov_indices(uint8_t indirect) { // Find the first row enabling the CMOV selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_cmov == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_cmov == FF(1); }); ASSERT_TRUE(row != trace.end()); - main_idx = static_cast(row - trace.begin()); + main_addr = static_cast(row - trace.begin()); - auto clk = row->avm_main_clk; + auto clk = row->main_clk; compute_index_a(clk, is_operand_indirect(indirect, 0)); compute_index_c(clk, is_operand_indirect(indirect, 2)); // Find the memory trace position corresponding to the load sub-operation of register ib. row = std::ranges::find_if(trace.begin(), trace.end(), gen_matcher(clk, AvmMemTraceBuilder::SUB_CLK_LOAD_B)); ASSERT_TRUE(row != trace.end()); - mem_b_idx = static_cast(row - trace.begin()); + mem_b_addr = static_cast(row - trace.begin()); // Find the memory trace position of the indirect load for register ib. if (is_operand_indirect(indirect, 1)) { row = std::ranges::find_if( trace.begin(), trace.end(), gen_matcher(clk, AvmMemTraceBuilder::SUB_CLK_IND_LOAD_B)); ASSERT_TRUE(row != trace.end()); - mem_ind_b_idx = static_cast(row - trace.begin()); + mem_ind_b_addr = static_cast(row - trace.begin()); } // Find the memory trace position corresponding to the load sub-operation of register id. row = std::ranges::find_if(trace.begin(), trace.end(), gen_matcher(clk, AvmMemTraceBuilder::SUB_CLK_LOAD_D)); ASSERT_TRUE(row != trace.end()); - mem_d_idx = static_cast(row - trace.begin()); + mem_d_addr = static_cast(row - trace.begin()); // Find the memory trace position of the indirect load for register id. if (is_operand_indirect(indirect, 3)) { row = std::ranges::find_if( trace.begin(), trace.end(), gen_matcher(clk, AvmMemTraceBuilder::SUB_CLK_IND_LOAD_D)); ASSERT_TRUE(row != trace.end()); - mem_ind_d_idx = static_cast(row - trace.begin()); + mem_ind_d_addr = static_cast(row - trace.begin()); } } @@ -174,65 +177,65 @@ class AvmMemOpcodeTests : public ::testing::Test { { compute_mov_indices(indirect); FF const val_ff = uint256_t::from_uint128(val); - auto const& main_row = trace.at(main_idx); + auto const& main_row = trace.at(main_addr); if (indirect) { - EXPECT_THAT(main_row, - AllOf(Field(&Row::avm_main_mem_idx_a, dir_src_offset), - Field(&Row::avm_main_mem_idx_c, dir_dst_offset))); + EXPECT_THAT( + main_row, + AllOf(MAIN_ROW_FIELD_EQ(mem_addr_a, dir_src_offset), MAIN_ROW_FIELD_EQ(mem_addr_c, dir_dst_offset))); } EXPECT_THAT(main_row, - AllOf(Field(&Row::avm_main_sel_mov, 1), - Field(&Row::avm_main_sel_mov_a, 1), - Field(&Row::avm_main_ia, val_ff), - Field(&Row::avm_main_ib, 0), - Field(&Row::avm_main_ic, val_ff), - Field(&Row::avm_main_r_in_tag, static_cast(tag)), - Field(&Row::avm_main_w_in_tag, static_cast(tag)))); + AllOf(MAIN_ROW_FIELD_EQ(sel_op_mov, 1), + MAIN_ROW_FIELD_EQ(sel_mov_ia_to_ic, 1), + MAIN_ROW_FIELD_EQ(ia, val_ff), + MAIN_ROW_FIELD_EQ(ib, 0), + MAIN_ROW_FIELD_EQ(ic, val_ff), + MAIN_ROW_FIELD_EQ(r_in_tag, static_cast(tag)), + MAIN_ROW_FIELD_EQ(w_in_tag, static_cast(tag)))); - auto const& mem_a_row = trace.at(mem_a_idx); + auto const& mem_a_row = trace.at(mem_a_addr); EXPECT_THAT(mem_a_row, - AllOf(Field(&Row::avm_mem_tag_err, 0), - Field(&Row::avm_mem_r_in_tag, static_cast(tag)), - Field(&Row::avm_mem_tag, static_cast(tag)), - Field(&Row::avm_mem_sel_mov_a, 1), - Field(&Row::avm_mem_addr, indirect ? dir_src_offset : src_offset), - Field(&Row::avm_mem_val, val_ff), - Field(&Row::avm_mem_rw, 0), - Field(&Row::avm_mem_op_a, 1))); + AllOf(MEM_ROW_FIELD_EQ(tag_err, 0), + MEM_ROW_FIELD_EQ(r_in_tag, static_cast(tag)), + MEM_ROW_FIELD_EQ(tag, static_cast(tag)), + MEM_ROW_FIELD_EQ(sel_mov_ia_to_ic, 1), + MEM_ROW_FIELD_EQ(addr, indirect ? dir_src_offset : src_offset), + MEM_ROW_FIELD_EQ(val, val_ff), + MEM_ROW_FIELD_EQ(rw, 0), + MEM_ROW_FIELD_EQ(sel_op_a, 1))); - auto const& mem_c_row = trace.at(mem_c_idx); + auto const& mem_c_row = trace.at(mem_c_addr); EXPECT_THAT(mem_c_row, - AllOf(Field(&Row::avm_mem_tag_err, 0), - Field(&Row::avm_mem_w_in_tag, static_cast(tag)), - Field(&Row::avm_mem_tag, static_cast(tag)), - Field(&Row::avm_mem_addr, indirect ? dir_dst_offset : dst_offset), - Field(&Row::avm_mem_val, val_ff), - Field(&Row::avm_mem_op_c, 1))); + AllOf(MEM_ROW_FIELD_EQ(tag_err, 0), + MEM_ROW_FIELD_EQ(w_in_tag, static_cast(tag)), + MEM_ROW_FIELD_EQ(tag, static_cast(tag)), + MEM_ROW_FIELD_EQ(addr, indirect ? dir_dst_offset : dst_offset), + MEM_ROW_FIELD_EQ(val, val_ff), + MEM_ROW_FIELD_EQ(sel_op_c, 1))); if (indirect) { - auto const& mem_ind_a_row = trace.at(mem_ind_a_idx); + auto const& mem_ind_a_row = trace.at(mem_ind_a_addr); EXPECT_THAT(mem_ind_a_row, - AllOf(Field(&Row::avm_mem_tag_err, 0), - Field(&Row::avm_mem_r_in_tag, static_cast(AvmMemoryTag::U32)), - Field(&Row::avm_mem_tag, static_cast(AvmMemoryTag::U32)), - Field(&Row::avm_mem_addr, src_offset), - Field(&Row::avm_mem_val, dir_src_offset), - Field(&Row::avm_mem_ind_op_a, 1))); - - auto const& mem_ind_c_row = trace.at(mem_ind_c_idx); + AllOf(MEM_ROW_FIELD_EQ(tag_err, 0), + MEM_ROW_FIELD_EQ(r_in_tag, static_cast(AvmMemoryTag::U32)), + MEM_ROW_FIELD_EQ(tag, static_cast(AvmMemoryTag::U32)), + MEM_ROW_FIELD_EQ(addr, src_offset), + MEM_ROW_FIELD_EQ(val, dir_src_offset), + MEM_ROW_FIELD_EQ(sel_resolve_ind_addr_a, 1))); + + auto const& mem_ind_c_row = trace.at(mem_ind_c_addr); EXPECT_THAT(mem_ind_c_row, - AllOf(Field(&Row::avm_mem_tag_err, 0), - Field(&Row::avm_mem_r_in_tag, static_cast(AvmMemoryTag::U32)), - Field(&Row::avm_mem_tag, static_cast(AvmMemoryTag::U32)), - Field(&Row::avm_mem_addr, dst_offset), - Field(&Row::avm_mem_val, dir_dst_offset), - Field(&Row::avm_mem_ind_op_c, 1))); + AllOf(MEM_ROW_FIELD_EQ(tag_err, 0), + MEM_ROW_FIELD_EQ(r_in_tag, static_cast(AvmMemoryTag::U32)), + MEM_ROW_FIELD_EQ(tag, static_cast(AvmMemoryTag::U32)), + MEM_ROW_FIELD_EQ(addr, dst_offset), + MEM_ROW_FIELD_EQ(val, dir_dst_offset), + MEM_ROW_FIELD_EQ(sel_resolve_ind_addr_c, 1))); } - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } void common_cmov_trace_validate(bool indirect, @@ -252,82 +255,82 @@ class AvmMemOpcodeTests : public ::testing::Test { FF const& mov_val = mov_a ? a : b; FF const inv = mov_a ? d.invert() : 1; - EXPECT_THAT(trace.at(main_idx), - AllOf(Field("ia", &Row::avm_main_ia, a), - Field("ib", &Row::avm_main_ib, b), - Field("ic", &Row::avm_main_ic, mov_val), - Field("id", &Row::avm_main_id, d), - Field("op_a", &Row::avm_main_mem_op_a, 1), - Field("op_b", &Row::avm_main_mem_op_b, 1), - Field("op_c", &Row::avm_main_mem_op_c, 1), - Field("op_d", &Row::avm_main_mem_op_d, 1), - Field("rwa", &Row::avm_main_rwa, 0), - Field("rwb", &Row::avm_main_rwb, 0), - Field("rwc", &Row::avm_main_rwc, 1), - Field("rwd", &Row::avm_main_rwd, 0), - Field("mem_idx_a", &Row::avm_main_mem_idx_a, addr_a), - Field("mem_idx_b", &Row::avm_main_mem_idx_b, addr_b), - Field("mem_idx_c", &Row::avm_main_mem_idx_c, addr_c), - Field("mem_idx_d", &Row::avm_main_mem_idx_d, addr_d), - Field("ind_op_a", &Row::avm_main_ind_op_a, static_cast(indirect)), - Field("ind_op_b", &Row::avm_main_ind_op_b, static_cast(indirect)), - Field("ind_op_c", &Row::avm_main_ind_op_c, static_cast(indirect)), - Field("ind_op_d", &Row::avm_main_ind_op_d, static_cast(indirect)), - Field("sel_cmov", &Row::avm_main_sel_cmov, 1), - Field("sel_mov_a", &Row::avm_main_sel_mov_a, mov_a), - Field("sel_mov_b", &Row::avm_main_sel_mov_b, !mov_a), - Field("r_in_tag", &Row::avm_main_r_in_tag, static_cast(mov_tag)), - Field("w_in_tag", &Row::avm_main_w_in_tag, static_cast(mov_tag)), - Field("inv", &Row::avm_main_inv, inv))); - - EXPECT_THAT(trace.at(mem_a_idx), - AllOf(Field("r_in_tag", &Row::avm_mem_r_in_tag, static_cast(mov_tag)), - Field("w_in_tag", &Row::avm_mem_w_in_tag, static_cast(mov_tag)), - Field("tag", &Row::avm_mem_tag, static_cast(tag_a)), - Field("sel_mov_a", &Row::avm_mem_sel_mov_a, mov_a), - Field("mem_addr", &Row::avm_mem_addr, addr_a), - Field("val", &Row::avm_mem_val, a), - Field("rw", &Row::avm_mem_rw, 0), - Field("skip_check_tag", &Row::avm_mem_skip_check_tag, mov_a ? 0 : 1), - Field("op_a", &Row::avm_mem_op_a, 1), - Field("ind_op_a", &Row::avm_mem_ind_op_a, 0))); - - EXPECT_THAT(trace.at(mem_b_idx), - AllOf(Field("r_in_tag", &Row::avm_mem_r_in_tag, static_cast(mov_tag)), - Field("w_in_tag", &Row::avm_mem_w_in_tag, static_cast(mov_tag)), - Field("tag", &Row::avm_mem_tag, static_cast(tag_b)), - Field("tag_err", &Row::avm_mem_tag_err, 0), - Field("sel_mov_b", &Row::avm_mem_sel_mov_b, !mov_a), - Field("mem_addr", &Row::avm_mem_addr, addr_b), - Field("val", &Row::avm_mem_val, b), - Field("rw", &Row::avm_mem_rw, 0), - Field("skip_check_tag", &Row::avm_mem_skip_check_tag, mov_a ? 1 : 0), - Field("op_b", &Row::avm_mem_op_b, 1), - Field("ind_op_b", &Row::avm_mem_ind_op_b, 0))); - - EXPECT_THAT(trace.at(mem_c_idx), - AllOf(Field("r_in_tag", &Row::avm_mem_r_in_tag, static_cast(mov_tag)), - Field("w_in_tag", &Row::avm_mem_w_in_tag, static_cast(mov_tag)), - Field("tag", &Row::avm_mem_tag, static_cast(mov_tag)), - Field("tag_err", &Row::avm_mem_tag_err, 0), - Field("mem_addr", &Row::avm_mem_addr, addr_c), - Field("val", &Row::avm_mem_val, mov_a ? a : b), - Field("rw", &Row::avm_mem_rw, 1), - Field("skip_check_tag", &Row::avm_mem_skip_check_tag, 0), - Field("op_c", &Row::avm_mem_op_c, 1), - Field("ind_op_c", &Row::avm_mem_ind_op_c, 0))); - - EXPECT_THAT(trace.at(mem_d_idx), - AllOf(Field("r_in_tag", &Row::avm_mem_r_in_tag, static_cast(mov_tag)), - Field("w_in_tag", &Row::avm_mem_w_in_tag, static_cast(mov_tag)), - Field("tag", &Row::avm_mem_tag, static_cast(tag_d)), - Field("tag_err", &Row::avm_mem_tag_err, 0), - Field("mem_addr", &Row::avm_mem_addr, addr_d), - Field("val", &Row::avm_mem_val, d), - Field("rw", &Row::avm_mem_rw, 0), - Field("skip_check_tag", &Row::avm_mem_skip_check_tag, 1), - Field("op_d", &Row::avm_mem_op_d, 1), - Field("ind_op_d", &Row::avm_mem_ind_op_d, 0))); + EXPECT_THAT(trace.at(main_addr), + AllOf(MAIN_ROW_FIELD_EQ(ia, a), + MAIN_ROW_FIELD_EQ(ib, b), + MAIN_ROW_FIELD_EQ(ic, mov_val), + MAIN_ROW_FIELD_EQ(id, d), + MAIN_ROW_FIELD_EQ(sel_mem_op_a, 1), + MAIN_ROW_FIELD_EQ(sel_mem_op_b, 1), + MAIN_ROW_FIELD_EQ(sel_mem_op_c, 1), + MAIN_ROW_FIELD_EQ(sel_mem_op_d, 1), + MAIN_ROW_FIELD_EQ(rwa, 0), + MAIN_ROW_FIELD_EQ(rwb, 0), + MAIN_ROW_FIELD_EQ(rwc, 1), + MAIN_ROW_FIELD_EQ(rwd, 0), + MAIN_ROW_FIELD_EQ(mem_addr_a, addr_a), + MAIN_ROW_FIELD_EQ(mem_addr_b, addr_b), + MAIN_ROW_FIELD_EQ(mem_addr_c, addr_c), + MAIN_ROW_FIELD_EQ(mem_addr_d, addr_d), + MAIN_ROW_FIELD_EQ(sel_resolve_ind_addr_a, static_cast(indirect)), + MAIN_ROW_FIELD_EQ(sel_resolve_ind_addr_b, static_cast(indirect)), + MAIN_ROW_FIELD_EQ(sel_resolve_ind_addr_c, static_cast(indirect)), + MAIN_ROW_FIELD_EQ(sel_resolve_ind_addr_d, static_cast(indirect)), + MAIN_ROW_FIELD_EQ(sel_op_cmov, 1), + MAIN_ROW_FIELD_EQ(sel_mov_ia_to_ic, mov_a), + MAIN_ROW_FIELD_EQ(sel_mov_ib_to_ic, !mov_a), + MAIN_ROW_FIELD_EQ(r_in_tag, static_cast(mov_tag)), + MAIN_ROW_FIELD_EQ(w_in_tag, static_cast(mov_tag)), + MAIN_ROW_FIELD_EQ(inv, inv))); + + EXPECT_THAT(trace.at(mem_a_addr), + AllOf(MEM_ROW_FIELD_EQ(r_in_tag, static_cast(mov_tag)), + MEM_ROW_FIELD_EQ(w_in_tag, static_cast(mov_tag)), + MEM_ROW_FIELD_EQ(tag, static_cast(tag_a)), + MEM_ROW_FIELD_EQ(sel_mov_ia_to_ic, mov_a), + MEM_ROW_FIELD_EQ(addr, addr_a), + MEM_ROW_FIELD_EQ(val, a), + MEM_ROW_FIELD_EQ(rw, 0), + MEM_ROW_FIELD_EQ(skip_check_tag, mov_a ? 0 : 1), + MEM_ROW_FIELD_EQ(sel_op_a, 1), + MEM_ROW_FIELD_EQ(sel_resolve_ind_addr_a, 0))); + + EXPECT_THAT(trace.at(mem_b_addr), + AllOf(MEM_ROW_FIELD_EQ(r_in_tag, static_cast(mov_tag)), + MEM_ROW_FIELD_EQ(w_in_tag, static_cast(mov_tag)), + MEM_ROW_FIELD_EQ(tag, static_cast(tag_b)), + MEM_ROW_FIELD_EQ(tag_err, 0), + MEM_ROW_FIELD_EQ(sel_mov_ib_to_ic, !mov_a), + MEM_ROW_FIELD_EQ(addr, addr_b), + MEM_ROW_FIELD_EQ(val, b), + MEM_ROW_FIELD_EQ(rw, 0), + MEM_ROW_FIELD_EQ(skip_check_tag, mov_a ? 1 : 0), + MEM_ROW_FIELD_EQ(sel_op_b, 1), + MEM_ROW_FIELD_EQ(sel_resolve_ind_addr_b, 0))); + + EXPECT_THAT(trace.at(mem_c_addr), + AllOf(MEM_ROW_FIELD_EQ(r_in_tag, static_cast(mov_tag)), + MEM_ROW_FIELD_EQ(w_in_tag, static_cast(mov_tag)), + MEM_ROW_FIELD_EQ(tag, static_cast(mov_tag)), + MEM_ROW_FIELD_EQ(tag_err, 0), + MEM_ROW_FIELD_EQ(addr, addr_c), + MEM_ROW_FIELD_EQ(val, mov_a ? a : b), + MEM_ROW_FIELD_EQ(rw, 1), + MEM_ROW_FIELD_EQ(skip_check_tag, 0), + MEM_ROW_FIELD_EQ(sel_op_c, 1), + MEM_ROW_FIELD_EQ(sel_resolve_ind_addr_c, 0))); + + EXPECT_THAT(trace.at(mem_d_addr), + AllOf(MEM_ROW_FIELD_EQ(r_in_tag, static_cast(mov_tag)), + MEM_ROW_FIELD_EQ(w_in_tag, static_cast(mov_tag)), + MEM_ROW_FIELD_EQ(tag, static_cast(tag_d)), + MEM_ROW_FIELD_EQ(tag_err, 0), + MEM_ROW_FIELD_EQ(addr, addr_d), + MEM_ROW_FIELD_EQ(val, d), + MEM_ROW_FIELD_EQ(rw, 0), + MEM_ROW_FIELD_EQ(skip_check_tag, 1), + MEM_ROW_FIELD_EQ(sel_op_d, 1), + MEM_ROW_FIELD_EQ(sel_resolve_ind_addr_d, 0))); } }; @@ -393,12 +396,12 @@ TEST_F(AvmMemOpcodeTests, indirectMovInvalidAddressTag) compute_mov_indices(true); - EXPECT_EQ(trace.at(main_idx).avm_main_tag_err, 1); - EXPECT_THAT(trace.at(mem_ind_c_idx), - AllOf(Field(&Row::avm_mem_tag_err, 1), - Field(&Row::avm_mem_tag, static_cast(AvmMemoryTag::U128)), - Field(&Row::avm_mem_r_in_tag, static_cast(AvmMemoryTag::U32)), - Field(&Row::avm_mem_ind_op_c, 1))); + EXPECT_EQ(trace.at(main_addr).main_tag_err, 1); + EXPECT_THAT(trace.at(mem_ind_c_addr), + AllOf(MEM_ROW_FIELD_EQ(tag_err, 1), + MEM_ROW_FIELD_EQ(tag, static_cast(AvmMemoryTag::U128)), + MEM_ROW_FIELD_EQ(r_in_tag, static_cast(AvmMemoryTag::U32)), + MEM_ROW_FIELD_EQ(sel_resolve_ind_addr_c, 1))); validate_trace(std::move(trace), public_inputs, true); } @@ -526,21 +529,21 @@ TEST_F(AvmMemOpcodeTests, directSet) auto const& row = trace.at(1); EXPECT_THAT(row, - AllOf(Field(&Row::avm_main_tag_err, 0), - Field(&Row::avm_main_ic, 5683), - Field(&Row::avm_main_mem_idx_c, 99), - Field(&Row::avm_main_mem_op_c, 1), - Field(&Row::avm_main_rwc, 1), - Field(&Row::avm_main_ind_op_c, 0))); - - EXPECT_THAT(trace.at(mem_c_idx), - AllOf(Field(&Row::avm_mem_val, 5683), - Field(&Row::avm_mem_addr, 99), - Field(&Row::avm_mem_op_c, 1), - Field(&Row::avm_mem_rw, 1), - Field(&Row::avm_mem_ind_op_c, 0))); - - validate_trace(std::move(trace)); + AllOf(MAIN_ROW_FIELD_EQ(tag_err, 0), + MAIN_ROW_FIELD_EQ(ic, 5683), + MAIN_ROW_FIELD_EQ(mem_addr_c, 99), + MAIN_ROW_FIELD_EQ(sel_mem_op_c, 1), + MAIN_ROW_FIELD_EQ(rwc, 1), + MAIN_ROW_FIELD_EQ(sel_resolve_ind_addr_c, 0))); + + EXPECT_THAT(trace.at(mem_c_addr), + AllOf(MEM_ROW_FIELD_EQ(val, 5683), + MEM_ROW_FIELD_EQ(addr, 99), + MEM_ROW_FIELD_EQ(sel_op_c, 1), + MEM_ROW_FIELD_EQ(rw, 1), + MEM_ROW_FIELD_EQ(sel_resolve_ind_addr_c, 0))); + + validate_trace(std::move(trace), public_inputs); } TEST_F(AvmMemOpcodeTests, indirectSet) @@ -554,33 +557,33 @@ TEST_F(AvmMemOpcodeTests, indirectSet) auto const& row = trace.at(2); EXPECT_THAT(row, - AllOf(Field(&Row::avm_main_tag_err, 0), - Field(&Row::avm_main_ic, 1979), - Field(&Row::avm_main_mem_idx_c, 100), - Field(&Row::avm_main_mem_op_c, 1), - Field(&Row::avm_main_rwc, 1), - Field(&Row::avm_main_ind_op_c, 1), - Field(&Row::avm_main_ind_c, 10))); - - EXPECT_THAT(trace.at(mem_c_idx), - AllOf(Field(&Row::avm_mem_val, 1979), - Field(&Row::avm_mem_addr, 100), - Field(&Row::avm_mem_op_c, 1), - Field(&Row::avm_mem_rw, 1), - Field(&Row::avm_mem_ind_op_c, 0), - Field(&Row::avm_mem_w_in_tag, static_cast(AvmMemoryTag::U64)), - Field(&Row::avm_mem_tag, static_cast(AvmMemoryTag::U64)))); - - EXPECT_THAT(trace.at(mem_ind_c_idx), - AllOf(Field(&Row::avm_mem_val, 100), - Field(&Row::avm_mem_addr, 10), - Field(&Row::avm_mem_op_c, 0), - Field(&Row::avm_mem_rw, 0), - Field(&Row::avm_mem_ind_op_c, 1), - Field(&Row::avm_mem_r_in_tag, static_cast(AvmMemoryTag::U32)), - Field(&Row::avm_mem_tag, static_cast(AvmMemoryTag::U32)))); - - validate_trace(std::move(trace)); + AllOf(MAIN_ROW_FIELD_EQ(tag_err, 0), + MAIN_ROW_FIELD_EQ(ic, 1979), + MAIN_ROW_FIELD_EQ(mem_addr_c, 100), + MAIN_ROW_FIELD_EQ(sel_mem_op_c, 1), + MAIN_ROW_FIELD_EQ(rwc, 1), + MAIN_ROW_FIELD_EQ(sel_resolve_ind_addr_c, 1), + MAIN_ROW_FIELD_EQ(ind_addr_c, 10))); + + EXPECT_THAT(trace.at(mem_c_addr), + AllOf(MEM_ROW_FIELD_EQ(val, 1979), + MEM_ROW_FIELD_EQ(addr, 100), + MEM_ROW_FIELD_EQ(sel_op_c, 1), + MEM_ROW_FIELD_EQ(rw, 1), + MEM_ROW_FIELD_EQ(sel_resolve_ind_addr_c, 0), + MEM_ROW_FIELD_EQ(w_in_tag, static_cast(AvmMemoryTag::U64)), + MEM_ROW_FIELD_EQ(tag, static_cast(AvmMemoryTag::U64)))); + + EXPECT_THAT(trace.at(mem_ind_c_addr), + AllOf(MEM_ROW_FIELD_EQ(val, 100), + MEM_ROW_FIELD_EQ(addr, 10), + MEM_ROW_FIELD_EQ(sel_op_c, 0), + MEM_ROW_FIELD_EQ(rw, 0), + MEM_ROW_FIELD_EQ(sel_resolve_ind_addr_c, 1), + MEM_ROW_FIELD_EQ(r_in_tag, static_cast(AvmMemoryTag::U32)), + MEM_ROW_FIELD_EQ(tag, static_cast(AvmMemoryTag::U32)))); + + validate_trace(std::move(trace), public_inputs); } TEST_F(AvmMemOpcodeTests, indirectSetWrongTag) @@ -594,23 +597,23 @@ TEST_F(AvmMemOpcodeTests, indirectSetWrongTag) auto const& row = trace.at(2); EXPECT_THAT(row, - AllOf(Field(&Row::avm_main_tag_err, 1), - Field(&Row::avm_main_mem_op_c, 1), - Field(&Row::avm_main_rwc, 1), - Field(&Row::avm_main_ind_op_c, 1), - Field(&Row::avm_main_ind_c, 10))); - - EXPECT_THAT(trace.at(mem_ind_c_idx), - AllOf(Field(&Row::avm_mem_val, 100), - Field(&Row::avm_mem_addr, 10), - Field(&Row::avm_mem_op_c, 0), - Field(&Row::avm_mem_rw, 0), - Field(&Row::avm_mem_ind_op_c, 1), - Field(&Row::avm_mem_r_in_tag, static_cast(AvmMemoryTag::U32)), - Field(&Row::avm_mem_tag, static_cast(AvmMemoryTag::U8)), - Field(&Row::avm_mem_tag_err, 1))); - - validate_trace(std::move(trace)); + AllOf(MAIN_ROW_FIELD_EQ(tag_err, 1), + MAIN_ROW_FIELD_EQ(sel_mem_op_c, 1), + MAIN_ROW_FIELD_EQ(rwc, 1), + MAIN_ROW_FIELD_EQ(sel_resolve_ind_addr_c, 1), + MAIN_ROW_FIELD_EQ(ind_addr_c, 10))); + + EXPECT_THAT(trace.at(mem_ind_c_addr), + AllOf(MEM_ROW_FIELD_EQ(val, 100), + MEM_ROW_FIELD_EQ(addr, 10), + MEM_ROW_FIELD_EQ(sel_op_c, 0), + MEM_ROW_FIELD_EQ(rw, 0), + MEM_ROW_FIELD_EQ(sel_resolve_ind_addr_c, 1), + MEM_ROW_FIELD_EQ(r_in_tag, static_cast(AvmMemoryTag::U32)), + MEM_ROW_FIELD_EQ(tag, static_cast(AvmMemoryTag::U8)), + MEM_ROW_FIELD_EQ(tag_err, 1))); + + validate_trace(std::move(trace), public_inputs); } /****************************************************************************** @@ -627,7 +630,7 @@ TEST_F(AvmMemOpcodeNegativeTests, movWrongOutputErrorTag) { build_mov_trace(false, 234, 0, 1, AvmMemoryTag::U8); compute_mov_indices(false); - trace.at(main_idx).avm_main_tag_err = 1; + trace.at(main_addr).main_tag_err = 1; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "INCL_MEM_TAG_ERR"); } @@ -636,7 +639,7 @@ TEST_F(AvmMemOpcodeNegativeTests, movWrongOutputValue) { build_mov_trace(false, 234, 0, 1, AvmMemoryTag::U8); compute_mov_indices(false); - trace.at(main_idx).avm_main_ic = 233; + trace.at(main_addr).main_ic = 233; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "MOV_SAME_VALUE_A"); } @@ -645,7 +648,7 @@ TEST_F(AvmMemOpcodeNegativeTests, indMovWrongOutputValue) { build_mov_trace(true, 8732, 23, 24, AvmMemoryTag::U16, 432, 876); compute_mov_indices(true); - trace.at(main_idx).avm_main_ic = 8733; + trace.at(main_addr).main_ic = 8733; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "MOV_SAME_VALUE_A"); } @@ -665,14 +668,14 @@ TEST_F(AvmMemOpcodeNegativeTests, movWrongOutputTagLoadIa) auto trace_tmp = trace; - trace.at(mem_a_idx).avm_mem_r_in_tag = tag_u64; - trace.at(mem_a_idx).avm_mem_tag_err = 1; - trace.at(mem_a_idx).avm_mem_one_min_inv = one_min_inverse_diff; - trace.at(mem_c_idx).avm_mem_tag = tag_u64; - trace.at(mem_c_idx).avm_mem_w_in_tag = tag_u64; - trace.at(main_idx).avm_main_r_in_tag = tag_u64; - trace.at(main_idx).avm_main_w_in_tag = tag_u64; - trace.at(main_idx).avm_main_tag_err = 1; + trace.at(mem_a_addr).mem_r_in_tag = tag_u64; + trace.at(mem_a_addr).mem_tag_err = 1; + trace.at(mem_a_addr).mem_one_min_inv = one_min_inverse_diff; + trace.at(mem_c_addr).mem_tag = tag_u64; + trace.at(mem_c_addr).mem_w_in_tag = tag_u64; + trace.at(main_addr).main_r_in_tag = tag_u64; + trace.at(main_addr).main_w_in_tag = tag_u64; + trace.at(main_addr).main_tag_err = 1; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "MOV_SAME_TAG"); } @@ -688,17 +691,17 @@ TEST_F(AvmMemOpcodeNegativeTests, movWrongOutputTagDisabledSelector) build_mov_trace(false, 234, 0, 1, AvmMemoryTag::U8); compute_mov_indices(false); - trace.at(mem_a_idx).avm_mem_r_in_tag = tag_u64; - trace.at(mem_a_idx).avm_mem_w_in_tag = tag_u64; - trace.at(mem_a_idx).avm_mem_tag_err = 1; - trace.at(mem_a_idx).avm_mem_one_min_inv = one_min_inverse_diff; - trace.at(mem_a_idx).avm_mem_sel_mov_a = 0; - trace.at(mem_c_idx).avm_mem_tag = tag_u64; - trace.at(mem_c_idx).avm_mem_r_in_tag = tag_u64; - trace.at(mem_c_idx).avm_mem_w_in_tag = tag_u64; - trace.at(main_idx).avm_main_r_in_tag = tag_u64; - trace.at(main_idx).avm_main_w_in_tag = tag_u64; - trace.at(main_idx).avm_main_tag_err = 1; + trace.at(mem_a_addr).mem_r_in_tag = tag_u64; + trace.at(mem_a_addr).mem_w_in_tag = tag_u64; + trace.at(mem_a_addr).mem_tag_err = 1; + trace.at(mem_a_addr).mem_one_min_inv = one_min_inverse_diff; + trace.at(mem_a_addr).mem_sel_mov_ia_to_ic = 0; + trace.at(mem_c_addr).mem_tag = tag_u64; + trace.at(mem_c_addr).mem_r_in_tag = tag_u64; + trace.at(mem_c_addr).mem_w_in_tag = tag_u64; + trace.at(main_addr).main_r_in_tag = tag_u64; + trace.at(main_addr).main_w_in_tag = tag_u64; + trace.at(main_addr).main_tag_err = 1; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_A"); } @@ -712,10 +715,10 @@ TEST_F(AvmMemOpcodeNegativeTests, movWrongOutputTagInMainTrace) build_mov_trace(false, 234, 0, 1, AvmMemoryTag::U8); compute_mov_indices(false); - trace.at(mem_c_idx).avm_mem_tag = tag_u64; - trace.at(mem_c_idx).avm_mem_w_in_tag = tag_u64; - trace.at(main_idx).avm_main_w_in_tag = tag_u64; - trace.at(main_idx).avm_main_tag_err = 1; + trace.at(mem_c_addr).mem_tag = tag_u64; + trace.at(mem_c_addr).mem_w_in_tag = tag_u64; + trace.at(main_addr).main_w_in_tag = tag_u64; + trace.at(main_addr).main_tag_err = 1; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "MOV_MAIN_SAME_TAG"); } @@ -728,8 +731,8 @@ TEST_F(AvmMemOpcodeNegativeTests, movWrongOutputTagMainTraceRead) build_mov_trace(false, 234, 0, 1, AvmMemoryTag::U8); compute_mov_indices(false); - trace.at(mem_c_idx).avm_mem_tag = tag_u64; - trace.at(mem_c_idx).avm_mem_w_in_tag = tag_u64; + trace.at(mem_c_addr).mem_tag = tag_u64; + trace.at(mem_c_addr).mem_w_in_tag = tag_u64; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_C"); } @@ -741,7 +744,7 @@ TEST_F(AvmMemOpcodeNegativeTests, cmovBInsteadA) { build_cmov_trace_neg_test(true); - trace.at(main_idx).avm_main_ic = 1980; + trace.at(main_addr).main_ic = 1980; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "MOV_SAME_VALUE_A"); } @@ -749,7 +752,7 @@ TEST_F(AvmMemOpcodeNegativeTests, cmovAInsteadB) { build_cmov_trace_neg_test(false); - trace.at(main_idx).avm_main_ic = 1979; + trace.at(main_addr).main_ic = 1979; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "MOV_SAME_VALUE_B"); } @@ -757,9 +760,9 @@ TEST_F(AvmMemOpcodeNegativeTests, cmovAChangeTag) { build_cmov_trace_neg_test(true); - trace.at(mem_c_idx).avm_mem_tag = static_cast(AvmMemoryTag::U32); - trace.at(mem_c_idx).avm_mem_w_in_tag = static_cast(AvmMemoryTag::U32); - trace.at(main_idx).avm_main_w_in_tag = static_cast(AvmMemoryTag::U32); + trace.at(mem_c_addr).mem_tag = static_cast(AvmMemoryTag::U32); + trace.at(mem_c_addr).mem_w_in_tag = static_cast(AvmMemoryTag::U32); + trace.at(main_addr).main_w_in_tag = static_cast(AvmMemoryTag::U32); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "MOV_MAIN_SAME_TAG"); } @@ -768,7 +771,7 @@ TEST_F(AvmMemOpcodeNegativeTests, cmovASkipCheckAbuse) { build_cmov_trace_neg_test(true); - trace.at(mem_a_idx).avm_mem_skip_check_tag = 1; + trace.at(mem_a_addr).mem_skip_check_tag = 1; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "SKIP_CHECK_TAG"); } @@ -777,8 +780,8 @@ TEST_F(AvmMemOpcodeNegativeTests, cmovASkipCheckAbuseDisableSelMovA) { build_cmov_trace_neg_test(true); - trace.at(mem_a_idx).avm_mem_skip_check_tag = 1; - trace.at(mem_a_idx).avm_mem_sel_mov_a = 0; + trace.at(mem_a_addr).mem_skip_check_tag = 1; + trace.at(mem_a_addr).mem_sel_mov_ia_to_ic = 0; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_A"); } @@ -787,8 +790,8 @@ TEST_F(AvmMemOpcodeNegativeTests, cmovBSkipCheckAbuseDisableSelMovB) { build_cmov_trace_neg_test(false); - trace.at(mem_b_idx).avm_mem_skip_check_tag = 1; - trace.at(mem_b_idx).avm_mem_sel_mov_b = 0; + trace.at(mem_b_addr).mem_skip_check_tag = 1; + trace.at(mem_b_addr).mem_sel_mov_ib_to_ic = 0; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "PERM_MAIN_MEM_B"); } diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp index 926ce9bc290..38428559194 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/avm_memory.test.cpp @@ -47,37 +47,37 @@ TEST_F(AvmMemoryTests, mismatchedTagAddOperation) auto trace = trace_builder.finalize(); // Find the first row enabling the addition selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_add == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_add == FF(1); }); EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avm_main_ia, FF(98)); - EXPECT_EQ(row->avm_main_ib, FF(12)); - EXPECT_EQ(row->avm_main_ic, FF(0)); + EXPECT_EQ(row->main_ia, FF(98)); + EXPECT_EQ(row->main_ib, FF(12)); + EXPECT_EQ(row->main_ic, FF(0)); - auto clk = row->avm_main_clk; + auto clk = row->main_clk; // Find the memory trace position corresponding to the load sub-operation of register ia. row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_A; + return r.mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_A; }); EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avm_mem_tag_err, FF(1)); // Error is raised - EXPECT_EQ(row->avm_mem_r_in_tag, FF(static_cast(AvmMemoryTag::U8))); - EXPECT_EQ(row->avm_mem_tag, FF(static_cast(AvmMemoryTag::FF))); + EXPECT_EQ(row->mem_tag_err, FF(1)); // Error is raised + EXPECT_EQ(row->mem_r_in_tag, FF(static_cast(AvmMemoryTag::U8))); + EXPECT_EQ(row->mem_tag, FF(static_cast(AvmMemoryTag::FF))); // Find the memory trace position corresponding to the add sub-operation of register ib. row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_B; + return r.mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_B; }); EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avm_mem_tag_err, FF(1)); // Error is raised - EXPECT_EQ(row->avm_mem_r_in_tag, FF(static_cast(AvmMemoryTag::U8))); - EXPECT_EQ(row->avm_mem_tag, FF(static_cast(AvmMemoryTag::FF))); + EXPECT_EQ(row->mem_tag_err, FF(1)); // Error is raised + EXPECT_EQ(row->mem_r_in_tag, FF(static_cast(AvmMemoryTag::U8))); + EXPECT_EQ(row->mem_tag, FF(static_cast(AvmMemoryTag::FF))); validate_trace(std::move(trace), public_inputs, true); } @@ -94,35 +94,35 @@ TEST_F(AvmMemoryTests, mismatchedTagEqOperation) auto trace = trace_builder.finalize(); // Find the first row enabling the equality selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_eq == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_eq == FF(1); }); EXPECT_TRUE(row != trace.end()); - auto clk = row->avm_main_clk; + auto clk = row->main_clk; // Find the memory trace position corresponding to the load sub-operation of register ia. row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_A; + return r.mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_A; }); EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avm_mem_tag_err, FF(0)); // Error is NOT raised - EXPECT_EQ(row->avm_mem_r_in_tag, FF(static_cast(AvmMemoryTag::U32))); - EXPECT_EQ(row->avm_mem_tag, FF(static_cast(AvmMemoryTag::U32))); + EXPECT_EQ(row->mem_tag_err, FF(0)); // Error is NOT raised + EXPECT_EQ(row->mem_r_in_tag, FF(static_cast(AvmMemoryTag::U32))); + EXPECT_EQ(row->mem_tag, FF(static_cast(AvmMemoryTag::U32))); // Find the memory trace position corresponding to the load sub-operation of register ib. row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_B; + return r.mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_B; }); EXPECT_TRUE(row != trace.end()); - EXPECT_EQ(row->avm_mem_tag_err, FF(1)); // Error is raised - EXPECT_EQ(row->avm_mem_r_in_tag, FF(static_cast(AvmMemoryTag::U32))); - EXPECT_EQ(row->avm_mem_tag, FF(static_cast(AvmMemoryTag::U16))); + EXPECT_EQ(row->mem_tag_err, FF(1)); // Error is raised + EXPECT_EQ(row->mem_r_in_tag, FF(static_cast(AvmMemoryTag::U32))); + EXPECT_EQ(row->mem_tag, FF(static_cast(AvmMemoryTag::U16))); - validate_trace(std::move(trace)); + validate_trace(std::move(trace), public_inputs); } // Testing violation that m_lastAccess is a delimiter for two different addresses @@ -138,20 +138,20 @@ TEST_F(AvmMemoryTests, mLastAccessViolation) auto trace = trace_builder.finalize(); // Find the row with subtraction operation - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sub == FF(1); }); EXPECT_TRUE(row != trace.end()); - auto clk = row->avm_main_clk; + auto clk = row->main_clk; // Find the row for memory trace with last memory entry for address 1 (read for subtraction) row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_addr == FF(1) && - r.avm_mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_A; + return r.mem_addr == FF(1) && + r.mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_A; }); EXPECT_TRUE(row != trace.end()); - row->avm_mem_lastAccess = FF(0); + row->mem_lastAccess = FF(0); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "MEM_LAST_ACCESS_DELIMITER"); } @@ -169,20 +169,20 @@ TEST_F(AvmMemoryTests, readWriteConsistencyValViolation) auto trace = trace_builder.finalize(); // Find the row with multiplication operation - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_mul == FF(1); }); EXPECT_TRUE(row != trace.end()); - auto clk = row->avm_main_clk + 1; // return operation is just after the multiplication + auto clk = row->main_clk + 1; // return operation is just after the multiplication // Find the row for memory trace with last memory entry for address 2 (read for multiplication) row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_addr == FF(2) && - r.avm_mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_A; + return r.mem_addr == FF(2) && + r.mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_A; }); EXPECT_TRUE(row != trace.end()); - row->avm_mem_val = FF(35); + row->mem_val = FF(35); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "MEM_READ_WRITE_VAL_CONSISTENCY"); } @@ -199,20 +199,20 @@ TEST_F(AvmMemoryTests, readWriteConsistencyTagViolation) auto trace = trace_builder.finalize(); // Find the row with multiplication operation - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_mul == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_mul == FF(1); }); EXPECT_TRUE(row != trace.end()); - auto clk = row->avm_main_clk + 1; // return operation is just after the multiplication + auto clk = row->main_clk + 1; // return operation is just after the multiplication // Find the row for memory trace with last memory entry for address 2 (read for multiplication) row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_addr == FF(2) && - r.avm_mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_A; + return r.mem_addr == FF(2) && + r.mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_A; }); EXPECT_TRUE(row != trace.end()); - row->avm_mem_tag = static_cast(AvmMemoryTag::U16); + row->mem_tag = static_cast(AvmMemoryTag::U16); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "MEM_READ_WRITE_TAG_CONSISTENCY"); } @@ -223,7 +223,7 @@ TEST_F(AvmMemoryTests, readUninitializedMemoryViolation) trace_builder.return_op(0, 1, 1); // Return single memory word at position 1 auto trace = trace_builder.finalize(); - trace[1].avm_mem_val = 9; + trace[1].mem_val = 9; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "MEM_ZERO_INIT"); } @@ -239,25 +239,25 @@ TEST_F(AvmMemoryTests, mismatchedTagErrorViolation) auto trace = trace_builder.finalize(); // Find the first row enabling the subtraction selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_sub == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_sub == FF(1); }); EXPECT_TRUE(row != trace.end()); - auto clk = row->avm_main_clk; + auto clk = row->main_clk; // Find the memory trace position corresponding to the subtraction sub-operation of register ia. row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_A; + return r.mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_A; }); - row->avm_mem_tag_err = FF(0); + row->mem_tag_err = FF(0); auto index = static_cast(row - trace.begin()); auto trace2 = trace; EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "MEM_IN_TAG_CONSISTENCY_1"); // More sophisticated attempt by adapting witness "on_min_inv" to make pass the above constraint - trace2[index].avm_mem_one_min_inv = FF(1); + trace2[index].mem_one_min_inv = FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace2)), "MEM_IN_TAG_CONSISTENCY_2"); } @@ -273,18 +273,18 @@ TEST_F(AvmMemoryTests, consistentTagNoErrorViolation) auto trace = trace_builder.finalize(); // Find the first row enabling the fdiv selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fdiv == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fdiv == FF(1); }); EXPECT_TRUE(row != trace.end()); - auto clk = row->avm_main_clk; + auto clk = row->main_clk; // Find the memory trace position corresponding to the fdiv sub-operation of register ia. row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_A; + return r.mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_LOAD_A; }); - row->avm_mem_tag_err = FF(1); + row->mem_tag_err = FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "MEM_IN_TAG_CONSISTENCY_1"); } @@ -299,19 +299,19 @@ TEST_F(AvmMemoryTests, noErrorTagWriteViolation) auto trace = trace_builder.finalize(); // Find the first row enabling the fdiv selector - auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.avm_main_sel_op_fdiv == FF(1); }); + auto row = std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_fdiv == FF(1); }); ASSERT_TRUE(row != trace.end()); - auto clk = row->avm_main_clk; + auto clk = row->main_clk; // Find the memory trace position corresponding to the fdiv sub-operation of register ic. row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { - return r.avm_mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_STORE_C; + return r.mem_tsp == FF(AvmMemTraceBuilder::NUM_SUB_CLK) * clk + AvmMemTraceBuilder::SUB_CLK_STORE_C; }); ASSERT_TRUE(row != trace.end()); - row->avm_mem_tag_err = FF(1); + row->mem_tag_err = FF(1); EXPECT_THROW_WITH_MESSAGE(validate_trace_check_circuit(std::move(trace)), "NO_TAG_ERR_WRITE"); } diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp index 46cd2d48aa3..8d31f30ce9a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.cpp @@ -73,66 +73,66 @@ void mutate_ic_in_trace(std::vector& trace, std::function&& sele EXPECT_TRUE(row != trace.end()); // Mutate the correct result in the main trace - row->avm_main_ic = newValue; + row->main_ic = newValue; // Optionally mutate the corresponding ic value in alu if (alu) { - auto const clk = row->avm_main_clk; + auto const clk = row->main_clk; // Find the relevant alu trace entry. - auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.avm_alu_clk == clk; }); + auto alu_row = std::ranges::find_if(trace.begin(), trace.end(), [clk](Row r) { return r.alu_clk == clk; }); EXPECT_TRUE(alu_row != trace.end()); - alu_row->avm_alu_ic = newValue; + alu_row->alu_ic = newValue; } // Adapt the memory trace to be consistent with the wrong result - auto const clk = row->avm_main_clk; - auto const addr = row->avm_main_mem_idx_c; + auto const clk = row->main_clk; + auto const addr = row->main_mem_addr_c; // Find the relevant memory trace entry. auto mem_row = std::ranges::find_if( - trace.begin(), trace.end(), [clk, addr](Row r) { return r.avm_mem_clk == clk && r.avm_mem_addr == addr; }); + trace.begin(), trace.end(), [clk, addr](Row r) { return r.mem_clk == clk && r.mem_addr == addr; }); EXPECT_TRUE(mem_row != trace.end()); - mem_row->avm_mem_val = newValue; + mem_row->mem_val = newValue; }; // TODO: Should be a cleaner way to do this void update_slice_registers(Row& row, uint256_t a) { - row.avm_alu_u8_r0 = static_cast(a); + row.alu_u8_r0 = static_cast(a); a >>= 8; - row.avm_alu_u8_r1 = static_cast(a); + row.alu_u8_r1 = static_cast(a); a >>= 8; - row.avm_alu_u16_r0 = static_cast(a); + row.alu_u16_r0 = static_cast(a); a >>= 16; - row.avm_alu_u16_r1 = static_cast(a); + row.alu_u16_r1 = static_cast(a); a >>= 16; - row.avm_alu_u16_r2 = static_cast(a); + row.alu_u16_r2 = static_cast(a); a >>= 16; - row.avm_alu_u16_r3 = static_cast(a); + row.alu_u16_r3 = static_cast(a); a >>= 16; - row.avm_alu_u16_r4 = static_cast(a); + row.alu_u16_r4 = static_cast(a); a >>= 16; - row.avm_alu_u16_r5 = static_cast(a); + row.alu_u16_r5 = static_cast(a); a >>= 16; - row.avm_alu_u16_r6 = static_cast(a); + row.alu_u16_r6 = static_cast(a); a >>= 16; - row.avm_alu_u16_r7 = static_cast(a); + row.alu_u16_r7 = static_cast(a); a >>= 16; - row.avm_alu_u16_r8 = static_cast(a); + row.alu_u16_r8 = static_cast(a); a >>= 16; - row.avm_alu_u16_r9 = static_cast(a); + row.alu_u16_r9 = static_cast(a); a >>= 16; - row.avm_alu_u16_r10 = static_cast(a); + row.alu_u16_r10 = static_cast(a); a >>= 16; - row.avm_alu_u16_r11 = static_cast(a); + row.alu_u16_r11 = static_cast(a); a >>= 16; - row.avm_alu_u16_r12 = static_cast(a); + row.alu_u16_r12 = static_cast(a); a >>= 16; - row.avm_alu_u16_r13 = static_cast(a); + row.alu_u16_r13 = static_cast(a); a >>= 16; - row.avm_alu_u16_r14 = static_cast(a); + row.alu_u16_r14 = static_cast(a); } // TODO: There has to be a better way to do. diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp index 6c8aa4fd068..c3c665f3490 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp @@ -2,6 +2,7 @@ #include "barretenberg/vm/avm_trace/avm_common.hpp" #include "barretenberg/vm/avm_trace/avm_trace.hpp" +#include "gmock/gmock.h" #include #define EXPECT_THROW_WITH_MESSAGE(code, expectedMessage) \ @@ -10,8 +11,11 @@ FAIL() << "An exception was expected"; \ } catch (const std::exception& e) { \ std::string message = e.what(); \ - EXPECT_TRUE(message.find(expectedMessage) != std::string::npos); \ + EXPECT_THAT(message, ::testing::HasSubstr(expectedMessage)); \ } + +#define MAIN_ROW_FIELD_EQ(field_name, expression) Field(#field_name, &Row::main_##field_name, expression) + namespace tests_avm { using Flavor = bb::AvmFlavor; @@ -21,16 +25,13 @@ using ThreeOpParam = std::array; using ThreeOpParamRow = std::tuple; using VmPublicInputs = bb::avm_trace::VmPublicInputs; -// To toggle all relevant unit tests with proving, set the env variable "AVM_TESTS_ENABLE_PROVING". -static const bool ENABLE_PROVING = std::getenv("AVM_TESTS_ENABLE_PROVING") != nullptr; - // If the test is expecting a relation to fail, then use validate_trace_check_circuit. // Otherwise, use validate_trace with a single argument. If the proving needs to be // enabled all the time in a given test, use validate_trace with setting with_proof = true. void validate_trace_check_circuit(std::vector&& trace, VmPublicInputs public_inputs = {}); void validate_trace(std::vector&& trace, VmPublicInputs const& public_inputs = {}, - bool with_proof = ENABLE_PROVING); + bool with_proof = bb::avm_trace::ENABLE_PROVING); void mutate_ic_in_trace(std::vector& trace, std::function&& selectRow, FF const& newValue, diff --git a/barretenberg/ts/CHANGELOG.md b/barretenberg/ts/CHANGELOG.md index b695c13fdc2..b546c5f69fe 100644 --- a/barretenberg/ts/CHANGELOG.md +++ b/barretenberg/ts/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [0.43.0](https://github.com/AztecProtocol/aztec-packages/compare/barretenberg.js-v0.42.0...barretenberg.js-v0.43.0) (2024-06-18) + + +### Miscellaneous + +* **barretenberg.js:** Synchronize aztec-packages versions + ## [0.42.0](https://github.com/AztecProtocol/aztec-packages/compare/barretenberg.js-v0.41.0...barretenberg.js-v0.42.0) (2024-06-04) diff --git a/barretenberg/ts/package.json b/barretenberg/ts/package.json index adbb6c9c406..77f78d446a8 100644 --- a/barretenberg/ts/package.json +++ b/barretenberg/ts/package.json @@ -1,6 +1,6 @@ { "name": "@aztec/bb.js", - "version": "0.42.0", + "version": "0.43.0", "homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/barretenberg/ts", "license": "MIT", "type": "module", diff --git a/build-system/scripts/deploy_terraform b/build-system/scripts/deploy_terraform index 5418073ba28..5312bdec1d7 100755 --- a/build-system/scripts/deploy_terraform +++ b/build-system/scripts/deploy_terraform @@ -36,6 +36,8 @@ export TF_VAR_CHAIN_ID=$CHAIN_ID if [ -n "$REPOSITORY" ]; then BACKEND_CONFIG=-backend-config="key=$DEPLOY_TAG/$REPOSITORY" echo "Using backend key $DEPLOY_TAG/$REPOSITORY" +else + BACKEND_CONFIG="" fi terraform init -input=false $BACKEND_CONFIG diff --git a/build_manifest.yml b/build_manifest.yml index e0f6d26397e..b26e4e84d96 100644 --- a/build_manifest.yml +++ b/build_manifest.yml @@ -50,6 +50,7 @@ avm-transpiler: - ^noir/ dependencies: - noir + multiarch: host aztec-nargo: buildDir: . @@ -61,6 +62,7 @@ aztec-nargo: dependencies: - avm-transpiler - noir + multiarch: buildx # Compiles all aztec noir projects using nargo and the avm-transpiler. noir-projects: @@ -69,6 +71,15 @@ noir-projects: - noir - avm-transpiler +# Compiles all aztec noir projects using nargo and the avm-transpiler, then tests them using the TXE. +noir-projects-tests: + buildDir: noir-projects + dockerfile: Dockerfile.test + dependencies: + - noir + - avm-transpiler + - yarn-project + # Uses nargo to compile all the noir test programs, used to test bb and bb.js. noir-compile-acir-tests: buildDir: noir/noir-repo/test_programs diff --git a/cspell.json b/cspell.json index de8ab29d0db..78f4bd23c72 100644 --- a/cspell.json +++ b/cspell.json @@ -120,6 +120,8 @@ "initialise", "interruptible", "isequal", + "ivpk", + "ivsk", "jsons", "Kademlia", "keccak", @@ -170,6 +172,8 @@ "otterscan", "outdir", "overlayfs", + "ovpk", + "ovsk", "pako", "Palla", "parallelizable", diff --git a/docs/docs/aztec/concepts/accounts/authwit.md b/docs/docs/aztec/concepts/accounts/authwit.md index a1b64fd135f..d416abfd4ed 100644 --- a/docs/docs/aztec/concepts/accounts/authwit.md +++ b/docs/docs/aztec/concepts/accounts/authwit.md @@ -138,25 +138,30 @@ The above flow could be re-entered at token transfer. It is mainly for show to i ### What about public -As noted earlier, we could use the ERC20 standard for public. But this seems like a waste when we have the ability to try righting some wrongs. Instead, we can expand our AuthWit scheme to also work in public. This is actually quite simple, instead of asking an oracle (which we can't do as easily because not private execution) we can just store the AuthWit in the account contract, and look it up when we need it. While this needs the storage to be updated ahead of time, we can quite easily do so by batching the AuthWit updates with the interaction - a benefit of Account Contracts. +As noted earlier, we could use the ERC20 standard for public. But this seems like a waste when we have the ability to try righting some wrongs. Instead, we can expand our AuthWit scheme to also work in public. This is actually quite simple, instead of asking an oracle (which we can't do as easily because not private execution) we can just store the AuthWit in a shared registry, and look it up when we need it. While this needs the storage to be updated ahead of time (can be same tx), we can quite easily do so by batching the AuthWit updates with the interaction - a benefit of Account Contracts. A shared registry is used such that execution from the sequencers point of view will be more straight forward and predictable. Furthermore, since we have the authorization data directly in public state, if they are both set and unset (authorized and then used) in the same transaction, there will be no state effect after the transaction for the authorization which saves gas ⛽. ```mermaid sequenceDiagram actor Alice participant AC as Alice Account + participant AR as Auth Registry participant Token + participant Defi rect rgb(191, 223, 255) note right of Alice: Alice sends a batch - Alice->>AC: Allow Defi to call transfer(Alice, Defi, 1000); + Alice->>AC: Authorize Defi to call transfer(Alice, Defi, 1000); activate AC Alice->>AC: Defi.deposit(Token, 1000); end + AC->>AR: Authorize Defi to call transfer(Alice, Defi, 1000); + AR->>AR: add authorize to true AC->>Defi: deposit(Token, 1000); activate Defi Defi->>Token: transfer(Alice, Defi, 1000); activate Token - Token->>AC: Check if Defi may call transfer(Alice, Defi, 1000); - AC->>Token: AuthWit validity + Token->>AR: Check if Defi may call transfer(Alice, Defi, 1000); + AR->>AR: set authorize to false + AR->>Token: AuthWit validity Token->>Token: throw if invalid AuthWit Token->>Token: transfer(Alice, Defi, 1000); Token->>Defi: success diff --git a/docs/docs/guides/smart_contracts/writing_contracts/authwit.md b/docs/docs/guides/smart_contracts/writing_contracts/authwit.md index 48e33797a53..18b21cd75b7 100644 --- a/docs/docs/guides/smart_contracts/writing_contracts/authwit.md +++ b/docs/docs/guides/smart_contracts/writing_contracts/authwit.md @@ -70,16 +70,15 @@ sequenceDiagram Note in particular that the request for a witness is done by the token contract, and the user will have to provide it to the contract before it can continue execution. Since the request is made all the way into the contract where it is to be used, we don't need to pass it along as an extra input to the functions before it which gives us a cleaner interface. ::: -As part of `AuthWit` we are assuming that the `on_behalf_of` implements the private and/or public functions: +As part of `AuthWit` we are assuming that the `on_behalf_of` implements the private function: ```rust #[aztec(private)] fn spend_private_authwit(inner_hash: Field) -> Field; - -#[aztec(public)] -fn spend_public_authwit(inner_hash: Field) -> Field; ``` +For public authwit, we have a shared registry that is used, there we are using a `consume` function. + Both return the value `0xabf64ad4` (`IS_VALID` selector) for a successful authentication, and `0x00000000` for a failed authentication. You might be wondering why we are expecting the return value to be a selector instead of a boolean. This is mainly to account for a case of selector collisions where the same selector is used for different functions, and we don't want an account to mistakenly allow a different function to be called on its behalf - it is hard to return the selector by mistake, but you might have other functions returning a bool. ## The `AuthWit` library. @@ -113,7 +112,7 @@ This is to cover the case where the `on_behalf_of` might implemented some functi ### Utilities for public calls -Very similar to the above, we have variations that work in the public domain. These functions are wrapped to give a similar flow for both cases, but behind the scenes the logic of the account contracts is slightly different since they cannot use the oracle as they are not in the private domain. +Very similar to the above, we have variations that work in the public domain (`assert_current_call_valid_authwit_public`). These functions are wrapped to give a similar flow for both cases, but behind the scenes the logic is slightly different since the public goes to the auth registry, while the private flow calls the account contract. #### Example @@ -167,7 +166,7 @@ With private functions covered, how can we use this in a public function? Well, #### Authenticating an action in TypeScript -Authenticating an action in the public domain is quite similar to the private domain, with the difference that we are executing a function on the account contract to add the witness, if you recall, this is because we don't have access to the oracle in the public domain. +Authenticating an action in the public domain is slightly different from the private domain, since we are executing a function on the auth registry contract to add the witness flag. As you might recall, this was to ensure that we don't need to call into the account contract from public, which is a potential DOS vector. In the snippet below, this is done as a separate contract call, but can also be done as part of a batch as mentioned in the [Accounts concepts](../../../aztec/concepts/accounts/authwit.md#what-about-public). @@ -177,13 +176,11 @@ In the snippet below, this is done as a separate contract call, but can also be We have cases where we need a non-wallet contract to approve an action to be executed by another contract. One of the cases could be when making more complex defi where funds are passed along. When doing so, we need the intermediate contracts to support approving of actions on their behalf. -To support this, we must implement the `spend_public_authwit` function as seen in the snippet below. - -#include_code authwit_uniswap_get /noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr rust +This is fairly straight forward to do using the `auth` library which include logic for updating values in the public auth registry. Namely, you can prepare the `message_hash` using `compute_call_authwit_hash` and then simply feed it into the `set_authorized` function (both are in `auth` library) to update the value. -It also needs a way to update those storage values. Since we want the updates to be trustless, we can compute the action based on the function inputs, and then have the contract compute the key at which it must add a `true` to approve the action. +When another contract later is consuming the authwit using `assert_current_call_valid_authwit_public` it will be calling the registry, and spend that authwit. -An example of this would be our Uniswap example which performs a cross chain swap on L1. In here, we both do private and public auth witnesses, where the public is set by the uniswap L2 contract itself. In the below snippet, you can see that we compute the action hash, and then update an `approved_action` mapping with the hash as key and `true` as value. When we then call the `token_bridge` to execute afterwards, it reads this value, burns the tokens, and consumes the authentication. +An example of this would be our Uniswap example which performs a cross chain swap on L1. In here, we both do private and public auth witnesses, where the public is set by the uniswap L2 contract itself. In the below snippet, you can see that we compute the action hash and update the value in the registry. When we then call the `token_bridge` to execute afterwards, it reads this value, burns the tokens, and consumes the authentication. #include_code authwit_uniswap_set /noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr rust diff --git a/docs/docs/guides/smart_contracts/writing_contracts/common_patterns/index.md b/docs/docs/guides/smart_contracts/writing_contracts/common_patterns/index.md index c0d0369c3e8..5e0997a595e 100644 --- a/docs/docs/guides/smart_contracts/writing_contracts/common_patterns/index.md +++ b/docs/docs/guides/smart_contracts/writing_contracts/common_patterns/index.md @@ -117,7 +117,7 @@ Hence, it's necessary to add a "randomness" field to your note to prevent such a ### L1 -- L2 interactions -Refer to [Token Portal tutorial on bridging tokens between L1 and L2](../../../../tutorials/contract_tutorials/advanced/token_bridge/index.md). This example shows how to: +Refer to [Token Portal tutorial on bridging tokens between L1 and L2](../../../../tutorials/contract_tutorials/advanced/token_bridge/index.md) and/or [Uniswap smart contract example that shows how to swap on L1 using funds on L2](../../../../reference/smart_contract_reference/examples/uniswap/index.md). Both examples show how to: 1. L1 -> L2 message flow 2. L2 -> L1 message flow @@ -131,7 +131,7 @@ To send a note to someone, they need to have a key which we can encrypt the note There are several patterns here: 1. Give the contract a key and share it amongst all participants. This leaks privacy, as anyone can see all the notes in the contract. -2. `Unshield` funds into the contract. This works like ethereum - to achieve contract composability, you move funds into the public domain. This way the contract doesn't even need keys. +2. `Unshield` funds into the contract - this is used in the [Uniswap smart contract example where a user sends private funds into a Uniswap Portal contract which eventually withdraws to L1 to swap on L1 Uniswap](../../../../reference/smart_contract_reference/examples/uniswap/index.md). This works like Ethereum - to achieve contract composability, you move funds into the public domain. This way the contract doesn't even need keys. There are several other designs we are discussing through [in this discourse post](https://discourse.aztec.network/t/how-to-handle-private-escrows-between-two-parties/2440) but they need some changes in the protocol or in our demo contract. If you are interested in this discussion, please participate in the discourse post! diff --git a/docs/docs/migration_notes.md b/docs/docs/migration_notes.md index f46468a31a1..6fed5c9c3b5 100644 --- a/docs/docs/migration_notes.md +++ b/docs/docs/migration_notes.md @@ -8,10 +8,117 @@ Aztec is in full-speed development. Literally every version breaks compatibility ## TBD +### [Aztec.nr] changes to `NoteInterface` +`compute_nullifier` function was renamed to `compute_note_hash_and_nullifier` and now the function has to return not only the nullifier but also the note hash used to compute the nullifier. +The same change was done to `compute_nullifier_without_context` function. +These changes were done because having the note hash exposed allowed us to not having to re-compute it again in `destroy_note` function of Aztec.nr which led to significant decrease in gate counts (see the [optimization PR](https://github.com/AztecProtocol/aztec-packages/pull/7103) for more details). + + +```diff +- impl NoteInterface for ValueNote { +- fn compute_nullifier(self, context: &mut PrivateContext) -> Field { +- let note_hash_for_nullify = compute_note_hash_for_consumption(self); +- let secret = context.request_nsk_app(self.npk_m_hash); +- poseidon2_hash([ +- note_hash_for_nullify, +- secret, +- GENERATOR_INDEX__NOTE_NULLIFIER as Field, +- ]) +- } +- +- fn compute_nullifier_without_context(self) -> Field { +- let note_hash_for_nullify = compute_note_hash_for_consumption(self); +- let secret = get_nsk_app(self.npk_m_hash); +- poseidon2_hash([ +- note_hash_for_nullify, +- secret, +- GENERATOR_INDEX__NOTE_NULLIFIER as Field, +- ]) +- } +- } ++ impl NoteInterface for ValueNote { ++ fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> (Field, Field) { ++ let note_hash_for_nullify = compute_note_hash_for_consumption(self); ++ let secret = context.request_nsk_app(self.npk_m_hash); ++ let nullifier = poseidon2_hash([ ++ note_hash_for_nullify, ++ secret, ++ GENERATOR_INDEX__NOTE_NULLIFIER as Field, ++ ]); ++ (note_hash_for_nullify, nullifier) ++ } ++ ++ fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) { ++ let note_hash_for_nullify = compute_note_hash_for_consumption(self); ++ let secret = get_nsk_app(self.npk_m_hash); ++ let nullifier = poseidon2_hash([ ++ note_hash_for_nullify, ++ secret, ++ GENERATOR_INDEX__NOTE_NULLIFIER as Field, ++ ]); ++ (note_hash_for_nullify, nullifier) ++ } ++ } +``` + +### [Aztec.nr] `note_getter` returns `BoundedVec` + +The `get_notes` and `view_notes` function no longer return an array of options (i.e. `[Option, N_NOTES]`) but instead a `BoundedVec`. This better conveys the useful property the old array had of having all notes collapsed at the beginning of the array, which allows for powerful optimizations and gate count reduction when setting the `options.limit` value. + +A `BoundedVec` has a `max_len()`, which equals the number of elements it can hold, and a `len()`, which equals the number of elements it currently holds. Since `len()` is typically not knwon at compile time, iterating over a `BoundedVec` looks slightly different than iterating over an array of options: + +```diff +- let option_notes = get_notes(options); +- for i in 0..option_notes.len() { +- if option_notes[i].is_some() { +- let note = option_notes[i].unwrap_unchecked(); +- } +- } ++ let notes = get_notes(options); ++ for i in 0..notes.max_len() { ++ if i < notes.len() { ++ let note = notes.get_unchecked(i); ++ } ++ } +``` + +To further reduce gate count, you can iterate over `options.limit` instead of `max_len()`, since `options.limit` is guaranteed to be larger or equal to `len()`, and smaller or equal to `max_len()`: + +```diff +- for i in 0..notes.max_len() { ++ for i in 0..options.limit { +``` + +## 0.43.0 + +### [Aztec.nr] break `token.transfer()` into `transfer` and `transferFrom` +Earlier we had just one function - `transfer()` which used authwits to handle the case where a contract/user wants to transfer funds on behalf of another user. +To reduce circuit sizes and proof times, we are breaking up `transfer` and introducing a dedicated `transferFrom()` function like in the ERC20 standard. + ### [Aztec.nr] `options.limit` has to be constant The `limit` parameter in `NoteGetterOptions` and `NoteViewerOptions` is now required to be a compile-time constant. This allows performing loops over this value, which leads to reduced circuit gate counts when setting a `limit` value. +### [Aztec.nr] canonical public authwit registry + +The public authwits are moved into a shared registry (auth registry) to make it easier for sequencers to approve for their non-revertible (setup phase) whitelist. Previously, it was possible to DOS a sequencer by having a very expensive authwit validation that fails at the end, now the whitelist simply need the registry. + +Notable, this means that consuming a public authwit will no longer emit a nullifier in the account contract but instead update STORAGE in the public domain. This means that there is a larger difference between private and public again. However, it also means that if contracts need to approve, and use the approval in the same tx, it is transient and don't need to go to DA (saving 96 bytes). + +For the typescript wallets this is handled so the APIs don't change, but account contracts should get rid of their current setup with `approved_actions`. + +```diff +- let actions = AccountActions::init(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); ++ let actions = AccountActions::init(&mut context, is_valid_impl); +``` + +For contracts we have added a `set_authorized` function in the auth library that can be used to set values in the registry. + +```diff +- storage.approved_action.at(message_hash).write(true); ++ set_authorized(&mut context, message_hash, true); +``` + ### [Aztec.nr] emit encrypted logs Emitting or broadcasting encrypted notes are no longer done as part of the note creation, but must explicitly be either emitted or discarded instead. diff --git a/docs/docs/protocol-specs/public-vm/gen/_instruction-set.mdx b/docs/docs/protocol-specs/public-vm/gen/_instruction-set.mdx index efcabe4b3ba..0431d007a93 100644 --- a/docs/docs/protocol-specs/public-vm/gen/_instruction-set.mdx +++ b/docs/docs/protocol-specs/public-vm/gen/_instruction-set.mdx @@ -14,245 +14,280 @@ Click on an instruction name to jump to its section. - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + diff --git a/docs/docs/reference/smart_contract_reference/dependencies.md b/docs/docs/reference/smart_contract_reference/dependencies.md index 0035b3454aa..95232193a9f 100644 --- a/docs/docs/reference/smart_contract_reference/dependencies.md +++ b/docs/docs/reference/smart_contract_reference/dependencies.md @@ -1,6 +1,6 @@ --- title: Importing Aztec.nr -sidebar_position: 4 +sidebar_position: 5 --- On this page you will find information about Aztec.nr libraries and up-to-date paths for use in your `Nargo.toml`. diff --git a/docs/docs/reference/smart_contract_reference/examples/_category_.json b/docs/docs/reference/smart_contract_reference/examples/_category_.json new file mode 100644 index 00000000000..29f159518ad --- /dev/null +++ b/docs/docs/reference/smart_contract_reference/examples/_category_.json @@ -0,0 +1,6 @@ +{ + "label": "Smart Contract Examples", + "position": 0, + "collapsible": true, + "collapsed": true +} diff --git a/docs/docs/reference/smart_contract_reference/examples/uniswap/_category_.json b/docs/docs/reference/smart_contract_reference/examples/uniswap/_category_.json new file mode 100644 index 00000000000..4f4e9976ade --- /dev/null +++ b/docs/docs/reference/smart_contract_reference/examples/uniswap/_category_.json @@ -0,0 +1,6 @@ +{ + "label": "Uniswap Bridge", + "position": 0, + "collapsible": true, + "collapsed": true +} diff --git a/docs/docs/reference/smart_contract_reference/examples/uniswap/e2e_tests.md b/docs/docs/reference/smart_contract_reference/examples/uniswap/e2e_tests.md new file mode 100644 index 00000000000..055c29a84c1 --- /dev/null +++ b/docs/docs/reference/smart_contract_reference/examples/uniswap/e2e_tests.md @@ -0,0 +1,13 @@ +--- +title: e2e tests (TypeScript) +sidebar_position: 3 +--- + +## Private flow test + +#include_code uniswap_private yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts typescript + +## Public flow test + +#include_code uniswap_public yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts typescript + diff --git a/docs/docs/reference/smart_contract_reference/examples/uniswap/index.md b/docs/docs/reference/smart_contract_reference/examples/uniswap/index.md new file mode 100644 index 00000000000..91dd4fe0194 --- /dev/null +++ b/docs/docs/reference/smart_contract_reference/examples/uniswap/index.md @@ -0,0 +1,31 @@ +--- +title: Overview +sidebar_position: 0 +--- + +import Image from "@theme/IdealImage"; + +# Swap on L1 Uniswap from L2 + +This smart contract example allows someone with funds on L2 to be able to swap using L1 Uniswap and then get the swapped assets back to L2. In this example, L1 will refer to Ethereum and L2 will refer to Aztec. + +The flow will be: + +1. The user withdraws their “input” assets to L1 (i.e. burn them on L2 and create a L2 to L1 message to withdraw) +2. We create an L2 → L1 message to swap on L1 +3. On L1, the user gets their input tokens, consumes the swap message, and executes the swap +4. The user deposits the “output” tokens to the output token portal so it can be deposited into L2 +5. We will assume that token portals and token bridges for the input and output tokens must exist. These are what we built in the [token bridge tutorial](../../../../tutorials/contract_tutorials/advanced/token_bridge/0_setup.md). + +The execution of swap on L1 should be designed such that any 3rd party can execute the swap on behalf of the user. This helps maintain user privacy by not requiring links between L1 and L2 activity. + +This reference will cover: +1. Uniswap Portal - a contract on L1 that talks to the input token portal to withdraw the assets, executes the swap, and deposits the swapped tokens back to L2 +2. Uniswap L2 contract - a contract on L2 that creates the needed messages to perform the swap on L1 + + + +This diagram describes the private flow. + +This code works alongside a token portal that you can learn to build [in this tutorial](../../../../tutorials/contract_tutorials/advanced/token_bridge/0_setup.md). + diff --git a/docs/docs/reference/smart_contract_reference/examples/uniswap/l1_contract.md b/docs/docs/reference/smart_contract_reference/examples/uniswap/l1_contract.md new file mode 100644 index 00000000000..cbb164b26f6 --- /dev/null +++ b/docs/docs/reference/smart_contract_reference/examples/uniswap/l1_contract.md @@ -0,0 +1,37 @@ +--- +title: L1 contracts (EVM) +sidebar_position: 2 +--- + +This page goes over the code in the L1 contract for Uniswap, which works alongside a [token portal](../../../../tutorials/contract_tutorials/advanced/token_bridge/index.md). + +## Setup + +#include_code setup l1-contracts/test/portals/UniswapPortal.sol solidity + +## Public swap + +#include_code solidity_uniswap_swap_public l1-contracts/test/portals/UniswapPortal.sol solidity + +1. It fetches the input and output tokens we are swapping. The Uniswap portal only needs to know the portal addresses of the input and output as they store the underlying ERC20 token address. +2. Consumes the `withdraw` message to get input tokens on L1 to itself. This is needed to execute the swap. + + Before it actually can swap, it checks if the provided swap parameters were what the user actually wanted by creating a message content hash (similar to what we did in the L2 contract) to ensure the right parameters are used. + +3. Executes the swap and receives the output funds to itself. + + The deadline by which the funds should be swapped is `block.timestamp` i.e. this block itself. This makes things atomic on the L1 side. + +4. The portal must deposit the output funds back to L2 using the output token’s portal. For this we first approve the token portal to move Uniswap funds, and then call the portal’s `depositToAztecPublic()` method to transfer funds to the portal and create a L1 → l2 message to mint the right amount of output tokens on L2. + +To incentivize the sequencer to pick up this message, we pass a fee to the deposit message. + +You can find the corresponding function on the [L2 contracts page](l2_contract.md#public-swap). + +## Private swap + +This works very similarly to the public flow. + +#include_code solidity_uniswap_swap_private l1-contracts/test/portals/UniswapPortal.sol solidity + +You can find the corresponding function on the [L2 contracts page](l2_contract.md#private-swap). diff --git a/docs/docs/reference/smart_contract_reference/examples/uniswap/l2_contract.md b/docs/docs/reference/smart_contract_reference/examples/uniswap/l2_contract.md new file mode 100644 index 00000000000..3ead8d76254 --- /dev/null +++ b/docs/docs/reference/smart_contract_reference/examples/uniswap/l2_contract.md @@ -0,0 +1,89 @@ +--- +title: L2 Contracts (Aztec) +sidebar_position: 1 +--- + +This page goes over the code in the L2 contract for Uniswap, which works alongside a [token bridge](../../../../tutorials/contract_tutorials/advanced/token_bridge/0_setup.md). + +## Main.nr + +### Setup and constructor + +#include_code uniswap_setup noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr rust +We just need to store the portal address for the token that we want to swap. + + +### Public swap + +#include_code swap_public noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr rust + +1. We check that `msg.sender()` has appropriate approval to call this on behalf of the sender by constructing an authwit message and checking if `from` has given the approval (read more about authwit [here](../../../../aztec/concepts/accounts/authwit.md)). +2. We fetch the underlying aztec token that needs to be swapped. +3. We transfer the user’s funds to the Uniswap contract. Like with Ethereum, the user must have provided approval to the Uniswap contract to do so. The user must provide the nonce they used in the approval for transfer, so that Uniswap can send it to the token contract, to prove it has appropriate approval. +4. Funds are added to the Uniswap contract. +5. Uniswap must exit the input tokens to L1. For this it has to approve the bridge to burn its tokens on its behalf and then actually exit the funds. We call the [`exit_to_l1_public()` method on the token bridge](../../../../tutorials/contract_tutorials/advanced/token_bridge/index.md). We use the public flow for exiting since we are operating on public state. +6. It is not enough for us to simply emit a message to withdraw the funds. We also need to emit a message to display our swap intention. If we do not do this, there is nothing stopping a third party from calling the Uniswap portal with their own parameters and consuming our message. + +So the Uniswap portal (on L1) needs to know: + +- The token portals for the input and output token (to withdraw the input token to L1 and later deposit the output token to L2) +- The amount of input tokens they want to swap +- The Uniswap fee tier they want to use +- The minimum output amount they can accept (for slippage protection) + +The Uniswap portal must first withdraw the input tokens, then check that the swap message exists in the outbox, execute the swap, and then call the output token to deposit the swapped tokens to L2. So the Uniswap portal must also be pass any parameters needed to complete the deposit of swapped tokens to L2. From the tutorial on building token bridges we know these are: + +- The address on L2 which must receive the output tokens (remember this is public flow) +- The secret hash for consume the L1 to L2 message. Since this is the public flow the preimage doesn’t need to be a secret. + +You can find the corresponding function on the [L1 contracts page](l1_contract.md). + +### Private swap + +#include_code swap_private noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr rust + +This uses a util function `compute_swap_private_content_hash()` - find that [here](#utils) + +This flow works similarly to the public flow with a few notable changes: + +- Notice how in the `swap_private()`, user has to pass in `token` address which they didn't in the public flow? Since `swap_private()` is a private method, it can't read what token is publicly stored on the token bridge, so instead the user passes a token address, and `_assert_token_is_same()` checks that this user provided address is same as the one in storage. Note that because public functions are executed by the sequencer while private methods are executed locally, all public calls are always done after all private calls are done. So first the burn would happen and only later the sequencer asserts that the token is same. Note that the sequencer just sees a request to `execute_assert_token_is_same` and therefore has no context on what the appropriate private method was. If the assertion fails, then the kernel circuit will fail to create a proof and hence the transaction will be dropped. +- In the public flow, the user calls `transfer_public()`. Here instead, the user calls `unshield()`. Why? The user can't directly transfer their private tokens (their notes) to the uniswap contract, because later the Uniswap contract has to approve the bridge to burn these notes and withdraw to L1. The authwit flow for the private domain requires a signature from the `sender`, which in this case would be the Uniswap contract. For the contract to sign, it would need a private key associated to it. But who would operate this key? +- To work around this, the user can unshield their private tokens into Uniswap L2 contract. Unshielding would convert user's private notes to public balance. It is a private method on the token contract that reduces a user’s private balance and then calls a public method to increase the recipient’s (ie Uniswap) public balance. **Remember that first all private methods are executed and then later all public methods will be - so the Uniswap contract won’t have the funds until public execution begins.** +- Now uniswap has public balance (like with the public flow). Hence, `swap_private()` calls the internal public method which approves the input token bridge to burn Uniswap’s tokens and calls `exit_to_l1_public` to create an L2 → L1 message to exit to L1. +- Constructing the message content for swapping works exactly as the public flow except instead of specifying who would be the Aztec address that receives the swapped funds, we specify a secret hash (`secret_hash_for_redeeming_minted_notes`). Only those who know the preimage to the secret can later redeem the minted notes to themselves. + +### Approve the bridge to burn this contract's funds + +Both public and private swap functions call this function: + +#include_code authwit_uniswap_set noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr rust + +### Assertions + +#include_code assert_token_is_same noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr rust + +This is a simple function that asserts that the token passed in to the function is the one that the bridge is associated with. + +## Utils + +### Compute content hash for public + +#include_code uniswap_public_content_hash noir-projects/noir-contracts/contracts/uniswap_contract/src/util.nr rust + +This method computes the L2 to L1 message content hash for the public. To find out how it is consumed on L1, view the [L1 contracts page](./l1_contract.md) + +### Compute content hash for private + +#include_code compute_swap_private_content_hash noir-projects/noir-contracts/contracts/uniswap_contract/src/util.nr rust + +This method computes the L2 to L1 message content hash for the private. To find out how it is consumed on L1, view the [L1 contracts page](./l1_contract.md). + +## Redeeming assets + +So you emitted a message to withdraw input tokens to L1 and a message to swap. Then you or someone on your behalf can swap on L1 and emit a message to deposit swapped assets to L2. + +You still need to "claim" these swapped funds on L2. + +In the public flow, you can call [`claim_public()`](../../../../tutorials/contract_tutorials/advanced/token_bridge/2_minting_on_aztec.md) on the output token bridge which consumes the deposit message and mints your assets. + +In the private flow, you can choose to leak your secret for L1 → L2 message consumption to let someone mint the notes on L2 (by calling [`claim_private()`](../../../../tutorials/contract_tutorials/advanced/token_bridge/2_minting_on_aztec.md) on the output token bridge) and then you can later redeem these notes to yourself by presenting the preimage to `secret_hash_for_redeeming_minted_notes` and calling the `redeem_shield()` method on the token contract. \ No newline at end of file diff --git a/docs/docs/reference/smart_contract_reference/globals.md b/docs/docs/reference/smart_contract_reference/globals.md index 803fc08c86d..ae034a17f6f 100644 --- a/docs/docs/reference/smart_contract_reference/globals.md +++ b/docs/docs/reference/smart_contract_reference/globals.md @@ -1,7 +1,7 @@ --- title: Global Variables description: Documentation of Aztec's Global Variables in the Public and Private Contexts -sidebar_position: 1 +sidebar_position: 2 --- # Global Variables diff --git a/docs/docs/reference/smart_contract_reference/history_lib_reference.md b/docs/docs/reference/smart_contract_reference/history_lib_reference.md index 9971a6ef775..825d2ddb8cc 100644 --- a/docs/docs/reference/smart_contract_reference/history_lib_reference.md +++ b/docs/docs/reference/smart_contract_reference/history_lib_reference.md @@ -1,6 +1,6 @@ --- title: History Reference -sidebar_position: 2 +sidebar_position: 3 --- diff --git a/docs/docs/reference/smart_contract_reference/portals/_category_.json b/docs/docs/reference/smart_contract_reference/portals/_category_.json index e52acf91653..3a04a4bcda8 100644 --- a/docs/docs/reference/smart_contract_reference/portals/_category_.json +++ b/docs/docs/reference/smart_contract_reference/portals/_category_.json @@ -1,6 +1,6 @@ { "label": "Portals", - "position": 3, + "position": 4, "collapsible": true, "collapsed": true } diff --git a/docs/docs/reference/smart_contract_reference/storage/_category_.json b/docs/docs/reference/smart_contract_reference/storage/_category_.json index 49a4bd8abca..25edf7aa1c2 100644 --- a/docs/docs/reference/smart_contract_reference/storage/_category_.json +++ b/docs/docs/reference/smart_contract_reference/storage/_category_.json @@ -1,5 +1,5 @@ { - "position": 0, + "position": 1, "collapsible": true, "collapsed": true, "label": "Storage" diff --git a/docs/src/preprocess/InstructionSet/genMarkdown.js b/docs/src/preprocess/InstructionSet/genMarkdown.js index b0284ad062a..f19c364b94c 100644 --- a/docs/src/preprocess/InstructionSet/genMarkdown.js +++ b/docs/src/preprocess/InstructionSet/genMarkdown.js @@ -12,8 +12,8 @@ function escapeBraces(str) { return str.replace(//g, ">"); } -function stripBraces(str) { - return str.replace(/[<>]/g, ""); +function escapeTicks(str) { + return str.replace(/`/g, "\\`"); } function instructionSetPreface() { @@ -44,10 +44,10 @@ function htmlInstructionSetTable() { const instr = INSTRUCTION_SET[i]; const name = instr["Name"]; let row = `\n`; - row += `\t`; + row += `\t\n`; row += `\t`; diff --git a/iac/mainnet-fork/Dockerfile b/iac/mainnet-fork/Dockerfile deleted file mode 100644 index c0240ccadc8..00000000000 --- a/iac/mainnet-fork/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM ubuntu:focal - -# Install nginx -RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections -RUN apt-get update && apt install -y git curl nginx - -# Copy nginx config -COPY . . -COPY nginx/gateway.conf /etc/nginx/gateway.conf -COPY nginx/nginx.conf /etc/nginx/nginx.conf - -# Install foundry -RUN ./scripts/install_foundry.sh -ENV PATH="./foundry/bin:${PATH}" - -# Run anvil and nginx -EXPOSE 80 -ENTRYPOINT ["sh", "-c", "./scripts/run_nginx_anvil.sh"] \ No newline at end of file diff --git a/iac/mainnet-fork/Earthfile b/iac/mainnet-fork/Earthfile new file mode 100644 index 00000000000..fb480d1801d --- /dev/null +++ b/iac/mainnet-fork/Earthfile @@ -0,0 +1,29 @@ +VERSION 0.8 + +build: + FROM ubuntu:focal + + # Install nginx + RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections + RUN apt-get update && apt install -y git curl nginx + + # Copy nginx config + COPY . . + COPY nginx/gateway.conf /etc/nginx/gateway.conf + COPY nginx/nginx.conf /etc/nginx/nginx.conf + + # Install foundry + RUN ./scripts/install_foundry.sh + ENV PATH="./foundry/bin:${PATH}" + + # Expose port 80 + EXPOSE 80 + + # Set entrypoint + ENTRYPOINT ["sh", "-c", "./scripts/run_nginx_anvil.sh"] + +export-mainnet-fork: + FROM +build + ARG DIST_TAG="aztec-dev" + ARG ARCH + SAVE IMAGE --push spypsy/mainnet-fork:${DIST_TAG}${ARCH:+-$ARCH} diff --git a/iac/mainnet-fork/nginx/nginx.conf b/iac/mainnet-fork/nginx/nginx.conf index 0deef80724e..5e078c52cc8 100644 --- a/iac/mainnet-fork/nginx/nginx.conf +++ b/iac/mainnet-fork/nginx/nginx.conf @@ -10,6 +10,7 @@ http { # Basic Settings ## + client_max_body_size 20M; sendfile on; tcp_nopush on; tcp_nodelay on; diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 9e842c857ad..e031af8cbd8 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -21,7 +21,7 @@ library Constants { uint256 internal constant MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL = 16; uint256 internal constant MAX_NEW_L2_TO_L1_MSGS_PER_CALL = 2; uint256 internal constant MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL = 32; - uint256 internal constant MAX_PUBLIC_DATA_READS_PER_CALL = 16; + uint256 internal constant MAX_PUBLIC_DATA_READS_PER_CALL = 32; uint256 internal constant MAX_NOTE_HASH_READ_REQUESTS_PER_CALL = 32; uint256 internal constant MAX_NULLIFIER_READ_REQUESTS_PER_CALL = 32; uint256 internal constant MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL = 32; @@ -37,7 +37,7 @@ library Constants { uint256 internal constant MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX = 63; uint256 internal constant PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX = 1; uint256 internal constant MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX = 64; - uint256 internal constant MAX_PUBLIC_DATA_READS_PER_TX = 32; + uint256 internal constant MAX_PUBLIC_DATA_READS_PER_TX = 64; uint256 internal constant MAX_NEW_L2_TO_L1_MSGS_PER_TX = 8; uint256 internal constant MAX_NOTE_HASH_READ_REQUESTS_PER_TX = 128; uint256 internal constant MAX_NULLIFIER_READ_REQUESTS_PER_TX = 128; @@ -47,7 +47,7 @@ library Constants { uint256 internal constant MAX_NOTE_ENCRYPTED_LOGS_PER_TX = 64; uint256 internal constant MAX_ENCRYPTED_LOGS_PER_TX = 8; uint256 internal constant MAX_UNENCRYPTED_LOGS_PER_TX = 8; - uint256 internal constant MAX_PUBLIC_DATA_HINTS = 64; + uint256 internal constant MAX_PUBLIC_DATA_HINTS = 128; uint256 internal constant NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16; uint256 internal constant VK_TREE_HEIGHT = 3; uint256 internal constant FUNCTION_TREE_HEIGHT = 5; @@ -100,6 +100,8 @@ library Constants { uint256 internal constant FIXED_DA_GAS = 512; uint256 internal constant CANONICAL_KEY_REGISTRY_ADDRESS = 2153455745675440165069577621832684870696142028027528497509357256345838682961; + uint256 internal constant CANONICAL_AUTH_REGISTRY_ADDRESS = + 18091885756106795278141309801070173692350235742979924147720536894670507925831; uint256 internal constant DEPLOYER_CONTRACT_ADDRESS = 19511485909966796736993840362353440247573331327062358513665772226446629198132; uint256 internal constant REGISTERER_CONTRACT_ADDRESS = @@ -148,21 +150,21 @@ library Constants { uint256 internal constant TOTAL_FEES_LENGTH = 1; uint256 internal constant HEADER_LENGTH = 23; uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 457; - uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 530; + uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 578; uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 460; uint256 internal constant PUBLIC_CONTEXT_INPUTS_LENGTH = 41; uint256 internal constant AGGREGATION_OBJECT_LENGTH = 16; uint256 internal constant SCOPED_READ_REQUEST_LEN = 3; uint256 internal constant PUBLIC_DATA_READ_LENGTH = 2; - uint256 internal constant VALIDATION_REQUESTS_LENGTH = 1538; + uint256 internal constant VALIDATION_REQUESTS_LENGTH = 1602; uint256 internal constant PUBLIC_DATA_UPDATE_REQUEST_LENGTH = 3; uint256 internal constant COMBINED_ACCUMULATED_DATA_LENGTH = 333; uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = 40; uint256 internal constant CALL_REQUEST_LENGTH = 7; uint256 internal constant PRIVATE_ACCUMULATED_DATA_LENGTH = 1152; - uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2739; + uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2803; uint256 internal constant PUBLIC_ACCUMULATED_DATA_LENGTH = 983; - uint256 internal constant PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 3770; + uint256 internal constant PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 3834; uint256 internal constant KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 383; uint256 internal constant CONSTANT_ROLLUP_DATA_LENGTH = 14; uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 31; diff --git a/noir-projects/Dockerfile b/noir-projects/Dockerfile index ab4c6270e97..dc2ecf46362 100644 --- a/noir-projects/Dockerfile +++ b/noir-projects/Dockerfile @@ -15,11 +15,11 @@ WORKDIR /usr/src/noir-projects COPY . . # Build WORKDIR /usr/src/noir-projects/noir-contracts -RUN ./bootstrap.sh && nargo test --silence-warnings +RUN ./bootstrap.sh WORKDIR /usr/src/noir-projects/noir-protocol-circuits -RUN ./bootstrap.sh && nargo test --silence-warnings +RUN ./bootstrap.sh WORKDIR /usr/src/noir-projects/aztec-nr -RUN nargo test --silence-warnings +RUN nargo compile --silence-warnings FROM scratch COPY --from=builder /usr/src/noir-projects /usr/src/noir-projects \ No newline at end of file diff --git a/noir-projects/Dockerfile.test b/noir-projects/Dockerfile.test new file mode 100644 index 00000000000..40edcbaaf35 --- /dev/null +++ b/noir-projects/Dockerfile.test @@ -0,0 +1,38 @@ +FROM aztecprotocol/noir as noir +FROM aztecprotocol/avm-transpiler as transpiler +FROM aztecprotocol/yarn-project as yarn-project + +RUN apt-get update && apt-get install -y parallel + +# Copy in nargo +COPY --from=noir /usr/src/noir/noir-repo/target/release/nargo /usr/src/noir/noir-repo/target/release/nargo +ENV PATH="/usr/src/noir/noir-repo/target/release:${PATH}" +# Copy in transpiler +COPY --from=transpiler /usr/src/avm-transpiler/target/release/avm-transpiler /usr/src/avm-transpiler/target/release/avm-transpiler +ENV PATH="/usr/src/avm-transpiler/target/release:${PATH}" + +# All built files are ignored so we have to repeat the txe build here. +# It is fast (compared to the tests) and we're moving to earthly, so we don't bother with something more sophisticated. +WORKDIR /usr/src/yarn-project +RUN yarn workspaces focus @aztec/txe +RUN cd ./txe && yarn build + +# Copy in noir projects +WORKDIR /usr/src/noir-projects +COPY . . + +# Build & test +RUN cd ./noir-protocol-circuits && ./bootstrap.sh && nargo test --silence-warnings + +RUN cd /usr/src/yarn-project/txe && yarn start & echo $! > /tmp/txe.pid && \ + # Wait for TXE to initialize + sleep 5 && \ + cd ./noir-contracts && \ + ./bootstrap.sh && nargo test --silence-warnings --oracle-resolver http://localhost:8080 ; \ + kill $(cat /tmp/txe.pid) + +RUN cd /usr/src/yarn-project/txe && yarn start & echo $! > /tmp/txe.pid && \ + # Wait for TXE to initialize + sleep 5 && \ + cd ./aztec-nr && \ + nargo test --silence-warnings --oracle-resolver http://localhost:8080 \ No newline at end of file diff --git a/noir-projects/Earthfile b/noir-projects/Earthfile index 2a7c32ab568..df8db2aa046 100644 --- a/noir-projects/Earthfile +++ b/noir-projects/Earthfile @@ -41,10 +41,25 @@ build: SAVE ARTIFACT noir-protocol-circuits test: - FROM +build - RUN cd noir-protocol-circuits && nargo test --silence-warnings - RUN cd aztec-nr && nargo test --silence-warnings - RUN cd noir-contracts && nargo test --silence-warnings + FROM ../yarn-project/+txe + + # Install nargo + COPY ../noir/+nargo/nargo /usr/bin/nargo + + COPY +build/. /usr/src/noir-projects + + RUN cd /usr/src/noir-projects/noir-protocol-circuits && nargo test --silence-warnings + RUN cd /usr/src/yarn-project/txe && yarn start & echo $! > /tmp/txe.pid && \ + # Wait for TXE to initialize + sleep 5 && \ + cd /usr/src/noir-projects/aztec-nr && nargo test --silence-warnings --oracle-resolver http://localhost:8080 ; \ + kill $(cat /tmp/txe.pid) + + RUN cd /usr/src/yarn-project/txe && yarn start & echo $! > /tmp/txe.pid && \ + # Wait for TXE to initialize + sleep 5 && \ + cd /usr/src/noir-projects/noir-contracts && nargo test --silence-warnings --oracle-resolver http://localhost:8080 ; \ + kill $(cat /tmp/txe.pid) format: FROM +build diff --git a/noir-projects/aztec-nr/.gitrepo b/noir-projects/aztec-nr/.gitrepo index 18dacb4e7e8..a9b40658cc8 100644 --- a/noir-projects/aztec-nr/.gitrepo +++ b/noir-projects/aztec-nr/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/AztecProtocol/aztec-nr branch = master - commit = df0d55d3da5c02d11a962a108857910e83da0a70 + commit = 2e5113eff6fa3209baf95f4053cda88f821a664f method = merge cmdver = 0.4.6 - parent = 110811b684750067e44b116cdb7baa2b826db6e5 + parent = 4913192d0539a407399ad77e31ab1346930c1361 diff --git a/noir-projects/aztec-nr/address-note/src/address_note.nr b/noir-projects/aztec-nr/address-note/src/address_note.nr index e68afdd7bf8..26d494bed65 100644 --- a/noir-projects/aztec-nr/address-note/src/address_note.nr +++ b/noir-projects/aztec-nr/address-note/src/address_note.nr @@ -23,24 +23,26 @@ struct AddressNote { impl NoteInterface for AddressNote { - fn compute_nullifier(self, context: &mut PrivateContext) -> Field { + fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } } diff --git a/noir-projects/aztec-nr/authwit/src/account.nr b/noir-projects/aztec-nr/authwit/src/account.nr index 33b519c7424..c00592520a3 100644 --- a/noir-projects/aztec-nr/authwit/src/account.nr +++ b/noir-projects/aztec-nr/authwit/src/account.nr @@ -1,5 +1,4 @@ use dep::aztec::context::{PrivateContext, PublicContext}; -use dep::aztec::state_vars::{Map, PublicMutable}; use dep::aztec::protocol_types::{address::AztecAddress, abis::function_selector::FunctionSelector, hash::pedersen_hash}; use crate::entrypoint::{app::AppPayload, fee::FeePayload}; @@ -8,26 +7,11 @@ use crate::auth::{IS_VALID_SELECTOR, compute_outer_authwit_hash}; struct AccountActions { context: Context, is_valid_impl: fn(&mut PrivateContext, Field) -> bool, - approved_action: Map, Context>, } impl AccountActions { - pub fn init( - context: Context, - approved_action_storage_slot: Field, - is_valid_impl: fn(&mut PrivateContext, Field) -> bool - ) -> Self { - AccountActions { - context, - is_valid_impl, - approved_action: Map::new( - context, - approved_action_storage_slot, - |context, slot| { - PublicMutable::new(context, slot) - } - ) - } + pub fn init(context: Context, is_valid_impl: fn(&mut PrivateContext, Field) -> bool) -> Self { + AccountActions { context, is_valid_impl } } } @@ -65,29 +49,3 @@ impl AccountActions<&mut PrivateContext> { } // docs:end:spend_private_authwit } - -impl AccountActions<&mut PublicContext> { - // docs:start:spend_public_authwit - pub fn spend_public_authwit(self, inner_hash: Field) -> Field { - // The `inner_hash` is "siloed" with the `msg_sender` to ensure that only it can - // consume the message. - // This ensures that contracts cannot consume messages that are not intended for them. - let message_hash = compute_outer_authwit_hash( - self.context.msg_sender(), - self.context.chain_id(), - self.context.version(), - inner_hash - ); - let is_valid = self.approved_action.at(message_hash).read(); - assert(is_valid == true, "Message not authorized by account"); - self.context.push_new_nullifier(message_hash, 0); - IS_VALID_SELECTOR - } - // docs:end:spend_public_authwit - - // docs:start:approve_public_authwit - pub fn approve_public_authwit(self, message_hash: Field) { - self.approved_action.at(message_hash).write(true); - } - // docs:end:approve_public_authwit -} diff --git a/noir-projects/aztec-nr/authwit/src/auth.nr b/noir-projects/aztec-nr/authwit/src/auth.nr index 5319536212d..b24bad76c17 100644 --- a/noir-projects/aztec-nr/authwit/src/auth.nr +++ b/noir-projects/aztec-nr/authwit/src/auth.nr @@ -1,6 +1,7 @@ use dep::aztec::protocol_types::{ abis::function_selector::FunctionSelector, address::AztecAddress, - constants::{GENERATOR_INDEX__AUTHWIT_INNER, GENERATOR_INDEX__AUTHWIT_OUTER}, hash::pedersen_hash + constants::{GENERATOR_INDEX__AUTHWIT_INNER, GENERATOR_INDEX__AUTHWIT_OUTER, CANONICAL_AUTH_REGISTRY_ADDRESS}, + hash::pedersen_hash }; use dep::aztec::{prelude::Deserialize, context::{PrivateContext, PublicContext, gas::GasOpts}, hash::hash_args_array}; @@ -19,14 +20,14 @@ pub fn assert_current_call_valid_authwit(context: &mut PrivateContext, on_behalf // docs:start:assert_current_call_valid_authwit_public // Assert that `on_behalf_of` have authorized the current call in a public context pub fn assert_current_call_valid_authwit_public(context: &mut PublicContext, on_behalf_of: AztecAddress) { - let function_selector = FunctionSelector::from_signature("spend_public_authwit(Field)"); let inner_hash = compute_inner_authwit_hash( [(*context).msg_sender().to_field(), (*context).selector().to_field(), (*context).get_args_hash()] ); + let result: Field = context.call_public_function( - on_behalf_of, - function_selector, - [inner_hash].as_slice(), + AztecAddress::from_field(CANONICAL_AUTH_REGISTRY_ADDRESS), + FunctionSelector::from_signature("consume((Field),Field)"), + [on_behalf_of.to_field(), inner_hash].as_slice(), GasOpts::default() ).deserialize_into(); assert(result == IS_VALID_SELECTOR, "Message not authorized by account"); @@ -69,3 +70,32 @@ pub fn compute_outer_authwit_hash( GENERATOR_INDEX__AUTHWIT_OUTER ) } + +/** + * Helper function to set the authorization status of a message hash + * + * @param message_hash The hash of the message to authorize + * @param authorize True if the message should be authorized, false if it should be revoked + */ +pub fn set_authorized(context: &mut PublicContext, message_hash: Field, authorize: bool) { + context.call_public_function( + AztecAddress::from_field(CANONICAL_AUTH_REGISTRY_ADDRESS), + FunctionSelector::from_signature("set_authorized(Field,bool)"), + [message_hash, authorize as Field].as_slice(), + GasOpts::default() + ).assert_empty(); +} + +/** + * Helper function to reject all authwits + * + * @param reject True if all authwits should be rejected, false otherwise + */ +pub fn set_reject_all(context: &mut PublicContext, reject: bool) { + context.call_public_function( + AztecAddress::from_field(CANONICAL_AUTH_REGISTRY_ADDRESS), + FunctionSelector::from_signature("set_reject_all(bool)"), + [context.this_address().to_field(), reject as Field].as_slice(), + GasOpts::default() + ).assert_empty(); +} diff --git a/noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr b/noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr index 69904595c96..dd1374f9eb0 100644 --- a/noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr +++ b/noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr @@ -1,20 +1,56 @@ -use dep::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress, traits::Deserialize}; +use dep::protocol_types::{ + abis::{function_selector::FunctionSelector, private_circuit_public_inputs::PrivateCircuitPublicInputs}, + address::AztecAddress, traits::Deserialize +}; -use crate::context::private_context::PrivateContext; -use crate::context::public_context::PublicContext; -use crate::context::gas::GasOpts; -use crate::context::public_context::FunctionReturns; +use crate::context::{ + private_context::PrivateContext, public_context::PublicContext, gas::GasOpts, + public_context::FunctionReturns, inputs::{PrivateContextInputs, PublicContextInputs} +}; use crate::oracle::arguments; -struct PrivateCallInterface { +trait CallInterface { + fn get_args(self) -> [Field]; + fn get_original(self) -> fn[Env](T) -> P; + fn get_selector(self) -> FunctionSelector; + fn get_name(self) -> str; + fn get_contract_address(self) -> AztecAddress; +} + +impl CallInterface for PrivateCallInterface { + fn get_args(self) -> [Field] { + self.args + } + + fn get_original(self) -> fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs { + self.original + } + + fn get_selector(self) -> FunctionSelector { + self.selector + } + + fn get_name(self) -> str { + self.name + } + + fn get_contract_address(self) -> AztecAddress { + self.target_contract + } +} + +struct PrivateCallInterface { target_contract: AztecAddress, selector: FunctionSelector, + name: str, args_hash: Field, + args: [Field], + original: fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs } -impl PrivateCallInterface { - pub fn call(self, context: &mut PrivateContext) -> T where T: Deserialize { +impl PrivateCallInterface { + pub fn call(self, context: &mut PrivateContext) -> T where T: Deserialize { let returns = context.call_private_function_with_packed_args( self.target_contract, self.selector, @@ -26,24 +62,49 @@ impl PrivateCallInterface { unpacked } - pub fn view(self, context: &mut PrivateContext) -> T where T: Deserialize { + pub fn view(self, context: &mut PrivateContext) -> T where T: Deserialize { let returns = context.call_private_function_with_packed_args(self.target_contract, self.selector, self.args_hash, true, false); returns.unpack_into() } - pub fn delegate_call(self, context: &mut PrivateContext) -> T where T: Deserialize { + pub fn delegate_call(self, context: &mut PrivateContext) -> T where T: Deserialize { let returns = context.call_private_function_with_packed_args(self.target_contract, self.selector, self.args_hash, false, true); returns.unpack_into() } } -struct PrivateVoidCallInterface { +impl CallInterface for PrivateVoidCallInterface { + fn get_args(self) -> [Field] { + self.args + } + + fn get_original(self) -> fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs { + self.original + } + + fn get_selector(self) -> FunctionSelector { + self.selector + } + + fn get_name(self) -> str { + self.name + } + + fn get_contract_address(self) -> AztecAddress { + self.target_contract + } +} + +struct PrivateVoidCallInterface { target_contract: AztecAddress, selector: FunctionSelector, + name: str, args_hash: Field, + args: [Field], + original: fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs } -impl PrivateVoidCallInterface { +impl PrivateVoidCallInterface { pub fn call(self, context: &mut PrivateContext) { context.call_private_function_with_packed_args( self.target_contract, @@ -63,55 +124,129 @@ impl PrivateVoidCallInterface { } } -struct PrivateStaticCallInterface { +impl CallInterface for PrivateStaticCallInterface { + fn get_args(self) -> [Field] { + self.args + } + + fn get_original(self) -> fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs { + self.original + } + + fn get_selector(self) -> FunctionSelector { + self.selector + } + + fn get_name(self) -> str { + self.name + } + + fn get_contract_address(self) -> AztecAddress { + self.target_contract + } +} + +struct PrivateStaticCallInterface { target_contract: AztecAddress, selector: FunctionSelector, + name: str, args_hash: Field, + args: [Field], + original: fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs } -impl PrivateStaticCallInterface { - pub fn view(self, context: &mut PrivateContext) -> T where T: Deserialize { +impl PrivateStaticCallInterface { + pub fn view(self, context: &mut PrivateContext) -> T where T: Deserialize { let returns = context.call_private_function_with_packed_args(self.target_contract, self.selector, self.args_hash, true, false); returns.unpack_into() } } -struct PrivateStaticVoidCallInterface { +impl CallInterface for PrivateStaticVoidCallInterface { + fn get_args(self) -> [Field] { + self.args + } + + fn get_original(self) -> fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs { + self.original + } + + fn get_selector(self) -> FunctionSelector { + self.selector + } + + fn get_name(self) -> str { + self.name + } + + fn get_contract_address(self) -> AztecAddress { + self.target_contract + } +} + +struct PrivateStaticVoidCallInterface { target_contract: AztecAddress, selector: FunctionSelector, + name: str, args_hash: Field, + args: [Field], + original: fn[Env](PrivateContextInputs) -> PrivateCircuitPublicInputs } -impl PrivateStaticVoidCallInterface { +impl PrivateStaticVoidCallInterface { pub fn view(self, context: &mut PrivateContext) { context.call_private_function_with_packed_args(self.target_contract, self.selector, self.args_hash, true, false).assert_empty(); } } -struct PublicCallInterface { +impl CallInterface for PublicCallInterface { + fn get_args(self) -> [Field] { + self.args + } + + fn get_original(self) -> fn[Env](PublicContextInputs) -> T { + self.original + } + + fn get_selector(self) -> FunctionSelector { + self.selector + } + + fn get_name(self) -> str { + self.name + } + + fn get_contract_address(self) -> AztecAddress { + self.target_contract + } +} + +struct PublicCallInterface { target_contract: AztecAddress, selector: FunctionSelector, + name: str, args: [Field], gas_opts: GasOpts, + original: fn[Env](PublicContextInputs) -> T } -impl PublicCallInterface { +impl PublicCallInterface { pub fn with_gas(self: &mut Self, gas_opts: GasOpts) -> &mut Self { self.gas_opts = gas_opts; self } - pub fn call(self, context: &mut PublicContext) -> T where T: Deserialize { + pub fn call(self, context: &mut PublicContext) -> T where T: Deserialize { let returns = context.call_public_function(self.target_contract, self.selector, self.args, self.gas_opts); returns.deserialize_into() } - pub fn view(self, context: &mut PublicContext) -> T where T: Deserialize { + pub fn view(self, context: &mut PublicContext) -> T where T: Deserialize { let returns = context.static_call_public_function(self.target_contract, self.selector, self.args, self.gas_opts); returns.deserialize_into() } - pub fn delegate_call(self, context: &mut PublicContext) -> T where T: Deserialize { + pub fn delegate_call(self, context: &mut PublicContext) -> T where T: Deserialize { let returns = context.delegate_call_public_function(self.target_contract, self.selector, self.args); returns.deserialize_into() } @@ -153,30 +288,54 @@ impl PublicCallInterface { } } -struct PublicVoidCallInterface { +impl CallInterface for PublicVoidCallInterface { + fn get_args(self) -> [Field] { + self.args + } + + fn get_original(self) -> fn[Env](PublicContextInputs) -> () { + self.original + } + + fn get_selector(self) -> FunctionSelector { + self.selector + } + + fn get_name(self) -> str { + self.name + } + + fn get_contract_address(self) -> AztecAddress { + self.target_contract + } +} + +struct PublicVoidCallInterface { target_contract: AztecAddress, selector: FunctionSelector, + name: str, args: [Field], gas_opts: GasOpts, + original: fn[Env](PublicContextInputs) -> () } -impl PublicVoidCallInterface { +impl PublicVoidCallInterface { pub fn with_gas(self: &mut Self, gas_opts: GasOpts) -> &mut Self { self.gas_opts = gas_opts; self } - pub fn call(self, context: &mut PublicContext) { + pub fn call(self, context: &mut PublicContext) { let returns = context.call_public_function(self.target_contract, self.selector, self.args, self.gas_opts); returns.assert_empty() } - pub fn view(self, context: &mut PublicContext) { + pub fn view(self, context: &mut PublicContext) { let returns = context.static_call_public_function(self.target_contract, self.selector, self.args, self.gas_opts); returns.assert_empty() } - pub fn delegate_call(self, context: &mut PublicContext) { + pub fn delegate_call(self, context: &mut PublicContext) { let returns = context.delegate_call_public_function(self.target_contract, self.selector, self.args); returns.assert_empty() } @@ -218,22 +377,47 @@ impl PublicVoidCallInterface { } } -struct PublicStaticCallInterface { +impl CallInterface for PublicStaticCallInterface { + fn get_args(self) -> [Field] { + self.args + } + + fn get_original(self) -> fn[Env](PublicContextInputs) -> T { + self.original + } + + fn get_selector(self) -> FunctionSelector { + self.selector + } + + fn get_name(self) -> str { + self.name + } + + fn get_contract_address(self) -> AztecAddress { + self.target_contract + } +} + +struct PublicStaticCallInterface { target_contract: AztecAddress, selector: FunctionSelector, + name: str, args: [Field], gas_opts: GasOpts, + original: fn[Env](PublicContextInputs) -> T } -impl PublicStaticCallInterface { +impl PublicStaticCallInterface { pub fn with_gas(self: &mut Self, gas_opts: GasOpts) -> &mut Self { self.gas_opts = gas_opts; self } - pub fn view(self, context: &mut PublicContext) -> T where T: Deserialize { + pub fn view(self, context: &mut PublicContext) -> T where T: Deserialize { let returns = context.static_call_public_function(self.target_contract, self.selector, self.args, self.gas_opts); - returns.deserialize_into() + let unpacked: T = returns.deserialize_into(); + unpacked } pub fn enqueue_view(self, context: &mut PrivateContext) { @@ -249,20 +433,44 @@ impl PublicStaticCallInterface { } } -struct PublicStaticVoidCallInterface { +impl CallInterface for PublicStaticVoidCallInterface { + fn get_args(self) -> [Field] { + self.args + } + + fn get_original(self) -> fn[Env](PublicContextInputs) -> () { + self.original + } + + fn get_selector(self) -> FunctionSelector { + self.selector + } + + fn get_name(self) -> str { + self.name + } + + fn get_contract_address(self) -> AztecAddress { + self.target_contract + } +} + +struct PublicStaticVoidCallInterface { target_contract: AztecAddress, selector: FunctionSelector, + name: str, args: [Field], gas_opts: GasOpts, + original: fn[Env](PublicContextInputs) -> () } -impl PublicStaticVoidCallInterface { +impl PublicStaticVoidCallInterface { pub fn with_gas(self: &mut Self, gas_opts: GasOpts) -> &mut Self { self.gas_opts = gas_opts; self } - pub fn view(self, context: &mut PublicContext) { + pub fn view(self, context: &mut PublicContext) { let returns = context.static_call_public_function(self.target_contract, self.selector, self.args, self.gas_opts); returns.assert_empty() } diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index 8d02ab3db00..2bdc6b0a51f 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -139,6 +139,8 @@ impl PrivateContext { self.new_note_hashes.push(NoteHash { value: note_hash, counter: self.next_counter() }); } + // TODO(#7112): This function is called with non-zero note hash only in 1 of 25 cases in aztec-packages repo + // - consider creating a separate function with 1 arg for the zero note hash case. fn push_new_nullifier(&mut self, nullifier: Field, nullified_note_hash: Field) { self.new_nullifiers.push(Nullifier { value: nullifier, note_hash: nullified_note_hash, counter: self.next_counter() }); } diff --git a/noir-projects/aztec-nr/aztec/src/context/unconstrained_context.nr b/noir-projects/aztec-nr/aztec/src/context/unconstrained_context.nr index a78e27c1b72..4f115696e5c 100644 --- a/noir-projects/aztec-nr/aztec/src/context/unconstrained_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/unconstrained_context.nr @@ -20,7 +20,7 @@ impl UnconstrainedContext { self.block_number } - fn contract_address(self) -> AztecAddress { + fn this_address(self) -> AztecAddress { self.contract_address } } diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr index 3d9c408afd7..48c0f5bfd69 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/incoming_body.nr @@ -66,9 +66,11 @@ mod test { fn set_header(&mut self, header: NoteHeader) {self.header = header; } - fn compute_nullifier(self, context: &mut PrivateContext) -> Field {1} + fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> (Field, Field) { + (1, 1) + } - fn compute_nullifier_without_context(self) -> Field {1} + fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) {(1,1)} fn serialize_content(self) -> [Field; ADDRESS_NOTE_LEN] { [self.address.to_field(), self.owner.to_field(), self.randomness]} diff --git a/noir-projects/aztec-nr/aztec/src/note/lifecycle.nr b/noir-projects/aztec-nr/aztec/src/note/lifecycle.nr index 2fc786ffc61..501decd69a9 100644 --- a/noir-projects/aztec-nr/aztec/src/note/lifecycle.nr +++ b/noir-projects/aztec-nr/aztec/src/note/lifecycle.nr @@ -57,25 +57,23 @@ pub fn destroy_note( context: &mut PrivateContext, note: Note ) where Note: NoteInterface { - let mut nullifier = 0; - let mut consumed_note_hash: Field = 0; - nullifier = note.compute_nullifier(context); + let (note_hash, nullifier) = note.compute_note_hash_and_nullifier(context); - // We also need the note hash corresponding to the "nullifier" - let header = note.get_header(); - - // A non-zero note hash counter implies that we're nullifying a transient note (i.e. one that has not yet been - // persisted in the trees and is instead if the pending new commitments array). In such a case we compute its hash - // to inform the kernel which note we're nullifyng so that it can find it and squash both the note and the - // nullifier. This value is unused when nullifying non transient notes - in that case the kernel simply persists - // the nullifier in the tree. - if (header.note_hash_counter != 0) { - // TODO(1718): Can we reuse the note hash computed in `compute_nullifier`? - consumed_note_hash = compute_note_hash_for_consumption(note); - } + let note_hash_counter = note.get_header().note_hash_counter; + let note_hash_for_consumption = if (note_hash_counter == 0) { + // Counter is zero, so we're nullifying a non-transient note and we don't populate the note_hash with real + // value (if we did so the `notifyNullifiedNote` oracle would throw). + 0 + } else { + // A non-zero note hash counter implies that we're nullifying a transient note (i.e. one that has not yet been + // persisted in the trees and is instead in the pending new note hashes array). In such a case we populate its + // hash with real value to inform the kernel which note we're nullifyng so that it can find it and squash both + // the note and the nullifier. + note_hash + }; let nullifier_counter = context.side_effect_counter; - assert(notify_nullified_note(nullifier, consumed_note_hash, nullifier_counter) == 0); + assert(notify_nullified_note(nullifier, note_hash_for_consumption, nullifier_counter) == 0); - context.push_new_nullifier(nullifier, consumed_note_hash) + context.push_new_nullifier(nullifier, note_hash_for_consumption) } diff --git a/noir-projects/aztec-nr/aztec/src/note/note_getter.nr b/noir-projects/aztec-nr/aztec/src/note/note_getter.nr index cef9498d6c8..53648875124 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_getter.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_getter.nr @@ -104,7 +104,7 @@ pub fn get_notes( context: &mut PrivateContext, storage_slot: Field, options: NoteGetterOptions -) -> [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] where Note: NoteInterface { +) -> BoundedVec where Note: NoteInterface { let opt_notes = get_notes_internal(storage_slot, options); constrain_get_notes_internal(context, storage_slot, opt_notes, options) @@ -115,8 +115,8 @@ fn constrain_get_notes_internal( storage_slot: Field, opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], options: NoteGetterOptions -) -> [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] where Note: NoteInterface { - let mut returned_notes = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; +) -> BoundedVec where Note: NoteInterface { + let mut returned_notes = BoundedVec::new(); // The filter is applied first to avoid pushing note read requests for notes we're not interested in. Note that // while the filter function can technically mutate the contents of the notes (as opposed to simply removing some), @@ -126,7 +126,6 @@ fn constrain_get_notes_internal( let filter_args = options.filter_args; let filtered_notes = filter_fn(opt_notes, filter_args); - let mut num_notes = 0; let mut prev_fields = [0; N]; for i in 0..filtered_notes.len() { let opt_note = filtered_notes[i]; @@ -151,14 +150,12 @@ fn constrain_get_notes_internal( // resulting in a smaller circuit and faster proving times. // We write at returned_notes[num_notes] because num_notes is only advanced when we have a value in // filtered_notes. - returned_notes[num_notes] = Option::some(note); - num_notes += 1; + returned_notes.push(note); }; } - assert(num_notes <= options.limit, "Got more notes than limit."); - - assert(num_notes != 0, "Cannot return zero notes"); + assert(returned_notes.len() <= options.limit, "Got more notes than limit."); + assert(returned_notes.len() != 0, "Cannot return zero notes"); returned_notes } @@ -223,12 +220,13 @@ unconstrained fn get_notes_internal( unconstrained pub fn view_notes( storage_slot: Field, options: NoteViewerOptions -) -> [Option; MAX_NOTES_PER_PAGE] where Note: NoteInterface { +) -> BoundedVec where Note: NoteInterface { let (num_selects, select_by_indexes, select_by_offsets, select_by_lengths, select_values, select_comparators, sort_by_indexes, sort_by_offsets, sort_by_lengths, sort_order) = flatten_options(options.selects, options.sorts); let placeholder_opt_notes = [Option::none(); MAX_NOTES_PER_PAGE]; let placeholder_fields = [0; VIEW_NOTE_ORACLE_RETURN_LENGTH]; let placeholder_note_length = [0; N]; - oracle::notes::get_notes( + + let notes_array = oracle::notes::get_notes( storage_slot, num_selects, select_by_indexes, @@ -246,7 +244,16 @@ unconstrained pub fn view_notes( placeholder_opt_notes, placeholder_fields, placeholder_note_length - ) + ); + + let mut notes = BoundedVec::new(); + for i in 0..notes_array.len() { + if notes_array[i].is_some() { + notes.push(notes_array[i].unwrap_unchecked()); + } + } + + notes } unconstrained fn flatten_options( diff --git a/noir-projects/aztec-nr/aztec/src/note/note_getter/test.nr b/noir-projects/aztec-nr/aztec/src/note/note_getter/test.nr index 7229268f1e5..42d28e25a05 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_getter/test.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_getter/test.nr @@ -9,22 +9,35 @@ use crate::{ }; use dep::protocol_types::address::AztecAddress; -use crate::test::{helpers::context_builder::ContextBuilder, mocks::mock_note::MockNote}; +use crate::test::{helpers::{test_environment::TestEnvironment, cheatcodes}, mocks::mock_note::MockNote}; -global contract_address = AztecAddress::from_field(69); global storage_slot: Field = 42; -fn setup() -> PrivateContext { - ContextBuilder::new().contract_address(contract_address).private() +fn setup() -> TestEnvironment { + TestEnvironment::new() } fn build_valid_note(value: Field) -> MockNote { - MockNote::new(value).contract_address(contract_address).storage_slot(storage_slot).build() + MockNote::new(value).contract_address(cheatcodes::get_contract_address()).storage_slot(storage_slot).build() +} + +fn assert_equivalent_vec_and_array(vec: BoundedVec, arr: [Option; N]) where T: Eq { + let mut count = 0; + + for i in 0..N { + if arr[i].is_some() { + assert_eq(arr[i].unwrap(), vec.get(count)); + count += 1; + } + } + + assert_eq(count, vec.len()); } #[test] fn processes_single_note() { - let mut context = setup(); + let mut env = setup(); + let mut context = env.private(); let mut notes_to_constrain = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; notes_to_constrain[0] = Option::some(build_valid_note(13)); @@ -32,13 +45,14 @@ fn processes_single_note() { let options = NoteGetterOptions::new(); let returned = constrain_get_notes_internal(&mut context, storage_slot, notes_to_constrain, options); - assert_eq(returned, notes_to_constrain); + assert_equivalent_vec_and_array(returned, notes_to_constrain); assert_eq(context.note_hash_read_requests.len(), 1); } #[test] fn processes_many_notes() { - let mut context = setup(); + let mut env = setup(); + let mut context = env.private(); let mut notes_to_constrain = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; notes_to_constrain[0] = Option::some(build_valid_note(13)); @@ -47,13 +61,14 @@ fn processes_many_notes() { let options = NoteGetterOptions::new(); let returned = constrain_get_notes_internal(&mut context, storage_slot, notes_to_constrain, options); - assert_eq(returned, notes_to_constrain); + assert_equivalent_vec_and_array(returned, notes_to_constrain); assert_eq(context.note_hash_read_requests.len(), 2); } #[test] fn collapses_notes_at_the_beginning_of_the_array() { - let mut context = setup(); + let mut env = setup(); + let mut context = env.private(); let mut opt_notes = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; opt_notes[1] = Option::some(build_valid_note(0)); @@ -76,12 +91,13 @@ fn collapses_notes_at_the_beginning_of_the_array() { expected[5] = Option::some(build_valid_note(5)); expected[6] = Option::some(build_valid_note(6)); - assert_eq(returned, expected); + assert_equivalent_vec_and_array(returned, expected); } #[test(should_fail_with="Cannot return zero notes")] - fn rejects_zero_notes() { - let mut context = setup(); +fn rejects_zero_notes() { + let mut env = setup(); + let mut context = env.private(); let opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; @@ -91,7 +107,8 @@ fn collapses_notes_at_the_beginning_of_the_array() { #[test(should_fail_with="Got more notes than limit.")] fn rejects_mote_notes_than_limit() { - let mut context = setup(); + let mut env = setup(); + let mut context = env.private(); let mut opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; opt_notes[1] = Option::some(build_valid_note(0)); @@ -105,7 +122,8 @@ fn rejects_mote_notes_than_limit() { #[test] fn applies_filter_before_constraining() { - let mut context = setup(); + let mut env = setup(); + let mut context = env.private(); let mut notes_to_constrain = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; let invalid_note = MockNote::new(13).build(); // This note does not have the correct address or storage slot @@ -132,13 +150,14 @@ fn applies_filter_before_constraining() { let mut expected = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; expected[0] = Option::some(build_valid_note(42)); - assert_eq(returned, expected); + assert_equivalent_vec_and_array(returned, expected); assert_eq(context.note_hash_read_requests.len(), 1); } #[test(should_fail_with="Mismatch note header contract address.")] fn rejects_mismatched_address() { - let mut context = setup(); + let mut env = setup(); + let mut context = env.private(); let note = MockNote::new(1).storage_slot(storage_slot).build(); // We're not setting the right contract address @@ -151,9 +170,10 @@ fn rejects_mismatched_address() { #[test(should_fail_with="Mismatch note header storage slot.")] fn rejects_mismatched_storage_slot() { - let mut context = setup(); + let mut env = setup(); + let mut context = env.private(); - let note = MockNote::new(1).contract_address(contract_address).build(); // We're not setting the right storage slot + let note = MockNote::new(1).contract_address(cheatcodes::get_contract_address()).build(); // We're not setting the right storage slot let mut opt_notes = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; opt_notes[0] = Option::some(note); @@ -164,7 +184,8 @@ fn rejects_mismatched_storage_slot() { #[test(should_fail_with="Mismatch return note field.")] fn rejects_mismatched_selector() { - let mut context = setup(); + let mut env = setup(); + let mut context = env.private(); let value = 10; let note = build_valid_note(value); @@ -184,7 +205,8 @@ fn rejects_mismatched_selector() { #[test(should_fail_with="Return notes not sorted in descending order.")] fn rejects_mismatched_desc_sort_order() { - let mut context = setup(); + let mut env = setup(); + let mut context = env.private(); let mut opt_notes = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; // Notes in ascending order @@ -201,7 +223,8 @@ fn rejects_mismatched_desc_sort_order() { #[test(should_fail_with="Return notes not sorted in ascending order.")] fn rejects_mismatched_asc_sort_order() { - let mut context = setup(); + let mut env = setup(); + let mut context = env.private(); let mut opt_notes = [Option::none(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]; // Notes in descending order diff --git a/noir-projects/aztec-nr/aztec/src/note/note_interface.nr b/noir-projects/aztec-nr/aztec/src/note/note_interface.nr index c9749de15f8..7206671e3dc 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_interface.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_interface.nr @@ -4,9 +4,9 @@ use dep::protocol_types::grumpkin_point::GrumpkinPoint; // docs:start:note_interface trait NoteInterface { - fn compute_nullifier(self, context: &mut PrivateContext) -> Field; + fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> (Field, Field); - fn compute_nullifier_without_context(self) -> Field; + fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field); // Autogenerated by the #[aztec(note)] macro unless it is overridden by a custom implementation fn serialize_content(self) -> [Field; N]; diff --git a/noir-projects/aztec-nr/aztec/src/note/utils.nr b/noir-projects/aztec-nr/aztec/src/note/utils.nr index cc98cdf96a5..cd587c1a643 100644 --- a/noir-projects/aztec-nr/aztec/src/note/utils.nr +++ b/noir-projects/aztec-nr/aztec/src/note/utils.nr @@ -38,17 +38,9 @@ fn compute_unique_note_hash(note_with_header: Note) -> Field where N } fn compute_siloed_note_hash(note_with_header: Note) -> Field where Note: NoteInterface { - let header = note_with_header.get_header(); - - let unique_note_hash = if (header.nonce == 0) { - // If nonce is zero, that means we are reading a public note. - // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386) - // Remove this once notes added from public also include nonces. - compute_inner_note_hash(note_with_header) - } else { - compute_unique_note_hash(note_with_header) - }; + let unique_note_hash = compute_note_hash_for_read_request(note_with_header); + let header = note_with_header.get_header(); compute_siloed_hash(header.contract_address, unique_note_hash) } @@ -57,7 +49,7 @@ pub fn compute_siloed_nullifier( context: &mut PrivateContext ) -> Field where Note: NoteInterface { let header = note_with_header.get_header(); - let inner_nullifier = note_with_header.compute_nullifier(context); + let (_, inner_nullifier) = note_with_header.compute_note_hash_and_nullifier(context); let input = [header.contract_address.to_field(), inner_nullifier]; pedersen_hash(input, GENERATOR_INDEX__OUTER_NULLIFIER) @@ -70,10 +62,14 @@ pub fn compute_note_hash_for_insertion(note: Note) -> Field where No pub fn compute_note_hash_for_read_request(note: Note) -> Field where Note: NoteInterface { let header = note.get_header(); - if (header.nonce != 0) { - compute_unique_note_hash(note) + let inner_note_hash = compute_inner_note_hash(note); + + // TODO(#1386): This if-else can be nuked once we have nonces injected from public + if (header.nonce == 0) { + // If nonce is zero, that means we are reading a public note. + inner_note_hash } else { - compute_inner_note_hash(note) + compute_unique_hash(header.nonce, inner_note_hash) } } @@ -112,8 +108,7 @@ pub fn compute_note_hash_and_optionally_a_nullifier( serialized_note: [Field; S] // docs:end:compute_note_hash_and_optionally_a_nullifier_args ) -> [Field; 4] where T: NoteInterface { let mut note = deserialize_content(arr_copy_slice(serialized_note, [0; N], 0)); - // TODO: change this to note.set_header(header) once https://github.com/noir-lang/noir/issues/4095 is fixed - T::set_header((&mut note), note_header); + note.set_header(note_header); let inner_note_hash = compute_inner_note_hash(note); @@ -128,7 +123,8 @@ pub fn compute_note_hash_and_optionally_a_nullifier( let siloed_note_hash = compute_siloed_hash(note_header.contract_address, unique_note_hash); let inner_nullifier = if compute_nullifier { - note.compute_nullifier_without_context() + let (_, nullifier) = note.compute_note_hash_and_nullifier_without_context(); + nullifier } else { 0 }; diff --git a/noir-projects/aztec-nr/aztec/src/oracle/public_call.nr b/noir-projects/aztec-nr/aztec/src/oracle/public_call.nr index 0116bf0b0ae..ed56c88fad8 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/public_call.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/public_call.nr @@ -1,5 +1,4 @@ use dep::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress}; -// TODO(6052): get new side effect counter from this call #[oracle(callPublicFunction)] unconstrained fn call_public_function_oracle( _contract_address: AztecAddress, diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/private_immutable.nr b/noir-projects/aztec-nr/aztec/src/state_vars/private_immutable.nr index e6c01bd3212..0c310180181 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/private_immutable.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/private_immutable.nr @@ -76,7 +76,7 @@ impl PrivateImmutable { // docs:start:view_note unconstrained pub fn view_note(self) -> Note where Note: NoteInterface { let mut options = NoteViewerOptions::new(); - view_notes(self.storage_slot, options.set_limit(1))[0].unwrap() + view_notes(self.storage_slot, options.set_limit(1)).get(0) } // docs:end:view_note } diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable.nr b/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable.nr index 1a66e07692c..cf0ee4d7aac 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable.nr @@ -36,8 +36,8 @@ impl PrivateMutable { // Under such circumstances, such application developers might wish to _not_ use this state variable type. // This is especially dangerous for initial assignment to elements of a `Map` type (for example), because the storage slot often also identifies an actor. e.g. // the initial assignment to `my_map.at(msg.sender)` will leak: `msg.sender`, the fact that an element of `my_map` was assigned-to for the first time, and the contract_address. - // Note: subsequent nullification of this state variable, via the `replace` method will not be leaky, if the `compute_nullifier()` method of the underlying note is designed to ensure privacy. - // For example, if the `compute_nullifier()` method injects the secret key of a note owner into the computed nullifier's preimage. + // Note: subsequent nullification of this state variable, via the `replace` method will not be leaky, if the `compute_note_hash_and_nullifier()` method of the underlying note is designed to ensure privacy. + // For example, if the `compute_note_hash_and_nullifier()` method injects the secret key of a note owner into the computed nullifier's preimage. pub fn compute_initialization_nullifier(self) -> Field { pedersen_hash( [self.storage_slot], @@ -118,7 +118,7 @@ impl PrivateMutable { // docs:start:view_note unconstrained pub fn view_note(self) -> Note where Note: NoteInterface { let mut options = NoteViewerOptions::new(); - view_notes(self.storage_slot, options.set_limit(1))[0].unwrap() + view_notes(self.storage_slot, options.set_limit(1)).get(0) } // docs:end:view_note } diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable/test.nr b/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable/test.nr index aca21ab515a..c3949a8e03e 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable/test.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/private_mutable/test.nr @@ -1,14 +1,16 @@ use dep::protocol_types::{address::AztecAddress, grumpkin_point::GrumpkinPoint}; use crate::{context::PrivateContext, state_vars::private_mutable::PrivateMutable}; -use crate::test::{mocks::mock_note::MockNote, helpers::context_builder::ContextBuilder}; +use crate::test::{mocks::mock_note::MockNote, helpers::{cheatcodes, test_environment::TestEnvironment}}; use dep::std::{unsafe::zeroed, test::OracleMock}; -global contract_address = AztecAddress::from_field(13); global storage_slot = 17; -fn setup() -> PrivateMutable { - let mut context = ContextBuilder::new().contract_address(contract_address).private(); - let state_var = PrivateMutable::new(&mut context, storage_slot); +fn setup() -> TestEnvironment { + TestEnvironment::new() +} + +fn in_private(env: &mut TestEnvironment) -> PrivateMutable { + let state_var = PrivateMutable::new(&mut env.private(), storage_slot); // This oracle is called for its side effects alone - it's always expected to return 0. OracleMock::mock("notifyCreatedNote").returns(0); @@ -18,13 +20,14 @@ fn setup() -> PrivateMutable { #[test] fn test_initialize_or_replace_without_nullifier() { - let state_var = setup(); + let mut env = setup(); + let state_var = in_private(&mut env); let ovpk_m: GrumpkinPoint = zeroed(); let ivpk_m: GrumpkinPoint = zeroed(); let value = 42; - let mut note = MockNote::new(value).contract_address(contract_address).storage_slot(storage_slot).build(); + let mut note = MockNote::new(value).contract_address(cheatcodes::get_contract_address()).storage_slot(storage_slot).build(); OracleMock::mock("checkNullifierExists").returns(0); state_var.initialize_or_replace(&mut note).discard(); diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr b/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr index 07a2552be26..1e9125d9bb7 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr @@ -58,10 +58,8 @@ impl PrivateSet { pub fn get_notes( self, options: NoteGetterOptions - ) -> [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] where Note: NoteInterface { - let storage_slot = self.storage_slot; - let opt_notes = get_notes(self.context, storage_slot, options); - opt_notes + ) -> BoundedVec where Note: NoteInterface { + get_notes(self.context, self.storage_slot, options) } // docs:end:get_notes } @@ -71,7 +69,7 @@ impl PrivateSet { unconstrained pub fn view_notes( self, options: NoteViewerOptions - ) -> [Option; MAX_NOTES_PER_PAGE] where Note: NoteInterface { + ) -> BoundedVec where Note: NoteInterface { view_notes(self.storage_slot, options) } // docs:end:view_notes diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/public_immutable/test.nr b/noir-projects/aztec-nr/aztec/src/state_vars/public_immutable/test.nr new file mode 100644 index 00000000000..7614ffff1d1 --- /dev/null +++ b/noir-projects/aztec-nr/aztec/src/state_vars/public_immutable/test.nr @@ -0,0 +1,53 @@ +use crate::{context::PublicContext, state_vars::public_immutable::PublicImmutable}; +use crate::test::{helpers::test_environment::TestEnvironment, mocks::mock_struct::MockStruct}; +use dep::protocol_types::traits::Serialize; + +global storage_slot = 7; + +fn setup() -> TestEnvironment { + TestEnvironment::new() +} + +fn in_public(env: TestEnvironment) -> PublicImmutable { + PublicImmutable::new(&mut env.public(), storage_slot) +} + +#[test] +fn test_uninitialized_by_default() { + let env = setup(); + let state_var = in_public(env); + + assert_eq(state_var.is_initialized(), false); +} + +#[test] +fn test_initialize_uninitialized() { + let env = setup(); + let state_var = in_public(env); + + let value = MockStruct::new(5, 6); + + state_var.initialize(value); + + assert(state_var.is_initialized()); + assert(state_var.read() == value); +} + +#[test(should_fail_with="PublicImmutable already initialized")] +fn test_initialize_already_initialized() { + let env = setup(); + let state_var = in_public(env); + + let value = MockStruct::new(5, 6); + + state_var.initialize(value); + state_var.initialize(value); +} + +#[test(should_fail_with="PublicImmutable not initialized")] +fn test_read_uninitialized() { + let env = setup(); + let state_var = in_public(env); + + let _ = state_var.read(); +} diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/test.nr b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/test.nr index 6403f166e9e..b193640a54b 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/test.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/test.nr @@ -1,377 +1,363 @@ -use dep::std::{merkle::compute_merkle_root, test::OracleMock}; - use crate::{ - context::{PublicContext, PrivateContext}, - state_vars::shared_mutable::{ - shared_mutable::SharedMutable, scheduled_value_change::ScheduledValueChange, - scheduled_delay_change::ScheduledDelayChange -}, - test::helpers::context_builder::ContextBuilder, oracle::get_public_data_witness::PublicDataWitness -}; - -use dep::protocol_types::{ - constants::{GENERATOR_INDEX__PUBLIC_LEAF_INDEX, PUBLIC_DATA_TREE_HEIGHT}, hash::pedersen_hash, - address::AztecAddress, public_data_tree_leaf_preimage::PublicDataTreeLeafPreimage + context::{PublicContext, PrivateContext}, state_vars::shared_mutable::shared_mutable::SharedMutable, + test::helpers::test_environment::TestEnvironment }; -global pre_value = 13; -global post_value = 42; +use dep::protocol_types::address::AztecAddress; global new_value = 57; global pre_delay = 20; global post_delay = 15; -global TEST_INITIAL_DELAY = 3; +global storage_slot = 57; -fn setup() -> (SharedMutable, Field) { - let block_number = 40; - let mut context = ContextBuilder::new().block_number(block_number).public(); +global TEST_INITIAL_DELAY: u32 = 30; - let storage_slot = 57; - let state_var = SharedMutable::new(&mut context, storage_slot); - - (state_var, block_number) +fn setup() -> TestEnvironment { + TestEnvironment::new() } -fn mock_value_change_read( - state_var: SharedMutable, - pre: Field, - post: Field, - block_of_change: Field -) { - let value_change_slot = state_var.get_value_change_storage_slot(); - let fields = ScheduledValueChange::new(pre, post, block_of_change as u32).serialize(); - - let _ = OracleMock::mock("storageRead").with_params((value_change_slot, 3)).returns(fields).times(1); +fn in_public(env: TestEnvironment) -> SharedMutable { + SharedMutable::new(&mut env.public(), storage_slot) } -fn mock_delay_change_read( - state_var: SharedMutable, - pre: Field, - post: Field, - block_of_change: Field -) { - let delay_change_slot = state_var.get_delay_change_storage_slot(); - let delay_change: ScheduledDelayChange = ScheduledDelayChange::new( - Option::some(pre as u32), - Option::some(post as u32), - block_of_change as u32 - ); - let fields = delay_change.serialize(); - - let _ = OracleMock::mock("storageRead").with_params((delay_change_slot, 1)).returns(fields).times(1); +fn in_private( + env: &mut TestEnvironment, + historical_block_number: u32 +) -> SharedMutable { + SharedMutable::new(&mut env.private_at(historical_block_number), storage_slot) } -fn mock_delay_change_read_uninitialized(state_var: SharedMutable) { - let delay_change_slot = state_var.get_delay_change_storage_slot(); - let _ = OracleMock::mock("storageRead").with_params((delay_change_slot, 1)).returns([0]).times(1); -} +// #[test] +// fn test_get_current_value_in_public_initial() { +// let env = setup(); +// let state_var = in_public(env); -// Useful since change and delay values are always the global pre/post ones, so we typically only care about their -// block of change. -fn mock_value_and_delay_read( - state_var: SharedMutable, - value_block_of_change: Field, - delay_block_of_change: Field -) { - mock_value_change_read(state_var, pre_value, post_value, value_block_of_change); - mock_delay_change_read(state_var, pre_delay, post_delay, delay_block_of_change); -} +// // 0 is the default empty value for a Field +// assert_eq(state_var.get_current_value_in_public(), 0); +// } -fn mock_value_change_write() -> OracleMock { - OracleMock::mock("storageWrite").returns([0; 3]) -} +// #[test] +// fn test_get_current_value_in_public_before_scheduled_change() { +// let mut env = setup(); +// let state_var = in_public(env); -fn mock_delay_change_write() -> OracleMock { - OracleMock::mock("storageWrite").returns([0; 1]) -} +// state_var.schedule_value_change(new_value); -fn assert_value_change_write( - state_var: SharedMutable, - mock: OracleMock, - pre: Field, - post: Field, - block_of_change: Field -) { - let fields = ScheduledValueChange::new(pre, post, block_of_change as u32).serialize(); - assert_eq(mock.get_last_params(), (state_var.get_value_change_storage_slot(), fields)); -} +// let (_, block_of_change) = state_var.get_scheduled_value_in_public(); -fn assert_delay_change_write( - state_var: SharedMutable, - mock: OracleMock, - pre: Field, - post: Field, - block_of_change: Field -) { - let delay_change: ScheduledDelayChange = ScheduledDelayChange::new( - Option::some(pre as u32), - Option::some(post as u32), - block_of_change as u32 - ); - - let fields = delay_change.serialize(); - assert_eq(mock.get_last_params(), (state_var.get_delay_change_storage_slot(), fields)); -} +// let original_value = 0; -#[test] -fn test_get_current_value_in_public() { - let (state_var, block_number) = setup(); +// // The current value has not changed +// assert_eq(state_var.get_current_value_in_public(), original_value); - // Change in the future, current value is pre - mock_value_change_read(state_var, pre_value, post_value, block_number + 1); - assert_eq(state_var.get_current_value_in_public(), pre_value); +// // The current value still does not change right before the block of change +// env.advance_block_to(block_of_change - 1); +// assert_eq(state_var.get_current_value_in_public(), original_value); +// } - // Change in the current block, current value is post - mock_value_change_read(state_var, pre_value, post_value, block_number); - assert_eq(state_var.get_current_value_in_public(), post_value); +// #[test] +// fn test_get_current_value_in_public_at_scheduled_change() { +// let mut env = setup(); +// let state_var = in_public(env); - // Change in the past, current value is post - mock_value_change_read(state_var, pre_value, post_value, block_number - 1); - assert_eq(state_var.get_current_value_in_public(), post_value); -} +// state_var.schedule_value_change(new_value); -#[test] -fn test_get_scheduled_value_in_public() { - let (state_var, block_number) = setup(); +// let (_, block_of_change) = state_var.get_scheduled_value_in_public(); - // Change in the future, scheduled is post (always is) - mock_value_change_read(state_var, pre_value, post_value, block_number + 1); - assert_eq(state_var.get_scheduled_value_in_public(), (post_value, (block_number + 1) as u32)); +// env.advance_block_to(block_of_change); +// assert_eq(state_var.get_current_value_in_public(), new_value); +// } - // Change in the current block, scheduled is post (always is) - mock_value_change_read(state_var, pre_value, post_value, block_number); - assert_eq(state_var.get_scheduled_value_in_public(), (post_value, block_number as u32)); +// #[test] +// fn test_get_current_value_in_public_after_scheduled_change() { +// let mut env = setup(); +// let state_var = in_public(env); - // Change in the past, scheduled is post (always is) - mock_value_change_read(state_var, pre_value, post_value, block_number - 1); - assert_eq(state_var.get_scheduled_value_in_public(), (post_value, (block_number - 1) as u32)); -} +// state_var.schedule_value_change(new_value); -#[test] -fn test_get_current_delay_in_public() { - let (state_var, block_number) = setup(); +// let (_, block_of_change) = state_var.get_scheduled_value_in_public(); - // Uninitialized - mock_delay_change_read_uninitialized(state_var); - assert_eq(state_var.get_current_delay_in_public(), TEST_INITIAL_DELAY as u32); +// env.advance_block_to(block_of_change + 10); +// assert_eq(state_var.get_current_value_in_public(), new_value); +// } - // Change in the future, current value is pre - mock_delay_change_read(state_var, pre_delay, post_delay, block_number + 1); - assert_eq(state_var.get_current_delay_in_public(), pre_delay as u32); +// #[test] +// fn test_get_current_value_in_private_before_change() { +// let mut env = setup(); - // Change in the current block, current value is post - mock_delay_change_read(state_var, pre_delay, post_delay, block_number); - assert_eq(state_var.get_current_delay_in_public(), post_delay as u32); +// let public_state_var = in_public(env); +// public_state_var.schedule_value_change(new_value); - // Change in the past, current value is post - mock_delay_change_read(state_var, pre_delay, post_delay, block_number - 1); - assert_eq(state_var.get_current_delay_in_public(), post_delay as u32); -} +// let (_, block_of_change) = public_state_var.get_scheduled_value_in_public(); -#[test] -fn test_get_scheduled_delay_in_public_before_change() { - let (state_var, block_number) = setup(); +// let schedule_block_number = env.block_number(); - // Uninitialized - mock_delay_change_read_uninitialized(state_var); - assert_eq(state_var.get_scheduled_delay_in_public(), (TEST_INITIAL_DELAY as u32, 0)); +// let private_state_var = in_private(&mut env, schedule_block_number); +// assert_eq(private_state_var.get_current_value_in_private(), 0); +// assert_eq(private_state_var.context.max_block_number.unwrap(), block_of_change - 1); +// } - // Change in the future, scheduled is post (always is) - mock_delay_change_read(state_var, pre_delay, post_delay, block_number + 1); - assert_eq(state_var.get_scheduled_delay_in_public(), (post_delay as u32, (block_number + 1) as u32)); +// #[test] +// fn test_get_current_value_in_private_immediately_before_change() { +// let mut env = setup(); - // Change in the current block, scheduled is post (always is) - mock_delay_change_read(state_var, pre_delay, post_delay, block_number); - assert_eq(state_var.get_scheduled_delay_in_public(), (post_delay as u32, block_number as u32)); +// let public_state_var = in_public(env); +// public_state_var.schedule_value_change(new_value); - // Change in the past, scheduled is post (always is) - mock_delay_change_read(state_var, pre_delay, post_delay, block_number - 1); - assert_eq(state_var.get_scheduled_delay_in_public(), (post_delay as u32, (block_number - 1) as u32)); -} +// let (_, block_of_change) = public_state_var.get_scheduled_value_in_public(); -#[test] -fn test_schedule_value_change_no_delay() { - let (state_var, block_number) = setup(); +// let private_state_var = in_private(&mut env, block_of_change - 1); - // Last value change was in the past - mock_value_change_read(state_var, pre_value, post_value, 0); +// assert_eq(private_state_var.get_current_value_in_private(), 0); +// assert_eq(private_state_var.context.max_block_number.unwrap(), block_of_change - 1); +// } - // Current delay is 0 - mock_delay_change_read(state_var, 0, 0, block_number); +// #[test] +// fn test_get_current_value_in_private_at_change() { +// let mut env = setup(); - let write_mock = mock_value_change_write(); +// let public_state_var = in_public(env); +// public_state_var.schedule_value_change(new_value); - state_var.schedule_value_change(new_value); +// let (_, block_of_change) = public_state_var.get_scheduled_value_in_public(); - // The new value has a block of change equal to the current block, i.e. it is the current value - assert_value_change_write(state_var, write_mock, post_value, new_value, block_number); -} +// let historical_block_number = block_of_change; +// let private_state_var = in_private(&mut env, historical_block_number); +// assert_eq(private_state_var.get_current_value_in_private(), new_value); +// assert_eq( +// private_state_var.context.max_block_number.unwrap(), historical_block_number + TEST_INITIAL_DELAY +// ); +// } -#[test] -fn test_schedule_value_change_before_change_no_scheduled_delay() { - let (state_var, block_number) = setup(); +// #[test] +// fn test_get_current_value_in_private_after_change() { +// let mut env = setup(); - // Value change in the future, delay change in the past - mock_value_and_delay_read(state_var, block_number + 1, block_number - 1); - let write_mock = mock_value_change_write(); +// let public_state_var = in_public(env); +// public_state_var.schedule_value_change(new_value); - state_var.schedule_value_change(new_value); +// let (_, block_of_change) = public_state_var.get_scheduled_value_in_public(); - // The new scheduled value change replaces the old one, post delay (current) is used - assert_value_change_write( - state_var, - write_mock, - pre_value, - new_value, - block_number + post_delay - ); -} +// let historical_block_number = block_of_change + 10; +// let private_state_var = in_private(&mut env, historical_block_number); +// assert_eq(private_state_var.get_current_value_in_private(), new_value); +// assert_eq( +// private_state_var.context.max_block_number.unwrap(), historical_block_number + TEST_INITIAL_DELAY +// ); +// } -#[test] -fn test_schedule_value_change_before_change_scheduled_delay() { - let (state_var, block_number) = setup(); +// #[test] +// fn test_get_current_delay_in_public() { +// let (state_var, block_number) = setup(); - // Value change in the future, delay change in the future - mock_value_and_delay_read(state_var, block_number + 1, block_number + 1); +// // Uninitialized +// mock_delay_change_read_uninitialized(state_var); +// assert_eq(state_var.get_current_delay_in_public(), TEST_INITIAL_DELAY as u32); - let write_mock = mock_value_change_write(); +// // Change in the future, current value is pre +// mock_delay_change_read(state_var, pre_delay, post_delay, block_number + 1); +// assert_eq(state_var.get_current_delay_in_public(), pre_delay as u32); - state_var.schedule_value_change(new_value); +// // Change in the current block, current value is post +// mock_delay_change_read(state_var, pre_delay, post_delay, block_number); +// assert_eq(state_var.get_current_delay_in_public(), post_delay as u32); - // The new scheduled value change replaces the old one, pre delay (current, not scheduled) is used - assert_value_change_write( - state_var, - write_mock, - pre_value, - new_value, - block_number + pre_delay - ); -} +// // Change in the past, current value is post +// mock_delay_change_read(state_var, pre_delay, post_delay, block_number - 1); +// assert_eq(state_var.get_current_delay_in_public(), post_delay as u32); +// } -#[test] -fn test_schedule_value_change_after_change_no_scheduled_delay() { - let (state_var, block_number) = setup(); +// #[test] +// fn test_get_scheduled_delay_in_public_before_change() { +// let (state_var, block_number) = setup(); - // Value change in the past, delay change in the past - mock_value_and_delay_read(state_var, block_number - 1, block_number - 1); - let write_mock = mock_value_change_write(); +// // Uninitialized +// mock_delay_change_read_uninitialized(state_var); +// assert_eq(state_var.get_scheduled_delay_in_public(), (TEST_INITIAL_DELAY as u32, 0)); - state_var.schedule_value_change(new_value); +// // Change in the future, scheduled is post (always is) +// mock_delay_change_read(state_var, pre_delay, post_delay, block_number + 1); +// assert_eq(state_var.get_scheduled_delay_in_public(), (post_delay as u32, (block_number + 1) as u32)); - // The previous post value becomes the pre value, post delay (current) is used - assert_value_change_write( - state_var, - write_mock, - post_value, - new_value, - block_number + post_delay - ); -} +// // Change in the current block, scheduled is post (always is) +// mock_delay_change_read(state_var, pre_delay, post_delay, block_number); +// assert_eq(state_var.get_scheduled_delay_in_public(), (post_delay as u32, block_number as u32)); -#[test] -fn test_schedule_value_change_after_change_scheduled_delay() { - let (state_var, block_number) = setup(); +// // Change in the past, scheduled is post (always is) +// mock_delay_change_read(state_var, pre_delay, post_delay, block_number - 1); +// assert_eq(state_var.get_scheduled_delay_in_public(), (post_delay as u32, (block_number - 1) as u32)); +// } - // Value change in the past, delay change in the future - mock_value_and_delay_read(state_var, block_number - 1, block_number + 1); +// #[test] +// fn test_schedule_value_change_no_delay() { +// let (state_var, block_number) = setup(); - let write_mock = mock_value_change_write(); +// // Last value change was in the past +// mock_value_change_read(state_var, pre_value, post_value, 0); + +// // Current delay is 0 +// mock_delay_change_read(state_var, 0, 0, block_number); + +// let write_mock = mock_value_change_write(); - state_var.schedule_value_change(new_value); - - // The previous post value becomes the pre value, pre delay (current, not scheduled) is used - assert_value_change_write( - state_var, - write_mock, - post_value, - new_value, - block_number + pre_delay - ); -} - -#[test] -fn test_schedule_delay_increase_before_change() { - let (state_var, block_number) = setup(); - - // Delay change in future, current delay is pre - mock_delay_change_read(state_var, pre_delay, post_delay, block_number + 1); - let write_mock = mock_delay_change_write(); - - let new_delay = pre_delay + 1; - state_var.schedule_delay_change(new_delay as u32); - - // The previous scheduled change is lost, change is immediate (due to increase) - assert_delay_change_write(state_var, write_mock, pre_delay, new_delay, block_number); -} - -#[test] -fn test_schedule_delay_reduction_before_change() { - let (state_var, block_number) = setup(); - - // Delay change in future, current delay is pre - mock_delay_change_read(state_var, pre_delay, post_delay, block_number + 1); - let write_mock = mock_delay_change_write(); - - let new_delay = pre_delay - 1; - state_var.schedule_delay_change(new_delay as u32); - - // The previous scheduled change is lost, change delay equals difference (due to reduction) - assert_delay_change_write( - state_var, - write_mock, - pre_delay, - new_delay, - block_number + pre_delay - new_delay - ); -} - -#[test] -fn test_schedule_delay_increase_after_change() { - let (state_var, block_number) = setup(); - - // Delay change in the past, current delay is post - mock_delay_change_read(state_var, pre_delay, post_delay, block_number - 1); - let write_mock = mock_delay_change_write(); - - let new_delay = post_delay + 1; - state_var.schedule_delay_change(new_delay as u32); - - // The current value becomes pre, change is immediate (due to increase) - assert_delay_change_write(state_var, write_mock, post_delay, new_delay, block_number); -} - -#[test] -fn test_schedule_delay_reduction_after_change() { - let (state_var, block_number) = setup(); - - // Delay change in the past, current delay is post - mock_delay_change_read(state_var, pre_delay, post_delay, block_number - 1); - let write_mock = mock_delay_change_write(); - - let new_delay = post_delay - 1; - state_var.schedule_delay_change(new_delay as u32); - - // The current value becomes pre, change delay equals difference (due to reduction) - assert_delay_change_write( - state_var, - write_mock, - post_delay, - new_delay, - block_number + post_delay - new_delay - ); -} - -#[test] -fn test_get_current_value_in_private_before_change() { - // Here we'd want to test that the private getter returns the correct value and sets max_block_number in the - // context to the expected block horizon, in all the possible scenarios (long before change, before near change, - // after change). - // However, this requires mocking the getPublicDataTreeWitness oracle so that we can convince the circuit that - // it got a valid historical proof. Because we can set the tree root to whatever we want in the context, this is - // trivial for a single historical value (we add a leaf and compute the root with any random path), but is quite - // hard if we're reading more than one value for the same root (as SharedMutable does): we essentially need to - // create an actual indexed tree and compute the correct path for each of the inserted values. - // TODO: implement an actual tree and use it here https://github.com/AztecProtocol/aztec-packages/issues/5494 -} +// state_var.schedule_value_change(new_value); + +// // The new value has a block of change equal to the current block, i.e. it is the current value +// assert_value_change_write(state_var, write_mock, post_value, new_value, block_number); +// } + +// #[test] +// fn test_schedule_value_change_before_change_no_scheduled_delay() { +// let (state_var, block_number) = setup(); + +// // Value change in the future, delay change in the past +// mock_value_and_delay_read(state_var, block_number + 1, block_number - 1); +// let write_mock = mock_value_change_write(); + +// state_var.schedule_value_change(new_value); + +// // The new scheduled value change replaces the old one, post delay (current) is used +// assert_value_change_write( +// state_var, +// write_mock, +// pre_value, +// new_value, +// block_number + post_delay +// ); +// } + +// #[test] +// fn test_schedule_value_change_before_change_scheduled_delay() { +// let (state_var, block_number) = setup(); + +// // Value change in the future, delay change in the future +// mock_value_and_delay_read(state_var, block_number + 1, block_number + 1); + +// let write_mock = mock_value_change_write(); + +// state_var.schedule_value_change(new_value); + +// // The new scheduled value change replaces the old one, pre delay (current, not scheduled) is used +// assert_value_change_write( +// state_var, +// write_mock, +// pre_value, +// new_value, +// block_number + pre_delay +// ); +// } + +// #[test] +// fn test_schedule_value_change_after_change_no_scheduled_delay() { +// let (state_var, block_number) = setup(); + +// // Value change in the past, delay change in the past +// mock_value_and_delay_read(state_var, block_number - 1, block_number - 1); +// let write_mock = mock_value_change_write(); + +// state_var.schedule_value_change(new_value); + +// // The previous post value becomes the pre value, post delay (current) is used +// assert_value_change_write( +// state_var, +// write_mock, +// post_value, +// new_value, +// block_number + post_delay +// ); +// } + +// #[test] +// fn test_schedule_value_change_after_change_scheduled_delay() { +// let (state_var, block_number) = setup(); + +// // Value change in the past, delay change in the future +// mock_value_and_delay_read(state_var, block_number - 1, block_number + 1); + +// let write_mock = mock_value_change_write(); + +// state_var.schedule_value_change(new_value); + +// // The previous post value becomes the pre value, pre delay (current, not scheduled) is used +// assert_value_change_write( +// state_var, +// write_mock, +// post_value, +// new_value, +// block_number + pre_delay +// ); +// } + +// #[test] +// fn test_schedule_delay_increase_before_change() { +// let (state_var, block_number) = setup(); + +// // Delay change in future, current delay is pre +// mock_delay_change_read(state_var, pre_delay, post_delay, block_number + 1); +// let write_mock = mock_delay_change_write(); + +// let new_delay = pre_delay + 1; +// state_var.schedule_delay_change(new_delay as u32); + +// // The previous scheduled change is lost, change is immediate (due to increase) +// assert_delay_change_write(state_var, write_mock, pre_delay, new_delay, block_number); +// } + +// #[test] +// fn test_schedule_delay_reduction_before_change() { +// let (state_var, block_number) = setup(); + +// // Delay change in future, current delay is pre +// mock_delay_change_read(state_var, pre_delay, post_delay, block_number + 1); +// let write_mock = mock_delay_change_write(); + +// let new_delay = pre_delay - 1; +// state_var.schedule_delay_change(new_delay as u32); + +// // The previous scheduled change is lost, change delay equals difference (due to reduction) +// assert_delay_change_write( +// state_var, +// write_mock, +// pre_delay, +// new_delay, +// block_number + pre_delay - new_delay +// ); +// } + +// #[test] +// fn test_schedule_delay_increase_after_change() { +// let (state_var, block_number) = setup(); + +// // Delay change in the past, current delay is post +// mock_delay_change_read(state_var, pre_delay, post_delay, block_number - 1); +// let write_mock = mock_delay_change_write(); + +// let new_delay = post_delay + 1; +// state_var.schedule_delay_change(new_delay as u32); + +// // The current value becomes pre, change is immediate (due to increase) +// assert_delay_change_write(state_var, write_mock, post_delay, new_delay, block_number); +// } + +// #[test] +// fn test_schedule_delay_reduction_after_change() { +// let (state_var, block_number) = setup(); + +// // Delay change in the past, current delay is post +// mock_delay_change_read(state_var, pre_delay, post_delay, block_number - 1); +// let write_mock = mock_delay_change_write(); + +// let new_delay = post_delay - 1; +// state_var.schedule_delay_change(new_delay as u32); + +// // The current value becomes pre, change delay equals difference (due to reduction) +// assert_delay_change_write( +// state_var, +// write_mock, +// post_delay, +// new_delay, +// block_number + post_delay - new_delay +// ); +// } \ No newline at end of file diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/storage.nr b/noir-projects/aztec-nr/aztec/src/state_vars/storage.nr index 0f8cce2323c..8ae9faf228c 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/storage.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/storage.nr @@ -8,9 +8,8 @@ trait Storage where T: Serialize + Deserialize { // Struct representing an exportable storage variable in the contract // Every entry in the storage struct will be exported in the compilation artifact as a -// Storable entity, containing the storage slot and the type of the variable -struct Storable { +// Storable entity, containing the storage slot +struct Storable { slot: Field, - typ: str } diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers.nr b/noir-projects/aztec-nr/aztec/src/test/helpers.nr index c5c7a4b5f31..b28a85add1c 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers.nr @@ -1 +1,4 @@ -mod context_builder; +mod test_environment; +mod cheatcodes; +mod types; +mod keys; diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr new file mode 100644 index 00000000000..014757cf9b0 --- /dev/null +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr @@ -0,0 +1,127 @@ +use dep::protocol_types::{abis::function_selector::FunctionSelector, address::{AztecAddress, PartialAddress}}; +use crate::context::inputs::{PublicContextInputs, PrivateContextInputs}; +use crate::test::helpers::types::{Deployer, TestAccount}; +use crate::keys::public_keys::PublicKeys; + +unconstrained pub fn reset() { + oracle_reset(); +} + +unconstrained pub fn get_contract_address() -> AztecAddress { + oracle_get_contract_address() +} + +unconstrained pub fn set_contract_address(address: AztecAddress) { + oracle_set_contract_address(address); +} + +unconstrained pub fn get_block_number() -> u32 { + oracle_get_block_number() +} + +unconstrained pub fn advance_blocks(blocks: u32) { + oracle_time_travel(blocks); +} + +unconstrained pub fn get_private_context_inputs(historical_block_number: u32) -> PrivateContextInputs { + oracle_get_private_context_inputs(historical_block_number) +} + +unconstrained pub fn get_public_context_inputs() -> PublicContextInputs { + oracle_get_public_context_inputs() +} + +unconstrained pub fn deploy( + path: str, + initializer: str, + args: [Field], + public_keys_hash: Field +) -> AztecAddress { + oracle_deploy(path, initializer, args, public_keys_hash) +} + +unconstrained pub fn direct_storage_write( + contract_address: AztecAddress, + storage_slot: Field, + fields: [Field; N] +) { + let _hash = direct_storage_write_oracle(contract_address, storage_slot, fields); +} + +unconstrained pub fn create_account() -> TestAccount { + oracle_create_account() +} + +unconstrained pub fn add_account(secret: Field, partial_address: PartialAddress) -> TestAccount { + oracle_add_account(secret, partial_address) +} + +unconstrained pub fn derive_keys(secret: Field) -> PublicKeys { + oracle_derive_keys(secret) +} + +unconstrained pub fn set_msg_sender(msg_sender: AztecAddress) { + oracle_set_msg_sender(msg_sender) +} + +unconstrained pub fn get_msg_sender() -> AztecAddress { + oracle_get_msg_sender() +} + +unconstrained pub fn get_side_effects_counter() -> u32 { + oracle_get_side_effects_counter() +} + +#[oracle(reset)] +fn oracle_reset() {} + +#[oracle(getContractAddress)] +fn oracle_get_contract_address() -> AztecAddress {} + +#[oracle(setContractAddress)] +fn oracle_set_contract_address(address: AztecAddress) {} + +#[oracle(getBlockNumber)] +fn oracle_get_block_number() -> u32 {} + +#[oracle(timeTravel)] +fn oracle_time_travel(blocks: u32) {} + +#[oracle(getPrivateContextInputs)] +fn oracle_get_private_context_inputs(historical_block_number: u32) -> PrivateContextInputs {} + +#[oracle(getPublicContextInputs)] +fn oracle_get_public_context_inputs() -> PublicContextInputs {} + +#[oracle(deploy)] +fn oracle_deploy( + path: str, + initializer: str, + args: [Field], + public_keys_hash: Field +) -> AztecAddress {} + +#[oracle(directStorageWrite)] +fn direct_storage_write_oracle( + _contract_address: AztecAddress, + _storage_slot: Field, + _values: [Field; N] +) -> [Field; N] {} + +#[oracle(createAccount)] +fn oracle_create_account() -> TestAccount {} + +#[oracle(addAccount)] +fn oracle_add_account(secret: Field, partial_address: PartialAddress) -> TestAccount {} + +#[oracle(deriveKeys)] +fn oracle_derive_keys(secret: Field) -> PublicKeys {} + +#[oracle(getMsgSender)] +fn oracle_get_msg_sender() -> AztecAddress {} + +#[oracle(setMsgSender)] +fn oracle_set_msg_sender(msg_sender: AztecAddress) {} + +#[oracle(getSideEffectsCounter)] +fn oracle_get_side_effects_counter() -> u32 {} diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/context_builder.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/context_builder.nr deleted file mode 100644 index 0b04ac52ccb..00000000000 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/context_builder.nr +++ /dev/null @@ -1,52 +0,0 @@ -use crate::context::{PrivateContext, PublicContext}; -use dep::protocol_types::address::AztecAddress; -use dep::std::test::OracleMock; - -struct ContextBuilder { - block_number: Option, - contract_address: Option, -} - -impl ContextBuilder { - fn new() -> Self { - Self { block_number: Option::none(), contract_address: Option::none() } - } - - fn block_number(&mut self, block_number: Field) -> &mut Self { - self.block_number = Option::some(block_number); - self - } - - fn contract_address(&mut self, contract_address: AztecAddress) -> &mut Self { - self.contract_address = Option::some(contract_address); - self - } - - fn private(&mut self) -> PrivateContext { - let mut context = PrivateContext::empty(); - - if self.block_number.is_some() { - context.inputs.historical_header.global_variables.block_number = self.block_number.unwrap_unchecked(); - } - - if self.contract_address.is_some() { - context.inputs.call_context.storage_contract_address = self.contract_address.unwrap_unchecked(); - } - - context - } - - fn public(&mut self) -> PublicContext { - let mut context = PublicContext::empty(); - - if self.block_number.is_some() { - let _ = OracleMock::mock("avmOpcodeBlockNumber").returns(self.block_number.unwrap()); - } - - if self.contract_address.is_some() { - let _ = OracleMock::mock("avmOpcodeAddress").returns(self.contract_address.unwrap()); - } - - context - } -} diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/keys.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/keys.nr new file mode 100644 index 00000000000..f4c53c95c20 --- /dev/null +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/keys.nr @@ -0,0 +1,18 @@ +use dep::protocol_types::{ + address::AztecAddress, storage::map::derive_storage_slot_in_map, + constants::CANONICAL_KEY_REGISTRY_ADDRESS, grumpkin_point::GrumpkinPoint +}; + +use crate::test::helpers::cheatcodes; + +pub fn store_master_key(key_index: Field, address: AztecAddress, key: GrumpkinPoint) { + let x_coordinate_map_slot = key_index * 2 + 1; + let y_coordinate_map_slot = x_coordinate_map_slot + 1; + let x_coordinate_derived_slot = derive_storage_slot_in_map(x_coordinate_map_slot, address); + let y_coordinate_derived_slot = derive_storage_slot_in_map(y_coordinate_map_slot, address); + + let canonical_registry_address = AztecAddress::from_field(CANONICAL_KEY_REGISTRY_ADDRESS); + + cheatcodes::direct_storage_write(canonical_registry_address, x_coordinate_derived_slot, [key.x]); + cheatcodes::direct_storage_write(canonical_registry_address, y_coordinate_derived_slot, [key.y]); +} diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr new file mode 100644 index 00000000000..142f6fd58f8 --- /dev/null +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr @@ -0,0 +1,207 @@ +use dep::protocol_types::{ + abis::{function_selector::FunctionSelector, private_circuit_public_inputs::PrivateCircuitPublicInputs}, + address::{AztecAddress, PartialAddress}, storage::map::derive_storage_slot_in_map, + constants::CANONICAL_KEY_REGISTRY_ADDRESS, grumpkin_point::GrumpkinPoint, traits::Deserialize +}; + +use crate::context::inputs::{PublicContextInputs, PrivateContextInputs}; +use crate::context::{packed_returns::PackedReturns, call_interfaces::CallInterface}; + +use crate::context::{PrivateContext, PublicContext, PrivateVoidCallInterface}; +use crate::test::helpers::{cheatcodes, types::{Deployer, TestAccount}, keys}; +use crate::keys::constants::{NULLIFIER_INDEX, INCOMING_INDEX, OUTGOING_INDEX, TAGGING_INDEX}; +use crate::hash::hash_args; + +use crate::note::{ + note_header::NoteHeader, note_interface::NoteInterface, + utils::{compute_note_hash_for_insertion, compute_note_hash_for_consumption} +}; +use crate::oracle::notes::notify_created_note; + +struct TestEnvironment { + contract_address: Option, + args_hash: Option, + function_selector: Option +} + +impl TestEnvironment { + fn new() -> Self { + cheatcodes::reset(); + Self { contract_address: Option::none(), args_hash: Option::none(), function_selector: Option::none() } + } + + fn block_number(self) -> u32 { + cheatcodes::get_block_number() + } + + fn advance_block_to(&mut self, block_number: u32) { + let difference = block_number - cheatcodes::get_block_number(); + self.advance_block_by(difference); + } + + fn advance_block_by(&mut self, blocks: u32) { + cheatcodes::advance_blocks(blocks); + } + + fn public(self) -> PublicContext { + PublicContext::empty() + } + + fn private(&mut self) -> PrivateContext { + self.private_at(cheatcodes::get_block_number()) + } + + fn private_at(&mut self, historical_block_number: u32) -> PrivateContext { + if historical_block_number >= cheatcodes::get_block_number() { + self.advance_block_to(historical_block_number + 1); + } + + let mut inputs = cheatcodes::get_private_context_inputs(historical_block_number); + + PrivateContext::new(inputs, 0) + } + + fn create_account(self) -> AztecAddress { + let test_account = cheatcodes::create_account(); + let address = test_account.address; + let keys = test_account.keys; + + keys::store_master_key(NULLIFIER_INDEX, address, keys.npk_m); + keys::store_master_key(INCOMING_INDEX, address, keys.ivpk_m); + keys::store_master_key(OUTGOING_INDEX, address, keys.ovpk_m); + keys::store_master_key(TAGGING_INDEX, address, keys.tpk_m); + + test_account.address + } + + fn create_account_contract(self, secret: Field) -> AztecAddress { + let public_keys = cheatcodes::derive_keys(secret); + let args = &[public_keys.ivpk_m.x, public_keys.ivpk_m.y]; + let address = cheatcodes::deploy( + "@aztec/noir-contracts.js/SchnorrAccount", + "constructor", + args, + public_keys.hash().to_field() + ); + cheatcodes::advance_blocks(1); + let test_account = cheatcodes::add_account(secret, PartialAddress::from_field(address.to_field())); + let address = test_account.address; + let keys = test_account.keys; + + keys::store_master_key(NULLIFIER_INDEX, address, keys.npk_m); + keys::store_master_key(INCOMING_INDEX, address, keys.ivpk_m); + keys::store_master_key(OUTGOING_INDEX, address, keys.ovpk_m); + keys::store_master_key(TAGGING_INDEX, address, keys.tpk_m); + + test_account.address + } + + fn deploy(self, path: str) -> Deployer { + Deployer { path, public_keys_hash: 0 } + } + + fn call_private( + self, + call_interface: C + ) -> T where C: CallInterface, T: Deserialize { + let original_fn = call_interface.get_original(); + let original_msg_sender = cheatcodes::get_msg_sender(); + let original_contract_address = cheatcodes::get_contract_address(); + let target_address = call_interface.get_contract_address(); + + cheatcodes::set_contract_address(target_address); + cheatcodes::set_msg_sender(original_contract_address); + let mut inputs = cheatcodes::get_private_context_inputs(cheatcodes::get_block_number() - 1); + inputs.call_context.function_selector = call_interface.get_selector(); + let public_inputs = original_fn(inputs); + + cheatcodes::set_contract_address(original_contract_address); + cheatcodes::set_msg_sender(original_msg_sender); + PackedReturns::new(public_inputs.returns_hash).unpack_into() + } + + fn call_private_void( + self, + call_interface: C + ) where C: CallInterface { + let original_fn = call_interface.get_original(); + let original_msg_sender = cheatcodes::get_msg_sender(); + let original_contract_address = cheatcodes::get_contract_address(); + let target_address = call_interface.get_contract_address(); + + cheatcodes::set_contract_address(target_address); + cheatcodes::set_msg_sender(original_contract_address); + let mut inputs = cheatcodes::get_private_context_inputs(cheatcodes::get_block_number() - 1); + inputs.call_context.function_selector = call_interface.get_selector(); + let public_inputs = original_fn(inputs); + + cheatcodes::set_contract_address(original_contract_address); + cheatcodes::set_msg_sender(original_msg_sender); + PackedReturns::new(public_inputs.returns_hash).assert_empty(); + } + + fn call_public(self, call_interface: C) -> T where C: CallInterface { + let original_fn = call_interface.get_original(); + let original_msg_sender = cheatcodes::get_msg_sender(); + let original_contract_address = cheatcodes::get_contract_address(); + let target_address = call_interface.get_contract_address(); + + cheatcodes::set_contract_address(target_address); + cheatcodes::set_msg_sender(original_contract_address); + let mut inputs = cheatcodes::get_public_context_inputs(); + inputs.selector = call_interface.get_selector().to_field(); + inputs.args_hash = hash_args(call_interface.get_args()); + let result = original_fn(inputs); + + cheatcodes::set_contract_address(original_contract_address); + cheatcodes::set_msg_sender(original_msg_sender); + result + } + + fn call_public_void(self, call_interface: C) where C: CallInterface { + let original_fn = call_interface.get_original(); + let original_msg_sender = cheatcodes::get_msg_sender(); + let original_contract_address = cheatcodes::get_contract_address(); + let target_address = call_interface.get_contract_address(); + + cheatcodes::set_contract_address(target_address); + cheatcodes::set_msg_sender(original_contract_address); + let mut inputs = cheatcodes::get_public_context_inputs(); + inputs.selector = call_interface.get_selector().to_field(); + inputs.args_hash = hash_args(call_interface.get_args()); + original_fn(inputs); + + cheatcodes::set_contract_address(original_contract_address); + cheatcodes::set_msg_sender(original_msg_sender); + } + + pub fn store_note_in_cache( + self, + note: &mut Note, + storage_slot: Field, + contract_address: AztecAddress + ) where Note: NoteInterface { + let original_contract_address = cheatcodes::get_contract_address(); + cheatcodes::set_contract_address(contract_address); + let note_hash_counter = cheatcodes::get_side_effects_counter(); + + let header = NoteHeader { contract_address, storage_slot, nonce: 0, note_hash_counter }; + // TODO: change this to note.set_header(header) once https://github.com/noir-lang/noir/issues/4095 is fixed + Note::set_header(note, header); + let inner_note_hash = compute_note_hash_for_insertion(*note); + + // TODO: Strong typing required because of https://github.com/noir-lang/noir/issues/4088 + let serialized_note: [Field; N] = Note::serialize_content(*note); + assert( + notify_created_note( + storage_slot, + Note::get_note_type_id(), + serialized_note, + inner_note_hash, + note_hash_counter + ) + == 0 + ); + cheatcodes::set_contract_address(original_contract_address); + } +} diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/types.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/types.nr new file mode 100644 index 00000000000..7baec3523d8 --- /dev/null +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/types.nr @@ -0,0 +1,110 @@ +use dep::protocol_types::{ + traits::{Deserialize, Serialize}, address::AztecAddress, + abis::{function_selector::FunctionSelector, private_circuit_public_inputs::PrivateCircuitPublicInputs} +}; + +use crate::context::inputs::{PublicContextInputs, PrivateContextInputs}; +use crate::context::call_interfaces::CallInterface; +use crate::test::helpers::cheatcodes; +use crate::keys::public_keys::{PUBLIC_KEYS_LENGTH, PublicKeys}; +use crate::hash::hash_args; + +struct Deployer { + path: str, + public_keys_hash: Field + } + +impl Deployer { + pub fn with_private_initializer( + self, + call_interface: C + ) -> AztecAddress where C: CallInterface { + let address = cheatcodes::deploy( + self.path, + call_interface.get_name(), + call_interface.get_args(), + self.public_keys_hash + ); + cheatcodes::advance_blocks(1); + let block_number = cheatcodes::get_block_number(); + let original_fn = call_interface.get_original(); + let original_msg_sender = cheatcodes::get_msg_sender(); + let original_contract_address = cheatcodes::get_contract_address(); + + cheatcodes::set_contract_address(address); + cheatcodes::set_msg_sender(original_contract_address); + let mut inputs = cheatcodes::get_private_context_inputs(block_number - 1); + inputs.call_context.function_selector = call_interface.get_selector(); + let _result = original_fn(inputs); + + cheatcodes::set_contract_address(original_contract_address); + cheatcodes::set_msg_sender(original_msg_sender); + address + } + + pub fn with_public_initializer( + self, + call_interface: C + ) -> AztecAddress where C: CallInterface { + let address = cheatcodes::deploy( + self.path, + call_interface.get_name(), + call_interface.get_args(), + self.public_keys_hash + ); + cheatcodes::advance_blocks(1); + let original_fn = call_interface.get_original(); + let original_msg_sender = cheatcodes::get_msg_sender(); + let original_contract_address = cheatcodes::get_contract_address(); + + cheatcodes::set_contract_address(address); + cheatcodes::set_msg_sender(original_contract_address); + let mut inputs = cheatcodes::get_public_context_inputs(); + inputs.selector = call_interface.get_selector().to_field(); + inputs.args_hash = hash_args(call_interface.get_args()); + let _result: T = original_fn(inputs); + + cheatcodes::set_contract_address(original_contract_address); + cheatcodes::set_msg_sender(original_msg_sender); + address + } + + pub fn without_initializer(self) -> AztecAddress { + let address = cheatcodes::deploy(self.path, "", &[], self.public_keys_hash); + address + } +} + +// Keys length + address +global TEST_ACCOUNT_LENGTH = PUBLIC_KEYS_LENGTH + 1; + +struct TestAccount { + address: AztecAddress, + keys: PublicKeys +} + +impl Serialize for TestAccount { + fn serialize(self) -> [Field; TEST_ACCOUNT_LENGTH] { + let mut output = [0; TEST_ACCOUNT_LENGTH]; + + output[0] = self.address.to_field(); + + for i in 0..PUBLIC_KEYS_LENGTH { + output[i+1] = self.keys.serialize()[i]; + } + output + } +} + +impl Deserialize for TestAccount { + fn deserialize(input: [Field; TEST_ACCOUNT_LENGTH]) -> Self { + let address = AztecAddress::from_field(input[0]); + let mut key_buffer = [0; PUBLIC_KEYS_LENGTH]; + for i in 0..PUBLIC_KEYS_LENGTH { + key_buffer[i] = input[i+1]; + } + let keys = PublicKeys::deserialize(key_buffer); + + Self { address, keys } + } +} diff --git a/noir-projects/aztec-nr/aztec/src/test/mocks.nr b/noir-projects/aztec-nr/aztec/src/test/mocks.nr index fb8ef27c7bf..148cc284a9f 100644 --- a/noir-projects/aztec-nr/aztec/src/test/mocks.nr +++ b/noir-projects/aztec-nr/aztec/src/test/mocks.nr @@ -1 +1,2 @@ mod mock_note; +mod mock_struct; diff --git a/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr b/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr index 8a7b853c794..3e320ec6559 100644 --- a/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr +++ b/noir-projects/aztec-nr/aztec/src/test/mocks/mock_note.nr @@ -39,12 +39,12 @@ impl NoteInterface for MockNote { 0 } - fn compute_nullifier(self, _context: &mut PrivateContext) -> Field { - 0 + fn compute_note_hash_and_nullifier(self, _context: &mut PrivateContext) -> (Field, Field) { + (0, 0) } - fn compute_nullifier_without_context(self) -> Field { - 0 + fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) { + (0, 0) } fn to_be_bytes(self, storage_slot: Field) -> [u8; MOCK_NOTE_BYTES_LENGTH] { diff --git a/noir-projects/aztec-nr/aztec/src/test/mocks/mock_struct.nr b/noir-projects/aztec-nr/aztec/src/test/mocks/mock_struct.nr new file mode 100644 index 00000000000..1a0ed1a304e --- /dev/null +++ b/noir-projects/aztec-nr/aztec/src/test/mocks/mock_struct.nr @@ -0,0 +1,36 @@ +use dep::protocol_types::traits::{Eq, Serialize, Deserialize}; + +struct MockStruct { + a: Field, + b: Field, +} + +impl MockStruct { + fn new(a: Field, b: Field) -> Self { + Self { a, b } + } +} + +impl Eq for MockStruct { + fn eq(self, other: Self) -> bool { + (self.a == other.a) & (self.b == other.b) + } +} + +impl Serialize<2> for MockStruct { + fn serialize(self) -> [Field; 2] { + [self.a, self.b] + } +} + +impl Deserialize<2> for MockStruct { + fn deserialize(fields: [Field; 2]) -> Self { + Self { a: fields[0], b: fields[1] } + } +} + +#[test] +fn test_serde() { + let val = MockStruct::new(5, 6); + assert_eq(val, MockStruct::deserialize(val.serialize())); +} diff --git a/noir-projects/aztec-nr/aztec/src/utils.nr b/noir-projects/aztec-nr/aztec/src/utils.nr index fb41f3fe022..3d3d8910a46 100644 --- a/noir-projects/aztec-nr/aztec/src/utils.nr +++ b/noir-projects/aztec-nr/aztec/src/utils.nr @@ -56,9 +56,9 @@ fn verify_collapse_hints( } last_index = Option::some(input_index); } else { - // We don't technically need to check past the length of the BoundedVec since those slots should not be - // accessible, but its fairly cheap to prevent dirty data from being stored there. - assert_eq(collapsed.get_unchecked(i), dep::std::unsafe::zeroed(), "Dirty collapsed vec"); + // BoundedVec assumes that the unused parts of the storage are zeroed out (e.g. in the Eq impl), so we make + // sure that this property holds. + assert_eq(collapsed.get_unchecked(i), dep::std::unsafe::zeroed(), "Dirty collapsed vec storage"); } } // We now know that: diff --git a/noir-projects/aztec-nr/aztec/src/utils/test.nr b/noir-projects/aztec-nr/aztec/src/utils/test.nr index f24064b972c..d8c1edd5e2f 100644 --- a/noir-projects/aztec-nr/aztec/src/utils/test.nr +++ b/noir-projects/aztec-nr/aztec/src/utils/test.nr @@ -111,7 +111,7 @@ fn verify_collapse_hints_wrong_vec_order() { verify_collapse_hints(original, collapsed, collapsed_to_input_index_mapping); } -#[test(should_fail_with="Dirty collapsed vec")] +#[test(should_fail_with="Dirty collapsed vec storage")] fn verify_collapse_hints_dirty_storage() { let original = [Option::some(7), Option::none(), Option::some(3)]; diff --git a/noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr b/noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr index 0f7103ac9ff..ff23dd0e159 100644 --- a/noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr +++ b/noir-projects/aztec-nr/easy-private-state/src/easy_private_uint.nr @@ -41,13 +41,13 @@ impl EasyPrivateUint<&mut PrivateContext> { // docs:start:get_notes let options = NoteGetterOptions::with_filter(filter_notes_min_sum, subtrahend as Field); - let maybe_notes = self.set.get_notes(options); + let notes = self.set.get_notes(options); // docs:end:get_notes let mut minuend: u64 = 0; for i in 0..options.limit { - if maybe_notes[i].is_some() { - let note = maybe_notes[i].unwrap_unchecked(); + if i < notes.len() { + let note = notes.get_unchecked(i); // Removes the note from the owner's set of notes. // docs:start:remove diff --git a/noir-projects/aztec-nr/value-note/src/balance_utils.nr b/noir-projects/aztec-nr/value-note/src/balance_utils.nr index 35b35d7e2dd..0f4a6715f18 100644 --- a/noir-projects/aztec-nr/value-note/src/balance_utils.nr +++ b/noir-projects/aztec-nr/value-note/src/balance_utils.nr @@ -12,16 +12,16 @@ unconstrained pub fn get_balance_with_offset(set: PrivateSet Field { let options = create_note_getter_options_for_decreasing_balance(max_amount); - let opt_notes = balance.get_notes(options); + let notes = balance.get_notes(options); let mut decremented = 0; for i in 0..options.limit { - if opt_notes[i].is_some() { - let note = opt_notes[i].unwrap_unchecked(); + if i < notes.len() { + let note = notes.get_unchecked(i); decremented += destroy_note(balance, note); } diff --git a/noir-projects/aztec-nr/value-note/src/value_note.nr b/noir-projects/aztec-nr/value-note/src/value_note.nr index d0bf0c65d04..409d6aaa9dc 100644 --- a/noir-projects/aztec-nr/value-note/src/value_note.nr +++ b/noir-projects/aztec-nr/value-note/src/value_note.nr @@ -24,26 +24,28 @@ struct ValueNote { impl NoteInterface for ValueNote { // docs:start:nullifier - fn compute_nullifier(self, context: &mut PrivateContext) -> Field { + fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } // docs:end:nullifier - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } } diff --git a/noir-projects/noir-contracts/Nargo.toml b/noir-projects/noir-contracts/Nargo.toml index 77fbe788429..53dd5747074 100644 --- a/noir-projects/noir-contracts/Nargo.toml +++ b/noir-projects/noir-contracts/Nargo.toml @@ -2,6 +2,7 @@ members = [ "contracts/app_subscription_contract", "contracts/auth_contract", + "contracts/auth_registry_contract", "contracts/avm_initializer_test_contract", "contracts/avm_test_contract", "contracts/fpc_contract", diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr index 6bfaa81c58f..df46548453e 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/main.nr @@ -12,7 +12,7 @@ contract AppSubscription { encrypted_logs::encrypted_note_emission::encode_and_encrypt, protocol_types::{traits::is_empty, grumpkin_point::GrumpkinPoint} }, - authwit::{account::AccountActions, auth_witness::get_auth_witness, auth::assert_current_call_valid_authwit}, + authwit::{auth_witness::get_auth_witness, auth::assert_current_call_valid_authwit}, gas_token::GasToken, token::Token }; diff --git a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr index 389cf3278d5..fb19b8a912e 100644 --- a/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr +++ b/noir-projects/noir-contracts/contracts/app_subscription_contract/src/subscription_note.nr @@ -19,24 +19,26 @@ struct SubscriptionNote { } impl NoteInterface for SubscriptionNote { - fn compute_nullifier(self, context: &mut PrivateContext) -> Field { + fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } } diff --git a/noir-projects/noir-contracts/contracts/auth_registry_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/auth_registry_contract/Nargo.toml new file mode 100644 index 00000000000..fa8615992ec --- /dev/null +++ b/noir-projects/noir-contracts/contracts/auth_registry_contract/Nargo.toml @@ -0,0 +1,9 @@ +[package] +name = "auth_registry_contract" +authors = [""] +compiler_version = ">=0.25.0" +type = "contract" + +[dependencies] +aztec = { path = "../../../aztec-nr/aztec" } +authwit = { path = "../../../aztec-nr/authwit" } diff --git a/noir-projects/noir-contracts/contracts/auth_registry_contract/src/main.nr b/noir-projects/noir-contracts/contracts/auth_registry_contract/src/main.nr new file mode 100644 index 00000000000..2992e6cf496 --- /dev/null +++ b/noir-projects/noir-contracts/contracts/auth_registry_contract/src/main.nr @@ -0,0 +1,123 @@ +contract AuthRegistry { + use dep::aztec::{state_vars::{PublicMutable, Map}, protocol_types::address::AztecAddress}; + use dep::authwit::auth::{IS_VALID_SELECTOR, compute_outer_authwit_hash, assert_current_call_valid_authwit}; + + #[aztec(storage)] + struct Storage { + reject_all: Map>, + // on_behalf_of => authwit hash => authorized + approved_actions: Map>>, + } + + /** + * Updates the `authorized` value for `msg_sender` for `message_hash`. + * + * @param message_hash The message hash being authorized + * @param authorize True if the caller is authorized to perform the message hash, false otherwise + */ + #[aztec(public)] + fn set_authorized(message_hash: Field, authorize: bool) { + storage.approved_actions.at(context.msg_sender()).at(message_hash).write(authorize); + } + + /** + * Updates the `reject_all` value for `msg_sender`. + * + * When `reject_all` is `true` any `consume` on `msg_sender` will revert. + * + * @param reject True if all actions should be rejected, false otherwise + */ + #[aztec(public)] + fn set_reject_all(reject: bool) { + storage.reject_all.at(context.msg_sender()).write(reject); + } + + /** + * Consumes an `inner_hash` on behalf of `on_behalf_of` if the caller is authorized to do so. + * + * Will revert even if the caller is authorized if `reject_all` is set to true for `on_behalf_of`. + * This is to support "mass-revoke". + * + * @param on_behalf_of The address on whose behalf the action is being consumed + * @param inner_hash The inner_hash of the authwit + * @return `IS_VALID_SELECTOR` if the action was consumed, revert otherwise + */ + #[aztec(public)] + fn consume(on_behalf_of: AztecAddress, inner_hash: Field) -> Field { + assert_eq(false, storage.reject_all.at(on_behalf_of).read(), "rejecting all"); + + let message_hash = compute_outer_authwit_hash( + context.msg_sender(), + context.chain_id(), + context.version(), + inner_hash + ); + + let authorized = storage.approved_actions.at(on_behalf_of).at(message_hash).read(); + + assert_eq(true, authorized, "unauthorized"); + storage.approved_actions.at(on_behalf_of).at(message_hash).write(false); + + IS_VALID_SELECTOR + } + + /** + * Updates a public authwit using a private authwit + * + * Useful for the case where you want someone else to insert a public authwit for you. + * For example, if Alice wants Bob to insert an authwit in public, such that they can execute + * a trade, Alice can create a private authwit, and Bob can call this function with it. + * + * @param approver The address of the approver (Alice in the example) + * @param message_hash The message hash to authorize + * @param authorize True if the message hash should be authorized, false otherwise + */ + #[aztec(private)] + fn set_authorized_private(approver: AztecAddress, message_hash: Field, authorize: bool) { + assert_current_call_valid_authwit(&mut context, approver); + AuthRegistry::at(context.this_address())._set_authorized(approver, message_hash, authorize).enqueue(&mut context); + } + + /** + * Internal function to update the `authorized` value for `approver` for `messageHash`. + * Used along with `set_authorized_private` to update the public authwit. + * + * @param approver The address of the approver + * @param message_hash The message hash being authorized + * @param authorize True if the caller is authorized to perform the message hash, false otherwise + */ + #[aztec(public)] + #[aztec(internal)] + fn _set_authorized(approver: AztecAddress, message_hash: Field, authorize: bool) { + storage.approved_actions.at(approver).at(message_hash).write(authorize); + } + + /** + * Fetches the `reject_all` value for `on_behalf_of`. + * + * @param on_behalf_of The address to check + * @return True if all actions are rejected, false otherwise + */ + #[aztec(public)] + #[aztec(view)] + fn is_reject_all(on_behalf_of: AztecAddress) -> bool { + storage.reject_all.at(on_behalf_of).read() + } + + /** + * Fetches the `authorized` value for `on_behalf_of` for `message_hash`. + * + * @param on_behalf_of The address on whose behalf the action is being consumed + * @param message_hash The message hash to check + * @return True if the caller is authorized to perform the action, false otherwise + */ + #[aztec(public)] + #[aztec(view)] + fn is_consumable(on_behalf_of: AztecAddress, message_hash: Field) -> bool { + storage.approved_actions.at(on_behalf_of).at(message_hash).read() + } + + unconstrained fn unconstrained_is_consumable(on_behalf_of: AztecAddress, message_hash: Field) -> pub bool { + storage.approved_actions.at(on_behalf_of).at(message_hash).read() + } +} diff --git a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr index c6271fc42ad..d870e8564f8 100644 --- a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr @@ -24,7 +24,7 @@ contract AvmTest { global big_field_136_bits: Field = 0x991234567890abcdef1234567890abcdef; // Libs - use dep::std::embedded_curve_ops::EmbeddedCurvePoint; + use dep::std::embedded_curve_ops::{EmbeddedCurvePoint, EmbeddedCurveScalar, multi_scalar_mul}; use dep::aztec::protocol_types::constants::CONTRACT_INSTANCE_LENGTH; use dep::aztec::prelude::{Map, Deserialize}; use dep::aztec::state_vars::PublicMutable; @@ -144,6 +144,15 @@ contract AvmTest { added } + #[aztec(public)] + fn variable_base_msm() -> [Field; 3] { + let g = EmbeddedCurvePoint { x: 1, y: 17631683881184975370165255887551781615748388533673675138860, is_infinite: false }; + let scalar = EmbeddedCurveScalar { lo: 3, hi: 0 }; + let scalar2 = EmbeddedCurveScalar { lo: 20, hi: 0 }; + let triple_g = multi_scalar_mul([g, g], [scalar, scalar2]); + triple_g + } + /************************************************************************ * Misc ************************************************************************/ diff --git a/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr b/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr index a5a27fa3f57..7e2dde51083 100644 --- a/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/benchmarking_contract/src/main.nr @@ -31,7 +31,7 @@ contract Benchmarking { let owner_notes = storage.notes.at(owner); let mut getter_options = NoteGetterOptions::new(); let notes = owner_notes.get_notes(getter_options.set_limit(1).set_offset(index)); - let note = notes[0].unwrap_unchecked(); + let note = notes.get_unchecked(0); owner_notes.remove(note); increment(owner_notes, note.value, owner, outgoing_viewer); } diff --git a/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr b/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr index 01d06077fb7..e8ae03dd953 100644 --- a/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr +++ b/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr @@ -123,12 +123,17 @@ impl Deck<&mut PrivateContext> { pub fn get_cards(&mut self, cards: [Card; N]) -> [CardNote; N] { let options = NoteGetterOptions::with_filter(filter_cards, cards); - let maybe_notes = self.set.get_notes(options); + let notes = self.set.get_notes(options); + + // This array will hold the notes that correspond to each of the requested cards. It begins empty (with all the + // options being none) and we gradually fill it up as we find the matching notes. let mut found_cards = [Option::none(); N]; + for i in 0..options.limit { - if maybe_notes[i].is_some() { - let card_note = CardNote::from_note(maybe_notes[i].unwrap_unchecked()); + if i < notes.len() { + let card_note = CardNote::from_note(notes.get_unchecked(i)); + // For each note that we read, we search for a matching card that we have not already marked as found. for j in 0..cards.len() { if found_cards[j].is_none() & (cards[j].strength == card_note.card.strength) @@ -139,6 +144,7 @@ impl Deck<&mut PrivateContext> { } } + // And then we assert that we did indeed find all cards, since found_cards and cards have the same length. found_cards.map( |card_note: Option| { assert(card_note.is_some(), "Card not found"); @@ -156,16 +162,19 @@ impl Deck<&mut PrivateContext> { } impl Deck { - unconstrained pub fn view_cards(self, offset: u32) -> [Option; MAX_NOTES_PER_PAGE] { + unconstrained pub fn view_cards(self, offset: u32) -> BoundedVec { let mut options = NoteViewerOptions::new(); - let opt_notes = self.set.view_notes(options.set_offset(offset)); - let mut opt_cards = [Option::none(); MAX_NOTES_PER_PAGE]; - - for i in 0..opt_notes.len() { - opt_cards[i] = opt_notes[i].map(|note: ValueNote| Card::from_field(note.value)); + let notes = self.set.view_notes(options.set_offset(offset)); + + // TODO: ideally we'd do let cards = notes.map(|note| Cards::from_field(note.value)); + // see https://github.com/noir-lang/noir/pull/5250 + let mut cards = BoundedVec::new(); + cards.len = notes.len(); + for i in 0..notes.len() { + cards.storage[i] = Card::from_field(notes.get_unchecked(i).value); } - opt_cards + cards } } diff --git a/noir-projects/noir-contracts/contracts/card_game_contract/src/main.nr b/noir-projects/noir-contracts/contracts/card_game_contract/src/main.nr index bfb982eef57..df8318028a1 100644 --- a/noir-projects/noir-contracts/contracts/card_game_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/card_game_contract/src/main.nr @@ -117,13 +117,12 @@ contract CardGame { game_storage.write(game_data); } - unconstrained fn view_collection_cards(owner: AztecAddress, offset: u32) -> pub [Option; MAX_NOTES_PER_PAGE] { + unconstrained fn view_collection_cards(owner: AztecAddress, offset: u32) -> pub BoundedVec { let collection = storage.collections.at(owner); - collection.view_cards(offset) } - unconstrained fn view_game_cards(game: u32, player: AztecAddress, offset: u32) -> pub [Option; MAX_NOTES_PER_PAGE] { + unconstrained fn view_game_cards(game: u32, player: AztecAddress, offset: u32) -> pub BoundedVec { let game_deck = storage.game_decks.at(game as Field).at(player); game_deck.view_cards(offset) diff --git a/noir-projects/noir-contracts/contracts/child_contract/src/main.nr b/noir-projects/noir-contracts/contracts/child_contract/src/main.nr index fea13f3b346..ab9483cce2a 100644 --- a/noir-projects/noir-contracts/contracts/child_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/child_contract/src/main.nr @@ -56,7 +56,7 @@ contract Child { let owner_npk_m_hash = header.get_npk_m_hash(&mut context, owner); let mut note = ValueNote::new(new_value, owner_npk_m_hash); - storage.a_map_with_private_values.at(owner).insert(&mut note).emit(encode_and_encrypt(&mut context, context.msg_sender(), owner)); + storage.a_map_with_private_values.at(owner).insert(&mut note).emit(encode_and_encrypt(&mut context, owner, owner)); new_value } @@ -65,7 +65,7 @@ contract Child { let mut options = NoteGetterOptions::new(); options = options.select(ValueNote::properties().value, amount, Option::none()).set_limit(1); let notes = storage.a_map_with_private_values.at(owner).get_notes(options); - notes[0].unwrap_unchecked().value + notes.get_unchecked(0).value } // Increments `current_value` by `new_value` @@ -104,8 +104,6 @@ contract Child { } #[aztec(public)] - // TODO(6052): The logs emitted are currently in the wrong order as we don't update - // counters for nested public calls fn set_value_with_two_nested_calls() { Child::at(context.this_address()).set_value_twice_with_nested_first().call(&mut context); Child::at(context.this_address()).set_value_twice_with_nested_last().call(&mut context); diff --git a/noir-projects/noir-contracts/contracts/claim_contract/src/main.nr b/noir-projects/noir-contracts/contracts/claim_contract/src/main.nr index 7a0b7a15ef0..d191ca8fe8a 100644 --- a/noir-projects/noir-contracts/contracts/claim_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/claim_contract/src/main.nr @@ -38,7 +38,8 @@ contract Claim { // Note: Only the owner of the npk_m will be able to produce the nsk_app and compute this nullifier. // The nullifier is unique to the note and THIS contract because the protocol siloes all nullifiers with // the address of a contract it was emitted from. - context.push_new_nullifier(proof_note.compute_nullifier(&mut context), 0); + let (_, nullifier) = proof_note.compute_note_hash_and_nullifier(&mut context); + context.push_new_nullifier(nullifier, 0); // 4) Finally we mint the reward token to the sender of the transaction Token::at(storage.reward_token.read_private()).mint_public(recipient, proof_note.value).enqueue(&mut context); diff --git a/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr b/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr index cf2a235e798..b843313be4b 100644 --- a/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/counter_contract/src/main.nr @@ -37,4 +37,29 @@ contract Counter { balance_utils::get_balance(counters.at(owner).set) } // docs:end:get_counter + + use dep::aztec::test::{helpers::{cheatcodes, test_environment::TestEnvironment}}; + use dep::aztec::protocol_types::storage::map::derive_storage_slot_in_map; + use dep::aztec::note::note_getter::{MAX_NOTES_PER_PAGE, view_notes}; + use dep::aztec::note::note_viewer_options::NoteViewerOptions; + + #[test] + fn test_initialize() { + // Setup env, generate keys + let mut env = TestEnvironment::new(); + let owner = env.create_account(); + let outgoing_viewer = env.create_account(); + + // Deploy contract and initialize + let initializer = Counter::interface().initialize(5, owner, outgoing_viewer); + let contract_address = env.deploy("@aztec/noir-contracts.js/Counter").with_private_initializer(initializer); + // Read the stored value in the note + + cheatcodes::set_contract_address(contract_address); + let counter_slot = Counter::storage().counters.slot; + let owner_slot = derive_storage_slot_in_map(counter_slot, owner); + let mut options = NoteViewerOptions::new(); + let notes: BoundedVec = view_notes(owner_slot, options); + assert(notes.get(0).value == 5); + } } diff --git a/noir-projects/noir-contracts/contracts/delegated_on_contract/src/main.nr b/noir-projects/noir-contracts/contracts/delegated_on_contract/src/main.nr index 7b7a30fb200..da7a24ce09b 100644 --- a/noir-projects/noir-contracts/contracts/delegated_on_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/delegated_on_contract/src/main.nr @@ -35,7 +35,7 @@ contract DelegatedOn { let mut options = NoteGetterOptions::new(); options = options.select(ValueNote::properties().value, amount, Option::none()).set_limit(1); let notes = storage.a_map_with_private_values.at(owner).get_notes(options); - notes[0].unwrap_unchecked().value + notes.get_unchecked(0).value } unconstrained fn view_public_value() -> pub Field { diff --git a/noir-projects/noir-contracts/contracts/delegator_contract/src/main.nr b/noir-projects/noir-contracts/contracts/delegator_contract/src/main.nr index b2ee7e2f556..8cb753c23e9 100644 --- a/noir-projects/noir-contracts/contracts/delegator_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/delegator_contract/src/main.nr @@ -35,7 +35,7 @@ contract Delegator { let mut options = NoteGetterOptions::new(); options = options.select(ValueNote::properties().value, amount, Option::none()).set_limit(1); let notes = storage.a_map_with_private_values.at(owner).get_notes(options); - notes[0].unwrap_unchecked().value + notes.get_unchecked(0).value } unconstrained fn view_public_value() -> pub Field { diff --git a/noir-projects/noir-contracts/contracts/docs_example_contract/src/main.nr b/noir-projects/noir-contracts/contracts/docs_example_contract/src/main.nr index b56307349b3..9653946054c 100644 --- a/noir-projects/noir-contracts/contracts/docs_example_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/docs_example_contract/src/main.nr @@ -211,17 +211,15 @@ contract DocsExample { } // docs:start:state_vars-NoteGetterOptionsComparatorExampleNoir - unconstrained fn read_note(amount: Field, comparator: u8) -> pub [Option; 10] { + unconstrained fn read_note(amount: Field, comparator: u8) -> pub BoundedVec { let mut options = NoteViewerOptions::new(); - let notes = storage.set.view_notes( + storage.set.view_notes( options.select( CardNote::properties().points, amount, Option::some(comparator) ) - ); - - notes + ) } // docs:end:state_vars-NoteGetterOptionsComparatorExampleNoir diff --git a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr index b51eaecc668..f1c3bd6f080 100644 --- a/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr +++ b/noir-projects/noir-contracts/contracts/docs_example_contract/src/types/card_note.nr @@ -30,24 +30,26 @@ impl CardNote { } impl NoteInterface for CardNote { - fn compute_nullifier(self, context: &mut PrivateContext) -> Field { + fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } } diff --git a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr index 0bc2689891e..1ca27ba7cdd 100644 --- a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/ecdsa_public_key_note.nr @@ -65,24 +65,26 @@ impl NoteInterface f EcdsaPublicKeyNote { x, y, npk_m_hash: serialized_note[4], header: NoteHeader::empty() } } - fn compute_nullifier(self, context: &mut PrivateContext) -> Field { + fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } } diff --git a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/main.nr index f58709b4bd5..0bb6c9c0076 100644 --- a/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/ecdsa_account_contract/src/main.nr @@ -21,8 +21,6 @@ contract EcdsaAccount { public_key: PrivateImmutable, } - global ACCOUNT_ACTIONS_STORAGE_SLOT = 2; - // Creates a new account out of an ECDSA public key to use for signature verification #[aztec(private)] #[aztec(initializer)] @@ -41,36 +39,23 @@ contract EcdsaAccount { // Note: If you globally change the entrypoint signature don't forget to update default_entrypoint.ts #[aztec(private)] fn entrypoint(app_payload: AppPayload, fee_payload: FeePayload) { - let actions = AccountActions::init(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); + let actions = AccountActions::init(&mut context, is_valid_impl); actions.entrypoint(app_payload, fee_payload); } #[aztec(private)] #[aztec(noinitcheck)] fn spend_private_authwit(inner_hash: Field) -> Field { - let actions = AccountActions::init(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); + let actions = AccountActions::init(&mut context, is_valid_impl); actions.spend_private_authwit(inner_hash) } - #[aztec(public)] - fn spend_public_authwit(inner_hash: Field) -> Field { - let actions = AccountActions::init(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); - actions.spend_public_authwit(inner_hash) - } - #[aztec(private)] #[aztec(internal)] fn cancel_authwit(outer_hash: Field) { context.push_new_nullifier(outer_hash, 0); } - #[aztec(public)] - #[aztec(internal)] - fn approve_public_authwit(outer_hash: Field) { - let actions = AccountActions::init(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); - actions.approve_public_authwit(outer_hash) - } - #[contract_library_method] fn is_valid_impl(context: &mut PrivateContext, outer_hash: Field) -> bool { // Load public key from storage diff --git a/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr b/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr index 0e0fe7e2ddd..372b11fbd5b 100644 --- a/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/inclusion_proofs_contract/src/main.nr @@ -55,8 +55,7 @@ contract InclusionProofs { if (nullified) { options = options.set_status(NoteStatus.ACTIVE_OR_NULLIFIED); } - let notes = private_values.get_notes(options); - let maybe_note = notes[0]; + let note = private_values.get_notes(options).get_unchecked(0); // docs:end:get_note_from_pxe // 2) Prove the note inclusion @@ -66,7 +65,7 @@ contract InclusionProofs { context.get_header() }; // docs:start:prove_note_inclusion - header.prove_note_inclusion(maybe_note.unwrap_unchecked()); + header.prove_note_inclusion(note); // docs:end:prove_note_inclusion } @@ -107,8 +106,7 @@ contract InclusionProofs { if (fail_case) { options = options.set_status(NoteStatus.ACTIVE_OR_NULLIFIED); } - let notes = private_values.get_notes(options); - let maybe_note = notes[0]; + let note = private_values.get_notes(options).get_unchecked(0); let header = if (use_block_number) { context.get_header_at(block_number) @@ -116,7 +114,7 @@ contract InclusionProofs { context.get_header() }; // docs:start:prove_note_not_nullified - header.prove_note_not_nullified(maybe_note.unwrap_unchecked(), &mut context); + header.prove_note_not_nullified(note, &mut context); // docs:end:prove_note_not_nullified } @@ -134,8 +132,7 @@ contract InclusionProofs { if (nullified) { options = options.set_status(NoteStatus.ACTIVE_OR_NULLIFIED); } - let notes = private_values.get_notes(options); - let note = notes[0].unwrap(); + let note = private_values.get_notes(options).get(0); // 2) Prove the note validity let header = if (use_block_number) { @@ -155,7 +152,7 @@ contract InclusionProofs { let mut options = NoteGetterOptions::new(); options = options.set_limit(1); let notes = private_values.get_notes(options); - let note = notes[0].unwrap(); + let note = notes.get(0); private_values.remove(note); } diff --git a/noir-projects/noir-contracts/contracts/parent_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/parent_contract/Nargo.toml index 53a4d614564..a91d3bd758c 100644 --- a/noir-projects/noir-contracts/contracts/parent_contract/Nargo.toml +++ b/noir-projects/noir-contracts/contracts/parent_contract/Nargo.toml @@ -6,3 +6,5 @@ type = "contract" [dependencies] aztec = { path = "../../../aztec-nr/aztec" } +child_contract = { path = "../child_contract" } +value_note = { path = "../../../aztec-nr/value-note" } diff --git a/noir-projects/noir-contracts/contracts/parent_contract/src/main.nr b/noir-projects/noir-contracts/contracts/parent_contract/src/main.nr index fb066de5ad6..b8789b55e6f 100644 --- a/noir-projects/noir-contracts/contracts/parent_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/parent_contract/src/main.nr @@ -242,4 +242,49 @@ contract Parent { // Call the target private function context.static_call_public_function(target_contract, target_selector, args); } + + use dep::aztec::test::{helpers::{cheatcodes, test_environment::TestEnvironment}}; + use dep::aztec::protocol_types::storage::map::derive_storage_slot_in_map; + use dep::aztec::note::note_getter::{MAX_NOTES_PER_PAGE, view_notes}; + use dep::aztec::note::note_viewer_options::NoteViewerOptions; + use dep::child_contract::Child; + use dep::value_note::value_note::ValueNote; + + #[test] + fn test_private_call() { + // Setup env, generate keys + let mut env = TestEnvironment::new(); + let owner = env.create_account(); + + // Deploy child contract + let child_contract_address = env.deploy("@aztec/noir-contracts.js/Child").without_initializer(); + cheatcodes::advance_blocks(1); + + // Set value in child through parent + let value_to_set = 7; + let parent_private_set_call_interface = Parent::interface().private_call( + child_contract_address, + FunctionSelector::from_signature("private_set_value(Field,(Field))"), + [value_to_set, owner.to_field()] + ); + let result: Field = env.call_private(parent_private_set_call_interface); + assert(result == value_to_set); + // Read the stored value in the note. We have to change the contract address to the child contract in order to read its notes + cheatcodes::set_contract_address(child_contract_address); + let counter_slot = Child::storage().a_map_with_private_values.slot; + let owner_slot = derive_storage_slot_in_map(counter_slot, owner); + let mut options = NoteViewerOptions::new(); + let notes: BoundedVec = view_notes(owner_slot, options); + let note_value = notes.get(0).value; + assert(note_value == value_to_set); + assert(note_value == result); + // Get value from child through parent + let parent_private_get_call_interface = Parent::interface().private_call( + child_contract_address, + FunctionSelector::from_signature("private_get_value(Field,(Field))"), + [7, owner.to_field()] + ); + let read_result: Field = env.call_private(parent_private_get_call_interface); + assert(note_value == read_result); + } } diff --git a/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr b/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr index 0fb30e0d728..6f5076d4ddf 100644 --- a/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/pending_note_hashes_contract/src/main.nr @@ -40,11 +40,11 @@ contract PendingNoteHashes { let options = NoteGetterOptions::with_filter(filter_notes_min_sum, amount); // get note inserted above - let maybe_notes = owner_balance.get_notes(options); + let notes = owner_balance.get_notes(options); - let note0 = maybe_notes[0].unwrap(); + let note0 = notes.get(0); assert(note.value == note0.value); - assert(maybe_notes[1].is_none()); + assert(notes.len() == 1); owner_balance.remove(note0); @@ -58,10 +58,13 @@ contract PendingNoteHashes { let options = NoteGetterOptions::with_filter(filter_notes_min_sum, amount); // get note (note inserted at bottom of function shouldn't exist yet) - let maybe_notes = owner_balance.get_notes(options); + let notes = owner_balance.get_notes(options); - assert(maybe_notes[0].is_none()); - assert(maybe_notes[1].is_none()); + // TODO https://github.com/AztecProtocol/aztec-packages/issues/7059: clean this test up - we won't actually hit + // this assert because the same one exists in get_notes (we always return at least one note), so all lines after + // this one are effectively dead code. We should find a different way to test what this function attempts to + // test. + assert(notes.len() == 0); let header = context.get_header(); let owner_npk_m_hash = header.get_npk_m_hash(&mut context, owner); @@ -139,7 +142,7 @@ contract PendingNoteHashes { let mut options = NoteGetterOptions::new(); options = options.set_limit(1); - let note = owner_balance.get_notes(options)[0].unwrap(); + let note = owner_balance.get_notes(options).get(0); assert(expected_value == note.value); @@ -154,10 +157,11 @@ contract PendingNoteHashes { let owner_balance = storage.balances.at(owner); let options = NoteGetterOptions::new(); - let maybe_notes = owner_balance.get_notes(options); + let notes = owner_balance.get_notes(options); - assert(maybe_notes[0].is_none()); - assert(maybe_notes[1].is_none()); + // TODO https://github.com/AztecProtocol/aztec-packages/issues/7059: review what this test aimed to test, as + // it's now superfluous: get_notes never returns 0 notes. + assert(notes.len() == 0); } // Test pending note hashes with note insertion done in a nested call @@ -384,7 +388,7 @@ contract PendingNoteHashes { let notes = owner_balance.get_notes(NoteGetterOptions::new()); for i in 0..max_notes_per_call() { - let note = notes[i].unwrap(); + let note = notes.get(i); owner_balance.remove(note); } } diff --git a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr index e679a9fc349..9334077bf57 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/main.nr @@ -6,7 +6,6 @@ contract SchnorrAccount { use dep::std; use dep::aztec::prelude::{AztecAddress, FunctionSelector, NoteHeader, PrivateContext, PrivateImmutable}; - use dep::aztec::state_vars::{Map, PublicMutable}; use dep::aztec::encrypted_logs::encrypted_note_emission::encode_and_encrypt; use dep::authwit::{ entrypoint::{app::AppPayload, fee::FeePayload}, account::AccountActions, @@ -22,7 +21,6 @@ contract SchnorrAccount { // docs:start:storage signing_public_key: PrivateImmutable, // docs:end:storage - approved_actions: Map>, } // Constructs the contract @@ -46,54 +44,23 @@ contract SchnorrAccount { #[aztec(private)] #[aztec(noinitcheck)] fn entrypoint(app_payload: AppPayload, fee_payload: FeePayload) { - let actions = AccountActions::init( - &mut context, - storage.approved_actions.storage_slot, - is_valid_impl - ); + let actions = AccountActions::init(&mut context, is_valid_impl); actions.entrypoint(app_payload, fee_payload); } #[aztec(private)] #[aztec(noinitcheck)] fn spend_private_authwit(inner_hash: Field) -> Field { - let actions = AccountActions::init( - &mut context, - storage.approved_actions.storage_slot, - is_valid_impl - ); + let actions = AccountActions::init(&mut context, is_valid_impl); actions.spend_private_authwit(inner_hash) } - #[aztec(public)] - #[aztec(noinitcheck)] - fn spend_public_authwit(inner_hash: Field) -> Field { - let actions = AccountActions::init( - &mut context, - storage.approved_actions.storage_slot, - is_valid_impl - ); - actions.spend_public_authwit(inner_hash) - } - #[aztec(private)] #[aztec(internal)] fn cancel_authwit(outer_hash: Field) { context.push_new_nullifier(outer_hash, 0); } - #[aztec(public)] - #[aztec(internal)] - #[aztec(noinitcheck)] - fn approve_public_authwit(outer_hash: Field) { - let actions = AccountActions::init( - &mut context, - storage.approved_actions.storage_slot, - is_valid_impl - ); - actions.approve_public_authwit(outer_hash) - } - #[contract_library_method] fn is_valid_impl(context: &mut PrivateContext, outer_hash: Field) -> bool { // docs:start:entrypoint @@ -122,40 +89,26 @@ contract SchnorrAccount { } /** - * @notice Helper function to check the existing and validity of authwitnesses - * @dev TODO: myself and block_number should be removed and passed from a context - * @param myself The address of the contract - * @param block_number The block number to check the nullifier against - * @param check_private Whether to check the validity of the authwitness in private state or not + * @notice Helper function to check validity of private authwitnesses * @param message_hash The message hash of the message to check the validity - * @return An array of two booleans, the first is the validity of the authwitness in the private state, - * the second is the validity of the authwitness in the public state - * Both values will be `false` if the nullifier is spent + * @return True if the message_hash can be consumed, false otherwise */ - unconstrained fn lookup_validity( - myself: AztecAddress, - block_number: u32, - check_private: bool, - message_hash: Field - ) -> pub [bool; 2] { - let valid_in_private = if check_private { - let public_key = storage.signing_public_key.view_note(); - let witness: [Field; 64] = get_auth_witness(message_hash); - let mut signature: [u8; 64] = [0; 64]; - for i in 0..64 { - signature[i] = witness[i] as u8; - } - std::schnorr::verify_signature_slice( - public_key.x, - public_key.y, - signature, - message_hash.to_be_bytes(32) - ) - } else { - false - }; + unconstrained fn lookup_validity(message_hash: Field) -> pub bool { + let public_key = storage.signing_public_key.view_note(); + let witness: [Field; 64] = get_auth_witness(message_hash); + let mut signature: [u8; 64] = [0; 64]; + for i in 0..64 { + signature[i] = witness[i] as u8; + } + let valid_in_private = std::schnorr::verify_signature_slice( + public_key.x, + public_key.y, + signature, + message_hash.to_be_bytes(32) + ); - let valid_in_public = storage.approved_actions.at(message_hash).read(); + let block_number = context.block_number(); + let myself = context.this_address(); // Compute the nullifier and check if it is spent // This will BLINDLY TRUST the oracle, but the oracle is us, and @@ -164,10 +117,6 @@ contract SchnorrAccount { let lower_wit = get_low_nullifier_membership_witness(block_number, siloed_nullifier); let is_spent = lower_wit.leaf_preimage.nullifier == siloed_nullifier; - if is_spent { - [false, false] - } else { - [valid_in_private, valid_in_public] - } + !is_spent & valid_in_private } } diff --git a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr index fdc55f5e363..33a50fb05fd 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_account_contract/src/public_key_note.nr @@ -19,24 +19,26 @@ struct PublicKeyNote { } impl NoteInterface for PublicKeyNote { - fn compute_nullifier(self, context: &mut PrivateContext) -> Field { + fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } } diff --git a/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr index 12c9ab3c7da..3441779536b 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr @@ -12,40 +12,25 @@ contract SchnorrHardcodedAccount { global public_key_x: Field = 0x0ede3d33c920df8fdf43f3e39ed38b0882c25b056620ef52fd016fe811aa2443; global public_key_y: Field = 0x29155934ffaa105323695b5f91faadd84acc21f4a8bda2fad760f992d692bc7f; - global ACCOUNT_ACTIONS_STORAGE_SLOT = 1; - // Note: If you globally change the entrypoint signature don't forget to update default_entrypoint.ts #[aztec(private)] fn entrypoint(app_payload: AppPayload, fee_payload: FeePayload) { - let actions = AccountActions::init(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); + let actions = AccountActions::init(&mut context, is_valid_impl); actions.entrypoint(app_payload, fee_payload); } #[aztec(private)] fn spend_private_authwit(inner_hash: Field) -> Field { - let actions = AccountActions::init(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); + let actions = AccountActions::init(&mut context, is_valid_impl); actions.spend_private_authwit(inner_hash) } - #[aztec(public)] - fn spend_public_authwit(inner_hash: Field) -> Field { - let actions = AccountActions::init(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); - actions.spend_public_authwit(inner_hash) - } - #[aztec(private)] #[aztec(internal)] fn cancel_authwit(outer_hash: Field) { context.push_new_nullifier(outer_hash, 0); } - #[aztec(public)] - #[aztec(internal)] - fn approve_public_authwit(outer_hash: Field) { - let actions = AccountActions::init(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); - actions.approve_public_authwit(outer_hash) - } - // docs:start:is-valid #[contract_library_method] fn is_valid_impl(_context: &mut PrivateContext, outer_hash: Field) -> bool { diff --git a/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr b/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr index 808c1ebc451..ca795fca252 100644 --- a/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/schnorr_single_key_account_contract/src/main.nr @@ -8,40 +8,25 @@ contract SchnorrSingleKeyAccount { use crate::{util::recover_address, auth_oracle::get_auth_witness}; - global ACCOUNT_ACTIONS_STORAGE_SLOT = 1; - // Note: If you globally change the entrypoint signature don't forget to update default_entrypoint.ts #[aztec(private)] fn entrypoint(app_payload: AppPayload, fee_payload: FeePayload) { - let actions = AccountActions::init(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); + let actions = AccountActions::init(&mut context, is_valid_impl); actions.entrypoint(app_payload, fee_payload); } #[aztec(private)] fn spend_private_authwit(inner_hash: Field) -> Field { - let actions = AccountActions::init(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); + let actions = AccountActions::init(&mut context, is_valid_impl); actions.spend_private_authwit(inner_hash) } - #[aztec(public)] - fn spend_public_authwit(inner_hash: Field) -> Field { - let actions = AccountActions::init(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); - actions.spend_public_authwit(inner_hash) - } - #[aztec(private)] #[aztec(internal)] fn cancel_authwit(outer_hash: Field) { context.push_new_nullifier(outer_hash, 0); } - #[aztec(public)] - #[aztec(internal)] - fn approve_public_authwit(outer_hash: Field) { - let actions = AccountActions::init(&mut context, ACCOUNT_ACTIONS_STORAGE_SLOT, is_valid_impl); - actions.approve_public_authwit(outer_hash) - } - #[contract_library_method] fn is_valid_impl(context: &mut PrivateContext, outer_hash: Field) -> bool { let witness = get_auth_witness(outer_hash); diff --git a/noir-projects/noir-contracts/contracts/static_child_contract/src/main.nr b/noir-projects/noir-contracts/contracts/static_child_contract/src/main.nr index 89c31eb8482..9ed71ce290e 100644 --- a/noir-projects/noir-contracts/contracts/static_child_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/static_child_contract/src/main.nr @@ -73,7 +73,7 @@ contract StaticChild { Option::none() ).set_limit(1); let notes = storage.a_private_value.get_notes(options); - notes[0].unwrap_unchecked().value + notes.get_unchecked(0).value } // Increments `current_value` by `new_value` diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index c68563ec1b1..0ec38297670 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -111,9 +111,9 @@ contract Test { options = options.set_status(NoteStatus.ACTIVE_OR_NULLIFIED); } - let opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = get_notes(&mut context, storage_slot, options); + let notes: BoundedVec = get_notes(&mut context, storage_slot, options); - opt_notes[0].unwrap().value + notes.get(0).value } #[aztec(private)] @@ -127,9 +127,9 @@ contract Test { options = options.set_status(NoteStatus.ACTIVE_OR_NULLIFIED); } - let opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = get_notes(&mut context, storage_slot, options); + let notes: BoundedVec = get_notes(&mut context, storage_slot, options); - [opt_notes[0].unwrap().value, opt_notes[1].unwrap().value] + [notes.get(0).value, notes.get(1).value] } unconstrained fn call_view_notes(storage_slot: Field, active_or_nullified: bool) -> pub Field { @@ -142,9 +142,9 @@ contract Test { options = options.set_status(NoteStatus.ACTIVE_OR_NULLIFIED); } - let opt_notes: [Option; MAX_NOTES_PER_PAGE] = view_notes(storage_slot, options); + let notes: BoundedVec = view_notes(storage_slot, options); - opt_notes[0].unwrap().value + notes.get(0).value } unconstrained fn call_view_notes_many(storage_slot: Field, active_or_nullified: bool) -> pub [Field; 2] { @@ -157,9 +157,9 @@ contract Test { options = options.set_status(NoteStatus.ACTIVE_OR_NULLIFIED); } - let opt_notes: [Option; MAX_NOTES_PER_PAGE] = view_notes(storage_slot, options); + let notes: BoundedVec = view_notes(storage_slot, options); - [opt_notes[0].unwrap().value, opt_notes[1].unwrap().value] + [notes.get(0).value, notes.get(1).value] } #[aztec(private)] @@ -169,9 +169,9 @@ contract Test { ); let options = NoteGetterOptions::new(); - let opt_notes: [Option; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL] = get_notes(&mut context, storage_slot, options); + let notes: BoundedVec = get_notes(&mut context, storage_slot, options); - let note = opt_notes[0].unwrap(); + let note = notes.get(0); destroy_note(&mut context, note); } @@ -475,7 +475,7 @@ contract Test { let mut options = NoteGetterOptions::new(); options = options.select(TestNote::properties().value, secret_hash, Option::none()).set_limit(1); let notes = notes_set.get_notes(options); - let note = notes[0].unwrap_unchecked(); + let note = notes.get_unchecked(0); notes_set.remove(note); } @@ -486,12 +486,12 @@ contract Test { // This function is used in the e2e_state_vars to test the SharedMutablePrivateGetter in isolation #[aztec(private)] - fn test_shared_mutable_private_getter( + fn test_shared_mutable_private_getter( contract_address_to_read: AztecAddress, storage_slot_of_shared_mutable: Field - ) -> Field where T: FromField, T: ToField { + ) -> Field { // It's a bit wonky because we need to know the delay for get_current_value_in_private to work correctly - let test: SharedMutablePrivateGetter = SharedMutablePrivateGetter::new( + let test: SharedMutablePrivateGetter = SharedMutablePrivateGetter::new( &mut context, contract_address_to_read, storage_slot_of_shared_mutable diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr b/noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr index bcca5adbab6..5fc660079a4 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/test_note.nr @@ -18,14 +18,14 @@ struct TestNote { impl NoteInterface for TestNote { - fn compute_nullifier(self, _context: &mut PrivateContext) -> Field { + fn compute_note_hash_and_nullifier(self, _context: &mut PrivateContext) -> (Field, Field) { // This note is expected to be shared between users and for this reason can't be nullified using a secret. - 0 + (0, 0) } - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) { // This note is expected to be shared between users and for this reason can't be nullified using a secret. - 0 + (0, 0) } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr index fd4590e5b6a..defab65772e 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/main.nr @@ -173,7 +173,7 @@ contract TokenBlacklist { Option::none() ).set_limit(1); let notes = pending_shields.get_notes(options); - let note = notes[0].unwrap_unchecked(); + let note = notes.get_unchecked(0); // Remove the note from the pending shields set pending_shields.remove(note); diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/balances_map.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/balances_map.nr index 56b63bc7590..a5436a93d95 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/balances_map.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/balances_map.nr @@ -39,16 +39,15 @@ impl BalancesMap { let mut balance = U128::from_integer(0); // docs:start:view_notes let mut options = NoteViewerOptions::new(); - let opt_notes = self.map.at(owner).view_notes(options.set_offset(offset)); + let notes = self.map.at(owner).view_notes(options.set_offset(offset)); // docs:end:view_notes - let len = opt_notes.len(); - for i in 0..len { - if opt_notes[i].is_some() { - balance = balance + opt_notes[i].unwrap_unchecked().get_amount(); + for i in 0..options.limit { + if i < notes.len() { + balance = balance + notes.get_unchecked(i).get_amount(); } } - if (opt_notes[len - 1].is_some()) { - balance = balance + self.balance_of_with_offset(owner, offset + opt_notes.len() as u32); + if (notes.len() == options.limit) { + balance = balance + self.balance_of_with_offset(owner, offset + options.limit); } balance @@ -84,13 +83,13 @@ impl BalancesMap { ) -> OuterNoteEmission where T: NoteInterface + OwnedNote { // docs:start:get_notes let options = NoteGetterOptions::with_filter(filter_notes_min_sum, subtrahend); - let maybe_notes = self.map.at(owner).get_notes(options); + let notes = self.map.at(owner).get_notes(options); // docs:end:get_notes let mut minuend: U128 = U128::from_integer(0); for i in 0..options.limit { - if maybe_notes[i].is_some() { - let note = maybe_notes[i].unwrap_unchecked(); + if i < notes.len() { + let note = notes.get_unchecked(i); // Removes the note from the owner's set of notes. // This will call the the `compute_nullifer` function of the `token_note` diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr index 0a65ce2d54e..e3919f717d3 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/token_note.nr @@ -8,7 +8,6 @@ use dep::aztec::{ trait OwnedNote { fn new(amount: U128, owner_npk_m_hash: Field) -> Self; fn get_amount(self) -> U128; - fn get_owner_npk_m_hash(self) -> Field; } global TOKEN_NOTE_LEN: Field = 3; // 3 plus a header. @@ -27,25 +26,27 @@ struct TokenNote { impl NoteInterface for TokenNote { // docs:start:nullifier - fn compute_nullifier(self, context: &mut PrivateContext) -> Field { + fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } // docs:end:nullifier - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } } @@ -62,8 +63,4 @@ impl OwnedNote for TokenNote { fn get_amount(self) -> U128 { self.amount } - - fn get_owner_npk_m_hash(self) -> Field { - self.npk_m_hash - } } diff --git a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr index c93b9b18956..1eada65f821 100644 --- a/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_blacklist_contract/src/types/transparent_note.nr @@ -41,8 +41,8 @@ impl NoteInterface for Transpa } // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): Ensure nullifier collisions are prevented - fn compute_nullifier(self, _context: &mut PrivateContext) -> Field { - self.compute_nullifier_without_context() + fn compute_note_hash_and_nullifier(self, _context: &mut PrivateContext) -> (Field, Field) { + self.compute_note_hash_and_nullifier_without_context() } // Computing a nullifier in a transparent note is not guarded by making secret a part of the nullifier preimage (as @@ -53,12 +53,13 @@ impl NoteInterface for Transpa // 3) the "get_notes" oracle constrains that the secret hash in the returned note matches the one computed in // circuit. // This achieves that the note can only be spent by the party that knows the secret. - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } } diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr index 4c6db0c5d4d..b263abeff01 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/main.nr @@ -281,7 +281,7 @@ contract Token { Option::none() ).set_limit(1); let notes = pending_shields.get_notes(options); - let note = notes[0].unwrap_unchecked(); + let note = notes.get_unchecked(0); // Remove the note from the pending shields set pending_shields.remove(note); @@ -395,5 +395,75 @@ contract Token { storage.balances.balance_of(owner).to_field() } // docs:end:balance_of_private + + use dep::aztec::test::{helpers::{cheatcodes, test_environment::TestEnvironment}}; + use dep::aztec::protocol_types::storage::map::derive_storage_slot_in_map; + use dep::aztec::note::note_getter::{MAX_NOTES_PER_PAGE, view_notes}; + use dep::aztec::note::note_viewer_options::NoteViewerOptions; + + #[test] + fn test_private_transfer() { + // Setup env, generate keys + let mut env = TestEnvironment::new(); + let owner = env.create_account(); + let recipient = env.create_account(); + let mint_amount = 10000; + + // Start the test in the account contract address + cheatcodes::set_contract_address(owner); + + // Deploy token contract + let initializer_call_interface = Token::interface().constructor( + owner, + "TestToken0000000000000000000000", + "TT00000000000000000000000000000", + 18 + ); + let token_contract_address = env.deploy("@aztec/noir-contracts.js/Token").with_public_initializer(initializer_call_interface); + env.advance_block_by(1); + + // Mint some tokens + let secret = 1; + let secret_hash = compute_secret_hash(secret); + let mint_private_call_interface = Token::at(token_contract_address).mint_private(mint_amount, secret_hash); + env.call_public(mint_private_call_interface); + + // Time travel so we can read keys from the registry + env.advance_block_by(6); + + // Store a note in the cache so we can redeem it + env.store_note_in_cache( + &mut TransparentNote::new(mint_amount, secret_hash), + Token::storage().pending_shields.slot, + token_contract_address + ); + + // Redeem our shielded tokens + let redeem_shield_call_interface = Token::at(token_contract_address).redeem_shield(owner, mint_amount, secret); + env.call_private_void(redeem_shield_call_interface); + + // Not really sure why this is needed? Nullifier inclusion in contract initializer fails otherwise. + // If it were to fail, it should do it at line 443, investigation required + env.advance_block_by(1); + + // Transfer tokens + let transfer_amount = 1000; + let private_token_transfer_call_interface = Token::at(token_contract_address).transfer(recipient, transfer_amount); + env.call_private_void(private_token_transfer_call_interface); + + // Check balances + cheatcodes::set_contract_address(token_contract_address); + + let balances_slot = Token::storage().balances.slot; + let recipient_slot = derive_storage_slot_in_map(balances_slot, recipient); + let mut options = NoteViewerOptions::new(); + let notes: BoundedVec = view_notes(recipient_slot, options); + assert(notes.get(0).amount.to_field() == transfer_amount); + + let owner_slot = derive_storage_slot_in_map(balances_slot, owner); + let mut options = NoteViewerOptions::new(); + let notes: BoundedVec = view_notes(owner_slot, options); + assert(notes.get(0).amount.to_field() == mint_amount - transfer_amount); + } } // docs:end:token_all \ No newline at end of file diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/balances_map.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/balances_map.nr index cada57a7497..a13206360c3 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/balances_map.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/balances_map.nr @@ -42,16 +42,15 @@ impl BalancesMap { let mut balance = U128::from_integer(0); // docs:start:view_notes let mut options = NoteViewerOptions::new(); - let opt_notes = self.map.at(owner).view_notes(options.set_offset(offset)); + let notes = self.map.at(owner).view_notes(options.set_offset(offset)); // docs:end:view_notes - let len = opt_notes.len(); - for i in 0..len { - if opt_notes[i].is_some() { - balance = balance + opt_notes[i].unwrap_unchecked().get_amount(); + for i in 0..options.limit { + if i < notes.len() { + balance = balance + notes.get_unchecked(i).get_amount(); } } - if (opt_notes[len - 1].is_some()) { - balance = balance + self.balance_of_with_offset(owner, offset + opt_notes.len() as u32); + if (notes.len() == options.limit) { + balance = balance + self.balance_of_with_offset(owner, offset + options.limit); } balance @@ -87,13 +86,13 @@ impl BalancesMap { ) -> OuterNoteEmission where T: NoteInterface + OwnedNote { // docs:start:get_notes let options = NoteGetterOptions::with_filter(filter_notes_min_sum, subtrahend); - let maybe_notes = self.map.at(owner).get_notes(options); + let notes = self.map.at(owner).get_notes(options); // docs:end:get_notes let mut minuend: U128 = U128::from_integer(0); for i in 0..options.limit { - if maybe_notes[i].is_some() { - let note = maybe_notes[i].unwrap_unchecked(); + if i < notes.len() { + let note = notes.get_unchecked(i); // Removes the note from the owner's set of notes. // This will call the the `compute_nullifer` function of the `token_note` diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr index 2a797ec83e8..e3919f717d3 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/token_note.nr @@ -2,7 +2,7 @@ use dep::aztec::{ prelude::{AztecAddress, NoteHeader, NoteInterface, PrivateContext}, protocol_types::{constants::GENERATOR_INDEX__NOTE_NULLIFIER, grumpkin_point::GrumpkinPoint, hash::poseidon2_hash}, note::utils::compute_note_hash_for_consumption, oracle::unsafe_rand::unsafe_rand, - note::note_emission::NoteEmission, keys::getters::get_nsk_app + keys::getters::get_nsk_app }; trait OwnedNote { @@ -26,25 +26,27 @@ struct TokenNote { impl NoteInterface for TokenNote { // docs:start:nullifier - fn compute_nullifier(self, context: &mut PrivateContext) -> Field { + fn compute_note_hash_and_nullifier(self, context: &mut PrivateContext) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = context.request_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } // docs:end:nullifier - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); let secret = get_nsk_app(self.npk_m_hash); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, secret, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } } diff --git a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr index c93b9b18956..1eada65f821 100644 --- a/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr +++ b/noir-projects/noir-contracts/contracts/token_contract/src/types/transparent_note.nr @@ -41,8 +41,8 @@ impl NoteInterface for Transpa } // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): Ensure nullifier collisions are prevented - fn compute_nullifier(self, _context: &mut PrivateContext) -> Field { - self.compute_nullifier_without_context() + fn compute_note_hash_and_nullifier(self, _context: &mut PrivateContext) -> (Field, Field) { + self.compute_note_hash_and_nullifier_without_context() } // Computing a nullifier in a transparent note is not guarded by making secret a part of the nullifier preimage (as @@ -53,12 +53,13 @@ impl NoteInterface for Transpa // 3) the "get_notes" oracle constrains that the secret hash in the returned note matches the one computed in // circuit. // This achieves that the note can only be spent by the party that knows the secret. - fn compute_nullifier_without_context(self) -> Field { + fn compute_note_hash_and_nullifier_without_context(self) -> (Field, Field) { let note_hash_for_nullify = compute_note_hash_for_consumption(self); - poseidon2_hash([ + let nullifier = poseidon2_hash([ note_hash_for_nullify, GENERATOR_INDEX__NOTE_NULLIFIER as Field, - ]) + ]); + (note_hash_for_nullify, nullifier) } } diff --git a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr index 0ccd4b5a74b..3bf3f00fb1b 100644 --- a/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/uniswap_contract/src/main.nr @@ -10,7 +10,7 @@ contract Uniswap { use dep::authwit::auth::{ IS_VALID_SELECTOR, assert_current_call_valid_authwit_public, compute_call_authwit_hash, - compute_outer_authwit_hash + compute_outer_authwit_hash, set_authorized }; use dep::token::Token; @@ -19,20 +19,15 @@ contract Uniswap { #[aztec(storage)] struct Storage { - // like with account contracts, stores the approval message on a slot and tracks if they are active - approved_action: Map>, - // tracks the nonce used to create the approval message for burning funds - // gets incremented each time after use to prevent replay attacks - nonce_for_burn_approval: PublicMutable, portal_address: SharedImmutable, } - // docs:end:uniswap_setup #[aztec(public)] #[aztec(initializer)] fn constructor(portal_address: EthAddress) { storage.portal_address.initialize(portal_address); } + // docs:end:uniswap_setup // docs:start:swap_public #[aztec(public)] @@ -153,28 +148,6 @@ contract Uniswap { } // docs:end:swap_private - // docs:start:authwit_uniswap_get - // Since the token bridge burns funds on behalf of this contract, this contract has to tell the token contract if the signature is valid - // implementation is similar to how account contracts validate public approvals. - // if valid, it returns the IS_VALID selector which is expected by token contract - #[aztec(public)] - fn spend_public_authwit(inner_hash: Field) -> Field { - let message_hash = compute_outer_authwit_hash( - context.msg_sender(), - context.chain_id(), - context.version(), - inner_hash - ); - let value = storage.approved_action.at(message_hash).read(); - if (value) { - context.push_new_nullifier(message_hash, 0); - IS_VALID_SELECTOR - } else { - 0 - } - } - // docs:end:authwit_uniswap_get - // docs:start:authwit_uniswap_set // This helper method approves the bridge to burn this contract's funds and exits the input asset to L1 // Assumes contract already has funds. @@ -188,8 +161,10 @@ contract Uniswap { token_bridge: AztecAddress, amount: Field ) { - // approve bridge to burn this contract's funds (required when exiting on L1, as it burns funds on L2): - let nonce_for_burn_approval = storage.nonce_for_burn_approval.read(); + // Since we will authorize and instantly spend the funds, all in public, we can use the same nonce + // every interaction. In practice, the authwit should be squashed, so this is also cheap! + let nonce = 0xdeadbeef; + let selector = FunctionSelector::from_signature("burn_public((Field),Field,Field)"); let message_hash = compute_call_authwit_hash( token_bridge, @@ -197,21 +172,15 @@ contract Uniswap { context.chain_id(), context.version(), selector, - [context.this_address().to_field(), amount, nonce_for_burn_approval] + [context.this_address().to_field(), amount, nonce] ); - storage.approved_action.at(message_hash).write(true); - // increment nonce_for_burn_approval so it won't be used again - storage.nonce_for_burn_approval.write(nonce_for_burn_approval + 1); + // We need to make a call to update it. + set_authorized(&mut context, message_hash, true); let this_portal_address = storage.portal_address.read_public(); // Exit to L1 Uniswap Portal ! - TokenBridge::at(token_bridge).exit_to_l1_public( - this_portal_address, - amount, - this_portal_address, - nonce_for_burn_approval - ).call(&mut context) + TokenBridge::at(token_bridge).exit_to_l1_public(this_portal_address, amount, this_portal_address, nonce).call(&mut context) } // docs:end:authwit_uniswap_set @@ -224,12 +193,5 @@ contract Uniswap { token.eq(TokenBridge::at(token_bridge).get_token().view(&mut context)), "input_asset address is not the same as seen in the bridge contract" ); } - - // /// Unconstrained /// - - // this method exists solely for e2e tests to test that nonce gets incremented each time. - unconstrained fn nonce_for_burn_approval() -> pub Field { - storage.nonce_for_burn_approval.read() - } // docs:end:assert_token_is_same } diff --git a/noir-projects/noir-contracts/extractFunctionAsNoirArtifact.js b/noir-projects/noir-contracts/extractFunctionAsNoirArtifact.js new file mode 100644 index 00000000000..842645d860f --- /dev/null +++ b/noir-projects/noir-contracts/extractFunctionAsNoirArtifact.js @@ -0,0 +1,51 @@ +const path = require("path"); +const fs = require("fs").promises; + +// Simple script to extract a contract function as a separate Noir artifact. +// We need to use this since the transpiling that we do on public functions make the contract artifacts +// unreadable by noir tooling, since they are no longer following the noir artifact format. +async function main() { + let [contractArtifactPath, functionName] = process.argv.slice(2); + if (!contractArtifactPath || !functionName) { + console.log( + "Usage: node extractFunctionAsNoirArtifact.js " + ); + return; + } + + const contractArtifact = JSON.parse( + await fs.readFile(contractArtifactPath, "utf8") + ); + const func = contractArtifact.functions.find((f) => f.name === functionName); + if (!func) { + console.error( + `Function ${functionName} not found in ${contractArtifactPath}` + ); + return; + } + + const artifact = { + noir_version: contractArtifact.noir_version, + hash: 0, + abi: func.abi, + bytecode: func.bytecode, + debug_symbols: func.debug_symbols, + file_map: contractArtifact.file_map, + names: ["main"], + }; + + const outputDir = path.dirname(contractArtifactPath); + const outputName = + path.basename(contractArtifactPath, ".json") + `-${functionName}.json`; + + const outPath = path.join(outputDir, outputName); + + console.log(`Writing to ${outPath}`); + + await fs.writeFile(outPath, JSON.stringify(artifact, null, 2)); +} + +main().catch((err) => { + console.error(err); + process.exit(1); +}); diff --git a/noir-projects/noir-contracts/scripts/flamegraph.sh b/noir-projects/noir-contracts/scripts/flamegraph.sh new file mode 100755 index 00000000000..6ee8d6cfb29 --- /dev/null +++ b/noir-projects/noir-contracts/scripts/flamegraph.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +set -eu + +# If first arg is -h or --help, print usage +if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then + echo "Usage: $0 " + echo "e.g.: $0 Token transfer" + echo "Generates a flamegraph for the given contract and function" + exit 0 +fi + +# Get the directory of the script +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +PROFILER="$SCRIPT_DIR/../../../noir/noir-repo/target/debug/noir-profiler" + +if [ ! -f $PROFILER ]; then + echo "Profiler not found, building profiler" + cd "$SCRIPT_DIR/../../../noir/noir-repo/tooling/profiler" + cargo build + cd "$SCRIPT_DIR" +fi + +# first console arg is contract name in camel case (e.g. TokenBridge) +CONTRACT=$1 + +# second console arg is the contract function +FUNCTION=$2 + +# convert contract name to following format: token_bridge_contract-TokenBridge.json +ARTIFACT=$(echo "$CONTRACT" | sed -r 's/^([A-Z])/\L\1/; s/([a-z0-9])([A-Z])/\1_\L\2/g') +ARTIFACT_NAME="${ARTIFACT}_contract-${CONTRACT}" + +# Extract artifact for the specific function +node "$SCRIPT_DIR/../extractFunctionAsNoirArtifact.js" "$SCRIPT_DIR/../target/${ARTIFACT_NAME}.json" $FUNCTION + +FUNCTION_ARTIFACT="${ARTIFACT_NAME}-${FUNCTION}.json" + +# We create dest directory and use it as an output for the generated main.svg file +mkdir -p "$SCRIPT_DIR/../dest" + +# At last, generate the flamegraph +$PROFILER gates-flamegraph --artifact-path "$SCRIPT_DIR/../target/$FUNCTION_ARTIFACT" --backend-path "$SCRIPT_DIR/../../../barretenberg/cpp/build/bin/bb" --output "$SCRIPT_DIR/../dest" + +# serve the file over http +echo "Serving flamegraph at http://0.0.0.0:8000/main.svg" +python3 -m http.server --directory "$SCRIPT_DIR/../dest" 8000 diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr index 53712f1f157..5c98a585441 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_call_stack_item.nr @@ -69,7 +69,7 @@ mod tests { let call_stack_item = PublicCallStackItem { contract_address, public_inputs, is_execution_request: true, function_data }; // Value from public_call_stack_item.test.ts "Computes a callstack item request hash" test - let test_data_call_stack_item_request_hash = 0x124a62189073cc551fea148d735d1e8b452e38537e075895b02ccfd9c9901819; + let test_data_call_stack_item_request_hash = 0x2751111aa213d9d21279da53531bf90c2da272cf3f959e2a2a1dfceb487bf102; assert_eq(call_stack_item.hash(), test_data_call_stack_item_request_hash); } @@ -87,7 +87,7 @@ mod tests { let call_stack_item = PublicCallStackItem { contract_address, public_inputs, is_execution_request: false, function_data }; // Value from public_call_stack_item.test.ts "Computes a callstack item hash" test - let test_data_call_stack_item_hash = 0x2cbb07062730bfc4933f5e8d533d5b62ac6e1b7922b831993377cd85d7445399; + let test_data_call_stack_item_hash = 0x1860d00d9602966e398c6d585216baba2ffa8c5eddda5faee041136665d8482a; assert_eq(call_stack_item.hash(), test_data_call_stack_item_hash); } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr index d3a9853ec42..cd76145a67e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr @@ -201,6 +201,6 @@ fn empty_hash() { let hash = inputs.hash(); // Value from public_circuit_public_inputs.test.ts "computes empty item hash" test - let test_data_empty_hash = 0x03ab5026ab5b3e6b81be5c3ec31c7937f293180c25a240eb75693cda81bb2a05; + let test_data_empty_hash = 0x01681b19fb7fe21aa9c2cf9fb47520149f46edd679b2e7c2b2c4a279fd685125; assert_eq(hash, test_data_empty_hash); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 05506e03e0d..2d48394e3af 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -22,14 +22,14 @@ global ARGS_LENGTH: u32 = 16; // docs:start:constants // "PER CALL" CONSTANTS -// If modifiying, update avm_kernel.pil / avm_constants.pil offset values (our pil does not yet support constant evaluation so values are hardcoded) +// If modifiying, update avm_kernel.pil / constants.pil offset values (our pil does not yet support constant evaluation so values are hardcoded) global MAX_NEW_NOTE_HASHES_PER_CALL: u32 = 16; global MAX_NEW_NULLIFIERS_PER_CALL: u32 = 16; global MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL: u32 = 4; global MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL: u32 = 16; global MAX_NEW_L2_TO_L1_MSGS_PER_CALL: u32 = 2; global MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL: u32 = 32; -global MAX_PUBLIC_DATA_READS_PER_CALL: u32 = 16; +global MAX_PUBLIC_DATA_READS_PER_CALL: u32 = 32; global MAX_NOTE_HASH_READ_REQUESTS_PER_CALL: u32 = 32; global MAX_NULLIFIER_READ_REQUESTS_PER_CALL: u32 = 32; global MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL: u32 = 32; @@ -51,7 +51,7 @@ global PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX: u32 = 1; // would then result in the type of the constant be a number and not a literal type. This would mess up the types. // Pain. global MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX: u32 = 64; // MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX + PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX; -global MAX_PUBLIC_DATA_READS_PER_TX: u32 = 32; +global MAX_PUBLIC_DATA_READS_PER_TX: u32 = 64; global MAX_NEW_L2_TO_L1_MSGS_PER_TX: u32 = 8; global MAX_NOTE_HASH_READ_REQUESTS_PER_TX: u32 = 128; global MAX_NULLIFIER_READ_REQUESTS_PER_TX: u32 = 128; @@ -68,7 +68,7 @@ global MAX_UNENCRYPTED_LOGS_PER_TX: u32 = 8; // KERNEL CIRCUIT PRIVATE INPUTS CONSTANTS // global MAX_PUBLIC_DATA_HINTS: u32 = MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX + MAX_PUBLIC_DATA_READS_PER_TX; // FIX: Sadly, writing this as above causes a type error in type_conversion.ts. -global MAX_PUBLIC_DATA_HINTS: u32 = 64; +global MAX_PUBLIC_DATA_HINTS: u32 = 128; // ROLLUP CONTRACT CONSTANTS - constants used only in l1-contracts global NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP: u32 = 16; @@ -147,6 +147,7 @@ global FIXED_DA_GAS: u32 = 512; // CANONICAL CONTRACT ADDRESSES global CANONICAL_KEY_REGISTRY_ADDRESS = 0x04c2d010f88e8c238882fbbcbce5c81fdc1dc8ece85e8dbf3f602b4d81ec0351; +global CANONICAL_AUTH_REGISTRY_ADDRESS = 0x27ffa4fb3da8a80b6365315f9798c887474854c71c0720e1c5236861288ce147; global DEPLOYER_CONTRACT_ADDRESS = 0x2b231c13768709b1ba51c1f86275b47e38dfac16e3d7f242cb578d92a4e2d934; global REGISTERER_CONTRACT_ADDRESS = 0x302da9b6000a76691341b250565ca5c67723261fa99af1435ffe5178ccb21417; global GAS_TOKEN_ADDRESS = 0x06fc7badd50bb8ee32439b52e8874b5a16ddd2aa1d5647ec46b2a0f51356f889; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr index 890d1ee3a60..416d3f123b2 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/hash.nr @@ -45,6 +45,8 @@ pub fn compute_note_hash_nonce(first_nullifier: Field, note_hash_index: u32) -> ) } +// TODO(benesjan): some of these functions seem to be duplicate to the ones in +// noir-projects/aztec-nr/aztec/src/note/utils.nr NUKE! fn compute_unique_note_hash(nonce: Field, note_hash: Field) -> Field { pedersen_hash( [ diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr index bce2078479a..01af1206fec 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/traits.nr @@ -110,4 +110,10 @@ impl Serialize for str { trait Deserialize { fn deserialize(fields: [Field; N]) -> Self; } -// docs:end:deserialize \ No newline at end of file +// docs:end:deserialize + +impl Deserialize for [Field; N] { + fn deserialize(fields: [Field; N]) -> Self { + fields + } +} diff --git a/noir/bb-version b/noir/bb-version new file mode 100644 index 00000000000..72a8a6313bb --- /dev/null +++ b/noir/bb-version @@ -0,0 +1 @@ +0.41.0 diff --git a/noir/noir-repo/Cargo.lock b/noir/noir-repo/Cargo.lock index eb058008359..9c4004edffa 100644 --- a/noir/noir-repo/Cargo.lock +++ b/noir/noir-repo/Cargo.lock @@ -1186,6 +1186,19 @@ dependencies = [ "syn 2.0.64", ] +[[package]] +name = "dashmap" +version = "5.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" +dependencies = [ + "cfg-if 1.0.0", + "hashbrown 0.14.5", + "lock_api", + "once_cell", + "parking_lot_core 0.9.8", +] + [[package]] name = "debugid" version = "0.8.0" @@ -1382,6 +1395,15 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" +[[package]] +name = "env_logger" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" +dependencies = [ + "log", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -2017,12 +2039,17 @@ dependencies = [ [[package]] name = "inferno" -version = "0.11.15" +version = "0.11.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fb7c1b80a1dfa604bb4a649a5c5aeef3d913f7c520cb42b40e534e8a61bcdfc" +checksum = "321f0f839cd44a4686e9504b0a62b4d69a50b62072144c71c68f5873c167b8d9" dependencies = [ "ahash 0.8.11", - "indexmap 1.9.3", + "clap", + "crossbeam-channel", + "crossbeam-utils", + "dashmap", + "env_logger", + "indexmap 2.2.6", "is-terminal", "itoa", "log", @@ -2714,6 +2741,29 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "noir_profiler" +version = "0.30.0" +dependencies = [ + "acir", + "clap", + "codespan-reporting", + "color-eyre", + "const_format", + "fm", + "im", + "inferno", + "nargo", + "noirc_abi", + "noirc_driver", + "noirc_errors", + "serde", + "serde_json", + "tempfile", + "tracing-appender", + "tracing-subscriber", +] + [[package]] name = "noir_wasm" version = "0.31.0" diff --git a/noir/noir-repo/Cargo.toml b/noir/noir-repo/Cargo.toml index 129661d157d..f180af01bdf 100644 --- a/noir/noir-repo/Cargo.toml +++ b/noir/noir-repo/Cargo.toml @@ -24,6 +24,7 @@ members = [ "tooling/noirc_abi", "tooling/noirc_abi_wasm", "tooling/acvm_cli", + "tooling/profiler", # ACVM "acvm-repo/acir_field", "acvm-repo/acir", @@ -36,7 +37,7 @@ members = [ # Utility crates "utils/iter-extended", ] -default-members = ["tooling/nargo_cli", "tooling/acvm_cli"] +default-members = ["tooling/nargo_cli", "tooling/acvm_cli", "tooling/profiler"] resolver = "2" [workspace.package] @@ -84,7 +85,7 @@ acvm_cli = { path = "tooling/acvm_cli" } # Arkworks ark-bn254 = { version = "^0.4.0", default-features = false, features = ["curve"] } ark-bls12-381 = { version = "^0.4.0", default-features = false, features = ["curve"] } -grumpkin = { version = "0.1.0", package = "noir_grumpkin", features = ["std"] } +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 } ark-std = { version = "^0.4.0", default-features = false } @@ -143,6 +144,7 @@ similar-asserts = "1.5.0" tempfile = "3.6.0" jsonrpc = { version = "0.16.0", features = ["minreq_http"] } flate2 = "1.0.24" +color-eyre = "0.6.2" rand = "0.8.5" proptest = "1.2.0" proptest-derive = "0.4.0" diff --git a/noir/noir-repo/aztec_macros/src/lib.rs b/noir/noir-repo/aztec_macros/src/lib.rs index a36b7b17d09..d79c7b190ed 100644 --- a/noir/noir-repo/aztec_macros/src/lib.rs +++ b/noir/noir-repo/aztec_macros/src/lib.rs @@ -65,14 +65,8 @@ fn transform( // 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( - crate_id, - &file_id, - context, - &mut submodule.contents, - submodule.name.0.contents.as_str(), - ) - .map_err(|err| (err.into(), file_id))? + if transform_module(&file_id, &mut submodule.contents, submodule.name.0.contents.as_str()) + .map_err(|err| (err.into(), file_id))? { check_for_aztec_dependency(crate_id, context)?; } @@ -87,9 +81,7 @@ fn transform( /// 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( - crate_id: &CrateId, file_id: &FileId, - context: &HirContext, module: &mut SortedModule, module_name: &str, ) -> Result { @@ -106,12 +98,7 @@ fn transform_module( if !check_for_storage_implementation(module, storage_struct_name) { generate_storage_implementation(module, storage_struct_name)?; } - // Make sure we're only generating the storage layout for the root crate - // In case we got a contract importing other contracts for their interface, we - // don't want to generate the storage layout for them - if crate_id == context.root_crate_id() { - generate_storage_layout(module, storage_struct_name.clone())?; - } + generate_storage_layout(module, storage_struct_name.clone(), module_name)?; } for structure in module.types.iter_mut() { @@ -219,7 +206,7 @@ fn transform_module( }); } - generate_contract_interface(module, module_name, &stubs)?; + generate_contract_interface(module, module_name, &stubs, storage_defined)?; } Ok(has_transformed_module) diff --git a/noir/noir-repo/aztec_macros/src/transforms/contract_interface.rs b/noir/noir-repo/aztec_macros/src/transforms/contract_interface.rs index e6ac43ad2c4..50add6d009f 100644 --- a/noir/noir-repo/aztec_macros/src/transforms/contract_interface.rs +++ b/noir/noir-repo/aztec_macros/src/transforms/contract_interface.rs @@ -64,11 +64,7 @@ pub fn stub_function(aztec_visibility: &str, func: &NoirFunction, is_static_call let parameters = func.parameters(); let is_void = if matches!(fn_return_type.typ, UnresolvedTypeData::Unit) { "Void" } else { "" }; let is_static = if is_static_call { "Static" } else { "" }; - let return_type_hint = if is_void == "Void" { - "".to_string() - } else { - format!("<{}>", fn_return_type.typ.to_string().replace("plain::", "")) - }; + let return_type_hint = fn_return_type.typ.to_string().replace("plain::", ""); let call_args = parameters .iter() .map(|arg| { @@ -76,22 +72,67 @@ pub fn stub_function(aztec_visibility: &str, func: &NoirFunction, is_static_call match &arg.typ.typ { UnresolvedTypeData::Array(_, typ) => { format!( - "let hash_{0} = {0}.map(|x: {1}| x.serialize()); - for i in 0..{0}.len() {{ - args_acc = args_acc.append(hash_{0}[i].as_slice()); - }}\n", + "let serialized_{0} = {0}.map(|x: {1}| x.serialize()); + for i in 0..{0}.len() {{ + args_acc = args_acc.append(serialized_{0}[i].as_slice()); + }}\n", param_name, typ.typ.to_string().replace("plain::", "") ) } - _ => { + UnresolvedTypeData::Named(_, _, _) | UnresolvedTypeData::String(_) => { format!("args_acc = args_acc.append({}.serialize().as_slice());\n", param_name) } + _ => { + format!("args_acc = args_acc.append(&[{}.to_field()]);\n", param_name) + } } }) .collect::>() .join(""); - if aztec_visibility != "Public" { + + let param_types = if !parameters.is_empty() { + parameters + .iter() + .map(|param| param.pattern.name_ident().0.contents.clone()) + .collect::>() + .join(", ") + } else { + "".to_string() + }; + + let original = format!( + "| inputs: dep::aztec::context::inputs::{}ContextInputs | -> {} {{ + {}(inputs{}) + }}", + aztec_visibility, + if aztec_visibility == "Private" { + "dep::aztec::protocol_types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs".to_string() + } else { + return_type_hint.clone() + }, + fn_name, + if param_types.is_empty() { "".to_string() } else { format!(" ,{} ", param_types) } + ); + let arg_types = format!( + "({}{})", + parameters + .iter() + .map(|param| param.typ.typ.to_string().replace("plain::", "")) + .collect::>() + .join(","), + // In order to distinguish between a single element Tuple (Type,) and a single type with unnecessary parenthesis around it (Type), + // The latter gets simplified to Type, that is NOT a valid env + if parameters.len() == 1 { "," } else { "" } + ); + + let generics = if is_void == "Void" { + format!("{}>", arg_types) + } else { + format!("{}, {}>", return_type_hint, arg_types) + }; + + let fn_body = if aztec_visibility != "Public" { let args_hash = if !parameters.is_empty() { format!( "let mut args_acc: [Field] = &[]; @@ -101,10 +142,14 @@ pub fn stub_function(aztec_visibility: &str, func: &NoirFunction, is_static_call call_args ) } else { - "let args_hash = 0;".to_string() + " + let mut args_acc: [Field] = &[]; + let args_hash = 0; + " + .to_string() }; - let fn_body = format!( + format!( "{} aztec::context::{}{}{}CallInterface {{ target_contract: self.target_contract, @@ -126,11 +171,12 @@ pub fn stub_function(aztec_visibility: &str, func: &NoirFunction, is_static_call ", call_args ); - let fn_body = format!( + format!( "{} aztec::context::Public{}{}CallInterface {{ target_contract: self.target_contract, - selector: {}, + selector, + name: \"{}\", args: args_acc, gas_opts: aztec::context::gas::GasOpts::default(), }}", @@ -152,7 +198,15 @@ pub fn generate_contract_interface( module: &mut SortedModule, module_name: &str, stubs: &[(String, Location)], + has_storage_layout: bool, ) -> Result<(), AztecMacroError> { + let storage_layout_getter = format!( + "#[contract_library_method] + pub fn storage() -> StorageLayout {{ + {}_STORAGE_LAYOUT + }}", + module_name, + ); let contract_interface = format!( " struct {0} {{ @@ -167,6 +221,12 @@ pub fn generate_contract_interface( ) -> Self {{ Self {{ target_contract }} }} + + pub fn interface() -> Self {{ + Self {{ target_contract: dep::aztec::protocol_types::address::AztecAddress::zero() }} + }} + + {2} }} #[contract_library_method] @@ -175,9 +235,18 @@ pub fn generate_contract_interface( ) -> {0} {{ {0} {{ target_contract }} }} + + #[contract_library_method] + pub fn interface() -> {0} {{ + {0} {{ target_contract: dep::aztec::protocol_types::address::AztecAddress::zero() }} + }} + + {3} ", module_name, stubs.iter().map(|(src, _)| src.to_owned()).collect::>().join("\n"), + if has_storage_layout { storage_layout_getter.clone() } else { "".to_string() }, + if has_storage_layout { format!("#[contract_library_method]\n{}", storage_layout_getter) } else { "".to_string() } ); let (contract_interface_ast, errors) = parse_program(&contract_interface); @@ -194,7 +263,7 @@ pub fn generate_contract_interface( .iter() .enumerate() .map(|(i, (method, orig_span))| { - if method.name() == "at" { + if method.name() == "at" || method.name() == "interface" || method.name() == "storage" { (method.clone(), *orig_span) } else { let (_, new_location) = stubs[i]; @@ -208,7 +277,9 @@ pub fn generate_contract_interface( module.types.push(contract_interface_ast.types.pop().unwrap()); module.impls.push(impl_with_locations); - module.functions.push(contract_interface_ast.functions.pop().unwrap()); + for function in contract_interface_ast.functions { + module.functions.push(function); + } Ok(()) } @@ -247,7 +318,7 @@ pub fn update_fn_signatures_in_contract_interface( let name = context.def_interner.function_name(func_id); let fn_parameters = &context.def_interner.function_meta(func_id).parameters.clone(); - if name == "at" { + if name == "at" || name == "interface" || name == "storage" { continue; } @@ -260,42 +331,29 @@ pub fn update_fn_signatures_in_contract_interface( .collect::>(), ); let hir_func = context.def_interner.function(func_id).block(&context.def_interner); - let call_interface_constructor_statement = context.def_interner.statement( - hir_func - .statements() - .last() - .ok_or((AztecMacroError::AztecDepNotFound, file_id))?, + + let function_selector_statement = context.def_interner.statement( + hir_func.statements().get(hir_func.statements().len() - 2).ok_or(( + AztecMacroError::CouldNotGenerateContractInterface { + secondary_message: Some( + "Function signature statement not found, invalid body length" + .to_string(), + ), + }, + file_id, + ))?, ); - let call_interface_constructor_expression = - match call_interface_constructor_statement { - HirStatement::Expression(expression_id) => { - match context.def_interner.expression(&expression_id) { - HirExpression::Constructor(hir_constructor_expression) => { - Ok(hir_constructor_expression) - } - _ => Err(( - AztecMacroError::CouldNotGenerateContractInterface { - secondary_message: Some( - "CallInterface constructor statement must be a constructor expression" - .to_string(), - ), - }, - file_id, - )), - } - } - _ => Err(( - AztecMacroError::CouldNotGenerateContractInterface { - secondary_message: Some( - "CallInterface constructor statement must be an expression" - .to_string(), - ), - }, - file_id, - )), - }?; - let (_, function_selector_expression_id) = - call_interface_constructor_expression.fields[1]; + let function_selector_expression_id = match function_selector_statement { + HirStatement::Let(let_statement) => Ok(let_statement.expression), + _ => Err(( + AztecMacroError::CouldNotGenerateContractInterface { + secondary_message: Some( + "Function selector statement must be an expression".to_string(), + ), + }, + file_id, + )), + }?; let function_selector_expression = context.def_interner.expression(&function_selector_expression_id); diff --git a/noir/noir-repo/aztec_macros/src/transforms/storage.rs b/noir/noir-repo/aztec_macros/src/transforms/storage.rs index 8b778b4cca6..bac87502c7d 100644 --- a/noir/noir-repo/aztec_macros/src/transforms/storage.rs +++ b/noir/noir-repo/aztec_macros/src/transforms/storage.rs @@ -497,6 +497,7 @@ pub fn assign_storage_slots( pub fn generate_storage_layout( module: &mut SortedModule, storage_struct_name: String, + module_name: &str, ) -> Result<(), AztecMacroError> { let definition = module .types @@ -504,33 +505,28 @@ pub fn generate_storage_layout( .find(|r#struct| r#struct.name.0.contents == *storage_struct_name) .unwrap(); - let mut generic_args = vec![]; let mut storable_fields = vec![]; let mut storable_fields_impl = vec![]; - definition.fields.iter().enumerate().for_each(|(index, (field_ident, field_type))| { - storable_fields.push(format!("{}: aztec::prelude::Storable", field_ident, index)); - generic_args.push(format!("N{}", index)); - storable_fields_impl.push(format!( - "{}: aztec::prelude::Storable {{ slot: 0, typ: \"{}\" }}", - field_ident, - field_type.to_string().replace("plain::", "") - )); + definition.fields.iter().for_each(|(field_ident, _)| { + storable_fields.push(format!("{}: dep::aztec::prelude::Storable", field_ident)); + storable_fields_impl + .push(format!("{}: dep::aztec::prelude::Storable {{ slot: 0 }}", field_ident,)); }); let storage_fields_source = format!( " - struct StorageLayout<{}> {{ + struct StorageLayout {{ {} }} #[abi(storage)] - global STORAGE_LAYOUT = StorageLayout {{ + global {}_STORAGE_LAYOUT = StorageLayout {{ {} }}; ", - generic_args.join(", "), storable_fields.join(",\n"), + module_name, storable_fields_impl.join(",\n") ); diff --git a/noir/noir-repo/compiler/noirc_errors/src/reporter.rs b/noir/noir-repo/compiler/noirc_errors/src/reporter.rs index cb5abbe2079..42cab72345d 100644 --- a/noir/noir-repo/compiler/noirc_errors/src/reporter.rs +++ b/noir/noir-repo/compiler/noirc_errors/src/reporter.rs @@ -202,14 +202,14 @@ fn stack_trace<'files>( let path = files.name(call_item.file).expect("should get file path"); let source = files.source(call_item.file).expect("should get file source"); - let (line, column) = location(source.as_ref(), call_item.span.start()); + let (line, column) = line_and_column_from_span(source.as_ref(), &call_item.span); result += &format!("{}. {}:{}:{}\n", i + 1, path, line, column); } result } -fn location(source: &str, span_start: u32) -> (u32, u32) { +pub fn line_and_column_from_span(source: &str, span: &Span) -> (u32, u32) { let mut line = 1; let mut column = 0; @@ -221,7 +221,7 @@ fn location(source: &str, span_start: u32) -> (u32, u32) { column = 0; } - if span_start <= i as u32 { + if span.start() <= i as u32 { break; } } diff --git a/noir/noir-repo/compiler/noirc_frontend/src/monomorphization/mod.rs b/noir/noir-repo/compiler/noirc_frontend/src/monomorphization/mod.rs index 07820a70b3f..faf8141df22 100644 --- a/noir/noir-repo/compiler/noirc_frontend/src/monomorphization/mod.rs +++ b/noir/noir-repo/compiler/noirc_frontend/src/monomorphization/mod.rs @@ -241,7 +241,9 @@ impl<'interner> Monomorphizer<'interner> { Definition::Oracle(opcode.to_string()) } FunctionKind::Recursive => { - unreachable!("Only main can be specified as recursive, which should already be checked"); + let id = + self.queue_function(id, expr_id, typ, turbofish_generics, trait_method); + Definition::Function(id) } } } diff --git a/noir/noir-repo/docs/docs/how_to/how-to-oracles.md b/noir/noir-repo/docs/docs/how_to/how-to-oracles.md index 2d2ed5c94b9..d6834c09c84 100644 --- a/noir/noir-repo/docs/docs/how_to/how-to-oracles.md +++ b/noir/noir-repo/docs/docs/how_to/how-to-oracles.md @@ -141,10 +141,10 @@ server.addMethod("resolve_function_call", async (params) => { if params.function !== "getSqrt" { throw Error("Unexpected foreign call") }; - const values = params.inputs[0].Array.map((field) => { + const values = params.inputs[0].map((field) => { return `${Math.sqrt(parseInt(field, 16))}`; }); - return { values: [{ Array: values }] }; + return { values }; }); ``` @@ -236,9 +236,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) => i.toString("hex")) }, + input[0].map((i) => i.toString("hex")), ]); - return [oracleReturn.values[0].Array]; + return { values: oracleReturn }; }; // the rest of your NoirJS code diff --git a/noir/noir-repo/tooling/acvm_cli/Cargo.toml b/noir/noir-repo/tooling/acvm_cli/Cargo.toml index 1cfd1f3b270..a592f2d65f3 100644 --- a/noir/noir-repo/tooling/acvm_cli/Cargo.toml +++ b/noir/noir-repo/tooling/acvm_cli/Cargo.toml @@ -20,7 +20,7 @@ path = "src/main.rs" [dependencies] thiserror.workspace = true toml.workspace = true -color-eyre = "0.6.2" +color-eyre.workspace = true clap.workspace = true acvm.workspace = true nargo.workspace = true diff --git a/noir/noir-repo/tooling/nargo_cli/Cargo.toml b/noir/noir-repo/tooling/nargo_cli/Cargo.toml index b9d7d7e3e48..e0e54449a6f 100644 --- a/noir/noir-repo/tooling/nargo_cli/Cargo.toml +++ b/noir/noir-repo/tooling/nargo_cli/Cargo.toml @@ -43,11 +43,16 @@ prettytable-rs = "0.10" rayon = "1.8.0" thiserror.workspace = true tower.workspace = true -async-lsp = { workspace = true, features = ["client-monitor", "stdio", "tracing", "tokio"] } +async-lsp = { workspace = true, features = [ + "client-monitor", + "stdio", + "tracing", + "tokio", +] } const_format.workspace = true similar-asserts.workspace = true termcolor = "1.1.2" -color-eyre = "0.6.2" +color-eyre.workspace = true tokio = { version = "1.0", features = ["io-std", "rt"] } dap.workspace = true clap-markdown = { git = "https://github.com/noir-lang/clap-markdown", rev = "450d759532c88f0dba70891ceecdbc9ff8f25d2b", optional = true } diff --git a/noir/noir-repo/tooling/noirc_abi/src/lib.rs b/noir/noir-repo/tooling/noirc_abi/src/lib.rs index b3d80099137..c3e1ade04fa 100644 --- a/noir/noir-repo/tooling/noirc_abi/src/lib.rs +++ b/noir/noir-repo/tooling/noirc_abi/src/lib.rs @@ -171,7 +171,7 @@ pub struct AbiReturnType { pub visibility: AbiVisibility, } -#[derive(Clone, Debug, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, Serialize, Deserialize)] #[cfg_attr(test, derive(arbitrary::Arbitrary))] pub struct Abi { /// An ordered list of the arguments to the program's `main` function, specifying their types and visibility. diff --git a/noir/noir-repo/tooling/profiler/Cargo.toml b/noir/noir-repo/tooling/profiler/Cargo.toml new file mode 100644 index 00000000000..baebe9292e6 --- /dev/null +++ b/noir/noir-repo/tooling/profiler/Cargo.toml @@ -0,0 +1,42 @@ +[package] +name = "noir_profiler" +description = "Profiler for noir circuits" +version.workspace = true +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 + +[[bin]] +name = "noir-profiler" +path = "src/main.rs" + +[dependencies] +color-eyre.workspace = true +clap.workspace = true +nargo.workspace = true +const_format.workspace = true +serde.workspace = true +serde_json.workspace = true +fm.workspace = true +codespan-reporting.workspace = true +inferno = "0.11.19" +im.workspace = true +acir.workspace = true +noirc_errors.workspace = true + +# Logs +tracing-subscriber.workspace = true +tracing-appender = "0.2.3" + +[dev-dependencies] +noirc_abi.workspace = true +noirc_driver.workspace = true +tempfile.workspace = true + +[features] +default = ["bn254"] +bn254 = ["acir/bn254"] diff --git a/noir/noir-repo/tooling/profiler/src/cli/gates_flamegraph_cmd.rs b/noir/noir-repo/tooling/profiler/src/cli/gates_flamegraph_cmd.rs new file mode 100644 index 00000000000..4f51eed4ba3 --- /dev/null +++ b/noir/noir-repo/tooling/profiler/src/cli/gates_flamegraph_cmd.rs @@ -0,0 +1,486 @@ +use std::collections::BTreeMap; +use std::io::BufWriter; +use std::path::{Path, PathBuf}; +use std::process::Command; + +use clap::Args; +use codespan_reporting::files::Files; +use color_eyre::eyre::{self, Context}; +use inferno::flamegraph::{from_lines, Options}; +use nargo::artifacts::debug::DebugArtifact; +use serde::{Deserialize, Serialize}; + +use acir::circuit::OpcodeLocation; +use nargo::artifacts::program::ProgramArtifact; +use nargo::errors::Location; +use noirc_errors::reporter::line_and_column_from_span; + +#[derive(Debug, Clone, Args)] +pub(crate) struct GatesFlamegraphCommand { + /// The path to the artifact JSON file + #[clap(long, short)] + artifact_path: String, + + /// Path to the noir backend binary + #[clap(long, short)] + backend_path: String, + + /// The output folder for the flamegraph svg files + #[clap(long, short)] + output: String, +} + +trait GatesProvider { + fn get_gates(&self, artifact_path: &Path) -> eyre::Result; +} + +struct BackendGatesProvider { + backend_path: PathBuf, +} + +impl GatesProvider for BackendGatesProvider { + fn get_gates(&self, artifact_path: &Path) -> eyre::Result { + let backend_gates_response = + Command::new(&self.backend_path).arg("gates").arg("-b").arg(artifact_path).output()?; + + // Parse the backend gates command stdout as json + let backend_gates_response: BackendGatesResponse = + serde_json::from_slice(&backend_gates_response.stdout)?; + Ok(backend_gates_response) + } +} + +trait FlamegraphGenerator { + fn generate_flamegraph<'lines, I: IntoIterator>( + &self, + folded_lines: I, + artifact_name: &str, + function_name: &str, + output_path: &Path, + ) -> eyre::Result<()>; +} + +struct InfernoFlamegraphGenerator {} + +impl FlamegraphGenerator for InfernoFlamegraphGenerator { + fn generate_flamegraph<'lines, I: IntoIterator>( + &self, + folded_lines: I, + artifact_name: &str, + function_name: &str, + output_path: &Path, + ) -> eyre::Result<()> { + let flamegraph_file = std::fs::File::create(output_path)?; + let flamegraph_writer = BufWriter::new(flamegraph_file); + + let mut options = Options::default(); + options.hash = true; + options.deterministic = true; + options.title = format!("{}-{}", artifact_name, function_name); + options.subtitle = Some("Sample = Gate".to_string()); + options.frame_height = 24; + options.color_diffusion = true; + + from_lines(&mut options, folded_lines, flamegraph_writer)?; + + Ok(()) + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +struct BackendGatesReport { + acir_opcodes: usize, + circuit_size: usize, + gates_per_opcode: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +struct BackendGatesResponse { + functions: Vec, +} + +struct FoldedStackItem { + total_gates: usize, + nested_items: BTreeMap, +} + +pub(crate) fn run(args: GatesFlamegraphCommand) -> eyre::Result<()> { + run_with_provider( + &PathBuf::from(args.artifact_path), + &BackendGatesProvider { backend_path: PathBuf::from(args.backend_path) }, + &InfernoFlamegraphGenerator {}, + &PathBuf::from(args.output), + ) +} + +fn run_with_provider( + artifact_path: &Path, + gates_provider: &Provider, + flamegraph_generator: &Generator, + output_path: &Path, +) -> eyre::Result<()> { + let program = + read_program_from_file(artifact_path).context("Error reading program from file")?; + + let backend_gates_response = + gates_provider.get_gates(artifact_path).context("Error querying backend for gates")?; + + let function_names = program.names.clone(); + + let debug_artifact: DebugArtifact = program.into(); + + for (func_idx, (func_gates, func_name)) in + backend_gates_response.functions.into_iter().zip(function_names).enumerate() + { + println!( + "Opcode count: {}, Total gates by opcodes: {}, Circuit size: {}", + func_gates.acir_opcodes, + func_gates.gates_per_opcode.iter().sum::(), + func_gates.circuit_size + ); + + // Create a nested hashmap with the stack items, folding the gates for all the callsites that are equal + let mut folded_stack_items = BTreeMap::new(); + + func_gates.gates_per_opcode.into_iter().enumerate().for_each(|(opcode_index, gates)| { + let call_stack = &debug_artifact.debug_symbols[func_idx] + .locations + .get(&OpcodeLocation::Acir(opcode_index)); + let location_names = if let Some(call_stack) = call_stack { + call_stack + .iter() + .map(|location| location_to_callsite_label(*location, &debug_artifact)) + .collect::>() + } else { + vec!["unknown".to_string()] + }; + + add_locations_to_folded_stack_items(&mut folded_stack_items, location_names, gates); + }); + let folded_lines = to_folded_sorted_lines(&folded_stack_items, Default::default()); + + flamegraph_generator.generate_flamegraph( + folded_lines.iter().map(|as_string| as_string.as_str()), + artifact_path.to_str().unwrap(), + &func_name, + &Path::new(&output_path).join(Path::new(&format!("{}.svg", &func_name))), + )?; + } + + Ok(()) +} + +pub(crate) fn read_program_from_file>( + circuit_path: P, +) -> eyre::Result { + let file_path = circuit_path.as_ref().with_extension("json"); + + let input_string = std::fs::read(file_path)?; + let program = serde_json::from_slice(&input_string)?; + + Ok(program) +} + +fn location_to_callsite_label<'files>( + location: Location, + files: &'files impl Files<'files, FileId = fm::FileId>, +) -> String { + let filename = + Path::new(&files.name(location.file).expect("should have a file path").to_string()) + .file_name() + .map(|os_str| os_str.to_string_lossy().to_string()) + .unwrap_or("invalid_path".to_string()); + let source = files.source(location.file).expect("should have a file source"); + + let code_slice = source + .as_ref() + .chars() + .skip(location.span.start() as usize) + .take(location.span.end() as usize - location.span.start() as usize) + .collect::(); + + // ";" is used for frame separation, and is not allowed by inferno + // Check code slice for ";" and replace it with 'GREEK QUESTION MARK' (U+037E) + let code_slice = code_slice.replace(';', "\u{037E}"); + + let (line, column) = line_and_column_from_span(source.as_ref(), &location.span); + + format!("{}:{}:{}::{}", filename, line, column, code_slice) +} + +fn add_locations_to_folded_stack_items( + stack_items: &mut BTreeMap, + locations: Vec, + gates: usize, +) { + let mut child_map = stack_items; + for (index, location) in locations.iter().enumerate() { + let current_item = child_map + .entry(location.clone()) + .or_insert(FoldedStackItem { total_gates: 0, nested_items: BTreeMap::new() }); + + child_map = &mut current_item.nested_items; + + if index == locations.len() - 1 { + current_item.total_gates += gates; + } + } +} + +/// Creates a vector of lines in the format that inferno expects from a nested hashmap of stack items +/// The lines have to be sorted in the following way, exploring the graph in a depth-first manner: +/// main 100 +/// main::foo 0 +/// main::foo::bar 200 +/// main::baz 27 +/// main::baz::qux 800 +fn to_folded_sorted_lines( + folded_stack_items: &BTreeMap, + parent_stacks: im::Vector, +) -> Vec { + folded_stack_items + .iter() + .flat_map(move |(location, folded_stack_item)| { + let frame_list: Vec = + parent_stacks.iter().cloned().chain(std::iter::once(location.clone())).collect(); + let line: String = + format!("{} {}", frame_list.join(";"), folded_stack_item.total_gates); + + let mut new_parent_stacks = parent_stacks.clone(); + new_parent_stacks.push_back(location.clone()); + + let child_lines: Vec = + to_folded_sorted_lines(&folded_stack_item.nested_items, new_parent_stacks); + + std::iter::once(line).chain(child_lines) + }) + .collect() +} + +#[cfg(test)] +mod tests { + use acir::circuit::{OpcodeLocation, Program}; + use color_eyre::eyre::{self}; + use fm::{FileId, FileManager}; + use nargo::artifacts::program::ProgramArtifact; + use noirc_driver::DebugFile; + use noirc_errors::{ + debug_info::{DebugInfo, ProgramDebugInfo}, + Location, Span, + }; + use std::{ + cell::RefCell, + collections::{BTreeMap, HashMap}, + path::{Path, PathBuf}, + }; + use tempfile::TempDir; + + use super::{BackendGatesReport, BackendGatesResponse, GatesProvider}; + + struct TestGateProvider { + mock_responses: HashMap, + } + + impl GatesProvider for TestGateProvider { + fn get_gates(&self, artifact_path: &std::path::Path) -> eyre::Result { + let response = self + .mock_responses + .get(artifact_path) + .expect("should have a mock response for the artifact path"); + + Ok(response.clone()) + } + } + + #[derive(Default)] + struct TestFlamegraphGenerator { + lines_received: RefCell>>, + } + + impl super::FlamegraphGenerator for TestFlamegraphGenerator { + fn generate_flamegraph<'lines, I: IntoIterator>( + &self, + folded_lines: I, + _artifact_name: &str, + _function_name: &str, + _output_path: &std::path::Path, + ) -> eyre::Result<()> { + let lines = folded_lines.into_iter().map(|line| line.to_string()).collect(); + self.lines_received.borrow_mut().push(lines); + Ok(()) + } + } + + fn find_spans_for(source: &str, needle: &str) -> Vec { + let mut spans = Vec::new(); + let mut start = 0; + while let Some(start_idx) = source[start..].find(needle) { + let start_idx = start + start_idx; + let end_idx = start_idx + needle.len(); + spans.push(Span::inclusive(start_idx as u32, end_idx as u32 - 1)); + start = end_idx; + } + spans + } + + struct TestCase { + expected_folded_sorted_lines: Vec>, + debug_symbols: ProgramDebugInfo, + file_map: BTreeMap, + gates_report: BackendGatesResponse, + } + + fn simple_test_case(temp_dir: &TempDir) -> TestCase { + let source_code = r##" + fn main() { + foo(); + bar(); + whatever(); + } + fn foo() { + baz(); + } + fn bar () { + whatever() + } + fn baz () { + whatever() + } + "##; + + let source_file_name = Path::new("main.nr"); + let mut fm = FileManager::new(temp_dir.path()); + let file_id = fm.add_file_with_source(source_file_name, source_code.to_string()).unwrap(); + + let main_declaration_location = + Location::new(find_spans_for(source_code, "fn main()")[0], file_id); + let main_foo_call_location = + Location::new(find_spans_for(source_code, "foo()")[0], file_id); + let main_bar_call_location = + Location::new(find_spans_for(source_code, "bar()")[0], file_id); + let main_whatever_call_location = + Location::new(find_spans_for(source_code, "whatever()")[0], file_id); + let foo_baz_call_location = Location::new(find_spans_for(source_code, "baz()")[0], file_id); + let bar_whatever_call_location = + Location::new(find_spans_for(source_code, "whatever()")[1], file_id); + let baz_whatever_call_location = + Location::new(find_spans_for(source_code, "whatever()")[2], file_id); + + let mut opcode_locations = BTreeMap::>::new(); + // main::foo::baz::whatever + opcode_locations.insert( + OpcodeLocation::Acir(0), + vec![ + main_declaration_location, + main_foo_call_location, + foo_baz_call_location, + baz_whatever_call_location, + ], + ); + + // main::bar::whatever + opcode_locations.insert( + OpcodeLocation::Acir(1), + vec![main_declaration_location, main_bar_call_location, bar_whatever_call_location], + ); + // main::whatever + opcode_locations.insert( + OpcodeLocation::Acir(2), + vec![main_declaration_location, main_whatever_call_location], + ); + + let file_map = BTreeMap::from_iter(vec![( + file_id, + DebugFile { source: source_code.to_string(), path: source_file_name.to_path_buf() }, + )]); + + let debug_symbols = ProgramDebugInfo { + debug_infos: vec![DebugInfo::new( + opcode_locations, + BTreeMap::default(), + BTreeMap::default(), + BTreeMap::default(), + )], + }; + + let backend_gates_response = BackendGatesResponse { + functions: vec![BackendGatesReport { + acir_opcodes: 3, + circuit_size: 100, + gates_per_opcode: vec![10, 20, 30], + }], + }; + + let expected_folded_sorted_lines = vec![ + "main.nr:2:9::fn main() 0".to_string(), + "main.nr:2:9::fn main();main.nr:3:13::foo() 0".to_string(), + "main.nr:2:9::fn main();main.nr:3:13::foo();main.nr:8:13::baz() 0".to_string(), + "main.nr:2:9::fn main();main.nr:3:13::foo();main.nr:8:13::baz();main.nr:14:13::whatever() 10".to_string(), + "main.nr:2:9::fn main();main.nr:4:13::bar() 0".to_string(), + "main.nr:2:9::fn main();main.nr:4:13::bar();main.nr:11:13::whatever() 20".to_string(), + "main.nr:2:9::fn main();main.nr:5:13::whatever() 30".to_string(), + ]; + + TestCase { + expected_folded_sorted_lines: vec![expected_folded_sorted_lines], + debug_symbols, + file_map, + gates_report: backend_gates_response, + } + } + + #[test] + fn test_flamegraph() { + let temp_dir = tempfile::tempdir().unwrap(); + + let test_cases = vec![simple_test_case(&temp_dir)]; + let artifact_names: Vec<_> = + test_cases.iter().enumerate().map(|(idx, _)| format!("test{}.json", idx)).collect(); + + let test_cases_with_names: Vec<_> = test_cases.into_iter().zip(artifact_names).collect(); + + let mut mock_responses: HashMap = HashMap::new(); + // Collect mock responses + for (test_case, artifact_name) in test_cases_with_names.iter() { + mock_responses.insert( + temp_dir.path().join(artifact_name.clone()), + test_case.gates_report.clone(), + ); + } + + let provider = TestGateProvider { mock_responses }; + + for (test_case, artifact_name) in test_cases_with_names.iter() { + let artifact_path = temp_dir.path().join(artifact_name.clone()); + + let artifact = ProgramArtifact { + noir_version: "0.0.0".to_string(), + hash: 27, + abi: noirc_abi::Abi::default(), + bytecode: Program::default(), + debug_symbols: test_case.debug_symbols.clone(), + file_map: test_case.file_map.clone(), + names: vec!["main".to_string()], + }; + + // Write the artifact to a file + let artifact_file = std::fs::File::create(&artifact_path).unwrap(); + serde_json::to_writer(artifact_file, &artifact).unwrap(); + + let flamegraph_generator = TestFlamegraphGenerator::default(); + + super::run_with_provider( + &artifact_path, + &provider, + &flamegraph_generator, + temp_dir.path(), + ) + .expect("should run without errors"); + + // Check that the flamegraph generator was called with the correct folded sorted lines + let calls_received = flamegraph_generator.lines_received.borrow().clone(); + + assert_eq!(calls_received, test_case.expected_folded_sorted_lines); + } + } +} diff --git a/noir/noir-repo/tooling/profiler/src/cli/mod.rs b/noir/noir-repo/tooling/profiler/src/cli/mod.rs new file mode 100644 index 00000000000..d54a3f6167c --- /dev/null +++ b/noir/noir-repo/tooling/profiler/src/cli/mod.rs @@ -0,0 +1,33 @@ +use clap::{Parser, Subcommand}; +use color_eyre::eyre; +use const_format::formatcp; + +mod gates_flamegraph_cmd; + +const PROFILER_VERSION: &str = env!("CARGO_PKG_VERSION"); + +static VERSION_STRING: &str = formatcp!("version = {}\n", PROFILER_VERSION,); + +#[derive(Parser, Debug)] +#[command(name="Noir profiler", author, version=VERSION_STRING, about, long_about = None)] +struct ProfilerCli { + #[command(subcommand)] + command: GatesFlamegraphCommand, +} + +#[non_exhaustive] +#[derive(Subcommand, Clone, Debug)] +enum GatesFlamegraphCommand { + GatesFlamegraph(gates_flamegraph_cmd::GatesFlamegraphCommand), +} + +pub(crate) fn start_cli() -> eyre::Result<()> { + let ProfilerCli { command } = ProfilerCli::parse(); + + match command { + GatesFlamegraphCommand::GatesFlamegraph(args) => gates_flamegraph_cmd::run(args), + } + .map_err(|err| eyre::eyre!("{}", err))?; + + Ok(()) +} diff --git a/noir/noir-repo/tooling/profiler/src/main.rs b/noir/noir-repo/tooling/profiler/src/main.rs new file mode 100644 index 00000000000..8e08644de23 --- /dev/null +++ b/noir/noir-repo/tooling/profiler/src/main.rs @@ -0,0 +1,35 @@ +#![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; + +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("PROFILER_LOG_DIR") { + let debug_file = rolling::daily(log_dir, "profiler-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/noir/scripts/sync-fixup.sh b/noir/scripts/sync-out-fixup.sh similarity index 53% rename from noir/scripts/sync-fixup.sh rename to noir/scripts/sync-out-fixup.sh index 1f1152d1cee..79976883d0b 100755 --- a/noir/scripts/sync-fixup.sh +++ b/noir/scripts/sync-out-fixup.sh @@ -3,14 +3,16 @@ set -eu cd $(dirname $0)/../noir-repo +BB_VERSION=$(cat ../bb-version) + tmp=$(mktemp) BACKEND_BARRETENBERG_PACKAGE_JSON=./tooling/noir_js_backend_barretenberg/package.json -jq '.dependencies."@aztec/bb.js" = "portal:../../../../barretenberg/ts"' $BACKEND_BARRETENBERG_PACKAGE_JSON > $tmp && mv $tmp $BACKEND_BARRETENBERG_PACKAGE_JSON +jq --arg v $BB_VERSION '.dependencies."@aztec/bb.js" = $v' $BACKEND_BARRETENBERG_PACKAGE_JSON > $tmp && mv $tmp $BACKEND_BARRETENBERG_PACKAGE_JSON # This script runs in CI which enforces immutable installs by default, # we then must turn this off in order to update yarn.lock. YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install -# Remove requirement for `wasm-opt` to be installed -sed -i "s/^require_command wasm-opt/#require_command wasm-opt/" ./tooling/noirc_abi_wasm/build.sh -sed -i "s/^require_command wasm-opt/#require_command wasm-opt/" ./acvm-repo/acvm_js/build.sh +# Add requirement for `wasm-opt` to be installed +sed -i "s/^#require_command wasm-opt/require_command wasm-opt/" ./tooling/noirc_abi_wasm/build.sh +sed -i "s/^#require_command wasm-opt/require_command wasm-opt/" ./acvm-repo/acvm_js/build.sh diff --git a/yarn-project/Earthfile b/yarn-project/Earthfile index 14b724a28b5..82f52d6e6eb 100644 --- a/yarn-project/Earthfile +++ b/yarn-project/Earthfile @@ -115,6 +115,19 @@ rollup-verifier-contract: RUN --entrypoint write-contract -c RootRollupArtifact -n UltraVerifier.sol SAVE ARTIFACT /usr/src/bb /usr/src/bb +txe: + FROM +build + RUN yarn workspaces focus @aztec/txe --production && yarn cache clean + # Remove a bunch of stuff that we don't need that takes up space. + RUN rm -rf \ + ../noir-projects \ + ../l1-contracts \ + ../barretenberg/ts/src \ + ../barretenberg/ts/dest/node-cjs \ + ../barretenberg/ts/dest/browser \ + **/artifacts + SAVE ARTIFACT /usr/src /usr/src + aztec-prod: FROM +build RUN yarn workspaces focus @aztec/aztec @aztec/builder --production && yarn cache clean @@ -148,6 +161,28 @@ aztec: CMD curl -fsSd '{\"jsonrpc\":\"2.0\",\"method\":\"pxe_getNodeInfo\",\"id\":1}' http://127.0.0.1:$port EXPOSE $port +aztec-faucet-build: + FROM +build + RUN yarn workspaces focus @aztec/aztec-faucet --production && yarn cache clean + RUN rm -rf \ + ../noir-projects \ + ../l1-contracts \ + ../barretenberg/ts/src \ + ../barretenberg/ts/dest/node-cjs \ + ../barretenberg/ts/dest/browser \ + aztec.js/dest/main.js \ + end-to-end \ + **/src \ + **/artifacts + SAVE ARTIFACT /usr/src /usr/src + +aztec-faucet: + FROM ubuntu:noble + RUN apt update && apt install nodejs curl -y && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + COPY +aztec-faucet/usr/src /usr/src + ENTRYPOINT ["node", "--no-warnings", "/usr/src/yarn-project/aztec-faucet/dest/bin/index.js"] + LET port=8080 + # We care about creating a slimmed down e2e image because we have to serialize it from earthly to docker for running. end-to-end-prod: FROM +build @@ -206,6 +241,18 @@ export-aztec: FROM +aztec SAVE IMAGE aztecprotocol/aztec:$EARTHLY_GIT_HASH +export-aztec-arch: + FROM +aztec + ARG DIST_TAG="latest" + ARG ARCH + SAVE IMAGE --push aztecprotocol/aztec:${DIST_TAG}${ARCH:+-$ARCH} + +export-aztec-faucet: + FROM +aztec-faucet + ARG DIST_TAG="latest" + ARG ARCH + SAVE IMAGE --push aztecprotocol/aztec-faucet:${DIST_TAG}${ARCH:+-$ARCH} + export-end-to-end: ARG EARTHLY_GIT_HASH FROM +end-to-end diff --git a/yarn-project/archiver/src/archiver/index.ts b/yarn-project/archiver/src/archiver/index.ts index a7294537624..81aa8727e17 100644 --- a/yarn-project/archiver/src/archiver/index.ts +++ b/yarn-project/archiver/src/archiver/index.ts @@ -3,3 +3,4 @@ export * from './config.js'; export { MemoryArchiverStore } from './memory_archiver_store/memory_archiver_store.js'; export { ArchiverDataStore } from './archiver_store.js'; export { KVArchiverDataStore } from './kv_archiver_store/kv_archiver_store.js'; +export { ContractInstanceStore } from './kv_archiver_store/contract_instance_store.js'; diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 5ccbf6266c7..da82aa420e7 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -122,7 +122,11 @@ export class AztecNodeService implements AztecNode { * @param config - The configuration to be used by the aztec node. * @returns - A fully synced Aztec Node for use in development/testing. */ - public static async createAndSync(config: AztecNodeConfig) { + public static async createAndSync( + config: AztecNodeConfig, + log = createDebugLogger('aztec:node'), + storeLog = createDebugLogger('aztec:node:lmdb'), + ) { const ethereumChain = createEthereumChain(config.rpcUrl, config.apiKey); //validate that the actual chain id matches that specified in configuration if (config.chainId !== ethereumChain.chainInfo.id) { @@ -131,8 +135,6 @@ export class AztecNodeService implements AztecNode { ); } - const log = createDebugLogger('aztec:node'); - const storeLog = createDebugLogger('aztec:node:lmdb'); const store = await initStoreForRollup( AztecLmdbStore.open(config.dataDirectory, false, storeLog), config.l1Contracts.rollupAddress, diff --git a/yarn-project/aztec.js/src/api/abi.ts b/yarn-project/aztec.js/src/api/abi.ts index 69f8b095aee..2f76188c5cd 100644 --- a/yarn-project/aztec.js/src/api/abi.ts +++ b/yarn-project/aztec.js/src/api/abi.ts @@ -1,3 +1,3 @@ -export { type ContractArtifact, type FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi'; +export { type ContractArtifact, type FunctionArtifact, EventSelector, FunctionSelector } from '@aztec/foundation/abi'; export { loadContractArtifact, contractArtifactToBuffer, contractArtifactFromBuffer } from '@aztec/types/abi'; export { type NoirCompiledContract } from '@aztec/types/noir'; diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index 4708ab8c8e7..8d9250c2c84 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -80,13 +80,15 @@ export class SentTx { if (opts?.debug) { const txHash = await this.getTxHash(); const tx = (await this.pxe.getTxEffect(txHash))!; - const visibleNotes = await this.pxe.getNotes({ txHash }); + const visibleIncomingNotes = await this.pxe.getIncomingNotes({ txHash }); + const visibleOutgoingNotes = await this.pxe.getOutgoingNotes({ txHash }); receipt.debugInfo = { noteHashes: tx.noteHashes, nullifiers: tx.nullifiers, publicDataWrites: tx.publicDataWrites, l2ToL1Msgs: tx.l2ToL1Msgs, - visibleNotes, + visibleIncomingNotes, + visibleOutgoingNotes, }; } return receipt; @@ -109,7 +111,7 @@ export class SentTx { */ public async getVisibleNotes(): Promise { await this.wait(); - return this.pxe.getNotes({ txHash: await this.getTxHash() }); + return this.pxe.getIncomingNotes({ txHash: await this.getTxHash() }); } protected async waitForReceipt(opts?: WaitOpts): Promise { diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 79eef304370..8fabb0e8f91 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -41,6 +41,7 @@ export { CheatCodes, EthAddressLike, EthCheatCodes, + EventSelectorLike, FieldLike, FunctionSelectorLike, WrappedFieldLike, diff --git a/yarn-project/aztec.js/src/utils/abi_types.ts b/yarn-project/aztec.js/src/utils/abi_types.ts index 71b88b89848..304c109899b 100644 --- a/yarn-project/aztec.js/src/utils/abi_types.ts +++ b/yarn-project/aztec.js/src/utils/abi_types.ts @@ -1,4 +1,10 @@ -import { type AztecAddress, type EthAddress, type Fr, type FunctionSelector } from '@aztec/circuits.js'; +import { + type AztecAddress, + type EthAddress, + type EventSelector, + type Fr, + type FunctionSelector, +} from '@aztec/circuits.js'; /** Any type that can be converted into a field for a contract call. */ export type FieldLike = Fr | Buffer | bigint | number | { /** Converts to field */ toField: () => Fr }; @@ -9,8 +15,11 @@ export type EthAddressLike = { /** Wrapped address */ address: FieldLike } | Eth /** Any type that can be converted into an AztecAddress Aztec.nr struct. */ export type AztecAddressLike = { /** Wrapped address */ address: FieldLike } | AztecAddress; -/** Any type that can be converted into an FunctionSelector Aztec.nr struct. */ +/** Any type that can be converted into a FunctionSelector Aztec.nr struct. */ export type FunctionSelectorLike = FieldLike | FunctionSelector; +/** Any type that can be converted into an EventSelector Aztec.nr struct. */ +export type EventSelectorLike = FieldLike | EventSelector; + /** Any type that can be converted into a struct with a single `inner` field. */ export type WrappedFieldLike = { /** Wrapped value */ inner: FieldLike } | FieldLike; diff --git a/yarn-project/aztec.js/src/utils/cheat_codes.ts b/yarn-project/aztec.js/src/utils/cheat_codes.ts index 4f95e2fa1fa..d10bbcef91d 100644 --- a/yarn-project/aztec.js/src/utils/cheat_codes.ts +++ b/yarn-project/aztec.js/src/utils/cheat_codes.ts @@ -291,7 +291,11 @@ export class AztecCheatCodes { * @returns The notes stored at the given slot */ public async loadPrivate(owner: AztecAddress, contract: AztecAddress, slot: Fr | bigint): Promise { - const extendedNotes = await this.pxe.getNotes({ owner, contractAddress: contract, storageSlot: new Fr(slot) }); + const extendedNotes = await this.pxe.getIncomingNotes({ + owner, + contractAddress: contract, + storageSlot: new Fr(slot), + }); return extendedNotes.map(extendedNote => extendedNote.note); } } diff --git a/yarn-project/aztec.js/src/wallet/account_wallet.ts b/yarn-project/aztec.js/src/wallet/account_wallet.ts index 93c4114a598..4452b15f953 100644 --- a/yarn-project/aztec.js/src/wallet/account_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/account_wallet.ts @@ -1,6 +1,7 @@ import { type AuthWitness, type FunctionCall, type PXE, type TxExecutionRequest } from '@aztec/circuit-types'; import { AztecAddress, CANONICAL_KEY_REGISTRY_ADDRESS, Fq, Fr, derivePublicKeyFromSecretKey } from '@aztec/circuits.js'; import { type ABIParameterVisibility, type FunctionAbi, FunctionType } from '@aztec/foundation/abi'; +import { AuthRegistryAddress } from '@aztec/protocol-contracts/auth-registry'; import { type AccountInterface } from '../account/interface.js'; import { ContractFunctionInteraction } from '../contract/contract_function_interaction.js'; @@ -80,11 +81,33 @@ export class AccountWallet extends BaseWallet { authorized: boolean, ): ContractFunctionInteraction { const message = this.getMessageHash(messageHashOrIntent); - if (authorized) { - return new ContractFunctionInteraction(this, this.getAddress(), this.getApprovePublicAuthwitAbi(), [message]); - } else { - return this.cancelAuthWit(message); - } + return new ContractFunctionInteraction(this, AuthRegistryAddress, this.getSetAuthorizedAbi(), [ + message, + authorized, + ]); + } + + /** + * Returns a function interaction to cancel a message hash as authorized or revoked. + * @param messageHashOrIntent - The message or the caller and action to revoke + * @returns - A function interaction. + */ + public cancelPublicAuthWit( + messageHashOrIntent: + | Fr + | Buffer + | { + /** The caller to approve */ + caller: AztecAddress; + /** The action to approve */ + action: ContractFunctionInteraction | FunctionCall; + /** The chain id to approve */ + chainId?: Fr; + /** The version to approve */ + version?: Fr; + }, + ): ContractFunctionInteraction { + return this.setPublicAuthWit(messageHashOrIntent, false); } /** @@ -152,17 +175,25 @@ export class AccountWallet extends BaseWallet { isValidInPublic: boolean; }> { const messageHash = this.getMessageHash(messageHashOrIntent); + const results = { isValidInPrivate: false, isValidInPublic: false }; + + // Check private const witness = await this.getAuthWitness(messageHash); - const blockNumber = await this.getBlockNumber(); - const interaction = new ContractFunctionInteraction(this, target, this.getLookupValidityAbi(), [ - target, - blockNumber, - witness != undefined, - messageHash, - ]); + if (witness !== undefined) { + results.isValidInPrivate = (await new ContractFunctionInteraction(this, target, this.getLookupValidityAbi(), [ + messageHash, + ]).simulate()) as boolean; + } - const [isValidInPrivate, isValidInPublic] = (await interaction.simulate()) as [boolean, boolean]; - return { isValidInPrivate, isValidInPublic }; + // check public + results.isValidInPublic = (await new ContractFunctionInteraction( + this, + AuthRegistryAddress, + this.getIsConsumableAbi(), + [target, messageHash], + ).simulate()) as boolean; + + return results; } /** @@ -224,9 +255,9 @@ export class AccountWallet extends BaseWallet { return this.getCompleteAddress().address; } - private getApprovePublicAuthwitAbi(): FunctionAbi { + private getSetAuthorizedAbi(): FunctionAbi { return { - name: 'approve_public_authwit', + name: 'set_authorized', isInitializer: false, functionType: FunctionType.PUBLIC, isInternal: true, @@ -237,6 +268,11 @@ export class AccountWallet extends BaseWallet { type: { kind: 'field' }, visibility: 'private' as ABIParameterVisibility, }, + { + name: 'authorize', + type: { kind: 'boolean' }, + visibility: 'private' as ABIParameterVisibility, + }, ], returnTypes: [], }; @@ -267,29 +303,31 @@ export class AccountWallet extends BaseWallet { functionType: FunctionType.UNCONSTRAINED, isInternal: false, isStatic: false, + parameters: [{ name: 'message_hash', type: { kind: 'field' }, visibility: 'private' as ABIParameterVisibility }], + returnTypes: [{ kind: 'boolean' }], + }; + } + + private getIsConsumableAbi(): FunctionAbi { + return { + name: 'unconstrained_is_consumable', + isInitializer: false, + functionType: FunctionType.UNCONSTRAINED, + isInternal: false, + isStatic: false, parameters: [ { - name: 'myself', + name: 'address', type: { + fields: [{ name: 'inner', type: { kind: 'field' } }], kind: 'struct', path: 'authwit::aztec::protocol_types::address::aztec_address::AztecAddress', - fields: [{ name: 'inner', type: { kind: 'field' } }], }, visibility: 'private' as ABIParameterVisibility, }, - { - name: 'block_number', - type: { kind: 'integer', sign: 'unsigned', width: 32 }, - visibility: 'private' as ABIParameterVisibility, - }, - { - name: 'check_private', - type: { kind: 'boolean' }, - visibility: 'private' as ABIParameterVisibility, - }, { name: 'message_hash', type: { kind: 'field' }, visibility: 'private' as ABIParameterVisibility }, ], - returnTypes: [{ kind: 'array', length: 2, type: { kind: 'boolean' } }], + returnTypes: [{ kind: 'boolean' }], }; } diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index ac28f0cac00..974895fa96e 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -4,9 +4,10 @@ import { type ExtendedNote, type FunctionCall, type GetUnencryptedLogsResponse, + type IncomingNotesFilter, type L2Block, type LogFilter, - type NoteFilter, + type OutgoingNotesFilter, type PXE, type PXEInfo, type SimulatedTx, @@ -129,8 +130,11 @@ export abstract class BaseWallet implements Wallet { getTxReceipt(txHash: TxHash): Promise { return this.pxe.getTxReceipt(txHash); } - getNotes(filter: NoteFilter): Promise { - return this.pxe.getNotes(filter); + getIncomingNotes(filter: IncomingNotesFilter): Promise { + return this.pxe.getIncomingNotes(filter); + } + getOutgoingNotes(filter: OutgoingNotesFilter): Promise { + return this.pxe.getOutgoingNotes(filter); } // TODO(#4956): Un-expose this getNoteNonces(note: ExtendedNote): Promise { diff --git a/yarn-project/aztec/CHANGELOG.md b/yarn-project/aztec/CHANGELOG.md index 3c4d709503f..3e6001e44b1 100644 --- a/yarn-project/aztec/CHANGELOG.md +++ b/yarn-project/aztec/CHANGELOG.md @@ -1,5 +1,22 @@ # Changelog +## [0.43.0](https://github.com/AztecProtocol/aztec-packages/compare/aztec-package-v0.42.0...aztec-package-v0.43.0) (2024-06-18) + + +### Features + +* Auth registry ([#7035](https://github.com/AztecProtocol/aztec-packages/issues/7035)) ([cea0b3b](https://github.com/AztecProtocol/aztec-packages/commit/cea0b3b29c2f7c37eb07c226a06534f92518cea6)) +* Nuking last hardcoded note type ids ([#7069](https://github.com/AztecProtocol/aztec-packages/issues/7069)) ([a23fd0b](https://github.com/AztecProtocol/aztec-packages/commit/a23fd0ba1604a5308fd77ed45a5b1d20da13f405)), closes [#5833](https://github.com/AztecProtocol/aztec-packages/issues/5833) + + +### Miscellaneous + +* Move gas bridge initialization into L1 contracts deployment ([#6912](https://github.com/AztecProtocol/aztec-packages/issues/6912)) ([26a1fc4](https://github.com/AztecProtocol/aztec-packages/commit/26a1fc4bcec04434b61651e2f527938a14f3ac3a)) +* Rename p2p vars ([#6916](https://github.com/AztecProtocol/aztec-packages/issues/6916)) ([ae7d757](https://github.com/AztecProtocol/aztec-packages/commit/ae7d75764fc704daae67be882e0e9f09a0a9407c)) +* Terraform Updates ([#6887](https://github.com/AztecProtocol/aztec-packages/issues/6887)) ([33a3870](https://github.com/AztecProtocol/aztec-packages/commit/33a3870d06ae8bb5d08dbbd9f72a62e0811e5e7d)) +* Transfer and transferfrom to save constrains for simpler cases ([#7013](https://github.com/AztecProtocol/aztec-packages/issues/7013)) ([612b972](https://github.com/AztecProtocol/aztec-packages/commit/612b9724a419224c72cd823c889ece4ae8f00ab0)) +* Updated devnet terraform ([#6927](https://github.com/AztecProtocol/aztec-packages/issues/6927)) ([4692fb0](https://github.com/AztecProtocol/aztec-packages/commit/4692fb034f22bb62593d257777b7b545993c27ab)) + ## [0.42.0](https://github.com/AztecProtocol/aztec-packages/compare/aztec-package-v0.41.0...aztec-package-v0.42.0) (2024-06-04) diff --git a/yarn-project/aztec/package.json b/yarn-project/aztec/package.json index 8b04c15e755..6caffb8c0ce 100644 --- a/yarn-project/aztec/package.json +++ b/yarn-project/aztec/package.json @@ -1,6 +1,6 @@ { "name": "@aztec/aztec", - "version": "0.42.0", + "version": "0.43.0", "type": "module", "exports": { ".": "./dest/index.js" diff --git a/yarn-project/aztec/src/examples/token.ts b/yarn-project/aztec/src/examples/token.ts index b9d8526ef8a..97fc5b244d2 100644 --- a/yarn-project/aztec/src/examples/token.ts +++ b/yarn-project/aztec/src/examples/token.ts @@ -48,17 +48,13 @@ async function main() { const aliceSecretHash = computeSecretHash(aliceSecret); const receipt = await tokenAlice.methods.mint_private(ALICE_MINT_BALANCE, aliceSecretHash).send().wait(); - // Add the newly created "pending shield" note to PXE - const pendingShieldsStorageSlot = new Fr(5); // The storage slot of `pending_shields` is 5. - // `pending_shields` underlying note type is TransparentNote, with the following type id. - const pendingShieldsNoteTypeId = new Fr(84114971101151129711410111011678111116101n); const note = new Note([new Fr(ALICE_MINT_BALANCE), aliceSecretHash]); const extendedNote = new ExtendedNote( note, alice.address, token.address, - pendingShieldsStorageSlot, - pendingShieldsNoteTypeId, + TokenContract.storage.pending_shields.slot, + TokenContract.notes.TransparentNote.id, receipt.txHash, ); await pxe.addNote(extendedNote); diff --git a/yarn-project/aztec/src/sandbox.ts b/yarn-project/aztec/src/sandbox.ts index fe75423fdb1..d9c7f0d113d 100644 --- a/yarn-project/aztec/src/sandbox.ts +++ b/yarn-project/aztec/src/sandbox.ts @@ -3,7 +3,7 @@ import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec import { AztecAddress, SignerlessWallet, type Wallet } from '@aztec/aztec.js'; import { DefaultMultiCallEntrypoint } from '@aztec/aztec.js/entrypoint'; import { type AztecNode } from '@aztec/circuit-types'; -import { CANONICAL_KEY_REGISTRY_ADDRESS } from '@aztec/circuits.js'; +import { CANONICAL_AUTH_REGISTRY_ADDRESS, CANONICAL_KEY_REGISTRY_ADDRESS } from '@aztec/circuits.js'; import { type DeployL1Contracts, type L1ContractAddresses, @@ -30,8 +30,9 @@ import { RollupAbi, RollupBytecode, } from '@aztec/l1-artifacts'; +import { AuthRegistryContract, KeyRegistryContract } from '@aztec/noir-contracts.js'; import { GasTokenContract } from '@aztec/noir-contracts.js/GasToken'; -import { KeyRegistryContract } from '@aztec/noir-contracts.js/KeyRegistry'; +import { getCanonicalAuthRegistry } from '@aztec/protocol-contracts/auth-registry'; import { GasTokenAddress, getCanonicalGasToken } from '@aztec/protocol-contracts/gas-token'; import { getCanonicalKeyRegistry } from '@aztec/protocol-contracts/key-registry'; import { type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe'; @@ -193,6 +194,39 @@ async function deployCanonicalKeyRegistry(deployer: Wallet) { logger.info(`Deployed Key Registry on L2 at ${canonicalKeyRegistry.address}`); } +/** + * Deploys the auth registry on L2. + */ +async function deployCanonicalAuthRegistry(deployer: Wallet) { + const canonicalAuthRegistry = getCanonicalAuthRegistry(); + + // We check to see if there exists a contract at the canonical Auth Registry address with the same contract class id as we expect. This means that + // the auth registry has already been deployed to the correct address. + if ( + (await deployer.getContractInstance(canonicalAuthRegistry.address))?.contractClassId.equals( + canonicalAuthRegistry.contractClass.id, + ) && + (await deployer.isContractClassPubliclyRegistered(canonicalAuthRegistry.contractClass.id)) + ) { + return; + } + + const authRegistry = await AuthRegistryContract.deploy(deployer) + .send({ contractAddressSalt: canonicalAuthRegistry.instance.salt, universalDeploy: true }) + .deployed(); + + if ( + !authRegistry.address.equals(canonicalAuthRegistry.address) || + !authRegistry.address.equals(AztecAddress.fromBigInt(CANONICAL_AUTH_REGISTRY_ADDRESS)) + ) { + throw new Error( + `Deployed Auth Registry address ${authRegistry.address} does not match expected address ${canonicalAuthRegistry.address}, or they both do not equal CANONICAL_AUTH_REGISTRY_ADDRESS`, + ); + } + + logger.info(`Deployed Auth Registry on L2 at ${canonicalAuthRegistry.address}`); +} + /** Sandbox settings. */ export type SandboxConfig = AztecNodeConfig & { /** Mnemonic used to derive the L1 deployer private key.*/ @@ -224,6 +258,9 @@ export async function createSandbox(config: Partial = {}) { await deployCanonicalKeyRegistry( new SignerlessWallet(pxe, new DefaultMultiCallEntrypoint(aztecNodeConfig.chainId, aztecNodeConfig.version)), ); + await deployCanonicalAuthRegistry( + new SignerlessWallet(pxe, new DefaultMultiCallEntrypoint(aztecNodeConfig.chainId, aztecNodeConfig.version)), + ); if (config.enableGas) { await deployCanonicalL2GasToken( diff --git a/yarn-project/aztec/terraform/node/main.tf b/yarn-project/aztec/terraform/node/main.tf index 3a205d1ff0b..d627d416f0a 100644 --- a/yarn-project/aztec/terraform/node/main.tf +++ b/yarn-project/aztec/terraform/node/main.tf @@ -234,31 +234,31 @@ resource "aws_ecs_task_definition" "aztec-node" { { "name": "ROLLUP_CONTRACT_ADDRESS", - "value": "${var.ROLLUP_CONTRACT_ADDRESS}" + "value": "${data.terraform_remote_state.l1_contracts.outputs.rollup_contract_address}" }, { "name": "INBOX_CONTRACT_ADDRESS", - "value": "${var.INBOX_CONTRACT_ADDRESS}" + "value": "${data.terraform_remote_state.l1_contracts.outputs.inbox_contract_address}" }, { "name": "OUTBOX_CONTRACT_ADDRESS", - "value": "${var.OUTBOX_CONTRACT_ADDRESS}" + "value": "${data.terraform_remote_state.l1_contracts.outputs.outbox_contract_address}" }, { "name": "REGISTRY_CONTRACT_ADDRESS", - "value": "${var.REGISTRY_CONTRACT_ADDRESS}" + "value": "${data.terraform_remote_state.l1_contracts.outputs.registry_contract_address}" }, { "name": "AVAILABILITY_ORACLE_CONTRACT_ADDRESS", - "value": "${var.AVAILABILITY_ORACLE_CONTRACT_ADDRESS}" + "value": "${data.terraform_remote_state.l1_contracts.outputs.availability_oracle_contract_address}" }, { "name": "GAS_TOKEN_CONTRACT_ADDRESS", - "value": "${var.GAS_TOKEN_CONTRACT_ADDRESS}" + "value": "${data.terraform_remote_state.l1_contracts.outputs.gas_token_contract_address}" }, { "name": "GAS_PORTAL_CONTRACT_ADDRESS", - "value": "${var.GAS_PORTAL_CONTRACT_ADDRESS}" + "value": "${data.terraform_remote_state.l1_contracts.outputs.gas_portal_contract_address}" }, { "name": "API_KEY", diff --git a/yarn-project/aztec/terraform/node/variables.tf b/yarn-project/aztec/terraform/node/variables.tf index 4463487e2c3..2febb315fa9 100644 --- a/yarn-project/aztec/terraform/node/variables.tf +++ b/yarn-project/aztec/terraform/node/variables.tf @@ -55,7 +55,7 @@ variable "SEQ_MIN_TX_PER_BLOCK" { variable "P2P_MIN_PEERS" { type = string - default = 50 + default = 5 } variable "P2P_MAX_PEERS" { @@ -85,5 +85,6 @@ variable "IMAGE_TAG" { } variable "FULL_IMAGE" { - type = string + type = string + default = "${var.DOCKERHUB_ACCOUNT}/aztec:${var.IMAGE_TAG}" } diff --git a/yarn-project/bb-prover/src/avm_proving.test.ts b/yarn-project/bb-prover/src/avm_proving.test.ts index ba17be603ab..917850189ff 100644 --- a/yarn-project/bb-prover/src/avm_proving.test.ts +++ b/yarn-project/bb-prover/src/avm_proving.test.ts @@ -146,6 +146,20 @@ describe('AVM WitGen, proof generation and verification', () => { TIMEOUT, ); + /************************************************************************ + * Avm Embedded Curve functions + ************************************************************************/ + describe('AVM Embedded Curve functions', () => { + const avmEmbeddedCurveFunctions: string[] = ['elliptic_curve_add_and_double', 'variable_base_msm']; + it.each(avmEmbeddedCurveFunctions)( + 'Should prove %s', + async name => { + await proveAndVerifyAvmTestContract(name); + }, + TIMEOUT, + ); + }); + /************************************************************************ * AvmContext functions ************************************************************************/ @@ -248,12 +262,14 @@ const proveAndVerifyAvmTestContract = async ( startGas, context, simulator.getBytecode(), + functionName, ); // TODO(dbanks12): public inputs should not be empty.... Need to construct them from AvmContext? const uncompressedBytecode = simulator.getBytecode()!; const publicInputs = getPublicInputs(pxResult); const avmCircuitInputs = new AvmCircuitInputs( + functionName, uncompressedBytecode, context.environment.calldata, publicInputs, diff --git a/yarn-project/bb-prover/src/prover/bb_native_proof_creator.ts b/yarn-project/bb-prover/src/prover/bb_native_proof_creator.ts index e59a8b87d22..3cc08097278 100644 --- a/yarn-project/bb-prover/src/prover/bb_native_proof_creator.ts +++ b/yarn-project/bb-prover/src/prover/bb_native_proof_creator.ts @@ -42,6 +42,7 @@ import { type NoirCompiledCircuit } from '@aztec/types/noir'; import { serializeWitness } from '@noir-lang/noirc_abi'; import { type WitnessMap } from '@noir-lang/types'; import * as fs from 'fs/promises'; +import { join } from 'path'; import { BB_RESULT, @@ -175,7 +176,7 @@ export class BBNativeProofCreator implements ProofCreator { throw new Error(errorMessage); } - this.log.info(`Successfully verified ${circuitType} proof in ${result.duration} ms`); + this.log.info(`Successfully verified ${circuitType} proof in ${Math.ceil(result.duration)} ms`); } private async verifyProofFromKey( @@ -304,13 +305,14 @@ export class BBNativeProofCreator implements ProofCreator { }> { const compressedBincodedWitness = serializeWitness(partialWitness); - const inputsWitnessFile = `${directory}/witness.gz`; + const inputsWitnessFile = join(directory, 'witness.gz'); await fs.writeFile(inputsWitnessFile, compressedBincodedWitness); this.log.debug(`Written ${inputsWitnessFile}`); - this.log.info(`Proving ${circuitType} circuit...`); + const dbgCircuitName = appCircuitName ? `(${appCircuitName})` : ''; + this.log.info(`Proving ${circuitType}${dbgCircuitName} circuit...`); const timer = new Timer(); @@ -324,13 +326,11 @@ export class BBNativeProofCreator implements ProofCreator { ); if (provingResult.status === BB_RESULT.FAILURE) { - this.log.error(`Failed to generate proof for ${circuitType}: ${provingResult.reason}`); + this.log.error(`Failed to generate proof for ${circuitType}${dbgCircuitName}: ${provingResult.reason}`); throw new Error(provingResult.reason); } - this.log.info( - `Generated ${circuitType === 'App' ? appCircuitName : circuitType} circuit proof in ${timer.ms()} ms`, - ); + this.log.info(`Generated ${circuitType}${dbgCircuitName} circuit proof in ${Math.ceil(timer.ms())} ms`); if (circuitType === 'App') { const vkData = await extractVkData(directory); diff --git a/yarn-project/bb-prover/src/prover/bb_prover.ts b/yarn-project/bb-prover/src/prover/bb_prover.ts index ad39a749448..33210ed6444 100644 --- a/yarn-project/bb-prover/src/prover/bb_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_prover.ts @@ -439,22 +439,17 @@ export class BBNativeRollupProver implements ServerCircuitProver { const rawProof = await fs.readFile(`${provingResult.proofPath!}/${PROOF_FILENAME}`); const proof = new Proof(rawProof, vkData.numPublicInputs); - logger.info( - `Generated proof for ${circuitType} in ${Math.ceil(provingResult.duration)} ms, size: ${ - proof.buffer.length - } bytes`, - { - circuitName: mapProtocolArtifactNameToCircuitName(circuitType), - // does not include reading the proof from disk - duration: provingResult.duration, - proofSize: proof.buffer.length, - eventName: 'circuit-proving', - // circuitOutput is the partial witness that became the input to the proof - inputSize: output.toBuffer().length, - circuitSize: vkData.circuitSize, - numPublicInputs: vkData.numPublicInputs, - } satisfies CircuitProvingStats, - ); + logger.info(`Generated proof for ${circuitType} in ${Math.ceil(provingResult.duration)} ms`, { + circuitName: mapProtocolArtifactNameToCircuitName(circuitType), + // does not include reading the proof from disk + duration: provingResult.duration, + proofSize: proof.buffer.length, + eventName: 'circuit-proving', + // circuitOutput is the partial witness that became the input to the proof + inputSize: output.toBuffer().length, + circuitSize: vkData.circuitSize, + numPublicInputs: vkData.numPublicInputs, + } satisfies CircuitProvingStats); return { circuitOutput: output, proof }; }; @@ -462,12 +457,12 @@ export class BBNativeRollupProver implements ServerCircuitProver { } private async generateAvmProofWithBB(input: AvmCircuitInputs, workingDirectory: string): Promise { - logger.debug(`Proving avm-circuit...`); + logger.info(`Proving avm-circuit for ${input.functionName}...`); const provingResult = await generateAvmProof(this.config.bbBinaryPath, workingDirectory, input, logger.verbose); if (provingResult.status === BB_RESULT.FAILURE) { - logger.error(`Failed to generate proof for avm-circuit: ${provingResult.reason}`); + logger.error(`Failed to generate AVM proof for ${input.functionName}: ${provingResult.reason}`); throw new Error(provingResult.reason); } @@ -490,18 +485,17 @@ export class BBNativeRollupProver implements ServerCircuitProver { const circuitType = 'avm-circuit' as const; logger.info( - `Generated proof for ${circuitType} in ${Math.ceil(provingResult.duration)} ms, size: ${ - proof.buffer.length - } bytes`, + `Generated proof for ${circuitType}(${input.functionName}) in ${Math.ceil(provingResult.duration)} ms`, { circuitName: circuitType, + appCircuitName: input.functionName, // does not include reading the proof from disk duration: provingResult.duration, proofSize: proof.buffer.length, eventName: 'circuit-proving', inputSize: input.toBuffer().length, - circuitSize: verificationKey.circuitSize, - numPublicInputs: verificationKey.numPublicInputs, + circuitSize: verificationKey.circuitSize, // FIX: wrong in VK + numPublicInputs: verificationKey.numPublicInputs, // FIX: wrong in VK } satisfies CircuitProvingStats, ); diff --git a/yarn-project/builder/src/contract-interface-gen/typescript.ts b/yarn-project/builder/src/contract-interface-gen/typescript.ts index 614cc21e631..5fc2828c500 100644 --- a/yarn-project/builder/src/contract-interface-gen/typescript.ts +++ b/yarn-project/builder/src/contract-interface-gen/typescript.ts @@ -194,10 +194,9 @@ function generateStorageLayoutGetter(input: ContractArtifact) { const storageFieldsUnionType = entries.map(([name]) => `'${name}'`).join(' | '); const layout = entries .map( - ([name, { slot, typ }]) => + ([name, { slot }]) => `${name}: { slot: new Fr(${slot.toBigInt()}n), - typ: "${typ}", }`, ) .join(',\n'); @@ -256,13 +255,13 @@ function generateEvents(events: any[] | undefined) { `; const fieldNames = event.fields.map((field: any) => `"${field.name}"`); - const eventType = `${eventName}: {decode: (payload: L1EventPayload | undefined) => ${eventName} | undefined, functionSelector: FunctionSelector, fieldNames: string[] }`; + const eventType = `${eventName}: {decode: (payload: L1EventPayload | undefined) => ${eventName} | undefined, eventSelector: EventSelector, fieldNames: string[] }`; const eventImpl = `${eventName}: { - decode: this.decodeEvent(${event.fields.length}, FunctionSelector.fromSignature('${eventName}(${event.fields + decode: this.decodeEvent(${event.fields.length}, EventSelector.fromSignature('${eventName}(${event.fields .map(() => 'Field') .join(',')})'), [${fieldNames}]), - functionSelector: FunctionSelector.fromSignature('${eventName}(${event.fields.map(() => 'Field').join(',')})'), + eventSelector: EventSelector.fromSignature('${eventName}(${event.fields.map(() => 'Field').join(',')})'), fieldNames: [${fieldNames}], }`; @@ -277,21 +276,21 @@ function generateEvents(events: any[] | undefined) { eventDefs: eventsMetadata.map(({ eventDef }) => eventDef).join('\n'), events: ` // Partial application is chosen is to avoid the duplication of so much codegen. - private static decodeEvent(fieldsLength: number, functionSelector: FunctionSelector, fields: string[]): (payload: L1EventPayload | undefined) => T | undefined { + private static decodeEvent(fieldsLength: number, eventSelector: EventSelector, fields: string[]): (payload: L1EventPayload | undefined) => T | undefined { return (payload: L1EventPayload | undefined): T | undefined => { if (payload === undefined) { return undefined; } if ( - !functionSelector.equals( - FunctionSelector.fromField(payload.eventTypeId), + !eventSelector.equals( + EventSelector.fromField(payload.eventTypeId), ) ) { return undefined; } if (payload.event.items.length !== fieldsLength) { throw new Error( - 'Something is weird here, we have matching FunctionSelectors, but the actual payload has mismatched length', + 'Something is weird here, we have matching EventSelectors, but the actual payload has mismatched length', ); } @@ -352,6 +351,7 @@ import { EthAddressLike, FieldLike, Fr, + EventSelector, FunctionSelector, FunctionSelectorLike, L1EventPayload, diff --git a/yarn-project/circuit-types/src/interfaces/configs.ts b/yarn-project/circuit-types/src/interfaces/configs.ts index a4074c862c0..389c76f15f5 100644 --- a/yarn-project/circuit-types/src/interfaces/configs.ts +++ b/yarn-project/circuit-types/src/interfaces/configs.ts @@ -1,19 +1,11 @@ import { type AztecAddress, type EthAddress, type Fr, type FunctionSelector } from '@aztec/circuits.js'; -/** A function that the sequencer allows to run in either setup or teardown phase */ -export type AllowedFunction = - | { - /** The contract address this selector is valid for */ - address: AztecAddress; - /** The function selector */ - selector: FunctionSelector; - } - | { - /** The contract class this selector is valid for */ - classId: Fr; - /** The function selector */ - selector: FunctionSelector; - }; +type AllowedInstance = { address: AztecAddress }; +type AllowedInstanceFunction = { address: AztecAddress; selector: FunctionSelector }; +type AllowedClass = { classId: Fr }; +type AllowedClassFunction = { classId: Fr; selector: FunctionSelector }; + +export type AllowedElement = AllowedInstance | AllowedInstanceFunction | AllowedClass | AllowedClassFunction; /** * The sequencer configuration. @@ -34,9 +26,9 @@ export interface SequencerConfig { /** The path to the ACVM binary */ acvmBinaryPath?: string; /** The list of functions calls allowed to run in setup */ - allowedFunctionsInSetup?: AllowedFunction[]; + allowedInSetup?: AllowedElement[]; /** The list of functions calls allowed to run teardown */ - allowedFunctionsInTeardown?: AllowedFunction[]; + allowedInTeardown?: AllowedElement[]; /** Max block size */ maxBlockSizeInBytes?: number; /** Whether to require every tx to have a fee payer */ diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index 23a3ec6b914..6092eda2780 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -6,7 +6,7 @@ import { type PartialAddress, type Point, } from '@aztec/circuits.js'; -import { type ContractArtifact, type FunctionSelector } from '@aztec/foundation/abi'; +import { type ContractArtifact, type EventSelector } from '@aztec/foundation/abi'; import { type ContractClassWithId, type ContractInstanceWithAddress, @@ -17,8 +17,8 @@ import { type NodeInfo } from '@aztec/types/interfaces'; import { type AuthWitness } from '../auth_witness.js'; import { type L2Block } from '../l2_block.js'; import { type GetUnencryptedLogsResponse, type L1EventPayload, type LogFilter } from '../logs/index.js'; -import { type ExtendedNote } from '../notes/index.js'; -import { type NoteFilter } from '../notes/note_filter.js'; +import { type IncomingNotesFilter } from '../notes/incoming_notes_filter.js'; +import { type ExtendedNote, type OutgoingNotesFilter } from '../notes/index.js'; import { type NoteProcessorStats } from '../stats/stats.js'; import { type SimulatedTx, type Tx, type TxHash, type TxReceipt } from '../tx/index.js'; import { type TxEffect } from '../tx_effect.js'; @@ -224,11 +224,18 @@ export interface PXE { getPublicStorageAt(contract: AztecAddress, slot: Fr): Promise; /** - * Gets notes of accounts registered in this PXE based on the provided filter. + * Gets incoming notes of accounts registered in this PXE based on the provided filter. * @param filter - The filter to apply to the notes. * @returns The requested notes. */ - getNotes(filter: NoteFilter): Promise; + getIncomingNotes(filter: IncomingNotesFilter): Promise; + + /** + * Gets outgoing notes of accounts registered in this PXE based on the provided filter. + * @param filter - The filter to apply to the notes. + * @returns The requested notes. + */ + getOutgoingNotes(filter: OutgoingNotesFilter): Promise; /** * Finds the nonce(s) for a given note. @@ -390,7 +397,7 @@ export interface PXE { */ export interface EventMetadata { decode(payload: L1EventPayload): T | undefined; - functionSelector: FunctionSelector; + eventSelector: EventSelector; fieldNames: string[]; } diff --git a/yarn-project/circuit-types/src/notes/comparator.ts b/yarn-project/circuit-types/src/notes/comparator.ts new file mode 100644 index 00000000000..d3fcc5f57bf --- /dev/null +++ b/yarn-project/circuit-types/src/notes/comparator.ts @@ -0,0 +1,11 @@ +/** + * The comparator to use to compare. + */ +export enum Comparator { + EQ = 1, + NEQ = 2, + LT = 3, + LTE = 4, + GT = 5, + GTE = 6, +} diff --git a/yarn-project/circuit-types/src/notes/note_filter.ts b/yarn-project/circuit-types/src/notes/incoming_notes_filter.ts similarity index 60% rename from yarn-project/circuit-types/src/notes/note_filter.ts rename to yarn-project/circuit-types/src/notes/incoming_notes_filter.ts index b014a9b2367..27ff8dcfb41 100644 --- a/yarn-project/circuit-types/src/notes/note_filter.ts +++ b/yarn-project/circuit-types/src/notes/incoming_notes_filter.ts @@ -1,21 +1,13 @@ import { type AztecAddress, type Fr } from '@aztec/circuits.js'; import { type TxHash } from '../tx/tx_hash.js'; +import { type NoteStatus } from './note_status.js'; /** - * The status of notes to retrieve. + * A filter used to fetch incoming notes. + * @remarks This filter is applied as an intersection of all its params. */ -export enum NoteStatus { - ACTIVE = 1, - ACTIVE_OR_NULLIFIED = 2, - // TODO 4217: add 'NULLIFIED' -} - -/** - * A filter used to fetch Notes. - * @remarks This filter is applied as an intersection of all it's params. - */ -export type NoteFilter = { +export type IncomingNotesFilter = { /** Hash of a transaction from which to fetch the notes. */ txHash?: TxHash; /** The contract address the note belongs to. */ @@ -29,15 +21,3 @@ export type NoteFilter = { /** The siloed nullifier for the note. */ siloedNullifier?: Fr; }; - -/** - * The comparator to use to compare. - */ -export enum Comparator { - EQ = 1, - NEQ = 2, - LT = 3, - LTE = 4, - GT = 5, - GTE = 6, -} diff --git a/yarn-project/circuit-types/src/notes/index.ts b/yarn-project/circuit-types/src/notes/index.ts index cba82199985..30e8b36f510 100644 --- a/yarn-project/circuit-types/src/notes/index.ts +++ b/yarn-project/circuit-types/src/notes/index.ts @@ -1,2 +1,5 @@ -export * from './note_filter.js'; +export * from './comparator.js'; export * from './extended_note.js'; +export * from './incoming_notes_filter.js'; +export * from './note_status.js'; +export * from './outgoing_notes_filter.js'; diff --git a/yarn-project/circuit-types/src/notes/note_status.ts b/yarn-project/circuit-types/src/notes/note_status.ts new file mode 100644 index 00000000000..8a32cc4854b --- /dev/null +++ b/yarn-project/circuit-types/src/notes/note_status.ts @@ -0,0 +1,8 @@ +/** + * The status of notes to retrieve. + */ +export enum NoteStatus { + ACTIVE = 1, + ACTIVE_OR_NULLIFIED = 2, + // TODO 4217: add 'NULLIFIED' +} diff --git a/yarn-project/circuit-types/src/notes/outgoing_notes_filter.ts b/yarn-project/circuit-types/src/notes/outgoing_notes_filter.ts new file mode 100644 index 00000000000..888c3fc6ef1 --- /dev/null +++ b/yarn-project/circuit-types/src/notes/outgoing_notes_filter.ts @@ -0,0 +1,18 @@ +import { type AztecAddress, type Fr } from '@aztec/circuits.js'; + +import { type TxHash } from '../tx/tx_hash.js'; + +/** + * A filter used to fetch outgoing notes. + * @remarks This filter is applied as an intersection of all its params. + */ +export type OutgoingNotesFilter = { + /** Hash of a transaction from which to fetch the notes. */ + txHash?: TxHash; + /** The contract address the note belongs to. */ + contractAddress?: AztecAddress; + /** The specific storage location of the note on the contract. */ + storageSlot?: Fr; + /** The owner of the note (whose public key was used to encrypt the note). */ + owner?: AztecAddress; +}; diff --git a/yarn-project/circuit-types/src/stats/stats.ts b/yarn-project/circuit-types/src/stats/stats.ts index 0ddb50c7acf..d5d6f4d6a88 100644 --- a/yarn-project/circuit-types/src/stats/stats.ts +++ b/yarn-project/circuit-types/src/stats/stats.ts @@ -191,7 +191,9 @@ export type NoteProcessorStats = { /** How many notes have been seen and trial-decrypted. */ seen: number; /** How many notes had decryption deferred due to a missing contract */ - deferred: number; + deferredIncoming: number; + /** How many notes had decryption deferred due to a missing contract */ + deferredOutgoing: number; /** How many incoming notes were successfully decrypted. */ decryptedIncoming: number; /** How many outgoing notes were successfully decrypted. */ diff --git a/yarn-project/circuit-types/src/tx/processed_tx.ts b/yarn-project/circuit-types/src/tx/processed_tx.ts index 130cc4a6a6d..cf6bb977423 100644 --- a/yarn-project/circuit-types/src/tx/processed_tx.ts +++ b/yarn-project/circuit-types/src/tx/processed_tx.ts @@ -54,6 +54,7 @@ export const AVM_REQUEST = 'AVM' as const; export type AvmProvingRequest = { type: typeof AVM_REQUEST; + functionName: string; // informational only bytecode: Buffer; calldata: Fr[]; avmHints: AvmExecutionHints; diff --git a/yarn-project/circuit-types/src/tx/tx_receipt.ts b/yarn-project/circuit-types/src/tx/tx_receipt.ts index fc32f1b077f..1543ef9fd46 100644 --- a/yarn-project/circuit-types/src/tx/tx_receipt.ts +++ b/yarn-project/circuit-types/src/tx/tx_receipt.ts @@ -122,9 +122,15 @@ interface DebugInfo { */ l2ToL1Msgs: Fr[]; /** - * Notes created in this tx which belong to accounts which are registered in the PXE which was used to submit the - * tx. You will not receive notes of accounts which are not registered in the PXE here even though they were - * created in this tx. + * Notes created in this tx which were successfully decoded with the incoming keys of accounts which are registered + * in the PXE which was used to submit the tx. You will not get notes of accounts which are not registered in + * the PXE here even though they were created in this tx. */ - visibleNotes: ExtendedNote[]; + visibleIncomingNotes: ExtendedNote[]; + /** + * Notes created in this tx which were successfully decoded with the outgoing keys of accounts which are registered + * in the PXE which was used to submit the tx. You will not get notes of accounts which are not registered in + * the PXE here even though they were created in this tx. + */ + visibleOutgoingNotes: ExtendedNote[]; } diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index a690d935505..77ce004e452 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -7,7 +7,7 @@ export const MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL = 4; export const MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL = 16; export const MAX_NEW_L2_TO_L1_MSGS_PER_CALL = 2; export const MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL = 32; -export const MAX_PUBLIC_DATA_READS_PER_CALL = 16; +export const MAX_PUBLIC_DATA_READS_PER_CALL = 32; export const MAX_NOTE_HASH_READ_REQUESTS_PER_CALL = 32; export const MAX_NULLIFIER_READ_REQUESTS_PER_CALL = 32; export const MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL = 32; @@ -23,7 +23,7 @@ export const MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX = 32; export const MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX = 63; export const PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX = 1; export const MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX = 64; -export const MAX_PUBLIC_DATA_READS_PER_TX = 32; +export const MAX_PUBLIC_DATA_READS_PER_TX = 64; export const MAX_NEW_L2_TO_L1_MSGS_PER_TX = 8; export const MAX_NOTE_HASH_READ_REQUESTS_PER_TX = 128; export const MAX_NULLIFIER_READ_REQUESTS_PER_TX = 128; @@ -33,7 +33,7 @@ export const MAX_KEY_VALIDATION_REQUESTS_PER_TX = 64; export const MAX_NOTE_ENCRYPTED_LOGS_PER_TX = 64; export const MAX_ENCRYPTED_LOGS_PER_TX = 8; export const MAX_UNENCRYPTED_LOGS_PER_TX = 8; -export const MAX_PUBLIC_DATA_HINTS = 64; +export const MAX_PUBLIC_DATA_HINTS = 128; export const NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP = 16; export const VK_TREE_HEIGHT = 3; export const FUNCTION_TREE_HEIGHT = 5; @@ -86,6 +86,8 @@ export const DA_GAS_PER_BYTE = 16; export const FIXED_DA_GAS = 512; export const CANONICAL_KEY_REGISTRY_ADDRESS = 2153455745675440165069577621832684870696142028027528497509357256345838682961n; +export const CANONICAL_AUTH_REGISTRY_ADDRESS = + 18091885756106795278141309801070173692350235742979924147720536894670507925831n; export const DEPLOYER_CONTRACT_ADDRESS = 19511485909966796736993840362353440247573331327062358513665772226446629198132n; export const REGISTERER_CONTRACT_ADDRESS = 21791696151759019003097706094037044371210776294983020497737005968946992649239n; @@ -132,21 +134,21 @@ export const TX_REQUEST_LENGTH = 13; export const TOTAL_FEES_LENGTH = 1; export const HEADER_LENGTH = 23; export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 457; -export const PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 530; +export const PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 578; export const PRIVATE_CALL_STACK_ITEM_LENGTH = 460; export const PUBLIC_CONTEXT_INPUTS_LENGTH = 41; export const AGGREGATION_OBJECT_LENGTH = 16; export const SCOPED_READ_REQUEST_LEN = 3; export const PUBLIC_DATA_READ_LENGTH = 2; -export const VALIDATION_REQUESTS_LENGTH = 1538; +export const VALIDATION_REQUESTS_LENGTH = 1602; export const PUBLIC_DATA_UPDATE_REQUEST_LENGTH = 3; export const COMBINED_ACCUMULATED_DATA_LENGTH = 333; export const COMBINED_CONSTANT_DATA_LENGTH = 40; export const CALL_REQUEST_LENGTH = 7; export const PRIVATE_ACCUMULATED_DATA_LENGTH = 1152; -export const PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2739; +export const PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 2803; export const PUBLIC_ACCUMULATED_DATA_LENGTH = 983; -export const PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 3770; +export const PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 3834; export const KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 383; export const CONSTANT_ROLLUP_DATA_LENGTH = 14; export const BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 31; diff --git a/yarn-project/circuits.js/src/contract/artifact_hash.ts b/yarn-project/circuits.js/src/contract/artifact_hash.ts index 1ad0a71fb7a..cbaadfdc7d9 100644 --- a/yarn-project/circuits.js/src/contract/artifact_hash.ts +++ b/yarn-project/circuits.js/src/contract/artifact_hash.ts @@ -59,29 +59,23 @@ export function computeArtifactHashPreimage(artifact: ContractArtifact) { } export function computeArtifactMetadataHash(artifact: ContractArtifact) { + // TODO: #6021 We need to make sure the artifact is deterministic from any specific compiler run. This relates to selectors not being sorted and being + // apparently random in the order they appear after compiled w/ nargo. We can try to sort this upon loading an artifact. // TODO: #6021: Should we use the sorted event selectors instead? They'd need to be unique for that. // Response - The output selectors need to be sorted, because if not noir makes no guarantees on the order of outputs for some reason const metadata = { name: artifact.name, outputs: artifact.outputs }; - // This is a temporary workaround for the Key Registry - // TODO: #6021 We need to make sure the artifact is deterministic from any specific compiler run. This relates to selectors not being sorted and being - // apparently random in the order they appear after compiled w/ nargo. We can try to sort this upon loading an artifact. - if (artifact.name === 'KeyRegistry') { - return sha256Fr(Buffer.from(JSON.stringify({ name: artifact.name }), 'utf-8')); - } - - // TODO(palla/gas) The GasToken depends on protocol-circuits/types, which in turn includes the address of the GasToken as a constant. - // Even though it is not being used, it seems that it is affecting the generated metadata hash. So we ignore it - // for the time being until we can determine whether it's an issue in how Noir deals with unused code in imported packages, - // or we move that constant out of protocol-circuits/types and into the rollup-lib, which is the only place where we actually need it. - if (artifact.name === 'GasToken') { - return sha256Fr(Buffer.from(JSON.stringify({ name: artifact.name }), 'utf-8')); - } + const exceptions: string[] = [ + 'AuthRegistry', + 'KeyRegistry', + 'GasToken', + 'ContractInstanceDeployer', + 'ContractClassRegisterer', + ]; - // TODO(palla) Minimize impact of contract instance deployer and class registerer addresses - // changing, using the same trick as in the contracts above. - if (artifact.name === 'ContractInstanceDeployer' || artifact.name === 'ContractClassRegisterer') { + // This is a temporary workaround for the canonical contracts to have deterministic deployments. + if (exceptions.includes(artifact.name)) { return sha256Fr(Buffer.from(JSON.stringify({ name: artifact.name }), 'utf-8')); } diff --git a/yarn-project/circuits.js/src/contract/contract_instance.ts b/yarn-project/circuits.js/src/contract/contract_instance.ts index 1d45791cdab..3168be0ce0c 100644 --- a/yarn-project/circuits.js/src/contract/contract_instance.ts +++ b/yarn-project/circuits.js/src/contract/contract_instance.ts @@ -1,11 +1,20 @@ -import { type ContractArtifact, type FunctionArtifact, getDefaultInitializer } from '@aztec/foundation/abi'; +import { + type ContractArtifact, + type FunctionArtifact, + FunctionSelector, + getDefaultInitializer, +} from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; import { type ContractInstance, type ContractInstanceWithAddress } from '@aztec/types/contracts'; import { getContractClassFromArtifact } from '../contract/contract_class.js'; import { computeContractClassId } from '../contract/contract_class_id.js'; -import { computeContractAddressFromInstance, computeInitializationHash } from './contract_address.js'; +import { + computeContractAddressFromInstance, + computeInitializationHash, + computeInitializationHashFromEncodedArgs, +} from './contract_address.js'; /** * Generates a Contract Instance from the deployment params. @@ -18,6 +27,7 @@ export function getContractInstanceFromDeployParams( opts: { constructorArtifact?: FunctionArtifact | string; constructorArgs?: any[]; + skipArgsDecoding?: boolean; salt?: Fr; publicKeysHash?: Fr; deployer?: AztecAddress; @@ -27,10 +37,15 @@ export function getContractInstanceFromDeployParams( const salt = opts.salt ?? Fr.random(); const constructorArtifact = getConstructorArtifact(artifact, opts.constructorArtifact); const deployer = opts.deployer ?? AztecAddress.ZERO; - const contractClass = getContractClassFromArtifact(artifact); const contractClassId = computeContractClassId(contractClass); - const initializationHash = computeInitializationHash(constructorArtifact, args); + const initializationHash = + constructorArtifact && opts?.skipArgsDecoding + ? computeInitializationHashFromEncodedArgs( + FunctionSelector.fromNameAndParameters(constructorArtifact?.name, constructorArtifact?.parameters), + args, + ) + : computeInitializationHash(constructorArtifact, args); const publicKeysHash = opts.publicKeysHash ?? Fr.ZERO; const instance: ContractInstance = { diff --git a/yarn-project/circuits.js/src/keys/derivation.ts b/yarn-project/circuits.js/src/keys/derivation.ts index 4d5e5ba3915..326940d65cb 100644 --- a/yarn-project/circuits.js/src/keys/derivation.ts +++ b/yarn-project/circuits.js/src/keys/derivation.ts @@ -13,7 +13,7 @@ import { getKeyGenerator } from './utils.js'; const curve = new Grumpkin(); export function computeAppNullifierSecretKey(masterNullifierSecretKey: GrumpkinPrivateKey, app: AztecAddress): Fr { - return poseidon2Hash([masterNullifierSecretKey.high, masterNullifierSecretKey.low, app, GeneratorIndex.NSK_M]); + return computeAppSecretKey(masterNullifierSecretKey, app, 'n'); // 'n' is the key prefix for nullifier secret key } export function computeAppSecretKey(skM: GrumpkinPrivateKey, app: AztecAddress, keyPrefix: KeyPrefix): Fr { @@ -40,12 +40,11 @@ export function computeIvskApp(ivsk: GrumpkinPrivateKey, address: AztecAddress) return new Fq((I.toBigInt() + ivsk.toBigInt()) % Fq.MODULUS); } -export function computeOvskApp(ovsk: GrumpkinPrivateKey, address: AztecAddress) { +export function computeOvskApp(ovsk: GrumpkinPrivateKey, app: AztecAddress) { + const ovskAppFr = computeAppSecretKey(ovsk, app, 'ov'); // 'ov' is the key prefix for outgoing viewing key // Here we are intentionally converting Fr (output of poseidon) to Fq. This is fine even though a distribution of // P = s * G will not be uniform because 2 * (q - r) / q is small. - return GrumpkinPrivateKey.fromBuffer( - poseidon2Hash([address.toField(), ovsk.high, ovsk.low, GeneratorIndex.OVSK_M]).toBuffer(), - ); + return GrumpkinPrivateKey.fromBuffer(ovskAppFr.toBuffer()); } export function deriveMasterNullifierSecretKey(secretKey: Fr): GrumpkinScalar { diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap index 4bc99c19ad4..df58d2f111e 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/public_call_stack_item.test.ts.snap @@ -1,9 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PublicCallStackItem Computes a callstack item hash 1`] = `"0x2cbb07062730bfc4933f5e8d533d5b62ac6e1b7922b831993377cd85d7445399"`; +exports[`PublicCallStackItem Computes a callstack item hash 1`] = `"0x1860d00d9602966e398c6d585216baba2ffa8c5eddda5faee041136665d8482a"`; -exports[`PublicCallStackItem Computes a callstack item request hash 1`] = `"0x124a62189073cc551fea148d735d1e8b452e38537e075895b02ccfd9c9901819"`; +exports[`PublicCallStackItem Computes a callstack item request hash 1`] = `"0x2751111aa213d9d21279da53531bf90c2da272cf3f959e2a2a1dfceb487bf102"`; -exports[`PublicCallStackItem computes empty item hash 1`] = `Fr<0x1553af0f4023e449e888c744485ea429955449a81d58598f8d63db48c321cbc7>`; +exports[`PublicCallStackItem computes empty item hash 1`] = `Fr<0x2c9346c79caabece80bfe330b9e45ed4dde78099e01a013da690485738a42af2>`; -exports[`PublicCallStackItem computes hash 1`] = `Fr<0x1943f02bfc111012aa1f28688425817d45653586f0c4665feb6723c9b539e147>`; +exports[`PublicCallStackItem computes hash 1`] = `Fr<0x272aa1a005b7839cdc8b72f50d2020529da11a5245f3c11481c29ce8b55e0da2>`; diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap index 0827283a033..5194415896a 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/public_circuit_public_inputs.test.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`PublicCircuitPublicInputs computes empty inputs hash 1`] = `Fr<0x03ab5026ab5b3e6b81be5c3ec31c7937f293180c25a240eb75693cda81bb2a05>`; +exports[`PublicCircuitPublicInputs computes empty inputs hash 1`] = `Fr<0x01681b19fb7fe21aa9c2cf9fb47520149f46edd679b2e7c2b2c4a279fd685125>`; -exports[`PublicCircuitPublicInputs hash matches snapshot 1`] = `Fr<0x17c2cd1141dbec7dd8598fee17e90627d0e843e7991533d4378191cea7c2abad>`; +exports[`PublicCircuitPublicInputs hash matches snapshot 1`] = `Fr<0x162be1c50854010ab8ab30efde30e9fb05c8d441c0d5942bb0eace875f584c64>`; diff --git a/yarn-project/circuits.js/src/structs/avm/avm.ts b/yarn-project/circuits.js/src/structs/avm/avm.ts index 19a55c38667..f33335f800c 100644 --- a/yarn-project/circuits.js/src/structs/avm/avm.ts +++ b/yarn-project/circuits.js/src/structs/avm/avm.ts @@ -367,6 +367,7 @@ export class AvmExecutionHints { export class AvmCircuitInputs { constructor( + public readonly functionName: string, // only informational public readonly bytecode: Buffer, public readonly calldata: Fr[], public readonly publicInputs: PublicCircuitPublicInputs, @@ -378,7 +379,10 @@ export class AvmCircuitInputs { * @returns - The inputs serialized to a buffer. */ toBuffer() { + const functionNameBuffer = Buffer.from(this.functionName); return serializeToBuffer( + functionNameBuffer.length, + functionNameBuffer, this.bytecode.length, this.bytecode, this.calldata.length, @@ -402,7 +406,11 @@ export class AvmCircuitInputs { */ isEmpty(): boolean { return ( - this.bytecode.length == 0 && this.calldata.length == 0 && this.publicInputs.isEmpty() && this.avmHints.isEmpty() + this.functionName.length == 0 && + this.bytecode.length == 0 && + this.calldata.length == 0 && + this.publicInputs.isEmpty() && + this.avmHints.isEmpty() ); } @@ -421,7 +429,7 @@ export class AvmCircuitInputs { * @returns An array of fields. */ static getFields(fields: FieldsOf) { - return [fields.bytecode, fields.calldata, fields.publicInputs, fields.avmHints] as const; + return [fields.functionName, fields.bytecode, fields.calldata, fields.publicInputs, fields.avmHints] as const; } /** @@ -432,8 +440,9 @@ export class AvmCircuitInputs { static fromBuffer(buff: Buffer | BufferReader): AvmCircuitInputs { const reader = BufferReader.asReader(buff); return new AvmCircuitInputs( - reader.readBuffer(), - reader.readVector(Fr), + /*functionName=*/ reader.readBuffer().toString(), + /*bytecode=*/ reader.readBuffer(), + /*calldata=*/ reader.readVector(Fr), PublicCircuitPublicInputs.fromBuffer(reader), AvmExecutionHints.fromBuffer(reader), ); diff --git a/yarn-project/circuits.js/src/structs/index.ts b/yarn-project/circuits.js/src/structs/index.ts index c8bf5154dc5..d90356a074a 100644 --- a/yarn-project/circuits.js/src/structs/index.ts +++ b/yarn-project/circuits.js/src/structs/index.ts @@ -84,6 +84,6 @@ export * from './tx_request.js'; export * from './validation_requests.js'; export * from './verification_key.js'; -export { FunctionSelector } from '@aztec/foundation/abi'; +export { EventSelector, FunctionSelector } from '@aztec/foundation/abi'; export * from '@aztec/foundation/aztec-address'; export * from '@aztec/foundation/fields'; diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index feb968a0dd1..c6fc3c783ec 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -1336,6 +1336,7 @@ export function makeAvmExecutionHints( */ export function makeAvmCircuitInputs(seed = 0, overrides: Partial> = {}): AvmCircuitInputs { return AvmCircuitInputs.from({ + functionName: `function${seed}`, bytecode: makeBytes((seed % 100) + 100, seed), calldata: makeArray((seed % 100) + 10, i => new Fr(i), seed + 0x1000), publicInputs: makePublicCircuitPublicInputs(seed + 0x2000), diff --git a/yarn-project/cli/src/inspect.ts b/yarn-project/cli/src/inspect.ts index 93fd5fde5ba..f8ff880f1ee 100644 --- a/yarn-project/cli/src/inspect.ts +++ b/yarn-project/cli/src/inspect.ts @@ -42,7 +42,7 @@ export async function inspectTx( const [receipt, effects, notes] = await Promise.all([ pxe.getTxReceipt(txHash), pxe.getTxEffect(txHash), - pxe.getNotes({ txHash, status: NoteStatus.ACTIVE_OR_NULLIFIED }), + pxe.getIncomingNotes({ txHash, status: NoteStatus.ACTIVE_OR_NULLIFIED }), ]); if (!receipt || !effects) { @@ -103,7 +103,7 @@ export async function inspectTx( if (nullifierCount > 0) { log(' Nullifiers:'); for (const nullifier of effects.nullifiers) { - const [note] = await pxe.getNotes({ siloedNullifier: nullifier }); + const [note] = await pxe.getIncomingNotes({ siloedNullifier: nullifier }); const deployed = deployNullifiers[nullifier.toString()]; const initialized = initNullifiers[nullifier.toString()]; const registered = classNullifiers[nullifier.toString()]; diff --git a/yarn-project/deploy_npm.sh b/yarn-project/deploy_npm.sh index f8d18abdac7..b7154d1226c 100755 --- a/yarn-project/deploy_npm.sh +++ b/yarn-project/deploy_npm.sh @@ -105,3 +105,4 @@ deploy_package p2p deploy_package prover-client deploy_package sequencer-client deploy_package aztec-node +deploy_package txe diff --git a/yarn-project/end-to-end/Earthfile b/yarn-project/end-to-end/Earthfile index 10db3c25b4a..2b3eda22113 100644 --- a/yarn-project/end-to-end/Earthfile +++ b/yarn-project/end-to-end/Earthfile @@ -46,6 +46,9 @@ E2E_TEST: # Run our docker compose, ending whenever sandbox ends, filtering out noisy eth_getLogs RUN docker run -e HARDWARE_CONCURRENCY=$hardware_concurrency --rm aztecprotocol/end-to-end:$AZTEC_DOCKER_TAG $test || $allow_fail +e2e-p2p: + DO +E2E_TEST --test=./src/e2e_p2p_network.test.ts + e2e-2-pxes: DO +E2E_TEST --test=./src/e2e_2_pxes.test.ts diff --git a/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts b/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts index b34053842f5..0f146badc93 100644 --- a/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts +++ b/yarn-project/end-to-end/src/benchmarks/bench_process_history.test.ts @@ -21,7 +21,7 @@ import { const BLOCK_SIZE = BENCHMARK_HISTORY_BLOCK_SIZE; const CHAIN_LENGTHS = BENCHMARK_HISTORY_CHAIN_LENGTHS; const MAX_CHAIN_LENGTH = CHAIN_LENGTHS[CHAIN_LENGTHS.length - 1]; -const SETUP_BLOCK_COUNT = 3; // deploy protocol contracts + deploy account + deploy contract +const SETUP_BLOCK_COUNT = 4; // deploy protocol contracts + deploy account + deploy contract describe('benchmarks/process_history', () => { let context: EndToEndContext; diff --git a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts index fb5f844a03c..3bb9d05de91 100644 --- a/yarn-project/end-to-end/src/e2e_2_pxes.test.ts +++ b/yarn-project/end-to-end/src/e2e_2_pxes.test.ts @@ -347,13 +347,20 @@ describe('e2e_2_pxes', () => { const noteValue = 5; let note: ExtendedNote; { + const owner = walletA.getAddress(); + const outgoingViewer = owner; + const receipt = await testContract.methods - .call_create_note(noteValue, walletA.getAddress(), walletA.getAddress(), noteStorageSlot) + .call_create_note(noteValue, owner, outgoingViewer, noteStorageSlot) .send() .wait({ debug: true }); - const notes = receipt.debugInfo?.visibleNotes; - expect(notes).toHaveLength(1); - note = notes![0]; + const { visibleIncomingNotes, visibleOutgoingNotes } = receipt.debugInfo!; + expect(visibleIncomingNotes).toHaveLength(1); + note = visibleIncomingNotes![0]; + + // Since owner is the same as outgoing viewer the incoming and outgoing notes should be the same + expect(visibleOutgoingNotes).toHaveLength(1); + expect(visibleOutgoingNotes![0]).toEqual(note); } // 3. Nullify the note diff --git a/yarn-project/end-to-end/src/e2e_authwit.test.ts b/yarn-project/end-to-end/src/e2e_authwit.test.ts index 2eb07f497d9..8200ce331b7 100644 --- a/yarn-project/end-to-end/src/e2e_authwit.test.ts +++ b/yarn-project/end-to-end/src/e2e_authwit.test.ts @@ -1,5 +1,6 @@ import { type AccountWallet, Fr, computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/aztec.js'; -import { SchnorrAccountContract } from '@aztec/noir-contracts.js'; +import { AuthRegistryContract, SchnorrAccountContract } from '@aztec/noir-contracts.js'; +import { getCanonicalAuthRegistry } from '@aztec/protocol-contracts/auth-registry'; import { jest } from '@jest/globals'; @@ -206,8 +207,8 @@ describe('e2e_authwit_tests', () => { isValidInPublic: true, }); - const c = await SchnorrAccountContract.at(wallets[0].getAddress(), wallets[0]); - await c.withWallet(wallets[1]).methods.spend_public_authwit(innerHash).send().wait(); + const registry = await AuthRegistryContract.at(getCanonicalAuthRegistry().instance.address, wallets[1]); + await registry.methods.consume(wallets[0].getAddress(), innerHash).send().wait(); expect(await wallets[0].lookupValidity(wallets[0].getAddress(), outerHash)).toEqual({ isValidInPrivate: false, @@ -232,17 +233,17 @@ describe('e2e_authwit_tests', () => { isValidInPublic: true, }); - await wallets[0].cancelAuthWit(outerHash).send().wait(); + await wallets[0].cancelPublicAuthWit(outerHash).send().wait(); expect(await wallets[0].lookupValidity(wallets[0].getAddress(), outerHash)).toEqual({ isValidInPrivate: false, isValidInPublic: false, }); - const c = await SchnorrAccountContract.at(wallets[0].getAddress(), wallets[0]); - const txCancelledAuthwit = c.withWallet(wallets[1]).methods.spend_public_authwit(innerHash).send(); - // The transaction should be dropped because of a cancelled authwit (duplicate nullifier) - await expect(txCancelledAuthwit.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); + const registry = await AuthRegistryContract.at(getCanonicalAuthRegistry().instance.address, wallets[1]); + await expect(registry.methods.consume(wallets[0].getAddress(), innerHash).simulate()).rejects.toThrow( + /unauthorized/, + ); }); }); }); diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/burn.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/burn.test.ts index 05ca22f844f..5e336d1b63d 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/burn.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/burn.test.ts @@ -14,7 +14,7 @@ describe('e2e_blacklist_token_contract burn', () => { await t.setup(); // Have to destructure again to ensure we have latest refs. ({ asset, tokenSim, wallets, blacklisted } = t); - }); + }, 600_000); afterAll(async () => { await t.teardown(); @@ -48,9 +48,9 @@ describe('e2e_blacklist_token_contract burn', () => { tokenSim.burnPublic(wallets[0].getAddress(), amount); - // Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer. - const txReplay = asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).send(); - await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); + await expect( + asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).simulate(), + ).rejects.toThrow(/unauthorized/); }); describe('failure cases', () => { @@ -68,7 +68,7 @@ describe('e2e_blacklist_token_contract burn', () => { const amount = balance0 - 1n; expect(amount).toBeGreaterThan(0n); const nonce = 1; - await expect(asset.methods.burn_public(wallets[0].getAddress(), amount, nonce).prove()).rejects.toThrow( + await expect(asset.methods.burn_public(wallets[0].getAddress(), amount, nonce).simulate()).rejects.toThrow( 'Assertion failed: invalid nonce', ); }); @@ -78,8 +78,8 @@ describe('e2e_blacklist_token_contract burn', () => { const amount = balance0 + 1n; const nonce = Fr.random(); await expect( - asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).prove(), - ).rejects.toThrow('Assertion failed: Message not authorized by account'); + asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).simulate(), + ).rejects.toThrow(/unauthorized/); }); it('burn more than balance on behalf of other', async () => { @@ -106,8 +106,8 @@ describe('e2e_blacklist_token_contract burn', () => { await wallets[0].setPublicAuthWit({ caller: wallets[0].getAddress(), action }, true).send().wait(); await expect( - asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).prove(), - ).rejects.toThrow('Assertion failed: Message not authorized by account'); + asset.withWallet(wallets[1]).methods.burn_public(wallets[0].getAddress(), amount, nonce).simulate(), + ).rejects.toThrow(/unauthorized/); }); it('burn from blacklisted account', async () => { diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/minting.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/minting.test.ts index ab535e3e61a..b3b7eef247d 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/minting.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/minting.test.ts @@ -14,7 +14,7 @@ describe('e2e_blacklist_token_contract mint', () => { await t.setup(); // Have to destructure again to ensure we have latest refs. ({ asset, tokenSim, wallets, blacklisted } = t); - }, 300_000); + }, 600_000); afterAll(async () => { await t.teardown(); @@ -99,9 +99,9 @@ describe('e2e_blacklist_token_contract mint', () => { tokenSim.redeemShield(wallets[0].getAddress(), amount); // 1 note should be created containing `amount` of tokens - const { visibleNotes } = receiptClaim.debugInfo!; - expect(visibleNotes.length).toBe(1); - expect(visibleNotes[0].note.items[0].toBigInt()).toBe(amount); + const { visibleIncomingNotes } = receiptClaim.debugInfo!; + expect(visibleIncomingNotes.length).toBe(1); + expect(visibleIncomingNotes[0].note.items[0].toBigInt()).toBe(amount); }); }); diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/shielding.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/shielding.test.ts index 22701ac0cbf..8898eb47798 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/shielding.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/shielding.test.ts @@ -1,6 +1,6 @@ import { Fr, computeSecretHash } from '@aztec/aztec.js'; -import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/index.js'; +import { U128_UNDERFLOW_ERROR } from '../fixtures/index.js'; import { BlacklistTokenContractTest } from './blacklist_token_contract_test.js'; describe('e2e_blacklist_token_contract shield + redeem_shield', () => { @@ -13,7 +13,7 @@ describe('e2e_blacklist_token_contract shield + redeem_shield', () => { await t.setup(); // Have to destructure again to ensure we have latest refs. ({ asset, tokenSim, wallets, blacklisted } = t); - }); + }, 600_000); afterAll(async () => { await t.teardown(); @@ -63,11 +63,9 @@ describe('e2e_blacklist_token_contract shield + redeem_shield', () => { await t.tokenSim.check(); // Check that replaying the shield should fail! - const txReplay = asset - .withWallet(wallets[1]) - .methods.shield(wallets[0].getAddress(), amount, secretHash, nonce) - .send(); - await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); + await expect( + asset.withWallet(wallets[1]).methods.shield(wallets[0].getAddress(), amount, secretHash, nonce).simulate(), + ).rejects.toThrow(/unauthorized/); // Redeem it await t.addPendingShieldNoteToPXE(0, amount, secretHash, receipt.txHash); @@ -120,7 +118,7 @@ describe('e2e_blacklist_token_contract shield + redeem_shield', () => { const action = asset.withWallet(wallets[2]).methods.shield(wallets[0].getAddress(), amount, secretHash, nonce); await wallets[0].setPublicAuthWit({ caller: wallets[1].getAddress(), action }, true).send().wait(); - await expect(action.prove()).rejects.toThrow('Assertion failed: Message not authorized by account'); + await expect(action.prove()).rejects.toThrow(/unauthorized/); }); it('on behalf of other (without approval)', async () => { @@ -130,8 +128,8 @@ describe('e2e_blacklist_token_contract shield + redeem_shield', () => { expect(amount).toBeGreaterThan(0n); await expect( - asset.withWallet(wallets[1]).methods.shield(wallets[0].getAddress(), amount, secretHash, nonce).prove(), - ).rejects.toThrow(`Assertion failed: Message not authorized by account`); + asset.withWallet(wallets[1]).methods.shield(wallets[0].getAddress(), amount, secretHash, nonce).simulate(), + ).rejects.toThrow(/unauthorized/); }); it('shielding from blacklisted account', async () => { diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts index e69813b6fed..ac8176b9e68 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_private.test.ts @@ -14,7 +14,7 @@ describe('e2e_blacklist_token_contract transfer private', () => { await t.setup(); // Have to destructure again to ensure we have latest refs. ({ asset, tokenSim, wallets, blacklisted } = t); - }); + }, 600_000); afterAll(async () => { await t.teardown(); diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_public.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_public.test.ts index 0b9fd846376..b1854b7677b 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_public.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/transfer_public.test.ts @@ -1,6 +1,6 @@ import { Fr } from '@aztec/aztec.js'; -import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/index.js'; +import { U128_UNDERFLOW_ERROR } from '../fixtures/index.js'; import { BlacklistTokenContractTest } from './blacklist_token_contract_test.js'; describe('e2e_blacklist_token_contract transfer public', () => { @@ -14,7 +14,7 @@ describe('e2e_blacklist_token_contract transfer public', () => { await t.setup(); // Have to destructure again to ensure we have latest refs. ({ asset, tokenSim, wallets, blacklisted } = t); - }); + }, 600_000); afterAll(async () => { await t.teardown(); @@ -61,12 +61,12 @@ describe('e2e_blacklist_token_contract transfer public', () => { tokenSim.transferPublic(wallets[0].getAddress(), wallets[1].getAddress(), amount); - // Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer. - const txReplay = asset - .withWallet(wallets[1]) - .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) - .send(); - await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); + await expect( + asset + .withWallet(wallets[1]) + .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) + .simulate(), + ).rejects.toThrow(/unauthorized/); }); describe('failure cases', () => { @@ -96,8 +96,8 @@ describe('e2e_blacklist_token_contract transfer public', () => { asset .withWallet(wallets[1]) .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce) - .prove(), - ).rejects.toThrow('Assertion failed: Message not authorized by account'); + .simulate(), + ).rejects.toThrow(/unauthorized/); }); it('transfer more than balance on behalf of other', async () => { @@ -137,26 +137,7 @@ describe('e2e_blacklist_token_contract transfer public', () => { await wallets[0].setPublicAuthWit({ caller: wallets[0].getAddress(), action }, true).send().wait(); // Perform the transfer - await expect(action.prove()).rejects.toThrow('Assertion failed: Message not authorized by account'); - - expect(await asset.methods.balance_of_public(wallets[0].getAddress()).simulate()).toEqual(balance0); - expect(await asset.methods.balance_of_public(wallets[1].getAddress()).simulate()).toEqual(balance1); - }); - - it('transfer on behalf of other, wrong designated caller', async () => { - const balance0 = await asset.methods.balance_of_public(wallets[0].getAddress()).simulate(); - const balance1 = await asset.methods.balance_of_public(wallets[1].getAddress()).simulate(); - const amount = balance0 + 2n; - const nonce = Fr.random(); - expect(amount).toBeGreaterThan(0n); - - // We need to compute the message we want to sign and add it to the wallet as approved - const action = asset - .withWallet(wallets[1]) - .methods.transfer_public(wallets[0].getAddress(), wallets[1].getAddress(), amount, nonce); - await wallets[0].setPublicAuthWit({ caller: wallets[0].getAddress(), action }, true).send().wait(); - // Perform the transfer - await expect(action.prove()).rejects.toThrow('Assertion failed: Message not authorized by account'); + await expect(action.simulate()).rejects.toThrow(/unauthorized/); expect(await asset.methods.balance_of_public(wallets[0].getAddress()).simulate()).toEqual(balance0); expect(await asset.methods.balance_of_public(wallets[1].getAddress()).simulate()).toEqual(balance1); diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/unshielding.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/unshielding.test.ts index 224a26b5f0f..8d11daf3c5e 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract/unshielding.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract/unshielding.test.ts @@ -14,7 +14,7 @@ describe('e2e_blacklist_token_contract unshielding', () => { await t.setup(); // Have to destructure again to ensure we have latest refs. ({ asset, tokenSim, wallets, blacklisted } = t); - }); + }, 600_000); afterAll(async () => { await t.teardown(); diff --git a/yarn-project/end-to-end/src/e2e_card_game.test.ts b/yarn-project/end-to-end/src/e2e_card_game.test.ts index ef9fa465666..24629f1e8f7 100644 --- a/yarn-project/end-to-end/src/e2e_card_game.test.ts +++ b/yarn-project/end-to-end/src/e2e_card_game.test.ts @@ -44,13 +44,13 @@ interface Game { current_round: bigint; } -interface NoirOption { - _is_some: boolean; - _value: T; +interface NoirBoundedVec { + storage: T[]; + len: bigint; } -function unwrapOptions(options: NoirOption[]): T[] { - return options.filter((option: any) => option._is_some).map((option: any) => option._value); +function boundedVecToArray(boundedVec: NoirBoundedVec): T[] { + return boundedVec.storage.slice(0, Number(boundedVec.len)); } // Game settings. @@ -149,7 +149,7 @@ describe('e2e_card_game', () => { // docs:end:send_tx const collection = await contract.methods.view_collection_cards(firstPlayer, 0).simulate({ from: firstPlayer }); const expected = getPackedCards(0, seed); - expect(unwrapOptions(collection)).toMatchObject(expected); + expect(boundedVecToArray(collection)).toMatchObject(expected); }); describe('game join', () => { @@ -161,7 +161,7 @@ describe('e2e_card_game', () => { contract.methods.buy_pack(seed).send().wait(), contractAsSecondPlayer.methods.buy_pack(seed).send().wait(), ]); - firstPlayerCollection = unwrapOptions( + firstPlayerCollection = boundedVecToArray( await contract.methods.view_collection_cards(firstPlayer, 0).simulate({ from: firstPlayer }), ); }); @@ -180,8 +180,8 @@ describe('e2e_card_game', () => { ).rejects.toThrow(`Assertion failed: Cannot return zero notes`); const collection = await contract.methods.view_collection_cards(firstPlayer, 0).simulate({ from: firstPlayer }); - expect(unwrapOptions(collection)).toHaveLength(1); - expect(unwrapOptions(collection)).toMatchObject([firstPlayerCollection[1]]); + expect(boundedVecToArray(collection)).toHaveLength(1); + expect(boundedVecToArray(collection)).toMatchObject([firstPlayerCollection[1]]); expect((await contract.methods.view_game(GAME_ID).simulate({ from: firstPlayer })) as Game).toMatchObject({ players: [ @@ -204,10 +204,10 @@ describe('e2e_card_game', () => { }); it('should start games', async () => { - const secondPlayerCollection = unwrapOptions( + const secondPlayerCollection = boundedVecToArray( (await contract.methods .view_collection_cards(secondPlayer, 0) - .simulate({ from: secondPlayer })) as NoirOption[], + .simulate({ from: secondPlayer })) as NoirBoundedVec, ); await Promise.all([ @@ -257,15 +257,15 @@ describe('e2e_card_game', () => { contractAsThirdPlayer.methods.buy_pack(seed).send().wait(), ]); - firstPlayerCollection = unwrapOptions( + firstPlayerCollection = boundedVecToArray( await contract.methods.view_collection_cards(firstPlayer, 0).simulate({ from: firstPlayer }), ); - secondPlayerCollection = unwrapOptions( + secondPlayerCollection = boundedVecToArray( await contract.methods.view_collection_cards(secondPlayer, 0).simulate({ from: secondPlayer }), ); - thirdPlayerCOllection = unwrapOptions( + thirdPlayerCOllection = boundedVecToArray( await contract.methods.view_collection_cards(thirdPlayer, 0).simulate({ from: thirdPlayer }), ); }); @@ -319,8 +319,8 @@ describe('e2e_card_game', () => { await contractFor(winner).methods.claim_cards(GAME_ID, game.rounds_cards.map(cardToField)).send().wait(); - const winnerCollection = unwrapOptions( - (await contract.methods.view_collection_cards(winner, 0).simulate({ from: winner })) as NoirOption[], + const winnerCollection = boundedVecToArray( + (await contract.methods.view_collection_cards(winner, 0).simulate({ from: winner })) as NoirBoundedVec, ); const winnerGameDeck = [winnerCollection[0], winnerCollection[3]]; diff --git a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts index 01cc6b8b067..a857c528f4b 100644 --- a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts +++ b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts @@ -225,7 +225,7 @@ describe('e2e_crowdfunding_and_claim', () => { }); // Get the notes emitted by the Crowdfunding contract and check that only 1 was emitted (the value note) - const notes = donateTxReceipt.debugInfo?.visibleNotes.filter(x => + const notes = donateTxReceipt.debugInfo?.visibleIncomingNotes.filter(x => x.contractAddress.equals(crowdfundingContract.address), ); expect(notes!.length).toEqual(1); @@ -291,7 +291,7 @@ describe('e2e_crowdfunding_and_claim', () => { }); // Get the notes emitted by the Crowdfunding contract and check that only 1 was emitted (the value note) - const notes = donateTxReceipt.debugInfo?.visibleNotes.filter(x => + const notes = donateTxReceipt.debugInfo?.visibleIncomingNotes.filter(x => x.contractAddress.equals(crowdfundingContract.address), ); expect(notes!.length).toEqual(1); @@ -347,9 +347,9 @@ describe('e2e_crowdfunding_and_claim', () => { let note: any; { const receipt = await inclusionsProofsContract.methods.create_note(owner, 5n).send().wait({ debug: true }); - const { visibleNotes } = receipt.debugInfo!; - expect(visibleNotes.length).toEqual(1); - note = await processExtendedNote(visibleNotes![0]); + const { visibleIncomingNotes } = receipt.debugInfo!; + expect(visibleIncomingNotes.length).toEqual(1); + note = await processExtendedNote(visibleIncomingNotes![0]); } // 3) Test the note was included diff --git a/yarn-project/end-to-end/src/e2e_fees/failures.test.ts b/yarn-project/end-to-end/src/e2e_fees/failures.test.ts index 54b3c7af11e..160c49e6d2c 100644 --- a/yarn-project/end-to-end/src/e2e_fees/failures.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/failures.test.ts @@ -134,7 +134,7 @@ describe('e2e_fees failures', () => { }, }) .wait(), - ).rejects.toThrow(/Message not authorized by account 'is_valid == true'/); + ).rejects.toThrow(/unauthorized/); // so does the sequencer await expect( diff --git a/yarn-project/end-to-end/src/e2e_key_registry.test.ts b/yarn-project/end-to-end/src/e2e_key_registry.test.ts index 5a21e4d70bb..d667eef74e3 100644 --- a/yarn-project/end-to-end/src/e2e_key_registry.test.ts +++ b/yarn-project/end-to-end/src/e2e_key_registry.test.ts @@ -74,9 +74,8 @@ describe('Key Registry', () => { keyRegistry .withWallet(wallets[0]) .methods.rotate_npk_m(wallets[1].getAddress(), Point.random(), Fr.ZERO) - .send() - .wait(), - ).rejects.toThrow('Assertion failed: Message not authorized by account'); + .simulate(), + ).rejects.toThrow(/unauthorized/); }); it('fresh key lib fails for non-existent account', async () => { diff --git a/yarn-project/end-to-end/src/e2e_key_rotation.test.ts b/yarn-project/end-to-end/src/e2e_key_rotation.test.ts index 554465fb5be..a6cbf6ad3e7 100644 --- a/yarn-project/end-to-end/src/e2e_key_rotation.test.ts +++ b/yarn-project/end-to-end/src/e2e_key_rotation.test.ts @@ -206,8 +206,8 @@ describe('e2e_key_rotation', () => { // 5. Now we check that a correct nullifier keys were used in both transfers { await awaitUserSynchronized(walletB, walletB.getAddress()); - const transfer1Notes = await walletB.getNotes({ txHash: txHashTransfer1 }); - const transfer2Notes = await walletB.getNotes({ txHash: txHashTransfer2 }); + const transfer1Notes = await walletB.getIncomingNotes({ txHash: txHashTransfer1 }); + const transfer2Notes = await walletB.getIncomingNotes({ txHash: txHashTransfer2 }); expect(transfer1Notes.length).toBe(1); expect(transfer2Notes.length).toBe(1); // Second field in the token note is the npk_m_hash diff --git a/yarn-project/end-to-end/src/e2e_note_getter.test.ts b/yarn-project/end-to-end/src/e2e_note_getter.test.ts index c26ecffe30d..be87db5bd48 100644 --- a/yarn-project/end-to-end/src/e2e_note_getter.test.ts +++ b/yarn-project/end-to-end/src/e2e_note_getter.test.ts @@ -3,18 +3,18 @@ import { DocsExampleContract, TestContract } from '@aztec/noir-contracts.js'; import { setup } from './fixtures/utils.js'; -interface NoirOption { - _is_some: boolean; - _value: T; +interface NoirBoundedVec { + storage: T[]; + len: bigint; +} + +function boundedVecToArray(boundedVec: NoirBoundedVec): T[] { + return boundedVec.storage.slice(0, Number(boundedVec.len)); } const sortFunc = (a: any, b: any) => a.points > b.points ? 1 : a.points < b.points ? -1 : a.randomness > b.randomness ? 1 : -1; -function unwrapOptions(options: NoirOption[]): T[] { - return options.filter((option: any) => option._is_some).map((option: any) => option._value); -} - describe('e2e_note_getter', () => { let wallet: Wallet; let teardown: () => Promise; @@ -60,7 +60,7 @@ describe('e2e_note_getter', () => { ]); expect( - unwrapOptions(returnEq) + boundedVecToArray(returnEq) .map(({ points, randomness }: any) => ({ points, randomness })) .sort(sortFunc), ).toStrictEqual( @@ -71,7 +71,7 @@ describe('e2e_note_getter', () => { ); expect( - unwrapOptions(returnNeq) + boundedVecToArray(returnNeq) .map(({ points, randomness }: any) => ({ points, randomness })) .sort(sortFunc), ).toStrictEqual( @@ -89,7 +89,7 @@ describe('e2e_note_getter', () => { ); expect( - unwrapOptions(returnLt) + boundedVecToArray(returnLt) .map(({ points, randomness }: any) => ({ points, randomness })) .sort(sortFunc), ).toStrictEqual( @@ -103,7 +103,7 @@ describe('e2e_note_getter', () => { ); expect( - unwrapOptions(returnGt) + boundedVecToArray(returnGt) .map(({ points, randomness }: any) => ({ points, randomness })) .sort(sortFunc), ).toStrictEqual( @@ -116,7 +116,7 @@ describe('e2e_note_getter', () => { ); expect( - unwrapOptions(returnLte) + boundedVecToArray(returnLte) .map(({ points, randomness }: any) => ({ points, randomness })) .sort(sortFunc), ).toStrictEqual( @@ -132,7 +132,7 @@ describe('e2e_note_getter', () => { ); expect( - unwrapOptions(returnGte) + boundedVecToArray(returnGte) .map(({ points, randomness }: any) => ({ points, randomness })) .sort(sortFunc), ).toStrictEqual( @@ -179,7 +179,7 @@ describe('e2e_note_getter', () => { async function assertNoReturnValue(storageSlot: number, activeOrNullified: boolean) { await expect(contract.methods.call_view_notes(storageSlot, activeOrNullified).simulate()).rejects.toThrow( - 'is_some', + 'index < self.len', // from BoundedVec::get ); await expect(contract.methods.call_get_notes(storageSlot, activeOrNullified).prove()).rejects.toThrow( `Assertion failed: Cannot return zero notes`, diff --git a/yarn-project/end-to-end/src/e2e_ordering.test.ts b/yarn-project/end-to-end/src/e2e_ordering.test.ts index 99aaa3d190b..949f64d8481 100644 --- a/yarn-project/end-to-end/src/e2e_ordering.test.ts +++ b/yarn-project/end-to-end/src/e2e_ordering.test.ts @@ -92,42 +92,34 @@ describe('e2e_ordering', () => { const expectedOrders = { set_value_twice_with_nested_first: [nestedValue, directValue] as bigint[], // eslint-disable-line camelcase set_value_twice_with_nested_last: [directValue, nestedValue] as bigint[], // eslint-disable-line camelcase - // TODO(6052) - // set_value_with_two_nested_calls: [nestedValue, directValue, directValue, nestedValue, directValue] as bigint[], // eslint-disable-line camelcase + set_value_with_two_nested_calls: [nestedValue, directValue, directValue, nestedValue, directValue] as bigint[], // eslint-disable-line camelcase } as const; - // TODO(6052): Once resolved, add 'set_value_with_nested_calls' - it.each(['set_value_twice_with_nested_first', 'set_value_twice_with_nested_last'] as const)( - 'orders public state updates in %s (and ensures final state value is correct)', - async method => { - const expectedOrder = expectedOrders[method]; + it.each([ + 'set_value_twice_with_nested_first', + 'set_value_twice_with_nested_last', + 'set_value_with_two_nested_calls', + ] as const)('orders public state updates in %s (and ensures final state value is correct)', async method => { + const expectedOrder = expectedOrders[method]; - await child.methods[method]().send().wait(); + await child.methods[method]().send().wait(); - const value = await pxe.getPublicStorageAt(child.address, new Fr(1)); - expect(value.value).toBe(expectedOrder[expectedOrder.length - 1]); // final state should match last value set - }, - ); + const value = await pxe.getPublicStorageAt(child.address, new Fr(1)); + expect(value.value).toBe(expectedOrder[expectedOrder.length - 1]); // final state should match last value set + }); - // TODO(#838): Public kernel outputs logs in wrong order! - // Full explanation: - // Emitting logs twice (first in a nested call, then directly) leads - // to a misordering of them by the public kernel because it sees them - // in reverse order. More info in this thread: https://discourse.aztec.network/t/identifying-the-ordering-of-state-access-across-contract-calls/382/12#transition-counters-for-private-calls-2 - // The below only works due to a hack which sorts the logs in ts - // See tail_phase_manager.ts - // TODO(6052): Once resolved, add 'set_value_with_two_nested_calls' - it.each(['set_value_twice_with_nested_first', 'set_value_twice_with_nested_last'] as const)( - 'orders unencrypted logs in %s', - async method => { - const expectedOrder = expectedOrders[method]; + it.each([ + 'set_value_twice_with_nested_first', + 'set_value_twice_with_nested_last', + 'set_value_with_two_nested_calls', + ] as const)('orders unencrypted logs in %s', async method => { + const expectedOrder = expectedOrders[method]; - await child.methods[method]().send().wait(); + await child.methods[method]().send().wait(); - // Logs are emitted in the expected order - await expectLogsFromLastBlockToBe(expectedOrder); - }, - ); + // Logs are emitted in the expected order + await expectLogsFromLastBlockToBe(expectedOrder); + }); }); }); }); diff --git a/yarn-project/end-to-end/src/flakey_e2e_p2p_network.test.ts b/yarn-project/end-to-end/src/e2e_p2p_network.test.ts similarity index 52% rename from yarn-project/end-to-end/src/flakey_e2e_p2p_network.test.ts rename to yarn-project/end-to-end/src/e2e_p2p_network.test.ts index 84173febc0d..42a5f26cb8b 100644 --- a/yarn-project/end-to-end/src/flakey_e2e_p2p_network.test.ts +++ b/yarn-project/end-to-end/src/e2e_p2p_network.test.ts @@ -8,10 +8,13 @@ import { GrumpkinScalar, type SentTx, TxStatus, + createDebugLogger, + sleep, } from '@aztec/aztec.js'; import { type BootNodeConfig, BootstrapNode, createLibP2PPeerId } from '@aztec/p2p'; import { type PXEService, createPXEService, getPXEServiceConfig as getRpcConfig } from '@aztec/pxe'; +import fs from 'fs'; import { mnemonicToAccount } from 'viem/accounts'; import { MNEMONIC } from './fixtures/fixtures.js'; @@ -30,21 +33,36 @@ interface NodeContext { account: AztecAddress; } +const PEER_ID_PRIVATE_KEYS = [ + '0802122002f651fd8653925529e3baccb8489b3af4d7d9db440cbf5df4a63ff04ea69683', + '08021220c3bd886df5fe5b33376096ad0dab3d2dc86ed2a361d5fde70f24d979dc73da41', + '080212206b6567ac759db5434e79495ec7458e5e93fe479a5b80713446e0bce5439a5655', + '08021220366453668099bdacdf08fab476ee1fced6bf00ddc1223d6c2ee626e7236fb526', +]; + describe('e2e_p2p_network', () => { let config: AztecNodeConfig; let logger: DebugLogger; let teardown: () => Promise; + let bootstrapNode: BootstrapNode; + let bootstrapNodeEnr: string; beforeEach(async () => { - ({ teardown, config, logger } = await setup(1)); + ({ teardown, config, logger } = await setup(0)); + bootstrapNode = await createBootstrapNode(); + bootstrapNodeEnr = bootstrapNode.getENR().encodeTxt(); }); afterEach(() => teardown()); + afterAll(() => { + for (let i = 0; i < NUM_NODES; i++) { + fs.rmSync(`./data-${i}`, { recursive: true, force: true }); + } + }); + it('should rollup txs from all peers', async () => { // create the bootstrap node for the network - const bootstrapNode = await createBootstrapNode(); - const bootstrapNodeEnr = bootstrapNode.getENR(); if (!bootstrapNodeEnr) { throw new Error('Bootstrap node ENR is not available'); } @@ -53,14 +71,29 @@ describe('e2e_p2p_network', () => { // should be set so that the only way for rollups to be built // is if the txs are successfully gossiped around the nodes. const contexts: NodeContext[] = []; + const nodes: AztecNodeService[] = []; for (let i = 0; i < NUM_NODES; i++) { - const node = await createNode(i + 1 + BOOT_NODE_UDP_PORT, bootstrapNodeEnr?.encodeTxt(), i); + const node = await createNode(i + 1 + BOOT_NODE_UDP_PORT, bootstrapNodeEnr, i); + nodes.push(node); + } + + // wait a bit for peers to discover each other + await sleep(2000); + + for (const node of nodes) { const context = await createPXEServiceAndSubmitTransactions(node, NUM_TXS_PER_NODE); contexts.push(context); } // now ensure that all txs were successfully mined - await Promise.all(contexts.flatMap(context => context.txs.map(tx => tx.wait()))); + await Promise.all( + contexts.flatMap((context, i) => + context.txs.map(async (tx, j) => { + logger.info(`Waiting for tx ${i}-${j}: ${await tx.getTxHash()} to be mined`); + return tx.wait(); + }), + ), + ); // shutdown all nodes. for (const context of contexts) { @@ -70,6 +103,61 @@ describe('e2e_p2p_network', () => { await bootstrapNode.stop(); }); + it('should re-discover stored peers without bootstrap node', async () => { + const contexts: NodeContext[] = []; + const nodes: AztecNodeService[] = []; + for (let i = 0; i < NUM_NODES; i++) { + const node = await createNode(i + 1 + BOOT_NODE_UDP_PORT, bootstrapNodeEnr, i, `./data-${i}`); + nodes.push(node); + } + // wait a bit for peers to discover each other + await sleep(3000); + + // stop bootstrap node + await bootstrapNode.stop(); + + // create new nodes from datadir + const newNodes: AztecNodeService[] = []; + + // stop all nodes + for (let i = 0; i < NUM_NODES; i++) { + const node = nodes[i]; + await node.stop(); + logger.info(`Node ${i} stopped`); + await sleep(1200); + const newNode = await createNode(i + 1 + BOOT_NODE_UDP_PORT, undefined, i, `./data-${i}`); + logger.info(`Node ${i} restarted`); + newNodes.push(newNode); + // const context = await createPXEServiceAndSubmitTransactions(node, NUM_TXS_PER_NODE); + // contexts.push(context); + } + + // wait a bit for peers to discover each other + await sleep(2000); + + for (const node of newNodes) { + const context = await createPXEServiceAndSubmitTransactions(node, NUM_TXS_PER_NODE); + contexts.push(context); + } + + // now ensure that all txs were successfully mined + await Promise.all( + contexts.flatMap((context, i) => + context.txs.map(async (tx, j) => { + logger.info(`Waiting for tx ${i}-${j}: ${await tx.getTxHash()} to be mined`); + return tx.wait(); + }), + ), + ); + + // shutdown all nodes. + // for (const context of contexts) { + for (const context of contexts) { + await context.node.stop(); + await context.pxeService.stop(); + } + }); + const createBootstrapNode = async () => { const peerId = await createLibP2PPeerId(); const bootstrapNode = new BootstrapNode(); @@ -87,7 +175,12 @@ describe('e2e_p2p_network', () => { }; // creates a P2P enabled instance of Aztec Node Service - const createNode = async (tcpListenPort: number, bootstrapNode: string, publisherAddressIndex: number) => { + const createNode = async ( + tcpListenPort: number, + bootstrapNode: string | undefined, + publisherAddressIndex: number, + dataDirectory?: string, + ) => { // We use different L1 publisher accounts in order to avoid duplicate tx nonces. We start from // publisherAddressIndex + 1 because index 0 was already used during test environment setup. const hdAccount = mnemonicToAccount(MNEMONIC, { addressIndex: publisherAddressIndex + 1 }); @@ -96,38 +189,21 @@ describe('e2e_p2p_network', () => { const newConfig: AztecNodeConfig = { ...config, + peerIdPrivateKey: PEER_ID_PRIVATE_KEYS[publisherAddressIndex], udpListenAddress: `0.0.0.0:${tcpListenPort}`, tcpListenAddress: `0.0.0.0:${tcpListenPort}`, tcpAnnounceAddress: `127.0.0.1:${tcpListenPort}`, udpAnnounceAddress: `127.0.0.1:${tcpListenPort}`, - bootstrapNodes: [bootstrapNode], minTxsPerBlock: NUM_TXS_PER_BLOCK, maxTxsPerBlock: NUM_TXS_PER_BLOCK, p2pEnabled: true, p2pBlockCheckIntervalMS: 1000, p2pL2QueueSize: 1, transactionProtocol: '', + dataDirectory, + bootstrapNodes: bootstrapNode ? [bootstrapNode] : [], }; - return await AztecNodeService.createAndSync(newConfig); - }; - - // submits a set of transactions to the provided Private eXecution Environment (PXE) - const submitTxsTo = async (pxe: PXEService, account: AztecAddress, numTxs: number) => { - const txs: SentTx[] = []; - for (let i = 0; i < numTxs; i++) { - const tx = getSchnorrAccount(pxe, Fr.random(), GrumpkinScalar.random(), Fr.random()).deploy(); - logger.info(`Tx sent with hash ${await tx.getTxHash()}`); - const receipt = await tx.getReceipt(); - expect(receipt).toEqual( - expect.objectContaining({ - status: TxStatus.PENDING, - error: '', - }), - ); - logger.info(`Receipt received for ${await tx.getTxHash()}`); - txs.push(tx); - } - return txs; + return await AztecNodeService.createAndSync(newConfig, createDebugLogger(`aztec:node-${tcpListenPort}`)); }; // creates an instance of the PXE and submit a given number of transactions to it. @@ -142,7 +218,7 @@ describe('e2e_p2p_network', () => { const completeAddress = CompleteAddress.fromSecretKeyAndPartialAddress(secretKey, Fr.random()); await pxeService.registerAccount(secretKey, completeAddress.partialAddress); - const txs = await submitTxsTo(pxeService, completeAddress.address, numTxs); + const txs = await submitTxsTo(pxeService, numTxs); return { txs, account: completeAddress.address, @@ -150,4 +226,36 @@ describe('e2e_p2p_network', () => { node, }; }; + + // submits a set of transactions to the provided Private eXecution Environment (PXE) + const submitTxsTo = async (pxe: PXEService, numTxs: number) => { + const txs: SentTx[] = []; + for (let i = 0; i < numTxs; i++) { + // const tx = getSchnorrAccount(pxe, Fr.random(), GrumpkinScalar.random(), Fr.random()).deploy(); + const accountManager = getSchnorrAccount(pxe, Fr.random(), GrumpkinScalar.random(), Fr.random()); + const deployMethod = await accountManager.getDeployMethod(); + await deployMethod.create({ + contractAddressSalt: accountManager.salt, + skipClassRegistration: true, + skipPublicDeployment: true, + universalDeploy: true, + }); + await deployMethod.prove({}); + const tx = deployMethod.send(); + + const txHash = await tx.getTxHash(); + + logger.info(`Tx sent with hash ${txHash}`); + const receipt = await tx.getReceipt(); + expect(receipt).toEqual( + expect.objectContaining({ + status: TxStatus.PENDING, + error: '', + }), + ); + logger.info(`Receipt received for ${txHash}`); + txs.push(tx); + } + return txs; + }; }); diff --git a/yarn-project/end-to-end/src/e2e_prover/e2e_avm_proving.test.ts b/yarn-project/end-to-end/src/e2e_prover/e2e_avm_proving.test.ts deleted file mode 100644 index 6af26eb9b85..00000000000 --- a/yarn-project/end-to-end/src/e2e_prover/e2e_avm_proving.test.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { FullProverTestAvm } from './e2e_prover_test_avm.js'; - -const TIMEOUT = 1_800_000; - -// This makes AVM proving throw if there's a failure. -process.env.AVM_PROVING_STRICT = '1'; - -describe('full_prover/avm', () => { - const t = new FullProverTestAvm('full_prover/avm'); - let { provenAsset: avmContract, logger } = t; - - beforeAll(async () => { - await t.applyBaseSnapshots(); - await t.setup(); - await t.deployVerifier(); - ({ provenAsset: avmContract, logger } = t); - }); - - afterAll(async () => { - await t.teardown(); - }); - - it( - 'proves simple contract call', - async () => { - logger.info( - `Starting test using function: ${avmContract.address}:${avmContract.methods.add_args_return.selector}`, - ); - await avmContract.methods.add_args_return(3, 5).send().wait(); - }, - TIMEOUT, - ); -}); diff --git a/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test_avm.ts b/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test_avm.ts deleted file mode 100644 index cc7e1372509..00000000000 --- a/yarn-project/end-to-end/src/e2e_prover/e2e_prover_test_avm.ts +++ /dev/null @@ -1,242 +0,0 @@ -import { SchnorrAccountContractArtifact, getSchnorrAccount } from '@aztec/accounts/schnorr'; -import { - type AccountWalletWithSecretKey, - type AztecNode, - type CompleteAddress, - type DebugLogger, - type Fq, - type Fr, - type PXE, - createDebugLogger, - deployL1Contract, -} from '@aztec/aztec.js'; -import { BBCircuitVerifier } from '@aztec/bb-prover'; -import { RollupAbi } from '@aztec/l1-artifacts'; -import { AvmTestContract } from '@aztec/noir-contracts.js'; -import { type PXEService } from '@aztec/pxe'; - -// @ts-expect-error solc-js doesn't publish its types https://github.com/ethereum/solc-js/issues/689 -import solc from 'solc'; -import { getContract } from 'viem'; - -import { waitRegisteredAccountSynced } from '../benchmarks/utils.js'; -import { getACVMConfig } from '../fixtures/get_acvm_config.js'; -import { getBBConfig } from '../fixtures/get_bb_config.js'; -import { - type ISnapshotManager, - type SubsystemsContext, - addAccounts, - createSnapshotManager, - publicDeployAccounts, -} from '../fixtures/snapshot_manager.js'; -import { setupPXEService } from '../fixtures/utils.js'; - -const { E2E_DATA_PATH: dataPath } = process.env; - -const SALT = 1; - -type ProvenSetup = { - pxe: PXE; - teardown: () => Promise; -}; - -/** - * Simpler version of FullProverTest. - */ -export class FullProverTestAvm { - private snapshotManager: ISnapshotManager; - logger: DebugLogger; - keys: Array<[Fr, Fq]> = []; - wallets: AccountWalletWithSecretKey[] = []; - accounts: CompleteAddress[] = []; - fakeProofsAsset!: AvmTestContract; - aztecNode!: AztecNode; - pxe!: PXEService; - private provenComponents: ProvenSetup[] = []; - private bbConfigCleanup?: () => Promise; - private acvmConfigCleanup?: () => Promise; - circuitProofVerifier?: BBCircuitVerifier; - provenAsset!: AvmTestContract; - private context!: SubsystemsContext; - - constructor(testName: string) { - this.logger = createDebugLogger(`aztec:full_prover_test:${testName}`); - this.snapshotManager = createSnapshotManager(`full_prover_integration/${testName}`, dataPath); - } - - /** - * Adds two state shifts to snapshot manager. - * 1. Add 2 accounts. - * 2. Publicly deploy accounts, deploy contract - */ - async applyBaseSnapshots() { - await this.snapshotManager.snapshot('2_accounts', addAccounts(2, this.logger), async ({ accountKeys }, { pxe }) => { - this.keys = accountKeys; - const accountManagers = accountKeys.map(ak => getSchnorrAccount(pxe, ak[0], ak[1], SALT)); - this.wallets = await Promise.all(accountManagers.map(a => a.getWallet())); - this.accounts = await pxe.getRegisteredAccounts(); - this.wallets.forEach((w, i) => this.logger.verbose(`Wallet ${i} address: ${w.getAddress()}`)); - }); - - await this.snapshotManager.snapshot( - 'client_prover_integration', - async () => { - // Create the token contract state. - // Move this account thing to addAccounts above? - this.logger.verbose(`Public deploy accounts...`); - await publicDeployAccounts(this.wallets[0], this.accounts.slice(0, 2)); - - this.logger.verbose(`Deploying AvmTestContract...`); - const asset = await AvmTestContract.deploy(this.wallets[0]).send().deployed(); - this.logger.verbose(`AvmTestContract deployed to ${asset.address}`); - - return { contractAddress: asset.address }; - }, - async ({ contractAddress }) => { - // Restore the token contract state. - this.fakeProofsAsset = await AvmTestContract.at(contractAddress, this.wallets[0]); - this.logger.verbose(`AvmTestContract address: ${this.fakeProofsAsset.address}`); - }, - ); - } - - async setup() { - this.context = await this.snapshotManager.setup(); - ({ pxe: this.pxe, aztecNode: this.aztecNode } = this.context); - - // Configure a full prover PXE - const [acvmConfig, bbConfig] = await Promise.all([getACVMConfig(this.logger), getBBConfig(this.logger)]); - if (!acvmConfig || !bbConfig) { - throw new Error('Missing ACVM or BB config'); - } - - this.acvmConfigCleanup = acvmConfig.cleanup; - this.bbConfigCleanup = bbConfig.cleanup; - - if (!bbConfig?.bbWorkingDirectory || !bbConfig?.bbBinaryPath) { - throw new Error(`Test must be run with BB native configuration`); - } - - this.circuitProofVerifier = await BBCircuitVerifier.new(bbConfig); - - this.logger.debug(`Configuring the node for real proofs...`); - await this.aztecNode.setConfig({ - proverAgentConcurrency: 1, - realProofs: true, - minTxsPerBlock: 1, - }); - - this.logger.debug(`Main setup completed, initializing full prover PXE and Node...`); - - for (let i = 0; i < 2; i++) { - const result = await setupPXEService( - this.aztecNode, - { - proverEnabled: true, - bbBinaryPath: bbConfig?.bbBinaryPath, - bbWorkingDirectory: bbConfig?.bbWorkingDirectory, - }, - undefined, - true, - ); - this.logger.debug(`Contract address ${this.fakeProofsAsset.address}`); - await result.pxe.registerContract(this.fakeProofsAsset); - - for (let i = 0; i < 2; i++) { - await waitRegisteredAccountSynced( - result.pxe, - this.keys[i][0], - this.wallets[i].getCompleteAddress().partialAddress, - ); - - await waitRegisteredAccountSynced( - this.pxe, - this.keys[i][0], - this.wallets[i].getCompleteAddress().partialAddress, - ); - } - - const account = getSchnorrAccount(result.pxe, this.keys[0][0], this.keys[0][1], SALT); - - await result.pxe.registerContract({ - instance: account.getInstance(), - artifact: SchnorrAccountContractArtifact, - }); - - const provenWallet = await account.getWallet(); - const asset = await AvmTestContract.at(this.fakeProofsAsset.address, provenWallet); - this.provenComponents.push({ - pxe: result.pxe, - teardown: result.teardown, - }); - this.provenAsset = asset; - } - - this.logger.debug(`Full prover PXE started!!`); - return this; - } - - async teardown() { - await this.snapshotManager.teardown(); - - // Cleanup related to the full prover PXEs - for (let i = 0; i < this.provenComponents.length; i++) { - await this.provenComponents[i].teardown(); - } - - await this.bbConfigCleanup?.(); - await this.acvmConfigCleanup?.(); - } - - async deployVerifier() { - if (!this.circuitProofVerifier) { - throw new Error('No verifier'); - } - - const { walletClient, publicClient, l1ContractAddresses } = this.context.deployL1ContractsValues; - - const contract = await this.circuitProofVerifier.generateSolidityContract( - 'RootRollupArtifact', - 'UltraVerifier.sol', - ); - - const input = { - language: 'Solidity', - sources: { - 'UltraVerifier.sol': { - content: contract, - }, - }, - settings: { - // we require the optimizer - optimizer: { - enabled: true, - runs: 200, - }, - outputSelection: { - '*': { - '*': ['evm.bytecode.object', 'abi'], - }, - }, - }, - }; - - const output = JSON.parse(solc.compile(JSON.stringify(input))); - - const abi = output.contracts['UltraVerifier.sol']['UltraVerifier'].abi; - const bytecode: string = output.contracts['UltraVerifier.sol']['UltraVerifier'].evm.bytecode.object; - - const verifierAddress = await deployL1Contract(walletClient, publicClient, abi, `0x${bytecode}`); - - this.logger.info(`Deployed Real verifier at ${verifierAddress}`); - - const rollup = getContract({ - abi: RollupAbi, - address: l1ContractAddresses.rollupAddress.toString(), - client: walletClient, - }); - - await rollup.write.setVerifier([verifierAddress.toString()]); - this.logger.info('Rollup only accepts valid proofs now'); - } -} diff --git a/yarn-project/end-to-end/src/e2e_prover/full.test.ts b/yarn-project/end-to-end/src/e2e_prover/full.test.ts index 1f38ec00c07..bbc1c8b7404 100644 --- a/yarn-project/end-to-end/src/e2e_prover/full.test.ts +++ b/yarn-project/end-to-end/src/e2e_prover/full.test.ts @@ -5,6 +5,11 @@ import { FullProverTest } from './e2e_prover_test.js'; const TIMEOUT = 1_800_000; +// This makes AVM proving throw if there's a failure. +process.env.AVM_PROVING_STRICT = '1'; +// Enable proving the full lookup tables (no truncation). +process.env.AVM_ENABLE_FULL_PROVING = '1'; + describe('full_prover', () => { const t = new FullProverTest('full_prover', 2); let { provenAssets, accounts, tokenSim, logger } = t; diff --git a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging/failure_cases.test.ts b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging/failure_cases.test.ts index a6b1b6e6ca5..7ec54101628 100644 --- a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging/failure_cases.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging/failure_cases.test.ts @@ -35,7 +35,7 @@ describe('e2e_public_cross_chain_messaging failures', () => { .withWallet(user1Wallet) .methods.exit_to_l1_public(ethAccount, withdrawAmount, EthAddress.ZERO, nonce) .prove(), - ).rejects.toThrow('Assertion failed: Message not authorized by account'); + ).rejects.toThrow(/unauthorized/); }, 60_000); it("can't claim funds privately which were intended for public deposit from the token portal", async () => { diff --git a/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts index bfe3406329c..f736b47a64c 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/burn.test.ts @@ -47,9 +47,9 @@ describe('e2e_token_contract burn', () => { tokenSim.burnPublic(accounts[0].address, amount); - // Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer. - const txReplay = asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce).send(); - await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); + await expect( + asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce).simulate(), + ).rejects.toThrow(/unauthorized/); }); describe('failure cases', () => { @@ -78,7 +78,7 @@ describe('e2e_token_contract burn', () => { const nonce = Fr.random(); await expect( asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce).simulate(), - ).rejects.toThrow('Assertion failed: Message not authorized by account'); + ).rejects.toThrow(/unauthorized/); }); it('burn more than balance on behalf of other', async () => { @@ -106,7 +106,7 @@ describe('e2e_token_contract burn', () => { await expect( asset.withWallet(wallets[1]).methods.burn_public(accounts[0].address, amount, nonce).simulate(), - ).rejects.toThrow('Assertion failed: Message not authorized by account'); + ).rejects.toThrow(/unauthorized/); }); }); }); diff --git a/yarn-project/end-to-end/src/e2e_token_contract/minting.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/minting.test.ts index 7a833d6a157..5fccd7a3bfb 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/minting.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/minting.test.ts @@ -89,9 +89,9 @@ describe('e2e_token_contract minting', () => { // docs:end:debug tokenSim.redeemShield(accounts[0].address, amount); // 1 note should be created containing `amount` of tokens - const { visibleNotes } = receiptClaim.debugInfo!; - expect(visibleNotes.length).toBe(1); - expect(visibleNotes[0].note.items[0].toBigInt()).toBe(amount); + const { visibleIncomingNotes } = receiptClaim.debugInfo!; + expect(visibleIncomingNotes.length).toBe(1); + expect(visibleIncomingNotes[0].note.items[0].toBigInt()).toBe(amount); }); }); diff --git a/yarn-project/end-to-end/src/e2e_token_contract/shielding.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/shielding.test.ts index 93ab4e44870..d7a576e09b5 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/shielding.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/shielding.test.ts @@ -1,6 +1,6 @@ import { Fr, computeSecretHash } from '@aztec/aztec.js'; -import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/fixtures.js'; +import { U128_UNDERFLOW_ERROR } from '../fixtures/fixtures.js'; import { TokenContractTest } from './token_contract_test.js'; describe('e2e_token_contract shield + redeem shield', () => { @@ -59,8 +59,9 @@ describe('e2e_token_contract shield + redeem shield', () => { await tokenSim.check(); // Check that replaying the shield should fail! - const txReplay = asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce).send(); - await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); + await expect( + asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce).simulate(), + ).rejects.toThrow(/unauthorized/); // Redeem it await t.addPendingShieldNoteToPXE(0, amount, secretHash, receipt.txHash); @@ -113,7 +114,7 @@ describe('e2e_token_contract shield + redeem shield', () => { const action = asset.withWallet(wallets[2]).methods.shield(accounts[0].address, amount, secretHash, nonce); await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); - await expect(action.simulate()).rejects.toThrow('Assertion failed: Message not authorized by account'); + await expect(action.simulate()).rejects.toThrow(/unauthorized/); }); it('on behalf of other (without approval)', async () => { @@ -124,7 +125,7 @@ describe('e2e_token_contract shield + redeem shield', () => { await expect( asset.withWallet(wallets[1]).methods.shield(accounts[0].address, amount, secretHash, nonce).simulate(), - ).rejects.toThrow(`Assertion failed: Message not authorized by account`); + ).rejects.toThrow(/unauthorized/); }); }); }); diff --git a/yarn-project/end-to-end/src/e2e_token_contract/transfer_public.test.ts b/yarn-project/end-to-end/src/e2e_token_contract/transfer_public.test.ts index cb352c57df2..c828a6bdb15 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract/transfer_public.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract/transfer_public.test.ts @@ -1,6 +1,6 @@ import { Fr, computeAuthWitMessageHash } from '@aztec/aztec.js'; -import { DUPLICATE_NULLIFIER_ERROR, U128_UNDERFLOW_ERROR } from '../fixtures/fixtures.js'; +import { U128_UNDERFLOW_ERROR } from '../fixtures/fixtures.js'; import { TokenContractTest } from './token_contract_test.js'; describe('e2e_token_contract transfer public', () => { @@ -60,12 +60,13 @@ describe('e2e_token_contract transfer public', () => { tokenSim.transferPublic(accounts[0].address, accounts[1].address, amount); - // Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer. - const txReplay = asset - .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) - .send(); - await expect(txReplay.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); + // Check that the message hash is no longer valid. + await expect( + asset + .withWallet(wallets[1]) + .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) + .simulate(), + ).rejects.toThrow(/unauthorized/); }); describe('failure cases', () => { @@ -96,7 +97,7 @@ describe('e2e_token_contract transfer public', () => { .withWallet(wallets[1]) .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) .simulate(), - ).rejects.toThrow('Assertion failed: Message not authorized by account'); + ).rejects.toThrow(/unauthorized/); }); it('transfer more than balance on behalf of other', async () => { @@ -149,7 +150,7 @@ describe('e2e_token_contract transfer public', () => { await wallets[0].setPublicAuthWit({ caller: accounts[0].address, action }, true).send().wait(); // Perform the transfer - await expect(action.simulate()).rejects.toThrow('Assertion failed: Message not authorized by account'); + await expect(action.simulate()).rejects.toThrow(/unauthorized/); expect(await asset.methods.balance_of_public(accounts[0].address).simulate()).toEqual(balance0); expect(await asset.methods.balance_of_public(accounts[1].address).simulate()).toEqual(balance1); @@ -169,7 +170,7 @@ describe('e2e_token_contract transfer public', () => { await wallets[0].setPublicAuthWit({ caller: accounts[0].address, action }, true).send().wait(); // Perform the transfer - await expect(action.simulate()).rejects.toThrow('Assertion failed: Message not authorized by account'); + await expect(action.simulate()).rejects.toThrow(/unauthorized/); expect(await asset.methods.balance_of_public(accounts[0].address).simulate()).toEqual(balance0); expect(await asset.methods.balance_of_public(accounts[1].address).simulate()).toEqual(balance1); @@ -187,14 +188,14 @@ describe('e2e_token_contract transfer public', () => { await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, true).send().wait(); - await wallets[0].cancelAuthWit({ caller: accounts[1].address, action }).send().wait(); + await wallets[0].cancelPublicAuthWit({ caller: accounts[1].address, action }).send().wait(); - // Check that the authwit is no longer valid. Need to try to send since nullifiers are handled by sequencer. - const txCancelledAuthwit = asset - .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) - .send(); - await expect(txCancelledAuthwit.wait()).rejects.toThrowError(DUPLICATE_NULLIFIER_ERROR); + await expect( + asset + .withWallet(wallets[1]) + .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) + .simulate(), + ).rejects.toThrowError(/unauthorized/); }); it('transfer on behalf of other, cancelled authwit, flow 2', async () => { @@ -211,12 +212,12 @@ describe('e2e_token_contract transfer public', () => { await wallets[0].setPublicAuthWit({ caller: accounts[1].address, action }, false).send().wait(); - // Check that the authwit is no longer valid. Need to try to send since nullifiers are handled by sequencer. - const txCancelledAuthwit = asset - .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) - .send(); - await expect(txCancelledAuthwit.wait()).rejects.toThrowError(DUPLICATE_NULLIFIER_ERROR); + await expect( + asset + .withWallet(wallets[1]) + .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) + .simulate(), + ).rejects.toThrowError(/unauthorized/); }); it('transfer on behalf of other, cancelled authwit, flow 3', async () => { @@ -237,27 +238,25 @@ describe('e2e_token_contract transfer public', () => { await wallets[0].setPublicAuthWit(messageHash, true).send().wait(); - await wallets[0].cancelAuthWit(messageHash).send().wait(); + await wallets[0].cancelPublicAuthWit(messageHash).send().wait(); - // Check that the message hash is no longer valid. Need to try to send since nullifiers are handled by sequencer. - const txCancelledAuthwit = asset - .withWallet(wallets[1]) - .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) - .send(); - await expect(txCancelledAuthwit.wait()).rejects.toThrow(DUPLICATE_NULLIFIER_ERROR); + await expect( + asset + .withWallet(wallets[1]) + .methods.transfer_public(accounts[0].address, accounts[1].address, amount, nonce) + .simulate(), + ).rejects.toThrow(/unauthorized/); }); it('transfer on behalf of other, invalid spend_public_authwit on "from"', async () => { const nonce = Fr.random(); - // Should fail as the returned value from the badAccount is malformed - const txCancelledAuthwit = asset - .withWallet(wallets[1]) - .methods.transfer_public(badAccount.address, accounts[1].address, 0, nonce) - .send(); - await expect(txCancelledAuthwit.wait()).rejects.toThrow( - "Assertion failed: Message not authorized by account 'result == IS_VALID_SELECTOR'", - ); + await expect( + asset + .withWallet(wallets[1]) + .methods.transfer_public(badAccount.address, accounts[1].address, 0, nonce) + .simulate(), + ).rejects.toThrow(/unauthorized/); }); it.skip('transfer into account to overflow', () => { diff --git a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts index 2c688623603..c897648c62c 100644 --- a/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts +++ b/yarn-project/end-to-end/src/fixtures/snapshot_manager.ts @@ -32,7 +32,7 @@ import { MNEMONIC } from './fixtures.js'; import { getACVMConfig } from './get_acvm_config.js'; import { getBBConfig } from './get_bb_config.js'; import { setupL1Contracts } from './setup_l1_contracts.js'; -import { deployCanonicalKeyRegistry } from './utils.js'; +import { deployCanonicalAuthRegistry, deployCanonicalKeyRegistry } from './utils.js'; export type SubsystemsContext = { anvil: Anvil; @@ -282,6 +282,10 @@ async function setupFromFresh(statePath: string | undefined, logger: Logger): Pr await deployCanonicalKeyRegistry( new SignerlessWallet(pxe, new DefaultMultiCallEntrypoint(aztecNodeConfig.chainId, aztecNodeConfig.version)), ); + logger.verbose('Deploying auth registry...'); + await deployCanonicalAuthRegistry( + new SignerlessWallet(pxe, new DefaultMultiCallEntrypoint(aztecNodeConfig.chainId, aztecNodeConfig.version)), + ); if (statePath) { writeFileSync(`${statePath}/aztec_node_config.json`, JSON.stringify(aztecNodeConfig)); diff --git a/yarn-project/end-to-end/src/fixtures/utils.ts b/yarn-project/end-to-end/src/fixtures/utils.ts index a2daa3f043e..07014915b30 100644 --- a/yarn-project/end-to-end/src/fixtures/utils.ts +++ b/yarn-project/end-to-end/src/fixtures/utils.ts @@ -30,6 +30,7 @@ import { deployInstance, registerContractClass } from '@aztec/aztec.js/deploymen import { DefaultMultiCallEntrypoint } from '@aztec/aztec.js/entrypoint'; import { type BBNativeProofCreator } from '@aztec/bb-prover'; import { + CANONICAL_AUTH_REGISTRY_ADDRESS, CANONICAL_KEY_REGISTRY_ADDRESS, GasSettings, MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS, @@ -54,8 +55,9 @@ import { RollupAbi, RollupBytecode, } from '@aztec/l1-artifacts'; -import { KeyRegistryContract } from '@aztec/noir-contracts.js'; +import { AuthRegistryContract, KeyRegistryContract } from '@aztec/noir-contracts.js'; import { GasTokenContract } from '@aztec/noir-contracts.js/GasToken'; +import { getCanonicalAuthRegistry } from '@aztec/protocol-contracts/auth-registry'; import { GasTokenAddress, getCanonicalGasToken } from '@aztec/protocol-contracts/gas-token'; import { getCanonicalKeyRegistry } from '@aztec/protocol-contracts/key-registry'; import { type ProverClient } from '@aztec/prover-client'; @@ -228,6 +230,9 @@ async function setupWithRemoteEnvironment( await deployCanonicalKeyRegistry( new SignerlessWallet(pxeClient, new DefaultMultiCallEntrypoint(chainId, protocolVersion)), ); + await deployCanonicalAuthRegistry( + new SignerlessWallet(pxeClient, new DefaultMultiCallEntrypoint(config.chainId, config.version)), + ); if (enableGas) { await deployCanonicalGasToken( @@ -377,6 +382,11 @@ export async function setup( new SignerlessWallet(pxe, new DefaultMultiCallEntrypoint(config.chainId, config.version)), ); + logger.verbose('Deploying auth registry...'); + await deployCanonicalAuthRegistry( + new SignerlessWallet(pxe, new DefaultMultiCallEntrypoint(config.chainId, config.version)), + ); + if (enableGas) { logger.verbose('Deploying gas token...'); await deployCanonicalGasToken( @@ -664,3 +674,36 @@ export async function deployCanonicalKeyRegistry(deployer: Wallet) { await expect(deployer.isContractClassPubliclyRegistered(canonicalKeyRegistry.contractClass.id)).resolves.toBe(true); await expect(deployer.getContractInstance(canonicalKeyRegistry.instance.address)).resolves.toBeDefined(); } + +export async function deployCanonicalAuthRegistry(deployer: Wallet) { + const canonicalAuthRegistry = getCanonicalAuthRegistry(); + + // We check to see if there exists a contract at the canonical Auth Registry address with the same contract class id as we expect. This means that + // the auth registry has already been deployed to the correct address. + if ( + (await deployer.getContractInstance(canonicalAuthRegistry.address))?.contractClassId.equals( + canonicalAuthRegistry.contractClass.id, + ) && + (await deployer.isContractClassPubliclyRegistered(canonicalAuthRegistry.contractClass.id)) + ) { + return; + } + + const authRegistry = await AuthRegistryContract.deploy(deployer) + .send({ contractAddressSalt: canonicalAuthRegistry.instance.salt, universalDeploy: true }) + .deployed(); + + if ( + !authRegistry.address.equals(canonicalAuthRegistry.address) || + !authRegistry.address.equals(AztecAddress.fromBigInt(CANONICAL_AUTH_REGISTRY_ADDRESS)) + ) { + throw new Error( + `Deployed Auth Registry address ${authRegistry.address} does not match expected address ${canonicalAuthRegistry.address}, or they both do not equal CANONICAL_AUTH_REGISTRY_ADDRESS`, + ); + } + + expect(computeContractAddressFromInstance(authRegistry.instance)).toEqual(authRegistry.address); + expect(getContractClassFromArtifact(authRegistry.artifact).id).toEqual(authRegistry.instance.contractClassId); + await expect(deployer.isContractClassPubliclyRegistered(canonicalAuthRegistry.contractClass.id)).resolves.toBe(true); + await expect(deployer.getContractInstance(canonicalAuthRegistry.instance.address)).resolves.toBeDefined(); +} diff --git a/yarn-project/end-to-end/src/flakey_e2e_inclusion_proofs_contract.test.ts b/yarn-project/end-to-end/src/flakey_e2e_inclusion_proofs_contract.test.ts index 0c0c0f9d489..5fb6a8e6113 100644 --- a/yarn-project/end-to-end/src/flakey_e2e_inclusion_proofs_contract.test.ts +++ b/yarn-project/end-to-end/src/flakey_e2e_inclusion_proofs_contract.test.ts @@ -1,6 +1,7 @@ import { type AccountWallet, AztecAddress, + type ExtendedNote, Fr, INITIAL_L2_BLOCK_NUM, type PXE, @@ -52,7 +53,7 @@ describe('e2e_inclusion_proofs_contract', () => { describe('proves note existence and its nullifier non-existence and nullifier non-existence failure case', () => { // Owner of a note let noteCreationBlockNumber: number; - let noteHashes, visibleNotes: any; + let noteHashes, visibleIncomingNotes: ExtendedNote[]; const value = 100n; let validNoteBlockNumber: any; @@ -61,13 +62,13 @@ describe('e2e_inclusion_proofs_contract', () => { const receipt = await contract.methods.create_note(owner, value).send().wait({ debug: true }); noteCreationBlockNumber = receipt.blockNumber!; - ({ noteHashes, visibleNotes } = receipt.debugInfo!); + ({ noteHashes, visibleIncomingNotes } = receipt.debugInfo!); }); it('should return the correct values for creating a note', () => { expect(noteHashes.length).toBe(1); - expect(visibleNotes.length).toBe(1); - const [receivedValue, receivedOwner, _randomness] = visibleNotes[0].note.items; + expect(visibleIncomingNotes.length).toBe(1); + const [receivedValue, receivedOwner, _randomness] = visibleIncomingNotes[0].note.items; expect(receivedValue.toBigInt()).toBe(value); expect(receivedOwner).toEqual(owner.toField()); }); @@ -144,7 +145,7 @@ describe('e2e_inclusion_proofs_contract', () => { }); }); - it('proves note validity (note commitment inclusion and nullifier non-inclusion)', async () => { + it('proves note validity (note hash inclusion and nullifier non-inclusion)', async () => { // Owner of a note const owner = wallets[0].getAddress(); let noteCreationBlockNumber: number; @@ -154,11 +155,11 @@ describe('e2e_inclusion_proofs_contract', () => { const receipt = await contract.methods.create_note(owner, value).send().wait({ debug: true }); noteCreationBlockNumber = receipt.blockNumber!; - const { noteHashes, visibleNotes } = receipt.debugInfo!; + const { noteHashes, visibleIncomingNotes } = receipt.debugInfo!; expect(noteHashes.length).toBe(1); - expect(visibleNotes.length).toBe(1); - const [receivedValue, receivedOwner, _randomness] = visibleNotes[0].note.items; + expect(visibleIncomingNotes.length).toBe(1); + const [receivedValue, receivedOwner, _randomness] = visibleIncomingNotes[0].note.items; expect(receivedValue.toBigInt()).toBe(value); expect(receivedOwner).toEqual(owner.toField()); } diff --git a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts index 8b9257d4a40..eca88b76dc1 100644 --- a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts +++ b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts @@ -179,7 +179,7 @@ describe('guides/dapp/testing', () => { it('checks private storage', async () => { // docs:start:private-storage - const notes = await pxe.getNotes({ + const notes = await pxe.getIncomingNotes({ owner: owner.getAddress(), contractAddress: token.address, storageSlot: ownerSlot, diff --git a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts index b56ed6e5ae5..f62fa9bc3c5 100644 --- a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts +++ b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts @@ -206,10 +206,6 @@ export const uniswapL1L2TestSuite = ( const wethL2BalanceBeforeSwap = await wethCrossChainHarness.getL2PrivateBalanceOf(ownerAddress); const daiL2BalanceBeforeSwap = await daiCrossChainHarness.getL2PrivateBalanceOf(ownerAddress); - // before swap - check nonce_for_burn_approval stored on uniswap - // (which is used by uniswap to approve the bridge to burn funds on its behalf to exit to L1) - const nonceForBurnApprovalBeforeSwap = await uniswapL2Contract.methods.nonce_for_burn_approval().simulate(); - // 3. Owner gives uniswap approval to unshield funds to self on its behalf logger.info('Approving uniswap to unshield funds to self on my behalf'); const nonceForWETHUnshieldApproval = new Fr(1n); @@ -289,9 +285,6 @@ export const uniswapL1L2TestSuite = ( await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge); // ensure that uniswap contract didn't eat the funds. await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n); - // check burn approval nonce incremented: - const nonceForBurnApprovalAfterSwap = await uniswapL2Contract.methods.nonce_for_burn_approval().simulate(); - expect(nonceForBurnApprovalAfterSwap).toBe(nonceForBurnApprovalBeforeSwap + 1n); // 5. Consume L2 to L1 message by calling uniswapPortal.swap_private() logger.info('Execute withdraw and swap on the uniswapPortal!'); @@ -442,10 +435,6 @@ export const uniswapL1L2TestSuite = ( ); await ownerWallet.setPublicAuthWit(transferMessageHash, true).send().wait(); - // before swap - check nonce_for_burn_approval stored on uniswap - // (which is used by uniswap to approve the bridge to burn funds on its behalf to exit to L1) - const nonceForBurnApprovalBeforeSwap = await uniswapL2Contract.methods.nonce_for_burn_approval().simulate(); - // 4. Swap on L1 - sends L2 to L1 message to withdraw WETH to L1 and another message to swap assets. const [secretForDepositingSwappedDai, secretHashForDepositingSwappedDai] = daiCrossChainHarness.generateClaimSecret(); @@ -521,10 +510,6 @@ export const uniswapL1L2TestSuite = ( // check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!) await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge); - // check burn approval nonce incremented: - const nonceForBurnApprovalAfterSwap = await uniswapL2Contract.methods.nonce_for_burn_approval().simulate(); - expect(nonceForBurnApprovalAfterSwap).toBe(nonceForBurnApprovalBeforeSwap + 1n); - // 5. Perform the swap on L1 with the `uniswapPortal.swap_private()` (consuming L2 to L1 messages) logger.info('Execute withdraw and swap on the uniswapPortal!'); const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf( @@ -773,10 +758,7 @@ export const uniswapL1L2TestSuite = ( ); await ownerWallet.setPublicAuthWit(swapMessageHash, true).send().wait(); - // Swap! - await expect(action.prove()).rejects.toThrow( - "Assertion failed: Message not authorized by account 'is_valid == true'", - ); + await expect(action.simulate()).rejects.toThrow(/unauthorized/); }); it("uniswap can't pull funds without transfer approval", async () => { @@ -808,8 +790,8 @@ export const uniswapL1L2TestSuite = ( ownerEthAddress, Fr.ZERO, ) - .prove(), - ).rejects.toThrow(`Assertion failed: Message not authorized by account 'is_valid == true'`); + .simulate(), + ).rejects.toThrow(/unauthorized/); }); // tests when trying to mix private and public flows: diff --git a/yarn-project/foundation/src/abi/abi.ts b/yarn-project/foundation/src/abi/abi.ts index 200e7b0088c..2b608086604 100644 --- a/yarn-project/foundation/src/abi/abi.ts +++ b/yarn-project/foundation/src/abi/abi.ts @@ -290,10 +290,6 @@ export type FieldLayout = { * Slot in which the field is stored. */ slot: Fr; - /** - * Type being stored at the slot (e.g., 'Map>') - */ - typ: string; }; /** diff --git a/yarn-project/foundation/src/fields/point.ts b/yarn-project/foundation/src/fields/point.ts index b152bffcc6a..bf12faf3a13 100644 --- a/yarn-project/foundation/src/fields/point.ts +++ b/yarn-project/foundation/src/fields/point.ts @@ -137,8 +137,20 @@ export class Point { return poseidon2Hash(this.toFields()); } + /** + * Check if this is point at infinity. + * Check this is consistent with how bb is encoding the point at infinity + */ + public get inf() { + return this.x == Fr.ZERO; + } + public toFieldsWithInf() { + return [this.x, this.y, new Fr(this.inf)]; + } + isOnGrumpkin() { - if (this.isZero()) { + // TODO: Check this against how bb handles curve check and infinity point check + if (this.inf) { return true; } diff --git a/yarn-project/p2p-bootstrap/terraform/main.tf b/yarn-project/p2p-bootstrap/terraform/main.tf index 7dbfed502b3..3536c88ee06 100644 --- a/yarn-project/p2p-bootstrap/terraform/main.tf +++ b/yarn-project/p2p-bootstrap/terraform/main.tf @@ -104,7 +104,7 @@ resource "aws_ecs_task_definition" "p2p-bootstrap" { container_definitions = < { - let discv5Service; let p2pService; if (config.p2pEnabled) { @@ -40,7 +39,7 @@ export const createP2PClient = async ( config.tcpAnnounceAddress = tcpAnnounceAddress; } else { throw new Error( - `Invalid announceTcpAddress provided: ${splitTcpAnnounceAddress}. Expected format: :`, + `Invalid announceTcpAddress provided: ${configTcpAnnounceAddress}. Expected format: :`, ); } } @@ -59,11 +58,10 @@ export const createP2PClient = async ( // Create peer discovery service const peerId = await createLibP2PPeerId(config.peerIdPrivateKey); - discv5Service = new DiscV5Service(peerId, config); - p2pService = await LibP2PService.new(config, discv5Service, peerId, txPool); + const discoveryService = new DiscV5Service(peerId, config); + p2pService = await LibP2PService.new(config, discoveryService, peerId, txPool, store); } else { p2pService = new DummyP2PService(); - discv5Service = new DummyPeerDiscoveryService(); } return new P2PClient(store, l2BlockSource, txPool, p2pService); }; diff --git a/yarn-project/p2p/src/client/p2p_client.test.ts b/yarn-project/p2p/src/client/p2p_client.test.ts index 91c0a5561f0..6726df9aeaa 100644 --- a/yarn-project/p2p/src/client/p2p_client.test.ts +++ b/yarn-project/p2p/src/client/p2p_client.test.ts @@ -37,7 +37,6 @@ describe('In-Memory P2P Client', () => { start: jest.fn(), stop: jest.fn(), propagateTx: jest.fn(), - settledTxs: jest.fn(), }; blockSource = new MockBlockSource(); diff --git a/yarn-project/p2p/src/client/p2p_client.ts b/yarn-project/p2p/src/client/p2p_client.ts index fe3c58db602..96401b35685 100644 --- a/yarn-project/p2p/src/client/p2p_client.ts +++ b/yarn-project/p2p/src/client/p2p_client.ts @@ -194,7 +194,7 @@ export class P2PClient implements P2P { this.log.debug('Stopped block downloader'); await this.runningPromise; this.setCurrentState(P2PClientState.STOPPED); - this.log.info('P2P client stopped...'); + this.log.info('P2P client stopped.'); } /** @@ -278,7 +278,6 @@ export class P2PClient implements P2P { for (const block of blocks) { const txHashes = block.body.txEffects.map(txEffect => txEffect.txHash); await this.txPool.deleteTxs(txHashes); - this.p2pService.settledTxs(txHashes); } } diff --git a/yarn-project/p2p/src/service/discV5_service.ts b/yarn-project/p2p/src/service/discV5_service.ts index 8838c180b2f..557a431e19b 100644 --- a/yarn-project/p2p/src/service/discV5_service.ts +++ b/yarn-project/p2p/src/service/discV5_service.ts @@ -1,9 +1,8 @@ import { createDebugLogger } from '@aztec/foundation/log'; -import { RunningPromise } from '@aztec/foundation/running-promise'; import { sleep } from '@aztec/foundation/sleep'; import { Discv5, type Discv5EventEmitter } from '@chainsafe/discv5'; -import { type ENR, SignableENR } from '@chainsafe/enr'; +import { ENR, SignableENR } from '@chainsafe/enr'; import type { PeerId } from '@libp2p/interface'; import { multiaddr } from '@multiformats/multiaddr'; import EventEmitter from 'events'; @@ -14,6 +13,8 @@ import { type PeerDiscoveryService, PeerDiscoveryState } from './service.js'; export const AZTEC_ENR_KEY = 'aztec_network'; +const delayBeforeStart = 2000; // 2sec + export enum AztecENR { devnet = 0x01, testnet = 0x02, @@ -33,11 +34,12 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService /** This instance's ENR */ private enr: SignableENR; - private runningPromise: RunningPromise; - private currentState = PeerDiscoveryState.STOPPED; private bootstrapNodes: string[]; + private bootstrapNodePeerIds: PeerId[] = []; + + private startTime = 0; constructor(private peerId: PeerId, config: P2PConfig, private logger = createDebugLogger('aztec:discv5_service')) { super(); @@ -83,18 +85,17 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService const multiAddrUdp = await enr.getFullMultiaddr('udp'); this.logger.debug(`ENR multiaddr: ${multiAddrTcp?.toString()}, ${multiAddrUdp?.toString()}`); }); - - this.runningPromise = new RunningPromise(async () => { - await this.discv5.findRandomNode(); - }, config.p2pPeerCheckIntervalMS); } public async start(): Promise { + // Do this conversion once since it involves an async function call + this.bootstrapNodePeerIds = await Promise.all(this.bootstrapNodes.map(enr => ENR.decodeTxt(enr).peerId())); if (this.currentState === PeerDiscoveryState.RUNNING) { throw new Error('DiscV5Service already started'); } this.logger.info('Starting DiscV5'); await this.discv5.start(); + this.startTime = Date.now(); this.logger.info('DiscV5 started'); this.currentState = PeerDiscoveryState.RUNNING; @@ -110,12 +111,25 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService this.logger.error(`Error adding bootnode ENRs: ${e}`); } } + } + + public async runRandomNodesQuery(): Promise { + if (this.currentState !== PeerDiscoveryState.RUNNING) { + throw new Error('DiscV5Service not running'); + } // First, wait some time before starting the peer discovery // reference: https://github.com/ChainSafe/lodestar/issues/3423 - await sleep(2000); + const msSinceStart = Date.now() - this.startTime; + if (Date.now() - this.startTime <= delayBeforeStart) { + await sleep(delayBeforeStart - msSinceStart); + } - this.runningPromise.start(); + try { + await this.discv5.findRandomNode(); + } catch (err) { + this.logger.error(`Error running discV5 random node query: ${err}`); + } } public getAllPeers(): ENR[] { @@ -134,8 +148,11 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService return this.currentState; } + public isBootstrapPeer(peerId: PeerId): boolean { + return this.bootstrapNodePeerIds.some(node => node.equals(peerId)); + } + public async stop(): Promise { - await this.runningPromise.stop(); await this.discv5.stop(); this.currentState = PeerDiscoveryState.STOPPED; } diff --git a/yarn-project/p2p/src/service/discv5_service.test.ts b/yarn-project/p2p/src/service/discv5_service.test.ts index dd5a58b9aae..67442f0a87e 100644 --- a/yarn-project/p2p/src/service/discv5_service.test.ts +++ b/yarn-project/p2p/src/service/discv5_service.test.ts @@ -1,3 +1,5 @@ +import { sleep } from '@aztec/foundation/sleep'; + import { jest } from '@jest/globals'; import type { PeerId } from '@libp2p/interface'; import { SemVer } from 'semver'; @@ -8,7 +10,7 @@ import { createLibP2PPeerId } from './libp2p_service.js'; import { PeerDiscoveryState } from './service.js'; const waitForPeers = (node: DiscV5Service, expectedCount: number): Promise => { - const timeout = 5_000; + const timeout = 7_000; return new Promise((resolve, reject) => { const timeoutId = setTimeout(() => { reject(new Error(`Timeout: Failed to connect to ${expectedCount} peers within ${timeout} ms`)); @@ -67,7 +69,17 @@ describe('Discv5Service', () => { const node2 = await createNode(basePort); await node1.start(); await node2.start(); - await waitForPeers(node2, 2); + await Promise.all([ + waitForPeers(node2, 2), + (async () => { + await sleep(2000); // wait for peer discovery to be able to start + for (let i = 0; i < 5; i++) { + await node1.runRandomNodesQuery(); + await node2.runRandomNodesQuery(); + await sleep(100); + } + })(), + ]); const node1Peers = await Promise.all(node1.getAllPeers().map(async peer => (await peer.peerId()).toString())); const node2Peers = await Promise.all(node2.getAllPeers().map(async peer => (await peer.peerId()).toString())); diff --git a/yarn-project/p2p/src/service/dummy_service.ts b/yarn-project/p2p/src/service/dummy_service.ts index cd1ed8d0d41..aeeedb1f03d 100644 --- a/yarn-project/p2p/src/service/dummy_service.ts +++ b/yarn-project/p2p/src/service/dummy_service.ts @@ -1,5 +1,6 @@ -import { type Tx, type TxHash } from '@aztec/circuit-types'; +import type { Tx, TxHash } from '@aztec/circuit-types'; +import type { PeerId } from '@libp2p/interface'; import EventEmitter from 'events'; import { type P2PService, type PeerDiscoveryService, PeerDiscoveryState } from './service.js'; @@ -66,6 +67,14 @@ export class DummyPeerDiscoveryService extends EventEmitter implements PeerDisco return []; } + public runRandomNodesQuery(): Promise { + return Promise.resolve(); + } + + public isBootstrapPeer(_: PeerId): boolean { + return false; + } + public getStatus(): PeerDiscoveryState { return this.currentState; } diff --git a/yarn-project/p2p/src/service/known_txs.test.ts b/yarn-project/p2p/src/service/known_txs.test.ts deleted file mode 100644 index 7c93b085320..00000000000 --- a/yarn-project/p2p/src/service/known_txs.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { randomTxHash } from '@aztec/circuit-types'; - -import { expect } from '@jest/globals'; -import type { Ed25519PeerId, PeerId } from '@libp2p/interface'; -import { mock } from 'jest-mock-extended'; - -import { KnownTxLookup } from './known_txs.js'; - -const createMockPeerId = (peerId: string): PeerId => { - return mock({ - toString: () => peerId, - }); -}; - -describe('Known Txs', () => { - it('Returns false when a peer has not seen a tx', () => { - const knownTxs = new KnownTxLookup(); - - const peer = createMockPeerId('Peer 1'); - const txHash = randomTxHash(); - - expect(knownTxs.hasPeerSeenTx(peer, txHash.toString())).toEqual(false); - }); - - it('Returns true when a peer has seen a tx', () => { - const knownTxs = new KnownTxLookup(); - - const peer = createMockPeerId('Peer 1'); - const peer2 = createMockPeerId('Peer 2'); - const txHash = randomTxHash(); - - knownTxs.addPeerForTx(peer, txHash.toString()); - - expect(knownTxs.hasPeerSeenTx(peer, txHash.toString())).toEqual(true); - expect(knownTxs.hasPeerSeenTx(peer2, txHash.toString())).toEqual(false); - - knownTxs.addPeerForTx(peer2, txHash.toString()); - - expect(knownTxs.hasPeerSeenTx(peer, txHash.toString())).toEqual(true); - expect(knownTxs.hasPeerSeenTx(peer2, txHash.toString())).toEqual(true); - }); -}); diff --git a/yarn-project/p2p/src/service/known_txs.ts b/yarn-project/p2p/src/service/known_txs.ts deleted file mode 100644 index d25c866aebe..00000000000 --- a/yarn-project/p2p/src/service/known_txs.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { type PeerId } from '@libp2p/interface'; - -/** - * Keeps a record of which Peers have 'seen' which transactions. - */ -export class KnownTxLookup { - private lookup: { [key: string]: { [key: string]: boolean } } = {}; - - constructor() {} - - /** - * Inform this lookup that a peer has 'seen' a transaction. - * @param peerId - The peerId of the peer that has 'seen' the transaction. - * @param txHash - The thHash of the 'seen' transaction. - */ - public addPeerForTx(peerId: PeerId, txHash: string) { - const peerIdAsString = peerId.toString(); - const existingLookup = this.lookup[txHash]; - if (existingLookup === undefined) { - const newLookup: { [key: string]: boolean } = {}; - newLookup[peerIdAsString] = true; - this.lookup[txHash] = newLookup; - return; - } - existingLookup[peerIdAsString] = true; - } - - /** - * Determine if a peer has 'seen' a transaction. - * @param peerId - The peerId of the peer. - * @param txHash - The thHash of the transaction. - * @returns A boolean indicating if the transaction has been 'seen' by the peer. - */ - public hasPeerSeenTx(peerId: PeerId, txHash: string) { - const existingLookup = this.lookup[txHash]; - if (existingLookup === undefined) { - return false; - } - const peerIdAsString = peerId.toString(); - return !!existingLookup[peerIdAsString]; - } - - /** - * Updates the lookup from the result of settled txs - * These txs will be cleared out of the lookup. - * It is possible that some txs could still be gossiped for a - * short period of time meaning they come back into this lookup - * but this should be infrequent and cause no undesirable effects - * @param txHashes - The hashes of the newly settled transactions - */ - public handleSettledTxs(txHashes: string[]) { - for (const txHash of txHashes) { - delete this.lookup[txHash]; - } - } -} diff --git a/yarn-project/p2p/src/service/libp2p_service.ts b/yarn-project/p2p/src/service/libp2p_service.ts index 6ae680020d0..5164ebfcd64 100644 --- a/yarn-project/p2p/src/service/libp2p_service.ts +++ b/yarn-project/p2p/src/service/libp2p_service.ts @@ -1,17 +1,16 @@ -import { type Tx, type TxHash } from '@aztec/circuit-types'; +import { type Tx } from '@aztec/circuit-types'; import { SerialQueue } from '@aztec/foundation/fifo'; import { createDebugLogger } from '@aztec/foundation/log'; -import { AztecLmdbStore } from '@aztec/kv-store/lmdb'; +import { RunningPromise } from '@aztec/foundation/running-promise'; +import type { AztecKVStore } from '@aztec/kv-store'; -import { ENR } from '@chainsafe/enr'; import { type GossipsubEvents, gossipsub } from '@chainsafe/libp2p-gossipsub'; import { noise } from '@chainsafe/libp2p-noise'; import { yamux } from '@chainsafe/libp2p-yamux'; import { identify } from '@libp2p/identify'; -import type { PeerId, PubSub, Stream } from '@libp2p/interface'; +import type { PeerId, PubSub } from '@libp2p/interface'; import '@libp2p/kad-dht'; import { mplex } from '@libp2p/mplex'; -import { peerIdFromString } from '@libp2p/peer-id'; import { createFromJSON, createSecp256k1PeerId } from '@libp2p/peer-id-factory'; import { tcp } from '@libp2p/tcp'; import { type Libp2p, createLibp2p } from 'libp2p'; @@ -20,7 +19,6 @@ import { type P2PConfig } from '../config.js'; import { type TxPool } from '../tx_pool/index.js'; import { convertToMultiaddr } from '../util.js'; import { AztecDatastore } from './data_store.js'; -import { KnownTxLookup } from './known_txs.js'; import { PeerManager } from './peer_manager.js'; import type { P2PService, PeerDiscoveryService } from './service.js'; import { AztecTxMessageCreator, fromTxMessage } from './tx_messages.js'; @@ -30,7 +28,6 @@ export interface PubSubLibp2p extends Libp2p { pubsub: PubSub; }; } - /** * Create a libp2p peer ID from the private key if provided, otherwise creates a new random ID. * @param privateKey - Optional peer ID private key as hex string @@ -52,16 +49,14 @@ export async function createLibP2PPeerId(privateKey?: string): Promise { */ export class LibP2PService implements P2PService { private jobQueue: SerialQueue = new SerialQueue(); - private knownTxLookup: KnownTxLookup = new KnownTxLookup(); private messageCreator: AztecTxMessageCreator; private peerManager: PeerManager; + private discoveryRunningPromise?: RunningPromise; constructor( private config: P2PConfig, private node: PubSubLibp2p, private peerDiscoveryService: PeerDiscoveryService, - private protocolId: string, private txPool: TxPool, - private bootstrapPeerIds: PeerId[] = [], private logger = createDebugLogger('aztec:libp2p_service'), ) { this.messageCreator = new AztecTxMessageCreator(config.txGossipVersion); @@ -73,54 +68,42 @@ export class LibP2PService implements P2PService { * @returns An empty promise. */ public async start() { + // Check if service is already started if (this.node.status === 'started') { throw new Error('P2P service already started'); } + + // Log listen & announce addresses const { tcpListenAddress, tcpAnnounceAddress } = this.config; this.logger.info(`Starting P2P node on ${tcpListenAddress}`); - if (!tcpAnnounceAddress) { throw new Error('Announce address not provided.'); } - const announceTcpMultiaddr = convertToMultiaddr(tcpAnnounceAddress, 'tcp'); - this.logger.info(`Announcing at ${announceTcpMultiaddr}`); - // handle discovered peers from external discovery service - this.peerDiscoveryService.on('peer:discovered', async (enr: ENR) => { - await this.addPeer(enr); - }); - - this.node.addEventListener('peer:connect', async evt => { - const peerId = evt.detail; - await this.handleNewConnection(peerId as PeerId); - }); - - this.node.addEventListener('peer:disconnect', async evt => { - const peerId = evt.detail; - if (this.isBootstrapPeer(peerId)) { - this.logger.info(`Disconnect from bootstrap peer ${peerId.toString()}`); - } else { - this.logger.info(`Disconnected from transaction peer ${peerId.toString()}`); - await this.peerManager.updateDiscoveryService(); - } - }); + // Start job queue, peer discovery service and libp2p node this.jobQueue.start(); await this.peerDiscoveryService.start(); await this.node.start(); this.logger.info(`Started P2P client with Peer ID ${this.node.peerId.toString()}`); - // Subscribe to standard topics by default + // Subscribe to standard GossipSub topics by default this.subscribeToTopic(this.messageCreator.getTopic()); - // add gossipsub listener + // add GossipSub listener this.node.services.pubsub.addEventListener('gossipsub:message', async e => { const { msg } = e.detail; this.logger.debug(`Received PUBSUB message.`); await this.jobQueue.put(() => this.handleNewGossipMessage(msg.topic, msg.data)); }); + + // Start running promise for peer discovery + this.discoveryRunningPromise = new RunningPromise(() => { + this.peerManager.discover(); + }, this.config.p2pPeerCheckIntervalMS); + this.discoveryRunningPromise.start(); } /** @@ -130,8 +113,12 @@ export class LibP2PService implements P2PService { public async stop() { this.logger.debug('Stopping job queue...'); await this.jobQueue.end(); + this.logger.debug('Stopping running promise...'); + await this.discoveryRunningPromise?.stop(); + this.logger.debug('Stopping peer discovery service...'); + await this.peerDiscoveryService.stop(); this.logger.debug('Stopping LibP2P...'); - await this.node.stop(); + await this.stopLibP2P(); this.logger.info('LibP2P service stopped'); } @@ -146,11 +133,14 @@ export class LibP2PService implements P2PService { peerDiscoveryService: PeerDiscoveryService, peerId: PeerId, txPool: TxPool, + store: AztecKVStore, ) { - const { tcpListenAddress, minPeerCount, maxPeerCount, transactionProtocol: protocolId } = config; + const { tcpListenAddress, tcpAnnounceAddress, minPeerCount, maxPeerCount } = config; const bindAddrTcp = convertToMultiaddr(tcpListenAddress, 'tcp'); + // We know tcpAnnounceAddress cannot be null here because we set it or throw when setting up the service. + const announceAddrTcp = convertToMultiaddr(tcpAnnounceAddress!, 'tcp'); - const datastore = new AztecDatastore(AztecLmdbStore.open()); + const datastore = new AztecDatastore(store); // The autonat service seems quite problematic in that using it seems to cause a lot of attempts // to dial ephemeral ports. I suspect that it works better if you can get the uPNPnat service to @@ -171,10 +161,19 @@ export class LibP2PService implements P2PService { peerId, addresses: { listen: [bindAddrTcp], + announce: [announceAddrTcp], }, transports: [ tcp({ maxConnections: config.maxPeerCount, + // socket option: the maximum length of the queue of pending connections + // https://nodejs.org/dist/latest-v18.x/docs/api/net.html#serverlisten + // it's not safe if we increase this number + backlog: 5, + closeServerOnMaxConnections: { + closeAbove: maxPeerCount ?? Infinity, + listenBelow: maxPeerCount ?? Infinity, + }, }), ], datastore, @@ -200,15 +199,7 @@ export class LibP2PService implements P2PService { }, }); - // extract bootstrap node peer IDs - let bootstrapPeerIds: PeerId[] = []; - if (config.bootstrapNodes.length) { - bootstrapPeerIds = await Promise.all( - config.bootstrapNodes.map(bootnodeEnr => ENR.decodeTxt(bootnodeEnr).peerId()), - ); - } - - return new LibP2PService(config, node, peerDiscoveryService, protocolId, txPool, bootstrapPeerIds); + return new LibP2PService(config, node, peerDiscoveryService, txPool); } /** @@ -260,71 +251,31 @@ export class LibP2PService implements P2PService { void this.jobQueue.put(() => Promise.resolve(this.sendTxToPeers(tx))); } - /** - * Handles the settling of a new batch of transactions. - * @param txHashes - The hashes of the newly settled transactions. - */ - public settledTxs(txHashes: TxHash[]): void { - this.knownTxLookup.handleSettledTxs(txHashes.map(x => x.toString())); - } - - private async addPeer(enr: ENR) { - const peerMultiAddr = await enr.getFullMultiaddr('tcp'); - if (!peerMultiAddr) { - // No TCP address, can't connect - return; - } - const peerIdStr = peerMultiAddr.getPeerId(); - - if (!peerIdStr) { - this.logger.debug(`Peer ID not found in discovered node's multiaddr: ${peerMultiAddr}`); - return; - } - - // check if peer is already known - const peerId = peerIdFromString(peerIdStr); - const hasPeer = await this.node.peerStore.has(peerId); - - // add to peer store if not already known - if (!hasPeer) { - this.logger.info(`Discovered peer ${peerIdStr}. Adding to libp2p peer list`); - let stream: Stream | undefined; - try { - stream = await this.node.dialProtocol(peerMultiAddr, this.protocolId); - } catch (err) { - this.logger.debug(`Failed to dial peer ${peerIdStr}: ${err}`); - } finally { - if (stream) { - await stream.close(); - } - } - } - } - - private async handleNewConnection(peerId: PeerId) { - if (this.isBootstrapPeer(peerId)) { - this.logger.info(`Connected to bootstrap peer ${peerId.toString()}`); - } else { - this.logger.info(`Connected to transaction peer ${peerId.toString()}`); - await this.peerManager.updateDiscoveryService(); - } - } - private async processTxFromPeer(tx: Tx): Promise { const txHash = tx.getTxHash(); const txHashString = txHash.toString(); - this.logger.debug(`Received tx ${txHashString} from external peer.`); + this.logger.verbose(`Received tx ${txHashString} from external peer.`); await this.txPool.addTxs([tx]); } private async sendTxToPeers(tx: Tx) { const { data: txData } = this.messageCreator.createTxMessage(tx); - this.logger.debug(`Sending tx ${tx.getTxHash().toString()} to peers`); + this.logger.verbose(`Sending tx ${tx.getTxHash().toString()} to peers`); const recipientsNum = await this.publishToTopic(this.messageCreator.getTopic(), txData); - this.logger.debug(`Sent tx ${tx.getTxHash().toString()} to ${recipientsNum} peers`); + this.logger.verbose(`Sent tx ${tx.getTxHash().toString()} to ${recipientsNum} peers`); } - private isBootstrapPeer(peer: PeerId) { - return this.bootstrapPeerIds.some(bootstrapPeer => bootstrapPeer.equals(peer)); + // Libp2p seems to hang sometimes if new peers are initiating connections. + private async stopLibP2P() { + const TIMEOUT_MS = 5000; // 5 seconds timeout + const timeout = new Promise((resolve, reject) => { + setTimeout(() => reject(new Error('Timeout during libp2p.stop()')), TIMEOUT_MS); + }); + try { + await Promise.race([this.node.stop(), timeout]); + this.logger.debug('Libp2p stopped'); + } catch (error) { + this.logger.error('Error during stop or timeout:', error); + } } } diff --git a/yarn-project/p2p/src/service/peer_manager.ts b/yarn-project/p2p/src/service/peer_manager.ts index 9e2993103d9..c81dab40124 100644 --- a/yarn-project/p2p/src/service/peer_manager.ts +++ b/yarn-project/p2p/src/service/peer_manager.ts @@ -1,26 +1,201 @@ import { createDebugLogger } from '@aztec/foundation/log'; +import { type ENR } from '@chainsafe/enr'; +import { type PeerId } from '@libp2p/interface'; +import { type Multiaddr } from '@multiformats/multiaddr'; import { type Libp2p } from 'libp2p'; import { type P2PConfig } from '../config.js'; -import { type PeerDiscoveryService, PeerDiscoveryState } from './service.js'; +import { type PeerDiscoveryService } from './service.js'; + +const MAX_DIAL_ATTEMPTS = 3; +const MAX_CACHED_PEERS = 100; + +type CachedPeer = { + peerId: PeerId; + enr: ENR; + multiaddrTcp: Multiaddr; + dialAttempts: number; +}; export class PeerManager { + private cachedPeers: Map = new Map(); constructor( private libP2PNode: Libp2p, - private discV5Node: PeerDiscoveryService, + private peerDiscoveryService: PeerDiscoveryService, private config: P2PConfig, private logger = createDebugLogger('aztec:p2p:peer_manager'), - ) {} - - async updateDiscoveryService() { - const peerCount = this.libP2PNode.getPeers().length; - if (peerCount >= this.config.maxPeerCount && this.discV5Node.getStatus() === PeerDiscoveryState.RUNNING) { - this.logger.debug('Max peer count reached, stopping discovery service'); - await this.discV5Node.stop(); - } else if (peerCount <= this.config.minPeerCount && this.discV5Node.getStatus() === PeerDiscoveryState.STOPPED) { - this.logger.debug('Min peer count reached, starting discovery service'); - await this.discV5Node.start(); + ) { + // Handle new established connections + this.libP2PNode.addEventListener('peer:connect', evt => { + const peerId = evt.detail; + if (this.peerDiscoveryService.isBootstrapPeer(peerId)) { + this.logger.debug(`Connected to bootstrap peer ${peerId.toString()}`); + } else { + this.logger.debug(`Connected to transaction peer ${peerId.toString()}`); + } + }); + + // Handle lost connections + this.libP2PNode.addEventListener('peer:disconnect', evt => { + const peerId = evt.detail; + if (this.peerDiscoveryService.isBootstrapPeer(peerId)) { + this.logger.debug(`Disconnected from bootstrap peer ${peerId.toString()}`); + } else { + this.logger.debug(`Disconnected from transaction peer ${peerId.toString()}`); + } + }); + + // Handle Discovered peers + this.peerDiscoveryService.on('peer:discovered', async (enr: ENR) => { + await this.handleDiscoveredPeer(enr); + }); + } + + /** + * Discovers peers. + */ + public discover() { + // Get current connections + const connections = this.libP2PNode.getConnections(); + + // Calculate how many connections we're looking to make + const peersToConnect = this.config.maxPeerCount - connections.length; + + this.logger.debug( + `Connections: ${connections.length}, Peers to connect: ${peersToConnect}, maxPeerCount: ${this.config.maxPeerCount}, cachedPeers: ${this.cachedPeers.size}`, + ); + + // Exit if no peers to connect + if (peersToConnect <= 0) { + return; + } + + const cachedPeersToDial: CachedPeer[] = []; + + const pendingDials = new Set( + this.libP2PNode + .getDialQueue() + .map(pendingDial => pendingDial.peerId?.toString()) + .filter(Boolean) as string[], + ); + + for (const [id, peerData] of this.cachedPeers.entries()) { + // if already dialling or connected to, remove from cache + if (pendingDials.has(id) || connections.some(conn => conn.remotePeer.equals(peerData.peerId))) { + this.cachedPeers.delete(id); + } else { + // cachedPeersToDial.set(id, enr); + cachedPeersToDial.push(peerData); + } + } + + // reverse to dial older entries first + cachedPeersToDial.reverse(); + + for (const peer of cachedPeersToDial) { + this.cachedPeers.delete(peer.peerId.toString()); + void this.dialPeer(peer); + } + + // if we need more peers, start randomNodesQuery + if (peersToConnect > 0) { + this.logger.debug('Running random nodes query'); + void this.peerDiscoveryService.runRandomNodesQuery(); + } + } + + /** + * Handles a discovered peer. + * @param enr - The discovered peer's ENR. + */ + private async handleDiscoveredPeer(enr: ENR) { + // TODO: Will be handling peer scoring here + + // check if peer is already connected + const [peerId, multiaddrTcp] = await Promise.all([enr.peerId(), enr.getFullMultiaddr('tcp')]); + + this.logger.debug(`Handling discovered peer ${peerId.toString()}, ${multiaddrTcp?.toString()}`); + + // throw if no tcp addr in multiaddr + if (!multiaddrTcp) { + this.logger.debug(`No TCP address in discovered node's multiaddr: ${enr.toString()}`); + return; + } + const connections = this.libP2PNode.getConnections(); + if (connections.some(conn => conn.remotePeer.equals(peerId))) { + this.logger.debug(`Already connected to peer ${peerId.toString()}`); + return; + } + + // check if peer is already in cache + const id = peerId.toString(); + if (this.cachedPeers.has(id)) { + this.logger.debug(`Already in cache ${id}`); + return; + } + + // create cached peer object + const cachedPeer: CachedPeer = { + peerId, + enr, + multiaddrTcp, + dialAttempts: 0, + }; + + // Determine if we should dial immediately or not + if (this.shouldDialPeer()) { + this.logger.debug(`Dialing peer ${id}`); + void this.dialPeer(cachedPeer); + } else { + this.logger.debug(`Caching peer ${id}`); + this.cachedPeers.set(id, cachedPeer); + // Prune set of cached peers + this.pruneCachedPeers(); + } + } + + async dialPeer(peer: CachedPeer) { + const id = peer.peerId.toString(); + await this.libP2PNode.peerStore.merge(peer.peerId, { multiaddrs: [peer.multiaddrTcp] }); + + this.logger.debug(`Dialing peer ${id}`); + try { + await this.libP2PNode.dial(peer.multiaddrTcp); + } catch { + this.logger.debug(`Failed to dial peer ${id}`); + peer.dialAttempts++; + if (peer.dialAttempts < MAX_DIAL_ATTEMPTS) { + this.cachedPeers.set(id, peer); + } else { + this.cachedPeers.delete(id); + } + } + } + + private shouldDialPeer(): boolean { + const connections = this.libP2PNode.getConnections().length; + this.logger.debug(`Connections: ${connections}, maxPeerCount: ${this.config.maxPeerCount}`); + if (connections >= this.config.maxPeerCount) { + this.logger.debug('Not dialing peer, maxPeerCount reached'); + return false; + } + return true; + } + + private pruneCachedPeers() { + let peersToDelete = this.cachedPeers.size - MAX_CACHED_PEERS; + if (peersToDelete <= 0) { + return; + } + + // Remove the oldest peers + for (const key of this.cachedPeers.keys()) { + this.cachedPeers.delete(key); + peersToDelete--; + if (peersToDelete <= 0) { + break; + } } } } diff --git a/yarn-project/p2p/src/service/service.ts b/yarn-project/p2p/src/service/service.ts index 5d3389af54d..f9933dd3b34 100644 --- a/yarn-project/p2p/src/service/service.ts +++ b/yarn-project/p2p/src/service/service.ts @@ -1,6 +1,7 @@ -import type { Tx, TxHash } from '@aztec/circuit-types'; +import type { Tx } from '@aztec/circuit-types'; import type { ENR } from '@chainsafe/enr'; +import type { PeerId } from '@libp2p/interface'; import type EventEmitter from 'events'; export enum PeerDiscoveryState { @@ -29,12 +30,6 @@ export interface P2PService { * @param tx - The transaction to be propagated. */ propagateTx(tx: Tx): void; - - /** - * Called upon receipt of settled transactions. - * @param txHashes - The hashes of the settled transactions. - */ - settledTxs(txHashes: TxHash[]): void; } /** @@ -57,6 +52,18 @@ export interface PeerDiscoveryService extends EventEmitter { */ getAllPeers(): ENR[]; + /** + * Runs findRandomNode query. + */ + runRandomNodesQuery(): Promise; + + /** + * Checks if the given peer is a bootstrap peer. + * @param peerId - The peer ID to check. + * @returns True if the peer is a bootstrap peer. + */ + isBootstrapPeer(peerId: PeerId): boolean; + /** * Event emitted when a new peer is discovered. */ diff --git a/yarn-project/package.json b/yarn-project/package.json index fa08f05b063..388c8f4d6df 100644 --- a/yarn-project/package.json +++ b/yarn-project/package.json @@ -51,6 +51,7 @@ "sequencer-client", "scripts", "types", + "txe", "world-state" ], "prettier": "@aztec/foundation/prettier", diff --git a/yarn-project/protocol-contracts/scripts/copy-contracts.sh b/yarn-project/protocol-contracts/scripts/copy-contracts.sh index a58fbdfcf60..239445f9bbc 100755 --- a/yarn-project/protocol-contracts/scripts/copy-contracts.sh +++ b/yarn-project/protocol-contracts/scripts/copy-contracts.sh @@ -7,6 +7,7 @@ contracts=( contract_instance_deployer_contract-ContractInstanceDeployer gas_token_contract-GasToken key_registry_contract-KeyRegistry + auth_registry_contract-AuthRegistry multi_call_entrypoint_contract-MultiCallEntrypoint ) diff --git a/yarn-project/protocol-contracts/src/auth-registry/artifact.ts b/yarn-project/protocol-contracts/src/auth-registry/artifact.ts new file mode 100644 index 00000000000..d33c2a9820f --- /dev/null +++ b/yarn-project/protocol-contracts/src/auth-registry/artifact.ts @@ -0,0 +1,6 @@ +import { loadContractArtifact } from '@aztec/types/abi'; +import { type NoirCompiledContract } from '@aztec/types/noir'; + +import AuthRegistryJson from '../artifacts/AuthRegistry.json' assert { type: 'json' }; + +export const AuthRegistryArtifact = loadContractArtifact(AuthRegistryJson as NoirCompiledContract); diff --git a/yarn-project/protocol-contracts/src/auth-registry/index.test.ts b/yarn-project/protocol-contracts/src/auth-registry/index.test.ts new file mode 100644 index 00000000000..88345788eb2 --- /dev/null +++ b/yarn-project/protocol-contracts/src/auth-registry/index.test.ts @@ -0,0 +1,17 @@ +import { + AztecAddress, + CANONICAL_AUTH_REGISTRY_ADDRESS, + computeContractAddressFromInstance, + getContractClassFromArtifact, +} from '@aztec/circuits.js'; + +import { getCanonicalAuthRegistry } from './index.js'; + +describe('AuthRegistry', () => { + it('returns canonical protocol contract', () => { + const contract = getCanonicalAuthRegistry(); + expect(computeContractAddressFromInstance(contract.instance)).toEqual(contract.address); + expect(getContractClassFromArtifact(contract.artifact).id).toEqual(contract.contractClass.id); + expect(contract.address).toEqual(AztecAddress.fromBigInt(CANONICAL_AUTH_REGISTRY_ADDRESS)); + }); +}); diff --git a/yarn-project/protocol-contracts/src/auth-registry/index.ts b/yarn-project/protocol-contracts/src/auth-registry/index.ts new file mode 100644 index 00000000000..7adf8c3e3e8 --- /dev/null +++ b/yarn-project/protocol-contracts/src/auth-registry/index.ts @@ -0,0 +1,22 @@ +import { AztecAddress, CANONICAL_AUTH_REGISTRY_ADDRESS } from '@aztec/circuits.js'; + +import { type ProtocolContract, getCanonicalProtocolContract } from '../protocol_contract.js'; +import { AuthRegistryArtifact } from './artifact.js'; + +/** Returns the canonical deployment of the auth registry. */ +export function getCanonicalAuthRegistry(): ProtocolContract { + const contract = getCanonicalProtocolContract(AuthRegistryArtifact, 1); + + if (!contract.address.equals(AuthRegistryAddress)) { + throw new Error( + `Incorrect address for auth registry (got ${contract.address.toString()} but expected ${AuthRegistryAddress.toString()}). Check CANONICAL_AUTH_REGISTRY_ADDRESS is set to the correct value in the constants files and run the protocol-contracts package tests.`, + ); + } + return contract; +} + +export function getCanonicalAuthRegistryAddress(): AztecAddress { + return getCanonicalAuthRegistry().address; +} + +export const AuthRegistryAddress = AztecAddress.fromBigInt(CANONICAL_AUTH_REGISTRY_ADDRESS); diff --git a/yarn-project/prover-client/src/orchestrator/orchestrator.ts b/yarn-project/prover-client/src/orchestrator/orchestrator.ts index a270cbb0628..99526b8dfd1 100644 --- a/yarn-project/prover-client/src/orchestrator/orchestrator.ts +++ b/yarn-project/prover-client/src/orchestrator/orchestrator.ts @@ -772,6 +772,7 @@ export class ProvingOrchestrator { // Nothing downstream depends on the AVM proof yet. So having this mode lets us incrementally build the AVM circuit. const doAvmProving = async (signal: AbortSignal) => { const inputs: AvmCircuitInputs = new AvmCircuitInputs( + publicFunction.vmRequest!.functionName, publicFunction.vmRequest!.bytecode, publicFunction.vmRequest!.calldata, publicFunction.vmRequest!.kernelRequest.inputs.publicCall.callStackItem.publicInputs, diff --git a/yarn-project/pxe/src/database/deferred_note_dao.test.ts b/yarn-project/pxe/src/database/deferred_note_dao.test.ts index 00ede18ca9c..d3c1e5d520b 100644 --- a/yarn-project/pxe/src/database/deferred_note_dao.test.ts +++ b/yarn-project/pxe/src/database/deferred_note_dao.test.ts @@ -5,7 +5,7 @@ import { randomInt } from '@aztec/foundation/crypto'; import { DeferredNoteDao } from './deferred_note_dao.js'; export const randomDeferredNoteDao = ({ - ivpkM = Point.random(), + publicKey = Point.random(), note = Note.random(), contractAddress = AztecAddress.random(), txHash = randomTxHash(), @@ -15,7 +15,7 @@ export const randomDeferredNoteDao = ({ dataStartIndexForTx = randomInt(100), }: Partial = {}) => { return new DeferredNoteDao( - ivpkM, + publicKey, note, contractAddress, storageSlot, diff --git a/yarn-project/pxe/src/database/deferred_note_dao.ts b/yarn-project/pxe/src/database/deferred_note_dao.ts index 0851f4dadcf..6e73db1e237 100644 --- a/yarn-project/pxe/src/database/deferred_note_dao.ts +++ b/yarn-project/pxe/src/database/deferred_note_dao.ts @@ -9,11 +9,8 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; */ export class DeferredNoteDao { constructor( - /** - * The incoming viewing public key the note was encrypted with. - * @dev Will never be ovpkM because there are no deferred notes for outgoing. - */ - public ivpkM: PublicKey, + /** IvpkM or OvpkM (depending on if incoming or outgoing) the note was encrypted with. */ + public publicKey: PublicKey, /** The note as emitted from the Noir contract. */ public note: Note, /** The contract address this note is created in. */ @@ -32,7 +29,7 @@ export class DeferredNoteDao { toBuffer(): Buffer { return serializeToBuffer( - this.ivpkM, + this.publicKey, this.note, this.contractAddress, this.storageSlot, diff --git a/yarn-project/pxe/src/database/index.ts b/yarn-project/pxe/src/database/index.ts index 4685cc2f7a8..e01c1803241 100644 --- a/yarn-project/pxe/src/database/index.ts +++ b/yarn-project/pxe/src/database/index.ts @@ -1 +1,2 @@ export * from './pxe_database.js'; +export * from './kv_pxe_database.js'; diff --git a/yarn-project/pxe/src/database/kv_pxe_database.ts b/yarn-project/pxe/src/database/kv_pxe_database.ts index 74f41fbae8d..4518329fc7d 100644 --- a/yarn-project/pxe/src/database/kv_pxe_database.ts +++ b/yarn-project/pxe/src/database/kv_pxe_database.ts @@ -1,4 +1,10 @@ -import { MerkleTreeId, type NoteFilter, NoteStatus, type PublicKey } from '@aztec/circuit-types'; +import { + type IncomingNotesFilter, + MerkleTreeId, + NoteStatus, + type OutgoingNotesFilter, + type PublicKey, +} from '@aztec/circuit-types'; import { AztecAddress, CompleteAddress, Header } from '@aztec/circuits.js'; import { type ContractArtifact } from '@aztec/foundation/abi'; import { toBufferBE } from '@aztec/foundation/bigint-buffer'; @@ -15,7 +21,7 @@ import { type ContractInstanceWithAddress, SerializableContractInstance } from ' import { DeferredNoteDao } from './deferred_note_dao.js'; import { IncomingNoteDao } from './incoming_note_dao.js'; -import { type OutgoingNoteDao } from './outgoing_note_dao.js'; +import { OutgoingNoteDao } from './outgoing_note_dao.js'; import { type PxeDatabase } from './pxe_database.js'; /** @@ -45,6 +51,12 @@ export class KVPxeDatabase implements PxeDatabase { #contractInstances: AztecMap; #db: AztecKVStore; + #outgoingNotes: AztecMap; + #outgoingNotesByContract: AztecMultiMap; + #outgoingNotesByStorageSlot: AztecMultiMap; + #outgoingNotesByTxHash: AztecMultiMap; + #outgoingNotesByOvpkM: AztecMultiMap; + constructor(private db: AztecKVStore) { this.#db = db; @@ -67,15 +79,21 @@ export class KVPxeDatabase implements PxeDatabase { this.#notesByContract = db.openMultiMap('notes_by_contract'); this.#notesByStorageSlot = db.openMultiMap('notes_by_storage_slot'); this.#notesByTxHash = db.openMultiMap('notes_by_tx_hash'); - this.#notesByIvpkM = db.openMultiMap('notes_by_owner'); + this.#notesByIvpkM = db.openMultiMap('notes_by_ivpk_m'); this.#nullifiedNotesByContract = db.openMultiMap('nullified_notes_by_contract'); this.#nullifiedNotesByStorageSlot = db.openMultiMap('nullified_notes_by_storage_slot'); this.#nullifiedNotesByTxHash = db.openMultiMap('nullified_notes_by_tx_hash'); - this.#nullifiedNotesByIvpkM = db.openMultiMap('nullified_notes_by_owner'); + this.#nullifiedNotesByIvpkM = db.openMultiMap('nullified_notes_by_ivpk_m'); this.#deferredNotes = db.openArray('deferred_notes'); this.#deferredNotesByContract = db.openMultiMap('deferred_notes_by_contract'); + + this.#outgoingNotes = db.openMap('outgoing_notes'); + this.#outgoingNotesByContract = db.openMultiMap('outgoing_notes_by_contract'); + this.#outgoingNotesByStorageSlot = db.openMultiMap('outgoing_notes_by_storage_slot'); + this.#outgoingNotesByTxHash = db.openMultiMap('outgoing_notes_by_tx_hash'); + this.#outgoingNotesByOvpkM = db.openMultiMap('outgoing_notes_by_ovpk_m'); } public async getContract( @@ -140,8 +158,7 @@ export class KVPxeDatabase implements PxeDatabase { await this.addNotes([note], []); } - addNotes(incomingNotes: IncomingNoteDao[], _outgoingNotes: OutgoingNoteDao[]): Promise { - // TODO(#6867): store the outgoing note + addNotes(incomingNotes: IncomingNoteDao[], outgoingNotes: OutgoingNoteDao[]): Promise { return this.db.transaction(() => { for (const dao of incomingNotes) { // store notes by their index in the notes hash tree @@ -156,6 +173,15 @@ export class KVPxeDatabase implements PxeDatabase { void this.#notesByTxHash.set(dao.txHash.toString(), noteIndex); void this.#notesByIvpkM.set(dao.ivpkM.toString(), noteIndex); } + + for (const dao of outgoingNotes) { + const noteIndex = toBufferBE(dao.index, 32).toString('hex'); + void this.#outgoingNotes.set(noteIndex, dao.toBuffer()); + void this.#outgoingNotesByContract.set(dao.contractAddress.toString(), noteIndex); + void this.#outgoingNotesByStorageSlot.set(dao.storageSlot.toString(), noteIndex); + void this.#outgoingNotesByTxHash.set(dao.txHash.toString(), noteIndex); + void this.#outgoingNotesByOvpkM.set(dao.ovpkM.toString(), noteIndex); + } }); } @@ -209,7 +235,7 @@ export class KVPxeDatabase implements PxeDatabase { }); } - #getNotes(filter: NoteFilter): IncomingNoteDao[] { + getIncomingNotes(filter: IncomingNotesFilter): Promise { const publicKey: PublicKey | undefined = filter.owner ? this.#getCompleteAddress(filter.owner)?.publicKeys.masterIncomingViewingPublicKey : undefined; @@ -279,11 +305,57 @@ export class KVPxeDatabase implements PxeDatabase { } } - return result; + return Promise.resolve(result); } - getNotes(filter: NoteFilter): Promise { - return Promise.resolve(this.#getNotes(filter)); + getOutgoingNotes(filter: OutgoingNotesFilter): Promise { + const ovpkM: PublicKey | undefined = filter.owner + ? this.#getCompleteAddress(filter.owner)?.publicKeys.masterOutgoingViewingPublicKey + : undefined; + + // Check if ovpkM is truthy + const ids = ovpkM + ? this.#outgoingNotesByOvpkM.getValues(ovpkM.toString()) + : // If ovpkM is falsy, check if filter.txHash is truthy + filter.txHash + ? this.#outgoingNotesByTxHash.getValues(filter.txHash.toString()) + : // If both ovpkM and filter.txHash are falsy, check if filter.contractAddress is truthy + filter.contractAddress + ? this.#outgoingNotesByContract.getValues(filter.contractAddress.toString()) + : // If ovpkM, filter.txHash, and filter.contractAddress are all falsy, check if filter.storageSlot is truthy + filter.storageSlot + ? this.#outgoingNotesByStorageSlot.getValues(filter.storageSlot.toString()) + : // If none of the above conditions are met, retrieve all keys from this.#outgoingNotes + this.#outgoingNotes.keys(); + + const notes: OutgoingNoteDao[] = []; + for (const id of ids) { + const serializedNote = this.#outgoingNotes.get(id); + if (!serializedNote) { + continue; + } + + const note = OutgoingNoteDao.fromBuffer(serializedNote); + if (filter.contractAddress && !note.contractAddress.equals(filter.contractAddress)) { + continue; + } + + if (filter.txHash && !note.txHash.equals(filter.txHash)) { + continue; + } + + if (filter.storageSlot && !note.storageSlot.equals(filter.storageSlot!)) { + continue; + } + + if (ovpkM && !note.ovpkM.equals(ovpkM)) { + continue; + } + + notes.push(note); + } + + return Promise.resolve(notes); } removeNullifiedNotes(nullifiers: Fr[], account: PublicKey): Promise { @@ -419,8 +491,16 @@ export class KVPxeDatabase implements PxeDatabase { return this.#syncedBlockPerPublicKey.set(publicKey.toString(), blockNumber); } - estimateSize(): number { - const notesSize = Array.from(this.#getNotes({})).reduce((sum, note) => sum + note.getSize(), 0); + async estimateSize(): Promise { + const incomingNotesSize = Array.from(await this.getIncomingNotes({})).reduce( + (sum, note) => sum + note.getSize(), + 0, + ); + const outgoingNotesSize = Array.from(await this.getOutgoingNotes({})).reduce( + (sum, note) => sum + note.getSize(), + 0, + ); + const authWitsSize = Array.from(this.#authWitnesses.values()).reduce( (sum, value) => sum + value.length * Fr.SIZE_IN_BYTES, 0, @@ -428,6 +508,6 @@ export class KVPxeDatabase implements PxeDatabase { const addressesSize = this.#addresses.length * CompleteAddress.SIZE_IN_BYTES; const treeRootsSize = Object.keys(MerkleTreeId).length * Fr.SIZE_IN_BYTES; - return notesSize + treeRootsSize + authWitsSize + addressesSize; + return incomingNotesSize + outgoingNotesSize + treeRootsSize + authWitsSize + addressesSize; } } diff --git a/yarn-project/pxe/src/database/outgoing_note_dao.test.ts b/yarn-project/pxe/src/database/outgoing_note_dao.test.ts index f2a52ca58af..166a5e9b51b 100644 --- a/yarn-project/pxe/src/database/outgoing_note_dao.test.ts +++ b/yarn-project/pxe/src/database/outgoing_note_dao.test.ts @@ -9,9 +9,22 @@ export const randomOutgoingNoteDao = ({ txHash = randomTxHash(), storageSlot = Fr.random(), noteTypeId = Fr.random(), + nonce = Fr.random(), + innerNoteHash = Fr.random(), + index = Fr.random().toBigInt(), ovpkM = Point.random(), }: Partial = {}) => { - return new OutgoingNoteDao(note, contractAddress, storageSlot, noteTypeId, txHash, ovpkM); + return new OutgoingNoteDao( + note, + contractAddress, + storageSlot, + noteTypeId, + txHash, + nonce, + innerNoteHash, + index, + ovpkM, + ); }; describe('Outgoing Note DAO', () => { diff --git a/yarn-project/pxe/src/database/outgoing_note_dao.ts b/yarn-project/pxe/src/database/outgoing_note_dao.ts index 1a8befa043f..e7e2b8c263d 100644 --- a/yarn-project/pxe/src/database/outgoing_note_dao.ts +++ b/yarn-project/pxe/src/database/outgoing_note_dao.ts @@ -1,5 +1,6 @@ import { Note, TxHash } from '@aztec/circuit-types'; import { AztecAddress, Fr, Point, type PublicKey } from '@aztec/circuits.js'; +import { toBigIntBE } from '@aztec/foundation/bigint-buffer'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; /** @@ -17,6 +18,15 @@ export class OutgoingNoteDao { public noteTypeId: Fr, /** The hash of the tx the note was created in. */ public txHash: TxHash, + /** The nonce of the note. */ + public nonce: Fr, + /** + * Inner note hash of the note. This is customizable by the app circuit. + * We can use this value to compute siloedNoteHash and uniqueSiloedNoteHash. + */ + public innerNoteHash: Fr, + /** The location of the relevant note in the note hash tree. */ + public index: bigint, /** The public key with which the note was encrypted. */ public ovpkM: PublicKey, ) {} @@ -28,6 +38,9 @@ export class OutgoingNoteDao { this.storageSlot, this.noteTypeId, this.txHash.buffer, + this.nonce, + this.innerNoteHash, + this.index, this.ovpkM, ]); } @@ -39,9 +52,22 @@ export class OutgoingNoteDao { const storageSlot = Fr.fromBuffer(reader); const noteTypeId = Fr.fromBuffer(reader); const txHash = new TxHash(reader.readBytes(TxHash.SIZE)); + const nonce = Fr.fromBuffer(reader); + const innerNoteHash = Fr.fromBuffer(reader); + const index = toBigIntBE(reader.readBytes(32)); const publicKey = Point.fromBuffer(reader); - return new OutgoingNoteDao(note, contractAddress, storageSlot, noteTypeId, txHash, publicKey); + return new OutgoingNoteDao( + note, + contractAddress, + storageSlot, + noteTypeId, + txHash, + nonce, + innerNoteHash, + index, + publicKey, + ); } toString() { diff --git a/yarn-project/pxe/src/database/pxe_database.ts b/yarn-project/pxe/src/database/pxe_database.ts index a5ffb5fadf1..4a875292693 100644 --- a/yarn-project/pxe/src/database/pxe_database.ts +++ b/yarn-project/pxe/src/database/pxe_database.ts @@ -1,4 +1,4 @@ -import { type NoteFilter } from '@aztec/circuit-types'; +import { type IncomingNotesFilter, type OutgoingNotesFilter } from '@aztec/circuit-types'; import { type CompleteAddress, type Header, type PublicKey } from '@aztec/circuits.js'; import { type ContractArtifact } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; @@ -47,11 +47,17 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD popCapsule(): Promise; /** - * Gets notes based on the provided filter. + * Gets incoming notes based on the provided filter. * @param filter - The filter to apply to the notes. * @returns The requested notes. */ - getNotes(filter: NoteFilter): Promise; + getIncomingNotes(filter: IncomingNotesFilter): Promise; + + /** + * Gets outgoing notes. + * @returns The outgoing notes. + */ + getOutgoingNotes(filter: OutgoingNotesFilter): Promise; /** * Adds a note to DB. @@ -170,5 +176,5 @@ export interface PxeDatabase extends ContractArtifactDatabase, ContractInstanceD * Returns the estimated size in bytes of this db. * @returns The estimated size in bytes of this db. */ - estimateSize(): number; + estimateSize(): Promise; } diff --git a/yarn-project/pxe/src/database/pxe_database_test_suite.ts b/yarn-project/pxe/src/database/pxe_database_test_suite.ts index 3095494580a..92a2dc1d2e5 100644 --- a/yarn-project/pxe/src/database/pxe_database_test_suite.ts +++ b/yarn-project/pxe/src/database/pxe_database_test_suite.ts @@ -1,4 +1,4 @@ -import { type NoteFilter, NoteStatus, randomTxHash } from '@aztec/circuit-types'; +import { type IncomingNotesFilter, NoteStatus, type OutgoingNotesFilter, randomTxHash } from '@aztec/circuit-types'; import { AztecAddress, CompleteAddress, INITIAL_L2_BLOCK_NUM, PublicKeys } from '@aztec/circuits.js'; import { makeHeader } from '@aztec/circuits.js/testing'; import { randomInt } from '@aztec/foundation/crypto'; @@ -8,6 +8,8 @@ import { SerializableContractInstance } from '@aztec/types/contracts'; import { type IncomingNoteDao } from './incoming_note_dao.js'; import { randomIncomingNoteDao } from './incoming_note_dao.test.js'; +import { type OutgoingNoteDao } from './outgoing_note_dao.js'; +import { randomOutgoingNoteDao } from './outgoing_note_dao.test.js'; import { type PxeDatabase } from './pxe_database.js'; /** @@ -74,7 +76,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { let storageSlots: Fr[]; let notes: IncomingNoteDao[]; - const filteringTests: [() => NoteFilter, () => IncomingNoteDao[]][] = [ + const filteringTests: [() => IncomingNotesFilter, () => IncomingNoteDao[]][] = [ [() => ({}), () => notes], [ @@ -107,7 +109,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { [() => ({ contractAddress: contractAddresses[0], storageSlot: storageSlots[1] }), () => []], ]; - beforeEach(() => { + beforeEach(async () => { owners = Array.from({ length: 2 }).map(() => CompleteAddress.random()); contractAddresses = Array.from({ length: 2 }).map(() => AztecAddress.random()); storageSlots = Array.from({ length: 2 }).map(() => Fr.random()); @@ -120,9 +122,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { index: BigInt(i), }), ); - }); - beforeEach(async () => { for (const owner of owners) { await database.addCompleteAddress(owner); } @@ -130,14 +130,14 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { it.each(filteringTests)('stores notes in bulk and retrieves notes', async (getFilter, getExpected) => { await database.addNotes(notes, []); - await expect(database.getNotes(getFilter())).resolves.toEqual(getExpected()); + await expect(database.getIncomingNotes(getFilter())).resolves.toEqual(getExpected()); }); it.each(filteringTests)('stores notes one by one and retrieves notes', async (getFilter, getExpected) => { for (const note of notes) { await database.addNote(note); } - await expect(database.getNotes(getFilter())).resolves.toEqual(getExpected()); + await expect(database.getIncomingNotes(getFilter())).resolves.toEqual(getExpected()); }); it.each(filteringTests)('retrieves nullified notes', async (getFilter, getExpected) => { @@ -154,9 +154,9 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { ).resolves.toEqual(notesToNullify); } - await expect(database.getNotes({ ...getFilter(), status: NoteStatus.ACTIVE_OR_NULLIFIED })).resolves.toEqual( - getExpected(), - ); + await expect( + database.getIncomingNotes({ ...getFilter(), status: NoteStatus.ACTIVE_OR_NULLIFIED }), + ).resolves.toEqual(getExpected()); }); it('skips nullified notes by default or when requesting active', async () => { @@ -170,8 +170,8 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { notesToNullify, ); - const actualNotesWithDefault = await database.getNotes({}); - const actualNotesWithActive = await database.getNotes({ status: NoteStatus.ACTIVE }); + const actualNotesWithDefault = await database.getIncomingNotes({}); + const actualNotesWithActive = await database.getIncomingNotes({ status: NoteStatus.ACTIVE }); expect(actualNotesWithDefault).toEqual(actualNotesWithActive); expect(actualNotesWithActive).toEqual(notes.filter(note => !notesToNullify.includes(note))); @@ -188,7 +188,7 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { notesToNullify, ); - const result = await database.getNotes({ + const result = await database.getIncomingNotes({ status: NoteStatus.ACTIVE_OR_NULLIFIED, }); @@ -198,7 +198,69 @@ export function describePxeDatabase(getDatabase: () => PxeDatabase) { }); }); - // TODO(#6867): Add tests for outgoing notes + describe('outgoing notes', () => { + let owners: CompleteAddress[]; + let contractAddresses: AztecAddress[]; + let storageSlots: Fr[]; + let notes: OutgoingNoteDao[]; + + const filteringTests: [() => OutgoingNotesFilter, () => OutgoingNoteDao[]][] = [ + [() => ({}), () => notes], + + [ + () => ({ contractAddress: contractAddresses[0] }), + () => notes.filter(note => note.contractAddress.equals(contractAddresses[0])), + ], + [() => ({ contractAddress: AztecAddress.random() }), () => []], + + [ + () => ({ storageSlot: storageSlots[0] }), + () => notes.filter(note => note.storageSlot.equals(storageSlots[0])), + ], + [() => ({ storageSlot: Fr.random() }), () => []], + + [() => ({ txHash: notes[0].txHash }), () => [notes[0]]], + [() => ({ txHash: randomTxHash() }), () => []], + + [ + () => ({ owner: owners[0].address }), + () => notes.filter(note => note.ovpkM.equals(owners[0].publicKeys.masterOutgoingViewingPublicKey)), + ], + + [ + () => ({ contractAddress: contractAddresses[0], storageSlot: storageSlots[0] }), + () => + notes.filter( + note => note.contractAddress.equals(contractAddresses[0]) && note.storageSlot.equals(storageSlots[0]), + ), + ], + [() => ({ contractAddress: contractAddresses[0], storageSlot: storageSlots[1] }), () => []], + ]; + + beforeEach(async () => { + owners = Array.from({ length: 2 }).map(() => CompleteAddress.random()); + contractAddresses = Array.from({ length: 2 }).map(() => AztecAddress.random()); + storageSlots = Array.from({ length: 2 }).map(() => Fr.random()); + + notes = Array.from({ length: 10 }).map((_, i) => + randomOutgoingNoteDao({ + contractAddress: contractAddresses[i % contractAddresses.length], + storageSlot: storageSlots[i % storageSlots.length], + ovpkM: owners[i % owners.length].publicKeys.masterOutgoingViewingPublicKey, + index: BigInt(i), + }), + ); + + for (const owner of owners) { + await database.addCompleteAddress(owner); + } + }); + + it.each(filteringTests)('stores notes in bulk and retrieves notes', async (getFilter, getExpected) => { + await database.addNotes([], notes); + await expect(database.getOutgoingNotes(getFilter())).resolves.toEqual(getExpected()); + }); + }); describe('block header', () => { it('stores and retrieves the block header', async () => { diff --git a/yarn-project/pxe/src/index.ts b/yarn-project/pxe/src/index.ts index d7cf6d57253..7c62b24d3ff 100644 --- a/yarn-project/pxe/src/index.ts +++ b/yarn-project/pxe/src/index.ts @@ -9,3 +9,5 @@ export * from '@aztec/foundation/fields'; export * from '@aztec/foundation/eth-address'; export * from '@aztec/foundation/aztec-address'; export * from '@aztec/key-store'; +export * from './database/index.js'; +export { ContractDataOracle } from './contract_data_oracle/index.js'; diff --git a/yarn-project/pxe/src/note_processor/note_processor.ts b/yarn-project/pxe/src/note_processor/note_processor.ts index e7a2d4d95e7..61b1a820ba0 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.ts @@ -44,7 +44,8 @@ export class NoteProcessor { seen: 0, decryptedIncoming: 0, decryptedOutgoing: 0, - deferred: 0, + deferredIncoming: 0, + deferredOutgoing: 0, failed: 0, blocks: 0, txs: 0, @@ -115,9 +116,8 @@ export class NoteProcessor { const blocksAndNotes: ProcessedData[] = []; // Keep track of notes that we couldn't process because the contract was not found. - // Note that there are no deferred outgoing notes because we don't need the contract there for anything since we - // are not attempting to derive a nullifier. - const deferredNoteDaosIncoming: DeferredNoteDao[] = []; + const deferredIncomingNotes: DeferredNoteDao[] = []; + const deferredOutgoingNotes: DeferredNoteDao[] = []; const ivskM = await this.keyStore.getMasterSecretKey(this.ivpkM); const ovskM = await this.keyStore.getMasterSecretKey(this.ovpkM); @@ -151,18 +151,23 @@ export class NoteProcessor { const outgoingTaggedNote = TaggedLog.decryptAsOutgoing(log.data, ovskM)!; if (incomingTaggedNote || outgoingTaggedNote) { - if ( - incomingTaggedNote && - outgoingTaggedNote && - !incomingTaggedNote.payload.equals(outgoingTaggedNote.payload) - ) { - throw new Error('Incoming and outgoing note payloads do not match.'); - } + // TODO(#7053): Re-enable this check + // if ( + // incomingTaggedNote && + // outgoingTaggedNote && + // !incomingTaggedNote.payload.equals(outgoingTaggedNote.payload) + // ) { + // throw new Error( + // `Incoming and outgoing note payloads do not match. Incoming: ${JSON.stringify( + // incomingTaggedNote.payload, + // )}, Outgoing: ${JSON.stringify(outgoingTaggedNote.payload)}`, + // ); + // } const payload = incomingTaggedNote?.payload || outgoingTaggedNote?.payload; const txHash = block.body.txEffects[indexOfTxInABlock].txHash; - const { incomingNote, outgoingNote, incomingDeferredNote } = await produceNoteDaos( + const { incomingNote, outgoingNote, incomingDeferredNote, outgoingDeferredNote } = await produceNoteDaos( this.simulator, incomingTaggedNote ? this.ivpkM : undefined, outgoingTaggedNote ? this.ovpkM : undefined, @@ -183,8 +188,12 @@ export class NoteProcessor { this.stats.decryptedOutgoing++; } if (incomingDeferredNote) { - deferredNoteDaosIncoming.push(incomingDeferredNote); - this.stats.deferred++; + deferredIncomingNotes.push(incomingDeferredNote); + this.stats.deferredIncoming++; + } + if (outgoingDeferredNote) { + deferredOutgoingNotes.push(outgoingDeferredNote); + this.stats.deferredOutgoing++; } if (incomingNote == undefined && outgoingNote == undefined && incomingDeferredNote == undefined) { @@ -203,7 +212,7 @@ export class NoteProcessor { } await this.processBlocksAndNotes(blocksAndNotes); - await this.processDeferredNotes(deferredNoteDaosIncoming); + await this.processDeferredNotes(deferredIncomingNotes, deferredOutgoingNotes); const syncedToBlock = blocks[blocks.length - 1].number; await this.db.setSynchedBlockNumberForPublicKey(this.ivpkM, syncedToBlock); @@ -253,14 +262,25 @@ export class NoteProcessor { /** * Store the given deferred notes in the database for later decoding. * - * @param deferredNoteDaos - notes that are intended for us but we couldn't process because the contract was not found. + * @param deferredIncomingNotes - incoming notes that are intended for us but we couldn't process because the contract was not found. + * @param deferredOutgoingNotes - outgoing notes that we couldn't process because the contract was not found. */ - private async processDeferredNotes(deferredNoteDaos: DeferredNoteDao[]) { - if (deferredNoteDaos.length) { - await this.db.addDeferredNotes(deferredNoteDaos); - deferredNoteDaos.forEach(noteDao => { + private async processDeferredNotes( + deferredIncomingNotes: DeferredNoteDao[], + deferredOutgoingNotes: DeferredNoteDao[], + ) { + if (deferredIncomingNotes.length || deferredOutgoingNotes.length) { + await this.db.addDeferredNotes([...deferredIncomingNotes, ...deferredOutgoingNotes]); + deferredIncomingNotes.forEach(noteDao => { this.log.verbose( - `Deferred note for contract ${noteDao.contractAddress} at slot ${ + `Deferred incoming note for contract ${noteDao.contractAddress} at slot ${ + noteDao.storageSlot + } in tx ${noteDao.txHash.toString()}`, + ); + }); + deferredOutgoingNotes.forEach(noteDao => { + this.log.verbose( + `Deferred outgoing note for contract ${noteDao.contractAddress} at slot ${ noteDao.storageSlot } in tx ${noteDao.txHash.toString()}`, ); @@ -272,29 +292,36 @@ export class NoteProcessor { * Retry decoding the given deferred notes because we now have the contract code. * * @param deferredNoteDaos - notes that we have previously deferred because the contract was not found - * @returns An array of incoming notes that were successfully decoded. + * @returns An object containing arrays of incoming and outgoing notes that were successfully decoded. * * @remarks Caller is responsible for making sure that we have the contract for the * deferred notes provided: we will not retry notes that fail again. */ - public async decodeDeferredNotes(deferredNoteDaos: DeferredNoteDao[]): Promise { + public async decodeDeferredNotes(deferredNoteDaos: DeferredNoteDao[]): Promise<{ + incomingNotes: IncomingNoteDao[]; + outgoingNotes: OutgoingNoteDao[]; + }> { const excludedIndices: Set = new Set(); const incomingNotes: IncomingNoteDao[] = []; + const outgoingNotes: OutgoingNoteDao[] = []; for (const deferredNote of deferredNoteDaos) { - const { ivpkM, note, contractAddress, storageSlot, noteTypeId, txHash, newNoteHashes, dataStartIndexForTx } = + const { publicKey, note, contractAddress, storageSlot, noteTypeId, txHash, newNoteHashes, dataStartIndexForTx } = deferredNote; const payload = new L1NotePayload(note, contractAddress, storageSlot, noteTypeId); - if (!ivpkM.equals(this.ivpkM)) { - // The note is not for this account, so we skip it. + const isIncoming = publicKey.equals(this.ivpkM); + const isOutgoing = publicKey.equals(this.ovpkM); + + if (!isIncoming && !isOutgoing) { + // The note does not belong to this note processor continue; } - const { incomingNote } = await produceNoteDaos( + const { incomingNote, outgoingNote } = await produceNoteDaos( this.simulator, - this.ivpkM, - undefined, + isIncoming ? this.ivpkM : undefined, + isOutgoing ? this.ovpkM : undefined, payload, txHash, newNoteHashes, @@ -303,14 +330,22 @@ export class NoteProcessor { this.log, ); - if (!incomingNote) { - throw new Error('Deferred note could not be decoded.'); + if (isIncoming) { + if (!incomingNote) { + throw new Error('Deferred incoming note could not be decoded'); + } + incomingNotes.push(incomingNote); + this.stats.decryptedIncoming++; + } + if (outgoingNote) { + if (!outgoingNote) { + throw new Error('Deferred outgoing note could not be decoded'); + } + outgoingNotes.push(outgoingNote); + this.stats.decryptedOutgoing++; } - - incomingNotes.push(incomingNote); - this.stats.decryptedIncoming++; } - return incomingNotes; + return { incomingNotes, outgoingNotes }; } } diff --git a/yarn-project/pxe/src/note_processor/produce_note_dao.ts b/yarn-project/pxe/src/note_processor/produce_note_dao.ts index 34c90f22962..9fc246a34fb 100644 --- a/yarn-project/pxe/src/note_processor/produce_note_dao.ts +++ b/yarn-project/pxe/src/note_processor/produce_note_dao.ts @@ -22,7 +22,7 @@ import { OutgoingNoteDao } from '../database/outgoing_note_dao.js'; * @param dataStartIndexForTx - The next available leaf index for the note hash tree for this transaction. * @param excludedIndices - Indices that have been assigned a note in the same tx. Notes in a tx can have the same l1NotePayload, we need to find a different index for each replicate. * @param simulator - An instance of AcirSimulator. - * @returns An object containing the incoming note, outgoing note, and deferred note. + * @returns An object containing the incoming, outgoing, and deferred notes. */ export async function produceNoteDaos( simulator: AcirSimulator, @@ -38,6 +38,7 @@ export async function produceNoteDaos( incomingNote: IncomingNoteDao | undefined; outgoingNote: OutgoingNoteDao | undefined; incomingDeferredNote: DeferredNoteDao | undefined; + outgoingDeferredNote: DeferredNoteDao | undefined; }> { if (!ivpkM && !ovpkM) { throw new Error('Both ivpkM and ovpkM are undefined. Cannot create note.'); @@ -45,21 +46,8 @@ export async function produceNoteDaos( let incomingNote: IncomingNoteDao | undefined; let outgoingNote: OutgoingNoteDao | undefined; - - // Note that there are no deferred outgoing notes because we don't need the contract there for anything since we - // are not attempting to derive a nullifier. let incomingDeferredNote: DeferredNoteDao | undefined; - - if (ovpkM) { - outgoingNote = new OutgoingNoteDao( - payload.note, - payload.contractAddress, - payload.storageSlot, - payload.noteTypeId, - txHash, - ovpkM, - ); - } + let outgoingDeferredNote: DeferredNoteDao | undefined; try { if (ivpkM) { @@ -69,6 +57,7 @@ export async function produceNoteDaos( txHash, payload, excludedIndices, + true, // For incoming we compute a nullifier (recipient of incoming is the party that nullifies). ); const index = BigInt(dataStartIndexForTx + noteHashIndex); excludedIndices?.add(noteHashIndex); @@ -107,10 +96,72 @@ export async function produceNoteDaos( } } + try { + if (ovpkM) { + if (incomingNote) { + // Incoming note is defined meaning that this PXE has both the incoming and outgoing keys. We can skip computing + // note hash and note index since we already have them in the incoming note. + outgoingNote = new OutgoingNoteDao( + payload.note, + payload.contractAddress, + payload.storageSlot, + payload.noteTypeId, + txHash, + incomingNote.nonce, + incomingNote.innerNoteHash, + incomingNote.index, + ovpkM, + ); + } else { + const { noteHashIndex, nonce, innerNoteHash } = await findNoteIndexAndNullifier( + simulator, + newNoteHashes, + txHash, + payload, + excludedIndices, + false, // For outgoing we do not compute a nullifier. + ); + const index = BigInt(dataStartIndexForTx + noteHashIndex); + excludedIndices?.add(noteHashIndex); + outgoingNote = new OutgoingNoteDao( + payload.note, + payload.contractAddress, + payload.storageSlot, + payload.noteTypeId, + txHash, + nonce, + innerNoteHash, + index, + ovpkM, + ); + } + } + } catch (e) { + if (e instanceof ContractNotFoundError) { + log.warn(e.message); + + if (ovpkM) { + outgoingDeferredNote = new DeferredNoteDao( + ovpkM, + payload.note, + payload.contractAddress, + payload.storageSlot, + payload.noteTypeId, + txHash, + newNoteHashes, + dataStartIndexForTx, + ); + } + } else { + log.error(`Could not process note because of "${e}". Discarding note...`); + } + } + return { incomingNote, outgoingNote, incomingDeferredNote, + outgoingDeferredNote, }; } @@ -124,6 +175,7 @@ export async function produceNoteDaos( * @param l1NotePayload - The note payload. * @param excludedIndices - Indices that have been assigned a note in the same tx. Notes in a tx can have the same * l1NotePayload. We need to find a different index for each replicate. + * @param computeNullifier - A flag indicating whether to compute the nullifier or just return 0. * @returns Nonce, index, inner hash and siloed nullifier for a given note. * @throws If cannot find the nonce for the note. */ @@ -133,6 +185,7 @@ async function findNoteIndexAndNullifier( txHash: TxHash, { contractAddress, storageSlot, noteTypeId, note }: L1NotePayload, excludedIndices: Set, + computeNullifier: boolean, ) { let noteHashIndex = 0; let nonce: Fr | undefined; @@ -157,7 +210,7 @@ async function findNoteIndexAndNullifier( expectedNonce, storageSlot, noteTypeId, - true, + computeNullifier, note, )); diff --git a/yarn-project/pxe/src/pxe_service/create_pxe_service.ts b/yarn-project/pxe/src/pxe_service/create_pxe_service.ts index 390855b9c2c..6d55b11709c 100644 --- a/yarn-project/pxe/src/pxe_service/create_pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/create_pxe_service.ts @@ -5,6 +5,7 @@ import { createDebugLogger } from '@aztec/foundation/log'; import { KeyStore } from '@aztec/key-store'; import { AztecLmdbStore } from '@aztec/kv-store/lmdb'; import { initStoreForRollup } from '@aztec/kv-store/utils'; +import { getCanonicalAuthRegistry } from '@aztec/protocol-contracts/auth-registry'; import { getCanonicalClassRegisterer } from '@aztec/protocol-contracts/class-registerer'; import { getCanonicalGasToken } from '@aztec/protocol-contracts/gas-token'; import { getCanonicalInstanceDeployer } from '@aztec/protocol-contracts/instance-deployer'; @@ -67,6 +68,7 @@ export async function createPXEService( getCanonicalMultiCallEntrypointContract(), getCanonicalGasToken(), getCanonicalKeyRegistry(), + getCanonicalAuthRegistry(), ]) { await server.registerContract(contract); } diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index fb8a51fb977..5422eea4f00 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -7,11 +7,12 @@ import { ExtendedNote, type FunctionCall, type GetUnencryptedLogsResponse, + type IncomingNotesFilter, L1EventPayload, type L2Block, type LogFilter, MerkleTreeId, - type NoteFilter, + type OutgoingNotesFilter, type PXE, type PXEInfo, type ProofCreator, @@ -34,7 +35,13 @@ import { getContractClassFromArtifact, } from '@aztec/circuits.js'; import { computeNoteHashNonce, siloNullifier } from '@aztec/circuits.js/hash'; -import { type ContractArtifact, type DecodedReturn, FunctionSelector, encodeArguments } from '@aztec/foundation/abi'; +import { + type ContractArtifact, + type DecodedReturn, + EventSelector, + FunctionSelector, + encodeArguments, +} from '@aztec/foundation/abi'; import { type Fq, Fr, type Point } from '@aztec/foundation/fields'; import { SerialQueue } from '@aztec/foundation/fifo'; import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log'; @@ -288,11 +295,11 @@ export class PXEService implements PXE { return await this.node.getPublicStorageAt(contract, slot); } - public async getNotes(filter: NoteFilter): Promise { - const noteDaos = await this.db.getNotes(filter); + public async getIncomingNotes(filter: IncomingNotesFilter): Promise { + const noteDaos = await this.db.getIncomingNotes(filter); - // TODO(benesjan): Refactor --> This type conversion is ugly but I decided to keep it this way for now because - // key derivation will affect all this + // TODO(#6531): Refactor --> This type conversion is ugly but I decided to keep it this way for now because + // key rotation will affect this const extendedNotes = noteDaos.map(async dao => { let owner = filter.owner; if (owner === undefined) { @@ -309,6 +316,27 @@ export class PXEService implements PXE { return Promise.all(extendedNotes); } + public async getOutgoingNotes(filter: OutgoingNotesFilter): Promise { + const noteDaos = await this.db.getOutgoingNotes(filter); + + // TODO(#6532): Refactor --> This type conversion is ugly but I decided to keep it this way for now because + // key rotation will affect this + const extendedNotes = noteDaos.map(async dao => { + let owner = filter.owner; + if (owner === undefined) { + const completeAddresses = (await this.db.getCompleteAddresses()).find(address => + address.publicKeys.masterOutgoingViewingPublicKey.equals(dao.ovpkM), + ); + if (completeAddresses === undefined) { + throw new Error(`Cannot find complete address for OvpkM ${dao.ovpkM.toString()}`); + } + owner = completeAddresses.address; + } + return new ExtendedNote(dao.note, owner, dao.contractAddress, dao.storageSlot, dao.noteTypeId, dao.txHash); + }); + return Promise.all(extendedNotes); + } + public async addNote(note: ExtendedNote) { const owner = await this.db.getCompleteAddress(note.owner); if (!owner) { @@ -831,7 +859,7 @@ export class PXEService implements PXE { if (visibleEvent.payload === undefined) { return undefined; } - if (!FunctionSelector.fromField(visibleEvent.payload.eventTypeId).equals(eventMetadata.functionSelector)) { + if (!EventSelector.fromField(visibleEvent.payload.eventTypeId).equals(eventMetadata.eventSelector)) { return undefined; } if (visibleEvent.payload.event.items.length !== eventMetadata.fieldNames.length) { diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 53352cb9508..02f6aa0859d 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -78,7 +78,7 @@ export class SimulatorOracle implements DBOracle { } async getNotes(contractAddress: AztecAddress, storageSlot: Fr, status: NoteStatus) { - const noteDaos = await this.db.getNotes({ + const noteDaos = await this.db.getIncomingNotes({ contractAddress, storageSlot, status, diff --git a/yarn-project/pxe/src/synchronizer/synchronizer.ts b/yarn-project/pxe/src/synchronizer/synchronizer.ts index 8a3c55478eb..7b301889b04 100644 --- a/yarn-project/pxe/src/synchronizer/synchronizer.ts +++ b/yarn-project/pxe/src/synchronizer/synchronizer.ts @@ -9,6 +9,7 @@ import { type KeyStore } from '@aztec/key-store'; import { type DeferredNoteDao } from '../database/deferred_note_dao.js'; import { type IncomingNoteDao } from '../database/incoming_note_dao.js'; import { type PxeDatabase } from '../database/index.js'; +import { type OutgoingNoteDao } from '../database/outgoing_note_dao.js'; import { NoteProcessor } from '../note_processor/index.js'; /** @@ -194,7 +195,7 @@ export class Synchronizer { eventName: 'note-processor-caught-up', account: noteProcessor.account.toString(), duration: noteProcessor.timer.ms(), - dbSize: this.db.estimateSize(), + dbSize: await this.db.estimateSize(), ...noteProcessor.stats, } satisfies NoteProcessorCaughtUpStats); @@ -333,37 +334,50 @@ export class Synchronizer { // keep track of decoded notes const incomingNotes: IncomingNoteDao[] = []; + const outgoingNotes: OutgoingNoteDao[] = []; + // now process each txHash for (const deferredNotes of txHashToDeferredNotes.values()) { // to be safe, try each note processor in case the deferred notes are for different accounts. for (const processor of this.noteProcessors) { - const notes = await processor.decodeDeferredNotes(deferredNotes); - incomingNotes.push(...notes); + const { incomingNotes: inNotes, outgoingNotes: outNotes } = await processor.decodeDeferredNotes(deferredNotes); + incomingNotes.push(...inNotes); + outgoingNotes.push(...outNotes); } } // now drop the deferred notes, and add the decoded notes await this.db.removeDeferredNotesByContract(contractAddress); - await this.db.addNotes(incomingNotes, []); + await this.db.addNotes(incomingNotes, outgoingNotes); incomingNotes.forEach(noteDao => { this.log.debug( - `Decoded deferred note for contract ${noteDao.contractAddress} at slot ${ + `Decoded deferred incoming note for contract ${noteDao.contractAddress} at slot ${ noteDao.storageSlot } with nullifier ${noteDao.siloedNullifier.toString()}`, ); }); + outgoingNotes.forEach(noteDao => { + this.log.debug( + `Decoded deferred outgoing note for contract ${noteDao.contractAddress} at slot ${noteDao.storageSlot}`, + ); + }); + + await this.#removeNullifiedNotes(incomingNotes); + } + + async #removeNullifiedNotes(notes: IncomingNoteDao[]) { // now group the decoded incoming notes by public key - const publicKeyToNotes: Map = new Map(); - for (const noteDao of incomingNotes) { - const notesForPublicKey = publicKeyToNotes.get(noteDao.ivpkM) ?? []; + const publicKeyToIncomingNotes: Map = new Map(); + for (const noteDao of notes) { + const notesForPublicKey = publicKeyToIncomingNotes.get(noteDao.ivpkM) ?? []; notesForPublicKey.push(noteDao); - publicKeyToNotes.set(noteDao.ivpkM, notesForPublicKey); + publicKeyToIncomingNotes.set(noteDao.ivpkM, notesForPublicKey); } // now for each group, look for the nullifiers in the nullifier tree - for (const [publicKey, notes] of publicKeyToNotes.entries()) { + for (const [publicKey, notes] of publicKeyToIncomingNotes.entries()) { const nullifiers = notes.map(n => n.siloedNullifier); const relevantNullifiers: Fr[] = []; for (const nullifier of nullifiers) { diff --git a/yarn-project/scripts/src/benchmarks/aggregate.ts b/yarn-project/scripts/src/benchmarks/aggregate.ts index 8e7c8d8cba6..5e6f6ab5d89 100644 --- a/yarn-project/scripts/src/benchmarks/aggregate.ts +++ b/yarn-project/scripts/src/benchmarks/aggregate.ts @@ -134,14 +134,25 @@ function processCircuitSimulation(entry: CircuitSimulationStats, results: Benchm */ function processCircuitProving(entry: CircuitProvingStats, results: BenchmarkCollectedResults) { if (entry.circuitName === 'app-circuit') { - const bucket = entry.appCircuitName; - if (!bucket) { + if (!entry.appCircuitName) { return; } + const bucket = entry.appCircuitName; append(results, 'app_circuit_proving_time_in_ms', bucket, entry.duration); append(results, 'app_circuit_proof_size_in_bytes', bucket, entry.proofSize); append(results, 'app_circuit_size_in_gates', bucket, entry.circuitSize); append(results, 'app_circuit_num_public_inputs', bucket, entry.numPublicInputs); + } else if (entry.circuitName === 'avm-circuit') { + if (!entry.appCircuitName) { + return; + } + const bucket = `${entry.appCircuitName} (avm)`; + append(results, 'app_circuit_proving_time_in_ms', bucket, entry.duration); + append(results, 'app_circuit_proof_size_in_bytes', bucket, entry.proofSize); + append(results, 'app_circuit_input_size_in_bytes', bucket, entry.inputSize); + // These are not yet correctly passed in bb_prover.ts. + // append(results, 'app_circuit_size_in_gates', bucket, entry.circuitSize); + // append(results, 'app_circuit_num_public_inputs', bucket, entry.numPublicInputs); } else { const bucket = entry.circuitName; append(results, 'protocol_circuit_proving_time_in_ms', bucket, entry.duration); diff --git a/yarn-project/sequencer-client/src/config.test.ts b/yarn-project/sequencer-client/src/config.test.ts new file mode 100644 index 00000000000..f71c8c800cd --- /dev/null +++ b/yarn-project/sequencer-client/src/config.test.ts @@ -0,0 +1,26 @@ +import { AztecAddress, Fr, FunctionSelector } from '@aztec/circuits.js'; + +import { parseSequencerAllowList } from './config.js'; + +describe('sequencer config', () => { + it('parse a sequencer config', () => { + const instance = { address: AztecAddress.random() }; + const instanceFunction = { address: AztecAddress.random(), selector: FunctionSelector.random() }; + const classId = { classId: Fr.random() }; + const classFunction = { classId: Fr.random(), selector: FunctionSelector.random() }; + + const config = [instance, instanceFunction, classId, classFunction]; + + const configStrings = [ + `I:${instance.address}`, + `I:${instanceFunction.address}:${instanceFunction.selector}`, + `C:${classId.classId}`, + `C:${classFunction.classId}:${classFunction.selector}`, + ]; + const stringifiedAllowList = configStrings.join(','); + + const allowList = parseSequencerAllowList(stringifiedAllowList); + + expect(allowList).toEqual(config); + }); +}); diff --git a/yarn-project/sequencer-client/src/config.ts b/yarn-project/sequencer-client/src/config.ts index c3de3aba519..bcf7b95c06c 100644 --- a/yarn-project/sequencer-client/src/config.ts +++ b/yarn-project/sequencer-client/src/config.ts @@ -1,13 +1,10 @@ -import { type AllowedFunction } from '@aztec/circuit-types'; +import { type AllowedElement } from '@aztec/circuit-types'; import { AztecAddress, Fr, FunctionSelector, getContractClassFromArtifact } from '@aztec/circuits.js'; import { type L1ContractAddresses, NULL_KEY } from '@aztec/ethereum'; import { EthAddress } from '@aztec/foundation/eth-address'; -import { EcdsaAccountContractArtifact } from '@aztec/noir-contracts.js/EcdsaAccount'; import { FPCContract } from '@aztec/noir-contracts.js/FPC'; -import { SchnorrAccountContractArtifact } from '@aztec/noir-contracts.js/SchnorrAccount'; -import { SchnorrHardcodedAccountContractArtifact } from '@aztec/noir-contracts.js/SchnorrHardcodedAccount'; -import { SchnorrSingleKeyAccountContractArtifact } from '@aztec/noir-contracts.js/SchnorrSingleKeyAccount'; import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token'; +import { AuthRegistryAddress } from '@aztec/protocol-contracts/auth-registry'; import { GasTokenAddress } from '@aztec/protocol-contracts/gas-token'; import { type Hex } from 'viem'; @@ -102,59 +99,70 @@ export function getConfigEnvVars(): SequencerClientConfig { feeRecipient: FEE_RECIPIENT ? AztecAddress.fromString(FEE_RECIPIENT) : undefined, acvmWorkingDirectory: ACVM_WORKING_DIRECTORY ? ACVM_WORKING_DIRECTORY : undefined, acvmBinaryPath: ACVM_BINARY_PATH ? ACVM_BINARY_PATH : undefined, - allowedFunctionsInSetup: SEQ_ALLOWED_SETUP_FN + allowedInSetup: SEQ_ALLOWED_SETUP_FN ? parseSequencerAllowList(SEQ_ALLOWED_SETUP_FN) : getDefaultAllowedSetupFunctions(), - allowedFunctionsInTeardown: SEQ_ALLOWED_TEARDOWN_FN + allowedInTeardown: SEQ_ALLOWED_TEARDOWN_FN ? parseSequencerAllowList(SEQ_ALLOWED_TEARDOWN_FN) : getDefaultAllowedTeardownFunctions(), }; } -function parseSequencerAllowList(value: string): AllowedFunction[] { - const entries: AllowedFunction[] = []; +/** + * Parses a string to a list of allowed elements. + * Each encoded is expected to be of one of the following formats + * `I:${address}` + * `I:${address}:${selector}` + * `C:${classId}` + * `C:${classId}:${selector}` + * + * @param value The string to parse + * @returns A list of allowed elements + */ +export function parseSequencerAllowList(value: string): AllowedElement[] { + const entries: AllowedElement[] = []; if (!value) { return entries; } for (const val of value.split(',')) { - const [identifierString, selectorString] = val.split(':'); - const selector = FunctionSelector.fromString(selectorString); + const [typeString, identifierString, selectorString] = val.split(':'); + const selector = selectorString !== undefined ? FunctionSelector.fromString(selectorString) : undefined; - if (identifierString.startsWith('0x')) { - entries.push({ - address: AztecAddress.fromString(identifierString), - selector, - }); - } else { - entries.push({ - classId: Fr.fromString(identifierString), - selector, - }); + if (typeString === 'I') { + if (selector) { + entries.push({ + address: AztecAddress.fromString(identifierString), + selector, + }); + } else { + entries.push({ + address: AztecAddress.fromString(identifierString), + }); + } + } else if (typeString === 'C') { + if (selector) { + entries.push({ + classId: Fr.fromString(identifierString), + selector, + }); + } else { + entries.push({ + classId: Fr.fromString(identifierString), + }); + } } } return entries; } -function getDefaultAllowedSetupFunctions(): AllowedFunction[] { +function getDefaultAllowedSetupFunctions(): AllowedElement[] { return [ + // needed for authwit support { - classId: getContractClassFromArtifact(SchnorrAccountContractArtifact).id, - selector: FunctionSelector.fromSignature('approve_public_authwit(Field)'), - }, - { - classId: getContractClassFromArtifact(SchnorrHardcodedAccountContractArtifact).id, - selector: FunctionSelector.fromSignature('approve_public_authwit(Field)'), - }, - { - classId: getContractClassFromArtifact(SchnorrSingleKeyAccountContractArtifact).id, - selector: FunctionSelector.fromSignature('approve_public_authwit(Field)'), - }, - { - classId: getContractClassFromArtifact(EcdsaAccountContractArtifact).id, - selector: FunctionSelector.fromSignature('approve_public_authwit(Field)'), + address: AuthRegistryAddress, }, // needed for claiming on the same tx as a spend { @@ -173,7 +181,7 @@ function getDefaultAllowedSetupFunctions(): AllowedFunction[] { ]; } -function getDefaultAllowedTeardownFunctions(): AllowedFunction[] { +function getDefaultAllowedTeardownFunctions(): AllowedElement[] { return [ { classId: getContractClassFromArtifact(FPCContract.artifact).id, diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index 1d781f8ad7c..aaa1831c190 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -7,7 +7,7 @@ import { type TxValidator, } from '@aztec/circuit-types'; import { - type AllowedFunction, + type AllowedElement, BlockProofError, type BlockProver, PROVING_STATUS, @@ -46,8 +46,8 @@ export class Sequencer { private _feeRecipient = AztecAddress.ZERO; private lastPublishedBlock = 0; private state = SequencerState.STOPPED; - private allowedFunctionsInSetup: AllowedFunction[] = []; - private allowedFunctionsInTeardown: AllowedFunction[] = []; + private allowedInSetup: AllowedElement[] = []; + private allowedInTeardown: AllowedElement[] = []; private maxBlockSizeInBytes: number = 1024 * 1024; constructor( @@ -87,15 +87,15 @@ export class Sequencer { if (config.feeRecipient) { this._feeRecipient = config.feeRecipient; } - if (config.allowedFunctionsInSetup) { - this.allowedFunctionsInSetup = config.allowedFunctionsInSetup; + if (config.allowedInSetup) { + this.allowedInSetup = config.allowedInSetup; } if (config.maxBlockSizeInBytes) { this.maxBlockSizeInBytes = config.maxBlockSizeInBytes; } // TODO(#5917) remove this. it is no longer needed since we don't need to whitelist functions in teardown - if (config.allowedFunctionsInTeardown) { - this.allowedFunctionsInTeardown = config.allowedFunctionsInTeardown; + if (config.allowedInTeardown) { + this.allowedInTeardown = config.allowedInTeardown; } } @@ -206,7 +206,7 @@ export class Sequencer { // TODO: It should be responsibility of the P2P layer to validate txs before passing them on here const allValidTxs = await this.takeValidTxs( pendingTxs, - this.txValidatorFactory.validatorForNewTxs(newGlobalVariables, this.allowedFunctionsInSetup), + this.txValidatorFactory.validatorForNewTxs(newGlobalVariables, this.allowedInSetup), ); // TODO: We are taking the size of the tx from private-land, but we should be doing this after running diff --git a/yarn-project/sequencer-client/src/tx_validator/phases_validator.ts b/yarn-project/sequencer-client/src/tx_validator/phases_validator.ts index 87a8a6c7520..537d646707a 100644 --- a/yarn-project/sequencer-client/src/tx_validator/phases_validator.ts +++ b/yarn-project/sequencer-client/src/tx_validator/phases_validator.ts @@ -1,4 +1,4 @@ -import { type AllowedFunction, PublicKernelType, Tx, type TxValidator } from '@aztec/circuit-types'; +import { type AllowedElement, PublicKernelType, Tx, type TxValidator } from '@aztec/circuit-types'; import { type PublicCallRequest } from '@aztec/circuits.js'; import { createDebugLogger } from '@aztec/foundation/log'; import { AbstractPhaseManager, ContractsDataSourcePublicDB } from '@aztec/simulator'; @@ -8,7 +8,7 @@ export class PhasesTxValidator implements TxValidator { #log = createDebugLogger('aztec:sequencer:tx_validator:tx_phases'); private contractDataSource: ContractsDataSourcePublicDB; - constructor(contracts: ContractDataSource, private setupAllowList: AllowedFunction[]) { + constructor(contracts: ContractDataSource, private setupAllowList: AllowedElement[]) { this.contractDataSource = new ContractsDataSourcePublicDB(contracts); } @@ -57,7 +57,7 @@ export class PhasesTxValidator implements TxValidator { return true; } - async isOnAllowList(publicCall: PublicCallRequest, allowList: AllowedFunction[]): Promise { + async isOnAllowList(publicCall: PublicCallRequest, allowList: AllowedElement[]): Promise { if (publicCall.isEmpty()) { return true; } @@ -66,27 +66,37 @@ export class PhasesTxValidator implements TxValidator { // do these checks first since they don't require the contract class for (const entry of allowList) { - if (!('address' in entry)) { - continue; + if ('address' in entry && !('selector' in entry)) { + if (contractAddress.equals(entry.address)) { + return true; + } } - if (contractAddress.equals(entry.address) && entry.selector.equals(functionSelector)) { - return true; + if ('address' in entry && 'selector' in entry) { + if (contractAddress.equals(entry.address) && entry.selector.equals(functionSelector)) { + return true; + } } - } - const contractClass = await this.contractDataSource.getContractInstance(contractAddress); - if (!contractClass) { - throw new Error(`Contract not found: ${publicCall.contractAddress.toString()}`); - } + const contractClass = await this.contractDataSource.getContractInstance(contractAddress); - for (const entry of allowList) { - if (!('classId' in entry)) { - continue; + if (!contractClass) { + throw new Error(`Contract not found: ${publicCall.contractAddress.toString()}`); + } + + if ('classId' in entry && !('selector' in entry)) { + if (contractClass.contractClassId.equals(entry.classId)) { + return true; + } } - if (contractClass.contractClassId.equals(entry.classId) && entry.selector.equals(functionSelector)) { - return true; + if ('classId' in entry && 'selector' in entry) { + if ( + contractClass.contractClassId.equals(entry.classId) && + (entry.selector === undefined || entry.selector.equals(functionSelector)) + ) { + return true; + } } } diff --git a/yarn-project/sequencer-client/src/tx_validator/tx_validator_factory.ts b/yarn-project/sequencer-client/src/tx_validator/tx_validator_factory.ts index f997aabaa41..6322ced853c 100644 --- a/yarn-project/sequencer-client/src/tx_validator/tx_validator_factory.ts +++ b/yarn-project/sequencer-client/src/tx_validator/tx_validator_factory.ts @@ -1,4 +1,4 @@ -import { type AllowedFunction, type ProcessedTx, type Tx, type TxValidator } from '@aztec/circuit-types'; +import { type AllowedElement, type ProcessedTx, type Tx, type TxValidator } from '@aztec/circuit-types'; import { type GlobalVariables } from '@aztec/circuits.js'; import { GasTokenAddress } from '@aztec/protocol-contracts/gas-token'; import { WorldStateDB, WorldStatePublicDB } from '@aztec/simulator'; @@ -18,7 +18,7 @@ export class TxValidatorFactory { private enforceFees: boolean, ) {} - validatorForNewTxs(globalVariables: GlobalVariables, setupAllowList: AllowedFunction[]): TxValidator { + validatorForNewTxs(globalVariables: GlobalVariables, setupAllowList: AllowedElement[]): TxValidator { return new AggregateTxValidator( new MetadataTxValidator(globalVariables), new DoubleSpendTxValidator(new WorldStateDB(this.merkleTreeDb)), diff --git a/yarn-project/simulator/src/avm/avm_gas.ts b/yarn-project/simulator/src/avm/avm_gas.ts index 7802d4177d1..d951f20fa32 100644 --- a/yarn-project/simulator/src/avm/avm_gas.ts +++ b/yarn-project/simulator/src/avm/avm_gas.ts @@ -123,6 +123,7 @@ const BaseGasCosts: Record = { [Opcode.SHA256]: DefaultBaseGasCost, [Opcode.PEDERSEN]: DefaultBaseGasCost, [Opcode.ECADD]: DefaultBaseGasCost, + [Opcode.MSM]: DefaultBaseGasCost, // Conversions [Opcode.TORADIXLE]: DefaultBaseGasCost, }; diff --git a/yarn-project/simulator/src/avm/avm_simulator.test.ts b/yarn-project/simulator/src/avm/avm_simulator.test.ts index f1e8c98fb90..1614305b0be 100644 --- a/yarn-project/simulator/src/avm/avm_simulator.test.ts +++ b/yarn-project/simulator/src/avm/avm_simulator.test.ts @@ -108,6 +108,20 @@ describe('AVM simulator: transpiled Noir contracts', () => { expect(results.output).toEqual([g3.x, g3.y, Fr.ZERO]); }); + it('variable msm operations', async () => { + const context = initContext(); + + const bytecode = getAvmTestContractBytecode('variable_base_msm'); + const results = await new AvmSimulator(context).executeBytecode(bytecode); + + expect(results.reverted).toBe(false); + const grumpkin = new Grumpkin(); + const g3 = grumpkin.mul(grumpkin.generator(), new Fq(3)); + const g20 = grumpkin.mul(grumpkin.generator(), new Fq(20)); + const expectedResult = grumpkin.add(g3, g20); + expect(results.output).toEqual([expectedResult.x, expectedResult.y, Fr.ZERO]); + }); + describe('U128 addition and overflows', () => { it('U128 addition', async () => { const calldata: Fr[] = [ diff --git a/yarn-project/simulator/src/avm/journal/journal.ts b/yarn-project/simulator/src/avm/journal/journal.ts index 6db4376f6d5..dd028a63db9 100644 --- a/yarn-project/simulator/src/avm/journal/journal.ts +++ b/yarn-project/simulator/src/avm/journal/journal.ts @@ -149,15 +149,6 @@ export class AvmPersistableStateManager { this.publicStorage.write(storageAddress, slot, value); // TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit - // The current info to the kernel clears any previous read or write request. - this.transitionalExecutionResult.contractStorageReads = - this.transitionalExecutionResult.contractStorageReads.filter( - read => !read.storageSlot.equals(slot) || !read.contractAddress!.equals(storageAddress), - ); - this.transitionalExecutionResult.contractStorageUpdateRequests = - this.transitionalExecutionResult.contractStorageUpdateRequests.filter( - update => !update.storageSlot.equals(slot) || !update.contractAddress!.equals(storageAddress), - ); this.transitionalExecutionResult.contractStorageUpdateRequests.push( new ContractStorageUpdateRequest(slot, value, this.trace.accessCounter, storageAddress), ); @@ -180,17 +171,9 @@ export class AvmPersistableStateManager { ); // TRANSITIONAL: This should be removed once the kernel handles and entire enqueued call per circuit - // The current info to the kernel kernel does not consider cached reads. - if (!cached) { - // The current info to the kernel removes any previous reads to the same slot. - this.transitionalExecutionResult.contractStorageReads = - this.transitionalExecutionResult.contractStorageReads.filter( - read => !read.storageSlot.equals(slot) || !read.contractAddress!.equals(storageAddress), - ); - this.transitionalExecutionResult.contractStorageReads.push( - new ContractStorageRead(slot, value, this.trace.accessCounter, storageAddress), - ); - } + this.transitionalExecutionResult.contractStorageReads.push( + new ContractStorageRead(slot, value, this.trace.accessCounter, storageAddress), + ); // We want to keep track of all performed reads (even reverted ones) this.trace.tracePublicStorageRead(storageAddress, slot, value, exists, cached); diff --git a/yarn-project/simulator/src/avm/opcodes/external_calls.ts b/yarn-project/simulator/src/avm/opcodes/external_calls.ts index 9ccc88d362e..20f72557b3c 100644 --- a/yarn-project/simulator/src/avm/opcodes/external_calls.ts +++ b/yarn-project/simulator/src/avm/opcodes/external_calls.ts @@ -94,6 +94,11 @@ abstract class ExternalCall extends Instruction { const oldStyleExecution = createPublicExecution(startSideEffectCounter, nestedContext.environment, calldata); const simulator = new AvmSimulator(nestedContext); const nestedCallResults: AvmContractCallResults = await simulator.execute(); + const functionName = + (await nestedContext.persistableState.hostStorage.contractsDb.getDebugFunctionName( + nestedContext.environment.address, + nestedContext.environment.temporaryFunctionSelector, + )) ?? `${nestedContext.environment.address}:${nestedContext.environment.temporaryFunctionSelector}`; const pxResults = convertAvmResultsToPxResult( nestedCallResults, startSideEffectCounter, @@ -101,6 +106,7 @@ abstract class ExternalCall extends Instruction { Gas.from(allocatedGas), nestedContext, simulator.getBytecode(), + functionName, ); // store the old PublicExecutionResult object to maintain a recursive data structure for the old kernel context.persistableState.transitionalExecutionResult.nestedExecutions.push(pxResults); diff --git a/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.test.ts b/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.test.ts new file mode 100644 index 00000000000..861d9b4ec71 --- /dev/null +++ b/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.test.ts @@ -0,0 +1,130 @@ +import { Fq, Fr } from '@aztec/circuits.js'; +import { Grumpkin } from '@aztec/circuits.js/barretenberg'; + +import { type AvmContext } from '../avm_context.js'; +import { Field, type MemoryValue, Uint8, Uint32 } from '../avm_memory_types.js'; +import { initContext } from '../fixtures/index.js'; +import { MultiScalarMul } from './multi_scalar_mul.js'; + +describe('MultiScalarMul Opcode', () => { + let context: AvmContext; + + beforeEach(async () => { + context = initContext(); + }); + it('Should (de)serialize correctly', () => { + const buf = Buffer.from([ + MultiScalarMul.opcode, // opcode + 7, // indirect + ...Buffer.from('12345678', 'hex'), // pointsOffset + ...Buffer.from('23456789', 'hex'), // scalars Offset + ...Buffer.from('3456789a', 'hex'), // outputOffset + ...Buffer.from('456789ab', 'hex'), // pointsLengthOffset + ]); + const inst = new MultiScalarMul( + /*indirect=*/ 7, + /*pointsOffset=*/ 0x12345678, + /*scalarsOffset=*/ 0x23456789, + /*outputOffset=*/ 0x3456789a, + /*pointsLengthOffset=*/ 0x456789ab, + ); + + expect(MultiScalarMul.deserialize(buf)).toEqual(inst); + expect(inst.serialize()).toEqual(buf); + }); + + it('Should perform msm correctly - direct', async () => { + const indirect = 0; + const grumpkin = new Grumpkin(); + // We need to ensure points are actually on curve, so we just use the generator + // In future we could use a random point, for now we create an array of [G, 2G, 3G] + const points = Array.from({ length: 3 }, (_, i) => grumpkin.mul(grumpkin.generator(), new Fq(i + 1))); + + // Pick some big scalars to test the edge cases + const scalars = [new Fq(Fq.MODULUS - 1n), new Fq(Fq.MODULUS - 2n), new Fq(1n)]; + const pointsReadLength = points.length * 3; // multiplied by 3 since we will store them as triplet in avm memory + const scalarsLength = scalars.length * 2; // multiplied by 2 since we will store them as lo and hi limbs in avm memory + // Transform the points and scalars into the format that we will write to memory + // We just store the x and y coordinates here, and handle the infinities when we write to memory + const storedScalars: Field[] = scalars.flatMap(s => [new Field(s.low), new Field(s.high)]); + // Points are stored as [x1, y1, inf1, x2, y2, inf2, ...] where the types are [Field, Field, Uint8, Field, Field, Uint8, ...] + const storedPoints: MemoryValue[] = points + .map(p => p.toFieldsWithInf()) + .flatMap(([x, y, inf]) => [new Field(x), new Field(y), new Uint8(inf.toNumber())]); + const pointsOffset = 0; + context.machineState.memory.setSlice(pointsOffset, storedPoints); + // Store scalars + const scalarsOffset = pointsOffset + pointsReadLength; + context.machineState.memory.setSlice(scalarsOffset, storedScalars); + // Store length of points to read + const pointsLengthOffset = scalarsOffset + scalarsLength; + context.machineState.memory.set(pointsLengthOffset, new Uint32(pointsReadLength)); + const outputOffset = pointsLengthOffset + 1; + + await new MultiScalarMul(indirect, pointsOffset, scalarsOffset, outputOffset, pointsLengthOffset).execute(context); + + const result = context.machineState.memory.getSlice(outputOffset, 3).map(r => r.toFr()); + + // We write it out explicitly here + let expectedResult = grumpkin.mul(points[0], scalars[0]); + expectedResult = grumpkin.add(expectedResult, grumpkin.mul(points[1], scalars[1])); + expectedResult = grumpkin.add(expectedResult, grumpkin.mul(points[2], scalars[2])); + + expect(result).toEqual([expectedResult.x, expectedResult.y, new Fr(0n)]); + }); + + it('Should perform msm correctly - indirect', async () => { + const indirect = 7; + const grumpkin = new Grumpkin(); + // We need to ensure points are actually on curve, so we just use the generator + // In future we could use a random point, for now we create an array of [G, 2G, 3G] + const points = Array.from({ length: 3 }, (_, i) => grumpkin.mul(grumpkin.generator(), new Fq(i + 1))); + + // Pick some big scalars to test the edge cases + const scalars = [new Fq(Fq.MODULUS - 1n), new Fq(Fq.MODULUS - 2n), new Fq(1n)]; + const pointsReadLength = points.length * 3; // multiplied by 3 since we will store them as triplet in avm memory + const scalarsLength = scalars.length * 2; // multiplied by 2 since we will store them as lo and hi limbs in avm memory + // Transform the points and scalars into the format that we will write to memory + // We just store the x and y coordinates here, and handle the infinities when we write to memory + const storedScalars: Field[] = scalars.flatMap(s => [new Field(s.low), new Field(s.high)]); + // Points are stored as [x1, y1, inf1, x2, y2, inf2, ...] where the types are [Field, Field, Uint8, Field, Field, Uint8, ...] + const storedPoints: MemoryValue[] = points + .map(p => p.toFieldsWithInf()) + .flatMap(([x, y, inf]) => [new Field(x), new Field(y), new Uint8(inf.toNumber())]); + const pointsOffset = 0; + context.machineState.memory.setSlice(pointsOffset, storedPoints); + // Store scalars + const scalarsOffset = pointsOffset + pointsReadLength; + context.machineState.memory.setSlice(scalarsOffset, storedScalars); + // Store length of points to read + const pointsLengthOffset = scalarsOffset + scalarsLength; + context.machineState.memory.set(pointsLengthOffset, new Uint32(pointsReadLength)); + const outputOffset = pointsLengthOffset + 1; + + // Set up the indirect pointers + const pointsIndirectOffset = outputOffset + 3; /* 3 since the output is a triplet */ + const scalarsIndirectOffset = pointsIndirectOffset + 1; + const outputIndirectOffset = scalarsIndirectOffset + 1; + + context.machineState.memory.set(pointsIndirectOffset, new Uint32(pointsOffset)); + context.machineState.memory.set(scalarsIndirectOffset, new Uint32(scalarsOffset)); + context.machineState.memory.set(outputIndirectOffset, new Uint32(outputOffset)); + + await new MultiScalarMul( + indirect, + pointsIndirectOffset, + scalarsIndirectOffset, + outputIndirectOffset, + pointsLengthOffset, + ).execute(context); + + const result = context.machineState.memory.getSlice(outputOffset, 3).map(r => r.toFr()); + + // We write it out explicitly here + let expectedResult = grumpkin.mul(points[0], scalars[0]); + expectedResult = grumpkin.add(expectedResult, grumpkin.mul(points[1], scalars[1])); + expectedResult = grumpkin.add(expectedResult, grumpkin.mul(points[2], scalars[2])); + + expect(result).toEqual([expectedResult.x, expectedResult.y, new Fr(0n)]); + }); +}); diff --git a/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.ts b/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.ts new file mode 100644 index 00000000000..5c9ffe87e20 --- /dev/null +++ b/yarn-project/simulator/src/avm/opcodes/multi_scalar_mul.ts @@ -0,0 +1,114 @@ +import { Fq, Point } from '@aztec/circuits.js'; +import { Grumpkin } from '@aztec/circuits.js/barretenberg'; + +import { strict as assert } from 'assert'; + +import { type AvmContext } from '../avm_context.js'; +import { Field, TypeTag } from '../avm_memory_types.js'; +import { InstructionExecutionError } from '../errors.js'; +import { Opcode, OperandType } from '../serialization/instruction_serialization.js'; +import { Addressing } from './addressing_mode.js'; +import { Instruction } from './instruction.js'; + +export class MultiScalarMul extends Instruction { + static type: string = 'MultiScalarMul'; + static readonly opcode: Opcode = Opcode.MSM; + + // Informs (de)serialization. See Instruction.deserialize. + static readonly wireFormat: OperandType[] = [ + OperandType.UINT8 /* opcode */, + OperandType.UINT8 /* indirect */, + OperandType.UINT32 /* points vector offset */, + OperandType.UINT32 /* scalars vector offset */, + OperandType.UINT32 /* output offset (fixed triplet) */, + OperandType.UINT32 /* points length offset */, + ]; + + constructor( + private indirect: number, + private pointsOffset: number, + private scalarsOffset: number, + private outputOffset: number, + private pointsLengthOffset: number, + ) { + super(); + } + + public async execute(context: AvmContext): Promise { + const memory = context.machineState.memory.track(this.type); + // Resolve indirects + const [pointsOffset, scalarsOffset, outputOffset] = Addressing.fromWire(this.indirect).resolve( + [this.pointsOffset, this.scalarsOffset, this.outputOffset], + memory, + ); + + // Length of the points vector should be U32 + memory.checkTag(TypeTag.UINT32, this.pointsLengthOffset); + // Get the size of the unrolled (x, y , inf) points vector + const pointsReadLength = memory.get(this.pointsLengthOffset).toNumber(); + assert(pointsReadLength % 3 === 0, 'Points vector offset should be a multiple of 3'); + // Divide by 3 since each point is represented as a triplet to get the number of points + const numPoints = pointsReadLength / 3; + // The tag for each triplet will be (Field, Field, Uint8) + for (let i = 0; i < numPoints; i++) { + const offset = pointsOffset + i * 3; + // Check (Field, Field) + memory.checkTagsRange(TypeTag.FIELD, offset, 2); + // Check Uint8 (inf flag) + memory.checkTag(TypeTag.UINT8, offset + 2); + } + // Get the unrolled (x, y, inf) representing the points + const pointsVector = memory.getSlice(pointsOffset, pointsReadLength); + + // The size of the scalars vector is twice the NUMBER of points because of the scalar limb decomposition + const scalarReadLength = numPoints * 2; + // Consume gas prior to performing work + const memoryOperations = { + reads: 1 + pointsReadLength + scalarReadLength /* points and scalars */, + writes: 3 /* output triplet */, + indirect: this.indirect, + }; + context.machineState.consumeGas(this.gasCost(memoryOperations)); + // Get the unrolled scalar (lo & hi) representing the scalars + const scalarsVector = memory.getSlice(scalarsOffset, scalarReadLength); + memory.checkTagsRange(TypeTag.FIELD, scalarsOffset, scalarReadLength); + + // Now we need to reconstruct the points and scalars into something we can operate on. + const grumpkinPoints: Point[] = []; + for (let i = 0; i < numPoints; i++) { + const p: Point = new Point(pointsVector[3 * i].toFr(), pointsVector[3 * i + 1].toFr()); + // Include this later when we have a standard for representing infinity + // const isInf = pointsVector[i + 2].toBoolean(); + + if (!p.isOnGrumpkin()) { + throw new InstructionExecutionError(`Point ${p.toString()} is not on the curve.`); + } + grumpkinPoints.push(p); + } + // The scalars are read from memory as Fr elements, which are limbs of Fq elements + // So we need to reconstruct them before performing the scalar multiplications + const scalarFqVector: Fq[] = []; + for (let i = 0; i < numPoints; i++) { + const scalarLo = scalarsVector[2 * i].toFr(); + const scalarHi = scalarsVector[2 * i + 1].toFr(); + const fqScalar = Fq.fromHighLow(scalarHi, scalarLo); + scalarFqVector.push(fqScalar); + } + // TODO: Is there an efficient MSM implementation in ts that we can replace this by? + const grumpkin = new Grumpkin(); + // Zip the points and scalars into pairs + const [firstBaseScalarPair, ...rest]: Array<[Point, Fq]> = grumpkinPoints.map((p, idx) => [p, scalarFqVector[idx]]); + // Fold the points and scalars into a single point + // We have to ensure get the first point, since the identity element (point at infinity) isn't quite working in ts + const outputPoint = rest.reduce( + (acc, curr) => grumpkin.add(acc, grumpkin.mul(curr[0], curr[1])), + grumpkin.mul(firstBaseScalarPair[0], firstBaseScalarPair[1]), + ); + const output = outputPoint.toFieldsWithInf().map(f => new Field(f)); + + memory.setSlice(outputOffset, output); + + memory.assert(memoryOperations); + context.machineState.incrementPc(); + } +} diff --git a/yarn-project/simulator/src/avm/serialization/bytecode_serialization.ts b/yarn-project/simulator/src/avm/serialization/bytecode_serialization.ts index 0cf22ba0a5c..f3afe05e088 100644 --- a/yarn-project/simulator/src/avm/serialization/bytecode_serialization.ts +++ b/yarn-project/simulator/src/avm/serialization/bytecode_serialization.ts @@ -53,6 +53,7 @@ import { Version, Xor, } from '../opcodes/index.js'; +import { MultiScalarMul } from '../opcodes/multi_scalar_mul.js'; import { BufferCursor } from './buffer_cursor.js'; import { Opcode } from './instruction_serialization.js'; @@ -143,6 +144,7 @@ const INSTRUCTION_SET = () => [Poseidon2.opcode, Poseidon2], [Sha256.opcode, Sha256], [Pedersen.opcode, Pedersen], + [MultiScalarMul.opcode, MultiScalarMul], // Conversions [ToRadixLE.opcode, ToRadixLE], ]); diff --git a/yarn-project/simulator/src/avm/serialization/instruction_serialization.ts b/yarn-project/simulator/src/avm/serialization/instruction_serialization.ts index d8ccbd91840..0a4ee888fcf 100644 --- a/yarn-project/simulator/src/avm/serialization/instruction_serialization.ts +++ b/yarn-project/simulator/src/avm/serialization/instruction_serialization.ts @@ -77,6 +77,7 @@ export enum Opcode { SHA256, // temp - may be removed, but alot of contracts rely on it PEDERSEN, // temp - may be removed, but alot of contracts rely on it ECADD, + MSM, // Conversion TORADIXLE, } diff --git a/yarn-project/simulator/src/client/client_execution_context.ts b/yarn-project/simulator/src/client/client_execution_context.ts index 161a4f06c53..ab66af72af1 100644 --- a/yarn-project/simulator/src/client/client_execution_context.ts +++ b/yarn-project/simulator/src/client/client_execution_context.ts @@ -21,7 +21,7 @@ import { type TxContext, } from '@aztec/circuits.js'; import { Aes128 } from '@aztec/circuits.js/barretenberg'; -import { computePublicDataTreeLeafSlot, computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash'; +import { computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash'; import { type FunctionAbi, type FunctionArtifact, countArgumentsSize } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { pedersenHash } from '@aztec/foundation/crypto'; @@ -676,20 +676,13 @@ export class ClientExecutionContext extends ViewDataOracle { * @param numberOfElements - Number of elements to read from the starting storage slot. */ public override async storageRead(startStorageSlot: Fr, numberOfElements: number): Promise { - // TODO(#4320): This is a hack to work around not having directly access to the public data tree but - // still having access to the witnesses - const bn = await this.db.getBlockNumber(); - const values = []; for (let i = 0n; i < numberOfElements; i++) { const storageSlot = new Fr(startStorageSlot.value + i); - const leafSlot = computePublicDataTreeLeafSlot(this.callContext.storageContractAddress, storageSlot); - const witness = await this.db.getPublicDataTreeWitness(bn, leafSlot); - if (!witness) { - throw new Error(`No witness for slot ${storageSlot.toString()}`); - } - const value = witness.leafPreimage.value; + + const value = await this.aztecNode.getPublicStorageAt(this.callContext.storageContractAddress, storageSlot); this.log.debug(`Oracle storage read: slot=${storageSlot.toString()} value=${value}`); + values.push(value); } return values; diff --git a/yarn-project/simulator/src/client/execution_note_cache.ts b/yarn-project/simulator/src/client/execution_note_cache.ts index 325e0b8f80b..3615b012c99 100644 --- a/yarn-project/simulator/src/client/execution_note_cache.ts +++ b/yarn-project/simulator/src/client/execution_note_cache.ts @@ -63,7 +63,6 @@ export class ExecutionNoteCache { nullifiedNoteHashCounter = note.counter; this.newNotes.set(contractAddress.toBigInt(), notes); } - return nullifiedNoteHashCounter; } diff --git a/yarn-project/simulator/src/client/index.ts b/yarn-project/simulator/src/client/index.ts index 60fcf15d4a9..bb30eff1312 100644 --- a/yarn-project/simulator/src/client/index.ts +++ b/yarn-project/simulator/src/client/index.ts @@ -1,3 +1,5 @@ export * from './simulator.js'; export * from './db_oracle.js'; export * from './execution_result.js'; +export * from './pick_notes.js'; +export * from './execution_note_cache.js'; diff --git a/yarn-project/simulator/src/mocks/fixtures.ts b/yarn-project/simulator/src/mocks/fixtures.ts index 088cdec820a..9c51ebbc184 100644 --- a/yarn-project/simulator/src/mocks/fixtures.ts +++ b/yarn-project/simulator/src/mocks/fixtures.ts @@ -144,6 +144,7 @@ export class PublicExecutionResultBuilder { transactionFee: Fr.ZERO, calldata: [], avmHints: AvmExecutionHints.empty(), + functionName: 'unknown', ...overrides, }; } diff --git a/yarn-project/simulator/src/public/abstract_phase_manager.ts b/yarn-project/simulator/src/public/abstract_phase_manager.ts index 3dd7016612d..1b2833e5875 100644 --- a/yarn-project/simulator/src/public/abstract_phase_manager.ts +++ b/yarn-project/simulator/src/public/abstract_phase_manager.ts @@ -77,6 +77,7 @@ export const PhaseIsRevertible: Record = { }; export type PublicProvingInformation = { + functionName: string; // informational only calldata: Fr[]; bytecode: Buffer; inputs: PublicKernelCircuitPrivateInputs; @@ -89,6 +90,7 @@ export function makeAvmProvingRequest( ): AvmProvingRequest { return { type: AVM_REQUEST, + functionName: info.functionName, bytecode: info.bytecode, calldata: info.calldata, avmHints: info.avmHints, @@ -282,15 +284,17 @@ export abstract class AbstractPhaseManager { const functionSelector = result.execution.functionSelector.toString(); if (result.reverted && !result.revertReason) { throw new Error( - `Simulation of ${result.execution.contractAddress.toString()}:${functionSelector} reverted with no reason.`, + `Simulation of ${result.execution.contractAddress.toString()}:${functionSelector}(${ + result.functionName + }) reverted with no reason.`, ); } if (result.reverted && !PhaseIsRevertible[this.phase]) { this.log.debug( - `Simulation error on ${result.execution.contractAddress.toString()}:${functionSelector} with reason: ${ - result.revertReason - }`, + `Simulation error on ${result.execution.contractAddress.toString()}:${functionSelector}(${ + result.functionName + }) with reason: ${result.revertReason}`, ); throw result.revertReason; } @@ -302,7 +306,9 @@ export abstract class AbstractPhaseManager { // Simulate the public kernel circuit. this.log.debug( - `Running public kernel circuit for ${result.execution.contractAddress.toString()}:${functionSelector}`, + `Running public kernel circuit for ${result.execution.contractAddress.toString()}:${functionSelector}(${ + result.functionName + })`, ); const callData = await this.getPublicCallData(result, isExecutionRequest); const [privateInputs, publicInputs] = await this.runKernelCircuit(kernelPublicOutput, callData); @@ -310,6 +316,7 @@ export abstract class AbstractPhaseManager { // Capture the inputs for later proving in the AVM and kernel. const publicProvingInformation: PublicProvingInformation = { + functionName: result.functionName, calldata: result.calldata, bytecode: result.bytecode!, inputs: privateInputs, @@ -322,7 +329,9 @@ export abstract class AbstractPhaseManager { // but the kernel carries the reverted flag forward. But if the simulator reverts, so should the kernel. if (result.reverted && kernelPublicOutput.revertCode.isOK()) { throw new Error( - `Public kernel circuit did not revert on ${result.execution.contractAddress.toString()}:${functionSelector}, but simulator did.`, + `Public kernel circuit did not revert on ${result.execution.contractAddress.toString()}:${functionSelector}(${ + result.functionName + }), but simulator did.`, ); } @@ -330,9 +339,9 @@ export abstract class AbstractPhaseManager { // So safely return the revert reason and the kernel output (which has had its revertible side effects dropped) if (result.reverted) { this.log.debug( - `Reverting on ${result.execution.contractAddress.toString()}:${functionSelector} with reason: ${ - result.revertReason - }`, + `Reverting on ${result.execution.contractAddress.toString()}:${functionSelector}(${ + result.functionName + }) with reason: ${result.revertReason}`, ); // TODO(@spalladino): Check gasUsed is correct. The AVM should take care of setting gasLeft to zero upon a revert. return { diff --git a/yarn-project/simulator/src/public/execution.ts b/yarn-project/simulator/src/public/execution.ts index e87eafcba4d..2d28731f621 100644 --- a/yarn-project/simulator/src/public/execution.ts +++ b/yarn-project/simulator/src/public/execution.ts @@ -9,11 +9,8 @@ import { type NoteHash, type Nullifier, type PublicCallRequest, - PublicDataRead, - PublicDataUpdateRequest, type ReadRequest, } from '@aztec/circuits.js'; -import { computePublicDataTreeLeafSlot, computePublicDataTreeValue } from '@aztec/circuits.js/hash'; import { type Gas } from '../avm/avm_gas.js'; @@ -80,6 +77,8 @@ export interface PublicExecutionResult { calldata: Fr[]; /** Hints for proving AVM execution. */ avmHints: AvmExecutionHints; + /** The name of the function that was executed. Only used for logging. */ + functionName: string; } /** @@ -98,72 +97,6 @@ export function isPublicExecutionResult( return 'execution' in input && input.execution !== undefined; } -/** - * Collect all public storage reads across all nested executions - * and convert them to PublicDataReads (to match kernel output). - * @param execResult - The topmost execution result. - * @returns All public data reads (in execution order). - */ -export function collectPublicDataReads(execResult: PublicExecutionResult): PublicDataRead[] { - // HACK(#1622): part of temporary hack - may be able to remove this function after public state ordering is fixed - const thisExecPublicDataReads = execResult.contractStorageReads.map(read => - contractStorageReadToPublicDataRead(read), - ); - const unsorted = [ - ...thisExecPublicDataReads, - ...[...execResult.nestedExecutions].flatMap(result => collectPublicDataReads(result)), - ]; - return unsorted.sort((a, b) => a.sideEffectCounter! - b.sideEffectCounter!); -} - -/** - * Collect all public storage update requests across all nested executions - * and convert them to PublicDataUpdateRequests (to match kernel output). - * @param execResult - The topmost execution result. - * @returns All public data reads (in execution order). - */ -export function collectPublicDataUpdateRequests(execResult: PublicExecutionResult): PublicDataUpdateRequest[] { - // HACK(#1622): part of temporary hack - may be able to remove this function after public state ordering is fixed - const thisExecPublicDataUpdateRequests = execResult.contractStorageUpdateRequests.map(update => - contractStorageUpdateRequestToPublicDataUpdateRequest(update), - ); - const unsorted = [ - ...thisExecPublicDataUpdateRequests, - ...[...execResult.nestedExecutions].flatMap(result => collectPublicDataUpdateRequests(result)), - ]; - return unsorted.sort((a, b) => a.sideEffectCounter! - b.sideEffectCounter!); -} - -/** - * Convert a Contract Storage Read to a Public Data Read. - * @param read - the contract storage read to convert - * @param contractAddress - the contract address of the read - * @returns The public data read. - */ -function contractStorageReadToPublicDataRead(read: ContractStorageRead): PublicDataRead { - return new PublicDataRead( - computePublicDataTreeLeafSlot(read.contractAddress!, read.storageSlot), - computePublicDataTreeValue(read.currentValue), - read.sideEffectCounter!, - ); -} - -/** - * Convert a Contract Storage Update Request to a Public Data Update Request. - * @param update - the contract storage update request to convert - * @param contractAddress - the contract address of the data update request. - * @returns The public data update request. - */ -function contractStorageUpdateRequestToPublicDataUpdateRequest( - update: ContractStorageUpdateRequest, -): PublicDataUpdateRequest { - return new PublicDataUpdateRequest( - computePublicDataTreeLeafSlot(update.contractAddress!, update.storageSlot), - computePublicDataTreeValue(update.newValue), - update.sideEffectCounter!, - ); -} - /** * Checks whether the child execution result is valid for a static call (no state modifications). * @param executionResult - The execution result of a public function diff --git a/yarn-project/simulator/src/public/executor.ts b/yarn-project/simulator/src/public/executor.ts index fde6b655eeb..45885d23de6 100644 --- a/yarn-project/simulator/src/public/executor.ts +++ b/yarn-project/simulator/src/public/executor.ts @@ -43,7 +43,7 @@ export class PublicExecutor { const address = execution.contractAddress; const selector = execution.functionSelector; const startGas = availableGas; - const fnName = await this.contractsDb.getDebugFunctionName(address, selector); + const fnName = (await this.contractsDb.getDebugFunctionName(address, selector)) ?? `${address}:${selector}`; PublicExecutor.log.verbose(`[AVM] Executing public external function ${fnName}.`); const timer = new Timer(); @@ -83,7 +83,7 @@ export class PublicExecutor { }.`, { eventName: 'avm-simulation', - appCircuitName: fnName ?? 'unknown', + appCircuitName: fnName, duration: timer.ms(), bytecodeSize: bytecode!.length, } satisfies AvmSimulationStats, @@ -96,6 +96,7 @@ export class PublicExecutor { startGas, avmContext, bytecode, + fnName, ); // TODO(https://github.com/AztecProtocol/aztec-packages/issues/5818): is this really needed? diff --git a/yarn-project/simulator/src/public/index.ts b/yarn-project/simulator/src/public/index.ts index c30b7b1079d..933b918f4c9 100644 --- a/yarn-project/simulator/src/public/index.ts +++ b/yarn-project/simulator/src/public/index.ts @@ -1,12 +1,6 @@ export * from './abstract_phase_manager.js'; export * from './db_interfaces.js'; -export { - collectPublicDataReads, - collectPublicDataUpdateRequests, - isPublicExecutionResult, - type PublicExecution, - type PublicExecutionResult, -} from './execution.js'; +export { isPublicExecutionResult, type PublicExecution, type PublicExecutionResult } from './execution.js'; export { PublicExecutor } from './executor.js'; export * from './fee_payment.js'; export { HintsBuilder } from './hints_builder.js'; diff --git a/yarn-project/simulator/src/public/transitional_adaptors.ts b/yarn-project/simulator/src/public/transitional_adaptors.ts index 21d26e0810c..36d0f2ade12 100644 --- a/yarn-project/simulator/src/public/transitional_adaptors.ts +++ b/yarn-project/simulator/src/public/transitional_adaptors.ts @@ -114,12 +114,14 @@ export function convertAvmResultsToPxResult( startGas: Gas, endAvmContext: AvmContext, bytecode: Buffer | undefined, + functionName: string, ): PublicExecutionResult { const endPersistableState = endAvmContext.persistableState; const endMachineState = endAvmContext.machineState; return { ...endPersistableState.transitionalExecutionResult, // includes nestedExecutions + functionName: functionName, execution: fromPx, returnValues: avmResult.output, startSideEffectCounter: new Fr(startSideEffectCounter), diff --git a/yarn-project/txe/.eslintrc.cjs b/yarn-project/txe/.eslintrc.cjs new file mode 100644 index 00000000000..e659927475c --- /dev/null +++ b/yarn-project/txe/.eslintrc.cjs @@ -0,0 +1 @@ +module.exports = require('@aztec/foundation/eslint'); diff --git a/yarn-project/txe/package.json b/yarn-project/txe/package.json new file mode 100644 index 00000000000..5658cd3b454 --- /dev/null +++ b/yarn-project/txe/package.json @@ -0,0 +1,82 @@ +{ + "name": "@aztec/txe", + "version": "0.0.0", + "type": "module", + "exports": "./dest/index.js", + "bin": "./dest/bin/index.js", + "typedocOptions": { + "entryPoints": [ + "./src/index.ts" + ], + "name": "TXE", + "tsconfig": "./tsconfig.json" + }, + "scripts": { + "build": "yarn clean && tsc -b", + "build:dev": "tsc -b --watch", + "clean": "rm -rf ./dest .tsbuildinfo", + "formatting": "run -T prettier --check ./src && run -T eslint ./src", + "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src", + "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests", + "start": "DEBUG='aztec:*' && node ./dest/bin/index.js" + }, + "inherits": [ + "../package.common.json" + ], + "jest": { + "moduleNameMapper": { + "^(\\.{1,2}/.*)\\.[cm]?js$": "$1" + }, + "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$", + "rootDir": "./src", + "workerThreads": true, + "transform": { + "^.+\\.tsx?$": [ + "@swc/jest" + ] + }, + "extensionsToTreatAsEsm": [ + ".ts" + ], + "reporters": [ + [ + "default", + { + "summaryThreshold": 9999 + } + ] + ] + }, + "dependencies": { + "@aztec/archiver": "workspace:^", + "@aztec/aztec.js": "workspace:^", + "@aztec/circuit-types": "workspace:^", + "@aztec/circuits.js": "workspace:^", + "@aztec/foundation": "workspace:^", + "@aztec/key-store": "workspace:^", + "@aztec/kv-store": "workspace:^", + "@aztec/noir-contracts.js": "workspace:^", + "@aztec/pxe": "workspace:^", + "@aztec/simulator": "workspace:^", + "@aztec/types": "workspace:^", + "@aztec/world-state": "workspace:^" + }, + "devDependencies": { + "@jest/globals": "^29.5.0", + "@types/jest": "^29.5.0", + "@types/node": "^18.7.23", + "jest": "^29.5.0", + "jest-mock-extended": "^3.0.3", + "ts-node": "^10.9.1", + "typescript": "^5.0.4" + }, + "files": [ + "dest", + "src", + "!*.test.*" + ], + "types": "./dest/index.d.ts", + "engines": { + "node": ">=18" + } +} diff --git a/yarn-project/txe/src/bin/index.ts b/yarn-project/txe/src/bin/index.ts new file mode 100644 index 00000000000..14934762159 --- /dev/null +++ b/yarn-project/txe/src/bin/index.ts @@ -0,0 +1,86 @@ +#!/usr/bin/env -S node --no-warnings +import { JsonRpcServer } from '@aztec/foundation/json-rpc/server'; +import { type Logger, createDebugLogger } from '@aztec/foundation/log'; + +import http from 'http'; + +import { TXEService } from '../txe_service/txe_service.js'; +import { type ForeignCallResult, toForeignCallResult } from '../util/encoding.js'; + +const { TXE_PORT = 8080 } = process.env; + +const logger = createDebugLogger('aztec:txe_service'); + +const TXESessions = new Map(); + +type MethodNames = { + [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never; +}[keyof T]; + +type TXEForeignCallInput = { + session_id: number; + function: MethodNames | 'reset'; + inputs: any[]; +}; + +class TXEDispatcher { + constructor(private logger: Logger) {} + + // eslint-disable-next-line camelcase + async resolve_foreign_call({ + session_id: sessionId, + function: functionName, + inputs, + }: TXEForeignCallInput): Promise { + this.logger.debug( + `Calling ${functionName} with inputs: ${JSON.stringify(inputs, null, 2)} on session ${sessionId}`, + ); + + if (!TXESessions.has(sessionId) && functionName != 'reset') { + this.logger.debug(`Creating new session ${sessionId}`); + TXESessions.set(sessionId, await TXEService.init(logger)); + } + + if (functionName === 'reset') { + TXESessions.delete(sessionId) && + this.logger.debug(`Called reset on session ${sessionId}, yeeting it out of existence`); + return toForeignCallResult([]); + } else { + const txeService = TXESessions.get(sessionId); + const response = await (txeService as any)[functionName](...inputs); + this.logger.debug( + `${sessionId}:${functionName}(${JSON.stringify(inputs, null, 2)}) -> ${JSON.stringify(response, null, 2)}`, + ); + return response; + } + } +} + +/** + * Creates an http server that forwards calls to the TXE and starts it on the given port. + * @param txeService - TXE that answers queries to the created HTTP server. + * @param port - Port to listen in. + * @returns A running http server. + */ +export function startTXEHttpServer(dispatcher: TXEDispatcher, port: string | number): http.Server { + const txeServer = new JsonRpcServer(dispatcher, {}, {}, ['init']); + + const app = txeServer.getApp(); + const httpServer = http.createServer(app.callback()); + httpServer.listen(port); + + return httpServer; +} + +/** + * Create and start a new TXE HTTP Server + */ +function main() { + logger.info(`Setting up TXE...`); + + startTXEHttpServer(new TXEDispatcher(logger), TXE_PORT); + + logger.info(`TXE listening on port ${TXE_PORT}`); +} + +main(); diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts new file mode 100644 index 00000000000..09115f3ebab --- /dev/null +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -0,0 +1,596 @@ +import { + L1NotePayload, + MerkleTreeId, + Note, + type NoteStatus, + NullifierMembershipWitness, + PublicDataWitness, + PublicDataWrite, + TaggedLog, + type UnencryptedL2Log, +} from '@aztec/circuit-types'; +import { type CircuitWitnessGenerationStats } from '@aztec/circuit-types/stats'; +import { + type CompleteAddress, + FunctionData, + type Header, + type KeyValidationRequest, + NULLIFIER_SUBTREE_HEIGHT, + type NULLIFIER_TREE_HEIGHT, + type NullifierLeafPreimage, + PUBLIC_DATA_SUBTREE_HEIGHT, + type PUBLIC_DATA_TREE_HEIGHT, + PrivateCallStackItem, + PrivateCircuitPublicInputs, + PrivateContextInputs, + type PublicCallRequest, + PublicDataTreeLeaf, + type PublicDataTreeLeafPreimage, + computeContractClassId, + deriveKeys, + getContractClassFromArtifact, +} from '@aztec/circuits.js'; +import { Aes128 } from '@aztec/circuits.js/barretenberg'; +import { computePublicDataTreeLeafSlot, siloNoteHash, siloNullifier } from '@aztec/circuits.js/hash'; +import { type ContractArtifact, type FunctionAbi, FunctionSelector, countArgumentsSize } from '@aztec/foundation/abi'; +import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { Fr, GrumpkinScalar, type Point } from '@aztec/foundation/fields'; +import { type Logger, applyStringFormatting } from '@aztec/foundation/log'; +import { Timer } from '@aztec/foundation/timer'; +import { type KeyStore } from '@aztec/key-store'; +import { ContractDataOracle } from '@aztec/pxe'; +import { + ExecutionError, + type ExecutionNoteCache, + type MessageLoadOracleInputs, + type NoteData, + Oracle, + type PackedValuesCache, + type TypedOracle, + acvm, + createSimulationError, + extractCallStack, + pickNotes, + toACVMWitness, + witnessMapToFields, +} from '@aztec/simulator'; +import { type ContractInstance, type ContractInstanceWithAddress } from '@aztec/types/contracts'; +import { MerkleTreeSnapshotOperationsFacade, type MerkleTrees } from '@aztec/world-state'; + +import { type TXEDatabase } from '../util/txe_database.js'; + +export class TXE implements TypedOracle { + private blockNumber = 0; + private sideEffectsCounter = 0; + private contractAddress: AztecAddress; + private msgSender: AztecAddress; + + private contractDataOracle: ContractDataOracle; + + constructor( + private logger: Logger, + private trees: MerkleTrees, + private packedValuesCache: PackedValuesCache, + private noteCache: ExecutionNoteCache, + private keyStore: KeyStore, + private txeDatabase: TXEDatabase, + ) { + this.contractDataOracle = new ContractDataOracle(txeDatabase); + this.contractAddress = AztecAddress.random(); + this.msgSender = AztecAddress.fromField(new Fr(0)); + } + + // Utils + + getMsgSender() { + return this.msgSender; + } + + setMsgSender(msgSender: Fr) { + this.msgSender = msgSender; + } + + getSideEffectsCounter() { + return this.sideEffectsCounter; + } + + setSideEffectsCounter(sideEffectsCounter: number) { + this.sideEffectsCounter = sideEffectsCounter; + } + + setContractAddress(contractAddress: AztecAddress) { + this.contractAddress = contractAddress; + } + + setBlockNumber(blockNumber: number) { + this.blockNumber = blockNumber; + } + + getTrees() { + return this.trees; + } + + getTXEDatabase() { + return this.txeDatabase; + } + + getKeyStore() { + return this.keyStore; + } + + async addContractInstance(contractInstance: ContractInstanceWithAddress) { + await this.txeDatabase.addContractInstance(contractInstance); + } + + async addContractArtifact(artifact: ContractArtifact) { + const contractClass = getContractClassFromArtifact(artifact); + await this.txeDatabase.addContractArtifact(computeContractClassId(contractClass), artifact); + } + + async getPrivateContextInputs(blockNumber: number, sideEffectsCounter = this.sideEffectsCounter) { + const trees = this.getTrees(); + const stateReference = await trees.getStateReference(true); + const inputs = PrivateContextInputs.empty(); + inputs.historicalHeader.globalVariables.blockNumber = new Fr(blockNumber); + inputs.historicalHeader.state = stateReference; + inputs.callContext.msgSender = this.msgSender; + inputs.callContext.storageContractAddress = this.contractAddress; + inputs.callContext.sideEffectCounter = sideEffectsCounter; + inputs.startSideEffectCounter = sideEffectsCounter; + return inputs; + } + + getPublicContextInputs() { + const inputs = { + functionSelector: FunctionSelector.fromField(new Fr(0)), + argsHash: new Fr(0), + isStaticCall: false, + toFields: function () { + return [this.functionSelector.toField(), this.argsHash, new Fr(this.isStaticCall)]; + }, + }; + return inputs; + } + + async avmOpcodeNullifierExists(innerNullifier: Fr, targetAddress: AztecAddress): Promise { + const nullifier = siloNullifier(targetAddress, innerNullifier!); + const db = this.trees.asLatest(); + const index = await db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer()); + return index !== undefined; + } + + async avmOpcodeEmitNullifier(nullifier: Fr) { + const db = this.trees.asLatest(); + const siloedNullifier = siloNullifier(this.contractAddress, nullifier); + await db.batchInsert(MerkleTreeId.NULLIFIER_TREE, [siloedNullifier.toBuffer()], NULLIFIER_SUBTREE_HEIGHT); + return Promise.resolve(); + } + + async avmOpcodeEmitNoteHash(innerNoteHash: Fr) { + const db = this.trees.asLatest(); + const noteHash = siloNoteHash(this.contractAddress, innerNoteHash); + await db.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, [noteHash]); + return Promise.resolve(); + } + + deriveKeys(secret: Fr) { + return deriveKeys(secret); + } + + // TypedOracle + + getBlockNumber(): Promise { + return Promise.resolve(this.blockNumber); + } + + getContractAddress(): Promise { + return Promise.resolve(this.contractAddress); + } + + getRandomField() { + return Fr.random(); + } + + packArgumentsArray(args: Fr[]): Promise { + return Promise.resolve(this.packedValuesCache.pack(args)); + } + + packReturns(returns: Fr[]): Promise { + return Promise.resolve(this.packedValuesCache.pack(returns)); + } + + unpackReturns(returnsHash: Fr): Promise { + return Promise.resolve(this.packedValuesCache.unpack(returnsHash)); + } + + getKeyValidationRequest(pkMHash: Fr): Promise { + return this.keyStore.getKeyValidationRequest(pkMHash, this.contractAddress); + } + + async getContractInstance(address: AztecAddress): Promise { + const contractInstance = await this.txeDatabase.getContractInstance(address); + if (!contractInstance) { + throw new Error(`Contract instance not found for address ${address}`); + } + return Promise.resolve(contractInstance); + } + + getMembershipWitness(_blockNumber: number, _treeId: MerkleTreeId, _leafValue: Fr): Promise { + throw new Error('Method not implemented.'); + } + + async getSiblingPath(blockNumber: number, treeId: MerkleTreeId, leafIndex: Fr) { + const committedDb = new MerkleTreeSnapshotOperationsFacade(this.trees, blockNumber); + const result = await committedDb.getSiblingPath(treeId, leafIndex.toBigInt()); + return result.toFields(); + } + + async getNullifierMembershipWitness( + blockNumber: number, + nullifier: Fr, + ): Promise { + const committedDb = new MerkleTreeSnapshotOperationsFacade(this.trees, blockNumber); + const index = await committedDb.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer()); + if (!index) { + return undefined; + } + + const leafPreimagePromise = committedDb.getLeafPreimage(MerkleTreeId.NULLIFIER_TREE, index); + const siblingPathPromise = committedDb.getSiblingPath( + MerkleTreeId.NULLIFIER_TREE, + BigInt(index), + ); + + const [leafPreimage, siblingPath] = await Promise.all([leafPreimagePromise, siblingPathPromise]); + + if (!leafPreimage) { + return undefined; + } + + return new NullifierMembershipWitness(BigInt(index), leafPreimage as NullifierLeafPreimage, siblingPath); + } + + async getPublicDataTreeWitness(blockNumber: number, leafSlot: Fr): Promise { + const committedDb = new MerkleTreeSnapshotOperationsFacade(this.trees, blockNumber); + const lowLeafResult = await committedDb.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot.toBigInt()); + if (!lowLeafResult) { + return undefined; + } else { + const preimage = (await committedDb.getLeafPreimage( + MerkleTreeId.PUBLIC_DATA_TREE, + lowLeafResult.index, + )) as PublicDataTreeLeafPreimage; + const path = await committedDb.getSiblingPath( + MerkleTreeId.PUBLIC_DATA_TREE, + lowLeafResult.index, + ); + return new PublicDataWitness(lowLeafResult.index, preimage, path); + } + } + + getLowNullifierMembershipWitness( + _blockNumber: number, + _nullifier: Fr, + ): Promise { + throw new Error('Method not implemented.'); + } + + getHeader(_blockNumber: number): Promise
{ + throw new Error('Method not implemented.'); + } + + getCompleteAddress(account: AztecAddress): Promise { + return Promise.resolve(this.txeDatabase.getAccount(account)); + } + + getAuthWitness(_messageHash: Fr): Promise { + throw new Error('Method not implemented.'); + } + + popCapsule(): Promise { + throw new Error('Method not implemented.'); + } + + getNotes( + storageSlot: Fr, + numSelects: number, + selectByIndexes: number[], + selectByOffsets: number[], + selectByLengths: number[], + selectValues: Fr[], + selectComparators: number[], + sortByIndexes: number[], + sortByOffsets: number[], + sortByLengths: number[], + sortOrder: number[], + limit: number, + offset: number, + _status: NoteStatus, + ) { + // Nullified pending notes are already removed from the list. + const pendingNotes = this.noteCache.getNotes(this.contractAddress, storageSlot); + + const notes = pickNotes(pendingNotes, { + selects: selectByIndexes.slice(0, numSelects).map((index, i) => ({ + selector: { index, offset: selectByOffsets[i], length: selectByLengths[i] }, + value: selectValues[i], + comparator: selectComparators[i], + })), + sorts: sortByIndexes.map((index, i) => ({ + selector: { index, offset: sortByOffsets[i], length: sortByLengths[i] }, + order: sortOrder[i], + })), + limit, + offset, + }); + + this.logger.debug( + `Returning ${notes.length} notes for ${this.contractAddress} at ${storageSlot}: ${notes + .map(n => `${n.nonce.toString()}:[${n.note.items.map(i => i.toString()).join(',')}]`) + .join(', ')}`, + ); + + return Promise.resolve(notes); + } + + async notifyCreatedNote(storageSlot: Fr, noteTypeId: Fr, noteItems: Fr[], innerNoteHash: Fr, counter: number) { + const note = new Note(noteItems); + this.noteCache.addNewNote( + { + contractAddress: this.contractAddress, + storageSlot, + nonce: Fr.ZERO, // Nonce cannot be known during private execution. + note, + siloedNullifier: undefined, // Siloed nullifier cannot be known for newly created note. + innerNoteHash, + }, + counter, + ); + const db = this.trees.asLatest(); + const noteHash = siloNoteHash(this.contractAddress, innerNoteHash); + await db.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, [noteHash]); + } + + async notifyNullifiedNote(innerNullifier: Fr, innerNoteHash: Fr, _counter: number) { + this.noteCache.nullifyNote(this.contractAddress, innerNullifier, innerNoteHash); + const db = this.trees.asLatest(); + const siloedNullifier = siloNullifier(this.contractAddress, innerNullifier); + await db.batchInsert(MerkleTreeId.NULLIFIER_TREE, [siloedNullifier.toBuffer()], NULLIFIER_SUBTREE_HEIGHT); + return Promise.resolve(); + } + + async checkNullifierExists(innerNullifier: Fr): Promise { + const nullifier = siloNullifier(this.contractAddress, innerNullifier!); + const db = this.trees.asLatest(); + const index = await db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer()); + return index !== undefined; + } + + getL1ToL2MembershipWitness( + _contractAddress: AztecAddress, + _messageHash: Fr, + _secret: Fr, + ): Promise> { + throw new Error('Method not implemented.'); + } + + async storageRead(startStorageSlot: Fr, numberOfElements: number): Promise { + const db = this.trees.asLatest(); + + const values = []; + for (let i = 0n; i < numberOfElements; i++) { + const storageSlot = startStorageSlot.add(new Fr(i)); + const leafSlot = computePublicDataTreeLeafSlot(this.contractAddress, storageSlot).toBigInt(); + + const lowLeafResult = await db.getPreviousValueIndex(MerkleTreeId.PUBLIC_DATA_TREE, leafSlot); + + let value = Fr.ZERO; + if (lowLeafResult && lowLeafResult.alreadyPresent) { + const preimage = (await db.getLeafPreimage( + MerkleTreeId.PUBLIC_DATA_TREE, + lowLeafResult.index, + )) as PublicDataTreeLeafPreimage; + value = preimage.value; + } + this.logger.debug(`Oracle storage read: slot=${storageSlot.toString()} value=${value}`); + values.push(value); + } + return values; + } + + async storageWrite(startStorageSlot: Fr, values: Fr[]): Promise { + const db = this.trees.asLatest(); + + const publicDataWrites = values.map((value, i) => { + const storageSlot = startStorageSlot.add(new Fr(i)); + this.logger.debug(`Oracle storage write: slot=${storageSlot.toString()} value=${value}`); + return new PublicDataWrite(computePublicDataTreeLeafSlot(this.contractAddress, storageSlot), value); + }); + await db.batchInsert( + MerkleTreeId.PUBLIC_DATA_TREE, + publicDataWrites.map(write => new PublicDataTreeLeaf(write.leafIndex, write.newValue).toBuffer()), + PUBLIC_DATA_SUBTREE_HEIGHT, + ); + return publicDataWrites.map(write => write.newValue); + } + + emitEncryptedLog(_contractAddress: AztecAddress, _randomness: Fr, _encryptedNote: Buffer, _counter: number): void { + return; + } + + emitEncryptedNoteLog(_noteHashCounter: number, _encryptedNote: Buffer, _counter: number): void { + return; + } + + computeEncryptedNoteLog( + contractAddress: AztecAddress, + storageSlot: Fr, + noteTypeId: Fr, + ovKeys: KeyValidationRequest, + ivpkM: Point, + preimage: Fr[], + ): Buffer { + const note = new Note(preimage); + const l1NotePayload = new L1NotePayload(note, contractAddress, storageSlot, noteTypeId); + const taggedNote = new TaggedLog(l1NotePayload); + + const ephSk = GrumpkinScalar.random(); + + const recipient = AztecAddress.random(); + + return taggedNote.encrypt(ephSk, recipient, ivpkM, ovKeys); + } + + emitUnencryptedLog(_log: UnencryptedL2Log, _counter: number): void { + throw new Error('Method not implemented.'); + } + + emitContractClassUnencryptedLog(_log: UnencryptedL2Log, _counter: number): Fr { + throw new Error('Method not implemented.'); + } + + async callPrivateFunction( + targetContractAddress: AztecAddress, + functionSelector: FunctionSelector, + argsHash: Fr, + sideEffectCounter: number, + _isStaticCall: boolean, + _isDelegateCall: boolean, + ): Promise { + this.logger.debug( + `Calling private function ${targetContractAddress}:${functionSelector} from ${this.contractAddress}`, + ); + // Store and modify env + const currentContractAddress = AztecAddress.fromField(this.contractAddress); + const currentMessageSender = AztecAddress.fromField(this.msgSender); + this.setMsgSender(this.contractAddress); + this.setContractAddress(targetContractAddress); + + const artifact = await this.contractDataOracle.getFunctionArtifact(targetContractAddress, functionSelector); + + const acir = artifact.bytecode; + const initialWitness = await this.getInitialWitness(artifact, argsHash, sideEffectCounter); + const acvmCallback = new Oracle(this); + const timer = new Timer(); + const acirExecutionResult = await acvm(acir, initialWitness, acvmCallback).catch((err: Error) => { + const execError = new ExecutionError( + err.message, + { + contractAddress: targetContractAddress, + functionSelector, + }, + extractCallStack(err, artifact.debug), + { cause: err }, + ); + this.logger.debug( + `Error executing private function ${targetContractAddress}:${functionSelector}\n${createSimulationError( + execError, + )}`, + ); + throw execError; + }); + const duration = timer.ms(); + const returnWitness = witnessMapToFields(acirExecutionResult.returnWitness); + const publicInputs = PrivateCircuitPublicInputs.fromFields(returnWitness); + + const initialWitnessSize = witnessMapToFields(initialWitness).length * Fr.SIZE_IN_BYTES; + this.logger.debug(`Ran external function ${targetContractAddress.toString()}:${functionSelector}`, { + circuitName: 'app-circuit', + duration, + eventName: 'circuit-witness-generation', + inputSize: initialWitnessSize, + outputSize: publicInputs.toBuffer().length, + appCircuitName: 'noname', + } satisfies CircuitWitnessGenerationStats); + + const callStackItem = new PrivateCallStackItem( + targetContractAddress, + new FunctionData(functionSelector, true), + publicInputs, + ); + // Apply side effects + this.sideEffectsCounter += publicInputs.endSideEffectCounter.toNumber(); + this.setContractAddress(currentContractAddress); + this.setMsgSender(currentMessageSender); + + return callStackItem; + } + + async getInitialWitness(abi: FunctionAbi, argsHash: Fr, sideEffectCounter: number) { + const argumentsSize = countArgumentsSize(abi); + + const args = this.packedValuesCache.unpack(argsHash); + + if (args.length !== argumentsSize) { + throw new Error('Invalid arguments size'); + } + + const privateContextInputs = await this.getPrivateContextInputs(this.blockNumber - 1, sideEffectCounter); + + const fields = [...privateContextInputs.toFields(), ...args]; + + return toACVMWitness(0, fields); + } + + callPublicFunction( + _targetContractAddress: AztecAddress, + _functionSelector: FunctionSelector, + _argsHash: Fr, + _sideEffectCounter: number, + _isStaticCall: boolean, + _isDelegateCall: boolean, + ): Promise { + throw new Error('Method not implemented.'); + } + + enqueuePublicFunctionCall( + _targetContractAddress: AztecAddress, + _functionSelector: FunctionSelector, + _argsHash: Fr, + _sideEffectCounter: number, + _isStaticCall: boolean, + _isDelegateCall: boolean, + ): Promise { + throw new Error('Method not implemented.'); + } + + setPublicTeardownFunctionCall( + _targetContractAddress: AztecAddress, + _functionSelector: FunctionSelector, + _argsHash: Fr, + _sideEffectCounter: number, + _isStaticCall: boolean, + _isDelegateCall: boolean, + ): Promise { + throw new Error('Method not implemented.'); + } + + aes128Encrypt(input: Buffer, initializationVector: Buffer, key: Buffer): Buffer { + const aes128 = new Aes128(); + return aes128.encryptBufferCBC(input, initializationVector, key); + } + + debugLog(message: string, fields: Fr[]): void { + this.logger.verbose(`debug_log ${applyStringFormatting(message, fields)}`); + } + + emitEncryptedEventLog( + _contractAddress: AztecAddress, + _randomness: Fr, + _encryptedEvent: Buffer, + _counter: number, + ): void { + return; + } + + computeEncryptedEventLog( + _contractAddress: AztecAddress, + _randomness: Fr, + _eventTypeId: Fr, + _ovKeys: KeyValidationRequest, + _ivpkM: Point, + _preimage: Fr[], + ): Buffer { + throw new Error('Method not implemented.'); + } +} diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts new file mode 100644 index 00000000000..6b53c0de1eb --- /dev/null +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -0,0 +1,522 @@ +import { L2Block, MerkleTreeId, PublicDataWrite } from '@aztec/circuit-types'; +import { + Fr, + FunctionSelector, + Header, + KeyValidationRequest, + PUBLIC_DATA_SUBTREE_HEIGHT, + Point, + PublicDataTreeLeaf, + getContractInstanceFromDeployParams, +} from '@aztec/circuits.js'; +import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash'; +import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { type Logger } from '@aztec/foundation/log'; +import { KeyStore } from '@aztec/key-store'; +import { type AztecKVStore } from '@aztec/kv-store'; +import { openTmpStore } from '@aztec/kv-store/utils'; +import { ExecutionNoteCache, PackedValuesCache, type TypedOracle } from '@aztec/simulator'; +import { MerkleTrees } from '@aztec/world-state'; + +import { TXE } from '../oracle/txe_oracle.js'; +import { + type ForeignCallArray, + type ForeignCallSingle, + fromArray, + fromSingle, + toArray, + toForeignCallResult, + toSingle, +} from '../util/encoding.js'; +import { TXEDatabase } from '../util/txe_database.js'; + +export class TXEService { + constructor(private logger: Logger, private typedOracle: TypedOracle, private store: AztecKVStore) {} + + static async init(logger: Logger) { + const store = openTmpStore(true); + const trees = await MerkleTrees.new(store, logger); + const packedValuesCache = new PackedValuesCache(); + const noteCache = new ExecutionNoteCache(); + const keyStore = new KeyStore(store); + const txeDatabase = new TXEDatabase(store); + logger.info(`TXE service initialized`); + const txe = new TXE(logger, trees, packedValuesCache, noteCache, keyStore, txeDatabase); + const service = new TXEService(logger, txe, store); + await service.timeTravel(toSingle(new Fr(1n))); + return service; + } + + // Cheatcodes + + async getPrivateContextInputs(blockNumber: ForeignCallSingle) { + const inputs = await (this.typedOracle as TXE).getPrivateContextInputs(fromSingle(blockNumber).toNumber()); + return toForeignCallResult(inputs.toFields().map(toSingle)); + } + + getPublicContextInputs() { + const inputs = (this.typedOracle as TXE).getPublicContextInputs(); + return toForeignCallResult(inputs.toFields().map(toSingle)); + } + + async timeTravel(blocks: ForeignCallSingle) { + const nBlocks = fromSingle(blocks).toNumber(); + this.logger.info(`time traveling ${nBlocks} blocks`); + const trees = (this.typedOracle as TXE).getTrees(); + for (let i = 0; i < nBlocks; i++) { + const header = Header.empty(); + const l2Block = L2Block.empty(); + header.state = await trees.getStateReference(true); + const blockNumber = await this.typedOracle.getBlockNumber(); + + header.globalVariables.blockNumber = new Fr(blockNumber); + header.state.partial.nullifierTree.root = Fr.fromBuffer( + (await trees.getTreeInfo(MerkleTreeId.NULLIFIER_TREE, true)).root, + ); + header.state.partial.noteHashTree.root = Fr.fromBuffer( + (await trees.getTreeInfo(MerkleTreeId.NOTE_HASH_TREE, true)).root, + ); + header.state.partial.publicDataTree.root = Fr.fromBuffer( + (await trees.getTreeInfo(MerkleTreeId.PUBLIC_DATA_TREE, true)).root, + ); + header.state.l1ToL2MessageTree.root = Fr.fromBuffer( + (await trees.getTreeInfo(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, true)).root, + ); + l2Block.archive.root = Fr.fromBuffer((await trees.getTreeInfo(MerkleTreeId.ARCHIVE, true)).root); + l2Block.header = header; + await trees.handleL2BlockAndMessages(l2Block, []); + (this.typedOracle as TXE).setBlockNumber(blockNumber + 1); + } + return toForeignCallResult([]); + } + + setContractAddress(address: ForeignCallSingle) { + const typedAddress = AztecAddress.fromField(fromSingle(address)); + (this.typedOracle as TXE).setContractAddress(typedAddress); + return toForeignCallResult([]); + } + + deriveKeys(secret: ForeignCallSingle) { + const keys = (this.typedOracle as TXE).deriveKeys(fromSingle(secret)); + return toForeignCallResult(keys.publicKeys.toFields().map(toSingle)); + } + + async deploy( + path: ForeignCallArray, + initializer: ForeignCallArray, + _length: ForeignCallSingle, + args: ForeignCallArray, + publicKeysHash: ForeignCallSingle, + ) { + const pathStr = fromArray(path) + .map(char => String.fromCharCode(char.toNumber())) + .join(''); + const initializerStr = fromArray(initializer) + .map(char => String.fromCharCode(char.toNumber())) + .join(''); + const decodedArgs = fromArray(args); + this.logger.debug(`Deploy ${pathStr} with ${initializerStr} and ${decodedArgs}`); + const contractModule = await import(pathStr); + // Hacky way of getting the class, the name of the Artifact is always longer + const contractClass = contractModule[Object.keys(contractModule).sort((a, b) => a.length - b.length)[0]]; + const instance = getContractInstanceFromDeployParams(contractClass.artifact, { + constructorArgs: decodedArgs, + skipArgsDecoding: true, + salt: Fr.ONE, + publicKeysHash: fromSingle(publicKeysHash), + constructorArtifact: initializerStr ? initializerStr : undefined, + deployer: AztecAddress.ZERO, + }); + + this.logger.debug(`Deployed ${contractClass.artifact.name} at ${instance.address}`); + await (this.typedOracle as TXE).addContractInstance(instance); + await (this.typedOracle as TXE).addContractArtifact(contractClass.artifact); + return toForeignCallResult([toSingle(instance.address)]); + } + + async directStorageWrite( + contractAddress: ForeignCallSingle, + startStorageSlot: ForeignCallSingle, + values: ForeignCallArray, + ) { + const trees = (this.typedOracle as TXE).getTrees(); + const startStorageSlotFr = fromSingle(startStorageSlot); + const valuesFr = fromArray(values); + const contractAddressFr = fromSingle(contractAddress); + const db = trees.asLatest(); + + const publicDataWrites = valuesFr.map((value, i) => { + const storageSlot = startStorageSlotFr.add(new Fr(i)); + this.logger.debug(`Oracle storage write: slot=${storageSlot.toString()} value=${value}`); + return new PublicDataWrite(computePublicDataTreeLeafSlot(contractAddressFr, storageSlot), value); + }); + await db.batchInsert( + MerkleTreeId.PUBLIC_DATA_TREE, + publicDataWrites.map(write => new PublicDataTreeLeaf(write.leafIndex, write.newValue).toBuffer()), + PUBLIC_DATA_SUBTREE_HEIGHT, + ); + return toForeignCallResult([toArray(publicDataWrites.map(write => write.newValue))]); + } + + async createAccount() { + const keyStore = (this.typedOracle as TXE).getKeyStore(); + const completeAddress = await keyStore.createAccount(); + const accountStore = (this.typedOracle as TXE).getTXEDatabase(); + await accountStore.setAccount(completeAddress.address, completeAddress); + this.logger.debug(`Created account ${completeAddress.address}`); + return toForeignCallResult([ + toSingle(completeAddress.address), + ...completeAddress.publicKeys.toFields().map(toSingle), + ]); + } + + async addAccount(secret: ForeignCallSingle, partialAddress: ForeignCallSingle) { + const keyStore = (this.typedOracle as TXE).getKeyStore(); + const completeAddress = await keyStore.addAccount(fromSingle(secret), fromSingle(partialAddress)); + const accountStore = (this.typedOracle as TXE).getTXEDatabase(); + await accountStore.setAccount(completeAddress.address, completeAddress); + return toForeignCallResult([ + toSingle(completeAddress.address), + ...completeAddress.publicKeys.toFields().map(toSingle), + ]); + } + + setMsgSender(msgSender: ForeignCallSingle) { + (this.typedOracle as TXE).setMsgSender(fromSingle(msgSender)); + return toForeignCallResult([]); + } + + getMsgSender() { + const msgSender = (this.typedOracle as TXE).getMsgSender(); + return toForeignCallResult([toSingle(msgSender)]); + } + + getSideEffectsCounter() { + const counter = (this.typedOracle as TXE).getSideEffectsCounter(); + return toForeignCallResult([toSingle(new Fr(counter))]); + } + + // PXE oracles + + getRandomField() { + return toForeignCallResult([toSingle(this.typedOracle.getRandomField())]); + } + + async getContractAddress() { + const contractAddress = await this.typedOracle.getContractAddress(); + return toForeignCallResult([toSingle(contractAddress.toField())]); + } + + async getBlockNumber() { + const blockNumber = await this.typedOracle.getBlockNumber(); + return toForeignCallResult([toSingle(new Fr(blockNumber))]); + } + + async avmOpcodeAddress() { + const contractAddress = await this.typedOracle.getContractAddress(); + return toForeignCallResult([toSingle(contractAddress.toField())]); + } + + async avmOpcodeBlockNumber() { + const blockNumber = await this.typedOracle.getBlockNumber(); + return toForeignCallResult([toSingle(new Fr(blockNumber))]); + } + + async packArgumentsArray(args: ForeignCallArray) { + const packed = await this.typedOracle.packArgumentsArray(fromArray(args)); + return toForeignCallResult([toSingle(packed)]); + } + + async packArguments(_length: ForeignCallSingle, values: ForeignCallArray) { + const packed = await this.typedOracle.packArgumentsArray(fromArray(values)); + return toForeignCallResult([toSingle(packed)]); + } + + // Since the argument is a slice, noir automatically adds a length field to oracle call. + async packReturns(_length: ForeignCallSingle, values: ForeignCallArray) { + const packed = await this.typedOracle.packReturns(fromArray(values)); + return toForeignCallResult([toSingle(packed)]); + } + + async unpackReturns(returnsHash: ForeignCallSingle) { + const unpacked = await this.typedOracle.unpackReturns(fromSingle(returnsHash)); + return toForeignCallResult([toArray(unpacked)]); + } + + // Since the argument is a slice, noir automatically adds a length field to oracle call. + debugLog(message: ForeignCallArray, _length: ForeignCallSingle, fields: ForeignCallArray) { + const messageStr = fromArray(message) + .map(field => String.fromCharCode(field.toNumber())) + .join(''); + const fieldsFr = fromArray(fields); + this.typedOracle.debugLog(messageStr, fieldsFr); + return toForeignCallResult([]); + } + + async storageRead(startStorageSlot: ForeignCallSingle, numberOfElements: ForeignCallSingle) { + const values = await this.typedOracle.storageRead( + fromSingle(startStorageSlot), + fromSingle(numberOfElements).toNumber(), + ); + return toForeignCallResult([toArray(values)]); + } + + async storageWrite(startStorageSlot: ForeignCallSingle, values: ForeignCallArray) { + const newValues = await this.typedOracle.storageWrite(fromSingle(startStorageSlot), fromArray(values)); + return toForeignCallResult([toArray(newValues)]); + } + + async getPublicDataTreeWitness(blockNumber: ForeignCallSingle, leafSlot: ForeignCallSingle) { + const parsedBlockNumber = fromSingle(blockNumber).toNumber(); + const parsedLeafSlot = fromSingle(leafSlot); + + const witness = await this.typedOracle.getPublicDataTreeWitness(parsedBlockNumber, parsedLeafSlot); + if (!witness) { + throw new Error(`Public data witness not found for slot ${parsedLeafSlot} at block ${parsedBlockNumber}.`); + } + return toForeignCallResult([toArray(witness.toFields())]); + } + + async getSiblingPath(blockNumber: ForeignCallSingle, treeId: ForeignCallSingle, leafIndex: ForeignCallSingle) { + const result = await this.typedOracle.getSiblingPath( + fromSingle(blockNumber).toNumber(), + fromSingle(treeId).toNumber(), + fromSingle(leafIndex), + ); + return toForeignCallResult([toArray(result)]); + } + + async getNotes( + storageSlot: ForeignCallSingle, + numSelects: ForeignCallSingle, + selectByIndexes: ForeignCallArray, + selectByOffsets: ForeignCallArray, + selectByLengths: ForeignCallArray, + selectValues: ForeignCallArray, + selectComparators: ForeignCallArray, + sortByIndexes: ForeignCallArray, + sortByOffsets: ForeignCallArray, + sortByLengths: ForeignCallArray, + sortOrder: ForeignCallArray, + limit: ForeignCallSingle, + offset: ForeignCallSingle, + status: ForeignCallSingle, + returnSize: ForeignCallSingle, + ) { + const noteDatas = await this.typedOracle.getNotes( + fromSingle(storageSlot), + fromSingle(numSelects).toNumber(), + fromArray(selectByIndexes).map(fr => fr.toNumber()), + fromArray(selectByOffsets).map(fr => fr.toNumber()), + fromArray(selectByLengths).map(fr => fr.toNumber()), + fromArray(selectValues), + fromArray(selectComparators).map(fr => fr.toNumber()), + fromArray(sortByIndexes).map(fr => fr.toNumber()), + fromArray(sortByOffsets).map(fr => fr.toNumber()), + fromArray(sortByLengths).map(fr => fr.toNumber()), + fromArray(sortOrder).map(fr => fr.toNumber()), + fromSingle(limit).toNumber(), + fromSingle(offset).toNumber(), + fromSingle(status).toNumber(), + ); + const noteLength = noteDatas?.[0]?.note.items.length ?? 0; + if (!noteDatas.every(({ note }) => noteLength === note.items.length)) { + throw new Error('Notes should all be the same length.'); + } + + const contractAddress = noteDatas[0]?.contractAddress ?? Fr.ZERO; + + // Values indicates whether the note is settled or transient. + const noteTypes = { + isSettled: new Fr(0), + isTransient: new Fr(1), + }; + const flattenData = noteDatas.flatMap(({ nonce, note, index }) => [ + nonce, + index === undefined ? noteTypes.isTransient : noteTypes.isSettled, + ...note.items, + ]); + + const returnFieldSize = fromSingle(returnSize).toNumber(); + const returnData = [noteDatas.length, contractAddress, ...flattenData].map(v => new Fr(v)); + if (returnData.length > returnFieldSize) { + throw new Error(`Return data size too big. Maximum ${returnFieldSize} fields. Got ${flattenData.length}.`); + } + + const paddedZeros = Array(returnFieldSize - returnData.length).fill(new Fr(0)); + return toForeignCallResult([toArray([...returnData, ...paddedZeros])]); + } + + notifyCreatedNote( + storageSlot: ForeignCallSingle, + noteTypeId: ForeignCallSingle, + note: ForeignCallArray, + innerNoteHash: ForeignCallSingle, + counter: ForeignCallSingle, + ) { + this.typedOracle.notifyCreatedNote( + fromSingle(storageSlot), + fromSingle(noteTypeId), + fromArray(note), + fromSingle(innerNoteHash), + fromSingle(counter).toNumber(), + ); + return toForeignCallResult([toSingle(new Fr(0))]); + } + + async notifyNullifiedNote( + innerNullifier: ForeignCallSingle, + innerNoteHash: ForeignCallSingle, + counter: ForeignCallSingle, + ) { + await this.typedOracle.notifyNullifiedNote( + fromSingle(innerNullifier), + fromSingle(innerNoteHash), + fromSingle(counter).toNumber(), + ); + return toForeignCallResult([toSingle(new Fr(0))]); + } + + async checkNullifierExists(innerNullifier: ForeignCallSingle) { + const exists = await this.typedOracle.checkNullifierExists(fromSingle(innerNullifier)); + return toForeignCallResult([toSingle(new Fr(exists))]); + } + + async getContractInstance(address: ForeignCallSingle) { + const instance = await this.typedOracle.getContractInstance(fromSingle(address)); + return toForeignCallResult([ + toArray([ + instance.salt, + instance.deployer, + instance.contractClassId, + instance.initializationHash, + instance.publicKeysHash, + ]), + ]); + } + + async avmOpcodeGetContractInstance(address: ForeignCallSingle) { + const instance = await this.typedOracle.getContractInstance(fromSingle(address)); + return toForeignCallResult([ + toArray([ + // AVM requires an extra boolean indicating the instance was found + new Fr(1), + instance.salt, + instance.deployer, + instance.contractClassId, + instance.initializationHash, + instance.publicKeysHash, + ]), + ]); + } + + avmOpcodeSender() { + const sender = (this.typedOracle as TXE).getMsgSender(); + return toForeignCallResult([toSingle(sender)]); + } + + async avmOpcodeEmitNullifier(nullifier: ForeignCallSingle) { + await (this.typedOracle as TXE).avmOpcodeEmitNullifier(fromSingle(nullifier)); + return toForeignCallResult([]); + } + + async avmOpcodeEmitNoteHash(innerNoteHash: ForeignCallSingle) { + await (this.typedOracle as TXE).avmOpcodeEmitNoteHash(fromSingle(innerNoteHash)); + return toForeignCallResult([]); + } + + async avmOpcodeNullifierExists(innerNullifier: ForeignCallSingle, targetAddress: ForeignCallSingle) { + const exists = await (this.typedOracle as TXE).avmOpcodeNullifierExists( + fromSingle(innerNullifier), + AztecAddress.fromField(fromSingle(targetAddress)), + ); + return toForeignCallResult([toSingle(new Fr(exists))]); + } + + async getPublicKeysAndPartialAddress(address: ForeignCallSingle) { + const parsedAddress = AztecAddress.fromField(fromSingle(address)); + const { publicKeys, partialAddress } = await this.typedOracle.getCompleteAddress(parsedAddress); + + return toForeignCallResult([toArray([...publicKeys.toFields(), partialAddress])]); + } + + async getKeyValidationRequest(pkMHash: ForeignCallSingle) { + const keyValidationRequest = await this.typedOracle.getKeyValidationRequest(fromSingle(pkMHash)); + return toForeignCallResult([toArray(keyValidationRequest.toFields())]); + } + + computeEncryptedNoteLog( + contractAddress: ForeignCallSingle, + storageSlot: ForeignCallSingle, + noteTypeId: ForeignCallSingle, + ovskApp: ForeignCallSingle, + ovpkMX: ForeignCallSingle, + ovpkMY: ForeignCallSingle, + ivpkMX: ForeignCallSingle, + ivpkMY: ForeignCallSingle, + preimage: ForeignCallArray, + ) { + const ovpkM = new Point(fromSingle(ovpkMX), fromSingle(ovpkMY)); + const ovKeys = new KeyValidationRequest(ovpkM, Fr.fromString(fromSingle(ovskApp).toString())); + const ivpkM = new Point(fromSingle(ivpkMX), fromSingle(ivpkMY)); + const encLog = this.typedOracle.computeEncryptedNoteLog( + AztecAddress.fromString(fromSingle(contractAddress).toString()), + Fr.fromString(fromSingle(storageSlot).toString()), + Fr.fromString(fromSingle(noteTypeId).toString()), + ovKeys, + ivpkM, + fromArray(preimage), + ); + const bytes: Fr[] = []; + + encLog.forEach(v => { + bytes.push(new Fr(v)); + }); + return toForeignCallResult([toArray(bytes)]); + } + + emitEncryptedLog( + _contractAddress: ForeignCallSingle, + _randomandomness: ForeignCallSingle, + _encryptedLog: ForeignCallSingle, + _counter: ForeignCallSingle, + ) { + return toForeignCallResult([]); + } + + emitEncryptedNoteLog( + _noteHashCounter: ForeignCallSingle, + _encryptedNote: ForeignCallArray, + _counter: ForeignCallSingle, + ) { + return toForeignCallResult([]); + } + + async callPrivateFunction( + targetContractAddress: ForeignCallSingle, + functionSelector: ForeignCallSingle, + argsHash: ForeignCallSingle, + sideEffectCounter: ForeignCallSingle, + isStaticCall: ForeignCallSingle, + isDelegateCall: ForeignCallSingle, + ) { + const result = await this.typedOracle.callPrivateFunction( + fromSingle(targetContractAddress), + FunctionSelector.fromField(fromSingle(functionSelector)), + fromSingle(argsHash), + fromSingle(sideEffectCounter).toNumber(), + fromSingle(isStaticCall).toBool(), + fromSingle(isDelegateCall).toBool(), + ); + return toForeignCallResult([toArray(result.toFields())]); + } + + async getNullifierMembershipWitness(blockNumber: ForeignCallSingle, nullifier: ForeignCallSingle) { + const parsedBlockNumber = fromSingle(blockNumber).toNumber(); + const witness = await this.typedOracle.getNullifierMembershipWitness(parsedBlockNumber, fromSingle(nullifier)); + if (!witness) { + throw new Error(`Nullifier membership witness not found at block ${parsedBlockNumber}.`); + } + return toForeignCallResult([toArray(witness.toFields())]); + } +} diff --git a/yarn-project/txe/src/util/encoding.ts b/yarn-project/txe/src/util/encoding.ts new file mode 100644 index 00000000000..0d4a78ba61a --- /dev/null +++ b/yarn-project/txe/src/util/encoding.ts @@ -0,0 +1,29 @@ +import { Fr } from '@aztec/foundation/fields'; + +export type ForeignCallSingle = string; + +export type ForeignCallArray = string[]; + +export type ForeignCallResult = { + values: (ForeignCallSingle | ForeignCallArray)[]; +}; + +export function fromSingle(obj: ForeignCallSingle) { + return Fr.fromBuffer(Buffer.from(obj, 'hex')); +} + +export function fromArray(obj: ForeignCallArray) { + return obj.map(str => Fr.fromBuffer(Buffer.from(str, 'hex'))); +} + +export function toSingle(obj: Fr) { + return obj.toString().slice(2); +} + +export function toArray(objs: Fr[]) { + return objs.map(obj => obj.toString()); +} + +export function toForeignCallResult(obj: (ForeignCallSingle | ForeignCallArray)[]) { + return { values: obj }; +} diff --git a/yarn-project/txe/src/util/txe_database.ts b/yarn-project/txe/src/util/txe_database.ts new file mode 100644 index 00000000000..b154fd8702a --- /dev/null +++ b/yarn-project/txe/src/util/txe_database.ts @@ -0,0 +1,24 @@ +import { type AztecAddress, CompleteAddress } from '@aztec/circuits.js'; +import { type AztecKVStore, type AztecMap } from '@aztec/kv-store'; +import { KVPxeDatabase } from '@aztec/pxe'; + +export class TXEDatabase extends KVPxeDatabase { + #accounts: AztecMap; + + constructor(db: AztecKVStore) { + super(db); + this.#accounts = db.openMap('accounts'); + } + + getAccount(key: AztecAddress) { + const completeAddress = this.#accounts.get(key.toString()); + if (!completeAddress) { + throw new Error(`Account not found: ${key.toString()}`); + } + return CompleteAddress.fromBuffer(completeAddress); + } + + async setAccount(key: AztecAddress, value: CompleteAddress) { + await this.#accounts.set(key.toString(), value.toBuffer()); + } +} diff --git a/yarn-project/txe/tsconfig.json b/yarn-project/txe/tsconfig.json new file mode 100644 index 00000000000..7db2bf79778 --- /dev/null +++ b/yarn-project/txe/tsconfig.json @@ -0,0 +1,47 @@ +{ + "extends": "..", + "compilerOptions": { + "outDir": "dest", + "rootDir": "src", + "tsBuildInfoFile": ".tsbuildinfo" + }, + "references": [ + { + "path": "../archiver" + }, + { + "path": "../aztec.js" + }, + { + "path": "../circuit-types" + }, + { + "path": "../circuits.js" + }, + { + "path": "../foundation" + }, + { + "path": "../key-store" + }, + { + "path": "../kv-store" + }, + { + "path": "../noir-contracts.js" + }, + { + "path": "../pxe" + }, + { + "path": "../simulator" + }, + { + "path": "../types" + }, + { + "path": "../world-state" + } + ], + "include": ["src"] +} diff --git a/yarn-project/types/src/abi/contract_artifact.ts b/yarn-project/types/src/abi/contract_artifact.ts index 8ca72aa68a7..9fff2b21b6a 100644 --- a/yarn-project/types/src/abi/contract_artifact.ts +++ b/yarn-project/types/src/abi/contract_artifact.ts @@ -2,7 +2,6 @@ import { type ABIParameter, type ABIParameterVisibility, type AbiType, - type BasicValue, type ContractArtifact, type ContractNote, type FieldLayout, @@ -227,10 +226,8 @@ function getStorageLayout(input: NoirCompiledContract) { return storageFields.reduce((acc: Record, field) => { const name = field.name; const slot = field.value.fields[0].value as IntegerValue; - const typ = field.value.fields[1].value as BasicValue<'string', string>; acc[name] = { slot: new Fr(BigInt(slot.value)), - typ: typ.value, }; return acc; }, {}); diff --git a/yarn-project/world-state/src/world-state-db/index.ts b/yarn-project/world-state/src/world-state-db/index.ts index 9d72e0991e8..f4c20a567f9 100644 --- a/yarn-project/world-state/src/world-state-db/index.ts +++ b/yarn-project/world-state/src/world-state-db/index.ts @@ -1,3 +1,5 @@ export * from './merkle_trees.js'; export * from './merkle_tree_db.js'; export * from './merkle_tree_operations.js'; +export * from './merkle_tree_operations_facade.js'; +export * from './merkle_tree_snapshot_operations_facade.js'; diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index d1fe44fd9df..cc328c7abd1 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -933,6 +933,34 @@ __metadata: languageName: unknown linkType: soft +"@aztec/txe@workspace:txe": + version: 0.0.0-use.local + resolution: "@aztec/txe@workspace:txe" + dependencies: + "@aztec/archiver": "workspace:^" + "@aztec/aztec.js": "workspace:^" + "@aztec/circuit-types": "workspace:^" + "@aztec/circuits.js": "workspace:^" + "@aztec/foundation": "workspace:^" + "@aztec/key-store": "workspace:^" + "@aztec/kv-store": "workspace:^" + "@aztec/noir-contracts.js": "workspace:^" + "@aztec/pxe": "workspace:^" + "@aztec/simulator": "workspace:^" + "@aztec/types": "workspace:^" + "@aztec/world-state": "workspace:^" + "@jest/globals": ^29.5.0 + "@types/jest": ^29.5.0 + "@types/node": ^18.7.23 + jest: ^29.5.0 + jest-mock-extended: ^3.0.3 + ts-node: ^10.9.1 + typescript: ^5.0.4 + bin: + txe: ./dest/bin/index.js + languageName: unknown + linkType: soft + "@aztec/types@workspace:^, @aztec/types@workspace:types": version: 0.0.0-use.local resolution: "@aztec/types@workspace:types"
OpcodeNameSummaryExpression
0x00 [`ADD`](#isa-section-add)0x00\[\`ADD\`\](#isa-section-add) Addition (a + b) { `M[dstOffset] = M[aOffset] + M[bOffset] mod 2^k` }
0x01 [`SUB`](#isa-section-sub)0x01\[\`SUB\`\](#isa-section-sub) Subtraction (a - b) { `M[dstOffset] = M[aOffset] - M[bOffset] mod 2^k` }
0x02 [`MUL`](#isa-section-mul)0x02\[\`MUL\`\](#isa-section-mul) Multiplication (a * b) { `M[dstOffset] = M[aOffset] * M[bOffset] mod 2^k` }
0x03 [`DIV`](#isa-section-div)0x03\[\`DIV\`\](#isa-section-div) Unsigned integer division (a / b) { `M[dstOffset] = M[aOffset] / M[bOffset]` }
0x04 [`FDIV`](#isa-section-fdiv)0x04\[\`FDIV\`\](#isa-section-fdiv) Field division (a / b) { `M[dstOffset] = M[aOffset] / M[bOffset]` }
0x05 [`EQ`](#isa-section-eq)0x05\[\`EQ\`\](#isa-section-eq) Equality check (a == b) { `M[dstOffset] = M[aOffset] == M[bOffset] ? 1 : 0` }
0x06 [`LT`](#isa-section-lt)0x06\[\`LT\`\](#isa-section-lt) Less-than check (a < b) { `M[dstOffset] = M[aOffset] < M[bOffset] ? 1 : 0` }
0x07 [`LTE`](#isa-section-lte)0x07\[\`LTE\`\](#isa-section-lte) Less-than-or-equals check (a <= b) { `M[dstOffset] = M[aOffset] <= M[bOffset] ? 1 : 0` }
0x08 [`AND`](#isa-section-and)0x08\[\`AND\`\](#isa-section-and) Bitwise AND (a & b) { `M[dstOffset] = M[aOffset] AND M[bOffset]` }
0x09 [`OR`](#isa-section-or)0x09\[\`OR\`\](#isa-section-or) Bitwise OR (a | b) { `M[dstOffset] = M[aOffset] OR M[bOffset]` }
0x0a [`XOR`](#isa-section-xor)0x0a\[\`XOR\`\](#isa-section-xor) Bitwise XOR (a ^ b) { `M[dstOffset] = M[aOffset] XOR M[bOffset]` }
0x0b [`NOT`](#isa-section-not)0x0b\[\`NOT\`\](#isa-section-not) Bitwise NOT (inversion) { `M[dstOffset] = NOT M[aOffset]` }
0x0c [`SHL`](#isa-section-shl)0x0c\[\`SHL\`\](#isa-section-shl) Bitwise leftward shift (a << b) { `M[dstOffset] = M[aOffset] << M[bOffset]` }
0x0d [`SHR`](#isa-section-shr)0x0d\[\`SHR\`\](#isa-section-shr) Bitwise rightward shift (a >> b) { `M[dstOffset] = M[aOffset] >> M[bOffset]` }
0x0e [`CAST`](#isa-section-cast)0x0e\[\`CAST\`\](#isa-section-cast) Type cast { `M[dstOffset] = cast(M[aOffset])` }
0x0f [`ADDRESS`](#isa-section-address)0x0f\[\`ADDRESS\`\](#isa-section-address) Get the address of the currently executing l2 contract { `M[dstOffset] = context.environment.address` }
0x10 [`STORAGEADDRESS`](#isa-section-storageaddress)0x10\[\`STORAGEADDRESS\`\](#isa-section-storageaddress) Get the _storage_ address of the currently executing context { `M[dstOffset] = context.environment.storageAddress` }
0x11 [`SENDER`](#isa-section-sender)0x11\[\`SENDER\`\](#isa-section-sender) Get the address of the sender (caller of the current context) { `M[dstOffset] = context.environment.sender` }
0x12 [`FEEPERL2GAS`](#isa-section-feeperl2gas)0x12\[\`FEEPERL2GAS\`\](#isa-section-feeperl2gas) Get the fee to be paid per "L2 gas" - constant for entire transaction { `M[dstOffset] = context.environment.feePerL2Gas` }
0x13 [`FEEPERDAGAS`](#isa-section-feeperdagas)0x13\[\`FEEPERDAGAS\`\](#isa-section-feeperdagas) Get the fee to be paid per "DA gas" - constant for entire transaction { `M[dstOffset] = context.environment.feePerDaGas` }
0x14 [`TRANSACTIONFEE`](#isa-section-transactionfee)0x14\[\`TRANSACTIONFEE\`\](#isa-section-transactionfee) Get the computed transaction fee during teardown phase, zero otherwise { `M[dstOffset] = context.environment.transactionFee` }
0x15 [`CONTRACTCALLDEPTH`](#isa-section-contractcalldepth)0x15\[\`CONTRACTCALLDEPTH\`\](#isa-section-contractcalldepth) Get how many contract calls deep the current call context is { `M[dstOffset] = context.environment.contractCallDepth` }
0x16 [`CHAINID`](#isa-section-chainid)0x16\[\`CHAINID\`\](#isa-section-chainid) Get this rollup's L1 chain ID { `M[dstOffset] = context.environment.globals.chainId` }
0x17 [`VERSION`](#isa-section-version)0x17\[\`VERSION\`\](#isa-section-version) Get this rollup's L2 version ID { `M[dstOffset] = context.environment.globals.version` }
0x18 [`BLOCKNUMBER`](#isa-section-blocknumber)0x18\[\`BLOCKNUMBER\`\](#isa-section-blocknumber) Get this L2 block's number { `M[dstOffset] = context.environment.globals.blocknumber` }
0x19 [`TIMESTAMP`](#isa-section-timestamp)0x19\[\`TIMESTAMP\`\](#isa-section-timestamp) Get this L2 block's timestamp { `M[dstOffset] = context.environment.globals.timestamp` }
0x1a [`COINBASE`](#isa-section-coinbase)0x1a\[\`COINBASE\`\](#isa-section-coinbase) Get the block's beneficiary address { `M[dstOffset] = context.environment.globals.coinbase` }
0x1b [`BLOCKL2GASLIMIT`](#isa-section-blockl2gaslimit)0x1b\[\`BLOCKL2GASLIMIT\`\](#isa-section-blockl2gaslimit) Total amount of "L2 gas" that a block can consume { `M[dstOffset] = context.environment.globals.l2GasLimit` }
0x1c [`BLOCKDAGASLIMIT`](#isa-section-blockdagaslimit)0x1c\[\`BLOCKDAGASLIMIT\`\](#isa-section-blockdagaslimit) Total amount of "DA gas" that a block can consume { `M[dstOffset] = context.environment.globals.daGasLimit` }
0x1d [`CALLDATACOPY`](#isa-section-calldatacopy)0x1d\[\`CALLDATACOPY\`\](#isa-section-calldatacopy) Copy calldata into memory { `M[dstOffset:dstOffset+copySize] = context.environment.calldata[cdOffset:cdOffset+copySize]` }
0x1e [`L2GASLEFT`](#isa-section-l2gasleft)0x1e\[\`L2GASLEFT\`\](#isa-section-l2gasleft) Remaining "L2 gas" for this call (after this instruction) { `M[dstOffset] = context.MachineState.l2GasLeft` }
0x1f [`DAGASLEFT`](#isa-section-dagasleft)0x1f\[\`DAGASLEFT\`\](#isa-section-dagasleft) Remaining "DA gas" for this call (after this instruction) { `M[dstOffset] = context.machineState.daGasLeft` }
0x20 [`JUMP`](#isa-section-jump)0x20\[\`JUMP\`\](#isa-section-jump) Jump to a location in the bytecode { `context.machineState.pc = loc` }
0x21 [`JUMPI`](#isa-section-jumpi)0x21\[\`JUMPI\`\](#isa-section-jumpi) Conditionally jump to a location in the bytecode { `context.machineState.pc = M[condOffset] > 0 ? loc : context.machineState.pc` }
0x22 [`INTERNALCALL`](#isa-section-internalcall)0x22\[\`INTERNALCALL\`\](#isa-section-internalcall) Make an internal call. Push the current PC to the internal call stack and jump to the target location. {`context.machineState.internalCallStack.push(context.machineState.pc) @@ -260,49 +295,56 @@ context.machineState.pc = loc`}
0x23 [`INTERNALRETURN`](#isa-section-internalreturn)0x23\[\`INTERNALRETURN\`\](#isa-section-internalreturn) Return from an internal call. Pop from the internal call stack and jump to the popped location. { `context.machineState.pc = context.machineState.internalCallStack.pop()` }
0x24 [`SET`](#isa-section-set)0x24\[\`SET\`\](#isa-section-set) Set a memory word from a constant in the bytecode { `M[dstOffset] = const` }
0x25 [`MOV`](#isa-section-mov)0x25\[\`MOV\`\](#isa-section-mov) Move a word from source memory location to destination { `M[dstOffset] = M[srcOffset]` }
0x26 [`CMOV`](#isa-section-cmov)0x26\[\`CMOV\`\](#isa-section-cmov) Move a word (conditionally chosen) from one memory location to another (`d = cond > 0 ? a : b`) { `M[dstOffset] = M[condOffset] > 0 ? M[aOffset] : M[bOffset]` }
0x27 [`SLOAD`](#isa-section-sload)0x27\[\`SLOAD\`\](#isa-section-sload) Load a word from this contract's persistent public storage. Zero is loaded for unwritten slots. {`M[dstOffset] = S[M[slotOffset]]`}
0x28 [`SSTORE`](#isa-section-sstore)0x28\[\`SSTORE\`\](#isa-section-sstore) Write a word to this contract's persistent public storage {`S[M[slotOffset]] = M[srcOffset]`}
0x29 [`NOTEHASHEXISTS`](#isa-section-notehashexists)0x29\[\`NOTEHASHEXISTS\`\](#isa-section-notehashexists) Check whether a note hash exists in the note hash tree (as of the start of the current block) {`exists = context.worldState.noteHashes.has({ @@ -313,7 +355,8 @@ M[existsOffset] = exists`}
0x2a [`EMITNOTEHASH`](#isa-section-emitnotehash)0x2a\[\`EMITNOTEHASH\`\](#isa-section-emitnotehash) Emit a new note hash to be inserted into the note hash tree {`context.worldState.noteHashes.append( @@ -322,7 +365,8 @@ M[existsOffset] = exists`}
0x2b [`NULLIFIEREXISTS`](#isa-section-nullifierexists)0x2b\[\`NULLIFIEREXISTS\`\](#isa-section-nullifierexists) Check whether a nullifier exists in the nullifier tree (including nullifiers from earlier in the current transaction or from earlier in the current block) {`exists = pendingNullifiers.has(M[addressOffset], M[nullifierOffset]) || context.worldState.nullifiers.has( @@ -332,7 +376,8 @@ M[existsOffset] = exists`}
0x2c [`EMITNULLIFIER`](#isa-section-emitnullifier)0x2c\[\`EMITNULLIFIER\`\](#isa-section-emitnullifier) Emit a new nullifier to be inserted into the nullifier tree {`context.worldState.nullifiers.append( @@ -341,7 +386,8 @@ M[existsOffset] = exists`}
0x2d [`L1TOL2MSGEXISTS`](#isa-section-l1tol2msgexists)0x2d\[\`L1TOL2MSGEXISTS\`\](#isa-section-l1tol2msgexists) Check if a message exists in the L1-to-L2 message tree {`exists = context.worldState.l1ToL2Messages.has({ @@ -351,7 +397,8 @@ M[existsOffset] = exists`}
0x2e [`HEADERMEMBER`](#isa-section-headermember)0x2e\[\`HEADERMEMBER\`\](#isa-section-headermember) Check if a header exists in the [archive tree](../state/archive) and retrieve the specified member if so {`exists = context.worldState.header.has({ @@ -364,7 +411,8 @@ if exists:
0x2f [`GETCONTRACTINSTANCE`](#isa-section-getcontractinstance)0x2f\[\`GETCONTRACTINSTANCE\`\](#isa-section-getcontractinstance) Copies contract instance data to memory {`M[dstOffset:dstOffset+CONTRACT_INSTANCE_SIZE+1] = [ @@ -379,7 +427,8 @@ if exists:
0x30 [`EMITUNENCRYPTEDLOG`](#isa-section-emitunencryptedlog)0x30\[\`EMITUNENCRYPTEDLOG\`\](#isa-section-emitunencryptedlog) Emit an unencrypted log {`context.accruedSubstate.unencryptedLogs.append( @@ -392,7 +441,8 @@ if exists:
0x31 [`SENDL2TOL1MSG`](#isa-section-sendl2tol1msg)0x31\[\`SENDL2TOL1MSG\`\](#isa-section-sendl2tol1msg) Send an L2-to-L1 message {`context.accruedSubstate.sentL2ToL1Messages.append( @@ -405,7 +455,8 @@ if exists:
0x32 [`CALL`](#isa-section-call)0x32\[\`CALL\`\](#isa-section-call) Call into another contract {`// instr.args are { gasOffset, addrOffset, argsOffset, retOffset, retSize } @@ -419,7 +470,8 @@ updateContextAfterNestedCall(context, instr.args, nestedContext)`}
0x33 [`STATICCALL`](#isa-section-staticcall)0x33\[\`STATICCALL\`\](#isa-section-staticcall) Call into another contract, disallowing World State and Accrued Substate modifications {`// instr.args are { gasOffset, addrOffset, argsOffset, retOffset, retSize } @@ -433,7 +485,8 @@ updateContextAfterNestedCall(context, instr.args, nestedContext)`}
0x34 [`DELEGATECALL`](#isa-section-delegatecall)0x34\[\`DELEGATECALL\`\](#isa-section-delegatecall) Call into another contract, but keep the caller's `sender` and `storageAddress` {`// instr.args are { gasOffset, addrOffset, argsOffset, retOffset, retSize } @@ -447,7 +500,8 @@ updateContextAfterNestedCall(context, instr.args, nestedContext)`}
0x35 [`RETURN`](#isa-section-return)0x35\[\`RETURN\`\](#isa-section-return) Halt execution within this context (without revert), optionally returning some data {`context.contractCallResults.output = M[retOffset:retOffset+retSize] @@ -455,7 +509,8 @@ halt`}
0x36 [`REVERT`](#isa-section-revert)0x36\[\`REVERT\`\](#isa-section-revert) Halt execution within this context as `reverted`, optionally returning some data {`context.contractCallResults.output = M[retOffset:retOffset+retSize] @@ -464,7 +519,8 @@ halt`}
0x37 [`TORADIXLE`](#isa-section-to_radix_le)0x37\[\`TORADIXLE\`\](#isa-section-to_radix_le) Convert a word to an array of limbs in little-endian radix form TBD: Storage of limbs and if T[dstOffset] is constrained to U8
${toOpcode(i)}${toOpcode(i)}[${stripBraces(name)}](#isa-section-${ + }'/>\\[${escapeTicks(name)}\\](#isa-section-${ instr["id"] })