@@ -10,7 +10,7 @@ use crate::{
1010 keccak256, Account , Address , AnalysisKind , Bytecode , Bytes , CreateScheme , EVMError , Env ,
1111 Eof , HashSet , Spec ,
1212 SpecId :: { self , * } ,
13- B256 , U256 ,
13+ B256 , EOF_MAGIC_BYTES , EOF_MAGIC_HASH , U256 ,
1414 } ,
1515 FrameOrResult , JournalCheckpoint , CALL_STACK_LIMIT ,
1616} ;
@@ -160,21 +160,37 @@ impl<DB: Database> InnerEvmContext<DB> {
160160 . map ( |( acc, is_cold) | ( acc. info . balance , is_cold) )
161161 }
162162
163- /// Return account code and if address is cold loaded.
163+ /// Return account code bytes and if address is cold loaded.
164+ ///
165+ /// In case of EOF account it will return `EOF_MAGIC` (0xEF00) as code.
164166 #[ inline]
165- pub fn code ( & mut self , address : Address ) -> Result < ( Bytecode , bool ) , EVMError < DB :: Error > > {
167+ pub fn code ( & mut self , address : Address ) -> Result < ( Bytes , bool ) , EVMError < DB :: Error > > {
166168 self . journaled_state
167169 . load_code ( address, & mut self . db )
168- . map ( |( a, is_cold) | ( a. info . code . clone ( ) . unwrap ( ) , is_cold) )
170+ . map ( |( a, is_cold) | {
171+ // SAFETY: safe to unwrap as load_code will insert code if it is empty.
172+ let code = a. info . code . as_ref ( ) . unwrap ( ) ;
173+ if code. is_eof ( ) {
174+ ( EOF_MAGIC_BYTES . clone ( ) , is_cold)
175+ } else {
176+ ( code. original_bytes ( ) . clone ( ) , is_cold)
177+ }
178+ } )
169179 }
170180
171181 /// Get code hash of address.
182+ ///
183+ /// In case of EOF account it will return `EOF_MAGIC_HASH`
184+ /// (the hash of `0xEF00`).
172185 #[ inline]
173186 pub fn code_hash ( & mut self , address : Address ) -> Result < ( B256 , bool ) , EVMError < DB :: Error > > {
174187 let ( acc, is_cold) = self . journaled_state . load_code ( address, & mut self . db ) ?;
175188 if acc. is_empty ( ) {
176189 return Ok ( ( B256 :: ZERO , is_cold) ) ;
177190 }
191+ if let Some ( true ) = acc. info . code . as_ref ( ) . map ( |code| code. is_eof ( ) ) {
192+ return Ok ( ( EOF_MAGIC_HASH , is_cold) ) ;
193+ }
178194 Ok ( ( acc. info . code_hash , is_cold) )
179195 }
180196
0 commit comments