@@ -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 ( ) } ;
@@ -361,6 +374,11 @@ impl BlobFactory {
361374 // Tx generation
362375 // =====================
363376
377+ fn sign_tx ( tx_hash : TransactionHash ) -> TransactionSignature {
378+ let sig = ecdsa_sign ( & Self :: OPERATOR_PRIVATE_KEY , & tx_hash. 0 ) . unwrap ( ) ;
379+ TransactionSignature ( Arc :: new ( vec ! [ sig. r, sig. s] ) )
380+ }
381+
364382 fn boostrap_declare_tx ( & mut self , contract : FeatureContract ) {
365383 let sender_address = ExecutableDeclareTransaction :: bootstrap_address ( ) ;
366384 let sierra = contract. get_sierra ( ) ;
@@ -416,6 +434,55 @@ impl BlobFactory {
416434 self . next_txs . push ( ( executable. into ( ) , internal_tx) ) ;
417435 }
418436
437+ fn make_free_deploy_account_tx ( & mut self , account : FeatureContract ) {
438+ let class_hash = account. get_sierra ( ) . calculate_class_hash ( ) ;
439+ let public_key = get_public_key ( & Self :: OPERATOR_PRIVATE_KEY ) ;
440+ let constructor_calldata = calldata ! [ public_key] ;
441+ let contract_address_salt = ContractAddressSalt :: default ( ) ;
442+ // Build with placeholder signature to compute the hash (signature excluded from hash).
443+ let rpc_tx_unsigned = RpcDeployAccountTransactionV3 {
444+ signature : TransactionSignature :: default ( ) ,
445+ resource_bounds : AllResourceBounds :: new_unlimited_gas_no_fee_enforcement ( ) ,
446+ tip : Tip :: default ( ) ,
447+ contract_address_salt,
448+ class_hash,
449+ constructor_calldata : constructor_calldata. clone ( ) ,
450+ nonce : Nonce :: default ( ) ,
451+ nonce_data_availability_mode : DataAvailabilityMode :: L1 ,
452+ fee_data_availability_mode : DataAvailabilityMode :: L1 ,
453+ paymaster_data : PaymasterData :: default ( ) ,
454+ } ;
455+ let contract_address = rpc_tx_unsigned. calculate_contract_address ( ) . unwrap ( ) ;
456+ let without_hash_unsigned = InternalRpcTransactionWithoutTxHash :: DeployAccount (
457+ InternalRpcDeployAccountTransaction {
458+ tx : RpcDeployAccountTransaction :: V3 ( rpc_tx_unsigned. clone ( ) ) ,
459+ contract_address,
460+ } ,
461+ ) ;
462+ let tx_hash = without_hash_unsigned. calculate_transaction_hash ( & CHAIN_ID ) . unwrap ( ) ;
463+ let signature = Self :: sign_tx ( tx_hash) ;
464+
465+ let mut rpc_tx_signed = rpc_tx_unsigned;
466+ rpc_tx_signed. signature = signature;
467+ let without_hash = InternalRpcTransactionWithoutTxHash :: DeployAccount (
468+ InternalRpcDeployAccountTransaction {
469+ tx : RpcDeployAccountTransaction :: V3 ( rpc_tx_signed. clone ( ) ) ,
470+ contract_address,
471+ } ,
472+ ) ;
473+
474+ let executable = ExecutableDeployAccountTx :: create (
475+ DeployAccountTransaction :: V3 ( rpc_tx_signed. into ( ) ) ,
476+ & CHAIN_ID ,
477+ )
478+ . unwrap ( ) ;
479+ let internal = InternalConsensusTransaction :: RpcTransaction ( InternalRpcTransaction {
480+ tx : without_hash,
481+ tx_hash,
482+ } ) ;
483+ self . next_txs . push ( ( executable. into ( ) , internal) ) ;
484+ }
485+
419486 // =====================
420487 // Data generation
421488 // =====================
@@ -602,8 +669,8 @@ async fn test_make_data() {
602669 // Create the list of transactions to be included in the blobs:
603670 // 1. bootstrap declare of an ERC20 contract.
604671 // 2. bootstrap declare of an account with real validate.
605- // TODO(Dori): the rest of the txs.
606672 // 3. deploy account (with zero fees).
673+ // TODO(Dori): the rest of the txs.
607674 // 4. deploy ERC20 contract from the account (with zero fees), while minting some tokens to the
608675 // sender account.
609676 // (from this point - all txs include non-zero fees, and no more bootstrap declares)
@@ -617,6 +684,8 @@ async fn test_make_data() {
617684 blob_factory. boostrap_declare_tx ( erc20_contract) ;
618685 blob_factory. close_block ( ) . await ;
619686 blob_factory. boostrap_declare_tx ( account_with_real_validate) ;
687+ blob_factory. close_block ( ) . await ;
688+ blob_factory. make_free_deploy_account_tx ( account_with_real_validate) ;
620689
621690 let ( blobs, preconfirmed_block) = blob_factory. finalize ( ) . await ;
622691 expect_file ! [ CHAIN_INFO_PATH ] . assert_eq ( & serde_json:: to_string_pretty ( & chain_info) . unwrap ( ) ) ;
0 commit comments