Skip to content

Commit c43084e

Browse files
feat(blockifier): expose more fields in OsConstants
1 parent 67ed994 commit c43084e

File tree

1 file changed

+105
-7
lines changed

1 file changed

+105
-7
lines changed

crates/blockifier/src/blockifier_versioned_constants.rs

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,10 @@ impl SyscallGasCost {
796796
assert!(self.linear_factor == 0, "The syscall has a linear factor cost to be considered.");
797797
self.base
798798
}
799+
800+
pub fn linear_syscall_cost(&self) -> u64 {
801+
self.linear_factor
802+
}
799803
}
800804

801805
#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
@@ -1073,29 +1077,123 @@ impl GasCosts {
10731077
#[derive(Debug, Default, PartialEq)]
10741078
pub struct OsConstants {
10751079
pub gas_costs: GasCosts,
1076-
pub validate_rounding_consts: ValidateRoundingConsts,
1077-
pub os_contract_addresses: OsContractAddresses,
1080+
1081+
// Selectors.
1082+
pub constructor_entry_point_selector: EntryPointSelector,
1083+
pub default_entry_point_selector: EntryPointSelector,
1084+
pub execute_entry_point_selector: EntryPointSelector,
1085+
pub transfer_entry_point_selector: EntryPointSelector,
1086+
pub validate_declare_entry_point_selector: EntryPointSelector,
1087+
pub validate_deploy_entry_point_selector: EntryPointSelector,
1088+
pub validate_entry_point_selector: EntryPointSelector,
1089+
1090+
// Execution limits.
10781091
pub validate_max_sierra_gas: GasAmount,
10791092
pub execute_max_sierra_gas: GasAmount,
1093+
1094+
// Validation.
1095+
pub validate_rounding_consts: ValidateRoundingConsts,
1096+
pub validated: String,
1097+
1098+
// Error strings.
1099+
pub error_block_number_out_of_range: String,
1100+
pub error_invalid_input_len: String,
1101+
pub error_invalid_argument: String,
1102+
pub error_out_of_gas: String,
1103+
pub error_entry_point_failed: String,
1104+
pub error_entry_point_not_found: String,
1105+
1106+
// Resource bounds names.
1107+
pub l1_gas: String,
1108+
pub l2_gas: String,
1109+
pub l1_data_gas: String,
1110+
1111+
// Resource bounds indices.
1112+
pub l1_gas_index: usize,
1113+
pub l1_data_gas_index: usize,
1114+
pub l2_gas_index: usize,
1115+
1116+
// Initial costs.
1117+
pub entry_point_initial_budget: u64,
1118+
pub default_initial_gas_cost: u64,
1119+
1120+
// L1 handler.
1121+
pub l1_handler_version: u8,
1122+
pub l1_handler_max_amount_bounds: GasVector,
1123+
1124+
// Miscellaneous.
1125+
pub nop_entry_point_offset: i8,
1126+
pub os_contract_addresses: OsContractAddresses,
1127+
pub sierra_array_len_bound: u64,
1128+
pub stored_block_hash_buffer: u8,
1129+
1130+
// Entry point type identifiers (in the OS).
1131+
pub entry_point_type_constructor: u8,
1132+
pub entry_point_type_external: u8,
1133+
pub entry_point_type_l1_handler: u8,
1134+
1135+
// Deprecated contract logic support.
10801136
pub v1_bound_accounts_cairo0: Vec<ClassHash>,
10811137
pub v1_bound_accounts_cairo1: Vec<ClassHash>,
10821138
pub v1_bound_accounts_max_tip: Tip,
1083-
pub l1_handler_max_amount_bounds: GasVector,
10841139
pub data_gas_accounts: Vec<ClassHash>,
10851140
}
10861141

10871142
impl OsConstants {
10881143
fn from_raw(raw_constants: &RawOsConstants, raw_resources: &RawOsResources) -> Self {
1144+
let gas_costs = GasCosts::from_raw(raw_constants, raw_resources);
1145+
1146+
// Preprocess inital budget costs.
1147+
let RawStepGasCost { step_gas_cost: entry_point_initial_budget_steps } =
1148+
raw_constants.entry_point_initial_budget;
1149+
let RawStepGasCost { step_gas_cost: default_initial_gas_cost_steps } =
1150+
raw_constants.default_initial_gas_cost;
1151+
let entry_point_initial_budget =
1152+
gas_costs.base.step_gas_cost * entry_point_initial_budget_steps.0;
1153+
let default_initial_gas_cost =
1154+
gas_costs.base.step_gas_cost * default_initial_gas_cost_steps.0;
1155+
10891156
Self {
1090-
gas_costs: GasCosts::from_raw(raw_constants, raw_resources),
1091-
validate_rounding_consts: raw_constants.validate_rounding_consts,
1092-
os_contract_addresses: raw_constants.os_contract_addresses,
1157+
gas_costs,
1158+
constructor_entry_point_selector: raw_constants.constructor_entry_point_selector,
1159+
default_entry_point_selector: raw_constants.default_entry_point_selector,
1160+
execute_entry_point_selector: raw_constants.execute_entry_point_selector,
1161+
transfer_entry_point_selector: raw_constants.transfer_entry_point_selector,
1162+
validate_declare_entry_point_selector: raw_constants
1163+
.validate_declare_entry_point_selector,
1164+
validate_deploy_entry_point_selector: raw_constants
1165+
.validate_deploy_entry_point_selector,
1166+
validate_entry_point_selector: raw_constants.validate_entry_point_selector,
10931167
validate_max_sierra_gas: raw_constants.validate_max_sierra_gas,
10941168
execute_max_sierra_gas: raw_constants.execute_max_sierra_gas,
1169+
validate_rounding_consts: raw_constants.validate_rounding_consts,
1170+
validated: raw_constants.validated.clone(),
1171+
error_block_number_out_of_range: raw_constants.error_block_number_out_of_range.clone(),
1172+
error_invalid_input_len: raw_constants.error_invalid_input_len.clone(),
1173+
error_invalid_argument: raw_constants.error_invalid_argument.clone(),
1174+
error_out_of_gas: raw_constants.error_out_of_gas.clone(),
1175+
error_entry_point_failed: raw_constants.error_entry_point_failed.clone(),
1176+
error_entry_point_not_found: raw_constants.error_entry_point_not_found.clone(),
1177+
l1_gas: raw_constants.l1_gas.clone(),
1178+
l2_gas: raw_constants.l2_gas.clone(),
1179+
l1_data_gas: raw_constants.l1_data_gas.clone(),
1180+
l1_gas_index: raw_constants.l1_gas_index,
1181+
l1_data_gas_index: raw_constants.l1_data_gas_index,
1182+
l2_gas_index: raw_constants.l2_gas_index,
1183+
entry_point_initial_budget,
1184+
default_initial_gas_cost,
1185+
l1_handler_version: raw_constants.l1_handler_version,
1186+
l1_handler_max_amount_bounds: raw_constants.l1_handler_max_amount_bounds,
1187+
nop_entry_point_offset: raw_constants.nop_entry_point_offset,
1188+
os_contract_addresses: raw_constants.os_contract_addresses,
1189+
sierra_array_len_bound: raw_constants.sierra_array_len_bound,
1190+
stored_block_hash_buffer: raw_constants.stored_block_hash_buffer,
1191+
entry_point_type_constructor: raw_constants.entry_point_type_constructor,
1192+
entry_point_type_external: raw_constants.entry_point_type_external,
1193+
entry_point_type_l1_handler: raw_constants.entry_point_type_l1_handler,
10951194
v1_bound_accounts_cairo0: raw_constants.v1_bound_accounts_cairo0.clone(),
10961195
v1_bound_accounts_cairo1: raw_constants.v1_bound_accounts_cairo1.clone(),
10971196
v1_bound_accounts_max_tip: raw_constants.v1_bound_accounts_max_tip,
1098-
l1_handler_max_amount_bounds: raw_constants.l1_handler_max_amount_bounds,
10991197
data_gas_accounts: raw_constants.data_gas_accounts.clone(),
11001198
}
11011199
}

0 commit comments

Comments
 (0)