@@ -5,7 +5,7 @@ use alloc::boxed::Box;
55use alloy_primitives:: { Address , Log , B256 , U256 } ;
66use core:: { error:: Error , fmt, fmt:: Debug } ;
77use revm:: {
8- context:: { Block , DBErrorMarker , JournalTr } ,
8+ context:: { journaled_state :: TransferError , Block , DBErrorMarker , JournalTr } ,
99 interpreter:: { SStoreResult , StateLoad } ,
1010 primitives:: { StorageKey , StorageValue } ,
1111 state:: { Account , AccountInfo , Bytecode } ,
@@ -52,6 +52,24 @@ trait EvmInternalsTr: Database<Error = ErasedError> + Debug {
5252 address : Address ,
5353 ) -> Result < StateLoad < & Account > , EvmInternalsError > ;
5454
55+ /// Increments the balance of the account.
56+ fn balance_incr ( & mut self , address : Address , balance : U256 ) -> Result < ( ) , EvmInternalsError > ;
57+
58+ /// Transfers the balance from one account to another.
59+ ///
60+ /// This will load both accounts
61+ fn transfer (
62+ & mut self ,
63+ from : Address ,
64+ to : Address ,
65+ balance : U256 ,
66+ ) -> Result < Option < TransferError > , EvmInternalsError > ;
67+
68+ /// Increments the nonce of the account.
69+ ///
70+ /// This creates a new journal entry with this change.
71+ fn nonce_bump_journal_entry ( & mut self , address : Address ) ;
72+
5573 fn sload (
5674 & mut self ,
5775 address : Address ,
@@ -62,6 +80,9 @@ trait EvmInternalsTr: Database<Error = ErasedError> + Debug {
6280
6381 fn set_code ( & mut self , address : Address , code : Bytecode ) ;
6482
83+ /// Sets bytecode with hash. Assume that account is warm.
84+ fn set_code_with_hash ( & mut self , address : Address , code : Bytecode , hash : B256 ) ;
85+
6586 fn sstore (
6687 & mut self ,
6788 address : Address ,
@@ -118,6 +139,23 @@ where
118139 self . 0 . load_account_with_code ( address) . map_err ( EvmInternalsError :: database)
119140 }
120141
142+ fn balance_incr ( & mut self , address : Address , balance : U256 ) -> Result < ( ) , EvmInternalsError > {
143+ self . 0 . balance_incr ( address, balance) . map_err ( EvmInternalsError :: database)
144+ }
145+
146+ fn transfer (
147+ & mut self ,
148+ from : Address ,
149+ to : Address ,
150+ balance : U256 ,
151+ ) -> Result < Option < TransferError > , EvmInternalsError > {
152+ self . 0 . transfer ( from, to, balance) . map_err ( EvmInternalsError :: database)
153+ }
154+
155+ fn nonce_bump_journal_entry ( & mut self , address : Address ) {
156+ self . 0 . nonce_bump_journal_entry ( address) ;
157+ }
158+
121159 fn sload (
122160 & mut self ,
123161 address : Address ,
@@ -134,6 +172,10 @@ where
134172 self . 0 . set_code ( address, code) ;
135173 }
136174
175+ fn set_code_with_hash ( & mut self , address : Address , code : Bytecode , hash : B256 ) {
176+ self . 0 . set_code_with_hash ( address, code, hash) ;
177+ }
178+
137179 fn sstore (
138180 & mut self ,
139181 address : Address ,
@@ -202,6 +244,34 @@ impl<'a> EvmInternals<'a> {
202244 self . internals . load_account_code ( address)
203245 }
204246
247+ /// Increments the balance of the account.
248+ pub fn balance_incr (
249+ & mut self ,
250+ address : Address ,
251+ balance : U256 ,
252+ ) -> Result < ( ) , EvmInternalsError > {
253+ self . internals . balance_incr ( address, balance)
254+ }
255+
256+ /// Transfers the balance from one account to another.
257+ ///
258+ /// This will load both accounts and return an error if the transfer fails.
259+ pub fn transfer (
260+ & mut self ,
261+ from : Address ,
262+ to : Address ,
263+ balance : U256 ,
264+ ) -> Result < Option < TransferError > , EvmInternalsError > {
265+ self . internals . transfer ( from, to, balance)
266+ }
267+
268+ /// Increments the nonce of the account.
269+ ///
270+ /// This creates a new journal entry with this change.
271+ pub fn nonce_bump_journal_entry ( & mut self , address : Address ) {
272+ self . internals . nonce_bump_journal_entry ( address) ;
273+ }
274+
205275 /// Loads a storage slot.
206276 pub fn sload (
207277 & mut self ,
@@ -221,6 +291,13 @@ impl<'a> EvmInternals<'a> {
221291 self . internals . set_code ( address, code) ;
222292 }
223293
294+ /// Sets bytecode with hash to the account.
295+ ///
296+ /// Assumes that the account is warm.
297+ pub fn set_code_with_hash ( & mut self , address : Address , code : Bytecode , hash : B256 ) {
298+ self . internals . set_code_with_hash ( address, code, hash) ;
299+ }
300+
224301 /// Stores the storage value in Journal state.
225302 pub fn sstore (
226303 & mut self ,
0 commit comments