Skip to content

Commit

Permalink
feat(blockifier): count the number of charged storage keys
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavGrs committed Nov 10, 2024
1 parent 8ca3e5d commit 500780f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions crates/blockifier/src/execution/alias_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,27 @@ use starknet_types_core::felt::Felt;
use crate::state::cached_state::{CachedState, StorageEntry};
use crate::state::state_api::{StateReader, StateResult};

/// Keys in contract addresses up to this address don't get aliases.
const N_SAVED_CONTRACT_ADDRESSES: u8 = 16;
/// The alias of a felt X up to this number is X.
/// This trivial mappings don't write to the alias contract.
const N_SELF_ALIASES: u8 = 128;

/// Returns the number of storage keys charged for new allocated aliases.
/// Counts keys that were previously empty and are now filled.
pub fn n_charged_storage_keys<S: StateReader>(
_state: &CachedState<S>,
_storage_changes: &HashMap<StorageEntry, Felt>,
state: &CachedState<S>,
storage_changes: &HashMap<StorageEntry, Felt>,
) -> StateResult<usize> {
// TODO: Implement this function
Ok(0)
let mut n_storage_keys = 0;
for ((contract_address, storage_key), new_value) in storage_changes {
if contract_address.0.0 >= N_SAVED_CONTRACT_ADDRESSES.into()
&& storage_key.0.0 >= N_SELF_ALIASES.into()
&& state.get_storage_at(*contract_address, *storage_key)? == Felt::ZERO
&& new_value != &Felt::ZERO
{
n_storage_keys += 1;
}
}
Ok(n_storage_keys)
}
2 changes: 1 addition & 1 deletion crates/starknet_api/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ pub struct StateDiffCommitment(pub PoseidonHash);
derive_more:: Deref,
)]
#[display(fmt = "{}", "_0.to_fixed_hex_string()")]
pub struct PatriciaKey(StarkHash);
pub struct PatriciaKey(pub StarkHash);

// 2**251
pub const PATRICIA_KEY_UPPER_BOUND: &str =
Expand Down

0 comments on commit 500780f

Please sign in to comment.