Skip to content

Commit cb6b1fe

Browse files
starknet_os: resources test - deploy account
1 parent 1140f15 commit cb6b1fe

3 files changed

Lines changed: 87 additions & 12 deletions

File tree

crates/blockifier/resources/blockifier_versioned_constants_0_14_4.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -513,12 +513,12 @@
513513
},
514514
"DeployAccount": {
515515
"constant": {
516-
"n_steps": 4583,
516+
"n_steps": 4989,
517517
"n_memory_holes": 0,
518518
"builtin_instance_counter": {
519-
"range_check_builtin": 93,
520-
"pedersen_builtin": 11,
521-
"poseidon_builtin": 11
519+
"range_check_builtin": 113,
520+
"pedersen_builtin": 10,
521+
"poseidon_builtin": 10
522522
}
523523
},
524524
"calldata_factor": {

crates/blockifier/resources/versioned_constants_diff_regression/0.14.3_0.14.4.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
~ /os_resources/execute_syscalls/Sha256ProcessBlock/n_steps: 1854
2929
~ /os_resources/execute_txs_inner/Declare/builtin_instance_counter/range_check_builtin: 92
3030
~ /os_resources/execute_txs_inner/Declare/n_steps: 3938
31+
~ /os_resources/execute_txs_inner/DeployAccount/constant/builtin_instance_counter/pedersen_builtin: 10
32+
~ /os_resources/execute_txs_inner/DeployAccount/constant/builtin_instance_counter/poseidon_builtin: 10
33+
~ /os_resources/execute_txs_inner/DeployAccount/constant/builtin_instance_counter/range_check_builtin: 113
34+
~ /os_resources/execute_txs_inner/DeployAccount/constant/n_steps: 4989
3135
~ /os_resources/execute_txs_inner/InvokeFunction/constant/builtin_instance_counter/poseidon_builtin: 11
3236
~ /os_resources/execute_txs_inner/InvokeFunction/constant/builtin_instance_counter/range_check_builtin: 110
3337
~ /os_resources/execute_txs_inner/InvokeFunction/constant/n_steps: 4779

crates/starknet_os_flow_tests/src/os_resources_test.rs

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ use expect_test::expect_file;
2121
use indexmap::IndexMap;
2222
use starknet_api::block::StarknetVersion;
2323
use starknet_api::contract_class::SierraVersion;
24-
use starknet_api::core::{ClassHash, ContractAddress, EthAddress};
25-
use starknet_api::executable_transaction::{InvokeTransaction, TransactionType};
24+
use starknet_api::core::{ClassHash, ContractAddress, EthAddress, Nonce};
25+
use starknet_api::executable_transaction::{
26+
DeployAccountTransaction,
27+
InvokeTransaction,
28+
TransactionType,
29+
};
30+
use starknet_api::test_utils::deploy_account::deploy_account_tx;
2631
use starknet_api::test_utils::invoke::invoke_tx;
2732
use starknet_api::transaction::fields::{Calldata, ContractAddressSalt};
2833
use starknet_api::transaction::{L2ToL1Payload, MessageToL1};
2934
use starknet_api::versioned_constants_logic::VersionedConstantsTrait;
30-
use starknet_api::{calldata, declare_tx_args, invoke_tx_args};
35+
use starknet_api::{calldata, declare_tx_args, deploy_account_tx_args, invoke_tx_args};
3136
use starknet_os::hint_processor::os_logger::ResourceFinalizer;
3237
use starknet_os::test_utils::{
3338
SHA256_BATCH_RESOURCES_LINEAR_UNSCALED,
@@ -522,16 +527,59 @@ async fn test_execute_txs_inner_resources() {
522527
let version = StarknetVersion::LATEST;
523528
let mut raw_vc: RawVersionedConstants =
524529
serde_json::from_str(VersionedConstants::json_str(&version).unwrap()).unwrap();
525-
// TODO(Dori): DeployAccount, L1Handler.
526-
const N_TXS: usize = 3;
530+
// TODO(Dori): L1Handler.
531+
const N_TXS: usize = 5;
527532

528533
// For linear factor measurements, it's not enough to just add one more calldata element; the
529534
// increase is not the same per element. The linear scale is on average.
530535
const INVOKE_SCALING_FACTOR: usize = 2;
536+
const DEPLOY_SCALING_FACTOR: usize = 2;
531537
const INVOKE_EXTRA_ARGS: usize = 10;
538+
const DEPLOY_EXTRA_ARGS: usize = 10;
532539

533-
let OsResourcesTestSetup { stable_contract_address, mut test_builder, .. } =
534-
setup_test_builder(Some(&raw_vc)).await;
540+
let OsResourcesTestSetup {
541+
stable_contract_address,
542+
stable_contract_class_hash,
543+
mut test_builder,
544+
..
545+
} = setup_test_builder(Some(&raw_vc)).await;
546+
547+
// Prepare the deploy account txs in advance, so we can fund the address before moving to the
548+
// next block (just so the funding tx is not in our measurement block). Use the stable contract
549+
// to prevent noise from changing contract address.
550+
let deploy_tx_first = DeployAccountTransaction::create(
551+
deploy_account_tx(
552+
deploy_account_tx_args! {
553+
class_hash: stable_contract_class_hash,
554+
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
555+
constructor_calldata: calldata![Felt::ZERO],
556+
// The stable contract was already deployed (from deployer address zero) with
557+
// trivial salt, so use non-trivial salt to get a new address.
558+
contract_address_salt: ContractAddressSalt(Felt::from(100)),
559+
},
560+
Nonce::default(),
561+
),
562+
&test_builder.chain_id(),
563+
)
564+
.unwrap();
565+
test_builder.add_fund_address_tx_with_default_amount(deploy_tx_first.contract_address);
566+
let deploy_tx_second = DeployAccountTransaction::create(
567+
deploy_account_tx(
568+
deploy_account_tx_args! {
569+
class_hash: stable_contract_class_hash,
570+
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
571+
constructor_calldata: span_calldata(DEPLOY_EXTRA_ARGS),
572+
// The stable contract was already deployed (from deployer address zero) with
573+
// trivial salt, so use non-trivial salt to get a new address.
574+
contract_address_salt: ContractAddressSalt(Felt::from(100)),
575+
},
576+
Nonce::default(),
577+
),
578+
&test_builder.chain_id(),
579+
)
580+
.unwrap();
581+
test_builder.add_fund_address_tx_with_default_amount(deploy_tx_second.contract_address);
582+
test_builder.move_to_next_block();
535583

536584
// Invoke.
537585
let invoke_args = invoke_tx_args! {
@@ -571,6 +619,10 @@ async fn test_execute_txs_inner_resources() {
571619
&test_builder.chain_id(),
572620
);
573621

622+
// Deploy account (pre-prepared).
623+
test_builder.add_deploy_account_tx(deploy_tx_first);
624+
test_builder.add_deploy_account_tx(deploy_tx_second);
625+
574626
// Execute the business logic and extract the business logic resources for each tx.
575627
let test_runner = test_builder.build().await;
576628
let business_logic_resources: [ExecutionResources; N_TXS] = test_runner
@@ -603,7 +655,13 @@ async fn test_execute_txs_inner_resources() {
603655
test_output.perform_default_validations();
604656

605657
// Fetch the OS resources for each tx.
606-
let [invoke_first, invoke_second, declare_constant]: [ExecutionResources; N_TXS] = test_output
658+
let [
659+
invoke_first,
660+
invoke_second,
661+
declare_constant,
662+
deploy_first,
663+
deploy_second,
664+
]: [ExecutionResources; N_TXS] = test_output
607665
.runner_output
608666
.txs_trace
609667
.iter()
@@ -626,6 +684,9 @@ async fn test_execute_txs_inner_resources() {
626684
let invoke_linear_factor = (&(&invoke_second - &invoke_first).filter_unused_builtins()
627685
* INVOKE_SCALING_FACTOR)
628686
.div_ceil(INVOKE_EXTRA_ARGS);
687+
let deploy_linear_factor = (&(&deploy_second - &deploy_first).filter_unused_builtins()
688+
* DEPLOY_SCALING_FACTOR)
689+
.div_ceil(DEPLOY_EXTRA_ARGS);
629690
raw_vc.os_resources.execute_txs_inner.extend([
630691
(
631692
TransactionType::InvokeFunction,
@@ -638,6 +699,16 @@ async fn test_execute_txs_inner_resources() {
638699
}),
639700
),
640701
(TransactionType::Declare, VariableResourceParams::Constant(declare_constant)),
702+
(
703+
TransactionType::DeployAccount,
704+
VariableResourceParams::WithFactor(ResourcesParams {
705+
constant: (&deploy_first - &deploy_linear_factor).filter_unused_builtins(),
706+
calldata_factor: VariableCallDataFactor::Scaled(CallDataFactor {
707+
resources: deploy_linear_factor,
708+
scaling_factor: DEPLOY_SCALING_FACTOR,
709+
}),
710+
}),
711+
),
641712
]);
642713

643714
// Verify computation.

0 commit comments

Comments
 (0)