From a3b4d5305bf55d8bba761f142136b0193d271138 Mon Sep 17 00:00:00 2001 From: Bowen Wang Date: Sat, 16 Sep 2023 15:40:24 +0100 Subject: [PATCH 1/6] feat: restrict creation of top level accounts --- chain/chain/src/tests/simple_chain.rs | 2 +- core/primitives-core/Cargo.toml | 2 + core/primitives-core/src/version.rs | 6 +- core/primitives/Cargo.toml | 2 + core/primitives/res/runtime_configs/139.yaml | 2 + integration-tests/Cargo.toml | 4 ++ .../src/tests/client/features.rs | 1 + .../src/tests/client/features/restrict_tla.rs | 61 +++++++++++++++++++ .../src/tests/client/process_blocks.rs | 21 +++++++ 9 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 core/primitives/res/runtime_configs/139.yaml create mode 100644 integration-tests/src/tests/client/features/restrict_tla.rs diff --git a/chain/chain/src/tests/simple_chain.rs b/chain/chain/src/tests/simple_chain.rs index a5e51a7dbaa..c1afc3cbf8c 100644 --- a/chain/chain/src/tests/simple_chain.rs +++ b/chain/chain/src/tests/simple_chain.rs @@ -48,7 +48,7 @@ fn build_chain() { // cargo insta test --accept -p near-chain --features nightly -- tests::simple_chain::build_chain let hash = chain.head().unwrap().last_block_hash; if cfg!(feature = "nightly") { - insta::assert_display_snapshot!(hash, @"GargNTMFiuET32KH5uPLFwMSU8xXtvrk6aGqgkPbRZg8"); + insta::assert_display_snapshot!(hash, @"CwaiZ4AmfJSnMN9rytYwwYHCTzLioC5xcjHzNkDex1HH"); } else { insta::assert_display_snapshot!(hash, @"712T4sPbJhNWWN3bWweccECGYWbnUmGpqpKW2SJpb2k5"); } diff --git a/core/primitives-core/Cargo.toml b/core/primitives-core/Cargo.toml index eca9aa693f8..9872782e835 100644 --- a/core/primitives-core/Cargo.toml +++ b/core/primitives-core/Cargo.toml @@ -36,6 +36,7 @@ protocol_feature_fix_staking_threshold = [] protocol_feature_fix_contract_loading_cost = [] protocol_feature_reject_blocks_with_outdated_protocol_version = [] protocol_feature_simple_nightshade_v2 = [] +protocol_feature_restrict_tla = [] nightly = [ "nightly_protocol", @@ -43,6 +44,7 @@ nightly = [ "protocol_feature_fix_staking_threshold", "protocol_feature_reject_blocks_with_outdated_protocol_version", "protocol_feature_simple_nightshade_v2", + "protocol_feature_restrict_tla" ] nightly_protocol = [ diff --git a/core/primitives-core/src/version.rs b/core/primitives-core/src/version.rs index 4d03a93a336..cd510d81199 100644 --- a/core/primitives-core/src/version.rs +++ b/core/primitives-core/src/version.rs @@ -120,6 +120,8 @@ pub enum ProtocolFeature { RejectBlocksWithOutdatedProtocolVersions, #[cfg(feature = "protocol_feature_simple_nightshade_v2")] SimpleNightshadeV2, + #[cfg(feature = "protocol_feature_restrict_tla")] + RestrictTla } impl ProtocolFeature { @@ -173,6 +175,8 @@ impl ProtocolFeature { ProtocolFeature::RejectBlocksWithOutdatedProtocolVersions => 132, #[cfg(feature = "protocol_feature_simple_nightshade_v2")] ProtocolFeature::SimpleNightshadeV2 => 135, + #[cfg(feature = "protocol_feature_restrict_tla")] + ProtocolFeature::RestrictTla => 139, } } } @@ -185,7 +189,7 @@ const STABLE_PROTOCOL_VERSION: ProtocolVersion = 63; /// Largest protocol version supported by the current binary. pub const PROTOCOL_VERSION: ProtocolVersion = if cfg!(feature = "nightly_protocol") { // On nightly, pick big enough version to support all features. - 138 + 139 } else { // Enable all stable features. STABLE_PROTOCOL_VERSION diff --git a/core/primitives/Cargo.toml b/core/primitives/Cargo.toml index 4334d4f3447..5aaf40d9d54 100644 --- a/core/primitives/Cargo.toml +++ b/core/primitives/Cargo.toml @@ -49,12 +49,14 @@ protocol_feature_fix_staking_threshold = ["near-primitives-core/protocol_feature protocol_feature_fix_contract_loading_cost = ["near-primitives-core/protocol_feature_fix_contract_loading_cost"] protocol_feature_reject_blocks_with_outdated_protocol_version = ["near-primitives-core/protocol_feature_reject_blocks_with_outdated_protocol_version"] protocol_feature_simple_nightshade_v2 = ["near-primitives-core/protocol_feature_simple_nightshade_v2"] +protocol_feature_restrict_tla = ["near-primitives-core/protocol_feature_restrict_tla"] nightly = [ "nightly_protocol", "protocol_feature_fix_contract_loading_cost", "protocol_feature_fix_staking_threshold", "protocol_feature_reject_blocks_with_outdated_protocol_version", "protocol_feature_simple_nightshade_v2", + "protocol_feature_restrict_tla", "near-fmt/nightly", "near-primitives-core/nightly", "near-vm-runner/nightly", diff --git a/core/primitives/res/runtime_configs/139.yaml b/core/primitives/res/runtime_configs/139.yaml new file mode 100644 index 00000000000..91331e7412a --- /dev/null +++ b/core/primitives/res/runtime_configs/139.yaml @@ -0,0 +1,2 @@ +# Implements NEP-492, disallowing all top-level accounts. +min_allowed_top_level_account_length: { old: 32, new: 65 } \ No newline at end of file diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 29a9e6ef6c3..2fec13cb273 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -80,12 +80,16 @@ protocol_feature_reject_blocks_with_outdated_protocol_version = [ protocol_feature_simple_nightshade_v2 = [ "near-primitives/protocol_feature_simple_nightshade_v2", ] +protocol_feature_restrict_tla = [ + "near-primitives/protocol_feature_restrict_tla", +] nightly = [ "nightly_protocol", "protocol_feature_fix_contract_loading_cost", "protocol_feature_reject_blocks_with_outdated_protocol_version", "protocol_feature_simple_nightshade_v2", + "protocol_feature_restrict_tla", "near-actix-test-utils/nightly", "near-async/nightly", "near-chain-configs/nightly", diff --git a/integration-tests/src/tests/client/features.rs b/integration-tests/src/tests/client/features.rs index 744d550c8e5..a31caae0237 100644 --- a/integration-tests/src/tests/client/features.rs +++ b/integration-tests/src/tests/client/features.rs @@ -17,3 +17,4 @@ mod lower_storage_key_limit; mod nearvm; mod restore_receipts_after_fix_apply_chunks; mod zero_balance_account; +mod restrict_tla; diff --git a/integration-tests/src/tests/client/features/restrict_tla.rs b/integration-tests/src/tests/client/features/restrict_tla.rs new file mode 100644 index 00000000000..48995ee6514 --- /dev/null +++ b/integration-tests/src/tests/client/features/restrict_tla.rs @@ -0,0 +1,61 @@ +use super::super::process_blocks::create_account; +use crate::tests::client::utils::TestEnvNightshadeSetupExt; +use near_chain::ChainGenesis; +use near_chain_configs::Genesis; +use near_client::test_utils::TestEnv; +use near_primitives::errors::{ActionError, ActionErrorKind}; +use near_primitives::types::{AccountId, BlockHeight}; +use near_primitives::views::FinalExecutionStatus; +use near_primitives_core::version::PROTOCOL_VERSION; +use nearcore::config::GenesisExt; + +#[test] +#[ignore] +fn test_create_top_level_accounts() { + let epoch_length: BlockHeight = 5; + let account: AccountId = "test0".parse().unwrap(); + let mut genesis = Genesis::test(vec![account.clone()], 1); + genesis.config.epoch_length = epoch_length; + genesis.config.protocol_version = PROTOCOL_VERSION; + println!("genesis protocol version: {}", genesis.config.protocol_version); + let runtime_config = near_primitives::runtime::config_store::RuntimeConfigStore::new(None); + let mut env = TestEnv::builder(ChainGenesis::new(&genesis)) + .real_epoch_managers(&genesis.config) + .nightshade_runtimes_with_runtime_config_store(&genesis, vec![runtime_config]) + .build(); + + let top_level_accounts = [ + "0x06012c8cf97bead5deae237070f9587f8e7a266d", + "0x5e97870f263700f46aa00d967821199b9bc5a120", + "0x0000000000000000000000000000000000000000", + "alice", + "thisisaveryverylongtoplevelaccount", + ]; + for (_, id) in top_level_accounts.iter().enumerate() { + let new_account_id = id.parse::().unwrap(); + let tx_hash = create_account( + &mut env, + account.clone(), + new_account_id.clone(), + epoch_length, + 1, + PROTOCOL_VERSION, + ); + let transaction_result = + env.clients[0].chain.get_final_transaction_result(&tx_hash).unwrap(); + assert_eq!( + transaction_result.status, + FinalExecutionStatus::Failure( + ActionError { + index: Some(0), + kind: ActionErrorKind::CreateAccountOnlyByRegistrar { + account_id: new_account_id, + registrar_account_id: "registrar".parse().unwrap(), + predecessor_id: account.clone() + } + } + .into() + ) + ); + } +} diff --git a/integration-tests/src/tests/client/process_blocks.rs b/integration-tests/src/tests/client/process_blocks.rs index ccfb1ed4ca9..8cbef6fb3a3 100644 --- a/integration-tests/src/tests/client/process_blocks.rs +++ b/integration-tests/src/tests/client/process_blocks.rs @@ -130,6 +130,27 @@ pub(crate) fn produce_blocks_from_height( produce_blocks_from_height_with_protocol_version(env, blocks_number, height, PROTOCOL_VERSION) } +pub(crate) fn create_account(env: &mut TestEnv, old_account_id: AccountId, new_account_id: AccountId, epoch_length: u64, height: BlockHeight, protocol_version: ProtocolVersion) -> CryptoHash { + let block = env.clients[0].chain.get_block_by_height(height - 1).unwrap(); + let signer = + InMemorySigner::from_seed(old_account_id.clone(), KeyType::ED25519, old_account_id.as_ref()); + + + let tx = SignedTransaction::create_account( + height, + old_account_id.clone(), + new_account_id, + 10u128.pow(24), + signer.public_key(), + &signer, + *block.hash(), + ); + let tx_hash = tx.get_hash(); + assert_eq!(env.clients[0].process_tx(tx, false, false), ProcessTxResponse::ValidTx); + produce_blocks_from_height_with_protocol_version(env, epoch_length, height, protocol_version); + tx_hash +} + pub(crate) fn deploy_test_contract_with_protocol_version( env: &mut TestEnv, account_id: AccountId, From dc1200d9d6f606269f824c71cceae5aa00bc45ca Mon Sep 17 00:00:00 2001 From: Bowen Wang Date: Wed, 20 Sep 2023 21:41:12 +0100 Subject: [PATCH 2/6] fix tests --- chain/chain/src/tests/simple_chain.rs | 2 +- core/primitives-core/Cargo.toml | 2 +- core/primitives-core/src/version.rs | 2 +- core/primitives/Cargo.toml | 2 +- .../res/runtime_configs/parameters.snap | 2 +- core/primitives/src/runtime/config_store.rs | 1 + integration-tests/Cargo.toml | 2 +- .../src/tests/client/features.rs | 3 ++- .../src/tests/client/features/restrict_tla.rs | 6 ++---- .../src/tests/client/process_blocks.rs | 20 ++++++++++++++----- 10 files changed, 26 insertions(+), 16 deletions(-) diff --git a/chain/chain/src/tests/simple_chain.rs b/chain/chain/src/tests/simple_chain.rs index c1afc3cbf8c..4b875f0a846 100644 --- a/chain/chain/src/tests/simple_chain.rs +++ b/chain/chain/src/tests/simple_chain.rs @@ -78,7 +78,7 @@ fn build_chain() { let hash = chain.head().unwrap().last_block_hash; if cfg!(feature = "nightly") { - insta::assert_display_snapshot!(hash, @"2aurKZqRfPkZ3woNjA7Kf79wq5MYz98AohTYWoBFiG7o"); + insta::assert_display_snapshot!(hash, @"Dn18HUFm149fojXpwV1dYCfjdPh56S1k233kp7vmnFeE"); } else { insta::assert_display_snapshot!(hash, @"GUAPgvPQQmhumyuFzPusg3BKtRkVLpCw4asTAWgdTLq6"); } diff --git a/core/primitives-core/Cargo.toml b/core/primitives-core/Cargo.toml index 9872782e835..9d9a34e5d80 100644 --- a/core/primitives-core/Cargo.toml +++ b/core/primitives-core/Cargo.toml @@ -43,8 +43,8 @@ nightly = [ "protocol_feature_fix_contract_loading_cost", "protocol_feature_fix_staking_threshold", "protocol_feature_reject_blocks_with_outdated_protocol_version", + "protocol_feature_restrict_tla", "protocol_feature_simple_nightshade_v2", - "protocol_feature_restrict_tla" ] nightly_protocol = [ diff --git a/core/primitives-core/src/version.rs b/core/primitives-core/src/version.rs index cd510d81199..2f461396eb1 100644 --- a/core/primitives-core/src/version.rs +++ b/core/primitives-core/src/version.rs @@ -121,7 +121,7 @@ pub enum ProtocolFeature { #[cfg(feature = "protocol_feature_simple_nightshade_v2")] SimpleNightshadeV2, #[cfg(feature = "protocol_feature_restrict_tla")] - RestrictTla + RestrictTla, } impl ProtocolFeature { diff --git a/core/primitives/Cargo.toml b/core/primitives/Cargo.toml index 5aaf40d9d54..5e716cf3b0a 100644 --- a/core/primitives/Cargo.toml +++ b/core/primitives/Cargo.toml @@ -55,8 +55,8 @@ nightly = [ "protocol_feature_fix_contract_loading_cost", "protocol_feature_fix_staking_threshold", "protocol_feature_reject_blocks_with_outdated_protocol_version", - "protocol_feature_simple_nightshade_v2", "protocol_feature_restrict_tla", + "protocol_feature_simple_nightshade_v2", "near-fmt/nightly", "near-primitives-core/nightly", "near-vm-runner/nightly", diff --git a/core/primitives/res/runtime_configs/parameters.snap b/core/primitives/res/runtime_configs/parameters.snap index cc0d2ebcd9a..fa50d929e32 100644 --- a/core/primitives/res/runtime_configs/parameters.snap +++ b/core/primitives/res/runtime_configs/parameters.snap @@ -4,7 +4,7 @@ description: THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. --- burnt_gas_reward 3 / 10 pessimistic_gas_price_inflation 103 / 100 -min_allowed_top_level_account_length 32 +min_allowed_top_level_account_length 65 registrar_account_id registrar storage_amount_per_byte 10000000000000000000 storage_num_bytes_account 100 diff --git a/core/primitives/src/runtime/config_store.rs b/core/primitives/src/runtime/config_store.rs index ff79648f06a..bbd341b02d8 100644 --- a/core/primitives/src/runtime/config_store.rs +++ b/core/primitives/src/runtime/config_store.rs @@ -37,6 +37,7 @@ static CONFIG_DIFFS: &[(ProtocolVersion, &str)] = &[ (62, include_config!("62.yaml")), (63, include_config!("63.yaml")), (129, include_config!("129.yaml")), + (139, include_config!("139.yaml")), ]; /// Testnet parameters for versions <= 29, which (incorrectly) differed from mainnet parameters diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 2fec13cb273..d4b674fa7da 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -88,8 +88,8 @@ nightly = [ "nightly_protocol", "protocol_feature_fix_contract_loading_cost", "protocol_feature_reject_blocks_with_outdated_protocol_version", - "protocol_feature_simple_nightshade_v2", "protocol_feature_restrict_tla", + "protocol_feature_simple_nightshade_v2", "near-actix-test-utils/nightly", "near-async/nightly", "near-chain-configs/nightly", diff --git a/integration-tests/src/tests/client/features.rs b/integration-tests/src/tests/client/features.rs index a31caae0237..1331d959656 100644 --- a/integration-tests/src/tests/client/features.rs +++ b/integration-tests/src/tests/client/features.rs @@ -16,5 +16,6 @@ mod limit_contract_functions_number; mod lower_storage_key_limit; mod nearvm; mod restore_receipts_after_fix_apply_chunks; -mod zero_balance_account; +#[cfg(feature = "protocol_feature_restrict_tla")] mod restrict_tla; +mod zero_balance_account; diff --git a/integration-tests/src/tests/client/features/restrict_tla.rs b/integration-tests/src/tests/client/features/restrict_tla.rs index 48995ee6514..3ab1b28dfeb 100644 --- a/integration-tests/src/tests/client/features/restrict_tla.rs +++ b/integration-tests/src/tests/client/features/restrict_tla.rs @@ -10,14 +10,12 @@ use near_primitives_core::version::PROTOCOL_VERSION; use nearcore::config::GenesisExt; #[test] -#[ignore] fn test_create_top_level_accounts() { let epoch_length: BlockHeight = 5; let account: AccountId = "test0".parse().unwrap(); let mut genesis = Genesis::test(vec![account.clone()], 1); genesis.config.epoch_length = epoch_length; genesis.config.protocol_version = PROTOCOL_VERSION; - println!("genesis protocol version: {}", genesis.config.protocol_version); let runtime_config = near_primitives::runtime::config_store::RuntimeConfigStore::new(None); let mut env = TestEnv::builder(ChainGenesis::new(&genesis)) .real_epoch_managers(&genesis.config) @@ -31,14 +29,14 @@ fn test_create_top_level_accounts() { "alice", "thisisaveryverylongtoplevelaccount", ]; - for (_, id) in top_level_accounts.iter().enumerate() { + for (index, id) in top_level_accounts.iter().enumerate() { let new_account_id = id.parse::().unwrap(); let tx_hash = create_account( &mut env, account.clone(), new_account_id.clone(), epoch_length, - 1, + 1 + index as u64 * epoch_length, PROTOCOL_VERSION, ); let transaction_result = diff --git a/integration-tests/src/tests/client/process_blocks.rs b/integration-tests/src/tests/client/process_blocks.rs index 8cbef6fb3a3..d2756afd97c 100644 --- a/integration-tests/src/tests/client/process_blocks.rs +++ b/integration-tests/src/tests/client/process_blocks.rs @@ -130,15 +130,25 @@ pub(crate) fn produce_blocks_from_height( produce_blocks_from_height_with_protocol_version(env, blocks_number, height, PROTOCOL_VERSION) } -pub(crate) fn create_account(env: &mut TestEnv, old_account_id: AccountId, new_account_id: AccountId, epoch_length: u64, height: BlockHeight, protocol_version: ProtocolVersion) -> CryptoHash { +#[allow(unused)] +pub(crate) fn create_account( + env: &mut TestEnv, + old_account_id: AccountId, + new_account_id: AccountId, + epoch_length: u64, + height: BlockHeight, + protocol_version: ProtocolVersion, +) -> CryptoHash { let block = env.clients[0].chain.get_block_by_height(height - 1).unwrap(); - let signer = - InMemorySigner::from_seed(old_account_id.clone(), KeyType::ED25519, old_account_id.as_ref()); - + let signer = InMemorySigner::from_seed( + old_account_id.clone(), + KeyType::ED25519, + old_account_id.as_ref(), + ); let tx = SignedTransaction::create_account( height, - old_account_id.clone(), + old_account_id, new_account_id, 10u128.pow(24), signer.public_key(), From a48aa672332dac241f7fd7015e071cb75f90a593 Mon Sep 17 00:00:00 2001 From: Bowen Wang Date: Mon, 25 Sep 2023 21:08:25 -0700 Subject: [PATCH 3/6] add snap --- ...untime__config_store__tests__139.json.snap | 216 ++++++++++++++++++ ...config_store__tests__testnet_139.json.snap | 216 ++++++++++++++++++ 2 files changed, 432 insertions(+) create mode 100644 core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__139.json.snap create mode 100644 core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_139.json.snap diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__139.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__139.json.snap new file mode 100644 index 00000000000..5a3c8b59b69 --- /dev/null +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__139.json.snap @@ -0,0 +1,216 @@ +--- +source: core/primitives/src/runtime/config_store.rs +expression: config_view +--- +{ + "storage_amount_per_byte": "10000000000000000000", + "transaction_costs": { + "action_receipt_creation_config": { + "send_sir": 108059500000, + "send_not_sir": 108059500000, + "execution": 108059500000 + }, + "data_receipt_creation_config": { + "base_cost": { + "send_sir": 36486732312, + "send_not_sir": 36486732312, + "execution": 36486732312 + }, + "cost_per_byte": { + "send_sir": 17212011, + "send_not_sir": 17212011, + "execution": 17212011 + } + }, + "action_creation_config": { + "create_account_cost": { + "send_sir": 3850000000000, + "send_not_sir": 3850000000000, + "execution": 3850000000000 + }, + "deploy_contract_cost": { + "send_sir": 184765750000, + "send_not_sir": 184765750000, + "execution": 184765750000 + }, + "deploy_contract_cost_per_byte": { + "send_sir": 6812999, + "send_not_sir": 6812999, + "execution": 64572944 + }, + "function_call_cost": { + "send_sir": 2319861500000, + "send_not_sir": 2319861500000, + "execution": 2319861500000 + }, + "function_call_cost_per_byte": { + "send_sir": 2235934, + "send_not_sir": 2235934, + "execution": 2235934 + }, + "transfer_cost": { + "send_sir": 115123062500, + "send_not_sir": 115123062500, + "execution": 115123062500 + }, + "stake_cost": { + "send_sir": 141715687500, + "send_not_sir": 141715687500, + "execution": 102217625000 + }, + "add_key_cost": { + "full_access_cost": { + "send_sir": 101765125000, + "send_not_sir": 101765125000, + "execution": 101765125000 + }, + "function_call_cost": { + "send_sir": 102217625000, + "send_not_sir": 102217625000, + "execution": 102217625000 + }, + "function_call_cost_per_byte": { + "send_sir": 1925331, + "send_not_sir": 1925331, + "execution": 1925331 + } + }, + "delete_key_cost": { + "send_sir": 94946625000, + "send_not_sir": 94946625000, + "execution": 94946625000 + }, + "delete_account_cost": { + "send_sir": 147489000000, + "send_not_sir": 147489000000, + "execution": 147489000000 + }, + "delegate_cost": { + "send_sir": 200000000000, + "send_not_sir": 200000000000, + "execution": 200000000000 + } + }, + "storage_usage_config": { + "num_bytes_account": 100, + "num_extra_bytes_record": 40 + }, + "burnt_gas_reward": [ + 3, + 10 + ], + "pessimistic_gas_price_inflation_ratio": [ + 103, + 100 + ] + }, + "wasm_config": { + "ext_costs": { + "base": 264768111, + "contract_loading_base": 35445963, + "contract_loading_bytes": 216750, + "read_memory_base": 2609863200, + "read_memory_byte": 3801333, + "write_memory_base": 2803794861, + "write_memory_byte": 2723772, + "read_register_base": 2517165186, + "read_register_byte": 98562, + "write_register_base": 2865522486, + "write_register_byte": 3801564, + "utf8_decoding_base": 3111779061, + "utf8_decoding_byte": 291580479, + "utf16_decoding_base": 3543313050, + "utf16_decoding_byte": 163577493, + "sha256_base": 4540970250, + "sha256_byte": 24117351, + "keccak256_base": 5879491275, + "keccak256_byte": 21471105, + "keccak512_base": 5811388236, + "keccak512_byte": 36649701, + "ripemd160_base": 853675086, + "ripemd160_block": 680107584, + "ed25519_verify_base": 210000000000, + "ed25519_verify_byte": 9000000, + "ecrecover_base": 278821988457, + "log_base": 3543313050, + "log_byte": 13198791, + "storage_write_base": 64196736000, + "storage_write_key_byte": 70482867, + "storage_write_value_byte": 31018539, + "storage_write_evicted_byte": 32117307, + "storage_read_base": 56356845750, + "storage_read_key_byte": 30952533, + "storage_read_value_byte": 5611005, + "storage_remove_base": 53473030500, + "storage_remove_key_byte": 38220384, + "storage_remove_ret_value_byte": 11531556, + "storage_has_key_base": 54039896625, + "storage_has_key_byte": 30790845, + "storage_iter_create_prefix_base": 0, + "storage_iter_create_prefix_byte": 0, + "storage_iter_create_range_base": 0, + "storage_iter_create_from_byte": 0, + "storage_iter_create_to_byte": 0, + "storage_iter_next_base": 0, + "storage_iter_next_key_byte": 0, + "storage_iter_next_value_byte": 0, + "touching_trie_node": 16101955926, + "read_cached_trie_node": 2280000000, + "promise_and_base": 1465013400, + "promise_and_per_promise": 5452176, + "promise_return": 560152386, + "validator_stake_base": 911834726400, + "validator_total_stake_base": 911834726400, + "contract_compile_base": 0, + "contract_compile_bytes": 0, + "alt_bn128_g1_multiexp_base": 713000000000, + "alt_bn128_g1_multiexp_element": 320000000000, + "alt_bn128_g1_sum_base": 3000000000, + "alt_bn128_g1_sum_element": 5000000000, + "alt_bn128_pairing_check_base": 9686000000000, + "alt_bn128_pairing_check_element": 5102000000000 + }, + "grow_mem_cost": 1, + "regular_op_cost": 822756, + "disable_9393_fix": false, + "storage_get_mode": "FlatStorage", + "fix_contract_loading_cost": true, + "implicit_account_creation": true, + "math_extension": true, + "ed25519_verify": true, + "alt_bn128": true, + "function_call_weight": true, + "limit_config": { + "max_gas_burnt": 300000000000000, + "max_stack_height": 262144, + "contract_prepare_version": 2, + "initial_memory_pages": 1024, + "max_memory_pages": 2048, + "registers_memory_limit": 1073741824, + "max_register_size": 104857600, + "max_number_registers": 100, + "max_number_logs": 100, + "max_total_log_length": 16384, + "max_total_prepaid_gas": 300000000000000, + "max_actions_per_receipt": 100, + "max_number_bytes_method_names": 2000, + "max_length_method_name": 256, + "max_arguments_length": 4194304, + "max_length_returned_data": 4194304, + "max_contract_size": 4194304, + "max_transaction_size": 4194304, + "max_length_storage_key": 2048, + "max_length_storage_value": 4194304, + "max_promises_per_function_call_action": 1024, + "max_number_input_data_dependencies": 128, + "max_functions_number_per_contract": 10000, + "wasmer2_stack_limit": 204800, + "max_locals_per_contract": 1000000, + "account_id_validity_rules_version": 1 + } + }, + "account_creation_config": { + "min_allowed_top_level_account_length": 65, + "registrar_account_id": "registrar" + } +} diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_139.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_139.json.snap new file mode 100644 index 00000000000..5a3c8b59b69 --- /dev/null +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_139.json.snap @@ -0,0 +1,216 @@ +--- +source: core/primitives/src/runtime/config_store.rs +expression: config_view +--- +{ + "storage_amount_per_byte": "10000000000000000000", + "transaction_costs": { + "action_receipt_creation_config": { + "send_sir": 108059500000, + "send_not_sir": 108059500000, + "execution": 108059500000 + }, + "data_receipt_creation_config": { + "base_cost": { + "send_sir": 36486732312, + "send_not_sir": 36486732312, + "execution": 36486732312 + }, + "cost_per_byte": { + "send_sir": 17212011, + "send_not_sir": 17212011, + "execution": 17212011 + } + }, + "action_creation_config": { + "create_account_cost": { + "send_sir": 3850000000000, + "send_not_sir": 3850000000000, + "execution": 3850000000000 + }, + "deploy_contract_cost": { + "send_sir": 184765750000, + "send_not_sir": 184765750000, + "execution": 184765750000 + }, + "deploy_contract_cost_per_byte": { + "send_sir": 6812999, + "send_not_sir": 6812999, + "execution": 64572944 + }, + "function_call_cost": { + "send_sir": 2319861500000, + "send_not_sir": 2319861500000, + "execution": 2319861500000 + }, + "function_call_cost_per_byte": { + "send_sir": 2235934, + "send_not_sir": 2235934, + "execution": 2235934 + }, + "transfer_cost": { + "send_sir": 115123062500, + "send_not_sir": 115123062500, + "execution": 115123062500 + }, + "stake_cost": { + "send_sir": 141715687500, + "send_not_sir": 141715687500, + "execution": 102217625000 + }, + "add_key_cost": { + "full_access_cost": { + "send_sir": 101765125000, + "send_not_sir": 101765125000, + "execution": 101765125000 + }, + "function_call_cost": { + "send_sir": 102217625000, + "send_not_sir": 102217625000, + "execution": 102217625000 + }, + "function_call_cost_per_byte": { + "send_sir": 1925331, + "send_not_sir": 1925331, + "execution": 1925331 + } + }, + "delete_key_cost": { + "send_sir": 94946625000, + "send_not_sir": 94946625000, + "execution": 94946625000 + }, + "delete_account_cost": { + "send_sir": 147489000000, + "send_not_sir": 147489000000, + "execution": 147489000000 + }, + "delegate_cost": { + "send_sir": 200000000000, + "send_not_sir": 200000000000, + "execution": 200000000000 + } + }, + "storage_usage_config": { + "num_bytes_account": 100, + "num_extra_bytes_record": 40 + }, + "burnt_gas_reward": [ + 3, + 10 + ], + "pessimistic_gas_price_inflation_ratio": [ + 103, + 100 + ] + }, + "wasm_config": { + "ext_costs": { + "base": 264768111, + "contract_loading_base": 35445963, + "contract_loading_bytes": 216750, + "read_memory_base": 2609863200, + "read_memory_byte": 3801333, + "write_memory_base": 2803794861, + "write_memory_byte": 2723772, + "read_register_base": 2517165186, + "read_register_byte": 98562, + "write_register_base": 2865522486, + "write_register_byte": 3801564, + "utf8_decoding_base": 3111779061, + "utf8_decoding_byte": 291580479, + "utf16_decoding_base": 3543313050, + "utf16_decoding_byte": 163577493, + "sha256_base": 4540970250, + "sha256_byte": 24117351, + "keccak256_base": 5879491275, + "keccak256_byte": 21471105, + "keccak512_base": 5811388236, + "keccak512_byte": 36649701, + "ripemd160_base": 853675086, + "ripemd160_block": 680107584, + "ed25519_verify_base": 210000000000, + "ed25519_verify_byte": 9000000, + "ecrecover_base": 278821988457, + "log_base": 3543313050, + "log_byte": 13198791, + "storage_write_base": 64196736000, + "storage_write_key_byte": 70482867, + "storage_write_value_byte": 31018539, + "storage_write_evicted_byte": 32117307, + "storage_read_base": 56356845750, + "storage_read_key_byte": 30952533, + "storage_read_value_byte": 5611005, + "storage_remove_base": 53473030500, + "storage_remove_key_byte": 38220384, + "storage_remove_ret_value_byte": 11531556, + "storage_has_key_base": 54039896625, + "storage_has_key_byte": 30790845, + "storage_iter_create_prefix_base": 0, + "storage_iter_create_prefix_byte": 0, + "storage_iter_create_range_base": 0, + "storage_iter_create_from_byte": 0, + "storage_iter_create_to_byte": 0, + "storage_iter_next_base": 0, + "storage_iter_next_key_byte": 0, + "storage_iter_next_value_byte": 0, + "touching_trie_node": 16101955926, + "read_cached_trie_node": 2280000000, + "promise_and_base": 1465013400, + "promise_and_per_promise": 5452176, + "promise_return": 560152386, + "validator_stake_base": 911834726400, + "validator_total_stake_base": 911834726400, + "contract_compile_base": 0, + "contract_compile_bytes": 0, + "alt_bn128_g1_multiexp_base": 713000000000, + "alt_bn128_g1_multiexp_element": 320000000000, + "alt_bn128_g1_sum_base": 3000000000, + "alt_bn128_g1_sum_element": 5000000000, + "alt_bn128_pairing_check_base": 9686000000000, + "alt_bn128_pairing_check_element": 5102000000000 + }, + "grow_mem_cost": 1, + "regular_op_cost": 822756, + "disable_9393_fix": false, + "storage_get_mode": "FlatStorage", + "fix_contract_loading_cost": true, + "implicit_account_creation": true, + "math_extension": true, + "ed25519_verify": true, + "alt_bn128": true, + "function_call_weight": true, + "limit_config": { + "max_gas_burnt": 300000000000000, + "max_stack_height": 262144, + "contract_prepare_version": 2, + "initial_memory_pages": 1024, + "max_memory_pages": 2048, + "registers_memory_limit": 1073741824, + "max_register_size": 104857600, + "max_number_registers": 100, + "max_number_logs": 100, + "max_total_log_length": 16384, + "max_total_prepaid_gas": 300000000000000, + "max_actions_per_receipt": 100, + "max_number_bytes_method_names": 2000, + "max_length_method_name": 256, + "max_arguments_length": 4194304, + "max_length_returned_data": 4194304, + "max_contract_size": 4194304, + "max_transaction_size": 4194304, + "max_length_storage_key": 2048, + "max_length_storage_value": 4194304, + "max_promises_per_function_call_action": 1024, + "max_number_input_data_dependencies": 128, + "max_functions_number_per_contract": 10000, + "wasmer2_stack_limit": 204800, + "max_locals_per_contract": 1000000, + "account_id_validity_rules_version": 1 + } + }, + "account_creation_config": { + "min_allowed_top_level_account_length": 65, + "registrar_account_id": "registrar" + } +} From 751b5e5cf07ea50eab8034c3854b2b92333284a4 Mon Sep 17 00:00:00 2001 From: Bowen Wang Date: Tue, 26 Sep 2023 11:33:47 -0700 Subject: [PATCH 4/6] fix tests --- .../near_primitives__runtime__config_store__tests__139.json.snap | 1 + ...imitives__runtime__config_store__tests__testnet_139.json.snap | 1 + 2 files changed, 2 insertions(+) diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__139.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__139.json.snap index 5a3c8b59b69..3c4b293ccbb 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__139.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__139.json.snap @@ -172,6 +172,7 @@ expression: config_view }, "grow_mem_cost": 1, "regular_op_cost": 822756, + "vm_kind": "NearVm", "disable_9393_fix": false, "storage_get_mode": "FlatStorage", "fix_contract_loading_cost": true, diff --git a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_139.json.snap b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_139.json.snap index 5a3c8b59b69..3c4b293ccbb 100644 --- a/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_139.json.snap +++ b/core/primitives/src/runtime/snapshots/near_primitives__runtime__config_store__tests__testnet_139.json.snap @@ -172,6 +172,7 @@ expression: config_view }, "grow_mem_cost": 1, "regular_op_cost": 822756, + "vm_kind": "NearVm", "disable_9393_fix": false, "storage_get_mode": "FlatStorage", "fix_contract_loading_cost": true, From 2c1c3fd6814ee593baaeff6a23423d8299b8057b Mon Sep 17 00:00:00 2001 From: Bowen Wang Date: Mon, 2 Oct 2023 06:17:30 -0700 Subject: [PATCH 5/6] fix tests --- integration-tests/src/tests/client/features/restrict_tla.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/src/tests/client/features/restrict_tla.rs b/integration-tests/src/tests/client/features/restrict_tla.rs index 3ab1b28dfeb..b80621bae00 100644 --- a/integration-tests/src/tests/client/features/restrict_tla.rs +++ b/integration-tests/src/tests/client/features/restrict_tla.rs @@ -1,5 +1,4 @@ use super::super::process_blocks::create_account; -use crate::tests::client::utils::TestEnvNightshadeSetupExt; use near_chain::ChainGenesis; use near_chain_configs::Genesis; use near_client::test_utils::TestEnv; @@ -8,6 +7,7 @@ use near_primitives::types::{AccountId, BlockHeight}; use near_primitives::views::FinalExecutionStatus; use near_primitives_core::version::PROTOCOL_VERSION; use nearcore::config::GenesisExt; +use nearcore::test_utils::TestEnvNightshadeSetupExt; #[test] fn test_create_top_level_accounts() { From 073c523d8dcc70576aba32362c2f201b61a5b009 Mon Sep 17 00:00:00 2001 From: Bowen Wang Date: Mon, 2 Oct 2023 10:56:32 -0700 Subject: [PATCH 6/6] address some comments --- core/primitives-core/src/version.rs | 2 +- core/primitives/res/runtime_configs/parameters.snap | 2 +- integration-tests/src/tests/client/features/restrict_tla.rs | 2 ++ integration-tests/src/tests/client/process_blocks.rs | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/core/primitives-core/src/version.rs b/core/primitives-core/src/version.rs index da339429004..41b19df4d57 100644 --- a/core/primitives-core/src/version.rs +++ b/core/primitives-core/src/version.rs @@ -178,9 +178,9 @@ impl ProtocolFeature { ProtocolFeature::RejectBlocksWithOutdatedProtocolVersions => 132, #[cfg(feature = "protocol_feature_simple_nightshade_v2")] ProtocolFeature::SimpleNightshadeV2 => 135, + ProtocolFeature::PostStateRoot => 136, #[cfg(feature = "protocol_feature_restrict_tla")] ProtocolFeature::RestrictTla => 139, - ProtocolFeature::PostStateRoot => 136, } } } diff --git a/core/primitives/res/runtime_configs/parameters.snap b/core/primitives/res/runtime_configs/parameters.snap index 4a891b4dc7f..cbc4d5225fb 100644 --- a/core/primitives/res/runtime_configs/parameters.snap +++ b/core/primitives/res/runtime_configs/parameters.snap @@ -4,7 +4,7 @@ description: THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. --- burnt_gas_reward 3 / 10 pessimistic_gas_price_inflation 103 / 100 -min_allowed_top_level_account_length 65 +min_allowed_top_level_account_length 32 registrar_account_id registrar storage_amount_per_byte 10000000000000000000 storage_num_bytes_account 100 diff --git a/integration-tests/src/tests/client/features/restrict_tla.rs b/integration-tests/src/tests/client/features/restrict_tla.rs index b80621bae00..250a2e42af1 100644 --- a/integration-tests/src/tests/client/features/restrict_tla.rs +++ b/integration-tests/src/tests/client/features/restrict_tla.rs @@ -22,6 +22,8 @@ fn test_create_top_level_accounts() { .nightshade_runtimes_with_runtime_config_store(&genesis, vec![runtime_config]) .build(); + // These accounts cannot be created because they are top level accounts that are not implicit. + // Note that implicit accounts have to be 64 characters long. let top_level_accounts = [ "0x06012c8cf97bead5deae237070f9587f8e7a266d", "0x5e97870f263700f46aa00d967821199b9bc5a120", diff --git a/integration-tests/src/tests/client/process_blocks.rs b/integration-tests/src/tests/client/process_blocks.rs index 3f455ad8948..45cde15a2cb 100644 --- a/integration-tests/src/tests/client/process_blocks.rs +++ b/integration-tests/src/tests/client/process_blocks.rs @@ -123,7 +123,7 @@ pub(crate) fn produce_blocks_from_height( produce_blocks_from_height_with_protocol_version(env, blocks_number, height, PROTOCOL_VERSION) } -#[allow(unused)] +#[cfg(feature = "protocol_feature_restrict_tla")] pub(crate) fn create_account( env: &mut TestEnv, old_account_id: AccountId,