diff --git a/crates/blockifier/src/state/stateful_compression.rs b/crates/blockifier/src/state/stateful_compression.rs index 9617817bf0..30245bc323 100644 --- a/crates/blockifier/src/state/stateful_compression.rs +++ b/crates/blockifier/src/state/stateful_compression.rs @@ -19,11 +19,9 @@ type AliasKey = StorageKey; const INITIAL_AVAILABLE_ALIAS: Felt = Felt::from_hex_unchecked("0x80"); // The address of the alias contract. -static ALIAS_CONTRACT_ADDRESS: LazyLock = - LazyLock::new(|| ContractAddress(PatriciaKey::try_from(Felt::TWO).unwrap())); +const ALIAS_CONTRACT_ADDRESS: ContractAddress = ContractAddress(PatriciaKey::TWO); // The storage key of the alias counter in the alias contract. -static ALIAS_COUNTER_STORAGE_KEY: LazyLock = - LazyLock::new(|| StorageKey(PatriciaKey::try_from(Felt::ZERO).unwrap())); +const ALIAS_COUNTER_STORAGE_KEY: StorageKey = StorageKey(PatriciaKey::ZERO); // The minimal value for a key to be allocated an alias. Smaller keys are serialized as is (their // alias is identical to the key). static MIN_VALUE_FOR_ALIAS_ALLOC: LazyLock = @@ -39,7 +37,7 @@ struct AliasUpdater<'a, S: StateReader> { impl<'a, S: StateReader> AliasUpdater<'a, S> { fn new(state: &'a CachedState) -> StateResult { let stored_counter = - state.get_storage_at(*ALIAS_CONTRACT_ADDRESS, *ALIAS_COUNTER_STORAGE_KEY)?; + state.get_storage_at(ALIAS_CONTRACT_ADDRESS, ALIAS_COUNTER_STORAGE_KEY)?; Ok(Self { state, new_aliases: HashMap::new(), @@ -50,7 +48,7 @@ impl<'a, S: StateReader> AliasUpdater<'a, S> { /// Inserts the alias key to the updates if it's not already aliased. fn insert_alias(&mut self, alias_key: &AliasKey) -> StateResult<()> { if alias_key.0 >= *MIN_VALUE_FOR_ALIAS_ALLOC - && self.state.get_storage_at(*ALIAS_CONTRACT_ADDRESS, *alias_key)? == Felt::ZERO + && self.state.get_storage_at(ALIAS_CONTRACT_ADDRESS, *alias_key)? == Felt::ZERO && !self.new_aliases.contains_key(alias_key) { let alias_to_allocate = match self.next_free_alias { @@ -68,18 +66,18 @@ impl<'a, S: StateReader> AliasUpdater<'a, S> { fn finalize_updates(mut self) -> HashMap { match self.next_free_alias { None => { - self.new_aliases.insert(*ALIAS_COUNTER_STORAGE_KEY, INITIAL_AVAILABLE_ALIAS); + self.new_aliases.insert(ALIAS_COUNTER_STORAGE_KEY, INITIAL_AVAILABLE_ALIAS); } Some(alias) => { if !self.new_aliases.is_empty() { - self.new_aliases.insert(*ALIAS_COUNTER_STORAGE_KEY, alias); + self.new_aliases.insert(ALIAS_COUNTER_STORAGE_KEY, alias); } } } self.new_aliases .into_iter() - .map(|(key, alias)| ((*ALIAS_CONTRACT_ADDRESS, key), alias)) + .map(|(key, alias)| ((ALIAS_CONTRACT_ADDRESS, key), alias)) .collect() } } diff --git a/crates/blockifier/src/state/stateful_compression_test.rs b/crates/blockifier/src/state/stateful_compression_test.rs index d0717221cd..b490881852 100644 --- a/crates/blockifier/src/state/stateful_compression_test.rs +++ b/crates/blockifier/src/state/stateful_compression_test.rs @@ -18,7 +18,7 @@ fn insert_to_alias_contract( key: StorageKey, value: Felt, ) { - storage.insert((*ALIAS_CONTRACT_ADDRESS, key), value); + storage.insert((ALIAS_CONTRACT_ADDRESS, key), value); } fn initial_state(n_existing_aliases: u8) -> CachedState { @@ -27,7 +27,7 @@ fn initial_state(n_existing_aliases: u8) -> CachedState { let high_alias_key = INITIAL_AVAILABLE_ALIAS * Felt::TWO; insert_to_alias_contract( &mut state_reader.storage_view, - *ALIAS_COUNTER_STORAGE_KEY, + ALIAS_COUNTER_STORAGE_KEY, INITIAL_AVAILABLE_ALIAS + Felt::from(n_existing_aliases), ); for i in 0..n_existing_aliases { @@ -89,7 +89,7 @@ fn test_alias_updater( if !expected_alias_keys.is_empty() || n_existing_aliases == 0 { insert_to_alias_contract( &mut expected_storage_diff, - *ALIAS_COUNTER_STORAGE_KEY, + ALIAS_COUNTER_STORAGE_KEY, expected_next_alias, ); } diff --git a/crates/starknet_api/src/core.rs b/crates/starknet_api/src/core.rs index 8b1a055462..8aaa23f66e 100644 --- a/crates/starknet_api/src/core.rs +++ b/crates/starknet_api/src/core.rs @@ -354,6 +354,10 @@ pub const PATRICIA_KEY_UPPER_BOUND: &str = "0x800000000000000000000000000000000000000000000000000000000000000"; impl PatriciaKey { + pub const ZERO: Self = Self(StarkHash::ZERO); + pub const ONE: Self = Self(StarkHash::ONE); + pub const TWO: Self = Self(StarkHash::TWO); + pub fn key(&self) -> &StarkHash { &self.0 }