Skip to content

Commit 2a1e963

Browse files
wojciechosCopilot
andauthored
fix: resolve deploy account estimation issues (#2862)
* fix: resolve DEPLOY_ACCOUNT estimation issues - Skip class hash checks for DEPLOY_ACCOUNT (account doesn't exist yet) - Use max gas limits from versioned constants instead of account balance * Update vm/rust/src/execution.rs Co-authored-by: Copilot <[email protected]> Signed-off-by: wojciechos <[email protected]> --------- Signed-off-by: wojciechos <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent ff48c06 commit 2a1e963

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

vm/rust/src/execution.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
134155
const L2_GAS_SEARCH_MARGIN: GasAmount = GasAmount(1_000_000);
135156
enum 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

Comments
 (0)