Skip to content

Commit

Permalink
fix(blockifier): move max sierra_gas constants under os_constants (#2908
Browse files Browse the repository at this point in the history
)
  • Loading branch information
TzahiTaub authored Dec 25, 2024
1 parent f1e1e56 commit d30e22a
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 44 deletions.
6 changes: 3 additions & 3 deletions crates/blockifier/resources/versioned_constants_0_13_0.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"max_contract_bytecode_size": 61440
},
"invoke_tx_max_n_steps": 3000000,
"execute_max_sierra_gas": 10000000000,
"max_recursion_depth": 50,
"segment_arena_cells": true,
"disable_cairo0_redeclaration": false,
Expand Down Expand Up @@ -71,6 +70,8 @@
"validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895",
"transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e",
"default_entry_point_selector": 0,
"validate_max_sierra_gas": 10000000000,
"execute_max_sierra_gas": 10000000000,
"stored_block_hash_buffer": 10,
"step_gas_cost": 100,
"builtin_gas_costs": {
Expand Down Expand Up @@ -563,7 +564,6 @@
}
},
"validate_max_n_steps": 1000000,
"validate_max_sierra_gas": 10000000000,
"min_sierra_version_for_sierra_gas": "100.0.0",
"vm_resource_fee_cost": {
"builtins": {
Expand Down Expand Up @@ -617,4 +617,4 @@
1000
]
}
}
}
6 changes: 3 additions & 3 deletions crates/blockifier/resources/versioned_constants_0_13_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"max_contract_bytecode_size": 81920
},
"invoke_tx_max_n_steps": 4000000,
"execute_max_sierra_gas": 10000000000,
"deprecated_l2_resource_gas_costs": {
"gas_per_data_felt": [
128,
Expand Down Expand Up @@ -71,6 +70,8 @@
"validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895",
"transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e",
"default_entry_point_selector": 0,
"validate_max_sierra_gas": 10000000000,
"execute_max_sierra_gas": 10000000000,
"stored_block_hash_buffer": 10,
"step_gas_cost": 100,
"builtin_gas_costs": {
Expand Down Expand Up @@ -599,7 +600,6 @@
}
},
"validate_max_n_steps": 1000000,
"validate_max_sierra_gas": 10000000000,
"min_sierra_version_for_sierra_gas": "100.0.0",
"vm_resource_fee_cost": {
"builtins": {
Expand Down Expand Up @@ -653,4 +653,4 @@
10000
]
}
}
}
6 changes: 3 additions & 3 deletions crates/blockifier/resources/versioned_constants_0_13_1_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"max_contract_bytecode_size": 81920
},
"invoke_tx_max_n_steps": 4000000,
"execute_max_sierra_gas": 10000000000,
"deprecated_l2_resource_gas_costs": {
"gas_per_data_felt": [
128,
Expand Down Expand Up @@ -71,6 +70,8 @@
"validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895",
"transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e",
"default_entry_point_selector": 0,
"validate_max_sierra_gas": 10000000000,
"execute_max_sierra_gas": 10000000000,
"stored_block_hash_buffer": 10,
"step_gas_cost": 100,
"builtin_gas_costs": {
Expand Down Expand Up @@ -599,7 +600,6 @@
}
},
"validate_max_n_steps": 1000000,
"validate_max_sierra_gas": 10000000000,
"min_sierra_version_for_sierra_gas": "100.0.0",
"vm_resource_fee_cost": {
"builtins": {
Expand Down Expand Up @@ -653,4 +653,4 @@
10000
]
}
}
}
6 changes: 3 additions & 3 deletions crates/blockifier/resources/versioned_constants_0_13_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"max_contract_bytecode_size": 81920
},
"invoke_tx_max_n_steps": 10000000,
"execute_max_sierra_gas": 10000000000,
"deprecated_l2_resource_gas_costs": {
"gas_per_data_felt": [
128,
Expand Down Expand Up @@ -73,6 +72,7 @@
"error_entry_point_failed": "ENTRYPOINT_FAILED",
"error_entry_point_not_found": "ENTRYPOINT_NOT_FOUND",
"execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad",
"execute_max_sierra_gas": 10000000000,
"fee_transfer_gas_cost": {
"entry_point_initial_budget": 1,
"step_gas_cost": 600
Expand Down Expand Up @@ -113,6 +113,7 @@
"validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3",
"validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895",
"validate_entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775",
"validate_max_sierra_gas": 10000000000,
"validate_rounding_consts": {
"validate_block_number_rounding": 100,
"validate_timestamp_rounding": 3600
Expand Down Expand Up @@ -605,7 +606,6 @@
}
},
"validate_max_n_steps": 1000000,
"validate_max_sierra_gas": 10000000000,
"min_sierra_version_for_sierra_gas": "100.0.0",
"vm_resource_fee_cost": {
"builtins": {
Expand Down Expand Up @@ -659,4 +659,4 @@
10000
]
}
}
}
6 changes: 3 additions & 3 deletions crates/blockifier/resources/versioned_constants_0_13_2_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"max_contract_bytecode_size": 81920
},
"invoke_tx_max_n_steps": 10000000,
"execute_max_sierra_gas": 10000000000,
"deprecated_l2_resource_gas_costs": {
"gas_per_data_felt": [
128,
Expand Down Expand Up @@ -73,6 +72,7 @@
"error_entry_point_failed": "ENTRYPOINT_FAILED",
"error_entry_point_not_found": "ENTRYPOINT_NOT_FOUND",
"execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad",
"execute_max_sierra_gas": 10000000000,
"fee_transfer_gas_cost": {
"entry_point_initial_budget": 1,
"step_gas_cost": 600
Expand Down Expand Up @@ -113,6 +113,7 @@
"validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3",
"validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895",
"validate_entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775",
"validate_max_sierra_gas": 10000000000,
"validate_rounding_consts": {
"validate_block_number_rounding": 100,
"validate_timestamp_rounding": 3600
Expand Down Expand Up @@ -605,7 +606,6 @@
}
},
"validate_max_n_steps": 1000000,
"validate_max_sierra_gas": 10000000000,
"min_sierra_version_for_sierra_gas": "100.0.0",
"vm_resource_fee_cost": {
"builtins": {
Expand Down Expand Up @@ -659,4 +659,4 @@
10000
]
}
}
}
6 changes: 3 additions & 3 deletions crates/blockifier/resources/versioned_constants_0_13_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"max_contract_bytecode_size": 81920
},
"invoke_tx_max_n_steps": 10000000,
"execute_max_sierra_gas": 10000000000,
"deprecated_l2_resource_gas_costs": {
"gas_per_data_felt": [
128,
Expand Down Expand Up @@ -73,6 +72,7 @@
"error_entry_point_failed": "ENTRYPOINT_FAILED",
"error_entry_point_not_found": "ENTRYPOINT_NOT_FOUND",
"execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad",
"execute_max_sierra_gas": 10000000000,
"fee_transfer_gas_cost": {
"entry_point_initial_budget": 1,
"step_gas_cost": 600
Expand Down Expand Up @@ -113,6 +113,7 @@
"validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3",
"validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895",
"validate_entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775",
"validate_max_sierra_gas": 10000000000,
"validate_rounding_consts": {
"validate_block_number_rounding": 100,
"validate_timestamp_rounding": 3600
Expand Down Expand Up @@ -605,7 +606,6 @@
}
},
"validate_max_n_steps": 1000000,
"validate_max_sierra_gas": 10000000000,
"min_sierra_version_for_sierra_gas": "100.0.0",
"vm_resource_fee_cost": {
"builtins": {
Expand Down Expand Up @@ -659,4 +659,4 @@
10000
]
}
}
}
6 changes: 3 additions & 3 deletions crates/blockifier/resources/versioned_constants_0_13_4.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"max_contract_bytecode_size": 81920
},
"invoke_tx_max_n_steps": 10000000,
"execute_max_sierra_gas": 1000000000,
"deprecated_l2_resource_gas_costs": {
"gas_per_data_felt": [
128,
Expand Down Expand Up @@ -73,6 +72,7 @@
"error_entry_point_failed": "ENTRYPOINT_FAILED",
"error_entry_point_not_found": "ENTRYPOINT_NOT_FOUND",
"execute_entry_point_selector": "0x15d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad",
"execute_max_sierra_gas": 1000000000,
"default_initial_gas_cost": {
"step_gas_cost": 100000000
},
Expand Down Expand Up @@ -111,6 +111,7 @@
"validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3",
"validate_deploy_entry_point_selector": "0x36fcbf06cd96843058359e1a75928beacfac10727dab22a3972f0af8aa92895",
"validate_entry_point_selector": "0x162da33a4585851fe8d3af3c2a9c60b557814e221e0d4f30ff0b2189d9c7775",
"validate_max_sierra_gas": 100000000,
"validate_rounding_consts": {
"validate_block_number_rounding": 100,
"validate_timestamp_rounding": 3600
Expand Down Expand Up @@ -607,7 +608,6 @@
}
},
"validate_max_n_steps": 1000000,
"validate_max_sierra_gas": 100000000,
"min_sierra_version_for_sierra_gas": "1.6.0",
"vm_resource_fee_cost": {
"builtins": {
Expand Down Expand Up @@ -661,4 +661,4 @@
10000
]
}
}
}
7 changes: 4 additions & 3 deletions crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,9 @@ impl AccountTransaction {
if self.execution_flags.validate {
let limit_steps_by_resources = self.execution_flags.charge_fee;
// TODO(Aner): cap the gas for validation.
let remaining_validation_gas = &mut remaining_gas
.limit_usage(tx_context.block_context.versioned_constants.validate_max_sierra_gas);
let remaining_validation_gas = &mut remaining_gas.limit_usage(
tx_context.block_context.versioned_constants.os_constants.validate_max_sierra_gas,
);
Ok(self
.validate_tx(state, tx_context, remaining_validation_gas, limit_steps_by_resources)?
.inspect(|call_info| {
Expand Down Expand Up @@ -539,7 +540,7 @@ impl AccountTransaction {
let execute_call_info: Option<CallInfo>;
if matches!(&self.tx, Transaction::DeployAccount(_)) {
// Handle `DeployAccount` transactions separately, due to different order of things.
// Also, the execution context required form the `DeployAccount` execute phase is
// Also, the execution context required for the `DeployAccount` execute phase is
// validation context.
let mut execution_context = EntryPointExecutionContext::new_validate(
tx_context.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,10 @@ fn test_initial_gas(

let validate_call_info = &transaction_ex_info.validate_call_info.unwrap();
let validate_initial_gas = validate_call_info.call.initial_gas;
assert_eq!(validate_initial_gas, block_context.versioned_constants.validate_max_sierra_gas.0);
assert_eq!(
validate_initial_gas,
block_context.versioned_constants.os_constants.validate_max_sierra_gas.0
);
let validate_gas_consumed = validate_call_info.execution.gas_consumed;
assert!(validate_gas_consumed > 0, "New Cairo1 contract should consume gas.");

Expand All @@ -1728,6 +1731,7 @@ fn test_initial_gas(
// minus the gas consumed by validate. Need to add 1 as the check is strictly less than.
let mut prev_initial_gas = block_context
.versioned_constants
.os_constants
.execute_max_sierra_gas
.min(user_gas_bound - GasAmount(validate_gas_consumed) + GasAmount(1))
.0;
Expand Down
19 changes: 11 additions & 8 deletions crates/blockifier/src/transaction/transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ fn expected_validate_call_info(
TrackedResource::SierraGas => {
user_initial_gas
.unwrap_or(initial_gas_amount_from_block_context(None))
.min(VERSIONED_CONSTANTS.validate_max_sierra_gas)
.min(VERSIONED_CONSTANTS.os_constants.validate_max_sierra_gas)
.0
}
},
Expand Down Expand Up @@ -533,14 +533,15 @@ fn test_invoke_tx(
sender_address,
account_cairo_version,
tracked_resource,
Some(initial_gas.min(versioned_constants.validate_max_sierra_gas)),
Some(initial_gas.min(versioned_constants.os_constants.validate_max_sierra_gas)),
);

// Build expected execute call info.
let expected_return_result_calldata = vec![felt!(2_u8)];

let expected_validated_call = expected_validate_call_info.as_ref().unwrap().call.clone();
let expected_initial_execution_gas = versioned_constants
.os_constants
.execute_max_sierra_gas
.min(initial_gas - GasAmount(expected_arguments.validate_gas_consumed))
.0;
Expand Down Expand Up @@ -1834,7 +1835,7 @@ fn test_deploy_account_tx(
let expected_execute_initial_gas = user_initial_gas
// Note that in the case of deploy account, the initial gas in "execute" is limited by
// max_validation_sierra_gas.
.min(versioned_constants.validate_max_sierra_gas);
.min(versioned_constants.os_constants.validate_max_sierra_gas);
let expected_execute_call_info = Some(CallInfo {
call: CallEntryPoint {
class_hash: Some(account_class_hash),
Expand Down Expand Up @@ -2354,7 +2355,7 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) {
storage_address: contract_address,
caller_address: ContractAddress::default(),
call_type: CallType::Call,
initial_gas: block_context.versioned_constants.execute_max_sierra_gas.0,
initial_gas: block_context.versioned_constants.os_constants.execute_max_sierra_gas.0,
},
execution: CallExecution {
retdata: Retdata(vec![value]),
Expand Down Expand Up @@ -2633,7 +2634,7 @@ fn test_balance_print() {
resource_bounds: create_gas_amount_bounds_with_default_price(
GasVector{
l1_gas: GasAmount(1652),
l2_gas: versioned_constants.validate_max_sierra_gas + GasAmount(1234567),
l2_gas: versioned_constants.os_constants.validate_max_sierra_gas + GasAmount(1234567),
l1_data_gas: GasAmount(0),
}
),
Expand Down Expand Up @@ -2691,7 +2692,7 @@ fn test_invoke_max_sierra_gas_validate_execute(
let expected_validate_initial_gas = match account_tracked_resource {
TrackedResource::CairoSteps => VERSIONED_CONSTANTS.infinite_gas_for_vm_mode(),
TrackedResource::SierraGas => {
versioned_constants.validate_max_sierra_gas.min(user_initial_gas).0
versioned_constants.os_constants.validate_max_sierra_gas.min(user_initial_gas).0
}
};

Expand All @@ -2703,6 +2704,7 @@ fn test_invoke_max_sierra_gas_validate_execute(
TrackedResource::CairoSteps => VERSIONED_CONSTANTS.infinite_gas_for_vm_mode(),
TrackedResource::SierraGas => {
versioned_constants
.os_constants
.execute_max_sierra_gas
.min(
user_initial_gas
Expand Down Expand Up @@ -2751,7 +2753,7 @@ fn test_invoke_max_sierra_gas_validate_execute(
resource_bounds: create_gas_amount_bounds_with_default_price(
GasVector{
l1_gas: GasAmount(2203),
l2_gas: versioned_constants.validate_max_sierra_gas + GasAmount(1234567),
l2_gas: versioned_constants.os_constants.validate_max_sierra_gas + GasAmount(1234567),
l1_data_gas: GasAmount(0),
}
),
Expand Down Expand Up @@ -2809,7 +2811,7 @@ fn test_deploy_max_sierra_gas_validate_execute(
let actual_execute_initial_gas =
actual_execution_info.execute_call_info.as_ref().unwrap().call.initial_gas;
let expected_execute_initial_gas =
versioned_constants.validate_max_sierra_gas.min(user_initial_gas).0;
versioned_constants.os_constants.validate_max_sierra_gas.min(user_initial_gas).0;
assert_eq!(actual_execute_initial_gas, expected_execute_initial_gas);

let actual_validate_initial_gas =
Expand All @@ -2818,6 +2820,7 @@ fn test_deploy_max_sierra_gas_validate_execute(
TrackedResource::CairoSteps => VERSIONED_CONSTANTS.infinite_gas_for_vm_mode(),
TrackedResource::SierraGas => {
versioned_constants
.os_constants
.validate_max_sierra_gas
.min(
user_initial_gas
Expand Down
Loading

0 comments on commit d30e22a

Please sign in to comment.