From 59918682a991406e31a9cdd7f6c88359d3c96351 Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Mon, 4 Mar 2024 21:49:08 -0800 Subject: [PATCH] fix(katana): non-query-version fee estimates (#1610) Katana incorrectly assumes that all `starknet_estimateFee` requests are query-versioned, and hence arrives at wrong transaction hashes when clients attempt to estimate with non-query transactions. As of this writing, both Argent X and Braavos use non-query requests for 'DEPLOY_ACCOUNT' fee estimation. This bug prevents these wallets from being used on Katana networks. --- crates/katana/primitives/src/transaction.rs | 8 ++++---- crates/katana/rpc/rpc/src/starknet.rs | 12 +++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/katana/primitives/src/transaction.rs b/crates/katana/primitives/src/transaction.rs index ab9ae73c2d..76b3c4671b 100644 --- a/crates/katana/primitives/src/transaction.rs +++ b/crates/katana/primitives/src/transaction.rs @@ -87,12 +87,12 @@ impl ExecutableTxWithHash { Self { hash, transaction } } - pub fn new_query(transaction: ExecutableTx) -> Self { + pub fn new_query(transaction: ExecutableTx, is_query: bool) -> Self { let hash = match &transaction { ExecutableTx::L1Handler(tx) => tx.calculate_hash(), - ExecutableTx::Invoke(tx) => tx.calculate_hash(true), - ExecutableTx::Declare(tx) => tx.calculate_hash(true), - ExecutableTx::DeployAccount(tx) => tx.calculate_hash(true), + ExecutableTx::Invoke(tx) => tx.calculate_hash(is_query), + ExecutableTx::Declare(tx) => tx.calculate_hash(is_query), + ExecutableTx::DeployAccount(tx) => tx.calculate_hash(is_query), }; Self { hash, transaction } } diff --git a/crates/katana/rpc/rpc/src/starknet.rs b/crates/katana/rpc/rpc/src/starknet.rs index 464204e947..a3d76dce36 100644 --- a/crates/katana/rpc/rpc/src/starknet.rs +++ b/crates/katana/rpc/rpc/src/starknet.rs @@ -481,20 +481,26 @@ impl StarknetApiServer for StarknetApi { .map(|tx| { let tx = match tx { BroadcastedTx::Invoke(tx) => { + let is_query = tx.is_query(); let tx = tx.into_tx_with_chain_id(chain_id); - ExecutableTxWithHash::new_query(ExecutableTx::Invoke(tx)) + ExecutableTxWithHash::new_query(ExecutableTx::Invoke(tx), is_query) } BroadcastedTx::DeployAccount(tx) => { + let is_query = tx.is_query(); let tx = tx.into_tx_with_chain_id(chain_id); - ExecutableTxWithHash::new_query(ExecutableTx::DeployAccount(tx)) + ExecutableTxWithHash::new_query( + ExecutableTx::DeployAccount(tx), + is_query, + ) } BroadcastedTx::Declare(tx) => { + let is_query = tx.is_query(); let tx = tx .try_into_tx_with_chain_id(chain_id) .map_err(|_| StarknetApiError::InvalidContractClass)?; - ExecutableTxWithHash::new_query(ExecutableTx::Declare(tx)) + ExecutableTxWithHash::new_query(ExecutableTx::Declare(tx), is_query) } };