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

[move] Copy Sui's Move stdlib into external-crates. Bump the default package version to 2024 beta. #18827

Merged
merged 18 commits into from
Jul 28, 2024
Merged
1,126 changes: 0 additions & 1,126 deletions crates/sui-core/tests/staged/sui.yaml

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion crates/sui-move/src/unit_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ pub fn run_move_unit_tests(
report_stacktrace_on_abort: true,
..config
},
sui_move_natives::all_natives(/* silent */ false),
sui_move_natives::all_natives(
/* silent */ false,
&ProtocolConfig::get_for_max_version_UNSAFE(),
),
Some(initial_cost_schedule_for_unit_tests()),
compute_coverage,
&mut std::io::stdout(),
Expand Down
31 changes: 30 additions & 1 deletion crates/sui-open-rpc/spec/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,9 @@
"base_tx_cost_per_byte": {
"u64": "0"
},
"bcs_failure_cost": null,
"bcs_legacy_min_output_size_cost": null,
"bcs_per_byte_serialized_cost": null,
"binary_address_identifiers": null,
"binary_constant_pool": null,
"binary_enum_def_instantiations": null,
Expand Down Expand Up @@ -1419,6 +1422,8 @@
"crypto_invalid_arguments_cost": {
"u64": "100"
},
"debug_print_base_cost": null,
"debug_print_stack_trace_base_cost": null,
"dynamic_field_add_child_object_cost_base": {
"u64": "100"
},
Expand Down Expand Up @@ -1652,6 +1657,12 @@
"hash_keccak256_data_cost_per_byte": {
"u64": "2"
},
"hash_sha2_256_base_cost": null,
"hash_sha2_256_legacy_min_input_len_cost": null,
"hash_sha2_256_per_byte_cost": null,
"hash_sha3_256_base_cost": null,
"hash_sha3_256_legacy_min_input_len_cost": null,
"hash_sha3_256_per_byte_cost": null,
"hmac_hmac_sha3_256_cost_base": {
"u64": "52"
},
Expand Down Expand Up @@ -1875,6 +1886,14 @@
"storage_rebate_rate": {
"u64": "9900"
},
"string_check_utf8_base_cost": null,
"string_check_utf8_per_byte_cost": null,
"string_index_of_base_cost": null,
"string_index_of_per_byte_pattern_cost": null,
"string_index_of_per_byte_searched_cost": null,
"string_is_char_boundary_base_cost": null,
"string_sub_string_base_cost": null,
"string_sub_string_per_byte_cost": null,
"transfer_freeze_object_cost_base": {
"u64": "52"
},
Expand All @@ -1888,6 +1907,8 @@
"tx_context_derive_id_cost_base": {
"u64": "52"
},
"type_name_get_base_cost": null,
"type_name_get_per_byte_cost": null,
"types_is_one_time_witness_cost_base": {
"u64": "52"
},
Expand All @@ -1904,7 +1925,15 @@
"u64": "2"
},
"vdf_hash_to_input_cost": null,
"vdf_verify_vdf_cost": null
"vdf_verify_vdf_cost": null,
"vector_borrow_base_cost": null,
"vector_destroy_empty_base_cost": null,
"vector_empty_base_cost": null,
"vector_length_base_cost": null,
"vector_pop_back_base_cost": null,
"vector_push_back_base_cost": null,
"vector_push_back_legacy_per_abstract_memory_unit_cost": null,
"vector_swap_base_cost": null
}
}
}
Expand Down
96 changes: 96 additions & 0 deletions crates/sui-protocol-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ const MAX_PROTOCOL_VERSION: u64 = 53;
// Version 53: Add feature flag to decide whether to attempt to finalize bridge committee
// Enable consensus commit prologue V3 on testnet.
// Turn on shared object congestion control in testnet.
// Update stdlib natives costs

#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct ProtocolVersion(u64);
Expand Down Expand Up @@ -1101,6 +1102,40 @@ pub struct ProtocolConfig {
vdf_verify_vdf_cost: Option<u64>,
vdf_hash_to_input_cost: Option<u64>,

// Stdlib costs
bcs_per_byte_serialized_cost: Option<u64>,
bcs_legacy_min_output_size_cost: Option<u64>,
bcs_failure_cost: Option<u64>,

hash_sha2_256_base_cost: Option<u64>,
hash_sha2_256_per_byte_cost: Option<u64>,
hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
hash_sha3_256_base_cost: Option<u64>,
hash_sha3_256_per_byte_cost: Option<u64>,
hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
type_name_get_base_cost: Option<u64>,
type_name_get_per_byte_cost: Option<u64>,

string_check_utf8_base_cost: Option<u64>,
string_check_utf8_per_byte_cost: Option<u64>,
string_is_char_boundary_base_cost: Option<u64>,
string_sub_string_base_cost: Option<u64>,
string_sub_string_per_byte_cost: Option<u64>,
string_index_of_base_cost: Option<u64>,
string_index_of_per_byte_pattern_cost: Option<u64>,
string_index_of_per_byte_searched_cost: Option<u64>,

vector_empty_base_cost: Option<u64>,
vector_length_base_cost: Option<u64>,
vector_push_back_base_cost: Option<u64>,
vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
vector_borrow_base_cost: Option<u64>,
vector_pop_back_base_cost: Option<u64>,
vector_destroy_empty_base_cost: Option<u64>,
vector_swap_base_cost: Option<u64>,
debug_print_base_cost: Option<u64>,
debug_print_stack_trace_base_cost: Option<u64>,

// ==== Ephemeral (consensus only) params deleted ====
//
// Const params for consensus scoring decision
Expand Down Expand Up @@ -1909,6 +1944,36 @@ impl ProtocolConfig {
vdf_verify_vdf_cost: None,
vdf_hash_to_input_cost: None,

bcs_per_byte_serialized_cost: None,
bcs_legacy_min_output_size_cost: None,
bcs_failure_cost: None,
hash_sha2_256_base_cost: None,
hash_sha2_256_per_byte_cost: None,
hash_sha2_256_legacy_min_input_len_cost: None,
hash_sha3_256_base_cost: None,
hash_sha3_256_per_byte_cost: None,
hash_sha3_256_legacy_min_input_len_cost: None,
type_name_get_base_cost: None,
type_name_get_per_byte_cost: None,
string_check_utf8_base_cost: None,
string_check_utf8_per_byte_cost: None,
string_is_char_boundary_base_cost: None,
string_sub_string_base_cost: None,
string_sub_string_per_byte_cost: None,
string_index_of_base_cost: None,
string_index_of_per_byte_pattern_cost: None,
string_index_of_per_byte_searched_cost: None,
vector_empty_base_cost: None,
vector_length_base_cost: None,
vector_push_back_base_cost: None,
vector_push_back_legacy_per_abstract_memory_unit_cost: None,
vector_borrow_base_cost: None,
vector_pop_back_base_cost: None,
vector_destroy_empty_base_cost: None,
vector_swap_base_cost: None,
debug_print_base_cost: None,
debug_print_stack_trace_base_cost: None,

max_size_written_objects: None,
max_size_written_objects_system_tx: None,

Expand Down Expand Up @@ -2536,6 +2601,37 @@ impl ProtocolConfig {
cfg.feature_flags.per_object_congestion_control_mode =
PerObjectCongestionControlMode::TotalTxCount;
}

// Adjust stdlib gas costs
cfg.bcs_per_byte_serialized_cost = Some(2);
cfg.bcs_legacy_min_output_size_cost = Some(52);
cfg.bcs_failure_cost = Some(52);
cfg.debug_print_base_cost = Some(52);
cfg.debug_print_stack_trace_base_cost = Some(52);
cfg.hash_sha2_256_base_cost = Some(52);
cfg.hash_sha2_256_per_byte_cost = Some(2);
cfg.hash_sha2_256_legacy_min_input_len_cost = Some(1);
cfg.hash_sha3_256_base_cost = Some(52);
cfg.hash_sha3_256_per_byte_cost = Some(2);
cfg.hash_sha3_256_legacy_min_input_len_cost = Some(1);
cfg.type_name_get_base_cost = Some(52);
cfg.type_name_get_per_byte_cost = Some(2);
cfg.string_check_utf8_base_cost = Some(52);
cfg.string_check_utf8_per_byte_cost = Some(2);
cfg.string_is_char_boundary_base_cost = Some(52);
cfg.string_sub_string_base_cost = Some(52);
cfg.string_sub_string_per_byte_cost = Some(2);
cfg.string_index_of_base_cost = Some(52);
cfg.string_index_of_per_byte_pattern_cost = Some(2);
cfg.string_index_of_per_byte_searched_cost = Some(2);
cfg.vector_empty_base_cost = Some(52);
cfg.vector_length_base_cost = Some(52);
cfg.vector_push_back_base_cost = Some(52);
cfg.vector_push_back_legacy_per_abstract_memory_unit_cost = Some(2);
cfg.vector_borrow_base_cost = Some(52);
cfg.vector_pop_back_base_cost = Some(52);
cfg.vector_destroy_empty_base_cost = Some(52);
cfg.vector_swap_base_cost = Some(52);
}
// Use this template when making changes:
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,35 @@ hmac_hmac_sha3_256_input_cost_per_byte: 2
hmac_hmac_sha3_256_input_cost_per_block: 2
check_zklogin_id_cost_base: 200
check_zklogin_issuer_cost_base: 200
bcs_per_byte_serialized_cost: 2
bcs_legacy_min_output_size_cost: 52
bcs_failure_cost: 52
hash_sha2_256_base_cost: 52
hash_sha2_256_per_byte_cost: 2
hash_sha2_256_legacy_min_input_len_cost: 1
hash_sha3_256_base_cost: 52
hash_sha3_256_per_byte_cost: 2
hash_sha3_256_legacy_min_input_len_cost: 1
type_name_get_base_cost: 52
type_name_get_per_byte_cost: 2
string_check_utf8_base_cost: 52
string_check_utf8_per_byte_cost: 2
string_is_char_boundary_base_cost: 52
string_sub_string_base_cost: 52
string_sub_string_per_byte_cost: 2
string_index_of_base_cost: 52
string_index_of_per_byte_pattern_cost: 2
string_index_of_per_byte_searched_cost: 2
vector_empty_base_cost: 52
vector_length_base_cost: 52
vector_push_back_base_cost: 52
vector_push_back_legacy_per_abstract_memory_unit_cost: 2
vector_borrow_base_cost: 52
vector_pop_back_base_cost: 52
vector_destroy_empty_base_cost: 52
vector_swap_base_cost: 52
debug_print_base_cost: 52
debug_print_stack_trace_base_cost: 52
execution_version: 3
consensus_bad_nodes_stake_threshold: 20
max_jwk_votes_per_validator_per_epoch: 240
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,35 @@ hmac_hmac_sha3_256_input_cost_per_byte: 2
hmac_hmac_sha3_256_input_cost_per_block: 2
check_zklogin_id_cost_base: 200
check_zklogin_issuer_cost_base: 200
bcs_per_byte_serialized_cost: 2
bcs_legacy_min_output_size_cost: 52
bcs_failure_cost: 52
hash_sha2_256_base_cost: 52
hash_sha2_256_per_byte_cost: 2
hash_sha2_256_legacy_min_input_len_cost: 1
hash_sha3_256_base_cost: 52
hash_sha3_256_per_byte_cost: 2
hash_sha3_256_legacy_min_input_len_cost: 1
type_name_get_base_cost: 52
type_name_get_per_byte_cost: 2
string_check_utf8_base_cost: 52
string_check_utf8_per_byte_cost: 2
string_is_char_boundary_base_cost: 52
string_sub_string_base_cost: 52
string_sub_string_per_byte_cost: 2
string_index_of_base_cost: 52
string_index_of_per_byte_pattern_cost: 2
string_index_of_per_byte_searched_cost: 2
vector_empty_base_cost: 52
vector_length_base_cost: 52
vector_push_back_base_cost: 52
vector_push_back_legacy_per_abstract_memory_unit_cost: 2
vector_borrow_base_cost: 52
vector_pop_back_base_cost: 52
vector_destroy_empty_base_cost: 52
vector_swap_base_cost: 52
debug_print_base_cost: 52
debug_print_stack_trace_base_cost: 52
execution_version: 3
consensus_bad_nodes_stake_threshold: 20
max_jwk_votes_per_validator_per_epoch: 240
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,35 @@ check_zklogin_id_cost_base: 200
check_zklogin_issuer_cost_base: 200
vdf_verify_vdf_cost: 1500
vdf_hash_to_input_cost: 100
bcs_per_byte_serialized_cost: 2
bcs_legacy_min_output_size_cost: 52
bcs_failure_cost: 52
hash_sha2_256_base_cost: 52
hash_sha2_256_per_byte_cost: 2
hash_sha2_256_legacy_min_input_len_cost: 1
hash_sha3_256_base_cost: 52
hash_sha3_256_per_byte_cost: 2
hash_sha3_256_legacy_min_input_len_cost: 1
type_name_get_base_cost: 52
type_name_get_per_byte_cost: 2
string_check_utf8_base_cost: 52
string_check_utf8_per_byte_cost: 2
string_is_char_boundary_base_cost: 52
string_sub_string_base_cost: 52
string_sub_string_per_byte_cost: 2
string_index_of_base_cost: 52
string_index_of_per_byte_pattern_cost: 2
string_index_of_per_byte_searched_cost: 2
vector_empty_base_cost: 52
vector_length_base_cost: 52
vector_push_back_base_cost: 52
vector_push_back_legacy_per_abstract_memory_unit_cost: 2
vector_borrow_base_cost: 52
vector_pop_back_base_cost: 52
vector_destroy_empty_base_cost: 52
vector_swap_base_cost: 52
debug_print_base_cost: 52
debug_print_stack_trace_base_cost: 52
execution_version: 3
consensus_bad_nodes_stake_threshold: 20
max_jwk_votes_per_validator_per_epoch: 240
Expand All @@ -299,3 +328,4 @@ checkpoint_summary_version_specific_data: 1
max_soft_bundle_size: 5
bridge_should_try_to_finalize_committee: true
max_accumulated_txn_cost_per_object_in_mysticeti_commit: 10

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn bench<M: Measurement + 'static>(c: &mut Criterion<M>, fun: &str) {
let move_vm = MoveVM::new(move_stdlib_natives::all_natives(
AccountAddress::from_hex_literal("0x1").unwrap(),
move_stdlib_natives::GasParameters::zeros(),
/* silent debug */ true,
))
.unwrap();
execute(c, &move_vm, modules, fun);
Expand Down
11 changes: 2 additions & 9 deletions external-crates/move/crates/move-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@

use anyhow::Result;
use move_core_types::account_address::AccountAddress;
use move_stdlib_natives::{all_natives, nursery_natives, GasParameters, NurseryGasParameters};
use move_stdlib_natives::{all_natives, GasParameters};

fn main() -> Result<()> {
let cost_table = &move_vm_test_utils::gas_schedule::INITIAL_COST_SCHEDULE;
let addr = AccountAddress::from_hex_literal("0x1").unwrap();
let natives = all_natives(addr, GasParameters::zeros())
.into_iter()
.chain(nursery_natives(
/* silent */ false,
addr,
NurseryGasParameters::zeros(),
))
.collect();
let natives = all_natives(addr, GasParameters::zeros(), /* silent */ false);

move_cli::move_cli(natives, cost_table)
}
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,6 @@ impl Serialize for Flavor {

impl Default for Edition {
fn default() -> Self {
Edition::LEGACY
Edition::E2024_BETA
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ error[E04023]: invalid method call
10 │ 0u64.f();
│ ^^^^^^^^
│ │ │
│ │ No local 'use fun' alias was found for 'u64.f'
│ │ No local 'use fun' alias was found for 'u64.f', and no function 'f' was found in the defining module 'std::u64'
│ Invalid method call. No known method 'f' on type 'u64'

error[E04023]: invalid method call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ error[E10004]: invalid usage of known attribute
2 │ module a::m {}
│ - Previously declared here
3 │
4 │ #[defines_primitive(u64)]
4 │ #[defines_primitive(signer)]
│ ^^^^^^^^^^^^^^^^^^^^^^^^^ Duplicate definer annotated for primitive type 'signer'

error[E10004]: invalid usage of known attribute
┌─ tests/move_2024/typing/duplicate_defines_primitive.move:7:3
7 │ #[defines_primitive(u64)]
│ ^^^^^^^^^^^^^^^^^^^^^^ Duplicate definer annotated for primitive type 'u64'
┌─ /Users/tmn/sui/external-crates/move/crates/move-stdlib/sources/u64.move:5:13
5 │ module std::u64 {
│ --- Previously declared here

Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#[defines_primitive(u64)]
#[defines_primitive(signer)]
module a::m {}

#[defines_primitive(u64)]
#[defines_primitive(signer)]
module a::n {}

#[defines_primitive(u64)]
module a::x {}
Loading
Loading