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 341c83681c1b..29242863c9bd 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 @@ -1,9 +1,9 @@ -use crate::context::{Context}; -use crate::oracle::{storage::{storage_read, storage_write}}; -use crate::history::public_value_inclusion::prove_public_value_inclusion; -use dep::std::option::Option; -use dep::protocol_types::traits::{Deserialize, Serialize}; -use crate::state_vars::storage::Storage; +use crate::{ + context::{Context}, hash::pedersen_hash, + history::public_value_inclusion::prove_public_value_inclusion, + oracle::{storage::{storage_read, storage_write}}, state_vars::storage::Storage +}; +use dep::protocol_types::{constants::GENERATOR_INDEX__IMMUTABLE_INITIALIZE_PLACEHOLDER, traits::{Deserialize, Serialize}}; struct SharedImmutable{ context: Context, @@ -18,9 +18,7 @@ impl SharedImmutable { context: Context, storage_slot: Field ) -> Self { - assert( - (storage_slot != 0) & (storage_slot != 1), "Storage slots 0 and 1 not allowed. Storage slots must start from 2." - ); + assert(storage_slot != 0, "Storage slot 0 not allowed. Storage slots must start from 1."); Self { context, storage_slot } } @@ -32,9 +30,12 @@ impl SharedImmutable { self.context.public.unwrap_unchecked().assert_deployment(); // We check that the struct is not yet initialized by checking if the placeholder slot is 0 - let placeholder_storage_slot = self.storage_slot - 1; + let placeholder_storage_slot = pedersen_hash( + [self.storage_slot], + GENERATOR_INDEX__IMMUTABLE_INITIALIZE_PLACEHOLDER + ); let fields_read: [Field; 1] = storage_read(placeholder_storage_slot); - assert(fields_read[0] != 0, "SharedImmutable already initialized"); + assert(fields_read[0] == 0, "SharedImmutable already initialized"); // We populate the placeholder slot with a non-zero value to indicate that the struct is initialized storage_write(placeholder_storage_slot, [0xdead]); 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..99b7f0068339 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 @@ -230,3 +230,4 @@ global GENERATOR_INDEX__VK = 41; global GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS = 42; global GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS = 43; global GENERATOR_INDEX__FUNCTION_ARGS = 44; +global GENERATOR_INDEX__IMMUTABLE_INITIALIZE_PLACEHOLDER = 45; diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 47bbff17361c..bfb3ef3f4626 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -144,4 +144,5 @@ export enum GeneratorIndex { PRIVATE_CIRCUIT_PUBLIC_INPUTS = 42, PUBLIC_CIRCUIT_PUBLIC_INPUTS = 43, FUNCTION_ARGS = 44, + IMMUTABLE_INITIALIZE_PLACEHOLDER = 45, }