Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoGiachetta committed Dec 10, 2024
1 parent 39b0fb9 commit d19189b
Show file tree
Hide file tree
Showing 313 changed files with 1,345 additions and 3,724 deletions.
4 changes: 1 addition & 3 deletions crates/blockifier/bench/blockifier_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
//! Run the benchmarks using `cargo bench --bench blockifier_bench`.
use blockifier::test_utils::transfers_generator::{
RecipientGeneratorType,
TransfersGenerator,
TransfersGeneratorConfig,
RecipientGeneratorType, TransfersGenerator, TransfersGeneratorConfig,
};
use criterion::{criterion_group, criterion_main, Criterion};

Expand Down
7 changes: 1 addition & 6 deletions crates/blockifier/src/blockifier/block.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use log::warn;
use starknet_api::block::{
BlockHashAndNumber,
BlockNumber,
GasPrice,
GasPriceVector,
GasPrices,
NonzeroGasPrice,
BlockHashAndNumber, BlockNumber, GasPrice, GasPriceVector, GasPrices, NonzeroGasPrice,
};
use starknet_api::state::StorageKey;

Expand Down
4 changes: 1 addition & 3 deletions crates/blockifier/src/blockifier/stateful_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use thiserror::Error;

use crate::blockifier::config::TransactionExecutorConfig;
use crate::blockifier::transaction_executor::{
TransactionExecutor,
TransactionExecutorError,
BLOCK_STATE_ACCESS_ERR,
TransactionExecutor, TransactionExecutorError, BLOCK_STATE_ACCESS_ERR,
};
use crate::context::{BlockContext, TransactionContext};
use crate::execution::call_info::CallInfo;
Expand Down
9 changes: 2 additions & 7 deletions crates/blockifier/src/blockifier/stateful_validator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::{fund_account, test_state};
use crate::test_utils::{CairoVersion, RunnableCairo1, BALANCE};
use crate::transaction::test_utils::{
block_context,
create_account_tx_for_validate_test_nonce_0,
default_all_resource_bounds,
default_l1_resource_bounds,
FaultyAccountTxCreatorArgs,
INVALID,
VALID,
block_context, create_account_tx_for_validate_test_nonce_0, default_all_resource_bounds,
default_l1_resource_bounds, FaultyAccountTxCreatorArgs, INVALID, VALID,
};
use crate::transaction::transaction_types::TransactionType;

Expand Down
18 changes: 4 additions & 14 deletions crates/blockifier/src/blockifier/transaction_executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ use starknet_types_core::felt::Felt;

use crate::blockifier::config::TransactionExecutorConfig;
use crate::blockifier::transaction_executor::{
TransactionExecutor,
TransactionExecutorError,
BLOCK_STATE_ACCESS_ERR,
TransactionExecutor, TransactionExecutorError, BLOCK_STATE_ACCESS_ERR,
};
use crate::bouncer::{Bouncer, BouncerWeights};
use crate::context::BlockContext;
Expand All @@ -24,22 +22,14 @@ use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::l1_handler::l1handler_tx;
use crate::test_utils::{
create_calldata,
maybe_dummy_block_hash_and_number,
CairoVersion,
RunnableCairo1,
BALANCE,
create_calldata, maybe_dummy_block_hash_and_number, CairoVersion, RunnableCairo1, BALANCE,
DEFAULT_STRK_L1_GAS_PRICE,
};
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::errors::TransactionExecutionError;
use crate::transaction::test_utils::{
block_context,
calculate_class_info_for_testing,
create_test_init_data,
emit_n_events_tx,
l1_resource_bounds,
TestInitData,
block_context, calculate_class_info_for_testing, create_test_init_data, emit_n_events_tx,
l1_resource_bounds, TestInitData,
};
use crate::transaction::transaction_execution::Transaction;
fn tx_executor_test_body<S: StateReader>(
Expand Down
4 changes: 1 addition & 3 deletions crates/blockifier/src/blockifier/transfers_flow_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use rstest::rstest;

use crate::blockifier::config::ConcurrencyConfig;
use crate::test_utils::transfers_generator::{
RecipientGeneratorType,
TransfersGenerator,
TransfersGeneratorConfig,
RecipientGeneratorType, TransfersGenerator, TransfersGeneratorConfig,
};

#[rstest]
Expand Down
3 changes: 1 addition & 2 deletions crates/blockifier/src/bouncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use starknet_api::core::ClassHash;
use starknet_api::execution_resources::GasAmount;

use crate::blockifier::transaction_executor::{
TransactionExecutorError,
TransactionExecutorResult,
TransactionExecutorError, TransactionExecutorResult,
};
use crate::execution::call_info::ExecutionSummary;
use crate::fee::gas_usage::get_onchain_data_segment_length;
Expand Down
5 changes: 1 addition & 4 deletions crates/blockifier/src/bouncer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ use starknet_api::{class_hash, contract_address, storage_key};
use super::BouncerConfig;
use crate::blockifier::transaction_executor::TransactionExecutorError;
use crate::bouncer::{
verify_tx_weights_within_max_capacity,
Bouncer,
BouncerWeights,
BuiltinCount,
verify_tx_weights_within_max_capacity, Bouncer, BouncerWeights, BuiltinCount,
};
use crate::context::BlockContext;
use crate::execution::call_info::ExecutionSummary;
Expand Down
4 changes: 1 addition & 3 deletions crates/blockifier/src/concurrency/fee_utils_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::{fund_account, test_state, test_state_inner};
use crate::test_utils::{create_trivial_calldata, CairoVersion, RunnableCairo1, BALANCE};
use crate::transaction::test_utils::{
block_context,
default_all_resource_bounds,
invoke_tx_with_default_flags,
block_context, default_all_resource_bounds, invoke_tx_with_default_flags,
};

#[rstest]
Expand Down
55 changes: 23 additions & 32 deletions crates/blockifier/src/concurrency/versioned_state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,20 @@ use starknet_api::test_utils::deploy_account::executable_deploy_account_tx;
use starknet_api::test_utils::NonceManager;
use starknet_api::transaction::fields::{ContractAddressSalt, ValidResourceBounds};
use starknet_api::{
calldata,
class_hash,
compiled_class_hash,
contract_address,
deploy_account_tx_args,
felt,
nonce,
storage_key,
calldata, class_hash, compiled_class_hash, contract_address, deploy_account_tx_args, felt,
nonce, storage_key,
};

use crate::concurrency::test_utils::{
class_hash,
contract_address,
safe_versioned_state_for_testing,
class_hash, contract_address, safe_versioned_state_for_testing,
};
use crate::concurrency::versioned_state::{
ThreadSafeVersionedState,
VersionedState,
VersionedStateProxy,
ThreadSafeVersionedState, VersionedState, VersionedStateProxy,
};
use crate::concurrency::TxIndex;
use crate::context::BlockContext;
use crate::state::cached_state::{
CachedState,
ContractClassMapping,
StateMaps,
TransactionalState,
CachedState, ContractClassMapping, StateMaps, TransactionalState,
};
use crate::state::errors::StateError;
use crate::state::state_api::{State, StateReader, UpdatableState};
Expand Down Expand Up @@ -104,9 +91,11 @@ fn test_versioned_state_proxy() {
StateError::UndeclaredClassHash(class_hash) if
another_class_hash == class_hash
);
assert!(
!versioned_state_proxys[0].state().declared_contracts.read(0, another_class_hash).unwrap()
);
assert!(!versioned_state_proxys[0]
.state()
.declared_contracts
.read(0, another_class_hash)
.unwrap());

// Write to the state.
let new_key = storage_key!(0x11_u8);
Expand Down Expand Up @@ -176,12 +165,16 @@ fn test_versioned_state_proxy() {
versioned_state_proxys[9].get_class_hash_at(contract_address).unwrap(),
class_hash_v7
);
assert!(
!versioned_state_proxys[0].state().declared_contracts.read(0, another_class_hash).unwrap()
);
assert!(
versioned_state_proxys[4].state().declared_contracts.read(4, another_class_hash).unwrap()
);
assert!(!versioned_state_proxys[0]
.state()
.declared_contracts
.read(0, another_class_hash)
.unwrap());
assert!(versioned_state_proxys[4]
.state()
.declared_contracts
.read(4, another_class_hash)
.unwrap());
// Include the writes in the current transaction.
assert_eq!(
versioned_state_proxys[10].get_class_hash_at(contract_address).unwrap(),
Expand Down Expand Up @@ -331,11 +324,9 @@ fn test_validate_reads(

assert_eq!(transactional_state.cache.borrow().initial_reads.declared_contracts.len(), 1);

assert!(
safe_versioned_state
.pin_version(1)
.validate_reads(&transactional_state.cache.borrow().initial_reads)
);
assert!(safe_versioned_state
.pin_version(1)
.validate_reads(&transactional_state.cache.borrow().initial_reads));
}

#[rstest]
Expand Down
13 changes: 3 additions & 10 deletions crates/blockifier/src/concurrency/worker_logic_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,14 @@ use crate::state::state_api::StateReader;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{
create_calldata,
create_trivial_calldata,
CairoVersion,
RunnableCairo1,
BALANCE,
create_calldata, create_trivial_calldata, CairoVersion, RunnableCairo1, BALANCE,
TEST_ERC20_CONTRACT_ADDRESS2,
};
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::objects::HasRelatedFeeType;
use crate::transaction::test_utils::{
calculate_class_info_for_testing,
default_all_resource_bounds,
emit_n_events_tx,
invoke_tx_with_default_flags,
max_fee,
calculate_class_info_for_testing, default_all_resource_bounds, emit_n_events_tx,
invoke_tx_with_default_flags, max_fee,
};
use crate::transaction::transaction_execution::Transaction;

Expand Down
9 changes: 2 additions & 7 deletions crates/blockifier/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ use serde::{Deserialize, Serialize};
use starknet_api::block::{BlockInfo, FeeType, GasPriceVector};
use starknet_api::core::{ChainId, ContractAddress};
use starknet_api::transaction::fields::{
AllResourceBounds,
GasVectorComputationMode,
ValidResourceBounds,
AllResourceBounds, GasVectorComputationMode, ValidResourceBounds,
};

use crate::bouncer::BouncerConfig;
use crate::transaction::objects::{
CurrentTransactionInfo,
HasRelatedFeeType,
TransactionInfo,
TransactionInfoCreator,
CurrentTransactionInfo, HasRelatedFeeType, TransactionInfo, TransactionInfoCreator,
};
use crate::versioned_constants::VersionedConstants;

Expand Down
9 changes: 3 additions & 6 deletions crates/blockifier/src/execution/common_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ use std::ops::Shl;
use std::rc::Rc;

use cairo_vm::hint_processor::builtin_hint_processor::builtin_hint_processor_definition::{
BuiltinHintProcessor,
HintFunc,
BuiltinHintProcessor, HintFunc,
};
use cairo_vm::hint_processor::builtin_hint_processor::hint_utils::{
get_integer_from_var_name,
insert_value_from_var_name,
get_integer_from_var_name, insert_value_from_var_name,
};
use cairo_vm::hint_processor::hint_processor_definition::HintReference;
use cairo_vm::serde::deserialize_program::ApTracking;
Expand All @@ -20,8 +18,7 @@ use num_bigint::BigUint;
use starknet_types_core::felt::Felt;

use crate::execution::hint_code::{
NORMALIZE_ADDRESS_SET_IS_250_HINT,
NORMALIZE_ADDRESS_SET_IS_SMALL_HINT,
NORMALIZE_ADDRESS_SET_IS_250_HINT, NORMALIZE_ADDRESS_SET_IS_SMALL_HINT,
};

/// Transaction execution mode.
Expand Down
11 changes: 3 additions & 8 deletions crates/blockifier/src/execution/contract_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use cairo_lang_casm::hints::Hint;
use cairo_lang_starknet_classes::casm_contract_class::{CasmContractClass, CasmContractEntryPoint};
use cairo_lang_starknet_classes::NestedIntList;
use cairo_vm::serde::deserialize_program::{
ApTracking,
FlowTrackingData,
HintParams,
ReferenceManager,
ApTracking, FlowTrackingData, HintParams, ReferenceManager,
};
use cairo_vm::types::builtin_name::BuiltinName;
use cairo_vm::types::errors::program_errors::ProgramError;
Expand All @@ -24,9 +21,7 @@ use serde::{Deserialize, Deserializer, Serialize};
use starknet_api::contract_class::{ContractClass, EntryPointType};
use starknet_api::core::EntryPointSelector;
use starknet_api::deprecated_contract_class::{
ContractClass as DeprecatedContractClass,
EntryPointOffset,
EntryPointV0,
ContractClass as DeprecatedContractClass, EntryPointOffset, EntryPointV0,
Program as DeprecatedProgram,
};
use starknet_types_core::felt::Felt;
Expand Down Expand Up @@ -187,7 +182,7 @@ impl CompiledClassV0 {
+ self.n_builtins()
+ self.bytecode_length()
+ 1; // Hinted class hash.
// The hashed data size is approximately the number of hashes (invoked in hash chains).
// The hashed data size is approximately the number of hashes (invoked in hash chains).
let n_steps = constants::N_STEPS_PER_PEDERSEN * hashed_data_size;

ExecutionResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ use crate::execution::call_info::{CallExecution, CallInfo, ChargedResources};
use crate::execution::contract_class::{CompiledClassV0, TrackedResource};
use crate::execution::deprecated_syscalls::hint_processor::DeprecatedSyscallHintProcessor;
use crate::execution::entry_point::{
CallEntryPoint,
EntryPointExecutionContext,
EntryPointExecutionResult,
CallEntryPoint, EntryPointExecutionContext, EntryPointExecutionResult,
};
use crate::execution::errors::{PostExecutionError, PreExecutionError};
use crate::execution::execution_utils::{read_execution_retdata, Args, ReadOnlySegments};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ use starknet_api::core::{calculate_contract_address, ChainId};
use starknet_api::state::StorageKey;
use starknet_api::transaction::fields::{Calldata, ContractAddressSalt, Fee};
use starknet_api::transaction::{
EventContent,
EventData,
EventKey,
TransactionVersion,
QUERY_VERSION_BASE,
EventContent, EventData, EventKey, TransactionVersion, QUERY_VERSION_BASE,
};
use starknet_api::{calldata, felt, nonce, storage_key, tx_hash};
use starknet_types_core::felt::Felt;
Expand All @@ -30,20 +26,12 @@ use crate::state::state_api::StateReader;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{
calldata_for_deploy_test,
get_syscall_resources,
trivial_external_entry_point_new,
CairoVersion,
CURRENT_BLOCK_NUMBER,
CURRENT_BLOCK_NUMBER_FOR_VALIDATE,
CURRENT_BLOCK_TIMESTAMP,
CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE,
TEST_SEQUENCER_ADDRESS,
calldata_for_deploy_test, get_syscall_resources, trivial_external_entry_point_new,
CairoVersion, CURRENT_BLOCK_NUMBER, CURRENT_BLOCK_NUMBER_FOR_VALIDATE, CURRENT_BLOCK_TIMESTAMP,
CURRENT_BLOCK_TIMESTAMP_FOR_VALIDATE, TEST_SEQUENCER_ADDRESS,
};
use crate::transaction::objects::{
CommonAccountFields,
DeprecatedTransactionInfo,
TransactionInfo,
CommonAccountFields, DeprecatedTransactionInfo, TransactionInfo,
};
use crate::versioned_constants::VersionedConstants;
use crate::{check_entry_point_execution_error_for_custom_hint, retdata};
Expand Down
Loading

0 comments on commit d19189b

Please sign in to comment.