diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 6f1202c6c097..d429deaa406e 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -69,10 +69,10 @@ library Constants { uint256 internal constant L1_TO_L2_MSG_SUBTREE_HEIGHT = 4; uint256 internal constant L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH = 12; uint256 internal constant FUNCTION_SELECTOR_NUM_BYTES = 4; - uint256 internal constant MAPPING_SLOT_PEDERSEN_SEPARATOR = 4; uint256 internal constant NUM_FIELDS_PER_SHA256 = 2; uint256 internal constant ARGS_HASH_CHUNK_LENGTH = 32; uint256 internal constant ARGS_HASH_CHUNK_COUNT = 32; + uint256 internal constant INITIALIZATION_SLOT_SEPARATOR = 1000; uint256 internal constant MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 1000; uint256 internal constant MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 500; uint256 internal constant MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS = 500; diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/shared_immutable.nr b/noir-projects/aztec-nr/aztec/src/state_vars/shared_immutable.nr index fd122875b42d..32e0c82d68b2 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/shared_immutable.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/shared_immutable.nr @@ -2,7 +2,7 @@ use crate::{ context::Context, history::public_value_inclusion::prove_public_value_inclusion, oracle::{storage::{storage_read, storage_write}}, state_vars::storage::Storage }; -use dep::protocol_types::traits::{Deserialize, Serialize}; +use dep::protocol_types::{constants::INITIALIZATION_SLOT_SEPARATOR, traits::{Deserialize, Serialize}}; struct SharedImmutable{ context: Context, @@ -34,7 +34,7 @@ impl SharedImmutable { // ); // We check that the struct is not yet initialized by checking if the initialization slot is 0 - let initialization_slot = self.storage_slot - 1; + let initialization_slot = INITIALIZATION_SLOT_SEPARATOR + self.storage_slot; let fields_read: [Field; 1] = storage_read(initialization_slot); assert(fields_read[0] == 0, "SharedImmutable already initialized"); diff --git a/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr index be81885d0591..480b0f825e7d 100644 --- a/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/src/crates/types/src/constants.nr @@ -93,11 +93,11 @@ global L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH: Field = 12; // MISC CONSTANTS global FUNCTION_SELECTOR_NUM_BYTES: Field = 4; -global MAPPING_SLOT_PEDERSEN_SEPARATOR: Field = 4; // sha256 hash is stored in two fields to accommodate all 256-bits of the hash global NUM_FIELDS_PER_SHA256: Field = 2; global ARGS_HASH_CHUNK_LENGTH: u32 = 32; global ARGS_HASH_CHUNK_COUNT: u32 = 32; +global INITIALIZATION_SLOT_SEPARATOR: Field = 1000; // CONTRACT CLASS CONSTANTS // This should be around 8192 (assuming 2**15 instructions packed at 8 bytes each), diff --git a/noir/aztec_macros/src/lib.rs b/noir/aztec_macros/src/lib.rs index 5a4ea56396d3..1826d77b9bfb 100644 --- a/noir/aztec_macros/src/lib.rs +++ b/noir/aztec_macros/src/lib.rs @@ -932,8 +932,7 @@ fn assign_storage_slots( )), }?; - // We start from 2 because 0 storage slot is buggy and 1 is reserved for the initialization slot - let mut storage_slot: u64 = 2; + let mut storage_slot: u64 = 1; for (index, (_, expr_id)) in storage_constructor_expression.fields.iter().enumerate() { let fields = r#struct.borrow().get_fields(&[]); let (_, field_type) = fields.get(index).unwrap(); @@ -980,9 +979,7 @@ fn assign_storage_slots( )); }); - // We add 1 on the next line because some of the types use value in initialization storage slot - // (set as "type storage slot - 1") to determine whether the value in the type was already initialized. - storage_slot += type_serialized_len + 1; + storage_slot += type_serialized_len; } } } diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 47bbff17361c..9be3302b9b1e 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -55,10 +55,10 @@ export const PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH = 35; export const L1_TO_L2_MSG_SUBTREE_HEIGHT = 4; export const L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH = 12; export const FUNCTION_SELECTOR_NUM_BYTES = 4; -export const MAPPING_SLOT_PEDERSEN_SEPARATOR = 4; export const NUM_FIELDS_PER_SHA256 = 2; export const ARGS_HASH_CHUNK_LENGTH = 32; export const ARGS_HASH_CHUNK_COUNT = 32; +export const INITIALIZATION_SLOT_SEPARATOR = 1000; export const MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 1000; export const MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 500; export const MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS = 500;