Skip to content

Commit 4de11b1

Browse files
authored
chore: remove script tech debt (#22333)
1 parent 6107551 commit 4de11b1

File tree

16 files changed

+43
-47
lines changed

16 files changed

+43
-47
lines changed

crates/sui-open-rpc/spec/openrpc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,7 @@
13211321
"disallow_adding_abilities_on_upgrade": false,
13221322
"disallow_change_struct_type_params_on_upgrade": false,
13231323
"disallow_new_modules_in_deps_only_packages": false,
1324+
"disallow_self_identifier": false,
13241325
"enable_coin_deny_list": false,
13251326
"enable_coin_deny_list_v2": false,
13261327
"enable_effects_v2": false,

crates/sui-protocol-config/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,10 @@ struct FeatureFlags {
612612
#[serde(skip_serializing_if = "is_false")]
613613
validate_identifier_inputs: bool,
614614

615+
// Disallow self identifier
616+
#[serde(skip_serializing_if = "is_false")]
617+
disallow_self_identifier: bool,
618+
615619
// Enables Mysticeti fastpath.
616620
#[serde(skip_serializing_if = "is_false")]
617621
mysticeti_fastpath: bool,
@@ -3679,6 +3683,7 @@ impl ProtocolConfig {
36793683

36803684
cfg.feature_flags
36813685
.record_consensus_determined_version_assignments_in_prologue_v2 = true;
3686+
cfg.feature_flags.disallow_self_identifier = true;
36823687
}
36833688
// Use this template when making changes:
36843689
//
@@ -3729,6 +3734,7 @@ impl ProtocolConfig {
37293734
max_back_edges_per_module,
37303735
max_basic_blocks_in_script: None,
37313736
max_idenfitier_len: self.max_move_identifier_len_as_option(), // Before protocol version 9, there was no limit
3737+
disallow_self_identifier: self.feature_flags.disallow_self_identifier,
37323738
allow_receiving_object_id: self.allow_receiving_object_id(),
37333739
reject_mutable_random_on_entry_functions: self
37343740
.reject_mutable_random_on_entry_functions(),

crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_85.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ feature_flags:
7373
consensus_distributed_vote_scoring_strategy: true
7474
consensus_round_prober: true
7575
validate_identifier_inputs: true
76+
disallow_self_identifier: true
7677
relocate_event_module: true
7778
uncompressed_g1_group_elements: true
7879
disallow_new_modules_in_deps_only_packages: true

crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_85.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ feature_flags:
7575
consensus_distributed_vote_scoring_strategy: true
7676
consensus_round_prober: true
7777
validate_identifier_inputs: true
78+
disallow_self_identifier: true
7879
relocate_event_module: true
7980
uncompressed_g1_group_elements: true
8081
disallow_new_modules_in_deps_only_packages: true

crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_85.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ feature_flags:
7979
consensus_distributed_vote_scoring_strategy: true
8080
consensus_round_prober: true
8181
validate_identifier_inputs: true
82+
disallow_self_identifier: true
8283
mysticeti_fastpath: true
8384
relocate_event_module: true
8485
uncompressed_g1_group_elements: true

crates/sui-types/src/transaction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ fn type_input_validity_check(
152152
let next_depth = depth + 1;
153153
if config.validate_identifier_inputs() {
154154
fp_ensure!(
155-
identifier::is_valid(&s.module),
155+
identifier::is_valid(&s.module) && s.module != "<SELF>",
156156
UserInputError::InvalidIdentifier {
157157
error: s.module.clone()
158158
}
159159
);
160160
fp_ensure!(
161-
identifier::is_valid(&s.name),
161+
identifier::is_valid(&s.name) && s.name != "<SELF>",
162162
UserInputError::InvalidIdentifier {
163163
error: s.name.clone()
164164
}

external-crates/move/crates/bytecode-verifier-tests/src/unit_tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub(crate) fn production_config() -> (VerifierConfig, MeterConfig) {
4848

4949
max_constant_vector_len: Some(DEFAULT_MAX_CONSTANT_VECTOR_LEN),
5050
max_idenfitier_len: Some(DEFAULT_MAX_IDENTIFIER_LENGTH),
51+
disallow_self_identifier: true,
5152
allow_receiving_object_id: true,
5253
reject_mutable_random_on_entry_functions: true,
5354
bytecode_version: VERSION_MAX,

external-crates/move/crates/move-binary-format/src/file_format.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ use move_core_types::{
4242
};
4343
#[cfg(any(test, feature = "fuzzing"))]
4444
use proptest::{collection::vec, prelude::*, strategy::BoxedStrategy};
45-
use ref_cast::RefCast;
4645
use serde::{Deserialize, Serialize};
4746
use std::fmt::{Display, Formatter};
4847
use std::ops::BitOr;
@@ -246,12 +245,6 @@ pub type TypeSignaturePool = Vec<TypeSignature>;
246245
/// locals used and their types.
247246
pub type SignaturePool = Vec<Signature>;
248247

249-
// TODO: "<SELF>" only passes the validator for identifiers because it is special cased. Whenever
250-
// "<SELF>" is removed, so should the special case in identifier.rs.
251-
pub fn self_module_name() -> &'static IdentStr {
252-
IdentStr::ref_cast("<SELF>")
253-
}
254-
255248
/// Index 0 into the LocalsSignaturePool, which is guaranteed to be an empty list.
256249
/// Used to represent function/struct instantiation with no type arguments -- effectively
257250
/// non-generic functions and structs.
@@ -2835,7 +2828,7 @@ pub fn empty_module() -> CompiledModule {
28352828
name: IdentifierIndex(0),
28362829
}],
28372830
self_module_handle_idx: ModuleHandleIndex(0),
2838-
identifiers: vec![self_module_name().to_owned()],
2831+
identifiers: vec![move_core_types::ident_str!("DUMMY").to_owned()],
28392832
address_identifiers: vec![AccountAddress::ZERO],
28402833
constant_pool: vec![],
28412834
metadata: vec![],

external-crates/move/crates/move-bytecode-verifier/src/limits.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,27 @@ impl<'a> LimitsVerifier<'a> {
207207

208208
/// Verifies the lengths of all identifers are valid
209209
fn verify_identifiers(&self, config: &VerifierConfig) -> PartialVMResult<()> {
210-
if let Some(max_idenfitier_len) = config.max_idenfitier_len {
211-
for (idx, identifier) in self.module.identifiers().iter().enumerate() {
212-
if identifier.len() > (max_idenfitier_len as usize) {
213-
return Err(verification_error(
214-
StatusCode::IDENTIFIER_TOO_LONG,
215-
IndexKind::Identifier,
216-
idx as TableIndex,
217-
));
218-
}
210+
for (idx, identifier) in self.module.identifiers().iter().enumerate() {
211+
if config
212+
.max_idenfitier_len
213+
.is_some_and(|max_identifier_len| identifier.len() > (max_identifier_len as usize))
214+
{
215+
return Err(verification_error(
216+
StatusCode::IDENTIFIER_TOO_LONG,
217+
IndexKind::Identifier,
218+
idx as TableIndex,
219+
));
220+
}
221+
222+
if config.disallow_self_identifier && identifier.as_str() == "<SELF>" {
223+
return Err(verification_error(
224+
StatusCode::INVALID_IDENTIFIER,
225+
IndexKind::Identifier,
226+
idx as TableIndex,
227+
));
219228
}
220229
}
230+
221231
Ok(())
222232
}
223233
}

external-crates/move/crates/move-core-types/src/vm_status.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ pub enum StatusCode {
314314
ZERO_SIZED_ENUM = 1134,
315315
MAX_VARIANTS_REACHED = 1135,
316316

317+
INVALID_IDENTIFIER = 1136,
318+
317319
// These are errors that the VM might raise if a violation of internal
318320
// invariants takes place.
319321
// Invariant Violation Errors: 2000-2999

external-crates/move/crates/move-model/src/builder/module_builder.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
},
2323
model::{
2424
DatatypeId, EnumData, FunId, FunctionData, Loc, ModuleId, NamedConstantData,
25-
NamedConstantId, SCRIPT_BYTECODE_FUN_NAME, StructData,
25+
NamedConstantId, StructData,
2626
},
2727
project_1st,
2828
symbol::{Symbol, SymbolPool},
@@ -485,16 +485,7 @@ impl ModuleBuilder<'_, '_> {
485485
let handle_idx = module.function_def_at(def_idx).function;
486486
let handle = module.function_handle_at(handle_idx);
487487
let name_str = module.identifier_at(handle.name).as_str();
488-
let name = if name_str == SCRIPT_BYTECODE_FUN_NAME {
489-
// This is a pseudo script module, which has exactly one function. Determine
490-
// the name of this function.
491-
self.parent.fun_table.iter().find_map(|(k, _)| {
492-
if k.module_name == self.module_name
493-
{ Some(k.symbol) } else { None }
494-
}).expect("unexpected script with multiple or no functions")
495-
} else {
496-
self.symbol_pool().make(name_str)
497-
};
488+
let name = self.symbol_pool().make(name_str);
498489
if let Some(entry) = self.parent.fun_table.get(&self.qualified_by_module(name)) {
499490
let arg_names = project_1st(&entry.params);
500491
let type_arg_names = project_1st(&entry.type_params);

external-crates/move/crates/move-model/src/model.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,6 @@ use crate::{
6565
// =================================================================================================
6666
// # Constants
6767

68-
/// A name we use to represent a script as a module.
69-
pub const SCRIPT_MODULE_NAME: &str = "<SELF>";
70-
71-
/// Names used in the bytecode/AST to represent the main function of a script
72-
pub const SCRIPT_BYTECODE_FUN_NAME: &str = "<SELF>";
73-
7468
/// A prefix used for structs which are backing specification ("ghost") memory.
7569
pub const GHOST_MEMORY_PREFIX: &str = "Ghost$";
7670

@@ -865,17 +859,7 @@ impl GlobalEnv {
865859
function_data: BTreeMap<FunId, FunctionData>,
866860
) {
867861
let idx = self.module_data.len();
868-
let effective_name = if module.self_id().name().as_str() == SCRIPT_MODULE_NAME {
869-
// Use the name of the first function in this module.
870-
function_data
871-
.iter()
872-
.next()
873-
.expect("functions in script")
874-
.1
875-
.name
876-
} else {
877-
self.symbol_pool.make(module.self_id().name().as_str())
878-
};
862+
let effective_name = self.symbol_pool.make(module.self_id().name().as_str());
879863
let name = ModuleName::from_str(&module.self_id().address().to_string(), effective_name);
880864
let struct_idx_to_id: BTreeMap<StructDefinitionIndex, DatatypeId> = struct_data
881865
.iter()

external-crates/move/crates/move-vm-config/src/verifier.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct VerifierConfig {
2525
pub max_back_edges_per_module: Option<usize>,
2626
pub max_basic_blocks_in_script: Option<usize>,
2727
pub max_idenfitier_len: Option<u64>,
28+
pub disallow_self_identifier: bool,
2829
pub allow_receiving_object_id: bool,
2930
pub reject_mutable_random_on_entry_functions: bool,
3031
pub bytecode_version: u32,
@@ -69,6 +70,7 @@ impl Default for VerifierConfig {
6970
max_basic_blocks_in_script: None,
7071
max_constant_vector_len: Some(DEFAULT_MAX_CONSTANT_VECTOR_LEN),
7172
max_idenfitier_len: Some(DEFAULT_MAX_IDENTIFIER_LENGTH),
73+
disallow_self_identifier: false,
7274
allow_receiving_object_id: true,
7375
reject_mutable_random_on_entry_functions: true,
7476
bytecode_version: VERSION_MAX,

external-crates/move/move-execution/v0/crates/bytecode-verifier-tests/src/unit_tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub(crate) fn production_config() -> (VerifierConfig, MeterConfig) {
4848

4949
max_constant_vector_len: Some(DEFAULT_MAX_CONSTANT_VECTOR_LEN),
5050
max_idenfitier_len: Some(DEFAULT_MAX_IDENTIFIER_LENGTH),
51+
disallow_self_identifier: true,
5152
allow_receiving_object_id: true,
5253
reject_mutable_random_on_entry_functions: true,
5354
bytecode_version: VERSION_6,

external-crates/move/move-execution/v1/crates/bytecode-verifier-tests/src/unit_tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub(crate) fn production_config() -> (VerifierConfig, MeterConfig) {
4848

4949
max_constant_vector_len: Some(DEFAULT_MAX_CONSTANT_VECTOR_LEN),
5050
max_idenfitier_len: Some(DEFAULT_MAX_IDENTIFIER_LENGTH),
51+
disallow_self_identifier: true,
5152
allow_receiving_object_id: true,
5253
reject_mutable_random_on_entry_functions: true,
5354
bytecode_version: VERSION_6,

external-crates/move/move-execution/v2/crates/bytecode-verifier-tests/src/unit_tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub(crate) fn production_config() -> (VerifierConfig, MeterConfig) {
4848

4949
max_constant_vector_len: Some(DEFAULT_MAX_CONSTANT_VECTOR_LEN),
5050
max_idenfitier_len: Some(DEFAULT_MAX_IDENTIFIER_LENGTH),
51+
disallow_self_identifier: true,
5152
allow_receiving_object_id: true,
5253
reject_mutable_random_on_entry_functions: true,
5354
bytecode_version: VERSION_6,

0 commit comments

Comments
 (0)