Skip to content

Commit

Permalink
feat(blockifier): add impl for GasCosts in versioned_constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonatan-Starkware committed Nov 14, 2024
1 parent d88b77c commit 1d93eab
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions crates/blockifier/src/versioned_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,53 @@ pub struct GasCosts {
pub sha256_process_block_gas_cost: u64,
}

impl GasCosts {
pub fn get_builtin_gas_cost(&self, builtin: &BuiltinName) -> u64 {
match *builtin {
BuiltinName::output => 0,
BuiltinName::range_check => self.range_check_gas_cost,
BuiltinName::pedersen => self.pedersen_gas_cost,
BuiltinName::ecdsa => 0,
BuiltinName::keccak => 0,
BuiltinName::bitwise => self.bitwise_builtin_gas_cost,
BuiltinName::ec_op => self.ecop_gas_cost,
BuiltinName::poseidon => self.poseidon_gas_cost,
BuiltinName::segment_arena => 0,
BuiltinName::range_check96 => self.range_check_gas_cost,
BuiltinName::add_mod => self.add_mod_gas_cost,
BuiltinName::mul_mod => self.mul_mod_gas_cost,
}
}

pub fn get_syscall_gas_cost_in_os_constants(&self, selector: &SyscallSelector) -> u64 {
match selector {
SyscallSelector::CallContract => self.call_contract_gas_cost,
SyscallSelector::Deploy => self.deploy_gas_cost,
SyscallSelector::EmitEvent => self.emit_event_gas_cost,
SyscallSelector::GetBlockHash => self.get_block_hash_gas_cost,
SyscallSelector::GetExecutionInfo => self.get_execution_info_gas_cost,
SyscallSelector::Keccak => self.keccak_gas_cost,
SyscallSelector::Sha256ProcessBlock => self.sha256_process_block_gas_cost,
SyscallSelector::LibraryCall => self.library_call_gas_cost,
SyscallSelector::ReplaceClass => self.replace_class_gas_cost,
SyscallSelector::Secp256k1Add => self.secp256k1_add_gas_cost,
SyscallSelector::Secp256k1GetPointFromX => self.secp256k1_get_point_from_x_gas_cost,
SyscallSelector::Secp256k1GetXy => self.secp256k1_get_xy_gas_cost,
SyscallSelector::Secp256k1Mul => self.secp256k1_mul_gas_cost,
SyscallSelector::Secp256k1New => self.secp256k1_new_gas_cost,
SyscallSelector::Secp256r1Add => self.secp256r1_add_gas_cost,
SyscallSelector::Secp256r1GetPointFromX => self.secp256r1_get_point_from_x_gas_cost,
SyscallSelector::Secp256r1GetXy => self.secp256r1_get_xy_gas_cost,
SyscallSelector::Secp256r1Mul => self.secp256r1_mul_gas_cost,
SyscallSelector::Secp256r1New => self.secp256r1_new_gas_cost,
SyscallSelector::SendMessageToL1 => self.send_message_to_l1_gas_cost,
SyscallSelector::StorageRead => self.storage_read_gas_cost,
SyscallSelector::StorageWrite => self.storage_write_gas_cost,
_ => 0,
}
}
}

// Below, serde first deserializes the json into a regular IndexMap wrapped by the newtype
// `OsConstantsRawJson`, then calls the `try_from` of the newtype, which handles the
// conversion into actual values.
Expand Down

0 comments on commit 1d93eab

Please sign in to comment.