@@ -10,7 +10,7 @@ use crate::{
10
10
keccak256, Account , Address , AnalysisKind , Bytecode , Bytes , CreateScheme , EVMError , Env ,
11
11
Eof , HashSet , Spec ,
12
12
SpecId :: { self , * } ,
13
- B256 , U256 ,
13
+ B256 , EOF_MAGIC_BYTES , EOF_MAGIC_HASH , U256 ,
14
14
} ,
15
15
FrameOrResult , JournalCheckpoint , CALL_STACK_LIMIT ,
16
16
} ;
@@ -160,21 +160,37 @@ impl<DB: Database> InnerEvmContext<DB> {
160
160
. map ( |( acc, is_cold) | ( acc. info . balance , is_cold) )
161
161
}
162
162
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.
164
166
#[ 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 > > {
166
168
self . journaled_state
167
169
. 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
+ } )
169
179
}
170
180
171
181
/// Get code hash of address.
182
+ ///
183
+ /// In case of EOF account it will return `EOF_MAGIC_HASH`
184
+ /// (the hash of `0xEF00`).
172
185
#[ inline]
173
186
pub fn code_hash ( & mut self , address : Address ) -> Result < ( B256 , bool ) , EVMError < DB :: Error > > {
174
187
let ( acc, is_cold) = self . journaled_state . load_code ( address, & mut self . db ) ?;
175
188
if acc. is_empty ( ) {
176
189
return Ok ( ( B256 :: ZERO , is_cold) ) ;
177
190
}
191
+ if let Some ( true ) = acc. info . code . as_ref ( ) . map ( |code| code. is_eof ( ) ) {
192
+ return Ok ( ( EOF_MAGIC_HASH , is_cold) ) ;
193
+ }
178
194
Ok ( ( acc. info . code_hash , is_cold) )
179
195
}
180
196
0 commit comments