From cb1e25b8c6f203d8a7e4beb2f027d72bee981695 Mon Sep 17 00:00:00 2001 From: Facundo Date: Thu, 18 Apr 2024 13:51:36 +0100 Subject: [PATCH] chore: allow expressions in constant generation (#5839) Noir supports expressions in constants, so now we can leverage that. Changes * Moved note-related constants to the `note` crate because they were only used there. * Updated all possible structs to use expressions for their lengths. --- .../references/storage/private_state.md | 2 +- .../src/core/libraries/ConstantsGen.sol | 55 ++++++++++----- noir-projects/aztec-nr/aztec/src/note.nr | 1 + .../aztec-nr/aztec/src/note/constants.nr | 6 ++ .../aztec-nr/aztec/src/note/note_getter.nr | 8 +-- .../aztec/src/note/note_viewer_options.nr | 3 +- .../oracle/get_l1_to_l2_membership_witness.nr | 4 +- .../aztec/src/state_vars/private_set.nr | 3 +- .../contracts/card_game_contract/src/cards.nr | 5 +- .../contracts/card_game_contract/src/main.nr | 4 +- .../contracts/test_contract/src/main.nr | 4 +- .../src/abis/private_circuit_public_inputs.nr | 16 ++--- .../src/abis/public_circuit_public_inputs.nr | 2 +- .../crates/types/src/abis/read_request.nr | 12 ++-- .../crates/types/src/abis/side_effect.nr | 23 +++---- .../crates/types/src/constants.nr | 60 ++++++---------- .../src/contrakt/storage_update_request.nr | 2 +- yarn-project/circuits.js/src/constants.gen.ts | 68 ++++++++++++++----- .../circuits.js/src/scripts/constants.in.ts | 2 +- 19 files changed, 166 insertions(+), 114 deletions(-) create mode 100644 noir-projects/aztec-nr/aztec/src/note/constants.nr diff --git a/docs/docs/developers/contracts/references/storage/private_state.md b/docs/docs/developers/contracts/references/storage/private_state.md index dd82a21a02c..6215902d3ef 100644 --- a/docs/docs/developers/contracts/references/storage/private_state.md +++ b/docs/docs/developers/contracts/references/storage/private_state.md @@ -240,7 +240,7 @@ Functionally similar to [`get_notes`](#get_notes), but executed unconstrained an #include_code view_notes /noir-projects/aztec-nr/value-note/src/balance_utils.nr rust -There's also a limit on the maximum number of notes that can be returned in one go. To find the current limit, refer to [this file](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr) and look for `MAX_NOTES_PER_PAGE`. +There's also a limit on the maximum number of notes that can be returned in one go. To find the current limit, refer to [this file](https://github.com/AztecProtocol/aztec-packages/blob/#include_aztec_version/noir-projects/aztec-nr/aztec/src/note/constants.nr) and look for `MAX_NOTES_PER_PAGE`. The key distinction is that this method is unconstrained. It does not perform a check to verify if the notes actually exist, which is something the [`get_notes`](#get_notes) method does under the hood. Therefore, it should only be used in an unconstrained contract function. diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index ea4ec9cca1c..6661fc67443 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -70,9 +70,10 @@ library Constants { uint256 internal constant FUNCTION_SELECTOR_NUM_BYTES = 4; uint256 internal constant ARGS_HASH_CHUNK_LENGTH = 64; uint256 internal constant ARGS_HASH_CHUNK_COUNT = 64; + uint256 internal constant MAX_ARGS_LENGTH = ARGS_HASH_CHUNK_COUNT * ARGS_HASH_CHUNK_LENGTH; uint256 internal constant INITIALIZATION_SLOT_SEPARATOR = 1000_000_000; uint256 internal constant INITIAL_L2_BLOCK_NUM = 1; - uint256 internal constant BLOB_SIZE_IN_BYTES = 126976; + uint256 internal constant BLOB_SIZE_IN_BYTES = 31 * 4096; uint256 internal constant NESTED_CALL_L2_GAS_BUFFER = 20000; uint256 internal constant MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 16200; uint256 internal constant MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 3000; @@ -89,17 +90,12 @@ library Constants { 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631; uint256 internal constant DEPLOYER_CONTRACT_ADDRESS = 0x1b5ecf3d26907648cf737f4304759b8c5850478e839e72f8ce1f5791b286e8f2; - uint256 internal constant L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH = 17; - uint256 internal constant MAX_NOTE_FIELDS_LENGTH = 20; - uint256 internal constant GET_NOTE_ORACLE_RETURN_LENGTH = 23; - uint256 internal constant MAX_NOTES_PER_PAGE = 10; - uint256 internal constant VIEW_NOTE_ORACLE_RETURN_LENGTH = 212; uint256 internal constant AZTEC_ADDRESS_LENGTH = 1; - uint256 internal constant CALL_CONTEXT_LENGTH = 21; - uint256 internal constant GAS_SETTINGS_LENGTH = 10; uint256 internal constant DIMENSION_GAS_SETTINGS_LENGTH = 3; uint256 internal constant GAS_FEES_LENGTH = 3; uint256 internal constant GAS_LENGTH = 3; + uint256 internal constant GAS_SETTINGS_LENGTH = 1 + 3 * DIMENSION_GAS_SETTINGS_LENGTH; + uint256 internal constant CALL_CONTEXT_LENGTH = 8 + GAS_SETTINGS_LENGTH + GAS_LENGTH; uint256 internal constant CONTENT_COMMITMENT_LENGTH = 4; uint256 internal constant CONTRACT_INSTANCE_LENGTH = 6; uint256 internal constant CONTRACT_STORAGE_READ_LENGTH = 2; @@ -107,21 +103,48 @@ library Constants { uint256 internal constant ETH_ADDRESS_LENGTH = 1; uint256 internal constant FUNCTION_DATA_LENGTH = 2; uint256 internal constant FUNCTION_LEAF_PREIMAGE_LENGTH = 5; - uint256 internal constant GLOBAL_VARIABLES_LENGTH = 9; - uint256 internal constant HEADER_LENGTH = 23; + uint256 internal constant GLOBAL_VARIABLES_LENGTH = 6 + GAS_FEES_LENGTH; + uint256 internal constant APPEND_ONLY_TREE_SNAPSHOT_LENGTH = 2; uint256 internal constant L1_TO_L2_MESSAGE_LENGTH = 6; uint256 internal constant L2_TO_L1_MESSAGE_LENGTH = 2; uint256 internal constant MAX_BLOCK_NUMBER_LENGTH = 2; uint256 internal constant NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH = 4; uint256 internal constant NULLIFIER_KEY_VALIDATION_REQUEST_CONTEXT_LENGTH = 5; uint256 internal constant PARTIAL_STATE_REFERENCE_LENGTH = 6; - uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = 238; - uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 235; - uint256 internal constant PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 222; - uint256 internal constant STATE_REFERENCE_LENGTH = 8; + uint256 internal constant READ_REQUEST_LENGTH = 2; + uint256 internal constant SIDE_EFFECT_LENGTH = 2; + uint256 internal constant SIDE_EFFECT_LINKED_TO_NOTE_HASH_LENGTH = 3; + uint256 internal constant STATE_REFERENCE_LENGTH = + APPEND_ONLY_TREE_SNAPSHOT_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH; uint256 internal constant TX_CONTEXT_DATA_LENGTH = 4; - uint256 internal constant TX_REQUEST_LENGTH = 18; - uint256 internal constant ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH = 25; + uint256 internal constant TX_REQUEST_LENGTH = + 2 + TX_CONTEXT_DATA_LENGTH + FUNCTION_DATA_LENGTH + GAS_SETTINGS_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 + (SIDE_EFFECT_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) + + (SIDE_EFFECT_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + + (SIDE_EFFECT_LINKED_TO_NOTE_HASH_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + + (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 + 2; + 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 + (SIDE_EFFECT_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + + (SIDE_EFFECT_LINKED_TO_NOTE_HASH_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 + AZTEC_ADDRESS_LENGTH /* revert_code */ + + 1 + GAS_LENGTH; + uint256 internal constant PRIVATE_CALL_STACK_ITEM_LENGTH = + AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_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/aztec-nr/aztec/src/note.nr b/noir-projects/aztec-nr/aztec/src/note.nr index b457a126b2d..6479366face 100644 --- a/noir-projects/aztec-nr/aztec/src/note.nr +++ b/noir-projects/aztec-nr/aztec/src/note.nr @@ -1,3 +1,4 @@ +mod constants; mod lifecycle; mod note_getter; mod note_getter_options; diff --git a/noir-projects/aztec-nr/aztec/src/note/constants.nr b/noir-projects/aztec-nr/aztec/src/note/constants.nr new file mode 100644 index 00000000000..66a404c1b3d --- /dev/null +++ b/noir-projects/aztec-nr/aztec/src/note/constants.nr @@ -0,0 +1,6 @@ +global MAX_NOTE_FIELDS_LENGTH: u64 = 20; +// The plus 1 is 1 extra field for nonce. +// + 2 for EXTRA_DATA: [number_of_return_notes, contract_address] +global GET_NOTE_ORACLE_RETURN_LENGTH: u64 = MAX_NOTE_FIELDS_LENGTH + 1 + 2; +global MAX_NOTES_PER_PAGE: u64 = 10; +global VIEW_NOTE_ORACLE_RETURN_LENGTH: u64 = MAX_NOTES_PER_PAGE * (MAX_NOTE_FIELDS_LENGTH + 1) + 2; \ No newline at end of file diff --git a/noir-projects/aztec-nr/aztec/src/note/note_getter.nr b/noir-projects/aztec-nr/aztec/src/note/note_getter.nr index 2829583ccab..21fa5ad1530 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_getter.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_getter.nr @@ -1,11 +1,7 @@ -use dep::protocol_types::{ - constants::{ - MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, GET_NOTE_ORACLE_RETURN_LENGTH, GET_NOTES_ORACLE_RETURN_LENGTH, - MAX_NOTES_PER_PAGE, VIEW_NOTE_ORACLE_RETURN_LENGTH -} -}; +use dep::protocol_types::{constants::{MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, GET_NOTES_ORACLE_RETURN_LENGTH}}; use crate::context::PrivateContext; use crate::note::{ + constants::{GET_NOTE_ORACLE_RETURN_LENGTH, MAX_NOTES_PER_PAGE, VIEW_NOTE_ORACLE_RETURN_LENGTH}, note_getter_options::{NoteGetterOptions, Select, Sort, SortOrder, Comparator, NoteStatus, PropertySelector}, note_interface::NoteInterface, note_viewer_options::NoteViewerOptions, utils::compute_note_hash_for_consumption diff --git a/noir-projects/aztec-nr/aztec/src/note/note_viewer_options.nr b/noir-projects/aztec-nr/aztec/src/note/note_viewer_options.nr index eeed1ddac84..c2bd2002cca 100644 --- a/noir-projects/aztec-nr/aztec/src/note/note_viewer_options.nr +++ b/noir-projects/aztec-nr/aztec/src/note/note_viewer_options.nr @@ -1,7 +1,8 @@ use dep::std::option::Option; use crate::note::note_getter_options::{PropertySelector, Select, Sort, Comparator, NoteStatus}; -use dep::protocol_types::{constants::MAX_NOTES_PER_PAGE, traits::ToField}; +use dep::protocol_types::traits::ToField; use crate::note::note_interface::NoteInterface; +use crate::note::constants::MAX_NOTES_PER_PAGE; // docs:start:NoteViewerOptions struct NoteViewerOptions { diff --git a/noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_membership_witness.nr b/noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_membership_witness.nr index e1f61401b17..55adcae73a1 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_membership_witness.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/get_l1_to_l2_membership_witness.nr @@ -1,4 +1,6 @@ -use dep::protocol_types::{address::AztecAddress, constants::L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH}; +use dep::protocol_types::{address::AztecAddress}; + +global L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH: u64 = 17; // Obtains membership witness (index and sibling path) for a message in the L1 to L2 message tree. #[oracle(getL1ToL2MembershipWitness)] diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr b/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr index b72b405d197..c48e9b3708f 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr @@ -1,9 +1,10 @@ use dep::protocol_types::{ - constants::{MAX_NOTES_PER_PAGE, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL}, + constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, abis::side_effect::{SideEffect, SideEffectLinkedToNoteHash} }; use crate::context::{PrivateContext, PublicContext, Context}; use crate::note::{ + constants::MAX_NOTES_PER_PAGE, lifecycle::{create_note, create_note_hash_from_public, destroy_note}, note_getter::{get_notes, view_notes}, note_getter_options::NoteGetterOptions, note_header::NoteHeader, note_interface::NoteInterface, note_viewer_options::NoteViewerOptions, diff --git a/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr b/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr index ccad0898f9a..51f914b567a 100644 --- a/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr +++ b/noir-projects/noir-contracts/contracts/card_game_contract/src/cards.nr @@ -3,9 +3,10 @@ use dep::aztec::prelude::{AztecAddress, FunctionSelector, PrivateContext, NoteHe use dep::aztec::{ protocol_types::{ traits::{ToField, Serialize, FromField}, - constants::{MAX_NOTES_PER_PAGE, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL} + constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, }, - context::{PublicContext, Context}, note::note_getter::view_notes, state_vars::PrivateSet + context::{PublicContext, Context}, note::note_getter::view_notes, state_vars::PrivateSet, + note::constants::MAX_NOTES_PER_PAGE, }; use dep::std; use dep::std::{option::Option}; diff --git a/noir-projects/noir-contracts/contracts/card_game_contract/src/main.nr b/noir-projects/noir-contracts/contracts/card_game_contract/src/main.nr index d4416eff7cd..fb37c121fcb 100644 --- a/noir-projects/noir-contracts/contracts/card_game_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/card_game_contract/src/main.nr @@ -2,12 +2,12 @@ mod cards; mod game; contract CardGame { - use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress, constants::MAX_NOTES_PER_PAGE}; + use dep::aztec::protocol_types::{abis::function_selector::FunctionSelector, address::AztecAddress}; use dep::aztec::{context::Context, hash::pedersen_hash, state_vars::{Map, PublicMutable}}; use dep::value_note::{balance_utils, value_note::{ValueNote, VALUE_NOTE_LEN}}; - use dep::aztec::note::note_header::NoteHeader; + use dep::aztec::note::{note_header::NoteHeader, constants::MAX_NOTES_PER_PAGE}; use crate::cards::{PACK_CARDS, Deck, Card, get_pack_cards, compute_deck_strength}; use crate::game::{NUMBER_OF_PLAYERS, NUMBER_OF_CARDS_DECK, PLAYABLE_CARDS, PlayerEntry, Game, GAME_SERIALIZED_LEN}; diff --git a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr index 92e8ad6490c..851b8e59ee6 100644 --- a/noir-projects/noir-contracts/contracts/test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/test_contract/src/main.nr @@ -7,9 +7,11 @@ contract Test { use dep::aztec::protocol_types::{ abis::private_circuit_public_inputs::PrivateCircuitPublicInputs, - constants::{MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NOTES_PER_PAGE}, traits::Serialize + constants::{MAX_NOTE_HASH_READ_REQUESTS_PER_CALL}, traits::Serialize }; + use dep::aztec::note::constants::MAX_NOTES_PER_PAGE; + use dep::aztec::state_vars::shared_mutable::SharedMutablePrivateGetter; // docs:start:unencrypted_import diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr index 0e49b29d76d..09fbc60463e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr @@ -93,32 +93,32 @@ impl Serialize for PrivateCircuitPublicInp fields.extend_from_array(self.max_block_number.serialize()); - for i in 0..MAX_NOTE_HASH_READ_REQUESTS_PER_CALL{ + for i in 0..self.note_hash_read_requests.len() { fields.extend_from_array(self.note_hash_read_requests[i].serialize()); } - for i in 0..MAX_NULLIFIER_READ_REQUESTS_PER_CALL{ + for i in 0..self.nullifier_read_requests.len() { fields.extend_from_array(self.nullifier_read_requests[i].serialize()); } - for i in 0..MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL{ + for i in 0..self.nullifier_key_validation_requests.len() { fields.extend_from_array(self.nullifier_key_validation_requests[i].serialize()); } - for i in 0..MAX_NEW_NOTE_HASHES_PER_CALL{ + for i in 0..self.new_note_hashes.len() { fields.extend_from_array(self.new_note_hashes[i].serialize()); } - for i in 0..MAX_NEW_NULLIFIERS_PER_CALL{ + for i in 0..self.new_nullifiers.len() { fields.extend_from_array(self.new_nullifiers[i].serialize()); } fields.extend_from_array(self.private_call_stack_hashes); fields.extend_from_array(self.public_call_stack_hashes); - for i in 0..MAX_NEW_L2_TO_L1_MSGS_PER_CALL { + for i in 0..self.new_l2_to_l1_msgs.len() { fields.extend_from_array(self.new_l2_to_l1_msgs[i].serialize()); } fields.push(self.start_side_effect_counter as Field); fields.push(self.end_side_effect_counter as Field); - for i in 0..MAX_ENCRYPTED_LOGS_PER_CALL{ + for i in 0..self.encrypted_logs_hashes.len() { fields.extend_from_array(self.encrypted_logs_hashes[i].serialize()); } - for i in 0..MAX_UNENCRYPTED_LOGS_PER_CALL{ + for i in 0..self.unencrypted_logs_hashes.len() { fields.extend_from_array(self.unencrypted_logs_hashes[i].serialize()); } fields.push(self.encrypted_log_preimages_length); diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr index 6ac77bcc55d..ca5dc4742f3 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/public_circuit_public_inputs.nr @@ -17,7 +17,7 @@ use crate::{ traits::{Hash, Serialize, Deserialize, Empty}, utils::reader::Reader }; -struct PublicCircuitPublicInputs{ +struct PublicCircuitPublicInputs { call_context: CallContext, args_hash: Field, 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 1d6acb753f1..1a1e221405c 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 @@ -1,10 +1,10 @@ use crate::{ abis::side_effect::{OrderedValue, ContractScopedOrderedValue}, - traits::{Empty, Serialize, Deserialize}, address::AztecAddress + traits::{Empty, Serialize, Deserialize}, address::AztecAddress, + constants::READ_REQUEST_LENGTH, }; use dep::std::cmp::Eq; -global READ_REQUEST_SERIALIZED_LEN = 2; global READ_REQUEST_CONTEXT_SERIALIZED_LEN = 3; struct ReadRequest { @@ -37,14 +37,14 @@ impl Empty for ReadRequest { } } -impl Serialize for ReadRequest { - fn serialize(self) -> [Field; READ_REQUEST_SERIALIZED_LEN] { +impl Serialize for ReadRequest { + fn serialize(self) -> [Field; READ_REQUEST_LENGTH] { [self.value, self.counter as Field] } } -impl Deserialize for ReadRequest { - fn deserialize(values: [Field; READ_REQUEST_SERIALIZED_LEN]) -> Self { +impl Deserialize for ReadRequest { + fn deserialize(values: [Field; READ_REQUEST_LENGTH]) -> Self { Self { value: values[0], counter: values[1] as u32, 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 d7e4cca3fe8..63448cc0ebe 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 @@ -1,11 +1,10 @@ use crate::{ address::AztecAddress, constants::GENERATOR_INDEX__SIDE_EFFECT, - traits::{Empty, Hash, Serialize, Deserialize} + traits::{Empty, Hash, Serialize, Deserialize}, + constants::{SIDE_EFFECT_LENGTH, SIDE_EFFECT_LINKED_TO_NOTE_HASH_LENGTH}, }; use dep::std::cmp::Eq; -global SIDE_EFFECT_SERIALIZED_LEN = 2; - trait Ordered { fn counter(self) -> u32; } @@ -64,14 +63,14 @@ impl Hash for SideEffect { } } -impl Serialize for SideEffect { - fn serialize(self) -> [Field; SIDE_EFFECT_SERIALIZED_LEN] { +impl Serialize for SideEffect { + fn serialize(self) -> [Field; SIDE_EFFECT_LENGTH] { [self.value, self.counter as Field] } } -impl Deserialize for SideEffect { - fn deserialize(values: [Field; SIDE_EFFECT_SERIALIZED_LEN]) -> Self { +impl Deserialize for SideEffect { + fn deserialize(values: [Field; SIDE_EFFECT_LENGTH]) -> Self { Self { value: values[0], counter: values[1] as u32, @@ -79,7 +78,7 @@ impl Deserialize for SideEffect { } } -struct SideEffectLinkedToNoteHash{ +struct SideEffectLinkedToNoteHash { value: Field, note_hash: Field, counter: u32, @@ -126,14 +125,14 @@ impl Hash for SideEffectLinkedToNoteHash { } } -impl Serialize<3> for SideEffectLinkedToNoteHash { - fn serialize(self) -> [Field; 3] { +impl Serialize for SideEffectLinkedToNoteHash { + fn serialize(self) -> [Field; SIDE_EFFECT_LINKED_TO_NOTE_HASH_LENGTH] { [self.value, self.note_hash, self.counter as Field] } } -impl Deserialize<3> for SideEffectLinkedToNoteHash { - fn deserialize(values: [Field; 3]) -> Self { +impl Deserialize for SideEffectLinkedToNoteHash { + fn deserialize(values: [Field; SIDE_EFFECT_LINKED_TO_NOTE_HASH_LENGTH]) -> Self { Self { value: values[0], note_hash: values[1], 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 4d040a0db25..e8e5f1cf2ee 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -33,12 +33,8 @@ global MAX_NOTE_HASH_READ_REQUESTS_PER_CALL: u64 = 32; global MAX_NULLIFIER_READ_REQUESTS_PER_CALL: u64 = 2; // Change it to a larger value when there's a seperate reset circuit. global MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL: u64 = 2; global MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL: u64 = 1; -// Note: if changing enc logs per call value by n, change PRIVATE_CALL_STACK_ITEM_LENGTH and PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH by 2n -// and change DEPLOYER_CONTRACT_ADDRESS to new value -global MAX_ENCRYPTED_LOGS_PER_CALL: u64 = 4; -// Note: if changing unenc logs per call value by n, change PRIVATE_CALL_STACK_ITEM_LENGTH, PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH, and PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH by 2n -// and change DEPLOYER_CONTRACT_ADDRESS to new value -global MAX_UNENCRYPTED_LOGS_PER_CALL: u64 = 4; +global MAX_ENCRYPTED_LOGS_PER_CALL: u64 = 4; // If modifying, update DEPLOYER_CONTRACT_ADDRESS. +global MAX_UNENCRYPTED_LOGS_PER_CALL: u64 = 4; // If modifying, update DEPLOYER_CONTRACT_ADDRESS. // "PER TRANSACTION" CONSTANTS global MAX_NEW_NOTE_HASHES_PER_TX: u64 = 64; @@ -59,7 +55,9 @@ global NUM_UNENCRYPTED_LOGS_HASHES_PER_TX: u64 = 1; // docs:end:constants // KERNEL CIRCUIT PRIVATE INPUTS CONSTANTS -global MAX_PUBLIC_DATA_HINTS: u64 = 64; // MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX + MAX_PUBLIC_DATA_READS_PER_TX; +// global MAX_PUBLIC_DATA_HINTS: u64 = MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX + MAX_PUBLIC_DATA_READS_PER_TX; +// FIX: Sadly, writing this as above causes a type error in type_conversion.ts. +global MAX_PUBLIC_DATA_HINTS: u64 = 64; // ROLLUP CONTRACT CONSTANTS - constants used only in l1-contracts global NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP: u64 = 16; @@ -101,8 +99,7 @@ global MAX_ARGS_LENGTH: u64 = ARGS_HASH_CHUNK_COUNT * ARGS_HASH_CHUNK_LENGTH; // to be large enough so that it's ensured that it doesn't collide with storage slots of other variables. global INITIALIZATION_SLOT_SEPARATOR: Field = 1000_000_000; global INITIAL_L2_BLOCK_NUM: Field = 1; -// 126976 = 31 * 4096; -global BLOB_SIZE_IN_BYTES: Field = 126976; +global BLOB_SIZE_IN_BYTES: Field = 31 * 4096; // How much gas is subtracted from L2GASLEFT when making a nested public call by default in the AVM global NESTED_CALL_L2_GAS_BUFFER = 20000; @@ -131,27 +128,13 @@ global REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = 0xe7af8166354 global DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631; global DEPLOYER_CONTRACT_ADDRESS = 0x1b5ecf3d26907648cf737f4304759b8c5850478e839e72f8ce1f5791b286e8f2; -// NOIR CONSTANTS - constants used only in yarn-packages/noir-contracts -// Some are defined here because Noir doesn't yet support globals referencing other globals yet. -// Move these constants to a noir file once the issue below is resolved: -// https://github.com/noir-lang/noir/issues/1734 -global L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH: u64 = 17; -global MAX_NOTE_FIELDS_LENGTH: u64 = 20; -// GET_NOTE_ORACLE_RETURN_LENGT = MAX_NOTE_FIELDS_LENGTH + 1 + 2 -// The plus 1 is 1 extra field for nonce. -// + 2 for EXTRA_DATA: [number_of_return_notes, contract_address] -global GET_NOTE_ORACLE_RETURN_LENGTH: u64 = 23; -global MAX_NOTES_PER_PAGE: u64 = 10; -// VIEW_NOTE_ORACLE_RETURN_LENGTH = MAX_NOTES_PER_PAGE * (MAX_NOTE_FIELDS_LENGTH + 1) + 2; -global VIEW_NOTE_ORACLE_RETURN_LENGTH: u64 = 212; - // LENGTH OF STRUCTS SERIALIZED TO FIELDS global AZTEC_ADDRESS_LENGTH = 1; -global CALL_CONTEXT_LENGTH: u64 = 21; // 8 + GAS_SETTINGS_LENGTH + GAS_LENGTH -global GAS_SETTINGS_LENGTH: u64 = 10; // 1 + 3 * DIMENSION_GAS_SETTINGS_LENGTH global DIMENSION_GAS_SETTINGS_LENGTH: u64 = 3; global GAS_FEES_LENGTH: u64 = 3; global GAS_LENGTH: u64 = 3; +global GAS_SETTINGS_LENGTH: u64 = 1 + 3 * DIMENSION_GAS_SETTINGS_LENGTH; +global CALL_CONTEXT_LENGTH: u64 = 8 + GAS_SETTINGS_LENGTH + GAS_LENGTH; global CONTENT_COMMITMENT_LENGTH: u64 = 4; global CONTRACT_INSTANCE_LENGTH: u64 = 6; global CONTRACT_STORAGE_READ_LENGTH: u64 = 2; @@ -159,26 +142,26 @@ global CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH: u64 = 2; global ETH_ADDRESS_LENGTH = 1; global FUNCTION_DATA_LENGTH: u64 = 2; global FUNCTION_LEAF_PREIMAGE_LENGTH: u64 = 5; -global GLOBAL_VARIABLES_LENGTH: u64 = 9; // 6 + GAS_FEES_LENGTH -global HEADER_LENGTH: u64 = 23; // 2 for last_archive + 4 for content commitment + 8 for state reference + GLOBAL_VARIABLES_LENGTH +global GLOBAL_VARIABLES_LENGTH: u64 = 6 + GAS_FEES_LENGTH; +global APPEND_ONLY_TREE_SNAPSHOT_LENGTH = 2; global L1_TO_L2_MESSAGE_LENGTH: u64 = 6; global L2_TO_L1_MESSAGE_LENGTH: u64 = 2; global MAX_BLOCK_NUMBER_LENGTH: u64 = 2; // 1 for the option flag, 1 for the value global NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH = 4; global NULLIFIER_KEY_VALIDATION_REQUEST_CONTEXT_LENGTH = 5; global PARTIAL_STATE_REFERENCE_LENGTH: u64 = 6; -global PRIVATE_CALL_STACK_ITEM_LENGTH: u64 = 238; -// Change this ONLY if you have changed the PrivateCircuitPublicInputs structure. -// In other words, if the structure/size of the public inputs of a function call changes then we should change this -// constant as well PRIVATE_CALL_STACK_ITEM_LENGTH -global PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH: u64 = 235; -// Change this ONLY if you have changed the PublicCircuitPublicInputs structure. -global PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH: u64 = 222; -global STATE_REFERENCE_LENGTH: u64 = 8; // 2 for snap + 8 for partial +global READ_REQUEST_LENGTH = 2; +global SIDE_EFFECT_LENGTH = 2; +global SIDE_EFFECT_LINKED_TO_NOTE_HASH_LENGTH = 3; +global STATE_REFERENCE_LENGTH: u64 = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH; global TX_CONTEXT_DATA_LENGTH: u64 = 4; -global TX_REQUEST_LENGTH: u64 = 18; // 2 + TX_CONTEXT_DATA_LENGTH + FUNCTION_DATA_LENGTH + GAS_SETTINGS_LENGTH +global TX_REQUEST_LENGTH: u64 = 2 + TX_CONTEXT_DATA_LENGTH + FUNCTION_DATA_LENGTH + GAS_SETTINGS_LENGTH; +global HEADER_LENGTH: u64 = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + CONTENT_COMMITMENT_LENGTH + STATE_REFERENCE_LENGTH + GLOBAL_VARIABLES_LENGTH; +global PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH: u64 = CALL_CONTEXT_LENGTH + 3 + MAX_BLOCK_NUMBER_LENGTH + (SIDE_EFFECT_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) + (SIDE_EFFECT_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (SIDE_EFFECT_LINKED_TO_NOTE_HASH_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + (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 + 2; +global PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH: u64 = 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 + (SIDE_EFFECT_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (SIDE_EFFECT_LINKED_TO_NOTE_HASH_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 + AZTEC_ADDRESS_LENGTH + /* revert_code */ 1 + GAS_LENGTH; +global PRIVATE_CALL_STACK_ITEM_LENGTH: u64 = AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH; -global ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH: Field = 25; // 2 + FUNCTION_DATA_LENGTH + CALL_CONTEXT_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; global NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP: Field = 2048; @@ -189,7 +172,8 @@ global CONTRACT_DATA_NUM_BYTES_PER_BASE_ROLLUP_UNPADDED: Field = 52; global L2_TO_L1_MSGS_NUM_BYTES_PER_BASE_ROLLUP: Field = 64; global LOGS_HASHES_NUM_BYTES_PER_BASE_ROLLUP: Field = 64; global NUM_MSGS_PER_BASE_PARITY: u64 = 4; -// NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP / NUM_MSGS_PER_BASE_PARITY +// global NUM_BASE_PARITY_PER_ROOT_PARITY: u64 = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP / NUM_MSGS_PER_BASE_PARITY; +// FIX: Sadly, writing this as above causes a type error in type_conversion.ts. global NUM_BASE_PARITY_PER_ROOT_PARITY: u64 = 4; /** 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 01176175f60..34654e18775 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 @@ -4,7 +4,7 @@ use crate::{ }; use dep::std::cmp::Eq; -struct StorageUpdateRequest{ +struct StorageUpdateRequest { storage_slot : Field, new_value : Field, } diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 9ac707568fd..6441113ed89 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -56,9 +56,10 @@ export const L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH = 12; export const FUNCTION_SELECTOR_NUM_BYTES = 4; export const ARGS_HASH_CHUNK_LENGTH = 64; export const ARGS_HASH_CHUNK_COUNT = 64; +export const MAX_ARGS_LENGTH = ARGS_HASH_CHUNK_COUNT * ARGS_HASH_CHUNK_LENGTH; export const INITIALIZATION_SLOT_SEPARATOR = 1000_000_000; export const INITIAL_L2_BLOCK_NUM = 1; -export const BLOB_SIZE_IN_BYTES = 126976; +export const BLOB_SIZE_IN_BYTES = 31 * 4096; export const NESTED_CALL_L2_GAS_BUFFER = 20000; export const MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 16200; export const MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 3000; @@ -74,17 +75,12 @@ export const REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE = export const DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE = 0x85864497636cf755ae7bde03f267ce01a520981c21c3682aaf82a631n; export const DEPLOYER_CONTRACT_ADDRESS = 0x1b5ecf3d26907648cf737f4304759b8c5850478e839e72f8ce1f5791b286e8f2n; -export const L1_TO_L2_MESSAGE_ORACLE_CALL_LENGTH = 17; -export const MAX_NOTE_FIELDS_LENGTH = 20; -export const GET_NOTE_ORACLE_RETURN_LENGTH = 23; -export const MAX_NOTES_PER_PAGE = 10; -export const VIEW_NOTE_ORACLE_RETURN_LENGTH = 212; export const AZTEC_ADDRESS_LENGTH = 1; -export const CALL_CONTEXT_LENGTH = 21; -export const GAS_SETTINGS_LENGTH = 10; export const DIMENSION_GAS_SETTINGS_LENGTH = 3; export const GAS_FEES_LENGTH = 3; export const GAS_LENGTH = 3; +export const GAS_SETTINGS_LENGTH = 1 + 3 * DIMENSION_GAS_SETTINGS_LENGTH; +export const CALL_CONTEXT_LENGTH = 8 + GAS_SETTINGS_LENGTH + GAS_LENGTH; export const CONTENT_COMMITMENT_LENGTH = 4; export const CONTRACT_INSTANCE_LENGTH = 6; export const CONTRACT_STORAGE_READ_LENGTH = 2; @@ -92,21 +88,61 @@ export const CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH = 2; export const ETH_ADDRESS_LENGTH = 1; export const FUNCTION_DATA_LENGTH = 2; export const FUNCTION_LEAF_PREIMAGE_LENGTH = 5; -export const GLOBAL_VARIABLES_LENGTH = 9; -export const HEADER_LENGTH = 23; +export const GLOBAL_VARIABLES_LENGTH = 6 + GAS_FEES_LENGTH; +export const APPEND_ONLY_TREE_SNAPSHOT_LENGTH = 2; export const L1_TO_L2_MESSAGE_LENGTH = 6; export const L2_TO_L1_MESSAGE_LENGTH = 2; export const MAX_BLOCK_NUMBER_LENGTH = 2; export const NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH = 4; export const NULLIFIER_KEY_VALIDATION_REQUEST_CONTEXT_LENGTH = 5; export const PARTIAL_STATE_REFERENCE_LENGTH = 6; -export const PRIVATE_CALL_STACK_ITEM_LENGTH = 238; -export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = 235; -export const PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH = 222; -export const STATE_REFERENCE_LENGTH = 8; +export const READ_REQUEST_LENGTH = 2; +export const SIDE_EFFECT_LENGTH = 2; +export const SIDE_EFFECT_LINKED_TO_NOTE_HASH_LENGTH = 3; +export const STATE_REFERENCE_LENGTH = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + PARTIAL_STATE_REFERENCE_LENGTH; export const TX_CONTEXT_DATA_LENGTH = 4; -export const TX_REQUEST_LENGTH = 18; -export const ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH = 25; +export const TX_REQUEST_LENGTH = 2 + TX_CONTEXT_DATA_LENGTH + FUNCTION_DATA_LENGTH + GAS_SETTINGS_LENGTH; +export const HEADER_LENGTH = + APPEND_ONLY_TREE_SNAPSHOT_LENGTH + CONTENT_COMMITMENT_LENGTH + STATE_REFERENCE_LENGTH + GLOBAL_VARIABLES_LENGTH; +export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = + CALL_CONTEXT_LENGTH + + 3 + + MAX_BLOCK_NUMBER_LENGTH + + SIDE_EFFECT_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 + + SIDE_EFFECT_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL + + SIDE_EFFECT_LINKED_TO_NOTE_HASH_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL + + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + + 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 + + 2; +export const 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 + + SIDE_EFFECT_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL + + SIDE_EFFECT_LINKED_TO_NOTE_HASH_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 + + AZTEC_ADDRESS_LENGTH + + /* revert_code */ 1 + + GAS_LENGTH; +export const PRIVATE_CALL_STACK_ITEM_LENGTH = + AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_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; export const NULLIFIERS_NUM_BYTES_PER_BASE_ROLLUP = 2048; diff --git a/yarn-project/circuits.js/src/scripts/constants.in.ts b/yarn-project/circuits.js/src/scripts/constants.in.ts index a5fadc66e2a..33ede0eded4 100644 --- a/yarn-project/circuits.js/src/scripts/constants.in.ts +++ b/yarn-project/circuits.js/src/scripts/constants.in.ts @@ -122,7 +122,7 @@ function parseNoirFile(fileContent: string): ParsedContent { return; } - const [, name, _type, value] = line.match(/global\s+(\w+)(\s*:\s*\w+)?\s*=\s*(0x[a-fA-F0-9]+|[\d_]+);/) || []; + const [, name, _type, value] = line.match(/global\s+(\w+)(\s*:\s*\w+)?\s*=\s*(.+?);/) || []; if (!name || !value) { // eslint-disable-next-line no-console