From 161c2ff8c22a723a425a41ac96c80dea890dacc8 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Mon, 13 May 2024 22:34:03 +0000 Subject: [PATCH 1/7] Update serialisation --- .../vm/avm_trace/aztec_constants.hpp | 44 ++++++++- .../src/core/libraries/ConstantsGen.sol | 94 +++++-------------- .../crates/public-kernel-lib/src/common.nr | 10 +- .../src/public_kernel_app_logic.nr | 2 +- .../src/public_kernel_setup.nr | 2 +- .../src/public_kernel_tail.nr | 4 +- .../src/public_kernel_teardown.nr | 2 +- .../crates/types/src/abis.nr | 1 + .../combined_accumulated_data.nr | 44 ++++++++- .../private_accumulated_data.nr | 61 +++++++++++- .../public_accumulated_data.nr | 89 +++++++++++++++++- .../crates/types/src/abis/call_request.nr | 27 +++++- .../crates/types/src/abis/caller_context.nr | 24 ++++- .../types/src/abis/combined_constant_data.nr | 33 ++++++- .../crates/types/src/abis/gas.nr | 8 ++ .../crates/types/src/abis/gas_fees.nr | 8 ++ .../crates/types/src/abis/gas_settings.nr | 8 ++ .../private_kernel_circuit_public_inputs.nr | 49 +++++++++- .../public_kernel_circuit_public_inputs.nr | 74 ++++++++++++++- .../crates/types/src/abis/kernel_data.nr | 10 +- .../crates/types/src/abis/max_block_number.nr | 8 ++ .../crates/types/src/abis/note_hash.nr | 16 ++++ .../types/src/abis/note_hash_leaf_preimage.nr | 16 +++- .../crates/types/src/abis/nullifier.nr | 18 +++- .../abis/nullifier_key_validation_request.nr | 10 +- .../types/src/abis/nullifier_leaf_preimage.nr | 16 ++++ .../crates/types/src/abis/public_data_read.nr | 19 +++- .../src/abis/public_data_update_request.nr | 19 +++- .../types/src/abis/public_kernel_data.nr | 11 +++ .../crates/types/src/abis/read_request.nr | 18 +++- .../crates/types/src/abis/side_effect.nr | 8 ++ .../rollup_validation_requests.nr | 29 +++++- .../validation_requests.nr | 53 ++++++++++- .../crates/types/src/constants.nr | 3 + .../crates/types/src/contrakt/storage_read.nr | 8 ++ .../src/contrakt/storage_update_request.nr | 8 ++ .../types/src/messaging/l2_to_l1_message.nr | 16 ++++ .../crates/types/src/recursion/proof.nr | 28 ++++++ .../types/src/recursion/verification_key.nr | 15 +++ .../crates/types/src/tests/fixture_builder.nr | 6 +- yarn-project/circuits.js/src/constants.gen.ts | 17 ++++ 41 files changed, 821 insertions(+), 115 deletions(-) create mode 100644 noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr 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..e6c67cfdc7f 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,16 +87,19 @@ 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; @@ -124,6 +127,39 @@ 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; +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); 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 58354ffb7c5..dd5b5cfb74a 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -80,16 +80,11 @@ library Constants { uint256 internal constant MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS = 3000; uint256 internal constant REGISTERER_PRIVATE_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS = 19; uint256 internal constant REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS = 12; - uint256 internal constant REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE = - 0x6999d1e02b08a447a463563453cb36919c9dd7150336fc7c4d2b52f8; - uint256 internal constant REGISTERER_PRIVATE_FUNCTION_BROADCASTED_MAGIC_VALUE = - 0x1b70e95fde0b70adc30496b90a327af6a5e383e028e7a43211a07bcd; - uint256 internal constant REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = - 0xe7af816635466f128568edb04c9fa024f6c87fb9010fdbffa68b3d99; - uint256 internal constant DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = - 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631; - uint256 internal constant DEPLOYER_CONTRACT_ADDRESS = - 0x2e9c386f07e22a1d24e677ab70407b2dd0adbc7cafb9c822bf249685d6a2e4cc; + uint256 internal constant REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE = 0x6999d1e02b08a447a463563453cb36919c9dd7150336fc7c4d2b52f8; + uint256 internal constant REGISTERER_PRIVATE_FUNCTION_BROADCASTED_MAGIC_VALUE = 0x1b70e95fde0b70adc30496b90a327af6a5e383e028e7a43211a07bcd; + uint256 internal constant REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = 0xe7af816635466f128568edb04c9fa024f6c87fb9010fdbffa68b3d99; + uint256 internal constant DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631; + uint256 internal constant DEPLOYER_CONTRACT_ADDRESS = 0x2e9c386f07e22a1d24e677ab70407b2dd0adbc7cafb9c822bf249685d6a2e4cc; uint256 internal constant DEFAULT_GAS_LIMIT = 1_000_000_000; uint256 internal constant DEFAULT_TEARDOWN_GAS_LIMIT = 100_000_000; uint256 internal constant DEFAULT_MAX_FEE_PER_GAS = 10; @@ -97,13 +92,11 @@ library Constants { uint256 internal constant DA_BYTES_PER_FIELD = 32; uint256 internal constant DA_GAS_PER_BYTE = 16; uint256 internal constant FIXED_DA_GAS = 512; - uint256 internal constant CANONICAL_KEY_REGISTRY_ADDRESS = - 0x1585e564a60e6ec974bc151b62705292ebfc75c33341986a47fd9749cedb567e; + uint256 internal constant CANONICAL_KEY_REGISTRY_ADDRESS = 0x1585e564a60e6ec974bc151b62705292ebfc75c33341986a47fd9749cedb567e; uint256 internal constant AZTEC_ADDRESS_LENGTH = 1; uint256 internal constant GAS_FEES_LENGTH = 2; uint256 internal constant GAS_LENGTH = 2; - uint256 internal constant GAS_SETTINGS_LENGTH = - GAS_LENGTH * 2 + GAS_FEES_LENGTH /* inclusion_fee */ + 1; + uint256 internal constant GAS_SETTINGS_LENGTH = GAS_LENGTH * 2 + GAS_FEES_LENGTH + /* inclusion_fee */ 1; uint256 internal constant CALL_CONTEXT_LENGTH = 6; uint256 internal constant CONTENT_COMMITMENT_LENGTH = 4; uint256 internal constant CONTRACT_INSTANCE_LENGTH = 5; @@ -119,8 +112,7 @@ library Constants { uint256 internal constant SCOPED_L2_TO_L1_MESSAGE_LENGTH = L2_TO_L1_MESSAGE_LENGTH + 1; uint256 internal constant MAX_BLOCK_NUMBER_LENGTH = 2; uint256 internal constant NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH = 3; - uint256 internal constant SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH = - NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH + 1; + uint256 internal constant SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH = NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH + 1; uint256 internal constant PARTIAL_STATE_REFERENCE_LENGTH = 6; uint256 internal constant READ_REQUEST_LENGTH = 2; uint256 internal constant NOTE_HASH_LENGTH = 2; @@ -129,67 +121,27 @@ library Constants { uint256 internal constant SCOPED_NULLIFIER_LENGTH = NULLIFIER_LENGTH + 1; uint256 internal constant SIDE_EFFECT_LENGTH = 2; uint256 internal constant ROLLUP_VALIDATION_REQUESTS_LENGTH = MAX_BLOCK_NUMBER_LENGTH; - uint256 internal constant STATE_REFERENCE_LENGTH = - APPEND_ONLY_TREE_SNAPSHOT_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH; + uint256 internal constant STATE_REFERENCE_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH; uint256 internal constant TX_CONTEXT_LENGTH = 2 + GAS_SETTINGS_LENGTH; uint256 internal constant TX_REQUEST_LENGTH = 2 + TX_CONTEXT_LENGTH + FUNCTION_DATA_LENGTH; - uint256 internal constant HEADER_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH - + CONTENT_COMMITMENT_LENGTH + STATE_REFERENCE_LENGTH + GLOBAL_VARIABLES_LENGTH; - uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = CALL_CONTEXT_LENGTH + 3 - + 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) + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL - + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + 1 - + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 - + (SIDE_EFFECT_LENGTH * MAX_ENCRYPTED_LOGS_PER_CALL) - + (SIDE_EFFECT_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 2 + HEADER_LENGTH + TX_CONTEXT_LENGTH; - uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = CALL_CONTEXT_LENGTH + 2 - + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) - + (READ_REQUEST_LENGTH * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL) - + (CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL) - + (CONTRACT_STORAGE_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_CALL) - + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) - + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) - + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 - + (SIDE_EFFECT_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 1 + HEADER_LENGTH - + GLOBAL_VARIABLES_LENGTH + AZTEC_ADDRESS_LENGTH /* revert_code */ + 1 + 2 * GAS_LENGTH /* transaction_fee */ - + 1; - uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = - AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH; - uint256 internal constant PUBLIC_CONTEXT_INPUTS_LENGTH = - CALL_CONTEXT_LENGTH + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + GAS_LENGTH + 2; + uint256 internal constant HEADER_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + CONTENT_COMMITMENT_LENGTH + STATE_REFERENCE_LENGTH + GLOBAL_VARIABLES_LENGTH; + uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = CALL_CONTEXT_LENGTH + 3 + 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) + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + 1 + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + (SIDE_EFFECT_LENGTH * MAX_ENCRYPTED_LOGS_PER_CALL) + (SIDE_EFFECT_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 2 + HEADER_LENGTH + TX_CONTEXT_LENGTH; + uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = CALL_CONTEXT_LENGTH + 2 + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) + (READ_REQUEST_LENGTH * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL) + (CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL) + (CONTRACT_STORAGE_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_CALL) + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + (SIDE_EFFECT_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 1 + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + AZTEC_ADDRESS_LENGTH + /* revert_code */ 1 + 2 * GAS_LENGTH + /* transaction_fee */ 1; + uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH; + uint256 internal constant PUBLIC_CONTEXT_INPUTS_LENGTH = CALL_CONTEXT_LENGTH + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + GAS_LENGTH + 2; uint256 internal constant SCOPED_READ_REQUEST_LEN = READ_REQUEST_LENGTH + 1; uint256 internal constant PUBLIC_DATA_READ_LENGTH = 2; - uint256 internal constant 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); + uint256 internal constant 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); uint256 internal constant PUBLIC_DATA_UPDATE_REQUEST_LENGTH = 2; - uint256 internal constant 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; - uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = - HEADER_LENGTH + TX_CONTEXT_LENGTH + GLOBAL_VARIABLES_LENGTH; + uint256 internal constant 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; + uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = HEADER_LENGTH + TX_CONTEXT_LENGTH + GLOBAL_VARIABLES_LENGTH; uint256 internal constant CALLER_CONTEXT_LENGTH = 2 * AZTEC_ADDRESS_LENGTH; - uint256 internal constant CALL_REQUEST_LENGTH = - 1 + AZTEC_ADDRESS_LENGTH + CALLER_CONTEXT_LENGTH + 2; - uint256 internal constant 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); - uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1 - + VALIDATION_REQUESTS_LENGTH + PRIVATE_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH - + CALL_REQUEST_LENGTH; - uint256 internal constant ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH = - 2 + FUNCTION_DATA_LENGTH + CALL_CONTEXT_LENGTH; + uint256 internal constant CALL_REQUEST_LENGTH = 1 + AZTEC_ADDRESS_LENGTH + CALLER_CONTEXT_LENGTH + 2; + uint256 internal constant 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); + uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1 + VALIDATION_REQUESTS_LENGTH + PRIVATE_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + CALL_REQUEST_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); + 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; uint256 internal constant NOTE_HASHES_NUM_BYTES_PER_BASE_ROLLUP = 2048; uint256 internal constant NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP = 2048; 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 83dfd47ef6d..724e7470130 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 9eb7eb4a126..f2e361200f9 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 bd90b42fac0..afae91e0e93 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 e92e4c791a4..df7cec67ffc 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}, @@ -113,7 +113,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 }, constants::{ 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 981d431d4a7..f75e1735434 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 e7aee9e9d52..56e95a80e20 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; +use crate::traits::{Serialize, Deserialize, Eq, Empty}; +use crate::utils::reader::Reader; struct PrivateKernelCircuitPublicInputs { min_revertible_side_effect_counter: u32, @@ -28,3 +29,49 @@ 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), + }; + + 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(), + } + } +} + +#[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 06722dfce8e..3166b356128 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,7 +2,9 @@ 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; +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; struct PublicKernelCircuitPublicInputs { validation_requests: ValidationRequests, @@ -31,3 +33,73 @@ 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], + } + } +} + +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()); + } + + + 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]) + }; + 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..00acbaf6172 --- /dev/null +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_kernel_data.nr @@ -0,0 +1,11 @@ +use crate::recursion::{proof::NestedRecursiveProof, verification_key::VerificationKey}; +use crate::constants::VK_TREE_HEIGHT; +use crate::abis::kernel_circuit_public_inputs::{PublicKernelCircuitPublicInputs, KernelCircuitPublicInputs}; + +struct PublicKernelData { + public_inputs: PublicKernelCircuitPublicInputs, + proof: NestedRecursiveProof, + 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 32e4ef51d4c..65b862f57f0 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; +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); + 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 105a3fed3bb..52d3dc8ca3f 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, @@ -233,8 +233,8 @@ impl FixtureBuilder { let public_inputs = self.to_public_kernel_circuit_public_inputs(revertible); PublicKernelData { public_inputs, - proof: crate::mocked::Proof::empty(), - vk: crate::mocked::VerificationKey::empty(), + proof: NestedRecursiveProof::empty(), + vk: VerificationKey::empty(), vk_index: self.vk_index, vk_path: self.vk_path } diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 0d5ac6d8742..90f14d189e6 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -194,6 +194,23 @@ export const PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = PRIVATE_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + CALL_REQUEST_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; 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; From b55066be0f50cb4877963c0d57d60b1d36771ac3 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Mon, 13 May 2024 22:46:20 +0000 Subject: [PATCH 2/7] Fixes --- .../vm/avm_trace/aztec_constants.hpp | 11 +- .../src/core/libraries/ConstantsGen.sol | 104 ++++++++++++++---- .../crates/types/src/constants.nr | 2 +- yarn-project/circuits.js/src/constants.gen.ts | 6 +- 4 files changed, 92 insertions(+), 31 deletions(-) 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 e6c67cfdc7f..381dab411c3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp @@ -106,7 +106,7 @@ 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) + @@ -148,9 +148,9 @@ const size_t PRIVATE_ACCUMULATED_DATA_LENGTH = (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; +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) + @@ -159,7 +159,8 @@ const size_t PUBLIC_ACCUMULATED_DATA_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); + 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 dd5b5cfb74a..23935b18b31 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -80,11 +80,16 @@ library Constants { uint256 internal constant MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS = 3000; uint256 internal constant REGISTERER_PRIVATE_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS = 19; uint256 internal constant REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_ADDITIONAL_FIELDS = 12; - uint256 internal constant REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE = 0x6999d1e02b08a447a463563453cb36919c9dd7150336fc7c4d2b52f8; - uint256 internal constant REGISTERER_PRIVATE_FUNCTION_BROADCASTED_MAGIC_VALUE = 0x1b70e95fde0b70adc30496b90a327af6a5e383e028e7a43211a07bcd; - uint256 internal constant REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = 0xe7af816635466f128568edb04c9fa024f6c87fb9010fdbffa68b3d99; - uint256 internal constant DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631; - uint256 internal constant DEPLOYER_CONTRACT_ADDRESS = 0x2e9c386f07e22a1d24e677ab70407b2dd0adbc7cafb9c822bf249685d6a2e4cc; + uint256 internal constant REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE = + 0x6999d1e02b08a447a463563453cb36919c9dd7150336fc7c4d2b52f8; + uint256 internal constant REGISTERER_PRIVATE_FUNCTION_BROADCASTED_MAGIC_VALUE = + 0x1b70e95fde0b70adc30496b90a327af6a5e383e028e7a43211a07bcd; + uint256 internal constant REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = + 0xe7af816635466f128568edb04c9fa024f6c87fb9010fdbffa68b3d99; + uint256 internal constant DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = + 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631; + uint256 internal constant DEPLOYER_CONTRACT_ADDRESS = + 0x2e9c386f07e22a1d24e677ab70407b2dd0adbc7cafb9c822bf249685d6a2e4cc; uint256 internal constant DEFAULT_GAS_LIMIT = 1_000_000_000; uint256 internal constant DEFAULT_TEARDOWN_GAS_LIMIT = 100_000_000; uint256 internal constant DEFAULT_MAX_FEE_PER_GAS = 10; @@ -92,11 +97,13 @@ library Constants { uint256 internal constant DA_BYTES_PER_FIELD = 32; uint256 internal constant DA_GAS_PER_BYTE = 16; uint256 internal constant FIXED_DA_GAS = 512; - uint256 internal constant CANONICAL_KEY_REGISTRY_ADDRESS = 0x1585e564a60e6ec974bc151b62705292ebfc75c33341986a47fd9749cedb567e; + uint256 internal constant CANONICAL_KEY_REGISTRY_ADDRESS = + 0x1585e564a60e6ec974bc151b62705292ebfc75c33341986a47fd9749cedb567e; uint256 internal constant AZTEC_ADDRESS_LENGTH = 1; uint256 internal constant GAS_FEES_LENGTH = 2; uint256 internal constant GAS_LENGTH = 2; - uint256 internal constant GAS_SETTINGS_LENGTH = GAS_LENGTH * 2 + GAS_FEES_LENGTH + /* inclusion_fee */ 1; + uint256 internal constant GAS_SETTINGS_LENGTH = + GAS_LENGTH * 2 + GAS_FEES_LENGTH /* inclusion_fee */ + 1; uint256 internal constant CALL_CONTEXT_LENGTH = 6; uint256 internal constant CONTENT_COMMITMENT_LENGTH = 4; uint256 internal constant CONTRACT_INSTANCE_LENGTH = 5; @@ -112,7 +119,8 @@ library Constants { uint256 internal constant SCOPED_L2_TO_L1_MESSAGE_LENGTH = L2_TO_L1_MESSAGE_LENGTH + 1; uint256 internal constant MAX_BLOCK_NUMBER_LENGTH = 2; uint256 internal constant NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH = 3; - uint256 internal constant SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH = NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH + 1; + uint256 internal constant SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH = + NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH + 1; uint256 internal constant PARTIAL_STATE_REFERENCE_LENGTH = 6; uint256 internal constant READ_REQUEST_LENGTH = 2; uint256 internal constant NOTE_HASH_LENGTH = 2; @@ -121,27 +129,77 @@ library Constants { uint256 internal constant SCOPED_NULLIFIER_LENGTH = NULLIFIER_LENGTH + 1; uint256 internal constant SIDE_EFFECT_LENGTH = 2; uint256 internal constant ROLLUP_VALIDATION_REQUESTS_LENGTH = MAX_BLOCK_NUMBER_LENGTH; - uint256 internal constant STATE_REFERENCE_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH; + uint256 internal constant STATE_REFERENCE_LENGTH = + APPEND_ONLY_TREE_SNAPSHOT_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH; uint256 internal constant TX_CONTEXT_LENGTH = 2 + GAS_SETTINGS_LENGTH; uint256 internal constant TX_REQUEST_LENGTH = 2 + TX_CONTEXT_LENGTH + FUNCTION_DATA_LENGTH; - uint256 internal constant HEADER_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + CONTENT_COMMITMENT_LENGTH + STATE_REFERENCE_LENGTH + GLOBAL_VARIABLES_LENGTH; - uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = CALL_CONTEXT_LENGTH + 3 + 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) + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + 1 + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + (SIDE_EFFECT_LENGTH * MAX_ENCRYPTED_LOGS_PER_CALL) + (SIDE_EFFECT_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 2 + HEADER_LENGTH + TX_CONTEXT_LENGTH; - uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = CALL_CONTEXT_LENGTH + 2 + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) + (READ_REQUEST_LENGTH * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL) + (CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL) + (CONTRACT_STORAGE_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_CALL) + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + (SIDE_EFFECT_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 1 + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + AZTEC_ADDRESS_LENGTH + /* revert_code */ 1 + 2 * GAS_LENGTH + /* transaction_fee */ 1; - uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH; - uint256 internal constant PUBLIC_CONTEXT_INPUTS_LENGTH = CALL_CONTEXT_LENGTH + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + GAS_LENGTH + 2; + uint256 internal constant HEADER_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + + CONTENT_COMMITMENT_LENGTH + STATE_REFERENCE_LENGTH + GLOBAL_VARIABLES_LENGTH; + uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 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) + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + 1 + + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + + (SIDE_EFFECT_LENGTH * MAX_ENCRYPTED_LOGS_PER_CALL) + + (SIDE_EFFECT_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 2 + HEADER_LENGTH + TX_CONTEXT_LENGTH; + uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = CALL_CONTEXT_LENGTH + 2 + + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) + + (READ_REQUEST_LENGTH * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL) + + (CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL) + + (CONTRACT_STORAGE_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_CALL) + + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + + (SIDE_EFFECT_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 1 + HEADER_LENGTH + + GLOBAL_VARIABLES_LENGTH + AZTEC_ADDRESS_LENGTH /* revert_code */ + 1 + 2 * GAS_LENGTH /* transaction_fee */ + + 1; + uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = + AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH; + uint256 internal constant PUBLIC_CONTEXT_INPUTS_LENGTH = + CALL_CONTEXT_LENGTH + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + GAS_LENGTH + 2; uint256 internal constant SCOPED_READ_REQUEST_LEN = READ_REQUEST_LENGTH + 1; uint256 internal constant PUBLIC_DATA_READ_LENGTH = 2; - uint256 internal constant 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); + uint256 internal constant 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); uint256 internal constant PUBLIC_DATA_UPDATE_REQUEST_LENGTH = 2; - uint256 internal constant 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; - uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = HEADER_LENGTH + TX_CONTEXT_LENGTH + GLOBAL_VARIABLES_LENGTH; + uint256 internal constant 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; + uint256 internal constant COMBINED_CONSTANT_DATA_LENGTH = + HEADER_LENGTH + TX_CONTEXT_LENGTH + GLOBAL_VARIABLES_LENGTH; uint256 internal constant CALLER_CONTEXT_LENGTH = 2 * AZTEC_ADDRESS_LENGTH; - uint256 internal constant CALL_REQUEST_LENGTH = 1 + AZTEC_ADDRESS_LENGTH + CALLER_CONTEXT_LENGTH + 2; - uint256 internal constant 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); - uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1 + VALIDATION_REQUESTS_LENGTH + PRIVATE_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + CALL_REQUEST_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); - uint256 internal constant ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH = 2 + FUNCTION_DATA_LENGTH + CALL_CONTEXT_LENGTH; + uint256 internal constant CALL_REQUEST_LENGTH = + 1 + AZTEC_ADDRESS_LENGTH + CALLER_CONTEXT_LENGTH + 2; + uint256 internal constant 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); + uint256 internal constant PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1 + + VALIDATION_REQUESTS_LENGTH + PRIVATE_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_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; uint256 internal constant NOTE_HASHES_NUM_BYTES_PER_BASE_ROLLUP = 2048; uint256 internal constant NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP = 2048; 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 5c48df43a27..396174ec5b9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -191,7 +191,7 @@ global PRIVATE_ACCUMULATED_DATA_LENGTH = (SCOPED_NOTE_HASH_LENGTH * MAX_NEW_NOTE 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); +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; diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index e67aa741d5c..968f3215c08 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -193,7 +193,8 @@ 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 + @@ -210,7 +211,8 @@ export const PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = PUBLIC_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + 1 + - MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX * CALL_REQUEST_LENGTH; + 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; From 56b9d7366cbf547f5e4ebd36ea1318defbe8dc0d Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Mon, 13 May 2024 22:49:23 +0000 Subject: [PATCH 3/7] WIP --- .../crates/types/src/abis/public_kernel_data.nr | 4 ++-- .../crates/types/src/tests/fixture_builder.nr | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 index 00acbaf6172..16b4054e58c 100644 --- 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 @@ -1,10 +1,10 @@ -use crate::recursion::{proof::NestedRecursiveProof, verification_key::VerificationKey}; +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: NestedRecursiveProof, + proof: Proof, vk: VerificationKey, vk_index: u32, vk_path: [Field; VK_TREE_HEIGHT], 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 6ad1b65d1fc..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 @@ -237,8 +237,8 @@ impl FixtureBuilder { let public_inputs = self.to_public_kernel_circuit_public_inputs(revertible); PublicKernelData { public_inputs, - proof: NestedRecursiveProof::empty(), - vk: VerificationKey::empty(), + proof: crate::mocked::Proof::empty(), + vk: crate::mocked::VerificationKey::empty(), vk_index: self.vk_index, vk_path: self.vk_path } From 2fea5f74bc8015f04c56508458840bd83203ae0f Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 14 May 2024 10:55:57 +0000 Subject: [PATCH 4/7] More serialisation --- .../base_or_merge_rollup_public_inputs.nr | 60 ++++++++++++++++++- .../src/abis/constant_rollup_data.nr | 45 +++++++++++++- .../kernel_circuit_public_inputs.nr | 57 +++++++++++++++++- .../crates/types/src/constants.nr | 5 ++ 4 files changed, 164 insertions(+), 3 deletions(-) diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/base_or_merge_rollup_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/base_or_merge_rollup_public_inputs.nr index 90406f9e18e..33f6ac78e45 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/base_or_merge_rollup_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/base_or_merge_rollup_public_inputs.nr @@ -1,6 +1,7 @@ use dep::types::{ abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot, - partial_state_reference::PartialStateReference, mocked::AggregationObject, traits::Empty + constants::BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH, partial_state_reference::PartialStateReference, + mocked::AggregationObject, traits::{Empty, Serialize, Deserialize}, utils::reader::Reader }; use crate::abis::constant_rollup_data::ConstantRollupData; @@ -43,3 +44,60 @@ impl Empty for BaseOrMergeRollupPublicInputs { } } } + +impl Eq for BaseOrMergeRollupPublicInputs { + fn eq(self, other: Self) -> bool { + (self.rollup_type == other.rollup_type) & + (self.height_in_block_tree == other.height_in_block_tree) & + (self.constants.eq(other.constants)) & + (self.start.eq(other.start)) & + (self.end.eq(other.end)) & + (self.txs_effects_hash == other.txs_effects_hash) & + (self.out_hash == other.out_hash) + } +} + +impl Serialize for BaseOrMergeRollupPublicInputs { + fn serialize(self) -> [Field; BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); + + fields.push(self.rollup_type as Field); + fields.push(self.height_in_block_tree as Field); + fields.extend_from_array(self.constants.serialize()); + fields.extend_from_array(self.start.serialize()); + fields.extend_from_array(self.end.serialize()); + fields.push(self.txs_effects_hash as Field); + fields.push(self.out_hash as Field); + + assert_eq(fields.len(), BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH); + + fields.storage + } +} + +impl Deserialize for BaseOrMergeRollupPublicInputs { + fn deserialize(fields: [Field; BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH]) -> BaseOrMergeRollupPublicInputs { + let mut reader = Reader::new(fields); + let item = Self { + rollup_type: reader.read() as u32, + height_in_block_tree: reader.read(), + aggregation_object : AggregationObject::empty(), + constants: reader.read_struct(ConstantRollupData::deserialize), + start: reader.read_struct(PartialStateReference::deserialize), + end: reader.read_struct(PartialStateReference::deserialize), + txs_effects_hash: reader.read(), + out_hash: reader.read(), + }; + + reader.finish(); + item + } +} + +#[test] +fn serialization_of_empty() { + let item = BaseOrMergeRollupPublicInputs::empty(); + let serialized = item.serialize(); + let deserialized = BaseOrMergeRollupPublicInputs::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr index 824860f74b1..6bfb8ffe111 100644 --- a/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/constant_rollup_data.nr @@ -1,7 +1,8 @@ use dep::std::cmp::Eq; use dep::types::{ abis::{global_variables::GlobalVariables, append_only_tree_snapshot::AppendOnlyTreeSnapshot}, - traits::Empty + traits::{Empty, Serialize, Deserialize}, constants::CONSTANT_ROLLUP_DATA_LENGTH, + utils::reader::Reader }; struct ConstantRollupData { @@ -41,3 +42,45 @@ impl Empty for ConstantRollupData { } } } + +impl Serialize for ConstantRollupData { + fn serialize(self) -> [Field; CONSTANT_ROLLUP_DATA_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); + + fields.extend_from_array(self.last_archive.serialize()); + fields.push(self.private_kernel_vk_tree_root as Field); + fields.push(self.public_kernel_vk_tree_root as Field); + fields.push(self.base_rollup_vk_hash as Field); + fields.push(self.merge_rollup_vk_hash as Field); + fields.extend_from_array(self.global_variables.serialize()); + + assert_eq(fields.len(), CONSTANT_ROLLUP_DATA_LENGTH); + + fields.storage + } +} + +impl Deserialize for ConstantRollupData { + fn deserialize(fields: [Field; CONSTANT_ROLLUP_DATA_LENGTH]) -> ConstantRollupData { + let mut reader = Reader::new(fields); + let item = Self { + last_archive: reader.read_struct(AppendOnlyTreeSnapshot::deserialize), + private_kernel_vk_tree_root: reader.read(), + public_kernel_vk_tree_root: reader.read(), + base_rollup_vk_hash: reader.read(), + merge_rollup_vk_hash: reader.read(), + global_variables: reader.read_struct(GlobalVariables::deserialize), + }; + + reader.finish(); + item + } +} + +#[test] +fn serialization_of_empty() { + let item = ConstantRollupData::empty(); + let serialized = item.serialize(); + let deserialized = ConstantRollupData::deserialize(serialized); + assert(item.eq(deserialized)); +} diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr index 57d14ffbab9..e650bb101c1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/kernel_circuit_public_inputs/kernel_circuit_public_inputs.nr @@ -3,7 +3,9 @@ use crate::{ accumulated_data::CombinedAccumulatedData, combined_constant_data::CombinedConstantData, validation_requests::RollupValidationRequests, gas::Gas }, - address::AztecAddress, partial_state_reference::PartialStateReference, traits::Empty + address::AztecAddress, partial_state_reference::PartialStateReference, + traits::{Empty, Eq, Serialize, Deserialize}, constants::KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH, + utils::reader::Reader }; use crate::mocked::AggregationObject; @@ -38,6 +40,51 @@ impl Empty for KernelCircuitPublicInputs { } } +impl Eq for KernelCircuitPublicInputs { + fn eq(self, other: Self) -> bool { + (self.rollup_validation_requests.eq(other.rollup_validation_requests)) & + (self.end.eq(other.end)) & + (self.constants.eq(other.constants)) & + (self.start_state.eq(other.start_state)) & + (self.revert_code == other.revert_code) & + (self.fee_payer.eq(other.fee_payer)) + } +} + +impl Serialize for KernelCircuitPublicInputs { + fn serialize(self) -> [Field; KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH] { + let mut fields: BoundedVec = BoundedVec::new(); + + fields.extend_from_array(self.rollup_validation_requests.serialize()); + fields.extend_from_array(self.end.serialize()); + fields.extend_from_array(self.constants.serialize()); + fields.extend_from_array(self.start_state.serialize()); + fields.push(self.revert_code as Field); + fields.extend_from_array(self.fee_payer.serialize()); + + assert_eq(fields.len(), KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH); + + fields.storage + } +} + +impl Deserialize for KernelCircuitPublicInputs { + fn deserialize(fields: [Field; KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH]) -> KernelCircuitPublicInputs { + let mut reader = Reader::new(fields); + let item = Self { + rollup_validation_requests: reader.read_struct(RollupValidationRequests::deserialize), + end: reader.read_struct(CombinedAccumulatedData::deserialize), + constants: reader.read_struct(CombinedConstantData::deserialize), + start_state: reader.read_struct(PartialStateReference::deserialize), + revert_code: reader.read() as u8, + fee_payer: reader.read_struct(AztecAddress::deserialize), + }; + + reader.finish(); + item + } +} + mod tests { use crate::abis::{ kernel_circuit_public_inputs::kernel_circuit_public_inputs::KernelCircuitPublicInputs, @@ -80,4 +127,12 @@ mod tests { let transaction_fee = inputs.compute_transaction_fee(); assert_eq(transaction_fee, 42 + 2 * 10 + 3 * 20); } + + #[test] + fn serialization_of_empty() { + let item = KernelCircuitPublicInputs::empty(); + let serialized = item.serialize(); + let deserialized = KernelCircuitPublicInputs::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 396174ec5b9..1f23864d042 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -193,6 +193,11 @@ global PRIVATE_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1 + VALIDATION_REQUESTS_LEN 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 KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = ROLLUP_VALIDATION_REQUESTS_LENGTH + COMBINED_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 1 + AZTEC_ADDRESS_LENGTH; + +global CONSTANT_ROLLUP_DATA_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + 1 + 1 + 1 + 1 + GLOBAL_VARIABLES_LENGTH; +global BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 1 + 1 + CONSTANT_ROLLUP_DATA_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 1 + 1; + 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; From 0a3ab10847072efd24e3c40a92372c113dfdfddc Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 14 May 2024 11:00:43 +0000 Subject: [PATCH 5/7] Fix --- .../types/src/abis/validation_requests/validation_requests.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5a1e5ad5e77..2cc7fabdb0c 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 @@ -89,7 +89,7 @@ impl Empty for ValidationRequests { impl Eq for ValidationRequests { fn eq(self, other: Self) -> bool { - self.for_rollup.eq(other.for_rollup) & + (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) & From 2ec86f5ad05b72c037d8781cc4a13f21d1fbcc12 Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 14 May 2024 11:17:44 +0000 Subject: [PATCH 6/7] Updates constants --- .../src/barretenberg/vm/avm_trace/aztec_constants.hpp | 6 ++++++ l1-contracts/src/core/libraries/ConstantsGen.sol | 7 +++++++ yarn-project/circuits.js/src/constants.gen.ts | 10 ++++++++++ 3 files changed, 23 insertions(+) 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 381dab411c3..3018c4bb8cf 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp @@ -161,6 +161,12 @@ 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 KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = ROLLUP_VALIDATION_REQUESTS_LENGTH + + COMBINED_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + + PARTIAL_STATE_REFERENCE_LENGTH + 1 + AZTEC_ADDRESS_LENGTH; +const size_t CONSTANT_ROLLUP_DATA_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + 1 + 1 + 1 + 1 + GLOBAL_VARIABLES_LENGTH; +const size_t BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = + 1 + 1 + CONSTANT_ROLLUP_DATA_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 1 + 1; 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 23935b18b31..2cac3d43f8e 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -198,6 +198,13 @@ library Constants { 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 KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = ROLLUP_VALIDATION_REQUESTS_LENGTH + + COMBINED_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + + PARTIAL_STATE_REFERENCE_LENGTH + 1 + AZTEC_ADDRESS_LENGTH; + uint256 internal constant CONSTANT_ROLLUP_DATA_LENGTH = + APPEND_ONLY_TREE_SNAPSHOT_LENGTH + 1 + 1 + 1 + 1 + GLOBAL_VARIABLES_LENGTH; + uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 1 + 1 + CONSTANT_ROLLUP_DATA_LENGTH + + PARTIAL_STATE_REFERENCE_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 1 + 1; 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/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 968f3215c08..c48dda3db46 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -213,6 +213,16 @@ export const PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1 + MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX * CALL_REQUEST_LENGTH + AZTEC_ADDRESS_LENGTH; +export const KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = + ROLLUP_VALIDATION_REQUESTS_LENGTH + + COMBINED_ACCUMULATED_DATA_LENGTH + + COMBINED_CONSTANT_DATA_LENGTH + + PARTIAL_STATE_REFERENCE_LENGTH + + 1 + + AZTEC_ADDRESS_LENGTH; +export const CONSTANT_ROLLUP_DATA_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + 1 + 1 + 1 + 1 + GLOBAL_VARIABLES_LENGTH; +export const BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = + 1 + 1 + CONSTANT_ROLLUP_DATA_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 1 + 1; 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; From 3aaf2d23186db7a1f94dfab541c2f5d7dbcbe5bb Mon Sep 17 00:00:00 2001 From: PhilWindle Date: Tue, 14 May 2024 13:28:51 +0000 Subject: [PATCH 7/7] WIP --- .../cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp | 4 ++-- l1-contracts/src/core/libraries/ConstantsGen.sol | 6 +++--- .../noir-protocol-circuits/crates/types/src/constants.nr | 4 ++-- yarn-project/circuits.js/src/constants.gen.ts | 7 ++----- 4 files changed, 9 insertions(+), 12 deletions(-) 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 3018c4bb8cf..62246d48614 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp @@ -164,9 +164,9 @@ const size_t PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = const size_t KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = ROLLUP_VALIDATION_REQUESTS_LENGTH + COMBINED_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 1 + AZTEC_ADDRESS_LENGTH; -const size_t CONSTANT_ROLLUP_DATA_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + 1 + 1 + 1 + 1 + GLOBAL_VARIABLES_LENGTH; +const size_t CONSTANT_ROLLUP_DATA_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + 4 + GLOBAL_VARIABLES_LENGTH; const size_t BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = - 1 + 1 + CONSTANT_ROLLUP_DATA_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 1 + 1; + CONSTANT_ROLLUP_DATA_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 4; 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 2cac3d43f8e..6d7217fa8e6 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -202,9 +202,9 @@ library Constants { + COMBINED_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 1 + AZTEC_ADDRESS_LENGTH; uint256 internal constant CONSTANT_ROLLUP_DATA_LENGTH = - APPEND_ONLY_TREE_SNAPSHOT_LENGTH + 1 + 1 + 1 + 1 + GLOBAL_VARIABLES_LENGTH; - uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 1 + 1 + CONSTANT_ROLLUP_DATA_LENGTH - + PARTIAL_STATE_REFERENCE_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 1 + 1; + APPEND_ONLY_TREE_SNAPSHOT_LENGTH + 4 + GLOBAL_VARIABLES_LENGTH; + uint256 internal constant BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = CONSTANT_ROLLUP_DATA_LENGTH + + PARTIAL_STATE_REFERENCE_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 4; 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/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 1f23864d042..1799f1e176a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -195,8 +195,8 @@ global PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = VALIDATION_REQUESTS_LENGTH + global KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = ROLLUP_VALIDATION_REQUESTS_LENGTH + COMBINED_ACCUMULATED_DATA_LENGTH + COMBINED_CONSTANT_DATA_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 1 + AZTEC_ADDRESS_LENGTH; -global CONSTANT_ROLLUP_DATA_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + 1 + 1 + 1 + 1 + GLOBAL_VARIABLES_LENGTH; -global BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = 1 + 1 + CONSTANT_ROLLUP_DATA_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 1 + 1; +global CONSTANT_ROLLUP_DATA_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + 4 + GLOBAL_VARIABLES_LENGTH; +global BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = CONSTANT_ROLLUP_DATA_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 4; global ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH: u64 = 2 + FUNCTION_DATA_LENGTH + CALL_CONTEXT_LENGTH; global GET_NOTES_ORACLE_RETURN_LENGTH: u64 = 674; diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 66dfa858e82..ecf31fe3334 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -213,7 +213,6 @@ export const PUBLIC_KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = 1 + MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX * CALL_REQUEST_LENGTH + AZTEC_ADDRESS_LENGTH; -<<<<<<< HEAD export const KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = ROLLUP_VALIDATION_REQUESTS_LENGTH + COMBINED_ACCUMULATED_DATA_LENGTH + @@ -221,11 +220,9 @@ export const KERNEL_CIRCUIT_PUBLIC_INPUTS_LENGTH = PARTIAL_STATE_REFERENCE_LENGTH + 1 + AZTEC_ADDRESS_LENGTH; -export const CONSTANT_ROLLUP_DATA_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + 1 + 1 + 1 + 1 + GLOBAL_VARIABLES_LENGTH; +export const CONSTANT_ROLLUP_DATA_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + 4 + GLOBAL_VARIABLES_LENGTH; export const BASE_OR_MERGE_PUBLIC_INPUTS_LENGTH = - 1 + 1 + CONSTANT_ROLLUP_DATA_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 1 + 1; -======= ->>>>>>> master + CONSTANT_ROLLUP_DATA_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH + 4; 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;