Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoGiachetta committed Dec 10, 2024
1 parent db67a24 commit 30be222
Show file tree
Hide file tree
Showing 22 changed files with 1,015 additions and 1,321 deletions.
1,006 changes: 501 additions & 505 deletions crates/blockifier/resources/versioned_constants_0_13_1.json

Large diffs are not rendered by default.

1,006 changes: 501 additions & 505 deletions crates/blockifier/resources/versioned_constants_0_13_1_1.json

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions crates/blockifier/resources/versioned_constants_0_13_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
},
"invoke_tx_max_n_steps": 10000000,
"execute_max_sierra_gas": 10000000000,
"execute_max_sierra_gas": 10000000000,
"deprecated_l2_resource_gas_costs": {
"gas_per_data_felt": [
128,
Expand Down Expand Up @@ -42,7 +41,6 @@
"disable_cairo0_redeclaration": true,
"enable_stateful_compression": false,
"comprehensive_state_diff": false,
"comprehensive_state_diff": false,
"allocation_cost": {
"blob_cost": {
"l1_gas": 0,
Expand Down Expand Up @@ -97,7 +95,6 @@
},
"range_check_gas_cost": 70,
"keccak_builtin_gas_cost": 0,
"keccak_builtin_gas_cost": 0,
"pedersen_gas_cost": 0,
"bitwise_builtin_gas_cost": 594,
"ecop_gas_cost": 0,
Expand All @@ -112,11 +109,9 @@
"step_gas_cost": 100
},
"transaction_gas_cost": {
"entry_point_initial_budget": 2,
"entry_point_initial_budget": 2,
"fee_transfer_gas_cost": 1,
"step_gas_cost": 1100
"step_gas_cost": 1100
},
"transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e",
"validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3",
Expand Down Expand Up @@ -615,7 +610,6 @@
},
"validate_max_n_steps": 1000000,
"validate_max_sierra_gas": 10000000000,
"validate_max_sierra_gas": 10000000000,
"min_compiler_version_for_sierra_gas": "2.8.0",
"vm_resource_fee_cost": {
"builtins": {
Expand Down
6 changes: 0 additions & 6 deletions crates/blockifier/resources/versioned_constants_0_13_2_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
},
"invoke_tx_max_n_steps": 10000000,
"execute_max_sierra_gas": 10000000000,
"execute_max_sierra_gas": 10000000000,
"deprecated_l2_resource_gas_costs": {
"gas_per_data_felt": [
128,
Expand Down Expand Up @@ -42,7 +41,6 @@
"disable_cairo0_redeclaration": true,
"enable_stateful_compression": false,
"comprehensive_state_diff": false,
"comprehensive_state_diff": false,
"allocation_cost": {
"blob_cost": {
"l1_gas": 0,
Expand Down Expand Up @@ -97,7 +95,6 @@
},
"range_check_gas_cost": 70,
"keccak_builtin_gas_cost": 0,
"keccak_builtin_gas_cost": 0,
"pedersen_gas_cost": 0,
"bitwise_builtin_gas_cost": 594,
"ecop_gas_cost": 0,
Expand All @@ -112,11 +109,9 @@
"step_gas_cost": 100
},
"transaction_gas_cost": {
"entry_point_initial_budget": 2,
"entry_point_initial_budget": 2,
"fee_transfer_gas_cost": 1,
"step_gas_cost": 1100
"step_gas_cost": 1100
},
"transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e",
"validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3",
Expand Down Expand Up @@ -615,7 +610,6 @@
},
"validate_max_n_steps": 1000000,
"validate_max_sierra_gas": 10000000000,
"validate_max_sierra_gas": 10000000000,
"min_compiler_version_for_sierra_gas": "2.8.0",
"vm_resource_fee_cost": {
"builtins": {
Expand Down
6 changes: 0 additions & 6 deletions crates/blockifier/resources/versioned_constants_0_13_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
},
"invoke_tx_max_n_steps": 10000000,
"execute_max_sierra_gas": 10000000000,
"execute_max_sierra_gas": 10000000000,
"deprecated_l2_resource_gas_costs": {
"gas_per_data_felt": [
128,
Expand Down Expand Up @@ -42,7 +41,6 @@
"disable_cairo0_redeclaration": true,
"enable_stateful_compression": false,
"comprehensive_state_diff": false,
"comprehensive_state_diff": false,
"allocation_cost": {
"blob_cost": {
"l1_gas": 0,
Expand Down Expand Up @@ -97,7 +95,6 @@
},
"range_check_gas_cost": 70,
"keccak_builtin_gas_cost": 0,
"keccak_builtin_gas_cost": 0,
"pedersen_gas_cost": 0,
"bitwise_builtin_gas_cost": 594,
"ecop_gas_cost": 0,
Expand All @@ -112,11 +109,9 @@
"step_gas_cost": 100
},
"transaction_gas_cost": {
"entry_point_initial_budget": 2,
"entry_point_initial_budget": 2,
"fee_transfer_gas_cost": 1,
"step_gas_cost": 1100
"step_gas_cost": 1100
},
"transfer_entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e",
"validate_declare_entry_point_selector": "0x289da278a8dc833409cabfdad1581e8e7d40e42dcaed693fa4008dcdb4963b3",
Expand Down Expand Up @@ -615,7 +610,6 @@
},
"validate_max_n_steps": 1000000,
"validate_max_sierra_gas": 10000000000,
"validate_max_sierra_gas": 10000000000,
"min_compiler_version_for_sierra_gas": "2.8.0",
"vm_resource_fee_cost": {
"builtins": {
Expand Down
4 changes: 0 additions & 4 deletions crates/blockifier/src/concurrency/versioned_state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use rstest::{fixture, rstest};
use starknet_api::abi::abi_utils::{get_fee_token_var_address, get_storage_var_address};
use starknet_api::core::{calculate_contract_address, ClassHash, ContractAddress};
use starknet_api::test_utils::deploy_account::executable_deploy_account_tx;
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::{
Expand Down Expand Up @@ -228,7 +227,6 @@ fn test_run_parallel_txs(default_all_resource_bounds: ValidResourceBounds) {
let mut state_2 = TransactionalState::create_transactional(&mut versioned_state_proxy_2);

// Prepare transactions
let tx = executable_deploy_account_tx(
let tx = executable_deploy_account_tx(
deploy_account_tx_args! {
class_hash: account_without_validation.get_class_hash(),
Expand All @@ -252,8 +250,6 @@ fn test_run_parallel_txs(default_all_resource_bounds: ValidResourceBounds) {
constructor_calldata: constructor_calldata.clone(),
};
let nonce_manager = &mut NonceManager::default();
let tx = executable_deploy_account_tx(deploy_tx_args, nonce_manager);
let delpoy_account_tx_2 = AccountTransaction::new_for_sequencing(tx);

let tx = executable_deploy_account_tx(deploy_tx_args, nonce_manager);
let delpoy_account_tx_2 = AccountTransaction::new_for_sequencing(tx);
Expand Down
30 changes: 5 additions & 25 deletions crates/blockifier/src/state/cached_state_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,10 @@ fn cached_state_state_diff_conversion() {
assert_eq!(expected_state_diff, state.to_state_diff().unwrap().state_maps.into());
}

fn create_state_cache_for_test<S: StateReader>(
fn create_state_cache_for_test<S: StateReader>(
state: &mut CachedState<S>,
sender_address: Option<ContractAddress>,
fee_token_address: ContractAddress,
) -> StateCache {
) -> StateCache {
let contract_address = contract_address!(CONTRACT_ADDRESS);
let contract_address2 = contract_address!("0x101");
Expand Down Expand Up @@ -335,7 +333,6 @@ fn create_state_cache_for_test<S: StateReader>(
state.set_storage_at(fee_token_address, sender_balance_key, felt!("0x1999")).unwrap();
}
state.borrow_updated_state_cache().unwrap().clone()
state.borrow_updated_state_cache().unwrap().clone()
}

#[rstest]
Expand All @@ -346,7 +343,7 @@ fn test_from_state_changes_for_fee_charge(
let fee_token_address = contract_address!("0x17");
let state_changes =
create_state_cache_for_test(&mut state, sender_address, fee_token_address).to_state_diff();
create_state_cache_for_test(&mut state, sender_address, fee_token_address).to_state_diff();
create_state_cache_for_test(&mut state, sender_address, fee_token_address).to_state_diff();
let state_changes_count = state_changes.count_for_fee_charge(sender_address, fee_token_address);
let n_expected_storage_updates = 1 + usize::from(sender_address.is_some());
let expected_state_changes_count = StateChangesCountForFee {
Expand All @@ -363,7 +360,6 @@ fn test_from_state_changes_for_fee_charge(
}

#[rstest]
fn test_state_cache_merge(
fn test_state_cache_merge(
#[values(Some(contract_address!("0x102")), None)] sender_address: Option<ContractAddress>,
) {
Expand All @@ -374,8 +370,6 @@ fn test_state_cache_merge(
let mut transactional_state = TransactionalState::create_transactional(&mut state);
let block_context = BlockContext::create_for_testing();
let fee_token_address = block_context.chain_info.fee_token_addresses.eth_fee_token_address;
let state_cache1 =
create_state_cache_for_test(&mut transactional_state, sender_address, fee_token_address);
let state_cache1 =
create_state_cache_for_test(&mut transactional_state, sender_address, fee_token_address);
transactional_state.commit();
Expand All @@ -398,8 +392,6 @@ fn test_state_cache_merge(
assert_eq!(StateCache::squash_state_caches(vec![&state_cache1, &state_cache2]), state_cache1);
assert_eq!(StateCache::squash_state_caches(vec![&state_cache2, &state_cache1]), state_cache1);

// Get the storage updates addresses and keys from the state_cache1, to overwrite.
let state_changes1 = state_cache1.to_state_diff();
// Get the storage updates addresses and keys from the state_cache1, to overwrite.
let state_changes1 = state_cache1.to_state_diff();
let mut storage_updates_keys = state_changes1.state_maps.storage.keys();
Expand All @@ -417,24 +409,18 @@ fn test_state_cache_merge(
transactional_state.increment_nonce(contract_address).unwrap();
// Get the new state cache and then commit the transactional state.
let state_cache3 = transactional_state.borrow_updated_state_cache().unwrap().clone();
// Get the new state cache and then commit the transactional state.
let state_cache3 = transactional_state.borrow_updated_state_cache().unwrap().clone();
transactional_state.commit();

// Get the total state changes of the CachedState underlying all the temporary transactional
// states. We expect the state_changes to match the merged state_changes of the transactional
// states, but only when done in the right order.
let state_changes_final = state.get_actual_state_changes().unwrap();
assert_eq!(
StateCache::squash_state_caches(vec![&state_cache1, &state_cache2, &state_cache3])
.to_state_diff(),
StateCache::squash_state_caches(vec![&state_cache1, &state_cache2, &state_cache3])
.to_state_diff(),
state_changes_final
);
assert_ne!(
StateCache::squash_state_caches(vec![&state_cache3, &state_cache1, &state_cache2])
.to_state_diff(),
StateCache::squash_state_caches(vec![&state_cache3, &state_cache1, &state_cache2])
.to_state_diff(),
state_changes_final
Expand All @@ -452,30 +438,24 @@ fn test_state_cache_merge(
#[case(false, vec![felt!("0x7"), felt!("0x1")], false)]
#[case(false, vec![felt!("0x0"), felt!("0x8")], false)]
#[case(false, vec![felt!("0x0"), felt!("0x8"), felt!("0x0")], false)]
fn test_state_cache_commit_and_merge(
fn test_state_cache_commit_and_merge(
#[case] is_base_empty: bool,
#[case] storage_updates: Vec<Felt>,
#[case] charged: bool,
#[values(true, false)] comprehensive_state_diff: bool,
#[values(true, false)] comprehensive_state_diff: bool,
) {
let contract_address = contract_address!(CONTRACT_ADDRESS);
let storage_key = StorageKey::from(0x10_u16);
// Set initial state
let mut state: CachedState<DictStateReader> = CachedState::default();

let non_empty_base_value = felt!("0x1");

let non_empty_base_value = felt!("0x1");
if !is_base_empty {
state.set_storage_at(contract_address, storage_key, non_empty_base_value).unwrap();
state.set_storage_at(contract_address, storage_key, non_empty_base_value).unwrap();
}
let mut state_caches = vec![];
let mut state_caches = vec![];

for value in storage_updates.iter() {
for value in storage_updates.iter() {
// In the end of the previous loop, state has moved into the transactional state.
let mut transactional_state = TransactionalState::create_transactional(&mut state);
Expand All @@ -488,8 +468,8 @@ fn test_state_cache_commit_and_merge(
let merged_changes =
StateCache::squash_state_diff(state_caches.iter().collect(), comprehensive_state_diff);
if comprehensive_state_diff {
// The comprehensive_state_diff is needed for backward compatibility of versions before the
// allocated keys feature was inserted.
// The comprehensive_state_diff is needed for backward compatibility of versions before
// the allocated keys feature was inserted.
assert_ne!(merged_changes.allocated_keys.is_empty(), charged);
}

Expand All @@ -508,8 +488,8 @@ fn test_state_cache_commit_and_merge(
let merged_changes =
StateCache::squash_state_diff(state_caches.iter().collect(), comprehensive_state_diff);
if comprehensive_state_diff {
// The comprehensive_state_diff is needed for backward compatibility of versions before the
// allocated keys feature was inserted.
// The comprehensive_state_diff is needed for backward compatibility of versions before
// the allocated keys feature was inserted.
assert_ne!(merged_changes.allocated_keys.is_empty(), charged);
}

Expand Down
5 changes: 0 additions & 5 deletions crates/blockifier/src/test_utils/cairo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,6 @@ fn get_tag_and_repo_file_path(git_tag_override: Option<String>) -> (String, Path
pub fn prepare_group_tag_compiler_deps(tag_and_toolchain: &TagAndToolchain) {
let (optional_tag, optional_toolchain) = tag_and_toolchain;

(tag, cairo_repo_path)
}

pub fn prepare_group_tag_compiler_deps(git_tag_override: Option<String>) {
let (tag, cairo_repo_path) = get_tag_and_repo_file_path(git_tag_override);
// Checkout the required version in the compiler repo.
let (tag, cairo_repo_path) = get_tag_and_repo_file_path(optional_tag.clone());
run_and_verify_output(Command::new("git").args([
Expand Down
20 changes: 3 additions & 17 deletions crates/blockifier/src/test_utils/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::collections::HashMap;

use std::collections::HashMap;

use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use cairo_lang_starknet_classes::contract_class::ContractClass as CairoLangContractClass;
use itertools::Itertools;
Expand Down Expand Up @@ -95,9 +93,6 @@ const CAIRO_STEPS_TEST_CONTRACT_RUST_TOOLCHAIN: &str = "2024-04-29";
pub type TagAndToolchain = (Option<String>, Option<String>);
pub type TagToContractsMapping = HashMap<TagAndToolchain, Vec<FeatureContract>>;

pub type TagAndToolchain = (Option<String>, Option<String>);
pub type TagToContractsMapping = HashMap<TagAndToolchain, Vec<FeatureContract>>;

/// Enum representing all feature contracts.
/// The contracts that are implemented in both Cairo versions include a version field.
#[derive(Clone, Copy, Debug, EnumIter, Hash, PartialEq, Eq)]
Expand Down Expand Up @@ -223,7 +218,6 @@ impl FeatureContract {
/// Some contracts are designed to test behavior of code compiled with a
/// specific (old) compiler tag. To run the (old) compiler, older rust
/// version is required.
pub fn fixed_tag_and_rust_toolchain(&self) -> TagAndToolchain {
pub fn fixed_tag_and_rust_toolchain(&self) -> TagAndToolchain {
match self {
Self::LegacyTestContract => (
Expand Down Expand Up @@ -339,7 +333,6 @@ impl FeatureContract {

/// Compiles the feature contract and returns the compiled contract as a byte vector.
/// Panics if the contract is ERC20, as ERC20 contract recompilation is not supported.
pub fn compile(&self) -> CompilationArtifacts {
pub fn compile(&self) -> CompilationArtifacts {
if matches!(self, Self::ERC20(_)) {
panic!("ERC20 contract recompilation not supported.");
Expand Down Expand Up @@ -368,9 +361,9 @@ impl FeatureContract {
}
}

/// Fetch PC locations from the compiled contract to compute the expected PC locations in the
/// traceback. Computation is not robust, but as long as the cairo function itself is not
/// edited, this computation should be stable.
/// Fetch PC locations from the compiled contract to compute the expected PC locations in
/// the traceback. Computation is not robust, but as long as the cairo function
/// itself is not edited, this computation should be stable.
fn get_offset(
&self,
entry_point_selector: EntryPointSelector,
Expand Down Expand Up @@ -487,11 +480,4 @@ impl FeatureContract {
.map(|contract| (contract.fixed_tag_and_rust_toolchain(), contract))
.into_group_map()
}

pub fn cairo1_feature_contracts_by_tag() -> TagToContractsMapping {
Self::all_feature_contracts()
.filter(|contract| contract.cairo_version() != CairoVersion::Cairo0)
.map(|contract| (contract.fixed_tag_and_rust_toolchain(), contract))
.into_group_map()
}
}
Loading

0 comments on commit 30be222

Please sign in to comment.