Skip to content

Commit

Permalink
chore: Update serialisation (#6378)
Browse files Browse the repository at this point in the history
This PR adds lots of serialisation methods and tests to
`noir-protocol-circuits`.

---------

Co-authored-by: Aztec Bot <49558828+AztecBot@users.noreply.github.com>
  • Loading branch information
PhilWindle and AztecBot authored May 14, 2024
1 parent 8eb0398 commit 527129d
Show file tree
Hide file tree
Showing 42 changed files with 839 additions and 69 deletions.
45 changes: 21 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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
Expand Down Expand Up @@ -124,15 +121,15 @@ 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:
# # fetch-depth: 100 # Downloading base benchmark from master requires access to history
# # 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
Expand All @@ -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
Expand All @@ -171,15 +168,15 @@ 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 }}" }
# 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: 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
Expand All @@ -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
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
47 changes: 42 additions & 5 deletions barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) +
Expand All @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -106,3 +106,45 @@ impl Serialize<COMBINED_ACCUMULATED_DATA_LENGTH> for CombinedAccumulatedData {
fields.storage
}
}

impl Deserialize<COMBINED_ACCUMULATED_DATA_LENGTH> 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));
}
Loading

0 comments on commit 527129d

Please sign in to comment.