@@ -7,7 +7,7 @@ use crate::{
7
7
memory:: { self , calculate_memory_size} ,
8
8
precompiles:: is_precompile,
9
9
utils:: { address_to_word, word_to_address, * } ,
10
- vm:: { RetData , StateBackup , VM } ,
10
+ vm:: { StateBackup , VM } ,
11
11
} ;
12
12
use bytes:: Bytes ;
13
13
use ethrex_common:: {
@@ -715,24 +715,16 @@ impl<'a> VM<'a> {
715
715
Bytes :: new ( ) ,
716
716
false ,
717
717
max_message_call_gas,
718
- 0 ,
719
718
new_depth,
720
719
true ,
720
+ true ,
721
+ U256 :: zero ( ) ,
722
+ 0 ,
721
723
) ;
722
724
self . call_frames . push ( new_call_frame) ;
723
725
724
726
self . accrued_substate . created_accounts . insert ( new_address) ; // Mostly for SELFDESTRUCT during initcode.
725
727
726
- self . return_data . push ( RetData {
727
- is_create : true ,
728
- ret_offset : U256 :: zero ( ) ,
729
- ret_size : 0 ,
730
- should_transfer_value : true ,
731
- to : new_address,
732
- msg_sender : deployer_address,
733
- value : value_in_wei_to_send,
734
- max_message_call_gas,
735
- } ) ;
736
728
// Backup of Database, Substate, Gas Refunds and Transient Storage if sub-context is reverted
737
729
let backup = StateBackup :: new (
738
730
self . accrued_substate . clone ( ) ,
@@ -823,16 +815,6 @@ impl<'a> VM<'a> {
823
815
self . increase_account_balance ( to, value) ?;
824
816
}
825
817
826
- self . return_data . push ( RetData {
827
- is_create : false ,
828
- ret_offset,
829
- ret_size,
830
- should_transfer_value,
831
- to,
832
- msg_sender,
833
- value,
834
- max_message_call_gas : gas_limit,
835
- } ) ;
836
818
let new_call_frame = CallFrame :: new (
837
819
msg_sender,
838
820
to,
@@ -842,9 +824,11 @@ impl<'a> VM<'a> {
842
824
calldata. into ( ) ,
843
825
is_static,
844
826
gas_limit,
845
- 0 ,
846
827
new_depth,
828
+ should_transfer_value,
847
829
false ,
830
+ ret_offset,
831
+ ret_size,
848
832
) ;
849
833
self . call_frames . push ( new_call_frame) ;
850
834
// Backup of Database, Substate, Gas Refunds and Transient Storage if sub-context is reverted
@@ -870,22 +854,17 @@ impl<'a> VM<'a> {
870
854
self . call_frames . push ( executed_call_frame. clone ( ) ) ;
871
855
return Ok ( false ) ;
872
856
}
873
- let retdata = self
874
- . return_data
875
- . pop ( )
876
- . ok_or ( VMError :: Internal ( InternalError :: CouldNotPopCallframe ) ) ?;
877
- if retdata. is_create {
878
- self . handle_return_create ( executed_call_frame, tx_report, retdata) ?;
857
+ if executed_call_frame. create_op_called {
858
+ self . handle_return_create ( executed_call_frame, tx_report) ?;
879
859
} else {
880
- self . handle_return_call ( executed_call_frame, tx_report, retdata ) ?;
860
+ self . handle_return_call ( executed_call_frame, tx_report) ?;
881
861
}
882
862
Ok ( true )
883
863
}
884
864
pub fn handle_return_call (
885
865
& mut self ,
886
866
executed_call_frame : & CallFrame ,
887
867
tx_report : & ExecutionReport ,
888
- retdata : RetData ,
889
868
) -> Result < ( ) , VMError > {
890
869
// Return gas left from subcontext
891
870
let gas_left_from_new_call_frame = executed_call_frame
@@ -902,8 +881,8 @@ impl<'a> VM<'a> {
902
881
parent_call_frame. logs . extend ( tx_report. logs . clone ( ) ) ;
903
882
memory:: try_store_range (
904
883
& mut parent_call_frame. memory ,
905
- retdata . ret_offset ,
906
- retdata . ret_size ,
884
+ executed_call_frame . ret_offset ,
885
+ executed_call_frame . ret_size ,
907
886
& tx_report. output ,
908
887
) ?;
909
888
parent_call_frame. sub_return_data = tx_report. output . clone ( ) ;
@@ -919,10 +898,16 @@ impl<'a> VM<'a> {
919
898
}
920
899
TxResult :: Revert ( _) => {
921
900
// Revert value transfer
922
- if retdata. should_transfer_value {
923
- self . decrease_account_balance ( retdata. to , retdata. value ) ?;
924
-
925
- self . increase_account_balance ( retdata. msg_sender , retdata. value ) ?;
901
+ if executed_call_frame. should_transfer_value {
902
+ self . decrease_account_balance (
903
+ executed_call_frame. to ,
904
+ executed_call_frame. msg_value ,
905
+ ) ?;
906
+
907
+ self . increase_account_balance (
908
+ executed_call_frame. msg_sender ,
909
+ executed_call_frame. msg_value ,
910
+ ) ?;
926
911
}
927
912
// Push 0 to stack
928
913
self . current_call_frame_mut ( ) ?. stack . push ( REVERT_FOR_CALL ) ?;
@@ -934,10 +919,9 @@ impl<'a> VM<'a> {
934
919
& mut self ,
935
920
executed_call_frame : & CallFrame ,
936
921
tx_report : & ExecutionReport ,
937
- retdata : RetData ,
938
922
) -> Result < ( ) , VMError > {
939
- let unused_gas = retdata
940
- . max_message_call_gas
923
+ let unused_gas = executed_call_frame
924
+ . gas_limit
941
925
. checked_sub ( tx_report. gas_used )
942
926
. ok_or ( InternalError :: GasOverflow ) ?;
943
927
@@ -956,16 +940,21 @@ impl<'a> VM<'a> {
956
940
TxResult :: Success => {
957
941
self . current_call_frame_mut ( ) ?
958
942
. stack
959
- . push ( address_to_word ( retdata . to ) ) ?;
943
+ . push ( address_to_word ( executed_call_frame . to ) ) ?;
960
944
self . merge_call_frame_backup_with_parent ( & executed_call_frame. call_frame_backup ) ?;
961
945
}
962
946
TxResult :: Revert ( err) => {
963
947
// Return value to sender
964
- self . increase_account_balance ( retdata. msg_sender , retdata. value ) ?;
948
+ self . increase_account_balance (
949
+ executed_call_frame. msg_sender ,
950
+ executed_call_frame. msg_value ,
951
+ ) ?;
965
952
966
953
// Deployment failed so account shouldn't exist
967
- cache:: remove_account ( & mut self . db . cache , & retdata. to ) ;
968
- self . accrued_substate . created_accounts . remove ( & retdata. to ) ;
954
+ cache:: remove_account ( & mut self . db . cache , & executed_call_frame. to ) ;
955
+ self . accrued_substate
956
+ . created_accounts
957
+ . remove ( & executed_call_frame. to ) ;
969
958
970
959
let current_call_frame = self . current_call_frame_mut ( ) ?;
971
960
// If revert we have to copy the return_data
0 commit comments