Skip to content

Commit

Permalink
build(fee): tx_args holds valid resource bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrod-starkware committed Aug 20, 2024
1 parent 4c6cf77 commit 70c9eb0
Show file tree
Hide file tree
Showing 20 changed files with 179 additions and 53 deletions.
2 changes: 1 addition & 1 deletion crates/blockifier/src/test_utils/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub fn declare_tx(declare_tx_args: DeclareTxArgs, class_info: ClassInfo) -> Acco
starknet_api::transaction::DeclareTransaction::V3(DeclareTransactionV3 {
signature: declare_tx_args.signature,
sender_address: declare_tx_args.sender_address,
resource_bounds: declare_tx_args.resource_bounds,
resource_bounds: declare_tx_args.resource_bounds.try_into().expect("todo"),
tip: declare_tx_args.tip,
nonce_data_availability_mode: declare_tx_args.nonce_data_availability_mode,
fee_data_availability_mode: declare_tx_args.fee_data_availability_mode,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/test_utils/deploy_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn deploy_account_tx(
} else if deploy_tx_args.version == TransactionVersion::THREE {
starknet_api::transaction::DeployAccountTransaction::V3(DeployAccountTransactionV3 {
signature: deploy_tx_args.signature,
resource_bounds: deploy_tx_args.resource_bounds,
resource_bounds: deploy_tx_args.resource_bounds.try_into().expect("todo"),
tip: deploy_tx_args.tip,
nonce_data_availability_mode: deploy_tx_args.nonce_data_availability_mode,
fee_data_availability_mode: deploy_tx_args.fee_data_availability_mode,
Expand Down
2 changes: 1 addition & 1 deletion crates/blockifier/src/test_utils/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn invoke_tx(invoke_args: InvokeTxArgs) -> InvokeTransaction {
})
} else if invoke_args.version == TransactionVersion::THREE {
starknet_api::transaction::InvokeTransaction::V3(InvokeTransactionV3 {
resource_bounds: invoke_args.resource_bounds,
resource_bounds: invoke_args.resource_bounds.try_into().expect("todo"),
calldata: invoke_args.calldata,
sender_address: invoke_args.sender_address,
nonce: invoke_args.nonce,
Expand Down
6 changes: 3 additions & 3 deletions crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl TransactionInfoCreator for DeclareTransaction {
starknet_api::transaction::DeclareTransaction::V3(tx) => {
Ok(TransactionInfo::Current(CurrentTransactionInfo {
common_fields,
resource_bounds: tx.resource_bounds.clone().try_into()?,
resource_bounds: tx.resource_bounds.clone(),
tip: tx.tip,
nonce_data_availability_mode: tx.nonce_data_availability_mode,
fee_data_availability_mode: tx.fee_data_availability_mode,
Expand Down Expand Up @@ -411,7 +411,7 @@ impl TransactionInfoCreator for DeployAccountTransaction {
starknet_api::transaction::DeployAccountTransaction::V3(tx) => {
Ok(TransactionInfo::Current(CurrentTransactionInfo {
common_fields,
resource_bounds: tx.resource_bounds.clone().try_into()?,
resource_bounds: tx.resource_bounds.clone(),
tip: tx.tip,
nonce_data_availability_mode: tx.nonce_data_availability_mode,
fee_data_availability_mode: tx.fee_data_availability_mode,
Expand Down Expand Up @@ -535,7 +535,7 @@ impl TransactionInfoCreator for InvokeTransaction {
starknet_api::transaction::InvokeTransaction::V3(tx) => {
Ok(TransactionInfo::Current(CurrentTransactionInfo {
common_fields,
resource_bounds: tx.resource_bounds.clone().try_into()?,
resource_bounds: tx.resource_bounds.clone(),
tip: tx.tip,
nonce_data_availability_mode: tx.nonce_data_availability_mode,
fee_data_availability_mode: tx.fee_data_availability_mode,
Expand Down
4 changes: 2 additions & 2 deletions crates/mempool_test_utils/src/starknet_api_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ use starknet_api::transaction::{
AccountDeploymentData,
Calldata,
ContractAddressSalt,
DeprecatedResourceBoundsMapping as ExecutableResourceBoundsMapping,
PaymasterData,
ResourceBounds,
Tip,
TransactionHash,
TransactionSignature,
TransactionVersion,
ValidResourceBounds,
};
use starknet_api::{calldata, felt};
use starknet_types_core::felt::Felt;
Expand Down Expand Up @@ -554,7 +554,7 @@ pub fn create_executable_tx(
sender_address,
tip,
nonce,
resource_bounds: ExecutableResourceBoundsMapping::default(),
resource_bounds: ValidResourceBounds::L1Gas(ResourceBounds::default()),
signature: TransactionSignature::default(),
calldata: Calldata::default(),
nonce_data_availability_mode: DataAvailabilityMode::L1,
Expand Down
3 changes: 1 addition & 2 deletions crates/native_blockifier/src/py_declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use starknet_api::transaction::{
DeclareTransactionV0V1,
DeclareTransactionV2,
DeclareTransactionV3,
DeprecatedResourceBoundsMapping,
Fee,
PaymasterData,
Tip,
Expand Down Expand Up @@ -88,7 +87,7 @@ impl TryFrom<PyDeclareTransactionV3> for DeclareTransactionV3 {
type Error = NativeBlockifierInputError;
fn try_from(tx: PyDeclareTransactionV3) -> Result<Self, Self::Error> {
Ok(Self {
resource_bounds: DeprecatedResourceBoundsMapping::try_from(tx.resource_bounds)?,
resource_bounds: tx.resource_bounds.try_into()?,
tip: Tip(tx.tip),
signature: TransactionSignature(from_py_felts(tx.signature)),
nonce: Nonce(tx.nonce.0),
Expand Down
3 changes: 1 addition & 2 deletions crates/native_blockifier/src/py_deploy_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use starknet_api::transaction::{
ContractAddressSalt,
DeployAccountTransactionV1,
DeployAccountTransactionV3,
DeprecatedResourceBoundsMapping,
Fee,
PaymasterData,
Tip,
Expand Down Expand Up @@ -64,7 +63,7 @@ impl TryFrom<PyDeployAccountTransactionV3> for DeployAccountTransactionV3 {
type Error = NativeBlockifierInputError;
fn try_from(tx: PyDeployAccountTransactionV3) -> Result<Self, Self::Error> {
Ok(Self {
resource_bounds: DeprecatedResourceBoundsMapping::try_from(tx.resource_bounds)?,
resource_bounds: tx.resource_bounds.try_into()?,
tip: Tip(tx.tip),
signature: TransactionSignature(from_py_felts(tx.signature)),
nonce: Nonce(tx.nonce.0),
Expand Down
3 changes: 1 addition & 2 deletions crates/native_blockifier/src/py_invoke_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use starknet_api::data_availability::DataAvailabilityMode;
use starknet_api::transaction::{
AccountDeploymentData,
Calldata,
DeprecatedResourceBoundsMapping,
Fee,
InvokeTransactionV0,
InvokeTransactionV1,
Expand Down Expand Up @@ -87,7 +86,7 @@ impl TryFrom<PyInvokeTransactionV3> for InvokeTransactionV3 {
type Error = NativeBlockifierInputError;
fn try_from(tx: PyInvokeTransactionV3) -> Result<Self, Self::Error> {
Ok(Self {
resource_bounds: DeprecatedResourceBoundsMapping::try_from(tx.resource_bounds)?,
resource_bounds: tx.resource_bounds.try_into()?,
tip: Tip(tx.tip),
signature: TransactionSignature(from_py_felts(tx.signature)),
nonce: Nonce(tx.nonce.0),
Expand Down
14 changes: 13 additions & 1 deletion crates/native_blockifier/src/py_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ use blockifier::transaction::transaction_execution::Transaction;
use blockifier::transaction::transaction_types::TransactionType;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use starknet_api::transaction::{Resource, ResourceBounds};
use starknet_api::transaction::{
DeprecatedResourceBoundsMapping,
Resource,
ResourceBounds,
ValidResourceBounds,
};
use starknet_api::StarknetApiError;

use crate::errors::{NativeBlockifierInputError, NativeBlockifierResult};
Expand Down Expand Up @@ -84,6 +89,13 @@ impl TryFrom<PyResourceBoundsMapping>
}
}

impl TryFrom<PyResourceBoundsMapping> for ValidResourceBounds {
type Error = StarknetApiError;
fn try_from(py_resource_bounds_mapping: PyResourceBoundsMapping) -> Result<Self, Self::Error> {
DeprecatedResourceBoundsMapping::try_from(py_resource_bounds_mapping)?.try_into()
}
}

#[derive(Clone)]
pub enum PyDataAvailabilityMode {
L1 = 0,
Expand Down
18 changes: 10 additions & 8 deletions crates/papyrus_common/src/transaction_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use starknet_api::core::{calculate_contract_address, ChainId, ContractAddress};
use starknet_api::data_availability::DataAvailabilityMode;
use starknet_api::hash::StarkHash;
use starknet_api::transaction::{
AllResourceBounds,
DeclareTransaction,
DeclareTransactionV0V1,
DeclareTransactionV2,
Expand All @@ -16,18 +17,17 @@ use starknet_api::transaction::{
DeployAccountTransactionV1,
DeployAccountTransactionV3,
DeployTransaction,
DeprecatedResourceBoundsMapping,
InvokeTransaction,
InvokeTransactionV0,
InvokeTransactionV1,
InvokeTransactionV3,
L1HandlerTransaction,
Resource,
ResourceBounds,
Tip,
Transaction,
TransactionHash,
TransactionVersion,
ValidResourceBounds,
};
use starknet_api::StarknetApiError;
use starknet_types_core::felt::Felt;
Expand Down Expand Up @@ -220,15 +220,17 @@ pub(crate) fn ascii_as_felt(ascii_str: &str) -> Result<Felt, StarknetApiError> {

// An implementation of the SNIP: https://github.com/EvyatarO/SNIPs/blob/snip-8/SNIPS/snip-8.md
fn get_tip_resource_bounds_hash(
resource_bounds_mapping: &DeprecatedResourceBoundsMapping,
resource_bounds: &ValidResourceBounds,
tip: &Tip,
) -> Result<Felt, StarknetApiError> {
let l1_resource_bounds =
resource_bounds_mapping.0.get(&Resource::L1Gas).expect("Missing l1 resource");
let l1_resource = get_concat_resource(l1_resource_bounds, L1_GAS)?;
let (l1_resource_bounds, l2_resource_bounds) = match resource_bounds {
ValidResourceBounds::L1Gas(l1_gas_bounds) => (l1_gas_bounds, &ResourceBounds::default()),
ValidResourceBounds::AllResources(AllResourceBounds { l1_gas, l2_gas, .. }) => {
(l1_gas, l2_gas)
}
};

let l2_resource_bounds =
resource_bounds_mapping.0.get(&Resource::L2Gas).expect("Missing l2 resource");
let l1_resource = get_concat_resource(l1_resource_bounds, L1_GAS)?;
let l2_resource = get_concat_resource(l2_resource_bounds, L2_GAS)?;

Ok(HashChain::new()
Expand Down
17 changes: 17 additions & 0 deletions crates/papyrus_rpc/src/v0_6/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ impl From<ResourceBoundsMapping> for starknet_api::transaction::DeprecatedResour
}
}

impl From<ResourceBoundsMapping> for starknet_api::transaction::ValidResourceBounds {
fn from(value: ResourceBoundsMapping) -> Self {
Self::L1Gas(value.l1_gas)
}
}

impl From<starknet_api::transaction::ValidResourceBounds> for ResourceBoundsMapping {
fn from(value: starknet_api::transaction::ValidResourceBounds) -> Self {
match value {
starknet_api::transaction::ValidResourceBounds::L1Gas(l1_gas) => {
Self { l1_gas, l2_gas: ResourceBounds::default() }
}
starknet_api::transaction::ValidResourceBounds::AllResources(_) => todo!(),
}
}
}

impl From<starknet_api::transaction::DeprecatedResourceBoundsMapping> for ResourceBoundsMapping {
fn from(value: starknet_api::transaction::DeprecatedResourceBoundsMapping) -> Self {
Self {
Expand Down
17 changes: 17 additions & 0 deletions crates/papyrus_rpc/src/v0_7/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,23 @@ impl From<starknet_api::transaction::DeprecatedResourceBoundsMapping> for Resour
}
}

impl From<ResourceBoundsMapping> for starknet_api::transaction::ValidResourceBounds {
fn from(value: ResourceBoundsMapping) -> Self {
Self::L1Gas(value.l1_gas)
}
}

impl From<starknet_api::transaction::ValidResourceBounds> for ResourceBoundsMapping {
fn from(value: starknet_api::transaction::ValidResourceBounds) -> Self {
match value {
starknet_api::transaction::ValidResourceBounds::L1Gas(l1_gas) => {
Self { l1_gas, l2_gas: ResourceBounds::default() }
}
starknet_api::transaction::ValidResourceBounds::AllResources(_) => todo!(),
}
}
}

#[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
pub struct DeclareTransactionV3 {
pub resource_bounds: ResourceBoundsMapping,
Expand Down
17 changes: 14 additions & 3 deletions crates/papyrus_storage/src/serialization/serializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ use starknet_api::state::{
};
use starknet_api::transaction::{
AccountDeploymentData,
AllResourceBounds,
Calldata,
ContractAddressSalt,
DeclareTransaction,
Expand Down Expand Up @@ -119,6 +120,7 @@ use starknet_api::transaction::{
TransactionOutput,
TransactionSignature,
TransactionVersion,
ValidResourceBounds,
};
use starknet_types_core::felt::Felt;
use tracing::warn;
Expand Down Expand Up @@ -147,6 +149,11 @@ const COMPRESSION_THRESHOLD_BYTES: usize = 384;

auto_storage_serde! {
pub struct AccountDeploymentData(pub Vec<Felt>);
pub struct AllResourceBounds {
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,
Expand Down Expand Up @@ -211,7 +218,7 @@ auto_storage_serde! {
pub sender_address: ContractAddress,
}
pub struct DeclareTransactionV3 {
pub resource_bounds: DeprecatedResourceBoundsMapping,
pub resource_bounds: ValidResourceBounds,
pub tip: Tip,
pub signature: TransactionSignature,
pub nonce: Nonce,
Expand Down Expand Up @@ -419,6 +426,10 @@ auto_storage_serde! {
}
pub struct TransactionSignature(pub Vec<Felt>);
pub struct TransactionVersion(pub Felt);
pub enum ValidResourceBounds {
L1Gas(ResourceBounds) = 0,
AllResources(AllResourceBounds) = 1,
}
pub struct Version{
pub major: u32,
pub minor: u32,
Expand Down Expand Up @@ -1162,7 +1173,7 @@ auto_storage_serde_conditionally_compressed! {
}

pub struct DeployAccountTransactionV3 {
pub resource_bounds: DeprecatedResourceBoundsMapping,
pub resource_bounds: ValidResourceBounds,
pub tip: Tip,
pub signature: TransactionSignature,
pub nonce: Nonce,
Expand Down Expand Up @@ -1198,7 +1209,7 @@ auto_storage_serde_conditionally_compressed! {
}

pub struct InvokeTransactionV3 {
pub resource_bounds: DeprecatedResourceBoundsMapping,
pub resource_bounds: ValidResourceBounds,
pub tip: Tip,
pub signature: TransactionSignature,
pub nonce: Nonce,
Expand Down
18 changes: 15 additions & 3 deletions crates/papyrus_test_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ use starknet_api::state::{
};
use starknet_api::transaction::{
AccountDeploymentData,
AllResourceBounds,
Calldata,
ContractAddressSalt,
DeclareTransaction,
Expand Down Expand Up @@ -142,6 +143,7 @@ use starknet_api::transaction::{
TransactionOutput,
TransactionSignature,
TransactionVersion,
ValidResourceBounds,
};
use starknet_types_core::felt::Felt;

Expand Down Expand Up @@ -420,6 +422,11 @@ pub trait GetTestInstance: Sized {

auto_impl_get_test_instance! {
pub struct AccountDeploymentData(pub Vec<Felt>);
pub struct AllResourceBounds {
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,
Expand Down Expand Up @@ -517,7 +524,7 @@ auto_impl_get_test_instance! {
pub sender_address: ContractAddress,
}
pub struct DeclareTransactionV3 {
pub resource_bounds: DeprecatedResourceBoundsMapping,
pub resource_bounds: ValidResourceBounds,
pub tip: Tip,
pub signature: TransactionSignature,
pub nonce: Nonce,
Expand Down Expand Up @@ -550,7 +557,7 @@ auto_impl_get_test_instance! {
pub constructor_calldata: Calldata,
}
pub struct DeployAccountTransactionV3 {
pub resource_bounds: DeprecatedResourceBoundsMapping,
pub resource_bounds: ValidResourceBounds,
pub tip: Tip,
pub signature: TransactionSignature,
pub nonce: Nonce,
Expand Down Expand Up @@ -657,7 +664,7 @@ auto_impl_get_test_instance! {
pub calldata: Calldata,
}
pub struct InvokeTransactionV3 {
pub resource_bounds: DeprecatedResourceBoundsMapping,
pub resource_bounds: ValidResourceBounds,
pub tip: Tip,
pub signature: TransactionSignature,
pub nonce: Nonce,
Expand Down Expand Up @@ -784,6 +791,11 @@ auto_impl_get_test_instance! {
pub r#type: String,
}

pub enum ValidResourceBounds {
L1Gas(ResourceBounds) = 0,
AllResources(AllResourceBounds) = 1,
}

pub struct CasmContractClass {
pub prime: BigUint,
pub compiler_version: String,
Expand Down
Loading

0 comments on commit 70c9eb0

Please sign in to comment.