diff --git a/crates/blockifier/src/transaction/objects.rs b/crates/blockifier/src/transaction/objects.rs index f3a7ed7cf4..83f2618a23 100644 --- a/crates/blockifier/src/transaction/objects.rs +++ b/crates/blockifier/src/transaction/objects.rs @@ -212,7 +212,7 @@ pub trait HasRelatedFeeType { fn is_l1_handler(&self) -> bool; fn fee_type(&self) -> FeeType { - if self.is_l1_handler() || self.version() < TransactionVersion::THREE { + if self.is_l1_handler() || self.version().base_lt(&TransactionVersion::THREE) { FeeType::Eth } else { FeeType::Strk diff --git a/crates/blockifier/src/transaction/transactions.rs b/crates/blockifier/src/transaction/transactions.rs index 56785195e5..e5a756516f 100644 --- a/crates/blockifier/src/transaction/transactions.rs +++ b/crates/blockifier/src/transaction/transactions.rs @@ -154,13 +154,13 @@ impl DeclareTransaction { let declare_version = declare_tx.version(); // Verify contract class version. if !is_cairo1(&class_info.contract_class()) { - if declare_version > TransactionVersion::ONE { + if declare_version.base_gt(&TransactionVersion::ONE) { Err(TransactionExecutionError::ContractClassVersionMismatch { declare_version, cairo_version: 0, })? } - } else if declare_version <= TransactionVersion::ONE { + } else if declare_version.base_le(&TransactionVersion::ONE) { Err(TransactionExecutionError::ContractClassVersionMismatch { declare_version, cairo_version: 1, diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index e00a8ad3b0..cd89fa0171 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -1417,7 +1417,7 @@ fn test_declare_tx( account .get_class() .tracked_resource(&versioned_constants.min_compiler_version_for_sierra_gas), - if tx_version >= TransactionVersion::THREE { + if tx_version.base_ge(&TransactionVersion::THREE) { user_initial_gas_from_bounds(default_l1_resource_bounds) } else { None diff --git a/crates/papyrus_rpc/src/v0_8/block.rs b/crates/papyrus_rpc/src/v0_8/block.rs index 2659535a3b..700fb96806 100644 --- a/crates/papyrus_rpc/src/v0_8/block.rs +++ b/crates/papyrus_rpc/src/v0_8/block.rs @@ -80,7 +80,7 @@ pub struct ResourcePrice { pub price_in_fri: GasPrice, } -#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)] pub struct Block { #[serde(skip_serializing_if = "Option::is_none")] pub status: Option, diff --git a/crates/papyrus_rpc/src/v0_8/transaction.rs b/crates/papyrus_rpc/src/v0_8/transaction.rs index 769fc50a0e..d4fbc2c1e0 100644 --- a/crates/papyrus_rpc/src/v0_8/transaction.rs +++ b/crates/papyrus_rpc/src/v0_8/transaction.rs @@ -95,7 +95,7 @@ pub enum TransactionVersion3 { Version3OnlyQuery, } -#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)] #[serde(untagged)] pub enum Transactions { Hashes(Vec), @@ -533,20 +533,20 @@ impl TryFrom for InvokeTransaction } } -#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)] pub struct TransactionWithHash { pub transaction_hash: TransactionHash, #[serde(flatten)] pub transaction: Transaction, } -#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)] pub struct TransactionWithReceipt { pub receipt: TransactionReceiptInBlock, pub transaction: Transaction, } -#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] #[serde(tag = "type")] pub enum Transaction { #[serde(rename = "DECLARE")] diff --git a/crates/starknet_api/src/transaction.rs b/crates/starknet_api/src/transaction.rs index 7a88857833..17051b061e 100644 --- a/crates/starknet_api/src/transaction.rs +++ b/crates/starknet_api/src/transaction.rs @@ -59,7 +59,7 @@ pub struct FullTransaction { } /// A transaction. -#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)] pub enum Transaction { /// A declare transaction. Declare(DeclareTransaction), @@ -456,7 +456,7 @@ impl TransactionHasher for DeployAccountTransaction { } /// A deploy transaction. -#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize)] pub struct DeployTransaction { pub version: TransactionVersion, pub class_hash: ClassHash, @@ -618,7 +618,7 @@ impl TransactionHasher for InvokeTransaction { } /// An L1 handler transaction. -#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize)] pub struct L1HandlerTransaction { pub version: TransactionVersion, pub nonce: Nonce, @@ -831,18 +831,7 @@ pub struct TransactionSignature(pub Vec); /// A transaction version. #[derive( - Debug, - Copy, - Clone, - Default, - Eq, - PartialEq, - Hash, - Deserialize, - Serialize, - PartialOrd, - Ord, - derive_more::Deref, + Debug, Copy, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, derive_more::Deref, )] pub struct TransactionVersion(pub Felt); @@ -858,6 +847,28 @@ impl TransactionVersion { /// [TransactionVersion] constant that's equal to 3. pub const THREE: Self = { Self(Felt::THREE) }; + + fn without_query_bit(&self) -> Self { + let mut self_biguint = self.0.to_biguint(); + self_biguint.set_bit(QUERY_VERSION_BASE_BIT.into(), false); + Self(self_biguint.into()) + } + + pub fn base_le(&self, other: &Self) -> bool { + self.without_query_bit().0 <= other.without_query_bit().0 + } + + pub fn base_lt(&self, other: &Self) -> bool { + self.without_query_bit().0 < other.without_query_bit().0 + } + + pub fn base_ge(&self, other: &Self) -> bool { + !self.base_lt(other) + } + + pub fn base_gt(&self, other: &Self) -> bool { + !self.base_le(other) + } } // TODO: TransactionVersion and SignedTransactionVersion should probably be separate types. diff --git a/crates/starknet_client/src/reader/objects/transaction.rs b/crates/starknet_client/src/reader/objects/transaction.rs index aa1cdd5f37..a8e7b53fa8 100644 --- a/crates/starknet_client/src/reader/objects/transaction.rs +++ b/crates/starknet_client/src/reader/objects/transaction.rs @@ -135,7 +135,7 @@ impl Transaction { } } -#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)] +#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Deserialize, Serialize)] #[serde(deny_unknown_fields)] pub struct L1HandlerTransaction { pub transaction_hash: TransactionHash,