Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,10 @@
},
"calldata_factor": {
"resources": {
"n_steps": 37,
"n_steps": 26,
"n_memory_holes": 0,
"builtin_instance_counter": {
"pedersen_builtin": 2,
"pedersen_builtin": 1,
"poseidon_builtin": 1
}
},
Expand All @@ -526,11 +526,9 @@
},
"calldata_factor": {
"resources": {
"n_steps": 15,
"n_steps": 3,
"n_memory_holes": 0,
"builtin_instance_counter": {
"poseidon_builtin": 1
}
"builtin_instance_counter": {}
},
"scaling_factor": 2
}
Expand Down
71 changes: 47 additions & 24 deletions crates/starknet_os_flow_tests/src/os_resources_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,15 @@ async fn test_execute_txs_inner_resources() {
let version = StarknetVersion::LATEST;
let mut raw_vc: RawVersionedConstants =
serde_json::from_str(VersionedConstants::json_str(&version).unwrap()).unwrap();
const N_TXS: usize = 5;
const N_TXS: usize = 6;

let (os_resources_contract_address, deployable_class_hash, mut test_builder) =
setup_test_builder().await;

// Prepare the deploy account tx in advance, so we can fund the address before moving to the
// Prepare the deploy account txs in advance, so we can fund the address before moving to the
// next block (just so the funding tx is not in our measurement block). Use the special contract
// to prevent noise from changing contract address.
let deploy_tx = DeployAccountTransaction::create(
let deploy_tx_base = DeployAccountTransaction::create(
deploy_account_tx(
deploy_account_tx_args! {
class_hash: deployable_class_hash,
Expand All @@ -468,7 +468,20 @@ async fn test_execute_txs_inner_resources() {
&test_builder.chain_id(),
)
.unwrap();
test_builder.add_fund_address_tx_with_default_amount(deploy_tx.contract_address);
test_builder.add_fund_address_tx_with_default_amount(deploy_tx_base.contract_address);
let deploy_tx_extra = DeployAccountTransaction::create(
deploy_account_tx(
deploy_account_tx_args! {
class_hash: deployable_class_hash,
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
constructor_calldata: calldata![Felt::ONE, Felt::ZERO],
},
Nonce::default(),
),
&test_builder.chain_id(),
)
.unwrap();
test_builder.add_fund_address_tx_with_default_amount(deploy_tx_extra.contract_address);
test_builder.move_to_next_block();

// Invoke: base.
Expand Down Expand Up @@ -527,7 +540,8 @@ async fn test_execute_txs_inner_resources() {
test_builder.add_cairo1_declare_tx(tx, data_gas_contract_sierra);

// Deploy account (pre-prepared).
test_builder.add_deploy_account_tx(deploy_tx);
test_builder.add_deploy_account_tx(deploy_tx_base);
test_builder.add_deploy_account_tx(deploy_tx_extra);

// L1 handler.
test_builder.add_l1_handler(
Expand Down Expand Up @@ -570,22 +584,28 @@ async fn test_execute_txs_inner_resources() {
test_output.perform_default_validations();

// Fetch the OS resources for each tx.
let [invoke_base, invoke_extra, declare_overhead, deploy_account_overhead, l1_handler_overhead]: [ExecutionResources; N_TXS] =
test_output
.runner_output
.txs_trace
.iter()
.rev()
.take(N_TXS)
.rev()
.map(|trace| trace.get_resources().unwrap().clone())
.zip(business_logic_resources)
.map(|(os_resources, business_logic_resources)| {
(&os_resources - &business_logic_resources).filter_unused_builtins()
})
.collect::<Vec<_>>()
.try_into()
.unwrap();
let [
invoke_base,
invoke_extra,
declare_overhead,
deploy_account_base,
deploy_account_extra,
l1_handler_overhead,
]: [ExecutionResources; N_TXS] = test_output
.runner_output
.txs_trace
.iter()
.rev()
.take(N_TXS)
.rev()
.map(|trace| trace.get_resources().unwrap().clone())
.zip(business_logic_resources)
.map(|(os_resources, business_logic_resources)| {
(&os_resources - &business_logic_resources).filter_unused_builtins()
})
.collect::<Vec<_>>()
.try_into()
.unwrap();

// Invoke: variable cost, with scaling of 2.
let VariableResourceParams::WithFactor(mut invoke_resources_params) = raw_vc
Expand Down Expand Up @@ -634,7 +654,6 @@ async fn test_execute_txs_inner_resources() {
.insert(TransactionType::Declare, VariableResourceParams::Constant(declare_overhead));

// Deploy account: variable cost, with scaling of 2.
// TODO(Dori): Compute linear factor cost.
let VariableResourceParams::WithFactor(mut deploy_account_resources_params) =
raw_vc.os_resources.execute_txs_inner.get(&TransactionType::DeployAccount).unwrap().clone()
else {
Expand All @@ -643,7 +662,7 @@ async fn test_execute_txs_inner_resources() {
raw_vc.os_resources.execute_txs_inner.get(&TransactionType::DeployAccount).unwrap()
);
};
let VariableCallDataFactor::Scaled(ref deploy_account_scaling_factor) =
let VariableCallDataFactor::Scaled(mut deploy_account_scaling_factor) =
deploy_account_resources_params.calldata_factor
else {
panic!(
Expand All @@ -656,7 +675,11 @@ async fn test_execute_txs_inner_resources() {
"Deploy account scaling factor has unexpected value: {:?}",
deploy_account_scaling_factor.scaling_factor
);
deploy_account_resources_params.constant = deploy_account_overhead;
deploy_account_scaling_factor.resources =
(&deploy_account_extra - &deploy_account_base).filter_unused_builtins();
deploy_account_resources_params.calldata_factor =
VariableCallDataFactor::Scaled(deploy_account_scaling_factor);
deploy_account_resources_params.constant = deploy_account_base;
raw_vc.os_resources.execute_txs_inner.insert(
TransactionType::DeployAccount,
VariableResourceParams::WithFactor(deploy_account_resources_params),
Expand Down
Loading