Skip to content

Commit

Permalink
test(blockifier): fix broken revert-recurse fee check in test (#3133)
Browse files Browse the repository at this point in the history
Signed-off-by: Dori Medini <[email protected]>
  • Loading branch information
dorimedini-starkware authored Jan 8, 2025
1 parent aa2ef2c commit db2e07f
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions crates/blockifier/src/transaction/account_transactions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,14 +1047,29 @@ fn test_n_reverted_computation_units(
.unwrap();
let n_units_2 =
result.receipt.resources.computation.total_charged_computation_units(tracked_resource);
let _actual_fee_2 = result.receipt.fee.0;
let actual_fee_2 = result.receipt.fee.0;
// Ensure the transaction was reverted.
assert!(result.is_reverted());

// Make sure that n_units and actual_fee diffs are the same for two consecutive reverted calls.
assert_eq!(n_units_1 - n_units_0, n_units_2 - n_units_1);
// TODO(Meshi, 19/1/2025): Uncomment this line when the fee calculation is fixed.
// assert_eq!(actual_fee_1 - actual_fee_0, actual_fee_2 - actual_fee_1);
match (tracked_resource, resource_bounds.get_gas_vector_computation_mode()) {
// If we are tracking sierra gas, but the user signed on L1 gas bounds only, we may have
// rounding differences in the number of L1 gas units the user is charged for.
// This rounding error can result in at most one unit of L1 gas difference, so the final fee
// can differ by at most the L1 gas price.
(TrackedResource::SierraGas, GasVectorComputationMode::NoL2Gas) => {
assert!(
(i128::try_from(actual_fee_1 - actual_fee_0).unwrap()
- i128::try_from(actual_fee_2 - actual_fee_1).unwrap())
.unsigned_abs()
<= block_context.block_info.gas_prices.l1_gas_price(&FeeType::Strk).get().0
);
}
_ => {
assert_eq!(actual_fee_1 - actual_fee_0, actual_fee_2 - actual_fee_1);
}
}

// Save the delta between two consecutive calls to be tested against a much larger recursion.
let single_call_units_delta = n_units_1 - n_units_0;
Expand Down Expand Up @@ -1089,27 +1104,29 @@ fn test_n_reverted_computation_units(
.unwrap();
let n_units_100 =
result.receipt.resources.computation.total_charged_computation_units(tracked_resource);
let _actual_fee_100 = result.receipt.fee.0;
let actual_fee_100 = result.receipt.fee.0;
// Ensure the transaction was reverted.
assert!(result.is_reverted());

// Make sure that n_units and actual_fee grew as expected.
assert_eq!(n_units_100 - n_units_0, 100 * single_call_units_delta);
// When charging for sierra gas with no L2 gas user bound, due to rounding errors in converting
// L2 gas units to L1 gas, the fee may be a bit off.

// TODO(Meshi): Uncomment this block when the fee calculation is fixed.
// match (tracked_resource, resource_bounds.get_gas_vector_computation_mode()) {
// (TrackedResource::SierraGas, GasVectorComputationMode::NoL2Gas) => {
// assert!(
// 100 * single_call_fee_delta - (actual_fee_100 - actual_fee_0)
// < 10 * single_call_fee_delta
// );
// }
// _ => {
// assert_eq!(actual_fee_100 - actual_fee_0, 100 * single_call_fee_delta);
// }
//}
// L2 gas units to L1 gas, the fee may be a bit off. We may have an error of one L1 gas units
// per recursion, so the fee diff is at most 100 times the price of an L1 gas unit.
match (tracked_resource, resource_bounds.get_gas_vector_computation_mode()) {
(TrackedResource::SierraGas, GasVectorComputationMode::NoL2Gas) => {
assert!(
(i128::try_from(100 * single_call_fee_delta).unwrap()
- i128::try_from(actual_fee_100 - actual_fee_0).unwrap())
.unsigned_abs()
< 100
* block_context.block_info.gas_prices.l1_gas_price(&FeeType::Strk).get().0
);
}
_ => {
assert_eq!(actual_fee_100 - actual_fee_0, 100 * single_call_fee_delta);
}
}
}

#[rstest]
Expand Down

0 comments on commit db2e07f

Please sign in to comment.