@@ -85,6 +85,15 @@ pub fn is_l2_gas_accounting_enabled(
8585    block_context :  & BlockContext , 
8686    gas_computation_mode :  & GasVectorComputationMode , 
8787)  -> StateResult < bool >  { 
88+     // DEPLOY_ACCOUNT: Cannot determine L2 gas accounting from sender's class hash (account doesn't exist yet). 
89+     // For Braavos accounts, constructor also swaps class hash, breaking L2 gas detection entirely. 
90+     if  is_deploy_account_transaction ( transaction)  { 
91+         return  Ok ( matches ! ( 
92+             gas_computation_mode, 
93+             GasVectorComputationMode :: All 
94+         ) ) ; 
95+     } 
96+ 
8897    let  sender_class_hash = state. get_class_hash_at ( transaction. sender_address ( ) ) ?; 
8998
9099    // L2 gas accounting is disabled if the sender contract is uninitialized. 
@@ -130,6 +139,18 @@ fn determine_gas_vector_mode(transaction: &Transaction) -> GasVectorComputationM
130139    } 
131140} 
132141
142+ fn  is_deploy_account_transaction ( transaction :  & Transaction )  -> bool  { 
143+     matches ! ( 
144+         transaction, 
145+         Transaction :: Account ( 
146+             blockifier:: transaction:: account_transaction:: AccountTransaction  { 
147+                 tx:  starknet_api:: executable_transaction:: AccountTransaction :: DeployAccount ( _) , 
148+                 ..
149+             } 
150+         ) 
151+     ) 
152+ } 
153+ 
133154/// The margin used in binary search for finding the minimal L2 gas limit. 
134155const  L2_GAS_SEARCH_MARGIN :  GasAmount  = GasAmount ( 1_000_000 ) ; 
135156enum  SimulationError  { 
@@ -383,6 +404,13 @@ where
383404
384405    match  tx { 
385406        Transaction :: Account ( account_transaction)  => { 
407+             // DEPLOY_ACCOUNT: Normal logic calculates max gas based on account balance, but account doesn't exist yet (balance = 0). 
408+             // This would set gas limit to zero, causing immediate "out of gas". Use max gas limit from versioned constants instead. 
409+             if  is_deploy_account_transaction ( tx)  { 
410+                 let  max_sierra_gas_limit = block_context. versioned_constants ( ) . os_constants . validate_max_sierra_gas . 0 ; 
411+                 return  Ok ( GasAmount :: from ( max_sierra_gas_limit) ) ; 
412+             } 
413+ 
386414            // Retrieve the fee token address. 
387415            let  fee_token_address = block_context
388416                . chain_info ( ) 
0 commit comments