Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runtime): restrict creation of non-implicit TLA #9589

Merged
merged 8 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions chain/chain/src/tests/simple_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down
2 changes: 2 additions & 0 deletions core/primitives-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ 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",
"protocol_feature_fix_contract_loading_cost",
"protocol_feature_fix_staking_threshold",
"protocol_feature_reject_blocks_with_outdated_protocol_version",
"protocol_feature_restrict_tla",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't think tla is a widely known acronym, how about the full wording "top_level_accounts"? Same in the protocol feature enum.

"protocol_feature_simple_nightshade_v2",
]

Expand Down
6 changes: 5 additions & 1 deletion core/primitives-core/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ pub enum ProtocolFeature {
RejectBlocksWithOutdatedProtocolVersions,
#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
SimpleNightshadeV2,
#[cfg(feature = "protocol_feature_restrict_tla")]
RestrictTla,
/// Enables block production with post-state-root.
/// NEP: https://github.com/near/NEPs/pull/507
PostStateRoot,
Expand Down Expand Up @@ -177,6 +179,8 @@ impl ProtocolFeature {
#[cfg(feature = "protocol_feature_simple_nightshade_v2")]
ProtocolFeature::SimpleNightshadeV2 => 135,
ProtocolFeature::PostStateRoot => 136,
#[cfg(feature = "protocol_feature_restrict_tla")]
ProtocolFeature::RestrictTla => 139,
Comment on lines +182 to +183
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Out of order, probably due to some merging, can you put it after post state root?

Any reason to increase the version by 3?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Out of order, probably due to some merging, can you put it after post state root?

Done

Any reason to increase the version by 3?

That is because there was a 138 when this feature was implemented and it is actually hard to change because of the yaml file (a bunch of things need to be regenerated). There is no harm jumping a few versions for nightly so I think it's okay.

}
}
}
Expand All @@ -189,7 +193,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
Expand Down
2 changes: 2 additions & 0 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ 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_restrict_tla",
"protocol_feature_simple_nightshade_v2",
"near-fmt/nightly",
"near-primitives-core/nightly",
Expand Down
2 changes: 2 additions & 0 deletions core/primitives/res/runtime_configs/139.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Implements NEP-492, disallowing all top-level accounts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL
Also cool that it respects protocol version.

min_allowed_top_level_account_length: { old: 32, new: 65 }
1 change: 1 addition & 0 deletions core/primitives/src/runtime/config_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
---
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,
"vm_kind": "NearVm",
"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"
}
}
Loading