@@ -52,41 +52,52 @@ use starknet_api::block_hash::block_hash_calculator::{
5252 TransactionHashingData ,
5353} ;
5454use starknet_api:: consensus_transaction:: InternalConsensusTransaction ;
55- use starknet_api:: contract_address;
5655use starknet_api:: contract_class:: compiled_class_hash:: HashVersion ;
5756use starknet_api:: core:: { ChainId , Nonce , OsChainInfo } ;
5857use starknet_api:: data_availability:: { DataAvailabilityMode , L1DataAvailabilityMode } ;
5958use starknet_api:: executable_transaction:: {
6059 AccountTransaction as ExecutableAccountTx ,
6160 DeclareTransaction as ExecutableDeclareTransaction ,
61+ DeployAccountTransaction as ExecutableDeployAccountTx ,
6262 Transaction as ExecutableTx ,
6363} ;
6464use starknet_api:: hash:: StateRoots ;
6565use starknet_api:: rpc_transaction:: {
6666 InternalRpcDeclareTransactionV3 ,
67+ InternalRpcDeployAccountTransaction ,
6768 InternalRpcTransaction ,
6869 InternalRpcTransactionWithoutTxHash ,
70+ RpcDeployAccountTransaction ,
71+ RpcDeployAccountTransactionV3 ,
6972} ;
7073use starknet_api:: state:: ThinStateDiff ;
7174use starknet_api:: test_utils:: TEST_SEQUENCER_ADDRESS ;
7275use starknet_api:: transaction:: fields:: {
7376 AccountDeploymentData ,
7477 AllResourceBounds ,
78+ ContractAddressSalt ,
7579 PaymasterData ,
7680 Tip ,
7781 TransactionSignature ,
7882} ;
7983use starknet_api:: transaction:: {
84+ CalculateContractAddress ,
8085 DeclareTransaction ,
86+ DeployAccountTransaction ,
87+ TransactionHash ,
8188 TransactionHasher ,
8289 TransactionOffsetInBlock ,
8390 TransactionVersion ,
8491} ;
92+ use starknet_api:: { calldata, contract_address} ;
8593use starknet_committer:: block_committer:: input:: StateDiff ;
8694use starknet_committer:: db:: facts_db:: FactsDb ;
8795use starknet_committer:: db:: forest_trait:: StorageInitializer ;
96+ use starknet_core:: crypto:: ecdsa_sign;
97+ use starknet_crypto:: get_public_key;
8898use starknet_patricia_storage:: map_storage:: MapStorage ;
8999use starknet_transaction_prover:: running:: committer_utils:: commit_state_diff;
100+ use starknet_types_core:: felt:: Felt ;
90101
91102const GCS_ERROR_CODE_NOT_FOUND : u16 = 404 ;
92103
@@ -194,6 +205,8 @@ struct BlobFactory {
194205}
195206
196207impl BlobFactory {
208+ const OPERATOR_PRIVATE_KEY : Felt = Felt :: THREE ;
209+
197210 pub fn new ( ) -> Self {
198211 let chain_info =
199212 ChainInfo { chain_id : CHAIN_ID . clone ( ) , ..ChainInfo :: create_for_testing ( ) } ;
@@ -358,6 +371,11 @@ impl BlobFactory {
358371 // Tx generation
359372 // =====================
360373
374+ fn sign_tx ( tx_hash : TransactionHash ) -> TransactionSignature {
375+ let sig = ecdsa_sign ( & Self :: OPERATOR_PRIVATE_KEY , & tx_hash. 0 ) . unwrap ( ) ;
376+ TransactionSignature ( Arc :: new ( vec ! [ sig. r, sig. s] ) )
377+ }
378+
361379 fn boostrap_declare_tx ( & mut self , contract : FeatureContract ) {
362380 let sender_address = ExecutableDeclareTransaction :: bootstrap_address ( ) ;
363381 let sierra = contract. get_sierra ( ) ;
@@ -413,6 +431,55 @@ impl BlobFactory {
413431 self . next_txs . push ( ( executable. into ( ) , internal_tx) ) ;
414432 }
415433
434+ fn make_free_deploy_account_tx ( & mut self , account : FeatureContract ) {
435+ let class_hash = account. get_sierra ( ) . calculate_class_hash ( ) ;
436+ let public_key = get_public_key ( & Self :: OPERATOR_PRIVATE_KEY ) ;
437+ let constructor_calldata = calldata ! [ public_key] ;
438+ let contract_address_salt = ContractAddressSalt :: default ( ) ;
439+ // Build with placeholder signature to compute the hash (signature excluded from hash).
440+ let rpc_tx_unsigned = RpcDeployAccountTransactionV3 {
441+ signature : TransactionSignature :: default ( ) ,
442+ resource_bounds : AllResourceBounds :: new_unlimited_gas_no_fee_enforcement ( ) ,
443+ tip : Tip :: default ( ) ,
444+ contract_address_salt,
445+ class_hash,
446+ constructor_calldata : constructor_calldata. clone ( ) ,
447+ nonce : Nonce :: default ( ) ,
448+ nonce_data_availability_mode : DataAvailabilityMode :: L1 ,
449+ fee_data_availability_mode : DataAvailabilityMode :: L1 ,
450+ paymaster_data : PaymasterData :: default ( ) ,
451+ } ;
452+ let contract_address = rpc_tx_unsigned. calculate_contract_address ( ) . unwrap ( ) ;
453+ let without_hash_unsigned = InternalRpcTransactionWithoutTxHash :: DeployAccount (
454+ InternalRpcDeployAccountTransaction {
455+ tx : RpcDeployAccountTransaction :: V3 ( rpc_tx_unsigned. clone ( ) ) ,
456+ contract_address,
457+ } ,
458+ ) ;
459+ let tx_hash = without_hash_unsigned. calculate_transaction_hash ( & CHAIN_ID ) . unwrap ( ) ;
460+ let signature = Self :: sign_tx ( tx_hash) ;
461+
462+ let mut rpc_tx_signed = rpc_tx_unsigned;
463+ rpc_tx_signed. signature = signature;
464+ let without_hash = InternalRpcTransactionWithoutTxHash :: DeployAccount (
465+ InternalRpcDeployAccountTransaction {
466+ tx : RpcDeployAccountTransaction :: V3 ( rpc_tx_signed. clone ( ) ) ,
467+ contract_address,
468+ } ,
469+ ) ;
470+
471+ let executable = ExecutableDeployAccountTx :: create (
472+ DeployAccountTransaction :: V3 ( rpc_tx_signed. into ( ) ) ,
473+ & CHAIN_ID ,
474+ )
475+ . unwrap ( ) ;
476+ let internal = InternalConsensusTransaction :: RpcTransaction ( InternalRpcTransaction {
477+ tx : without_hash,
478+ tx_hash,
479+ } ) ;
480+ self . next_txs . push ( ( executable. into ( ) , internal) ) ;
481+ }
482+
416483 // =====================
417484 // Data generation
418485 // =====================
@@ -599,8 +666,8 @@ async fn test_make_data() {
599666 // Create the list of transactions to be included in the blobs:
600667 // 1. bootstrap declare of an ERC20 contract.
601668 // 2. bootstrap declare of an account with real validate.
602- // TODO(Dori): the rest of the txs.
603669 // 3. deploy account (with zero fees).
670+ // TODO(Dori): the rest of the txs.
604671 // 4. deploy ERC20 contract from the account (with zero fees), while minting some tokens to the
605672 // sender account.
606673 // (from this point - all txs include non-zero fees, and no more bootstrap declares)
@@ -614,6 +681,8 @@ async fn test_make_data() {
614681 blob_factory. boostrap_declare_tx ( erc20_contract) ;
615682 blob_factory. close_block ( ) . await ;
616683 blob_factory. boostrap_declare_tx ( account_with_real_validate) ;
684+ blob_factory. close_block ( ) . await ;
685+ blob_factory. make_free_deploy_account_tx ( account_with_real_validate) ;
617686
618687 let ( blobs, preconfirmed_block) = blob_factory. finalize ( ) . await ;
619688 expect_file ! [ CHAIN_INFO_PATH ] . assert_eq ( & serde_json:: to_string_pretty ( & chain_info) . unwrap ( ) ) ;
0 commit comments