@@ -11,6 +11,7 @@ use blockifier::blockifier_versioned_constants::{
1111use blockifier:: context:: BlockContext ;
1212use blockifier:: execution:: deprecated_syscalls:: DeprecatedSyscallSelector as Selector ;
1313use blockifier:: test_utils:: dict_state_reader:: DictStateReader ;
14+ use blockifier:: transaction:: objects:: ExecutionResourcesTraits ;
1415use blockifier_test_utils:: cairo_versions:: RunnableCairo1 ;
1516use blockifier_test_utils:: contracts:: FeatureContract ;
1617use cairo_vm:: vm:: runners:: cairo_runner:: ExecutionResources ;
@@ -77,21 +78,24 @@ const UNMEASURABLE_SYSCALLS: [Selector; 28] = [
7778
7879/// Store a mapping from a linearly-charged syscall, with the number of "linear elements" in it's
7980/// first measurement. For example, if we measure the base and linear costs of a [Selector::Deploy]
80- /// by running :
81+ /// by measuring :
8182/// ```
82- /// deploy_syscall(stable_class_hash, 3, array![2, 0, 0].span(), true).unwrap_syscall();
83- /// deploy_syscall(stable_class_hash, 3, array![3, 0, 0, 0].span(), true).unwrap_syscall();
83+ /// let deploy_from_zero = true;
84+ /// let M1 = COST(deploy_syscall(class_hash, salt, calldata: [0], deploy_from_zero));
85+ /// let M2 = COST(deploy_syscall(class_hash, salt, calldata: [100] + [0; 100], deploy_from_zero));
8486/// ```
85- /// ... then the linear factor is exactly the difference between the two measurements, because the
86- /// second measurement has one more linear element (4) than the first measurement (3). However, the
87- /// first call has 3 elements in it's calldata, so to compute the estimated cost of a zero-element
88- /// call (base) we need to subtract three times the linear factor from the first measurement. In
89- /// this case, the value in the mapping will be 3.
90- /// The second call will always have one more linear element than the first call.
87+ /// then the base and linear parts can be computed by:
88+ /// ```
89+ /// let LINEAR = (M2 - M1) / 100;
90+ /// let BASE = M1 - LINEAR;
91+ /// ```
92+ /// The formula for `LINEAR` is simple, and note that we must subtract one `LINEAR` from `M1` to get
93+ /// `BASE` because the `M1` measurement has a single calldata element (length of calldata: 0).
9194/// Note: Keccak does not store the linear factor in the same entry in the versioned constants, but
9295/// it does have a measurable linear factor stored under [Selector::KeccakRound].
9396static SYSCALLS_WITH_LINEAR_FACTOR : LazyLock < HashMap < Selector , usize > > =
9497 LazyLock :: new ( || HashMap :: from ( [ ( Selector :: Deploy , 1 ) , ( Selector :: MetaTxV0 , 1 ) ] ) ) ;
98+ const LARGE_INPUT_LENGTH : usize = 100 ;
9599
96100/// Expected syscalls in the fee transfer call. Should be removed from the list of syscalls during
97101/// measurement iteration - only the syscalls called during __execute__ should be measured.
@@ -349,7 +353,9 @@ async fn test_os_resources_regression() {
349353 ) ;
350354 let next_resources =
351355 maybe_deduct_inner ( next_syscall_trace. get_resources ( ) . unwrap ( ) . clone ( ) , selector) ;
352- let linear_factor_resources = ( & next_resources - & resources) . filter_unused_builtins ( ) ;
356+ let linear_factor_resources = ( & next_resources - & resources)
357+ . div_ceil ( LARGE_INPUT_LENGTH )
358+ . filter_unused_builtins ( ) ;
353359
354360 // Linear factor is computed; deduct the linear overhead from the base cost to get the
355361 // real base cost.
0 commit comments