diff --git a/crates/client/rpc/src/trace_api.rs b/crates/client/rpc/src/trace_api.rs index 114e61e240..f0ea45d938 100644 --- a/crates/client/rpc/src/trace_api.rs +++ b/crates/client/rpc/src/trace_api.rs @@ -445,7 +445,8 @@ fn tx_execution_infos_to_tx_trace( // TODO(#1291): Compute state diff correctly state_diff: None, }), - TxType::Deploy => todo!(), //TODO: Implement this using Starknet-rs old commits (becareful, Receipt version exist but here we need a trace) + TxType::Deploy => todo!(), /* TODO: Implement this using Starknet-rs old commits (becareful, Receipt version + * exist but here we need a trace) */ TxType::DeployAccount => { TransactionTrace::DeployAccount(DeployAccountTransactionTrace { validate_invocation, diff --git a/crates/pallets/starknet/src/lib.rs b/crates/pallets/starknet/src/lib.rs index 5d1586d9ac..f1e540dcdc 100644 --- a/crates/pallets/starknet/src/lib.rs +++ b/crates/pallets/starknet/src/lib.rs @@ -85,8 +85,8 @@ use mp_sequencer_address::{InherentError, InherentType, DEFAULT_SEQUENCER_ADDRES use mp_storage::{StarknetStorageSchemaVersion, PALLET_STARKNET_SCHEMA}; use mp_transactions::execution::Execute; use mp_transactions::{ - DeclareTransaction, DeployAccountTransaction, HandleL1MessageTransaction, InvokeTransaction, Transaction, - UserOrL1HandlerTransaction, UserTransaction, DeployTransaction, + DeclareTransaction, DeployAccountTransaction, DeployTransaction, HandleL1MessageTransaction, InvokeTransaction, + Transaction, UserOrL1HandlerTransaction, UserTransaction, }; use sp_runtime::traits::UniqueSaturatedInto; use sp_runtime::DigestItem; @@ -727,8 +727,6 @@ pub mod pallet { Ok(()) } - - /// Consume a message from L1. /// /// # Arguments @@ -751,33 +749,33 @@ pub mod pallet { ) -> DispatchResult { // This ensures that the function can only be called via unsigned transaction. ensure_none(origin)?; - + let input_transaction = transaction; let chain_id = Self::chain_id(); let transaction = input_transaction.into_executable::(chain_id, paid_fee_on_l1, false); - + let nonce: Nonce = transaction.tx.nonce; - + // Ensure that L1 Message has not been executed Self::ensure_l1_message_not_executed(&nonce).map_err(|_| Error::::L1MessageAlreadyExecuted)?; - + // Store infornamtion about message being processed // The next instruction executes the message // Either successfully or not L1Messages::::mutate(|nonces| nonces.insert(nonce)); - + // Execute let tx_execution_infos = transaction - .execute( - &mut BlockifierStateAdapter::::default(), - &Self::get_block_context(), - &RuntimeExecutionConfigBuilder::new::().build(), - ) - .map_err(|e| { - log::error!("Failed to consume l1 message: {}", e); - Error::::TransactionExecutionFailed - })?; - + .execute( + &mut BlockifierStateAdapter::::default(), + &Self::get_block_context(), + &RuntimeExecutionConfigBuilder::new::().build(), + ) + .map_err(|e| { + log::error!("Failed to consume l1 message: {}", e); + Error::::TransactionExecutionFailed + })?; + let tx_hash = transaction.tx_hash; Self::emit_and_store_tx_and_fees_events( tx_hash, @@ -789,10 +787,10 @@ pub mod pallet { Transaction::L1Handler(input_transaction), tx_execution_infos.revert_error, ); - + Ok(()) } - + /// DeployTransaction, type of transaction used before Starknet v0.10.1. /// Before you can calculate the transaction hash, get the deployed contract address. /// # Arguments @@ -808,17 +806,17 @@ pub mod pallet { pub fn deploy(origin: OriginFor, transaction: DeployTransaction) -> DispatchResult { // This ensures that the function can only be called via unsigned transaction. ensure_none(origin)?; - + let input_transaction = transaction; let chain_id = T::ChainId::get(); let transaction = input_transaction.into_executable::(chain_id, false); - + // Check if contract is deployed ensure!( !ContractClassHashes::::contains_key(transaction.contract_address), Error::::AccountAlreadyDeployed ); - + // Execute let tx_execution_infos = transaction .execute( @@ -830,7 +828,7 @@ pub mod pallet { log::error!("failed to deploy transaction: {:?}", e); Error::::TransactionExecutionFailed })?; - + let tx_hash = transaction.tx_hash; Self::emit_and_store_tx_and_fees_events( tx_hash, @@ -838,11 +836,11 @@ pub mod pallet { &tx_execution_infos.fee_transfer_call_info, ); Self::store_transaction(tx_hash, Transaction::Deploy(input_transaction), tx_execution_infos.revert_error); - + Ok(()) } } - + #[pallet::inherent] impl ProvideInherent for Pallet { type Call = Call; diff --git a/crates/pallets/starknet/src/transaction_validation.rs b/crates/pallets/starknet/src/transaction_validation.rs index 99b99aca7f..618ce25dd8 100644 --- a/crates/pallets/starknet/src/transaction_validation.rs +++ b/crates/pallets/starknet/src/transaction_validation.rs @@ -110,19 +110,23 @@ impl Pallet { match transaction { UserOrL1HandlerTransaction::User(transaction) => { - let validation_result = - match transaction { - // There is no way to validate it before the account is actuallly deployed - UserTransaction::DeployAccount(_) => Ok(None), - UserTransaction::Deploy(_) => Ok(None), //TODO : Verify this (an account can do a DeployTransaction without being declared first?) - UserTransaction::Declare(tx, contract_class) => tx - .try_into_executable::(chain_id, contract_class.clone(), false) - .map_err(|_| InvalidTransaction::BadProof)? - .validate_tx(&mut state, &block_context, &mut execution_resources, &mut initial_gas, false), - UserTransaction::Invoke(tx) => tx - .into_executable::(chain_id, false) - .validate_tx(&mut state, &block_context, &mut execution_resources, &mut initial_gas, false), - }; + let validation_result = match transaction { + // There is no way to validate it before the account is actuallly deployed + UserTransaction::DeployAccount(_) => Ok(None), + UserTransaction::Deploy(_) => Ok(None), /* TODO : Verify this (an account can do a + * DeployTransaction without being declared first?) */ + UserTransaction::Declare(tx, contract_class) => tx + .try_into_executable::(chain_id, contract_class.clone(), false) + .map_err(|_| InvalidTransaction::BadProof)? + .validate_tx(&mut state, &block_context, &mut execution_resources, &mut initial_gas, false), + UserTransaction::Invoke(tx) => tx.into_executable::(chain_id, false).validate_tx( + &mut state, + &block_context, + &mut execution_resources, + &mut initial_gas, + false, + ), + }; if let Err(TransactionExecutionError::ValidateTransactionError( EntryPointExecutionError::PreExecutionError(PreExecutionError::UninitializedStorageAddress( diff --git a/crates/primitives/transactions/src/conversions.rs b/crates/primitives/transactions/src/conversions.rs index 6894200e58..bb4bc9e5fc 100644 --- a/crates/primitives/transactions/src/conversions.rs +++ b/crates/primitives/transactions/src/conversions.rs @@ -13,8 +13,8 @@ use starknet_api::transaction::{Fee, TransactionVersion}; use super::compute_hash::ComputeTransactionHash; use super::{ - DeclareTransaction, DeclareTransactionV0, DeclareTransactionV1, DeclareTransactionV2, DeployAccountTransaction, DeployTransaction, - HandleL1MessageTransaction, InvokeTransaction, InvokeTransactionV0, InvokeTransactionV1, + DeclareTransaction, DeclareTransactionV0, DeclareTransactionV1, DeclareTransactionV2, DeployAccountTransaction, + DeployTransaction, HandleL1MessageTransaction, InvokeTransaction, InvokeTransactionV0, InvokeTransactionV1, }; impl DeclareTransactionV0 { @@ -218,11 +218,12 @@ impl DeployTransaction { offset_version: bool, ) -> btx::DeployTransaction { let account_address = self.get_account_address(); - let transaction_hash: Felt252Wrapper = - self.compute_hash_given_contract_address::(chain_id.into(), account_address, offset_version, None).into(); + let transaction_hash: Felt252Wrapper = self + .compute_hash_given_contract_address::(chain_id.into(), account_address, offset_version, None) + .into(); let contract_address: Felt252Wrapper = account_address.into(); - //let transaction_hash = self.compute_hash::(chain_id, offset_version, None); - + // let transaction_hash = self.compute_hash::(chain_id, offset_version, None); + btx::DeployTransaction { tx: sttx::DeployTransaction { version: sttx::TransactionVersion(StarkFelt::from(1u128)), @@ -234,7 +235,7 @@ impl DeployTransaction { contract_address: contract_address.into(), } } - + pub fn from_starknet(inner: starknet_api::transaction::DeployTransaction) -> Self { Self { class_hash: inner.class_hash.into(), diff --git a/crates/primitives/transactions/src/execution.rs b/crates/primitives/transactions/src/execution.rs index 8e9e5f7ad0..569e5964cc 100644 --- a/crates/primitives/transactions/src/execution.rs +++ b/crates/primitives/transactions/src/execution.rs @@ -20,7 +20,8 @@ use blockifier::transaction::objects::{ use blockifier::transaction::transaction_types::TransactionType; use blockifier::transaction::transaction_utils::{update_remaining_gas, verify_no_calls_to_other_contracts}; use blockifier::transaction::transactions::{ - DeclareTransaction, DeployTransaction, DeployAccountTransaction, Executable, InvokeTransaction, L1HandlerTransaction, + DeclareTransaction, DeployAccountTransaction, DeployTransaction, Executable, InvokeTransaction, + L1HandlerTransaction, }; use mp_fee::{calculate_tx_fee, charge_fee, compute_transaction_resources}; use mp_felt::Felt252Wrapper;