Skip to content

Commit

Permalink
revert(blockifier): remove redundant blockifier transactions and rela…
Browse files Browse the repository at this point in the history
…ted fns
  • Loading branch information
avivg-starkware committed Nov 5, 2024
1 parent d790045 commit 6b00f8d
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 541 deletions.
71 changes: 0 additions & 71 deletions crates/blockifier/src/execution/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ use crate::execution::errors::{ContractClassError, PreExecutionError};
use crate::execution::execution_utils::{poseidon_hash_many_cost, sn_api_to_cairo_vm_program};
#[cfg(feature = "cairo_native")]
use crate::execution::native::contract_class::NativeContractClassV1;
use crate::fee::eth_gas_constants;
use crate::transaction::errors::TransactionExecutionError;
use crate::versioned_constants::CompilerVersion;

Expand Down Expand Up @@ -521,76 +520,6 @@ fn convert_entry_points_v1(external: &[CasmContractEntryPoint]) -> Vec<EntryPoin
.collect()
}

#[derive(Clone, Debug)]
// TODO(Ayelet,10/02/2024): Change to bytes.
pub struct ClassInfo {
contract_class: ContractClass,
sierra_program_length: usize,
abi_length: usize,
}

impl TryFrom<starknet_api::contract_class::ClassInfo> for ClassInfo {
type Error = ProgramError;

fn try_from(class_info: starknet_api::contract_class::ClassInfo) -> Result<Self, Self::Error> {
let starknet_api::contract_class::ClassInfo {
contract_class,
sierra_program_length,
abi_length,
} = class_info;

Ok(Self { contract_class: contract_class.clone(), sierra_program_length, abi_length })
}
}

impl ClassInfo {
pub fn bytecode_length(&self) -> usize {
match &self.contract_class {
ContractClass::V0(contract_class) => contract_class.bytecode_length(),
ContractClass::V1(contract_class) => contract_class.bytecode.len(),
}
}

pub fn contract_class(&self) -> ContractClass {
self.contract_class.clone()
}

pub fn sierra_program_length(&self) -> usize {
self.sierra_program_length
}

pub fn abi_length(&self) -> usize {
self.abi_length
}

pub fn code_size(&self) -> usize {
(self.bytecode_length() + self.sierra_program_length())
// We assume each felt is a word.
* eth_gas_constants::WORD_WIDTH
+ self.abi_length()
}

pub fn new(
contract_class: &ContractClass,
sierra_program_length: usize,
abi_length: usize,
) -> ContractClassResult<Self> {
let (contract_class_version, condition) = match contract_class {
ContractClass::V0(_) => (0, sierra_program_length == 0),
ContractClass::V1(_) => (1, sierra_program_length > 0),
};

if condition {
Ok(Self { contract_class: contract_class.clone(), sierra_program_length, abi_length })
} else {
Err(ContractClassError::ContractClassVersionSierraProgramLengthMismatch {
contract_class_version,
sierra_program_length,
})
}
}
}

// TODO(Yoni): organize this file.
#[derive(Clone, Debug, Default, Eq, PartialEq)]
/// Modelled after [cairo_lang_starknet_classes::contract_class::ContractEntryPoints].
Expand Down
25 changes: 1 addition & 24 deletions crates/blockifier/src/transaction/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ use starknet_api::transaction::{
ContractAddressSalt,
Fee,
GasVectorComputationMode,
InvokeTransactionV0,
InvokeTransactionV1,
InvokeTransactionV3,
ResourceBounds,
TransactionHash,
TransactionSignature,
TransactionVersion,
ValidResourceBounds,
Expand Down Expand Up @@ -50,7 +46,7 @@ use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::constants;
use crate::transaction::objects::{FeeType, TransactionExecutionInfo, TransactionExecutionResult};
use crate::transaction::transaction_types::TransactionType;
use crate::transaction::transactions::{ExecutableTransaction, InvokeTransaction};
use crate::transaction::transactions::ExecutableTransaction;

// Corresponding constants to the ones in faulty_account.
pub const VALID: u64 = 0;
Expand All @@ -62,25 +58,6 @@ pub const GET_BLOCK_NUMBER: u64 = 5;
pub const GET_BLOCK_TIMESTAMP: u64 = 6;
pub const GET_SEQUENCER_ADDRESS: u64 = 7;

macro_rules! impl_from_versioned_tx {
($(($specified_tx_type:ty, $enum_variant:ident)),*) => {
$(impl From<$specified_tx_type> for InvokeTransaction {
fn from(tx: $specified_tx_type) -> Self {
Self::new(
starknet_api::transaction::InvokeTransaction::$enum_variant(tx),
TransactionHash::default(),
)
}
})*
};
}

impl_from_versioned_tx!(
(InvokeTransactionV0, V0),
(InvokeTransactionV1, V1),
(InvokeTransactionV3, V3)
);

/// Test fixtures.
#[fixture]
Expand Down
Loading

0 comments on commit 6b00f8d

Please sign in to comment.