@@ -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 ( ) } ;
@@ -359,6 +372,11 @@ impl BlobFactory {
359372 // Tx generation
360373 // =====================
361374
375+ fn sign_tx ( tx_hash : TransactionHash ) -> TransactionSignature {
376+ let sig = ecdsa_sign ( & Self :: OPERATOR_PRIVATE_KEY , & tx_hash. 0 ) . unwrap ( ) ;
377+ TransactionSignature ( Arc :: new ( vec ! [ sig. r, sig. s] ) )
378+ }
379+
362380 fn boostrap_declare_tx ( & mut self , contract : FeatureContract ) {
363381 let sender_address = ExecutableDeclareTransaction :: bootstrap_address ( ) ;
364382 let sierra = contract. get_sierra ( ) ;
@@ -414,6 +432,55 @@ impl BlobFactory {
414432 self . next_txs . push ( ( executable. into ( ) , internal_tx) ) ;
415433 }
416434
435+ fn make_free_deploy_account_tx ( & mut self , account : FeatureContract ) {
436+ let class_hash = account. get_sierra ( ) . calculate_class_hash ( ) ;
437+ let public_key = get_public_key ( & Self :: OPERATOR_PRIVATE_KEY ) ;
438+ let constructor_calldata = calldata ! [ public_key] ;
439+ let contract_address_salt = ContractAddressSalt :: default ( ) ;
440+ // Build with placeholder signature to compute the hash (signature excluded from hash).
441+ let rpc_tx_unsigned = RpcDeployAccountTransactionV3 {
442+ signature : TransactionSignature :: default ( ) ,
443+ resource_bounds : AllResourceBounds :: new_unlimited_gas_no_fee_enforcement ( ) ,
444+ tip : Tip :: default ( ) ,
445+ contract_address_salt,
446+ class_hash,
447+ constructor_calldata : constructor_calldata. clone ( ) ,
448+ nonce : Nonce :: default ( ) ,
449+ nonce_data_availability_mode : DataAvailabilityMode :: L1 ,
450+ fee_data_availability_mode : DataAvailabilityMode :: L1 ,
451+ paymaster_data : PaymasterData :: default ( ) ,
452+ } ;
453+ let contract_address = rpc_tx_unsigned. calculate_contract_address ( ) . unwrap ( ) ;
454+ let without_hash_unsigned = InternalRpcTransactionWithoutTxHash :: DeployAccount (
455+ InternalRpcDeployAccountTransaction {
456+ tx : RpcDeployAccountTransaction :: V3 ( rpc_tx_unsigned. clone ( ) ) ,
457+ contract_address,
458+ } ,
459+ ) ;
460+ let tx_hash = without_hash_unsigned. calculate_transaction_hash ( & CHAIN_ID ) . unwrap ( ) ;
461+ let signature = Self :: sign_tx ( tx_hash) ;
462+
463+ let mut rpc_tx_signed = rpc_tx_unsigned;
464+ rpc_tx_signed. signature = signature;
465+ let without_hash = InternalRpcTransactionWithoutTxHash :: DeployAccount (
466+ InternalRpcDeployAccountTransaction {
467+ tx : RpcDeployAccountTransaction :: V3 ( rpc_tx_signed. clone ( ) ) ,
468+ contract_address,
469+ } ,
470+ ) ;
471+
472+ let executable = ExecutableDeployAccountTx :: create (
473+ DeployAccountTransaction :: V3 ( rpc_tx_signed. into ( ) ) ,
474+ & CHAIN_ID ,
475+ )
476+ . unwrap ( ) ;
477+ let internal = InternalConsensusTransaction :: RpcTransaction ( InternalRpcTransaction {
478+ tx : without_hash,
479+ tx_hash,
480+ } ) ;
481+ self . next_txs . push ( ( executable. into ( ) , internal) ) ;
482+ }
483+
417484 // =====================
418485 // Data generation
419486 // =====================
@@ -600,8 +667,8 @@ async fn test_make_data() {
600667 // Create the list of transactions to be included in the blobs:
601668 // 1. bootstrap declare of an ERC20 contract.
602669 // 2. bootstrap declare of an account with real validate.
603- // TODO(Dori): the rest of the txs.
604670 // 3. deploy account (with zero fees).
671+ // TODO(Dori): the rest of the txs.
605672 // 4. deploy ERC20 contract from the account (with zero fees), while minting some tokens to the
606673 // sender account.
607674 // (from this point - all txs include non-zero fees, and no more bootstrap declares)
@@ -615,6 +682,8 @@ async fn test_make_data() {
615682 blob_factory. boostrap_declare_tx ( erc20_contract) ;
616683 blob_factory. close_block ( ) . await ;
617684 blob_factory. boostrap_declare_tx ( account_with_real_validate) ;
685+ blob_factory. close_block ( ) . await ;
686+ blob_factory. make_free_deploy_account_tx ( account_with_real_validate) ;
618687
619688 let ( blobs, preconfirmed_block) = blob_factory. finalize ( ) . await ;
620689 expect_file ! [ CHAIN_INFO_PATH ] . assert_eq ( & serde_json:: to_string_pretty ( & chain_info) . unwrap ( ) ) ;
0 commit comments