From 876b13a48cfcd391bfdc392879fcbf238fbc2aa0 Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Mon, 16 Dec 2024 15:35:47 +0200 Subject: [PATCH] test(starknet_api): set l1 handler tx version to default zero --- crates/blockifier/src/abi/constants.rs | 6 ------ crates/blockifier/src/test_utils/l1_handler.rs | 4 ++-- crates/native_blockifier/src/py_l1_handler.rs | 3 +-- crates/papyrus_protobuf/src/converters/transaction.rs | 3 ++- crates/papyrus_rpc/src/v0_8/execution_test.rs | 3 ++- crates/papyrus_rpc/src/v0_8/transaction.rs | 3 ++- crates/papyrus_rpc/src/v0_8/transaction_test.rs | 5 +++-- crates/starknet_api/src/test_utils/l1_handler.rs | 3 ++- crates/starknet_api/src/transaction/constants.rs | 4 ++++ 9 files changed, 18 insertions(+), 16 deletions(-) diff --git a/crates/blockifier/src/abi/constants.rs b/crates/blockifier/src/abi/constants.rs index ba8ed1e896..7de227f7de 100644 --- a/crates/blockifier/src/abi/constants.rs +++ b/crates/blockifier/src/abi/constants.rs @@ -1,9 +1,3 @@ -use starknet_api::transaction::TransactionVersion; -use starknet_types_core::felt::Felt; - -// The version is considered 0 for L1-Handler transaction hash calculation purposes. -pub const L1_HANDLER_VERSION: TransactionVersion = TransactionVersion(Felt::ZERO); - // OS-related constants. pub const L1_TO_L2_MSG_HEADER_SIZE: usize = 5; pub const L2_TO_L1_MSG_HEADER_SIZE: usize = 3; diff --git a/crates/blockifier/src/test_utils/l1_handler.rs b/crates/blockifier/src/test_utils/l1_handler.rs index a57d08b8b6..0222c120dc 100644 --- a/crates/blockifier/src/test_utils/l1_handler.rs +++ b/crates/blockifier/src/test_utils/l1_handler.rs @@ -3,8 +3,8 @@ use starknet_api::calldata; use starknet_api::core::ContractAddress; use starknet_api::executable_transaction::L1HandlerTransaction; use starknet_api::test_utils::l1_handler::{executable_l1_handler_tx, L1HandlerTxArgs}; +use starknet_api::transaction::constants::L1_HANDLER_VERSION; use starknet_api::transaction::fields::Fee; -use starknet_api::transaction::TransactionVersion; use starknet_types_core::felt::Felt; pub fn l1handler_tx(l1_fee: Fee, contract_address: ContractAddress) -> L1HandlerTransaction { @@ -15,7 +15,7 @@ pub fn l1handler_tx(l1_fee: Fee, contract_address: ContractAddress) -> L1Handler ]; executable_l1_handler_tx(L1HandlerTxArgs { - version: TransactionVersion::ZERO, + version: L1_HANDLER_VERSION, contract_address, entry_point_selector: selector_from_name("l1_handler_set_value"), calldata, diff --git a/crates/native_blockifier/src/py_l1_handler.rs b/crates/native_blockifier/src/py_l1_handler.rs index df90b9642e..9af53c0189 100644 --- a/crates/native_blockifier/src/py_l1_handler.rs +++ b/crates/native_blockifier/src/py_l1_handler.rs @@ -1,11 +1,10 @@ use std::sync::Arc; -use blockifier::abi::constants; use pyo3::prelude::*; use starknet_api::core::{ContractAddress, EntryPointSelector, Nonce}; use starknet_api::executable_transaction::L1HandlerTransaction; use starknet_api::transaction::fields::{Calldata, Fee}; -use starknet_api::transaction::TransactionHash; +use starknet_api::transaction::{constants, TransactionHash}; use crate::errors::{NativeBlockifierInputError, NativeBlockifierResult}; use crate::py_utils::{from_py_felts, py_attr, PyFelt}; diff --git a/crates/papyrus_protobuf/src/converters/transaction.rs b/crates/papyrus_protobuf/src/converters/transaction.rs index 2e43b8ccf6..5232afcfd1 100644 --- a/crates/papyrus_protobuf/src/converters/transaction.rs +++ b/crates/papyrus_protobuf/src/converters/transaction.rs @@ -7,6 +7,7 @@ use prost::Message; use starknet_api::block::GasPrice; use starknet_api::core::{ClassHash, CompiledClassHash, EntryPointSelector, Nonce}; use starknet_api::execution_resources::GasAmount; +use starknet_api::transaction::constants::L1_HANDLER_VERSION; use starknet_api::transaction::fields::{ AccountDeploymentData, AllResourceBounds, @@ -1253,7 +1254,7 @@ impl From for protobuf::transaction::Deploy { impl TryFrom for L1HandlerTransaction { type Error = ProtobufConversionError; fn try_from(value: protobuf::transaction::L1HandlerV0) -> Result { - let version = TransactionVersion(Felt::ZERO); + let version = L1_HANDLER_VERSION; let nonce = Nonce( value diff --git a/crates/papyrus_rpc/src/v0_8/execution_test.rs b/crates/papyrus_rpc/src/v0_8/execution_test.rs index 732525a62f..f11f28d8d1 100644 --- a/crates/papyrus_rpc/src/v0_8/execution_test.rs +++ b/crates/papyrus_rpc/src/v0_8/execution_test.rs @@ -64,6 +64,7 @@ use starknet_api::deprecated_contract_class::ContractClass as SN_API_DeprecatedC use starknet_api::hash::StarkHash; use starknet_api::state::{StorageKey, ThinStateDiff as StarknetApiStateDiff}; use starknet_api::test_utils::{path_in_resources, read_json_file}; +use starknet_api::transaction::constants::L1_HANDLER_VERSION; use starknet_api::transaction::fields::{Calldata, Fee}; use starknet_api::transaction::{ L1HandlerTransaction, @@ -1204,7 +1205,7 @@ async fn pending_trace_block_transactions_and_trace_transaction_execution_contex #[test] fn message_from_l1_to_l1_handler_tx() { let l1_handler_tx = L1HandlerTransaction::from(MESSAGE_FROM_L1.clone()); - assert_eq!(l1_handler_tx.version, TransactionVersion::ONE); + assert_eq!(l1_handler_tx.version, L1_HANDLER_VERSION); assert_eq!(l1_handler_tx.contract_address, *CONTRACT_ADDRESS); assert_eq!(l1_handler_tx.entry_point_selector, selector_from_name("l1_handle")); // The first item of calldata is the from_address. diff --git a/crates/papyrus_rpc/src/v0_8/transaction.rs b/crates/papyrus_rpc/src/v0_8/transaction.rs index 1637542041..6ea8d75b8b 100644 --- a/crates/papyrus_rpc/src/v0_8/transaction.rs +++ b/crates/papyrus_rpc/src/v0_8/transaction.rs @@ -27,6 +27,7 @@ use starknet_api::core::{ use starknet_api::data_availability::DataAvailabilityMode; use starknet_api::execution_resources::GasAmount; use starknet_api::serde_utils::bytes_from_hex_str; +use starknet_api::transaction::constants::L1_HANDLER_VERSION; use starknet_api::transaction::fields::{ AccountDeploymentData, AllResourceBounds, @@ -1281,7 +1282,7 @@ impl From for L1HandlerTransaction { calldata.extend_from_slice(&message.payload.0); let calldata = Calldata(Arc::new(calldata)); Self { - version: TransactionVersion::ONE, + version: L1_HANDLER_VERSION, contract_address: message.to_address, entry_point_selector: message.entry_point_selector, calldata, diff --git a/crates/papyrus_rpc/src/v0_8/transaction_test.rs b/crates/papyrus_rpc/src/v0_8/transaction_test.rs index 965656b6f8..645776169f 100644 --- a/crates/papyrus_rpc/src/v0_8/transaction_test.rs +++ b/crates/papyrus_rpc/src/v0_8/transaction_test.rs @@ -7,6 +7,7 @@ use papyrus_test_utils::{ use pretty_assertions::assert_eq; use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector, Nonce}; use starknet_api::data_availability::DataAvailabilityMode; +use starknet_api::transaction::constants::L1_HANDLER_VERSION; use starknet_api::transaction::fields::{ AccountDeploymentData, Calldata, @@ -16,7 +17,7 @@ use starknet_api::transaction::fields::{ Tip, TransactionSignature, }; -use starknet_api::transaction::{L1HandlerTransaction, Transaction, TransactionVersion}; +use starknet_api::transaction::{L1HandlerTransaction, Transaction}; use starknet_api::{calldata, contract_address, felt, nonce}; use starknet_client::writer::objects::transaction as client_transaction; @@ -38,7 +39,7 @@ use super::{ lazy_static::lazy_static! { // A transaction from MAINNET with tx hash 0x439e12f67962c353182d72b4af12c3f11eaba4b36e552aebcdcd6db66971bdb. static ref L1_HANDLER_TX: L1HandlerTransaction = L1HandlerTransaction { - version: TransactionVersion::ZERO, + version: L1_HANDLER_VERSION, nonce: nonce!(0x18e94d), contract_address: contract_address!( "0x73314940630fd6dcda0d772d4c972c4e0a9946bef9dabf4ef84eda8ef542b82" diff --git a/crates/starknet_api/src/test_utils/l1_handler.rs b/crates/starknet_api/src/test_utils/l1_handler.rs index 0610ac8711..d7daae7e3a 100644 --- a/crates/starknet_api/src/test_utils/l1_handler.rs +++ b/crates/starknet_api/src/test_utils/l1_handler.rs @@ -1,5 +1,6 @@ use crate::core::{ContractAddress, EntryPointSelector, Nonce}; use crate::executable_transaction::L1HandlerTransaction as ExecutableL1HandlerTransaction; +use crate::transaction::constants::L1_HANDLER_VERSION; use crate::transaction::fields::{Calldata, Fee}; use crate::transaction::{L1HandlerTransaction, TransactionHash, TransactionVersion}; @@ -17,7 +18,7 @@ pub struct L1HandlerTxArgs { impl Default for L1HandlerTxArgs { fn default() -> Self { L1HandlerTxArgs { - version: TransactionVersion::THREE, + version: L1_HANDLER_VERSION, nonce: Nonce::default(), contract_address: ContractAddress::default(), entry_point_selector: EntryPointSelector::default(), diff --git a/crates/starknet_api/src/transaction/constants.rs b/crates/starknet_api/src/transaction/constants.rs index 36b013616e..85ac43383a 100644 --- a/crates/starknet_api/src/transaction/constants.rs +++ b/crates/starknet_api/src/transaction/constants.rs @@ -2,8 +2,12 @@ use std::sync::LazyLock; use starknet_types_core::felt::Felt; +use super::TransactionVersion; use crate::core::ascii_as_felt; +// The version is considered 0 for L1-Handler transaction hash calculation purposes. +pub const L1_HANDLER_VERSION: TransactionVersion = TransactionVersion::ZERO; + pub const EXECUTE_ENTRY_POINT_NAME: &str = "__execute__"; pub const TRANSFER_ENTRY_POINT_NAME: &str = "transfer"; pub const VALIDATE_ENTRY_POINT_NAME: &str = "__validate__";