diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 966c1536f7c..a097d4b70fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,10 +4,7 @@ on: branches: [master] pull_request: {} workflow_dispatch: - inputs: - username: - description: "Defaults to GitHub Actor" - required: false + inputs: {} concurrency: # force parallelism in master @@ -18,7 +15,7 @@ env: DOCKERHUB_PASSWORD: "${{ secrets.DOCKERHUB_PASSWORD }}" RUN_ID: ${{ github.run_id }} RUN_ATTEMPT: ${{ github.run_attempt }} - USERNAME: ${{ inputs.username || github.actor }} + 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 }} @@ -32,12 +29,12 @@ jobs: setup: uses: ./.github/workflows/setup-runner.yml with: - username: ${{ inputs.username || github.actor }} + username: ${{ github.event.pull_request.user.login || github.actor }} runner_type: builder-x86 secrets: inherit build: needs: setup - runs-on: ${{ inputs.username || github.actor }}-x86 + runs-on: ${{ github.event.pull_request.user.login || github.actor }}-x86 outputs: e2e_list: ${{ steps.e2e_list.outputs.list }} bench_list: ${{ steps.bench_list.outputs.list }} @@ -46,7 +43,7 @@ jobs: with: { ref: "${{ env.GIT_COMMIT }}" } - uses: ./.github/ci-setup-action with: - concurrency_key: build-${{ inputs.username || github.actor }}-x86 + concurrency_key: build-${{ github.event.pull_request.user.login || github.actor }}-x86 # prepare images locally, tagged by commit hash - name: "Build E2E Image" timeout-minutes: 40 @@ -124,7 +121,7 @@ jobs: # # bench-summary: # # needs: e2e - # # runs-on: ${{ inputs.username || github.actor }}-x86 + # # runs-on: ${{ github.event.pull_request.user.login || github.actor }}-x86 # # steps: # # - uses: actions/checkout@v4 # # with: @@ -132,7 +129,7 @@ jobs: # # ref: "${{ env.GIT_COMMIT }}" # # - uses: ./.github/ci-setup-action # # with: - # # concurrency_key: build-${{ inputs.username || github.actor }}-x86 + # # concurrency_key: build-${{ github.event.pull_request.user.login || github.actor }}-x86 # # - name: "Build and upload bench aggregate file" # # working-directory: ./yarn-project/scripts # # run: earthly-ci -P --secret AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} --secret AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} +bench-aggregate @@ -151,13 +148,13 @@ jobs: noir-format: needs: setup - runs-on: ${{ inputs.username || github.actor }}-x86 + runs-on: ${{ github.event.pull_request.user.login || github.actor }}-x86 steps: - uses: actions/checkout@v4 with: { ref: "${{ env.GIT_COMMIT }}" } - uses: ./.github/ci-setup-action with: - concurrency_key: noir-format-${{ inputs.username || github.actor }}-x86 + concurrency_key: noir-format-${{ github.event.pull_request.user.login || github.actor }}-x86 - name: "Format Noir" working-directory: ./noir/ timeout-minutes: 25 @@ -171,7 +168,7 @@ jobs: # only ran on x86 for resource reasons (memory intensive) bb-native-tests: needs: setup - runs-on: ${{ inputs.username || github.actor }}-x86 + runs-on: ${{ github.event.pull_request.user.login || github.actor }}-x86 steps: - uses: actions/checkout@v4 with: { ref: "${{ env.GIT_COMMIT }}" } @@ -179,7 +176,7 @@ jobs: - uses: ./.github/ci-setup-action with: # must be globally unique for build x runner - concurrency_key: bb-native-tests-${{ inputs.username || github.actor }}-x86 + concurrency_key: bb-native-tests-${{ github.event.pull_request.user.login || github.actor }}-x86 - name: "Native Prover Tests" working-directory: ./barretenberg/cpp/ timeout-minutes: 25 @@ -202,37 +199,37 @@ jobs: noir-test: needs: setup - runs-on: ${{ inputs.username || github.actor }}-x86 + runs-on: ${{ github.event.pull_request.user.login || github.actor }}-x86 steps: - uses: actions/checkout@v4 with: { ref: "${{ env.GIT_COMMIT }}" } - uses: ./.github/ci-setup-action with: - concurrency_key: noir-${{ inputs.username || github.actor }}-x86 + concurrency_key: noir-${{ github.event.pull_request.user.login || github.actor }}-x86 - name: "Test Noir JS packages" run: earthly-ci --no-output ./noir+test noir-packages-test: needs: setup - runs-on: ${{ inputs.username || github.actor }}-x86 + runs-on: ${{ github.event.pull_request.user.login || github.actor }}-x86 steps: - uses: actions/checkout@v4 with: { ref: "${{ env.GIT_COMMIT }}" } - uses: ./.github/ci-setup-action with: - concurrency_key: noir-packages-${{ inputs.username || github.actor }}-x86 + concurrency_key: noir-packages-${{ github.event.pull_request.user.login || github.actor }}-x86 - name: "Test Noir JS packages" run: earthly-ci --no-output ./noir+packages-test noir-projects: needs: setup - runs-on: ${{ inputs.username || github.actor }}-x86 + runs-on: ${{ github.event.pull_request.user.login || github.actor }}-x86 steps: - uses: actions/checkout@v4 with: { ref: "${{ env.GIT_COMMIT }}" } - uses: ./.github/ci-setup-action with: - concurrency_key: noir-projects-${{ inputs.username || github.actor }}-x86 + concurrency_key: noir-projects-${{ github.event.pull_request.user.login || github.actor }}-x86 - name: "Noir Projects" timeout-minutes: 25 run: earthly-ci --no-output ./noir-projects/+test @@ -336,14 +333,14 @@ jobs: docs-preview: needs: build - runs-on: ${{ inputs.username || github.actor }}-x86 + runs-on: ${{ github.event.pull_request.user.login || github.actor }}-x86 if: github.event.number steps: - uses: actions/checkout@v4 with: { ref: "${{ env.GIT_COMMIT }}" } - uses: ./.github/ci-setup-action with: - concurrency_key: docs-preview-${{ inputs.username || github.actor }}-x86 + concurrency_key: docs-preview-${{ github.event.pull_request.user.login || github.actor }}-x86 - name: "Docs Preview" timeout-minutes: 30 run: earthly-ci --no-output ./docs/+deploy-preview --PR=${{ github.event.number }} --AZTEC_BOT_COMMENTER_GITHUB_TOKEN=${{ secrets.AZTEC_BOT_GITHUB_TOKEN }} --NETLIFY_AUTH_TOKEN=${{ secrets.NETLIFY_AUTH_TOKEN }} --NETLIFY_SITE_ID=${{ secrets.NETLIFY_SITE_ID }} @@ -374,7 +371,7 @@ jobs: protocol-circuits-gates-report: needs: setup - runs-on: ${{ inputs.username || github.actor }}-x86 + runs-on: ${{ github.event.pull_request.user.login || github.actor }}-x86 permissions: pull-requests: write steps: @@ -383,7 +380,7 @@ jobs: # Only allow one memory-hunger prover test to use this runner - uses: ./.github/ci-setup-action with: - concurrency_key: protocol-circuits-gates-report-${{ inputs.username || github.actor }}-x86 + concurrency_key: protocol-circuits-gates-report-${{ github.event.pull_request.user.login || github.actor }}-x86 - name: "Noir Protocol Circuits Report" working-directory: ./noir-projects/ timeout-minutes: 25 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 060d6776cb1..381dab411c3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp @@ -62,7 +62,7 @@ const size_t MAX_ARGS_LENGTH = ARGS_HASH_CHUNK_COUNT * ARGS_HASH_CHUNK_LENGTH; const size_t INITIAL_L2_BLOCK_NUM = 1; const size_t BLOB_SIZE_IN_BYTES = 31 * 4096; const size_t NESTED_CALL_L2_GAS_BUFFER = 20000; -const size_t MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 16200; +const size_t MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 32000; const size_t MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 3000; const size_t MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS = 3000; const size_t REGISTERER_PRIVATE_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS = 19; @@ -87,23 +87,26 @@ const size_t FUNCTION_LEAF_PREIMAGE_LENGTH = 5; const size_t GLOBAL_VARIABLES_LENGTH = 6 + GAS_FEES_LENGTH; const size_t APPEND_ONLY_TREE_SNAPSHOT_LENGTH = 2; const size_t L1_TO_L2_MESSAGE_LENGTH = 6; -const size_t L2_TO_L1_MESSAGE_LENGTH = 2; +const size_t L2_TO_L1_MESSAGE_LENGTH = 3; +const size_t SCOPED_L2_TO_L1_MESSAGE_LENGTH = L2_TO_L1_MESSAGE_LENGTH + 1; const size_t MAX_BLOCK_NUMBER_LENGTH = 2; const size_t NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH = 3; -const size_t NULLIFIER_KEY_VALIDATION_REQUEST_CONTEXT_LENGTH = 4; +const size_t SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH = NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH + 1; const size_t PARTIAL_STATE_REFERENCE_LENGTH = 6; const size_t READ_REQUEST_LENGTH = 2; const size_t NOTE_HASH_LENGTH = 2; -const size_t NOTE_HASH_CONTEXT_LENGTH = 3; +const size_t SCOPED_NOTE_HASH_LENGTH = NOTE_HASH_LENGTH + 2; const size_t NULLIFIER_LENGTH = 3; +const size_t SCOPED_NULLIFIER_LENGTH = NULLIFIER_LENGTH + 1; const size_t SIDE_EFFECT_LENGTH = 2; +const size_t ROLLUP_VALIDATION_REQUESTS_LENGTH = MAX_BLOCK_NUMBER_LENGTH; const size_t STATE_REFERENCE_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH; const size_t TX_CONTEXT_LENGTH = 2 + GAS_SETTINGS_LENGTH; const size_t TX_REQUEST_LENGTH = 2 + TX_CONTEXT_LENGTH + FUNCTION_DATA_LENGTH; const size_t HEADER_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + CONTENT_COMMITMENT_LENGTH + STATE_REFERENCE_LENGTH + GLOBAL_VARIABLES_LENGTH; const size_t PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = - CALL_CONTEXT_LENGTH + 3 + MAX_BLOCK_NUMBER_LENGTH + (READ_REQUEST_LENGTH * MAX_NOTE_HASH_READ_REQUESTS_PER_CALL) + + CALL_CONTEXT_LENGTH + 4 + MAX_BLOCK_NUMBER_LENGTH + (READ_REQUEST_LENGTH * MAX_NOTE_HASH_READ_REQUESTS_PER_CALL) + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) + (NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL) + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + @@ -124,6 +127,40 @@ const size_t PRIVATE_CALL_STACK_ITEM_LENGTH = AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH; const size_t PUBLIC_CONTEXT_INPUTS_LENGTH = CALL_CONTEXT_LENGTH + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + GAS_LENGTH + 2; +const size_t SCOPED_READ_REQUEST_LEN = READ_REQUEST_LENGTH + 1; +const size_t PUBLIC_DATA_READ_LENGTH = 2; +const size_t VALIDATION_REQUESTS_LENGTH = + ROLLUP_VALIDATION_REQUESTS_LENGTH + (SCOPED_READ_REQUEST_LEN * MAX_NOTE_HASH_READ_REQUESTS_PER_TX) + + (SCOPED_READ_REQUEST_LEN * MAX_NULLIFIER_READ_REQUESTS_PER_TX) + + (SCOPED_READ_REQUEST_LEN * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX) + + (SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX) + + (PUBLIC_DATA_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_TX); +const size_t PUBLIC_DATA_UPDATE_REQUEST_LENGTH = 2; +const size_t COMBINED_ACCUMULATED_DATA_LENGTH = + MAX_NEW_NOTE_HASHES_PER_TX + MAX_NEW_NULLIFIERS_PER_TX + MAX_NEW_L2_TO_L1_MSGS_PER_TX + 4 + + (MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * PUBLIC_DATA_UPDATE_REQUEST_LENGTH) + GAS_LENGTH; +const size_t COMBINED_CONSTANT_DATA_LENGTH = HEADER_LENGTH + TX_CONTEXT_LENGTH + GLOBAL_VARIABLES_LENGTH; +const size_t CALLER_CONTEXT_LENGTH = 2 * AZTEC_ADDRESS_LENGTH; +const size_t CALL_REQUEST_LENGTH = 1 + AZTEC_ADDRESS_LENGTH + CALLER_CONTEXT_LENGTH + 2; +const size_t PRIVATE_ACCUMULATED_DATA_LENGTH = + (SCOPED_NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_TX) + (SCOPED_NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_TX) + + (MAX_NEW_L2_TO_L1_MSGS_PER_TX * SCOPED_L2_TO_L1_MESSAGE_LENGTH) + (SIDE_EFFECT_LENGTH * MAX_ENCRYPTED_LOGS_PER_TX) + + (SIDE_EFFECT_LENGTH * MAX_UNENCRYPTED_LOGS_PER_TX) + 2 + + (CALL_REQUEST_LENGTH * MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX) + + (CALL_REQUEST_LENGTH * MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX); +const size_t PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = + 1 + VALIDATION_REQUESTS_LENGTH + PRIVATE_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + + CALL_REQUEST_LENGTH + AZTEC_ADDRESS_LENGTH; +const size_t PUBLIC_ACCUMULATED_DATA_LENGTH = + (MAX_NEW_NOTE_HASHES_PER_TX * NOTE_HASH_LENGTH) + (MAX_NEW_NULLIFIERS_PER_TX * NULLIFIER_LENGTH) + + (MAX_NEW_L2_TO_L1_MSGS_PER_TX * 1) + (MAX_ENCRYPTED_LOGS_PER_TX * SIDE_EFFECT_LENGTH) + + (MAX_UNENCRYPTED_LOGS_PER_TX * SIDE_EFFECT_LENGTH) + 2 + + (MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * PUBLIC_DATA_UPDATE_REQUEST_LENGTH) + + (MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX * CALL_REQUEST_LENGTH) + GAS_LENGTH; +const size_t PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = + VALIDATION_REQUESTS_LENGTH + PUBLIC_ACCUMULATED_DATA_LENGTH + PUBLIC_ACCUMULATED_DATA_LENGTH + + COMBINED_CONSTANT_DATA_LENGTH + 1 + (MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX * CALL_REQUEST_LENGTH) + + AZTEC_ADDRESS_LENGTH; const size_t ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH = 2 + FUNCTION_DATA_LENGTH + CALL_CONTEXT_LENGTH; const size_t GET_NOTES_ORACLE_RETURN_LENGTH = 674; const size_t NOTE_HASHES_NUM_BYTES_PER_BASE_ROLLUP = 2048; diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index ff662654f9e..23935b18b31 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -187,7 +187,17 @@ library Constants { + (CALL_REQUEST_LENGTH * MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX); uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1 + VALIDATION_REQUESTS_LENGTH + PRIVATE_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH - + CALL_REQUEST_LENGTH; + + CALL_REQUEST_LENGTH + AZTEC_ADDRESS_LENGTH; + uint256 internal constant PUBLIC_ACCUMULATED_DATA_LENGTH = ( + MAX_NEW_NOTE_HASHES_PER_TX * NOTE_HASH_LENGTH + ) + (MAX_NEW_NULLIFIERS_PER_TX * NULLIFIER_LENGTH) + (MAX_NEW_L2_TO_L1_MSGS_PER_TX * 1) + + (MAX_ENCRYPTED_LOGS_PER_TX * SIDE_EFFECT_LENGTH) + + (MAX_UNENCRYPTED_LOGS_PER_TX * SIDE_EFFECT_LENGTH) + 2 + + (MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * PUBLIC_DATA_UPDATE_REQUEST_LENGTH) + + (MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX * CALL_REQUEST_LENGTH) + GAS_LENGTH; + uint256 internal constant PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = VALIDATION_REQUESTS_LENGTH + + PUBLIC_ACCUMULATED_DATA_LENGTH + PUBLIC_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + + 1 + (MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX * CALL_REQUEST_LENGTH) + AZTEC_ADDRESS_LENGTH; uint256 internal constant ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH = 2 + FUNCTION_DATA_LENGTH + CALL_CONTEXT_LENGTH; uint256 internal constant GET_NOTES_ORACLE_RETURN_LENGTH = 674; diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr index 3f9f12ef6a6..3c0e9b0fbe1 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/common.nr @@ -1,11 +1,11 @@ use dep::types::{ abis::{ call_request::CallRequest, public_call_stack_item::PublicCallStackItem, - kernel_circuit_public_inputs::PublicKernelCircuitPublicInputsBuilder, kernel_data::PublicKernelData, - note_hash::NoteHash, nullifier::Nullifier, public_call_data::PublicCallData, - public_data_read::PublicDataRead, public_data_update_request::PublicDataUpdateRequest, - side_effect::SideEffect, global_variables::GlobalVariables, - combined_constant_data::CombinedConstantData + kernel_circuit_public_inputs::PublicKernelCircuitPublicInputsBuilder, + public_kernel_data::PublicKernelData, note_hash::NoteHash, nullifier::Nullifier, + public_call_data::PublicCallData, public_data_read::PublicDataRead, + public_data_update_request::PublicDataUpdateRequest, side_effect::SideEffect, + global_variables::GlobalVariables, combined_constant_data::CombinedConstantData }, address::AztecAddress, contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr index 044ba1727a6..206b8de6ffa 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_app_logic.nr @@ -1,5 +1,5 @@ use dep::types::abis::public_call_data::PublicCallData; -use dep::types::abis::kernel_data::PublicKernelData; +use dep::types::abis::public_kernel_data::PublicKernelData; use dep::types::PublicKernelCircuitPublicInputs; use dep::types::abis::kernel_circuit_public_inputs::PublicKernelCircuitPublicInputsBuilder; use dep::types::utils::arrays::array_to_bounded_vec; diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr index 0b5031f3f99..9c3f1ba4a98 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_setup.nr @@ -1,7 +1,7 @@ use crate::common; use dep::types::abis::{ kernel_circuit_public_inputs::{PublicKernelCircuitPublicInputs, PublicKernelCircuitPublicInputsBuilder}, - kernel_data::PublicKernelData, public_call_data::PublicCallData + public_kernel_data::PublicKernelData, public_call_data::PublicCallData }; struct PublicKernelSetupCircuitPrivateInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr index e6c2fa5cc68..632555d5307 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_tail.nr @@ -6,7 +6,7 @@ use dep::reset_kernel_lib::{ use dep::types::{ abis::{ accumulated_data::CombinedAccumulatedData, kernel_circuit_public_inputs::KernelCircuitPublicInputs, - kernel_data::PublicKernelData + public_kernel_data::PublicKernelData }, constants::MAX_PUBLIC_DATA_HINTS, merkle_tree::{conditionally_assert_check_membership, MembershipWitness}, @@ -114,7 +114,7 @@ mod tests { }; use dep::types::{ abis::{ - kernel_circuit_public_inputs::KernelCircuitPublicInputs, kernel_data::PublicKernelData, + kernel_circuit_public_inputs::KernelCircuitPublicInputs, public_kernel_data::PublicKernelData, nullifier::ScopedNullifier, nullifier_leaf_preimage::NullifierLeafPreimage }, address::AztecAddress, diff --git a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr index 88657fd1ce3..af033b1ba8e 100644 --- a/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr +++ b/noir-projects/noir-protocol-circuits/crates/public-kernel-lib/src/public_kernel_teardown.nr @@ -1,7 +1,7 @@ use crate::common; use dep::types::abis::{ kernel_circuit_public_inputs::{PublicKernelCircuitPublicInputs, PublicKernelCircuitPublicInputsBuilder}, - kernel_data::PublicKernelData, public_call_data::PublicCallData, gas_fees::GasFees + public_kernel_data::PublicKernelData, public_call_data::PublicCallData, gas_fees::GasFees }; struct PublicKernelTeardownCircuitPrivateInputs { diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis.nr index 9b95b164f5a..878bb933b1f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis.nr @@ -28,6 +28,7 @@ mod private_kernel; mod kernel_circuit_public_inputs; mod kernel_data; mod private_kernel_data; +mod public_kernel_data; mod call_request; mod private_call_stack_item; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr index 21e62582622..452cac06dc0 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/combined_accumulated_data.nr @@ -9,7 +9,7 @@ use crate::{ MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, COMBINED_ACCUMULATED_DATA_LENGTH }, - utils::arrays::array_merge, traits::{Empty, Serialize} + utils::arrays::array_merge, traits::{Empty, Serialize, Deserialize}, utils::reader::Reader }; struct CombinedAccumulatedData { @@ -106,3 +106,45 @@ impl Serialize for CombinedAccumulatedData { fields.storage } } + +impl Deserialize for CombinedAccumulatedData { + fn deserialize(fields: [Field; COMBINED_ACCUMULATED_DATA_LENGTH]) -> CombinedAccumulatedData { + let mut reader = Reader::new(fields); + + let item = CombinedAccumulatedData { + new_note_hashes: reader.read_array([0; MAX_NEW_NOTE_HASHES_PER_TX]), + new_nullifiers: reader.read_array([0; MAX_NEW_NULLIFIERS_PER_TX]), + new_l2_to_l1_msgs: reader.read_array([0; MAX_NEW_L2_TO_L1_MSGS_PER_TX]), + encrypted_logs_hash: reader.read(), + unencrypted_logs_hash: reader.read(), + encrypted_log_preimages_length: reader.read(), + unencrypted_log_preimages_length: reader.read(), + public_data_update_requests: reader.read_struct_array(PublicDataUpdateRequest::deserialize, [PublicDataUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]), + gas_used: reader.read_struct(Gas::deserialize), + }; + reader.finish(); + item + } +} + +impl Eq for CombinedAccumulatedData { + fn eq(self, other: Self) -> bool { + (self.new_note_hashes == other.new_note_hashes) & + (self.new_nullifiers == other.new_nullifiers) & + (self.new_l2_to_l1_msgs == other.new_l2_to_l1_msgs) & + (self.encrypted_logs_hash == other.encrypted_logs_hash) & + (self.unencrypted_logs_hash == other.unencrypted_logs_hash) & + (self.encrypted_log_preimages_length == other.encrypted_log_preimages_length) & + (self.unencrypted_log_preimages_length == other.unencrypted_log_preimages_length) & + (self.public_data_update_requests == other.public_data_update_requests) & + (self.gas_used == other.gas_used) + } +} + +#[test] +fn serialization_of_empty() { + let item = CombinedAccumulatedData::empty(); + let serialized = item.serialize(); + let deserialized = CombinedAccumulatedData::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data.nr index 502acaab910..4984175614c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/private_accumulated_data.nr @@ -3,7 +3,8 @@ use crate::{ call_request::CallRequest, gas::Gas, note_hash::ScopedNoteHash, nullifier::ScopedNullifier, side_effect::SideEffect }, - traits::Serialize, messaging::l2_to_l1_message::ScopedL2ToL1Message + traits::{Serialize, Deserialize, Eq, Empty}, messaging::l2_to_l1_message::ScopedL2ToL1Message, + utils::reader::Reader }; use crate::constants::{ MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, @@ -68,3 +69,61 @@ impl Serialize for PrivateAccumulatedData { fields.storage } } + +impl Deserialize for PrivateAccumulatedData { + fn deserialize(fields: [Field; PRIVATE_ACCUMULATED_DATA_LENGTH]) -> PrivateAccumulatedData { + let mut reader = Reader::new(fields); + + let item = PrivateAccumulatedData { + new_note_hashes: reader.read_struct_array(ScopedNoteHash::deserialize, [ScopedNoteHash::empty(); MAX_NEW_NOTE_HASHES_PER_TX]), + new_nullifiers: reader.read_struct_array(ScopedNullifier::deserialize, [ScopedNullifier::empty(); MAX_NEW_NULLIFIERS_PER_TX]), + new_l2_to_l1_msgs: reader.read_struct_array(ScopedL2ToL1Message::deserialize, [ScopedL2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_TX]), + encrypted_logs_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_ENCRYPTED_LOGS_PER_TX]), + unencrypted_logs_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_UNENCRYPTED_LOGS_PER_TX]), + encrypted_log_preimages_length: reader.read(), + unencrypted_log_preimages_length: reader.read(), + private_call_stack: reader.read_struct_array(CallRequest::deserialize, [CallRequest::empty(); MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX]), + public_call_stack: reader.read_struct_array(CallRequest::deserialize, [CallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX]), + }; + reader.finish(); + item + } +} + +impl Eq for PrivateAccumulatedData { + fn eq(self, other: Self) -> bool { + (self.new_note_hashes == other.new_note_hashes) & + (self.new_nullifiers == other.new_nullifiers) & + (self.new_l2_to_l1_msgs == other.new_l2_to_l1_msgs) & + (self.encrypted_logs_hashes == other.encrypted_logs_hashes) & + (self.unencrypted_logs_hashes == other.unencrypted_logs_hashes) & + (self.encrypted_log_preimages_length == other.encrypted_log_preimages_length) & + (self.unencrypted_log_preimages_length == other.unencrypted_log_preimages_length) & + (self.private_call_stack == other.private_call_stack) & + (self.public_call_stack == other.public_call_stack) + } +} + +impl Empty for PrivateAccumulatedData { + fn empty() -> Self { + PrivateAccumulatedData { + new_note_hashes: [ScopedNoteHash::empty(); MAX_NEW_NOTE_HASHES_PER_TX], + new_nullifiers: [ScopedNullifier::empty(); MAX_NEW_NULLIFIERS_PER_TX], + new_l2_to_l1_msgs: [ScopedL2ToL1Message::empty(); MAX_NEW_L2_TO_L1_MSGS_PER_TX], + encrypted_logs_hashes: [SideEffect::empty(); MAX_ENCRYPTED_LOGS_PER_TX], + unencrypted_logs_hashes: [SideEffect::empty(); MAX_UNENCRYPTED_LOGS_PER_TX], + encrypted_log_preimages_length: 0, + unencrypted_log_preimages_length: 0, + private_call_stack: [CallRequest::empty(); MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX], + public_call_stack: [CallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX], + } + } +} + +#[test] +fn serialization_of_empty() { + let item = PrivateAccumulatedData::empty(); + let serialized = item.serialize(); + let deserialized = PrivateAccumulatedData::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr index 8a4b4f8c129..518a24b1675 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/accumulated_data/public_accumulated_data.nr @@ -6,9 +6,9 @@ use crate::{ constants::{ MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_ENCRYPTED_LOGS_PER_TX, - MAX_UNENCRYPTED_LOGS_PER_TX + MAX_UNENCRYPTED_LOGS_PER_TX, PUBLIC_ACCUMULATED_DATA_LENGTH }, - traits::Empty + traits::{Empty, Serialize, Deserialize}, utils::reader::Reader }; struct PublicAccumulatedData { @@ -47,3 +47,88 @@ impl Empty for PublicAccumulatedData { } } } + +impl Serialize for PublicAccumulatedData { + fn serialize(self) -> [Field; PUBLIC_ACCUMULATED_DATA_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); + + for i in 0..MAX_NEW_NOTE_HASHES_PER_TX { + fields.extend_from_array(self.new_note_hashes[i].serialize()); + } + + for i in 0..MAX_NEW_NULLIFIERS_PER_TX { + fields.extend_from_array(self.new_nullifiers[i].serialize()); + } + + fields.extend_from_array(self.new_l2_to_l1_msgs); + + for i in 0..MAX_ENCRYPTED_LOGS_PER_TX { + fields.extend_from_array(self.encrypted_logs_hashes[i].serialize()); + } + + for i in 0..MAX_UNENCRYPTED_LOGS_PER_TX { + fields.extend_from_array(self.unencrypted_logs_hashes[i].serialize()); + } + + fields.push(self.encrypted_log_preimages_length); + fields.push(self.unencrypted_log_preimages_length); + + for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX { + fields.extend_from_array(self.public_data_update_requests[i].serialize()); + } + + for i in 0..MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX { + fields.extend_from_array(self.public_call_stack[i].serialize()); + } + + fields.extend_from_array(self.gas_used.serialize()); + + assert_eq(fields.len(), PUBLIC_ACCUMULATED_DATA_LENGTH); + + fields.storage + } +} + +impl Deserialize for PublicAccumulatedData { + fn deserialize(fields: [Field; PUBLIC_ACCUMULATED_DATA_LENGTH]) -> PublicAccumulatedData { + let mut reader = Reader::new(fields); + + let item = PublicAccumulatedData { + new_note_hashes: reader.read_struct_array(NoteHash::deserialize, [NoteHash::empty(); MAX_NEW_NOTE_HASHES_PER_TX]), + new_nullifiers: reader.read_struct_array(Nullifier::deserialize, [Nullifier::empty(); MAX_NEW_NULLIFIERS_PER_TX]), + new_l2_to_l1_msgs: reader.read_array([0; MAX_NEW_L2_TO_L1_MSGS_PER_TX]), + encrypted_logs_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_ENCRYPTED_LOGS_PER_TX]), + unencrypted_logs_hashes: reader.read_struct_array(SideEffect::deserialize, [SideEffect::empty(); MAX_UNENCRYPTED_LOGS_PER_TX]), + encrypted_log_preimages_length: reader.read(), + unencrypted_log_preimages_length: reader.read(), + public_data_update_requests: reader.read_struct_array(PublicDataUpdateRequest::deserialize, [PublicDataUpdateRequest::empty(); MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX]), + public_call_stack: reader.read_struct_array(CallRequest::deserialize, [CallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX]), + gas_used: reader.read_struct(Gas::deserialize), + }; + reader.finish(); + item + } +} + +impl Eq for PublicAccumulatedData { + fn eq(self, other: Self) -> bool { + (self.new_note_hashes == other.new_note_hashes) & + (self.new_nullifiers == other.new_nullifiers) & + (self.new_l2_to_l1_msgs == other.new_l2_to_l1_msgs) & + (self.encrypted_logs_hashes == other.encrypted_logs_hashes) & + (self.unencrypted_logs_hashes == other.unencrypted_logs_hashes) & + (self.encrypted_log_preimages_length == other.encrypted_log_preimages_length) & + (self.unencrypted_log_preimages_length == other.unencrypted_log_preimages_length) & + (self.public_data_update_requests == other.public_data_update_requests) & + (self.public_call_stack == other.public_call_stack) & + (self.gas_used == other.gas_used) + } +} + +#[test] +fn serialization_of_empty() { + let item = PublicAccumulatedData::empty(); + let serialized = item.serialize(); + let deserialized = PublicAccumulatedData::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr index 2c667c25f08..fe4a440a52d 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/call_request.nr @@ -1,8 +1,9 @@ use crate::address::AztecAddress; use dep::std::cmp::Eq; -use crate::traits::{Empty, Serialize}; +use crate::traits::{Empty, Serialize, Deserialize}; use crate::abis::caller_context::CallerContext; use crate::constants::CALL_REQUEST_LENGTH; +use crate::utils::reader::Reader; struct CallRequest { hash: Field, @@ -49,3 +50,27 @@ impl Serialize for CallRequest { fields.storage } } + +impl Deserialize for CallRequest { + fn deserialize(fields: [Field; CALL_REQUEST_LENGTH]) -> CallRequest { + let mut reader = Reader::new(fields); + + let item = CallRequest { + hash: reader.read(), + caller_contract_address: reader.read_struct(AztecAddress::deserialize), + caller_context: reader.read_struct(CallerContext::deserialize), + start_side_effect_counter: reader.read() as u32, + end_side_effect_counter: reader.read() as u32, + }; + reader.finish(); + item + } +} + +#[test] +fn serialization_of_empty() { + let item = CallRequest::empty(); + let serialized = item.serialize(); + let deserialized = CallRequest::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr index 70c929fc04a..e9c7b283947 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/caller_context.nr @@ -1,7 +1,8 @@ use crate::address::AztecAddress; use dep::std::cmp::Eq; -use crate::traits::{Empty, Serialize}; +use crate::traits::{Empty, Serialize, Deserialize}; use crate::constants::CALLER_CONTEXT_LENGTH; +use crate::utils::reader::Reader; struct CallerContext { msg_sender: AztecAddress, @@ -42,3 +43,24 @@ impl Serialize for CallerContext { fields.storage } } + +impl Deserialize for CallerContext { + fn deserialize(fields: [Field; CALLER_CONTEXT_LENGTH]) -> CallerContext { + let mut reader = Reader::new(fields); + + let item = CallerContext { + msg_sender: reader.read_struct(AztecAddress::deserialize), + storage_contract_address: reader.read_struct(AztecAddress::deserialize), + }; + reader.finish(); + item + } +} + +#[test] +fn serialization_of_empty() { + let item = CallerContext::empty(); + let serialized = item.serialize(); + let deserialized = CallerContext::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr index 2fcd910a23b..7f4496af650 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/combined_constant_data.nr @@ -1,8 +1,9 @@ use crate::transaction::tx_context::TxContext; use crate::header::Header; -use crate::traits::{Empty, Serialize}; +use crate::traits::{Empty, Serialize, Deserialize}; use crate::abis::global_variables::GlobalVariables; use crate::constants::COMBINED_CONSTANT_DATA_LENGTH; +use crate::utils::reader::Reader; struct CombinedConstantData { historical_header: Header, @@ -44,3 +45,33 @@ impl Serialize for CombinedConstantData { fields.storage } } + +impl Deserialize for CombinedConstantData { + fn deserialize(fields: [Field; COMBINED_CONSTANT_DATA_LENGTH]) -> CombinedConstantData { + let mut reader = Reader::new(fields); + + let item = CombinedConstantData { + historical_header: reader.read_struct(Header::deserialize), + tx_context: reader.read_struct(TxContext::deserialize), + global_variables: reader.read_struct(GlobalVariables::deserialize), + }; + reader.finish(); + item + } +} + +impl Eq for CombinedConstantData { + fn eq(self, other: Self) -> bool { + (self.historical_header.eq(other.historical_header)) & + (self.tx_context.eq(other.tx_context)) & + (self.global_variables.eq(other.global_variables)) + } +} + +#[test] +fn serialization_of_empty() { + let item = CombinedConstantData::empty(); + let serialized = item.serialize(); + let deserialized = CombinedConstantData::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas.nr index 4354f316c3a..cd5f87f3cfa 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas.nr @@ -69,3 +69,11 @@ impl Empty for Gas { } } +#[test] +fn serialization_of_empty() { + let item = Gas::empty(); + let serialized = item.serialize(); + let deserialized = Gas::deserialize(serialized); + assert(item.eq(deserialized)); +} + diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_fees.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_fees.nr index 70680bad93a..e1ad93d61a0 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_fees.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_fees.nr @@ -46,3 +46,11 @@ impl Empty for GasFees { GasFees::new(0, 0) } } + +#[test] +fn serialization_of_empty() { + let item = GasFees::empty(); + let serialized = item.serialize(); + let deserialized = GasFees::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_settings.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_settings.nr index 5d1081db428..5baff152aca 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_settings.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/gas_settings.nr @@ -69,3 +69,11 @@ impl Deserialize for GasSettings { GasSettings::new(reader.read_struct(Gas::deserialize), reader.read_struct(Gas::deserialize), reader.read_struct(GasFees::deserialize), reader.read()) } } + +#[test] +fn serialization_of_empty() { + let item = GasSettings::empty(); + let serialized = item.serialize(); + let deserialized = GasSettings::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs.nr index 0acec33c99c..7139411cd3c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/private_kernel_circuit_public_inputs.nr @@ -3,7 +3,8 @@ use crate::abis::{ validation_requests::ValidationRequests, call_request::CallRequest }; use crate::constants::PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH; -use crate::traits::{Serialize, Deserialize}; +use crate::traits::{Serialize, Deserialize, Eq, Empty}; +use crate::utils::reader::Reader; use crate::address::AztecAddress; struct PrivateKernelCircuitPublicInputs { @@ -31,3 +32,51 @@ impl Serialize for PrivateKernelCir fields.storage } } + +impl Deserialize for PrivateKernelCircuitPublicInputs { + fn deserialize(fields: [Field; PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH]) -> PrivateKernelCircuitPublicInputs { + let mut reader = Reader::new(fields); + let item = Self { + min_revertible_side_effect_counter: reader.read() as u32, + validation_requests: reader.read_struct(ValidationRequests::deserialize), + end: reader.read_struct(PrivateAccumulatedData::deserialize), + constants: reader.read_struct(CombinedConstantData::deserialize), + public_teardown_call_request: reader.read_struct(CallRequest::deserialize), + fee_payer: reader.read_struct(AztecAddress::deserialize), + }; + + reader.finish(); + item + } +} + +impl Eq for PrivateKernelCircuitPublicInputs { + fn eq(self, other: Self) -> bool { + (self.min_revertible_side_effect_counter == other.min_revertible_side_effect_counter) & + (self.validation_requests.eq(other.validation_requests)) & + (self.end.eq(other.end)) & + (self.constants.eq(other.constants)) & + (self.public_teardown_call_request.eq(other.public_teardown_call_request)) + } +} + +impl Empty for PrivateKernelCircuitPublicInputs { + fn empty() -> Self { + Self { + min_revertible_side_effect_counter: 0, + validation_requests: ValidationRequests::empty(), + end: PrivateAccumulatedData::empty(), + constants: CombinedConstantData::empty(), + public_teardown_call_request: CallRequest::empty(), + fee_payer: AztecAddress::empty() + } + } +} + +#[test] +fn serialization_of_empty() { + let item = PrivateKernelCircuitPublicInputs::empty(); + let serialized = item.serialize(); + let deserialized = PrivateKernelCircuitPublicInputs::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr index e5a83da9ac3..c9216326cb0 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/public_kernel_circuit_public_inputs.nr @@ -2,8 +2,10 @@ use crate::abis::{ accumulated_data::PublicAccumulatedData, combined_constant_data::CombinedConstantData, validation_requests::{RollupValidationRequests, ValidationRequests}, call_request::CallRequest }; +use crate::constants::{MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH}; +use crate::traits::{Empty, Serialize, Deserialize, Eq}; +use crate::utils::reader::Reader; use crate::address::AztecAddress; -use crate::constants::MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX; struct PublicKernelCircuitPublicInputs { validation_requests: ValidationRequests, @@ -33,3 +35,77 @@ impl PublicKernelCircuitPublicInputs { self.public_teardown_call_stack[0].hash != 0 } } + +impl Empty for PublicKernelCircuitPublicInputs { + fn empty() -> Self { + PublicKernelCircuitPublicInputs { + validation_requests: ValidationRequests::empty(), + end_non_revertible: PublicAccumulatedData::empty(), + end: PublicAccumulatedData::empty(), + constants: CombinedConstantData::empty(), + revert_code: 0, + public_teardown_call_stack: [CallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX], + fee_payer: AztecAddress::empty() + } + } +} + +impl Serialize for PublicKernelCircuitPublicInputs { + fn serialize(self) -> [Field; PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); + + fields.extend_from_array(self.validation_requests.serialize()); + fields.extend_from_array(self.end_non_revertible.serialize()); + fields.extend_from_array(self.end.serialize()); + fields.extend_from_array(self.constants.serialize()); + fields.push(self.revert_code as Field); + + for i in 0..MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX { + fields.extend_from_array(self.public_teardown_call_stack[i].serialize()); + } + + fields.extend_from_array(self.fee_payer.serialize()); + + + assert_eq(fields.len(), PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH); + + fields.storage + } +} + +impl Deserialize for PublicKernelCircuitPublicInputs { + fn deserialize(fields: [Field; PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH]) -> PublicKernelCircuitPublicInputs { + let mut reader = Reader::new(fields); + + let item = PublicKernelCircuitPublicInputs { + validation_requests: reader.read_struct(ValidationRequests::deserialize), + end_non_revertible: reader.read_struct(PublicAccumulatedData::deserialize), + end: reader.read_struct(PublicAccumulatedData::deserialize), + constants: reader.read_struct(CombinedConstantData::deserialize), + revert_code: reader.read() as u8, + public_teardown_call_stack: reader.read_struct_array(CallRequest::deserialize, [CallRequest::empty(); MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX]), + fee_payer: reader.read_struct(AztecAddress::deserialize), + }; + reader.finish(); + item + } +} + +impl Eq for PublicKernelCircuitPublicInputs { + fn eq(self, other: Self) -> bool { + (self.validation_requests == other.validation_requests) & + (self.end_non_revertible == other.end_non_revertible) & + (self.end == other.end) & + (self.constants == other.constants) & + (self.revert_code == other.revert_code) & + (self.public_teardown_call_stack == other.public_teardown_call_stack) + } +} + +#[test] +fn serialization_of_empty() { + let item = PublicKernelCircuitPublicInputs::empty(); + let serialized = item.serialize(); + let deserialized = PublicKernelCircuitPublicInputs::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr index 6bdbbb4d4a5..c23b84c9205 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_data.nr @@ -1,14 +1,6 @@ use crate::mocked::{Proof, VerificationKey}; use crate::constants::VK_TREE_HEIGHT; -use crate::abis::kernel_circuit_public_inputs::{PublicKernelCircuitPublicInputs, KernelCircuitPublicInputs}; - -struct PublicKernelData { - public_inputs: PublicKernelCircuitPublicInputs, - proof: Proof, - vk: VerificationKey, - vk_index: u32, - vk_path: [Field; VK_TREE_HEIGHT], -} +use crate::abis::kernel_circuit_public_inputs::KernelCircuitPublicInputs; struct KernelData { public_inputs: KernelCircuitPublicInputs, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/max_block_number.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/max_block_number.nr index bbd36f8bf43..6aa7d5db67f 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/max_block_number.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/max_block_number.nr @@ -73,6 +73,14 @@ impl MaxBlockNumber { } } +#[test] +fn serialization_of_empty() { + let item = MaxBlockNumber::empty(); + let serialized = item.serialize(); + let deserialized = MaxBlockNumber::deserialize(serialized); + assert(item.eq(deserialized)); +} + #[test] fn zeroed_is_none() { // Large parts of the kernel rely on zeroed to initialize structs. This conveniently matches what `default` does, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash.nr index 53a248718c2..a41f3daa1cc 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash.nr @@ -125,3 +125,19 @@ impl ScopedNoteHash { NoteHash { value: self.note_hash.value, counter: 0 } } } + +#[test] +fn serialization_of_empty() { + let item = NoteHash::empty(); + let serialized = item.serialize(); + let deserialized = NoteHash::deserialize(serialized); + assert(item.eq(deserialized)); +} + +#[test] +fn serialization_of_empty_scoped() { + let item = ScopedNoteHash::empty(); + let serialized = item.serialize(); + let deserialized = ScopedNoteHash::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash_leaf_preimage.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash_leaf_preimage.nr index 9a0c9efb7ea..f5eadd9dc6e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash_leaf_preimage.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/note_hash_leaf_preimage.nr @@ -2,7 +2,7 @@ global NOTE_HASH_LEAF_PREIMAGE_LENGTH: u64 = 1; use crate::{ abis::{read_request::ScopedReadRequest, side_effect::Readable}, hash::silo_note_hash, - merkle_tree::leaf_preimage::LeafPreimage, traits::{Empty, Hash} + merkle_tree::leaf_preimage::LeafPreimage, traits::{Empty, Hash, Eq} }; struct NoteHashLeafPreimage { @@ -47,3 +47,17 @@ impl NoteHashLeafPreimage { Self { value: fields[0] } } } + +impl Eq for NoteHashLeafPreimage{ + fn eq(self, other: Self) -> bool { + self.value == other.value + } +} + +#[test] +fn serialization_of_empty() { + let item = NoteHashLeafPreimage::empty(); + let serialized = item.serialize(); + let deserialized = NoteHashLeafPreimage::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier.nr index da4c140d43d..b7f95facb3c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier.nr @@ -118,7 +118,7 @@ impl Deserialize for ScopedNullifier { let mut reader = Reader::new(values); let res = Self { nullifier: reader.read_struct(Nullifier::deserialize), - contract_address: AztecAddress::from_field(values[3]), + contract_address: reader.read_struct(AztecAddress::deserialize), }; reader.finish(); res @@ -145,3 +145,19 @@ impl ScopedNullifier { Nullifier { value: self.nullifier.value, counter: 0, note_hash: 0 } } } + +#[test] +fn serialization_of_empty() { + let item = Nullifier::empty(); + let serialized = item.serialize(); + let deserialized = Nullifier::deserialize(serialized); + assert(item.eq(deserialized)); +} + +#[test] +fn serialization_of_empty_scoped() { + let item = ScopedNullifier::empty(); + let serialized = item.serialize(); + let deserialized = ScopedNullifier::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr index 19789c938a6..0424f6a3d7e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_key_validation_request.nr @@ -84,10 +84,18 @@ impl Deserialize for ScopedNulli let mut reader = Reader::new(fields); let res = Self { request: reader.read_struct(NullifierKeyValidationRequest::deserialize), - contract_address: AztecAddress::from_field(fields[3]), + contract_address: reader.read_struct(AztecAddress::deserialize), }; reader.finish(); res } } +#[test] +fn serialization_of_empty() { + let item = ScopedNullifierKeyValidationRequest::empty(); + let serialized = item.serialize(); + let deserialized = ScopedNullifierKeyValidationRequest::deserialize(serialized); + assert(item.eq(deserialized)); +} + diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr index 2eaf66edc90..d11d743721b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/nullifier_leaf_preimage.nr @@ -75,3 +75,19 @@ impl NullifierLeafPreimage { Self { nullifier: fields[0], next_nullifier: fields[1], next_index: fields[2] as u64 } } } + +impl Eq for NullifierLeafPreimage { + fn eq(self, other: Self) -> bool { + (self.nullifier == other.nullifier) & + (self.next_nullifier == other.next_nullifier) & + (self.next_index == other.next_index) + } +} + +#[test] +fn serialization_of_empty() { + let item = NullifierLeafPreimage::empty(); + let serialized = item.serialize(); + let deserialized = NullifierLeafPreimage::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr index a434580019b..4fad899e121 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_read.nr @@ -1,6 +1,6 @@ use crate::constants::{GENERATOR_INDEX__PUBLIC_DATA_READ, PUBLIC_DATA_READ_LENGTH}; use dep::std::cmp::Eq; -use crate::traits::{Empty, Hash, Serialize}; +use crate::traits::{Empty, Hash, Serialize, Deserialize}; struct PublicDataRead { leaf_slot : Field, @@ -42,3 +42,20 @@ impl Serialize for PublicDataRead { [self.leaf_slot, self.value] } } + +impl Deserialize for PublicDataRead { + fn deserialize(fields: [Field; PUBLIC_DATA_READ_LENGTH]) -> Self { + PublicDataRead { + leaf_slot: fields[0], + value: fields[1], + } + } +} + +#[test] +fn serialization_of_empty() { + let item = PublicDataRead::empty(); + let serialized = item.serialize(); + let deserialized = PublicDataRead::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr index ab887214acf..bbbc360fd8b 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_data_update_request.nr @@ -1,6 +1,6 @@ use crate::constants::{PUBLIC_DATA_UPDATE_REQUEST_LENGTH, GENERATOR_INDEX__PUBLIC_DATA_UPDATE_REQUEST}; use dep::std::cmp::Eq; -use crate::traits::{Empty, Hash, Serialize}; +use crate::traits::{Empty, Hash, Serialize, Deserialize}; struct PublicDataUpdateRequest { leaf_slot : Field, @@ -43,3 +43,20 @@ impl Serialize for PublicDataUpdateRequest { [self.leaf_slot, self.new_value] } } + +impl Deserialize for PublicDataUpdateRequest { + fn deserialize(fields: [Field; PUBLIC_DATA_UPDATE_REQUEST_LENGTH]) -> PublicDataUpdateRequest { + PublicDataUpdateRequest { + leaf_slot: fields[0], + new_value: fields[1], + } + } +} + +#[test] +fn serialization_of_empty() { + let item = PublicDataUpdateRequest::empty(); + let serialized = item.serialize(); + let deserialized = PublicDataUpdateRequest::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr new file mode 100644 index 00000000000..16b4054e58c --- /dev/null +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr @@ -0,0 +1,11 @@ +use crate::mocked::{Proof, VerificationKey}; +use crate::constants::VK_TREE_HEIGHT; +use crate::abis::kernel_circuit_public_inputs::{PublicKernelCircuitPublicInputs, KernelCircuitPublicInputs}; + +struct PublicKernelData { + public_inputs: PublicKernelCircuitPublicInputs, + proof: Proof, + vk: VerificationKey, + vk_index: u32, + vk_path: [Field; VK_TREE_HEIGHT], +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr index 6d3663354b0..c8a0286ce3e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/read_request.nr @@ -79,7 +79,7 @@ impl Deserialize for ScopedReadRequest { let mut reader = Reader::new(values); let res = Self { read_request: reader.read_struct(ReadRequest::deserialize), - contract_address: AztecAddress::from_field(values[2]), + contract_address: reader.read_struct(AztecAddress::deserialize), }; reader.finish(); res @@ -94,3 +94,19 @@ impl ScopedReadRequest { self.read_request.counter } } + +#[test] +fn serialization_of_empty_read() { + let item = ReadRequest::empty(); + let serialized = item.serialize(); + let deserialized = ReadRequest::deserialize(serialized); + assert(item.eq(deserialized)); +} + +#[test] +fn serialization_of_empty_scoped() { + let item = ScopedReadRequest::empty(); + let serialized = item.serialize(); + let deserialized = ScopedReadRequest::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr index 78b54a59a0b..1f402b623b4 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/side_effect.nr @@ -75,3 +75,11 @@ impl Deserialize for SideEffect { } } } + +#[test] +fn serialization_of_empty() { + let item = SideEffect::empty(); + let serialized = item.serialize(); + let deserialized = SideEffect::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/rollup_validation_requests.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/rollup_validation_requests.nr index d1761a1a859..56688fe64fb 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/rollup_validation_requests.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/rollup_validation_requests.nr @@ -1,6 +1,6 @@ use crate::{ - abis::max_block_number::MaxBlockNumber, traits::{Empty, Serialize}, - constants::ROLLUP_VALIDATION_REQUESTS_LENGTH + abis::max_block_number::MaxBlockNumber, traits::{Empty, Serialize, Deserialize}, + constants::ROLLUP_VALIDATION_REQUESTS_LENGTH, utils::reader::Reader }; // These are validation requests that cannot be fulfilled in the current context (private or public), and must be @@ -23,3 +23,28 @@ impl Serialize for RollupValidationRequests { } } +impl Deserialize for RollupValidationRequests { + fn deserialize(fields: [Field; ROLLUP_VALIDATION_REQUESTS_LENGTH]) -> RollupValidationRequests { + let mut reader = Reader::new(fields); + let item = Self { + max_block_number: reader.read_struct(MaxBlockNumber::deserialize), + }; + reader.finish(); + item + } +} + +impl Eq for RollupValidationRequests { + fn eq(self, other: Self) -> bool { + self.max_block_number.eq(other.max_block_number) + } +} + +#[test] +fn serialization_of_empty() { + let item = RollupValidationRequests::empty(); + let serialized = item.serialize(); + let deserialized = RollupValidationRequests::deserialize(serialized); + assert(item.eq(deserialized)); +} + diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests.nr index d8e34e36311..5a1e5ad5e77 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests.nr @@ -10,7 +10,7 @@ use crate::{ MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX, VALIDATION_REQUESTS_LENGTH }, - traits::Serialize + traits::{Serialize, Deserialize, Empty}, utils::reader::Reader }; // TODO - Use specific structs for private and public: PrivateValidationRequests vs PublicValidationRequests @@ -54,3 +54,54 @@ impl Serialize for ValidationRequests { fields.storage } } + +impl Deserialize for ValidationRequests { + fn deserialize(serialized: [Field; VALIDATION_REQUESTS_LENGTH]) -> Self { + // TODO(#4390): This should accept a reader ^ to avoid copying data. + let mut reader = Reader::new(serialized); + let item = Self { + for_rollup: reader.read_struct(RollupValidationRequests::deserialize), + note_hash_read_requests: reader.read_struct_array(ScopedReadRequest::deserialize, [ScopedReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_TX]), + nullifier_read_requests: reader.read_struct_array(ScopedReadRequest::deserialize, [ScopedReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_TX]), + nullifier_non_existent_read_requests: reader.read_struct_array(ScopedReadRequest::deserialize, [ScopedReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX]), + nullifier_key_validation_requests: reader.read_struct_array(ScopedNullifierKeyValidationRequest::deserialize, [ScopedNullifierKeyValidationRequest::empty(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX]), + public_data_reads: reader.read_struct_array(PublicDataRead::deserialize, [PublicDataRead::empty(); MAX_PUBLIC_DATA_READS_PER_TX]), + }; + + reader.finish(); + item + } +} + +impl Empty for ValidationRequests { + fn empty() -> Self { + + ValidationRequests { + for_rollup: RollupValidationRequests::empty(), + note_hash_read_requests: [ScopedReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_TX], + nullifier_read_requests: [ScopedReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_TX], + nullifier_non_existent_read_requests: [ScopedReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX], + nullifier_key_validation_requests: [ScopedNullifierKeyValidationRequest::empty(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX], + public_data_reads: [PublicDataRead::empty(); MAX_PUBLIC_DATA_READS_PER_TX], + } + } +} + +impl Eq for ValidationRequests { + fn eq(self, other: Self) -> bool { + self.for_rollup.eq(other.for_rollup) & + (self.note_hash_read_requests == other.note_hash_read_requests) & + (self.nullifier_read_requests == other.nullifier_read_requests) & + (self.nullifier_non_existent_read_requests == other.nullifier_non_existent_read_requests) & + (self.nullifier_key_validation_requests == other.nullifier_key_validation_requests) & + (self.public_data_reads == other.public_data_reads) + } +} + +#[test] +fn serialization_of_empty() { + let item = ValidationRequests::empty(); + let serialized = item.serialize(); + let deserialized = ValidationRequests::deserialize(serialized); + assert(item.eq(deserialized)); +} 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 d7c6c6d44dd..396174ec5b9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -190,6 +190,9 @@ global CALL_REQUEST_LENGTH = 1 + AZTEC_ADDRESS_LENGTH + CALLER_CONTEXT_LENGTH + global PRIVATE_ACCUMULATED_DATA_LENGTH = (SCOPED_NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_TX) + (SCOPED_NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_TX) + (MAX_NEW_L2_TO_L1_MSGS_PER_TX * SCOPED_L2_TO_L1_MESSAGE_LENGTH) + (SIDE_EFFECT_LENGTH * MAX_ENCRYPTED_LOGS_PER_TX) + (SIDE_EFFECT_LENGTH * MAX_UNENCRYPTED_LOGS_PER_TX) + 2 + (CALL_REQUEST_LENGTH * MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX) + (CALL_REQUEST_LENGTH * MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX); global PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1 + VALIDATION_REQUESTS_LENGTH + PRIVATE_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + CALL_REQUEST_LENGTH + AZTEC_ADDRESS_LENGTH; +global PUBLIC_ACCUMULATED_DATA_LENGTH = (MAX_NEW_NOTE_HASHES_PER_TX * NOTE_HASH_LENGTH) + (MAX_NEW_NULLIFIERS_PER_TX * NULLIFIER_LENGTH) + (MAX_NEW_L2_TO_L1_MSGS_PER_TX * 1) + (MAX_ENCRYPTED_LOGS_PER_TX * SIDE_EFFECT_LENGTH) + (MAX_UNENCRYPTED_LOGS_PER_TX * SIDE_EFFECT_LENGTH) + 2 + (MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * PUBLIC_DATA_UPDATE_REQUEST_LENGTH) + (MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX * CALL_REQUEST_LENGTH) + GAS_LENGTH; +global PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = VALIDATION_REQUESTS_LENGTH + PUBLIC_ACCUMULATED_DATA_LENGTH + PUBLIC_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + 1 + (MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX * CALL_REQUEST_LENGTH) + AZTEC_ADDRESS_LENGTH; + global ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH: u64 = 2 + FUNCTION_DATA_LENGTH + CALL_CONTEXT_LENGTH; global GET_NOTES_ORACLE_RETURN_LENGTH: u64 = 674; global NOTE_HASHES_NUM_BYTES_PER_BASE_ROLLUP: Field = 2048; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr index 04ee782bd3d..38adc0a4f32 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_read.nr @@ -49,3 +49,11 @@ impl StorageRead { self.storage_slot == 0 } } + +#[test] +fn serialization_of_empty() { + let item = StorageRead::empty(); + let serialized = item.serialize(); + let deserialized = StorageRead::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr index 34654e18775..5c9e244f937 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contrakt/storage_update_request.nr @@ -51,3 +51,11 @@ impl StorageUpdateRequest { self.storage_slot == 0 } } + +#[test] +fn serialization_of_empty() { + let item = StorageUpdateRequest::empty(); + let serialized = item.serialize(); + let deserialized = StorageUpdateRequest::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr index 8f21f8e2c77..a16cbb1f153 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/messaging/l2_to_l1_message.nr @@ -93,3 +93,19 @@ impl Deserialize for ScopedL2ToL1Message { res } } + +#[test] +fn serialization_of_empty_l2() { + let item = L2ToL1Message::empty(); + let serialized = item.serialize(); + let deserialized = L2ToL1Message::deserialize(serialized); + assert(item.eq(deserialized)); +} + +#[test] +fn serialization_of_empty_scoped_l2() { + let item = ScopedL2ToL1Message::empty(); + let serialized = item.serialize(); + let deserialized = ScopedL2ToL1Message::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/recursion/proof.nr b/noir-projects/noir-protocol-circuits/crates/types/src/recursion/proof.nr index fd30f4469bf..eb1bd1a2af4 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/recursion/proof.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/recursion/proof.nr @@ -50,3 +50,31 @@ impl Empty for NestedRecursiveProof { } } } + +impl Eq for RecursiveProof { + fn eq(self, other: Self) -> bool { + (self.fields == other.fields) + } +} + +impl Eq for NestedRecursiveProof { + fn eq(self, other: Self) -> bool { + (self.fields == other.fields) + } +} + +#[test] +fn serialization_of_empty_recursive() { + let item = RecursiveProof::empty(); + let serialized = item.serialize(); + let deserialized = RecursiveProof::deserialize(serialized); + assert(item.eq(deserialized)); +} + +#[test] +fn serialization_of_empty_nested() { + let item = NestedRecursiveProof::empty(); + let serialized = item.serialize(); + let deserialized = NestedRecursiveProof::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr b/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr index c4cc9b2230f..59f27758760 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/recursion/verification_key.nr @@ -37,3 +37,18 @@ impl Empty for VerificationKey { } } } + +impl Eq for VerificationKey { + fn eq(self, other: Self) -> bool { + (self.hash == other.hash) & + (self.key == other.key) + } +} + +#[test] +fn serialization_of_empty() { + let key = VerificationKey::empty(); + let serialized = key.serialize(); + let deserialized = VerificationKey::deserialize(serialized); + assert(key.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr index 2235dc7e7ac..c8d4f452bc1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr @@ -5,7 +5,7 @@ use crate::{ accumulated_data::{CombinedAccumulatedData, PrivateAccumulatedData, PrivateAccumulatedDataBuilder, PublicAccumulatedData}, global_variables::GlobalVariables, combined_constant_data::CombinedConstantData, kernel_circuit_public_inputs::{KernelCircuitPublicInputs, PrivateKernelCircuitPublicInputs, PublicKernelCircuitPublicInputs}, - kernel_data::{PublicKernelData, KernelData}, max_block_number::MaxBlockNumber, + kernel_data::KernelData, public_kernel_data::PublicKernelData, max_block_number::MaxBlockNumber, private_kernel_data::PrivateKernelData, note_hash::{NoteHash, ScopedNoteHash}, nullifier::{Nullifier, ScopedNullifier}, nullifier_key_validation_request::ScopedNullifierKeyValidationRequest, diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index ff27401376b..968f3215c08 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -193,7 +193,26 @@ export const PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = VALIDATION_REQUESTS_LENGTH + PRIVATE_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + - CALL_REQUEST_LENGTH; + CALL_REQUEST_LENGTH + + AZTEC_ADDRESS_LENGTH; +export const PUBLIC_ACCUMULATED_DATA_LENGTH = + MAX_NEW_NOTE_HASHES_PER_TX * NOTE_HASH_LENGTH + + MAX_NEW_NULLIFIERS_PER_TX * NULLIFIER_LENGTH + + MAX_NEW_L2_TO_L1_MSGS_PER_TX * 1 + + MAX_ENCRYPTED_LOGS_PER_TX * SIDE_EFFECT_LENGTH + + MAX_UNENCRYPTED_LOGS_PER_TX * SIDE_EFFECT_LENGTH + + 2 + + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * PUBLIC_DATA_UPDATE_REQUEST_LENGTH + + MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX * CALL_REQUEST_LENGTH + + GAS_LENGTH; +export const PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = + VALIDATION_REQUESTS_LENGTH + + PUBLIC_ACCUMULATED_DATA_LENGTH + + PUBLIC_ACCUMULATED_DATA_LENGTH + + COMBINED_CONSTANT_DATA_LENGTH + + 1 + + MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX * CALL_REQUEST_LENGTH + + AZTEC_ADDRESS_LENGTH; export const ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH = 2 + FUNCTION_DATA_LENGTH + CALL_CONTEXT_LENGTH; export const GET_NOTES_ORACLE_RETURN_LENGTH = 674; export const NOTE_HASHES_NUM_BYTES_PER_BASE_ROLLUP = 2048;