@@ -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 ExecutableDeclareTx ,
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
@@ -201,6 +212,8 @@ struct BlobFactory {
201212}
202213
203214impl BlobFactory {
215+ const OPERATOR_PRIVATE_KEY : Felt = Felt :: THREE ;
216+
204217 pub fn new ( ) -> Self {
205218 let chain_info =
206219 ChainInfo { chain_id : CHAIN_ID . clone ( ) , ..ChainInfo :: create_for_testing ( ) } ;
@@ -362,6 +375,11 @@ impl BlobFactory {
362375 // Tx generation
363376 // =====================
364377
378+ fn sign_tx ( tx_hash : TransactionHash ) -> TransactionSignature {
379+ let sig = ecdsa_sign ( & Self :: OPERATOR_PRIVATE_KEY , & tx_hash. 0 ) . unwrap ( ) ;
380+ TransactionSignature ( Arc :: new ( vec ! [ sig. r, sig. s] ) )
381+ }
382+
365383 fn boostrap_declare_tx ( & mut self , contract : FeatureContract ) {
366384 let sender_address = ExecutableDeclareTx :: bootstrap_address ( ) ;
367385 let sierra = contract. get_sierra ( ) ;
@@ -417,6 +435,55 @@ impl BlobFactory {
417435 self . next_txs . push ( ( executable. into ( ) , internal_tx) ) ;
418436 }
419437
438+ fn make_free_deploy_account_tx ( & mut self , account : FeatureContract ) {
439+ let class_hash = account. get_sierra ( ) . calculate_class_hash ( ) ;
440+ let public_key = get_public_key ( & Self :: OPERATOR_PRIVATE_KEY ) ;
441+ let constructor_calldata = calldata ! [ public_key] ;
442+ let contract_address_salt = ContractAddressSalt :: default ( ) ;
443+ // Build with placeholder signature to compute the hash (signature excluded from hash).
444+ let rpc_tx_unsigned = RpcDeployAccountTransactionV3 {
445+ signature : TransactionSignature :: default ( ) ,
446+ resource_bounds : AllResourceBounds :: new_unlimited_gas_no_fee_enforcement ( ) ,
447+ tip : Tip :: default ( ) ,
448+ contract_address_salt,
449+ class_hash,
450+ constructor_calldata : constructor_calldata. clone ( ) ,
451+ nonce : Nonce :: default ( ) ,
452+ nonce_data_availability_mode : DataAvailabilityMode :: L1 ,
453+ fee_data_availability_mode : DataAvailabilityMode :: L1 ,
454+ paymaster_data : PaymasterData :: default ( ) ,
455+ } ;
456+ let contract_address = rpc_tx_unsigned. calculate_contract_address ( ) . unwrap ( ) ;
457+ let without_hash_unsigned = InternalRpcTransactionWithoutTxHash :: DeployAccount (
458+ InternalRpcDeployAccountTransaction {
459+ tx : RpcDeployAccountTransaction :: V3 ( rpc_tx_unsigned. clone ( ) ) ,
460+ contract_address,
461+ } ,
462+ ) ;
463+ let tx_hash = without_hash_unsigned. calculate_transaction_hash ( & CHAIN_ID ) . unwrap ( ) ;
464+ let signature = Self :: sign_tx ( tx_hash) ;
465+
466+ let mut rpc_tx_signed = rpc_tx_unsigned;
467+ rpc_tx_signed. signature = signature;
468+ let without_hash = InternalRpcTransactionWithoutTxHash :: DeployAccount (
469+ InternalRpcDeployAccountTransaction {
470+ tx : RpcDeployAccountTransaction :: V3 ( rpc_tx_signed. clone ( ) ) ,
471+ contract_address,
472+ } ,
473+ ) ;
474+
475+ let executable = ExecutableDeployAccountTx :: create (
476+ DeployAccountTransaction :: V3 ( rpc_tx_signed. into ( ) ) ,
477+ & CHAIN_ID ,
478+ )
479+ . unwrap ( ) ;
480+ let internal = InternalConsensusTransaction :: RpcTransaction ( InternalRpcTransaction {
481+ tx : without_hash,
482+ tx_hash,
483+ } ) ;
484+ self . next_txs . push ( ( executable. into ( ) , internal) ) ;
485+ }
486+
420487 // =====================
421488 // Data generation
422489 // =====================
@@ -606,8 +673,8 @@ async fn test_make_data() {
606673 // Create the list of transactions to be included in the blobs:
607674 // 1. bootstrap declare of an ERC20 contract.
608675 // 2. bootstrap declare of an account with real validate.
609- // TODO(Dori): the rest of the txs.
610676 // 3. deploy account (with zero fees).
677+ // TODO(Dori): the rest of the txs.
611678 // 4. deploy ERC20 contract from the account (with zero fees), while minting some tokens to the
612679 // sender account.
613680 // (from this point - all txs include non-zero fees, and no more bootstrap declares)
@@ -621,6 +688,8 @@ async fn test_make_data() {
621688 blob_factory. boostrap_declare_tx ( erc20_contract) ;
622689 blob_factory. close_block ( ) . await ;
623690 blob_factory. boostrap_declare_tx ( account_with_real_validate) ;
691+ blob_factory. close_block ( ) . await ;
692+ blob_factory. make_free_deploy_account_tx ( account_with_real_validate) ;
624693
625694 let ( blobs, preconfirmed_block) = blob_factory. finalize ( ) . await ;
626695 expect_file ! [ CHAIN_INFO_PATH ] . assert_eq ( & serde_json:: to_string_pretty ( & chain_info) . unwrap ( ) ) ;
0 commit comments