1- use crate::header:: {get_header , BlockHeaderPartial };
2- use crate::account:: {MAX_ACCOUNT_STATE_LEN , MAX_ACCOUNT_DEPTH_NO_LEAF_M , MAX_ACCOUNT_LEAF_LEN };
3- use crate::misc:: {types ::{Address , Bytes32 , BYTES32_LENGTH , HASH_LEN }, bytes:: right_pad , fragment::Fragment };
1+ use crate::account:: {MAX_ACCOUNT_DEPTH_NO_LEAF_M , MAX_ACCOUNT_LEAF_LEN , MAX_ACCOUNT_STATE_LEN };
2+ use crate::header:: {BlockHeaderPartial , get_header };
3+ use crate::merkle_patricia_proofs::proof::ProofInput ;
4+ use crate::misc:: {
5+ bytes:: right_pad ,
6+ fragment::Fragment ,
7+ types ::{Address , Bytes32 , BYTES32_LENGTH , HASH_LEN },
8+ };
9+ use crate::rlp::decode::decode_string ;
410use crate::serde::Serde ;
511use crate::verifiers::account::verify_account ;
612use crate::verifiers::storage::verify_storage_values ;
7- use crate::merkle_patricia_proofs::proof::ProofInput ;
8- use crate::rlp::decode::decode_string ;
913
1014use dep::std::hash::keccak256 ;
1115
@@ -17,15 +21,18 @@ global MAX_STORAGE_VALUE_LEN: u32 = 32; // Values taken from storageProofConfig
1721global MAX_STORAGE_LEAF_LEN : u32 = 69 ;
1822
1923struct Account {
20- nonce : u32 ,
24+ nonce : u64 ,
2125 balance : Field ,
2226 storage_root : Bytes32 ,
2327 code_hash : Bytes32 ,
2428}
2529
2630impl Eq for Account {
2731 fn eq (self , other : Self ) -> bool {
28- (self .nonce == other .nonce ) & (self .balance == other .balance ) & (self .storage_root == other .storage_root ) & (self .code_hash == other .code_hash )
32+ (self .nonce == other .nonce )
33+ & (self .balance == other .balance )
34+ & (self .storage_root == other .storage_root )
35+ & (self .code_hash == other .code_hash )
2936 }
3037}
3138
@@ -34,7 +41,7 @@ impl Eq for Account {
3441struct StateAndStorageProofInput {
3542 account : Account ,
3643 state_proof_input : ProofInput <MAX_PREFIXED_KEY_NIBBLE_LEN , MAX_ACCOUNT_STATE_LEN , MAX_ACCOUNT_DEPTH_NO_LEAF_M , MAX_ACCOUNT_LEAF_LEN >,
37- storage_proof_input : ProofInput <MAX_PREFIXED_KEY_NIBBLE_LEN , MAX_STORAGE_VALUE_LEN , MAX_STORAGE_DEPTH_NO_LEAF_M , MAX_STORAGE_LEAF_LEN >
44+ storage_proof_input : ProofInput <MAX_PREFIXED_KEY_NIBBLE_LEN , MAX_STORAGE_VALUE_LEN , MAX_STORAGE_DEPTH_NO_LEAF_M , MAX_STORAGE_LEAF_LEN >,
3845}
3946
4047struct StorageWithinBlock <let N : u32 > {
@@ -47,22 +54,26 @@ type ProofInputSerialized<let LEN: u32> = [Field; LEN];
4754
4855impl Eq for StorageWithinBlock <1 > {
4956 fn eq (self , other : Self ) -> bool {
50- (self .block_hash == other .block_hash ) & (self .account == other .account ) & (self .values [0 ] == other .values [0 ])
57+ (self .block_hash == other .block_hash )
58+ & (self .account == other .account )
59+ & (self .values [0 ] == other .values [0 ])
5160 }
5261}
5362
5463fn assert_storage_key_equals (
5564 storage_key : Bytes32 ,
56- storage_key_hash : [u8 ; MAX_PREFIXED_KEY_NIBBLE_LEN ]
65+ storage_key_hash : [u8 ; MAX_PREFIXED_KEY_NIBBLE_LEN ],
5766) {
5867 let storage_key_hash_fragment = Fragment ::new (
5968 MAX_PREFIXED_KEY_NIBBLE_LEN - HASH_LEN ,
6069 HASH_LEN ,
61- storage_key_hash
70+ storage_key_hash ,
6271 );
63- let other_storage_key_hash_fragment = Fragment ::from_array (keccak256 (storage_key , BYTES32_LENGTH as u32 ));
72+ let other_storage_key_hash_fragment =
73+ Fragment ::from_array (keccak256 (storage_key , BYTES32_LENGTH as u32 ));
6474 assert (
65- storage_key_hash_fragment .eq (other_storage_key_hash_fragment ), "Storage key does not match the argument"
75+ storage_key_hash_fragment .eq (other_storage_key_hash_fragment ),
76+ "Storage key does not match the argument" ,
6677 );
6778}
6879
@@ -72,7 +83,9 @@ fn get_fragment<let N: u32>(left_padded_value: [u8; N]) -> Fragment<N, u8> {
7283 Fragment ::new (value_offset , value_len , left_padded_value )
7384}
7485
75- fn get_storage_value (rlp_encoded_value : [u8 ; MAX_STORAGE_VALUE_LEN ]) -> [u8 ; MAX_STORAGE_VALUE_LEN ] {
86+ fn get_storage_value (
87+ rlp_encoded_value : [u8 ; MAX_STORAGE_VALUE_LEN ],
88+ ) -> [u8 ; MAX_STORAGE_VALUE_LEN ] {
7689 let mut storage_value = get_fragment (rlp_encoded_value );
7790 let rlp_fragment = decode_string (storage_value );
7891 let rlp_header_len = rlp_fragment .offset ;
@@ -89,36 +102,43 @@ fn get_storage_value(rlp_encoded_value: [u8; MAX_STORAGE_VALUE_LEN]) -> [u8; MAX
89102
90103pub fn get_account_with_storage (
91104 chain_id : Field ,
92- block_number : u32 ,
105+ block_number : u64 ,
93106 address : Address ,
94- storage_key : Bytes32
107+ storage_key : Bytes32 ,
95108) -> StorageWithinBlock <1 > {
96- let BlockHeaderPartial { number : _ , hash , state_root , transactions_root : _ , receipts_root : _ } = get_header (chain_id , block_number );
97- let StateAndStorageProofInput { account , state_proof_input , storage_proof_input } = get_proof_unconstrained (chain_id , block_number , address , storage_key );
109+ let BlockHeaderPartial { number : _ , hash , state_root , transactions_root : _ , receipts_root : _ } =
110+ get_header (chain_id , block_number );
111+ let StateAndStorageProofInput { account , state_proof_input , storage_proof_input } =
112+ get_proof_unconstrained (chain_id , block_number , address , storage_key );
98113
99114 verify_account (address , account , state_proof_input , state_root );
100115 verify_storage_values ([storage_proof_input ], account .storage_root );
101116
102117 assert_storage_key_equals (storage_key , storage_proof_input .key );
103118
104- StorageWithinBlock { block_hash : hash , account , values : [get_storage_value (storage_proof_input .value )] }
119+ StorageWithinBlock {
120+ block_hash : hash ,
121+ account ,
122+ values : [get_storage_value (storage_proof_input .value )],
123+ }
105124}
106125
107126#[oracle(get_proof)]
108127unconstrained fn get_proof_oracle <let STATE_PROOF_INPUT_LEN : u32 , let STORAGE_PROOF_INPUT : u32 >(
109128 _chain_id : Field ,
110- _block_no : u32 ,
129+ _block_no : u64 ,
111130 _address : Address ,
112- _storage_key : Bytes32
113- ) -> (Account , ProofInputSerialized <STATE_PROOF_INPUT_LEN >, ProofInputSerialized <STORAGE_PROOF_INPUT >) {}
131+ _storage_key : Bytes32 ,
132+ ) -> (Account , ProofInputSerialized <STATE_PROOF_INPUT_LEN >, ProofInputSerialized <STORAGE_PROOF_INPUT >) {}
114133
115134unconstrained fn get_proof_unconstrained (
116135 chain_id : Field ,
117- block_no : u32 ,
136+ block_no : u64 ,
118137 address : Address ,
119- storage_key : Bytes32
138+ storage_key : Bytes32 ,
120139) -> StateAndStorageProofInput {
121- let (account , state_proof_input , storage_proof_input ) = get_proof_oracle (chain_id , block_no , address , storage_key );
140+ let (account , state_proof_input , storage_proof_input ) =
141+ get_proof_oracle (chain_id , block_no , address , storage_key );
122142 let state_proof_input = Serde ::deserialize (state_proof_input );
123143 let storage_proof_input = Serde ::deserialize (storage_proof_input );
124144
0 commit comments