From 8d90abf1748920a9f009d0c18cd596b304cc18b5 Mon Sep 17 00:00:00 2001 From: Noa Oved Date: Mon, 22 Jan 2024 15:05:48 +0200 Subject: [PATCH] feat(fee): set the resources slope values --- crates/blockifier/src/fee/os_resources.rs | 15 +++++++++------ .../src/transaction/account_transactions_test.rs | 2 +- .../src/transaction/execution_flavors_test.rs | 16 ++++++++-------- .../src/transaction/transactions_test.rs | 14 ++++++++------ 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/crates/blockifier/src/fee/os_resources.rs b/crates/blockifier/src/fee/os_resources.rs index 022f505f99..a81e9ed294 100644 --- a/crates/blockifier/src/fee/os_resources.rs +++ b/crates/blockifier/src/fee/os_resources.rs @@ -257,13 +257,14 @@ fn os_resources() -> serde_json::Value { "n_memory_holes": 82, "n_steps": 3798 }, + // Calculation of transaction hash + contract address + memcpy. "calldata_factor":{ "builtin_instance_counter": { - "pedersen_builtin": 0, + "pedersen_builtin": 2, "range_check_builtin": 0 }, "n_memory_holes": 0, - "n_steps": 0 + "n_steps": 21 }, }, "InvokeFunction": { @@ -275,13 +276,14 @@ fn os_resources() -> serde_json::Value { "n_memory_holes": 68, "n_steps": 3549 }, + // Calculation of transaction hash. "calldata_factor": { "builtin_instance_counter": { - "pedersen_builtin": 0, + "pedersen_builtin": 1, "range_check_builtin": 0 }, "n_memory_holes": 0, - "n_steps": 0 + "n_steps": 8 } }, "L1Handler": { @@ -293,13 +295,14 @@ fn os_resources() -> serde_json::Value { "n_memory_holes": 0, "n_steps": 1157 }, + // Calculation of transaction hash + memcpy. "calldata_factor": { "builtin_instance_counter": { - "pedersen_builtin": 0, + "pedersen_builtin": 1, "range_check_builtin": 0 }, "n_memory_holes": 0, - "n_steps": 0 + "n_steps": 13 } } } diff --git a/crates/blockifier/src/transaction/account_transactions_test.rs b/crates/blockifier/src/transaction/account_transactions_test.rs index 688e1d82df..d7c34c59ed 100644 --- a/crates/blockifier/src/transaction/account_transactions_test.rs +++ b/crates/blockifier/src/transaction/account_transactions_test.rs @@ -831,7 +831,7 @@ fn test_max_fee_to_max_steps_conversion( ) { let TestInitData { mut state, account_address, contract_address, mut nonce_manager } = create_test_init_data(&block_context.chain_info, CairoVersion::Cairo0); - let actual_gas_used = 6108; + let actual_gas_used = 6140; let actual_gas_used_as_u128: u128 = actual_gas_used.into(); let actual_fee = actual_gas_used_as_u128 * 100000000000; let actual_strk_gas_price = diff --git a/crates/blockifier/src/transaction/execution_flavors_test.rs b/crates/blockifier/src/transaction/execution_flavors_test.rs index b13dfbd97d..fc5bbf2e1e 100644 --- a/crates/blockifier/src/transaction/execution_flavors_test.rs +++ b/crates/blockifier/src/transaction/execution_flavors_test.rs @@ -189,7 +189,7 @@ fn test_simulate_validate_charge_fee_pre_validate( ); // Second scenario: minimal fee not covered. Actual fee is precomputed. - let (actual_gas_used, actual_fee) = gas_and_fee(6095, validate, &fee_type); + let (actual_gas_used, actual_fee) = gas_and_fee(6127, validate, &fee_type); let result = account_invoke_tx(invoke_tx_args! { max_fee: Fee(10), resource_bounds: l1_resource_bounds(10, 10), @@ -329,7 +329,7 @@ fn test_simulate_validate_charge_fee_fail_validate( } = create_flavors_test_state(&block_context.chain_info, cairo_version); // Validation scenario: fallible validation. - let (actual_gas_used, actual_fee) = gas_and_fee(30830, validate, &fee_type); + let (actual_gas_used, actual_fee) = gas_and_fee(30854, validate, &fee_type); let result = account_invoke_tx(invoke_tx_args! { max_fee, resource_bounds: l1_resource_bounds(MAX_L1_GAS_AMOUNT, MAX_L1_GAS_PRICE), @@ -407,7 +407,7 @@ fn test_simulate_validate_charge_fee_mid_execution( }; // First scenario: logic error. Should result in revert; actual fee should be shown. - let (revert_gas_used, revert_fee) = gas_and_fee(5312, validate, &fee_type); + let (revert_gas_used, revert_fee) = gas_and_fee(5344, validate, &fee_type); let tx_execution_info = account_invoke_tx(invoke_tx_args! { calldata: recurse_calldata(test_contract_address, true, 3), nonce: nonce_manager.next(account_address), @@ -439,7 +439,7 @@ fn test_simulate_validate_charge_fee_mid_execution( // If `charge_fee` is true, execution is limited by sender bounds, so less resources will be // used. Otherwise, execution is limited by block bounds, so more resources will be used. let (limited_gas_used, limited_fee) = gas_and_fee(7721, validate, &fee_type); - let (unlimited_gas_used, unlimited_fee) = gas_and_fee(10087, validate, &fee_type); + let (unlimited_gas_used, unlimited_fee) = gas_and_fee(10119, validate, &fee_type); let tx_execution_info = account_invoke_tx(invoke_tx_args! { max_fee: fee_bound, resource_bounds: l1_resource_bounds(gas_bound, gas_price), @@ -559,8 +559,8 @@ fn test_simulate_validate_charge_fee_post_execution( gas_and_fee(base_gas_bound, validate, &fee_type); // `__validate__` and overhead resources + number of reverted steps, comes out slightly more // than the gas bound. - let (revert_gas_usage, revert_fee) = gas_and_fee(9323, validate, &fee_type); - let (unlimited_gas_used, unlimited_fee) = gas_and_fee(10087, validate, &fee_type); + let (revert_gas_usage, revert_fee) = gas_and_fee(9355, validate, &fee_type); + let (unlimited_gas_used, unlimited_fee) = gas_and_fee(10119, validate, &fee_type); let tx_execution_info = account_invoke_tx(invoke_tx_args! { max_fee: just_not_enough_fee_bound, resource_bounds: l1_resource_bounds(just_not_enough_gas_bound, gas_price), @@ -599,8 +599,8 @@ fn test_simulate_validate_charge_fee_post_execution( // Second scenario: balance too low. // Execute a transfer, and make sure we get the expected result. - let (success_actual_gas, actual_fee) = gas_and_fee(8585, validate, &fee_type); - let (fail_actual_gas, fail_actual_cost) = gas_and_fee(5833, validate, &fee_type); + let (success_actual_gas, actual_fee) = gas_and_fee(8633, validate, &fee_type); + let (fail_actual_gas, fail_actual_cost) = gas_and_fee(5881, validate, &fee_type); assert!(stark_felt!(actual_fee) < current_balance); let transfer_amount = stark_felt_to_felt(current_balance) - Felt252::from(actual_fee.0 / 2); let recipient = stark_felt!(7_u8); diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index 34dc09ecae..0544df6d48 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -296,7 +296,7 @@ fn default_invoke_tx_args( #[case::with_cairo0_account( ExpectedResultTestInvokeTx{ range_check: 102, - n_steps: 4464, + n_steps: 4496, vm_resources: VmExecutionResources { n_steps: 62, n_memory_holes: 0, @@ -310,7 +310,7 @@ fn default_invoke_tx_args( #[case::with_cairo1_account( ExpectedResultTestInvokeTx{ range_check: 115, - n_steps: 4917, + n_steps: 4949, vm_resources: VmExecutionResources { n_steps: 284, n_memory_holes: 1, @@ -340,6 +340,7 @@ fn test_invoke_tx( // Extract invoke transaction fields for testing, as it is consumed when creating an account // transaction. let calldata = Calldata(Arc::clone(&invoke_tx.calldata().0)); + let calldata_length = &invoke_tx.calldata().0.len(); let sender_address = invoke_tx.sender_address(); let account_tx = AccountTransaction::Invoke(invoke_tx); @@ -426,7 +427,7 @@ fn test_invoke_tx( usize_from_u128(expected_blob_gas_usage).unwrap(), ), (abi_constants::L1_GAS_USAGE.to_string(), usize_from_u128(expected_gas_usage).unwrap()), - (HASH_BUILTIN_NAME.to_string(), 16), + (HASH_BUILTIN_NAME.to_string(), 16 + calldata_length), (RANGE_CHECK_BUILTIN_NAME.to_string(), expected_arguments.range_check), (abi_constants::N_STEPS_RESOURCE.to_string(), expected_arguments.n_steps), ])), @@ -1685,6 +1686,7 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { let value = StarkFelt::from_u128(0x44); let calldata = calldata![from_address, key, value]; let tx = l1_handler_tx(&calldata, Fee(1)); + let payload_size = tx.payload_size(); let actual_execution_info = tx.execute(state, block_context, true, true).unwrap(); @@ -1723,8 +1725,8 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { }; let expected_resource_mapping = ResourcesMapping(HashMap::from([ - (HASH_BUILTIN_NAME.to_string(), 11), - (abi_constants::N_STEPS_RESOURCE.to_string(), 1390), + (HASH_BUILTIN_NAME.to_string(), 11 + payload_size), + (abi_constants::N_STEPS_RESOURCE.to_string(), 1416), (RANGE_CHECK_BUILTIN_NAME.to_string(), 23), (abi_constants::L1_GAS_USAGE.to_string(), expected_gas_usage), (abi_constants::BLOB_GAS_USAGE.to_string(), expected_blob_gas_usage), @@ -1762,7 +1764,7 @@ fn test_l1_handler(#[values(false, true)] use_kzg_da: bool) { error, TransactionExecutionError::TransactionFeeError( TransactionFeeError::InsufficientL1Fee { paid_fee, actual_fee, }) - if paid_fee == Fee(0) && actual_fee == Fee(1741300000000000) + if paid_fee == Fee(0) && actual_fee == Fee(1743900000000000) ); }