diff --git a/crates/blockifier/src/execution/syscalls/hint_processor.rs b/crates/blockifier/src/execution/syscalls/hint_processor.rs index 2f99a2f884..c72eab6caa 100644 --- a/crates/blockifier/src/execution/syscalls/hint_processor.rs +++ b/crates/blockifier/src/execution/syscalls/hint_processor.rs @@ -469,7 +469,7 @@ impl<'a> SyscallHintProcessor<'a> { let l1_data_gas_as_felt = Felt::from_hex(L1_DATA_GAS).map_err(SyscallExecutionError::from)?; - let flat_resource_bounds = match tx_info.resource_bounds { + let flat_resource_bounds = match &tx_info.resource_bounds { starknet_api::transaction::ValidResourceBounds::L1Gas(l1_bounds) => { vec![ l1_gas_as_felt, @@ -480,21 +480,17 @@ impl<'a> SyscallHintProcessor<'a> { Felt::ZERO, ] } - starknet_api::transaction::ValidResourceBounds::AllResources { - l1_gas, - l2_gas, - l1_data_gas, - } => { + starknet_api::transaction::ValidResourceBounds::AllResources(resources) => { vec![ l1_gas_as_felt, - Felt::from(l1_gas.max_amount), - Felt::from(l1_gas.max_price_per_unit), + Felt::from(resources.l1_gas.max_amount), + Felt::from(resources.l1_gas.max_price_per_unit), l2_gas_as_felt, - Felt::from(l2_gas.max_amount), - Felt::from(l2_gas.max_price_per_unit), + Felt::from(resources.l2_gas.max_amount), + Felt::from(resources.l2_gas.max_price_per_unit), l1_data_gas_as_felt, - Felt::from(l1_data_gas.max_amount), - Felt::from(l1_data_gas.max_price_per_unit), + Felt::from(resources.l1_data_gas.max_amount), + Felt::from(resources.l1_data_gas.max_price_per_unit), ] } }; diff --git a/crates/papyrus_common/src/transaction_hash.rs b/crates/papyrus_common/src/transaction_hash.rs index 5c7c14dc67..1e3accc4b0 100644 --- a/crates/papyrus_common/src/transaction_hash.rs +++ b/crates/papyrus_common/src/transaction_hash.rs @@ -224,7 +224,9 @@ fn get_tip_resource_bounds_hash( ) -> Result { let (l1_resource_bounds, l2_resource_bounds) = match resource_bounds { ValidResourceBounds::L1Gas(l1_gas_bounds) => (l1_gas_bounds, &ResourceBounds::default()), - ValidResourceBounds::AllResources { l1_gas, l2_gas, .. } => (l1_gas, l2_gas), + ValidResourceBounds::AllResources(all_resources) => { + (&all_resources.l1_gas, &all_resources.l2_gas) + } }; let l1_resource = get_concat_resource(l1_resource_bounds, L1_GAS)?; diff --git a/crates/papyrus_storage/src/serialization/serializers.rs b/crates/papyrus_storage/src/serialization/serializers.rs index 6e5751ddd6..e1b8ce8540 100644 --- a/crates/papyrus_storage/src/serialization/serializers.rs +++ b/crates/papyrus_storage/src/serialization/serializers.rs @@ -76,6 +76,7 @@ use starknet_api::state::{ }; use starknet_api::transaction::{ AccountDeploymentData, + AllResourcesBounds, Calldata, ContractAddressSalt, DeclareTransaction, @@ -148,6 +149,11 @@ const COMPRESSION_THRESHOLD_BYTES: usize = 384; auto_storage_serde! { pub struct AccountDeploymentData(pub Vec); + pub struct AllResourcesBounds { + pub l1_gas: ResourceBounds, + pub l2_gas: ResourceBounds, + pub l1_data_gas: ResourceBounds, + } pub struct BlockHash(pub StarkHash); pub struct StorageBlockHeader { pub block_hash: BlockHash, @@ -420,6 +426,10 @@ auto_storage_serde! { } pub struct TransactionSignature(pub Vec); pub struct TransactionVersion(pub Felt); + pub enum ValidResourceBounds { + L1Gas(ResourceBounds) = 0, + AllResources(AllResourcesBounds) = 1, + } pub struct Version{ pub major: u32, pub minor: u32, diff --git a/crates/papyrus_test_utils/src/lib.rs b/crates/papyrus_test_utils/src/lib.rs index 48ac9481c1..7943f57e85 100644 --- a/crates/papyrus_test_utils/src/lib.rs +++ b/crates/papyrus_test_utils/src/lib.rs @@ -99,6 +99,7 @@ use starknet_api::state::{ }; use starknet_api::transaction::{ AccountDeploymentData, + AllResourcesBounds, Calldata, ContractAddressSalt, DeclareTransaction, @@ -421,6 +422,11 @@ pub trait GetTestInstance: Sized { auto_impl_get_test_instance! { pub struct AccountDeploymentData(pub Vec); + pub struct AllResourcesBounds { + pub l1_gas: ResourceBounds, + pub l2_gas: ResourceBounds, + pub l1_data_gas: ResourceBounds, + } pub struct BlockHash(pub StarkHash); pub struct BlockHeader { pub block_hash: BlockHash, @@ -785,6 +791,11 @@ auto_impl_get_test_instance! { pub r#type: String, } + pub enum ValidResourceBounds { + L1Gas(ResourceBounds) = 0, + AllResources(AllResourcesBounds) = 1, + } + pub struct CasmContractClass { pub prime: BigUint, pub compiler_version: String, diff --git a/crates/starknet_api/src/transaction.rs b/crates/starknet_api/src/transaction.rs index b57e0dcbf9..0d3d751d68 100644 --- a/crates/starknet_api/src/transaction.rs +++ b/crates/starknet_api/src/transaction.rs @@ -955,7 +955,14 @@ impl TryFrom> for DeprecatedResourceBoundsMappin #[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] pub enum ValidResourceBounds { L1Gas(ResourceBounds), // Pre 0.13.3. L2 bounds are signed but never used. - AllResources { l1_gas: ResourceBounds, l2_gas: ResourceBounds, l1_data_gas: ResourceBounds }, + AllResources(AllResourcesBounds), +} + +#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)] +pub struct AllResourcesBounds { + pub l1_gas: ResourceBounds, + pub l2_gas: ResourceBounds, + pub l1_data_gas: ResourceBounds, } /// Deserializes raw resource bounds, given as map, into valid resource bounds. @@ -979,10 +986,10 @@ impl Serialize for ValidResourceBounds { (Resource::L1Gas, *l1_gas), (Resource::L2Gas, ResourceBounds::default()), ]), - ValidResourceBounds::AllResources { l1_gas, l2_gas, l1_data_gas } => BTreeMap::from([ - (Resource::L1Gas, *l1_gas), - (Resource::L2Gas, *l2_gas), - (Resource::L1DataGas, *l1_data_gas), + ValidResourceBounds::AllResources(all_resources) => BTreeMap::from([ + (Resource::L1Gas, all_resources.l1_gas), + (Resource::L2Gas, all_resources.l2_gas), + (Resource::L1DataGas, all_resources.l1_data_gas), ]), }; DeprecatedResourceBoundsMapping(map).serialize(s) @@ -998,11 +1005,11 @@ impl TryFrom> for ValidResourceBounds { (raw_resource_bounds.get(&Resource::L1Gas), raw_resource_bounds.get(&Resource::L2Gas)) { match raw_resource_bounds.get(&Resource::L1DataGas) { - Some(data_bounds) => Ok(Self::AllResources { + Some(data_bounds) => Ok(Self::AllResources(AllResourcesBounds { l1_gas: *l1_bounds, l1_data_gas: *data_bounds, l2_gas: *l2_bounds, - }), + })), None => { if l2_bounds.is_zero() { Ok(Self::L1Gas(*l1_bounds)) diff --git a/crates/starknet_api/src/transaction_hash.rs b/crates/starknet_api/src/transaction_hash.rs index dc8fc2da0c..d0046acd25 100644 --- a/crates/starknet_api/src/transaction_hash.rs +++ b/crates/starknet_api/src/transaction_hash.rs @@ -179,7 +179,9 @@ fn get_tip_resource_bounds_hash( ) -> Result { let (l1_resource_bounds, l2_resource_bounds) = match resource_bounds { ValidResourceBounds::L1Gas(l1_gas_bounds) => (l1_gas_bounds, &ResourceBounds::default()), - ValidResourceBounds::AllResources { l1_gas, l2_gas, .. } => (l1_gas, l2_gas), + ValidResourceBounds::AllResources(all_resources) => { + (&all_resources.l1_gas, &all_resources.l2_gas) + } }; let l1_resource = get_concat_resource(l1_resource_bounds, L1_GAS)?;