@@ -24,6 +24,7 @@ use starknet_api::versioned_constants_logic::VersionedConstantsTrait;
2424use strum:: IntoEnumIterator ;
2525use thiserror:: Error ;
2626
27+ use crate :: execution:: call_info:: { CairoPrimitiveName , OpcodeName } ;
2728use crate :: execution:: common_hints:: ExecutionMode ;
2829use crate :: execution:: execution_utils:: poseidon_hash_many_cost;
2930use crate :: execution:: syscalls:: vm_syscall_utils:: { SyscallSelector , SyscallUsageMap } ;
@@ -926,6 +927,7 @@ pub struct BaseGasCosts {
926927}
927928
928929#[ derive( Clone , Copy , Debug , Default , Deserialize , PartialEq , Serialize ) ]
930+ // TODO(AvivG): Consider renaming to CairoPrimitiveGasCosts to match with its usage in the bouncer.
929931pub struct BuiltinGasCosts {
930932 // Range check has a hard-coded cost higher than its proof percentage to avoid the overhead of
931933 // retrieving its price from the table.
@@ -965,6 +967,23 @@ impl BuiltinGasCosts {
965967
966968 Ok ( gas_cost)
967969 }
970+
971+ pub fn get_opcode_gas_cost ( & self , opcode : & OpcodeName ) -> u64 {
972+ match opcode {
973+ OpcodeName :: Blake => self . blake ,
974+ }
975+ }
976+
977+ /// Returns the gas cost for any Cairo primitive (builtin or opcode).
978+ pub fn get_cairo_primitive_gas_cost (
979+ & self ,
980+ primitive : & CairoPrimitiveName ,
981+ ) -> Result < u64 , GasCostsError > {
982+ match primitive {
983+ CairoPrimitiveName :: Builtin ( builtin) => self . get_builtin_gas_cost ( builtin) ,
984+ CairoPrimitiveName :: Opcode ( opcode) => Ok ( self . get_opcode_gas_cost ( opcode) ) ,
985+ }
986+ }
968987}
969988
970989/// Gas cost constants. For more documentation see in core/os/constants.cairo.
0 commit comments