@@ -3,6 +3,8 @@ use std::marker::PhantomData;
33use std:: sync:: LazyLock ;
44
55use async_trait:: async_trait;
6+ #[ cfg( feature = "os_input" ) ]
7+ use starknet_api:: block:: BlockNumber ;
68use starknet_api:: core:: { ContractAddress , PATRICIA_KEY_UPPER_BOUND_FELT } ;
79use starknet_api:: hash:: { HashOutput , StateRoots } ;
810use starknet_patricia:: db_layout:: { NodeLayout , NodeLayoutFor } ;
@@ -50,6 +52,8 @@ use crate::db::index_db::types::{
5052 IndexLayoutSubTree ,
5153 IndexNodeContext ,
5254} ;
55+ #[ cfg( feature = "os_input" ) ]
56+ use crate :: db:: serde_db_utils:: DbBlockNumber ;
5357use crate :: forest:: deleted_nodes:: DeletedNodes ;
5458use crate :: forest:: filled_forest:: FilledForest ;
5559use crate :: forest:: forest_errors:: ForestResult ;
@@ -84,6 +88,28 @@ static STATE_ROOT_METADATA_PREFIX: LazyLock<[u8; 32]> = LazyLock::new(|| {
8488 ( Felt :: from_bytes_be ( & STATE_DIFF_HASH_METADATA_PREFIX ) + Felt :: ONE ) . to_bytes_be ( )
8589} ) ;
8690
91+ /// Prefix for accessed-keys digest metadata (committed per block).
92+ #[ cfg( feature = "os_input" ) ]
93+ pub ( crate ) static ACCESSED_KEYS_DIGEST_METADATA_PREFIX : LazyLock < [ u8 ; 32 ] > =
94+ LazyLock :: new ( || ( Felt :: from_bytes_be ( & STATE_ROOT_METADATA_PREFIX ) + Felt :: ONE ) . to_bytes_be ( ) ) ;
95+
96+ /// Prefix for merged Patricia proofs payload KV (per block).
97+ #[ cfg( feature = "os_input" ) ]
98+ pub ( crate ) static PATRICIA_PATHS_PREFIX : LazyLock < [ u8 ; 32 ] > = LazyLock :: new ( || {
99+ ( Felt :: from_bytes_be ( & ACCESSED_KEYS_DIGEST_METADATA_PREFIX ) + Felt :: ONE ) . to_bytes_be ( )
100+ } ) ;
101+
102+ /// DB key for persisted merged Patricia proofs at `height`.
103+ #[ cfg( feature = "os_input" ) ]
104+ pub ( crate ) fn patricia_proofs_db_key ( height : BlockNumber ) -> DbKey {
105+ let mut key = Vec :: with_capacity ( 64 ) ;
106+ key. extend_from_slice ( & * PATRICIA_PATHS_PREFIX ) ;
107+ let block_number_bytes: [ u8 ; 8 ] = DbBlockNumber ( height) . serialize ( ) ;
108+ key. extend_from_slice ( & block_number_bytes) ;
109+ key. extend_from_slice ( & [ 0u8 ; 24 ] ) ;
110+ DbKey ( key)
111+ }
112+
87113pub struct IndexDb < S : Storage , H = TreeHashFunctionImpl > {
88114 storage : S ,
89115 phantom : PhantomData < H > ,
@@ -287,6 +313,13 @@ impl<S: Storage> ForestMetadata for IndexDb<S> {
287313 key. extend_from_slice ( & block_number_bytes) ;
288314 key. extend_from_slice ( & [ 0u8 ; 24 ] ) ;
289315 }
316+ #[ cfg( feature = "os_input" ) ]
317+ ForestMetadataType :: OsInputWitnessDigest ( block_number) => {
318+ key. extend_from_slice ( & * ACCESSED_KEYS_DIGEST_METADATA_PREFIX ) ;
319+ let block_number_bytes: [ u8 ; 8 ] = block_number. serialize ( ) ;
320+ key. extend_from_slice ( & block_number_bytes) ;
321+ key. extend_from_slice ( & [ 0u8 ; 24 ] ) ;
322+ }
290323 }
291324 DbKey ( key)
292325 }
0 commit comments