@@ -43,35 +43,49 @@ impl TreeHashFunctionImpl {
4343/// <https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/starknet-state/#trie_construction>
4444impl TreeHashFunction < ContractState > for TreeHashFunctionImpl {
4545 fn compute_leaf_hash ( contract_state : & ContractState ) -> HashOutput {
46- HashOutput ( Pedersen :: hash (
47- & Pedersen :: hash (
48- & Pedersen :: hash ( & contract_state. class_hash . 0 , & contract_state. storage_root_hash . 0 ) ,
49- & contract_state. nonce . 0 ,
50- ) ,
51- & Self :: CONTRACT_STATE_HASH_VERSION ,
52- ) )
46+ compute_contract_state_leaf_hash ( contract_state)
5347 }
5448 fn compute_node_hash ( node_data : & NodeData < ContractState , HashOutput > ) -> HashOutput {
5549 Self :: compute_node_hash_with_inner_hash_function :: < PedersenHashFunction > ( node_data)
5650 }
5751}
5852
53+ fn compute_contract_state_leaf_hash < L : AsRef < ContractState > > (
54+ contract_state_leaf : & L ,
55+ ) -> HashOutput {
56+ let contract_state: & ContractState = contract_state_leaf. as_ref ( ) ;
57+ HashOutput ( Pedersen :: hash (
58+ & Pedersen :: hash (
59+ & Pedersen :: hash ( & contract_state. class_hash . 0 , & contract_state. storage_root_hash . 0 ) ,
60+ & contract_state. nonce . 0 ,
61+ ) ,
62+ & TreeHashFunctionImpl :: CONTRACT_STATE_HASH_VERSION ,
63+ ) )
64+ }
65+
5966/// Implementation of TreeHashFunction for the classes trie.
6067/// The implementation is based on the following reference:
6168/// <https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/starknet-state/#trie_construction>
6269impl TreeHashFunction < CompiledClassHash > for TreeHashFunctionImpl {
6370 fn compute_leaf_hash ( compiled_class_hash : & CompiledClassHash ) -> HashOutput {
64- let contract_class_leaf_version: Felt = Felt :: from_hex ( Self :: CONTRACT_CLASS_LEAF_V0 )
65- . expect (
66- "could not parse hex string corresponding to b'CONTRACT_CLASS_LEAF_V0' to Felt" ,
67- ) ;
68- HashOutput ( Poseidon :: hash ( & contract_class_leaf_version, & compiled_class_hash. 0 ) )
71+ compute_compiled_class_leaf_hash ( compiled_class_hash)
6972 }
7073 fn compute_node_hash ( node_data : & NodeData < CompiledClassHash , HashOutput > ) -> HashOutput {
7174 Self :: compute_node_hash_with_inner_hash_function :: < PoseidonHashFunction > ( node_data)
7275 }
7376}
7477
78+ fn compute_compiled_class_leaf_hash < L : AsRef < CompiledClassHash > > (
79+ compiled_class_hash_leaf : & L ,
80+ ) -> HashOutput {
81+ let compiled_class_hash: & CompiledClassHash = compiled_class_hash_leaf. as_ref ( ) ;
82+ let contract_class_leaf_version: Felt = Felt :: from_hex (
83+ TreeHashFunctionImpl :: CONTRACT_CLASS_LEAF_V0 ,
84+ )
85+ . expect ( "could not parse hex string corresponding to b'CONTRACT_CLASS_LEAF_V0' to Felt" ) ;
86+ HashOutput ( Poseidon :: hash ( & contract_class_leaf_version, & compiled_class_hash. 0 ) )
87+ }
88+
7589/// Implementation of TreeHashFunction for the storage trie.
7690/// The implementation is based on the following reference:
7791/// <https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/starknet-state/#trie_construction>
0 commit comments