@@ -640,8 +640,14 @@ impl ExecutionEntryPoint {
640
640
tx_execution_context : & TransactionExecutionContext ,
641
641
block_context : & BlockContext ,
642
642
) -> Result < CallInfo , TransactionError > {
643
+ use cairo_lang_sierra:: {
644
+ extensions:: core:: { CoreLibfunc , CoreType , CoreTypeConcrete } ,
645
+ program_registry:: ProgramRegistry ,
646
+ } ;
643
647
use serde_json:: json;
644
648
649
+ use crate :: syscalls:: business_logic_syscall_handler:: SYSCALL_BASE ;
650
+
645
651
let entry_point = match self . entry_point_type {
646
652
EntryPointType :: External => contract_class
647
653
. entry_points_by_type
@@ -664,6 +670,8 @@ impl ExecutionEntryPoint {
664
670
} ;
665
671
666
672
let sierra_program = contract_class. extract_sierra_program ( ) . unwrap ( ) ;
673
+ let program_registry: ProgramRegistry < CoreType , CoreLibfunc > =
674
+ ProgramRegistry :: new ( & sierra_program) . unwrap ( ) ;
667
675
668
676
let native_context = NativeContext :: new ( ) ;
669
677
let mut native_program = native_context. compile ( & sierra_program) . unwrap ( ) ;
@@ -672,16 +680,15 @@ impl ExecutionEntryPoint {
672
680
673
681
let syscall_handler = NativeSyscallHandler {
674
682
starknet_storage_state : contract_storage_state,
675
- n_emitted_events : 0 ,
676
683
events : Vec :: new ( ) ,
677
684
l2_to_l1_messages : Vec :: new ( ) ,
678
- n_sent_messages : 0 ,
679
685
contract_address : self . contract_address . clone ( ) ,
680
686
internal_calls : Vec :: new ( ) ,
681
687
caller_address : self . caller_address . clone ( ) ,
682
688
entry_point_selector : self . entry_point_selector . clone ( ) ,
683
689
tx_execution_context : tx_execution_context. clone ( ) ,
684
690
block_context : block_context. clone ( ) ,
691
+ resources_manager : Default :: default ( ) ,
685
692
} ;
686
693
687
694
native_program
@@ -694,14 +701,20 @@ impl ExecutionEntryPoint {
694
701
. as_ptr ( )
695
702
. as_ptr ( ) as * const ( ) as usize ;
696
703
697
- let fn_id = & sierra_program
704
+ let entry_point_fn = & sierra_program
698
705
. funcs
699
706
. iter ( )
700
707
. find ( |x| x. id . id == ( entry_point. function_idx as u64 ) )
701
- . unwrap ( )
702
- . id ;
708
+ . unwrap ( ) ;
709
+ let ret_types: Vec < & CoreTypeConcrete > = entry_point_fn
710
+ . signature
711
+ . ret_types
712
+ . iter ( )
713
+ . map ( |x| program_registry. get_type ( x) . unwrap ( ) )
714
+ . collect ( ) ;
715
+ let entry_point_id = & entry_point_fn. id ;
703
716
704
- let required_init_gas = native_program. get_required_init_gas ( fn_id ) ;
717
+ let required_init_gas = native_program. get_required_init_gas ( entry_point_id ) ;
705
718
706
719
let calldata: Vec < _ > = self
707
720
. calldata
@@ -719,13 +732,13 @@ impl ExecutionEntryPoint {
719
732
*/
720
733
721
734
let wrapped_calldata = vec ! [ calldata] ;
722
- let params: Vec < Value > = sierra_program. funcs [ fn_id . id as usize ]
735
+ let params: Vec < Value > = sierra_program. funcs [ entry_point_id . id as usize ]
723
736
. params
724
737
. iter ( )
725
738
. map ( |param| {
726
739
match param. ty . debug_name . as_ref ( ) . unwrap ( ) . as_str ( ) {
727
740
"GasBuiltin" => {
728
- json ! ( self . initial_gas as u64 )
741
+ json ! ( self . initial_gas)
729
742
}
730
743
"Pedersen" | "SegmentArena" | "RangeCheck" | "Bitwise" | "Poseidon" => {
731
744
json ! ( null)
@@ -748,11 +761,14 @@ impl ExecutionEntryPoint {
748
761
let native_executor = NativeExecutor :: new ( native_program) ;
749
762
750
763
native_executor
751
- . execute ( fn_id , json ! ( params) , returns, required_init_gas)
764
+ . execute ( entry_point_id , json ! ( params) , returns, required_init_gas)
752
765
. map_err ( |e| TransactionError :: CustomError ( format ! ( "cairo-native error: {:?}" , e) ) ) ?;
753
766
754
- let result: String = String :: from_utf8 ( writer) . unwrap ( ) ;
755
- let value = serde_json:: from_str :: < NativeExecutionResult > ( & result) . unwrap ( ) ;
767
+ let value = NativeExecutionResult :: deserialize_from_ret_types (
768
+ & mut serde_json:: Deserializer :: from_slice ( & writer) ,
769
+ & ret_types,
770
+ )
771
+ . expect ( "failed to serialize starknet execution result" ) ;
756
772
757
773
Ok ( CallInfo {
758
774
caller_address : self . caller_address . clone ( ) ,
@@ -773,8 +789,10 @@ impl ExecutionEntryPoint {
773
789
failure_flag : value. failure_flag ,
774
790
l2_to_l1_messages : syscall_handler. l2_to_l1_messages ,
775
791
internal_calls : syscall_handler. internal_calls ,
776
- // TODO: check it's correct
777
- gas_consumed : self . initial_gas - u128:: from ( value. gas_builtin . unwrap_or ( 0 ) ) ,
792
+ gas_consumed : self
793
+ . initial_gas
794
+ . saturating_sub ( SYSCALL_BASE )
795
+ . saturating_sub ( value. remaining_gas ) ,
778
796
} )
779
797
}
780
798
}
0 commit comments