Skip to content

Commit ff4a53a

Browse files
starknet_os: resources test - deploy account
1 parent 79997f7 commit ff4a53a

4 files changed

Lines changed: 88 additions & 13 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
@@ -504,12 +504,12 @@
504504
},
505505
"DeployAccount": {
506506
"constant": {
507-
"n_steps": 4583,
507+
"n_steps": 4989,
508508
"n_memory_holes": 0,
509509
"builtin_instance_counter": {
510-
"range_check_builtin": 93,
511-
"pedersen_builtin": 11,
512-
"poseidon_builtin": 11
510+
"range_check_builtin": 113,
511+
"pedersen_builtin": 10,
512+
"poseidon_builtin": 10
513513
}
514514
},
515515
"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
@@ -24,6 +24,10 @@
2424
~ /os_resources/execute_syscalls/Sha256ProcessBlock/n_steps: 1854
2525
~ /os_resources/execute_txs_inner/Declare/builtin_instance_counter/range_check_builtin: 92
2626
~ /os_resources/execute_txs_inner/Declare/n_steps: 3938
27+
~ /os_resources/execute_txs_inner/DeployAccount/constant/builtin_instance_counter/pedersen_builtin: 10
28+
~ /os_resources/execute_txs_inner/DeployAccount/constant/builtin_instance_counter/poseidon_builtin: 10
29+
~ /os_resources/execute_txs_inner/DeployAccount/constant/builtin_instance_counter/range_check_builtin: 113
30+
~ /os_resources/execute_txs_inner/DeployAccount/constant/n_steps: 4989
2731
~ /os_resources/execute_txs_inner/InvokeFunction/constant/builtin_instance_counter/poseidon_builtin: 11
2832
~ /os_resources/execute_txs_inner/InvokeFunction/constant/builtin_instance_counter/range_check_builtin: 110
2933
~ /os_resources/execute_txs_inner/InvokeFunction/constant/n_steps: 4779
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
35
1+
36

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::{SHA256_BATCH_RESOURCES_LINEAR_UNSCALED, SHA256_BATCH_SIZE};
3338
use starknet_types_core::felt::Felt;
@@ -504,16 +509,59 @@ async fn test_execute_txs_inner_resources() {
504509
let version = StarknetVersion::LATEST;
505510
let mut raw_vc: RawVersionedConstants =
506511
serde_json::from_str(VersionedConstants::json_str(&version).unwrap()).unwrap();
507-
// TODO(Dori): DeployAccount, L1Handler.
508-
const N_TXS: usize = 3;
512+
// TODO(Dori): L1Handler.
513+
const N_TXS: usize = 5;
509514

510515
// For linear factor measurements, it's not enough to just add one more calldata element; the
511516
// increase is not the same per element. The linear scale is on average.
512517
const INVOKE_SCALING_FACTOR: usize = 2;
518+
const DEPLOY_SCALING_FACTOR: usize = 2;
513519
const INVOKE_EXTRA_ARGS: usize = 10;
520+
const DEPLOY_EXTRA_ARGS: usize = 10;
514521

515-
let OsResourcesTestSetup { stable_contract_address, mut test_builder, .. } =
516-
setup_test_builder(Some(&raw_vc)).await;
522+
let OsResourcesTestSetup {
523+
stable_contract_address,
524+
stable_contract_class_hash,
525+
mut test_builder,
526+
..
527+
} = setup_test_builder(Some(&raw_vc)).await;
528+
529+
// Prepare the deploy account txs in advance, so we can fund the address before moving to the
530+
// next block (just so the funding tx is not in our measurement block). Use the stable contract
531+
// to prevent noise from changing contract address.
532+
let deploy_tx_first = DeployAccountTransaction::create(
533+
deploy_account_tx(
534+
deploy_account_tx_args! {
535+
class_hash: stable_contract_class_hash,
536+
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
537+
constructor_calldata: calldata![Felt::ZERO],
538+
// The stable contract was already deployed (from deployer address zero) with
539+
// trivial salt, so use non-trivial salt to get a new address.
540+
contract_address_salt: ContractAddressSalt(Felt::from(100)),
541+
},
542+
Nonce::default(),
543+
),
544+
&test_builder.chain_id(),
545+
)
546+
.unwrap();
547+
test_builder.add_fund_address_tx_with_default_amount(deploy_tx_first.contract_address);
548+
let deploy_tx_second = DeployAccountTransaction::create(
549+
deploy_account_tx(
550+
deploy_account_tx_args! {
551+
class_hash: stable_contract_class_hash,
552+
resource_bounds: *NON_TRIVIAL_RESOURCE_BOUNDS,
553+
constructor_calldata: span_calldata(DEPLOY_EXTRA_ARGS),
554+
// The stable contract was already deployed (from deployer address zero) with
555+
// trivial salt, so use non-trivial salt to get a new address.
556+
contract_address_salt: ContractAddressSalt(Felt::from(100)),
557+
},
558+
Nonce::default(),
559+
),
560+
&test_builder.chain_id(),
561+
)
562+
.unwrap();
563+
test_builder.add_fund_address_tx_with_default_amount(deploy_tx_second.contract_address);
564+
test_builder.move_to_next_block();
517565

518566
// Invoke.
519567
let invoke_args = invoke_tx_args! {
@@ -553,6 +601,10 @@ async fn test_execute_txs_inner_resources() {
553601
&test_builder.chain_id(),
554602
);
555603

604+
// Deploy account (pre-prepared).
605+
test_builder.add_deploy_account_tx(deploy_tx_first);
606+
test_builder.add_deploy_account_tx(deploy_tx_second);
607+
556608
// Execute the business logic and extract the business logic resources for each tx.
557609
let test_runner = test_builder.build().await;
558610
let business_logic_resources: [ExecutionResources; N_TXS] = test_runner
@@ -585,7 +637,13 @@ async fn test_execute_txs_inner_resources() {
585637
test_output.perform_default_validations();
586638

587639
// Fetch the OS resources for each tx.
588-
let [invoke_first, invoke_second, declare_constant]: [ExecutionResources; N_TXS] = test_output
640+
let [
641+
invoke_first,
642+
invoke_second,
643+
declare_constant,
644+
deploy_first,
645+
deploy_second,
646+
]: [ExecutionResources; N_TXS] = test_output
589647
.runner_output
590648
.txs_trace
591649
.iter()
@@ -608,6 +666,9 @@ async fn test_execute_txs_inner_resources() {
608666
let invoke_linear_factor = (&(&invoke_second - &invoke_first).filter_unused_builtins()
609667
* INVOKE_SCALING_FACTOR)
610668
.div_ceil(INVOKE_EXTRA_ARGS);
669+
let deploy_linear_factor = (&(&deploy_second - &deploy_first).filter_unused_builtins()
670+
* DEPLOY_SCALING_FACTOR)
671+
.div_ceil(DEPLOY_EXTRA_ARGS);
611672
raw_vc.os_resources.execute_txs_inner.extend([
612673
(
613674
TransactionType::InvokeFunction,
@@ -620,6 +681,16 @@ async fn test_execute_txs_inner_resources() {
620681
}),
621682
),
622683
(TransactionType::Declare, VariableResourceParams::Constant(declare_constant)),
684+
(
685+
TransactionType::DeployAccount,
686+
VariableResourceParams::WithFactor(ResourcesParams {
687+
constant: (&deploy_first - &deploy_linear_factor).filter_unused_builtins(),
688+
calldata_factor: VariableCallDataFactor::Scaled(CallDataFactor {
689+
resources: deploy_linear_factor,
690+
scaling_factor: DEPLOY_SCALING_FACTOR,
691+
}),
692+
}),
693+
),
623694
]);
624695

625696
// Verify computation.

0 commit comments

Comments
 (0)